@jungjaehoon/mama-core 1.1.2 → 1.1.3
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/dist/config-loader.d.ts +61 -0
- package/dist/config-loader.js +187 -0
- package/dist/db-adapter/base-adapter.d.ts +76 -0
- package/dist/db-adapter/base-adapter.js +11 -0
- package/dist/db-adapter/index.d.ts +24 -0
- package/dist/db-adapter/index.js +29 -0
- package/dist/db-adapter/sqlite-adapter.d.ts +73 -0
- package/dist/db-adapter/sqlite-adapter.js +330 -0
- package/dist/db-adapter/statement.d.ts +119 -0
- package/dist/db-adapter/statement.js +113 -0
- package/dist/db-manager.d.ts +252 -0
- package/dist/db-manager.js +622 -0
- package/dist/debug-logger.d.ts +32 -0
- package/dist/debug-logger.js +83 -0
- package/dist/decision-formatter.d.ts +172 -0
- package/dist/decision-formatter.js +894 -0
- package/dist/decision-tracker.d.ts +218 -0
- package/dist/decision-tracker.js +531 -0
- package/dist/embedding-cache.d.ts +83 -0
- package/dist/embedding-cache.js +182 -0
- package/dist/embedding-client.d.ts +43 -0
- package/dist/embedding-client.js +132 -0
- package/dist/embedding-server/index.d.ts +65 -0
- package/dist/embedding-server/index.js +397 -0
- package/dist/embedding-server/mobile/auth.d.ts +53 -0
- package/dist/embedding-server/mobile/auth.js +140 -0
- package/dist/embedding-server/mobile/daemon.d.ts +128 -0
- package/dist/embedding-server/mobile/daemon.js +303 -0
- package/dist/embedding-server/mobile/output-parser.d.ts +115 -0
- package/dist/embedding-server/mobile/output-parser.js +241 -0
- package/dist/embedding-server/mobile/session-api.d.ts +57 -0
- package/dist/embedding-server/mobile/session-api.js +261 -0
- package/dist/embedding-server/mobile/session-manager.d.ts +135 -0
- package/dist/embedding-server/mobile/session-manager.js +333 -0
- package/dist/embedding-server/mobile/websocket-handler.d.ts +127 -0
- package/dist/embedding-server/mobile/websocket-handler.js +435 -0
- package/dist/embeddings.d.ts +75 -0
- package/dist/embeddings.js +262 -0
- package/dist/errors.d.ts +131 -0
- package/dist/errors.js +225 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +193 -0
- package/dist/mama-api.d.ts +954 -0
- package/dist/mama-api.js +2210 -0
- package/dist/memory-inject.d.ts +24 -0
- package/dist/memory-inject.js +116 -0
- package/dist/memory-store.d.ts +103 -0
- package/dist/memory-store.js +129 -0
- package/dist/notification-manager.d.ts +7 -0
- package/dist/notification-manager.js +12 -0
- package/dist/ollama-client.d.ts +51 -0
- package/dist/ollama-client.js +308 -0
- package/dist/outcome-tracker.d.ts +165 -0
- package/dist/outcome-tracker.js +315 -0
- package/dist/progress-indicator.d.ts +48 -0
- package/dist/progress-indicator.js +82 -0
- package/dist/query-intent.d.ts +27 -0
- package/dist/query-intent.js +144 -0
- package/dist/relevance-scorer.d.ts +124 -0
- package/dist/relevance-scorer.js +243 -0
- package/dist/test-utils.d.ts +66 -0
- package/dist/test-utils.js +166 -0
- package/dist/tier-validator.d.ts +55 -0
- package/dist/tier-validator.js +216 -0
- package/dist/time-formatter.d.ts +25 -0
- package/dist/time-formatter.js +93 -0
- package/package.json +3 -2
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MAMA Tier Validator
|
|
4
|
+
*
|
|
5
|
+
* Centralized tier validation module for MAMA.
|
|
6
|
+
* Validates system requirements and determines tier status (1 or 2).
|
|
7
|
+
*
|
|
8
|
+
* Tier 1: Full features (Node.js 18+, SQLite, Embeddings, Database)
|
|
9
|
+
* Tier 2: Degraded mode (missing one or more requirements)
|
|
10
|
+
*
|
|
11
|
+
* @module tier-validator
|
|
12
|
+
*/
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.checkNodeVersion = checkNodeVersion;
|
|
18
|
+
exports.checkSQLite = checkSQLite;
|
|
19
|
+
exports.checkEmbeddings = checkEmbeddings;
|
|
20
|
+
exports.checkDatabase = checkDatabase;
|
|
21
|
+
exports.validateTier = validateTier;
|
|
22
|
+
exports.getTierDescription = getTierDescription;
|
|
23
|
+
exports.getTierBanner = getTierBanner;
|
|
24
|
+
const fs_1 = __importDefault(require("fs"));
|
|
25
|
+
const path_1 = __importDefault(require("path"));
|
|
26
|
+
const os_1 = __importDefault(require("os"));
|
|
27
|
+
/**
|
|
28
|
+
* Validates Node.js version requirement
|
|
29
|
+
*/
|
|
30
|
+
function checkNodeVersion() {
|
|
31
|
+
try {
|
|
32
|
+
const nodeVersion = process.versions.node;
|
|
33
|
+
const majorVersion = parseInt(nodeVersion.split('.')[0], 10);
|
|
34
|
+
if (majorVersion >= 18) {
|
|
35
|
+
return {
|
|
36
|
+
status: 'pass',
|
|
37
|
+
details: `v${nodeVersion}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
status: 'fail',
|
|
42
|
+
details: `v${nodeVersion} (requires 18+)`,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
47
|
+
return {
|
|
48
|
+
status: 'fail',
|
|
49
|
+
details: `Error checking version: ${message}`,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates SQLite (better-sqlite3) availability
|
|
55
|
+
*/
|
|
56
|
+
function checkSQLite() {
|
|
57
|
+
try {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
59
|
+
const Database = require('better-sqlite3');
|
|
60
|
+
// Test instantiation with in-memory database
|
|
61
|
+
const testDb = new Database(':memory:');
|
|
62
|
+
testDb.close();
|
|
63
|
+
return {
|
|
64
|
+
status: 'pass',
|
|
65
|
+
details: 'better-sqlite3 native module ready',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
+
return {
|
|
71
|
+
status: 'fail',
|
|
72
|
+
details: `better-sqlite3 not available: ${message}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validates embedding model availability
|
|
78
|
+
*/
|
|
79
|
+
function checkEmbeddings() {
|
|
80
|
+
try {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
82
|
+
const { getModelName } = require('./embeddings');
|
|
83
|
+
const modelName = getModelName();
|
|
84
|
+
// Check if model is cached
|
|
85
|
+
const cacheDir = process.env.HF_HOME ||
|
|
86
|
+
process.env.TRANSFORMERS_CACHE ||
|
|
87
|
+
path_1.default.join(os_1.default.homedir(), '.cache', 'huggingface', 'transformers');
|
|
88
|
+
// Model cache structure: cache_dir/models--org--model/snapshots/hash/
|
|
89
|
+
const modelPath = path_1.default.join(cacheDir, `models--${modelName.replace('/', '--')}`);
|
|
90
|
+
if (fs_1.default.existsSync(modelPath)) {
|
|
91
|
+
return {
|
|
92
|
+
status: 'pass',
|
|
93
|
+
details: `${modelName} (cached)`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
status: 'fail',
|
|
98
|
+
details: `${modelName} not cached (will download on first use)`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
103
|
+
return {
|
|
104
|
+
status: 'fail',
|
|
105
|
+
details: `Error checking embeddings: ${message}`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validates database file accessibility
|
|
111
|
+
*/
|
|
112
|
+
function checkDatabase() {
|
|
113
|
+
try {
|
|
114
|
+
const dbPath = process.env.MAMA_DB_PATH || path_1.default.join(os_1.default.homedir(), '.claude', 'mama-memory.db');
|
|
115
|
+
const dbDir = path_1.default.dirname(dbPath);
|
|
116
|
+
// Check if directory exists or can be created
|
|
117
|
+
if (!fs_1.default.existsSync(dbDir)) {
|
|
118
|
+
try {
|
|
119
|
+
fs_1.default.mkdirSync(dbDir, { recursive: true });
|
|
120
|
+
}
|
|
121
|
+
catch (mkdirErr) {
|
|
122
|
+
const message = mkdirErr instanceof Error ? mkdirErr.message : String(mkdirErr);
|
|
123
|
+
return {
|
|
124
|
+
status: 'fail',
|
|
125
|
+
details: `Cannot create database directory: ${message}`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Check write access
|
|
130
|
+
try {
|
|
131
|
+
fs_1.default.accessSync(dbDir, fs_1.default.constants.W_OK);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return {
|
|
135
|
+
status: 'fail',
|
|
136
|
+
details: `No write access to ${dbDir}`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
status: 'pass',
|
|
141
|
+
details: dbPath,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
146
|
+
return {
|
|
147
|
+
status: 'fail',
|
|
148
|
+
details: `Error checking database: ${message}`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Validates MAMA tier status
|
|
154
|
+
*
|
|
155
|
+
* Performs all system checks and determines tier:
|
|
156
|
+
* - Tier 1: All checks pass (full features)
|
|
157
|
+
* - Tier 2: One or more checks fail (degraded mode)
|
|
158
|
+
*/
|
|
159
|
+
async function validateTier() {
|
|
160
|
+
const checks = [
|
|
161
|
+
{
|
|
162
|
+
name: 'Node.js',
|
|
163
|
+
...checkNodeVersion(),
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'SQLite',
|
|
167
|
+
...checkSQLite(),
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'Embeddings',
|
|
171
|
+
...checkEmbeddings(),
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'Database',
|
|
175
|
+
...checkDatabase(),
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
// Determine tier: all pass = tier 1, any fail = tier 2
|
|
179
|
+
const tier = checks.every((c) => c.status === 'pass') ? 1 : 2;
|
|
180
|
+
return {
|
|
181
|
+
tier,
|
|
182
|
+
checks,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get user-friendly tier description
|
|
187
|
+
*/
|
|
188
|
+
function getTierDescription(tier) {
|
|
189
|
+
const descriptions = {
|
|
190
|
+
1: 'Full Features - All systems operational',
|
|
191
|
+
2: 'Degraded Mode - Some features unavailable',
|
|
192
|
+
};
|
|
193
|
+
return descriptions[tier] || 'Unknown Tier';
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Get tier status banner
|
|
197
|
+
*/
|
|
198
|
+
function getTierBanner(validation) {
|
|
199
|
+
const { tier, checks } = validation;
|
|
200
|
+
const failedChecks = checks.filter((c) => c.status === 'fail');
|
|
201
|
+
let banner = `\n┌─────────────────────────────────────────┐\n`;
|
|
202
|
+
banner += `│ MAMA Tier ${tier}: ${getTierDescription(tier).split(' - ')[0]}\n`;
|
|
203
|
+
if (failedChecks.length > 0) {
|
|
204
|
+
banner += `│\n`;
|
|
205
|
+
banner += `│ ⚠️ Issues detected:\n`;
|
|
206
|
+
failedChecks.forEach((check) => {
|
|
207
|
+
banner += `│ • ${check.name}: ${check.details}\n`;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
banner += `│ ✅ All systems operational\n`;
|
|
212
|
+
}
|
|
213
|
+
banner += `└─────────────────────────────────────────┘\n`;
|
|
214
|
+
return banner;
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=tier-validator.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time Formatter - Human-Readable Time Formatting
|
|
3
|
+
*
|
|
4
|
+
* Converts Unix timestamps to human-readable relative time format
|
|
5
|
+
* Examples: "2d ago", "3h ago", "just now"
|
|
6
|
+
*
|
|
7
|
+
* Used by list_decisions and recall_decision tools
|
|
8
|
+
*
|
|
9
|
+
* @module time-formatter
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Format Unix timestamp (milliseconds) to human-readable relative time
|
|
13
|
+
*
|
|
14
|
+
* AC #2: Format created_at as human-readable ("2d ago", "3h ago", etc.)
|
|
15
|
+
*
|
|
16
|
+
* @param timestamp - Unix timestamp in milliseconds OR ISO 8601 string
|
|
17
|
+
* @returns Human-readable time string
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* formatTimeAgo(Date.now() - 3600000) // "1h ago"
|
|
21
|
+
* formatTimeAgo(Date.now() - 172800000) // "2d ago"
|
|
22
|
+
* formatTimeAgo("2025-11-20T10:30:00Z") // "2d ago" (if today is 2025-11-22)
|
|
23
|
+
*/
|
|
24
|
+
export declare function formatTimeAgo(timestamp: number | string | null | undefined): string;
|
|
25
|
+
//# sourceMappingURL=time-formatter.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Time Formatter - Human-Readable Time Formatting
|
|
4
|
+
*
|
|
5
|
+
* Converts Unix timestamps to human-readable relative time format
|
|
6
|
+
* Examples: "2d ago", "3h ago", "just now"
|
|
7
|
+
*
|
|
8
|
+
* Used by list_decisions and recall_decision tools
|
|
9
|
+
*
|
|
10
|
+
* @module time-formatter
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.formatTimeAgo = formatTimeAgo;
|
|
14
|
+
const debug_logger_js_1 = require("./debug-logger.js");
|
|
15
|
+
/**
|
|
16
|
+
* Format Unix timestamp (milliseconds) to human-readable relative time
|
|
17
|
+
*
|
|
18
|
+
* AC #2: Format created_at as human-readable ("2d ago", "3h ago", etc.)
|
|
19
|
+
*
|
|
20
|
+
* @param timestamp - Unix timestamp in milliseconds OR ISO 8601 string
|
|
21
|
+
* @returns Human-readable time string
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* formatTimeAgo(Date.now() - 3600000) // "1h ago"
|
|
25
|
+
* formatTimeAgo(Date.now() - 172800000) // "2d ago"
|
|
26
|
+
* formatTimeAgo("2025-11-20T10:30:00Z") // "2d ago" (if today is 2025-11-22)
|
|
27
|
+
*/
|
|
28
|
+
function formatTimeAgo(timestamp) {
|
|
29
|
+
try {
|
|
30
|
+
// Handle null/undefined (but allow 0 as valid Unix epoch)
|
|
31
|
+
if (timestamp === null || timestamp === undefined) {
|
|
32
|
+
(0, debug_logger_js_1.warn)('[time-formatter] Timestamp is null or undefined, returning "unknown"');
|
|
33
|
+
return 'unknown';
|
|
34
|
+
}
|
|
35
|
+
// Parse ISO 8601 string to timestamp (if string provided)
|
|
36
|
+
let timestampMs;
|
|
37
|
+
if (typeof timestamp === 'string') {
|
|
38
|
+
timestampMs = new Date(timestamp).getTime();
|
|
39
|
+
if (isNaN(timestampMs)) {
|
|
40
|
+
(0, debug_logger_js_1.warn)(`[time-formatter] Invalid ISO 8601 string: ${timestamp}`);
|
|
41
|
+
return 'unknown';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
timestampMs = timestamp;
|
|
46
|
+
}
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
const diff = now - timestampMs;
|
|
49
|
+
// Handle future timestamps (shouldn't happen, but be defensive)
|
|
50
|
+
if (diff < 0) {
|
|
51
|
+
(0, debug_logger_js_1.warn)(`[time-formatter] Future timestamp detected: ${timestamp}`);
|
|
52
|
+
return 'just now';
|
|
53
|
+
}
|
|
54
|
+
// Calculate time units
|
|
55
|
+
const seconds = Math.floor(diff / 1000);
|
|
56
|
+
const minutes = Math.floor(seconds / 60);
|
|
57
|
+
const hours = Math.floor(minutes / 60);
|
|
58
|
+
const days = Math.floor(hours / 24);
|
|
59
|
+
const weeks = Math.floor(days / 7);
|
|
60
|
+
const months = Math.floor(days / 30);
|
|
61
|
+
const years = Math.floor(days / 365);
|
|
62
|
+
// Return human-readable format
|
|
63
|
+
if (seconds < 60) {
|
|
64
|
+
return 'just now';
|
|
65
|
+
}
|
|
66
|
+
if (minutes < 60) {
|
|
67
|
+
return `${minutes}m ago`;
|
|
68
|
+
}
|
|
69
|
+
if (hours < 24) {
|
|
70
|
+
return `${hours}h ago`;
|
|
71
|
+
}
|
|
72
|
+
if (days < 7) {
|
|
73
|
+
return `${days}d ago`;
|
|
74
|
+
}
|
|
75
|
+
if (weeks < 4) {
|
|
76
|
+
return `${weeks}w ago`;
|
|
77
|
+
}
|
|
78
|
+
// Guard against "0mo ago" when days are 28-29 (months = Math.floor(days/30) = 0)
|
|
79
|
+
if (months < 1) {
|
|
80
|
+
return `${weeks}w ago`;
|
|
81
|
+
}
|
|
82
|
+
if (months < 12) {
|
|
83
|
+
return `${months}mo ago`;
|
|
84
|
+
}
|
|
85
|
+
return `${years}y ago`;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
89
|
+
(0, debug_logger_js_1.warn)(`[time-formatter] Error formatting timestamp ${timestamp}: ${message}`);
|
|
90
|
+
return 'unknown';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=time-formatter.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungjaehoon/mama-core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "MAMA Core - Shared modules for Memory-Augmented MCP Assistant",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"./errors": "./dist/errors.js",
|
|
25
25
|
"./time-formatter": "./dist/time-formatter.js",
|
|
26
26
|
"./outcome-tracker": "./dist/outcome-tracker.js",
|
|
27
|
-
"./query-intent": "./dist/query-intent.js"
|
|
27
|
+
"./query-intent": "./dist/query-intent.js",
|
|
28
|
+
"./test-utils": "./dist/test-utils.js"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
30
31
|
"build": "tsc",
|