memtrace 0.1.37 → 0.1.45
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/README.md +2 -2
- package/bin/memtrace.js +102 -14
- package/install.js +21 -179
- package/installer/dist/commands/doctor.d.ts +16 -0
- package/installer/dist/commands/doctor.js +86 -0
- package/installer/dist/commands/install.d.ts +9 -0
- package/installer/dist/commands/install.js +104 -0
- package/installer/dist/commands/picker.d.ts +6 -0
- package/installer/dist/commands/picker.js +22 -0
- package/installer/dist/fs-safe.d.ts +21 -0
- package/installer/dist/fs-safe.js +35 -0
- package/installer/dist/index.d.ts +2 -0
- package/installer/dist/index.js +52 -0
- package/installer/dist/skills.d.ts +17 -0
- package/installer/dist/skills.js +64 -0
- package/installer/dist/transformers/claude.d.ts +41 -0
- package/installer/dist/transformers/claude.js +400 -0
- package/installer/dist/transformers/cursor.d.ts +7 -0
- package/installer/dist/transformers/cursor.js +84 -0
- package/installer/dist/transformers/index.d.ts +7 -0
- package/installer/dist/transformers/index.js +7 -0
- package/installer/dist/transformers/types.d.ts +39 -0
- package/installer/dist/transformers/types.js +1 -0
- package/installer/dist/utils.d.ts +5 -0
- package/installer/dist/utils.js +22 -0
- package/installer/package.json +49 -0
- package/installer/skills/commands/memtrace-api-topology.md +65 -0
- package/installer/skills/commands/memtrace-cochange.md +76 -0
- package/installer/skills/commands/memtrace-evolution.md +135 -0
- package/installer/skills/commands/memtrace-graph.md +117 -0
- package/installer/skills/commands/memtrace-impact.md +64 -0
- package/installer/skills/commands/memtrace-index.md +66 -0
- package/installer/skills/commands/memtrace-quality.md +69 -0
- package/installer/skills/commands/memtrace-relationships.md +73 -0
- package/installer/skills/commands/memtrace-search.md +67 -0
- package/installer/skills/workflows/memtrace-change-impact-analysis.md +85 -0
- package/installer/skills/workflows/memtrace-codebase-exploration.md +108 -0
- package/installer/skills/workflows/memtrace-episode-replay.md +100 -0
- package/installer/skills/workflows/memtrace-first.md +120 -0
- package/installer/skills/workflows/memtrace-incident-investigation.md +125 -0
- package/installer/skills/workflows/memtrace-refactoring-guide.md +116 -0
- package/installer/skills/workflows/memtrace-session-continuity.md +98 -0
- package/package.json +10 -5
- package/skills/commands/memtrace-api-topology.md +3 -0
- package/skills/commands/memtrace-cochange.md +3 -0
- package/skills/commands/memtrace-evolution.md +3 -0
- package/skills/commands/memtrace-graph.md +54 -4
- package/skills/commands/memtrace-impact.md +3 -0
- package/skills/commands/memtrace-index.md +3 -0
- package/skills/commands/memtrace-quality.md +3 -0
- package/skills/commands/memtrace-relationships.md +3 -0
- package/skills/commands/memtrace-search.md +18 -13
- package/skills/workflows/memtrace-first.md +12 -0
- package/uninstall.js +22 -28
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memtrace-first
|
|
3
|
+
description: "Use when working on any indexed codebase before searching files, reading code, debugging issues, tracing call flows, finding implementations, understanding behavior, or answering 'how does X work' questions. Triggered by: file search, symbol lookup, code navigation, debugging, tracing, understanding architecture, finding where something is defined or called."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Memtrace First
|
|
7
|
+
|
|
8
|
+
## The Iron Law
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
IF THE REPO IS INDEXED IN MEMTRACE → USE MEMTRACE TOOLS FIRST.
|
|
12
|
+
NEVER reach for Grep/Glob/Read to discover or understand code.
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Memtrace is the memory layer of the codebase. It has the full knowledge graph: every symbol, call, import, community, process, and API — with time dimension. File tools are blind to this structure.
|
|
16
|
+
|
|
17
|
+
**97% better accuracy. 83% fewer wasted tokens. No exceptions.**
|
|
18
|
+
|
|
19
|
+
## Parameter Types — Read This Before Calling Any Tool
|
|
20
|
+
|
|
21
|
+
All memtrace MCP tools are **strictly typed**. Pass JSON numbers (not strings) for integer parameters.
|
|
22
|
+
|
|
23
|
+
| Parameter | Correct | WRONG (fails with MCP error -32602) |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `limit`, `min_size`, `depth`, `max_depth`, `last_n` | `limit: 20` | `limit: "20"` |
|
|
26
|
+
| `repo_id`, `branch`, `name`, `symbol_name`, `query` | `repo_id: "my-repo"` | `repo_id: my-repo` (unquoted) |
|
|
27
|
+
| `fuzzy`, `include_tests`, `invalidate` | `fuzzy: true` | `fuzzy: "true"` |
|
|
28
|
+
|
|
29
|
+
If you see `failed to deserialize parameters: invalid type: string "N", expected usize`, remove the quotes from the number and retry.
|
|
30
|
+
|
|
31
|
+
## Check Indexing First (Once Per Session)
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
mcp__memtrace__list_indexed_repositories
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
If the current repo appears → Memtrace is active. Follow this skill for ALL code tasks.
|
|
38
|
+
If not indexed → offer to index with `mcp__memtrace__index_directory`, then follow this skill.
|
|
39
|
+
|
|
40
|
+
## Task → Tool Map
|
|
41
|
+
|
|
42
|
+
| What you need | Use instead of Grep/Glob/Read |
|
|
43
|
+
|---|---|
|
|
44
|
+
| Find a function / class / symbol | `find_symbol` or `find_code` |
|
|
45
|
+
| Understand how something works | `get_symbol_context` |
|
|
46
|
+
| Find all callers of a function | `get_symbol_context` (callers field) |
|
|
47
|
+
| Find all callees / dependencies | `get_symbol_context` (callees field) |
|
|
48
|
+
| Trace a request / execution path | `get_process_flow` |
|
|
49
|
+
| Understand module structure | `list_communities` |
|
|
50
|
+
| Find the most important symbols | `find_central_symbols` |
|
|
51
|
+
| Find API endpoints | `find_api_endpoints` |
|
|
52
|
+
| Find where an API is called | `find_api_calls` |
|
|
53
|
+
| Debug a problem | `get_symbol_context` → `get_impact` → `get_evolution` |
|
|
54
|
+
| What changed recently? | `get_changes_since` or `get_evolution` |
|
|
55
|
+
| What breaks if I change X? | `get_impact` |
|
|
56
|
+
| Cross-service / cross-repo calls | `get_service_diagram` or `get_api_topology` |
|
|
57
|
+
| Dependency between two symbols | `find_dependency_path` |
|
|
58
|
+
| What files change together? | `get_cochange_context` |
|
|
59
|
+
| Architecture overview | `list_communities` + `find_central_symbols` |
|
|
60
|
+
|
|
61
|
+
## Standard Workflows
|
|
62
|
+
|
|
63
|
+
### "How does X work?" / "Explain X"
|
|
64
|
+
1. `find_symbol` or `find_code` → locate the symbol
|
|
65
|
+
2. `get_symbol_context` → callers, callees, community, processes
|
|
66
|
+
3. `get_process_flow` (if it's a process/request path)
|
|
67
|
+
4. Read source ONLY for the exact lines you need to quote
|
|
68
|
+
|
|
69
|
+
### Debugging "X is broken"
|
|
70
|
+
1. `find_symbol` → locate the broken thing
|
|
71
|
+
2. `get_symbol_context` → understand its role
|
|
72
|
+
3. `get_impact` → blast radius (what else breaks)
|
|
73
|
+
4. `get_evolution` → what changed recently (mode: `recent`)
|
|
74
|
+
5. `get_changes_since` → confirm timing vs incident
|
|
75
|
+
|
|
76
|
+
### "Where is X defined / called?"
|
|
77
|
+
1. `find_symbol` with `fuzzy: true`
|
|
78
|
+
2. `get_symbol_context` for full caller/callee map
|
|
79
|
+
3. Read specific file only after locating exact line
|
|
80
|
+
|
|
81
|
+
### Before any code modification
|
|
82
|
+
1. `find_symbol` → confirm you have the right target
|
|
83
|
+
2. `get_symbol_context` → understand full context
|
|
84
|
+
3. `get_impact` → know blast radius before touching anything
|
|
85
|
+
|
|
86
|
+
## Red Flags — STOP, Use Memtrace Instead
|
|
87
|
+
|
|
88
|
+
You are violating this skill if you think:
|
|
89
|
+
|
|
90
|
+
| Thought | Reality |
|
|
91
|
+
|---|---|
|
|
92
|
+
| "Let me grep for this" | `find_code` or `find_symbol` is faster and structurally aware |
|
|
93
|
+
| "Let me glob for the file" | `find_symbol` returns exact location with context |
|
|
94
|
+
| "Let me read the whole file" | `get_symbol_context` gives you only what matters |
|
|
95
|
+
| "It's just a quick search" | Grep has no understanding of call graphs, communities, or time |
|
|
96
|
+
| "I don't know if it's indexed" | Check with `list_indexed_repositories` first — takes 1 second |
|
|
97
|
+
| "The user didn't say to use Memtrace" | User asked about the code. Repo is indexed. Use Memtrace. |
|
|
98
|
+
| "This is a simple question" | Simple questions benefit most — one `find_symbol` vs 20 file reads |
|
|
99
|
+
|
|
100
|
+
## When File Tools Are Still Correct
|
|
101
|
+
|
|
102
|
+
Use Grep/Glob/Read ONLY for:
|
|
103
|
+
- Reading the **exact source lines** of a symbol you already located via Memtrace
|
|
104
|
+
- Files that are config, data, or docs (not source code symbols)
|
|
105
|
+
- Repos confirmed NOT indexed in Memtrace
|
|
106
|
+
|
|
107
|
+
Never use file tools as a **discovery** mechanism when Memtrace is available.
|
|
108
|
+
|
|
109
|
+
## Skill Priority
|
|
110
|
+
|
|
111
|
+
This skill is a **process skill** — it runs BEFORE any implementation or search skill.
|
|
112
|
+
|
|
113
|
+
When this skill applies, it overrides default file-search behavior. Use the specific Memtrace sub-skills for deep detail on each tool:
|
|
114
|
+
|
|
115
|
+
- Discovery → `memtrace-search`
|
|
116
|
+
- Impact analysis → `memtrace-impact`
|
|
117
|
+
- Temporal / change analysis → `memtrace-evolution`
|
|
118
|
+
- Incident investigation → `memtrace-incident-investigation`
|
|
119
|
+
- Architecture overview → `memtrace-codebase-exploration`
|
|
120
|
+
- Refactoring → `memtrace-refactoring-guide`
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
- mcp__memtrace__get_cochange_context
|
|
15
|
+
- mcp__memtrace__get_episode_replay
|
|
16
|
+
user-invocable: true
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
## Steps
|
|
24
|
+
|
|
25
|
+
### 1. Establish the timeline
|
|
26
|
+
|
|
27
|
+
Determine:
|
|
28
|
+
- **Incident time** — when did the problem start? (This becomes the `to` parameter)
|
|
29
|
+
- **Lookback window** — how far back to search? Start with 24 hours, expand if needed.
|
|
30
|
+
- **Repo(s)** — which services are affected? Call `list_indexed_repositories` to get repo_ids.
|
|
31
|
+
|
|
32
|
+
### 2. Surface recent changes near the incident
|
|
33
|
+
|
|
34
|
+
Call `get_evolution` with:
|
|
35
|
+
- `mode: "recent"` — temporal proximity weighting: `impact × exp(−0.5 × Δhours)`
|
|
36
|
+
- `from` — lookback start (e.g., 24 hours before incident)
|
|
37
|
+
- `to` — the incident timestamp
|
|
38
|
+
- `repo_id` — the affected repo
|
|
39
|
+
|
|
40
|
+
**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.
|
|
41
|
+
|
|
42
|
+
**Success criteria:** A ranked list of changes, with the most likely culprits at the top.
|
|
43
|
+
|
|
44
|
+
### 3. Check for unexpected changes
|
|
45
|
+
|
|
46
|
+
Call `get_evolution` again with `mode: "novel"` on the same time window:
|
|
47
|
+
- Flags changes to rarely-modified code (high in_degree, low change frequency)
|
|
48
|
+
- A core utility that hasn't changed in 90 days suddenly changing near an incident is a strong signal
|
|
49
|
+
|
|
50
|
+
**Decision:** If `novel` mode surfaces different symbols than `recent` mode, investigate both — the root cause may be an unexpected change to stable infrastructure.
|
|
51
|
+
|
|
52
|
+
### 4. Trace the blast radius of top suspects
|
|
53
|
+
|
|
54
|
+
For the top 3–5 symbols from steps 2–3, call `get_impact` with `direction: upstream`:
|
|
55
|
+
- How many downstream consumers were affected?
|
|
56
|
+
- What execution flows pass through this symbol?
|
|
57
|
+
|
|
58
|
+
**Decision:** Prioritize symbols where the blast radius overlaps with the reported failure area.
|
|
59
|
+
|
|
60
|
+
### 5. Trace execution flows
|
|
61
|
+
|
|
62
|
+
Use `get_symbol_context` on the top suspects to see which processes (HTTP handlers, background jobs, etc.) they participate in.
|
|
63
|
+
|
|
64
|
+
**Decision:** If the incident is in a specific endpoint/flow, focus on suspects that are members of that process.
|
|
65
|
+
|
|
66
|
+
### 6. Build the full timeline for the suspect
|
|
67
|
+
|
|
68
|
+
Once you have a primary suspect, call `get_timeline` with the symbol name to see its full version history:
|
|
69
|
+
- What changed in each commit?
|
|
70
|
+
- When was the last "stable" version?
|
|
71
|
+
- Was the change a modification, or was it newly added?
|
|
72
|
+
|
|
73
|
+
### 7. Correlate with surrounding changes
|
|
74
|
+
|
|
75
|
+
Call `get_evolution` with mode `directional` to separate:
|
|
76
|
+
- **Added symbols** — new code introduced (potential new bugs)
|
|
77
|
+
- **Removed symbols** — deleted code (potential missing functionality)
|
|
78
|
+
- **Modified symbols** — changed behaviour (potential regressions)
|
|
79
|
+
|
|
80
|
+
### 8. Check historical coupling (cochange)
|
|
81
|
+
|
|
82
|
+
For the primary suspect, call `get_cochange_context`:
|
|
83
|
+
- Which symbols historically co-change with this one?
|
|
84
|
+
- If the blast radius from `get_impact` doesn't explain the failure area, check cochange partners — the coupling may be behavioral, not structural.
|
|
85
|
+
|
|
86
|
+
**Decision:** If a cochange partner is in the failure area but has no direct call relationship to the suspect, it's a hidden dependency — investigate both.
|
|
87
|
+
|
|
88
|
+
### 9. Replay the sub-commit implementation history (if needed)
|
|
89
|
+
|
|
90
|
+
If the suspect's commit history doesn't explain the intent, call `get_episode_replay`:
|
|
91
|
+
- What was tried before the final committed state?
|
|
92
|
+
- Was any approach attempted and reverted in the same session?
|
|
93
|
+
- The `attempted_and_reverted` hint often explains why seemingly-correct code was changed to something subtler.
|
|
94
|
+
|
|
95
|
+
## Report: Root Cause Analysis
|
|
96
|
+
|
|
97
|
+
1. **Incident Timeline** — when it started, what was observed
|
|
98
|
+
2. **Most Likely Cause** — the top-ranked change(s) by `recent` mode with blast radius confirmation
|
|
99
|
+
3. **Supporting Evidence** — novelty signal (was this an unexpected change?), blast radius overlap with failure area, process membership overlap
|
|
100
|
+
4. **Change History** — full timeline of the suspect symbol
|
|
101
|
+
5. **Affected Scope** — all processes and downstream consumers impacted
|
|
102
|
+
6. **Remediation** — revert the change, fix forward, or mitigate
|
|
103
|
+
|
|
104
|
+
## Algorithm Selection Guide for Incidents
|
|
105
|
+
|
|
106
|
+
| Phase | Tool / Mode | Why |
|
|
107
|
+
|-------|-------------|-----|
|
|
108
|
+
| Initial triage | `get_evolution` `recent` | Time-weighted ranking surfaces changes near the incident |
|
|
109
|
+
| Anomaly detection | `get_evolution` `novel` | Catches unexpected changes to stable code |
|
|
110
|
+
| Scope assessment | `get_impact` | Ranks by structural significance (blast radius) |
|
|
111
|
+
| Hidden coupling | `get_cochange_context` | Surfaces behavioral coupling not in the call graph |
|
|
112
|
+
| Direction analysis | `get_evolution` `directional` | Separates added/removed/modified |
|
|
113
|
+
| Sub-commit intent | `get_episode_replay` | Reveals what was tried before the committed state |
|
|
114
|
+
| Quick summary | `get_evolution` `overview` | Fast module-level scan before deep-diving |
|
|
115
|
+
|
|
116
|
+
## Common Mistakes
|
|
117
|
+
|
|
118
|
+
| Mistake | Reality |
|
|
119
|
+
|---------|---------|
|
|
120
|
+
| Starting with `impact` mode | Use `recent` first — time proximity is the strongest signal for incidents |
|
|
121
|
+
| Only looking at the most recent commit | The root cause may be from an earlier change whose effects were delayed |
|
|
122
|
+
| Ignoring `novel` mode | Unexpected changes to stable code are often the root cause |
|
|
123
|
+
| Not checking blast radius overlap | A change is only a suspect if its blast radius reaches the failure area |
|
|
124
|
+
| Stopping at call graph analysis | `get_cochange_context` finds hidden coupling — symbols that move together without calling each other |
|
|
125
|
+
| Reading only committed code | `get_episode_replay` reveals tried-and-reverted approaches that explain the current implementation |
|
|
@@ -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 |
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memtrace-session-continuity
|
|
3
|
+
description: "Use at the start of any session to check what changed since last time, when resuming work after a break, when an agent needs to orient itself without guessing timestamps, or when asked 'what changed while I was away'"
|
|
4
|
+
allowed-tools:
|
|
5
|
+
- mcp__memtrace__get_changes_since
|
|
6
|
+
- mcp__memtrace__list_indexed_repositories
|
|
7
|
+
- mcp__memtrace__get_evolution
|
|
8
|
+
user-invocable: true
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
Session continuity for agents. Instead of guessing a time window and blindly running `get_evolution`, pass a `session_anchor` from your last session and get back exactly what changed — nothing more. The response returns a new anchor to persist for next time.
|
|
14
|
+
|
|
15
|
+
**Core principle:** Agents track a cursor, not a clock. Never guess timestamps.
|
|
16
|
+
|
|
17
|
+
## Steps
|
|
18
|
+
|
|
19
|
+
### 1. Find or bootstrap the session anchor
|
|
20
|
+
|
|
21
|
+
Look for a stored `session_anchor` from your last session:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"last_episode_id": "ep_abc123",
|
|
26
|
+
"last_reference_time": "2026-04-13T10:43:00Z"
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
If you have no anchor yet (first run), call `list_indexed_repositories`. Each repo now includes `last_episode_id`, `last_episode_time`, and `last_episode_type` — use `last_episode_id` as your bootstrap anchor.
|
|
31
|
+
|
|
32
|
+
### 2. Call `get_changes_since`
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
get_changes_since(
|
|
36
|
+
repo_id: "...",
|
|
37
|
+
last_episode_id: "ep_abc123" // preferred — exact episode boundary
|
|
38
|
+
// OR
|
|
39
|
+
last_reference_time: "2026-04-13T10:43:00Z" // fallback
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 3. Interpret the response
|
|
44
|
+
|
|
45
|
+
| `status` | Meaning | Action |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| `no_changes` | Nothing changed since your anchor | Safe to proceed; store new anchor |
|
|
48
|
+
| `changes_detected` | Full symbol-level delta returned | Review `modified[]`, `added[]`, `removed[]` |
|
|
49
|
+
| `changes_detected_overview` | >500 candidates — module rollup only | Check `by_module` for affected areas |
|
|
50
|
+
| `error` | Bad anchor or unknown episode | Fall back to `last_reference_time` or re-index |
|
|
51
|
+
|
|
52
|
+
### 4. Decide whether changes are relevant
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
changes_detected
|
|
56
|
+
├── Check modified[]/added[]/removed[] — do any overlap with your current task?
|
|
57
|
+
│ ├── YES → understand what changed before proceeding
|
|
58
|
+
│ └── NO → safe to continue, update anchor
|
|
59
|
+
|
|
60
|
+
changes_detected_overview (large window)
|
|
61
|
+
├── Check by_module — does any changed module overlap with your task area?
|
|
62
|
+
│ ├── YES → get_evolution(mode: compound) scoped to that window for detail
|
|
63
|
+
│ └── NO → ignore, update anchor
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 5. Always persist the returned anchor
|
|
67
|
+
|
|
68
|
+
Every response includes a new `session_anchor`. Store it for next session:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"session_anchor": {
|
|
73
|
+
"last_episode_id": "ep_xyz789",
|
|
74
|
+
"last_reference_time": "2026-04-13T14:22:00Z"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Auto-mode Selection
|
|
80
|
+
|
|
81
|
+
`get_changes_since` automatically picks the right mode so it never crashes:
|
|
82
|
+
|
|
83
|
+
| Candidate count | Mode selected | What you get |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| 0 | — | `no_changes` immediately |
|
|
86
|
+
| 1–499 | `compound` | Full symbol scoring |
|
|
87
|
+
| 500+ | `overview` | Module rollup only |
|
|
88
|
+
|
|
89
|
+
`candidate_count` in the response tells you what was found before selection.
|
|
90
|
+
|
|
91
|
+
## Common Mistakes
|
|
92
|
+
|
|
93
|
+
| Mistake | Reality |
|
|
94
|
+
|---------|---------|
|
|
95
|
+
| Using `get_evolution` with a guessed timestamp | `get_changes_since` uses an exact episode boundary — no guessing, no over-fetching |
|
|
96
|
+
| Discarding the returned `session_anchor` | Without it, next session reverts to timestamp guessing |
|
|
97
|
+
| Treating `changes_detected_overview` as too large to act on | `by_module` is complete — it tells you exactly which areas changed even in large windows |
|
|
98
|
+
| Calling this tool repeatedly within one session | Call once at session start; use the returned evolution result for the rest of the session |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memtrace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"description": "Code intelligence graph — MCP server + AI agent skills + visualization UI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"skills",
|
|
12
12
|
"claude-code"
|
|
13
13
|
],
|
|
14
|
-
"homepage": "https://memtrace.
|
|
14
|
+
"homepage": "https://memtrace.io",
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
17
|
"url": "https://github.com/syncable-dev/memtrace-public"
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"bin/",
|
|
25
25
|
"skills/",
|
|
26
|
+
"installer/",
|
|
26
27
|
"install.js",
|
|
27
28
|
"uninstall.js"
|
|
28
29
|
],
|
|
@@ -30,10 +31,14 @@
|
|
|
30
31
|
"postinstall": "node install.js",
|
|
31
32
|
"preuninstall": "node uninstall.js"
|
|
32
33
|
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"commander": "^12.0.0",
|
|
36
|
+
"fs-extra": "^11.0.0"
|
|
37
|
+
},
|
|
33
38
|
"optionalDependencies": {
|
|
34
|
-
"@memtrace/darwin-arm64": "0.1.
|
|
35
|
-
"@memtrace/linux-x64": "0.1.
|
|
36
|
-
"@memtrace/win32-x64": "0.1.
|
|
39
|
+
"@memtrace/darwin-arm64": "0.1.38",
|
|
40
|
+
"@memtrace/linux-x64": "0.1.38",
|
|
41
|
+
"@memtrace/win32-x64": "0.1.38"
|
|
37
42
|
},
|
|
38
43
|
"engines": {
|
|
39
44
|
"node": ">=18"
|
|
@@ -23,6 +23,9 @@ Map the HTTP API surface of a codebase — exposed endpoints, outbound HTTP call
|
|
|
23
23
|
| `get_api_topology` | Cross-repo call graph: which service calls which endpoint |
|
|
24
24
|
| `link_repositories` | Manually link repos for cross-repo edge detection |
|
|
25
25
|
|
|
26
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
27
|
+
|
|
28
|
+
|
|
26
29
|
## Steps
|
|
27
30
|
|
|
28
31
|
### 1. Discover endpoints
|
|
@@ -17,6 +17,9 @@ Find symbols that historically co-change with a target symbol — ranked by co-o
|
|
|
17
17
|
|
|
18
18
|
They are complementary. A symbol with no direct callers can still have strong cochange partners if it's always modified alongside another in every commit.
|
|
19
19
|
|
|
20
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
21
|
+
|
|
22
|
+
|
|
20
23
|
## Steps
|
|
21
24
|
|
|
22
25
|
### 1. Identify the target symbol
|
|
@@ -27,6 +27,9 @@ This is memtrace's most powerful analytical tool. It implements six distinct sco
|
|
|
27
27
|
| `directional` | Asymmetric scoring (added→out_degree, removed→in_degree, modified→impact) | "What was added vs removed?" — structural change direction |
|
|
28
28
|
| `overview` | Fast module-level rollup only | Quick summary — no per-symbol scoring, just module counts |
|
|
29
29
|
|
|
30
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
31
|
+
|
|
32
|
+
|
|
30
33
|
## Steps
|
|
31
34
|
|
|
32
35
|
### 1. Determine the time window
|
|
@@ -26,18 +26,48 @@ Graph algorithms that reveal the structural architecture of a codebase — commu
|
|
|
26
26
|
| `get_process_flow` | Trace a single process step-by-step |
|
|
27
27
|
| `execute_cypher` | Direct read-only Cypher queries for custom analysis |
|
|
28
28
|
|
|
29
|
+
## Parameter Types — Read This First
|
|
30
|
+
|
|
31
|
+
All memtrace MCP tools are **strictly typed**. Numbers must be JSON numbers, not strings.
|
|
32
|
+
|
|
33
|
+
| Parameter shape | Correct | Wrong (will fail deserialization) |
|
|
34
|
+
|-----------------|---------|-----------------------------------|
|
|
35
|
+
| Integer/count (`limit`, `min_size`, `depth`) | `limit: 20` | `limit: "20"` |
|
|
36
|
+
| String identifier (`repo_id`, `branch`, `name`) | `repo_id: "my-repo"` | `repo_id: my-repo` |
|
|
37
|
+
| Boolean (`fuzzy`, `include_tests`) | `fuzzy: true` | `fuzzy: "true"` |
|
|
38
|
+
|
|
39
|
+
If you see `MCP error -32602: invalid type: string "N", expected usize`, you passed a string where a number was required. Remove the quotes.
|
|
40
|
+
|
|
29
41
|
## Steps
|
|
30
42
|
|
|
31
43
|
### 1. Understand the architecture
|
|
32
44
|
|
|
33
45
|
Start with `list_communities` to see how the codebase is naturally partitioned into logical modules. Each community has a name, member count, and representative symbols.
|
|
34
46
|
|
|
47
|
+
**`list_communities` parameters:**
|
|
48
|
+
- `repo_id` — string, required. Repository ID (from `list_indexed_repositories`).
|
|
49
|
+
- `branch` — string, optional. Defaults to `"main"`.
|
|
50
|
+
- `min_size` — **integer**, optional. Minimum community size to include. Default `3`.
|
|
51
|
+
- `limit` — **integer**, optional. Max communities to return. Default `50`, capped at `200`.
|
|
52
|
+
|
|
53
|
+
Example (correct):
|
|
54
|
+
```json
|
|
55
|
+
{ "repo_id": "Memtrace", "limit": 20 }
|
|
56
|
+
```
|
|
57
|
+
Example (WRONG — will fail):
|
|
58
|
+
```json
|
|
59
|
+
{ "repo_id": "Memtrace", "limit": "20" }
|
|
60
|
+
```
|
|
61
|
+
|
|
35
62
|
### 2. Find critical infrastructure
|
|
36
63
|
|
|
37
64
|
Use `find_central_symbols` to identify the most important symbols:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
- `
|
|
65
|
+
|
|
66
|
+
**`find_central_symbols` parameters:**
|
|
67
|
+
- `repo_id` — string, required.
|
|
68
|
+
- `branch` — string, optional. Defaults to `"main"`.
|
|
69
|
+
- `limit` — **integer**, optional. How many to return. Default `20`, capped at `100`.
|
|
70
|
+
- `algorithm` — string, optional. `"pagerank"` (default, via MAGE — falls back to degree if unavailable) or `"degree"` (simple in-degree count, no MAGE required).
|
|
41
71
|
|
|
42
72
|
### 3. Find architectural chokepoints
|
|
43
73
|
|
|
@@ -46,16 +76,36 @@ Use `find_bridge_symbols` to find symbols that, if removed, would disconnect par
|
|
|
46
76
|
- **Integration points** — good places for interfaces/contracts
|
|
47
77
|
- **Refactoring targets** — often too much responsibility concentrated in one place
|
|
48
78
|
|
|
79
|
+
**`find_bridge_symbols` parameters:**
|
|
80
|
+
- `repo_id` — string, required.
|
|
81
|
+
- `branch` — string, optional. Defaults to `"main"`.
|
|
82
|
+
- `limit` — **integer**, optional. Default `15`, capped at `50`.
|
|
83
|
+
|
|
49
84
|
### 4. Trace execution flows
|
|
50
85
|
|
|
51
86
|
Use `list_processes` to see all entry points (HTTP handlers, background jobs, CLI commands, event handlers).
|
|
52
87
|
|
|
53
|
-
|
|
88
|
+
**`list_processes` parameters:**
|
|
89
|
+
- `repo_id` — string, required.
|
|
90
|
+
- `branch` — string, optional. Defaults to `"main"`.
|
|
91
|
+
- `limit` — **integer**, optional. Default `50`.
|
|
92
|
+
|
|
93
|
+
Use `get_process_flow` with a process name to trace a specific flow step-by-step — shows the full call chain from entry point through business logic to data access.
|
|
94
|
+
|
|
95
|
+
**`get_process_flow` parameters:**
|
|
96
|
+
- `process` — string, required. Process name or entry-point symbol name (from `list_processes`).
|
|
97
|
+
- `repo_id` — string, required.
|
|
98
|
+
- `branch` — string, optional. Defaults to `"main"`.
|
|
54
99
|
|
|
55
100
|
### 5. Custom queries
|
|
56
101
|
|
|
57
102
|
Use `execute_cypher` for advanced graph queries not covered by built-in tools. This is read-only and runs directly against the knowledge graph.
|
|
58
103
|
|
|
104
|
+
**`execute_cypher` parameters:**
|
|
105
|
+
- `query` — string, required. A read-only Cypher query. Write keywords (CREATE, MERGE, DELETE, SET, etc.) are forbidden. Use `$repo_id` to scope to a repository.
|
|
106
|
+
- `params` — object, optional. JSON object of parameter bindings.
|
|
107
|
+
- `repo_id` — string, optional. If provided, injected as `$repo_id` into `params`.
|
|
108
|
+
|
|
59
109
|
## Decision Points
|
|
60
110
|
|
|
61
111
|
| Question | Tool |
|
|
@@ -20,6 +20,9 @@ Compute the blast radius of changing a specific symbol. Traces upstream (what de
|
|
|
20
20
|
| `get_impact` | Blast radius from a specific symbol (by ID) |
|
|
21
21
|
| `detect_changes` | Scope symbols affected by a diff/patch |
|
|
22
22
|
|
|
23
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
24
|
+
|
|
25
|
+
|
|
23
26
|
## Steps
|
|
24
27
|
|
|
25
28
|
### 1. Identify the symbol
|
|
@@ -21,6 +21,9 @@ Index a local codebase into the persistent code knowledge graph. This is always
|
|
|
21
21
|
| `incremental` | Only re-parse changed files (use for subsequent runs) |
|
|
22
22
|
| `clear_existing` | Wipe and rebuild from scratch |
|
|
23
23
|
|
|
24
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
25
|
+
|
|
26
|
+
|
|
24
27
|
## Steps
|
|
25
28
|
|
|
26
29
|
### 1. Check if already indexed
|
|
@@ -22,6 +22,9 @@ Identify code quality issues using structural graph analysis — dead code (zero
|
|
|
22
22
|
| `find_most_complex_functions` | Top-N functions by complexity across the repo |
|
|
23
23
|
| `get_repository_stats` | Repo-wide counts: nodes, edges, communities, processes |
|
|
24
24
|
|
|
25
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
26
|
+
|
|
27
|
+
|
|
25
28
|
## Steps
|
|
26
29
|
|
|
27
30
|
### 1. Get repository overview
|
|
@@ -25,6 +25,9 @@ Traverse the code knowledge graph to map relationships between symbols — calle
|
|
|
25
25
|
| `exporters` | Which files import this module? |
|
|
26
26
|
| `type_usages` | Where is this type/interface referenced? |
|
|
27
27
|
|
|
28
|
+
> **Parameter types:** MCP parameters are strictly typed. Numbers (`limit`, `depth`, `min_size`, `last_n`, etc.) must be JSON numbers — not strings. Use `limit: 20`, never `limit: "20"`. Passing a string yields `MCP error -32602: invalid type: string, expected usize`.
|
|
29
|
+
|
|
30
|
+
|
|
28
31
|
## Steps
|
|
29
32
|
|
|
30
33
|
### 1. Get the symbol ID
|