coord-send.sh, coord-inbox.sh, coord-done.sh and the 40-check coord-selftest.sh, unchanged, as the extraction baseline. Selftest passes 40/40 in this location (script paths are dir-relative). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HBbjgS5A55RVavoyjJC4FX
61 lines
2.1 KiB
Bash
Executable file
61 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
# coord-done.sh - mark directed coordination message(s) as handled by moving
|
|
# them from this repo's inbox to archive (kept, never deleted). Idempotent and
|
|
# fail-safe. ASCII only, bash 3.2 safe.
|
|
#
|
|
# Usage:
|
|
# coord-done.sh <basename>... mark the named message(s) handled
|
|
# coord-done.sh --all mark all pending directed messages handled
|
|
# coord-done.sh [--repo <name>] <basename>...
|
|
# Env: CLAUDE_COORD_DIR overrides the mailbox root.
|
|
set -u
|
|
export LC_ALL=C
|
|
|
|
COORD="${CLAUDE_COORD_DIR:-$HOME/.claude/coord}"
|
|
REPO=""
|
|
ALL=0
|
|
# Indexed array, never a space-joined string: basenames may contain any
|
|
# character except "/", and re-splitting would make them un-archivable.
|
|
NAMES=()
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
# bash 3.2: `shift 2` past the end of $# is a no-op -> would loop forever.
|
|
--repo) [ $# -ge 2 ] || { echo "coord-done: --repo requires a value" >&2; exit 2; }
|
|
REPO="$2"; shift 2 ;;
|
|
--all) ALL=1; shift ;;
|
|
-h|--help) grep '^#' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
|
|
*) NAMES+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
if [ -z "$REPO" ]; then
|
|
REPO="$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null)"
|
|
[ -z "$REPO" ] && REPO="$(basename "$(pwd)" 2>/dev/null)"
|
|
fi
|
|
[ -z "$REPO" ] && { echo "coord-done: cannot resolve repo" >&2; exit 2; }
|
|
|
|
INBOX="$COORD/$REPO/inbox"
|
|
ARCHIVE="$COORD/$REPO/archive"
|
|
[ -d "$INBOX" ] || { echo "coord-done: no inbox for $REPO"; exit 0; }
|
|
|
|
moved=0
|
|
archive_one() {
|
|
case "$1" in */*|"") echo "coord-done: invalid name: $1" >&2; return 1 ;; esac
|
|
if [ -e "$INBOX/$1" ]; then
|
|
mkdir -p "$ARCHIVE" 2>/dev/null && mv "$INBOX/$1" "$ARCHIVE/" 2>/dev/null && moved=$((moved + 1))
|
|
fi
|
|
}
|
|
|
|
if [ "$ALL" -eq 1 ]; then
|
|
for f in "$INBOX"/*.md; do
|
|
[ -e "$f" ] || continue
|
|
archive_one "$(basename "$f")"
|
|
done
|
|
else
|
|
# bash 3.2 + set -u: expanding an empty array errors, so guard on length.
|
|
[ "${#NAMES[@]}" -eq 0 ] && { echo "coord-done: name(s) or --all required" >&2; exit 2; }
|
|
for b in "${NAMES[@]}"; do archive_one "$b"; done
|
|
fi
|
|
|
|
echo "coord-done: $moved message(s) archived for $REPO"
|
|
exit 0
|