Skip to content

Conversation

@cawpea
Copy link
Owner

@cawpea cawpea commented Jan 2, 2026

Issue

closes #36

cawpea and others added 9 commits January 2, 2026 12:13
- Add message-formatter.ts for consistent CLI output styling
- Replace raw ANSI codes with chalk in diff-display.ts
- Standardize emoji usage across all commands (10 distinct types)
- Implement color scheme (red=error, green=success, yellow=warning, cyan=info)
- Translate Japanese comments/messages to English in backup.ts
- Refactor all console output to use msg.* helpers
- Add verbose mode support with debug messages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add displayColoredCodeBlock function to parse markdown code blocks
- Display code with green + prefix and dim backticks
- Apply to INSERT_CODE_BLOCK and default preview cases
- Improve visual clarity when previewing code insertions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Detect CODE_REF comment changes with arrow (→)
- Display old CODE_REF in red, arrow in yellow, new CODE_REF in green
- Highlight CODE_REF: label in cyan bold for single comments
- Dim HTML comment markers (<!-- and -->)
- Improve visual clarity when reviewing fix options

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…NTENT_MISMATCH

When Option 2 is selected for CODE_CONTENT_MISMATCH errors (converting symbol reference to line numbers),
the preview now displays a diff showing:
- The code block that will be kept (from markdown)
- The actual code in the file at the new line numbers

This makes it clear to users that the code block needs manual adjustment after updating the CODE_REF comment
to use line numbers instead of symbol references.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ISMATCH

When Option 2 is selected for CODE_CONTENT_MISMATCH errors (converting symbol
reference to line numbers), the preview was incorrectly showing both expected
and actual code as the same.

Root cause: The switch statement was using error.type instead of action.type,
which caused it to hit the CODE_CONTENT_MISMATCH case handler instead of the
UPDATE_LINE_NUMBERS case handler. This resulted in comparing error.expectedCode
(1 line from document) with action.newCodeBlock (also 1 line from document)
instead of extracting the actual code from the file (4 lines with JSDoc).

Changes:
- Switch on action.type instead of error.type in displayFixPreview
- Add special handling for CODE_LOCATION_MISMATCH within UPDATE_LINE_NUMBERS case
- Remove unused displayLineRangeDiff import
- Update test to use flexible string matching for colored output

Now correctly displays:
- Expected code (in document): 1 line without JSDoc
- Actual code (in file): 4 lines with JSDoc comment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
When Option 2 is selected for CODE_CONTENT_MISMATCH (convert symbol to line numbers),
the previous behavior showed a confusing diff between document code and file code,
making users think the code block would be updated. However, Option 2 only updates
the CODE_REF comment and keeps the code block unchanged.

Changes:
- Remove code diff display for UPDATE_LINE_NUMBERS from CODE_CONTENT_MISMATCH
- Show clear warning message that code block will remain unchanged
- Remove unused extractLinesFromFile import

This makes it clear that:
- Option 1: Updates both CODE_REF and code block
- Option 2: Updates only CODE_REF, code block needs manual adjustment

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
  - Add note about color-coded output in CLI usage guide
  - Describe standardized color schemes and emoji indicators
  - Update following introduction of centralized message formatter
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

Pull Request Review

Thank you for this PR! This is a well-structured refactoring that significantly improves the consistency and maintainability of CLI output.

Strengths

1. Excellent Architecture

  • The new message-formatter.ts module provides centralized, well-documented message formatting
  • Good separation of concerns between message-formatter and styles modules
  • Clean API via the msg convenience export

2. Code Quality

  • Comprehensive JSDoc comments throughout
  • Consistent TypeScript usage
  • Good use of chalk for color management
  • Significantly improved readability

3. Improved User Experience

  • Unified color scheme across commands
  • Better diff display with grouped changes
  • Documentation update in cli-usage.md

4. Good Refactoring

  • Converted Japanese comments to English in backup.ts
  • Updated test expectations to match new output

Issues and Concerns

1. Missing Test Coverage (HIGH PRIORITY)

The new message-formatter.ts module (237 lines) has NO test coverage. This is a significant gap.

Recommendation: Create src/utils/message-formatter.test.ts with tests for each message type, verbose mode behavior, complex formatters, and edge cases.

