diff --git a/ts/src/agents/pr_assistant/forbidden-paths.ts b/ts/src/agents/pr_assistant/forbidden-paths.ts index ca94fedf..24e401ca 100644 --- a/ts/src/agents/pr_assistant/forbidden-paths.ts +++ b/ts/src/agents/pr_assistant/forbidden-paths.ts @@ -7,7 +7,8 @@ import { isGenerated } from "./review-triage.ts"; const VENDOR_DIRS = new Set(["node_modules", "__pycache__", ".venv", "venv"]); const ENV_TEMPLATES = new Set([".env.example", ".env.sample", ".env.template", ".env.dist"]); // Agent instructions are owner policy: a fix once overwrote a public AGENTS.md with private instructions (radar-ofertas#23). -const AGENT_INSTRUCTIONS = new Set(["agents.md", "claude.md", "gemini.md", "copilot-instructions.md", ".cursorrules"]); +const AGENT_INSTRUCTIONS = new Set(["agents.md", "agent.md", "claude.md", "gemini.md", "copilot-instructions.md", ".cursorrules", ".windsurfrules", ".clinerules"]); +const AGENT_INSTRUCTION_DIRS = [".cursor/rules/", ".github/instructions/", ".clinerules/"]; export function isForbiddenPath(path: string): boolean { const parts = path.replace(/\\/g, "/").split("/"); @@ -15,6 +16,8 @@ export function isForbiddenPath(path: string): boolean { if (parts.some((p) => VENDOR_DIRS.has(p))) return true; if (/\.py[co]$/.test(base)) return true; if (AGENT_INSTRUCTIONS.has(base.toLowerCase())) return true; + const normalized = `/${parts.join("/").toLowerCase()}`; + if (AGENT_INSTRUCTION_DIRS.some((d) => normalized.includes(`/${d}`))) return true; return (base === ".env" || base.startsWith(".env.")) && !ENV_TEMPLATES.has(base); } diff --git a/ts/tests/forbidden-paths.test.ts b/ts/tests/forbidden-paths.test.ts index 7192cb4d..362b5fcb 100644 --- a/ts/tests/forbidden-paths.test.ts +++ b/ts/tests/forbidden-paths.test.ts @@ -18,6 +18,11 @@ test("isForbiddenPath flags agent instruction files in any folder or case", () = for (const p of ["AGENTS.md", "web/AGENTS.md", "CLAUDE.md", "docs/claude.md", "GEMINI.md", ".github/copilot-instructions.md", ".cursorrules"]) expect(isForbiddenPath(p)).toBe(true); for (const p of ["docs/agents.mdx", "src/agents.ts", "AGENTS.md.bak", "README.md"]) expect(isForbiddenPath(p)).toBe(false); }); +// Same policy for other agents' instruction files: AMP's AGENT.md, Windsurf/Cline rules, Cursor rules and Copilot path instructions. +test("isForbiddenPath flags other agents' instruction files and folders", () => { + for (const p of ["AGENT.md", "pkg/agent.md", ".windsurfrules", ".clinerules", ".clinerules/style.md", ".cursor/rules/ts.mdc", "web/.cursor/rules/a.mdc", ".github/instructions/ts.instructions.md"]) expect(isForbiddenPath(p)).toBe(true); + for (const p of [".cursor/mcp.json", ".github/workflows/ci.yml", "docs/instructions/setup.md", "src/rules/a.ts"]) expect(isForbiddenPath(p)).toBe(false); +}); test("validateChanges rejects a fix that rewrites AGENTS.md", async () => { const [ok, reason] = await validateChanges(tmp(), ["src/a.ts", "AGENTS.md"]); expect(ok).toBe(false);