Skip to content

Commit 211f230

Browse files
committed
fix: clean Pi chat output and settings diagnostics
1 parent 0b6010e commit 211f230

3 files changed

Lines changed: 80 additions & 8 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import { sanitizePiAssistantTextDelta } from "./PiAdapter.ts";
4+
5+
describe("sanitizePiAssistantTextDelta", () => {
6+
it("removes Pi CLI update notices while preserving assistant text", () => {
7+
expect(
8+
sanitizePiAssistantTextDelta(
9+
"New version available: v0.75.3 (installed v0.73.1). Run: npm i -g @earendil-works/pi-coding-agent PI_OK",
10+
),
11+
).toBe("PI_OK");
12+
});
13+
14+
it("leaves normal assistant text untouched", () => {
15+
expect(sanitizePiAssistantTextDelta("PI_OK")).toBe("PI_OK");
16+
});
17+
});

‎apps/server/src/provider/Layers/PiAdapter.ts‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ import {
4444
ProviderAdapterSessionNotFoundError,
4545
ProviderAdapterValidationError,
4646
} from "../Errors.ts";
47-
import {
48-
acpPermissionOutcome,
49-
mapAcpToAdapterError,
50-
} from "../acp/AcpAdapterSupport.ts";
47+
import { acpPermissionOutcome, mapAcpToAdapterError } from "../acp/AcpAdapterSupport.ts";
5148
import { type AcpSessionRuntimeShape } from "../acp/AcpSessionRuntime.ts";
5249
import {
5350
makeAcpAssistantItemEvent,
@@ -155,6 +152,13 @@ function parsePiResume(raw: unknown): { sessionId: string } | undefined {
155152
return { sessionId: raw.sessionId.trim() };
156153
}
157154

155+
const PI_CLI_UPDATE_NOTICE_PATTERN =
156+
/(^|\n)New version available: v[^\n]*\(installed v[^\n]*\)\. Run: npm i -g @earendil-works\/pi-coding-agent\s*/g;
157+
158+
export function sanitizePiAssistantTextDelta(text: string): string {
159+
return text.replace(PI_CLI_UPDATE_NOTICE_PATTERN, "$1");
160+
}
161+
158162
function selectAutoApprovedPermissionOption(
159163
request: EffectAcpSchema.RequestPermissionRequest,
160164
): string | undefined {
@@ -554,7 +558,12 @@ export function makePiAdapter(piSettings: PiSettings, options?: PiAdapterLiveOpt
554558
}),
555559
);
556560
return;
557-
case "ContentDelta":
561+
case "ContentDelta": {
562+
const text = sanitizePiAssistantTextDelta(event.text);
563+
if (text.length === 0) {
564+
return;
565+
}
566+
558567
yield* logNative(
559568
ctx.threadId,
560569
"session/update",
@@ -568,11 +577,12 @@ export function makePiAdapter(piSettings: PiSettings, options?: PiAdapterLiveOpt
568577
threadId: ctx.threadId,
569578
turnId: ctx.activeTurnId,
570579
...(event.itemId ? { itemId: event.itemId } : {}),
571-
text: event.text,
580+
text,
572581
rawPayload: event.rawPayload,
573582
}),
574583
);
575584
return;
585+
}
576586
}
577587
}),
578588
),

‎apps/web/src/components/settings/ProviderInstanceCard.tsx‎

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ function readConfigStringArray(config: unknown, key: string): ReadonlyArray<stri
101101
return value.filter((entry): entry is string => typeof entry === "string");
102102
}
103103