2. Redundant Verbose Check (Low Priority)

In src/cli/fix.ts:223, the explicit options.verbose check is redundant since msg.debug() already checks verbose mode internally.

3. Breaking Change Not Documented (Medium Priority)

The backup.ts error messages changed from Japanese to English. Should be documented in PR description or CHANGELOG.

4. Verbose Mode State

The verbose flag is stored as static state which could cause issues in testing. Consider adding a reset method.

Additional Observations

  • The new diff grouping logic in diff-display.ts is excellent
  • All code style requirements from CLAUDE.md are met
  • No security concerns identified

Recommendations

Must Fix:

  1. Add test coverage for message-formatter.ts (blocking issue)

Should Fix:
2. Remove redundant options.verbose check in fix.ts:223
3. Document the breaking change in PR description

Nice to Have:
4. Add a reset method for verbose state to help with testing

Overall Assessment

This is a high-quality refactoring with sound architectural decisions, clean code, and good documentation. The only significant concern is missing test coverage for the new module.

Score: 8/10 (would be 9.5/10 with test coverage)

Great work on this PR!

Add 48 test cases covering:
- Basic message formatting (error, warning, info, success, neutral)
- Verbose mode and debug functionality
- Error detail formatting with optional location
- Summary formatting with backup paths
- Specialized messages (startFix, startValidation, file, backup, skip, context)
- msg convenience export
- COLOR_SCHEMES export
- Special character handling (HTML, newlines, Unicode)
- Edge cases (long messages, large numbers, many backups)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

Pull Request Review: Feature/#36 Unify Style Prompts

Overview

This PR successfully centralizes message formatting and styling across the CLI by introducing a new message-formatter utility module. The changes create a consistent user experience with unified color schemes, emojis, and message formats.


✅ Strengths

1. Excellent Code Organization

  • The new message-formatter.ts module provides a clean, centralized API for all message formatting
  • Clear separation of concerns with dedicated methods for different message types
  • Well-structured color schemes and emoji constants
  • The convenience export (msg) provides an ergonomic API

2. Comprehensive Test Coverage

  • message-formatter.test.ts has 382 lines of thorough test cases
  • Tests cover:
    • All basic formatting methods (error, warning, info, success, etc.)
    • Verbose mode functionality
    • Edge cases (empty strings, special characters, unicode, long messages)
    • All specialized methods (errorDetail, summary, etc.)
    • The convenience export API
  • Tests verify both emoji inclusion and color application

3. Consistent Styling Across CLI

  • Both validate.ts and fix.ts now use the unified message formatter
  • diff-display.ts updated to use COLOR_SCHEMES from message-formatter
  • styles.ts properly imports and reuses color schemes for consistency
  • Removes hardcoded ANSI codes and scattered emoji usage

4. Good Documentation

  • Added user-facing documentation in docs/user-guide/cli-usage.md
  • JSDoc comments on all public methods
  • Clear type definitions

5. Improved UX Features

  • Verbose mode support with msg.setVerbose()
  • Debug messages only shown when verbose mode enabled
  • Better visual hierarchy with context indentation
  • Grouped diff output in diff-display.ts (removed lines shown together, then added lines)

🔍 Code Quality Observations

Minor Issues

  1. Potential Global State Issue (src/utils/message-formatter.ts:49)

    • The verboseMode is stored as static class state
    • This could be problematic if the module is used in parallel contexts or tests run concurrently
    • Suggestion: Consider making this configurable through dependency injection or ensuring proper cleanup in tests
  2. Type Safety (src/utils/message-formatter.ts:11)

    • MessageType is defined but never used in the actual implementation
    • Suggestion: Either remove it or use it to type-check method parameters
  3. Inconsistent Emoji Spacing (src/utils/prompt.ts:161)

    • Line 161 has hardcoded emoji: '\n⚠️ Note: Code block will remain unchanged...'
    • This bypasses the centralized emoji system and should use msg.warning() instead
    • Recommendation: Refactor to use the message formatter
  4. Diff Display Grouping (src/utils/diff-display.ts:18-59)

    • The new grouping logic is good but adds some complexity
    • The flushChanges function is nested and could be easier to test if extracted
    • Suggestion: Consider extracting this as a helper function for better testability
  5. Error Message Internationalization

    • Removed Japanese error messages (src/utils/backup.ts:32)
    • All messages are now English-only
    • Question: Is i18n support planned for the future? If so, the message-formatter might need refactoring

