Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(acceptance,topic): don't ask admins for collaboration access; keep project "+" topics in the project (#21551)

Arvin Xu281e29bcda50
diff --git a/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.test.ts b/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.test.ts
index 1451c68d8f4..d121f31060a 100644
--- a/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.test.ts
+++ b/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.test.ts
@@ -58,12 +58,15 @@ describe('canManageAcceptance', () => {
).resolves.toBe(false);
});
- it('does not let an ordinary member write a teammate delivery', async () => {
+ // A member holds write access, like a repository's write permission that is
+ // enough to merge a pull request — only viewers are kept to comments.
+ it("lets an ordinary member of the acceptance's own workspace write a teammate's delivery", async () => {
getMember.mockResolvedValue({ role: 'member' });
await expect(
canManageAcceptance({ serverDB: db, userId: 'me' }, row('teammate', 'ws_a')),
- ).resolves.toBe(false);
+ ).resolves.toBe(true);
+ expect(getMember).toHaveBeenCalledWith('ws_a', 'me');
});
it('does not let a non-member write it', async () => {
@@ -96,6 +99,7 @@ describe('filterManageableAcceptances', () => {
['ws_owned', 'owner'],
['ws_admin', 'admin'],
['ws_member', 'member'],
+ ['ws_viewer', 'viewer'],
]),
);
@@ -105,6 +109,7 @@ describe('filterManageableAcceptances', () => {
row('teammate', 'ws_owned'),
row('teammate', 'ws_admin'),
row('teammate', 'ws_member'),
+ row('teammate', 'ws_viewer'),
row('teammate', null),
];
await expect(
@@ -114,6 +119,7 @@ describe('filterManageableAcceptances', () => {
row('me', 'ws_member'),
row('teammate', 'ws_owned'),
row('teammate', 'ws_admin'),
+ row('teammate', 'ws_member'),
]);
});
diff --git a/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.ts b/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.ts
index 012b6b971ed..a12fece0a28 100644
--- a/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.ts
+++ b/apps/server/src/routers/lambda/_helpers/acceptanceWriteScope.ts
@@ -3,12 +3,12 @@ import type { AcceptanceItem } from '@/database/schemas/verify';
import type { LobeChatDatabase } from '@/database/type';
/**
- * Workspace roles that may decide on a teammate's acceptance. Admins run the
- * workspace day to day, so a delivery waiting on its author must not be stuck
- * until the one owner turns up; members and viewers weigh in through approvals
- * and comments instead.
+ * Workspace roles that may decide on a teammate's acceptance: everyone with
+ * write access, the way a repository's write permission is enough to merge a
+ * pull request. A delivery waiting on its author must not be stuck until an
+ * owner turns up; viewers, who only read, weigh in through comments instead.
*/
-const DECIDER_ROLES = new Set(['owner', 'admin']);
+const DECIDER_ROLES = new Set(['owner', 'admin', 'member']);
const isDeciderRole = (role?: string | null) => Boolean(role && DECIDER_ROLES.has(role));
@@ -21,7 +21,7 @@ export interface AcceptanceScopeCtx {
* May this caller write to this acceptance?
*
* The creator always may. Beyond that, an acceptance that belongs to a workspace
- * may also be managed by an OWNER or ADMIN of **that** workspace — not of the caller's
+ * may also be managed by any non-viewer (owner, admin or member) of **that** workspace — not of the caller's
* currently-active one, which is frequently a different workspace or none at
* all. Reading membership off the row's own workspace is what makes the rule
* stable no matter where the caller happens to be standing, and it is the same
diff --git a/apps/server/src/routers/lambda/acceptance/procedures.ts b/apps/server/src/routers/lambda/acceptance/procedures.ts
index 325fd4ca400..d9a6671c1ea 100644
--- a/apps/server/src/routers/lambda/acceptance/procedures.ts
+++ b/apps/server/src/routers/lambda/acceptance/procedures.ts
@@ -18,7 +18,7 @@ import { AcceptanceService } from '@/server/services/verify';
import { canManageAcceptance } from '../_helpers/acceptanceWriteScope';
export const ACCEPTANCE_DECISION_FORBIDDEN =
- 'Only the creator, a workspace owner or a workspace admin can change this acceptance';
+ 'Only the creator or a workspace member with edit access can change this acceptance';
/** Reads addressed purely by acceptance id — visibility is checked in the handler. */
export const publicAcceptanceProcedure = publicProcedure.use(serverDatabase);
diff --git a/apps/server/src/routers/lambda/acceptanceComment.ts b/apps/server/src/routers/lambda/acceptanceComment.ts
index 892a3e9b184..291ebc2156d 100644
--- a/apps/server/src/routers/lambda/acceptanceComment.ts
+++ b/apps/server/src/routers/lambda/acceptanceComment.ts
@@ -579,7 +579,7 @@ export const acceptanceCommentRouter = router({
message: 'A goal gate cannot hand out reject access',
});
// The owner already holds everything a grant hands out. A workspace
- // admin who may decide still cannot talk to the owner's agent, so they
+ // member who may decide still cannot talk to the owner's agent, so they
// may ask like anyone else.
if (access.isOwner)
throw new TRPCError({
@@ -653,7 +653,7 @@ export const acceptanceCommentRouter = router({
if (!(await canManageAcceptance(ctx, access.acceptance)))
throw new TRPCError({
code: 'FORBIDDEN',
- message: 'Only the creator, a workspace owner or a workspace admin can answer this',
+ message: 'Only the creator or a workspace member with edit access can answer this',
});
const transition = ACCESS_TRANSITIONS[input.decision];
diff --git a/locales/en-US/verify.json b/locales/en-US/verify.json
index a1d702d8cc0..aac436d4b8a 100644
--- a/locales/en-US/verify.json
+++ b/locales/en-US/verify.json
@@ -9,7 +9,7 @@
"acceptance.access.grant": "Grant",
"acceptance.access.grantHint": "If you grant this, they can send the delivery back and read and talk in the bound conversation. Their messages run on your agent, under your account.",
"acceptance.access.pendingCount": "{{count}} edit-collaboration request(s) waiting",
- "acceptance.access.pendingDescription": "Waiting for the creator, a workspace owner or an admin to respond.",
+ "acceptance.access.pendingDescription": "Waiting for the creator or a workspace member with edit access to respond.",
"acceptance.access.pendingTitle": "Edit-collaboration requested",
"acceptance.access.reasonPlaceholder": "What do you want to move forward? (optional)",
"acceptance.access.request": "Request edit-collaboration access",
@@ -51,9 +51,9 @@
"acceptance.bar.progress": "{{done}} of {{total}} checks confirmed — {{rest}} awaiting your review",
"acceptance.bar.progressDone": "All {{total}} checks confirmed — ready to accept",
"acceptance.bar.progressZero": "{{total}} checks awaiting your review",
- "acceptance.bar.readOnlyReason": "Only the creator, a workspace owner or an admin can accept or reject this delivery. You can still approve it, comment in Discussion, or request edit-collaboration access.",
+ "acceptance.bar.readOnlyReason": "Only the creator or a workspace member with edit access can accept or reject this delivery. You can still approve it, comment in Discussion, or request edit-collaboration access.",
"acceptance.bar.rejectComment": "Reject delivery",
- "acceptance.bar.rejectOnlyReason": "You have edit-collaboration access. Accepting the delivery stays with the creator, a workspace owner or an admin.",
+ "acceptance.bar.rejectOnlyReason": "You have edit-collaboration access. Accepting the delivery stays with the creator or a workspace member with edit access.",
"acceptance.bar.rerun": "Fix",
"acceptance.bar.rerunDrafted": "Added to your composer — review and send it.",
"acceptance.bar.rerunSent": "Sent to the source conversation — the repair round is starting.",
@@ -116,7 +116,7 @@
"acceptance.comments.approvalCount": "{{count}} reviewer(s) approved",
"acceptance.comments.approve": "Approve this delivery",
"acceptance.comments.approveAgain": "Approve this round",
- "acceptance.comments.approveDescription": "This records your approval. It doesn’t change the acceptance status — only the creator, a workspace owner or an admin can accept the delivery.",
+ "acceptance.comments.approveDescription": "This records your approval. It doesn’t change the acceptance status — only the creator or a workspace member with edit access can accept the delivery.",
"acceptance.comments.approveSummaryPlaceholder": "One-line summary (optional)",
"acceptance.comments.approved": "Approved",
"acceptance.comments.approvedAtRound": "Approved (round {{round}})",
diff --git a/locales/zh-CN/verify.json b/locales/zh-CN/verify.json
index b1ee81373b9..425307017ac 100644
--- a/locales/zh-CN/verify.json
+++ b/locales/zh-CN/verify.json
@@ -9,7 +9,7 @@
"acceptance.access.grant": "同意",
"acceptance.access.grantHint": "同意后,对方可以打回这次交付,并能查看关联对话、直接和你的 Agent 对话;对方的消息由你的 Agent 用你的账号执行。",
"acceptance.access.pendingCount": "{{count}} 个编辑协作申请待处理",
- "acceptance.access.pendingDescription": "等待发起人、工作区所有者或管理员处理。",
+ "acceptance.access.pendingDescription": "等待发起人或有编辑权限的工作区成员处理。",
"acceptance.access.pendingTitle": "已申请编辑协作权限",
"acceptance.access.reasonPlaceholder": "想推进什么?(可选)",
"acceptance.access.request": "申请编辑协作权限",
@@ -51,9 +51,9 @@
"acceptance.bar.progress": "已完成 {{done}} / {{total}} 项验证项,剩余 {{rest}} 项等待你的验收",
"acceptance.bar.progressDone": "{{total}} 项验证项已全部确认,可以接受交付",
"acceptance.bar.progressZero": "共 {{total}} 项等待你的验收",
- "acceptance.bar.readOnlyReason": "只有发起人、工作区所有者或管理员可以接受或打回这次交付。你仍然可以表达接受、在讨论中留言,或申请编辑协作权限。",
+ "acceptance.bar.readOnlyReason": "只有发起人或有编辑权限的工作区成员可以接受或打回这次交付。你仍然可以表达接受、在讨论中留言,或申请编辑协作权限。",
"acceptance.bar.rejectComment": "打回交付",
- "acceptance.bar.rejectOnlyReason": "你有编辑协作权限;接受交付仍由发起人、工作区所有者或管理员决定。",
+ "acceptance.bar.rejectOnlyReason": "你有编辑协作权限;接受交付仍由发起人或有编辑权限的工作区成员决定。",
"acceptance.bar.rerun": "打回重跑",
"acceptance.bar.rerunDrafted": "已填入对话框,检查后发送。",
"acceptance.bar.rerunSent": "已发送到源会话,修复轮次启动中。",
@@ -116,7 +116,7 @@
"acceptance.comments.approvalCount": "{{count}} 位评审已接受",
"acceptance.comments.approve": "表达接受交付",
"acceptance.comments.approveAgain": "表达接受本轮",
- "acceptance.comments.approveDescription": "这是你的评审意见,不会改变验收状态;只有发起人、工作区所有者或管理员能接受交付。",
+ "acceptance.comments.approveDescription": "这是你的评审意见,不会改变验收状态;只有发起人或有编辑权限的工作区成员能接受交付。",
"acceptance.comments.approveSummaryPlaceholder": "一句话总结(可选)",
"acceptance.comments.approved": "已接受",
"acceptance.comments.approvedAtRound": "已接受(第 {{round}} 轮)",
diff --git a/packages/locales/src/default/verify.ts b/packages/locales/src/default/verify.ts
index 8713c48bf99..47962befb38 100644
--- a/packages/locales/src/default/verify.ts
+++ b/packages/locales/src/default/verify.ts
@@ -213,7 +213,7 @@ export default {
'acceptance.bar.progressDone': 'All {{total}} checks confirmed — ready to accept',
'acceptance.bar.progressZero': '{{total}} checks awaiting your review',
'acceptance.bar.readOnlyReason':
- 'Only the creator, a workspace owner or an admin can accept or reject this delivery. You can still approve it, comment in Discussion, or request edit-collaboration access.',
+ 'Only the creator or a workspace member with edit access can accept or reject this delivery. You can still approve it, comment in Discussion, or request edit-collaboration access.',
'acceptance.bar.rejectComment': 'Reject delivery',
'acceptance.bar.rerun': 'Fix',
'acceptance.bar.rerunDrafted': 'Added to your composer — review and send it.',
@@ -306,7 +306,7 @@ export default {
'acceptance.comments.regionCount': '{{count}} region note(s)',
'acceptance.comments.approve': 'Approve this delivery',
'acceptance.comments.approveDescription':
- 'This records your approval. It doesn’t change the acceptance status — only the creator, a workspace owner or an admin can accept the delivery.',
+ 'This records your approval. It doesn’t change the acceptance status — only the creator or a workspace member with edit access can accept the delivery.',
'acceptance.comments.approveSummaryPlaceholder': 'One-line summary (optional)',
'acceptance.comments.withdraw': 'Withdraw approval',
'acceptance.comments.withdrawDescription':
@@ -1049,7 +1049,7 @@ export default {
'If you grant this, they can send the delivery back and read and talk in the bound conversation. Their messages run on your agent, under your account.',
'acceptance.access.pendingCount': '{{count}} edit-collaboration request(s) waiting',
'acceptance.access.pendingDescription':
- 'Waiting for the creator, a workspace owner or an admin to respond.',
+ 'Waiting for the creator or a workspace member with edit access to respond.',
'acceptance.access.pendingTitle': 'Edit-collaboration requested',
'acceptance.access.reasonPlaceholder': 'What do you want to move forward? (optional)',
'acceptance.access.request': 'Request edit-collaboration access',
@@ -1065,7 +1065,7 @@ export default {
'acceptance.access.title': 'Want to help move this delivery forward?',
'acceptance.access.withdraw': 'Withdraw request',
'acceptance.bar.rejectOnlyReason':
- 'You have edit-collaboration access. Accepting the delivery stays with the creator, a workspace owner or an admin.',
+ 'You have edit-collaboration access. Accepting the delivery stays with the creator or a workspace member with edit access.',
'acceptance.collaboration.empty': 'No messages in this conversation yet.',
'acceptance.collaboration.expand': 'Open the bound conversation',
'acceptance.collaboration.hint':
diff --git a/src/features/Acceptance/Viewer/Comments/CollaborationRequestBanner.tsx b/src/features/Acceptance/Viewer/Comments/CollaborationRequestBanner.tsx
index c54c6623919..78c870e6248 100644
--- a/src/features/Acceptance/Viewer/Comments/CollaborationRequestBanner.tsx
+++ b/src/features/Acceptance/Viewer/Comments/CollaborationRequestBanner.tsx
@@ -14,6 +14,7 @@ import { userProfileSelectors } from '@/store/user/selectors';
import { useAcceptanceScope } from '../AcceptanceScope';
import { useAcceptanceBundle } from '../useAcceptanceBundle';
+import { needsCollaborationRequest } from '../visibility';
import { openCollaborationRequestModal } from './CollaborationRequestModal';
import { useAcceptanceComments } from './hooks';
@@ -70,7 +71,7 @@ const CollaborationRequestBanner = () => {
const viewerId = useUserStore(userProfileSelectors.userId);
const [withdrawing, setWithdrawing] = useState(false);
- if (!data || !canComment || data.isOwner || data.canCollaborate) return null;
+ if (!data || !canComment || !needsCollaborationRequest(data)) return null;
if (data.acceptance.subjectType === 'goal_gate') return null;
if (data.acceptance.status === 'accepted' || data.acceptance.status === 'closed') return null;
diff --git a/src/features/Acceptance/Viewer/visibility.test.ts b/src/features/Acceptance/Viewer/visibility.test.ts
index caa406b19c0..57196a31f5d 100644
--- a/src/features/Acceptance/Viewer/visibility.test.ts
+++ b/src/features/Acceptance/Viewer/visibility.test.ts
@@ -6,6 +6,7 @@ import {
canReviewAcceptance,
canViewAcceptanceHistory,
isReadOnlyAcceptanceDecider,
+ needsCollaborationRequest,
resolveAcceptanceHistoryNavigation,
} from './visibility';
@@ -88,3 +89,30 @@ describe('canRejectAcceptanceOnly', () => {
expect(canRejectAcceptanceOnly(undefined)).toBe(false);
});
});
+
+describe('needsCollaborationRequest', () => {
+ it('asks a plain reviewer to request collaboration', () => {
+ expect(
+ needsCollaborationRequest({ canCollaborate: false, canReview: false, isOwner: false }),
+ ).toBe(true);
+ });
+
+ it('does not ask a workspace owner/admin who can already decide the delivery', () => {
+ expect(
+ needsCollaborationRequest({ canCollaborate: false, canReview: true, isOwner: false }),
+ ).toBe(false);
+ });
+
+ it('does not ask the creator or a viewer who was already granted collaboration', () => {
+ expect(
+ needsCollaborationRequest({ canCollaborate: false, canReview: true, isOwner: true }),
+ ).toBe(false);
+ expect(
+ needsCollaborationRequest({ canCollaborate: true, canReview: false, isOwner: false }),
+ ).toBe(false);
+ });
+
+ it('shows nothing before the bundle loads', () => {
+ expect(needsCollaborationRequest(undefined)).toBe(false);
+ });
+});
diff --git a/src/features/Acceptance/Viewer/visibility.ts b/src/features/Acceptance/Viewer/visibility.ts
index 371e6080a54..20ae230b0c0 100644
--- a/src/features/Acceptance/Viewer/visibility.ts
+++ b/src/features/Acceptance/Viewer/visibility.ts
@@ -11,12 +11,12 @@ export const resolveAcceptanceHistoryNavigation = (
* Whether the viewer may act on the checks (accept / reject / ignore, group
* feedback, proposal adjudication).
*
- * The server decides this — it is the creator OR an owner/admin of the
+ * The server decides this — it is the creator OR a non-viewer member of the
* acceptance's workspace, exactly what the write path enforces — so the client must not
* re-derive it from `isOwner`. Reading it off the bundle rather than taking it
* from the host is what keeps a shared link from rendering live controls whose
* every click answers "Acceptance not found"; deriving it from ownership alone
- * is what locked a workspace owner out of a teammate's delivery.
+ * is what locked a workspace member out of a teammate's delivery.
*/
export const canReviewAcceptance = (bundle?: { canReview?: boolean; isOwner?: boolean } | null) =>
Boolean(bundle?.canReview);
@@ -49,3 +49,15 @@ export const canCommentOnAcceptanceEvidence = (
bundle: { isOwner: boolean } | null | undefined,
canComment: boolean,
) => canComment && Boolean(bundle);
+
+/**
+ * Whether the viewer still has to ask a decider for edit-collaboration.
+ *
+ * Anyone who already decides this delivery — its creator, or a non-viewer member of
+ * its workspace (`canReview`) — or who was granted collaboration has nothing to
+ * request. Keying off `isOwner` alone made a workspace member with edit access, who holds
+ * the full decision bar, be asked to petition the author for access they have.
+ */
+export const needsCollaborationRequest = (
+ bundle?: { canCollaborate?: boolean; canReview?: boolean; isOwner?: boolean } | null,
+) => Boolean(bundle) && !bundle!.isOwner && !bundle!.canReview && !bundle!.canCollaborate;
diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx
index be736aade16..a8eb09e59cf 100644
--- a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx
+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.test.tsx
@@ -28,6 +28,9 @@ const directoryRows = vi.hoisted(
deviceId?: string;
deviceName?: string;
path?: string;
+ environmentId?: string;
+ instanceId?: string;
+ permission?: string;
}>,
);
const subGroupModeMock = vi.hoisted(() => ({ value: 'none' as string }));
@@ -772,7 +775,7 @@ it('opens the plain new-topic composer when a merged project group spans multipl
// ROOT CAUSE: the first fix opened a chooser modal here, but the expected
// habit is the plain new-topic composer — the user picks the machine in the
// composer control bar, so no modal may pop and no directory default may be
- // pre-committed for a multi-machine merged group.
+ // committed to the agent for a multi-machine merged group.
directoryRows.length = 0;
openProjectTopicModalMock.mockClear();
commitAgentDefaultMock.mockClear();
@@ -786,6 +789,10 @@ it('opens the plain new-topic composer when a merged project group spans multipl
projectSlug: 'multi-project',
projectId: 'prj-multi',
projectAvatar: '📦',
+ deviceId: 'device-2',
+ environmentId: 'env-a',
+ instanceId: 'inst-a',
+ permission: 'readWrite',
},
{
id: 'binding-multi-b',
@@ -793,6 +800,10 @@ it('opens the plain new-topic composer when a merged project group spans multipl
projectSlug: 'multi-project',
projectId: 'prj-multi',
projectAvatar: '📦',
+ deviceId: 'device-1',
+ environmentId: 'env-b',
+ instanceId: 'inst-b',
+ permission: 'readWrite',
},
);
render(
@@ -831,9 +842,13 @@ it('opens the plain new-topic composer when a merged project group spans multipl
expect(commitAgentDefaultMock).not.toHaveBeenCalled();
expect(switchTopicMock).toHaveBeenCalledWith(null, { skipRefreshMessage: true });
expect(routerPushMock).toHaveBeenCalledWith('/agent/agent-1');
- // A multi-directory group has no single directory to stage — the user picks
- // the machine in the composer.
- expect(setPendingNewTopicDirectoryMock).not.toHaveBeenCalled();
+ // ROOT CAUSE of the detached topic: nothing was staged, so the first send
+ // created a path-only conversation outside the project. The agent's current
+ // device (device-1) wins; the composer's device switcher can move it.
+ expect(setPendingNewTopicDirectoryMock).toHaveBeenCalledWith({
+ agentId: 'agent-1',
+ projectWorkingDirectoryId: 'binding-multi-b',
+ });
});
it('keeps the legacy directory start when a project group has a single directory', async () => {
diff --git a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx
index fb8c2099a05..eea3f99a31f 100644
--- a/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx
+++ b/src/features/AgentSidebar/Topic/TopicListContent/ByProjectMode/GroupItem.tsx
@@ -34,14 +34,19 @@ import Avatar from '@/components/Avatar';
import TailMarquee from '@/components/TailMarquee';
import { useCommitWorkingDirectory } from '@/features/ChatInput/ControlBar/useCommitWorkingDirectory';
import { AgentDirectoryActions } from '@/features/Projects/WorkingDirectories/AgentDirectoryActions';
+import { canStageDraftOn } from '@/features/Projects/WorkingDirectories/startProjectTopicDraft';
+import { useAgentFixedDeviceId } from '@/features/Projects/WorkingDirectories/useAgentFixedDeviceId';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
+import { resolveTargetDeviceId } from '@/helpers/agentWorkingDirectory';
import { useActiveLocation } from '@/hooks/useActiveLocation';
import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';
+import { useEffectiveAgencyConfig } from '@/hooks/useEffectiveAgencyConfig';
import { usePermission } from '@/hooks/usePermission';
import { useQueryRoute } from '@/hooks/useQueryRoute';
import { useAgentStore } from '@/store/agent';
import { useChatStore } from '@/store/chat';
+import { useElectronStore } from '@/store/electron';
import { useGlobalStore } from '@/store/global';
import { type ProjectTopicSubGroupMode } from '@/store/global/initialState';
import { systemStatusSelectors } from '@/store/global/selectors';
@@ -137,18 +142,50 @@ const GroupItem = memo<GroupItemComponentProps>(({ group, expanded }) => {
],
);
- // A merged project group may span several machines. It opens the plain new
- // topic composer — no directory is pre-committed and no chooser modal pops;
- // the user picks the machine/directory in the composer control bar, the
- // same habit as the header's new-topic action. Single-directory groups keep
- // the legacy direct start above.
+ // A merged project group may span several machines, so there is no single
+ // directory to commit to the agent. It still has to open the blank composer
+ // INSIDE the project: stage one runnable directory — the agent's current
+ // device first — so the first send binds the new topic to the project, and
+ // let the user move to another machine in the composer's device switcher.
+ // Staging nothing (the old behaviour) dropped the topic into a path-only
+ // conversation, detached from the project the "+" belonged to. No directory
+ // can run it → fall back to the plain composer, as before.
+ const fixedDeviceId = useAgentFixedDeviceId(targetAgentId);
+ const { agencyConfig, workspaceScoped } = useEffectiveAgencyConfig(targetAgentId ?? '', {
+ topicId: null,
+ });
+ const currentDeviceId = useElectronStore((s) => s.gatewayDeviceInfo?.deviceId);
const handleStartPlain = useCallback(() => {
if (!currentAgentId || !targetAgentId) return;
+ const runnable = projectDirectories.filter((d) => canStageDraftOn(d, fixedDeviceId));
+ const preferredDeviceId = resolveTargetDeviceId(agencyConfig, currentDeviceId, {
+ workspaceScoped,
+ });
+ const stagedDirectory =
+ runnable.find((d) => preferredDeviceId && d.deviceId === preferredDeviceId) ?? runnable[0];
useChatStore.getState().switchTopic(null, { skipRefreshMessage: true });
+ useChatStore
+ .getState()
+ .setPendingNewTopicDirectory(
+ stagedDirectory
+ ? { agentId: targetAgentId, projectWorkingDirectoryId: stagedDirectory.id }
+ : undefined,
+ );
router.push(
buildPrefixedAgentRoutePath(AGENT_CHAT_URL(targetAgentId), agentRoute, activeWorkspaceSlug),
);
- }, [currentAgentId, targetAgentId, router, agentRoute, activeWorkspaceSlug]);
+ }, [
+ currentAgentId,
+ targetAgentId,
+ projectDirectories,
+ fixedDeviceId,
+ agencyConfig,
+ currentDeviceId,
+ workspaceScoped,
+ router,
+ agentRoute,
+ activeWorkspaceSlug,
+ ]);
// Start on one specific project directory — the device sub-group "+". The
// directory pins the device, so nothing is committed to the agent default.