Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion ts/src/agents/pr_assistant/forbidden-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ 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("/");
const base = parts[parts.length - 1] ?? "";
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);
}

Expand Down
5 changes: 5 additions & 0 deletions ts/tests/forbidden-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading