🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 fix(RuntimeConfig): instant-apply working directory with recent list (#13641)
Innei4d15979fab5e
diff --git a/apps/desktop/src/main/controllers/SystemCtr.ts b/apps/desktop/src/main/controllers/SystemCtr.tsindex 9f2762c310b..2a40b0109bf 100644--- a/apps/desktop/src/main/controllers/SystemCtr.ts+++ b/apps/desktop/src/main/controllers/SystemCtr.ts@@ -1,3 +1,5 @@+import { readFile } from 'node:fs/promises';+import path from 'node:path';import process from 'node:process';import type { ElectronAppState, ThemeMode } from '@lobechat/electron-client-ipc';@@ -169,7 +171,7 @@ export default class SystemController extends ControllerModule {async selectFolder(payload?: {defaultPath?: string;title?: string;- }): Promise<string | undefined> {+ }): Promise<{ path: string; repoType?: 'git' | 'github' } | undefined> {const mainWindow = this.app.browserManager.getMainWindow()?.browserWindow;const result = await dialog.showOpenDialog(mainWindow!, {@@ -182,7 +184,10 @@ export default class SystemController extends ControllerModule {return undefined;}- return result.filePaths[0];+ const folderPath = result.filePaths[0];+ const repoType = await this.detectRepoType(folderPath);++ return { path: folderPath, repoType };}@IpcMethod()@@ -230,6 +235,17 @@ export default class SystemController extends ControllerModule {}}+ private async detectRepoType(dirPath: string): Promise<'git' | 'github' | undefined> {+ const gitConfigPath = path.join(dirPath, '.git', 'config');+ try {+ const config = await readFile(gitConfigPath, 'utf8');+ if (config.includes('github.com')) return 'github';+ return 'git';+ } catch {+ return undefined;+ }+ }+private async setSystemThemeMode(themeMode: ThemeMode) {nativeTheme.themeSource = themeMode;}diff --git a/locales/en-US/plugin.json b/locales/en-US/plugin.jsonindex 46f88012c62..495b4d3cb54 100644--- a/locales/en-US/plugin.json+++ b/locales/en-US/plugin.json@@ -415,9 +415,13 @@"loading.plugin": "Skill running…","localSystem.workingDirectory.agentDescription": "Default working directory for all conversations with this Agent","localSystem.workingDirectory.agentLevel": "Agent Working Directory",+ "localSystem.workingDirectory.chooseDifferentFolder": "Choose a different folder","localSystem.workingDirectory.current": "Current working directory",+ "localSystem.workingDirectory.noRecent": "No recent directories","localSystem.workingDirectory.notSet": "Click to set working directory","localSystem.workingDirectory.placeholder": "Enter directory path, e.g. /Users/name/projects",+ "localSystem.workingDirectory.recent": "Recent",+ "localSystem.workingDirectory.removeRecent": "Remove from recent","localSystem.workingDirectory.selectFolder": "Select folder","localSystem.workingDirectory.title": "Working Directory","localSystem.workingDirectory.topicDescription": "Override Agent default for this conversation only",diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.jsonindex 811865849d6..4234e66cf2e 100644--- a/locales/zh-CN/plugin.json+++ b/locales/zh-CN/plugin.json@@ -416,9 +416,13 @@"loading.plugin": "技能运行中…","localSystem.workingDirectory.agentDescription": "该助手下所有对话的默认工作目录","localSystem.workingDirectory.agentLevel": "代理工作目录",+ "localSystem.workingDirectory.chooseDifferentFolder": "选择其他文件夹","localSystem.workingDirectory.current": "当前工作目录",+ "localSystem.workingDirectory.noRecent": "暂无最近目录","localSystem.workingDirectory.notSet": "点击设置工作目录","localSystem.workingDirectory.placeholder": "输入目录路径,如 /Users/name/projects",+ "localSystem.workingDirectory.recent": "最近使用",+ "localSystem.workingDirectory.removeRecent": "从最近目录中移除","localSystem.workingDirectory.selectFolder": "选择文件夹","localSystem.workingDirectory.title": "工作目录","localSystem.workingDirectory.topicDescription": "仅覆盖当前对话的工作目录",diff --git a/src/features/ChatInput/RuntimeConfig/WorkingDirectory.tsx b/src/features/ChatInput/RuntimeConfig/WorkingDirectory.tsxindex b3f99917486..9e46d80b9ee 100644--- a/src/features/ChatInput/RuntimeConfig/WorkingDirectory.tsx+++ b/src/features/ChatInput/RuntimeConfig/WorkingDirectory.tsx@@ -1,8 +1,9 @@import { isDesktop } from '@lobechat/const';-import { Flexbox, Icon, Text } from '@lobehub/ui';-import { Button, Divider, Input, Space, Switch } from 'antd';-import { FolderOpen } from 'lucide-react';-import { memo, useCallback, useState } from 'react';+import { Github } from '@lobehub/icons';+import { Flexbox, Icon } from '@lobehub/ui';+import { createStaticStyles, cssVar } from 'antd-style';+import { CheckIcon, FolderIcon, FolderOpenIcon, GitBranchIcon, XIcon } from 'lucide-react';+import { memo, type ReactNode, useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';import { electronSystemService } from '@/services/electron/system';@@ -11,6 +12,95 @@ import { agentByIdSelectors } from '@/store/agent/selectors';import { useChatStore } from '@/store/chat';import { topicSelectors } from '@/store/chat/selectors';+import { addRecentDir, getRecentDirs, type RecentDirEntry, removeRecentDir } from './recentDirs';++const styles = createStaticStyles(({ css }) => ({+ chooseFolderItem: css`+ cursor: pointer;++ padding-block: 8px;+ padding-inline: 8px;+ border-radius: ${cssVar.borderRadius};++ font-size: 13px;+ color: ${cssVar.colorTextSecondary};++ transition: background-color 0.2s;++ &:hover {+ color: ${cssVar.colorText};+ background: ${cssVar.colorFillTertiary};+ }+ `,+ dirItem: css`+ cursor: pointer;++ padding-block: 6px;+ padding-inline: 8px;+ border-radius: ${cssVar.borderRadius};++ transition: background-color 0.2s;++ &:hover {+ background: ${cssVar.colorFillTertiary};+ }+ `,+ dirItemActive: css`+ background: ${cssVar.colorFillTertiary};+ `,+ dirName: css`+ font-size: 13px;+ font-weight: 500;+ color: ${cssVar.colorText};+ `,+ dirPath: css`+ overflow: hidden;++ font-size: 11px;+ color: ${cssVar.colorTextDescription};+ text-overflow: ellipsis;+ white-space: nowrap;+ `,+ removeBtn: 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};+ }+ `,+ sectionTitle: css`+ padding-inline: 8px;++ font-size: 11px;+ font-weight: 500;+ color: ${cssVar.colorTextQuaternary};+ text-transform: uppercase;+ letter-spacing: 0.5px;+ `,+}));++const renderDirIcon = (repoType?: 'git' | 'github'): ReactNode => {+ const iconStyle = { color: cssVar.colorTextTertiary, flex: 'none' as const };+ if (repoType === 'github') return <Github size={16} style={iconStyle} />;+ return (+ <Icon icon={repoType === 'git' ? GitBranchIcon : FolderIcon} size={16} style={iconStyle} />+ );+};+interface WorkingDirectoryContentProps {agentId: string;onClose?: () => void;@@ -19,152 +109,111 @@ interface WorkingDirectoryContentProps {const WorkingDirectoryContent = memo<WorkingDirectoryContentProps>(({ agentId, onClose }) => {const { t } = useTranslation('plugin');- // Get current valuesconst agentWorkingDirectory = useAgentStore((s) =>agentByIdSelectors.getAgentWorkingDirectoryById(agentId)(s),);const topicWorkingDirectory = useChatStore(topicSelectors.currentTopicWorkingDirectory);- const activeTopicId = useChatStore((s) => s.activeTopicId);+ const effectiveDir = topicWorkingDirectory || agentWorkingDirectory;- // Actionsconst updateAgentRuntimeEnvConfig = useAgentStore((s) => s.updateAgentRuntimeEnvConfigById);- const updateTopicMetadata = useChatStore((s) => s.updateTopicMetadata);- // Local state for editing- const [agentDir, setAgentDir] = useState(agentWorkingDirectory || '');- const [topicDir, setTopicDir] = useState(topicWorkingDirectory || '');- const [useTopicOverride, setUseTopicOverride] = useState(!!topicWorkingDirectory);- const [loading, setLoading] = useState(false);+ const [recentDirs, setRecentDirs] = useState(getRecentDirs);- const handleSelectAgentFolder = useCallback(async () => {- if (!isDesktop) return;- const folder = await electronSystemService.selectFolder({- defaultPath: agentDir || undefined,- title: t('localSystem.workingDirectory.selectFolder'),- });- if (folder) setAgentDir(folder);- }, [agentDir, t]);+ const displayDirs = useMemo(() => {+ const dirs = [...recentDirs];+ if (effectiveDir && !dirs.some((d) => d.path === effectiveDir)) {+ dirs.unshift({ path: effectiveDir });+ }+ return dirs;+ }, [recentDirs, effectiveDir]);- const handleSelectTopicFolder = useCallback(async () => {+ const selectDir = useCallback(+ async (entry: RecentDirEntry) => {+ await updateAgentRuntimeEnvConfig(agentId, { workingDirectory: entry.path });+ setRecentDirs(addRecentDir(entry));+ onClose?.();+ },+ [agentId, updateAgentRuntimeEnvConfig, onClose],+ );++ const handleChooseFolder = useCallback(async () => {if (!isDesktop) return;- const folder = await electronSystemService.selectFolder({- defaultPath: topicDir || undefined,+ const result = await electronSystemService.selectFolder({+ defaultPath: effectiveDir || undefined,title: t('localSystem.workingDirectory.selectFolder'),});- if (folder) setTopicDir(folder);- }, [topicDir, t]);-- const handleSave = useCallback(async () => {- setLoading(true);- try {- // Save agent working directory- await updateAgentRuntimeEnvConfig(agentId, {- workingDirectory: agentDir || undefined,- });-- // Save topic working directory if override is enabled- if (activeTopicId && useTopicOverride) {- await updateTopicMetadata(activeTopicId, {- workingDirectory: topicDir || undefined,- });- } else if (activeTopicId && !useTopicOverride && topicWorkingDirectory) {- // Clear topic override if disabled- await updateTopicMetadata(activeTopicId, {- workingDirectory: undefined,- });- }-- onClose?.();- } finally {- setLoading(false);+ if (result) {+ await selectDir({ path: result.path, repoType: result.repoType });}- }, [- agentId,- agentDir,- activeTopicId,- useTopicOverride,- topicDir,- topicWorkingDirectory,- updateAgentRuntimeEnvConfig,- updateTopicMetadata,- onClose,- ]);+ }, [effectiveDir, t, selectDir]);++ const handleRemoveRecent = useCallback((e: React.MouseEvent, path: string) => {+ e.stopPropagation();+ setRecentDirs(removeRecentDir(path));+ }, []);++ const getDirName = (path: string) => path.split('/').findLast(Boolean) || path;return (- <Flexbox gap={12} style={{ maxWidth: 600, minWidth: 320 }}>- <Flexbox gap={4}>- <Text style={{ fontSize: 12 }} type="secondary">- {t('localSystem.workingDirectory.agentLevel')}- </Text>- <Flexbox horizontal gap={8}>- <Input- placeholder={t('localSystem.workingDirectory.placeholder')}- size="small"- style={{ flex: 1, fontSize: 12 }}- value={agentDir}- variant={'filled'}- onChange={(e) => setAgentDir(e.target.value)}- />- {isDesktop && (- <Button size="small" type={'text'} onClick={handleSelectAgentFolder}>- <Icon icon={FolderOpen} size={14} />- </Button>- )}+ <Flexbox gap={4} style={{ minWidth: 280 }}>+ <div className={styles.sectionTitle}>{t('localSystem.workingDirectory.recent')}</div>+ {displayDirs.length === 0 ? (+ <Flexbox+ align={'center'}+ justify={'center'}+ style={{ color: cssVar.colorTextQuaternary, fontSize: 12, padding: '12px 8px' }}+ >+ {t('localSystem.workingDirectory.noRecent')}</Flexbox>- </Flexbox>-- {activeTopicId && (- <>- <Divider style={{ margin: 0 }} />-- <Flexbox- horizontal- align="center"- gap={8}- style={{ cursor: 'pointer' }}- onClick={() => {- setUseTopicOverride(!useTopicOverride);- }}- >- <Switch checked={useTopicOverride} size="small" onChange={setUseTopicOverride} />- <Text style={{ fontSize: 12 }}>{t('localSystem.workingDirectory.topicOverride')}</Text>- </Flexbox>-- {useTopicOverride && (- <Flexbox gap={4}>- <Text style={{ fontSize: 12 }} type="secondary">- {t('localSystem.workingDirectory.topicLevel')}- </Text>- <Flexbox horizontal gap={8}>- <Input- placeholder={t('localSystem.workingDirectory.placeholder')}- size="small"- style={{ flex: 1, fontSize: 12 }}- value={topicDir}- variant={'filled'}- onChange={(e) => setTopicDir(e.target.value)}- />- {isDesktop && (- <Button size="small" type={'text'} onClick={handleSelectTopicFolder}>- <Icon icon={FolderOpen} size={14} />- </Button>- )}+ ) : (+ displayDirs.map((entry) => {+ const isActive = entry.path === effectiveDir;+ return (+ <Flexbox+ horizontal+ align={'center'}+ className={`${styles.dirItem} ${isActive ? styles.dirItemActive : ''}`}+ gap={8}+ key={entry.path}+ onClick={() => selectDir(entry)}+ >+ {renderDirIcon(entry.repoType)}+ <Flexbox flex={1} style={{ minWidth: 0 }}>+ <div className={styles.dirName}>{getDirName(entry.path)}</div>+ <div className={styles.dirPath}>{entry.path}</div></Flexbox>+ {isActive ? (+ <Icon+ icon={CheckIcon}+ size={16}+ style={{ color: cssVar.colorSuccess, flex: 'none' }}+ />+ ) : (+ <div+ className={styles.removeBtn}+ title={t('localSystem.workingDirectory.removeRecent')}+ onClick={(e) => handleRemoveRecent(e, entry.path)}+ >+ <Icon icon={XIcon} size={12} />+ </div>+ )}</Flexbox>- )}- </>+ );+ }))}- <Flexbox horizontal justify="flex-end">- <Space>- <Button size="small" onClick={onClose}>- {t('cancel', { ns: 'common' })}- </Button>- <Button loading={loading} size="small" type="primary" onClick={handleSave}>- {t('save', { ns: 'common' })}- </Button>- </Space>- </Flexbox>+ {isDesktop && (+ <Flexbox+ horizontal+ align={'center'}+ className={styles.chooseFolderItem}+ gap={8}+ onClick={handleChooseFolder}+ >+ <Icon icon={FolderOpenIcon} size={14} />+ <span>{t('localSystem.workingDirectory.chooseDifferentFolder')}</span>+ </Flexbox>+ )}</Flexbox>);});diff --git a/src/features/ChatInput/RuntimeConfig/index.tsx b/src/features/ChatInput/RuntimeConfig/index.tsxindex 44b0011bae2..ff0beea146a 100644--- a/src/features/ChatInput/RuntimeConfig/index.tsx+++ b/src/features/ChatInput/RuntimeConfig/index.tsx@@ -1,16 +1,18 @@import { isDesktop } from '@lobechat/const';import { type RuntimeEnvMode } from '@lobechat/types';+import { Github } from '@lobehub/icons';import { Flexbox, Icon, Popover, Skeleton, Tooltip } from '@lobehub/ui';import { createStaticStyles, cssVar, cx } from 'antd-style';import {ChevronDownIcon,CloudIcon,FolderIcon,+ GitBranchIcon,LaptopIcon,MonitorOffIcon,SquircleDashed,} from 'lucide-react';-import { memo, useCallback, useState } from 'react';+import { memo, type ReactNode, useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';import { useAgentStore } from '@/store/agent';@@ -21,6 +23,7 @@ import { topicSelectors } from '@/store/chat/selectors';import { useAgentId } from '../hooks/useAgentId';import { useUpdateAgentConfig } from '../hooks/useUpdateAgentConfig';import ApprovalMode from './ApprovalMode';+import { getRecentDirs } from './recentDirs';import WorkingDirectory from './WorkingDirectory';const MODE_ICONS: Record<RuntimeEnvMode, typeof LaptopIcon> = {@@ -112,6 +115,15 @@ const RuntimeConfig = memo(() => {);const effectiveWorkingDirectory = topicWorkingDirectory || agentWorkingDirectory;+ const dirIconNode = useMemo((): ReactNode => {+ if (!effectiveWorkingDirectory) return <Icon icon={SquircleDashed} size={14} />;+ const dirs = getRecentDirs();+ const match = dirs.find((d) => d.path === effectiveWorkingDirectory);+ if (match?.repoType === 'github') return <Github size={14} />;+ if (match?.repoType === 'git') return <Icon icon={GitBranchIcon} size={14} />;+ return <Icon icon={FolderIcon} size={14} />;+ }, [effectiveWorkingDirectory]);+const switchMode = useCallback(async (mode: RuntimeEnvMode) => {if (mode === runtimeMode) return;@@ -208,7 +220,7 @@ const RuntimeConfig = memo(() => {const dirButton = (<div className={styles.button}>- <Icon icon={effectiveWorkingDirectory ? FolderIcon : SquircleDashed} size={14} />+ {dirIconNode}<span>{displayName}</span><Icon icon={ChevronDownIcon} size={12} /></div>@@ -220,7 +232,8 @@ const RuntimeConfig = memo(() => {<Popovercontent={<WorkingDirectory agentId={agentId} onClose={() => setDirPopoverOpen(false)} />}open={dirPopoverOpen}- placement="bottomRight"+ placement="bottomLeft"+ styles={{ content: { padding: 4 } }}trigger="click"onOpenChange={setDirPopoverOpen}>diff --git a/src/features/ChatInput/RuntimeConfig/recentDirs.ts b/src/features/ChatInput/RuntimeConfig/recentDirs.tsnew file mode 100644index 00000000000..811a032b397--- /dev/null+++ b/src/features/ChatInput/RuntimeConfig/recentDirs.ts@@ -0,0 +1,36 @@+export const RECENT_DIRS_KEY = 'lobechat-recent-working-directories';+export const MAX_RECENT_DIRS = 5;++export interface RecentDirEntry {+ path: string;+ repoType?: 'git' | 'github';+}++export const getRecentDirs = (): RecentDirEntry[] => {+ try {+ const stored = localStorage.getItem(RECENT_DIRS_KEY);+ if (!stored) return [];+ const parsed = JSON.parse(stored);+ if (!Array.isArray(parsed)) return [];+ return parsed+ .map((item: unknown) =>+ typeof item === 'string' ? { path: item } : (item as RecentDirEntry),+ )+ .filter((d): d is RecentDirEntry => !!d?.path);+ } catch {+ return [];+ }+};++export const addRecentDir = (entry: RecentDirEntry): RecentDirEntry[] => {+ const dirs = getRecentDirs().filter((d) => d.path !== entry.path);+ const updated = [entry, ...dirs].slice(0, MAX_RECENT_DIRS);+ localStorage.setItem(RECENT_DIRS_KEY, JSON.stringify(updated));+ return updated;+};++export const removeRecentDir = (path: string): RecentDirEntry[] => {+ const updated = getRecentDirs().filter((d) => d.path !== path);+ localStorage.setItem(RECENT_DIRS_KEY, JSON.stringify(updated));+ return updated;+};diff --git a/src/locales/default/plugin.ts b/src/locales/default/plugin.tsindex 04801ac7cb9..c6298f1f1b3 100644--- a/src/locales/default/plugin.ts+++ b/src/locales/default/plugin.ts@@ -424,8 +424,12 @@ export default {'Default working directory for all conversations with this Agent','localSystem.workingDirectory.agentLevel': 'Agent Working Directory','localSystem.workingDirectory.current': 'Current working directory',+ 'localSystem.workingDirectory.chooseDifferentFolder': 'Choose a different folder',+ 'localSystem.workingDirectory.noRecent': 'No recent directories','localSystem.workingDirectory.notSet': 'Click to set working directory','localSystem.workingDirectory.placeholder': 'Enter directory path, e.g. /Users/name/projects',+ 'localSystem.workingDirectory.recent': 'Recent',+ 'localSystem.workingDirectory.removeRecent': 'Remove from recent','localSystem.workingDirectory.selectFolder': 'Select folder','localSystem.workingDirectory.title': 'Working Directory','localSystem.workingDirectory.topicDescription':diff --git a/src/services/electron/system.ts b/src/services/electron/system.tsindex 8dcd6490d3c..3d3950f9e13 100644--- a/src/services/electron/system.ts+++ b/src/services/electron/system.ts@@ -66,7 +66,7 @@ class ElectronSystemService {async selectFolder(params?: {defaultPath?: string;title?: string;- }): Promise<string | undefined> {+ }): Promise<{ path: string; repoType?: 'git' | 'github' } | undefined> {return this.ipc.system.selectFolder(params);}}