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(bots): 从本机旧式群启动的任务如实告诉伙伴结果会私下交给主人

Chriscc3477e1200e
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index 32ed70e09c..bb81ee8689 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -3859,6 +3859,7 @@ describe('Bot Session task end-to-end runtime', () => {
onInteractionDispatched?: () => Promise<void>;
/** The group message channel for tasks started from a group (bot-group-chat.md §10). */
postGroupTaskMessage?: Parameters<typeof createBotDelegationService>[0]['postGroupTaskMessage'];
+ groupHasTaskChannel?: Parameters<typeof createBotDelegationService>[0]['groupHasTaskChannel'];
} = {}) {
const accountReady = options.accountReady ?? (() => true);
const started: StartedTurn[] = [];
@@ -4074,6 +4075,7 @@ describe('Bot Session task end-to-end runtime', () => {
const delegation = createBotDelegationService({
maxActiveChildren: options.maxActiveChildren,
postGroupTaskMessage: options.postGroupTaskMessage,
+ groupHasTaskChannel: options.groupHasTaskChannel,
readSessionExecution: options.readSessionExecution,
collectArtifacts: options.collectArtifacts,
discardDelegationQueuedInputs: options.discardDelegationQueuedInputs ?? (coordinator
@@ -4288,6 +4290,18 @@ describe('Bot Session task end-to-end runtime', () => {
} finally { release(); runtime.dispose(); }
});
+ it('tells the teammate a task from an old local-only group reports to the owner privately', async () => {
+ await seedPair(); seedGroupLane();
+ const release = registerGroupToolAuthority('group-lane', { botId: 'bot-a', mode: 'owner', isCurrent: () => true, validate: async () => {} });
+ const groupHasTaskChannel = vi.fn(async () => false);
+ const runtime = createDelegationRuntime({ groupHasTaskChannel });
+ try {
+ const task = await runtime.delegation.startSessionTask({ callerSessionId: 'group-lane', objective: 'Local group work' });
+ expect(task).toMatchObject({ ok: true, completionDestination: 'private' });
+ expect(groupHasTaskChannel).toHaveBeenCalledWith('fixture');
+ } finally { release(); runtime.dispose(); }
+ });
+
it('lets the owner stop a group task from its card after the group reply that started it has ended', async () => {
await seedPair(); seedGroupLane();
const release = registerGroupToolAuthority('group-lane', { botId: 'bot-a', mode: 'owner', isCurrent: () => true, validate: async () => {} });
diff --git a/apps/desktop/src/main/maker-ipc/botDelegationService.ts b/apps/desktop/src/main/maker-ipc/botDelegationService.ts
index bb5397e72b..fb2fdc5043 100644
--- a/apps/desktop/src/main/maker-ipc/botDelegationService.ts
+++ b/apps/desktop/src/main/maker-ipc/botDelegationService.ts
@@ -200,6 +200,11 @@ export interface BotDelegationServiceDeps {
* refusal (not retryable) falls back to the owner's private chat so no result is lost.
*/
postGroupTaskMessage?: (input: BotGroupTaskPostInput) => Promise<BotGroupTaskPostResult>;
+ /**
+ * Whether a group can carry a teammate's own task messages (a Chat Server room). An old
+ * local-only group cannot: its task's confirmations and result go to the owner's private chat.
+ */
+ groupHasTaskChannel?: (groupId: string) => Promise<boolean>;
now?: () => number;
createId?: () => string;
maxActiveChildren?: number;
@@ -2568,8 +2573,12 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {
input: SessionTaskInput,
): Promise<BotDelegationResult<{
modelRoute: BotModelRoute;
- /** `group`: the card, confirmations and result stay in the group this was started from. */
- completionDestination?: 'group';
+ /**
+ * `group`: the card, confirmations and result stay in the group this was started from.
+ * `private`: started from an old local-only group, which cannot carry them; they go to the
+ * owner's private chat with the teammate instead (bot-group-chat.md §10).
+ */
+ completionDestination?: 'group' | 'private';
delegationId: string;
childSessionId: string;
/**
@@ -2699,13 +2708,16 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {
},
});
if (!started.ok) return started;
+ const groupId = caller.role === 'group' ? /^group:([^:]+)/.exec(caller.routeKey ?? '')?.[1] ?? null : null;
+ const completionDestination = groupId === null ? null
+ : await deps.groupHasTaskChannel?.(groupId).catch(() => true) === false ? 'private' as const : 'group' as const;
return {
ok: true,
delegationId: started.delegationId,
childSessionId: started.childSessionId,
status: started.status,
deadlineAt: started.deadlineAt,
- ...(caller.role === 'group' ? { completionDestination: 'group' as const } : {}),
+ ...(completionDestination ? { completionDestination } : {}),
modelRoute: {
harness: taskRuntime.agentKind === 'codex' ? 'codex' : taskRuntime.agentKind === 'pi' ? 'pi' : 'claude',
model: taskRuntime.model,
diff --git a/apps/desktop/src/main/maker-ipc/botGroupChatService.ts b/apps/desktop/src/main/maker-ipc/botGroupChatService.ts
index 82e13f7796..da86e6955d 100644
--- a/apps/desktop/src/main/maker-ipc/botGroupChatService.ts
+++ b/apps/desktop/src/main/maker-ipc/botGroupChatService.ts
@@ -2173,6 +2173,7 @@ export function createBotGroupChatService(deps: BotGroupChatServiceDeps) {
/** Only a server room has a message channel a teammate can post into outside a turn. */
postCompanionTaskMessage: async (_input: BotGroupTaskPostInput): Promise<BotGroupTaskPostResult> =>
({ ok: false, errorCode: 'GROUP_CHANNEL_UNAVAILABLE', retryable: false }),
+ hasCompanionTaskChannel: async (_groupId: string): Promise<boolean> => false,
dispose,
};
}
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 329cf192c8..b22fa49123 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -199,6 +199,7 @@ export function withChatServer(local: BotGroupChatService, deps: BotGroupChatSer
editPlanStep: (...args) => service().editPlanStep(...args),
settleLaneTurn: (...args) => service().settleLaneTurn(...args),
postCompanionTaskMessage: (...args) => service().postCompanionTaskMessage(...args),
+ hasCompanionTaskChannel: (...args) => service().hasCompanionTaskChannel(...args),
dispose: () => { active.dispose(); local.dispose(); },
};
}
@@ -1584,6 +1585,8 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
},
// A teammate's own message about an independent task it started from this group
// (bot-group-chat.md §10): posted outside any execution, as that teammate, never as the owner.
+ /** A server room (or an old local group already upgraded to one) carries task messages. */
+ hasCompanionTaskChannel: async (groupId: string): Promise<boolean> => (await taskRoomFor(groupId)) !== null,
postCompanionTaskMessage: async (input: BotGroupTaskPostInput): Promise<BotGroupTaskPostResult> => {
const refused = (errorCode: string): BotGroupTaskPostResult => ({ ok: false, errorCode, retryable: false });
try {
diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.ts
index 3a097a9a06..79aae9eef5 100644
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@ -12031,6 +12031,8 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)
postGroupTaskMessage: async (input) => botGroupChatServiceHolder
? botGroupChatServiceHolder.postCompanionTaskMessage(input)
: { ok: false as const, errorCode: 'GROUP_CHANNEL_UNAVAILABLE', retryable: true },
+ groupHasTaskChannel: async (groupId) => botGroupChatServiceHolder
+ ? botGroupChatServiceHolder.hasCompanionTaskChannel(groupId) : true,
});
registerBotLifecycleHandlers({
maker,
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index 30f6e65247..5d43bfc8a4 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -349,7 +349,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授
群专线的 `role=group` 是来源身份,不等于只读历史任务,也不单独构成授权。读取自己的 Profile、能力与 Skill 目录时,必须核对活跃执行、伙伴归属、成员状态、授权版本及执行租约;只聊天的专线仍不可读取私人资料。群主身份不能替代伙伴主人身份。
-只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机按该伙伴的主力电脑读,不论群是经哪台电脑打开还是直接从 Chat Server 进入;主力电脑未知时,经电脑打开的群读那台电脑,直接进入的群退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。
+只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么;从本机旧式群(没有服务器房间)启动时返回 `completion_destination=private`,伙伴告诉群里结果会私下交给主人,不承诺在群里更新。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机按该伙伴的主力电脑读,不论群是经哪台电脑打开还是直接从 Chat Server 进入;主力电脑未知时,经电脑打开的群读那台电脑,直接进入的群退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。
非主人群工具授权仅允许读取伙伴自身资料、已选能力和自己的技能;应用级能力目录与默认模型查询仍须当前主人执行授权。
diff --git a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
index 6a5e7d96de..48f5383bd6 100644
--- a/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
+++ b/packages/lizi-mcps/src/__tests__/lizi_xdtHelperMcpServer.test.ts
@@ -430,6 +430,18 @@ describe("cindy_helper MCP server", () => {
}),
);
+ // An old local-only group cannot carry the task's messages: the teammate must not promise them there.
+ startSessionTask.mockResolvedValueOnce({ ok: true as const, delegationId: "session-task-2", childSessionId: "desktop-child-2",
+ status: "running", completionDestination: 'private', deadlineAt: 1_788_000_000_000 });
+ const privateTask = parsePayload(
+ await client.callTool({ name: "call_tool", arguments: { name: "start_session_task", args: {
+ instruction: "Build and verify a standalone HTML demo.",
+ } } }),
+ ) as { completion_destination?: string; guidance?: string };
+ expect(privateTask.completion_destination).toBe('private');
+ expect(privateTask.guidance).toContain("private chat");
+ expect(privateTask.guidance).not.toContain("will arrive here");
+
const replied = parsePayload(
await client.callTool({ name: "call_tool", arguments: { name: "message_session_task", args: {
task_id: "session-task-1",
diff --git a/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts b/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts
index d8db28550c..4de7a21e90 100644
--- a/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts
+++ b/packages/lizi-mcps/src/lizi_xdtHelperMcpServer.ts
@@ -430,7 +430,9 @@ function registerStartSessionTaskEntry(
guidance:
(result.completionDestination === 'group'
? 'This task lives in this group: its card is already posted here, and anything it needs confirmed plus its final result will arrive here as your own messages. Tell the group briefly what you started; do not promise a private-chat update. '
- : '') + "The task card tracks progress and the result will return automatically. Do not start it again. Treat model_route and task/session ids as internal bookkeeping; do not echo them or the delegated instruction in ordinary replies unless the user asks for these details.",
+ : result.completionDestination === 'private'
+ ? 'This older group cannot carry task messages: anything the task needs confirmed and its final result go to your owner\'s private chat with you, not here. Tell the group briefly what you started and that the result will reach your owner privately. '
+ : '') + "The task card tracks progress and the result will return automatically. Do not start it again. Treat model_route and task/session ids as internal bookkeeping; do not echo them or the delegated instruction in ordinary replies unless the user asks for these details.",
})
: errorPayload(result.errorCode, result.message);
},