Skip to content

Commit 80fae75

Browse files
committed
fix(gemini): fix auth detection and disable update checks
1 parent a35f34a commit 80fae75

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

packages/lib/src/core/templates-entrypoint/gemini.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,35 +106,25 @@ try {
106106
if (!isRecord(settings)) settings = {}
107107
} catch {}
108108
109-
const nextSettings = {
110-
...settings,
111-
security: {
112-
...(isRecord(settings.security) ? settings.security : {}),
113-
folderTrust: {
114-
...(isRecord(settings.security?.folderTrust) ? settings.security.folderTrust : {}),
115-
enabled: false
116-
}
117-
},
118-
approvalPolicy: "never"
119-
}
109+
const nextSettings = JSON.parse(JSON.stringify(settings))
110+
111+
if (!isRecord(nextSettings.security)) nextSettings.security = {}
112+
if (!isRecord(nextSettings.security.folderTrust)) nextSettings.security.folderTrust = {}
113+
114+
nextSettings.security.folderTrust.enabled = false
115+
nextSettings.approvalPolicy = "never"
116+
117+
// Force auth method detection
118+
const settingsDir = path.dirname(settingsPath)
119+
const oauthPath = path.join(settingsDir, "oauth_creds.json")
120+
const apiKeyPath = path.join(settingsDir, "..", ".api-key")
120121
121-
// Auto-detect auth method if not set
122-
const currentAuth = nextSettings.security.auth
123-
if (!isRecord(currentAuth) || !currentAuth.selectedType) {
124-
const settingsDir = path.dirname(settingsPath)
125-
const configDir = process.env.GEMINI_CONFIG_DIR || ""
126-
127-
const hasOauth = fs.existsSync(path.join(settingsDir, "oauth_creds.json")) ||
128-
(configDir && fs.existsSync(path.join(configDir, ".gemini", "oauth_creds.json")))
129-
130-
const hasApiKey = fs.existsSync(path.join(settingsDir, "..", ".api-key")) ||
131-
(configDir && fs.existsSync(path.join(configDir, ".api-key")))
132-
133-
if (hasOauth) {
134-
nextSettings.security.auth = { ...(isRecord(currentAuth) ? currentAuth : {}), selectedType: "oauth-personal" }
135-
} else if (hasApiKey) {
136-
nextSettings.security.auth = { ...(isRecord(currentAuth) ? currentAuth : {}), selectedType: "api-key" }
137-
}
122+
if (fs.existsSync(oauthPath)) {
123+
if (!isRecord(nextSettings.security.auth)) nextSettings.security.auth = {}
124+
nextSettings.security.auth.selectedType = "oauth-personal"
125+
} else if (fs.existsSync(apiKeyPath)) {
126+
if (!isRecord(nextSettings.security.auth)) nextSettings.security.auth = {}
127+
nextSettings.security.auth.selectedType = "api-key"
138128
}
139129
140130
if (JSON.stringify(settings) !== JSON.stringify(nextSettings)) {
@@ -174,6 +164,8 @@ const renderGeminiProfileSetup = (config: TemplateConfig): string =>
174164
String.raw`GEMINI_PROFILE="/etc/profile.d/gemini-config.sh"
175165
printf "export GEMINI_AUTH_LABEL=%q\n" "$GEMINI_AUTH_LABEL" > "$GEMINI_PROFILE"
176166
printf "export GEMINI_HOME=%q\n" "${config.geminiHome}" >> "$GEMINI_PROFILE"
167+
printf "export GEMINI_CLI_DISABLE_UPDATE_CHECK=true\n" >> "$GEMINI_PROFILE"
168+
printf "export GEMINI_CLI_NONINTERACTIVE=true\n" >> "$GEMINI_PROFILE"
177169
cat <<'EOF' >> "$GEMINI_PROFILE"
178170
if [[ -f "$GEMINI_HOME/.api-key" ]]; then
179171
export GEMINI_API_KEY="$(cat "$GEMINI_HOME/.api-key" | tr -d '\r\n')"
@@ -182,7 +174,9 @@ EOF
182174
chmod 0644 "$GEMINI_PROFILE" || true
183175
184176
docker_git_upsert_ssh_env "GEMINI_AUTH_LABEL" "$GEMINI_AUTH_LABEL"
185-
docker_git_upsert_ssh_env "GEMINI_API_KEY" "${"$"}{GEMINI_API_KEY:-}"`
177+
docker_git_upsert_ssh_env "GEMINI_API_KEY" "${GEMINI_API_KEY:-}"
178+
docker_git_upsert_ssh_env "GEMINI_CLI_DISABLE_UPDATE_CHECK" "true"
179+
docker_git_upsert_ssh_env "GEMINI_CLI_NONINTERACTIVE" "true"`
186180

187181
const entrypointGeminiNoticeTemplate = String.raw`# Ensure global GEMINI.md exists for container context
188182
GEMINI_MD_PATH="__GEMINI_HOME__/GEMINI.md"

packages/lib/src/core/templates/dockerfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RUN set -eu; \
6161
RUN oh-my-opencode --version
6262
RUN npm install -g @anthropic-ai/claude-code@latest
6363
RUN claude --version
64-
RUN npm install -g @google/gemini-cli@latest
64+
RUN npm install -g @google/gemini-cli@latest --force
6565
RUN gemini --version`
6666

6767
const renderDockerfileOpenCode = (): string =>

0 commit comments

Comments
 (0)