Skip to content

Simplify the user message display patch#429

Merged
bl-ue merged 1 commit intomainfrom
simplify-user-message-display-patch-012826
Jan 29, 2026
Merged

Simplify the user message display patch#429
bl-ue merged 1 commit intomainfrom
simplify-user-message-display-patch-012826

Conversation

@bl-ue
Copy link
Member

@bl-ue bl-ue commented Jan 29, 2026

Now it works with every CC version from 0.2.9 to 2.1.23.

Summary by CodeRabbit

  • Refactor
    • Improved internal message display patch processing with a unified configuration approach.
    • Simplified component detection logic and error handling for patch operations.

✏️ Tip: You can customize this high-level summary in your review settings.

Now it works with every CC version from 0.2.9 to 2.1.23.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

The PR refactors user message display patching from multi-parameter function signatures to a unified config-driven architecture. The findBoxComponent helper is simplified to prioritize the ink-box pattern. The writeUserMessageDisplay function consolidates scattered parameters into a structured UserMessageDisplayConfig object.

Changes

Cohort / File(s) Summary
Helper Simplification
src/patches/helpers.ts
Reworks findBoxComponent to prioritize the ink-box createElement pattern and falls back to displayName-based Box pattern. Removes extensive fallback logic and alternative analyses, simplifying control flow by ~42 lines.
Configuration-Driven Refactor
src/patches/index.ts, src/patches/userMessageDisplay.ts
Consolidates multi-parameter writeUserMessageDisplay calls into a single UserMessageDisplayConfig object. Rewrites patch logic from location-based detection to unified config-driven approach with consolidated regex, chalk styling, and box attribute construction. Error handling unified to single consistent failure message.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

Hopping through patches with newfound grace,
Config objects take their place,
findBoxComponent trims the fat,
Chalk styling—simple and that,
Unified patterns, logic sublime,
The refactor's perfect, right on time! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: simplifying the user message display patch logic across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/patches/userMessageDisplay.ts`:
- Around line 234-238: The code builds formattedMessage and chalkFormattedString
by injecting config.format directly into a template literal, which breaks if
config.format contains backticks or `${`; fix this by pre-escaping those
sequences before composing formattedMessage — e.g., create an escapedFormat from
config.format where backticks are replaced with \` and the sequence `${` is
replaced with `\${`, then use escapedFormat in the existing formattedMessage
(`formattedMessage` and `chalkFormattedString`) so the patched JS remains valid;
update the code paths that reference config.format (the formattedMessage
construction and chalkFormattedString) to use the escapedFormat variable
instead.
🧹 Nitpick comments (1)
src/patches/helpers.ts (1)

293-310: Tighten ink-box regex to avoid false positives in minified bundles.

Line 293-296 uses wide .{0,2000} / .{0,200} spans, which can over-match in minified code and select the wrong component. Consider constraining the match to the current function body to keep it strict and deterministic.

♻️ Proposed tightening (stay within function body)
-  const inkBoxPattern =
-    /function ([$\w]+)\(.{0,2000}\b([$\w]+)=[$\w]+(?:\.default)?\.createElement\("ink-box".{0,200}?return \2/;
+  const inkBoxPattern =
+    /function ([$\w]+)\([^)]*\)\{[^}]{0,2000}\b([$\w]+)=[$\w]+(?:\.default)?\.createElement\("ink-box"[^}]{0,200}?return \2/;

Based on learnings: “In patches under src/patches/, assume code works with minified, original Claude Code installations. Patch regexes must be strict and match the minified format exactly (ignore formatting differences like whitespace/newlines).”

@bl-ue bl-ue merged commit f31efb5 into main Jan 29, 2026
2 checks passed
@bl-ue bl-ue deleted the simplify-user-message-display-patch-012826 branch January 29, 2026 02:57
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