Repository navigation
refactor: address review findings from Rovodev PR #1377 #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e3c756e
4ebb5cd
48d7b39
85ba550
a89bdb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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" }, | ||||||||||||||||
|
|
@@ -189,6 +188,7 @@ export const GITIGNORE_ENTRY_REGISTRY: ReadonlyArray<GitignoreEntryTag> = [ | |||||||||||||||
| feature: "general", | ||||||||||||||||
| entry: "**/.rovodev/AGENTS.md", | ||||||||||||||||
| }, | ||||||||||||||||
| { target: "rovodev", feature: "rules", entry: "**/AGENTS.local.md" }, | ||||||||||||||||
|
||||||||||||||||
| { 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/", | |
| }, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 & { | ||
|
|
@@ -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
|
||
| } | ||
| } | ||
|
|
@@ -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 = | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
||
| 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, | ||
|
|
@@ -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( | ||
|
|
@@ -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") { | ||
|
|
@@ -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`, | ||
|
|
@@ -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 () => { | ||
|
|
@@ -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); | ||
|
|
@@ -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); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**/.rovodev/AGENTS.mdis tagged asfeature: "general", but it’s the primary Rovodev rules output file (analogous to**/CLAUDE.md,**/GEMINI.md, etc. which are tagged asfeature: "rules"). Becausegeneralentries are always included byfilterGitignoreEntries, this makes it impossible to exclude Rovodev rules outputs when filtering by features. Consider tagging this entry asfeature: "rules"for consistency and correct feature filtering behavior.