memorydetective 1.0.1 → 1.1.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.
- package/CHANGELOG.md +25 -1
- package/LICENSE +201 -21
- package/NOTICE +19 -0
- package/README.md +14 -10
- package/dist/cli.js +49 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/parsers/shortenClassName.d.ts +45 -0
- package/dist/parsers/shortenClassName.js +155 -0
- package/dist/parsers/shortenClassName.js.map +1 -0
- package/dist/tools/analyzeMemgraph.d.ts +11 -2
- package/dist/tools/analyzeMemgraph.js +37 -9
- package/dist/tools/analyzeMemgraph.js.map +1 -1
- package/dist/tools/findCycles.d.ts +6 -2
- package/dist/tools/findCycles.js +11 -6
- package/dist/tools/findCycles.js.map +1 -1
- package/dist/tools/reachableFromCycle.d.ts +61 -0
- package/dist/tools/reachableFromCycle.js +116 -0
- package/dist/tools/reachableFromCycle.js.map +1 -0
- package/dist/tools/renderCycleGraph.d.ts +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,29 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.1.0] — 2026-05-01
|
|
10
|
+
|
|
11
|
+
Response-size + cycle-scoped queries + license switch + first-run engagement.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **`reachableFromCycle` tool** — cycle-scoped reachability + per-class counting. Pick a cycle by `cycleIndex` or `rootClassName` substring, get instance counts of every class reachable from that cycle root. Distinguishes the actual culprit (the cycle root) from its retained dependencies. API shape inspired by Meta's `memlab` predicate-based queries. Tool count: 19 → 20.
|
|
16
|
+
- **`verbosity` parameter** on `analyzeMemgraph`, `findCycles`, and `reachableFromCycle`. Three levels: `compact` (default — drops module prefixes, collapses nested SwiftUI `ModifiedContent` into `+N modifiers`, truncates deep generics with a hash placeholder), `normal` (lighter shortening, depth preserved), `full` (Swift demangled names verbatim).
|
|
17
|
+
- **`maxClassesInChain` parameter** on `analyzeMemgraph` (default 10). Caps the per-cycle `classesInChain` array to the top N unique classes ranked by occurrence count, with app-level types prioritized over SwiftUI internals. The full unique-class total is reported in a new `classesInChainTotal` field for context.
|
|
18
|
+
- **Class-name shortener** (`src/parsers/shortenClassName.ts`) — three layers (drop modules, collapse `ModifiedContent` chains, truncate deep generics) with deterministic hash placeholders so the same nested type produces the same short code across runs (useful for diffing two memgraphs).
|
|
19
|
+
- **First-run CLI banner** — first time `memorydetective` runs in non-JSON mode on a machine, prints a one-time message pointing at the GitHub repo, `USAGE.md`, and the sponsor link. Marker stored at `~/.config/memorydetective/seen` so it never re-prints.
|
|
20
|
+
- **Help / output footers** — `--help` and `analyze`/`classify` non-JSON output append a discreet `# ⭐ github.com/carloshpdoc/memorydetective` line. JSON output is untouched (won't break pipes / CI).
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **License: MIT → Apache 2.0.** Permissions are unchanged for users (commercial use, modification, distribution all allowed). Apache 2.0 adds an explicit patent grant + a `NOTICE` file mechanism; the `NOTICE` file ships in the npm tarball and surfaces project attribution in downstream "About" / acknowledgements screens.
|
|
25
|
+
- `analyzeMemgraph` default response is now ~80% smaller for SwiftUI-heavy memgraphs (the per-cycle `classesInChain` no longer floods with hundreds of demangled SwiftUI generics; class names per node compress from 1000+ chars to ~200). Full-fidelity output is still available via `verbosity: "full"`.
|
|
26
|
+
- README: license badge updated to Apache 2.0; tool count updated 19 → 20.
|
|
27
|
+
|
|
28
|
+
### Notes
|
|
29
|
+
|
|
30
|
+
- No breaking changes — all new parameters have sensible defaults. Old callers continue to work; they just receive smaller, more readable responses.
|
|
31
|
+
|
|
9
32
|
## [1.0.1] — 2026-05-01
|
|
10
33
|
|
|
11
34
|
### Added
|
|
@@ -74,6 +97,7 @@ When called with no arguments it starts the MCP server over stdio.
|
|
|
74
97
|
- **`captureMemgraph`** does not work on physical iOS devices — `leaks(1)` only attaches to processes on the local Mac (which includes iOS simulators). Memory Graph capture from a physical device still requires Xcode.
|
|
75
98
|
- **`detectLeaksInXCUITest`** is flagged experimental: orchestration logic is implemented but not yet validated against a wide set of production XCUITest runs.
|
|
76
99
|
|
|
77
|
-
[Unreleased]: https://github.com/carloshpdoc/memorydetective/compare/v1.0
|
|
100
|
+
[Unreleased]: https://github.com/carloshpdoc/memorydetective/compare/v1.1.0...HEAD
|
|
101
|
+
[1.1.0]: https://github.com/carloshpdoc/memorydetective/compare/v1.0.1...v1.1.0
|
|
78
102
|
[1.0.1]: https://github.com/carloshpdoc/memorydetective/compare/v1.0.0...v1.0.1
|
|
79
103
|
[1.0.0]: https://github.com/carloshpdoc/memorydetective/releases/tag/v1.0.0
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Carlos Henrique
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
memorydetective
|
|
2
|
+
Copyright 2026 Carlos Henrique
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License").
|
|
5
|
+
A copy of the License is included in this distribution as `LICENSE`,
|
|
6
|
+
and is also available at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Project home:
|
|
11
|
+
https://github.com/carloshpdoc/memorydetective
|
|
12
|
+
|
|
13
|
+
This product includes software developed by Carlos Henrique
|
|
14
|
+
(https://github.com/carloshpdoc).
|
|
15
|
+
|
|
16
|
+
If `memorydetective` saves you time, please consider:
|
|
17
|
+
• Starring the repository: https://github.com/carloshpdoc/memorydetective
|
|
18
|
+
• Sponsoring development: https://github.com/sponsors/carloshpdoc
|
|
19
|
+
• Buying me a coffee: https://buymeacoffee.com/carloshperc
|
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/memorydetective)
|
|
6
6
|
[](https://github.com/carloshpdoc/memorydetective/actions/workflows/ci.yml)
|
|
7
|
-
[](./LICENSE)
|
|
8
|
+
[](https://github.com/carloshpdoc/memorydetective/stargazers)
|
|
8
9
|
[](#requirements)
|
|
9
10
|
[](#requirements)
|
|
10
11
|
|
|
@@ -176,9 +177,9 @@ Copilot's MCP integration moves fast — if this snippet is stale, see the [VS C
|
|
|
176
177
|
|
|
177
178
|
## API
|
|
178
179
|
|
|
179
|
-
|
|
180
|
+
20 MCP tools, grouped by purpose.
|
|
180
181
|
|
|
181
|
-
### Read & analyze (
|
|
182
|
+
### Read & analyze (13)
|
|
182
183
|
|
|
183
184
|
| Tool | What |
|
|
184
185
|
|---|---|
|
|
@@ -186,6 +187,7 @@ Copilot's MCP integration moves fast — if this snippet is stale, see the [VS C
|
|
|
186
187
|
| `findCycles` | Extract just the ROOT CYCLE blocks as flattened chains, with optional `className` substring filter. |
|
|
187
188
|
| `findRetainers` | "Who is keeping `<class>` alive?" — returns retain chain paths from a top-level node down to the match. |
|
|
188
189
|
| `countAlive` | Count instances by class. Provide `className` for one number, or omit for top-N most-leaked classes. |
|
|
190
|
+
| `reachableFromCycle` | Cycle-scoped reachability. "How many `<X>` instances are reachable from the cycle rooted at `<Y>`?" — distinguishes the actual culprit from its retained dependencies. |
|
|
189
191
|
| `diffMemgraphs` | Compare two `.memgraph` snapshots: total deltas + class-count changes + cycles new/gone/persisted. |
|
|
190
192
|
| `classifyCycle` | Match each ROOT CYCLE against a built-in catalog of 8 known patterns (TagIndexProjection, ForEachState, Combine sink, Task captures, NotificationCenter observer, etc.) with confidence + fix hint. |
|
|
191
193
|
| `analyzeHangs` | Parse `xctrace` `potential-hangs` schema; return Hang vs Microhang counts + top N longest. |
|
|
@@ -293,17 +295,19 @@ If `memorydetective` saves you time, you can support continued development:
|
|
|
293
295
|
|
|
294
296
|
Every contribution helps keep this maintained and documented.
|
|
295
297
|
|
|
296
|
-
##
|
|
298
|
+
## License
|
|
297
299
|
|
|
298
|
-
|
|
299
|
-
- **v0.2** — community-contributable cycle catalog, Claude Code plugin (`/plugin install memorydetective`), close the `analyzeTimeProfile` SIGSEGV gap. Design docs in [docs/](./docs/).
|
|
300
|
-
- **Phase 3** (gated) — GitHub Action + SaaS dashboard for PR-time leak detection.
|
|
300
|
+
Apache 2.0 — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
|
|
301
301
|
|
|
302
|
-
|
|
302
|
+
Permits commercial use, modification, distribution, patent use. Includes attribution clause via the `NOTICE` file.
|
|
303
303
|
|
|
304
|
-
##
|
|
304
|
+
## Companion MCPs
|
|
305
|
+
|
|
306
|
+
`memorydetective` focuses on memory-graph and trace artifacts. To bridge "found this leak in the cycle" with "find it in your codebase", pair it with a Swift source-aware MCP. Recommended:
|
|
307
|
+
|
|
308
|
+
- [SwiftLens](https://github.com/swiftlens/swiftlens) — wraps SourceKit-LSP for Swift symbol lookup, reference search, hover info. Different license model (non-commercial); read its terms before using in a paid product.
|
|
305
309
|
|
|
306
|
-
|
|
310
|
+
A future version of `memorydetective` may include a similar source-bridging surface natively under Apache 2.0; see the v1.2 roadmap notes in the design docs.
|
|
307
311
|
|
|
308
312
|
## Why "memorydetective"?
|
|
309
313
|
|
package/dist/cli.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
* memorydetective --help
|
|
11
11
|
* memorydetective --version
|
|
12
12
|
*/
|
|
13
|
-
import { existsSync } from "node:fs";
|
|
14
|
-
import {
|
|
13
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { resolve as resolvePath, join as joinPath } from "node:path";
|
|
15
16
|
import { analyzeMemgraph } from "./tools/analyzeMemgraph.js";
|
|
16
17
|
import { classifyCycle } from "./tools/classifyCycle.js";
|
|
17
18
|
const C = {
|
|
@@ -24,7 +25,7 @@ const C = {
|
|
|
24
25
|
cyan: "\x1b[36m",
|
|
25
26
|
gray: "\x1b[90m",
|
|
26
27
|
};
|
|
27
|
-
const VERSION = "1.0
|
|
28
|
+
const VERSION = "1.1.0";
|
|
28
29
|
const HELP = `${C.bold}memorydetective${C.reset} — iOS leak hunting from the CLI
|
|
29
30
|
|
|
30
31
|
${C.dim}Usage:${C.reset}
|
|
@@ -39,8 +40,38 @@ ${C.dim}Flags:${C.reset}
|
|
|
39
40
|
|
|
40
41
|
${C.dim}When called with no arguments, memorydetective starts as an MCP server${C.reset}
|
|
41
42
|
${C.dim}over stdio. See https://github.com/carloshpdoc/memorydetective#configure${C.reset}
|
|
42
|
-
${C.dim}for full Claude Code / Desktop / Cursor / Cline configuration.${C.reset}
|
|
43
|
+
${C.dim}for full Claude Code / Desktop / Cursor / Cline / Kiro configuration.${C.reset}
|
|
44
|
+
|
|
45
|
+
${C.dim}⭐ Star: ${C.reset}https://github.com/carloshpdoc/memorydetective
|
|
46
|
+
`;
|
|
47
|
+
const FIRST_RUN_BANNER = `
|
|
48
|
+
${C.bold}👋 First time using memorydetective?${C.reset}
|
|
49
|
+
|
|
50
|
+
${C.green}⭐ Star:${C.reset} https://github.com/carloshpdoc/memorydetective
|
|
51
|
+
${C.cyan}📖 Guide:${C.reset} https://github.com/carloshpdoc/memorydetective/blob/main/USAGE.md
|
|
52
|
+
${C.yellow}☕ Sponsor:${C.reset} https://buymeacoffee.com/carloshperc
|
|
53
|
+
|
|
54
|
+
${C.dim}This message shows once.${C.reset}
|
|
43
55
|
`;
|
|
56
|
+
const FIRST_RUN_MARKER = joinPath(homedir(), ".config", "memorydetective", "seen");
|
|
57
|
+
/** Show the first-time banner once per machine, then create a marker so it
|
|
58
|
+
* never shows again. Failures (e.g. read-only home) are silent — banner
|
|
59
|
+
* hygiene shouldn't break the user's actual work. */
|
|
60
|
+
function maybeShowFirstRunBanner() {
|
|
61
|
+
try {
|
|
62
|
+
if (existsSync(FIRST_RUN_MARKER))
|
|
63
|
+
return;
|
|
64
|
+
process.stderr.write(FIRST_RUN_BANNER + "\n");
|
|
65
|
+
mkdirSync(joinPath(homedir(), ".config", "memorydetective"), {
|
|
66
|
+
recursive: true,
|
|
67
|
+
});
|
|
68
|
+
writeFileSync(FIRST_RUN_MARKER, new Date().toISOString());
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// ignore — never fail because of the banner
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const DIAGNOSIS_FOOTER = `${C.dim}# Found this useful? ⭐ https://github.com/carloshpdoc/memorydetective${C.reset}`;
|
|
44
75
|
const KNOWN_COMMANDS = ["analyze", "classify", "--help", "-h", "help", "--version", "-v"];
|
|
45
76
|
function truncate(s, max) {
|
|
46
77
|
return s.length > max ? s.slice(0, max - 1) + "…" : s;
|
|
@@ -128,7 +159,12 @@ function suggestCommand(input) {
|
|
|
128
159
|
}
|
|
129
160
|
async function runAnalyze(memgraphPath, asJson) {
|
|
130
161
|
validateMemgraphPath(memgraphPath);
|
|
131
|
-
const result = await analyzeMemgraph({
|
|
162
|
+
const result = await analyzeMemgraph({
|
|
163
|
+
path: memgraphPath,
|
|
164
|
+
fullChains: false,
|
|
165
|
+
verbosity: "compact",
|
|
166
|
+
maxClassesInChain: 10,
|
|
167
|
+
});
|
|
132
168
|
if (asJson) {
|
|
133
169
|
process.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
134
170
|
return 0;
|
|
@@ -155,6 +191,7 @@ async function runAnalyze(memgraphPath, asJson) {
|
|
|
155
191
|
}
|
|
156
192
|
console.log(`\n ${C.bold}Diagnosis:${C.reset}`);
|
|
157
193
|
console.log(` ${C.green}${result.diagnosis}${C.reset}\n`);
|
|
194
|
+
console.log(DIAGNOSIS_FOOTER + "\n");
|
|
158
195
|
return 0;
|
|
159
196
|
}
|
|
160
197
|
async function runClassify(memgraphPath, asJson) {
|
|
@@ -190,9 +227,16 @@ async function runClassify(memgraphPath, asJson) {
|
|
|
190
227
|
}
|
|
191
228
|
}
|
|
192
229
|
console.log("");
|
|
230
|
+
console.log(DIAGNOSIS_FOOTER + "\n");
|
|
193
231
|
return 0;
|
|
194
232
|
}
|
|
195
233
|
export async function runCli(args) {
|
|
234
|
+
// Fire the first-run banner before dispatching anything heavy. JSON-mode
|
|
235
|
+
// callers shouldn't see it (might mess with their pipes), so we only show
|
|
236
|
+
// it for human-output commands.
|
|
237
|
+
const isJsonRun = args.includes("--json");
|
|
238
|
+
if (!isJsonRun)
|
|
239
|
+
maybeShowFirstRunBanner();
|
|
196
240
|
const [cmd, ...rest] = args;
|
|
197
241
|
try {
|
|
198
242
|
switch (cmd) {
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,CAAC,GAAG;IACR,KAAK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C,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,qBAAqB,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC;gBAC3E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC3B,OAAO,CAAC,CAAC;YACX,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,KAAK,IAAI,QAAQ,EAAE,CAAC,CAAC;QACtD,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { analyzeAppLaunch, analyzeAppLaunchSchema, } from "./tools/analyzeAppLau
|
|
|
19
19
|
import { renderCycleGraph, renderCycleGraphSchema, } from "./tools/renderCycleGraph.js";
|
|
20
20
|
import { logShow, logShowSchema, logStream, logStreamSchema, } from "./tools/logShow.js";
|
|
21
21
|
import { detectLeaksInXCUITest, detectLeaksInXCUITestSchema, } from "./tools/detectLeaksInXCUITest.js";
|
|
22
|
+
import { reachableFromCycle, reachableFromCycleSchema, } from "./tools/reachableFromCycle.js";
|
|
22
23
|
const SERVER_NAME = "memorydetective";
|
|
23
24
|
const SERVER_VERSION = "0.1.0-dev";
|
|
24
25
|
const server = new McpServer({
|
|
@@ -211,6 +212,16 @@ server.registerTool("detectLeaksInXCUITest", {
|
|
|
211
212
|
const result = await detectLeaksInXCUITest(input);
|
|
212
213
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
213
214
|
});
|
|
215
|
+
server.registerTool("reachableFromCycle", {
|
|
216
|
+
title: "Count instances reachable from a specific cycle root",
|
|
217
|
+
description: "Cycle-scoped reachability + class counting. Answers questions like \"how many `NSURLSessionConfiguration` instances are reachable from the cycle rooted at `DetailViewModel`?\" — distinguishing the actual culprit (the cycle root) from its retained dependencies. Pick a cycle by zero-based `cycleIndex` or by `rootClassName` substring. Returns per-class counts ranked by occurrence, plus the total reachable node count.",
|
|
218
|
+
inputSchema: reachableFromCycleSchema.shape,
|
|
219
|
+
}, async (input) => {
|
|
220
|
+
const result = await reachableFromCycle(input);
|
|
221
|
+
return {
|
|
222
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
223
|
+
};
|
|
224
|
+
});
|
|
214
225
|
async function main() {
|
|
215
226
|
// CLI mode: when called with arguments, run the synchronous CLI wrapper.
|
|
216
227
|
// No arguments → start the MCP server over stdio (the default and the
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,eAAe,EACf,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,eAAe,EACf,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,OAAO,EACP,aAAa,EACb,SAAS,EACT,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,eAAe,EACf,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,aAAa,EACb,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACz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AE;IACnB,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shorten verbose Swift / SwiftUI class names so MCP tool responses fit in
|
|
3
|
+
* an LLM context budget.
|
|
4
|
+
*
|
|
5
|
+
* Real SwiftUI demangled types nest 8+ generic levels deep and run 1000+ chars.
|
|
6
|
+
* Example input (one node, one chain):
|
|
7
|
+
*
|
|
8
|
+
* SwiftUI.ModifiedContent<SwiftUI.ModifiedContent<SwiftUI.ModifiedContent<
|
|
9
|
+
* SwiftUI._ConditionalContent<SwiftUI.ModifiedContent<SwiftUI.ModifiedContent<
|
|
10
|
+
* SwiftUI.AsyncImage<SwiftUI._ConditionalContent<...>>>, ...>>, ...>>
|
|
11
|
+
*
|
|
12
|
+
* Three layers of shortening, in order:
|
|
13
|
+
* 1. Drop standard module prefixes (Swift., SwiftUI., Foundation., Combine.)
|
|
14
|
+
* 2. Collapse nested ModifiedContent chains into "BaseType +N modifiers"
|
|
15
|
+
* 3. Truncate any remaining generic depth past `maxDepth` with a hash
|
|
16
|
+
* placeholder, e.g. `…<#1a2b3c>` (so equal generics still hash equal).
|
|
17
|
+
*
|
|
18
|
+
* Output for the example above might be:
|
|
19
|
+
* `ModifiedContent<…<#a3f1>> +12 modifiers`
|
|
20
|
+
*
|
|
21
|
+
* The full original is preserved on the caller side; this function never
|
|
22
|
+
* mutates the underlying CycleNode — it only returns a shortened display string.
|
|
23
|
+
*/
|
|
24
|
+
interface ShortenOptions {
|
|
25
|
+
/** Hard cap on the final string length (default 200). */
|
|
26
|
+
maxLength?: number;
|
|
27
|
+
/** Truncate generic angle-bracket depth past this (default 3). */
|
|
28
|
+
maxDepth?: number;
|
|
29
|
+
/** Drop module prefixes like `Swift.`, `SwiftUI.` (default true). */
|
|
30
|
+
dropModules?: boolean;
|
|
31
|
+
/** Collapse nested `ModifiedContent<…>` chains (default true). */
|
|
32
|
+
collapseModifiers?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Public API: produce a shortened display string for a class name. */
|
|
35
|
+
export declare function shortenClassName(className: string, opts?: ShortenOptions): string;
|
|
36
|
+
/**
|
|
37
|
+
* Verbosity levels accepted by tools that surface class names.
|
|
38
|
+
*
|
|
39
|
+
* - `compact`: aggressive shortening (default for high-signal/low-token output).
|
|
40
|
+
* - `normal`: drop modules, collapse modifiers, but keep depth.
|
|
41
|
+
* - `full`: return the original Swift demangled name verbatim.
|
|
42
|
+
*/
|
|
43
|
+
export type Verbosity = "compact" | "normal" | "full";
|
|
44
|
+
export declare function shortenForVerbosity(className: string, verbosity: Verbosity): string;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shorten verbose Swift / SwiftUI class names so MCP tool responses fit in
|
|
3
|
+
* an LLM context budget.
|
|
4
|
+
*
|
|
5
|
+
* Real SwiftUI demangled types nest 8+ generic levels deep and run 1000+ chars.
|
|
6
|
+
* Example input (one node, one chain):
|
|
7
|
+
*
|
|
8
|
+
* SwiftUI.ModifiedContent<SwiftUI.ModifiedContent<SwiftUI.ModifiedContent<
|
|
9
|
+
* SwiftUI._ConditionalContent<SwiftUI.ModifiedContent<SwiftUI.ModifiedContent<
|
|
10
|
+
* SwiftUI.AsyncImage<SwiftUI._ConditionalContent<...>>>, ...>>, ...>>
|
|
11
|
+
*
|
|
12
|
+
* Three layers of shortening, in order:
|
|
13
|
+
* 1. Drop standard module prefixes (Swift., SwiftUI., Foundation., Combine.)
|
|
14
|
+
* 2. Collapse nested ModifiedContent chains into "BaseType +N modifiers"
|
|
15
|
+
* 3. Truncate any remaining generic depth past `maxDepth` with a hash
|
|
16
|
+
* placeholder, e.g. `…<#1a2b3c>` (so equal generics still hash equal).
|
|
17
|
+
*
|
|
18
|
+
* Output for the example above might be:
|
|
19
|
+
* `ModifiedContent<…<#a3f1>> +12 modifiers`
|
|
20
|
+
*
|
|
21
|
+
* The full original is preserved on the caller side; this function never
|
|
22
|
+
* mutates the underlying CycleNode — it only returns a shortened display string.
|
|
23
|
+
*/
|
|
24
|
+
const MODULE_PREFIXES = [
|
|
25
|
+
"Swift.",
|
|
26
|
+
"SwiftUI.",
|
|
27
|
+
"Foundation.",
|
|
28
|
+
"Combine.",
|
|
29
|
+
"_Concurrency.",
|
|
30
|
+
];
|
|
31
|
+
const MODIFIED_CONTENT_RE = /SwiftUI\.ModifiedContent<|ModifiedContent</g;
|
|
32
|
+
/**
|
|
33
|
+
* Cheap deterministic hash of a string for hash-truncation placeholders.
|
|
34
|
+
* Identical inputs produce identical short codes — useful for diffing two
|
|
35
|
+
* memgraph dumps where a class name appears in both.
|
|
36
|
+
*/
|
|
37
|
+
function shortHash(s) {
|
|
38
|
+
let h = 5381;
|
|
39
|
+
for (let i = 0; i < s.length; i++) {
|
|
40
|
+
h = ((h << 5) + h + s.charCodeAt(i)) | 0;
|
|
41
|
+
}
|
|
42
|
+
return (h >>> 0).toString(16).slice(0, 6);
|
|
43
|
+
}
|
|
44
|
+
function dropModules(s) {
|
|
45
|
+
let out = s;
|
|
46
|
+
for (const prefix of MODULE_PREFIXES) {
|
|
47
|
+
out = out.split(prefix).join("");
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Count nested ModifiedContent occurrences and produce a `+N modifiers` summary.
|
|
53
|
+
* Heuristic but reliable for real SwiftUI dumps.
|
|
54
|
+
*/
|
|
55
|
+
function collapseModifiedContent(s) {
|
|
56
|
+
const matches = s.match(MODIFIED_CONTENT_RE);
|
|
57
|
+
const count = matches ? matches.length : 0;
|
|
58
|
+
if (count === 0)
|
|
59
|
+
return s;
|
|
60
|
+
// Find the innermost non-ModifiedContent type. We walk past every
|
|
61
|
+
// `ModifiedContent<` pair, ignoring its arguments.
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < s.length) {
|
|
64
|
+
const remainder = s.slice(i);
|
|
65
|
+
const m = remainder.match(/^(SwiftUI\.)?ModifiedContent</);
|
|
66
|
+
if (!m)
|
|
67
|
+
break;
|
|
68
|
+
i += m[0].length;
|
|
69
|
+
}
|
|
70
|
+
// From `i`, take the first nested type up to its first `,` or `>`.
|
|
71
|
+
const tail = s.slice(i);
|
|
72
|
+
const inner = tail.match(/^([\w._]+)(?:<[^,>]*>)?/);
|
|
73
|
+
const baseType = inner ? inner[1] : "ModifiedContent";
|
|
74
|
+
return `${baseType} +${count} modifiers`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Truncate generic depth past `maxDepth`. Replaces deeper generics with a
|
|
78
|
+
* hash placeholder so semantically-distinct types stay distinguishable.
|
|
79
|
+
*/
|
|
80
|
+
function truncateDepth(s, maxDepth) {
|
|
81
|
+
let depth = 0;
|
|
82
|
+
let out = "";
|
|
83
|
+
let i = 0;
|
|
84
|
+
let truncatedFragment = "";
|
|
85
|
+
let truncating = false;
|
|
86
|
+
let truncationDepth = 0;
|
|
87
|
+
while (i < s.length) {
|
|
88
|
+
const ch = s[i];
|
|
89
|
+
if (ch === "<") {
|
|
90
|
+
depth += 1;
|
|
91
|
+
if (!truncating && depth > maxDepth) {
|
|
92
|
+
truncating = true;
|
|
93
|
+
truncationDepth = depth - 1;
|
|
94
|
+
out += "<";
|
|
95
|
+
i += 1;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (ch === ">") {
|
|
100
|
+
depth -= 1;
|
|
101
|
+
if (truncating && depth === truncationDepth) {
|
|
102
|
+
out += `…<#${shortHash(truncatedFragment)}>>`;
|
|
103
|
+
truncatedFragment = "";
|
|
104
|
+
truncating = false;
|
|
105
|
+
i += 1;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (truncating) {
|
|
110
|
+
truncatedFragment += ch;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
out += ch;
|
|
114
|
+
}
|
|
115
|
+
i += 1;
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
/** Public API: produce a shortened display string for a class name. */
|
|
120
|
+
export function shortenClassName(className, opts = {}) {
|
|
121
|
+
const { maxLength = 200, maxDepth = 3, dropModules: doDrop = true, collapseModifiers = true, } = opts;
|
|
122
|
+
if (!className)
|
|
123
|
+
return "";
|
|
124
|
+
if (className.length <= maxLength && !className.includes("<")) {
|
|
125
|
+
return className;
|
|
126
|
+
}
|
|
127
|
+
let s = className;
|
|
128
|
+
if (doDrop)
|
|
129
|
+
s = dropModules(s);
|
|
130
|
+
if (collapseModifiers)
|
|
131
|
+
s = collapseModifiedContent(s);
|
|
132
|
+
s = truncateDepth(s, maxDepth);
|
|
133
|
+
// Final hard cap: middle-truncate.
|
|
134
|
+
if (s.length > maxLength) {
|
|
135
|
+
const half = Math.floor((maxLength - 1) / 2);
|
|
136
|
+
s = s.slice(0, half) + "…" + s.slice(s.length - half);
|
|
137
|
+
}
|
|
138
|
+
return s;
|
|
139
|
+
}
|
|
140
|
+
export function shortenForVerbosity(className, verbosity) {
|
|
141
|
+
switch (verbosity) {
|
|
142
|
+
case "full":
|
|
143
|
+
return className;
|
|
144
|
+
case "normal":
|
|
145
|
+
return shortenClassName(className, {
|
|
146
|
+
maxLength: 400,
|
|
147
|
+
maxDepth: 6,
|
|
148
|
+
collapseModifiers: false,
|
|
149
|
+
});
|
|
150
|
+
case "compact":
|
|
151
|
+
default:
|
|
152
|
+
return shortenClassName(className, { maxLength: 200, maxDepth: 3 });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=shortenClassName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shortenClassName.js","sourceRoot":"","sources":["../../src/parsers/shortenClassName.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;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,GAAG,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAWD,MAAM,UAAU,mBAAmB,CACjC,SAAiB,EACjB,SAAoB;IAEpB,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,MAAM;YACT,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,gBAAgB,CAAC,SAAS,EAAE;gBACjC,SAAS,EAAE,GAAG;gBACd,QAAQ,EAAE,CAAC;gBACX,iBAAiB,EAAE,KAAK;aACzB,CAAC,CAAC;QACL,KAAK,SAAS,CAAC;QACf;YACE,OAAO,gBAAgB,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;AACH,CAAC"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type Verbosity } from "../parsers/shortenClassName.js";
|
|
2
3
|
import type { LeaksReport } from "../types.js";
|
|
3
4
|
export declare const analyzeMemgraphSchema: z.ZodObject<{
|
|
4
5
|
path: z.ZodString;
|
|
5
6
|
fullChains: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
verbosity: z.ZodDefault<z.ZodEnum<["compact", "normal", "full"]>>;
|
|
8
|
+
maxClassesInChain: z.ZodDefault<z.ZodNumber>;
|
|
6
9
|
}, "strip", z.ZodTypeAny, {
|
|
7
10
|
path: string;
|
|
8
11
|
fullChains: boolean;
|
|
12
|
+
verbosity: "compact" | "normal" | "full";
|
|
13
|
+
maxClassesInChain: number;
|
|
9
14
|
}, {
|
|
10
15
|
path: string;
|
|
11
16
|
fullChains?: boolean | undefined;
|
|
17
|
+
verbosity?: "compact" | "normal" | "full" | undefined;
|
|
18
|
+
maxClassesInChain?: number | undefined;
|
|
12
19
|
}>;
|
|
13
20
|
export type AnalyzeMemgraphInput = z.infer<typeof analyzeMemgraphSchema>;
|
|
14
21
|
export interface CycleSummary {
|
|
@@ -19,8 +26,10 @@ export interface CycleSummary {
|
|
|
19
26
|
instanceSize?: number;
|
|
20
27
|
/** Number of descendant nodes in the retain chain. */
|
|
21
28
|
chainLength: number;
|
|
22
|
-
/**
|
|
29
|
+
/** Top-ranked class names appearing in the chain (capped, app-level priority). */
|
|
23
30
|
classesInChain: string[];
|
|
31
|
+
/** Total unique class names found in the chain (the cap-aware count for context). */
|
|
32
|
+
classesInChainTotal: number;
|
|
24
33
|
}
|
|
25
34
|
export interface AnalyzeMemgraphResult {
|
|
26
35
|
ok: boolean;
|
|
@@ -45,5 +54,5 @@ export interface AnalyzeMemgraphResult {
|
|
|
45
54
|
* Pure function: take a `leaks` stdout string and a source path, produce a structured analysis.
|
|
46
55
|
* Split out so it can be tested without spawning a subprocess.
|
|
47
56
|
*/
|
|
48
|
-
export declare function summarizeLeaks(leaksText: string, path: string, fullChains?: boolean): AnalyzeMemgraphResult;
|
|
57
|
+
export declare function summarizeLeaks(leaksText: string, path: string, fullChains?: boolean, verbosity?: Verbosity, maxClassesInChain?: number): AnalyzeMemgraphResult;
|
|
49
58
|
export declare function analyzeMemgraph(input: AnalyzeMemgraphInput): Promise<AnalyzeMemgraphResult>;
|
|
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { resolve as resolvePath } from "node:path";
|
|
4
4
|
import { runCommand } from "../runtime/exec.js";
|
|
5
5
|
import { parseLeaksOutput, rootCyclesOnly } from "../parsers/leaksOutput.js";
|
|
6
|
+
import { shortenForVerbosity, } from "../parsers/shortenClassName.js";
|
|
6
7
|
export const analyzeMemgraphSchema = z.object({
|
|
7
8
|
path: z
|
|
8
9
|
.string()
|
|
@@ -12,15 +13,26 @@ export const analyzeMemgraphSchema = z.object({
|
|
|
12
13
|
.boolean()
|
|
13
14
|
.default(false)
|
|
14
15
|
.describe("When true, include the full nested retain chains in the response. Default false returns only top-level ROOT CYCLE summaries to keep payloads small."),
|
|
16
|
+
verbosity: z
|
|
17
|
+
.enum(["compact", "normal", "full"])
|
|
18
|
+
.default("compact")
|
|
19
|
+
.describe("Class-name verbosity. `compact` (default) drops module prefixes, collapses nested SwiftUI ModifiedContent into `+N modifiers`, and truncates deep generics with a hash placeholder. `normal` keeps more detail. `full` returns Swift demangled names verbatim."),
|
|
20
|
+
maxClassesInChain: z
|
|
21
|
+
.number()
|
|
22
|
+
.int()
|
|
23
|
+
.positive()
|
|
24
|
+
.max(50)
|
|
25
|
+
.default(10)
|
|
26
|
+
.describe("Cap on how many unique class names to surface per cycle's `classesInChain` array. Default 10 — enough to identify app-level types without flooding the response."),
|
|
15
27
|
});
|
|
16
28
|
/**
|
|
17
29
|
* Pure function: take a `leaks` stdout string and a source path, produce a structured analysis.
|
|
18
30
|
* Split out so it can be tested without spawning a subprocess.
|
|
19
31
|
*/
|
|
20
|
-
export function summarizeLeaks(leaksText, path, fullChains = false) {
|
|
32
|
+
export function summarizeLeaks(leaksText, path, fullChains = false, verbosity = "compact", maxClassesInChain = 10) {
|
|
21
33
|
const report = parseLeaksOutput(leaksText);
|
|
22
34
|
const roots = rootCyclesOnly(report.cycles);
|
|
23
|
-
const cycles = roots.map((c) => summarizeCycle(c));
|
|
35
|
+
const cycles = roots.map((c) => summarizeCycle(c, verbosity, maxClassesInChain));
|
|
24
36
|
const diagnosis = buildDiagnosis(report, cycles);
|
|
25
37
|
return {
|
|
26
38
|
ok: true,
|
|
@@ -39,25 +51,41 @@ export function summarizeLeaks(leaksText, path, fullChains = false) {
|
|
|
39
51
|
diagnosis,
|
|
40
52
|
};
|
|
41
53
|
}
|
|
42
|
-
function summarizeCycle(node) {
|
|
43
|
-
const
|
|
54
|
+
function summarizeCycle(node, verbosity, maxClassesInChain) {
|
|
55
|
+
const classCounts = new Map();
|
|
44
56
|
let chainLength = 0;
|
|
45
57
|
const visit = (n) => {
|
|
46
58
|
chainLength += 1;
|
|
47
|
-
if (n.className)
|
|
48
|
-
|
|
59
|
+
if (n.className) {
|
|
60
|
+
const short = shortenForVerbosity(n.className, verbosity);
|
|
61
|
+
classCounts.set(short, (classCounts.get(short) ?? 0) + 1);
|
|
62
|
+
}
|
|
49
63
|
for (const child of n.children)
|
|
50
64
|
visit(child);
|
|
51
65
|
};
|
|
52
66
|
visit(node);
|
|
67
|
+
// Rank classes by occurrence count, take top N. App-level classes (those
|
|
68
|
+
// that don't start with a stdlib prefix even in compact form) get
|
|
69
|
+
// priority since they're the ones the user actually wrote.
|
|
70
|
+
const ranked = Array.from(classCounts.entries())
|
|
71
|
+
.sort((a, b) => {
|
|
72
|
+
const aIsApp = !/^(_DictionaryStorage|Closure|ForEach|Modified|AsyncImage|StoredLocation|LocationBox|TagIndex|AnyHashable|WeakBox|AnyLocation)/.test(a[0]);
|
|
73
|
+
const bIsApp = !/^(_DictionaryStorage|Closure|ForEach|Modified|AsyncImage|StoredLocation|LocationBox|TagIndex|AnyHashable|WeakBox|AnyLocation)/.test(b[0]);
|
|
74
|
+
if (aIsApp !== bIsApp)
|
|
75
|
+
return aIsApp ? -1 : 1;
|
|
76
|
+
return b[1] - a[1];
|
|
77
|
+
})
|
|
78
|
+
.slice(0, maxClassesInChain)
|
|
79
|
+
.map(([name]) => name);
|
|
53
80
|
return {
|
|
54
|
-
className: node.className,
|
|
81
|
+
className: shortenForVerbosity(node.className, verbosity),
|
|
55
82
|
address: node.address,
|
|
56
83
|
count: node.count,
|
|
57
84
|
size: node.size,
|
|
58
85
|
instanceSize: node.instanceSize,
|
|
59
86
|
chainLength,
|
|
60
|
-
classesInChain:
|
|
87
|
+
classesInChain: ranked,
|
|
88
|
+
classesInChainTotal: classCounts.size,
|
|
61
89
|
};
|
|
62
90
|
}
|
|
63
91
|
function buildDiagnosis(report, cycles) {
|
|
@@ -89,6 +117,6 @@ export async function analyzeMemgraph(input) {
|
|
|
89
117
|
if (result.code !== 0 && result.code !== 1) {
|
|
90
118
|
throw new Error(`leaks failed (code ${result.code}): ${result.stderr || result.stdout}`);
|
|
91
119
|
}
|
|
92
|
-
return summarizeLeaks(result.stdout, path, input.fullChains ?? false);
|
|
120
|
+
return summarizeLeaks(result.stdout, path, input.fullChains ?? false, input.verbosity ?? "compact", input.maxClassesInChain ?? 10);
|
|
93
121
|
}
|
|
94
122
|
//# sourceMappingURL=analyzeMemgraph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzeMemgraph.js","sourceRoot":"","sources":["../../src/tools/analyzeMemgraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"analyzeMemgraph.js","sourceRoot":"","sources":["../../src/tools/analyzeMemgraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AAGxC,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AAC;QAC3C,MAAM,IAAI,KAAK,CACb,sBAAsB,MAAM,CAAC,IAAI,MAAM,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CACxE,CAAC;IACJ,CAAC;IAED,OAAO,cAAc,CACnB,MAAM,CAAC,MAAM,EACb,IAAI,EACJ,KAAK,CAAC,UAAU,IAAI,KAAK,EACzB,KAAK,CAAC,SAAS,IAAI,SAAS,EAC5B,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type Verbosity } from "../parsers/shortenClassName.js";
|
|
2
3
|
export declare const findCyclesSchema: z.ZodObject<{
|
|
3
4
|
path: z.ZodString;
|
|
4
5
|
className: z.ZodOptional<z.ZodString>;
|
|
5
6
|
maxDepth: z.ZodDefault<z.ZodNumber>;
|
|
7
|
+
verbosity: z.ZodDefault<z.ZodEnum<["compact", "normal", "full"]>>;
|
|
6
8
|
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
path: string;
|
|
8
9
|
maxDepth: number;
|
|
10
|
+
path: string;
|
|
11
|
+
verbosity: "compact" | "normal" | "full";
|
|
9
12
|
className?: string | undefined;
|
|
10
13
|
}, {
|
|
11
14
|
path: string;
|
|
12
15
|
className?: string | undefined;
|
|
13
16
|
maxDepth?: number | undefined;
|
|
17
|
+
verbosity?: "compact" | "normal" | "full" | undefined;
|
|
14
18
|
}>;
|
|
15
19
|
export type FindCyclesInput = z.infer<typeof findCyclesSchema>;
|
|
16
20
|
export interface CycleChainEntry {
|
|
@@ -41,5 +45,5 @@ export interface FindCyclesResult {
|
|
|
41
45
|
cycles: CycleResult[];
|
|
42
46
|
}
|
|
43
47
|
/** Pure function: parse `leaks` output and return the cycles array. */
|
|
44
|
-
export declare function extractCycles(leaksText: string, path: string, filter?: string, maxDepth?: number): FindCyclesResult;
|
|
48
|
+
export declare function extractCycles(leaksText: string, path: string, filter?: string, maxDepth?: number, verbosity?: Verbosity): FindCyclesResult;
|
|
45
49
|
export declare function findCycles(input: FindCyclesInput): Promise<FindCyclesResult>;
|
package/dist/tools/findCycles.js
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { resolve as resolvePath } from "node:path";
|
|
4
4
|
import { runCommand } from "../runtime/exec.js";
|
|
5
5
|
import { parseLeaksOutput, rootCyclesOnly, walkCycles, } from "../parsers/leaksOutput.js";
|
|
6
|
+
import { shortenForVerbosity, } from "../parsers/shortenClassName.js";
|
|
6
7
|
export const findCyclesSchema = z.object({
|
|
7
8
|
path: z.string().min(1).describe("Absolute path to a `.memgraph` file."),
|
|
8
9
|
className: z
|
|
@@ -15,8 +16,12 @@ export const findCyclesSchema = z.object({
|
|
|
15
16
|
.positive()
|
|
16
17
|
.default(10)
|
|
17
18
|
.describe("Truncate chains beyond this depth (default 10)."),
|
|
19
|
+
verbosity: z
|
|
20
|
+
.enum(["compact", "normal", "full"])
|
|
21
|
+
.default("compact")
|
|
22
|
+
.describe("Class-name verbosity. `compact` shortens SwiftUI generic names aggressively; `full` returns demangled names verbatim."),
|
|
18
23
|
});
|
|
19
|
-
function flattenChain(node, maxDepth) {
|
|
24
|
+
function flattenChain(node, maxDepth, verbosity) {
|
|
20
25
|
const out = [];
|
|
21
26
|
for (const { node: n, depth } of walkCycles([node])) {
|
|
22
27
|
if (depth > maxDepth)
|
|
@@ -25,7 +30,7 @@ function flattenChain(node, maxDepth) {
|
|
|
25
30
|
depth,
|
|
26
31
|
edge: n.edge,
|
|
27
32
|
retainKind: n.retainKind,
|
|
28
|
-
className: n.className,
|
|
33
|
+
className: shortenForVerbosity(n.className, verbosity),
|
|
29
34
|
address: n.address,
|
|
30
35
|
count: n.count,
|
|
31
36
|
size: n.size,
|
|
@@ -36,16 +41,16 @@ function flattenChain(node, maxDepth) {
|
|
|
36
41
|
return out;
|
|
37
42
|
}
|
|
38
43
|
/** Pure function: parse `leaks` output and return the cycles array. */
|
|
39
|
-
export function extractCycles(leaksText, path, filter, maxDepth = 10) {
|
|
44
|
+
export function extractCycles(leaksText, path, filter, maxDepth = 10, verbosity = "compact") {
|
|
40
45
|
const report = parseLeaksOutput(leaksText);
|
|
41
46
|
const roots = rootCyclesOnly(report.cycles);
|
|
42
47
|
const cycles = roots.map((c) => {
|
|
43
|
-
const chain = flattenChain(c, maxDepth);
|
|
48
|
+
const chain = flattenChain(c, maxDepth, verbosity);
|
|
44
49
|
const matched = filter
|
|
45
50
|
? chain.some((entry) => entry.className.includes(filter))
|
|
46
51
|
: true;
|
|
47
52
|
return {
|
|
48
|
-
rootClass: c.className,
|
|
53
|
+
rootClass: shortenForVerbosity(c.className, verbosity),
|
|
49
54
|
rootAddress: c.address,
|
|
50
55
|
count: c.count,
|
|
51
56
|
size: c.size,
|
|
@@ -73,6 +78,6 @@ export async function findCycles(input) {
|
|
|
73
78
|
if (result.code !== 0 && result.code !== 1) {
|
|
74
79
|
throw new Error(`leaks failed (code ${result.code}): ${result.stderr || result.stdout}`);
|
|
75
80
|
}
|
|
76
|
-
return extractCycles(result.stdout, path, input.className, input.maxDepth ?? 10);
|
|
81
|
+
return extractCycles(result.stdout, path, input.className, input.maxDepth ?? 10, input.verbosity ?? "compact");
|
|
77
82
|
}
|
|
78
83
|
//# sourceMappingURL=findCycles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findCycles.js","sourceRoot":"","sources":["../../src/tools/findCycles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,2BAA2B,CAAC;
|
|
1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oped reachability + class counting.
|
|
5
|
+
*
|
|
6
|
+
* Answers questions like:
|
|
7
|
+
* "How many `NSURLSessionConfiguration` instances are reachable from the
|
|
8
|
+
* cycle rooted at `DetailViewModel`?"
|
|
9
|
+
*
|
|
10
|
+
* Where global `countAlive` would say "4495 NSURLSessionConfiguration", this
|
|
11
|
+
* tool says "1100 reachable from each of the 4 cycles, so the cycle root is
|
|
12
|
+
* the actual culprit pinning them in memory."
|
|
13
|
+
*
|
|
14
|
+
* API shape inspired by Meta's `memlab` predicate-based queries.
|
|
15
|
+
*/
|
|
16
|
+
export declare const reachableFromCycleSchema: z.ZodObject<{
|
|
17
|
+
path: z.ZodString;
|
|
18
|
+
cycleIndex: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
rootClassName: z.ZodOptional<z.ZodString>;
|
|
20
|
+
className: z.ZodOptional<z.ZodString>;
|
|
21
|
+
topN: z.ZodDefault<z.ZodNumber>;
|
|
22
|
+
verbosity: z.ZodDefault<z.ZodEnum<["compact", "normal", "full"]>>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
path: string;
|
|
25
|
+
verbosity: "compact" | "normal" | "full";
|
|
26
|
+
topN: number;
|
|
27
|
+
className?: string | undefined;
|
|
28
|
+
cycleIndex?: number | undefined;
|
|
29
|
+
rootClassName?: string | undefined;
|
|
30
|
+
}, {
|
|
31
|
+
path: string;
|
|
32
|
+
className?: string | undefined;
|
|
33
|
+
verbosity?: "compact" | "normal" | "full" | undefined;
|
|
34
|
+
topN?: number | undefined;
|
|
35
|
+
cycleIndex?: number | undefined;
|
|
36
|
+
rootClassName?: string | undefined;
|
|
37
|
+
}>;
|
|
38
|
+
export type ReachableFromCycleInput = z.infer<typeof reachableFromCycleSchema>;
|
|
39
|
+
export interface ClassCount {
|
|
40
|
+
className: string;
|
|
41
|
+
count: number;
|
|
42
|
+
}
|
|
43
|
+
export interface ReachableFromCycleResult {
|
|
44
|
+
ok: boolean;
|
|
45
|
+
path: string;
|
|
46
|
+
/** The cycle that was scoped to. */
|
|
47
|
+
cycle: {
|
|
48
|
+
index: number;
|
|
49
|
+
rootClass: string;
|
|
50
|
+
rootAddress: string;
|
|
51
|
+
/** Total reachable nodes from this cycle root (including descendants). */
|
|
52
|
+
totalReachable: number;
|
|
53
|
+
};
|
|
54
|
+
/** When `className` filter is provided, only that class shows up. Otherwise top N. */
|
|
55
|
+
counts: ClassCount[];
|
|
56
|
+
/** Total unique classes in the cycle's reachable set. */
|
|
57
|
+
uniqueClasses: number;
|
|
58
|
+
}
|
|
59
|
+
/** Pure: compute the result from a parsed report. Exposed for testing. */
|
|
60
|
+
export declare function reachableFromReport(report: LeaksReport, path: string, input: ReachableFromCycleInput): ReachableFromCycleResult;
|
|
61
|
+
export declare function reachableFromCycle(input: ReachableFromCycleInput): Promise<ReachableFromCycleResult>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { runLeaksAndParse } from "../runtime/leaks.js";
|
|
3
|
+
import { rootCyclesOnly } from "../parsers/leaksOutput.js";
|
|
4
|
+
import { shortenForVerbosity, } from "../parsers/shortenClassName.js";
|
|
5
|
+
/**
|
|
6
|
+
* Cycle-scoped reachability + class counting.
|
|
7
|
+
*
|
|
8
|
+
* Answers questions like:
|
|
9
|
+
* "How many `NSURLSessionConfiguration` instances are reachable from the
|
|
10
|
+
* cycle rooted at `DetailViewModel`?"
|
|
11
|
+
*
|
|
12
|
+
* Where global `countAlive` would say "4495 NSURLSessionConfiguration", this
|
|
13
|
+
* tool says "1100 reachable from each of the 4 cycles, so the cycle root is
|
|
14
|
+
* the actual culprit pinning them in memory."
|
|
15
|
+
*
|
|
16
|
+
* API shape inspired by Meta's `memlab` predicate-based queries.
|
|
17
|
+
*/
|
|
18
|
+
export const reachableFromCycleSchema = z.object({
|
|
19
|
+
path: z.string().min(1).describe("Absolute path to a `.memgraph` file."),
|
|
20
|
+
cycleIndex: z
|
|
21
|
+
.number()
|
|
22
|
+
.int()
|
|
23
|
+
.nonnegative()
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Zero-based index of the ROOT CYCLE to scope to. Mutually exclusive with `rootClassName`. When neither is given, defaults to cycle index 0."),
|
|
26
|
+
rootClassName: z
|
|
27
|
+
.string()
|
|
28
|
+
.optional()
|
|
29
|
+
.describe("Substring of the root cycle's class name (e.g. \"DetailViewModel\"). Picks the first ROOT CYCLE whose root matches. Mutually exclusive with `cycleIndex`."),
|
|
30
|
+
className: z
|
|
31
|
+
.string()
|
|
32
|
+
.optional()
|
|
33
|
+
.describe("Optional filter — only count nodes whose className contains this substring. When omitted, returns the full per-class breakdown."),
|
|
34
|
+
topN: z
|
|
35
|
+
.number()
|
|
36
|
+
.int()
|
|
37
|
+
.positive()
|
|
38
|
+
.max(100)
|
|
39
|
+
.default(20)
|
|
40
|
+
.describe("Cap on per-class entries returned (default 20)."),
|
|
41
|
+
verbosity: z
|
|
42
|
+
.enum(["compact", "normal", "full"])
|
|
43
|
+
.default("compact")
|
|
44
|
+
.describe("Class-name verbosity for the response. See analyzeMemgraph for the same flag."),
|
|
45
|
+
});
|
|
46
|
+
/** Pure: walk the tree from root, count nodes by className. */
|
|
47
|
+
function countReachableFromNode(root, verbosity) {
|
|
48
|
+
const counts = new Map();
|
|
49
|
+
let total = 0;
|
|
50
|
+
const visit = (n) => {
|
|
51
|
+
total += 1;
|
|
52
|
+
if (n.className) {
|
|
53
|
+
const short = shortenForVerbosity(n.className, verbosity);
|
|
54
|
+
counts.set(short, (counts.get(short) ?? 0) + 1);
|
|
55
|
+
}
|
|
56
|
+
for (const child of n.children)
|
|
57
|
+
visit(child);
|
|
58
|
+
};
|
|
59
|
+
visit(root);
|
|
60
|
+
return { byClass: counts, total };
|
|
61
|
+
}
|
|
62
|
+
function pickCycle(report, input) {
|
|
63
|
+
const roots = rootCyclesOnly(report.cycles);
|
|
64
|
+
if (roots.length === 0)
|
|
65
|
+
return null;
|
|
66
|
+
if (input.rootClassName) {
|
|
67
|
+
const idx = roots.findIndex((r) => r.className.includes(input.rootClassName));
|
|
68
|
+
if (idx >= 0)
|
|
69
|
+
return { node: roots[idx], index: idx };
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const idx = input.cycleIndex ?? 0;
|
|
73
|
+
if (idx >= roots.length)
|
|
74
|
+
return null;
|
|
75
|
+
return { node: roots[idx], index: idx };
|
|
76
|
+
}
|
|
77
|
+
/** Pure: compute the result from a parsed report. Exposed for testing. */
|
|
78
|
+
export function reachableFromReport(report, path, input) {
|
|
79
|
+
const picked = pickCycle(report, input);
|
|
80
|
+
if (!picked) {
|
|
81
|
+
throw new Error(input.rootClassName
|
|
82
|
+
? `No ROOT CYCLE found whose root class contains "${input.rootClassName}".`
|
|
83
|
+
: `No ROOT CYCLE at index ${input.cycleIndex ?? 0}. Available roots: ${rootCyclesOnly(report.cycles).length}.`);
|
|
84
|
+
}
|
|
85
|
+
const verbosity = input.verbosity ?? "compact";
|
|
86
|
+
const { byClass, total } = countReachableFromNode(picked.node, verbosity);
|
|
87
|
+
let entries = Array.from(byClass.entries()).map(([n, c]) => ({
|
|
88
|
+
className: n,
|
|
89
|
+
count: c,
|
|
90
|
+
}));
|
|
91
|
+
if (input.className) {
|
|
92
|
+
entries = entries.filter((e) => e.className.includes(input.className));
|
|
93
|
+
}
|
|
94
|
+
entries.sort((a, b) => b.count - a.count);
|
|
95
|
+
entries = entries.slice(0, input.topN ?? 20);
|
|
96
|
+
return {
|
|
97
|
+
ok: true,
|
|
98
|
+
path,
|
|
99
|
+
cycle: {
|
|
100
|
+
index: picked.index,
|
|
101
|
+
rootClass: shortenForVerbosity(picked.node.className, verbosity),
|
|
102
|
+
rootAddress: picked.node.address,
|
|
103
|
+
totalReachable: total,
|
|
104
|
+
},
|
|
105
|
+
counts: entries,
|
|
106
|
+
uniqueClasses: byClass.size,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export async function reachableFromCycle(input) {
|
|
110
|
+
if (input.cycleIndex !== undefined && input.rootClassName !== undefined) {
|
|
111
|
+
throw new Error("Provide either `cycleIndex` or `rootClassName`, not both.");
|
|
112
|
+
}
|
|
113
|
+
const { report, resolvedPath } = await runLeaksAndParse(input.path);
|
|
114
|
+
return reachableFromReport(report, resolvedPath, input);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=reachableFromCycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reachableFromCycle.js","sourceRoot":"","sources":["../../src/tools/reachableFromCycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACL,mBAAmB,GAEpB,MAAM,gCAAgC,CAAC;AAGxC;;;;;;;;;;;;GAYG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IACxE,UAAU,EAAE,CAAC;SACV,MAAM,EAAE;SACR,GAAG,EAAE;SACL,WAAW,EAAE;SACb,QAAQ,EAAE;SACV,QAAQ,CACP,4IAA4I,CAC7I;IACH,aAAa,EAAE,CAAC;SACb,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,2JAA2J,CAC5J;IACH,SAAS,EAAE,CAAC;SACT,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,iIAAiI,CAClI;IACH,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,GAAG,CAAC,GAAG,CAAC;SACR,OAAO,CAAC,EAAE,CAAC;SACX,QAAQ,CAAC,iDAAiD,CAAC;IAC9D,SAAS,EAAE,C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assName: z.ZodDefault<z.ZodNumber>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
path: string;
|
|
11
10
|
maxDepth: number;
|
|
11
|
+
path: string;
|
|
12
12
|
cycleIndex: number;
|
|
13
13
|
format: "mermaid" | "dot";
|
|
14
14
|
truncateClassName: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memorydetective",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "MCP server for iOS leak hunting and performance investigation. Reads .memgraph + .trace files, captures new ones via xctrace and leaks(1), classifies retain cycles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dist",
|
|
12
12
|
"README.md",
|
|
13
13
|
"LICENSE",
|
|
14
|
+
"NOTICE",
|
|
14
15
|
"CHANGELOG.md",
|
|
15
16
|
"USAGE.md"
|
|
16
17
|
],
|
|
@@ -35,7 +36,7 @@
|
|
|
35
36
|
"performance"
|
|
36
37
|
],
|
|
37
38
|
"author": "Carlos Henrique",
|
|
38
|
-
"license": "
|
|
39
|
+
"license": "Apache-2.0",
|
|
39
40
|
"homepage": "https://github.com/carloshpdoc/memorydetective#readme",
|
|
40
41
|
"repository": {
|
|
41
42
|
"type": "git",
|