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.
Files changed (430) hide show
  1. package/.opencode/agents/med-chat-triager.md +204 -0
  2. package/.opencode/agents/med-flashcard-maker.md +63 -0
  3. package/.opencode/agents/med-knowledge-architect.md +230 -0
  4. package/.opencode/agents/med-link-graph-curator.md +177 -0
  5. package/.opencode/agents/med-publish-guard.md +62 -0
  6. package/.opencode/commands/flashcards.md +25 -0
  7. package/.opencode/commands/mednotes/create.md +25 -0
  8. package/.opencode/commands/mednotes/enrich.md +27 -0
  9. package/.opencode/commands/mednotes/fix-wiki.md +27 -0
  10. package/.opencode/commands/mednotes/history.md +22 -0
  11. package/.opencode/commands/mednotes/link-body.md +25 -0
  12. package/.opencode/commands/mednotes/link-related.md +27 -0
  13. package/.opencode/commands/mednotes/link.md +27 -0
  14. package/.opencode/commands/mednotes/pdf-library.md +27 -0
  15. package/.opencode/commands/mednotes/process-chats.md +23 -0
  16. package/.opencode/commands/mednotes/setup.md +21 -0
  17. package/.opencode/commands/mednotes/status.md +27 -0
  18. package/.opencode/commands/mednotes/telemetry.md +27 -0
  19. package/.opencode/commands/report.md +26 -0
  20. package/.opencode/mednotes/AGENTS.md +57 -0
  21. package/.opencode/mednotes/agents/med-chat-triager.md +197 -0
  22. package/.opencode/mednotes/agents/med-flashcard-maker.md +56 -0
  23. package/.opencode/mednotes/agents/med-knowledge-architect.md +224 -0
  24. package/.opencode/mednotes/agents/med-link-graph-curator.md +171 -0
  25. package/.opencode/mednotes/agents/med-publish-guard.md +55 -0
  26. package/.opencode/mednotes/contracts/.gitkeep +1 -0
  27. package/.opencode/mednotes/contracts/agents.json +116 -0
  28. package/.opencode/mednotes/contracts/opencode-plugin.json +70 -0
  29. package/.opencode/mednotes/docs/agent-prompt-hardening.md +567 -0
  30. package/.opencode/mednotes/docs/agent-role-contracts.md +94 -0
  31. package/.opencode/mednotes/docs/anki-mcp-twenty-rules.md +214 -0
  32. package/.opencode/mednotes/docs/anki-templates/README.md +39 -0
  33. package/.opencode/mednotes/docs/anki-templates/cloze.back.html +23 -0
  34. package/.opencode/mednotes/docs/anki-templates/cloze.front.html +14 -0
  35. package/.opencode/mednotes/docs/anki-templates/qa.back.html +24 -0
  36. package/.opencode/mednotes/docs/anki-templates/qa.front.html +14 -0
  37. package/.opencode/mednotes/docs/anki-templates/style.css +182 -0
  38. package/.opencode/mednotes/docs/atomicity-splitting-policy.md +113 -0
  39. package/.opencode/mednotes/docs/extension-docs.md +40 -0
  40. package/.opencode/mednotes/docs/flashcard-ingestion.md +278 -0
  41. package/.opencode/mednotes/docs/knowledge-architect.md +208 -0
  42. package/.opencode/mednotes/docs/merge-policy.md +110 -0
  43. package/.opencode/mednotes/docs/public-vocabulary.md +104 -0
  44. package/.opencode/mednotes/docs/semantic-linker.md +141 -0
  45. package/.opencode/mednotes/docs/taxonomy-policy.md +90 -0
  46. package/.opencode/mednotes/docs/triage-policy.md +187 -0
  47. package/.opencode/mednotes/docs/vault-version-control.md +758 -0
  48. package/.opencode/mednotes/docs/vocabulary-db-recovery.md +58 -0
  49. package/.opencode/mednotes/docs/workflow-output-contract.md +779 -0
  50. package/.opencode/mednotes/hooks/hooks.json +79 -0
  51. package/.opencode/mednotes/package-lock.json +6361 -0
  52. package/.opencode/mednotes/package.json +15 -0
  53. package/.opencode/mednotes/pyproject.toml +48 -0
  54. package/.opencode/mednotes/scripts/bootstrap_windows_python_uv.cmd +13 -0
  55. package/.opencode/mednotes/scripts/bootstrap_windows_python_uv.ps1 +172 -0
  56. package/.opencode/mednotes/scripts/enrich_notes.py +23 -0
  57. package/.opencode/mednotes/scripts/full_reset_windows_python_uv.cmd +13 -0
  58. package/.opencode/mednotes/scripts/hooks/antigravity_hook_status.mjs +212 -0
  59. package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/antigravity.mjs +169 -0
  60. package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/harness_payload.mjs +103 -0
  61. package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/opencode_plugin.mjs +341 -0
  62. package/.opencode/mednotes/scripts/hooks/mednotes_hook/adapters/opencode_user_config_sync.mjs +177 -0
  63. package/.opencode/mednotes/scripts/hooks/mednotes_hook/anki_preflight.mjs +214 -0
  64. package/.opencode/mednotes/scripts/hooks/mednotes_hook/cli.mjs +143 -0
  65. package/.opencode/mednotes/scripts/hooks/mednotes_hook/diagnostics.mjs +11 -0
  66. package/.opencode/mednotes/scripts/hooks/mednotes_hook/domain/agent_directive_core.mjs +160 -0
  67. package/.opencode/mednotes/scripts/hooks/mednotes_hook/fsm_directive.mjs +1470 -0
  68. package/.opencode/mednotes/scripts/hooks/mednotes_hook/hook_errors.mjs +120 -0
  69. package/.opencode/mednotes/scripts/hooks/mednotes_hook/retention.mjs +114 -0
  70. package/.opencode/mednotes/scripts/hooks/mednotes_hook/runtime.mjs +174 -0
  71. package/.opencode/mednotes/scripts/hooks/mednotes_hook/telemetry_capture.mjs +511 -0
  72. package/.opencode/mednotes/scripts/hooks/mednotes_hook/vault_guard.mjs +624 -0
  73. package/.opencode/mednotes/scripts/hooks/mednotes_hook.mjs +5 -0
  74. package/.opencode/mednotes/scripts/mednotes/_runtime_paths.py +24 -0
  75. package/.opencode/mednotes/scripts/mednotes/anki_model_validator.py +18 -0
  76. package/.opencode/mednotes/scripts/mednotes/capture_extension_diff.py +1562 -0
  77. package/.opencode/mednotes/scripts/mednotes/feedback_report.py +16 -0
  78. package/.opencode/mednotes/scripts/mednotes/flashcard_index.py +18 -0
  79. package/.opencode/mednotes/scripts/mednotes/flashcard_pipeline.py +18 -0
  80. package/.opencode/mednotes/scripts/mednotes/flashcard_report.py +18 -0
  81. package/.opencode/mednotes/scripts/mednotes/flashcard_sources.py +18 -0
  82. package/.opencode/mednotes/scripts/mednotes/obsidian/README.md +6 -0
  83. package/.opencode/mednotes/scripts/mednotes/obsidian_note_utils.py +20 -0
  84. package/.opencode/mednotes/scripts/mednotes/pdf_library/cli.py +16 -0
  85. package/.opencode/mednotes/scripts/mednotes/project_fsm.py +229 -0
  86. package/.opencode/mednotes/scripts/mednotes/setup_telemetry_email.py +404 -0
  87. package/.opencode/mednotes/scripts/mednotes/sync_anki_twenty_rules.py +18 -0
  88. package/.opencode/mednotes/scripts/mednotes/sync_opencode_user_config.py +36 -0
  89. package/.opencode/mednotes/scripts/mednotes/wiki/cli.py +20 -0
  90. package/.opencode/mednotes/scripts/mednotes/wiki_graph.py +18 -0
  91. package/.opencode/mednotes/scripts/mednotes/wiki_tree.py +134 -0
  92. package/.opencode/mednotes/scripts/reset_windows_python_uv.ps1 +625 -0
  93. package/.opencode/mednotes/scripts/run_python.mjs +109 -0
  94. package/.opencode/mednotes/scripts/vault/vault_commit.ps1 +19 -0
  95. package/.opencode/mednotes/scripts/vault/vault_commit.sh +18 -0
  96. package/.opencode/mednotes/scripts/vault/vault_git.ps1 +19 -0
  97. package/.opencode/mednotes/scripts/vault/vault_git.py +3107 -0
  98. package/.opencode/mednotes/scripts/vault/vault_git.sh +18 -0
  99. package/.opencode/mednotes/scripts/vault/vault_precommit.ps1 +19 -0
  100. package/.opencode/mednotes/scripts/vault/vault_precommit.sh +18 -0
  101. package/.opencode/mednotes/skills/THIRD_PARTY_NOTICES.md +45 -0
  102. package/.opencode/mednotes/skills/create-medical-flashcards/SKILL.md +113 -0
  103. package/.opencode/mednotes/skills/create-medical-note/SKILL.md +90 -0
  104. package/.opencode/mednotes/skills/enrich-medical-note/SKILL.md +120 -0
  105. package/.opencode/mednotes/skills/fix-medical-wiki/SKILL.md +559 -0
  106. package/.opencode/mednotes/skills/link-medical-wiki/SKILL.md +224 -0
  107. package/.opencode/mednotes/skills/obsidian-cli/SKILL.md +118 -0
  108. package/.opencode/mednotes/skills/obsidian-markdown/SKILL.md +207 -0
  109. package/.opencode/mednotes/skills/obsidian-markdown/references/CALLOUTS.md +58 -0
  110. package/.opencode/mednotes/skills/obsidian-markdown/references/EMBEDS.md +63 -0
  111. package/.opencode/mednotes/skills/obsidian-markdown/references/PROPERTIES.md +61 -0
  112. package/.opencode/mednotes/skills/obsidian-ops/SKILL.md +136 -0
  113. package/.opencode/mednotes/skills/pdf-library/SKILL.md +45 -0
  114. package/.opencode/mednotes/skills/process-medical-chats/SKILL.md +246 -0
  115. package/.opencode/mednotes/skills/workflow-report/SKILL.md +100 -0
  116. package/.opencode/mednotes/src/mednotes/__init__.py +5 -0
  117. package/.opencode/mednotes/src/mednotes/domains/__init__.py +5 -0
  118. package/.opencode/mednotes/src/mednotes/domains/flashcards/README.md +26 -0
  119. package/.opencode/mednotes/src/mednotes/domains/flashcards/__init__.py +2 -0
  120. package/.opencode/mednotes/src/mednotes/domains/flashcards/build_demo_apkg.py +177 -0
  121. package/.opencode/mednotes/src/mednotes/domains/flashcards/contracts.py +385 -0
  122. package/.opencode/mednotes/src/mednotes/domains/flashcards/flashcards_machine.py +522 -0
  123. package/.opencode/mednotes/src/mednotes/domains/flashcards/fsm.py +817 -0
  124. package/.opencode/mednotes/src/mednotes/domains/flashcards/index.py +630 -0
  125. package/.opencode/mednotes/src/mednotes/domains/flashcards/install_models.py +445 -0
  126. package/.opencode/mednotes/src/mednotes/domains/flashcards/model.py +359 -0
  127. package/.opencode/mednotes/src/mednotes/domains/flashcards/obsidian_links.py +135 -0
  128. package/.opencode/mednotes/src/mednotes/domains/flashcards/obsidian_note_utils.py +546 -0
  129. package/.opencode/mednotes/src/mednotes/domains/flashcards/pipeline.py +580 -0
  130. package/.opencode/mednotes/src/mednotes/domains/flashcards/report.py +510 -0
  131. package/.opencode/mednotes/src/mednotes/domains/flashcards/sources.py +682 -0
  132. package/.opencode/mednotes/src/mednotes/domains/flashcards/sync_rules.py +184 -0
  133. package/.opencode/mednotes/src/mednotes/domains/history/__init__.py +1 -0
  134. package/.opencode/mednotes/src/mednotes/domains/history/history_fsm.py +852 -0
  135. package/.opencode/mednotes/src/mednotes/domains/history/history_machine.py +453 -0
  136. package/.opencode/mednotes/src/mednotes/domains/setup/__init__.py +7 -0
  137. package/.opencode/mednotes/src/mednotes/domains/setup/setup_fsm.py +808 -0
  138. package/.opencode/mednotes/src/mednotes/domains/setup/setup_machine.py +973 -0
  139. package/.opencode/mednotes/src/mednotes/domains/wiki/README.md +64 -0
  140. package/.opencode/mednotes/src/mednotes/domains/wiki/__init__.py +1 -0
  141. package/.opencode/mednotes/src/mednotes/domains/wiki/api.py +668 -0
  142. package/.opencode/mednotes/src/mednotes/domains/wiki/batch_state.py +102 -0
  143. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/__init__.py +1 -0
  144. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/atomicity/__init__.py +1 -0
  145. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/atomicity/atomicity.py +877 -0
  146. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/body_link/__init__.py +1 -0
  147. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/body_link/body_linker.py +1562 -0
  148. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/effects/__init__.py +1 -0
  149. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/effects/effect_adapters.py +949 -0
  150. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/effects/fix_wiki_runtime_adapters.py +433 -0
  151. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/__init__.py +1 -0
  152. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/coverage.py +413 -0
  153. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/graph.py +396 -0
  154. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/graph/graph_fixes.py +161 -0
  155. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/hygiene/__init__.py +1 -0
  156. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/hygiene/hygiene.py +483 -0
  157. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/__init__.py +2 -0
  158. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/anchors.py +185 -0
  159. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/__init__.py +0 -0
  160. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/cache.py +223 -0
  161. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/config.py +131 -0
  162. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/download.py +224 -0
  163. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/frontmatter.py +59 -0
  164. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/insert.py +227 -0
  165. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/core/local_import.py +54 -0
  166. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/__init__.py +42 -0
  167. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/web_profiles.py +99 -0
  168. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/web_search.py +203 -0
  169. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/illustrate/sources/wikimedia.py +102 -0
  170. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/__init__.py +1 -0
  171. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/markdown_db_adapter.mjs +434 -0
  172. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/markdown_node_runtime.py +274 -0
  173. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/markdown/markdown_query.py +227 -0
  174. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/__init__.py +1 -0
  175. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/artifacts.py +605 -0
  176. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/canonical_merge.py +277 -0
  177. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/markdown_zones.py +85 -0
  178. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/meaning_planner.py +307 -0
  179. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_iter.py +67 -0
  180. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_merge.py +278 -0
  181. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_plan.py +409 -0
  182. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_policy.py +22 -0
  183. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/__init__.py +79 -0
  184. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/fixes.py +264 -0
  185. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/frontmatter.py +435 -0
  186. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/models.py +208 -0
  187. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/prompts.py +37 -0
  188. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/tables.py +236 -0
  189. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/note_style/validate.py +404 -0
  190. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/provenance.py +478 -0
  191. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/raw_chats.py +273 -0
  192. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/notes/sources_backfill.py +235 -0
  193. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/__init__.py +10 -0
  194. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/anchors.py +16 -0
  195. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/captions.py +47 -0
  196. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/cli.py +179 -0
  197. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/cloud.py +52 -0
  198. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/config.py +196 -0
  199. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/context_packets.py +76 -0
  200. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/db.py +81 -0
  201. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/doctor.py +102 -0
  202. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/figure_ids.py +42 -0
  203. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/ingest.py +326 -0
  204. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/insert.py +316 -0
  205. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/mentions.py +57 -0
  206. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/ocr.py +71 -0
  207. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/paths.py +35 -0
  208. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/pdf_engine.py +77 -0
  209. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/schema.py +155 -0
  210. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/search.py +188 -0
  211. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/__init__.py +1 -0
  212. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/app.py +89 -0
  213. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/image_backend.py +29 -0
  214. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/pdf/tui/state.py +65 -0
  215. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/__init__.py +1 -0
  216. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/publish.py +1139 -0
  217. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/publish_receipts.py +365 -0
  218. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/publish/publish_recovery.py +240 -0
  219. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/__init__.py +1 -0
  220. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/agent_behavior_corpus.py +2069 -0
  221. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/agent_report_validation.py +4448 -0
  222. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/agent_run_audit.py +852 -0
  223. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/architect_prompt_eval.py +341 -0
  224. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/body_linker_eval.py +240 -0
  225. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/curator_output_validation.py +175 -0
  226. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/curator_prompt_eval.py +865 -0
  227. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/quality/triager_prompt_eval.py +1295 -0
  228. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/related_notes/__init__.py +1 -0
  229. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/related_notes/related_notes.py +1920 -0
  230. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/related_notes/related_notes_headless.py +1186 -0
  231. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/__init__.py +1 -0
  232. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/plan_attestation.py +148 -0
  233. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/specialist_receipts.py +360 -0
  234. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/specialist_runtime.py +52 -0
  235. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/specialist/specialist_task_runner.py +2470 -0
  236. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/style/__init__.py +1 -0
  237. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/style/style.py +1952 -0
  238. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/subagents/__init__.py +1 -0
  239. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/subagents/agents.py +1767 -0
  240. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/__init__.py +1 -0
  241. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/alias_projection.py +331 -0
  242. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/link_terms.py +151 -0
  243. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/llm_disambiguation.py +182 -0
  244. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/__init__.py +116 -0
  245. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/audit.py +201 -0
  246. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/migration.py +314 -0
  247. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/normalize.py +72 -0
  248. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/policy.py +135 -0
  249. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/resolve.py +413 -0
  250. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/schema.py +157 -0
  251. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/taxonomy/status.py +137 -0
  252. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_bootstrap.py +509 -0
  253. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_curator_batch.py +1115 -0
  254. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_ingestion.py +632 -0
  255. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_map.py +930 -0
  256. package/.opencode/mednotes/src/mednotes/domains/wiki/capabilities/vocabulary/vocabulary_recovery.py +1388 -0
  257. package/.opencode/mednotes/src/mednotes/domains/wiki/cli.py +6665 -0
  258. package/.opencode/mednotes/src/mednotes/domains/wiki/common.py +69 -0
  259. package/.opencode/mednotes/src/mednotes/domains/wiki/config.py +210 -0
  260. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/__init__.py +74 -0
  261. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/agent_report.py +242 -0
  262. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/agent_run_audit.py +196 -0
  263. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/agents.py +601 -0
  264. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/curator.py +256 -0
  265. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/effect_payloads.py +519 -0
  266. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/happy_path.py +190 -0
  267. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/link_git.py +110 -0
  268. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/link_runtime_artifact.py +52 -0
  269. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/note_plan.py +75 -0
  270. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/paths.py +114 -0
  271. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/public_report.py +53 -0
  272. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/publish.py +111 -0
  273. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/raw_coverage.py +217 -0
  274. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/related_notes.py +136 -0
  275. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/related_notes_headless.py +153 -0
  276. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/related_notes_runtime.py +395 -0
  277. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/schema_registry.py +637 -0
  278. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/specialist.py +432 -0
  279. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/status.py +62 -0
  280. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/style_rewrite.py +568 -0
  281. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/vocabulary_ingestion.py +223 -0
  282. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_blockers.py +510 -0
  283. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_guardrails.py +637 -0
  284. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_outcomes.py +121 -0
  285. package/.opencode/mednotes/src/mednotes/domains/wiki/contracts/workflow_receipts.py +100 -0
  286. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/__init__.py +1 -0
  287. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/__init__.py +1 -0
  288. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/__main__.py +4 -0
  289. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/cli.py +275 -0
  290. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/__init__.py +2 -0
  291. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/candidates.py +193 -0
  292. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/cli.py +189 -0
  293. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/gemini.py +220 -0
  294. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/inputs.py +120 -0
  295. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/models.py +34 -0
  296. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/parsing.py +48 -0
  297. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/prompts.py +216 -0
  298. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/quality.py +54 -0
  299. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/reporting.py +24 -0
  300. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/runner.py +433 -0
  301. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/utils.py +39 -0
  302. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/enrich/workflow/vault_guard_bridge.py +17 -0
  303. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/__init__.py +1 -0
  304. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_context_packets.py +454 -0
  305. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_decision_projection.py +133 -0
  306. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_effects.py +1260 -0
  307. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_fsm.py +2768 -0
  308. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_machine.py +1588 -0
  309. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_plan.py +306 -0
  310. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_primary_objective.py +316 -0
  311. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_problem.py +153 -0
  312. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_receipt_evidence.py +306 -0
  313. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_states.py +290 -0
  314. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/fix_wiki_user_report.py +342 -0
  315. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/fix_wiki/health.py +6332 -0
  316. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/__init__.py +1 -0
  317. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_fsm.py +1119 -0
  318. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_git.py +638 -0
  319. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_machine.py +1106 -0
  320. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_retry_governance.py +374 -0
  321. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_runtime_result.py +485 -0
  322. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/link_triggers.py +183 -0
  323. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/linking.py +2758 -0
  324. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/reference_repair.py +718 -0
  325. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link/related_notes_fsm.py +1855 -0
  326. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link_related/__init__.py +1 -0
  327. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/link_related/link_related_machine.py +834 -0
  328. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/__init__.py +1 -0
  329. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_fsm.py +1592 -0
  330. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_machine.py +3097 -0
  331. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_primary_objective.py +28 -0
  332. package/.opencode/mednotes/src/mednotes/domains/wiki/flows/process_chats/process_chats_runtime_result.py +185 -0
  333. package/.opencode/mednotes/src/mednotes/domains/wiki/performance.py +97 -0
  334. package/.opencode/mednotes/src/mednotes/kernel/__init__.py +6 -0
  335. package/.opencode/mednotes/src/mednotes/kernel/agent_directive.py +336 -0
  336. package/.opencode/mednotes/src/mednotes/kernel/base.py +51 -0
  337. package/.opencode/mednotes/src/mednotes/kernel/blockers.py +39 -0
  338. package/.opencode/mednotes/src/mednotes/kernel/effect_executor.py +55 -0
  339. package/.opencode/mednotes/src/mednotes/kernel/effect_intent.py +69 -0
  340. package/.opencode/mednotes/src/mednotes/kernel/effects.py +160 -0
  341. package/.opencode/mednotes/src/mednotes/kernel/errors.py +38 -0
  342. package/.opencode/mednotes/src/mednotes/kernel/fsm_event.py +35 -0
  343. package/.opencode/mednotes/src/mednotes/kernel/fsm_model.py +55 -0
  344. package/.opencode/mednotes/src/mednotes/kernel/fsm_transition_result.py +75 -0
  345. package/.opencode/mednotes/src/mednotes/kernel/guardrails.py +188 -0
  346. package/.opencode/mednotes/src/mednotes/kernel/progress.py +319 -0
  347. package/.opencode/mednotes/src/mednotes/kernel/public_report.py +346 -0
  348. package/.opencode/mednotes/src/mednotes/kernel/state_machine.py +164 -0
  349. package/.opencode/mednotes/src/mednotes/kernel/workflow.py +619 -0
  350. package/.opencode/mednotes/src/mednotes/platform/__init__.py +5 -0
  351. package/.opencode/mednotes/src/mednotes/platform/backup_policy.py +382 -0
  352. package/.opencode/mednotes/src/mednotes/platform/feedback/__init__.py +62 -0
  353. package/.opencode/mednotes/src/mednotes/platform/feedback/cli.py +275 -0
  354. package/.opencode/mednotes/src/mednotes/platform/feedback/contracts.py +83 -0
  355. package/.opencode/mednotes/src/mednotes/platform/feedback/core.py +4168 -0
  356. package/.opencode/mednotes/src/mednotes/platform/feedback/integrity.py +989 -0
  357. package/.opencode/mednotes/src/mednotes/platform/feedback/operational_contract.py +2293 -0
  358. package/.opencode/mednotes/src/mednotes/platform/feedback/telemetry.py +875 -0
  359. package/.opencode/mednotes/src/mednotes/platform/feedback/telemetry_config.py +65 -0
  360. package/.opencode/mednotes/src/mednotes/platform/opencode_runtime_config.py +182 -0
  361. package/.opencode/mednotes/src/mednotes/platform/paths/__init__.py +1560 -0
  362. package/.opencode/mednotes/src/mednotes/platform/secrets.py +89 -0
  363. package/.opencode/mednotes/src/mednotes/platform/user_config.py +103 -0
  364. package/.opencode/mednotes/src/mednotes/platform/vault_guard.py +214 -0
  365. package/.opencode/mednotes/uv.lock +932 -0
  366. package/.opencode/mednotes.generated.json +395 -0
  367. package/.opencode/opencode.json +31 -0
  368. package/.opencode/plugins/mednotes-fsm.mjs +7 -0
  369. package/.opencode/plugins/mednotes_hook/adapters/antigravity.mjs +169 -0
  370. package/.opencode/plugins/mednotes_hook/adapters/harness_payload.mjs +103 -0
  371. package/.opencode/plugins/mednotes_hook/adapters/opencode_plugin.mjs +341 -0
  372. package/.opencode/plugins/mednotes_hook/adapters/opencode_user_config_sync.mjs +177 -0
  373. package/.opencode/plugins/mednotes_hook/anki_preflight.mjs +214 -0
  374. package/.opencode/plugins/mednotes_hook/cli.mjs +143 -0
  375. package/.opencode/plugins/mednotes_hook/diagnostics.mjs +11 -0
  376. package/.opencode/plugins/mednotes_hook/domain/agent_directive_core.mjs +160 -0
  377. package/.opencode/plugins/mednotes_hook/fsm_directive.mjs +1470 -0
  378. package/.opencode/plugins/mednotes_hook/hook_errors.mjs +120 -0
  379. package/.opencode/plugins/mednotes_hook/retention.mjs +114 -0
  380. package/.opencode/plugins/mednotes_hook/runtime.mjs +174 -0
  381. package/.opencode/plugins/mednotes_hook/telemetry_capture.mjs +511 -0
  382. package/.opencode/plugins/mednotes_hook/vault_guard.mjs +624 -0
  383. package/AGENTS.md +57 -0
  384. package/README.md +194 -0
  385. package/adapters/antigravity/agents.json +80 -0
  386. package/adapters/antigravity/templates/med-chat-triager.md +214 -0
  387. package/adapters/antigravity/templates/med-flashcard-maker.md +72 -0
  388. package/adapters/antigravity/templates/med-knowledge-architect.md +241 -0
  389. package/adapters/antigravity/templates/med-link-graph-curator.md +187 -0
  390. package/adapters/antigravity/templates/med-publish-guard.md +71 -0
  391. package/adapters/gemini-cli/gemini-extension.json +14 -0
  392. package/adapters/gemini-cli/package.json +15 -0
  393. package/adapters/gemini-cli/pyproject.toml +48 -0
  394. package/bin/mednotes-opencode.mjs +155 -0
  395. package/contracts/agents.json +116 -0
  396. package/core/agents/med-chat-triager.md +197 -0
  397. package/core/agents/med-flashcard-maker.md +56 -0
  398. package/core/agents/med-knowledge-architect.md +224 -0
  399. package/core/agents/med-link-graph-curator.md +171 -0
  400. package/core/agents/med-publish-guard.md +55 -0
  401. package/core/commands/flashcards.toml +22 -0
  402. package/core/commands/mednotes/create.toml +22 -0
  403. package/core/commands/mednotes/enrich.toml +24 -0
  404. package/core/commands/mednotes/fix-wiki.toml +24 -0
  405. package/core/commands/mednotes/history.toml +19 -0
  406. package/core/commands/mednotes/link-body.toml +22 -0
  407. package/core/commands/mednotes/link-related.toml +24 -0
  408. package/core/commands/mednotes/link.toml +24 -0
  409. package/core/commands/mednotes/pdf-library.toml +24 -0
  410. package/core/commands/mednotes/process-chats.toml +20 -0
  411. package/core/commands/mednotes/setup.toml +18 -0
  412. package/core/commands/mednotes/status.toml +24 -0
  413. package/core/commands/mednotes/telemetry.toml +24 -0
  414. package/core/commands/report.toml +23 -0
  415. package/core/skills/THIRD_PARTY_NOTICES.md +45 -0
  416. package/core/skills/create-medical-flashcards/SKILL.md +113 -0
  417. package/core/skills/create-medical-note/SKILL.md +90 -0
  418. package/core/skills/enrich-medical-note/SKILL.md +120 -0
  419. package/core/skills/fix-medical-wiki/SKILL.md +559 -0
  420. package/core/skills/link-medical-wiki/SKILL.md +224 -0
  421. package/core/skills/obsidian-cli/SKILL.md +118 -0
  422. package/core/skills/obsidian-markdown/SKILL.md +207 -0
  423. package/core/skills/obsidian-markdown/references/CALLOUTS.md +58 -0
  424. package/core/skills/obsidian-markdown/references/EMBEDS.md +63 -0
  425. package/core/skills/obsidian-markdown/references/PROPERTIES.md +61 -0
  426. package/core/skills/obsidian-ops/SKILL.md +136 -0
  427. package/core/skills/pdf-library/SKILL.md +45 -0
  428. package/core/skills/process-medical-chats/SKILL.md +246 -0
  429. package/core/skills/workflow-report/SKILL.md +100 -0
  430. package/package.json +45 -0
