Skip to content

Commit acebd29

Browse files
committed
fix(gemini): improve settings sync and fix auth detection
1 parent 8b8c527 commit acebd29

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ const nextSettings = {
118118
approvalPolicy: "never"
119119
}
120120
121+
// Auto-detect auth method if not set
122+
if (!nextSettings.security.auth || !nextSettings.security.auth.selectedType) {
123+
if (fs.existsSync(path.join(path.dirname(settingsPath), "oauth_creds.json"))) {
124+
nextSettings.security.auth = { ...(nextSettings.security.auth || {}), selectedType: "oauth-personal" }
125+
} else if (fs.existsSync(path.join(path.dirname(settingsPath), "..", ".api-key"))) {
126+
nextSettings.security.auth = { ...(nextSettings.security.auth || {}), selectedType: "api-key" }
127+
}
128+
}
129+
121130
if (JSON.stringify(settings) !== JSON.stringify(nextSettings)) {
122131
fs.mkdirSync(path.dirname(settingsPath), { recursive: true })
123132
fs.writeFileSync(settingsPath, JSON.stringify(nextSettings, null, 2) + "\n")

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export const authGeminiLoginOauth = (
317317
)
318318
)
319319

320-
// Pre-trust directories just in case the setting is ignored
320+
// Pre-trust the container's home directory to skip interactive prompt
321321
const trustedFoldersPath = `${credentialsDir}/trustedFolders.json`
322322
yield* _(
323323
fs.writeFileString(
@@ -329,18 +329,6 @@ export const authGeminiLoginOauth = (
329329
)
330330
)
331331

332-
// Pre-create projects.json to avoid ENOENT during rename within the container
333-
const projectsPath = `${credentialsDir}/projects.json`
334-
yield* _(
335-
fs.writeFileString(
336-
projectsPath,
337-
JSON.stringify({
338-
projects: {},
339-
byPath: {}
340-
})
341-
)
342-
)
343-
344332
yield* _(
345333
runGeminiOauthLoginWithPrompt(cwd, accountPath, {
346334
image: geminiImageName,

0 commit comments

Comments
 (0)