@slorenzot/memento-core 2.0.0 → 2.0.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.
- package/dist/ConfigManager.d.ts +44 -59
- package/dist/ConfigManager.d.ts.map +1 -1
- package/dist/ConfigManager.js +78 -279
- package/dist/ConfigManager.js.map +1 -1
- package/dist/MemoryEngine.d.ts +30 -0
- package/dist/MemoryEngine.d.ts.map +1 -1
- package/dist/MemoryEngine.js +136 -11
- package/dist/MemoryEngine.js.map +1 -1
- package/dist/auth/device-flow-client.d.ts +48 -0
- package/dist/auth/device-flow-client.d.ts.map +1 -0
- package/dist/auth/device-flow-client.js +143 -0
- package/dist/auth/device-flow-client.js.map +1 -0
- package/dist/auth/index.d.ts +4 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/token-store.d.ts +46 -0
- package/dist/auth/token-store.d.ts.map +1 -0
- package/dist/auth/token-store.js +117 -0
- package/dist/auth/token-store.js.map +1 -0
- package/dist/auth/types.d.ts +83 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +4 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/sync/conflict-resolution.d.ts +26 -0
- package/dist/sync/conflict-resolution.d.ts.map +1 -0
- package/dist/sync/conflict-resolution.js +64 -0
- package/dist/sync/conflict-resolution.js.map +1 -0
- package/dist/sync/index.d.ts +5 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +12 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/sync-client.d.ts +41 -0
- package/dist/sync/sync-client.d.ts.map +1 -0
- package/dist/sync/sync-client.js +101 -0
- package/dist/sync/sync-client.js.map +1 -0
- package/dist/sync/sync-engine.d.ts +58 -0
- package/dist/sync/sync-engine.d.ts.map +1 -0
- package/dist/sync/sync-engine.js +370 -0
- package/dist/sync/sync-engine.js.map +1 -0
- package/dist/sync/types.d.ts +107 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +20 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/token-savings.d.ts +42 -0
- package/dist/token-savings.d.ts.map +1 -0
- package/dist/token-savings.js +104 -0
- package/dist/token-savings.js.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/ConfigManager.d.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Global config format (~/.memento/config.json).
|
|
3
|
+
* No per-project config files — all projects share the centralized DB.
|
|
4
|
+
*/
|
|
2
5
|
export interface MementoConfig {
|
|
3
|
-
|
|
4
|
-
dbPath?: string;
|
|
5
|
-
storagePath?: string;
|
|
6
|
-
projectId?: string;
|
|
7
|
-
}
|
|
8
|
-
/** New structured config format (.memento/config.json) */
|
|
9
|
-
export interface MementoConfigV1 {
|
|
10
|
-
version: 1;
|
|
11
|
-
project: string;
|
|
12
|
-
database: {
|
|
13
|
-
path: string;
|
|
14
|
-
wal?: boolean;
|
|
15
|
-
};
|
|
6
|
+
version?: number;
|
|
16
7
|
defaults?: {
|
|
17
|
-
autoSeed?: boolean;
|
|
18
8
|
scope?: 'project' | 'personal';
|
|
9
|
+
tokenSavings?: {
|
|
10
|
+
/** Report estimated token savings in search/context responses. Default: true */
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
};
|
|
19
13
|
session?: {
|
|
20
14
|
/** Max ms a session can be active before considered stale. Default: 86400000 (24h) */
|
|
21
15
|
staleThresholdMs?: number;
|
|
@@ -24,34 +18,24 @@ export interface MementoConfigV1 {
|
|
|
24
18
|
}
|
|
25
19
|
/** Default stale threshold: 24 hours in milliseconds */
|
|
26
20
|
export declare const DEFAULT_STALE_THRESHOLD_MS: number;
|
|
27
|
-
/**
|
|
28
|
-
export interface
|
|
29
|
-
project?: string;
|
|
30
|
-
dbPath?: string;
|
|
31
|
-
targetDir?: string;
|
|
32
|
-
force?: boolean;
|
|
33
|
-
global?: boolean;
|
|
34
|
-
}
|
|
35
|
-
/** Result of config creation */
|
|
36
|
-
export interface CreateConfigResult {
|
|
21
|
+
/** Result of config initialization */
|
|
22
|
+
export interface InitConfigResult {
|
|
37
23
|
configPath: string;
|
|
38
24
|
dbPath: string;
|
|
39
|
-
|
|
40
|
-
migrated: boolean;
|
|
41
|
-
backupPath?: string;
|
|
25
|
+
created: boolean;
|
|
42
26
|
}
|
|
43
|
-
/** Result of
|
|
44
|
-
export interface
|
|
27
|
+
/** Result of project DB migration */
|
|
28
|
+
export interface MigrateProjectDbResult {
|
|
45
29
|
success: boolean;
|
|
46
30
|
sourcePath: string;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
projectDir: string;
|
|
32
|
+
projectId: string;
|
|
33
|
+
observationsImported: number;
|
|
34
|
+
sessionsImported: number;
|
|
50
35
|
error?: string;
|
|
51
36
|
}
|
|
52
|
-
|
|
53
|
-
declare const
|
|
54
|
-
declare const NEW_CONFIG_FILE = "config.json";
|
|
37
|
+
/** Centralized database path — all projects in one DB */
|
|
38
|
+
export declare const GLOBAL_DB_PATH: string;
|
|
55
39
|
declare const GLOBAL_CONFIG_DIR: string;
|
|
56
40
|
declare const GLOBAL_CONFIG_PATH: string;
|
|
57
41
|
/**
|
|
@@ -62,41 +46,42 @@ declare const GLOBAL_CONFIG_PATH: string;
|
|
|
62
46
|
* - Strip leading/trailing hyphens
|
|
63
47
|
*
|
|
64
48
|
* Examples:
|
|
65
|
-
* "sura chile autos"
|
|
66
|
-
* "suratech-salesforce-CL-app"
|
|
67
|
-
* "my__cool project"
|
|
68
|
-
* "--leading-trailing--"
|
|
69
|
-
* " spaces everywhere "
|
|
49
|
+
* "sura chile autos" -> "sura-chile-autos"
|
|
50
|
+
* "suratech-salesforce-CL-app" -> "suratech-salesforce-cl-app"
|
|
51
|
+
* "my__cool project" -> "my-cool-project"
|
|
52
|
+
* "--leading-trailing--" -> "leading-trailing"
|
|
53
|
+
* " spaces everywhere " -> "spaces-everywhere"
|
|
70
54
|
*/
|
|
71
55
|
export declare function normalizeProjectId(name: string): string;
|
|
72
56
|
/**
|
|
73
|
-
*
|
|
74
|
-
* Priority:
|
|
57
|
+
* Resolve the database path.
|
|
58
|
+
* Priority: MEMENTO_DB_PATH env var > centralized ~/.memento/memento.db
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveDbPath(_config?: MementoConfig): string;
|
|
61
|
+
/**
|
|
62
|
+
* Detect project_id from the current working directory.
|
|
63
|
+
* Priority: MEMENTO_PROJECT_ID env var > package.json name > directory name > "default"
|
|
75
64
|
*/
|
|
76
|
-
export declare function
|
|
65
|
+
export declare function getProjectId(_config?: MementoConfig): string;
|
|
77
66
|
/**
|
|
78
|
-
*
|
|
79
|
-
* Returns
|
|
67
|
+
* Load global config from ~/.memento/config.json.
|
|
68
|
+
* Returns default config if file doesn't exist.
|
|
80
69
|
*/
|
|
81
|
-
export declare function
|
|
70
|
+
export declare function loadConfig(): MementoConfig;
|
|
82
71
|
/**
|
|
83
|
-
* Read the stale session threshold from
|
|
72
|
+
* Read the stale session threshold from global config.
|
|
84
73
|
* Returns DEFAULT_STALE_THRESHOLD_MS (24h) if not configured.
|
|
85
74
|
*/
|
|
86
75
|
export declare function getStaleThresholdMs(): number;
|
|
87
|
-
export declare function loadConfig(): MementoConfig;
|
|
88
|
-
export declare function resolveStoragePath(config: MementoConfig): string;
|
|
89
|
-
export declare function resolveDbPath(config: MementoConfig): string;
|
|
90
|
-
export declare function getProjectId(config: MementoConfig): string;
|
|
91
76
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
77
|
+
* Check if token savings reporting is enabled.
|
|
78
|
+
* Priority: MEMENTO_TOKEN_SAVINGS env var > config file > default (true)
|
|
94
79
|
*/
|
|
95
|
-
export declare function
|
|
80
|
+
export declare function isTokenSavingsEnabled(): boolean;
|
|
96
81
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
82
|
+
* Ensure the global ~/.memento/ directory and config exist.
|
|
83
|
+
* Creates them if they don't exist.
|
|
99
84
|
*/
|
|
100
|
-
export declare function
|
|
101
|
-
export { GLOBAL_CONFIG_DIR, GLOBAL_CONFIG_PATH
|
|
85
|
+
export declare function ensureGlobalDir(): InitConfigResult;
|
|
86
|
+
export { GLOBAL_CONFIG_DIR, GLOBAL_CONFIG_PATH };
|
|
102
87
|
//# sourceMappingURL=ConfigManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigManager.d.ts","sourceRoot":"","sources":["../src/ConfigManager.ts"],"names":[],"mappings":"AAMA
|
|
1
|
+
{"version":3,"file":"ConfigManager.d.ts","sourceRoot":"","sources":["../src/ConfigManager.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC;QAC/B,YAAY,CAAC,EAAE;YACb,gFAAgF;YAChF,OAAO,CAAC,EAAE,OAAO,CAAC;SACnB,CAAC;QACF,OAAO,CAAC,EAAE;YACR,sFAAsF;YACtF,gBAAgB,CAAC,EAAE,MAAM,CAAC;SAC3B,CAAC;KACH,CAAC;CACH;AAED,wDAAwD;AACxD,eAAO,MAAM,0BAA0B,QAAsB,CAAC;AAE9D,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qCAAqC;AACrC,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,yDAAyD;AACzD,eAAO,MAAM,cAAc,QAA4C,CAAC;AAExE,QAAA,MAAM,iBAAiB,QAA8B,CAAC;AAEtD,QAAA,MAAM,kBAAkB,QAA8C,CAAC;AAIvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAWvD;AAmBD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAU7D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAW5D;AAID;;;GAGG;AACH,wBAAgB,UAAU,IAAI,aAAa,CAO1C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,MAAM,CAO5C;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAgB/C;AAID;;;GAGG;AACH,wBAAgB,eAAe,IAAI,gBAAgB,CAqBlD;AAID,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/ConfigManager.js
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.GLOBAL_CONFIG_PATH = exports.GLOBAL_CONFIG_DIR = exports.GLOBAL_DB_PATH = exports.DEFAULT_STALE_THRESHOLD_MS = void 0;
|
|
4
4
|
exports.normalizeProjectId = normalizeProjectId;
|
|
5
|
-
exports.findProjectConfig = findProjectConfig;
|
|
6
|
-
exports.findConfigPath = findConfigPath;
|
|
7
|
-
exports.getStaleThresholdMs = getStaleThresholdMs;
|
|
8
|
-
exports.loadConfig = loadConfig;
|
|
9
|
-
exports.resolveStoragePath = resolveStoragePath;
|
|
10
5
|
exports.resolveDbPath = resolveDbPath;
|
|
11
6
|
exports.getProjectId = getProjectId;
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
7
|
+
exports.loadConfig = loadConfig;
|
|
8
|
+
exports.getStaleThresholdMs = getStaleThresholdMs;
|
|
9
|
+
exports.isTokenSavingsEnabled = isTokenSavingsEnabled;
|
|
10
|
+
exports.ensureGlobalDir = ensureGlobalDir;
|
|
14
11
|
const fs_1 = require("fs");
|
|
15
12
|
const path_1 = require("path");
|
|
16
13
|
const os_1 = require("os");
|
|
17
14
|
/** Default stale threshold: 24 hours in milliseconds */
|
|
18
15
|
exports.DEFAULT_STALE_THRESHOLD_MS = 24 * 60 * 60 * 1000;
|
|
19
16
|
// ─── Constants ──────────────────────────────────────────────
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
dbPath: '.memento/db/memento.db',
|
|
23
|
-
storagePath: 'database/storage',
|
|
24
|
-
};
|
|
25
|
-
const LEGACY_CONFIG_FILE = '.mementorc';
|
|
26
|
-
exports.LEGACY_CONFIG_FILE = LEGACY_CONFIG_FILE;
|
|
27
|
-
const NEW_CONFIG_DIR = '.memento';
|
|
28
|
-
exports.NEW_CONFIG_DIR = NEW_CONFIG_DIR;
|
|
29
|
-
const NEW_CONFIG_FILE = 'config.json';
|
|
30
|
-
exports.NEW_CONFIG_FILE = NEW_CONFIG_FILE;
|
|
17
|
+
/** Centralized database path — all projects in one DB */
|
|
18
|
+
exports.GLOBAL_DB_PATH = (0, path_1.join)((0, os_1.homedir)(), '.memento', 'memento.db');
|
|
31
19
|
const GLOBAL_CONFIG_DIR = (0, path_1.join)((0, os_1.homedir)(), '.memento');
|
|
32
20
|
exports.GLOBAL_CONFIG_DIR = GLOBAL_CONFIG_DIR;
|
|
33
21
|
const GLOBAL_CONFIG_FILE = 'config.json';
|
|
@@ -42,11 +30,11 @@ exports.GLOBAL_CONFIG_PATH = GLOBAL_CONFIG_PATH;
|
|
|
42
30
|
* - Strip leading/trailing hyphens
|
|
43
31
|
*
|
|
44
32
|
* Examples:
|
|
45
|
-
* "sura chile autos"
|
|
46
|
-
* "suratech-salesforce-CL-app"
|
|
47
|
-
* "my__cool project"
|
|
48
|
-
* "--leading-trailing--"
|
|
49
|
-
* " spaces everywhere "
|
|
33
|
+
* "sura chile autos" -> "sura-chile-autos"
|
|
34
|
+
* "suratech-salesforce-CL-app" -> "suratech-salesforce-cl-app"
|
|
35
|
+
* "my__cool project" -> "my-cool-project"
|
|
36
|
+
* "--leading-trailing--" -> "leading-trailing"
|
|
37
|
+
* " spaces everywhere " -> "spaces-everywhere"
|
|
50
38
|
*/
|
|
51
39
|
function normalizeProjectId(name) {
|
|
52
40
|
if (!name || typeof name !== 'string') {
|
|
@@ -72,288 +60,99 @@ function loadJSONFile(path) {
|
|
|
72
60
|
return null;
|
|
73
61
|
}
|
|
74
62
|
}
|
|
75
|
-
|
|
76
|
-
return (typeof config === 'object' &&
|
|
77
|
-
config !== null &&
|
|
78
|
-
config.version === 1 &&
|
|
79
|
-
typeof config.project === 'string' &&
|
|
80
|
-
typeof config.database?.path === 'string');
|
|
81
|
-
}
|
|
82
|
-
function deriveProjectName(dir) {
|
|
83
|
-
// Try package.json first
|
|
84
|
-
const packageJsonPath = (0, path_1.join)(dir, 'package.json');
|
|
85
|
-
const packageJson = loadJSONFile(packageJsonPath);
|
|
86
|
-
if (packageJson?.name) {
|
|
87
|
-
// Strip @scope/ prefix
|
|
88
|
-
return packageJson.name.replace(/^@[^/]+\//, '');
|
|
89
|
-
}
|
|
90
|
-
// Fall back to directory name
|
|
91
|
-
return (0, path_1.basename)(dir);
|
|
92
|
-
}
|
|
93
|
-
// ─── Config Discovery ──────────────────────────────────────
|
|
63
|
+
// ─── Path Resolution ────────────────────────────────────────
|
|
94
64
|
/**
|
|
95
|
-
*
|
|
96
|
-
* Priority:
|
|
65
|
+
* Resolve the database path.
|
|
66
|
+
* Priority: MEMENTO_DB_PATH env var > centralized ~/.memento/memento.db
|
|
97
67
|
*/
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// New format first: .memento/config.json
|
|
104
|
-
const newConfigPath = (0, path_1.join)(currentDir, NEW_CONFIG_DIR, NEW_CONFIG_FILE);
|
|
105
|
-
if ((0, fs_1.existsSync)(newConfigPath)) {
|
|
106
|
-
const config = loadJSONFile(newConfigPath);
|
|
107
|
-
if (isConfigV1(config)) {
|
|
108
|
-
return configV1ToLegacy(config, currentDir);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// Legacy format: .mementorc
|
|
112
|
-
const legacyConfigPath = (0, path_1.join)(currentDir, LEGACY_CONFIG_FILE);
|
|
113
|
-
if ((0, fs_1.existsSync)(legacyConfigPath)) {
|
|
114
|
-
const config = loadJSONFile(legacyConfigPath);
|
|
115
|
-
if (config) {
|
|
116
|
-
return config;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const parentDir = (0, path_1.dirname)(currentDir);
|
|
120
|
-
if (parentDir === currentDir) {
|
|
121
|
-
break;
|
|
68
|
+
function resolveDbPath(_config) {
|
|
69
|
+
if (process.env.MEMENTO_DB_PATH) {
|
|
70
|
+
const envPath = process.env.MEMENTO_DB_PATH;
|
|
71
|
+
if (envPath.startsWith('~/')) {
|
|
72
|
+
return (0, path_1.join)((0, os_1.homedir)(), envPath.slice(2));
|
|
122
73
|
}
|
|
123
|
-
|
|
124
|
-
depth++;
|
|
74
|
+
return envPath;
|
|
125
75
|
}
|
|
126
|
-
return
|
|
76
|
+
return exports.GLOBAL_DB_PATH;
|
|
127
77
|
}
|
|
128
78
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
79
|
+
* Detect project_id from the current working directory.
|
|
80
|
+
* Priority: MEMENTO_PROJECT_ID env var > package.json name > directory name > "default"
|
|
131
81
|
*/
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
let depth = 0;
|
|
136
|
-
while (depth < maxDepth) {
|
|
137
|
-
const newConfigPath = (0, path_1.join)(currentDir, NEW_CONFIG_DIR, NEW_CONFIG_FILE);
|
|
138
|
-
if ((0, fs_1.existsSync)(newConfigPath))
|
|
139
|
-
return newConfigPath;
|
|
140
|
-
const legacyConfigPath = (0, path_1.join)(currentDir, LEGACY_CONFIG_FILE);
|
|
141
|
-
if ((0, fs_1.existsSync)(legacyConfigPath))
|
|
142
|
-
return legacyConfigPath;
|
|
143
|
-
const parentDir = (0, path_1.dirname)(currentDir);
|
|
144
|
-
if (parentDir === currentDir)
|
|
145
|
-
break;
|
|
146
|
-
currentDir = parentDir;
|
|
147
|
-
depth++;
|
|
82
|
+
function getProjectId(_config) {
|
|
83
|
+
if (process.env.MEMENTO_PROJECT_ID) {
|
|
84
|
+
return normalizeProjectId(process.env.MEMENTO_PROJECT_ID);
|
|
148
85
|
}
|
|
149
|
-
|
|
86
|
+
const packageJsonPath = (0, path_1.join)(process.cwd(), 'package.json');
|
|
87
|
+
const packageJson = loadJSONFile(packageJsonPath);
|
|
88
|
+
const rawName = packageJson?.name || (0, path_1.basename)(process.cwd());
|
|
89
|
+
// Strip @scope/ prefix before normalizing
|
|
90
|
+
return normalizeProjectId(rawName.replace(/^@[^/]+\//, ''));
|
|
150
91
|
}
|
|
151
92
|
// ─── Config Loading ─────────────────────────────────────────
|
|
152
93
|
/**
|
|
153
|
-
*
|
|
154
|
-
* Returns
|
|
94
|
+
* Load global config from ~/.memento/config.json.
|
|
95
|
+
* Returns default config if file doesn't exist.
|
|
155
96
|
*/
|
|
156
|
-
function getStaleThresholdMs() {
|
|
157
|
-
const configPath = findConfigPath();
|
|
158
|
-
if (!configPath)
|
|
159
|
-
return exports.DEFAULT_STALE_THRESHOLD_MS;
|
|
160
|
-
// Only V1 config supports this setting
|
|
161
|
-
if (configPath.endsWith('config.json')) {
|
|
162
|
-
const v1 = loadJSONFile(configPath);
|
|
163
|
-
if (v1?.defaults?.session?.staleThresholdMs) {
|
|
164
|
-
return v1.defaults.session.staleThresholdMs;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return exports.DEFAULT_STALE_THRESHOLD_MS;
|
|
168
|
-
}
|
|
169
97
|
function loadConfig() {
|
|
170
|
-
let config = { ...DEFAULT_CONFIG };
|
|
171
|
-
const projectConfig = findProjectConfig();
|
|
172
|
-
if (projectConfig) {
|
|
173
|
-
config = { ...config, ...projectConfig };
|
|
174
|
-
}
|
|
175
98
|
const globalConfig = loadJSONFile(GLOBAL_CONFIG_PATH);
|
|
176
99
|
if (globalConfig) {
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
// Environment variable overrides
|
|
180
|
-
if (process.env.MEMENTO_STORAGE_METHOD) {
|
|
181
|
-
config.storageMethod = process.env.MEMENTO_STORAGE_METHOD;
|
|
182
|
-
}
|
|
183
|
-
if (process.env.MEMENTO_DB_PATH) {
|
|
184
|
-
config.dbPath = process.env.MEMENTO_DB_PATH;
|
|
185
|
-
}
|
|
186
|
-
if (process.env.MEMENTO_STORAGE_PATH) {
|
|
187
|
-
config.storagePath = process.env.MEMENTO_STORAGE_PATH;
|
|
188
|
-
}
|
|
189
|
-
if (process.env.MEMENTO_PROJECT_ID) {
|
|
190
|
-
config.projectId = process.env.MEMENTO_PROJECT_ID;
|
|
191
|
-
}
|
|
192
|
-
return config;
|
|
193
|
-
}
|
|
194
|
-
// ─── Path Resolution ────────────────────────────────────────
|
|
195
|
-
function resolveStoragePath(config) {
|
|
196
|
-
const storagePath = config.storagePath || DEFAULT_CONFIG.storagePath;
|
|
197
|
-
if (storagePath.startsWith('/')) {
|
|
198
|
-
return storagePath;
|
|
199
|
-
}
|
|
200
|
-
if (storagePath.startsWith('~/')) {
|
|
201
|
-
return (0, path_1.join)((0, os_1.homedir)(), storagePath.slice(2));
|
|
202
|
-
}
|
|
203
|
-
return (0, path_1.join)(process.cwd(), storagePath);
|
|
204
|
-
}
|
|
205
|
-
function resolveDbPath(config) {
|
|
206
|
-
const dbPath = config.dbPath || DEFAULT_CONFIG.dbPath;
|
|
207
|
-
if (dbPath.startsWith('/')) {
|
|
208
|
-
return dbPath;
|
|
209
|
-
}
|
|
210
|
-
if (dbPath.startsWith('~/')) {
|
|
211
|
-
return (0, path_1.join)((0, os_1.homedir)(), dbPath.slice(2));
|
|
100
|
+
return globalConfig;
|
|
212
101
|
}
|
|
213
|
-
return
|
|
102
|
+
return { version: 1, defaults: { scope: 'project' } };
|
|
214
103
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Read the stale session threshold from global config.
|
|
106
|
+
* Returns DEFAULT_STALE_THRESHOLD_MS (24h) if not configured.
|
|
107
|
+
*/
|
|
108
|
+
function getStaleThresholdMs() {
|
|
109
|
+
const config = loadConfig();
|
|
110
|
+
if (config?.defaults?.session?.staleThresholdMs) {
|
|
111
|
+
return config.defaults.session.staleThresholdMs;
|
|
218
112
|
}
|
|
219
|
-
|
|
220
|
-
const packageJson = loadJSONFile(packageJsonPath);
|
|
221
|
-
const rawName = packageJson?.name || 'default';
|
|
222
|
-
// Strip @scope/ prefix before normalizing (consistent with deriveProjectName)
|
|
223
|
-
return normalizeProjectId(rawName.replace(/^@[^/]+\//, ''));
|
|
224
|
-
}
|
|
225
|
-
// ─── Config V1 ↔ Legacy Conversion ─────────────────────────
|
|
226
|
-
function configV1ToLegacy(v1, _configDir) {
|
|
227
|
-
return {
|
|
228
|
-
storageMethod: 'database',
|
|
229
|
-
dbPath: v1.database.path,
|
|
230
|
-
projectId: v1.project,
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
function legacyToConfigV1(legacy, projectDir) {
|
|
234
|
-
return {
|
|
235
|
-
version: 1,
|
|
236
|
-
project: legacy.projectId || deriveProjectName(projectDir),
|
|
237
|
-
database: {
|
|
238
|
-
path: legacy.dbPath || (0, path_1.join)('.memento', 'memento.db'),
|
|
239
|
-
wal: true,
|
|
240
|
-
},
|
|
241
|
-
defaults: {
|
|
242
|
-
autoSeed: true,
|
|
243
|
-
scope: 'project',
|
|
244
|
-
},
|
|
245
|
-
};
|
|
113
|
+
return exports.DEFAULT_STALE_THRESHOLD_MS;
|
|
246
114
|
}
|
|
247
|
-
// ─── Config Creation ────────────────────────────────────────
|
|
248
115
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
116
|
+
* Check if token savings reporting is enabled.
|
|
117
|
+
* Priority: MEMENTO_TOKEN_SAVINGS env var > config file > default (true)
|
|
251
118
|
*/
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
let migrated = false;
|
|
267
|
-
let backupPath;
|
|
268
|
-
const legacyPath = (0, path_1.join)(resolvedDir, LEGACY_CONFIG_FILE);
|
|
269
|
-
let projectName = project || deriveProjectName(resolvedDir);
|
|
270
|
-
let resolvedDbPath = dbPath || (0, path_1.join)(NEW_CONFIG_DIR, 'memento.db');
|
|
271
|
-
// If migrating from legacy config
|
|
272
|
-
if (!global && (0, fs_1.existsSync)(legacyPath)) {
|
|
273
|
-
const legacyConfig = loadJSONFile(legacyPath);
|
|
274
|
-
if (legacyConfig) {
|
|
275
|
-
if (!project)
|
|
276
|
-
projectName = legacyConfig.projectId || projectName;
|
|
277
|
-
if (!dbPath && legacyConfig.dbPath) {
|
|
278
|
-
// Keep existing DB path from legacy config
|
|
279
|
-
resolvedDbPath = legacyConfig.dbPath;
|
|
280
|
-
}
|
|
281
|
-
migrated = true;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
// Build V1 config
|
|
285
|
-
const config = {
|
|
286
|
-
version: 1,
|
|
287
|
-
project: projectName,
|
|
288
|
-
database: {
|
|
289
|
-
path: resolvedDbPath,
|
|
290
|
-
wal: true,
|
|
291
|
-
},
|
|
292
|
-
defaults: {
|
|
293
|
-
autoSeed: true,
|
|
294
|
-
scope: global ? 'personal' : 'project',
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
// Write config
|
|
298
|
-
(0, fs_1.mkdirSync)(configDir, { recursive: true });
|
|
299
|
-
(0, fs_1.writeFileSync)(configPath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
300
|
-
return {
|
|
301
|
-
configPath,
|
|
302
|
-
dbPath: global
|
|
303
|
-
? (0, path_1.join)(GLOBAL_CONFIG_DIR, resolvedDbPath)
|
|
304
|
-
: (0, path_1.join)(resolvedDir, resolvedDbPath),
|
|
305
|
-
projectDir: resolvedDir,
|
|
306
|
-
migrated,
|
|
307
|
-
backupPath,
|
|
308
|
-
};
|
|
119
|
+
function isTokenSavingsEnabled() {
|
|
120
|
+
// Env var override (highest priority)
|
|
121
|
+
const envVal = process.env.MEMENTO_TOKEN_SAVINGS;
|
|
122
|
+
if (envVal !== undefined) {
|
|
123
|
+
return envVal === 'true' || envVal === '1';
|
|
124
|
+
}
|
|
125
|
+
// Config file
|
|
126
|
+
const config = loadConfig();
|
|
127
|
+
const configVal = config?.defaults?.tokenSavings?.enabled;
|
|
128
|
+
if (configVal !== undefined) {
|
|
129
|
+
return configVal;
|
|
130
|
+
}
|
|
131
|
+
// Default: enabled
|
|
132
|
+
return true;
|
|
309
133
|
}
|
|
310
|
-
// ───
|
|
134
|
+
// ─── Initialization ─────────────────────────────────────────
|
|
311
135
|
/**
|
|
312
|
-
*
|
|
313
|
-
*
|
|
136
|
+
* Ensure the global ~/.memento/ directory and config exist.
|
|
137
|
+
* Creates them if they don't exist.
|
|
314
138
|
*/
|
|
315
|
-
function
|
|
316
|
-
|
|
317
|
-
const
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
targetPath,
|
|
326
|
-
backupPath,
|
|
327
|
-
config: {},
|
|
328
|
-
error: `No .mementorc found at ${sourcePath}`,
|
|
139
|
+
function ensureGlobalDir() {
|
|
140
|
+
(0, fs_1.mkdirSync)(GLOBAL_CONFIG_DIR, { recursive: true });
|
|
141
|
+
const configPath = GLOBAL_CONFIG_PATH;
|
|
142
|
+
const created = !(0, fs_1.existsSync)(configPath);
|
|
143
|
+
if (created) {
|
|
144
|
+
const defaultConfig = {
|
|
145
|
+
version: 1,
|
|
146
|
+
defaults: {
|
|
147
|
+
scope: 'project',
|
|
148
|
+
},
|
|
329
149
|
};
|
|
150
|
+
(0, fs_1.writeFileSync)(configPath, JSON.stringify(defaultConfig, null, 2) + '\n', 'utf-8');
|
|
330
151
|
}
|
|
331
|
-
// Load and validate legacy config
|
|
332
|
-
const legacyConfig = loadJSONFile(sourcePath);
|
|
333
|
-
if (!legacyConfig) {
|
|
334
|
-
return {
|
|
335
|
-
success: false,
|
|
336
|
-
sourcePath,
|
|
337
|
-
targetPath,
|
|
338
|
-
backupPath,
|
|
339
|
-
config: {},
|
|
340
|
-
error: `Failed to parse ${sourcePath}`,
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
// Convert to V1
|
|
344
|
-
const v1Config = legacyToConfigV1(legacyConfig, sourceDir);
|
|
345
|
-
// Create target directory
|
|
346
|
-
(0, fs_1.mkdirSync)(targetDir, { recursive: true });
|
|
347
|
-
// Write new config
|
|
348
|
-
(0, fs_1.writeFileSync)(targetPath, JSON.stringify(v1Config, null, 2) + '\n', 'utf-8');
|
|
349
|
-
// Backup original
|
|
350
|
-
(0, fs_1.renameSync)(sourcePath, backupPath);
|
|
351
152
|
return {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
backupPath,
|
|
356
|
-
config: v1Config,
|
|
153
|
+
configPath,
|
|
154
|
+
dbPath: exports.GLOBAL_DB_PATH,
|
|
155
|
+
created,
|
|
357
156
|
};
|
|
358
157
|
}
|
|
359
158
|
//# sourceMappingURL=ConfigManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConfigManager.js","sourceRoot":"","sources":["../src/ConfigManager.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ConfigManager.js","sourceRoot":"","sources":["../src/ConfigManager.ts"],"names":[],"mappings":";;;AAuEA,gDAWC;AAuBD,sCAUC;AAMD,oCAWC;AAQD,gCAOC;AAMD,kDAOC;AAMD,sDAgBC;AAQD,0CAqBC;AAnND,2BAAwE;AACxE,+BAAsC;AACtC,2BAA6B;AAuB7B,wDAAwD;AAC3C,QAAA,0BAA0B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAoB9D,+DAA+D;AAE/D,yDAAyD;AAC5C,QAAA,cAAc,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;AAExE,MAAM,iBAAiB,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,UAAU,CAAC,CAAC;AAoK7C,8CAAiB;AAnK1B,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,kBAAkB,GAAG,IAAA,WAAI,EAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAAC;AAkK3C,gDAAkB;AAhK9C,8DAA8D;AAE9D;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAI;SACR,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAG,wDAAwD;SACtF,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAO,iCAAiC;WAC7D,SAAS,CAAC,CAAmB,8BAA8B;AAClE,CAAC;AAED,+DAA+D;AAE/D,SAAS,YAAY,CAAI,IAAY;IACnC,IAAI,CAAC,IAA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