11import type { PlatformError } from "@effect/platform/Error"
22import { Effect } from "effect"
3- import type { AuthGeminiLoginCommand , AuthGeminiLogoutCommand , AuthGeminiStatusCommand } from "../core/domain.js"
3+ import type { AuthGeminiLoginCommand } from "../core/domain.js"
44import type { AuthError , CommandFailedError } from "../shell/errors.js"
55import {
6+ defaultGeminiSettings ,
67 geminiApiKeyPath ,
78 geminiContainerHomeDir ,
89 geminiCredentialsPath ,
9- geminiEnvFilePath ,
1010 geminiImageName ,
1111 type GeminiRuntime ,
1212 prepareGeminiCredentialsDir ,
13- resolveGeminiAuthMethod ,
1413 withGeminiAuth ,
1514 writeInitialSettings
1615} from "./auth-gemini-helpers.js"
@@ -45,66 +44,7 @@ export const authGeminiLogin = (
4544 yield * _ (
4645 fs . writeFileString (
4746 settingsPath ,
48- JSON . stringify (
49- {
50- model : {
51- name : "gemini-3.1-pro-preview-yolo" ,
52- compressionThreshold : 0.9 ,
53- disableLoopDetection : true
54- } ,
55- modelConfigs : {
56- customAliases : {
57- "yolo-ultra" : {
58- "modelConfig" : {
59- "model" : "gemini-3.1-pro-preview-yolo" ,
60- "generateContentConfig" : {
61- "tools" : [
62- {
63- "googleSearch" : { }
64- } ,
65- {
66- "urlContext" : { }
67- }
68- ]
69- }
70- }
71- }
72- }
73- } ,
74- general : {
75- defaultApprovalMode : "auto_edit"
76- } ,
77- tools : {
78- allowed : [
79- "run_shell_command" ,
80- "write_file" ,
81- "googleSearch" ,
82- "urlContext"
83- ]
84- } ,
85- sandbox : {
86- enabled : false
87- } ,
88- security : {
89- folderTrust : {
90- enabled : false
91- } ,
92- auth : {
93- selectedType : "oauth-personal"
94- } ,
95- disableYoloMode : false
96- } ,
97- mcpServers : {
98- playwright : {
99- command : "docker-git-playwright-mcp" ,
100- args : [ ] ,
101- trust : true
102- }
103- }
104- } ,
105- null ,
106- 2
107- ) + "\n"
47+ JSON . stringify ( defaultGeminiSettings , null , 2 ) + "\n"
10848 )
10949 )
11050 } ) ) . pipe (
@@ -165,66 +105,7 @@ export const authGeminiLoginOauth = (
165105 yield * _ (
166106 fs . writeFileString (
167107 settingsPath ,
168- JSON . stringify (
169- {
170- model : {
171- name : "gemini-3.1-pro-preview-yolo" ,
172- compressionThreshold : 0.9 ,
173- disableLoopDetection : true
174- } ,
175- modelConfigs : {
176- customAliases : {
177- "yolo-ultra" : {
178- "modelConfig" : {
179- "model" : "gemini-3.1-pro-preview-yolo" ,
180- "generateContentConfig" : {
181- "tools" : [
182- {
183- "googleSearch" : { }
184- } ,
185- {
186- "urlContext" : { }
187- }
188- ]
189- }
190- }
191- }
192- }
193- } ,
194- general : {
195- defaultApprovalMode : "auto_edit"
196- } ,
197- tools : {
198- allowed : [
199- "run_shell_command" ,
200- "write_file" ,
201- "googleSearch" ,
202- "urlContext"
203- ]
204- } ,
205- sandbox : {
206- enabled : false
207- } ,
208- security : {
209- folderTrust : {
210- enabled : false
211- } ,
212- auth : {
213- selectedType : "oauth-personal"
214- } ,
215- disableYoloMode : false
216- } ,
217- mcpServers : {
218- playwright : {
219- command : "docker-git-playwright-mcp" ,
220- args : [ ] ,
221- trust : true
222- }
223- }
224- } ,
225- null ,
226- 2
227- ) + "\n"
108+ JSON . stringify ( defaultGeminiSettings , null , 2 ) + "\n"
228109 )
229110 )
230111 } ) ,
@@ -234,53 +115,5 @@ export const authGeminiLoginOauth = (
234115 )
235116}
236117
237- // CHANGE: show Gemini CLI auth status for a given label
238- // WHY: allow verifying API key/OAuth presence without exposing credentials
239- // QUOTE(ТЗ): "Добавь поддержку gemini CLI"
240- // REF: issue-146
241- // SOURCE: https://geminicli.com/docs/get-started/authentication/
242- // FORMAT THEOREM: forall cmd: authGeminiStatus(cmd) -> connected(cmd, method) | disconnected(cmd)
243- // PURITY: SHELL
244- // EFFECT: Effect<void, PlatformError | CommandFailedError, GeminiRuntime>
245- // INVARIANT: never logs API keys or OAuth tokens
246- // COMPLEXITY: O(1)
247- export const authGeminiStatus = (
248- command : AuthGeminiStatusCommand
249- ) : Effect . Effect < void , PlatformError | CommandFailedError , GeminiRuntime > =>
250- withGeminiAuth ( command , ( { accountLabel, accountPath, fs } ) =>
251- Effect . gen ( function * ( _ ) {
252- const authMethod = yield * _ ( resolveGeminiAuthMethod ( fs , accountPath ) )
253- if ( authMethod === "none" ) {
254- yield * _ ( Effect . log ( `Gemini not connected (${ accountLabel } ).` ) )
255- return
256- }
257- yield * _ ( Effect . log ( `Gemini connected (${ accountLabel } , ${ authMethod } ).` ) )
258- } ) )
259-
260- // CHANGE: logout Gemini CLI by clearing API key and OAuth credentials for a label
261- // WHY: allow revoking Gemini CLI access deterministically
262- // QUOTE(ТЗ): "Добавь поддержку gemini CLI"
263- // REF: issue-146
264- // SOURCE: https://geminicli.com/docs/get-started/authentication/
265- // FORMAT THEOREM: forall cmd: authGeminiLogout(cmd) -> credentials_cleared(cmd)
266- // PURITY: SHELL
267- // EFFECT: Effect<void, PlatformError | CommandFailedError, GeminiRuntime>
268- // INVARIANT: all credential files (API key and OAuth) are removed from account directory
269- // COMPLEXITY: O(1)
270- export const authGeminiLogout = (
271- command : AuthGeminiLogoutCommand
272- ) : Effect . Effect < void , PlatformError | CommandFailedError , GeminiRuntime > =>
273- Effect . gen ( function * ( _ ) {
274- const accountLabel = normalizeAccountLabel ( command . label , "default" )
275- yield * _ (
276- withGeminiAuth ( command , ( { accountPath, fs } ) =>
277- Effect . gen ( function * ( _ ) {
278- // Clear API key
279- yield * _ ( fs . remove ( geminiApiKeyPath ( accountPath ) , { force : true } ) )
280- yield * _ ( fs . remove ( geminiEnvFilePath ( accountPath ) , { force : true } ) )
281- // Clear OAuth credentials (entire .gemini directory)
282- yield * _ ( fs . remove ( geminiCredentialsPath ( accountPath ) , { recursive : true , force : true } ) )
283- } ) )
284- )
285- yield * _ ( autoSyncState ( `chore(state): auth gemini logout ${ accountLabel } ` ) )
286- } ) . pipe ( Effect . asVoid )
118+ export { authGeminiLogout } from "./auth-gemini-logout.js"
119+ export { authGeminiStatus } from "./auth-gemini-status.js"
0 commit comments