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(desktop): run queue turns in their own dialogue lane

zqchris683f05554122
diff --git a/apps/desktop/src/main/localDb/ipc/bots.ts b/apps/desktop/src/main/localDb/ipc/bots.ts
index 45dc9b12df..3874456b94 100644
--- a/apps/desktop/src/main/localDb/ipc/bots.ts
+++ b/apps/desktop/src/main/localDb/ipc/bots.ts
@@ -105,7 +105,7 @@ import { generateBotCreationDraft, readBotCreationDraft, generateBotCreationAvat
import { botInvitationProgress, type BotInvitationProgress } from '../../../shared/botInvitation.js';
import type { BotPackageOpening } from '../../../shared/botMarket.js';
import { botDmThreadRouteKey, parseBotDmThreadRouteKey, type BotDmThreadSummary } from '../../../shared/botDmThread.js';
-import { botGroupLaneRouteKey, botGroupPlanRouteKey, chatGroupLaneRouteKey, chatGroupThreadRouteKey, groupLaneOfRouteKey, parseBotGroupIdFromRouteKey, type ChatLaneAccess } from '../../../shared/botGroupChat.js';
+import { botGroupLaneRouteKey, botGroupPlanRouteKey, chatGroupLaneRouteKey, chatGroupTalkRouteKey, chatGroupThreadRouteKey, groupLaneOfRouteKey, parseBotGroupIdFromRouteKey, type ChatLaneAccess } from '../../../shared/botGroupChat.js';
import { queueBotInvitation as enqueueBotInvitation } from '../../maker-ipc/botInvitation.js';
import { getMakerIfReady, validateBotCapabilityAdditions } from '../../maker-host/index.js';
import type { BotCapabilityUpdate } from '../../maker-ipc/botCapabilityService.js';
@@ -313,6 +313,9 @@ export type EnsureBotGroupLaneResult =
*
* With `threadRootId` (server groups only), the Bot's own lane for that Thread: same
* Profile, model chain and working place as the group lane, but its own context.
+ *
+ * With `talkPlanId` (server groups only), the Bot's own lane for that queue: like a Thread
+ * lane, it talks in the group lane's place with its own context; no project folder.
*/
export async function ensureBotGroupLaneSession(input: {
botId: string;
@@ -321,12 +324,14 @@ export async function ensureBotGroupLaneSession(input: {
chatAccess?: ChatLaneAccess;
plan?: { planId: string; workDir: string; sessionId?: string };
threadRootId?: string;
+ talkPlanId?: string;
}): Promise<EnsureBotGroupLaneResult> {
const owner = captureBotOperationOwner();
const client = getDbClient();
const db = client.drizzle;
const routeKey = input.plan
? input.chatAccess ? `${chatGroupLaneRouteKey(input.groupId, input.chatAccess)}:plan:${input.plan.planId}` : botGroupPlanRouteKey(input.groupId, input.plan.planId)
+ : input.chatAccess && input.talkPlanId ? chatGroupTalkRouteKey(input.groupId, input.chatAccess, input.talkPlanId)
: input.chatAccess && input.threadRootId ? chatGroupThreadRouteKey(input.groupId, input.chatAccess, input.threadRootId)
: input.chatAccess ? chatGroupLaneRouteKey(input.groupId, input.chatAccess) : botGroupLaneRouteKey(input.groupId);
const [existing] = await db
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botGroupLaneTx.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botGroupLaneTx.test.ts
index ae59782f25..370838ea76 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botGroupLaneTx.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botGroupLaneTx.test.ts
@@ -15,7 +15,7 @@ vi.mock('../../localDb/client/current.js', async () => {
import { tx } from '../../localDb/worker/opHandlers/tx.js';
import { BotPlanWorkDirUnavailableError, prepareBotWorkspaceRuntime } from '../botWorkspaceRuntime.js';
import { ensureBotChatOnlyWorkspaceDir } from '../botProfileFolder.js';
-import { chatGroupLaneRouteKey } from '../../../shared/botGroupChat.js';
+import { chatGroupLaneRouteKey, chatGroupTalkRouteKey } from '../../../shared/botGroupChat.js';
import type { MakerSessionCreateOpts } from '../sessionRequest.js';
function laneSession(id: string) {
@@ -141,6 +141,20 @@ describe('Bot group lane transactions', () => {
expect(ensureWorkspaceDir).not.toHaveBeenCalled();
});
+ // bot-group-chat.md §7.0: a queue turn has no project folder. It starts where its group lane works:
+ // the teammate's own place, or the grant's isolated chat folder for chat-only access.
+ it.each(['owner', 'tools', 'chat'] as const)('starts a %s queue lane where its group lane works', async mode => {
+ const access = { mode, revision: 1 };
+ const routeKey = chatGroupTalkRouteKey('g1', access, 'queue-1');
+ const workingDir = mode === 'chat' ? await ensureBotChatOnlyWorkspaceDir(ownerRoot, 'mimi', chatGroupLaneRouteKey('g1', access)) : '/private-bot-home';
+ const session = { ...laneSession('queue-step'), workingDir, workspaceKind: 'dialogue' };
+ tx(db, { name: 'bots.createGroupLane', args: { botId: 'mimi', groupId: 'g1', routeKey, session } });
+ const ensureWorkspaceDir = vi.fn(async () => '/private-bot-home');
+ const opts: MakerSessionCreateOpts = { id: session.id, agentKind: 'claude-code', model: session.model, workingDir: '', workspaceKind: 'project', remoteHostId: 'stale-host' };
+ await prepareBotWorkspaceRuntime(opts, { ownerUserDataPath: () => ownerRoot, ensureWorkspaceDir });
+ expect(opts).toMatchObject({ workingDir, workspaceKind: 'dialogue', remoteHostId: undefined });
+ });
+
it.each(['', ':plan:server-plan'])('isolates chat-only startup%s even with a matching legacy project plan and stale session directory', async suffix => {
const routeKey = `${chatGroupLaneRouteKey('g1', { mode: 'chat', revision: 2 })}${suffix}`;
const workingDir = await ensureBotChatOnlyWorkspaceDir(ownerRoot, 'mimi', routeKey);
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
index edb67c837a..dc4a35defd 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -1478,8 +1478,10 @@ describe('Chat Server result delivery and refresh', () => {
expect(prompt()).toContain('You are turn 2 of 2. Your focus: tests.');
expect(prompt()).not.toContain('unrelated main group chatter');
expect(downloaded).toEqual([answerFile]);
- // A discussion only talks: no project folder or worktree, and a plain lane without a work directory.
- expect(deps.ensureLane).toHaveBeenCalledWith(expect.objectContaining({ plan: { planId, workDir: '', sessionId: undefined } }));
+ // A queue turn only talks: no project folder or worktree, its own queue lane rather than a 分工 lane
+ // (an owner-access 分工 lane without a work directory cannot start).
+ expect(deps.ensureLane).toHaveBeenCalledWith(expect.objectContaining({ talkPlanId: planId }));
+ expect(vi.mocked(deps.ensureLane).mock.calls[0][0]).not.toHaveProperty('plan');
} else {
expect(prompt()).not.toContain('You are turn');
expect(prompt()).toContain('unrelated main group chatter');
diff --git a/apps/desktop/src/main/maker-ipc/botGroupChatService.ts b/apps/desktop/src/main/maker-ipc/botGroupChatService.ts
index 737c91925c..abf271e612 100644
--- a/apps/desktop/src/main/maker-ipc/botGroupChatService.ts
+++ b/apps/desktop/src/main/maker-ipc/botGroupChatService.ts
@@ -113,7 +113,8 @@ export interface BotGroupLaneTerminal {
export interface BotGroupChatServiceDeps {
/**
* With `plan`, the Bot's 分工 Session for that plan (bot-group-chat.md §7.4); with
- * `threadRootId`, the Bot's own lane for that Thread (§3).
+ * `threadRootId`, the Bot's own lane for that Thread (§3); with `talkPlanId`, its own
+ * lane for that queue (§7.0).
*/
ensureLane: (input: {
botId: string;
@@ -122,6 +123,7 @@ export interface BotGroupChatServiceDeps {
chatAccess?: import('../../shared/botGroupChat.js').ChatLaneAccess;
plan?: { planId: string; workDir: string; sessionId?: string };
threadRootId?: string;
+ talkPlanId?: string;
}) => Promise<LaneResult>;
/** Same hidden, durable input path as Bot DMs; attachments go with the turn like a task message's. */
dispatch: (params: {
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 059a363f5a..2816d61f3e 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -1617,7 +1617,9 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
const threadRootId = run.plan ? undefined : source?.threadRootId ?? undefined;
const lane = await deps.ensureLane({ botId: bot.id, groupId: s.room.id, title: s.room.name,
chatAccess: { mode: execution.access_mode, revision: execution.access_revision },
- ...(run.plan ? { plan: { planId: run.plan.id, workDir: run.workspace?.workDir ?? '', sessionId: run.workspace?.ownerSessionId ?? undefined } } : {}),
+ // A queue turn talks in its own lane (no project folder); a division of work runs in its work directory.
+ ...(run.plan?.kind === 'talk' ? { talkPlanId: run.plan.id }
+ : run.plan ? { plan: { planId: run.plan.id, workDir: run.workspace?.workDir ?? '', sessionId: run.workspace?.ownerSessionId ?? undefined } } : {}),
...(threadRootId ? { threadRootId } : {}) });
if (!lane.ok) throw new Error(lane.errorCode);
run.sessionId = lane.sessionId;
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupTimelineItem.tsx b/apps/desktop/src/renderer/features/bots/BotGroupTimelineItem.tsx
index b593f251d4..46b086f713 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupTimelineItem.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupTimelineItem.tsx
@@ -454,7 +454,8 @@ function BotGroupTimelineItemImpl(props: BotGroupTimelineItemProps) {
plan={props.plan}
members={members}
actionable={false}
- reassignable={props.planReassignable ?? false}
+ // Only the creator, an owner or an admin may change who speaks next.
+ reassignable={(props.planReassignable ?? false) && props.plan.canManage !== false}
pending={props.planPending ?? null}
runningSince={props.planRunningSince ?? null}
doneAt={props.planDoneAt}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 53dd74e5a9..b3730aa28a 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -2236,6 +2236,21 @@ describe('BotGroupChatView', () => {
}
});
+ // Only the creator, an owner or an admin may change who speaks next in a waiting queue.
+ it.each([[true, 1], [false, 0]] as const)('offers reassigning a waiting queue turn only to a manager (canManage=%s)', async (canManage, menus) => {
+ const base = plan().steps;
+ const queue = plan({
+ status: 'waiting', currentStep: 0, kind: 'talk', canManage,
+ steps: [{ ...base[0]!, task: '', status: 'done' }, { ...base[1]!, task: '', status: 'pending' }],
+ });
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: withPlan(queue) });
+ renderView();
+ const card = await screen.findByTestId('bot-group-arrangement');
+ const pending = within(card).getAllByTestId('bot-group-plan-step')[1]!;
+ fireEvent.pointerDown(pending, { button: 0, ctrlKey: false });
+ expect(screen.queryAllByRole('menu')).toHaveLength(menus);
+ });
+
it('offers the next step after a hand-off and opens its files inside the work directory', async () => {
const waiting = plan({
status: 'waiting',
diff --git a/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts b/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts
index c6168638a0..7bcf06ce70 100644
--- a/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts
+++ b/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts
@@ -10,7 +10,7 @@ import {
botGroupExecutionFailureBatches,
chatGroupMembership,
} from '../botGroupPresentation.js';
-import { BOT_GROUP_RUNTIME_FAILURE_CODES, readBotGroupExecutionFailure, type BotGroupErrorCode, type BotGroupExecutionFailureView, type BotGroupMemberView, type BotGroupMessageView, type BotGroupNoticeCode, type BotGroupPlanView } from '../botGroupChat.js';
+import { chatGroupTalkRouteKey, groupLaneOfRouteKey, isChatOnlyGroupLane, BOT_GROUP_RUNTIME_FAILURE_CODES, readBotGroupExecutionFailure, type BotGroupErrorCode, type BotGroupExecutionFailureView, type BotGroupMemberView, type BotGroupMessageView, type BotGroupNoticeCode, type BotGroupPlanView } from '../botGroupChat.js';
describe('server group membership affordances', () => {
const self = { actorId: 'self', isSelf: true, isOwned: true, role: 'member' } as BotGroupMemberView;
@@ -146,3 +146,13 @@ describe('plan follow-up and composer state', () => {
expect(botGroupComposerPlanState(plan({ kind: 'talk', status, canAdd }))).toEqual(expected);
});
});
+
+// A queue lane keeps the grant's boundary: a chat-only queue turn is chat-only (no tools, no owner
+// files) and works in its group lane's place (bot-group-chat.md §7.0).
+describe('queue lanes', () => {
+ it.each([['chat', true], ['owner', false], ['tools', false]] as const)('a %s queue lane is chat-only: %s', (mode, chatOnly) => {
+ const key = chatGroupTalkRouteKey('g1', { mode, revision: 2 }, 'q1');
+ expect(isChatOnlyGroupLane(key)).toBe(chatOnly);
+ expect(groupLaneOfRouteKey(key)).toBe(`group:g1:access:${mode}:2`);
+ });
+});
diff --git a/packages/maker-shared/src/botGroupChat.ts b/packages/maker-shared/src/botGroupChat.ts
index 601e7862ef..3f3b502a62 100644
--- a/packages/maker-shared/src/botGroupChat.ts
+++ b/packages/maker-shared/src/botGroupChat.ts
@@ -710,7 +710,15 @@ export function chatGroupLaneRouteKey(groupId: string, access: ChatLaneAccess):
return `group:${groupId}:access:${access.mode}:${access.revision}`;
}
export function isChatOnlyGroupLane(routeKey: string | null | undefined): boolean {
- return /^group:[^:]+:access:chat:[1-9][0-9]*(?::plan:[^:]+|:thread:[^:]+)?$/.test(routeKey ?? '');
+ return /^group:[^:]+:access:chat:[1-9][0-9]*(?::plan:[^:]+|:thread:[^:]+|:talk:[^:]+)?$/.test(routeKey ?? '');
+}
+
+/**
+ * A queue's own lane (bot-group-chat.md §7.0): one hidden Session per queue, grant and teammate,
+ * so each turn reads only its card. It talks in the group lane's place, never a project folder.
+ */
+export function chatGroupTalkRouteKey(groupId: string, access: ChatLaneAccess, planId: string): string {
+ return `${chatGroupLaneRouteKey(groupId, access)}:talk:${planId}`;
}
/**
@@ -727,9 +735,9 @@ export function parseBotGroupThreadRouteKey(routeKey: string | null | undefined)
return match ? { groupId: match[1]!, threadRootId: match[2]! } : null;
}
-/** The group lane a Thread lane belongs to; a Thread works in the same place as its group lane. */
+/** The group lane a Thread or queue lane belongs to; both work in the same place as their group lane. */
export function groupLaneOfRouteKey(routeKey: string): string {
- return routeKey.replace(/:thread:[^:]+$/, '');
+ return routeKey.replace(/:(?:thread|talk):[^:]+$/, '');
}
export function botGroupLaneRouteKey(groupId: string): string {