mednotes-opencode 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.opencode/agents/med-chat-triager.md +204 -0
- package/.opencode/agents/med-flashcard-maker.md +63 -0
- package/.opencode/agents/med-knowledge-architect.md +230 -0
- package/.opencode/agents/med-link-graph-curator.md +177 -0
- package/.opencode/agents/med-publish-guard.md +62 -0
- package/.opencode/commands/flashcards.md +25 -0
- package/.opencode/commands/mednotes/create.md +25 -0
- package/.opencode/commands/mednotes/enrich.md +27 -0
- package/.opencode/commands/mednotes/fix-wiki.md +27 -0
- package/.opencode/commands/mednotes/history.md +22 -0
- package/.opencode/commands/mednotes/link-body.md +25 -0
- package/.opencode/commands/mednotes/link-related.md +27 -0
- package/.opencode/commands/mednotes/link.md +27 -0
- package/.opencode/commands/mednotes/pdf-library.md +27 -0
- package/.opencode/commands/mednotes/process-chats.md +23 -0
- package/.opencode/commands/mednotes/setup.md +21 -0
- package/.opencode/commands/mednotes/status.md +27 -0
- package/.opencode/commands/mednotes/telemetry.md +27 -0
- package/.opencode/commands/report.md +26 -0
- package/.opencode/mednotes/AGENTS.md +57 -0
- package/.opencode/mednotes/agents/med-chat-triager.md +197 -0
- package/.opencode/mednotes/agents/med-flashcard-maker.md +56 -0
- package/.opencode/mednotes/agents/med-knowledge-architect.md +224 -0
- package/.opencode/mednotes/agents/med-link-graph-curator.md +171 -0
- package/.opencode/mednotes/agents/med-publish-guard.md +55 -0
- package/.opencode/mednotes/contracts/.gitkeep +1 -0
- package/.opencode/mednotes/contracts/agents.json +116 -0
- package/.opencode/mednotes/contracts/opencode-plugin.json +70 -0
- package/.opencode/mednotes/docs/agent-prompt-hardening.md +567 -0
- package/.opencode/mednotes/docs/agent-role-contracts.md +94 -0
- package/.opencode/mednotes/docs/anki-mcp-twenty-rules.md +214 -0
- package/.opencode/mednotes/docs/anki-templates/README.md +39 -0
- package/.opencode/mednotes/docs/anki-templates/cloze.back.html +23 -0
- package/.opencode/mednotes/docs/anki-templates/cloze.front.html +14 -0
- package/.opencode/mednotes/docs/anki-templates/qa.back.html +24 -0
- package/.opencode/mednotes/docs/anki-templates/qa.front.html +14 -0
- package/.opencode/mednotes/docs/anki-templates/style.css +182 -0
- package/.opencode/mednotes/docs/atomicity-splitting-policy.md +113 -0
- package/.opencode/mednotes/docs/extension-docs.md +40 -0
- package/.opencode/mednotes/docs/flashcard-ingestion.md +278 -0
- package/.opencode/mednotes/docs/knowledge-architect.md +208 -0
- package/.opencode/mednotes/docs/merge-policy.md +110 -0
- package/.opencode/mednotes/docs/public-vocabulary.md +104 -0
- package/.opencode/mednotes/docs/semantic-linker.md +141 -0
- package/.opencode/mednotes/docs/taxonomy-policy.md +90 -0
- package/.opencode/mednotes/docs/triage-policy.md +187 -0
- package/.opencode/mednotes/docs/vault-version-control.md +758 -0
- package/.opencode/mednotes/docs/vocabulary-db-recovery.md +58 -0
- package/.opencode/mednotes/docs/workflow-output-contract.md +779 -0
- package/.opencode/mednotes/hooks/hooks.json +79 -0
- package/.opencode/mednotes/package-lock.json +6361 -0
- package/.opencode/mednotes/package.json +15 -0
- package/.opencode/mednotes/pyproject.toml +48 -0
- package/.opencode/mednotes/scripts/bootstrap_windows_python_uv.cmd +13 -0
- package/.opencode/mednotes/scripts/bootstrap_windows_python_uv.ps1 +172 -0
- package/.opencode/mednotes/scripts/enrich_notes.py +23 -0
- package/.opencode/mednotes/scripts/full_reset_windows_python_uv.cmd +13 -0
- package/.opencode/mednotes/scripts/hooks/antigravity_hook_status.mjs +212 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/antigravity.mjs +169 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/harness_payload.mjs +103 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/opencode_plugin.mjs +341 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/opencode_user_config_sync.mjs +177 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/anki_preflight.mjs +214 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/cli.mjs +143 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/diagnostics.mjs +11 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/domain/agent_directive_core.mjs +160 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/fsm_directive.mjs +1470 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/hook_errors.mjs +120 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/retention.mjs +114 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/runtime.mjs +174 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/telemetry_capture.mjs +511 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook/vault_guard.mjs +624 -0
- package/.opencode/mednotes/scripts/hooks/mednotes_hook.mjs +5 -0
- package/.opencode/mednotes/scripts/mednotes/_runtime_paths.py +24 -0
- package/.opencode/mednotes/scripts/mednotes/anki_model_validator.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/capture_extension_diff.py +1562 -0
- package/.opencode/mednotes/scripts/mednotes/feedback_report.py +16 -0
- package/.opencode/mednotes/scripts/mednotes/flashcard_index.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/flashcard_pipeline.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/flashcard_report.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/flashcard_sources.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/obsidian/README.md +6 -0
- package/.opencode/mednotes/scripts/mednotes/obsidian_note_utils.py +20 -0
- package/.opencode/mednotes/scripts/mednotes/pdf_library/cli.py +16 -0
- package/.opencode/mednotes/scripts/mednotes/project_fsm.py +229 -0
- package/.opencode/mednotes/scripts/mednotes/setup_telemetry_email.py +404 -0
- package/.opencode/mednotes/scripts/mednotes/sync_anki_twenty_rules.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/sync_opencode_user_config.py +36 -0
- package/.opencode/mednotes/scripts/mednotes/wiki/cli.py +20 -0
- package/.opencode/mednotes/scripts/mednotes/wiki_graph.py +18 -0
- package/.opencode/mednotes/scripts/mednotes/wiki_tree.py +134 -0
- package/.opencode/mednotes/scripts/reset_windows_python_uv.ps1 +625 -0
- package/.opencode/mednotes/scripts/run_python.mjs +109 -0
- package/.opencode/mednotes/scripts/vault/vault_commit.ps1 +19 -0
- package/.opencode/mednotes/scripts/vault/vault_commit.sh +18 -0
- package/.opencode/mednotes/scripts/vault/vault_git.ps1 +19 -0
- package/.opencode/mednotes/scripts/vault/vault_git.py +3107 -0
- package/.opencode/mednotes/scripts/vault/vault_git.sh +18 -0
- package/.opencode/mednotes/scripts/vault/vault_precommit.ps1 +19 -0
- package/.opencode/mednotes/scripts/vault/vault_precommit.sh +18 -0
- package/.opencode/mednotes/skills/THIRD_PARTY_NOTICES.md +45 -0
- package/.opencode/mednotes/skills/create-medical-flashcards/SKILL.md +113 -0
- package/.opencode/mednotes/skills/create-medical-note/SKILL.md +90 -0
- package/.opencode/mednotes/skills/enrich-medical-note/SKILL.md +120 -0
- package/.opencode/mednotes/skills/fix-medical-wiki/SKILL.md +559 -0
- package/.opencode/mednotes/skills/link-medical-wiki/SKILL.md +224 -0
- package/.opencode/mednotes/skills/obsidian-cli/SKILL.md +118 -0
- package/.opencode/mednotes/skills/obsidian-markdown/SKILL.md +207 -0
- package/.opencode/mednotes/skills/obsidian-markdown/references/CALLOUTS.md +58 -0
- package/.opencode/mednotes/skills/obsidian-markdown/references/EMBEDS.md +63 -0
- package/.opencode/mednotes/skills/obsidian-markdown/references/PROPERTIES.md +61 -0
- package/.opencode/mednotes/skills/obsidian-ops/SKILL.md +136 -0
- package/.opencode/mednotes/skills/pdf-library/SKILL.md +45 -0
- package/.opencode/mednotes/skills/process-medical-chats/SKILL.md +246 -0
- package/.opencode/mednotes/skills/workflow-report/SKILL.md +100 -0
- package/.opencode/mednotes/src/mednotes/__init__.py +5 -0
- package/.opencode/mednotes/src/mednotes/domains/__init__.py +5 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/README.md +26 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/__init__.py +2 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/build_demo_apkg.py +177 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/contracts.py +385 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/flashcards_machine.py +522 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/fsm.py +817 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/index.py +630 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/install_models.py +445 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/model.py +359 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/obsidian_links.py +135 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/obsidian_note_utils.py +546 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/pipeline.py +580 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/report.py +510 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/sources.py +682 -0
- package/.opencode/mednotes/src/mednotes/domains/flashcards/sync_rules.py +184 -0
- package/.opencode/mednotes/src/mednotes/domains/history/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/history/history_fsm.py +852 -0
- package/.opencode/mednotes/src/mednotes/domains/history/history_machine.py +453 -0
- package/.opencode/mednotes/src/mednotes/domains/setup/__init__.py +7 -0
- package/.opencode/mednotes/src/mednotes/domains/setup/setup_fsm.py +808 -0
- package/.opencode/mednotes/src/mednotes/domains/setup/setup_machine.py +973 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/README.md +64 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/api.py +668 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/batch_state.py +102 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/atomicity/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/atomicity/atomicity.py +877 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/body_link/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/body_link/body_linker.py +1562 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/effects/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/effects/effect_adapters.py +949 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/effects/fix_wiki_runtime_adapters.py +433 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/coverage.py +413 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/graph.py +396 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/graph_fixes.py +161 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/hygiene/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/hygiene/hygiene.py +483 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/__init__.py +2 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/anchors.py +185 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/__init__.py +0 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/cache.py +223 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/config.py +131 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/download.py +224 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/frontmatter.py +59 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/insert.py +227 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/local_import.py +54 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/__init__.py +42 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/web_profiles.py +99 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/web_search.py +203 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/wikimedia.py +102 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/markdown_db_adapter.mjs +434 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/markdown_node_runtime.py +274 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/markdown_query.py +227 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/artifacts.py +605 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/canonical_merge.py +277 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/markdown_zones.py +85 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/meaning_planner.py +307 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_iter.py +67 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_merge.py +278 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_plan.py +409 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_policy.py +22 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/__init__.py +79 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/fixes.py +264 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/frontmatter.py +435 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/models.py +208 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/prompts.py +37 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/tables.py +236 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/validate.py +404 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/provenance.py +478 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/raw_chats.py +273 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/sources_backfill.py +235 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/__init__.py +10 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/anchors.py +16 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/captions.py +47 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/cli.py +179 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/cloud.py +52 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/config.py +196 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/context_packets.py +76 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/db.py +81 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/doctor.py +102 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/figure_ids.py +42 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/ingest.py +326 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/insert.py +316 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/mentions.py +57 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/ocr.py +71 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/paths.py +35 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/pdf_engine.py +77 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/schema.py +155 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/search.py +188 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/app.py +89 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/image_backend.py +29 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/state.py +65 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/publish.py +1139 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/publish_receipts.py +365 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/publish_recovery.py +240 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/agent_behavior_corpus.py +2069 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/agent_report_validation.py +4448 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/agent_run_audit.py +852 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/architect_prompt_eval.py +341 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/body_linker_eval.py +240 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/curator_output_validation.py +175 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/curator_prompt_eval.py +865 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/triager_prompt_eval.py +1295 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/related_notes/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/related_notes/related_notes.py +1920 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/related_notes/related_notes_headless.py +1186 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/plan_attestation.py +148 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/specialist_receipts.py +360 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/specialist_runtime.py +52 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/specialist_task_runner.py +2470 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/style/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/style/style.py +1952 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/subagents/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/subagents/agents.py +1767 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/alias_projection.py +331 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/link_terms.py +151 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/llm_disambiguation.py +182 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/__init__.py +116 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/audit.py +201 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/migration.py +314 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/normalize.py +72 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/policy.py +135 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/resolve.py +413 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/schema.py +157 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/status.py +137 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_bootstrap.py +509 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_curator_batch.py +1115 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_ingestion.py +632 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_map.py +930 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_recovery.py +1388 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/cli.py +6665 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/common.py +69 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/config.py +210 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/__init__.py +74 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/agent_report.py +242 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/agent_run_audit.py +196 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/agents.py +601 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/curator.py +256 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/effect_payloads.py +519 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/happy_path.py +190 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/link_git.py +110 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/link_runtime_artifact.py +52 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/note_plan.py +75 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/paths.py +114 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/public_report.py +53 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/publish.py +111 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/raw_coverage.py +217 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/related_notes.py +136 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/related_notes_headless.py +153 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/related_notes_runtime.py +395 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/schema_registry.py +637 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/specialist.py +432 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/status.py +62 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/style_rewrite.py +568 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/vocabulary_ingestion.py +223 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_blockers.py +510 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_guardrails.py +637 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_outcomes.py +121 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_receipts.py +100 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/__main__.py +4 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/cli.py +275 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/__init__.py +2 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/candidates.py +193 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/cli.py +189 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/gemini.py +220 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/inputs.py +120 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/models.py +34 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/parsing.py +48 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/prompts.py +216 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/quality.py +54 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/reporting.py +24 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/runner.py +433 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/utils.py +39 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/vault_guard_bridge.py +17 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_context_packets.py +454 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_decision_projection.py +133 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_effects.py +1260 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_fsm.py +2768 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_machine.py +1588 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_plan.py +306 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_primary_objective.py +316 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_problem.py +153 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_receipt_evidence.py +306 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_states.py +290 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_user_report.py +342 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/health.py +6332 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_fsm.py +1119 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_git.py +638 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_machine.py +1106 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_retry_governance.py +374 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_runtime_result.py +485 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_triggers.py +183 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/linking.py +2758 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/reference_repair.py +718 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/related_notes_fsm.py +1855 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link_related/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link_related/link_related_machine.py +834 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/__init__.py +1 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_fsm.py +1592 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_machine.py +3097 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_primary_objective.py +28 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_runtime_result.py +185 -0
- package/.opencode/mednotes/src/mednotes/domains/wiki/performance.py +97 -0
- package/.opencode/mednotes/src/mednotes/kernel/__init__.py +6 -0
- package/.opencode/mednotes/src/mednotes/kernel/agent_directive.py +336 -0
- package/.opencode/mednotes/src/mednotes/kernel/base.py +51 -0
- package/.opencode/mednotes/src/mednotes/kernel/blockers.py +39 -0
- package/.opencode/mednotes/src/mednotes/kernel/effect_executor.py +55 -0
- package/.opencode/mednotes/src/mednotes/kernel/effect_intent.py +69 -0
- package/.opencode/mednotes/src/mednotes/kernel/effects.py +160 -0
- package/.opencode/mednotes/src/mednotes/kernel/errors.py +38 -0
- package/.opencode/mednotes/src/mednotes/kernel/fsm_event.py +35 -0
- package/.opencode/mednotes/src/mednotes/kernel/fsm_model.py +55 -0
- package/.opencode/mednotes/src/mednotes/kernel/fsm_transition_result.py +75 -0
- package/.opencode/mednotes/src/mednotes/kernel/guardrails.py +188 -0
- package/.opencode/mednotes/src/mednotes/kernel/progress.py +319 -0
- package/.opencode/mednotes/src/mednotes/kernel/public_report.py +346 -0
- package/.opencode/mednotes/src/mednotes/kernel/state_machine.py +164 -0
- package/.opencode/mednotes/src/mednotes/kernel/workflow.py +619 -0
- package/.opencode/mednotes/src/mednotes/platform/__init__.py +5 -0
- package/.opencode/mednotes/src/mednotes/platform/backup_policy.py +382 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/__init__.py +62 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/cli.py +275 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/contracts.py +83 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/core.py +4168 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/integrity.py +989 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/operational_contract.py +2293 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/telemetry.py +875 -0
- package/.opencode/mednotes/src/mednotes/platform/feedback/telemetry_config.py +65 -0
- package/.opencode/mednotes/src/mednotes/platform/opencode_runtime_config.py +182 -0
- package/.opencode/mednotes/src/mednotes/platform/paths/__init__.py +1560 -0
- package/.opencode/mednotes/src/mednotes/platform/secrets.py +89 -0
- package/.opencode/mednotes/src/mednotes/platform/user_config.py +103 -0
- package/.opencode/mednotes/src/mednotes/platform/vault_guard.py +214 -0
- package/.opencode/mednotes/uv.lock +932 -0
- package/.opencode/mednotes.generated.json +395 -0
- package/.opencode/opencode.json +31 -0
- package/.opencode/plugins/mednotes-fsm.mjs +7 -0
- package/.opencode/plugins/mednotes_hook/adapters/antigravity.mjs +169 -0
- package/.opencode/plugins/mednotes_hook/adapters/harness_payload.mjs +103 -0
- package/.opencode/plugins/mednotes_hook/adapters/opencode_plugin.mjs +341 -0
- package/.opencode/plugins/mednotes_hook/adapters/opencode_user_config_sync.mjs +177 -0
- package/.opencode/plugins/mednotes_hook/anki_preflight.mjs +214 -0
- package/.opencode/plugins/mednotes_hook/cli.mjs +143 -0
- package/.opencode/plugins/mednotes_hook/diagnostics.mjs +11 -0
- package/.opencode/plugins/mednotes_hook/domain/agent_directive_core.mjs +160 -0
- package/.opencode/plugins/mednotes_hook/fsm_directive.mjs +1470 -0
- package/.opencode/plugins/mednotes_hook/hook_errors.mjs +120 -0
- package/.opencode/plugins/mednotes_hook/retention.mjs +114 -0
- package/.opencode/plugins/mednotes_hook/runtime.mjs +174 -0
- package/.opencode/plugins/mednotes_hook/telemetry_capture.mjs +511 -0
- package/.opencode/plugins/mednotes_hook/vault_guard.mjs +624 -0
- package/AGENTS.md +57 -0
- package/README.md +194 -0
- package/adapters/antigravity/agents.json +80 -0
- package/adapters/antigravity/templates/med-chat-triager.md +214 -0
- package/adapters/antigravity/templates/med-flashcard-maker.md +72 -0
- package/adapters/antigravity/templates/med-knowledge-architect.md +241 -0
- package/adapters/antigravity/templates/med-link-graph-curator.md +187 -0
- package/adapters/antigravity/templates/med-publish-guard.md +71 -0
- package/adapters/gemini-cli/gemini-extension.json +14 -0
- package/adapters/gemini-cli/package.json +15 -0
- package/adapters/gemini-cli/pyproject.toml +48 -0
- package/bin/mednotes-opencode.mjs +155 -0
- package/contracts/agents.json +116 -0
- package/core/agents/med-chat-triager.md +197 -0
- package/core/agents/med-flashcard-maker.md +56 -0
- package/core/agents/med-knowledge-architect.md +224 -0
- package/core/agents/med-link-graph-curator.md +171 -0
- package/core/agents/med-publish-guard.md +55 -0
- package/core/commands/flashcards.toml +22 -0
- package/core/commands/mednotes/create.toml +22 -0
- package/core/commands/mednotes/enrich.toml +24 -0
- package/core/commands/mednotes/fix-wiki.toml +24 -0
- package/core/commands/mednotes/history.toml +19 -0
- package/core/commands/mednotes/link-body.toml +22 -0
- package/core/commands/mednotes/link-related.toml +24 -0
- package/core/commands/mednotes/link.toml +24 -0
- package/core/commands/mednotes/pdf-library.toml +24 -0
- package/core/commands/mednotes/process-chats.toml +20 -0
- package/core/commands/mednotes/setup.toml +18 -0
- package/core/commands/mednotes/status.toml +24 -0
- package/core/commands/mednotes/telemetry.toml +24 -0
- package/core/commands/report.toml +23 -0
- package/core/skills/THIRD_PARTY_NOTICES.md +45 -0
- package/core/skills/create-medical-flashcards/SKILL.md +113 -0
- package/core/skills/create-medical-note/SKILL.md +90 -0
- package/core/skills/enrich-medical-note/SKILL.md +120 -0
- package/core/skills/fix-medical-wiki/SKILL.md +559 -0
- package/core/skills/link-medical-wiki/SKILL.md +224 -0
- package/core/skills/obsidian-cli/SKILL.md +118 -0
- package/core/skills/obsidian-markdown/SKILL.md +207 -0
- package/core/skills/obsidian-markdown/references/CALLOUTS.md +58 -0
- package/core/skills/obsidian-markdown/references/EMBEDS.md +63 -0
- package/core/skills/obsidian-markdown/references/PROPERTIES.md +61 -0
- package/core/skills/obsidian-ops/SKILL.md +136 -0
- package/core/skills/pdf-library/SKILL.md +45 -0
- package/core/skills/process-medical-chats/SKILL.md +246 -0
- package/core/skills/workflow-report/SKILL.md +100 -0
- package/package.json +45 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"""Raw chat frontmatter and filesystem helpers."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import errno
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import tempfile
|
|
9
|
+
import time
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from pydantic import ConfigDict
|
|
14
|
+
|
|
15
|
+
from mednotes.domains.wiki.capabilities.notes.note_plan import note_plan_summary, parse_triage_note_plan
|
|
16
|
+
from mednotes.domains.wiki.capabilities.notes.note_style.frontmatter import (
|
|
17
|
+
FrontmatterYamlUnavailable,
|
|
18
|
+
load_frontmatter_yaml,
|
|
19
|
+
)
|
|
20
|
+
from mednotes.domains.wiki.common import FileWriteError, MissingPathError, ValidationError
|
|
21
|
+
from mednotes.kernel.base import ContractModel
|
|
22
|
+
from mednotes.platform.backup_policy import (
|
|
23
|
+
DEFAULT_BACKUP_POLICY,
|
|
24
|
+
BackupPolicy,
|
|
25
|
+
cleanup_backups,
|
|
26
|
+
policy_from_values,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
_FRONTMATTER_DELIM = "---"
|
|
30
|
+
_KEY_RE = re.compile(r"^([A-Za-z0-9_-]+)\s*:\s*(.*)$")
|
|
31
|
+
_ATOMIC_WRITE_RETRY_DELAYS = (0.05, 0.1, 0.2, 0.4, 0.8)
|
|
32
|
+
_WINDOWS_LOCK_WINERRORS = {5, 32, 33}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class _RawSummaryDecisionFields(ContractModel):
|
|
36
|
+
"""Typed subset of raw chat summary fields used for status filtering."""
|
|
37
|
+
|
|
38
|
+
model_config = ConfigDict(extra="ignore", populate_by_name=True, validate_assignment=True)
|
|
39
|
+
|
|
40
|
+
status: str = ""
|
|
41
|
+
tipo: str = ""
|
|
42
|
+
chat_id: str = ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def split_frontmatter(text: str) -> tuple[list[str] | None, str]:
|
|
46
|
+
lines = text.splitlines(keepends=True)
|
|
47
|
+
if not lines or lines[0].strip() != _FRONTMATTER_DELIM:
|
|
48
|
+
return None, text
|
|
49
|
+
for idx in range(1, len(lines)):
|
|
50
|
+
if lines[idx].strip() == _FRONTMATTER_DELIM:
|
|
51
|
+
return lines[1:idx], "".join(lines[idx + 1 :])
|
|
52
|
+
return None, text
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _strip_quotes(value: str) -> str:
|
|
56
|
+
value = value.strip()
|
|
57
|
+
if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
|
|
58
|
+
try:
|
|
59
|
+
parsed = json.loads(value)
|
|
60
|
+
if isinstance(parsed, str):
|
|
61
|
+
return parsed
|
|
62
|
+
except json.JSONDecodeError:
|
|
63
|
+
pass
|
|
64
|
+
return value[1:-1]
|
|
65
|
+
return value
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def parse_frontmatter(text: str) -> dict[str, str]:
|
|
69
|
+
frontmatter, _body = split_frontmatter(text)
|
|
70
|
+
if frontmatter is None:
|
|
71
|
+
return {}
|
|
72
|
+
parsed: dict[str, str] = {}
|
|
73
|
+
for line in frontmatter:
|
|
74
|
+
match = _KEY_RE.match(line.strip())
|
|
75
|
+
if match:
|
|
76
|
+
parsed[match.group(1)] = _strip_quotes(match.group(2))
|
|
77
|
+
return parsed
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _format_yaml_value(value: str) -> str:
|
|
81
|
+
if value == "":
|
|
82
|
+
return '""'
|
|
83
|
+
if re.match(r"^[A-Za-z0-9_./@+-]+$", value):
|
|
84
|
+
return value
|
|
85
|
+
return json.dumps(value, ensure_ascii=False)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def update_frontmatter(text: str, updates: dict[str, str]) -> str:
|
|
89
|
+
frontmatter, body = split_frontmatter(text)
|
|
90
|
+
formatted = {key: f"{key}: {_format_yaml_value(value)}\n" for key, value in updates.items()}
|
|
91
|
+
if frontmatter is None:
|
|
92
|
+
return "---\n" + "".join(formatted.values()) + "---\n" + text
|
|
93
|
+
|
|
94
|
+
seen: set[str] = set()
|
|
95
|
+
out: list[str] = []
|
|
96
|
+
for line in frontmatter:
|
|
97
|
+
match = _KEY_RE.match(line.strip())
|
|
98
|
+
if match and match.group(1) in formatted:
|
|
99
|
+
key = match.group(1)
|
|
100
|
+
out.append(formatted[key])
|
|
101
|
+
seen.add(key)
|
|
102
|
+
else:
|
|
103
|
+
out.append(line)
|
|
104
|
+
for key, line in formatted.items():
|
|
105
|
+
if key not in seen:
|
|
106
|
+
out.append(line)
|
|
107
|
+
return "---\n" + "".join(out) + "---\n" + body
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def read_note_meta(path: Path) -> dict[str, str]:
|
|
111
|
+
try:
|
|
112
|
+
return parse_frontmatter(path.read_text(encoding="utf-8"))
|
|
113
|
+
except FileNotFoundError as exc:
|
|
114
|
+
raise MissingPathError(f"File not found: {path}") from exc
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def create_backup(path: Path, *, policy: BackupPolicy = DEFAULT_BACKUP_POLICY) -> Path:
|
|
118
|
+
policy.validate()
|
|
119
|
+
if not path.exists():
|
|
120
|
+
raise MissingPathError(f"File not found: {path}")
|
|
121
|
+
raise RuntimeError("Markdown .bak backups are retired; use vault version control restore points.")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def prune_backup_files(
|
|
125
|
+
root: Path,
|
|
126
|
+
*,
|
|
127
|
+
max_per_file: int | None = None,
|
|
128
|
+
retention_days: int | None = None,
|
|
129
|
+
policy: BackupPolicy = DEFAULT_BACKUP_POLICY,
|
|
130
|
+
) -> dict[str, Any]:
|
|
131
|
+
resolved_policy = policy_from_values(
|
|
132
|
+
max_per_file=max_per_file,
|
|
133
|
+
retention_days=retention_days,
|
|
134
|
+
policy=policy,
|
|
135
|
+
)
|
|
136
|
+
try:
|
|
137
|
+
return cleanup_backups(root, policy=resolved_policy)
|
|
138
|
+
except FileNotFoundError as exc:
|
|
139
|
+
raise MissingPathError(str(exc)) from exc
|
|
140
|
+
except ValueError as exc:
|
|
141
|
+
raise ValidationError(str(exc)) from exc
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _is_retryable_replace_error(exc: OSError) -> bool:
|
|
145
|
+
if isinstance(exc, PermissionError):
|
|
146
|
+
return True
|
|
147
|
+
if getattr(exc, "winerror", None) in _WINDOWS_LOCK_WINERRORS:
|
|
148
|
+
return True
|
|
149
|
+
return getattr(exc, "errno", None) in {errno.EACCES, errno.EPERM, errno.EBUSY}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _replace_with_retries(path: Path, tmp: Path, retry_delays: tuple[float, ...]) -> None:
|
|
153
|
+
attempts = len(retry_delays) + 1
|
|
154
|
+
last_error: OSError | None = None
|
|
155
|
+
for attempt_idx in range(attempts):
|
|
156
|
+
try:
|
|
157
|
+
os.replace(tmp, path)
|
|
158
|
+
return
|
|
159
|
+
except OSError as exc:
|
|
160
|
+
last_error = exc
|
|
161
|
+
if attempt_idx >= len(retry_delays) or not _is_retryable_replace_error(exc):
|
|
162
|
+
break
|
|
163
|
+
time.sleep(retry_delays[attempt_idx])
|
|
164
|
+
|
|
165
|
+
raise FileWriteError(
|
|
166
|
+
f"Could not atomically replace {path} after {attempts} attempts. "
|
|
167
|
+
f"The file may be locked by Obsidian, iCloud Drive, antivirus, or another process. "
|
|
168
|
+
f"Original error: {last_error}"
|
|
169
|
+
) from last_error
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def atomic_write_text(path: Path, text: str, *, retry_delays: tuple[float, ...] | None = None) -> None:
|
|
173
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
174
|
+
fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", suffix=".tmp", dir=str(path.parent))
|
|
175
|
+
tmp = Path(tmp_name)
|
|
176
|
+
try:
|
|
177
|
+
with os.fdopen(fd, "w", encoding="utf-8", newline="") as fh:
|
|
178
|
+
fh.write(text)
|
|
179
|
+
_replace_with_retries(path, tmp, _ATOMIC_WRITE_RETRY_DELAYS if retry_delays is None else retry_delays)
|
|
180
|
+
finally:
|
|
181
|
+
if tmp.exists():
|
|
182
|
+
try:
|
|
183
|
+
tmp.unlink()
|
|
184
|
+
except OSError:
|
|
185
|
+
pass
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def mutate_raw_frontmatter(raw_file: Path, updates: dict[str, str], dry_run: bool = False, backup: bool = False) -> dict[str, Any]:
|
|
189
|
+
if not raw_file.exists():
|
|
190
|
+
raise MissingPathError(f"Raw file not found: {raw_file}")
|
|
191
|
+
original = raw_file.read_text(encoding="utf-8")
|
|
192
|
+
updated = update_frontmatter(original, updates)
|
|
193
|
+
if dry_run:
|
|
194
|
+
return {"raw_file": str(raw_file), "backup": None, "updated": False, "updates": updates}
|
|
195
|
+
atomic_write_text(raw_file, updated)
|
|
196
|
+
return {"raw_file": str(raw_file), "backup": None, "updated": True, "updates": updates}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def list_raw_files(raw_dir: Path) -> list[Path]:
|
|
200
|
+
if not raw_dir.exists():
|
|
201
|
+
raise MissingPathError(f"Raw dir not found: {raw_dir}")
|
|
202
|
+
return sorted(path for path in raw_dir.glob("*.md") if path.is_file())
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def raw_summary(path: Path) -> dict[str, str]:
|
|
206
|
+
meta = read_note_meta(path)
|
|
207
|
+
chat_id = meta.get("fonte_id", "").strip()
|
|
208
|
+
result = {
|
|
209
|
+
"path": str(path),
|
|
210
|
+
"status": meta.get("status", ""),
|
|
211
|
+
"tipo": meta.get("tipo", ""),
|
|
212
|
+
"titulo_triagem": meta.get("titulo_triagem", ""),
|
|
213
|
+
"fonte_id": meta.get("fonte_id", ""),
|
|
214
|
+
"chat_id": chat_id,
|
|
215
|
+
"title": meta.get("titulo_triagem", ""),
|
|
216
|
+
"url": f"https://gemini.google.com/app/{chat_id}" if chat_id else "",
|
|
217
|
+
"date_created": meta.get("date_created", ""),
|
|
218
|
+
"exported_at": meta.get("exported_at", ""),
|
|
219
|
+
}
|
|
220
|
+
raw_plan = meta.get("note_plan", "")
|
|
221
|
+
if raw_plan:
|
|
222
|
+
try:
|
|
223
|
+
result.update({key: str(value) for key, value in note_plan_summary(parse_triage_note_plan(raw_plan, path)).items()})
|
|
224
|
+
except ValidationError as exc:
|
|
225
|
+
result["note_plan_error"] = str(exc)
|
|
226
|
+
return result
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def covered_raw_chat_index(wiki_dir: Path) -> dict[str, list[str]]:
|
|
230
|
+
if not wiki_dir.exists():
|
|
231
|
+
return {}
|
|
232
|
+
index: dict[str, list[str]] = {}
|
|
233
|
+
for note_path in sorted(wiki_dir.rglob("*.md")):
|
|
234
|
+
if not note_path.is_file():
|
|
235
|
+
continue
|
|
236
|
+
try:
|
|
237
|
+
frontmatter = load_frontmatter_yaml(note_path.read_text(encoding="utf-8"))
|
|
238
|
+
except (OSError, FrontmatterYamlUnavailable):
|
|
239
|
+
continue
|
|
240
|
+
raw_chats = frontmatter.get("chats")
|
|
241
|
+
if not isinstance(raw_chats, list):
|
|
242
|
+
continue
|
|
243
|
+
for chat in raw_chats:
|
|
244
|
+
if not isinstance(chat, dict):
|
|
245
|
+
continue
|
|
246
|
+
chat_id = str(chat.get("id") or "").strip()
|
|
247
|
+
if not chat_id:
|
|
248
|
+
continue
|
|
249
|
+
index.setdefault(chat_id, []).append(str(note_path))
|
|
250
|
+
return index
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def list_by_status(
|
|
254
|
+
raw_dir: Path,
|
|
255
|
+
mode: str,
|
|
256
|
+
*,
|
|
257
|
+
covered_raw_chat_ids: set[str] | None = None,
|
|
258
|
+
) -> list[dict[str, str]]:
|
|
259
|
+
covered_ids = covered_raw_chat_ids or set()
|
|
260
|
+
rows: list[dict[str, str]] = []
|
|
261
|
+
for path in list_raw_files(raw_dir):
|
|
262
|
+
item = raw_summary(path)
|
|
263
|
+
fields = _RawSummaryDecisionFields.model_validate(item)
|
|
264
|
+
status = fields.status.lower()
|
|
265
|
+
tipo = fields.tipo.lower()
|
|
266
|
+
if mode == "pending" and status in {"", "pendente"}:
|
|
267
|
+
raw_id = fields.chat_id or path.stem
|
|
268
|
+
if raw_id in covered_ids:
|
|
269
|
+
continue
|
|
270
|
+
rows.append(item)
|
|
271
|
+
elif mode == "triados" and status == "triado" and tipo == "medicina":
|
|
272
|
+
rows.append(item)
|
|
273
|
+
return rows
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"""Backfill canonical chat provenance for existing Wiki notes."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
from pydantic import ConfigDict, Field
|
|
8
|
+
|
|
9
|
+
from mednotes.domains.wiki.capabilities.markdown.markdown_query import MarkdownDbChatMetadataProvider
|
|
10
|
+
from mednotes.domains.wiki.capabilities.notes.note_iter import iter_notes
|
|
11
|
+
from mednotes.domains.wiki.capabilities.notes.note_style.frontmatter import FrontmatterYamlUnavailable
|
|
12
|
+
from mednotes.domains.wiki.capabilities.notes.provenance import (
|
|
13
|
+
ChatProvenance,
|
|
14
|
+
apply_note_provenance,
|
|
15
|
+
audit_note_provenance,
|
|
16
|
+
classify_note_provenance,
|
|
17
|
+
)
|
|
18
|
+
from mednotes.domains.wiki.capabilities.notes.raw_chats import atomic_write_text
|
|
19
|
+
from mednotes.domains.wiki.capabilities.vocabulary.link_terms import is_index_note as _is_index_note
|
|
20
|
+
from mednotes.domains.wiki.config import MedConfig
|
|
21
|
+
from mednotes.kernel.base import ContractModel, JsonObject
|
|
22
|
+
|
|
23
|
+
SOURCES_BACKFILL_AUDIT_SCHEMA = "medical-notes-workbench.chats-backfill-audit.v1"
|
|
24
|
+
SOURCES_BACKFILL_RECEIPT_SCHEMA = "medical-notes-workbench.chats-backfill-receipt.v1"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _FallbackChatMetadataProvider:
|
|
28
|
+
def lookup_chat(self, chat_id: str) -> None:
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class _ChatMetadataProvider(Protocol):
|
|
33
|
+
"""Small provider contract needed by provenance backfill."""
|
|
34
|
+
|
|
35
|
+
def lookup_chat(self, chat_id: str) -> object | None: ...
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class _ProvenanceAuditFields(ContractModel):
|
|
39
|
+
"""Typed view over provenance audit output used by this backfill flow."""
|
|
40
|
+
|
|
41
|
+
model_config = ConfigDict(extra="ignore", populate_by_name=True, validate_assignment=True)
|
|
42
|
+
|
|
43
|
+
errors: list[JsonObject] = Field(default_factory=list)
|
|
44
|
+
warnings: list[JsonObject] = Field(default_factory=list)
|
|
45
|
+
blocked_reason: str = ""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class _BackfillReportFields(ContractModel):
|
|
49
|
+
"""Closed operational fields for one note provenance backfill report."""
|
|
50
|
+
|
|
51
|
+
model_config = ConfigDict(extra="ignore", populate_by_name=True, validate_assignment=True)
|
|
52
|
+
|
|
53
|
+
status: str = ""
|
|
54
|
+
chat_ids: list[str] = Field(default_factory=list)
|
|
55
|
+
legacy_urls: list[str] = Field(default_factory=list)
|
|
56
|
+
warnings: list[JsonObject] = Field(default_factory=list)
|
|
57
|
+
wrote: bool = Field(default=False, strict=True)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class _MetadataLookupFields(ContractModel):
|
|
61
|
+
"""Typed metadata lookup mode used to summarize backfill execution."""
|
|
62
|
+
|
|
63
|
+
model_config = ConfigDict(extra="ignore", populate_by_name=True, validate_assignment=True)
|
|
64
|
+
|
|
65
|
+
mode: str = ""
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def audit_sources_backfill(config: MedConfig, *, node_modules_path: Path | None = None) -> dict[str, object]:
|
|
69
|
+
provider = MarkdownDbChatMetadataProvider(
|
|
70
|
+
wiki_dir=config.wiki_dir,
|
|
71
|
+
raw_dir=config.raw_dir,
|
|
72
|
+
node_modules_path=node_modules_path,
|
|
73
|
+
)
|
|
74
|
+
reports = [_note_backfill_report(path, provider) for path in _backfillable_notes(config.wiki_dir)]
|
|
75
|
+
return _summary_payload(
|
|
76
|
+
schema=SOURCES_BACKFILL_AUDIT_SCHEMA,
|
|
77
|
+
config=config,
|
|
78
|
+
reports=reports,
|
|
79
|
+
dry_run=True,
|
|
80
|
+
backup=False,
|
|
81
|
+
backup_paths=[],
|
|
82
|
+
write_errors=[],
|
|
83
|
+
metadata_lookup={"mode": "not_required_for_audit", "skipped_reason": "", "warning": None},
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def apply_sources_backfill(
|
|
88
|
+
config: MedConfig,
|
|
89
|
+
*,
|
|
90
|
+
backup: bool,
|
|
91
|
+
node_modules_path: Path | None = None,
|
|
92
|
+
metadata_fallback_reason: str = "",
|
|
93
|
+
metadata_warning: JsonObject | None = None,
|
|
94
|
+
) -> dict[str, object]:
|
|
95
|
+
backup = False
|
|
96
|
+
if metadata_fallback_reason:
|
|
97
|
+
provider: _ChatMetadataProvider = _FallbackChatMetadataProvider()
|
|
98
|
+
metadata_lookup = {
|
|
99
|
+
"mode": "fallback",
|
|
100
|
+
"skipped_reason": metadata_fallback_reason,
|
|
101
|
+
"warning": metadata_warning,
|
|
102
|
+
}
|
|
103
|
+
else:
|
|
104
|
+
provider = MarkdownDbChatMetadataProvider(
|
|
105
|
+
wiki_dir=config.wiki_dir,
|
|
106
|
+
raw_dir=config.raw_dir,
|
|
107
|
+
node_modules_path=node_modules_path,
|
|
108
|
+
)
|
|
109
|
+
metadata_lookup = {"mode": "markdown_query", "skipped_reason": "", "warning": None}
|
|
110
|
+
reports: list[JsonObject] = []
|
|
111
|
+
backup_paths: list[str] = []
|
|
112
|
+
write_errors: list[dict[str, str]] = []
|
|
113
|
+
for path in _backfillable_notes(config.wiki_dir):
|
|
114
|
+
report = _note_backfill_report(path, provider)
|
|
115
|
+
report_fields = _BackfillReportFields.model_validate(report)
|
|
116
|
+
if report_fields.status != "planned":
|
|
117
|
+
reports.append(report)
|
|
118
|
+
continue
|
|
119
|
+
original = path.read_text(encoding="utf-8")
|
|
120
|
+
try:
|
|
121
|
+
updated = _apply_text(original, report, provider)
|
|
122
|
+
if updated != original:
|
|
123
|
+
atomic_write_text(path, updated)
|
|
124
|
+
report = {**report, "status": "written", "wrote": True, "changed": True}
|
|
125
|
+
else:
|
|
126
|
+
report = {**report, "status": "already_canonical", "wrote": False, "changed": False}
|
|
127
|
+
except (FrontmatterYamlUnavailable, OSError) as exc:
|
|
128
|
+
write_errors.append({"path": str(path), "error": str(exc)})
|
|
129
|
+
report = {**report, "status": "write_error", "wrote": False, "changed": False, "error": str(exc)}
|
|
130
|
+
reports.append(report)
|
|
131
|
+
return _summary_payload(
|
|
132
|
+
schema=SOURCES_BACKFILL_RECEIPT_SCHEMA,
|
|
133
|
+
config=config,
|
|
134
|
+
reports=reports,
|
|
135
|
+
dry_run=False,
|
|
136
|
+
backup=backup,
|
|
137
|
+
backup_paths=backup_paths,
|
|
138
|
+
write_errors=write_errors,
|
|
139
|
+
metadata_lookup=metadata_lookup,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _backfillable_notes(wiki_dir: Path) -> list[Path]:
|
|
144
|
+
notes: list[Path] = []
|
|
145
|
+
for path in iter_notes(wiki_dir):
|
|
146
|
+
try:
|
|
147
|
+
text = path.read_text(encoding="utf-8")
|
|
148
|
+
except OSError:
|
|
149
|
+
notes.append(path)
|
|
150
|
+
continue
|
|
151
|
+
if _is_index_note(path, text):
|
|
152
|
+
continue
|
|
153
|
+
notes.append(path)
|
|
154
|
+
return notes
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _note_backfill_report(path: Path, provider: _ChatMetadataProvider) -> JsonObject:
|
|
158
|
+
text = path.read_text(encoding="utf-8")
|
|
159
|
+
audit = audit_note_provenance(text, chat_lookup=provider)
|
|
160
|
+
audit_fields = _ProvenanceAuditFields.model_validate(audit)
|
|
161
|
+
state = classify_note_provenance(text)
|
|
162
|
+
base = {
|
|
163
|
+
"path": str(path),
|
|
164
|
+
"chat_ids": list(state.chat_ids),
|
|
165
|
+
"legacy_urls": list(state.legacy_urls),
|
|
166
|
+
"errors": audit_fields.errors,
|
|
167
|
+
"warnings": audit_fields.warnings,
|
|
168
|
+
"wrote": False,
|
|
169
|
+
"changed": False,
|
|
170
|
+
}
|
|
171
|
+
if audit_fields.errors and audit_fields.blocked_reason == "chats.shape_invalid":
|
|
172
|
+
return {**base, "status": "blocked", "blocked_reason": "chats.shape_invalid"}
|
|
173
|
+
if state.status == "already_canonical":
|
|
174
|
+
return {**base, "status": "already_canonical", "blocked_reason": ""}
|
|
175
|
+
if state.status == "migratable" or state.chat_ids:
|
|
176
|
+
return {**base, "status": "planned", "blocked_reason": "", "would_write": True}
|
|
177
|
+
return {**base, "status": "warning", "blocked_reason": "", "would_write": False}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _apply_text(text: str, report: JsonObject, provider: _ChatMetadataProvider) -> str:
|
|
181
|
+
report_fields = _BackfillReportFields.model_validate(report)
|
|
182
|
+
chats = [ChatProvenance(chat_id) for chat_id in report_fields.chat_ids]
|
|
183
|
+
if not chats:
|
|
184
|
+
chats = [ChatProvenance(url) for url in report_fields.legacy_urls]
|
|
185
|
+
result = apply_note_provenance(text, chats=chats, chat_lookup=provider)
|
|
186
|
+
return str(result["text"])
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _summary_payload(
|
|
190
|
+
*,
|
|
191
|
+
schema: str,
|
|
192
|
+
config: MedConfig,
|
|
193
|
+
reports: list[JsonObject],
|
|
194
|
+
dry_run: bool,
|
|
195
|
+
backup: bool,
|
|
196
|
+
backup_paths: list[str],
|
|
197
|
+
write_errors: list[dict[str, str]],
|
|
198
|
+
metadata_lookup: JsonObject,
|
|
199
|
+
) -> dict[str, object]:
|
|
200
|
+
report_fields = [_BackfillReportFields.model_validate(report) for report in reports]
|
|
201
|
+
metadata_fields = _MetadataLookupFields.model_validate(metadata_lookup)
|
|
202
|
+
written_count = sum(1 for report in report_fields if report.wrote)
|
|
203
|
+
planned_count = sum(1 for report in report_fields if report.status == "planned")
|
|
204
|
+
if not dry_run and written_count == 0 and planned_count == 0 and metadata_fields.mode == "markdown_query":
|
|
205
|
+
metadata_lookup = {"mode": "not_required", "skipped_reason": "no_recoverable_sources", "warning": None}
|
|
206
|
+
warning_items = [
|
|
207
|
+
warning
|
|
208
|
+
for report in report_fields
|
|
209
|
+
for warning in report.warnings
|
|
210
|
+
]
|
|
211
|
+
blocked_count = sum(1 for report in report_fields if report.status in {"blocked", "write_error"})
|
|
212
|
+
status = "blocked" if blocked_count else "planned" if dry_run and planned_count else "completed"
|
|
213
|
+
return {
|
|
214
|
+
"schema": schema,
|
|
215
|
+
"phase": "provenance_backfill",
|
|
216
|
+
"status": status,
|
|
217
|
+
"dry_run": dry_run,
|
|
218
|
+
"backup": backup,
|
|
219
|
+
"wiki_dir": str(config.wiki_dir),
|
|
220
|
+
"raw_dir": str(config.raw_dir),
|
|
221
|
+
"scanned_count": len(reports),
|
|
222
|
+
"recoverable_count": sum(1 for report in report_fields if report.status == "planned"),
|
|
223
|
+
"would_write_count": planned_count if dry_run else 0,
|
|
224
|
+
"written_count": written_count,
|
|
225
|
+
"already_canonical_count": sum(1 for report in report_fields if report.status == "already_canonical"),
|
|
226
|
+
"unrecoverable_count": sum(1 for report in report_fields if report.status == "warning"),
|
|
227
|
+
"warning_count": len(warning_items),
|
|
228
|
+
"warnings": warning_items,
|
|
229
|
+
"blocked_count": blocked_count,
|
|
230
|
+
"write_error_count": len(write_errors),
|
|
231
|
+
"write_errors": write_errors,
|
|
232
|
+
"backup_paths": backup_paths,
|
|
233
|
+
"reports": reports,
|
|
234
|
+
"metadata_lookup": metadata_lookup,
|
|
235
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""PDF-library anchor adapter."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from mednotes.domains.wiki.capabilities.illustrate.anchors import AnchorProviderConfig, build_or_load_anchors
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def anchors_for_note(note_path: Path, *, cache_db: Path, max_anchors: int = 5, preferred_language: str = "pt-br"):
|
|
10
|
+
return build_or_load_anchors(
|
|
11
|
+
note_path,
|
|
12
|
+
cache_db=cache_db,
|
|
13
|
+
max_anchors=max_anchors,
|
|
14
|
+
preferred_language=preferred_language,
|
|
15
|
+
provider_config=AnchorProviderConfig(),
|
|
16
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Caption extraction for PDF text."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
from mednotes.domains.wiki.capabilities.pdf import figure_ids
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class Caption:
|
|
12
|
+
page_number: int
|
|
13
|
+
figure_id: str
|
|
14
|
+
text: str
|
|
15
|
+
bbox: tuple[float, float, float, float] | None = None
|
|
16
|
+
section_path_guess: list[str] = field(default_factory=list)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_CAPTION_RE = re.compile(
|
|
20
|
+
r"(?P<label>\b(?:fig(?:ure|ura)?|table|tabela|box|plate|algorithm|algoritmo)\.?\s*[0-9]+(?:[.\-][0-9]+)?\s*[- ]?\s*[a-zA-Z]?)\.?\s*(?P<body>[^\n]{0,240})",
|
|
21
|
+
re.IGNORECASE,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def extract_captions(text: str, *, page_number: int, section_path_guess: list[str] | None = None) -> list[Caption]:
|
|
26
|
+
captions: list[Caption] = []
|
|
27
|
+
seen: set[tuple[str, str]] = set()
|
|
28
|
+
for match in _CAPTION_RE.finditer(text):
|
|
29
|
+
label = match.group("label")
|
|
30
|
+
body = match.group("body").strip()
|
|
31
|
+
sentence = f"{label}. {body}".strip()
|
|
32
|
+
if len(sentence) < len(label) + 2:
|
|
33
|
+
continue
|
|
34
|
+
figure_id = figure_ids.normalize(label)
|
|
35
|
+
key = (figure_id, sentence)
|
|
36
|
+
if key in seen:
|
|
37
|
+
continue
|
|
38
|
+
seen.add(key)
|
|
39
|
+
captions.append(
|
|
40
|
+
Caption(
|
|
41
|
+
page_number=page_number,
|
|
42
|
+
figure_id=figure_id,
|
|
43
|
+
text=sentence,
|
|
44
|
+
section_path_guess=list(section_path_guess or []),
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
return captions
|