opencode-fractal-memory 0.6.11 → 0.6.13
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/management-server.js +11 -1
- package/dist/plugin/hooks.js +20 -13
- package/dist/plugin/index.js +3 -3
- package/package.json +1 -1
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { memLog } from "./logging";
|
|
3
3
|
let activeProcess = null;
|
|
4
|
+
let mgmtConfig = null;
|
|
5
|
+
export function isManagementServerRunning() {
|
|
6
|
+
return activeProcess !== null;
|
|
7
|
+
}
|
|
8
|
+
export function ensureManagementServer() {
|
|
9
|
+
if (mgmtConfig && mgmtConfig.enabled) {
|
|
10
|
+
startManagementServer(null, mgmtConfig.directory, { enabled: true, port: mgmtConfig.port });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
4
13
|
export function startManagementServer(_store, directory, config) {
|
|
5
14
|
if (activeProcess) {
|
|
6
15
|
memLog("warn", "management", "Management server already running, killing old instance");
|
|
7
16
|
stopManagementServer();
|
|
8
17
|
}
|
|
9
18
|
const standalonePath = path.join(__dirname, "management-standalone.js");
|
|
19
|
+
mgmtConfig = { enabled: config.enabled, port: config.port, directory };
|
|
10
20
|
try {
|
|
11
21
|
const proc = Bun.spawn(["bun", standalonePath], {
|
|
12
22
|
env: {
|
|
@@ -35,7 +45,7 @@ export function startManagementServer(_store, directory, config) {
|
|
|
35
45
|
export function stopManagementServer() {
|
|
36
46
|
if (activeProcess) {
|
|
37
47
|
try {
|
|
38
|
-
activeProcess.kill("
|
|
48
|
+
activeProcess.kill("SIGKILL");
|
|
39
49
|
memLog("info", "management", `Management server process ${activeProcess.pid} killed`);
|
|
40
50
|
}
|
|
41
51
|
catch (err) {
|
package/dist/plugin/hooks.js
CHANGED
|
@@ -2,7 +2,7 @@ import { memLog, memLogSimple, setSessionId } from "../logging";
|
|
|
2
2
|
import { generateFileSummary, generateFileLabel, SOURCE_FILE_EXTENSIONS } from "../file-summary";
|
|
3
3
|
import { distillRules, predictiveRateToolCall, applyScoreDecay } from "../hooks";
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
|
-
export function createHookHandlers(store, client, memConfig, ruleCache, ruleCacheDirty, sessionInjectionLock, latestUserMessage) {
|
|
5
|
+
export function createHookHandlers(store, client, memConfig, ruleCache, ruleCacheDirty, sessionInjectionLock, latestUserMessage, managementServer) {
|
|
6
6
|
return {
|
|
7
7
|
"experimental.chat.system.transform": async (input, output) => {
|
|
8
8
|
const sessionId = input.sessionID ?? `session-${Date.now()}`;
|
|
@@ -149,19 +149,26 @@ export function createHookHandlers(store, client, memConfig, ruleCache, ruleCach
|
|
|
149
149
|
memLog("warn", "file-summary", "Failed to store file memory", { error: String(err) });
|
|
150
150
|
}
|
|
151
151
|
},
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
|
|
152
|
+
event: async (input) => {
|
|
153
|
+
const { type, properties } = input.event;
|
|
154
|
+
if (type === "session.created") {
|
|
155
|
+
const sessionId = properties.info?.id ?? "unknown";
|
|
156
|
+
await store.createSessionMetrics(sessionId);
|
|
157
|
+
setSessionId(sessionId);
|
|
158
|
+
managementServer.start();
|
|
159
|
+
}
|
|
160
|
+
else if (type === "session.idle") {
|
|
161
|
+
const sessionId = properties.sessionID ?? "unknown";
|
|
162
|
+
await store.updateSessionMetrics(sessionId, { endedAt: Date.now(), status: "completed" });
|
|
163
|
+
if (memConfig?.autoDistill?.enabled) {
|
|
164
|
+
distillRules(store, memConfig.autoDistill, sessionId, client).then(msg => memLog("info", "auto-distill", msg)).catch(err => memLog("error", "auto-distill", "Failed", { error: String(err) }));
|
|
165
|
+
}
|
|
166
|
+
if (memConfig?.predictiveRating?.enabled) {
|
|
167
|
+
applyScoreDecay(store, memConfig.predictiveRating).then(msg => memLog("info", "predictive-rating", msg)).catch(err => memLog("error", "predictive-rating", "Decay failed", { error: String(err) }));
|
|
168
|
+
}
|
|
162
169
|
}
|
|
163
|
-
if (
|
|
164
|
-
|
|
170
|
+
else if (type === "session.deleted") {
|
|
171
|
+
managementServer.stop();
|
|
165
172
|
}
|
|
166
173
|
},
|
|
167
174
|
};
|
package/dist/plugin/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { initStorage, loadPluginConfig, seedRuleNodes, backfillData, scheduleBac
|
|
|
2
2
|
import { createHookHandlers } from "./hooks";
|
|
3
3
|
import { createToolMap } from "./tools";
|
|
4
4
|
import { memLog, perfNow } from "../logging";
|
|
5
|
-
import { stopManagementServer } from "../management-server";
|
|
5
|
+
import { stopManagementServer, ensureManagementServer } from "../management-server";
|
|
6
6
|
export const MemoryPlugin = async (ctx) => {
|
|
7
7
|
const { directory, client } = ctx;
|
|
8
8
|
const t0 = perfNow();
|
|
@@ -33,14 +33,14 @@ export const MemoryPlugin = async (ctx) => {
|
|
|
33
33
|
const sessionInjectionLock = new Map();
|
|
34
34
|
const latestUserMessage = { value: "" };
|
|
35
35
|
const autoRetrieveHook = createAutoRetrieveIfEnabled(store, memConfig);
|
|
36
|
-
const handlers = createHookHandlers(store, client, memConfig, ruleCache, ruleCacheDirty, sessionInjectionLock, latestUserMessage);
|
|
36
|
+
const handlers = createHookHandlers(store, client, memConfig, ruleCache, ruleCacheDirty, sessionInjectionLock, latestUserMessage, { start: ensureManagementServer, stop: stopManagementServer });
|
|
37
37
|
const toolMap = createToolMap(store, journalTools, client);
|
|
38
38
|
memLog("info", "init", "Plugin initialization completed", { totalDurationMs: perfNow() - t0 });
|
|
39
39
|
return {
|
|
40
40
|
...handlers,
|
|
41
41
|
...(autoRetrieveHook || {}),
|
|
42
42
|
tool: toolMap,
|
|
43
|
-
|
|
43
|
+
dispose: async () => {
|
|
44
44
|
stopManagementServer();
|
|
45
45
|
await store.close();
|
|
46
46
|
},
|