rules-merge
Merges rules-extract output from multiple projects into a unified portable rule set. Promotes .local.md patterns shared across a threshold of projects to Principles format. Use when consolidating org-wide rules after running rules-extract on 2+ repositories, merging coding standards across projects, or promoting shared patterns to portable Principles.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- rules-merge
- description
- Merges rules-extract output from multiple projects into a unified portable rule set. Promotes .local.md patterns shared across a threshold of projects to Principles format. Use when consolidating org-wide rules after running rules-extract on 2+ repositories, merging coding standards across projects, or promoting shared patterns to portable Principles.
- allowed-tools
- Read Glob Grep Write Bash(ls:*) Bash(mkdir:*) Bash(wc:*)
02 资源文件 4
- 参考文档references/config-schema.md564 B
- 参考文档references/output-formats.md990 B
- 参考文档references/promotion-algorithm.md3.0 KB
- 参考文档references/report-format.md1.2 KB
03 SKILL.md 正文
Merge Rules
Merges .Codex/rules/ from multiple projects into a unified portable rule set (.md + .examples.md). Promotes .local.md patterns that appear across a threshold of projects by converting them to Principles format. Merges .examples.md files alongside rule files.
Quick Start
- Run
rules-extracton each source project first (2+ required) - Create config —
.Codex/rules-merge.local.mdwith at minimum aprojects:list (seereferences/config-schema.md) - Dry run —
/rules-merge --dry-runto preview merges and promotions before writing - Merge —
/rules-mergeto write output tooutput_dir - Review report — check Merge Results, Promoted to Principles, and Below Threshold sections
/rules-merge # Merge using config file
/rules-merge --config <path> # Merge using specified config file
/rules-merge --dry-run # Show what would be merged without writing
When to Use
- Consolidating coding standards across 2+ repositories into one portable rule set
- After running
rules-extracton multiple projects and wanting to promote shared patterns - Producing org-wide
.Codex/rules/output for use withrules-apply - Merging rule updates from new projects into an existing org rule set
When NOT to Use
- Single-project rule extraction → use
rules-extractinstead - Applying merged org rules to a project → use
rules-applyinstead - Editing merged rules manually → edit the output file directly
- First-time rule extraction → run
rules-extractper project first
Configuration
Config file search order:
--config <path>argument.Codex/rules-merge.local.md(project-level)~/.Codex/rules-merge.local.md(user-level)
File format: YAML frontmatter only (no markdown body), same convention as rules-extract.local.md.
Key fields: projects (required, 2+ paths), output_dir (default: .Codex/rules/), rules_dir (default: .Codex/rules/), promote_threshold (default: 0.5), language (default: en)
See references/config-schema.md for the full annotated config template.
Processing Flow
Step 1: Load Configuration
- Search for config file (see search order above)
- If not found: Error "No config file found. Create
.Codex/rules-merge.local.mdor specify with--config."
- If not found: Error "No config file found. Create
- Parse YAML frontmatter, apply defaults for omitted fields
languageresolution order: Skill config → Codex settings (~/.Codex/settings.json→languagefield) → defaulten
- Validate:
projectsmust have at least 2 entries- Each project path must exist and contain
rules_dir - Error with clear message if validation fails
Step 2: Collect Rule Files
For each project:
- Find all
.md,.local.md, and.examples.mdfiles under{path}/{rules_dir}/(recursive) - Categorize:
languages/*.md→ portable principles (always merge). If the file also contains## Project-specific patterns(hybrid format fromsplit_output: false), treat patterns as promotion candidates (same as.local.md)frameworks/*.md→ same as aboveintegrations/*.md→ same as abovelanguages/*.local.md→ promotion candidateframeworks/*.local.md→ promotion candidateintegrations/*.local.md→ promotion candidatelanguages/*.examples.md→ example file (merge with rules)frameworks/*.examples.md→ example file (merge with rules)integrations/*.examples.md→ example file (merge with rules)project.md→ skip (inherently project-specific)project.examples.md→ skip (inherently project-specific)
- Parse each file: extract YAML frontmatter (
paths:) and body sections (## Principles,## Project-specific patterns,## Principles Examples,## Project-specific Examples)
Step 3: Normalize Similar File Names
Before merging, group files that refer to the same concept but have different names. This applies to .md, .local.md, and .examples.md files — a .md and its corresponding .local.md and .examples.md share the same normalization.
- Detect similar file names within the same directory (e.g.,
rails-controller.mdvsrails-controllers.md)- Singular/plural variants (e.g.,
controller/controllers) - Minor naming differences for the same concept (use AI judgment based on file content and
paths:frontmatter overlap)
- Singular/plural variants (e.g.,
- For each group, select a canonical name:
- Prefer the name used by the majority of projects
- If tied, prefer the name matching rules-extract's layered framework convention (e.g.,
<framework>-<layer>)
- Treat grouped files as the same file for subsequent merge steps
- Report normalized groups in the summary (e.g., "
rails-controller.md+rails-controllers.md→rails-controllers.md")
Step 4: Merge Portable Rules (.md)
Design note: Once a pattern is promoted to a Principle (via Step 5), it becomes a permanent org-level rule. To demote or remove a promoted Principle, manually edit the org rules output.
For each unique (normalized) file name across projects:
- Collect all versions from projects that have this file (including normalized variants)
- Merge
## Principlessections:- Deduplicate by principle name (text before parenthetical hints)
- Union hints from all projects for the same principle
- If same principle name but clearly different meaning → keep both, flag in report (see Conflict Handling)
- Preserve unique principles from any project
- Merge
paths:frontmatter: union of all path patterns, deduplicate - If file exists in only 1 project, include as-is
Steps 5 + 5.5: Promote Patterns and Merge Examples
Scan .local.md files (and hybrid .md files) for patterns appearing in enough projects to meet promote_threshold. Promoted patterns are converted from signature format to Principles format and appended to the corresponding .md output. .examples.md files are merged in parallel, with examples for promoted patterns moved to ## Principles Examples.
See references/promotion-algorithm.md for the full algorithm: semantic equivalence rules, threshold calculation, deduplication logic, and examples file merging.
Step 6: Write Output
- 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, then use
AskUserQuestion— question: "Output directory already has files. Overwrite?", options: "Overwrite" / "Cancel" — before overwriting - If not exists: create with
mkdir -p
- If
- Write merged files preserving directory structure:
languages/<lang>.md/languages/<lang>.examples.mdframeworks/<framework>.md/frameworks/<framework>.examples.mdintegrations/<framework>-<integration>.md/integrations/<framework>-<integration>.examples.md- Only
.mdand.examples.mdfiles (no.local.mdin output)
See references/output-formats.md for the output file format.
Step 7: Report Summary
Display report using the project's directory name (last path component) as label. Report headers are always in English.
See references/report-format.md for an annotated report example.
Conflict Handling
- Same principle, different hints: Union all hints, deduplicate
- Same principle name, different meaning: Keep both, flag in report for human review
- Same category, different paths: Union all path patterns
- Contradicting principles: Keep both, report as conflict for human review
Testing & Validation
After running rules-merge:
- Dry run first — run with
--dry-runto verify file list and promotion counts before writing - Promoted count — verify promoted pattern count matches expectations for patterns exceeding the threshold
- No
.local.mdin output — confirm the output directory contains only.mdand.examples.mdfiles - Examples pointers — every
.mdwith a sibling.examples.mdmust end with## Examples - Conflict review — review any flagged conflicts in the report before committing output
Quality gates:
- [ ] Report shows expected sources and file counts
- [ ] Promoted patterns are correct (run on known test data first if unsure)
- [ ] No unexpected conflicts
- [ ] Output directory contains no
.local.mdfiles - [ ] Dry run matches live run file list
Reference Guide
| Resource | Purpose |
|---|---|
references/config-schema.md |
Full annotated config file format |
references/promotion-algorithm.md |
Steps 5 and 5.5 — promotion algorithm and examples merging detail |
references/output-formats.md |
Output file format (.md and .examples.md structures) |
references/report-format.md |
Annotated sample report showing all output sections |
04 同仓库更多 Skills
demo
Fixture skill used by scripts.marketplace_ci sync tests.
export-demo
Fixture skill used by scripts.marketplace_ci export tests.
work-to-development
Validate an accepted Linear Issue's readiness for implementation (criteria, dependencies, duplicate/existing artifacts) and request governed branch/worktree creation through git-kit:starting-work — recording work-started Git/GitHub evidence and a deliberate Linear Started transition only after Git identity is read back and verified. Use when asked to start work on a Linear issue, begin development for an accepted issue, or prepare an accepted issue for implementation. Never creates a branch directly — always delegates to git-kit.
work-linking
Create and maintain stable cross-system links and authority labels between Notion and Linear records, and detect/repair drift between them. Use when asked to link a Notion record to a Linear record, check for drift between Notion and Linear, or repair a broken/stale link. Repairs only the bounded non-authoritative copy or link — never chooses by newest timestamp, and never creates a reverse-write loop against either system's own authority.
status-and-learning
Produce a dated, explicitly non-live Linear-to-Notion progress summary, or capture an outcome/learning after work completes. Use when asked to summarize progress to Notion, report portfolio status, or capture what was learned from a completed piece of work — not to disposition open follow-up items (see open-item-management for that). Never runs automatically or continuously — every summary is a deliberate, approved snapshot, not a live sync.
repository-gates
Discover, delegate, record, and invalidate this repository's actual Git/GitHub lifecycle gates (pre-commit, pre-push, PR required checks, Codex delta review, review requirements, merge rights) and the repository-policy provider profile that maps governed operations to git-kit. Use when asked what gates apply to this repository, to discover repository policy before starting Wave 2 work, or to check whether prior gate evidence is still valid after new commits. Discovery and delegation only — never executes a gate's own internal logic, and never invents a gate the repository doesn't actually define (in particular, never assumes a "Review Changes" gate exists).