Chrome DevTools for coding agents
feat: Use HeapSnapshotProxy.nodeIndexById (#2193)
Dominik Inführ6bd8c9167803
diff --git a/package-lock.json b/package-lock.jsonindex 4f4c6cdd..0fcb6418 100644--- a/package-lock.json+++ b/package-lock.json@@ -29,7 +29,7 @@"@types/yargs": "^17.0.33","@typescript-eslint/eslint-plugin": "^8.43.0","@typescript-eslint/parser": "^8.43.0",- "chrome-devtools-frontend": "1.0.1641723",+ "chrome-devtools-frontend": "1.0.1642845","core-js": "3.49.0","debug": "4.4.3","eslint": "^9.35.0",@@ -3284,9 +3284,9 @@}},"node_modules/chrome-devtools-frontend": {- "version": "1.0.1641723",- "resolved": "https://registry.npmjs.org/chrome-devtools-frontend/-/chrome-devtools-frontend-1.0.1641723.tgz",- "integrity": "sha512-o3x5thfNuShbfaj3csWDEcOdW7rbTIJtnKjFzsdpkVDvR/osy/gyzceGaDq5XFwM63K6Ah6Il6j3lp2S3IeTYw==",+ "version": "1.0.1642845",+ "resolved": "https://registry.npmjs.org/chrome-devtools-frontend/-/chrome-devtools-frontend-1.0.1642845.tgz",+ "integrity": "sha512-74XZ4L7VFHbwNvOZdLEy1iLBESAf0asei+32VPtLFvdhxjlcrscWyf5tqV3NVWLd7NziJhANwIV8oJSu5IVvAA==","dev": true,"license": "BSD-3-Clause"},diff --git a/package.json b/package.jsonindex f01126e1..f1c69028 100644--- a/package.json+++ b/package.json@@ -63,7 +63,7 @@"@types/yargs": "^17.0.33","@typescript-eslint/eslint-plugin": "^8.43.0","@typescript-eslint/parser": "^8.43.0",- "chrome-devtools-frontend": "1.0.1641723",+ "chrome-devtools-frontend": "1.0.1642845","core-js": "3.49.0","debug": "4.4.3","eslint": "^9.35.0",diff --git a/src/HeapSnapshotManager.ts b/src/HeapSnapshotManager.tsindex 772f431c..035496e9 100644--- a/src/HeapSnapshotManager.ts+++ b/src/HeapSnapshotManager.ts@@ -7,7 +7,6 @@import fsSync from 'node:fs';import path from 'node:path';-import {isNodeLike} from './formatters/HeapSnapshotFormatter.js';import {DevTools} from './third_party/index.js';import {createIdGenerator,@@ -116,36 +115,15 @@ export class HeapSnapshotManager {return await provider.serializeItemsRange(0, Infinity);}- async findNodeIndexById(- filePath: string,- nodeId: number,- ): Promise<number | undefined> {- const snapshot = await this.getSnapshot(filePath);- const aggregates = await this.getAggregates(filePath);- const filter =- new DevTools.HeapSnapshotModel.HeapSnapshotModel.NodeFilter();-- for (const classKey of Object.keys(aggregates)) {- const provider = snapshot.createNodesProviderForClass(classKey, filter);- const range = await provider.serializeItemsRange(0, Infinity);- for (const item of range.items) {- if (isNodeLike(item) && item.id === nodeId) {- return item.nodeIndex;- }- }- }- return undefined;- }-async getRetainers(filePath: string,nodeId: number,): Promise<DevTools.HeapSnapshotModel.HeapSnapshotModel.ItemsRange> {- const nodeIndex = await this.findNodeIndexById(filePath, nodeId);+ const snapshot = await this.getSnapshot(filePath);+ const nodeIndex = await snapshot.nodeIndexForId(nodeId);if (nodeIndex === undefined) {throw new Error(`Node with ID ${nodeId} not found`);}- const snapshot = await this.getSnapshot(filePath);const provider = snapshot.createRetainingEdgesProvider(nodeIndex);return await provider.serializeItemsRange(0, Infinity);}@@ -157,11 +135,11 @@ export class HeapSnapshotManager {maxNodes?: number,maxSiblings?: number,): Promise<DevTools.HeapSnapshotModel.HeapSnapshotModel.RetainingPaths> {- const nodeIndex = await this.findNodeIndexById(filePath, nodeId);+ const snapshot = await this.getSnapshot(filePath);+ const nodeIndex = await snapshot.nodeIndexForId(nodeId);if (nodeIndex === undefined) {throw new Error(`Node with ID ${nodeId} not found`);}- const snapshot = await this.getSnapshot(filePath);return await snapshot.getRetainingPaths(nodeIndex,maxDepth,