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
|
set -euo pipefail
|
||||||
|
|
||||||
# Get cwd from the acme window's directory context
|
# Acme sets $PWD to the window's directory for executed commands.
|
||||||
if [[ -n "${winid:-}" ]]; then
|
# Fall back to tag parsing if $winid is set (e.g. for pipe commands).
|
||||||
wname=$(9p read acme/$winid/tag | awk '{print $1}')
|
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
|
if [[ -d "$wname" ]]; then
|
||||||
cwd="$wname"
|
cwd="$wname"
|
||||||
elif [[ -f "$wname" ]]; then
|
elif [[ -f "$wname" ]]; then
|
||||||
cwd=$(dirname "$wname")
|
cwd=$(dirname "$wname")
|
||||||
else
|
|
||||||
cwd="$HOME"
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
cwd="$PWD"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Discover project root: git worktree root > git root > cwd
|
# Discover project root: git worktree root > cwd
|
||||||
project_root="$cwd"
|
project_root="$cwd"
|
||||||
if wt_root=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null); then
|
if wt_root=$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null); then
|
||||||
project_root="$wt_root"
|
project_root="$wt_root"
|
||||||
|
|
@ -37,9 +36,6 @@ AGENT="assistant"
|
||||||
# Ensure session exists (with project root as cwd)
|
# Ensure session exists (with project root as cwd)
|
||||||
if ! ollie-9p read "session/$SESSION/env" >/dev/null 2>&1; then
|
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
|
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
|
fi
|
||||||
|
|
||||||
# Ensure agent exists
|
# Ensure agent exists
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue