|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 5 | +PLUGIN_HOME="$HOME/.codex-self-evolution" |
| 6 | +LOG_DIR="$PLUGIN_HOME/logs" |
| 7 | +LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents" |
| 8 | +LABEL="com.codex-self-evolution.skill-synthesis" |
| 9 | +PLIST_PATH="$LAUNCH_AGENTS_DIR/$LABEL.plist" |
| 10 | +ENTRY_POINT="${CSEP_ENTRY_POINT:-codex-self-evolution}" |
| 11 | +INTERVAL_SECONDS="${CSEP_SKILL_SYNTHESIS_INTERVAL:-14400}" |
| 12 | +LOOKBACK_HOURS="${CSEP_SKILL_SYNTHESIS_LOOKBACK_HOURS:-24}" |
| 13 | +ARGS=("skill-synthesize" "--mode" "incremental" "--lookback-hours" "$LOOKBACK_HOURS") |
| 14 | + |
| 15 | +info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } |
| 16 | +warn() { printf '\033[1;33m[warn]\033[0m %s\n' "$*" >&2; } |
| 17 | +fail() { printf '\033[1;31m[fail]\033[0m %s\n' "$*" >&2; exit 1; } |
| 18 | + |
| 19 | +info "preflight checks" |
| 20 | +command -v "$ENTRY_POINT" >/dev/null 2>&1 || fail "$ENTRY_POINT not found on PATH. Run scripts/install.sh first." |
| 21 | +ENTRY_POINT_BIN="$(command -v "$ENTRY_POINT")" |
| 22 | +ENTRY_POINT_DIR="$(dirname "$ENTRY_POINT_BIN")" |
| 23 | +echo " $ENTRY_POINT OK at $ENTRY_POINT_BIN" |
| 24 | + |
| 25 | +mkdir -p "$LAUNCH_AGENTS_DIR" "$LOG_DIR" |
| 26 | + |
| 27 | +PI_BIN="$(command -v pi 2>/dev/null || true)" |
| 28 | +if [ -n "$PI_BIN" ]; then |
| 29 | + PI_DIR="$(dirname "$PI_BIN")" |
| 30 | + echo " pi found at $PI_BIN" |
| 31 | +else |
| 32 | + PI_DIR="" |
| 33 | + warn "pi not on PATH — skill synthesis agent:pi will not run." |
| 34 | +fi |
| 35 | + |
| 36 | +PLIST_PATH_ENV="/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
| 37 | +for dir in "$ENTRY_POINT_DIR" "$PI_DIR"; do |
| 38 | + [ -z "$dir" ] && continue |
| 39 | + case ":$PLIST_PATH_ENV:" in |
| 40 | + *":$dir:"*) ;; |
| 41 | + *) PLIST_PATH_ENV="$dir:$PLIST_PATH_ENV" ;; |
| 42 | + esac |
| 43 | +done |
| 44 | + |
| 45 | +if [ -f "$PLIST_PATH" ]; then |
| 46 | + info "removing previous $LABEL install" |
| 47 | + launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null || true |
| 48 | +fi |
| 49 | + |
| 50 | +info "writing $PLIST_PATH" |
| 51 | +cat > "$PLIST_PATH" <<PLIST |
| 52 | +<?xml version="1.0" encoding="UTF-8"?> |
| 53 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 54 | +<plist version="1.0"> |
| 55 | +<dict> |
| 56 | + <key>Label</key> |
| 57 | + <string>$LABEL</string> |
| 58 | + <key>ProgramArguments</key> |
| 59 | + <array> |
| 60 | + <string>$ENTRY_POINT_BIN</string> |
| 61 | + <string>${ARGS[0]}</string> |
| 62 | + <string>${ARGS[1]}</string> |
| 63 | + <string>${ARGS[2]}</string> |
| 64 | + <string>${ARGS[3]}</string> |
| 65 | + <string>${ARGS[4]}</string> |
| 66 | + </array> |
| 67 | + <key>EnvironmentVariables</key> |
| 68 | + <dict> |
| 69 | + <key>PATH</key> |
| 70 | + <string>$PLIST_PATH_ENV</string> |
| 71 | + <key>HOME</key> |
| 72 | + <string>$HOME</string> |
| 73 | + </dict> |
| 74 | + <key>StartInterval</key> |
| 75 | + <integer>$INTERVAL_SECONDS</integer> |
| 76 | + <key>RunAtLoad</key> |
| 77 | + <false/> |
| 78 | + <key>StandardOutPath</key> |
| 79 | + <string>$LOG_DIR/skill-synthesis.launchd.stdout.log</string> |
| 80 | + <key>StandardErrorPath</key> |
| 81 | + <string>$LOG_DIR/skill-synthesis.launchd.stderr.log</string> |
| 82 | + <key>ThrottleInterval</key> |
| 83 | + <integer>60</integer> |
| 84 | +</dict> |
| 85 | +</plist> |
| 86 | +PLIST |
| 87 | + |
| 88 | +info "loading $LABEL into launchd" |
| 89 | +launchctl bootstrap "gui/$(id -u)" "$PLIST_PATH" |
| 90 | + |
| 91 | +info "done." |
| 92 | +echo "" |
| 93 | +echo "Skill synthesis scheduler installed:" |
| 94 | +echo " label: $LABEL" |
| 95 | +echo " interval: ${INTERVAL_SECONDS}s (override via CSEP_SKILL_SYNTHESIS_INTERVAL)" |
| 96 | +echo " command: $ENTRY_POINT_BIN ${ARGS[*]}" |
| 97 | +echo " plist: $PLIST_PATH" |
| 98 | +echo " logs: $LOG_DIR/skill-synthesis.launchd.{stdout,stderr}.log" |
| 99 | +echo "" |
| 100 | +echo "Recommended first smoke:" |
| 101 | +echo " codex-self-evolution skill-synthesize --mode full --lookback-days 30 --dry-run" |
| 102 | +echo "" |
| 103 | +echo "Trigger real run manually:" |
| 104 | +echo " launchctl kickstart gui/\$(id -u)/$LABEL" |
| 105 | +echo "" |
| 106 | +echo "Remove later: $REPO/scripts/uninstall-skill-synthesis-scheduler.sh" |
0 commit comments