feat: 组合包配置集中到 my-pi/ 目录并改为整体重建

- 组合包拥有、可随时重建的配置、日志与缓存统一放在
  <agentDir>/my-pi/:permission-system/(policy.jsonc、hard-guards.jsonc、
  logs/)、rtk-optimizer/config.json、tool-search/(config.json、
  catalog-v1.json)与 system-prompt-cover.md。hashline.json、lsp.json
  由外部扩展读取固定路径,是唯一例外。
- 新增 config/bundle-manifest.json 与 scripts/rebuild-bundle-config.mjs:
  先校验全部来源与目标,在临时目录构建完整树,再整体删除旧 my-pi/
  (符号链接只删链接)并原子替换,不备份。install.sh / update.sh 每次
  运行都调用它;扩展自身不再播种或迁移配置。
- update.sh 删除 pi update 失败后的 git clean 恢复逻辑:Pi 1.3.0 会在
  下一次 pi update 时依据中断标记自行恢复。同时删除 Tool Search
  settings.json 快照迁移与封面部署脚本。
- Tool Search 改为读取 my-pi/tool-search/config.json(源为
  config/tool-search.json,须与 BUNDLE_TOOL_SEARCH_DEFAULTS 一致),
  不再读写 settings.json 的 toolSearch 段,移除 bundleDefaultsVersion。
