Skip to content

Fix boundary detection to not use \b in several regexes and fix tool call patching typo#538

Merged
bl-ue merged 1 commit intomainfrom
fix-native-var-detection-and-toolset-patching-typo
Feb 23, 2026
Merged

Fix boundary detection to not use \b in several regexes and fix tool call patching typo#538
bl-ue merged 1 commit intomainfrom
fix-native-var-detection-and-toolset-patching-typo

Conversation

@bl-ue
Copy link
Copy Markdown
Member

@bl-ue bl-ue commented Feb 22, 2026

Closes #534

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

This PR systematically replaces word-boundary anchors (\b) with more specific non-word-character patterns ([^$\w]) across multiple patch detection files to refine boundary detection. Additionally, two public exports from toolsets.ts are removed, and a changelog entry documents these fixes.

Changes

Cohort / File(s) Summary
Boundary Detection Refinements
src/patches/helpers.ts, src/patches/inputPatternHighlighters.ts, src/patches/patchesAppliedIndication.ts, src/patches/subagentModels.ts
Updated regex patterns to use [^$\w] (non-word-character requirement) instead of word boundaries (\b) for more precise boundary detection in chalk variables, React variables, Box components, version detection, and agent patching.
API Changes
src/patches/toolsets.ts
Removed two public exports: getAppStateVarAndGetterFunction and getToolFetchingUseMemoLocation. Refactored getMainAppComponentBodyStart pattern to filter matches containing 'commands:' when selecting the longest segment.
Documentation Updates
src/patches/statuslineUpdateThrottle.ts, CHANGELOG.md
Updated regex pattern documentation comments and added changelog entry documenting boundary detection modifications and typo fix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #426: Directly modifies the same helper functions (findChalkVar, getReactVar, findBoxComponent) where boundary patterns are being updated.
  • PR #388: Modifies overlapping patch-detection logic including box component and toolset regex patterns affected by this PR.
  • PR #532: Applies regex-based patch detection changes across src/patches directory with overlapping edits in toolsets.ts.

Poem

🐰 With whiskers twitching, I hop along,
Replacing \b where words belong,
[^$\w] now guards each precious line,
No false boundaries to cross the sign,
Clean detection, precise and fine! ✨

🚥 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 summarizes the main changes: replacing \b word boundaries with non-word-character patterns in multiple regexes and fixing a tool call patching issue, which are the primary objectives of this PR.
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 (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-native-var-detection-and-toolset-patching-typo

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
Copy Markdown
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.

🧹 Nitpick comments (4)
src/patches/patchesAppliedIndication.ts (1)

97-97: \w+ in createElementPattern should be [$\w]+.

The (?:\w+|\{[^}]+\}) alternative uses \w+ to match a simple argument, but a minified identifier that starts with $ would not match.

♻️ Use `[$\w]+` for the simple-argument alternative
-    /[^$\w]([$\w]+)\.createElement\(([$\w]+),(?:\w+|\{[^}]+\}),/g;
+    /[^$\w]([$\w]+)\.createElement\(([$\w]+),(?:[$\w]+|\{[^}]+\}),/g;

As per coding guidelines: "Use [\$\\w]+ instead of \\w+ for identifier matching in regex patterns to include $ for React refs."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/patchesAppliedIndication.ts` at line 97, The regex assigned to
createElementPattern currently uses \w+ in the simple-argument alternative which
misses identifiers starting with $; update the alternative from
(?:\w+|\{[^}]+\}) to use a character class allowing $ (?:[$\w]+|\{[^}]+\}) so
that createElementPattern correctly matches minified/JS identifiers with $
(adjust the same change wherever createElementPattern is defined or used).
src/patches/toolsets.ts (1)

79-79: \w+: for property name matching — prefer [$\w]+: per guidelines.

The \w+: in the destructuring pattern is used to match property names like commands:, initialFileHistorySnapshots:, etc. While these specific names won't start with $, the coding guidelines prefer [$\w]+ uniformly for identifier matching.

♻️ Use `[$\w]+:` for consistency with coding guidelines
-    /function ([$\w]+)\(\{(?:\w+:[$\w]+(?:=(?:[^,]+,|[^}]+\})|[,}]))+initialFileHistorySnapshots:[$\w]+,(?:\w+:[$\w]+(?:=(?:[^,]+,|[^}]+\})|[,}]))+\)/g;
+    /function ([$\w]+)\(\{(?:[$\w]+:[$\w]+(?:=(?:[^,]+,|[^}]+\})|[,}]))+initialFileHistorySnapshots:[$\w]+,(?:[$\w]+:[$\w]+(?:=(?:[^,]+,|[^}]+\})|[,}]))+\)/g;

As per coding guidelines: "Use [\$\\w]+ instead of \\w+ for identifier matching in regex patterns to include $ for React refs."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/toolsets.ts` at line 79, Update the regex literal that matches
destructured property names to use the allowed identifier character class with
dollar: replace occurrences of `\w+:` with `[$\w]+:` in the pattern `/function
([$\w]+)\(\{(?:\w+:[$\w]+(...))+initialFileHistorySnapshots:[$\w]+,(?:\w+:[$\w]+(...))+\\)/g`
so all property-name matches use `[$\w]+:` (preserve the rest of the pattern and
escaping exactly as in the existing regex).
src/patches/helpers.ts (2)

