Skip to content

fix(bin): seed remote secondmates from supplied origins - #1836

Merged
kunchenguid merged 7 commits into
mainfrom
fm/fm-remote-sm-seed-no-primary-side-effects-r1
Aug 7, 2026
Merged

kunchenguid merged 7 commits into
mainfrom
fm/fm-remote-sm-seed-no-primary-side-effects-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Aug 6, 2026 •

Copy link
Copy Markdown
Owner

Intent

Make remote secondmate seeding create no primary-home side effects beyond registering the remote route, and accept project origins from any host or forge. Firstmate shared, tracked material; captain direction 2026-08-04 after a real seed had to clone 6 repos into the primary home then remove them.

Problem: remote seed required a local projects/ clone only so it could read 'git remote get-url origin' into the provisioning manifest, forcing a disposable primary-side clone and a no-mistakes init during remote setup.

Captain's accepted requirements:

  1. No primary side effects outside registering the remote route and the unavoidable primary-private registration records (data/secondmates.md, the charter brief under data/, and meta when launched). Seeding must NOT require cloning into primary projects/, a no-mistakes init on the primary, or a fleet sync as a precondition.
  2. No rigid deterministic origin-URL machinery: no mandatory local clone, no single forced URL template.
  3. The firstmate agent resolves the origin (captain, registry text, prior clones elsewhere, gh, explicit paste) and supplies it into seed/provision; the scripts validate and transport what the agent provided rather than discovering it by side-effecting the primary.
  4. NEW captain requirement, decided mid-validation and explicitly in scope for this task: accepted origin URLs must be HOST/FORGE-AGNOSTIC, never a github whitelist. https/http/ssh/git schemes with any host, domain, port and path, plus the scp-like user@host:path form, must all pass - Bitbucket, GitHub Enterprise self-hosted, GitLab hosted and self-hosted, Gitea/Codeberg/sr.ht, and arbitrary self-hosted git. Validate STRUCTURE plus SAFETY only, never the forge or domain; fail closed on malformed input, injection vectors, and unsafe local/file: paths. E2E-verify NON-github origins: bitbucket.org, a self-hosted enterprise domain (git.example.com), a self-hosted GitLab, and a bare scp-like custom host.
  5. Captain's decision on the review gate's documentation-owner finding [doc-owner-split]: REFINED FIX - bin/fm-project-origin-lib.sh is the sole owner of accepted URL forms, docs carry a one-line pointer, and the secondmate-provisioning skill KEEPS its distinct agent-operating-behavior lines (the agent supplies the origin; no clone/init/fleet-sync) because that is a different contract, not URL-acceptance duplication. The earlier pipeline fix round removed those skill lines, so this run restores them per that decision; do not re-delete them.

Non-goals ruled out by the captain: copying project trees from primary to remote (the remote still clones from origin), and removing the need for remote host credentials to fetch the origin.

