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,277 @@
|
|
|
1
|
+
"""Apply process-chats canonical merges into existing Wiki notes."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from mednotes.domains.wiki.capabilities.graph.coverage import validate_raw_coverage_structure
|
|
10
|
+
from mednotes.domains.wiki.capabilities.markdown.markdown_query import (
|
|
11
|
+
MarkdownQueryUnavailable,
|
|
12
|
+
ensure_markdown_query_available,
|
|
13
|
+
markdown_query_blocked_payload,
|
|
14
|
+
)
|
|
15
|
+
from mednotes.domains.wiki.capabilities.notes.note_style.frontmatter import FrontmatterYamlUnavailable, infer_title
|
|
16
|
+
from mednotes.domains.wiki.capabilities.notes.provenance import _apply_note_provenance_from_raw_files
|
|
17
|
+
from mednotes.domains.wiki.capabilities.notes.raw_chats import atomic_write_text, mutate_raw_frontmatter
|
|
18
|
+
from mednotes.domains.wiki.capabilities.style.style import apply_style_rewrite
|
|
19
|
+
from mednotes.domains.wiki.capabilities.vocabulary.link_terms import normalize_key
|
|
20
|
+
from mednotes.domains.wiki.common import MissingPathError, ValidationError, _now_iso
|
|
21
|
+
from mednotes.domains.wiki.config import MedConfig, _path
|
|
22
|
+
from mednotes.domains.wiki.contracts.workflow_guardrails import annotate_payload
|
|
23
|
+
from mednotes.domains.wiki.flows.link.link_triggers import LINK_TRIGGER_CONTEXT_SCHEMA
|
|
24
|
+
|
|
25
|
+
CANONICAL_MERGE_APPLY_SCHEMA = "medical-notes-workbench.canonical-merge-apply.v1"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _load_coverage_primary_raw(path: Path) -> Path:
|
|
29
|
+
if not path.exists():
|
|
30
|
+
raise MissingPathError(f"Coverage inventory not found: {path}")
|
|
31
|
+
try:
|
|
32
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
33
|
+
except json.JSONDecodeError as exc:
|
|
34
|
+
raise ValidationError(f"Invalid coverage inventory JSON: {exc}") from exc
|
|
35
|
+
if not isinstance(data, dict):
|
|
36
|
+
raise ValidationError("Coverage inventory must be a JSON object")
|
|
37
|
+
raw_file = str(data.get("raw_file") or "").strip()
|
|
38
|
+
if not raw_file:
|
|
39
|
+
raise ValidationError("Coverage inventory missing raw_file")
|
|
40
|
+
return _path(raw_file)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _load_coverage_planned_meaning_keys(path: Path) -> set[str]:
|
|
44
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
45
|
+
items = data.get("items") if isinstance(data, dict) else None
|
|
46
|
+
if not isinstance(items, list):
|
|
47
|
+
return set()
|
|
48
|
+
return {
|
|
49
|
+
normalize_key(str(item.get("staged_title") or item.get("title") or ""))
|
|
50
|
+
for item in items
|
|
51
|
+
if isinstance(item, dict) and str(item.get("action") or "") == "planned_meaning"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _hash_if_present(path: Path) -> str:
|
|
56
|
+
return "sha256:" + hashlib.sha256(path.read_bytes()).hexdigest() if path.exists() else ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _wiki_relative_path(path: Path, config: MedConfig) -> str:
|
|
60
|
+
try:
|
|
61
|
+
return path.relative_to(config.wiki_dir).as_posix()
|
|
62
|
+
except ValueError:
|
|
63
|
+
return str(path)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _rollback(originals: dict[Path, str]) -> dict[str, list[str]]:
|
|
67
|
+
result = {"restored": [], "rollback_errors": []}
|
|
68
|
+
for path, text in originals.items():
|
|
69
|
+
try:
|
|
70
|
+
atomic_write_text(path, text)
|
|
71
|
+
result["restored"].append(str(path))
|
|
72
|
+
except Exception as exc: # pragma: no cover - OS-level rollback failure
|
|
73
|
+
result["rollback_errors"].append(f"{path}: {exc}")
|
|
74
|
+
return result
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _trigger_context(config: MedConfig, target_path: Path, *, coverage_path: Path) -> dict[str, Any]:
|
|
78
|
+
return {
|
|
79
|
+
"schema": LINK_TRIGGER_CONTEXT_SCHEMA,
|
|
80
|
+
"source_workflow": "/mednotes:process-chats",
|
|
81
|
+
"batch_id": str(coverage_path),
|
|
82
|
+
"changed_notes": [
|
|
83
|
+
{
|
|
84
|
+
"change_type": "modified",
|
|
85
|
+
"content_change": "text",
|
|
86
|
+
"path": _wiki_relative_path(target_path, config),
|
|
87
|
+
"title": target_path.stem,
|
|
88
|
+
"after_hash": _hash_if_present(target_path),
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _prepare_merge_content(content: str, *, content_path: Path, raw_paths: list[Path], coverage: dict[str, Any]) -> str:
|
|
95
|
+
title = infer_title(content, content_path)
|
|
96
|
+
try:
|
|
97
|
+
result = _apply_note_provenance_from_raw_files(
|
|
98
|
+
content,
|
|
99
|
+
raw_files=raw_paths,
|
|
100
|
+
title=title,
|
|
101
|
+
coverage_summary=coverage,
|
|
102
|
+
)
|
|
103
|
+
except FrontmatterYamlUnavailable as exc:
|
|
104
|
+
raise ValidationError(f"{exc.blocked_reason}: {exc.next_action}") from exc
|
|
105
|
+
except ValueError as exc:
|
|
106
|
+
raise ValidationError(f"chat_provenance_invalid: {exc}") from exc
|
|
107
|
+
return str(result["text"])
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def apply_canonical_merge(
|
|
111
|
+
config: MedConfig,
|
|
112
|
+
target_path: Path,
|
|
113
|
+
content_path: Path,
|
|
114
|
+
coverage_path: Path,
|
|
115
|
+
*,
|
|
116
|
+
dry_run: bool = False,
|
|
117
|
+
backup: bool = False,
|
|
118
|
+
) -> dict[str, Any]:
|
|
119
|
+
backup = False
|
|
120
|
+
raw_file = _load_coverage_primary_raw(coverage_path)
|
|
121
|
+
if not dry_run:
|
|
122
|
+
try:
|
|
123
|
+
ensure_markdown_query_available(
|
|
124
|
+
wiki_dir=config.wiki_dir,
|
|
125
|
+
raw_dir=config.raw_dir,
|
|
126
|
+
state_dir=config.state_dir,
|
|
127
|
+
)
|
|
128
|
+
except MarkdownQueryUnavailable as exc:
|
|
129
|
+
return annotate_payload(
|
|
130
|
+
{
|
|
131
|
+
**markdown_query_blocked_payload(
|
|
132
|
+
phase="canonical_merge_apply",
|
|
133
|
+
required_inputs=["target", "content", "coverage"],
|
|
134
|
+
),
|
|
135
|
+
"error_context": {
|
|
136
|
+
"blocked_reason": exc.blocked_reason,
|
|
137
|
+
"root_cause": "markdown_query_index_unavailable",
|
|
138
|
+
"affected_artifact": "markdown_query_index",
|
|
139
|
+
"error_summary": str(exc),
|
|
140
|
+
"suggested_fix": exc.next_action,
|
|
141
|
+
"next_action": exc.next_action,
|
|
142
|
+
"retry_scope": "setup_markdown_query_index_then_retry",
|
|
143
|
+
"details": exc.payload,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
phase="canonical_merge_apply",
|
|
147
|
+
status="blocked",
|
|
148
|
+
blocked_reason=exc.blocked_reason,
|
|
149
|
+
next_action=exc.next_action,
|
|
150
|
+
required_inputs=["target", "content", "coverage"],
|
|
151
|
+
human_decision_required=False,
|
|
152
|
+
)
|
|
153
|
+
coverage = validate_raw_coverage_structure(
|
|
154
|
+
coverage_path,
|
|
155
|
+
raw_file,
|
|
156
|
+
require_triage_note_plan=True,
|
|
157
|
+
)
|
|
158
|
+
coverage_keys = _load_coverage_planned_meaning_keys(coverage_path)
|
|
159
|
+
if normalize_key(target_path.stem) not in coverage_keys:
|
|
160
|
+
raise ValidationError(
|
|
161
|
+
"Canonical merge coverage does not include the existing target title: "
|
|
162
|
+
f"{target_path.stem}"
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
raw_paths = [_path(path) for path in coverage["raw_files"]]
|
|
166
|
+
prepared_content = _prepare_merge_content(
|
|
167
|
+
content_path.read_text(encoding="utf-8"),
|
|
168
|
+
content_path=content_path,
|
|
169
|
+
raw_paths=raw_paths,
|
|
170
|
+
coverage=coverage,
|
|
171
|
+
)
|
|
172
|
+
preflight = apply_style_rewrite(
|
|
173
|
+
target_path,
|
|
174
|
+
content_path,
|
|
175
|
+
dry_run=True,
|
|
176
|
+
backup=False,
|
|
177
|
+
rewritten_content=prepared_content,
|
|
178
|
+
)
|
|
179
|
+
result: dict[str, Any] = {
|
|
180
|
+
"schema": CANONICAL_MERGE_APPLY_SCHEMA,
|
|
181
|
+
"phase": "canonical_merge_apply",
|
|
182
|
+
"target_path": str(target_path),
|
|
183
|
+
"content_path": str(content_path),
|
|
184
|
+
"coverage_path": str(coverage_path),
|
|
185
|
+
"dry_run": dry_run,
|
|
186
|
+
"backup": backup,
|
|
187
|
+
"coverage": coverage,
|
|
188
|
+
"validation": preflight["validation"],
|
|
189
|
+
"changed": preflight["changed"],
|
|
190
|
+
"written": False,
|
|
191
|
+
"backup_path": None,
|
|
192
|
+
"raw_updates": [],
|
|
193
|
+
"processed_raw_count": 0,
|
|
194
|
+
"link_trigger_context": None,
|
|
195
|
+
}
|
|
196
|
+
if preflight["validation"]["errors"]:
|
|
197
|
+
return annotate_payload(
|
|
198
|
+
result,
|
|
199
|
+
phase="canonical_merge_apply",
|
|
200
|
+
status="blocked",
|
|
201
|
+
blocked_reason="validation_errors",
|
|
202
|
+
next_action="Corrigir o rewrite gerado pelo architect e repetir apply-canonical-merge --dry-run.",
|
|
203
|
+
required_inputs=["target", "content", "coverage"],
|
|
204
|
+
)
|
|
205
|
+
if not preflight["changed"]:
|
|
206
|
+
return annotate_payload(
|
|
207
|
+
result,
|
|
208
|
+
phase="canonical_merge_apply",
|
|
209
|
+
status="blocked",
|
|
210
|
+
blocked_reason="no_delta_to_merge",
|
|
211
|
+
next_action="Reclassificar a unidade como not_a_note se não houver delta, ou pedir novo rewrite ao architect.",
|
|
212
|
+
required_inputs=["target", "content", "coverage"],
|
|
213
|
+
)
|
|
214
|
+
if dry_run:
|
|
215
|
+
return annotate_payload(
|
|
216
|
+
result,
|
|
217
|
+
phase="canonical_merge_apply",
|
|
218
|
+
status="ready",
|
|
219
|
+
blocked_reason="",
|
|
220
|
+
next_action="Aplicar com apply-canonical-merge; rollback fica no ponto de restauração do vault.",
|
|
221
|
+
required_inputs=["target", "content", "coverage"],
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
originals = {target_path: target_path.read_text(encoding="utf-8")}
|
|
225
|
+
originals.update({path: path.read_text(encoding="utf-8") for path in raw_paths})
|
|
226
|
+
try:
|
|
227
|
+
applied = apply_style_rewrite(
|
|
228
|
+
target_path,
|
|
229
|
+
content_path,
|
|
230
|
+
dry_run=False,
|
|
231
|
+
backup=backup,
|
|
232
|
+
rewritten_content=prepared_content,
|
|
233
|
+
)
|
|
234
|
+
if applied["validation"]["errors"]:
|
|
235
|
+
result["validation"] = applied["validation"]
|
|
236
|
+
return annotate_payload(
|
|
237
|
+
result,
|
|
238
|
+
phase="canonical_merge_apply",
|
|
239
|
+
status="blocked",
|
|
240
|
+
blocked_reason="validation_errors",
|
|
241
|
+
next_action="Corrigir o rewrite gerado pelo architect e repetir apply-canonical-merge --dry-run.",
|
|
242
|
+
required_inputs=["target", "content", "coverage"],
|
|
243
|
+
)
|
|
244
|
+
result["written"] = bool(applied.get("written"))
|
|
245
|
+
result["backup_path"] = applied.get("backup_path")
|
|
246
|
+
raw_updates = [
|
|
247
|
+
mutate_raw_frontmatter(
|
|
248
|
+
path,
|
|
249
|
+
{"status": "processado", "processed_at": _now_iso()},
|
|
250
|
+
backup=backup,
|
|
251
|
+
)
|
|
252
|
+
for path in raw_paths
|
|
253
|
+
]
|
|
254
|
+
except Exception as exc:
|
|
255
|
+
rollback = _rollback(originals)
|
|
256
|
+
result["rollback"] = rollback
|
|
257
|
+
result["error"] = str(exc)
|
|
258
|
+
return annotate_payload(
|
|
259
|
+
result,
|
|
260
|
+
phase="canonical_merge_apply",
|
|
261
|
+
status="failed",
|
|
262
|
+
blocked_reason="io_error_rollback_performed",
|
|
263
|
+
next_action="Inspecionar erro de IO/rollback e repetir somente depois de liberar arquivos bloqueados.",
|
|
264
|
+
required_inputs=["target", "content", "coverage"],
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
result["raw_updates"] = raw_updates
|
|
268
|
+
result["processed_raw_count"] = len(raw_updates)
|
|
269
|
+
result["link_trigger_context"] = _trigger_context(config, target_path, coverage_path=coverage_path)
|
|
270
|
+
return annotate_payload(
|
|
271
|
+
result,
|
|
272
|
+
phase="canonical_merge_apply",
|
|
273
|
+
status="completed",
|
|
274
|
+
blocked_reason="",
|
|
275
|
+
next_action="Rodar linker a partir do trigger context gerado.",
|
|
276
|
+
required_inputs=["target", "content", "coverage"],
|
|
277
|
+
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Protected Markdown zones shared by Wiki workflows."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass(frozen=True, slots=True)
|
|
8
|
+
class MarkdownZone:
|
|
9
|
+
kind: str
|
|
10
|
+
start: int
|
|
11
|
+
end: int
|
|
12
|
+
start_line: int
|
|
13
|
+
end_line: int
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def protected_markdown_zones(text: str) -> list[MarkdownZone]:
|
|
17
|
+
zones: list[MarkdownZone] = []
|
|
18
|
+
lines = text.splitlines(keepends=True)
|
|
19
|
+
offset = 0
|
|
20
|
+
idx = 0
|
|
21
|
+
in_math = False
|
|
22
|
+
math_start = 0
|
|
23
|
+
math_start_line = 1
|
|
24
|
+
while idx < len(lines):
|
|
25
|
+
line = lines[idx]
|
|
26
|
+
stripped = line.strip().lower()
|
|
27
|
+
if stripped.startswith(("```", "~~~")):
|
|
28
|
+
marker = stripped[:3]
|
|
29
|
+
info = stripped[3:].strip()
|
|
30
|
+
kind = "fenced_mermaid" if info.startswith("mermaid") else "fenced_code"
|
|
31
|
+
start = offset
|
|
32
|
+
start_line = idx + 1
|
|
33
|
+
offset += len(line)
|
|
34
|
+
idx += 1
|
|
35
|
+
while idx < len(lines):
|
|
36
|
+
current = lines[idx]
|
|
37
|
+
current_stripped = current.strip().lower()
|
|
38
|
+
offset += len(current)
|
|
39
|
+
idx += 1
|
|
40
|
+
if current_stripped.startswith(marker):
|
|
41
|
+
break
|
|
42
|
+
zones.append(MarkdownZone(kind=kind, start=start, end=offset, start_line=start_line, end_line=idx))
|
|
43
|
+
continue
|
|
44
|
+
if stripped == "$$":
|
|
45
|
+
if not in_math:
|
|
46
|
+
in_math = True
|
|
47
|
+
math_start = offset
|
|
48
|
+
math_start_line = idx + 1
|
|
49
|
+
else:
|
|
50
|
+
zones.append(
|
|
51
|
+
MarkdownZone(
|
|
52
|
+
kind="display_math",
|
|
53
|
+
start=math_start,
|
|
54
|
+
end=offset + len(line),
|
|
55
|
+
start_line=math_start_line,
|
|
56
|
+
end_line=idx + 1,
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
in_math = False
|
|
60
|
+
offset += len(line)
|
|
61
|
+
idx += 1
|
|
62
|
+
if in_math:
|
|
63
|
+
zones.append(
|
|
64
|
+
MarkdownZone(
|
|
65
|
+
kind="display_math",
|
|
66
|
+
start=math_start,
|
|
67
|
+
end=len(text),
|
|
68
|
+
start_line=math_start_line,
|
|
69
|
+
end_line=len(lines),
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
return zones
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def blank_protected_markdown(text: str) -> str:
|
|
76
|
+
chars = list(text)
|
|
77
|
+
for zone in protected_markdown_zones(text):
|
|
78
|
+
for idx in range(zone.start, zone.end):
|
|
79
|
+
if chars[idx] != "\n":
|
|
80
|
+
chars[idx] = " "
|
|
81
|
+
return "".join(chars)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def is_protected_markdown_position(text: str, position: int) -> bool:
|
|
85
|
+
return any(zone.start <= position < zone.end for zone in protected_markdown_zones(text))
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"""Deterministic planner for triage-note-plan.v2 meaning work items."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
import sqlite3
|
|
6
|
+
import unicodedata
|
|
7
|
+
from dataclasses import asdict, dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from mednotes.domains.wiki.capabilities.notes.note_plan import (
|
|
12
|
+
PLANNED_MEANING_ACTION,
|
|
13
|
+
TRIAGE_NOTE_PLAN_V2_SCHEMA,
|
|
14
|
+
normalize_triage_note_plan_v2,
|
|
15
|
+
)
|
|
16
|
+
from mednotes.domains.wiki.capabilities.vocabulary.vocabulary_map import meaning_id_for
|
|
17
|
+
from mednotes.domains.wiki.common import SUBAGENT_PLAN_SCHEMA, ValidationError
|
|
18
|
+
from mednotes.domains.wiki.config import MedConfig
|
|
19
|
+
from mednotes.domains.wiki.contracts.workflow_outcomes import (
|
|
20
|
+
DecisionEvidence,
|
|
21
|
+
RejectedAutomation,
|
|
22
|
+
WorkflowDecision,
|
|
23
|
+
attach_human_decision_packet,
|
|
24
|
+
)
|
|
25
|
+
from mednotes.kernel.base import JsonObject
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class MeaningClaim:
|
|
30
|
+
label: str
|
|
31
|
+
scope: str
|
|
32
|
+
boundaries: tuple[str, ...]
|
|
33
|
+
kind: str
|
|
34
|
+
evidence_summary: str
|
|
35
|
+
id: str = ""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class MeaningWorkItem:
|
|
40
|
+
work_id: str
|
|
41
|
+
action: str
|
|
42
|
+
target_kind: str
|
|
43
|
+
raw_file: str
|
|
44
|
+
note_plan_item_id: str
|
|
45
|
+
meaning_claim: MeaningClaim
|
|
46
|
+
target_path: str = ""
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def plan_meaning_work_items(
|
|
50
|
+
config: MedConfig,
|
|
51
|
+
note_plan: dict[str, Any],
|
|
52
|
+
*,
|
|
53
|
+
raw_file: Path,
|
|
54
|
+
temp_root: Path,
|
|
55
|
+
agent: str = "med-knowledge-architect",
|
|
56
|
+
) -> dict[str, Any]:
|
|
57
|
+
try:
|
|
58
|
+
normalized = (
|
|
59
|
+
normalize_triage_note_plan_v2(note_plan, raw_file)
|
|
60
|
+
if note_plan.get("schema") == TRIAGE_NOTE_PLAN_V2_SCHEMA
|
|
61
|
+
else note_plan
|
|
62
|
+
)
|
|
63
|
+
except ValidationError as exc:
|
|
64
|
+
return _blocked_payload(
|
|
65
|
+
blocked_reason="meaning_claim_invalid",
|
|
66
|
+
message=str(exc),
|
|
67
|
+
raw_file=raw_file,
|
|
68
|
+
agent=agent,
|
|
69
|
+
)
|
|
70
|
+
if normalized.get("schema") != TRIAGE_NOTE_PLAN_V2_SCHEMA:
|
|
71
|
+
return _blocked_payload(
|
|
72
|
+
blocked_reason="note_plan_v2_required",
|
|
73
|
+
message="meaning planner requires triage-note-plan.v2",
|
|
74
|
+
raw_file=raw_file,
|
|
75
|
+
agent=agent,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
work_items: list[dict[str, Any]] = []
|
|
79
|
+
blocked_items: list[JsonObject] = []
|
|
80
|
+
for index, item in enumerate(normalized.get("items", []), start=1):
|
|
81
|
+
if item.get("action") != PLANNED_MEANING_ACTION:
|
|
82
|
+
continue
|
|
83
|
+
try:
|
|
84
|
+
claim = _meaning_claim(item.get("meaning_claim"))
|
|
85
|
+
except ValidationError as exc:
|
|
86
|
+
blocked_items.append(
|
|
87
|
+
_blocked_item(
|
|
88
|
+
raw_file=raw_file,
|
|
89
|
+
note_plan_item_id=str(item.get("id") or f"M{index:03d}"),
|
|
90
|
+
blocked_reason="meaning_claim_invalid",
|
|
91
|
+
message=str(exc),
|
|
92
|
+
)
|
|
93
|
+
)
|
|
94
|
+
continue
|
|
95
|
+
matches = _canonical_matches(config, _claim_id(claim))
|
|
96
|
+
if len(matches) > 1:
|
|
97
|
+
blocked_item = {
|
|
98
|
+
**_blocked_item(
|
|
99
|
+
raw_file=raw_file,
|
|
100
|
+
note_plan_item_id=str(item.get("id") or f"M{index:03d}"),
|
|
101
|
+
blocked_reason="human_decision_required.ambiguous_canonical_target",
|
|
102
|
+
message="More than one active canonical note is linked to this meaning_id.",
|
|
103
|
+
),
|
|
104
|
+
"meaning_claim": asdict(claim),
|
|
105
|
+
"candidate_targets": matches,
|
|
106
|
+
}
|
|
107
|
+
blocked_items.append(
|
|
108
|
+
attach_human_decision_packet(
|
|
109
|
+
blocked_item,
|
|
110
|
+
packet=_ambiguous_canonical_target_packet(
|
|
111
|
+
claim=claim,
|
|
112
|
+
matches=matches,
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
continue
|
|
117
|
+
if matches:
|
|
118
|
+
action = "rewrite_existing_note"
|
|
119
|
+
target_kind = "existing_wiki_note"
|
|
120
|
+
target_path = str(config.wiki_dir / matches[0]["path"])
|
|
121
|
+
else:
|
|
122
|
+
action = "create_new_note"
|
|
123
|
+
target_kind = "new_wiki_note"
|
|
124
|
+
target_path = ""
|
|
125
|
+
work_item = MeaningWorkItem(
|
|
126
|
+
work_id=f"meaning-{index:03d}-{_slug(claim.label)}",
|
|
127
|
+
action=action,
|
|
128
|
+
target_kind=target_kind,
|
|
129
|
+
raw_file=str(raw_file),
|
|
130
|
+
note_plan_item_id=str(item.get("id") or f"M{index:03d}"),
|
|
131
|
+
meaning_claim=claim,
|
|
132
|
+
target_path=target_path,
|
|
133
|
+
)
|
|
134
|
+
payload = asdict(work_item)
|
|
135
|
+
payload["agent"] = agent
|
|
136
|
+
payload["item_type"] = "meaning_work_item"
|
|
137
|
+
payload["launchable"] = True
|
|
138
|
+
payload["owner_key"] = target_path or f"meaning:{_claim_id(claim)}"
|
|
139
|
+
payload["temp_dir"] = str(temp_root / payload["work_id"])
|
|
140
|
+
payload["temp_output"] = str(temp_root / payload["work_id"] / f"{_slug(claim.label)}.md")
|
|
141
|
+
work_items.append(payload)
|
|
142
|
+
|
|
143
|
+
status = "blocked" if blocked_items else "ready"
|
|
144
|
+
return {
|
|
145
|
+
"schema": SUBAGENT_PLAN_SCHEMA,
|
|
146
|
+
"phase": "meaning-planner",
|
|
147
|
+
"agent": agent,
|
|
148
|
+
"status": status,
|
|
149
|
+
"blocked_reason": "preconditions_failed" if blocked_items else "",
|
|
150
|
+
"raw_file": str(raw_file),
|
|
151
|
+
"item_count": len(work_items),
|
|
152
|
+
"blocked_item_count": len(blocked_items),
|
|
153
|
+
"work_items": work_items,
|
|
154
|
+
"blocked_items": blocked_items,
|
|
155
|
+
"next_action": "" if not blocked_items else "Corrigir meaning_claim ou escolher alvo canônico antes do architect.",
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _meaning_claim(value: Any) -> MeaningClaim:
|
|
160
|
+
if not isinstance(value, dict):
|
|
161
|
+
raise ValidationError("meaning_claim missing")
|
|
162
|
+
missing = [
|
|
163
|
+
key
|
|
164
|
+
for key in ("label", "scope", "boundaries", "kind", "evidence_summary")
|
|
165
|
+
if key != "boundaries" and not str(value.get(key) or "").strip()
|
|
166
|
+
]
|
|
167
|
+
boundaries = value.get("boundaries")
|
|
168
|
+
if not isinstance(boundaries, list):
|
|
169
|
+
missing.append("boundaries")
|
|
170
|
+
if missing:
|
|
171
|
+
raise ValidationError(f"meaning_claim missing required fields: {', '.join(missing)}")
|
|
172
|
+
assert isinstance(boundaries, list)
|
|
173
|
+
boundaries_list = boundaries
|
|
174
|
+
return MeaningClaim(
|
|
175
|
+
label=str(value["label"]).strip(),
|
|
176
|
+
scope=str(value["scope"]).strip(),
|
|
177
|
+
boundaries=tuple(str(item).strip() for item in boundaries_list if str(item).strip()),
|
|
178
|
+
kind=str(value["kind"]).strip(),
|
|
179
|
+
evidence_summary=str(value["evidence_summary"]).strip(),
|
|
180
|
+
id=str(value.get("id") or value.get("meaning_id") or "").strip(),
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _claim_id(claim: MeaningClaim) -> str:
|
|
185
|
+
return claim.id or meaning_id_for(claim.label)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _canonical_matches(config: MedConfig, meaning_id: str) -> list[dict[str, str]]:
|
|
189
|
+
db_path = config.vocabulary_db_path
|
|
190
|
+
if db_path is None or not db_path.exists():
|
|
191
|
+
return []
|
|
192
|
+
with sqlite3.connect(db_path) as conn:
|
|
193
|
+
conn.row_factory = sqlite3.Row
|
|
194
|
+
rows = conn.execute(
|
|
195
|
+
"""
|
|
196
|
+
SELECT n.path, n.title, l.confidence
|
|
197
|
+
FROM meaning_note_links l
|
|
198
|
+
JOIN meanings m ON m.id = l.meaning_id AND m.status = 'active'
|
|
199
|
+
JOIN notes n ON n.id = l.note_id AND n.status = 'active'
|
|
200
|
+
WHERE l.meaning_id = ?
|
|
201
|
+
AND l.role = 'canonical'
|
|
202
|
+
AND l.status = 'active'
|
|
203
|
+
ORDER BY l.confidence DESC, n.path ASC
|
|
204
|
+
""",
|
|
205
|
+
(meaning_id,),
|
|
206
|
+
).fetchall()
|
|
207
|
+
return [
|
|
208
|
+
{
|
|
209
|
+
"path": str(row["path"]),
|
|
210
|
+
"title": str(row["title"]),
|
|
211
|
+
"confidence": str(row["confidence"]),
|
|
212
|
+
}
|
|
213
|
+
for row in rows
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _ambiguous_canonical_target_packet(
|
|
218
|
+
*,
|
|
219
|
+
claim: MeaningClaim,
|
|
220
|
+
matches: list[dict[str, str]],
|
|
221
|
+
) -> dict[str, Any]:
|
|
222
|
+
options = [
|
|
223
|
+
{
|
|
224
|
+
"id": f"use_{idx}",
|
|
225
|
+
"label": match["path"],
|
|
226
|
+
"value": match["path"],
|
|
227
|
+
"consequence": "O architect reescreve esse alvo canônico com o delta do raw chat.",
|
|
228
|
+
}
|
|
229
|
+
for idx, match in enumerate(matches, start=1)
|
|
230
|
+
]
|
|
231
|
+
decision = WorkflowDecision(
|
|
232
|
+
kind="ask_human",
|
|
233
|
+
phase="meaning-planner",
|
|
234
|
+
reason_code="human_decision_required.ambiguous_canonical_target",
|
|
235
|
+
public_summary=f"Qual nota canônica deve receber '{claim.label}'?",
|
|
236
|
+
developer_summary="More than one active canonical note is linked to this meaning_id.",
|
|
237
|
+
evidence=[
|
|
238
|
+
DecisionEvidence(
|
|
239
|
+
summary=f"'{claim.label}' possui múltiplos alvos canônicos ativos.",
|
|
240
|
+
technical_code="human_decision_required.ambiguous_canonical_target",
|
|
241
|
+
source="meaning-planner",
|
|
242
|
+
candidates=[{"meaning_claim": asdict(claim), "candidate_targets": matches}],
|
|
243
|
+
risk="Escolha automática pode reescrever a nota canônica errada.",
|
|
244
|
+
)
|
|
245
|
+
],
|
|
246
|
+
rejected_automations=[
|
|
247
|
+
RejectedAutomation(
|
|
248
|
+
kind="auto_fix",
|
|
249
|
+
reason_code="ambiguous_canonical_target",
|
|
250
|
+
reason="Nao ha alvo canonico unico para corrigir automaticamente.",
|
|
251
|
+
),
|
|
252
|
+
RejectedAutomation(
|
|
253
|
+
kind="auto_defer",
|
|
254
|
+
reason_code="blocks_architect",
|
|
255
|
+
reason="Pular a escolha impediria cobertura correta do raw chat.",
|
|
256
|
+
),
|
|
257
|
+
RejectedAutomation(
|
|
258
|
+
kind="auto_plan",
|
|
259
|
+
reason_code="plan_needs_canonical_target",
|
|
260
|
+
reason="O plano precisa de um alvo canonico antes de lancar o architect.",
|
|
261
|
+
),
|
|
262
|
+
],
|
|
263
|
+
next_action="Registrar a escolha e reexecutar plan-subagents --phase architect.",
|
|
264
|
+
resume_action="Registrar a escolha e reexecutar plan-subagents --phase architect.",
|
|
265
|
+
recommended_option_id=str(options[0]["id"]),
|
|
266
|
+
options=options,
|
|
267
|
+
)
|
|
268
|
+
packet = decision.to_human_decision_packet()
|
|
269
|
+
packet["kind"] = "ambiguous_canonical_target"
|
|
270
|
+
packet["type"] = "ambiguous_canonical_target"
|
|
271
|
+
return packet
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _blocked_item(*, raw_file: Path, note_plan_item_id: str, blocked_reason: str, message: str) -> JsonObject:
|
|
275
|
+
return {
|
|
276
|
+
"work_id": f"meaning-blocked-{_slug(note_plan_item_id)}",
|
|
277
|
+
"item_type": "meaning_work_item",
|
|
278
|
+
"raw_file": str(raw_file),
|
|
279
|
+
"note_plan_item_id": note_plan_item_id,
|
|
280
|
+
"blocked_reason": blocked_reason,
|
|
281
|
+
"reason": message,
|
|
282
|
+
"launchable": False,
|
|
283
|
+
"write_policy": "no_temp_note",
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _blocked_payload(*, blocked_reason: str, message: str, raw_file: Path, agent: str) -> JsonObject:
|
|
288
|
+
item = _blocked_item(raw_file=raw_file, note_plan_item_id="", blocked_reason=blocked_reason, message=message)
|
|
289
|
+
return {
|
|
290
|
+
"schema": SUBAGENT_PLAN_SCHEMA,
|
|
291
|
+
"phase": "meaning-planner",
|
|
292
|
+
"agent": agent,
|
|
293
|
+
"status": "blocked",
|
|
294
|
+
"blocked_reason": blocked_reason,
|
|
295
|
+
"raw_file": str(raw_file),
|
|
296
|
+
"item_count": 0,
|
|
297
|
+
"blocked_item_count": 1,
|
|
298
|
+
"work_items": [],
|
|
299
|
+
"blocked_items": [item],
|
|
300
|
+
"next_action": "Corrigir triage-note-plan.v2 antes de lançar architect.",
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _slug(value: str) -> str:
|
|
305
|
+
normalized = unicodedata.normalize("NFKD", value)
|
|
306
|
+
ascii_text = "".join(char for char in normalized if not unicodedata.combining(char))
|
|
307
|
+
return re.sub(r"[^a-zA-Z0-9._-]+", "-", ascii_text).strip("-._").lower() or "meaning"
|