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,193 @@
|
|
|
1
|
+
"""Image candidate search and thumbnail preparation."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Protocol
|
|
6
|
+
|
|
7
|
+
from mednotes.domains.wiki.capabilities.illustrate.core.download import DownloadError
|
|
8
|
+
from mednotes.domains.wiki.capabilities.illustrate.core.download import download as download_image
|
|
9
|
+
from mednotes.domains.wiki.capabilities.illustrate.sources import (
|
|
10
|
+
ImageCandidate,
|
|
11
|
+
SourceQuotaExceeded,
|
|
12
|
+
web_profiles,
|
|
13
|
+
web_search,
|
|
14
|
+
wikimedia,
|
|
15
|
+
)
|
|
16
|
+
from mednotes.domains.wiki.flows.enrich.workflow import quality
|
|
17
|
+
from mednotes.domains.wiki.flows.enrich.workflow.models import CandidateReport
|
|
18
|
+
from mednotes.domains.wiki.flows.enrich.workflow.utils import _log
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _SearchAdapter(Protocol):
|
|
22
|
+
"""Uniform image-search adapter used by the enrichment workflow."""
|
|
23
|
+
|
|
24
|
+
NAME: str
|
|
25
|
+
|
|
26
|
+
def search(
|
|
27
|
+
self,
|
|
28
|
+
query: str,
|
|
29
|
+
visual_type: str,
|
|
30
|
+
*,
|
|
31
|
+
top_k: int = 4,
|
|
32
|
+
language: str | None = None,
|
|
33
|
+
) -> list[ImageCandidate]: ...
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class _WikimediaAdapter:
|
|
37
|
+
NAME = wikimedia.NAME
|
|
38
|
+
|
|
39
|
+
def search(
|
|
40
|
+
self,
|
|
41
|
+
query: str,
|
|
42
|
+
visual_type: str,
|
|
43
|
+
*,
|
|
44
|
+
top_k: int = 4,
|
|
45
|
+
language: str | None = None,
|
|
46
|
+
) -> list[ImageCandidate]:
|
|
47
|
+
return wikimedia.search(query, visual_type, top_k=top_k)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class _WebSearchAdapter:
|
|
51
|
+
NAME = web_search.NAME
|
|
52
|
+
|
|
53
|
+
def search(
|
|
54
|
+
self,
|
|
55
|
+
query: str,
|
|
56
|
+
visual_type: str,
|
|
57
|
+
*,
|
|
58
|
+
top_k: int = 4,
|
|
59
|
+
language: str | None = None,
|
|
60
|
+
) -> list[ImageCandidate]:
|
|
61
|
+
return web_search.search(query, visual_type, top_k=top_k, language=language)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class _ProfileAdapter:
|
|
65
|
+
def __init__(self, name: str):
|
|
66
|
+
self.NAME = name
|
|
67
|
+
|
|
68
|
+
def search(
|
|
69
|
+
self,
|
|
70
|
+
query: str,
|
|
71
|
+
visual_type: str,
|
|
72
|
+
*,
|
|
73
|
+
top_k: int = 4,
|
|
74
|
+
language: str | None = None,
|
|
75
|
+
) -> list[ImageCandidate]:
|
|
76
|
+
return web_profiles.search_profile(
|
|
77
|
+
self.NAME,
|
|
78
|
+
query,
|
|
79
|
+
visual_type,
|
|
80
|
+
top_k=top_k,
|
|
81
|
+
language=language,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
_SOURCE_REGISTRY: dict[str, _SearchAdapter] = {
|
|
86
|
+
wikimedia.NAME: _WikimediaAdapter(),
|
|
87
|
+
web_search.NAME: _WebSearchAdapter(),
|
|
88
|
+
**{name: _ProfileAdapter(name) for name in web_profiles.PROFILES},
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def gather_candidates(
|
|
93
|
+
anchor: dict,
|
|
94
|
+
*,
|
|
95
|
+
sources_enabled: list[str],
|
|
96
|
+
top_k_per_source: int,
|
|
97
|
+
max_total: int,
|
|
98
|
+
preferred_language: str = "any",
|
|
99
|
+
) -> list[ImageCandidate]:
|
|
100
|
+
return gather_candidate_report(
|
|
101
|
+
anchor,
|
|
102
|
+
sources_enabled=sources_enabled,
|
|
103
|
+
top_k_per_source=top_k_per_source,
|
|
104
|
+
max_total=max_total,
|
|
105
|
+
preferred_language=preferred_language,
|
|
106
|
+
).candidates
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def gather_candidate_report(
|
|
110
|
+
anchor: dict,
|
|
111
|
+
*,
|
|
112
|
+
sources_enabled: list[str],
|
|
113
|
+
top_k_per_source: int,
|
|
114
|
+
max_total: int,
|
|
115
|
+
preferred_language: str = "any",
|
|
116
|
+
) -> CandidateReport:
|
|
117
|
+
seen_urls: set[str] = set()
|
|
118
|
+
out: list[ImageCandidate] = []
|
|
119
|
+
counts_by_source = dict.fromkeys(sources_enabled, 0)
|
|
120
|
+
failed_queries: list[tuple[str, str, str]] = []
|
|
121
|
+
for source_name in sources_enabled:
|
|
122
|
+
adapter = _SOURCE_REGISTRY.get(source_name)
|
|
123
|
+
if adapter is None:
|
|
124
|
+
failed_queries.append((source_name, "(adapter)", "fonte desconhecida"))
|
|
125
|
+
continue
|
|
126
|
+
for query in anchor["search_queries"]:
|
|
127
|
+
try:
|
|
128
|
+
cs = adapter.search(
|
|
129
|
+
query,
|
|
130
|
+
anchor["visual_type"],
|
|
131
|
+
top_k=top_k_per_source,
|
|
132
|
+
language=preferred_language,
|
|
133
|
+
)
|
|
134
|
+
except SourceQuotaExceeded:
|
|
135
|
+
raise
|
|
136
|
+
except Exception as e:
|
|
137
|
+
failed_queries.append((source_name, query, str(e)))
|
|
138
|
+
continue
|
|
139
|
+
for c in cs:
|
|
140
|
+
if c.image_url in seen_urls:
|
|
141
|
+
continue
|
|
142
|
+
seen_urls.add(c.image_url)
|
|
143
|
+
out.append(c)
|
|
144
|
+
counts_by_source[source_name] += 1
|
|
145
|
+
ranked = quality.rank_candidates_for_rerank(anchor["visual_type"], out)
|
|
146
|
+
return CandidateReport(
|
|
147
|
+
candidates=ranked[:max_total],
|
|
148
|
+
counts_by_source=counts_by_source,
|
|
149
|
+
failed_queries=failed_queries,
|
|
150
|
+
capped=len(ranked) > max_total,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _candidate_image_urls(c: ImageCandidate) -> list[str]:
|
|
155
|
+
urls = [c.image_url]
|
|
156
|
+
thumbnail_url = getattr(c, "thumbnail_url", None)
|
|
157
|
+
if thumbnail_url and thumbnail_url not in urls:
|
|
158
|
+
urls.append(thumbnail_url)
|
|
159
|
+
return urls
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def fetch_thumbs(
|
|
163
|
+
candidates: list[ImageCandidate],
|
|
164
|
+
*,
|
|
165
|
+
tmp_dir: Path,
|
|
166
|
+
user_agent: str | None = None,
|
|
167
|
+
) -> list[Path | None]:
|
|
168
|
+
"""Baixa thumbnails (256px) sem usar cache do projeto. Falha por candidata
|
|
169
|
+
é tolerada — devolve None na posição correspondente."""
|
|
170
|
+
out: list[Path | None] = []
|
|
171
|
+
for i, c in enumerate(candidates):
|
|
172
|
+
thumb_path = None
|
|
173
|
+
last_error = None
|
|
174
|
+
for url in _candidate_image_urls(c):
|
|
175
|
+
try:
|
|
176
|
+
res = download_image(
|
|
177
|
+
url,
|
|
178
|
+
vault_dir=tmp_dir,
|
|
179
|
+
max_dim=256,
|
|
180
|
+
webp_min_savings_pct=0, # sempre WebP nos thumbs
|
|
181
|
+
cache=None,
|
|
182
|
+
source=c.source,
|
|
183
|
+
source_url=c.source_url,
|
|
184
|
+
user_agent=user_agent,
|
|
185
|
+
)
|
|
186
|
+
thumb_path = Path(res["path"])
|
|
187
|
+
break
|
|
188
|
+
except DownloadError as e:
|
|
189
|
+
last_error = e
|
|
190
|
+
if thumb_path is None:
|
|
191
|
+
_log(f" [warn] thumb #{i} falhou: {last_error}", err=True)
|
|
192
|
+
out.append(thumb_path)
|
|
193
|
+
return out
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""CLI entrypoint for the image enrichment workflow."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import time
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from mednotes.domains.wiki.capabilities.illustrate.core.config import load as load_config
|
|
9
|
+
from mednotes.domains.wiki.capabilities.illustrate.core.config import wiki_memory_path
|
|
10
|
+
from mednotes.domains.wiki.flows.enrich.workflow import reporting
|
|
11
|
+
from mednotes.domains.wiki.flows.enrich.workflow.inputs import _resolve_note_inputs
|
|
12
|
+
from mednotes.domains.wiki.flows.enrich.workflow.models import _EXIT_SOURCE_QUOTA, NoteResult
|
|
13
|
+
from mednotes.domains.wiki.flows.enrich.workflow.runner import (
|
|
14
|
+
_log_run_header,
|
|
15
|
+
_print_summary,
|
|
16
|
+
_process_note,
|
|
17
|
+
_resolve_vault,
|
|
18
|
+
)
|
|
19
|
+
from mednotes.domains.wiki.flows.enrich.workflow.utils import _log
|
|
20
|
+
from mednotes.domains.wiki.flows.enrich.workflow.vault_guard_bridge import VaultGuardError, require_enrich_guard
|
|
21
|
+
from mednotes.platform.feedback import command_string, safe_record_workflow_run
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main(argv: list[str] | None = None) -> int:
|
|
25
|
+
started_at = time.time()
|
|
26
|
+
parser = argparse.ArgumentParser(
|
|
27
|
+
prog="enrich_notes",
|
|
28
|
+
description="Orquestrador end-to-end (gemini CLI + enricher toolbox).",
|
|
29
|
+
)
|
|
30
|
+
parser.add_argument(
|
|
31
|
+
"notes",
|
|
32
|
+
nargs="+",
|
|
33
|
+
type=Path,
|
|
34
|
+
help="Caminho(s) da(s) nota(s) .md",
|
|
35
|
+
)
|
|
36
|
+
parser.add_argument("--config", type=Path, default=None)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--force",
|
|
39
|
+
action="store_true",
|
|
40
|
+
help="Re-enriquece mesmo se images_enriched já é true.",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--quality-report",
|
|
44
|
+
type=Path,
|
|
45
|
+
default=None,
|
|
46
|
+
help="Escreve relatório local JSON com fontes, candidatos e razões de aceite/recusa.",
|
|
47
|
+
)
|
|
48
|
+
parser.add_argument(
|
|
49
|
+
"--quality-profile",
|
|
50
|
+
choices=["clinical", "broad"],
|
|
51
|
+
default="clinical",
|
|
52
|
+
help="Perfil de curadoria visual. clinical é estrito; broad preserva comportamento mais permissivo.",
|
|
53
|
+
)
|
|
54
|
+
args = parser.parse_args(argv)
|
|
55
|
+
|
|
56
|
+
cfg = load_config(args.config)
|
|
57
|
+
vault = _resolve_vault(cfg, args.config)
|
|
58
|
+
if vault is None:
|
|
59
|
+
_log(
|
|
60
|
+
f"erro: configure [vault].path no config.toml ou [paths].wiki_dir em {wiki_memory_path()}.",
|
|
61
|
+
err=True,
|
|
62
|
+
)
|
|
63
|
+
safe_record_workflow_run(
|
|
64
|
+
workflow="/mednotes:enrich",
|
|
65
|
+
command=command_string(),
|
|
66
|
+
payload={
|
|
67
|
+
"phase": "enrich_preflight",
|
|
68
|
+
"status": "failed",
|
|
69
|
+
"blocked_reason": "missing_vault_config",
|
|
70
|
+
"next_action": "Configurar [paths].wiki_dir em ~/.mednotes/config.toml ou [vault].path no config.toml e rodar novamente.",
|
|
71
|
+
"required_inputs": ["config", "wiki_dir"],
|
|
72
|
+
},
|
|
73
|
+
exit_code=4,
|
|
74
|
+
started_at=started_at,
|
|
75
|
+
)
|
|
76
|
+
return 4
|
|
77
|
+
|
|
78
|
+
notes, input_errors = _resolve_note_inputs(args.notes)
|
|
79
|
+
for note in notes:
|
|
80
|
+
try:
|
|
81
|
+
require_enrich_guard(note, command="enrich_notes")
|
|
82
|
+
except VaultGuardError as exc:
|
|
83
|
+
payload = exc.to_payload()
|
|
84
|
+
_log(str(payload["human_message"]), err=True)
|
|
85
|
+
safe_record_workflow_run(
|
|
86
|
+
workflow="/mednotes:enrich",
|
|
87
|
+
command=command_string(),
|
|
88
|
+
payload=payload,
|
|
89
|
+
exit_code=exc.exit_code,
|
|
90
|
+
started_at=started_at,
|
|
91
|
+
)
|
|
92
|
+
return exc.exit_code
|
|
93
|
+
_log_run_header(
|
|
94
|
+
cfg=cfg,
|
|
95
|
+
config_path=args.config,
|
|
96
|
+
vault=vault,
|
|
97
|
+
notes_count=len(notes),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
results: list[NoteResult] = list(input_errors)
|
|
101
|
+
for result in input_errors:
|
|
102
|
+
_log(f"erro: {result.message}", err=True)
|
|
103
|
+
for index, note in enumerate(notes, start=1):
|
|
104
|
+
if index > 1:
|
|
105
|
+
_log("")
|
|
106
|
+
result = _process_note(
|
|
107
|
+
note,
|
|
108
|
+
cfg=cfg,
|
|
109
|
+
vault=vault,
|
|
110
|
+
force=args.force,
|
|
111
|
+
index=index,
|
|
112
|
+
total=len(notes),
|
|
113
|
+
quality_profile=args.quality_profile,
|
|
114
|
+
)
|
|
115
|
+
results.append(result)
|
|
116
|
+
if result.code == _EXIT_SOURCE_QUOTA:
|
|
117
|
+
break
|
|
118
|
+
|
|
119
|
+
_print_summary(results)
|
|
120
|
+
if args.quality_report:
|
|
121
|
+
reporting.write_quality_report(args.quality_report, {
|
|
122
|
+
"schema": "medical-notes-workbench.enricher-quality-report.v1",
|
|
123
|
+
"note_count": len(results),
|
|
124
|
+
"quality_profile": args.quality_profile,
|
|
125
|
+
"sources_enabled": cfg["sources"]["enabled"],
|
|
126
|
+
"notes": [
|
|
127
|
+
result.quality_report
|
|
128
|
+
for result in results
|
|
129
|
+
if result.quality_report
|
|
130
|
+
],
|
|
131
|
+
})
|
|
132
|
+
exit_code = 0
|
|
133
|
+
for result in results:
|
|
134
|
+
if result.code != 0:
|
|
135
|
+
exit_code = result.code
|
|
136
|
+
break
|
|
137
|
+
safe_record_workflow_run(
|
|
138
|
+
workflow="/mednotes:enrich",
|
|
139
|
+
command=command_string(),
|
|
140
|
+
payload=_feedback_payload(results, vault=vault, force=args.force),
|
|
141
|
+
exit_code=exit_code,
|
|
142
|
+
started_at=started_at,
|
|
143
|
+
snippets=[result.message for result in results if result.message],
|
|
144
|
+
)
|
|
145
|
+
return exit_code
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _feedback_payload(results: list[NoteResult], *, vault: Path, force: bool) -> dict[str, object]:
|
|
149
|
+
enriched = sum(1 for item in results if item.status == "enriched")
|
|
150
|
+
skipped = sum(1 for item in results if item.status == "skipped")
|
|
151
|
+
no_insert = sum(1 for item in results if item.status == "no_insert")
|
|
152
|
+
failures = [item for item in results if item.code != 0]
|
|
153
|
+
source_counts: dict[str, int] = {}
|
|
154
|
+
for result in results:
|
|
155
|
+
for source, count in result.sources_count.items():
|
|
156
|
+
source_counts[source] = (source_counts[source] if source in source_counts else 0) + count
|
|
157
|
+
return {
|
|
158
|
+
"phase": "enrich_notes",
|
|
159
|
+
"status": "failed" if failures else "completed_with_warnings" if no_insert or skipped else "completed",
|
|
160
|
+
"blocked_reason": "source_quota" if any(item.code == _EXIT_SOURCE_QUOTA for item in failures) else "",
|
|
161
|
+
"next_action": "Revisar falhas e rodar novamente apenas para as notas afetadas." if failures else "",
|
|
162
|
+
"required_inputs": ["notes", "config", "wiki_dir"],
|
|
163
|
+
"vault_dir": str(vault),
|
|
164
|
+
"force": force,
|
|
165
|
+
"quality_reports_available": any(item.quality_report for item in results),
|
|
166
|
+
"summary": {
|
|
167
|
+
"note_count": len(results),
|
|
168
|
+
"enriched_count": enriched,
|
|
169
|
+
"skipped_count": skipped,
|
|
170
|
+
"no_insert_count": no_insert,
|
|
171
|
+
"failure_count": len(failures),
|
|
172
|
+
"inserted_count": sum(item.inserted_count for item in results),
|
|
173
|
+
},
|
|
174
|
+
"source_counts": source_counts,
|
|
175
|
+
"notes": [
|
|
176
|
+
{
|
|
177
|
+
"path": str(item.note),
|
|
178
|
+
"status": item.status,
|
|
179
|
+
"inserted_count": item.inserted_count,
|
|
180
|
+
"code": item.code,
|
|
181
|
+
}
|
|
182
|
+
for item in results
|
|
183
|
+
],
|
|
184
|
+
"errors": [item.message for item in failures if item.message],
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
if __name__ == "__main__":
|
|
189
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""Gemini CLI seam for image enrichment."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import tempfile
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import TypeVar
|
|
12
|
+
|
|
13
|
+
from mednotes.domains.wiki.flows.enrich.workflow.models import _DEFAULT_GEMINI_TIMEOUT_SECONDS, GeminiError
|
|
14
|
+
|
|
15
|
+
_WINDOWS_PROMPT_FILE_THRESHOLD = 6000
|
|
16
|
+
ParsedGeminiJsonT = TypeVar("ParsedGeminiJsonT")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _resolve_gemini_binary(binary: str) -> str:
|
|
20
|
+
"""Resolve o executável do Gemini CLI de forma portável.
|
|
21
|
+
|
|
22
|
+
No Windows, o Gemini instalado por npm costuma existir como `gemini.cmd`
|
|
23
|
+
em `%APPDATA%\npm`. `subprocess` com `shell=False` nem sempre resolve esse
|
|
24
|
+
shim quando o config diz só `gemini`, então normalizamos antes de montar o
|
|
25
|
+
comando.
|
|
26
|
+
"""
|
|
27
|
+
expanded = os.path.expandvars(os.path.expanduser(binary))
|
|
28
|
+
if _is_pathish(expanded):
|
|
29
|
+
return expanded
|
|
30
|
+
|
|
31
|
+
found = shutil.which(expanded)
|
|
32
|
+
if found:
|
|
33
|
+
return found
|
|
34
|
+
|
|
35
|
+
if expanded.lower() in {"gemini", "gemini.cmd"}:
|
|
36
|
+
for candidate in _npm_gemini_candidates():
|
|
37
|
+
if candidate.is_file():
|
|
38
|
+
return str(candidate)
|
|
39
|
+
|
|
40
|
+
return expanded
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _is_pathish(value: str) -> bool:
|
|
44
|
+
return (
|
|
45
|
+
"/" in value
|
|
46
|
+
or "\\" in value
|
|
47
|
+
or (len(value) >= 2 and value[1] == ":")
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _npm_gemini_candidates() -> list[Path]:
|
|
52
|
+
candidates: list[Path] = []
|
|
53
|
+
appdata = os.environ.get("APPDATA")
|
|
54
|
+
if appdata:
|
|
55
|
+
candidates.append(Path(appdata) / "npm" / "gemini.cmd")
|
|
56
|
+
prefix = os.environ.get("NPM_CONFIG_PREFIX")
|
|
57
|
+
if prefix:
|
|
58
|
+
prefix_path = Path(prefix)
|
|
59
|
+
candidates.extend(
|
|
60
|
+
[
|
|
61
|
+
prefix_path / "gemini.cmd",
|
|
62
|
+
prefix_path / "bin" / "gemini",
|
|
63
|
+
]
|
|
64
|
+
)
|
|
65
|
+
return candidates
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _invoke_gemini(
|
|
69
|
+
cmd: list[str],
|
|
70
|
+
*,
|
|
71
|
+
timeout_seconds: int = _DEFAULT_GEMINI_TIMEOUT_SECONDS,
|
|
72
|
+
) -> str:
|
|
73
|
+
"""Roda o gemini CLI e devolve stdout. Levanta GeminiError em rc != 0.
|
|
74
|
+
|
|
75
|
+
Seam pra teste: monkeypatch isso pra fingir respostas.
|
|
76
|
+
"""
|
|
77
|
+
try:
|
|
78
|
+
proc = subprocess.run(
|
|
79
|
+
_subprocess_command(cmd),
|
|
80
|
+
capture_output=True,
|
|
81
|
+
text=True,
|
|
82
|
+
check=False,
|
|
83
|
+
timeout=timeout_seconds,
|
|
84
|
+
)
|
|
85
|
+
except subprocess.TimeoutExpired as e:
|
|
86
|
+
raise GeminiError(
|
|
87
|
+
f"gemini CLI excedeu timeout de {timeout_seconds}s"
|
|
88
|
+
) from e
|
|
89
|
+
except FileNotFoundError as e:
|
|
90
|
+
raise GeminiError(
|
|
91
|
+
"gemini CLI não encontrado. Configure [gemini].binary com o caminho "
|
|
92
|
+
"do executável, ou garanta que `gemini`/`gemini.cmd` esteja no PATH."
|
|
93
|
+
) from e
|
|
94
|
+
except OSError as e:
|
|
95
|
+
raise GeminiError(f"gemini CLI não pôde ser iniciado: {e}") from e
|
|
96
|
+
if proc.returncode != 0:
|
|
97
|
+
raise GeminiError(
|
|
98
|
+
f"gemini CLI falhou (rc={proc.returncode}): {proc.stderr.strip()}"
|
|
99
|
+
)
|
|
100
|
+
return proc.stdout
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _subprocess_command(cmd: list[str]) -> list[str]:
|
|
104
|
+
if not cmd:
|
|
105
|
+
return cmd
|
|
106
|
+
executable = cmd[0]
|
|
107
|
+
suffix = Path(executable).suffix.lower()
|
|
108
|
+
if os.name == "nt" and suffix in {".cmd", ".bat"}:
|
|
109
|
+
comspec = os.environ.get("COMSPEC") or "cmd.exe"
|
|
110
|
+
return [comspec, "/d", "/s", "/c", *cmd]
|
|
111
|
+
return cmd
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def call_gemini(
|
|
115
|
+
prompt: str,
|
|
116
|
+
*,
|
|
117
|
+
binary: str,
|
|
118
|
+
model: str | None = None,
|
|
119
|
+
include_dirs: list[Path] | None = None,
|
|
120
|
+
skip_trust: bool = True,
|
|
121
|
+
timeout_seconds: int = _DEFAULT_GEMINI_TIMEOUT_SECONDS,
|
|
122
|
+
) -> str:
|
|
123
|
+
"""Chama o gemini CLI em modo headless. Multimodal via `@arquivo` no
|
|
124
|
+
próprio prompt + `--include-directories` pra dar acesso ao path."""
|
|
125
|
+
cmd = _base_gemini_command(
|
|
126
|
+
binary=binary,
|
|
127
|
+
model=model,
|
|
128
|
+
include_dirs=include_dirs,
|
|
129
|
+
skip_trust=skip_trust,
|
|
130
|
+
)
|
|
131
|
+
if _prompt_needs_file(prompt):
|
|
132
|
+
return _invoke_gemini_with_prompt_file(cmd, prompt, timeout_seconds=timeout_seconds)
|
|
133
|
+
cmd.extend(["-p", prompt])
|
|
134
|
+
return _invoke_gemini(cmd, timeout_seconds=timeout_seconds)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def _base_gemini_command(
|
|
138
|
+
*,
|
|
139
|
+
binary: str,
|
|
140
|
+
model: str | None,
|
|
141
|
+
include_dirs: list[Path] | None,
|
|
142
|
+
skip_trust: bool,
|
|
143
|
+
) -> list[str]:
|
|
144
|
+
cmd: list[str] = [_resolve_gemini_binary(binary)]
|
|
145
|
+
if skip_trust:
|
|
146
|
+
cmd.append("--skip-trust")
|
|
147
|
+
if include_dirs:
|
|
148
|
+
for d in include_dirs:
|
|
149
|
+
cmd.extend(["--include-directories", str(d)])
|
|
150
|
+
if model:
|
|
151
|
+
cmd.extend(["-m", model])
|
|
152
|
+
return cmd
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _prompt_needs_file(prompt: str) -> bool:
|
|
156
|
+
return os.name == "nt" and len(prompt) >= _WINDOWS_PROMPT_FILE_THRESHOLD
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _invoke_gemini_with_prompt_file(cmd: list[str], prompt: str, *, timeout_seconds: int) -> str:
|
|
160
|
+
with tempfile.TemporaryDirectory(prefix="mednotes-gemini-") as tmp:
|
|
161
|
+
prompt_path = Path(tmp) / "prompt.md"
|
|
162
|
+
prompt_path.write_text(prompt, encoding="utf-8")
|
|
163
|
+
file_cmd = [
|
|
164
|
+
*cmd,
|
|
165
|
+
"--include-directories",
|
|
166
|
+
str(prompt_path.parent),
|
|
167
|
+
"-p",
|
|
168
|
+
f"@{prompt_path}",
|
|
169
|
+
]
|
|
170
|
+
return _invoke_gemini(file_cmd, timeout_seconds=timeout_seconds)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def call_gemini_json_with_retry(
|
|
174
|
+
prompt: str,
|
|
175
|
+
parser: Callable[[str], ParsedGeminiJsonT],
|
|
176
|
+
*,
|
|
177
|
+
binary: str,
|
|
178
|
+
model: str | None = None,
|
|
179
|
+
include_dirs: list[Path] | None = None,
|
|
180
|
+
timeout_seconds: int = _DEFAULT_GEMINI_TIMEOUT_SECONDS,
|
|
181
|
+
skip_trust: bool = True,
|
|
182
|
+
label: str,
|
|
183
|
+
) -> tuple[ParsedGeminiJsonT, str]:
|
|
184
|
+
"""Chama o Gemini e dá uma chance de autocorreção quando ele responde
|
|
185
|
+
prose em vez do JSON contratado."""
|
|
186
|
+
raw = call_gemini(
|
|
187
|
+
prompt,
|
|
188
|
+
binary=binary,
|
|
189
|
+
model=model,
|
|
190
|
+
include_dirs=include_dirs,
|
|
191
|
+
skip_trust=skip_trust,
|
|
192
|
+
timeout_seconds=timeout_seconds,
|
|
193
|
+
)
|
|
194
|
+
try:
|
|
195
|
+
return parser(raw), raw
|
|
196
|
+
except (json.JSONDecodeError, ValueError) as first_error:
|
|
197
|
+
retry_prompt = (
|
|
198
|
+
"Sua resposta anterior para a tarefa abaixo foi inválida: "
|
|
199
|
+
f"{first_error}.\n\n"
|
|
200
|
+
"Responda novamente com APENAS JSON válido, sem comentários, sem Markdown, "
|
|
201
|
+
"sem texto antes ou depois.\n\n"
|
|
202
|
+
"TAREFA ORIGINAL:\n"
|
|
203
|
+
f"{prompt}\n\n"
|
|
204
|
+
"RESPOSTA ANTERIOR INVÁLIDA:\n"
|
|
205
|
+
f"{raw}"
|
|
206
|
+
)
|
|
207
|
+
retry_raw = call_gemini(
|
|
208
|
+
retry_prompt,
|
|
209
|
+
binary=binary,
|
|
210
|
+
model=model,
|
|
211
|
+
include_dirs=include_dirs,
|
|
212
|
+
skip_trust=skip_trust,
|
|
213
|
+
timeout_seconds=timeout_seconds,
|
|
214
|
+
)
|
|
215
|
+
try:
|
|
216
|
+
return parser(retry_raw), retry_raw
|
|
217
|
+
except (json.JSONDecodeError, ValueError) as retry_error:
|
|
218
|
+
raise ValueError(
|
|
219
|
+
f"{label} inválido após retry: {retry_error}"
|
|
220
|
+
) from retry_error
|