@mingxy/cerebro 1.10.2 → 1.10.5
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 +11 -1
- package/src/hooks.ts +1 -1
- package/src/logger.ts +20 -5
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
|
}
|
package/src/hooks.ts
CHANGED
|
@@ -448,7 +448,7 @@ export function compactingHook(client: OmemClient, containerTags: string[], tui:
|
|
|
448
448
|
mode: ingestMode,
|
|
449
449
|
tags: [...containerTags, "auto-capture"],
|
|
450
450
|
sessionId: effectiveSessionId,
|
|
451
|
-
parentSessionId: isSubAgent ?
|
|
451
|
+
parentSessionId: isSubAgent ? getMainSessionId?.() : undefined,
|
|
452
452
|
projectName: projectName,
|
|
453
453
|
});
|
|
454
454
|
logDebug("compactingHook ingestMessages result", { result: result === null ? "null(blocked)" : "ok" });
|
package/src/logger.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
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
|
-
const
|
|
5
|
+
const LEVEL_MAP: Record<string, number> = {
|
|
6
|
+
DEBUG: 0,
|
|
7
|
+
INFO: 1,
|
|
8
|
+
WARN: 2,
|
|
9
|
+
ERROR: 3,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const cfg = loadPluginConfig();
|
|
13
|
+
const MIN_LEVEL = LEVEL_MAP[cfg.logLevel] ?? LEVEL_MAP.INFO;
|
|
14
|
+
const LOG_DIR = cfg.logDir;
|
|
6
15
|
const LOG_FILE = join(LOG_DIR, "plugin.log");
|
|
16
|
+
const LOG_ENABLED = cfg.logEnabled;
|
|
7
17
|
|
|
8
|
-
|
|
18
|
+
let lastLogTime = Date.now();
|
|
9
19
|
|
|
10
20
|
function ensureLogDir(): void {
|
|
11
21
|
if (!existsSync(LOG_DIR)) {
|
|
@@ -16,11 +26,16 @@ function ensureLogDir(): void {
|
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
function writeLog(level: string, message: string, fields?: Record<string, unknown>): void {
|
|
29
|
+
if (!LOG_ENABLED) return;
|
|
30
|
+
const lvl = LEVEL_MAP[level] ?? 0;
|
|
31
|
+
if (lvl < MIN_LEVEL) return;
|
|
19
32
|
ensureLogDir();
|
|
20
33
|
const now = new Date();
|
|
34
|
+
const nowMs = now.getTime();
|
|
35
|
+
const delta = ((nowMs - lastLogTime) / 1000).toFixed(2);
|
|
36
|
+
lastLogTime = nowMs;
|
|
21
37
|
const ts = now.toISOString().replace("T", " ").replace(/\.\d+Z$/, "");
|
|
22
|
-
const
|
|
23
|
-
const parts = [`${level.padEnd(5)} ${ts} +${offset}ms service=cerebro`];
|
|
38
|
+
const parts = [`${level.padEnd(5)} ${ts} +${delta}s service=cerebro`];
|
|
24
39
|
if (fields) {
|
|
25
40
|
for (const [k, v] of Object.entries(fields)) {
|
|
26
41
|
const val = typeof v === "string" ? v : JSON.stringify(v);
|