Implements external LLM routing via opencode CLI for: - GitHub Copilot (gpt-5.2, claude-sonnet-4.5, claude-haiku-4.5, o3, gemini-3-pro) - Z.AI (glm-4.7 for code generation) - OpenCode native (big-pickle) Components: - mcp/llm-router/invoke.py: Main router with task-based model selection - mcp/llm-router/delegate.py: Agent delegation helper (respects external mode) - mcp/llm-router/toggle.py: Enable/disable external-only mode - mcp/llm-router/providers/: CLI wrappers for opencode and gemini Features: - Persistent toggle via state/external-mode.json - Task routing: reasoning -> gpt-5.2, code-gen -> glm-4.7, long-context -> gemini - Claude tier mapping: opus -> gpt-5.2, sonnet -> claude-sonnet-4.5, haiku -> claude-haiku-4.5 - Session-start hook announces when external mode is active - Natural language toggle support via component registry Plan: gleaming-routing-mercury Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
60 lines
1.9 KiB
Bash
Executable File
60 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Session start hook - provides context to Claude
|
|
# Output is injected into the session as a system reminder
|
|
|
|
set -euo pipefail
|
|
|
|
CLAUDE_DIR="${HOME}/.claude"
|
|
STATE_DIR="${CLAUDE_DIR}/state"
|
|
PA_DIR="${STATE_DIR}/personal-assistant"
|
|
|
|
# Check for unsummarized sessions
|
|
UNSUMMARIZED=0
|
|
if [[ -f "${PA_DIR}/history/index.json" ]]; then
|
|
UNSUMMARIZED=$(python3 -c "
|
|
import json
|
|
with open('${PA_DIR}/history/index.json') as f:
|
|
data = json.load(f)
|
|
unsummarized = [s for s in data.get('sessions', []) if not s.get('summarized', False)]
|
|
print(len(unsummarized))
|
|
" 2>/dev/null || echo "0")
|
|
fi
|
|
|
|
# Check for pending memory items
|
|
PENDING_DECISIONS=0
|
|
if [[ -f "${PA_DIR}/memory/decisions.json" ]]; then
|
|
PENDING_DECISIONS=$(python3 -c "
|
|
import json
|
|
with open('${PA_DIR}/memory/decisions.json') as f:
|
|
data = json.load(f)
|
|
pending = [d for d in data.get('items', []) if d.get('status') == 'pending']
|
|
print(len(pending))
|
|
" 2>/dev/null || echo "0")
|
|
fi
|
|
|
|
# Check external mode
|
|
EXTERNAL_MODE="disabled"
|
|
if [[ -f "${STATE_DIR}/external-mode.json" ]]; then
|
|
EXTERNAL_ENABLED=$(jq -r '.enabled // false' "${STATE_DIR}/external-mode.json" 2>/dev/null || echo "false")
|
|
if [[ "${EXTERNAL_ENABLED}" == "true" ]]; then
|
|
EXTERNAL_MODE="enabled"
|
|
fi
|
|
fi
|
|
|
|
# Output context as system reminder format
|
|
echo "SessionStart:resume hook success: Success"
|
|
|
|
# Add additional context if there's something noteworthy
|
|
if [[ "${UNSUMMARIZED}" -gt 0 || "${PENDING_DECISIONS}" -gt 0 || "${EXTERNAL_MODE}" == "enabled" ]]; then
|
|
echo "SessionStart hook additional context: "
|
|
if [[ "${EXTERNAL_MODE}" == "enabled" ]]; then
|
|
echo "- EXTERNAL MODE ACTIVE: All requests routed to external LLMs"
|
|
fi
|
|
if [[ "${UNSUMMARIZED}" -gt 0 ]]; then
|
|
echo "- ${UNSUMMARIZED} unsummarized session(s) available for review"
|
|
fi
|
|
if [[ "${PENDING_DECISIONS}" -gt 0 ]]; then
|
|
echo "- ${PENDING_DECISIONS} pending decision(s) to review"
|
|
fi
|
|
fi
|