104+
function readConfigString(config: unknown, key: string): string | null {
105+
if (config === null || typeof config !== "object") return null;
106+
const value = (config as Record<string, unknown>)[key];
107+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
108+
}
109+
104110
/**
105111
* Set `key` to an arbitrary value on the opaque config blob. Unlike
106112
* provider settings field updates, does not drop empty-looking values — the
@@ -529,6 +535,8 @@ export function ProviderInstanceCard({
529535
const suggestedBinaryPath = liveProvider?.suggestedBinaryPath?.trim();
530536
const isHermesDriver = String(instance.driver) === "hermes";
531537
const isPiDriver = String(instance.driver) === "pi";
538+
const configuredBinaryPath = readConfigString(instance.config, "binaryPath");
539+
const configuredPiBinaryPath = readConfigString(instance.config, "piBinaryPath");
532540
const FallbackIconComponent = driverOption?.icon;
533541
const displayName =
534542
instance.displayName?.trim() || driverOption?.label || String(instance.driver);
@@ -735,6 +743,42 @@ export function ProviderInstanceCard({
735743
<code className="text-xs text-muted-foreground">{versionLabel}</code>
736744
) : null;
737745

746+
const diagnosticsRows = [
747+
["Status", summary.headline],
748+
["Auth", liveProvider?.auth.status ?? "unknown"],
749+
["Version", versionLabel ?? "unknown"],
750+
["Binary", configuredBinaryPath ?? (isHermesDriver ? "hermes" : isPiDriver ? "pi-acp" : null)],
751+
...(isPiDriver ? [["Pi binary", configuredPiBinaryPath ?? "pi"]] : []),
752+
...(suggestedBinaryPath ? [["Detected path", suggestedBinaryPath]] : []),
753+
].filter((row): row is [string, string] => typeof row[1] === "string" && row[1].length > 0);
754+
755+
const diagnosticsNode =
756+
(isHermesDriver || isPiDriver) && diagnosticsRows.length > 0 ? (
757+
<div className="border-t border-border/60 px-4 py-3 sm:px-5">
758+
<div className="grid gap-3">
759+
<div className="grid gap-1">
760+
<span className="text-xs font-medium text-foreground">Provider diagnostics</span>
761+
<p className="text-xs leading-snug text-muted-foreground">
762+
Quick facts for debugging local setup, packaged app launches, and installed versions.
763+
</p>
764+
</div>
765+
<dl className="grid gap-1.5 rounded-md border border-border/70 bg-muted/20 p-2">
766+
{diagnosticsRows.map(([label, value]) => (
767+
<div key={label} className="grid min-w-0 grid-cols-[6.5rem_1fr] gap-2 text-xs">
768+
<dt className="text-muted-foreground">{label}</dt>
769+
<dd
770+
className="min-w-0 truncate font-mono text-[11px] text-foreground"
771+
title={value}
772+
>
773+
{value}
774+
</dd>
775+
</div>
776+
))}
777+
</dl>
778+
</div>
779+
</div>
780+
) : null;
781+
738782
const hermesSetupNode = isHermesDriver ? (
739783
<div className="border-t border-border/60 px-4 py-3 sm:px-5">
740784
<div className="grid gap-3">
@@ -792,8 +836,8 @@ export function ProviderInstanceCard({
792836
<div className="grid gap-1">
793837
<span className="text-xs font-medium text-foreground">Pi setup</span>
794838
<p className="text-xs leading-snug text-muted-foreground">
795-
T3 Code starts Pi through the pi-acp adapter. For GPT-5.5, sign into Pi with the
796-
ChatGPT Plus/Pro Codex provider, then verify both commands before sending a turn.
839+
T3 Code starts Pi through the pi-acp adapter. For GPT-5.5, sign into Pi with the ChatGPT
840+
Plus/Pro Codex provider, then verify both commands before sending a turn.
797841
</p>
798842
</div>
799843
{suggestedBinaryPath ? (
@@ -1076,6 +1120,7 @@ export function ProviderInstanceCard({
10761120

10771121
{hermesSetupNode}
10781122
{piSetupNode}
1123+
{diagnosticsNode}
10791124
{providerUpdateNode}
10801125

10811126
{driverOption ? (

0 commit comments

Comments
 (0)