diff --git a/CHANGELOG.md b/CHANGELOG.md index 75ab82d..4e70e83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't suppress line numbers by default (#360) - @bl-ue - Fix hideCtrlGToEdit patch (#361) - @basekevin - Fix context limit patch for CC 2.1.5 (#367) - @bl-ue +- Add a patch to make thinking blocks italic and dim again (#369) - @bl-ue ## [v3.2.5](https://github.com/Piebald-AI/tweakcc/releases/tag/v3.2.5) - 2026-01-09 diff --git a/src/patches/index.ts b/src/patches/index.ts index bf4bb62..dc1e550 100644 --- a/src/patches/index.ts +++ b/src/patches/index.ts @@ -63,6 +63,7 @@ import { writeHideStartupClawd } from './hideStartupClawd'; import { writeIncreaseFileReadLimit } from './increaseFileReadLimit'; import { writeSuppressLineNumbers } from './suppressLineNumbers'; import { writeSuppressRateLimitOptions } from './suppressRateLimitOptions'; +import { writeThinkingLabel } from './thinkingLabel'; import { restoreNativeBinaryFromBackup, restoreClijsFromBackup, @@ -605,6 +606,9 @@ export const applyCustomization = async ( // Apply thinking visibility patch (always enabled) if ((result = writeThinkingVisibility(content))) content = result; + // Apply thinking label styling patch (always enabled) + if ((result = writeThinkingLabel(content))) content = result; + // Apply patches applied indication const showTweakccVersion = config.settings.misc?.showTweakccVersion ?? true; const showPatchesApplied = config.settings.misc?.showPatchesApplied ?? true; diff --git a/src/patches/thinkingLabel.ts b/src/patches/thinkingLabel.ts new file mode 100644 index 0000000..0486740 --- /dev/null +++ b/src/patches/thinkingLabel.ts @@ -0,0 +1,101 @@ +// Please see the note about writing patches in ./index + +import { + LocationResult, + findBoxComponent, + findTextComponent, + getReactVar, + showDiff, +} from './index'; + +/** + * Finds the location of the "∴ Thinking…" createElement call to style it. + * + * Steps: + * 1. Find "∴ Thinking…" string + * 2. Within 200 chars, find createElement(X,null,Y) pattern + */ +const findThinkingLabelLocation = (oldFile: string): LocationResult | null => { + // Step 1: Find the "∴ Thinking…" anchor string + const thinkingAnchor = '∴ Thinking…'; + const anchorIndex = oldFile.indexOf(thinkingAnchor); + + if (anchorIndex === -1) { + console.error('patch: thinkingLabel: failed to find "∴ Thinking…" anchor'); + return null; + } + + // Step 2: Search within 200 characters after the anchor + const searchStart = anchorIndex; + const searchEnd = Math.min(anchorIndex + 200, oldFile.length); + const searchSection = oldFile.slice(searchStart, searchEnd); + + // Pattern: (reactVar).createElement(X,null,(thinkingTextVar)) + // We need to capture the whole expression and the react var + thinking text var + const createElementPattern = + /([$\w]+(?:\.default)?)\.createElement\(([$\w]+),null,([$\w]+)\)/; + const match = searchSection.match(createElementPattern); + + if (!match || match.index === undefined) { + console.error( + 'patch: thinkingLabel: failed to find createElement pattern within 200 chars of anchor' + ); + return null; + } + + return { + startIndex: searchStart + match.index, + endIndex: searchStart + match.index + match[0].length, + identifiers: [match[1], match[2], match[3]], // [reactVar, component, thinkingTextVar] + }; +}; + +/** + * Wraps the thinking label in styled Text component with italic and dimColor. + */ +export const writeThinkingLabel = (oldFile: string): string | null => { + const location = findThinkingLabelLocation(oldFile); + if (!location) { + return null; + } + + // Get Box and Text components from utilities + const boxVar = findBoxComponent(oldFile); + if (!boxVar) { + console.error('patch: thinkingLabel: failed to find Box component'); + return null; + } + + const textVar = findTextComponent(oldFile); + if (!textVar) { + console.error('patch: thinkingLabel: failed to find Text component'); + return null; + } + + const reactVar = getReactVar(oldFile); + if (!reactVar) { + console.error('patch: thinkingLabel: failed to find React variable'); + return null; + } + + const thinkingTextVar = location.identifiers![2]; + + // Build the replacement: + // ${reactVar}.createElement(${boxVar}, null, ${reactVar}.createElement(${textVar}, {italic:true,dimColor:true}, ${thinkingTextVar})) + const replacement = `${reactVar}.createElement(${boxVar},null,${reactVar}.createElement(${textVar},{italic:true,dimColor:true},${thinkingTextVar}))`; + + const newFile = + oldFile.slice(0, location.startIndex) + + replacement + + oldFile.slice(location.endIndex); + + showDiff( + oldFile, + newFile, + replacement, + location.startIndex, + location.endIndex + ); + + return newFile; +};