feat: 历史同步优化与消息已读属性

- 历史同步: 本地缓存优先、断点续传、按月批量同步
- 新增 sync_monthly.py: 支持逐月往前推进同步
- 消息表新增 is_read 字段,默认 false
- Obsidian 文档 frontmatter 自动补充 is_read: false
- 新增 migrate_add_is_read.py / migrate_obsidian_is_read.py 迁移脚本
- 总结 prompt 补充: 不记录腾讯会议号
- 历史同步失败时记录日志到 ~/.larkx/logs/history-failures.jsonl
This commit is contained in:
Benature
2026-11-08 11:31:18 +08:00
parent 99ee792c07
commit c8658ad064
10 changed files with 420 additions and 9 deletions

View File

@ -17,6 +17,25 @@ def _print_json(value):
print(json.dumps(value, ensure_ascii=False, indent=2, default=str))
def _report_history_failures(target_day, stats):
if not stats.get("failed"):
return
from snooper_history import format_history_failures, write_history_failures
failures = stats.get("failures", [])
details = format_history_failures(failures) or "无会话明细"
try:
log_path = write_history_failures(target_day, failures)
except OSError as error:
log_note = f"失败日志写入失败: {type(error).__name__}"
else:
log_note = f"失败日志: {log_path}"
print(
f"历史同步失败明细[{target_day.isoformat()}]: {details};{log_note}",
file=sys.stderr,
)
def cmd_web(args):
from snooper_web import WebError, run_web
@ -83,6 +102,7 @@ def cmd_history(args):
exclude_chat_ids=exclude_chat_ids,
force=args.force,
)
_report_history_failures(target_day, stats)
for key in total:
total[key] += stats[key]
print(
@ -112,6 +132,7 @@ def cmd_history(args):
except (HistoryError, SummaryError) as error:
print(f"历史消息入库失败: {error}", file=sys.stderr)
return 1
_report_history_failures(target_day, stats)
print(
f"历史消息入库完成: {target_day.isoformat()},会话 {stats['chats']} 个,"
f"跳过 {stats['skipped']} 个,日期内消息 {stats['matched']} 条,"
@ -236,6 +257,7 @@ def cmd_summarize(args):
f"飞书历史数据同步失败({type(error).__name__});"
"可使用 --no-fetch 明确只读本地库。"
) from error
_report_history_failures(target_day, fetch_stats)
if fetch_stats["failed"]:
raise SummaryError(
f"有 {fetch_stats['failed']} 个会话同步失败,已停止后续总结;"
@ -291,7 +313,7 @@ def cmd_summarize(args):
or default_summary_path(target_day)
)
content = add_obsidian_properties(
content, {"model": model.rsplit("/", 1)[-1]}
content, {"model": model.rsplit("/", 1)[-1], "is_read": False}
)
output = write_summary(output_path, content)
dry_run_path = configured_output_path(