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,374 @@
|
|
|
1
|
+
"""Retry governance for expensive linker diagnosis runs."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Literal
|
|
7
|
+
|
|
8
|
+
from pydantic import ConfigDict, Field, field_validator
|
|
9
|
+
|
|
10
|
+
from mednotes.domains.wiki.batch_state import canonical_json_hash
|
|
11
|
+
from mednotes.domains.wiki.capabilities.notes.raw_chats import atomic_write_text
|
|
12
|
+
from mednotes.domains.wiki.common import _now_iso, wiki_cli_command
|
|
13
|
+
from mednotes.domains.wiki.flows.link.link_git import LINK_STATE_SCHEMA_V2, default_link_state_path, load_link_state
|
|
14
|
+
from mednotes.kernel.base import ContractModel, JsonObject, JsonObjectAdapter
|
|
15
|
+
|
|
16
|
+
REDUNDANT_DIAGNOSIS_REASON = "redundant_diagnosis_without_state_change"
|
|
17
|
+
FORCE_DIAGNOSE_EVENT_CODE = "linker.force_diagnose_override"
|
|
18
|
+
|
|
19
|
+
_IDENTITY_FIELDS = (
|
|
20
|
+
"snapshot_hash",
|
|
21
|
+
"git_status_hash",
|
|
22
|
+
"vocabulary_db_hash",
|
|
23
|
+
"related_notes_export_hash",
|
|
24
|
+
"diagnosis_options_hash",
|
|
25
|
+
"trigger_context_hash",
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _as_str(value: object) -> str:
|
|
30
|
+
return value if isinstance(value, str) else ""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _as_int(value: object, *, default: int = 0) -> int:
|
|
34
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
35
|
+
return value
|
|
36
|
+
return default
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class _LooseRetryInput(ContractModel):
|
|
40
|
+
"""Typed adapter for persisted retry state and diagnosis JSON."""
|
|
41
|
+
|
|
42
|
+
model_config = ConfigDict(extra="ignore", populate_by_name=True, validate_assignment=True)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class DiagnosisIdentity(ContractModel):
|
|
46
|
+
"""Stable fingerprint fields that decide whether a failed diagnosis is redundant."""
|
|
47
|
+
|
|
48
|
+
snapshot_hash: str = ""
|
|
49
|
+
git_status_hash: str = ""
|
|
50
|
+
git_head: str = ""
|
|
51
|
+
vocabulary_db_hash: str = ""
|
|
52
|
+
related_notes_export_hash: str = ""
|
|
53
|
+
diagnosis_options_hash: str = ""
|
|
54
|
+
trigger_context_hash: str = ""
|
|
55
|
+
|
|
56
|
+
def field_value(self, field: str) -> str:
|
|
57
|
+
match field:
|
|
58
|
+
case "snapshot_hash":
|
|
59
|
+
return self.snapshot_hash
|
|
60
|
+
case "git_status_hash":
|
|
61
|
+
return self.git_status_hash
|
|
62
|
+
case "vocabulary_db_hash":
|
|
63
|
+
return self.vocabulary_db_hash
|
|
64
|
+
case "related_notes_export_hash":
|
|
65
|
+
return self.related_notes_export_hash
|
|
66
|
+
case "diagnosis_options_hash":
|
|
67
|
+
return self.diagnosis_options_hash
|
|
68
|
+
case "trigger_context_hash":
|
|
69
|
+
return self.trigger_context_hash
|
|
70
|
+
case _:
|
|
71
|
+
return ""
|
|
72
|
+
|
|
73
|
+
def compact_payload(self) -> JsonObject:
|
|
74
|
+
return self.to_payload()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class _SnapshotIdentityFields(_LooseRetryInput):
|
|
78
|
+
snapshot_hash: str = ""
|
|
79
|
+
vocabulary_db_hash: str = ""
|
|
80
|
+
related_notes_export_hash: str = ""
|
|
81
|
+
|
|
82
|
+
@field_validator("snapshot_hash", "vocabulary_db_hash", "related_notes_export_hash", mode="before")
|
|
83
|
+
@classmethod
|
|
84
|
+
def _coerce_text(cls, value: object) -> str:
|
|
85
|
+
return _as_str(value)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class _GitIdentityFields(_LooseRetryInput):
|
|
89
|
+
status_hash: str = ""
|
|
90
|
+
head: str = ""
|
|
91
|
+
|
|
92
|
+
@field_validator("status_hash", "head", mode="before")
|
|
93
|
+
@classmethod
|
|
94
|
+
def _coerce_text(cls, value: object) -> str:
|
|
95
|
+
return _as_str(value)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class _DiagnosisBlockerFingerprint(_LooseRetryInput):
|
|
99
|
+
code: str = ""
|
|
100
|
+
blocking_action_count: int = 0
|
|
101
|
+
human_decision_count: int = 0
|
|
102
|
+
|
|
103
|
+
@field_validator("code", mode="before")
|
|
104
|
+
@classmethod
|
|
105
|
+
def _coerce_text(cls, value: object) -> str:
|
|
106
|
+
return _as_str(value)
|
|
107
|
+
|
|
108
|
+
@field_validator("blocking_action_count", "human_decision_count", mode="before")
|
|
109
|
+
@classmethod
|
|
110
|
+
def _coerce_count(cls, value: object) -> int:
|
|
111
|
+
return _as_int(value)
|
|
112
|
+
|
|
113
|
+
def compact_payload(self) -> JsonObject:
|
|
114
|
+
return self.to_payload()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class _DiagnosisPayloadFields(_LooseRetryInput):
|
|
118
|
+
status: str = ""
|
|
119
|
+
blocked_reason: str = ""
|
|
120
|
+
next_action: str = ""
|
|
121
|
+
diagnosis_path: str = ""
|
|
122
|
+
returncode: int = 3
|
|
123
|
+
blockers: list[_DiagnosisBlockerFingerprint] = Field(default_factory=list)
|
|
124
|
+
|
|
125
|
+
@field_validator("status", "blocked_reason", "next_action", "diagnosis_path", mode="before")
|
|
126
|
+
@classmethod
|
|
127
|
+
def _coerce_text(cls, value: object) -> str:
|
|
128
|
+
return _as_str(value)
|
|
129
|
+
|
|
130
|
+
@field_validator("returncode", mode="before")
|
|
131
|
+
@classmethod
|
|
132
|
+
def _coerce_returncode(cls, value: object) -> int:
|
|
133
|
+
return _as_int(value, default=3)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class _DiagnosisAttempt(_LooseRetryInput):
|
|
137
|
+
diagnosis_path: str = ""
|
|
138
|
+
status: str = ""
|
|
139
|
+
blocked_reason: str = ""
|
|
140
|
+
snapshot_hash: str = ""
|
|
141
|
+
git_status_hash: str = ""
|
|
142
|
+
vocabulary_db_hash: str = ""
|
|
143
|
+
related_notes_export_hash: str = ""
|
|
144
|
+
diagnosis_options_hash: str = ""
|
|
145
|
+
trigger_context_hash: str = ""
|
|
146
|
+
blocker_fingerprint: str = ""
|
|
147
|
+
next_action: str = ""
|
|
148
|
+
created_at: str = ""
|
|
149
|
+
|
|
150
|
+
@field_validator(
|
|
151
|
+
"diagnosis_path",
|
|
152
|
+
"status",
|
|
153
|
+
"blocked_reason",
|
|
154
|
+
"snapshot_hash",
|
|
155
|
+
"git_status_hash",
|
|
156
|
+
"vocabulary_db_hash",
|
|
157
|
+
"related_notes_export_hash",
|
|
158
|
+
"diagnosis_options_hash",
|
|
159
|
+
"trigger_context_hash",
|
|
160
|
+
"blocker_fingerprint",
|
|
161
|
+
"next_action",
|
|
162
|
+
"created_at",
|
|
163
|
+
mode="before",
|
|
164
|
+
)
|
|
165
|
+
@classmethod
|
|
166
|
+
def _coerce_text(cls, value: object) -> str:
|
|
167
|
+
return _as_str(value)
|
|
168
|
+
|
|
169
|
+
def matches_identity(self, identity: DiagnosisIdentity) -> bool:
|
|
170
|
+
return all(self.identity_field(field) == identity.field_value(field) for field in _IDENTITY_FIELDS)
|
|
171
|
+
|
|
172
|
+
def identity_field(self, field: str) -> str:
|
|
173
|
+
match field:
|
|
174
|
+
case "snapshot_hash":
|
|
175
|
+
return self.snapshot_hash
|
|
176
|
+
case "git_status_hash":
|
|
177
|
+
return self.git_status_hash
|
|
178
|
+
case "vocabulary_db_hash":
|
|
179
|
+
return self.vocabulary_db_hash
|
|
180
|
+
case "related_notes_export_hash":
|
|
181
|
+
return self.related_notes_export_hash
|
|
182
|
+
case "diagnosis_options_hash":
|
|
183
|
+
return self.diagnosis_options_hash
|
|
184
|
+
case "trigger_context_hash":
|
|
185
|
+
return self.trigger_context_hash
|
|
186
|
+
case _:
|
|
187
|
+
return ""
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class _LinkState(_LooseRetryInput):
|
|
191
|
+
last_diagnosis_attempt: _DiagnosisAttempt | None = None
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class _ForceDiagnoseAgentEvent(ContractModel):
|
|
195
|
+
schema_id: Literal["medical-notes-workbench.agent-event.v1"] = Field(
|
|
196
|
+
default="medical-notes-workbench.agent-event.v1",
|
|
197
|
+
alias="schema",
|
|
198
|
+
)
|
|
199
|
+
type: Literal["force_diagnose_override"] = "force_diagnose_override"
|
|
200
|
+
code: Literal["linker.force_diagnose_override"] = FORCE_DIAGNOSE_EVENT_CODE
|
|
201
|
+
severity: Literal["medium"] = "medium"
|
|
202
|
+
root_cause_code: Literal["force_diagnose_override"] = "force_diagnose_override"
|
|
203
|
+
workflow: Literal["/mednotes:link"] = "/mednotes:link"
|
|
204
|
+
phase: Literal["diagnosis"] = "diagnosis"
|
|
205
|
+
recovery_command: str
|
|
206
|
+
artifact_path: str
|
|
207
|
+
redacted_sample: JsonObject
|
|
208
|
+
next_action: str
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def diagnosis_options_hash(
|
|
212
|
+
*,
|
|
213
|
+
include_related_notes: bool,
|
|
214
|
+
llm_disambiguation: str,
|
|
215
|
+
llm_model: str | None,
|
|
216
|
+
llm_timeout: int,
|
|
217
|
+
) -> str:
|
|
218
|
+
return "sha256:" + canonical_json_hash(
|
|
219
|
+
{
|
|
220
|
+
"include_related_notes": include_related_notes,
|
|
221
|
+
"llm_disambiguation": llm_disambiguation,
|
|
222
|
+
"llm_model": llm_model or "",
|
|
223
|
+
"llm_timeout": int(llm_timeout),
|
|
224
|
+
}
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def trigger_context_hash(trigger_context: object | None) -> str:
|
|
229
|
+
payload = JsonObjectAdapter.validate_python(trigger_context or {})
|
|
230
|
+
return "sha256:" + canonical_json_hash(payload)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def build_diagnosis_identity(
|
|
234
|
+
*,
|
|
235
|
+
snapshot: object,
|
|
236
|
+
git_context: object,
|
|
237
|
+
trigger_context: object | None,
|
|
238
|
+
include_related_notes: bool,
|
|
239
|
+
llm_disambiguation: str,
|
|
240
|
+
llm_model: str | None,
|
|
241
|
+
llm_timeout: int,
|
|
242
|
+
) -> DiagnosisIdentity:
|
|
243
|
+
snapshot_fields = _SnapshotIdentityFields.model_validate(snapshot)
|
|
244
|
+
git_fields = _GitIdentityFields.model_validate(git_context)
|
|
245
|
+
return DiagnosisIdentity(
|
|
246
|
+
snapshot_hash=snapshot_fields.snapshot_hash,
|
|
247
|
+
git_status_hash=git_fields.status_hash,
|
|
248
|
+
git_head=git_fields.head,
|
|
249
|
+
vocabulary_db_hash=snapshot_fields.vocabulary_db_hash,
|
|
250
|
+
related_notes_export_hash=snapshot_fields.related_notes_export_hash,
|
|
251
|
+
diagnosis_options_hash=diagnosis_options_hash(
|
|
252
|
+
include_related_notes=include_related_notes,
|
|
253
|
+
llm_disambiguation=llm_disambiguation,
|
|
254
|
+
llm_model=llm_model,
|
|
255
|
+
llm_timeout=llm_timeout,
|
|
256
|
+
),
|
|
257
|
+
trigger_context_hash=trigger_context_hash(trigger_context),
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def redundant_diagnosis_payload(link_state: object, identity: DiagnosisIdentity) -> JsonObject | None:
|
|
262
|
+
state = _LinkState.model_validate(link_state)
|
|
263
|
+
last = state.last_diagnosis_attempt
|
|
264
|
+
if last is None:
|
|
265
|
+
return None
|
|
266
|
+
if last.status not in {"blocked", "failed"}:
|
|
267
|
+
return None
|
|
268
|
+
if not last.matches_identity(identity):
|
|
269
|
+
return None
|
|
270
|
+
diagnosis_path = Path(last.diagnosis_path)
|
|
271
|
+
if not diagnosis_path.is_file():
|
|
272
|
+
return None
|
|
273
|
+
try:
|
|
274
|
+
raw_payload = json.loads(diagnosis_path.read_text(encoding="utf-8"))
|
|
275
|
+
except (OSError, json.JSONDecodeError):
|
|
276
|
+
raw_payload = {}
|
|
277
|
+
payload = JsonObjectAdapter.validate_python(raw_payload if isinstance(raw_payload, dict) else {})
|
|
278
|
+
payload_fields = _DiagnosisPayloadFields.model_validate(payload)
|
|
279
|
+
blocked_reason = last.blocked_reason or payload_fields.blocked_reason or "link_plan_blocked"
|
|
280
|
+
next_action = last.next_action or payload_fields.next_action
|
|
281
|
+
payload.update(
|
|
282
|
+
{
|
|
283
|
+
"status": last.status or "blocked",
|
|
284
|
+
"blocked_reason": blocked_reason,
|
|
285
|
+
"diagnosis_path": str(diagnosis_path),
|
|
286
|
+
"skipped_reason": REDUNDANT_DIAGNOSIS_REASON,
|
|
287
|
+
"next_action": next_action,
|
|
288
|
+
"retry_governance": {
|
|
289
|
+
"skipped": True,
|
|
290
|
+
"skipped_reason": REDUNDANT_DIAGNOSIS_REASON,
|
|
291
|
+
"state_file": str(default_link_state_path()),
|
|
292
|
+
"blocker_fingerprint": last.blocker_fingerprint,
|
|
293
|
+
},
|
|
294
|
+
"agent_events": [
|
|
295
|
+
{
|
|
296
|
+
"schema": "medical-notes-workbench.agent-event.v1",
|
|
297
|
+
"type": "redundant_diagnosis_without_state_change",
|
|
298
|
+
"code": "agent.redundant_diagnosis_without_state_change",
|
|
299
|
+
"severity": "medium",
|
|
300
|
+
"root_cause_code": REDUNDANT_DIAGNOSIS_REASON,
|
|
301
|
+
"workflow": "/mednotes:link",
|
|
302
|
+
"phase": "diagnosis",
|
|
303
|
+
"recovery_command": last.next_action,
|
|
304
|
+
"artifact_path": str(diagnosis_path),
|
|
305
|
+
"redacted_sample": {
|
|
306
|
+
"blocked_reason": last.blocked_reason,
|
|
307
|
+
"blocker_fingerprint": last.blocker_fingerprint,
|
|
308
|
+
},
|
|
309
|
+
"next_action": last.next_action,
|
|
310
|
+
}
|
|
311
|
+
],
|
|
312
|
+
}
|
|
313
|
+
)
|
|
314
|
+
payload["returncode"] = payload_fields.returncode
|
|
315
|
+
return payload
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def record_diagnosis_attempt(
|
|
319
|
+
payload: object,
|
|
320
|
+
*,
|
|
321
|
+
identity: DiagnosisIdentity,
|
|
322
|
+
state_path: Path | None = None,
|
|
323
|
+
) -> JsonObject:
|
|
324
|
+
payload_fields = _DiagnosisPayloadFields.model_validate(payload)
|
|
325
|
+
state_model = load_link_state(state_path)
|
|
326
|
+
state: JsonObject = state_model.to_payload() if state_model is not None else {}
|
|
327
|
+
state["schema"] = LINK_STATE_SCHEMA_V2
|
|
328
|
+
state["generated_at"] = _now_iso()
|
|
329
|
+
if "snapshot_hash" not in state and identity.snapshot_hash:
|
|
330
|
+
state["snapshot_hash"] = identity.snapshot_hash
|
|
331
|
+
if "git_head" not in state and identity.git_head:
|
|
332
|
+
state["git_head"] = identity.git_head
|
|
333
|
+
if "git_status_hash" not in state and identity.git_status_hash:
|
|
334
|
+
state["git_status_hash"] = identity.git_status_hash
|
|
335
|
+
last = _DiagnosisAttempt(
|
|
336
|
+
diagnosis_path=payload_fields.diagnosis_path,
|
|
337
|
+
status=payload_fields.status,
|
|
338
|
+
blocked_reason=payload_fields.blocked_reason,
|
|
339
|
+
snapshot_hash=identity.snapshot_hash,
|
|
340
|
+
git_status_hash=identity.git_status_hash,
|
|
341
|
+
vocabulary_db_hash=identity.vocabulary_db_hash,
|
|
342
|
+
related_notes_export_hash=identity.related_notes_export_hash,
|
|
343
|
+
diagnosis_options_hash=identity.diagnosis_options_hash,
|
|
344
|
+
trigger_context_hash=identity.trigger_context_hash,
|
|
345
|
+
blocker_fingerprint=blocker_fingerprint(payload_fields),
|
|
346
|
+
next_action=payload_fields.next_action,
|
|
347
|
+
created_at=_now_iso(),
|
|
348
|
+
)
|
|
349
|
+
state["last_diagnosis_attempt"] = last.to_payload()
|
|
350
|
+
path = state_path or default_link_state_path()
|
|
351
|
+
atomic_write_text(path, json.dumps(state, ensure_ascii=False, indent=2) + "\n")
|
|
352
|
+
return state
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def blocker_fingerprint(payload: object) -> str:
|
|
356
|
+
payload_fields = _DiagnosisPayloadFields.model_validate(payload)
|
|
357
|
+
clean_blockers = [blocker.compact_payload() for blocker in payload_fields.blockers]
|
|
358
|
+
fingerprint_payload = JsonObjectAdapter.validate_python(
|
|
359
|
+
{
|
|
360
|
+
"status": payload_fields.status,
|
|
361
|
+
"blocked_reason": payload_fields.blocked_reason,
|
|
362
|
+
"blockers": clean_blockers,
|
|
363
|
+
}
|
|
364
|
+
)
|
|
365
|
+
return "sha256:" + canonical_json_hash(fingerprint_payload)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def force_diagnose_event(*, diagnosis_path: Path) -> JsonObject:
|
|
369
|
+
return _ForceDiagnoseAgentEvent(
|
|
370
|
+
recovery_command=wiki_cli_command("run-linker", "--diagnose", "--json"),
|
|
371
|
+
artifact_path=str(diagnosis_path),
|
|
372
|
+
redacted_sample={"override": "--force-diagnose"},
|
|
373
|
+
next_action="Confirmar que algum input mudou ou registrar por que o override era necessario.",
|
|
374
|
+
).to_payload()
|