@@ -227,109 +227,104 @@ export const makeAcpRegistryAuth = Effect.fn("makeAcpRegistryAuth")(function* (o
227227 return yield * failure ( "start" , "The provider login command did not finish successfully." ) ;
228228 } ) ;
229229
230- const authenticate = ( methodId : string , context : ProviderAuthFlow . ProviderAuthFlowContext ) =>
231- Effect . gen ( function * ( ) {
232- if ( ! options . settings . enabled )
233- return yield * failure ( "start" , "Enable this provider before signing in." ) ;
234- const login = Effect . scoped (
235- Effect . gen ( function * ( ) {
236- const resolved = yield * resolve ;
237- const runtimeScope = yield * Scope . make ( ) ;
238- yield * Effect . addFinalizer ( ( ) => Scope . close ( runtimeScope , Exit . void ) ) ;
239- const runtime = yield * makeRuntime ( resolved . spawn ) . pipe (
240- Effect . provideService ( Scope . Scope , runtimeScope ) ,
241- ) ;
242- yield * runtime . handleElicitation ( ( request ) =>
243- Effect . gen ( function * ( ) {
244- if (
245- request . mode !== "url" ||
246- ! ( "url" in request ) ||
247- ! ( "elicitationId" in request ) ||
248- typeof request . url !== "string" ||
249- typeof request . elicitationId !== "string"
250- )
251- return { action : "decline" } as const ;
252- const url = normalizeAcpRegistryWebUrl ( request . url ) ;
253- const id = request . elicitationId . trim ( ) ;
254- if ( ! url || ! id || id . length > 128 ) return { action : "decline" } as const ;
255- const consent = yield * Deferred . make < boolean > ( ) ;
256- yield * context . setInteraction (
257- { type : "browser" , id, url, requiresConsent : true } ,
258- ( response ) =>
259- response . type === "browser"
260- ? Deferred . succeed ( consent , response . action === "accept" ) . pipe ( Effect . asVoid )
261- : Effect . void ,
262- ) ;
263- return ( yield * Deferred . await ( consent ) )
264- ? ( { action : "accept" } as const )
265- : ( { action : "decline" } as const ) ;
266- } ) ,
230+ const authenticate = Effect . fn ( "auth.authenticate" ) ( function * (
231+ methodId : string ,
232+ context : ProviderAuthFlow . ProviderAuthFlowContext ,
233+ ) {
234+ if ( ! options . settings . enabled )
235+ return yield * failure ( "start" , "Enable this provider before signing in." ) ;
236+ const login = Effect . scoped (
237+ Effect . gen ( function * ( ) {
238+ const resolved = yield * resolve ;
239+ const runtimeScope = yield * Scope . make ( ) ;
240+ yield * Effect . addFinalizer ( ( ) => Scope . close ( runtimeScope , Exit . void ) ) ;
241+ const runtime = yield * makeRuntime ( resolved . spawn ) . pipe (
242+ Effect . provideService ( Scope . Scope , runtimeScope ) ,
243+ ) ;
244+ yield * runtime . handleElicitation ( ( request ) =>
245+ Effect . gen ( function * ( ) {
246+ if (
247+ request . mode !== "url" ||
248+ ! ( "url" in request ) ||
249+ ! ( "elicitationId" in request ) ||
250+ typeof request . url !== "string" ||
251+ typeof request . elicitationId !== "string"
252+ )
253+ return { action : "decline" } as const ;
254+ const url = normalizeAcpRegistryWebUrl ( request . url ) ;
255+ const id = request . elicitationId . trim ( ) ;
256+ if ( ! url || ! id || id . length > 128 ) return { action : "decline" } as const ;
257+ const consent = yield * Deferred . make < boolean > ( ) ;
258+ yield * context . setInteraction (
259+ { type : "browser" , id, url, requiresConsent : true } ,
260+ ( response ) =>
261+ response . type === "browser"
262+ ? Deferred . succeed ( consent , response . action === "accept" ) . pipe ( Effect . asVoid )
263+ : Effect . void ,
264+ ) ;
265+ return ( yield * Deferred . await ( consent ) )
266+ ? ( { action : "accept" } as const )
267+ : ( { action : "decline" } as const ) ;
268+ } ) ,
269+ ) ;
270+ const initialized = yield * runtime
271+ . initialize ( )
272+ . pipe (
273+ Effect . mapError ( ( cause ) =>
274+ failure ( "start" , "Could not initialize the selected ACP agent." , cause ) ,
275+ ) ,
267276 ) ;
268- const initialized = yield * runtime
269- . initialize ( )
277+ const method = initialized . authMethods ?. find ( ( method ) => method . id === methodId ) ;
278+ if ( ! method )
279+ return yield * failure ( "start" , "The agent no longer advertises this sign-in method." ) ;
280+ if ( method . type === "terminal" ) {
281+ yield * Scope . close ( runtimeScope , Exit . void ) ;
282+ yield * runTerminal ( resolved , method , context ) . pipe ( Effect . scoped ) ;
283+ // Terminal login is a separate invocation. Reconnect after it exits so
284+ // the ACP process reads the credentials its login command persisted.
285+ const verifiedRuntime = yield * makeRuntime ( resolved . spawn ) ;
286+ yield * context . verifying ;
287+ yield * verifiedRuntime
288+ . start ( )
270289 . pipe (
271290 Effect . mapError ( ( cause ) =>
272- failure ( "start" , "Could not initialize the selected ACP agent." , cause ) ,
291+ failure (
292+ "verify" ,
293+ "The provider could not create a session after terminal sign-in." ,
294+ cause ,
295+ ) ,
273296 ) ,
274297 ) ;
275- const method = initialized . authMethods ?. find ( ( method ) => method . id === methodId ) ;
276- if ( ! method )
277- return yield * failure ( "start" , "The agent no longer advertises this sign-in method." ) ;
278- if ( method . type === "terminal" ) {
279- yield * Scope . close ( runtimeScope , Exit . void ) ;
280- yield * runTerminal ( resolved , method , context ) . pipe ( Effect . scoped ) ;
281- // Terminal login is a separate invocation. Reconnect after it exits so
282- // the ACP process reads the credentials its login command persisted.
283- const verifiedRuntime = yield * makeRuntime ( resolved . spawn ) ;
284- yield * context . verifying ;
285- yield * verifiedRuntime
286- . start ( )
287- . pipe (
288- Effect . mapError ( ( cause ) =>
289- failure (
290- "verify" ,
291- "The provider could not create a session after terminal sign-in." ,
292- cause ,
293- ) ,
294- ) ,
295- ) ;
296- } else {
297- if ( method . type === undefined || method . type === "agent" ) {
298- if ( ! runtime . authenticate )
299- return yield * failure (
300- "start" ,
301- "This runtime does not support explicit ACP sign-in." ,
302- ) ;
303- yield * runtime
304- . authenticate ( methodId )
305- . pipe (
306- Effect . mapError ( ( cause ) =>
307- failure ( "start" , "The ACP agent could not complete sign-in." , cause ) ,
308- ) ,
309- ) ;
310- }
311- // Legacy env_var methods use the secret-backed environment fields in
312- // provider settings. Never send their ID to authenticate.
313- yield * context . verifying ;
298+ } else {
299+ if ( method . type === undefined || method . type === "agent" ) {
300+ if ( ! runtime . authenticate )
301+ return yield * failure ( "start" , "This runtime does not support explicit ACP sign-in." ) ;
314302 yield * runtime
315- . start ( )
303+ . authenticate ( methodId )
316304 . pipe (
317305 Effect . mapError ( ( cause ) =>
318- failure (
319- "verify" ,
320- "The provider could not create a session after sign-in." ,
321- cause ,
322- ) ,
306+ failure ( "start" , "The ACP agent could not complete sign-in." , cause ) ,
323307 ) ,
324308 ) ;
325309 }
326- } ) ,
327- ) ;
328- yield * Option . isSome ( coordinator )
329- ? coordinator . value . withForegroundStartup ( agentKey , login )
330- : login ;
331- yield * options . onChanged ( true ) ;
332- } ) ;
310+ // Legacy env_var methods use the secret-backed environment fields in
311+ // provider settings. Never send their ID to authenticate.
312+ yield * context . verifying ;
313+ yield * runtime
314+ . start ( )
315+ . pipe (
316+ Effect . mapError ( ( cause ) =>
317+ failure ( "verify" , "The provider could not create a session after sign-in." , cause ) ,
318+ ) ,
319+ ) ;
320+ }
321+ } ) ,
322+ ) ;
323+ yield * Option . isSome ( coordinator )
324+ ? coordinator . value . withForegroundStartup ( agentKey , login )
325+ : login ;
326+ yield * options . onChanged ( true ) ;
327+ } ) ;
333328 const logout = Effect . scoped (
334329 Effect . gen ( function * ( ) {
335330 const resolved = yield * resolve ;
0 commit comments