🤯 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(agent): hold per-agent working directory in store (#15204)
Innei4c6a3999c1d4
diff --git a/src/store/agent/selectors/agentByIdSelectors.ts b/src/store/agent/selectors/agentByIdSelectors.tsindex 8e20c8f465f..ef209054334 100644--- a/src/store/agent/selectors/agentByIdSelectors.ts+++ b/src/store/agent/selectors/agentByIdSelectors.ts@@ -11,7 +11,6 @@ import {import { globalAgentContextManager } from '@/helpers/GlobalAgentContextManager';import { type AgentStoreState } from '../initialState';-import { getLocalAgentWorkingDirectory } from '../utils/localAgentWorkingDirectoryStorage';import { agentSelectors } from './selectors';/**@@ -90,11 +89,11 @@ const getAgentRuntimeEnvConfigById =*/const getAgentWorkingDirectoryById =(agentId: string) =>- (_s: AgentStoreState): string | undefined => {+ (s: AgentStoreState): string | undefined => {if (!isDesktop) return;const ctx = globalAgentContextManager.getContext();- return getLocalAgentWorkingDirectory(agentId) ?? ctx.desktopPath ?? ctx.homePath;+ return s.localAgentWorkingDirectoryMap[agentId] ?? ctx.desktopPath ?? ctx.homePath;};/**diff --git a/src/store/agent/selectors/selectors.ts b/src/store/agent/selectors/selectors.tsindex 45f2eaab0ab..30e10c675c8 100644--- a/src/store/agent/selectors/selectors.ts+++ b/src/store/agent/selectors/selectors.ts@@ -24,7 +24,6 @@ import { globalAgentContextManager } from '@/helpers/GlobalAgentContextManager';import { filterToolIds } from '@/helpers/toolFilters';import { type AgentStoreState } from '../initialState';-import { getLocalAgentWorkingDirectory } from '../utils/localAgentWorkingDirectoryStorage';import { builtinAgentSelectors } from './builtinAgentSelectors';// ========== Meta ============== //@@ -271,7 +270,7 @@ const currentAgentWorkingDirectory = (s: AgentStoreState): string | undefined =>if (!activeAgentId) return globalAgentContextManager.getContext().homePath;return (- getLocalAgentWorkingDirectory(activeAgentId) ??+ s.localAgentWorkingDirectoryMap[activeAgentId] ??globalAgentContextManager.getContext().homePath);})();diff --git a/src/store/agent/slices/agent/action.ts b/src/store/agent/slices/agent/action.tsindex cdf51f8ee44..c9a8f14cb82 100644--- a/src/store/agent/slices/agent/action.ts+++ b/src/store/agent/slices/agent/action.ts@@ -227,6 +227,13 @@ export class AgentSliceActionImpl {if (isDesktop && 'workingDirectory' in config) {setLocalAgentWorkingDirectory(agentId, config.workingDirectory);+ const nextMap = { ...this.#get().localAgentWorkingDirectoryMap };+ if (config.workingDirectory) {+ nextMap[agentId] = config.workingDirectory;+ } else {+ delete nextMap[agentId];+ }+ this.#set({ localAgentWorkingDirectoryMap: nextMap }, false, 'updateAgentWorkingDirectory');}const restConfig = { ...config };diff --git a/src/store/agent/slices/agent/initialState.ts b/src/store/agent/slices/agent/initialState.tsindex 817d2d67d60..a733114a356 100644--- a/src/store/agent/slices/agent/initialState.ts+++ b/src/store/agent/slices/agent/initialState.ts@@ -5,6 +5,8 @@ import { type AgentSettingsInstance } from '@/features/AgentSetting';import { type AgentItem } from '@/types/agent';import { type MetaData } from '@/types/meta';+import { readAllLocalAgentWorkingDirectories } from '../../utils/localAgentWorkingDirectoryStorage';+export type LoadingState = Record<Partial<keyof MetaData> | string, boolean>;export type SaveStatus = 'idle' | 'saving' | 'saved';@@ -25,6 +27,11 @@ export interface AgentSliceState {* Loading state for meta fields (used during autocomplete)*/loadingState: LoadingState;+ /**+ * Per-agent local working directory. Persisted to localStorage; held in+ * store so subscribers re-render on change.+ */+ localAgentWorkingDirectoryMap: Record<string, string>;/*** Save status for showing auto-save hint*/@@ -48,6 +55,7 @@ export const initialAgentSliceState: AgentSliceState = {agentMap: {},isAgentPinned: false,lastUpdatedTime: null,+ localAgentWorkingDirectoryMap: readAllLocalAgentWorkingDirectories(),loadingState: {avatar: false,backgroundColor: false,diff --git a/src/store/agent/utils/localAgentWorkingDirectoryStorage.ts b/src/store/agent/utils/localAgentWorkingDirectoryStorage.tsindex cd2141e7919..a9ee782d397 100644--- a/src/store/agent/utils/localAgentWorkingDirectoryStorage.ts+++ b/src/store/agent/utils/localAgentWorkingDirectoryStorage.ts@@ -38,6 +38,8 @@ export const getLocalAgentWorkingDirectory = (agentId: string): string | undefinreturn readMap()[agentId];};+export const readAllLocalAgentWorkingDirectories = (): Record<string, string> => readMap();+export const setLocalAgentWorkingDirectory = (agentId: string, workingDirectory?: string): void => {if (!agentId) return;