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(bot-autonomy): 共享给访客的任务不触发伙伴自主跟进

Chris5155f7c8e6b4
diff --git a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
index 8e976e04e0..0d66e1c4c5 100644
--- a/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
+++ b/apps/desktop/src/main/bot-autonomy/__tests__/taskWatch.test.ts
@@ -198,6 +198,15 @@ describe('TaskWatch local observation', () => {
});
});
+ // 依据:共享给访客的任务里有账号外的人发的话,不能借事件叫醒以主人权限运行的伙伴。最小失败输入:来源 shared。
+ it('shows a task shared with guests but gives it no follower', async () => {
+ const h = harness({ metas: [meta('guest', { source: 'shared' })] });
+ await h.watch.start();
+ h.watch.applyActivity('guest', activity('guest', 'running'));
+ await h.watch.settled();
+ expect(h.watch.get('guest')).toMatchObject({ phase: 'running', shared: true, followerBotId: null });
+ });
+
it('restarts the wait clock when a local task moves from one question to another', async () => {
const h = harness({ metas: [meta('q')] });
await h.watch.start();
diff --git a/apps/desktop/src/main/bot-autonomy/taskWatch.ts b/apps/desktop/src/main/bot-autonomy/taskWatch.ts
index 8353d47ea9..7396c6a264 100644
--- a/apps/desktop/src/main/bot-autonomy/taskWatch.ts
+++ b/apps/desktop/src/main/bot-autonomy/taskWatch.ts
@@ -407,6 +407,7 @@ export class TaskWatch {
canonicalOfBotId,
followerBotId: null,
source: localSource(meta, creatorBotId),
+ ...(meta.source === 'shared' ? { shared: true } : {}),
};
row.followerBotId = this.followerFor(row);
if (phase === 'finished' && previous?.phase !== 'finished') this.recordFinished(row, now);
@@ -456,6 +457,7 @@ export class TaskWatch {
canonicalOfBotId,
followerBotId: null,
source: localSource(meta, creatorBotId),
+ ...(meta.source === 'shared' ? { shared: true } : {}),
};
row.followerBotId = this.followerFor(row);
this.rows.set(meta.id, row);
@@ -463,10 +465,12 @@ export class TaskWatch {
}
}
- private followerFor(row: Pick<WatchedSession, 'creatorBotId' | 'deviceId' | 'canonicalOfBotId'>): string | null {
+ private followerFor(row: Pick<WatchedSession, 'creatorBotId' | 'deviceId' | 'canonicalOfBotId' | 'shared'>): string | null {
// 每台电脑上的任务由那台电脑上的伙伴跟:两台电脑上的同名伙伴(如各自的 Cindy 助理)不会各跟一遍。
// 另一台电脑的行只进工作台给主人看与允许;总调度仍可经工具显式继续它。
if (row.deviceId !== null) return null;
+ // 共享任务里有访客发的话:不能让账号外的内容叫醒以主人权限运行的伙伴,等你时直接提醒主人。
+ if (row.shared) return null;
const follower = deriveFollowerBotId({
creatorBotId: row.creatorBotId,
schedulerBotId: this.schedulerBotId,
@@ -787,6 +791,7 @@ export class TaskWatch {
creatorBotId: null,
followerBotId: null,
source: meta.source === 'scheduler' ? 'routine' : USER_SOURCES.has(String(meta.source ?? 'desktop')) ? 'user' : 'other',
+ ...(meta.source === 'shared' ? { shared: true } : {}),
};
row.followerBotId = this.followerFor(row);
if (phase === 'finished' && previous?.phase !== 'finished') this.recordFinished(row, now);
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchAccess.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchAccess.test.ts
index d5a298a1de..411d2fc3f5 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchAccess.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botWorkbenchAccess.test.ts
@@ -8,7 +8,8 @@
* 自己开的或明确接手的任务;目录不授予任何权限;总调度身份查不到时 fail closed。
* - 现有覆盖缺口:旧用例按项目目录授权,规则已整体替换;新授权矩阵此前没有任何覆盖。
* - 最小失败输入:总调度 / 开任务的伙伴 / 无关伙伴 × 普通任务、伙伴专线、后台任务、归档任务、
- * 另一台电脑上的任务;别的伙伴开的任务(跟进人是它 / 已交给总调度);观察层没有这一行。
+ * 另一台电脑上的任务;别的伙伴开的任务(跟进人是它 / 已交给总调度);观察层没有这一行;
+ * 共享给访客的任务(访客的话不能借伙伴之手推动主人账号里的事)。
* - tier:unit(依赖全部注入,无数据库与 Electron)。
*/
import { describe, expect, it, vi } from 'vitest';
@@ -36,9 +37,10 @@ const TARGETS: Record<string, WorkbenchTargetFacts> = {
'writer-created': ordinary('writer-created'),
'writer-handed': ordinary('writer-handed'),
'scheduler-created': ordinary('scheduler-created'),
+ 'shared-task': ordinary('shared-task', { source: 'shared' }),
};
/** 观察层状态行:creator / follower 由宿主按伙伴设置推导。im-task 与 laptop::s-3 故意没有行。 */
-const WATCHED: Record<string, { creatorBotId: string | null; followerBotId: string | null }> = {
+const WATCHED: Record<string, { creatorBotId: string | null; followerBotId: string | null; shared?: boolean }> = {
'owner-task': { creatorBotId: null, followerBotId: 'cindy-default' },
'writer-child': { creatorBotId: 'writer', followerBotId: 'writer' },
'writer-created': { creatorBotId: 'writer', followerBotId: 'writer' },
@@ -46,6 +48,7 @@ const WATCHED: Record<string, { creatorBotId: string | null; followerBotId: stri
'scheduler-created': { creatorBotId: 'cindy-default', followerBotId: 'cindy-default' },
'laptop::s-1': { creatorBotId: null, followerBotId: 'cindy-default' },
'laptop::s-2': { creatorBotId: 'writer', followerBotId: 'writer' },
+ 'laptop::s-4': { creatorBotId: null, followerBotId: null, shared: true },
};
function setup(options: { scheduler?: string | null; watched?: boolean } = {}) {
@@ -85,6 +88,9 @@ describe('workbench authorization matrix', () => {
['main-scheduler', 'scheduler-created', 'ok', 'ok'],
['main-scheduler', 'laptop::s-2', 'ok', 'TASK_FOLLOWED_BY_OTHER_BOT'],
['main-scheduler', 'laptop::s-3', 'ok', 'TASK_FOLLOWED_BY_OTHER_BOT'],
+ // 共享给访客的任务里有账号外的人发的话:可以看,不能经工作台推动(本机与另一台电脑)。
+ ['main-scheduler', 'shared-task', 'ok', 'TASK_SHARED_WITH_GUESTS'],
+ ['main-scheduler', 'laptop::s-4', 'ok', 'TASK_SHARED_WITH_GUESTS'],
['main-scheduler', 'bot-lane', 'TASK_NOT_ACCESSIBLE', 'TASK_NOT_ACCESSIBLE'],
['main-scheduler', 'archived-task', 'ok', 'TASK_ARCHIVED'],
['main-scheduler', 'review-task', 'TASK_NOT_SUPPORTED', 'TASK_NOT_SUPPORTED'],
diff --git a/apps/desktop/src/main/maker-ipc/botWorkbenchAccess.ts b/apps/desktop/src/main/maker-ipc/botWorkbenchAccess.ts
index 10414e20d7..35416b2879 100644
--- a/apps/desktop/src/main/maker-ipc/botWorkbenchAccess.ts
+++ b/apps/desktop/src/main/maker-ipc/botWorkbenchAccess.ts
@@ -83,6 +83,13 @@ export interface WorkbenchGrant {
followedByOtherBot?: string | null;
}
+/** 共享给访客的任务里有账号外的人发的话:伙伴不能经工作台推动它,只能告诉主人。 */
+const sharedTaskNotContinuable: Failure = {
+ ok: false,
+ errorCode: 'TASK_SHARED_WITH_GUESTS',
+ message: '这件任务共享给了访客,里面有账号外的人发的话;伙伴不能替主人继续它,请告诉主人由他自己处理。',
+};
+
/** 总调度对别的伙伴开的任务默认只看不跟。 */
export function followedByOtherBotFailure(creatorBotId: string): Failure {
const who = creatorBotId === 'unknown' ? '另一位伙伴' : `伙伴 ${creatorBotId}`;
@@ -152,7 +159,7 @@ export interface BotWorkbenchAccessDeps {
/** 当前总调度伙伴 id;观察层未就绪时返回 null(按不是总调度处理)。 */
schedulerBotId(): Promise<string | null>;
/** 观察层状态表的一行(本机裸 id / 远程 deviceId::sessionId);读不到返回 null。 */
- readWatched(taskKey: string): Pick<WatchedSession, 'creatorBotId' | 'followerBotId'> | null;
+ readWatched(taskKey: string): Pick<WatchedSession, 'creatorBotId' | 'followerBotId' | 'shared'> | null;
readResponsibleSessionIds(botId: string): Promise<string[]>;
saveResponsibility(botId: string, sessionId: string, responsible: boolean): Promise<void>;
/** 该伙伴自己的后台任务:执行任务 id → 状态。 */
@@ -218,6 +225,7 @@ export function createBotWorkbenchAccess(deps: BotWorkbenchAccessDeps) {
};
if (ref.kind === 'remote') {
if (!scheduler) return remoteNotAllowed;
+ if (mode === 'continue' && watched()?.shared) return sharedTaskNotContinuable;
if (mode === 'continue') {
const other = followedByOtherBot(botId, watched(), { remote: true, delegationChild: false });
if (other) return followedByOtherBotFailure(other);
@@ -225,6 +233,7 @@ export function createBotWorkbenchAccess(deps: BotWorkbenchAccessDeps) {
return { ok: true, ref, taskId: `${ref.deviceId}::${ref.sessionId}` };
}
const target = await deps.readTarget(ref.sessionId);
+ if (mode === 'continue' && target?.source === 'shared') return sharedTaskNotContinuable;
const grant = await grantFor(botId, ref.sessionId, scheduler);
if (scheduler && mode === 'continue' && target) {
grant.followedByOtherBot = followedByOtherBot(botId, watched(), {
diff --git a/apps/desktop/src/main/mcp-integrations/__tests__/taskDigest.test.ts b/apps/desktop/src/main/mcp-integrations/__tests__/taskDigest.test.ts
index 4a55f2d0d1..37013fa625 100644
--- a/apps/desktop/src/main/mcp-integrations/__tests__/taskDigest.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/__tests__/taskDigest.test.ts
@@ -21,7 +21,9 @@ function setup(watched: Record<string, WatchedSession> = {}) {
now: () => NOW,
watched: (key) => watched[key] ?? null,
local: {
- readSession: async (id) => (id === 'gone' ? { title: 'x', status: 'deleted', route: null } : id === 'local-1' ? { title: '修登录', status: 'active', route } : null),
+ readSession: async (id) => (id === 'gone' ? { title: 'x', status: 'deleted', route: null }
+ : id === 'local-1' ? { title: '修登录', status: 'active', route }
+ : id === 'shared-1' ? { title: '和访客一起改文案', status: 'active', route, shared: true } : null),
readActivity: async () => ({ phase: 'needs-interaction', interactionKind: 'permission', lastActivityAtMs: NOW - 9 * 60_000, runtimeGeneration: 4, route }),
readLastExchange: async () => ({ lastUserAsk: '修登录', lastAssistantLine: '要删旧表吗?' }),
queuedCount: async () => 2,
@@ -43,6 +45,16 @@ function setup(watched: Record<string, WatchedSession> = {}) {
}
describe('task digest assembly', () => {
+ // 依据:共享任务里最近一句「用户」可能是访客写的;摘要原样交给伙伴就成了账号外的人借伙伴下指令。
+ // 最小失败输入:来源 shared 的本机任务。
+ it('leaves out the conversation text of a task shared with guests and flags it', async () => {
+ const { read } = setup();
+ const result = await read({ sessionId: 'shared-1', callerSessionId: 'bot-main' });
+ expect(result).toMatchObject({ ok: true, digest: { last_user_ask: null, last_assistant_line: null, shared_task: true } });
+ expect(sessionFactsFromRow({ title: 't', status: 'active', source: 'shared' })).toMatchObject({ shared: true });
+ expect(sessionFactsFromRow({ title: 't', status: 'active', source: 'desktop' })?.shared).toBeUndefined();
+ });
+
it('builds a local digest, inferring the phase when the watcher has no row and surviving a failed PR read', async () => {
const { read, deps } = setup();
const result = await read({ sessionId: 'local-1', callerSessionId: 'bot-main' });
@@ -76,8 +88,9 @@ describe('task digest assembly', () => {
const withFlag = setup({ 'local-1': busy, 'laptop::s-1': remoteIdle });
expect(await withFlag.read({ sessionId: 'local-1' })).toMatchObject({ ok: true, digest: { phase: 'running', tool_in_flight: true } });
expect(await withFlag.read({ sessionId: 'laptop::s-1' })).not.toHaveProperty('digest.tool_in_flight');
- const { toolInFlight: _omitted, ...noFact } = busy;
- expect(await setup({ 'local-1': noFact }).read({ sessionId: 'local-1' })).not.toHaveProperty('digest.tool_in_flight');
+ const noFact: Partial<typeof busy> = { ...busy };
+ delete noFact.toolInFlight;
+ expect(await setup({ 'local-1': noFact as WatchedSession }).read({ sessionId: 'local-1' })).not.toHaveProperty('digest.tool_in_flight');
});
it('reads another computer without a route suggestion, and reports offline or missing tasks explicitly', async () => {
diff --git a/apps/desktop/src/main/mcp-integrations/taskDigest.ts b/apps/desktop/src/main/mcp-integrations/taskDigest.ts
index f0e1904e7a..3d040309ec 100644
--- a/apps/desktop/src/main/mcp-integrations/taskDigest.ts
+++ b/apps/desktop/src/main/mcp-integrations/taskDigest.ts
@@ -15,6 +15,8 @@ export interface TaskDigestSessionFacts {
title: string;
status: string;
route: TaskDigestRoute | null;
+ /** 共享给访客的任务(来源 shared):摘要不带对话原文。 */
+ shared?: boolean;
}
export interface TaskDigestActivity {
@@ -208,8 +210,9 @@ function assemble(input: {
phase,
elapsed_minutes: minutesSince(input.now, since),
idle_minutes: minutesSince(input.now, watched?.lastActivityAt ?? activity?.lastActivityAtMs),
- last_user_ask: input.exchange.lastUserAsk,
- last_assistant_line: input.exchange.lastAssistantLine,
+ // 共享任务里最近一句「用户」可能是访客写的:不交给伙伴当指令看。
+ last_user_ask: input.facts.shared ? null : input.exchange.lastUserAsk,
+ last_assistant_line: input.facts.shared ? null : input.exchange.lastAssistantLine,
pending_question: watched?.pendingQuestion ?? null,
error: watched?.error ?? null,
current_route: activity?.route ?? input.facts.route,
@@ -220,6 +223,7 @@ function assemble(input: {
follower_bot_id: watched?.followerBotId ?? null,
creator_bot_id: watched?.creatorBotId ?? null,
...(toolInFlight === undefined ? {} : { tool_in_flight: toolInFlight }),
+ ...(input.facts.shared ? { shared_task: true } : {}),
};
}
@@ -252,6 +256,7 @@ export function sessionFactsFromRow(row: unknown): TaskDigestSessionFacts | null
return {
title: text(record.title) ?? '',
status: text(record.status) ?? 'active',
+ ...(text(record.source) === 'shared' ? { shared: true } : {}),
route: harness && model
? {
harness,
diff --git a/apps/desktop/src/main/mcp-integrations/taskDigestHost.ts b/apps/desktop/src/main/mcp-integrations/taskDigestHost.ts
index efab0cb5fa..044e7359cc 100644
--- a/apps/desktop/src/main/mcp-integrations/taskDigestHost.ts
+++ b/apps/desktop/src/main/mcp-integrations/taskDigestHost.ts
@@ -145,6 +145,7 @@ export function createDesktopTaskDigestDeps(host: DesktopTaskDigestHost): TaskDi
.drizzle.select({
title: sessions.title,
status: sessions.status,
+ source: sessions.source,
agentKind: sessions.agentKind,
model: sessions.model,
providerId: sessions.providerId,
diff --git a/apps/desktop/src/shared/botAutonomy.ts b/apps/desktop/src/shared/botAutonomy.ts
index 844d175272..f3afa607ac 100644
--- a/apps/desktop/src/shared/botAutonomy.ts
+++ b/apps/desktop/src/shared/botAutonomy.ts
@@ -97,6 +97,10 @@ export interface WatchedSession {
*/
followerBotId: string | null;
source: WatchedSource;
+ /**
+ * 共享给访客的任务(来源 shared):里面有账号外的人发的话。不叫醒任何伙伴、不让伙伴自动继续,只进工作台给主人看。
+ */
+ shared?: boolean;
}
/** `sweep`:条件兜底(按伙伴、不针对单个任务;subject 为伙伴 id,任务字段为空串)。 */
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index a585f6d5b0..f7d005331b 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -638,6 +638,7 @@ Session 任务遵守同一套机制与呈现契约:
- 它暂停、已不在或不是本机主力电脑(云端伙伴在别处运行)时,只有它在资料里打开「它开的任务也交给总调度跟」
(`capabilities.allowSchedulerFollow`,缺省 false)才落到总调度,否则没人跟。
- 没有伙伴来源的本机任务(主人自己开的)由总调度跟。
+- 共享给访客的任务(来源 `shared`)没人跟:里面有账号外的人发的话,不能借事件叫醒以主人权限运行的伙伴。它只进工作台,「等你」超过阈值时直接提醒主人;任务摘要不带对话原文(标 `shared_task`),工作台工具也不能继续它(`TASK_SHARED_WITH_GUESTS`)。
- 另一台电脑上的任务恒为 null:由那台电脑上的伙伴跟(见 6.3.1),这台电脑只在工作台里显示。
- 没有可用总调度时为 null:不叫醒任何伙伴,只在工作台里能看到;本机任务「等你」超过阈值时宿主直接发系统提醒
(桌面通知 + 手机推送,主窗口在前台时不弹桌面通知),同一事件只提醒一次。跟进者的内置规则被主人暂停时同样处理。
diff --git a/packages/lizi-mcps/src/xdt-helper/get_task_digest.ts b/packages/lizi-mcps/src/xdt-helper/get_task_digest.ts
index 449e48cca6..71a181ca67 100644
--- a/packages/lizi-mcps/src/xdt-helper/get_task_digest.ts
+++ b/packages/lizi-mcps/src/xdt-helper/get_task_digest.ts
@@ -56,6 +56,11 @@ export interface TaskDigestWire {
queued_count: number | null;
follower_bot_id: string | null;
creator_bot_id: string | null;
+ /**
+ * 共享给访客的任务:里面有账号外的人发的话。为 true 时不给 last_user_ask / last_assistant_line,
+ * 伙伴不得据它自主行动,只告诉主人。
+ */
+ shared_task?: boolean;
}
export const TASK_DIGEST_MAX_BYTES = 2048;