@nandoblanco/opencode-local-memory 1.1.1 → 1.2.0
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/README.md +31 -10
- package/dist/gui-experimental.cjs +1 -0
- package/gui.css +635 -0
- package/gui.tsx +1314 -0
- package/index.js +333 -6
- package/package.json +23 -3
- package/rpc.d.ts +140 -0
- package/rpc.js +221 -0
- package/tui.ts +682 -100
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import path from "node:path";
|
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import { execFile } from "node:child_process";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { MemoryRpc } from "./rpc.js";
|
|
9
10
|
|
|
10
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
11
12
|
const __dirname = path.dirname(__filename);
|
|
@@ -483,15 +484,15 @@ async function getEmbedder() {
|
|
|
483
484
|
embedderPromise = (async function () {
|
|
484
485
|
let pipelineFn;
|
|
485
486
|
try {
|
|
486
|
-
const mod = await import("@
|
|
487
|
+
const mod = await import("@huggingface/transformers");
|
|
487
488
|
pipelineFn = mod.pipeline;
|
|
488
489
|
} catch {
|
|
489
|
-
const fallbackPath = path.resolve(__dirname, "node_modules/@
|
|
490
|
+
const fallbackPath = path.resolve(__dirname, "node_modules/@huggingface/transformers/dist/transformers.node.mjs");
|
|
490
491
|
const fallbackUrl = new URL("file:///" + fallbackPath.replace(/\\/g, "/")).href;
|
|
491
492
|
const mod = await import(fallbackUrl);
|
|
492
493
|
pipelineFn = mod.pipeline;
|
|
493
494
|
}
|
|
494
|
-
return pipelineFn("feature-extraction", "Xenova/all-MiniLM-L6-v2");
|
|
495
|
+
return pipelineFn("feature-extraction", "Xenova/all-MiniLM-L6-v2", { device: "cpu", dtype: "q8" });
|
|
495
496
|
})().catch(function (err) {
|
|
496
497
|
embedderPromise = null;
|
|
497
498
|
throw err;
|
|
@@ -1263,10 +1264,19 @@ async function storeMemoryFact(rootDir, input) {
|
|
|
1263
1264
|
const rawTags = Array.isArray(input.tags)
|
|
1264
1265
|
? input.tags.map(function (t) { return String(t).trim(); }).filter(Boolean).join(", ")
|
|
1265
1266
|
: String(input.tags || rawTopic).trim();
|
|
1266
|
-
|
|
1267
|
+
let tagsList = rawTags.replace(/[\[\]]+/g, "").replace(/[\r\n\s]+/g, " ").trim() || rawTopic;
|
|
1268
|
+
if (input.core === false) {
|
|
1269
|
+
tagsList = tagsList
|
|
1270
|
+
.split(",")
|
|
1271
|
+
.map(function (t) { return t.trim(); })
|
|
1272
|
+
.filter(function (t) { return t && t.toLowerCase() !== "core"; })
|
|
1273
|
+
.join(", ") || rawTopic;
|
|
1274
|
+
}
|
|
1267
1275
|
const cleanFact = String(input.fact || "").replace(/\s+/g, " ").trim();
|
|
1268
1276
|
const projectScope = normalizeProjectScope(input.project);
|
|
1269
|
-
const isCore = input.core ===
|
|
1277
|
+
const isCore = input.core === false
|
|
1278
|
+
? false
|
|
1279
|
+
: (input.core === true || /(?:^|,)\s*core\s*(?:,|$)/i.test(tagsList));
|
|
1270
1280
|
|
|
1271
1281
|
const blockLines = [
|
|
1272
1282
|
"",
|
|
@@ -1987,6 +1997,228 @@ function extractLastUserText(messages) {
|
|
|
1987
1997
|
return "";
|
|
1988
1998
|
}
|
|
1989
1999
|
|
|
2000
|
+
function isSafeSubPath(parentDir, targetPath) {
|
|
2001
|
+
const rel = path.relative(path.resolve(parentDir), path.resolve(targetPath));
|
|
2002
|
+
return Boolean(rel && !rel.startsWith("..") && !path.isAbsolute(rel));
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
function isSafeRegexPattern(pattern) {
|
|
2006
|
+
if (!pattern || pattern.length > 256) return false;
|
|
2007
|
+
if (/(\([^()]*[+*?][^()]*\))\s*[+*?{]/.test(pattern)) return false;
|
|
2008
|
+
return true;
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
function readSessionMarkdown(rootDir, relFile) {
|
|
2012
|
+
try {
|
|
2013
|
+
const cleanRel = String(relFile || "").replace(/\\/g, "/");
|
|
2014
|
+
if (!cleanRel.startsWith("sessions/")) return "";
|
|
2015
|
+
const fullPath = path.resolve(rootDir, cleanRel);
|
|
2016
|
+
if (!isSafeSubPath(rootDir, fullPath)) return "";
|
|
2017
|
+
if (fs.existsSync(fullPath)) {
|
|
2018
|
+
return fs.readFileSync(fullPath, "utf8").replace(/\r\n/g, "\n").trim();
|
|
2019
|
+
}
|
|
2020
|
+
} catch {
|
|
2021
|
+
// ignore read error
|
|
2022
|
+
}
|
|
2023
|
+
return "";
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
function parseInlineMemoryFilters(rawQ, tFilter, topFilter, mFilter, projFilter, coreOnlyFlag) {
|
|
2027
|
+
let effType = tFilter || "all";
|
|
2028
|
+
let effTopic = topFilter || "all";
|
|
2029
|
+
let effMode = mFilter || "hybrid";
|
|
2030
|
+
let effProject = projFilter || "all";
|
|
2031
|
+
let effCoreOnly = Boolean(coreOnlyFlag) || effType === "core";
|
|
2032
|
+
const tokens = String(rawQ || "").trim().split(/\s+/).filter(Boolean);
|
|
2033
|
+
const cleanTokens = [];
|
|
2034
|
+
|
|
2035
|
+
for (const tok of tokens) {
|
|
2036
|
+
const lower = tok.toLowerCase();
|
|
2037
|
+
if (lower === "type:topics" || lower === "type:facts" || lower === "in:topics") {
|
|
2038
|
+
effType = "topics";
|
|
2039
|
+
} else if (lower === "type:sessions" || lower === "in:sessions") {
|
|
2040
|
+
effType = "sessions";
|
|
2041
|
+
} else if (lower === "type:core" || lower === "in:core") {
|
|
2042
|
+
effType = "core";
|
|
2043
|
+
effCoreOnly = true;
|
|
2044
|
+
} else if (lower === "type:all") {
|
|
2045
|
+
effType = "all";
|
|
2046
|
+
} else if (lower === "core:true" || lower === "is:core") {
|
|
2047
|
+
effCoreOnly = true;
|
|
2048
|
+
} else if (lower.startsWith("project:")) {
|
|
2049
|
+
const val = lower.slice(8).trim();
|
|
2050
|
+
if (val) effProject = val;
|
|
2051
|
+
} else if (lower.startsWith("topic:")) {
|
|
2052
|
+
const val = lower.slice(6).trim();
|
|
2053
|
+
if (val) effTopic = val;
|
|
2054
|
+
} else if (lower.startsWith("re:") && tok.length > 3) {
|
|
2055
|
+
effMode = "regex";
|
|
2056
|
+
cleanTokens.push(tok.slice(3));
|
|
2057
|
+
} else {
|
|
2058
|
+
cleanTokens.push(tok);
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2062
|
+
return {
|
|
2063
|
+
cleanQ: cleanTokens.join(" ").trim(),
|
|
2064
|
+
effType: effType,
|
|
2065
|
+
effTopic: effTopic,
|
|
2066
|
+
effMode: effMode,
|
|
2067
|
+
effProject: effProject,
|
|
2068
|
+
effCoreOnly: effCoreOnly,
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
function sanitizeRpcEntry(entry) {
|
|
2073
|
+
const out = {
|
|
2074
|
+
id: String(entry.id || ""),
|
|
2075
|
+
date: String(entry.date || ""),
|
|
2076
|
+
file: String(entry.file || ""),
|
|
2077
|
+
tags: String(entry.tags || ""),
|
|
2078
|
+
fact: String(entry.fact || ""),
|
|
2079
|
+
};
|
|
2080
|
+
if (entry.project) out.project = String(entry.project);
|
|
2081
|
+
if (entry.core) out.core = true;
|
|
2082
|
+
return out;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
async function executeMemoryQuery(rootDir, input) {
|
|
2086
|
+
const opts = input || {};
|
|
2087
|
+
const entries = loadCachedVectors(rootDir) || [];
|
|
2088
|
+
const limit = Math.max(1, Math.min(200, Number(opts.limit) || 100));
|
|
2089
|
+
const parsed = parseInlineMemoryFilters(
|
|
2090
|
+
opts.query || "",
|
|
2091
|
+
opts.typeFilter || "all",
|
|
2092
|
+
opts.topicFilter || "all",
|
|
2093
|
+
opts.mode || "hybrid",
|
|
2094
|
+
opts.projectFilter || "all",
|
|
2095
|
+
opts.coreOnly
|
|
2096
|
+
);
|
|
2097
|
+
const q = parsed.cleanQ;
|
|
2098
|
+
const effType = parsed.effType;
|
|
2099
|
+
const effTopic = parsed.effTopic;
|
|
2100
|
+
const effMode = parsed.effMode;
|
|
2101
|
+
const effProject = parsed.effProject;
|
|
2102
|
+
const effCoreOnly = parsed.effCoreOnly;
|
|
2103
|
+
|
|
2104
|
+
let coreCount = 0;
|
|
2105
|
+
let topicsCount = 0;
|
|
2106
|
+
let sessionsCount = 0;
|
|
2107
|
+
const projectSet = new Set(["global"]);
|
|
2108
|
+
|
|
2109
|
+
for (const e of entries) {
|
|
2110
|
+
if (e.core) coreCount++;
|
|
2111
|
+
if (String(e.file || "").startsWith("topics/")) topicsCount++;
|
|
2112
|
+
if (String(e.file || "").startsWith("sessions/")) sessionsCount++;
|
|
2113
|
+
if (e.project && e.project !== "global") projectSet.add(String(e.project));
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
const matchesSubset = function (e) {
|
|
2117
|
+
if (effType === "core" && !e.core) return false;
|
|
2118
|
+
if (effType === "topics" && !String(e.file || "").startsWith("topics/")) return false;
|
|
2119
|
+
if (effType === "sessions" && !String(e.file || "").startsWith("sessions/")) return false;
|
|
2120
|
+
if (effTopic !== "all" && e.file !== "topics/" + effTopic + ".md") return false;
|
|
2121
|
+
if (effCoreOnly && !e.core) return false;
|
|
2122
|
+
if (effProject !== "all" && !matchesProjectScope(e.project, effProject, false)) return false;
|
|
2123
|
+
return true;
|
|
2124
|
+
};
|
|
2125
|
+
|
|
2126
|
+
const subset = entries.filter(matchesSubset);
|
|
2127
|
+
let hits = [];
|
|
2128
|
+
|
|
2129
|
+
if (!q) {
|
|
2130
|
+
const topicPart = subset.filter(function (e) { return !String(e.file || "").startsWith("sessions/"); }).reverse();
|
|
2131
|
+
const sessionPart = subset.filter(function (e) { return String(e.file || "").startsWith("sessions/"); }).reverse();
|
|
2132
|
+
hits = topicPart
|
|
2133
|
+
.concat(sessionPart)
|
|
2134
|
+
.slice(0, limit)
|
|
2135
|
+
.map(function (e) {
|
|
2136
|
+
return { score: 1, semanticScore: 0, entry: sanitizeRpcEntry(e) };
|
|
2137
|
+
});
|
|
2138
|
+
} else if (effMode === "regex" || (q.startsWith("/") && q.lastIndexOf("/") > 0)) {
|
|
2139
|
+
try {
|
|
2140
|
+
const lastSlash = q.startsWith("/") ? q.lastIndexOf("/") : -1;
|
|
2141
|
+
const pattern = lastSlash > 0 ? q.slice(1, lastSlash) : q;
|
|
2142
|
+
if (isSafeRegexPattern(pattern)) {
|
|
2143
|
+
const flags = lastSlash > 0 ? q.slice(lastSlash + 1) || "i" : "i";
|
|
2144
|
+
const re = new RegExp(pattern, flags);
|
|
2145
|
+
hits = subset
|
|
2146
|
+
.filter(function (e) {
|
|
2147
|
+
re.lastIndex = 0;
|
|
2148
|
+
return re.test(e._haystack || (e.id + " " + e.tags + " " + e.fact + " " + e.file));
|
|
2149
|
+
})
|
|
2150
|
+
.slice(0, limit)
|
|
2151
|
+
.map(function (e) {
|
|
2152
|
+
return { score: 1, semanticScore: 0, entry: sanitizeRpcEntry(e) };
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
} catch {
|
|
2156
|
+
hits = [];
|
|
2157
|
+
}
|
|
2158
|
+
} else {
|
|
2159
|
+
const lowerQ = q.toLowerCase();
|
|
2160
|
+
const words = lowerQ.split(/\s+/).filter(function (w) { return w.length >= 2; });
|
|
2161
|
+
const lexicalHits = [];
|
|
2162
|
+
for (const e of subset) {
|
|
2163
|
+
const hay = e._haystack || (e.id + " " + e.tags + " " + e.fact + " " + e.file).toLowerCase();
|
|
2164
|
+
let lex = 0;
|
|
2165
|
+
if (hay.includes(lowerQ)) {
|
|
2166
|
+
lex = 0.9;
|
|
2167
|
+
} else if (words.length > 0) {
|
|
2168
|
+
let matched = 0;
|
|
2169
|
+
for (const w of words) {
|
|
2170
|
+
if (hay.includes(w)) matched++;
|
|
2171
|
+
}
|
|
2172
|
+
if (matched > 0) lex = (matched / words.length) * 0.75;
|
|
2173
|
+
}
|
|
2174
|
+
if (lex > 0) {
|
|
2175
|
+
lexicalHits.push({ score: lex, semanticScore: 0, entry: sanitizeRpcEntry(e) });
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
lexicalHits.sort(function (a, b) { return b.score - a.score; });
|
|
2179
|
+
|
|
2180
|
+
if (effMode === "hybrid" && q.length >= 2) {
|
|
2181
|
+
try {
|
|
2182
|
+
const semHits = await searchMemory(rootDir, q, "hybrid", limit, {
|
|
2183
|
+
project: effProject,
|
|
2184
|
+
includeGlobal: effProject === "all",
|
|
2185
|
+
coreOnly: effCoreOnly,
|
|
2186
|
+
});
|
|
2187
|
+
const filteredSem = semHits
|
|
2188
|
+
.filter(function (h) {
|
|
2189
|
+
return matchesSubset(h.entry) && h.score >= 0.22;
|
|
2190
|
+
})
|
|
2191
|
+
.slice(0, limit)
|
|
2192
|
+
.map(function (h) {
|
|
2193
|
+
return {
|
|
2194
|
+
score: Number(h.score || 0),
|
|
2195
|
+
semanticScore: Number(h.semanticScore || 0),
|
|
2196
|
+
entry: sanitizeRpcEntry(h.entry),
|
|
2197
|
+
};
|
|
2198
|
+
});
|
|
2199
|
+
hits = filteredSem.length > 0 ? filteredSem : lexicalHits.slice(0, limit);
|
|
2200
|
+
} catch {
|
|
2201
|
+
hits = lexicalHits.slice(0, limit);
|
|
2202
|
+
}
|
|
2203
|
+
} else {
|
|
2204
|
+
hits = lexicalHits.slice(0, limit);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
return JSON.parse(
|
|
2209
|
+
JSON.stringify({
|
|
2210
|
+
rootDir: rootDir,
|
|
2211
|
+
totalEntries: entries.length,
|
|
2212
|
+
coreCount: coreCount,
|
|
2213
|
+
topicsCount: topicsCount,
|
|
2214
|
+
sessionsCount: sessionsCount,
|
|
2215
|
+
topics: getTopicSlugs(rootDir) || [],
|
|
2216
|
+
projects: Array.from(projectSet),
|
|
2217
|
+
hits: hits,
|
|
2218
|
+
})
|
|
2219
|
+
);
|
|
2220
|
+
}
|
|
2221
|
+
|
|
1990
2222
|
function createPluginDefinition() {
|
|
1991
2223
|
return {
|
|
1992
2224
|
id: "opencode-local-memory",
|
|
@@ -2006,6 +2238,75 @@ function createPluginDefinition() {
|
|
|
2006
2238
|
|
|
2007
2239
|
const registrations = [];
|
|
2008
2240
|
|
|
2241
|
+
if (ctx && ctx.rpc && typeof ctx.rpc.register === "function") {
|
|
2242
|
+
const rpcReg = await ctx.rpc.register(MemoryRpc, {
|
|
2243
|
+
async query(input) {
|
|
2244
|
+
return executeMemoryQuery(rootDir, input);
|
|
2245
|
+
},
|
|
2246
|
+
async store(input) {
|
|
2247
|
+
const saved = await storeMemoryFact(rootDir, input);
|
|
2248
|
+
return JSON.parse(
|
|
2249
|
+
JSON.stringify({
|
|
2250
|
+
entry: {
|
|
2251
|
+
id: String(saved.id || ""),
|
|
2252
|
+
date: String(saved.date || ""),
|
|
2253
|
+
file: String(saved.file || ""),
|
|
2254
|
+
tags: String(saved.tags || ""),
|
|
2255
|
+
fact: String(saved.fact || ""),
|
|
2256
|
+
project: String(saved.project || "global"),
|
|
2257
|
+
core: Boolean(saved.core),
|
|
2258
|
+
updated: Boolean(saved.updated),
|
|
2259
|
+
superseded: Array.isArray(saved.superseded) ? saved.superseded : [],
|
|
2260
|
+
},
|
|
2261
|
+
})
|
|
2262
|
+
);
|
|
2263
|
+
},
|
|
2264
|
+
async remove(input) {
|
|
2265
|
+
const res = await deleteMemoryEntry(rootDir, input && input.id);
|
|
2266
|
+
return JSON.parse(
|
|
2267
|
+
JSON.stringify({
|
|
2268
|
+
deleted: Array.isArray(res.deleted) ? res.deleted : [],
|
|
2269
|
+
notFound: Array.isArray(res.notFound) ? res.notFound : [],
|
|
2270
|
+
total: Number(res.total || 0),
|
|
2271
|
+
})
|
|
2272
|
+
);
|
|
2273
|
+
},
|
|
2274
|
+
async sync() {
|
|
2275
|
+
const res = await syncVectors(rootDir);
|
|
2276
|
+
return JSON.parse(
|
|
2277
|
+
JSON.stringify({
|
|
2278
|
+
total: Number(res.total || 0),
|
|
2279
|
+
embedded: Number(res.embedded || 0),
|
|
2280
|
+
reused: Number(res.reused || 0),
|
|
2281
|
+
vecFile: String(res.vecFile || path.join(rootDir, "vectors.json")),
|
|
2282
|
+
})
|
|
2283
|
+
);
|
|
2284
|
+
},
|
|
2285
|
+
async importMemory(input) {
|
|
2286
|
+
const res = await importExistingMemory(rootDir, {
|
|
2287
|
+
limit: input && input.limit ? Number(input.limit) : undefined,
|
|
2288
|
+
});
|
|
2289
|
+
return JSON.parse(
|
|
2290
|
+
JSON.stringify({
|
|
2291
|
+
importedFactsCount: Array.isArray(res.importedFacts) ? res.importedFacts.length : 0,
|
|
2292
|
+
skippedFacts: Number(res.skippedFacts || 0),
|
|
2293
|
+
importedSessionsCount: Array.isArray(res.importedSessions) ? res.importedSessions.length : 0,
|
|
2294
|
+
skippedSessions: Number(res.skippedSessions || 0),
|
|
2295
|
+
total: Number(res.syncResult && res.syncResult.total ? res.syncResult.total : 0),
|
|
2296
|
+
})
|
|
2297
|
+
);
|
|
2298
|
+
},
|
|
2299
|
+
async getSessionMarkdown(input) {
|
|
2300
|
+
const relFile = String((input && input.file) || "");
|
|
2301
|
+
return {
|
|
2302
|
+
file: relFile,
|
|
2303
|
+
markdown: readSessionMarkdown(rootDir, relFile),
|
|
2304
|
+
};
|
|
2305
|
+
},
|
|
2306
|
+
});
|
|
2307
|
+
if (rpcReg) registrations.push(rpcReg);
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2009
2310
|
if (ctx && ctx.tool && typeof ctx.tool.transform === "function") {
|
|
2010
2311
|
const toolReg = await ctx.tool.transform(function (editor) {
|
|
2011
2312
|
editor.add({
|
|
@@ -2284,6 +2585,7 @@ const server = createPluginDefinition();
|
|
|
2284
2585
|
export default server;
|
|
2285
2586
|
export {
|
|
2286
2587
|
server,
|
|
2588
|
+
MemoryRpc,
|
|
2287
2589
|
resolveMemoryDir,
|
|
2288
2590
|
resolveConfigDir,
|
|
2289
2591
|
resolveDbPath,
|
|
@@ -2307,7 +2609,9 @@ export {
|
|
|
2307
2609
|
searchMemory,
|
|
2308
2610
|
storeMemoryFact,
|
|
2309
2611
|
deleteMemoryEntry,
|
|
2310
|
-
storeSessionCheckpoint
|
|
2612
|
+
storeSessionCheckpoint,
|
|
2613
|
+
readSessionMarkdown,
|
|
2614
|
+
executeMemoryQuery
|
|
2311
2615
|
};
|
|
2312
2616
|
|
|
2313
2617
|
const isDirectRun = process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
|
|
@@ -2399,6 +2703,29 @@ if (isDirectRun) {
|
|
|
2399
2703
|
console.error("Store failed:", err);
|
|
2400
2704
|
process.exit(1);
|
|
2401
2705
|
});
|
|
2706
|
+
} else if (cmd === "store-json") {
|
|
2707
|
+
const payloadIdx = process.argv.indexOf("--payload");
|
|
2708
|
+
const rawPayload = (payloadIdx !== -1 && process.argv[payloadIdx + 1]) ? process.argv[payloadIdx + 1] : "{}";
|
|
2709
|
+
const parsedPayload = JSON.parse(rawPayload);
|
|
2710
|
+
storeMemoryFact(rootDir, parsedPayload).then(function (entry) {
|
|
2711
|
+
const out = Object.assign({}, entry);
|
|
2712
|
+
delete out.vector;
|
|
2713
|
+
delete out._haystack;
|
|
2714
|
+
console.log(JSON.stringify(out));
|
|
2715
|
+
}).catch(function (err) {
|
|
2716
|
+
console.error("Store JSON failed:", err);
|
|
2717
|
+
process.exit(1);
|
|
2718
|
+
});
|
|
2719
|
+
} else if (cmd === "delete-json") {
|
|
2720
|
+
const payloadIdx = process.argv.indexOf("--payload");
|
|
2721
|
+
const rawPayload = (payloadIdx !== -1 && process.argv[payloadIdx + 1]) ? process.argv[payloadIdx + 1] : "{}";
|
|
2722
|
+
const parsedPayload = JSON.parse(rawPayload);
|
|
2723
|
+
deleteMemoryEntry(rootDir, parsedPayload.id).then(function (res) {
|
|
2724
|
+
console.log(JSON.stringify(res));
|
|
2725
|
+
}).catch(function (err) {
|
|
2726
|
+
console.error("Delete JSON failed:", err);
|
|
2727
|
+
process.exit(1);
|
|
2728
|
+
});
|
|
2402
2729
|
} else if (cmd === "delete" || cmd === "rm") {
|
|
2403
2730
|
const id = process.argv.slice(3).join(",");
|
|
2404
2731
|
deleteMemoryEntry(rootDir, id).then(function (res) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nandoblanco/opencode-local-memory",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -10,19 +10,27 @@
|
|
|
10
10
|
"exports": {
|
|
11
11
|
".": "./index.js",
|
|
12
12
|
"./server": "./index.js",
|
|
13
|
-
"./tui": "./tui.ts"
|
|
13
|
+
"./tui": "./tui.ts",
|
|
14
|
+
"./rpc": "./rpc.js",
|
|
15
|
+
"./gui-experimental": "./dist/gui-experimental.cjs"
|
|
14
16
|
},
|
|
15
17
|
"bin": {
|
|
16
18
|
"opencode-local-memory": "index.js"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|
|
19
21
|
"index.js",
|
|
22
|
+
"rpc.js",
|
|
23
|
+
"rpc.d.ts",
|
|
20
24
|
"tui.ts",
|
|
25
|
+
"gui.tsx",
|
|
26
|
+
"gui.css",
|
|
27
|
+
"dist/gui-experimental.cjs",
|
|
21
28
|
"assets/screenshot.png",
|
|
22
29
|
"README.md",
|
|
23
30
|
"LICENSE"
|
|
24
31
|
],
|
|
25
32
|
"scripts": {
|
|
33
|
+
"build:gui": "vite build",
|
|
26
34
|
"test": "node --no-warnings --test test/memory.test.js"
|
|
27
35
|
},
|
|
28
36
|
"sideEffects": false,
|
|
@@ -41,7 +49,8 @@
|
|
|
41
49
|
"transformers"
|
|
42
50
|
],
|
|
43
51
|
"dependencies": {
|
|
44
|
-
"@
|
|
52
|
+
"@huggingface/transformers": "^4.3.2",
|
|
53
|
+
"onnxruntime-common": "1.30.0"
|
|
45
54
|
},
|
|
46
55
|
"peerDependencies": {
|
|
47
56
|
"@opencode-ai/plugin": ">=2.0.0",
|
|
@@ -63,10 +72,21 @@
|
|
|
63
72
|
"optional": true
|
|
64
73
|
}
|
|
65
74
|
},
|
|
75
|
+
"overrides": {
|
|
76
|
+
"glob": "14.0.5",
|
|
77
|
+
"minimatch": "11.0.8"
|
|
78
|
+
},
|
|
66
79
|
"author": "nandoblanco",
|
|
67
80
|
"license": "MIT",
|
|
68
81
|
"repository": {
|
|
69
82
|
"type": "git",
|
|
70
83
|
"url": "git+https://github.com/nandoblanco/opencode-local-memory.git"
|
|
84
|
+
},
|
|
85
|
+
"devDependencies": {
|
|
86
|
+
"@opencode/plugin": "^2.2.5",
|
|
87
|
+
"@opencode/theme": "^2.2.5",
|
|
88
|
+
"solid-js": "^1.9.18",
|
|
89
|
+
"vite": "^8.3.5",
|
|
90
|
+
"vite-plugin-solid": "^2.11.15"
|
|
71
91
|
}
|
|
72
92
|
}
|
package/rpc.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { JsonSchema, Rpc } from "@opencode/plugin/rpc";
|
|
2
|
+
|
|
3
|
+
export type MemoryTypeFilter = "all" | "core" | "topics" | "sessions";
|
|
4
|
+
export type MemoryModeFilter = "hybrid" | "keyword" | "regex";
|
|
5
|
+
|
|
6
|
+
export interface MemoryRpcEntry {
|
|
7
|
+
id: string;
|
|
8
|
+
date: string;
|
|
9
|
+
file: string;
|
|
10
|
+
tags: string;
|
|
11
|
+
fact: string;
|
|
12
|
+
project?: string;
|
|
13
|
+
core?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MemoryRpcHit {
|
|
17
|
+
score: number;
|
|
18
|
+
semanticScore: number;
|
|
19
|
+
entry: MemoryRpcEntry;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface MemoryRpcQueryInput {
|
|
23
|
+
query?: string;
|
|
24
|
+
typeFilter?: MemoryTypeFilter;
|
|
25
|
+
topicFilter?: string;
|
|
26
|
+
mode?: MemoryModeFilter;
|
|
27
|
+
projectFilter?: string;
|
|
28
|
+
coreOnly?: boolean;
|
|
29
|
+
limit?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface MemoryRpcQueryOutput {
|
|
33
|
+
rootDir: string;
|
|
34
|
+
totalEntries: number;
|
|
35
|
+
coreCount: number;
|
|
36
|
+
topicsCount: number;
|
|
37
|
+
sessionsCount: number;
|
|
38
|
+
topics: string[];
|
|
39
|
+
projects: string[];
|
|
40
|
+
hits: MemoryRpcHit[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface MemoryRpcStoreInput {
|
|
44
|
+
id?: string;
|
|
45
|
+
topic: string;
|
|
46
|
+
tags: string;
|
|
47
|
+
fact: string;
|
|
48
|
+
project?: string;
|
|
49
|
+
core?: boolean;
|
|
50
|
+
supersedes?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface MemoryRpcStoreOutput {
|
|
54
|
+
entry: {
|
|
55
|
+
id: string;
|
|
56
|
+
date: string;
|
|
57
|
+
file: string;
|
|
58
|
+
tags: string;
|
|
59
|
+
fact: string;
|
|
60
|
+
project: string;
|
|
61
|
+
core: boolean;
|
|
62
|
+
updated: boolean;
|
|
63
|
+
superseded: string[];
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface MemoryRpcRemoveInput {
|
|
68
|
+
id: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface MemoryRpcRemoveOutput {
|
|
72
|
+
deleted: Array<{ id: string; file: string }>;
|
|
73
|
+
notFound: string[];
|
|
74
|
+
total: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface MemoryRpcSyncInput {}
|
|
78
|
+
|
|
79
|
+
export interface MemoryRpcSyncOutput {
|
|
80
|
+
total: number;
|
|
81
|
+
embedded: number;
|
|
82
|
+
reused: number;
|
|
83
|
+
vecFile: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface MemoryRpcImportInput {
|
|
87
|
+
limit?: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface MemoryRpcImportOutput {
|
|
91
|
+
importedFactsCount: number;
|
|
92
|
+
skippedFacts: number;
|
|
93
|
+
importedSessionsCount: number;
|
|
94
|
+
skippedSessions: number;
|
|
95
|
+
total: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface MemoryRpcSessionMarkdownInput {
|
|
99
|
+
file: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface MemoryRpcSessionMarkdownOutput {
|
|
103
|
+
file: string;
|
|
104
|
+
markdown: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type SchemaFor<T> = JsonSchema.JsonSchema & { readonly __type?: T };
|
|
108
|
+
|
|
109
|
+
export declare const MemoryRpc: Rpc.Definition<
|
|
110
|
+
"opencode-local-memory",
|
|
111
|
+
{
|
|
112
|
+
query: {
|
|
113
|
+
input: SchemaFor<MemoryRpcQueryInput>;
|
|
114
|
+
output: SchemaFor<MemoryRpcQueryOutput>;
|
|
115
|
+
};
|
|
116
|
+
store: {
|
|
117
|
+
input: SchemaFor<MemoryRpcStoreInput>;
|
|
118
|
+
output: SchemaFor<MemoryRpcStoreOutput>;
|
|
119
|
+
};
|
|
120
|
+
remove: {
|
|
121
|
+
input: SchemaFor<MemoryRpcRemoveInput>;
|
|
122
|
+
output: SchemaFor<MemoryRpcRemoveOutput>;
|
|
123
|
+
};
|
|
124
|
+
sync: {
|
|
125
|
+
input: SchemaFor<MemoryRpcSyncInput>;
|
|
126
|
+
output: SchemaFor<MemoryRpcSyncOutput>;
|
|
127
|
+
};
|
|
128
|
+
importMemory: {
|
|
129
|
+
input: SchemaFor<MemoryRpcImportInput>;
|
|
130
|
+
output: SchemaFor<MemoryRpcImportOutput>;
|
|
131
|
+
};
|
|
132
|
+
getSessionMarkdown: {
|
|
133
|
+
input: SchemaFor<MemoryRpcSessionMarkdownInput>;
|
|
134
|
+
output: SchemaFor<MemoryRpcSessionMarkdownOutput>;
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
Record<never, never>
|
|
138
|
+
>;
|
|
139
|
+
|
|
140
|
+
export default MemoryRpc;
|