@devries-cameron20 / t3code Mirror · read-only / commits / 3f7c3aa57c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 01:45 UTC

fix(server): pnpm provider updates only offer versions pnpm will install (#19580)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Tristan Knight committed Oct 19, 2026 at 19:54 UTC 3f7c3aa57c504ba15b8cf89f0d69964477dc6dc2
4 files changed +168 -5
apps/server/src/ws.ts
+6 -2
@@ -168,6 +168,7 @@ import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRe
168 import * as AcpRegistryRuntimeCoordinator from "@t3tools/provider-acp-registry/server/AcpRegistryRuntimeCoordinator";
169 import * as ModelManifest from "./provider/ModelManifest.ts";
170 import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
171 +import { latestProviderVersionCacheKeys } from "@t3tools/provider-core/server/maintenanceResolver";
172 import * as ProviderMaintenanceRunner from "./provider/providerMaintenanceRunner.ts";
173 import * as ProviderAuthService from "./provider/ProviderAuthService.ts";
174 import { makeProviderInstallation } from "./provider/providerInstallation.ts";
@@ -2177,8 +2178,11 @@ const layerWsRpc = (
2178 const maintenance = yield* instance.snapshot.resolveMaintenance({
2179 fresh: true,
2180 });
2180 - if (maintenance.packageName)
2181 - yield* providerLatestVersions.invalidate(maintenance.packageName);
2181 + yield* Effect.forEach(
2182 + latestProviderVersionCacheKeys(maintenance),
2183 + providerLatestVersions.invalidate,
2184 + { discard: true },
2185 + );
2186 }),
2187 { concurrency: "unbounded", discard: true },
2188 );
packages/provider-core/src/server/maintenance.ts
+5
@@ -1,4 +1,5 @@
1 import type { ProviderDriverKind } from "@t3tools/contracts";
2 +import type * as Effect from "effect/Effect";
3
4 export interface ProviderMaintenanceCapabilities {
5 readonly provider: ProviderDriverKind;
@@ -10,6 +11,10 @@ export interface ProviderMaintenanceCapabilities {
11 * installer was asked and did not know.
12 */
13 readonly latestVersion?: string | null;
14 + /**
15 + * Deferred until update checks are enabled; `null` falls back to npm.
16 + */
17 + readonly lookupLatestVersion?: Effect.Effect<string | null>;
18 readonly compareVersions?: (current: string, latest: string) => number;
19 /**
20 * The executable T3 Code runs, symlinks followed, when no update command is
packages/provider-core/src/server/maintenanceResolver.test.ts
+78 -2
@@ -99,7 +99,10 @@ const noSpawn = ChildProcessSpawner.make(() =>
99 Effect.die("maintenance resolution should not spawn a process here"),
100 );
101
102 -function stdoutSpawner(onSpawn: (command: string, args: ReadonlyArray<string>) => string) {
102 +function stdoutSpawner(
103 + onSpawn: (command: string, args: ReadonlyArray<string>) => string,
104 + exitCodeOf: (args: ReadonlyArray<string>) => number = () => 0,
105 +) {
106 return ChildProcessSpawner.make((command) => {
107 const { command: executable, args } = command as unknown as {
108 readonly command: string;
@@ -108,7 +111,7 @@ function stdoutSpawner(onSpawn: (command: string, args: ReadonlyArray<string>) =
111 return Effect.succeed(
112 ChildProcessSpawner.makeHandle({
113 pid: ChildProcessSpawner.ProcessId(1),
111 - exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
114 + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(exitCodeOf(args))),
115 isRunning: Effect.succeed(false),
116 kill: () => Effect.void,
117 unref: Effect.succeed(Effect.void),
@@ -624,6 +627,79 @@ it.layer(NodeServices.layer)("providerMaintenance", (it) => {
627 }),
628 );
629
630 + it.effect.each([
631 + {
632 + case: "the eligible release",
633 + outdated: { "@example/package-tool": { current: "1.0.0", latest: "1.1.0" } },
634 + exitCode: 1,
635 + expected: "1.1.0",
636 + },
637 + { case: "no update during cooldown", outdated: {}, exitCode: 0, expected: "1.0.0" },
638 + {
639 + case: "the npm fallback when the pnpm probe fails",
640 + outdated: { "@example/package-tool": { current: "1.0.0", latest: "1.1.0" } },
641 + exitCode: 2,
642 + expected: "9.9.9",
643 + },
644 + ])(
645 + "advertises $case for pnpm-global installs",
646 + (fixture) =>
647 + Effect.gen(function* () {
648 + const tempDir = yield* makeTempDir("t3-pnpm-latest");
649 + const pnpmBinDir = NodePath.join(tempDir, "pnpm-bin");
650 + writeExecutable(NodePath.join(pnpmBinDir, "pnpm"));
651 + const link = linkIntoPackage(tempDir, "package-tool", [
652 + ".local",
653 + "share",
654 + "pnpm",
655 + "global",
656 + "5",
657 + "node_modules",
658 + "@example",
659 + "package-tool",
660 + ]);
661 +
662 + const capabilities = yield* resolveProviderMaintenanceCapabilitiesEffect(
663 + packageToolUpdate,
664 + { binaryPath: link, env: { PATH: "" } },
665 + ).pipe(
666 + Effect.provideService(HostProcess.Environment, { PATH: pnpmBinDir }),
667 + Effect.provideService(
668 + ChildProcessSpawner.ChildProcessSpawner,
669 + stdoutSpawner(
670 + (_command, args) =>
671 + args[0] === "outdated"
672 + ? JSON.stringify(fixture.outdated)
673 + : JSON.stringify([
674 + { dependencies: { "@example/package-tool": { version: "1.0.0" } } },
675 + ]),
676 + (args) => (args[0] === "outdated" ? fixture.exitCode : 0),
677 + ),
678 + ),
679 + );
680 +
681 + const provider = yield* enrichProviderSnapshotWithVersionAdvisory(
682 + installedPackageToolProvider,
683 + capabilities,
684 + ).pipe(
685 + Effect.provideServiceEffect(
686 + ProviderLatestVersions.ProviderLatestVersions,
687 + ProviderLatestVersions.make([["@example/package-tool", "9.9.9"]]),
688 + ),
689 + Effect.provideService(
690 + HttpClient.HttpClient,
691 + HttpClient.make(() => Effect.die("the npm version is already cached")),
692 + ),
693 + );
694 + expect(provider.versionAdvisory).toMatchObject({
695 + status: fixture.expected === "1.0.0" ? "current" : "behind_latest",
696 + currentVersion: "1.0.0",
697 + latestVersion: fixture.expected,
698 + });
699 + }),
700 + { skip: !symlinksSupported || windowsHost },
701 + );
702 +
703 it.effect.skipIf(windowsHost)(
704 "switches to bun updates when the resolved binary lives in bun's global bin",
705 () =>
packages/provider-core/src/server/maintenanceResolver.ts
+79 -1
@@ -121,6 +121,7 @@ export function makeProviderMaintenanceCapabilities(input: {
121 readonly platform?: NodeJS.Platform;
122 readonly env?: NodeJS.ProcessEnv;
123 readonly latestVersion?: string | null;
124 + readonly lookupLatestVersion?: Effect.Effect<string | null>;
125 }): ProviderMaintenanceCapabilities {
126 const platform = input.platform ?? HostProcess.Platform.defaultValue();
127 const update =
@@ -143,6 +144,7 @@ export function makeProviderMaintenanceCapabilities(input: {
144 packageName: input.packageName,
145 update,
146 ...("latestVersion" in input ? { latestVersion: input.latestVersion } : {}),
147 + ...(input.lookupLatestVersion ? { lookupLatestVersion: input.lookupLatestVersion } : {}),
148 };
149 }
150
@@ -326,6 +328,7 @@ const runProbe = Effect.fn("runProbe")(function* (
328 command: string,
329 args: ReadonlyArray<string>,
330 env: NodeJS.ProcessEnv,
331 + okExitCodes: ReadonlyArray<number> = [0],
332 ) {
333 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
334 const collect = Effect.gen(function* () {
@@ -348,7 +351,7 @@ const runProbe = Effect.fn("runProbe")(function* (
351 ],
352 { concurrency: "unbounded" },
353 );
351 - return Number(exitCode) !== 0 || stdout.truncated ? null : stdout.text;
354 + return !okExitCodes.includes(Number(exitCode)) || stdout.truncated ? null : stdout.text;
355 });
356 return yield* collect.pipe(
357 Effect.scoped,
@@ -364,6 +367,54 @@ const runProbe = Effect.fn("runProbe")(function* (
367 );
368 });
369
370 +const decodePnpmOutdated = Schema.decodeUnknownOption(
371 + Schema.fromJsonString(
372 + Schema.Record(Schema.String, Schema.Struct({ latest: Schema.optional(Schema.String) })),
373 + ),
374 +);
375 +const decodePnpmList = Schema.decodeUnknownOption(
376 + Schema.fromJsonString(
377 + Schema.Array(
378 + Schema.Struct({
379 + dependencies: Schema.optional(
380 + Schema.Record(Schema.String, Schema.Struct({ version: Schema.optional(Schema.String) })),
381 + ),
382 + }),
383 + ),
384 + ),
385 +);
386 +
387 +// Unlike npm's latest tag, pnpm outdated respects minimumReleaseAge and its excludes.
388 +const resolvePnpmGlobalLatestVersion = Effect.fn("resolvePnpmGlobalLatestVersion")(function* (
389 + packageName: string,
390 +) {
391 + // Match the updater's pnpm and server environment, rather than the instance's.
392 + const pnpmPath = yield* resolveCommandPath("pnpm");
393 + if (!pnpmPath) return null;
394 + // Silent reporting keeps project package-manager warnings out of the JSON.
395 + const outdated = yield* runProbe(
396 + pnpmPath,
397 + ["outdated", "-g", "--reporter=silent", "--format", "json", packageName],
398 + {},
399 + // pnpm outdated exits 1 when updates are available.
400 + [0, 1],
401 + );
402 + const outdatedEntries = outdated
403 + ? Option.getOrUndefined(decodePnpmOutdated(outdated))
404 + : undefined;
405 + if (!outdatedEntries) return null;
406 + const latest = nonEmptyString(outdatedEntries[packageName]?.latest);
407 + if (latest) return latest;
408 + // An empty result means the installed version is still the eligible release.
409 + const listed = yield* runProbe(
410 + pnpmPath,
411 + ["ls", "-g", "--reporter=silent", "--depth", "0", "--json", packageName],
412 + {},
413 + );
414 + const listedEntries = listed ? Option.getOrUndefined(decodePnpmList(listed)) : undefined;
415 + return nonEmptyString(listedEntries?.[0]?.dependencies?.[packageName]?.version);
416 +});
417 +
418 export const resolvePackageManagedProviderMaintenance = Effect.fn(
419 "resolvePackageManagedProviderMaintenance",
420 )(function* (
@@ -443,12 +494,16 @@ export const resolvePackageManagedProviderMaintenance = Effect.fn(
494 pnpmVersion !== null && satisfiesSemverRange(pnpmVersion, ">=10.4.0")
495 ? [`--allow-build=${packageName}`]
496 : [];
497 + const services = yield* Effect.context<ProviderMaintenanceResolverServices>();
498 return makeProviderMaintenanceCapabilities({
499 provider: definition.provider,
500 packageName,
501 updateExecutable: "pnpm",
502 updateArgs: ["add", "-g", ...allowBuild, `${packageName}@latest`],
503 updateLockKey: "pnpm-global",
504 + lookupLatestVersion: resolvePnpmGlobalLatestVersion(packageName).pipe(
505 + Effect.provideContext(services),
506 + ),
507 });
508 }
509
@@ -795,6 +850,21 @@ const fetchNpmLatestVersion = Effect.fn("fetchNpmLatestVersion")(function* (pack
850 return payload ? nonEmptyString(payload.version) : null;
851 });
852
853 +/** The installer's own answer is cached apart from the npm registry entry. */
854 +function installerLatestVersionKey(capabilities: ProviderMaintenanceCapabilities) {
855 + return capabilities.lookupLatestVersion && capabilities.update && capabilities.packageName
856 + ? `${capabilities.update.lockKey}:${capabilities.packageName}`
857 + : null;
858 +}
859 +
860 +export function latestProviderVersionCacheKeys(
861 + capabilities: ProviderMaintenanceCapabilities,
862 +): ReadonlyArray<string> {
863 + return [capabilities.packageName, installerLatestVersionKey(capabilities)].filter(
864 + (key) => key !== null,
865 + );
866 +}
867 +
868 export const resolveLatestProviderVersion = Effect.fn("resolveLatestProviderVersion")(function* (
869 maintenanceCapabilities: ProviderMaintenanceCapabilities,
870 ) {
@@ -807,6 +877,14 @@ export const resolveLatestProviderVersion = Effect.fn("resolveLatestProviderVers
877 }
878
879 const latestVersions = yield* ProviderLatestVersions.ProviderLatestVersions;
880 + const installerKey = installerLatestVersionKey(maintenanceCapabilities);
881 + if (installerKey && maintenanceCapabilities.lookupLatestVersion) {
882 + const installable = yield* latestVersions.cached(
883 + installerKey,
884 + maintenanceCapabilities.lookupLatestVersion,
885 + );
886 + if (installable !== null) return installable;
887 + }
888 return yield* latestVersions.cached(packageName, fetchNpmLatestVersion(packageName));
889 });
890