weavemark 0.8.0__py3-none-any.whl

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 (259) hide show
  1. weavemark/__init__.py +85 -0
  2. weavemark/api.py +459 -0
  3. weavemark/app.py +2395 -0
  4. weavemark/cli_inputs.py +245 -0
  5. weavemark/compilation/__init__.py +8 -0
  6. weavemark/compilation/args.py +150 -0
  7. weavemark/compilation/ask.py +252 -0
  8. weavemark/compilation/diagnostics.py +133 -0
  9. weavemark/compilation/directive_registry.py +94 -0
  10. weavemark/compilation/fslm_sugar.py +645 -0
  11. weavemark/compilation/iterate.py +518 -0
  12. weavemark/compilation/macros.py +1296 -0
  13. weavemark/compilation/multimodal.py +235 -0
  14. weavemark/compilation/prompt_header.py +177 -0
  15. weavemark/compilation/provenance.py +999 -0
  16. weavemark/compilation/result.py +134 -0
  17. weavemark/compilation/result_schema.py +192 -0
  18. weavemark/compilation/state.py +256 -0
  19. weavemark/compilation/structural.py +2244 -0
  20. weavemark/compilation/trace.py +211 -0
  21. weavemark/compile_options.py +44 -0
  22. weavemark/controller.py +2203 -0
  23. weavemark/defaults.py +10 -0
  24. weavemark/discovery/__init__.py +1 -0
  25. weavemark/discovery/catalog.py +115 -0
  26. weavemark/discovery/chat_ui.py +193 -0
  27. weavemark/discovery/config.py +146 -0
  28. weavemark/discovery/metadata.py +208 -0
  29. weavemark/discovery/tools.py +277 -0
  30. weavemark/engines/__init__.py +48 -0
  31. weavemark/engines/base.py +569 -0
  32. weavemark/engines/chain.py +270 -0
  33. weavemark/engines/chat.py +126 -0
  34. weavemark/engines/collaborative.py +253 -0
  35. weavemark/engines/fslm.py +1298 -0
  36. weavemark/engines/reflection.py +464 -0
  37. weavemark/engines/registry.py +93 -0
  38. weavemark/engines/self_consistency.py +31 -0
  39. weavemark/engines/single_call.py +185 -0
  40. weavemark/engines/tree_of_thought.py +68 -0
  41. weavemark/engines/weave.py +43 -0
  42. weavemark/exceptions.py +17 -0
  43. weavemark/fragments.py +187 -0
  44. weavemark/implementation.py +877 -0
  45. weavemark/library_cli.py +275 -0
  46. weavemark/logging_policy.py +351 -0
  47. weavemark/logging_setup.py +335 -0
  48. weavemark/packaging/__init__.py +27 -0
  49. weavemark/packaging/convert.py +61 -0
  50. weavemark/packaging/persist.py +135 -0
  51. weavemark/packaging/runner.py +228 -0
  52. weavemark/promplet_library.py +487 -0
  53. weavemark/promplets/README.md +89 -0
  54. weavemark/promplets/catalog/executable/childrens-book.weavemark.md +78 -0
  55. weavemark/promplets/catalog/executable/collaborative-investment-strategy.weavemark.md +68 -0
  56. weavemark/promplets/catalog/executable/collaborative-investment-strategy.weavemark.yaml +22 -0
  57. weavemark/promplets/catalog/executable/collaborative-writer.weavemark.md +62 -0
  58. weavemark/promplets/catalog/executable/collaborative-writer.weavemark.yaml +20 -0
  59. weavemark/promplets/catalog/executable/comic-strip.weavemark.md +123 -0
  60. weavemark/promplets/catalog/executable/companions/public_finance_reference.py +171 -0
  61. weavemark/promplets/catalog/executable/companions/recurring_topic_monitor.py +837 -0
  62. weavemark/promplets/catalog/executable/contrastive-mining.weavemark.md +113 -0
  63. weavemark/promplets/catalog/executable/contrastive-mining.weavemark.yaml +17 -0
  64. weavemark/promplets/catalog/executable/crisis-strategy-analyzer.earthquake.vars.json +8 -0
  65. weavemark/promplets/catalog/executable/crisis-strategy-analyzer.weavemark.md +152 -0
  66. weavemark/promplets/catalog/executable/financial-independence-goal-plan.weavemark.md +21 -0
  67. weavemark/promplets/catalog/executable/portfolio-calculator-agent.weavemark.md +45 -0
  68. weavemark/promplets/catalog/executable/react-agent.weavemark.md +67 -0
  69. weavemark/promplets/catalog/executable/recurring-topic-monitor.weavemark.md +134 -0
  70. weavemark/promplets/catalog/executable/recurring-topic-monitor.weavemark.yaml +23 -0
  71. weavemark/promplets/catalog/executable/reflection-solver.weavemark.md +64 -0
  72. weavemark/promplets/catalog/executable/reflection-writer.weavemark.md +56 -0
  73. weavemark/promplets/catalog/executable/reflection-writer.weavemark.yaml +22 -0
  74. weavemark/promplets/catalog/executable/self-consistency-solver.weavemark.md +39 -0
  75. weavemark/promplets/catalog/executable/self-consistency-solver.weavemark.yaml +11 -0
  76. weavemark/promplets/catalog/executable/self-improving-image.weavemark.md +35 -0
  77. weavemark/promplets/catalog/executable/simplified-tree-of-thought-solver.weavemark.md +55 -0
  78. weavemark/promplets/catalog/executable/spec-discovery.weavemark.md +57 -0
  79. weavemark/promplets/catalog/executable/storyboard-chain.weavemark.md +32 -0
  80. weavemark/promplets/catalog/executable/storyboard-chain.weavemark.yaml +10 -0
  81. weavemark/promplets/catalog/executable/tree-of-thought-solver.weavemark.md +73 -0
  82. weavemark/promplets/catalog/executable/tree-of-thought-solver.weavemark.yaml +21 -0
  83. weavemark/promplets/catalog/standalone/adaptive-interview.weavemark.md +135 -0
  84. weavemark/promplets/catalog/standalone/ai-kanban-board.vars.json +4 -0
  85. weavemark/promplets/catalog/standalone/ai-kanban-board.weavemark.md +246 -0
  86. weavemark/promplets/catalog/standalone/analysis-of-competing-hypotheses.vars.json +8 -0
  87. weavemark/promplets/catalog/standalone/analysis-of-competing-hypotheses.weavemark.md +153 -0
  88. weavemark/promplets/catalog/standalone/api-docs-generator.vars.json +27 -0
  89. weavemark/promplets/catalog/standalone/api-docs-generator.weavemark.md +59 -0
  90. weavemark/promplets/catalog/standalone/compoundvision-investment-simulator.historical.vars.json +3 -0
  91. weavemark/promplets/catalog/standalone/compoundvision-investment-simulator.montecarlo.vars.json +3 -0
  92. weavemark/promplets/catalog/standalone/compoundvision-investment-simulator.weavemark.md +200 -0
  93. weavemark/promplets/catalog/standalone/consulting-proposal.weavemark.md +84 -0
  94. weavemark/promplets/catalog/standalone/creative-ideation.weavemark.md +88 -0
  95. weavemark/promplets/catalog/standalone/decision-advisor.weavemark.md +71 -0
  96. weavemark/promplets/catalog/standalone/deep-summary.weavemark.md +52 -0
  97. weavemark/promplets/catalog/standalone/fieldpulse-iot-agriculture.vars.json +4 -0
  98. weavemark/promplets/catalog/standalone/fieldpulse-iot-agriculture.weavemark.md +146 -0
  99. weavemark/promplets/catalog/standalone/financial-independence-decision.weavemark.md +62 -0
  100. weavemark/promplets/catalog/standalone/financial-independence-goal-plan.weavemark.md +14 -0
  101. weavemark/promplets/catalog/standalone/investment-brief.weavemark.md +56 -0
  102. weavemark/promplets/catalog/standalone/issue-tree-analysis.vars.json +7 -0
  103. weavemark/promplets/catalog/standalone/issue-tree-analysis.weavemark.md +114 -0
  104. weavemark/promplets/catalog/standalone/iterative-onboarding-prompt.weavemark.md +28 -0
  105. weavemark/promplets/catalog/standalone/knowledge-base-article.weavemark.md +64 -0
  106. weavemark/promplets/catalog/standalone/learning-tutor.weavemark.md +57 -0
  107. weavemark/promplets/catalog/standalone/live-investment-decision-brief.weavemark.md +71 -0
  108. weavemark/promplets/catalog/standalone/logo-generator.weavemark.md +13 -0
  109. weavemark/promplets/catalog/standalone/market-research-brief.weavemark.md +70 -0
  110. weavemark/promplets/catalog/standalone/mece-structuring.vars.json +7 -0
  111. weavemark/promplets/catalog/standalone/mece-structuring.weavemark.md +120 -0
  112. weavemark/promplets/catalog/standalone/messy-notes-action-plan.weavemark.md +59 -0
  113. weavemark/promplets/catalog/standalone/mintlite-finance-app.vars.json +4 -0
  114. weavemark/promplets/catalog/standalone/mintlite-finance-app.weavemark.md +93 -0
  115. weavemark/promplets/catalog/standalone/multi-persona-debate.weavemark.md +87 -0
  116. weavemark/promplets/catalog/standalone/passive-income-android-app.weavemark.md +39 -0
  117. weavemark/promplets/catalog/standalone/program-debugging-assistant.weavemark.md +87 -0
  118. weavemark/promplets/catalog/standalone/program-review-checklist.weavemark.md +79 -0
  119. weavemark/promplets/catalog/standalone/prompt-refactoring-pipeline.weavemark.md +79 -0
  120. weavemark/promplets/catalog/standalone/prompt-refiner.weavemark.md +55 -0
  121. weavemark/promplets/catalog/standalone/research-brief.weavemark.md +66 -0
  122. weavemark/promplets/catalog/standalone/support-ticket-prompt-pack.weavemark.md +39 -0
  123. weavemark/promplets/catalog/standalone/tutorial-generator.weavemark.md +76 -0
  124. weavemark/promplets/catalog/standalone/voidborne-roguelike.vars.json +3 -0
  125. weavemark/promplets/catalog/standalone/voidborne-roguelike.weavemark.md +94 -0
  126. weavemark/promplets/domains/creative/fragments/illustrated-story-core.weavemark.md +248 -0
  127. weavemark/promplets/domains/creative/fragments/picture-book-html.weavemark.md +65 -0
  128. weavemark/promplets/domains/finance/fragments/finance-context-sufficiency.weavemark.md +43 -0
  129. weavemark/promplets/domains/finance/fragments/finance-safety.weavemark.md +56 -0
  130. weavemark/promplets/domains/finance/fragments/investment-decision.weavemark.md +61 -0
  131. weavemark/promplets/domains/finance/fragments/passive-income-capital-growth.weavemark.md +61 -0
  132. weavemark/promplets/domains/finance/fragments/passive-income-forecasting.weavemark.md +52 -0
  133. weavemark/promplets/domains/game-design/fragments/mechanics/deckbuilder.weavemark.md +45 -0
  134. weavemark/promplets/domains/game-design/fragments/mechanics/ecosystem-simulation.weavemark.md +45 -0
  135. weavemark/promplets/domains/game-design/fragments/mechanics/tower-defense.weavemark.md +47 -0
  136. weavemark/promplets/domains/game-design/fragments/production/playability-readability.weavemark.md +42 -0
  137. weavemark/promplets/domains/game-design/fragments/production/progression-balance-model.weavemark.md +40 -0
  138. weavemark/promplets/domains/product/fragments/metaphor-to-product.weavemark.md +36 -0
  139. weavemark/promplets/domains/product/fragments/product-validation-surface.weavemark.md +32 -0
  140. weavemark/promplets/domains/product/fragments/release-artifact-readiness.weavemark.md +43 -0
  141. weavemark/promplets/domains/product/fragments/release-readiness-gate.weavemark.md +42 -0
  142. weavemark/promplets/domains/programming/fragments/assets/generative-2d-sprites.weavemark.md +237 -0
  143. weavemark/promplets/domains/programming/fragments/debugging/root-cause-debugging.weavemark.md +41 -0
  144. weavemark/promplets/domains/programming/fragments/foundations/base-spec-author.weavemark.md +23 -0
  145. weavemark/promplets/domains/programming/fragments/foundations/software-spec.weavemark.md +54 -0
  146. weavemark/promplets/domains/programming/fragments/models/model-finance.weavemark.md +72 -0
  147. weavemark/promplets/domains/programming/fragments/modules/module-activity-stream.weavemark.md +59 -0
  148. weavemark/promplets/domains/programming/fragments/modules/module-ai-features.weavemark.md +22 -0
  149. weavemark/promplets/domains/programming/fragments/modules/module-auth.weavemark.md +28 -0
  150. weavemark/promplets/domains/programming/fragments/modules/module-card.weavemark.md +85 -0
  151. weavemark/promplets/domains/programming/fragments/modules/module-context-attachments.weavemark.md +60 -0
  152. weavemark/promplets/domains/programming/fragments/modules/module-dashboard.weavemark.md +35 -0
  153. weavemark/promplets/domains/programming/fragments/modules/module-local-sqlite-storage.weavemark.md +72 -0
  154. weavemark/promplets/domains/programming/fragments/modules/module-mobile-financial-dashboard.weavemark.md +36 -0
  155. weavemark/promplets/domains/programming/fragments/modules/module-notifications.weavemark.md +25 -0
  156. weavemark/promplets/domains/programming/fragments/modules/module-output-surfaces.weavemark.md +69 -0
  157. weavemark/promplets/domains/programming/fragments/modules/module-realtime.weavemark.md +27 -0
  158. weavemark/promplets/domains/programming/fragments/modules/module-rest-api.weavemark.md +41 -0
  159. weavemark/promplets/domains/programming/fragments/modules/module-workflow-board.weavemark.md +66 -0
  160. weavemark/promplets/domains/programming/fragments/stacks/stack-android-kotlin-compose.weavemark.md +39 -0
  161. weavemark/promplets/domains/programming/fragments/stacks/stack-python-fastapi-postgres.weavemark.md +32 -0
  162. weavemark/promplets/domains/programming/fragments/stacks/stack-rust-bevy.weavemark.md +36 -0
  163. weavemark/promplets/domains/programming/fragments/stacks/stack-typescript-nextjs-prisma-sqlite.weavemark.md +52 -0
  164. weavemark/promplets/domains/programming/fragments/stacks/stack-typescript-nextjs-prisma.weavemark.md +38 -0
  165. weavemark/promplets/domains/programming/fragments/types/type-2d-game.weavemark.md +38 -0
  166. weavemark/promplets/domains/programming/fragments/types/type-android-app.weavemark.md +38 -0
  167. weavemark/promplets/domains/programming/fragments/types/type-local-first-webapp.weavemark.md +47 -0
  168. weavemark/promplets/domains/programming/fragments/types/type-saas-webapp.weavemark.md +37 -0
  169. weavemark/promplets/domains/programming/fragments/types/web-based-game.weavemark.md +64 -0
  170. weavemark/promplets/domains/programming/fragments/validation/playwright-mcp-browser-validation.weavemark.md +81 -0
  171. weavemark/promplets/domains/programming/fragments/validation/release-validation-matrix.weavemark.md +39 -0
  172. weavemark/promplets/domains/research/fragments/deep-web-source-discovery.weavemark.md +52 -0
  173. weavemark/promplets/domains/research/fragments/news-event-triage.weavemark.md +55 -0
  174. weavemark/promplets/domains/research/fragments/news-quality.weavemark.md +42 -0
  175. weavemark/promplets/domains/research/fragments/recurring-topic-monitor.weavemark.md +41 -0
  176. weavemark/promplets/domains/work-intelligence/fragments/idea-execution-workspace.weavemark.md +56 -0
  177. weavemark/promplets/domains/work-intelligence/fragments/signal-to-action-workflow.weavemark.md +56 -0
  178. weavemark/promplets/domains/work-intelligence/fragments/topic-intelligence-monitor.weavemark.md +62 -0
  179. weavemark/promplets/experimental/fslm/fslm-support-triage-sugared.weavemark.json +23 -0
  180. weavemark/promplets/experimental/fslm/fslm-support-triage-sugared.weavemark.md +114 -0
  181. weavemark/promplets/experimental/fslm/fslm-support-triage.weavemark.json +21 -0
  182. weavemark/promplets/experimental/fslm/fslm-support-triage.weavemark.md +37 -0
  183. weavemark/promplets/experimental/fslm/fslm.weavemark.md +81 -0
  184. weavemark/promplets/experimental/fslm/support-triage.fslm.yaml +32 -0
  185. weavemark/promplets/experimental/studies/auto-research-ablation.weavemark.md +163 -0
  186. weavemark/promplets/experimental/weave/companions/market_data.py +263 -0
  187. weavemark/promplets/experimental/weave/weave-market-snapshot.weavemark.md +83 -0
  188. weavemark/promplets/stdlib/definitions/planning/goals.weavemark.md +103 -0
  189. weavemark/promplets/stdlib/fragments/analysis/ach-core.weavemark.md +60 -0
  190. weavemark/promplets/stdlib/fragments/analysis/financial-resilience-lens.weavemark.md +43 -0
  191. weavemark/promplets/stdlib/fragments/analysis/issue-tree-core.weavemark.md +63 -0
  192. weavemark/promplets/stdlib/fragments/analysis/mece-core.weavemark.md +79 -0
  193. weavemark/promplets/stdlib/fragments/analysis/optionality-decision.weavemark.md +32 -0
  194. weavemark/promplets/stdlib/fragments/analysis/strategic-problem-analysis.weavemark.md +34 -0
  195. weavemark/promplets/stdlib/fragments/decision/forecast-uncertainty.weavemark.md +32 -0
  196. weavemark/promplets/stdlib/fragments/decision/strategy-selection.weavemark.md +35 -0
  197. weavemark/promplets/stdlib/fragments/decision/values-tradeoff.weavemark.md +33 -0
  198. weavemark/promplets/stdlib/fragments/guidelines/context-sufficiency.weavemark.md +56 -0
  199. weavemark/promplets/stdlib/fragments/guidelines/evidence-quality.weavemark.md +30 -0
  200. weavemark/promplets/stdlib/fragments/guidelines/prompt-quality.weavemark.md +46 -0
  201. weavemark/promplets/stdlib/fragments/guidelines/release-evidence-quality.weavemark.md +36 -0
  202. weavemark/promplets/stdlib/fragments/guidelines/research-rigor.weavemark.md +48 -0
  203. weavemark/promplets/stdlib/fragments/ideation/contrastive-mining-core.weavemark.md +42 -0
  204. weavemark/promplets/stdlib/fragments/ideation/multi-persona-debate-core.weavemark.md +35 -0
  205. weavemark/promplets/stdlib/fragments/ideation/reverse-brainstorming.weavemark.md +243 -0
  206. weavemark/promplets/stdlib/fragments/ideation/scamper.weavemark.md +220 -0
  207. weavemark/promplets/stdlib/fragments/ideation/six-thinking-hats.weavemark.md +221 -0
  208. weavemark/promplets/stdlib/fragments/lenses/comparative-alternatives.weavemark.md +33 -0
  209. weavemark/promplets/stdlib/fragments/lenses/decision-gate.weavemark.md +34 -0
  210. weavemark/promplets/stdlib/fragments/lenses/explainability.weavemark.md +28 -0
  211. weavemark/promplets/stdlib/fragments/reasoning/action-planning.weavemark.md +37 -0
  212. weavemark/promplets/stdlib/fragments/reasoning/base-analyst.weavemark.md +24 -0
  213. weavemark/promplets/stdlib/fragments/reasoning/chain-of-thought.weavemark.md +37 -0
  214. weavemark/promplets/stdlib/fragments/reasoning/deep-summary.weavemark.md +37 -0
  215. weavemark/promplets/stdlib/fragments/reasoning/learner-model.weavemark.md +37 -0
  216. weavemark/promplets/stdlib/fragments/reasoning/prompt-refinement-core.weavemark.md +37 -0
  217. weavemark/promplets/stdlib/fragments/reasoning/unstructured-input-normalization.weavemark.md +44 -0
  218. weavemark/promplets/stdlib/fragments/strategy/indirect-strategy-principles.weavemark.md +90 -0
  219. weavemark/promplets/stdlib/fragments/teaching/mastery-practice-loop.weavemark.md +34 -0
  220. weavemark/promplets/stdlib/fragments/teaching/misconception-diagnosis.weavemark.md +34 -0
  221. weavemark/promplets/stdlib/fragments/teaching/socratic-tutoring.weavemark.md +36 -0
  222. weavemark/promplets/stdlib/fragments/writing/collaborative-writing-protocol.weavemark.md +35 -0
  223. weavemark/promplets/stdlib/fragments/writing/revision-critique-loop.weavemark.md +35 -0
  224. weavemark/promplets/stdlib/prelude/presentation.weavemark.md +33 -0
  225. weavemark/promplets/stdlib/prelude/semantics.weavemark.md +491 -0
  226. weavemark/promplets/tutorials/README.md +24 -0
  227. weavemark/promplets/tutorials/adaptive-tutor-guided.weavemark.md +40 -0
  228. weavemark/promplets/tutorials/adaptive-tutor.weavemark.md +36 -0
  229. weavemark/promplets/tutorials/metro-lines-pack.weavemark.md +53 -0
  230. weavemark/promplets/tutorials/metro-lines.weavemark.md +35 -0
  231. weavemark/promplets/tutorials/release-workbench-pack.weavemark.md +53 -0
  232. weavemark/promplets/tutorials/release-workbench.weavemark.md +42 -0
  233. weavemark/prompts/weavemark.system.md +2117 -0
  234. weavemark/protection.py +1044 -0
  235. weavemark/settings.py +623 -0
  236. weavemark/surfaces/__init__.py +39 -0
  237. weavemark/surfaces/base.py +185 -0
  238. weavemark/surfaces/markdown_adapter.py +350 -0
  239. weavemark/traces.py +151 -0
  240. weavemark/tui/__init__.py +1 -0
  241. weavemark/tui/app.py +421 -0
  242. weavemark/tui/callbacks.py +100 -0
  243. weavemark/tui/scanner.py +590 -0
  244. weavemark/tui/screens/__init__.py +1 -0
  245. weavemark/tui/screens/ask.py +119 -0
  246. weavemark/tui/screens/edit.py +254 -0
  247. weavemark/tui/screens/input.py +130 -0
  248. weavemark/tui/theme.tcss +232 -0
  249. weavemark/tui/widgets/__init__.py +1 -0
  250. weavemark/tui/widgets/preview.py +53 -0
  251. weavemark/tui/widgets/spec_info.py +73 -0
  252. weavemark/tui/widgets/step_log.py +46 -0
  253. weavemark/variable_paths.py +55 -0
  254. weavemark/version.py +16 -0
  255. weavemark-0.8.0.dist-info/METADATA +511 -0
  256. weavemark-0.8.0.dist-info/RECORD +259 -0
  257. weavemark-0.8.0.dist-info/WHEEL +4 -0
  258. weavemark-0.8.0.dist-info/entry_points.txt +2 -0
  259. weavemark-0.8.0.dist-info/licenses/LICENSE +21 -0
