Skip to content

fix(bin): unify project-name resolution across fm-brief, fm-spawn, and fm-fleet-sync - #61

Merged
trillium merged 2 commits into
mainfrom
fix/robots-2rwl-project-name-resolution
Aug 5, 2026
Merged

trillium merged 2 commits into
mainfrom
fix/robots-2rwl-project-name-resolution

Conversation

@trillium

@trillium trillium commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Intent

Fix robots-2rwl: bin/fm-brief.sh accepts a bare project name but bin/fm-spawn.sh requires projects/, a silent mismatch between two halves of the same dispatch. Reported repro: 'bin/fm-brief.sh hw-allowedhosts herdr-web' scaffolds fine, then 'bin/fm-spawn.sh hw-allowedhosts herdr-web' dies with 'line 930: cd: herdr-web: No such file or directory', while 'bin/fm-spawn.sh hw-allowedhosts projects/herdr-web' works. Cause: resolve_project_dir_arg() only rewrote arguments already starting with 'projects/', so a bare name fell through to cd and resolved against the process cwd, and the failure named an internal line number instead of the project argument. The reporter's stated fix direction, which this change follows deliberately: make the resolver accept a bare name resolving under $PROJECTS, checking $PROJECTS/ BEFORE treating the argument as a literal path so an explicit path still wins; fail with a named error suggesting the registry entry when neither resolves; and separately have fm-brief.sh reject unrecognized --flags, since the reporter also hit 'fm-brief.sh --project herdr-web --mode direct-PR' being silently accepted as if --project were the repo name (only symptom: 'warn: project "--project" not in registry'). Decisions made while implementing, which a reviewer reading only the diff would not know: (1) The mapping had three independent copies (fm-brief, fm-spawn, fm-fleet-sync), which is why they drifted silently, so the fix introduces a single owner, bin/fm-project-dir-lib.sh, rather than patching fm-spawn alone - this is the firstmate coding guidelines' one-owner rule for a shared contract, and removing the drift class is intentionally in scope. (2) Candidate mapping and existence checking are deliberately separate layers: fm-brief needs a candidate path for a best-effort git-remote read on a clone that may not be present, so fm_project_dir_candidate does no existence check while fm_resolve_project_dir does. (3) fm-fleet-sync resolves SOFTLY - an argument that resolves nowhere is returned unchanged so its pre-existing 'not a directory' skip still reports it - deliberately preserving current behavior rather than making fleet-sync newly fatal. (4) The bare-name cwd-relative fallback is preserved on purpose (fm-fleet-sync has an existing test asserting bare-name resolution is not cwd-sensitive), so resolution order is: absolute and explicit relative paths pass through untouched, a bare name prefers $PROJECTS/, and only then falls back to a cwd-relative directory. (5) Near-name suggestions fold case and separators so 'herdrweb' still suggests 'projects/herdr-web'. (6) Unknown-flag rejection came with '--' end-of-flags support and an explicit -h/--help case inside both arg loops, so '--help' after a positional is still answered instead of being rejected as unknown, and missing positionals now produce a one-line named usage error rather than dumping the ~150-line header or dying on an unbound array element. Tests are behavior tests through the executables (tests/fm-project-dir.test.sh, 13 cases): fm-spawn coverage reaches its missing-brief error, which proves the bare name resolved without launching anything.

What Changed

  • Introduced bin/fm-project-dir-lib.sh as the single owner of project-argument-to-clone-directory mapping, replacing three independent copies in fm-brief.sh, fm-spawn.sh, and fm-fleet-sync.sh that had drifted apart; a bare project name now resolves under $PROJECTS/ before falling back to cwd-relative, so a name that scaffolds in fm-brief.sh also works in fm-spawn.sh without the projects/ prefix.
  • fm-spawn.sh and fm-brief.sh now fail with a named error (including near-name suggestions) instead of a raw cd: <name>: No such file or directory at an internal line number; fm-brief.sh additionally rejects unrecognized --flags (with -- end-of-flags escape and -h/--help support) and emits named usage errors for missing positional arguments.
  • Added tests/fm-project-dir.test.sh (13 behavior tests through the executables) covering bare-name resolution, explicit-path passthrough, near-name suggestions, missing-positional errors, and unknown-flag rejection.

Risk Assessment

✅ Low: Change is well-scoped: a single shared library eliminates the concrete silent mismatch, fm-spawn's two-step resolve correctly captures resolution failures before cd, fleet-sync's soft fallback semantics are preserved verbatim by existing behavioral tests, and all 13 new tests drive real executables rather than reading source.

Testing

Ran the 13-case targeted behavior suite (tests/fm-project-dir.test.sh) against all changed files; every test passed, directly exercising the reported regression and all constraints stated in user intent.

Evidence: fm-project-dir test run — all 13 ok

