Files
openclaw-skills/workspace/model-selector/scripts/show-current.sh
b3nw 3b7d6bb67c Initial commit: custom OpenClaw skills from docker-test
- workspace: capmetro-monitor, github-notifications, model-selector
- workspace-security: vt-monitor, monitor-unauthorized
- workspace-home: cron-manager, monitor-unauthorized
- extensions: vt-sentinel (VT-Sentinel plugin)

Includes sync.sh for pull/push, README, AGENTS.md, .gitignore.
2026-02-16 15:32:44 +00:00

98 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# show-current.sh — Display the current model configuration from openclaw state
# Usage: show-current.sh
set -euo pipefail
# Find the state file
STATE_FILE="${OPENCLAW_STATE_DIR:-$HOME/.openclaw/state}/openclaw.json"
if [[ ! -f "$STATE_FILE" ]]; then
# Try alternative locations
for alt in \
"/opt/openclaw/state/openclaw.json" \
"${OPENCLAW_CONFIG_DIR:-$HOME/.openclaw/config}/openclaw.json"; do
if [[ -f "$alt" ]]; then
STATE_FILE="$alt"
break
fi
done
fi
if [[ ! -f "$STATE_FILE" ]]; then
echo "ERROR: Cannot find openclaw.json state file" >&2
echo "Searched:" >&2
echo " ${OPENCLAW_STATE_DIR:-$HOME/.openclaw/state}/openclaw.json" >&2
echo " /opt/openclaw/state/openclaw.json" >&2
echo " ${OPENCLAW_CONFIG_DIR:-$HOME/.openclaw/config}/openclaw.json" >&2
exit 1
fi
echo "📁 Config file: $STATE_FILE"
echo ""
python3 -c "
import json, sys, re
# Read file and strip JSON5 comments for parsing
with open('$STATE_FILE', 'r') as f:
content = f.read()
# Strip single-line comments (// ...) but not inside strings
lines = content.split('\n')
cleaned = []
for line in lines:
stripped = line.rstrip()
s = stripped.lstrip()
if s.startswith('//'):
continue
in_string = False
result = []
i = 0
while i < len(stripped):
c = stripped[i]
if c == '\"' and (i == 0 or stripped[i-1] != '\\\\'):
in_string = not in_string
elif c == '/' and i + 1 < len(stripped) and stripped[i+1] == '/' and not in_string:
break
result.append(c)
i += 1
cleaned.append(''.join(result))
# Remove trailing commas (JSON5)
json_str = '\n'.join(cleaned)
json_str = re.sub(r',\s*([}\]])', r'\1', json_str)
try:
cfg = json.loads(json_str)
except json.JSONDecodeError:
try:
cfg = json.loads(content)
except json.JSONDecodeError as e:
print(f'ERROR: Failed to parse config: {e}', file=sys.stderr)
sys.exit(1)
agents = cfg.get('agents', {})
defaults = agents.get('defaults', {})
model = defaults.get('model', {})
if isinstance(model, str):
print(f'🎯 Primary: {model}')
print(f'⛓️ Fallbacks: (none configured)')
else:
primary = model.get('primary', '(not set)')
fallbacks = model.get('fallbacks', [])
print(f'🎯 Primary: {primary}')
print(f'⛓️ Fallbacks ({len(fallbacks)}):')
for i, fb in enumerate(fallbacks, 1):
print(f' {i}. {fb}')
# Check for per-agent model overrides
agent_list = agents.get('list', [])
overrides = [(a.get('id', '?'), a.get('model', '')) for a in agent_list if 'model' in a]
if overrides:
print()
print('⚠️ Per-agent model overrides:')
for aid, amodel in overrides:
print(f' {aid}: {amodel}')
" 2>&1