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
16 changes: 16 additions & 0 deletions apps/frontend/src/main/ipc-handlers/github/utils/runner-env.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import { getOAuthModeClearVars } from '../../../agent/env-utils';
import { getAPIProfileEnv } from '../../../services/profile';
import { getProfileEnv } from '../../../rate-limit-detector';
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For better code organization and maintainability, the getProfileEnv function seems misplaced in rate-limit-detector.ts. Its purpose is to retrieve profile-specific environment variables, which is more aligned with profile management than rate limit detection.

Consider moving getProfileEnv to a more logical location, such as ../../../services/profile, where the related getAPIProfileEnv function is already defined. This would improve code structure, make the function easier to find, and avoid creating a dependency on rate-limit-detector for a non-rate-limiting concern.

Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the rate-limit-detector module and getProfileEnv export

# Find the rate-limit-detector file
echo "=== Locating rate-limit-detector module ==="
fd -e ts -e tsx "rate-limit-detector" apps/frontend/src/main

# Navigate from the current file to check the relative path
echo -e "\n=== Checking relative path resolution ==="
# From apps/frontend/src/main/ipc-handlers/github/utils/runner-env.ts
# ../../../rate-limit-detector should resolve to apps/frontend/src/main/rate-limit-detector

# Check for files in the main directory
echo "Files in apps/frontend/src/main directory:"
ls -la apps/frontend/src/main/ | head -20

Repository: AndyMik90/Auto-Claude

Length of output: 1540


🏁 Script executed:

#!/bin/bash
# Check for getProfileEnv export in the module

echo "=== Checking for getProfileEnv exports ==="
rg -n "export.*getProfileEnv" apps/frontend/src/main

echo -e "\n=== Checking rate-limit-detector module content ==="
# Check all files named rate-limit-detector or containing the module
fd "rate-limit-detector" apps/frontend/src/main --type f -x cat -n {}

Repository: AndyMik90/Auto-Claude

Length of output: 37620


🏁 Script executed:

#!/bin/bash
# Examine the full content of the runner-env.ts file to understand context

echo "=== Full content of runner-env.ts ==="
cat -n apps/frontend/src/main/ipc-handlers/github/utils/runner-env.ts

Repository: AndyMik90/Auto-Claude

Length of output: 1591


Import path is correct; consider refactoring module organization.

The import path '../../../rate-limit-detector' resolves correctly. However, the module's scope has expanded beyond rate limiting to include profile environment management. If this module continues to grow, consider extracting profile-related functions into a dedicated module to improve clarity and maintainability.

🤖 Prompt for AI Agents
In @apps/frontend/src/main/ipc-handlers/github/utils/runner-env.ts around line
3, The import getProfileEnv from '../../../rate-limit-detector' indicates the
rate-limit-detector module now contains profile environment logic; extract
profile-related functions (e.g., getProfileEnv) into a dedicated module (suggest
name: profile-env or profile-utils), export them from that new module, update
runner-env.ts to import getProfileEnv from the new module, and update any other
files that currently import profile helpers from rate-limit-detector to the new
path; ensure exports/exports names remain consistent and run tests/typechecks to
confirm no breaking imports.


/**
* Get environment variables for Python runner subprocesses.
*
* Environment variable precedence (lowest to highest):
* 1. apiProfileEnv - Custom Anthropic-compatible API profile (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN)
* 2. oauthModeClearVars - Clears stale ANTHROPIC_* vars when in OAuth mode
* 3. profileEnv - Claude OAuth token from profile manager (CLAUDE_CODE_OAUTH_TOKEN)
* 4. extraEnv - Caller-specific vars (e.g., USE_CLAUDE_MD)
*
* The profileEnv is critical for OAuth authentication (#563) - it retrieves the
* decrypted OAuth token from the profile manager's encrypted storage (macOS Keychain
* via Electron's safeStorage API).
*/
export async function getRunnerEnv(
extraEnv?: Record<string, string>
): Promise<Record<string, string>> {
const apiProfileEnv = await getAPIProfileEnv();
const oauthModeClearVars = getOAuthModeClearVars(apiProfileEnv);
const profileEnv = getProfileEnv();

return {
...apiProfileEnv,
...oauthModeClearVars,
...profileEnv, // OAuth token from profile manager (fixes #563)
...extraEnv,
};
}
Loading