Skip to content

feat(bin): seed the first commit of a brand-new empty GitHub repo - #1608

Open
ConcosleyMedia wants to merge 3 commits into
kunchenguid:mainfrom
ConcosleyMedia:fm/rule-except-t4
Open

ConcosleyMedia wants to merge 3 commits into
kunchenguid:mainfrom
ConcosleyMedia:fm/rule-except-t4

Conversation

@ConcosleyMedia

Copy link
Copy Markdown

Intent

Add a narrow, scripted sixth exception to firstmate's hard rule #1 ('never write to a project'), covering exactly one case: seeding the very first commit of a genuinely brand-new, zero-commit GitHub repo, so its default branch exists and a crewmate can get a worktree at all. Git cannot create a worktree for a branch with zero commits - that is a git limitation, not a firstmate policy - so a just-created empty repo (gh-axi repo create does not auto-initialize with a README) was previously a dead end: no crewmate could touch it and firstmate was not allowed to either. This happened for real with a project called promo-reel-forge.

Built bin/fm-seed-empty-repo.sh (takes a project dir or registry name), following the existing patterns in bin/fm-project-mode.sh and bin/fm-fleet-sync.sh for resolving a project's dir/registry entry and origin remote. Deliberate design decisions:

  • The safety net is a LIVE GitHub API check via gh-axi, never a trusted flag or argument: it checks repos/OWNER/REPO size==0, that the branches list is empty, AND that the commits API call fails with the expected "Git Repository is empty" signature (verified as a substring match) rather than succeeding or failing for some unrelated/inconclusive reason (auth, rate limit, network) - an inconclusive failure refuses loudly rather than being treated as confirmation of emptiness, since silently proceeding on an ambiguous signal would defeat the point of the safety net.
  • Only after that full verification does it run exactly one empty-allowed commit ("Initial commit") and a plain push to the default branch - no file content, no other commits, never a force-push.
  • Extra defense-in-depth refusals: dirty working tree, local branch already has a commit (already seeded), local branch name disagreeing with the remote's declared default branch, no origin remote, origin remote not on github.com, gh-axi unavailable.
  • Owner/repo slug parsing reuses the same sed pattern already used in bin/fm-bearings-snapshot.sh's repo_slug helper.
  • Refusal messages use REFUSED: for the safety-net verification failures (mirroring bin/fm-merge-local.sh's guarded-refusal style) and error: for ordinary usage/precondition failures.

Added a colocated test suite at tests/fm-seed-empty-repo.test.sh (11 cases) following the repo's tests/lib.sh conventions: a fake gh-axi in a per-case fakebin controls the three API responses via env vars, and real local git objects are used throughout, including for the one happy-path test where the origin remote is a real local bare repo whose path deliberately contains a github.com/owner/repo segment so the script's github.com URL-parsing regex sees a valid slug while the actual git push stays fully local (no network). Both the script and the test file are shellcheck-clean under the repo's pinned shellcheck 0.11.0 via bin/fm-lint.sh, and bin/fm-doc-audience-check.sh passes.

Updated AGENTS.md per the coding-guidelines skill's decision tree (detailed procedure belongs in the owning skill, not inline in AGENTS.md):

  • Section 1: added the sixth exception to the existing prose list of sanctioned project-write exceptions in hard rule chore: initialize no-mistakes gate #1, pointing to section 6 for the procedure.
  • Section 6: added one sentence noting that project-management's initialization procedure also covers this narrow empty-repo case via the new script, deferring detail to that skill.
  • .agents/skills/project-management/SKILL.md: added the actual procedural paragraph directly after the existing "## Initialize" section (the closest existing match to the task's described "Initialize (no-mistakes mode only)" block), spelling out that this path is strictly for a zero-commit repo and never applies again once the project has any real history - every subsequent change goes through a crewmate as normal.

This is firstmate's own tracked repository, so I (a firstmate crewmate) was authorized to edit AGENTS.md, bin/, and .agents/skills/ directly per the task brief; ran bin/fm-ensure-agents-md.sh afterward per the brief's project-memory instructions and confirmed it was a no-op (AGENTS.md's "Maintaining this file" section was already present).

Note on this run: two earlier runs against this same branch content failed for reasons unrelated to the code under review - one hit a 403 push failure because origin was read-only and a writable fork remote had not yet been registered (now fixed via no-mistakes init --fork-url), and after that a stray empty commit I had accidentally created via a malformed shell command was surgically removed from branch history via git rebase --onto (verified byte-identical tree content before/after, both fix commits preserved), and the most recent attempt's review step failed only because the reviewing agent's own OAuth session had expired mid-run, not because of any issue with the change itself.

What Changed

  • Added bin/fm-seed-empty-repo.sh, a guarded script that resolves a project's directory/registry entry and origin remote, performs a live GitHub API check (repo size 0, empty branches list, and a commits-API call that fails with the expected "Git Repository is empty" signature) as the safety net, then pushes exactly one empty "Initial commit" to the default branch so a crewmate can obtain a worktree against a repo git otherwise cannot branch.
  • Added defense-in-depth refusals for a dirty working tree, an already-seeded local branch, local/remote default-branch name mismatch, missing or non-GitHub origin, and unavailable gh-axi, distinguishing safety-net verification failures (REFUSED:) from ordinary precondition failures (error:).
  • Added a colocated 11-case test suite (tests/fm-seed-empty-repo.test.sh) using a fake gh-axi to control the three API responses and real local git objects throughout, and isolated FM_STATE_OVERRIDE handling in those tests to prevent cross-test state leakage.
  • Documented the new sixth exception to hard rule 1 in AGENTS.md, the initialization procedure in .agents/skills/project-management/SKILL.md, and added the script to the bin/ toolbelt reference table in docs/scripts.md.

Risk Assessment

✅ Low: A narrow, well-isolated addition (new script + colocated tests + doc pointers) with no changes to existing behavior; the safety net (triple live-verified GitHub API check before any commit/push, no force-push, fails closed on any ambiguous signal) is sound, its output parsing matches gh-axi's actual API response format (verified live against a real GitHub repo), and all 11 tests exercise the refusal paths that matter.

Testing

Ran the full colocated test suite (11/11 passing) and performed manual end-to-end verification with real local git objects (no network) that reproduces the exact promo-reel-forge scenario: seeding a genuinely empty repo succeeds and unblocks git worktree add that previously failed with git's own limitation, while an inconclusive GitHub API failure is refused loudly with zero commits created, confirming the safety-net design decision works as intended.

Evidence: End-to-end CLI transcript: seed happy path, worktree-add before/after payoff, and inconclusive-failure refusal
=== fm-seed-empty-repo.sh end-to-end demo ===

1) Simulated a genuinely empty GitHub repo (zero commits, local and remote).
2) Ran the script exactly as an operator would:

$ bash bin/fm-seed-empty-repo.sh $PROJ
To file://.../remotes/github.com/example/promo-reel-forge
 * [new branch]      main -> main
seeded: pushed the first commit to example/promo-reel-forge (main); $PROJ is ready for cloning and dispatch

3) Verified the actual crewmate payoff: git worktree add for a task branch.

