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
+22
-97
@@ -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
|
||||
@@ -21,14 +21,6 @@ ZSH_AUTOSUGGESTIONS_REPOSITORY=https://github.com/zsh-users/zsh-autosuggestions.
|
||||
ZSH_SYNTAX_HIGHLIGHTING_REPOSITORY=https://github.com/zsh-users/zsh-syntax-highlighting.git
|
||||
install_failed=0
|
||||
|
||||
say() {
|
||||
printf '%s\n' "$*"
|
||||
}
|
||||
|
||||
warn() {
|
||||
printf '警告: %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
ask_yes_no() {
|
||||
prompt=$1
|
||||
printf '%s [y/N] ' "$prompt"
|
||||
@@ -64,42 +56,6 @@ record_install_failure() {
|
||||
install_failed=1
|
||||
}
|
||||
|
||||
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
|
||||
fi
|
||||
printf '%s\n' "$HOME/.pi/agent"
|
||||
}
|
||||
|
||||
# 整体删除并重建组合包拥有的 <agentDir>/my-pi/ 配置目录;脚本目录内的组合包副本即为来源。
|
||||
rebuild_bundle_config() {
|
||||
rebuild_helper=$SCRIPT_DIR/scripts/rebuild-bundle-config.mjs
|
||||
if [ ! -f "$rebuild_helper" ]; then
|
||||
warn "找不到组合包配置重建辅助脚本,已跳过配置重建。"
|
||||
return 1
|
||||
fi
|
||||
if ! command -v node >/dev/null 2>&1; then
|
||||
warn "找不到 node,无法重建组合包配置目录。"
|
||||
return 1
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
java_major_version() {
|
||||
java_version=$(java -version 2>&1 | awk -F '"' 'NR == 1 { print $2 }')
|
||||
case $java_version in
|
||||
@@ -117,7 +73,13 @@ install_codegraph() {
|
||||
warn "安装 CodeGraph 需要 curl。"
|
||||
return 1
|
||||
fi
|
||||
curl -fsSL "$CODEGRAPH_INSTALL_URL" | sh || return 1
|
||||
codegraph_installer=$(mktemp "${TMPDIR:-/tmp}/my-pi-codegraph.XXXXXX") || return 1
|
||||
if ! curl -fsSL "$CODEGRAPH_INSTALL_URL" -o "$codegraph_installer" || \
|
||||
! sh "$codegraph_installer"; then
|
||||
rm -f "$codegraph_installer"
|
||||
return 1
|
||||
fi
|
||||
rm -f "$codegraph_installer"
|
||||
|
||||
# 官方安装器默认使用 ~/.local/bin;让本次检查立即看到新命令。
|
||||
if [ -d "$HOME/.local/bin" ]; then
|
||||
@@ -152,21 +114,6 @@ install_jdtls() {
|
||||
command -v jdtls >/dev/null 2>&1
|
||||
}
|
||||
|
||||
detect_kitty() {
|
||||
kitty_bin=
|
||||
if command -v kitty >/dev/null 2>&1; then
|
||||
kitty_bin=$(command -v kitty)
|
||||
return 0
|
||||
fi
|
||||
for candidate in /Applications/kitty.app/Contents/MacOS/kitty "$HOME/.local/kitty.app/bin/kitty"; do
|
||||
if [ -x "$candidate" ]; then
|
||||
kitty_bin=$candidate
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
install_kitty() {
|
||||
case $(uname -s) in
|
||||
Darwin)
|
||||
@@ -178,16 +125,18 @@ install_kitty() {
|
||||
warn "安装 Kitty 需要 curl。"
|
||||
return 1
|
||||
fi
|
||||
curl -L "$KITTY_INSTALL_URL" | sh /dev/stdin || return 1
|
||||
installer_file=$(mktemp "${TMPDIR:-/tmp}/my-pi-kitty.XXXXXX") || return 1
|
||||
if ! curl -fsSL "$KITTY_INSTALL_URL" -o "$installer_file" || \
|
||||
! sh "$installer_file"; then
|
||||
rm -f "$installer_file"
|
||||
return 1
|
||||
fi
|
||||
rm -f "$installer_file"
|
||||
;;
|
||||
esac
|
||||
detect_kitty
|
||||
}
|
||||
|
||||
resolve_kitty_config_dir() {
|
||||
kitty_config_dir=${KITTY_CONFIG_DIRECTORY:-${XDG_CONFIG_HOME:-$HOME/.config}/kitty}
|
||||
}
|
||||
|
||||
kitty_solarized_dark_configured() {
|
||||
resolve_kitty_config_dir
|
||||
[ -f "$kitty_config_dir/current-theme.conf" ] || return 1
|
||||
@@ -201,14 +150,6 @@ configure_kitty_solarized_dark() {
|
||||
"$kitty_bin" +kitten themes --reload-in=none "Solarized Dark"
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
oh_my_zsh_installed() {
|
||||
resolve_zsh_paths
|
||||
[ -f "$oh_my_zsh_dir/oh-my-zsh.sh" ]
|
||||
@@ -238,20 +179,6 @@ prepare_zshrc() {
|
||||
[ -f "$zshrc_file" ] || : > "$zshrc_file" || return 1
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
zshrc_has_oh_my_zsh_loader() {
|
||||
[ -f "$zshrc_file" ] || return 1
|
||||
grep -E '^[[:space:]]*(source|\.)[[:space:]].*oh-my-zsh\.sh' "$zshrc_file" >/dev/null 2>&1
|
||||
@@ -270,7 +197,7 @@ ensure_oh_my_zsh_loader() {
|
||||
set_powerlevel10k_theme() {
|
||||
prepare_zshrc || return 1
|
||||
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"'
|
||||
}
|
||||
|
||||
@@ -327,7 +254,7 @@ add_zsh_plugin() {
|
||||
prepare_zshrc || return 1
|
||||
ensure_oh_my_zsh_loader || return 1
|
||||
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)"
|
||||
}
|
||||
|
||||
@@ -369,9 +296,7 @@ if ! pi install "$PACKAGE_SOURCE"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
say "Pi 组合包安装完成,开始部署受管配置。"
|
||||
|
||||
rebuild_bundle_config || record_install_failure "组合包配置重建"
|
||||
say "Pi 组合包安装完成。"
|
||||
|
||||
say "开始检查终端环境和机器级 CLI 依赖。"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user