@pcircle/memesh 3.2.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.de.md +28 -7
  2. package/README.es.md +28 -7
  3. package/README.fr.md +28 -7
  4. package/README.ja.md +28 -7
  5. package/README.ko.md +28 -7
  6. package/README.md +47 -14
  7. package/README.pt.md +28 -7
  8. package/README.th.md +28 -7
  9. package/README.vi.md +28 -7
  10. package/README.zh-CN.md +28 -7
  11. package/README.zh-TW.md +28 -7
  12. package/dashboard/dist/index.html +2 -2
  13. package/dist/core/auto-tagger.d.ts +5 -0
  14. package/dist/core/auto-tagger.d.ts.map +1 -0
  15. package/dist/core/auto-tagger.js +99 -0
  16. package/dist/core/auto-tagger.js.map +1 -0
  17. package/dist/core/config.d.ts +1 -0
  18. package/dist/core/config.d.ts.map +1 -1
  19. package/dist/core/config.js +29 -1
  20. package/dist/core/config.js.map +1 -1
  21. package/dist/core/embedder.d.ts +1 -0
  22. package/dist/core/embedder.d.ts.map +1 -1
  23. package/dist/core/embedder.js +120 -47
  24. package/dist/core/embedder.js.map +1 -1
  25. package/dist/core/lifecycle.d.ts +7 -0
  26. package/dist/core/lifecycle.d.ts.map +1 -1
  27. package/dist/core/lifecycle.js +91 -0
  28. package/dist/core/lifecycle.js.map +1 -1
  29. package/dist/core/operations.d.ts +1 -0
  30. package/dist/core/operations.d.ts.map +1 -1
  31. package/dist/core/operations.js +9 -0
  32. package/dist/core/operations.js.map +1 -1
  33. package/dist/core/patterns.d.ts +39 -0
  34. package/dist/core/patterns.d.ts.map +1 -0
  35. package/dist/core/patterns.js +109 -0
  36. package/dist/core/patterns.js.map +1 -0
  37. package/dist/core/schema-export.d.ts.map +1 -1
  38. package/dist/core/schema-export.js +17 -0
  39. package/dist/core/schema-export.js.map +1 -1
  40. package/dist/core/scoring.d.ts +6 -0
  41. package/dist/core/scoring.d.ts.map +1 -1
  42. package/dist/core/scoring.js +8 -3
  43. package/dist/core/scoring.js.map +1 -1
  44. package/dist/db.d.ts.map +1 -1
  45. package/dist/db.js +29 -2
  46. package/dist/db.js.map +1 -1
  47. package/dist/transports/http/server.d.ts.map +1 -1
  48. package/dist/transports/http/server.js +53 -8
  49. package/dist/transports/http/server.js.map +1 -1
  50. package/dist/transports/mcp/handlers.d.ts +17 -0
  51. package/dist/transports/mcp/handlers.d.ts.map +1 -1
  52. package/dist/transports/mcp/handlers.js +91 -1
  53. package/dist/transports/mcp/handlers.js.map +1 -1
  54. package/dist/transports/schemas.d.ts +10 -0
  55. package/dist/transports/schemas.d.ts.map +1 -1
  56. package/dist/transports/schemas.js +4 -0
  57. package/dist/transports/schemas.js.map +1 -1
  58. package/hooks/hooks.json +12 -0
  59. package/package.json +4 -1
  60. package/plugin.json +1 -1
  61. package/scripts/hooks/pre-edit-recall.js +163 -0
  62. package/scripts/hooks/session-start.js +52 -2
  63. package/scripts/hooks/session-summary.js +44 -1
  64. package/skills/memesh/SKILL.md +110 -52
  65. package/skills/memesh-review/SKILL.md +69 -26
@@ -7,7 +7,7 @@
7
7
  import { createRequire } from 'module';
8
8
  import { homedir } from 'os';
9
9
  import { join, basename, dirname } from 'path';
