A tool for parsing traffic on the jetstream and applying a moderation workstream based on regexp based rules

fix(auth): convert isLoggedIn to lazy initialization

Change isLoggedIn from eager evaluation at module load time to lazy
initialization. Authentication now only starts when isLoggedIn is
first awaited, preventing race conditions during test setup or when
the module is imported before the application is ready.

The implementation uses a thenable object for backward compatibility,
allowing existing `await isLoggedIn` patterns to continue working.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Changed files
+18 -1
src
+18 -1
src/agent.ts
··· 170 170 } 171 171 172 172 export const login = authenticateWithRetry; 173 - export const isLoggedIn = authenticateWithRetry().then(() => true); 173 + 174 + // Lazy getter for isLoggedIn - authentication only starts when first accessed 175 + let _isLoggedIn: Promise<boolean> | null = null; 176 + 177 + export function getIsLoggedIn(): Promise<boolean> { 178 + if (!_isLoggedIn) { 179 + _isLoggedIn = authenticateWithRetry().then(() => true); 180 + } 181 + return _isLoggedIn; 182 + } 183 + 184 + // For backward compatibility - callers can still use `await isLoggedIn` 185 + // but authentication is now lazy instead of eager 186 + export const isLoggedIn = { 187 + then<T>(onFulfilled: (value: boolean) => T | PromiseLike<T>): Promise<T> { 188 + return getIsLoggedIn().then(onFulfilled); 189 + }, 190 + };