Skip to content

Commit 9b227dc

Browse files
committed
Updated refactor.md
1 parent 39c35c0 commit 9b227dc

3 files changed

Lines changed: 134 additions & 2 deletions

File tree

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,19 @@ Boost automatically discovers skills from `vendor/codebar-ag/coding-guidelines/r
5656

5757
If your editor supports MCP (Model Context Protocol), configure it to use the Boost MCP server for full context. See the [Laravel Boost documentation](https://laravel.com/docs/boost) for your editor's setup.
5858

59-
### Step 5: Override skills locally (optional)
59+
### Step 5: Refactor command (Cursor)
60+
61+
To run a full codebase refactor against all guidelines:
62+
63+
1. Ensure `.cursor/commands/` exists in your project
64+
2. Copy the refactor prompt:
65+
- From package: `cp vendor/codebar-ag/coding-guidelines/refactor.md .cursor/commands/refactor.md`
66+
- Or from guidelines (if synced): `cp guidelines/refactor.md .cursor/commands/refactor.md`
67+
3. In Cursor, type `/refactor` and run the command
68+
69+
The prompt instructs the AI to discover all skills, map them to your codebase, analyze for violations, and refactor for full compliance. Use it when newly adopting guidelines or to cross-check AI implementations.
70+
71+
### Step 6: Override skills locally (optional)
6072

6173
To customize a skill for your project, create a file at `.ai/skills/{skill-name}/SKILL.md`. Your local version takes precedence over the package default.
6274

@@ -80,7 +92,7 @@ To sync the complete guidelines repo (`.github/prompts`, `RULES.md`, etc.) into
8092
}
8193
```
8294

83-
Then run `composer sync-guidelines`. This clones or pulls the repo into `guidelines/` at your project root.
95+
Then run `composer sync-guidelines`. This clones or pulls the repo into `guidelines/` at your project root and copies `refactor.md` to `.cursor/commands/refactor.md` for use with Cursor slash commands.
8496

8597
---
8698

refactor.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Codebase Refactor — Full Guidelines Compliance
2+
3+
You are refactoring a Laravel codebase to achieve 100% alignment with **codebar-ag coding guidelines**. This prompt is used when (a) newly adopting guidelines in an existing project, or (b) cross-checking AI-generated implementations for compliance.
4+
5+
---
6+
7+
## 1. Skill Discovery
8+
9+
Locate skills from one of these paths (check in order; first existing wins):
10+
11+
- `vendor/codebar-ag/coding-guidelines/resources/boost/skills/`
12+
- `guidelines/resources/boost/skills/`
13+
14+
Project overrides in `.ai/skills/{skill-name}/SKILL.md` take precedence over package defaults.
15+
16+
**Action:** List all `SKILL.md` files. For each skill, extract:
17+
18+
- `name` (from frontmatter or folder)
19+
- `Tags` — the first path-like value (e.g. `app/Models/**/*.php`) is the glob for file discovery
20+
- `Rules`, `Anti-Patterns`, `Examples` — apply these when analyzing and refactoring
21+
22+
---
23+
24+
## 2. Processing Order (Dependency-Aware)
25+
26+
Process skills in this order to avoid repeated edits and respect dependencies:
27+
28+
| Phase | Skills |
29+
|-------|--------|
30+
| Foundation | `general`, `php`, `helperfunctions` |
31+
| Data layer | `migrations`, `enums`, `models`, `traits` |
32+
| Backend core | `actions`, `services`, `dto`, `exceptions`, `interfaces` |
33+
| HTTP layer | `formrequests`, `controllers`, `middleware`, `requests`, `resources`, `routing` |
34+
| Infrastructure | `commands`, `jobs`, `events`, `observers`, `policies` |
35+
| Frontend | `blade`, `design`, `livewire`, `tailwind`, `translations` |
36+
| Integrations | `saloon`, `docuware`, `albatros` (only if matching files exist) |
37+
| Helpers | `helpers` |
38+
| Testing | `phpunit`, `pesttesting`, `phpstan`, `dusk` |
39+
40+
---
41+
42+
## 3. Per-Skill Workflow
43+
44+
For each skill in order:
45+
46+
1. **Match files** — Find all files in the workspace that match the skill’s glob patterns from Tags (e.g. `app/Http/Controllers/**/*.php`).
47+
2. **Skip if empty** — If no files match (e.g. no Albatros service), skip the skill.
48+
3. **Read skill** — Load the full `SKILL.md` content for Rules, Examples, and Anti-Patterns.
49+
4. **Analyze** — Check each matching file against the Rules and Anti-Patterns.
50+
5. **Refactor** — Fix violations using the skill’s Examples. Preserve behavior; do not introduce breaking changes.
51+
6. **Batch edits** — Group edits by skill (e.g. all controller fixes in one pass).
52+
53+
---
54+
55+
## 4. Efficiency Directives
56+
57+
- **Incremental changes** — Prefer small, reviewable edits over large rewrites.
58+
- **Prioritize when large** — If the scope is large, produce a prioritized compliance report and refactor in phases.
59+
- **Cross-check mode** — When validating recent AI work, focus first on recently changed files, then broaden if needed.
60+
- **Avoid redundant passes** — Process skills in the defined order so earlier fixes are not undone by later ones.
61+
62+
---
63+
64+
## 5. Output Format
65+
66+
### Phase A: Compliance Report (before edits)
67+
68+
Produce a concise report:
69+
70+
- Skills that apply (have matching files)
71+
- Skills that are skipped (no matching files)
72+
- Per skill: files with violations, brief description of each violation
73+
- Summary: total violations, suggested commit grouping
74+
75+
### Phase B: Refactoring (skill-by-skill)
76+
77+
For each skill with violations:
78+
79+
1. State the skill name and what is being fixed.
80+
2. Apply the changes.
81+
3. Suggest a commit message for that batch of changes.
82+
83+
---
84+
85+
## 6. Tags-to-Glob Mapping
86+
87+
Skills use Tags like:
88+
89+
```
90+
**Tags:** app/Models/**/*.php, laravel, php, backend, eloquent, model, database
91+
```
92+
93+
Use the **first path-like Tag** (e.g. `app/Models/**/*.php`, `database/migrations/**/*.php`, `resources/views/**/*.blade.php`) as the glob. Some skills have multiple paths (e.g. `app/Events/**/*.php`, `app/Listeners/**/*.php`); include all path-like Tags for that skill.
94+
95+
---
96+
97+
## 7. Non-Breaking Refactors Only
98+
99+
- Do not change observable behavior.
100+
- Do not remove or rename public APIs without explicit approval.
101+
- Prefer additive fixes (add missing types, FormRequests, transactions) over removals.
102+
- If a refactor is ambiguous or risky, report it and do not apply it automatically.
103+
104+
---
105+
106+
**Begin by discovering skills, then producing the compliance report, then executing refactors in the specified order.**

scripts/sync-guidelines.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,17 @@
2929
}
3030

3131
echo "Guidelines synced to {$targetDir}/.".PHP_EOL;
32+
33+
// Copy refactor.md to .cursor/commands/ for Cursor slash commands
34+
$refactorSource = __DIR__.'/../refactor.md';
35+
$commandsDir = '.cursor/commands';
36+
$refactorDest = $commandsDir.'/refactor.md';
37+
38+
if (file_exists($refactorSource)) {
39+
if (! is_dir($commandsDir)) {
40+
mkdir($commandsDir, 0755, true);
41+
}
42+
if (copy($refactorSource, $refactorDest)) {
43+
echo "Refactor command copied to {$refactorDest}.".PHP_EOL;
44+
}
45+
}

0 commit comments

Comments
 (0)