Use agent directories for working dir suggestions

This commit is contained in:
Mohamed Boudra
2025-12-23 23:11:48 +07:00
parent c4b9a68c6b
commit 38c1f52035
@@ -250,7 +250,7 @@ function AgentFlowModal({
const isImportFlow = flow === "import"; const isImportFlow = flow === "import";
const isCreateFlow = !isImportFlow; const isCreateFlow = !isImportFlow;
const { recentPaths, addRecentPath } = useRecentPaths(); const { addRecentPath } = useRecentPaths();
const { connectionStates } = useDaemonConnections(); const { connectionStates } = useDaemonConnections();
const daemonEntries = useMemo(() => Array.from(connectionStates.values()), [connectionStates]); const daemonEntries = useMemo(() => Array.from(connectionStates.values()), [connectionStates]);
const initialServerId = useMemo(() => { const initialServerId = useMemo(() => {
@@ -351,6 +351,18 @@ function AgentFlowModal({
const agents = session?.agents; const agents = session?.agents;
const providerModels = session?.providerModels; const providerModels = session?.providerModels;
const requestProviderModels = session?.requestProviderModels; const requestProviderModels = session?.requestProviderModels;
const agentWorkingDirSuggestions = useMemo(() => {
if (!selectedServerId || !agents) {
return [];
}
const uniquePaths = new Set<string>();
agents.forEach((agent) => {
if (agent.cwd) {
uniquePaths.add(agent.cwd);
}
});
return Array.from(uniquePaths);
}, [agents, selectedServerId]);
const gitRepoInfoRequest = useDaemonRequest< const gitRepoInfoRequest = useDaemonRequest<
{ cwd: string }, { cwd: string },
RepoInfoState, RepoInfoState,
@@ -2167,7 +2179,7 @@ function AgentFlowModal({
onOpen={() => openDropdownSheet("workingDir")} onOpen={() => openDropdownSheet("workingDir")}
onClose={closeDropdown} onClose={closeDropdown}
disabled={isLoading} disabled={isLoading}
recentPaths={recentPaths} suggestedPaths={agentWorkingDirSuggestions}
onSelectPath={handleUserWorkingDirChange} onSelectPath={handleUserWorkingDirChange}
/> />
@@ -2755,7 +2767,7 @@ interface WorkingDirectoryDropdownProps {
onOpen: () => void; onOpen: () => void;
onClose: () => void; onClose: () => void;
disabled: boolean; disabled: boolean;
recentPaths: string[]; suggestedPaths: string[];
onSelectPath: (value: string) => void; onSelectPath: (value: string) => void;
} }
@@ -2766,7 +2778,7 @@ function WorkingDirectoryDropdown({
onOpen, onOpen,
onClose, onClose,
disabled, disabled,
recentPaths, suggestedPaths,
onSelectPath, onSelectPath,
}: WorkingDirectoryDropdownProps): ReactElement { }: WorkingDirectoryDropdownProps): ReactElement {
const inputRef = useRef<TextInput | null>(null); const inputRef = useRef<TextInput | null>(null);
@@ -2782,14 +2794,14 @@ function WorkingDirectoryDropdown({
const normalizedSearch = searchQuery.trim().toLowerCase(); const normalizedSearch = searchQuery.trim().toLowerCase();
const filteredPaths = useMemo(() => { const filteredPaths = useMemo(() => {
if (!normalizedSearch) { if (!normalizedSearch) {
return recentPaths; return suggestedPaths;
} }
return recentPaths.filter((path) => return suggestedPaths.filter((path) =>
path.toLowerCase().includes(normalizedSearch) path.toLowerCase().includes(normalizedSearch)
); );
}, [recentPaths, normalizedSearch]); }, [suggestedPaths, normalizedSearch]);
const hasRecentPaths = recentPaths.length > 0; const hasSuggestedPaths = suggestedPaths.length > 0;
const hasMatches = filteredPaths.length > 0; const hasMatches = filteredPaths.length > 0;
const sanitizedSearchValue = searchQuery.trim(); const sanitizedSearchValue = searchQuery.trim();
const showCustomOption = sanitizedSearchValue.length > 0; const showCustomOption = sanitizedSearchValue.length > 0;
@@ -2812,9 +2824,9 @@ function WorkingDirectoryDropdown({
disabled={disabled} disabled={disabled}
errorMessage={errorMessage || undefined} errorMessage={errorMessage || undefined}
helperText={ helperText={
hasRecentPaths hasSuggestedPaths
? "Search saved directories or paste a new path." ? "Search directories from existing agents or paste a new path."
: "No saved directories yet - search to add one." : "No agent directories yet - search to add one."
} }
/> />
<DropdownSheet title="Working Directory" visible={isOpen} onClose={onClose}> <DropdownSheet title="Working Directory" visible={isOpen} onClose={onClose}>
@@ -2828,9 +2840,9 @@ function WorkingDirectoryDropdown({
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
/> />
{!hasRecentPaths && !showCustomOption ? ( {!hasSuggestedPaths && !showCustomOption ? (
<Text style={styles.helperText}> <Text style={styles.helperText}>
We will remember the directories you use most often. We'll suggest directories from agents on this host once they exist.
</Text> </Text>
) : null} ) : null}
{showCustomOption ? ( {showCustomOption ? (
@@ -2869,9 +2881,9 @@ function WorkingDirectoryDropdown({
); );
})} })}
</View> </View>
) : hasRecentPaths ? ( ) : hasSuggestedPaths ? (
<Text style={styles.helperText}> <Text style={styles.helperText}>
No recent paths match your search. No agent directories match your search.
</Text> </Text>
) : null} ) : null}
</DropdownSheet> </DropdownSheet>