memorydetective 1.1.0 → 1.2.1

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 (37) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/README.md +49 -20
  3. package/USAGE.md +39 -23
  4. package/dist/cli.js +1 -1
  5. package/dist/index.js +41 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/runtime/sourcekit/client.d.ts +37 -0
  8. package/dist/runtime/sourcekit/client.js +132 -0
  9. package/dist/runtime/sourcekit/client.js.map +1 -0
  10. package/dist/runtime/sourcekit/pool.d.ts +25 -0
  11. package/dist/runtime/sourcekit/pool.js +101 -0
  12. package/dist/runtime/sourcekit/pool.js.map +1 -0
  13. package/dist/runtime/sourcekit/protocol.d.ts +37 -0
  14. package/dist/runtime/sourcekit/protocol.js +161 -0
  15. package/dist/runtime/sourcekit/protocol.js.map +1 -0
  16. package/dist/tools/swift/_helpers.d.ts +29 -0
  17. package/dist/tools/swift/_helpers.js +64 -0
  18. package/dist/tools/swift/_helpers.js.map +1 -0
  19. package/dist/tools/swift/findSymbolReferences.d.ts +30 -0
  20. package/dist/tools/swift/findSymbolReferences.js +56 -0
  21. package/dist/tools/swift/findSymbolReferences.js.map +1 -0
  22. package/dist/tools/swift/getHoverInfo.d.ts +27 -0
  23. package/dist/tools/swift/getHoverInfo.js +40 -0
  24. package/dist/tools/swift/getHoverInfo.js.map +1 -0
  25. package/dist/tools/swift/getSymbolDefinition.d.ts +46 -0
  26. package/dist/tools/swift/getSymbolDefinition.js +68 -0
  27. package/dist/tools/swift/getSymbolDefinition.js.map +1 -0
  28. package/dist/tools/swift/getSymbolsOverview.d.ts +22 -0
  29. package/dist/tools/swift/getSymbolsOverview.js +33 -0
  30. package/dist/tools/swift/getSymbolsOverview.js.map +1 -0
  31. package/dist/tools/swift/index.d.ts +14 -0
  32. package/dist/tools/swift/index.js +15 -0
  33. package/dist/tools/swift/index.js.map +1 -0
  34. package/dist/tools/swift/searchPattern.d.ts +38 -0
  35. package/dist/tools/swift/searchPattern.js +71 -0
  36. package/dist/tools/swift/searchPattern.js.map +1 -0
  37. package/package.json +3 -1
package/CHANGELOG.md CHANGED
@@ -6,6 +6,44 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.1] — 2026-05-01
10
+
11
+ ### Added
12
+
13
+ - README: new fourth example "End-to-end: leak → file → fix suggestion" walking through the complete chat-driven workflow with v1.2's Swift source-bridging tools.
14
+ - USAGE.md: section 4 ("Common follow-up requests") expanded with prompts that exercise `swiftGetSymbolDefinition`, `swiftFindSymbolReferences`, `swiftGetSymbolsOverview`, `swiftGetHoverInfo`, `swiftSearchPattern`. New `reachableFromCycle` row added.
15
+ - USAGE.md: section 3 ("How fixes flow") rewritten to reflect the new responsibility split — `memorydetective` now covers diagnose **and** source bridging; the agent owns "decide and apply the edit".
16
+
17
+ ### Changed
18
+
19
+ - USAGE.md concrete end-to-end example replaced with a richer 9-step flow that exercises memgraph analysis + `reachableFromCycle` + Swift LSP tools end-to-end.
20
+
21
+ ### Notes
22
+
23
+ - Doc-only release. No code changes from `1.2.0`.
24
+
25
+ ## [1.2.0] — 2026-05-01
26
+
27
+ Swift source-bridging. The agent can now go from "found a leak in the cycle" to "find the file/line in this project" without leaving chat. 20 → 25 tools.
28
+
29
+ ### Added
30
+
31
+ - **5 Swift source-bridging tools** backed by a `sourcekit-lsp` subprocess pool:
32
+ - `swiftGetSymbolDefinition` — locate a class/struct/enum/etc. declaration. Pre-scans candidate paths with a fast regex, then asks SourceKit-LSP for jump-to-definition.
33
+ - `swiftFindSymbolReferences` — every reference to a Swift symbol via `textDocument/references`. Includes a `needsIndex` hint when the IndexStoreDB is missing.
34
+ - `swiftGetSymbolsOverview` — top-level symbols in a file (cheap orientation when landing in a new file).
35
+ - `swiftGetHoverInfo` — type info / docs at a position. Useful to disambiguate class vs struct `self` captures.
36
+ - `swiftSearchPattern` — pure regex search over a Swift file (no LSP, no index). Catches closure capture lists and other patterns LSP can't see.
37
+ - **`src/runtime/sourcekit/` infrastructure**: `client.ts` (LSP subprocess + JSON-RPC stdio via `vscode-jsonrpc`), `pool.ts` (per-project-root client pool with 5-minute idle shutdown), `protocol.ts` (typed wrappers for the LSP methods we use, using `vscode-languageserver-protocol` types).
38
+ - New deps: `vscode-jsonrpc`, `vscode-languageserver-protocol`. Both MIT.
39
+ - 13 new unit tests for the Swift tools (mostly `searchPattern` + helper coverage; LSP-backed tools require a live SourceKit-LSP and are smoke-tested out-of-band).
40
+
41
+ ### Notes
42
+
43
+ - The Swift tools require macOS + a full Xcode install (`xcrun sourcekit-lsp` must be available). Command Line Tools alone is not enough.
44
+ - For cross-file references, the project needs an `IndexStoreDB` at `<projectRoot>/.build/index/store`. Build it with `swift build -Xswiftc -index-store-path -Xswiftc <projectRoot>/.build/index/store`.
45
+ - `sourcekit-lsp` cold start is ~2s; the pool amortizes that across calls within a project.
46
+
9
47
  ## [1.1.0] — 2026-05-01
