-
Notifications
You must be signed in to change notification settings - Fork 80
Add patch to prevent updates to unsupported versions #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mike1858
wants to merge
6
commits into
main
Choose a base branch
from
autoupdate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+182
−0
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
279fd9a
Add patch to prevent updates to unsupported versions
mike1858 c5d20ed
Fix
mike1858 e04c393
Fix CR review
mike1858 d5c4d7c
Merge branch 'main' into autoupdate
georpar f0bb541
Merge branch 'main' into autoupdate
georpar a037a3d
Finish the preventUnsupportedUpdates patch
georpar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| // Please see the note about writing patches in ./index | ||
| // | ||
| // This patch prevents Claude Code from auto-updating to versions that tweakcc | ||
| // doesn't yet support. It works by checking if the prompts file exists on GitHub | ||
| // for the target version before allowing the update. | ||
|
|
||
| import { LocationResult, showDiff } from './index'; | ||
|
|
||
| /** | ||
| * Finds the location in the auto-updater where the latest version is fetched | ||
| * and the update decision is made. | ||
| * | ||
| * The pattern we're looking for (minified): | ||
| * BUILD_TIME:"..."}.VERSION,CHANNEL_VAR=hq()?.autoUpdatesChannel??"latest",VERSION_VAR=await FUNC(CHANNEL_VAR),OTHER_VAR=FUNC2(); | ||
| * | ||
| * We'll inject code after VERSION_VAR assignment to check if it's supported. | ||
| */ | ||
| const getAutoUpdaterLocation = (oldFile: string): LocationResult | null => { | ||
| // Pattern to match the auto-updater version fetch in minified code | ||
| // The key markers are: | ||
| // - BUILD_TIME:"..." followed by }.VERSION, | ||
| // - hq()?.autoUpdatesChannel??"latest" | ||
| // - await FUNC(VAR) pattern | ||
| // Captures: [1]=channel var, [2]=version var, [3]=fetch function, [4]=next var, [5]=next func | ||
| const pattern = | ||
| /BUILD_TIME:"[^"]+"\}\.VERSION,([$\w]+)=hq\(\)\?\.autoUpdatesChannel\?\?"latest",([$\w]+)=await ([$\w]+)\(\1\),([$\w]+)=([$\w]+)\(\);/; | ||
|
|
||
| const match = oldFile.match(pattern); | ||
|
|
||
| if (!match || match.index === undefined) { | ||
| console.error( | ||
| 'patch: preventUnsupportedUpdates: failed to find auto-updater pattern' | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| startIndex: match.index, | ||
| endIndex: match.index + match[0].length, | ||
| identifiers: [ | ||
| match[0], // Full match | ||
| match[1], // channel var (e.g., _) | ||
| match[2], // version var (e.g., Z) | ||
| match[3], // fetch function (e.g., _t) | ||
| match[4], // next var (e.g., G) | ||
| match[5], // next var's function (e.g., Ed) | ||
| ], | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets the variable name used for the current version. | ||
| * This is typically $ in the code pattern: | ||
| * let $={...}.VERSION, | ||
| */ | ||
| const getCurrentVersionVar = ( | ||
| oldFile: string, | ||
| autoUpdaterLocation: LocationResult | ||
| ): string | null => { | ||
| // Look backwards from our match to find the current version variable | ||
| // Pattern: let CURRENT_VAR={...ISSUES_EXPLAINER:... | ||
| const searchStart = Math.max(0, autoUpdaterLocation.startIndex - 500); | ||
| const searchChunk = oldFile.slice( | ||
| searchStart, | ||
| autoUpdaterLocation.startIndex | ||
| ); | ||
|
|
||
| // Find the last "let VAR={" pattern with ISSUES_EXPLAINER reference (minified format) | ||
| const pattern = /let ([$\w]+)=\{[^}]*ISSUES_EXPLAINER:/g; | ||
| let lastMatch = null; | ||
| let match; | ||
|
|
||
| while ((match = pattern.exec(searchChunk)) !== null) { | ||
| lastMatch = match; | ||
| } | ||
|
|
||
| if (!lastMatch) { | ||
| console.error( | ||
| 'patch: preventUnsupportedUpdates: failed to find current version variable' | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| return lastMatch[1]; | ||
| }; | ||
|
|
||
| export const writePreventUnsupportedUpdates = ( | ||
| oldFile: string | ||
| ): string | null => { | ||
| const location = getAutoUpdaterLocation(oldFile); | ||
| if (!location) { | ||
| return null; | ||
| } | ||
|
|
||
| const currentVersionVar = getCurrentVersionVar(oldFile, location); | ||
| if (!currentVersionVar) { | ||
| return null; | ||
| } | ||
|
|
||
| const channelVar = location.identifiers![1]; | ||
| const versionVar = location.identifiers![2]; | ||
| const fetchFunc = location.identifiers![3]; | ||
| const nextVar = location.identifiers![4]; | ||
| const nextFunc = location.identifiers![5]; | ||
|
|
||
| // Construct the replacement with the tweakcc version check injected | ||
| // The check wraps the version fetch to check if tweakcc supports the version. | ||
| // If the prompts file doesn't exist (404), it returns the current version to block the update. | ||
| const tweakccVersionCheck = `${versionVar}=await(async()=>{let v=await ${fetchFunc}(${channelVar});if(!v)return v;try{const r=await fetch(\`https://raw.githubusercontent.com/Piebald-AI/tweakcc/refs/heads/main/data/prompts/prompts-\${v}.json\`,{method:'HEAD'});if(!r.ok)return ${currentVersionVar};}catch(e){}return v;})(),`; | ||
|
|
||
| // Reconstruct the original prefix (BUILD_TIME part) which we matched but want to preserve | ||
| const buildTimeMatch = location.identifiers![0].match(/BUILD_TIME:"[^"]+"\}/); | ||
| const buildTimePrefix = buildTimeMatch ? buildTimeMatch[0] : ''; | ||
|
|
||
| const replacement = | ||
| buildTimePrefix + | ||
| `.VERSION,` + | ||
| `${channelVar}=hq()?.autoUpdatesChannel??"latest",` + | ||
| tweakccVersionCheck + | ||
| `${nextVar}=${nextFunc}();`; | ||
|
|
||
| const newFile = | ||
| oldFile.slice(0, location.startIndex) + | ||
| replacement + | ||
| oldFile.slice(location.endIndex); | ||
|
|
||
| showDiff( | ||
| oldFile, | ||
| newFile, | ||
| replacement, | ||
| location.startIndex, | ||
| location.endIndex | ||
| ); | ||
|
|
||
| return newFile; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.