toon-memory 1.6.7 → 1.6.9
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/mcp/server.js +12 -27
- package/package.json +1 -1
- package/src/mcp/server.ts +13 -35
package/mcp/server.js
CHANGED
|
@@ -27648,7 +27648,6 @@ var MEMORY_DIR = join(process.cwd(), ".opencode", "memory");
|
|
|
27648
27648
|
var MEMORY_FILE = join(MEMORY_DIR, "data.toon");
|
|
27649
27649
|
var ARCHIVE_FILE = join(MEMORY_DIR, "archive.toon");
|
|
27650
27650
|
var CONFIG_FILE = join(MEMORY_DIR, "config.json");
|
|
27651
|
-
var ENV_FILE = join(MEMORY_DIR, ".env");
|
|
27652
27651
|
var ARCHIVE_DAYS = 30;
|
|
27653
27652
|
var ALGORITHM = "aes-256-gcm";
|
|
27654
27653
|
function loadConfig() {
|
|
@@ -27665,20 +27664,8 @@ function saveConfig(config2) {
|
|
|
27665
27664
|
ensureMemoryDir();
|
|
27666
27665
|
writeFileSync(CONFIG_FILE, JSON.stringify(config2, null, 2));
|
|
27667
27666
|
}
|
|
27668
|
-
function
|
|
27669
|
-
|
|
27670
|
-
if (!existsSync(ENV_FILE)) return void 0;
|
|
27671
|
-
const content = readFileSync(ENV_FILE, "utf-8").trim();
|
|
27672
|
-
const match = content.match(/^TOON_MEMORY_KEY=(.+)$/m);
|
|
27673
|
-
return match ? match[1] : void 0;
|
|
27674
|
-
} catch {
|
|
27675
|
-
return void 0;
|
|
27676
|
-
}
|
|
27677
|
-
}
|
|
27678
|
-
function writeEnvKey(key) {
|
|
27679
|
-
ensureMemoryDir();
|
|
27680
|
-
writeFileSync(ENV_FILE, `TOON_MEMORY_KEY=${key}
|
|
27681
|
-
`);
|
|
27667
|
+
function getKey() {
|
|
27668
|
+
return process.env.TOON_MEMORY_KEY;
|
|
27682
27669
|
}
|
|
27683
27670
|
function ensureMemoryDir() {
|
|
27684
27671
|
if (!existsSync(MEMORY_DIR)) mkdirSync(MEMORY_DIR, { recursive: true });
|
|
@@ -27717,12 +27704,12 @@ function readMemory() {
|
|
|
27717
27704
|
const config2 = loadConfig();
|
|
27718
27705
|
const data = readFileSync(MEMORY_FILE, "utf-8");
|
|
27719
27706
|
if (config2.encrypted) {
|
|
27720
|
-
const key =
|
|
27721
|
-
if (!key) return
|
|
27707
|
+
const key = getKey();
|
|
27708
|
+
if (!key) return "";
|
|
27722
27709
|
try {
|
|
27723
27710
|
return decrypt(data, key);
|
|
27724
27711
|
} catch {
|
|
27725
|
-
return
|
|
27712
|
+
return "";
|
|
27726
27713
|
}
|
|
27727
27714
|
}
|
|
27728
27715
|
return data;
|
|
@@ -27731,12 +27718,11 @@ function writeMemory(content) {
|
|
|
27731
27718
|
ensureMemoryFile();
|
|
27732
27719
|
const config2 = loadConfig();
|
|
27733
27720
|
if (config2.encrypted) {
|
|
27734
|
-
const key =
|
|
27735
|
-
if (key)
|
|
27736
|
-
|
|
27737
|
-
|
|
27738
|
-
|
|
27739
|
-
}
|
|
27721
|
+
const key = getKey();
|
|
27722
|
+
if (!key) return;
|
|
27723
|
+
const encrypted = encrypt(content, key);
|
|
27724
|
+
writeFileSync(MEMORY_FILE, encrypted);
|
|
27725
|
+
return;
|
|
27740
27726
|
}
|
|
27741
27727
|
writeFileSync(MEMORY_FILE, content);
|
|
27742
27728
|
}
|
|
@@ -28044,12 +28030,11 @@ server.registerTool(
|
|
|
28044
28030
|
const encrypted = encrypt(data, key);
|
|
28045
28031
|
writeFileSync(MEMORY_FILE, encrypted);
|
|
28046
28032
|
saveConfig({ encrypted: true });
|
|
28047
|
-
writeEnvKey(key);
|
|
28048
28033
|
return {
|
|
28049
28034
|
content: [{
|
|
28050
28035
|
type: "text",
|
|
28051
28036
|
text: `\u{1F510} Encriptaci\xF3n habilitada
|
|
28052
|
-
\u26A0\uFE0F Guarda esta clave (no se puede recuperar):
|
|
28037
|
+
\u26A0\uFE0F Guarda esta clave en TOON_MEMORY_KEY (no se puede recuperar):
|
|
28053
28038
|
${key}`
|
|
28054
28039
|
}]
|
|
28055
28040
|
};
|
|
@@ -28069,7 +28054,7 @@ server.registerTool(
|
|
|
28069
28054
|
if (!config2.encrypted) {
|
|
28070
28055
|
return { content: [{ type: "text", text: "La encriptaci\xF3n no est\xE1 habilitada" }] };
|
|
28071
28056
|
}
|
|
28072
|
-
const resolvedKey = key ||
|
|
28057
|
+
const resolvedKey = key || getKey() || "";
|
|
28073
28058
|
if (!resolvedKey) {
|
|
28074
28059
|
return { content: [{ type: "text", text: "\u274C No hay clave. P\xE1sala como argumento o la del archivo .env" }] };
|
|
28075
28060
|
}
|
package/package.json
CHANGED
package/src/mcp/server.ts
CHANGED
|
@@ -20,9 +20,6 @@ const ARCHIVE_FILE = join(MEMORY_DIR, "archive.toon")
|
|
|
20
20
|
/** Configuration file for encryption settings */
|
|
21
21
|
const CONFIG_FILE = join(MEMORY_DIR, "config.json")
|
|
22
22
|
|
|
23
|
-
/** Env file storing the encryption key (gitignored via .opencode/) */
|
|
24
|
-
const ENV_FILE = join(MEMORY_DIR, ".env")
|
|
25
|
-
|
|
26
23
|
/** Maximum active entries before auto-archive */
|
|
27
24
|
const MAX_ENTRIES = 100
|
|
28
25
|
|
|
@@ -73,29 +70,12 @@ function saveConfig(config: MemoryConfig): void {
|
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
/**
|
|
76
|
-
*
|
|
73
|
+
* Get the encryption key from environment variable.
|
|
77
74
|
*
|
|
78
75
|
* @returns The key string, or undefined if not set
|
|
79
76
|
*/
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
if (!existsSync(ENV_FILE)) return undefined
|
|
83
|
-
const content = readFileSync(ENV_FILE, "utf-8").trim()
|
|
84
|
-
const match = content.match(/^TOON_MEMORY_KEY=(.+)$/m)
|
|
85
|
-
return match ? match[1] : undefined
|
|
86
|
-
} catch {
|
|
87
|
-
return undefined
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Write the encryption key to .env file.
|
|
93
|
-
*
|
|
94
|
-
* @param key - Hex-encoded encryption key
|
|
95
|
-
*/
|
|
96
|
-
function writeEnvKey(key: string): void {
|
|
97
|
-
ensureMemoryDir()
|
|
98
|
-
writeFileSync(ENV_FILE, `TOON_MEMORY_KEY=${key}\n`)
|
|
77
|
+
function getKey(): string | undefined {
|
|
78
|
+
return process.env.TOON_MEMORY_KEY
|
|
99
79
|
}
|
|
100
80
|
|
|
101
81
|
/**
|
|
@@ -185,12 +165,12 @@ function readMemory(): string {
|
|
|
185
165
|
const data = readFileSync(MEMORY_FILE, "utf-8")
|
|
186
166
|
|
|
187
167
|
if (config.encrypted) {
|
|
188
|
-
const key =
|
|
189
|
-
if (!key) return
|
|
168
|
+
const key = getKey()
|
|
169
|
+
if (!key) return ""
|
|
190
170
|
try {
|
|
191
171
|
return decrypt(data, key)
|
|
192
172
|
} catch {
|
|
193
|
-
return
|
|
173
|
+
return ""
|
|
194
174
|
}
|
|
195
175
|
}
|
|
196
176
|
|
|
@@ -208,12 +188,11 @@ function writeMemory(content: string): void {
|
|
|
208
188
|
const config = loadConfig()
|
|
209
189
|
|
|
210
190
|
if (config.encrypted) {
|
|
211
|
-
const key =
|
|
212
|
-
if (key)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
191
|
+
const key = getKey()
|
|
192
|
+
if (!key) return
|
|
193
|
+
const encrypted = encrypt(content, key)
|
|
194
|
+
writeFileSync(MEMORY_FILE, encrypted)
|
|
195
|
+
return
|
|
217
196
|
}
|
|
218
197
|
|
|
219
198
|
writeFileSync(MEMORY_FILE, content)
|
|
@@ -684,12 +663,11 @@ server.registerTool(
|
|
|
684
663
|
writeFileSync(MEMORY_FILE, encrypted)
|
|
685
664
|
|
|
686
665
|
saveConfig({ encrypted: true })
|
|
687
|
-
writeEnvKey(key)
|
|
688
666
|
|
|
689
667
|
return {
|
|
690
668
|
content: [{
|
|
691
669
|
type: "text" as const,
|
|
692
|
-
text: `🔐 Encriptación habilitada\n⚠️ Guarda esta clave (no se puede recuperar):\n${key}`
|
|
670
|
+
text: `🔐 Encriptación habilitada\n⚠️ Guarda esta clave en TOON_MEMORY_KEY (no se puede recuperar):\n${key}`
|
|
693
671
|
}],
|
|
694
672
|
}
|
|
695
673
|
}
|
|
@@ -721,7 +699,7 @@ server.registerTool(
|
|
|
721
699
|
return { content: [{ type: "text" as const, text: "La encriptación no está habilitada" }] }
|
|
722
700
|
}
|
|
723
701
|
|
|
724
|
-
const resolvedKey = key ||
|
|
702
|
+
const resolvedKey = key || getKey() || ""
|
|
725
703
|
if (!resolvedKey) {
|
|
726
704
|
return { content: [{ type: "text" as const, text: "❌ No hay clave. Pásala como argumento o la del archivo .env" }] }
|
|
727
705
|
}
|