feat: manage CLAUDE.md/AGENTS.md as a delimited begin/end block instead of overwriting the whole file#33
Open
dehuaichendragonplus wants to merge 2 commits into
Conversation
…ad of overwriting the whole file
SyncClaude/SyncCodex previously regenerated the entire CLAUDE.md/AGENTS.md, which clobbered any
hand-authored content a user added (and any content that survived from a prior version). They now
manage only the region between the managed begin marker and a new end marker
(<!-- /Funplay Unity MCP managed project skills -->), preserving everything outside it:
- absent/empty file -> create title + block
- complete begin..end block -> replace just the block in place
- no begin marker -> append the block below the user's existing content
- begin marker, no end -> legacy whole-file marker (or corrupted block) of unknowable
extent; skip + warn rather than clobber
Disabling a platform now strips just the block (deleting the file only if nothing but a bare title
remains) instead of deleting the whole file. BuildClaude/CodexAgentsContent are split into
Build*ManagedBlock (block body, no title). IsManagedFile and the version-status/Upgrade Skills
detection are unchanged -- they match markers by content (Contains/IndexOf), independent of
position, so they work whether markers sit at the top of a fully-managed file or inside a block.
Verified via reflection over temp files: create (title+block), append-to-hand-authored (user
content preserved + block added), in-place update (block replaced, user content kept), legacy
begin-only (skipped unchanged), block removal (block stripped, user content kept), and block-only
file (deleted).
…ithout-end marker The disable path routed the "begin marker present, end marker missing/out-of-order" state into DeleteManagedFile, which deletes the file whenever IsManagedFile is true (begin marker present) -- destroying hand-authored content in a file that only had a stale/legacy begin marker. Now only a COMPLETE begin..end block is stripped; a begin-without-end (or no markers) is left untouched with a warning, matching WriteManagedBlock's safe handling of the same state.
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.
Why this change is needed
Today
SyncClaude/SyncCodexregenerate the entireCLAUDE.md/AGENTS.mdon every sync (File.WriteAllText(path, BuildXxxContent(...))). Any content a user adds to these files — project architecture notes, coding conventions, pitfalls, other (non-Funplay) agent instructions — is silently destroyed the next time Project Skills syncs (after a package upgrade, or after toggling platforms).Real incident that motivated this: in a production project, a hand-authored
CLAUDE.md(hundreds of lines of project-specific guidance) still carried the Funplay managed marker at its top from an earlier generation. A later sync overwrote the whole file back down to Funplay's ~40 generated lines, losing everything. The single-line marker is an unreliable ownership signal — it survives a hand-rewrite of the body, soIsManagedFilereports "managed" while the body is actually the user's.Root problem: Funplay treats these shared root files as wholly-owned, but they are shared surfaces users legitimately edit.
Change approach
Manage only a delimited block, never the whole file:
ManagedMarkeras the begin marker (soIsManagedFileand version-status detection keep working) and add an end marker<!-- /Funplay Unity MCP managed project skills -->.WriteManagedBlock(path, title, block):title+ blockRemoveManagedBlock(platform disabled) strips just the block; deletes the file only if nothing but a bare title/whitespace remains. Files without a block fall back to the legacy delete guard.BuildClaude/CodexAgentsContentsplit intoBuild*ManagedBlock(block body only, no# CLAUDE.mdtitle).IsManagedFile, the version-status /Upgrade Skillsdetection, and cursor rules. Status detection matches markers by content (Contains/IndexOf), independent of position, so it works whether markers sit at the top of a fully-managed file or inside a block.Benefits
CLAUDE.md/AGENTS.mdis never destroyed again — theMCP HTTP transport can fail to restart after Unity domain reload because previous listener is not fully stopped#1 safety issue with the current behavior.Upgrade Skillsstill delivers new guidance without a full-file rewrite.Test results
Verified in a Unity 6000.3.13f1 project (package compiles with zero errors), then exercised
WriteManagedBlock/RemoveManagedBlockvia reflection over temp files:# CLAUDE.md+ block ✔RemoveManagedBlockon block + user contentRemoveManagedBlockon block-only fileCompatibility testing
claudeandcodexguidance-file platforms.cursorrules (Funplay-namespaced files under.cursor/rules/) are unchanged; LM Studio / VS Code / Trae / Kiro don't generate a guidance file at all (SupportedPlatforms = { codex, claude, cursor }), so they're unaffected.FunplayMCPClientConfigPanel) is untouched.Upgrade Skillsbehavior is unchanged and verified (detection is position-independent, so markers inside a block are detected identically to markers at the top of a fully-managed file).Checklist
Funplay > MCP Serveropens and starts correctly.idea/or.DS_StoreCHANGELOG.md