From 69b06b8c0e07759846a4d455f0c6e2346fc559ff Mon Sep 17 00:00:00 2001 From: Parfii-bot Date: Tue, 21 Apr 2026 04:12:53 +0800 Subject: [PATCH] fix(install): per-file backup for shared hooks dir $HOOKS_DIR ($HOME/.claude/hooks) is shared with other kits. Backing up the whole directory cumulatively bloats foreign hooks across re-runs. Switch to backup_file per KeiSeiKit-owned hook so only the 3 files we actually overwrite get a .bak-TIMESTAMP sibling. backup_dir remains for KeiSeiKit-owned directories (_blocks, _templates, _assembler, skills). --- install.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index fa51d55..05dde0c 100755 --- a/install.sh +++ b/install.sh @@ -92,6 +92,18 @@ backup_dir() { say "backed up existing $target to $backup" } +# Per-file backup for shared directories like $HOOKS_DIR, where other kits +# may drop sibling files we must not touch. Only the specific file is moved +# aside to .bak-TIMESTAMP. +backup_file() { + local target="$1" + [ -f "$target" ] || return 0 + local backup="${target}.bak-$(date +%s)" + mv "$target" "$backup" + BACKUP_PAIRS+=("$target|$backup") + say "backed up existing $target to $backup" +} + # Activate KeiSeiKit hooks by merging settings-snippet.json into the user's # settings.json. Idempotent: # - If settings.json is absent, copy snippet verbatim (minus _comment key). @@ -230,9 +242,12 @@ if [[ -f "$KIT_DIR/_assembler/.gitignore" ]]; then fi # --- copy hooks (refresh; hooks are logic, not config) --------------------- +# $HOOKS_DIR is shared with other kits — back up each KeiSeiKit-owned hook +# individually rather than the whole directory, so foreign hooks are not +# dragged into .bak-TIMESTAMP snapshots on every re-run. say "copying hooks -> $HOOKS_DIR/" -backup_dir "$HOOKS_DIR" for h in assemble-agents.sh assemble-validate.sh no-hand-edit-agents.sh; do + backup_file "$HOOKS_DIR/$h" cp -f "$KIT_DIR/hooks/$h" "$HOOKS_DIR/$h" chmod +x "$HOOKS_DIR/$h" done