Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
101 changes: 101 additions & 0 deletions src/patches/thinkingLabel.ts
Original file line number Diff line number Diff line change
@@ -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;
};