Skip to content

Fix Fast mode for API key auth#90

Open
Clarence12138 wants to merge 2 commits into
Haleclipse:masterfrom
Clarence12138:fix/fast-mode-apikey
Open

Fix Fast mode for API key auth#90
Clarence12138 wants to merge 2 commits into
Haleclipse:masterfrom
Clarence12138:fix/fast-mode-apikey

Conversation

@Clarence12138

@Clarence12138 Clarence12138 commented Jun 23, 2026

Copy link
Copy Markdown

Summary

  • Fixes Codex 26.602.30954 缺失fast模式 #82.
  • Extends the Fast mode patch to handle newer positive authMethod === "chatgpt" gates by allowing API key auth too.
  • Keeps the legacy negative-gate patch path and makes reruns idempotent when the gate is already patched.

Notes

  • Rebuilt and manually verified on macOS arm64 with API key auth.
  • Confirmed patched ASAR contains chatgpt || apikey service-tier gates.

Summary by Sourcery

Update the Fast mode patch script to support newer auth gate patterns and improve its robustness and reporting.

Enhancements:

  • Extend Fast mode auth gate handling to support ChatGPT and API key users, including conditional gate patterns.
  • Refactor the AST traversal and patch collection logic into smaller helpers for readability and reuse.
  • Improve patch application flow with explicit parsing, platform targeting, and summary reporting, and export collectPatches for external use.

@sourcery-ai

sourcery-ai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors and extends the Fast mode patch script so it can detect and update both legacy negative auth gates and newer positive authMethod === "chatgpt" gates, including support for API key auth, while making the script more testable and its CLI behavior clearer.

Flow diagram for updated Fast mode auth gate patching

flowchart TD
  Main[Main CLI entry] --> GetPlatforms[GetPlatforms]
  GetPlatforms --> FindTargets[FindTargets]
  FindTargets -->|targets| ProcessBundles[Loop over bundles]

  ProcessBundles --> ProcessBundleFn[ProcessBundle]
  ProcessBundleFn --> ParseBundle[ParseBundle]
  ParseBundle --> CollectPatches[CollectPatches]

  subgraph AuthGateDetection[Auth gate detection]
    CollectPatches --> LegacyNeg[CollectLegacyNegativeGatePatches]
    CollectPatches --> PositiveGate[CollectPositiveAuthGatePatches]
    CollectPatches --> ConditionalGate[CollectConditionalAuthGatePatches]
  end

  ProcessBundleFn -->|isCheck| ReportCandidates[Print candidate patches]
  ProcessBundleFn -->|!isCheck and patches| ApplyPatches[ApplyPatches]
  ApplyPatches --> WriteFile[Write patched bundle]

  ProcessBundles --> Summary[PrintSummary]
  Summary --> Exit[Exit CLI]
Loading

File-Level Changes

Change Details Files
Add richer AST helpers and gate-detection logic to support both legacy negative auth gates and new positive ChatGPT-only gates, extending them to also allow API-key auth and handling conditional expressions.
  • Introduce utility helpers for walking the AST with parent context, extracting source snippets, detecting function nodes, string/false literals, and identifying authMethod === "chatgpt" binary expressions.
  • Implement detection of legacy negative !== auth gates and replace them with a constant false expression, while avoiding duplicates and no-op replacements.
  • Implement detection of positive authMethod === "chatgpt" gates and expand them into `chatgpt
Refactor bundle processing, platform discovery, and CLI behavior to make patching idempotent, testable, and more transparent via structured logging and a new export.
  • Split logic into smaller functions for finding target bundles, parsing bundles safely with error reporting, applying patches, computing available platforms, and processing a single bundle in either check or write mode.
  • Change output behavior to log each patch candidate or applied change with its original and replacement expression, and add a summarized result message depending on whether --check is used and how many gates were found/patched.
  • Adjust platform discovery to work without locateBundles, using direct directory scanning under SRC_DIR by platform/asar/assets path, and encapsulate platform resolution into a helper.
  • Guard main() with if (require.main === module) and export collectPatches to allow unit testing or reuse in other modules.
scripts/patch-fast-mode.js

Assessment against linked issues

Issue Objective Addressed Explanation
#82 Ensure the Codex 26.602.30954 Windows build exposes/enables Fast mode (removing or relaxing authMethod-based gates so Fast mode is available, including for API key authentication).

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new parseBundle now throws on parse errors where the previous version silently skipped problematic bundles; if mixed/legacy assets are expected, consider restoring the try/catch around parsing or handling these errors per-bundle so a single bad asset doesn’t abort the whole script.
  • Several gate detections (e.g., collectLegacyNegativeGatePatches, collectConditionalAuthGatePatches) still rely on sourceFor(...).includes(...); if the bundle format drifts, these string checks may become brittle, so it may be worth tightening them to purely AST-based predicates where possible.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `parseBundle` now throws on parse errors where the previous version silently skipped problematic bundles; if mixed/legacy assets are expected, consider restoring the `try/catch` around parsing or handling these errors per-bundle so a single bad asset doesn’t abort the whole script.
- Several gate detections (e.g., `collectLegacyNegativeGatePatches`, `collectConditionalAuthGatePatches`) still rely on `sourceFor(...).includes(...)`; if the bundle format drifts, these string checks may become brittle, so it may be worth tightening them to purely AST-based predicates where possible.

## Individual Comments

### Comment 1
<location path="scripts/patch-fast-mode.js" line_range="243-253" />
<code_context>
+}
+
+function printSummary({ isCheck, totalCandidates, totalPatched }) {
+  if (isCheck && totalCandidates > 0) {
+    console.log(`  [ok] ${totalCandidates} auth gate(s) would be patched`);
+  } else if (isCheck) {
+    console.log("  [ok] no fast_mode auth gates need patching");
+  } else if (totalPatched > 0) {
     console.log(`  [ok] ${totalPatched} auth gate(s) removed`);
   } else {
     console.log("  [ok] fast_mode auth gates already patched or absent");
</code_context>
<issue_to_address>
**suggestion:** Summary messages still talk about gates being “removed”, which no longer matches the extended behavior.

Given that we now both remove legacy negative gates and broaden ChatGPT-only gates to include API-key auth, the messages `auth gate(s) removed` / `auth gate(s) would be patched` are misleading. Consider using language like `auth gate(s) patched` (or similar) and differentiating between `totalCandidates` and `totalPatched` in the output so the summary more accurately reflects what actually occurred.

```suggestion
function printSummary({ isCheck, totalCandidates, totalPatched }) {
  if (isCheck && totalCandidates > 0) {
    console.log(`  [ok] ${totalCandidates} auth gate(s) would be patched`);
  } else if (isCheck) {
    console.log("  [ok] no fast_mode auth gates need patching");
  } else if (totalPatched > 0) {
    const candidateSuffix =
      totalCandidates && totalCandidates !== totalPatched
        ? ` (out of ${totalCandidates} candidate auth gate(s))`
        : "";
    console.log(`  [ok] ${totalPatched} auth gate(s) patched${candidateSuffix}`);
  } else {
    console.log("  [ok] fast_mode auth gates already patched or absent");
  }
}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread scripts/patch-fast-mode.js
@Clarence12138

Copy link
Copy Markdown
Author

本地测试是 OK 的,刚开始开源贡献,如果有不当的地方哈雷佬随时指正 hhh

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.

Codex 26.602.30954 缺失fast模式

1 participant