FABRIC/scripts/br-get-next-bead.sh
jeda 57e8193f7b feat(bd-2kf): Add comprehensive test coverage for parser and store
- Add 36 parser tests covering:
  - parseLogLine with valid/invalid inputs
  - parseLogLines for multi-line parsing
  - formatEvent with all options
  - Edge cases: malformed JSON, missing fields, colorization

- Add 35 store tests covering:
  - InMemoryEventStore add/query operations
  - Worker status tracking (active/idle/error)
  - Event filtering by worker, level, bead, timestamp
  - maxEvents limit and LRU trimming
  - getStore/resetStore singleton management

- Close phase beads (bd-2pa, bd-n8l, bd-2nu) as infrastructure complete
- Close test beads (bd-5eh, bd-2en) with comprehensive coverage
- Total: 91 tests passing across parser, store, and tailer

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-03 10:43:24 +00:00

81 lines
2.2 KiB
Bash
Executable file

#!/bin/bash
# br-get-next-bead.sh
# ALT-006: Direct ready-queue.json reader
#
# This is an ALTERNATIVE to br ready that reads the pre-computed
# ready-queue.json file instead of querying the database.
#
# Usage:
# ./scripts/br-get-next-bead.sh # Get highest priority bead
# ./scripts/br-get-next-bead.sh --claim # Get and claim the bead
# ./scripts/br-get-next-bead.sh --json # Output as JSON
#
# For HUMAN bead bd-3sh - Worker starvation alternative solution
set -euo pipefail
READY_QUEUE="/home/coder/FABRIC/.beads/ready-queue.json"
CLAIM_MODE=false
JSON_OUTPUT=false
while [[ $# -gt 0 ]]; do
case $1 in
--claim|-c)
CLAIM_MODE=true
shift
;;
--json|-j)
JSON_OUTPUT=true
shift
;;
--help|-h)
echo "Usage: $0 [--claim] [--json]"
echo ""
echo "Options:"
echo " --claim, -c Claim the bead (set status to in_progress)"
echo " --json, -j Output as JSON"
echo " --help, -h Show this help"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Check if ready-queue exists
if [[ ! -f "$READY_QUEUE" ]]; then
echo "ERROR: ready-queue.json not found at $READY_QUEUE" >&2
echo "Run the queue generator first or use br-ready-workaround.sh" >&2
exit 1
fi
# Get the first available bead (highest priority)
NEXT_BEAD=$(jq -c '.beads[0]' "$READY_QUEUE" 2>/dev/null)
if [[ -z "$NEXT_BEAD" || "$NEXT_BEAD" == "null" ]]; then
echo "ERROR: No beads available in ready-queue.json" >&2
exit 1
fi
BEAD_ID=$(echo "$NEXT_BEAD" | jq -r '.id')
BEAD_TITLE=$(echo "$NEXT_BEAD" | jq -r '.title')
BEAD_PRIORITY=$(echo "$NEXT_BEAD" | jq -r '.priority')
if [[ "$JSON_OUTPUT" == "true" ]]; then
echo "$NEXT_BEAD"
else
echo "Next available bead:"
echo " ID: $BEAD_ID"
echo " Priority: P$BEAD_PRIORITY"
echo " Title: $BEAD_TITLE"
fi
# Claim the bead if requested
if [[ "$CLAIM_MODE" == "true" ]]; then
echo ""
echo "Claiming bead $BEAD_ID..."
br update "$BEAD_ID" --status in_progress
echo "Bead claimed! Start working on: $BEAD_TITLE"
fi