Skip to content

feat(rules): select rules per target with the include rules option - #4017

Merged
dyoshikawa merged 3 commits into
mainfrom
resolve-issue-4016-per-target-rules
Nov 29, 2026
Merged

dyoshikawa merged 3 commits into
mainfrom
resolve-issue-4016-per-target-rules

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds per-target rule selection: an include list in a target's rules feature options (object form of targets). A target with include receives only the named rules, local and fetched (.rulesync/rules/.curated/) alike, so fetched rules can be routed per tool without editing their frontmatter, which rulesync install rewrites.

"targets": {
  "claudecode": ["rules", "skills"],
  "antigravity-cli": { "rules": { "include": ["git-safety", "language-and-commits"] } }
}

What changed

  • RulesProcessor.loadRulesyncFiles narrows the merged rules (all input roots, local + curated) by the include option before the usual root/target handling.
  • Names match the way sources[].rules matches (reuses normalizeRuleFilterName / isWildcardSelection): file name without .md (.md accepted), a nested rule by its path (frontend/react), ["*"] = every rule, [] = none.
  • An unknown name fails generate with an error naming the target and the names.
  • A non-array value fails with a clear options error.
  • Unit tests (project, global, curated, nested, wildcard, errors, warnings) and two e2e cases (selection with a curated rule; unknown name failing generate).
  • Docs: per-feature options table plus a new "Selecting rules per target" section in docs/guide/configuration.md; a pointer from docs/guide/declarative-sources.md. The JSON schema needs no change (feature options are typed as a free-form record).

Design decisions (made autonomously, can be revisited)

  • Pure narrowing filter. The targets frontmatter still applies. A named rule whose frontmatter excludes the target is not generated, and a warning names it. include can never add a rule to a tool the rule itself excludes.
  • Root rule is not special. If the root rule is left out, the target gets no root file. The "No root rulesync rule file found" warning is suppressed in that case because it was left out on purpose. A localRoot rule without its root still fails as before.
  • [] is allowed (no rules), unlike sources[].rules, where an empty list is an error because it is ambiguous with skills. Here it is not ambiguous.
  • include survives --targets. Unlike other per-feature options, it is always read from the config file (getRulesFeatureOptions in src/config/config.ts), so generate -t <target> never writes rules the target excludes. The --check owner comparison already used the config-file options.
  • Targets that share an output file (e.g. AGENTS.md) share one selection: last target wins, as for any shared file (documented; no extra warning, since the existing fold-root overwrite watch already reports the lossy case).
  • The import fold-duplication check applies include too. It falls back to every rule when the selection is invalid, so import never fails on it.

Skipped

  • The alternative top-level ruleTargets field from the issue, by design.

Closes #4016

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 3 commits November 29, 2026 15:32
Add an `include` option to a target's `rules` feature options in the
object form of `targets`. When set, the target receives only the named
rules, local and fetched (.curated) alike, so fetched rules can be routed
per tool without editing frontmatter that install rewrites.

Names match like sources[].rules (file name without .md; nested rules by
path), an unknown name fails generate, and the targets frontmatter still
applies on top. Works in project and global mode.

Closes #4016

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
Read the rules `include` option from the configuration file even when
--targets replaces the object form of targets, so a narrowed run never
writes the rules a target deliberately excludes. Apply `include` in the
import fold-duplication check too (falling back to every rule on an
invalid selection), and document that targets sharing an output file
share one selection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…r-target-rules

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit d6a4b1e into main Nov 29, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-4016-per-target-rules branch November 29, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-target rule selection in rulesync.jsonc (fetched rules can't use targets frontmatter)

1 participant