@devries-cameron20 / t3code Mirror · read-only / commits / dcd39b4b6e
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 21, 12:15 UTC

fix(pi): model list loads when the server's folder has a project MCP config (#28557)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Prem Chaitanya Prathi committed Nov 15, 2026 at 10:14 UTC dcd39b4b6e37fbf8568817e328235f96106e0a66
2 files changed +114 -7
packages/provider-pi/src/server/status.test.ts
+60 -1
@@ -19,6 +19,13 @@ const decodeRpcRequest = Schema.decodeSync(
19 Schema.fromJsonString(Schema.Struct({ id: Schema.String, type: Schema.String })),
20 );
21 const encodeJsonLine = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
22 +const STARTUP_DIALOG = `${encodeJsonLine({
23 + type: "extension_ui_request",
24 + id: "ui-1",
25 + method: "select",
26 + title: "Allow project MCP server “github”?",
27 + options: ["Don't allow", "Allow"],
28 +})}\n`;
29
30 function processHandle(input: {
31 readonly stdout?: string;
@@ -118,6 +125,10 @@ const piDiscoverySpawner = (
125 readonly version?: string;
126 readonly state?: unknown;
127 readonly authCheck?: string | undefined;
128 + /** Without `--no-approve`, print a project-trust dialog and exit 0 as Pi 1.x does. */
129 + readonly startupDialog?: boolean;
130 + /** What `--no-approve` lists once project-local extensions are skipped. */
131 + readonly declinedProjectInventory?: unknown;
132 } = {},
133 ) =>
134 Effect.succeed(
@@ -132,13 +143,24 @@ const piDiscoverySpawner = (
143 ? Effect.die(`Unexpected pi ${args.join(" ")}`)
144 : Effect.succeed(processHandle({ stdout: options.authCheck, exitCode: 1 }));
145 }
146 + if (
147 + options.startupDialog === true &&
148 + !args.includes("--no-extensions") &&
149 + !args.includes("--no-approve")
150 + ) {
151 + return Effect.succeed(processHandle({ stdout: STARTUP_DIALOG }));
152 + }
153 if (args.includes("--no-extensions") && extensionFreeInventory === exitsWithoutExtensions) {
154 return Effect.succeed(
155 processHandle({ stderr: 'Error: Unknown provider "demo".', exitCode: 1 }),
156 );
157 }
158 return piRpcProcess(
141 - args.includes("--no-extensions") ? extensionFreeInventory : inventory,
159 + args.includes("--no-extensions")
160 + ? extensionFreeInventory
161 + : args.includes("--no-approve") && options.declinedProjectInventory !== undefined
162 + ? options.declinedProjectInventory
163 + : inventory,
164 args.includes("--no-extensions") ? onExtensionFreeModelRequest : Effect.void,
165 options.state,
166 );
@@ -423,6 +445,43 @@ describe("PiProvider", () => {
445 }).pipe(Effect.provide(NodeServices.layer)),
446 );
447
448 + it.effect.each([
449 + { launchArgs: "", startupDialog: true, models: ["default", "anthropic/claude-opus"] },
450 + { launchArgs: "--approve", startupDialog: true, models: ["default"] },
451 + {
452 + launchArgs: "",
453 + startupDialog: false,
454 + models: ["default", "anthropic/claude-opus", "project/local-model"],
455 + },
456 + ])(
457 + "keeps project trust unless a startup dialog blocks discovery (dialog: $startupDialog, launch args '$launchArgs')",
458 + (row) =>
459 + Effect.gen(function* () {
460 + const spawner = yield* piDiscoverySpawner(
461 + {
462 + models: [
463 + { provider: "anthropic", id: "claude-opus" },
464 + { provider: "project", id: "local-model" },
465 + ],
466 + },
467 + undefined,
468 + undefined,
469 + {
470 + startupDialog: row.startupDialog,
471 + declinedProjectInventory: { models: [{ provider: "anthropic", id: "claude-opus" }] },
472 + },
473 + );
474 + const snapshot = yield* checkPiProviderStatus({
475 + ...settings,
476 + launchArgs: row.launchArgs,
477 + }).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner));
478 + assert.deepEqual(
479 + snapshot.models.map((model) => model.slug),
480 + row.models,
481 + );
482 + }).pipe(Effect.provide(NodeServices.layer)),
483 + );
484 +
485 // regression: #18498 a malformed model inventory must not restore stale Pi models
486 it.effect.each([
487 ["missing models", {}],
packages/provider-pi/src/server/status.ts
+54 -6
@@ -8,6 +8,7 @@ import type { PiSettings } from "../settings.ts";
8 import { causeErrorTag } from "@t3tools/shared/observability";
9 import { resolveSpawnCommand } from "@t3tools/shared/shell";
10 import { compareSemverVersions } from "@t3tools/shared/semver";
11 +import * as Cause from "effect/Cause";
12 import * as DateTime from "effect/DateTime";
13 import * as Effect from "effect/Effect";
14 import * as Stream from "effect/Stream";
@@ -167,6 +168,36 @@ const makePiDiscoveryConnection = Effect.fnUntraced(function* (
168 return connection;
169 });
170
171 +// A failed response echoes Pi's own `command` field as the operation, so log only names we sent.
172 +const PI_LOGGED_RPC_OPERATIONS = new Set([
173 + "spawn",
174 + "read",
175 + "write",
176 + "exit",
177 + "terminate",
178 + "get_state",
179 + "get_available_models",
180 + "get_commands",
181 +]);
182 +
183 +const PI_PROJECT_TRUST_ARGUMENTS = new Set(["--approve", "-a", "--no-approve", "-na"]);
184 +
185 +const readPiInventory = Effect.fn("PiProviderStatus.readPiInventory")(function* (
186 + piSettings: PiSettings,
187 + environment: NodeJS.ProcessEnv,
188 + launchArgs: ReadonlyArray<string>,
189 + timeoutMs: number,
190 + cwd?: string,
191 +) {
192 + const connection = yield* makePiDiscoveryConnection(piSettings, environment, launchArgs, cwd);
193 + const stateData = yield* connection.request({ type: "get_state" }, timeoutMs);
194 + const modelsData = yield* connection.request({ type: "get_available_models" }, timeoutMs);
195 + const commandsData = yield* connection
196 + .request({ type: "get_commands" }, timeoutMs)
197 + .pipe(Effect.orElseSucceed(() => undefined));
198 + return { stateData, modelsData, commandsData };
199 +}, Effect.scoped);
200 +
201 // Text generation runs Pi with --no-extensions, so it cannot load models that an
202 // extension or package registers. Listing models with that launch tells them apart.
203 const discoverPiTextGenerationModelSlugs = Effect.fn(
@@ -217,12 +248,25 @@ const discoverPiViaRpc = Effect.fn("PiProviderStatus.discoverPiViaRpc")(function
248 }),
249 Effect.forkScoped,
250 );
220 - const connection = yield* makePiDiscoveryConnection(piSettings, environment, launchArgs, cwd);
221 - const stateData = yield* connection.request({ type: "get_state" }, timeoutMs);
222 - const modelsData = yield* connection.request({ type: "get_available_models" }, timeoutMs);
223 - const commandsData = yield* connection
224 - .request({ type: "get_commands" }, timeoutMs)
225 - .pipe(Effect.orElseSucceed(() => undefined));
251 + const { stateData, modelsData, commandsData } = yield* readPiInventory(
252 + piSettings,
253 + environment,
254 + launchArgs,
255 + timeoutMs,
256 + cwd,
257 + ).pipe(
258 + // Pi's RPC mode reads stdin only after session_start, so a startup dialog (an MCP adapter asking
259 + // to approve a project server) can never be answered and Pi exits. Retry declining project trust
260 + // unless the user chose a trust mode, so trusted projects keep their project-local models.
261 + Effect.catchIf(
262 + (error) =>
263 + error._tag === "PiRpcError" &&
264 + (error.operation === "read" || error.operation === "exit") &&
265 + !launchArgs.some((arg) => PI_PROJECT_TRUST_ARGUMENTS.has(arg)),
266 + () =>
267 + readPiInventory(piSettings, environment, [...launchArgs, "--no-approve"], timeoutMs, cwd),
268 + ),
269 + );
270 const discoveredModels = yield* Effect.fromResult(parseDiscoveredModels(modelsData, stateData));
271 const { slashCommands, skills } = parsePiDiscoveredCommands(commandsData);
272 const textGenerationModelSlugs = yield* Fiber.join(textGenerationModelSlugsFiber);
@@ -532,8 +576,12 @@ export const checkPiProviderStatus = Effect.fn("checkPiProviderStatus")(function
576 Effect.exit,
577 );
578 if (Exit.isFailure(discoveryExit)) {
579 + const failure = Cause.findErrorOption(discoveryExit.cause);
580 yield* Effect.logWarning("Pi RPC discovery failed.", {
581 errorTag: causeErrorTag(discoveryExit.cause),
582 + ...(Option.isSome(failure) && PI_LOGGED_RPC_OPERATIONS.has(failure.value.operation)
583 + ? { operation: failure.value.operation }
584 + : {}),
585 });
586 return buildServerProvider({
587 presentation: PI_PRESENTATION,