Files
karuo-ai/.restore-backups/F22_恢复前_20260723_210051/karuo_route.sh

50 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="/Users/karuo/Documents/个人/卡若AI"
REGISTRY="$ROOT/SKILL_REGISTRY.md"
if [[ ! -f "$REGISTRY" ]]; then
echo "Missing registry: $REGISTRY" >&2
exit 1
fi
QUERY="${*:-}"
if [[ -z "$QUERY" ]]; then
echo "Usage: $0 <keyword>" >&2
exit 2
fi
# Natural-language queries usually contain several keywords. Searching the
# complete sentence as one literal/regex makes valid Skills look unavailable.
# Split on whitespace, escape regex metacharacters, and match any useful token.
PATTERN="$(
printf '%s\n' "$QUERY" |
tr '[:space:]' '\n' |
awk 'length($0) >= 2 &&
tolower($0) != "skill" &&
$0 != "请求" &&
$0 != "功能" &&
$0 != "卡若AI" &&
$0 != "卡罗维亚" &&
$0 != "卡路AI"' |
sed 's/[][(){}.^$*+?|\\/]/\\&/g' |
paste -sd'|' -
)"
[[ -n "$PATTERN" ]] || PATTERN="$(printf '%s' "$QUERY" | sed 's/[][(){}.^$*+?|\\/]/\\&/g')"
# Chinese ASR text often has no spaces. Extract high-value routing terms from
# the original sentence so phrases such as “优化破解这个skill” still match.
for term in 破甲 破解 越狱回归 请求被拦截 PromptInjection Smali Frida Hook 逆向分析 模拟登录; do
compact_query="${QUERY// /}"
compact_term="${term// /}"
compact_query_lower="$(printf '%s' "$compact_query" | tr '[:upper:]' '[:lower:]')"
compact_term_lower="$(printf '%s' "$compact_term" | tr '[:upper:]' '[:lower:]')"
if [[ "$compact_query_lower" == *"$compact_term_lower"* ]]; then
PATTERN="${PATTERN}|${term}"
fi
done
rg -n -i --color never --context 1 -- "$PATTERN" "$REGISTRY" | head -80