166-167: Comment now slightly misleading after the \b[^$\w] change.

The comment on line 166 still reads ;([$\w]+)=T\(fH\(\),1\) (documenting a ; prefix), but the actual pattern now accepts any [^$\w] character.

♻️ Update comment
-  // ;([$\w]+)=T\(fH\(\),1\)
-  // Pattern: ;X=moduleLoader(reactModuleBun,1)
+  // [^$\w]([$\w]+)=T\(fH\(\),1\)
+  // Pattern: <non-$\w>X=moduleLoader(reactModuleBun,1)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/helpers.ts` around lines 166 - 167, Update the misleading comment
that still shows a leading semicolon `;([$\w]+)=T\(fH\(\),1\)` to reflect the
actual regex change from a `\b` boundary to `[^$\w]` — e.g., mention the pattern
now accepts any non-$\w character (showing `[^$\w]([$\w]+)=T\(fH\(\),1)` or
equivalent description). Locate the comment near the pattern in
src/patches/helpers.ts and replace the old example/comment text so it accurately
documents the current regex behavior.

6-6: Residual \b in the findChalkVar pattern.

The \b after each method name (e.g., cyan\b, bold\b) is redundant — the next character is always . or (, both non-word, so \b is vacuously true — but the guidelines say to avoid \b entirely due to V8 performance.

♻️ Remove the redundant `\b`
-    /[^$\w]([$\w]+)(?:\.(?:cyan|gray|green|red|yellow|ansi256|bgAnsi256|bgHex|bgRgb|hex|rgb|bold|dim|inverse|italic|strikethrough|underline)\b)+\(/g;
+    /[^$\w]([$\w]+)(?:\.(?:cyan|gray|green|red|yellow|ansi256|bgAnsi256|bgHex|bgRgb|hex|rgb|bold|dim|inverse|italic|strikethrough|underline))+\(/g;

As per coding guidelines: "Avoid \\b in regex patterns due to V8 performance issues; use literal character alternatives."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/patches/helpers.ts` at line 6, The regex assigned to findChalkVar
contains residual \b tokens after each chalk method (e.g., cyan\b, bold\b);
remove those \b instances and update the pattern to use literal-character checks
instead (for example replace each \b with a lookahead like (?=[.(]) or simply
drop them since the next char is always '.' or '(') so the regex still matches
chained chalk methods without using word-boundary anchors.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/patches/helpers.ts`:
- Around line 166-167: Update the misleading comment that still shows a leading
semicolon `;([$\w]+)=T\(fH\(\),1\)` to reflect the actual regex change from a
`\b` boundary to `[^$\w]` — e.g., mention the pattern now accepts any non-$\w
character (showing `[^$\w]([$\w]+)=T\(fH\(\),1)` or equivalent description).
Locate the comment near the pattern in src/patches/helpers.ts and replace the
old example/comment text so it accurately documents the current regex behavior.
- Line 6: The regex assigned to findChalkVar contains residual \b tokens after
each chalk method (e.g., cyan\b, bold\b); remove those \b instances and update
the pattern to use literal-character checks instead (for example replace each \b
with a lookahead like (?=[.(]) or simply drop them since the next char is always
'.' or '(') so the regex still matches chained chalk methods without using
word-boundary anchors.

In `@src/patches/patchesAppliedIndication.ts`:
- Line 97: The regex assigned to createElementPattern currently uses \w+ in the
simple-argument alternative which misses identifiers starting with $; update the
alternative from (?:\w+|\{[^}]+\}) to use a character class allowing $
(?:[$\w]+|\{[^}]+\}) so that createElementPattern correctly matches minified/JS
identifiers with $ (adjust the same change wherever createElementPattern is
defined or used).

In `@src/patches/toolsets.ts`:
- Line 79: Update the regex literal that matches destructured property names to
use the allowed identifier character class with dollar: replace occurrences of
`\w+:` with `[$\w]+:` in the pattern `/function
([$\w]+)\(\{(?:\w+:[$\w]+(...))+initialFileHistorySnapshots:[$\w]+,(?:\w+:[$\w]+(...))+\\)/g`
so all property-name matches use `[$\w]+:` (preserve the rest of the pattern and
escaping exactly as in the existing regex).

@bl-ue bl-ue merged commit cc935ad into main Feb 23, 2026
2 checks passed
@bl-ue bl-ue deleted the fix-native-var-detection-and-toolset-patching-typo branch February 23, 2026 00:14
ljepson pushed a commit to ljepson/tweakcc that referenced this pull request Feb 25, 2026
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.

cc 2.1.50 undefined is not an object (evaluating 'R.blue')

1 participant