- 默认权限策略开启 debugLog。
- 旧位置的残留文件不迁移、不清理;AGENTS.md / README 同步新约束。

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
云服务部-叶林立
2026-10-19 02:26:57 -07:00
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent 7e6a8faae1
commit 2682bd7fa7
40 changed files with 711 additions and 1339 deletions
+17 -122
View File
@@ -57,91 +57,6 @@ select_updated_bundle_config() {
fi
}
recover_incomplete_bundle_update() {
recovery_applicable=0
case $PACKAGE_SOURCE in
git:git@bitbucket.org:siakitem/my-pi.git) ;;
*) return 1 ;;
esac
agent_dir=${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}
recovery_target=$agent_dir/git/bitbucket.org/siakitem/my-pi
recovery_marker=$agent_dir/git/bitbucket.org/siakitem/.my-pi.pi-update-incomplete
if [ ! -f "$recovery_marker" ] || [ -L "$recovery_marker" ]; then
return 1
fi
if ! command -v git >/dev/null 2>&1 || [ ! -d "$recovery_target/.git" ]; then
warn "检测到 Pi Git 升级中断标记,但无法验证已安装 checkout,已跳过自动恢复。"
return 1
fi
recovery_target=$(CDPATH=; cd "$recovery_target" 2>/dev/null && pwd -P) || return 1
recovery_top=$(git -C "$recovery_target" rev-parse --show-toplevel 2>/dev/null) || return 1
recovery_top=$(CDPATH=; cd "$recovery_top" 2>/dev/null && pwd -P) || return 1
recovery_origin=$(git -C "$recovery_target" remote get-url origin 2>/dev/null) || return 1
if [ "$recovery_top" != "$recovery_target" ] || \
[ "$recovery_origin" != "git@bitbucket.org:siakitem/my-pi.git" ]; then
warn "检测到 Pi Git 升级中断标记,但 checkout 身份校验失败,拒绝自动清理。"
return 1
fi
recovery_applicable=1
say "检测到默认组合包的 Pi Git 升级中断,正在有限重试依赖清理。"
recovery_attempt=1
while [ "$recovery_attempt" -le 4 ]; do
if git -C "$recovery_target" clean -fdx; then
say "✓ Pi Git 缓存清理在第 ${recovery_attempt} 次尝试后完成。"
return 0
fi
warn "Pi Git 缓存第 ${recovery_attempt} 次清理未完成。"
recovery_attempt=$((recovery_attempt + 1))
done
warn "Pi Git 缓存清理在 4 次尝试后仍未完成;将交由最后一次 pi update 恢复依赖并报告结果。"
return 1
}
migrate_tool_search_settings() {
settings_file=${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}/settings.json
if [ ! -e "$settings_file" ]; then
say "- Pi settings.json 尚不存在;Tool Search 将在下次加载时写入当前默认值。"
return 0
fi
if [ -z "${updated_bundle_dir:-}" ] || [ ! -f "$updated_bundle_dir/scripts/migrate-tool-search-settings.mjs" ]; then
warn "无法定位升级后组合包中的 Tool Search settings.json 迁移辅助脚本,已保留现有配置。"
return 1
fi
migration_helper=$updated_bundle_dir/scripts/migrate-tool-search-settings.mjs
if ! command -v node >/dev/null 2>&1; then
warn "迁移 Tool Search settings.json 需要 Node.js,已保留现有配置。"
return 1
fi
migration_result=$(node "$migration_helper" "$settings_file") || return 1
case $migration_result in
migrated:*)
say "✓ Tool Search 旧版默认配置已迁移到当前组合包默认值。"
say " 原配置备份:${migration_result#migrated:}"
;;
current)
say "✓ Tool Search 用户配置已是当前组合包默认版本。"
;;
custom)
say "- 检测到自定义 Tool Search 用户配置,已完整保留。"
;;
missing-section)
say "- settings.json 尚未包含 Tool Search 配置;下次加载时将补充当前默认值。"
;;
missing)
say "- settings.json 在迁移前已被移除;下次加载时将写入当前默认值。"
;;
*)
warn "Tool Search settings.json 迁移返回未知状态,已停止该项同步。"
return 1
;;
esac
}
resolve_agent_dir() {
if [ -n "${PI_CODING_AGENT_DIR:-}" ]; then
case $PI_CODING_AGENT_DIR in
@@ -153,28 +68,27 @@ resolve_agent_dir() {
printf '%s\n' "$HOME/.pi/agent"
}
# 把组合包权威的系统提示词封面同步到 agent 目录;未受管的自定义封面会被覆盖。
deploy_system_prompt_cover() {
if [ -z "${updated_bundle_dir:-}" ] || [ ! -f "$updated_bundle_dir/scripts/deploy-system-prompt-cover.mjs" ]; then
warn "无法定位升级后组合包中的 SYSTEM_COVER.md 部署辅助脚本,已保留现有封面。"
# 整体删除并重建组合包拥有的 <agentDir>/my-pi/ 配置目录;helper 必须来自升级后的
# 组合包,缺失时报告失败且绝不回退到脚本目录中可能陈旧的副本。
rebuild_bundle_config() {
if [ -z "${updated_bundle_dir:-}" ] || [ ! -f "$updated_bundle_dir/scripts/rebuild-bundle-config.mjs" ]; then
warn "无法定位升级后组合包中的配置重建辅助脚本,已保留现有配置。"
return 1
fi
if ! command -v node >/dev/null 2>&1; then
warn "找不到 node,无法同步 SYSTEM_COVER.md;Pi 将使用默认系统提示词封面。"
warn "找不到 node,无法重建组合包配置目录。"
return 1
fi
cover_helper=$updated_bundle_dir/scripts/deploy-system-prompt-cover.mjs
cover_agent_dir=$(resolve_agent_dir) || return 1
cover_status=$(node "$cover_helper" "$cover_agent_dir" 2>&1) || {
warn "SYSTEM_COVER.md 同步失败:$cover_status"
rebuild_helper=$updated_bundle_dir/scripts/rebuild-bundle-config.mjs
rebuild_agent_dir=$(resolve_agent_dir) || return 1
rebuild_status=$(node "$rebuild_helper" "$rebuild_agent_dir" 2>&1) || {
warn "组合包配置目录重建失败:$rebuild_status"
return 1
}
case $cover_status in
created) say "✓ 已部署系统提示词封面:$cover_agent_dir/SYSTEM_COVER.md" ;;
updated) say "✓ 已同步系统提示词封面到组合包当前版本。" ;;
current) say "✓ 系统提示词封面已是当前组合包版本。" ;;
case $rebuild_status in
rebuilt:*) say "✓ 已重建组合包配置目录:${rebuild_status#rebuilt:}" ;;
*)
warn "SYSTEM_COVER.md 部署返回未知状态:$cover_status"
warn "组合包配置重建返回未知状态:$rebuild_status"
return 1
;;
esac
@@ -452,31 +366,12 @@ if ! command -v pi >/dev/null 2>&1; then
fi
say "正在升级 Pi 组合包:$PACKAGE_SOURCE"
if pi update "$PACKAGE_SOURCE"; then
:
else
recovery_applicable=0
recovery_cleaned=0
if recover_incomplete_bundle_update; then
recovery_cleaned=1
fi
if [ "$recovery_applicable" -ne 1 ]; then
warn "pi update 执行失败,已停止后续升级。"
exit 1
fi
if [ "$recovery_cleaned" -eq 1 ]; then
say "正在重试 Pi 组合包升级,由 Pi 完成依赖安装并清除中断标记。"
else
warn "正在执行最后一次 pi update,以恢复可能被部分清理的依赖。"
fi
if ! pi update "$PACKAGE_SOURCE"; then
warn "pi update 自动恢复后仍然失败,已停止后续升级。"
exit 1
fi
if ! pi update "$PACKAGE_SOURCE"; then
warn "pi update 执行失败,已停止后续升级。重新运行 update.sh 即可,Pi 会自行恢复未完成的升级。"
exit 1
fi
select_updated_bundle_config || exit 1
migrate_tool_search_settings || record_update_failure "Tool Search 用户配置"
deploy_system_prompt_cover || record_update_failure "SYSTEM_COVER.md"
rebuild_bundle_config || record_update_failure "组合包配置重建"
say "组合包升级完成,开始升级已安装的终端环境和机器级 CLI;未安装项将直接跳过。"
update_kitty || record_update_failure "Kitty"