memtrace 0.5.1 → 0.5.13

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.
@@ -178,7 +178,7 @@ function writePluginManifest(cacheDir) {
178
178
  version,
179
179
  author: {
180
180
  name: 'Syncable',
181
- email: 'support@syncable.dev',
181
+ email: 'support@memtrace.io',
182
182
  },
183
183
  homepage: 'https://memtrace.io',
184
184
  repository: `https://github.com/${MARKETPLACE_REPO}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memtrace",
3
- "version": "0.5.1",
3
+ "version": "0.5.13",
4
4
  "description": "Code intelligence graph — MCP server + AI agent skills + visualization UI",
5
5
  "keywords": [
6
6
  "mcp",
@@ -39,11 +39,11 @@
39
39
  "fs-extra": "^11.0.0"
40
40
  },
41
41
  "optionalDependencies": {
42
- "@memtrace/darwin-arm64": "0.5.1",
43
- "@memtrace/linux-x64": "0.5.1",
44
- "@memtrace/win32-x64": "0.5.1",
45
- "@memtrace/linux-x64-noavx2": "0.5.1",
46
- "@memtrace/win32-x64-noavx2": "0.5.1"
42
+ "@memtrace/darwin-arm64": "0.5.13",
43
+ "@memtrace/linux-x64": "0.5.13",
44
+ "@memtrace/win32-x64": "0.5.13",
45
+ "@memtrace/linux-x64-noavx2": "0.5.13",
46
+ "@memtrace/win32-x64-noavx2": "0.5.13"
47
47
  },
48
48
  "engines": {
49
49
  "node": ">=18"
@@ -122,6 +122,7 @@ If not indexed → offer to index with `mcp__memtrace__index_directory`, then fo
122
122
  | What files change together? | `get_cochange_context` |
123
123
  | Architecture overview | `list_communities` + `find_central_symbols` |
124
124
  | About to edit / quote — need exact lines | Bounded `Read(file, offset=start_line, limit=N)` (preferred), or `get_source_window` for path-resolution parity |
125
+ | About to choose between competing idioms (ternary vs if-else, arrow vs fn-decl, const vs let, await vs `.then`) | `get_style_fingerprint(repo_id, file_path)` — empirical codebase norm; see `memtrace-style-fingerprint` workflow |
125
126
 
126
127
  ## Standard Workflows
127
128
 
@@ -147,6 +148,7 @@ If not indexed → offer to index with `mcp__memtrace__index_directory`, then fo
147
148
  1. `find_symbol` → confirm you have the right target
148
149
  2. `get_symbol_context` → understand full context
149
150
  3. `get_impact` → know blast radius before touching anything
151
+ 4. `get_style_fingerprint(repo_id, file_path=<file>)` → match the codebase's empirical idiom (ternary vs if-else, arrow vs fn-decl, etc.) — see `memtrace-style-fingerprint` workflow for the full decision rule
150
152
 
151
153
  ## Red Flags — STOP, Use Memtrace Instead
152
154
 
@@ -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.