fix: warn and back up before replacing custom content in agent files - #575
Open
Som Samantray (SomSamantray) wants to merge 5 commits into
Open
Conversation
… content Detect custom content inside the managed OPENWIKI:START/END block of AGENTS.md and CLAUDE.md. Before refreshing, save the file to <file>.openwiki.bak atomically (temp-plus-rename) and warn on stderr, naming the file, the backup path, and any replaced backup. Canonical blocks are now skipped entirely (no rewrite, no mtime churn), CRLF and lone-CR files compare equal to the LF snippet, and marker validation runs for both files before any backup or write so an aborted run never leaves a backup. The scheduled-update workflow's add-paths now includes the backups as the durable CI recovery artifact.
The TUI call site appends the warning as a run-log text event and mirrors it to stderr so it survives a re-render or an error-terminated run that discards the log. The --print call site pins explicit stderr wiring so piped stdout stays clean.
README code-mode section now covers the backup file, the restore procedure, and moving content outside the markers to stop replacement. Adds a patch changeset for the fix.
…ration Extract pathExists into fs-errors.ts (the repo's designated home for fs helpers) and use it for the backup-existence check, dropping the whole-file read. Collapse the paired backupContent/warning fields into a single optional backup object, run backup writes in parallel, and hoist the normalized snippet out of the per-file prepare loop.
- Mirror run-log warnings to stderr via a testable factory (survives a throwing log callback) - Warn when an existing workflow predates the backup commit paths, so existing installs learn their CI discards backups - Emit warnings for already-succeeded backups when a sibling backup fails, then abort with context (agent files left unchanged) - Sweep stale backup temp files left by a crash between write and rename - Refuse to rewrite or back up non-UTF-8 agent files lossily - Document pathExists error-policy divergence from pre-existing copies - Test hardening: fresh-backup suffix discrimination, temp cleanup assertion, symlink target refresh, pathExists unit tests
🦋 Changeset detectedLatest commit: e68cb6f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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
openwikicode-mode runs can no longer silently destroy custom content in a repo'sAGENTS.md/CLAUDE.md.Before: any content a user placed inside the managed
<!-- OPENWIKI:START -->…<!-- OPENWIKI:END -->block was replaced with the generated snippet on the nextinit/update/chat run, with no notice (the destructive path behind #573).After: when the managed block holds content that differs from the generated snippet, the run saves the file to
<file>.openwiki.bak(atomic temp-plus-rename), prints a warning naming the file and the backup path, then refreshes. Canonical blocks are left completely untouched — no rewrite, no mtime churn, line endings preserved (CRLF and lone-CR files compare equal to the LF snippet). Malformed markers still abort with both files unchanged, and an aborted run never leaves a backup behind.Design decisions
add-paths, so CI users get a durable recovery artifact.onWarningsink on the setup options, defaulting to stderr. The TUI mirrors warnings to the run log and stderr (so they survive a re-render or an error-terminated run);--print/CI keeps piped stdout clean.openwiki code --initnow warns when an already-present workflow predates the backup commit paths, since a preserved workflow is never silently modified.Session-settled decisions carried from planning: protection posture warn+backup-then-proceed (user-approved, over abort-with-error and warn-only); warning channel onWarning option with stderr default (user-approved, over hardcoded stderr and the shared event stream).
Fixes #573
Testing
openwiki code --update --printon a fixture repo with a hand-edited block emits the warning on stderr, keeps stdout clean, writes the.bak, and preserves surrounding content; a second run is silent; a malformed-marker sibling aborts with no backup for either file;--initagainst a pre-existing workflow warns about the missing backup paths without touching the customized file.Known residuals
pathExistscopies insrc/schedules.ts/src/connectors/tools.ts(different error policies) are not yet migrated to the new sharedsrc/fs-errors.tshelper.Post-Deploy Monitoring & Validation
No additional operational monitoring required. This is a CLI + generated-workflow change; watch scheduled-update PRs of affected repos for the backup files in
add-pathsdiffs, and roll back by reverting this commit.