refactor: split pi-generic config into pi-toolkit repo

Parallel to the opencode-toolkit split earlier today. Pi's own config
(keybindings, shell env loader, settings template) moves to a new
sibling repo so opencode-devbox's mempalace opt-out can build slim
containers that include pi without dragging in chromadb + embedding
models (~300 MB).

What moved to pi-toolkit (https://gitea.jordbo.se/joakimp/pi-toolkit):
- extensions/pi/keybindings.json          (mosh/tmux newline fix)
- extensions/pi/pi-env.zsh                (sources ~/.config/pi/.env)
- extensions/pi/settings.example.json     (Bedrock template)
- install.sh::install_pi_keybindings      (symlink step)
- install.sh::install_pi_env_loader       (cp step + bash fallback)
- install.sh::check_pi_settings           (probe)
- install.sh::check_aws_env               (probe)

What stays here (this is the pi\u2194mempalace bridge, mempalace-side):
- extensions/pi/mempalace.ts              (the MCP extension)
- install.sh::install_pi_extension        (symlink step)
- NEW: install.sh::check_pi_toolkit       (probe: warns if pi is
                                           installed but pi-toolkit's
                                           artifacts are missing, with
                                           git-clone pointer)

install.sh shrank from 520 to 403 lines. Uninstall mirror correctly
does NOT touch pi-toolkit-owned files (explicit comment).

Docs updated:
- extensions/pi/README.md: rewritten as 'pi\u2194MemPalace MCP bridge',
  recipe becomes 'Deploying pi with mempalace' (pi-toolkit step 3,
  this repo step 5).
- AGENTS.md: Structure block + 'What install.sh does' section reflect
  the narrower scope and list the four things that moved out.
- README.md: repo-contents line + Setup section's deploy summary.

Verified on tor-ms22: full install\u2192uninstall\u2192reinstall lifecycle clean.
After mempalace-toolkit uninstall, pi-toolkit artifacts
(~/.pi/agent/keybindings.json, ~/.oh-my-zsh/custom/pi-env.zsh) remain
intact \u2014 correctly untouched. check_pi_toolkit probe fires green when
both exist.
This commit is contained in:
2026-05-05 17:26:53 +02:00
parent 3d3a0fb125
commit 16915f0e55
7 changed files with 178 additions and 454 deletions
+43 -175
View File
@@ -16,23 +16,13 @@ SKILL_SRC="${SCRIPT_DIR}/SKILL.md"
SKILL_DEST_DIR="${HOME}/.agents/skills/opencode-mempalace-bridge"
SKILL_DEST="${SKILL_DEST_DIR}/SKILL.md"
# pi coding-agent extension (optional — only linked if pi is installed)
# pi coding-agent MCP bridge extension (optional — only linked if pi is installed)
# Pi-generic config (env loader, keybindings, settings template) lives in
# the pi-toolkit repo; install it separately for the base pi bring-up.
PI_EXT_SRC="${SCRIPT_DIR}/extensions/pi/mempalace.ts"
PI_EXT_DEST_DIR="${HOME}/.pi/agent/extensions"
PI_EXT_DEST="${PI_EXT_DEST_DIR}/mempalace.ts"
# pi keybindings (generic mosh/tmux newline fix — safe on any machine)
PI_KEYS_SRC="${SCRIPT_DIR}/extensions/pi/keybindings.json"
PI_KEYS_DEST="${HOME}/.pi/agent/keybindings.json"
# pi settings template (NOT symlinked — pi rewrites this file at runtime)
PI_SETTINGS_EXAMPLE="${SCRIPT_DIR}/extensions/pi/settings.example.json"
PI_SETTINGS_DEST="${HOME}/.pi/agent/settings.json"
# pi env loader (shell glue that sources ~/.config/pi/.env into every shell)
PI_ENV_SRC="${SCRIPT_DIR}/extensions/pi/pi-env.zsh"
PI_ENV_OMZ_DEST="${HOME}/.oh-my-zsh/custom/pi-env.zsh"
# ── args ─────────────────────────────────────────────
ACTION="install"
ASSUME_YES="no"
@@ -56,31 +46,22 @@ What install does:
(auto-discovered by opencode; run agents-sync from cli_utils to also
reach Claude Code and Kiro)
- If pi (~/.pi/agent/extensions/) exists, symlinks extensions/pi/mempalace.ts
into ~/.pi/agent/extensions/mempalace.ts (pi bridge). Skipped otherwise.
- If pi exists, symlinks extensions/pi/keybindings.json into
~/.pi/agent/keybindings.json (generic mosh/tmux newline fix).
- If pi exists, warns if ~/.pi/agent/settings.json is missing and points
at extensions/pi/settings.example.json as a template (NOT symlinked —
pi rewrites this file at runtime).
- If oh-my-zsh is detected (~/.oh-my-zsh/custom/ exists), copies
extensions/pi/pi-env.zsh into ~/.oh-my-zsh/custom/pi-env.zsh so every
new zsh shell sources ~/.config/pi/.env. Uses cp (not symlink) because
that dir gets backed up by rsync_copy and symlinks would break
portability. Re-runs are idempotent when content matches the repo;
warns and leaves local edits alone if they differ.
- If oh-my-zsh is NOT detected, prints a shell-specific source snippet
for ~/.zshrc or ~/.bashrc. Does not auto-edit rc files.
- Warns if AWS_PROFILE / AWS_REGION are unset (only relevant to users
whose pi settings.json selects amazon-bedrock as defaultProvider).
into ~/.pi/agent/extensions/mempalace.ts (the pi↔mempalace MCP bridge).
Skipped on machines without pi.
- Warns if pi is installed but pi-toolkit doesn't appear to be (i.e. the
keybindings, env loader, and settings template are missing). pi-toolkit
is a separate repo owning pi's own config: split out 2026-05-05.
Clone: ssh://git@gitea.jordbo.se:2222/joakimp/pi-toolkit.git
- Drops a .skill-source marker in the skill dir so sibling tooling
(deploy-skills.sh, agents-sync.zsh) knows the dir is externally owned
What uninstall does:
- Removes symlinks in ~/.local/bin/ that point into this repo
- Removes the skill symlink if it points into this repo
- Removes the pi extension symlink if it points into this repo
- Removes the pi keybindings symlink if it points into this repo
- Removes the pi↔mempalace MCP bridge symlink if it points into this repo
- Removes the .skill-source marker and empty skill dir
- Does NOT touch pi-toolkit-owned artifacts (keybindings, env loader).
Run pi-toolkit/install.sh --uninstall for those.
EOF
exit 0 ;;
*) echo "Unknown flag: $1" >&2; exit 2 ;;
@@ -285,127 +266,38 @@ install_pi_extension() {
printf ' at startup only).\n'
}
install_pi_keybindings() {
# Generic mosh/tmux newline fix. Non-destructive: if a real
# keybindings.json exists we back it up rather than clobber.
[[ -d "$PI_EXT_DEST_DIR" ]] || return 0 # no pi → no keybindings
note "Linking pi keybindings → $PI_KEYS_DEST"
if [[ -e "$PI_KEYS_DEST" || -L "$PI_KEYS_DEST" ]]; then
if link_if_into_repo "$PI_KEYS_DEST"; then
ok "pi keybindings already linked"
return 0
fi
local backup="${PI_KEYS_DEST}.bak.$(date +%Y%m%d-%H%M%S)"
mv "$PI_KEYS_DEST" "$backup"
warn "Existing $PI_KEYS_DEST backed up to $backup"
fi
ln -s "$PI_KEYS_SRC" "$PI_KEYS_DEST"
ok "Linked keybindings.json → $PI_KEYS_SRC"
}
# ── Pi-toolkit detection ─────────────────────────────────────────
# Pi-generic config (keybindings, settings template, shell env loader) lives
# in the sibling pi-toolkit repo. This file used to own those; the split
# happened 2026-05-05 so opencode-devbox can build slim containers that
# include pi without dragging in mempalace. We don't install those artifacts
# here — we only print a pointer when pi is detected but pi-toolkit isn't.
check_pi_toolkit() {
[[ -d "$PI_EXT_DEST_DIR" ]] || return 0 # no pi → nothing to say
install_pi_env_loader() {
# Ship pi-env.zsh (sources ~/.config/pi/.env so AWS vars etc. are in
# every shell that starts pi). Two paths depending on shell setup:
#
# 1. oh-my-zsh present → cp into ~/.oh-my-zsh/custom/ (auto-loaded by
# omz). cp not symlink because that directory is typically part of
# a dotfiles backup (rsync_copy.sh in the myconfigs repo) and a
# symlink into mempalace-toolkit would break when restored on
# another host.
# 2. No oh-my-zsh → print a source snippet for ~/.zshrc or ~/.bashrc.
# We don't auto-edit rc files — too invasive for an optional glue
# file. The loader itself is POSIX-compatible (set -a / source /
# set +a), so bash users can source it directly.
# Best-effort detection: pi-toolkit installs keybindings.json as a
# symlink and copies pi-env.zsh into ~/.oh-my-zsh/custom/. We don't
# know where the pi-toolkit repo is cloned, so just check whether the
# downstream artifacts exist.
local has_keys="no"
local has_env="no"
[[ -L "$HOME/.pi/agent/keybindings.json" ]] && has_keys="yes"
[[ -f "$HOME/.oh-my-zsh/custom/pi-env.zsh" ]] && has_env="yes"
[[ -d "$PI_EXT_DEST_DIR" ]] || return 0 # no pi → skip
if [[ -d "$HOME/.oh-my-zsh/custom" ]]; then
note "Installing pi-env.zsh into ~/.oh-my-zsh/custom/"
if [[ -f "$PI_ENV_OMZ_DEST" ]]; then
if cmp -s "$PI_ENV_SRC" "$PI_ENV_OMZ_DEST"; then
ok "pi-env.zsh already installed (content matches repo)"
return 0
fi
warn "$PI_ENV_OMZ_DEST exists and differs from repo copy"
printf ' Leaving your edits alone. Compare with:\n'
printf ' diff %q %q\n' "$PI_ENV_OMZ_DEST" "$PI_ENV_SRC"
printf ' To adopt the repo version: rm that file and re-run install.sh\n'
return 0
fi
cp "$PI_ENV_SRC" "$PI_ENV_OMZ_DEST"
ok "Copied pi-env.zsh → $PI_ENV_OMZ_DEST"
printf ' Open a new shell (or `exec zsh`) to load AWS_PROFILE / AWS_REGION.\n'
if [[ "$has_keys" == "yes" || "$has_env" == "yes" ]]; then
ok "pi-toolkit artifacts detected (keybindings=$has_keys env-loader=$has_env)"
return 0
fi
# No oh-my-zsh — print shell-specific snippet.
note "oh-my-zsh not detected — manual shell setup needed"
local shell_name
shell_name="$(basename "${SHELL:-bash}")"
local rc_file
case "$shell_name" in
zsh) rc_file="~/.zshrc" ;;
bash) rc_file="~/.bashrc" ;;
*) rc_file="~/.${shell_name}rc # adjust for your shell" ;;
esac
printf ' Add this line to %s so every shell sources ~/.config/pi/.env:\n' "$rc_file"
printf ' source %q\n' "$PI_ENV_SRC"
printf ' (the loader itself is POSIX-compatible — works in bash and zsh.)\n'
}
# ── Verify ~/.pi/agent/settings.json exists ──────────────────────────
# If pi is installed but settings.json is missing, `pi` refuses to start
# without `--provider ... --model ...` on every invocation. The toolkit
# ships extensions/pi/settings.example.json as a template with a working
# Bedrock (eu-west-1) stanza — copy + edit for your region/account.
#
# NOT symlinked: pi rewrites settings.json at runtime (lastChangelogVersion
# bumps on upgrade), which would dirty the repo and cause merge noise.
# Template-only install is the right trade-off.
check_pi_settings() {
[[ -d "$PI_EXT_DEST_DIR" ]] || return 0 # no pi → nothing to check
if [[ -f "$PI_SETTINGS_DEST" ]]; then
ok "pi settings.json present at $PI_SETTINGS_DEST"
return 0
fi
warn "pi settings.json NOT found at $PI_SETTINGS_DEST"
printf ' Without it, pi must be invoked with --provider/--model on every run.\n'
printf ' Bootstrap from the shipped template:\n'
printf ' cp %q %q\n' "$PI_SETTINGS_EXAMPLE" "$PI_SETTINGS_DEST"
printf ' $EDITOR %q # adjust region prefix + model IDs\n' "$PI_SETTINGS_DEST"
printf ' See extensions/pi/README.md for the eu./us./anthropic: prefix rules.\n'
return 0
}
# ── Verify AWS env vars are present for Bedrock-backed pi ────────────
# Only meaningful if pi's settings.json selects amazon-bedrock. We do a
# best-effort grep rather than parsing JSON — false positives are cheap
# (one extra probe) and the check is gated on pi being installed at all.
check_aws_env() {
[[ -d "$PI_EXT_DEST_DIR" ]] || return 0 # no pi → nothing to check
# Only warn if settings.json selects amazon-bedrock. If pi uses a
# non-Bedrock provider (bare anthropic, openai, ...) AWS creds are
# irrelevant and this probe would be noise. If settings.json doesn't
# exist yet, check_pi_settings already told the user to bootstrap it
# — we can't know which provider they'll pick, so stay quiet here.
[[ -f "$PI_SETTINGS_DEST" ]] || return 0
grep -q '"amazon-bedrock"' "$PI_SETTINGS_DEST" 2>/dev/null || return 0
if [[ -n "${AWS_PROFILE:-}" && -n "${AWS_REGION:-}" ]]; then
ok "AWS env present (AWS_PROFILE=$AWS_PROFILE, AWS_REGION=$AWS_REGION)"
return 0
fi
warn "AWS_PROFILE and/or AWS_REGION not set in this shell"
printf ' pi with defaultProvider=amazon-bedrock needs both to invoke Bedrock.\n'
printf ' Recommended layout (matches the tor-ms22 dotfiles pattern):\n'
printf ' ~/.config/pi/.env # AWS_PROFILE=..., AWS_REGION=...\n'
printf ' ~/.oh-my-zsh/custom/pi-env.zsh # set -a; source ~/.config/pi/.env; set +a\n'
printf ' See extensions/pi/README.md#environment-setup for the template.\n'
warn "pi detected but pi-toolkit doesn't appear installed"
printf ' pi-toolkit ships pi'"'"'s own config (keybindings, env loader,\n'
printf ' settings template) — formerly part of this repo, split out\n'
printf ' 2026-05-05. Install it separately for the full pi bring-up:\n'
printf ' git clone ssh://git@gitea.jordbo.se:2222/joakimp/pi-toolkit.git\n'
printf ' cd pi-toolkit && ./install.sh\n'
printf ' This toolkit'"'"'s install still does the pi↔mempalace MCP bridge\n'
printf ' (mempalace.ts extension) regardless — that part is mempalace-side.\n'
return 0
}
@@ -419,7 +311,7 @@ do_install() {
echo " Symlink SKILL.md into $SKILL_DEST"
if [[ -d "$PI_EXT_DEST_DIR" ]]; then
echo " Symlink extensions/pi/mempalace.ts into $PI_EXT_DEST"
echo " Symlink extensions/pi/keybindings.json into $PI_KEYS_DEST"
echo " (install pi-toolkit separately for keybindings + env loader + settings template)"
fi
echo
confirm || { echo "Aborted."; exit 0; }
@@ -430,19 +322,13 @@ do_install() {
echo
install_pi_extension
echo
install_pi_keybindings
echo
install_pi_env_loader
echo
check_path
echo
check_wake_up_protocol
echo
check_opencode_mcp
echo
check_pi_settings
echo
check_aws_env
check_pi_toolkit
echo
ok "Done."
echo
@@ -491,27 +377,9 @@ do_uninstall() {
ok "No pi extension symlink to remove"
fi
echo
note "Removing pi keybindings symlink"
if link_if_into_repo "$PI_KEYS_DEST"; then
rm "$PI_KEYS_DEST"
ok "Removed pi keybindings symlink"
else
ok "No pi keybindings symlink to remove"
fi
echo
note "Removing pi-env.zsh loader (oh-my-zsh path)"
# Only remove if content still matches the repo copy — user may have
# local edits we shouldn't silently discard.
if [[ -f "$PI_ENV_OMZ_DEST" ]] && cmp -s "$PI_ENV_SRC" "$PI_ENV_OMZ_DEST"; then
rm "$PI_ENV_OMZ_DEST"
ok "Removed $PI_ENV_OMZ_DEST"
elif [[ -f "$PI_ENV_OMZ_DEST" ]]; then
warn "$PI_ENV_OMZ_DEST differs from repo copy — left alone"
else
ok "No pi-env.zsh loader to remove"
fi
# Note: pi keybindings + pi-env.zsh loader are owned by pi-toolkit now
# (split 2026-05-05). Run `pi-toolkit/install.sh --uninstall` to remove
# those artifacts. We deliberately do not touch them here.
# Remove the marker and the now-empty skill directory, but only if
# the marker was written by us and the directory has nothing else in it.