task-done 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. # Close one task of an inline plan execution in a single call: run the task's
  3. # test command, keep its full output in the workspace, print the tail, and —
  4. # only if the command succeeded — append the completion line to the ledger.
  5. # A failing command records nothing: the task is not complete.
  6. #
  7. # Usage: task-done PLAN_FILE TASK_NUMBER BASE -- TEST_COMMAND [ARGS...]
  8. # BASE is the SHA task-start printed; the completion line records BASE..HEAD.
  9. # Exit: the test command's exit status.
  10. set -euo pipefail
  11. if [ $# -lt 5 ] || [ "$4" != "--" ]; then
  12. echo "usage: task-done PLAN_FILE TASK_NUMBER BASE -- TEST_COMMAND [ARGS...]" >&2
  13. exit 2
  14. fi
  15. plan=$1
  16. n=$2
  17. base=$3
  18. shift 4
  19. sdd="$(cd "$(dirname "$0")/../../subagent-driven-development/scripts" && pwd)"
  20. git rev-parse --verify --quiet "$base" >/dev/null || { echo "bad BASE: $base" >&2; exit 2; }
  21. dir=$("$sdd/sdd-workspace" "$plan")
  22. log="$dir/task-${n}-tests.log"
  23. ledger="$dir/progress.md"
  24. # Render the command the way a person would type it, for the ledger line.
  25. cmd=""
  26. for a in "$@"; do
  27. case "$a" in
  28. *[[:space:]\"\;\|\&]*) cmd="$cmd '$a'" ;;
  29. *) cmd="$cmd $a" ;;
  30. esac
  31. done
  32. cmd=${cmd# }
  33. rc=0
  34. "$@" > "$log" 2>&1 || rc=$?
  35. tail -n 5 "$log"
  36. if [ "$rc" -ne 0 ]; then
  37. echo "task-done: test command exited $rc; Task $n NOT recorded (full output: $log)" >&2
  38. exit "$rc"
  39. fi
  40. last=$(grep -v '^[[:space:]]*$' "$log" | tail -n 1)
  41. [ -f "$ledger" ] || printf '# SDD ledger — plan: %s\n' "$plan" > "$ledger"
  42. line="Task $n: complete (commits $(git rev-parse --short=7 "$base")..$(git rev-parse --short=7 HEAD), tests: $cmd → $last)"
  43. printf '%s\n' "$line" >> "$ledger"
  44. echo "ledger: $line"