whale-memory-core 0.5.0 → 0.5.1

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.
@@ -15,15 +15,19 @@ function ensureDir(memDir) {
15
15
  }
16
16
 
17
17
  // 单写者锁:多进程追加时排队;超时报错,不静默丢事件
18
+ // Windows 上并发 mkdir/rm 同一路径会短暂返回 EPERM/ENOENT,当成“忙”重试
19
+ const BUSY = new Set(['EEXIST', 'EPERM', 'ENOENT', 'EBUSY', 'EACCES'])
20
+
18
21
  function withLock(memDir, fn, { timeoutMs = 3000 } = {}) {
19
22
  const lock = eventsFile(memDir) + '.lock'
20
23
  const start = Date.now()
21
24
  for (;;) {
22
25
  try {
26
+ fs.mkdirSync(memDir, { recursive: true })
23
27
  fs.mkdirSync(lock)
24
28
  break
25
29
  } catch (e) {
26
- if (e.code !== 'EEXIST') throw e
30
+ if (!BUSY.has(e.code)) throw e
27
31
  try {
28
32
  const st = fs.statSync(lock)
29
33
  if (Date.now() - st.mtimeMs > 10000) { fs.rmSync(lock, { recursive: true, force: true }); continue }
@@ -33,15 +33,19 @@ function atomicWrite(file, body) {
33
33
  }
34
34
 
35
35
  // 单写者锁:另一个进程正在写时等一会儿;超过 timeout 报错,不静默覆盖
36
+ // Windows 上并发 mkdir/rm 同一路径会短暂返回 EPERM/ENOENT,当成“忙”重试
37
+ const BUSY = new Set(['EEXIST', 'EPERM', 'ENOENT', 'EBUSY', 'EACCES'])
38
+
36
39
  function withLock(dir, fn, { timeoutMs = 2000 } = {}) {
37
40
  const lock = path.join(dir, '.lock')
38
41
  const start = Date.now()
39
42
  for (;;) {
40
43
  try {
44
+ fs.mkdirSync(dir, { recursive: true })
41
45
  fs.mkdirSync(lock)
42
46
  break
43
47
  } catch (e) {
44
- if (e.code !== 'EEXIST') throw e
48
+ if (!BUSY.has(e.code)) throw e
45
49
  try {
46
50
  const st = fs.statSync(lock)
47
51
  if (Date.now() - st.mtimeMs > 10000) { fs.rmSync(lock, { recursive: true, force: true }); continue }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whale-memory-core",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Self-layer autobiographical memory core: then / later, append-only. Vault, evidence and consolidation live in the QQ Agent plugin.",
5
5
  "type": "module",
6
6
  "main": "./index.js",