10
- import { existsSync, mkdirSync, readFileSync } from 'fs';
10
+ import { existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs';
11
11
  import { fileURLToPath } from 'url';
12
12
 
13
13
  const require = createRequire(import.meta.url);
@@ -238,6 +238,49 @@ process.stdin.on('end', async () => {
238
238
  [...baseTags, 'type:heavy-session']
239
239
  );
240
240
  }
241
+
242
+ // ── Recall effectiveness tracking ────────────────────────────────
243
+ // Read which entities were injected at session start, check if
244
+ // their names appear in the transcript, update hits/misses.
245
+ try {
246
+ const injectedPath = join(homedir(), '.memesh', 'last-session-injected.json');
247
+ if (existsSync(injectedPath)) {
248
+ const injectedData = JSON.parse(readFileSync(injectedPath, 'utf8'));
249
+ const { entityIds, entityNames } = injectedData;
250
+
251
+ if (entityIds && entityIds.length > 0) {
252
+ // Check if recall_hits column exists (v4.0+ migration)
253
+ const colCheck = db.prepare("PRAGMA table_info(entities)").all();
254
+ if (colCheck.some(c => c.name === 'recall_hits')) {
255
+ // Build a lowercase transcript text for matching
256
+ const transcriptText = readFileSync(transcriptPath, 'utf8').toLowerCase();
257
+
258
+ const updateHit = db.prepare(
259
+ 'UPDATE entities SET recall_hits = COALESCE(recall_hits, 0) + 1 WHERE id = ?'
260
+ );
261
+ const updateMiss = db.prepare(
262
+ 'UPDATE entities SET recall_misses = COALESCE(recall_misses, 0) + 1 WHERE id = ?'
263
+ );
264
+
265
+ for (let i = 0; i < entityIds.length; i++) {
266
+ const name = (entityNames[i] || '').toLowerCase();
267
+ // Skip very short names to avoid false positives
268
+ if (name.length < 4) continue;
269
+ if (transcriptText.includes(name)) {
270
+ updateHit.run(entityIds[i]);
271
+ } else {
272
+ updateMiss.run(entityIds[i]);
273
+ }
274
+ }
275
+ }
276
+ }
277
+
278
+ // Clean up temp file
279
+ try { unlinkSync(injectedPath); } catch {}
280
+ }
281
+ } catch {
282
+ // Non-critical — don't break session summary
283
+ }
241
284
  } finally {
242
285
  db.close();
243
286
  }
@@ -1,73 +1,131 @@
1
1
  ---
2
2
  name: memesh
3
- description: Use MeMesh to remember, recall, and manage AI knowledge across sessions. Triggers when the user asks to remember something, recall past decisions, forget outdated info, or manage their memory. Also triggers proactively when you make important decisions, fix bugs, or learn lessons worth preserving.
3
+ description: Use MeMesh to remember, recall, and manage AI knowledge across sessions. Triggers when the user asks to remember something, recall past decisions, forget outdated info, learn from mistakes, or analyze work patterns. Also triggers proactively when you make important decisions, fix bugs, or learn lessons worth preserving.
4
4
  user-invocable: true
5
5
  ---
6
6
 
7
7
  # MeMesh — AI Memory Management
8
8
 
