refactor: move daemon registry into host-runtime store

This commit is contained in:
Mohamed Boudra
2026-03-12 19:02:06 +07:00
parent 9f089be946
commit 554017b0b8
36 changed files with 1487 additions and 1194 deletions
@@ -21,7 +21,7 @@ import {
ExplorerSidebarAnimationProvider,
} from "@/contexts/explorer-sidebar-animation-context";
import { usePanelStore } from "@/stores/panel-store";
import { useDaemonRegistry } from "@/contexts/daemon-registry-context";
import { useHosts } from "@/runtime/host-runtime";
import { useSessionStore } from "@/stores/session-store";
import {
useHostRuntimeSession,
@@ -94,7 +94,7 @@ export function AgentReadyScreen({
}) {
const resolvedAgentId = agentId?.trim() || undefined;
const resolvedServerId = serverId?.trim() || undefined;
const { daemons } = useDaemonRegistry();
const daemons = useHosts();
const runtimeServerId = resolvedServerId ?? "";
const {
snapshot: runtimeSnapshot,
@@ -25,7 +25,7 @@ import {
checkoutStatusQueryKey,
} from '@/hooks/use-checkout-status-query'
import { useAllAgentsList } from '@/hooks/use-all-agents-list'
import { useDaemonRegistry } from '@/contexts/daemon-registry-context'
import { useHosts } from '@/runtime/host-runtime'
import { buildBranchComboOptions, normalizeBranchOptionName } from '@/utils/branch-suggestions'
import { shortenPath } from '@/utils/shorten-path'
import { collectAgentWorkingDirectorySuggestions } from '@/utils/agent-working-directory-suggestions'
@@ -138,7 +138,7 @@ function DraftAgentScreenContent({
const { theme } = useUnistyles()
const router = useRouter()
const insets = useSafeAreaInsets()
const { daemons } = useDaemonRegistry()
const daemons = useHosts()
const runtime = getHostRuntimeStore()
const runtimeVersion = useSyncExternalStore(
(onStoreChange) => runtime.subscribeAll(onStoreChange),
+8 -11
View File
@@ -13,7 +13,8 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
import { StyleSheet, UnistylesRuntime, useUnistyles } from "react-native-unistyles";
import { Sun, Moon, Monitor, Globe, Settings, RotateCw, Trash2 } from "lucide-react-native";
import { useAppSettings, type AppSettings } from "@/hooks/use-settings";
import { useDaemonRegistry, type HostProfile, type HostConnection } from "@/contexts/daemon-registry-context";
import type { HostProfile, HostConnection } from "@/types/host-connection";
import { useHosts, useHostMutations } from "@/runtime/host-runtime";
import { formatConnectionStatus, getConnectionStatusTone } from "@/utils/daemons";
import { confirmDialog } from "@/utils/confirm-dialog";
import { MenuHeader } from "@/components/headers/menu-header";
@@ -487,12 +488,8 @@ export default function SettingsScreen() {
const routeServerId = typeof params.serverId === "string" ? params.serverId.trim() : "";
const { settings, isLoading: settingsLoading, updateSettings } = useAppSettings();
const {
daemons,
isLoading: daemonLoading,
updateHost,
removeHost,
removeConnection,
} = useDaemonRegistry();
daemons, renameHost, removeHost, removeConnection,
} = { daemons: useHosts(), ...useHostMutations() };
const [isAddHostMethodVisible, setIsAddHostMethodVisible] = useState(false);
const [isDirectHostVisible, setIsDirectHostVisible] = useState(false);
const [isPasteLinkVisible, setIsPasteLinkVisible] = useState(false);
@@ -503,7 +500,7 @@ export default function SettingsScreen() {
const [isRemovingHost, setIsRemovingHost] = useState(false);
const [editingDaemon, setEditingDaemon] = useState<HostProfile | null>(null);
const [isSavingEdit, setIsSavingEdit] = useState(false);
const isLoading = settingsLoading || daemonLoading;
const isLoading = settingsLoading;
const isMountedRef = useRef(true);
const lastHandledEditHostRef = useRef<string | null>(null);
const isDesktop = Platform.OS === "web";
@@ -615,7 +612,7 @@ export default function SettingsScreen() {
try {
setIsSavingEdit(true);
await updateHost(editingServerId, { label: nextLabel });
await renameHost(editingServerId, nextLabel);
handleCloseEditDaemon();
} catch (error) {
console.error("[Settings] Failed to rename host", error);
@@ -623,7 +620,7 @@ export default function SettingsScreen() {
} finally {
setIsSavingEdit(false);
}
}, [editingServerId, handleCloseEditDaemon, isSavingEdit, updateHost]);
}, [editingServerId, handleCloseEditDaemon, isSavingEdit, renameHost]);
const handleRemoveConnection = useCallback(
async (serverId: string, connectionId: string) => {
@@ -767,7 +764,7 @@ export default function SettingsScreen() {
hostname={pendingNameHostname}
onSkip={() => setPendingNameHost(null)}
onSave={(label) => {
void updateHost(pendingNameHost.serverId, { label }).finally(() => {
void renameHost(pendingNameHost.serverId, label).finally(() => {
setPendingNameHost(null);
});
}}