Loading...
Loading...
Merge extract-rules output from multiple projects into a unified portable rule set. Promotes .local.md patterns shared across projects to Principles format.
npx skill4agent add hiroro-work/claude-plugins merge-rules.claude/rules/.local.md.examples.md/merge-rules # Merge using config file
/merge-rules --config <path> # Merge using specified config file
/merge-rules --dry-run # Show what would be merged without writing--config <path>.claude/merge-rules.local.md~/.claude/merge-rules.local.mdextract-rules.local.md---
# Source projects (each must have extract-rules output)
projects:
- ~/projects/frontend-app
- ~/projects/backend-api
- ~/projects/shared-lib
# Output directory (default: .claude/rules/)
output_dir: .claude/rules/
# Rules directory within each project (default: .claude/rules/)
# Corresponds to extract-rules' output_dir setting
rules_dir: .claude/rules/
# Threshold for promoting .local.md patterns (default: 0.5 = majority)
# Examples: 3 projects → 2/3 needed, 4 projects → 3/4, 5 projects → 3/5
promote_threshold: 0.5
# Report language (default: ja)
language: ja
---.claude/merge-rules.local.md--configlanguage~/.claude/settings.jsonlanguagejaprojectsrules_dir.md.local.md.examples.md{path}/{rules_dir}/languages/*.md## Project-specific patternssplit_output: false.local.mdframeworks/*.mdintegrations/*.mdlanguages/*.local.mdframeworks/*.local.mdintegrations/*.local.mdlanguages/*.examples.mdframeworks/*.examples.mdintegrations/*.examples.mdproject.mdproject.examples.mdpaths:## Principles## Project-specific patterns## Principles Examples## Project-specific Examples.md.local.md.examples.md.md.local.md.examples.mdrails-controller.mdrails-controller.local.mdrails-controller.examples.mdrails-controllers.*rails-controller.mdrails-controllers.mdrails-model.mdrails-models.mdcontrollercontrollerspaths:<framework>-<layer>rails-controller.mdrails-controllers.mdrails-controllers.md.local.mdlanguages/typescript.mdintegrations/rails-inertia.md## Principlespaths:languages/typescriptframeworks/rails-controllersintegrations/rails-inertia## Project-specific patterns.local.md.md-.md.local.md-useAuth()useAuth() → { user, login, logout }len(projects) * promote_threshold## Principles.md`signature` - descriptionDescription (simplified signature)`useAuth() → { user, login, logout }` - auth hook interfaceAuth hook interface (useAuth)`clean_bracket_params(:keyword)` - WAF付加のブラケット除去WAF付加のブラケット除去 (clean_bracket_params)`RefOrNull<T extends { id: string }> = T | { id: null }` - nullable refsNullable refs (RefOrNull<T>).examples.md### FP only## Principles Examples######.examples.md# <Category> Rules - Examples
## Principles Examples
### <Principle name>
**Good:**
```<lang>
<example><example>
- `###` titles must match the corresponding rule name in the merged output `.md` file. Do not rephrase
- No `paths:` frontmatter (prevents auto-loading)
- If no examples exist for any merged rule, skip generating the `.examples.md` file
### Step 6: Write Output
1. Check output directory:
- If `--dry-run`: skip writing, show planned file list with contents summary, then go to Step 7
- If exists and has files: warn and ask for confirmation before overwriting
- If not exists: create with `mkdir -p`
2. Write merged files preserving directory structure:
- `languages/<lang>.md`
- `languages/<lang>.examples.md` (if examples exist)
- `frameworks/<framework>.md`
- `frameworks/<framework>.examples.md` (if examples exist)
- `integrations/<framework>-<integration>.md`
- `integrations/<framework>-<integration>.examples.md` (if examples exist)
- Only `.md` and `.examples.md` files (no `.local.md` in output)
3. Output file format:
```markdown
---
paths:
- "**/*.ts"
- "**/*.tsx"
---
# TypeScript Rules
## Principles
- Immutability (spread, map/filter/reduce, const)
- Type safety (strict mode, explicit annotations, no any)
- Auth hook interface (useAuth).md## Principles## Principles.examples.md## Examples
When in doubt: ./<name>.examples.md# Merge Rules Report
## Sources
- frontend-app (3 files)
- backend-api (2 files)
- shared-lib (4 files)
## File Name Normalization
- `rails-controller.md` + `rails-controllers.md` → `rails-controllers.md`
- `rails-model.md` + `rails-models.md` → `rails-models.md`
## Merge Results
| File | Sources | Principles | Promoted to Principles | Examples |
|------|---------|------------|------------------------|----------|
| languages/typescript.md | 3/3 | 5 | 2 | 7 |
| frameworks/react.md | 2/3 | 3 | 1 | 4 |
| integrations/rails-inertia.md | 2/3 | 2 | 0 | 2 |
**Principles** = total including promoted. **Examples** = total `###` entries in the output `.examples.md`.
## Promoted to Principles
- `useAuth()` → Auth hook interface (useAuth) - 3/3 projects
- `pathFor() + url()` → Path helpers (pathFor, url) - 2/3 projects
## Below Threshold (reference)
- `useCustomHook()` (typescript) - 1/3 (frontend-app only)
- `ApiClient.create()` (typescript) - 1/3 (backend-api only)
## Skipped
- project.md x3 (project-specific, skipped)