@pcircle/memesh 2.9.2 → 2.9.4

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 (142) hide show
  1. package/README.de.md +119 -78
  2. package/README.es.md +116 -75
  3. package/README.fr.md +116 -75
  4. package/README.id.md +115 -74
  5. package/README.ja.md +111 -70
  6. package/README.ko.md +116 -75
  7. package/README.md +113 -72
  8. package/README.th.md +118 -77
  9. package/README.vi.md +116 -75
  10. package/README.zh-CN.md +120 -79
  11. package/README.zh-TW.md +116 -75
  12. package/dist/core/GitCommandParser.d.ts +11 -0
  13. package/dist/core/GitCommandParser.d.ts.map +1 -0
  14. package/dist/core/GitCommandParser.js +43 -0
  15. package/dist/core/GitCommandParser.js.map +1 -0
  16. package/dist/core/HookIntegration.d.ts +0 -3
  17. package/dist/core/HookIntegration.d.ts.map +1 -1
  18. package/dist/core/HookIntegration.js +6 -30
  19. package/dist/core/HookIntegration.js.map +1 -1
  20. package/dist/db/ConnectionPool.d.ts.map +1 -1
  21. package/dist/db/ConnectionPool.js +17 -1
  22. package/dist/db/ConnectionPool.js.map +1 -1
  23. package/dist/db/adapters/BetterSqlite3Adapter.d.ts.map +1 -1
  24. package/dist/db/adapters/BetterSqlite3Adapter.js +22 -0
  25. package/dist/db/adapters/BetterSqlite3Adapter.js.map +1 -1
  26. package/dist/embeddings/EmbeddingService.d.ts +3 -0
  27. package/dist/embeddings/EmbeddingService.d.ts.map +1 -1
  28. package/dist/embeddings/EmbeddingService.js +28 -6
  29. package/dist/embeddings/EmbeddingService.js.map +1 -1
  30. package/dist/embeddings/InMemoryVectorAdapter.d.ts +15 -0
  31. package/dist/embeddings/InMemoryVectorAdapter.d.ts.map +1 -0
  32. package/dist/embeddings/InMemoryVectorAdapter.js +58 -0
  33. package/dist/embeddings/InMemoryVectorAdapter.js.map +1 -0
  34. package/dist/embeddings/SqliteVecAdapter.d.ts +15 -0
  35. package/dist/embeddings/SqliteVecAdapter.d.ts.map +1 -0
  36. package/dist/embeddings/SqliteVecAdapter.js +107 -0
  37. package/dist/embeddings/SqliteVecAdapter.js.map +1 -0
  38. package/dist/embeddings/VectorExtension.d.ts +2 -4
  39. package/dist/embeddings/VectorExtension.d.ts.map +1 -1
  40. package/dist/embeddings/VectorExtension.js.map +1 -1
  41. package/dist/embeddings/VectorSearchAdapter.d.ts +17 -0
  42. package/dist/embeddings/VectorSearchAdapter.d.ts.map +1 -0
  43. package/dist/embeddings/VectorSearchAdapter.js +2 -0
  44. package/dist/embeddings/VectorSearchAdapter.js.map +1 -0
  45. package/dist/embeddings/index.d.ts +6 -1
  46. package/dist/embeddings/index.d.ts.map +1 -1
  47. package/dist/embeddings/index.js +4 -1
  48. package/dist/embeddings/index.js.map +1 -1
  49. package/dist/knowledge-graph/ContentHasher.d.ts +4 -0
  50. package/dist/knowledge-graph/ContentHasher.d.ts.map +1 -0
  51. package/dist/knowledge-graph/ContentHasher.js +8 -0
  52. package/dist/knowledge-graph/ContentHasher.js.map +1 -0
  53. package/dist/knowledge-graph/KGSearchEngine.d.ts +37 -0
  54. package/dist/knowledge-graph/KGSearchEngine.d.ts.map +1 -0
  55. package/dist/knowledge-graph/KGSearchEngine.js +257 -0
  56. package/dist/knowledge-graph/KGSearchEngine.js.map +1 -0
  57. package/dist/knowledge-graph/index.d.ts +18 -7
  58. package/dist/knowledge-graph/index.d.ts.map +1 -1
  59. package/dist/knowledge-graph/index.js +147 -242
  60. package/dist/knowledge-graph/index.js.map +1 -1
  61. package/dist/mcp/ServerInitializer.d.ts.map +1 -1
  62. package/dist/mcp/ServerInitializer.js +1 -1
  63. package/dist/mcp/ServerInitializer.js.map +1 -1
  64. package/dist/mcp/StdinBufferManager.d.ts +11 -0
  65. package/dist/mcp/StdinBufferManager.d.ts.map +1 -0
  66. package/dist/mcp/StdinBufferManager.js +62 -0
  67. package/dist/mcp/StdinBufferManager.js.map +1 -0
  68. package/dist/mcp/ToolDefinitions.js +3 -3
  69. package/dist/mcp/ToolDefinitions.js.map +1 -1
  70. package/dist/mcp/daemon/StdioProxyClient.d.ts.map +1 -1
  71. package/dist/mcp/daemon/StdioProxyClient.js +6 -0
  72. package/dist/mcp/daemon/StdioProxyClient.js.map +1 -1
  73. package/dist/mcp/handlers/HookToolHandler.d.ts +10 -0
  74. package/dist/mcp/handlers/HookToolHandler.d.ts.map +1 -0
  75. package/dist/mcp/handlers/HookToolHandler.js +92 -0
  76. package/dist/mcp/handlers/HookToolHandler.js.map +1 -0
  77. package/dist/mcp/handlers/MemoryToolHandler.d.ts +21 -0
  78. package/dist/mcp/handlers/MemoryToolHandler.d.ts.map +1 -0
  79. package/dist/mcp/handlers/MemoryToolHandler.js +430 -0
  80. package/dist/mcp/handlers/MemoryToolHandler.js.map +1 -0
  81. package/dist/mcp/handlers/SystemToolHandler.d.ts +14 -0
  82. package/dist/mcp/handlers/SystemToolHandler.d.ts.map +1 -0
  83. package/dist/mcp/handlers/SystemToolHandler.js +224 -0
  84. package/dist/mcp/handlers/SystemToolHandler.js.map +1 -0
  85. package/dist/mcp/handlers/ToolHandlers.d.ts +4 -17
  86. package/dist/mcp/handlers/ToolHandlers.d.ts.map +1 -1
  87. package/dist/mcp/handlers/ToolHandlers.js +19 -689
  88. package/dist/mcp/handlers/ToolHandlers.js.map +1 -1
  89. package/dist/mcp/handlers/index.d.ts +3 -0
  90. package/dist/mcp/handlers/index.d.ts.map +1 -1
  91. package/dist/mcp/handlers/index.js +3 -0
  92. package/dist/mcp/handlers/index.js.map +1 -1
  93. package/dist/mcp/server-bootstrap.js +24 -59
  94. package/dist/mcp/server-bootstrap.js.map +1 -1
  95. package/dist/mcp/tools/buddy-do.d.ts.map +1 -1
  96. package/dist/mcp/tools/buddy-do.js +17 -1
  97. package/dist/mcp/tools/buddy-do.js.map +1 -1
  98. package/dist/mcp/tools/buddy-remember.d.ts +1 -1
  99. package/dist/mcp/tools/buddy-remember.d.ts.map +1 -1
  100. package/dist/mcp/tools/buddy-remember.js +58 -16
  101. package/dist/mcp/tools/buddy-remember.js.map +1 -1
  102. package/dist/mcp/tools/create-entities.d.ts.map +1 -1
  103. package/dist/mcp/tools/create-entities.js +18 -24
  104. package/dist/mcp/tools/create-entities.js.map +1 -1
  105. package/dist/memory/MemorySearchEngine.d.ts +17 -0
  106. package/dist/memory/MemorySearchEngine.d.ts.map +1 -0
  107. package/dist/memory/MemorySearchEngine.js +88 -0
  108. package/dist/memory/MemorySearchEngine.js.map +1 -0
  109. package/dist/memory/ProactiveRecaller.d.ts +26 -0
  110. package/dist/memory/ProactiveRecaller.d.ts.map +1 -0
  111. package/dist/memory/ProactiveRecaller.js +96 -0
  112. package/dist/memory/ProactiveRecaller.js.map +1 -0
  113. package/dist/memory/UnifiedMemoryStore.d.ts +1 -0
  114. package/dist/memory/UnifiedMemoryStore.d.ts.map +1 -1
  115. package/dist/memory/UnifiedMemoryStore.js +12 -64
  116. package/dist/memory/UnifiedMemoryStore.js.map +1 -1
  117. package/dist/memory/index.d.ts +3 -0
  118. package/dist/memory/index.d.ts.map +1 -1
  119. package/dist/memory/index.js +2 -0
  120. package/dist/memory/index.js.map +1 -1
  121. package/dist/ui/MetricsStore.d.ts.map +1 -1
  122. package/dist/ui/MetricsStore.js +21 -2
  123. package/dist/ui/MetricsStore.js.map +1 -1
  124. package/dist/utils/index.d.ts +0 -2
  125. package/dist/utils/index.d.ts.map +1 -1
  126. package/dist/utils/index.js +0 -2
  127. package/dist/utils/index.js.map +1 -1
  128. package/dist/utils/tracing/index.d.ts +0 -1
  129. package/dist/utils/tracing/index.d.ts.map +1 -1
  130. package/dist/utils/tracing/index.js +0 -1
  131. package/dist/utils/tracing/index.js.map +1 -1
  132. package/package.json +2 -12
  133. package/plugin.json +1 -1
  134. package/scripts/hooks/__tests__/post-tool-use-recall.test.js +192 -0
  135. package/scripts/hooks/__tests__/session-start-recall.test.js +86 -0
  136. package/scripts/hooks/post-tool-use-recall-utils.js +74 -0
  137. package/scripts/hooks/post-tool-use.js +83 -0
  138. package/scripts/hooks/pre-tool-use.js +30 -1
  139. package/scripts/hooks/session-start-recall-utils.js +40 -0
  140. package/scripts/hooks/session-start.js +66 -0
  141. package/scripts/hooks/templates/planning-template.md +46 -0
  142. package/scripts/postinstall-new.js +8 -1
