@@ -153,6 +153,46 @@ function replaceRequired(file: string, before: string, after: string) {
153153 NodeFS . writeFileSync ( file , source . replace ( before , after ) ) ;
154154}
155155
156+ // A conflicted carried fix can retain the pre-migration Crypto service even
157+ // though the current Effect version exposes Digest and SecureRandom separately.
158+ // Normalize only the exact known shape; fail closed if that shape changes.
159+ export function normalizeAcpRandomCompatibility ( source : string ) : string {
160+ const legacyImport = 'import * as Crypto from "effect/Crypto";' ;
161+ if ( ! source . includes ( legacyImport ) ) {
162+ if ( / \b C r y p t o \b | e f f e c t \/ C r y p t o / . test ( source ) )
163+ throw new Error ( "Unexpected ACP random compatibility shape: unrecognized Crypto reference" ) ;
164+ return source ;
165+ }
166+ if ( ( source . match ( / \b c r y p t o \b / g) ?? [ ] ) . length !== 5 )
167+ throw new Error ( "Unexpected ACP random compatibility shape: extra crypto binding references" ) ;
168+ const replacements : ReadonlyArray < readonly [ string , string , number ] > = [
169+ [
170+ legacyImport ,
171+ 'import * as Digest from "effect/crypto/Digest";\nimport * as SecureRandom from "effect/crypto/SecureRandom";' ,
172+ 1 ,
173+ ] ,
174+ [ "Crypto.Crypto" , "SecureRandom.SecureRandom" , 6 ] ,
175+ [
176+ "const crypto = yield* SecureRandom.SecureRandom;" ,
177+ "const random = yield* SecureRandom.SecureRandom;" ,
178+ 1 ,
179+ ] ,
180+ [ "SecureRandom.SecureRandom, crypto)" , "SecureRandom.SecureRandom, random)" , 4 ] ,
181+ ] ;
182+ let result = source ;
183+ for ( const [ before , after , expected ] of replacements ) {
184+ const count = result . split ( before ) . length - 1 ;
185+ if ( count !== expected )
186+ throw new Error (
187+ `Unexpected ACP random compatibility shape: ${ before } (${ count } , expected ${ expected } )` ,
188+ ) ;
189+ result = result . replaceAll ( before , after ) ;
190+ }
191+ if ( / \b C r y p t o \b | e f f e c t \/ C r y p t o / . test ( result ) )
192+ throw new Error ( "Unexpected ACP random compatibility shape: residual Crypto reference" ) ;
193+ return result ;
194+ }
195+
156196function resolveConflict ( commit : string , allowedFiles : ReadonlyArray < string > ) {
157197 if ( ! process . env . COPILOT_GITHUB_TOKEN )
158198 throw new Error ( "Set the COPILOT_GITHUB_TOKEN Actions secret to resolve conflicts." ) ;
@@ -329,6 +369,14 @@ function prepare() {
329369 else if ( fix . label )
330370 applied . push ( `${ fix . label } : https://github.com/${ fork } /commit/${ fix . commit } ` ) ;
331371 }
372+ const acpDriver = "packages/provider-acp-registry/src/server/driver.ts" ;
373+ const acpSource = NodeFS . readFileSync ( acpDriver , "utf8" ) ;
374+ const normalizedAcpSource = normalizeAcpRandomCompatibility ( acpSource ) ;
375+ if ( normalizedAcpSource !== acpSource ) {
376+ NodeFS . writeFileSync ( acpDriver , normalizedAcpSource ) ;
377+ git ( "add" , acpDriver ) ;
378+ git ( "commit" , "-m" , "fix(acp): retain current random and digest services" ) ;
379+ }
332380 // The CLI release index and downloads must point at the same distribution.
333381 replaceRequired (
334382 "packages/shared/src/cliRelease.ts" ,
0 commit comments