acme-ollie-ensure: use PWD (acme sets it), tag fallback for HOME
Confirmed acme calls threadspawnd with window dir. Added tag-based fallback when PWD is HOME (top-level window).
This commit is contained in:
parent
53baa43203
commit
59c19cace9
|
|
@ -9,21 +9,20 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
# Get cwd from the acme window's directory context
|
||||
if [[ -n "${winid:-}" ]]; then
|
||||
wname=$(9p read acme/$winid/tag | awk '{print $1}')
|
||||
# Acme sets $PWD to the window's directory for executed commands.
|
||||
# Fall back to tag parsing if $winid is set (e.g. for pipe commands).
|
||||
cwd="$PWD"
|
||||
if [[ -n "${winid:-}" ]] && [[ "$cwd" == "$HOME" || "$cwd" == "$HOME/" ]]; then
|
||||
# PWD is $HOME — likely the top-level window. Try tag-based detection.
|
||||
wname=$(9p read "acme/$winid/tag" | awk '{print $1}')
|
||||
if [[ -d "$wname" ]]; then
|
||||
cwd="$wname"
|
||||
elif [[ -f "$wname" ]]; then
|
||||
cwd=$(dirname "$wname")
|
||||
else
|
||||
cwd="$HOME"
|
||||
fi
|
||||
else
|
||||
cwd="$PWD"
|
||||
fi
|
||||
|
||||
# Discover project root: git worktree root > git root > cwd
|
||||
# Discover project root: git worktree root > cwd
|
||||
project_root="$cwd"
|
||||
if wt_root=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null); then
|
||||
project_root="$wt_root"
|
||||
|
|
@ -37,9 +36,6 @@ AGENT="assistant"
|
|||
# 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" "$project_root" | ollie-9p write "session/new" 2>/dev/null || true
|
||||
else
|
||||
# Update cwd in case project root changed
|
||||
printf 'cwd=%s\n' "$project_root" | ollie-9p write "session/$SESSION/cfg" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Ensure agent exists
|
||||
|
|
|
|||
Loading…
Reference in New Issue