MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / sync_reading_notes_github

Function sync_reading_notes_github

deployments/desktop/shared/agents.py:1587–1700  ·  view source on GitHub ↗
(user_id: str = "", response_language: str = "zh")

Source from the content-addressed store, hash-verified

1585 applied = _run_git(["apply", "--3way", "--whitespace=nowarn", "-"], repo_dir, check=False, timeout=120, input=local_patch)
1586 if applied.returncode == 0:
1587 return True, False, (applied.stdout or applied.stderr or "").strip()
1588
1589 _run_git(["reset", "--hard", f"origin/{branch}"], repo_dir, timeout=120)
1590 _run_git(["clean", "-fd"], repo_dir)
1591 warning = (
1592 "Remote version was kept because local note changes conflicted with remote updates."
1593 if language == "en"
1594 else "本地笔记改动与远端更新冲突,已按远端版本保留并丢弃本地冲突改动。"
1595 )
1596 detail = (applied.stderr or applied.stdout or "").strip()
1597 return True, True, f"{warning} {detail}".strip()
1598
1599
1600def _notes_llm_sync_review(
1601 repo_dir: Path,
1602 branch: str,
1603 enabled: bool,
1604 response_language: str = "zh",
1605) -> Dict[str, Any]:
1606 language = _normalize_response_language(response_language)
1607 if not enabled:
1608 return {
1609 "enabled": False,
1610 "reviewed": False,
1611 "summary": "LLM review is disabled." if language == "en" else "LLM 校对已关闭。",
1612 }
1613 try:
1614 provider = build_llm_provider()
1615 if getattr(provider, "name", "") == "mock":
1616 return {
1617 "enabled": True,
1618 "reviewed": False,
1619 "summary": (
1620 "The current LLM provider is mock; semantic review was skipped."
1621 if language == "en"
1622 else "当前 LLM provider 为 mock,跳过语义校对。"
1623 ),
1624 }
1625 status = _git_output(["status", "--short"], repo_dir)
1626 staged_stat = _git_output(["diff", "--cached", "--stat"], repo_dir)
1627 try:
1628 remote_stat = _git_output(["diff", "--stat", f"HEAD..origin/{branch}"], repo_dir)
1629 except Exception:
1630 remote_stat = ""
1631 staged_diff = _git_output(["diff", "--cached", "--", "*.md"], repo_dir)
1632 if len(staged_diff) > 12000:
1633 staged_diff = staged_diff[:12000] + "\n\n[diff truncated]"
1634 output_rule = (
1635 "Return concise English JSON with keys: risk_level, summary, suggested_action."
1636 if language == "en"
1637 else "Return concise Chinese JSON with keys: risk_level, summary, suggested_action."
1638 )
1639 prompt = "\n".join(
1640 [
1641 "Review this PaperFlow reading-notes Git sync before commit.",
1642 "Check whether local Daily Note and Deep Reading markdown changes look like additive preservation rather than accidental deletion.",
1643 output_rule,
1644 "",

Callers

nothing calls this directly

Calls 15

_notes_git_remoteFunction · 0.85
_ensure_notes_git_repoFunction · 0.85
_ensure_notes_gitignoreFunction · 0.85
_run_gitFunction · 0.85
_notes_llm_sync_reviewFunction · 0.85
_git_outputFunction · 0.85
_git_ahead_behindFunction · 0.85

Tested by

no test coverage detected