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 查看用量和缓存命中率
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# manage_memos
|
||||
|
||||
管理备忘录:添加、列出、删除。
|
||||
|
||||
备忘录存储在 `.data/memos.json` 文件中。
|
||||
|
||||
## Risk Level
|
||||
Low
|
||||
|
||||
## Parameters
|
||||
```json
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {
|
||||
"type": "string",
|
||||
"description": "操作类型",
|
||||
"enum": ["add", "list", "delete"]
|
||||
},
|
||||
"content": {
|
||||
"type": "string",
|
||||
"description": "备忘内容(add 时需要)"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "备忘编号(delete 时需要)"
|
||||
}
|
||||
},
|
||||
"required": ["action"]
|
||||
}
|
||||
```
|
||||
|
||||
## Execute
|
||||
```bash
|
||||
scripts/memo.sh
|
||||
```
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
# 备忘录管理 — 存储 .data/memos.json
|
||||
MEMO_FILE=".data/memos.json"
|
||||
mkdir -p "$(dirname "$MEMO_FILE")"
|
||||
[ ! -f "$MEMO_FILE" ] && echo '[]' > "$MEMO_FILE"
|
||||
|
||||
read -r INPUT
|
||||
export MEMO_INPUT="$INPUT"
|
||||
|
||||
python3 - "$MEMO_FILE" << 'PYEOF'
|
||||
import sys, json, os, datetime
|
||||
|
||||
path = sys.argv[1]
|
||||
input_raw = os.environ.get('MEMO_INPUT', '{}')
|
||||
|
||||
try: req = json.loads(input_raw)
|
||||
except:
|
||||
print('无效的 JSON 输入')
|
||||
sys.exit(1)
|
||||
|
||||
action = req.get('action', 'list')
|
||||
content = req.get('content', '')
|
||||
memo_id = req.get('id', '')
|
||||
|
||||
data = json.load(open(path)) if os.path.exists(path) and os.path.getsize(path) > 0 else []
|
||||
|
||||
if action == 'add':
|
||||
if not content:
|
||||
print('请提供 content 参数')
|
||||
sys.exit(1)
|
||||
next_id = max([m.get('id', 0) for m in data], default=0) + 1
|
||||
data.append({'id': next_id, 'content': content, 'created_at': datetime.datetime.now().isoformat()})
|
||||
json.dump(data, open(path, 'w'), ensure_ascii=False, indent=2)
|
||||
print(f'已添加备忘录 #{next_id}')
|
||||
|
||||
elif action == 'list':
|
||||
if not data:
|
||||
print('暂无备忘录')
|
||||
else:
|
||||
for m in data:
|
||||
ts = m.get('created_at', '?')[:16]
|
||||
print(f"#{m['id']} [{ts}] {m['content']}")
|
||||
|
||||
elif action == 'delete':
|
||||
if not memo_id:
|
||||
print('请提供 id 参数')
|
||||
sys.exit(1)
|
||||
new = [m for m in data if str(m.get('id', '')) != str(memo_id)]
|
||||
if len(new) == len(data):
|
||||
print(f'未找到备忘 #{memo_id}')
|
||||
else:
|
||||
json.dump(new, open(path, 'w'), ensure_ascii=False, indent=2)
|
||||
print(f'已删除备忘 #{memo_id}')
|
||||
|
||||
else:
|
||||
print(f'未知操作: {action}(支持: add, list, delete)')
|
||||
sys.exit(1)
|
||||
PYEOF
|
||||
Reference in New Issue
Block a user