nullius-eval 0.1.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 (291) hide show
  1. _nullius_app/.env.example +55 -0
  2. _nullius_app/app.py +96 -0
  3. _nullius_app/requirements.txt +1 -0
  4. _nullius_app/static/brand/README.md +20 -0
  5. _nullius_app/static/brand/docker.svg +1 -0
  6. _nullius_app/static/brand/favicon.svg +1 -0
  7. _nullius_app/static/brand/huggingface.svg +37 -0
  8. _nullius_app/static/brand/mark-dark.svg +1 -0
  9. _nullius_app/static/brand/marks.svg +34 -0
  10. _nullius_app/static/brand/tokens.json +51 -0
  11. _nullius_app/static/brand/typesafe.png +0 -0
  12. _nullius_app/static/brand/wordmark-dark.svg +1 -0
  13. _nullius_app/static/builder/command-builder-core.js +763 -0
  14. _nullius_app/static/builder/command-builder.css +248 -0
  15. _nullius_app/static/builder/command-builder.js +997 -0
  16. _nullius_app/static/builder/model-picker.js +113 -0
  17. _nullius_app/static/catalogue/add.js +46 -0
  18. _nullius_app/static/catalogue/agents/README.md +19 -0
  19. _nullius_app/static/catalogue/agents/goose.svg +1 -0
  20. _nullius_app/static/catalogue/agents/jiuwenswarm.svg +33 -0
  21. _nullius_app/static/catalogue/agents/marks.json +8 -0
  22. _nullius_app/static/catalogue/agents/mini-swe-agent.svg +7 -0
  23. _nullius_app/static/catalogue/agents/opencode.svg +7 -0
  24. _nullius_app/static/catalogue/catalogue.css +436 -0
  25. _nullius_app/static/catalogue/catalogue.js +87 -0
  26. _nullius_app/static/catalogue/marks.svg +29 -0
  27. _nullius_app/static/catalogue/new.js +78 -0
  28. _nullius_app/static/catalogue/versions.js +27 -0
  29. _nullius_app/static/compare/comparison.css +117 -0
  30. _nullius_app/static/controls.js +117 -0
  31. _nullius_app/static/disclosures.js +70 -0
  32. _nullius_app/static/fonts/0569c822cab6c510.ttf +0 -0
  33. _nullius_app/static/fonts/DMSans-Medium.woff2 +0 -0
  34. _nullius_app/static/fonts/DMSans-Regular.woff2 +0 -0
  35. _nullius_app/static/fonts/IBMPlexMono-Medium.woff2 +0 -0
  36. _nullius_app/static/fonts/IBMPlexMono-Regular.woff2 +0 -0
  37. _nullius_app/static/fonts/InstrumentSerif-Italic.woff2 +0 -0
  38. _nullius_app/static/fonts/InstrumentSerif-Regular.woff2 +0 -0
  39. _nullius_app/static/fonts/README.md +11 -0
  40. _nullius_app/static/fonts/c1e7453ea26a1d1e.ttf +0 -0
  41. _nullius_app/static/fonts/dmsans-OFL.txt +93 -0
  42. _nullius_app/static/fonts/ibmplexmono-OFL.txt +93 -0
  43. _nullius_app/static/fonts/instrumentserif-OFL.txt +93 -0
  44. _nullius_app/static/fonts.css +49 -0
  45. _nullius_app/static/notifications.js +49 -0
  46. _nullius_app/static/onboarding.css +78 -0
  47. _nullius_app/static/onboarding.js +158 -0
  48. _nullius_app/static/runs/board.css +358 -0
  49. _nullius_app/static/runs/board.js +127 -0
  50. _nullius_app/static/runs/launches.css +88 -0
  51. _nullius_app/static/runs/live-board.css +186 -0
  52. _nullius_app/static/runs/live-board.js +394 -0
  53. _nullius_app/static/runs/path-suggestions.js +119 -0
  54. _nullius_app/static/runs/start.css +38 -0
  55. _nullius_app/static/settings/autosave.js +162 -0
  56. _nullius_app/static/settings/custom-keys.js +100 -0
  57. _nullius_app/static/settings/data-providers.js +88 -0
  58. _nullius_app/static/settings/judges.js +61 -0
  59. _nullius_app/static/settings/modal.css +32 -0
  60. _nullius_app/static/settings/modal.js +91 -0
  61. _nullius_app/static/settings/navigation.js +55 -0
  62. _nullius_app/static/settings/prices.js +68 -0
  63. _nullius_app/static/settings/providers.js +134 -0
  64. _nullius_app/static/settings/sandbox.js +20 -0
  65. _nullius_app/static/settings/settings.css +288 -0
  66. _nullius_app/static/style.css +1752 -0
  67. _nullius_app/static/traces/conversation.css +49 -0
  68. _nullius_app/static/traces/conversation.js +215 -0
  69. _nullius_app/templates/agents/entry.html +145 -0
  70. _nullius_app/templates/agents/kits.html +55 -0
  71. _nullius_app/templates/agents/standard.html +58 -0
  72. _nullius_app/templates/base.html +479 -0
  73. _nullius_app/templates/builder/new_run.html +55 -0
  74. _nullius_app/templates/catalogue/add_dialog.html +32 -0
  75. _nullius_app/templates/catalogue/benchmark.html +270 -0
  76. _nullius_app/templates/catalogue/benchmarks.html +91 -0
  77. _nullius_app/templates/catalogue/new.html +141 -0
  78. _nullius_app/templates/catalogue/use_bundle.html +11 -0
  79. _nullius_app/templates/compare/_detail.html +37 -0
  80. _nullius_app/templates/compare/compare.html +298 -0
  81. _nullius_app/templates/compare/compare_picker.html +51 -0
  82. _nullius_app/templates/compare/compare_task.html +329 -0
  83. _nullius_app/templates/runs/_execution.html +131 -0
  84. _nullius_app/templates/runs/_runtime.html +5 -0
  85. _nullius_app/templates/runs/ascii-mark.html +485 -0
  86. _nullius_app/templates/runs/feasibility.html +127 -0
  87. _nullius_app/templates/runs/index.html +609 -0
  88. _nullius_app/templates/runs/job.html +460 -0
  89. _nullius_app/templates/runs/preparing.html +14 -0
  90. _nullius_app/templates/runs/reconcile.html +124 -0
  91. _nullius_app/templates/runs/setup.html +272 -0
  92. _nullius_app/templates/runs/start.html +51 -0
  93. _nullius_app/templates/settings/custom_keys.html +82 -0
  94. _nullius_app/templates/settings/data_providers.html +27 -0
  95. _nullius_app/templates/settings/settings.html +564 -0
  96. _nullius_app/templates/traces/_charts.html +165 -0
  97. _nullius_app/templates/traces/_conversation.html +37 -0
  98. _nullius_app/templates/traces/_judgement.html +72 -0
  99. _nullius_app/templates/traces/artifact.html +15 -0
  100. _nullius_app/templates/traces/trial.html +838 -0
  101. _nullius_app/templates/workspaces/workspaces.html +54 -0
  102. _nullius_app/web/__init__.py +1 -0
  103. _nullius_app/web/agents.py +230 -0
  104. _nullius_app/web/builder.py +406 -0
  105. _nullius_app/web/catalogue.py +370 -0
  106. _nullius_app/web/compare.py +489 -0
  107. _nullius_app/web/core.py +17 -0
  108. _nullius_app/web/execute.py +223 -0
  109. _nullius_app/web/feasibility.py +60 -0
  110. _nullius_app/web/filters.py +231 -0
  111. _nullius_app/web/judge.py +623 -0
  112. _nullius_app/web/judge_tasks.py +33 -0
  113. _nullius_app/web/onboarding.py +20 -0
  114. _nullius_app/web/reconcile.py +47 -0
  115. _nullius_app/web/runs.py +464 -0
  116. _nullius_app/web/settings.py +324 -0
  117. _nullius_app/web/shared.py +507 -0
  118. _nullius_app/web/traces.py +306 -0
  119. _nullius_app/web/workspaces.py +84 -0
  120. nullius/__init__.py +32 -0
  121. nullius/__main__.py +5 -0
  122. nullius/catalogue/__init__.py +0 -0
  123. nullius/catalogue/agents/codex/agent.json +222 -0
  124. nullius/catalogue/agents/codex/config.toml +25 -0
  125. nullius/catalogue/agents/goose/agent.json +131 -0
  126. nullius/catalogue/agents/goose/config.yaml +20 -0
  127. nullius/catalogue/agents/jiuwenswarm/agent.json +197 -0
  128. nullius/catalogue/agents/jiuwenswarm/agent.py +355 -0
  129. nullius/catalogue/agents/mini-swe-agent/agent.json +68 -0
  130. nullius/catalogue/agents/mini-swe-agent/run.py +37 -0
  131. nullius/catalogue/agents/opencode/agent.json +135 -0
  132. nullius/catalogue/agents/opencode/opencode.json +32 -0
  133. nullius/catalogue/agents/reference/agent.json +89 -0
  134. nullius/catalogue/agents/reference/agent.py +209 -0
  135. nullius/catalogue/agents/terminus-2/agent.json +64 -0
  136. nullius/catalogue/agents/terminus-2/run.py +139 -0
  137. nullius/catalogue/benchmarks/gaia/benchmark.json +72 -0
  138. nullius/catalogue/benchmarks/gaia/data-source.json +29 -0
  139. nullius/catalogue/benchmarks/gaia/driver.py +188 -0
  140. nullius/catalogue/benchmarks/gaia/env/data.Dockerfile +1 -0
  141. nullius/catalogue/benchmarks/gaia/standard.json +278 -0
  142. nullius/catalogue/benchmarks/gaia/upstream-settings.json +275 -0
  143. nullius/catalogue/benchmarks/gsm8k/benchmark.json +34 -0
  144. nullius/catalogue/benchmarks/gsm8k/driver.py +101 -0
  145. nullius/catalogue/benchmarks/gsm8k/standard.json +124 -0
  146. nullius/catalogue/benchmarks/gsm8k/upstream-settings.json +86 -0
  147. nullius/catalogue/benchmarks/humaneval/benchmark.json +36 -0
  148. nullius/catalogue/benchmarks/humaneval/driver.py +243 -0
  149. nullius/catalogue/benchmarks/humaneval/standard.json +115 -0
  150. nullius/catalogue/benchmarks/humaneval/upstream-settings.json +72 -0
  151. nullius/catalogue/benchmarks/locomo/benchmark.json +43 -0
  152. nullius/catalogue/benchmarks/locomo/driver.py +270 -0
  153. nullius/catalogue/benchmarks/locomo/standard.json +265 -0
  154. nullius/catalogue/benchmarks/locomo/upstream-settings.json +112 -0
  155. nullius/catalogue/benchmarks/longmemeval/benchmark.json +65 -0
  156. nullius/catalogue/benchmarks/longmemeval/driver.py +379 -0
  157. nullius/catalogue/benchmarks/longmemeval/standard.json +733 -0
  158. nullius/catalogue/benchmarks/longmemeval/upstream-settings.json +76 -0
  159. nullius/catalogue/benchmarks/swe-bench-verified/benchmark.json +87 -0
  160. nullius/catalogue/benchmarks/swe-bench-verified/driver.py +116 -0
  161. nullius/catalogue/benchmarks/swe-bench-verified/images.json +502 -0
  162. nullius/catalogue/benchmarks/swe-bench-verified/standard.json +108 -0
  163. nullius/catalogue/benchmarks/swe-bench-verified/upstream-settings.json +32 -0
  164. nullius/catalogue/benchmarks/tau3-bench/benchmark.json +49 -0
  165. nullius/catalogue/benchmarks/tau3-bench/driver.py +608 -0
  166. nullius/catalogue/benchmarks/tau3-bench/mcp_server.py +114 -0
  167. nullius/catalogue/benchmarks/tau3-bench/search_relay.py +19 -0
  168. nullius/catalogue/benchmarks/tau3-bench/standard.json +547 -0
  169. nullius/catalogue/benchmarks/tau3-bench/upstream-settings.json +639 -0
  170. nullius/catalogue/benchmarks/terminal-bench/benchmark.json +69 -0
  171. nullius/catalogue/benchmarks/terminal-bench/driver.py +267 -0
  172. nullius/catalogue/benchmarks/terminal-bench/standard.json +166 -0
  173. nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json +36 -0
  174. nullius/catalogue/capabilities/keyword-memory/capability.json +33 -0
  175. nullius/catalogue/capabilities/keyword-memory/capability.py +55 -0
  176. nullius/catalogue/capabilities/mem0/capability.json +135 -0
  177. nullius/catalogue/capabilities/mem0/capability.py +173 -0
  178. nullius/catalogue/catalog.py +426 -0
  179. nullius/catalogue/citation.py +116 -0
  180. nullius/catalogue/harbor_entry.py +367 -0
  181. nullius/catalogue/sources.py +107 -0
  182. nullius/catalogue/storage.py +125 -0
  183. nullius/cli.py +85 -0
  184. nullius/compare/__init__.py +0 -0
  185. nullius/compare/cli.py +265 -0
  186. nullius/compare/comparison.py +184 -0
  187. nullius/execution.py +1653 -0
  188. nullius/gitrefs.py +128 -0
  189. nullius/harbor/__init__.py +0 -0
  190. nullius/harbor/feed.py +228 -0
  191. nullius/harbor/source.py +582 -0
  192. nullius/hosts.py +368 -0
  193. nullius/importers/__init__.py +140 -0
  194. nullius/importers/atif.py +387 -0
  195. nullius/importers/cli.py +135 -0
  196. nullius/importers/otel.py +274 -0
  197. nullius/judge/__init__.py +14 -0
  198. nullius/judge/batch.py +122 -0
  199. nullius/judge/client.py +433 -0
  200. nullius/judge/floors.json +86 -0
  201. nullius/judge/lanes.py +89 -0
  202. nullius/judge/questions.py +309 -0
  203. nullius/judge/reconcile.py +176 -0
  204. nullius/judge/state.py +224 -0
  205. nullius/judge/store.py +167 -0
  206. nullius/migrate.py +268 -0
  207. nullius/onboarding.py +116 -0
  208. nullius/paths.py +89 -0
  209. nullius/prerequisites.py +129 -0
  210. nullius/prices.py +283 -0
  211. nullius/progress.py +294 -0
  212. nullius/providers.py +335 -0
  213. nullius/recipes/__init__.py +0 -0
  214. nullius/recipes/launch.py +78 -0
  215. nullius/redact.py +72 -0
  216. nullius/runs/__init__.py +0 -0
  217. nullius/runs/artifacts.py +67 -0
  218. nullius/runs/classify.py +216 -0
  219. nullius/runs/cli.py +316 -0
  220. nullius/runs/feasibility.py +442 -0
  221. nullius/runs/launches.py +149 -0
  222. nullius/runs/live.py +715 -0
  223. nullius/runs/parse.py +1016 -0
  224. nullius/runs/verifier.py +241 -0
  225. nullius/sandbox.py +109 -0
  226. nullius/secrets.py +218 -0
  227. nullius/settings.py +544 -0
  228. nullius/standard/__init__.py +15 -0
  229. nullius/standard/acp.py +305 -0
  230. nullius/standard/cancellation.py +19 -0
  231. nullius/standard/cli.py +703 -0
  232. nullius/standard/conform.py +149 -0
  233. nullius/standard/container.py +1870 -0
  234. nullius/standard/definitions.py +1651 -0
  235. nullius/standard/egress.py +192 -0
  236. nullius/standard/fidelity.py +256 -0
  237. nullius/standard/forward.py +139 -0
  238. nullius/standard/hostreq.py +105 -0
  239. nullius/standard/howto.py +220 -0
  240. nullius/standard/install.py +428 -0
  241. nullius/standard/job.py +551 -0
  242. nullius/standard/jsonl.py +129 -0
  243. nullius/standard/kits/agent-conversation-v1/driver.py +27 -0
  244. nullius/standard/kits/agent-conversation-v1/standard.json +26 -0
  245. nullius/standard/kits/agent-search-v1/driver.py +171 -0
  246. nullius/standard/kits/agent-search-v1/standard.json +99 -0
  247. nullius/standard/kits/agent-task-v1/driver.py +25 -0
  248. nullius/standard/kits/agent-task-v1/standard.json +100 -0
  249. nullius/standard/kits/agent-tools-v1/driver.py +206 -0
  250. nullius/standard/kits/agent-tools-v1/mcp_kit.py +209 -0
  251. nullius/standard/kits/agent-tools-v1/standard.json +119 -0
  252. nullius/standard/kits/agent-workspace-v1/driver.py +65 -0
  253. nullius/standard/kits/agent-workspace-v1/standard.json +95 -0
  254. nullius/standard/kits/cap-memory-v1/driver.py +39 -0
  255. nullius/standard/kits/cap-memory-v1/standard.json +91 -0
  256. nullius/standard/ledger.py +326 -0
  257. nullius/standard/match.py +66 -0
  258. nullius/standard/mcp_bridge.py +62 -0
  259. nullius/standard/mcp_machine.py +193 -0
  260. nullius/standard/merge.py +239 -0
  261. nullius/standard/names.py +37 -0
  262. nullius/standard/network_requirements.py +44 -0
  263. nullius/standard/pace.py +53 -0
  264. nullius/standard/payload.py +278 -0
  265. nullius/standard/pins.py +130 -0
  266. nullius/standard/ports.py +70 -0
  267. nullius/standard/prove.py +373 -0
  268. nullius/standard/recipe.py +746 -0
  269. nullius/standard/relay.py +785 -0
  270. nullius/standard/run.py +1781 -0
  271. nullius/standard/setup_container.py +208 -0
  272. nullius/standard/shard.py +71 -0
  273. nullius/standard/web_services.py +30 -0
  274. nullius/traces/__init__.py +0 -0
  275. nullius/traces/behavior.py +131 -0
  276. nullius/traces/charts.py +898 -0
  277. nullius/traces/conversation.py +159 -0
  278. nullius/traces/otel.py +608 -0
  279. nullius/traces/trace.py +1477 -0
  280. nullius/traces/trajectory.py +586 -0
  281. nullius/workspace.py +417 -0
  282. nullius/workspace_cli.py +119 -0
  283. nullius_eval-0.1.0.dist-info/METADATA +93 -0
  284. nullius_eval-0.1.0.dist-info/RECORD +291 -0
  285. nullius_eval-0.1.0.dist-info/WHEEL +5 -0
  286. nullius_eval-0.1.0.dist-info/entry_points.txt +2 -0
  287. nullius_eval-0.1.0.dist-info/licenses/LICENSE +202 -0
  288. nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/dmsans-OFL.txt +93 -0
  289. nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/ibmplexmono-OFL.txt +93 -0
  290. nullius_eval-0.1.0.dist-info/licenses/app/static/fonts/instrumentserif-OFL.txt +93 -0
  291. nullius_eval-0.1.0.dist-info/top_level.txt +2 -0
