Documentation
¶
Overview ¶
Package pyfmt reproduces the Python string formatting that orch's user-visible messages were built on.
These are not cosmetic helpers. `scripts/parity.sh` diffs the two binaries' output line for line, so a message that says `"claude"` where Python said `'claude'` is a failure, and a cap printed `80000` where Python printed `80,000` is another. Go's own verbs produce neither form: `%q` writes double quotes with Go's escaping rules, and `%d` has no thousands separator.
The package exists because the same function was about to be written a third time. `internal/graph` and `internal/router` each carried a private `pyQuote`, and the two copies did not agree: router's skipped the backslash escape in its double-quoted branch and the control characters in both, so the same input rendered two ways depending on which package formatted it. `repr("it's a back\slash")` is `"it's a back\\slash"` in Python and graph, and `"it's a back\slash"` in router. Neither package's tests covered it. Quote below is graph's — the correct one — and both packages now call it.
Python's `repr(float)` is here too, in float.go. It started in `internal/state`, which needs it for the spend dedup preimage; it moved when `internal/providers` turned out to need the same thing for claude's `--max-budget-usd`, whose value dispatcher.py builds as `str(budget)`. Its golden vector — values CPython actually printed, given as raw IEEE-754 bits so the test file cannot round the case it is testing — came with it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Commas ¶
Commas renders an integer the way Python's `{n:,}` does: groups of three digits separated by commas, with the sign kept in front.
Token counts and caps are printed this way in the budget gate's block reason, which is the line an operator reads when a run stops dispatching.
func Float ¶
Float renders v exactly as Python's repr(float) does.
This is not a cosmetic choice. `cost_usd` and `duration_s` are interpolated into the `spend` dedup preimage through a Python f-string, so the hash a Python orch writes depends on Python's float formatting. Go's own shortest formatting disagrees in two places:
value Python strconv.FormatFloat(v, 'g', -1, 64) 1.0 "1.0" "1" 5400.0 "5400.0" "5400" -0.0 "-0.0" "-0" 1e16 "1e+16" "1e+16" 1e21 "1e+21" "1e+21"
Get it wrong and two orch binaries sharing one orch.db compute different hashes for the same spend row, so `INSERT OR IGNORE` stops ignoring and the budget gate double-counts every dispatch. The failure is silent and permanent, which is why it has its own golden table in pyfmt_test.go.
CPython's rule (`float_repr` → `PyOS_double_to_string(v, 'r', 0, Py_DTSF_ADD_DOT_0)`):
- the shortest decimal digit string that round-trips,
- exponential form when decpt <= -4 or decpt > 16, written as `e±dd` with at least two exponent digits,
- otherwise positional, with ".0" appended when it would otherwise look like an integer.
`decpt` is the position of the decimal point relative to the digit string: 5400.0 has digits "54" and decpt 4.
func Quote ¶
Quote renders a string the way Python's `{x!r}` does for the values that reach orch's messages — task ids, model names, provider and preset names.
Python's repr prefers single quotes and switches to double only when the value contains a single quote and no double quote. Those names are `[A-Za-z0-9._/-]` in practice, so the simple case is the only one that happens — but the rule is implemented rather than assumed, because every one of those values comes out of a file a user edits.
Types ¶
This section is empty.