#!/usr/bin/env bash # Scribe — release this session's task claims as it ends (milestone 381 step 4). # # A claim records a session's attention, and a session that ends has none left # to give. This is the mechanical half of the hand-off: it needs nothing from # the model, only the session id the harness reports. The other half — writing # down where the work stands — only the model can do, and it is stated as a # practice in the skill and the static context, not here. # # A TIDY-UP, NOT THE GUARANTEE. SessionEnd does not fire on a crash, a killed # terminal or a dropped connection, and those are exactly the cases the claim # was designed around. The lease is what makes a dead session's claim read as # dead; this only keeps the ordinary exit from leaving a claim to run out. # # NOT ON /clear. A clear ends one conversation and starts the next in the same # terminal, and SessionStart(source=clear) pushes back the work this session # had claimed. Releasing here would leave that push with nothing to say. The # next write moves the claim wherever the work actually continues. # # EXIT 0 AND SILENT, ALWAYS. Nobody reads a SessionEnd hook's output, and the # session is ending whether this succeeds or not. set -uo pipefail # shellcheck source=plugin/hooks/scribe_defs.sh . "$(dirname "${BASH_SOURCE[0]}")/scribe_defs.sh" command -v curl >/dev/null 2>&1 || exit 0 scribe_config || exit 0 event=$(cat 2>/dev/null || true) [ -n "$event" ] || exit 0 event_flat=$(printf '%s' "$event" | scribe_json_flat) reason=$(scribe_json_pick "$event_flat" '.reason') [ "$reason" = "clear" ] && exit 0 session_id=$(scribe_json_pick "$event_flat" '.session_id') [ -n "$session_id" ] || exit 0 sid_enc=$(printf '%s' "$session_id" | scribe_urlenc) || exit 0 curl -fsS --max-time 4 \ -H "Authorization: Bearer ${token}" \ "${url%/}/api/plugin/release-session?session_id=${sid_enc}" \ >/dev/null 2>&1 || true exit 0