acme: auto-create session/agent like kate plugin
Add acme-ollie-ensure helper that: - Creates 'acme' session if it doesn't exist - Creates agent named by cwd hash (like kate's approach) - Updates agent cwd if it already exists All acme commands now call acme-ollie-ensure before sending prompts, so they work without manual session setup.
This commit is contained in:
parent
e667689729
commit
6937dda94a
|
|
@ -22,18 +22,20 @@ if [[ -z "$selection" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Build location string
|
||||
location=""
|
||||
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
||||
location=" in \`$filename\`"
|
||||
fi
|
||||
|
||||
# Build the prompt
|
||||
# Build and send the prompt
|
||||
prompt="Write unit tests for this code${location}:
|
||||
|
||||
\`\`\`
|
||||
$selection
|
||||
\`\`\`"
|
||||
|
||||
# Send to ollie
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ if [[ -z "$filename" || "$filename" == *"+Errors" || "$filename" == "+*" ]]; the
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Build the prompt
|
||||
prompt="Describe and explain this file: $filename"
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Send to ollie via the o script
|
||||
# Build and send the prompt
|
||||
prompt="Describe and explain this file: $filename"
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -22,18 +22,20 @@ if [[ -z "$selection" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Build location string
|
||||
location=""
|
||||
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
||||
location=" in \`$filename\`"
|
||||
fi
|
||||
|
||||
# Build the prompt
|
||||
# Build and send the prompt
|
||||
prompt="Add documentation comments to this code${location}:
|
||||
|
||||
\`\`\`
|
||||
$selection
|
||||
\`\`\`"
|
||||
|
||||
# Send to ollie
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
# Explain - Ask ollie to explain the selected code in acme
|
||||
#
|
||||
# Usage: Select code, then middle-click Explain in the tag
|
||||
# Sends: "Explain this code (from <filename>):\n\n```\n<selection>\n```"
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
|
@ -14,7 +13,7 @@ fi
|
|||
# Get the window name (filename) from the tag
|
||||
filename=$(9p read acme/$winid/tag | awk '{print $1}')
|
||||
|
||||
# Read the current selection by setting addr to dot and reading xdata
|
||||
# Read the current selection
|
||||
echo 'addr=dot' | 9p write acme/$winid/ctl
|
||||
selection=$(9p read acme/$winid/xdata 2>/dev/null || true)
|
||||
|
||||
|
|
@ -23,18 +22,20 @@ if [[ -z "$selection" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Build context string
|
||||
context=""
|
||||
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
||||
context=" (from $filename)"
|
||||
fi
|
||||
|
||||
# Build the prompt
|
||||
# Build and send the prompt
|
||||
prompt="Explain this code${context}:
|
||||
|
||||
\`\`\`
|
||||
$selection
|
||||
\`\`\`"
|
||||
|
||||
# Send to ollie
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -22,18 +22,20 @@ if [[ -z "$selection" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Build location string
|
||||
location=""
|
||||
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
||||
location=" in \`$filename\`"
|
||||
fi
|
||||
|
||||
# Build the prompt
|
||||
# Build and send the prompt
|
||||
prompt="Fix this code${location}:
|
||||
|
||||
\`\`\`
|
||||
$selection
|
||||
\`\`\`"
|
||||
|
||||
# Send to ollie
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -22,18 +22,20 @@ if [[ -z "$selection" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Build location string
|
||||
location=""
|
||||
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
||||
location=" in \`$filename\`"
|
||||
fi
|
||||
|
||||
# Build the prompt
|
||||
# Build and send the prompt
|
||||
prompt="Refactor this code${location}:
|
||||
|
||||
\`\`\`
|
||||
$selection
|
||||
\`\`\`"
|
||||
|
||||
# Send to ollie
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
# SendVerbatim - Send the selected text to ollie as-is (wrapped in code fence)
|
||||
#
|
||||
# Usage: Select text, then middle-click SendVerbatim in the tag
|
||||
# The selection is sent wrapped in a code fence with language detection
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
|
@ -23,6 +22,9 @@ if [[ -z "$selection" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure acme session/agent exists
|
||||
eval $(acme-ollie-ensure)
|
||||
|
||||
# Detect language from file extension
|
||||
lang=""
|
||||
if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; then
|
||||
|
|
@ -55,10 +57,9 @@ if [[ -n "$filename" && "$filename" != *"+Errors" && "$filename" != "+*" ]]; the
|
|||
esac
|
||||
fi
|
||||
|
||||
# Build the prompt - just the code fence with selection
|
||||
# Build and send the prompt
|
||||
prompt="\`\`\`${lang}
|
||||
$selection
|
||||
\`\`\`"
|
||||
|
||||
# Send to ollie
|
||||
echo "$prompt" | o prompt
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
#!/bin/bash
|
||||
# acme-ollie-ensure - Ensure acme session and agent exist
|
||||
#
|
||||
# Creates session "acme" if needed, creates/selects agent based on cwd hash.
|
||||
# Outputs the agent path for use by other scripts.
|
||||
#
|
||||
# Usage: eval $(acme-ollie-ensure)
|
||||
# Then use $OLLIE_AGENT_PATH
|
||||
|
||||
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"
|
||||
elif [[ -f "$wname" ]]; then
|
||||
cwd=$(dirname "$wname")
|
||||
else
|
||||
cwd="$HOME"
|
||||
fi
|
||||
else
|
||||
cwd="$PWD"
|
||||
fi
|
||||
|
||||
# Create a short hash from the cwd for the agent name
|
||||
# Use first 8 chars of md5sum for uniqueness
|
||||
agent_hash=$(echo -n "$cwd" | md5sum | cut -c1-8)
|
||||
AGENT="$agent_hash"
|
||||
|
||||
# Ensure session exists
|
||||
if ! ollie-9p read "session/$SESSION/id" >/dev/null 2>&1; then
|
||||
printf 'name=%s\ncwd=%s\n' "$SESSION" "$cwd" | ollie-9p write "session/new" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Ensure agent exists
|
||||
if ! ollie-9p read "session/$SESSION/agent/$AGENT/id" >/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
|
||||
fi
|
||||
|
||||
# Output for eval
|
||||
echo "export session=$SESSION"
|
||||
echo "export agent=$AGENT"
|
||||
echo "export OLLIE_AGENT_PATH=session/$SESSION/agent/$AGENT"
|
||||
5
justfile
5
justfile
|
|
@ -189,6 +189,7 @@ install-data:
|
|||
install -m755 data/scripts/logseq-cli {{bin}}/logseq-cli
|
||||
install -m755 data/scripts/o {{bin}}/o
|
||||
# Acme scripts
|
||||
install -m755 data/scripts/acme/acme-ollie-ensure {{bin}}/acme-ollie-ensure
|
||||
install -m755 data/scripts/acme/AskFile {{bin}}/AskFile
|
||||
install -m755 data/scripts/acme/Explain {{bin}}/Explain
|
||||
install -m755 data/scripts/acme/Document {{bin}}/Document
|
||||
|
|
@ -214,7 +215,7 @@ uninstall:
|
|||
rm -f {{bin}}/Ollie {{bin}}/Kmpl {{bin}}/Oi {{bin}}/Theo
|
||||
rm -f {{bin}}/ollie-remount {{bin}}/o
|
||||
rm -f {{bin}}/prompt {{bin}}/ollieread {{bin}}/sendctl {{bin}}/ollie-ls
|
||||
rm -f {{bin}}/AskFile {{bin}}/Explain {{bin}}/Document {{bin}}/Fix {{bin}}/Refactor {{bin}}/AddTests {{bin}}/SendVerbatim
|
||||
rm -f {{bin}}/AskFile {{bin}}/Explain {{bin}}/Document {{bin}}/Fix {{bin}}/Refactor {{bin}}/AddTests {{bin}}/SendVerbatim {{bin}}/acme-ollie-ensure
|
||||
rm -rf {{cfg}}
|
||||
# Service files
|
||||
rm -f ~/.config/systemd/user/ollie.service
|
||||
|
|
@ -232,7 +233,7 @@ uninstall-kf5:
|
|||
rm -f {{bin}}/Ollie {{bin}}/Kmpl {{bin}}/Oi {{bin}}/Theo
|
||||
rm -f {{bin}}/ollie-remount {{bin}}/o
|
||||
rm -f {{bin}}/prompt {{bin}}/ollieread {{bin}}/sendctl {{bin}}/ollie-ls
|
||||
rm -f {{bin}}/AskFile {{bin}}/Explain {{bin}}/Document {{bin}}/Fix {{bin}}/Refactor {{bin}}/AddTests {{bin}}/SendVerbatim
|
||||
rm -f {{bin}}/AskFile {{bin}}/Explain {{bin}}/Document {{bin}}/Fix {{bin}}/Refactor {{bin}}/AddTests {{bin}}/SendVerbatim {{bin}}/acme-ollie-ensure
|
||||
rm -rf {{cfg}}
|
||||
# Service files
|
||||
rm -f ~/.config/systemd/user/ollie.service
|
||||
|
|
|
|||
Loading…
Reference in New Issue