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,103 @@
|
|
|
1
|
+
export function firstString(...values) {
|
|
2
|
+
for (const value of values) {
|
|
3
|
+
if (typeof value === "string" && value.length > 0) return value;
|
|
4
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
5
|
+
}
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function firstObject(...values) {
|
|
10
|
+
for (const value of values) {
|
|
11
|
+
if (value && typeof value === "object" && !Array.isArray(value)) return value;
|
|
12
|
+
}
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function normalizedArgs(args) {
|
|
17
|
+
const input = args && typeof args === "object" ? { ...args } : {};
|
|
18
|
+
const command = firstString(input.command, input.cmd, input.script, input.CommandLine);
|
|
19
|
+
const cwd = firstString(input.cwd, input.Cwd, input.workingDirectory, input.WorkingDirectory);
|
|
20
|
+
const target = firstString(
|
|
21
|
+
input.file_path,
|
|
22
|
+
input.filePath,
|
|
23
|
+
input.path,
|
|
24
|
+
input.TargetFile,
|
|
25
|
+
input.AbsolutePath,
|
|
26
|
+
input.SearchDirectory,
|
|
27
|
+
input.DirectoryPath,
|
|
28
|
+
);
|
|
29
|
+
if (command) input.command = command;
|
|
30
|
+
if (cwd) input.cwd = cwd;
|
|
31
|
+
if (target) {
|
|
32
|
+
input.file_path = target;
|
|
33
|
+
input.target_file = target;
|
|
34
|
+
}
|
|
35
|
+
return input;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function isAgyRuntime(payload) {
|
|
39
|
+
return (
|
|
40
|
+
Boolean(payload?.antigravity_payload_seen) ||
|
|
41
|
+
Boolean(payload?.hookEventName || payload?.conversationId || payload?.workspacePaths)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function runtimeFromPayload(payload) {
|
|
46
|
+
if (isAgyRuntime(payload)) return "antigravity";
|
|
47
|
+
if (
|
|
48
|
+
payload?.opencode_payload_seen ||
|
|
49
|
+
payload?.opencodePayloadSeen ||
|
|
50
|
+
String(payload?.runtime || "").toLowerCase() === "opencode" ||
|
|
51
|
+
String(payload?.harness || "").toLowerCase() === "opencode"
|
|
52
|
+
) {
|
|
53
|
+
return "opencode";
|
|
54
|
+
}
|
|
55
|
+
return "gemini-cli";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function isOpenCodeRuntime(payload, card = null) {
|
|
59
|
+
return runtimeFromPayload(payload) === "opencode" || String(card?.runtime || "") === "opencode";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function sessionIdFromPayload(payload) {
|
|
63
|
+
return cleanFileStem(String(payload?.session_id || payload?.conversation_id || payload?.conversationId || ""));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function cleanFileStem(value) {
|
|
67
|
+
return String(value || "")
|
|
68
|
+
.replace(/[^a-zA-Z0-9_.-]/g, "_")
|
|
69
|
+
.slice(0, 120);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function toolInput(payload) {
|
|
73
|
+
return firstObject(payload?.tool_input, payload?.toolInput, payload?.input, payload?.parameters, payload?.args);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function normalizedToolName(payload) {
|
|
77
|
+
return String(payload?.tool_name || payload?.toolName || payload?.name || payload?.tool || "")
|
|
78
|
+
.trim()
|
|
79
|
+
.toLowerCase();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function toolCommandLine(payload) {
|
|
83
|
+
const input = toolInput(payload);
|
|
84
|
+
return String(input.command || input.CommandLine || input.commandLine || input.cmd || input.script || "");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function hookEventNameFromPayload(payload) {
|
|
88
|
+
return String(payload?.hook_event_name || payload?.hookEventName || "");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function normalizeHookEvent(payload, card = null) {
|
|
92
|
+
const runtime = card && String(card.runtime || "") ? String(card.runtime) : runtimeFromPayload(payload);
|
|
93
|
+
return {
|
|
94
|
+
runtime,
|
|
95
|
+
eventName: hookEventNameFromPayload(payload),
|
|
96
|
+
sessionId: sessionIdFromPayload(payload),
|
|
97
|
+
toolName: normalizedToolName(payload),
|
|
98
|
+
toolInput: toolInput(payload),
|
|
99
|
+
toolResponse: firstObject(payload?.tool_response, payload?.toolResponse, payload?.response, payload?.result),
|
|
100
|
+
cwd: String(payload?.cwd || ""),
|
|
101
|
+
transcriptPath: String(payload?.transcript_path || payload?.transcriptPath || ""),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
captureAgentDirectiveAfterTool,
|
|
8
|
+
guardAgentDirectiveBeforeTool,
|
|
9
|
+
injectAgentDirectiveBeforeAgent,
|
|
10
|
+
} from "../fsm_directive.mjs";
|
|
11
|
+
import { applyMedNotesOpenCodeRuntimeConfig } from "./opencode_user_config_sync.mjs";
|
|
12
|
+
|
|
13
|
+
const OPENCODE_TASK_METADATA_SCHEMA = "medical-notes-workbench.opencode-specialist-task-metadata.v1";
|
|
14
|
+
const OPENCODE_SPECIALIST_RAW_CONTENT_KEYS = new Set([
|
|
15
|
+
"content",
|
|
16
|
+
"markdown",
|
|
17
|
+
"raw_chat",
|
|
18
|
+
"raw_chat_content",
|
|
19
|
+
"raw_markdown",
|
|
20
|
+
"raw_markdown_content",
|
|
21
|
+
"note_text",
|
|
22
|
+
"html",
|
|
23
|
+
]);
|
|
24
|
+
const OPENCODE_SPECIALIST_SAFE_TEXT_KEYS = new Set([
|
|
25
|
+
"agent",
|
|
26
|
+
"attestation_created_by",
|
|
27
|
+
"expected_model",
|
|
28
|
+
"item_type",
|
|
29
|
+
"model_policy",
|
|
30
|
+
"missing_specialist_task_run_receipt_action",
|
|
31
|
+
"phase",
|
|
32
|
+
"preferred_model_tier",
|
|
33
|
+
"raw_file",
|
|
34
|
+
"required_model_tier",
|
|
35
|
+
"rewrite_prompt",
|
|
36
|
+
"schema",
|
|
37
|
+
"source_work_id",
|
|
38
|
+
"specialist_task_run_receipt_path",
|
|
39
|
+
"staged_title",
|
|
40
|
+
"target_hash_before",
|
|
41
|
+
"target_path",
|
|
42
|
+
"target_kind",
|
|
43
|
+
"temp_output",
|
|
44
|
+
"temp_output_path",
|
|
45
|
+
"title",
|
|
46
|
+
"coverage_path",
|
|
47
|
+
"taxonomy",
|
|
48
|
+
"work_id",
|
|
49
|
+
"write_markdown_to",
|
|
50
|
+
"write_policy",
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
function hookPayload(input, output = {}, eventName) {
|
|
54
|
+
const toolState = firstObjectValue(output?.state, input?.state, output?.part?.state, input?.part?.state);
|
|
55
|
+
return {
|
|
56
|
+
hook_event_name: eventName,
|
|
57
|
+
runtime: "opencode",
|
|
58
|
+
opencode_payload_seen: true,
|
|
59
|
+
session_id: String(input?.sessionID || ""),
|
|
60
|
+
tool_name: opencodeToolName(input, output),
|
|
61
|
+
tool_input: firstObjectValue(output?.args, input?.args, toolState.input, output?.input, input?.input),
|
|
62
|
+
tool_response: {
|
|
63
|
+
title: String(output?.title || toolState.title || ""),
|
|
64
|
+
output: String(output?.output || toolState.output || ""),
|
|
65
|
+
metadata: firstObjectValue(output?.metadata, input?.metadata, toolState.metadata),
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function opencodeToolName(input, output = {}) {
|
|
71
|
+
return String(
|
|
72
|
+
input?.tool || output?.tool || input?.toolName || output?.toolName || input?.part?.tool || output?.part?.tool || "",
|
|
73
|
+
).toLowerCase();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function denialMessage(result) {
|
|
77
|
+
if (result?.decision !== "deny") return "";
|
|
78
|
+
return [result.blocked_reason, result.directive_field, result.reason, result.agent_message]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join(" | ");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function appHomeDir() {
|
|
84
|
+
return path.resolve(process.env.MEDNOTES_HOME || path.join(os.homedir(), ".mednotes"));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function safeFileStem(value) {
|
|
88
|
+
return (
|
|
89
|
+
String(value || "")
|
|
90
|
+
.replace(/[^a-zA-Z0-9_.-]/g, "_")
|
|
91
|
+
.slice(0, 120) || "unknown"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function objectValue(value) {
|
|
96
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function firstObjectValue(...values) {
|
|
100
|
+
for (const value of values) {
|
|
101
|
+
const candidate = objectValue(value);
|
|
102
|
+
if (Object.keys(candidate).length > 0) return candidate;
|
|
103
|
+
}
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function sha256Text(value) {
|
|
108
|
+
return `sha256:${crypto
|
|
109
|
+
.createHash("sha256")
|
|
110
|
+
.update(String(value || ""))
|
|
111
|
+
.digest("hex")}`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function parseJsonObjectFromText(value) {
|
|
115
|
+
const text = String(value || "").trim();
|
|
116
|
+
try {
|
|
117
|
+
const parsed = JSON.parse(text);
|
|
118
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
119
|
+
} catch {
|
|
120
|
+
// Continue below for prompts that wrap the JSON work item with small prose.
|
|
121
|
+
}
|
|
122
|
+
const start = text.indexOf("{");
|
|
123
|
+
if (start < 0) return {};
|
|
124
|
+
let depth = 0;
|
|
125
|
+
let inString = false;
|
|
126
|
+
let escaped = false;
|
|
127
|
+
for (let index = start; index < text.length; index += 1) {
|
|
128
|
+
const char = text[index];
|
|
129
|
+
if (escaped) {
|
|
130
|
+
escaped = false;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (char === "\\") {
|
|
134
|
+
escaped = true;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (char === '"') {
|
|
138
|
+
inString = !inString;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (inString) continue;
|
|
142
|
+
if (char === "{") depth += 1;
|
|
143
|
+
if (char === "}") {
|
|
144
|
+
depth -= 1;
|
|
145
|
+
if (depth === 0) {
|
|
146
|
+
try {
|
|
147
|
+
const parsed = JSON.parse(text.slice(start, index + 1));
|
|
148
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
149
|
+
} catch {
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function typedWorkItemFromPrompt(prompt) {
|
|
159
|
+
const packet = parseJsonObjectFromText(prompt);
|
|
160
|
+
const candidates = [
|
|
161
|
+
packet,
|
|
162
|
+
objectValue(packet.work_item),
|
|
163
|
+
objectValue(packet.workItem),
|
|
164
|
+
...(Array.isArray(packet.current_batch_items) ? packet.current_batch_items : []),
|
|
165
|
+
...(Array.isArray(packet.currentBatchItems) ? packet.currentBatchItems : []),
|
|
166
|
+
];
|
|
167
|
+
for (const candidate of candidates) {
|
|
168
|
+
const workItem = objectValue(candidate);
|
|
169
|
+
if (!workItem.work_id || !workItem.temp_output) continue;
|
|
170
|
+
if (isStyleRewriteWorkItem(workItem) || isArchitectWorkItem(workItem)) return workItem;
|
|
171
|
+
}
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function isStyleRewriteWorkItem(workItem) {
|
|
176
|
+
if (!workItem.target_hash_before) return false;
|
|
177
|
+
if (!workItem.subagent_output_contract || typeof workItem.subagent_output_contract !== "object") return false;
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function isArchitectWorkItem(workItem) {
|
|
182
|
+
const expected = objectValue(workItem.expected_output_schema);
|
|
183
|
+
if (String(workItem.phase || "") !== "architect") return false;
|
|
184
|
+
if (String(workItem.agent || "") !== "med-knowledge-architect") return false;
|
|
185
|
+
if (String(workItem.item_type || "") !== "meaning_work_item") return false;
|
|
186
|
+
if (String(expected.schema || "") !== "medical-notes-workbench.architect-output.v1") return false;
|
|
187
|
+
if (!workItem.raw_file) return false;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function architectOutputFromTaskResponse(outputText) {
|
|
192
|
+
const payload = parseJsonObjectFromText(outputText);
|
|
193
|
+
if (String(payload.schema || "") !== "medical-notes-workbench.architect-output.v1") {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
return payload;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function writeArchitectOutputArtifact(workItem, outputText) {
|
|
200
|
+
if (!isArchitectWorkItem(workItem)) return;
|
|
201
|
+
const artifact = architectOutputFromTaskResponse(outputText);
|
|
202
|
+
if (!artifact.schema) return;
|
|
203
|
+
if (String(artifact.temp_output_path || "") !== String(workItem.temp_output || "")) return;
|
|
204
|
+
const baseDir = path.join(appHomeDir(), "hook-state", "opencode-task-output");
|
|
205
|
+
const byWorkIdPath = path.join(baseDir, "by-work-id", `${safeFileStem(workItem.work_id)}.json`);
|
|
206
|
+
const text = `${JSON.stringify(artifact, null, 2)}\n`;
|
|
207
|
+
await fs.mkdir(path.dirname(byWorkIdPath), { recursive: true });
|
|
208
|
+
await fs.writeFile(byWorkIdPath, text, "utf8");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function looksLikeRawContent(prompt) {
|
|
212
|
+
const text = String(prompt || "");
|
|
213
|
+
return (
|
|
214
|
+
/(^|\n)---\s*\n[\s\S]{0,200}\n---\s*\n#\s+/m.test(text) ||
|
|
215
|
+
/\bChats_Raw\b|\bWiki_Medicina\b|\[Chat Original\]|gemini\.google\.com\/app\//i.test(text) ||
|
|
216
|
+
/<(?:!doctype|html|body|article|section)\b/i.test(text)
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function promptEmbedsRawContent(prompt) {
|
|
221
|
+
const packet = parseJsonObjectFromText(prompt);
|
|
222
|
+
const items = Array.isArray(packet.current_batch_items) ? packet.current_batch_items : [];
|
|
223
|
+
if (items.length === 1 && Object.keys(packet).length === 1) {
|
|
224
|
+
return workItemEmbedsRawContent(items[0]);
|
|
225
|
+
}
|
|
226
|
+
return looksLikeRawContent(prompt);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function workItemEmbedsRawContent(value, parentKey = "") {
|
|
230
|
+
if (Array.isArray(value)) return value.some((item) => workItemEmbedsRawContent(item, parentKey));
|
|
231
|
+
if (!value || typeof value !== "object") {
|
|
232
|
+
if (typeof value !== "string") return false;
|
|
233
|
+
const key = String(parentKey || "").toLowerCase();
|
|
234
|
+
if (OPENCODE_SPECIALIST_SAFE_TEXT_KEYS.has(key)) return false;
|
|
235
|
+
return looksLikeRawContent(value);
|
|
236
|
+
}
|
|
237
|
+
for (const [key, item] of Object.entries(value)) {
|
|
238
|
+
const normalizedKey = String(key || "").toLowerCase();
|
|
239
|
+
if (OPENCODE_SPECIALIST_RAW_CONTENT_KEYS.has(normalizedKey)) return true;
|
|
240
|
+
if (workItemEmbedsRawContent(item, normalizedKey)) return true;
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function writeNativeTaskMetadata(input, output = {}) {
|
|
246
|
+
const toolName = String(input?.tool || output?.tool || input?.part?.tool || output?.part?.tool || "").toLowerCase();
|
|
247
|
+
if (toolName !== "task") return;
|
|
248
|
+
const state = firstObjectValue(output?.state, input?.state, output?.part?.state, input?.part?.state);
|
|
249
|
+
const status = String(state.status || output?.status || input?.status || "").toLowerCase();
|
|
250
|
+
if (status && status !== "completed") return;
|
|
251
|
+
const args = firstObjectValue(output?.args, input?.args, state.input, output?.input, input?.input);
|
|
252
|
+
const prompt = String(args?.prompt || "");
|
|
253
|
+
const workItem = typedWorkItemFromPrompt(prompt);
|
|
254
|
+
if (!workItem.work_id) return;
|
|
255
|
+
const metadata = firstObjectValue(
|
|
256
|
+
output?.metadata,
|
|
257
|
+
input?.metadata,
|
|
258
|
+
state.metadata,
|
|
259
|
+
output?.part?.state?.metadata,
|
|
260
|
+
input?.part?.state?.metadata,
|
|
261
|
+
);
|
|
262
|
+
const model = objectValue(metadata.model);
|
|
263
|
+
const taskSessionId = String(metadata.sessionId || "");
|
|
264
|
+
const parentSessionId = String(metadata.parentSessionId || input?.sessionID || "");
|
|
265
|
+
const providerId = String(model.providerID || "");
|
|
266
|
+
const modelId = String(model.modelID || "");
|
|
267
|
+
if (!taskSessionId || !parentSessionId || !providerId || !modelId) return;
|
|
268
|
+
|
|
269
|
+
const payload = {
|
|
270
|
+
schema: OPENCODE_TASK_METADATA_SCHEMA,
|
|
271
|
+
work_id: String(workItem.work_id),
|
|
272
|
+
task_id: taskSessionId,
|
|
273
|
+
parent_session_id: parentSessionId,
|
|
274
|
+
specialist_session_id: taskSessionId,
|
|
275
|
+
provider_id: providerId,
|
|
276
|
+
model_id: modelId,
|
|
277
|
+
model_tier: "specialist",
|
|
278
|
+
tool_sequence: ["task"],
|
|
279
|
+
prompt_contract: "single_current_batch_items_json",
|
|
280
|
+
raw_content_embedded: promptEmbedsRawContent(prompt),
|
|
281
|
+
capture_source: "opencode_tool_execute_after",
|
|
282
|
+
capture_session_id: String(input?.sessionID || parentSessionId),
|
|
283
|
+
tool_call_id: String(
|
|
284
|
+
input?.callID ||
|
|
285
|
+
input?.callId ||
|
|
286
|
+
output?.callID ||
|
|
287
|
+
output?.callId ||
|
|
288
|
+
input?.part?.callID ||
|
|
289
|
+
output?.part?.callID ||
|
|
290
|
+
"",
|
|
291
|
+
),
|
|
292
|
+
tool_prompt_sha256: sha256Text(prompt),
|
|
293
|
+
tool_response_sha256: sha256Text(output?.output || state.output || input?.output || ""),
|
|
294
|
+
captured_at: new Date().toISOString(),
|
|
295
|
+
};
|
|
296
|
+
const baseDir = path.join(appHomeDir(), "hook-state", "opencode-task-metadata");
|
|
297
|
+
const byWorkIdPath = path.join(baseDir, "by-work-id", `${safeFileStem(workItem.work_id)}.json`);
|
|
298
|
+
const bySessionPath = path.join(
|
|
299
|
+
baseDir,
|
|
300
|
+
"by-session",
|
|
301
|
+
safeFileStem(parentSessionId),
|
|
302
|
+
`${safeFileStem(workItem.work_id)}.json`,
|
|
303
|
+
);
|
|
304
|
+
const text = `${JSON.stringify(payload, null, 2)}\n`;
|
|
305
|
+
await fs.mkdir(path.dirname(byWorkIdPath), { recursive: true });
|
|
306
|
+
await fs.writeFile(byWorkIdPath, text, "utf8");
|
|
307
|
+
await fs.mkdir(path.dirname(bySessionPath), { recursive: true });
|
|
308
|
+
await fs.writeFile(bySessionPath, text, "utf8");
|
|
309
|
+
await writeArchitectOutputArtifact(workItem, String(output?.output || state.output || input?.output || ""));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export const server = async () => ({
|
|
313
|
+
config: async (config) => {
|
|
314
|
+
applyMedNotesOpenCodeRuntimeConfig(config);
|
|
315
|
+
},
|
|
316
|
+
"experimental.chat.system.transform": async (input, output) => {
|
|
317
|
+
const result = await injectAgentDirectiveBeforeAgent({
|
|
318
|
+
hook_event_name: "BeforeAgent",
|
|
319
|
+
runtime: "opencode",
|
|
320
|
+
opencode_payload_seen: true,
|
|
321
|
+
session_id: String(input?.sessionID || ""),
|
|
322
|
+
});
|
|
323
|
+
const context = result?.hookSpecificOutput?.additionalContext;
|
|
324
|
+
if (context) output.system.push(context);
|
|
325
|
+
},
|
|
326
|
+
"tool.execute.before": async (input, output) => {
|
|
327
|
+
const result = await guardAgentDirectiveBeforeTool(hookPayload(input, output, "PreToolUse"));
|
|
328
|
+
const message = denialMessage(result);
|
|
329
|
+
if (message) throw new Error(`mednotes_fsm_hook_blocked: ${message}`);
|
|
330
|
+
},
|
|
331
|
+
"tool.execute.after": async (input, output) => {
|
|
332
|
+
await writeNativeTaskMetadata(input, output);
|
|
333
|
+
await captureAgentDirectiveAfterTool(hookPayload(input, output, "AfterTool"));
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
export const MedNotesFSM = server;
|
|
338
|
+
MedNotesFSM.id = "medical-notes-workbench-fsm";
|
|
339
|
+
MedNotesFSM.server = server;
|
|
340
|
+
|
|
341
|
+
export default MedNotesFSM;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
// OpenCode imports the project plugin before user agents are invoked. This
|
|
7
|
+
// adapter uses that boot point to apply only runtime knobs from the user TOML:
|
|
8
|
+
// specialist model ids and reasoning effort. FSM state and workflow policy do
|
|
9
|
+
// not live here.
|
|
10
|
+
const FIELD_TO_AGENT = new Map([
|
|
11
|
+
["med_chat_triager", "med-chat-triager"],
|
|
12
|
+
["med_flashcard_maker", "med-flashcard-maker"],
|
|
13
|
+
["med_knowledge_architect", "med-knowledge-architect"],
|
|
14
|
+
["med_link_graph_curator", "med-link-graph-curator"],
|
|
15
|
+
["med_publish_guard", "med-publish-guard"],
|
|
16
|
+
]);
|
|
17
|
+
const REASONING_EFFORTS = new Set(["minimal", "low", "medium", "high"]);
|
|
18
|
+
|
|
19
|
+
export function syncMedNotesOpenCodeUserConfig(projectRoot = opencodeProjectRoot()) {
|
|
20
|
+
if (autoSyncDisabled()) return { status: "disabled", agents: [] };
|
|
21
|
+
const runtimeByAgent = readRuntimeOverrides(projectRoot);
|
|
22
|
+
applyRuntimeOverridesToFiles(projectRoot, runtimeByAgent);
|
|
23
|
+
return {
|
|
24
|
+
status: "synced",
|
|
25
|
+
project_root: projectRoot,
|
|
26
|
+
agents: Object.keys(runtimeByAgent).sort(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function applyMedNotesOpenCodeRuntimeConfig(config, projectRoot = opencodeProjectRoot()) {
|
|
31
|
+
const runtimeByAgent = readRuntimeOverrides(projectRoot);
|
|
32
|
+
config.agent = config.agent && typeof config.agent === "object" ? config.agent : {};
|
|
33
|
+
for (const [agentId, runtimeConfig] of Object.entries(runtimeByAgent)) {
|
|
34
|
+
const entry = config.agent[agentId] && typeof config.agent[agentId] === "object" ? config.agent[agentId] : {};
|
|
35
|
+
config.agent[agentId] = { ...entry, ...runtimeConfig };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readRuntimeOverrides(projectRoot) {
|
|
40
|
+
const configPath = findConfigPath(projectRoot);
|
|
41
|
+
if (!configPath || !existsSync(configPath)) return {};
|
|
42
|
+
return parseAgentRuntimeConfig(readFileSync(configPath, "utf8"), configPath);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function applyRuntimeOverridesToFiles(projectRoot, runtimeByAgent) {
|
|
46
|
+
if (Object.keys(runtimeByAgent).length === 0) return;
|
|
47
|
+
updateOpenCodeJson(path.join(projectRoot, ".opencode", "opencode.json"), runtimeByAgent);
|
|
48
|
+
for (const [agentId, runtimeConfig] of Object.entries(runtimeByAgent)) {
|
|
49
|
+
updateAgentMarkdown(path.join(projectRoot, ".opencode", "agents", `${agentId}.md`), runtimeConfig);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function updateOpenCodeJson(configPath, runtimeByAgent) {
|
|
54
|
+
if (!existsSync(configPath)) return;
|
|
55
|
+
const parsed = JSON.parse(readFileSync(configPath, "utf8"));
|
|
56
|
+
parsed.agent = parsed.agent && typeof parsed.agent === "object" ? parsed.agent : {};
|
|
57
|
+
for (const [agentId, runtimeConfig] of Object.entries(runtimeByAgent)) {
|
|
58
|
+
const entry = parsed.agent[agentId] && typeof parsed.agent[agentId] === "object" ? parsed.agent[agentId] : {};
|
|
59
|
+
parsed.agent[agentId] = { ...entry, ...runtimeConfig };
|
|
60
|
+
}
|
|
61
|
+
writeIfChanged(configPath, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function updateAgentMarkdown(agentPath, runtimeConfig) {
|
|
65
|
+
if (!existsSync(agentPath)) return;
|
|
66
|
+
let text = readFileSync(agentPath, "utf8");
|
|
67
|
+
if (runtimeConfig.model) {
|
|
68
|
+
text = replaceFrontmatterLine(agentPath, text, "model", runtimeConfig.model);
|
|
69
|
+
}
|
|
70
|
+
if (runtimeConfig.reasoningEffort) {
|
|
71
|
+
text = replaceFrontmatterLine(agentPath, text, "reasoningEffort", runtimeConfig.reasoningEffort);
|
|
72
|
+
}
|
|
73
|
+
writeIfChanged(agentPath, text);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function replaceFrontmatterLine(agentPath, text, key, value) {
|
|
77
|
+
const pattern = new RegExp(`^${key}: .+$`, "m");
|
|
78
|
+
if (!pattern.test(text)) {
|
|
79
|
+
throw new Error(`MedNotes OpenCode auto-sync could not find ${key} in ${agentPath}`);
|
|
80
|
+
}
|
|
81
|
+
return text.replace(pattern, `${key}: ${frontmatterScalar(value)}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseAgentRuntimeConfig(text, configPath) {
|
|
85
|
+
// The MedNotes config template emits simple [agents.<name>] TOML sections.
|
|
86
|
+
// Keeping this parser narrow avoids making plugin startup depend on Python or
|
|
87
|
+
// a package install before OpenCode opens.
|
|
88
|
+
const runtimeByAgent = {};
|
|
89
|
+
let currentAgentId = "";
|
|
90
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
91
|
+
const line = rawLine.trim();
|
|
92
|
+
if (!line || line.startsWith("#")) continue;
|
|
93
|
+
|
|
94
|
+
const section = line.match(/^\[agents\.([A-Za-z0-9_]+)\]$/);
|
|
95
|
+
if (section) {
|
|
96
|
+
currentAgentId = FIELD_TO_AGENT.get(section[1]) || "";
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (line.startsWith("[")) {
|
|
100
|
+
currentAgentId = "";
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (!currentAgentId) continue;
|
|
104
|
+
|
|
105
|
+
const assignment = line.match(/^([A-Za-z0-9_]+)\s*=\s*(.+)$/);
|
|
106
|
+
if (!assignment) continue;
|
|
107
|
+
const key = assignment[1];
|
|
108
|
+
const value = parseTomlStringValue(assignment[2], configPath);
|
|
109
|
+
if (key === "model") {
|
|
110
|
+
if (!value) throw new Error(`MedNotes OpenCode config has empty model for ${currentAgentId}`);
|
|
111
|
+
runtimeByAgent[currentAgentId] = { ...(runtimeByAgent[currentAgentId] || {}), model: value };
|
|
112
|
+
}
|
|
113
|
+
if (key === "reasoning_effort") {
|
|
114
|
+
if (!REASONING_EFFORTS.has(value)) {
|
|
115
|
+
throw new Error(`MedNotes OpenCode config has invalid reasoning_effort for ${currentAgentId}: ${value}`);
|
|
116
|
+
}
|
|
117
|
+
runtimeByAgent[currentAgentId] = { ...(runtimeByAgent[currentAgentId] || {}), reasoningEffort: value };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return runtimeByAgent;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function parseTomlStringValue(rawValue, configPath) {
|
|
124
|
+
const value = rawValue.trim();
|
|
125
|
+
if (value.startsWith('"')) {
|
|
126
|
+
let escaped = false;
|
|
127
|
+
for (let index = 1; index < value.length; index += 1) {
|
|
128
|
+
const char = value[index];
|
|
129
|
+
if (escaped) {
|
|
130
|
+
escaped = false;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (char === "\\") {
|
|
134
|
+
escaped = true;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (char === '"') return JSON.parse(value.slice(0, index + 1));
|
|
138
|
+
}
|
|
139
|
+
throw new Error(`Invalid quoted TOML string in ${configPath}`);
|
|
140
|
+
}
|
|
141
|
+
if (value.startsWith("'")) {
|
|
142
|
+
const end = value.indexOf("'", 1);
|
|
143
|
+
if (end > 0) return value.slice(1, end);
|
|
144
|
+
throw new Error(`Invalid literal TOML string in ${configPath}`);
|
|
145
|
+
}
|
|
146
|
+
return value.split("#", 1)[0].trim();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function findConfigPath(projectRoot) {
|
|
150
|
+
if (process.env.MEDNOTES_CONFIG) return path.resolve(process.env.MEDNOTES_CONFIG);
|
|
151
|
+
if (process.env.MEDNOTES_HOME) return path.resolve(process.env.MEDNOTES_HOME, "config.toml");
|
|
152
|
+
for (let current = path.resolve(projectRoot); ; current = path.dirname(current)) {
|
|
153
|
+
const candidate = path.join(current, "config.toml");
|
|
154
|
+
if (existsSync(candidate)) return candidate;
|
|
155
|
+
if (current === path.dirname(current)) break;
|
|
156
|
+
}
|
|
157
|
+
return path.join(os.homedir(), ".mednotes", "config.toml");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function opencodeProjectRoot() {
|
|
161
|
+
const adapterDir = path.dirname(fileURLToPath(import.meta.url));
|
|
162
|
+
return path.resolve(adapterDir, "..", "..", "..", "..");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function autoSyncDisabled() {
|
|
166
|
+
return /^(0|false|no)$/i.test(process.env.MEDNOTES_OPENCODE_AUTO_SYNC || "");
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function frontmatterScalar(value) {
|
|
170
|
+
const text = String(value);
|
|
171
|
+
return /^[A-Za-z0-9_./:@-]+$/.test(text) ? text : JSON.stringify(text);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function writeIfChanged(filePath, nextText) {
|
|
175
|
+
const current = existsSync(filePath) ? readFileSync(filePath, "utf8") : "";
|
|
176
|
+
if (current !== nextText) writeFileSync(filePath, nextText, "utf8");
|
|
177
|
+
}
|