9
- You have access to MeMesh, a persistent memory layer with 6 tools. Use them to remember important knowledge across sessions.
10
-
11
- ## When to Use (Proactive)
12
-
13
- **Remember automatically when:**
14
- - A design decision is made ("let's use OAuth" remember it)
15
- - A bug is fixed (root cause + fix → remember as lesson)
16
- - A pattern is established ("we always use Zod for validation" → remember as pattern)
17
- - Architecture changes ("moved from monolith to microservices" → remember)
18
- - The user explicitly says "remember this" or "don't forget"
19
-
20
- **Recall automatically when:**
21
- - Starting work on a feature that might have prior decisions
22
- - The user asks "what did we decide about X?"
23
- - You need context about a project's conventions
24
-
25
- **Forget when:**
26
- - A decision is superseded by a new one (use `supersedes` relation)
27
- - The user says "forget about X" or "that's outdated"
28
-
29
- ## Tools Reference
30
-
31
- ### remember
32
- ```json
33
- {
34
- "name": "auth-decision",
35
- "type": "decision",
36
- "observations": ["Use OAuth 2.0 with PKCE for authentication"],
37
- "tags": ["project:myapp", "topic:auth"],
38
- "relations": [{"to": "old-auth", "type": "supersedes"}]
39
- }
9
+ Persistent memory layer for AI agents. Remember decisions, recall context, learn from mistakes — across sessions.
10
+
11
+ ## How to Access (auto-detect)
12
+
13
+ ```
14
+ 1. MCP tools available? (remember, recall, forget, learn in your tool list)
15
+ YES: use MCP tools directly (fastest, structured I/O)
16
+ NO: continue to step 2
17
+
18
+ 2. CLI available? Run: memesh status
19
+ → Works: use CLI commands below
20
+ "command not found": Run: npx @pcircle/memesh status
21
+ Works: use npx @pcircle/memesh <command> for all commands below
22
+ ```
23
+
24
+ All examples below use CLI. MCP tools accept the same parameters as JSON objects.
25
+
26
+ ## What's Already Automatic (Claude Code Plugin Hooks)
27
+
28
+ If MeMesh is installed as a Claude Code plugin, these happen **without any action from you**:
29
+
30
+ | Hook | When | What it does |
31
+ |------|------|-------------|
32
+ | **SessionStart** | Every session begins | Auto-recalls top memories for current project + surfaces lesson warnings |
33
+ | **PostToolUse** | After `git commit` | Auto-tracks commit with diff stats as a memory entity |
34
+ | **Stop** | Session ends | Auto-captures session knowledge + runs LLM failure analysis → lessons |
35
+ | **PreCompact** | Before context compaction | Saves important knowledge before conversation history is compressed |
36
+
37
+ **You do NOT need to manually:**
38
+ - Recall at session start (hook does it)
39
+ - Remember commits (hook does it)
40
+ - Summarize sessions (hook does it)
41
+
42
+ **You DO need to manually** use the commands below for intentional knowledge management.
43
+
44
+ ## When to Use
45
+
46
+ ### Proactive triggers — do these WITHOUT being asked
47
+
48
+ | Situation | Action |
49
+ |-----------|--------|
50
+ | Design decision made | `memesh remember --name "auth-choice" --type decision --obs "Use OAuth 2.0 with PKCE" --tags "project:myapp"` |
51
+ | Bug fixed | `memesh learn --error "what broke" --fix "what fixed it" --root-cause "why" --severity major` |
52
+ | Pattern established | `memesh remember --name "validation-pattern" --type pattern --obs "Always use Zod"` |
53
+ | Starting work on a feature | `memesh recall "feature-name" --json` |
54
+ | User asks "what did we decide?" | `memesh recall "topic" --tag "project:myapp"` |
55
+ | Info is outdated | `memesh forget --name "old-decision"` |
56
+
57
+ ### When NOT to remember
58
+ - Trivial implementation details (variable names, import paths)
59
+ - Anything that took < 5 minutes to decide
60
+ - Information already in the codebase (comments, README, config)
61
+
62
+ ## Common Scenarios
63
+
64
+ ### You just fixed a bug
65
+ ```bash
66
+ memesh learn \
67
+ --error "SIGSEGV when running vitest with threads" \
68
+ --fix "Use pool: 'forks' instead of 'threads' for native modules" \
69
+ --root-cause "better-sqlite3 native module is not thread-safe" \
70
+ --prevention "Check if test framework supports native modules before choosing pool" \
71
+ --severity major
72
+ ```
73
+ This creates a `lesson_learned` entity. Lessons are surfaced as **proactive warnings** at next session start.
74
+
75
+ ### You need context before working
76
+ ```bash
77
+ memesh recall "authentication" --json
78
+ memesh recall --tag "project:myapp" --limit 10
79
+ memesh recall --cross-project # search across all projects
80
+ ```
81
+ Results are ranked by relevance, recency, frequency, confidence, and temporal validity.
82
+
83
+ ### A decision was just made
84
+ ```bash
85
+ memesh remember \
86
+ --name "db-choice-2026" \
87
+ --type decision \
88
+ --obs "Use SQLite for local-first" "Rejected PostgreSQL due to deployment complexity" \
89
+ --tags "project:myapp" "topic:database"
40
90
  ```
41
- Types: `decision`, `pattern`, `lesson`, `bug_fix`, `architecture`, `convention`
91
+ Types: `decision` `pattern` `lesson_learned` `bug_fix` `architecture` `convention` `feature` `best_practice` `concept` `tool` `note`
42
92
 
43
- ### recall
44
- ```json
45
- {"query": "authentication", "tag": "project:myapp", "limit": 10}
93
+ ### Old info needs updating
94
+ ```bash
95
+ memesh forget --name "old-auth-approach" # archive entire entity
96
+ memesh forget --name "auth-approach" --observation "Use JWT" # remove one fact only
46
97
  ```
