@@ -2,7 +2,7 @@ import * as FileSystem from "@effect/platform/FileSystem"
22import type * as CommandExecutor from "@effect/platform/CommandExecutor"
33import type { PlatformError } from "@effect/platform/Error"
44import * as Path from "@effect/platform/Path"
5- import { authClaudeLogout , authGeminiLogin , authGeminiLogout } from "@effect-template/lib/usecases/auth"
5+ import { authClaudeLogout , authGeminiLogin , authGeminiLogout , authGrokLogin , authGrokLogout } from "@effect-template/lib/usecases/auth"
66import { ensureEnvFile , parseEnvEntries , readEnvText , upsertEnvKey } from "@effect-template/lib/usecases/env-file"
77import { renderError , type AppError } from "@effect-template/lib/usecases/errors"
88import { defaultProjectsRoot } from "@effect-template/lib/usecases/menu-helpers"
@@ -16,6 +16,7 @@ type MenuAuthRuntime = FileSystem.FileSystem | Path.Path | CommandExecutor.Comma
1616
1717const claudeAuthRoot = `${ defaultProjectsRoot ( process . cwd ( ) ) } /.orch/auth/claude`
1818const geminiAuthRoot = `${ defaultProjectsRoot ( process . cwd ( ) ) } /.orch/auth/gemini`
19+ const grokAuthRoot = `${ defaultProjectsRoot ( process . cwd ( ) ) } /.orch/auth/grok`
1920const globalEnvPath = `${ defaultProjectsRoot ( process . cwd ( ) ) } /.orch/env/global.env`
2021
2122const normalizeLabel = ( value : string ) : string => {
@@ -102,18 +103,21 @@ export const readAuthMenuSnapshot = (): Effect.Effect<AuthSnapshot, PlatformErro
102103 Effect . flatMap ( ( { envText, fs, path } ) =>
103104 Effect . all ( {
104105 claudeAuthEntries : countAuthAccountDirectories ( fs , path , claudeAuthRoot ) ,
105- geminiAuthEntries : countAuthAccountDirectories ( fs , path , geminiAuthRoot )
106+ geminiAuthEntries : countAuthAccountDirectories ( fs , path , geminiAuthRoot ) ,
107+ grokAuthEntries : countAuthAccountDirectories ( fs , path , grokAuthRoot )
106108 } ) . pipe (
107- Effect . map ( ( { claudeAuthEntries, geminiAuthEntries } ) => ( {
109+ Effect . map ( ( { claudeAuthEntries, geminiAuthEntries, grokAuthEntries } ) => ( {
108110 globalEnvPath,
109111 claudeAuthPath : claudeAuthRoot ,
110112 geminiAuthPath : geminiAuthRoot ,
113+ grokAuthPath : grokAuthRoot ,
111114 totalEntries : parseEnvEntries ( envText ) . filter ( ( entry ) => entry . value . trim ( ) . length > 0 ) . length ,
112115 githubTokenEntries : countKeyEntries ( envText , "GITHUB_TOKEN" ) ,
113116 gitTokenEntries : countKeyEntries ( envText , "GIT_AUTH_TOKEN" ) ,
114117 gitUserEntries : countKeyEntries ( envText , "GIT_AUTH_USER" ) ,
115118 claudeAuthEntries,
116- geminiAuthEntries
119+ geminiAuthEntries,
120+ grokAuthEntries
117121 } ) )
118122 )
119123 )
@@ -135,7 +139,11 @@ const syncMessage = (request: AuthMenuRequest): string =>
135139 ? `chore(state): auth claude logout ${ canonicalLabel ( request . label ) } `
136140 : request . flow === "GeminiApiKey"
137141 ? `chore(state): auth gemini ${ canonicalLabel ( request . label ) } `
138- : `chore(state): auth gemini logout ${ canonicalLabel ( request . label ) } `
142+ : request . flow === "GeminiLogout"
143+ ? `chore(state): auth gemini logout ${ canonicalLabel ( request . label ) } `
144+ : request . flow === "GrokApiKey"
145+ ? `chore(state): auth grok ${ canonicalLabel ( request . label ) } `
146+ : `chore(state): auth grok logout ${ canonicalLabel ( request . label ) } `
139147
140148const writeEnvBackedAuthFlow = (
141149 request : AuthMenuRequest
@@ -213,15 +221,45 @@ export const runAuthMenuFlow = (
213221 error instanceof ApiBadRequestError ? error : new ApiBadRequestError ( { message : String ( error ) } )
214222 )
215223 )
216- : pipe (
217- authGeminiLogout ( {
218- _tag : "AuthGeminiLogout" ,
219- label : request . label ?? null ,
220- geminiAuthPath : geminiAuthRoot
221- } ) ,
222- Effect . mapError ( mapMenuAuthError ) ,
223- Effect . zipRight ( readAuthMenuSnapshot ( ) ) ,
224- Effect . mapError ( ( error ) =>
225- error instanceof ApiBadRequestError ? error : new ApiBadRequestError ( { message : String ( error ) } )
224+ : request . flow === "GeminiLogout"
225+ ? pipe (
226+ authGeminiLogout ( {
227+ _tag : "AuthGeminiLogout" ,
228+ label : request . label ?? null ,
229+ geminiAuthPath : geminiAuthRoot
230+ } ) ,
231+ Effect . mapError ( mapMenuAuthError ) ,
232+ Effect . zipRight ( readAuthMenuSnapshot ( ) ) ,
233+ Effect . mapError ( ( error ) =>
234+ error instanceof ApiBadRequestError ? error : new ApiBadRequestError ( { message : String ( error ) } )
235+ )
226236 )
227- )
237+ : request . flow === "GrokApiKey"
238+ ? pipe (
239+ authGrokLogin (
240+ {
241+ _tag : "AuthGrokLogin" ,
242+ label : request . label ?? null ,
243+ grokAuthPath : grokAuthRoot ,
244+ isWeb : true
245+ } ,
246+ request . apiKey ?? ""
247+ ) ,
248+ Effect . mapError ( mapMenuAuthError ) ,
249+ Effect . zipRight ( readAuthMenuSnapshot ( ) ) ,
250+ Effect . mapError ( ( error ) =>
251+ error instanceof ApiBadRequestError ? error : new ApiBadRequestError ( { message : String ( error ) } )
252+ )
253+ )
254+ : pipe (
255+ authGrokLogout ( {
256+ _tag : "AuthGrokLogout" ,
257+ label : request . label ?? null ,
258+ grokAuthPath : grokAuthRoot
259+ } ) ,
260+ Effect . mapError ( mapMenuAuthError ) ,
261+ Effect . zipRight ( readAuthMenuSnapshot ( ) ) ,
262+ Effect . mapError ( ( error ) =>
263+ error instanceof ApiBadRequestError ? error : new ApiBadRequestError ( { message : String ( error ) } )
264+ )
265+ )
0 commit comments