Answer prose round 1: mark the reading-cost item decision, split the rise rule's reasons, and say the trend counts since the last reset
This commit is contained in:
+3
-3
@@ -20,8 +20,8 @@ It then compares the median tokens of the history's last 5 figures with the 5 be
|
||||
the order their chunks finished, and prints "Rising:" or "Not rising:" with both medians. Rising, it
|
||||
lists the files the last 5 chunks read most. With fewer than 10 figures, it says so.
|
||||
|
||||
Exit 1, saying why, when git cannot start or finds no checkout, the archive or the history cannot
|
||||
be read or written, or a figure in the history cannot be read back.
|
||||
Exit 1, saying why, on unknown arguments, or when git cannot start or finds no checkout, the
|
||||
archive or the history cannot be read or written, or a figure in the history cannot be read back.
|
||||
"""
|
||||
import collections
|
||||
import dataclasses
|
||||
@@ -264,7 +264,7 @@ def merged(history: str, figures: list[str]) -> str:
|
||||
|
||||
def trend(readings: list[Reading]) -> str:
|
||||
if len(readings) < 2 * WINDOW:
|
||||
return f"{len(readings)} chunks measured; the trend needs {2 * WINDOW}."
|
||||
return f"{len(readings)} chunks measured since the last reset; the trend needs {2 * WINDOW}."
|
||||
last, earlier = middle(readings[-WINDOW:]), middle(readings[-2 * WINDOW:-WINDOW])
|
||||
medians = f"the last {WINDOW} chunks' median is {last} new input tokens before their first commit, the {WINDOW} before them {earlier}."
|
||||
if last <= earlier:
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ def shell_reads(command: str, cwd: str, home: str) -> Reads:
|
||||
|
||||
|
||||
def shell_lines(command: str) -> typing.Iterator[list[str]]:
|
||||
"""Each line's tokens, skipping a heredoc's body, which feeds a program rather than naming files."""
|
||||
"""Each line's tokens, skipping a heredoc's body, which feeds a program."""
|
||||
ends = None
|
||||
for line in command.splitlines():
|
||||
if ends is not None:
|
||||
@@ -56,7 +56,7 @@ def segments(tokens: list[str]) -> list[list[str]]:
|
||||
if target:
|
||||
target = False
|
||||
elif all(char in "();<>|&" for char in token):
|
||||
# A redirect's target is written or fed, not read by the command.
|
||||
# A redirect's target is not an operand, so it does not count as a read.
|
||||
target = "<" in token or ">" in token
|
||||
found.append([])
|
||||
else:
|
||||
|
||||
@@ -72,7 +72,7 @@ class Measure(unittest.TestCase):
|
||||
class Figures(unittest.TestCase):
|
||||
def test_rises_only_above_the_five_before_and_needs_ten(self):
|
||||
flat = [Reading(100, collections.Counter({"a.py": 1}))] * 10
|
||||
self.assertEqual(reading_cost.trend(flat[:9]), "9 chunks measured; the trend needs 10.")
|
||||
self.assertEqual(reading_cost.trend(flat[:9]), "9 chunks measured since the last reset; the trend needs 10.")
|
||||
self.assertTrue(reading_cost.trend(flat).startswith("Not rising: the last 5 chunks' median is 100 new input tokens"))
|
||||
self.assertTrue(reading_cost.trend(flat[:9] + [Reading(3000000, collections.Counter())]).startswith("Not rising:"))
|
||||
self.assertEqual(reading_cost.trend(flat[:5] + [Reading(101, collections.Counter({"b.py": 2}))] * 5), "Rising: the last 5 chunks' median is 101 new input tokens before their first commit, the 5 before them 100.\n\nRead most over the last 5 (opens and searches):\n\n- `b.py` 10")
|
||||
@@ -135,13 +135,13 @@ class ReadingCostTool(unittest.TestCase):
|
||||
ran = self.run_tool(worktree)
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
history = worktree / "docs" / "comprehension-history.md"
|
||||
self.assertEqual(ran.stdout, f"Appended 2 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} to {history}.\n2 chunks measured; the trend needs 10.\n")
|
||||
self.assertEqual(ran.stdout, f"Appended 2 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} to {history}.\n2 chunks measured since the last reset; the trend needs 10.\n")
|
||||
figure = "## Reading cost, chunk {}, finished {}\n\n33 new input tokens before the first commit.\n\nRead most (opens and searches):\n\n- `a.py` 1\n"
|
||||
self.assertEqual(history.read_text(), "# Comprehension history\n\n" + "\n".join(figure.format(chunk.folder[:12], chunk.finished) for chunk in chunks))
|
||||
self.assertTrue(self.run_tool(worktree).stdout.startswith(f"Appended 0 reading-cost figures from"))
|
||||
self.assertEqual(history.read_text().count("## Reading cost"), 2)
|
||||
reset = self.run_tool(worktree, "--reset")
|
||||
self.assertEqual(reset.stdout, f"Appended 0 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} and a reset to {history}.\n0 chunks measured; the trend needs 10.\n")
|
||||
self.assertEqual(reset.stdout, f"Appended 0 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} and a reset to {history}.\n0 chunks measured since the last reset; the trend needs 10.\n")
|
||||
self.assertRegex(history.read_text(), r"\n## Reading cost reset, \d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ\n$")
|
||||
|
||||
def test_refuses_an_option_it_does_not_know(self):
|
||||
|
||||
Reference in New Issue
Block a user