cancho-tools

tally 0.1.0

Count distinct lines or fields and report the most frequent, ordered by count then bytewise key; one bounded pass, the same answer on every machine.

tally [--root DIR] [--field N [--delim D]] [--top N] [--max-keys N] [--max-line-bytes N] [--format json|text] [FILE...]
output
one JSON document
schema
tally.v1
reversibility
reversible-cheap
guarantees
deterministic, idempotent, bounded_memory
concurrency
read-only: it never writes, so any number may run at once
confinement
beneath: with --root, paths are checked lexically against it and then opened beneath it one component at a time, following no symbolic link (path.symlink), so nothing outside the root is reachable through one; without it, a reader opens the path as given, links and all, and a writer still follows no link in the file's own name
reads the environment
no
reads the clock
no
compiler
de4e52fd8180
for an agent
SKILL.md (tally skill)

Authority

Derived by cancho authority from the source, embedded in the binary, and checked against tools.toml's ceiling in CI. Every label is bounded.

What the row cannot say:

Operands

OperandRoleHow manyMeaning
FILE...path-read0 or morethe files to count, in order, none reads standard input

Flags

FlagKindRoleDefaultMeaning
--rootpathrootresolve every FILE relative to this directory and refuse paths outside it
--field -fnatnonecount field N (1-based) of each line instead of the whole line
--delim -dtextnone the one byte that separates fields (default tab)
--topnatnone10how many of the most frequent keys to report (ceiling 1000000)
--max-keysnatnone100000the most distinct keys held, one more is limit.too-many-keys (ceiling 1000000)
--max-line-bytesnatnone1048576the longest line counted, a longer one is limit.line-too-long (ceiling 16777216)
--formatchoice:json/textnonejsonjson for a program, text (count, tab, key) for a person

Limits

LimitDefaultCeiling
top101,000,000
max-keys100,0001,000,000
max-line-bytes1,048,57616,777,216

Exit codes

CodeNameMeaning
0SUCCESSwhat was asked was done; zero matches is success
1GENERAL_ERRORthe operating system failed mid-operation, or the tool caught a bug in itself
2INVALID_ARGSthe invocation is malformed or names something of the wrong kind; nothing was read
3NOT_FOUNDa named input does not exist
4PERMISSION_DENIEDthe operating system refused, or the tool's own confinement did
8PRECONDITION_FAILEDthe answer is no, or a limit was reached

Rules (17)

Match on rule, not on the message. A retry repair is an argv that can be run as it stands, and never widens what the tool may touch.

RuleExitRepairWhen
args.unknown-flag2sometimesa flag that is not in the tool's table
args.missing-value2nevera flag that takes a value was given none
args.bad-value2nevera flag's value is not of the flag's kind
args.duplicate-flag2neverthe same flag was given twice
path.empty2neveran empty path
path.dotdot2sometimesa path with a `..` component
path.absolute2alwaysan absolute path where one relative to --root is wanted
path.outside-root4neveran absolute path that is not under --root
path.too-long2nevera path longer than 4096 bytes
path.symlink4nevera path that runs through a symbolic link, which the tool does not follow
io.not-found3nevera named input does not exist
io.not-a-directory3nevera path runs through something that is not a directory
io.is-a-directory2nevera directory where a file is wanted
io.permission-denied4neverthe operating system refused access
io.read-failed1neverthe operating system failed a read
limit.line-too-long8sometimesa line longer than --max-line-bytes
limit.too-many-keys8nevermore distinct keys than --max-keys

Evidence

each gate is a test in cancho-tools/tests/conformance, run by CI on the commit this binary was built from:

Agent in the loop: not run: no claim that this tool is more agent-friendly than the incumbents is made (cancho docs/agent-toolbox.md section 7.2).