toon-memory 1.6.8 → 1.7.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/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 readEnvKey() {
27669
- try {
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 });
@@ -27709,15 +27696,12 @@ function decrypt(encryptedData, key) {
27709
27696
  decrypted += decipher.final("utf8");
27710
27697
  return decrypted;
27711
27698
  }
27712
- function generateKey() {
27713
- return randomBytes(32).toString("hex");
27714
- }
27715
27699
  function readMemory() {
27716
27700
  ensureMemoryFile();
27717
27701
  const config2 = loadConfig();
27718
27702
  const data = readFileSync(MEMORY_FILE, "utf-8");
27719
27703
  if (config2.encrypted) {
27720
- const key = readEnvKey();
27704
+ const key = getKey();
27721
27705
  if (!key) return "";
27722
27706
  try {
27723
27707
  return decrypt(data, key);
@@ -27731,7 +27715,7 @@ function writeMemory(content) {
27731
27715
  ensureMemoryFile();
27732
27716
  const config2 = loadConfig();
27733
27717
  if (config2.encrypted) {
27734
- const key = readEnvKey();
27718
+ const key = getKey();
27735
27719
  if (!key) return;
27736
27720
  const encrypted = encrypt(content, key);
27737
27721
  writeFileSync(MEMORY_FILE, encrypted);
@@ -28038,12 +28022,14 @@ server.registerTool(
28038
28022
  if (config2.encrypted) {
28039
28023
  return { content: [{ type: "text", text: "La encriptaci\xF3n ya est\xE1 habilitada" }] };
28040
28024
  }
28041
- const key = generateKey();
28025
+ const key = getKey();
28026
+ if (!key) {
28027
+ return { content: [{ type: "text", text: "\u274C Define TOON_MEMORY_KEY en el entorno antes de encriptar" }] };
28028
+ }
28042
28029
  const data = readFileSync(MEMORY_FILE, "utf-8");
28043
28030
  const encrypted = encrypt(data, key);
28044
28031
  writeFileSync(MEMORY_FILE, encrypted);
28045
28032
  saveConfig({ encrypted: true });
28046
- writeEnvKey(key);
28047
28033
  return {
28048
28034
  content: [{ type: "text", text: "\u{1F510} Encriptaci\xF3n habilitada" }]
28049
28035
  };
@@ -28063,7 +28049,7 @@ server.registerTool(
28063
28049
  if (!config2.encrypted) {
28064
28050
  return { content: [{ type: "text", text: "La encriptaci\xF3n no est\xE1 habilitada" }] };
28065
28051
  }
28066
- const resolvedKey = key || readEnvKey() || "";
28052
+ const resolvedKey = key || getKey() || "";
28067
28053
  if (!resolvedKey) {
28068
28054
  return { content: [{ type: "text", text: "\u274C No hay clave. P\xE1sala como argumento o la del archivo .env" }] };
28069
28055
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toon-memory",
3
- "version": "1.6.8",
3
+ "version": "1.7.0",
4
4
  "description": "Persistent memory system for AI coding agents using TOON format (40% fewer tokens than JSON)",
5
5
  "type": "module",
6
6
  "bin": {
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
- * Read the encryption key from .env file.
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 readEnvKey(): string | undefined {
81
- try {
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,7 +165,7 @@ function readMemory(): string {
185
165
  const data = readFileSync(MEMORY_FILE, "utf-8")
186
166
 
187
167
  if (config.encrypted) {
188
- const key = readEnvKey()
168
+ const key = getKey()
189
169
  if (!key) return ""
190
170
  try {
191
171
  return decrypt(data, key)
@@ -208,7 +188,7 @@ function writeMemory(content: string): void {
208
188
  const config = loadConfig()
209
189
 
210
190
  if (config.encrypted) {
211
- const key = readEnvKey()
191
+ const key = getKey()
212
192
  if (!key) return
213
193
  const encrypted = encrypt(content, key)
214
194
  writeFileSync(MEMORY_FILE, encrypted)
@@ -676,14 +656,16 @@ server.registerTool(
676
656
  return { content: [{ type: "text" as const, text: "La encriptación ya está habilitada" }] }
677
657
  }
678
658
 
679
- const key = generateKey()
680
- const data = readFileSync(MEMORY_FILE, "utf-8")
659
+ const key = getKey()
660
+ if (!key) {
661
+ return { content: [{ type: "text" as const, text: "❌ Define TOON_MEMORY_KEY en el entorno antes de encriptar" }] }
662
+ }
681
663
 
664
+ const data = readFileSync(MEMORY_FILE, "utf-8")
682
665
  const encrypted = encrypt(data, key)
683
666
  writeFileSync(MEMORY_FILE, encrypted)
684
667
 
685
668
  saveConfig({ encrypted: true })
686
- writeEnvKey(key)
687
669
 
688
670
  return {
689
671
  content: [{ type: "text" as const, text: "🔐 Encriptación habilitada" }],
@@ -717,7 +699,7 @@ server.registerTool(
717
699
  return { content: [{ type: "text" as const, text: "La encriptación no está habilitada" }] }
718
700
  }
719
701
 
720
- const resolvedKey = key || readEnvKey() || ""
702
+ const resolvedKey = key || getKey() || ""
721
703
  if (!resolvedKey) {
722
704
  return { content: [{ type: "text" as const, text: "❌ No hay clave. Pásala como argumento o la del archivo .env" }] }
723
705
  }