opencode-fractal-memory 0.6.6 → 0.6.8
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.
|
@@ -4,11 +4,10 @@ import * as os from "node:os";
|
|
|
4
4
|
import { Database } from "bun:sqlite";
|
|
5
5
|
import { memLog } from "../logging";
|
|
6
6
|
export const DB_PATHS = {};
|
|
7
|
-
export function initDbPaths(
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
DB_PATHS.
|
|
11
|
-
DB_PATHS.project = projectDbPath;
|
|
7
|
+
export function initDbPaths(_projectDir) {
|
|
8
|
+
const unifiedDbPath = path.join(os.homedir(), ".config", "opencode", "memory.db");
|
|
9
|
+
DB_PATHS.global = unifiedDbPath;
|
|
10
|
+
DB_PATHS.project = unifiedDbPath;
|
|
12
11
|
}
|
|
13
12
|
export function openDb(scope) {
|
|
14
13
|
const dbPath = DB_PATHS[scope] || scope;
|
|
@@ -88,11 +87,38 @@ export function queryNodes(scope) {
|
|
|
88
87
|
sticky, confidence, created_at, updated_at, parent_ids,
|
|
89
88
|
LENGTH(content) as content_length, metadata
|
|
90
89
|
FROM memory_nodes
|
|
90
|
+
WHERE scope = ?
|
|
91
91
|
ORDER BY level, importance DESC
|
|
92
|
-
`).all();
|
|
92
|
+
`).all(scope);
|
|
93
93
|
db.close();
|
|
94
94
|
return rows.map((r) => rowToNode(r));
|
|
95
95
|
}
|
|
96
|
+
export function queryPlaybooks(scope) {
|
|
97
|
+
const db = openDb(scope);
|
|
98
|
+
if (!db)
|
|
99
|
+
return [];
|
|
100
|
+
const rows = db.query(`
|
|
101
|
+
SELECT id, label, content, metadata, times_used, usefulness_score
|
|
102
|
+
FROM memory_nodes
|
|
103
|
+
WHERE type = 'playbook' AND scope = ?
|
|
104
|
+
ORDER BY label
|
|
105
|
+
`).all(scope);
|
|
106
|
+
db.close();
|
|
107
|
+
return rows.map((r) => {
|
|
108
|
+
const meta = r.metadata ? JSON.parse(r.metadata) : {};
|
|
109
|
+
return {
|
|
110
|
+
id: r.id,
|
|
111
|
+
name: r.label || "",
|
|
112
|
+
description: r.content || "",
|
|
113
|
+
steps: meta.steps || [],
|
|
114
|
+
triggers: meta.triggers || [],
|
|
115
|
+
tags: meta.tags || [],
|
|
116
|
+
executionCount: meta.executionCount ?? r.times_used ?? 0,
|
|
117
|
+
avgDurationMs: meta.avgDurationMs ?? null,
|
|
118
|
+
lastExecutedAt: meta.lastExecutedAt ?? null,
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
}
|
|
96
122
|
export function cosineSimilarity(a, b) {
|
|
97
123
|
let dot = 0, normA = 0, normB = 0;
|
|
98
124
|
for (let i = 0; i < a.length && i < b.length; i++) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { memLog } from "../logging";
|
|
2
2
|
import { generateEmbedding } from "../embeddings";
|
|
3
|
-
import { queryNodes, getAvailableScopes, extractLinks, computeStats, readProjectConfig, writeProjectConfig, rowToNode, withDb, jsonResponse, cosineSimilarity, } from "./helpers";
|
|
3
|
+
import { queryNodes, queryPlaybooks, getAvailableScopes, extractLinks, computeStats, readProjectConfig, writeProjectConfig, rowToNode, withDb, jsonResponse, cosineSimilarity, } from "./helpers";
|
|
4
4
|
function handleScopes() {
|
|
5
5
|
return jsonResponse(getAvailableScopes());
|
|
6
6
|
}
|
|
@@ -15,6 +15,9 @@ function handleStats(ctx) {
|
|
|
15
15
|
const nodes = queryNodes(ctx.scope);
|
|
16
16
|
return jsonResponse(computeStats(nodes));
|
|
17
17
|
}
|
|
18
|
+
function handlePlaybooks(ctx) {
|
|
19
|
+
return jsonResponse(queryPlaybooks(ctx.scope));
|
|
20
|
+
}
|
|
18
21
|
function handleConfigGet() {
|
|
19
22
|
return jsonResponse(readProjectConfig());
|
|
20
23
|
}
|
|
@@ -186,6 +189,7 @@ export function registerRoutes(router) {
|
|
|
186
189
|
router.get(/^\/api\/nodes$/, (_, ctx) => handleNodes(ctx));
|
|
187
190
|
router.get(/^\/api\/links$/, (_, ctx) => handleLinks(ctx));
|
|
188
191
|
router.get(/^\/api\/stats$/, (_, ctx) => handleStats(ctx));
|
|
192
|
+
router.get(/^\/api\/playbooks$/, (_, ctx) => handlePlaybooks(ctx));
|
|
189
193
|
router.get(/^\/api\/config$/, () => handleConfigGet());
|
|
190
194
|
router.put(/^\/api\/config$/, (req) => handleConfigSave(req));
|
|
191
195
|
router.post(/^\/api\/config$/, (req) => handleConfigSave(req));
|