@@ -12,6 +12,7 @@ import {
1212} from "@t3tools/contracts" ;
1313import type { AcpRegistryDistributionPreference } from "../settings.ts" ;
1414import type { AcpRegistrySettings } from "../settings.ts" ;
15+ import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease" ;
1516import * as HostProcess from "@t3tools/shared/HostProcess" ;
1617import {
1718 mergePathEntries ,
@@ -238,6 +239,18 @@ export function resolveAcpRegistryPlatformTarget(
238239 return os && arch ? ( `${ os } -${ arch } ` as AcpRegistryPlatformTarget ) : undefined ;
239240}
240241
242+ function resolveAcpRegistryPlatformTargetCandidates (
243+ platformTarget : AcpRegistryPlatformTarget | undefined ,
244+ ) : ReadonlyArray < AcpRegistryPlatformTarget > {
245+ if ( platformTarget === undefined ) return [ ] ;
246+ // Windows 11 on ARM executes windows-x86_64 binaries under Prism emulation
247+ // when an agent does not publish a native windows-aarch64 binary.
248+ if ( platformTarget === "windows-aarch64" ) {
249+ return [ "windows-aarch64" , "windows-x86_64" ] ;
250+ }
251+ return [ platformTarget ] ;
252+ }
253+
241254interface ExactPackageSpec {
242255 readonly name : string ;
243256 readonly version : string ;
@@ -375,18 +388,22 @@ export const acpRegistryManagedBinaryDirectories = Effect.fn("acpRegistryManaged
375388 ( left , right ) => right . localeCompare ( left , undefined , { numeric : true } ) ,
376389 ) ;
377390 for ( const version of versions ) {
378- const installRoot = path . join ( installsDirectory , agent , version , target ) ;
379- if ( yield * fileSystem . exists ( installRoot ) . pipe ( Effect . orElseSucceed ( ( ) => false ) ) ) {
380- const binaryTarget = cachedAgentByInstall . get ( `${ agent } \0${ version } ` ) ?. distribution
381- . binary ?. [ target ] ;
382- const commandSegments =
383- binaryTarget === undefined ? undefined : normalizeRegistryCommandPath ( binaryTarget . cmd ) ;
384- const directory =
385- commandSegments === undefined
386- ? installRoot
387- : path . join ( installRoot , ...commandSegments . slice ( 0 , - 1 ) ) ;
388- if ( yield * fileSystem . exists ( directory ) . pipe ( Effect . orElseSucceed ( ( ) => false ) ) ) {
389- directories . push ( directory ) ;
391+ for ( const candidateTarget of resolveAcpRegistryPlatformTargetCandidates ( target ) ) {
392+ const installRoot = path . join ( installsDirectory , agent , version , candidateTarget ) ;
393+ if ( yield * fileSystem . exists ( installRoot ) . pipe ( Effect . orElseSucceed ( ( ) => false ) ) ) {
394+ const binaryTarget = cachedAgentByInstall . get ( `${ agent } \0${ version } ` ) ?. distribution
395+ . binary ?. [ candidateTarget ] ;
396+ const commandSegments =
397+ binaryTarget === undefined
398+ ? undefined
399+ : normalizeRegistryCommandPath ( binaryTarget . cmd ) ;
400+ const directory =
401+ commandSegments === undefined
402+ ? installRoot
403+ : path . join ( installRoot , ...commandSegments . slice ( 0 , - 1 ) ) ;
404+ if ( yield * fileSystem . exists ( directory ) . pipe ( Effect . orElseSucceed ( ( ) => false ) ) ) {
405+ directories . push ( directory ) ;
406+ }
390407 }
391408 }
392409 }
@@ -409,7 +426,9 @@ export function resolveAcpRegistryDistribution(input: {
409426 readonly platformTarget : AcpRegistryPlatformTarget | undefined ;
410427} ) : ResolvedAcpRegistryDistribution | undefined {
411428 const { agent, platformTarget } = input ;
412- const binary = platformTarget ? agent . distribution . binary ?. [ platformTarget ] : undefined ;
429+ const binary = resolveAcpRegistryPlatformTargetCandidates ( platformTarget )
430+ . map ( ( candidate ) => agent . distribution . binary ?. [ candidate ] )
431+ . find ( ( entry ) => entry !== undefined ) ;
413432 const candidates : ReadonlyArray < AcpRegistryDistributionKind > =
414433 input . preference === "auto" ? [ "binary" , "npx" , "uvx" ] : [ input . preference ] ;
415434
@@ -1336,11 +1355,16 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
13361355
13371356 const binaryPaths = ( agent : AcpRegistryAgent , target : typeof AcpRegistryBinaryTarget . Type ) => {
13381357 const commandSegments = normalizeRegistryCommandPath ( target . cmd ) ;
1339- if ( platformTarget === undefined || commandSegments === undefined ) return undefined ;
1340- const installRoot = path . join ( agentInstallRoot ( agent ) , platformTarget ) ;
1358+ const matchedPlatformTarget =
1359+ resolveAcpRegistryPlatformTargetCandidates ( platformTarget ) . find (
1360+ ( candidate ) => agent . distribution . binary ?. [ candidate ] === target ,
1361+ ) ?? platformTarget ;
1362+ if ( matchedPlatformTarget === undefined || commandSegments === undefined ) return undefined ;
1363+ const installRoot = path . join ( agentInstallRoot ( agent ) , matchedPlatformTarget ) ;
13411364 return {
13421365 commandSegments,
13431366 installRoot,
1367+ platformTarget : matchedPlatformTarget ,
13441368 executablePath : path . join ( installRoot , ...commandSegments ) ,
13451369 } ;
13461370 } ;
@@ -1487,6 +1511,14 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14871511 yield * fileSystem . makeDirectory ( path . dirname ( targetPath ) , { recursive : true } ) ;
14881512 yield * fileSystem . rename ( archivePath , targetPath ) ;
14891513 } else {
1514+ // The new Windows ARM fallback must extract x64 ZIPs even when Git's GNU tar wins PATH.
1515+ // Keep archive selection for existing native distributions unchanged in this PR.
1516+ const tarCommand =
1517+ platformTarget === "windows-aarch64" &&
1518+ paths . platformTarget === "windows-x86_64" &&
1519+ kind === "zip"
1520+ ? cliArchiveTarCommand ( platform , hostEnvironment )
1521+ : "tar" ;
14901522 const listArgs =
14911523 kind === "tar_gz"
14921524 ? [ "-tzf" , archivePath ]
@@ -1498,7 +1530,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
14981530 const entries =
14991531 listArgs === undefined
15001532 ? yield * runCommand ( "unzip" , [ "-Z1" , archivePath ] )
1501- : yield * runCommand ( "tar" , listArgs ) ;
1533+ : yield * runCommand ( tarCommand , listArgs ) ;
15021534 if ( ! validateArchiveEntries ( entries ) ) {
15031535 return yield * new AcpRegistryError ( {
15041536 reason : "archive_invalid" ,
@@ -1509,7 +1541,7 @@ export const makeAcpRegistryCatalog = Effect.fn("AcpRegistryCatalog.make")(funct
15091541 yield * runCommand ( "unzip" , [ "-q" , archivePath , "-d" , extractionRoot ] ) ;
15101542 } else {
15111543 const extractFlag = kind === "tar_gz" ? "-xzf" : kind === "tar_bz2" ? "-xjf" : "-xf" ;
1512- yield * runCommand ( "tar" , [ extractFlag , archivePath , "-C" , extractionRoot ] ) ;
1544+ yield * runCommand ( tarCommand , [ extractFlag , archivePath , "-C" , extractionRoot ] ) ;
15131545 }
15141546 }
15151547
0 commit comments