@memlab/mcp-server 2.3.0 → 2.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/README.md +18 -14
  2. package/bin/.eslintrc.js +26 -0
  3. package/bin/memlab-cli.js +313 -0
  4. package/dist/artifact-classes.d.ts +86 -0
  5. package/dist/artifact-classes.d.ts.map +1 -0
  6. package/dist/artifact-classes.js +261 -0
  7. package/dist/artifact-classes.js.map +1 -0
  8. package/dist/capture-mode.d.ts +60 -0
  9. package/dist/capture-mode.d.ts.map +1 -0
  10. package/dist/capture-mode.js +39 -0
  11. package/dist/capture-mode.js.map +1 -0
  12. package/dist/guardrail.d.ts.map +1 -1
  13. package/dist/guardrail.js +13 -0
  14. package/dist/guardrail.js.map +1 -1
  15. package/dist/heap-state.d.ts +96 -2
  16. package/dist/heap-state.d.ts.map +1 -1
  17. package/dist/heap-state.js +197 -2
  18. package/dist/heap-state.js.map +1 -1
  19. package/dist/index.js +41 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/progress.d.ts +25 -0
  22. package/dist/progress.d.ts.map +1 -0
  23. package/dist/progress.js +46 -0
  24. package/dist/progress.js.map +1 -0
  25. package/dist/result-handles.d.ts +11 -0
  26. package/dist/result-handles.d.ts.map +1 -0
  27. package/dist/result-handles.js +77 -0
  28. package/dist/result-handles.js.map +1 -0
  29. package/dist/string-index.d.ts +55 -0
  30. package/dist/string-index.d.ts.map +1 -0
  31. package/dist/string-index.js +91 -0
  32. package/dist/string-index.js.map +1 -0
  33. package/dist/tool-registry.d.ts +42 -0
  34. package/dist/tool-registry.d.ts.map +1 -0
  35. package/dist/tool-registry.js +20 -0
  36. package/dist/tool-registry.js.map +1 -0
  37. package/dist/tools/analyze-run.d.ts +12 -0
  38. package/dist/tools/analyze-run.d.ts.map +1 -0
  39. package/dist/tools/analyze-run.js +343 -0
  40. package/dist/tools/analyze-run.js.map +1 -0
  41. package/dist/tools/app-heap.d.ts +12 -0
  42. package/dist/tools/app-heap.d.ts.map +1 -0
  43. package/dist/tools/app-heap.js +140 -0
  44. package/dist/tools/app-heap.js.map +1 -0
  45. package/dist/tools/auto-investigate.d.ts.map +1 -1
  46. package/dist/tools/auto-investigate.js +91 -49
  47. package/dist/tools/auto-investigate.js.map +1 -1
  48. package/dist/tools/batch.d.ts +12 -0
  49. package/dist/tools/batch.d.ts.map +1 -0
  50. package/dist/tools/batch.js +168 -0
  51. package/dist/tools/batch.js.map +1 -0
  52. package/dist/tools/cache-analysis.d.ts.map +1 -1
  53. package/dist/tools/cache-analysis.js +156 -5
  54. package/dist/tools/cache-analysis.js.map +1 -1
  55. package/dist/tools/class-histogram.d.ts.map +1 -1
  56. package/dist/tools/class-histogram.js +14 -3
  57. package/dist/tools/class-histogram.js.map +1 -1
  58. package/dist/tools/collection-trend.d.ts +55 -0
  59. package/dist/tools/collection-trend.d.ts.map +1 -0
  60. package/dist/tools/collection-trend.js +315 -0
  61. package/dist/tools/collection-trend.js.map +1 -0
  62. package/dist/tools/detached-dom.d.ts +2 -0
  63. package/dist/tools/detached-dom.d.ts.map +1 -1
  64. package/dist/tools/detached-dom.js +291 -20
  65. package/dist/tools/detached-dom.js.map +1 -1
  66. package/dist/tools/dev-artifacts.d.ts +62 -6
  67. package/dist/tools/dev-artifacts.d.ts.map +1 -1
  68. package/dist/tools/dev-artifacts.js +466 -23
  69. package/dist/tools/dev-artifacts.js.map +1 -1
  70. package/dist/tools/diff-snapshots.d.ts.map +1 -1
  71. package/dist/tools/diff-snapshots.js +101 -44
  72. package/dist/tools/diff-snapshots.js.map +1 -1
  73. package/dist/tools/dominator-attribution.d.ts +12 -0
  74. package/dist/tools/dominator-attribution.d.ts.map +1 -0
  75. package/dist/tools/dominator-attribution.js +189 -0
  76. package/dist/tools/dominator-attribution.js.map +1 -0
  77. package/dist/tools/dominator-chain.d.ts +12 -0
  78. package/dist/tools/dominator-chain.d.ts.map +1 -0
  79. package/dist/tools/dominator-chain.js +92 -0
  80. package/dist/tools/dominator-chain.js.map +1 -0
  81. package/dist/tools/duplicate-objects.d.ts +12 -0
  82. package/dist/tools/duplicate-objects.d.ts.map +1 -0
  83. package/dist/tools/duplicate-objects.js +172 -0
  84. package/dist/tools/duplicate-objects.js.map +1 -0
  85. package/dist/tools/duplicated-strings.d.ts.map +1 -1
  86. package/dist/tools/duplicated-strings.js +46 -38
  87. package/dist/tools/duplicated-strings.js.map +1 -1
  88. package/dist/tools/eval.d.ts +1 -0
  89. package/dist/tools/eval.d.ts.map +1 -1
  90. package/dist/tools/eval.js +787 -30
  91. package/dist/tools/eval.js.map +1 -1
  92. package/dist/tools/explain-delta.d.ts +12 -0
  93. package/dist/tools/explain-delta.d.ts.map +1 -0
  94. package/dist/tools/explain-delta.js +170 -0
  95. package/dist/tools/explain-delta.js.map +1 -0
  96. package/dist/tools/find-nodes-by-class.d.ts.map +1 -1
  97. package/dist/tools/find-nodes-by-class.js +112 -13
  98. package/dist/tools/find-nodes-by-class.js.map +1 -1
  99. package/dist/tools/finding-index.d.ts +22 -0
  100. package/dist/tools/finding-index.d.ts.map +1 -0
  101. package/dist/tools/finding-index.js +247 -0
  102. package/dist/tools/finding-index.js.map +1 -0
  103. package/dist/tools/for-each.d.ts.map +1 -1
  104. package/dist/tools/for-each.js +15 -3
  105. package/dist/tools/for-each.js.map +1 -1
  106. package/dist/tools/get-references.d.ts.map +1 -1
  107. package/dist/tools/get-references.js +35 -6
  108. package/dist/tools/get-references.js.map +1 -1
  109. package/dist/tools/get-referrers.d.ts.map +1 -1
  110. package/dist/tools/get-referrers.js +52 -6
  111. package/dist/tools/get-referrers.js.map +1 -1
  112. package/dist/tools/hunt-report.d.ts +12 -0
  113. package/dist/tools/hunt-report.d.ts.map +1 -0
  114. package/dist/tools/hunt-report.js +186 -0
  115. package/dist/tools/hunt-report.js.map +1 -0
  116. package/dist/tools/hypothesis.d.ts +12 -0
  117. package/dist/tools/hypothesis.d.ts.map +1 -0
  118. package/dist/tools/hypothesis.js +221 -0
  119. package/dist/tools/hypothesis.js.map +1 -0
  120. package/dist/tools/intern-opportunities.d.ts.map +1 -1
  121. package/dist/tools/intern-opportunities.js +721 -75
  122. package/dist/tools/intern-opportunities.js.map +1 -1
  123. package/dist/tools/ladder.d.ts +33 -0
  124. package/dist/tools/ladder.d.ts.map +1 -0
  125. package/dist/tools/ladder.js +266 -0
  126. package/dist/tools/ladder.js.map +1 -0
  127. package/dist/tools/largest-objects.d.ts.map +1 -1
  128. package/dist/tools/largest-objects.js +43 -16
  129. package/dist/tools/largest-objects.js.map +1 -1
  130. package/dist/tools/leak-report.d.ts +12 -0
  131. package/dist/tools/leak-report.d.ts.map +1 -0
  132. package/dist/tools/leak-report.js +256 -0
  133. package/dist/tools/leak-report.js.map +1 -0
  134. package/dist/tools/load-snapshot.d.ts +78 -0
  135. package/dist/tools/load-snapshot.d.ts.map +1 -1
  136. package/dist/tools/load-snapshot.js +519 -29
  137. package/dist/tools/load-snapshot.js.map +1 -1
  138. package/dist/tools/map-entries.d.ts +12 -0
  139. package/dist/tools/map-entries.d.ts.map +1 -0
  140. package/dist/tools/map-entries.js +139 -0
  141. package/dist/tools/map-entries.js.map +1 -0
  142. package/dist/tools/match-object.d.ts +12 -0
  143. package/dist/tools/match-object.d.ts.map +1 -0
  144. package/dist/tools/match-object.js +165 -0
  145. package/dist/tools/match-object.js.map +1 -0
  146. package/dist/tools/object-shape.d.ts.map +1 -1
  147. package/dist/tools/object-shape.js +92 -30
  148. package/dist/tools/object-shape.js.map +1 -1
  149. package/dist/tools/population-diff.d.ts +57 -0
  150. package/dist/tools/population-diff.d.ts.map +1 -0
  151. package/dist/tools/population-diff.js +338 -0
  152. package/dist/tools/population-diff.js.map +1 -0
  153. package/dist/tools/quick-diagnosis.d.ts.map +1 -1
  154. package/dist/tools/quick-diagnosis.js +12 -4
  155. package/dist/tools/quick-diagnosis.js.map +1 -1
  156. package/dist/tools/retainer-layers.d.ts +23 -0
  157. package/dist/tools/retainer-layers.d.ts.map +1 -0
  158. package/dist/tools/retainer-layers.js +179 -0
  159. package/dist/tools/retainer-layers.js.map +1 -0
  160. package/dist/tools/retainer-summary.d.ts +1 -0
  161. package/dist/tools/retainer-summary.d.ts.map +1 -1
  162. package/dist/tools/retainer-summary.js +128 -32
  163. package/dist/tools/retainer-summary.js.map +1 -1
  164. package/dist/tools/retainer-trace.d.ts.map +1 -1
  165. package/dist/tools/retainer-trace.js +105 -25
  166. package/dist/tools/retainer-trace.js.map +1 -1
  167. package/dist/tools/search-nodes.d.ts.map +1 -1
  168. package/dist/tools/search-nodes.js +5 -1
  169. package/dist/tools/search-nodes.js.map +1 -1
  170. package/dist/tools/search-strings.d.ts.map +1 -1
  171. package/dist/tools/search-strings.js +53 -7
  172. package/dist/tools/search-strings.js.map +1 -1
  173. package/dist/tools/sequence-analysis.d.ts +49 -0
  174. package/dist/tools/sequence-analysis.d.ts.map +1 -1
  175. package/dist/tools/sequence-analysis.js +268 -78
  176. package/dist/tools/sequence-analysis.js.map +1 -1
  177. package/dist/tools/shape-histogram.d.ts.map +1 -1
  178. package/dist/tools/shape-histogram.js +9 -2
  179. package/dist/tools/shape-histogram.js.map +1 -1
  180. package/dist/tools/sliced-strings.d.ts.map +1 -1
  181. package/dist/tools/sliced-strings.js +22 -4
  182. package/dist/tools/sliced-strings.js.map +1 -1
  183. package/dist/tools/snapshot-header.d.ts +28 -0
  184. package/dist/tools/snapshot-header.d.ts.map +1 -0
  185. package/dist/tools/snapshot-header.js +111 -0
  186. package/dist/tools/snapshot-header.js.map +1 -0
  187. package/dist/tools/string-patterns.d.ts.map +1 -1
  188. package/dist/tools/string-patterns.js +5 -4
  189. package/dist/tools/string-patterns.js.map +1 -1
  190. package/dist/tools/tools-index.d.ts +12 -0
  191. package/dist/tools/tools-index.d.ts.map +1 -0
  192. package/dist/tools/tools-index.js +342 -0
  193. package/dist/tools/tools-index.js.map +1 -0
  194. package/dist/tools/verify-fix.d.ts +23 -0
  195. package/dist/tools/verify-fix.d.ts.map +1 -0
  196. package/dist/tools/verify-fix.js +211 -0
  197. package/dist/tools/verify-fix.js.map +1 -0
  198. package/dist/tools/weakmap-entries.d.ts.map +1 -1
  199. package/dist/tools/weakmap-entries.js +6 -1
  200. package/dist/tools/weakmap-entries.js.map +1 -1
  201. package/dist/utils.d.ts +204 -1
  202. package/dist/utils.d.ts.map +1 -1
  203. package/dist/utils.js +478 -8
  204. package/dist/utils.js.map +1 -1
  205. package/package.json +5 -4