@@ -125,11 +125,21 @@ function mergeResponses(responses) {
125
125
  // Routing Config
126
126
  // ============================================================================
127
127
 
128
+ /** Module-level cache for routing config (30-second TTL) */
129
+ let _routingConfigCache = null;
130
+ let _routingConfigTimestamp = 0;
131
+ const ROUTING_CONFIG_TTL_MS = 30_000;
132
+
128
133
  /**
129
134
  * Load routing config with fallback defaults.
130
135
  * Creates default config if file doesn't exist.
136
+ * Results are cached for 30 seconds to avoid repeated file I/O.
131
137
  */
132
138
  function loadRoutingConfig() {
139
+ const now = Date.now();
140
+ if (_routingConfigCache && (now - _routingConfigTimestamp) < ROUTING_CONFIG_TTL_MS) {
141
+ return _routingConfigCache;
142
+ }
133
143
  const defaults = {
134
144
  version: 1,
135
145
  modelRouting: {
@@ -156,7 +166,10 @@ function loadRoutingConfig() {
156
166
  try {
157
167
  if (fs.existsSync(ROUTING_CONFIG_FILE)) {
158
168
  const config = JSON.parse(fs.readFileSync(ROUTING_CONFIG_FILE, 'utf-8'));
159
- return { ...defaults, ...config };
169
+ const merged = { ...defaults, ...config };
170
+ _routingConfigCache = merged;
171
+ _routingConfigTimestamp = now;
172
+ return merged;
160
173
  }
161
174
  } catch (error) {
162
175
  logError('loadRoutingConfig', error);
@@ -173,6 +186,8 @@ function loadRoutingConfig() {
173
186
  // Non-critical — works with in-memory defaults
174
187
  }
175
188
 
189
+ _routingConfigCache = defaults;
190
+ _routingConfigTimestamp = now;
176
191
  return defaults;
177
192
  }
178
193
 
@@ -185,10 +200,24 @@ function loadRoutingConfig() {
185
200
  * @param {string} entry - Log entry
186
201
  * @param {Object} config - Routing config
187
202
  */
203
+ const AUDIT_LOG_MAX_BYTES = 1_048_576; // 1 MB
204
+ const AUDIT_LOG_KEEP_LINES = 500;
205
+
188
206
  function auditLog(entry, config) {
189
207
  if (!config.auditLog) return;
190
208
 
191
209
  try {
210
+ // Rotate if log exceeds 1 MB: keep only the last 500 lines
211
+ if (fs.existsSync(ROUTING_AUDIT_LOG)) {
212
+ const stat = fs.statSync(ROUTING_AUDIT_LOG);
213
+ if (stat.size > AUDIT_LOG_MAX_BYTES) {
214
+ const content = fs.readFileSync(ROUTING_AUDIT_LOG, 'utf-8');
215
+ const lines = content.split('\n');
216
+ const truncated = lines.slice(-AUDIT_LOG_KEEP_LINES).join('\n');
217
+ fs.writeFileSync(ROUTING_AUDIT_LOG, truncated);
218
+ }
219
+ }
220
+
192
221
  const timestamp = new Date().toISOString();
193
222
  const line = `[${timestamp}] ${entry}\n`;
194
223
  fs.appendFileSync(ROUTING_AUDIT_LOG, line);
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Session-Start Recall Utilities
3
+ *
4
+ * Utility functions for proactive memory recall during session start.
5
+ * Builds search queries from project context and formats recall results.
6
+ */
7
+
8
+ /**
9
+ * Build FTS5 search query from project name and recent commits.
10
+ * Strips conventional commit prefixes (fix:, feat(scope):, etc.)
11
+ * @param {string} projectName
12
+ * @param {string[]} recentCommits
13
+ * @returns {string}
14
+ */
15
+ export function buildSessionRecallQuery(projectName, recentCommits = []) {
16
+ const parts = [projectName];
17
+ if (recentCommits.length > 0) {
18
+ const cleaned = recentCommits
19
+ .map(msg => msg.replace(/^(fix|feat|chore|refactor|perf|docs|test|style|ci)\(?[^)]*\)?:\s*/i, '').trim())
20
+ .filter(msg => msg.length > 0);
21
+ parts.push(...cleaned);
22
+ }
23
+ return parts.join(' ').trim();
24
+ }
25
+
26
+ /**
27
+ * Format recall results for hook output display.
28
+ * Shows max 2 observations per entity.
29
+ * @param {Array<{name: string, observations: string[], similarity: number}>} results
30
+ * @returns {string} Formatted output (empty string if no results)
31
+ */
32
+ export function formatRecallOutput(results) {
33
+ if (!results || results.length === 0) return '';
34
+ const lines = results.map(r => {
35
+ const pct = Math.round(r.similarity * 100);
36
+ const obs = r.observations.slice(0, 2).join('; ');
37
+ return ` - ${r.name} (${pct}%): ${obs}`;
38
+ });
39
+ return lines.join('\n');
40
+ }
@@ -27,8 +27,10 @@ import {
27
27
  queryActivePlans,
28
28
  renderTimelineCompact,
29
29
  } from './hook-utils.js';
30
+ import { buildSessionRecallQuery, formatRecallOutput } from './session-start-recall-utils.js';
30
31
  import fs from 'fs';
31
32
  import path from 'path';
33
+ import { execFileSync } from 'child_process';
32
34
 
33
35
  // ============================================================================
34
36
  // File Paths
@@ -444,6 +446,67 @@ function displayActivePlans() {
444
446
  }
445
447
  }
446
448
 
449
+ /**
450
+ * Proactive memory recall — queries KG for memories related to current project.
451
+ * Uses project name + last 3 git commits as search query.
452
+ */
453
+ function recallProactiveMemories() {
454
+ try {
455
+ const projectName = path.basename(process.cwd());
456
+
457
+ let recentCommits = [];
458
+ try {
459
+ const gitOutput = execFileSync('git', ['log', '--oneline', '-3', '--format=%s'], {
460
+ timeout: 3000,
461
+ encoding: 'utf-8',
462
+ cwd: process.cwd(),
463
+ });
464
+ recentCommits = gitOutput.trim().split('\n').filter(Boolean);
465
+ } catch {
466
+ // Not a git repo or no commits
467
+ }
468
+
469
+ const query = buildSessionRecallQuery(projectName, recentCommits);
470
+ if (!query) return;
471
+
472
+ // Build FTS5 tokens
473
+ const ftsTokens = query.split(/\s+/)
474
+ .filter(t => t.length > 2)
475
+ .slice(0, 10)
476
+ .map(t => `"${t.replace(/"/g, '""')}"*`)
477
+ .join(' OR ');
478
+
479
+ if (!ftsTokens) return;
480
+
481
+ const sql = `
482
+ SELECT e.name, e.type,
483
+ (SELECT json_group_array(content) FROM observations o WHERE o.entity_id = e.id) as observations_json
484
+ FROM entities e
485
+ JOIN entities_fts ON entities_fts.rowid = e.id
486
+ WHERE entities_fts MATCH ?
487
+ ORDER BY bm25(entities_fts, 10.0, 5.0)
488
+ LIMIT 5
489
+ `;
490
+
491
+ const result = sqliteQueryJSON(MEMESH_DB_PATH, sql, [ftsTokens]);
492
+ if (!result || result.length === 0) return;
493
+
494
+ const formatted = result.map(r => ({
495
+ name: r.name,
496
+ observations: JSON.parse(r.observations_json || '[]').filter(Boolean).slice(0, 3),
497
+ similarity: 0.5,
498
+ }));
499
+
500
+ const output = formatRecallOutput(formatted);
501
+ if (output) {
502
+ console.log('\n Proactive Memory Recall:');
503
+ console.log(output);
504
+ }
505
+ } catch (error) {
506
+ logError('proactive-recall', error);
507
+ }
508
+ }
509
+
447
510
  function sessionStart() {
448
511
  console.log('\nšŸš€ Smart-Agents Session Started\n');
449
512
 
@@ -458,6 +521,9 @@ function sessionStart() {
458
521
  const recalledMemory = recallRecentKeyPoints();
459
522
  displayRecalledMemory(recalledMemory);
460
523
 
524
+ // Proactive memory recall (project context + recent commits)
525
+ recallProactiveMemories();
526
+
461
527
  // Display active plans (beta)
462
528
  displayActivePlans();
463
529
 
@@ -0,0 +1,46 @@
1
+ ## Required Plan Sections
2
+
3
+ Your plan MUST include all of the following sections. Incomplete plans will be rejected.
4
+
5
+ ### 1. System Design Description (SDD)
6
+ - Component architecture and responsibilities
7
+ - Data flow between components
8
+ - Interface contracts (input/output types)
9
+ - Dependencies and integration points
10
+
11
+ ### 2. Behavior-Driven Design (BDD)
12
+ For EACH feature, write Gherkin scenarios:
13
+
14
+ ```gherkin
15
+ Scenario: [descriptive name]
16
+ Given [precondition]
17
+ When [action]
18
+ Then [expected outcome]
19
+ ```
20
+
21
+ Cover: happy path, error path, edge cases.
22
+
23
+ ### 3. Edge Case Handling
24
+
25
+ | Edge Case | How Handled | Test Coverage |
26
+ |-----------|------------|---------------|
27
+ | [case] | [strategy] | [yes/no] |
28
+
29
+ Include at minimum: empty input, null/undefined, boundary values, concurrent access, timeout, large data.
30
+
31
+ ### 4. Dry-Run Test Plan
32
+ Before dispatching heavy tasks, verify:
33
+ - [ ] Core function compiles (`tsc --noEmit` or `node --check`)
34
+ - [ ] Unit test for critical path passes
35
+ - [ ] Integration point verified with real call
36
+ - [ ] No regressions in existing tests
37
+
38
+ ### 5. Risk Assessment
39
+
40
+ | Risk | Probability | Impact | Mitigation |
41
+ |------|------------|--------|------------|
42
+ | [risk] | High/Med/Low | High/Med/Low | [strategy] |
43
+
44
+ ---
45
+
46
+ **IMPORTANT**: After completing this plan, present it to the user and wait for explicit approval before proceeding to implementation. Do NOT auto-execute.
@@ -284,7 +284,14 @@ ${chalk.dim('Need help? Open an issue: https://github.com/PCIRCLE-AI/claude-code
284
284
  );
285
285
 
286
286
  // Exit with appropriate code
287
- process.exit(allSuccess ? 0 : 0); // Non-fatal warnings still exit 0
287
+ // Critical failures (MCP config, plugin registration) → exit 1
288
+ // Non-critical failures (skills, symlink already exists) → exit 0
289
+ const hasCriticalFailure = !results.mcpConfigured && results.mode !== 'local';
290
+ const hasPluginFailure = !results.pluginEnabled;
291
+ if (hasCriticalFailure || hasPluginFailure) {
292
+ process.exit(1);
293
+ }
294
+ process.exit(0);
288
295
  }
289
296
 
290
297
  // ============================================================================