sid-isnt-done 0.6.0

sid is a UNIX-inspired coding agent for Anthropic-compatible APIs
#!/bin/sh
set -eu

# escalate — the only honest self-report is escalation.
#
# Agents do not self-report success (./ci is the verifier); calling this
# tool is how an agent or judge says it wants a human.  The ralph harness
# reads the escalation out of the transcript and maps it to exit code 3.

lookup() {
    printenv "$1"
}

PREFIX=${RCVAR_ARGV0:?missing RCVAR_ARGV0}

case "${1:-}" in
rcvar)
    printf '%s\n' \
        "${PREFIX}_REQUEST_FILE" \
        "${PREFIX}_RESULT_FILE" \
        "${PREFIX}_SCRATCH_DIR" \
        "${PREFIX}_TEMP_DIR" \
        "${PREFIX}_TMPDIR" \
        "${PREFIX}_WORKSPACE_ROOT" \
        "${PREFIX}_SESSION_ID" \
        "${PREFIX}_SESSION_DIR" \
        "${PREFIX}_AGENT_ID" \
        "${PREFIX}_TOOL_ID" \
        "${PREFIX}_TOOL_NAME" \
        "${PREFIX}_TOOL_PROTOCOL" \
        "${PREFIX}_RC_CONF_PATH" \
        "${PREFIX}_RC_D_PATH"
    ;;
confirm)
    REQUEST_FILE="$(lookup "${PREFIX}_REQUEST_FILE")"
    reason=$(jq -r '.invocation.input.reason // "no reason given"' "$REQUEST_FILE")
    printf 'escalate: %s\n' "$reason"
    ;;
run)
    REQUEST_FILE="$(lookup "${PREFIX}_REQUEST_FILE")"
    RESULT_FILE="$(lookup "${PREFIX}_RESULT_FILE")"

    request_id=$(jq -r '.request_id' "$REQUEST_FILE")
    reason=$(jq -r '.invocation.input.reason // empty' "$REQUEST_FILE")

    write_success() {
        text="$1"
        jq -n --arg rid "$request_id" --arg txt "$text" \
            '{"protocol_version":1,"request_id":$rid,"ok":true,"output":{"kind":"text","text":$txt},"error":null}' \
            > "$RESULT_FILE"
    }

    write_error() {
        code="$1"; msg="$2"
        jq -n --arg rid "$request_id" --arg c "$code" --arg m "$msg" \
            '{"protocol_version":1,"request_id":$rid,"ok":false,"output":null,"error":{"code":$c,"message":$m}}' \
            > "$RESULT_FILE"
    }

    if [ -z "$reason" ]; then
        write_error "missing_reason" "escalate requires a 'reason' field so the human knows what to look at"
        exit 0
    fi

    write_success "Escalation recorded; a human will review. End your turn."
    ;;
*)
    echo "usage: $0 [rcvar|confirm|run]" >&2
    exit 129
    ;;
esac