Skip to content

Add patch to prevent updates to unsupported versions#408

Draft
mike1858 wants to merge 6 commits intomainfrom
autoupdate
Draft

Add patch to prevent updates to unsupported versions#408
mike1858 wants to merge 6 commits intomainfrom
autoupdate

Conversation

@mike1858
Copy link
Member

@mike1858 mike1858 commented Jan 24, 2026

Closes #170.

Note: I can't test this until a new version of Claude Code (2.1.20) comes out.

Summary by CodeRabbit

  • New Features
    • Added a new setting "Prevent updates to unsupported versions" (default: off).
    • Exposed a toggle in Misc settings so users can enable/disable this behavior from the UI.
    • When enabled, the app checks update targets and blocks installation of versions not yet supported, preventing those updates from proceeding.

✏️ Tip: You can customize this high-level summary in your review settings.

@mike1858 mike1858 requested a review from bl-ue January 24, 2026 18:48
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 24, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review
📝 Walkthrough

Walkthrough

Adds a new misc setting preventUpdateToUnsupportedVersions, exposes it in the UI, and wires a new patch into the patch pipeline that injects a runtime check into the auto-updater to block updates when the corresponding prompts file is missing on GitHub.

Changes

Cohort / File(s) Summary
Configuration & Types
src/defaultSettings.ts, src/types.ts
Add preventUpdateToUnsupportedVersions: boolean to DEFAULT_SETTINGS and MiscConfig (default: false).
Patching Pipeline
src/patches/index.ts, src/patches/preventUnsupportedUpdates.ts
Add writePreventUnsupportedUpdates export and invoke it in the patch pipeline when the misc flag is enabled; new patch injects a version-check + HEAD request flow into the minified auto-updater to block unsupported-version updates.
User Interface
src/ui/components/MiscView.tsx
Add toggle preventUnsupportedUpdates bound to settings.misc.preventUpdateToUnsupportedVersions, ensuring misc is initialized before updating.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant UI as tweakcc UI
    participant Patch as Patch Pipeline
    participant Updater as Auto-updater (patched)
    participant GitHub as GitHub

    User->>UI: Toggle "Prevent unsupported updates" (on)
    UI->>Patch: Persist settings (preventUpdateToUnsupportedVersions = true)
    Note over Patch: Patch pipeline runs during packaging/patch step and injects check into Updater

    Note over Updater: At runtime when checking for updates...
    Updater->>GitHub: HEAD /prompts/VERSION_X
    GitHub-->>Updater: 200 / 404
    alt 200 OK
        Updater->>Updater: Proceed with update to VERSION_X
    else 404 Not Found
        Updater->>Updater: Block update (unsupported)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • bl-ue

Poem

🐰
I hop through code at break of dawn,
I stitch a guard where updates spawn,
No leap to versions we can't tend,
Prompts stay safe — I watch and mend,
Hooray for steady, snug-updates! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 change: adding a patch mechanism to prevent updates to unsupported Claude Code versions, which is the primary objective of this PR.
Linked Issues check ✅ Passed The PR implements the requested feature from issue #170: preventing auto-updates to unsupported Claude Code versions while keeping auto-update enabled, through configuration flag, patch logic, and UI controls.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the unsupported version prevention feature: configuration flag, patching logic, UI integration, and type definitions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch autoupdate

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/patches/preventUnsupportedUpdates.ts`:
- Around line 106-112: The injected test code in tweakccVersionCheck is spoofing
the fetched version to "99.0.0" and writing debug logs to /tmp/tweakcc-test.log,
which will always block updates and leaks logs; remove the test artifacts so the
check uses the real fetched version variable (versionVar/v) and eliminate all
require("fs").appendFileSync calls and the hardcoded v="99.0.0" assignment;
retain the HEAD request using fetchFunc/channelVar and return currentVersionVar
only when the HEAD check fails or throws, preserving the original control flow
in the async IIFE.
🧹 Nitpick comments (1)
src/patches/preventUnsupportedUpdates.ts (1)

100-104: Consider adding length validation for identifiers array.

While getAutoUpdaterLocation guarantees 6 elements in identifiers when returning non-null, the non-null assertions (!) here rely on that implicit contract. If the regex or return structure changes, this could silently break.

💡 Optional: Add explicit validation
+  if (!location.identifiers || location.identifiers.length < 6) {
+    console.error('patch: preventUnsupportedUpdates: invalid identifiers array');
+    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];
+  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];

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/patches/preventUnsupportedUpdates.ts`:
- Around line 106-110: The injected tweakccVersionCheck currently swallows HEAD
fetch errors and allows updates; change the inline IIFE so its catch returns the
current version variable (currentVersionVar) to fail-closed: inside the
try/catch in the async IIFE used to compute versionVar (the template string
assigned to tweakccVersionCheck that references versionVar, fetchFunc,
channelVar, and currentVersionVar), ensure the catch block returns
${currentVersionVar} (and not nothing) so any fetch exception causes the code to
fallback to the current version and block the update.
🧹 Nitpick comments (1)
src/patches/preventUnsupportedUpdates.ts (1)

60-75: Broaden current-version lookup to reduce patch brittleness.

The 500‑char window and let‑only pattern make this easy to miss if minification shifts or uses const/var, causing the patch to no-op. Scanning up to the updater block and allowing const|var makes the match more resilient.

♻️ Suggested change
-  const searchStart = Math.max(0, autoUpdaterLocation.startIndex - 500);
-  const searchChunk = oldFile.slice(
-    searchStart,
-    autoUpdaterLocation.startIndex
-  );
+  const searchChunk = oldFile.slice(0, autoUpdaterLocation.startIndex);

-  const pattern = /let ([$\w]+)=\{[^}]*ISSUES_EXPLAINER:/g;
+  const pattern = /\b(?:let|const|var)\s+([$\w]+)=\{[^}]*ISSUES_EXPLAINER:/g;

@mike1858 mike1858 requested a review from bl-ue January 24, 2026 23:17
georpar added a commit to georpar/tweakcc that referenced this pull request Jan 26, 2026
@georpar
Copy link
Member

georpar commented Jan 27, 2026

@mike1858 Not working for me:

patch: preventUnsupportedUpdates: failed to find auto-updater pattern

Once you've fixed that (and added the 2.1.20 prompts to the tweakcc repo), to test if the patch is working properly, you can modify the preventUnsupportedUpdates patch locally to point it to https://github.com/georpar/tweakcc (doesn't have 2.1.20 prompts), downgrade CC to 2.1.19. When you're done testing, point it back to Piebald-AI/tweakcc and test again, to make sure updating works when the latest system prompts are supported by tweakcc.

@georpar georpar marked this pull request as draft January 27, 2026 01:55
@mike1858
Copy link
Member Author

@georpar Can you please try it now and mark it as ready for review if it works? It should work.

@mike1858 mike1858 requested review from georpar and removed request for bl-ue January 30, 2026 18:02
@georpar
Copy link
Member

georpar commented Feb 1, 2026

The code looks good, and it works with npm installations, but it doesn't work with native installations. Needs to be investigated by @mike1858 or me.

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.

Feature: prevent auto-update to unsupported versions

3 participants