ok - fm-project-dir-lib: bare names map under projects/ while explicit paths pass through ok - fm-project-dir-lib: bare, projects/<name>, and absolute forms all resolve to the same clone ok - fm-project-dir-lib: an explicit relative path is never redirected under projects/ ok - fm-project-dir-lib: a bare name still falls back to a cwd-relative directory ok - fm-project-dir-lib: an unresolvable name fails with a named error and a clone suggestion ok - fm-spawn.sh: a bare project name resolves under projects/ (matches fm-brief.sh) ok - fm-spawn.sh: an unresolvable project fails with a named error, not a raw cd failure ok - fm-spawn.sh: an unknown --flag is rejected, never consumed as a positional ok - fm-brief.sh: an unknown --flag is rejected instead of being taken as the repo name ok - fm-brief.sh: a missing repo name is a named usage error ok - fm-brief.sh: documented flags still parse after unknown-flag rejection ok - fm-brief.sh: '--' ends flag parsing for a positional that must start with -- ok - fm-brief.sh/fm-spawn.sh: --help is answered wherever it appears, not rejected as unknown

ok - fm-project-dir-lib: bare names map under projects/ while explicit paths pass through
ok - fm-project-dir-lib: bare, projects/<name>, and absolute forms all resolve to the same clone
ok - fm-project-dir-lib: an explicit relative path is never redirected under projects/
ok - fm-project-dir-lib: a bare name still falls back to a cwd-relative directory
ok - fm-project-dir-lib: an unresolvable name fails with a named error and a clone suggestion
ok - fm-spawn.sh: a bare project name resolves under projects/ (matches fm-brief.sh)
ok - fm-spawn.sh: an unresolvable project fails with a named error, not a raw cd failure
ok - fm-spawn.sh: an unknown --flag is rejected, never consumed as a positional
ok - fm-brief.sh: an unknown --flag is rejected instead of being taken as the repo name
ok - fm-brief.sh: a missing repo name is a named usage error
ok - fm-brief.sh: documented flags still parse after unknown-flag rejection
ok - fm-brief.sh: '--' ends flag parsing for a positional that must start with --
ok - fm-brief.sh/fm-spawn.sh: --help is answered wherever it appears, not rejected as unknown

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-project-dir.test.sh — 13 behavior tests covering bare-name resolution, projects/<name> form, absolute paths, explicit-relative-path priority, cwd-relative fallback, unresolvable-name named error with fuzzy suggestion, fm-spawn.sh bare-name regression, fm-spawn.sh unknown-flag rejection, fm-brief.sh unknown-flag rejection, missing-positional named error, known-flags still scaffold, '--' end-of-flags, and --help after a positional
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

`bin/fm-brief.sh hw-allowedhosts herdr-web` scaffolded fine, but the very
next command in the same workflow, `bin/fm-spawn.sh hw-allowedhosts
herdr-web`, died with

    bin/fm-spawn.sh: line 930: cd: herdr-web: No such file or directory

Half a dispatch accepted a bare project name and the other half did not.
fm-spawn's resolve_project_dir_arg only rewrote an argument that already
began with "projects/", so a bare name fell through untouched to `cd` and
resolved against the process cwd. The failure named an internal line
number and a shell builtin rather than the project argument, so the caller
had no way to see that "projects/herdr-web" was the accepted spelling.

The mapping from a project argument to a clone directory had three
independent copies (fm-brief, fm-spawn, fm-fleet-sync), which is why they
could drift apart silently in the first place. Give it one owner:

  bin/fm-project-dir-lib.sh
    fm_project_dir_candidate  - argument -> candidate path, no existence
                                check (fm-brief needs a path for a
                                best-effort git-remote read on a clone
                                that may not be there)
    fm_resolve_project_dir    - candidate, then a cwd-relative fallback,
                                then a named error listing what it tried
                                and up to three near-name suggestions
    fm_project_dir_fold       - fold case and separators so "herdrweb"
                                still suggests "projects/herdr-web"

Resolution order preserves what already worked: absolute and explicit
relative paths (./x, ../x, a/b) pass through untouched, so an explicit
path still wins over a same-named clone; a bare name prefers
$PROJECTS/<name> and only then falls back to a cwd-relative directory.
fm-fleet-sync resolves softly, returning the argument unchanged when
nothing resolves, so its existing "not a directory" skip still reports it.

Second half of the same defect: both entry points swallowed an unknown
--flag as a positional, so

    bin/fm-brief.sh <id> --project herdr-web --mode direct-PR

scaffolded a brief for a project literally named "--project" and said so
only in a `warn:` line. Both scripts now reject an unknown option with
exit 2, honor `--` for a positional that must start with `--`, answer
`--help` wherever it appears, and name a missing positional instead of
dying on an unbound array element.

tests/fm-project-dir.test.sh covers all of it through the executables: a
bare name reaching fm-spawn's brief check proves resolution succeeded
without launching anything.

Fixes robots-2rwl.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@trillium, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f33ae058-ec36-4fe2-b1a0-cca802feab6d

📥 Commits

Reviewing files that changed from the base of the PR and between ba51491 and 784210e.

📒 Files selected for processing (6)
  • bin/fm-brief.sh
  • bin/fm-fleet-sync.sh
  • bin/fm-project-dir-lib.sh
  • bin/fm-spawn.sh
  • docs/scripts.md
  • tests/fm-project-dir.test.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@trillium
trillium merged commit ca61bfa into main Aug 5, 2026
10 checks passed
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