🤯 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(desktop): make working-directory clear work for built-in agents (#16273)
Arvin Xu3b12dc4231d4
diff --git a/locales/en-US/device.json b/locales/en-US/device.jsonindex 40a04bd35b0..c03e54facd0 100644--- a/locales/en-US/device.json+++ b/locales/en-US/device.json@@ -29,6 +29,7 @@"workingDirectory.filesLoading": "Loading changes…","workingDirectory.filesModified": "Modified","workingDirectory.ghMissing": "Install and log in to the GitHub CLI (`gh`) to see linked pull requests",+ "workingDirectory.heteroHint": "This agent always runs inside a working directory. Until you pick one, it uses a default folder — choose another below to change it.","workingDirectory.newBranchPlaceholder": "feature/new-branch-name","workingDirectory.noRecent": "No recent directories","workingDirectory.notSet": "Click to set working directory",diff --git a/locales/zh-CN/device.json b/locales/zh-CN/device.jsonindex 8eb8a674b3a..7954db885fa 100644--- a/locales/zh-CN/device.json+++ b/locales/zh-CN/device.json@@ -29,6 +29,7 @@"workingDirectory.filesLoading": "加载中…","workingDirectory.filesModified": "修改","workingDirectory.ghMissing": "安装并登录 GitHub CLI(gh)即可显示关联的 Pull Request",+ "workingDirectory.heteroHint": "该 Agent 始终在某个工作目录中运行。在你手动选择之前,会使用默认目录——可在下方选择其他目录。","workingDirectory.newBranchPlaceholder": "feature/新分支名称","workingDirectory.noRecent": "暂无最近目录","workingDirectory.notSet": "点击设置工作目录",diff --git a/packages/locales/src/default/device.ts b/packages/locales/src/default/device.tsindex 2d4d64904eb..b94e6955500 100644--- a/packages/locales/src/default/device.ts+++ b/packages/locales/src/default/device.ts@@ -34,6 +34,8 @@ export default {'workingDirectory.filesModified': 'Modified','workingDirectory.ghMissing':'Install and log in to the GitHub CLI (`gh`) to see linked pull requests',+ 'workingDirectory.heteroHint':+ 'This agent always runs inside a working directory. Until you pick one, it uses a default folder — choose another below to change it.','workingDirectory.newBranchPlaceholder': 'feature/new-branch-name','workingDirectory.noRecent': 'No recent directories','workingDirectory.notSet': 'Click to set working directory',diff --git a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsxindex 2f169d7a6a3..e53ee8cff90 100644--- a/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx+++ b/src/features/ChatInput/ControlBar/WorkingDirectoryPicker.tsx@@ -9,6 +9,7 @@ import {FolderIcon,FolderOpenIcon,FolderPlusIcon,+ InfoIcon,XIcon,} from 'lucide-react';import { memo, useState } from 'react';@@ -125,6 +126,19 @@ const styles = createStaticStyles(({ css }) => ({text-overflow: ellipsis;white-space: nowrap;`,+ hint: css`+ margin-block: 2px 4px;+ margin-inline: 4px;+ padding-block: 6px;+ padding-inline: 8px;+ border-radius: ${cssVar.borderRadius};++ font-size: 12px;+ line-height: 1.5;+ color: ${cssVar.colorTextSecondary};++ background: ${cssVar.colorFillQuaternary};+ `,removeBtn: css`cursor: pointer;@@ -256,6 +270,10 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =useMigrateDeviceRecents();const agencyConfig = useAgentStore(agentByIdSelectors.getAgencyConfigById(agentId));+ // Derive hetero-ness from the agencyConfig already in hand — `heterogeneousProvider`+ // is exactly what `isAgentHeterogeneousById` checks, so a second store subscription+ // would only be redundant binding.+ const isHeterogeneous = !!agencyConfig?.heterogeneousProvider;const currentDeviceId = useElectronStore((s) => s.gatewayDeviceInfo?.deviceId);const targetDeviceId = resolveTargetDeviceId(agencyConfig, currentDeviceId);// The local machine's filesystem is browsable; a remote device's is not.@@ -305,6 +323,12 @@ const WorkingDirectoryPicker = memo<WorkingDirectoryPickerProps>(({ agentId }) =const content = (<Flexbox gap={4} style={{ minWidth: 280 }}>+ {isHeterogeneous && (+ <Flexbox horizontal align={'flex-start'} className={styles.hint} gap={6}>+ <Icon icon={InfoIcon} size={14} style={{ flex: 'none', marginTop: 2 }} />+ <span>{t('workingDirectory.heteroHint')}</span>+ </Flexbox>+ )}<Flexbox horizontal align={'center'} distribution={'space-between'}><div className={styles.sectionTitle}>{t('workingDirectory.recent')}</div>{hasClearableSelection && (diff --git a/src/features/ChatInput/ControlBar/useCommitWorkingDirectory.ts b/src/features/ChatInput/ControlBar/useCommitWorkingDirectory.tsindex 0348db2a674..876bade5f2a 100644--- a/src/features/ChatInput/ControlBar/useCommitWorkingDirectory.ts+++ b/src/features/ChatInput/ControlBar/useCommitWorkingDirectory.ts@@ -13,12 +13,20 @@ import { useElectronStore } from '@/store/electron';/*** Unified working-directory writes, shared by the directory picker for both- * local and remote runs. Write rules:+ * local and remote runs.*+ * **Set** rules:* - **active topic** → `topic.metadata.workingDirectory` (per-topic override)* - **no topic yet** → `agencyConfig.workingDirByDevice[targetDeviceId]`* - **always** → upsert the target device's `workingDirs` recent list*+ * **Clear** cascades to whichever precedence level currently supplies the cwd+ * (topic override first, then the agent-level default), instead of only the+ * active topic. Built-in agents never bake the cwd into the topic the way the+ * hetero flow does (see `conversationLifecycle` newTopic metadata), so a+ * topic-only clear would leave the agent-level value re-supplying the directory+ * and Clear would look dead.+ ** Changing a topic's cwd invalidates its pinned CC session (sessions are keyed* per-cwd), so warn before the implicit reset — same as the legacy pickers.*/@@ -43,36 +51,23 @@ export const useCommitWorkingDirectory = (agentId: string) => {const targetDeviceId = resolveTargetDeviceId(agencyConfig, currentDeviceId);const writeCwd = useCallback(- async (newPath: string | undefined, entry?: WorkingDirEntry) => {+ async (newPath: string, entry?: WorkingDirEntry) => {// Topic override wins once a conversation exists; otherwise persist the// agent's per-device choice so a new topic inherits it.if (activeTopicId) {await updateTopicMetadata(activeTopicId, { workingDirectory: newPath });- } else {- if (targetDeviceId) {- const prev = agencyConfig?.workingDirByDevice ?? {};- // Clearing sends `undefined` rather than dropping the key: deep-merge- // (client store + server persist) can't remove a key, so the delete is- // carried as an explicit `undefined` and pruned after each merge.- const nextMap: Record<string, string | undefined> = {- ...prev,- [targetDeviceId]: newPath || undefined,- };- await updateAgentConfigById(agentId, {- agencyConfig: { ...agencyConfig, workingDirByDevice: nextMap },- });- }- // Clearing the agent default must also drop the legacy per-agent value —- // otherwise it keeps re-supplying a stale cwd from a lower precedence- // level and Clear looks dead. (Only clears the localStorage map; no- // network round-trip since `workingDirectory` is stripped before send.)- if (!newPath && legacyAgentWorkingDirectory) {- await updateAgentRuntimeEnvConfigById(agentId, { workingDirectory: undefined });- }+ } else if (targetDeviceId) {+ const prev = agencyConfig?.workingDirByDevice ?? {};+ await updateAgentConfigById(agentId, {+ agencyConfig: {+ ...agencyConfig,+ workingDirByDevice: { ...prev, [targetDeviceId]: newPath },+ },+ });}// Record on the target device's recent list (not the device-wide default —// a per-agent pick shouldn't repoint other agents on the same device).- if (newPath && entry && targetDeviceId) {+ if (entry && targetDeviceId) {await updateDeviceCwd(targetDeviceId, { ...entry, path: newPath }, { setDefault: false });}},@@ -81,14 +76,53 @@ export const useCommitWorkingDirectory = (agentId: string) => {agencyConfig,activeTopicId,targetDeviceId,- legacyAgentWorkingDirectory,updateAgentConfigById,- updateAgentRuntimeEnvConfigById,updateTopicMetadata,updateDeviceCwd,],);+ // Clear whichever precedence level currently supplies the cwd, so the picker+ // falls back to the next level (agent default → device default → "not set").+ const clearCwd = useCallback(async () => {+ // A topic override (when present) is the effective source — drop it first so+ // we fall back to the agent default rather than nuking everything.+ if (activeTopicId && activeTopic?.metadata?.workingDirectory) {+ await updateTopicMetadata(activeTopicId, { workingDirectory: undefined });+ return;+ }+ // No topic override: clear the agent-level default(s). Clearing sends+ // `undefined` rather than dropping the key — deep-merge (client store ++ // server persist) can't remove a key, so the delete is carried as an+ // explicit `undefined` and pruned after each merge. The user can't tell the+ // per-device map from the legacy slot, so clear both together to avoid a+ // dead second click.+ if (targetDeviceId && agencyConfig?.workingDirByDevice?.[targetDeviceId]) {+ const nextMap: Record<string, string | undefined> = {+ ...agencyConfig.workingDirByDevice,+ [targetDeviceId]: undefined,+ };+ await updateAgentConfigById(agentId, {+ agencyConfig: { ...agencyConfig, workingDirByDevice: nextMap },+ });+ }+ // (Only clears the localStorage map; no network round-trip since+ // `workingDirectory` is stripped before send.)+ if (legacyAgentWorkingDirectory) {+ await updateAgentRuntimeEnvConfigById(agentId, { workingDirectory: undefined });+ }+ }, [+ agentId,+ agencyConfig,+ activeTopic,+ activeTopicId,+ targetDeviceId,+ legacyAgentWorkingDirectory,+ updateAgentConfigById,+ updateAgentRuntimeEnvConfigById,+ updateTopicMetadata,+ ]);+/** Pick a directory (with the CC-session-reset guard). */const commit = useCallback(async (entry: WorkingDirEntry) => {@@ -145,7 +179,7 @@ export const useCommitWorkingDirectory = (agentId: string) => {/** Clear the current selection (falls back to the next precedence level). */const clear = useCallback(async () => {- const run = () => writeCwd(undefined);+ const run = () => clearCwd();const priorSessionId = activeTopic?.metadata?.heteroSessionId;const priorCwd = activeTopic?.metadata?.workingDirectory;@@ -160,7 +194,7 @@ export const useCommitWorkingDirectory = (agentId: string) => {return;}await run();- }, [activeTopic, t, writeCwd]);+ }, [activeTopic, t, clearCwd]);return { clear, commit, commitAgentDefault };};