Skill Tracer
Skills › Superpowers › executing-plans › task-done

task-done

52 lines · skills/executing-plans/scripts/task-done at 2ce8aa1

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.
10set -euo pipefail
12if [ $# -lt 5 ] || [ "$4" != "--" ]; then
13 echo "usage: task-done PLAN_FILE TASK_NUMBER BASE -- TEST_COMMAND [ARGS...]" >&2
14 exit 2
15fi
17plan=$1
18n=$2
19base=$3
20shift 4
21sdd="$(cd "$(dirname "$0")/../../subagent-driven-development/scripts" && pwd)"
23git rev-parse --verify --quiet "$base" >/dev/null || { echo "bad BASE: $base" >&2; exit 2; }
25dir=$("$sdd/sdd-workspace" "$plan")
26log="$dir/task-${n}-tests.log"
27ledger="$dir/progress.md"
29# Render the command the way a person would type it, for the ledger line.
30cmd=""
31for a in "$@"; do
32 case "$a" in
33 *[[:space:]\"\;\|\&]*) cmd="$cmd '$a'" ;;
34 *) cmd="$cmd $a" ;;
35 esac
36done
37cmd=${cmd# }
39rc=0
40"$@" > "$log" 2>&1 || rc=$?
42tail -n 5 "$log"
43if [ "$rc" -ne 0 ]; then
44 echo "task-done: test command exited $rc; Task $n NOT recorded (full output: $log)" >&2
45 exit "$rc"
46fi
48last=$(grep -v '^[[:space:]]*$' "$log" | tail -n 1) || last="(no output)"
49[ -f "$ledger" ] || printf '# SDD ledger — plan: %s\n' "$plan" > "$ledger"
50line="Task $n: complete (commits $(git rev-parse --short=7 "$base")..$(git rev-parse --short=7 HEAD), tests: $cmd → $last)"
51printf '%s\n' "$line" >> "$ledger"
52echo "ledger: $line"