agent-bios 0.19.3 → 0.20.0

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 (172) hide show
  1. package/DEPENDENCIES.md +62 -20
  2. package/INSTALL.md +1 -1
  3. package/README.md +16 -21
  4. package/claude/agents/frontier.md +1 -1
  5. package/claude/agents/sweep.md +2 -1
  6. package/claude/agents/workhorse.md +2 -2
  7. package/claude/guides/claude-prompting.md +494 -167
  8. package/claude/guides/cli-multi-model-workflow.md +8 -7
  9. package/claude/guides/gpt-prompting.md +241 -111
  10. package/claude/guides/session-distill-workflow.md +93 -43
  11. package/claude/guides/tooling-gotchas.md +3 -1
  12. package/codex/agents/reviewer.toml +2 -2
  13. package/codex/agents/sweep.toml +1 -1
  14. package/codex/agents/workhorse.toml +2 -2
  15. package/codex/guides/claude-prompting.md +494 -167
  16. package/codex/guides/cli-multi-model-workflow.md +8 -7
  17. package/codex/guides/gpt-prompting.md +241 -111
  18. package/codex/guides/session-distill-workflow.md +93 -43
  19. package/codex/guides/tooling-gotchas.md +3 -1
  20. package/compose/assemble.py +4 -1
  21. package/compose/canary.sh +8 -6
  22. package/compose/host_platform.py +158 -15
  23. package/compose/instructions-state.py +183 -41
  24. package/compose/instructions_app.py +2 -2
  25. package/compose/instructions_install.py +222 -27
  26. package/compose/instructions_session.py +250 -75
  27. package/compose/instructions_setup.py +6 -6
  28. package/compose/instructions_setup_cli.py +2 -36
  29. package/compose/instructions_setup_i18n.py +3 -3
  30. package/compose/instructions_store.py +160 -3
  31. package/compose/instructions_transaction.py +29 -5
  32. package/compose/instructions_ui_runtime.py +2 -2
  33. package/compose/setup/START.md +1 -1
  34. package/docs/advanced-launch.md +4 -0
  35. package/docs/releases/0.19.4.md +99 -0
  36. package/docs/releases/0.20.0.md +102 -0
  37. package/docs/setup.md +4 -4
  38. package/install.sh +54 -20
  39. package/launch/agent-launch.py +171 -22
  40. package/launch/agent-launch.toml +64 -29
  41. package/launch/agent-launch.zsh +104 -13
  42. package/launch/claude_subcommands.py +179 -0
  43. package/launch/provision-venv.sh +1 -1
  44. package/launch/shell_integration.py +7 -1
  45. package/learn/collect-learning.py +60 -9
  46. package/learn/migrate-learnings.py +70 -4
  47. package/learn/redact.py +2 -1
  48. package/package.json +37 -4
  49. package/provenance.json +1 -1
  50. package/session-cost.py +141 -18
  51. package/session-distill/coverage.json +6 -0
  52. package/session-distill/distill.py +2575 -0
  53. package/session-distill/grammar/__init__.py +0 -0
  54. package/session-distill/grammar/owner_lines.py +874 -0
  55. package/session-distill/originators.json +9 -0
  56. package/session-distill/packets/cross_review.md +31 -0
  57. package/session-distill/packets/form.md +86 -0
  58. package/session-distill/packets/judge.md +81 -0
  59. package/session-distill/packets/placement_contract.md +90 -0
  60. package/session-distill/packets/propose.md +124 -0
  61. package/session-distill/packets/read.md +57 -0
  62. package/session-distill/packets/reconsider.md +53 -0
  63. package/session-distill/packets/s7b.md +65 -0
  64. package/session-distill/packets/s9b.md +39 -0
  65. package/session-distill/packets/stitch.md +35 -0
  66. package/session-distill/packets/sweep.md +33 -0
  67. package/session-distill/runlib/__init__.py +0 -0
  68. package/session-distill/runlib/bound.py +1102 -0
  69. package/session-distill/runlib/breaker.py +467 -0
  70. package/session-distill/runlib/census.py +2347 -0
  71. package/session-distill/runlib/claims.py +420 -0
  72. package/session-distill/runlib/controls.py +902 -0
  73. package/session-distill/runlib/coverage.py +881 -0
  74. package/session-distill/runlib/declare.py +888 -0
  75. package/session-distill/runlib/delivery_evidence.py +1145 -0
  76. package/session-distill/runlib/derive.py +812 -0
  77. package/session-distill/runlib/destinations.py +3072 -0
  78. package/session-distill/runlib/dispatch.py +7939 -0
  79. package/session-distill/runlib/drift.py +1077 -0
  80. package/session-distill/runlib/entry.py +401 -0
  81. package/session-distill/runlib/evidence.py +890 -0
  82. package/session-distill/runlib/exposure.py +1162 -0
  83. package/session-distill/runlib/gate.py +2727 -0
  84. package/session-distill/runlib/gitread.py +79 -0
  85. package/session-distill/runlib/inventory.py +19624 -0
  86. package/session-distill/runlib/journal.py +1919 -0
  87. package/session-distill/runlib/ledger.py +3210 -0
  88. package/session-distill/runlib/ledger_compat.py +101 -0
  89. package/session-distill/runlib/ledger_migration.py +190 -0
  90. package/session-distill/runlib/lifecycle_intake.py +693 -0
  91. package/session-distill/runlib/lineage.py +454 -0
  92. package/session-distill/runlib/measures.py +249 -0
  93. package/session-distill/runlib/monitor.py +1180 -0
  94. package/session-distill/runlib/operations.py +522 -0
  95. package/session-distill/runlib/packet.py +838 -0
  96. package/session-distill/runlib/placement.py +1769 -0
  97. package/session-distill/runlib/projection.py +4090 -0
  98. package/session-distill/runlib/ranking.py +740 -0
  99. package/session-distill/runlib/receipts.py +200 -0
  100. package/session-distill/runlib/records.py +1965 -0
  101. package/session-distill/runlib/search.py +249 -0
  102. package/session-distill/runlib/sequencing.py +829 -0
  103. package/session-distill/runlib/sources.py +641 -0
  104. package/session-distill/runlib/stage_adjudicate.py +845 -0
  105. package/session-distill/runlib/stage_apply.py +1378 -0
  106. package/session-distill/runlib/stage_approvals.py +758 -0
  107. package/session-distill/runlib/stage_close.py +1220 -0
  108. package/session-distill/runlib/stage_confirm.py +929 -0
  109. package/session-distill/runlib/stage_delivery.py +3080 -0
  110. package/session-distill/runlib/stage_form.py +2576 -0
  111. package/session-distill/runlib/stage_judge.py +4248 -0
  112. package/session-distill/runlib/stage_propose.py +3307 -0
  113. package/session-distill/runlib/stage_read.py +5179 -0
  114. package/session-distill/runlib/stage_render.py +2739 -0
  115. package/session-distill/runlib/stage_retrieve.py +924 -0
  116. package/session-distill/runlib/stage_review_korean.py +1002 -0
  117. package/session-distill/runlib/stage_review_proposals.py +1292 -0
  118. package/session-distill/runlib/stagelock.py +412 -0
  119. package/session-distill/runlib/stop.py +1061 -0
  120. package/session-distill/runlib/targets.py +809 -0
  121. package/session-distill/runlib/usage.py +280 -0
  122. package/session-distill/runlib/validate.py +319 -0
  123. package/session-distill/runlib/views.py +4327 -0
  124. package/session-distill/schemas/adjudication.schema.json +35 -0
  125. package/session-distill/schemas/approval.schema.json +35 -0
  126. package/session-distill/schemas/census.schema.json +128 -0
  127. package/session-distill/schemas/checks.schema.json +207 -0
  128. package/session-distill/schemas/claim.schema.json +16 -0
  129. package/session-distill/schemas/confirmation.schema.json +24 -0
  130. package/session-distill/schemas/coverage.schema.json +66 -0
  131. package/session-distill/schemas/cross_review.schema.json +24 -0
  132. package/session-distill/schemas/event.schema.json +20 -0
  133. package/session-distill/schemas/evidence.schema.json +20 -0
  134. package/session-distill/schemas/expected_observation.schema.json +18 -0
  135. package/session-distill/schemas/form.schema.json +103 -0
  136. package/session-distill/schemas/intake.schema.json +71 -0
  137. package/session-distill/schemas/inventory.schema.json +872 -0
  138. package/session-distill/schemas/judge.schema.json +77 -0
  139. package/session-distill/schemas/ledger.schema.json +313 -0
  140. package/session-distill/schemas/observation.schema.json +16 -0
  141. package/session-distill/schemas/propose.schema.json +555 -0
  142. package/session-distill/schemas/read.schema.json +76 -0
  143. package/session-distill/schemas/reconsider.schema.json +122 -0
  144. package/session-distill/schemas/run.schema.json +150 -0
  145. package/session-distill/schemas/s7b.schema.json +200 -0
  146. package/session-distill/schemas/s9b.schema.json +28 -0
  147. package/session-distill/schemas/stitch.schema.json +25 -0
  148. package/session-distill/schemas/sweep.schema.json +25 -0
  149. package/session-distill/seats.json +149 -0
  150. package/session-distill/tables/allowed_pairs.json +257 -0
  151. package/session-distill/tables/controls.json +30 -0
  152. package/session-distill/tables/delivery_evidence.json +36 -0
  153. package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
  154. package/session-distill/tables/destinations.json +684 -0
  155. package/session-distill/tables/drift_layers.json +68 -0
  156. package/session-distill/tables/exposure_rules.json +192 -0
  157. package/session-distill/tables/placement_rules.json +148 -0
  158. package/session-distill/tables/propose_fixtures.json +154 -0
  159. package/session-distill/tables/ranking.json +194 -0
  160. package/session-distill/tables/redundancy.json +10 -0
  161. package/session-distill/tables/structural_rules.json +44 -0
  162. package/session-distill/tables/transition_fixtures.json +398 -0
  163. package/session-distill/tables/transitions.json +69 -0
  164. package/session-distill/tables/unit_outcome.json +67 -0
  165. package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
  166. package/wrappers/claude-run.sh +481 -33
  167. package/wrappers/claude_hermetic_evidence.py +1423 -0
  168. package/wrappers/codex-helm.sh +44 -13
  169. package/wrappers/codex-run.sh +183 -20
  170. package/wrappers/codex_frame_filter.py +1199 -0
  171. package/wrappers/codex_protocol.py +737 -0
  172. package/wrappers/jsonl_lines.py +65 -0
