dsh-snail-memory 0.1.5 → 0.1.6
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/dist/store/json.js +10 -1
- package/dist/store/store.js +33 -9
- package/dsh.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin.json +1 -1
package/dist/store/json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
1
|
+
import { mkdir, open, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { dirname } from 'node:path';
|
|
4
4
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
@@ -128,6 +128,15 @@ export async function writeTextAtomic(path, text) {
|
|
|
128
128
|
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
129
129
|
await writeFile(temporary, text, 'utf8');
|
|
130
130
|
try {
|
|
131
|
+
// Flush the temporary file before publishing it by rename, so a crash can
|
|
132
|
+
// never leave a zero-byte or partially written destination behind.
|
|
133
|
+
const handle = await open(temporary, 'r+');
|
|
134
|
+
try {
|
|
135
|
+
await handle.sync();
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
await handle.close();
|
|
139
|
+
}
|
|
131
140
|
for (let attempt = 0;; attempt += 1) {
|
|
132
141
|
try {
|
|
133
142
|
await rename(temporary, path);
|
package/dist/store/store.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { appendFile, readFile, rm } from 'node:fs/promises';
|
|
1
|
+
import { appendFile, readFile, rename, rm } from 'node:fs/promises';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import { entriesForScope, revisionForScope, workspaceIndexRefs } from './aggregate.js';
|
|
4
4
|
import { WriterLock, WriterLockOwnershipError } from './lock.js';
|
|
@@ -459,22 +459,46 @@ export class MemoryStore {
|
|
|
459
459
|
return null;
|
|
460
460
|
throw error;
|
|
461
461
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
462
|
+
try {
|
|
463
|
+
const value = JSON.parse(text);
|
|
464
|
+
const candidate = value;
|
|
465
|
+
if (!value || typeof value !== 'object' || candidate.formatVersion !== 1
|
|
466
|
+
|| !Array.isArray(candidate.ids)
|
|
467
|
+
|| candidate.ids.some(id => typeof id !== 'string')) {
|
|
468
|
+
throw new Error('Cannot read projection recovery intent');
|
|
469
|
+
}
|
|
470
|
+
return candidate;
|
|
471
|
+
}
|
|
472
|
+
catch {
|
|
473
|
+
// The intent file is only a rebuild hint. A damaged hint must never
|
|
474
|
+
// block startup or writes: quarantine it and rebuild every projection
|
|
475
|
+
// from the authoritative state instead.
|
|
476
|
+
await rename(this.paths.projectionPending, `${this.paths.projectionPending}.corrupt`)
|
|
477
|
+
.catch(() => rm(this.paths.projectionPending, { force: true }).catch(() => { }));
|
|
478
|
+
return 'all';
|
|
466
479
|
}
|
|
467
|
-
return value;
|
|
468
480
|
}
|
|
469
481
|
async recoverPendingProjections() {
|
|
470
482
|
const pending = await this.readPendingProjections();
|
|
471
483
|
if (!pending)
|
|
472
484
|
return;
|
|
473
|
-
|
|
485
|
+
const ids = pending === 'all'
|
|
486
|
+
? this.state.entries.map(entry => entry.id)
|
|
487
|
+
: pending.ids;
|
|
488
|
+
for (const id of ids) {
|
|
474
489
|
await this.lock.heartbeat();
|
|
475
490
|
const index = this.state.entries.find(entry => entry.id === id);
|
|
476
|
-
if (index)
|
|
477
|
-
|
|
491
|
+
if (index) {
|
|
492
|
+
try {
|
|
493
|
+
await writeDetailProjection(this.paths, await readDetailRecord(this.paths, index));
|
|
494
|
+
}
|
|
495
|
+
catch (error) {
|
|
496
|
+
// A full rebuild skips records that cannot be read; an explicit
|
|
497
|
+
// intent still surfaces damaged authoritative data.
|
|
498
|
+
if (pending !== 'all')
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
478
502
|
else
|
|
479
503
|
await removeDetailProjection(this.paths, id);
|
|
480
504
|
}
|
package/dsh.plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-snail-memory",
|
|
3
3
|
"name": "Snail Memory",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"description": {
|
|
6
6
|
"en": "Layered single-user global and workspace memory with a web panel, an in-context index, on-demand records and per-session opt-in.",
|
|
7
7
|
"zh": "单用户、分层的全局与 workspace 记忆:Web 面板管理条目与整理、整合设置;索引常驻上下文、详情按需加载,按对话手动开启。"
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "dsh-snail-memory",
|
|
3
3
|
"name": "Snail Memory",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"description": {
|
|
6
6
|
"en": "Layered single-user global and workspace memory with a web panel, an in-context index, on-demand records and per-session opt-in.",
|
|
7
7
|
"zh": "单用户、分层的全局与 workspace 记忆:Web 面板管理条目与整理、整合设置;索引常驻上下文、详情按需加载,按对话手动开启。"
|