fix: preserve existing agent guide files during install

This commit is contained in:
zfc
2026-03-12 21:33:59 +08:00
parent c27b85193f
commit e16da89569
3 changed files with 197 additions and 9 deletions
+22 -5
View File
@@ -91,6 +91,23 @@ sync_file() {
fi
}
sync_guide_file() {
local src="$1"
local dst="$2"
local create_msg="$3"
local skip_msg="$4"
if [ ! -f "$dst" ]; then
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
log_info "$create_msg"
TOTAL_NEW=$((TOTAL_NEW + 1))
else
log_info "$skip_msg"
TOTAL_SKIPPED=$((TOTAL_SKIPPED + 1))
fi
}
install_layout() {
local input="$1"
local skill_dir
@@ -147,11 +164,11 @@ install_layout() {
guide_src_path="$TMP_DIR/$GUIDE_SRC"
if [ -f "$guide_src_path" ]; then
sync_file \
sync_guide_file \
"$guide_src_path" \
"$GUIDE_DST" \
"✨ 新增项目引导: $GUIDE_DST" \
"🔄 更新项目引导: $GUIDE_DST (本地版本已备份为 ${GUIDE_DST}.local.bak"
"✨ 新增项目引导: ${GUIDE_DST}" \
"⏭️ 跳过项目引导: ${GUIDE_DST}(已存在,保持原样"
fi
INSTALLED_TARGETS="${INSTALLED_TARGETS}${INSTALLED_TARGETS:+, }$TARGET"
@@ -188,12 +205,12 @@ echo " 📁 目标目录: $INSTALLED_TARGETS"
echo " 📦 版本: $VERSION"
echo ""
echo " ✨ 新增: $TOTAL_NEW"
echo " 🔄 更新: $TOTAL_UPDATED(本地版本已备份为 .local.bak)"
echo " 🔄 更新: ${TOTAL_UPDATED}(本地版本已备份为 .local.bak)"
echo " ⏭️ 无变化: $TOTAL_SKIPPED"
echo ""
if [ "$TOTAL_UPDATED" -gt 0 ]; then
log_warn "$TOTAL_UPDATED 个文件被更新,本地修改已备份为 .local.bak"
log_warn "${TOTAL_UPDATED} 个文件被更新,本地修改已备份为 .local.bak"
log_warn "如需恢复本地版本: mv SKILL.md.local.bak SKILL.md"
log_warn "如需对比差异: diff SKILL.md SKILL.md.local.bak"
fi