refactor: skill 脚本输出改为结构化 JSON

- query_weather: {location, now: {temp,text}, forecast: [{date,day,night,tempMin,tempMax}]}
- search_web: {query, answer, results: [{title,url,content}]}
- get_current_datetime: {datetime}
- list_scheduled_tasks: {tasks: [{name,description,enabled,command,...}]}
- manage_scheduled_task: {ok, action, name} / {error}

LLM 直接看到结构化数据,不再依赖脚本拼接的中文自然语言
This commit is contained in:
2026-06-02 10:32:27 +08:00
parent fac2016b7e
commit 81c736f873
5 changed files with 111 additions and 253 deletions
@@ -1,7 +1,5 @@
#!/bin/bash
# 管理定时任务
set -e
# 管理定时任务 → JSON 输出
read -r input
ACTION=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('action',''))" 2>/dev/null)
NAME=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('name',''))" 2>/dev/null)
@@ -10,39 +8,32 @@ INTERVAL=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdi
DESC=$(echo "$input" | python3 -c "import sys,json; print(json.load(sys.stdin).get('description',''))" 2>/dev/null)
DB_URL="${DATABASE_URL}"
if [ -z "$DB_URL" ]; then
echo "数据库未配置(DATABASE_URL"
exit 1
fi
[ -z "$DB_URL" ] && echo '{"error":"数据库未配置"}' && exit 0
[ -z "$NAME" ] && echo '{"error":"请提供 name 参数"}' && exit 0
case "$ACTION" in
add)
if [ -z "$CMD" ]; then
echo "add 操作需要 command 参数"
exit 1
fi
psql "$DB_URL" -c "
INSERT INTO scheduled_tasks (id, name, description, command, interval_seconds, enabled, next_run_at)
VALUES (gen_random_uuid(), '$NAME', '$DESC', '$CMD', $INTERVAL, true, NOW() + interval '$INTERVAL seconds')
ON CONFLICT (name) DO UPDATE
SET command = EXCLUDED.command, interval_seconds = EXCLUDED.interval_seconds, enabled = true, description = EXCLUDED.description
" 2>/dev/null && echo "✅ 已添加/更新定时任务: $NAME" || echo "❌ 添加失败(表 scheduled_tasks 可能未创建)"
;;
delete)
psql "$DB_URL" -c "DELETE FROM scheduled_tasks WHERE name = '$NAME'" 2>/dev/null
echo "✅ 已删除定时任务: $NAME"
;;
enable)
psql "$DB_URL" -c "UPDATE scheduled_tasks SET enabled = true WHERE name = '$NAME'" 2>/dev/null
echo "✅ 已启用定时任务: $NAME"
;;
disable)
psql "$DB_URL" -c "UPDATE scheduled_tasks SET enabled = false WHERE name = '$NAME'" 2>/dev/null
echo "✅ 已禁用定时任务: $NAME"
;;
*)
echo "未知操作: $ACTION(支持: add, delete, enable, disable"
exit 1
;;
add)
[ -z "$CMD" ] && echo '{"error":"add 需要 command 参数"}' && exit 0
psql "$DB_URL" -c "
INSERT INTO scheduled_tasks (id, name, description, command, interval_seconds, enabled, next_run_at)
VALUES (gen_random_uuid(), '$NAME', '$DESC', '$CMD', $INTERVAL, true, NOW() + interval '$INTERVAL seconds')
ON CONFLICT (name) DO UPDATE SET command=EXCLUDED.command, interval_seconds=EXCLUDED.interval_seconds, enabled=true, description=EXCLUDED.description
" 2>/dev/null && echo '{"ok":true,"action":"add","name":"'"$NAME"'"}' || echo '{"error":"添加失败"}'
;;
delete)
psql "$DB_URL" -c "DELETE FROM scheduled_tasks WHERE name = '$NAME'" 2>/dev/null
echo '{"ok":true,"action":"delete","name":"'"$NAME"'"}'
;;
enable)
psql "$DB_URL" -c "UPDATE scheduled_tasks SET enabled = true WHERE name = '$NAME'" 2>/dev/null
echo '{"ok":true,"action":"enable","name":"'"$NAME"'"}'
;;
disable)
psql "$DB_URL" -c "UPDATE scheduled_tasks SET enabled = false WHERE name = '$NAME'" 2>/dev/null
echo '{"ok":true,"action":"disable","name":"'"$NAME"'"}'
;;
*)
echo '{"error":"未知操作: '"$ACTION"'(支持: add, delete, enable, disable"}'
exit 1
;;
esac