@@ -0,0 +1,179 @@
1
+ #!/usr/bin/env python
2
+ """Internal JSON CLI for /mednotes:pdf-library."""
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ from pathlib import Path
8
+
9
+ from mednotes.domains.wiki.capabilities.pdf import config as config_mod
10
+ from mednotes.domains.wiki.capabilities.pdf import doctor, ingest
11
+ from mednotes.kernel.base import JsonObject, JsonObjectAdapter
12
+
13
+ EXIT_OK = 0
14
+ EXIT_USAGE = 2
15
+ EXIT_VALIDATION = 3
16
+ EXIT_IO = 5
17
+
18
+
19
+ def scan_dry_run(cfg: config_mod.PdfLibraryConfig, *, app_home: Path | None = None) -> JsonObject:
20
+ return _as_payload(ingest.scan_dry_run(cfg, app_home=app_home))
21
+
22
+
23
+ def main(argv: list[str] | None = None) -> int:
24
+ parser = build_parser()
25
+ args = parser.parse_args(argv)
26
+ try:
27
+ payload = dispatch(args)
28
+ except Exception as exc:
29
+ payload = _as_payload({
30
+ "schema": "medical-notes-workbench.pdf-library-error.v1",
31
+ "status": "failed",
32
+ "phase": getattr(args, "command", "unknown"),
33
+ "error": type(exc).__name__,
34
+ "message": str(exc),
35
+ })
36
+ _emit(payload)
37
+ return EXIT_IO
38
+ _emit(payload)
39
+ status = _payload_status(payload)
40
+ if status in {"blocked", "blocked_vault_guard_required"}:
41
+ return EXIT_VALIDATION
42
+ if status == "failed":
43
+ return EXIT_IO
44
+ return EXIT_OK
45
+
46
+
47
+ def build_parser() -> argparse.ArgumentParser:
48
+ parser = argparse.ArgumentParser(prog="pdf-library")
49
+ sub = parser.add_subparsers(dest="command", required=True)
50
+
51
+ doctor_p = sub.add_parser("doctor")
52
+ doctor_p.add_argument("--json", action="store_true")
53
+ doctor_p.add_argument("--config", type=Path)
54
+ doctor_p.add_argument("--path", "--pdf-dir", dest="paths", type=Path, action="append")
55
+
56
+ setup_p = sub.add_parser("setup")
57
+ setup_p.add_argument("--json", action="store_true")
58
+ setup_p.add_argument("--dry-run", action="store_true")
59
+
60
+ tui_p = sub.add_parser("tui")
61
+ tui_p.add_argument("--note", type=Path)
62
+ tui_p.add_argument("--image-backend", default=None)
63
+ tui_p.add_argument("--open-mode", choices=["inline", "split-auto"], default="inline")
64
+
65
+ ingest_p = sub.add_parser("ingest")
66
+ ingest_sub = ingest_p.add_subparsers(dest="ingest_command", required=True)
67
+ scan_p = ingest_sub.add_parser("scan")
68
+ scan_p.add_argument("--dry-run", action="store_true", required=True)
69
+ scan_p.add_argument("--json", action="store_true")
70
+ scan_p.add_argument("--config", type=Path)
71
+ scan_p.add_argument("--path", "--pdf-dir", dest="paths", type=Path, action="append")
72
+ add_p = ingest_sub.add_parser("add")
73
+ add_p.add_argument("pdfs", type=Path, nargs="+")
74
+ add_p.add_argument("--json", action="store_true")
75
+ remove_p = ingest_sub.add_parser("remove")
76
+ remove_p.add_argument("--pdf-sha256", required=True)
77
+ remove_p.add_argument("--json", action="store_true")
78
+ reindex_p = ingest_sub.add_parser("reindex")
79
+ reindex_p.add_argument("--pdf-sha256")
80
+ reindex_p.add_argument("--path", type=Path)
81
+ reindex_p.add_argument("--json", action="store_true")
82
+
83
+ search_p = sub.add_parser("search")
84
+ group = search_p.add_mutually_exclusive_group(required=False)
85
+ group.add_argument("--query")
86
+ group.add_argument("--note", type=Path)
87
+ search_p.add_argument("--anchor-id", default="")
88
+ search_p.add_argument("--provider", default="local")
89
+ search_p.add_argument("--top-k", type=int, default=20)
90
+ search_p.add_argument("--json", action="store_true")
91
+
92
+ insert_p = sub.add_parser("insert")
93
+ insert_sub = insert_p.add_subparsers(dest="insert_command", required=True)
94
+ preview_p = insert_sub.add_parser("preview")
95
+ preview_p.add_argument("--note", type=Path, required=True)
96
+ preview_p.add_argument("--figure-uid", required=True)
97
+ preview_p.add_argument("--anchor-id", default="")
98
+ preview_p.add_argument("--section", action="append", dest="section_path")
99
+ preview_p.add_argument("--crop", type=Path)
100
+ preview_p.add_argument("--json", action="store_true")
101
+ apply_p = insert_sub.add_parser("apply")
102
+ apply_p.add_argument("--preview-receipt", type=Path, required=True)
103
+ apply_p.add_argument("--confirm", action="store_true")
104
+ apply_p.add_argument("--json", action="store_true")
105
+ return parser
106
+
107
+
108
+ def dispatch(args: argparse.Namespace) -> JsonObject:
109
+ if args.command == "doctor":
110
+ cfg = config_mod.load_pdf_library_config(config_path=args.config, cli_paths=args.paths)
111
+ return _as_payload(doctor.run_doctor(cfg=cfg))
112
+ if args.command == "setup":
113
+ return _as_payload(doctor.setup_payload(dry_run=args.dry_run))
114
+ if args.command == "tui":
115
+ from mednotes.domains.wiki.capabilities.pdf.tui.app import PdfLibraryApp
116
+ from mednotes.domains.wiki.capabilities.pdf.tui.state import PdfLibraryState
117
+
118
+ app = PdfLibraryApp(state=PdfLibraryState(selected_note=args.note), image_backend=args.image_backend or "auto")
119
+ app.run()
120
+ return _as_payload({"schema": "medical-notes-workbench.pdf-library-tui.v1", "status": "closed", "phase": "tui"})
121
+ if args.command == "ingest":
122
+ if args.ingest_command == "scan":
123
+ cfg = config_mod.load_pdf_library_config(config_path=args.config, cli_paths=args.paths)
124
+ return _as_payload(ingest.scan_dry_run(cfg))
125
+ if args.ingest_command == "add":
126
+ return _as_payload(ingest.add_pdfs(args.pdfs))
127
+ if args.ingest_command == "remove":
128
+ return _as_payload(ingest.remove_pdf(pdf_sha256=args.pdf_sha256))
129
+ if args.ingest_command == "reindex":
130
+ return _as_payload(ingest.reindex_pdf(pdf_sha256=args.pdf_sha256, path=args.path))
131
+ if args.command == "search":
132
+ from mednotes.domains.wiki.capabilities.pdf import search
133
+
134
+ return _as_payload(
135
+ search.search(
136
+ search.SearchRequest(
137
+ query_text=args.query or "",
138
+ note_path=args.note,
139
+ anchor_id=args.anchor_id,
140
+ provider=args.provider,
141
+ top_k=args.top_k,
142
+ )
143
+ )
144
+ )
145
+ if args.command == "insert":
146
+ from mednotes.domains.wiki.capabilities.pdf import insert
147
+
148
+ if args.insert_command == "preview":
149
+ crop = args.crop
150
+ if crop is None:
151
+ return _as_payload({
152
+ "schema": insert.PREVIEW_SCHEMA,
153
+ "status": "blocked",
154
+ "phase": "insert_preview",
155
+ "blocked_reason": "crop_path_required",
156
+ "next_action": "pass --crop PATH",
157
+ })
158
+ section = list(args.section_path or [])
159
+ return insert.preview(note_path=args.note, figure_uid=args.figure_uid, section_path=section, crop_path=crop)
160
+ if args.insert_command == "apply":
161
+ return insert.apply_preview(receipt_path=args.preview_receipt, confirm=args.confirm)
162
+ raise AssertionError(f"unhandled command: {args.command}")
163
+
164
+
165
+ def _as_payload(payload: object) -> JsonObject:
166
+ return JsonObjectAdapter.validate_python(payload)
167
+
168
+
169
+ def _payload_status(payload: JsonObject) -> str:
170
+ value = _as_payload(payload).get("status")
171
+ return value if isinstance(value, str) else ""
172
+
173
+
174
+ def _emit(payload: JsonObject) -> None:
175
+ print(json.dumps(_as_payload(payload), ensure_ascii=False))
176
+
177
+
178
+ if __name__ == "__main__":
179
+ raise SystemExit(main())
@@ -0,0 +1,52 @@
1
+ """Optional provider registry for PDF library cloud assists."""
2
+ from __future__ import annotations
3
+
4
+ from datetime import UTC, datetime
5
+ from typing import Any
6
+
7
+ RESERVED_PROVIDERS = {"huggingface_free", "free_api_quota", "hosted_open_model_free_quota"}
8
+ FUNCTIONAL_PROVIDERS = {"local", "gemini_cli"}
9
+
10
+
11
+ def resolve_provider(provider: str) -> dict[str, Any]:
12
+ if provider in RESERVED_PROVIDERS:
13
+ return {
14
+ "schema": "medical-notes-workbench.pdf-library-provider-receipt.v1",
15
+ "provider": provider,
16
+ "model": "",
17
+ "purpose": "anchors",
18
+ "status": "blocked",
19
+ "blocked_reason": "provider_not_implemented",
20
+ "quota_limited": False,
21
+ "item_count": 0,
22
+ "created_at": _now(),
23
+ "next_action": "use gemini_cli or local mode",
24
+ }
25
+ if provider not in FUNCTIONAL_PROVIDERS:
26
+ return {
27
+ "schema": "medical-notes-workbench.pdf-library-provider-receipt.v1",
28
+ "provider": provider,
29
+ "model": "",
30
+ "purpose": "anchors",
31
+ "status": "blocked",
32
+ "blocked_reason": "provider_not_implemented",
33
+ "quota_limited": False,
34
+ "item_count": 0,
35
+ "created_at": _now(),
36
+ "next_action": "use gemini_cli or local mode",
37
+ }
38
+ return {
39
+ "schema": "medical-notes-workbench.pdf-library-provider-receipt.v1",
40
+ "provider": provider,
41
+ "model": "gemini-configured-default" if provider == "gemini_cli" else "",
42
+ "purpose": "anchors",
43
+ "status": "completed",
44
+ "blocked_reason": "",
45
+ "quota_limited": False,
46
+ "item_count": 0,
47
+ "created_at": _now(),
48
+ }
49
+
50
+
51
+ def _now() -> str:
52
+ return datetime.now(UTC).isoformat()
@@ -0,0 +1,196 @@
1
+ """Configuration loading for the PDF library."""
2
+ from __future__ import annotations
3
+
4
+ import os
5
+ import tomllib
6
+ from dataclasses import dataclass, field
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+ from mednotes.domains.wiki.capabilities.pdf import paths
11
+
12
+ VALID_CLOUD_POLICIES = {"optional", "disabled"}
13
+ VALID_IMAGE_BACKENDS = {"auto", "sixel", "tgp", "halfcell", "chafa", "ascii", "none"}
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class PdfLibraryLocalConfig:
18
+ text_index: str = "sqlite-fts5"
19
+ image_embedding: str = "none"
20
+ ocr: str = "tesseract"
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class PdfLibraryCloudConfig:
25
+ enabled: bool = True
26
+ default_provider: str = "gemini_cli"
27
+ allow_free_api_quota: bool = True
28
+ allow_hosted_open_model_free_quota: bool = True
29
+ send_full_pdf: bool = False
30
+ send_full_ocr_text: bool = False
31
+ record_provider_receipts: bool = True
32
+
33
+
34
+ @dataclass(frozen=True)
35
+ class PdfLibraryContextConfig:
36
+ detect_figure_ids: bool = True
37
+ link_mentions: bool = True
38
+ default_mention_window_pages: int = 20
39
+ conflict_policy: str = "needs_review"
40
+
41
+
42
+ @dataclass(frozen=True)
43
+ class PdfLibraryOcrConfig:
44
+ enabled: bool = True
45
+ backend: str = "tesseract"
46
+ languages: list[str] = field(default_factory=lambda: ["por", "eng"])
47
+ auto_run: bool = False
48
+ max_parallel_pages: int = 1
49
+ page_timeout_seconds: int = 90
50
+
51
+
52
+ @dataclass(frozen=True)
53
+ class PdfLibraryTuiConfig:
54
+ enabled: bool = True
55
+ show_thumbnails: bool = True
56
+ image_backend: str = "auto"
57
+ confirm_insert: bool = True
58
+
59
+
60
+ @dataclass(frozen=True)
61
+ class PdfLibraryConfig:
62
+ enabled: bool = True
63
+ mode: str = "cost-constrained-12gb"
64
+ paths: list[Path] = field(default_factory=list)
65
+ index_granularity: str = "figure"
66
+ cloud_policy: str = "optional"
67
+ local: PdfLibraryLocalConfig = field(default_factory=PdfLibraryLocalConfig)
68
+ cloud: PdfLibraryCloudConfig = field(default_factory=PdfLibraryCloudConfig)
69
+ context: PdfLibraryContextConfig = field(default_factory=PdfLibraryContextConfig)
70
+ ocr: PdfLibraryOcrConfig = field(default_factory=PdfLibraryOcrConfig)
71
+ tui: PdfLibraryTuiConfig = field(default_factory=PdfLibraryTuiConfig)
72
+
73
+
74
+ def load_pdf_library_config(
75
+ *,
76
+ config_path: Path | None = None,
77
+ cli_paths: list[Path] | None = None,
78
+ cloud_policy: str | None = None,
79
+ image_backend: str | None = None,
80
+ ) -> PdfLibraryConfig:
81
+ raw = _read_config(config_path or paths.app_config_path())
82
+ section = raw.get("pdf_library") if isinstance(raw.get("pdf_library"), dict) else {}
83
+ cfg = _from_section(section)
84
+
85
+ env_paths = _env_paths()
86
+ effective_paths = cli_paths if cli_paths is not None else env_paths if env_paths is not None else cfg.paths
87
+ effective_cloud_policy = (
88
+ cloud_policy
89
+ or os.environ.get("MEDNOTES_PDF_LIBRARY_CLOUD_POLICY")
90
+ or cfg.cloud_policy
91
+ )
92
+ effective_image_backend = (
93
+ image_backend
94
+ or os.environ.get("MEDNOTES_PDF_LIBRARY_IMAGE_BACKEND")
95
+ or cfg.tui.image_backend
96
+ )
97
+ _validate_choice("cloud_policy", effective_cloud_policy, VALID_CLOUD_POLICIES)
98
+ _validate_choice("image_backend", effective_image_backend, VALID_IMAGE_BACKENDS)
99
+ return PdfLibraryConfig(
100
+ enabled=cfg.enabled,
101
+ mode=cfg.mode,
102
+ paths=[_resolve_path(path) for path in effective_paths],
103
+ index_granularity=cfg.index_granularity,
104
+ cloud_policy=effective_cloud_policy,
105
+ local=cfg.local,
106
+ cloud=cfg.cloud,
107
+ context=cfg.context,
108
+ ocr=cfg.ocr,
109
+ tui=PdfLibraryTuiConfig(
110
+ enabled=cfg.tui.enabled,
111
+ show_thumbnails=cfg.tui.show_thumbnails,
112
+ image_backend=effective_image_backend,
113
+ confirm_insert=cfg.tui.confirm_insert,
114
+ ),
115
+ )
116
+
117
+
118
+ def _read_config(path: Path) -> dict[str, Any]:
119
+ try:
120
+ return tomllib.loads(path.expanduser().read_text(encoding="utf-8"))
121
+ except FileNotFoundError:
122
+ return {}
123
+
124
+
125
+ def _from_section(section: dict[str, Any]) -> PdfLibraryConfig:
126
+ local = section.get("local") if isinstance(section.get("local"), dict) else {}
127
+ cloud = section.get("cloud") if isinstance(section.get("cloud"), dict) else {}
128
+ context = section.get("context") if isinstance(section.get("context"), dict) else {}
129
+ ocr = section.get("ocr") if isinstance(section.get("ocr"), dict) else {}
130
+ tui = section.get("tui") if isinstance(section.get("tui"), dict) else {}
131
+ return PdfLibraryConfig(
132
+ enabled=bool(section.get("enabled", True)),
133
+ mode=str(section.get("mode", "cost-constrained-12gb")),
134
+ paths=[_resolve_path(Path(str(item))) for item in _as_list(section.get("paths"))],
135
+ index_granularity=str(section.get("index_granularity", "figure")),
136
+ cloud_policy=str(section.get("cloud_policy", "optional")),
137
+ local=PdfLibraryLocalConfig(
138
+ text_index=str(local.get("text_index", "sqlite-fts5")),
139
+ image_embedding=str(local.get("image_embedding", "none")),
140
+ ocr=str(local.get("ocr", "tesseract")),
141
+ ),
142
+ cloud=PdfLibraryCloudConfig(
143
+ enabled=bool(cloud.get("enabled", True)),
144
+ default_provider=str(cloud.get("default_provider", "gemini_cli")),
145
+ allow_free_api_quota=bool(cloud.get("allow_free_api_quota", True)),
146
+ allow_hosted_open_model_free_quota=bool(cloud.get("allow_hosted_open_model_free_quota", True)),
147
+ send_full_pdf=bool(cloud.get("send_full_pdf", False)),
148
+ send_full_ocr_text=bool(cloud.get("send_full_ocr_text", False)),
149
+ record_provider_receipts=bool(cloud.get("record_provider_receipts", True)),
150
+ ),
151
+ context=PdfLibraryContextConfig(
152
+ detect_figure_ids=bool(context.get("detect_figure_ids", True)),
153
+ link_mentions=bool(context.get("link_mentions", True)),
154
+ default_mention_window_pages=int(context.get("default_mention_window_pages", 20)),
155
+ conflict_policy=str(context.get("conflict_policy", "needs_review")),
156
+ ),
157
+ ocr=PdfLibraryOcrConfig(
158
+ enabled=bool(ocr.get("enabled", True)),
159
+ backend=str(ocr.get("backend", "tesseract")),
160
+ languages=[str(item) for item in _as_list(ocr.get("languages", ["por", "eng"]))],
161
+ auto_run=bool(ocr.get("auto_run", False)),
162
+ max_parallel_pages=int(ocr.get("max_parallel_pages", 1)),
163
+ page_timeout_seconds=int(ocr.get("page_timeout_seconds", 90)),
164
+ ),
165
+ tui=PdfLibraryTuiConfig(
166
+ enabled=bool(tui.get("enabled", True)),
167
+ show_thumbnails=bool(tui.get("show_thumbnails", True)),
168
+ image_backend=str(tui.get("image_backend", "auto")),
169
+ confirm_insert=bool(tui.get("confirm_insert", True)),
170
+ ),
171
+ )
172
+
173
+
174
+ def _as_list(value: Any) -> list[Any]:
175
+ if value is None:
176
+ return []
177
+ if isinstance(value, list):
178
+ return value
179
+ return [value]
180
+
181
+
182
+ def _env_paths() -> list[Path] | None:
183
+ raw = os.environ.get("MEDNOTES_PDF_LIBRARY_PATHS")
184
+ if raw is None:
185
+ return None
186
+ items = [part.strip() for part in raw.replace(",", os.pathsep).split(os.pathsep)]
187
+ return [_resolve_path(Path(part)) for part in items if part]
188
+
189
+
190
+ def _resolve_path(path: Path) -> Path:
191
+ return path.expanduser().resolve(strict=False)
192
+
193
+
194
+ def _validate_choice(name: str, value: str, choices: set[str]) -> None:
195
+ if value not in choices:
196
+ raise ValueError(f"invalid {name}: {value!r}; expected one of {sorted(choices)}")
@@ -0,0 +1,76 @@
1
+ """Redacted context packets for PDF figures."""
2
+ from __future__ import annotations
3
+
4
+ import hashlib
5
+ import json
6
+ from typing import Any
7
+
8
+ from mednotes.domains.wiki.capabilities.pdf.captions import Caption
9
+ from mednotes.domains.wiki.capabilities.pdf.mentions import Mention
10
+
11
+ SCHEMA = "medical-notes-workbench.pdf-figure-context-packet.v1"
12
+ EVIDENCE_LEVELS = {"caption_and_mentions", "caption_only", "mentions_only", "page_context_only", "visual_only"}
13
+
14
+
15
+ def build_packet(
16
+ *,
17
+ caption: Caption | None = None,
18
+ mentions: list[Mention] | None = None,
19
+ heading_window: str | None = None,
20
+ figure_uid: str | None = None,
21
+ ) -> dict[str, Any]:
22
+ mentions = list(mentions or [])
23
+ evidence_level = _evidence_level(caption, mentions)
24
+ if evidence_level not in EVIDENCE_LEVELS:
25
+ return {"status": "blocked", "blocked_reason": "invalid_evidence_level"}
26
+ conflict_reason = _conflict_reason(caption, mentions, heading_window)
27
+ is_low_confidence = bool(conflict_reason or evidence_level in {"page_context_only", "visual_only", "mentions_only"})
28
+ figure_id = caption.figure_id if caption else mentions[0].figure_id if mentions else ""
29
+ return {
30
+ "schema": SCHEMA,
31
+ "figure_uid": figure_uid or _uid(figure_id, caption.text if caption else ""),
32
+ "figure_id": figure_id,
33
+ "caption": {"page_number": caption.page_number, "text": caption.text} if caption else None,
34
+ "mentions": [
35
+ {
36
+ "page_number": mention.page_number,
37
+ "sentence": mention.sentence,
38
+ "section_path_guess": list(mention.section_path_guess),
39
+ }
40
+ for mention in mentions
41
+ ],
42
+ "section_path_guess": list(caption.section_path_guess if caption else mentions[0].section_path_guess if mentions else []),
43
+ "evidence_level": evidence_level,
44
+ "is_low_confidence": is_low_confidence,
45
+ "conflict_reason": conflict_reason,
46
+ "source_coordinates": {
47
+ "caption_page": caption.page_number if caption else None,
48
+ "mention_pages": [mention.page_number for mention in mentions],
49
+ },
50
+ }
51
+
52
+
53
+ def _evidence_level(caption: Caption | None, mentions: list[Mention]) -> str:
54
+ if caption and mentions:
55
+ return "caption_and_mentions"
56
+ if caption:
57
+ return "caption_only"
58
+ if mentions:
59
+ return "mentions_only"
60
+ return "visual_only"
61
+
62
+
63
+ def _conflict_reason(caption: Caption | None, mentions: list[Mention], heading_window: str | None) -> str:
64
+ if not caption or not mentions or heading_window:
65
+ return ""
66
+ for mention in mentions:
67
+ if caption.section_path_guess and mention.section_path_guess and caption.section_path_guess[:1] == mention.section_path_guess[:1]:
68
+ continue
69
+ if abs(mention.page_number - caption.page_number) > 20:
70
+ return "same_id_distant_sections"
71
+ return ""
72
+
73
+
74
+ def _uid(*parts: str) -> str:
75
+ material = json.dumps(parts, ensure_ascii=False, sort_keys=True).encode("utf-8")
76
+ return f"ctx:{hashlib.sha256(material).hexdigest()[:16]}"
@@ -0,0 +1,81 @@
1
+ """SQLite helpers for the PDF library."""
2
+ from __future__ import annotations
3
+
4
+ import sqlite3
5
+ from pathlib import Path
6
+
7
+ from mednotes.domains.wiki.capabilities.pdf import schema
8
+
9
+
10
+ def open_database(path: Path) -> sqlite3.Connection:
11
+ path.expanduser().parent.mkdir(parents=True, exist_ok=True)
12
+ conn = sqlite3.connect(path)
13
+ conn.row_factory = sqlite3.Row
14
+ conn.execute("PRAGMA foreign_keys=ON")
15
+ with conn:
16
+ conn.executescript(schema.SCHEMA_SQL)
17
+ conn.execute(
18
+ "INSERT OR REPLACE INTO metadata(key, value) VALUES ('schema_version', ?)",
19
+ (schema.SCHEMA_VERSION,),
20
+ )
21
+ return conn
22
+
23
+
24
+ def schema_version(conn: sqlite3.Connection) -> str:
25
+ row = conn.execute("SELECT value FROM metadata WHERE key = 'schema_version'").fetchone()
26
+ return str(row[0]) if row else ""
27
+
28
+
29
+ def replace_page_fts(
30
+ conn: sqlite3.Connection,
31
+ *,
32
+ pdf_sha256: str,
33
+ page_number: int,
34
+ title_guess: str,
35
+ section_path_guess: str,
36
+ text: str,
37
+ ) -> None:
38
+ conn.execute("DELETE FROM page_fts WHERE pdf_sha256 = ? AND page_number = ?", (pdf_sha256, page_number))
39
+ conn.execute(
40
+ "INSERT INTO page_fts(pdf_sha256, page_number, title_guess, section_path_guess, text) VALUES (?, ?, ?, ?, ?)",
41
+ (pdf_sha256, page_number, title_guess, section_path_guess, text),
42
+ )
43
+
44
+
45
+ def replace_figure_fts(
46
+ conn: sqlite3.Connection,
47
+ *,
48
+ figure_uid: str,
49
+ pdf_sha256: str,
50
+ figure_id: str,
51
+ display_label: str,
52
+ caption: str,
53
+ ) -> None:
54
+ conn.execute("DELETE FROM figure_fts WHERE figure_uid = ?", (figure_uid,))
55
+ conn.execute(
56
+ "INSERT INTO figure_fts(figure_uid, pdf_sha256, figure_id, display_label, caption) VALUES (?, ?, ?, ?, ?)",
57
+ (figure_uid, pdf_sha256, figure_id, display_label, caption),
58
+ )
59
+
60
+
61
+ def replace_mention_fts(
62
+ conn: sqlite3.Connection,
63
+ *,
64
+ mention_uid: str,
65
+ pdf_sha256: str,
66
+ figure_id: str,
67
+ sentence: str,
68
+ paragraph: str,
69
+ section_path_guess: str,
70
+ ) -> None:
71
+ conn.execute("DELETE FROM mention_fts WHERE mention_uid = ?", (mention_uid,))
72
+ conn.execute(
73
+ "INSERT INTO mention_fts(mention_uid, pdf_sha256, figure_id, sentence, paragraph, section_path_guess) VALUES (?, ?, ?, ?, ?, ?)",
74
+ (mention_uid, pdf_sha256, figure_id, sentence, paragraph, section_path_guess),
75
+ )
76
+
77
+
78
+ def delete_document_fts(conn: sqlite3.Connection, *, pdf_sha256: str) -> None:
79
+ conn.execute("DELETE FROM page_fts WHERE pdf_sha256 = ?", (pdf_sha256,))
80
+ conn.execute("DELETE FROM figure_fts WHERE pdf_sha256 = ?", (pdf_sha256,))
81
+ conn.execute("DELETE FROM mention_fts WHERE pdf_sha256 = ?", (pdf_sha256,))
@@ -0,0 +1,102 @@
1
+ """Bootstrap-safe doctor and setup helpers."""
2
+ from __future__ import annotations
3
+
4
+ import importlib.util
5
+ import os
6
+ import platform
7
+ import shutil
8
+ import subprocess
9
+ from datetime import UTC, datetime
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from mednotes.domains.wiki.capabilities.pdf import config as config_mod
14
+ from mednotes.domains.wiki.capabilities.pdf import paths
15
+
16
+ DOCTOR_SCHEMA = "medical-notes-workbench.pdf-library-doctor.v1"
17
+ SETUP_SCHEMA = "medical-notes-workbench.pdf-library-setup.v1"
18
+ REQUIRED_MODULES = {
19
+ "fitz": "PyMuPDF",
20
+ "pytesseract": "pytesseract",
21
+ "textual": "textual",
22
+ }
23
+
24
+
25
+ def run_doctor(*, cfg: config_mod.PdfLibraryConfig | None = None, app_home: Path | None = None) -> dict[str, Any]:
26
+ cfg = cfg or config_mod.load_pdf_library_config()
27
+ missing = [dist for module, dist in REQUIRED_MODULES.items() if importlib.util.find_spec(module) is None]
28
+ missing_paths = [str(path) for path in cfg.paths if not path.exists()]
29
+ payload: dict[str, Any] = {
30
+ "schema": DOCTOR_SCHEMA,
31
+ "status": "ok",
32
+ "phase": "doctor",
33
+ "app_home": str(app_home or paths.app_home()),
34
+ "configured_paths": [str(path) for path in cfg.paths],
35
+ "missing_paths": missing_paths,
36
+ "dependencies": {
37
+ "missing": missing,
38
+ "tesseract_binary": shutil.which("tesseract") or "",
39
+ "platform": platform.platform(),
40
+ },
41
+ "third_party_notices": [
42
+ "PyMuPDF is optional and distributed under AGPL/commercial terms.",
43
+ ],
44
+ "created_at": _now(),
45
+ }
46
+ blockers: list[str] = []
47
+ if missing:
48
+ blockers.append("pdf_library_dependencies_missing")
49
+ if missing_paths:
50
+ blockers.append("pdf_library_paths_missing")
51
+ if blockers:
52
+ payload.update(
53
+ {
54
+ "status": "blocked",
55
+ "blocked_reason": blockers[0],
56
+ "next_action": "/mednotes:pdf-library setup" if "pdf_library_dependencies_missing" in blockers else "fix configured PDF paths",
57
+ "required_inputs": ["pdf-library optional dependencies"] if missing else ["valid PDF paths"],
58
+ }
59
+ )
60
+ return payload
61
+
62
+
63
+ def setup_payload(*, dry_run: bool, app_home: Path | None = None, extension_path: Path | None = None) -> dict[str, Any]:
64
+ root = app_home or paths.app_home()
65
+ venv = root.parent / ".venv"
66
+ project = extension_path or paths.extension_root()
67
+ cmd = ["uv", "sync", "--project", str(project), "--extra", "pdf-library"]
68
+ payload: dict[str, Any] = {
69
+ "schema": SETUP_SCHEMA,
70
+ "status": "dry_run" if dry_run else "running",
71
+ "phase": "setup",
72
+ "uv_project_environment": str(venv),
73
+ "command": cmd,
74
+ "third_party_notices": [
75
+ "PyMuPDF is optional and distributed under AGPL/commercial terms.",
76
+ ],
77
+ }
78
+ if dry_run:
79
+ return payload
80
+ env = dict(os.environ)
81
+ env["UV_PROJECT_ENVIRONMENT"] = str(venv)
82
+ proc = subprocess.run(cmd, text=True, capture_output=True, env=env, check=False)
83
+ payload.update(
84
+ {
85
+ "status": "ok" if proc.returncode == 0 else "failed",
86
+ "exit_code": proc.returncode,
87
+ "stdout_tail": proc.stdout[-4000:],
88
+ "stderr_tail": proc.stderr[-4000:],
89
+ }
90
+ )
91
+ if proc.returncode != 0:
92
+ payload.update(
93
+ {
94
+ "blocked_reason": "pdf_library_setup_failed",
95
+ "next_action": "corrigir ambiente uv/Python e rodar /mednotes:setup",
96
+ }
97
+ )
98
+ return payload
99
+
100
+
101
+ def _now() -> str:
102
+ return datetime.now(UTC).isoformat()