BEFORE (unseeded repo, git's own limitation):
$ git worktree add -b task/demo wt main
fatal: not a valid object name: 'main'
exit code: 255

AFTER (seeded via fm-seed-empty-repo.sh):
$ git worktree add -b task/demo wt main
Preparing worktree (new branch 'task/demo')
HEAD is now at f04cf07 Initial commit
exit code: 0

4) Verified the safety-net design decision: an inconclusive commits-API
   failure (e.g. rate limit) is refused loudly, never treated as confirmation
   of emptiness, and no commit is created.

$ bash bin/fm-seed-empty-repo.sh $PROJ   # commits API fails with 403 rate-limit, not the "empty" signature
REFUSED: could not confirm example/some-repo has zero commits; the commits API call failed for an unexpected reason: error: "gh: API rate limit exceeded (HTTP 403)"
exit code: 1

$ git -C $PROJ log --oneline
fatal: your current branch 'main' does not have any commits yet   # no commit was created

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ AGENTS.md - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-seed-empty-repo.test.sh — all 11 cases pass (happy path, non-zero size, non-empty branches, commits-API success, inconclusive commits-API failure, no origin, non-GitHub origin, dirty tree, already-seeded, branch mismatch, gh-axi missing)
  • Manual E2E: built a real local bare 'GitHub' remote at a github.com/owner/repo-shaped path with zero commits, ran bin/fm-seed-empty-repo.sh against a real clone of it with a gh-axi stub answering size=0/branches=[]/commits=409-empty, confirmed the script pushed exactly one 'Initial commit' to both local and remote
  • Manual E2E payoff check: confirmed git worktree add -b task/demo wt main fails with fatal: not a valid object name: 'main' against the unseeded repo, and succeeds after seeding — demonstrating the actual crewmate-dispatch blocker the change fixes
  • Manual E2E safety-net check: ran the script against a live-shaped inconclusive commits-API failure (403 rate limit, not the 'Git Repository is empty' signature) and confirmed it printed REFUSED: could not confirm ... failed for an unexpected reason and created no commit
  • Reviewed AGENTS.md, .agents/skills/project-management/SKILL.md, and docs/scripts.md diffs against the described intent (sixth hard-rule-1 exception, section 6 pointer, toolbelt table entry)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…commit

Git cannot create a worktree for a branch with zero commits, so a
just-created empty GitHub repo (gh-axi repo create does not
auto-initialize) was a dead end no crewmate could reach and firstmate
was not allowed to write to either. bin/fm-seed-empty-repo.sh is the
sixth sanctioned exception to hard rule kunchenguid#1: it verifies live against
the GitHub API, never a flag or argument, that the repo genuinely has
zero commits on every branch, then pushes a single empty commit and
nothing else.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant