bin/tokencut.mjs finds the input file like this:
const file = args.find((a) => !a.startsWith("--") && args[args.indexOf(a) - 1] !== "--max" && args[args.indexOf(a) - 1] !== "--max-tool" && args[args.indexOf(a) - 1] !== "--price" && args[args.indexOf(a) - 1] !== "--out");
Two problems:
- The list of value-taking flags is hand-maintained. Add a fifth flag that takes a value and the file detection silently starts treating that value as the input path.
args.indexOf(a) returns the first match, not the current one. tokencut --max 8000 8000.json finds index 1 for the string 8000, checks args[0], which is not --max, and takes 8000 as the filename.
Both produce a confusing could not read 8000 rather than anything that points at the real problem.
Suggested fix
Parse positionally in one pass: walk args, and when an entry is a known value flag, consume the next entry as its value; the first leftover entry is the file. That removes the lookup entirely and makes adding a flag a one-line change.
Acceptance
tokencut --max 8000 8000.json reads 8000.json
tokencut payload.json --price 3 still works
- Adding a new value flag does not require touching the file detection
- Tests cover both cases above
bin/tokencut.mjsfinds the input file like this:Two problems:
args.indexOf(a)returns the first match, not the current one.tokencut --max 8000 8000.jsonfinds index 1 for the string8000, checksargs[0], which is not--max, and takes8000as the filename.Both produce a confusing
could not read 8000rather than anything that points at the real problem.Suggested fix
Parse positionally in one pass: walk
args, and when an entry is a known value flag, consume the next entry as its value; the first leftover entry is the file. That removes the lookup entirely and makes adding a flag a one-line change.Acceptance
tokencut --max 8000 8000.jsonreads8000.jsontokencut payload.json --price 3still works