weavemark/__init__.py ADDED
@@ -0,0 +1,85 @@
1
+ """WeaveMark public Python library API."""
2
+
3
+ from weavemark.api import (
4
+ AskCallback,
5
+ CompileOptions,
6
+ EngineInput,
7
+ EventCallback,
8
+ PathLike,
9
+ RuntimeConfigInput,
10
+ WeaveMarkCompilationError,
11
+ WeaveMarkError,
12
+ WeaveMarkRunResult,
13
+ compile_file,
14
+ compile_text,
15
+ execute_file,
16
+ execute_text,
17
+ format_compiled_output,
18
+ load_runtime_config,
19
+ )
20
+ from weavemark.compilation.ask import AskPrompt
21
+ from weavemark.compilation.diagnostics import Diagnostic
22
+ from weavemark.compilation.provenance import (
23
+ ProvenanceManifest,
24
+ ProvenanceOptions,
25
+ ReplayMismatchError,
26
+ )
27
+ from weavemark.compilation.result import CompositionResult
28
+ from weavemark.compilation.trace import (
29
+ CompilationStep,
30
+ CompilationTrace,
31
+ DirectiveApplication,
32
+ SourceSpan,
33
+ StepJudgment,
34
+ )
35
+ from weavemark.engines import Engine, ExecutionResult, PromptConfig, RuntimeConfig
36
+ from weavemark.promplet_library import (
37
+ bundled_promplet,
38
+ bundled_promplet_path,
39
+ bundled_promplets,
40
+ bundled_promplets_path,
41
+ iter_bundled_promplets,
42
+ read_bundled_promplet,
43
+ )
44
+ from weavemark.version import LANGUAGE_VERSION, __version__
45
+
46
+ __all__ = [
47
+ "CompileOptions",
48
+ "AskCallback",
49
+ "AskPrompt",
50
+ "CompilationStep",
51
+ "CompilationTrace",
52
+ "CompositionResult",
53
+ "Diagnostic",
54
+ "DirectiveApplication",
55
+ "Engine",
56
+ "EngineInput",
57
+ "EventCallback",
58
+ "ExecutionResult",
59
+ "PathLike",
60
+ "PromptConfig",
61
+ "ProvenanceManifest",
62
+ "ProvenanceOptions",
63
+ "ReplayMismatchError",
64
+ "WeaveMarkCompilationError",
65
+ "WeaveMarkError",
66
+ "WeaveMarkRunResult",
67
+ "RuntimeConfig",
68
+ "RuntimeConfigInput",
69
+ "LANGUAGE_VERSION",
70
+ "SourceSpan",
71
+ "StepJudgment",
72
+ "compile_file",
73
+ "compile_text",
74
+ "bundled_promplet",
75
+ "bundled_promplet_path",
76
+ "bundled_promplets",
77
+ "bundled_promplets_path",
78
+ "execute_file",
79
+ "execute_text",
80
+ "format_compiled_output",
81
+ "iter_bundled_promplets",
82
+ "load_runtime_config",
83
+ "read_bundled_promplet",
84
+ "__version__",
85
+ ]
weavemark/api.py ADDED
@@ -0,0 +1,459 @@
1
+ """Public Python API for compiling and executing WeaveMark programs."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from collections.abc import Awaitable, Callable, Mapping
7
+ from dataclasses import dataclass
8
+ from pathlib import Path
9
+ from typing import Any, TypeAlias
10
+
11
+ from ellements.core import LLMClientProtocol
12
+ from ellements.execution import OnStepCallback
13
+
14
+ from weavemark.compilation.ask import AskPrompt
15
+ from weavemark.compilation.provenance import ProvenanceOptions
16
+ from weavemark.compilation.result import CompositionResult
17
+ from weavemark.compile_options import (
18
+ DEFAULT_COMPILE_FORMAT,
19
+ normalize_compile_format,
20
+ supported_compile_formats_text,
21
+ )
22
+ from weavemark.controller import (
23
+ WeaveMarkConfig,
24
+ WeaveMarkController,
25
+ )
26
+ from weavemark.defaults import DEFAULT_MODEL
27
+ from weavemark.engines import (
28
+ ArtifactCallback,
29
+ Engine,
30
+ ExecutionResult,
31
+ RuntimeConfig,
32
+ call_engine_execute,
33
+ resolve_engine,
34
+ )
35
+ from weavemark.logging_setup import new_client
36
+ from weavemark.protection import ProtectionContext
37
+ from weavemark.settings import (
38
+ WeaveMarkSettings,
39
+ builtin_weavemark_settings,
40
+ load_weavemark_settings,
41
+ )
42
+
43
+ PathLike: TypeAlias = str | Path
44
+ EventCallback: TypeAlias = Callable[[str, dict[str, Any]], None]
45
+ AskCallback: TypeAlias = Callable[[AskPrompt], str | Awaitable[str]]
46
+ RuntimeConfigInput: TypeAlias = RuntimeConfig | Mapping[str, Any] | PathLike | None
47
+ EngineInput: TypeAlias = str | Engine | None
48
+
49
+
50
+ @dataclass(frozen=True)
51
+ class CompileOptions:
52
+ """Options for WeaveMark compilation.
53
+
54
+ WeaveMark compilation is async because semantic directives may need an LLM
55
+ reference compiler when deterministic structural helpers cannot resolve the
56
+ full program.
57
+ """
58
+
59
+ model: str = DEFAULT_MODEL
60
+ temperature: float = 0.3
61
+ max_iterations: int = 15
62
+ use_structural_helpers: bool = True
63
+ max_effect_rounds: int = 6
64
+ max_effect_questions: int = 20
65
+ max_iterate_turns: int = 6
66
+ max_compilation_steps: int = 64
67
+ max_total_model_calls: int = 100
68
+ max_compile_seconds: float = 300.0
69
+
70
+ def to_controller_config(self) -> WeaveMarkConfig:
71
+ """Convert public compile options to controller configuration."""
72
+
73
+ return WeaveMarkConfig(
74
+ model=self.model,
75
+ temperature=self.temperature,
76
+ max_iterations=self.max_iterations,
77
+ use_structural_helpers=self.use_structural_helpers,
78
+ max_effect_rounds=self.max_effect_rounds,
79
+ max_effect_questions=self.max_effect_questions,
80
+ max_iterate_turns=self.max_iterate_turns,
81
+ max_compilation_steps=self.max_compilation_steps,
82
+ max_total_model_calls=self.max_total_model_calls,
83
+ max_compile_seconds=self.max_compile_seconds,
84
+ )
85
+
86
+
87
+ @dataclass(frozen=True)
88
+ class WeaveMarkRunResult:
89
+ """Result returned by ``execute_text`` and ``execute_file``."""
90
+
91
+ compiled: CompositionResult
92
+ execution: ExecutionResult
93
+ engine: str
94
+ runtime_config: RuntimeConfig | None = None
95
+
96
+ @property
97
+ def output(self) -> str:
98
+ """Primary text output produced by the execution engine."""
99
+
100
+ return str(self.execution.output)
101
+
102
+
103
+ class WeaveMarkError(Exception):
104
+ """Base exception raised by the public WeaveMark library API."""
105
+
106
+
107
+ class WeaveMarkCompilationError(WeaveMarkError):
108
+ """Raised when execution is requested for a spec that did not compile."""
109
+
110
+ def __init__(self, result: CompositionResult) -> None:
111
+ self.result = result
112
+ message = "WeaveMark compilation failed"
113
+ if result.errors:
114
+ message += ": " + "; ".join(result.errors)
115
+ super().__init__(message)
116
+
117
+
118
+ async def compile_text(
119
+ spec_text: str,
120
+ variables: Mapping[str, Any] | None = None,
121
+ *,
122
+ base_dir: PathLike | None = None,
123
+ options: CompileOptions | None = None,
124
+ on_event: EventCallback | None = None,
125
+ ask_handler: AskCallback | None = None,
126
+ client: LLMClientProtocol | None = None,
127
+ protection_context: ProtectionContext | None = None,
128
+ provenance: ProvenanceOptions | None = None,
129
+ source_path: PathLike | None = None,
130
+ ) -> CompositionResult:
131
+ """Compile WeaveMark source text into prompt artifacts.
132
+
133
+ Args:
134
+ spec_text: WeaveMark source text.
135
+ variables: Values used for ``@{variable}`` substitution.
136
+ base_dir: Directory used for relative file references, module lookup,
137
+ and project-level ``weavemark.json`` discovery. Defaults to the
138
+ current working directory.
139
+ options: Compiler/model settings. Defaults match the CLI.
140
+ on_event: Optional callback receiving controller events such as
141
+ ``"composing"``, ``"transition"``, ``"issue"``, and ``"done"``.
142
+ ask_handler: Optional callback used by standard-library ``@ask`` to
143
+ collect compile-time answers.
144
+ client: Optional ``ellements`` LLM client for advanced integrations.
145
+ provenance: Optional manifest, run-recording, or strict replay settings.
146
+ source_path: Optional source identity for provenance when compiling text.
147
+
148
+ Returns:
149
+ A ``CompositionResult`` containing the composed prompt, named prompts,
150
+ emitted artifacts, tool schemas, bindings, execution metadata, and
151
+ diagnostics.
152
+ """
153
+
154
+ resolved_options = options or CompileOptions()
155
+ root = _resolve_base_dir(base_dir)
156
+ controller = WeaveMarkController(
157
+ resolved_options.to_controller_config(),
158
+ client=client,
159
+ )
160
+ return await controller.compose(
161
+ spec_text,
162
+ dict(variables or {}),
163
+ root,
164
+ on_event=on_event,
165
+ ask_handler=ask_handler,
166
+ protection=protection_context,
167
+ provenance=provenance,
168
+ source_path=Path(source_path).expanduser().resolve() if source_path else None,
169
+ )
170
+
171
+
172
+ async def compile_file(
173
+ promplet_file: PathLike,
174
+ variables: Mapping[str, Any] | None = None,
175
+ *,
176
+ options: CompileOptions | None = None,
177
+ on_event: EventCallback | None = None,
178
+ ask_handler: AskCallback | None = None,
179
+ client: LLMClientProtocol | None = None,
180
+ protection_context: ProtectionContext | None = None,
181
+ provenance: ProvenanceOptions | None = None,
182
+ ) -> CompositionResult:
183
+ """Compile a WeaveMark file from disk.
184
+
185
+ The promplet's parent directory becomes the base directory for relative
186
+ ``@refine`` / ``@embed`` paths, effective-library module resolution, and
187
+ project ``weavemark.json`` settings.
188
+ """
189
+
190
+ promplet_path = _resolve_file(promplet_file)
191
+ return await compile_text(
192
+ promplet_path.read_text(encoding="utf-8"),
193
+ variables,
194
+ base_dir=promplet_path.parent,
195
+ options=options,
196
+ on_event=on_event,
197
+ ask_handler=ask_handler,
198
+ client=client,
199
+ protection_context=protection_context,
200
+ provenance=provenance,
201
+ source_path=promplet_path,
202
+ )
203
+
204
+
205
+ async def execute_text(
206
+ spec_text: str,
207
+ variables: Mapping[str, Any] | None = None,
208
+ *,
209
+ base_dir: PathLike | None = None,
210
+ options: CompileOptions | None = None,
211
+ runtime_config: RuntimeConfigInput = None,
212
+ engine: EngineInput = None,
213
+ on_event: EventCallback | None = None,
214
+ ask_handler: AskCallback | None = None,
215
+ on_step: OnStepCallback | None = None,
216
+ on_artifact: ArtifactCallback | None = None,
217
+ client: LLMClientProtocol | None = None,
218
+ protection_context: ProtectionContext | None = None,
219
+ provenance: ProvenanceOptions | None = None,
220
+ source_path: PathLike | None = None,
221
+ ) -> WeaveMarkRunResult:
222
+ """Compile WeaveMark source text, then execute it with an engine.
223
+
224
+ Runtime config variables are applied before compilation; explicit
225
+ ``variables`` override runtime config variables, matching the CLI.
226
+
227
+ ``on_artifact`` receives each ``@output file:`` artifact record the moment an
228
+ engine produces it (e.g. one per rendered page), enabling streaming
229
+ persistence rather than only writing everything after the whole run finishes.
230
+ """
231
+
232
+ resolved_runtime_config = load_runtime_config(runtime_config)
233
+ effective_options = options or CompileOptions()
234
+ if resolved_runtime_config is None:
235
+ resolved_runtime_config = RuntimeConfig(model=effective_options.model)
236
+ elif resolved_runtime_config.model is None:
237
+ resolved_runtime_config.model = effective_options.model
238
+ merged_variables = _merge_runtime_variables(resolved_runtime_config, variables)
239
+ compiled = await compile_text(
240
+ spec_text,
241
+ merged_variables,
242
+ base_dir=base_dir,
243
+ options=effective_options,
244
+ on_event=on_event,
245
+ ask_handler=ask_handler,
246
+ client=client,
247
+ protection_context=protection_context,
248
+ provenance=provenance,
249
+ source_path=source_path,
250
+ )
251
+ if compiled.errors:
252
+ raise WeaveMarkCompilationError(compiled)
253
+ resolved_runtime_config.protection = compiled.protection
254
+
255
+ resolved_engine, engine_name = _resolve_execution_engine(
256
+ engine,
257
+ resolved_runtime_config,
258
+ compiled,
259
+ client
260
+ or new_client(
261
+ model=resolved_runtime_config.model or effective_options.model,
262
+ protection=compiled.protection,
263
+ logging_settings=load_weavemark_settings(
264
+ _resolve_base_dir(base_dir)
265
+ ).settings.logging,
266
+ ),
267
+ )
268
+ execution = await call_engine_execute(
269
+ resolved_engine,
270
+ compiled,
271
+ resolved_runtime_config,
272
+ on_step=on_step,
273
+ on_artifact=on_artifact,
274
+ )
275
+ return WeaveMarkRunResult(
276
+ compiled=compiled,
277
+ execution=execution,
278
+ engine=engine_name,
279
+ runtime_config=resolved_runtime_config,
280
+ )
281
+
282
+
283
+ async def execute_file(
284
+ promplet_file: PathLike,
285
+ variables: Mapping[str, Any] | None = None,
286
+ *,
287
+ options: CompileOptions | None = None,
288
+ runtime_config: RuntimeConfigInput = None,
289
+ engine: EngineInput = None,
290
+ on_event: EventCallback | None = None,
291
+ ask_handler: AskCallback | None = None,
292
+ on_step: OnStepCallback | None = None,
293
+ on_artifact: ArtifactCallback | None = None,
294
+ client: LLMClientProtocol | None = None,
295
+ protection_context: ProtectionContext | None = None,
296
+ provenance: ProvenanceOptions | None = None,
297
+ ) -> WeaveMarkRunResult:
298
+ """Compile a WeaveMark file, then execute it with an engine."""
299
+
300
+ promplet_path = _resolve_file(promplet_file)
301
+ return await execute_text(
302
+ promplet_path.read_text(encoding="utf-8"),
303
+ variables,
304
+ base_dir=promplet_path.parent,
305
+ options=options,
306
+ runtime_config=runtime_config,
307
+ engine=engine,
308
+ on_event=on_event,
309
+ ask_handler=ask_handler,
310
+ on_step=on_step,
311
+ on_artifact=on_artifact,
312
+ client=client,
313
+ protection_context=protection_context,
314
+ provenance=provenance,
315
+ source_path=promplet_path,
316
+ )
317
+
318
+
319
+ def load_runtime_config(config: RuntimeConfigInput) -> RuntimeConfig | None:
320
+ """Load runtime engine config from an object, mapping, JSON file, or YAML file."""
321
+
322
+ if config is None:
323
+ return None
324
+ if isinstance(config, RuntimeConfig):
325
+ return config
326
+ if isinstance(config, str | Path):
327
+ path = _resolve_file(config)
328
+ if path.suffix in (".yaml", ".yml"):
329
+ return RuntimeConfig.from_yaml(path)
330
+ return RuntimeConfig.from_json(path)
331
+ return _runtime_config_from_mapping(config)
332
+
333
+
334
+ def format_compiled_output(
335
+ result: CompositionResult,
336
+ output_format: str | None = None,
337
+ *,
338
+ base_dir: PathLike | None = None,
339
+ settings: WeaveMarkSettings | None = None,
340
+ ) -> str:
341
+ """Render a compiled result the same way the CLI renders primary output.
342
+
343
+ ``markdown`` returns ``result.composed_prompt`` and ``json`` returns structured
344
+ result JSON. Custom format identifiers and aliases are resolved through
345
+ ``weavemark.json`` settings when ``base_dir`` or ``settings`` is supplied.
346
+ """
347
+
348
+ resolved_settings = _resolve_settings(base_dir, settings)
349
+ raw_format = output_format
350
+ if raw_format is None and result.compile:
351
+ compile_format = result.compile.get("format")
352
+ raw_format = str(compile_format) if compile_format is not None else None
353
+ raw_format = raw_format or DEFAULT_COMPILE_FORMAT
354
+
355
+ normalized = normalize_compile_format(raw_format, resolved_settings)
356
+ if normalized is None:
357
+ raise ValueError(
358
+ f"Unsupported output format: {raw_format}. "
359
+ f"Supported formats: {supported_compile_formats_text(resolved_settings)}."
360
+ )
361
+
362
+ if normalized == "json":
363
+ return json.dumps(result.to_dict(), indent=2, ensure_ascii=False)
364
+ return str(result.composed_prompt)
365
+
366
+
367
+ def _resolve_base_dir(base_dir: PathLike | None) -> Path:
368
+ if base_dir is None:
369
+ return Path.cwd()
370
+ return Path(base_dir).expanduser().resolve()
371
+
372
+
373
+ def _resolve_file(path: PathLike) -> Path:
374
+ resolved = Path(path).expanduser().resolve()
375
+ if not resolved.is_file():
376
+ raise FileNotFoundError(resolved)
377
+ return resolved
378
+
379
+
380
+ def _resolve_settings(
381
+ base_dir: PathLike | None,
382
+ settings: WeaveMarkSettings | None,
383
+ ) -> WeaveMarkSettings:
384
+ if settings is not None:
385
+ return settings
386
+ if base_dir is None:
387
+ return builtin_weavemark_settings()
388
+ return load_weavemark_settings(Path(base_dir).expanduser().resolve()).settings
389
+
390
+
391
+ def _merge_runtime_variables(
392
+ runtime_config: RuntimeConfig | None,
393
+ variables: Mapping[str, Any] | None,
394
+ ) -> dict[str, Any]:
395
+ merged = dict(runtime_config.variables) if runtime_config else {}
396
+ merged.update(dict(variables or {}))
397
+ return merged
398
+
399
+
400
+ def _resolve_execution_engine(
401
+ engine: EngineInput,
402
+ runtime_config: RuntimeConfig | None,
403
+ compiled: CompositionResult,
404
+ client: LLMClientProtocol | None,
405
+ ) -> tuple[Engine, str]:
406
+ if engine is None:
407
+ engine_name = _engine_name_from_result(runtime_config, compiled)
408
+ return (
409
+ resolve_engine(
410
+ engine_name,
411
+ client=client,
412
+ protection=runtime_config.protection if runtime_config else None,
413
+ ),
414
+ engine_name,
415
+ )
416
+ if isinstance(engine, str):
417
+ return (
418
+ resolve_engine(
419
+ engine,
420
+ client=client,
421
+ protection=runtime_config.protection if runtime_config else None,
422
+ ),
423
+ engine,
424
+ )
425
+ return engine, engine.__class__.__name__
426
+
427
+
428
+ def _engine_name_from_result(
429
+ runtime_config: RuntimeConfig | None,
430
+ compiled: CompositionResult,
431
+ ) -> str:
432
+ if runtime_config is not None and runtime_config.engine:
433
+ return str(runtime_config.engine)
434
+ declared = compiled.execution.get("type") if compiled.execution else None
435
+ if isinstance(declared, str) and declared:
436
+ return declared
437
+ return "single-call"
438
+
439
+
440
+ def _runtime_config_from_mapping(data: Mapping[str, Any]) -> RuntimeConfig:
441
+ return RuntimeConfig.from_mapping(data)
442
+
443
+
444
+ __all__ = [
445
+ "CompileOptions",
446
+ "EngineInput",
447
+ "EventCallback",
448
+ "PathLike",
449
+ "WeaveMarkCompilationError",
450
+ "WeaveMarkError",
451
+ "WeaveMarkRunResult",
452
+ "RuntimeConfigInput",
453
+ "compile_file",
454
+ "compile_text",
455
+ "execute_file",
456
+ "execute_text",
457
+ "format_compiled_output",
458
+ "load_runtime_config",
459
+ ]