Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(agent-island): 主力电脑在其他设备上的伙伴也显示在本机灵动岛
Dash381b49c3e74a
diff --git a/apps/desktop/src/main/agent-island/companionIdentity.ts b/apps/desktop/src/main/agent-island/companionIdentity.tsindex 3c7a4e8e17..8c22392ca7 100644--- a/apps/desktop/src/main/agent-island/companionIdentity.ts+++ b/apps/desktop/src/main/agent-island/companionIdentity.ts@@ -54,48 +54,70 @@ export async function readAgentIslandCompanion(sessionId: string): Promise<Agentconst group = groupId? await db.select({ name: botGroups.name }).from(botGroups).where(eq(botGroups.id, groupId)).get(): undefined;- const avatar = row.avatar.trim();- const emoji = isSingleBotAvatarGrapheme(avatar) ? avatar : null;- const imageJpeg = emoji ? undefined : await avatarThumbnail(avatar);const groupName = group?.name.trim();+ const base = companionSnapshotWithoutArtwork({ name: row.name, avatar: row.avatar, avatarColor: row.avatarColor, groupName });+ const imageJpeg = companionAvatarHasArtwork(row.avatar) ? await companionAvatarThumbnail(row.avatar) : undefined;+ return { botId: row.botId, companion: imageJpeg ? { ...base, imageJpeg } : base };+}++/** Name, tint and glyph: everything but the artwork, available without any read. */+export function companionSnapshotWithoutArtwork(identity: {+ name: string;+ avatar: string;+ avatarColor: string;+ groupName?: string;+}): AgentIslandCompanionSnapshot {+ const avatar = identity.avatar.trim();+ const emoji = isSingleBotAvatarGrapheme(avatar) ? avatar : null;return {- botId: row.botId,- companion: {- name: row.name,- ...(groupName ? { groupName } : {}),- hue: normalizeBotAvatarHue(row.avatarColor),- ...(imageJpeg ? { imageJpeg } : {}),- glyph: emoji ?? botAvatarInitial(row.name),- glyphIsInitial: !emoji,- },+ name: identity.name,+ ...(identity.groupName ? { groupName: identity.groupName } : {}),+ hue: normalizeBotAvatarHue(identity.avatarColor),+ glyph: emoji ?? botAvatarInitial(identity.name),+ glyphIsInitial: !emoji,};}-function avatarThumbnail(avatar: string): Promise<string | undefined> {- const cached = thumbnails.get(avatar);+export function companionAvatarHasArtwork(avatar: string): boolean {+ return !isSingleBotAvatarGrapheme(avatar.trim());+}++/**+ * Bounded JPEG of the companion's artwork. `deviceId` names the computer that holds a+ * `cindy-media://` avatar of a companion running elsewhere; it is read through this+ * computer's companion avatar copy, the same one the roster shows.+ */+export function companionAvatarThumbnail(avatar: string, deviceId?: string | null): Promise<string | undefined> {+ const key = `${deviceId ?? ''}\n${avatar.trim()}`;+ const cached = thumbnails.get(key);if (cached) return cached;- const pending = encodeAvatarThumbnail(avatar).catch(() => undefined);- thumbnails.set(avatar, pending);+ const pending = encodeAvatarThumbnail(avatar.trim(), deviceId ?? null).catch(() => undefined);+ thumbnails.set(key, pending);if (thumbnails.size > THUMBNAIL_CACHE_LIMIT) thumbnails.delete(thumbnails.keys().next().value!);// Artwork is optional: a failed read falls back to the glyph and retries on the next lookup.- void pending.then((value) => { if (!value && thumbnails.get(avatar) === pending) thumbnails.delete(avatar); });+ void pending.then((value) => { if (!value && thumbnails.get(key) === pending) thumbnails.delete(key); });return pending;}-async function encodeAvatarThumbnail(avatar: string): Promise<string | undefined> {- const bytes = await readAvatarBytes(avatar);+async function encodeAvatarThumbnail(avatar: string, deviceId: string | null): Promise<string | undefined> {+ const bytes = await readAvatarBytes(avatar, deviceId);if (!bytes) return undefined;const encoded = await encodeNotificationAvatar(bytes, sharp);return encoded?.kind === 'jpeg' ? encoded.value : undefined;}-async function readAvatarBytes(avatar: string): Promise<Buffer | undefined> {+async function readAvatarBytes(avatar: string, deviceId: string | null): Promise<Buffer | undefined> {const preset = PRESET_AVATAR_FILES[avatar.toLowerCase()];if (preset) {const root = app.isPackaged ? process.resourcesPath : path.join(app.getAppPath(), 'resources');return readFile(path.join(root, preset));}- if (!isManagedBotAvatarUrl(avatar)) return undefined;- const bytes = await readFile(resolveSafe(avatar).absPath);+ let local: string | null = isManagedBotAvatarUrl(avatar) && !deviceId ? avatar : null;+ if (!local && (deviceId || avatar.startsWith('https://'))) {+ const { companionAvatarCache } = await import('../companion-cloud/avatarCacheHost.js');+ local = await companionAvatarCache.resolve({ avatar, deviceId, fetch: true });+ }+ if (!local || !isManagedBotAvatarUrl(local)) return undefined;+ const bytes = await readFile(resolveSafe(local).absPath);return bytes.length > BOT_AVATAR_MAX_BYTES ? undefined : bytes;}diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.tsindex 18f6b9a9b4..fcb356391a 100644--- a/apps/desktop/src/main/agent-island/service.ts+++ b/apps/desktop/src/main/agent-island/service.ts@@ -76,7 +76,13 @@ import {type AgentIslandScreenLayoutMetrics,} from '../../shared/agentIsland.js';import { getSessionRowSnapshot } from '../localDb/ipc/sessions.js';-import { readAgentIslandCompanion, type AgentIslandCompanionIdentity } from './companionIdentity.js';+import {+ companionAvatarHasArtwork,+ companionAvatarThumbnail,+ companionSnapshotWithoutArtwork,+ readAgentIslandCompanion,+ type AgentIslandCompanionIdentity,+} from './companionIdentity.js';import { createLogger } from '../logger.js';import { t } from '../i18n.js';import { isAppContentWindow, isFocusedAppContentWindow } from '../windowFocusClassifier.js';@@ -164,6 +170,7 @@ const REMOTE_AUTH_ERROR_FALLBACK_MS = 30_000;// 点击卡片到主窗导航落地之间可能隔着一次 renderer 冷加载,与主窗导航保留同量级。const ISLAND_ENTRY_ALERT_TTL_MS = 60_000;const MAX_ISLAND_ENTRY_SESSION_ID_LENGTH = 128;+const REMOTE_COMPANION_CACHE_LIMIT = 64;const MAX_ISLAND_ENTRY_ID_LENGTH = 32;interface AgentIslandSessionMeta {@@ -325,6 +332,8 @@ export class AgentIslandService {private publishTimer: ReturnType<typeof setTimeout> | null = null;private readonly metadataCache = new Map<string, AgentIslandCachedMetadata>();private readonly metadataLoading = new Set<string>();+ private readonly remoteCompanions = new Map<string, AgentIslandCompanionSnapshot>();+ private lastDeviceSessionInputs: readonly AgentIslandRemoteSessionInput[] = [];private readonly layoutPreferencesByDisplayId: Map<number, AgentIslandLayoutPreference>;private readonly detachedLayoutPreferences: AgentIslandLayoutPreference[];private nativeFailureLogged = false;@@ -707,8 +716,14 @@ export class AgentIslandService {* 本机活动快照,也就不会被 relay 当作本机任务再推给控制端。*/setDeviceSessions(inputs: readonly AgentIslandRemoteSessionInput[]): void {+ this.lastDeviceSessionInputs = inputs;setAgentIslandStrings(this.state, buildAgentIslandStrings());- const result = syncAgentIslandDeviceSessions(this.state, inputs, Date.now());+ const result = syncAgentIslandDeviceSessions(+ this.state,+ inputs,+ Date.now(),+ (input) => this.remoteCompanionSnapshot(input),+ );for (const input of inputs) {if (input.phase === 'completed' && input.completionNotification === 'silent') {this.mutedCompletionSoundSessionIds.add(input.sessionId);@@ -729,6 +744,32 @@ export class AgentIslandService {}}+ /**+ * A remote companion's identity is drawn at once with its tint and glyph; its artwork is+ * read through this computer's avatar copy and swapped in when ready. One object per+ * identity, so an unchanged companion never republishes the island.+ */+ private remoteCompanionSnapshot(input: AgentIslandRemoteSessionInput): AgentIslandCompanionSnapshot | null {+ const identity = input.companion;+ if (!identity) return null;+ const key = JSON.stringify([input.deviceId, identity.name, identity.avatar, identity.avatarColor]);+ const cached = this.remoteCompanions.get(key);+ if (cached) return cached;+ const base = companionSnapshotWithoutArtwork(identity);+ this.remoteCompanions.set(key, base);+ if (this.remoteCompanions.size > REMOTE_COMPANION_CACHE_LIMIT) {+ this.remoteCompanions.delete(this.remoteCompanions.keys().next().value!);+ }+ if (identity.avatar && companionAvatarHasArtwork(identity.avatar)) {+ void companionAvatarThumbnail(identity.avatar, input.deviceId).then((imageJpeg) => {+ if (!imageJpeg || this.remoteCompanions.get(key) !== base) return;+ this.remoteCompanions.set(key, { ...base, imageJpeg });+ this.setDeviceSessions(this.lastDeviceSessionInputs);+ });+ }+ return base;+ }+waitForCompletionNotification(sessionId: string): Promise<boolean> | undefined {return this.sessionActivityRelay.waitForCompletionNotification(sessionId);}@@ -746,6 +787,8 @@ export class AgentIslandService {this.emitSessionActivityTransitions([], Date.now());this.metadataCache.clear();this.metadataLoading.clear();+ this.remoteCompanions.clear();+ this.lastDeviceSessionInputs = [];this.lastSoundDisplayState = null;this.soundCooldownUntilByEvent.clear();this.silencedRunSessionIds.clear();diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.tsindex b99219c976..2b278c5c9a 100644--- a/apps/desktop/src/main/agent-island/state.ts+++ b/apps/desktop/src/main/agent-island/state.ts@@ -1153,6 +1153,8 @@ export function syncAgentIslandDeviceSessions(state: AgentIslandState,inputs: readonly AgentIslandRemoteSessionInput[],now: number,+ /** Display identity of a remote companion chat; must return a stable object per identity. */+ resolveCompanion: (input: AgentIslandRemoteSessionInput) => AgentIslandCompanionSnapshot | null = () => null,): AgentIslandDeviceSessionSyncResult {const result: AgentIslandDeviceSessionSyncResult = { changed: false, baselineSessionIds: [], events: [] };const incoming = new Map(inputs.map((input) => [input.sessionId, input]));@@ -1173,7 +1175,7 @@ export function syncAgentIslandDeviceSessions(result.baselineSessionIds.push(input.sessionId);result.changed = true;}- if (applyDeviceSessionMeta(session, input)) result.changed = true;+ if (applyDeviceSessionMeta(session, input, resolveCompanion(input))) result.changed = true;const waitingForCompletionNotification = session.pendingDeviceCompletionNotification === true;const transition = applyDeviceSessionPhase(state, session, input, previous, now);if (input.phase === 'completed') {@@ -1200,14 +1202,20 @@ export function syncAgentIslandDeviceSessions(function applyDeviceSessionMeta(session: AgentIslandSessionState,input: AgentIslandRemoteSessionInput,+ companion: AgentIslandCompanionSnapshot | null,): boolean {- const project = projectNameFromWorkingDir(input.workingDir, input.workspaceKind);+ // A companion's home folder on that computer is not a project; its group is the context.+ const project = companion+ ? companion.groupName ?? null+ : projectNameFromWorkingDir(input.workingDir, input.workspaceKind);const projectName = [project, input.deviceName].filter(Boolean).join(' · ') || null;const agentKind = dbToMakerAgentKind(input.agentKind);const changed = session.title !== input.title+ || session.companion !== companion|| session.projectName !== projectName|| session.agentKind !== agentKind;session.title = input.title;+ session.companion = companion;session.projectName = projectName;session.agentKind = agentKind;return changed;diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsxindex f73660b053..b6a28a6d99 100644--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx@@ -108,7 +108,8 @@ import { makeFolderPickerNewMakerRouteState } from '@/features/cc-agent/lib/newMimport { makeGenericNewMakerRouteState } from '@/features/cc-agent/lib/genericNewMakerRouteState';import { resolveSessionRoute } from '@/lib/orcaSessionIdentity';import { ensureBotProfilesLoaded, getBotProfiles } from '@/features/bots/botStore';-import { botRouteForOwnedSession, createSessionEntryNavigator, resolveBotRouteForSessionEntry } from '@/features/bots/botSessionOwners';+import { botRouteForOwnedSession, createSessionEntryNavigator, remoteBotRouteForSession, resolveBotRouteForSessionEntry } from '@/features/bots/botSessionOwners';+import { readRemoteBots } from '@/features/bots/useRemoteBots';import { useSessionEntryLocationCommits } from '@/features/bots/useSessionEntryLocationCommits';import { islandEntryRouteState, requestIslandEntryAlertDisposal } from '@/features/bots/islandEntryAlert';import { requestProviderShareJoin } from '@/features/provider-share/joinIntent';@@ -564,7 +565,8 @@ export function MainLayout() {// One navigator for the layout's lifetime: its sequence must span re-renders so a// late lookup for an earlier notification cannot override a newer click.const [navigateToSession] = useState(() => createSessionEntryNavigator({- readKnownBotRoute: (sessionId) => botRouteForOwnedSession(getBotProfiles(), sessionId),+ readKnownBotRoute: (sessionId) => botRouteForOwnedSession(getBotProfiles(), sessionId)+ ?? remoteBotRouteForSession(readRemoteBots(), sessionId),resolveBotRoute: (sessionId) => resolveBotRouteForSessionEntry(sessionId, {readProfiles: getBotProfiles,loadProfiles: ensureBotProfilesLoaded,diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.tsindex 13a3ae9fd5..56bfc5ea80 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts@@ -17,6 +17,7 @@ import {buildBotSessionOwners,createSessionEntryNavigator,findBotProfileForSession,+ remoteBotRouteForSession,resolveBotRouteForSessionEntry,type BotSessionEntryTarget,} from '../botSessionOwners';@@ -134,6 +135,16 @@ describe('伙伴归属表', () => {});});+ // 主力电脑在另一台设备的伙伴不在本机投影里:此前灵动岛点击只能落到普通任务页。+ it('主力电脑在别的设备上的伙伴,点击回到那台设备的伙伴页', () => {+ const remote = [{ id: 'opus', deviceId: 'mac studio', sessionId: 's-remote' }];+ expect(remoteBotRouteForSession(remote, 's-remote')).toEqual({+ route: '/bots/remote/mac%20studio/opus',+ consumesAlert: false,+ });+ expect(remoteBotRouteForSession(remote, 's-other')).toBeNull();+ });+it('群专线回到它所在的群,点击即处置;缺群 id 的旧投影回伙伴主页', () => {const bot = profile({sessions: [diff --git a/apps/desktop/src/renderer/features/bots/botSessionOwners.ts b/apps/desktop/src/renderer/features/bots/botSessionOwners.tsindex a8ffce3f40..3ae4e3e146 100644--- a/apps/desktop/src/renderer/features/bots/botSessionOwners.ts+++ b/apps/desktop/src/renderer/features/bots/botSessionOwners.ts@@ -11,6 +11,7 @@import type { BotSessionOwner } from '@/features/cc-agent/lib/projectGrouping';import type { BotProfile } from './botStore';+import type { RemoteBot } from './remoteBotRoster';import { isBotGroupLaneSession } from './botGroupLane';/**@@ -87,6 +88,22 @@ export function botRouteForOwnedSession(return { route: `${botRoute}/session/${encodeURIComponent(sessionId)}`, consumesAlert: false };}+/**+ * A companion whose main computer is another device: its chat opens on that device's+ * companion page. Only its main chat is projected here, so that is all an entry can name.+ */+export function remoteBotRouteForSession(+ remoteBots: readonly Pick<RemoteBot, 'id' | 'deviceId' | 'sessionId'>[],+ sessionId: string,+): BotSessionEntryTarget | null {+ const bot = remoteBots.find((candidate) => candidate.sessionId === sessionId);+ if (!bot) return null;+ return {+ route: `/bots/remote/${encodeURIComponent(bot.deviceId)}/${encodeURIComponent(bot.id)}`,+ consumesAlert: false,+ };+}+type LoadedBotProfilesReader = () => readonly BotProfile[] | null;let loadedBotProfilesReader: LoadedBotProfilesReader | null = null;diff --git a/apps/desktop/src/renderer/features/bots/useRemoteBots.ts b/apps/desktop/src/renderer/features/bots/useRemoteBots.tsindex 6259fe0fa6..33c6b75ef2 100644--- a/apps/desktop/src/renderer/features/bots/useRemoteBots.ts+++ b/apps/desktop/src/renderer/features/bots/useRemoteBots.ts@@ -31,6 +31,11 @@ const subscribe = (fn: () => void) => {};const empty: RemoteBot[] = [];+/** Non-hook read for entry routing (island / notification clicks); empty while signed out. */+export function readRemoteBots(): readonly RemoteBot[] {+ return owner ? snapshot : empty;+}+export function useRemoteBots(): readonly RemoteBot[] {const { dataOwnerId, isAuthenticated } = useAuth();const rows = useSyncExternalStore(subscribe, () => snapshot);diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts b/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.tsindex 6f8904f87f..4a4d2eb804 100644--- a/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts+++ b/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts@@ -146,6 +146,36 @@ describe('buildAgentIslandRemoteSessionInputs', () => {);});+ // A companion whose main computer is another device never reached the island: its chat is a+ // hidden Bot Session, skipped with the task list. It is account-wide, so the task scope does not apply.+ it('shows a remote companion chat as the companion, whatever the task scope', () => {+ const bot = {+ id: 'opus', deviceId: 'device-a', deviceName: 'Mac Studio', name: 'Opus',+ avatar: 'cindy-media://blobs/' + 'a'.repeat(64) + '.png', avatarColor: 'teal',+ description: '', preview: '', activityAt: 1, sessionId: 'a-1', online: true,+ };+ const offline = { ...bot, id: 'away', sessionId: 'b-2', online: false };+ const inputs = buildAgentIslandRemoteSessionInputs(+ [remoteSession('a-1', 'device-a', { source: 'bot' })], [MACHINE_LOCAL], readActivity, [bot, offline],+ );+ // A local path is not a companion avatar value: it never reaches main.+ const parsed = parseAgentIslandRemoteSessions([+ ...inputs,+ { ...inputs[0], sessionId: 'x-1', companion: { name: 'X', avatar: '/etc/passwd', avatarColor: 'red' } },+ ]);+ expect(parsed?.[0]).toMatchObject({+ sessionId: 'a-1', deviceId: 'device-a', title: 'Opus', phase: 'running', detail: 'Reading files',+ companion: { name: 'Opus', avatar: bot.avatar, avatarColor: 'teal' },+ });+ expect(parsed?.map((input) => input.sessionId)).toEqual(['a-1', 'x-1']);+ expect(parsed?.[1]?.companion?.avatar).toBe('');++ const state = createAgentIslandState();+ const companion = { name: 'Opus', hue: 'teal' as const, glyph: 'O', glyphIsInitial: true };+ syncAgentIslandDeviceSessions(state, parsed!.slice(0, 1), 2_000, (input) => (input.companion ? companion : null));+ expect(state.sessions.get('a-1')).toMatchObject({ companion, title: 'Opus', projectName: 'Mac Studio' });+ });+it('skips Bot tasks and disconnected devices', () => {expect(buildAgentIslandRemoteSessionInputs(diff --git a/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts b/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.tsindex 8e91005db3..19a4056549 100644--- a/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts+++ b/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts@@ -4,11 +4,14 @@* ---------------------------------------------------------------------------* 范围跟侧栏「任务范围」走:只同步当前范围内、侧栏会展示的远程任务;断线设备的快照* 可能停在旧状态,不同步。状态跃迁的判定(何时弹出 / 响铃 / 发通知)在 main 的岛状态机。+ * 伙伴属于账号、不受任务范围限制:主力电脑在那台设备上的伙伴,聊天活动也同步过来。*/import { useEffect, useRef } from 'react';import type { AgentIslandRemoteSessionInput } from '../../../shared/agentIsland';import type { Session } from '@/lib/ccAgent.types';+import type { RemoteBot } from '@/features/bots/remoteBotRoster';+import { useRemoteBots } from '@/features/bots/useRemoteBots';import { useRemoteProjectSessions } from './remoteProjectsStore';import {getRemoteSessionActivity,@@ -22,11 +25,33 @@ export function buildAgentIslandRemoteSessionInputs(remoteSessions: Session[],selection: MachineSelection,readActivity: (sessionId: string, deviceId: string) => RemoteSessionActivity | undefined,+ remoteBots: readonly RemoteBot[] = [],): AgentIslandRemoteSessionInput[] {const inputs: AgentIslandRemoteSessionInput[] = [];+ // Companions belong to the account, not to a task scope: a companion whose main computer is+ // another device reports its chat here whatever machine the sidebar is scoped to. Its chat is+ // a hidden Session, so it is never also in the remote task list.+ for (const bot of remoteBots) {+ if (!bot.sessionId || !bot.online) continue;+ const activity = readActivity(bot.sessionId, bot.deviceId);+ if (!activity) continue;+ inputs.push({+ ...remoteActivityInput(activity),+ sessionId: bot.sessionId,+ deviceId: bot.deviceId,+ deviceName: bot.deviceName || null,+ title: bot.name,+ workingDir: null,+ workspaceKind: null,+ agentKind: null,+ companion: { name: bot.name, avatar: bot.avatar, avatarColor: bot.avatarColor },+ });+ }+ const companionSessionIds = new Set(inputs.map((input) => input.sessionId));for (const session of selectVisibleSessions([], remoteSessions, selection)) {const deviceId = session.deviceLinkDeviceId;if (!deviceId || session.deviceLinkConnectionStatus === 'disconnected') continue;+ if (companionSessionIds.has(session.id)) continue;const activity = readActivity(session.id, deviceId);if (!activity) continue;inputs.push({@@ -37,24 +62,34 @@ export function buildAgentIslandRemoteSessionInputs(workingDir: session.workingDir,workspaceKind: session.workspaceKind,agentKind: session.agentKind,- phase: activity.phase,- detail: activity.compactDetail,- ...(activity.completionNotification ? { completionNotification: activity.completionNotification } : {}),- ...(activity.workingPhase ? { workingPhase: activity.workingPhase } : {}),- ...(activity.interactionKind- ? {- interactionKind:- activity.interactionKind as AgentIslandRemoteSessionInput['interactionKind'],- }- : {}),+ ...remoteActivityInput(activity),});}return inputs;}+function remoteActivityInput(activity: RemoteSessionActivity): Pick<+ AgentIslandRemoteSessionInput,+ 'phase' | 'detail' | 'completionNotification' | 'workingPhase' | 'interactionKind'+> {+ return {+ phase: activity.phase,+ detail: activity.compactDetail,+ ...(activity.completionNotification ? { completionNotification: activity.completionNotification } : {}),+ ...(activity.workingPhase ? { workingPhase: activity.workingPhase } : {}),+ ...(activity.interactionKind+ ? {+ interactionKind:+ activity.interactionKind as AgentIslandRemoteSessionInput['interactionKind'],+ }+ : {}),+ };+}+/** 主窗常驻挂载一次(MainLayout)。内容未变时不发 IPC。 */export function useAgentIslandRemoteSessionsSync(): void {const remoteSessions = useRemoteProjectSessions();+ const remoteBots = useRemoteBots();const selection = useEffectiveSelectedMachineId();const activityRevision = useRemoteSessionActivityRevision();const lastSignatureRef = useRef<string | null>(null);@@ -66,6 +101,7 @@ export function useAgentIslandRemoteSessionsSync(): void {remoteSessions,selection,getRemoteSessionActivity,+ remoteBots,);const signature = JSON.stringify(inputs);if (signature === lastSignatureRef.current) return;@@ -74,5 +110,5 @@ export function useAgentIslandRemoteSessionsSync(): void {// 下一次变化时重发完整列表。lastSignatureRef.current = null;});- }, [remoteSessions, selection, activityRevision]);+ }, [remoteSessions, remoteBots, selection, activityRevision]);}diff --git a/apps/desktop/src/shared/agentIsland.ts b/apps/desktop/src/shared/agentIsland.tsindex df44dcfbf3..6e2c95f450 100644--- a/apps/desktop/src/shared/agentIsland.ts+++ b/apps/desktop/src/shared/agentIsland.ts@@ -1,6 +1,7 @@import { BRAND_NAME } from '@cindy/maker-shared/branding';import type { SessionActivitySnapshot } from '@cindy/maker-shared/session-activity';import type { BotAvatarHue } from './botAvatarHue.js';+import { isSupportedBotAvatarValue } from './botAvatarValue.js';export type AgentIslandSessionPhase = 'running' | 'needs-interaction' | 'completed' | 'error';@@ -814,6 +815,15 @@ export interface AgentIslandRemoteSessionInput {detail: string;workingPhase?: string;interactionKind?: AgentIslandInteractionKind;+ /** The companion this chat speaks for, when its main computer is the other device. */+ companion?: AgentIslandRemoteCompanionInput;+}++export interface AgentIslandRemoteCompanionInput {+ name: string;+ /** Stored avatar value as the other computer reports it (grapheme, preset, its blob or a cloud image). */+ avatar: string;+ avatarColor: string;}const AGENT_ISLAND_REMOTE_SESSIONS_MAX = 500;@@ -851,6 +861,7 @@ export function parseAgentIslandRemoteSessions(raw: unknown): AgentIslandRemoteS? record.interactionKind as AgentIslandInteractionKind: undefined;const workingPhase = readBoundedString(record.workingPhase, 64);+ const companion = readRemoteCompanion(record.companion);out.push({sessionId,deviceId,@@ -865,11 +876,28 @@ export function parseAgentIslandRemoteSessions(raw: unknown): AgentIslandRemoteSdetail: readBoundedString(record.detail, AGENT_ISLAND_REMOTE_TEXT_MAX_LENGTH) ?? '',...(workingPhase ? { workingPhase } : {}),...(interactionKind ? { interactionKind } : {}),+ ...(companion ? { companion } : {}),});}return out;}+function readRemoteCompanion(value: unknown): AgentIslandRemoteCompanionInput | null {+ if (typeof value !== 'object' || value === null) return null;+ const record = value as Record<string, unknown>;+ const name = readBoundedString(record.name, AGENT_ISLAND_REMOTE_TEXT_MAX_LENGTH);+ if (!name) return null;+ const avatar = typeof record.avatar === 'string' ? record.avatar.trim() : '';+ // Only values a companion avatar can hold: never an arbitrary local path or data URI.+ const supportedAvatar = (avatar.startsWith('https://') && avatar.length <= 2048)+ || isSupportedBotAvatarValue(avatar);+ return {+ name,+ avatar: supportedAvatar ? avatar : '',+ avatarColor: readBoundedString(record.avatarColor, 64) ?? '',+ };+}+function readBoundedString(value: unknown, maxLength: number): string | null {if (typeof value !== 'string') return null;const trimmed = value.trim();diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.mdindex 327c238ed5..e47d28f1b0 100644--- a/docs/product-rules/cindy-bots-runtime.md+++ b/docs/product-rules/cindy-bots-runtime.md@@ -610,6 +610,8 @@ Session 任务遵守同一套机制与呈现契约:Agent 标识,群专线在名字后附群名,不显示伙伴工作目录;回复完成时以消息样式呈现(头像跨两行、不标「完成」),运行中、待处理、报错与未读回复由头像上的光环和角标表示。委派执行仍是普通任务。伙伴改名或换头像后灵动岛立即更新;头像只在本机生成有界缩略图,读不到时回退底色加 emoji 或名字首字。+ 主力电脑是另一台已远控电脑的伙伴,聊天活动同样出现在本机灵动岛(不受侧栏任务范围限制,头像经本机的伙伴+ 头像副本读取),点击打开它在那台电脑上的聊天页。- iOS 的伙伴正常回复使用系统通信通知:伙伴名字、头像与回复摘要,应用角标由系统绘制。普通任务、报错和待处理事项保留原通知语义。头像仅携带有界缩略图、内置头像标识或单个字符,不上传公开头像地址;缺失头像回退名字首字,扩展失败仍交付原通知。