feat(editor): add --magic-fix to auto-rename files to canonical extension

Natural follow-up to --audit-tree: when that utility flags
ext-mismatch or magic-no-ext issues, --magic-fix proposes (and
optionally applies) the renames that resolve them. Walks a
directory recursively, reads each file's 4-byte magic, looks it
up in the format table, and renames to the canonical extension
when the current extension doesn't match (or is absent).

Defaults to dry-run for safety — prints the proposed renames so
they can be reviewed first; pass --apply to commit them. Refuses
to clobber existing files: when the target path already exists
(e.g. foo.wsct + foo.wsrg both with WSRG magic), the rename is
flagged as a collision and skipped, leaving both files in place
for manual resolution. Returns exit 1 if any proposals exist (in
dry-run) or any collisions are skipped (in apply), so it composes
into shell pipelines.

JSON sidecar via --json. Suggested workflow:
  --audit-tree dir          # find what's broken
  --magic-fix dir           # preview the auto-fixes
  --magic-fix dir --apply   # commit them
  --audit-tree dir          # confirm clean

CLI flag count 921 -> 922.
This commit is contained in:
Kelsi 2026-05-09 21:57:26 -07:00
parent 3e73860475
commit 74be3f6135
6 changed files with 215 additions and 0 deletions

View file

@ -137,6 +137,7 @@ const char* const kArgRequired[] = {
"--info-magic", "--summary-dir", "--rename-by-magic",
"--bulk-rename-by-magic", "--touch-tree", "--tree-summary-md",
"--catalog-grep", "--diff-headers", "--audit-tree",
"--magic-fix",
"--gen-animations", "--gen-animations-combat", "--gen-animations-movement",
"--info-wani", "--validate-wani",
"--export-wani-json", "--import-wani-json",