/ devlog / settle_gold.sh
#!/bin/sh
# Settles gold, or reports it unchanged, and prints its head.
#
# Run this as the first action of every round, always, with the commit
# message Chris showed for the last delivered patch, or with no argument
# when he showed none. Paste what it prints; never write gold's head
# from memory.
#
#   settle_gold.sh "a page that fronts the news"   settles the oldest
#                                                  delivered patch
#   settle_gold.sh                                 settles nothing
#
# GOLD and LEDGER may be set in the environment; the defaults suit a
# sandbox with gold at /home/claude/gold.
GOLD=${GOLD:-/home/claude/gold}
WORK=${WORK:-/home/claude/work}
LEDGER=${LEDGER:-/home/claude/gold_ledger.txt}
touch "$LEDGER"
if [ -n "$1" ]; then
    line=`grep ' delivered$' "$LEDGER" | head -1`
    if [ -z "$line" ]; then
        echo "settle: nothing is waiting; gold left alone"
    else
        patch=`echo "$line" | cut -d' ' -f1`
        cd "$GOLD" || exit 1
        if git apply "$patch"; then
            git add -A
            git -c user.email=llm@dev.null -c user.name=LLM \
                commit -q -m "$1"
            git tag -f confirmed-head HEAD > /dev/null
            # work's marker has to move with gold's, or the next cut
            # carries hunks gold already holds and will not apply
            if [ -d "$WORK/.git" ]; then
                (cd "$WORK" && git tag -f confirmed-head HEAD > /dev/null)
            fi
            grep -v "^$patch " "$LEDGER" > "$LEDGER.next"
            echo "$patch `echo "$line" | cut -d' ' -f2` settled" \
                >> "$LEDGER.next"
            mv "$LEDGER.next" "$LEDGER"
        else
            echo "settle: $patch would not apply; gold left alone"
        fi
    fi
fi
cd "$GOLD" || exit 1
echo "gold: `git log -1 --format='%h %s'`"
waiting=`grep -c ' delivered$' "$LEDGER"`
if [ "$waiting" -gt 0 ]; then
    echo "waiting to be settled:"
    grep ' delivered$' "$LEDGER"
fi
X