feat: worktree-based run isolation for parallel loops
Each /agent-loop:run now creates a git worktree for the feature branch before generating stories. This provides full isolation: - Multiple loops can run in parallel on different specs in the same project - Main working directory stays on main, always available - Each worktree has its own .loop/ state, tmux session, and branch - Completed runs are archived to main's .loop/archive/ with runs.log Changes: - setup.sh: add --init-worktree mode for initializing worktree .loop/ - archive.sh: add archive_from_worktree() for cross-directory archiving - loop.sh: replace branch checkout with validation (worktree is pre-checked-out) - agents/planner.md: accept absolute path prefix for worktree .loop/ writes - skills/run/SKILL.md: full rewrite — worktree creation in Phase 2, launch in Phase 3, archive on completion, .active-worktree tracking file - skills/stories/SKILL.md: worktree-aware, defer to /run for full flow Bump to 0.12.0.
This commit is contained in:
57
setup.sh
57
setup.sh
@@ -11,16 +11,30 @@
|
||||
set -euo pipefail
|
||||
|
||||
# --- Parse arguments ---
|
||||
UPDATE_ONLY=false
|
||||
ACTION="scaffold"
|
||||
MODE="${1:-implement}"
|
||||
WORKTREE_PATH=""
|
||||
MAIN_LOOP_DIR=""
|
||||
|
||||
if [ "$MODE" = "--update" ]; then
|
||||
UPDATE_ONLY=true
|
||||
MODE="${2:-implement}" # mode not used in update, but keep arg parsing clean
|
||||
fi
|
||||
case "$MODE" in
|
||||
--update)
|
||||
ACTION="update"
|
||||
MODE="${2:-implement}"
|
||||
;;
|
||||
--init-worktree)
|
||||
ACTION="init-worktree"
|
||||
WORKTREE_PATH="$2"
|
||||
MAIN_LOOP_DIR="$3"
|
||||
if [ -z "$WORKTREE_PATH" ] || [ -z "$MAIN_LOOP_DIR" ]; then
|
||||
echo "[setup] ERROR: --init-worktree requires <worktree_path> <main_loop_dir>"
|
||||
echo "[setup] Usage: setup.sh --init-worktree /path/to/worktree /path/to/main/.loop"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Validate mode ---
|
||||
if [ "$UPDATE_ONLY" = false ] && [[ ! "$MODE" =~ ^(implement|explore|fix)$ ]]; then
|
||||
if [ "$ACTION" = "scaffold" ] && [[ ! "$MODE" =~ ^(implement|explore|fix)$ ]]; then
|
||||
echo "[setup] ERROR: Invalid mode '$MODE'. Must be: implement, explore, fix"
|
||||
exit 1
|
||||
fi
|
||||
@@ -63,7 +77,7 @@ if [ -f "$HARNESS_SRC/.claude-plugin/plugin.json" ]; then
|
||||
fi
|
||||
|
||||
# --- Update-only mode: refresh harness files without touching run state ---
|
||||
if [ "$UPDATE_ONLY" = true ]; then
|
||||
if [ "$ACTION" = "update" ]; then
|
||||
LOOP_DIR="$(pwd)/.loop"
|
||||
if [ ! -d "$LOOP_DIR" ]; then
|
||||
echo "[setup] ERROR: No .loop/ directory found. Run setup first."
|
||||
@@ -83,6 +97,34 @@ if [ "$UPDATE_ONLY" = true ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --- Init-worktree mode: initialize .loop/ in a worktree from main's config ---
|
||||
if [ "$ACTION" = "init-worktree" ]; then
|
||||
LOOP_DIR="$WORKTREE_PATH/.loop"
|
||||
mkdir -p "$LOOP_DIR"
|
||||
|
||||
# Copy harness files from plugin source
|
||||
cp -r "$HARNESS_SRC/prompts" "$LOOP_DIR/"
|
||||
cp -r "$HARNESS_SRC/templates" "$LOOP_DIR/"
|
||||
cp -r "$HARNESS_SRC/lib" "$LOOP_DIR/"
|
||||
cp "$HARNESS_SRC/loop.sh" "$LOOP_DIR/"
|
||||
chmod +x "$LOOP_DIR/loop.sh"
|
||||
|
||||
# Copy project config and init from main's .loop/
|
||||
[ -f "$MAIN_LOOP_DIR/config.json" ] && cp "$MAIN_LOOP_DIR/config.json" "$LOOP_DIR/"
|
||||
[ -f "$MAIN_LOOP_DIR/init.sh" ] && cp "$MAIN_LOOP_DIR/init.sh" "$LOOP_DIR/"
|
||||
|
||||
# Stamp harness version
|
||||
[ -n "$PLUGIN_VERSION" ] && echo "$PLUGIN_VERSION" > "$LOOP_DIR/.harness-version"
|
||||
|
||||
# Create .gitignore for worktree's .loop/
|
||||
cat > "$LOOP_DIR/.gitignore" << 'GITIGNORE'
|
||||
*
|
||||
GITIGNORE
|
||||
|
||||
echo "[setup] Worktree .loop/ initialized at $LOOP_DIR"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --- Ensure git repo exists ---
|
||||
if ! git rev-parse --git-dir &>/dev/null; then
|
||||
echo "[setup] No git repo found. Initializing..."
|
||||
@@ -141,6 +183,7 @@ archive/
|
||||
.archive-staging/
|
||||
.last-branch
|
||||
.harness-version
|
||||
.active-worktree
|
||||
.loop.lock
|
||||
GITIGNORE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user