@@ -75,6 +75,18 @@ def _load(name, filename):
75
75
  return module
76
76
 
77
77
 
78
+ def load_jsonl():
79
+ """wrappers/jsonl_lines.py, in this package root: a JSONL record ends at "\n" or "\r\n"
80
+ only, read from the file's bytes (single source)."""
81
+ path = REPO / "wrappers" / "jsonl_lines.py"
82
+ if not path.is_file():
83
+ die(f"the JSONL splitter is missing: {path}")
84
+ spec = importlib.util.spec_from_file_location("jsonl_lines", path)
85
+ module = importlib.util.module_from_spec(spec)
86
+ spec.loader.exec_module(module)
87
+ return module
88
+
89
+
78
90
  def load_collect():
79
91
  """Reuse collect-learning.py's host/home/marker constants (single source)."""
80
92
  return _load("collect_learning", "collect-learning.py")
@@ -212,7 +224,7 @@ def prune_jsonl(jsonl, remove_ids, dry):
212
224
  if not jsonl.is_file():
213
225
  return 0
214
226
  kept, removed = [], 0
215
- for line in jsonl.read_text(encoding="utf-8").splitlines():
227
+ for line, terminator in load_jsonl().read_terminated(jsonl):
216
228
  s = line.strip()
217
229
  if s:
