ontogen 1.2.0__tar.gz

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 (246) hide show
  1. ontogen-1.2.0/.gitignore +16 -0
  2. ontogen-1.2.0/.python-version +1 -0
  3. ontogen-1.2.0/CLAUDE.md +46 -0
  4. ontogen-1.2.0/LICENSE +190 -0
  5. ontogen-1.2.0/PKG-INFO +100 -0
  6. ontogen-1.2.0/README.md +86 -0
  7. ontogen-1.2.0/cache_skills/0c200ceb12f4186b.py +45 -0
  8. ontogen-1.2.0/cache_skills/664dcf149808d805.py +34 -0
  9. ontogen-1.2.0/cache_skills/allocate.fast.py +34 -0
  10. ontogen-1.2.0/cache_skills/allocate.naive.py +34 -0
  11. ontogen-1.2.0/cache_skills/c5f84ddd6a2c7547.py +28 -0
  12. ontogen-1.2.0/cache_skills/e254e5f29b990b38.py +34 -0
  13. ontogen-1.2.0/cache_skills/f6c454bade25773f.py +45 -0
  14. ontogen-1.2.0/cache_skills/fb21437ad1abd5bd.py +28 -0
  15. ontogen-1.2.0/cache_skills/match_orders.fast.py +45 -0
  16. ontogen-1.2.0/cache_skills/match_orders.naive.py +45 -0
  17. ontogen-1.2.0/config.toml.example +35 -0
  18. ontogen-1.2.0/docs/OPERATOR.md +88 -0
  19. ontogen-1.2.0/docs/README.md +26 -0
  20. ontogen-1.2.0/docs/anatomy.html +788 -0
  21. ontogen-1.2.0/docs/design/DATAPLANE.md +37 -0
  22. ontogen-1.2.0/docs/design/FREEZE_v1.md +44 -0
  23. ontogen-1.2.0/docs/design/IDEAL.md +34 -0
  24. ontogen-1.2.0/docs/design/MODEL.md +124 -0
  25. ontogen-1.2.0/docs/design/NOT.md +104 -0
  26. ontogen-1.2.0/docs/design/PARADIGM_LIMITS.md +80 -0
  27. ontogen-1.2.0/docs/design/SCARS.md +146 -0
  28. ontogen-1.2.0/docs/design/SHIP.md +70 -0
  29. ontogen-1.2.0/docs/design/SPEC.md +280 -0
  30. ontogen-1.2.0/docs/design/STACK.md +72 -0
  31. ontogen-1.2.0/docs/design/THEORY_BRIDGE.md +42 -0
  32. ontogen-1.2.0/docs/design/TRUST.md +69 -0
  33. ontogen-1.2.0/docs/design/UNEXPRESSIBLE.md +44 -0
  34. ontogen-1.2.0/docs/log/DECISIONS.md +615 -0
  35. ontogen-1.2.0/docs/log/JOURNAL.md +587 -0
  36. ontogen-1.2.0/docs/log/PLAN.md +367 -0
  37. ontogen-1.2.0/docs/log/PREDICTIONS.md +38 -0
  38. ontogen-1.2.0/docs/references/lago-spec.md +48 -0
  39. ontogen-1.2.0/docs/spikes/expr/RESULTS.md +32 -0
  40. ontogen-1.2.0/docs/spikes/expr/a_pyast.py +232 -0
  41. ontogen-1.2.0/docs/spikes/expr/run_spike.py +115 -0
  42. ontogen-1.2.0/exams/billing2_flows.yaml +13 -0
  43. ontogen-1.2.0/exams/booking_flows.yaml +28 -0
  44. ontogen-1.2.0/exams/conformance_expr.jsonl +240 -0
  45. ontogen-1.2.0/exams/f1.py +94 -0
  46. ontogen-1.2.0/exams/f2.py +136 -0
  47. ontogen-1.2.0/exams/f3.py +119 -0
  48. ontogen-1.2.0/exams/f4.py +124 -0
  49. ontogen-1.2.0/exams/f5.py +181 -0
  50. ontogen-1.2.0/exams/f6.py +174 -0
  51. ontogen-1.2.0/exams/f8.py +178 -0
  52. ontogen-1.2.0/exams/faudit.py +106 -0
  53. ontogen-1.2.0/exams/fauth.py +142 -0
  54. ontogen-1.2.0/exams/fcold.py +98 -0
  55. ontogen-1.2.0/exams/fcompose.py +110 -0
  56. ontogen-1.2.0/exams/fgauntlet.py +145 -0
  57. ontogen-1.2.0/exams/fgene.py +92 -0
  58. ontogen-1.2.0/exams/fgengrow.py +78 -0
  59. ontogen-1.2.0/exams/fgrow.py +127 -0
  60. ontogen-1.2.0/exams/fheldout.py +61 -0
  61. ontogen-1.2.0/exams/fideal.py +204 -0
  62. ontogen-1.2.0/exams/finit.py +105 -0
  63. ontogen-1.2.0/exams/fisland.py +164 -0
  64. ontogen-1.2.0/exams/flago.py +181 -0
  65. ontogen-1.2.0/exams/fmath.py +254 -0
  66. ontogen-1.2.0/exams/fmega.py +301 -0
  67. ontogen-1.2.0/exams/fmodels.py +110 -0
  68. ontogen-1.2.0/exams/fnl.py +108 -0
  69. ontogen-1.2.0/exams/fnu.py +186 -0
  70. ontogen-1.2.0/exams/fops.py +102 -0
  71. ontogen-1.2.0/exams/fp15.py +64 -0
  72. ontogen-1.2.0/exams/fparadigm.py +186 -0
  73. ontogen-1.2.0/exams/frelease.py +148 -0
  74. ontogen-1.2.0/exams/fship.py +126 -0
  75. ontogen-1.2.0/exams/fslm.py +66 -0
  76. ontogen-1.2.0/exams/fspectral.py +170 -0
  77. ontogen-1.2.0/exams/fstress.py +332 -0
  78. ontogen-1.2.0/exams/ftier_a.py +185 -0
  79. ontogen-1.2.0/exams/ftypes2.py +141 -0
  80. ontogen-1.2.0/exams/fvariants.py +78 -0
  81. ontogen-1.2.0/exams/fy7.py +144 -0
  82. ontogen-1.2.0/exams/hotel_flows.yaml +23 -0
  83. ontogen-1.2.0/exams/lago_flows.yaml +59 -0
  84. ontogen-1.2.0/exams/market_flows.yaml +36 -0
  85. ontogen-1.2.0/exams/shop_flows.yaml +17 -0
  86. ontogen-1.2.0/exams/wallet_flows.yaml +11 -0
  87. ontogen-1.2.0/genomes/.grown/fx.54ca22ae086de42c.qwen_qwen3-coder.py +34 -0
  88. ontogen-1.2.0/genomes/authwallet.yaml +44 -0
  89. ontogen-1.2.0/genomes/billing2.yaml +34 -0
  90. ontogen-1.2.0/genomes/booking.yaml +85 -0
  91. ontogen-1.2.0/genomes/exchange.yaml +35 -0
  92. ontogen-1.2.0/genomes/fxlive.yaml +47 -0
  93. ontogen-1.2.0/genomes/hotel.yaml +16 -0
  94. ontogen-1.2.0/genomes/islands/fraudscore.py +13 -0
  95. ontogen-1.2.0/genomes/islands/fx_adapter.py +34 -0
  96. ontogen-1.2.0/genomes/islands/gateway.py +18 -0
  97. ontogen-1.2.0/genomes/islands/idp.py +15 -0
  98. ontogen-1.2.0/genomes/islands/tracker.py +14 -0
  99. ontogen-1.2.0/genomes/lago.yaml +8 -0
  100. ontogen-1.2.0/genomes/market.yaml +69 -0
  101. ontogen-1.2.0/genomes/shop.yaml +11 -0
  102. ontogen-1.2.0/genomes/skill_smuggler.yaml +47 -0
  103. ontogen-1.2.0/life/.gitignore +2 -0
  104. ontogen-1.2.0/life/README.md +18 -0
  105. ontogen-1.2.0/life/data/events.jsonl +12 -0
  106. ontogen-1.2.0/life/data/warden.jsonl +1 -0
  107. ontogen-1.2.0/life/flows.yaml +47 -0
  108. ontogen-1.2.0/life/genome.yaml +127 -0
  109. ontogen-1.2.0/life/pulse.log +1179 -0
  110. ontogen-1.2.0/life/pulse.py +62 -0
  111. ontogen-1.2.0/life/run.sh +15 -0
  112. ontogen-1.2.0/life/warden.log +68 -0
  113. ontogen-1.2.0/math/FREEZE_v0.1.md +63 -0
  114. ontogen-1.2.0/math/MANIFESTO.md +146 -0
  115. ontogen-1.2.0/math/PART_VII.md +345 -0
  116. ontogen-1.2.0/math/README.md +407 -0
  117. ontogen-1.2.0/math/REVIEW_1.md +12 -0
  118. ontogen-1.2.0/math/ontogenic_system_math_core.md +639 -0
  119. ontogen-1.2.0/math/ontogenic_system_math_htn.md +118 -0
  120. ontogen-1.2.0/math/ontogenic_system_math_hypotheses.md +264 -0
  121. ontogen-1.2.0/math/ontogenic_system_math_layers.md +168 -0
  122. ontogen-1.2.0/math/ontogenic_system_math_pillars.md +642 -0
  123. ontogen-1.2.0/math/ontogenic_system_math_polish.md +223 -0
  124. ontogen-1.2.0/math/ontogenic_system_math_proofs.md +449 -0
  125. ontogen-1.2.0/math/ontogenic_system_math_survival.md +239 -0
  126. ontogen-1.2.0/math/ontogenic_system_math_tradeoff.md +175 -0
  127. ontogen-1.2.0/math/ontogenic_system_math_wire.md +175 -0
  128. ontogen-1.2.0/modules/commerce_events.yaml +8 -0
  129. ontogen-1.2.0/modules/lago_metering.yaml +175 -0
  130. ontogen-1.2.0/modules/loyalty.yaml +27 -0
  131. ontogen-1.2.0/modules/orders.yaml +55 -0
  132. ontogen-1.2.0/modules/payments.yaml +39 -0
  133. ontogen-1.2.0/modules/reservations.yaml +25 -0
  134. ontogen-1.2.0/modules/rooms.yaml +26 -0
  135. ontogen-1.2.0/modules/shipping.yaml +25 -0
  136. ontogen-1.2.0/modules/stock.yaml +33 -0
  137. ontogen-1.2.0/modules/support.yaml +33 -0
  138. ontogen-1.2.0/pyproject.toml +33 -0
  139. ontogen-1.2.0/src/onto/__init__.py +2 -0
  140. ontogen-1.2.0/src/onto/attest.py +224 -0
  141. ontogen-1.2.0/src/onto/cli.py +530 -0
  142. ontogen-1.2.0/src/onto/core/__init__.py +0 -0
  143. ontogen-1.2.0/src/onto/core/conformance.py +72 -0
  144. ontogen-1.2.0/src/onto/core/court.py +407 -0
  145. ontogen-1.2.0/src/onto/core/expr.py +303 -0
  146. ontogen-1.2.0/src/onto/core/genome.py +399 -0
  147. ontogen-1.2.0/src/onto/core/interview.py +246 -0
  148. ontogen-1.2.0/src/onto/core/ir.py +95 -0
  149. ontogen-1.2.0/src/onto/core/membrane.py +130 -0
  150. ontogen-1.2.0/src/onto/core/migrate.py +113 -0
  151. ontogen-1.2.0/src/onto/core/modules.py +231 -0
  152. ontogen-1.2.0/src/onto/core/mutants.py +97 -0
  153. ontogen-1.2.0/src/onto/core/mutgate.py +92 -0
  154. ontogen-1.2.0/src/onto/core/organism.py +378 -0
  155. ontogen-1.2.0/src/onto/core/placer.py +139 -0
  156. ontogen-1.2.0/src/onto/core/propose.py +61 -0
  157. ontogen-1.2.0/src/onto/core/serve.py +408 -0
  158. ontogen-1.2.0/src/onto/core/skills.py +265 -0
  159. ontogen-1.2.0/src/onto/core/spectral.py +179 -0
  160. ontogen-1.2.0/src/onto/core/store.py +124 -0
  161. ontogen-1.2.0/src/onto/core/warden.py +385 -0
  162. ontogen-1.2.0/src/onto/dialects/__init__.py +0 -0
  163. ontogen-1.2.0/src/onto/dialects/go_stdlib/__init__.py +0 -0
  164. ontogen-1.2.0/src/onto/dialects/go_stdlib/emit.py +129 -0
  165. ontogen-1.2.0/src/onto/dialects/go_stdlib/gates.py +119 -0
  166. ontogen-1.2.0/src/onto/dialects/go_stdlib/rulebench.py +42 -0
  167. ontogen-1.2.0/src/onto/dialects/go_stdlib/skeleton.py +470 -0
  168. ontogen-1.2.0/src/onto/dialects/python_stdlib/__init__.py +0 -0
  169. ontogen-1.2.0/src/onto/dialects/python_stdlib/gates.py +80 -0
  170. ontogen-1.2.0/src/onto/dialects/python_stdlib/skeleton.py +454 -0
  171. ontogen-1.2.0/src/onto/dialects/registry.py +24 -0
  172. ontogen-1.2.0/src/onto/growdialect.py +197 -0
  173. ontogen-1.2.0/src/onto/growgen.py +215 -0
  174. ontogen-1.2.0/src/onto/growisland.py +174 -0
  175. ontogen-1.2.0/src/onto/judge.py +74 -0
  176. ontogen-1.2.0/src/onto/lint.py +82 -0
  177. ontogen-1.2.0/src/onto/mcp_server.py +90 -0
  178. ontogen-1.2.0/src/onto/nlfront.py +391 -0
  179. ontogen-1.2.0/src/onto/ribosome.py +342 -0
  180. ontogen-1.2.0/src/onto/scaffold.py +256 -0
  181. ontogen-1.2.0/src/onto/templates_gallery/hotel/flows.yaml +23 -0
  182. ontogen-1.2.0/src/onto/templates_gallery/hotel/genome.yaml +16 -0
  183. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/commerce_events.yaml +8 -0
  184. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/lago_metering.yaml +175 -0
  185. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/loyalty.yaml +27 -0
  186. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/orders.yaml +55 -0
  187. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/payments.yaml +39 -0
  188. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/reservations.yaml +25 -0
  189. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/rooms.yaml +26 -0
  190. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/shipping.yaml +25 -0
  191. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/stock.yaml +33 -0
  192. ontogen-1.2.0/src/onto/templates_gallery/hotel/modules/support.yaml +33 -0
  193. ontogen-1.2.0/src/onto/templates_gallery/lago/flows.yaml +59 -0
  194. ontogen-1.2.0/src/onto/templates_gallery/lago/genome.yaml +8 -0
  195. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/commerce_events.yaml +8 -0
  196. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/lago_metering.yaml +175 -0
  197. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/loyalty.yaml +27 -0
  198. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/orders.yaml +55 -0
  199. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/payments.yaml +39 -0
  200. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/reservations.yaml +25 -0
  201. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/rooms.yaml +26 -0
  202. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/shipping.yaml +25 -0
  203. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/stock.yaml +33 -0
  204. ontogen-1.2.0/src/onto/templates_gallery/lago/modules/support.yaml +33 -0
  205. ontogen-1.2.0/src/onto/templates_gallery/market/flows.yaml +36 -0
  206. ontogen-1.2.0/src/onto/templates_gallery/market/genome.yaml +69 -0
  207. ontogen-1.2.0/src/onto/templates_gallery/market/islands/fraudscore.py +13 -0
  208. ontogen-1.2.0/src/onto/templates_gallery/market/islands/fx_adapter.py +34 -0
  209. ontogen-1.2.0/src/onto/templates_gallery/market/islands/gateway.py +18 -0
  210. ontogen-1.2.0/src/onto/templates_gallery/market/islands/idp.py +15 -0
  211. ontogen-1.2.0/src/onto/templates_gallery/market/islands/tracker.py +14 -0
  212. ontogen-1.2.0/src/onto/templates_gallery/market/modules/commerce_events.yaml +8 -0
  213. ontogen-1.2.0/src/onto/templates_gallery/market/modules/lago_metering.yaml +175 -0
  214. ontogen-1.2.0/src/onto/templates_gallery/market/modules/loyalty.yaml +27 -0
  215. ontogen-1.2.0/src/onto/templates_gallery/market/modules/orders.yaml +55 -0
  216. ontogen-1.2.0/src/onto/templates_gallery/market/modules/payments.yaml +39 -0
  217. ontogen-1.2.0/src/onto/templates_gallery/market/modules/reservations.yaml +25 -0
  218. ontogen-1.2.0/src/onto/templates_gallery/market/modules/rooms.yaml +26 -0
  219. ontogen-1.2.0/src/onto/templates_gallery/market/modules/shipping.yaml +25 -0
  220. ontogen-1.2.0/src/onto/templates_gallery/market/modules/stock.yaml +33 -0
  221. ontogen-1.2.0/src/onto/templates_gallery/market/modules/support.yaml +33 -0
  222. ontogen-1.2.0/src/onto/templates_gallery/starter/flows.yaml +12 -0
  223. ontogen-1.2.0/src/onto/templates_gallery/starter/genome.yaml +25 -0
  224. ontogen-1.2.0/src/onto/theory/__init__.py +0 -0
  225. ontogen-1.2.0/src/onto/theory/formulas.py +95 -0
  226. ontogen-1.2.0/src/onto/theory/provenance.py +53 -0
  227. ontogen-1.2.0/tests/test_conformance.py +17 -0
  228. ontogen-1.2.0/tests/test_court.py +53 -0
  229. ontogen-1.2.0/tests/test_expr.py +45 -0
  230. ontogen-1.2.0/tests/test_flow_gates.py +91 -0
  231. ontogen-1.2.0/tests/test_freeze.py +26 -0
  232. ontogen-1.2.0/tests/test_go_dialect.py +33 -0
  233. ontogen-1.2.0/tests/test_interview.py +53 -0
  234. ontogen-1.2.0/tests/test_ir.py +26 -0
  235. ontogen-1.2.0/tests/test_lint.py +60 -0
  236. ontogen-1.2.0/tests/test_migrate.py +47 -0
  237. ontogen-1.2.0/tests/test_modules.py +78 -0
  238. ontogen-1.2.0/tests/test_organism.py +75 -0
  239. ontogen-1.2.0/tests/test_placer.py +50 -0
  240. ontogen-1.2.0/tests/test_policies.py +100 -0
  241. ontogen-1.2.0/tests/test_python_dialect.py +32 -0
  242. ontogen-1.2.0/tests/test_review2.py +150 -0
  243. ontogen-1.2.0/tests/test_skills.py +94 -0
  244. ontogen-1.2.0/tests/test_theory.py +48 -0
  245. ontogen-1.2.0/tools/check.sh +17 -0
  246. ontogen-1.2.0/uv.lock +662 -0
