/** * useUser (API §12.2) — self as the shell-domain `User` (typed * firstName/lastName/email). The provider PRE-RESOLVES it at boot (`primeUser`), * so `useUser` is synchronous below the provider (API §2). OS-plane absent → throws * descriptively to the nearest boundary; a never-primed shell suspends on first use * (§1.4). FLAG: not yet re-rendered on rename — becomes live via a memory shape. */ import type { UserNode } from '@astrale-os/shell' import { useShell } from '../../session/shell.hook.js' import { loadUser, userCache } from './user.store.js' export function useUser(): UserNode { const shell = useShell() const entry = userCache.get(shell) ?? loadUser(shell) if (entry.status === 'pending') throw entry.promise // OS plane resolved absent at boot — throw to the nearest boundary; do NOT // re-load (the plane is not coming back this session). if (entry.status === 'unavailable') throw entry.error if (entry.status === 'rejected') { // Retryable transient: drop the poisoned cell so an error-boundary retry // re-loads `me()` instead of re-throwing the same failure forever. userCache.delete(shell) throw entry.error } return entry.value }