vault-sync: 2026-09-16 00:00 (jimmy)

This commit is contained in:
jimmy
2026-09-16 00:00:30 -07:00
parent cf3c882c94
commit 00719428b2
194 changed files with 42289 additions and 0 deletions
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# =============================================================================
# scripts/build.sh — Run the platform adapter to populate dist/<platform>/
# =============================================================================
# Usage: bash scripts/build.sh --platform <name>
# Discovers available platforms by listing adapters/ subdirectories.
# =============================================================================
set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# shellcheck source=scripts/lib.sh
source "$SCRIPT_DIR/lib.sh"
# ── Parse args ─────────────────────────────────────────────────────────────
PLATFORM="claude-code"
while [[ $# -gt 0 ]]; do
case "$1" in
--platform) PLATFORM="$2"; shift 2 ;;
*) die "Unknown argument: $1" ;;
esac
done
# ── Validate platform ─────────────────────────────────────────────────────
if [[ ! -d "$REPO_ROOT/adapters/$PLATFORM" ]]; then
AVAILABLE="$(ls "$REPO_ROOT/adapters/" 2>/dev/null | grep -v '^lib.sh$' | tr '\n' ' ')"
die "Unknown platform: $PLATFORM. Available: $AVAILABLE"
fi
# ── Check dependencies ─────────────────────────────────────────────────────
case "$PLATFORM" in
codex-cli) ;;
*)
command -v jq >/dev/null 2>&1 || die "jq is required for the build (install via brew, apt, etc.)"
;;
esac
# ── Source adapters ────────────────────────────────────────────────────────
# shellcheck source=adapters/lib.sh
source "$REPO_ROOT/adapters/lib.sh"
# shellcheck source=/dev/null
source "$REPO_ROOT/adapters/$PLATFORM/adapter.sh"
# ── Run the build ──────────────────────────────────────────────────────────
DIST_DIR="$REPO_ROOT/dist/$PLATFORM"
info "Building $PLATFORM → $DIST_DIR"
adapter_build "$REPO_ROOT" "$DIST_DIR"
success "Build complete"
@@ -0,0 +1,337 @@
#!/usr/bin/env bash
# =============================================================================
# My Brain Is Full - Crew :: Installer
# =============================================================================
# Run this from inside the cloned repo, which should be inside your vault:
#
# cd /path/to/your-vault/My-Brain-Is-Full-Crew
# bash scripts/launchme.sh
#
# It builds and copies agents, skills, references, hooks, and settings into
# the vault's platform directory.
#
# Options:
# --platform <name> Platform to build for (interactive selection if omitted)
# --target <path> Override the vault destination path
# =============================================================================
set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/lib.sh
source "$SCRIPT_DIR/lib.sh"
resolve_paths "${BASH_SOURCE[0]}"
# ── Parse args ─────────────────────────────────────────────────────────────
PLATFORM=""
TARGET_OVERRIDE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--platform) PLATFORM="$2"; shift 2 ;;
--target) TARGET_OVERRIDE="$2"; shift 2 ;;
*) die "Unknown argument: $1 (use --platform <name> or --target <path>)" ;;
esac
done
[[ -n "$TARGET_OVERRIDE" ]] && VAULT_DIR="$TARGET_OVERRIDE"
# ── Platform selection (interactive if not specified) ──────────────────────
if [[ -z "$PLATFORM" ]]; then
# Discover available platforms from adapters/ directories
AVAILABLE=()
for d in "$REPO_DIR/adapters/"*/; do
[[ -f "${d}adapter.sh" ]] || continue
AVAILABLE+=("$(basename "$d")")
done
if [[ ${#AVAILABLE[@]} -eq 0 ]]; then
die "No adapters found in adapters/"
fi
echo ""
echo -e " ${BOLD}Select your agent platform:${NC}"
echo ""
for i in "${!AVAILABLE[@]}"; do
echo -e " ${BOLD}$((i+1)))${NC} ${AVAILABLE[$i]}"
done
echo ""
if ! read -r -p " > " PLATFORM_CHOICE 2>/dev/null; then PLATFORM_CHOICE=""; fi
# Accept either number or name
if [[ "$PLATFORM_CHOICE" =~ ^[0-9]+$ ]] && (( PLATFORM_CHOICE >= 1 && PLATFORM_CHOICE <= ${#AVAILABLE[@]} )); then
PLATFORM="${AVAILABLE[$((PLATFORM_CHOICE-1))]}"
else
# Try matching by name
for p in "${AVAILABLE[@]}"; do
if [[ "$p" == "$PLATFORM_CHOICE" ]]; then
PLATFORM="$p"
break
fi
done
fi
[[ -n "$PLATFORM" ]] || die "Invalid selection: $PLATFORM_CHOICE"
echo ""
info "Selected platform: $PLATFORM"
fi
# ── Banner ────────────────────────────────────────────────────────────────────
print_banner "Setup "
echo -e " Repo: ${BOLD}${REPO_DIR}${NC}"
echo -e " Vault: ${BOLD}${VAULT_DIR}${NC}"
echo ""
# ── Confirm vault location ────────────────────────────────────────────────────
if [[ -z "$TARGET_OVERRIDE" ]]; then
echo -e "${BOLD}Is this your Obsidian vault folder?${NC}"
echo -e " ${DIM}${VAULT_DIR}${NC}"
echo ""
echo -e " ${BOLD}y)${NC} Yes, install here"
echo -e " ${BOLD}n)${NC} No, let me type the correct path"
if ! read -r -p " > " CONFIRM 2>/dev/null; then CONFIRM=""; fi
if [[ "$CONFIRM" =~ ^[Nn]$ ]]; then
echo ""
echo -e "${BOLD}Enter the full path to your Obsidian vault:${NC}"
if ! read -r -p " > " VAULT_DIR 2>/dev/null; then
die "Cannot read input — are you running in a non-interactive shell?"
fi
VAULT_DIR="${VAULT_DIR/#\~/$HOME}"
[[ -d "$VAULT_DIR" ]] || die "Directory not found: $VAULT_DIR"
fi
fi
# ── Check for existing installation ──────────────────────────────────────────
EXISTING=0
[[ -d "$VAULT_DIR/.claude" ]] && EXISTING=1
[[ -d "$VAULT_DIR/.opencode" ]] && EXISTING=1
[[ -d "$VAULT_DIR/.gemini" ]] && EXISTING=1
[[ -d "$VAULT_DIR/.codex" ]] && EXISTING=1
[[ -f "$VAULT_DIR/CLAUDE.md" ]] && EXISTING=1
[[ -f "$VAULT_DIR/AGENTS.md" ]] && EXISTING=1
[[ -f "$VAULT_DIR/GEMINI.md" ]] && EXISTING=1
if [[ $EXISTING -eq 1 ]]; then
warn "An existing installation was detected:"
[[ -d "$VAULT_DIR/.claude" ]] && warn " .claude/ directory exists"
[[ -d "$VAULT_DIR/.opencode" ]] && warn " .opencode/ directory exists"
[[ -d "$VAULT_DIR/.gemini" ]] && warn " .gemini/ directory exists"
[[ -d "$VAULT_DIR/.codex" ]] && warn " .codex/ directory exists"
[[ -f "$VAULT_DIR/CLAUDE.md" ]] && warn " CLAUDE.md exists"
[[ -f "$VAULT_DIR/AGENTS.md" ]] && warn " AGENTS.md exists"
[[ -f "$VAULT_DIR/GEMINI.md" ]] && warn " GEMINI.md exists"
echo ""
echo -e " ${BOLD}The installer will overwrite core files. Custom agents are never deleted.${NC}"
echo -e " ${DIM}Your vault notes are never touched.${NC}"
echo ""
echo -e " ${BOLD}c)${NC} Continue"
echo -e " ${BOLD}q)${NC} Quit"
if ! read -r -p " > " ANSWER 2>/dev/null; then ANSWER=""; fi
if [[ ! "$ANSWER" =~ ^[Cc]$ ]]; then
echo ""; info "Installation cancelled."; echo ""; exit 0
fi
fi
echo ""
# ── Build the platform dist ───────────────────────────────────────────────
info "Building $PLATFORM adapter..."
bash "$SCRIPT_DIR/build.sh" --platform "$PLATFORM"
DIST_DIR="$REPO_DIR/dist/$PLATFORM"
[[ -d "$DIST_DIR" ]] || die "Build did not produce $DIST_DIR"
# ── Platform-specific install layout ────────────────────────────────────────
case "$PLATFORM" in
claude-code)
DIST_COMPONENTS_DIR="$DIST_DIR/.claude"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.claude"
DISPATCHER_SRC="$DIST_DIR/CLAUDE.md"
DISPATCHER_DST="$VAULT_DIR/CLAUDE.md"
MCP_SRC="$DIST_DIR/.mcp.json"
MCP_DST="$VAULT_DIR/.mcp.json"
HAS_PLUGINS=0
;;
opencode)
DIST_COMPONENTS_DIR="$DIST_DIR/.opencode"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.opencode"
DISPATCHER_SRC="$DIST_DIR/AGENTS.md"
DISPATCHER_DST="$VAULT_DIR/AGENTS.md"
MCP_SRC="$DIST_DIR/opencode.json"
MCP_DST="$VAULT_DIR/opencode.json"
HAS_PLUGINS=1
;;
gemini-cli)
DIST_COMPONENTS_DIR="$DIST_DIR/.gemini"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.gemini"
DISPATCHER_SRC="$DIST_DIR/GEMINI.md"
DISPATCHER_DST="$VAULT_DIR/GEMINI.md"
MCP_SRC=""
MCP_DST=""
HAS_PLUGINS=0
DIST_SKILLS_DIR="$DIST_COMPONENTS_DIR/skills"
VAULT_SKILLS_DIR="$VAULT_COMPONENTS_DIR/skills"
;;
codex-cli)
DIST_COMPONENTS_DIR="$DIST_DIR/.codex"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.codex"
DISPATCHER_SRC="$DIST_DIR/AGENTS.md"
DISPATCHER_DST="$VAULT_DIR/AGENTS.md"
MCP_SRC="$DIST_DIR/.codex/config.toml"
MCP_DST="$VAULT_DIR/.codex/config.toml"
HAS_PLUGINS=0
DIST_SKILLS_DIR="$DIST_DIR/.agents/skills"
VAULT_SKILLS_DIR="$VAULT_DIR/.agents/skills"
;;
*)
die "Unknown platform: $PLATFORM (install layout not defined)"
;;
esac
[[ -n "${DIST_SKILLS_DIR:-}" ]] || DIST_SKILLS_DIR="$DIST_COMPONENTS_DIR/skills"
[[ -n "${VAULT_SKILLS_DIR:-}" ]] || VAULT_SKILLS_DIR="$VAULT_COMPONENTS_DIR/skills"
PLATFORM_VAULT_DIR="$VAULT_COMPONENTS_DIR"
# Load opencode-specific helpers when building for opencode
if [[ "$PLATFORM" == "opencode" ]]; then
# shellcheck source=adapters/opencode/config-merge.sh
source "$REPO_DIR/adapters/opencode/config-merge.sh"
fi
# ── Migrate legacy manifests (if any) ────────────────────────────────────────
manifest_migrate
# ── Deprecate agents/refs removed from repo (reinstall only) ─────────────────
DEP_COUNT=0
if [[ $EXISTING -eq 1 ]]; then
DEP_COUNT=$(deprecate_removed "agents" "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
DEP_COUNT=$((DEP_COUNT + $(deprecate_removed "references" "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")))
fi
# ── Ensure vault support dirs ─────────────────────────────────────────────────
mkdir -p "$VAULT_DIR/Meta/states"
# ── Install components ────────────────────────────────────────────────────────
info "Installing agents..."
if [[ "$PLATFORM" == "codex-cli" ]]; then
AGENT_COUNT=$(install_toml_agents "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
else
AGENT_COUNT=$(install_agents "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
fi
success "Agents: $AGENT_COUNT installed/updated"
info "Installing references..."
REF_COUNT=$(install_refs "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")
success "References: $REF_COUNT installed/updated"
info "Installing skills..."
SKILL_COUNT=$(install_skills "$DIST_SKILLS_DIR" "$VAULT_SKILLS_DIR")
success "Skills: $SKILL_COUNT installed/updated"
info "Installing hooks..."
HOOK_COUNT=$(install_hooks "$DIST_COMPONENTS_DIR/hooks" "$VAULT_COMPONENTS_DIR/hooks")
success "Hooks: $HOOK_COUNT installed/updated"
# ── Deprecate stale orchestra scripts on reinstall ──────────────────────────
OLD_ORCH_MANIFEST="$VAULT_DIR/Meta/scripts/.core-manifest"
if [[ $EXISTING -eq 1 && -f "$OLD_ORCH_MANIFEST" ]]; then
while IFS= read -r old_script; do
[[ -z "$old_script" ]] && continue
[[ -f "$REPO_DIR/orchestra/$old_script" ]] && continue
vault_script="$VAULT_DIR/Meta/scripts/$old_script"
[[ -f "$vault_script" ]] || continue
rm "$vault_script"
warn "Removed stale script: $old_script"
done < "$OLD_ORCH_MANIFEST"
fi
# ── Copy orchestra scripts ──────────────────────────────────────────────────
ORCH_COUNT=0
if [[ -d "$REPO_DIR/orchestra" ]]; then
mkdir -p "$VAULT_DIR/Meta/scripts"
: > "$VAULT_DIR/Meta/scripts/.core-manifest"
for script in "$REPO_DIR/orchestra/"*; do
[[ -f "$script" ]] || continue
bname="$(basename "$script")"
[[ "$bname" == "README.md" ]] && continue
cp "$script" "$VAULT_DIR/Meta/scripts/"
chmod +x "$VAULT_DIR/Meta/scripts/$bname"
echo "$bname" >> "$VAULT_DIR/Meta/scripts/.core-manifest"
ORCH_COUNT=$((ORCH_COUNT + 1))
done
success "Copied $ORCH_COUNT orchestra scripts to Meta/scripts/"
fi
PLUGIN_COUNT=0
if [[ $HAS_PLUGINS -eq 1 && -d "$DIST_COMPONENTS_DIR/plugins" ]]; then
info "Installing plugins..."
PLUGIN_COUNT=$(install_plugins "$DIST_COMPONENTS_DIR/plugins" "$VAULT_COMPONENTS_DIR/plugins")
success "Plugins: $PLUGIN_COUNT installed/updated"
fi
# settings.json only exists for claude-code (hook config lives in the JS plugin on opencode)
if [[ -f "$DIST_COMPONENTS_DIR/settings.json" ]]; then
install_settings "$DIST_COMPONENTS_DIR/settings.json" "$VAULT_COMPONENTS_DIR"
fi
install_dispatcher "$DISPATCHER_SRC" "$DISPATCHER_DST"
# ── MCP / opencode.json ───────────────────────────────────────────────────────
if [[ -f "$MCP_SRC" ]]; then
if [[ "$PLATFORM" == "opencode" && -f "$MCP_DST" ]]; then
oc_config_merge "$MCP_SRC" "$MCP_DST" "$MCP_DST"
info "Merged opencode.json (user config preserved)"
else
copy_if_changed "$MCP_SRC" "$MCP_DST"
fi
fi
# ── Done ──────────────────────────────────────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD} Setup complete!${NC}"
echo ""
echo -e " ${VAULT_DIR}/"
FW_DIR_NAME="$(basename "$VAULT_COMPONENTS_DIR")"
DISPATCHER_NAME="$(basename "$DISPATCHER_DST")"
if [[ "$PLATFORM" == "codex-cli" ]]; then
echo -e " ├── .codex/"
echo -e " │ ├── agents/ ${DIM}← custom agents${NC}"
echo -e " │ ├── references/ ${DIM}← shared docs${NC}"
echo -e " │ └── config.toml ${DIM}← MCP + profiles${NC}"
echo -e " ├── .agents/"
echo -e " │ └── skills/ ${DIM}← repo skills${NC}"
else
echo -e " ├── ${FW_DIR_NAME}/"
echo -e " │ ├── agents/ ${DIM}← agents${NC}"
echo -e " │ ├── skills/ ${DIM}← skills${NC}"
echo -e " │ ├── hooks/ ${DIM}← hooks${NC}"
if [[ $HAS_PLUGINS -eq 1 ]]; then
echo -e " │ ├── plugins/ ${DIM}← hook plugins${NC}"
else
echo -e " │ ├── settings.json ${DIM}← hooks configuration${NC}"
fi
echo -e " │ └── references/ ${DIM}← shared docs${NC}"
fi
echo -e " ├── Meta/"
echo -e " │ └── scripts/ ${DIM}← ${ORCH_COUNT:-0} orchestra scripts${NC}"
if [[ "$PLATFORM" == "codex-cli" && -f "$MCP_DST" ]]; then
echo -e " └── ${DISPATCHER_NAME} ${DIM}← project instructions${NC}"
elif [[ -n "$MCP_SRC" && -f "$MCP_DST" ]]; then
echo -e " ├── ${DISPATCHER_NAME} ${DIM}← project instructions${NC}"
echo -e " └── $(basename "$MCP_DST") ${DIM}← MCP servers${NC}"
else
echo -e " └── ${DISPATCHER_NAME} ${DIM}← project instructions${NC}"
fi
if [[ $DEP_COUNT -gt 0 ]]; then
echo ""
warn "$DEP_COUNT file(s) were deprecated (moved to ${FW_DIR_NAME}/deprecated/)"
fi
echo ""
echo -e " ${BOLD}Next steps:${NC}"
case "$PLATFORM" in
claude-code) echo -e " 1. Open Claude Code in your vault folder" ;;
opencode) echo -e " 1. Open OpenCode in your vault folder" ;;
gemini-cli) echo -e " 1. Open Gemini CLI in your vault folder" ;;
codex-cli) echo -e " 1. Open Codex CLI in your vault folder (run: codex)" ;;
*) echo -e " 1. Open your agent platform in your vault folder" ;;
esac
echo -e " 2. Say: ${BOLD}\"Initialize my vault\"${NC}"
echo -e " 3. The Architect will guide you through setup"
echo ""
echo -e " ${DIM}To update after a git pull: bash scripts/updateme.sh${NC}"
echo ""
@@ -0,0 +1,500 @@
#!/usr/bin/env bash
# =============================================================================
# My Brain Is Full - Crew :: Shared library
# Sourced by launchme.sh and updateme.sh — do NOT execute directly.
# =============================================================================
# ── Colors ────────────────────────────────────────────────────────────────────
if [[ -t 1 ]]; then
GREEN='\033[0;32m'; CYAN='\033[0;36m'; YELLOW='\033[1;33m'
RED='\033[0;31m'; BOLD='\033[1m'; DIM='\033[2m'; NC='\033[0m'
else
GREEN=''; CYAN=''; YELLOW=''; RED=''; BOLD=''; DIM=''; NC=''
fi
# ── Logging ───────────────────────────────────────────────────────────────────
# Everything is on stderr to keep stdout clean for machine-readable output in updateme.sh.
info() { echo -e " ${CYAN}>${NC} $*" >&2; }
success() { echo -e " ${GREEN}✓${NC} $*" >&2; }
warn() { echo -e " ${YELLOW}!${NC} $*" >&2; }
die() { echo -e "\n ${RED}Error: $*${NC}\n" >&2; exit 1; }
# ── Path resolution ───────────────────────────────────────────────────────────
# Sets SCRIPT_DIR, REPO_DIR, VAULT_DIR globals.
# Usage: resolve_paths "${BASH_SOURCE[0]}"
resolve_paths() {
SCRIPT_DIR="$(cd "$(dirname "$1")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
VAULT_DIR="$(cd "$REPO_DIR/.." && pwd)"
[[ -d "$REPO_DIR/agents" ]] || die "Can't find agents/ in $REPO_DIR — are you running this from the repo?"
[[ -d "$REPO_DIR/references" ]] || die "Can't find references/ in $REPO_DIR"
}
# ── Change tracking ───────────────────────────────────────────────────────────
# Set by copy_if_changed and merge_marked_file after every call.
_LAST_CHANGED=0
# Controls per-file logging in install_* functions.
# Set VERBOSE_COPY=1 in the caller for per-file change output (used by updateme.sh).
VERBOSE_COPY=0
# ── copy_if_changed <src> <dst> ───────────────────────────────────────────────
# Copies src to dst only when they differ or dst doesn't exist.
# Sets _LAST_CHANGED=1 if a copy was made, 0 otherwise.
copy_if_changed() {
local src="$1" dst="$2"
_LAST_CHANGED=0
if ! diff -q "$src" "$dst" >/dev/null 2>&1; then
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
_LAST_CHANGED=1
fi
}
# ── copy_tree_if_changed <src_dir> <dst_dir> ────────────────────────────────
# Overlays a source directory tree onto the destination when files differ or
# the destination does not exist. This preserves nested skill assets/scripts
# needed by platforms such as Codex CLI.
copy_tree_if_changed() {
local src="$1" dst="$2"
_LAST_CHANGED=0
if [[ ! -d "$dst" ]] || ! diff -qr "$src" "$dst" >/dev/null 2>&1; then
mkdir -p "$dst"
cp -R "$src/." "$dst/"
_LAST_CHANGED=1
fi
}
# ── _insert_after_start_marker <dst> <content> ───────────────────────────────
# Inserts <content> immediately after the MBIFC:CUSTOM_AGENTS_START line in dst.
# dst must already exist and contain the marker.
_insert_after_start_marker() {
local dst="$1" content="$2"
[[ -z "$content" ]] && return 0
local start_line
start_line=$(grep -n '<!-- MBIFC:CUSTOM_AGENTS_START -->' "$dst" | head -1 | cut -d: -f1)
[[ -z "$start_line" ]] && return 0
local saved_file tmpfile
saved_file="$(mktemp)"
tmpfile="$(mktemp)"
# printf '%s\n' ensures a trailing newline so the next file line starts cleanly.
# bash $() strips trailing newlines, so content never has one already.
printf '%s\n' "$content" > "$saved_file"
{
head -n "$start_line" "$dst"
cat "$saved_file"
tail -n +"$((start_line + 1))" "$dst"
} > "$tmpfile"
mv "$tmpfile" "$dst"
rm -f "$saved_file"
}
# ── merge_marked_file <src> <dst> ─────────────────────────────────────────────
# Copies src to dst, preserving content between <!-- MBIFC:CUSTOM_AGENTS_START -->
# and <!-- MBIFC:CUSTOM_AGENTS_END --> markers from the existing dst.
#
# Handles three cases:
# 1. dst doesn't exist → plain copy
# 2. Both src and dst have markers → marker-based merge (primary path)
# 3. src has markers, dst doesn't → migration: extracts legacy custom rows
# from pre-marker installations
#
# Sets _LAST_CHANGED=1 if dst was written.
merge_marked_file() {
local src="$1" dst="$2"
_LAST_CHANGED=0
# Case 1: dst doesn't exist yet
if [[ ! -f "$dst" ]]; then
mkdir -p "$(dirname "$dst")"
cp "$src" "$dst"
_LAST_CHANGED=1
return 0
fi
local src_has_markers=0 dst_has_markers=0
grep -q '<!-- MBIFC:CUSTOM_AGENTS_START -->' "$src" 2>/dev/null && src_has_markers=1
grep -q '<!-- MBIFC:CUSTOM_AGENTS_START -->' "$dst" 2>/dev/null && dst_has_markers=1
# src has no markers → standard copy-if-changed
if [[ $src_has_markers -eq 0 ]]; then
copy_if_changed "$src" "$dst"
return 0
fi
# Case 3: src has markers, dst doesn't → migration from old format
if [[ $dst_has_markers -eq 0 ]]; then
local custom_rows=""
local CORE_NAMES="architect scribe sorter seeker connector librarian transcriber postman"
while IFS= read -r row; do
local aname
aname=$(printf '%s' "$row" | awk -F'|' '{gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2); print $2}')
if [[ -n "$aname" ]] && ! echo " $CORE_NAMES " | grep -qw " $aname "; then
custom_rows="${custom_rows}${row}"$'\n'
fi
done < <(grep "^|" "$dst" 2>/dev/null \
| grep -v "^|[[:space:]]*Name[[:space:]]*|" \
| grep -v "^|[-:[:space:]]*|")
cp "$src" "$dst"
_LAST_CHANGED=1
if [[ -n "$custom_rows" ]]; then
_insert_after_start_marker "$dst" "$custom_rows"
warn "Migrated legacy custom agents in $(basename "$dst") to MBIFC marker format"
fi
return 0
fi
# Case 2: both have markers → extract saved content, build merged result,
# only update dst if the result actually differs (ensures idempotency).
local saved_content
saved_content=$(awk \
'/<!-- MBIFC:CUSTOM_AGENTS_START -->/{f=1; next}
/<!-- MBIFC:CUSTOM_AGENTS_END -->/{f=0}
f{print}' \
"$dst")
local merged; merged="$(mktemp)"
cp "$src" "$merged"
[[ -n "$saved_content" ]] && _insert_after_start_marker "$merged" "$saved_content"
if ! diff -q "$merged" "$dst" >/dev/null 2>&1; then
cp "$merged" "$dst"
_LAST_CHANGED=1
[[ $VERBOSE_COPY -eq 1 && -n "$saved_content" ]] && info "Merged: $(basename "$src") (custom content preserved)"
fi
rm -f "$merged"
}
# ── Manifest helpers ──────────────────────────────────────────────────────────
# Single unified manifest at $VAULT_DIR/.{framework}/.mbifc-manifest
# Format: INI-style with [section] headers, one entry per line.
#
# PLATFORM_VAULT_DIR must be set before calling these functions (e.g.
# $VAULT_DIR/.claude for claude-code, $VAULT_DIR/.opencode for opencode).
# Defaults to $VAULT_DIR/.claude for backwards compatibility.
manifest_read() {
local section="$1"
local file="${PLATFORM_VAULT_DIR:-$VAULT_DIR/.claude}/.mbifc-manifest"
[[ -f "$file" ]] || return 0
awk -v sec="[$section]" '
$0 == sec { found=1; next }
found && /^\[[a-zA-Z0-9_-]+\]$/ { exit }
found && NF > 0 { print }
' "$file"
}
manifest_write() {
local section="$1"; shift
local entries=("$@")
local file="${PLATFORM_VAULT_DIR:-$VAULT_DIR/.claude}/.mbifc-manifest"
mkdir -p "$(dirname "$file")"
local tmpfile; tmpfile="$(mktemp)"
local in_section=0 section_written=0
if [[ -f "$file" ]]; then
while IFS= read -r line || [[ -n "$line" ]]; do
if [[ "$line" == "[$section]" ]]; then
in_section=1; continue
fi
if [[ "$line" =~ ^\[[a-zA-Z0-9_-]+\]$ ]] && [[ $in_section -eq 1 ]]; then
in_section=0
# Write the replacement section, then the next section header
{ printf '[%s]\n' "$section"
for e in "${entries[@]}"; do [[ -n "$e" ]] && printf '%s\n' "$e"; done
printf '\n'
} >> "$tmpfile"
section_written=1
fi
[[ $in_section -eq 0 ]] && printf '%s\n' "$line" >> "$tmpfile"
done < "$file"
fi
# Section wasn't encountered, or was at end of file with no following section
if [[ $section_written -eq 0 ]]; then
{ printf '[%s]\n' "$section"
for e in "${entries[@]}"; do [[ -n "$e" ]] && printf '%s\n' "$e"; done
printf '\n'
} >> "$tmpfile"
fi
mv "$tmpfile" "$file"
}
manifest_remove() {
local section="$1" name="$2"
local file="${PLATFORM_VAULT_DIR:-$VAULT_DIR/.claude}/.mbifc-manifest"
[[ -f "$file" ]] || return 0
local tmpfile; tmpfile="$(mktemp)"
local in_section=0
while IFS= read -r line || [[ -n "$line" ]]; do
if [[ "$line" == "[$section]" ]]; then in_section=1; printf '%s\n' "$line" >> "$tmpfile"; continue; fi
if [[ "$line" =~ ^\[[a-zA-Z0-9_-]+\]$ ]]; then in_section=0; fi
if [[ $in_section -eq 1 && "$line" == "$name" ]]; then continue; fi
printf '%s\n' "$line" >> "$tmpfile"
done < "$file"
mv "$tmpfile" "$file"
}
# Converts legacy per-directory .core-manifest files to the unified format.
# Runs only when legacy files are present; idempotent thereafter.
manifest_migrate() {
local _fw_dir="${PLATFORM_VAULT_DIR:-$VAULT_DIR/.claude}"
local agents_mf="$_fw_dir/agents/.core-manifest"
local refs_mf="$_fw_dir/references/.core-manifest"
[[ -f "$agents_mf" ]] || [[ -f "$refs_mf" ]] || return 0
warn "Migrating legacy manifests to unified .mbifc-manifest..."
if [[ -f "$agents_mf" ]]; then
local entries=()
while IFS= read -r line || [[ -n "$line" ]]; do [[ -n "$line" ]] && entries+=("$line"); done < "$agents_mf"
manifest_write "agents" "${entries[@]}"
rm "$agents_mf"
fi
if [[ -f "$refs_mf" ]]; then
local entries=()
while IFS= read -r line || [[ -n "$line" ]]; do [[ -n "$line" ]] && entries+=("$line"); done < "$refs_mf"
manifest_write "references" "${entries[@]}"
rm "$refs_mf"
fi
success "Manifest migrated to $(basename "$_fw_dir")/.mbifc-manifest"
}
# ── Deprecation ───────────────────────────────────────────────────────────────
# deprecate_removed <section> <src_dir> <dst_dir>
# Moves files listed in the manifest for <section> that no longer exist in
# <src_dir> to $PLATFORM_VAULT_DIR/deprecated/, prepending a DEPRECATED header.
# Prints the count of deprecated files to stdout.
deprecate_removed() {
local section="$1" src_dir="$2" dst_dir="$3"
local count=0
while IFS= read -r name; do
[[ -z "$name" ]] && continue
[[ -f "$src_dir/$name" ]] && continue # still in repo — keep it
local vault_file="$dst_dir/$name"
[[ -f "$vault_file" ]] || continue # not present — skip
[[ "$name" == *"-DEPRECATED"* ]] && continue # already deprecated
local dep_name="${name%.md}-DEPRECATED.md"
local dep_dir="${PLATFORM_VAULT_DIR:-$VAULT_DIR/.claude}/deprecated"
mkdir -p "$dep_dir"
[[ -f "$dep_dir/$dep_name" ]] && continue # already done in a prior run
mv "$vault_file" "$dep_dir/$dep_name"
{ printf '########\nDEPRECATED DO NOT USE\n########\n\n'
cat "$dep_dir/$dep_name"
} > "$dep_dir/$dep_name.tmp"
mv "$dep_dir/$dep_name.tmp" "$dep_dir/$dep_name"
manifest_remove "$section" "$name"
warn "Deprecated: $name → $(basename "${PLATFORM_VAULT_DIR:-$VAULT_DIR/.claude}")/deprecated/$dep_name"
count=$((count + 1))
done < <(manifest_read "$section")
printf '%d' "$count"
}
# ── Component installers ──────────────────────────────────────────────────────
# Each function installs one component type and prints the changed-file count
# to stdout. All respect VERBOSE_COPY for per-file logging.
#
# USER_MUTABLE_REFS: space-separated list of reference filenames that may
# contain user-added content between MBIFC markers. These use merge_marked_file
# instead of copy_if_changed.
USER_MUTABLE_REFS="agents-registry.md agents.md"
install_agents() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
mkdir -p "$dst_dir"
for src in "$src_dir/"*; do
[[ -f "$src" ]] || continue
case "$src" in
*.md|*.toml) ;;
*) continue ;;
esac
local name; name="$(basename "$src")"
manifest+=("$name")
copy_if_changed "$src" "$dst_dir/$name"
if [[ $_LAST_CHANGED -eq 1 ]]; then
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated agent: $name" || true
count=$((count + 1))
fi
done
manifest_write "agents" "${manifest[@]}"
printf '%d' "$count"
}
# install_toml_agents <src_dir> <dst_dir>
# Copies *.toml agent files from src to dst. Used by Codex CLI platform installs
# where agents are .toml rather than .md. Tracked in the manifest under "agents".
install_toml_agents() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
mkdir -p "$dst_dir"
for src in "$src_dir/"*.toml; do
[[ -f "$src" ]] || continue
local name; name="$(basename "$src")"
manifest+=("$name")
copy_if_changed "$src" "$dst_dir/$name"
if [[ $_LAST_CHANGED -eq 1 ]]; then
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated agent: $name" || true
count=$((count + 1))
fi
done
manifest_write "agents" "${manifest[@]}"
printf '%d' "$count"
}
install_refs() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
mkdir -p "$dst_dir"
for src in "$src_dir/"*.md; do
[[ -f "$src" ]] || continue
local name; name="$(basename "$src")"
local dst="$dst_dir/$name"
manifest+=("$name")
if [[ " $USER_MUTABLE_REFS " == *" $name "* ]]; then
merge_marked_file "$src" "$dst"
else
copy_if_changed "$src" "$dst"
fi
if [[ $_LAST_CHANGED -eq 1 ]]; then
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated reference: $name" || true
count=$((count + 1))
fi
done
manifest_write "references" "${manifest[@]}"
printf '%d' "$count"
}
install_skills() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
[[ -d "$src_dir" ]] || { printf '0'; return 0; }
for skill_src in "$src_dir/"*/; do
[[ -f "${skill_src}SKILL.md" ]] || continue
local name; name="$(basename "$skill_src")"
manifest+=("$name")
copy_tree_if_changed "$skill_src" "$dst_dir/$name"
if [[ $_LAST_CHANGED -eq 1 ]]; then
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated skill: $name" || true
count=$((count + 1))
fi
done
manifest_write "skills" "${manifest[@]}"
printf '%d' "$count"
}
install_hooks() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
[[ -d "$src_dir" ]] || { printf '0'; return 0; }
mkdir -p "$dst_dir"
for src in "$src_dir/"*.sh; do
[[ -f "$src" ]] || continue
local name; name="$(basename "$src")"
local dst="$dst_dir/$name"
manifest+=("$name")
copy_if_changed "$src" "$dst"
if [[ $_LAST_CHANGED -eq 1 ]]; then
chmod +x "$dst"
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated hook: $name" || true
count=$((count + 1))
fi
done
manifest_write "hooks" "${manifest[@]}"
printf '%d' "$count"
}
# install_plugins <src_dir> <dst_dir>
# Copies *.js plugin files from src to dst. Mirrors install_hooks but for
# opencode plugins (the opencode framework expects JavaScript files under
# .opencode/plugins/). Tracked in the manifest under key "plugins".
install_plugins() {
local src_dir="$1" dst_dir="$2"
local count=0 manifest=()
[[ -d "$src_dir" ]] || { printf '0'; return 0; }
mkdir -p "$dst_dir"
for src in "$src_dir/"*.js; do
[[ -f "$src" ]] || continue
local name; name="$(basename "$src")"
local dst="$dst_dir/$name"
manifest+=("$name")
copy_if_changed "$src" "$dst"
if [[ $_LAST_CHANGED -eq 1 ]]; then
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated plugin: $name" || true
count=$((count + 1))
fi
done
manifest_write "plugins" "${manifest[@]}"
printf '%d' "$count"
}
# install_settings <src_json> <dst_dir>
# Always syncs settings.json from src to dst when they differ.
# Creates a .bak of the previous version so users can recover custom entries.
# Sets _LAST_CHANGED.
install_settings() {
local src="$1" dst_dir="$2"
local dst="$dst_dir/settings.json"
_LAST_CHANGED=0
[[ -f "$src" ]] || return 0
mkdir -p "$dst_dir"
if [[ ! -f "$dst" ]]; then
cp "$src" "$dst"
_LAST_CHANGED=1
elif ! diff -q "$src" "$dst" >/dev/null 2>&1; then
cp "$dst" "${dst}.bak"
cp "$src" "$dst"
_LAST_CHANGED=1
[[ $VERBOSE_COPY -eq 1 ]] && info "Updated settings.json (previous version saved as settings.json.bak)" || true
[[ $VERBOSE_COPY -eq 1 ]] && info "For custom hooks, use settings.local.json instead" || true
fi
}
# install_dispatcher <src_file> <dst_path>
# Copies the source dispatcher file to the destination.
# Backs up existing customized dispatcher before overwriting.
# Sets _LAST_CHANGED.
install_dispatcher() {
local src="$1" dst="$2"
[[ -f "$src" ]] || return 0
if [[ -f "$dst" ]] && ! diff -q "$src" "$dst" >/dev/null 2>&1; then
local dst_dir; dst_dir="$(dirname "$dst")"
local dst_base; dst_base="$(basename "$dst" .md)"
local backup
if [[ -f "$dst_dir/${dst_base}_ORIGINAL.md" ]]; then
backup="$dst_dir/${dst_base}_ORIGINAL_$(date +%Y%m%d_%H%M%S).md"
else
backup="$dst_dir/${dst_base}_ORIGINAL.md"
fi
cp "$dst" "$backup"
warn "Existing $(basename "$dst") backed up to $(basename "$backup")"
fi
copy_if_changed "$src" "$dst"
[[ $_LAST_CHANGED -eq 1 && $VERBOSE_COPY -eq 1 ]] && info "Updated $(basename "$dst")" || true
}
# ── UI helpers ────────────────────────────────────────────────────────────────
print_banner() {
local title="$1"
echo ""
echo -e "${BOLD}╔══════════════════════════════════════════╗${NC}"
echo -e "${BOLD}║ My Brain Is Full - Crew :: ${title}${NC}"
echo -e "${BOLD}╚══════════════════════════════════════════╝${NC}"
echo ""
}
@@ -0,0 +1,227 @@
#!/usr/bin/env bash
# =============================================================================
# My Brain Is Full - Crew :: Updater
# =============================================================================
# After pulling new changes from the repo, run this to update the crew:
#
# cd /path/to/your-vault/My-Brain-Is-Full-Crew
# git pull
# bash scripts/updateme.sh
#
# Options:
# --platform <name> Platform to update (auto-detected if omitted)
# --target <path> Override the vault destination path
# =============================================================================
set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=scripts/lib.sh
source "$SCRIPT_DIR/lib.sh"
resolve_paths "${BASH_SOURCE[0]}"
# ── Parse args ─────────────────────────────────────────────────────────────
PLATFORM=""
TARGET_OVERRIDE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--platform) PLATFORM="$2"; shift 2 ;;
--target) TARGET_OVERRIDE="$2"; shift 2 ;;
*) die "Unknown argument: $1" ;;
esac
done
[[ -n "$TARGET_OVERRIDE" ]] && VAULT_DIR="$TARGET_OVERRIDE"
# ── Banner ────────────────────────────────────────────────────────────────────
print_banner "Update "
# ── Auto-detect platform if not specified ────────────────────────────────────
if [[ -z "$PLATFORM" ]]; then
DETECTED=()
[[ -d "$VAULT_DIR/.claude/agents" ]] && DETECTED+=("claude-code")
[[ -d "$VAULT_DIR/.opencode/agents" ]] && DETECTED+=("opencode")
[[ -d "$VAULT_DIR/.gemini/agents" ]] && DETECTED+=("gemini-cli")
[[ -d "$VAULT_DIR/.codex/agents" ]] && DETECTED+=("codex-cli")
if [[ ${#DETECTED[@]} -eq 0 ]]; then
die "No installed platform detected in $VAULT_DIR — run launchme.sh first"
elif [[ ${#DETECTED[@]} -eq 1 ]]; then
PLATFORM="${DETECTED[0]}"
info "Detected platform: $PLATFORM"
else
echo -e " ${BOLD}Multiple platforms detected:${NC}"
echo ""
for i in "${!DETECTED[@]}"; do
echo -e " ${BOLD}$((i+1)))${NC} ${DETECTED[$i]}"
done
echo ""
if ! read -r -p " Which platform to update? > " PLATFORM_CHOICE 2>/dev/null; then PLATFORM_CHOICE=""; fi
if [[ "$PLATFORM_CHOICE" =~ ^[0-9]+$ ]] && (( PLATFORM_CHOICE >= 1 && PLATFORM_CHOICE <= ${#DETECTED[@]} )); then
PLATFORM="${DETECTED[$((PLATFORM_CHOICE-1))]}"
else
for p in "${DETECTED[@]}"; do
[[ "$p" == "$PLATFORM_CHOICE" ]] && PLATFORM="$p" && break
done
fi
[[ -n "$PLATFORM" ]] || die "Invalid selection: $PLATFORM_CHOICE"
info "Selected platform: $PLATFORM"
fi
fi
# ── Check vault has been set up ───────────────────────────────────────────────
case "$PLATFORM" in
claude-code) _SETUP_CHECK="$VAULT_DIR/.claude/agents" ;;
opencode) _SETUP_CHECK="$VAULT_DIR/.opencode/agents" ;;
gemini-cli) _SETUP_CHECK="$VAULT_DIR/.gemini/agents" ;;
codex-cli) _SETUP_CHECK="$VAULT_DIR/.codex/agents" ;;
*) die "Unknown platform: $PLATFORM" ;;
esac
[[ -d "$_SETUP_CHECK" ]] \
|| die "No agents/ found in $VAULT_DIR for platform '$PLATFORM' — run launchme.sh first"
# ── Confirm ───────────────────────────────────────────────────────────────────
case "$PLATFORM" in
opencode) _DISP_NAME="AGENTS.md"; _FW_DIR_NAME="opencode" ;;
gemini-cli) _DISP_NAME="GEMINI.md"; _FW_DIR_NAME="gemini" ;;
claude-code) _DISP_NAME="CLAUDE.md"; _FW_DIR_NAME="claude" ;;
codex-cli) _DISP_NAME="AGENTS.md"; _FW_DIR_NAME="codex" ;;
*) die "Unknown platform: $PLATFORM" ;;
esac
echo -e "${BOLD}This will update core agents, skills, references, hooks, and ${_DISP_NAME}.${NC}"
echo -e " ${DIM}Custom agents in .${_FW_DIR_NAME}/agents/ are never overwritten or deleted.${NC}"
echo -e " ${DIM}Custom content between MBIFC markers in references is preserved.${NC}"
echo -e " ${DIM}Your vault notes are never touched.${NC}"
echo ""
echo -e " ${BOLD}c)${NC} Continue"
echo -e " ${BOLD}q)${NC} Quit"
if ! read -r -p " > " ANSWER 2>/dev/null; then ANSWER=""; fi
if [[ ! "$ANSWER" =~ ^[Cc]$ ]]; then
echo ""; info "Update cancelled."; echo ""; exit 0
fi
echo ""
# ── Build the platform dist ───────────────────────────────────────────────
info "Building $PLATFORM adapter..."
bash "$SCRIPT_DIR/build.sh" --platform "$PLATFORM"
DIST_DIR="$REPO_DIR/dist/$PLATFORM"
[[ -d "$DIST_DIR" ]] || die "Build did not produce $DIST_DIR"
# ── Platform-specific install layout ────────────────────────────────────────
case "$PLATFORM" in
claude-code)
DIST_COMPONENTS_DIR="$DIST_DIR/.claude"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.claude"
DISPATCHER_SRC="$DIST_DIR/CLAUDE.md"
DISPATCHER_DST="$VAULT_DIR/CLAUDE.md"
MCP_SRC="$DIST_DIR/.mcp.json"
MCP_DST="$VAULT_DIR/.mcp.json"
HAS_PLUGINS=0
;;
opencode)
DIST_COMPONENTS_DIR="$DIST_DIR/.opencode"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.opencode"
DISPATCHER_SRC="$DIST_DIR/AGENTS.md"
DISPATCHER_DST="$VAULT_DIR/AGENTS.md"
MCP_SRC="$DIST_DIR/opencode.json"
MCP_DST="$VAULT_DIR/opencode.json"
HAS_PLUGINS=1
;;
gemini-cli)
DIST_COMPONENTS_DIR="$DIST_DIR/.gemini"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.gemini"
DISPATCHER_SRC="$DIST_DIR/GEMINI.md"
DISPATCHER_DST="$VAULT_DIR/GEMINI.md"
MCP_SRC=""
MCP_DST=""
HAS_PLUGINS=0
DIST_SKILLS_DIR="$DIST_COMPONENTS_DIR/skills"
VAULT_SKILLS_DIR="$VAULT_COMPONENTS_DIR/skills"
;;
codex-cli)
DIST_COMPONENTS_DIR="$DIST_DIR/.codex"
VAULT_COMPONENTS_DIR="$VAULT_DIR/.codex"
DISPATCHER_SRC="$DIST_DIR/AGENTS.md"
DISPATCHER_DST="$VAULT_DIR/AGENTS.md"
MCP_SRC="$DIST_DIR/.codex/config.toml"
MCP_DST="$VAULT_DIR/.codex/config.toml"
HAS_PLUGINS=0
DIST_SKILLS_DIR="$DIST_DIR/.agents/skills"
VAULT_SKILLS_DIR="$VAULT_DIR/.agents/skills"
;;
*)
die "Unknown platform: $PLATFORM (install layout not defined)"
;;
esac
[[ -n "${DIST_SKILLS_DIR:-}" ]] || DIST_SKILLS_DIR="$DIST_COMPONENTS_DIR/skills"
[[ -n "${VAULT_SKILLS_DIR:-}" ]] || VAULT_SKILLS_DIR="$VAULT_COMPONENTS_DIR/skills"
PLATFORM_VAULT_DIR="$VAULT_COMPONENTS_DIR"
# Load opencode-specific helpers when building for opencode
if [[ "$PLATFORM" == "opencode" ]]; then
# shellcheck source=adapters/opencode/config-merge.sh
source "$REPO_DIR/adapters/opencode/config-merge.sh"
fi
# ── Migrate legacy manifests (if any) ────────────────────────────────────────
manifest_migrate
# ── Deprecate agents/refs removed from repo ──────────────────────────────────
DEP_COUNT=$(deprecate_removed "agents" "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
DEP_COUNT=$((DEP_COUNT + $(deprecate_removed "references" "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")))
# ── Ensure vault support dirs ─────────────────────────────────────────────────
mkdir -p "$VAULT_DIR/Meta/states"
# ── Update components (per-file logging enabled) ─────────────────────────────
VERBOSE_COPY=1
if [[ "$PLATFORM" == "codex-cli" ]]; then
AGENT_COUNT=$(install_toml_agents "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
else
AGENT_COUNT=$(install_agents "$DIST_COMPONENTS_DIR/agents" "$VAULT_COMPONENTS_DIR/agents")
fi
REF_COUNT=$(install_refs "$DIST_COMPONENTS_DIR/references" "$VAULT_COMPONENTS_DIR/references")
SKILL_COUNT=$(install_skills "$DIST_SKILLS_DIR" "$VAULT_SKILLS_DIR")
HOOK_COUNT=$(install_hooks "$DIST_COMPONENTS_DIR/hooks" "$VAULT_COMPONENTS_DIR/hooks")
PLUGIN_COUNT=0
if [[ $HAS_PLUGINS -eq 1 && -d "$DIST_COMPONENTS_DIR/plugins" ]]; then
info "Installing plugins..."
PLUGIN_COUNT=$(install_plugins "$DIST_COMPONENTS_DIR/plugins" "$VAULT_COMPONENTS_DIR/plugins")
success "Plugins: $PLUGIN_COUNT installed/updated"
fi
SETTINGS_CHANGED=0
if [[ -f "$DIST_COMPONENTS_DIR/settings.json" ]]; then
install_settings "$DIST_COMPONENTS_DIR/settings.json" "$VAULT_COMPONENTS_DIR"
SETTINGS_CHANGED=$_LAST_CHANGED
fi
install_dispatcher "$DISPATCHER_SRC" "$DISPATCHER_DST"
DISPATCHER_CHANGED=$_LAST_CHANGED
# ── MCP / opencode.json ───────────────────────────────────────────────────────
if [[ -f "$MCP_SRC" ]]; then
if [[ "$PLATFORM" == "opencode" && -f "$MCP_DST" ]]; then
oc_config_merge "$MCP_SRC" "$MCP_DST" "$MCP_DST"
info "Merged opencode.json (user config preserved)"
else
copy_if_changed "$MCP_SRC" "$MCP_DST"
fi
fi
# ── Summary ───────────────────────────────────────────────────────────────────
echo ""
TOTAL=$((AGENT_COUNT + REF_COUNT + SKILL_COUNT + HOOK_COUNT + PLUGIN_COUNT + SETTINGS_CHANGED + DISPATCHER_CHANGED))
if [[ $TOTAL -eq 0 && $DEP_COUNT -eq 0 ]]; then
success "Everything is already up to date!"
else
success "Updated $AGENT_COUNT agent(s), $SKILL_COUNT skill(s), $REF_COUNT reference(s), $HOOK_COUNT hook(s)${PLUGIN_COUNT:+, $PLUGIN_COUNT plugin(s)}"
[[ $SETTINGS_CHANGED -eq 1 ]] && info "settings.json updated (backup saved as settings.json.bak)"
[[ $DISPATCHER_CHANGED -eq 1 ]] && info "Dispatcher file updated"
[[ $DEP_COUNT -gt 0 ]] && warn "$DEP_COUNT file(s) deprecated (moved to deprecated/)"
fi
echo ""
echo -e " ${DIM}Restart $PLATFORM to pick up the changes.${NC}"
echo ""