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。

plugin tasks: default to the Pi harness when the chain model is offered there

Dashe3e43e3c5277
diff --git a/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-agent-tasks.md b/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-agent-tasks.md
index af2c1ac1c4..6a5312fc66 100644
--- a/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-agent-tasks.md
+++ b/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-agent-tasks.md
@@ -289,7 +289,7 @@ text 与 context 合计不超过 64000;tasks.send 的 text 上限仍为 32768
`models()` 返回统一目录可选项的完整 route、efforts 和 supportsFastMode。用户明确选择后将 route 原样传给 create,或用 `setModel({taskId, expectedRevision, route})` 修改已有自有任务。运行中按普通任务的安全边界切换,不修改应用默认。两方法使用前检查 capabilities.operations。
当 `capabilities().pluginDefaultModel === true` 时,持续复用任务的插件可在每次新输入前调用
`setModel({taskId, expectedRevision, route:'plugin-default'})`。Host 当次读取本插件有效的任务模型设置(隐藏卡片时忽略旧值),
-复用 create 的模型解析规则(未指定时采用当前新任务选择),只同步模型、来源、引擎、强度和 Fast,
+复用 create 的模型解析规则(未指定时跟随系统辅助模型,优先 Pi 引擎与较低推理强度,最后才是当前新任务选择),只同步模型、来源、引擎、强度和 Fast,
不改权限、目录或其它任务。返回 `{status,task}`;配置相同返回 unchanged,不反复切换。
后续 send 使用返回 task.revision。须先处理已接受/结果不确定的旧请求,再同步下一次输入,
不得修改旧请求的回执或为模型变化重发。旧 Host 未声明此能力时保留原任务行为,不传入该 route。
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts
index 3d9825c987..a1ba1d4af9 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskDefaultRoute.test.ts
@@ -21,13 +21,18 @@ describe('auxiliaryChainSessionCandidates', () => {
]);
});
- // Rule: a chain head without a light effort level yields to a later candidate
- // that has one; default efforts are only a last pass. tier: unit.
- it('tries every candidate at a light effort before any candidate at its default', () => {
- expect(pluginTaskRouteAttempts(['a', 'b'])).toEqual([
- { candidate: 'a', effort: 'low' }, { candidate: 'a', effort: 'medium' },
- { candidate: 'b', effort: 'low' }, { candidate: 'b', effort: 'medium' },
- { candidate: 'a', effort: undefined }, { candidate: 'b', effort: undefined },
+ // Rule (2026-10-28): plugin tasks run on Pi when the model is offered there; a
+ // chain head without a light effort level yields to a later candidate that has
+ // one; default efforts are only a last pass. tier: unit.
+ it('tries each candidate on Pi first, every candidate at a light effort before any default', () => {
+ const a = { agentKind: 'codex' as const, providerId: 'xd', model: 'a' };
+ const b = { agentKind: 'pi' as const, providerId: 'xd', model: 'b' };
+ const aPi = { ...a, agentKind: 'pi' as const };
+ expect(pluginTaskRouteAttempts([a, b])).toEqual([
+ { candidate: aPi, effort: 'low' }, { candidate: aPi, effort: 'medium' },
+ { candidate: a, effort: 'low' }, { candidate: a, effort: 'medium' },
+ { candidate: b, effort: 'low' }, { candidate: b, effort: 'medium' },
+ { candidate: aPi, effort: undefined }, { candidate: a, effort: undefined }, { candidate: b, effort: undefined },
]);
});
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 8cd801ead1..3f4bd3cc0a 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/pluginTaskService.test.ts
@@ -1402,17 +1402,19 @@ it('rechecks saved preferences at the runtime mutation boundary', async () => {
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.
+ // model; the settings copy says it follows the system auxiliary model. It runs
+ // on Pi when the provider offers the model there (2026-10-28). 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'] }],
+ availableAgents: () => ['codex', 'pi'],
+ availableModels: () => [{ id: 'next', efforts: ['high'] }, { id: 'cheap', efforts: ['low', 'high'] }, { id: 'nolow', efforts: ['high'] }, { id: 'onpi', efforts: ['medium', 'high'] }],
hasCindyAiApiKey: () => true,
- readProviderRouting: async () => ({ availability: { 'claude-code': [], pi: [],
- codex: [{ id: f.route.providerId, name: 'provider', models: ['next', 'cheap', 'nolow'] }] },
+ readProviderRouting: async () => ({ availability: { 'claude-code': [],
+ pi: [{ id: f.route.providerId, name: 'provider', models: ['onpi'] }],
+ codex: [{ id: f.route.providerId, name: 'provider', models: ['next', 'cheap', 'nolow', 'onpi'] }] },
resolveDefaultProviderIdForModel: () => f.route.providerId }),
});
const source = readFileSync(new URL('../register.ts', import.meta.url), 'utf8');
@@ -1427,9 +1429,12 @@ it('an open plugin selection without a source session follows the auxiliary chai
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.
+ // First usable candidate wins, at low effort; a model Pi does not offer stays on the chain's harness.
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' });
+ .resolves.toMatchObject({ model: 'cheap', effort: 'low', agentKind: 'codex' });
+ // A model the provider offers on Pi runs on Pi, at its lightest level.
+ await expect(run([{ agentKind: 'codex', providerId: f.route.providerId, model: 'onpi' }]))
+ .resolves.toMatchObject({ model: 'onpi', effort: 'medium', agentKind: 'pi' });
// A chain head without a light effort level yields to the next candidate that has one.
await expect(run([{ agentKind: 'codex', providerId: f.route.providerId, model: 'nolow' }, { agentKind: 'codex', providerId: f.route.providerId, model: 'cheap' }]))
.resolves.toMatchObject({ model: 'cheap', effort: 'low' });
diff --git a/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts b/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts
index cdad96f253..ba33839d6e 100644
--- a/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts
+++ b/apps/desktop/src/main/maker-ipc/pluginTaskDefaultRoute.ts
@@ -1,6 +1,12 @@
/**
* Default model for a plugin's own persistent tasks (created without a source
- * session): follow the system auxiliary-model chain at low reasoning effort.
+ * session): follow the system auxiliary-model chain, on the Pi harness when the
+ * model is offered there, at the lightest reasoning effort available.
+ *
+ * Pi first (decided 2026-10-28): on a real install with many plugins, the same
+ * deepseek passage reasoned three to five times longer through Codex than
+ * through Pi, whose tool surface stays small whatever is installed. Codex and
+ * Claude remain the fallback when Pi does not offer the candidate model.
*
* 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
@@ -47,18 +53,24 @@ export function auxiliaryChainSessionCandidates(refs: readonly string[]): Plugin
/** Reasoning levels light enough for a plugin's background work, cheapest first. */
export const PLUGIN_TASK_LIGHT_EFFORTS = ['low', 'medium'] as const;
+/** The same provider/model on Pi first, then on the harness the chain named. */
+function harnessVariants<T extends { agentKind: AgentKind }>(candidate: T): T[] {
+ return candidate.agentKind === 'pi' ? [candidate] : [{ ...candidate, agentKind: 'pi' }, candidate];
+}
+
/**
- * Route attempts in order: every candidate at a light effort before any candidate
- * at its default. A chain head that only offers high/xhigh (deepseek-v4-flash on
- * xd) therefore yields to the next candidate that has low, instead of running
- * subtitle passages at high reasoning.
+ * Route attempts in order: every candidate (Pi variant first) at a light effort
+ * before any candidate at its default. A chain head that only offers high/xhigh
+ * therefore yields to the next candidate that has a light level, instead of
+ * running subtitle passages at high reasoning.
*/
-export function pluginTaskRouteAttempts<T>(
+export function pluginTaskRouteAttempts<T extends { agentKind: AgentKind }>(
candidates: readonly T[],
): Array<{ candidate: T; effort: (typeof PLUGIN_TASK_LIGHT_EFFORTS)[number] | undefined }> {
+ const expanded = candidates.flatMap(harnessVariants);
return [
- ...candidates.flatMap(candidate => PLUGIN_TASK_LIGHT_EFFORTS.map(effort => ({ candidate, effort }))),
- ...candidates.map(candidate => ({ candidate, effort: undefined })),
+ ...expanded.flatMap(candidate => PLUGIN_TASK_LIGHT_EFFORTS.map(effort => ({ candidate, effort }))),
+ ...expanded.map(candidate => ({ candidate, effort: undefined })),
];
}
diff --git a/docs/dev-rules/plugin-task-api-implementation.md b/docs/dev-rules/plugin-task-api-implementation.md
index 2f5ea2da6d..e109b0ccc2 100644
--- a/docs/dev-rules/plugin-task-api-implementation.md
+++ b/docs/dev-rules/plugin-task-api-implementation.md
@@ -123,7 +123,7 @@ Session/Plan 仍独立检查。旧 Host 可能只隐藏 UI,依赖停用语义
| 入口 | 模型来源与复用 | 权限与结果 |
| --- | --- | --- |
-| `tasks.create` | 显式 route → 插件任务设置 → 经验证的 callId 发起任务 → 当前新任务选择;保存准入后的完整 route | 可选 permissionMode;启用卡片时受其权限上限约束,隐藏时不读该上限;省略沿用设置,缺省 ask;返回普通任务及持久创建回执 |
+| `tasks.create` | 显式 route → 插件任务设置 → 经验证的 callId 发起任务 → 系统辅助模型链(同一供应商与模型先试 Pi 引擎,再试链上写明的引擎;先取 low/medium,都没有才用默认档)→ 当前新任务选择;保存准入后的完整 route | 可选 permissionMode;启用卡片时受其权限上限约束,隐藏时不读该上限;省略沿用设置,缺省 ask;返回普通任务及持久创建回执 |
| `tasks.send` | 使用该任务当前 route,检查 revision 和当前可用性;不因新默认变化重建任务 | 复核插件归属与权限;结果使用逐输入 run 回执 |
| `agent.errand` | 共用模型解析;无显式覆盖时优先保留已有专属任务的当前模型。配置冲突时只在新任务创建成功后替换映射,旧历史保留 | 旧权限边界、sessionKey、jobId 与结果取回协议保持兼容 |
| `workspace.ensureSession` | 已有工作区入口照常复用;新建才使用插件设置/发起任务/当前新任务完整组合 | 目录仍经亲选或原有确认流程;只建入口、不运行 Agent |