Answer product-owner round 1: name the figure's new input tokens, label the places' counts, give a usage error one line, and say where the reading-cost item goes
This commit is contained in:
+19
-18
@@ -3,14 +3,14 @@
|
||||
|
||||
usage: reading_cost.py [--reset] [history]
|
||||
|
||||
Run it inside a project checkout or one of its worktrees. history defaults to
|
||||
docs/comprehension-history.md there, created when missing. It reads loop-claude's archive of the
|
||||
project, $LOOP_CLAUDE_TRANSCRIPTS/<key> (default ~/.claude/loop-claude-transcripts), <key> being
|
||||
the checkout's path relative to ~/code, or to / outside it. For each chunk the judge ruled
|
||||
finished, under a UTC time, that history does not hold, it measures what the worker and its subagents read before
|
||||
the worker's first commit: the tokens they took in, and how often they opened or searched each
|
||||
file git tracks in the checkout. A chunk whose worker never committed is not measured. Each
|
||||
figure is appended under a "## Reading cost, chunk <id>, finished <UTC time>" heading, in the
|
||||
Run it inside a project checkout or one of its worktrees. history defaults to docs/comprehension-
|
||||
history.md there, created when missing. It reads loop-claude's archive of the project,
|
||||
$LOOP_CLAUDE_TRANSCRIPTS/<key> (default ~/.claude/loop-claude-transcripts), <key> being the
|
||||
checkout's path relative to ~/code, or to / outside it. For each finished chunk the history does not
|
||||
yet hold, it measures what the worker and its subagents read before the worker's first commit: their
|
||||
new input tokens (uncached and cache-written; cache reads excluded), and how often they opened or
|
||||
searched each file git tracks in the checkout. A chunk whose worker never committed is not measured.
|
||||
Each figure is appended under a "## Reading cost, chunk <id>, finished <UTC time>" heading, in the
|
||||
order the chunks finished.
|
||||
|
||||
--reset also appends a "## Reading cost reset, <UTC time>" heading: the trend then counts only
|
||||
@@ -49,7 +49,7 @@ HEADING = "Reading cost, chunk "
|
||||
PLACE = re.compile(r"^- `(.+)` (\d+)$")
|
||||
PLACES_KEPT = 10
|
||||
RESET = "Reading cost reset, "
|
||||
TOKENS = re.compile(r"^(\d+) tokens read before the first commit\.$")
|
||||
TOKENS = re.compile(r"^(\d+) new input tokens before the first commit\.$")
|
||||
WINDOW = 5
|
||||
|
||||
|
||||
@@ -70,10 +70,12 @@ class Checkout:
|
||||
def main(argv: list[str]) -> int:
|
||||
reset = argv[:1] == ["--reset"]
|
||||
given = argv[1:] if reset else argv
|
||||
if given[:1] in (["-h"], ["--help"]) or len(given) > 1 or given[:1] and given[0].startswith("-"):
|
||||
helped = given[:1] in (["-h"], ["--help"]) and len(given) == 1
|
||||
print(__doc__.strip(), file=sys.stdout if helped else sys.stderr)
|
||||
return 0 if helped else 1
|
||||
if given in (["-h"], ["--help"]):
|
||||
print(__doc__.strip())
|
||||
return 0
|
||||
if len(given) > 1 or given[:1] and given[0].startswith("-"):
|
||||
print(f"unknown arguments {' '.join(given)}; usage: reading_cost.py [--reset] [history]", file=sys.stderr)
|
||||
return 1
|
||||
checkout = located()
|
||||
if isinstance(checkout, Failure):
|
||||
return failed(checkout)
|
||||
@@ -85,7 +87,7 @@ def main(argv: list[str]) -> int:
|
||||
if isinstance(updated, Failure):
|
||||
return failed(updated)
|
||||
appended, readings = updated
|
||||
print(f"Appended {appended} reading-cost figures from {archive}{' and a reset' if reset else ''} to {history}.")
|
||||
print(f"Appended {appended} reading-cost figure{'' if appended == 1 else 's'} from {archive}{' and a reset' if reset else ''} to {history}.")
|
||||
print(trend(readings))
|
||||
return 0
|
||||
|
||||
@@ -233,7 +235,7 @@ def relative(path: str, roots: list[str]) -> str | None:
|
||||
|
||||
def figure(chunk: FinishedChunk, reading: Reading) -> str:
|
||||
places = "".join(f"- `{path}` {times}\n" for path, times in ranked(reading.places))
|
||||
return f"## {HEADING}{chunk_id(chunk)}, finished {chunk.finished}\n\n{reading.tokens} tokens read before the first commit.\n" + (f"\nRead most:\n\n{places}" if places else "")
|
||||
return f"## {HEADING}{chunk_id(chunk)}, finished {chunk.finished}\n\n{reading.tokens} new input tokens before the first commit.\n" + (f"\nRead most (opens and searches):\n\n{places}" if places else "")
|
||||
|
||||
|
||||
# The figures after the last reset, in the order their chunks finished: each machine appends its own archive's chunks.
|
||||
@@ -260,16 +262,15 @@ def merged(history: str, figures: list[str]) -> str:
|
||||
return history.rstrip("\n") + "\n\n" + "\n".join(figures)
|
||||
|
||||
|
||||
# Medians, so one chunk that ran a panel of readers or waited out a usage limit does not decide the trend alone.
|
||||
def trend(readings: list[Reading]) -> str:
|
||||
if len(readings) < 2 * WINDOW:
|
||||
return f"{len(readings)} chunks measured; the trend needs {2 * WINDOW}."
|
||||
last, earlier = middle(readings[-WINDOW:]), middle(readings[-2 * WINDOW:-WINDOW])
|
||||
medians = f"the last {WINDOW} chunks' median is {last} tokens read before their first commit, the {WINDOW} before them {earlier}."
|
||||
medians = f"the last {WINDOW} chunks' median is {last} new input tokens before their first commit, the {WINDOW} before them {earlier}."
|
||||
if last <= earlier:
|
||||
return f"Not rising: {medians}"
|
||||
read_most = "".join(f"\n- `{path}` {times}" for path, times in ranked(sum((reading.places for reading in readings[-WINDOW:]), collections.Counter())))
|
||||
return f"Rising: {medians}\n\nRead most over the last {WINDOW}:\n{read_most}"
|
||||
return f"Rising: {medians}\n\nRead most over the last {WINDOW} (opens and searches):\n{read_most}"
|
||||
|
||||
|
||||
def middle(readings: list[Reading]) -> int:
|
||||
|
||||
Reference in New Issue
Block a user