Artifact 90e6a487337d990aad632da0929cacf241e0a9dbb1f9bf6e760a83f1f8982b11:
- File
src/tally.h
— part of check-in
[cef6a0ad45]
at
2026-11-17 07:37:01
on branch trunk
— suit curate writes a page for deciding what each asset is worth keeping
suit curate [--since DAYS] [--out FILE] runs a usage scan and writes one self-contained HTML page, mode 0600, atomically, to curate.html in suit's home folder or to FILE. It changes no wardrobe file, config, stamp or ledger. The page names projects and stays on this machine; it loads nothing from the network and has no inline handlers.
Each skill, agent and command in the wardrobes is a row: uses in the window and in each of the last four weeks, last used, the projects it was used in, its description and what that costs every session, where it is worn, whether it is in the attic, and whether it is the owner's or an upstream's. Origin comes from the entries of the check-in the upstream's record names, so an upstream's skills beside the owner's own in skills/ are told apart. A name in two wardrobes is tagged with its wardrobe.
Each row starts from a suggestion with its reason: retire when unused in the window, unless its files changed within it; limit when three or more uses all came from one known project; otherwise keep. A folder that is not a known project cannot be limited to, and the page says how to make it one. The owner picks keep, limit or retire per row, with keys or in bulk on what is shown, and copies or saves the choices as a short text file. Applying it is a separate step, not in this check-in. The format is in docs/curate.md: one line per asset, `keep KIND WARDROBE NAME`, `retire KIND WARDROBE NAME`, or `personal KIND WARDROBE NAME PROJECT`.
The page is src/curate.html, turned into a C array at build time with od and awk, so the release build needs no other tool. Values are written as JSON with markup characters, U+2028 and U+2029 escaped and invalid UTF-8 replaced. The page script has its own test, run under node where node is installed and reported as skipped elsewhere. A new fuzz target covers the front-matter reader and the JSON writer.
Page sizes: 37 KB for the test fixture, 252 KB for 500 assets, 805 KB at the 4096-asset bound.
A new suite, test/curate.sh, with 288 cases, is part of the gate.
2993 unit checks (was 2855), 620 shell cases, 1153 store cases, 846 placement cases, 378 project cases, 236 usage cases and 288 curate cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (66 minutes, on a loaded machine; one earlier run failed only the loaded speed measurement, at 1.06 to 1.11 ms, and this run passed it at 0.99 ms). 100% coverage in all 31 source files. No existing case was changed. (user: dmestas, size: 3466) [annotate] [blame] [check-ins using]
#ifndef SUIT_TALLY_H #define SUIT_TALLY_H #include "conf.h" #include <stddef.h> #include <stdint.h> // Usage counts (docs/usage.md): what suit keeps, per machine, of how often each // skill, agent and command was invoked, read from the session records the // harnesses keep. $SUIT_HOME/usage/events and $SUIT_HOME/usage/offsets. constexpr size_t TALLY_EVENTS_FILE_MAX = 33554432; // the events file, in bytes constexpr size_t TALLY_EVENTS_NEW_MAX = 8388608; // the events one scan may add, in bytes constexpr uint32_t TALLY_EVENTS_MAX = 500000; // events kept constexpr uint32_t TALLY_FILES_MAX = 16384; // session files known at once constexpr uint32_t TALLY_ROWS_MAX = 65536; // distinct names in one report constexpr int TALLY_DAYS_KEPT = 400; // events older than this are dropped constexpr int TALLY_FIRST_SCAN_DAYS = 45; // a first scan reads files modified this recently constexpr int TALLY_WINDOW_DEFAULT = 30; // `suit usage scan`: read what is new in every harness's session records and // add it to the tally. Prints one line. 0, 1 after a message, 2 for a config // the scan cannot use, or EXIT_BUSY. int cmd_usage_scan(void); // `suit usage [--since DAYS] [--kind KIND] [--harness NAME] [--project KEY] [--tsv]`: // a scan, then the table. ARGV is what follows "usage". 2 for bad arguments. int cmd_usage(int argc, char **argv); // `suit tend` with no name: tend every wardrobe, then scan once. The scan's // failure is reported and does not change the exit status. int cmd_tend_all(void); // ---- for `suit curate` (docs/curate.md) ----------------------------------------- // One event of the tally. The pointers stay valid until the process ends. // TIME starts with "YYYY-MM-DDTHH:MM:SS" (TALLY_TIME_LEN bytes). typedef struct { const char *time; UseKind kind; const char *name; size_t name_len; const char *project; size_t project_len; } TallyEvent; typedef void (*TallyEventSink)(void *state, const TallyEvent *ev); constexpr size_t TALLY_TIME_LEN = 19; // A scan as `suit usage` does it, then the events kept are held for tally_each. // Returns what `suit usage` returns: 0, 1 after a message, 2 (no wardrobe, a bad // config), or EXIT_BUSY. The config and the wardrobes it read, and the time the // scan took as "now", are then available below. int tally_open(void); void tally_each(TallyEventSink sink, void *state); const Conf *tally_conf(void); const Wards *tally_wards(void); int64_t tally_now(void); // Whether the harness section SEC of tally_conf() has `sessions` and a `use` rule. bool tally_scannable(const Section *sec); // ---- for the tests ---------------------------------------------------------- // SEC seconds since 1970 as "YYYY-MM-DDTHH:MM:SS" into OUT (20 bytes). void tally_civil(int64_t sec, char out[20]); // Whether the LEN bytes start with a time of that form and hold no tab or newline. bool tally_time_ok(const char *t, size_t len); // Drop the lines of BUF (LEN bytes, each ending in a newline, starting with a // time) whose time is before CUTOFF, then lines from the front until at most // MAX_EVENTS lines and MAX_BYTES bytes remain. Returns the new length. size_t tally_trim(char *buf, size_t len, const char *cutoff, uint32_t max_events, size_t max_bytes); // Whether the PLEN bytes of PATTERN, with "*" for any run of bytes, match all of NAME. bool tally_wild(const char *pattern, size_t plen, const char *name); #endif