disinto/supervisor/update-prompt.sh
openhands bd02330b22 fix: shellcheck TODO has no enforcement — || true may never be removed (#71)
- Fix SC2164: add || exit 1 to bare cd in update-prompt.sh
- Fix SC2155: separate declare and assign in env.sh, supervisor-poll.sh, dev-agent.sh
- Fix SC2034: inline suppression for vars used by sourced helpers
- Remove unused `mergeable` declaration, rename unused loop var to `_w`
- Remove || true from shellcheck CI step — failures are now blocking

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 01:53:02 +00:00

47 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# update-prompt.sh — Append a lesson to a best-practices file
#
# Usage:
# ./supervisor/update-prompt.sh "best-practices/memory.md" "### Title\nBody text"
# ./supervisor/update-prompt.sh --from-file "best-practices/memory.md" /tmp/lesson.md
#
# Called by claude -p when it learns something during a fix.
# Commits and pushes the update to the disinto repo.
source "$(dirname "$0")/../lib/env.sh"
TARGET_FILE="${FACTORY_ROOT}/supervisor/$1"
shift
if [ "$1" = "--from-file" ] && [ -f "$2" ]; then
LESSON=$(cat "$2")
elif [ -n "$1" ]; then
LESSON="$1"
else
echo "Usage: update-prompt.sh <relative-path> '<lesson text>'" >&2
echo " or: update-prompt.sh <relative-path> --from-file <path>" >&2
exit 1
fi
if [ ! -f "$TARGET_FILE" ]; then
echo "Target file not found: $TARGET_FILE" >&2
exit 1
fi
# Append under "Lessons Learned" section if it exists, otherwise at end
if grep -q "## Lessons Learned" "$TARGET_FILE"; then
echo "" >> "$TARGET_FILE"
echo "$LESSON" >> "$TARGET_FILE"
else
echo "" >> "$TARGET_FILE"
echo "## Lessons Learned" >> "$TARGET_FILE"
echo "" >> "$TARGET_FILE"
echo "$LESSON" >> "$TARGET_FILE"
fi
cd "$FACTORY_ROOT" || exit 1
git add "supervisor/$1" 2>/dev/null || git add "$TARGET_FILE"
git commit -m "supervisor: learned — $(echo "$LESSON" | head -1 | sed 's/^#* *//')" --no-verify 2>/dev/null
git push origin main 2>/dev/null
log "Updated $(basename "$TARGET_FILE") with new lesson"