Artifact c88352b72448ae77521cf232624a3ea0266d39e44f185a9b7a10fc310ca0e13e:
- File
src/curate.h
— part of check-in
[1ed63201f4]
at
2026-11-18 03:02:04
on branch trunk
— suit curate apply turns the page's choices into config changes
suit curate apply FILE reads the choices file the curation page makes and prints a plan: which outfits and wears it edits, which wardrobes it checks in and in what order, and the links that will appear and disappear at each scope. Without --yes nothing changes. With --yes it edits each wardrobe's suit.conf and checks it in, with a comment such as "Curate: 3 kept, 1 limited, 12 retired". It does not place anything; the next run sees the config changed and applies.
- keep leaves a worn asset as it is. A loose asset, or one coming back from the attic, goes to the outfit kept.WARDROBE, worn at user scope. - limit moves the asset from its user outfits to personal.WARDROBE.SLUG, worn by [wear personal PROJECT], created or reused wherever it is. - retire removes the asset from every outfit of its wardrobe and adds it to attic.WARDROBE, which nothing wears. Apply refuses if a wear reaches an attic. - Removing one name from an outfit that lists `*` turns the `*` into an explicit list of the names it reached, minus that one, and the plan says so: names added to the store later are then not included by that outfit. No exclusion syntax was added.
Outfit names carry the wardrobe because outfit names are one set across wardrobes; a name too long for that is refused for its line. A wardrobe that defines a new outfit is checked in before any wardrobe whose wear names it, so a failure part-way leaves only an outfit nothing wears; a run that would need the opposite order is refused before anything changes.
Configs are edited as text: only the lines that must change are rewritten, and comments, blank lines, alignment, line endings and the order of everything else are kept. Every edited config must parse and the combined set must pass the merge check before anything is written. A wardrobe with local changes is refused, so the check-in holds the curation only. A failed check-in puts that wardrobe's file back.
A malformed line, a duplicate, a bad header or a path given as a project refuses the whole file, listing every problem. An unknown asset is warned about and skipped; a choice already true is silent.
A new suite, test/curate_apply.sh, with 376 cases, is part of the gate, and a new fuzz target covers the choices parser and the line editor.
3669 unit checks (was 2993), 625 shell cases, 1153 store cases, 985 placement cases, 378 project cases, 236 usage cases, 288 curate cases and 376 curate-apply cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (44 minutes). 100% coverage in all 32 source files. No existing case was changed. (user: dmestas, size: 6965) [annotate] [blame] [check-ins using]
#ifndef SUIT_CURATE_H #define SUIT_CURATE_H #include "conf.h" #include <stddef.h> #include <stdint.h> // `suit curate` (docs/curate.md): one self-contained HTML page that shows every // skill, agent and command of the wardrobes beside how it is used, and a text // file of the choices made on it. It changes nothing else. constexpr uint32_t CURATE_ASSETS_MAX = 4096; // assets on a page constexpr uint32_t CURATE_PROJECTS_MAX = 64; // projects listed for one asset; the rest are summed constexpr uint32_t CURATE_TOP = 10; // names used that match no asset, listed constexpr size_t CURATE_HEAD_MAX = 16384; // bytes of a file read for its description constexpr size_t CURATE_DESC_KEEP = 300; // bytes of a description kept constexpr uint32_t CURATE_FILES_MAX = 4096; // files of one asset counted for its size constexpr int CURATE_DEPTH_MAX = 16; // folders nested in one asset counted for its size constexpr size_t CURATE_PAGE_MAX = 16777216; // bytes of the page constexpr uint32_t CURATE_RECS_MAX = 600000; // (asset, project) uses and unmatched uses held at once // `suit curate [--since DAYS] [--out FILE]`. ARGV is what follows "curate". // 0; 1 after a message (a file cannot be read or written, a bound is passed); // 2 for bad arguments or a config that cannot be used; EXIT_BUSY. int cmd_curate(int argc, char **argv); // ---- `suit curate apply` (docs/curate.md, "Applying the choices") ----------------------------- // `suit curate apply FILE [--yes]`. ARGV is what follows "apply". 0 when done, or when nothing // was to be done, or the plan was shown; 1 when an operation failed; 2 for bad arguments or a // refused file or config; EXIT_LOCAL_CHANGES (12); EXIT_NEEDS_REPAIR (15); EXIT_BUSY (20). int cmd_curate_apply(int argc, char **argv); constexpr size_t CHOICE_PROJECT_MAX = 512; // bytes of a PROJECT in the choices file constexpr size_t CHOICES_FILE_MAX = 4194304; // bytes of a choices file typedef enum { CHOICE_KEEP, CHOICE_PERSONAL, CHOICE_RETIRE } ChoiceAct; typedef struct { ChoiceAct act; int kind; // 0 skill, 1 agent, 2 command, as AssetKind char ward[CONF_NAME_MAX + 1]; char name[CONF_NAME_MAX + 1]; char project[CHOICE_PROJECT_MAX + 1]; // personal only } CurateChoice; // What a line of a choices file is: blank or a comment; a choice; malformed (MSG says // how); or a personal choice whose PROJECT is a folder (starting with ~ or /) or `-`, // which a config cannot name as a TARGET: refused, MSG says so. typedef enum { CHOICE_NONE, CHOICE_OK, CHOICE_BAD, CHOICE_FOLDER } ChoiceLine; // True if the LEN bytes are the first line, `# suit choices 1` (a final CR is allowed). bool curate_choices_header(const char *line, size_t len); // Parse one line of LEN bytes, without its newline, into C. MSG (CAP bytes) is set for // CHOICE_BAD and CHOICE_FOLDER. ChoiceLine curate_choice_parse(const char *line, size_t len, CurateChoice *c, char *msg, size_t cap); // The name of the outfit of wardrobe WARD that holds what is limited to PROJECT: // `personal.WARD.` and PROJECT with every byte outside A-Z a-z 0-9 . _ - replaced by `-`, cut // to fit CONF_NAME_MAX bytes; for N above 1, with `-N` at the end (the second project that // would have the same name). OUT has CONF_NAME_MAX + 1 bytes. Returns the length, or 0 when // `personal.WARD.` and the suffix do not fit in CONF_NAME_MAX bytes (the wardrobe's name is too long). size_t curate_personal_outfit(const char *ward, const char *project, unsigned n, char *out); // BASE.WARD (BASE is attic or kept) into OUT (CONF_NAME_MAX + 1 bytes): its length, or 0 if it does not fit. size_t curate_home_outfit(const char *base, const char *ward, char *out); // Whether the outfit NAME is an attic: `attic`, or `attic.` and more. Nothing it lists is worn. bool curate_is_attic(const char *name); // Edits of a suit.conf as text, in TEXT (LEN bytes, room for CAP), changing only the lines // named. Lines are counted as the parser counts them. A new line ends as the first line of the // file does (CR LF or LF). typedef enum { EDIT_OK, EDIT_LONG, EDIT_FULL } EditResult; // Rewrite the value of the entry `KEY = VALUE` on LINE with the N WORDS joined by single spaces, // leaving the key as written and what follows the value (spaces, a comment, a CR) as it was; // with N 0, remove the line. EDIT_LONG: the line would pass CONF_LINE_MAX bytes. EDIT_FULL: the // text would pass CAP bytes. Nothing is changed for either. EditResult curate_edit_value(char *text, size_t *len, size_t cap, int line, const char *const *words, size_t n); // Insert the line ENTRY after LINE. EditResult curate_edit_insert(char *text, size_t *len, size_t cap, int line, const char *entry); // Append, after one blank line (none if the text is empty or already ends in one), the line HEADER and, // if ENTRY is not null, the line ENTRY. EditResult curate_edit_append(char *text, size_t *len, size_t cap, const char *header, const char *entry); // ---- for the tests ---------------------------------------------------------- // The `description` of the front matter in the first LEN bytes of a file, whitespace // collapsed, into OUT (room for LEN + 1 bytes), and its length: 0 when there is no // front matter (a first line "---" and a later one) or no description. size_t curate_front_description(const char *data, size_t len, char *out); // The length of the first MAX bytes of S (LEN bytes) cut so as not to split a UTF-8 character. size_t curate_cut(const char *s, size_t len, size_t max); // A bounded buffer. OVER is set when something did not fit; nothing is then added. typedef struct { char *p; size_t cap; size_t len; bool over; } CurateBuf; // Append the N bytes of S to B, or set OVER if they do not fit. void curate_put(CurateBuf *b, const char *s, size_t n); // Append the LEN bytes of S as a JSON string, quotes included, in which every // "<", ">", "&", U+2028 and U+2029 is a \u escape and every byte that is not // UTF-8 is U+FFFD. void curate_json_string(CurateBuf *b, const char *s, size_t len); // Call CB for the index of each of the N names (sorted, byte order) that the // usage name USAGE (LEN bytes) is an invocation of: it is equal to the name, or // ends with a colon and the name. Returns how many. uint32_t curate_matches(const char *const *names, uint32_t n, const char *usage, size_t len, void (*cb)(void *state, uint32_t index), void *state); // The times, as "YYYY-MM-DDTHH:MM:SS", from which a use counts: in the window of // DAYS, in the last 90 days, and in each of the last four 7-day periods before NOW. typedef struct { char window[20]; char d90[20]; char week[4][20]; } CurateCuts; void curate_cuts(int64_t now, int days, CurateCuts *c); // The period of the time T (at least TALLY_TIME_LEN bytes): 0 the oldest to 3 the // newest, -1 when it is older than 28 days. int curate_week(const CurateCuts *c, const char *t); #endif