Repository navigation
feat(rules): add preserveUnmanagedRuleContent to keep hand edits in root rule files - #4019
Merged
dyoshikawa merged 4 commits intoNov 29, 2026
Merged
Conversation
…oot rule files With the opt-in preserveUnmanagedRuleContent config key, rulesync wraps the generated body of every root rule file between <!-- Generated by Rulesync --> and <!-- End of Rulesync --> and keeps content outside the fence on generate. generate --check compares the spliced result, and import reads only the fenced part. A file without markers is treated as rulesync-owned. Closes #4010 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
- Ignore marker lines inside Markdown code blocks so a body quoting the markers stays stable across runs - Strip to the fenced part on import only when the option is on - On the --delete sweep and retireTargets, remove only the fenced block of a root rule file and keep the hand-written rest - Pass the option to rulesync convert - Keep CRLF line endings of an existing file when splicing Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
Under preserveUnmanagedRuleContent, a root rule file without a fence is no longer rulesync's, so the --delete sweep and retireTargets keep it instead of deleting the hand-written rest on the next run. Only root rule files are fenced on removal; per-rule files are deleted as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…eserve-unmanaged-rule-content # Conflicts: # docs/guide/configuration.md # src/config/config-resolver.ts # src/config/config.ts # src/generated/docs-content.ts # src/lib/generate.test.ts
dyoshikawa
deleted the
resolve-issue-4010-preserve-unmanaged-rule-content
branch
November 29, 2026 07:20
This was referenced Nov 29, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in
preserveUnmanagedRuleContentkey torulesync.jsonc. When it is on, every root rule file rulesync writes (AGENTS.md,CLAUDE.md,CLAUDE.local.md,~/.codex/AGENTS.md,~/.claude/CLAUDE.md, ZCode, Codebuff, ...) gets its generated body fenced between<!-- Generated by Rulesync -->and<!-- End of Rulesync -->, and content before and after the fence is kept on the nextgenerate. Default output is unchanged.What changed
src/features/rules/rule-managed-block.ts: splice and extract helpers for the Markdown fence. Generated frontmatter stays on the first line, ahead of the fence. An existing file's leading frontmatter is replaced only when the generated content has its own.AiFile.composeWrittenContent(): a new hook the write phase uses to compute what goes on disk from the existing content and the generated content.ToolRuleoverrides it when preservation is on. Becausegenerate --check/--dry-rungo through the samewriteAiFilescomparison, content outside the fence is never reported as drift.RulesProcessor: newpreserveUnmanagedContentoption (wired from config ingenerate). It marks every rootToolRuleit emits, which covers local-root files and root mirrors too. Per-rule files in rules directories (.claude/rules/*.md,.cursor/rules/*.mdc, ...) are not fenced.Import (and the source side of
convert): with the option on, when a rule file has both markers, only the fenced part goes into.rulesync/rules/. With it off, the whole file is imported. Hand-written content is not copied into the source, so the round trip does not duplicate it.Config:
preserveUnmanagedRuleContent(schema,Config,ConfigResolver). Config-file only, likepreserveUnownedHooks, which has no CLI flag either.Docs: configuration reference and a new section in the global-mode guide. Regenerated
docs-content.ts.Tests: unit tests for the splice/extract helpers, processor tests (fence, kept content, check drift, option off, import), a config-resolver test, and a global-mode e2e case (generate -> hand edit ->
--check-> regenerate -> import).Removal: when a root rule file stops being generated (
--deletesweep,retireTargets), only the fenced block is removed and the hand-written rest is kept. The file is deleted only if nothing else is left. A root file without a fence is no longer treated as rulesync's and is left in place, including one written before the option was on, so it has to be removed by hand. Only root rule files get this treatment; per-rule files are deleted as before.Marker lines inside Markdown code blocks are ignored. An existing CRLF file keeps CRLF line endings.
rulesync converthonors the option.Design decisions (made autonomously; open to revisit)
preserveUnmanagedRuleContentmatches thepreserveUnownedHooksfamily. No CLI flag, because the sibling has none and this is a property of the files, not of one run.src/lib/gitignore.tsis tied to gitignore entries and its legacy-block heuristics, so it was not shared. Only the marker wording was reused.Skipped
Closes #4010
🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4