@@ -0,0 +1,256 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall memory_lab
9
+ */
10
+ import { z } from 'zod';
11
+ import memlabHeapAnalysis from '@memlab/heap-analysis';
12
+ const { getFullHeapFromFile } = memlabHeapAnalysis;
13
+ import { formatBytes, formatNumber, markdownTable, errorResult, toolResult, } from '../utils.js';
14
+ import { artifactLabel } from '../artifact-classes.js';
15
+ import { computeSequenceTrends, normalizeClassName, } from './sequence-analysis.js';
16
+ import { collectDevRoots, computeReachableWithoutDevRoots, } from './dev-artifacts.js';
17
+ import { getFirstNonFrameworkRetainer } from './detached-dom.js';
18
+ // Nodes kept per candidate class for the retainer sample. Small on purpose: the
19
+ // question is "what shape of thing holds these", and a handful of instances
20
+ // answers it — walking thousands would cost more than the trend pass itself.
21
+ const MAX_SAMPLES_PER_CLASS = 8;
22
+ const RETAINER_SAMPLES = 3;
23
+ // A class whose instances are overwhelmingly dev-root-retained is a measurement
24
+ // artifact in production terms, whatever its growth curve looks like. Matches
25
+ // the majority-not-any threshold intern_opportunities uses, for the same reason:
26
+ // a class can legitimately mix a few console-held instances with real data.
27
+ const DEV_ONLY_SHARE = 0.8;
28
+ // Deliberately NOT a sum of retainedSize across the class: retained sizes
29
+ // overlap wherever instances nest, so summing them reports figures larger than
30
+ // the heap (measured: 5.9 GB of `Object` in a 200 MB heap). Net self-size delta
31
+ // across the ladder is additive and is the growth the report is about anyway.
32
+ function displayName(row) {
33
+ return row.name.length > 0 ? row.name : `(unnamed ${row.type})`;
34
+ }
35
+ function topRetainerLabel(ev) {
36
+ const counts = new Map();
37
+ for (const node of ev.samples.slice(0, RETAINER_SAMPLES)) {
38
+ const label = getFirstNonFrameworkRetainer(node);
39
+ counts.set(label, (counts.get(label) ?? 0) + 1);
40
+ }
41
+ let best = '(unknown)';
42
+ let bestCount = 0;
43
+ for (const [label, c] of counts) {
44
+ if (c > bestCount) {
45
+ best = label;
46
+ bestCount = c;
47
+ }
48
+ }
49
+ return best;
50
+ }
51
+ export function registerLeakReport(server) {
52
+ server.tool('memlab_leak_report', 'One-call leak triage across an ORDERED ladder of >=2 heap snapshots: runs the growth-trend pass, then gathers per-class EVIDENCE from the final snapshot and returns a single table — class, per-rung counts, Δ and Δ/cycle, how much of it is dev/automation-retained, the dominant retainer, and a verdict hint. ' +
53
+ 'Exists because the trend pass alone cannot tell a leak from an artifact: every hunt then ran memlab_dev_artifacts and a retainer trace by hand on each grower and joined the three outputs mentally, which is the step that gets skipped right before something is reported as a production leak. Composes memlab_sequence_analysis with memlab_dev_artifacts and a retainer sample; costs one extra snapshot load (the last rung) on top of the ladder pass. ' +
54
+ 'The verdict column is a HINT, not a conclusion — confirm a candidate with memlab_retainer_trace on the example node before calling it a leak. Paths may be local, manifold:// URLs, or bare filenames.', {
55
+ paths: z
56
+ .array(z.string())
57
+ .min(1)
58
+ .describe('Ordered list of >=2 snapshot paths (oldest first): local absolute paths, manifold:// URLs, or bare snapshot filenames. A single ["ladder:<name>"] entry expands to a ladder saved with memlab_ladder.'),
59
+ cycles: z
60
+ .number()
61
+ .optional()
62
+ .describe('Number of interaction cycles driven between the FIRST and LAST snapshot. When provided, a "Δ/cycle" column is reported — a per-cycle rate is what says whether growth scales with interaction, which a total cannot.'),
63
+ limit: z
64
+ .number()
65
+ .optional()
66
+ .default(10)
67
+ .describe('Maximum number of growing classes to gather evidence for (default 10).'),
68
+ min_growth_count: z
69
+ .number()
70
+ .optional()
71
+ .default(50)
72
+ .describe('Only consider classes whose net instance-count growth is at least this (default 50).'),
73
+ monotonic_only: z
74
+ .boolean()
75
+ .optional()
76
+ .default(false)
77
+ .describe('Only consider classes that grew at EVERY step (default false: grew-net classes are included and flagged as noisy).'),
78
+ include_artifacts: z
79
+ .boolean()
80
+ .optional()
81
+ .default(false)
82
+ .describe('Include classes that are known measurement artifacts (CDP inspector retention, V8 JIT warmup, Blink a11y caches, captured Error stacks). Default false: they are counted in a one-line summary instead of consuming evidence slots, since none of them is an app leak.'),
83
+ max_file_size_mb: z
84
+ .number()
85
+ .optional()
86
+ .describe('Per-file size ceiling in MB, matching memlab_load_snapshot / memlab_sequence_analysis defaults. Snapshots are loaded one at a time and dropped before the next.'),
87
+ }, async ({ paths, cycles, limit, min_growth_count, monotonic_only, include_artifacts, max_file_size_mb, }) => {
88
+ try {
89
+ const { steps, rows } = await computeSequenceTrends(paths, {
90
+ minGrowthCount: min_growth_count,
91
+ monotonicOnly: monotonic_only,
92
+ maxFileSizeMB: max_file_size_mb,
93
+ toolName: 'memlab_leak_report',
94
+ });
95
+ const n = steps.length;
96
+ const artifactRows = rows.filter(r => r.artifact != null);
97
+ const candidates = (include_artifacts ? rows : rows.filter(r => r.artifact == null)).slice(0, limit);
98
+ const heapNet = steps[n - 1].totalSize - steps[0].totalSize;
99
+ const lines = [
100
+ `## Leak report (${n} snapshots)`,
101
+ '',
102
+ `Heap self-size ${heapNet >= 0 ? 'grew' : 'shrank'} by ${formatBytes(Math.abs(heapNet))} across the ladder (${formatNumber(steps[0].nodeCount)} → ${formatNumber(steps[n - 1].nodeCount)} nodes).`,
103
+ '',
104
+ ];
105
+ if (n === 2) {
106
+ lines.push('> ⚠️ **Only 2 snapshots: "↑ every step" is monotonic by construction** and cannot separate a real trend from a single GC-band sample. Capture at least a third rung before treating anything here as a leak.', '');
107
+ }
108
+ if (candidates.length === 0) {
109
+ lines.push(`No non-artifact class grew by >= ${formatNumber(min_growth_count)} instances across the ladder — no unbounded-growth signal to report.`);
110
+ if (artifactRows.length > 0) {
111
+ lines.push('', `> 🧹 ${formatNumber(artifactRows.length)} growing class(es) were known measurement artifacts (pass \`include_artifacts: true\` to see them).`);
112
+ }
113
+ return toolResult(lines.join('\n'));
114
+ }
115
+ // Evidence pass. The trend loop drops each graph before loading the
116
+ // next, so the final rung is re-opened here — one extra load, and the
117
+ // only way to ask retention questions about the classes the trend pass
118
+ // just identified.
119
+ const snapshot = await getFullHeapFromFile(steps[n - 1].localPath);
120
+ const devRoots = collectDevRoots(snapshot);
121
+ const reached = devRoots.byId.size > 0
122
+ ? computeReachableWithoutDevRoots(snapshot, devRoots)
123
+ : null;
124
+ const evidence = new Map();
125
+ for (const c of candidates) {
126
+ evidence.set(c.key, {
127
+ total: 0,
128
+ devOnly: 0,
129
+ samples: [],
130
+ example: null,
131
+ exampleRetained: -1,
132
+ anyExample: null,
133
+ });
134
+ }
135
+ snapshot.nodes.forEach(node => {
136
+ if (node.id <= 3)
137
+ return;
138
+ // Must key exactly as buildHistogram does, normalization included, or
139
+ // per-instance Context/scope classes never match their trend row.
140
+ const ev = evidence.get(`${node.type}::${normalizeClassName(node.name)}`);
141
+ if (!ev)
142
+ return;
143
+ ev.total++;
144
+ if (reached != null && reached[node.nodeIndex] === 0)
145
+ ev.devOnly++;
146
+ if (ev.anyExample == null)
147
+ ev.anyExample = node;
148
+ if (!node.hasPathEdge)
149
+ return;
150
+ if (ev.samples.length < MAX_SAMPLES_PER_CLASS)
151
+ ev.samples.push(node);
152
+ if (node.retainedSize > ev.exampleRetained) {
153
+ ev.exampleRetained = node.retainedSize;
154
+ ev.example = node;
155
+ }
156
+ });
157
+ // The biggest traceable instance is the most informative one to walk, so
158
+ // put it at the head of every retainer sample.
159
+ for (const ev of evidence.values()) {
160
+ if (ev.example != null) {
161
+ ev.samples = [
162
+ ev.example,
163
+ ...ev.samples.filter(s => s.id !== ev.example.id),
164
+ ];
165
+ }
166
+ }
167
+ const perCycle = cycles != null && cycles > 0;
168
+ const showDevOnly = reached != null;
169
+ const headers = [
170
+ 'Class',
171
+ 'Type',
172
+ ...steps.map((_, i) => `#${i + 1}`),
173
+ 'Δ count',
174
+ ...(perCycle ? ['Δ/cycle'] : []),
175
+ 'Δ size',
176
+ ...(showDevOnly ? ['Dev-only'] : []),
177
+ 'Top retainer',
178
+ 'Verdict hint',
179
+ ];
180
+ const rightCols = new Set();
181
+ for (let i = 2; i < headers.length - 2; i++)
182
+ rightCols.add(i);
183
+ let leakCandidates = 0;
184
+ let devOnlyClasses = 0;
185
+ const tableRows = candidates.map(r => {
186
+ const ev = evidence.get(r.key);
187
+ const devShare = ev.total > 0 ? ev.devOnly / ev.total : 0;
188
+ const isDevOnly = showDevOnly && devShare >= DEV_ONLY_SHARE;
189
+ if (isDevOnly)
190
+ devOnlyClasses++;
191
+ let verdict;
192
+ if (r.artifact != null) {
193
+ verdict = artifactLabel(r.artifact);
194
+ }
195
+ else if (isDevOnly) {
196
+ verdict = '🛠 dev/automation-retained (not production)';
197
+ }
198
+ else if (r.trend === 'monotonic-up') {
199
+ verdict = '↑ every step — LEAK candidate';
200
+ leakCandidates++;
201
+ }
202
+ else {
203
+ verdict = 'grew net (noisy)';
204
+ }
205
+ const label = displayName(r);
206
+ return [
207
+ label.length > 34 ? label.slice(0, 31) + '…' : label,
208
+ r.type,
209
+ ...r.counts.map(c => formatNumber(c)),
210
+ `+${formatNumber(r.netCount)}`,
211
+ ...(perCycle ? [(r.netCount / cycles).toFixed(2)] : []),
212
+ `${r.netSize >= 0 ? '+' : ''}${formatBytes(r.netSize)}`,
213
+ ...(showDevOnly
214
+ ? [
215
+ ev.total === 0
216
+ ? '—'
217
+ : ev.devOnly === 0
218
+ ? '—'
219
+ : `${(devShare * 100).toFixed(0)}%`,
220
+ ]
221
+ : []),
222
+ (label => (label.length > 44 ? label.slice(0, 41) + '…' : label))(topRetainerLabel(ev)),
223
+ verdict,
224
+ ];
225
+ });
226
+ lines.push(markdownTable(headers, tableRows, rightCols));
227
+ lines.push('', `**${formatNumber(leakCandidates)} leak candidate(s)** of ${formatNumber(candidates.length)} growing class(es) examined` +
228
+ (devOnlyClasses > 0
229
+ ? `; ${formatNumber(devOnlyClasses)} ruled out as dev/automation-retained`
230
+ : '') +
231
+ (artifactRows.length > 0 && !include_artifacts
232
+ ? `; ${formatNumber(artifactRows.length)} known measurement artifact(s) not shown (\`include_artifacts: true\`)`
233
+ : '') +
234
+ '.');
235
+ if (!showDevOnly) {
236
+ lines.push('', '_No dev/automation roots were found in the final snapshot, so the dev-only column is omitted — nothing here is being attributed to the inspector._');
237
+ }
238
+ // Point at the single next call for the strongest candidate rather than
239
+ // a menu: the failure mode this tool exists to fix is a plausible
240
+ // grower being reported without anyone tracing it.
241
+ const strongest = candidates.find(r => r.artifact == null &&
242
+ r.trend === 'monotonic-up' &&
243
+ evidence.get(r.key)?.example != null);
244
+ if (strongest) {
245
+ const ev = evidence.get(strongest.key);
246
+ const example = ev.example;
247
+ lines.push('', `**Next:** confirm the top candidate before reporting it — \`memlab_retainer_trace({node_id: ${example.id}})\` on the largest traceable \`${displayName(strongest)}\` instance in the final rung, then \`memlab_dominator_chain\` on whatever owns it. Counts alone cannot distinguish a leak from a cache that grew and will be evicted.`);
248
+ }
249
+ return toolResult(lines.join('\n'));
250
+ }
251
+ catch (err) {
252
+ return errorResult(err);
253
+ }
254
+ });
255
+ }
256
+ //# sourceMappingURL=leak-report.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leak-report.js","sourceRoot":"","sources":["../../src/tools/leak-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,kBAAkB,MAAM,uBAAuB,CAAC;AACvD,MAAM,EAAC,mBAAmB,EAAC,GAAG,kBAAkB,CAAC;AACjD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,aAAa,EACb,WAAW,EAC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B,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,IAAI,IAAI,CACvC,CAAC;YACF,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAa,CAAC;gBACnD,MAAM,OAAO,GAAG,EAAE,CAAC,OAAoB,CAAC;gBACxC,KAAK,CAAC,IAAI,CACR,EAAE,EACF,+FAA+F,OAAO,CAAC,EAAE,mCAAmC,WAAW,CAAC,SAAS,CAAC,wKAAwK,CAC3U,CAAC;YACJ,CAAC;YAED,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -9,6 +9,83 @@
9
9
  */
