Files
iAs/resources/skills/execute_shell/scripts/shell.sh
T
wunianxiao b9de3665d9 feat: iPet → iAs 完整迁移,Rust 版微信 AI 助手
Phase 1  CLI 框架 + 配置系统
  - clap 子命令: login / listen / send / whoami / usage
  - config.json + env var 替换
  - tracing 日志系统
  - state 持久化(auth/runtime 文件存 + PostgreSQL)

Phase 2  微信通道
  - wechat::client — 完整 iLink Bot HTTP API 实现
  - 扫码登录(终端二维码 + 轮询状态)
  - 长轮询 getupdates / 消息收发 / 监听注册

Phase 3  AI 对话(纯文本 + function calling)
  - LlmProvider trait: DeepSeek + LM Studio 实现
  - SSE 流式解析(text / reasoning / tool_calls delta / usage)
  - Conversation: 消息历史 + chat / chat_with_tools 工具循环

Phase 4  PostgreSQL 集成
  - app_state(认证 KV 存储)
  - chat_records(消息收发记录)
  - llm_usage(Token 用量统计缓存命中率)
  - user_memories(长期记忆持久化)
  - pending_approvals(审批确认码)
  - scheduled_tasks(定时任务表)

Phase 5  一切皆 Skill(工具系统)
  - SkillRegistry: 系统 + 用户 skills 双目录合并
  - SKILL.md 解析器 + 子进程执行器(stdin JSON → stdout)
  - 9 个系统 Skills: datetime / weather / search / email /
    shell / schedule / memos / read_memories / read_summaries
  - ApprovalManager: High 风险技能 → 确认码审批(透明模式)
  - High 风险技能:确认码审批(透明模式)

Phase 6  定时任务调度器

上下文管理
  - ChatSession: checkpoint + token budget (28K) + summaries
  - Token 估算器(中英文自适应)
  - 12h 空闲 → trigger_idle_summary(不入会话)
  - Budget 溢出 → trigger_overflow_summary(入会话 + drain 旧消息)
  - Summarizer: LLM 生成自然语言摘要(fallback 简单截断)
  - 长期记忆 / 摘要 通过 read_memories / read_summaries 工具按需读取

工具调用日志 + Token 统计
  - INFO: 工具名 + 参数 + 结果摘要
  - DEBUG: 子进程 exit/stdout/stderr
  - ias usage --since --until --model 查看用量和缓存命中率
2026-06-01 17:21:43 +08:00

37 lines
981 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 执行 shell 命令
# 高风险:需要确认码审批
set -e
read -r input
CMD=$(echo "$input" | python3 -c "
import sys, json
d = json.load(sys.stdin)
print(d.get('command', ''))
" 2>/dev/null)
TIMEOUT=$(echo "$input" | python3 -c "
import sys, json
d = json.load(sys.stdin)
print(d.get('timeout', 30))
" 2>/dev/null)
if [ -z "$CMD" ]; then
echo "请提供 command 参数"
exit 1
fi
# 安全限制:禁止危险命令
LOWER_CMD=$(echo "$CMD" | tr '[:upper:]' '[:lower:]')
for DANGEROUS in "rm -rf /" "mkfs" "dd if=" ":(){ :|:& };:" "> /dev/" "wget http" "curl http"; do
if echo "$LOWER_CMD" | grep -q "$DANGEROUS"; then
echo "禁止执行危险命令: $DANGEROUS"
exit 1
fi
done
# 输出前 N 行防止刷屏
OUTPUT=$(timeout "$TIMEOUT" bash -c "$CMD" 2>&1 || echo "命令执行失败(退出码: $?")
echo "$OUTPUT" | head -50
[ "$(echo "$OUTPUT" | wc -l)" -gt 50 ] && echo "...(输出已截断,共 $(echo "$OUTPUT" | wc -l) 行)"