Artifact 82ba0428d5a934086c552b2755e33d29f8350d00108cdd813c77598bc1b2bcef:
- File
src/resolve.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: 5834) [annotate] [blame] [check-ins using]
#ifndef SUIT_RESOLVE_H #define SUIT_RESOLVE_H #include "conf.h" #include "project.h" #include <stddef.h> #include <stdint.h> // Resolve works out the placements of the User scope from a parsed config and // a listing of the store. It reads nothing and changes nothing. typedef enum { AK_SKILL, AK_AGENT, AK_COMMAND, AK_INSTRUCTIONS, AK_FILE, AK_SLOT, AK_COUNT } AssetKind; constexpr uint32_t ASSET_MAX = 2048; // names per kind constexpr uint32_t PLACE_MAX = 4096; // placements constexpr uint32_t SKIP_MAX = 1024; // skipped lines constexpr size_t SKIP_LEN = 256; constexpr size_t PLAN_TEXT_MAX = 524288; // paths in a plan // What the stores hold: for a skill the name is the folder's name; for an // agent or a command the name is the file's name without a trailing ".md". // ward is the wardrobe whose store holds it. typedef struct { uint32_t n; const char *name[ASSET_MAX]; const char *file[ASSET_MAX]; uint8_t ward[ASSET_MAX]; } NameList; typedef struct { NameList list[AK_COMMAND + 1]; // skills, agents, commands } Assets; typedef struct { const char *dest; const char *src; const char *harness; // "-" for a file or a slot AssetKind kind; bool limited; // supplied by a wear limited to this machine const char *project; // the project folder a personal placement is in; nullptr for the User scope ProjectKind vcs; // that project's kind const char *outfit; // the outfit that asked for it const char *ward; // the wardrobe whose store holds src (a file suit joins has the first's) } Placement; // A file suit writes: FIRST's content, a blank line, SECOND's content. It is // the source of the placement that has the same path as its source. // Each join takes two placements, so a plan has at most half as many joins. constexpr uint32_t JOIN_MAX = PLACE_MAX / 2; constexpr size_t JOIN_PATH_MAX = 4096; // One place that supplies an asset, for `suit why`: what resolve decided about // it. PENDING is internal and never survives a resolve. typedef enum { FATE_PENDING, FATE_PLACED, FATE_DROPPED, FATE_JOINED, FATE_OTHER_MACHINE, FATE_NO_PROJECT, FATE_NO_FOLDER } Fate; constexpr uint32_t SUPPLIER_MAX = 64; // suppliers of the one name asked about typedef struct { const char *scope; // "user" or "personal" const char *key; // the project's key for personal, else "" const char *machine; // the machine the wear is limited to, "" if none const char *outfit; const char *harness; // "-" for a file or a slot const char *dest; // "-" if there is none (no folder, or no project) const char *src; const char *project; // the project folder; nullptr for the User scope and for no project const char *ward; // the wardrobe that supplies it AssetKind kind; Fate fate; } Supplier; typedef struct { char path[JOIN_PATH_MAX]; const char *first; // the unlimited wear's instructions const char *second; // the machine-limited wear's } Join; typedef struct { uint32_t n; Placement p[PLACE_MAX]; uint32_t njoins; Join joins[JOIN_MAX]; uint32_t nskips; char skips[SKIP_MAX][SKIP_LEN]; // "skipped ..." lines char text[PLAN_TEXT_MAX]; size_t used; bool overflow; // a path did not fit in text uint32_t nsuppliers; // resolve_why only Supplier sup[SUPPLIER_MAX]; } Plan; typedef struct { char msg[512]; } ResolveError; // The Project personal scope is placed in every project of PROJECTS whose key a // `[wear personal KEY]` names, inside the project's folder. // HOME expands a leading ~; WARDS says where each wardrobe's store is (every // path and asset name an outfit or a need gives is in the store of the wardrobe that defines it) // and SUIT_HOME holds slots/ and joined/. MACHINE is this machine's name, "" if it has none: a wear // limited to another machine is ignored. On success P is sorted by destination // with no duplicates. [[nodiscard]] bool resolve(const Conf *conf, const Assets *assets, const char *home, const char *suit_home, const Wards *wards, const char *machine, const Projects *projects, Plan *p, ResolveError *err); // resolve, and in P->sup every place that supplies the asset NAME (the name of a // skill, agent or command with or without .md, "instructions", a slot's name, a // file's destination as the config gives it), with what resolve decided about // each: placed, dropped for a machine-limited one, joined, or never applied. [[nodiscard]] bool resolve_why(const Conf *conf, const Assets *assets, const char *home, const char *suit_home, const Wards *wards, const char *machine, const Projects *projects, const char *name, Plan *p, ResolveError *err); // For `suit curate` (docs/curate.md): which assets each outfit lists, and which // outfits each wear reaches. SINK is called, for every outfit of the set, with a // null WEAR for each asset the outfit lists (a `skills`, `agents` or `commands` // entry, `*` and patterns included, matched among the assets of the outfit's own // wardrobe), and then, for every wear section of any scope and limit, with that // wear for each asset of every outfit the wear names, includes and all. KIND and // INDEX say which asset of ASSETS. A wear limited to another machine is reached // all the same: the config is the wardrobe's, shared between machines. typedef void (*ReachSink)(void *state, const Section *wear, const Section *outfit, AssetKind kind, uint32_t index); void resolve_reach(const Conf *conf, const Assets *assets, ReachSink sink, void *state); // The kind's name as the config and the reports spell it. const char *asset_kind_name(AssetKind kind); // True if NAME matches PATTERN, where * matches any run of characters. bool glob_match(const char *pattern, const char *name); #endif