(
repo_dir: Path,
branch: str,
enabled: bool,
response_language: str = "zh",
)
| 1504 | |
| 1505 | _run_git(["reset", "--hard", f"origin/{branch}"], repo_dir, timeout=120) |
| 1506 | _run_git(["clean", "-fd"], repo_dir) |
| 1507 | warning = ( |
| 1508 | "Remote version was kept because local note changes conflicted with remote updates." |
| 1509 | if language == "en" |
| 1510 | else "本地笔记改动与远端更新冲突,已按远端版本保留并丢弃本地冲突改动。" |
| 1511 | ) |
| 1512 | detail = (applied.stderr or applied.stdout or "").strip() |
| 1513 | return True, True, f"{warning} {detail}".strip() |
| 1514 | |
| 1515 | |
| 1516 | def _notes_llm_sync_review( |
| 1517 | repo_dir: Path, |
| 1518 | branch: str, |
| 1519 | enabled: bool, |
| 1520 | response_language: str = "zh", |
| 1521 | ) -> Dict[str, Any]: |
| 1522 | language = _normalize_response_language(response_language) |
| 1523 | if not enabled: |
| 1524 | return { |
| 1525 | "enabled": False, |
| 1526 | "reviewed": False, |
| 1527 | "summary": "LLM review is disabled." if language == "en" else "LLM 校对已关闭。", |
| 1528 | } |
| 1529 | try: |
| 1530 | provider = build_llm_provider() |
| 1531 | if getattr(provider, "name", "") == "mock": |
| 1532 | return { |
| 1533 | "enabled": True, |
| 1534 | "reviewed": False, |
| 1535 | "summary": ( |
| 1536 | "The current LLM provider is mock; semantic review was skipped." |
| 1537 | if language == "en" |
| 1538 | else "当前 LLM provider 为 mock,跳过语义校对。" |
| 1539 | ), |
| 1540 | } |
| 1541 | status = _git_output(["status", "--short"], repo_dir) |
| 1542 | staged_stat = _git_output(["diff", "--cached", "--stat"], repo_dir) |
| 1543 | try: |
| 1544 | remote_stat = _git_output(["diff", "--stat", f"HEAD..origin/{branch}"], repo_dir) |
| 1545 | except Exception: |
| 1546 | remote_stat = "" |
| 1547 | staged_diff = _git_output(["diff", "--cached", "--", "*.md"], repo_dir) |
| 1548 | if len(staged_diff) > 12000: |
| 1549 | staged_diff = staged_diff[:12000] + "\n\n[diff truncated]" |
| 1550 | output_rule = ( |
| 1551 | "Return concise English JSON with keys: risk_level, summary, suggested_action." |
| 1552 | if language == "en" |
| 1553 | else "Return concise Chinese JSON with keys: risk_level, summary, suggested_action." |
| 1554 | ) |
| 1555 | prompt = "\n".join( |
| 1556 | [ |
| 1557 | "Review this PaperFlow reading-notes Git sync before commit.", |
| 1558 | "Check whether local Daily Note and Deep Reading markdown changes look like additive preservation rather than accidental deletion.", |
| 1559 | output_rule, |
| 1560 | "", |
| 1561 | f"branch: {branch}", |
| 1562 | "git status:", |
| 1563 | status or "(clean)", |
no test coverage detected