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。

CR2: 云端能力值没有模型链/任务模型时清掉本机副本的旧覆盖

nanaba945532535b
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 a0e2f189e3..f864ecd87b 100644
--- a/apps/desktop/src/main/companion-cloud/__tests__/capabilities.test.ts
+++ b/apps/desktop/src/main/companion-cloud/__tests__/capabilities.test.ts
@@ -23,7 +23,7 @@ describe('portable companion capabilities', () => {
// 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' } });
+ expect(companionCapabilitiesPatch({ mcpServers: ['a'], mcpServerNames: { a: 'Wiki' } }, { chain: [], task: null })).toMatchObject({ mcpServers: ['a'], mcpServerNames: { a: 'Wiki' } });
});
it('carries only the model chain the owner chose, without routes that run on another computer', () => {
@@ -54,10 +54,18 @@ describe('companionCapabilitiesPatch', () => {
expect(patch).not.toHaveProperty('permissions');
});
- it('follows this computer\'s default model when none of the saved routes is usable, and leaves the model alone when none was chosen', () => {
+ it('follows this computer\'s default model when none of the saved routes is usable', () => {
expect(companionCapabilitiesPatch({ modelChain: [route('m1')] }, { chain: [], task: null }))
- .toEqual({ modelOverride: null, modelChainOverride: null });
- expect(companionCapabilitiesPatch({ memory: true }, { chain: [], task: null })).toEqual({ memory: true });
- expect(companionCapabilitiesPatch({ taskModel: route('t1') }, { chain: [], task: null })).toEqual({ taskModelOverride: null });
+ .toEqual({ modelOverride: null, modelChainOverride: null, taskModelOverride: null });
+ expect(companionCapabilitiesPatch({ taskModel: route('t1') }, { chain: [], task: null })).toMatchObject({ taskModelOverride: null });
+ expect(companionCapabilitiesPatch({ taskModel: route('t1') }, { chain: [], task: route('t1') })).toMatchObject({ taskModelOverride: route('t1') });
+ });
+
+ it('clears the model and task-model choices a copy kept from an earlier stay when the cloud value names none', () => {
+ // The main computer follows its default (or cleared its task model): a stale local override must not survive.
+ expect(companionCapabilitiesPatch({ memory: true }, { chain: [], task: null }))
+ .toEqual({ memory: true, modelOverride: null, modelChainOverride: null, taskModelOverride: null });
+ expect(companionCapabilitiesPatch({ modelChain: [route('m1')] }, { chain: [route('m1')], task: null }))
+ .toMatchObject({ modelChainOverride: [route('m1')], taskModelOverride: null });
});
});
diff --git a/apps/desktop/src/main/companion-cloud/capabilities.ts b/apps/desktop/src/main/companion-cloud/capabilities.ts
index 650f6e9273..729a72eb7f 100644
--- a/apps/desktop/src/main/companion-cloud/capabilities.ts
+++ b/apps/desktop/src/main/companion-cloud/capabilities.ts
@@ -111,7 +111,10 @@ export function parseCompanionCapabilities(raw: unknown): CompanionCapabilitiesV
/** What the new home could not keep of the old setup; shown once as a line after the move. */
export type CompanionArrivalNotice = 'permissions' | 'model';
-/** The settings patch for `updateBotProfile` from a cloud value and the routes usable here. */
+/**
+ * The settings patch for `updateBotProfile` from a cloud value and the routes usable here. Only called
+ * for a present `companion.capabilities.v1` value; without the key (an older main computer) nothing is touched.
+ */
export function companionCapabilitiesPatch(value: CompanionCapabilitiesValue, models: {
chain: BotModelRoute[]; task: BotModelRoute | null;
}): Record<string, unknown> {
@@ -119,12 +122,12 @@ export function companionCapabilitiesPatch(value: CompanionCapabilitiesValue, mo
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) {
- const [primary] = models.chain;
- if (primary) Object.assign(patch, primary, { modelChain: models.chain, modelChainOverride: models.chain });
- // None of the saved routes exists here: follow this computer's default.
- else Object.assign(patch, { modelOverride: null, modelChainOverride: null });
- }
- if (value.taskModel) patch.taskModelOverride = models.task;
+ // The value exists, so the main computer's setup is known: a model it does not name is one it
+ // follows its default for, and a copy kept here from an earlier stay must not keep its old choice.
+ const [primary] = models.chain;
+ if (value.modelChain && primary) Object.assign(patch, primary, { modelChain: models.chain, modelChainOverride: models.chain });
+ // No chain saved, or none of the saved routes exists here: follow this computer's default.
+ else Object.assign(patch, { modelOverride: null, modelChainOverride: null });
+ patch.taskModelOverride = value.taskModel ? models.task : null;
return patch;
}
diff --git a/docs/product-rules/cloud-companions.md b/docs/product-rules/cloud-companions.md
index f45c0e5317..ac7a728f1f 100644
--- a/docs/product-rules/cloud-companions.md
+++ b/docs/product-rules/cloud-companions.md
@@ -58,7 +58,8 @@
- 模型是偏好,连接不跨电脑复用(2026-10-22 起,取代此前「换主力电脑后新电脑先跟随本机默认模型」):
只上传伙伴自己选定的模型链与任务模型(跟随默认的不上传,新电脑同样跟随它自己的默认;指定在别的电脑上运行的路线不带),
不含连接与凭证。接管时逐条检查这台电脑能否用同一来源 + 型号:能用的保留(按原顺序),不能用的去掉,一条都不能用就跟随
- 这台电脑的默认模型,并在伙伴聊天里提示一行。
+ 这台电脑的默认模型,并在伙伴聊天里提示一行。云端有 `companion.capabilities.v1` 但没有模型链 / 任务模型时(原主力跟随默认,或清掉了任务模型),
+ 接管已有的本机副本也会清掉它之前留下的模型链覆盖 / 任务模型覆盖,跟随这台电脑的默认;整个键不存在(旧版本主力)时才一律不动。
- 能力引用的处理:技能 / MCP / 工具集只带 id;这台电脑没有的引用原样保留,能力设置里标成「这台电脑不可用」
(沿用现有目录里 `available: false` 的呈现),装好之后自然生效,不静默删除。
MCP 的 id 对人没有意义,所以 `companion.capabilities.v1` 另带被引用 MCP 的显示名 `mcpServerNames`(只有名字,不含地址、请求头或凭证;旧值没有这个字段照常读取,新电脑存进伙伴设置的 `mcpServerNames`),能力设置里这类行显示可读名称加「这台电脑不可用」;没有名字时才显示 id。内置工具集用界面已有的名称,技能的 id 本身就是名字。