cortex-mcp 1.2.4 → 1.4.1

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 (63) hide show
  1. package/dist/db/memory-store.d.ts +2 -2
  2. package/dist/db/memory-store.d.ts.map +1 -1
  3. package/dist/db/memory-store.js +26 -4
  4. package/dist/db/memory-store.js.map +1 -1
  5. package/dist/memory/auto-learner.d.ts.map +1 -1
  6. package/dist/memory/auto-learner.js +62 -23
  7. package/dist/memory/auto-learner.js.map +1 -1
  8. package/dist/memory/convention-detector.d.ts +11 -0
  9. package/dist/memory/convention-detector.d.ts.map +1 -0
  10. package/dist/memory/convention-detector.js +294 -0
  11. package/dist/memory/convention-detector.js.map +1 -0
  12. package/dist/memory/correction-detector.d.ts +33 -0
  13. package/dist/memory/correction-detector.d.ts.map +1 -0
  14. package/dist/memory/correction-detector.js +129 -0
  15. package/dist/memory/correction-detector.js.map +1 -0
  16. package/dist/memory/error-learner.d.ts +26 -0
  17. package/dist/memory/error-learner.d.ts.map +1 -0
  18. package/dist/memory/error-learner.js +145 -0
  19. package/dist/memory/error-learner.js.map +1 -0
  20. package/dist/memory/file-relationships.d.ts +47 -0
  21. package/dist/memory/file-relationships.d.ts.map +1 -0
  22. package/dist/memory/file-relationships.js +130 -0
  23. package/dist/memory/file-relationships.js.map +1 -0
  24. package/dist/memory/impact-analyzer.d.ts +16 -0
  25. package/dist/memory/impact-analyzer.d.ts.map +1 -0
  26. package/dist/memory/impact-analyzer.js +189 -0
  27. package/dist/memory/impact-analyzer.js.map +1 -0
  28. package/dist/memory/instructions-generator.d.ts +30 -0
  29. package/dist/memory/instructions-generator.d.ts.map +1 -0
  30. package/dist/memory/instructions-generator.js +117 -0
  31. package/dist/memory/instructions-generator.js.map +1 -0
  32. package/dist/memory/pre-flight.d.ts +24 -0
  33. package/dist/memory/pre-flight.d.ts.map +1 -0
  34. package/dist/memory/pre-flight.js +121 -0
  35. package/dist/memory/pre-flight.js.map +1 -0
  36. package/dist/memory/preference-learner.d.ts +28 -0
  37. package/dist/memory/preference-learner.d.ts.map +1 -0
  38. package/dist/memory/preference-learner.js +144 -0
  39. package/dist/memory/preference-learner.js.map +1 -0
  40. package/dist/memory/regression-guard.d.ts +35 -0
  41. package/dist/memory/regression-guard.d.ts.map +1 -0
  42. package/dist/memory/regression-guard.js +90 -0
  43. package/dist/memory/regression-guard.js.map +1 -0
  44. package/dist/memory/resume-work.d.ts +37 -0
  45. package/dist/memory/resume-work.d.ts.map +1 -0
  46. package/dist/memory/resume-work.js +122 -0
  47. package/dist/memory/resume-work.js.map +1 -0
  48. package/dist/memory/success-tracker.d.ts +33 -0
  49. package/dist/memory/success-tracker.d.ts.map +1 -0
  50. package/dist/memory/success-tracker.js +75 -0
  51. package/dist/memory/success-tracker.js.map +1 -0
  52. package/dist/memory/tool-recommender.d.ts +29 -0
  53. package/dist/memory/tool-recommender.d.ts.map +1 -0
  54. package/dist/memory/tool-recommender.js +117 -0
  55. package/dist/memory/tool-recommender.js.map +1 -0
  56. package/dist/memory/usage-stats.d.ts +59 -0
  57. package/dist/memory/usage-stats.d.ts.map +1 -0
  58. package/dist/memory/usage-stats.js +122 -0
  59. package/dist/memory/usage-stats.js.map +1 -0
  60. package/dist/server/mcp-handler.d.ts.map +1 -1
  61. package/dist/server/mcp-handler.js +634 -14
  62. package/dist/server/mcp-handler.js.map +1 -1
  63. package/package.json +1 -1
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectPreferences = detectPreferences;
4
+ exports.getStoredPreferences = getStoredPreferences;
5
+ // ─── Preference Detection Patterns ───────────────────────────────────────────
6
+ const PREFERENCE_PATTERNS = [
7
+ // Communication style
8
+ {
9
+ category: 'communication',
10
+ signals: [
11
+ /\b(keep it short|be (more )?(brief|concise)|too (long|verbose)|shorter|less (text|detail))\b/gi,
12
+ /\b(tldr|tl;dr|just the (code|answer)|skip the explanation)\b/gi,
13
+ ],
14
+ preference: 'User prefers concise, short responses — skip long explanations',
15
+ confidence: 0.85,
16
+ },
17
+ {
18
+ category: 'communication',
19
+ signals: [
20
+ /\b(explain (more|why|how)|tell me (more|why)|what does .{3,20} mean|I don'?t understand)\b/gi,
21
+ /\b(more detail|elaborate|walk me through|step by step)\b/gi,
22
+ ],
23
+ preference: 'User prefers detailed explanations — explain reasoning and steps',
24
+ confidence: 0.80,
25
+ },
26
+ // Workflow style
27
+ {
28
+ category: 'workflow',
29
+ signals: [
30
+ /\b(just (do|fix|change|build) it|don'?t ask|stop asking|go ahead)\b/gi,
31
+ /\b(you decide|your (call|choice)|whatever you think|I trust you)\b/gi,
32
+ ],
33
+ preference: 'User prefers autonomous execution — do it without asking for approval',
34
+ confidence: 0.85,
35
+ },
36
+ {
37
+ category: 'workflow',
38
+ signals: [
39
+ /\b(ask (me|first)|check with me|don'?t (change|modify) (without|until)|show me (first|before))\b/gi,
40
+ /\b(let me (review|see|approve)|wait for (my|approval))\b/gi,
41
+ ],
42
+ preference: 'User prefers to review before changes — always ask before modifying',
43
+ confidence: 0.85,
44
+ },
45
+ // Coding style
46
+ {
47
+ category: 'coding',
48
+ signals: [
49
+ /\b(use (typescript|ts)|type(d|safe|safety)|add types|interface|generic)\b/gi,
50
+ ],
51
+ preference: 'User values TypeScript strict typing — always add types and interfaces',
52
+ confidence: 0.70,
53
+ },
54
+ {
55
+ category: 'coding',
56
+ signals: [
57
+ /\b(add (tests|test)|test (first|coverage)|write (a )?test|unit test|spec)\b/gi,
58
+ ],
59
+ preference: 'User values testing — write tests alongside code',
60
+ confidence: 0.75,
61
+ },
62
+ {
63
+ category: 'coding',
64
+ signals: [
65
+ /\b(no (comments|documentation)|don'?t add comments|too many comments|over.?comment)\b/gi,
66
+ ],
67
+ preference: 'User prefers minimal comments — code should be self-documenting',
68
+ confidence: 0.75,
69
+ },
70
+ {
71
+ category: 'coding',
72
+ signals: [
73
+ /\b(add comments|document|jsdoc|explain the code|comment the|well.?documented)\b/gi,
74
+ ],
75
+ preference: 'User values code documentation — add comments and JSDoc',
76
+ confidence: 0.75,
77
+ },
78
+ // Style preferences
79
+ {
80
+ category: 'style',
81
+ signals: [
82
+ /\b(dark (mode|theme)|prefer dark|use dark)\b/gi,
83
+ ],
84
+ preference: 'User prefers dark mode/theme',
85
+ confidence: 0.80,
86
+ },
87
+ {
88
+ category: 'style',
89
+ signals: [
90
+ /\b(simple|minimal|minimalist|clean|no (fancy|animation|effect))\b/gi,
91
+ ],
92
+ preference: 'User prefers simple, minimalist design — avoid complex UI effects',
93
+ confidence: 0.70,
94
+ },
95
+ ];
96
+ // ─── Main Detector ───────────────────────────────────────────────────────────
97
+ /**
98
+ * Detect user preferences from their message text.
99
+ * Call this from auto_learn when context is provided.
100
+ */
101
+ function detectPreferences(userText) {
102
+ if (!userText || userText.length < 10)
103
+ return [];
104
+ const results = [];
105
+ const seen = new Set();
106
+ for (const pattern of PREFERENCE_PATTERNS) {
107
+ for (const signal of pattern.signals) {
108
+ signal.lastIndex = 0;
109
+ const match = signal.exec(userText);
110
+ if (match && !seen.has(pattern.preference)) {
111
+ seen.add(pattern.preference);
112
+ results.push({
113
+ category: pattern.category,
114
+ preference: pattern.preference,
115
+ confidence: pattern.confidence,
116
+ evidence: match[0].trim().slice(0, 100),
117
+ });
118
+ break;
119
+ }
120
+ }
121
+ }
122
+ return results;
123
+ }
124
+ /**
125
+ * Get all stored preferences for injection into force_recall.
126
+ */
127
+ function getStoredPreferences(memoryStore) {
128
+ // Search for preference-tagged memories
129
+ try {
130
+ const results = memoryStore.searchFTS('preference', 10);
131
+ const prefs = results.filter(r => r.memory.tags?.includes('preference') || r.memory.type === 'CONVENTION');
132
+ if (prefs.length === 0)
133
+ return '';
134
+ const lines = ['## 👤 User Preferences'];
135
+ for (const p of prefs.slice(0, 5)) {
136
+ lines.push(`- ${p.memory.intent}`);
137
+ }
138
+ return lines.join('\n');
139
+ }
140
+ catch {
141
+ return '';
142
+ }
143
+ }
144
+ //# sourceMappingURL=preference-learner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preference-learner.js","sourceRoot":"","sources":["../../src/memory/preference-learner.ts"],"names":[],"mappings":";;AA+HA,8CAwBC;AAKD,oDAkBC;AA1JD,gFAAgF;AAEhF,MAAM,mBAAmB,GAKpB;IACD,sBAAsB;IACtB;QACI,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE;YACL,gGAAgG;YAChG,gEAAgE;SACnE;QACD,UAAU,EAAE,gEAAgE;QAC5E,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,eAAe;QACzB,OAAO,EAAE;YACL,8FAA8F;YAC9F,4DAA4D;SAC/D;QACD,UAAU,EAAE,kEAAkE;QAC9E,UAAU,EAAE,IAAI;KACnB;IAED,iBAAiB;IACjB;QACI,QAAQ,EAAE,UAAU;QACpB,OAAO,EAAE;YACL,uEAAuE;YACvE,sEAAsE;SACzE;QACD,UAAU,EAAE,uEAAuE;QACnF,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,UAAU;QACpB,OAAO,EAAE;YACL,oGAAoG;YACpG,4DAA4D;SAC/D;QACD,UAAU,EAAE,qEAAqE;QACjF,UAAU,EAAE,IAAI;KACnB;IAED,eAAe;IACf;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,6EAA6E;SAChF;QACD,UAAU,EAAE,wEAAwE;QACpF,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,+EAA+E;SAClF;QACD,UAAU,EAAE,kDAAkD;QAC9D,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,yFAAyF;SAC5F;QACD,UAAU,EAAE,iEAAiE;QAC7E,UAAU,EAAE,IAAI;KACnB;IACD;QACI,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE;YACL,mFAAmF;SACtF;QACD,UAAU,EAAE,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L,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,WAAwB;IACzD,wCAAwC;IACxC,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAC7B,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,CAAC,IAAK,CAAC,CAAC,MAAM,CAAC,IAAe,KAAK,YAAY,CACtF,CAAC;QAEF,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAElC,MAAM,KAAK,GAAa,CAAC,wBAAwB,CAAC,CAAC;QACnD,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Regression Guard — Stores verification steps alongside bug fixes.
3
+ *
4
+ * THE GAP THIS FILLS:
5
+ * When a bug is fixed, the AI stores WHAT was fixed but not HOW to verify
6
+ * it didn't regress. Next time a similar issue appears, the AI has to
7
+ * figure out testing from scratch.
8
+ *
9
+ * This module:
10
+ * 1. Attaches verification steps to BUG_FIX memories
11
+ * 2. When a similar bug appears, surfaces both the fix AND the test
12
+ * 3. Tracks which fixes have been verified vs unverified
13
+ */
14
+ import { MemoryStore } from '../db/memory-store';
15
+ export interface VerificationStep {
16
+ command?: string;
17
+ check?: string;
18
+ file?: string;
19
+ }
20
+ /**
21
+ * Extract verification steps from AI text.
22
+ * Looks for build/test commands and their expected outcomes.
23
+ */
24
+ export declare function extractVerificationSteps(text: string): VerificationStep[];
25
+ /**
26
+ * Find verification steps for similar past bugs.
27
+ * When a new bug appears, search for related fixes and their verification.
28
+ */
29
+ export declare function findRelatedVerification(memoryStore: MemoryStore, bugDescription: string): string[];
30
+ /**
31
+ * Attach verification steps to a bug fix description.
32
+ * Returns enhanced text with verification section appended.
33
+ */
34
+ export declare function attachVerification(fixDescription: string, steps: VerificationStep[]): string;
35
+ //# sourceMappingURL=regression-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regression-guard.d.ts","sourceRoot":"","sources":["../../src/memory/regression-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,gBAAgB;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAsCzE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBlG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAkB5F"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractVerificationSteps = extractVerificationSteps;
4
+ exports.findRelatedVerification = findRelatedVerification;
5
+ exports.attachVerification = attachVerification;
6
+ const types_1 = require("../types");
7
+ /**
8
+ * Extract verification steps from AI text.
9
+ * Looks for build/test commands and their expected outcomes.
10
+ */
11
+ function extractVerificationSteps(text) {
12
+ const steps = [];
13
+ const seen = new Set();
14
+ // 1. npm commands
15
+ const npmRegex = /npm\s+(?:run\s+)?(\w+)/gi;
16
+ let match;
17
+ while ((match = npmRegex.exec(text)) !== null) {
18
+ const cmd = match[0];
19
+ if (seen.has(cmd))
20
+ continue;
21
+ seen.add(cmd);
22
+ // Look for expected result near the command
23
+ const nearText = text.slice(Math.max(0, match.index - 100), match.index + 200);
24
+ let check = '';
25
+ if (/0\s+error|no\s+error|pass|success/i.test(nearText)) {
26
+ check = 'Should succeed with 0 errors';
27
+ }
28
+ else if (/fail|error|broke/i.test(nearText)) {
29
+ check = 'Was failing — verify it passes now';
30
+ }
31
+ steps.push({ command: cmd, check: check || `Run ${cmd} and verify output` });
32
+ }
33
+ // 2. Test file references
34
+ const testRegex = /(\w+\.(?:test|spec)\.\w+)/gi;
35
+ while ((match = testRegex.exec(text)) !== null) {
36
+ if (seen.has(match[1]))
37
+ continue;
38
+ seen.add(match[1]);
39
+ steps.push({ file: match[1], check: `Run tests in ${match[1]}` });
40
+ }
41
+ // 3. Build verification
42
+ if (/tsc|compile|typescript/i.test(text) && !seen.has('build')) {
43
+ steps.push({ command: 'npm run build', check: 'TypeScript compilation should have 0 errors' });
44
+ }
45
+ return steps.slice(0, 5);
46
+ }
47
+ /**
48
+ * Find verification steps for similar past bugs.
49
+ * When a new bug appears, search for related fixes and their verification.
50
+ */
51
+ function findRelatedVerification(memoryStore, bugDescription) {
52
+ const verifications = [];
53
+ try {
54
+ const results = memoryStore.searchFTS(bugDescription, 10);
55
+ for (const r of results) {
56
+ if (r.memory.type === types_1.MemoryType.BUG_FIX && r.memory.action) {
57
+ // Check if action contains verification info
58
+ const action = r.memory.action;
59
+ if (/verify|test|check|build|npm|command/i.test(action)) {
60
+ verifications.push(`📋 For "${r.memory.intent.slice(0, 60)}": ${action.slice(0, 150)}`);
61
+ }
62
+ }
63
+ }
64
+ }
65
+ catch { /* non-fatal */ }
66
+ return verifications.slice(0, 5);
67
+ }
68
+ /**
69
+ * Attach verification steps to a bug fix description.
70
+ * Returns enhanced text with verification section appended.
71
+ */
72
+ function attachVerification(fixDescription, steps) {
73
+ if (steps.length === 0)
74
+ return fixDescription;
75
+ let enhanced = fixDescription;
76
+ enhanced += '\n\n--- Verification ---';
77
+ for (const step of steps) {
78
+ if (step.command) {
79
+ enhanced += `\nRun: ${step.command}`;
80
+ }
81
+ if (step.file) {
82
+ enhanced += `\nCheck: ${step.file}`;
83
+ }
84
+ if (step.check) {
85
+ enhanced += ` → ${step.check}`;
86
+ }
87
+ }
88
+ return enhanced;
89
+ }
90
+ //# sourceMappingURL=regression-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regression-guard.js","sourceRoot":"","sources":["../../src/memory/regression-guard.ts"],"names":[],"mappings":";;AA0BA,4DAsCC;AAMD,0DAiBC;AAMD,gDAkBC;AAjGD,oCAAsC;AAQtC;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,IAAY;IACjD,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,kBAAkB;IAClB,MAAM,QAAQ,GAAG,0BAA0B,CAAC;IAC5C,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QAC5C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEd,4CAA4C;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC;QAC/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AC;QACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,QAAQ,IAAI,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Resume Work — Context recovery after conversation truncation.
3
+ *
4
+ * When a long conversation gets cut off, the AI loses context.
5
+ * This module surfaces: what was the last session about, what changed,
6
+ * what was in progress, and what's still remaining.
7
+ *
8
+ * Like opening your notebook and seeing "stopped at step 3 of 7".
9
+ */
10
+ import { MemoryStore } from '../db/memory-store';
11
+ export interface ResumeContext {
12
+ lastSession: string | null;
13
+ recentMemories: Array<{
14
+ type: string;
15
+ intent: string;
16
+ age: string;
17
+ }>;
18
+ currentTasks: Array<{
19
+ intent: string;
20
+ age: string;
21
+ }>;
22
+ recentCorrections: Array<{
23
+ intent: string;
24
+ age: string;
25
+ }>;
26
+ recentDecisions: Array<{
27
+ intent: string;
28
+ age: string;
29
+ }>;
30
+ }
31
+ /**
32
+ * Build context for resuming work after a conversation break.
33
+ */
34
+ export declare function buildResumeContext(memoryStore: MemoryStore): ResumeContext;
35
+ /** Format resume context for AI consumption */
36
+ export declare function formatResumeContext(ctx: ResumeContext): string;
37
+ //# sourceMappingURL=resume-work.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume-work.d.ts","sourceRoot":"","sources":["../../src/memory/resume-work.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,YAAY,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrD,iBAAiB,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1D,eAAe,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAoE1E;AAED,+CAA+C;AAC/C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAwC9D"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildResumeContext = buildResumeContext;
4
+ exports.formatResumeContext = formatResumeContext;
5
+ const session_tracker_1 = require("./session-tracker");
6
+ /**
7
+ * Build context for resuming work after a conversation break.
8
+ */
9
+ function buildResumeContext(memoryStore) {
10
+ const result = {
11
+ lastSession: null,
12
+ recentMemories: [],
13
+ currentTasks: [],
14
+ recentCorrections: [],
15
+ recentDecisions: [],
16
+ };
17
+ // 1. Get last session summary
18
+ try {
19
+ const sessions = (0, session_tracker_1.getRecentSessions)(memoryStore, 3);
20
+ if (sessions && sessions.length > 0) {
21
+ const last = sessions[0];
22
+ result.lastSession = typeof last === 'string' ? last :
23
+ typeof last === 'object' ? (last.summary || last.topic ||
24
+ JSON.stringify(last).slice(0, 200)) : String(last);
25
+ }
26
+ }
27
+ catch { /* session tracking might not have data */ }
28
+ // 2. Recent memories (last 24 hours)
29
+ const dayAgo = Date.now() - 24 * 60 * 60 * 1000;
30
+ try {
31
+ const all = memoryStore.getActive(50);
32
+ const recent = all.filter(m => m.timestamp >= dayAgo);
33
+ result.recentMemories = recent.slice(0, 20).map(m => ({
34
+ type: m.type,
35
+ intent: m.intent,
36
+ age: formatAge(m.timestamp),
37
+ }));
38
+ }
39
+ catch { /* */ }
40
+ // 3. Current tasks (CURRENT_TASK type memories)
41
+ try {
42
+ const tasks = memoryStore.getByType('CURRENT_TASK', 10);
43
+ result.currentTasks = tasks
44
+ .filter(t => Date.now() - t.timestamp < 7 * 24 * 60 * 60 * 1000) // Last 7 days
45
+ .map(t => ({
46
+ intent: t.intent,
47
+ age: formatAge(t.timestamp),
48
+ }));
49
+ }
50
+ catch { /* type might not exist yet */ }
51
+ // 4. Recent corrections (most valuable for not repeating mistakes)
52
+ try {
53
+ const corrections = memoryStore.getByType('CORRECTION', 10);
54
+ result.recentCorrections = corrections
55
+ .filter(c => Date.now() - c.timestamp < 3 * 24 * 60 * 60 * 1000) // Last 3 days
56
+ .map(c => ({
57
+ intent: c.intent,
58
+ age: formatAge(c.timestamp),
59
+ }));
60
+ }
61
+ catch { /* */ }
62
+ // 5. Recent decisions
63
+ try {
64
+ const decisions = memoryStore.getByType('DECISION', 10);
65
+ result.recentDecisions = decisions
66
+ .filter(d => Date.now() - d.timestamp < 7 * 24 * 60 * 60 * 1000) // Last 7 days
67
+ .map(d => ({
68
+ intent: d.intent,
69
+ age: formatAge(d.timestamp),
70
+ }));
71
+ }
72
+ catch { /* */ }
73
+ return result;
74
+ }
75
+ /** Format resume context for AI consumption */
76
+ function formatResumeContext(ctx) {
77
+ const lines = ['# 🔄 Resume Work — Where We Left Off\n'];
78
+ if (ctx.lastSession) {
79
+ lines.push(`## Last Session\n${ctx.lastSession}\n`);
80
+ }
81
+ if (ctx.currentTasks.length > 0) {
82
+ lines.push('## 📋 Current Tasks');
83
+ ctx.currentTasks.forEach(t => lines.push(`- ${t.intent} _(${t.age})_`));
84
+ lines.push('');
85
+ }
86
+ if (ctx.recentCorrections.length > 0) {
87
+ lines.push('## 🔴 Recent Corrections (DON\'T repeat)');
88
+ ctx.recentCorrections.forEach(c => lines.push(`- ${c.intent} _(${c.age})_`));
89
+ lines.push('');
90
+ }
91
+ if (ctx.recentDecisions.length > 0) {
92
+ lines.push('## 📌 Recent Decisions');
93
+ ctx.recentDecisions.forEach(d => lines.push(`- ${d.intent} _(${d.age})_`));
94
+ lines.push('');
95
+ }
96
+ if (ctx.recentMemories.length > 0) {
97
+ lines.push(`## 🧠 Recent Activity (${ctx.recentMemories.length} memories in last 24h)`);
98
+ const byType = {};
99
+ ctx.recentMemories.forEach(m => { byType[m.type] = (byType[m.type] || 0) + 1; });
100
+ Object.entries(byType).forEach(([type, count]) => {
101
+ lines.push(`- ${type}: ${count}`);
102
+ });
103
+ lines.push('');
104
+ }
105
+ if (lines.length <= 1) {
106
+ lines.push('No recent activity found. This may be a fresh session.');
107
+ }
108
+ return lines.join('\n');
109
+ }
110
+ // ─── Helper ──────────────────────────────────────────────────────────────────
111
+ function formatAge(timestamp) {
112
+ const diff = Date.now() - timestamp;
113
+ const mins = Math.floor(diff / 60000);
114
+ if (mins < 60)
115
+ return `${mins}m ago`;
116
+ const hours = Math.floor(mins / 60);
117
+ if (hours < 24)
118
+ return `${hours}h ago`;
119
+ const days = Math.floor(hours / 24);
120
+ return `${days}d ago`;
121
+ }
122
+ //# sourceMappingURL=resume-work.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resume-work.js","sourceRoot":"","sources":["../../src/memory/resume-work.ts"],"names":[],"mappings":";;AAuBA,gDAoEC;AAGD,kDAwCC;AA5HD,uDAAsD;AAUtD;;GAEG;AACH,SAAgB,kBAAkB,CAAC,WAAwB;IACvD,MAAM,MAAM,GAAkB;QAC1B,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,EAAE;QAClB,YAAY,EAAE,EAAE;QAChB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;KACtB,CAAC;IAEF,8BAA8B;IAC9B,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,IAAA,mCAAiB,EAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACnD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GA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,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;IACpC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;IACtC,IAAI,IAAI,GAAG,EAAE;QAAE,OAAO,GAAG,IAAI,OAAO,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IACpC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,GAAG,KAAK,OAAO,CAAC;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,IAAI,OAAO,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Success Tracker — Reinforces approaches that work.
3
+ *
4
+ * When the user says "that worked", "perfect", "great job", "exactly what I wanted",
5
+ * this module captures what approach was used and stores it as a proven pattern.
6
+ *
7
+ * The AI currently only learns from MISTAKES (corrections, bug fixes).
8
+ * But learning from SUCCESS is equally important — repeat what works.
9
+ *
10
+ * Detects:
11
+ * - Explicit praise: "perfect", "that's exactly right", "great"
12
+ * - Implicit success: "it works now", "the tests pass", "build succeeded"
13
+ * - Task completion: "done", "all good", "ship it"
14
+ */
15
+ export interface SuccessSignal {
16
+ type: 'explicit_praise' | 'implicit_success' | 'task_completion';
17
+ trigger: string;
18
+ confidence: number;
19
+ }
20
+ /**
21
+ * Detect success signals from user text.
22
+ */
23
+ export declare function detectSuccess(text: string): SuccessSignal[];
24
+ /**
25
+ * Build a success memory from the signal and the AI's recent response context.
26
+ * The context should describe what approach was used.
27
+ */
28
+ export declare function buildSuccessMemory(signal: SuccessSignal, aiContext: string): {
29
+ intent: string;
30
+ reason: string;
31
+ tags: string[];
32
+ };
33
+ //# sourceMappingURL=success-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"success-tracker.d.ts","sourceRoot":"","sources":["../../src/memory/success-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,iBAAiB,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACtB;AAyBD;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAiB3D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG;IAC1E,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAClB,CAcA"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Success Tracker — Reinforces approaches that work.
4
+ *
5
+ * When the user says "that worked", "perfect", "great job", "exactly what I wanted",
6
+ * this module captures what approach was used and stores it as a proven pattern.
7
+ *
8
+ * The AI currently only learns from MISTAKES (corrections, bug fixes).
9
+ * But learning from SUCCESS is equally important — repeat what works.
10
+ *
11
+ * Detects:
12
+ * - Explicit praise: "perfect", "that's exactly right", "great"
13
+ * - Implicit success: "it works now", "the tests pass", "build succeeded"
14
+ * - Task completion: "done", "all good", "ship it"
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.detectSuccess = detectSuccess;
18
+ exports.buildSuccessMemory = buildSuccessMemory;
19
+ // ─── Detection Patterns ──────────────────────────────────────────────────────
20
+ const PRAISE_PATTERNS = [
21
+ // Explicit praise (highest confidence)
22
+ { regex: /\b(?:perfect|exactly\s+(?:right|what\s+i\s+(?:wanted|needed)))\b/i, type: 'explicit_praise', confidence: 0.95 },
23
+ { regex: /\b(?:great\s+(?:job|work)|well\s+done|nice\s+work|awesome|excellent)\b/i, type: 'explicit_praise', confidence: 0.90 },
24
+ { regex: /\bthat'?s?\s+(?:exactly|precisely|perfectly)\s+(?:right|correct|it)\b/i, type: 'explicit_praise', confidence: 0.90 },
25
+ { regex: /\bthank(?:s| you)\s+(?:that|this|it)\s+(?:works?|helped|fixed)\b/i, type: 'explicit_praise', confidence: 0.85 },
26
+ { regex: /\byou\s+(?:nailed|got)\s+it\b/i, type: 'explicit_praise', confidence: 0.90 },
27
+ // Implicit success (medium confidence)
28
+ { regex: /\b(?:it|that)\s+works?\s+(?:now|perfectly|great|fine)\b/i, type: 'implicit_success', confidence: 0.85 },
29
+ { regex: /\btests?\s+(?:pass|passed|passing|all\s+pass)\b/i, type: 'implicit_success', confidence: 0.90 },
30
+ { regex: /\bbuild\s+(?:succeeded|passed|success|works)\b/i, type: 'implicit_success', confidence: 0.90 },
31
+ { regex: /\b(?:no\s+(?:more\s+)?errors?|error\s+(?:is\s+)?(?:gone|fixed|resolved))\b/i, type: 'implicit_success', confidence: 0.85 },
32
+ { regex: /\b(?:the\s+)?(?:bug|issue|problem)\s+(?:is\s+)?(?:fixed|resolved|gone)\b/i, type: 'implicit_success', confidence: 0.85 },
33
+ // Task completion (lower confidence — context-dependent)
34
+ { regex: /\b(?:all\s+(?:good|done|set)|we'?re?\s+(?:good|done|set))\b/i, type: 'task_completion', confidence: 0.75 },
35
+ { regex: /\b(?:ship\s+it|let'?s?\s+(?:merge|deploy|push))\b/i, type: 'task_completion', confidence: 0.80 },
36
+ { regex: /\b(?:looks?\s+(?:good|great|perfect)|lgtm)\b/i, type: 'task_completion', confidence: 0.80 },
37
+ ];
38
+ /**
39
+ * Detect success signals from user text.
40
+ */
41
+ function detectSuccess(text) {
42
+ const signals = [];
43
+ const seen = new Set();
44
+ for (const pattern of PRAISE_PATTERNS) {
45
+ const match = text.match(pattern.regex);
46
+ if (match && !seen.has(pattern.type)) {
47
+ signals.push({
48
+ type: pattern.type,
49
+ trigger: match[0],
50
+ confidence: pattern.confidence,
51
+ });
52
+ seen.add(`${pattern.type}:${match[0].toLowerCase()}`);
53
+ }
54
+ }
55
+ return signals;
56
+ }
57
+ /**
58
+ * Build a success memory from the signal and the AI's recent response context.
59
+ * The context should describe what approach was used.
60
+ */
61
+ function buildSuccessMemory(signal, aiContext) {
62
+ // Extract the approach from AI context (first meaningful sentence)
63
+ const approach = aiContext
64
+ .split(/[.\n]/)
65
+ .map(s => s.trim())
66
+ .filter(s => s.length > 20 && s.length < 200)
67
+ .slice(0, 2)
68
+ .join('. ') || aiContext.slice(0, 200);
69
+ return {
70
+ intent: `[PROVEN] ${approach}`,
71
+ reason: `User confirmed success: "${signal.trigger}" (${signal.type}, confidence: ${signal.confidence})`,
72
+ tags: ['success', 'proven-pattern', signal.type],
73
+ };
74
+ }
75
+ //# sourceMappingURL=success-tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"success-tracker.js","sourceRoot":"","sources":["../../src/memory/success-tracker.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAkCH,sCAiBC;AAMD,gDAkBC;AAnED,gFAAgF;AAEhF,MAAM,eAAe,GAA8E;IAC/F,uCAAuC;IACvC,EAAE,KAAK,EAAE,mEAAmE,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE;IACzH,EAAE,KAAK,EAAE,yEAAyE,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE;IAC/H,EAAE,KAAK,EAAE,wEAAwE,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9H,EAAE,KAAK,EAAE,mEAAmE,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE;IACzH,EAAE,KAAK,EAAE,gCAAgC,EAAE,IAAI,EAAE,iBAAiB,EAAE,UAAU,EAAE,IAAI,EAAE;IAEtF,uCAAuC;IACvC,EAAE,KAAK,EAAE,0DAA0D,EAAE,IAAI,EAAE,kBAAkB,EAAE,UAAU,EAAE,IAAI,EAAE;IACjH,EAAE,K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CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC1D,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,MAAqB,EAAE,SAAiB;IAKvE,mEAAmE;IACnE,MAAM,QAAQ,GAAG,SAAS;SACrB,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC;SAC5C,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;SACX,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE3C,OAAO;QACH,MAAM,EAAE,YAAY,QAAQ,EAAE;QAC9B,MAAM,EAAE,4BAA4B,MAAM,CAAC,OAAO,MAAM,MAAM,CAAC,IAAI,iBAAiB,MAAM,CAAC,UAAU,GAAG;QACxG,IAAI,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC;KACnD,CAAC;AACN,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Tool Recommender — Suggests which Cortex tools to use based on context.
3
+ *
4
+ * THE GAP THIS FILLS:
5
+ * The AI has 20 tools but often doesn't know WHEN to use which.
6
+ * This module analyzes the current situation and recommends the right tools.
7
+ *
8
+ * Like a flight checklist: "Before takeoff: check instruments, fuel, clearance."
9
+ * Here: "Before editing auth.ts: run pre_check, check_impact, verify_code."
10
+ */
11
+ export interface ToolRecommendation {
12
+ tool: string;
13
+ reason: string;
14
+ priority: 'must' | 'should' | 'could';
15
+ }
16
+ /**
17
+ * Recommend tools based on what the user is doing.
18
+ */
19
+ export declare function recommendTools(context: {
20
+ topic?: string;
21
+ currentFile?: string;
22
+ isNewConversation?: boolean;
23
+ recentAction?: string;
24
+ }): ToolRecommendation[];
25
+ /**
26
+ * Format tool recommendations for injection.
27
+ */
28
+ export declare function formatRecommendations(recs: ToolRecommendation[]): string;
29
+ //# sourceMappingURL=tool-recommender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-recommender.d.ts","sourceRoot":"","sources":["../../src/memory/tool-recommender.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CACzC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,kBAAkB,EAAE,CAgGvB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,MAAM,CASxE"}