Decisions and tradeoffs:

  • The project positional accepts =. A bare is a deliberate backward-compatible convenience that reads an already-present clone's origin, never a reason to create one; that is why the mandatory clone check was deleted rather than the fallback.
  • bin/fm-project-origin-lib.sh is the single owner of accepted forms and states in its header that there is no host, domain, or forge allowlist and there must never be one. Verified before changing anything: the validator never had a forge whitelist - bitbucket, GHE-style domains, self-hosted GitLab with a port, Gitea, Codeberg, sr.ht, raw IPv4, and underscore hosts already passed on structure. Two genuine gaps found and closed: a bracketed IPv6 literal in the scp-like form (e.g. [2001:db8::1]:/srv/repo.git) was refused and is now accepted, and a '/../' traversal inside a local or file: origin was accepted and is now refused because it names a path on the cloning host's own filesystem.
  • Both ends validate: the sending parent before transport and the receiving host before cloning, so a manifest is never trusted because the sender looked at it.
  • Origins read from an existing local clone go through the same validator, so an exotic remote (e.g. git+ssh://) is now refused where it previously passed. Deliberate and fail-closed; the error names the URL and the = escape hatch.
  • Deliberately unchanged: the project's registered delivery mode still comes from the primary's data/projects.md (unregistered and local-only projects are still refused), and the manifest wire schema fm-remote-home-provision.v1 is unchanged because only the origin's SOURCE changed, so an older remote code root still provisions.
  • Verification: the E2E lives in the existing tests/fm-remote-secondmate-lifecycle-e2e.test.sh rather than a new runner. It seeds a registered project the primary has never cloned and asserts the primary projects/ tree is byte-identical afterwards via a hash snapshot, plus refusals for missing origin, unsafe origin, local-only, and unregistered project, and a receiving-host rejection of an unsafe manifest origin. A second case seeds four non-GitHub origins in one seed (bitbucket.org, git.example.com, ssh:// self-hosted GitLab with port, scp-like [email protected]) and asserts each URL reached the remote side's git clone unchanged and each clone carries its own origin's content. Because the suite is offline, a fixture origin resolver on the remote code root records the exact clone source production code hands to git and serves it from a local bare repository; it is removed afterwards and the remote code root is asserted clean. tests/fm-project-origin.test.sh leads its accepted matrix with non-GitHub hosts and demonstrates the ext:: hazard against real git before pinning its refusal, so no test asserts implementation source text.

Delivery note: the previous run for this branch was cancelled because a GitHub Actions outage meant no workflow run was ever created for its pushed head, so its CI monitor could never see checks. That outage has lifted; this run re-pushes a fresh head for a genuine CI result. yolo is off, so the captain merges.

What Changed

  • Allow remote secondmate seeds to accept <project>=<origin-url>, removing the requirement for a matching project clone in the primary home while retaining the existing-clone fallback for bare project names.
  • Validate supplied origins at both provisioning boundaries with a shared, host-agnostic validator that supports standard URL and scp-like forms while rejecting malformed, executable, and unsafe local paths.
  • Document and cover no-primary-project side effects, non-GitHub origins, unsafe manifests, and registered delivery-mode enforcement.

Risk Assessment

✅ Low: The change is well-bounded, removes the mandatory primary clone path, validates supplied origins at both transport boundaries, and the authority-validation fix closes the previously identified malformed and option-shaped host paths without introducing a forge allowlist.

Testing

No separate baseline commands were supplied; both targeted executable tests passed, their evidence runs demonstrated forge-agnostic remote cloning and no primary project-tree mutation, and final cleanup verification found no testing changes in the worktree.

Evidence: Project origin validation transcript

Accepted ordinary clone URLs and refused executable, option-shaped, and unsafe forms. All tests passed.

ok - ordinary clone URLs are accepted and clone with the command the remote host runs
ok - executable transports, option-shaped values, and unusable spellings are refused
ALL TESTS PASSED
Evidence: Remote secondmate lifecycle E2E transcript

Demonstrates supplied-origin remote seeding without primary project-tree changes, receiver-side validation, and unchanged Bitbucket, self-hosted, and scp-like origins reaching remote clones. All tests passed.

ok - overlapping remote home provisioning serializes through publication and rollback
ok - remote seed rollback preserves serialized competing routes
ok - unknown readiness preserves its route and brief for reconciliation
ok - remote seeding checks, repairs, and re-checks readiness, then stops on a remaining gap
ok - remote seeding proceeds once the repair closes every gap
ok - remote seeding provisions a supplied origin without touching the primary project tree
ok - remote provisioning re-validates a supplied origin at the receiving host
ok - seeding carries bitbucket, self-hosted, and scp-like origins through to the remote clone
ok - remote seed registers the route and provisions the whole home and project clone on that host
ok - remote inheritance rejects incomplete and superseded payload generations
ok - mixed local and remote routes validate without migration
ok - remote spawn launches on the remote-local backend and records a host-qualified route
ok - legacy and mismatched remote endpoints fail closed before backend access
ok - non-herdr remote endpoints are refused without changing either route
ok - remote spawn serializes inheritance through launch publication
ok - marked send and routed reply complete through the existing parent correlation owner
ok - partial remote inheritance retains reread intent through bootstrap convergence
ok - config push and bootstrap serialize remote inheritance convergence
ok - remote inherited config retains and retries a failed live reread nudge
ok - fleet snapshot projects mixed local and remote structured state
ok - remote update imports and fast-forwards the persistent home on its configured host
ok - startup repairs remote readiness before probing without relaunching
ok - startup reports alive legacy backends without changing their routes
ok - unreachable remote state remains unknown with no local respawn or failover
ok - remote retirement refuses child work, then removes only its own endpoint while a shared-session sibling survives
ALL TESTS PASSED

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • 🚨 bin/fm-project-origin-lib.sh:50 - Required criterion 4 says to “validate STRUCTURE plus SAFETY” and “fail closed on malformed input [and] injection vectors,” but this hunk accepts every non-whitespace value after these scheme prefixes without parsing the authority. Consequently malformed origins such as https:///repo.git, ssh://:2222/repo.git, and invalid IPv6 spellings pass; option-shaped SSH hosts can also reach Git. Tighten validation at this shared sender/receiver boundary to require a structurally valid host/authority and reject option-shaped hosts, while retaining host/forge agnosticism.

🔧 Fix: Validate project origin authorities safely
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • tests/fm-project-origin.test.sh
  • tests/fm-remote-secondmate-lifecycle-e2e.test.sh
  • tests/fm-project-origin.test.sh | tee /var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/no-mistakes-evidence/01KZCM0792QMZQY587JAGF2YXW/project-origin-validation.txt
  • tests/fm-remote-secondmate-lifecycle-e2e.test.sh | tee /var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/no-mistakes-evidence/01KZCM0792QMZQY587JAGF2YXW/remote-secondmate-lifecycle.txt
  • git status --short confirmed testing left the worktree unchanged
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Remote seeding required a local projects/<name> clone purely to read
`git remote get-url origin` into the provisioning manifest, so setting up
a remote second mate forced disposable clones and no-mistakes inits in the
primary home for projects that home has no reason to hold.

Firstmate now resolves the origin itself and names it as <project>=<origin-url>.
The seed validates and transports what it is given, and the receiving host
re-validates it rather than trusting the sender; bin/fm-project-origin-lib.sh
is the single owner of which URLs are accepted, refusing executable remote-helper
transports, option-shaped values, and unusable spellings at both ends. A bare
<project> still reads an already-present clone's origin, so nothing that works
today has to change. Registry consistency is unchanged: an unregistered or
local-only project is still refused.

A remote seed therefore creates nothing in the primary home beyond the route,
the charter, and its launch record.

The lifecycle test now seeds a registered project the primary has never cloned
and asserts the primary project tree is byte-identical afterwards, alongside
refusals for a missing origin, an unsafe origin, a local-only project, and an
unregistered project.
Firstmate is a shared template, so a project origin must be able to name any
host: GitHub Enterprise on a private domain, GitLab hosted or self-hosted,
Bitbucket, Gitea, Codeberg, sr.ht, a bare IP, an SSH config alias, or a plain
server nobody else has heard of. The validator already decided on structure
rather than on a forge allowlist, and this makes that guarantee explicit and
closes the two gaps that a host-agnostic rule exposed:

- a bracketed IPv6 literal in the scp-like form is now accepted, so a host
  reachable only by address is not excluded
- a "/../" traversal inside a local or file: origin is now refused, because
  that names a path on the cloning host's own filesystem

The library is the single owner of the accepted forms, and its header says
plainly that there is no host, domain, or forge allowlist and there must never
be one. The skill keeps its distinct agent-operating lines (the agent resolves
and supplies the origin; a remote seed creates nothing in the primary home
beyond the route, the charter, and its launch record) and points at the library
for URL acceptance and at the operator doc for the rest.

The lifecycle test now drives Bitbucket, a self-hosted enterprise domain, a
self-hosted GitLab over ssh with a port, and a bare scp-like custom host through
the real seed, manifest, transport, and remote provisioning path in one seed,
asserting each URL reaches git unchanged and each clone carries its own origin's
content. The unit matrix leads with non-GitHub hosts for the same reason.
@kunchenguid kunchenguid changed the title fix: seed remote secondmates without primary project clones fix(bin): seed remote secondmates from supplied origins Aug 6, 2026
@kunchenguid
kunchenguid merged commit fb368dc into main Aug 7, 2026
13 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-remote-sm-seed-no-primary-side-effects-r1 branch August 7, 2026 00:36
kaku-san added a commit to kaku-san/firstmate that referenced this pull request Aug 7, 2026