feat!: unify mosaic CLI — native launcher, no bin/ directory
All checks were successful
ci/woodpecker/pr/ci Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful

BREAKING CHANGE: ~/.config/mosaic/bin/ is removed entirely.
The mosaic npm CLI is now the only executable.

## What changed

- **bin/ → deleted**: All scripts moved to tools/_scripts/ (internal)
- **mosaic-launch → deleted**: Launcher logic is native TypeScript
  in packages/cli/src/commands/launch.ts
- **mosaic.ps1 → deleted**: PowerShell launcher removed
- **Framework install.sh**: Complete rewrite with migration system
- **Version tracking**: .framework-version file (schema v2)
- **Migration v1→v2**: Auto-removes bin/, cleans old PATH entries
  from shell profiles

## Native TypeScript launcher (commands/launch.ts)

All runtime launch logic ported from bash:
- Runtime prompt builder (AGENTS.md + RUNTIME.md + USER.md + TOOLS.md)
- Mission context injection (reads .mosaic/orchestrator/mission.json)
- PRD status injection (scans docs/PRD.md)
- Pre-flight checks (MOSAIC_HOME, AGENTS.md, SOUL.md, runtime binary)
- Session lock management with signal cleanup
- Per-runtime launch: Claude, Codex, OpenCode, Pi
- Yolo mode flags per runtime
- Pi skill discovery + extension loading
- Framework management (init, doctor, sync, bootstrap) delegates
  to tools/_scripts/ bash implementations

## Installer

- tools/install.sh: detects framework by .framework-version or AGENTS.md
- Framework install.sh: migration system with schema versioning
- Forward-compatible: add migrations as numbered blocks
- No PATH manipulation for framework (npm bin is the only PATH entry)
This commit is contained in:
Jarvis
2026-04-02 19:23:44 -05:00
parent 04db8591af
commit 15830e2f2a
43 changed files with 724 additions and 1475 deletions

View File

