@mingxy/cerebro 1.10.3 → 1.10.6
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/omem.example.jsonc +3 -8
- package/package.json +1 -1
- package/src/config.ts +16 -1
- package/src/logger.ts +11 -7
package/omem.example.jsonc
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
// omem server connection
|
|
3
2
|
"apiUrl": "https://www.mengxy.cc",
|
|
4
3
|
"apiKey": "your-tenant-id",
|
|
5
4
|
|
|
6
|
-
// request timeout in milliseconds
|
|
7
5
|
"requestTimeoutMs": 15000,
|
|
8
6
|
|
|
9
|
-
// content limits
|
|
10
7
|
"maxQueryLength": 200,
|
|
11
8
|
"maxContentChars": 30000,
|
|
12
9
|
"maxContentLength": 500,
|
|
13
10
|
|
|
14
|
-
// auto capture settings
|
|
15
11
|
"autoCaptureThreshold": 5,
|
|
16
12
|
"ingestMode": "smart",
|
|
17
13
|
|
|
18
|
-
// recall tuning
|
|
19
14
|
"similarityThreshold": 0.4,
|
|
20
15
|
"maxRecallResults": 10,
|
|
21
16
|
|
|
22
|
-
// UI settings
|
|
23
17
|
"toastDelayMs": 7000,
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
"
|
|
19
|
+
"logEnabled": true,
|
|
20
|
+
"logLevel": "INFO",
|
|
21
|
+
"logDir": "~/.config/cerebro"
|
|
27
22
|
}
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -20,6 +20,10 @@ export interface OmemPluginConfig {
|
|
|
20
20
|
maxRecallResults: number;
|
|
21
21
|
// UI settings
|
|
22
22
|
toastDelayMs: number;
|
|
23
|
+
// Logging
|
|
24
|
+
logEnabled: boolean;
|
|
25
|
+
logLevel: "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
26
|
+
logDir: string;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
const DEFAULTS: OmemPluginConfig = {
|
|
@@ -34,6 +38,9 @@ const DEFAULTS: OmemPluginConfig = {
|
|
|
34
38
|
similarityThreshold: 0.4,
|
|
35
39
|
maxRecallResults: 10,
|
|
36
40
|
toastDelayMs: 7000,
|
|
41
|
+
logEnabled: true,
|
|
42
|
+
logLevel: "INFO",
|
|
43
|
+
logDir: join(homedir(), ".config", "cerebro"),
|
|
37
44
|
};
|
|
38
45
|
|
|
39
46
|
export function loadPluginConfig(overrides?: Partial<OmemPluginConfig>): OmemPluginConfig {
|
|
@@ -41,7 +48,7 @@ export function loadPluginConfig(overrides?: Partial<OmemPluginConfig>): OmemPlu
|
|
|
41
48
|
|
|
42
49
|
// Try loading from config file
|
|
43
50
|
try {
|
|
44
|
-
const cfgPath = join(homedir(), ".config", "
|
|
51
|
+
const cfgPath = join(homedir(), ".config", "cerebro", "config.json");
|
|
45
52
|
const cfg = JSON.parse(readFileSync(cfgPath, "utf-8"));
|
|
46
53
|
|
|
47
54
|
if (cfg.apiUrl) config.apiUrl = cfg.apiUrl;
|
|
@@ -55,6 +62,9 @@ export function loadPluginConfig(overrides?: Partial<OmemPluginConfig>): OmemPlu
|
|
|
55
62
|
if (typeof cfg.similarityThreshold === "number") config.similarityThreshold = cfg.similarityThreshold;
|
|
56
63
|
if (typeof cfg.maxRecallResults === "number") config.maxRecallResults = cfg.maxRecallResults;
|
|
57
64
|
if (typeof cfg.toastDelayMs === "number") config.toastDelayMs = cfg.toastDelayMs;
|
|
65
|
+
if (typeof cfg.logEnabled === "boolean") config.logEnabled = cfg.logEnabled;
|
|
66
|
+
if (cfg.logLevel === "DEBUG" || cfg.logLevel === "INFO" || cfg.logLevel === "WARN" || cfg.logLevel === "ERROR") config.logLevel = cfg.logLevel;
|
|
67
|
+
if (typeof cfg.logDir === "string" && cfg.logDir) config.logDir = cfg.logDir;
|
|
58
68
|
} catch {
|
|
59
69
|
// Config file doesn't exist or is invalid, use defaults
|
|
60
70
|
}
|
|
@@ -83,6 +93,11 @@ export function loadPluginConfig(overrides?: Partial<OmemPluginConfig>): OmemPlu
|
|
|
83
93
|
Object.assign(config, overrides);
|
|
84
94
|
}
|
|
85
95
|
|
|
96
|
+
// Expand ~ to home directory in logDir
|
|
97
|
+
if (config.logDir?.startsWith("~")) {
|
|
98
|
+
config.logDir = config.logDir.replace(/^~/, homedir());
|
|
99
|
+
}
|
|
100
|
+
|
|
86
101
|
return config as OmemPluginConfig;
|
|
87
102
|
}
|
|
88
103
|
|
package/src/logger.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync, existsSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
2
|
import { join } from "node:path";
|
|
3
|
+
import { loadPluginConfig } from "./config.js";
|
|
4
4
|
|
|
5
5
|
const LEVEL_MAP: Record<string, number> = {
|
|
6
6
|
DEBUG: 0,
|
|
@@ -9,12 +9,13 @@ const LEVEL_MAP: Record<string, number> = {
|
|
|
9
9
|
ERROR: 3,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const LOG_DIR =
|
|
12
|
+
const cfg = loadPluginConfig();
|
|
13
|
+
const MIN_LEVEL = LEVEL_MAP[cfg.logLevel] ?? LEVEL_MAP.INFO;
|
|
14
|
+
const LOG_DIR = cfg.logDir;
|
|
15
15
|
const LOG_FILE = join(LOG_DIR, "plugin.log");
|
|
16
|
+
const LOG_ENABLED = cfg.logEnabled;
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
let lastLogTime = Date.now();
|
|
18
19
|
|
|
19
20
|
function ensureLogDir(): void {
|
|
20
21
|
if (!existsSync(LOG_DIR)) {
|
|
@@ -25,13 +26,16 @@ function ensureLogDir(): void {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function writeLog(level: string, message: string, fields?: Record<string, unknown>): void {
|
|
29
|
+
if (!LOG_ENABLED) return;
|
|
28
30
|
const lvl = LEVEL_MAP[level] ?? 0;
|
|
29
31
|
if (lvl < MIN_LEVEL) return;
|
|
30
32
|
ensureLogDir();
|
|
31
33
|
const now = new Date();
|
|
34
|
+
const nowMs = now.getTime();
|
|
35
|
+
const delta = ((nowMs - lastLogTime) / 1000).toFixed(2);
|
|
36
|
+
lastLogTime = nowMs;
|
|
32
37
|
const ts = now.toISOString().replace("T", " ").replace(/\.\d+Z$/, "");
|
|
33
|
-
const
|
|
34
|
-
const parts = [`${level.padEnd(5)} ${ts} +${offset}ms service=cerebro`];
|
|
38
|
+
const parts = [`${level.padEnd(5)} ${ts} +${delta}s service=cerebro`];
|
|
35
39
|
if (fields) {
|
|
36
40
|
for (const [k, v] of Object.entries(fields)) {
|
|
37
41
|
const val = typeof v === "string" ? v : JSON.stringify(v);
|