Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ rulesync.local.jsonc
**/.rooignore
**/.roo/mcp.json
**/.roo/subagents/
**/.rovodev/
**/.rovodev/AGENTS.md
**/AGENTS.local.md
**/.rovodev/subagents/
**/.rovodev/skills/
**/.agents/skills/
**/.warp/
**/WARP.md
2 changes: 1 addition & 1 deletion src/cli/commands/gitignore-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const GITIGNORE_ENTRY_REGISTRY: ReadonlyArray<GitignoreEntryTag> = [
{ target: "common", feature: "general", entry: ".rulesync/rules/*.local.md" },
{ target: "common", feature: "general", entry: "rulesync.local.jsonc" },
{ target: "common", feature: "general", entry: "!.rulesync/.aiignore" },
{ target: "common", feature: "general", entry: "**/AGENTS.local.md" },

// AGENTS.md
{ target: "agentsmd", feature: "rules", entry: "**/AGENTS.md" },
Expand Down Expand Up @@ -189,6 +188,7 @@ export const GITIGNORE_ENTRY_REGISTRY: ReadonlyArray<GitignoreEntryTag> = [
feature: "general",

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

**/.rovodev/AGENTS.md is tagged as feature: "general", but it’s the primary Rovodev rules output file (analogous to **/CLAUDE.md, **/GEMINI.md, etc. which are tagged as feature: "rules"). Because general entries are always included by filterGitignoreEntries, this makes it impossible to exclude Rovodev rules outputs when filtering by features. Consider tagging this entry as feature: "rules" for consistency and correct feature filtering behavior.

Suggested change
feature: "general",
feature: "rules",

Copilot uses AI. Check for mistakes.
entry: "**/.rovodev/AGENTS.md",
},
{ target: "rovodev", feature: "rules", entry: "**/AGENTS.local.md" },

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

The Rovodev target’s gitignore entries no longer cover the modular rules output directory (.rovodev/.rulesync/modular-rules/). Since RovodevRule.getSettablePaths() uses this location for non-root rules, generated modular rule files may now show up as unignored artifacts (previously masked by **/.rovodev/). Add an explicit ignore entry for .rovodev/.rulesync/modular-rules/ (likely under feature: "rules") and re-sync the generated .gitignore.

Suggested change
{ target: "rovodev", feature: "rules", entry: "**/AGENTS.local.md" },
{ target: "rovodev", feature: "rules", entry: "**/AGENTS.local.md" },
{
target: "rovodev",
feature: "rules",
entry: "**/.rovodev/.rulesync/modular-rules/",
},

Copilot uses AI. Check for mistakes.
{ target: "rovodev", feature: "subagents", entry: "**/.rovodev/subagents/" },
{ target: "rovodev", feature: "skills", entry: "**/.rovodev/skills/" },
{ target: "rovodev", feature: "skills", entry: "**/.agents/skills/" },
Expand Down
9 changes: 9 additions & 0 deletions src/features/rules/rovodev-rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ describe("RovodevRule", () => {
expect(RovodevRule.isAllowedModularRulesRelativePath("AGENTS.local.md")).toBe(false);
expect(RovodevRule.isAllowedModularRulesRelativePath(join("x", "AGENTS.md"))).toBe(false);
});

it("should reject reserved basenames case-insensitively", () => {
expect(RovodevRule.isAllowedModularRulesRelativePath("agents.md")).toBe(false);
expect(RovodevRule.isAllowedModularRulesRelativePath("Agents.md")).toBe(false);
expect(RovodevRule.isAllowedModularRulesRelativePath("AGENTS.MD")).toBe(false);
expect(RovodevRule.isAllowedModularRulesRelativePath("agents.local.md")).toBe(false);
expect(RovodevRule.isAllowedModularRulesRelativePath("Agents.Local.Md")).toBe(false);
expect(RovodevRule.isAllowedModularRulesRelativePath(join("x", "agents.md"))).toBe(false);
});
});

