polyctl 0.7.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.
- polyctl/__init__.py +7 -0
- polyctl/__main__.py +5 -0
- polyctl/a2a.py +226 -0
- polyctl/a2a_mcp.py +546 -0
- polyctl/acp.py +417 -0
- polyctl/adapters/README.md +101 -0
- polyctl/adapters/aider.json +32 -0
- polyctl/adapters/amazon-q.json +15 -0
- polyctl/adapters/amp.json +16 -0
- polyctl/adapters/antigravity.json +120 -0
- polyctl/adapters/claude-code.json +229 -0
- polyctl/adapters/cloud-generic.json +57 -0
- polyctl/adapters/codex.json +47 -0
- polyctl/adapters/command-code.json +45 -0
- polyctl/adapters/copilot.json +17 -0
- polyctl/adapters/cursor-agent.json +29 -0
- polyctl/adapters/deepseek.json +13 -0
- polyctl/adapters/droid.json +34 -0
- polyctl/adapters/gemini.json +30 -0
- polyctl/adapters/grok.json +22 -0
- polyctl/adapters/hermes.json +34 -0
- polyctl/adapters/kilocode.json +30 -0
- polyctl/adapters/kimi.json +23 -0
- polyctl/adapters/kiro.json +332 -0
- polyctl/adapters/ollama.json +29 -0
- polyctl/adapters/omp.json +34 -0
- polyctl/adapters/openai-api.json +68 -0
- polyctl/adapters/opencode.json +162 -0
- polyctl/adapters/pi.json +24 -0
- polyctl/adapters/pr-agent.json +54 -0
- polyctl/adapters/profiles.json +9 -0
- polyctl/adapters/qoder.json +163 -0
- polyctl/adapters/qwen.json +27 -0
- polyctl/adapters/reasonix.json +25 -0
- polyctl/adapters/rewriters/rtk.json +24 -0
- polyctl/adapters/trae.json +31 -0
- polyctl/adapters/vendors.json +42 -0
- polyctl/adapters/warp.json +88 -0
- polyctl/allowlist.py +1756 -0
- polyctl/api_review.py +920 -0
- polyctl/cli.py +835 -0
- polyctl/conformance_harness.py +9 -0
- polyctl/demo.py +503 -0
- polyctl/drivers.py +146 -0
- polyctl/email.py +160 -0
- polyctl/features.py +98 -0
- polyctl/journal.py +144 -0
- polyctl/language.py +945 -0
- polyctl/lib.py +1296 -0
- polyctl/matrix.py +660 -0
- polyctl/mcp.py +1362 -0
- polyctl/ntfy.py +169 -0
- polyctl/outbound.py +39 -0
- polyctl/parts/__init__.py +5 -0
- polyctl/parts/cli_authority.py +2615 -0
- polyctl/parts/cli_channels.py +1325 -0
- polyctl/parts/cli_checks.py +2293 -0
- polyctl/parts/cli_completion.py +686 -0
- polyctl/parts/cli_evidence.py +141 -0
- polyctl/parts/cli_gain.py +375 -0
- polyctl/parts/cli_harness.py +392 -0
- polyctl/parts/cli_hooks.py +1816 -0
- polyctl/parts/cli_install.py +638 -0
- polyctl/parts/cli_lanes.py +106 -0
- polyctl/parts/cli_maintenance.py +2536 -0
- polyctl/parts/cli_next.py +248 -0
- polyctl/parts/cli_pr.py +53 -0
- polyctl/parts/cli_project.py +2857 -0
- polyctl/parts/cli_review.py +5158 -0
- polyctl/parts/cli_status.py +898 -0
- polyctl/parts/lib_adapters.py +2933 -0
- polyctl/parts/lib_alarms.py +2106 -0
- polyctl/parts/lib_events.py +224 -0
- polyctl/parts/lib_evidence.py +412 -0
- polyctl/parts/lib_gates.py +2099 -0
- polyctl/parts/lib_lanes.py +829 -0
- polyctl/parts/lib_mail.py +1541 -0
- polyctl/parts/lib_next.py +652 -0
- polyctl/parts/lib_pr.py +331 -0
- polyctl/parts/lib_slices.py +3337 -0
- polyctl/parts/lib_state.py +2415 -0
- polyctl/parts/lib_transcript.py +4118 -0
- polyctl/pressure.py +325 -0
- polyctl/prices.json +47 -0
- polyctl/procs.py +1194 -0
- polyctl/settings.py +505 -0
- polyctl/skill/SKILL.md +365 -0
- polyctl/skillkit.py +503 -0
- polyctl/storage.py +2055 -0
- polyctl/telegram.py +327 -0
- polyctl/tiers.py +123 -0
- polyctl/verdicts.py +41 -0
- polyctl/watchdog.py +3887 -0
- polyctl/web.py +337 -0
- polyctl-0.7.0.dist-info/METADATA +235 -0
- polyctl-0.7.0.dist-info/RECORD +99 -0
- polyctl-0.7.0.dist-info/WHEEL +4 -0
- polyctl-0.7.0.dist-info/entry_points.txt +5 -0
- polyctl-0.7.0.dist-info/licenses/LICENSE +21 -0
polyctl/pressure.py
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"""How hard the machine is pressed, read before heavy work starts (MACHINE-PRESSURE).
|
|
2
|
+
|
|
3
|
+
Five test suites at once swap a laptop into uselessness while each one looks reasonable on its own, and a machine in
|
|
4
|
+
that state appears hung, which is the most expensive kind of confusion to debug. The machine gate lock keeps polyctl's own
|
|
5
|
+
suites apart; what else loads the machine - a container build, an indexer, a suite run outside polyctl - it cannot see. So
|
|
6
|
+
a gate run and `polyctl lock -- <command>`, once they hold the lock, and `polyctl lane start`, before it makes anything, read
|
|
7
|
+
three figures, each against a machine setting, and wait while one is past its limit rather than thrash:
|
|
8
|
+
|
|
9
|
+
- memory free, in percent: on macOS the system-wide free percentage `memory_pressure` prints, the figure the kernel
|
|
10
|
+
acts on - one worked out from vm_stat's page counts read 1.1 GB free on a machine the system called 47% free, and
|
|
11
|
+
nearly stopped a healthy batch; on Linux MemAvailable over MemTotal, from /proc/meminfo.
|
|
12
|
+
- swap-ins a second: the lower median of four back-to-back one-second samples of the swap-in counter, vm_stat's
|
|
13
|
+
Swapins on macOS and pswpin in /proc/vmstat on Linux. Paging spikes by an order of magnitude for a second whenever
|
|
14
|
+
anything starts: four samples of an idle machine read 96, 185, 237 and 1482, and the mean of a window holding the
|
|
15
|
+
last closed the gate on a machine with 49% of its memory free. The median lets one burst pass and still catches
|
|
16
|
+
sustained thrash, which runs in the thousands; idle to busy stays under 200.
|
|
17
|
+
- disk free on the volume that holds the home, in GiB, never `/`: on macOS `/` is the sealed system volume and reads
|
|
18
|
+
100% full when all is well. Three agents once failed within minutes of each other on a full disk while memory read
|
|
19
|
+
40% free and paging 12 a second, and what they saw read like ordinary test failures.
|
|
20
|
+
|
|
21
|
+
Swap used is never read. macOS keeps a swap file after the pressure that grew it has passed, so an idle machine reads
|
|
22
|
+
93% used, and a gate on it is red for ever - a gate everyone learns to ignore, which is worse than none.
|
|
23
|
+
|
|
24
|
+
On Windows, and wherever a figure cannot be read, it is "not measured": said once, and never a refusal on its
|
|
25
|
+
account. `read` is the one place a command reads the machine through; the real reading samples paging for four
|
|
26
|
+
seconds, and the test suite puts a calm machine there (tests/conftest.py). Standard library only.
|
|
27
|
+
"""
|
|
28
|
+
import os
|
|
29
|
+
import re
|
|
30
|
+
import subprocess
|
|
31
|
+
import sys
|
|
32
|
+
import time
|
|
33
|
+
from collections import namedtuple
|
|
34
|
+
|
|
35
|
+
UTF8 = "utf-8" # every text file polyctl writes or reads; Windows would otherwise use cp1252
|
|
36
|
+
|
|
37
|
+
# The swap-in counter is read SAMPLES + 1 times, SAMPLE_SECONDS apart; the rate is the lower median of the rises.
|
|
38
|
+
SAMPLES = 4
|
|
39
|
+
SAMPLE_SECONDS = 1
|
|
40
|
+
# Between two readings while a command waits for the machine to have room again.
|
|
41
|
+
RECHECK_SECONDS = 10
|
|
42
|
+
# What memory_pressure or vm_stat may take to answer before its figure is not measured.
|
|
43
|
+
PROGRAM_SECONDS = 10
|
|
44
|
+
GIB = float(1 << 30)
|
|
45
|
+
# Where Linux keeps the figures; a test points these at files of its own.
|
|
46
|
+
MEMINFO = "/proc/meminfo"
|
|
47
|
+
VMSTAT = "/proc/vmstat"
|
|
48
|
+
|
|
49
|
+
# The machine setting each figure is held to (src/polyctl/settings.py).
|
|
50
|
+
MEMORY_FLOOR = "limits.refuse_below_free_memory_pct"
|
|
51
|
+
PAGING_CEILING = "limits.refuse_above_swapins_per_sec"
|
|
52
|
+
DISK_FLOOR = "limits.refuse_below_free_disk_gib"
|
|
53
|
+
ELSEWHERE = "polyctl reads it on macOS and Linux"
|
|
54
|
+
|
|
55
|
+
# One reading. A figure is None where it was not measured, and `unmeasured` holds (what, why) for each such figure,
|
|
56
|
+
# or ("machine", why) when nothing was read at all; `swapin_samples` are the one-second rates the median came from.
|
|
57
|
+
Reading = namedtuple("Reading", "free_memory_pct swapins_per_sec swapin_samples free_disk_gib unmeasured")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def parse_memory_pressure(text):
|
|
61
|
+
"""The system-wide free percentage `memory_pressure` prints on macOS, or None."""
|
|
62
|
+
found = re.search(r"free percentage:\s*(\d+(?:\.\d+)?)\s*%", text or "")
|
|
63
|
+
return float(found.group(1)) if found else None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def parse_vm_stat(text):
|
|
67
|
+
"""vm_stat's Swapins counter on macOS - pages swapped in since boot - or None. Its Swapouts is never read."""
|
|
68
|
+
found = re.search(r"^Swapins:\s*(\d+)\.?\s*$", text or "", re.M)
|
|
69
|
+
return int(found.group(1)) if found else None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def parse_meminfo(text):
|
|
73
|
+
"""MemAvailable as a percentage of MemTotal, from Linux's /proc/meminfo, or None.
|
|
74
|
+
|
|
75
|
+
Its SwapTotal and SwapFree are never read: swap used is a high-water mark, not present pressure.
|
|
76
|
+
"""
|
|
77
|
+
values = dict(re.findall(r"^(MemTotal|MemAvailable):\s*(\d+)", text or "", re.M))
|
|
78
|
+
total = int(values.get("MemTotal") or 0)
|
|
79
|
+
if not total or "MemAvailable" not in values:
|
|
80
|
+
return None
|
|
81
|
+
return 100.0 * int(values["MemAvailable"]) / total
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def parse_vmstat(text):
|
|
85
|
+
"""pswpin from Linux's /proc/vmstat - pages swapped in since boot - or None."""
|
|
86
|
+
found = re.search(r"^pswpin\s+(\d+)\s*$", text or "", re.M)
|
|
87
|
+
return int(found.group(1)) if found else None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def swapin_rate(count):
|
|
91
|
+
"""(swap-ins a second, the samples, None), or (None, (), why) when the counter cannot be read.
|
|
92
|
+
|
|
93
|
+
`count()` gives (pages swapped in since boot, None), or (None, why). The counter is read once and then SAMPLES
|
|
94
|
+
times, a second apart; each sample is its rise over the time that passed, which is the second and what reading
|
|
95
|
+
the counter took. The rate is the lower median of the samples, the second smallest of four, as the machine
|
|
96
|
+
script that measured these numbers takes it: it is over a ceiling only when three of the four seconds were,
|
|
97
|
+
so a burst of a second or two passes, and a mean, which one burst decides, is never taken.
|
|
98
|
+
"""
|
|
99
|
+
before, why = count()
|
|
100
|
+
if before is None:
|
|
101
|
+
return None, (), why
|
|
102
|
+
at = time.monotonic()
|
|
103
|
+
samples = []
|
|
104
|
+
for _ in range(SAMPLES):
|
|
105
|
+
time.sleep(SAMPLE_SECONDS)
|
|
106
|
+
now_count, why = count()
|
|
107
|
+
if now_count is None:
|
|
108
|
+
return None, (), why
|
|
109
|
+
now = time.monotonic()
|
|
110
|
+
samples.append(max(0, int(round((now_count - before) / max(now - at, 0.001)))))
|
|
111
|
+
before, at = now_count, now
|
|
112
|
+
return sorted(samples)[(len(samples) - 1) // 2], tuple(samples), None
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _program_output(name):
|
|
116
|
+
"""(what program `name` printed, None), or (None, why it could not be read). The program is the one PATH holds,
|
|
117
|
+
found as polyctl finds every program it starts, never in the current directory (WINDOWS-NO-CWD-EXEC)."""
|
|
118
|
+
from . import lib as A
|
|
119
|
+
program = A.program_path(name)
|
|
120
|
+
if program is None:
|
|
121
|
+
return None, f"{name} is not on PATH"
|
|
122
|
+
try:
|
|
123
|
+
done = subprocess.run([program], stdin=subprocess.DEVNULL, capture_output=True, text=True, encoding=UTF8,
|
|
124
|
+
errors="replace", timeout=PROGRAM_SECONDS)
|
|
125
|
+
except subprocess.TimeoutExpired:
|
|
126
|
+
return None, f"{name} did not answer in {PROGRAM_SECONDS}s"
|
|
127
|
+
except OSError as exc:
|
|
128
|
+
return None, f"{name} could not be started ({exc.strerror or exc})"
|
|
129
|
+
if done.returncode:
|
|
130
|
+
return None, f"{name} exited {done.returncode}"
|
|
131
|
+
return done.stdout, None
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _file_text(path):
|
|
135
|
+
try:
|
|
136
|
+
with open(path, encoding=UTF8, errors="replace") as fh:
|
|
137
|
+
return fh.read(), None
|
|
138
|
+
except OSError as exc:
|
|
139
|
+
return None, f"{path} cannot be read ({exc.strerror or exc})"
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _figure(source, parse, missing):
|
|
143
|
+
"""(the figure `parse` finds in what `source()` gives, None), or (None, why it was not found)."""
|
|
144
|
+
text, why = source()
|
|
145
|
+
if text is None:
|
|
146
|
+
return None, why
|
|
147
|
+
value = parse(text)
|
|
148
|
+
return (value, None) if value is not None else (None, missing)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def _memory_macos():
|
|
152
|
+
return _figure(lambda: _program_output("memory_pressure"), parse_memory_pressure,
|
|
153
|
+
"memory_pressure printed no free percentage")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _swapins_macos():
|
|
157
|
+
return _figure(lambda: _program_output("vm_stat"), parse_vm_stat, "vm_stat printed no Swapins line")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _memory_linux():
|
|
161
|
+
return _figure(lambda: _file_text(MEMINFO), parse_meminfo, f"{MEMINFO} names no MemAvailable")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _swapins_linux():
|
|
165
|
+
return _figure(lambda: _file_text(VMSTAT), parse_vmstat, f"{VMSTAT} has no pswpin line")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _free_disk_gib(path):
|
|
169
|
+
"""(GiB a user may still write on the volume that holds `path`, None), or (None, why)."""
|
|
170
|
+
try:
|
|
171
|
+
st = os.statvfs(path)
|
|
172
|
+
except (OSError, AttributeError) as exc:
|
|
173
|
+
return None, f"the home volume cannot be read ({exc})"
|
|
174
|
+
return st.f_bavail * st.f_frsize / GIB, None
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def measure(system=None):
|
|
178
|
+
"""The machine as it is now, on `system` (this one's, sys.platform, unless a test names another).
|
|
179
|
+
|
|
180
|
+
About four seconds on macOS and Linux, where paging is sampled; nothing is read on Windows, which says so.
|
|
181
|
+
Elsewhere memory and paging are not measured and the disk is.
|
|
182
|
+
"""
|
|
183
|
+
system = sys.platform if system is None else system
|
|
184
|
+
if system.startswith("win"):
|
|
185
|
+
return Reading(None, None, (), None, (("machine", "polyctl reads memory, paging and disk on macOS and Linux"),))
|
|
186
|
+
if system == "darwin":
|
|
187
|
+
memory, swapins = _memory_macos, _swapins_macos
|
|
188
|
+
elif system.startswith("linux"):
|
|
189
|
+
memory, swapins = _memory_linux, _swapins_linux
|
|
190
|
+
else:
|
|
191
|
+
memory = swapins = None
|
|
192
|
+
unmeasured = []
|
|
193
|
+
free_memory, why = memory() if memory else (None, ELSEWHERE)
|
|
194
|
+
if free_memory is None:
|
|
195
|
+
unmeasured.append(("memory", why))
|
|
196
|
+
rate, samples, why = swapin_rate(swapins) if swapins else (None, (), ELSEWHERE)
|
|
197
|
+
if rate is None:
|
|
198
|
+
unmeasured.append(("paging", why))
|
|
199
|
+
from . import lib as A
|
|
200
|
+
free_disk, why = _free_disk_gib(A.HOME)
|
|
201
|
+
if free_disk is None:
|
|
202
|
+
unmeasured.append(("disk", why))
|
|
203
|
+
return Reading(free_memory, rate, samples, free_disk, tuple(unmeasured))
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def read():
|
|
207
|
+
"""The machine now: the one place a command reads it through. The test suite replaces this one function with a
|
|
208
|
+
calm machine read at once (tests/conftest.py), as the real reading takes four seconds."""
|
|
209
|
+
return measure()
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def limits(cfg):
|
|
213
|
+
"""{setting: its value} for the three machine limits."""
|
|
214
|
+
from . import settings as S
|
|
215
|
+
return {key: S.get(cfg, key) for key in (MEMORY_FLOOR, PAGING_CEILING, DISK_FLOOR)}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _down(value):
|
|
219
|
+
"""A figure as a person reads it: whole, or to one decimal, never rounded up across a limit."""
|
|
220
|
+
tenths = int(value * 10 + 1e-6) / 10.0 # 14.7 is 14.699... as a float, and still 14.7
|
|
221
|
+
return f"{tenths:.0f}" if tenths == int(tenths) else f"{tenths:.1f}"
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def shortfalls(reading, cfg):
|
|
225
|
+
"""[(setting, what the reading shows against it)] for each measured figure past its limit; a figure that was not
|
|
226
|
+
measured is never one."""
|
|
227
|
+
limit, out = limits(cfg), []
|
|
228
|
+
if reading.free_memory_pct is not None and reading.free_memory_pct < limit[MEMORY_FLOOR]:
|
|
229
|
+
out.append((MEMORY_FLOOR, f"memory {_down(reading.free_memory_pct)}% free, under the {limit[MEMORY_FLOOR]}% "
|
|
230
|
+
f"floor ({MEMORY_FLOOR})"))
|
|
231
|
+
if reading.swapins_per_sec is not None and reading.swapins_per_sec > limit[PAGING_CEILING]:
|
|
232
|
+
out.append((PAGING_CEILING, f"paging at {reading.swapins_per_sec} swap-ins a second, over the "
|
|
233
|
+
f"{limit[PAGING_CEILING]} ceiling ({PAGING_CEILING})"))
|
|
234
|
+
if reading.free_disk_gib is not None and reading.free_disk_gib < limit[DISK_FLOOR]:
|
|
235
|
+
out.append((DISK_FLOOR, f"disk {_down(reading.free_disk_gib)} GiB free on the home volume, under the "
|
|
236
|
+
f"{limit[DISK_FLOOR]} GiB floor ({DISK_FLOOR})"))
|
|
237
|
+
return out
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def unmeasured_note(reading):
|
|
241
|
+
"""The one line a reading says of the figures it could not read, or None when it read them all."""
|
|
242
|
+
if not reading.unmeasured:
|
|
243
|
+
return None
|
|
244
|
+
named = "; ".join(f"{what} not measured ({why})" for what, why in reading.unmeasured)
|
|
245
|
+
return f"{named}: nothing waits or refuses on {'it' if len(reading.unmeasured) == 1 else 'them'}"
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def summary(reading, cfg):
|
|
249
|
+
"""The reading on one line, each figure past its limit naming the limit: what `polyctl doctor` shows."""
|
|
250
|
+
unmeasured = dict(reading.unmeasured)
|
|
251
|
+
if "machine" in unmeasured:
|
|
252
|
+
return f"not measured ({unmeasured['machine']})"
|
|
253
|
+
limit, parts = limits(cfg), []
|
|
254
|
+
if reading.free_memory_pct is None:
|
|
255
|
+
parts.append(f"memory not measured ({unmeasured.get('memory')})")
|
|
256
|
+
else:
|
|
257
|
+
short = reading.free_memory_pct < limit[MEMORY_FLOOR]
|
|
258
|
+
parts.append(f"memory {_down(reading.free_memory_pct)}% free"
|
|
259
|
+
+ (f", under the {limit[MEMORY_FLOOR]}% floor" if short else ""))
|
|
260
|
+
if reading.swapins_per_sec is None:
|
|
261
|
+
parts.append(f"paging not measured ({unmeasured.get('paging')})")
|
|
262
|
+
else:
|
|
263
|
+
short = reading.swapins_per_sec > limit[PAGING_CEILING]
|
|
264
|
+
parts.append(f"paging {reading.swapins_per_sec} swap-ins/s"
|
|
265
|
+
+ (f", over the {limit[PAGING_CEILING]} ceiling" if short else ""))
|
|
266
|
+
if reading.free_disk_gib is None:
|
|
267
|
+
parts.append(f"disk not measured ({unmeasured.get('disk')})")
|
|
268
|
+
else:
|
|
269
|
+
short = reading.free_disk_gib < limit[DISK_FLOOR]
|
|
270
|
+
parts.append(f"disk {_down(reading.free_disk_gib)} GiB free"
|
|
271
|
+
+ (f", under the {limit[DISK_FLOOR]} GiB floor" if short else ""))
|
|
272
|
+
return " · ".join(parts)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def refusal(short, waited, what):
|
|
276
|
+
"""The sentence a start refused for the machine prints: each figure past its limit, and what a person does."""
|
|
277
|
+
keys = [key for key, _ in short]
|
|
278
|
+
remedies = (["free disk on the home volume"] if DISK_FLOOR in keys else []) \
|
|
279
|
+
+ (["let the machine settle"] if MEMORY_FLOOR in keys or PAGING_CEILING in keys else [])
|
|
280
|
+
change = (f"the limit for this machine: polyctl config set {keys[0]} <n> --machine" if len(keys) == 1
|
|
281
|
+
else "the limits for this machine: polyctl config set <setting> <n> --machine")
|
|
282
|
+
head = f"the machine is still short after {waited}s" if waited > 0 else "the machine is short"
|
|
283
|
+
action = " and ".join(remedies)
|
|
284
|
+
return (f"{head}; not starting {what}: {'; '.join(text for _, text in short)}. "
|
|
285
|
+
f"{action[:1].upper()}{action[1:]}, then run this again; or a person changes {change}")
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _say(tone, text):
|
|
289
|
+
from . import lib as A
|
|
290
|
+
print(f"{A.C[tone]}{text}{A.C['reset']}", flush=True)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def wait_for_room(cfg, wait, what):
|
|
294
|
+
"""None once the machine has room for `what`, or the refusal to print when it stayed short for `wait` seconds.
|
|
295
|
+
|
|
296
|
+
A machine that has room costs one reading. One that is short is read again every RECHECK_SECONDS while it stays
|
|
297
|
+
so, and only while another reading can end before `wait` seconds are up, the first one's length being what each
|
|
298
|
+
takes; with no wait the first reading decides. What could not be read is said once, from the first reading, and
|
|
299
|
+
never refuses: a figure not measured is no figure past its limit.
|
|
300
|
+
"""
|
|
301
|
+
started = time.monotonic()
|
|
302
|
+
reading = read()
|
|
303
|
+
note = unmeasured_note(reading)
|
|
304
|
+
if note:
|
|
305
|
+
_say("dim", note)
|
|
306
|
+
short = shortfalls(reading, cfg)
|
|
307
|
+
if not short:
|
|
308
|
+
return None
|
|
309
|
+
took = time.monotonic() - started
|
|
310
|
+
deadline = started + max(0, wait)
|
|
311
|
+
if wait > 0:
|
|
312
|
+
_say("yellow", f"the machine is short: {'; '.join(text for _, text in short)} — waiting up to {wait}s "
|
|
313
|
+
f"for room")
|
|
314
|
+
while short:
|
|
315
|
+
left = deadline - time.monotonic()
|
|
316
|
+
if left <= took:
|
|
317
|
+
break
|
|
318
|
+
time.sleep(min(RECHECK_SECONDS, left - took))
|
|
319
|
+
reading = read()
|
|
320
|
+
short = shortfalls(reading, cfg)
|
|
321
|
+
if not short:
|
|
322
|
+
_say("green", f"the machine has room again after {int(time.monotonic() - started)}s: "
|
|
323
|
+
f"{summary(reading, cfg)}")
|
|
324
|
+
return None
|
|
325
|
+
return refusal(short, wait, what)
|
polyctl/prices.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"about": "The prices `polyctl cost --usd` estimates a US-dollar cost from (USD-COST). Each is a vendor's published list price in US dollars for `per_tokens` tokens of one kind `kinds` names. `version` counts the changes to this table; each vendor says when its prices were read (`as_of`), where (`source`) and what they do not cover (`scope`). A model or a kind of token this table does not price is unknown to polyctl, never zero, and a model served free is priced only by an entry that lists it at zero. `ids` are the other ids a model is written as, such as a dated snapshot. docs/telemetry.md says how to update it.",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"currency": "USD",
|
|
5
|
+
"per_tokens": 1000000,
|
|
6
|
+
"kinds": {
|
|
7
|
+
"input": "input tokens at the base rate: those after the last cache breakpoint, or all of them without caching",
|
|
8
|
+
"cache_write_5m": "input tokens written to a prompt cache that lives five minutes",
|
|
9
|
+
"cache_write_1h": "input tokens written to a prompt cache that lives one hour",
|
|
10
|
+
"cache_read": "input tokens read from a prompt cache, which also refreshes it",
|
|
11
|
+
"output": "output tokens, thinking included"
|
|
12
|
+
},
|
|
13
|
+
"vendors": {
|
|
14
|
+
"anthropic": {
|
|
15
|
+
"as_of": "2026-09-26",
|
|
16
|
+
"source": "https://platform.claude.com/docs/en/about-claude/pricing",
|
|
17
|
+
"scope": "Claude API list prices at standard speed with global routing. Not covered: fast mode, the Batch API, US-only inference, Amazon Bedrock and Google Cloud, server tools billed per request such as web search, and negotiated discounts.",
|
|
18
|
+
"models": {
|
|
19
|
+
"claude-fable-5-1": {"input": 10, "cache_write_5m": 12.5, "cache_write_1h": 20, "cache_read": 0.25, "output": 50},
|
|
20
|
+
"claude-mythos-5-1": {"input": 10, "cache_write_5m": 12.5, "cache_write_1h": 20, "cache_read": 0.25, "output": 50},
|
|
21
|
+
"claude-fable-5": {"input": 10, "cache_write_5m": 12.5, "cache_write_1h": 20, "cache_read": 1, "output": 50},
|
|
22
|
+
"claude-mythos-5": {"input": 10, "cache_write_5m": 12.5, "cache_write_1h": 20, "cache_read": 1, "output": 50},
|
|
23
|
+
"claude-opus-5-5": {"input": 4, "cache_write_5m": 5, "cache_write_1h": 8, "cache_read": 0.2, "output": 20},
|
|
24
|
+
"claude-opus-5": {"input": 5, "cache_write_5m": 6.25, "cache_write_1h": 10, "cache_read": 0.5, "output": 25},
|
|
25
|
+
"claude-opus-4-8": {"input": 5, "cache_write_5m": 6.25, "cache_write_1h": 10, "cache_read": 0.5, "output": 25},
|
|
26
|
+
"claude-opus-4-7": {"input": 5, "cache_write_5m": 6.25, "cache_write_1h": 10, "cache_read": 0.5, "output": 25},
|
|
27
|
+
"claude-opus-4-6": {"input": 5, "cache_write_5m": 6.25, "cache_write_1h": 10, "cache_read": 0.5, "output": 25},
|
|
28
|
+
"claude-opus-4-5": {"input": 5, "cache_write_5m": 6.25, "cache_write_1h": 10, "cache_read": 0.5, "output": 25,
|
|
29
|
+
"ids": ["claude-opus-4-5-20251101"]},
|
|
30
|
+
"claude-opus-4-1": {"input": 15, "cache_write_5m": 18.75, "cache_write_1h": 30, "cache_read": 1.5, "output": 75,
|
|
31
|
+
"ids": ["claude-opus-4-1-20250805"]},
|
|
32
|
+
"claude-opus-4-0": {"input": 15, "cache_write_5m": 18.75, "cache_write_1h": 30, "cache_read": 1.5, "output": 75,
|
|
33
|
+
"ids": ["claude-opus-4-20250514"]},
|
|
34
|
+
"claude-sonnet-5": {"input": 2, "cache_write_5m": 2.5, "cache_write_1h": 4, "cache_read": 0.2, "output": 10},
|
|
35
|
+
"claude-sonnet-4-6": {"input": 3, "cache_write_5m": 3.75, "cache_write_1h": 6, "cache_read": 0.3, "output": 15},
|
|
36
|
+
"claude-sonnet-4-5": {"input": 3, "cache_write_5m": 3.75, "cache_write_1h": 6, "cache_read": 0.3, "output": 15,
|
|
37
|
+
"ids": ["claude-sonnet-4-5-20250929"]},
|
|
38
|
+
"claude-sonnet-4-0": {"input": 3, "cache_write_5m": 3.75, "cache_write_1h": 6, "cache_read": 0.3, "output": 15,
|
|
39
|
+
"ids": ["claude-sonnet-4-20250514"]},
|
|
40
|
+
"claude-haiku-4-5": {"input": 1, "cache_write_5m": 1.25, "cache_write_1h": 2, "cache_read": 0.1, "output": 5,
|
|
41
|
+
"ids": ["claude-haiku-4-5-20251001"]},
|
|
42
|
+
"claude-3-5-haiku-20241022": {"input": 0.8, "cache_write_5m": 1, "cache_write_1h": 1.6, "cache_read": 0.08,
|
|
43
|
+
"output": 4}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|