diff --git a/plugins/phased-delivery/.claude-plugin/plugin.json b/plugins/phased-delivery/.claude-plugin/plugin.json index 3349403..52f4e0e 100644 --- a/plugins/phased-delivery/.claude-plugin/plugin.json +++ b/plugins/phased-delivery/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "phased-delivery", - "version": "0.15.1", + "version": "0.15.2", "description": "Plan work as self-contained phases, then implement it phase by phase.", "author": { "name": "Bryan" diff --git a/plugins/phased-delivery/hooks/session-start.sh b/plugins/phased-delivery/hooks/session-start.sh index 95a0f0e..7884391 100644 --- a/plugins/phased-delivery/hooks/session-start.sh +++ b/plugins/phased-delivery/hooks/session-start.sh @@ -1,6 +1,7 @@ #!/bin/sh # SessionStart: tell the agent when to use the phased-delivery skills, and -# list unfinished phase files written by plan-in-phases in this repository. +# list unfinished phase files written by plan-in-phases in this repository +# (and in its ignored .ai-scratchpad/plans). # Phase files are found by the header line plan-in-phases puts in each one. marker='Implement with the implement-in-phases skill' @@ -11,7 +12,10 @@ json_escape() { unfinished="" if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then - unfinished=$(git grep -l --untracked -F "$marker" -- '*.md' 2>/dev/null | + # plans kept out of the repository in .ai-scratchpad/plans (git grep skips ignored files) + plans="$(git rev-parse --show-cdup).ai-scratchpad/plans" + unfinished=$({ git grep -l --untracked -F "$marker" -- '*.md' 2>/dev/null + [ -d "$plans" ] && grep -rlF --include='*.md' "$marker" "$plans" 2>/dev/null; } | grep -E '(^|/)[0-9][0-9]-[^/]*(/phase)?\.md$' | head -50 | while IFS= read -r f; do status=$(grep -m1 '^Status:' "$f" | sed 's/^Status:[[:space:]]*//') diff --git a/plugins/phased-delivery/scripts/claude-build.sh b/plugins/phased-delivery/scripts/claude-build.sh index d96eb22..8ec6379 100755 --- a/plugins/phased-delivery/scripts/claude-build.sh +++ b/plugins/phased-delivery/scripts/claude-build.sh @@ -5,7 +5,8 @@ # PROMPT is a file holding stage-builder.md and its inputs, kept outside # REPO; its text is passed as the prompt. Claude works in REPO with the # phased-delivery plugin off and thinking summarized in the stream (the -# hidden --thinking-display flag; headless runs otherwise leave it empty). +# hidden --thinking-display flag, when this claude has it; headless runs +# otherwise leave it empty). # OUTDIR receives report.md (the final message), stream.jsonl (written as # the call runs) and stderr.txt. # @@ -24,7 +25,7 @@ # seconds without output); 8 the budget was reached; other non-zero: the # claude exit status. Never commits; the orchestrator does. set -u -[ $# -eq 6 ] || { sed -n '2,25p' "$0" >&2; exit 2; } +[ $# -eq 6 ] || { sed -n '2,26p' "$0" >&2; exit 2; } REPO=$1; PROMPT=$2; MODEL=$3; EFFORT=$4; BUDGET=$5; OUT=$6 MODE=${CLAUDE_BUILD_PERMISSIONS:-acceptEdits} case "$MODE" in @@ -37,10 +38,14 @@ case "$STALL" in esac mkdir -p "$OUT" TEXT=$(cat "$PROMPT") || exit 2 +# --thinking-display is undocumented, and claude -p fails on an unknown option: pass it only while +# this claude knows it (it then rejects the invalid value here, naming the option; otherwise --version runs) +THINK= +claude --thinking-display check --version < /dev/null 2>&1 | grep -q -- --thinking-display && THINK=summarized (cd "$REPO" && exec claude -p "$TEXT" --model "$MODEL" --effort "$EFFORT" \ --max-budget-usd "$BUDGET" \ --settings '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false}}' \ - --thinking-display summarized \ + ${THINK:+--thinking-display "$THINK"} \ --permission-mode "$MODE" --no-session-persistence \ --output-format stream-json --verbose) \ < /dev/null > "$OUT/stream.jsonl" 2> "$OUT/stderr.txt" & diff --git a/plugins/phased-delivery/tests/fake-claude.sh b/plugins/phased-delivery/tests/fake-claude.sh index 5deca3f..c4c7ffc 100644 --- a/plugins/phased-delivery/tests/fake-claude.sh +++ b/plugins/phased-delivery/tests/fake-claude.sh @@ -15,6 +15,8 @@ # prints one assistant event (a thinking summary and a tool call, for the # driver's live feed) and the result event claude-build.sh parses. A call past the last step # exits 1 with a message on stderr and nothing printed. +# claude-build.sh's probe for --thinking-display: answer as a claude that knows it, without taking a step +case " $* " in *" --version "*) echo "error: option '--thinking-display ' argument is invalid" >&2; exit 1;; esac exec python3 - "$@" <<'PY' import json, os, sys, time diff --git a/plugins/phased-delivery/tests/test_claude_build.py b/plugins/phased-delivery/tests/test_claude_build.py index 711e7f3..0b63575 100644 --- a/plugins/phased-delivery/tests/test_claude_build.py +++ b/plugins/phased-delivery/tests/test_claude_build.py @@ -20,14 +20,19 @@ "cacheCreationInputTokens": 9070}}} -def run(tmp_path, events, code=0, permissions=None, pause=0, stall=None): - """Run the script with a stub `claude` that records its arguments and prints EVENTS.""" +def run(tmp_path, events, code=0, permissions=None, pause=0, stall=None, thinking=True): + """Run the script with a stub `claude` that records its arguments and prints EVENTS. + + THINKING: whether the stub knows --thinking-display (claude-build.sh probes it first).""" bin_dir = tmp_path / "bin" bin_dir.mkdir() (tmp_path / "events.jsonl").write_text("not json\n" + "".join(json.dumps(e) + "\n" for e in events)) (tmp_path / "prompt.md").write_text("Build stage 03.1.") stub = bin_dir / "claude" - stub.write_text(f'#!/bin/sh\nprintf "%s\\n" "$@" > "{tmp_path / "args.txt"}"\n' + probe = ("echo \"error: option '--thinking-display ' argument 'check' is invalid\" >&2; exit 1" + if thinking else "echo 2.1.330; exit 0") + stub.write_text(f'#!/bin/sh\ncase " $* " in *" --version "*) {probe};; esac\n' + f'printf "%s\\n" "$@" > "{tmp_path / "args.txt"}"\n' f'echo "claude failed" >&2\ncat "{tmp_path / "events.jsonl"}"\nsleep {pause}\nexit {code}\n') stub.chmod(0o755) env = {**os.environ, "PATH": f"{bin_dir}:{os.environ['PATH']}"} @@ -86,3 +91,9 @@ def test_stall_stops_the_call(tmp_path): other = tmp_path / "other" other.mkdir() assert run(other, [BUILT], stall="soon").returncode == 2 + + +def test_thinking_display_left_out_when_unknown(tmp_path): + # a claude without the undocumented option would fail the call on it + assert run(tmp_path, [BUILT], thinking=False).returncode == 0 + assert "--thinking-display" not in (tmp_path / "args.txt").read_text().splitlines() diff --git a/plugins/phased-delivery/tests/test_run_phase.py b/plugins/phased-delivery/tests/test_run_phase.py index 708d82e..6fb7102 100644 --- a/plugins/phased-delivery/tests/test_run_phase.py +++ b/plugins/phased-delivery/tests/test_run_phase.py @@ -155,6 +155,30 @@ def test_plan_ignored_by_git(repo): assert git(repo, "status", "--porcelain") == "" +@pytest.mark.parametrize("basis, pair", [ + (dict.fromkeys("JFRCKPVS", 0), ["gpt-9-sol", "medium"]), # no top+ stage: the review is top + (dict(zip("JFRCKPVS", (1, 1, 1, 1, 2, 2, 2, 1))), ["gpt-9-astra", "high"]), # 01.2 is top+: so is the review +]) +def test_review_routed_by_hardest_stage(repo, basis, pair): + plan = repo / PLAN_DIR + # the routing tests' full set: with fewer pairs, top can reach top+'s pick (top is never below middle+) + (plan / "models-available.json").write_text(json.dumps({**AVAILABLE, "models": [ + {"id": f"gpt-9-{name}", "efforts": ["low", "medium", "high", "xhigh", "max"]} + for name in ("luna", "terra", "sol", "astra", "nova")]})) + two = json.loads((plan / "01-demo/01.2.json").read_text()) + two["brief"]["model_basis"] = basis + (plan / "01-demo/01.2.json").write_text(json.dumps(two)) + for cmd in ([SCRIPTS / "select-models.py", plan / "models-available.json", "--profiles", PROFILES, + "--out", plan / "models.md"], [SCRIPTS / "plan-check.py", plan, "--repo", repo]): + subprocess.run([sys.executable, *cmd], check=True, capture_output=True) + git(repo, "add", ".") + git(repo, "commit", "-q", "-m", "two pairs") + result = drive(repo, [REVISED_NOTHING, BUILD_ONE, BUILD_TWO, REVIEW]) + assert result.returncode == 0, result.stdout + result.stderr + review = json.loads((repo.parent / "steps.json.calls").read_text().splitlines()[3]) + assert [review[review.index("--model") + 1], review[review.index("--effort") + 1]] == pair + + def test_rerun_of_built_phase(repo): drive(repo, [REVISED_NOTHING, BUILD_ONE, BUILD_TWO, REVIEW]) head = git(repo, "rev-parse", "HEAD") diff --git a/plugins/phased-delivery/tests/test_session_start.py b/plugins/phased-delivery/tests/test_session_start.py index f32119e..eef854a 100644 --- a/plugins/phased-delivery/tests/test_session_start.py +++ b/plugins/phased-delivery/tests/test_session_start.py @@ -38,11 +38,14 @@ def test_codex_off_line(tmp_path): def test_lists_phase_folders(tmp_path): subprocess.run(["git", "init", "-q", str(tmp_path)], check=True) - for name, status in (("01-a", "planned"), ("02-b", "built abc123")): - d = tmp_path / "docs" / "plans" / "x" / name + (tmp_path / ".gitignore").write_text(".ai-scratchpad/\n") + for where, name, status in (("docs/plans", "01-a", "planned"), ("docs/plans", "02-b", "built abc123"), + (".ai-scratchpad/plans", "01-c", "planned")): + d = tmp_path / where / "x" / name d.mkdir(parents=True) (d / "phase.md").write_text( f"# Phase\n\nImplement with the implement-in-phases skill; do not build.\nStatus: {status}\n") context = hook_context(tmp_path) assert "- docs/plans/x/01-a/phase.md (planned)" in context assert "02-b" not in context + assert "- .ai-scratchpad/plans/x/01-c/phase.md (planned)" in context # ignored, still listed