🐛 Potential Bugs

None identified - The code changes look solid with no obvious bugs.


⚡ Performance Concerns

No significant concerns. The changes are primarily cosmetic/formatting:

  • String operations are lightweight
  • No new I/O operations introduced
  • Chalk is already a dependency, so no additional overhead

🔒 Security Concerns

No security issues identified. The changes deal with display formatting only and don't:

  • Process untrusted input
  • Execute shell commands
  • Access sensitive data
  • Create vulnerabilities

🧪 Test Coverage Assessment

Excellent test coverage with a few notes:

  1. Integration Testing

    • While unit tests are comprehensive, consider adding integration tests that verify the end-to-end CLI output
    • Testing the actual colored output in CI might be tricky (consider snapshot testing)
  2. Missing Test Case (src/utils/diff-display.test.ts:80)

    • New test added for grouped changes is good
    • However, it doesn't test the case where changes are interspersed with matching lines
    • Suggestion: Add test case for pattern like: change → match → change
  3. Verbose Mode Test Isolation (src/utils/message-formatter.test.ts:60-62)

    • Tests properly reset verbose mode in beforeEach
    • Good practice to avoid test pollution

📚 Documentation Needs

  1. User Documentation

    • Added helpful context to docs/user-guide/cli-usage.md
    • Explains the color-coded output feature
  2. Developer Documentation ⚠️

    • Consider adding examples of how to use message-formatter in the architecture docs
    • Could benefit from a migration guide if other contributors need to update old code
    • Suggestion: Add a brief section to docs/development/coding-standards.md about using the message formatter
  3. API Documentation

    • JSDoc comments are present and clear

📊 Code Metrics

  • Files changed: 13
  • Additions: 881 lines
  • Deletions: 181 lines
  • Net change: +700 lines (mostly tests and new utility)
  • New files: 2 (message-formatter.ts and message-formatter.test.ts)

The line count increase is justified by:

  • Comprehensive test suite (382 lines)
  • Well-documented new module (237 lines)
  • Improved code clarity throughout

🎯 Adherence to Coding Standards

Based on CLAUDE.md and coding standards:

Style Compliance

  • 2-space indentation: ✅
  • Single quotes: ✅
  • Semicolons enabled: ✅
  • 100 char print width: ✅
  • Type imports: ✅ (import type used in message-formatter.ts:11)

Best Practices

  • Proper TypeScript types
  • Good function decomposition
  • Clear naming conventions

🎨 Suggestions for Enhancement

  1. Color Configuration

    • Consider making colors configurable for different terminal themes
    • Some users might want to disable colors (CI environments, accessibility)
    • Suggestion: Add a NO_COLOR environment variable check
  2. Testing Utilities

    • The message formatter could export a stripAnsi utility for testing
    • Would help other tests verify message content without color codes
  3. Performance Optimization (very minor)

    • formatCodeLine in styles.ts:161-206 does multiple regex replacements
    • Consider using a single pass with a more complex regex if this becomes a bottleneck

✅ Recommendation

APPROVE with minor suggestions

This is a high-quality PR that significantly improves the codebase:

  • Clear improvement in code organization
  • Excellent test coverage
  • Better user experience
  • No breaking changes
  • Well-documented

The minor issues identified are not blockers and could be addressed in follow-up PRs if desired.

Closes #36


🔄 Optional Follow-up Tasks

Consider creating issues for:

  1. Adding NO_COLOR environment variable support
  2. Integration/snapshot tests for CLI output
  3. Developer guide section in documentation
  4. Refactoring remaining hardcoded emojis (like prompt.ts:161)

Great work on this refactor! 🎉

@cawpea cawpea merged commit 7a67ab1 into develop Jan 2, 2026
4 checks passed
@cawpea cawpea deleted the feature/#36_unify-style-prompts branch January 2, 2026 15:06
@github-actions
Copy link

github-actions bot commented Jan 2, 2026

🎉 This PR is included in version 0.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify the style of various prompts.

2 participants