Skip to content

Commit 09c4b56

Browse files
committed
fix(gemini): generate settings.json on host to ensure correct auth type
1 parent 04b812b commit 09c4b56

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

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

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,48 +92,18 @@ GEMINI_CONFIG_SETTINGS_FILE="$GEMINI_SETTINGS_DIR/settings.json"
9292
mkdir -p "$GEMINI_SETTINGS_DIR" || true
9393
9494
# Disable folder trust prompt and enable auto-approval in settings.json
95-
# Detect auth method using Bash (more reliable in entrypoint)
96-
GEMINI_DETECTED_AUTH=""
97-
if [[ -f "$GEMINI_CONFIG_DIR/.gemini/oauth_creds.json" ]]; then
98-
GEMINI_DETECTED_AUTH="oauth-personal"
99-
elif [[ -f "$GEMINI_CONFIG_DIR/.api-key" ]]; then
100-
GEMINI_DETECTED_AUTH="api-key"
101-
fi
102-
103-
GEMINI_SYNC_SETTINGS_SCRIPT=$(cat <<'NODE'
104-
const fs = require("node:fs")
105-
const path = require("node:path")
106-
const settingsPath = process.argv[2]
107-
const detectedAuth = process.argv[3]
108-
if (!settingsPath) process.exit(1)
109-
110-
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v)
111-
112-
let settings = {}
113-
try {
114-
settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"))
115-
if (!isRecord(settings)) settings = {}
116-
} catch {}
117-
118-
const nextSettings = JSON.parse(JSON.stringify(settings))
119-
120-
if (!isRecord(nextSettings.security)) nextSettings.security = {}
121-
if (!isRecord(nextSettings.security.folderTrust)) nextSettings.security.folderTrust = {}
122-
123-
nextSettings.security.folderTrust.enabled = false
124-
nextSettings.approvalPolicy = "never"
125-
126-
if (detectedAuth) {
127-
nextSettings.security.auth = { ...(isRecord(nextSettings.security.auth) ? nextSettings.security.auth : {}), selectedType: detectedAuth }
128-
}
129-
130-
if (JSON.stringify(settings) !== JSON.stringify(nextSettings)) {
131-
fs.mkdirSync(path.dirname(settingsPath), { recursive: true })
132-
fs.writeFileSync(settingsPath, JSON.stringify(nextSettings, null, 2) + "\n")
95+
if [[ ! -f "$GEMINI_CONFIG_SETTINGS_FILE" ]]; then
96+
cat <<'EOF' > "$GEMINI_CONFIG_SETTINGS_FILE"
97+
{
98+
"security": {
99+
"folderTrust": {
100+
"enabled": false
101+
}
102+
},
103+
"approvalPolicy": "never"
133104
}
134-
NODE
135-
)
136-
node -e "$GEMINI_SYNC_SETTINGS_SCRIPT" "$GEMINI_CONFIG_SETTINGS_FILE" "$GEMINI_DETECTED_AUTH" || true
105+
EOF
106+
fi
137107
138108
# Pre-trust important directories in trustedFolders.json
139109
# Use flat mapping as required by recent Gemini CLI versions

packages/lib/src/usecases/auth-gemini.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,24 @@ export const authGeminiLoginOauth = (
335335
containerPath: geminiContainerHomeDir
336336
})
337337
)
338+
339+
// Generate complete settings.json on the host so containers don't have to guess
340+
yield* _(
341+
fs.writeFileString(
342+
settingsPath,
343+
JSON.stringify({
344+
security: {
345+
folderTrust: {
346+
enabled: false
347+
},
348+
auth: {
349+
selectedType: "oauth-personal"
350+
}
351+
},
352+
approvalPolicy: "never"
353+
}, null, 2) + "\n"
354+
)
355+
)
338356
}),
339357
{ buildImage: true }
340358
).pipe(

0 commit comments

Comments
 (0)