memtrace 0.1.2-2.5

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.
@@ -0,0 +1,108 @@
1
+ ---
2
+ name: memtrace-codebase-exploration
3
+ description: "Use when the user asks to explore a codebase, understand a project, onboard to a new repo, get an overview of how code is structured, map the architecture, or wants a comprehensive understanding of a codebase they're new to"
4
+ allowed-tools:
5
+ - mcp__memtrace__index_directory
6
+ - mcp__memtrace__check_job_status
7
+ - mcp__memtrace__list_indexed_repositories
8
+ - mcp__memtrace__get_repository_stats
9
+ - mcp__memtrace__list_communities
10
+ - mcp__memtrace__list_processes
11
+ - mcp__memtrace__find_central_symbols
12
+ - mcp__memtrace__find_bridge_symbols
13
+ - mcp__memtrace__find_api_endpoints
14
+ - mcp__memtrace__get_api_topology
15
+ - mcp__memtrace__get_evolution
16
+ - mcp__memtrace__find_most_complex_functions
17
+ user-invocable: true
18
+ ---
19
+
20
+ ## Overview
21
+
22
+ Full codebase exploration workflow — from indexing through architectural understanding. Chains indexing, graph algorithms, community detection, and temporal analysis into a structured onboarding experience. Use this when someone is new to a codebase and needs to build a mental model.
23
+
24
+ ## Steps
25
+
26
+ ### 1. Index the codebase
27
+
28
+ Call `list_indexed_repositories` first. If the repo is already indexed, skip to step 2.
29
+
30
+ Otherwise, call `index_directory` with the project path, then poll `check_job_status` until completion.
31
+
32
+ **Success criteria:** Repo appears in `list_indexed_repositories` with non-zero node/edge counts.
33
+
34
+ ### 2. Get the lay of the land
35
+
36
+ Call `get_repository_stats` to understand scale:
37
+ - How many functions, classes, methods, interfaces?
38
+ - How many relationships (calls, imports, extends)?
39
+ - How many communities and processes were detected?
40
+
41
+ Report these numbers to the user — they set expectations for the codebase's size and complexity.
42
+
43
+ ### 3. Map the architecture (communities)
44
+
45
+ Call `list_communities` to see how the codebase naturally clusters into logical modules.
46
+
47
+ **Decision:** If >10 communities, summarize the top 5–7 by size and let the user ask about specific ones.
48
+
49
+ Each community represents a cohesive module — these are the "areas" of the codebase.
50
+
51
+ ### 4. Find the most important symbols
52
+
53
+ Call `find_central_symbols` with `method: "pagerank"` and `limit: 15`.
54
+
55
+ These are the symbols that the rest of the codebase depends on most heavily. They form the "skeleton" of the architecture.
56
+
57
+ ### 5. Find architectural bottlenecks
58
+
59
+ Call `find_bridge_symbols` to identify chokepoints — symbols that connect otherwise-separate parts of the codebase.
60
+
61
+ **Decision:** If bridge symbols overlap heavily with central symbols, flag them as critical infrastructure — high importance AND single point of failure.
62
+
63
+ ### 6. Map execution flows
64
+
65
+ Call `list_processes` to discover entry points:
66
+ - HTTP handlers (API endpoints)
67
+ - Background jobs
68
+ - CLI commands
69
+ - Event handlers
70
+
71
+ This shows HOW the code is actually used at runtime, not just how it's structured.
72
+
73
+ ### 7. Map the API surface (if applicable)
74
+
75
+ Call `find_api_endpoints` to list all HTTP routes.
76
+
77
+ **Decision:** If multiple repos are indexed, also call `get_api_topology` to map service-to-service dependencies.
78
+
79
+ ### 8. Recent activity
80
+
81
+ Call `get_evolution` with mode `overview` and a 30-day window to see which modules have been most active recently.
82
+
83
+ **Decision:** If the user asks about specific recent changes, switch to mode `compound` for symbol-level detail.
84
+
85
+ ### 9. Complexity hotspots
86
+
87
+ Call `find_most_complex_functions` with `limit: 10` to identify potential technical debt.
88
+
89
+ ## Report Synthesis
90
+
91
+ Synthesize findings into a structured overview:
92
+
93
+ 1. **Scale** — languages, total symbols, total relationships
94
+ 2. **Architecture** — main communities/modules and what they do
95
+ 3. **Critical Infrastructure** — central symbols and bridge points
96
+ 4. **Execution Flows** — how the code is entered and used
97
+ 5. **API Surface** — endpoints and service dependencies
98
+ 6. **Recent Activity** — what's been changing in the last 30 days
99
+ 7. **Technical Debt** — complexity hotspots and potential dead code
100
+
101
+ ## Common Mistakes
102
+
103
+ | Mistake | Reality |
104
+ |---------|---------|
105
+ | Skipping indexing and using file-based grep | The knowledge graph provides structural understanding that grep cannot — callers, callees, communities, processes |
106
+ | Reporting raw numbers without interpretation | "450 functions across 12 communities" means nothing; describe what each community does |
107
+ | Only looking at code structure | Execution flows (processes) show how the code is actually used — always include them |
108
+ | Ignoring temporal context | Recent evolution shows where active development is happening — this is where the user will likely need to work |
@@ -0,0 +1,104 @@
1
+ ---
2
+ name: memtrace-incident-investigation
3
+ description: "Use when the user is investigating a bug, incident, production issue, regression, something that broke, root cause analysis, debugging a failure, or trying to figure out what went wrong and when"
4
+ allowed-tools:
5
+ - mcp__memtrace__get_evolution
6
+ - mcp__memtrace__get_timeline
7
+ - mcp__memtrace__detect_changes
8
+ - mcp__memtrace__get_impact
9
+ - mcp__memtrace__get_symbol_context
10
+ - mcp__memtrace__find_code
11
+ - mcp__memtrace__find_symbol
12
+ - mcp__memtrace__analyze_relationships
13
+ - mcp__memtrace__list_indexed_repositories
14
+ user-invocable: true
15
+ ---
16
+
17
+ ## Overview
18
+
19
+ Root cause investigation workflow for incidents, regressions, and production issues. Uses temporal analysis with the `recent` scoring mode to surface changes closest to the incident time, then traces blast radius and execution flows to identify the likely cause.
20
+
21
+ ## Steps
22
+
23
+ ### 1. Establish the timeline
24
+
25
+ Determine:
26
+ - **Incident time** — when did the problem start? (This becomes the `to` parameter)
27
+ - **Lookback window** — how far back to search? Start with 24 hours, expand if needed.
28
+ - **Repo(s)** — which services are affected? Call `list_indexed_repositories` to get repo_ids.
29
+
30
+ ### 2. Surface recent changes near the incident
31
+
32
+ Call `get_evolution` with:
33
+ - `mode: "recent"` — temporal proximity weighting: `impact × exp(−0.5 × Δhours)`
34
+ - `from` — lookback start (e.g., 24 hours before incident)
35
+ - `to` — the incident timestamp
36
+ - `repo_id` — the affected repo
37
+
38
+ **Why `recent` mode?** It exponentially amplifies changes close to the incident time while still weighting by structural impact. A high-impact change made 1 hour before the incident scores much higher than the same change made 20 hours before.
39
+
40
+ **Success criteria:** A ranked list of changes, with the most likely culprits at the top.
41
+
42
+ ### 3. Check for unexpected changes
43
+
44
+ Call `get_evolution` again with `mode: "novel"` on the same time window:
45
+ - Flags changes to rarely-modified code (high in_degree, low change frequency)
46
+ - A core utility that hasn't changed in 90 days suddenly changing near an incident is a strong signal
47
+
48
+ **Decision:** If `novel` mode surfaces different symbols than `recent` mode, investigate both — the root cause may be an unexpected change to stable infrastructure.
49
+
50
+ ### 4. Trace the blast radius of top suspects
51
+
52
+ For the top 3–5 symbols from steps 2–3, call `get_impact` with `direction: upstream`:
53
+ - How many downstream consumers were affected?
54
+ - What execution flows pass through this symbol?
55
+
56
+ **Decision:** Prioritize symbols where the blast radius overlaps with the reported failure area.
57
+
58
+ ### 5. Trace execution flows
59
+
60
+ Use `get_symbol_context` on the top suspects to see which processes (HTTP handlers, background jobs, etc.) they participate in.
61
+
62
+ **Decision:** If the incident is in a specific endpoint/flow, focus on suspects that are members of that process.
63
+
64
+ ### 6. Build the full timeline for the suspect
65
+
66
+ Once you have a primary suspect, call `get_timeline` with the symbol name to see its full version history:
67
+ - What changed in each commit?
68
+ - When was the last "stable" version?
69
+ - Was the change a modification, or was it newly added?
70
+
71
+ ### 7. Correlate with surrounding changes
72
+
73
+ Call `get_evolution` with mode `directional` to separate:
74
+ - **Added symbols** — new code introduced (potential new bugs)
75
+ - **Removed symbols** — deleted code (potential missing functionality)
76
+ - **Modified symbols** — changed behaviour (potential regressions)
77
+
78
+ ## Report: Root Cause Analysis
79
+
80
+ 1. **Incident Timeline** — when it started, what was observed
81
+ 2. **Most Likely Cause** — the top-ranked change(s) by `recent` mode with blast radius confirmation
82
+ 3. **Supporting Evidence** — novelty signal (was this an unexpected change?), blast radius overlap with failure area, process membership overlap
83
+ 4. **Change History** — full timeline of the suspect symbol
84
+ 5. **Affected Scope** — all processes and downstream consumers impacted
85
+ 6. **Remediation** — revert the change, fix forward, or mitigate
86
+
87
+ ## Algorithm Selection Guide for Incidents
88
+
89
+ | Phase | Mode | Why |
90
+ |-------|------|-----|
91
+ | Initial triage | `recent` | Time-weighted ranking surfaces changes near the incident |
92
+ | Anomaly detection | `novel` | Catches unexpected changes to stable code |
93
+ | Scope assessment | `impact` | Ranks by structural significance (blast radius) |
94
+ | Direction analysis | `directional` | Separates added/removed/modified |
95
+ | Quick summary | `overview` | Fast module-level scan before deep-diving |
96
+
97
+ ## Common Mistakes
98
+
99
+ | Mistake | Reality |
100
+ |---------|---------|
101
+ | Starting with `impact` mode | Use `recent` first — time proximity is the strongest signal for incidents |
102
+ | Only looking at the most recent commit | The root cause may be from an earlier change whose effects were delayed |
103
+ | Ignoring `novel` mode | Unexpected changes to stable code are often the root cause |
104
+ | Not checking blast radius overlap | A change is only a suspect if its blast radius reaches the failure area |
@@ -0,0 +1,116 @@
1
+ ---
2
+ name: memtrace-refactoring-guide
3
+ description: "Use when the user wants to refactor code, reduce complexity, clean up technical debt, split a large function, extract a module, reorganize code, identify refactoring priorities, or improve code structure"
4
+ allowed-tools:
5
+ - mcp__memtrace__find_most_complex_functions
6
+ - mcp__memtrace__find_dead_code
7
+ - mcp__memtrace__find_bridge_symbols
8
+ - mcp__memtrace__find_central_symbols
9
+ - mcp__memtrace__get_symbol_context
10
+ - mcp__memtrace__get_impact
11
+ - mcp__memtrace__get_evolution
12
+ - mcp__memtrace__analyze_relationships
13
+ - mcp__memtrace__list_communities
14
+ - mcp__memtrace__calculate_cyclomatic_complexity
15
+ - mcp__memtrace__list_indexed_repositories
16
+ user-invocable: true
17
+ ---
18
+
19
+ ## Overview
20
+
21
+ Guided refactoring workflow — identifies refactoring candidates using structural analysis, scores them by risk and priority, and produces a phased refactoring plan. Combines complexity metrics, dead code detection, bridge analysis, and temporal evolution to prioritize what to refactor first and how to do it safely.
22
+
23
+ ## Steps
24
+
25
+ ### 1. Identify refactoring candidates
26
+
27
+ Run these three tools in parallel to build a candidate list:
28
+
29
+ **a) Complexity hotspots:**
30
+ Call `find_most_complex_functions` with `limit: 20`
31
+
32
+ **b) Dead code:**
33
+ Call `find_dead_code` to find unused symbols
34
+
35
+ **c) Architectural bottlenecks:**
36
+ Call `find_bridge_symbols` to find chokepoints with too much responsibility
37
+
38
+ ### 2. Score candidates by volatility
39
+
40
+ Call `get_evolution` with mode `compound` over a 90-day window:
41
+ - Symbols that are BOTH complex AND frequently changing are the highest priority
42
+ - Complex but stable code can wait — it's not causing active pain
43
+ - Volatile but simple code may be fine — frequent changes to simple code is normal
44
+
45
+ **Priority matrix:**
46
+
47
+ | | Low Complexity | High Complexity |
48
+ |---|---|---|
49
+ | **Stable (low change freq)** | Leave alone | Monitor; refactor if touched |
50
+ | **Volatile (high change freq)** | Normal; leave alone | **TOP PRIORITY** — refactor first |
51
+
52
+ ### 3. Assess risk for top candidates
53
+
54
+ For each top-priority candidate, call `get_impact` with `direction: both`:
55
+ - **Low risk** → refactor directly
56
+ - **Medium risk** → refactor with comprehensive tests
57
+ - **High/Critical risk** → plan incremental migration with backward compatibility
58
+
59
+ Also call `get_symbol_context` to check:
60
+ - How many processes does this symbol participate in? (More = more testing needed)
61
+ - Is it part of a cross-repo API? (If yes, coordinate with consumers)
62
+
63
+ ### 4. Understand the neighbourhood
64
+
65
+ For each refactoring target, call `analyze_relationships`:
66
+ - `find_callees` — what does it depend on? (these become candidates for extraction)
67
+ - `find_callers` — what depends on it? (these need updating after refactoring)
68
+ - `class_hierarchy` — is it part of an inheritance chain? (Liskov concerns)
69
+
70
+ ### 5. Check community boundaries
71
+
72
+ Call `list_communities` and check: does the refactoring target sit at a community boundary?
73
+ - If yes, the refactoring may involve splitting responsibilities across modules
74
+ - If it belongs clearly to one community, the refactoring is more contained
75
+
76
+ ### 6. Produce the refactoring plan
77
+
78
+ Synthesize into a phased plan:
79
+
80
+ **Phase 1 — Quick Wins:**
81
+ - Dead code removal (zero-risk deletions)
82
+ - Simple functions with high churn (reduce volatility)
83
+
84
+ **Phase 2 — High-Impact Refactors:**
85
+ - Complex + volatile functions (highest priority by the matrix)
86
+ - Bridge symbols with too many responsibilities (extract interfaces)
87
+
88
+ **Phase 3 — Structural Improvements:**
89
+ - Splitting oversized communities into smaller, focused modules
90
+ - Extracting shared logic from bridge symbols into dedicated services
91
+
92
+ For each item, include:
93
+ 1. **Target** — function/class name, file, current complexity score
94
+ 2. **Why** — complexity + volatility + blast radius rationale
95
+ 3. **How** — specific refactoring approach (extract method, split class, introduce interface)
96
+ 4. **Risk** — impact analysis rating + affected processes
97
+ 5. **Test Plan** — which callers/processes to verify
98
+
99
+ ## Decision Points
100
+
101
+ | Condition | Action |
102
+ |-----------|--------|
103
+ | Complex + volatile + high blast radius | Highest priority — but plan carefully; incremental approach |
104
+ | Complex + stable + low blast radius | Can wait; refactor when you're already touching nearby code |
105
+ | Dead code with zero callers | Safe to delete — quick win |
106
+ | Bridge symbol with many dependents | Extract interface first, then refactor implementation behind it |
107
+ | Symbol in cross-repo API | Coordinate with consumers; backward-compatible changes only |
108
+
109
+ ## Common Mistakes
110
+
111
+ | Mistake | Reality |
112
+ |---------|---------|
113
+ | Refactoring the most complex function first | Complexity alone isn't enough — prioritize by complexity × volatility |
114
+ | Deleting all dead code at once | Some "dead" code is called dynamically; verify before batch deletion |
115
+ | Refactoring without checking blast radius | A "simple" refactor on a bridge symbol can cascade across the codebase |
116
+ | Not checking temporal evolution | A complex function that hasn't changed in a year is lower priority than a simpler one that changes weekly |