Skip to content
Merged
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
51 changes: 51 additions & 0 deletions src/utils/patching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,54 @@ function showDiff(
}
}

const getVerbosePropertyLocation = (oldFile: string): LocationResult | null => {
const createElementPattern =
/createElement\([$\w]+,\{[^}]+spinnerTip[^}]+overrideMessage[^}]+\}/;
const createElementMatch = oldFile.match(createElementPattern);

if (!createElementMatch || createElementMatch.index === undefined) {
console.error(
'patch: verbose: failed to find createElement with spinnerTip and overrideMessage'
);
return null;
}

const extractedString = createElementMatch[0];

const verbosePattern = /verbose:[^,}]+/;
const verboseMatch = extractedString.match(verbosePattern);

if (!verboseMatch || verboseMatch.index === undefined) {
console.error('patch: verbose: failed to find verbose property');
return null;
}

// Calculate absolute positions in the original file
const absoluteVerboseStart = createElementMatch.index + verboseMatch.index;
const absoluteVerboseEnd = absoluteVerboseStart + verboseMatch[0].length;

return {
startIndex: absoluteVerboseStart,
endIndex: absoluteVerboseEnd,
};
};

export const writeVerboseProperty = (oldFile: string): string | null => {
const location = getVerbosePropertyLocation(oldFile);
if (!location) {
return null;
}

const newCode = 'verbose:true';
const newFile =
oldFile.slice(0, location.startIndex) +
newCode +
oldFile.slice(location.endIndex);

showDiff(oldFile, newFile, newCode, location.startIndex, location.endIndex);
return newFile;
};

export const applyCustomization = async (
config: TweakccConfig,
ccInstInfo: ClaudeCodeInstallationInfo
Expand Down Expand Up @@ -662,6 +710,9 @@ export const applyCustomization = async (
if ((result = writeThinkerSymbolMirrorOption(content, config.settings.thinkingStyle.reverseMirror)))
content = result;

// Apply verbose property patch (always true by default)
if ((result = writeVerboseProperty(content))) content = result;

await fs.writeFile(ccInstInfo.cliPath, content);
return await updateConfigFile(config => {
config.changesApplied = true;
Expand Down