Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 修复渠道新建任务缺少伙伴头像标记
xuzini-xzn8613a8593a6f
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.tsindex 81fc2c2497..865cf55741 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botTaskResponsibilityAuthority.test.ts@@ -1,9 +1,9 @@import { readFileSync } from 'node:fs';import Database from 'better-sqlite3';import { drizzle } from 'drizzle-orm/better-sqlite3';-import { and, desc, eq, isNotNull } from 'drizzle-orm';+import { and, desc, eq, inArray, isNotNull, isNull } from 'drizzle-orm';import ts from 'typescript';-import { expect, it } from 'vitest';+import { expect, it, vi } from 'vitest';import { botDelegations, botProfiles, botSessionLinks, sessions } from '../../localDb/schema.js';// Exercise the real authority queries against SQLite, without Electron startup.@@ -42,3 +42,78 @@ it('derives caller identity from the active local canonical link and creation onexpect(await resolve('canonical')).toMatchObject({ ok: false, errorCode: 'BOT_SESSION_INACTIVE' });} finally { sqlite.close(); }});+++// 生产入口: captureBotCreatedTaskResponsibility; 结果: 新任务保存伙伴归属并通知列表刷新。+// Bug: 飞书 channel / group 调用方被工作台权限检查误排除,任务标题旁缺伙伴头像。+// 现有覆盖只测 canonical 身份查询或 mock 掉整个调用方解析,没有覆盖专线创建链路。+// 最小失败输入: active Bot + active channel link + 新 desktop 任务。tier: unit,内存 SQLite。+const chunk = source.slice(source.indexOf('export async function resolveWorkbenchCaller'), source.indexOf('type Failure = {'));+const js = ts.transpileModule(+ `${chunk.replaceAll('export ', '')}; return { captureBotCreatedTaskResponsibility, resolveWorkbenchCaller };`,+ { compilerOptions: { target: ts.ScriptTarget.ES2022 } },+).outputText;++function fixture(role: string) {+ const sqlite = new Database(':memory:');+ sqlite.exec(`+ CREATE TABLE sessions(id TEXT, source TEXT, status TEXT, remote_host_id TEXT, orca_role TEXT);+ CREATE TABLE bot_profiles(id TEXT, status TEXT);+ CREATE TABLE bot_session_links(id TEXT, session_id TEXT, bot_id TEXT, role TEXT, archived_at INTEGER);+ CREATE TABLE bot_delegations(id TEXT, child_session_id TEXT);+ INSERT INTO sessions VALUES ('caller','bot','active',NULL,NULL),('created','desktop','active',NULL,NULL);+ INSERT INTO bot_profiles VALUES ('hihi','active');+ `);+ sqlite.prepare("INSERT INTO bot_session_links VALUES ('link', ?, ?, ?, NULL)").run('caller', 'hihi', role);+ const save = vi.fn(async () => {});+ const broadcast = vi.fn();+ const deps = {+ getDbClient: () => ({ drizzle: drizzle(sqlite) }),+ and, desc, eq, inArray, isNotNull, isNull, botDelegations, botProfiles, botSessionLinks, sessions,+ isAppSessionBoundaryPending: () => false,+ activeOwnerScopeKey: () => 'synthetic-owner',+ ownerScopedUserDataPath: () => '/synthetic-owner-home',+ setTaskResponsibility: save,+ broadcastBotWorkbenchChanged: broadcast,+ };+ const api = new Function(...Object.keys(deps), js)(...Object.values(deps)) as {+ captureBotCreatedTaskResponsibility(id: string): Promise<null | ((id: string) => Promise<void>)>;+ resolveWorkbenchCaller(id: string): Promise<{ ok: boolean; errorCode?: string }>;+ };+ return { sqlite, save, broadcast, ...api };+}++it.each(['canonical', 'thread', 'channel', 'group'])(+ 'records the creator of a fresh task from the active %s companion conversation', async (role) => {+ const f = fixture(role);+ try {+ const record = await f.captureBotCreatedTaskResponsibility('caller');+ expect(record).not.toBeNull();+ await record!('created');+ expect(f.save).toHaveBeenCalledWith('/synthetic-owner-home', 'hihi', 'created', true, expect.any(Function));+ expect(f.broadcast).toHaveBeenCalledWith('hihi');+ // Recognizing a creator must not grant a channel/group conversation workbench access.+ if (role === 'channel' || role === 'group') {+ expect(await f.resolveWorkbenchCaller('caller')).toMatchObject({ ok: false, errorCode: 'BOT_MAIN_TASK_REQUIRED' });+ }+ } finally { f.sqlite.close(); }+ },+);++it.each([+ ['history', ''],+ ['delegation', ''],+ ['channel', "UPDATE sessions SET source='desktop' WHERE id='caller'"],+ ['channel', "UPDATE sessions SET status='archived' WHERE id='caller'"],+ ['channel', "UPDATE sessions SET remote_host_id='ssh-host' WHERE id='caller'"],+ ['channel', "UPDATE bot_profiles SET status='paused'"],+ ['channel', 'UPDATE bot_session_links SET archived_at=1'],+] as const)('does not claim creation from an ineligible caller (%s, %s)', async (role, update) => {+ const f = fixture(role);+ try {+ if (update) f.sqlite.exec(update);+ expect(await f.captureBotCreatedTaskResponsibility('caller')).toBeNull();+ expect(f.save).not.toHaveBeenCalled();+ expect(f.broadcast).not.toHaveBeenCalled();+ } finally { f.sqlite.close(); }+});diff --git a/apps/desktop/src/main/maker-ipc/botWorkbenchTools.ts b/apps/desktop/src/main/maker-ipc/botWorkbenchTools.tsindex 4d65a59c84..6944cf142c 100644--- a/apps/desktop/src/main/maker-ipc/botWorkbenchTools.ts+++ b/apps/desktop/src/main/maker-ipc/botWorkbenchTools.ts@@ -8,7 +8,7 @@* 跨电脑 send_to_session 的同一条通路),由调用方注入;停止走通用的 stop_session_turn。* 2026-10-17 放弃「项目」:不再按目录发现候选、不再现算项目素材、不再导入本机外部会话。*/-import { and, desc, eq, isNotNull } from 'drizzle-orm';+import { and, desc, eq, inArray, isNotNull, isNull } from 'drizzle-orm';import { hasTaskActionAuthorization, assertTaskActionCurrent } from './taskActionAuthorization.js';import { getDbClient } from '../localDb/client/current.js';@@ -135,13 +135,33 @@ export async function readBotResponsibilityScope(};}+/** Creation attribution is not workbench authorization: channel/group conversations can create tasks too. */+async function resolveBotTaskCreator(callerSessionId: string): Promise<string | null> {+ const [row] = await getDbClient().drizzle+ .select({ botId: botSessionLinks.botId })+ .from(botSessionLinks)+ .innerJoin(sessions, eq(sessions.id, botSessionLinks.sessionId))+ .innerJoin(botProfiles, eq(botProfiles.id, botSessionLinks.botId))+ .where(and(+ eq(botSessionLinks.sessionId, callerSessionId),+ inArray(botSessionLinks.role, ['canonical', 'thread', 'channel', 'group']),+ isNull(botSessionLinks.archivedAt),+ eq(sessions.source, 'bot'),+ eq(sessions.status, 'active'),+ isNull(sessions.remoteHostId),+ eq(botProfiles.status, 'active'),+ ))+ .limit(1);+ return row?.botId ?? null;+}+/** Capture the creator before a generic create-mode handoff crosses async boundaries. */export async function captureBotCreatedTaskResponsibility(callerSessionId?: string) {if (!callerSessionId || isAppSessionBoundaryPending()) return null;const scope = activeOwnerScopeKey();const root = ownerScopedUserDataPath();- const caller = await resolveWorkbenchCaller(callerSessionId);- if (!caller.ok) return null;+ const botId = await resolveBotTaskCreator(callerSessionId);+ if (!botId) return null;const assertCurrent = () => {if (isAppSessionBoundaryPending() || activeOwnerScopeKey() !== scope) throw new Error('OWNER_SCOPE_CHANGED');};@@ -151,8 +171,8 @@ export async function captureBotCreatedTaskResponsibility(callerSessionId?: striconst target = await readWorkbenchTarget(sessionId);if (!target || target.status !== 'active' || target.botLinked || target.remoteHostId || target.orcaRole === 'worker') return;assertCurrent();- await setTaskResponsibility(root, caller.botId, sessionId, true, assertCurrent);- broadcastBotWorkbenchChanged(caller.botId);+ await setTaskResponsibility(root, botId, sessionId, true, assertCurrent);+ broadcastBotWorkbenchChanged(botId);};}diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/botTaskCreationResponsibility.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/botTaskCreationResponsibility.test.tsindex cf43ab53e0..029150e293 100644--- a/apps/desktop/src/main/mcp-integrations/__tests__/botTaskCreationResponsibility.test.ts+++ b/apps/desktop/src/main/mcp-integrations/__tests__/botTaskCreationResponsibility.test.ts@@ -64,7 +64,7 @@ it.each(['ordinary-caller', 'remote-target', 'worker-target', 'owner-switch'])('isAppSessionBoundaryPending: () => false,activeOwnerScopeKey: () => owner,ownerScopedUserDataPath: () => '/synthetic-owner-home',- resolveWorkbenchCaller: async () => reason === 'ordinary-caller' ? { ok: false } : { ok: true, botId: 'creator' },+ resolveBotTaskCreator: async () => reason === 'ordinary-caller' ? null : 'creator',readWorkbenchTarget: async () => ({ status: 'active', botLinked: false, remoteHostId: reason === 'remote-target' ? 'remote' : null, orcaRole: reason === 'worker-target' ? 'worker' : null }),setTaskResponsibility: save,broadcastBotWorkbenchChanged: vi.fn(),