Skip to content

Comments

fix: backup existing config files before overwriting#119

Merged
kieranklaassen merged 1 commit intoEveryInc:mainfrom
jzw:feature/backup-config-files
Feb 8, 2026
Merged

fix: backup existing config files before overwriting#119
kieranklaassen merged 1 commit intoEveryInc:mainfrom
jzw:feature/backup-config-files

Conversation

@jzw
Copy link
Contributor

@jzw jzw commented Jan 23, 2026

Summary

  • Adds a backupFile() utility that creates timestamped backups before overwriting
  • Backs up config.toml before writing (Codex target)
  • Backs up opencode.json before writing (OpenCode target)
  • Backup files use the pattern: config.toml.bak.2026-01-23T21-16-40-065Z

Context

When running bunx @every-env/compound-plugin install compound-engineering --to codex, the CLI overwrites ~/.codex/config.toml without warning, which can destroy user customizations.

Test plan

  • Added test for Codex config backup
  • Added test for OpenCode config backup
  • All existing tests pass

🤖 Generated with Claude Code

@jzw
Copy link
Contributor Author

jzw commented Jan 24, 2026

@kieranklaassen this bit me. I figured it may be good to save others the same frustration.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b67848fc27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 5 to 9
if (!(await pathExists(filePath))) return null

const timestamp = new Date().toISOString().replace(/[:.]/g, "-")
const backupPath = `${filePath}.bak.${timestamp}`
await fs.copyFile(filePath, backupPath)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow overwrite when backup copy lacks perms

The new backupFile always runs fs.copyFile when a config exists. copyFile needs read access to the source file and write access to the parent directory; if a config is writable but not readable (or the directory is not writable for new files), the backup throws and the install/convert aborts even though overwriting the config would have succeeded before. This introduces a regression for restrictive-permission setups (e.g., write-only config files or read-only directories), where the CLI now fails before writing the new config.

Useful? React with 👍 / 👎.

Copy link
Contributor Author

@jzw jzw Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the directory isn't writable, the script already fails when writing prompts/skills before reaching the config backup. The only edge case this blocks is write-only config files, which is feels exceedingly rare. Made it best-effort anyway, backup failures are now silently ignored.

Before writing config.toml (Codex) or opencode.json (OpenCode), the CLI
attempts to create a timestamped backup of any existing config file.
This prevents accidental data loss when users have customized configs.

Backup is best-effort - if it fails (e.g., unusual permissions), the
install continues without blocking.

Backup files are named: config.toml.bak.2026-01-23T21-16-40-065Z
@kieranklaassen
Copy link
Collaborator

OHH TYTY!

@kieranklaassen kieranklaassen added the enhancement New feature or request label Feb 8, 2026
Copy link
Collaborator

@kieranklaassen kieranklaassen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice safety improvement, TY!

@kieranklaassen kieranklaassen merged commit c69c47f into EveryInc:main Feb 8, 2026
kprimdal added a commit to primux-dk/laravel-compound-engineering that referenced this pull request Feb 9, 2026
- Add `sync` command to sync ~/.claude/ personal config to OpenCode/Codex (EveryInc#123)
- Backup existing config files before overwriting (EveryInc#119)
- Remove worktree creation confirmation prompt (EveryInc#144)
- Fix .git file detection in worktrees (use -e instead of -d) (EveryInc#159)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
criztiano pushed a commit to criztiano/coen that referenced this pull request Feb 10, 2026
Before writing config.toml (Codex) or opencode.json (OpenCode), the CLI
attempts to create a timestamped backup of any existing config file.
This prevents accidental data loss when users have customized configs.

Backup is best-effort - if it fails (e.g., unusual permissions), the
install continues without blocking.

Backup files are named: config.toml.bak.2026-01-23T21-16-40-065Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants