fix: improve local file matching for WeChat draft sync
- learn_edits.py: prioritize output_file field from history.yaml, fall back to title slug matching, then largest file - SKILL.md: add output_file field to history.yaml schema - Fixes wrong file match when multiple articles share the same date Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2773a8bb9b
commit
73a67fffc7
2 changed files with 25 additions and 3 deletions
1
SKILL.md
1
SKILL.md
|
|
@ -429,6 +429,7 @@ python3 {skill_dir}/toolkit/cli.py preview {markdown} --theme {theme} --no-open
|
|||
title: "{标题}"
|
||||
topic_source: "热点抓取" # 或 "用户指定"
|
||||
topic_keywords: ["{词1}", "{词2}"]
|
||||
output_file: "{output 文件路径}" # e.g. output/2026-03-31-zhangxue-slow-accumulation.md
|
||||
framework: "{框架}"
|
||||
enhance_strategy: "{增强策略}" # angle_discovery/density_boost/detail_anchoring/real_feel
|
||||
word_count: {字数}
|
||||
|
|
|
|||
|
|
@ -111,13 +111,34 @@ def fetch_wechat_draft() -> tuple[str, str, str]:
|
|||
title = latest.get("title", "")
|
||||
|
||||
# Find the local draft file
|
||||
# Priority: output_file field → title slug match → largest file
|
||||
date = latest.get("date", "")
|
||||
output_dir = SKILL_DIR / "output"
|
||||
draft_path = None
|
||||
if date:
|
||||
candidates = list(output_dir.glob(f"{date}-*.md"))
|
||||
if candidates:
|
||||
|
||||
# First try: exact path from history
|
||||
output_file = latest.get("output_file", "")
|
||||
if output_file:
|
||||
candidate = SKILL_DIR / output_file if not Path(output_file).is_absolute() else Path(output_file)
|
||||
if candidate.exists():
|
||||
draft_path = candidate
|
||||
|
||||
if not draft_path and date:
|
||||
candidates = sorted(output_dir.glob(f"{date}-*.md"))
|
||||
if len(candidates) == 1:
|
||||
draft_path = candidates[0]
|
||||
elif len(candidates) > 1:
|
||||
# Multiple files on same date — try to match by title keywords
|
||||
title_lower = title.lower()
|
||||
for c in candidates:
|
||||
slug = c.stem.replace(date + "-", "").replace("-", " ")
|
||||
# Check if slug words appear in title
|
||||
if any(w in title_lower for w in slug.split() if len(w) > 1):
|
||||
draft_path = c
|
||||
break
|
||||
if not draft_path:
|
||||
# Fallback: use the largest file (likely the final version)
|
||||
draft_path = max(candidates, key=lambda p: p.stat().st_size)
|
||||
|
||||
if not draft_path or not draft_path.exists():
|
||||
raise FileNotFoundError(
|
||||
|
|
|
|||
Loading…
Reference in a new issue