Artifact 447f763bf5d0fca0dbcc22b05ab6532abe8b2335e2df8abc7f4ea61b8d2f1799:
- File
src/ledger.h
— part of check-in
[45a7e1e117]
at
2026-11-13 07:44:25
on branch trunk
— Phase 4b-2: your own assets placed inside each project that matches
An outfit worn at personal scope for a project's key is now linked into every project with that key, and into each of its linked worktrees: skills, agents, commands, instructions and files, under the folders the harness names for a project. The machine limit and joined instructions work there as they do at the User scope.
The links are hidden from version control per project, never globally. For a git project suit keeps one marked block in that project's local exclude file, leaves every other byte of the file as it was, and removes only the block on suit off. A Fossil or zit project has no such file, so its links are placed and suit status says they are visible.
Suit never runs git and never stages or commits anything. A file already in the project at a destination is a clash, left as it is and reported, so a committed file always wins.
1006 unit checks, 227 shell cases, 146 store cases, 612 placement cases and 310 project cases, under clang and under gcc 16. 100% coverage in all 19 source files. The no-change run costs about 0.43 ms over an empty program. (user: dmestas, size: 2129) [annotate] [blame] [check-ins using]
#ifndef SUIT_LEDGER_H #define SUIT_LEDGER_H #include <stddef.h> #include <stdint.h> // The ledger, $SUIT_HOME/ledger: the only record of what suit owns. One line // per thing suit made: // // link DEST SOURCE a symlink at DEST pointing at SOURCE // dir DEST a folder suit made to hold a link or a file // file DEST a file suit wrote: a joined instruction file // block DEST a marked block suit keeps in the file DEST (a project's // local exclude file); "block DEST created" if suit made // the file // // Paths are absolute, with no space or newline in them. Nothing else is // allowed in the file: a line that is not one of these is an error, and the // whole file is rejected. constexpr size_t LEDGER_FILE_MAX = 1048576; constexpr size_t LEDGER_LINE_MAX = 8192; constexpr uint32_t LEDGER_ENTRY_MAX = 4096; typedef enum { ENTRY_LINK, ENTRY_DIR, ENTRY_FILE, ENTRY_BLOCK } EntryKind; typedef struct { EntryKind kind; const char *dest; const char *src; // nullptr for a dir or a file; for a block "created" or nullptr } LedgerEntry; typedef struct { uint32_t n; LedgerEntry e[LEDGER_ENTRY_MAX]; char buf[LEDGER_FILE_MAX + 1]; } Ledger; // line is 0 when the error concerns the whole file. typedef struct { int line; char msg[256]; } LedgerError; // Parse DATA (LEN bytes). On failure L is empty and ERR says what and where. [[nodiscard]] bool ledger_parse(Ledger *l, const char *data, size_t len, LedgerError *err); // Read PATH. A file that is not there is an empty ledger. [[nodiscard]] bool ledger_load(Ledger *l, const char *path, LedgerError *err); // Write the entries, links then dirs then files then blocks, each sorted by path, atomically. Returns 0 // or an errno value. L's entries need not point into L's own buffer. int ledger_write(const Ledger *l, const char *path); // The link entry for DEST, or nullptr. const LedgerEntry *ledger_find_link(const Ledger *l, const char *dest); // The text a block entry has in SRC when suit made the file. extern const char LEDGER_CREATED[]; #endif