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,546 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic Obsidian note metadata helpers for Gemini extension agents.
|
|
3
|
+
|
|
4
|
+
The flashcard agent owns card reasoning. This script owns small, auditable note
|
|
5
|
+
metadata operations: creating Obsidian deeplinks and adding/removing frontmatter
|
|
6
|
+
tags after Anki writes succeed.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import argparse
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import re
|
|
14
|
+
import sys
|
|
15
|
+
import tempfile
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
from typing import Literal
|
|
18
|
+
from urllib.parse import quote
|
|
19
|
+
|
|
20
|
+
from pydantic import BaseModel, ConfigDict, Field, ValidationError, model_validator
|
|
21
|
+
|
|
22
|
+
from mednotes.domains.flashcards.contracts import FlashcardsTaggingReceipt, FlashcardsVaultGuardReceipt
|
|
23
|
+
from mednotes.platform.paths import resolve_wiki_dir
|
|
24
|
+
|
|
25
|
+
EXIT_OK = 0
|
|
26
|
+
EXIT_USAGE = 2
|
|
27
|
+
EXIT_MISSING = 4
|
|
28
|
+
EXIT_IO = 5
|
|
29
|
+
|
|
30
|
+
_DELIM = "---"
|
|
31
|
+
_TAG_KEY_RE = re.compile(r"^(?P<indent>\s*)(?P<key>tags?|Tags?)\s*:\s*(?P<value>.*)$")
|
|
32
|
+
_LIST_ITEM_RE = re.compile(r"^\s*-\s*(?P<value>.*?)\s*$")
|
|
33
|
+
_VALID_TAG_RE = re.compile(r"^[A-Za-z0-9_/-]+$")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class NoteUtilsError(Exception):
|
|
37
|
+
exit_code = EXIT_IO
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class UsageError(NoteUtilsError):
|
|
41
|
+
exit_code = EXIT_USAGE
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class MissingPathError(NoteUtilsError):
|
|
45
|
+
exit_code = EXIT_MISSING
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class FlashcardsTagAuthorization(BaseModel):
|
|
49
|
+
"""Typed guard proving an Obsidian tag write came from the FSM effect path."""
|
|
50
|
+
|
|
51
|
+
model_config = ConfigDict(extra="forbid", strict=True)
|
|
52
|
+
|
|
53
|
+
effect_target: Literal["flashcards.tag_obsidian"]
|
|
54
|
+
receipt_path: Path
|
|
55
|
+
workflow: Literal["/flashcards"]
|
|
56
|
+
effect_kind: Literal["run_subworkflow"]
|
|
57
|
+
receipt_effect_target: Literal["flashcards.tag_obsidian"]
|
|
58
|
+
vault_guard_active: bool = Field(strict=True)
|
|
59
|
+
rollback_declared: bool = Field(strict=True)
|
|
60
|
+
receipt_id: str = Field(min_length=1)
|
|
61
|
+
|
|
62
|
+
@model_validator(mode="after")
|
|
63
|
+
def _requires_flashcards_effect_receipt(self) -> FlashcardsTagAuthorization:
|
|
64
|
+
if not self.vault_guard_active:
|
|
65
|
+
raise ValueError("vault guard receipt must prove resource_guard_active")
|
|
66
|
+
if not self.rollback_declared:
|
|
67
|
+
raise ValueError("vault guard receipt must declare rollback")
|
|
68
|
+
return self
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _path(value: str | os.PathLike[str]) -> Path:
|
|
72
|
+
return Path(os.path.expandvars(str(value))).expanduser()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _resolve_existing_file(value: str | os.PathLike[str]) -> Path:
|
|
76
|
+
path = _path(value)
|
|
77
|
+
if not path.exists():
|
|
78
|
+
raise MissingPathError(f"File not found: {path}")
|
|
79
|
+
if not path.is_file():
|
|
80
|
+
raise UsageError(f"Expected a file path, got: {path}")
|
|
81
|
+
return path.resolve()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _atomic_write_text(path: Path, text: str) -> None:
|
|
85
|
+
fd, tmp_name = tempfile.mkstemp(prefix=f".{path.name}.", suffix=".tmp", dir=str(path.parent))
|
|
86
|
+
tmp = Path(tmp_name)
|
|
87
|
+
try:
|
|
88
|
+
with os.fdopen(fd, "w", encoding="utf-8", newline="") as fh:
|
|
89
|
+
fh.write(text)
|
|
90
|
+
tmp.replace(path)
|
|
91
|
+
except Exception:
|
|
92
|
+
try:
|
|
93
|
+
tmp.unlink(missing_ok=True)
|
|
94
|
+
finally:
|
|
95
|
+
raise
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _is_relative_to(path: Path, parent: Path) -> bool:
|
|
99
|
+
try:
|
|
100
|
+
path.relative_to(parent)
|
|
101
|
+
except ValueError:
|
|
102
|
+
return False
|
|
103
|
+
return True
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _candidate_vault_roots(path: Path, explicit_root: str | None = None) -> list[Path]:
|
|
107
|
+
candidates: list[Path] = []
|
|
108
|
+
if explicit_root:
|
|
109
|
+
candidates.append(_path(explicit_root).resolve())
|
|
110
|
+
|
|
111
|
+
resolution = resolve_wiki_dir(context_paths=[path], enable_gemini_probe=False)
|
|
112
|
+
if resolution.ok and resolution.path:
|
|
113
|
+
candidates.append(resolution.path.resolve())
|
|
114
|
+
|
|
115
|
+
for parent in (path.parent, *path.parents):
|
|
116
|
+
if (parent / ".obsidian").is_dir():
|
|
117
|
+
candidates.append(parent.resolve())
|
|
118
|
+
if parent.name == "Wiki_Medicina":
|
|
119
|
+
candidates.append(parent.resolve())
|
|
120
|
+
|
|
121
|
+
seen: set[Path] = set()
|
|
122
|
+
roots: list[Path] = []
|
|
123
|
+
for candidate in candidates:
|
|
124
|
+
if candidate not in seen and _is_relative_to(path, candidate):
|
|
125
|
+
roots.append(candidate)
|
|
126
|
+
seen.add(candidate)
|
|
127
|
+
return roots
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def infer_vault_root(path: Path, explicit_root: str | None = None) -> Path | None:
|
|
131
|
+
roots = _candidate_vault_roots(path, explicit_root)
|
|
132
|
+
if not roots:
|
|
133
|
+
return None
|
|
134
|
+
return max(roots, key=lambda root: len(root.parts))
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def obsidian_deeplink(
|
|
138
|
+
path: Path,
|
|
139
|
+
*,
|
|
140
|
+
vault_root: str | None = None,
|
|
141
|
+
vault_name: str | None = None,
|
|
142
|
+
pane_type: str | None = None,
|
|
143
|
+
absolute_path: bool = True,
|
|
144
|
+
fallback_to_absolute_path: bool = True,
|
|
145
|
+
) -> str:
|
|
146
|
+
"""Return an Obsidian URI for a note path.
|
|
147
|
+
|
|
148
|
+
By default, use the real resolved filesystem path. The caller already has
|
|
149
|
+
access to the note file, so the link should not depend on guessing which
|
|
150
|
+
vault contains it. Passing ``absolute_path=False`` opts into the portable
|
|
151
|
+
`vault` + vault-relative `file` form when a vault root is inferable.
|
|
152
|
+
"""
|
|
153
|
+
resolved = path.resolve()
|
|
154
|
+
if absolute_path:
|
|
155
|
+
encoded_path = quote(str(resolved), safe="")
|
|
156
|
+
uri = f"obsidian://open?path={encoded_path}"
|
|
157
|
+
else:
|
|
158
|
+
root = infer_vault_root(resolved, explicit_root=vault_root)
|
|
159
|
+
if root is None:
|
|
160
|
+
if not fallback_to_absolute_path:
|
|
161
|
+
raise UsageError(
|
|
162
|
+
"Could not infer the Obsidian vault root. Pass --vault-root or create a .obsidian "
|
|
163
|
+
"directory in the vault."
|
|
164
|
+
)
|
|
165
|
+
encoded_path = quote(str(resolved), safe="")
|
|
166
|
+
uri = f"obsidian://open?path={encoded_path}"
|
|
167
|
+
else:
|
|
168
|
+
name = vault_name or root.name
|
|
169
|
+
file_path = resolved.relative_to(root).as_posix()
|
|
170
|
+
uri = f"obsidian://open?vault={quote(name, safe='')}&file={quote(file_path, safe='')}"
|
|
171
|
+
if pane_type:
|
|
172
|
+
uri += f"&paneType={quote(pane_type, safe='')}"
|
|
173
|
+
return uri
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _split_frontmatter(text: str) -> tuple[list[str] | None, str]:
|
|
177
|
+
lines = text.splitlines(keepends=True)
|
|
178
|
+
if not lines or lines[0].strip() != _DELIM:
|
|
179
|
+
return None, text
|
|
180
|
+
for idx in range(1, len(lines)):
|
|
181
|
+
if lines[idx].strip() == _DELIM:
|
|
182
|
+
return lines[1:idx], "".join(lines[idx + 1 :])
|
|
183
|
+
return None, text
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _strip_quotes(value: str) -> str:
|
|
187
|
+
value = value.strip()
|
|
188
|
+
if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
|
|
189
|
+
return value[1:-1]
|
|
190
|
+
return value
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _strip_inline_comment(value: str) -> str:
|
|
194
|
+
quote_char: str | None = None
|
|
195
|
+
bracket_depth = 0
|
|
196
|
+
for idx, char in enumerate(value):
|
|
197
|
+
if char in {"'", '"'}:
|
|
198
|
+
quote_char = None if quote_char == char else char
|
|
199
|
+
elif char == "[" and quote_char is None:
|
|
200
|
+
bracket_depth += 1
|
|
201
|
+
elif char == "]" and quote_char is None and bracket_depth:
|
|
202
|
+
bracket_depth -= 1
|
|
203
|
+
if (
|
|
204
|
+
char == "#"
|
|
205
|
+
and quote_char is None
|
|
206
|
+
and bracket_depth == 0
|
|
207
|
+
and idx > 0
|
|
208
|
+
and value[idx - 1].isspace()
|
|
209
|
+
):
|
|
210
|
+
return value[:idx].rstrip()
|
|
211
|
+
return value.strip()
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def normalize_tag(tag: str) -> str:
|
|
215
|
+
normalized = tag.strip().lstrip("#").strip()
|
|
216
|
+
if not normalized:
|
|
217
|
+
raise UsageError("Tag cannot be empty")
|
|
218
|
+
if not _VALID_TAG_RE.match(normalized):
|
|
219
|
+
raise UsageError(
|
|
220
|
+
f"Unsupported tag {tag!r}; use Obsidian-style tags with letters, numbers, _, / or -"
|
|
221
|
+
)
|
|
222
|
+
return normalized
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _parse_inline_tags(value: str) -> list[str]:
|
|
226
|
+
value = _strip_inline_comment(value).strip()
|
|
227
|
+
if not value:
|
|
228
|
+
return []
|
|
229
|
+
if value.startswith("[") and value.endswith("]"):
|
|
230
|
+
value = value[1:-1]
|
|
231
|
+
raw_items = [part.strip() for part in value.split(",")] if "," in value else [value]
|
|
232
|
+
return [normalize_tag(_strip_quotes(item)) for item in raw_items if _strip_quotes(item)]
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def _find_tags_block(frontmatter: list[str]) -> tuple[int, int] | None:
|
|
236
|
+
for idx, line in enumerate(frontmatter):
|
|
237
|
+
match = _TAG_KEY_RE.match(line)
|
|
238
|
+
if not match or match.group("indent"):
|
|
239
|
+
continue
|
|
240
|
+
value = _strip_inline_comment(match.group("value"))
|
|
241
|
+
if value:
|
|
242
|
+
return idx, idx + 1
|
|
243
|
+
end = idx + 1
|
|
244
|
+
while end < len(frontmatter) and _LIST_ITEM_RE.match(frontmatter[end]):
|
|
245
|
+
end += 1
|
|
246
|
+
return idx, end
|
|
247
|
+
return None
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _read_tags_from_block(block: list[str]) -> list[str]:
|
|
251
|
+
if not block:
|
|
252
|
+
return []
|
|
253
|
+
first = _TAG_KEY_RE.match(block[0])
|
|
254
|
+
if not first:
|
|
255
|
+
return []
|
|
256
|
+
value = _strip_inline_comment(first.group("value"))
|
|
257
|
+
raw_tags: list[str] = []
|
|
258
|
+
if value:
|
|
259
|
+
raw_tags.extend(_parse_inline_tags(value))
|
|
260
|
+
else:
|
|
261
|
+
for line in block[1:]:
|
|
262
|
+
item = _LIST_ITEM_RE.match(line)
|
|
263
|
+
if item:
|
|
264
|
+
raw_tags.append(normalize_tag(_strip_quotes(_strip_inline_comment(item.group("value")))))
|
|
265
|
+
|
|
266
|
+
seen: set[str] = set()
|
|
267
|
+
tags: list[str] = []
|
|
268
|
+
for tag in raw_tags:
|
|
269
|
+
if tag not in seen:
|
|
270
|
+
tags.append(tag)
|
|
271
|
+
seen.add(tag)
|
|
272
|
+
return tags
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _format_yaml_tag(tag: str) -> str:
|
|
276
|
+
if _VALID_TAG_RE.match(tag):
|
|
277
|
+
return tag
|
|
278
|
+
return json.dumps(tag, ensure_ascii=False)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _format_tags_block(tags: list[str]) -> list[str]:
|
|
282
|
+
return ["tags:\n", *(f" - {_format_yaml_tag(tag)}\n" for tag in tags)]
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def _mutate_frontmatter_tags(text: str, tag: str, action: str) -> tuple[str, list[str]]:
|
|
286
|
+
target = normalize_tag(tag)
|
|
287
|
+
frontmatter, body = _split_frontmatter(text)
|
|
288
|
+
|
|
289
|
+
if frontmatter is None:
|
|
290
|
+
if action == "remove-tag":
|
|
291
|
+
return text, []
|
|
292
|
+
frontmatter = _format_tags_block([target])
|
|
293
|
+
return "---\n" + "".join(frontmatter) + "---\n" + text, [target]
|
|
294
|
+
|
|
295
|
+
block_range = _find_tags_block(frontmatter)
|
|
296
|
+
existing = _read_tags_from_block(frontmatter[block_range[0] : block_range[1]]) if block_range else []
|
|
297
|
+
tags = list(existing)
|
|
298
|
+
|
|
299
|
+
if action == "add-tag" and target not in tags:
|
|
300
|
+
tags.append(target)
|
|
301
|
+
elif action == "remove-tag":
|
|
302
|
+
tags = [item for item in tags if item != target]
|
|
303
|
+
|
|
304
|
+
if block_range:
|
|
305
|
+
start, end = block_range
|
|
306
|
+
replacement = _format_tags_block(tags) if tags else []
|
|
307
|
+
frontmatter = [*frontmatter[:start], *replacement, *frontmatter[end:]]
|
|
308
|
+
elif tags:
|
|
309
|
+
frontmatter = [*frontmatter, *_format_tags_block(tags)]
|
|
310
|
+
|
|
311
|
+
if not any(line.strip() for line in frontmatter):
|
|
312
|
+
return body, tags
|
|
313
|
+
return "---\n" + "".join(frontmatter) + "---\n" + body, tags
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _load_flashcards_tag_authorization(
|
|
317
|
+
*,
|
|
318
|
+
effect_target: str | None,
|
|
319
|
+
receipt_path: str | None,
|
|
320
|
+
dry_run: bool,
|
|
321
|
+
) -> FlashcardsTagAuthorization | None:
|
|
322
|
+
"""Require the official effect + vault receipt before any real note write."""
|
|
323
|
+
|
|
324
|
+
if dry_run:
|
|
325
|
+
return None
|
|
326
|
+
if not effect_target or not receipt_path:
|
|
327
|
+
raise UsageError(
|
|
328
|
+
"Obsidian tag writes require WorkflowEffect target flashcards.tag_obsidian "
|
|
329
|
+
"and --vault-guard-receipt."
|
|
330
|
+
)
|
|
331
|
+
receipt_file = _resolve_existing_file(receipt_path)
|
|
332
|
+
try:
|
|
333
|
+
vault_guard_receipt = FlashcardsVaultGuardReceipt.model_validate_json(
|
|
334
|
+
receipt_file.read_text(encoding="utf-8")
|
|
335
|
+
)
|
|
336
|
+
return FlashcardsTagAuthorization.model_validate(
|
|
337
|
+
{
|
|
338
|
+
"effect_target": effect_target,
|
|
339
|
+
"receipt_path": receipt_file,
|
|
340
|
+
"workflow": vault_guard_receipt.workflow,
|
|
341
|
+
"effect_kind": vault_guard_receipt.effect_kind,
|
|
342
|
+
"receipt_effect_target": vault_guard_receipt.effect_target,
|
|
343
|
+
"vault_guard_active": vault_guard_receipt.resource_guard_active,
|
|
344
|
+
"rollback_declared": vault_guard_receipt.rollback_declared,
|
|
345
|
+
"receipt_id": vault_guard_receipt.receipt_id,
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
except json.JSONDecodeError as exc:
|
|
349
|
+
raise UsageError(f"Invalid vault guard receipt JSON: {receipt_file}") from exc
|
|
350
|
+
except ValidationError as exc:
|
|
351
|
+
raise UsageError(f"Invalid vault guard receipt JSON: {receipt_file}: {exc}") from exc
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def mutate_note_tag(
|
|
355
|
+
path: Path,
|
|
356
|
+
tag: str,
|
|
357
|
+
action: str,
|
|
358
|
+
*,
|
|
359
|
+
dry_run: bool = False,
|
|
360
|
+
backup: bool = False,
|
|
361
|
+
authorization: FlashcardsTagAuthorization | None = None,
|
|
362
|
+
) -> dict[str, object]:
|
|
363
|
+
old_text = path.read_text(encoding="utf-8")
|
|
364
|
+
new_text, tags = _mutate_frontmatter_tags(old_text, tag, action)
|
|
365
|
+
changed = new_text != old_text
|
|
366
|
+
backup_file: Path | None = None
|
|
367
|
+
|
|
368
|
+
if changed and not dry_run and authorization is None:
|
|
369
|
+
raise UsageError(
|
|
370
|
+
"Refusing direct Obsidian tag mutation without WorkflowEffect target "
|
|
371
|
+
"flashcards.tag_obsidian and vault guard receipt."
|
|
372
|
+
)
|
|
373
|
+
if changed and not dry_run:
|
|
374
|
+
_atomic_write_text(path, new_text)
|
|
375
|
+
|
|
376
|
+
record: dict[str, object] = {
|
|
377
|
+
"path": str(path),
|
|
378
|
+
"action": action,
|
|
379
|
+
"tag": normalize_tag(tag),
|
|
380
|
+
"changed": changed,
|
|
381
|
+
"dry_run": dry_run,
|
|
382
|
+
"backup": str(backup_file) if backup_file else None,
|
|
383
|
+
"tags": tags,
|
|
384
|
+
}
|
|
385
|
+
if authorization is not None:
|
|
386
|
+
record["effect_target"] = authorization.effect_target
|
|
387
|
+
record["version_control_safety"] = {
|
|
388
|
+
"no_resource_mutation": False,
|
|
389
|
+
"rollback_declared": authorization.rollback_declared,
|
|
390
|
+
"resource_guard_active": authorization.vault_guard_active,
|
|
391
|
+
"direct_mutation_forbidden": True,
|
|
392
|
+
"mutation_without_guard": False,
|
|
393
|
+
"changed_file_count": 1 if changed else 0,
|
|
394
|
+
}
|
|
395
|
+
if changed:
|
|
396
|
+
record["link_trigger_context"] = {
|
|
397
|
+
"schema": "medical-notes-workbench.link-trigger-context.v1",
|
|
398
|
+
"reason": "obsidian_metadata_tag_changed",
|
|
399
|
+
"workflow": "/flashcards",
|
|
400
|
+
"path": str(path),
|
|
401
|
+
"visual_only": False,
|
|
402
|
+
}
|
|
403
|
+
return record
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def _cmd_deeplink(args: argparse.Namespace) -> int:
|
|
407
|
+
records = []
|
|
408
|
+
for raw_path in args.paths:
|
|
409
|
+
path = _resolve_existing_file(raw_path)
|
|
410
|
+
records.append(
|
|
411
|
+
{
|
|
412
|
+
"path": str(path),
|
|
413
|
+
"deeplink": obsidian_deeplink(
|
|
414
|
+
path,
|
|
415
|
+
vault_root=args.vault_root,
|
|
416
|
+
vault_name=args.vault_name,
|
|
417
|
+
pane_type=args.pane_type,
|
|
418
|
+
absolute_path=args.absolute_path,
|
|
419
|
+
),
|
|
420
|
+
}
|
|
421
|
+
)
|
|
422
|
+
print(json.dumps(records, ensure_ascii=False, indent=2))
|
|
423
|
+
return EXIT_OK
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _cmd_tag(args: argparse.Namespace) -> int:
|
|
427
|
+
authorization = _load_flashcards_tag_authorization(
|
|
428
|
+
effect_target=args.effect_target,
|
|
429
|
+
receipt_path=args.vault_guard_receipt,
|
|
430
|
+
dry_run=args.dry_run,
|
|
431
|
+
)
|
|
432
|
+
records = []
|
|
433
|
+
for raw_path in args.paths:
|
|
434
|
+
path = _resolve_existing_file(raw_path)
|
|
435
|
+
records.append(
|
|
436
|
+
mutate_note_tag(
|
|
437
|
+
path,
|
|
438
|
+
args.tag,
|
|
439
|
+
args.action,
|
|
440
|
+
dry_run=args.dry_run,
|
|
441
|
+
backup=False,
|
|
442
|
+
authorization=authorization,
|
|
443
|
+
)
|
|
444
|
+
)
|
|
445
|
+
changed_files = [
|
|
446
|
+
str(record["path"])
|
|
447
|
+
for record in records
|
|
448
|
+
if bool(record["changed"] if "changed" in record else False)
|
|
449
|
+
]
|
|
450
|
+
vault_guard_receipt = (
|
|
451
|
+
{
|
|
452
|
+
"receipt_path": str(authorization.receipt_path),
|
|
453
|
+
"receipt_id": authorization.receipt_id,
|
|
454
|
+
"resource_guard_active": authorization.vault_guard_active,
|
|
455
|
+
"rollback_declared": authorization.rollback_declared,
|
|
456
|
+
"effect_target": authorization.effect_target,
|
|
457
|
+
}
|
|
458
|
+
if authorization is not None
|
|
459
|
+
else {}
|
|
460
|
+
)
|
|
461
|
+
receipt = FlashcardsTaggingReceipt(
|
|
462
|
+
status="dry_run" if args.dry_run else ("completed" if changed_files else "completed_noop"),
|
|
463
|
+
changed_files=changed_files,
|
|
464
|
+
tag=normalize_tag(args.tag),
|
|
465
|
+
vault_guard_receipt=vault_guard_receipt,
|
|
466
|
+
records=records,
|
|
467
|
+
)
|
|
468
|
+
print(json.dumps(receipt.to_payload(), ensure_ascii=False, indent=2))
|
|
469
|
+
return EXIT_OK
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
473
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
474
|
+
subparsers = parser.add_subparsers(dest="action", required=True)
|
|
475
|
+
|
|
476
|
+
deeplink = subparsers.add_parser("deeplink", help="emit Obsidian deeplink JSON for note paths")
|
|
477
|
+
deeplink.add_argument("paths", nargs="+", help="Markdown note paths")
|
|
478
|
+
deeplink.add_argument(
|
|
479
|
+
"--vault-root",
|
|
480
|
+
default=None,
|
|
481
|
+
help=(
|
|
482
|
+
"vault root path used with --vault-file; defaults to persistent "
|
|
483
|
+
"app config.toml [paths].wiki_dir, legacy config/env, nearest .obsidian "
|
|
484
|
+
"parent, or Wiki_Medicina"
|
|
485
|
+
),
|
|
486
|
+
)
|
|
487
|
+
deeplink.add_argument(
|
|
488
|
+
"--vault-name",
|
|
489
|
+
default=None,
|
|
490
|
+
help="vault name to encode in the URI; defaults to the inferred vault root folder name",
|
|
491
|
+
)
|
|
492
|
+
deeplink.add_argument(
|
|
493
|
+
"--absolute-path",
|
|
494
|
+
action="store_true",
|
|
495
|
+
default=True,
|
|
496
|
+
help="emit obsidian://open?path=... using the real note path; this is the default",
|
|
497
|
+
)
|
|
498
|
+
deeplink.add_argument(
|
|
499
|
+
"--vault-file",
|
|
500
|
+
dest="absolute_path",
|
|
501
|
+
action="store_false",
|
|
502
|
+
help="emit obsidian://open?vault=...&file=... when a vault root can be inferred",
|
|
503
|
+
)
|
|
504
|
+
deeplink.add_argument(
|
|
505
|
+
"--pane-type",
|
|
506
|
+
choices=("tab", "split", "window"),
|
|
507
|
+
default=None,
|
|
508
|
+
help="optional Obsidian paneType parameter",
|
|
509
|
+
)
|
|
510
|
+
deeplink.set_defaults(func=_cmd_deeplink)
|
|
511
|
+
|
|
512
|
+
for action in ("add-tag", "remove-tag"):
|
|
513
|
+
tag_parser = subparsers.add_parser(action, help=f"{action} in note frontmatter")
|
|
514
|
+
tag_parser.add_argument("paths", nargs="+", help="Markdown note paths")
|
|
515
|
+
tag_parser.add_argument("--tag", default="anki", help="frontmatter tag, default: anki")
|
|
516
|
+
tag_parser.add_argument("--dry-run", action="store_true", help="report changes without writing")
|
|
517
|
+
tag_parser.add_argument(
|
|
518
|
+
"--effect-target",
|
|
519
|
+
default=None,
|
|
520
|
+
help="official WorkflowEffect target authorizing a real Obsidian tag write",
|
|
521
|
+
)
|
|
522
|
+
tag_parser.add_argument(
|
|
523
|
+
"--vault-guard-receipt",
|
|
524
|
+
default=None,
|
|
525
|
+
help="JSON receipt proving vault guard and rollback safety for the effect",
|
|
526
|
+
)
|
|
527
|
+
tag_parser.set_defaults(func=_cmd_tag)
|
|
528
|
+
|
|
529
|
+
return parser
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def main(argv: list[str] | None = None) -> int:
|
|
533
|
+
parser = build_parser()
|
|
534
|
+
args = parser.parse_args(argv)
|
|
535
|
+
try:
|
|
536
|
+
return args.func(args)
|
|
537
|
+
except NoteUtilsError as exc:
|
|
538
|
+
print(str(exc), file=sys.stderr)
|
|
539
|
+
return exc.exit_code
|
|
540
|
+
except OSError as exc:
|
|
541
|
+
print(str(exc), file=sys.stderr)
|
|
542
|
+
return EXIT_IO
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
if __name__ == "__main__":
|
|
546
|
+
raise SystemExit(main())
|