/**
* IDB Target Cache
*
*
* Caches IDB target information to avoid repeated `idb list-targets` calls.
* Similar to SimulatorCache, tracks:
* - Available targets (devices + simulators)
* - Screen dimensions for coordinate validation
* - Connection status (USB/WiFi for devices)
* - Last used target for auto-detection
* - Usage tracking for intelligent defaults
*
*/
export interface IDBTarget {
udid: string;
name: string;
type: 'device' | 'simulator';
state: 'Booted' | 'Shutdown';
osVersion: string;
architecture: string;
screenDimensions: {
width: number;
height: number;
};
connectionType?: 'usb' | 'wifi';
companionPort?: number;
lastUsed?: number;
successfulOperations: number;
}
/**
* IDB Target Cache Manager
*
* Why: Avoid expensive `idb list-targets` calls on every operation.
* Cache targets for 5 seconds (configurable) to balance performance with state accuracy.
*
* Note: Short TTL is critical because simulator boot state changes frequently during
* development. A 60s TTL caused stale "Shutdown" data when simulators were actually "Booted",
* blocking all IDB operations. 5 seconds provides fast cache while ensuring state accuracy.
*/
declare class IDBTargetCacheManager {
private cache;
/**
* Get target by UDID, refreshing cache if stale
*
* Why: Primary method for accessing target info.
* Auto-refreshes cache if TTL expired.
*
* @param udid - Target UDID
* @returns IDBTarget with full details
* @throws McpError if target not found
*/
getTarget(udid: string): Promise;
/**
* Get last used target for auto-detection
*
* Why: Enable UDID auto-detection for better UX.
* Prefers booted targets, then most recently used.
*
* @returns Last used booted target, or undefined if none
*/
getLastUsedTarget(): Promise;
/**
* Find target by UDID (no error if not found)
*
* Why: Non-throwing version for existence checks.
*
* @param udid - Target UDID
* @returns IDBTarget if found, undefined otherwise
*/
findTargetByUdid(udid: string): Promise;
/**
* List all cached targets
*
* Why: Support idb-targets tool for listing available targets.
*
* @param filters - Optional filters for state, type
* @returns Array of IDBTargets
*/
listTargets(filters?: {
state?: 'Booted' | 'Shutdown';
type?: 'device' | 'simulator';
}): Promise;
/**
* Record successful operation for usage tracking
*
* Why: Track which targets are actively used for intelligent defaults.
*
* @param udid - Target UDID
*/
recordSuccess(udid: string): void;
/**
* Clear cache to force refresh
*
* Why: Support manual cache invalidation for troubleshooting.
*/
clearCache(): void;
/**
* Set cache TTL
*
* Why: Allow runtime configuration of cache duration.
*
* @param ttlMs - Time-to-live in milliseconds
*/
setCacheTTL(ttlMs: number): void;
/**
* Get cache statistics
*
* Why: Support cache-get-stats tool for monitoring.
*
* @returns Cache stats including target count, TTL, last fetch time
*/
getCacheStats(): {
targetCount: number;
ttl: number;
lastFetched: number;
cacheAge: number;
};
/**
* Fetch screen dimensions for a target using idb describe
*
* Why: idb list-targets doesn't include screen_dimensions.
* We need to call idb describe to get this information.
*
* @param udid - Target UDID
* @param target - Target object to update
*/
private fetchScreenDimensions;
/**
* Refresh cache from IDB if stale
*
* Why: Internal method to maintain cache freshness.
* Called automatically by public methods.
*/
private refreshIfStale;
/**
* Force cache refresh from IDB
*
* Why: Fetch latest target list from IDB.
* Parses JSON output and populates cache.
*/
private refreshCache;
}
export declare const IDBTargetCache: IDBTargetCacheManager;
export {};
//# sourceMappingURL=idb-target-cache.d.ts.map