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(ui): clarify working directory and agent profile header (#17055)

AmAzing-27d90644c57e
diff --git a/locales/en-US/device.json b/locales/en-US/device.json
index f0486a7718b..e07ace1f2e7 100644
--- a/locales/en-US/device.json
+++ b/locales/en-US/device.json
@@ -18,6 +18,7 @@
"workingDirectory.chooseDifferentFolder": "Choose a folder...",
"workingDirectory.clean": "clean",
"workingDirectory.clear": "Reset to default",
+ "workingDirectory.clearDefault": "Clear default",
"workingDirectory.createBranchAction": "Checkout new branch…",
"workingDirectory.createBranchTitle": "Create new branch",
"workingDirectory.createWorktreeAction": "Create worktree…",
@@ -27,6 +28,7 @@
"workingDirectory.current": "Current working directory",
"workingDirectory.currentWorktree": "current",
"workingDirectory.defaultBadge": "Default",
+ "workingDirectory.defaultUpdateFailed": "Couldn’t update the default working directory",
"workingDirectory.deleteBranchAction": "Delete branch",
"workingDirectory.deleteBranchConfirm": "Delete branch “{{name}}”? This permanently removes it, including any unmerged commits.",
"workingDirectory.deleteBranchTitle": "Delete branch",
@@ -64,7 +66,7 @@
"workingDirectory.pushInProgress": "Pushing…",
"workingDirectory.pushNoop": "Everything up-to-date",
"workingDirectory.pushSuccess": "Pushed successfully",
- "workingDirectory.recent": "Working directories",
+ "workingDirectory.recent": "Working directory",
"workingDirectory.refreshGitStatus": "Refresh branch & PR status",
"workingDirectory.removeRecent": "Remove from recent",
"workingDirectory.removeWorktreeAction": "Delete worktree",
diff --git a/locales/zh-CN/device.json b/locales/zh-CN/device.json
index 7283cc5f87e..9af9f3dc6f3 100644
--- a/locales/zh-CN/device.json
+++ b/locales/zh-CN/device.json
@@ -18,6 +18,7 @@
"workingDirectory.chooseDifferentFolder": "选择其他文件夹",
"workingDirectory.clean": "clean",
"workingDirectory.clear": "恢复默认",
+ "workingDirectory.clearDefault": "取消默认",
"workingDirectory.createBranchAction": "检出新分支…",
"workingDirectory.createBranchTitle": "创建新分支",
"workingDirectory.createWorktreeAction": "创建工作树…",
@@ -27,6 +28,7 @@
"workingDirectory.current": "当前工作目录",
"workingDirectory.currentWorktree": "current",
"workingDirectory.defaultBadge": "默认",
+ "workingDirectory.defaultUpdateFailed": "无法更新默认工作目录",
"workingDirectory.deleteBranchAction": "删除分支",
"workingDirectory.deleteBranchConfirm": "确定删除分支「{{name}}」吗?此操作会永久删除该分支,包括尚未合并的提交。",
"workingDirectory.deleteBranchTitle": "删除分支",
diff --git a/packages/locales/src/default/device.ts b/packages/locales/src/default/device.ts
index e242b0c4dc1..d97d40fdd39 100644
--- a/packages/locales/src/default/device.ts
+++ b/packages/locales/src/default/device.ts
@@ -18,6 +18,7 @@ export default {
'workingDirectory.checkoutFailed': 'Checkout failed',
'workingDirectory.chooseDifferentFolder': 'Choose a folder...',
'workingDirectory.clear': 'Reset to default',
+ 'workingDirectory.clearDefault': 'Clear default',
'workingDirectory.clean': 'clean',
'workingDirectory.createBranchAction': 'Checkout new branch…',
'workingDirectory.createBranchTitle': 'Create new branch',
@@ -27,6 +28,7 @@ export default {
'workingDirectory.createWorktreeTitle': 'Create new worktree',
'workingDirectory.current': 'Current working directory',
'workingDirectory.defaultBadge': 'Default',
+ 'workingDirectory.defaultUpdateFailed': 'Couldn’t update the default working directory',
'workingDirectory.deleteBranchAction': 'Delete branch',
'workingDirectory.deleteBranchConfirm':
'Delete branch “{{name}}”? This permanently removes it, including any unmerged commits.',
@@ -64,7 +66,7 @@ export default {
'workingDirectory.pushInProgress': 'Pushing…',
'workingDirectory.pushNoop': 'Everything up-to-date',
'workingDirectory.pushSuccess': 'Pushed successfully',
- 'workingDirectory.recent': 'Working directories',
+ 'workingDirectory.recent': 'Working directory',
'workingDirectory.refreshGitStatus': 'Refresh branch & PR status',
'workingDirectory.removeRecent': 'Remove from recent',
'workingDirectory.removed': 'Removed “{{name}}”',
diff --git a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
index d56d232a7a3..618ad7a2cbd 100644
--- a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
+++ b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx
@@ -4,7 +4,7 @@ import { isDesktop } from '@lobechat/const';
import type { WorkingDirEntry } from '@lobechat/types';
import { getWorkingDirSourcePath } from '@lobechat/types';
import { isRecord } from '@lobechat/utils';
-import { Flexbox, Icon, Input, Popover, Tooltip } from '@lobehub/ui';
+import { ActionIcon, Flexbox, Icon, Input, Popover, Tooltip } from '@lobehub/ui';
import { toast } from '@lobehub/ui/base-ui';
import { createStaticStyles, cssVar, cx } from 'antd-style';
import {
@@ -160,27 +160,6 @@ const styles = createStaticStyles(({ css }) => ({
text-overflow: ellipsis;
white-space: nowrap;
`,
- rowAction: css`
- cursor: pointer;
-
- display: flex;
- flex: none;
- align-items: center;
- justify-content: center;
-
- width: 20px;
- height: 20px;
- border-radius: ${cssVar.borderRadius};
-
- color: ${cssVar.colorTextQuaternary};
-
- transition: all 0.2s;
-
- &:hover {
- color: ${cssVar.colorTextSecondary};
- background: ${cssVar.colorFillSecondary};
- }
- `,
rowActions: css`
display: none;
flex: none;
@@ -365,6 +344,7 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =
);
const { clear, commit } = useCommitWorkingDirectory(agentId);
+ const clearDeviceDefaultCwd = useDeviceStore((s) => s.clearDeviceDefaultCwd);
const removeDeviceWorkingDir = useDeviceStore((s) => s.removeDeviceWorkingDir);
const updateDeviceCwd = useDeviceStore((s) => s.updateDeviceCwd);
@@ -425,15 +405,29 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =
});
};
- const handleSetDefault = (e: React.MouseEvent, entry: WorkingDirEntry) => {
+ const handleToggleDefault = async (
+ e: React.MouseEvent,
+ entry: WorkingDirEntry,
+ isDefault: boolean,
+ ) => {
e.stopPropagation();
- if (targetDeviceId) void updateDeviceCwd(targetDeviceId, entry, { setDefault: true });
+ if (!targetDeviceId) return;
+
+ try {
+ if (isDefault) await clearDeviceDefaultCwd(targetDeviceId);
+ else await updateDeviceCwd(targetDeviceId, entry, { setDefault: true });
+ } catch {
+ toast.error(t('workingDirectory.defaultUpdateFailed'));
+ }
};
const renderRow = (entry: WorkingDirEntry) => {
const sourcePath = getWorkingDirSourcePath(entry);
const isActive = sourcePath === selectedDir;
const isDefault = !!deviceDefaultCwd && sourcePath === deviceDefaultCwd;
+ const defaultActionLabel = t(
+ isDefault ? 'workingDirectory.clearDefault' : 'workingDirectory.setDefault',
+ );
return (
<Flexbox
horizontal
@@ -457,24 +451,27 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =
<div className={styles.dirPath}>{entry.path}</div>
</Flexbox>
<Flexbox horizontal align={'center'} gap={2} style={{ flex: 'none' }}>
- {/* Set-as-default is offered on every non-default row — including the
- active one (promoting the dir you're currently using to the device
- default is the common case). Remove (X) is hidden on the active row:
- you can't remove the selection out from under yourself. */}
+ {/* The same Star toggles the device default in both directions. Remove
+ (X) is hidden on the active row: you can't remove the selection out
+ from under yourself. */}
<div className={cx('wd-row-actions', styles.rowActions)}>
- {!isDefault && (
- <Tooltip title={t('workingDirectory.setDefault')}>
- <div className={styles.rowAction} onClick={(e) => handleSetDefault(e, entry)}>
- <Icon icon={StarIcon} size={13} />
- </div>
- </Tooltip>
- )}
+ <ActionIcon
+ active={isDefault}
+ aria-label={defaultActionLabel}
+ aria-pressed={isDefault}
+ icon={StarIcon}
+ size={{ blockSize: 20, size: 13 }}
+ title={defaultActionLabel}
+ onClick={(e) => void handleToggleDefault(e, entry, isDefault)}
+ />
{!isActive && (
- <Tooltip title={t('workingDirectory.removeRecent')}>
- <div className={styles.rowAction} onClick={(e) => handleRemoveRecent(e, entry)}>
- <Icon icon={XIcon} size={12} />
- </div>
- </Tooltip>
+ <ActionIcon
+ aria-label={t('workingDirectory.removeRecent')}
+ icon={XIcon}
+ size={{ blockSize: 20, size: 12 }}
+ title={t('workingDirectory.removeRecent')}
+ onClick={(e) => handleRemoveRecent(e, entry)}
+ />
)}
</div>
{isActive && (
@@ -537,7 +534,7 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =
const displayName = selectedDir
? (getWorkingDirectoryName(selectedDir) ?? selectedDir)
- : t('workingDirectory.notSet');
+ : t('workingDirectory.title');
const trigger = (
<div className={styles.button}>
@@ -564,7 +561,7 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =
{open ? (
trigger
) : (
- <Tooltip title={selectedDir || t('workingDirectory.notSet')}>{trigger}</Tooltip>
+ <Tooltip title={selectedDir || t('workingDirectory.title')}>{trigger}</Tooltip>
)}
</div>
</Popover>
diff --git a/src/routes/(main)/agent/profile/features/Header/AutoSaveHint.tsx b/src/routes/(main)/agent/profile/features/Header/AutoSaveHint.tsx
deleted file mode 100644
index 69676c1f509..00000000000
--- a/src/routes/(main)/agent/profile/features/Header/AutoSaveHint.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-'use client';
-
-import { memo } from 'react';
-
-import AutoSaveHintBase from '@/components/Editor/AutoSaveHint';
-import { useAgentStore } from '@/store/agent';
-
-/**
- * AutoSaveHint - Save status indicator for agent settings
- */
-const AutoSaveHint = memo(() => {
- const saveStatus = useAgentStore((s) => s.saveStatus);
- const lastUpdatedTime = useAgentStore((s) => s.lastUpdatedTime);
-
- return <AutoSaveHintBase lastUpdatedTime={lastUpdatedTime} saveStatus={saveStatus || 'idle'} />;
-});
-
-export default AutoSaveHint;
diff --git a/src/routes/(main)/agent/profile/features/Header/index.test.tsx b/src/routes/(main)/agent/profile/features/Header/index.test.tsx
index 457074398ec..18c649c302a 100644
--- a/src/routes/(main)/agent/profile/features/Header/index.test.tsx
+++ b/src/routes/(main)/agent/profile/features/Header/index.test.tsx
@@ -208,10 +208,6 @@ vi.mock('./AgentStatusTag', () => ({
default: () => null,
}));
-vi.mock('./AutoSaveHint', () => ({
- default: () => null,
-}));
-
vi.mock('./AgentVersionReviewTag', () => ({
default: () => null,
}));
diff --git a/src/routes/(main)/agent/profile/features/Header/index.tsx b/src/routes/(main)/agent/profile/features/Header/index.tsx
index d3533b8033b..e913580ae9c 100644
--- a/src/routes/(main)/agent/profile/features/Header/index.tsx
+++ b/src/routes/(main)/agent/profile/features/Header/index.tsx
@@ -36,7 +36,6 @@ import { selectors as profileSelectors, useProfileStore } from '../store';
import AgentForkTag from './AgentForkTag';
import AgentStatusTag from './AgentStatusTag';
import AgentVersionReviewTag from './AgentVersionReviewTag';
-import AutoSaveHint from './AutoSaveHint';
type HeaderTranslation = TFunction<
readonly ['setting', 'chat', 'file', 'common', 'spend'],
@@ -253,7 +252,6 @@ const Header = memo(() => {
{activeAgentId && (
<AgentBreadcrumb agentId={activeAgentId} title={t('tab.profile', { ns: 'chat' })} />
)}
- <AutoSaveHint />
<AgentStatusTag />
<AgentVersionReviewTag />
<AgentForkTag />
diff --git a/src/store/device/action.test.ts b/src/store/device/action.test.ts
new file mode 100644
index 00000000000..112e7c87535
--- /dev/null
+++ b/src/store/device/action.test.ts
@@ -0,0 +1,97 @@
+import type { DeviceListItem, WorkingDirEntry } from '@lobechat/types';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { mutate } from '@/libs/swr';
+import { deviceKeys } from '@/libs/swr/keys';
+import { deviceService } from '@/services/device';
+
+import { deviceSelectors } from './selectors';
+import { useDeviceStore } from './store';
+
+vi.mock('@/libs/swr', () => ({
+ mutate: vi.fn(),
+ useClientDataSWR: vi.fn(),
+}));
+
+const buildDevice = (overrides: Partial<DeviceListItem> = {}): DeviceListItem => ({
+ channels: [],
+ defaultCwd: '/repo',
+ deviceId: 'dev-1',
+ enroller: null,
+ friendlyName: null,
+ hostname: null,
+ identitySource: 'machine-id',
+ lastSeen: new Date(0).toISOString(),
+ online: false,
+ platform: null,
+ registered: true,
+ scope: 'personal',
+ workingDirs: [],
+ ...overrides,
+});
+
+describe('DeviceAction', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.mocked(mutate).mockResolvedValue(undefined);
+ vi.spyOn(deviceService, 'updateDevice').mockResolvedValue({ success: true });
+ useDeviceStore.setState({ devices: [], isDevicesInit: true });
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
+ describe('clearDeviceDefaultCwd', () => {
+ it('clears the device default without removing it from recent directories', async () => {
+ const workingDirs: WorkingDirEntry[] = [
+ { path: '/repo', repoType: 'git' },
+ { path: '/other' },
+ ];
+ const otherDevice = buildDevice({
+ defaultCwd: '/other-device',
+ deviceId: 'dev-2',
+ workingDirs: [{ path: '/other-device' }],
+ });
+ useDeviceStore.setState({
+ devices: [buildDevice({ workingDirs }), otherDevice],
+ });
+
+ await useDeviceStore.getState().clearDeviceDefaultCwd('dev-1');
+
+ const state = useDeviceStore.getState();
+ expect(deviceSelectors.getDeviceDefaultCwd('dev-1')(state)).toBeUndefined();
+ expect(deviceSelectors.getDeviceWorkingDirs('dev-1')(state)).toEqual(workingDirs);
+ expect(state.devices.find((device) => device.deviceId === 'dev-2')).toEqual(otherDevice);
+ expect(deviceService.updateDevice).toHaveBeenCalledWith({
+ defaultCwd: null,
+ deviceId: 'dev-1',
+ });
+ expect(mutate).toHaveBeenCalledWith(deviceKeys.listDevices());
+ });
+
+ it('does nothing when the target device does not exist', async () => {
+ useDeviceStore.setState({ devices: [buildDevice()] });
+
+ await useDeviceStore.getState().clearDeviceDefaultCwd('missing');
+
+ expect(deviceService.updateDevice).not.toHaveBeenCalled();
+ expect(mutate).not.toHaveBeenCalled();
+ });
+
+ it('restores the previous default and revalidates when persistence fails', async () => {
+ const workingDirs: WorkingDirEntry[] = [{ path: '/repo', repoType: 'git' }];
+ useDeviceStore.setState({ devices: [buildDevice({ workingDirs })] });
+ vi.mocked(deviceService.updateDevice).mockRejectedValueOnce(new Error('save failed'));
+
+ await expect(useDeviceStore.getState().clearDeviceDefaultCwd('dev-1')).rejects.toThrow(
+ 'save failed',
+ );
+
+ const state = useDeviceStore.getState();
+ expect(deviceSelectors.getDeviceDefaultCwd('dev-1')(state)).toBe('/repo');
+ expect(deviceSelectors.getDeviceWorkingDirs('dev-1')(state)).toEqual(workingDirs);
+ expect(mutate).toHaveBeenCalledWith(deviceKeys.listDevices());
+ });
+ });
+});
diff --git a/src/store/device/action.ts b/src/store/device/action.ts
index dd02ae348be..44c2f419c6f 100644
--- a/src/store/device/action.ts
+++ b/src/store/device/action.ts
@@ -68,6 +68,42 @@ export class DeviceActionImpl {
}
};
+ /** Clear a device's default cwd without removing it from the recent directory list. */
+ clearDeviceDefaultCwd = async (deviceId: string): Promise<void> => {
+ const device = this.#get().devices.find((d) => d.deviceId === deviceId);
+ if (!device?.defaultCwd) return;
+
+ const previousDefaultCwd = device.defaultCwd;
+
+ this.#set(
+ {
+ devices: this.#get().devices.map((d) =>
+ d.deviceId === deviceId ? { ...d, defaultCwd: null } : d,
+ ) as DeviceListItem[],
+ },
+ false,
+ 'clearDeviceDefaultCwd',
+ );
+
+ try {
+ await deviceService.updateDevice({ defaultCwd: null, deviceId });
+ } catch (error) {
+ // Preserve the prior default if the optimistic write cannot be persisted.
+ this.#set(
+ {
+ devices: this.#get().devices.map((d) =>
+ d.deviceId === deviceId ? { ...d, defaultCwd: previousDefaultCwd } : d,
+ ) as DeviceListItem[],
+ },
+ false,
+ 'clearDeviceDefaultCwd/error',
+ );
+ throw error;
+ } finally {
+ await mutate(deviceKeys.listDevices());
+ }
+ };
+
/**
* Merge legacy recent dirs (read from localStorage by the caller — the store
* stays out of feature-layer storage) into a device's `device.workingDirs`.