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
package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_bootstrap.py
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
"""Fresh vocabulary bootstrap/reset helpers."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
import sqlite3
|
|
7
|
+
from dataclasses import dataclass, field
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import TypedDict
|
|
10
|
+
|
|
11
|
+
from pydantic import Field
|
|
12
|
+
|
|
13
|
+
from mednotes.domains.wiki.batch_state import file_sha256
|
|
14
|
+
from mednotes.domains.wiki.capabilities.notes.note_iter import iter_notes
|
|
15
|
+
from mednotes.domains.wiki.capabilities.notes.note_style.frontmatter import (
|
|
16
|
+
FrontmatterYamlUnavailable,
|
|
17
|
+
canonical_wiki_tags,
|
|
18
|
+
dump_frontmatter_yaml,
|
|
19
|
+
load_frontmatter_yaml,
|
|
20
|
+
split_frontmatter,
|
|
21
|
+
)
|
|
22
|
+
from mednotes.domains.wiki.capabilities.notes.raw_chats import atomic_write_text
|
|
23
|
+
from mednotes.domains.wiki.capabilities.vocabulary.link_terms import is_index_note as _is_index_note
|
|
24
|
+
from mednotes.domains.wiki.capabilities.vocabulary.link_terms import obsidian_target_name
|
|
25
|
+
from mednotes.domains.wiki.capabilities.vocabulary.vocabulary_map import (
|
|
26
|
+
initialize_vocabulary_db,
|
|
27
|
+
note_content_hash,
|
|
28
|
+
upsert_note,
|
|
29
|
+
)
|
|
30
|
+
from mednotes.domains.wiki.common import _now_iso
|
|
31
|
+
from mednotes.domains.wiki.config import MedConfig
|
|
32
|
+
from mednotes.kernel.base import ContractModel, JsonObjectAdapter, JsonValue
|
|
33
|
+
|
|
34
|
+
BOOTSTRAP_PLAN_SCHEMA = "medical-notes-workbench.vocabulary-bootstrap-plan.v1"
|
|
35
|
+
BOOTSTRAP_RECEIPT_SCHEMA = "medical-notes-workbench.vocabulary-bootstrap-receipt.v1"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class PreservedFrontmatter(ContractModel):
|
|
39
|
+
aliases: list[str] = Field(default_factory=list)
|
|
40
|
+
tags: list[str] = Field(default_factory=list)
|
|
41
|
+
chats: JsonValue | None = None
|
|
42
|
+
image_fields: dict[str, str | list[str]] = Field(default_factory=dict)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class SemanticIngestionQueueItem(TypedDict):
|
|
46
|
+
schema: str
|
|
47
|
+
note_path: str
|
|
48
|
+
content_hash: str
|
|
49
|
+
queue_flags: list[str]
|
|
50
|
+
assigned_agent: str
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class BootstrapNoteOperationPayload(TypedDict):
|
|
54
|
+
path: str
|
|
55
|
+
before_hash: str
|
|
56
|
+
after_hash: str
|
|
57
|
+
queue_flags: list[str]
|
|
58
|
+
changed: bool
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class BootstrapPlanPayload(TypedDict):
|
|
62
|
+
schema: str
|
|
63
|
+
wiki_dir: str
|
|
64
|
+
note_count: int
|
|
65
|
+
note_operations: list[BootstrapNoteOperationPayload]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class BootstrapReceiptPayload(TypedDict, total=False):
|
|
69
|
+
schema: str
|
|
70
|
+
generated_at: str
|
|
71
|
+
status: str
|
|
72
|
+
trigger: str
|
|
73
|
+
automatic: bool
|
|
74
|
+
db_path: str
|
|
75
|
+
wiki_dir: str
|
|
76
|
+
plan_path: str
|
|
77
|
+
queue_path: str
|
|
78
|
+
receipt_path: str
|
|
79
|
+
note_count: int
|
|
80
|
+
queued_note_count: int
|
|
81
|
+
changed_files: list[str]
|
|
82
|
+
backup_paths: list[str]
|
|
83
|
+
dry_run: bool
|
|
84
|
+
note_count_deferred: bool
|
|
85
|
+
deferred_reason: str
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class SemanticIngestionQueuePayload(TypedDict):
|
|
89
|
+
schema: str
|
|
90
|
+
generated_at: str
|
|
91
|
+
db_path: str
|
|
92
|
+
item_count: int
|
|
93
|
+
items: list[SemanticIngestionQueueItem]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass(frozen=True)
|
|
97
|
+
class BootstrapNoteOperation:
|
|
98
|
+
path: Path
|
|
99
|
+
before_hash: str
|
|
100
|
+
after_text: str
|
|
101
|
+
after_frontmatter: PreservedFrontmatter
|
|
102
|
+
queue_flags: list[str]
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def changed(self) -> bool:
|
|
106
|
+
return self.path.read_text(encoding="utf-8") != self.after_text if self.path.exists() else True
|
|
107
|
+
|
|
108
|
+
def queue_item(self) -> SemanticIngestionQueueItem:
|
|
109
|
+
return {
|
|
110
|
+
"schema": "medical-notes-workbench.note-semantic-ingestion-queue.v1",
|
|
111
|
+
"note_path": str(self.path),
|
|
112
|
+
"content_hash": "sha256:" + _sha256_text(self.after_text),
|
|
113
|
+
"queue_flags": self.queue_flags,
|
|
114
|
+
"assigned_agent": "med-link-graph-curator",
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@dataclass
|
|
119
|
+
class BootstrapPlan:
|
|
120
|
+
wiki_dir: Path
|
|
121
|
+
note_operations: list[BootstrapNoteOperation] = field(default_factory=list)
|
|
122
|
+
schema: str = BOOTSTRAP_PLAN_SCHEMA
|
|
123
|
+
|
|
124
|
+
def as_dict(self) -> BootstrapPlanPayload:
|
|
125
|
+
return {
|
|
126
|
+
"schema": self.schema,
|
|
127
|
+
"wiki_dir": str(self.wiki_dir),
|
|
128
|
+
"note_count": len(self.note_operations),
|
|
129
|
+
"note_operations": [
|
|
130
|
+
{
|
|
131
|
+
"path": str(item.path),
|
|
132
|
+
"before_hash": item.before_hash,
|
|
133
|
+
"after_hash": "sha256:" + _sha256_text(item.after_text),
|
|
134
|
+
"queue_flags": item.queue_flags,
|
|
135
|
+
"changed": item.changed,
|
|
136
|
+
}
|
|
137
|
+
for item in self.note_operations
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def plan_fresh_bootstrap_reset(*, wiki_dir: Path) -> BootstrapPlan:
|
|
143
|
+
operations: list[BootstrapNoteOperation] = []
|
|
144
|
+
for path in iter_notes(wiki_dir) if wiki_dir.exists() else []:
|
|
145
|
+
text = path.read_text(encoding="utf-8")
|
|
146
|
+
if _is_index_note(path, text):
|
|
147
|
+
continue
|
|
148
|
+
after_text, after_frontmatter = _reset_note_text(text)
|
|
149
|
+
operations.append(
|
|
150
|
+
BootstrapNoteOperation(
|
|
151
|
+
path=path,
|
|
152
|
+
before_hash="sha256:" + file_sha256(path),
|
|
153
|
+
after_text=after_text,
|
|
154
|
+
after_frontmatter=after_frontmatter,
|
|
155
|
+
queue_flags=["aliases_missing", "concept_mapping_missing"],
|
|
156
|
+
)
|
|
157
|
+
)
|
|
158
|
+
return BootstrapPlan(wiki_dir=wiki_dir, note_operations=operations)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def apply_fresh_bootstrap_reset(
|
|
162
|
+
*,
|
|
163
|
+
wiki_dir: Path,
|
|
164
|
+
db_path: Path,
|
|
165
|
+
backup: bool = False,
|
|
166
|
+
run_dir: Path | None = None,
|
|
167
|
+
trigger: str = "vocabulary_db_missing",
|
|
168
|
+
automatic: bool = True,
|
|
169
|
+
) -> BootstrapReceiptPayload:
|
|
170
|
+
plan = plan_fresh_bootstrap_reset(wiki_dir=wiki_dir)
|
|
171
|
+
run_dir = run_dir or db_path.parent
|
|
172
|
+
run_dir.mkdir(parents=True, exist_ok=True)
|
|
173
|
+
plan_path = run_dir / "vocabulary-bootstrap-plan.json"
|
|
174
|
+
queue_path = run_dir / "note-semantic-ingestion-queue.json"
|
|
175
|
+
receipt_path = run_dir / "vocabulary-bootstrap-receipt.json"
|
|
176
|
+
atomic_write_text(plan_path, json.dumps(plan.as_dict(), ensure_ascii=False, indent=2) + "\n")
|
|
177
|
+
|
|
178
|
+
backup_paths: list[str] = []
|
|
179
|
+
changed_files: list[str] = []
|
|
180
|
+
if db_path.exists():
|
|
181
|
+
archive_path = run_dir / f"{db_path.name}.before-reset"
|
|
182
|
+
archive_path.write_bytes(db_path.read_bytes())
|
|
183
|
+
db_path.unlink()
|
|
184
|
+
initialize_vocabulary_db(db_path)
|
|
185
|
+
|
|
186
|
+
queue_items: list[SemanticIngestionQueueItem] = []
|
|
187
|
+
with sqlite3.connect(db_path) as conn:
|
|
188
|
+
for operation in plan.note_operations:
|
|
189
|
+
if operation.changed:
|
|
190
|
+
atomic_write_text(operation.path, operation.after_text)
|
|
191
|
+
changed_files.append(str(operation.path))
|
|
192
|
+
content_hash = note_content_hash(operation.path)
|
|
193
|
+
note_id = upsert_note(conn, path=operation.path, title=_title_for(operation.after_text, operation.path), content_hash=content_hash)
|
|
194
|
+
queue_item = {
|
|
195
|
+
"schema": "medical-notes-workbench.note-semantic-ingestion-queue.v1",
|
|
196
|
+
"note_path": str(operation.path),
|
|
197
|
+
"content_hash": content_hash,
|
|
198
|
+
"queue_flags": operation.queue_flags,
|
|
199
|
+
"assigned_agent": "med-link-graph-curator",
|
|
200
|
+
}
|
|
201
|
+
queue_items.append(queue_item)
|
|
202
|
+
conn.execute(
|
|
203
|
+
"""
|
|
204
|
+
INSERT INTO note_semantic_ingestion_queue(note_id, note_path, content_hash, queue_flags_json, assigned_agent, status)
|
|
205
|
+
VALUES (?, ?, ?, ?, 'med-link-graph-curator', 'pending')
|
|
206
|
+
ON CONFLICT(note_path, content_hash) DO UPDATE SET
|
|
207
|
+
queue_flags_json=excluded.queue_flags_json,
|
|
208
|
+
assigned_agent='med-link-graph-curator',
|
|
209
|
+
status='pending',
|
|
210
|
+
updated_at=CURRENT_TIMESTAMP
|
|
211
|
+
""",
|
|
212
|
+
(note_id, str(operation.path), content_hash, json.dumps(operation.queue_flags, ensure_ascii=False)),
|
|
213
|
+
)
|
|
214
|
+
queue_payload: SemanticIngestionQueuePayload = {
|
|
215
|
+
"schema": "medical-notes-workbench.note-semantic-ingestion-queue.v1",
|
|
216
|
+
"generated_at": _now_iso(),
|
|
217
|
+
"db_path": str(db_path),
|
|
218
|
+
"item_count": len(queue_items),
|
|
219
|
+
"items": queue_items,
|
|
220
|
+
}
|
|
221
|
+
atomic_write_text(queue_path, json.dumps(queue_payload, ensure_ascii=False, indent=2) + "\n")
|
|
222
|
+
receipt: BootstrapReceiptPayload = {
|
|
223
|
+
"schema": BOOTSTRAP_RECEIPT_SCHEMA,
|
|
224
|
+
"generated_at": _now_iso(),
|
|
225
|
+
"status": "queued_semantic_ingestion" if queue_items else "completed",
|
|
226
|
+
"trigger": trigger,
|
|
227
|
+
"automatic": automatic,
|
|
228
|
+
"db_path": str(db_path),
|
|
229
|
+
"wiki_dir": str(wiki_dir),
|
|
230
|
+
"plan_path": str(plan_path),
|
|
231
|
+
"queue_path": str(queue_path),
|
|
232
|
+
"receipt_path": str(receipt_path),
|
|
233
|
+
"note_count": len(plan.note_operations),
|
|
234
|
+
"queued_note_count": len(queue_items),
|
|
235
|
+
"changed_files": changed_files,
|
|
236
|
+
"backup_paths": backup_paths,
|
|
237
|
+
}
|
|
238
|
+
atomic_write_text(receipt_path, json.dumps(receipt, ensure_ascii=False, indent=2) + "\n")
|
|
239
|
+
return receipt
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def ensure_vocabulary_db(
|
|
243
|
+
config: MedConfig,
|
|
244
|
+
*,
|
|
245
|
+
run_dir: Path | None = None,
|
|
246
|
+
backup: bool = False,
|
|
247
|
+
force_reset: bool = False,
|
|
248
|
+
trigger: str = "vocabulary_db_missing",
|
|
249
|
+
) -> BootstrapReceiptPayload:
|
|
250
|
+
backup = False
|
|
251
|
+
db_path = getattr(config, "vocabulary_db_path", None)
|
|
252
|
+
if db_path is None:
|
|
253
|
+
return {
|
|
254
|
+
"status": "skipped",
|
|
255
|
+
"trigger": "vocabulary_db_unconfigured",
|
|
256
|
+
"automatic": False,
|
|
257
|
+
"db_path": "",
|
|
258
|
+
}
|
|
259
|
+
if db_path.exists() and not force_reset:
|
|
260
|
+
return {
|
|
261
|
+
"status": "existing",
|
|
262
|
+
"trigger": "vocabulary_db_present",
|
|
263
|
+
"automatic": False,
|
|
264
|
+
"db_path": str(db_path),
|
|
265
|
+
}
|
|
266
|
+
return apply_fresh_bootstrap_reset(
|
|
267
|
+
wiki_dir=config.wiki_dir,
|
|
268
|
+
db_path=db_path,
|
|
269
|
+
backup=backup,
|
|
270
|
+
run_dir=run_dir,
|
|
271
|
+
trigger="explicit_vocabulary_reset" if force_reset else trigger,
|
|
272
|
+
automatic=not force_reset,
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def planned_vocabulary_bootstrap(
|
|
277
|
+
config: MedConfig,
|
|
278
|
+
*,
|
|
279
|
+
force_reset: bool = False,
|
|
280
|
+
scan_notes: bool = True,
|
|
281
|
+
) -> BootstrapReceiptPayload:
|
|
282
|
+
db_path = config.vocabulary_db_path
|
|
283
|
+
if db_path is None:
|
|
284
|
+
return {
|
|
285
|
+
"status": "skipped",
|
|
286
|
+
"trigger": "vocabulary_db_unconfigured",
|
|
287
|
+
"automatic": False,
|
|
288
|
+
"db_path": "",
|
|
289
|
+
}
|
|
290
|
+
if db_path.exists() and not force_reset:
|
|
291
|
+
return {
|
|
292
|
+
"status": "existing",
|
|
293
|
+
"trigger": "vocabulary_db_present",
|
|
294
|
+
"automatic": False,
|
|
295
|
+
"db_path": str(db_path),
|
|
296
|
+
}
|
|
297
|
+
if not scan_notes:
|
|
298
|
+
return {
|
|
299
|
+
"schema": BOOTSTRAP_RECEIPT_SCHEMA,
|
|
300
|
+
"generated_at": _now_iso(),
|
|
301
|
+
"status": "planned",
|
|
302
|
+
"trigger": "explicit_vocabulary_reset" if force_reset else "vocabulary_db_missing",
|
|
303
|
+
"automatic": not force_reset,
|
|
304
|
+
"db_path": str(db_path),
|
|
305
|
+
"wiki_dir": str(config.wiki_dir),
|
|
306
|
+
"note_count": 0,
|
|
307
|
+
"queued_note_count": 0,
|
|
308
|
+
"changed_files": [],
|
|
309
|
+
"backup_paths": [],
|
|
310
|
+
"dry_run": True,
|
|
311
|
+
"note_count_deferred": True,
|
|
312
|
+
"deferred_reason": "apply_will_generate_vocabulary_bootstrap_receipt",
|
|
313
|
+
}
|
|
314
|
+
plan = plan_fresh_bootstrap_reset(wiki_dir=config.wiki_dir)
|
|
315
|
+
return {
|
|
316
|
+
"schema": BOOTSTRAP_RECEIPT_SCHEMA,
|
|
317
|
+
"generated_at": _now_iso(),
|
|
318
|
+
"status": "planned",
|
|
319
|
+
"trigger": "explicit_vocabulary_reset" if force_reset else "vocabulary_db_missing",
|
|
320
|
+
"automatic": not force_reset,
|
|
321
|
+
"db_path": str(db_path),
|
|
322
|
+
"wiki_dir": str(config.wiki_dir),
|
|
323
|
+
"note_count": len(plan.note_operations),
|
|
324
|
+
"queued_note_count": len(plan.note_operations),
|
|
325
|
+
"changed_files": [],
|
|
326
|
+
"backup_paths": [],
|
|
327
|
+
"dry_run": True,
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def resolve_vocabulary_bootstrap(
|
|
332
|
+
config: MedConfig,
|
|
333
|
+
*,
|
|
334
|
+
apply: bool,
|
|
335
|
+
run_dir: Path | None = None,
|
|
336
|
+
backup: bool = False,
|
|
337
|
+
force_reset: bool = False,
|
|
338
|
+
scan_notes: bool = True,
|
|
339
|
+
) -> BootstrapReceiptPayload:
|
|
340
|
+
db_path = config.vocabulary_db_path
|
|
341
|
+
should_apply = apply or force_reset or bool(db_path and db_path.exists())
|
|
342
|
+
if should_apply:
|
|
343
|
+
return ensure_vocabulary_db(config, run_dir=run_dir, backup=backup, force_reset=force_reset)
|
|
344
|
+
return planned_vocabulary_bootstrap(config, force_reset=force_reset, scan_notes=scan_notes)
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def _reset_note_text(text: str) -> tuple[str, PreservedFrontmatter]:
|
|
348
|
+
frontmatter, body = split_frontmatter(text)
|
|
349
|
+
after_frontmatter = _extract_preserved_frontmatter(frontmatter or "")
|
|
350
|
+
body = _replace_wikilinks_preserving_protected_zones(body)
|
|
351
|
+
rendered = _render_frontmatter(after_frontmatter)
|
|
352
|
+
normalized_body = body.lstrip("\n")
|
|
353
|
+
return (rendered + normalized_body if rendered else normalized_body), after_frontmatter
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
def _extract_preserved_frontmatter(frontmatter: str) -> PreservedFrontmatter:
|
|
357
|
+
try:
|
|
358
|
+
structured = load_frontmatter_yaml(f"---\n{frontmatter}---\n") if frontmatter.strip() else {}
|
|
359
|
+
except FrontmatterYamlUnavailable:
|
|
360
|
+
structured = {}
|
|
361
|
+
tags = canonical_wiki_tags(_extract_yaml_list(frontmatter, "tags"))
|
|
362
|
+
chats: JsonValue | None = None
|
|
363
|
+
raw_chats: object = structured.get("chats")
|
|
364
|
+
if raw_chats:
|
|
365
|
+
chats = _coerce_json_value(raw_chats)
|
|
366
|
+
image_fields: dict[str, str | list[str]] = {}
|
|
367
|
+
for key in re.findall(r"(?m)^([A-Za-z0-9_-]+)\s*:", frontmatter):
|
|
368
|
+
if key.startswith(("images_", "image_")):
|
|
369
|
+
values = _extract_yaml_list(frontmatter, key)
|
|
370
|
+
image_fields[key] = values if values else _extract_scalar(frontmatter, key)
|
|
371
|
+
return PreservedFrontmatter(tags=tags, chats=chats, image_fields=image_fields)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _coerce_json_value(value: object) -> JsonValue | None:
|
|
375
|
+
if value is None:
|
|
376
|
+
return None
|
|
377
|
+
try:
|
|
378
|
+
return JsonObjectAdapter.validate_python({"value": value})["value"]
|
|
379
|
+
except ValueError:
|
|
380
|
+
return str(value)
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _extract_yaml_list(frontmatter: str, key: str) -> list[str]:
|
|
384
|
+
inline = re.search(rf"(?m)^{re.escape(key)}\s*:\s*\[(.*?)\]\s*$", frontmatter)
|
|
385
|
+
if inline:
|
|
386
|
+
return [_clean_yaml_item(item) for item in inline.group(1).split(",") if item.strip()]
|
|
387
|
+
block = re.search(rf"(?m)^{re.escape(key)}[ \t]*:[ \t]*\n((?:[ \t]*-[ \t]*.*(?:\n|$))+)", frontmatter)
|
|
388
|
+
if not block:
|
|
389
|
+
return []
|
|
390
|
+
values: list[str] = []
|
|
391
|
+
for line in block.group(1).splitlines():
|
|
392
|
+
match = re.match(r"^\s*-\s*(.*?)\s*$", line)
|
|
393
|
+
if match:
|
|
394
|
+
values.append(_clean_yaml_item(match.group(1)))
|
|
395
|
+
return [value for value in values if value]
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def _extract_scalar(frontmatter: str, key: str) -> str:
|
|
399
|
+
match = re.search(rf"(?m)^{re.escape(key)}\s*:\s*(.*?)\s*$", frontmatter)
|
|
400
|
+
return _clean_yaml_item(match.group(1)) if match else ""
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def _clean_yaml_item(value: str) -> str:
|
|
404
|
+
return value.strip().strip("'\"").strip()
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _render_frontmatter(data: PreservedFrontmatter) -> str:
|
|
408
|
+
lines: list[str] = []
|
|
409
|
+
if data.aliases:
|
|
410
|
+
lines.append("aliases:\n")
|
|
411
|
+
lines.extend(f" - {json.dumps(alias, ensure_ascii=False)}\n" for alias in data.aliases)
|
|
412
|
+
if data.tags:
|
|
413
|
+
lines.append("tags:\n")
|
|
414
|
+
lines.extend(f" - {tag}\n" if re.match(r"^[A-Za-z0-9_/-]+$", tag) else f" - {json.dumps(tag, ensure_ascii=False)}\n" for tag in data.tags)
|
|
415
|
+
if data.chats is not None:
|
|
416
|
+
lines.extend(_dump_structured_frontmatter_item("chats", data.chats))
|
|
417
|
+
for key, value in data.image_fields.items():
|
|
418
|
+
if isinstance(value, list):
|
|
419
|
+
lines.append(f"{key}:\n")
|
|
420
|
+
lines.extend(f" - {json.dumps(item, ensure_ascii=False)}\n" for item in value)
|
|
421
|
+
elif value:
|
|
422
|
+
lines.append(f"{key}: {json.dumps(value, ensure_ascii=False)}\n")
|
|
423
|
+
return f"---\n{''.join(lines)}---\n" if lines else ""
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _dump_structured_frontmatter_item(key: str, value: JsonValue) -> list[str]:
|
|
427
|
+
return list(dump_frontmatter_yaml({key: value}).splitlines(keepends=True))
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
_RELATED_RE = re.compile(r"(?m)^##\s+(?:🔗\s+)?Notas Relacionadas\s*$")
|
|
431
|
+
_NEXT_H2_RE = re.compile(r"(?m)^##\s+")
|
|
432
|
+
_FOOTER_RE = re.compile(r"(?m)^---\s*$")
|
|
433
|
+
_WIKILINK_RE = re.compile(r"(?<!!)\[\[([^\]]+)\]\]")
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _replace_wikilinks_preserving_protected_zones(text: str) -> str:
|
|
437
|
+
spans = _protected_spans(text)
|
|
438
|
+
parts: list[str] = []
|
|
439
|
+
cursor = 0
|
|
440
|
+
for start, end in spans:
|
|
441
|
+
parts.append(_replace_wikilinks(text[cursor:start]))
|
|
442
|
+
parts.append(text[start:end])
|
|
443
|
+
cursor = end
|
|
444
|
+
parts.append(_replace_wikilinks(text[cursor:]))
|
|
445
|
+
return "".join(parts)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
def _protected_spans(text: str) -> list[tuple[int, int]]:
|
|
449
|
+
spans: list[tuple[int, int]] = []
|
|
450
|
+
for match in re.finditer(r"```.*?```", text, re.DOTALL):
|
|
451
|
+
spans.append((match.start(), match.end()))
|
|
452
|
+
for match in re.finditer(r"!\[\[[^\]]+\]\]", text):
|
|
453
|
+
spans.append((match.start(), match.end()))
|
|
454
|
+
for match in _FOOTER_RE.finditer(text):
|
|
455
|
+
tail = text[match.start() :]
|
|
456
|
+
if "[[_Índice_Medicina]]" in tail or "Chat Original" in tail:
|
|
457
|
+
spans.append((match.start(), len(text)))
|
|
458
|
+
break
|
|
459
|
+
for line in re.finditer(r"(?m)^#.*$", text):
|
|
460
|
+
spans.append((line.start(), line.end()))
|
|
461
|
+
spans.extend(_related_section_spans(text))
|
|
462
|
+
return _merge_spans(spans)
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _related_section_spans(text: str) -> list[tuple[int, int]]:
|
|
466
|
+
spans: list[tuple[int, int]] = []
|
|
467
|
+
for match in _RELATED_RE.finditer(text):
|
|
468
|
+
next_h2 = _NEXT_H2_RE.search(text, match.end())
|
|
469
|
+
footer = _FOOTER_RE.search(text, match.end())
|
|
470
|
+
candidates = [item.start() for item in (next_h2, footer) if item is not None]
|
|
471
|
+
spans.append((match.start(), min(candidates) if candidates else len(text)))
|
|
472
|
+
return spans
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def _merge_spans(spans: list[tuple[int, int]]) -> list[tuple[int, int]]:
|
|
476
|
+
merged: list[tuple[int, int]] = []
|
|
477
|
+
for start, end in sorted(spans):
|
|
478
|
+
if start >= end:
|
|
479
|
+
continue
|
|
480
|
+
if not merged or start > merged[-1][1]:
|
|
481
|
+
merged.append((start, end))
|
|
482
|
+
continue
|
|
483
|
+
previous_start, previous_end = merged[-1]
|
|
484
|
+
merged[-1] = (previous_start, max(previous_end, end))
|
|
485
|
+
return merged
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def _replace_wikilinks(text: str) -> str:
|
|
489
|
+
def replace(match: re.Match[str]) -> str:
|
|
490
|
+
raw = match.group(1).strip()
|
|
491
|
+
if "|" in raw:
|
|
492
|
+
return raw.rsplit("|", 1)[1].strip()
|
|
493
|
+
target = raw.split("#", 1)[0].strip()
|
|
494
|
+
return obsidian_target_name(target) if target else raw
|
|
495
|
+
|
|
496
|
+
return _WIKILINK_RE.sub(replace, text)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def _title_for(text: str, path: Path) -> str:
|
|
500
|
+
for line in text.splitlines():
|
|
501
|
+
if line.startswith("# "):
|
|
502
|
+
return line[2:].strip() or path.stem
|
|
503
|
+
return path.stem
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def _sha256_text(text: str) -> str:
|
|
507
|
+
import hashlib
|
|
508
|
+
|
|
509
|
+
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|