memtrace-skills 0.7.10
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/dist/commands/doctor.d.ts +16 -0
- package/dist/commands/doctor.js +199 -0
- package/dist/commands/enterprise-install.d.ts +7 -0
- package/dist/commands/enterprise-install.js +129 -0
- package/dist/commands/install.d.ts +9 -0
- package/dist/commands/install.js +104 -0
- package/dist/commands/picker.d.ts +6 -0
- package/dist/commands/picker.js +22 -0
- package/dist/commands/rail-install.d.ts +7 -0
- package/dist/commands/rail-install.js +37 -0
- package/dist/fs-safe.d.ts +21 -0
- package/dist/fs-safe.js +35 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +87 -0
- package/dist/rail-install.d.ts +20 -0
- package/dist/rail-install.js +183 -0
- package/dist/skills.d.ts +17 -0
- package/dist/skills.js +64 -0
- package/dist/transformers/claude.d.ts +71 -0
- package/dist/transformers/claude.js +702 -0
- package/dist/transformers/codex.d.ts +8 -0
- package/dist/transformers/codex.js +294 -0
- package/dist/transformers/cursor.d.ts +7 -0
- package/dist/transformers/cursor.js +124 -0
- package/dist/transformers/gemini.d.ts +3 -0
- package/dist/transformers/gemini.js +78 -0
- package/dist/transformers/hermes.d.ts +5 -0
- package/dist/transformers/hermes.js +136 -0
- package/dist/transformers/index.d.ts +14 -0
- package/dist/transformers/index.js +24 -0
- package/dist/transformers/kiro.d.ts +2 -0
- package/dist/transformers/kiro.js +69 -0
- package/dist/transformers/opencode.d.ts +2 -0
- package/dist/transformers/opencode.js +77 -0
- package/dist/transformers/rail-hooks.d.ts +56 -0
- package/dist/transformers/rail-hooks.js +303 -0
- package/dist/transformers/shared.d.ts +18 -0
- package/dist/transformers/shared.js +129 -0
- package/dist/transformers/types.d.ts +40 -0
- package/dist/transformers/types.js +1 -0
- package/dist/transformers/vscode.d.ts +3 -0
- package/dist/transformers/vscode.js +53 -0
- package/dist/transformers/windsurf.d.ts +3 -0
- package/dist/transformers/windsurf.js +43 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +22 -0
- package/package.json +50 -0
- package/plugins/memtrace-skills/.claude-plugin/plugin.json +23 -0
- package/plugins/memtrace-skills/references/mcp-parameters.md +302 -0
- package/plugins/memtrace-skills/skills/memtrace-api-topology/SKILL.md +58 -0
- package/plugins/memtrace-skills/skills/memtrace-change-impact-analysis/SKILL.md +75 -0
- package/plugins/memtrace-skills/skills/memtrace-cochange/SKILL.md +71 -0
- package/plugins/memtrace-skills/skills/memtrace-code-review/SKILL.md +41 -0
- package/plugins/memtrace-skills/skills/memtrace-codebase-exploration/SKILL.md +94 -0
- package/plugins/memtrace-skills/skills/memtrace-continuous-memory/SKILL.md +96 -0
- package/plugins/memtrace-skills/skills/memtrace-episode-replay/SKILL.md +94 -0
- package/plugins/memtrace-skills/skills/memtrace-evolution/SKILL.md +128 -0
- package/plugins/memtrace-skills/skills/memtrace-first/SKILL.md +194 -0
- package/plugins/memtrace-skills/skills/memtrace-fleet-coordination/SKILL.md +80 -0
- package/plugins/memtrace-skills/skills/memtrace-fleet-first/SKILL.md +125 -0
- package/plugins/memtrace-skills/skills/memtrace-fleet-publish-intent/SKILL.md +48 -0
- package/plugins/memtrace-skills/skills/memtrace-fleet-record-episode/SKILL.md +44 -0
- package/plugins/memtrace-skills/skills/memtrace-fleet-resolve/SKILL.md +54 -0
- package/plugins/memtrace-skills/skills/memtrace-graph/SKILL.md +67 -0
- package/plugins/memtrace-skills/skills/memtrace-impact/SKILL.md +58 -0
- package/plugins/memtrace-skills/skills/memtrace-incident-investigation/SKILL.md +112 -0
- package/plugins/memtrace-skills/skills/memtrace-index/SKILL.md +65 -0
- package/plugins/memtrace-skills/skills/memtrace-quality/SKILL.md +63 -0
- package/plugins/memtrace-skills/skills/memtrace-refactoring-guide/SKILL.md +103 -0
- package/plugins/memtrace-skills/skills/memtrace-relationships/SKILL.md +67 -0
- package/plugins/memtrace-skills/skills/memtrace-search/SKILL.md +93 -0
- package/plugins/memtrace-skills/skills/memtrace-session-continuity/SKILL.md +93 -0
- package/plugins/memtrace-skills/skills/memtrace-style-fingerprint/SKILL.md +105 -0
- package/skills/commands/memtrace-api-topology.md +65 -0
- package/skills/commands/memtrace-cochange.md +76 -0
- package/skills/commands/memtrace-evolution.md +135 -0
- package/skills/commands/memtrace-fleet-publish-intent.md +51 -0
- package/skills/commands/memtrace-fleet-record-episode.md +48 -0
- package/skills/commands/memtrace-fleet-resolve.md +59 -0
- package/skills/commands/memtrace-graph.md +75 -0
- package/skills/commands/memtrace-impact.md +64 -0
- package/skills/commands/memtrace-index.md +71 -0
- package/skills/commands/memtrace-quality.md +69 -0
- package/skills/commands/memtrace-relationships.md +73 -0
- package/skills/commands/memtrace-search.md +93 -0
- package/skills/workflows/memtrace-change-impact-analysis.md +85 -0
- package/skills/workflows/memtrace-code-review.md +48 -0
- package/skills/workflows/memtrace-codebase-exploration.md +108 -0
- package/skills/workflows/memtrace-continuous-memory.md +104 -0
- package/skills/workflows/memtrace-episode-replay.md +100 -0
- package/skills/workflows/memtrace-first.md +194 -0
- package/skills/workflows/memtrace-fleet-coordination.md +87 -0
- package/skills/workflows/memtrace-fleet-first.md +132 -0
- package/skills/workflows/memtrace-incident-investigation.md +125 -0
- package/skills/workflows/memtrace-refactoring-guide.md +116 -0
- package/skills/workflows/memtrace-session-continuity.md +98 -0
- package/skills/workflows/memtrace-style-fingerprint.md +111 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memtrace-incident-investigation
|
|
3
|
+
description: "Always use for source-code bugs, incidents, regressions, production issues, failures, root cause analysis, what broke, or what changed when debugging. Do not start with Grep, Glob, rg, find, or manual file search for code causes; Memtrace combines symbol search, impact, call graph, and temporal history."
|
|
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: "Always use when the user wants to refactor source code, reduce complexity, clean technical debt, split large functions, extract modules, reorganize code, or choose refactoring priorities. Do not use Grep or manual reference search to plan refactors; Memtrace provides complexity, dead-code, relationships, and impact context."
|
|
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: "Always use at session start or resume when the user asks to continue, catch up, see what changed while away, recover prior context, or orient without guessing timestamps in an indexed source-code repo. Do not use git log, Grep, or manual file search for catch-up; Memtrace provides session anchors and change memory."
|
|
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 |
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: memtrace-style-fingerprint
|
|
3
|
+
description: "Always use before writing or editing source code in an indexed repo when choosing between competing idioms (ternary vs if-else, arrow vs function declaration, const vs let, await vs .then, early-return vs nested-return). Pull the codebase's empirical style norm from Memtrace and match it instead of re-deriving style from training priors. Do not maintain a markdown style guide for the project; the fingerprint is sampled live from the actual code."
|
|
4
|
+
allowed-tools:
|
|
5
|
+
- mcp__memtrace__get_style_fingerprint
|
|
6
|
+
- mcp__memtrace__get_codebase_briefing
|
|
7
|
+
- mcp__memtrace__find_code
|
|
8
|
+
- mcp__memtrace__list_indexed_repositories
|
|
9
|
+
user-invocable: true
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
Every indexed Memtrace repository carries an empirical **style fingerprint** — descriptive histograms of competing AST idioms (ternary vs if-else, arrow vs function declaration, const vs let, await vs `.then`, early-return vs nested-return depth) computed at parse time and rolled up to Repository + Community level. This workflow tells you when and how to consult it so your edits match the codebase's existing idioms instead of drifting on stylistic choices the linter doesn't catch.
|
|
15
|
+
|
|
16
|
+
The fingerprint is **descriptive, not prescriptive**. It reports what the codebase actually does, not what a style guide says it should do. If the codebase deviates from a popular convention for some reason, the fingerprint captures the deviation and you should match the deviation — that's the whole point. For prescriptive bug/security/perf rules, use `find_code_review_issues` instead.
|
|
17
|
+
|
|
18
|
+
## When to use this workflow
|
|
19
|
+
|
|
20
|
+
| Situation | Action |
|
|
21
|
+
|---|---|
|
|
22
|
+
| About to write new code (function, component, module) in an indexed repo | Step 1 + Step 2 with `file_path=<the file you'll create>` |
|
|
23
|
+
| About to edit an existing file | Step 1 + Step 2 with `file_path=<that file>` |
|
|
24
|
+
| Asked "what's the convention here for X?" | Step 1 only — repo-mode fingerprint answers it |
|
|
25
|
+
| Deciding between two equivalent idioms (ternary vs if, arrow vs fn-decl, await vs then) | Step 2 with `file_path` — `delta_from_codebase_norm` tells you which idiom matches the norm |
|
|
26
|
+
| Reviewing a diff | Step 2 on each modified file — flag any new idioms that diverge from the file's language norm |
|
|
27
|
+
| Session start in a multi-day project | Read the `style:` line in `get_codebase_briefing` (auto-included) |
|
|
28
|
+
|
|
29
|
+
If the repo is not indexed in Memtrace, this workflow does not apply — fall back to your default behavior.
|
|
30
|
+
|
|
31
|
+
## Steps
|
|
32
|
+
|
|
33
|
+
### 1. Get the codebase's overall norm
|
|
34
|
+
|
|
35
|
+
Call `get_style_fingerprint(repo_id)` with no `file_path`. The response includes:
|
|
36
|
+
|
|
37
|
+
- `histogram` — raw counts (e.g. `ternary_count: 1005, if_stmt_count: 8087`)
|
|
38
|
+
- `ratios` — computed shares for each competing pair (e.g. `ternary_share: 0.11`)
|
|
39
|
+
- `dominant_idioms` — top-3 dimensions sorted by `|ratio - 0.5|` (strongest preferences first), each with a `dimension`, `ratio`, and human-readable `interpretation`
|
|
40
|
+
- `function_count` — sample size at the repo level
|
|
41
|
+
- `sample_threshold` — minimum observations before a ratio is committed (currently 20)
|
|
42
|
+
|
|
43
|
+
A `ratio` of `null` means the codebase doesn't have enough observations for that dimension to commit a norm — treat it as "no signal", do not assume one.
|
|
44
|
+
|
|
45
|
+
### 2. Get the file's deviation from the norm (when about to edit a specific file)
|
|
46
|
+
|
|
47
|
+
Call `get_style_fingerprint(repo_id, file_path=<file>)`. The response adds:
|
|
48
|
+
|
|
49
|
+
- `file_fingerprint` — the same shape as `histogram`/`ratios`/`function_count` but computed over just the functions in that file
|
|
50
|
+
- `codebase_fingerprint` — repo aggregate for comparison
|
|
51
|
+
- `delta_from_codebase_norm` — array of dimensions where the file diverges ≥0.15 from the codebase, sorted by absolute delta, capped at top 5. Each entry has `dimension`, `file_ratio`, `codebase_ratio`, `abs_delta`, and a `note` describing the direction
|
|
52
|
+
|
|
53
|
+
**Match the file's `language_fingerprint`, not the repo aggregate.** In file mode the response carries `language` (the file's language), `language_fingerprint` (that language's slice — the primary comparator), and `delta_from_language_norm` (divergence vs the language, not the repo). Per-language slicing prevents cross-applying Python norms to JS code or vice versa — read the `language_fingerprint`. (`delta_from_codebase_norm` is retained as a deprecated alias and is removed in 0.5.14.)
|
|
54
|
+
|
|
55
|
+
If `delta_from_language_norm` is empty, the file is already aligned — proceed without style adjustments. If it has entries, your edits should not amplify the divergence (e.g. don't add more ternaries to a file that's already above the language's ternary norm).
|
|
56
|
+
|
|
57
|
+
### 3. Read the briefing line at session start (passive)
|
|
58
|
+
|
|
59
|
+
`get_codebase_briefing(repo_id)` auto-includes a `style:` line in its summary when the sample threshold is met and at least one ratio is outside the 0.4..0.6 no-preference band. Format:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
style: <interpretation 1> (<%>); <interpretation 2> (<%>); <interpretation 3> (<%>)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Example on a TS/JS-heavy codebase:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
style: strongly prefers arrow functions (98%); strongly prefers async/await over .then chains (88%); strongly prefers const over let (94%)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
You should already be reading the briefing at session start (per `memtrace-codebase-exploration`). The `style:` line lands in your context for free — no extra call needed.
|
|
72
|
+
|
|
73
|
+
## Decision points
|
|
74
|
+
|
|
75
|
+
| Condition | Action |
|
|
76
|
+
|---|---|
|
|
77
|
+
| `dominant_idioms[0].ratio >= 0.85` or `<= 0.15` | Treat as a hard preference — match it unless there's a specific structural reason not to |
|
|
78
|
+
| `dominant_idioms[0].ratio` in `0.65..0.85` or `0.15..0.35` | Treat as a soft preference — match it for new code, leave existing patterns alone |
|
|
79
|
+
| `ratio` in `0.4..0.6` | No clear preference — use your own judgment, match local file context |
|
|
80
|
+
| `ratio` is `null` (below sample threshold) | No signal — don't assume a norm; pick the idiom that fits the immediate context |
|
|
81
|
+
| `delta_from_codebase_norm` shows your target file already diverges from the norm | Don't amplify the divergence with your edits — match the codebase, not the outlier file |
|
|
82
|
+
| `file_fingerprint` is empty (file has no functions yet, or is a config file) | Use the language slice or repo aggregate; this is creation territory |
|
|
83
|
+
|
|
84
|
+
## Anti-patterns — do not do these
|
|
85
|
+
|
|
86
|
+
- **Reading the repo aggregate when editing a single-language file.** If the codebase is 70% TS / 30% Python, the repo aggregate mixes both. The `language_fingerprint` (when available) or `codebase_fingerprint.ratios` filtered by the file's language is what you should match. Cross-applying TS norms to a Python file is the failure mode this whole tool exists to prevent.
|
|
87
|
+
- **Treating the fingerprint as prescriptive.** It tells you what the codebase does. If the codebase consistently does something unusual, match that — don't override with "this isn't best practice" arguments. The whole point is to stop drifting from the codebase's own choices.
|
|
88
|
+
- **Calling `get_style_fingerprint` for every line of code.** Once per file at the start of an edit session is enough. The norm doesn't change between your edits within the same session.
|
|
89
|
+
- **Ignoring the briefing line.** It auto-loads into your context. If you act on style choices in an edit session without reading it first, you're spending tool calls to re-derive something you already had.
|
|
90
|
+
- **Adding a markdown style guide to the project.** The fingerprint is the style guide. It refreshes on every reindex. A markdown file would either duplicate it or contradict it.
|
|
91
|
+
|
|
92
|
+
## Naming-case dimensions (shipped in 0.5.13)
|
|
93
|
+
|
|
94
|
+
Beyond the AST idioms, the fingerprint also reports identifier **naming-case** per scope, across all 13 source languages:
|
|
95
|
+
|
|
96
|
+
- **Variables / functions / types / constants / files** — the share of camelCase / snake_case / PascalCase / SCREAMING_SNAKE / kebab. Read e.g. `ratios.naming_variables_snake_share` or the `dominant_idioms` entry that names the scope's winning case ("vars are snake_case (89%)").
|
|
97
|
+
- **Config keys** for YAML / JSON / TOML / HCL / SQL — `ratios.config_keys_*_share`.
|
|
98
|
+
- **Enforcement-aware:** languages that compiler-enforce a scope return `null` for it (Rust vars/fns/types/consts, Ruby constants). A `null` there means "the compiler decides, not the codebase" — don't try to match a non-signal.
|
|
99
|
+
- **Go** reports `go_exported_share` (PascalCase = exported) instead of per-case naming, because case encodes visibility in Go.
|
|
100
|
+
|
|
101
|
+
When editing, match the naming case the file's `language_fingerprint` reports for the scope you're touching — same per-language rule as the idiom dimensions.
|
|
102
|
+
|
|
103
|
+
## What this workflow does NOT cover
|
|
104
|
+
|
|
105
|
+
- **Security / bug / performance rules** — use `find_code_review_issues` (prescriptive deterministic review).
|
|
106
|
+
- **Comment / docstring style** — not in scope; use file-local examples.
|
|
107
|
+
- **Architecture / module-organization decisions** — see `memtrace-codebase-exploration` and `memtrace-refactoring-guide`.
|
|
108
|
+
|
|
109
|
+
## Why this exists
|
|
110
|
+
|
|
111
|
+
Without this workflow, LLM editors drift session-to-session on style choices that aren't enforced by linters — one session uses ternaries, the next doesn't; one uses arrow functions, the next uses `function`. The fix isn't a manually-maintained style guide (stale by week 2). The fix is sampling the codebase's actual idioms at parse time and reading them before each edit. The fingerprint is computed in the same parse pass as cyclomatic + cognitive complexity at sub-1% overhead, so the cost of providing the answer is near zero.
|