Skip to content

refactor(fleet-launcher): introduce CliConvention trait#159

Merged
NagyVikt merged 1 commit into
mainfrom
agent/refactor-cli-convention-trait
May 16, 2026
Merged

refactor(fleet-launcher): introduce CliConvention trait#159
NagyVikt merged 1 commit into
mainfrom
agent/refactor-cli-convention-trait

Conversation

@NagyVikt
Copy link
Copy Markdown
Contributor

Summary

  • New CliConvention trait, implemented on CliKind (one match arm per variant) to replace the inlined 4-way match in build_command_line()
  • build_command_line() shrinks from ~32 lines to a single delegating call
  • CliKind::binary() and CliKind::home_env() kept as inherent methods that delegate to the trait, so existing callers (bin/spawn.rs, heartbeat.rs) compile unchanged

Trait

pub trait CliConvention {
    fn binary(&self) -> &'static str;
    fn home_env(&self) -> &'static str;
    fn command_line(&self, prompt: Option<&str>, extra_args: &[String]) -> String;
}

Chose enum-impl over struct-per-CLI: CliKind is Copy, already wired into the public API and heartbeat.rs, and all four CLIs are compile-time known — a Box<dyn CliConvention> registry would add an allocation per command build for zero call-site benefit. The trait still provides a swap-in seam if dynamic registration is needed later.

Behavior

Identical for all 4 CLIs. Verified by the existing tests (build_command_line_per_cli_conventions, cli_home_envs_match_each_cli, cli_parse_accepts_aliases, write_launch_script_emits_exports_cd_and_exec):

  • codex: bare positional prompt — codex hello --flag 'with space'
  • claude: still emits --dangerously-skip-permissions before the prompt — claude --dangerously-skip-permissions 'review this'
  • gemini: still piped via stdin — printf '%s' hi | gemini
  • claw: bare positional prompt, no auto-injected bypass flag — claw 'ship it'
  • Home env vars unchanged: CODEX_HOME, CLAUDE_CONFIG_DIR, GEMINI_CLI_HOME, CLAW_CONFIG_HOME

Stack

Targets feat/fleet-launcher (#158) which introduces the crate. GitHub will auto-retarget this PR to main once #158 merges.

Test plan

  • cargo check -p fleet-launcher — clean
  • cargo test -p fleet-launcher — 12/12 pass
  • No other workspace crate depends on fleet-launcher (greped — fleet_launcher:: is only referenced inside this crate's own bin/ and heartbeat.rs)

@NagyVikt NagyVikt changed the base branch from feat/fleet-launcher to main May 16, 2026 15:06
Replace the per-variant match in build_command_line() with a
CliConvention trait implemented on CliKind. The trait owns
binary(), home_env(), and command_line(prompt, extra_args) so
new CLIs add one impl arm instead of touching a central match.

- build_command_line() collapses from ~30 lines to a single
  delegating call: spec.cli.command_line(prompt, extras).
- CliKind keeps its existing inherent binary() / home_env() methods
  for source compatibility; they delegate to the trait.
- Behavior preserved: Claude still injects
  --dangerously-skip-permissions, Gemini still pipes the prompt via
  printf '%s' | gemini, Codex and Claw still use a bare positional
  prompt, and home env vars (CODEX_HOME, CLAUDE_CONFIG_DIR,
  GEMINI_CLI_HOME, CLAW_CONFIG_HOME) are unchanged.
- All 12 existing tests pass.
@NagyVikt NagyVikt force-pushed the agent/refactor-cli-convention-trait branch from 71cc1b5 to cb195ce Compare May 16, 2026 15:07
@NagyVikt NagyVikt merged commit 139f2b6 into main May 16, 2026
3 checks passed
@NagyVikt NagyVikt deleted the agent/refactor-cli-convention-trait branch May 16, 2026 15:13
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