@pmelab/gtd 1.10.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/gtd-loop ADDED
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Drives the two-beat protocol (README.md "The reference loop driver") to a
5
+ # human gate. Both mutators are attempted every iteration, refusal-tolerant:
6
+ # whichever actor is actually awaited claims the turn (captures the human's
7
+ # uncommitted edit after a halt, or the agent's own edit from the previous
8
+ # iteration), the other refuses harmlessly.
9
+ prev_state=""
10
+ prev_prompt=""
11
+
12
+ while true; do
13
+ gtd step --json >/dev/null 2>&1 || true
14
+ gtd step-agent --json >/dev/null 2>&1 || true
15
+
16
+ if ! next_json="$(gtd next --json 2>&1)"; then
17
+ echo "gtd-loop: could not determine the next step:" >&2
18
+ echo "$next_json" >&2
19
+ echo "Run \`gtd status\` to inspect the repo." >&2
20
+ exit 1
21
+ fi
22
+
23
+ actor="$(jq -r .actor <<<"$next_json")"
24
+ pending="$(jq -r .pending <<<"$next_json")"
25
+ state="$(jq -r .state <<<"$next_json")"
26
+ prompt="$(jq -r .prompt <<<"$next_json")"
27
+
28
+ if [[ "$actor" != "agent" ]]; then
29
+ echo "--- Your turn ($state) ---"
30
+ gtd next
31
+ exit 0
32
+ fi
33
+
34
+ if [[ "$pending" == "true" ]]; then
35
+ prev_state=""
36
+ prev_prompt=""
37
+ continue
38
+ fi
39
+
40
+ # Stall detection (skills/loop/SKILL.md): the same agent-owned state and
41
+ # prompt repeating means the last dispatch made no progress — stop rather
42
+ # than spin on it.
43
+ if [[ "$state" == "$prev_state" && "$prompt" == "$prev_prompt" ]]; then
44
+ echo "gtd-loop: no progress at '$state' — the agent's last turn changed nothing. Stopping to avoid spinning." >&2
45
+ gtd next >&2
46
+ exit 1
47
+ fi
48
+ prev_state="$state"
49
+ prev_prompt="$prompt"
50
+
51
+ # Swappable agent adapter: GTD_LOOP_AGENT_CMD lets any coding agent CLI
52
+ # stand in for the default, receiving the prompt via $GTD_LOOP_PROMPT.
53
+ cmd="${GTD_LOOP_AGENT_CMD:-}"
54
+ if [[ -z "$cmd" ]]; then
55
+ cmd='claude -p "$GTD_LOOP_PROMPT" --dangerously-skip-permissions'
56
+ fi
57
+ GTD_LOOP_PROMPT="$prompt" bash -c "$cmd"
58
+ done