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): 默认收起平台任务列表并复用折叠组件

xd77990e9cc19f
diff --git a/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs b/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs
index 5bb10a5bbe..01d77cce7c 100644
--- a/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs
+++ b/apps/desktop/scripts/fixtures/wechat-companion/ui-page.mjs
@@ -66,7 +66,13 @@ export default {
// the wrapped status group jumping to the left. Measure the chevron's edge.
async check(page, ui) {
if (ui.data.hiddenIm) {
- await page.locator('[title="拉拉, 徐紫旎, 姚刘浏"]').waitFor({ state: 'visible' });
+ const platform = await ui.t('bots.channels.platform.feishu');
+ const record = page.locator('[title="拉拉, 徐紫旎, 姚刘浏"]');
+ await page.getByRole('button', { name: await ui.t('bots.channels.lanes.expand', { platform }), exact: true }).waitFor({ state: 'visible' });
+ assert.equal(await record.isVisible(), false, 'task list is collapsed on entry');
+ await ui.capture('tasks-initial-collapsed');
+ await page.getByRole('button', { name: await ui.t('bots.channels.lanes.expand', { platform }), exact: true }).click();
+ await record.waitFor({ state: 'visible' });
const row = page.locator('button').filter({ hasText: '8c9b5c' });
await row.waitFor({ state: 'visible' });
const resting = await row.evaluate((el) => getComputedStyle(el).boxShadow);
@@ -85,13 +91,14 @@ export default {
assert.notEqual(focused.boxShadow, 'none', 'focus ring must survive the global outline suppression');
assert.equal(focused.outlineStyle, 'none');
await row.evaluate((el) => el.blur());
- const platform = await ui.t('bots.channels.platform.feishu');
const collapse = page.getByRole('button', { name: await ui.t('bots.channels.lanes.collapse', { platform }), exact: true });
await ui.capture('tasks-expanded');
await collapse.click();
+ await row.waitFor({ state: 'hidden' });
assert.equal(await row.isVisible(), false, 'task records collapse without invoking a write');
await ui.capture('tasks-collapsed');
await page.getByRole('button', { name: await ui.t('bots.channels.lanes.expand', { platform }), exact: true }).click();
+ await row.waitFor({ state: 'visible' });
assert.equal(await row.isVisible(), true, 'task records return after expanding');
return;
}
diff --git a/apps/desktop/src/renderer/features/bots/BotChannelsPage.tsx b/apps/desktop/src/renderer/features/bots/BotChannelsPage.tsx
index af7989b76b..9240ccd197 100644
--- a/apps/desktop/src/renderer/features/bots/BotChannelsPage.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotChannelsPage.tsx
@@ -17,6 +17,7 @@ import { useNavigate } from 'react-router-dom';
import { ChromeIconButton } from '@/components/title-bar/ChromeIconButton';
import { AttentionDot } from '@/components/sidebar/AttentionDot';
import { Button } from '@/components/ui/button';
+import { Collapse } from '@/components/ui/collapse';
import { useConfirmDialog } from '@/components/ui/confirm-dialog-provider';
import { FormField } from '@/components/ui/form-field';
import { Input } from '@/components/ui/input';
@@ -365,7 +366,7 @@ function ConnectionLanes({ connectionId, botId, botName, platform }: { connectio
const { t } = useBotTranslation();
const navigate = useNavigate();
const { confirm } = useConfirmDialog();
- const [expanded, setExpanded] = useState(true);
+ const [expanded, setExpanded] = useState(false);
const contentId = useId();
const [lanes, setLanes] = useState<BotImConnectionLane[] | null>(null);
const [loadFailed, setLoadFailed] = useState(false);
@@ -456,7 +457,7 @@ function ConnectionLanes({ connectionId, botId, botName, platform }: { connectio
{expanded ? <ChevronUp size={14} aria-hidden /> : <ChevronRight size={14} aria-hidden />}
</ChromeIconButton>
</div>
- <div id={contentId} hidden={!expanded} className={expanded ? 'flex flex-col gap-2' : 'hidden'}>
+ <Collapse open={expanded} id={contentId} inert={!expanded} innerClassName="flex flex-col gap-2">
<p className="text-11 leading-[1.5] text-[var(--text-tertiary)]">
{t('bots.channels.lanes.hint', { name: botName })}
</p>
@@ -554,7 +555,7 @@ function ConnectionLanes({ connectionId, botId, botName, platform }: { connectio
{notice.text}
</p>
) : null}
- </div>
+ </Collapse>
</div>
);
}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botChannelsPage.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/botChannelsPage.test.tsx
index 784c908c86..b34737098c 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botChannelsPage.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botChannelsPage.test.tsx
@@ -99,10 +99,14 @@ beforeEach(() => {
});
afterEach(cleanup);
+async function expandTaskList() {
+ fireEvent.click(await screen.findByRole('button', { name: /^bots\.channels\.lanes\.expand:/ }));
+}
+
describe('BotChannelsPage', () => {
// 用户确认的飞书任务折叠合同;既有测试只覆盖打开与重启。
// 最小输入:一条连接和一条专线。unit:真实组件点击后列表隐藏,展开保留原记录,无业务写入。
- it('collapses only this connection task list and restores it without changing sessions', async () => {
+ it('starts collapsed, expands and restores only this connection task list without changing sessions', async () => {
lanesApi = {
listLanes: vi.fn(async () => ({ connectionId: 'a1b2c3d4e5f6', lanes: [
{ sessionId: 'lane', kind: 'topic', chatId: 'group', threadId: 'topic', name: 'Release room', state: 'idle', lastActivityAt: null, contextMessageCount: 0 },
@@ -113,12 +117,14 @@ describe('BotChannelsPage', () => {
render(<BotChannelsPage bot={mia} />);
const label = { platform: 'bots.channels.platform.feishu' };
expect(await screen.findByText(`bots.channels.lanes.title:${JSON.stringify(label)}`)).toBeTruthy();
- expect(screen.getByRole('button', { name: /^Release room/ })).toBeTruthy();
+ expect(screen.queryByRole('button', { name: /^Release room/ })).toBeNull();
+ await expandTaskList();
+ expect(await screen.findByRole('button', { name: /^Release room/ })).toBeTruthy();
fireEvent.click(screen.getByRole('button', { name: `bots.channels.lanes.collapse:${JSON.stringify(label)}` }));
expect(screen.queryByRole('button', { name: /^Release room/ })).toBeNull();
expect(screen.getByText('bots.channels.platform.feishu')).toBeTruthy();
fireEvent.click(screen.getByRole('button', { name: `bots.channels.lanes.expand:${JSON.stringify(label)}` }));
- expect(screen.getByRole('button', { name: /^Release room/ })).toBeTruthy();
+ expect(await screen.findByRole('button', { name: /^Release room/ })).toBeTruthy();
expect(lanesApi.resetLane).not.toHaveBeenCalled();
expect(mocks.navigate).not.toHaveBeenCalled();
});
@@ -136,6 +142,7 @@ describe('BotChannelsPage', () => {
};
installApi({ connections: [connection({ channel: 'feishu', botId: 'bot/1' })] });
render(<BotChannelsPage bot={{ ...mia, id: 'bot/1' }} />);
+ await expandTaskList();
for (const lane of lanes) {
const name = lane.kind === 'owner-dm' ? 'bots.channels.lanes.ownerName' : lane.name;
const open = await screen.findByRole('button', { name: new RegExp(`^${name}`) });
@@ -194,17 +201,18 @@ describe('BotChannelsPage', () => {
};
installApi({ connections: [connection({ channel: 'feishu' })] });
render(<BotChannelsPage bot={mia} />);
+ await expandTaskList();
fireEvent.click(await screen.findByRole('button', { name: 'bots.channels.lanes.archiveAria:{"lane":"Release room"}' }));
if (outcome === 'cancel') {
await waitFor(() => expect(mocks.confirm).toHaveBeenCalled());
expect(lanesApi.archiveLane).not.toHaveBeenCalled();
- expect(screen.getByRole('button', { name: /^Release room/ })).toBeTruthy();
+ expect(await screen.findByRole('button', { name: /^Release room/ })).toBeTruthy();
} else {
await waitFor(() => expect(lanesApi.archiveLane).toHaveBeenCalledWith({ id: 'a1b2c3d4e5f6', sessionId: 's-topic' }));
if (outcome === 'done') await waitFor(() => expect(screen.queryByRole('button', { name: /^Release room/ })).toBeNull());
else {
expect(await screen.findByText('bots.channels.lanes.archiveFailed')).toBeTruthy();
- expect(screen.getByRole('button', { name: /^Release room/ })).toBeTruthy();
+ expect(await screen.findByRole('button', { name: /^Release room/ })).toBeTruthy();
}
}
expect(lanesApi.resetLane).not.toHaveBeenCalled();
@@ -226,6 +234,8 @@ describe('BotChannelsPage', () => {
vi.useFakeTimers();
try {
await act(async () => { render(<BotChannelsPage bot={mia} />); });
+ await act(async () => { fireEvent.click(screen.getByRole('button', { name: /^bots\.channels\.lanes\.expand:/ })); });
+ await act(async () => { vi.advanceTimersByTime(16); });
const archive = screen.getByRole('button', { name: 'bots.channels.lanes.archiveAria:{"lane":"Release room"}' });
await act(async () => { vi.advanceTimersByTime(20_000); });
await act(async () => { fireEvent.click(archive); });
@@ -249,6 +259,7 @@ describe('BotChannelsPage', () => {
};
installApi({ connections: [connection()] });
render(<BotChannelsPage bot={mia} />);
+ await expandTaskList();
fireEvent.click(await screen.findByRole('button', { name: 'bots.channels.lanes.resetAria:{"lane":"Hulu Report"}' }));
await waitFor(() =>
@@ -273,6 +284,7 @@ describe('BotChannelsPage', () => {
};
installApi({ connections: [connection()] });
render(<BotChannelsPage bot={mia} />);
+ await expandTaskList();
fireEvent.click(await screen.findByRole('button', { name: 'bots.channels.lanes.resetAria:{"lane":"bots.channels.lanes.ownerName"}' }));
await waitFor(() =>
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 2b5857dd3d..813ab46cb6 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -653,7 +653,9 @@ action remains the registered compact secondary Button and is outside this exemp
This records the accepted quiet list, not a general exemption for settings actions.
The section title uses the connection platform (for example, “飞书任务”). A 28px
-shared quiet icon action at the right toggles only the hint and task list; its 14px
+shared quiet icon action at the right toggles only the hint and task list, which
+start collapsed whenever the panel mounts. Reuse the shared `Collapse` container
+for the existing expansion motion and unmounting; its 14px
chevron and localized Tip name the next action. Each listed conversation, including the owner DM, adds a 28px
quiet archive action immediately before the unchanged restart Button, with a 4px
action gap. Reuse the sidebar task archive glyph (`Archive`, 14px, stroke width 2).
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index edfcca319e..1b31c59ecc 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -155,7 +155,7 @@ Discord 传输层只放行主人,钉钉群里被 @ 时成员也能触发(成
别人说的不冒充主人:专线里主人与群成员 / 外部用户的消息落在同一条任务,每条消息的 `imSource.origin` 存谁、在哪说的
(与发给模型的 `[渠道说明]` / `[发言人]` 同源),任务面板的卡头对非主人消息写出发言人与群名,主人消息沿用
「Cindy · 来自 X」;外部用户私聊的渠道说明写明发言人并点出「不是主人」,不再按 speaker 有无把私聊误判成群。
-「消息平台」页每条连接下的小节以平台命名(如「飞书任务」),标题右侧可展开 / 收起说明与列表,
+「消息平台」页每条连接下的小节以平台命名(如「飞书任务」),首次进入面板时默认收起,标题右侧可展开 / 收起说明与列表,
不改变连接和任务状态。列出这条连接名下的主人私聊(伙伴主任务)与各群 / 话题 / 外部用户私聊
专线,每条可「重新开始」——复用伙伴已有的 `restartBotCanonicalRuntime` 交接(同一条任务、记录与记忆不删,下一条消息
换干净的原生会话),不另写换会话逻辑,见 `im/shared/botImLaneRuntime.ts`。