The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as HttpClient from "effect/http/HttpClient"; |
| 4 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 5 | |
| 6 | import { |
| 7 | homebrewOwnershipFromCommandPath, |
| 8 | isNixStoreCommandPath, |
| 9 | makeManualOnlyProviderMaintenanceCapabilities, |
| 10 | makeProviderMaintenanceCapabilities, |
| 11 | resolveHomebrewProviderMaintenance, |
| 12 | resolveMacPortsOwner, |
| 13 | resolveMiseProviderMaintenance, |
| 14 | type ProviderMaintenanceCapabilitiesResolver, |
| 15 | } from "@t3tools/provider-core/server/maintenanceResolver"; |
| 16 | import { FX_DRIVER_KIND } from "./acpSupport.ts"; |
| 17 | |
| 18 | /** The stable release `fx upgrade` and fx's setup script install. */ |
| 19 | const FX_LATEST_RELEASE_URL = "https://releases.fx.sh/latest.txt"; |
| 20 | |
| 21 | export const fetchLatestFxVersion = Effect.fn("fetchLatestFxVersion")(function* () { |
| 22 | const client = yield* HttpClient.HttpClient; |
| 23 | return yield* client.execute(HttpClientRequest.get(FX_LATEST_RELEASE_URL)).pipe( |
| 24 | Effect.flatMap((response) => |
| 25 | response.status >= 200 && response.status < 300 ? response.text : Effect.succeed(""), |
| 26 | ), |
| 27 | Effect.map((body) => body.trim().match(/^v?(\d+\.\d+\.\d+)$/)?.[1] ?? null), |
| 28 | Effect.timeout(4_000), |
| 29 | Effect.orElseSucceed(() => null), |
| 30 | ); |
| 31 | }); |
| 32 | |
| 33 | // fx after 0.0.13 needs Darwin 24, but its updater does not check the host version. |
| 34 | export const makeFxMaintenance = ( |
| 35 | lookupLatestVersion: Effect.Effect<string | null>, |
| 36 | ): ProviderMaintenanceCapabilitiesResolver => ({ |
| 37 | resolve: Effect.fn("FxMaintenance.resolve")(function* (context) { |
| 38 | const input = { provider: FX_DRIVER_KIND, packageName: null }; |
| 39 | const manualOnly = makeManualOnlyProviderMaintenanceCapabilities(input); |
| 40 | if ( |
| 41 | context === null || |
| 42 | (context.platform === "darwin" && Number.parseInt(yield* HostProcess.KernelRelease, 10) < 24) |
| 43 | ) { |
| 44 | return manualOnly; |
| 45 | } |
| 46 | // fx has no mise registry tool, so a mise-owned install stays manual-only. |
| 47 | if (yield* resolveMiseProviderMaintenance(input, undefined, context)) { |
| 48 | return makeManualOnlyProviderMaintenanceCapabilities({ |
| 49 | ...input, |
| 50 | installPath: context.realCommandPath, |
| 51 | lookupLatestVersion, |
| 52 | }); |
| 53 | } |
| 54 | if ([context.resolvedCommandPath, context.realCommandPath].some(isNixStoreCommandPath)) { |
| 55 | return makeManualOnlyProviderMaintenanceCapabilities({ |
| 56 | ...input, |
| 57 | installPath: context.realCommandPath, |
| 58 | }); |
| 59 | } |
| 60 | const macPortsName = yield* resolveMacPortsOwner(context); |
| 61 | if (macPortsName !== null) { |
| 62 | return makeManualOnlyProviderMaintenanceCapabilities({ |
| 63 | ...input, |
| 64 | installPath: context.realCommandPath, |
| 65 | ...(macPortsName ? { manualCommand: `sudo port upgrade ${macPortsName}` } : {}), |
| 66 | }); |
| 67 | } |
| 68 | const homebrew = homebrewOwnershipFromCommandPath(context.realCommandPath); |
| 69 | if (homebrew) { |
| 70 | if (homebrew.kind !== "formula" || homebrew.name !== "fx-agent") return manualOnly; |
| 71 | return (yield* resolveHomebrewProviderMaintenance(input, homebrew, context)) ?? manualOnly; |
| 72 | } |
| 73 | return makeProviderMaintenanceCapabilities({ |
| 74 | ...input, |
| 75 | updateExecutable: context.resolvedCommandPath, |
| 76 | updateArgs: ["upgrade"], |
| 77 | updateLockKey: `fx:${context.realCommandPath}`, |
| 78 | platform: context.platform, |
| 79 | env: context.env, |
| 80 | lookupLatestVersion, |
| 81 | }); |
| 82 | }), |
| 83 | }); |