10
48
 
11
49
  Response-size + cycle-scoped queries + license switch + first-run engagement.
@@ -97,7 +135,9 @@ When called with no arguments it starts the MCP server over stdio.
97
135
  - **`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.
98
136
  - **`detectLeaksInXCUITest`** is flagged experimental: orchestration logic is implemented but not yet validated against a wide set of production XCUITest runs.
99
137
 
100
- [Unreleased]: https://github.com/carloshpdoc/memorydetective/compare/v1.1.0...HEAD
138
+ [Unreleased]: https://github.com/carloshpdoc/memorydetective/compare/v1.2.1...HEAD
139
+ [1.2.1]: https://github.com/carloshpdoc/memorydetective/compare/v1.2.0...v1.2.1
140
+ [1.2.0]: https://github.com/carloshpdoc/memorydetective/compare/v1.1.0...v1.2.0
101
141
  [1.1.0]: https://github.com/carloshpdoc/memorydetective/compare/v1.0.1...v1.1.0
102
142
  [1.0.1]: https://github.com/carloshpdoc/memorydetective/compare/v1.0.0...v1.0.1
103
143
  [1.0.0]: https://github.com/carloshpdoc/memorydetective/releases/tag/v1.0.0
package/README.md CHANGED
@@ -72,6 +72,40 @@ memorydetective classify ~/Desktop/myapp.memgraph
72
72
  > **Claude:** *(calls `listTraceDevices` → `recordTimeProfile` → `analyzeHangs`)*
73
73
  > Recorded `~/Desktop/run.trace` (90s, attached to DemoApp on iPhone 17 Pro Max). Found **23 user-visible hangs** (>500 ms each), longest 1.16 s, average 769 ms — severe load. All on the main thread. Sample-level hotspots aren't symbolicated yet; open the trace in Instruments for that step (or wait for `analyzeTimeProfile` v0.2).
74
74
 
75
+ ### End-to-end: leak → file → fix suggestion
76
+
77
+ The full loop, from artifact to code edit. Combines memory-graph analysis with Swift source-bridging.
78
+
79
+ > **You:** Tem um leak. Memgraph em `~/Desktop/example-leaks.memgraph`. The cycle points at `DetailViewModel`. Find where it lives in the project `~/Development/myapp/` and suggest a fix.
80
+ >
81
+ > **Claude:** *(calls `analyzeMemgraph` → `classifyCycle` → `reachableFromCycle`)*
82
+ > Found **4 ROOT CYCLE blocks**. The dominant one matches `swiftui.tag-index-projection` with high confidence. `reachableFromCycle` confirms 4 `DetailViewModel` instances pinning ~1100 `NSURLSessionConfiguration`s each — the VM is the culprit, the network stack is collateral.
83
+ >
84
+ > *(calls `swiftSearchPattern` to locate `.tag(` + `onImageSliderTap` patterns in `~/Development/myapp/Sources/`)*
85
+ > 1 match in `MyApp/Views/MediaCarousel.swift:142`.
86
+ >
87
+ > *(calls `swiftGetSymbolDefinition({ symbolName: "DetailViewModel", projectRoot: "...", candidatePaths: ["MyApp/ViewModels/"] })`)*
88
+ > Declared at `MyApp/ViewModels/DetailViewModel.swift:18` — `class DetailViewModel: ObservableObject`.
89
+ >
90
+ > *(calls `swiftFindSymbolReferences` to scope the blast radius — 7 callsites)*
91
+ >
92
+ > **Suggested fix at `MediaCarousel.swift:142`:**
93
+ > ```swift
94
+ > // before
95
+ > .tag(index)
96
+ > .onImageSliderTap { index in
97
+ > self.viewModel.handlePhotoTap(at: index)
98
+ > }
99
+ >
100
+ > // after — static helper + weak captures
101
+ > .tag(index)
102
+ > .onImageSliderTap { [weak vm = _viewModel.wrappedValue,
103
+ > weak coord = self.coordinator] index in
104
+ > Self.handlePhotoTap(index: index, viewModel: vm, coordinator: coord)
105
+ > }
106
+ > ```
107
+ > Want me to apply this and verify with a fresh `.memgraph`?
108
+
75
109
  ---
76
110
 
77
111
  ## Configure
@@ -177,7 +211,7 @@ Copilot's MCP integration moves fast — if this snippet is stale, see the [VS C
177
211
 
178
212
  ## API
179
213
 
180
- 20 MCP tools, grouped by purpose.
214
+ 25 MCP tools, grouped by purpose.
181
215
 
182
216
  ### Read & analyze (13)
183
217
 
@@ -224,6 +258,20 @@ Copilot's MCP integration moves fast — if this snippet is stale, see the [VS C
224
258
  |---|---|
225
259
  | `detectLeaksInXCUITest` | **Experimental.** Build the workspace for testing, run the named XCUITest, capture `.memgraph` baseline + after, diff. Returns `passed: false` when new ROOT CYCLEs appear that aren't in the user's allowlist. CI-runnable. |
226
260
 
261
+ ### Swift source bridging (5)
262
+
263
+ Pair the memory-graph diagnosis with source-code lookups via SourceKit-LSP. Closes the loop "found this leak in the cycle → find the file/line in your project".
264
+
265
+ | Tool | What |
266
+ |---|---|
267
+ | `swiftGetSymbolDefinition` | Locate the file:line where a Swift symbol is declared. Pre-scans `candidatePaths` (or `hint.filePath`) with a fast regex, then asks SourceKit-LSP for jump-to-definition. |
268
+ | `swiftFindSymbolReferences` | Find every reference to a Swift symbol via SourceKit-LSP `textDocument/references`. Requires an `IndexStoreDB` for cross-file results — the response carries a `needsIndex` hint when the index is missing. |
269
+ | `swiftGetSymbolsOverview` | List top-level symbols (classes, structs, enums, protocols, free functions) in a Swift file via `documentSymbol`. Cheap orientation when the agent lands in a new file. |
270
+ | `swiftGetHoverInfo` | Type info / docs at a (line, character) position. Disambiguates `self` captures: a class self in a closure can leak; a struct self can't. |
271
+ | `swiftSearchPattern` | Pure regex search over a Swift file (no LSP, no index). Catches what LSP misses: closure capture lists, `Task { ... self ... }` blocks, custom patterns from a leak chain. |
272
+
273
+ These tools require macOS + Xcode (full Xcode, not just Command Line Tools — `xcrun sourcekit-lsp` must be available). They start a `sourcekit-lsp` subprocess per project root and reuse it across calls; the subprocess shuts down after a 5-minute idle window.
274
+
227
275
  > **Why `captureMemgraph` doesn't work on physical iOS devices**: `leaks(1)` only attaches to processes running on the local Mac (which includes iOS simulators). Memory Graph capture from a real device goes through Xcode's debugger over USB/lockdownd — different mechanism, no public CLI equivalent.
228
276
 
229
277
  ### CLI mode
@@ -275,17 +323,6 @@ Contributions are welcome — bug reports, feature requests, new cycle patterns,
275
323
 
276
324
  In v0.2 the catalog moves to a separate repo so patterns can be added without modifying the server code.
277
325
 
278
- ### Working on the demo GIF
279
-
280
- The demo GIF is generated deterministically from `examples/demo.tape` via [vhs](https://github.com/charmbracelet/vhs):
281
-
282
- ```bash
283
- brew install vhs
284
- vhs examples/demo.tape
285
- ```
286
-
287
- The `.tape` file is committed; the `.gif` is regenerated from it. If you change the demo flow, please update both.
288
-
289
326
  ## Support this project
290
327
 
291
328
  If `memorydetective` saves you time, you can support continued development:
@@ -301,14 +338,6 @@ Apache 2.0 — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).
301
338
 
302
339
  Permits commercial use, modification, distribution, patent use. Includes attribution clause via the `NOTICE` file.
303
340
 
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.
309
-
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.
311
-
312
341
  ## Why "memorydetective"?
313
342
 
314
343
  Hunting retain cycles in SwiftUI feels like detective work: you have a body (the leaked instance), a crime scene (the `.memgraph`), and a chain of suspects (the retain chain). The tool helps you read the evidence and name the killer. The brand follows the work.
package/USAGE.md CHANGED
@@ -117,15 +117,18 @@ Claude orchestrates the full flow (see [section 3](#3-how-fixes-actually-flow-fr
117
117
 
118
118
  ## 3. How fixes actually flow from diagnosis to edit
119
119
 
120
- `memorydetective` is the **diagnose** side. It tells you **what** is wrong, **where in the cycle**, and **what type of fix** is needed. It does **not** edit your code.
120
+ `memorydetective` covers the diagnose side **and the source-bridging side**. It tells you **what** is wrong, **where in the cycle**, **what type of fix** is needed, **where the relevant types live in your project** (via Swift LSP integration), and **every callsite that references them**. It does not edit your code — that final step still belongs to your LLM agent.
121
121
 
122
- The **edit** side comes from your LLM agent (Claude Code, Cursor, Cline, …) using its native code-editing tools (Read, Grep, Edit, …).
122
+ So the workflow has two halves:
123
123
 
124
- This split is intentional:
124
+ | Half | Owned by `memorydetective` | Owned by the LLM agent |
125
+ |---|---|---|
126
+ | **Diagnose** | ✅ memgraph parsing, cycle classification, fix-hint catalog, hangs / allocations / app-launch / animation hitches | |
127
+ | **Locate in source** | ✅ `swiftGetSymbolDefinition`, `swiftFindSymbolReferences`, `swiftSearchPattern`, `swiftGetSymbolsOverview`, `swiftGetHoverInfo` (SourceKit-LSP under the hood) | |
128
+ | **Decide the actual edit** | | ✅ The agent reads the surrounding code, picks the right capture-list pattern, writes the diff |
129
+ | **Apply the edit** | | ✅ The agent's `Edit`/`MultiEdit` tools write to the user's file |
125
130
 
126
- - The fix depends on your real code (file paths, surrounding context, naming). `memorydetective` knows nothing about your codebase.
127
- - LLM agents already excel at code editing. Letting them keep that role keeps `memorydetective` focused.
128
- - The catalog of known patterns becomes the knowledge moat; the LLM brings the codebase awareness.
131
+ The split between "locate" (us) and "edit" (the agent) is intentional. Locating is a deterministic SourceKit-LSP query; editing requires understanding the user's surrounding code style, naming conventions, and intent — that's the LLM's strength. We give the agent every piece of structured information it needs to make the edit, and step back at the file-write boundary.
129
132
 
130
133
  ### Concrete end-to-end example
131
134
 
@@ -133,39 +136,45 @@ Configuration (one-time): `memorydetective` registered as an MCP server in Claud
133
136
 
134
137
  You open Claude Code in your iOS project and ask:
135
138
 
136
- > **You:** I exported `~/Desktop/myapp.memgraph` after closing some detail screens something is leaking. Diagnose and find where to fix in this codebase.
139
+ > **You:** Tem um leak. Memgraph em `~/Desktop/example-leaks.memgraph`. The cycle points at `DetailViewModel`. Find where it lives in the project `~/Development/myapp/` and suggest a fix.
137
140
 
138
141
  What Claude does, step by step:
139
142
 
140
- 1. **Calls `analyzeMemgraph(path: "~/Desktop/myapp.memgraph")`**
141
- - Receives: 60,436 leaks, 4 ROOT CYCLE blocks, top cycle is a `_DictionaryStorage` chain.
143
+ 1. **Calls `analyzeMemgraph(path)`**
144
+ - Receives: 60,436 leaks, 4 ROOT CYCLE blocks, top cycle is a `_DictionaryStorage` chain. App-level classes in chain: `DetailViewModel`, `GraphQLClient`, `ItemRepositoryImpl`.
145
+
146
+ 2. **Calls `classifyCycle(path)`**
147
+ - Receives: `swiftui.tag-index-projection` (high confidence) + fix hint pointing at `.tag()` modifier capturing `self`.
148
+
149
+ 3. **Calls `reachableFromCycle({ rootClassName: "DetailViewModel" })`**
150
+ - Confirms 4 `DetailViewModel` instances and ~1100 `NSURLSessionConfiguration`s reachable from each — the VM is the culprit pinning the network stack as collateral, not the other way around.
151
+
152
+ 4. **Calls `swiftSearchPattern({ pattern: "\\.tag\\(", filePath: "..." })` across views**
153
+ - Surfaces 1 match in `MyApp/Views/MediaCarousel.swift:142`.
142
154
 
143
- 2. **Calls `classifyCycle(path: "~/Desktop/myapp.memgraph")`**
144
- - Receives: pattern `swiftui.tag-index-projection` (high confidence) + fix hint about `.tag()` and weak capture.
155
+ 5. **Calls `swiftGetSymbolDefinition({ symbolName: "DetailViewModel", projectRoot: "~/Development/myapp/", candidatePaths: ["MyApp/ViewModels/"] })`**
156
+ - Returns `MyApp/ViewModels/DetailViewModel.swift:18` `class DetailViewModel: ObservableObject`.
145
157
 
146
- 3. **Uses its own code-editing tools to find the offending file:**
147
- - `Grep` for `.tag(` in your `*.swift` files.
148
- - `Grep` for `onImageSliderTap` (or whatever closure name surfaced in the chain).
149
- - `Read` the candidate files to see how the closure is captured.
158
+ 6. **Calls `swiftFindSymbolReferences({ symbolName: "DetailViewModel", filePath: "..." })`**
159
+ - Lists 7 callsites across the codebase. Helps the agent gauge fix blast radius.
150
160
 
151
- 4. **Presents the proposed fix in chat:**
161
+ 7. **Presents the proposed fix in chat:**
152
162
 
153
- > **Claude:** Found the cycle. `WishlistPlaceDetailsView.swift:142` passes `onImageSliderTap` as a closure that captures `self`. The `.tag(index)` modifier on the carousel `ForEach` is what triggers the SwiftUI internal `TagIndexProjection` observation that pins the cycle.
163
+ > **Claude:** Found the cycle. `MediaCarousel.swift:142` passes `onImageSliderTap` as a closure that captures `self`. The `.tag(index)` modifier on the carousel `ForEach` triggers the SwiftUI internal `TagIndexProjection` observation that pins `DetailViewModel`.
154
164
  >
155
- > Suggested fix: hoist the handler to a `static` function and capture only what's needed weakly:
165
+ > Suggested fix:
156
166
  > ```swift
157
167
  > // before
158
168
  > onImageSliderTap: { index in
159
169
  > self.viewModel.handlePhotoTap(at: index)
160
170
  > }
161
171
  >
162
- > // after
172
+ > // after — static helper + weak captures
163
173
  > onImageSliderTap: { [weak vm = _viewModel.wrappedValue,
164
174
  > weak coord = self.coordinator] index in
165
175
  > Self.handlePhotoTap(index: index, viewModel: vm, coordinator: coord)
166
176
  > }
167
177
  >
168
- > // plus a static helper:
169
178
  > private static func handlePhotoTap(
170
179
  > index: Int,
171
180
  > viewModel: DetailViewModel?,
@@ -175,11 +184,11 @@ What Claude does, step by step:
175
184
  >
176
185
  > Want me to apply this?
177
186
 
178
- 5. **You accept** → Claude calls its own `Edit` tool → diff appears in your IDE → you review and commit.
187
+ 8. **You accept** → Claude calls its own `Edit` tool → diff appears in your IDE → you review and commit.
179
188
 
180
- 6. **(Optional) Verify the fix:** export a fresh `.memgraph` after running the same flow, then ask Claude:
189
+ 9. **(Optional) Verify the fix:** export a fresh `.memgraph` after running the same flow, then ask Claude:
181
190
 
182
- > **You:** Did the fix work? Compare `~/Desktop/myapp-before.memgraph` to `~/Desktop/myapp-after.memgraph`.
191
+ > **You:** Did the fix work? Compare `~/Desktop/before.memgraph` to `~/Desktop/after.memgraph`.
183
192
 
184
193
  Claude calls `diffMemgraphs` — instance counts dropped, the `swiftui.tag-index-projection` cycle is gone from `cycles.persisted`, present in `cycles.goneFromBefore`.
185
194
 
@@ -202,12 +211,19 @@ Once you have the diagnosis, here are useful follow-up prompts you can paste int
202
211
  | Prompt | What Claude calls |
203
212
  |---|---|
204
213
  | "How many `DetailViewModel` instances are leaking?" | `countAlive(path, className: "DetailViewModel")` |
214
+ | "How many `NSURLSessionConfiguration`s are *inside* the cycle rooted at `DetailViewModel`?" | `reachableFromCycle(path, rootClassName: "DetailViewModel", className: "NSURLSessionConfiguration")` |
205
215
  | "Show the retain chain that keeps `DetailViewModel` alive." | `findRetainers(path, className: "DetailViewModel")` |
206
216
  | "Compare `~/Desktop/before.memgraph` to `~/Desktop/after.memgraph` — did the leak go away?" | `diffMemgraphs(before, after)` |
207
217
  | "Render the cycle as a Mermaid graph for the PR description." | `renderCycleGraph(path, format: "mermaid")` |
208
218
  | "Profile this app on my iPhone for 90 seconds and tell me about hangs." | `listTraceDevices` → `recordTimeProfile` → `analyzeHangs` |
209
219
  | "Pull the last 5 minutes of `error`-level logs from `MyApp`." | `logShow(last: "5m", process: "MyApp", level: "default")` |
210
220
  | "Run my XCUITest with leak detection." | `detectLeaksInXCUITest(workspace, scheme, testIdentifier, …)` |
221
+ | **Source bridging — combine with the memory tools above:** | |
222
+ | "Where is `DetailViewModel` declared in this project?" | `swiftGetSymbolDefinition(symbolName, candidatePaths)` |
223
+ | "Find every reference to `DetailViewModel` across the codebase." | `swiftFindSymbolReferences(symbolName, filePath)` |
224
+ | "What types live in `MediaCarousel.swift`?" | `swiftGetSymbolsOverview(filePath)` |
225
+ | "What's the type at this position in this file?" | `swiftGetHoverInfo(filePath, line, character)` |
226
+ | "Search for `[weak self]` captures in this file." | `swiftSearchPattern(filePath, pattern: "\\[weak self\\]")` |
211
227
 
212
228
  The agent decides which tool to call based on your prompt — you don't need to remember the tool names.
213
229
 
package/dist/cli.js CHANGED
@@ -25,7 +25,7 @@ const C = {
25
25
  cyan: "\x1b[36m",
26
26
  gray: "\x1b[90m",
27
27
  };
28
- const VERSION = "1.1.0";
28
+ const VERSION = "1.2.1";
29
29
  const HELP = `${C.bold}memorydetective${C.reset} — iOS leak hunting from the CLI
30
30
 
31
31
  ${C.dim}Usage:${C.reset}
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ import { renderCycleGraph, renderCycleGraphSchema, } from "./tools/renderCycleGr
20
20
  import { logShow, logShowSchema, logStream, logStreamSchema, } from "./tools/logShow.js";
21
21
  import { detectLeaksInXCUITest, detectLeaksInXCUITestSchema, } from "./tools/detectLeaksInXCUITest.js";
22
22
  import { reachableFromCycle, reachableFromCycleSchema, } from "./tools/reachableFromCycle.js";
23
+ import { swiftGetSymbolDefinition, swiftGetSymbolDefinitionSchema, swiftFindSymbolReferences, swiftFindSymbolReferencesSchema, swiftGetSymbolsOverview, swiftGetSymbolsOverviewSchema, swiftGetHoverInfo, swiftGetHoverInfoSchema, swiftSearchPattern, swiftSearchPatternSchema, } from "./tools/swift/index.js";
23
24
  const SERVER_NAME = "memorydetective";
24
25
  const SERVER_VERSION = "0.1.0-dev";
25
26
  const server = new McpServer({
@@ -222,6 +223,46 @@ server.registerTool("reachableFromCycle", {
222
223
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
223
224
  };
224
225
  });
226
+ server.registerTool("swiftGetSymbolDefinition", {
227
+ title: "Locate a Swift symbol's source declaration",
228
+ description: "Find the file:line where a Swift symbol (class, struct, enum, protocol, func, var, etc.) is declared. Pre-scans `candidatePaths` (or `hint.filePath`) with a fast regex first, then asks SourceKit-LSP for jump-to-definition. Returns the position even when LSP can't follow through. Use after `findRetainers` / `classifyCycle` surface a class name from a memgraph cycle to land in the actual source file.",
229
+ inputSchema: swiftGetSymbolDefinitionSchema.shape,
230
+ }, async (input) => {
231
+ const result = await swiftGetSymbolDefinition(input);
232
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
233
+ });
234
+ server.registerTool("swiftFindSymbolReferences", {
235
+ title: "Find every reference to a Swift symbol",
236
+ description: "Locates the symbol's declaration in `filePath`, then asks SourceKit-LSP for `textDocument/references`. Returns every callsite + capture across the project, with a snippet of each line. **Requires an IndexStoreDB** at `<projectRoot>/.build/index/store` for cross-file references — build it with `swift build -Xswiftc -index-store-path -Xswiftc <projectRoot>/.build/index/store`. The result includes a `needsIndex: true` hint when the index is missing.",
237
+ inputSchema: swiftFindSymbolReferencesSchema.shape,
238
+ }, async (input) => {
239
+ const result = await swiftFindSymbolReferences(input);
240
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
241
+ });
242
+ server.registerTool("swiftGetSymbolsOverview", {
243
+ title: "List top-level symbols in a Swift file",
244
+ description: "Cheap orientation: returns the top-level symbols (classes, structs, enums, protocols, free functions) declared in a Swift file via SourceKit-LSP's `documentSymbol`. Set `topLevelOnly: false` for nested children too. Useful right after `swiftGetSymbolDefinition` lands you in a new file.",
245
+ inputSchema: swiftGetSymbolsOverviewSchema.shape,
246
+ }, async (input) => {
247
+ const result = await swiftGetSymbolsOverview(input);
248
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
249
+ });
250
+ server.registerTool("swiftGetHoverInfo", {
251
+ title: "Get type info / docs at a Swift source position",
252
+ description: "SourceKit-LSP `textDocument/hover` at a (line, character) position. Returns the markdown / plaintext hover content plus a best-effort extracted declaration fragment. Use to disambiguate `self` captures: a class self in a closure can leak; a struct self can't.",
253
+ inputSchema: swiftGetHoverInfoSchema.shape,
254
+ }, async (input) => {
255
+ const result = await swiftGetHoverInfo(input);
256
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
257
+ });
258
+ server.registerTool("swiftSearchPattern", {
259
+ title: "Regex-search a Swift file (no LSP)",
260
+ description: "Pure regex search over a file's contents — no SourceKit-LSP, no IndexStoreDB. Catches what LSP misses: closure capture lists (`[weak self]`, `[unowned self]`), `Task { ... self ... }` blocks, and any other pattern the agent constructs from a leak chain. Returns matches with line/character positions and a trimmed snippet.",
261
+ inputSchema: swiftSearchPatternSchema.shape,
262
+ }, async (input) => {
263
+ const result = await swiftSearchPattern(input);
264
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
265
+ });
225
266
  async function main() {
226
267
  // CLI mode: when called with arguments, run the synchronous CLI wrapper.
227
268
  // 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,C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IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,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,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,sBAAs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ACF,CAAC;AAEF,KAAK,UAAU,IAAI;IACjB,yEAAyE;IACzE,sEAAsE;IACtE,sBAAsB;IACtB,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;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,37 @@
1
+ /**
2
+ * Persistent `sourcekit-lsp` subprocess client.
3
+ *
4
+ * One client per project root. Talks LSP over JSON-RPC stdio using
5
+ * `vscode-jsonrpc` for framing. Lifecycle:
6
+ *
7
+ * spawn -> initialize -> initialized -> [lots of requests] -> shutdown -> exit
8
+ *
9
+ * Used by the Swift source-bridging tools (`getSymbolDefinition`,
10
+ * `findSymbolReferences`, etc.). The pool (`./pool.ts`) keeps one client
11
+ * alive per project root and shuts it down after an idle window so we
12
+ * don't hold onto resources or stall builds.
13
+ */
14
+ export interface SourceKitClientOptions {
15
+ projectRoot: string;
16
+ /** Override the binary path. Defaults to `xcrun sourcekit-lsp`. */
17
+ command?: string;
18
+ args?: string[];
19
+ /** Initialization timeout, ms. Default 30s. */
20
+ initTimeoutMs?: number;
21
+ }
22
+ export interface InitializedClient {
23
+ projectRoot: string;
24
+ /** Send an arbitrary LSP request by method name. */
25
+ sendRequest<R = unknown>(method: string, params?: unknown): Promise<R>;
26
+ /** Send a notification (no response). */
27
+ sendNotification(method: string, params?: unknown): void;
28
+ /** Track a document as open with the server. Idempotent per uri. */
29
+ didOpen(filePath: string, languageId?: string): void;
30
+ /** Stop the server gracefully. Once called, the client cannot be reused. */
31
+ dispose(): Promise<void>;
32
+ }
33
+ /**
34
+ * Spawn `sourcekit-lsp`, drive the LSP handshake, and return a client
35
+ * that exposes typed request/notification helpers.
36
+ */
37
+ export declare function createSourceKitClient(opts: SourceKitClientOptions): Promise<InitializedClient>;
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Persistent `sourcekit-lsp` subprocess client.
3
+ *
4
+ * One client per project root. Talks LSP over JSON-RPC stdio using
5
+ * `vscode-jsonrpc` for framing. Lifecycle:
6
+ *
7
+ * spawn -> initialize -> initialized -> [lots of requests] -> shutdown -> exit
8
+ *
9
+ * Used by the Swift source-bridging tools (`getSymbolDefinition`,
10
+ * `findSymbolReferences`, etc.). The pool (`./pool.ts`) keeps one client
11
+ * alive per project root and shuts it down after an idle window so we
12
+ * don't hold onto resources or stall builds.
13
+ */
14
+ import { spawn } from "node:child_process";
15
+ import { resolve as resolvePath } from "node:path";
16
+ import { pathToFileURL } from "node:url";
17
+ import { createMessageConnection, StreamMessageReader, StreamMessageWriter, } from "vscode-jsonrpc/node.js";
18
+ const DEFAULT_INIT_TIMEOUT = 30_000;
19
+ /**
20
+ * Spawn `sourcekit-lsp`, drive the LSP handshake, and return a client
21
+ * that exposes typed request/notification helpers.
22
+ */
23
+ export async function createSourceKitClient(opts) {
24
+ const command = opts.command ?? "xcrun";
25
+ const args = opts.args ?? ["sourcekit-lsp"];
26
+ const projectRoot = resolvePath(opts.projectRoot);
27
+ const child = spawn(command, args, {
28
+ cwd: projectRoot,
29
+ stdio: ["pipe", "pipe", "pipe"],
30
+ });
31
+ const connection = createMessageConnection(new StreamMessageReader(child.stdout), new StreamMessageWriter(child.stdin));
32
+ // Forward stderr to our stderr so SourceKit warnings/errors are visible.
33
+ child.stderr.on("data", (chunk) => {
34
+ process.stderr.write(`[sourcekit-lsp] ${chunk.toString("utf8")}`);
35
+ });
36
+ let exited = false;
37
+ child.on("exit", () => {
38
+ exited = true;
39
+ });
40
+ connection.listen();
41
+ const projectUri = pathToFileURL(projectRoot).href;
42
+ const initTimeoutMs = opts.initTimeoutMs ?? DEFAULT_INIT_TIMEOUT;
43
+ await withTimeout(connection.sendRequest("initialize", {
44
+ processId: process.pid,
45
+ rootUri: projectUri,
46
+ workspaceFolders: [{ uri: projectUri, name: projectRoot }],
47
+ capabilities: {
48
+ textDocument: {
49
+ definition: { linkSupport: true },
50
+ references: {},
51
+ hover: { contentFormat: ["plaintext", "markdown"] },
52
+ documentSymbol: { hierarchicalDocumentSymbolSupport: true },
53
+ },
54
+ workspace: { workspaceFolders: true },
55
+ },
56
+ initializationOptions: {
57
+ // sourcekit-lsp picks up .build/index/store automatically when present.
58
+ },
59
+ }), initTimeoutMs, "sourcekit-lsp initialize");
60
+ connection.sendNotification("initialized", {});
61
+ const openDocs = { set: new Set() };
62
+ const client = {
63
+ projectRoot,
64
+ async sendRequest(method, params) {
65
+ if (exited)
66
+ throw new Error("sourcekit-lsp client has exited");
67
+ return await connection.sendRequest(method, params);
68
+ },
69
+ sendNotification(method, params) {
70
+ if (exited)
71
+ throw new Error("sourcekit-lsp client has exited");
72
+ connection.sendNotification(method, params);
73
+ },
74
+ didOpen(filePath, languageId = "swift") {
75
+ const uri = pathToFileURL(resolvePath(filePath)).href;
76
+ if (openDocs.set.has(uri))
77
+ return;
78
+ openDocs.set.add(uri);
79
+ // We don't ship the file's text here — sourcekit-lsp reads from disk
80
+ // when version === 1. This works for read-only operations
81
+ // (definition, references, hover, documentSymbol).
82
+ connection.sendNotification("textDocument/didOpen", {
83
+ textDocument: {
84
+ uri,
85
+ languageId,
86
+ version: 1,
87
+ text: "",
88
+ },
89
+ });
90
+ },
91
+ async dispose() {
92
+ if (exited)
93
+ return;
94
+ try {
95
+ await withTimeout(connection.sendRequest("shutdown"), 5_000, "sourcekit-lsp shutdown");
96
+ connection.sendNotification("exit");
97
+ }
98
+ catch {
99
+ // best effort — kill the process if shutdown didn't complete
100
+ }
101
+ try {
102
+ connection.dispose();
103
+ }
104
+ catch { }
105
+ if (!exited) {
106
+ child.kill("SIGTERM");
107
+ // Give it a moment to die gracefully, then SIGKILL.
108
+ await new Promise((resolve) => {
109
+ const t = setTimeout(() => {
110
+ try {
111
+ child.kill("SIGKILL");
112
+ }
113
+ catch { }
114
+ resolve();
115
+ }, 2_000);
116
+ child.once("exit", () => {
117
+ clearTimeout(t);
118
+ resolve();
119
+ });
120
+ });
121
+ }
122
+ },
123
+ };
124
+ return client;
125
+ }
126
+ async function withTimeout(p, ms, label) {
127
+ return await Promise.race([
128
+ Promise.resolve(p),
129
+ new Promise((_, reject) => setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms)),
130
+ ]);
131
+ }
132
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/runtime/sourcekit/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,KAAK,EAAuC,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,wBAAwB,CAAC;AAuBhC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAMpC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,CA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,CAAe,CAAC;QAChC,IAAI,OAAO,CAAI,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAC3B,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAC5E;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Pool of `sourcekit-lsp` clients, keyed by project root.
3
+ *
4
+ * Why a pool: starting `sourcekit-lsp` and waiting for it to be ready costs
5
+ * ~2 seconds. Doing that on every tool call would kill the agent loop.
6
+ * Instead we keep one client alive per project root and reuse it across
7
+ * tool invocations. After an idle window we shut it down so we're not
8
+ * blocking the user's build/test pipeline.
9
+ */
10
+ import { type InitializedClient } from "./client.js";
11
+ /** Resolve a file path to its enclosing project root by walking up to the
12
+ * nearest `Package.swift`, `*.xcodeproj`, or `*.xcworkspace`. Falls back
13
+ * to the file's directory if nothing is found. */
14
+ export declare function projectRootFor(filePath: string): string;
15
+ export interface AcquireOptions {
16
+ /** Override idle shutdown window, ms. Default 5min. */
17
+ idleMs?: number;
18
+ }
19
+ /** Acquire an LSP client for a project root. Reuses an existing one if
20
+ * warm, spawns + initializes one otherwise. */
21
+ export declare function acquireClient(projectRoot: string, opts?: AcquireOptions): Promise<InitializedClient>;
22
+ /** Manually shut down the client for a given project root. */
23
+ export declare function shutdownClient(projectRoot: string): Promise<void>;
24
+ /** Shut down all pooled clients. Useful in tests + on process exit. */
25
+ export declare function shutdownAll(): Promise<void>;