10
10
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
11
11
  export declare const DEFAULT_MANIFOLD_BUCKET = "nest_server_nodejs_heap_snapshots";
12
+ export declare const LOCAL_FILE_SIZE_LIMIT_MB = 900;
13
+ export declare const MANIFOLD_FETCH_SIZE_LIMIT_MB = 2100;
14
+ export declare const DEFAULT_MAX_NODES = 12000000;
15
+ export declare const DEFAULT_MAX_EDGES = 24000000;
16
+ export declare const WARN_NODE_COUNT = 2000000;
17
+ export declare const NODES_PER_HEAP_MB = 1700;
18
+ export declare const EDGES_PER_HEAP_MB = 6800;
19
+ export declare const LOAD_BYTES_PER_NODE = 200;
20
+ export declare const LOAD_BYTES_PER_EDGE = 40;
21
+ export declare const HEADROOM_SAFETY_FRACTION = 0.8;
22
+ /**
23
+ * Projected additional heap (MB) a full load of this graph will occupy.
24
+ * Light loads skip the dominator/retained-size arrays; the parsed graph still
25
+ * dominates, so the discount is modest and intentionally conservative.
26
+ */
27
+ export declare function estimateLoadHeapMB(counts: {
28
+ nodeCount: number;
29
+ edgeCount: number;
30
+ }, light: boolean): number;
31
+ /**
32
+ * Old-space headroom (MB) left for a new load: the configured limit minus what
33
+ * is already committed. Returns null when the limit can't be read, in which case
34
+ * the caller skips the guard rather than guessing.
35
+ */
36
+ export declare function getHeapHeadroomMB(): number | null;
37
+ /**
38
+ * Configured V8 old-space limit in MB (reflects --max-old-space-size). Returns 0
39
+ * when it can't be read, so callers fall back to the fixed floors.
40
+ */
41
+ export declare function getOldSpaceLimitMB(): number;
42
+ /**
43
+ * Default node/edge load ceilings, auto-scaled from the configured old-space
44
+ * limit and floored at the historical fixed defaults so the ceiling never
45
+ * regresses below what was previously safe. `heapLimitMB` is 0 when the limit
46
+ * couldn't be read (ceilings then equal the fixed floors).
47
+ */
48
+ export declare function computeDefaultCeilings(): {
49
+ maxNodes: number;
50
+ maxEdges: number;
51
+ heapLimitMB: number;
52
+ };
53
+ /**
54
+ * Cheaply read `node_count` / `edge_count` from a .heapsnapshot header without
55
+ * parsing the whole file. The V8 format begins with
56
+ * `{"snapshot":{"meta":{…},"node_count":N,"edge_count":M,…},…}`, so both counts
57
+ * sit within the first few KB. Reads a bounded prefix and regex-extracts them;
58
+ * returns null when they aren't found in the prefix (caller then skips the count
59
+ * guard rather than failing the load).
60
+ */
61
+ export declare function peekSnapshotCounts(localPath: string): {
62
+ nodeCount: number;
63
+ edgeCount: number;
64
+ } | null;
65
+ /**
66
+ * Estimate the largest same-app capture (in MB) that would fit under the load
67
+ * ceiling, from THIS snapshot's own node/edge density. Server captures of one app
68
+ * have a roughly stable nodes-per-MB and edges-per-MB, so once a capture is
69
+ * refused for exceeding the ceiling, `ceiling ÷ density` tells the reader what
70
+ * file size to look for instead — turning the manual "hit ceiling → compute
71
+ * density by hand → re-query Scuba for a smaller file" loop into one number
72
+ * (sweep feedback round 7 §2: the guess-and-retry loop was the dominant friction).
73
+ * Edge-density usually binds first on edge-dense Nest heaps, so we take the min of
74
+ * the node-bound and edge-bound estimates. Returns null when it can't be computed.
75
+ */
76
+ export declare function estimateMaxLoadableMB(counts: {
77
+ nodeCount: number;
78
+ edgeCount: number;
79
+ }, fileSizeMB: number, ceilings: {
80
+ maxNodes: number;
81
+ maxEdges: number;
82
+ }): number | null;
83
+ /**
84
+ * Resolve the effective max-file-size limit (MB). An explicit caller value always
85
+ * wins; otherwise default by source — Manifold-fetched server snapshots get the
86
+ * higher ceiling, local files keep the tighter guard.
87
+ */
88
+ export declare function resolveMaxFileSizeMB(explicit: number | undefined, fetchedFromManifold: boolean): number;
12
89
  /**
13
90
  * Resolve a `file_path` that may be a local path, a `manifold://bucket/key`
14
91
  * URL, or a bare snapshot filename to a local path, fetching from Manifold
@@ -18,5 +95,6 @@ export declare function resolveSnapshotPath(filePath: string): {
18
95
  localPath: string;
19
96
  fetchedFrom: string | null;
20
97
  };
98
+ export declare function extractCaptureTime(fileName: string): Date | null;
21
99
  export declare function registerLoadSnapshot(server: McpServer): void;
22
100
  //# sourceMappingURL=load-snapshot.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"load-snapshot.d.ts","sourceRoot":"","sources":["../../src/tools/load-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AA0BvE,eAAO,MAAM,uBAAuB,sCAAsC,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACrD,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAoCA;AAmID,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA+M5D"}
1
+ {"version":3,"file":"load-snapshot.d.ts","sourceRoot":"","sources":["../../src/tools/load-snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;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