#!/usr/bin/env bash set -euo pipefail # graphlemon A-1 spike driver. # Tests whether Claude Code dynamic workflows can be invoked programmatically # (headless, no human in the loop) with parseable structured output, per # architecture.md §10.1 and SDD 00-SDD-生成记录.md assumption A-1. # # Usage: ./run-spike.sh /path/to/some/git/repo # The target repo just needs to be *a* git repo -- it does not need to be # graphlemon itself. Do not point this at a repo you care about disturbing; # it only writes .claude/workflows/graphlemon-a1-spike.js into it. TARGET_REPO="${1:?Usage: ./run-spike.sh /path/to/target/git/repo}" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "== Pre-flight ==" command -v claude >/dev/null || { echo "FAIL: claude CLI not found on PATH"; exit 1; } claude --version echo "(dynamic workflows require Claude Code v2.1.154+, and on Pro require enabling" echo " the 'Dynamic workflows' row in /config from an interactive session first)" mkdir -p "$TARGET_REPO/.claude/workflows" cp "$SCRIPT_DIR/workflow-under-test.js" "$TARGET_REPO/.claude/workflows/graphlemon-a1-spike.js" echo "Installed workflow -> $TARGET_REPO/.claude/workflows/graphlemon-a1-spike.js" cd "$TARGET_REPO" SCHEMA='{"type":"object","required":["input_numbers","squares","sum"],"properties":{"input_numbers":{"type":"array"},"squares":{"type":"array"},"sum":{"type":"number"}}}' echo echo "== Test 1: normal -p invocation, no stdin available, expect NO interactive prompt ==" START=$(date +%s) set +e OUT1=$(claude -p 'Run /graphlemon-a1-spike with args {"numbers":[2,3,4]}' \ --output-format json \ --json-schema "$SCHEMA" \ --permission-mode bypassPermissions \ < /dev/null) RC1=$? set -e END=$(date +%s) echo "$OUT1" > "$SCRIPT_DIR/result-test1.json" echo "exit code: $RC1, elapsed: $((END-START))s" echo "$OUT1" | python3 -m json.tool 2>/dev/null | head -80 || echo "$OUT1" echo echo "== Test 2: --bare invocation (docs recommend --bare for scripted/SDK calls) ==" echo " checks whether bare mode still discovers .claude/workflows/" START=$(date +%s) set +e OUT2=$(claude --bare -p 'Run /graphlemon-a1-spike with args {"numbers":[2,3,4]}' \ --output-format json \ --json-schema "$SCHEMA" \ --permission-mode bypassPermissions \ < /dev/null) RC2=$? set -e END=$(date +%s) echo "$OUT2" > "$SCRIPT_DIR/result-test2-bare.json" echo "exit code: $RC2, elapsed: $((END-START))s" echo "$OUT2" | python3 -m json.tool 2>/dev/null | head -80 || echo "$OUT2" echo echo "== Verdict ==" python3 "$SCRIPT_DIR/check-results.py" "$SCRIPT_DIR/result-test1.json" "$SCRIPT_DIR/result-test2-bare.json"