@@ -1,12 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
# ─── Mosaic Framework Installer ──────────────────────────────────────────────
#
# Installs/upgrades the framework DATA to ~/.config/mosaic/.
# No executables are placed on PATH — the mosaic npm CLI is the only binary.
#
# Called by tools/install.sh (the unified installer). Can also be run directly.
#
# Environment:
# MOSAIC_HOME — target directory (default: ~/.config/mosaic)
# MOSAIC_INSTALL_MODE — prompt|keep|overwrite (default: prompt)
# MOSAIC_ALLOW_MISSING_SEQUENTIAL_THINKING — 1 to bypass MCP check
# MOSAIC_SKIP_SKILLS_SYNC — 1 to skip skill sync
# ──────────────────────────────────────────────────────────────────────────────
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_DIR="${MOSAIC_HOME:-$HOME/.config/mosaic}"
INSTALL_MODE="${MOSAIC_INSTALL_MODE:-prompt}" # prompt|keep|overwrite
PRESERVE_PATHS=("SOUL.md" "USER.md" "TOOLS.md" "memory")
INSTALL_MODE="${MOSAIC_INSTALL_MODE:-prompt}"
# Colors (disabled if not a terminal)
# Files preserved across upgrades (never overwritten)
PRESERVE_PATHS=("SOUL.md" "USER.md" "TOOLS.md" "memory" "sources")
# Current framework schema version — bump this when the layout changes.
# The migration system uses this to run upgrade steps.
FRAMEWORK_VERSION=2
# ─── colours ──────────────────────────────────────────────────────────────────
if [[ -t 1 ]]; then
GREEN='\033[0;32m' YELLOW='\033[0;33m' RED='\033[0;31m'
CYAN='\033[0;36m' BOLD='\033[1m' RESET='\033[0m'
@@ -19,9 +39,29 @@ warn() { echo -e " ${YELLOW}⚠${RESET} $1" >&2; }
fail() { echo -e " ${RED}${RESET} $1" >&2; }
step() { echo -e "\n${BOLD}$1${RESET}"; }
# ─── helpers ──────────────────────────────────────────────────────────────────
is_existing_install() {
[[ -d "$TARGET_DIR" ]] || return 1
[[ -f "$TARGET_DIR/bin/mosaic" || -f "$TARGET_DIR/AGENTS.md" || -f "$TARGET_DIR/SOUL.md" ]]
[[ -f "$TARGET_DIR/AGENTS.md" || -f "$TARGET_DIR/SOUL.md" ]]
}
installed_framework_version() {
local vf="$TARGET_DIR/.framework-version"
if [[ -f "$vf" ]]; then
cat "$vf" 2>/dev/null || echo "0"
else
# No version file = legacy install (version 0 or 1)
if [[ -d "$TARGET_DIR/bin" ]]; then
echo "1" # Has bin/ → pre-migration legacy
else
echo "0" # Fresh or unknown
fi
fi
}
write_framework_version() {
echo "$FRAMEWORK_VERSION" > "$TARGET_DIR/.framework-version"
}
select_install_mode() {
@@ -39,33 +79,22 @@ select_install_mode() {
fi
case "$INSTALL_MODE" in
keep|overwrite)
;;
keep|overwrite) ;;
prompt)
if [[ -t 0 ]]; then
echo ""
echo "Existing Mosaic install detected at: $TARGET_DIR"
echo "Choose reinstall mode:"
echo " 1) keep Keep local files (SOUL.md, USER.md, TOOLS.md, memory/) while updating framework"
echo " 2) overwrite Replace everything in $TARGET_DIR"
echo " 3) cancel Abort install"
echo " 1) keep Update framework, preserve local files (SOUL.md, USER.md, etc.)"
echo " 2) overwrite Replace everything"
echo " 3) cancel Abort"
printf "Selection [1/2/3] (default: 1): "
read -r selection
case "${selection:-1}" in
1|k|K|keep|KEEP) INSTALL_MODE="keep" ;;
2|o|O|overwrite|OVERWRITE) INSTALL_MODE="overwrite" ;;
3|c|C|cancel|CANCEL|n|N|no|NO)
fail "Install cancelled."
exit 1
;;
*)
warn "Unrecognized selection '$selection'; defaulting to keep."
INSTALL_MODE="keep"
;;
1|k|K|keep) INSTALL_MODE="keep" ;;
2|o|O|overwrite) INSTALL_MODE="overwrite" ;;
*) fail "Install cancelled."; exit 1 ;;
esac
else
warn "Existing install detected without interactive input; defaulting to keep local files."
INSTALL_MODE="keep"
fi
;;
@@ -83,10 +112,9 @@ sync_framework() {
fi
if command -v rsync >/dev/null 2>&1; then
local rsync_args=(-a --delete --exclude ".git")
local rsync_args=(-a --delete --exclude ".git" --exclude ".framework-version")
if [[ "$INSTALL_MODE" == "keep" ]]; then
local path
for path in "${PRESERVE_PATHS[@]}"; do
rsync_args+=(--exclude "$path")
done
@@ -96,10 +124,10 @@ sync_framework() {
return
fi
# Fallback: cp-based sync
local preserve_tmp=""
if [[ "$INSTALL_MODE" == "keep" ]]; then
preserve_tmp="$(mktemp -d "${TMPDIR:-/tmp}/mosaic-preserve-XXXXXX")"
local path
for path in "${PRESERVE_PATHS[@]}"; do
if [[ -e "$TARGET_DIR/$path" ]]; then
mkdir -p "$preserve_tmp/$(dirname "$path")"
@@ -108,12 +136,11 @@ sync_framework() {
done
fi
find "$TARGET_DIR" -mindepth 1 -maxdepth 1 ! -name ".git" -exec rm -rf {} +
find "$TARGET_DIR" -mindepth 1 -maxdepth 1 ! -name ".git" ! -name ".framework-version" -exec rm -rf {} +
cp -R "$SOURCE_DIR"/. "$TARGET_DIR"/
rm -rf "$TARGET_DIR/.git"
if [[ -n "$preserve_tmp" ]]; then
local path
for path in "${PRESERVE_PATHS[@]}"; do
if [[ -e "$preserve_tmp/$path" ]]; then
rm -rf "$TARGET_DIR/$path"
@@ -125,136 +152,133 @@ sync_framework() {
fi
}
# ═══════════════════════════════════════════════════════════════════════════════
# Migrations — run sequentially from the installed version to FRAMEWORK_VERSION
# ═══════════════════════════════════════════════════════════════════════════════
run_migrations() {
local from_version
from_version="$(installed_framework_version)"
if [[ "$from_version" -ge "$FRAMEWORK_VERSION" ]]; then
return # Already current
fi
step "Running migrations (v${from_version} → v${FRAMEWORK_VERSION})"
# ── Migration: v0/v1 → v2 ─────────────────────────────────────────────────
# Remove bin/ directory — all executables now live in the npm CLI.
# Scripts that were in bin/ are now in tools/_scripts/.
if [[ "$from_version" -lt 2 ]]; then
if [[ -d "$TARGET_DIR/bin" ]]; then
ok "Removing legacy bin/ directory (executables now in npm CLI)"
rm -rf "$TARGET_DIR/bin"
fi
# Remove old mosaic PATH entry from shell profiles
for profile in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
if [[ -f "$profile" ]] && grep -qF "$TARGET_DIR/bin" "$profile"; then
# Remove the PATH line and the comment above it
sed -i.mosaic-migration-bak \
-e "\|# Mosaic agent framework|d" \
-e "\|$TARGET_DIR/bin|d" \
"$profile"
ok "Cleaned up old PATH entry from $(basename "$profile")"
rm -f "${profile}.mosaic-migration-bak"
fi
done
# Remove stale rails/ symlink
if [[ -L "$TARGET_DIR/rails" ]]; then
rm -f "$TARGET_DIR/rails"
fi
fi
# ── Future migrations go here ──────────────────────────────────────────────
# if [[ "$from_version" -lt 3 ]]; then
# ...
# fi
}
# ═══════════════════════════════════════════════════════════════════════════════
# Main
# ═══════════════════════════════════════════════════════════════════════════════
step "Installing Mosaic framework"
mkdir -p "$TARGET_DIR"
select_install_mode
if [[ "$INSTALL_MODE" == "keep" ]]; then
ok "Install mode: keep local SOUL.md/USER.md/TOOLS.md/memory while updating framework"
ok "Install mode: keep local files (SOUL.md, USER.md, TOOLS.md, memory/)"
else
ok "Install mode: overwrite existing files"
ok "Install mode: overwrite"
fi
sync_framework
# Ensure memory directory exists (preserved across upgrades, may not exist on fresh install)
# Ensure memory directory exists
mkdir -p "$TARGET_DIR/memory"
chmod +x "$TARGET_DIR"/bin/*
chmod +x "$TARGET_DIR"/install.sh
# Ensure tool scripts are executable
find "$TARGET_DIR/tools" -name "*.sh" -exec chmod +x {} + 2>/dev/null || true
find "$TARGET_DIR/tools/_scripts" -type f -exec chmod +x {} + 2>/dev/null || true
# Create backward-compat symlink: rails/ → tools/
if [[ -d "$TARGET_DIR/tools" ]]; then
if [[ -d "$TARGET_DIR/rails" ]] && [[ ! -L "$TARGET_DIR/rails" ]]; then
rm -rf "$TARGET_DIR/rails"
fi
ln -sfn "tools" "$TARGET_DIR/rails"
fi
ok "Framework synced to $TARGET_DIR"
ok "Framework installed to $TARGET_DIR"
# Run migrations before post-install (migrations may remove old bin/ etc.)
run_migrations
step "Post-install tasks"
if "$TARGET_DIR/bin/mosaic-link-runtime-assets" >/dev/null 2>&1; then
ok "Runtime assets linked"
else
warn "Runtime asset linking failed (non-fatal)"
fi
SCRIPTS="$TARGET_DIR/tools/_scripts"
if "$TARGET_DIR/bin/mosaic-ensure-sequential-thinking" >/dev/null 2>&1; then
ok "sequential-thinking MCP configured"
else
if [[ "${MOSAIC_ALLOW_MISSING_SEQUENTIAL_THINKING:-0}" == "1" ]]; then
warn "sequential-thinking MCP setup failed but bypassed (MOSAIC_ALLOW_MISSING_SEQUENTIAL_THINKING=1)"
if [[ -x "$SCRIPTS/mosaic-link-runtime-assets" ]]; then
if "$SCRIPTS/mosaic-link-runtime-assets" >/dev/null 2>&1; then
ok "Runtime assets linked"
else
fail "sequential-thinking MCP setup failed (hard requirement)."
fail "Set MOSAIC_ALLOW_MISSING_SEQUENTIAL_THINKING=1 only for temporary bypass scenarios."
exit 1
warn "Runtime asset linking failed (non-fatal)"
fi
fi
if "$TARGET_DIR/bin/mosaic-ensure-excalidraw" >/dev/null 2>&1; then
ok "excalidraw MCP configured"
else
warn "excalidraw MCP setup failed (non-fatal) — run 'mosaic-ensure-excalidraw' to retry"
fi
if [[ "${MOSAIC_SKIP_SKILLS_SYNC:-0}" == "1" ]]; then
ok "Skills sync skipped (MOSAIC_SKIP_SKILLS_SYNC=1)"
else
if "$TARGET_DIR/bin/mosaic-sync-skills" >/dev/null 2>&1; then
ok "Skills synced"
if [[ -x "$SCRIPTS/mosaic-ensure-sequential-thinking" ]]; then
if "$SCRIPTS/mosaic-ensure-sequential-thinking" >/dev/null 2>&1; then
ok "sequential-thinking MCP configured"
else
warn "Skills sync failed (non-fatal)"
if [[ "${MOSAIC_ALLOW_MISSING_SEQUENTIAL_THINKING:-0}" == "1" ]]; then
warn "sequential-thinking MCP setup bypassed (MOSAIC_ALLOW_MISSING_SEQUENTIAL_THINKING=1)"
else
fail "sequential-thinking MCP setup failed (hard requirement)."
exit 1
fi
fi
fi
if "$TARGET_DIR/bin/mosaic-migrate-local-skills" --apply >/dev/null 2>&1; then
ok "Local skills migrated"
else
warn "Local skill migration failed (non-fatal)"
if [[ -x "$SCRIPTS/mosaic-ensure-excalidraw" ]]; then
"$SCRIPTS/mosaic-ensure-excalidraw" >/dev/null 2>&1 && ok "excalidraw MCP configured" || warn "excalidraw MCP setup failed (non-fatal)"
fi
if "$TARGET_DIR/bin/mosaic-doctor" >/dev/null 2>&1; then
ok "Health audit passed"
else
warn "Health audit reported issues — run 'mosaic doctor' for details"
if [[ "${MOSAIC_SKIP_SKILLS_SYNC:-0}" != "1" ]] && [[ -x "$SCRIPTS/mosaic-sync-skills" ]]; then
"$SCRIPTS/mosaic-sync-skills" >/dev/null 2>&1 && ok "Skills synced" || warn "Skills sync failed (non-fatal)"
fi
step "PATH configuration"
PATH_LINE="export PATH=\"$TARGET_DIR/bin:\$PATH\""
# Find the right shell profile
if [[ -n "${ZSH_VERSION:-}" ]] || [[ "$(basename "${SHELL:-}")" == "zsh" ]]; then
SHELL_PROFILE="$HOME/.zshrc"
elif [[ -f "$HOME/.bashrc" ]]; then
SHELL_PROFILE="$HOME/.bashrc"
elif [[ -f "$HOME/.profile" ]]; then
SHELL_PROFILE="$HOME/.profile"
else
SHELL_PROFILE="$HOME/.profile"
if [[ -x "$SCRIPTS/mosaic-migrate-local-skills" ]]; then
"$SCRIPTS/mosaic-migrate-local-skills" --apply >/dev/null 2>&1 && ok "Local skills migrated" || warn "Local skill migration failed (non-fatal)"
fi
PATH_CHANGED=false
if grep -qF "$TARGET_DIR/bin" "$SHELL_PROFILE" 2>/dev/null; then
ok "Already in PATH via $SHELL_PROFILE"
else
{
echo ""
echo "# Mosaic agent framework"
echo "$PATH_LINE"
} >> "$SHELL_PROFILE"
ok "Added to PATH in $SHELL_PROFILE"
PATH_CHANGED=true
if [[ -x "$SCRIPTS/mosaic-doctor" ]]; then
"$SCRIPTS/mosaic-doctor" >/dev/null 2>&1 && ok "Health audit passed" || warn "Health audit reported issues — run 'mosaic doctor' for details"
fi
# Write version stamp AFTER everything succeeds
write_framework_version
# ── Summary ──────────────────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD} Mosaic installed successfully.${RESET}"
echo -e "${GREEN}${BOLD} Mosaic framework installed.${RESET}"
echo ""
# Collect next steps
NEXT_STEPS=()
if [[ "$PATH_CHANGED" == "true" ]]; then
NEXT_STEPS+=("Run ${CYAN}source $SHELL_PROFILE${RESET} or log out and back in to activate PATH.")
fi
if [[ ! -f "$TARGET_DIR/SOUL.md" ]]; then
NEXT_STEPS+=("Run ${CYAN}mosaic init${RESET} to set up your agent identity (SOUL.md), user profile (USER.md), and tool config (TOOLS.md).")
elif grep -q "not configured" "$TARGET_DIR/USER.md" 2>/dev/null; then
NEXT_STEPS+=("Run ${CYAN}mosaic init${RESET} to personalize your user profile (USER.md) and tool config (TOOLS.md).")
fi
if [[ ${#NEXT_STEPS[@]} -gt 0 ]]; then
echo -e " ${BOLD}Next steps:${RESET}"
for i in "${!NEXT_STEPS[@]}"; do
echo -e " $((i+1)). ${NEXT_STEPS[$i]}"
done
echo -e " Run ${CYAN}mosaic init${RESET} to set up your agent identity."
echo ""
fi