47
- Omit query to list recent memories. Results are ranked by relevance, recency, and access frequency.
98
+ Archives (soft-delete). Never permanently removes.
48
99
 
49
- ### forget
50
- ```json
51
- {"name": "outdated-design"}
100
+ ### Memories are getting verbose
101
+ ```bash
102
+ memesh consolidate --name "entity-with-many-observations"
103
+ memesh consolidate --tag "project:myapp" --min-obs 5
52
104
  ```
53
- Archives the entity (soft-delete). Add `"observation": "specific text"` to remove just one fact.
105
+ Compresses observations using LLM. Requires Smart Mode configured.
54
106
 
55
- ### consolidate
56
- ```json
57
- {"name": "auth-history", "min_observations": 5}
107
+ ### Backup or share memories
108
+ ```bash
109
+ memesh export --tag "project:myapp" > memories.json
110
+ memesh import memories.json --merge skip # skip | overwrite | append
58
111
  ```
59
- Compresses verbose memories using LLM. Requires Smart Mode configured.
60
112
 
61
- ### export / import
62
- ```json
63
- {"tag": "project:myapp"}
113
+ ### Check MeMesh health
114
+ ```bash
115
+ memesh status # version, search level, embeddings
116
+ memesh config list # current configuration
64
117
  ```
65
- Export memories as JSON for sharing. Import with merge strategies: `skip`, `overwrite`, `append`.
118
+
119
+ ## MCP-Only Features
120
+
121
+ These require MCP tools or the HTTP API (`memesh serve` + REST calls):
122
+
123
+ - **user_patterns** — Analyzes work patterns (schedule, tool preferences, strengths) from existing memories. Categories: `workSchedule`, `toolPreferences`, `strengths`, `focusAreas`.
66
124
 
67
125
  ## Best Practices
68
126
 
69
127
  1. **Be specific** — "Use OAuth 2.0 with PKCE" not "auth stuff decided"
70
128
  2. **Tag by project** — Always include `project:<name>` tag
71
- 3. **Use relations**Link related decisions with `related-to`, replace old ones with `supersedes`
72
- 4. **Type correctly** — Use the right type (decision/pattern/lesson) for better search
73
- 5. **Don't over-remember** — Skip trivial things. Remember decisions that took > 5 minutes to make.
129
+ 3. **Use `--json`**When you need to parse output programmatically
130
+ 4. **Learn from every bug** — Every fix is a future warning. Use `learn`, not just `remember`.
131
+ 5. **Don't over-remember** — Decisions that took > 5 minutes. Patterns worth preserving. Not trivia.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: memesh-review
3
- description: Review and clean up the MeMesh memory database. Find stale, contradicting, or redundant memories and suggest cleanup actions. Use when asked to "review memories", "clean up knowledge", or "what's in my memory".
3
+ description: Review and optimize the MeMesh memory database. Analyzes health score, finds stale/conflicting/redundant memories, shows work patterns, and suggests cleanup actions. Use when asked to "review memories", "check memory health", "clean up knowledge", or "what's in my memory".
4
4
  user-invocable: true
5
5
  ---
6
6
 
@@ -8,47 +8,90 @@ user-invocable: true
8
8
 
9
9
  Review the memory database and provide actionable cleanup recommendations.
10
10
 
11
+ ## How to Access
12
+
13
+ Use CLI (works everywhere) or MCP tools (if available). See the `memesh` skill for auto-detect instructions.
14
+
11
15
  ## Process
12
16
 
13
- 1. **Recall recent memories** — use `recall` with no query to see what's stored
14
- 2. **Check for staleness** — identify memories not accessed in 30+ days
15
- 3. **Check for conflicts** — look for `contradicts` relations or opposing observations
16
- 4. **Check for verbosity** — entities with 5+ observations that could be consolidated
17
- 5. **Report findings** with specific actions
17
+ ### Step 1: Gather data
18
+
19
+ ```bash
20
+ # Get system health
21
+ memesh status
22
+
23
+ # Get all recent memories (structured output for analysis)
24
+ memesh recall --limit 50 --json
18
25
 