@@ -0,0 +1,16 @@
1
+ __pycache__/
2
+ *.pyc
3
+ .venv/
4
+ .pytest_cache/
5
+ build/
6
+ *.egg-info/
7
+ .onto/
8
+ # generated attestations, keys, live config (never commit)
9
+ genomes/attest.json
10
+ genomes/attest.md
11
+ **/attest.json
12
+ **/attest.md
13
+ .pypirc
14
+ *.pypirc
15
+ config.toml
16
+ dist/
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,46 @@
1
+ # v1 — project operating system (read FIRST in every session)
2
+
3
+ You are the ribosome of this project: cheap, forgetful, replaceable. Meaning lives in
4
+ the documents, not in the session. This file is your O(k) context.
5
+
6
+ ## What this is
7
+ A living compiler of ontologies (docs/design/SPEC.md §0). Numbering: **v0 = ../archgen**
8
+ (a donor of scars, NOT a donor of code, except what's listed in docs/log/PLAN.md), **v1 = here**.
9
+
10
+ ## Constitution of the method
11
+ docs/design/MODEL.md — the universal model of development (layers, cycle, roles, coverage,
12
+ the UNIVERSAL roadmap). On conflict with it, SPEC refines the mechanisms.
13
+
14
+ ## If you are the OPERATOR of an organism (feature/operation, not core development)
15
+ Read docs/OPERATOR.md + `onto explain <root> <entity>` — that's enough;
16
+ the rest here is for engine developers.
17
+
18
+ ## Reading order (for a new session 1–3 is enough)
19
+ 1. this file; 2. docs/log/PLAN.md — where we are (phase statuses); 3. docs/log/JOURNAL.md — the last
20
+ 2–3 entries. Deeper as needed: docs/design/SPEC.md (architecture), docs/design/NOT.md (prohibitions),
21
+ docs/log/DECISIONS.md (why it's so), docs/design/SCARS.md (v0), docs/log/PREDICTIONS.md (what to check).
22
+
23
+ ## Hierarchy of truth (on conflict, the upper one wins)
24
+ 1. the user's word in the current session → 2. docs/log/DECISIONS.md (accepted decisions)
25
+ → 3. SPEC/NOT → 4. PLAN → 5. JOURNAL/chats/artifacts (derived).
26
+ A contradiction between documents = a bug: fix the document, record it in JOURNAL.
27
+
28
+ ## Session protocol (mandatory)
29
+ - START: read points 1–3; do NOT begin code if the phase is unclear.
30
+ - WORK: a new decision → a line in docs/log/DECISIONS.md (D-number, status, why);
31
+ a cancelled one — supersede, don't delete. Inexpressible/dropped → docs/design/UNEXPRESSIBLE.md
32
+ (create on the first occurrence). An idea outside the current phase → JOURNAL "parking,"
33
+ do NOT implement (NOT §26).
34
+ - FINISH: an entry in docs/log/JOURNAL.md (what was done/decided/opened, 5–10 lines) +
35
+ `git add v1 && git commit` — a wave without a commit does not exist (S7 v0).
36
+ - PHASE EXAM: walk through docs/log/PREDICTIONS.md — fulfilled/not, mark it.
37
+
38
+ ## Hard prohibitions (full list — docs/design/NOT.md, 36 items)
39
+ The core knows no languages (I1); no regex-DSL; extra=allow is forbidden;
40
+ F1 — an interpreter WITHOUT code generation; commit only v1/ (don't touch archgen);
41
+ "from the theorem" only for Derived; no batches in the ribosome.
42
+
43
+ ## Artifacts outside the repo
44
+ "Anatomy of v1" diagram: claude.ai/code/artifact/2515e15d-cb36-410d-ab78-e97f94d5ed54
45
+ (source — docs/anatomy.html, edit it and republish to the same URL).
46
+ Claude memory: ~/.claude/projects/-home-the maintainer-dnaContract/memory/.
ontogen-1.2.0/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works.
111
+
112
+ You may add Your own copyright statement to Your modifications and
113
+ may provide additional or different license terms and conditions
114
+ for use, reproduction, or distribution of Your modifications, or
115
+ for any such Derivative Works as a whole, provided Your use,
116
+ reproduction, and distribution of the Work otherwise complies with
117
+ the conditions stated in this License.
118
+
119
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
120
+ any Contribution intentionally submitted for inclusion in the Work
121
+ by You to the Licensor shall be under the terms and conditions of
122
+ this License, without any additional terms or conditions.
123
+ Notwithstanding the above, nothing herein shall supersede or modify
124
+ the terms of any separate license agreement you may have executed
125
+ with Licensor regarding such Contributions.
126
+
127
+ 6. Trademarks. This License does not grant permission to use the trade
128
+ names, trademarks, service marks, or product names of the Licensor,
129
+ except as required for reasonable and customary use in describing the
130
+ origin of the Work and reproducing the content of the NOTICE file.
131
+
132
+ 7. Disclaimer of Warranty. Unless required by applicable law or
133
+ agreed to in writing, Licensor provides the Work (and each
134
+ Contributor provides its Contributions) on an "AS IS" BASIS,
135
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
136
+ implied, including, without limitation, any warranties or conditions
137
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
138
+ PARTICULAR PURPOSE. You are solely responsible for determining the
139
+ appropriateness of using or redistributing the Work and assume any
140
+ risks associated with Your exercise of permissions under this License.
141
+
142
+ 8. Limitation of Liability. In no event and under no legal theory,
143
+ whether in tort (including negligence), contract, or otherwise,
144
+ unless required by applicable law (such as deliberate and grossly
145
+ negligent acts) or agreed to in writing, shall any Contributor be
146
+ liable to You for damages, including any direct, indirect, special,
147
+ incidental, or consequential damages of any character arising as a
148
+ result of this License or out of the use or inability to use the
149
+ Work (including but not limited to damages for loss of goodwill,
150
+ work stoppage, computer failure or malfunction, or any and all
151
+ other commercial damages or losses), even if such Contributor
152
+ has been advised of the possibility of such damages.
153
+
154
+ 9. Accepting Warranty or Additional Liability. While redistributing
155
+ the Work or Derivative Works thereof, You may choose to offer,
156
+ and charge a fee for, acceptance of support, warranty, indemnity,
157
+ or other liability obligations and/or rights consistent with this
158
+ License. However, in accepting such obligations, You may act only
159
+ on Your own behalf and on Your sole responsibility, not on behalf
160
+ of any other Contributor, and only if You agree to indemnify,
161
+ defend, and hold each Contributor harmless for any liability
162
+ incurred by, or claims asserted against, such Contributor by reason
163
+ of your accepting any such warranty or additional liability.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ APPENDIX: How to apply the Apache License to your work.
168
+
169
+ To apply the Apache License to your work, attach the following
170
+ boilerplate notice, with the fields enclosed by brackets "[]"
171
+ replaced with your own identifying information. (Don't include
172
+ the brackets!) The text should be enclosed in the appropriate
173
+ comment syntax for the file format. We also recommend that a
174
+ file or class name and description of purpose be included on the
175
+ same "printed page" as the copyright notice for easier
176
+ identification within third-party archives.
177
+
178
+ Copyright 2026 the ontogen authors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
ontogen-1.2.0/PKG-INFO ADDED
@@ -0,0 +1,100 @@
1
+ Metadata-Version: 2.5
2
+ Name: ontogen
3
+ Version: 1.2.0
4
+ Summary: onto: a living ontology compiler — programs are genomes; code is a proven, printed phenotype
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: code-generation,compiler,formal-verification,genome,ontology,smt
8
+ Requires-Python: <3.14,>=3.13
9
+ Requires-Dist: mcp>=2.0.0
10
+ Requires-Dist: pydantic>=2.7
11
+ Requires-Dist: pyyaml>=6
12
+ Requires-Dist: z3-solver>=4.13
13
+ Description-Content-Type: text/markdown
14
+
15
+ # onto — a living compiler of ontologies
16
+
17
+ A program is stored not as code, but as a **genome**: entities, rules with
18
+ executable bodies, contracts, invariants. Code is the phenotype: printed into
19
+ dialects (Go, Python), proven by the court (SMT), living under a warden, and
20
+ regrown from scratch. A change in behavior without confirmation is a question with an
21
+ executable counterexample, not a silent merge.
22
+
23
+ ```bash
24
+ uv tool install ontogen # -> global `onto`
25
+ onto validate genomes/hotel.yaml # typecheck the genome
26
+ onto court genomes/hotel.yaml # SMT court: contracts proven, mutants distinguished
27
+ onto serve genomes/hotel.yaml --port 8090 --data ./data [--store sqlite]
28
+ onto warden genomes/hotel.yaml ... # daemon: watch -> gates -> molt -> monitors
29
+ onto materialize genomes/hotel.yaml --dialect go-stdlib # print the phenotype
30
+ onto mcp genomes/hotel.yaml # a mouth for the LLM (propose = the only write)
31
+ ```
32
+
33
+ ## Models: bring your own (any OpenAI-compatible provider)
34
+
35
+ Configure providers and per-task model ladders in `.onto/config.toml` —
36
+ OpenRouter, OpenAI, Groq, Together, DeepSeek, a local Ollama/vLLM, anything
37
+ OpenAI-compatible. Name a known provider and give only a key (base_url is a
38
+ preset); reference models as `provider:model` or bare. Keys come from
39
+ `${ENV}` or `@keyfile`, never hardcoded. `onto models` shows the registry.
40
+
41
+ ```toml
42
+ [default]
43
+ provider = "openrouter"
44
+ [provider.openrouter]
45
+ api_key = "${OPENROUTER_API_KEY}"
46
+ [provider.local]
47
+ base_url = "http://localhost:11434/v1" # Ollama
48
+ api_key = "ollama"
49
+ [ladders]
50
+ skills = ["qwen/qwen3-coder", "qwen/qwen3-coder-plus"]
51
+ nl = ["anthropic/claude-sonnet-4.5", "local:qwen2.5-coder"]
52
+ ```
53
+
54
+ ## Quickstart (zero machine)
55
+
56
+ ```bash
57
+ curl -LsSf https://astral.sh/uv/install.sh | sh # 1. uv (brings its own Python)
58
+ uv tool install ontogen # 2. the engine, isolated
59
+ onto init # 3. couple this project + harness
60
+ # -> .onto/ + genome/ + MCP registration + edit-guard hook + skill
61
+ onto court genome/genome.yaml # prove (ALL PROVED)
62
+ onto serve genome/genome.yaml --data .onto/data # live organism from second zero
63
+ ```
64
+
65
+ The harness (Claude Code) sees the MCP server immediately; it changes
66
+ behavior only through `propose` (checkers + SMT court + semantic diff), and
67
+ a hook blocks any direct edit of the genome or the printed phenotype.
68
+ Dialect toolchains (e.g. Go/JVM) are pulled lazily, only at `materialize`.
69
+
70
+ ## Status: 1.2.0 — the U1-U8 constitution is closed, IR v1.0 is frozen (D72)
71
+
72
+ ## End-to-end scenario (IDEAL, works)
73
+ A natural-language product description -> `nlfront` builds a genome+acceptance -> the COURT proves
74
+ -> the organism lives (warden timers, /admin, /list, /q?params, webhooks)
75
+ -> any language is grown by the model (`growdialect`). Exams: exams/fnl.py,
76
+ exams/fideal.py, exams/fgrow.py.
77
+
78
+ ## Where to look
79
+ | you need | read |
80
+ |---|---|
81
+ | HOW any software is developed under this model | **`docs/design/MODEL.md`** — the method's constitution |
82
+ | to run an organism (features, operation) | `docs/OPERATOR.md` + `onto explain <root> <entity>` |
83
+ | engine development | `CLAUDE.md` -> `docs/log/PLAN.md` -> `docs/log/JOURNAL.md` |
84
+ | architecture and decisions | `docs/design/SPEC.md`, `docs/log/DECISIONS.md` (D1–D87) |
85
+ | what we don't do and why | `docs/design/NOT.md`, `docs/design/SCARS.md` (v0 scars), `docs/design/UNEXPRESSIBLE.md` |
86
+ | visual diagram | `docs/anatomy.html` |
87
+
88
+ ## What the exams have proven (exams/, all green)
89
+ the organism lives via an interpreter without code generation; one judge is green on
90
+ interpreter+Go+Python; contracts are proven (COURT), 21/21 mutants
91
+ distinguished, an equivalent mutant recognized; gene composition (payments in three
92
+ domains byte-for-byte); metabolism by measured heat with failure-with-arithmetic;
93
+ warden: molt in 0.3s, migration of 30k live events by functor, REVOKE of rights;
94
+ live CEGIS with an SLM (~$0.001/skill); a membrane for others' organisms (drift ->
95
+ trust revocation); 25k ev/s ingest, p99 1.8ms, kill -9 -> start from snapshot
96
+ 0.01s; jsonl|sqlite store with a byte-identical fold. Running the whole battery:
97
+ `tools/check.sh`.
98
+
99
+ Status: the engine is built and delivered exam by exam (see `docs/log/PLAN.md`); open —
100
+ calendar operation and the external operator (F7).
@@ -0,0 +1,86 @@
1
+ # onto — a living compiler of ontologies
2
+
3
+ A program is stored not as code, but as a **genome**: entities, rules with
4
+ executable bodies, contracts, invariants. Code is the phenotype: printed into
5
+ dialects (Go, Python), proven by the court (SMT), living under a warden, and
6
+ regrown from scratch. A change in behavior without confirmation is a question with an
7
+ executable counterexample, not a silent merge.
8
+
9
+ ```bash
10
+ uv tool install ontogen # -> global `onto`
11
+ onto validate genomes/hotel.yaml # typecheck the genome
12
+ onto court genomes/hotel.yaml # SMT court: contracts proven, mutants distinguished
13
+ onto serve genomes/hotel.yaml --port 8090 --data ./data [--store sqlite]
14
+ onto warden genomes/hotel.yaml ... # daemon: watch -> gates -> molt -> monitors
15
+ onto materialize genomes/hotel.yaml --dialect go-stdlib # print the phenotype
16
+ onto mcp genomes/hotel.yaml # a mouth for the LLM (propose = the only write)
17
+ ```
18
+
19
+ ## Models: bring your own (any OpenAI-compatible provider)
20
+
21
+ Configure providers and per-task model ladders in `.onto/config.toml` —
22
+ OpenRouter, OpenAI, Groq, Together, DeepSeek, a local Ollama/vLLM, anything
23
+ OpenAI-compatible. Name a known provider and give only a key (base_url is a
24
+ preset); reference models as `provider:model` or bare. Keys come from
25
+ `${ENV}` or `@keyfile`, never hardcoded. `onto models` shows the registry.
26
+
27
+ ```toml
28
+ [default]
29
+ provider = "openrouter"
30
+ [provider.openrouter]
31
+ api_key = "${OPENROUTER_API_KEY}"
32
+ [provider.local]
33
+ base_url = "http://localhost:11434/v1" # Ollama
34
+ api_key = "ollama"
35
+ [ladders]
36
+ skills = ["qwen/qwen3-coder", "qwen/qwen3-coder-plus"]
37
+ nl = ["anthropic/claude-sonnet-4.5", "local:qwen2.5-coder"]
38
+ ```
39
+
40
+ ## Quickstart (zero machine)
41
+
42
+ ```bash
43
+ curl -LsSf https://astral.sh/uv/install.sh | sh # 1. uv (brings its own Python)
44
+ uv tool install ontogen # 2. the engine, isolated
45
+ onto init # 3. couple this project + harness
46
+ # -> .onto/ + genome/ + MCP registration + edit-guard hook + skill
47
+ onto court genome/genome.yaml # prove (ALL PROVED)
48
+ onto serve genome/genome.yaml --data .onto/data # live organism from second zero
49
+ ```
50
+
51
+ The harness (Claude Code) sees the MCP server immediately; it changes
52
+ behavior only through `propose` (checkers + SMT court + semantic diff), and
53
+ a hook blocks any direct edit of the genome or the printed phenotype.
54
+ Dialect toolchains (e.g. Go/JVM) are pulled lazily, only at `materialize`.
55
+
56
+ ## Status: 1.2.0 — the U1-U8 constitution is closed, IR v1.0 is frozen (D72)
57
+
58
+ ## End-to-end scenario (IDEAL, works)
59
+ A natural-language product description -> `nlfront` builds a genome+acceptance -> the COURT proves
60
+ -> the organism lives (warden timers, /admin, /list, /q?params, webhooks)
61
+ -> any language is grown by the model (`growdialect`). Exams: exams/fnl.py,
62
+ exams/fideal.py, exams/fgrow.py.
63
+
64
+ ## Where to look
65
+ | you need | read |
66
+ |---|---|
67
+ | HOW any software is developed under this model | **`docs/design/MODEL.md`** — the method's constitution |
68
+ | to run an organism (features, operation) | `docs/OPERATOR.md` + `onto explain <root> <entity>` |
69
+ | engine development | `CLAUDE.md` -> `docs/log/PLAN.md` -> `docs/log/JOURNAL.md` |
70
+ | architecture and decisions | `docs/design/SPEC.md`, `docs/log/DECISIONS.md` (D1–D87) |
71
+ | what we don't do and why | `docs/design/NOT.md`, `docs/design/SCARS.md` (v0 scars), `docs/design/UNEXPRESSIBLE.md` |
72
+ | visual diagram | `docs/anatomy.html` |
73
+
74
+ ## What the exams have proven (exams/, all green)
75
+ the organism lives via an interpreter without code generation; one judge is green on
76
+ interpreter+Go+Python; contracts are proven (COURT), 21/21 mutants
77
+ distinguished, an equivalent mutant recognized; gene composition (payments in three
78
+ domains byte-for-byte); metabolism by measured heat with failure-with-arithmetic;
79
+ warden: molt in 0.3s, migration of 30k live events by functor, REVOKE of rights;
80
+ live CEGIS with an SLM (~$0.001/skill); a membrane for others' organisms (drift ->
81
+ trust revocation); 25k ev/s ingest, p99 1.8ms, kill -9 -> start from snapshot
82
+ 0.01s; jsonl|sqlite store with a byte-identical fold. Running the whole battery:
83
+ `tools/check.sh`.
84
+
85
+ Status: the engine is built and delivered exam by exam (see `docs/log/PLAN.md`); open —
86
+ calendar operation and the external operator (F7).
@@ -0,0 +1,45 @@
1
+ def fast_match_orders(bids, asks):
2
+ # Filter out orders with qty <= 0
3
+ bids = [b for b in bids if b.qty > 0]
4
+ asks = [a for a in asks if a.qty > 0]
5
+
6
+ # Sort bids: highest price first, then earliest ts, then lex id
7
+ bids.sort(key=lambda x: (-x.price, x.ts, x.id))
8
+ # Sort asks: lowest price first, then earliest ts, then lex id
9
+ asks.sort(key=lambda x: (x.price, x.ts, x.id))
10
+
11
+ trades = []
12
+ i, j = 0, 0 # pointers for bids and asks
13
+
14
+ while i < len(bids) and j < len(asks):
15
+ bid = bids[i]
16
+ ask = asks[j]
17
+
18
+ # Check if they can match
19
+ if bid.price >= ask.price:
20
+ # Match quantity is the minimum of remaining quantities
21
+ match_qty = min(bid.qty, ask.qty)
22
+ if match_qty > 0:
23
+ # Create trade at ask's price
24
+ trade = {
25
+ "bid": bid.id,
26
+ "ask": ask.id,
27
+ "price": ask.price,
28
+ "qty": match_qty
29
+ }
30
+ trades.append(trade)
31
+
32
+ # Update remaining quantities
33
+ bid.qty -= match_qty
34
+ ask.qty -= match_qty
35
+
36
+ # Move to next order if current is fully filled
37
+ if bid.qty == 0:
38
+ i += 1
39
+ if ask.qty == 0:
40
+ j += 1
41
+ else:
42
+ # No more matches possible due to price mismatch
43
+ break
44
+
45
+ return trades
@@ -0,0 +1,34 @@
1
+ def fast_allocate(demands, stocks):
2
+ # Aggregate available stock by SKU
3
+ stock_dict = {}
4
+ for st in stocks:
5
+ stock_dict[st.sku] = stock_dict.get(st.sku, 0) + st.available
6
+
7
+ # Sort demands: higher priority first, then by id ascending
8
+ sorted_demands = sorted(demands, key=lambda d: (-d.priority, d.id))
9
+
10
+ allocations = []
11
+ # Track how much has been allocated per demand and per sku
12
+ allocated_to_demand = {d.id: 0 for d in demands}
13
+ allocated_per_sku = {sku: 0 for sku in stock_dict}
14
+
15
+ for demand in sorted_demands:
16
+ remaining_demand = demand.qty - allocated_to_demand[demand.id]
17
+ if remaining_demand <= 0:
18
+ continue
19
+
20
+ available_stock = stock_dict.get(demand.sku, 0) - allocated_per_sku.get(demand.sku, 0)
21
+ if available_stock <= 0:
22
+ continue
23
+
24
+ alloc_qty = min(remaining_demand, available_stock)
25
+ if alloc_qty > 0:
26
+ allocations.append({
27
+ "id": demand.id,
28
+ "sku": demand.sku,
29
+ "qty": alloc_qty
30
+ })
31
+ allocated_to_demand[demand.id] += alloc_qty
32
+ allocated_per_sku[demand.sku] += alloc_qty
33
+
34
+ return allocations
@@ -0,0 +1,34 @@
1
+ def fast_allocate(demands, stocks):
2
+ # Aggregate available stock by SKU
3
+ stock_dict = {}
4
+ for st in stocks:
5
+ stock_dict[st.sku] = stock_dict.get(st.sku, 0) + st.available
6
+
7
+ # Sort demands: higher priority first, then by id ascending
8
+ sorted_demands = sorted(demands, key=lambda d: (-d.priority, d.id))
9
+
10
+ allocations = []
11
+ # Track how much has been allocated per demand and per sku
12
+ allocated_to_demand = {d.id: 0 for d in demands}
13
+ allocated_per_sku = {sku: 0 for sku in stock_dict}
14
+
15
+ for demand in sorted_demands:
16
+ remaining_demand = demand.qty - allocated_to_demand[demand.id]
17
+ if remaining_demand <= 0:
18
+ continue
19
+
20
+ available_stock = stock_dict.get(demand.sku, 0) - allocated_per_sku.get(demand.sku, 0)
21
+ if available_stock <= 0:
22
+ continue
23
+
24
+ alloc_qty = min(remaining_demand, available_stock)
25
+ if alloc_qty > 0:
26
+ allocations.append({
27
+ "id": demand.id,
28
+ "sku": demand.sku,
29
+ "qty": alloc_qty
30
+ })
31
+ allocated_to_demand[demand.id] += alloc_qty
32
+ allocated_per_sku[demand.sku] += alloc_qty
33
+
34
+ return allocations
@@ -0,0 +1,34 @@
1
+ def naive_allocate(demands, stocks):
2
+ # Aggregate available stock by SKU
3
+ stock_dict = {}
4
+ for st in stocks:
5
+ stock_dict[st.sku] = stock_dict.get(st.sku, 0) + st.available
6
+
7
+ # Sort demands: higher priority first, then by id ascending
8
+ sorted_demands = sorted(demands, key=lambda d: (-d.priority, d.id))
9
+
10
+ allocations = []
11
+ # Track how much has been allocated per demand and per sku
12
+ allocated_to_demand = {d.id: 0 for d in demands}
13
+ allocated_per_sku = {sku: 0 for sku in stock_dict}
14
+
15
+ for demand in sorted_demands:
16
+ remaining_demand = demand.qty - allocated_to_demand[demand.id]
17
+ if remaining_demand <= 0:
18
+ continue
19
+
20
+ available_stock = stock_dict.get(demand.sku, 0) - allocated_per_sku.get(demand.sku, 0)
21
+ if available_stock <= 0:
22
+ continue
23
+
24
+ alloc_qty = min(remaining_demand, available_stock)
25
+ if alloc_qty > 0:
26
+ allocations.append({
27
+ "id": demand.id,
28
+ "sku": demand.sku,
29
+ "qty": alloc_qty
30
+ })
31
+ allocated_to_demand[demand.id] += alloc_qty
32
+ allocated_per_sku[demand.sku] += alloc_qty
33
+
34
+ return allocations
@@ -0,0 +1,28 @@
1
+ def fast_allocate(demands, stocks):
2
+ # Create a copy of available stock quantities that we can modify
3
+ stock_available = {st.sku: st.available for st in stocks}
4
+
5
+ # Sort demands by priority (descending) then by id (ascending)
6
+ sorted_demands = sorted(demands, key=lambda d: (-d.priority, d.id))
7
+
8
+ allocations = []
9
+
10
+ for demand in sorted_demands:
11
+ # Check if there's any stock available for this SKU
12
+ if demand.sku in stock_available and stock_available[demand.sku] > 0:
13
+ # Allocate the minimum of what's demanded and what's available
14
+ alloc_qty = min(demand.qty, stock_available[demand.sku])
15
+
16
+ # Only create an allocation if qty > 0
17
+ if alloc_qty > 0:
18
+ # Create allocation as a dict
19
+ allocations.append({
20
+ "id": demand.id,
21
+ "sku": demand.sku,
22
+ "qty": alloc_qty
23
+ })
24
+
25
+ # Reduce available stock
26
+ stock_available[demand.sku] -= alloc_qty
27
+
28
+ return allocations
@@ -0,0 +1,34 @@
1
+ def naive_allocate(demands, stocks):
2
+ # Aggregate available stock by SKU
3
+ stock_dict = {}
4
+ for st in stocks:
5
+ stock_dict[st.sku] = stock_dict.get(st.sku, 0) + st.available
6
+
7
+ # Sort demands: higher priority first, then by id ascending
8
+ sorted_demands = sorted(demands, key=lambda d: (-d.priority, d.id))
9
+
10
+ allocations = []
11
+ # Track how much has been allocated per demand and per sku
12
+ allocated_to_demand = {d.id: 0 for d in demands}
13
+ allocated_per_sku = {sku: 0 for sku in stock_dict}
14
+
15
+ for demand in sorted_demands:
16
+ remaining_demand = demand.qty - allocated_to_demand[demand.id]
17
+ if remaining_demand <= 0:
18
+ continue
19
+
20
+ available_stock = stock_dict.get(demand.sku, 0) - allocated_per_sku.get(demand.sku, 0)
21
+ if available_stock <= 0:
22
+ continue
23
+
24
+ alloc_qty = min(remaining_demand, available_stock)
25
+ if alloc_qty > 0:
26
+ allocations.append({
27
+ "id": demand.id,
28
+ "sku": demand.sku,
29
+ "qty": alloc_qty
30
+ })
31
+ allocated_to_demand[demand.id] += alloc_qty
32
+ allocated_per_sku[demand.sku] += alloc_qty
33
+
34
+ return allocations