Skip to content

feat(rules): warn on diverging include selections for a shared root file - #4029

Merged
dyoshikawa merged 5 commits into
mainfrom
resolve-issue-4021-scrap-followups
Nov 30, 2026
Merged

dyoshikawa merged 5 commits into
mainfrom
resolve-issue-4021-scrap-followups

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

Handles both low follow-ups from #4021.

  1. Per-target rules.include (feat(rules): select rules per target with the include rules option #4017): rulesync generate now warns, once per file, when targets that write the same root rule file (for example codexcli and opencode, both AGENTS.md) resolve different rule selections and at least one of them sets include. The warning names the file, the targets, and the target that wins (the last one in config order). Nothing else changes.
  2. preserveUnmanagedRuleContent (feat(rules): add preserveUnmanagedRuleContent to keep hand edits in root rule files #4019): a frontmatter block above the fence that Rulesync wrote earlier, when the newly generated body has no frontmatter, is kept. Generate and --delete stay stable with it, and the behavior is now documented.

What changed

  • src/lib/shared-root-selection-watch.ts (new): records the rulesync rules each target resolved for each root ToolRule path, keyed by resolved output path. report() compares selections only for shared paths where some target sets include, and warns once per path. Wired into generateRulesCore next to the existing fold-root overwrite watch. displayPath is now exported from fold-root-overwrite-watch.ts so both watches name files the same way.
  • src/features/rules/rule-managed-block.ts: the doc comment explains why a leading frontmatter block is kept when the generated content has none.
  • Tests: unit tests for the watch (diverging, matching, no include, not shared). An e2e case (codexcli with include plus opencode warns exactly once, and the same list on both stays quiet). A splice test (stale frontmatter: two generates give the same result, and removing the fence leaves the block). A processor test that runs generate twice (second run writes nothing) and then the --delete sweep twice (the block stays, nothing grows).
  • Docs: docs/guide/configuration.md (the include shared-file bullet mentions the warning, and the preserveUnmanagedRuleContent reference covers the kept frontmatter) and docs/guide/global-mode.md. Regenerated docs-content.ts.

Design decisions (made autonomously)

  • Keep, do not drop, stale frontmatter. The fence opens every file Rulesync writes, so frontmatter that a person adds by hand also sits right above the start marker. That is the case the existing test keeps a hand-written leading frontmatter when the generated content has none protects. Being directly before the fence therefore does not show the block is Rulesync's. Matching "the shape this target emits" does not work either: the case only comes up when the target no longer emits frontmatter. Since there is no safe signal, the conservative choice wins: never delete possibly hand-written content. Docs tell users to remove a stale block by hand once. After a --delete sweep, the block keeps the file in place, as for any hand-written content.
  • The warning fires only when the shared root file's contents differ and some target's include actually leaves a rule out. Many targets (kilo, antigravity-cli, copilot, ...) file non-root rules in their own directories, so a different include list often leaves the shared root file byte-identical, and in that case nothing is reported. include: ["*"], or a list naming every rule, narrows nothing, so it is not blamed for differences that come from the rules' own targets frontmatter.
  • One warning per shared root file. If an overwritten fold target (e.g. codexcli) folded any non-root rule into the file, with or without include, those rules are lost because of the target order. Only the fold-root overwrite warning, with its reorder advice, is printed then. The selection warning takes over only when the fold target folded nothing, because its include left it the root rule alone. Reordering would not help in that case.
  • Narrowing counts only rules targeting the tool. A rule whose targets frontmatter excludes the tool does not make an include list look narrowed.
  • Root files only. Each target writes its own non-root files, so only the shared root file holds one target's output.

Closes #4021

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 5 commits November 30, 2026 22:47
When targets that write the same root rule file (e.g. codexcli and
opencode, both AGENTS.md) resolve different rule selections and at least
one of them sets the per-target `include` rules option, generate now warns
once per file, naming the file, the targets and the last target that wins.
Output is unchanged.

Under preserveUnmanagedRuleContent, a leading frontmatter block above the
fence is kept when the generated body has none, since it cannot be told
apart from hand-written frontmatter. Document this and cover generate and
--delete stability in tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
The shared-root selection warning now fires only when the targets sharing
a root file would write different contents to it and at least one of them
actually leaves rules out through `include`. Auto-discovery targets that
file non-root rules in their own directories (kilo and antigravity-cli on
AGENTS.md, for example) are no longer told to drop a valid config, and
`include: ["*"]` is no longer blamed for differences that come from
`targets` frontmatter. A file the selection warning names is skipped by
the fold-root overwrite warning, so the run does not give conflicting
advice. Tests use setupTestDirectory and cover a global-mode path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
When a fold target that keeps every rule is overwritten by a later
narrowed target, the loss comes from the target order, so the fold-root
overwrite warning (with its reorder advice) is printed and the selection
warning skips that file. The selection warning only takes over when the
overwritten fold target narrowed its own selection. Each shared root file
gets one warning.

The selection warning no longer claims `include` is the cause, and
`include` narrowing is measured against the rules targeting the tool, so
a rule for another tool does not make a selection look narrowed.

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

# Conflicts:
#	src/generated/docs-content.ts
The fold-root overwrite warning was skipped whenever the overwritten fold
target narrowed its selection, so a fold target that narrowed a little
but still folded non-root rules lost them with no warning (e.g. codexcli
and kilo both with include ["overview", "git-safety"]). The file is now
handed to the selection warning only when the fold target folded nothing
(its resolved selection holds no non-root rule); otherwise the fold
warning with its reorder advice is printed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
@dyoshikawa
dyoshikawa merged commit 75fd350 into main Nov 30, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-4021-scrap-followups branch November 30, 2026 14:33
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.

Follow-ups: low findings left from the 2026-11-29 issue run (#4017-#4020)

1 participant