Skip to content

refactor(cli): replace the output globals with an explicit Out#322

Merged
socksy merged 2 commits into
developfrom
refactor/output-explicit-writer
Jul 15, 2026
Merged

refactor(cli): replace the output globals with an explicit Out#322
socksy merged 2 commits into
developfrom
refactor/output-explicit-writer

Conversation

@socksy

@socksy socksy commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Where CLI output went was controlled by two mutable globals: an OUTPUT_MODE and a CURRENT_SENDER that the MCP server set and cleared around each tool call. Every output::* function read them to choose between stdout, JSON, and the MCP peer. So a command never said where its output went. That was decided elsewhere, out of sight, and the MCP path had to juggle a global sender to capture anything a command printed.

This passes the destination in as a value instead. Commands take an Out, and the writing functions become methods on it. The CLI builds one over stdout. For an MCP tool, the Out wraps a writer that forwards each line to that call's channel. The sender and the notification flag live on the value now, not in globals.

Most of the ~17-file diff is the mechanical output::foo(x)out.foo(x) sweep.

Out is cloneable so the spawned log and status monitors can share the writer, which is why it sits behind an Arc<Mutex>. Tests, build, and fmt pass.

@socksy socksy force-pushed the refactor/output-explicit-writer branch from 27ff998 to d34e910 Compare July 6, 2026 19:41
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 43ece5e3-477a-4ed7-ae61-c65170bff4ce

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/output-explicit-writer

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

@socksy socksy force-pushed the refactor/output-explicit-writer branch 3 times, most recently from a4c7b3a to 2709898 Compare July 6, 2026 20:10
@socksy socksy marked this pull request as ready for review July 14, 2026 09:54
Where CLI output went was controlled by two mutable globals: an OUTPUT_MODE and a CURRENT_SENDER that the MCP server set and cleared around each tool call. Every output:: function read them to choose between stdout, JSON, and the MCP peer, so a command never said where its own output went.

Pass the destination in as a value instead: commands take an Out and the writing functions become methods on it. The CLI builds one over stdout; an MCP tool builds one whose writer forwards each line to that call's channel. The sender and the notification flag live on the value, not in globals.
@socksy socksy force-pushed the refactor/output-explicit-writer branch from 2709898 to a0233a2 Compare July 15, 2026 11:44
pub fn clean_head_sha(dir: &Path) -> Option<String> {
if !is_inside_work_tree(dir) {
debug!("{:?} is not inside a git worktree; skipping idempotency key", dir);
debug!(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but cargo fmt was failing on this file

@konstantinoscs konstantinoscs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I wonder if there's a way to actually test the concurrent call scenario (and that the channels never cross-talk

@socksy socksy merged commit 1b5dfd6 into develop Jul 15, 2026
28 checks passed
@socksy socksy deleted the refactor/output-explicit-writer branch July 15, 2026 12:55
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.

3 participants