(options: {
phase: McpStartupPhase;
shutdownReason: McpShutdownReason | null;
startedAtMs: number;
commandExecutor?: CommandExecutor;
})
| 272 | } |
| 273 | |
| 274 | export async function buildMcpLifecycleSnapshot(options: { |
| 275 | phase: McpStartupPhase; |
| 276 | shutdownReason: McpShutdownReason | null; |
| 277 | startedAtMs: number; |
| 278 | commandExecutor?: CommandExecutor; |
| 279 | }): Promise<McpLifecycleSnapshot> { |
| 280 | const memoryUsage = process.memoryUsage(); |
| 281 | const activitySnapshot = getDaemonActivitySnapshot(); |
| 282 | const peerSample = await sampleMcpPeerProcesses( |
| 283 | options.commandExecutor ?? getDefaultCommandExecutor(), |
| 284 | process.pid, |
| 285 | ); |
| 286 | const simulatorLaunchOsLogSessions = await listActiveSimulatorLaunchOsLogSessions(); |
| 287 | |
| 288 | const snapshotWithoutAnomalies = { |
| 289 | pid: process.pid, |
| 290 | ppid: process.ppid, |
| 291 | orphaned: process.ppid === 1, |
| 292 | phase: options.phase, |
| 293 | shutdownReason: options.shutdownReason, |
| 294 | uptimeMs: Math.max(0, Date.now() - options.startedAtMs), |
| 295 | rssBytes: memoryUsage.rss, |
| 296 | heapUsedBytes: memoryUsage.heapUsed, |
| 297 | watcherRunning: isWatcherRunning(), |
| 298 | watchedPath: getWatchedPath(), |
| 299 | activeOperationCount: activitySnapshot.activeOperationCount, |
| 300 | activeOperationByCategory: activitySnapshot.byCategory, |
| 301 | debuggerSessionCount: getDefaultDebuggerManager().listSessions().length, |
| 302 | simulatorLaunchOsLogSessionCount: simulatorLaunchOsLogSessions.length, |
| 303 | ownedSimulatorLaunchOsLogSessionCount: simulatorLaunchOsLogSessions.filter( |
| 304 | (session) => session.ownedByCurrentProcess, |
| 305 | ).length, |
| 306 | videoCaptureSessionCount: listActiveVideoCaptureSessionIds().length, |
| 307 | swiftPackageProcessCount: activeProcesses.size, |
| 308 | matchingMcpProcessCount: peerSample.count, |
| 309 | matchingMcpPeerSummary: peerSample.peers, |
| 310 | }; |
| 311 | |
| 312 | return { |
| 313 | ...snapshotWithoutAnomalies, |
| 314 | anomalies: classifyMcpLifecycleAnomalies(snapshotWithoutAnomalies), |
| 315 | }; |
| 316 | } |
| 317 | |
| 318 | export function createMcpLifecycleCoordinator( |
| 319 | options: McpLifecycleCoordinatorOptions, |
no test coverage detected