Search Documentation

Search for pages and headings in the documentation

firstmate delivery

modules/firstmate.nix provisions firstmate as an agent distro. It fetches one pinned commit of kunchenguid/firstmate as a flake input (inputs.firstmate, with flake = false) and copies that tree into ~/firstmate. The install is a copy of a content-addressed Nix source, not a git clone: the store path carries no .git and no remote is configured, so there is nothing to pull. The activation still provisions a .git with the pinned revision’s history, because firstmate needs one (see Git history).

What the delivery copies

The activation builds the delivered tree from the pinned input plus the tracked patches in patches/firstmate/, then copies it over ~/firstmate with cp -R "$distroSource"/. "$firstmateDir"/. Only the distro’s tracked files exist in the source, so a re-delivery overwrites source files and leaves the gitignored operational directories alone: data/, state/, config/, projects/, and .no-mistakes/ are never present in the source and never touched. The activation then runs chmod -R u+w ~/firstmate, because a store copy is read-only while the distro writes its own config and runs git and gh from the install. A running firstmate keeps the AGENTS.md it loaded at launch, so re-delivered instructions reach it only on the next conversation.

Git history

firstmate’s self-repository publication gate refuses every publishing dispatch when its code root has no readable history. In bin/fm-role-lib.sh, fm_role_self_repo returns 2 for that undeterminable lineage.

A flake input cannot supply that history. The input stores the tree without .git, and this Nix’s git fetcher has no leaveDotGit or deepClone (Lix rejects the attribute), so no input can retain git metadata. The activation therefore provisions the repository itself, the way the live install’s history was made by hand before: git init, then a git fetch of the pinned revision by URL. Fetching by URL adds no remote, and the activation removes FETCH_HEAD afterwards, so firstmate’s ordinary update path cannot pull an unmanaged tree over the delivery. The revision is inputs.firstmate.rev, so the history cannot drift from the delivered tree.

After delivery the install has the pinned revision as HEAD on a local main branch, the upstream root commit present, and the repository is not shallow. The activation writes only ~/firstmate/.git. It never checks out a file, so the delivered working tree stays byte-identical. A pin bump fetches the new revision and moves main; a shallow or history-less install is repaired the same way. A revision the fetch cannot provide aborts the activation instead of leaving an install the gate cannot judge.

The two state markers

Both markers live in ~/firstmate/state/.

Marker Role
.distro-source Records the source path that is installed. The activation reads it at the start of a run and rewrites it at the end.
.distro-receive Opt-in consent for re-delivery. Its presence is what lets the activation overwrite an existing install when the source differs. The activation never creates it and never deletes it.

The activation reads the installed value with installedDistro="$(cat "$distroMarker" 2>/dev/null || echo unknown)", so a missing or unreadable .distro-source reads as unknown. Every run rewrites .distro-source with the value that run decided on, so hand-editing the marker is not a durable way to change what the activation does.

Activation branches

The activation branches on whether ~/firstmate/AGENTS.md exists and whether the recorded source matches the delivered source path.

  • Fresh install — ~/firstmate/AGENTS.md is absent. The activation creates ~/firstmate, copies the delivered tree, and records the delivered source as installed, printing nothing beyond the normal activation output.
  • Up to date — AGENTS.md exists and .distro-source already equals the delivered source path. The activation copies nothing, prints nothing, and rewrites the marker unchanged.
  • Differs, with .distro-receive — AGENTS.md exists, the recorded source differs, and the marker is present. The activation copies the delivered tree, records the new source, and prints re-delivering firstmate from <source> at verbose level.
  • Differs, without .distro-receive — AGENTS.md exists, the recorded source differs, and the marker is absent. The activation copies nothing, leaves the install and the recorded value untouched, and prints firstmate: pinned distro <source> differs from installed <installed>; create <stateDir>/.distro-receive to re-deliver.

What state/.distro-source changes and does not change

.distro-source is only the comparison key; it is never a copy trigger.

  • Setting it to the delivered source path makes the activation read the install as up to date and copy nothing, even when the installed files are stale.
  • Setting it to any other value, or to unknown, or removing it makes the activation read the install as differing. The delivered path is content-addressed, so it changes on every pin bump and on every change to the tracked patches, and the comparison therefore differs again after each one. A hand-made match only lasts until the next delivery.
  • A differing source still needs .distro-receive before the activation copies: the differing source alone never causes a copy.
  • A hand-edited value does not survive the run, because the activation rewrites the marker at the end of every run.

Reconciling a stale install

A stale or hand-copied ~/firstmate works with this mechanism once its local modifications are carried as patches applied at delivery instead of being hand-edited into the installed copy.

  1. Carry each local behaviour as a tracked patch under patches/firstmate/ and apply it to the pinned input in modules/firstmate.nix. The delivered source is then the patched tree, and a patch that stops applying fails the build instead of silently delivering the unpatched source. patches/firstmate/README.md names the current set.
  2. Create the opt-in marker the activation will not create itself: touch ~/firstmate/state/.distro-receive.
  3. Run the activation, for example just switch or home-manager switch, which re-delivers the patched tree.
  4. Restart the running firstmate so it loads the re-delivered AGENTS.md.

The one-way door

Once state/.distro-receive exists, every later pin bump is delivered automatically, and the activation never removes the marker. Because a re-delivery overwrites the tracked files with the delivered source, anything hand-edited into ~/firstmate is lost at the next switch. Keep local modifications in patches/firstmate/ so a re-delivery carries them.