|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Generate claude/blender-rules.md from rules/*.mdc. |
| 2 | +"""Generate the Claude Code copies of rules/*.mdc. |
3 | 3 |
|
4 | | -Claude Code does not read Cursor .mdc rules. This writes a plain-markdown |
5 | | -summary (one section per rule: description, load scope, link to the full rule) |
6 | | -that a Claude Code user imports from their own CLAUDE.md with |
7 | | -``@path/to/Blender-Developer-Tools/claude/blender-rules.md``. |
| 4 | +Claude Code does not read Cursor .mdc rules. This writes the same plain-markdown |
| 5 | +summary (one section per rule: description, load scope, link to the full rule |
| 6 | +with its Wrong/Right examples) to two places: |
| 7 | +
|
| 8 | +- claude/skills/blender-rules/SKILL.md: a skill the plugin ships |
| 9 | + (.claude-plugin/plugin.json "skills"), so plugin users get the rules with no |
| 10 | + second clone; Claude loads it when writing or reviewing bpy code. |
| 11 | +- claude/blender-rules.md: for always-on use, imported from a project's |
| 12 | + CLAUDE.md with ``@path/to/Blender-Developer-Tools/claude/blender-rules.md``. |
| 13 | +
|
| 14 | +Links are absolute GitHub URLs so they open from an installed plugin, a |
| 15 | +checkout, or a CLAUDE.md import alike. |
8 | 16 |
|
9 | 17 | python scripts/build_claude_rules.py # rewrite the file |
10 | 18 | python scripts/build_claude_rules.py --check # exit 1 if it is stale (CI) |
|
18 | 26 |
|
19 | 27 | REPO = Path(__file__).resolve().parent.parent |
20 | 28 | OUT = REPO / "claude" / "blender-rules.md" |
| 29 | +SKILL_OUT = REPO / "claude" / "skills" / "blender-rules" / "SKILL.md" |
| 30 | +RULE_URL = "https://github.com/TMHSDigital/Blender-Developer-Tools/blob/main/rules/" |
| 31 | +SKILL_FRONT = """--- |
| 32 | +name: blender-rules |
| 33 | +description: Blender Python anti-pattern rules (bmesh leaks, bpy.ops in loops, deprecated context-copy overrides, bulk mesh writes, prop annotations and context guards, Extensions manifest, import scale, export modifiers, glTF/FBX axis RNA). Use when writing, reviewing or fixing any bpy / Blender add-on or script code. |
| 34 | +--- |
| 35 | +
|
| 36 | +""" |
21 | 37 |
|
22 | 38 |
|
23 | 39 | def parse(path: Path) -> tuple[str, list[str]]: |
@@ -50,24 +66,34 @@ def render() -> str: |
50 | 66 | "", |
51 | 67 | desc, |
52 | 68 | "", |
53 | | - f"Applies to: {', '.join(f'`{g}`' for g in globs) or 'n/a'}. Full rule: `rules/{path.name}`.", |
| 69 | + f"Applies to: {', '.join(f'`{g}`' for g in globs) or 'n/a'}. Full rule: [`rules/{path.name}`]({RULE_URL}{path.name}).", |
54 | 70 | "", |
55 | 71 | ] |
56 | 72 | return "\n".join(lines).rstrip("\n") + "\n" |
57 | 73 |
|
58 | 74 |
|
| 75 | +def outputs() -> dict[Path, str]: |
| 76 | + body = render() |
| 77 | + return {OUT: body, SKILL_OUT: SKILL_FRONT + body} |
| 78 | + |
| 79 | + |
59 | 80 | def main() -> int: |
60 | | - new = render() |
61 | 81 | if "--check" in sys.argv: |
62 | | - old = OUT.read_text(encoding="utf-8").replace("\r\n", "\n") if OUT.exists() else "" |
63 | | - if old != new: |
64 | | - print("claude/blender-rules.md is stale; run python scripts/build_claude_rules.py", file=sys.stderr) |
| 82 | + stale = [] |
| 83 | + for path, new in outputs().items(): |
| 84 | + old = path.read_text(encoding="utf-8").replace("\r\n", "\n") if path.exists() else "" |
| 85 | + if old != new: |
| 86 | + stale.append(path.relative_to(REPO).as_posix()) |
| 87 | + if stale: |
| 88 | + print(f"{', '.join(stale)} stale; run python scripts/build_claude_rules.py", |
| 89 | + file=sys.stderr) |
65 | 90 | return 1 |
66 | | - print("claude/blender-rules.md is up to date") |
| 91 | + print("claude/blender-rules.md and claude/skills/blender-rules/SKILL.md are up to date") |
67 | 92 | return 0 |
68 | | - OUT.parent.mkdir(exist_ok=True) |
69 | | - OUT.write_text(new, encoding="utf-8", newline="\n") |
70 | | - print(f"wrote {OUT.relative_to(REPO)}") |
| 93 | + for path, new in outputs().items(): |
| 94 | + path.parent.mkdir(parents=True, exist_ok=True) |
| 95 | + path.write_text(new, encoding="utf-8", newline="\n") |
| 96 | + print(f"wrote {path.relative_to(REPO)}") |
71 | 97 | return 0 |
72 | 98 |
|
73 | 99 |
|
|
0 commit comments