From d15190803a622e516cc521fe3220a1b98fcee253 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 04:55:28 +0000 Subject: [PATCH] Show Pi model names with slashes and underscores in full (#9823) * fix(pi): keep slashes and underscores in model display names Pi model labels were built as `${provider}/${name}` and then cut at the last `/`, so a free-text name such as "... ~60-70 tok/s, 52/56)" was shown as "56)". Underscores were also rewritten to spaces ("IQ3_S" -> "IQ3 S"). The compact model trigger in the app repeated the last-`/` cut. Build the Pi label from the model's own `name`/`id`: shorten only path-like values with no whitespace (OpenRouter reports names like "google/gemini-2.5-flash-lite"), and keep free-text names intact. The compact trigger now strips only a leading provider namespace. Co-Authored-By: Claude Opus 5.5 * test(pi): cover model labels through the catalog and drop stale ACP copies acp-agent.test.ts still imported transformPiModels, which the Pi label fix removed, so its modelTransformer test and a stale copy of the old Pi label tests failed. The modelTransformer test now supplies its own transformer, and the Pi label cases run through fetchCatalog with the reported model names instead of an exported helper. Co-authored-by: Rahul Sharma <19687913+rms523@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 * fix(pi): keep colons inside free-text model names The vendor-prefix strip cut a free-text Pi name at its first ": ", so "Qwen3 IQ3_S (tail skip: on, 52/56)" showed as "on, 52/56)". Strip only when the text before ": " has no parenthesis or comma, which keeps OpenRouter's "Vendor: Model" names shortened. Co-authored-by: Rahul Sharma <19687913+rms523@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Rahul Sharma <19687913+rms523@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> --- .../composer/agent-controls/model-sheet.tsx | 6 +- .../src/composer/agent-controls/utils.test.ts | 17 ++++ .../app/src/composer/agent-controls/utils.ts | 6 ++ .../server/agent/providers/acp-agent.test.ts | 62 ++---------- .../server/agent/providers/pi/agent.test.ts | 99 ++++++++++++------- .../src/server/agent/providers/pi/agent.ts | 59 +++++------ 6 files changed, 120 insertions(+), 129 deletions(-) diff --git a/packages/app/src/composer/agent-controls/model-sheet.tsx b/packages/app/src/composer/agent-controls/model-sheet.tsx index c9da7d778..95f25ddc4 100644 --- a/packages/app/src/composer/agent-controls/model-sheet.tsx +++ b/packages/app/src/composer/agent-controls/model-sheet.tsx @@ -31,6 +31,7 @@ import { toolbarSlot, type ToolbarGlyphs, } from "@/components/ui/control-geometry"; +import { shortModelLabel } from "./utils"; const SNAP_POINTS = ["80%", "90%"]; const MODEL_LIST_TOP_INSET = 4; @@ -66,11 +67,6 @@ interface CompactModelSheetProps { children: ReactNode; } -function shortModelLabel(label: string): string { - const separatorIndex = label.lastIndexOf("/"); - return separatorIndex === -1 ? label : label.slice(separatorIndex + 1); -} - function resolveModelSheetProfileActions( onCreateProfile: ((seed: AgentProfileSeed) => void) | undefined, onEditProfile: ((profileId: string) => void) | undefined, diff --git a/packages/app/src/composer/agent-controls/utils.test.ts b/packages/app/src/composer/agent-controls/utils.test.ts index ad8f6da98..35d4d89a1 100644 --- a/packages/app/src/composer/agent-controls/utils.test.ts +++ b/packages/app/src/composer/agent-controls/utils.test.ts @@ -4,6 +4,7 @@ import { getAgentControlHintKey, normalizeModelId, resolveAgentModelSelection, + shortModelLabel, } from "./utils"; describe("getAgentControlHintKey", () => { @@ -251,3 +252,19 @@ describe("resolveAgentModelSelection", () => { expect(selection.displayThinking).toBe("Max"); }); }); + +describe("shortModelLabel", () => { + it("drops a provider namespace", () => { + expect(shortModelLabel("openrouter/gpt-5.5")).toBe("gpt-5.5"); + expect(shortModelLabel("openrouter/google/gemini-2.5-flash")).toBe("gemini-2.5-flash"); + }); + + it("keeps slashes inside a display name", () => { + expect(shortModelLabel("DeepSeek V4.1 Flash (~6-7 tok/s, 56/56)")).toBe( + "DeepSeek V4.1 Flash (~6-7 tok/s, 56/56)", + ); + expect(shortModelLabel("llama-swap/DeepSeek V4.1 Flash (56/56)")).toBe( + "DeepSeek V4.1 Flash (56/56)", + ); + }); +}); diff --git a/packages/app/src/composer/agent-controls/utils.ts b/packages/app/src/composer/agent-controls/utils.ts index 26a5cabe5..3e86a122c 100644 --- a/packages/app/src/composer/agent-controls/utils.ts +++ b/packages/app/src/composer/agent-controls/utils.ts @@ -35,6 +35,12 @@ export function normalizeModelId(modelId: string | null | undefined): string | n return normalized; } +// Drops a provider namespace ("openrouter/gpt-5.5" -> "gpt-5.5") for the compact trigger. +// A namespace segment has no spaces, so slashes inside a display name ("52/56") survive. +export function shortModelLabel(label: string): string { + return label.replace(/^(?:[^\s/]+\/)+(?=\S)/, ""); +} + export function getFeatureHighlightColor(featureId: string): FeatureHighlightColor { switch (featureId) { case FAST_MODE_FEATURE_ID: diff --git a/packages/server/src/server/agent/providers/acp-agent.test.ts b/packages/server/src/server/agent/providers/acp-agent.test.ts index 004e4cba9..748d2b462 100644 --- a/packages/server/src/server/agent/providers/acp-agent.test.ts +++ b/packages/server/src/server/agent/providers/acp-agent.test.ts @@ -51,7 +51,6 @@ import { } from "./copilot-acp-agent.js"; import { GenericACPAgentClient } from "./generic-acp-agent.js"; import { parseKiroExtensionCommands } from "./kiro-acp-agent.js"; -import { transformPiModels } from "./pi/agent.js"; import type { AgentStreamEvent } from "../agent-sdk-types.js"; import type { AgentCapabilityFlags, @@ -2260,7 +2259,12 @@ describe("ACPAgentClient modelTransformer", () => { provider: "pi", logger: createTestLogger(), defaultCommand: ["test-acp"], - modelTransformer: transformPiModels, + modelTransformer: (models) => + models.map((model) => ({ + ...model, + label: model.label.split("/").at(-1) ?? model.label, + description: model.id, + })), }); await expect( @@ -2914,60 +2918,6 @@ describe("ACP providers advertise session listing", () => { }); }); -describe("transformPiModels", () => { - test("keeps slash-free labels unchanged", () => { - expect( - transformPiModels([ - { - provider: "pi", - id: "gpt-4.1-mini", - label: "GPT 4.1 Mini", - description: "Fast", - }, - ]), - ).toEqual([ - { - provider: "pi", - id: "gpt-4.1-mini", - label: "GPT 4.1 Mini", - description: "Fast", - }, - ]); - }); - - test("uses the last path segment as label and preserves existing descriptions", () => { - expect( - transformPiModels([ - { - provider: "pi", - id: "openrouter/openai/gpt-4.1-mini", - label: "openrouter/openai/gpt-4.1-mini", - description: undefined, - }, - { - provider: "pi", - id: "anthropic/claude-sonnet-4", - label: "anthropic/claude-sonnet-4", - description: "Balanced", - }, - ]), - ).toEqual([ - { - provider: "pi", - id: "openrouter/openai/gpt-4.1-mini", - label: "gpt-4.1-mini", - description: "openrouter/openai/gpt-4.1-mini", - }, - { - provider: "pi", - id: "anthropic/claude-sonnet-4", - label: "claude-sonnet-4", - description: "Balanced", - }, - ]); - }); -}); - describe("ACPAgentSession slash commands", () => { test("returns immediately for ACP sessions that do not wait for async command discovery", async () => { const session = new ACPAgentSession( diff --git a/packages/server/src/server/agent/providers/pi/agent.test.ts b/packages/server/src/server/agent/providers/pi/agent.test.ts index d152810a9..eab96283b 100644 --- a/packages/server/src/server/agent/providers/pi/agent.test.ts +++ b/packages/server/src/server/agent/providers/pi/agent.test.ts @@ -19,12 +19,7 @@ import { pathToFileURL } from "node:url"; import { describe, expect, onTestFinished, test } from "vitest"; import type { AgentSession, AgentSessionConfig, AgentStreamEvent } from "../../agent-sdk-types.js"; -import { - PiProviderOptionsSchema, - PiRpcAgentClient, - PiRpcAgentSession, - transformPiModels, -} from "./agent.js"; +import { PiProviderOptionsSchema, PiRpcAgentClient, PiRpcAgentSession } from "./agent.js"; import { PiCliRuntime } from "./cli-runtime.js"; import { FakePi } from "./test-utils/fake-pi.js"; import { createPiExtensionHost } from "./extensions/index.js"; @@ -3970,35 +3965,73 @@ readline.createInterface({ input: process.stdin }).on("line", (line) => { }); }); -describe("transformPiModels", () => { - test("normalizes labels that include the upstream provider prefix", () => { - expect( - transformPiModels([ - { - provider: "pi", - id: "openrouter/google/gemini-2.5-flash-lite", - label: "openrouter/google/gemini_2.5 flash lite", - }, - { - provider: "pi", - id: "openrouter/openai/gpt-5.5", - label: "openrouter/OpenAI: GPT-5.5", - }, - ]), - ).toEqual([ - { - provider: "pi", - id: "openrouter/google/gemini-2.5-flash-lite", - label: "gemini 2.5 flash lite", - description: "openrouter/google/gemini_2.5 flash lite", +describe("Pi catalog model labels", () => { + test.each([ + { + name: "keeps slashes and underscores inside a free-text model name", + model: { + provider: "llama-swap", + id: "s-q3fn(p-t)", + name: "Qwen3.8 Flash Next IQ3_S, prior + tail skip (fastest, ~60-70 tok/s on 0.2.10, 52/56)", }, - { - provider: "pi", - id: "openrouter/openai/gpt-5.5", - label: "GPT-5.5", - description: "openrouter/OpenAI: GPT-5.5", + label: "Qwen3.8 Flash Next IQ3_S, prior + tail skip (fastest, ~60-70 tok/s on 0.2.10, 52/56)", + }, + { + name: "keeps a free-text name that ends in a slash-separated word", + model: { + provider: "llama-swap", + id: "ds-strata-6", + name: "DeepSeek V4.1 Flash 2.25bpw via Strata (full 6 experts, untested, ~5-6 tok/s)", }, - ]); + label: "DeepSeek V4.1 Flash 2.25bpw via Strata (full 6 experts, untested, ~5-6 tok/s)", + }, + { + name: "keeps a colon inside a free-text model name", + model: { + provider: "llama-swap", + id: "qwen3-tail", + name: "Qwen3 IQ3_S (tail skip: on, 52/56)", + }, + label: "Qwen3 IQ3_S (tail skip: on, 52/56)", + }, + { + name: "drops the vendor prefix from an upstream model name", + model: { provider: "openrouter", id: "openai/gpt-5.5", name: "OpenAI: GPT-5.5" }, + label: "GPT-5.5", + }, + { + name: "shortens a path-like name to its last segment", + model: { + provider: "openrouter", + id: "google/gemini-2.5-flash-lite", + name: "google/gemini-2.5-flash-lite", + }, + label: "gemini-2.5-flash-lite", + }, + { + name: "falls back to the last segment of a path-like id", + model: { provider: "openrouter", id: "google/gemini_2.5-flash-lite" }, + label: "gemini 2.5-flash-lite", + }, + { + name: "falls back to an id with spaces when the name is blank", + model: { provider: "local", id: "DeepSeek-V4.1-Flash 2.25bpw (Strata)", name: " " }, + label: "DeepSeek-V4.1-Flash 2.25bpw (Strata)", + }, + ])("$name", async ({ model, label }) => { + const pi = new FakePi(); + pi.queueSessionSetup((session) => { + session.models = [model]; + }); + + const catalog = await createClient(pi).fetchCatalog({ + scope: "workspace", + cwd: "/workspace/project", + force: false, + }); + + expect(catalog.models.map((entry) => entry.label)).toEqual([label]); + expect(catalog.models[0]?.id).toBe(`${model.provider}/${model.id}`); }); }); diff --git a/packages/server/src/server/agent/providers/pi/agent.ts b/packages/server/src/server/agent/providers/pi/agent.ts index 60d745ea2..b5a887c11 100644 --- a/packages/server/src/server/agent/providers/pi/agent.ts +++ b/packages/server/src/server/agent/providers/pi/agent.ts @@ -313,34 +313,25 @@ interface PiSlashCommandInvocation { type AutoCompactMode = boolean | "toggle" | "unknown"; -function normalizePiModelLabel(label: string): string { - const normalizedLabel = label.trim().replace(/[_\s]+/g, " "); - const vendorSeparatorIndex = normalizedLabel.indexOf(": "); - if (vendorSeparatorIndex === -1) { - return normalizedLabel; +// Drops an upstream "Vendor: " prefix ("OpenAI: GPT-5.5"). A colon inside parentheses or after a +// comma belongs to the model name ("DeepSeek V4 (ctx: 128k)"), so it is kept. +function stripVendorPrefix(label: string): string { + const vendorSeparatorIndex = label.indexOf(": "); + if (vendorSeparatorIndex === -1 || /[(),]/.test(label.slice(0, vendorSeparatorIndex))) { + return label; } - - return normalizedLabel.slice(vendorSeparatorIndex + 2).trim(); + return label.slice(vendorSeparatorIndex + 2).trim(); } -export function transformPiModels(models: AgentModelDefinition[]): AgentModelDefinition[] { - return models.map((model) => { - if (!model.label.includes("/")) { - return model; - } - - const segments = model.label.split("/").filter((segment) => segment.length > 0); - const rawLabel = segments.at(-1); - if (!rawLabel) { - return model; - } - - return { - ...model, - label: normalizePiModelLabel(rawLabel), - description: model.description ?? model.label, - }; - }); +// A Pi model name is either a path ("google/gemini_2.5-flash", as OpenRouter reports it) or +// free text that can contain slashes and underscores ("IQ3_S ... 52/56"). Only shorten paths. +function piModelLabel(model: Pick): string { + const text = model.name?.trim().replace(/\s+/g, " ") || model.id.trim(); + if (/\s/.test(text)) { + return stripVendorPrefix(text); + } + const lastSegment = text.split("/").findLast((segment) => segment.length > 0) ?? text; + return stripVendorPrefix(lastSegment.replace(/_+/g, " ")); } function isPiThinkingLevel(value: string | null | undefined): value is PiThinkingLevel { @@ -1166,7 +1157,7 @@ function mapPiModel(model: PiModel, provider: AgentProvider): AgentModelDefiniti return { provider, id: `${model.provider}/${model.id}`, - label: `${model.provider}/${model.name ?? model.id}`, + label: piModelLabel(model), description: `${model.provider}/${model.id}`, metadata: { provider: model.provider, @@ -2817,15 +2808,13 @@ export class PiRpcAgentClient implements AgentClient { "get_state", () => catalogSession.getState(), ); - const models = transformPiModels( - piModels.map((model) => { - const mapped = mapPiModel(model, PI_PROVIDER); - const isConfigured = - model.provider === configuredModel?.provider && model.id === configuredModel?.id; - if (isConfigured) mapped.isDefault = true; - return mapped; - }), - ); + const models = piModels.map((model) => { + const mapped = mapPiModel(model, PI_PROVIDER); + const isConfigured = + model.provider === configuredModel?.provider && model.id === configuredModel?.id; + if (isConfigured) mapped.isDefault = true; + return mapped; + }); return { models, modes: [] }; } finally { context?.signal.removeEventListener("abort", handleAbort);