diff --git a/data/scripts/acme/acme-ollie-ensure b/data/scripts/acme/acme-ollie-ensure index f3f92ae..75bb2a2 100755 --- a/data/scripts/acme/acme-ollie-ensure +++ b/data/scripts/acme/acme-ollie-ensure @@ -1,19 +1,16 @@ #!/bin/bash # acme-ollie-ensure - Ensure acme session and agent exist # -# Creates session "acme" if needed, creates/selects one agent per git root. -# Outputs the session and agent names for use by other scripts. +# One session per project root (git worktree aware), one agent "assistant". +# Session name: acme-{hash of project root} # # Usage: eval $(acme-ollie-ensure) # Then use $OLLIE_SESSION and $OLLIE_AGENT set -euo pipefail -SESSION="acme" - # Get cwd from the acme window's directory context if [[ -n "${winid:-}" ]]; then - # Get window name and extract directory wname=$(9p read acme/$winid/tag | awk '{print $1}') if [[ -d "$wname" ]]; then cwd="$wname" @@ -26,27 +23,25 @@ else cwd="$PWD" fi -# Walk up to the repository root so all files in one checkout share an agent. -git_root=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null || true) -if [[ -n "$git_root" ]]; then - cwd="$git_root" +# Discover project root: git worktree root > git root > cwd +project_root="$cwd" +if wt_root=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null); then + project_root="$wt_root" fi -# Create a short hash from the project root for the agent name -agent_hash=$(printf '%s' "$cwd" | md5sum | cut -c1-8) -AGENT="$agent_hash" +# Session name from project root hash +session_hash=$(printf '%s' "$project_root" | md5sum | cut -c1-8) +SESSION="acme-$session_hash" +AGENT="assistant" -# Ensure session exists +# Ensure session exists (with project root as cwd) if ! ollie-9p read "session/$SESSION/env" >/dev/null 2>&1; then - printf 'name=%s\ncwd=%s\n' "$SESSION" "$cwd" | ollie-9p write "session/new" 2>/dev/null || true + printf 'name=%s\ncwd=%s\n' "$SESSION" "$project_root" | ollie-9p write "session/new" 2>/dev/null || true fi # Ensure agent exists if ! ollie-9p read "session/$SESSION/agent/$AGENT/cfg" >/dev/null 2>&1; then - printf 'name=%s\ncwd=%s\n' "$AGENT" "$cwd" | ollie-9p write "session/$SESSION/agent/new" 2>/dev/null || true -else - # Update cwd if agent already exists - echo "cwd $cwd" | ollie-9p write "session/$SESSION/agent/$AGENT/ctl" 2>/dev/null || true + printf 'name=%s\n' "$AGENT" | ollie-9p write "session/$SESSION/agent/new" 2>/dev/null || true fi # Output for eval