xiaozuoassistant 0.1.72 → 0.1.74

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.
@@ -62,7 +62,13 @@ export class ShortTermMemory {
62
62
  }
63
63
  async loadSessionsFromDisk() {
64
64
  try {
65
- const data = await fs.readJson(INDEX_FILE);
65
+ // Invalidate cache by reading file directly
66
+ // Use fs.readFile to bypass any potential fs-extra internal caching (though unlikely)
67
+ // and ensure we get fresh data
68
+ const content = await fs.readFile(INDEX_FILE, 'utf-8');
69
+ const data = JSON.parse(content);
70
+ // Log loaded data count for debugging
71
+ console.log(`[ShortTermMemory:${this.instanceId}] Loaded ${Array.isArray(data) ? data.length : 0} sessions from disk.`);
66
72
  this.sessions.clear();
67
73
  if (Array.isArray(data)) {
68
74
  for (const meta of data) {
@@ -73,7 +79,7 @@ export class ShortTermMemory {
73
79
  }
74
80
  }
75
81
  catch (e) {
76
- console.error('[ShortTermMemory] Failed to load index.json:', e);
82
+ console.error(`[ShortTermMemory:${this.instanceId}] Failed to load index.json:`, e);
77
83
  // 此时保持 sessions 为空或之前的状态
78
84
  }
79
85
  }
@@ -166,11 +172,13 @@ export class ShortTermMemory {
166
172
  const sessionDir = this.getSessionDir(id);
167
173
  await fs.ensureDir(sessionDir);
168
174
  await fs.writeJson(this.getMessagesFile(id), [], { spaces: 2 });
175
+ // IMPORTANT: Reload from disk BEFORE adding new session to avoid overwriting other processes' changes
176
+ await this.loadSessionsFromDisk();
169
177
  // 更新内存
170
178
  this.sessions.set(id, meta);
171
179
  // 异步持久化
172
180
  await this.persistIndex();
173
- console.log(`[ShortTermMemory] Session created: ${id}`);
181
+ console.log(`[ShortTermMemory:${this.instanceId}] Session created and persisted: ${id}`);
174
182
  return { meta, messages: [] };
175
183
  }
176
184
  async listSessions() {
@@ -367,8 +375,24 @@ export class ShortTermMemory {
367
375
  await this.loadSessionsFromDisk();
368
376
  sessionMeta = this.sessions.get(sessionId);
369
377
  }
378
+ // 如果仍然没有,尝试直接从 index.json 读取一次,绕过缓存逻辑
370
379
  if (!sessionMeta) {
371
- console.error(`[ShortTermMemory:${this.instanceId}] Session ${sessionId} not found even after reload.`);
380
+ try {
381
+ const content = await fs.readFile(INDEX_FILE, 'utf-8');
382
+ const data = JSON.parse(content);
383
+ const found = Array.isArray(data) ? data.find((m) => m.id === sessionId) : null;
384
+ if (found) {
385
+ console.log(`[ShortTermMemory:${this.instanceId}] Session ${sessionId} found in fresh disk read, recovering...`);
386
+ this.sessions.set(found.id, found);
387
+ sessionMeta = found;
388
+ }
389
+ }
390
+ catch (e) {
391
+ console.error(`[ShortTermMemory:${this.instanceId}] Emergency disk read failed:`, e);
392
+ }
393
+ }
394
+ if (!sessionMeta) {
395
+ console.error(`[ShortTermMemory:${this.instanceId}] Session ${sessionId} not found even after emergency reload.`);
372
396
  throw new Error(`Session ${sessionId} not found`);
373
397
  }
374
398
  const msg = { ...message };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "xiaozuoassistant",
3
3
  "private": false,
4
4
  "description": "Your personal, locally-hosted AI assistant for office productivity.",
5
- "version": "0.1.72",
5
+ "version": "0.1.74",
6
6
  "author": "mantle.lau",
7
7
  "license": "MIT",
8
8
  "repository": {