Artifact 06270dd04ec13b727b7aea9b362e070949af366088388fafba65e9ad6c52f12d:
- File
src/assets.c
— 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: 3301) [annotate] [blame] [check-ins using]
#include "assets.h" #include "platform.h" #include <errno.h> #include <stdio.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> constexpr size_t PATH_CAP = 4096; static char asset_text[ASSET_TEXT_MAX]; static size_t asset_used; typedef struct { NameList *list; AssetKind kind; const char *dir; uint8_t ward; } Listing; static int add_asset(void *state, const char *entry) { Listing *l = state; if (entry[0] == '.') return 0; char path[PATH_CAP]; [[maybe_unused]] int n = snprintf(path, sizeof path, "%s/%s", l->dir, entry); ensure(n > 0 && (size_t)n < sizeof path); // PATH_ROOM leaves room for an entry's name struct stat st = {}; (void)sys_stat(path, &st); bool wanted = l->kind == AK_SKILL ? S_ISDIR(st.st_mode) : S_ISREG(st.st_mode); if (!wanted) return 0; size_t len = strlen(entry); bool md = l->kind != AK_SKILL && len > 3 && strcmp(entry + len - 3, ".md") == 0; size_t name_len = md ? len - 3 : len; if (l->list->n == ASSET_MAX || asset_used + len + 1 + name_len + 1 > ASSET_TEXT_MAX) { say(STDERR_FILENO, "suit: the store has too many %s (limit %u, %zu bytes of names)\n", asset_kind_name(l->kind), ASSET_MAX, ASSET_TEXT_MAX); return 1; } char *file = asset_text + asset_used; memcpy(file, entry, len + 1); char *name = file + len + 1; memcpy(name, entry, name_len); name[name_len] = '\0'; asset_used += len + 1 + name_len + 1; l->list->file[l->list->n] = file; l->list->ward[l->list->n] = l->ward; l->list->name[l->list->n++] = name; return 0; } // Names in order, so the plan does not depend on the order the folder lists. // Equal names stay in the order of their wardrobes. static void sort_names(NameList *l) { for (uint32_t i = 1; i < l->n; i++) { for (uint32_t j = i; j > 0 && strcmp(l->name[j - 1], l->name[j]) > 0; j--) { const char *name = l->name[j]; const char *file = l->file[j]; uint8_t ward = l->ward[j]; l->name[j] = l->name[j - 1]; l->file[j] = l->file[j - 1]; l->ward[j] = l->ward[j - 1]; l->name[j - 1] = name; l->file[j - 1] = file; l->ward[j - 1] = ward; } } } // What every wardrobe's store holds, each asset marked with its wardrobe. int assets_load(const Wards *w, Assets *a) { static const char *const dirs[AK_COMMAND + 1] = {"skills", "agents", "commands"}; asset_used = 0; for (int k = AK_SKILL; k <= AK_COMMAND; k++) a->list[k].n = 0; for (uint32_t wi = 0; wi < w->n; wi++) { for (int k = AK_SKILL; k <= AK_COMMAND; k++) { char dir[PATH_CAP]; [[maybe_unused]] int n = snprintf(dir, sizeof dir, "%s/%s", w->w[wi].store, dirs[k]); ensure(n > 0 && (size_t)n < sizeof dir); Listing l = {&a->list[k], (AssetKind)k, dir, (uint8_t)wi}; int rc = sys_listdir(dir, add_asset, &l); if (rc > 0) return 1; if (rc < 0 && errno != ENOENT) { say(STDERR_FILENO, "suit: cannot read %s: %s\n", dir, strerror(errno)); return 1; } } } for (int k = AK_SKILL; k <= AK_COMMAND; k++) sort_names(&a->list[k]); return 0; }