mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat: 组合包配置以包内 config/ 为唯一来源,并新增受保护写入人工审批
配置统一:权限策略、硬防御、Tool Search、提示词封面以及新迁入的 RTK、pi-compaction、pi-worktree、pi-hermes-memory 配置全部由扩展 直接读取已安装组合包内的 config/,pi install / pi update 即完成部署; 删除 rebuild-bundle-config.mjs 与 bundle-manifest.json,my-pi/ 只保留 日志与缓存。update.sh 成功升级后将默认 git 来源的已安装副本 reset 回发布版本。AGENTS.md 新增「组合包配置原则」。 脚本整合:search_config.sh / ssh_config.sh 合并为 configure.sh search|ssh;install.sh / update.sh 共享函数抽到 scripts/lib.sh,远程 安装器改为先下载到临时文件再执行,下载失败可被检测。 权限:hard-guards 新增 protectedWrites,写入 Pi 凭据/设置、已安装 组合包与扩展目录、pi-ssh 凭据库时一律人工确认(跳过 AutoReview、 yolo 与 Session grant,无 UI 时拒绝);放行 ls、LSP 查询、ctx 只读、 web_search、Chrome 只读与 git 只读命令,skill_manage 改为 ask。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent
a0ee9389c7
commit
2aa1be0b54
@@ -3,13 +3,13 @@
|
||||
set -u
|
||||
|
||||
SCRIPT_DIR=$(CDPATH=; cd "$(dirname "$0")" && pwd) || exit 1
|
||||
MANAGED_CONFIG_HELPERS=$SCRIPT_DIR/scripts/managed-config.sh
|
||||
if [ ! -f "$MANAGED_CONFIG_HELPERS" ]; then
|
||||
printf '错误: 找不到受管配置辅助脚本:%s\n' "$MANAGED_CONFIG_HELPERS" >&2
|
||||
MY_PI_LIB=$SCRIPT_DIR/scripts/lib.sh
|
||||
if [ ! -f "$MY_PI_LIB" ]; then
|
||||
printf '错误: 找不到共享辅助脚本:%s\n' "$MY_PI_LIB" >&2
|
||||
exit 1
|
||||
fi
|
||||
# shellcheck source=scripts/managed-config.sh
|
||||
. "$MANAGED_CONFIG_HELPERS"
|
||||
# shellcheck source=scripts/lib.sh
|
||||
. "$MY_PI_LIB"
|
||||
|
||||
PACKAGE_SOURCE=${PI_PACKAGE_SOURCE:-git:git@bitbucket.org:siakitem/my-pi.git}
|
||||
POWERLEVEL10K_PRESET_FILE=$SCRIPT_DIR/config/p10k.zsh
|
||||
@@ -20,14 +20,6 @@ KITTY_VERSION_URL=https://sw.kovidgoyal.net/kitty/current-version.txt
|
||||
update_failed=0
|
||||
brew_metadata_refreshed=0
|
||||
|
||||
say() {
|
||||
printf '%s\n' "$*"
|
||||
}
|
||||
|
||||
warn() {
|
||||
printf '警告: %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
record_update_failure() {
|
||||
warn "$1 升级或配置同步失败;其余已安装组件仍会继续处理。"
|
||||
update_failed=1
|
||||
@@ -35,6 +27,7 @@ record_update_failure() {
|
||||
|
||||
select_updated_bundle_config() {
|
||||
updated_bundle_dir=
|
||||
updated_bundle_managed_git=0
|
||||
case $PACKAGE_SOURCE in
|
||||
/*)
|
||||
updated_bundle_dir=$PACKAGE_SOURCE
|
||||
@@ -44,6 +37,7 @@ select_updated_bundle_config() {
|
||||
;;
|
||||
git:git@bitbucket.org:siakitem/my-pi.git)
|
||||
updated_bundle_dir=${PI_CODING_AGENT_DIR:-$HOME/.pi/agent}/git/bitbucket.org/siakitem/my-pi
|
||||
updated_bundle_managed_git=1
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -57,62 +51,18 @@ select_updated_bundle_config() {
|
||||
fi
|
||||
}
|
||||
|
||||
resolve_agent_dir() {
|
||||
if [ -n "${PI_CODING_AGENT_DIR:-}" ]; then
|
||||
case $PI_CODING_AGENT_DIR in
|
||||
~/*) printf '%s\n' "$HOME/${PI_CODING_AGENT_DIR#~/}" ;;
|
||||
*) printf '%s\n' "$PI_CODING_AGENT_DIR" ;;
|
||||
esac
|
||||
return 0
|
||||
# pi update 只在有新提交时覆盖已安装副本;update.sh 每次成功升级后都把受管
|
||||
# checkout 还原到已发布版本,使对已安装副本的本地修改(包括扩展设置界面的
|
||||
# 保存)不积累。只对默认 git 来源的受管 checkout 执行:本地路径来源就是用户的
|
||||
# 工作仓库,绝不能 reset。不做 git clean,以保留 node_modules。
|
||||
restore_installed_bundle() {
|
||||
[ "${updated_bundle_managed_git:-0}" = "1" ] || return 0
|
||||
[ -d "$updated_bundle_dir/.git" ] || return 0
|
||||
if git -C "$updated_bundle_dir" reset --quiet --hard HEAD; then
|
||||
say "✓ 已还原已安装组合包中的本地修改"
|
||||
else
|
||||
record_update_failure "已安装组合包本地修改还原"
|
||||
fi
|
||||
printf '%s\n' "$HOME/.pi/agent"
|
||||
}
|
||||
|
||||
# 整体删除并重建组合包拥有的 <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,无法重建组合包配置目录。"
|
||||
return 1
|
||||
fi
|
||||
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 $rebuild_status in
|
||||
rebuilt:*) say "✓ 已重建组合包配置目录:${rebuild_status#rebuilt:}" ;;
|
||||
*)
|
||||
warn "组合包配置重建返回未知状态:$rebuild_status"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
resolve_zsh_paths() {
|
||||
oh_my_zsh_dir=${ZSH:-$HOME/.oh-my-zsh}
|
||||
zsh_custom_dir=${ZSH_CUSTOM:-$oh_my_zsh_dir/custom}
|
||||
zshrc_file=${ZDOTDIR:-$HOME}/.zshrc
|
||||
my_pi_config_dir=${XDG_CONFIG_HOME:-$HOME/.config}/my-pi
|
||||
p10k_managed_config_file=$my_pi_config_dir/p10k.zsh
|
||||
}
|
||||
|
||||
replace_zsh_managed_block() {
|
||||
managed_id=$1
|
||||
managed_placement=$2
|
||||
managed_anchor=$3
|
||||
shift 3
|
||||
managed_content=$(mktemp "${TMPDIR:-/tmp}/my-pi-zsh-block.XXXXXX") || return 1
|
||||
printf '%s\n' "$@" > "$managed_content"
|
||||
my_pi_replace_managed_block "$zshrc_file" "$managed_id" "$managed_content" \
|
||||
"$managed_placement" "$managed_anchor"
|
||||
managed_status=$?
|
||||
rm -f "$managed_content"
|
||||
return "$managed_status"
|
||||
}
|
||||
|
||||
update_git_checkout() {
|
||||
@@ -186,29 +136,6 @@ update_brew_formula_if_installed() {
|
||||
fi
|
||||
}
|
||||
|
||||
detect_kitty() {
|
||||
kitty_bin=
|
||||
if command -v kitty >/dev/null 2>&1; then
|
||||
kitty_bin=$(command -v kitty)
|
||||
return 0
|
||||
fi
|
||||
case $(uname -s) in
|
||||
Darwin) kitty_candidates="/Applications/kitty.app/Contents/MacOS/kitty" ;;
|
||||
*) kitty_candidates="$HOME/.local/kitty.app/bin/kitty" ;;
|
||||
esac
|
||||
for candidate in $kitty_candidates; do
|
||||
if [ -x "$candidate" ]; then
|
||||
kitty_bin=$candidate
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
resolve_kitty_config_dir() {
|
||||
kitty_config_dir=${KITTY_CONFIG_DIRECTORY:-${XDG_CONFIG_HOME:-$HOME/.config}/kitty}
|
||||
}
|
||||
|
||||
kitty_uses_solarized_dark() {
|
||||
resolve_kitty_config_dir
|
||||
[ -f "$kitty_config_dir/current-theme.conf" ] &&
|
||||
@@ -347,13 +274,13 @@ update_zsh_environment() {
|
||||
fi
|
||||
if my_pi_managed_block_exists "$zshrc_file" "powerlevel10k-theme"; then
|
||||
replace_zsh_managed_block "powerlevel10k-theme" "before" \
|
||||
'^(# >>> my-pi:oh-my-zsh-loader >>>|[[:space:]]*(source|\.)[[:space:]].*oh-my-zsh\.sh)' \
|
||||
"$MY_PI_ZSH_LOADER_ANCHOR" \
|
||||
'ZSH_THEME="powerlevel10k/powerlevel10k"' || record_update_failure ".zshrc Powerlevel10k 主题受管块"
|
||||
fi
|
||||
for plugin in git zsh-autosuggestions zsh-syntax-highlighting; do
|
||||
if my_pi_managed_block_exists "$zshrc_file" "zsh-plugin-$plugin"; then
|
||||
replace_zsh_managed_block "zsh-plugin-$plugin" "before" \
|
||||
'^(# >>> my-pi:oh-my-zsh-loader >>>|[[:space:]]*(source|\.)[[:space:]].*oh-my-zsh\.sh)' \
|
||||
"$MY_PI_ZSH_LOADER_ANCHOR" \
|
||||
"plugins+=($plugin)" || record_update_failure ".zshrc $plugin 受管块"
|
||||
fi
|
||||
done
|
||||
@@ -381,7 +308,7 @@ if ! pi update "$PACKAGE_SOURCE"; then
|
||||
exit 1
|
||||
fi
|
||||
select_updated_bundle_config || exit 1
|
||||
rebuild_bundle_config || record_update_failure "组合包配置重建"
|
||||
restore_installed_bundle
|
||||
|
||||
say "组合包升级完成,开始升级已安装的终端环境和机器级 CLI;未安装项将直接跳过。"
|
||||
update_kitty || record_update_failure "Kitty"
|
||||
|
||||
Reference in New Issue
Block a user