harb/.claude/hooks/supervisor/triage.sh
openhands 85350caf52 feat: OptimizerV3 with direct 2D staking-to-LP parameter mapping
Core protocol changes for launch readiness:

- OptimizerV3: binary bear/bull mapping from (staking%, avgTax) — avoids
  exploitable AW 30-90 kill zone. Bear: AS=30%, AW=100, CI=0, DD=0.3e18.
  Bull: AS=100%, AW=20, CI=0, DD=1e18. UUPS upgradeable with __gap[48].
- Directional VWAP: only records prices on ETH inflow (buys), preventing
  sell-side dilution of price memory
- Floor formula: unified max(scarcity, mirror, clamp) — VWAP mirror uses
  distance from adjusted VWAP as floor distance, no branching
- PriceOracle (M-1 fix): correct fallback TWAP divisor (60000s, not 300s)
- Access control (M-2 fix): deployer-only guard on one-time setters
- Recenter rate limit (M-3 fix): 60-second cooldown for open recenters
- Safe fallback params: recenter() optimizer-failure defaults changed from
  exploitable CI=50%/AW=50 to safe bear-mode CI=0/AW=100
- Recentered event for monitoring and indexing
- VERSION bump to 2, kraiken-lib COMPATIBLE_CONTRACT_VERSIONS updated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 18:21:18 +00:00

72 lines
2.3 KiB
Bash
Executable file

#!/bin/bash
# Triage a Claude Code event using a fast LLM.
# Called by hook scripts when bash pre-filtering can't decide.
#
# Usage: triage.sh <event-type> <cwd> <context>
# event-type: stopped | error | notification
# cwd: project directory (used to find config + state)
# context: the relevant context (tmux output, error message, etc.)
#
# Reads supervisor-state.json to find the goal for this session.
# Returns one of: FINE | NEEDS_NUDGE | STUCK | DONE | ESCALATE
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib.sh"
EVENT_TYPE="${1:-unknown}"
CWD="${2:-.}"
CONTEXT="${3:-}"
CONFIG=$(ccs_find_config "$CWD")
# Try to find the goal from supervisor state
STATE_FILE="${CCS_STATE_FILE:-${HOME}/.openclaw/workspace/supervisor-state.json}"
GOAL="unknown"
if [ -f "$STATE_FILE" ]; then
# Match by cwd/projectDir
GOAL=$(jq -r --arg cwd "$CWD" '
.sessions | to_entries[] | select(.value.projectDir == $cwd) | .value.goal
' "$STATE_FILE" 2>/dev/null || echo "unknown")
fi
PROMPT="You are a coding agent supervisor. A Claude Code session just triggered an event.
Event: ${EVENT_TYPE}
Project: ${CWD}
Goal: ${GOAL}
Recent terminal output:
${CONTEXT}
Classify this situation with exactly one word on the first line:
FINE - Agent is working normally, no intervention needed
NEEDS_NUDGE - Agent hit a transient error or stopped prematurely, should be told to continue
STUCK - Agent is looping or not making progress, needs different approach
DONE - Agent completed the task successfully
ESCALATE - Situation needs human judgment
Then a one-line explanation."
VERDICT=$(ccs_triage "$CONFIG" "$PROMPT")
echo "$VERDICT"
# Extract the classification (first word of first line)
CLASSIFICATION=$(echo "$VERDICT" | head -1 | awk '{print $1}')
# Only notify if action is needed
case "$CLASSIFICATION" in
FINE)
# Log silently, don't wake anyone
echo "[$(date -u +%FT%TZ)] FINE | $EVENT_TYPE | $CWD" >> "${CCS_LOG_FILE:-/tmp/ccs-triage.log}"
;;
NEEDS_NUDGE|STUCK|DONE|ESCALATE)
ccs_notify "$CONFIG" "cc-supervisor: $CLASSIFICATION | $EVENT_TYPE | cwd=$CWD | $VERDICT"
;;
*)
# Couldn't parse — notify to be safe
ccs_notify "$CONFIG" "cc-supervisor: UNKNOWN | $EVENT_TYPE | cwd=$CWD | verdict=$VERDICT"
;;
esac