Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(plugins): 支持打开插件侧栏并跳到对应任务
Dash95b774976cb5
diff --git a/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-task-view.md b/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-task-view.mdindex f6f3b5361c..5ab30020fa 100644--- a/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-task-view.md+++ b/apps/desktop/resources/system-skills/cindy-plugin-creator/references/plugin-task-view.md@@ -32,6 +32,12 @@包内页面、不接收网址,所以没有 preview 那样的白名单与限速。错误码:`PERMISSION_DENIED`(未声明 taskView 或未启用)/ `INVALID_REQUEST` /`HOST_NOT_READY`(当前没有任务,或没有宿主窗口);+- 用户点击主视图里的任务跳转按钮时,可调用 `cindy.taskView({ sessionId, focus: true })`:+ 打开该任务的插件页签,并通过宿主既有任务导航切到该任务;已分离的侧栏也按主动打开处理。+ 缺省或 `focus: false` 仍只开页签、不抢前台,后台工具调用不应传 `focus: true`。+ 成功回执额外带 `focusRequested: true`,表示导航请求已投递,不表示目标任务一定存在;+ 不存在的任务沿用任务导航的错误处理。旧宿主可能忽略 `focus`,缺该回执字段时应提示更新,+ 不能声称已跳转。`peek: true` 始终只查询,即使同时传 `focus: true` 也不导航。- `cindy.taskView({ peek: true })` 只问"现在打开会落到哪个任务",不开页签:有台前任务回 `{ ok: true, sessionId }`,没有则 `HOST_NOT_READY`。用它决定自己的界面(如 mainView管理页)要不要出现"在当前任务中打开"一类入口——整页主视图里通常没有台前任务;diff --git a/apps/desktop/src/main/cindy-brain/__tests__/taskViewSlot.test.ts b/apps/desktop/src/main/cindy-brain/__tests__/taskViewSlot.test.tsindex 1eab298ad4..4bd8b97214 100644--- a/apps/desktop/src/main/cindy-brain/__tests__/taskViewSlot.test.ts+++ b/apps/desktop/src/main/cindy-brain/__tests__/taskViewSlot.test.ts@@ -41,6 +41,40 @@ function makeSlot(overrides: Partial<TaskViewSlotDeps> = {}) {}describe('taskViewSlot', () => {+ // 主视图的显式跳转须同时导航任务与打开页签;原测试只覆盖后台开页。+ // 最小输入:focus:true;unit,缺省/peek 不抢前台,投递失败不导航。+ it('focus explicitly reveals the same task, while old requests and peek remain passive', () => {+ const { slot, pushes } = makeSlot();+ const reveal = vi.fn();+ expect(slot.handleRequest('sim', { sessionId: 'task-1', focus: true })).toMatchObject({+ ok: false,+ errorCode: 'HOST_NOT_READY',+ });+ slot.setRevealSession(reveal);+ for (const request of [{}, { focus: false }, { peek: true, focus: true }])+ slot.handleRequest('sim', request);+ expect(reveal).not.toHaveBeenCalled();+ expect(slot.handleRequest('sim', { sessionId: 'task-1', focus: true })).toEqual({+ ok: true,+ sessionId: 'task-1',+ focusRequested: true,+ });+ expect(reveal).toHaveBeenCalledExactlyOnceWith('task-1');+ expect(pushes.at(-1)).toEqual({ instanceId: 'sim', sessionId: 'task-1', focus: true });+ expect(slot.handleRequest('sim', { focus: 'true' })).toMatchObject({+ ok: false,+ errorCode: 'INVALID_REQUEST',+ });+ const failed = makeSlot({ broadcast: () => false }).slot;+ const failedReveal = vi.fn();+ failed.setRevealSession(failedReveal);+ expect(failed.handleRequest('sim', { focus: true })).toMatchObject({+ ok: false,+ errorCode: 'HOST_NOT_READY',+ });+ expect(failedReveal).not.toHaveBeenCalled();+ });+// PR #6861 discussion_r4353708280:原有 broadcast=false 用例绕过了真实选窗适配器。// 最小失败输入:只有隐藏沙箱,或主窗正在重载;unit,验证回执及实际投递目标。it.each(['absent', 'loading', 'destroyed-contents', 'crashed', 'closed', 'send-failed', 'ready'] as const)(diff --git a/apps/desktop/src/main/cindy-brain/index.ts b/apps/desktop/src/main/cindy-brain/index.tsindex 7e8ec8989e..89670db457 100644--- a/apps/desktop/src/main/cindy-brain/index.ts+++ b/apps/desktop/src/main/cindy-brain/index.ts@@ -2111,6 +2111,7 @@ export function setGhostAgentTurnRunner(runner: GhostAgentTurnRunner | null): voexport function setGhostSessionRevealer(reveal: ((sessionId: string) => void) | null): void {getGhostAgentSlot().setRevealSession(reveal);getGhostErrandSlot().setRevealSession(reveal);+ getGhostTaskViewSlot().setRevealSession(reveal);}const pluginTargetSlot = new PluginTargetSlot();diff --git a/apps/desktop/src/main/cindy-brain/taskViewSlot.ts b/apps/desktop/src/main/cindy-brain/taskViewSlot.tsindex 20cc71ac27..84aa5e9565 100644--- a/apps/desktop/src/main/cindy-brain/taskViewSlot.ts+++ b/apps/desktop/src/main/cindy-brain/taskViewSlot.ts@@ -25,6 +25,7 @@ import { isMainShellWindowUrl } from './scheduleSlot.js';export interface GhostTaskViewOpenPush {instanceId: string;sessionId: string;+ focus?: true;}/** Electron 投递适配器;保留在槽旁边以便免启动 Electron 验证窗口生命周期。 */@@ -69,8 +70,14 @@ function fail(}export class GhostTaskViewSlot {+ private revealSession: ((sessionId: string) => void) | null = null;+constructor(private readonly deps: TaskViewSlotDeps) {}+ setRevealSession(reveal: ((sessionId: string) => void) | null): void {+ this.revealSession = reveal;+ }+handleRequest(ghostId: string, payload: unknown): GhostPipeTaskViewResult {const ghost = this.deps.getGhost(ghostId);if (!ghost?.enabled || !ghost.manifest.taskView) {@@ -88,13 +95,27 @@ export class GhostTaskViewSlot {if (request.peek !== undefined && request.peek !== true) {return fail('INVALID_REQUEST', 'peek 只接受 true');}+ if (request.focus !== undefined && typeof request.focus !== 'boolean') {+ return fail('INVALID_REQUEST', 'focus 必须是布尔值');+ }const sessionId =typeof request.sessionId === 'string' ? request.sessionId : this.deps.focusedSessionId();if (!sessionId) return fail('HOST_NOT_READY', '当前没有任务可承载任务页');if (request.peek === true) return { ok: true, sessionId };- const delivered = this.deps.broadcast({ instanceId: installedGhostStoragePart(ghost), sessionId });+ if (request.focus === true && !this.revealSession)+ return fail('HOST_NOT_READY', '任务导航尚未就绪');+ const delivered = this.deps.broadcast({+ instanceId: installedGhostStoragePart(ghost),+ sessionId,+ ...(request.focus === true ? { focus: true as const } : {}),+ });if (!delivered) return fail('HOST_NOT_READY', '当前没有可用的宿主窗口');+ if (request.focus === true) this.revealSession!(sessionId);this.deps.log?.info('ghost task view open requested', { ghostId, sessionId });- return { ok: true, sessionId };+ return {+ ok: true,+ sessionId,+ ...(request.focus === true ? { focusRequested: true as const } : {}),+ };}}diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.tsindex ddd5885955..a5d78999b1 100644--- a/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.ts+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreCindyMakeAttention.test.ts@@ -97,6 +97,17 @@ describe('Make result dots at the real message ingress', () => {await Promise.resolve();expect(openPluginTaskTab).toHaveBeenCalledTimes(role === 'primary' ? 1 : 0);expect(openUrlInSidebarBrowser).toHaveBeenCalledTimes(role === 'primary' ? 1 : 0);+ if (role === 'primary')+ expect(openPluginTaskTab).toHaveBeenLastCalledWith(sessionId, 'sim', {+ userInitiated: false,+ });+ taskView({ instanceId: 'sim', sessionId, focus: true });+ await Promise.resolve();+ expect(openPluginTaskTab).toHaveBeenCalledTimes(role === 'primary' ? 2 : 0);+ if (role === 'primary')+ expect(openPluginTaskTab).toHaveBeenLastCalledWith(sessionId, 'sim', {+ userInitiated: true,+ });});it.each(['local', 'remote'])('updates %s dots without mounting the card or running an Agent',diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.tsindex 6f65a99617..4a55388c2d 100644--- a/apps/desktop/src/renderer/lib/makerChatStore.ts+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts@@ -9809,16 +9809,16 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {);// ── 插件任务页开页(taskView 槽):main 已做资格审与落点解析,这里只在该任务的- // 右侧栏打开 / 聚焦任务页页签。与 preview 同样只由主窗口处理,不抢前台。+ // 右侧栏打开 / 聚焦任务页页签。只由主窗口处理;显式 focus 才按用户导航打开。bindIpc((cb: (data: unknown, ownerStamp?: unknown) => void) =>window.electronAPI.ghosts?.onTaskViewOpen?.(cb),(raw: unknown, ownerStamp?: unknown) => {if (!isCurrentLocalLiveIngress(ownerStamp)) return;if (isSidebarWindow() || isSecondaryWindow()) return;- const p = raw as { instanceId?: unknown; sessionId?: unknown } | null;+ const p = raw as { instanceId?: unknown; sessionId?: unknown; focus?: unknown } | null;if (!p || typeof p.instanceId !== 'string' || typeof p.sessionId !== 'string') return;- void openPluginTaskTab(p.sessionId, p.instanceId, { userInitiated: false }).catch(() => {+ void openPluginTaskTab(p.sessionId, p.instanceId, { userInitiated: p.focus === true }).catch(() => {/* 标签落地失败(任务桶异常等)不致命,静默 */});},diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.tsindex 89328c3c16..da70cc5c5f 100644--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@ -1583,7 +1583,7 @@ interface ElectronAPI {resolveConfirm: (requestId: string, confirmed: boolean) => Promise<{ handled: boolean }>;/** taskView 槽:插件请求在指定任务的右侧栏打开 / 聚焦它的任务页页签(main 已资格审)。 */onTaskViewOpen: (- callback: (payload: { instanceId: string; sessionId: string }) => void,+ callback: (payload: { instanceId: string; sessionId: string; focus?: true }) => void,) => () => void;/** preview 槽:插件请求在右侧栏内置浏览器开预览标签(main 已白名单守门+限速)。 */onPreviewOpen: (diff --git a/apps/desktop/src/shared/ghost.ts b/apps/desktop/src/shared/ghost.tsindex c6827abafb..bb91e7842d 100644--- a/apps/desktop/src/shared/ghost.ts+++ b/apps/desktop/src/shared/ghost.ts@@ -6949,7 +6949,7 @@ export type GhostPipePreviewResult =* 主机落到台前任务,插件据此把自己的业务状态(如设备)绑定到该任务。*/export type GhostPipeTaskViewResult =- | { ok: true; sessionId: string }+ | { ok: true; sessionId: string; focusRequested?: true }| {ok: false;errorCode: 'PERMISSION_DENIED' | 'INVALID_REQUEST' | 'HOST_NOT_READY' | 'INTERNAL';