cortex-mcp 1.2.3 → 1.4.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.
- package/README.md +9 -2
- package/dist/db/memory-store.d.ts +2 -2
- package/dist/db/memory-store.d.ts.map +1 -1
- package/dist/db/memory-store.js +26 -4
- package/dist/db/memory-store.js.map +1 -1
- package/dist/memory/auto-learner.d.ts.map +1 -1
- package/dist/memory/auto-learner.js +16 -0
- package/dist/memory/auto-learner.js.map +1 -1
- package/dist/memory/convention-detector.d.ts +11 -0
- package/dist/memory/convention-detector.d.ts.map +1 -0
- package/dist/memory/convention-detector.js +294 -0
- package/dist/memory/convention-detector.js.map +1 -0
- package/dist/memory/correction-detector.d.ts +33 -0
- package/dist/memory/correction-detector.d.ts.map +1 -0
- package/dist/memory/correction-detector.js +129 -0
- package/dist/memory/correction-detector.js.map +1 -0
- package/dist/memory/error-learner.d.ts +26 -0
- package/dist/memory/error-learner.d.ts.map +1 -0
- package/dist/memory/error-learner.js +145 -0
- package/dist/memory/error-learner.js.map +1 -0
- package/dist/memory/file-relationships.d.ts +47 -0
- package/dist/memory/file-relationships.d.ts.map +1 -0
- package/dist/memory/file-relationships.js +130 -0
- package/dist/memory/file-relationships.js.map +1 -0
- package/dist/memory/impact-analyzer.d.ts +16 -0
- package/dist/memory/impact-analyzer.d.ts.map +1 -0
- package/dist/memory/impact-analyzer.js +189 -0
- package/dist/memory/impact-analyzer.js.map +1 -0
- package/dist/memory/instructions-generator.d.ts +30 -0
- package/dist/memory/instructions-generator.d.ts.map +1 -0
- package/dist/memory/instructions-generator.js +117 -0
- package/dist/memory/instructions-generator.js.map +1 -0
- package/dist/memory/pre-flight.d.ts +24 -0
- package/dist/memory/pre-flight.d.ts.map +1 -0
- package/dist/memory/pre-flight.js +121 -0
- package/dist/memory/pre-flight.js.map +1 -0
- package/dist/memory/preference-learner.d.ts +28 -0
- package/dist/memory/preference-learner.d.ts.map +1 -0
- package/dist/memory/preference-learner.js +144 -0
- package/dist/memory/preference-learner.js.map +1 -0
- package/dist/memory/regression-guard.d.ts +35 -0
- package/dist/memory/regression-guard.d.ts.map +1 -0
- package/dist/memory/regression-guard.js +90 -0
- package/dist/memory/regression-guard.js.map +1 -0
- package/dist/memory/resume-work.d.ts +37 -0
- package/dist/memory/resume-work.d.ts.map +1 -0
- package/dist/memory/resume-work.js +122 -0
- package/dist/memory/resume-work.js.map +1 -0
- package/dist/memory/success-tracker.d.ts +33 -0
- package/dist/memory/success-tracker.d.ts.map +1 -0
- package/dist/memory/success-tracker.js +75 -0
- package/dist/memory/success-tracker.js.map +1 -0
- package/dist/memory/tool-recommender.d.ts +29 -0
- package/dist/memory/tool-recommender.d.ts.map +1 -0
- package/dist/memory/tool-recommender.js +117 -0
- package/dist/memory/tool-recommender.js.map +1 -0
- package/dist/memory/usage-stats.d.ts +59 -0
- package/dist/memory/usage-stats.d.ts.map +1 -0
- package/dist/memory/usage-stats.js +122 -0
- package/dist/memory/usage-stats.js.map +1 -0
- package/dist/server/mcp-handler.d.ts.map +1 -1
- package/dist/server/mcp-handler.js +634 -14
- package/dist/server/mcp-handler.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Recommender — Suggests which Cortex tools to use based on context.
|
|
4
|
+
*
|
|
5
|
+
* THE GAP THIS FILLS:
|
|
6
|
+
* The AI has 20 tools but often doesn't know WHEN to use which.
|
|
7
|
+
* This module analyzes the current situation and recommends the right tools.
|
|
8
|
+
*
|
|
9
|
+
* Like a flight checklist: "Before takeoff: check instruments, fuel, clearance."
|
|
10
|
+
* Here: "Before editing auth.ts: run pre_check, check_impact, verify_code."
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.recommendTools = recommendTools;
|
|
14
|
+
exports.formatRecommendations = formatRecommendations;
|
|
15
|
+
/**
|
|
16
|
+
* Recommend tools based on what the user is doing.
|
|
17
|
+
*/
|
|
18
|
+
function recommendTools(context) {
|
|
19
|
+
const recommendations = [];
|
|
20
|
+
// ─── New conversation? Always force_recall first ────────────────
|
|
21
|
+
if (context.isNewConversation) {
|
|
22
|
+
recommendations.push({
|
|
23
|
+
tool: 'force_recall',
|
|
24
|
+
reason: 'Start of conversation — load all context (corrections, decisions, conventions)',
|
|
25
|
+
priority: 'must',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// ─── About to edit a file? Pre-check it ────────────────────────
|
|
29
|
+
if (context.currentFile) {
|
|
30
|
+
recommendations.push({
|
|
31
|
+
tool: 'pre_check',
|
|
32
|
+
reason: `Check conventions, gotchas, and past bugs for ${context.currentFile}`,
|
|
33
|
+
priority: 'should',
|
|
34
|
+
});
|
|
35
|
+
recommendations.push({
|
|
36
|
+
tool: 'check_impact',
|
|
37
|
+
reason: `See what depends on ${context.currentFile} before changing it`,
|
|
38
|
+
priority: 'should',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
// ─── Topic suggests specific tools ─────────────────────────────
|
|
42
|
+
if (context.topic) {
|
|
43
|
+
const lower = context.topic.toLowerCase();
|
|
44
|
+
if (lower.includes('debug') || lower.includes('error') || lower.includes('bug') || lower.includes('fix')) {
|
|
45
|
+
recommendations.push({
|
|
46
|
+
tool: 'recall_memory',
|
|
47
|
+
reason: 'Search for similar past bugs and failed attempts',
|
|
48
|
+
priority: 'must',
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (lower.includes('review') || lower.includes('check')) {
|
|
52
|
+
recommendations.push({
|
|
53
|
+
tool: 'review_code',
|
|
54
|
+
reason: 'Review against stored conventions and past bug patterns',
|
|
55
|
+
priority: 'should',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (lower.includes('new') || lower.includes('create') || lower.includes('build') || lower.includes('add')) {
|
|
59
|
+
recommendations.push({
|
|
60
|
+
tool: 'scan_project',
|
|
61
|
+
reason: 'Ensure project context is loaded before building new features',
|
|
62
|
+
priority: 'could',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (lower.includes('import') || lower.includes('package') || lower.includes('dependency')) {
|
|
66
|
+
recommendations.push({
|
|
67
|
+
tool: 'verify_code',
|
|
68
|
+
reason: 'Check if imports are valid and packages exist',
|
|
69
|
+
priority: 'must',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (lower.includes('where') || lower.includes('left off') || lower.includes('continue') || lower.includes('resume')) {
|
|
73
|
+
recommendations.push({
|
|
74
|
+
tool: 'resume_work',
|
|
75
|
+
reason: 'Recover context from previous session',
|
|
76
|
+
priority: 'must',
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ─── After making changes ──────────────────────────────────────
|
|
81
|
+
if (context.recentAction === 'code_written') {
|
|
82
|
+
recommendations.push({
|
|
83
|
+
tool: 'auto_learn',
|
|
84
|
+
reason: 'Store decisions and patterns from this response',
|
|
85
|
+
priority: 'must',
|
|
86
|
+
});
|
|
87
|
+
recommendations.push({
|
|
88
|
+
tool: 'verify_code',
|
|
89
|
+
reason: 'Verify imports and exports in the code you just wrote',
|
|
90
|
+
priority: 'should',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// Deduplicate by tool name, keeping highest priority
|
|
94
|
+
const seen = new Map();
|
|
95
|
+
const priorityOrder = { must: 0, should: 1, could: 2 };
|
|
96
|
+
for (const rec of recommendations) {
|
|
97
|
+
const existing = seen.get(rec.tool);
|
|
98
|
+
if (!existing || priorityOrder[rec.priority] < priorityOrder[existing.priority]) {
|
|
99
|
+
seen.set(rec.tool, rec);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return [...seen.values()].sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Format tool recommendations for injection.
|
|
106
|
+
*/
|
|
107
|
+
function formatRecommendations(recs) {
|
|
108
|
+
if (recs.length === 0)
|
|
109
|
+
return '';
|
|
110
|
+
const lines = ['## 🛠️ Recommended Tools'];
|
|
111
|
+
for (const rec of recs) {
|
|
112
|
+
const badge = rec.priority === 'must' ? '🔴' : rec.priority === 'should' ? '🟡' : '🟢';
|
|
113
|
+
lines.push(`- ${badge} **${rec.tool}** — ${rec.reason}`);
|
|
114
|
+
}
|
|
115
|
+
return lines.join('\n');
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=tool-recommender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-recommender.js","sourceRoot":"","sources":["../../src/memory/tool-recommender.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAWH,wCAqGC;AAKD,sDASC;AAtHD;;GAEG;AACH,SAAgB,cAAc,CAAC,OAK9B;IACG,MAAM,eAAe,GAAyB,EAAE,CAAC;IAEjD,mEAAmE;IACnE,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;QAC5B,eAAe,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,gFAAgF;YACxF,QAAQ,EAAE,MAAM;SACnB,CAAC,CAAC;IACP,CAAC;IAED,kEAAkE;IAClE,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACtB,eAAe,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,iDAAiD,OAAO,CAAC,WAAW,EAAE;YAC9E,QAAQ,EAAE,QAAQ;SACrB,CAAC,CAAC;QACH,eAAe,CAAC,IAAI,CAAC;YACjB,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,uBAAuB,OAAO,CAAC,WAAW,qBAAqB;YACvE,QAAQ,EAAE,QAAQ;SACrB,CAAC,CAAC;IACP,CAAC;IAED,kEAAkE;IAClE,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,C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,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;AACpG,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,IAA0B;IAC5D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjC,MAAM,KAAK,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC3C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QACvF,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,GAAG,CAAC,IAAI,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage Stats — Tracks Cortex usage metrics for impact visibility.
|
|
3
|
+
*
|
|
4
|
+
* Solves the #1 retention problem: users don't SEE the value Cortex provides.
|
|
5
|
+
* Tracks recalls, stores, catches, and estimates time saved.
|
|
6
|
+
*/
|
|
7
|
+
declare const lifetimeStats: {
|
|
8
|
+
totalRecalls: number;
|
|
9
|
+
totalMemoriesServed: number;
|
|
10
|
+
totalHallucationsCaught: number;
|
|
11
|
+
totalMemoriesStored: number;
|
|
12
|
+
totalSessions: number;
|
|
13
|
+
};
|
|
14
|
+
/** Record a recall event */
|
|
15
|
+
export declare function trackRecall(memoriesReturned: number): void;
|
|
16
|
+
/** Record a memory store event */
|
|
17
|
+
export declare function trackStore(): void;
|
|
18
|
+
/** Record a hallucination catch */
|
|
19
|
+
export declare function trackCatch(): void;
|
|
20
|
+
/** Record a scan */
|
|
21
|
+
export declare function trackScan(): void;
|
|
22
|
+
/** Record a code review */
|
|
23
|
+
export declare function trackReview(): void;
|
|
24
|
+
/** Estimate time saved (each recalled memory ≈ 15s of re-explanation) */
|
|
25
|
+
export declare function estimateTimeSaved(): {
|
|
26
|
+
seconds: number;
|
|
27
|
+
formatted: string;
|
|
28
|
+
};
|
|
29
|
+
/** Format stats footer for injection into force_recall response */
|
|
30
|
+
export declare function formatStatsFooter(): string;
|
|
31
|
+
/** Get full stats object */
|
|
32
|
+
export declare function getUsageStats(): {
|
|
33
|
+
session: {
|
|
34
|
+
recallCount: number;
|
|
35
|
+
memoriesServed: number;
|
|
36
|
+
hallucationsCaught: number;
|
|
37
|
+
memoriesStored: number;
|
|
38
|
+
projectsScanned: number;
|
|
39
|
+
codeReviews: number;
|
|
40
|
+
sessionStart: number;
|
|
41
|
+
};
|
|
42
|
+
lifetime: {
|
|
43
|
+
totalRecalls: number;
|
|
44
|
+
totalMemoriesServed: number;
|
|
45
|
+
totalHallucationsCaught: number;
|
|
46
|
+
totalMemoriesStored: number;
|
|
47
|
+
totalSessions: number;
|
|
48
|
+
};
|
|
49
|
+
timeSaved: {
|
|
50
|
+
seconds: number;
|
|
51
|
+
formatted: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** Reset session stats (called on new session) */
|
|
55
|
+
export declare function resetSessionStats(): void;
|
|
56
|
+
/** Initialize lifetime stats from stored data */
|
|
57
|
+
export declare function initLifetimeStats(stored: Partial<typeof lifetimeStats>): void;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=usage-stats.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-stats.d.ts","sourceRoot":"","sources":["../../src/memory/usage-stats.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,QAAA,MAAM,aAAa;;;;;;CAMlB,CAAC;AAEF,4BAA4B;AAC5B,wBAAgB,WAAW,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAK1D;AAED,kCAAkC;AAClC,wBAAgB,UAAU,IAAI,IAAI,CAGjC;AAED,mCAAmC;AACnC,wBAAgB,UAAU,IAAI,IAAI,CAGjC;AAED,oBAAoB;AACpB,wBAAgB,SAAS,IAAI,IAAI,CAEhC;AAED,2BAA2B;AAC3B,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAK1E;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,IAAI,MAAM,CAgB1C;AAED,4BAA4B;AAC5B,wBAAgB,aAAa;;;;;;;;;;;;;;;;;;iBA3BmB,MAAM;mBAAa,MAAM;;EAiCxE;AAED,kDAAkD;AAClD,wBAAgB,iBAAiB,IAAI,IAAI,CAWxC;AAED,iDAAiD;AACjD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,aAAa,CAAC,GAAG,IAAI,CAM7E"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Usage Stats — Tracks Cortex usage metrics for impact visibility.
|
|
4
|
+
*
|
|
5
|
+
* Solves the #1 retention problem: users don't SEE the value Cortex provides.
|
|
6
|
+
* Tracks recalls, stores, catches, and estimates time saved.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.trackRecall = trackRecall;
|
|
10
|
+
exports.trackStore = trackStore;
|
|
11
|
+
exports.trackCatch = trackCatch;
|
|
12
|
+
exports.trackScan = trackScan;
|
|
13
|
+
exports.trackReview = trackReview;
|
|
14
|
+
exports.estimateTimeSaved = estimateTimeSaved;
|
|
15
|
+
exports.formatStatsFooter = formatStatsFooter;
|
|
16
|
+
exports.getUsageStats = getUsageStats;
|
|
17
|
+
exports.resetSessionStats = resetSessionStats;
|
|
18
|
+
exports.initLifetimeStats = initLifetimeStats;
|
|
19
|
+
// Session-scoped stats (lightweight, in-memory)
|
|
20
|
+
let sessionStats = {
|
|
21
|
+
recallCount: 0,
|
|
22
|
+
memoriesServed: 0,
|
|
23
|
+
hallucationsCaught: 0,
|
|
24
|
+
memoriesStored: 0,
|
|
25
|
+
projectsScanned: 0,
|
|
26
|
+
codeReviews: 0,
|
|
27
|
+
sessionStart: Date.now(),
|
|
28
|
+
};
|
|
29
|
+
// Lifetime stats (persisted via memory store events)
|
|
30
|
+
const lifetimeStats = {
|
|
31
|
+
totalRecalls: 0,
|
|
32
|
+
totalMemoriesServed: 0,
|
|
33
|
+
totalHallucationsCaught: 0,
|
|
34
|
+
totalMemoriesStored: 0,
|
|
35
|
+
totalSessions: 0,
|
|
36
|
+
};
|
|
37
|
+
/** Record a recall event */
|
|
38
|
+
function trackRecall(memoriesReturned) {
|
|
39
|
+
sessionStats.recallCount++;
|
|
40
|
+
sessionStats.memoriesServed += memoriesReturned;
|
|
41
|
+
lifetimeStats.totalRecalls++;
|
|
42
|
+
lifetimeStats.totalMemoriesServed += memoriesReturned;
|
|
43
|
+
}
|
|
44
|
+
/** Record a memory store event */
|
|
45
|
+
function trackStore() {
|
|
46
|
+
sessionStats.memoriesStored++;
|
|
47
|
+
lifetimeStats.totalMemoriesStored++;
|
|
48
|
+
}
|
|
49
|
+
/** Record a hallucination catch */
|
|
50
|
+
function trackCatch() {
|
|
51
|
+
sessionStats.hallucationsCaught++;
|
|
52
|
+
lifetimeStats.totalHallucationsCaught++;
|
|
53
|
+
}
|
|
54
|
+
/** Record a scan */
|
|
55
|
+
function trackScan() {
|
|
56
|
+
sessionStats.projectsScanned++;
|
|
57
|
+
}
|
|
58
|
+
/** Record a code review */
|
|
59
|
+
function trackReview() {
|
|
60
|
+
sessionStats.codeReviews++;
|
|
61
|
+
}
|
|
62
|
+
/** Estimate time saved (each recalled memory ≈ 15s of re-explanation) */
|
|
63
|
+
function estimateTimeSaved() {
|
|
64
|
+
const seconds = lifetimeStats.totalMemoriesServed * 15;
|
|
65
|
+
if (seconds < 60)
|
|
66
|
+
return { seconds, formatted: `${seconds}s` };
|
|
67
|
+
if (seconds < 3600)
|
|
68
|
+
return { seconds, formatted: `${Math.round(seconds / 60)} min` };
|
|
69
|
+
return { seconds, formatted: `${(seconds / 3600).toFixed(1)} hours` };
|
|
70
|
+
}
|
|
71
|
+
/** Format stats footer for injection into force_recall response */
|
|
72
|
+
function formatStatsFooter() {
|
|
73
|
+
const timeSaved = estimateTimeSaved();
|
|
74
|
+
const parts = [];
|
|
75
|
+
if (lifetimeStats.totalRecalls > 0) {
|
|
76
|
+
parts.push(`${lifetimeStats.totalMemoriesServed} memories recalled`);
|
|
77
|
+
}
|
|
78
|
+
if (timeSaved.seconds > 0) {
|
|
79
|
+
parts.push(`saved you ~${timeSaved.formatted} of re-explanation`);
|
|
80
|
+
}
|
|
81
|
+
if (lifetimeStats.totalHallucationsCaught > 0) {
|
|
82
|
+
parts.push(`${lifetimeStats.totalHallucationsCaught} hallucination${lifetimeStats.totalHallucationsCaught > 1 ? 's' : ''} caught`);
|
|
83
|
+
}
|
|
84
|
+
if (parts.length === 0)
|
|
85
|
+
return '';
|
|
86
|
+
return `\n> 🧠 Cortex: ${parts.join(' | ')}`;
|
|
87
|
+
}
|
|
88
|
+
/** Get full stats object */
|
|
89
|
+
function getUsageStats() {
|
|
90
|
+
return {
|
|
91
|
+
session: { ...sessionStats },
|
|
92
|
+
lifetime: { ...lifetimeStats },
|
|
93
|
+
timeSaved: estimateTimeSaved(),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** Reset session stats (called on new session) */
|
|
97
|
+
function resetSessionStats() {
|
|
98
|
+
lifetimeStats.totalSessions++;
|
|
99
|
+
sessionStats = {
|
|
100
|
+
recallCount: 0,
|
|
101
|
+
memoriesServed: 0,
|
|
102
|
+
hallucationsCaught: 0,
|
|
103
|
+
memoriesStored: 0,
|
|
104
|
+
projectsScanned: 0,
|
|
105
|
+
codeReviews: 0,
|
|
106
|
+
sessionStart: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** Initialize lifetime stats from stored data */
|
|
110
|
+
function initLifetimeStats(stored) {
|
|
111
|
+
if (stored.totalRecalls)
|
|
112
|
+
lifetimeStats.totalRecalls = stored.totalRecalls;
|
|
113
|
+
if (stored.totalMemoriesServed)
|
|
114
|
+
lifetimeStats.totalMemoriesServed = stored.totalMemoriesServed;
|
|
115
|
+
if (stored.totalHallucationsCaught)
|
|
116
|
+
lifetimeStats.totalHallucationsCaught = stored.totalHallucationsCaught;
|
|
117
|
+
if (stored.totalMemoriesStored)
|
|
118
|
+
lifetimeStats.totalMemoriesStored = stored.totalMemoriesStored;
|
|
119
|
+
if (stored.totalSessions)
|
|
120
|
+
lifetimeStats.totalSessions = stored.totalSessions;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=usage-stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage-stats.js","sourceRoot":"","sources":["../../src/memory/usage-stats.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAuBH,kCAKC;AAGD,gCAGC;AAGD,gCAGC;AAGD,8BAEC;AAGD,kCAEC;AAGD,8CAKC;AAGD,8CAgBC;AAGD,sCAMC;AAGD,8CAWC;AAGD,8CAMC;AA3GD,gDAAgD;AAChD,IAAI,YAAY,GAAG;IACf,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,CAAC;IACjB,kBAAkB,EAAE,CAAC;IACrB,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,CAAC;IAClB,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;CAC3B,CAAC;AAEF,qDAAqD;AACrD,MAAM,aAAa,GAAG;IAClB,YAAY,EAAE,CAAC;IACf,mBAAmB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AAE;KAC3B,CAAC;AACN,CAAC;AAED,iDAAiD;AACjD,SAAgB,iBAAiB,CAAC,MAAqC;IACnE,IAAI,MAAM,CAAC,YAAY;QAAE,aAAa,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;IAC1E,IAAI,MAAM,CAAC,mBAAmB;QAAE,aAAa,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAC/F,IAAI,MAAM,CAAC,uBAAuB;QAAE,aAAa,CAAC,uBAAuB,GAAG,MAAM,CAAC,uBAAuB,CAAC;IAC3G,IAAI,MAAM,CAAC,mBAAmB;QAAE,aAAa,CAAC,mBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAC/F,IAAI,MAAM,CAAC,aAAa;QAAE,aAAa,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;AACjF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/server/mcp-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-handler.d.ts","sourceRoot":"","sources":["../../src/server/mcp-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAwT3C,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,MAAM;4BAC5D,GAAG,KAAG,OAAO,CAAC,GAAG,CAAC;EAouD1D"}
|