Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(desktop): 新会话 Agent 切换器上线 Pi tab —— vendor 三值化 + 转换正本收敛

zqchrisaaf9b522f0c4
diff --git a/apps/desktop/src/main/im/shared/sessionRepo.ts b/apps/desktop/src/main/im/shared/sessionRepo.ts
index f7462aeb73..f642be6386 100644
--- a/apps/desktop/src/main/im/shared/sessionRepo.ts
+++ b/apps/desktop/src/main/im/shared/sessionRepo.ts
@@ -17,6 +17,7 @@ import type { ProviderView } from '@cindy/model-providers';
import { permissionModeOrAsk } from '@cindy/maker-shared/permission-mode';
import { getDbClient } from '../../localDb/client/current';
+import { normalizeDbAgentKind } from '../../../shared/agentKindConversion';
import { sessions } from '../../localDb/schema';
import { createLogger, maskPath } from '../../logger';
import { setSessionProvider } from '../../maker-host/session-provider-store';
@@ -36,7 +37,7 @@ export function toCoreAgentKind(kind: string): AgentKind {
/** core AgentKind → sessions.agentKind 列的 legacy 存储值。 */
function toDbAgentKind(kind: AgentKind): string {
- return kind === 'codex' ? 'codex' : 'cc';
+ return normalizeDbAgentKind(kind);
}
export interface ImSessionRow {
diff --git a/apps/desktop/src/main/localDb/chatHistoryReader.ts b/apps/desktop/src/main/localDb/chatHistoryReader.ts
index 3b39587406..39eb8d49d7 100644
--- a/apps/desktop/src/main/localDb/chatHistoryReader.ts
+++ b/apps/desktop/src/main/localDb/chatHistoryReader.ts
@@ -29,7 +29,7 @@ const messageRowid = sql<number>`"messages"."rowid"`;
// ── Types ───────────────────────────────────────────────────────────────────
export type HistoryOrder = 'asc' | 'desc';
-export type HistoryAgentKind = 'cc' | 'codex';
+export type HistoryAgentKind = 'cc' | 'codex' | 'pi';
export interface HistoryCursor {
createdAt: number; // unix ms
diff --git a/apps/desktop/src/main/localDb/conversationSearch.ts b/apps/desktop/src/main/localDb/conversationSearch.ts
index 1938059cbc..d11d2d0b54 100644
--- a/apps/desktop/src/main/localDb/conversationSearch.ts
+++ b/apps/desktop/src/main/localDb/conversationSearch.ts
@@ -17,6 +17,7 @@ import { DESKTOP_VISIBLE_SESSION_SOURCES } from '../../shared/sessionSource.js';
import { getDbClient } from './client/current.js';
import { messages, sessions } from './schema.js';
import { searchChatHistoryHybrid } from './chatHistorySearch.js';
+import { normalizeDbAgentKind } from '../../shared/agentKindConversion.js';
import {
collectContentHitsUntilUniqueSessions,
fuzzyTitleMatch,
@@ -332,7 +333,7 @@ function sessionSummaryFromRow(
title: row.title,
workingDir: row.workingDir,
workspaceKind: row.workspaceKind,
- agentKind: row.agentKind === 'codex' ? 'codex' : 'cc',
+ agentKind: normalizeDbAgentKind(row.agentKind),
status: row.status,
source: row.source,
orcaRole: row.orcaRole,
diff --git a/apps/desktop/src/main/localDb/ipc/messages.ts b/apps/desktop/src/main/localDb/ipc/messages.ts
index acefd56d1e..2b9b83bd45 100644
--- a/apps/desktop/src/main/localDb/ipc/messages.ts
+++ b/apps/desktop/src/main/localDb/ipc/messages.ts
@@ -945,7 +945,7 @@ export async function createMessage(
* agentMeta 需要它;main 侧 SDK 事件落库路径必传,renderer pending echo 等
* 无 SDK 元信息的行留空(null 回落 session.agentKind)。
*/
- agentKind?: 'cc' | 'codex' | null;
+ agentKind?: 'cc' | 'codex' | 'pi' | null;
createdAt?: number;
},
opts?: {
@@ -1680,7 +1680,7 @@ export interface ParkedEngineSession {
*/
export async function findParkedEngineSession(
sessionId: string,
- targetDbKind: 'cc' | 'codex',
+ targetDbKind: 'cc' | 'codex' | 'pi',
): Promise<ParkedEngineSession | null> {
const db = getDbClient().drizzle;
const [sessRow] = await db
diff --git a/apps/desktop/src/main/localDb/ipc/pluginWorkspaceSessions.ts b/apps/desktop/src/main/localDb/ipc/pluginWorkspaceSessions.ts
index 4cbedb31f5..68b1aa0b37 100644
--- a/apps/desktop/src/main/localDb/ipc/pluginWorkspaceSessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/pluginWorkspaceSessions.ts
@@ -74,7 +74,7 @@ export async function createPluginDraftSession(params: {
* 由 mapper 兜底)——让插件建的 draft 跟随用户当前的模型/强度选择。
*/
defaults?: {
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
model?: string;
effort?: string;
fastMode?: boolean;
diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.ts
index bacbc87501..c5bd2ef633 100644
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@ -21,6 +21,7 @@ import type { DbClient } from '../client/DbClient';
import { sessions, messages } from '../schema';
import { throwIpcError, requireString, requireObject } from '../../utils/ipcValidate';
import { resolveBusinessSessionId } from '../../sessionIds';
+import { normalizeDbAgentKind } from '../../../shared/agentKindConversion';
import {
sessionToCamel,
sessionCreateToRow,
@@ -192,7 +193,7 @@ const REMOTE_PERSIST_FIELDS = new Set([
export async function applyAgentSwitchToSessionRow(
sessionId: string,
patch: {
- agentKind: 'cc' | 'codex';
+ agentKind: 'cc' | 'codex' | 'pi';
model: string;
providerId: string | null | undefined;
sdkSessionId?: string | null;
@@ -961,7 +962,7 @@ export function registerSessionIpc(): void {
state: row.status === 'deleted' ? 'deleted' : 'available',
status: row.status,
title: row.title,
- agentKind: row.agentKind === 'codex' ? 'codex' : 'cc',
+ agentKind: normalizeDbAgentKind(row.agentKind),
};
});
});
diff --git a/apps/desktop/src/main/localDb/mapper.ts b/apps/desktop/src/main/localDb/mapper.ts
index 4419bffe9c..50eb148f19 100644
--- a/apps/desktop/src/main/localDb/mapper.ts
+++ b/apps/desktop/src/main/localDb/mapper.ts
@@ -218,7 +218,7 @@ export function messageToCamel(row: MessageRow): Message {
content,
toolUseId: row.toolUseId,
agentMeta,
- agentKind: (row.agentKind as 'cc' | 'codex' | null) ?? null,
+ agentKind: (row.agentKind as 'cc' | 'codex' | 'pi' | null) ?? null,
createdAt: new Date(row.createdAt).toISOString(),
};
}
@@ -373,7 +373,7 @@ export function messageCreateToRow(
content: unknown;
toolUseId?: string;
agentMeta?: AgentMeta | null;
- agentKind?: 'cc' | 'codex' | null;
+ agentKind?: 'cc' | 'codex' | 'pi' | null;
createdAt?: number;
},
now: number,
diff --git a/apps/desktop/src/main/maker-ipc/agentHandoff.ts b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
index a458635d22..ba4ac44be0 100644
--- a/apps/desktop/src/main/maker-ipc/agentHandoff.ts
+++ b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
@@ -14,7 +14,7 @@
import { projectPersistedAgentFacingUserText } from '@cindy/maker-shared/agent-input-projection';
/** DB 层引擎标识(sessions.agent_kind / messages.agent_kind 的值域)。 */
-export type DbAgentKind = 'cc' | 'codex';
+export type DbAgentKind = 'cc' | 'codex' | 'pi';
/** 构造交接文本所需的最小消息投影(content 已 JSON.parse,即 camel Message.content)。 */
export interface HandoffSourceMessage {
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index c7e7218e42..f4c2b4622e 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -315,6 +315,7 @@ import {
recordTurnSpend,
} from '../usageBroadcaster.js';
import { throwIpcError } from '../utils/ipcValidate.js';
+import { dbToMakerAgentKind, makerToDbAgentKind } from '../../shared/agentKindConversion.js';
import { readWorkflowProgressForSession } from '../workflow-progress/reader.js';
import {
AgentInputCoordinator,
@@ -2018,7 +2019,7 @@ export async function registerPendingCredentialSwitchForSession(
const prevModel = live?.model ?? prevRow?.model ?? null;
service.register(sessionId, {
...target,
- ...(dbAgentKind ? { agentKind: dbAgentKind === 'cc' ? 'claude-code' as const : 'codex' as const } : {}),
+ ...(dbAgentKind ? { agentKind: dbToMakerAgentKind(dbAgentKind) } : {}),
...(prevModel
? {
previousRoute: {
@@ -2656,7 +2657,7 @@ export function wireSessionToIpc(session: ReturnType<Maker['getSession']>): void
// session-agent-switch:登记本会话当前引擎,broadcaster / user 行落库据此逐行
// stamp messages.agent_kind(切换后历史行的 agent_meta 必须按写入时引擎解析)。
- noteSessionAgentKind(session.id, session.agentKind === 'codex' ? 'codex' : 'cc');
+ noteSessionAgentKind(session.id, makerToDbAgentKind(session.agentKind));
// 订阅槽①旁听 tap(独立监听,叠加在主转发之外互不干扰):AgentEvent →
// did-turn-*。资格(用户主会话)与自动化轮次过滤都在 tap 内部,这里零逻辑。
@@ -8357,7 +8358,7 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const dbAgentKind = getSessionDbAgentKind(sessionId);
if (dbAgentKind) {
const reroute = await assertModelRouteUsable(
- dbAgentKind === 'cc' ? 'claude-code' : 'codex',
+ dbToMakerAgentKind(dbAgentKind),
model,
typeof providerId === 'string' ? providerId : null,
);
diff --git a/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts b/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts
index bee4b7eacf..890646d729 100644
--- a/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts
@@ -36,6 +36,7 @@ import {
type HandoffSourceMessage,
} from './agentHandoff.js';
import { throwIpcError } from '../utils/ipcValidate.js';
+import { dbToMakerAgentKind, makerToDbAgentKind, normalizeDbAgentKind } from '../../shared/agentKindConversion.js';
function throwIfAgentSwitchAborted(signal: AbortSignal | undefined): void {
if (signal?.aborted) {
@@ -50,18 +51,20 @@ export interface ParkedEngineSessionRef {
watermarkRowid: number;
}
-/** DB 'cc'/'codex' ↔ maker-core 'claude-code'/'codex' 映射(与 register.ts 各处内联口径一致)。 */
+/** DB ↔ maker-core 形态映射 —— 正本在 shared/agentKindConversion.ts,此处仅转发。 */
export function toDbAgentKind(kind: AgentKind): DbAgentKind {
- return kind === 'codex' ? 'codex' : 'cc';
+ return makerToDbAgentKind(kind);
}
export function toMakerAgentKind(dbKind: string): AgentKind {
- return dbKind === 'codex' ? 'codex' : 'claude-code';
+ return dbToMakerAgentKind(dbKind);
}
/** 交接 framing 与边界卡展示用的引擎名。 */
export function agentEngineLabel(dbKind: DbAgentKind): string {
- return dbKind === 'codex' ? 'Codex' : 'Claude Code';
+ if (dbKind === 'codex') return 'Codex';
+ if (dbKind === 'pi') return 'Pi';
+ return 'Claude Code';
}
/** role='agent_switch' 边界行的 content 结构(与 renderer AgentSwitchContent 对齐)。 */
@@ -362,8 +365,8 @@ export async function performSessionAgentSwitch(
throwIpcError('UNSUPPORTED_CAPABILITY', 'agent switch is not supported for Orca sessions');
}
- const fromDbKind: DbAgentKind = row.agentKind === 'codex' ? 'codex' : 'cc';
- const toDbKind: DbAgentKind = targetAgentKind === 'codex' ? 'codex' : 'cc';
+ const fromDbKind: DbAgentKind = normalizeDbAgentKind(row.agentKind);
+ const toDbKind: DbAgentKind = makerToDbAgentKind(targetAgentKind);
if (fromDbKind === toDbKind) {
// 同引擎 = 纯模型切换,调用方应走 SET_MODEL;这里按 no-op 成功返回。
// 顺带清 pending:用户先登记了跨引擎切换、又选回当前引擎 = 改主意取消。
diff --git a/apps/desktop/src/main/maker-orchestration/fork.ts b/apps/desktop/src/main/maker-orchestration/fork.ts
index 08ff1d20b8..5d0fd3ff2e 100644
--- a/apps/desktop/src/main/maker-orchestration/fork.ts
+++ b/apps/desktop/src/main/maker-orchestration/fork.ts
@@ -16,6 +16,7 @@ import { sessions, messages } from '../localDb/schema';
import { sessionToCamel } from '../localDb/mapper';
import { getMaker } from '../maker-host/index.js';
import { createBusinessSessionId } from '../sessionIds.js';
+import { normalizeDbAgentKind } from '../../shared/agentKindConversion.js';
import type { Session } from '../../renderer/lib/ccAgent.types';
import {
type ClaudeTranscriptAnchorIndex,
@@ -50,7 +51,7 @@ function normalizePositiveInt(value: unknown): number {
const messageRowid = sql<number>`rowid`;
-type DbAgentKind = 'cc' | 'codex';
+type DbAgentKind = 'cc' | 'codex' | 'pi';
interface MessagePosition {
createdAt: number;
@@ -168,7 +169,7 @@ async function resolveForkNativeSource(
if (!source.sdkSessionId) {
throw forkError('SOURCE_NEVER_RAN', '原会话尚未运行,无法 fork');
}
- const agentKind: DbAgentKind = source.agentKind === 'codex' ? 'codex' : 'cc';
+ const agentKind: DbAgentKind = normalizeDbAgentKind(source.agentKind);
return {
agentKind,
sdkSessionId: source.sdkSessionId,
diff --git a/apps/desktop/src/main/messagePersistBroadcaster.ts b/apps/desktop/src/main/messagePersistBroadcaster.ts
index 5f00937112..3028d481a9 100644
--- a/apps/desktop/src/main/messagePersistBroadcaster.ts
+++ b/apps/desktop/src/main/messagePersistBroadcaster.ts
@@ -81,13 +81,13 @@ type CreateDbMessageBody = Parameters<typeof createDbMessage>[1];
* session.agent_kind 只代表"当前引擎",历史行的 agent_meta 必须按写入时引擎解析。
* clearSessionPersistState 时清理。
*/
-const dbAgentKindBySession = new Map<string, 'cc' | 'codex'>();
+const dbAgentKindBySession = new Map<string, 'cc' | 'codex' | 'pi'>();
-export function noteSessionAgentKind(sessionId: string, dbAgentKind: 'cc' | 'codex'): void {
+export function noteSessionAgentKind(sessionId: string, dbAgentKind: 'cc' | 'codex' | 'pi'): void {
dbAgentKindBySession.set(sessionId, dbAgentKind);
}
-export function getSessionDbAgentKind(sessionId: string): 'cc' | 'codex' | null {
+export function getSessionDbAgentKind(sessionId: string): 'cc' | 'codex' | 'pi' | null {
return dbAgentKindBySession.get(sessionId) ?? null;
}
diff --git a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
index bbddc57034..5b5b22aff9 100644
--- a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
+++ b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
@@ -46,7 +46,7 @@ interface ErrorBannerProps {
onContinueAfterUsageReset?: () => void;
/** 当前 session 的 agent kind。codex 的 401 / Missing bearer 必须 hide Retry,
* 否则 retry 撞同一个 in-memory auth retry-loop 产生重复失败 turn。 */
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
/** 当前 session 的远端 host id;非空 + agentKind='codex' 时显「同步登录态」按钮。
* 本地 codex 401 仍 hide Retry, 但只能提示用户去自己 fix login (没有 sync 入口)。 */
remoteHostId?: string;
diff --git a/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx b/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx
index 0bfa33d0aa..ac8e21b468 100644
--- a/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx
+++ b/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx
@@ -130,7 +130,7 @@ export function ErrorTailErrorBanner({
errorText: string;
onContinue: () => Promise<void> | void;
onDismiss: () => void;
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
remoteHostId?: string;
deviceLinkDeviceId?: string | null;
modelId?: string;
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index ab5808fbe2..801fa8841b 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -203,7 +203,7 @@ interface MessageStreamProps {
sessionTitle?: string | null;
/** Owning agent kind — propagated to UserMessage so capability gates
* (fork/rewind icon visibility) can read the right agent's capabilities. */
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
/** Owning session's remote SSH host id (null for local sessions). Forwarded
* so message-level controls can gate features unsupported on remote
* (e.g. rewind on cc-remote daemon sessions). */
@@ -2024,7 +2024,7 @@ function renderWorkGroupChild(
workingDir: string;
sessionId?: string;
sessionTitle?: string | null;
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
remoteHostId?: string | null;
isSessionStreaming: boolean;
firstUserMessageClientId: string | null;
@@ -3760,7 +3760,7 @@ const MessageItem = memo(function MessageItem({
remoteHostId?: string | null;
/** Forwarded to User/AssistantMessage so they can read this agent's
* capabilities (gates Fork/Rewind icon visibility). */
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
/** Whether this session currently has an in-flight SDK turn. Rewind uses it
* to require an idle live query; fork can still target stable history. */
sessionRunning?: boolean;
diff --git a/apps/desktop/src/renderer/components/icons/PiMark.tsx b/apps/desktop/src/renderer/components/icons/PiMark.tsx
new file mode 100644
index 0000000000..d5f86b19a9
--- /dev/null
+++ b/apps/desktop/src/renderer/components/icons/PiMark.tsx
@@ -0,0 +1,37 @@
+/**
+ * PiMark —— pi coding agent(earendil-works/pi)的身份 mark。
+ *
+ * pi 上游没有对外的品牌 glyph 规范,这里用块状笔画的 π 字形,笔画粗细与
+ * ClaudeMark 像素脸 / CodexMark `>_` 花形的视觉重量对齐。
+ * - variant="mono"(默认):currentColor,跟随主题/状态染色;
+ * - variant="brand":pi 无官方品牌色,当前与 mono 相同(保留参数是为了与
+ * ClaudeMark/CodexMark 的调用面一致,出现官方色后只改这里)。
+ */
+
+interface PiMarkProps {
+ size?: number;
+ className?: string;
+ variant?: 'mono' | 'brand';
+}
+
+export function PiMark({ size = 14, className }: PiMarkProps) {
+ return (
+ <svg
+ width={size}
+ height={size}
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ className={className}
+ aria-hidden
+ >
+ <g fill="currentColor">
+ {/* 横梁 */}
+ <rect x="3" y="5" width="18" height="3.4" rx="1.2" />
+ {/* 左腿(直) */}
+ <rect x="6.4" y="7.2" width="3.4" height="11.8" rx="1.2" />
+ {/* 右腿(底部外撇一点,呼应手写 π 的收笔) */}
+ <path d="M14.4 7.2h3.4v9.2c0 .9.4 1.4 1.2 1.4h.6c.3 0 .4.14.4.42v1.36c0 .28-.14.42-.42.42h-1.3c-2.5 0-3.88-1.3-3.88-3.7V7.2Z" />
+ </g>
+ </svg>
+ );
+}
diff --git a/apps/desktop/src/renderer/components/new-chat/VendorSegmentedSwitcher.tsx b/apps/desktop/src/renderer/components/new-chat/VendorSegmentedSwitcher.tsx
index 435bfcc7f6..41d6f9dbae 100644
--- a/apps/desktop/src/renderer/components/new-chat/VendorSegmentedSwitcher.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/VendorSegmentedSwitcher.tsx
@@ -20,6 +20,7 @@ import { cn } from '@/lib/utils';
import type { MakerVendor } from '@/lib/ccAgent.types';
import { CodexMark } from '@/components/icons/CodexMark';
import { ClaudeMark } from '@/components/icons/ClaudeMark';
+import { PiMark } from '@/components/icons/PiMark';
interface VendorSegmentedSwitcherProps {
value: MakerVendor;
@@ -62,6 +63,7 @@ interface SegmentOption {
const OPTIONS: readonly SegmentOption[] = [
{ vendor: 'cc', label: 'Claude', Mark: ClaudeMark },
{ vendor: 'codex', label: 'Codex', Mark: CodexMark },
+ { vendor: 'pi', label: 'Pi', Mark: PiMark },
] as const;
export function VendorSegmentedSwitcher({
diff --git a/apps/desktop/src/renderer/components/settings/__tests__/WorkspacePrefsEditorRendering.test.tsx b/apps/desktop/src/renderer/components/settings/__tests__/WorkspacePrefsEditorRendering.test.tsx
index 20b6ef84a8..e2807ed677 100644
--- a/apps/desktop/src/renderer/components/settings/__tests__/WorkspacePrefsEditorRendering.test.tsx
+++ b/apps/desktop/src/renderer/components/settings/__tests__/WorkspacePrefsEditorRendering.test.tsx
@@ -270,7 +270,7 @@ describe('WorkspacePrefsEditor 复用标准选择器', () => {
render(<WorkspacePrefsEditor alias="cindy" state={stateWith({ editable: false })} />);
const tabs = screen.getAllByRole('tab');
- expect(tabs.length).toBe(2);
+ expect(tabs.length).toBe(3);
for (const tab of tabs) expect((tab as HTMLButtonElement).disabled).toBe(true);
tabs.find((t) => t.getAttribute('aria-selected') === 'false')?.click();
diff --git a/apps/desktop/src/renderer/components/status/TodaySpendChip.tsx b/apps/desktop/src/renderer/components/status/TodaySpendChip.tsx
index 10b8b538c7..7ee36a831d 100644
--- a/apps/desktop/src/renderer/components/status/TodaySpendChip.tsx
+++ b/apps/desktop/src/renderer/components/status/TodaySpendChip.tsx
@@ -1001,7 +1001,7 @@ function renderSegmentedLabel(segments: React.ReactNode[]): React.ReactNode {
}
interface TodaySpendChipProps {
- vendorKey?: 'cc' | 'codex';
+ vendorKey?: 'cc' | 'codex' | 'pi';
/** 当前会话模型;codex/ 折扣 GPT 恒走 gateway API, 即使 oauth-bearer spawn 也按 API 形态显示。 */
modelId?: string | null;
/**
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
index 4a753e9ccc..937701021b 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx
@@ -24,6 +24,7 @@ import {
} from 'react';
import type { CSSProperties, ReactNode } from 'react';
import { useLocation, useNavigate, useOutletContext, useParams } from 'react-router-dom';
+import { normalizeDbAgentKind } from '../../../shared/agentKindConversion';
import { useTranslation } from 'react-i18next';
import type { AgentInputReference } from '@cindy/maker-shared/agent-input-projection';
import {
@@ -1914,8 +1915,9 @@ export function CCAgentSessionView({
.then((workers) => {
if (cancelled || workers.length === 0) return;
const activeWorker = workers[0]; // MVP: 假设最多 1 个 active Worker
- const kind: 'cc' | 'codex' = activeWorker.session?.agentKind === 'codex' ? 'codex' : 'cc';
- setCollabWorker(kind);
+ // orca worker 创建面未开 pi;万一读到脏值也按 codex 收敛,不撑开 toggle 契约。
+ const normalizedKind = normalizeDbAgentKind(activeWorker.session?.agentKind);
+ setCollabWorker(normalizedKind === 'cc' ? 'cc' : 'codex');
})
.catch(() => undefined);
return () => {
@@ -2005,8 +2007,8 @@ export function CCAgentSessionView({
: Promise.resolve();
try {
const workerAgent = form.agent;
- const worker: 'cc' | 'codex' = workerAgent === 'codex' ? 'codex' : 'cc';
- setCollabWorker(worker);
+ const normalizedWorker = normalizeDbAgentKind(workerAgent);
+ setCollabWorker(normalizedWorker === 'cc' ? 'cc' : 'codex');
setCreateWorkerOpen(false);
// 粘滞归属(codex review P2):入口与协同策略查询都按粘滞 remoteDeviceId 指向被控端,
// mutation 必须同口径 —— 非粘滞的 makerApiFor 在 relay 瞬断窗口内会退回本机
@@ -3761,7 +3763,7 @@ export function CCAgentSessionView({
</Tip>
)}
<TodaySpendChip
- vendorKey={displayAgentKind === 'codex' ? 'codex' : 'cc'}
+ vendorKey={normalizeDbAgentKind(displayAgentKind)}
modelId={agentSwitchIntent?.model ?? session?.model ?? null}
providerId={
agentSwitchIntent
@@ -3778,7 +3780,7 @@ export function CCAgentSessionView({
<ContextCapacityRing
contextTokens={agentStatus.contextTokens}
model={agentSwitchIntent?.model ?? session?.model ?? ''}
- vendorKey={displayAgentKind === 'codex' ? 'codex' : 'cc'}
+ vendorKey={normalizeDbAgentKind(displayAgentKind)}
sdkContextWindow={agentStatus.contextWindow}
deviceId={remoteDeviceId}
onCompact={
@@ -4239,7 +4241,7 @@ function formatTokenCount(n: number): string {
*/
function getModelContextWindow(
model: string,
- vendorKey: 'cc' | 'codex',
+ vendorKey: 'cc' | 'codex' | 'pi',
deviceId?: string,
): number | undefined {
const found = getModelsForVendor(vendorKey, deviceId).find((m) => m.id === model);
@@ -4256,7 +4258,7 @@ function ContextCapacityRing({
}: {
contextTokens: number;
model: string;
- vendorKey: 'cc' | 'codex';
+ vendorKey: 'cc' | 'codex' | 'pi';
/** SDK-reported context window; 0 = not yet known → use hardcoded fallback. */
sdkContextWindow: number;
/** device-link 远程会话所属被控端 id;按被控端能力查 contextWindow(本机会话 undefined,行为不变)。 */
diff --git a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
index 6720541f9a..3fc1e0bdcb 100644
--- a/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/NewMakerDraftRoute.tsx
@@ -64,6 +64,7 @@ import { InheritedSubscriptionNotice } from '@/components/onboarding/InheritedSu
import { resolveDeviceLinkSubmission } from './deviceLinkCreateArgs';
import { commitRemoteSessionHandoff } from './remoteSessionHandoff';
import { VendorSegmentedSwitcher } from '@/components/new-chat/VendorSegmentedSwitcher';
+import { dbToMakerAgentKind, normalizeDbAgentKind } from '../../../shared/agentKindConversion';
import { TopRightChipStack, TopRightChipStackProvider } from '@/components/chat/TopRightChipStack';
import { useProportionalWidth } from '@/hooks/useProportionalWidth';
import { useCCSessions } from '@/hooks/useCCSessions';
@@ -560,9 +561,9 @@ export function NewMakerDraftRoute() {
// 当前 vendor 对应的 prefs(切 vendor 后这里自动重算 → 透传到 ChatInput initial*)
const currentPrefs = draft.lastByVendor[draft.vendor];
const chatPrefs = currentPrefs;
- const persistedAgentKind: 'cc' | 'codex' = draft.vendor === 'codex' ? 'codex' : 'cc';
- const authVendor: 'cc' | 'codex' = persistedAgentKind;
- const capabilityAgentKind = persistedAgentKind === 'codex' ? 'codex' : 'claude-code';
+ const persistedAgentKind: 'cc' | 'codex' | 'pi' = normalizeDbAgentKind(draft.vendor);
+ const authVendor: 'cc' | 'codex' | 'pi' = persistedAgentKind;
+ const capabilityAgentKind = dbToMakerAgentKind(persistedAgentKind);
// 品牌区跟随当前主题;icon / logo 的固定布局统一由 ThemeBrandLockup 负责。
const [activeColorTheme, setActiveColorTheme] = useState<ColorTheme | null>(() =>
@@ -1546,7 +1547,7 @@ export function NewMakerDraftRoute() {
const handleRemoteProjectAdded = useCallback(
async (target: RemoteProjectTarget) => {
// vendor 由外层 VendorSegmentedSwitcher (draft.vendor) 单一决策 —— dialog 不再让用户选。
- const draftVendor: 'cc' | 'codex' = draft.vendor === 'codex' ? 'codex' : 'cc';
+ const draftVendor: 'cc' | 'codex' | 'pi' = normalizeDbAgentKind(draft.vendor);
if (target.kind === 'device-link') {
// device-link:**不**像 SSH 立即建会话(会在被控端留空会话)。改为把当前草稿指向该被控
@@ -1658,7 +1659,7 @@ export function NewMakerDraftRoute() {
}
if (effectivePlanMode) patchCurrentVendorPrefs({ planMode: false });
makerChatStore.setSessionRuntime(newSession.id, {
- agentKind: draftVendor === 'codex' ? 'codex' : 'claude-code',
+ agentKind: dbToMakerAgentKind(draftVendor),
fastMode: sshFastMode,
planModeEnabled: effectivePlanMode,
});
diff --git a/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts b/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts
index a9ff65f6aa..58e51b232f 100644
--- a/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts
+++ b/apps/desktop/src/renderer/features/cc-agent/deviceLinkCreateArgs.ts
@@ -23,8 +23,8 @@ import type { AgentKind } from '@/hooks/useAgentCapabilities';
import type { Effort, PermissionMode } from '@/lib/userPreferences.types';
export interface DeviceLinkCreateParams {
- /** 草稿 vendor 形态:'cc' | 'codex'(persistedAgentKind)。 */
- agentKind: 'cc' | 'codex';
+ /** 草稿 vendor 形态:'cc' | 'codex' | 'pi'(persistedAgentKind)。 */
+ agentKind: 'cc' | 'codex' | 'pi';
/**
* 被控端上的项目目录。缺省 / 空白 = 在该设备上建**不绑项目的 standalone dialogue**,
* workspaceKind 随之派生为 'dialogue',运行目录由被控端分配。
diff --git a/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts b/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts
index 2ef92c8e1a..b3be2751b3 100644
--- a/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts
+++ b/apps/desktop/src/renderer/features/scheduler/lib/scheduleFormLogic.ts
@@ -263,9 +263,11 @@ export function applyRunMode(
/** renderer Session.agentKind('cc'|'codex')→ schedule agentKind 映射。 */
export function sessionAgentKindToScheduleAgentKind(
- kind: 'cc' | 'codex',
+ kind: 'cc' | 'codex' | 'pi',
): ScheduleFormState['agentKind'] {
- return kind === 'codex' ? 'codex' : 'claude-code';
+ if (kind === 'codex') return 'codex';
+ if (kind === 'pi') return 'pi';
+ return 'claude-code';
}
interface TemplateAgentDefaults {
diff --git a/apps/desktop/src/renderer/lib/ccAgent.types.ts b/apps/desktop/src/renderer/lib/ccAgent.types.ts
index b502ff6526..1c5e7f87ad 100644
--- a/apps/desktop/src/renderer/lib/ccAgent.types.ts
+++ b/apps/desktop/src/renderer/lib/ccAgent.types.ts
@@ -13,7 +13,7 @@ export type DeviceLinkConnectionStatus = 'connected' | 'disconnected';
* 暂时只有 'cc'(Claude Code)。未来扩展 'codex' 等时新增枚举值即可,
* schema 不动;老 session DEFAULT 'cc' 兜底。
*/
-export type AgentKind = 'cc' | 'codex';
+export type AgentKind = 'cc' | 'codex' | 'pi';
export type MakerVendor = AgentKind | 'orca';
export type OrcaRole = 'lead' | 'worker';
@@ -342,6 +342,6 @@ export interface Message {
* session-agent-switch 后 session.agentKind 只代表当前活跃引擎,历史行按本字段解析;
* null = 切换功能上线前的老消息(回落 session.agentKind)。
*/
- agentKind?: 'cc' | 'codex' | null;
+ agentKind?: 'cc' | 'codex' | 'pi' | null;
createdAt: string; // ISO 8601
}
diff --git a/apps/desktop/src/renderer/lib/modelDefinitions.ts b/apps/desktop/src/renderer/lib/modelDefinitions.ts
index 8798a3d04e..11380875c0 100644
--- a/apps/desktop/src/renderer/lib/modelDefinitions.ts
+++ b/apps/desktop/src/renderer/lib/modelDefinitions.ts
@@ -17,7 +17,7 @@ export interface ModelDefinition {
description: string;
efforts: readonly Effort[];
defaultEffort: Effort | null;
- vendorKey: 'cc' | 'codex';
+ vendorKey: 'cc' | 'codex' | 'pi';
contextWindow?: number;
supportsFastMode?: boolean;
/** 目录展示排序;缺省排末尾(见 getDefaultModelForVendor)。 */
@@ -26,7 +26,7 @@ export interface ModelDefinition {
defaultEnabled?: boolean;
}
-function toLegacy(m: ModelDescriptor, vendorKey: 'cc' | 'codex'): ModelDefinition {
+function toLegacy(m: ModelDescriptor, vendorKey: 'cc' | 'codex' | 'pi'): ModelDefinition {
return {
id: m.id,
label: m.displayName,
@@ -97,7 +97,7 @@ export function getModelById(modelId: string, deviceId?: string): ModelDefinitio
}
export function getModelsForVendor(
- vendorKey: 'cc' | 'codex',
+ vendorKey: 'cc' | 'codex' | 'pi',
deviceId?: string,
): readonly ModelDefinition[] {
return allCachedModels(deviceId).filter((m) => m.vendorKey === vendorKey);
@@ -135,7 +135,7 @@ function firstByCatalogOrder(models: readonly ModelDefinition[]): ModelDefinitio
* 自动化任务(scheduler)的默认**故意不同**:无人值守场景成本保守,走 useScheduleForm.ts
* getScheduleDefaultModel 三级回退(冷启动 Sonnet),不要把这里的默认接到 scheduler 上。
*/
-export function getDefaultModelForVendor(vendorKey: 'cc' | 'codex', deviceId?: string): ModelDefinition {
+export function getDefaultModelForVendor(vendorKey: 'cc' | 'codex' | 'pi', deviceId?: string): ModelDefinition {
const list = getModelsForVendor(vendorKey, deviceId);
// capabilities 还没拉到时退化到一个静态 placeholder, 让调用方拿到非 undefined。
// 调用方真正需要值时通常已经在 useEffect 后, capabilities 已就绪。
diff --git a/apps/desktop/src/renderer/lib/sessionService.ts b/apps/desktop/src/renderer/lib/sessionService.ts
index a3f3daad2b..1eafe17853 100644
--- a/apps/desktop/src/renderer/lib/sessionService.ts
+++ b/apps/desktop/src/renderer/lib/sessionService.ts
@@ -56,7 +56,7 @@ export async function create(body?: {
fastMode?: boolean;
/** 计划模式一级开关(与 permissionMode 正交); 草稿开着计划模式时随建会话落库。 */
planModeEnabled?: boolean;
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
orcaRole?: OrcaRole | null;
/** 附加只读引用目录列表 (绝对路径); main 端 mapper 会 JSON.stringify 后写库。 */
extraDirs?: string[];
diff --git a/apps/desktop/src/renderer/state/newMakerDraft.ts b/apps/desktop/src/renderer/state/newMakerDraft.ts
index d6bb2e345e..58fa5271fe 100644
--- a/apps/desktop/src/renderer/state/newMakerDraft.ts
+++ b/apps/desktop/src/renderer/state/newMakerDraft.ts
@@ -157,6 +157,18 @@ export interface NewMakerDraft {
* 在目录里都是默认隐藏的模型 —— 种子默认模型压根不在用户看到的清单里。
*/
function defaultVendorPrefs(vendor: MakerVendor): VendorPrefs {
+ if (vendor === 'pi') {
+ return {
+ // pi 走 XD 网关(anthropic-messages 可达面),默认给网关中档模型;
+ // 目录未含该 id 时由 ChatInput 的 vendor 回退逻辑纠正。
+ model: 'claude-sonnet-5',
+ effort: 'high',
+ // pi 当前 capabilities 仅暴露完全访问档(ask 档随 cindy-bridge extension 上线)。
+ permissionMode: 'bypassPermissions',
+ planMode: false,
+ providerId: null,
+ };
+ }
if (vendor === 'codex') {
return {
model: getDefaultModelForVendor('codex').id,
@@ -198,6 +210,7 @@ function makeDefault(): NewMakerDraft {
extraDirs: [],
lastByVendor: {
cc: defaultVendorPrefs('cc'),
+ pi: defaultVendorPrefs('pi'),
orca: defaultVendorPrefs('orca'),
codex: defaultVendorPrefs('codex'),
},
@@ -231,7 +244,7 @@ function sanitize(raw: unknown): NewMakerDraft {
// F-COLLAB (2026-05): 'orca' vendor 已被 ChatInput 底部的 toggle 取代,
// sanitize 时把历史 localStorage 残留的 'orca' 自动迁移到 'cc',避免空白入口。
const vendor: MakerVendor =
- r.vendor === 'codex' ? 'codex' : 'cc';
+ r.vendor === 'codex' || r.vendor === 'pi' ? r.vendor : 'cc';
const workingDir = normalizeDraftWorkingDir(r.workingDir);
const remoteHostId =
typeof r.remoteHostId === 'string' && r.remoteHostId.trim().length > 0
@@ -363,6 +376,7 @@ function sanitize(raw: unknown): NewMakerDraft {
extraDirs,
lastByVendor: {
cc: sanitizeVendorPrefs(lastByVendorRaw.cc, 'cc'),
+ pi: sanitizeVendorPrefs(lastByVendorRaw.pi, 'pi'),
orca: sanitizeVendorPrefs(lastByVendorRaw.orca, 'orca'),
codex: sanitizeVendorPrefs(lastByVendorRaw.codex, 'codex'),
},
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index beaf777e9a..197fccf3f1 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -112,7 +112,7 @@ interface DeviceLinkPresenceSnapshot {
/** .cshare 导入向导的预览数据(main 侧 SharePreview 的镜像)。 */
interface SessionSharePreview {
title: string;
- agentKind: 'cc' | 'codex';
+ agentKind: 'cc' | 'codex' | 'pi';
workspaceKind: 'project' | 'dialogue';
originalWorkingDir: string | null;
exportedAt: string;
@@ -1860,7 +1860,7 @@ interface ElectronAPI {
syncNewMakerDraft: (snapshot: {
lastByVendor: Partial<
Record<
- 'cc' | 'codex',
+ 'cc' | 'codex' | 'pi',
{ model?: string; effort?: string; permissionMode?: string; providerId?: string | null }
>
>;
@@ -3424,7 +3424,7 @@ interface ElectronAPI {
permissionMode?: string;
fastMode?: boolean;
planModeEnabled?: boolean;
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
orcaRole?: import('@/lib/ccAgent.types').OrcaRole | null;
/** 附加只读引用目录列表 (绝对路径); main 端 mapper 会 JSON.stringify 后写库。 */
extraDirs?: string[];
diff --git a/apps/desktop/src/shared/agentKindConversion.ts b/apps/desktop/src/shared/agentKindConversion.ts
new file mode 100644
index 0000000000..e66b72f0e1
--- /dev/null
+++ b/apps/desktop/src/shared/agentKindConversion.ts
@@ -0,0 +1,31 @@
+/**
+ * agentKindConversion —— DB/renderer 形态('cc' | 'codex' | 'pi')与 maker-core
+ * 形态('claude-code' | 'codex' | 'pi')的唯一双向映射。
+ *
+ * 背景:sessions.agent_kind 历史上存 renderer 形态('cc' 起家,default 'cc'),
+ * maker-core 用 'claude-code'。三值化前全仓散落 `x === 'cc' ? 'claude-code' :
+ * 'codex'` 这类二元 ternary —— pi 进来后每一处都会把 pi 误判成另一家。
+ * 一律改走本模块;新增 agent 只改这里。
+ */
+
+/** DB(sessions.agent_kind)与 renderer 侧的 agent 形态。 */
+export type DbAgentKind = 'cc' | 'codex' | 'pi';
+/** maker-core / IPC 契约侧的 agent 形态。 */
+export type MakerAgentKindWire = 'claude-code' | 'codex' | 'pi';
+
+export function dbToMakerAgentKind(db: string | null | undefined): MakerAgentKindWire {
+ if (db === 'codex') return 'codex';
+ if (db === 'pi') return 'pi';
+ return 'claude-code'; // 'cc' 与历史缺省
+}
+
+export function makerToDbAgentKind(maker: string | null | undefined): DbAgentKind {
+ if (maker === 'codex') return 'codex';
+ if (maker === 'pi') return 'pi';
+ return 'cc'; // 'claude-code' 与历史缺省
+}
+
+/** 宽输入归一成 DbAgentKind;非法值回落 'cc'(与 sessions 表 default 同语义)。 */
+export function normalizeDbAgentKind(value: string | null | undefined): DbAgentKind {
+ return value === 'codex' || value === 'pi' ? value : 'cc';
+}
diff --git a/apps/desktop/src/shared/conversationSearch.ts b/apps/desktop/src/shared/conversationSearch.ts
index 40e4836e4c..1e886a7b9a 100644
--- a/apps/desktop/src/shared/conversationSearch.ts
+++ b/apps/desktop/src/shared/conversationSearch.ts
@@ -2,7 +2,7 @@ import { projectDraftSessionTitle } from '@cindy/maker-shared/session-title';
import type { SessionSource } from './sessionSource';
-export type ConversationSearchAgentKind = 'cc' | 'codex';
+export type ConversationSearchAgentKind = 'cc' | 'codex' | 'pi';
export type ConversationSearchWorkspaceKind = 'project' | 'dialogue';
export type ConversationSearchSessionStatus = 'active' | 'archived' | 'deleted';
export type ConversationSearchOrcaRole = 'lead' | 'worker';
diff --git a/apps/desktop/src/shared/sessionReference.ts b/apps/desktop/src/shared/sessionReference.ts
index 15d77aba69..f700cd51d8 100644
--- a/apps/desktop/src/shared/sessionReference.ts
+++ b/apps/desktop/src/shared/sessionReference.ts
@@ -10,5 +10,5 @@ export interface SessionReference {
state: 'available' | 'deleted' | 'missing';
status?: 'active' | 'archived' | 'deleted';
title?: string;
- agentKind?: 'cc' | 'codex';
+ agentKind?: 'cc' | 'codex' | 'pi';
}
diff --git a/packages/lizi-mcps/src/xdt-helper/_history_types.ts b/packages/lizi-mcps/src/xdt-helper/_history_types.ts
index 4a43835f86..38d62ed159 100644
--- a/packages/lizi-mcps/src/xdt-helper/_history_types.ts
+++ b/packages/lizi-mcps/src/xdt-helper/_history_types.ts
@@ -8,7 +8,7 @@
import type { ControlResult } from '../types.js';
-export type HistoryAgentKind = 'cc' | 'codex';
+export type HistoryAgentKind = 'cc' | 'codex' | 'pi';
export type HistoryOrder = 'asc' | 'desc';
/** Stable business errors exposed by cross-device history readers. */