(
*,
user_id: str,
paper: Dict[str, Any],
report_payload: Dict[str, Any],
report_path: Path,
report_content: str,
)
| 2104 | |
| 2105 | |
| 2106 | def _sync_obsidian_daily_note( |
| 2107 | *, |
| 2108 | user_id: str, |
| 2109 | paper: Dict[str, Any], |
| 2110 | report_payload: Dict[str, Any], |
| 2111 | report_path: Path, |
| 2112 | report_content: str, |
| 2113 | ) -> Optional[str]: |
| 2114 | daily_note = _obsidian_daily_note_path(report_path, paper) |
| 2115 | if daily_note is None: |
| 2116 | return None |
| 2117 | daily_note.parent.mkdir(parents=True, exist_ok=True) |
| 2118 | category = _daily_note_category(paper, report_payload) |
| 2119 | entry = _daily_note_entry( |
| 2120 | paper=paper, |
| 2121 | report_payload=report_payload, |
| 2122 | report_path=report_path, |
| 2123 | report_content=report_content, |
| 2124 | ) |
| 2125 | marker = entry.splitlines()[0] |
| 2126 | current = daily_note.read_text(encoding="utf-8") if daily_note.exists() else "" |
| 2127 | if marker in current: |
| 2128 | current = _remove_daily_note_entry(current, marker) or current |
| 2129 | current = _prune_empty_daily_note_sections(current) |
| 2130 | section_heading = f"# {category}" |
| 2131 | if section_heading not in current: |
| 2132 | current = current.rstrip() + ("\n\n" if current.strip() else "") + section_heading + "\n" |
| 2133 | insert_at = current.find(section_heading) + len(section_heading) |
| 2134 | next_section = current.find("\n# ", insert_at) |
| 2135 | if next_section == -1: |
| 2136 | updated = current.rstrip() + "\n\n" + entry |
| 2137 | else: |
| 2138 | updated = current[:next_section].rstrip() + "\n\n" + entry + "\n" + current[next_section:].lstrip("\n") |
| 2139 | user_profile = _daily_note_user_profile(user_id) |
| 2140 | updated = _refresh_daily_note_topic_summaries(updated, user_profile=user_profile) |
| 2141 | updated = _llm_review_daily_note_categories(updated, user_profile=user_profile) |
| 2142 | updated = _refresh_daily_note_topic_summaries(updated, user_profile=user_profile) |
| 2143 | daily_note.write_text(updated.rstrip() + "\n", encoding="utf-8") |
| 2144 | _sync_obsidian_toc(daily_note) |
| 2145 | return str(daily_note) |
| 2146 | |
| 2147 | |
| 2148 | def _markdown_section_excerpt(content: str, *headings: str, max_chars: int = 900) -> str: |
no test coverage detected