describe("round-trip", () => {
Expand Down
73 changes: 60 additions & 13 deletions src/features/rules/rovodev-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type RovodevRuleParams = AiFileParams & {
root?: boolean;
};

/** Basenames reserved for project memory; not modular rules under `.rovodev/.rulesync/modular-rules/`. */
const DISALLOWED_ROVODEV_MODULAR_RULE_BASENAMES = new Set(["AGENTS.md", "AGENTS.local.md"]);
/** Basenames reserved for project memory; not modular rules under `.rovodev/.rulesync/modular-rules/`. Lower-cased for case-insensitive comparison (macOS/Windows). */
const DISALLOWED_ROVODEV_MODULAR_RULE_BASENAMES = new Set(["agents.md", "agents.local.md"]);

/** Project paths; `nonRoot` is modular rules under `.rovodev/.rulesync/modular-rules/`. */
export type RovodevRuleSettablePaths = ToolRuleSettablePaths & {
Expand Down Expand Up @@ -53,7 +53,7 @@ export class RovodevRule extends ToolRule {
if (segment === "" || segment === "." || segment === "..") {
continue;
}
if (DISALLOWED_ROVODEV_MODULAR_RULE_BASENAMES.has(segment)) {
if (DISALLOWED_ROVODEV_MODULAR_RULE_BASENAMES.has(segment.toLowerCase())) {
return false;
Comment on lines 52 to 57

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

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

The new case-insensitive reserved-name check isn’t currently covered by tests: existing specs only assert rejection for "AGENTS.md" / "AGENTS.local.md" exact casing. Add test cases for mixed/lowercase variants (e.g., "agents.md", "Agents.Local.MD", and nested segments) to prevent regressions on case-insensitive filesystems.

Copilot uses AI. Check for mistakes.
}
}
Expand Down Expand Up @@ -107,23 +107,70 @@ export class RovodevRule extends ToolRule {
paths.nonRoot &&
overrideDirPath === paths.nonRoot.relativeDirPath
) {
if (!this.isAllowedModularRulesRelativePath(relativeFilePath)) {
throw new Error(
`Reserved Rovodev memory basename under modular-rules (not a modular rule): ${join(overrideDirPath, relativeFilePath)}`,
);
}
const fileContent = await readFileContent(join(baseDir, overrideDirPath, relativeFilePath));
return new RovodevRule({
return this.fromModularFile({
baseDir,
relativeDirPath: overrideDirPath,
relativeFilePath,
fileContent,
relativeDirPath: overrideDirPath,
validate,
global,
root: false,
});
}

return this.fromRootFile({
baseDir,
relativeFilePath,
overrideDirPath,
validate,
global,
paths,
});
}

private static async fromModularFile({
baseDir,
relativeFilePath,
relativeDirPath,
validate,
global,
}: {
baseDir: string;
relativeFilePath: string;
relativeDirPath: string;
validate: boolean;
global: boolean;
}): Promise<RovodevRule> {
if (!this.isAllowedModularRulesRelativePath(relativeFilePath)) {
throw new Error(
`Reserved Rovodev memory basename under modular-rules (not a modular rule): ${join(relativeDirPath, relativeFilePath)}`,
);
}
const fileContent = await readFileContent(join(baseDir, relativeDirPath, relativeFilePath));
return new RovodevRule({
baseDir,
relativeDirPath,
relativeFilePath,
fileContent,
validate,
global,
root: false,
});
}

private static async fromRootFile({
baseDir,
relativeFilePath,
overrideDirPath,
validate,
global,
paths,
}: {
baseDir: string;
relativeFilePath: string;
overrideDirPath: string | undefined;
validate: boolean;
global: boolean;
paths: RovodevRuleSettablePaths | ToolRuleSettablePathsGlobal;
}): Promise<RovodevRule> {
const relativeDirPath = overrideDirPath ?? paths.root.relativeDirPath;

const agentsMdExpectedLocationsDescription =
Expand Down
125 changes: 46 additions & 79 deletions src/features/rules/rules-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,40 @@ export class RulesProcessor extends FeatureProcessor {
return dirName === "" ? "." : dirName;
};

/**
* Build deletion rules from discovered file paths: resolve dir, check traversal, create forDeletion, filter isDeletable.
*
* Two modes:
* - **Root mode** (no opts): `relativeFilePath` = `basename(filePath)`, traversal checks `relativeDirPath` against `this.baseDir`.
* - **Non-root mode** (with `baseDirOverride` + `relativeDirPathOverride`): `relativeFilePath` = `relative(baseDirOverride, filePath)`,
* traversal checks `relativeFilePath` against `baseDirOverride`.
*/
const buildDeletionRulesFromPaths = (
filePaths: string[],
opts?: { baseDirOverride: string; relativeDirPathOverride: string },
): ToolRule[] => {
const effectiveBaseDir = opts?.baseDirOverride ?? this.baseDir;
return filePaths
.map((filePath) => {
const relativeDirPath =
opts?.relativeDirPathOverride ?? resolveRelativeDirPath(filePath);
const relativeFilePath = opts?.baseDirOverride
? relative(effectiveBaseDir, filePath)
: basename(filePath);

Copilot AI Mar 30, 2026

Copy link

Choose a reason for hiding this comment

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

buildDeletionRulesFromPaths allows baseDirOverride without requiring relativeDirPathOverride, but in that case relativeDirPath still comes from resolveRelativeDirPath(filePath) (which is based on this.baseDir). That can produce an incorrect deletion path (duplicated subdirs) if a future call site passes only baseDirOverride. Consider either (a) computing relativeDirPath relative to effectiveBaseDir when baseDirOverride is set, or (b) asserting/enforcing that relativeDirPathOverride must be provided whenever baseDirOverride is used.

Copilot uses AI. Check for mistakes.
checkPathTraversal({
relativePath: opts?.baseDirOverride ? relativeFilePath : relativeDirPath,
intendedRootDir: effectiveBaseDir,
});
return factory.class.forDeletion({
baseDir: this.baseDir,
relativeDirPath,
relativeFilePath,
global: this.global,
});
})
.filter((rule) => rule.isDeletable());
};

const findFilesWithFallback = async (
primaryGlob: string,
alternativeRoots: typeof settablePaths.alternativeRoots,
Expand Down Expand Up @@ -957,21 +991,7 @@ export class RulesProcessor extends FeatureProcessor {
);

if (forDeletion) {
return uniqueRootFilePaths
.map((filePath) => {
const relativeDirPath = resolveRelativeDirPath(filePath);
checkPathTraversal({
relativePath: relativeDirPath,
intendedRootDir: this.baseDir,
});
return factory.class.forDeletion({
baseDir: this.baseDir,
relativeDirPath,
relativeFilePath: basename(filePath),
global: this.global,
});
})
.filter((rule) => rule.isDeletable());
return buildDeletionRulesFromPaths(uniqueRootFilePaths);
}

return await Promise.all(
Expand Down Expand Up @@ -1005,21 +1025,7 @@ export class RulesProcessor extends FeatureProcessor {
const uniqueLocalRootFilePaths = await findFilesByGlobs(
join(this.baseDir, "AGENTS.local.md"),
);
return uniqueLocalRootFilePaths
.map((filePath) => {
const relativeDirPath = resolveRelativeDirPath(filePath);
checkPathTraversal({
relativePath: relativeDirPath,
intendedRootDir: this.baseDir,
});
return factory.class.forDeletion({
baseDir: this.baseDir,
relativeDirPath,
relativeFilePath: basename(filePath),
global: this.global,
});
})
.filter((rule) => rule.isDeletable());
return buildDeletionRulesFromPaths(uniqueLocalRootFilePaths);
}

if (this.toolTarget !== "claudecode" && this.toolTarget !== "claudecode-legacy") {
Expand All @@ -1036,21 +1042,7 @@ export class RulesProcessor extends FeatureProcessor {
(alt) => join(this.baseDir, alt.relativeDirPath, "CLAUDE.local.md"),
);

return uniqueLocalRootFilePaths
.map((filePath) => {
const relativeDirPath = resolveRelativeDirPath(filePath);
checkPathTraversal({
relativePath: relativeDirPath,
intendedRootDir: this.baseDir,
});
return factory.class.forDeletion({
baseDir: this.baseDir,
relativeDirPath,
relativeFilePath: basename(filePath),
global: this.global,
});
})
.filter((rule) => rule.isDeletable());
return buildDeletionRulesFromPaths(uniqueLocalRootFilePaths);
})();
this.logger.debug(
`Found ${localRootToolRules.length} local root tool rule files for deletion`,
Expand All @@ -1065,21 +1057,7 @@ export class RulesProcessor extends FeatureProcessor {
return [];
}
const mirrorPaths = await findFilesByGlobs(join(this.baseDir, "AGENTS.md"));
return mirrorPaths
.map((filePath) => {
const relativeDirPath = resolveRelativeDirPath(filePath);
checkPathTraversal({
relativePath: relativeDirPath,
intendedRootDir: this.baseDir,
});
return factory.class.forDeletion({
baseDir: this.baseDir,
relativeDirPath,
relativeFilePath: basename(filePath),
global: this.global,
});
})
.filter((rule) => rule.isDeletable());
return buildDeletionRulesFromPaths(mirrorPaths);
})();

const nonRootToolRules = await (async () => {
Expand All @@ -1092,9 +1070,16 @@ export class RulesProcessor extends FeatureProcessor {
join(nonRootBaseDir, "**", `*.${factory.meta.extension}`),
);

if (forDeletion) {
return buildDeletionRulesFromPaths(nonRootFilePaths, {
baseDirOverride: nonRootBaseDir,
relativeDirPathOverride: settablePaths.nonRoot.relativeDirPath,
});
}

const modularRootRelative = settablePaths.nonRoot.relativeDirPath;
const nonRootPathsForImport =
!forDeletion && this.toolTarget === "rovodev"
this.toolTarget === "rovodev"
? nonRootFilePaths.filter((filePath) => {
const relativeFilePath = relative(nonRootBaseDir, filePath);
const ok = RovodevRule.isAllowedModularRulesRelativePath(relativeFilePath);
Expand All @@ -1107,24 +1092,6 @@ export class RulesProcessor extends FeatureProcessor {
})
: nonRootFilePaths;

if (forDeletion) {
return nonRootFilePaths
.map((filePath) => {
const relativeFilePath = relative(nonRootBaseDir, filePath);
checkPathTraversal({
relativePath: relativeFilePath,
intendedRootDir: nonRootBaseDir,
});
return factory.class.forDeletion({
baseDir: this.baseDir,
relativeDirPath: settablePaths.nonRoot?.relativeDirPath ?? ".",
relativeFilePath,
global: this.global,
});
})
.filter((rule) => rule.isDeletable());
}

return await Promise.all(
nonRootPathsForImport.map((filePath) => {
const relativeFilePath = relative(nonRootBaseDir, filePath);
Expand Down
Loading