Skip to content

refactor(broker): split main.rs into CLI and runtime modules #875

Description

@willwashburn

Problem

src/main.rs is over 7k lines and currently owns many unrelated responsibilities: CLI definitions, command dispatch, broker runtime setup, Relaycast connection setup, delivery retry state, helper functions, and tests. That makes the binary entrypoint hard to scan and hard to test in isolation.

Scope

After the broker crate is isolated, make main.rs a thin entrypoint and move responsibilities into focused modules.

Suggested shape:

src/main.rs
src/cli/mod.rs
src/cli/args.rs
src/cli/commands/init.rs
src/cli/commands/pty.rs
src/cli/commands/headless.rs
src/cli/commands/mcp_args.rs
src/cli/commands/swarm.rs
src/cli/commands/dump_pty.rs
src/cli/commands/wrap.rs
src/broker/runtime.rs
src/broker/delivery.rs
src/broker/state.rs

Acceptance criteria

  • main.rs mostly parses/dispatches through relay_broker::cli::run() or equivalent.
  • Clap command structs are moved out of main.rs into cli modules.
  • run_init, run_headless_worker, run_dump_pty, and MCP argument handling live near their command modules or a broker runtime module.
  • Existing CLI behavior and flags remain compatible.
  • Relevant Rust tests pass.

Notes

This should be a mechanical extraction where possible. Avoid broad behavior changes so the diff stays reviewable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions