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,359 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Validate Anki note model fields captured from Anki MCP calls.
|
|
3
|
+
|
|
4
|
+
The agent still calls `mcp_anki-mcp_modelNames` and
|
|
5
|
+
`mcp_anki-mcp_modelFieldNames`. This script validates the collected result in a
|
|
6
|
+
small, testable contract before any card write.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
import sys
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Literal
|
|
15
|
+
|
|
16
|
+
from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, field_validator, model_validator
|
|
17
|
+
from pydantic import ValidationError as PydanticValidationError
|
|
18
|
+
from typing_extensions import TypeAliasType
|
|
19
|
+
|
|
20
|
+
SCHEMA = "medical-notes-workbench.anki-model-validation.v1"
|
|
21
|
+
SET_SCHEMA = "medical-notes-workbench.anki-model-set-validation.v1"
|
|
22
|
+
DEFAULT_REQUIRED_FIELDS = ("Frente", "Verso", "Verso Extra", "Obsidian")
|
|
23
|
+
QA_REQUIRED_FIELDS = ("Frente", "Verso", "Verso Extra", "Obsidian")
|
|
24
|
+
CLOZE_REQUIRED_FIELDS = ("Texto", "Verso Extra", "Obsidian")
|
|
25
|
+
DEFAULT_QA_MODEL = "Medicina"
|
|
26
|
+
DEFAULT_CLOZE_MODEL = "Medicina Cloze"
|
|
27
|
+
|
|
28
|
+
EXIT_OK = 0
|
|
29
|
+
EXIT_USAGE = 2
|
|
30
|
+
EXIT_VALIDATION = 3
|
|
31
|
+
EXIT_IO = 5
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ValidatorError(Exception):
|
|
35
|
+
exit_code = EXIT_IO
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class UsageError(ValidatorError):
|
|
39
|
+
exit_code = EXIT_USAGE
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ValidationError(ValidatorError):
|
|
43
|
+
exit_code = EXIT_VALIDATION
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
JsonValue = TypeAliasType(
|
|
47
|
+
"JsonValue",
|
|
48
|
+
str | int | float | bool | None | list["JsonValue"] | dict[str, "JsonValue"],
|
|
49
|
+
)
|
|
50
|
+
JsonObject = dict[str, JsonValue]
|
|
51
|
+
JsonValueAdapter = TypeAdapter(JsonValue)
|
|
52
|
+
JsonObjectAdapter = TypeAdapter(JsonObject)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class _ContractModel(BaseModel):
|
|
56
|
+
# This CLI consumes raw Anki MCP JSON, but workflow decisions use only these
|
|
57
|
+
# normalized fields after validation.
|
|
58
|
+
model_config = ConfigDict(extra="ignore", populate_by_name=True, validate_assignment=True)
|
|
59
|
+
|
|
60
|
+
def to_payload(self) -> JsonObject:
|
|
61
|
+
return _json_object(self.model_dump(mode="json", by_alias=True), prefix=type(self).__name__)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class _AnkiModelEntry(_ContractModel):
|
|
65
|
+
name: str
|
|
66
|
+
fields: list[str] = Field(default_factory=list)
|
|
67
|
+
|
|
68
|
+
@field_validator("name", mode="before")
|
|
69
|
+
@classmethod
|
|
70
|
+
def _name_as_text(cls, value: object) -> str:
|
|
71
|
+
return "" if value is None else str(value)
|
|
72
|
+
|
|
73
|
+
@field_validator("fields", mode="before")
|
|
74
|
+
@classmethod
|
|
75
|
+
def _fields_as_text_list(cls, value: object) -> list[str]:
|
|
76
|
+
if not isinstance(value, list):
|
|
77
|
+
raise ValueError("fields must be a list")
|
|
78
|
+
return [str(field) for field in value]
|
|
79
|
+
|
|
80
|
+
@model_validator(mode="after")
|
|
81
|
+
def _requires_name(self) -> _AnkiModelEntry:
|
|
82
|
+
if not self.name:
|
|
83
|
+
raise ValueError("model name must be non-empty")
|
|
84
|
+
return self
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class _AnkiModelsPayload(_ContractModel):
|
|
88
|
+
models: list[_AnkiModelEntry] = Field(default_factory=list)
|
|
89
|
+
|
|
90
|
+
@model_validator(mode="before")
|
|
91
|
+
@classmethod
|
|
92
|
+
def _accept_mcp_shapes(cls, value: object) -> object:
|
|
93
|
+
if not isinstance(value, dict):
|
|
94
|
+
return value
|
|
95
|
+
if "models" in value:
|
|
96
|
+
return value
|
|
97
|
+
models: list[JsonObject] = []
|
|
98
|
+
for name, fields in value.items():
|
|
99
|
+
models.append({"name": str(name), "fields": JsonValueAdapter.validate_python(fields)})
|
|
100
|
+
return {"models": models}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class _CheckedModel(_ContractModel):
|
|
104
|
+
name: str
|
|
105
|
+
fields: list[str] = Field(default_factory=list)
|
|
106
|
+
missing_fields: list[str] = Field(default_factory=list)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class _ModelValidationResult(_ContractModel):
|
|
110
|
+
schema_id: Literal["medical-notes-workbench.anki-model-validation.v1"] = Field(
|
|
111
|
+
default=SCHEMA,
|
|
112
|
+
alias="schema",
|
|
113
|
+
)
|
|
114
|
+
ok: bool
|
|
115
|
+
model: str = ""
|
|
116
|
+
fields: list[str] = Field(default_factory=list)
|
|
117
|
+
required_fields: list[str] = Field(default_factory=list)
|
|
118
|
+
checked_models: list[_CheckedModel] = Field(default_factory=list)
|
|
119
|
+
warning: str = ""
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class _ResolvedModel(_ContractModel):
|
|
123
|
+
model: str = ""
|
|
124
|
+
fields: list[str] = Field(default_factory=list)
|
|
125
|
+
required_fields: list[str] = Field(default_factory=list)
|
|
126
|
+
ok: bool
|
|
127
|
+
checked_models: list[_CheckedModel] = Field(default_factory=list)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class _ModelSetValidationResult(_ContractModel):
|
|
131
|
+
schema_id: Literal["medical-notes-workbench.anki-model-set-validation.v1"] = Field(
|
|
132
|
+
default=SET_SCHEMA,
|
|
133
|
+
alias="schema",
|
|
134
|
+
)
|
|
135
|
+
ok: bool
|
|
136
|
+
missing_kinds: list[str] = Field(default_factory=list)
|
|
137
|
+
qa: _ResolvedModel
|
|
138
|
+
cloze: _ResolvedModel
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _validation_message(exc: PydanticValidationError, *, prefix: str) -> UsageError:
|
|
142
|
+
first = exc.errors()[0] if exc.errors() else {}
|
|
143
|
+
loc_parts = first["loc"] if "loc" in first else ()
|
|
144
|
+
loc = ".".join(str(part) for part in loc_parts) or "$"
|
|
145
|
+
msg = str(first["msg"] if "msg" in first else str(exc))
|
|
146
|
+
return UsageError(f"{prefix}: {loc}: {msg}")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _json_object(value: object, *, prefix: str) -> JsonObject:
|
|
150
|
+
try:
|
|
151
|
+
return JsonObjectAdapter.validate_python(value)
|
|
152
|
+
except PydanticValidationError as exc:
|
|
153
|
+
raise _validation_message(exc, prefix=prefix) from exc
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _read_json(path: str) -> JsonValue:
|
|
157
|
+
if path == "-":
|
|
158
|
+
raw = json.loads(sys.stdin.read())
|
|
159
|
+
else:
|
|
160
|
+
with Path(path).open("r", encoding="utf-8") as fh:
|
|
161
|
+
raw = json.load(fh)
|
|
162
|
+
try:
|
|
163
|
+
return JsonValueAdapter.validate_python(raw)
|
|
164
|
+
except PydanticValidationError as exc:
|
|
165
|
+
raise _validation_message(exc, prefix=f"JSON payload {path}") from exc
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _json(data: object) -> None:
|
|
169
|
+
print(json.dumps(data, ensure_ascii=False, indent=2, sort_keys=True))
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _models_from_payload(payload: object) -> list[_AnkiModelEntry]:
|
|
173
|
+
if not isinstance(payload, dict):
|
|
174
|
+
raise UsageError("Expected JSON object with models list, or {model_name: fields} map")
|
|
175
|
+
try:
|
|
176
|
+
return _AnkiModelsPayload.model_validate(payload).models
|
|
177
|
+
except PydanticValidationError as exc:
|
|
178
|
+
raise _validation_message(exc, prefix="Anki model payload") from exc
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _validate_models_result(
|
|
182
|
+
payload: object,
|
|
183
|
+
*,
|
|
184
|
+
required_fields: tuple[str, ...] = DEFAULT_REQUIRED_FIELDS,
|
|
185
|
+
preferred_model: str | None = None,
|
|
186
|
+
) -> _ModelValidationResult:
|
|
187
|
+
models = _models_from_payload(payload)
|
|
188
|
+
checked: list[_CheckedModel] = []
|
|
189
|
+
|
|
190
|
+
ordered = models
|
|
191
|
+
if preferred_model:
|
|
192
|
+
ordered = sorted(models, key=lambda item: item.name != preferred_model)
|
|
193
|
+
|
|
194
|
+
for model in ordered:
|
|
195
|
+
fields = set(model.fields)
|
|
196
|
+
missing = [field for field in required_fields if field not in fields]
|
|
197
|
+
record = _CheckedModel(name=model.name, fields=model.fields, missing_fields=missing)
|
|
198
|
+
checked.append(record)
|
|
199
|
+
if not missing and (preferred_model is None or model.name == preferred_model or not preferred_model):
|
|
200
|
+
return _ModelValidationResult(
|
|
201
|
+
ok=True,
|
|
202
|
+
model=model.name,
|
|
203
|
+
fields=model.fields,
|
|
204
|
+
required_fields=list(required_fields),
|
|
205
|
+
checked_models=checked,
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
compatible = [record for record in checked if not record.missing_fields]
|
|
209
|
+
if compatible and preferred_model:
|
|
210
|
+
chosen = compatible[0]
|
|
211
|
+
return _ModelValidationResult(
|
|
212
|
+
ok=True,
|
|
213
|
+
model=chosen.name,
|
|
214
|
+
fields=chosen.fields,
|
|
215
|
+
required_fields=list(required_fields),
|
|
216
|
+
checked_models=checked,
|
|
217
|
+
warning=f"Preferred model {preferred_model!r} is missing required fields; using {chosen.name!r}.",
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
return _ModelValidationResult(
|
|
221
|
+
ok=False,
|
|
222
|
+
model="",
|
|
223
|
+
fields=[],
|
|
224
|
+
required_fields=list(required_fields),
|
|
225
|
+
checked_models=checked,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def validate_models(
|
|
230
|
+
payload: object,
|
|
231
|
+
*,
|
|
232
|
+
required_fields: tuple[str, ...] = DEFAULT_REQUIRED_FIELDS,
|
|
233
|
+
preferred_model: str | None = None,
|
|
234
|
+
) -> JsonObject:
|
|
235
|
+
return _validate_models_result(
|
|
236
|
+
payload,
|
|
237
|
+
required_fields=required_fields,
|
|
238
|
+
preferred_model=preferred_model,
|
|
239
|
+
).to_payload()
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def validate_model_set(
|
|
243
|
+
payload: object,
|
|
244
|
+
*,
|
|
245
|
+
qa_required_fields: tuple[str, ...] = QA_REQUIRED_FIELDS,
|
|
246
|
+
cloze_required_fields: tuple[str, ...] = CLOZE_REQUIRED_FIELDS,
|
|
247
|
+
preferred_qa_model: str | None = DEFAULT_QA_MODEL,
|
|
248
|
+
preferred_cloze_model: str | None = DEFAULT_CLOZE_MODEL,
|
|
249
|
+
) -> JsonObject:
|
|
250
|
+
"""Valida o par Q&A + Cloze a partir de um único payload de modelos.
|
|
251
|
+
|
|
252
|
+
O payload aceita as mesmas formas que `validate_models`: dict
|
|
253
|
+
`{nome: [campos]}`, ou `{ "models": [{"name": ..., "fields": [...]}] }`.
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
qa_result = _validate_models_result(
|
|
257
|
+
payload,
|
|
258
|
+
required_fields=qa_required_fields,
|
|
259
|
+
preferred_model=preferred_qa_model,
|
|
260
|
+
)
|
|
261
|
+
cloze_result = _validate_models_result(
|
|
262
|
+
payload,
|
|
263
|
+
required_fields=cloze_required_fields,
|
|
264
|
+
preferred_model=preferred_cloze_model,
|
|
265
|
+
)
|
|
266
|
+
ok = qa_result.ok and cloze_result.ok
|
|
267
|
+
missing_kinds = [
|
|
268
|
+
kind
|
|
269
|
+
for kind, result in (("qa", qa_result), ("cloze", cloze_result))
|
|
270
|
+
if not result.ok
|
|
271
|
+
]
|
|
272
|
+
result = _ModelSetValidationResult(
|
|
273
|
+
ok=ok,
|
|
274
|
+
missing_kinds=missing_kinds,
|
|
275
|
+
qa=_ResolvedModel(
|
|
276
|
+
model=qa_result.model,
|
|
277
|
+
fields=qa_result.fields,
|
|
278
|
+
required_fields=list(qa_required_fields),
|
|
279
|
+
ok=qa_result.ok,
|
|
280
|
+
checked_models=qa_result.checked_models,
|
|
281
|
+
),
|
|
282
|
+
cloze=_ResolvedModel(
|
|
283
|
+
model=cloze_result.model,
|
|
284
|
+
fields=cloze_result.fields,
|
|
285
|
+
required_fields=list(cloze_required_fields),
|
|
286
|
+
ok=cloze_result.ok,
|
|
287
|
+
checked_models=cloze_result.checked_models,
|
|
288
|
+
),
|
|
289
|
+
)
|
|
290
|
+
return result.to_payload()
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _cmd_validate(args: argparse.Namespace) -> int:
|
|
294
|
+
required_fields = tuple(args.required_field or DEFAULT_REQUIRED_FIELDS)
|
|
295
|
+
result = validate_models(
|
|
296
|
+
_read_json(args.models_json),
|
|
297
|
+
required_fields=required_fields,
|
|
298
|
+
preferred_model=args.preferred_model,
|
|
299
|
+
)
|
|
300
|
+
_json(result)
|
|
301
|
+
if not result["ok"]:
|
|
302
|
+
return EXIT_VALIDATION
|
|
303
|
+
return EXIT_OK
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
307
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
308
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
309
|
+
|
|
310
|
+
validate = sub.add_parser("validate", help="validate captured model fields")
|
|
311
|
+
validate.add_argument("--models-json", required=True, help="model fields JSON file, or '-' for stdin")
|
|
312
|
+
validate.add_argument("--preferred-model", help="preferred Anki model name")
|
|
313
|
+
validate.add_argument(
|
|
314
|
+
"--required-field",
|
|
315
|
+
action="append",
|
|
316
|
+
default=None,
|
|
317
|
+
help="required field name; repeatable",
|
|
318
|
+
)
|
|
319
|
+
validate.set_defaults(func=_cmd_validate)
|
|
320
|
+
|
|
321
|
+
validate_set = sub.add_parser(
|
|
322
|
+
"validate-set",
|
|
323
|
+
help="valida em conjunto os modelos Q&A e Cloze",
|
|
324
|
+
)
|
|
325
|
+
validate_set.add_argument(
|
|
326
|
+
"--models-json", required=True, help="modelos capturados do Anki, ou '-' para stdin"
|
|
327
|
+
)
|
|
328
|
+
validate_set.add_argument("--qa-model", default=DEFAULT_QA_MODEL)
|
|
329
|
+
validate_set.add_argument("--cloze-model", default=DEFAULT_CLOZE_MODEL)
|
|
330
|
+
validate_set.set_defaults(func=_cmd_validate_set)
|
|
331
|
+
|
|
332
|
+
return parser
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _cmd_validate_set(args: argparse.Namespace) -> int:
|
|
336
|
+
result = validate_model_set(
|
|
337
|
+
_read_json(args.models_json),
|
|
338
|
+
preferred_qa_model=args.qa_model,
|
|
339
|
+
preferred_cloze_model=args.cloze_model,
|
|
340
|
+
)
|
|
341
|
+
_json(result)
|
|
342
|
+
return EXIT_OK if result["ok"] else EXIT_VALIDATION
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def main(argv: list[str] | None = None) -> int:
|
|
346
|
+
parser = build_parser()
|
|
347
|
+
args = parser.parse_args(argv)
|
|
348
|
+
try:
|
|
349
|
+
return args.func(args)
|
|
350
|
+
except ValidatorError as exc:
|
|
351
|
+
print(str(exc), file=sys.stderr)
|
|
352
|
+
return exc.exit_code
|
|
353
|
+
except (OSError, json.JSONDecodeError) as exc:
|
|
354
|
+
print(str(exc), file=sys.stderr)
|
|
355
|
+
return EXIT_IO
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
if __name__ == "__main__":
|
|
359
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from enum import StrEnum
|
|
4
|
+
from urllib.parse import quote
|
|
5
|
+
|
|
6
|
+
from pydantic import Field, field_validator
|
|
7
|
+
|
|
8
|
+
from mednotes.kernel.base import ContractModel
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ObsidianPathStyle(StrEnum):
|
|
12
|
+
POSIX = "posix"
|
|
13
|
+
WINDOWS_DRIVE = "windows_drive"
|
|
14
|
+
WINDOWS_UNC = "windows_unc"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ObsidianLinkMode(StrEnum):
|
|
18
|
+
VAULT_FILE = "vault_file"
|
|
19
|
+
ABSOLUTE_PATH = "absolute_path"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ObsidianLinkCandidate(ContractModel):
|
|
23
|
+
mode: ObsidianLinkMode
|
|
24
|
+
uri: str
|
|
25
|
+
|
|
26
|
+
@field_validator("uri")
|
|
27
|
+
@classmethod
|
|
28
|
+
def _non_empty(cls, value: str) -> str:
|
|
29
|
+
cleaned = value.strip()
|
|
30
|
+
if not cleaned:
|
|
31
|
+
raise ValueError("value must be non-empty")
|
|
32
|
+
return cleaned
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ObsidianLinkBuildResult(ContractModel):
|
|
36
|
+
selected: ObsidianLinkCandidate
|
|
37
|
+
candidates: list[ObsidianLinkCandidate] = Field(default_factory=list)
|
|
38
|
+
path_style: ObsidianPathStyle
|
|
39
|
+
absolute_path: str
|
|
40
|
+
vault_name: str = ""
|
|
41
|
+
vault_relative_path: str = ""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def detect_path_style(path_text: str) -> ObsidianPathStyle:
|
|
45
|
+
if path_text.startswith("\\\\"):
|
|
46
|
+
return ObsidianPathStyle.WINDOWS_UNC
|
|
47
|
+
if len(path_text) >= 3 and path_text[0].isalpha() and path_text[1:3] in {":\\", ":/"}:
|
|
48
|
+
return ObsidianPathStyle.WINDOWS_DRIVE
|
|
49
|
+
return ObsidianPathStyle.POSIX
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def to_vault_relative_posix(value: str) -> str:
|
|
53
|
+
return value.replace("\\", "/").strip("/")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _absolute_path_uri(absolute_path: str) -> str:
|
|
57
|
+
return f"obsidian://open?path={quote(absolute_path, safe='')}"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _vault_file_uri(vault_name: str, vault_relative_path: str) -> str:
|
|
61
|
+
return (
|
|
62
|
+
"obsidian://open?"
|
|
63
|
+
f"vault={quote(vault_name, safe='')}"
|
|
64
|
+
f"&file={quote(to_vault_relative_posix(vault_relative_path), safe='')}"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def build_obsidian_link_result(
|
|
69
|
+
*,
|
|
70
|
+
absolute_path: str,
|
|
71
|
+
path_style: ObsidianPathStyle | str = "",
|
|
72
|
+
vault_name: str = "",
|
|
73
|
+
vault_relative_path: str = "",
|
|
74
|
+
) -> ObsidianLinkBuildResult:
|
|
75
|
+
cleaned_absolute = absolute_path.strip()
|
|
76
|
+
if not cleaned_absolute:
|
|
77
|
+
raise ValueError("absolute_path must be non-empty")
|
|
78
|
+
|
|
79
|
+
style = ObsidianPathStyle(path_style or detect_path_style(cleaned_absolute))
|
|
80
|
+
cleaned_vault_name = vault_name.strip()
|
|
81
|
+
cleaned_relative_path = (
|
|
82
|
+
to_vault_relative_posix(vault_relative_path.strip()) if vault_relative_path.strip() else ""
|
|
83
|
+
)
|
|
84
|
+
candidates: list[ObsidianLinkCandidate] = []
|
|
85
|
+
if cleaned_vault_name and cleaned_relative_path:
|
|
86
|
+
candidates.append(
|
|
87
|
+
ObsidianLinkCandidate(
|
|
88
|
+
mode=ObsidianLinkMode.VAULT_FILE,
|
|
89
|
+
uri=_vault_file_uri(cleaned_vault_name, cleaned_relative_path),
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
candidates.append(
|
|
93
|
+
ObsidianLinkCandidate(
|
|
94
|
+
mode=ObsidianLinkMode.ABSOLUTE_PATH,
|
|
95
|
+
uri=_absolute_path_uri(cleaned_absolute),
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
return ObsidianLinkBuildResult(
|
|
99
|
+
selected=candidates[0],
|
|
100
|
+
candidates=candidates,
|
|
101
|
+
path_style=style,
|
|
102
|
+
absolute_path=cleaned_absolute,
|
|
103
|
+
vault_name=cleaned_vault_name,
|
|
104
|
+
vault_relative_path=cleaned_relative_path,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def build_obsidian_link_candidates(
|
|
109
|
+
*,
|
|
110
|
+
absolute_path: str,
|
|
111
|
+
path_style: ObsidianPathStyle | str = "",
|
|
112
|
+
vault_name: str = "",
|
|
113
|
+
vault_relative_path: str = "",
|
|
114
|
+
) -> list[ObsidianLinkCandidate]:
|
|
115
|
+
return build_obsidian_link_result(
|
|
116
|
+
absolute_path=absolute_path,
|
|
117
|
+
path_style=path_style,
|
|
118
|
+
vault_name=vault_name,
|
|
119
|
+
vault_relative_path=vault_relative_path,
|
|
120
|
+
).candidates
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def build_obsidian_deeplink(
|
|
124
|
+
*,
|
|
125
|
+
absolute_path: str,
|
|
126
|
+
path_style: ObsidianPathStyle | str = "",
|
|
127
|
+
vault_name: str = "",
|
|
128
|
+
vault_relative_path: str = "",
|
|
129
|
+
) -> str:
|
|
130
|
+
return build_obsidian_link_result(
|
|
131
|
+
absolute_path=absolute_path,
|
|
132
|
+
path_style=path_style,
|
|
133
|
+
vault_name=vault_name,
|
|
134
|
+
vault_relative_path=vault_relative_path,
|
|
135
|
+
).selected.uri
|