Skip to content

Conversation

@linw1995
Copy link
Owner

Summary

This PR focuses on reducing code duplication and improving error handling across multiple modules:

Changes

1. Anthropic client (crates/anthropic/src/client.rs)

  • Introduced messages_builder! macro to eliminate duplication between MessagesBuilder and MessagesStreamBuilder
  • Reduced ~120 lines of repetitive builder code
  • Both builders now share a single implementation via macro

2. Code highlighting (crates/coco-highlight/src/lang.rs)

  • Created simple_config() helper function to reduce duplication in language configuration
  • Consolidated bash, diff, and JSON config creation into a single reusable function

3. Component macros (crates/coco-macro/src/lib.rs)

  • Extracted parse_type_id() function with improved error handling
  • Added proper span information for compile-time errors
  • Better error messages when component attribute is missing or malformed
  • Both ComponentExt and ContentComponentExt macros now share the same parsing logic

4. TUI widgets (crates/coco-tui/src/widgets/)

  • Created new shared tabs module with reusable tab panel utilities
  • Extracted tab_panel_width(), tab_panel_height(), and render_tabs_panel() functions
  • Both bash and str_replace tools now use the shared tab rendering code

5. Session socket client (src/combo/session.rs)

  • Introduced send_and_expect() helper method to reduce duplication in request-response patterns
  • All metadata, MCP, prompt, and reply methods now use the same underlying implementation

Benefits

  • Reduced code duplication: ~200+ lines of repetitive code eliminated
  • Improved maintainability: Changes to builder/response patterns now only need to be made in one place
  • Better error messages: Compile-time errors in macros now include proper span information
  • Clearer code organization: Shared utilities are properly abstracted into reusable functions

- Use declarative macro to generate MessagesBuilder and MessagesStreamBuilder
- Improve proc-macro error reporting with proper span information
- Extract shared tab panel rendering function into widgets/tabs module
- Add send_and_expect helper to simplify session socket client
@linw1995 linw1995 added the enhancement New feature or request label Jan 28, 2026
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 31.57895% with 143 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.15%. Comparing base (a46f02c) to head (00bbe8f).
⚠️ Report is 9 commits behind head on dev.

Files with missing lines Patch % Lines
crates/anthropic/src/client.rs 0.00% 80 Missing ⚠️
crates/coco-tui/src/widgets/tabs.rs 0.00% 25 Missing ⚠️
crates/coco-macro/src/lib.rs 64.86% 13 Missing ⚠️
...ates/coco-tui/src/components/messages/tool/bash.rs 0.00% 10 Missing ⚠️
...co-tui/src/components/messages/tool/str_replace.rs 0.00% 9 Missing ⚠️
src/combo/session.rs 76.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #153      +/-   ##
==========================================
- Coverage   50.22%   47.15%   -3.08%     
==========================================
  Files          93       99       +6     
  Lines       25033    27274    +2241     
==========================================
+ Hits        12574    12860     +286     
- Misses      12459    14414    +1955     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@linw1995 linw1995 merged commit 7f457e0 into dev Jan 28, 2026
3 checks passed
@linw1995 linw1995 deleted the refactor/claude-auto branch January 28, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants