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(plugins): 插件自建任务默认跟随辅助模型链并使用低推理强度

Dash3f69b077962a
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts
new file mode 100644
index 0000000000..dcd9b2ebb8
--- /dev/null
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts
@@ -0,0 +1,30 @@
+import { describe, expect, it } from 'vitest';
+
+import { encodeCatalogModelPin } from '../../../shared/catalogModelPin.js';
+import { auxiliaryChainSessionCandidates, pluginTaskSelectionIsOpen } from '../pluginTaskDefaultRoute.js';
+
+describe('auxiliaryChainSessionCandidates', () => {
+ // Rule: a plugin's own persistent task (no originating session) follows the
+ // auxiliary chain instead of the new-task composer selection. tier: unit.
+ it('maps catalog pins and lightweight profiles to session routes in chain order', () => {
+ const refs = [
+ encodeCatalogModelPin({ providerId: 'xd', agentKind: 'codex', model: 'deepseek/deepseek-v4-flash' }),
+ 'codex-gpt-5.4-mini',
+ 'litellm-gpt-5.4-mini',
+ encodeCatalogModelPin({ providerId: 'xd', agentKind: 'codex', model: 'deepseek/deepseek-v4-flash' }),
+ 'not-a-ref',
+ ];
+ expect(auxiliaryChainSessionCandidates(refs)).toEqual([
+ { agentKind: 'codex', providerId: 'xd', model: 'deepseek/deepseek-v4-flash' },
+ { agentKind: 'codex', providerId: 'openai', model: 'gpt-5.4-mini' },
+ { agentKind: 'codex', providerId: 'xd', model: 'gpt-5.4-mini' },
+ ]);
+ });
+
+ it('treats any explicit identifying field as a closed selection', () => {
+ expect(pluginTaskSelectionIsOpen({})).toBe(true);
+ expect(pluginTaskSelectionIsOpen({ effort: 'low' })).toBe(true);
+ expect(pluginTaskSelectionIsOpen({ model: 'gpt-6.1-sol' })).toBe(false);
+ expect(pluginTaskSelectionIsOpen({ providerId: 'openai' })).toBe(false);
+ });
+});
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
index f517c8aade..2c86e6b484 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it, vi } from 'vitest';
import { readFileSync } from 'node:fs';
import { createHash } from 'node:crypto';
import ts from 'typescript';
+import { pluginTaskSelectionIsOpen } from '../pluginTaskDefaultRoute.js';
import { createSessionExecutionResolver } from '../sessionExecutionSelection.js';
import { Session } from '@cindy/maker-core';
import { fastModeToStorage } from '@cindy/maker-shared';
@@ -1399,6 +1400,44 @@ it('rechecks saved preferences at the runtime mutation boundary', async () => {
expect(apply).not.toHaveBeenCalled();
});
+it('an open plugin selection without a source session follows the auxiliary chain at low effort', async () => {
+ // Rule: a plugin's own persistent task must not borrow the new-task composer
+ // model; the settings copy says it follows the system auxiliary model. tier: unit.
+ const f = fixture();
+ const selected = { harness: 'codex' as const, model: 'next', providerId: f.route.providerId, effort: 'high' as const, fastMode: false };
+ const resolver = createSessionExecutionResolver({
+ captureOwner: () => () => {}, readCaller: async () => { throw Error('unexpected caller'); },
+ readDefault: () => ({ agentKind: selected.harness, model: selected.model, providerId: selected.providerId, effort: selected.effort, fastMode: selected.fastMode }),
+ availableAgents: () => ['codex'],
+ availableModels: () => [{ id: 'next', efforts: ['high'] }, { id: 'cheap', efforts: ['low', 'high'] }, { id: 'nolow', efforts: ['high'] }],
+ hasCindyAiApiKey: () => true,
+ readProviderRouting: async () => ({ availability: { 'claude-code': [], pi: [],
+ codex: [{ id: f.route.providerId, name: 'provider', models: ['next', 'cheap', 'nolow'] }] },
+ resolveDefaultProviderIdForModel: () => f.route.providerId }),
+ });
+ const source = readFileSync(new URL('../register.ts', import.meta.url), 'utf8');
+ const resolveStart = source.indexOf(' const resolveRoute = async');
+ const resolve = source.slice(resolveStart, source.indexOf(' const readExecution', resolveStart));
+ const run = (candidates: Array<{ agentKind: 'codex'; providerId: string; model: string }>, config = {}, sourceSessionId?: string) => {
+ const deps = { readPluginTaskConfig: () => config, getSelectedNewMakerRoute: () => selected,
+ activeOwnerScopeKey: () => 'owner', assertPlugin: () => {}, getPluginTaskSourceSessionId: () => sourceSessionId,
+ resolveSessionExecution: resolver, PluginTaskError, routeUnavailable: () => { throw Error('unavailable'); },
+ getEffectiveAuxiliaryModelRefs: () => ['chain'], getEffectiveAuxiliaryModelChainSnapshot: () => 'chain',
+ auxiliaryChainSessionCandidates: () => candidates, pluginTaskSelectionIsOpen };
+ const js = ts.transpileModule(`${resolve}\nreturn resolveRoute;`, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText;
+ return new Function(...Object.keys(deps), js)(...Object.values(deps))('p') as Promise<{ model: string; effort: string }>;
+ };
+ // First usable candidate wins, at low effort.
+ await expect(run([{ agentKind: 'codex', providerId: f.route.providerId, model: 'missing' }, { agentKind: 'codex', providerId: f.route.providerId, model: 'cheap' }]))
+ .resolves.toMatchObject({ model: 'cheap', effort: 'low' });
+ // A model without a low effort level still routes, at its default effort.
+ await expect(run([{ agentKind: 'codex', providerId: f.route.providerId, model: 'nolow' }])).resolves.toMatchObject({ model: 'nolow' });
+ // No usable candidate: the new-task selection remains the last resort.
+ await expect(run([{ agentKind: 'codex', providerId: f.route.providerId, model: 'missing' }])).resolves.toMatchObject({ model: 'next', effort: 'high' });
+ // An explicit plugin model never consults the chain.
+ await expect(run([{ agentKind: 'codex', providerId: f.route.providerId, model: 'cheap' }], { model: 'next' })).resolves.toMatchObject({ model: 'next' });
+});
+
it.each([
['provider', 'reset'], ['provider', 'partial'],
['mutation', 'reset'], ['mutation', 'partial'],
@@ -1437,7 +1476,10 @@ it.each([
const resolve = source.slice(resolveStart, source.indexOf(' const readExecution', resolveStart));
const deps = { getPluginTaskDefaults: () => config, getSelectedNewMakerRoute: () => selected,
activeOwnerScopeKey: () => 'owner', assertPlugin: () => {}, getPluginTaskSourceSessionId: () => undefined,
- resolveSessionExecution: resolver, PluginTaskError, routeUnavailable: () => { throw Error('unavailable'); } };
+ resolveSessionExecution: resolver, PluginTaskError, routeUnavailable: () => { throw Error('unavailable'); },
+ // No auxiliary chain configured in this scenario: the new-task selection stays the inherited default.
+ getEffectiveAuxiliaryModelRefs: () => [], getEffectiveAuxiliaryModelChainSnapshot: () => '',
+ auxiliaryChainSessionCandidates: () => [], pluginTaskSelectionIsOpen };
const js = ts.transpileModule(`${resolve}\nreturn {${preference} resolveRoute};`, {
compilerOptions: { target: ts.ScriptTarget.ES2022 },
}).outputText;
diff --git a/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts b/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts
new file mode 100644
index 0000000000..1483ca1e64
--- /dev/null
+++ b/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts
@@ -0,0 +1,50 @@
+/**
+ * Default model for a plugin's own persistent tasks (created without a source
+ * session): follow the system auxiliary-model chain at low reasoning effort.
+ *
+ * The plugin settings page has always described the model row as "follows the
+ * system auxiliary model"; routes created from inside a user's session still
+ * inherit that session's model (resolveRoute with a sourceSessionId). Only the
+ * no-source path used to borrow the new-task composer selection, which made a
+ * subtitle translation cost whatever model the user last picked for coding.
+ */
+import type { AgentKind } from '@cindy/maker-core';
+import { getUtilityModelProfile } from '../../shared/utilityModelProfiles.js';
+import { parsedAuxiliaryModelRefs } from '../utility-model/resolveAuxiliaryModelChain.js';
+
+export interface PluginTaskDefaultCandidate {
+ agentKind: AgentKind;
+ providerId: string;
+ model: string;
+}
+
+/** Lightweight profiles run through the same gateways as one-shot utility calls. */
+function profileRoute(id: Parameters<typeof getUtilityModelProfile>[0]): PluginTaskDefaultCandidate {
+ const profile = getUtilityModelProfile(id);
+ return {
+ agentKind: 'codex',
+ providerId: profile.transport === 'codex-responses' ? 'openai' : 'xd',
+ model: profile.model,
+ };
+}
+
+/** Ordered, de-duplicated session routes derived from the auxiliary chain refs. */
+export function auxiliaryChainSessionCandidates(refs: readonly string[]): PluginTaskDefaultCandidate[] {
+ const out: PluginTaskDefaultCandidate[] = [];
+ const seen = new Set<string>();
+ for (const ref of parsedAuxiliaryModelRefs(refs)) {
+ const candidate = ref.kind === 'catalog'
+ ? { agentKind: ref.route.agentKind as AgentKind, providerId: ref.route.providerId, model: ref.route.model }
+ : profileRoute(ref.id);
+ const key = `${candidate.agentKind}\u0000${candidate.providerId}\u0000${candidate.model}`;
+ if (seen.has(key)) continue;
+ seen.add(key);
+ out.push(candidate);
+ }
+ return out;
+}
+
+/** The plugin left the route open when none of the identifying fields is set. */
+export function pluginTaskSelectionIsOpen(selection: { agentKind?: unknown; model?: unknown; providerId?: unknown }): boolean {
+ return !selection.agentKind && !selection.model && !selection.providerId;
+}
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 9007d1dcd1..38d5a1fee5 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -662,6 +662,8 @@ import { readSessionNotificationPreview } from '../localDb/sessionNotificationPr
import { createBotGroupWorkDir } from './botGroupWorkDir.js';
import { createBotGroupAttachmentStore } from './botGroupAttachments.js';
import { requestUtilityText } from '../utility-model/oneShotCandidates.js';
+import { getEffectiveAuxiliaryModelChainSnapshot, getEffectiveAuxiliaryModelRefs } from '../utility-model/resolveAuxiliaryModelChain.js';
+import { auxiliaryChainSessionCandidates, pluginTaskSelectionIsOpen } from './pluginTaskDefaultRoute.js';
import { validateExistingLocalProjectDirectory } from '../mcp-integrations/createProject.js';
import { gitExec } from '../worktree/gitExec.js';
import { BOT_GROUP_CLIENT_ID_PREFIX } from '../../shared/botGroupChat.js';
@@ -14172,7 +14174,23 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
const sourceSessionId = getPluginTaskSourceSessionId(pluginId, callId);
if (callId && !sourceSessionId && !(selection.agentKind && selection.model && selection.providerId)) throw new PluginTaskError('ROUTE_UNAVAILABLE', '发起任务已不可用,请重新调用,或在面板选择模型后创建任务');
try {
- const execution = await resolveSessionExecution(selection, sourceSessionId);
+ let execution: Awaited<ReturnType<typeof resolveSessionExecution>> | undefined;
+ if (!sourceSessionId && pluginTaskSelectionIsOpen(selection)) {
+ // A plugin's own task with no originating session follows the auxiliary
+ // chain at low effort; an unavailable candidate falls through to the next,
+ // and the new-task selection remains the last resort.
+ for (const candidate of auxiliaryChainSessionCandidates(getEffectiveAuxiliaryModelRefs())) {
+ for (const effort of ['low', undefined] as const) {
+ try {
+ execution = await resolveSessionExecution({ ...selection, ...candidate, ...(effort ? { effort } : {}) });
+ assertPlugin(pluginId);
+ break;
+ } catch { execution = undefined; }
+ }
+ if (execution) break;
+ }
+ }
+ execution ??= await resolveSessionExecution(selection, sourceSessionId);
assertPlugin(pluginId);
if (!execution.providerId) return routeUnavailable();
return { ...execution, agentKind: execution.agentKind === 'claude-code' ? 'cc' : execution.agentKind,
@@ -14199,8 +14217,10 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
// inherit the new-task selection; partial/reset settings can do so.
const fallback = config.agentKind && config.model && config.providerId
? undefined : getSelectedNewMakerRoute(activeOwnerScopeKey());
- return { ...config, inheritedDefault: fallback ? JSON.stringify([
- fallback.harness, fallback.model, fallback.providerId, fallback.effort, fallback.fastMode,
+ // An open selection also follows the auxiliary chain; its snapshot is part of the fingerprint.
+ const chain = pluginTaskSelectionIsOpen(config) ? getEffectiveAuxiliaryModelChainSnapshot() : undefined;
+ return { ...config, inheritedDefault: fallback || chain ? JSON.stringify([
+ fallback?.harness, fallback?.model, fallback?.providerId, fallback?.effort, fallback?.fastMode, chain,
]) : undefined };
},
readPermissionMode: pluginId => {