feat(installer): implement MAM skills installer with complete user guide and pass reviewer reviews
This commit is contained in:
Executable
+164
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env bash
|
||||
# ==============================================================================
|
||||
# Multi-Agent Mux (MAM) Skill Installer
|
||||
# Efficiently installs MAM orchestration rules & skills to another project.
|
||||
# ==============================================================================
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# ANSI color codes
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper functions for logs
|
||||
log_info() { echo -e "${BLUE}[INFO]${NC} $*"; }
|
||||
log_ok() { echo -e "${GREEN}[OK]${NC} $*"; }
|
||||
log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
|
||||
log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
|
||||
|
||||
show_help() {
|
||||
cat <<EOF
|
||||
Usage: $0 [options]
|
||||
|
||||
Options:
|
||||
-t, --target <path> Target directory/project where MAM should be installed (defaults to current directory)
|
||||
-f, --force Force copy AGENTS.md even if it already exists (backups are still made)
|
||||
-h, --help Show this help message
|
||||
EOF
|
||||
}
|
||||
|
||||
TARGET_DIR="."
|
||||
FORCE=0
|
||||
|
||||
# Parse CLI arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-t|--target)
|
||||
TARGET_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
-f|--force)
|
||||
FORCE=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown option: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Resolve absolute path for source and target, tracking symlinks gracefully
|
||||
SOURCE="${BASH_SOURCE[0]}"
|
||||
while [ -h "$SOURCE" ]; do
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
||||
SOURCE="$(readlink "$SOURCE")"
|
||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
|
||||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
|
||||
SRC_DIR="$(cd "$DIR/.." && pwd)"
|
||||
TARGET_DIR="$(mkdir -p "$TARGET_DIR" && cd "$TARGET_DIR" && pwd)"
|
||||
|
||||
log_info "Installing MAM skills to target project: $TARGET_DIR"
|
||||
log_info "Source directory resolved: $SRC_DIR"
|
||||
|
||||
if [ "$SRC_DIR" = "$TARGET_DIR" ]; then
|
||||
log_error "Source and Target directories are the same! Cannot install to oneself."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 1. Dependency Checks
|
||||
log_info "Verifying host dependencies..."
|
||||
DEPS=(tmux python3 sqlite3 rsync)
|
||||
MISSING_DEPS=()
|
||||
for dep in "${DEPS[@]}"; do
|
||||
if ! command -v "$dep" &>/dev/null; then
|
||||
MISSING_DEPS+=("$dep")
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${#MISSING_DEPS[@]} -ne 0 ]; then
|
||||
log_error "Missing required dependencies: ${MISSING_DEPS[*]}"
|
||||
log_error "Please install them before using MAM."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check Python PyYAML library
|
||||
if ! python3 -c "import yaml" &>/dev/null; then
|
||||
log_warn "Python 'pyyaml' package is not installed. Python YAML parsing features may fail."
|
||||
log_warn "Please run: pip install pyyaml"
|
||||
fi
|
||||
log_ok "Dependency checks completed."
|
||||
|
||||
# 2. Copy .agents/ folder
|
||||
log_info "Deploying orchestration rules & skills (.agents/)..."
|
||||
mkdir -p "$TARGET_DIR/.agents"
|
||||
|
||||
# Sync rules and skills, avoiding copying temporary or system files
|
||||
# Exclude git histories or internal runtime cache if any
|
||||
rsync -a --exclude='.git/' --exclude='reports/' --exclude='*.log' --exclude='__pycache__/' --exclude='*.pyc' "$SRC_DIR/.agents/" "$TARGET_DIR/.agents/"
|
||||
log_ok "Deployed Rules and Skills under target's .agents/"
|
||||
|
||||
# 3. Copy AGENTS.md to root
|
||||
log_info "Configuring developer guidelines (AGENTS.md)..."
|
||||
if [ -f "$TARGET_DIR/AGENTS.md" ]; then
|
||||
if [ "$FORCE" -eq 1 ]; then
|
||||
log_warn "AGENTS.md already exists in target project. Backing up and overwriting..."
|
||||
cp "$TARGET_DIR/AGENTS.md" "$TARGET_DIR/AGENTS.md.bak.$(date +%s)"
|
||||
cp "$SRC_DIR/AGENTS.md" "$TARGET_DIR/AGENTS.md"
|
||||
log_ok "Guidelines overwritten successfully."
|
||||
else
|
||||
log_warn "AGENTS.md already exists in target. Skipping copy. Use -f/--force to overwrite."
|
||||
fi
|
||||
else
|
||||
cp "$SRC_DIR/AGENTS.md" "$TARGET_DIR/AGENTS.md"
|
||||
log_ok "Guidelines AGENTS.md copied to project root."
|
||||
fi
|
||||
|
||||
# 4. Gitignore adjustments
|
||||
log_info "Registering runtime isolation blocks in .gitignore..."
|
||||
GITIGNORE="$TARGET_DIR/.gitignore"
|
||||
MAM_PATTERN="/.mam/"
|
||||
|
||||
if [ -f "$GITIGNORE" ]; then
|
||||
if grep -Fqx "$MAM_PATTERN" "$GITIGNORE"; then
|
||||
log_ok "/.mam/ already registered in target's .gitignore."
|
||||
else
|
||||
echo -e "\n# Multi-Agent Mux (MAM) runtime databases and isolation cache\n$MAM_PATTERN" >> "$GITIGNORE"
|
||||
log_ok "Appended /.mam/ registration to .gitignore."
|
||||
fi
|
||||
else
|
||||
echo -e "# Multi-Agent Mux (MAM) runtime databases and isolation cache\n$MAM_PATTERN" > "$GITIGNORE"
|
||||
log_ok "Created .gitignore with /.mam/ exclusion."
|
||||
fi
|
||||
|
||||
# 5. Initialize runtime reports folder
|
||||
mkdir -p "$TARGET_DIR/.mam/reports"
|
||||
log_ok "Initialized runtime structures."
|
||||
|
||||
# Done
|
||||
log_ok "MAM Installation completed successfully!"
|
||||
cat <<EOF
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
💡 Quick Start Guide:
|
||||
1. Initialize a new isolated session:
|
||||
$ bash .agents/skills/multi-agent-mux-create/scripts/create_session.sh \\
|
||||
--workspace "$TARGET_DIR" --agent claude --role developer --isolate
|
||||
|
||||
2. Attach to the running session:
|
||||
$ tmux -L multi-agent-mux attach -t <session_name>
|
||||
|
||||
3. Gracefully stop the session:
|
||||
$ bash .agents/skills/multi-agent-mux-stop/scripts/stop_session.sh \\
|
||||
--session <session_name> --agent claude
|
||||
--------------------------------------------------------------------------------
|
||||
EOF
|
||||
Reference in New Issue
Block a user