refactor: ci-debug to lib, rewrite README

- Moved ci-debug.sh from dev/ to lib/ (shared utility)
- README: fixed supervisor description (all alerts go to claude)
- README: replaced implementation details with actual design principles
This commit is contained in:
openhands 2026-03-12 18:10:25 +00:00
parent 04e80ee391
commit 4895ad1989
4 changed files with 31 additions and 50 deletions

View file

@ -1,79 +0,0 @@
#!/usr/bin/env bash
# ci-debug.sh — Query Woodpecker CI (CLI for logs, API for structure)
#
# Usage:
# ci-debug.sh status [pipeline] — pipeline overview + step states
# ci-debug.sh logs <pipeline> <step#> — full logs for a step
# ci-debug.sh failures [pipeline] — all failed step logs
# ci-debug.sh list [count] — recent pipelines (default 10)
set -euo pipefail
# Load shared environment
source "$(dirname "$0")/../lib/env.sh"
export WOODPECKER_SERVER="http://localhost:8000"
# WOODPECKER_TOKEN loaded from .env via env.sh
REPO="johba/harb"
API="${WOODPECKER_SERVER}/api/repos/2"
api() {
curl -sf -H "Authorization: Bearer ${WOODPECKER_TOKEN}" "${API}/$1"
}
get_latest() {
api "pipelines?per_page=1" | jq -r '.[0].number'
}
case "${1:-help}" in
list)
COUNT="${2:-10}"
api "pipelines?per_page=${COUNT}" | \
jq -r '.[] | "#\(.number) \(.status) \(.event) \(.commit[:7]) \(.message | split("\n")[0][:60])"'
;;
status)
P="${2:-$(get_latest)}"
echo "Pipeline #${P}:"
api "pipelines/${P}" | \
jq -r '" Status: \(.status) Event: \(.event) Commit: \(.commit[:7])"'
echo "Steps:"
api "pipelines/${P}" | \
jq -r '.workflows[]? | " [\(.name)]", (.children[]? | " [\(.pid)] \(.name) → \(.state) (exit \(.exit_code))")'
;;
logs)
P="${2:?Usage: ci-debug.sh logs <pipeline> <step#>}"
S="${3:?Usage: ci-debug.sh logs <pipeline> <step#>}"
woodpecker-cli pipeline log show "$REPO" "$P" "$S"
;;
failures)
P="${2:-$(get_latest)}"
FAILED=$(api "pipelines/${P}" | \
jq -r '.workflows[]?.children[]? | select(.state=="failure") | "\(.pid)\t\(.name)"')
if [ -z "$FAILED" ]; then
echo "No failed steps in pipeline #${P}"
exit 0
fi
while IFS=$'\t' read -r pid name; do
echo "=== FAILED: ${name} (step ${pid}) ==="
woodpecker-cli pipeline log show "$REPO" "$P" "$pid" 2>/dev/null | tail -200
echo ""
done <<< "$FAILED"
;;
help|*)
cat <<'EOF'
ci-debug.sh — Query Woodpecker CI
Commands:
list [count] Recent pipelines (default 10)
status [pipeline] Pipeline overview + step states
logs <pipeline> <step#> Full step logs (step# = pid from status)
failures [pipeline] All failed step logs (last 200 lines each)
EOF
;;
esac

View file

@ -973,7 +973,7 @@ while [ "$REVIEW_ROUND" -lt "$MAX_REVIEW_ROUNDS" ]; do
CI_ERROR_LOG=""
if [ -n "$PIPELINE_NUM" ]; then
CI_ERROR_LOG=$(bash "${FACTORY_ROOT}/dev/ci-debug.sh" failures "$PIPELINE_NUM" 2>/dev/null | tail -80 | head -c 8000 || echo "")
CI_ERROR_LOG=$(bash "${FACTORY_ROOT}/lib/ci-debug.sh" failures "$PIPELINE_NUM" 2>/dev/null | tail -80 | head -c 8000 || echo "")
fi
log "CI code failure — feeding back to claude (attempt ${CI_FIX_COUNT})"
@ -984,9 +984,9 @@ You are in worktree ${WORKTREE} on branch ${BRANCH}.
## CI Debug Tool
\`\`\`bash
bash "${FACTORY_ROOT}/dev/ci-debug.sh" status ${PIPELINE_NUM:-0}
bash "${FACTORY_ROOT}/dev/ci-debug.sh" logs ${PIPELINE_NUM:-0} <step-name>
bash "${FACTORY_ROOT}/dev/ci-debug.sh" failures ${PIPELINE_NUM:-0}
bash "${FACTORY_ROOT}/lib/ci-debug.sh" status ${PIPELINE_NUM:-0}
bash "${FACTORY_ROOT}/lib/ci-debug.sh" logs ${PIPELINE_NUM:-0} <step-name>
bash "${FACTORY_ROOT}/lib/ci-debug.sh" failures ${PIPELINE_NUM:-0}
\`\`\`
## Failed step: ${FAILED_STEP:-unknown} (exit code ${FAILED_EXIT:-?}, pipeline #${PIPELINE_NUM:-?})