Artifact 95c6232502c1c4e9795576d72720fa48760a223191fe100e914f55191161f103:
- File
docs/upstreams.md
— part of check-in
[75c8fde976]
at
2026-11-18 23:06:52
on branch trunk
— Instructions join per harness, and an upstream can be a local folder
A harness's instruction file is now joined from up to four suppliers, ranked: the shared one, the harness's own (an outfit with only = HARNESS), the one limited to this machine, and the machine's own for that harness. Each rank has at most one supplier; more than one rank is joined in that order, each source as it is in the store, separated by a blank line. One supplier still links straight to the store's file. So every harness can read a shared file and one harness an extra one, where an only outfit's instructions used to clash with the shared ones. The same rule holds at personal scope.
An upstream whose url is file:// and an absolute path is a local upstream. suit upstream NAME take with no FOLDER takes from it. The hourly suit tend takes every local upstream whose folder changed since its last take, and accepts it when trust = auto, so a skill whose home is one of the owner's own repositories is placed without a copy kept by hand. Changed is decided by a stamp of the folder kept in suit's home folder (path, size, mtime, inode and executable bit of each entry): an unchanged hour costs one lstat per entry and opens no file of the upstream. As with the no-change run, an edit that keeps a file's size and mtime is not seen until the next one that does not. A missing folder is one attention item that clears when it is back. The take comment names the folder, and the pin when there is one.
Three upstream usage cases changed their expected text, because take no longer needs a FOLDER.
3828 unit checks (was 3792), 625 shell cases, 1258 store cases (was 1153), 1032 placement cases (was 985), 382 project cases (was 378), 237 usage cases (was 236), 288 curate cases, 376 curate-apply cases and 172 https cases, under clang, under gcc 16, with no user name set and umask 002, and under umask 027, in one run of make gate (77 minutes). 100% coverage in all 34 source files. (user: dmestas, size: 21882) [annotate] [blame] [check-ins using]
# Upstreams An upstream is a source of assets that someone else maintains ([vocabulary.md](vocabulary.md)). Its files come into a wardrobe from a folder on disk, wait there for review, and are merged into trunk. A local fix survives an update, and an update that would overwrite one waits for you. This page is part one (phase 8c-1): taking from a folder. Fetching an archive over HTTPS is part two and is not built. ## The model - Each upstream has a branch of its own, `upstream-NAME`, in the repository of the wardrobe whose `suit.conf` defines it ([conf-format.md](conf-format.md), "More than one wardrobe"). Branches travel with the wardrobe: `suit sync`, `suit tend` and `suit clone` carry every branch, so a take on one machine is seen on the others. - The branch holds only that upstream's files, at `INTO/ENTRY/...` for each entry (file or folder) of the folder read. Its first check-in has trunk's first check-in, the empty one every wardrobe starts with, as its parent, so trunk and the branch share an ancestor and a later merge is three-way. Each take after that is one check-in on top of the branch's tip. - The base of each merge is the check-in of the branch whose files trunk holds now, the one the record `upstreams/NAME` names ("The record"), not the newest ancestor trunk and the branch share. - Updates merge into trunk, in the working copy, after a dry run. A file you edited and the upstream changed on a different line merges; the same line is a conflict, and nothing is changed. - An update waits for review unless the upstream says `trust = auto`. - Taking never touches the working copy. The check-in is built from a deck (libfossil's own calls, `fsl_deck_save`) in the wardrobe's repository, with no checkout, so your edits, new files and the files suit placed stay as they are. Every byte of a file that suit writes into the working copy goes through suit's file writer, as for an update. ## The config ``` [upstream mattpocock] url = https://github.com/mattpocock/skills pin = de4f182c30876a2460ca307e2f601b9b892527e5 path = skills/engineering into = skills trust = review ``` | Key | Meaning | Default | |---|---|---| | `url` | `file://` and an absolute path makes a local upstream ("Local upstreams"). Any other url is where part two will fetch from, and `take` does not use it. | none | | `pin` | A word naming the version. Required by `take` unless the url is local, at most 256 bytes. It is a label: suit cannot check that a folder matches it. It is written into the check-in's comment. | none | | `path` | The folder of the upstream to read, relative to FOLDER, with no `..` part. | the folder's top | | `into` | Where the files land in the wardrobe: a relative path of names, at most 256 bytes, no empty, `.` or `..` part and no part that starts with a dot. | `skills` | | `trust` | `review` or `auto`. | `review` | An upstream that carries two kinds of asset is written as two sections that share `url` and `pin`, one for each `into`. ## Commands | Command | Does | Exit codes | |---|---|---| | `suit upstream NAME take [FOLDER]` | Checks the files of FOLDER in on the branch. With no FOLDER, takes from the local url. With `trust = review` leaves an item in the attention file. With `trust = auto` goes on as `accept` does. | 0, 1, 2, 3 lint, 12, 13, 15 | | `suit upstream NAME diff` | Prints what `accept` would change in trunk. Changes nothing. | 0, 1, 2, 12, 15 | | `suit upstream NAME accept [--theirs PATH] [--mine PATH]...` | Merges the branch's tip into trunk. | 0, 1, 2, 12, 13, 15 | | `suit upstream NAME undo` | Reverses the newest accept not yet undone, by a new check-in on trunk. | 0, 1, 2, 12, 13, 15 | | `suit upstreams` | One line for each upstream of every wardrobe. Changes nothing. | 0, 1, 2, 15 | Exit 2 is a usage or config error: an upstream the config does not define (the message names it), a missing `pin`, a `path` with a `..` part or an absolute one, a `--theirs` or `--mine` path that is not a conflict it can settle. Exit 1 is any other error (a folder that cannot be read, a symlink, a limit, a clash). Exit 3 is a lint finding, 12 is local changes in the working copy, 13 is a conflict, 15 is an unfinished update ([store.md](store.md), "The journal and repair"). ### take `FOLDER` is a folder on disk. It may be left out when the url is local ("Local upstreams"); otherwise a take with no FOLDER is exit 2. With `path` set, the folder read is `FOLDER/PATH`, which must exist and be a folder. 1. Names that start with `.` are skipped at any depth, so `.git` never comes in. 2. A symlink is refused: the take fails, naming the link. Only regular files and folders are taken; a fifo or a socket is refused the same way. The executable bit of a file is kept. 3. At most 4096 files and 64 MiB in all (`UPSTREAM_FILES_MAX`, `UPSTREAM_BYTES_MAX`). Over either, nothing is checked in and the message says which. A path is at most 512 bytes inside `INTO`, and folders nest at most 32 levels, counting the folder read as the first; over either, the take fails. 4. A folder that holds no file to take (nothing, or only names that start with a dot) is refused. 5. The lint that runs at check-in runs on the files to be taken, with the rules of the wardrobe's `suit.lint` ([store.md](store.md), "The lint"), and the skill folder rule applies to what lands under `skills/`. A finding stops the take, listed as the lint lists it, with exit 3. 6. A file the take would add at `INTO/...` that trunk already has, and that is neither in the tree of the last check-in on this branch nor in the check-in trunk's `upstreams/NAME` names (an undo can bring back a file a later take removed), is a clash: the take fails naming the file, with exit 1. If another upstream's branch holds the file the message names that upstream. Two upstreams may not supply the same path. Nothing is changed. 7. If the files, their modes and their content, are the branch tip's, nothing is checked in: `upstream NAME: no change`, exit 0. 8. Otherwise one check-in on `upstream-NAME` with the comment `upstream NAME at PIN`, or `upstream NAME from FOLDER` for a local upstream, with ` at PIN` after it when the config has a pin. Files the upstream no longer has are removed on the branch. 9. With `trust = review`: `upstream NAME: update waiting for review`, once in the attention file for the upstream (replaced, never repeated), and on standard output. With `trust = auto`: the same item is written, then the take goes on as `accept` and removes it when that merges; a conflict leaves the item described below and exits 13. The take is one transaction. A lint finding, a clash, or a failed write leaves the repository, the working copy and the attention file as they were. ### accept Merges the tip of `upstream-NAME` into trunk, in the working copy of the wardrobe that defines it, with the discipline of the fork merge in `suit sync` ([store.md](store.md)). 1. Nothing taken yet: exit 1. The working copy is not at trunk's tip: exit 1, run `suit store update NAME`; the merge is made at trunk's tip so that its check-in builds on trunk and never forks it. 2. The working copy's `upstreams/NAME` already names the branch's tip: `upstream NAME: nothing to accept`, exit 0. A stale attention item for the upstream is dropped. 3. Local changes in the working copy stop it: `local changes: run suit commit or wait for suit tend`, exit 12. 4. A dry run, against the base the record names ("The record"). A file changed on both sides merges when the changes do not overlap (a line-level three-way merge, as libfossil does it) and is a conflict when they do. Also conflicts: a binary file both sides changed, a file one side changed and the other deleted, and a file added over an untracked file. 5. No conflict: the merge is made through suit's file writer and the journal, the record `upstreams/NAME` is written (below), and the merge is checked in as `Merge upstream NAME at PIN`, where PIN is the pin the branch was taken at. The attention item is removed. 6. Any conflict: no file changes, no conflict marker is written anywhere, the attention item becomes `upstream NAME: N files conflict`, `conflict PATH` is printed for each, in byte order of path, and the exit is 13. 7. `--theirs PATH` takes the upstream's version of a conflicting file and `--mine PATH` keeps trunk's. Each can be given more than once, up to 64 paths for each, and the rest is merged. It succeeds only if every conflict is named. With conflicts left, those are listed and counted and nothing changes. A PATH that is not a conflict it can settle (not in conflict at all, or a file added over an untracked file, which the merge would overwrite) is an error, exit 2, and a PATH named by both is a usage error. 8. An accept that was undone can be made again, and so can a newer take: the base is the check-in the record names after the undo ("Undo"). `--theirs` and `--mine` first let the merge write the files, with markers in the ones that overlap, then replace each settled file with the chosen version. The journal covers a stop part way, as for an update. ### diff One line for each file `accept` would change in trunk, in byte order of path: `add PATH`, `change PATH`, `remove PATH` or `conflict PATH`. It prints the list only. A unified diff of trunk's version against the merged result is not printed: libfossil can merge and diff text, but a merged result only exists once the merge has written files, and `diff` changes nothing. The exit is 0 even when there are conflicts, since the lines say so. The same checks as `accept` apply first (nothing taken, not at trunk's tip, nothing to accept, local changes). ### upstreams One line for each upstream of every wardrobe, in byte order of name: ``` NAME: STATE (taken PIN_TAKEN, config PIN) ``` `PIN_TAKEN` is read from the comment of the branch's tip and `PIN` is the config's (`none` when it has none). `STATE` is one of: - `never taken`: no branch yet (the line is `NAME: never taken (config PIN)`). - `current`: the working copy's `upstreams/NAME` names the branch's tip. - `waiting for review`: it does not, or there is no such file or it is malformed. - `conflict`: it is not, and the attention file holds `upstream NAME: N files conflict`. ## The record Every accept that succeeds writes one small tracked file in the wardrobe, `upstreams/NAME`: the full hash of the `upstream-NAME` check-in that was accepted, a space, its pin and a newline. It is written through suit's file writer after the merge and any settling are applied and before the check-in, and is part of the merge check-in, so that check-in always changes at least that file and libfossil's refusal of an empty check-in cannot arise. It is how suit knows an upstream is `current`: the file names the branch's tip, whatever the merge did, and it travels with the wardrobe, so another machine sees it after `suit sync`. It is not decided by asking libfossil whether the tip is an ancestor, because a merge settled with `--mine` can be checked in without a merge parent (observed in the library's `plink` table), which would leave the upstream `waiting` for ever. A missing or malformed file means never accepted; the next accept rewrites it. The record is also the base of the next merge. `accept` and `diff` merge the branch's tip into trunk against the check-in the record names (libfossil's `baselineRid`, fossil's `merge --baseline`), or against trunk's first check-in, the parent of the first take, when there is no record. So what is merged is always the upstream's change from the files trunk took last to the tip, whatever trunk's history holds: after an undo, whose undone tip stays an ancestor of trunk, and after `--mine`, whose check-in has no merge parent. A record that is there but names no check-in of the branch (changed by hand) leaves the base to the newest ancestor trunk and the branch share, as libfossil finds it. The merge check-in still has the tip as its second parent, so `fossil timeline` and `zit` show the branch merged into trunk as before. The lint passes it, a take does not treat it as a clash (it is in no upstream's `into` unless you point `into` at `upstreams`), and placing reads only the `skills`, `agents` and `commands` folders, so it is never placed. `diff` does not list it. ## The attention file One item for each upstream, replaced and never repeated ([store.md](store.md), "The attention file"): - `upstream NAME: update waiting for review`, from a take. - `upstream NAME: N files conflict`, from an `accept` that found conflicts. N counts the ones left after `--theirs` and `--mine`. A clean `accept` removes it. The item belongs to the machine that took: another machine sees the update through `suit upstreams`. An item of an upstream is kept apart from the items of a wardrobe: `suit tend` of a wardrobe that has the same name as an upstream leaves the upstream's item, and the reverse. When `suit sync` (or `suit store update`) brings the working copy to a newer version, each upstream branch in the wardrobe's repository whose tip the working copy's `upstreams/NAME` records as accepted has its item removed, so an accept made on another machine does not leave a stale item here. Items of upstreams still waiting stay. The check reads the record, not the config, and does nothing when the repository has no upstream branch. ## Undo `suit upstream NAME undo` reverses the newest accept of NAME that has not been undone, in the wardrobe that defines it. It is a new check-in on trunk. It never rewrites history and never moves a branch. `suit back` cannot do this: the undo record libfossil keeps for a merge ends when the merge is checked in, so after an accept, as after any `suit commit`, `suit back NAME` says it cannot go back (exit 14) and changes nothing. Each of these stops with its own message and changes nothing: 1. NAME is not an upstream of any wardrobe: exit 2. 2. Local changes in the working copy: `local changes: run suit commit or wait for suit tend`, exit 12. 3. The working copy is not at trunk's tip: exit 1, run `suit store update NAME`, as for `accept`. 4. An unfinished update: exit 15. 5. Nothing to undo: `upstream NAME: nothing to undo`, exit 0. That is when `upstreams/NAME` is missing or not whole (a hash of 40 to 64 hex digits, a space, a pin, a newline and nothing after), or when no accept of NAME is left in trunk's history. Let M be the check-in of the accept: the newest check-in in trunk's history whose comment is `Merge upstream NAME at PIN`, not counting one that a later `Undo upstream NAME at PIN` already reversed (each undo hides the accept below it, so two undos in a row reverse two accepts). Let P be M's first parent, which is trunk just before the accept. For every file M changed relative to P (added, changed or removed, the record file included, a change of the executable bit too): - If the file at trunk's tip is byte for byte, and mode for mode, what M made of it (or still absent, when M removed it), it goes back to its content in P, or is removed when P did not have it. - Otherwise it changed after the accept, and that is a conflict. So is a file that would come back where an untracked file of yours is. With any conflict no file changes, `conflict PATH` is printed for each in byte order of path, `upstream NAME: N files conflict; undo changed nothing` goes to standard error, and the exit is 13. There is no `--mine` or `--theirs`: settle the files by hand and run it again. A file the accept did not change is not looked at, so an edit of yours to one survives the undo. The files are written through suit's file writer and the journal, as for `accept`, and checked in on trunk as `Undo upstream NAME at PIN`, PIN being the pin recorded for M. It is an ordinary check-in with one parent. A failed step puts every file back, and the repository and the attention file stay as they were. The record file goes back to its content in P: the previous accepted hash and pin, or no file when P had none. So `suit upstreams` says `waiting for review` again, since the branch's tip is not the accepted one, and the item `upstream NAME: update waiting for review` is written, as after a take with `trust = review`. This holds for `trust = auto` too: an undo is never followed by an automatic accept, and a later take of the same files says `no change`. ### After an undo The record names the previous accepted check-in, or is gone, so `accept` merges the branch's tip against that ("The record"). Accepting the undone update again gives trunk the files it had after the accept that was undone, byte for byte, and `diff` lists what that would change. A newer take is merged the same way: all of its changes since the check-in the record names come in, not only those since the undone take, and your edits to other lines stay. With `trust = auto` such a newer take is accepted as any take is; the undo itself is never followed by an automatic accept. ## Limits of the library - A file one side deleted and the other changed is not reported by libfossil's merge: it drops the file the upstream deleted even if you changed it, and leaves out one you deleted and the upstream changed. Suit finds both by comparing the base's files with each side's, and counts them as conflicts. `--mine` and `--theirs` settle them. - Left alone, libfossil merges against the newest ancestor trunk and the branch share, which after an undo or a `--mine` is not what trunk holds; suit names the base itself ("The record"). Only a record changed by hand so that it names no check-in of the branch falls back to that ancestor. - Updating a working copy to a version that has fewer files leaves the empty folders behind, so on another machine an undo that removed a folder's last file leaves the folder, empty. ## Local upstreams Some assets live in a repository of your own on this machine. An upstream whose `url` is `file://` and an absolute path is a local upstream, and that folder stays the one source of its assets: no copy of them is kept in a wardrobe except the branch and what is accepted from it. ``` [upstream context] url = file:///home/me/projects/context/skill into = skills trust = auto ``` - The folder is the path in the url, and `path` goes below it as for any take. `suit upstream NAME take` with no FOLDER takes from it; with a FOLDER, the FOLDER is read instead, as for any upstream. - `pin` is optional. The take's comment is `upstream NAME from FOLDER`, and `upstream NAME from FOLDER at PIN` if the config has a pin. The folder's own version (the commit of a git, fossil or zit checkout it is in) is not read: that would take a child process or a second reader of repositories for a label, and a take's content is what the branch records. `suit upstreams` shows `from FOLDER` where it shows a pin. - `suit tend` with no name, the hourly pass, takes each local upstream after the wardrobes are tended and before the usage scan, if its folder changed since its last take. With `trust = auto` it then accepts as a take does; a conflict leaves its item ("The attention file") and is not tried again until the folder changes. A take whose content is the branch tip's does nothing, as always. The exit of `suit tend` is the worst exit of a take; a conflict does not count, a folder that is missing does not, and a config that cannot be read is said and does not either, as for the usage scan. - A missing folder is one attention item, `upstream NAME: folder FOLDER is missing`, and not an error. It replaces the upstream's other item, and goes when the folder is back: if the upstream is then waiting for review, that item returns. An item of a conflict is not restored; `suit upstream NAME accept` finds it again. - A url of `file://` followed by anything but a slash is exit 2 where it is used. A path that is not a folder is exit 1 (`is not a folder`). ### The stamp Deciding that a folder changed must not read it every hour. The take reads the folder's files; the stamp only looks at them. It is one number over every file and folder a take would read (names that start with a dot are skipped, as for a take): the path, size, modification time to the nanosecond, inode, and whether it is a file and executable. It also covers the folder's own path and `into`. It is kept in `$SUIT_HOME/upstream-NAME.stamp`, a line of text, written beside, synced and renamed, not in a wardrobe, so another machine decides for itself. A tend with nothing changed makes one `lstat` for each file and folder and one read of the stamp, and opens no file of the upstream. The cost is the walk, which is as large as the folder (at most 4096 files). Only a take that went through, or that ended in a conflict, saves the stamp, so one that failed (a lint finding, a clash, a symlink) is tried again at the next tend. A stamp that cannot be read is not the stamp: the folder is taken, and the take finds no change if there is none. A failed write is exit 1 and leaves the old stamp. Limits: a file changed in place without a change of size, time or inode is not seen, and neither is one whose time was set back to what it was. `suit upstream NAME take` reads the folder whatever the stamp says, and leaves the stamp alone. ## Part two Not built, and waiting on HTTPS (the same transport as `suit sync` to an `https://` remote): `suit upstream NAME fetch` will download the archive at `url` for the pinned version, check it against a checksum kept in a second key, unpack it and take it as `take` does, and `suit tend` will look for new versions by itself (it already does for a local upstream). Everything on this page works the same on what it takes.