19
- ## Steps
26
+ # Get memories by type for quality analysis
27
+ memesh recall --tag "type:decision" --json
28
+ memesh recall --tag "type:lesson_learned" --json
29
+ memesh recall --tag "type:session_keypoint" --json
30
+ ```
20
31
 
21
- ### Step 1: Load overview
32
+ If MCP `user_patterns` tool is available, also run it for work pattern analysis:
22
33
  ```json
23
- recall: {"limit": 50}
34
+ user_patterns: {}
24
35
  ```
25
36
 
26
37
  ### Step 2: Analyze and report
27
38
 
28
- Present findings in this format:
39
+ From the recalled data, compute and present:
29
40
 
30
- ```
31
- ## Memory Review
41
+ ```markdown
42
+ ## Memory Health Report
43
+
44
+ ### Overview
45
+ - Total entities: N
46
+ - Last 30 days active: N (N%)
47
+ - Knowledge types: N decisions, N patterns, N lessons, N auto-tracked
48
+
49
+ ### Health Score: N/100
50
+ - Activity: N% (accessed in last 30 days)
51
+ - Quality: N% (high confidence, well-tagged)
52
+ - Freshness: N% (new this week)
53
+ - Self-Improvement: N% (lessons learned ratio)
32
54
 
33
- ### Summary
34
- - Total memories recalled: N
35
- - Active: N | Archived: N
55
+ ### Quality Issues Found
36
56
 
37
- ### Stale (not accessed in 30+ days)
38
- - "entity-name" — last observation: "..." — Suggest: archive or keep?
57
+ **Stale (not accessed 30+ days, low confidence)**
58
+ - "entity-name" — confidence: N% — Suggest: archive?
39
59
 
40
- ### Could be consolidated (5+ observations)
41
- - "entity-name" (8 observations) — Suggest: run consolidate
60
+ **Verbose (5+ observations, needs consolidation)**
61
+ - "entity-name" (N observations) — Suggest: `memesh consolidate --name "entity-name"`
42
62
 
43
- ### Potential conflicts
44
- - "use-jwt" vs "no-jwt" — contradicting auth decisions
63
+ **Potential conflicts**
64
+ - "entity-A" vs "entity-B" — contradicting decisions
45
65
 
46
- ### Recommended actions
47
- 1. Archive "old-design" (superseded by "new-design")
48
- 2. Consolidate "auth-history" (12 observations ~3)
49
- 3. Review conflict between "X" and "Y"
66
+ **Noise ratio**
67
+ - N% auto-tracked (session_keypoint, commit) vs N% intentional knowledge
68
+ - If noise > 80%: recommend more deliberate `memesh remember` usage
69
+
70
+ ### Recommended Actions
71
+ 1. `memesh forget --name "old-design"` (superseded)
72
+ 2. `memesh consolidate --name "auth-history"` (12 obs → ~3)
73
+ 3. `memesh remember ...` (knowledge gap in [area])
50
74
  ```
51
75
 
52
76
  ### Step 3: Execute approved actions
53
77
 
54
- After presenting the report, ask the user which actions to execute. Then use `forget`, `consolidate`, or `remember` with `supersedes` accordingly.
78
+ Present the report first. Ask which actions to execute. Then run the commands:
79
+
80
+ ```bash
81
+ memesh forget --name "outdated-entity"
82
+ memesh consolidate --name "verbose-entity"
83
+ memesh remember --name "missing-knowledge" --type decision --obs "..."
84
+ ```
85
+
86
+ ### Step 4: Verify
87
+
88
+ ```bash
89
+ memesh recall --limit 5 --json # confirm changes took effect
90
+ ```
91
+
92
+ ## Tips
93
+
94
+ - Run every 1-2 weeks to keep memory healthy
95
+ - Health score < 50 → too many stale or low-quality memories
96
+ - Noise > 80% → encourage deliberate `memesh remember` for decisions
97
+ - Dashboard available at: http://localhost:3737/dashboard (run `memesh serve` first)