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。

fix(companion-cloud): D9 name the kept references a new computer does not have

nana246c17dfd266
diff --git a/apps/desktop/src/main/companion-cloud/__tests__/capabilities.test.ts b/apps/desktop/src/main/companion-cloud/__tests__/capabilities.test.ts
index b4aaa629a0..a0e2f189e3 100644
--- a/apps/desktop/src/main/companion-cloud/__tests__/capabilities.test.ts
+++ b/apps/desktop/src/main/companion-cloud/__tests__/capabilities.test.ts
@@ -16,6 +16,16 @@ describe('portable companion capabilities', () => {
toolsetMode: 'inherit', mcpServers: ['mcp-1'], mcpMode: 'allowlist', memory: false, inputHandoff: true, allowSchedulerFollow: true, gender: 'female' });
});
+ it('carries the names of the referenced MCP servers (this computer\'s win, an earlier computer\'s are kept), nothing else about them', () => {
+ const config = { mcpServers: ['mcp-1', 'mcp-2', 'mcp-3'], mcpServerNames: { 'mcp-2': 'Old name', 'mcp-3': 'From before', stray: 'x' } };
+ const value = portableCompanionCapabilities(config, null, { 'mcp-1': 'Docs', 'mcp-2': 'New name', other: 'y' });
+ expect(value.mcpServerNames).toEqual({ 'mcp-1': 'Docs', 'mcp-2': 'New name', 'mcp-3': 'From before' });
+ // Read back from the cloud defensively, and handed to the profile for display.
+ expect(parseCompanionCapabilities({ mcpServers: ['a'], mcpServerNames: { a: ' Wiki ', b: 'unreferenced', c: 3 } })?.mcpServerNames).toEqual({ a: 'Wiki' });
+ expect(parseCompanionCapabilities({ mcpServers: ['a'] })).toEqual({ mcpServers: ['a'] });
+ expect(companionCapabilitiesPatch({ mcpServers: ['a'], mcpServerNames: { a: 'Wiki' } }, { chain: [], task: null })).toEqual({ mcpServers: ['a'], mcpServerNames: { a: 'Wiki' } });
+ });
+
it('carries only the model chain the owner chose, without routes that run on another computer', () => {
const chosen = [route('m1'), route('m2', { agentDeviceId: 'phone-1' })];
expect(portableCompanionCapabilities({}, chosen).modelChain).toEqual([route('m1')]);
diff --git a/apps/desktop/src/main/companion-cloud/capabilities.ts b/apps/desktop/src/main/companion-cloud/capabilities.ts
index 7dc104ec19..650f6e9273 100644
--- a/apps/desktop/src/main/companion-cloud/capabilities.ts
+++ b/apps/desktop/src/main/companion-cloud/capabilities.ts
@@ -20,6 +20,8 @@ export interface CompanionCapabilitiesValue {
toolsetMode?: SelectionMode;
mcpServers?: string[];
mcpMode?: SelectionMode;
+ /** Display names of the referenced MCP servers (their ids mean nothing to a person); never configuration. */
+ mcpServerNames?: Record<string, string>;
memory?: boolean;
inputHandoff?: boolean;
allowSchedulerFollow?: boolean;
@@ -33,6 +35,17 @@ const refs = (value: unknown): string[] | undefined => Array.isArray(value)
? [...new Set(value.filter((id): id is string => typeof id === 'string' && !!id.trim() && id.length <= MAX_REF_LENGTH))].slice(0, MAX_REFS)
: undefined;
const mode = (value: unknown): SelectionMode | undefined => (value === 'inherit' || value === 'allowlist' ? value : undefined);
+const MAX_NAME_LENGTH = 80;
+/** Names for the referenced ids only (the list may hold ids this computer does not know). */
+function referencedNames(raw: unknown, ids: string[] | undefined): Record<string, string> | undefined {
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw) || !ids?.length) return undefined;
+ const names: Record<string, string> = {};
+ for (const id of ids) {
+ const name = (raw as Record<string, unknown>)[id];
+ if (typeof name === 'string' && name.trim()) names[id] = name.trim().slice(0, MAX_NAME_LENGTH);
+ }
+ return Object.keys(names).length ? names : undefined;
+}
/** A route that names another computer to run on has no meaning on the new home. */
const portableRoute = (route: BotModelRoute) => !route.agentDeviceId;
@@ -40,7 +53,8 @@ const portableRoute = (route: BotModelRoute) => !route.agentDeviceId;
* The portable part of a capabilities record. `explicitChain` is the companion's own chosen model
* chain (null: it follows the default, which the new computer then also follows).
*/
-export function portableCompanionCapabilities(config: Record<string, unknown>, explicitChain: BotModelRoute[] | null): CompanionCapabilitiesValue {
+export function portableCompanionCapabilities(config: Record<string, unknown>, explicitChain: BotModelRoute[] | null,
+ localMcpNames: Record<string, string> = {}): CompanionCapabilitiesValue {
const value: CompanionCapabilitiesValue = {};
for (const [field, selection] of [['skills', 'skillMode'], ['toolsets', 'toolsetMode'], ['mcpServers', 'mcpMode']] as const) {
const list = refs(config[field]);
@@ -48,6 +62,9 @@ export function portableCompanionCapabilities(config: Record<string, unknown>, e
const selected = mode(config[selection]);
if (selected) value[selection] = selected;
}
+ // Names this computer knows win; the rest keep what an earlier computer sent along.
+ const mcpNames = referencedNames({ ...(config.mcpServerNames as Record<string, unknown> | undefined), ...localMcpNames }, value.mcpServers);
+ if (mcpNames) value.mcpServerNames = mcpNames;
const excluded = refs(config.skillsExcluded);
if (excluded) value.skillsExcluded = excluded;
for (const field of ['memory', 'inputHandoff', 'allowSchedulerFollow'] as const) {
@@ -74,6 +91,8 @@ export function parseCompanionCapabilities(raw: unknown): CompanionCapabilitiesV
const selected = mode(input[selection]);
if (selected) value[selection] = selected;
}
+ const mcpNames = referencedNames(input.mcpServerNames, value.mcpServers);
+ if (mcpNames) value.mcpServerNames = mcpNames;
const excluded = refs(input.skillsExcluded);
if (excluded) value.skillsExcluded = excluded;
for (const field of ['memory', 'inputHandoff', 'allowSchedulerFollow'] as const) {
@@ -97,7 +116,7 @@ export function companionCapabilitiesPatch(value: CompanionCapabilitiesValue, mo
chain: BotModelRoute[]; task: BotModelRoute | null;
}): Record<string, unknown> {
const patch: Record<string, unknown> = {};
- for (const field of ['skills', 'skillMode', 'skillsExcluded', 'toolsets', 'toolsetMode', 'mcpServers', 'mcpMode', 'memory', 'inputHandoff', 'allowSchedulerFollow'] as const) {
+ for (const field of ['skills', 'skillMode', 'skillsExcluded', 'toolsets', 'toolsetMode', 'mcpServers', 'mcpMode', 'mcpServerNames', 'memory', 'inputHandoff', 'allowSchedulerFollow'] as const) {
if (value[field] !== undefined) patch[field] = value[field];
}
if (value.modelChain) {
diff --git a/apps/desktop/src/main/companion-cloud/host.ts b/apps/desktop/src/main/companion-cloud/host.ts
index 245ffef003..4aa03936a4 100644
--- a/apps/desktop/src/main/companion-cloud/host.ts
+++ b/apps/desktop/src/main/companion-cloud/host.ts
@@ -22,6 +22,7 @@ import type { BotModelRoute } from '../../shared/botModelChain.js';
import { inferBotTemplatePresetId } from '../../shared/botTemplatePreset.js';
import { resolveBotCanonicalSession } from '../maker-ipc/botCanonicalSessionRegistry.js';
import { readExplicitBotModelChain } from '../maker-host/bot-model-chain-settings-store.js';
+import { listCustomMcpServers } from '../maker-host/custom-mcp-store.js';
import { resolveAvailableTaskModels } from '../maker-ipc/appDefaultModelControl.js';
import { botProfileDir, botProfileMemoryDir, readBotProfileFolder, writeBotProfileFolder } from '../maker-ipc/botProfileFolder.js';
import { onBotRemoteResourceChanged } from '../maker-ipc/botRemoteResourceInvalidation.js';
@@ -83,8 +84,10 @@ export async function readCompanionValues(botId: string, selfDeviceId: string |
try {
const config = JSON.parse(row.capabilities ?? '{}') as unknown;
if (!config || typeof config !== 'object' || Array.isArray(config)) throw new Error('CAPABILITIES_UNREADABLE');
+ // Names of this computer's own MCP servers, so a computer without them can still say which one it is.
+ const mcpNames = Object.fromEntries((await listCustomMcpServers().catch(() => [])).map(server => [server.id, server.name]));
values.push({ key: COMPANION_CAPABILITIES_KEY, value: portableCompanionCapabilities(
- config as Record<string, unknown>, readExplicitBotModelChain(config as Record<string, unknown>)) });
+ config as Record<string, unknown>, readExplicitBotModelChain(config as Record<string, unknown>), mcpNames) });
} catch { values.push({ key: COMPANION_CAPABILITIES_KEY, value: null, unread: true }); }
const memoryDir = botProfileMemoryDir(userDataDir, botId);
// Only a missing folder means "no memories"; any other read error aborts this cycle so the
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index f7428b5c66..545bb4c4df 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -1259,6 +1259,9 @@ async function readProfile(
mcpServers: Array.isArray(config.mcpServers)
? config.mcpServers.filter((item): item is string => typeof item === 'string')
: [],
+ ...(config.mcpServerNames && typeof config.mcpServerNames === 'object' && !Array.isArray(config.mcpServerNames)
+ ? { mcpServerNames: Object.fromEntries(Object.entries(config.mcpServerNames as Record<string, unknown>)
+ .filter((entry): entry is [string, string] => typeof entry[1] === 'string')) } : {}),
memory: config.memory !== false,
permissions: config.permissions === 'trusted' || config.permissions === 'auto' ? config.permissions : 'ask',
// Stored and enforced elsewhere (input handoff policy, scheduler follow); the settings page reads them
diff --git a/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx b/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx
index 66b4a8f36f..def379f1d6 100644
--- a/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotCapabilitySettings.tsx
@@ -148,8 +148,15 @@ export function BotCapabilitySettings({
name: t(`settings.builtinTools.plugins.${item.id}.name`, { defaultValue: item.name }),
description: t(`settings.builtinTools.plugins.${item.id}.description`, { defaultValue: item.description ?? '' }),
} : item);
+ // A kept reference this computer does not have: its name (not its internal id), flagged as not here.
for (const id of selected[kind])
- if (!rows.some((item) => item.id === id)) rows.push({ id, name: id, available: false });
+ if (!rows.some((item) => item.id === id)) rows.push({
+ id,
+ name: kind === 'mcp' ? capabilities.mcpServerNames?.[id] || id
+ : kind === 'toolset' ? t(`settings.builtinTools.plugins.${id}.name`, { defaultValue: id }) : id,
+ available: false,
+ missing: true,
+ });
const mode = kind === 'mcp' ? capabilities.mcpMode : kind === 'toolset' ? capabilities.toolsetMode : 'allowlist';
// Inheritance can only become an explicit selection from a complete
// catalog of this kind. Missing/refreshing entries must not drop tools.
@@ -176,7 +183,7 @@ export function BotCapabilitySettings({
<p className="text-13 font-medium text-[var(--text-primary)]">{item.name}</p>
{item.description && <p className="mt-1 text-12 leading-5 text-[var(--text-secondary)]">{item.description}</p>}
{item.personal && <p className="mt-1 text-12 text-[var(--text-secondary)]">{t('bots.capabilities.personalHint')}</p>}
- {!item.available && <p className="mt-1 text-12 leading-5 text-[var(--text-secondary)]">{t('bots.capabilities.unavailableHint')}</p>}
+ {!item.available && <p className="mt-1 text-12 leading-5 text-[var(--text-secondary)]">{t(item.missing ? 'bots.capabilities.notOnThisComputer' : 'bots.capabilities.unavailableHint')}</p>}
{kind === 'toolset' && onConfigure && <Button type="button" size="sm" variant="secondary" className="mt-2"
onClick={() => onConfigure(kind, item.id)}>{t('bots.capabilities.configure')}</Button>}
</div>
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx
index 807eafc805..0d5883e18e 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botCapabilitySettings.test.tsx
@@ -66,6 +66,24 @@ describe('controlled capability page lifetime', () => {
});
});
+it('shows the name, not the internal id, of a kept reference this computer does not have', async () => {
+ Object.defineProperty(window, 'electronAPI', {
+ configurable: true,
+ value: {
+ localDb: { sessionsPush: { onPatched: () => h.offPush }, bots: { listSkills: async () => [] } },
+ maker: { onMcpChanged: () => h.offMcp, listCustomMcpServers: h.list, listAgentSkills: async () => ({ success: true, skills: [] }), plugins: { list: async () => [] } },
+ },
+ });
+ const bot = { id: 'bot-1', canonicalSessionId: 's1' } as BotProfile;
+ const capabilities = { modelChain: [], modelChainOverride: null, mcpMode: 'allowlist', mcpServers: ['mcp_9f3a', 'mcp_unnamed'],
+ mcpServerNames: { mcp_9f3a: '公司知识库' }, toolsets: [] } as unknown as BotProfile['capabilities'];
+ const view = render(<BotCapabilitySettings bot={bot} capabilities={capabilities} skills={[]} onChange={vi.fn()} expanded />);
+ expect(await view.findByText('公司知识库')).toBeTruthy();
+ expect(view.queryByText('mcp_9f3a')).toBeNull();
+ expect(view.getByText('mcp_unnamed')).toBeTruthy();
+ expect(view.getAllByText('bots.capabilities.notOnThisComputer')).toHaveLength(2);
+});
+
it.each([
{ enabled: true, runtimeStatus: 'discovered', firstEnabled: false, firstStatus: 'discovered' },
{ enabled: false, runtimeStatus: 'discovered', firstEnabled: true, firstStatus: 'discovered' },
diff --git a/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts b/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts
index 96b6be155b..288f034543 100644
--- a/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts
+++ b/apps/desktop/src/renderer/features/bots/botSettingsTarget.ts
@@ -15,6 +15,8 @@ export type BotCapabilityEntry = {
description?: string;
available: boolean;
personal?: boolean;
+ /** Kept from the companion's setup but not present on this computer. */
+ missing?: boolean;
};
type Bots = NonNullable<Window['electronAPI']['localDb']>['bots'];
diff --git a/apps/desktop/src/renderer/features/bots/botStore.ts b/apps/desktop/src/renderer/features/bots/botStore.ts
index 503117d7a1..1d918a1a22 100644
--- a/apps/desktop/src/renderer/features/bots/botStore.ts
+++ b/apps/desktop/src/renderer/features/bots/botStore.ts
@@ -54,6 +54,8 @@ export interface BotCapabilities {
toolsets: string[];
mcpMode: 'inherit' | 'allowlist';
mcpServers: string[];
+ /** Display names of MCP servers this computer may not have (ids alone mean nothing to a person). */
+ mcpServerNames?: Record<string, string>;
memory: boolean;
permissions: 'ask' | 'auto' | 'trusted';
/** 代输入: may this companion ask the owner to finish an on-screen step. Missing = allowed. */
@@ -672,6 +674,9 @@ export function normalizeDbProfile(value: unknown): BotProfile | null {
toolsets,
mcpMode: normalizeCapabilityMode(rawCapabilities?.mcpMode),
mcpServers: normalizeStringList(rawCapabilities?.mcpServers),
+ ...(rawCapabilities?.mcpServerNames && typeof rawCapabilities.mcpServerNames === 'object' && !Array.isArray(rawCapabilities.mcpServerNames)
+ ? { mcpServerNames: Object.fromEntries(Object.entries(rawCapabilities.mcpServerNames as Record<string, unknown>)
+ .filter((entry): entry is [string, string] => typeof entry[1] === 'string')) } : {}),
},
canonicalSessionId:
typeof item.canonicalSessionId === 'string' ? item.canonicalSessionId : undefined,
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index a57598f939..d012b1b372 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -9840,6 +9840,7 @@
"selectedHint": "Only selected items in this list are allowed for this companion.",
"personalHint": "A skill learned by this companion, loaded with its profile.",
"unavailableHint": "Unavailable on this computer or execution target. Configure its connection or system access first.",
+ "notOnThisComputer": "Not available on this computer",
"configure": "Open configuration",
"empty_toolset": "No built-in tools are available on this execution target.",
"empty_mcp": "No custom MCP servers have been added.",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 8d9ce37df2..c2d706c410 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -9806,6 +9806,7 @@
"selectedHint": "この一覧では、仲間は選択した項目だけを使用できます。",
"personalHint": "この仲間が学んだスキルです。仲間のプロフィールと共に読み込まれます。",
"unavailableHint": "このコンピュータまたは実行環境では利用できません。接続やシステム権限を設定してください。",
+ "notOnThisComputer": "このパソコンでは利用できません",
"configure": "設定を開く",
"empty_toolset": "この実行環境には利用できる内蔵ツールがありません。",
"empty_mcp": "カスタム MCP サーバーはまだ追加されていません。",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index ac780b5179..eaa24ffb1c 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -9806,6 +9806,7 @@
"selectedHint": "이 목록에서는 선택한 항목만 사용할 수 있습니다.",
"personalHint": "이 동료가 학습한 스킬로 프로필과 함께 자동으로 불러옵니다.",
"unavailableHint": "이 컴퓨터 또는 실행 환경에서 사용할 수 없습니다. 연결이나 시스템 권한을 먼저 설정하세요.",
+ "notOnThisComputer": "이 컴퓨터에서는 사용할 수 없습니다",
"configure": "설정 열기",
"empty_toolset": "이 실행 환경에 사용 가능한 내장 도구가 없습니다.",
"empty_mcp": "사용자 지정 MCP 서버가 아직 추가되지 않았습니다.",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index b796452a6a..0fa5e3a355 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -9806,6 +9806,7 @@
"selectedHint": "此列表中,伙伴只使用已选中的项目。",
"personalHint": "伙伴自己学到的技能,随伙伴自动加载。",
"unavailableHint": "本机或当前执行环境暂不可用,请先配置连接或系统授权。",
+ "notOnThisComputer": "这台电脑不可用",
"configure": "前往配置",
"empty_toolset": "当前执行环境没有可用的内置工具。",
"empty_mcp": "尚未添加自定义 MCP 服务。",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
index 3dad8e7339..dac150b343 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json
@@ -9806,6 +9806,7 @@
"selectedHint": "此清單中,夥伴只使用已選取的項目。",
"personalHint": "夥伴自己學到的技能,隨夥伴自動載入。",
"unavailableHint": "本機或目前執行環境暫不可用,請先設定連線或系統授權。",
+ "notOnThisComputer": "這台電腦不可用",
"configure": "前往設定",
"empty_toolset": "目前執行環境沒有可用的內建工具。",
"empty_mcp": "尚未新增自訂 MCP 服務。",
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index 304a7acdc3..0cd747161a 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -61,6 +61,7 @@
这台电脑的默认模型,并在伙伴聊天里提示一行。
- 能力引用的处理:技能 / MCP / 工具集只带 id;这台电脑没有的引用原样保留,能力设置里标成「这台电脑不可用」
(沿用现有目录里 `available: false` 的呈现),装好之后自然生效,不静默删除。
+ MCP 的 id 对人没有意义,所以 `companion.capabilities.v1` 另带被引用 MCP 的显示名 `mcpServerNames`(只有名字,不含地址、请求头或凭证;旧值没有这个字段照常读取,新电脑存进伙伴设置的 `mcpServerNames`),能力设置里这类行显示可读名称加「这台电脑不可用」;没有名字时才显示 id。内置工具集用界面已有的名称,技能的 id 本身就是名字。
- 权限档不随行:接管时新建的副本使用新建伙伴的默认档,并提示一行;接管已有的本机副本时保留它自己的权限档,不提示。
- 旧版本主力电脑没有 `companion.capabilities.v1`:接管时保持原行为(不改能力配置,新建的副本用默认值),其资料快照里的
`templateId` 仍会恢复到新建的副本上。