Artifact 78703cd83d106360d19fe2b2b94b0b25fdd666e0ca5b6f13fdc58b9ffe7bc3d7:
- File
src/resolve.h
— part of check-in
[f96cbc3342]
at
2026-11-13 03:51:02
on branch trunk
— Phase 4a: outfits limited to a machine, and instruction files joined
suit machine shows or sets this machine's name. An outfit worn with machine=NAME applies on that machine and nowhere else, and where it and an unlimited outfit supply the same destination the machine's wins.
A harness has one instruction file per scope. When the unlimited and the machine-limited outfit both supply instructions, suit writes one file with the unlimited text first and the machine's after it, and links the harness to that. It is rewritten when either source changes and removed when no longer needed. This is the one case where an edit in the store reaches a harness only after suit's next run.
The ledger gains an entry for a file suit wrote, so suit off removes the joined file too.
420 unit checks, 227 shell cases, 146 store cases, 612 placement cases, under clang and under gcc 16. 100% coverage in all 16 source files. The no-change run costs about 0.46 ms over an empty program quiet and 0.66 to 0.79 ms loaded.
The checked-in fuzz corpus now includes inputs grown for the ledger reader (61) and more for the stamp reader (108), beside the config parser's 300. The replay tool's input table grew, because fuzzing had filled the old one on the development machine. (user: dmestas, size: 2599) [annotate] [blame] [check-ins using]
#ifndef SUIT_RESOLVE_H #define SUIT_RESOLVE_H #include "conf.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 store holds: 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". typedef struct { uint32_t n; const char *name[ASSET_MAX]; const char *file[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 } 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. constexpr size_t JOIN_PATH_MAX = 4096; 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[CONF_HARNESS_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 } Plan; typedef struct { char msg[512]; } ResolveError; // HOME expands a leading ~; STORE is the store's folder 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 char *store, const char *machine, Plan *p, ResolveError *err); // 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