weflow-cli 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +105 -0
- package/CHANGELOG.md +121 -0
- package/CONTRIBUTING.md +45 -0
- package/LICENSE +21 -21
- package/OPERATIONS.md +272 -0
- package/README.en.md +281 -0
- package/README.md +334 -149
- package/SECURITY.md +47 -0
- package/bin/weflow-cli.ts +4050 -581
- package/dist/bin/weflow-cli.js +4310 -588
- package/dist/bin/weflow-cli.js.map +1 -1
- package/dist/mcp-server/index.js +178 -236
- package/dist/mcp-server/index.js.map +1 -1
- package/dist/src/core/dbPathService.d.ts +15 -1
- package/dist/src/core/dbPathService.d.ts.map +1 -1
- package/dist/src/core/dbPathService.js +177 -19
- package/dist/src/core/dbPathService.js.map +1 -1
- package/dist/src/core/keyService.d.ts +8 -0
- package/dist/src/core/keyService.d.ts.map +1 -1
- package/dist/src/core/keyService.js +127 -22
- package/dist/src/core/keyService.js.map +1 -1
- package/dist/src/core/ntCore.d.ts +59 -1
- package/dist/src/core/ntCore.d.ts.map +1 -1
- package/dist/src/core/ntCore.js +201 -65
- package/dist/src/core/ntCore.js.map +1 -1
- package/dist/src/core/sqlcipherCore.d.ts.map +1 -1
- package/dist/src/core/sqlcipherCore.js +18 -1
- package/dist/src/core/sqlcipherCore.js.map +1 -1
- package/dist/src/core/wcdbCore.d.ts.map +1 -1
- package/dist/src/core/wcdbCore.js +3 -6
- package/dist/src/core/wcdbCore.js.map +1 -1
- package/dist/src/services/assistantDaemon.d.ts +19 -0
- package/dist/src/services/assistantDaemon.d.ts.map +1 -0
- package/dist/src/services/assistantDaemon.js +117 -0
- package/dist/src/services/assistantDaemon.js.map +1 -0
- package/dist/src/services/assistantMemory.d.ts +36 -0
- package/dist/src/services/assistantMemory.d.ts.map +1 -0
- package/dist/src/services/assistantMemory.js +182 -0
- package/dist/src/services/assistantMemory.js.map +1 -0
- package/dist/src/services/assistantPrivacy.d.ts +25 -0
- package/dist/src/services/assistantPrivacy.d.ts.map +1 -0
- package/dist/src/services/assistantPrivacy.js +77 -0
- package/dist/src/services/assistantPrivacy.js.map +1 -0
- package/dist/src/services/assistantRouting.d.ts +18 -0
- package/dist/src/services/assistantRouting.d.ts.map +1 -0
- package/dist/src/services/assistantRouting.js +68 -0
- package/dist/src/services/assistantRouting.js.map +1 -0
- package/dist/src/services/assistantService.d.ts +37 -0
- package/dist/src/services/assistantService.d.ts.map +1 -0
- package/dist/src/services/assistantService.js +284 -0
- package/dist/src/services/assistantService.js.map +1 -0
- package/dist/src/services/assistantTools.d.ts +24 -0
- package/dist/src/services/assistantTools.d.ts.map +1 -0
- package/dist/src/services/assistantTools.js +582 -0
- package/dist/src/services/assistantTools.js.map +1 -0
- package/dist/src/services/chatService.d.ts +44 -0
- package/dist/src/services/chatService.d.ts.map +1 -1
- package/dist/src/services/chatService.js +105 -4
- package/dist/src/services/chatService.js.map +1 -1
- package/dist/src/services/configService.d.ts +55 -0
- package/dist/src/services/configService.d.ts.map +1 -1
- package/dist/src/services/configService.js +147 -6
- package/dist/src/services/configService.js.map +1 -1
- package/dist/src/services/evidenceService.d.ts +30 -0
- package/dist/src/services/evidenceService.d.ts.map +1 -0
- package/dist/src/services/evidenceService.js +98 -0
- package/dist/src/services/evidenceService.js.map +1 -0
- package/dist/src/services/exportService.d.ts +13 -20
- package/dist/src/services/exportService.d.ts.map +1 -1
- package/dist/src/services/exportService.js +113 -47
- package/dist/src/services/exportService.js.map +1 -1
- package/dist/src/services/initKeyService.d.ts +19 -0
- package/dist/src/services/initKeyService.d.ts.map +1 -0
- package/dist/src/services/initKeyService.js +80 -0
- package/dist/src/services/initKeyService.js.map +1 -0
- package/dist/src/services/messageContract.d.ts +23 -0
- package/dist/src/services/messageContract.d.ts.map +1 -0
- package/dist/src/services/messageContract.js +49 -0
- package/dist/src/services/messageContract.js.map +1 -0
- package/dist/src/services/messageQuery.d.ts +7 -0
- package/dist/src/services/messageQuery.d.ts.map +1 -0
- package/dist/src/services/messageQuery.js +30 -0
- package/dist/src/services/messageQuery.js.map +1 -0
- package/dist/src/services/wechat-formatter.js +14 -14
- package/dist/src/services/wechatMessageService.d.ts.map +1 -1
- package/dist/src/services/wechatMessageService.js +31 -3
- package/dist/src/services/wechatMessageService.js.map +1 -1
- package/dist/src/services/whitelistService.d.ts +52 -4
- package/dist/src/services/whitelistService.d.ts.map +1 -1
- package/dist/src/services/whitelistService.js +183 -17
- package/dist/src/services/whitelistService.js.map +1 -1
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/dateRange.d.ts +15 -0
- package/dist/src/utils/dateRange.d.ts.map +1 -0
- package/dist/src/utils/dateRange.js +48 -0
- package/dist/src/utils/dateRange.js.map +1 -0
- package/dist/src/utils/mcpSecurity.d.ts +5 -0
- package/dist/src/utils/mcpSecurity.d.ts.map +1 -0
- package/dist/src/utils/mcpSecurity.js +39 -0
- package/dist/src/utils/mcpSecurity.js.map +1 -0
- package/dist/src/utils/packageRoot.d.ts +2 -0
- package/dist/src/utils/packageRoot.d.ts.map +1 -0
- package/dist/src/utils/packageRoot.js +16 -0
- package/dist/src/utils/packageRoot.js.map +1 -0
- package/dist/src/utils/python.d.ts +2 -0
- package/dist/src/utils/python.d.ts.map +1 -0
- package/dist/src/utils/python.js +72 -0
- package/dist/src/utils/python.js.map +1 -0
- package/dist/src/utils/pythonProcessEnv.d.ts +3 -0
- package/dist/src/utils/pythonProcessEnv.d.ts.map +1 -0
- package/dist/src/utils/pythonProcessEnv.js +46 -0
- package/dist/src/utils/pythonProcessEnv.js.map +1 -0
- package/dist/src/utils/talkerUtils.d.ts +4 -1
- package/dist/src/utils/talkerUtils.d.ts.map +1 -1
- package/dist/src/utils/talkerUtils.js +9 -9
- package/dist/src/utils/talkerUtils.js.map +1 -1
- package/dist/src/utils/wechatEmoji.d.ts +5 -0
- package/dist/src/utils/wechatEmoji.d.ts.map +1 -0
- package/dist/src/utils/wechatEmoji.js +35 -0
- package/dist/src/utils/wechatEmoji.js.map +1 -0
- package/docs/AI_INTERFACE.md +189 -0
- package/docs/BRANCHES.md +87 -0
- package/docs/DATA_CONTRACT.md +74 -0
- package/docs/DECISIONS.md +270 -0
- package/docs/DEEPSEEK_V4_FLASH/346/226/275/345/267/245/346/226/207/346/241/243.md +234 -0
- package/docs/EVIDENCE_GUIDE.md +96 -0
- package/docs/MCP.md +95 -0
- package/docs/PARTNERS.md +41 -0
- package/docs/PROJECT_STATE.md +96 -0
- package/docs/RELEASING.md +124 -0
- package/docs/ROADMAP.md +191 -0
- package/docs/SETUP.md +103 -0
- package/docs/images/weflow-architecture-gpt-image-2.png +0 -0
- package/docs/images/weflow-architecture.png +0 -0
- package/docs/images/weflow-architecture.svg +65 -0
- package/mcp-server/index.ts +169 -269
- package/package.json +81 -72
- package/requirements-3x.txt +4 -0
- package/requirements-voice.txt +15 -0
- package/requirements.txt +9 -0
- package/resources/js/marked.min.js +69 -0
- package/resources/wechat-emoji/666.png +0 -0
- package/resources/wechat-emoji/Awesome.png +0 -0
- package/resources/wechat-emoji/Concerned.png +0 -0
- package/resources/wechat-emoji/Cry.png +0 -0
- package/resources/wechat-emoji/Emm.png +0 -0
- package/resources/wechat-emoji/Facepalm.png +0 -0
- package/resources/wechat-emoji/Grin.png +0 -0
- package/resources/wechat-emoji/OK.png +0 -0
- package/resources/wechat-emoji/Respect.png +0 -0
- package/resources/wechat-emoji/Sick.png +0 -0
- package/resources/wechat-emoji/Sleep.png +0 -0
- package/resources/wechat-emoji/Smile.png +0 -0
- package/resources/wechat-emoji//344/272/262/344/272/262.png +0 -0
- package/resources/wechat-emoji//344/276/277/344/276/277.png +0 -0
- package/resources/wechat-emoji//345/201/267/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/202/262/346/205/242.png +0 -0
- package/resources/wechat-emoji//345/206/215/350/247/201.png +0 -0
- package/resources/wechat-emoji//345/207/213/350/260/242.png +0 -0
- package/resources/wechat-emoji//345/212/240/346/262/271.png +0 -0
- package/resources/wechat-emoji//345/213/276/345/274/225.png +0 -0
- package/resources/wechat-emoji//345/217/221/345/221/206.png +0 -0
- package/resources/wechat-emoji//345/217/221/346/200/222.png +0 -0
- package/resources/wechat-emoji//345/217/221/346/212/226.png +0 -0
- package/resources/wechat-emoji//345/217/257/346/200/234.png +0 -0
- package/resources/wechat-emoji//345/217/263/345/223/274/345/223/274.png +0 -0
- package/resources/wechat-emoji//345/217/271/346/260/224.png +0 -0
- package/resources/wechat-emoji//345/220/203/347/223/234.png +0 -0
- package/resources/wechat-emoji//345/220/210/345/215/201.png +0 -0
- package/resources/wechat-emoji//345/220/220.png +0 -0
- package/resources/wechat-emoji//345/221/262/347/211/231.png +0 -0
- package/resources/wechat-emoji//345/222/222/351/252/202.png +0 -0
- package/resources/wechat-emoji//345/222/226/345/225/241.png +0 -0
- package/resources/wechat-emoji//345/223/207.png +0 -0
- package/resources/wechat-emoji//345/225/244/351/205/222.png +0 -0
- package/resources/wechat-emoji//345/230/230.png +0 -0
- package/resources/wechat-emoji//345/230/264/345/224/207.png +0 -0
- package/resources/wechat-emoji//345/230/277/345/223/210.png +0 -0
- package/resources/wechat-emoji//345/233/247.png +0 -0
- package/resources/wechat-emoji//345/233/260.png +0 -0
- package/resources/wechat-emoji//345/235/217/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/244/247/345/223/255.png +0 -0
- package/resources/wechat-emoji//345/244/251/345/225/212.png +0 -0
- package/resources/wechat-emoji//345/244/252/351/230/263.png +0 -0
- package/resources/wechat-emoji//345/244/261/346/234/233.png +0 -0
- package/resources/wechat-emoji//345/245/270/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/245/275/347/232/204.png +0 -0
- package/resources/wechat-emoji//345/247/224/345/261/210.png +0 -0
- package/resources/wechat-emoji//345/256/263/347/276/236.png +0 -0
- package/resources/wechat-emoji//345/260/264/345/260/254.png +0 -0
- package/resources/wechat-emoji//345/272/206/347/245/235.png +0 -0
- package/resources/wechat-emoji//345/274/261.png +0 -0
- package/resources/wechat-emoji//345/274/272.png +0 -0
- package/resources/wechat-emoji//345/276/227/346/204/217.png +0 -0
- package/resources/wechat-emoji//345/276/256/347/254/221.png +0 -0
- package/resources/wechat-emoji//345/277/203/347/242/216.png +0 -0
- package/resources/wechat-emoji//345/277/253/345/223/255/344/272/206.png +0 -0
- package/resources/wechat-emoji//346/201/220/346/203/247.png +0 -0
- package/resources/wechat-emoji//346/202/240/351/227/262.png +0 -0
- package/resources/wechat-emoji//346/203/212/346/201/220.png +0 -0
- package/resources/wechat-emoji//346/203/212/350/256/266.png +0 -0
- package/resources/wechat-emoji//346/204/211/345/277/253.png +0 -0
- package/resources/wechat-emoji//346/206/250/347/254/221.png +0 -0
- package/resources/wechat-emoji//346/211/223/350/204/270.png +0 -0
- package/resources/wechat-emoji//346/212/223/347/213/202.png +0 -0
- package/resources/wechat-emoji//346/212/240/351/274/273.png +0 -0
- package/resources/wechat-emoji//346/212/261/346/213/263.png +0 -0
- package/resources/wechat-emoji//346/213/245/346/212/261.png +0 -0
- package/resources/wechat-emoji//346/213/263/345/244/264.png +0 -0
- package/resources/wechat-emoji//346/215/202/350/204/270.png +0 -0
- package/resources/wechat-emoji//346/217/241/346/211/213.png +0 -0
- package/resources/wechat-emoji//346/222/207/345/230/264.png +0 -0
- package/resources/wechat-emoji//346/223/246/346/261/227.png +0 -0
- package/resources/wechat-emoji//346/225/262/346/211/223.png +0 -0
- package/resources/wechat-emoji//346/227/240/350/257/255.png +0 -0
- package/resources/wechat-emoji//346/227/272/346/237/264.png +0 -0
- package/resources/wechat-emoji//346/231/225.png +0 -0
- package/resources/wechat-emoji//346/234/210/344/272/256.png +0 -0
- package/resources/wechat-emoji//346/234/272/346/231/272.png +0 -0
- package/resources/wechat-emoji//346/261/227.png +0 -0
- package/resources/wechat-emoji//346/265/201/346/263/252.png +0 -0
- package/resources/wechat-emoji//347/202/270/345/274/271.png +0 -0
- package/resources/wechat-emoji//347/203/237/350/212/261.png +0 -0
- package/resources/wechat-emoji//347/210/206/347/253/271.png +0 -0
- package/resources/wechat-emoji//347/210/261/345/277/203.png +0 -0
- package/resources/wechat-emoji//347/214/252/345/244/264.png +0 -0
- package/resources/wechat-emoji//347/216/253/347/221/260.png +0 -0
- package/resources/wechat-emoji//347/224/237/347/227/205.png +0 -0
- package/resources/wechat-emoji//347/226/221/351/227/256.png +0 -0
- package/resources/wechat-emoji//347/231/274.png +0 -0
- package/resources/wechat-emoji//347/231/275/347/234/274.png +0 -0
- package/resources/wechat-emoji//347/232/261/347/234/211.png +0 -0
- package/resources/wechat-emoji//347/235/241.png +0 -0
- package/resources/wechat-emoji//347/240/264/346/266/225/344/270/272/347/254/221.png +0 -0
- package/resources/wechat-emoji//347/244/274/347/211/251.png +0 -0
- package/resources/wechat-emoji//347/244/276/344/274/232/347/244/276/344/274/232.png +0 -0
- package/resources/wechat-emoji//347/246/217.png +0 -0
- package/resources/wechat-emoji//347/254/221/350/204/270.png +0 -0
- package/resources/wechat-emoji//347/272/242/345/214/205.png +0 -0
- package/resources/wechat-emoji//347/277/273/347/231/275/347/234/274.png +0 -0
- package/resources/wechat-emoji//350/200/266.png +0 -0
- package/resources/wechat-emoji//350/203/234/345/210/251.png +0 -0
- package/resources/wechat-emoji//350/204/270/347/272/242.png +0 -0
- package/resources/wechat-emoji//350/211/262.png +0 -0
- package/resources/wechat-emoji//350/213/246/346/266/251.png +0 -0
- package/resources/wechat-emoji//350/217/234/345/210/200.png +0 -0
- package/resources/wechat-emoji//350/233/213/347/263/225.png +0 -0
- package/resources/wechat-emoji//350/241/260.png +0 -0
- package/resources/wechat-emoji//350/243/202/345/274/200.png +0 -0
- package/resources/wechat-emoji//350/256/251/346/210/221/347/234/213/347/234/213.png +0 -0
- package/resources/wechat-emoji//350/260/203/347/232/256.png +0 -0
- package/resources/wechat-emoji//350/267/263/350/267/263.png +0 -0
- package/resources/wechat-emoji//350/275/254/345/234/210.png +0 -0
- package/resources/wechat-emoji//351/204/231/350/247/206.png +0 -0
- package/resources/wechat-emoji//351/227/255/345/230/264.png +0 -0
- package/resources/wechat-emoji//351/230/264/351/231/251.png +0 -0
- package/resources/wechat-emoji//351/232/276/350/277/207.png +0 -0
- package/resources/wechat-emoji//351/252/267/351/253/205.png +0 -0
- package/resources/wechat-emoji//351/274/223/346/216/214.png +0 -0
- package/scripts/_batch_link_sources.py +73 -73
- package/scripts/_utils.py +29 -0
- package/scripts/annual_report.py +796 -796
- package/scripts/auto_tag.py +128 -128
- package/scripts/biz_daily.py +210 -53
- package/scripts/chat_report.py +10 -0
- package/scripts/chat_stats.py +702 -702
- package/scripts/classify_daily.py +17 -11
- package/scripts/create_reading_notes.py +370 -370
- package/scripts/daily_stats.py +132 -0
- package/scripts/enrich_backlinks.py +163 -163
- package/scripts/export_chat_html.py +1704 -107
- package/scripts/extract_todos.py +445 -404
- package/scripts/fav_server.py +119 -12
- package/scripts/fix_topics.py +111 -111
- package/scripts/generate_ai_report.py +1 -1
- package/scripts/generate_html.py +597 -277
- package/scripts/inspection_records.py +354 -0
- package/scripts/mcp_bridge.py +398 -398
- package/scripts/nt_decrypt.py +702 -48
- package/scripts/pipeline.py +27 -19
- package/scripts/promote_all.py +312 -310
- package/scripts/promote_ideas.py +299 -297
- package/scripts/rag_chat.py +194 -191
- package/scripts/semantic_search.py +435 -431
- package/scripts/sync_fav.py +201 -146
- package/scripts/sync_weread.py +192 -192
- package/scripts/vault_rag.py +140 -139
- package/scripts/vault_search.py +141 -141
- package/scripts/wechat_emoji.py +132 -0
- package/scripts/wechat_emoticon.py +433 -0
- package/scripts/wechat_image.py +258 -0
- package/scripts/wechat_voice.py +327 -0
- package/src/core/dbPathService.ts +163 -18
- package/src/core/keyService.ts +137 -25
- package/src/core/ntCore.ts +215 -62
- package/src/core/sqlcipherCore.ts +17 -1
- package/src/core/wcdbCore.ts +3 -7
- package/src/services/assistantDaemon.ts +111 -0
- package/src/services/assistantMemory.ts +193 -0
- package/src/services/assistantPrivacy.ts +87 -0
- package/src/services/assistantRouting.ts +92 -0
- package/src/services/assistantService.ts +295 -0
- package/src/services/assistantTools.ts +549 -0
- package/src/services/chatService.ts +133 -4
- package/src/services/configService.ts +194 -6
- package/src/services/evidenceService.ts +129 -0
- package/src/services/exportService.ts +113 -48
- package/src/services/initKeyService.ts +83 -0
- package/src/services/messageContract.ts +77 -0
- package/src/services/messageQuery.ts +38 -0
- package/src/services/wechat-formatter.ts +348 -348
- package/src/services/wechatMessageService.ts +25 -3
- package/src/services/wereadService.ts +308 -308
- package/src/services/whitelistService.ts +209 -22
- package/src/types.ts +20 -0
- package/src/utils/dateRange.ts +58 -0
- package/src/utils/mcpSecurity.ts +39 -0
- package/src/utils/packageRoot.ts +14 -0
- package/src/utils/python.ts +73 -0
- package/src/utils/pythonProcessEnv.ts +45 -0
- package/src/utils/talkerUtils.ts +14 -2
- package/dist/src/utils/errors.d.ts +0 -25
- package/dist/src/utils/errors.d.ts.map +0 -1
- package/dist/src/utils/errors.js +0 -43
- package/dist/src/utils/errors.js.map +0 -1
- package/dist/src/utils/pythonRunner.d.ts +0 -27
- package/dist/src/utils/pythonRunner.d.ts.map +0 -1
- package/dist/src/utils/pythonRunner.js +0 -62
- package/dist/src/utils/pythonRunner.js.map +0 -1
- package/src/utils/errors.ts +0 -42
- package/src/utils/pythonRunner.ts +0 -81
package/scripts/extract_todos.py
CHANGED
|
@@ -1,404 +1,445 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""
|
|
3
|
-
微信对话待办提取 & 任务追踪 — AI 识别承诺 + JSON 持久化。
|
|
4
|
-
|
|
5
|
-
用法:
|
|
6
|
-
python scripts/extract_todos.py extract [--days 7]
|
|
7
|
-
python scripts/extract_todos.py list [--status pending|done] [--urgency high|mid|low]
|
|
8
|
-
python scripts/extract_todos.py done <id>
|
|
9
|
-
python scripts/extract_todos.py undone <id>
|
|
10
|
-
python scripts/extract_todos.py rm <id>
|
|
11
|
-
python scripts/extract_todos.py remind
|
|
12
|
-
|
|
13
|
-
数据: ~/.weflow-cli/todos.json
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
import sys, os, json, hashlib, argparse
|
|
17
|
-
from datetime import datetime, timezone, timedelta
|
|
18
|
-
from pathlib import Path
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
c
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
'
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
sender_raw =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
'
|
|
135
|
-
'
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
conn
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
response =
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if
|
|
220
|
-
continue
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
'
|
|
225
|
-
'
|
|
226
|
-
'
|
|
227
|
-
'
|
|
228
|
-
'
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if
|
|
242
|
-
todos = [t for t in todos if t['
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
todos
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
#
|
|
303
|
-
p = subparsers.add_parser('
|
|
304
|
-
p.add_argument('--
|
|
305
|
-
p.add_argument('--
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
p =
|
|
310
|
-
p.add_argument('
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
p.
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
print(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
print(f
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
微信对话待办提取 & 任务追踪 — AI 识别承诺 + JSON 持久化。
|
|
4
|
+
|
|
5
|
+
用法:
|
|
6
|
+
python scripts/extract_todos.py extract [--days 7]
|
|
7
|
+
python scripts/extract_todos.py list [--status pending|done] [--urgency high|mid|low]
|
|
8
|
+
python scripts/extract_todos.py done <id>
|
|
9
|
+
python scripts/extract_todos.py undone <id>
|
|
10
|
+
python scripts/extract_todos.py rm <id>
|
|
11
|
+
python scripts/extract_todos.py remind
|
|
12
|
+
|
|
13
|
+
数据: ~/.weflow-cli/todos.json
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import sys, os, json, hashlib, argparse
|
|
17
|
+
from datetime import datetime, timezone, timedelta
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
21
|
+
from _utils import load_config, decrypt_lock, call_deepseek
|
|
22
|
+
|
|
23
|
+
TODOS_FILE = os.path.join(os.path.expanduser('~'), '.weflow-cli', 'todos.json')
|
|
24
|
+
TZ = timezone(timedelta(hours=8))
|
|
25
|
+
|
|
26
|
+
TODO_EXTRACT_PROMPT = """你是一个任务提取助手。分析微信聊天记录,提取其中出现的承诺、待办、约定事项。
|
|
27
|
+
|
|
28
|
+
要求:
|
|
29
|
+
1. 提取任何人的承诺或待办(如"我明天做""我处理""尽快发"等)
|
|
30
|
+
2. 每项返回 JSON: {{"task": "事项描述", "urgency": "高/中/低", "deadline": "截止描述或未提及"}}
|
|
31
|
+
3. 不要提取闲聊、问候等非任务内容
|
|
32
|
+
4. 如果没有待办,返回空数组 []
|
|
33
|
+
|
|
34
|
+
聊天记录:
|
|
35
|
+
{messages}
|
|
36
|
+
|
|
37
|
+
请只返回 JSON 数组,不要其他内容。"""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# ====== Database ======
|
|
41
|
+
|
|
42
|
+
def open_db(db_path, key_hex, salt_hex):
|
|
43
|
+
try:
|
|
44
|
+
from sqlcipher3 import dbapi2 as sqlcipher
|
|
45
|
+
except ImportError as exc:
|
|
46
|
+
raise RuntimeError('请安装: pip install sqlcipher3') from exc
|
|
47
|
+
raw_key = f"x'{key_hex}{salt_hex}'"
|
|
48
|
+
conn = sqlcipher.connect(db_path)
|
|
49
|
+
c = conn.cursor()
|
|
50
|
+
c.execute(f'PRAGMA key = "{raw_key}";')
|
|
51
|
+
c.execute("SELECT count(*) FROM sqlite_master")
|
|
52
|
+
return conn
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_name_map(contact_db, contact_key, contact_salt):
|
|
56
|
+
name_map = {}
|
|
57
|
+
if not contact_db or not contact_key or not os.path.exists(contact_db):
|
|
58
|
+
return name_map
|
|
59
|
+
try:
|
|
60
|
+
conn = open_db(contact_db, contact_key, contact_salt)
|
|
61
|
+
c = conn.cursor()
|
|
62
|
+
c.execute("SELECT username, COALESCE(NULLIF(remark,''), NULLIF(nick_name,''), username) FROM contact")
|
|
63
|
+
for r in c.fetchall():
|
|
64
|
+
name_map[r[0]] = r[1]
|
|
65
|
+
conn.close()
|
|
66
|
+
except:
|
|
67
|
+
pass
|
|
68
|
+
return name_map
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def collect_recent_messages(conn, start_ts, end_ts, name_map, limit_per_session=50):
|
|
72
|
+
"""收集近期待办相关消息:扫描所有会话,过滤含承诺/任务关键词的消息。"""
|
|
73
|
+
c = conn.cursor()
|
|
74
|
+
try:
|
|
75
|
+
c.execute("SELECT user_name FROM Name2Id WHERE is_session = 1")
|
|
76
|
+
sessions = [r[0] for r in c.fetchall()]
|
|
77
|
+
except:
|
|
78
|
+
c.execute("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'Msg_%'")
|
|
79
|
+
sessions = [r[0].replace('Msg_', '') for r in c.fetchall()]
|
|
80
|
+
|
|
81
|
+
# 关键词预筛选:承诺、任务、约定类词汇
|
|
82
|
+
keywords = ['明天', '下次', '等会', '一会', '尽快', '稍后', '待会', '改天',
|
|
83
|
+
'我弄', '我做', '我来', '我写', '我发', '我处理', '我整', '我搞',
|
|
84
|
+
'我看看', '我去', '我找', '我帮忙', '我帮', '好的我', '行我',
|
|
85
|
+
'没问题', 'ok', 'OK', '可以我', '收到我']
|
|
86
|
+
|
|
87
|
+
all_msgs = []
|
|
88
|
+
seen = set()
|
|
89
|
+
|
|
90
|
+
for talker in sessions[:80]:
|
|
91
|
+
tbl = f"Msg_{hashlib.md5(talker.encode()).hexdigest()}"
|
|
92
|
+
try:
|
|
93
|
+
c.execute(f'SELECT COUNT(*) FROM sqlite_master WHERE name="{tbl}"')
|
|
94
|
+
if c.fetchone()[0] == 0:
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
c.execute(f'''
|
|
98
|
+
SELECT create_time, real_sender_id, message_content
|
|
99
|
+
FROM "{tbl}"
|
|
100
|
+
WHERE create_time >= ? AND create_time < ?
|
|
101
|
+
AND message_content IS NOT NULL
|
|
102
|
+
ORDER BY create_time DESC
|
|
103
|
+
LIMIT ?
|
|
104
|
+
''', (start_ts, end_ts, limit_per_session))
|
|
105
|
+
|
|
106
|
+
for ts, sender_id, content in c.fetchall():
|
|
107
|
+
if not content or not isinstance(content, str) or len(content) < 5:
|
|
108
|
+
continue
|
|
109
|
+
# 关键词过滤
|
|
110
|
+
content_lower = content.lower()
|
|
111
|
+
if not any(kw.lower() in content_lower for kw in keywords):
|
|
112
|
+
continue
|
|
113
|
+
# 去重
|
|
114
|
+
msg_hash = hashlib.md5(f"{talker}:{ts}:{content[:50]}".encode()).hexdigest()
|
|
115
|
+
if msg_hash in seen:
|
|
116
|
+
continue
|
|
117
|
+
seen.add(msg_hash)
|
|
118
|
+
|
|
119
|
+
# 获取发送者名称
|
|
120
|
+
try:
|
|
121
|
+
c2 = conn.cursor()
|
|
122
|
+
c2.execute("SELECT user_name FROM Name2Id WHERE rowid = ?", (sender_id,))
|
|
123
|
+
row = c2.fetchone()
|
|
124
|
+
sender_raw = row[0] if row else str(sender_id)
|
|
125
|
+
except:
|
|
126
|
+
sender_raw = str(sender_id)
|
|
127
|
+
sender_name = name_map.get(sender_raw, sender_raw)
|
|
128
|
+
talker_name = name_map.get(talker, talker)
|
|
129
|
+
|
|
130
|
+
dt = datetime.fromtimestamp(ts, tz=TZ)
|
|
131
|
+
all_msgs.append({
|
|
132
|
+
'time': dt.strftime('%m-%d %H:%M'),
|
|
133
|
+
'talker': talker_name,
|
|
134
|
+
'sender': sender_name,
|
|
135
|
+
'content': content[:300],
|
|
136
|
+
})
|
|
137
|
+
except:
|
|
138
|
+
pass
|
|
139
|
+
|
|
140
|
+
all_msgs.sort(key=lambda x: x['time'])
|
|
141
|
+
return all_msgs
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# ====== Todo CRUD ======
|
|
145
|
+
|
|
146
|
+
def load_todos() -> list[dict]:
|
|
147
|
+
if os.path.exists(TODOS_FILE):
|
|
148
|
+
try:
|
|
149
|
+
return json.loads(open(TODOS_FILE, encoding='utf-8').read())
|
|
150
|
+
except:
|
|
151
|
+
return []
|
|
152
|
+
return []
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def save_todos(todos: list[dict]):
|
|
156
|
+
os.makedirs(os.path.dirname(TODOS_FILE), exist_ok=True)
|
|
157
|
+
with open(TODOS_FILE, 'w', encoding='utf-8') as f:
|
|
158
|
+
json.dump(todos, f, ensure_ascii=False, indent=2)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def extract_todos(api_key: str, days: int = 7):
|
|
162
|
+
"""扫描最近的聊天记录,AI 提取待办。"""
|
|
163
|
+
config = load_config()
|
|
164
|
+
nt_db = config.get('ntDbPath', '')
|
|
165
|
+
if not nt_db:
|
|
166
|
+
return {"error": "未初始化,请先运行 weflow-cli init"}
|
|
167
|
+
|
|
168
|
+
nt_key = decrypt_lock(config.get('ntKey', ''))
|
|
169
|
+
nt_salt = config.get('ntSalt', '')
|
|
170
|
+
contact_key = decrypt_lock(config.get('contactKey', ''))
|
|
171
|
+
contact_salt = config.get('contactSalt', '')
|
|
172
|
+
msg_dir = os.path.dirname(nt_db.replace('\\', '/'))
|
|
173
|
+
wxid_dir = os.path.dirname(os.path.dirname(msg_dir))
|
|
174
|
+
contact_db = os.path.join(wxid_dir, 'db_storage', 'contact', 'contact.db')
|
|
175
|
+
|
|
176
|
+
name_map = get_name_map(contact_db, contact_key, contact_salt)
|
|
177
|
+
now = datetime.now(TZ)
|
|
178
|
+
start_ts = int((now - timedelta(days=days)).timestamp())
|
|
179
|
+
end_ts = int(now.timestamp())
|
|
180
|
+
|
|
181
|
+
conn = open_db(nt_db, nt_key, nt_salt)
|
|
182
|
+
messages = collect_recent_messages(conn, start_ts, end_ts, name_map)
|
|
183
|
+
conn.close()
|
|
184
|
+
|
|
185
|
+
if not messages:
|
|
186
|
+
return {"new": 0, "total": len(load_todos()), "message": "近 {days} 天没有发现相关消息"}
|
|
187
|
+
|
|
188
|
+
# 构建 prompt
|
|
189
|
+
msg_text = '\n'.join(
|
|
190
|
+
f"[{m['time']}] {m['talker']} - {m['sender']}: {m['content']}"
|
|
191
|
+
for m in messages[-150:] # 最多 150 条
|
|
192
|
+
)
|
|
193
|
+
prompt = TODO_EXTRACT_PROMPT.format(messages=msg_text)
|
|
194
|
+
|
|
195
|
+
# AI 提取
|
|
196
|
+
try:
|
|
197
|
+
response = call_deepseek(prompt, api_key, max_tokens=2000, timeout=90)
|
|
198
|
+
# 清理可能的 markdown 代码块
|
|
199
|
+
response = response.strip()
|
|
200
|
+
if response.startswith('```'):
|
|
201
|
+
response = response.split('\n', 1)[1]
|
|
202
|
+
if response.endswith('```'):
|
|
203
|
+
response = response[:-3]
|
|
204
|
+
todos_raw = json.loads(response)
|
|
205
|
+
except Exception as e:
|
|
206
|
+
return {"error": f"AI 提取失败: {e}"}
|
|
207
|
+
|
|
208
|
+
if not isinstance(todos_raw, list):
|
|
209
|
+
return {"error": "AI 返回格式错误"}
|
|
210
|
+
|
|
211
|
+
# 合并到现有待办(去重:相同 task 文本)
|
|
212
|
+
existing = load_todos()
|
|
213
|
+
existing_tasks = {t['task'] for t in existing}
|
|
214
|
+
new_count = 0
|
|
215
|
+
|
|
216
|
+
for item in todos_raw:
|
|
217
|
+
if not isinstance(item, dict) or not item.get('task'):
|
|
218
|
+
continue
|
|
219
|
+
if item['task'] in existing_tasks:
|
|
220
|
+
continue
|
|
221
|
+
todo = {
|
|
222
|
+
'id': f"todo_{now.strftime('%Y%m%d_%H%M%S')}_{new_count + 1}",
|
|
223
|
+
'task': item['task'],
|
|
224
|
+
'urgency': item.get('urgency', '中'),
|
|
225
|
+
'deadline': item.get('deadline', '未提及'),
|
|
226
|
+
'status': 'pending',
|
|
227
|
+
'created_at': now.strftime('%Y-%m-%d %H:%M'),
|
|
228
|
+
'context': '',
|
|
229
|
+
}
|
|
230
|
+
existing.append(todo)
|
|
231
|
+
new_count += 1
|
|
232
|
+
|
|
233
|
+
save_todos(existing)
|
|
234
|
+
return {"new": new_count, "total": len(existing)}
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def list_todos(status: str = None, urgency: str = None):
|
|
238
|
+
todos = load_todos()
|
|
239
|
+
if status:
|
|
240
|
+
todos = [t for t in todos if t['status'] == status]
|
|
241
|
+
if urgency:
|
|
242
|
+
todos = [t for t in todos if t['urgency'] == urgency]
|
|
243
|
+
|
|
244
|
+
# 排序:pending 在前,高紧急度在前
|
|
245
|
+
order = {'pending': 0, 'done': 1}
|
|
246
|
+
urg_order = {'高': 0, '中': 1, '低': 2}
|
|
247
|
+
todos.sort(key=lambda t: (order.get(t['status'], 2), urg_order.get(t['urgency'], 3)))
|
|
248
|
+
|
|
249
|
+
return todos
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def find_todo(todo_id: str):
|
|
253
|
+
for todo in load_todos():
|
|
254
|
+
if todo['id'] == todo_id or todo['id'].startswith(todo_id):
|
|
255
|
+
return todo
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def toggle_todo(todo_id: str, status: str):
|
|
260
|
+
todos = load_todos()
|
|
261
|
+
for t in todos:
|
|
262
|
+
if t['id'] == todo_id or t['id'].startswith(todo_id):
|
|
263
|
+
t['status'] = status
|
|
264
|
+
save_todos(todos)
|
|
265
|
+
return t
|
|
266
|
+
return None
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def delete_todo(todo_id: str):
|
|
270
|
+
todos = load_todos()
|
|
271
|
+
for i, t in enumerate(todos):
|
|
272
|
+
if t['id'] == todo_id or t['id'].startswith(todo_id):
|
|
273
|
+
deleted = todos.pop(i)
|
|
274
|
+
save_todos(todos)
|
|
275
|
+
return deleted
|
|
276
|
+
return None
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def remind():
|
|
280
|
+
"""显示需要关注的待办。"""
|
|
281
|
+
todos = load_todos()
|
|
282
|
+
pending = [t for t in todos if t['status'] == 'pending']
|
|
283
|
+
high = [t for t in pending if t['urgency'] == '高']
|
|
284
|
+
mid = [t for t in pending if t['urgency'] == '中']
|
|
285
|
+
low = [t for t in pending if t['urgency'] == '低']
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
'total_pending': len(pending),
|
|
289
|
+
'high': high,
|
|
290
|
+
'mid': mid,
|
|
291
|
+
'low': low,
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# ====== Main ======
|
|
296
|
+
|
|
297
|
+
def main():
|
|
298
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
299
|
+
parser = argparse.ArgumentParser(description='待办提取与任务追踪')
|
|
300
|
+
subparsers = parser.add_subparsers(dest='command')
|
|
301
|
+
|
|
302
|
+
# extract
|
|
303
|
+
p = subparsers.add_parser('extract', help='从聊天记录中 AI 提取待办')
|
|
304
|
+
p.add_argument('--days', type=int, default=7, help='扫描最近多少天(默认 7)')
|
|
305
|
+
p.add_argument('--api-key', help='DeepSeek API key(优先从 config 读取)')
|
|
306
|
+
|
|
307
|
+
# list
|
|
308
|
+
p = subparsers.add_parser('list', help='列出待办')
|
|
309
|
+
p.add_argument('--status', choices=['pending', 'done'], help='按状态筛选')
|
|
310
|
+
p.add_argument('--urgency', choices=['高', '中', '低'], help='按紧急度筛选')
|
|
311
|
+
p.add_argument('--json', action='store_true', help='JSON 输出')
|
|
312
|
+
|
|
313
|
+
# done
|
|
314
|
+
p = subparsers.add_parser('done', help='标记待办为已完成')
|
|
315
|
+
p.add_argument('id', help='待办 ID(或前缀)')
|
|
316
|
+
p.add_argument('--json', action='store_true', help='JSON 输出')
|
|
317
|
+
|
|
318
|
+
# undone
|
|
319
|
+
p = subparsers.add_parser('undone', help='取消已完成标记')
|
|
320
|
+
p.add_argument('id', help='待办 ID(或前缀)')
|
|
321
|
+
p.add_argument('--json', action='store_true', help='JSON 输出')
|
|
322
|
+
|
|
323
|
+
# rm
|
|
324
|
+
p = subparsers.add_parser('rm', help='删除待办')
|
|
325
|
+
p.add_argument('id', help='待办 ID(或前缀)')
|
|
326
|
+
p.add_argument('--json', action='store_true', help='JSON 输出')
|
|
327
|
+
|
|
328
|
+
p = subparsers.add_parser('preview', help='预览待办写操作,不修改数据')
|
|
329
|
+
p.add_argument('id', help='待办 ID(或前缀)')
|
|
330
|
+
p.add_argument('--action', required=True, choices=['done', 'undone', 'remove'])
|
|
331
|
+
|
|
332
|
+
# remind
|
|
333
|
+
p = subparsers.add_parser('remind', help='查看待办提醒')
|
|
334
|
+
p.add_argument('--json', action='store_true', help='JSON 输出')
|
|
335
|
+
|
|
336
|
+
args = parser.parse_args()
|
|
337
|
+
|
|
338
|
+
if not args.command:
|
|
339
|
+
parser.print_help()
|
|
340
|
+
sys.exit(1)
|
|
341
|
+
|
|
342
|
+
if args.command == 'extract':
|
|
343
|
+
config = load_config()
|
|
344
|
+
api_key = getattr(args, 'api_key', None) or os.environ.get('DEEPSEEK_API_KEY', '') or config.get('deepseekApiKey', '')
|
|
345
|
+
if not api_key:
|
|
346
|
+
print('[ERROR] 缺少 DeepSeek API key')
|
|
347
|
+
sys.exit(1)
|
|
348
|
+
print(f'扫描最近 {args.days} 天的聊天记录...')
|
|
349
|
+
result = extract_todos(api_key, days=args.days)
|
|
350
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
351
|
+
|
|
352
|
+
elif args.command == 'list':
|
|
353
|
+
result = list_todos(args.status, args.urgency)
|
|
354
|
+
if getattr(args, 'json', False):
|
|
355
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
356
|
+
elif not result:
|
|
357
|
+
print('✅ 暂无待办')
|
|
358
|
+
else:
|
|
359
|
+
status_labels = {'pending': '⬜', 'done': '✅'}
|
|
360
|
+
urg_labels = {'高': '🔴', '中': '🟡', '低': '🟢'}
|
|
361
|
+
for t in result:
|
|
362
|
+
s = status_labels.get(t['status'], '❓')
|
|
363
|
+
u = urg_labels.get(t['urgency'], '⚪')
|
|
364
|
+
print(f" {s} {u} [{t['id']}] {t['task']}")
|
|
365
|
+
if t.get('deadline') and t['deadline'] != '未提及':
|
|
366
|
+
print(f" ⏰ {t['deadline']}")
|
|
367
|
+
print(f"\n共 {len(result)} 项")
|
|
368
|
+
|
|
369
|
+
elif args.command == 'done':
|
|
370
|
+
t = toggle_todo(args.id, 'done')
|
|
371
|
+
if args.json:
|
|
372
|
+
print(json.dumps({'success': bool(t), 'action': 'done', 'todo': t}, ensure_ascii=False, indent=2))
|
|
373
|
+
if not t:
|
|
374
|
+
sys.exit(1)
|
|
375
|
+
return
|
|
376
|
+
if t:
|
|
377
|
+
print(f'✅ 已标记完成: {t["task"]}')
|
|
378
|
+
else:
|
|
379
|
+
print(f'未找到待办: {args.id}')
|
|
380
|
+
|
|
381
|
+
elif args.command == 'undone':
|
|
382
|
+
t = toggle_todo(args.id, 'pending')
|
|
383
|
+
if args.json:
|
|
384
|
+
print(json.dumps({'success': bool(t), 'action': 'undone', 'todo': t}, ensure_ascii=False, indent=2))
|
|
385
|
+
if not t:
|
|
386
|
+
sys.exit(1)
|
|
387
|
+
return
|
|
388
|
+
if t:
|
|
389
|
+
print(f'🔄 已恢复: {t["task"]}')
|
|
390
|
+
else:
|
|
391
|
+
print(f'未找到待办: {args.id}')
|
|
392
|
+
|
|
393
|
+
elif args.command == 'rm':
|
|
394
|
+
t = delete_todo(args.id)
|
|
395
|
+
if args.json:
|
|
396
|
+
print(json.dumps({'success': bool(t), 'action': 'remove', 'todo': t}, ensure_ascii=False, indent=2))
|
|
397
|
+
if not t:
|
|
398
|
+
sys.exit(1)
|
|
399
|
+
return
|
|
400
|
+
if t:
|
|
401
|
+
print(f'🗑️ 已删除: {t["task"]}')
|
|
402
|
+
else:
|
|
403
|
+
print(f'未找到待办: {args.id}')
|
|
404
|
+
|
|
405
|
+
elif args.command == 'preview':
|
|
406
|
+
todo = find_todo(args.id)
|
|
407
|
+
print(json.dumps({
|
|
408
|
+
'success': bool(todo),
|
|
409
|
+
'dryRun': True,
|
|
410
|
+
'action': args.action,
|
|
411
|
+
'todo': todo,
|
|
412
|
+
}, ensure_ascii=False, indent=2))
|
|
413
|
+
if not todo:
|
|
414
|
+
sys.exit(1)
|
|
415
|
+
|
|
416
|
+
elif args.command == 'remind':
|
|
417
|
+
result = remind()
|
|
418
|
+
if args.json:
|
|
419
|
+
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
420
|
+
return
|
|
421
|
+
print(f'\n📋 待办提醒 — {datetime.now(TZ).strftime("%Y-%m-%d %H:%M")}')
|
|
422
|
+
print(f' 共 {result["total_pending"]} 项未完成\n')
|
|
423
|
+
if result['high']:
|
|
424
|
+
print('🔴 高紧急度:')
|
|
425
|
+
for t in result['high']:
|
|
426
|
+
print(f' - {t["task"]}')
|
|
427
|
+
if t['deadline'] != '未提及':
|
|
428
|
+
print(f' ⏰ {t["deadline"]}')
|
|
429
|
+
print()
|
|
430
|
+
if result['mid']:
|
|
431
|
+
print('🟡 中紧急度:')
|
|
432
|
+
for t in result['mid']:
|
|
433
|
+
print(f' - {t["task"]}')
|
|
434
|
+
print()
|
|
435
|
+
if result['low']:
|
|
436
|
+
print('🟢 低紧急度:')
|
|
437
|
+
for t in result['low']:
|
|
438
|
+
print(f' - {t["task"]}')
|
|
439
|
+
print()
|
|
440
|
+
if result['total_pending'] == 0:
|
|
441
|
+
print('✅ 暂无待办,干得好!')
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
if __name__ == '__main__':
|
|
445
|
+
main()
|