53 lines
1.5 KiB
Bash
Executable File
53 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Document - Ask ollie to add documentation comments to selected code
|
|
#
|
|
# Usage: Select code, then middle-click Document in the tag
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ -z "${winid:-}" ]]; then
|
|
echo "Document must be run from within acme" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Get the window name (filename) from the tag
|
|
filename=$(9p read acme/$winid/tag | awk '{print $1}')
|
|
|
|
# Read the current selection
|
|
echo 'addr=dot' | 9p write acme/$winid/ctl
|
|
selection=$(9p read acme/$winid/xdata 2>/dev/null || true)
|
|
|
|
if [[ -z "$selection" ]]; then
|
|
echo "No selection. Select some code first." >&2
|
|
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 and send the prompt
|
|
prompt="Edit the source file $filename.
|
|
|
|
The selected code below is the target. It may be incomplete context:
|
|
|
|
$selection
|
|
|
|
Instructions:
|
|
- Read the actual file and relevant surrounding code before editing.
|
|
- Add documentation comments to the selected declarations.
|
|
- Do not change executable code or unrelated code.
|
|
- Match the language and existing project style.
|
|
- Document behavior, parameters, return values, errors, and non-obvious edge cases.
|
|
- Apply the edit directly to the file. Do not only describe a patch.
|
|
- Run formatting or relevant checks if available.
|
|
|
|
After editing, report the file changed and a one-sentence summary."
|
|
|
|
echo "$prompt" | o "$OLLIE_SESSION/$OLLIE_AGENT" prompt
|