Complete Zustand migration: fix component access to session APIs

Finalizes the pure Zustand refactor by ensuring all components properly access both session state and imperative methods through useDaemonSession. Moves CLAUDE.md to root and ignores local overrides.

Changes:
- Fix useDaemonSession to return stable combined state + methods object
- Update components to use useDaemonSession instead of direct context
- Fix realtime context to work with session state only
- Move CLAUDE.md to root, ignore CLAUDE.local.md for local config
- Add proper null checks and type safety throughout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2025-12-02 17:42:49 +00:00
co-authored by Claude
parent 473e11d25f
commit 5ddaea7352
12 changed files with 483 additions and 195 deletions
+48 -1
View File
@@ -507,11 +507,13 @@ export function SessionProvider({ children, serverUrl, serverId }: SessionProvid
// WebSocket message handlers - directly update Zustand store
useEffect(() => {
console.log("[Session] Setting up session_state listener for", serverId);
const unsubSessionState = ws.on("session_state", (message) => {
if (message.type !== "session_state") return;
const { agents: agentsList, commands: commandsList } = message.payload;
console.log("[Session] Session state:", agentsList.length, "agents,", commandsList.length, "commands");
console.log("[Session] ✅ Received session_state:", agentsList.length, "agents,", commandsList.length, "commands");
setInitializingAgents(serverId, new Map());
const agents = new Map();
@@ -1581,6 +1583,51 @@ export function SessionProvider({ children, serverUrl, serverId }: SessionProvid
]
);
// Sync imperative methods to Zustand store so useDaemonSession can access them without React Context
// Memoize the methods object to avoid infinite re-renders (object reference must be stable)
const setSessionMethods = useSessionStore((state) => state.setSessionMethods);
const methods = useMemo(() => ({
setVoiceDetectionFlags,
requestGitDiff,
requestDirectoryListing,
requestFilePreview,
navigateExplorerBack,
requestProviderModels,
restartServer,
initializeAgent,
refreshAgent,
cancelAgentRun,
sendAgentMessage,
sendAgentAudio,
deleteAgent,
createAgent,
resumeAgent,
setAgentMode,
respondToPermission,
}), [
setVoiceDetectionFlags,
requestGitDiff,
requestDirectoryListing,
requestFilePreview,
navigateExplorerBack,
requestProviderModels,
restartServer,
initializeAgent,
refreshAgent,
cancelAgentRun,
sendAgentMessage,
sendAgentAudio,
deleteAgent,
createAgent,
resumeAgent,
setAgentMode,
respondToPermission,
]);
useEffect(() => {
setSessionMethods(serverId, methods);
}, [serverId, setSessionMethods, methods]);
return (
<SessionContext.Provider value={value}>
{children}