The listing sliced rows[-args.last:], so `--last 0` became rows[-0:],
which is every move, and `--last -1` became rows[1:], every move but the
oldest. Neither is what the flag says. A count below 1 now stops with
"--last must be 1 or more" (argparse usage error, exit 2).
With an unwritable history location (ANTIALGORITHM_HISTORY under a
read-only folder), seed.py printed the seed and then exited 1 with a
PermissionError traceback, and `moves.py add` failed the same way. An
agent that sees a failed command may throw the seed away and pick a
start point from its own taste, which is what the skill forbids, so the
seed has to succeed whatever happens to the history.
Now:
- load() turns a read error (no permission, a folder in the way) into
one line on stderr and an empty history, so seeds are still rolled,
only without avoiding recent values.
- seed.py prints the seed, and if saving fails it prints one line on
stderr and still exits 0.
- `moves.py add` prints "could not save the move: <reason>" and exits 1,
since saving is its whole job, but without a traceback.
add() still reads the file itself and fails on a read error rather than
treating the history as empty, so a file it cannot read is never
overwritten with a single row. This is one finding across three files:
the history module decides what a failure is, and each script decides
what it means for its own exit status.
One bad row in history.jsonl broke both scripts until the file was
deleted by hand:
- a byte that is not UTF-8 (`{"type":"move","move":"x \xff"}`) raised
UnicodeDecodeError in load();
- a line that is valid JSON but not an object (`5`, `null`) raised
AttributeError on entry.get();
- `"seed": null` or `"seed": ["a"]` raised AttributeError in
load_recent(), and `"seed": {"color": ["a"]}` raised an unhashable
TypeError in pick();
- a move row without "move" raised KeyError in the listing.
load() now decodes with errors="replace", so a stray byte costs one
character instead of the whole file, and returns only JSON objects.
load_recent() skips seeds that are not objects and values that are not
strings, and moves.py lists only rows whose move is a string. Bad shapes
are filtered out before the recent-seed and --last slices, so they don't
take a slot from a good row.
This is one finding across three files: the reader and both consumers
each crashed on a different shape of the same corrupt file. Rows that
are JSON objects are written back unchanged by the next add, so no good
row is lost; only lines that are not JSON objects drop out.