feat(M13 PBI-31 T-519b/T-520b): NavBar stand-by badge + quota-check runbook (#119)

* feat(M13 T-519b): SSE worker_heartbeat + NavBar stand-by badge

Aanvulling op scrum4me-mcp PR #25 (worker_heartbeat MCP-tool).

- app/api/realtime/solo/route.ts: WorkerHeartbeatPayload type +
  isWorkerHeartbeatPayload guard + shouldEmit-routing op user_id.
- stores/solo-store.ts: workerQuotaPct + workerQuotaCheckAt state +
  setWorkerQuota action. Reset bij decrementWorkers naar 0.
- lib/realtime/use-solo-realtime.ts: handle worker_heartbeat-event,
  roep setWorkerQuota.
- components/solo/nav-status-indicators.tsx: stand-by badge wanneer
  workerQuotaPct < minQuotaPct + tooltip met drempel.
- components/shared/nav-bar.tsx + app/(app)/layout.tsx: minQuotaPct
  prop plumbing van User.min_quota_pct naar NavStatusIndicators.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(M13 T-520b): pre-flight quota-check sectie in mcp-integration

Documenteert de batch-loop-uitbreiding:
1. get_worker_settings → min_quota_pct
2. bin/worker-quota-probe.sh → pct + reset
3. worker_heartbeat naar server (NavBar stand-by-badge)
4. Sleep tot reset bij low quota; anders wait_for_job

Verwijst naar bin/worker-quota-probe.sh in scrum4me-docker (zie
PR daar).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-05-06 04:34:48 +02:00 committed by GitHub
parent 555ed8fe89
commit 31dc429b61
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 126 additions and 8 deletions

View file

@ -2,7 +2,7 @@
# Documentation Index
Auto-generated on 2026-05-05 from front-matter and headings.
Auto-generated on 2026-05-06 from front-matter and headings.
## Architecture Decision Records

View file

@ -70,6 +70,43 @@ Wanneer je als agent draait (na een instructie als *"pak de volgende job uit de
Dit blijft gelden als je tussen jobs door commits, branches of pushes hebt gedaan — die afsluiting hoort bij de individuele job, niet bij het einde van de batch.
## Pre-flight quota-check (M13)
Vóór elke `wait_for_job`-aanroep doet de worker een pre-flight quota-check
om te voorkomen dat-ie 600 s blokkeert terwijl Anthropic-quota toch op
0 staat. Loop:
1. `mcp__scrum4me__get_worker_settings()``{ min_quota_pct }`
2. `bash bin/worker-quota-probe.sh` → JSON `{ pct, reset_at_iso, ... }`
3. `mcp__scrum4me__worker_heartbeat({ last_quota_pct: pct, last_quota_check_at })`
— server emit een SSE-event zodat NavBar realtime de stand-by-badge
kan tonen
4. **Als `pct < min_quota_pct`**: log "stand-by, wachten tot
`reset_at_iso`", sleep tot reset (cap op 1 uur), spring naar stap 2
5. **Anders**: ga door met `wait_for_job`
Pseudo-bash:
```bash
QUOTA_JSON=$(/opt/agent/bin/worker-quota-probe.sh)
PCT=$(echo "$QUOTA_JSON" | jq -r '.pct')
RESET=$(echo "$QUOTA_JSON" | jq -r '.reset_at_iso')
# Stuur naar server (best-effort; failure niet-fataal)
mcp_call worker_heartbeat "{\"last_quota_pct\": $PCT}"
if [[ "$PCT" -lt "$MIN_PCT" ]]; then
log "stand-by until $RESET (pct=$PCT < min=$MIN_PCT)"
sleep_until "$RESET"
continue
fi
```
**Beperking**: de probe kost ~1 outputtoken per check. 12 checks/uur =
12 tokens/uur overhead — verwaarloosbaar. De `min_quota_pct`-setting
staat per default op 20% — bij vrije Pro/Max-plans typisch ruim genoeg
om dagelijks werk niet te verstoren.
**Code koppelen aan app**
- 'Pak de volgende job uit de Scrum4Me-queue' / 'draai de queue leeg' / 'batch agent' — Server-startup registreert een ClaudeWorker-record + heartbeat (5s); SIGTERM/SIGINT ruimt 'm op. UI in NavBar telt actieve workers via `last_seen_at < now() - 15s`.