[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79QMX058QY5DJS6C8EJG2N2":3,"skill-same:01M79QMX058QY5DJS6C8EJG2N2":58},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":13,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M79QMX058QY5DJS6C8EJG2N2","rules-apply",null,"Apply organization-wide rules (from rules-merge output) to the current project. Use when syncing portable Principles from a shared rules repository, merging org rules into project rules, cleaning up promoted patterns from .local.md files, fixing non-conforming rule files, or propagating rules-merge output to a project. Detects tech stack, merges Principles, removes duplicate patterns, and ensures rules-extract\u002Frules-merge convention conformance.","AndreHahm\u002Fandres-cc-marketplace","AndreHahm","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F80748019?v=4","01M79N2VZJT9MAJ7K695C9VXQ4","01M79N2W06PFX8BSCQ592M8K8K",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fplugin-devkit\u002Fskills\u002Frules-apply\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: rules-apply\ndescription: >-\n  Apply organization-wide rules (from rules-merge output) to the current project.\n  Use when syncing portable Principles from a shared rules repository, merging org\n  rules into project rules, cleaning up promoted patterns from .local.md files,\n  fixing non-conforming rule files, or propagating rules-merge output to a project.\n  Detects tech stack, merges Principles, removes duplicate patterns, and ensures\n  rules-extract\u002Frules-merge convention conformance.\nallowed-tools: Read Glob Grep Write Bash(gh:*) Bash(mktemp:*) Bash(rm -rf *\u002Frules-apply-*) Bash(rm .claude\u002Frules\u002F**\u002F*.local.md)\n---\n\n# Apply Rules\n\nApplies organization-wide rules (produced by rules-merge) to the current project. Detects the project's tech stack, selects relevant rules, merges them with existing rules-extract output, cleans up promoted patterns from `.local.md` files, and ensures the final structure conforms to the rules-extract\u002Frules-merge convention.\n\n## Quick Start\n\n1. **Set up source** — pass a GitHub URL\u002Flocal path as argument, or create `.claude\u002Frules-apply.local.md` with a `source:` field\n2. **Run** — `\u002Frules-apply \u003Csource>` or `\u002Frules-apply` (uses config file); add `--dry-run` to preview first\n3. **Confirm tech stack** — review detected languages\u002Fframeworks; add `include:` overrides if anything is missing\n4. **Approve integrations** — respond to any prompts for undetected integration rules (all \u002F none \u002F by number)\n5. **Resolve conflicts** — for Principles that differ between org and project: adopt org \u002F keep project \u002F keep both\n6. **Confirm structure cleanup** — approve migration plan for any non-conforming files\n7. **Check report** — verify Applied Rules, Promoted Pattern Cleanup, and Skipped sections\n\n## When to Use\n\n- Syncing portable Principles from a shared rules repository into the current project\n- After `rules-merge` produces updated org rules that need propagating downstream\n- Cleaning up `.local.md` patterns that have been promoted to org-level Principles\n- Fixing non-conforming rule files to match the rules-extract\u002Frules-merge convention\n- Updating project rules when org conventions change\n\n## When NOT to Use\n\n- Creating new rules from scratch → use `rule-development` instead\n- Extracting project patterns into portable rules → use `rules-extract` instead\n- Merging rules across multiple projects into one org set → use `rules-merge` instead\n- Reviewing compliance of existing rules against a diff → use `rules-review` instead\n\n## Usage\n\n```text\n\u002Frules-apply \u003Csource>                  # Apply from GitHub URL or local path\n\u002Frules-apply                           # Apply using config file\n\u002Frules-apply --config \u003Cpath>           # Apply using specified config file\n\u002Frules-apply --dry-run                 # Show what would change without writing\n\u002Frules-apply --dry-run \u003Csource>        # Dry run with specified source\n```\n\n`\u003Csource>` points directly to the rules directory (rules-merge or rules-extract output):\n- GitHub: `https:\u002F\u002Fgithub.com\u002Forg\u002Frepo\u002Ftree\u002Fmain\u002F.claude\u002Frules`\n- Local: `~\u002Forg-rules\u002F.claude\u002Frules`\n\n## Configuration\n\nConfig file search order:\n1. `--config \u003Cpath>` argument\n2. `.claude\u002Frules-apply.local.md` (project-level)\n3. `~\u002F.claude\u002Frules-apply.local.md` (user-level)\n\n**File format:** YAML frontmatter only (no markdown body), same convention as `rules-extract.local.md` and `rules-merge.local.md`.\n\n**Key fields:** `source` (required), `output_dir` (default: `.claude\u002Frules\u002F`), `auto_detect` (default: `true`), `include`\u002F`exclude` (arrays), `language` (default: `en`)\n\nSee `references\u002Fconfig-template.md` for the full annotated config file.\n\nCLI argument `\u003Csource>` overrides the config's `source` field.\n\n## Processing Flow\n\n### Step 1: Load Configuration\n\n1. If CLI `\u003Csource>` argument provided, use it (overrides config `source`)\n2. Search for config file (see search order above)\n3. Parse YAML frontmatter, apply defaults for omitted fields\n   - **`language` resolution order:** Skill config → Claude Code settings (`~\u002F.claude\u002Fsettings.json` → `language` field) → default `en`\n4. Validate:\n   - `source` must be specified (via CLI argument or config file)\n   - If neither: Error \"No source specified. Provide a GitHub URL or local path as argument, or create `.claude\u002Frules-apply.local.md` with a `source:` field.\"\n\n### Step 2: Fetch Source Rules\n\n**If source is a local path:**\n\n1. Expand `~` and resolve to absolute path\n2. Verify directory exists and contains rule files (`.md`)\n3. Read directly from this location\n\n**If source is a GitHub URL:**\n\nParse URL to extract owner, repo, branch, and path:\n- `https:\u002F\u002Fgithub.com\u002F{owner}\u002F{repo}\u002Ftree\u002F{branch}\u002F{path}`\n- Example: `https:\u002F\u002Fgithub.com\u002Forg\u002Frepo\u002Ftree\u002Fmain\u002F.claude\u002Frules`\n  → owner: `org`, repo: `repo`, branch: `main`, path: `.claude\u002Frules`\n\n**Note on ambiguous refs:** Branch names may contain `\u002F` (e.g., `feature\u002Frules-v2`), and refs can also be tags or SHAs. Simple URL splitting cannot reliably separate ref from path. To handle this robustly:\n- Try resolving ref candidates from longest prefix first using `gh api repos\u002F{owner}\u002F{repo}\u002Fgit\u002Fref\u002F{candidate}`\n- Alternatively, the user can specify components separately in the config:\n  ```yaml\n  source_repo: org\u002Frepo\n  source_ref: feature\u002Frules-v2\n  source_path: .claude\u002Frules\n  ```\n  When these fields are present, they take precedence over URL parsing.\n- For the common case (branch = `main` or `master`), simple URL parsing works.\n\nFetch using `gh api`:\n\n1. Verify authentication: `gh auth status`\n2. Create temp directory: `mktemp -d -t rules-apply-XXXXXX`. Record the exact path `mktemp` returns — Step 8's cleanup deletes only this literal path, never a re-derived or pattern-matched one.\n3. List top-level directory contents:\n   ```\n   gh api repos\u002F{owner}\u002F{repo}\u002Fcontents\u002F{path}?ref={branch}\n   ```\n   For each entry with `type: \"dir\"`, recursively fetch subdirectory contents:\n   ```\n   gh api repos\u002F{owner}\u002F{repo}\u002Fcontents\u002F{path}\u002F{subdir}?ref={branch}\n   ```\n   This dynamically discovers all categories (not limited to `languages\u002F`, `frameworks\u002F`, `integrations\u002F`).\n4. For each `.md` file found, fetch content and decode:\n   ```\n   gh api repos\u002F{owner}\u002F{repo}\u002Fcontents\u002F{file_path}?ref={branch} --jq '.content | @base64d'\n   ```\n   Save to tmpdir preserving directory structure\n5. Temp dir is cleaned up in Step 8\n\n**Inventory source files:**\n- Glob for `**\u002F*.md` and `**\u002F*.examples.md` under the source rules directory\n- Skip `project.md` and `project.examples.md` (inherently project-specific)\n- Skip `.local.md` files (rules-merge output should not contain these, but handle gracefully)\n- Parse each file: extract YAML frontmatter (`paths:`) and body sections\n\n### Step 3: Detect Target Project Tech Stack\n\nAnalyze the current working directory to determine which source rules are relevant. Detection is best-effort, based on dependency files (e.g., `Gemfile`, `package.json`) and project directory structure (e.g., `app\u002Fcontrollers\u002F`).\n\nRead `references\u002Fdetection-heuristics.md` for the full detection table mapping indicators to rule files. If the source contains rule files not covered in the table, use AI judgment to match them against the project's dependencies and file structure.\n\n**Apply overrides:**\n- Add `include:` entries to the detected set\n- Remove `exclude:` entries from the detected set\n- If `auto_detect: false`: start with ALL source rules, then apply `exclude` only\n\n### Step 4: Filter and Propose\n\n**If `auto_detect: false`:** Apply ALL source rules (minus `exclude` entries). Skip the proposal step entirely — no integration proposals or skipped rules. Proceed directly to Step 5.\n\n**If `auto_detect: true` (default):**\n\n1. **Auto-matched rules**: Rules that match detected tech stack → apply automatically\n2. **Integration proposals**: For integrations NOT detected in the project but related to a detected framework (e.g., source has `integrations\u002Frails-pundit` but project doesn't use `pundit`), use `AskUserQuestion` to present them as a single list:\n\n   > The following integration rules are available in the source but were not detected in your project. Which would you like to apply?\n   > 1. `integrations\u002Frails-pundit` — Authorization library Pundit rules\n   > 2. `integrations\u002Frails-good-job` — Job queue GoodJob rules\n   >\n   > Options: all \u002F none \u002F specify by number (e.g. \"1\" or \"1,2\")\n\n   Apply only those the user approves.\n\n3. **Skipped rules**: Rules for tech not detected and not in related frameworks → skip, list in report\n\n### Step 5: Inventory Existing Target Rules\n\n1. Check if `{output_dir}\u002F` exists in the target project\n2. If exists, read all files: `.md`, `.local.md`, `.examples.md`\n3. Parse frontmatter and body sections for each\n4. Categorize files the same way as source files\n5. **Detect hybrid format**: If any target `.md` file contains `## Project-specific patterns` (hybrid format from rules-extract `split_output: false`), note this. The merge step will convert hybrid to split format because the split format (separate `.md` and `.local.md`) is the standard expected by both rules-extract and rules-merge, and mixing formats causes confusion when rules flow back through the pipeline. Note: source files from rules-merge should not contain `## Project-specific patterns` (promoted patterns are converted to Principles format)\n\n### Step 5.5: Normalize File Names\n\nBefore merging, align target file names with source (canonical) names. This prevents duplicate files for the same concept (e.g., `rails-controller.md` vs `rails-controllers.md`).\n\n1. Compare target file names against source file names within the same category\n2. Detect naming variants: singular\u002Fplural (`controller`\u002F`controllers`), minor differences for the same concept\n3. If renames are detected, use `AskUserQuestion` to confirm:\n   > The following target files will be renamed to match source (canonical) names:\n   > 1. `frameworks\u002Frails-controller.md` → `frameworks\u002Frails-controllers.md`\n   >\n   > Options: all \u002F none \u002F specify by number\n4. Apply approved renames and report in the summary\n\n### Step 6: Merge Rules\n\nFor each filtered source rule file, determine the merge action:\n\n**6a. Merge `.md` files (Principles):**\n\n**Case: No existing `.md`**\n1. Copy source `.md` as-is (source from rules-merge contains only `## Principles`)\n\n**Case: Existing `.md` exists**\n1. **`paths:` frontmatter**: Union of all path patterns, deduplicate\n2. **Hybrid → split conversion**: If existing `.md` contains `## Project-specific patterns` (hybrid format):\n   - Extract that section and move to `.local.md` (create if not exists, append if exists)\n   - Remove the section from `.md`, keeping only `## Principles`\n3. **`## Principles`**:\n   - Match principles by name (text before parenthetical hints)\n   - Source principle not in target → Add\n   - Target principle not in source → Keep (project may have added its own)\n   - Same principle, same meaning but different hints → Union hints from both\n   - Same principle name but different content → Collect all conflicts, then use `AskUserQuestion` to present them together:\n     > The following principles differ between org rules and project rules:\n     >\n     > **1. Immutability** (in `languages\u002Fruby.md`)\n     > - Org: `Immutability (spread, map\u002Ffilter\u002Freduce, const)`\n     > - Project: `Immutability (freeze, deep clone, readonly)`\n     >\n     > **2. Error handling** (in `frameworks\u002Frails.md`)\n     > - Org: `Error handling (rescue, custom exceptions)`\n     > - Project: `Error handling (rescue, retry, circuit breaker)`\n     >\n     > For each, choose: (a) Adopt org rule \u002F (b) Keep project rule \u002F (c) Keep both\n     > Example: \"1a, 2c\" or \"all a\"\n\n**6b. Clean up promoted patterns from `.local.md` files:**\n\n`.local.md` files contain project-specific patterns discovered by rules-extract. When org rules promote a pattern to a Principle, the original pattern in `.local.md` becomes redundant. rules-apply cleans up these duplicates while preserving genuinely project-specific patterns.\n\n- rules-apply does not write new patterns to `.local.md`\n- **Cross-format duplicate removal**: After merging Principles in Step 6a, scan target `.local.md` for patterns whose description matches a Principle name now present in the corresponding `.md` (e.g., `` `useAuth() → { user, login, logout }` - auth hook interface `` is a duplicate of `Auth hook interface (useAuth)` in `## Principles`). Use AI judgment for semantic equivalence (case-insensitive, synonyms)\n- Remove matched patterns from `.local.md`\n- If `.local.md` becomes empty after removal, use `AskUserQuestion` to confirm before deleting the file — present the full list of `.local.md` files this run would delete as a single list for confirmation, same pattern as Step 7's non-conforming-file migration: \"The following `.local.md` files are now empty after duplicate cleanup. Delete them?\" — options \"Delete all\" \u002F \"Keep all (leave as empty files)\" \u002F \"specify by number\". Never delete silently, even though the removed patterns were confirmed duplicates — the file itself is a real, separately-named artifact a user may still reference elsewhere.\n- Preserve all patterns that do not match any Principle (genuinely project-specific)\n- **Sync `paths:` frontmatter**: for any `.local.md` that still exists after cleanup, ensure its `paths:` frontmatter matches the sibling `.md`'s `paths:` (union and deduplicate with any existing entries on `.local.md`). This keeps project-specific patterns auto-loading under the same scope as the portable Principles. Older `.local.md` files generated before rules-extract propagated `paths:` to `.local.md` may be unscoped; this step retrofits the scope without requiring a full rules-extract re-run\n\n**6c. Merge `.examples.md` files:**\n\n**Case: No existing `.examples.md`**\n- Copy source `.examples.md` as-is (source from rules-merge contains only `## Principles Examples`)\n\n**Case: Existing `.examples.md` exists**\n1. **`## Principles Examples`**: Add examples from source for principles not already covered in target\n2. **`## Project-specific Examples`** (target only): Remove examples whose `###` title corresponds to patterns removed from `.local.md` in Step 6b. Preserve all other existing entries\n\n**6d. Ensure `## Examples` reference:**\n- Every `.md` and `.local.md` that still exists and has a corresponding `.examples.md` must end with:\n  ```markdown\n  ## Examples\n  When in doubt: .\u002F\u003Cname>.examples.md\n  ```\n- If a `.local.md` was deleted in Step 6b (became empty), no reference is needed\n\n### Step 7: Structure Conformance Check + Auto-cleanup\n\nScan `output_dir` for files that don't conform to rules-extract\u002Frules-merge convention:\n\n**Valid patterns:**\n- `{category}\u002F{name}.md`\n- `{category}\u002F{name}.local.md`\n- `{category}\u002F{name}.examples.md`\n- `project.md`\n- `project.examples.md`\n\n**Valid categories:** `languages\u002F`, `frameworks\u002F`, `integrations\u002F`\n\n**Non-conforming file handling:**\n1. Read the non-conforming file and analyze its content\n2. Determine the appropriate conforming file(s) to migrate rules into (based on category, content, and `paths:` hints)\n3. Use `AskUserQuestion` to present the migration plan as a single list for confirmation:\n   > The following non-conforming files were detected. Migrate their rules to conforming files and delete them?\n   > 1. `frameworks\u002Fold-custom-rules.md` → migrate to `frameworks\u002Frails.md`\n   > 2. `ruby-rules.md` → migrate to `languages\u002Fruby.md`\n   > 3. `project.rules.md` → migrate to `project.md` (**project file — confirm individually**)\n   >\n   > Options: all \u002F none \u002F specify by number (e.g. \"1,2\")\n   >\n   > Note: `project.*` files are excluded from \"all\". Specify them individually by number.\n4. User approval → merge rules into conforming file(s) and delete non-conforming files\n5. Report all migrations and deletions\n\n### Step 8: Cleanup\n\nIf source was a GitHub URL, remove the temp directory: `rm -rf \u003Ctmpdir>`, where `\u003Ctmpdir>` is the exact literal path `mktemp` returned in Step 2 — never a re-derived, globbed, or reconstructed path. The `allowed-tools` scope (`Bash(rm -rf *\u002Frules-apply-*)`) is a coarse pattern match, not a path-boundary guarantee, since it matches the `rules-apply-` prefix as text regardless of which directory it appears under — the actual safety boundary is this step using only the recorded Step 2 path, not the permission string alone.\n\n### Step 9: Report Summary\n\nDisplay report. Report headers are always in English, content in the configured `language`.\n\nSee `references\u002Freport-format.md` for an annotated report example.\n\n## Conflict Handling\n\nSummary of user-confirmation points and automatic actions:\n\n| Situation | Action |\n|-----------|--------|\n| Principle in source, not in target | Auto-add |\n| Principle in target, not in source | Auto-keep |\n| Same principle, different hints | Auto-union hints |\n| Same principle name, different content | **AskUserQuestion**: collect all conflicts, present together (adopt org \u002F keep project \u002F keep both) |\n| Non-conforming file detected | **AskUserQuestion**: present migration plan as single list for confirmation |\n| `project.*` non-conforming file | Excluded from \"all\" — must be specified individually by number |\n| Target file name differs from source canonical name | **AskUserQuestion**: confirm renames (all \u002F none \u002F specify) |\n| Undetected integration rule (related framework) | **AskUserQuestion**: present as single list for approval (all \u002F none \u002F specify) |\n| `.local.md` pattern matching a Principle | Auto-remove from `.local.md` (cross-format duplicate cleanup) |\n| `.local.md` pattern not matching any Principle | Preserved |\n| `## Project-specific Examples` for removed pattern | Auto-remove |\n| `## Project-specific Examples` for remaining pattern | Preserved |\n\n---\n\n## Testing & Validation\n\nAfter running rules-apply:\n\n1. **Applied rules** — each rule file in the report appears at the correct path in `output_dir`\n2. **Promoted cleanup** — patterns removed from `.local.md` match Principles now in the corresponding `.md`\n3. **Examples reference** — every `.md`\u002F`.local.md` with a sibling `.examples.md` ends with `## Examples`\n4. **No orphaned `.local.md`** — `.local.md` files that became empty were deleted\n5. **Dry run first** — run with `--dry-run` on unfamiliar sources to preview changes before writing\n\n**Quality gates:**\n- [ ] Report shows no unexpected skips (verify `auto_detect` and `include`\u002F`exclude` config)\n- [ ] Conflict resolutions recorded in report\n- [ ] Structure cleanup applied: no non-conforming files remain in `output_dir`\n- [ ] `paths:` frontmatter on `.local.md` matches sibling `.md` after sync\n- [ ] Temp directory cleaned up (no leftover dirs from GitHub fetch)\n\n---\n\n## Reference Guide\n\n| Resource | Purpose |\n|---|---|\n| `references\u002Fdetection-heuristics.md` | Tech stack detection table — maps dependency files and project structure to rule files |\n| `references\u002Fconfig-template.md` | Full annotated config file format for `rules-apply.local.md` |\n| `references\u002Freport-format.md` | Annotated sample report showing all output sections |\n","# Apply Rules\n\nApplies organization-wide rules (produced by rules-merge) to the current project. Detects the project's tech stack, selects relevant rules, merges them with existing rules-extract output, cleans up promoted patterns from `.local.md` files, and ensures the final structure conforms to the rules-extract\u002Frules-merge convention.\n\n## Quick Start\n\n1. **Set up source** — pass a GitHub URL\u002Flocal path as argument, or create `.claude\u002Frules-apply.local.md` with a `source:` field\n2. **Run** — `\u002Frules-apply \u003Csource>` or `\u002Frules-apply` (uses config file); add `--dry-run` to preview first\n3. **Confirm tech stack** — review detected languages\u002Fframeworks; add `include:` overrides if anything is missing\n4. **Approve integrations** — respond to any prompts for undetected integration rules (all \u002F none \u002F by number)\n5. **Resolve conflicts** — for Principles that differ between org and project: adopt org \u002F keep project \u002F keep both\n6. **Confirm structure cleanup** — approve migration plan for any non-conforming files\n7. **Check report** — verify Applied Rules, Promoted Pattern Cleanup, and Skipped sections\n\n## When to Use\n\n- Syncing portable Principles from a shared rules repository into the current project\n- After `rules-merge` produces updated org rules that need propagating downstream\n- Cleaning up `.local.md` patterns that have been promoted to org-level Principles\n- Fixing non-conforming rule files to match the rules-extract\u002Frules-merge convention\n- Updating project rules when org conventions change\n\n## When NOT to Use\n\n- Creating new rules from scratch → use `rule-development` instead\n- Extracting project patterns into portable rules → use `rules-extract` instead\n- Merging rules across multiple projects into one org set → use `rules-merge` instead\n- Reviewing compliance of existing rules against a diff → use `rules-review` instead\n\n## Usage\n\n```text\n\u002Frules-apply \u003Csource>                  # Apply from GitHub URL or local path\n\u002Frules-apply                           # Apply using config file\n\u002Frules-apply --config \u003Cpath>           # Apply using specified config file\n\u002Frules-apply --dry-run                 # Show what would change without writing\n\u002Frules-apply --dry-run \u003Csource>        # Dry run with specified source\n```\n\n`\u003Csource>` points directly to the rules directory (rules-merge or rules-extract output):\n- GitHub: `https:\u002F\u002Fgithub.com\u002Forg\u002Frepo\u002Ftree\u002Fmain\u002F.claude\u002Frules`\n- Local: `~\u002Forg-rules\u002F.claude\u002Frules`\n\n## Configuration\n\nConfig file search order:\n1. `--config \u003Cpath>` argument\n2. `.claude\u002Frules-apply.local.md` (project-level)\n3. `~\u002F.claude\u002Frules-apply.local.md` (user-level)\n\n**File format:** YAML frontmatter only (no markdown body), same convention as `rules-extract.local.md` and `rules-merge.local.md`.\n\n**Key fields:** `source` (required), `output_dir` (default: `.claude\u002Frules\u002F`), `auto_detect` (default: `true`), `include`\u002F`exclude` (arrays), `language` (default: `en`)\n\nSee `references\u002Fconfig-template.md` for the full annotated config file.\n\nCLI argument `\u003Csource>` overrides the config's `source` field.\n\n## Processing Flow\n\n### Step 1: Load Configuration\n\n1. If CLI `\u003Csource>` argument provided, use it (overrides config `source`)\n2. Search for config file (see search order above)\n3. Parse YAML frontmatter, apply defaults for omitted fields\n   - **`language` resolution order:** Skill config → Claude Code settings (`~\u002F.claude\u002Fsettings.json` → `language` field) → default `en`\n4. Validate:\n   - `source` must be specified (via CLI argument or config file)\n   - If neither: Error \"No source specified. Provide a GitHub URL or local path as argument, or create `.claude\u002Frules-apply.local.md` with a `source:` field.\"\n\n### Step 2: Fetch Source Rules\n\n**If source is a local path:**\n\n1. Expand `~` and resolve to absolute path\n2. Verify directory exists and contains rule files (`.md`)\n3. Read directly from this location\n\n**If source is a GitHub URL:**\n\nParse URL to extract owner, repo, branch, and path:\n- `https:\u002F\u002Fgithub.com\u002F{owner}\u002F{repo}\u002Ftree\u002F{branch}\u002F{path}`\n- Example: `https:\u002F\u002Fgithub.com\u002Forg\u002Frepo\u002Ftree\u002Fmain\u002F.claude\u002Frules`\n  → owner: `org`, repo: `repo`, branch: `main`, path: `.claude\u002Frules`\n\n**Note on ambiguous refs:** Branch names may contain `\u002F` (e.g., `feature\u002Frules-v2`), and refs can also be tags or SHAs. Simple URL splitting cannot reliably separate ref from path. To handle this robustly:\n- Try resolving ref candidates from longest prefix first using `gh api repos\u002F{owner}\u002F{repo}\u002Fgit\u002Fref\u002F{candidate}`\n- Alternatively, the user can specify components separately in the config:\n  ```yaml\n  source_repo: org\u002Frepo\n  source_ref: feature\u002Frules-v2\n  source_path: .claude\u002Frules\n  ```\n  When these fields are present, they take precedence over URL parsing.\n- For the common case (branch = `main` or `master`), simple URL parsing works.\n\nFetch using `gh api`:\n\n1. Verify authentication: `gh auth status`\n2. Create temp directory: `mktemp -d -t rules-apply-XXXXXX`. Record the exact path `mktemp` returns — Step 8's cleanup deletes only this literal path, never a re-derived or pattern-matched one.\n3. List top-level directory contents:\n   ```\n   gh api repos\u002F{owner}\u002F{repo}\u002Fcontents\u002F{path}?ref={branch}\n   ```\n   For each entry with `type: \"dir\"`, recursively fetch subdirectory contents:\n   ```\n   gh api repos\u002F{owner}\u002F{repo}\u002Fcontents\u002F{path}\u002F{subdir}?ref={branch}\n   ```\n   This dynamically discovers all categories (not limited to `languages\u002F`, `frameworks\u002F`, `integrations\u002F`).\n4. For each `.md` file found, fetch content and decode:\n   ```\n   gh api repos\u002F{owner}\u002F{repo}\u002Fcontents\u002F{file_path}?ref={branch} --jq '.content | @base64d'\n   ```\n   Save to tmpdir preserving directory structure\n5. Temp dir is cleaned up in Step 8\n\n**Inventory source files:**\n- Glob for `**\u002F*.md` and `**\u002F*.examples.md` under the source rules directory\n- Skip `project.md` and `project.examples.md` (inherently project-specific)\n- Skip `.local.md` files (rules-merge output should not contain these, but handle gracefully)\n- Parse each file: extract YAML frontmatter (`paths:`) and body sections\n\n### Step 3: Detect Target Project Tech Stack\n\nAnalyze the current working directory to determine which source rules are relevant. Detection is best-effort, based on dependency files (e.g., `Gemfile`, `package.json`) and project directory structure (e.g., `app\u002Fcontrollers\u002F`).\n\nRead `references\u002Fdetection-heuristics.md` for the full detection table mapping indicators to rule files. If the source contains rule files not covered in the table, use AI judgment to match them against the project's dependencies and file structure.\n\n**Apply overrides:**\n- Add `include:` entries to the detected set\n- Remove `exclude:` entries from the detected set\n- If `auto_detect: false`: start with ALL source rules, then apply `exclude` only\n\n### Step 4: Filter and Propose\n\n**If `auto_detect: false`:** Apply ALL source rules (minus `exclude` entries). Skip the proposal step entirely — no integration proposals or skipped rules. Proceed directly to Step 5.\n\n**If `auto_detect: true` (default):**\n\n1. **Auto-matched rules**: Rules that match detected tech stack → apply automatically\n2. **Integration proposals**: For integrations NOT detected in the project but related to a detected framework (e.g., source has `integrations\u002Frails-pundit` but project doesn't use `pundit`), use `AskUserQuestion` to present them as a single list:\n\n   > The following integration rules are available in the source but were not detected in your project. Which would you like to apply?\n   > 1. `integrations\u002Frails-pundit` — Authorization library Pundit rules\n   > 2. `integrations\u002Frails-good-job` — Job queue GoodJob rules\n   >\n   > Options: all \u002F none \u002F specify by number (e.g. \"1\" or \"1,2\")\n\n   Apply only those the user approves.\n\n3. **Skipped rules**: Rules for tech not detected and not in related frameworks → skip, list in report\n\n### Step 5: Inventory Existing Target Rules\n\n1. Check if `{output_dir}\u002F` exists in the target project\n2. If exists, read all files: `.md`, `.local.md`, `.examples.md`\n3. Parse frontmatter and body sections for each\n4. Categorize files the same way as source files\n5. **Detect hybrid format**: If any target `.md` file contains `## Project-specific patterns` (hybrid format from rules-extract `split_output: false`), note this. The merge step will convert hybrid to split format because the split format (separate `.md` and `.local.md`) is the standard expected by both rules-extract and rules-merge, and mixing formats causes confusion when rules flow back through the pipeline. Note: source files from rules-merge should not contain `## Project-specific patterns` (promoted patterns are converted to Principles format)\n\n### Step 5.5: Normalize File Names\n\nBefore merging, align target file names with source (canonical) names. This prevents duplicate files for the same concept (e.g., `rails-controller.md` vs `rails-controllers.md`).\n\n1. Compare target file names against source file names within the same category\n2. Detect naming variants: singular\u002Fplural (`controller`\u002F`controllers`), minor differences for the same concept\n3. If renames are detected, use `AskUserQuestion` to confirm:\n   > The following target files will be renamed to match source (canonical) names:\n   > 1. `frameworks\u002Frails-controller.md` → `frameworks\u002Frails-controllers.md`\n   >\n   > Options: all \u002F none \u002F specify by number\n4. Apply approved renames and report in the summary\n\n### Step 6: Merge Rules\n\nFor each filtered source rule file, determine the merge action:\n\n**6a. Merge `.md` files (Principles):**\n\n**Case: No existing `.md`**\n1. Copy source `.md` as-is (source from rules-merge contains only `## Principles`)\n\n**Case: Existing `.md` exists**\n1. **`paths:` frontmatter**: Union of all path patterns, deduplicate\n2. **Hybrid → split conversion**: If existing `.md` contains `## Project-specific patterns` (hybrid format):\n   - Extract that section and move to `.local.md` (create if not exists, append if exists)\n   - Remove the section from `.md`, keeping only `## Principles`\n3. **`## Principles`**:\n   - Match principles by name (text before parenthetical hints)\n   - Source principle not in target → Add\n   - Target principle not in source → Keep (project may have added its own)\n   - Same principle, same meaning but different hints → Union hints from both\n   - Same principle name but different content → Collect all conflicts, then use `AskUserQuestion` to present them together:\n     > The following principles differ between org rules and project rules:\n     >\n     > **1. Immutability** (in `languages\u002Fruby.md`)\n     > - Org: `Immutability (spread, map\u002Ffilter\u002Freduce, const)`\n     > - Project: `Immutability (freeze, deep clone, readonly)`\n     >\n     > **2. Error handling** (in `frameworks\u002Frails.md`)\n     > - Org: `Error handling (rescue, custom exceptions)`\n     > - Project: `Error handling (rescue, retry, circuit breaker)`\n     >\n     > For each, choose: (a) Adopt org rule \u002F (b) Keep project rule \u002F (c) Keep both\n     > Example: \"1a, 2c\" or \"all a\"\n\n**6b. Clean up promoted patterns from `.local.md` files:**\n\n`.local.md` files contain project-specific patterns discovered by rules-extract. When org rules promote a pattern to a Principle, the original pattern in `.local.md` becomes redundant. rules-apply cleans up these duplicates while preserving genuinely project-specific patterns.\n\n- rules-apply does not write new patterns to `.local.md`\n- **Cross-format duplicate removal**: After merging Principles in Step 6a, scan target `.local.md` for patterns whose description matches a Principle name now present in the corresponding `.md` (e.g., `` `useAuth() → { user, login, logout }` - auth hook interface `` is a duplicate of `Auth hook interface (useAuth)` in `## Principles`). Use AI judgment for semantic equivalence (case-insensitive, synonyms)\n- Remove matched patterns from `.local.md`\n- If `.local.md` becomes empty after removal, use `AskUserQuestion` to confirm before deleting the file — present the full list of `.local.md` files this run would delete as a single list for confirmation, same pattern as Step 7's non-conforming-file migration: \"The following `.local.md` files are now empty after duplicate cleanup. Delete them?\" — options \"Delete all\" \u002F \"Keep all (leave as empty files)\" \u002F \"specify by number\". Never delete silently, even though the removed patterns were confirmed duplicates — the file itself is a real, separately-named artifact a user may still reference elsewhere.\n- Preserve all patterns that do not match any Principle (genuinely project-specific)\n- **Sync `paths:` frontmatter**: for any `.local.md` that still exists after cleanup, ensure its `paths:` frontmatter matches the sibling `.md`'s `paths:` (union and deduplicate with any existing entries on `.local.md`). This keeps project-specific patterns auto-loading under the same scope as the portable Principles. Older `.local.md` files generated before rules-extract propagated `paths:` to `.local.md` may be unscoped; this step retrofits the scope without requiring a full rules-extract re-run\n\n**6c. Merge `.examples.md` files:**\n\n**Case: No existing `.examples.md`**\n- Copy source `.examples.md` as-is (source from rules-merge contains only `## Principles Examples`)\n\n**Case: Existing `.examples.md` exists**\n1. **`## Principles Examples`**: Add examples from source for principles not already covered in target\n2. **`## Project-specific Examples`** (target only): Remove examples whose `###` title corresponds to patterns removed from `.local.md` in Step 6b. Preserve all other existing entries\n\n**6d. Ensure `## Examples` reference:**\n- Every `.md` and `.local.md` that still exists and has a corresponding `.examples.md` must end with:\n  ```markdown\n  ## Examples\n  When in doubt: .\u002F\u003Cname>.examples.md\n  ```\n- If a `.local.md` was deleted in Step 6b (became empty), no reference is needed\n\n### Step 7: Structure Conformance Check + Auto-cleanup\n\nScan `output_dir` for files that don't conform to rules-extract\u002Frules-merge convention:\n\n**Valid patterns:**\n- `{category}\u002F{name}.md`\n- `{category}\u002F{name}.local.md`\n- `{category}\u002F{name}.examples.md`\n- `project.md`\n- `project.examples.md`\n\n**Valid categories:** `languages\u002F`, `frameworks\u002F`, `integrations\u002F`\n\n**Non-conforming file handling:**\n1. Read the non-conforming file and analyze its content\n2. Determine the appropriate conforming file(s) to migrate rules into (based on category, content, and `paths:` hints)\n3. Use `AskUserQuestion` to present the migration plan as a single list for confirmation:\n   > The following non-conforming files were detected. Migrate their rules to conforming files and delete them?\n   > 1. `frameworks\u002Fold-custom-rules.md` → migrate to `frameworks\u002Frails.md`\n   > 2. `ruby-rules.md` → migrate to `languages\u002Fruby.md`\n   > 3. `project.rules.md` → migrate to `project.md` (**project file — confirm individually**)\n   >\n   > Options: all \u002F none \u002F specify by number (e.g. \"1,2\")\n   >\n   > Note: `project.*` files are excluded from \"all\". Specify them individually by number.\n4. User approval → merge rules into conforming file(s) and delete non-conforming files\n5. Report all migrations and deletions\n\n### Step 8: Cleanup\n\nIf source was a GitHub URL, remove the temp directory: `rm -rf \u003Ctmpdir>`, where `\u003Ctmpdir>` is the exact literal path `mktemp` returned in Step 2 — never a re-derived, globbed, or reconstructed path. The `allowed-tools` scope (`Bash(rm -rf *\u002Frules-apply-*)`) is a coarse pattern match, not a path-boundary guarantee, since it matches the `rules-apply-` prefix as text regardless of which directory it appears under — the actual safety boundary is this step using only the recorded Step 2 path, not the permission string alone.\n\n### Step 9: Report Summary\n\nDisplay report. Report headers are always in English, content in the configured `language`.\n\nSee `references\u002Freport-format.md` for an annotated report example.\n\n## Conflict Handling\n\nSummary of user-confirmation points and automatic actions:\n\n| Situation | Action |\n|-----------|--------|\n| Principle in source, not in target | Auto-add |\n| Principle in target, not in source | Auto-keep |\n| Same principle, different hints | Auto-union hints |\n| Same principle name, different content | **AskUserQuestion**: collect all conflicts, present together (adopt org \u002F keep project \u002F keep both) |\n| Non-conforming file detected | **AskUserQuestion**: present migration plan as single list for confirmation |\n| `project.*` non-conforming file | Excluded from \"all\" — must be specified individually by number |\n| Target file name differs from source canonical name | **AskUserQuestion**: confirm renames (all \u002F none \u002F specify) |\n| Undetected integration rule (related framework) | **AskUserQuestion**: present as single list for approval (all \u002F none \u002F specify) |\n| `.local.md` pattern matching a Principle | Auto-remove from `.local.md` (cross-format duplicate cleanup) |\n| `.local.md` pattern not matching any Principle | Preserved |\n| `## Project-specific Examples` for removed pattern | Auto-remove |\n| `## Project-specific Examples` for remaining pattern | Preserved |\n\n---\n\n## Testing & Validation\n\nAfter running rules-apply:\n\n1. **Applied rules** — each rule file in the report appears at the correct path in `output_dir`\n2. **Promoted cleanup** — patterns removed from `.local.md` match Principles now in the corresponding `.md`\n3. **Examples reference** — every `.md`\u002F`.local.md` with a sibling `.examples.md` ends with `## Examples`\n4. **No orphaned `.local.md`** — `.local.md` files that became empty were deleted\n5. **Dry run first** — run with `--dry-run` on unfamiliar sources to preview changes before writing\n\n**Quality gates:**\n- [ ] Report shows no unexpected skips (verify `auto_detect` and `include`\u002F`exclude` config)\n- [ ] Conflict resolutions recorded in report\n- [ ] Structure cleanup applied: no non-conforming files remain in `output_dir`\n- [ ] `paths:` frontmatter on `.local.md` matches sibling `.md` after sync\n- [ ] Temp directory cleaned up (no leftover dirs from GitHub fetch)\n\n---\n\n## Reference Guide\n\n| Resource | Purpose |\n|---|---|\n| `references\u002Fdetection-heuristics.md` | Tech stack detection table — maps dependency files and project structure to rule files |\n| `references\u002Fconfig-template.md` | Full annotated config file format for `rules-apply.local.md` |\n| `references\u002Freport-format.md` | Annotated sample report showing all output sections |\n",{"name":5,"description":7,"allowed-tools":23},"Read Glob Grep Write Bash(gh:*) Bash(mktemp:*) Bash(rm -rf *\u002Frules-apply-*) Bash(rm .claude\u002Frules\u002F**\u002F*.local.md)","main","1bf12900cac6f28e346abd2912bdb78d306de723","plugins\u002Fplugin-devkit\u002Fskills\u002Frules-apply","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace","https:\u002F\u002Fgithub.com\u002FAndreHahm","2026-11-15 04:26:16",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add AndreHahm\u002Fandres-cc-marketplace --skill rules-apply",{"tool":36,"command":37},"bunx","bunx skills add AndreHahm\u002Fandres-cc-marketplace --skill rules-apply",{"tool":39,"command":40},"pnpm","pnpm dlx skills add AndreHahm\u002Fandres-cc-marketplace --skill rules-apply","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fplugin-devkit\u002Fskills\u002Frules-apply\u002FSKILL.md",true,[44,50,54],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},"references\u002Fconfig-template.md","REFERENCE","参考文档",916,"https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fplugin-devkit\u002Fskills\u002Frules-apply\u002Freferences\u002Fconfig-template.md",{"path":51,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":52,"sourceHtmlUrl":53},"references\u002Fdetection-heuristics.md",2458,"https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fplugin-devkit\u002Fskills\u002Frules-apply\u002Freferences\u002Fdetection-heuristics.md",{"path":55,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":56,"sourceHtmlUrl":57},"references\u002Freport-format.md",1219,"https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fplugin-devkit\u002Fskills\u002Frules-apply\u002Freferences\u002Freport-format.md",[59,66,73,80,87,94],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M79R0K918Z0XDM74R0EY5H3P","demo","Fixture skill used by scripts.marketplace_ci sync tests.","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Ftests\u002Fmarketplace_ci\u002Ffixtures\u002Fplugins\u002Fsample-kit\u002Fskills\u002Fdemo\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M79R08VMDJA2FPJKH3ZM309K","export-demo","Fixture skill used by scripts.marketplace_ci export tests.","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Ftests\u002Fmarketplace_ci\u002Ffixtures\u002Fclaude\u002Fskills\u002Fexport-demo\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M79R042FS581DS2JNW5AZ1MK","work-to-development","Validate an accepted Linear Issue's readiness for implementation (criteria, dependencies, duplicate\u002Fexisting artifacts) and request governed branch\u002Fworktree creation through git-kit:starting-work — recording work-started Git\u002FGitHub 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.","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkmanagement-kit\u002Fskills\u002Fwork-to-development\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":18},"01M79QZZD4EHB82P72P4N92BKT","work-linking","Create and maintain stable cross-system links and authority labels between Notion and Linear records, and detect\u002Frepair 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\u002Fstale 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.","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkmanagement-kit\u002Fskills\u002Fwork-linking\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":18},"01M79QZVFA3GTVNZMJ51NESVSP","status-and-learning","Produce a dated, explicitly non-live Linear-to-Notion progress summary, or capture an outcome\u002Flearning 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.","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkmanagement-kit\u002Fskills\u002Fstatus-and-learning\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":18},"01M79QZNSKSABK7X2PT93X8QT5","repository-gates","Discover, delegate, record, and invalidate this repository's actual Git\u002FGitHub 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).","https:\u002F\u002Fgithub.com\u002FAndreHahm\u002Fandres-cc-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkmanagement-kit\u002Fskills\u002Frepository-gates\u002FSKILL.md",[],[]]