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): keep automations out of task return history (#4293)

DavidShenXD48d3e9d169a4
diff --git a/apps/desktop/src/renderer/components/sidebar/__tests__/SidebarTopNav.bots.test.tsx b/apps/desktop/src/renderer/components/sidebar/__tests__/SidebarTopNav.bots.test.tsx
index 1e65fae758..91c6df971e 100644
--- a/apps/desktop/src/renderer/components/sidebar/__tests__/SidebarTopNav.bots.test.tsx
+++ b/apps/desktop/src/renderer/components/sidebar/__tests__/SidebarTopNav.bots.test.tsx
@@ -49,6 +49,28 @@ function Harness({ initialPath, owner = 'one' }: { initialPath: string; owner?:
}
describe('Sidebar teammate return action', () => {
+ it('keeps the previous task when visiting automations before teammates', () => {
+ const sessionPath = '/cc-agent/session-1?remoteHostId=host-1#message-2';
+ render(<Harness initialPath={sessionPath} />);
+ fireEvent.click(screen.getByRole('button', { name: 'ccAgent.layout.automations' }));
+ expect(screen.getByRole('button', { name: 'ccAgent.layout.automations' }).getAttribute('aria-current')).toBe('page');
+ fireEvent.click(screen.getByRole('button', { name: '伙伴' }));
+ fireEvent.click(screen.getByRole('button', { name: '返回任务' }));
+ expect(screen.getByTestId('location').textContent).toBe(sessionPath);
+ expect(screen.getByRole('button', { name: 'ccAgent.layout.automations' }).hasAttribute('aria-current')).toBe(false);
+ });
+
+ it.each(['/cc-agent/scheduled', '/cc-agent/scheduled/?filter=enabled#schedule-1'])(
+ 'returns to the task index after entering teammates from %s without a previous task',
+ (initialPath) => {
+ render(<Harness initialPath={initialPath} />);
+ fireEvent.click(screen.getByRole('button', { name: '伙伴' }));
+ fireEvent.click(screen.getByRole('button', { name: '返回任务' }));
+ expect(screen.getByTestId('location').textContent).toBe('/cc-agent');
+ expect(screen.getByRole('button', { name: 'ccAgent.layout.automations' }).hasAttribute('aria-current')).toBe(false);
+ },
+ );
+
it('does not seed a new owner from the unchanged router entry', () => {
const oldPath = '/cc-agent/old-owner-session?remoteHostId=old-host#message-2';
function OwnerRouter({ owner }: { owner: string }) {
diff --git a/apps/desktop/src/renderer/hooks/useActiveMainView.ts b/apps/desktop/src/renderer/hooks/useActiveMainView.ts
index c92410b436..c3c9789a80 100644
--- a/apps/desktop/src/renderer/hooks/useActiveMainView.ts
+++ b/apps/desktop/src/renderer/hooks/useActiveMainView.ts
@@ -13,6 +13,7 @@
*
* URL 派生由本 hook 维护;各视图最后位置由账号级 MainViewHistoryProvider 共享,
* 避免侧栏滚动段卸载后丢失返回位置。未提供 Provider 时使用实例内记忆。
+ * 自动化页保留当前视图归属,但不覆盖任务返回位置。
* [PROTOCOL]: 变更时更新此头部,然后检查 CLAUDE.md
*/
@@ -69,7 +70,14 @@ export function useActiveMainView() {
) return;
if (matchedKey) {
history.current.lastMatchedKey = matchedKey;
- history.current.paths[matchedKey] = location.pathname + location.search + location.hash;
+ // Automations share the task layout, but are not a task destination.
+ // Keep the previous task (or the index fallback) for return navigation.
+ const isAutomations =
+ location.pathname === '/cc-agent/scheduled' ||
+ location.pathname.startsWith('/cc-agent/scheduled/');
+ if (!isAutomations) {
+ history.current.paths[matchedKey] = location.pathname + location.search + location.hash;
+ }
}
}, [history, matchedKey, location.key, location.pathname, location.search, location.hash]);