218
230
  try:
@@ -222,9 +234,10 @@ def prune_jsonl(jsonl, remove_ids, dry):
222
234
  continue
223
235
  except json.JSONDecodeError:
224
236
  pass # keep malformed lines untouched
225
- kept.append(line)
237
+ kept.append(line + terminator)
226
238
  if removed and not dry:
227
- atomic_write(jsonl, "\n".join(kept) + ("\n" if kept else ""))
239
+ # bytes, so no newline translation (Windows text mode) touches a kept line's own terminator
240
+ atomic_write(jsonl, "".join(kept).encode("utf-8"))
228
241
  return removed
229
242
 
230
243
 
@@ -327,7 +340,7 @@ def migrate(home, host, promotions, in_bundle, collect, dry=False, instructions_
327
340
  jsonl = home / "personal" / "learnings.jsonl"
328
341
  local_ids = set()
329
342
  if jsonl.is_file():
330
- for line in jsonl.read_text(encoding="utf-8").splitlines():
343
+ for line in load_jsonl().read(jsonl):
331
344
  s = line.strip()
332
345
  if not s:
333
346
  continue
@@ -461,8 +474,15 @@ def _self_test():
461
474
  user's bundle), removal of an in-bundle promotion from BOTH prose + jsonl,
462
475
  idempotency, and that the user's own '## Personal' text is untouched. Uses
463
476
  collect-learning's own writers so the seeded format is authoritative."""
477
+ import atexit
478
+ import shutil
464
479
  import tempfile
465
480
 
481
+ # Every scratch home below is made inside one root, removed when the process ends however it ends: the
482
+ # homes used to outlive it, sixteen directories per umbrella run.
483
+ tempfile.tempdir = tempfile.mkdtemp(prefix="migrate-selftest-root-")
484
+ atexit.register(shutil.rmtree, tempfile.tempdir, True)
485
+
466
486
  collect = load_collect()
467
487
 
468
488
  def rec(lid, domain):
@@ -699,6 +719,52 @@ def _self_test():
699
719
  valid.write_text('{"version": 2, "promotions": [{"learning_id": "x"}]}', encoding="utf-8")
700
720
  checks.append(("a real manifest still loads", len(load_manifest(valid)) == 1))
701
721
 
722
+ # a learnings.jsonl record ends at "\n" only; collect-learning writes U+2028 and U+2029 raw
723
+ # (ensure_ascii=False), and str.splitlines() would cut the record there
724
+ sep = "before\u2028between\u2029after"
725
+ sep_dir = pathlib.Path(tempfile.mkdtemp(prefix="migrate-jsonl-"))
726
+ kept_line = json.dumps(dict(rec(L["off"], "office-work"), lesson=sep), ensure_ascii=False)
727
+ (sep_dir / "learnings.jsonl").write_text(kept_line + "\n" + json.dumps(rec(L["core"], "core")) + "\n", encoding="utf-8")
728
+ pruned = prune_jsonl(sep_dir / "learnings.jsonl", {L["core"]}, dry=False)
729
+ checks.append(("jsonl-line-separators-inside-a-string-read-whole (prune_jsonl): the kept record is byte for byte",
730
+ pruned == 1 and (sep_dir / "learnings.jsonl").read_text(encoding="utf-8") == kept_line + "\n"))
731
+ # a bare CR is JSON whitespace, which text-mode reading would turn into a line break; a CRLF record stays CRLF
732
+ cr_line = "{\r" + json.dumps(rec(L["off"], "office-work"))[1:]
733
+ (sep_dir / "learnings.jsonl").write_bytes((cr_line + "\r\n" + json.dumps(rec(L["core"], "core")) + "\n").encode("utf-8"))
734
+ pruned = prune_jsonl(sep_dir / "learnings.jsonl", {L["core"]}, dry=False)
735
+ checks.append(("jsonl-bare-cr-whitespace-and-crlf-read-whole (prune_jsonl): the kept record is byte for byte",
736
+ pruned == 1 and (sep_dir / "learnings.jsonl").read_bytes() == (cr_line + "\r\n").encode("utf-8")))
737
+ # the rewrite keeps each line's own terminator under Windows text-mode writing too, which
738
+ # turns every "\n" written as text into "\r\n"
739
+ from unittest import mock
740
+ real_write_text = pathlib.Path.write_text
741
+
742
+ def windows_write_text(self, data, encoding=None, errors=None, newline=None):
743
+ return real_write_text(self, data.replace("\n", "\r\n") if newline is None else data,
744
+ encoding=encoding, errors=errors, newline=newline)
745
+ lf_line = json.dumps(rec(L["bb"], "builder-base"))
746
+ (sep_dir / "learnings.jsonl").write_bytes((cr_line + "\r\n" + lf_line + "\n" + json.dumps(rec(L["core"], "core")) + "\n")
747
+ .encode("utf-8"))
748
+ with mock.patch.object(pathlib.Path, "write_text", windows_write_text):
749
+ pruned = prune_jsonl(sep_dir / "learnings.jsonl", {L["core"]}, dry=False)
750
+ checks.append(("jsonl-rewrite-keeps-each-terminator-under-windows-newline-translation (prune_jsonl)",
751
+ pruned == 1 and (sep_dir / "learnings.jsonl").read_bytes()
752
+ == (cr_line + "\r\n" + lf_line + "\n").encode("utf-8")))
753
+ home = seed_claude()
754
+ jsonl = home / "personal" / "learnings.jsonl"
755
+ jsonl.write_text("".join(json.dumps(dict(json.loads(line), lesson=sep), ensure_ascii=False) + "\n"
756
+ for line in jsonl.read_text(encoding="utf-8").split("\n") if line), encoding="utf-8")
757
+ s = migrate(home, "claude", promos, make_in_bundle(["builder-base"]), collect)
758
+ checks.append(("jsonl-line-separators-inside-a-string-read-whole (migrate): every record's id is held locally",
759
+ s["removed"] == 2 and s["kept_not_in_bundle"] == 1))
760
+ home = seed_claude()
761
+ jsonl = home / "personal" / "learnings.jsonl"
762
+ jsonl.write_bytes("".join("{\r" + json.dumps(json.loads(line))[1:] + "\r\n"
763
+ for line in jsonl.read_text(encoding="utf-8").split("\n") if line).encode("utf-8"))
764
+ s = migrate(home, "claude", promos, make_in_bundle(["builder-base"]), collect)
765
+ checks.append(("jsonl-bare-cr-whitespace-and-crlf-read-whole (migrate): every record's id is held locally",
766
+ s["removed"] == 2 and s["kept_not_in_bundle"] == 1))
767
+
702
768
  failed = [n for n, ok in checks if not ok]
703
769
  if failed:
704
770
  for n in failed:
package/learn/redact.py CHANGED
@@ -3,7 +3,8 @@
3
3
 
4
4
  Both flows that egress session-derived text redact through here, so the floor
5
5
  is single-sourced (concept economy) rather than duplicated per call site:
6
- * heavy flow — session-distill/digest.py (per-session digests);
6
+ * heavy flow — session-distill/runlib/projection.py (the driver's transcript
7
+ views; it loads this module by path, never a copy of its patterns);
7
8
  * light flow — learn/collect-learning.py (`learn!` prose + upload + the
8
9
  curator export downstream, since the server stores what it receives —
9
10
  redaction that does not happen HERE cannot be undone there).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agent-bios",
3
- "version": "0.19.3",
4
- "releaseDate": "2026-09-29",
3
+ "version": "0.20.0",
4
+ "releaseDate": "2026-11-17",
5
5
  "description": "A thin, low-level instruction layer for LLM CLI agents: one set of principles and behavior whichever model you run. Stores private, editable instructions for explicitly activated sessions.",
6
6
  "bin": {
7
7
  "agent-bios": "install.sh"
@@ -23,6 +23,7 @@
23
23
  "learn/learning.schema.json",
24
24
  "learn/promotions.json",
25
25
  "launch/agent-launch.zsh",
26
+ "launch/claude_subcommands.py",
26
27
  "launch/agent-launch.py",
27
28
  "launch/shell_integration.py",
28
29
  "compose/pkgid.py",
@@ -75,11 +76,39 @@
75
76
  "learn/migrate-learnings.py",
76
77
  "learn/redact.py",
77
78
  "wrappers/codex-run.sh",
79
+ "wrappers/codex_frame_filter.py",
80
+ "wrappers/codex_protocol.py",
78
81
  "wrappers/codex-helm.sh",
79
82
  "wrappers/claude-run.sh",
83
+ "wrappers/claude_hermetic_evidence.py",
84
+ "wrappers/jsonl_lines.py",
80
85
  "install.sh",
81
86
  "launch/provision-venv.sh",
82
87
  "session-cost.py",
88
+ "session-distill/distill.py",
89
+ "session-distill/runlib/",
90
+ "session-distill/grammar/",
91
+ "session-distill/schemas/",
92
+ "session-distill/tables/redundancy.json",
93
+ "session-distill/tables/transition_fixtures.json",
94
+ "session-distill/tables/allowed_pairs.json",
95
+ "session-distill/tables/destinations.json",
96
+ "session-distill/tables/drift_layers.json",
97
+ "session-distill/tables/exposure_rules.json",
98
+ "session-distill/tables/structural_rules.json",
99
+ "session-distill/tables/placement_rules.json",
100
+ "session-distill/tables/ranking.json",
101
+ "session-distill/tables/propose_fixtures.json",
102
+ "session-distill/tables/transitions.json",
103
+ "session-distill/tables/controls.json",
104
+ "session-distill/tables/delivery_evidence.json",
105
+ "session-distill/tables/delivery_evidence_fixtures.json",
106
+ "session-distill/tables/unit_outcome.json",
107
+ "session-distill/tables/unit_outcome_fixtures.json",
108
+ "session-distill/packets/",
109
+ "session-distill/seats.json",
110
+ "session-distill/originators.json",
111
+ "session-distill/coverage.json",
83
112
  "docs/",
84
113
  "README.md",
85
114
  "INSTALL.md",
@@ -88,12 +117,16 @@
88
117
  "compose/native_cli.py",
89
118
  "compose/host_platform.py",
90
119
  "compose/runtime_entry.py",
91
- "compose/windows_deploy.py"
120
+ "compose/windows_deploy.py",
121
+ "!**/__pycache__",
122
+ "!**/__pycache__/**",
123
+ "!**/*.pyc",
124
+ "!**/*.pyo"
92
125
  ],
93
126
  "scripts": {
94
127
  "postinstall": "printf '\\n> agent-bios installed. Deploy into this environment with: agent-bios install\\n> Then: agent-bios verify | status | uninstall\\n\\n'",
95
128
  "prepack": "bash gates/check-publish.sh --stamp",
96
- "prepublishOnly": "bash gates/check-publish.sh --guard",
129
+ "prepublishOnly": "python3 gates/check-model-currency.py --publish-guard && bash gates/check-publish.sh --guard",
97
130
  "postpack": "rm -f provenance.json"
98
131
  },
99
132
  "publishConfig": {
package/provenance.json CHANGED
@@ -1 +1 @@
1
- {"commit":"338a16e35f0b6262107a808c9cc20721b6f4facd","committedAt":"2026-09-30T20:23:32+09:00","dirty":false}
1
+ {"commit":"9cfe7f54af3e841e9739e30072c16c98a76b187d","committedAt":"2026-11-17T13:30:35+09:00","dirty":false}
package/session-cost.py CHANGED
@@ -18,31 +18,70 @@ the bill: measured over two real sessions here, cache read + cache write were
18
18
  92-94% of cost and output 6-8%, so context size is the cost, and the only lever
19
19
  on it is how long a session is allowed to grow before it is reset.
20
20
  """
21
- import json, sys, glob, os, itertools, tempfile, subprocess
21
+ import json, sys, glob, os, itertools, re, tempfile, subprocess
22
22
  from datetime import datetime, timezone
23
23
 
24
24
  # $/MTok: input, output, cache_read, cache_write_5m, cache_write_1h
25
+ # Whole table re-read against the vendor pricing page on 2026-10-21. That pass added the
26
+ # 5.5 generation and corrected `claude-sonnet-5`, which carried Sonnet 4.6's rates — it
27
+ # had been overcharging every Sonnet 5 session by half since it was written.
28
+ # `claude-fable-5-2` added 2026-11-11 from the same page — the vendor's platform docs at
29
+ # `about-claude/pricing`, named without its URL because `gates/check-endpoints.py` forbids a
30
+ # shipped file from carrying one. Its "Model pricing" table
31
+ # reads base input / 5m cache writes / 1h cache writes / cache hits / output — NOT this
32
+ # tuple's order, so the row is reordered rather than copied across. The generation's cache
33
+ # hit is 0.025x base input, which is why it reads cheaper per cached token than Opus 5.5 on
34
+ # a dearer model. The page prices Mythos 5.2 identically; no Mythos row past `claude-mythos-5`
35
+ # is carried here, so a Mythos session reports unpriced rather than at a guessed rate.
25
36
  PRICES = {
26
37
  "claude-fable-5": (10.0, 50.0, 1.00, 12.50, 20.0),
27
- # Fable 5.1 model overview, verified 2026-09-08.
38
+ "claude-fable-5-2": (8.0, 40.0, 0.20, 10.0, 16.0),
28
39
  "claude-fable-5-1": (10.0, 50.0, 0.25, 12.50, 20.0),
29
40
  "claude-mythos-5": (10.0, 50.0, 1.00, 12.50, 20.0),
41
+ "claude-opus-5-5": (4.0, 20.0, 0.20, 5.0, 8.0),
30
42
  "claude-opus-5": (5.0, 25.0, 0.50, 6.25, 10.0),
31
43
  "claude-opus-4-8": (5.0, 25.0, 0.50, 6.25, 10.0),
32
44
  "claude-opus-4-7": (5.0, 25.0, 0.50, 6.25, 10.0),
33
45
  "claude-opus-4-6": (5.0, 25.0, 0.50, 6.25, 10.0),
34
- "claude-sonnet-5": (3.0, 15.0, 0.30, 3.75, 6.0),
46
+ "claude-sonnet-5-5": (2.0, 10.0, 0.10, 2.50, 4.0),
47
+ "claude-sonnet-5": (2.0, 10.0, 0.20, 2.50, 4.0),
35
48
  "claude-sonnet-4-6": (3.0, 15.0, 0.30, 3.75, 6.0),
49
+ # Haiku 5.5 is the short-prompt rate; see TIERED below.
50
+ "claude-haiku-5-5": (0.10, 0.50, 0.01, 0.125, 0.20),
36
51
  "claude-haiku-4-5": (1.0, 5.0, 0.10, 1.25, 2.0),
37
52
  }
38
53
 
39
- def price_for(model):
40
- # Version-specific rates take precedence over their family prefix.
41
- for k, v in sorted(PRICES.items(), key=lambda item: len(item[0]), reverse=True):
42
- if model.startswith(k):
43
- return v
54
+ # Models the vendor bills at two rates by PROMPT length. A session total cannot say which
55
+ # of its requests crossed the threshold — the per-request sizes are gone by the time the
56
+ # transcript is aggregated — so the table holds the lower rate and the report says, by
57
+ # name, that the figure is a floor. Silently picking either rate would print a plausible
58
+ # number that is wrong in a direction nobody could see.
59
+ TIERED = {
60
+ "claude-haiku-5-5": "prompts over 100k tokens bill at 5x — this figure is a floor",
61
+ }
62
+
63
+ def price_key(model):
64
+ """The PRICES key this model bills under, or None. See price_for for the rule."""
65
+ if model in PRICES:
66
+ return model
67
+ for k in PRICES:
68
+ if model.startswith(k) and re.fullmatch(r"-\d{8}", model[len(k):]):
69
+ return k
44
70
  return None
45
71
 
72
+
73
+ def price_for(model):
74
+ """An exact id, or that same id carrying a release-date suffix. Nothing else.
75
+
76
+ This matched any prefix until 2026-10-21, which was wrong in the one direction that
77
+ cannot be noticed: a generation's id is a PREFIX of the next one, so `claude-opus-5-5`
78
+ priced itself at `claude-opus-5` rates and printed a plausible number. An unknown
79
+ model now returns None, which the report prints as `?` and collects under `unpriced`
80
+ — visibly missing beats quietly wrong. The accepted tail is the vendor's dated
81
+ spelling (`claude-haiku-4-5-20251001`), which is the same model at the same price."""
82
+ key = price_key(model)
83
+ return PRICES[key] if key else None
84
+
46
85
  def moment(ts):
47
86
  """A transcript timestamp as an aware datetime, or None if it is not one.
48
87
 
@@ -59,8 +98,19 @@ def moment(ts):
59
98
  return parsed if parsed.tzinfo else parsed.replace(tzinfo=timezone.utc)
60
99
 
61
100
 
101
+ # The usage keys this report reads. The vendor calls the transcript format internal and liable to
102
+ # change between versions, so a usage object carrying none of them is a moved format, not a free
103
+ # request: it is counted and named with the host version. A key added beside these is no alarm.
104
+ USAGE_KEYS = ("input_tokens", "output_tokens", "cache_read_input_tokens", "cache_creation_input_tokens",
105
+ "cache_creation")
106
+
107
+
62
108
  def scan(path):
63
- """-> {(scope, model): {in,out,cr,cw5,cw1,turns}}, (t_min, t_max), {scope: agent_ids}
109
+ """-> {(scope, model): {in,out,cr,cw5,cw1,turns}}, (t_min, t_max), {scope: agent_ids}, drift
110
+
111
+ `drift` is what the totals leave out: `unread`, the responses whose usage object carries none
112
+ of USAGE_KEYS, `versions`, the host versions those records name, and `bad_lines`, the lines
113
+ that are not JSON.
64
114
 
65
115
  A single API response is written to the transcript several times as it
66
116
  streams, each line carrying output_tokens *so far* (e.g. 2, 2, 2, 540).
@@ -70,17 +120,22 @@ def scan(path):
70
120
  """
71
121
  best, tmin, tmax = {}, None, None
72
122
  agents = {"main": set(), "sub": set()}
123
+ drift = {"unread": 0, "versions": set(), "bad_lines": 0}
73
124
  anonymous = itertools.count()
74
125
  try:
75
126
  handle = open(path, errors="replace")
76
127
  except OSError as exc:
77
128
  print(f"session-cost: cannot read {path}: {exc}", file=sys.stderr)
78
- return {}, (None, None), agents
129
+ return {}, (None, None), agents, drift
79
130
  with handle:
80
131
  for line in handle:
81
132
  try:
82
133
  d = json.loads(line)
83
134
  except json.JSONDecodeError:
135
+ drift["bad_lines"] += 1
136
+ continue
137
+ if not isinstance(d, dict):
138
+ drift["bad_lines"] += 1
84
139
  continue
85
140
  at = moment(d.get("timestamp"))
86
141
  if at is not None:
@@ -103,10 +158,13 @@ def scan(path):
103
158
  key = (scope, ident if ident else f"anonymous-{next(anonymous)}")
104
159
  prev = best.get(key)
105
160
  if prev is None or u.get("output_tokens", 0) > prev[1].get("output_tokens", 0):
106
- best[key] = (model, u)
161
+ best[key] = (model, u, d.get("version"))
107
162
 
108
163
  agg = {}
109
- for (scope, _), (model, u) in best.items():
164
+ for (scope, _), (model, u, version) in best.items():
165
+ if not any(k in u for k in USAGE_KEYS):
166
+ drift["unread"] += 1
167
+ drift["versions"].add(version if isinstance(version, str) and version else None)
110
168
  a = agg.setdefault((scope, model), dict(inp=0, out=0, cr=0, cw5=0, cw1=0, turns=0))
111
169
  a["inp"] += u.get("input_tokens", 0)
112
170
  a["out"] += u.get("output_tokens", 0)
@@ -118,7 +176,7 @@ def scan(path):
118
176
  else:
119
177
  a["cw5"] += u.get("cache_creation_input_tokens", 0)
120
178
  a["turns"] += 1
121
- return agg, (tmin, tmax), agents
179
+ return agg, (tmin, tmax), agents, drift
122
180
 
123
181
  def cost(model, a):
124
182
  p = price_for(model)
@@ -141,13 +199,17 @@ def report(session_path):
141
199
  sources += [(os.path.basename(f)[:-6], f)
142
200
  for f in sorted(glob.glob(os.path.join(base, "subagents", "*.jsonl")))]
143
201
  print(f"\n=== {os.path.basename(session_path)} ===")
144
- grand, unpriced = 0.0, []
202
+ grand, unpriced, tiered_seen = 0.0, [], set()
145
203
  hdr = (f"{'source':<38}{'model':<22}{'turns':>6}{'input':>9}{'output':>9}"
146
204
  f"{'cache_rd':>10}{'cache_wr':>10}{'cost$':>9}")
147
205
  print(hdr); print("-" * len(hdr))
148
206
  span_min = span_max = None
207
+ unread, versions, bad_lines = 0, set(), 0
149
208
  for label, path in sources:
150
- agg, (tmin, tmax), agents = scan(path)
209
+ agg, (tmin, tmax), agents, drift = scan(path)
210
+ unread += drift["unread"]
211
+ versions |= drift["versions"]
212
+ bad_lines += drift["bad_lines"]
151
213
  if tmin:
152
214
  span_min = min(span_min or tmin, tmin); span_max = max(span_max or tmax, tmax)
153
215
  for (scope, model), a in sorted(agg.items()):
@@ -160,6 +222,8 @@ def report(session_path):
160
222
  name = "main"
161
223
  c = cost(model, a)
162
224
  cs = f"{c:9.2f}" if c is not None else " ?"
225
+ if c is not None and price_key(model) in TIERED:
226
+ tiered_seen.add(price_key(model))
163
227
  if c is None:
164
228
  unpriced.append(model)
165
229
  else:
@@ -173,6 +237,17 @@ def report(session_path):
173
237
  print(f"\nwall clock: no usable timestamps | modeled total cost: ${grand:,.2f}")
174
238
  if unpriced:
175
239
  print(f"WARN unpriced models: {set(unpriced)}")
240
+ if unread:
241
+ named = sorted(v for v in versions if v)
242
+ writer = ", ".join(f"Claude Code {v}" for v in named) + (", " if named and None in versions else "")
243
+ writer += "a record naming no host version" if None in versions else ""
244
+ print(f"WARN {unread} response(s) carry a usage object with none of the keys this report reads "
245
+ f"({', '.join(USAGE_KEYS)}), written by {writer}: the transcript format has moved, and the "
246
+ f"totals above count them as zero")
247
+ if bad_lines:
248
+ print(f"WARN {bad_lines} line(s) are not a JSON record and were skipped")
249
+ for key in sorted(tiered_seen):
250
+ print(f"NOTE {key}: {TIERED[key]}")
176
251
  return 0
177
252
 
178
253
  # ── context budget ────────────────────────────────────────────────────────────
@@ -384,10 +459,30 @@ def _self_test():
384
459
 
385
460
  def check(name, got, want):
386
461
  ok = got == want
387
- print(f" {'ok ' if ok else 'FAIL'} {name}" + ("" if ok else f" got {got!r} want {want!r}"))
462
+ # A failure goes to stderr too: the umbrella runs this quietly and shows stderr alone.
463
+ print(f" {'ok ' if ok else 'FAIL'} {name}" + ("" if ok else f" got {got!r} want {want!r}"),
464
+ file=sys.stdout if ok else sys.stderr)
388
465
  if not ok:
389
466
  failures.append(name)
390
467
 
468
+ # Price lookup, which had no control at all while it silently priced one generation
469
+ # at the previous one's rates. The first case is the defect; the rest fence the rule.
470
+ # Two halves of the same rule. Once a generation HAS a row the first case can only
471
+ # ask that the rows differ; the second keeps the original defect reachable by naming
472
+ # a generation the table does not carry, where the old prefix rule billed a neighbour.
473
+ check("a generation bills at its own rate, not the previous generation's",
474
+ price_for("claude-opus-5-5") != price_for("claude-opus-5"), True)
475
+ check("a generation the table does not carry is unpriced, not billed at a neighbour",
476
+ price_for("claude-opus-5-9"), None)
477
+ check("an exact id is priced", price_for("claude-opus-5"), PRICES["claude-opus-5"])
478
+ check("a dated spelling is the same model at the same price",
479
+ price_for("claude-haiku-4-5-20251001"), PRICES["claude-haiku-4-5"])
480
+ check("a longer number is not a dated suffix", price_for("claude-opus-50"), None)
481
+ check("an unknown family is unpriced rather than guessed",
482
+ price_for("gpt-6.1-sol"), None)
483
+ check("the price table is not empty, so the cases above judge something",
484
+ len(PRICES) > 0, True)
485
+
391
486
  def write(dirpath, name, records):
392
487
  p = os.path.join(dirpath, name)
393
488
  with open(p, "w", encoding="utf-8") as fh:
@@ -398,7 +493,8 @@ def _self_test():
398
493
  with tempfile.TemporaryDirectory() as td:
399
494
  # A version-specific cache rate must reach the public report without
400
495
  # changing the older model's rate. Run the real CLI/scan/cost path.
401
- for model, expected in (("claude-fable-5-1", "$0.25"),
496
+ for model, expected in (("claude-fable-5-2", "$0.20"),
497
+ ("claude-fable-5-1", "$0.25"),
402
498
  ("claude-fable-5", "$1.00")):
403
499
  transcript = write(td, model + ".jsonl", [
404
500
  {"type": "assistant", "message": {
@@ -413,6 +509,32 @@ def _self_test():
413
509
  "modeled total cost: " + expected in result.stdout),
414
510
  (0, True))
415
511
 
512
+ # A usage key the vendor renames reads as zero. The report names how many responses it
513
+ # could not read and the host version that wrote them; a key added beside the known ones
514
+ # is no alarm; a line that is not JSON is counted, not skipped in silence.
515
+ def cost_report(name, records, raw=""):
516
+ path = write(td, name, records)
517
+ if raw:
518
+ with open(path, "a", encoding="utf-8") as fh:
519
+ fh.write(raw)
520
+ done = subprocess.run([sys.executable, os.path.abspath(__file__), path], capture_output=True, text=True)
521
+ return done.returncode, done.stdout
522
+ moved = [{"type": "assistant", "version": "9.9.9-planted", "message": {
523
+ "id": f"moved-{n}", "model": "claude-opus-5", "usage": {"inputTokens": 10, "outputTokens": 5}}}
524
+ for n in range(2)]
525
+ code, out = cost_report("moved.jsonl", moved)
526
+ check("a renamed usage key is reported by count and host version",
527
+ (code, "WARN 2 response(s) carry a usage object with none of the keys" in out, "9.9.9-planted" in out),
528
+ (0, True, True))
529
+ code, out = cost_report("added.jsonl", [{"type": "assistant", "version": "9.9.9-planted", "message": {
530
+ "id": "added", "model": "claude-opus-5",
531
+ "usage": {"input_tokens": 10, "output_tokens": 5, "planted_new_key": 3}}}])
532
+ check("a usage key added beside the known ones raises nothing", (code, "WARN" in out), (0, False))
533
+ code, out = cost_report("bad-line.jsonl", moved[:0] + [{"type": "assistant", "message": {
534
+ "id": "fine", "model": "claude-opus-5", "usage": {"input_tokens": 10}}}], raw="{not json\n")
535
+ check("a line that is not JSON is counted", (code, "WARN 1 line(s) are not a JSON record" in out),
536
+ (0, True))
537
+
416
538
  # Claude: two requests. The first is written twice as it streams, the
417
539
  # second is a sidechain that must not be counted.
418
540
  claude = write(td, "claude.jsonl", [
@@ -490,7 +612,8 @@ def _self_test():
490
612
  check("an unmeasurable transcript reports failure, not zero",
491
613
  context_report(empty), False)
492
614
 
493
- print("\nself-test: " + (f"{len(failures)} FAILED" if failures else "all passed"))
615
+ print("\nself-test: " + (f"{len(failures)} FAILED" if failures else "all passed"),
616
+ file=sys.stderr if failures else sys.stdout)
494
617
  return 1 if failures else 0
495
618
 
496
619
 
@@ -0,0 +1,6 @@
1
+ {
2
+ "backlog": [],
3
+ "pending_events": [],
4
+ "transcripts": {},
5
+ "windows": {}
6
+ }