nullius/onboarding.py ADDED
@@ -0,0 +1,116 @@
1
+ """Getting started: the checklist a person is guided through on a first open.
2
+
3
+ Five sections, each a page of the application and its sub-tasks. A sub-task
4
+ is done by a fact this machine can check (``fact``: a key set, a run on disk,
5
+ a trial judged) or, where nothing on disk records it, by the person having
6
+ been on the page that does it (``visit``: a path pattern the browser matches
7
+ and remembers). Nothing here is stored: the facts are read on each ask, and
8
+ the visits stay in the browser that made them.
9
+
10
+ ``target`` says where on a page the thing to do is, so the guide can point at
11
+ it: a list of (CSS selector, label) tried in order on the page the person is
12
+ on; when none is there, the guide opens ``page`` and tries again.
13
+ """
14
+ from __future__ import annotations
15
+
16
+ import os
17
+ import shutil
18
+ import subprocess
19
+ from typing import Callable, Iterable, Optional
20
+
21
+ from nullius import providers
22
+ from nullius.standard import container
23
+
24
+ CONTROLS = ("nop", "oracle")
25
+ PROVIDER_KEYS = ("OPENROUTER_API_KEY", "OPENAI_API_KEY", "MODEL_API_URL")
26
+
27
+ SECTIONS = [
28
+ {"id": "setup", "name": "Set up", "page": "settings_page", "where": "Settings", "subs": [
29
+ {"id": "provider", "text": "Add a model provider key", "fact": "provider",
30
+ "target": [["#providers", "Add a key for one provider"]]},
31
+ {"id": "where", "text": "Choose where runs happen", "fact": "where",
32
+ "target": [["#hosts", "Add a host, or run on this machine with Docker or Podman"]]},
33
+ {"id": "judge", "text": "Pick a judge", "fact": "judge", "optional": True,
34
+ "target": [["#judge", "Choose System One or an LLM judge"]]},
35
+ ]},
36
+ {"id": "bench", "name": "Pick a benchmark", "page": "benchmarks_page", "where": "Benchmarks", "subs": [
37
+ {"id": "browse", "text": "Browse the catalogue", "visit": r"^/benchmarks/?$",
38
+ "target": [[".bench-filters, #bench-find", "Filter by category, runner or origin"]]},
39
+ {"id": "open", "text": "Open a benchmark's page", "visit": r"^/benchmarks/(?!new)[^/]+$",
40
+ "target": [[".bench-card", "Open a benchmark"]]},
41
+ ]},
42
+ {"id": "check", "name": "Free check run", "page": "new_run", "where": "Run builder", "subs": [
43
+ {"id": "builder", "text": "Open the run builder", "visit": r"^/new-run/?$",
44
+ "target": [[".nb-steps", "Start at Benchmark, then each step in turn"]]},
45
+ {"id": "control", "text": "Run oracle and nop on a few tasks", "fact": "control_run",
46
+ "target": [[".nb-steps", "At the Agent step, add oracle and nop: no model, no cost"]]},
47
+ ]},
48
+ {"id": "read", "name": "Read the result", "page": "index", "where": "Runs", "subs": [
49
+ {"id": "job", "text": "Open a job", "visit": r"^/job/[^/]+$",
50
+ "target": [["main table tbody tr a[href*='/job/']", "Open a job"]]},
51
+ {"id": "trial", "text": "Open a trial and its trace", "visit": r"^/trial/[^/]+/[^/]+$",
52
+ "target": [["tr[data-outcome] a[href*='/trial/']", "Open a trial"],
53
+ ["main table tbody tr a[href*='/job/']", "Open a job, then one of its trials"]]},
54
+ {"id": "judged", "text": "Ask a judge about a trial", "fact": "judged", "optional": True,
55
+ "target": [["[id^='judge-all'], #judgement", "Judge the trials"],
56
+ ["main table tbody tr a[href*='/job/']", "Open a job to judge its trials"]]},
57
+ ]},
58
+ {"id": "compare", "name": "Run an agent and compare", "page": "compare", "where": "Compare", "subs": [
59
+ {"id": "agent", "text": "Run an agent on the same tasks", "fact": "agent_run", "page": "new_run",
60
+ "target": [[".nb-steps", "The same benchmark, then an agent at the Agent step"]]},
61
+ {"id": "compared", "text": "Compare two runs", "visit": r"^/compare/?\?(.*&)?pick=",
62
+ "target": [["main form, main table", "Pick two runs on the same tasks"]]},
63
+ ]},
64
+ ]
65
+
66
+
67
+ def docker_answers(timeout: float = 5.0) -> bool:
68
+ """Whether the container backend's engine (``container.DOCKER``: docker, or
69
+ podman) can run a container here: the command *and* ``<engine> ps``
70
+ answering. The command alone is not enough - Docker Desktop's WSL
71
+ integration leaves ``/usr/bin/docker`` in place while its engine is quit."""
72
+ if not shutil.which(container.DOCKER):
73
+ return False
74
+ try:
75
+ return subprocess.run([container.DOCKER, "ps"], capture_output=True, timeout=timeout, stdin=subprocess.DEVNULL).returncode == 0
76
+ except (OSError, subprocess.TimeoutExpired):
77
+ return False
78
+
79
+
80
+ def facts(env, jobs: Iterable[dict] = (), judged: bool = False, docker: Optional[Callable] = None) -> dict:
81
+ """What this machine says is done: ``env`` the settings Nullius reads,
82
+ ``jobs`` the open workspace's job index entries (each with its ``agent``),
83
+ ``judged`` whether any of its trials holds a judgement."""
84
+ from nullius.judge import client
85
+ agents = [(j.get("agent") or "").lower() for j in jobs]
86
+ found = (docker or docker_answers)()
87
+ return {
88
+ "provider": any((env.get(k) or "").strip() for k in PROVIDER_KEYS) or bool(providers.endpoints(env)),
89
+ "where": bool((env.get("HOSTS") or "").strip()) or found,
90
+ "judge": bool(client.system_one(env)) or bool(client.llm_judge(env)),
91
+ "control_run": any(a in CONTROLS for a in agents),
92
+ "agent_run": any(a and a not in CONTROLS for a in agents),
93
+ "judged": bool(judged),
94
+ }
95
+
96
+
97
+ def any_judged(ws_dir: Optional[str]) -> bool:
98
+ """Whether a workspace holds a judgement from either judge."""
99
+ from nullius.judge import store
100
+ for lane in store.ROOTS.values():
101
+ root = os.path.join(ws_dir or "", lane)
102
+ if ws_dir and os.path.isdir(root) and any(files for _, _, files in os.walk(root)):
103
+ return True
104
+ return False
105
+
106
+
107
+ def checklist(found: dict, url_for: Callable) -> list:
108
+ """The sections for the guide, each sub-task with ``done`` set from a
109
+ fact (True/False) or left None for the browser to settle by its visits."""
110
+ out = []
111
+ for s in SECTIONS:
112
+ subs = [{"id": x["id"], "text": x["text"], "optional": x.get("optional", False),
113
+ "done": bool(found.get(x["fact"])) if "fact" in x else None, "visit": x.get("visit"),
114
+ "url": url_for(x.get("page", s["page"])), "target": x["target"]} for x in s["subs"]]
115
+ out.append({"id": s["id"], "name": s["name"], "where": s["where"], "url": url_for(s["page"]), "subs": subs})
116
+ return out
nullius/paths.py ADDED
@@ -0,0 +1,89 @@
1
+ """Persistent per-user locations, independent of the installation or cwd.
2
+
3
+ NULLIUS_HOME gives a self-contained config/data/cache tree for a separate
4
+ profile. Otherwise use XDG locations on Unix and native user locations on
5
+ Windows/macOS. Merely resolving a path creates nothing.
6
+ """
7
+ from __future__ import annotations
8
+
9
+ import argparse
10
+ import json
11
+ import os
12
+ import sys
13
+
14
+
15
+ def _directory(kind: str, env=None) -> str:
16
+ env = os.environ if env is None else env
17
+ if env.get("NULLIUS_HOME"):
18
+ return os.path.join(os.path.abspath(os.path.expanduser(env["NULLIUS_HOME"])), kind)
19
+ variable = {"config": "XDG_CONFIG_HOME", "data": "XDG_DATA_HOME", "cache": "XDG_CACHE_HOME"}[kind]
20
+ explicit = env.get(variable, "")
21
+ if explicit and os.path.isabs(explicit):
22
+ return os.path.join(explicit, "nullius")
23
+ home = os.path.expanduser("~")
24
+ if sys.platform == "win32":
25
+ return os.path.join(env.get("LOCALAPPDATA") or os.path.join(home, "AppData", "Local"), "Nullius", kind)
26
+ if sys.platform == "darwin":
27
+ base = "Caches" if kind == "cache" else "Application Support"
28
+ return os.path.join(home, "Library", base, "Nullius", *([] if kind == "cache" else [kind]))
29
+ base = {"config": ".config", "data": os.path.join(".local", "share"), "cache": ".cache"}[kind]
30
+ return os.path.join(home, base, "nullius")
31
+
32
+
33
+ def config_dir(env=None) -> str:
34
+ return _directory("config", env)
35
+
36
+
37
+ def data_dir(env=None) -> str:
38
+ return _directory("data", env)
39
+
40
+
41
+ def cache_dir(env=None) -> str:
42
+ return _directory("cache", env)
43
+
44
+
45
+ def settings_file(env=None) -> str:
46
+ return os.path.join(config_dir(env), "settings.json")
47
+
48
+
49
+ def prices_file(env=None) -> str:
50
+ env = os.environ if env is None else env
51
+ return env.get("NULLIUS_PRICES") or os.path.join(config_dir(env), "prices.json")
52
+
53
+
54
+ def catalogue_dir(env=None) -> str:
55
+ env = os.environ if env is None else env
56
+ return env.get("NULLIUS_CATALOGUE") or os.path.join(data_dir(env), "catalogue")
57
+
58
+
59
+ def workspaces_dir(env=None) -> str:
60
+ env = os.environ if env is None else env
61
+ return env.get("WORKSPACES_DIR") or os.path.join(data_dir(env), "workspaces")
62
+
63
+
64
+ def runs_dir(env=None) -> str:
65
+ env = os.environ if env is None else env
66
+ return env.get("RUNS_DIR") or os.path.join(data_dir(env), "runs")
67
+
68
+
69
+ def secrets_dir(env=None) -> str:
70
+ env = os.environ if env is None else env
71
+ return env.get("SECRETS_DIR") or os.path.join(config_dir(env), "secrets")
72
+
73
+
74
+ def main(argv=None) -> int:
75
+ parser = argparse.ArgumentParser(description="Show Nullius's persistent user directories (no secret values).")
76
+ parser.add_argument("--json", action="store_true")
77
+ args = parser.parse_args(argv)
78
+ values = {"settings": settings_file(), "secrets": secrets_dir(), "prices": prices_file(), "catalogue": catalogue_dir(),
79
+ "workspaces": workspaces_dir(), "runs": runs_dir(), "cache": cache_dir()}
80
+ if args.json:
81
+ print(json.dumps(values, indent=2))
82
+ else:
83
+ for name, path in values.items():
84
+ print(f"{name}: {path}")
85
+ return 0
86
+
87
+
88
+ if __name__ == "__main__":
89
+ raise SystemExit(main())
@@ -0,0 +1,129 @@
1
+ """What a run needs of the machine it runs on, and whether that machine has it.
2
+
3
+ The builder's Review step asks before Run (``/new-run/prerequisites``,
4
+ ``web/builder.py``): one row per need, and Run waits until every row is
5
+ ready. A run asks again as it starts (``execution.py``), because a machine
6
+ can change between the two - docker quit, a program removed.
7
+
8
+ A need is one of:
9
+
10
+ - ``engine``: the standard's container backend's engine (``container.DOCKER``:
11
+ docker, or podman) on PATH **and** answering this user - Docker Desktop's
12
+ placeholder command, there while the engine is quit, is not docker. Its row also says when
13
+ the engine has ``userns-remap``, which the standard's containers run outside of;
14
+ - ``docker``: the same, for Harbor, which runs the docker program;
15
+ - ``uv``: on a host it is installed when missing, here it must be there (a
16
+ pinned Harbor runs through ``uvx``, a runner's install builds with it);
17
+ - ``harbor``: a recipe from before the pin runs the ``harbor`` on PATH;
18
+ - ``python3``, ``git``: the standard's cli, on a host;
19
+ - a benchmark's machine setup (``host`` in its definition): its programs,
20
+ optional GPU memory minimum, and the commands that install them.
21
+
22
+ Nothing here installs anything or writes anything: each check is
23
+ ``command -v``, the engine's ``version`` and, when needed, ``nvidia-smi`` here,
24
+ or one ssh probe for a host (``hosts.test``). Remote GPU memory is checked
25
+ by the run as it starts there.
26
+ """
27
+ from __future__ import annotations
28
+
29
+ import shutil
30
+ import time
31
+ from typing import Callable, Dict, List, Optional
32
+
33
+ from nullius import hosts
34
+ from nullius.standard import container, hostreq
35
+
36
+ LABEL = {"engine": "Docker or Podman", "docker": "Docker", "uv": "uv", "harbor": "Harbor on PATH", "python3": "python3", "git": "git"}
37
+
38
+ # the docker row's detail for the standard on an engine with userns-remap (container.userns_remap)
39
+ REMAPPED = "the engine answers, and Nullius's containers run outside its userns-remap"
40
+
41
+ # Whether the engine answers here, asked at most once a minute: the builder asks on each preview.
42
+ _HERE = {"at": 0.0, "why": None}
43
+
44
+
45
+ def docker_here(fresh: bool = False) -> Optional[str]:
46
+ """Why the container backend's engine (``container.DOCKER``) cannot run
47
+ containers on this machine for this user, or None when it can: the
48
+ engine asked, not only the command looked for.
49
+ Kept for a minute unless ``fresh``."""
50
+ if fresh or time.monotonic() - _HERE["at"] > 60:
51
+ _HERE.update(at=time.monotonic(), why=container.unusable())
52
+ return _HERE["why"]
53
+
54
+
55
+ def row(name: str, state: str, detail: str = "", install: Optional[List[str]] = None, label: str = "") -> dict:
56
+ """One need: ``state`` ok, missing (Run waits) or install (the run puts it there)."""
57
+ return {"name": name, "label": label or LABEL.get(name, name), "state": state, "detail": detail, "install": install or []}
58
+
59
+
60
+ def check_here(needs: List[str], setups: Optional[Dict[str, dict]] = None, *, standard: bool = False,
61
+ which: Optional[Callable] = None, docker: Optional[Callable] = None,
62
+ remap: Optional[Callable] = None) -> List[dict]:
63
+ """The rows for this machine. ``setups``: a benchmark's machine setups by
64
+ name, each ``{summary, check: [programs], install: [commands]}``, with an
65
+ optional ``gpu_memory_mb`` minimum. ``standard``: the recipe is the
66
+ standard's, whose containers Nullius starts. ``which``, ``docker`` and
67
+ ``remap`` are looked up at call time, so a test can stand in for them."""
68
+ which = which or shutil.which
69
+ docker = docker or docker_here
70
+ remap = remap or container.userns_remap
71
+ rows = []
72
+ for n in needs:
73
+ if n in ("engine", "docker"):
74
+ why = docker()
75
+ if not why and n == "docker" and not which("docker"):
76
+ why = "Install Docker on this machine: Harbor runs the docker program"
77
+ rows.append(row(n, "missing", why) if why else
78
+ row(n, "ok", REMAPPED if standard and remap() else "the engine answers"))
79
+ elif n == "uv":
80
+ rows.append(row(n, "ok") if which("uvx") else row(n, "missing", "uv is not on this machine's PATH", ["curl -LsSf https://astral.sh/uv/install.sh | sh"]))
81
+ elif n == "harbor":
82
+ rows.append(row(n, "ok") if which("harbor") else row(n, "missing", "a recipe from before the pin runs the harbor on PATH: pin a Harbor on the Harbor step"))
83
+ else:
84
+ rows.append(row(n, "ok") if which(n) else row(n, "missing", f"{n} is not on this machine's PATH"))
85
+ lacking = hostreq.problems({"host": setups or {}}, list(setups or {}), which)
86
+ for name, s in (setups or {}).items():
87
+ rows.append(row("setup:" + name, "missing", lacking[name], s.get("install"), label=name)
88
+ if name in lacking else row("setup:" + name, "ok", s.get("summary", ""), label=name))
89
+ return rows
90
+
91
+
92
+ def check_host(host: hosts.Host, needs: List[str], setups: Optional[Dict[str, dict]] = None, *,
93
+ standard: bool = False, test: Optional[Callable] = None) -> List[dict]:
94
+ """The rows for a host, from one ssh probe. Unreachable: one row, and nothing else is known."""
95
+ test = test or hosts.test
96
+ programs = [p for s in (setups or {}).values() for p in s.get("check") or []]
97
+ programs += [n for n in needs if n in ("python3", "git")]
98
+ got = test(host, programs=programs)
99
+ if not got["ok"]:
100
+ return [row("connect", "missing", got.get("error") or "no answer", label="Connection")]
101
+ gone = set(got.get("missing") or [])
102
+ rows = [row("connect", "ok", got.get("hostname") or host.label, label="Connection")]
103
+ for n in needs:
104
+ if n == "engine" and got["engine"] != "docker":
105
+ rows.append(row(n, "missing", "neither docker nor podman is on the host") if not got["engine"]
106
+ else row(n, "missing", "podman is on the host but this user cannot use it (podman ps failed)")
107
+ if got["podman_ok"] is False else row(n, "ok", "the engine answers"))
108
+ elif n in ("engine", "docker"):
109
+ rows.append(row(n, "missing", "docker is not on the host") if not got["docker"]
110
+ else row(n, "missing", "docker is on the host but this user cannot use it (docker ps failed): "
111
+ "add the user to the docker group there, then log in again") if got["docker_ok"] is False
112
+ else row(n, "ok", REMAPPED if standard and got.get("docker_userns") else "the engine answers"))
113
+ elif n == "uv":
114
+ rows.append(row(n, "ok") if got["uv"] else row(n, "install", "installed on the host when the run starts"))
115
+ elif n == "harbor":
116
+ rows.append(row(n, "ok", got.get("harbor_version") or "") if got["harbor"]
117
+ else row(n, "missing", "a recipe from before the pin runs the harbor on the host's PATH: pin a Harbor on the Harbor step"))
118
+ else:
119
+ rows.append(row(n, "missing", f"{n} is not on the host's PATH") if n in gone else row(n, "ok"))
120
+ for name, s in (setups or {}).items():
121
+ lacking = [p for p in s.get("check") or [] if p in gone]
122
+ rows.append(row("setup:" + name, "missing", ", ".join(lacking) + " not on PATH", s.get("install"), label=name)
123
+ if lacking else row("setup:" + name, "ok", s.get("summary", ""), label=name))
124
+ return rows
125
+
126
+
127
+ def ready(machines: List[dict]) -> bool:
128
+ """Whether Run may go: no row of any machine is missing."""
129
+ return all(r["state"] != "missing" for m in machines for r in m["rows"])
nullius/prices.py ADDED
@@ -0,0 +1,283 @@
1
+ """Model prices, the user's own: what a call's cost is estimated from when
2
+ the provider's reply does not carry one.
3
+
4
+ Nullius ships no price. The list lives in one file of the user's
5
+ configuration, ``prices.json`` (``NULLIUS_PRICES`` names another: the file a
6
+ host is sent), in two parts:
7
+
8
+ ``models`` a public list, fetched on request (``update``) and kept whole
9
+ with where it came from and when: LiteLLM's
10
+ ``model_prices_and_context_window.json``, keyed by the model
11
+ names the providers themselves use
12
+ ``own`` the user's rows, which win over the list: a price it lacks, a
13
+ negotiated one, a model served under a name of one's own
14
+
15
+ A row is USD per million tokens: ``input`` and ``output``, optionally
16
+ ``cached`` (input a cache served), ``cache_write``, ``cache_write_1h``, and ``max_output``,
17
+ the model's output limit in tokens. A model is priced by exactly its name or
18
+ not at all: a name that only starts like another's is another model.
19
+
20
+ Nothing here runs during a run: a run reads the file, never the network.
21
+
22
+ nullius prices # where the list came from, how many models, the user's own rows
23
+ nullius prices list MODEL ... # those models' rows
24
+ nullius prices update [--from URL-or-file]
25
+ nullius prices set MODEL INPUT OUTPUT [--cached X] [--cache-write X] [--cache-write-1h X] [--max-output N]
26
+ nullius prices remove MODEL
27
+ """
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import json
32
+ import os
33
+ import time
34
+ import urllib.request
35
+ from typing import Callable, Dict, Iterable, Optional, Tuple
36
+
37
+ from nullius import paths
38
+
39
+ SOURCE = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json"
40
+ RATES = ("input", "output", "cached", "cache_write", "cache_write_1h") # USD per million tokens
41
+ _LISTED = {"input": "input_cost_per_token", "output": "output_cost_per_token",
42
+ "cached": "cache_read_input_token_cost", "cache_write": "cache_creation_input_token_cost",
43
+ "cache_write_1h": "cache_creation_input_token_cost_above_1hr"}
44
+ _MOST = 64 * 1024 * 1024 # a list larger than this is not a price list
45
+
46
+
47
+ def path(env=None) -> str:
48
+ return paths.prices_file(env)
49
+
50
+
51
+ def load(env=None) -> dict:
52
+ """The file as ``{from, on, models, own}``; missing or unreadable, empty:
53
+ no price is better than a run that cannot start for its price list."""
54
+ doc = {"from": "", "on": "", "models": {}, "own": {}}
55
+ try:
56
+ with open(path(env), encoding="utf-8") as f:
57
+ got = json.load(f)
58
+ except (OSError, ValueError):
59
+ return doc
60
+ if isinstance(got, dict):
61
+ for k in ("from", "on"):
62
+ if isinstance(got.get(k), str):
63
+ doc[k] = got[k]
64
+ for k in ("models", "own"):
65
+ if isinstance(got.get(k), dict):
66
+ doc[k] = {n: r for n, r in got[k].items() if _usable(r)}
67
+ return doc
68
+
69
+
70
+ def _usable(r) -> bool:
71
+ return isinstance(r, dict) and all(_number(r.get(k)) for k in ("input", "output"))
72
+
73
+
74
+ def _number(v) -> bool:
75
+ return isinstance(v, (int, float)) and not isinstance(v, bool) and v >= 0
76
+
77
+
78
+ def save(doc: dict, env=None) -> None:
79
+ """Written whole beside the file, then renamed: a reader never finds half a list."""
80
+ out = path(env)
81
+ os.makedirs(os.path.dirname(out) or ".", exist_ok=True)
82
+ part = f"{out}.{os.getpid()}.part"
83
+ with open(part, "w", encoding="utf-8") as f:
84
+ json.dump(doc, f, indent=1, sort_keys=True)
85
+ f.write("\n")
86
+ os.replace(part, out)
87
+
88
+
89
+ def table(env=None) -> Dict[str, dict]:
90
+ """Every priced model: the list, then the user's own rows over it."""
91
+ doc = load(env)
92
+ return {**doc["models"], **doc["own"]}
93
+
94
+
95
+ def given(names: Iterable[Optional[str]], prices: Optional[Dict[str, dict]]) -> Dict[str, dict]:
96
+ """The rows of ``prices`` for exactly ``names``: what a relay started as
97
+ a process of its own is handed, which cannot take the whole list."""
98
+ prices = prices or {}
99
+ return {n: prices[n] for n in dict.fromkeys(n for n in names if n) if n in prices}
100
+
101
+
102
+ def row(input, output, cached=None, cache_write=None, max_output=None, *, cache_write_1h=None) -> dict:
103
+ """One row, checked: rates are numbers not below zero, the limit a whole number above it."""
104
+ out = {}
105
+ for name, v in (("input", input), ("output", output), ("cached", cached), ("cache_write", cache_write), ("cache_write_1h", cache_write_1h)):
106
+ if v is None:
107
+ continue
108
+ try:
109
+ v = float(v)
110
+ except (TypeError, ValueError):
111
+ raise ValueError(f"{name}: a price in USD per million tokens, not {v!r}")
112
+ if not v >= 0 or v == float("inf"):
113
+ raise ValueError(f"{name}: a price in USD per million tokens, not {v!r}")
114
+ out[name] = v
115
+ if max_output is not None:
116
+ try:
117
+ n = int(max_output)
118
+ except (TypeError, ValueError):
119
+ n = 0
120
+ if n <= 0:
121
+ raise ValueError(f"max_output: the model's output limit in tokens, not {max_output!r}")
122
+ out["max_output"] = n
123
+ return out
124
+
125
+
126
+ def parse(text: str) -> Tuple[str, dict]:
127
+ """``MODEL=INPUT,OUTPUT[,CACHED,WRITE,WRITE_1H]``, a run's ``--price``.
128
+ Optional rates may be left empty; existing two/three-rate rows keep their meaning."""
129
+ name, eq, rest = str(text).partition("=")
130
+ bits = [b.strip() for b in rest.split(",")] if eq else []
131
+ if not name.strip() or not 2 <= len(bits) <= 5 or not all(bits[:2]):
132
+ raise ValueError(f"--price {text!r}: MODEL=INPUT,OUTPUT[,CACHED,WRITE,WRITE_1H], in USD per million tokens")
133
+ try:
134
+ return name.strip(), row(**{k: v or None for k, v in zip(RATES, bits)})
135
+ except ValueError as e:
136
+ raise ValueError(f"--price {text!r}: {e}")
137
+
138
+
139
+ def convert(listing) -> Dict[str, dict]:
140
+ """LiteLLM's list as rows: its costs are per token, a row's per million.
141
+ An entry with no input price is not a priced model (the list's own
142
+ sample, an image model priced per picture) and is left out."""
143
+ if not isinstance(listing, dict):
144
+ raise ValueError("not a price list: a JSON object of models was expected")
145
+ out = {}
146
+ for name, e in listing.items():
147
+ if not isinstance(e, dict) or not _number(e.get(_LISTED["input"])):
148
+ continue
149
+ r = {"input": round(e[_LISTED["input"]] * 1e6, 6),
150
+ "output": round(e[_LISTED["output"]] * 1e6, 6) if _number(e.get(_LISTED["output"])) else 0.0}
151
+ for k in ("cached", "cache_write", "cache_write_1h"):
152
+ if _number(e.get(_LISTED[k])):
153
+ r[k] = round(e[_LISTED[k]] * 1e6, 6)
154
+ limit = e.get("max_output_tokens")
155
+ if isinstance(limit, int) and not isinstance(limit, bool) and limit > 0:
156
+ r["max_output"] = limit
157
+ out[str(name)] = r
158
+ if not out:
159
+ raise ValueError("not a price list: no model in it has a price")
160
+ return out
161
+
162
+
163
+ def _fetch(source: str) -> bytes:
164
+ if source.startswith("https://"):
165
+ req = urllib.request.Request(source, headers={"User-Agent": "nullius"}) # nothing of the user or the machine
166
+ with urllib.request.urlopen(req, timeout=60) as r:
167
+ return r.read(_MOST + 1)
168
+ if "://" in source:
169
+ raise ValueError("only an https address or a file is read")
170
+ with open(source, "rb") as f:
171
+ return f.read(_MOST + 1)
172
+
173
+
174
+ def update(source: Optional[str] = None, env=None, fetch: Optional[Callable[[str], bytes]] = None,
175
+ today: Optional[str] = None) -> dict:
176
+ """The public list fetched and kept in place of the last one; the user's
177
+ own rows are not touched. Nothing is written when the fetch or the list
178
+ is bad: the list held stays. Returns ``{n, from, on}``."""
179
+ source = source or SOURCE
180
+ try:
181
+ raw = (fetch or _fetch)(source)
182
+ except (OSError, ValueError) as e:
183
+ why = e.strerror if isinstance(e, OSError) and e.filename else e # a file's error names the file again
184
+ raise ValueError(f"could not fetch the price list from {source}: {why}")
185
+ if len(raw) > _MOST:
186
+ raise ValueError(f"{source}: too large to be a price list")
187
+ try:
188
+ models = convert(json.loads(raw))
189
+ except ValueError as e:
190
+ raise ValueError(f"{source}: {e}")
191
+ doc = load(env)
192
+ doc.update({"from": source, "on": today or time.strftime("%Y-%m-%d"), "models": models})
193
+ save(doc, env)
194
+ return {"n": len(models), "from": doc["from"], "on": doc["on"]}
195
+
196
+
197
+ def set_own(name: str, r: dict, env=None) -> None:
198
+ name = str(name).strip()
199
+ if not name or not _usable(r):
200
+ raise ValueError("a model's name, and its input and output prices")
201
+ doc = load(env)
202
+ doc["own"][name] = r
203
+ save(doc, env)
204
+
205
+
206
+ def remove_own(name: str, env=None) -> bool:
207
+ doc = load(env)
208
+ if doc["own"].pop(str(name).strip(), None) is None:
209
+ return False
210
+ save(doc, env)
211
+ return True
212
+
213
+
214
+ def state(env=None) -> dict:
215
+ """What Settings shows: how many models the list prices, where it came
216
+ from and when, and the user's own rows."""
217
+ doc = load(env)
218
+ return {"n": len(doc["models"]), "from": doc["from"], "on": doc["on"], "own": doc["own"]}
219
+
220
+
221
+ def said(name: str, r: dict) -> str:
222
+ bits = [f"input {r['input']:g}", f"output {r['output']:g}"]
223
+ bits += [f"{label} {r[k]:g}" for k, label in (("cached", "cached"), ("cache_write", "cache write"),
224
+ ("cache_write_1h", "cache write 1h")) if k in r]
225
+ if "max_output" in r:
226
+ bits.append(f"output limit {r['max_output']}")
227
+ return f"{name}: " + ", ".join(bits)
228
+
229
+
230
+ def main(argv=None) -> int:
231
+ ap = argparse.ArgumentParser(prog="nullius prices",
232
+ description="The user's model prices, in USD per million tokens: what a run's cost is estimated from.")
233
+ sub = ap.add_subparsers(dest="cmd")
234
+ ls = sub.add_parser("list", help="the list's source and size, the user's own rows, and the rows of the models named")
235
+ ls.add_argument("models", nargs="*")
236
+ ls.add_argument("--json", action="store_true")
237
+ up = sub.add_parser("update", help="fetch the public list and keep it; the user's own rows stay")
238
+ up.add_argument("--from", dest="source", metavar="URL-or-file", help=f"another list in the same format (default: {SOURCE})")
239
+ st = sub.add_parser("set", help="a price of the user's own, which wins over the list")
240
+ st.add_argument("model")
241
+ st.add_argument("input")
242
+ st.add_argument("output")
243
+ st.add_argument("--cached")
244
+ st.add_argument("--cache-write")
245
+ st.add_argument("--cache-write-1h")
246
+ st.add_argument("--max-output")
247
+ rm = sub.add_parser("remove", help="remove one of the user's own prices")
248
+ rm.add_argument("model")
249
+ a = ap.parse_args(argv)
250
+ try:
251
+ if a.cmd == "update":
252
+ got = update(a.source)
253
+ print(f"{got['n']} models priced, from {got['from']}")
254
+ return 0
255
+ if a.cmd == "set":
256
+ r = row(a.input, a.output, a.cached, a.cache_write, a.max_output, cache_write_1h=a.cache_write_1h)
257
+ set_own(a.model, r)
258
+ print(said(a.model.strip(), r))
259
+ return 0
260
+ if a.cmd == "remove":
261
+ if not remove_own(a.model):
262
+ ap.exit(1, f"{a.model}: not one of your own prices\n")
263
+ return 0
264
+ except ValueError as e:
265
+ ap.exit(1, f"{e}\n")
266
+ doc, names = load(), list(getattr(a, "models", None) or [])
267
+ both = {**doc["models"], **doc["own"]}
268
+ if getattr(a, "json", False):
269
+ print(json.dumps({"file": path(), "from": doc["from"], "on": doc["on"], "n": len(doc["models"]), "own": doc["own"],
270
+ "models": {n: both.get(n) for n in names}}, indent=2))
271
+ return 0
272
+ print(f"file: {path()}")
273
+ print(f"list: {len(doc['models'])} models, from {doc['from']} on {doc['on']}" if doc["models"]
274
+ else "list: none yet - nullius prices update")
275
+ for n, r in sorted(doc["own"].items()):
276
+ print("own " + said(n, r))
277
+ for n in names:
278
+ print(said(n, both[n]) if n in both else f"{n}: no price")
279
+ return 0
280
+
281
+
282
+ if __name__ == "__main__":
283
+ raise SystemExit(main())