zen-fs-config 0.7.6 → 0.7.8

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/index.d.mts CHANGED
@@ -631,6 +631,15 @@ interface IConfigRepo {
631
631
  * instead of being treated as a "missing file" that gets re-created.
632
632
  */
633
633
  deleteFile(path: string): Promise<void>;
634
+ /**
635
+ * Write a repo-root file (`/.config/...`, `/.meta/...`, `/shared/...`) at its
636
+ * real path and record its `.version` sidecar.
637
+ *
638
+ * Distinct from `setConfig(path)`, which prefixes `/${appId}` and is meant for
639
+ * app payload keys; using it for root paths writes to a shadow location
640
+ * (`/admin/.config/...`) that nothing reads.
641
+ */
642
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
634
643
  /**
635
644
  * Sync .meta/ files (backends.json) to all replica backends.
636
645
  * Called automatically by createConfigRepo() after setupSync().
@@ -1068,6 +1077,15 @@ declare class ConfigRepo implements IConfigRepo {
1068
1077
  private refreshSyncExclusions;
1069
1078
  /** Invalidate the tombstone cache — call after tombstones are modified. */
1070
1079
  private invalidateTombstoneCache;
1080
+ /**
1081
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
1082
+ *
1083
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
1084
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
1085
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
1086
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
1087
+ */
1088
+ private clearTombstonesForWrite;
1071
1089
  /**
1072
1090
  * 判定墓碑目标路径是否在删除之后被重新创建。
1073
1091
  *
@@ -1243,6 +1261,17 @@ declare class ConfigRepo implements IConfigRepo {
1243
1261
  ensureDir(filePath: string): Promise<void>;
1244
1262
  private walkDir;
1245
1263
  writeMetaFile(path: string, data: unknown): Promise<void>;
1264
+ /**
1265
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
1266
+ *
1267
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
1268
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
1269
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
1270
+ *
1271
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
1272
+ * 与内部写描述符 / 元数据的行为一致。
1273
+ */
1274
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
1246
1275
  readMetaFile<T>(path: string): Promise<T | null>;
1247
1276
  /** Read a text file; `null` when absent (used for byte-compare-then-write). */
1248
1277
  private readTextIfExists;
package/dist/index.d.ts CHANGED
@@ -631,6 +631,15 @@ interface IConfigRepo {
631
631
  * instead of being treated as a "missing file" that gets re-created.
632
632
  */
633
633
  deleteFile(path: string): Promise<void>;
634
+ /**
635
+ * Write a repo-root file (`/.config/...`, `/.meta/...`, `/shared/...`) at its
636
+ * real path and record its `.version` sidecar.
637
+ *
638
+ * Distinct from `setConfig(path)`, which prefixes `/${appId}` and is meant for
639
+ * app payload keys; using it for root paths writes to a shadow location
640
+ * (`/admin/.config/...`) that nothing reads.
641
+ */
642
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
634
643
  /**
635
644
  * Sync .meta/ files (backends.json) to all replica backends.
636
645
  * Called automatically by createConfigRepo() after setupSync().
@@ -1068,6 +1077,15 @@ declare class ConfigRepo implements IConfigRepo {
1068
1077
  private refreshSyncExclusions;
1069
1078
  /** Invalidate the tombstone cache — call after tombstones are modified. */
1070
1079
  private invalidateTombstoneCache;
1080
+ /**
1081
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
1082
+ *
1083
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
1084
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
1085
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
1086
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
1087
+ */
1088
+ private clearTombstonesForWrite;
1071
1089
  /**
1072
1090
  * 判定墓碑目标路径是否在删除之后被重新创建。
1073
1091
  *
@@ -1243,6 +1261,17 @@ declare class ConfigRepo implements IConfigRepo {
1243
1261
  ensureDir(filePath: string): Promise<void>;
1244
1262
  private walkDir;
1245
1263
  writeMetaFile(path: string, data: unknown): Promise<void>;
1264
+ /**
1265
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
1266
+ *
1267
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
1268
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
1269
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
1270
+ *
1271
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
1272
+ * 与内部写描述符 / 元数据的行为一致。
1273
+ */
1274
+ writeRepoFile(path: string, data: string | Uint8Array): Promise<void>;
1246
1275
  readMetaFile<T>(path: string): Promise<T | null>;
1247
1276
  /** Read a text file; `null` when absent (used for byte-compare-then-write). */
1248
1277
  private readTextIfExists;
package/dist/index.js CHANGED
@@ -3006,6 +3006,40 @@ var ConfigRepo = class {
3006
3006
  invalidateTombstoneCache() {
3007
3007
  this.tombstoneCache = null;
3008
3008
  }
3009
+ /**
3010
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
3011
+ *
3012
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
3013
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
3014
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
3015
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
3016
+ */
3017
+ async clearTombstonesForWrite(filePath) {
3018
+ let tombstones;
3019
+ try {
3020
+ tombstones = await this.readTombstones();
3021
+ } catch {
3022
+ return;
3023
+ }
3024
+ const normalized = normalizeTombstonePath(filePath);
3025
+ const affected = tombstones.filter((t) => {
3026
+ if (!t.path) return false;
3027
+ if (t.path === normalized) return true;
3028
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
3029
+ });
3030
+ if (affected.length === 0) return;
3031
+ for (const tombstone of affected) {
3032
+ try {
3033
+ await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
3034
+ } catch {
3035
+ }
3036
+ }
3037
+ this.invalidateTombstoneCache();
3038
+ await this.readTombstones();
3039
+ log5.log(
3040
+ `[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
3041
+ );
3042
+ }
3009
3043
  /**
3010
3044
  * 判定墓碑目标路径是否在删除之后被重新创建。
3011
3045
  *
@@ -3774,6 +3808,7 @@ var ConfigRepo = class {
3774
3808
  async persistConfig(fullPath, bytes) {
3775
3809
  await this.ensureDir(fullPath);
3776
3810
  await this.cachedFS.writeFile(fullPath, bytes);
3811
+ await this.clearTombstonesForWrite(fullPath);
3777
3812
  const author = `${this.appId}/${this.nodeId}`;
3778
3813
  const version = await incrementVersion(this.fullFS, fullPath, bytes, author);
3779
3814
  await this.writeVersionSidecar(fullPath, version);
@@ -3915,6 +3950,31 @@ var ConfigRepo = class {
3915
3950
  const version = await incrementVersion(this.fullFS, path, bytes, author);
3916
3951
  await this.writeVersionSidecar(path, version);
3917
3952
  }
3953
+ /**
3954
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
3955
+ *
3956
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
3957
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
3958
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
3959
+ *
3960
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
3961
+ * 与内部写描述符 / 元数据的行为一致。
3962
+ */
3963
+ async writeRepoFile(path, data) {
3964
+ this.assertNotDisposed();
3965
+ const p = path.startsWith("/") ? path : `/${path}`;
3966
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
3967
+ await this.ensureDir(p);
3968
+ await this.cachedFS.writeFile(p, bytes);
3969
+ await this.clearTombstonesForWrite(p);
3970
+ const author = `${this.appId}/${this.nodeId}`;
3971
+ try {
3972
+ const version = await incrementVersion(this.fullFS, p, bytes, author);
3973
+ await this.writeVersionSidecar(p, version);
3974
+ } catch (err) {
3975
+ log5.warn(`[ConfigRepo] writeRepoFile: version sidecar failed for ${p}:`, err);
3976
+ }
3977
+ }
3918
3978
  async readMetaFile(path) {
3919
3979
  try {
3920
3980
  const raw = await this.cachedFS.readFile(path);
@@ -5138,7 +5198,10 @@ var AppDataGroupImpl = class {
5138
5198
  }
5139
5199
  this.fs = createChrootFS(this.localFS, "/", {
5140
5200
  hiddenPrefixes: [META_DIR, CONFIG_DIR],
5141
- onWrite: (path, data) => this.recordVersion(path, data),
5201
+ onWrite: async (path, data) => {
5202
+ await this.clearTombstonesForWrite(path);
5203
+ await this.recordVersion(path, data);
5204
+ },
5142
5205
  onUnlink: (path) => this.deleteFile(path),
5143
5206
  onRmdir: (path) => this.deleteFile(path)
5144
5207
  });
@@ -5294,6 +5357,34 @@ var AppDataGroupImpl = class {
5294
5357
  this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
5295
5358
  }
5296
5359
  }
5360
+ /**
5361
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
5362
+ *
5363
+ * 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
5364
+ * 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
5365
+ */
5366
+ async clearTombstonesForWrite(filePath) {
5367
+ try {
5368
+ const tombstones = await this.tombstones.list();
5369
+ const normalized = normalizeTombstonePath(filePath);
5370
+ const affected = tombstones.filter((t) => {
5371
+ if (!t.path) return false;
5372
+ if (t.path === normalized) return true;
5373
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
5374
+ });
5375
+ if (affected.length === 0) return;
5376
+ for (const tombstone of affected) await this.tombstones.remove(tombstone);
5377
+ this.refreshSyncExclusions(await this.tombstones.list());
5378
+ log5.log(
5379
+ `[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
5380
+ );
5381
+ } catch (err) {
5382
+ log5.warn(
5383
+ `[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
5384
+ err
5385
+ );
5386
+ }
5387
+ }
5297
5388
  async confirmTombstones() {
5298
5389
  try {
5299
5390
  await this.tombstones.confirm(this.tombstoneTargets());
package/dist/index.mjs CHANGED
@@ -2431,6 +2431,40 @@ var ConfigRepo = class {
2431
2431
  invalidateTombstoneCache() {
2432
2432
  this.tombstoneCache = null;
2433
2433
  }
2434
+ /**
2435
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
2436
+ *
2437
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
2438
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
2439
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
2440
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
2441
+ */
2442
+ async clearTombstonesForWrite(filePath) {
2443
+ let tombstones;
2444
+ try {
2445
+ tombstones = await this.readTombstones();
2446
+ } catch {
2447
+ return;
2448
+ }
2449
+ const normalized = normalizeTombstonePath(filePath);
2450
+ const affected = tombstones.filter((t) => {
2451
+ if (!t.path) return false;
2452
+ if (t.path === normalized) return true;
2453
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
2454
+ });
2455
+ if (affected.length === 0) return;
2456
+ for (const tombstone of affected) {
2457
+ try {
2458
+ await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
2459
+ } catch {
2460
+ }
2461
+ }
2462
+ this.invalidateTombstoneCache();
2463
+ await this.readTombstones();
2464
+ log5.log(
2465
+ `[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
2466
+ );
2467
+ }
2434
2468
  /**
2435
2469
  * 判定墓碑目标路径是否在删除之后被重新创建。
2436
2470
  *
@@ -3199,6 +3233,7 @@ var ConfigRepo = class {
3199
3233
  async persistConfig(fullPath, bytes) {
3200
3234
  await this.ensureDir(fullPath);
3201
3235
  await this.cachedFS.writeFile(fullPath, bytes);
3236
+ await this.clearTombstonesForWrite(fullPath);
3202
3237
  const author = `${this.appId}/${this.nodeId}`;
3203
3238
  const version = await incrementVersion(this.fullFS, fullPath, bytes, author);
3204
3239
  await this.writeVersionSidecar(fullPath, version);
@@ -3340,6 +3375,31 @@ var ConfigRepo = class {
3340
3375
  const version = await incrementVersion(this.fullFS, path, bytes, author);
3341
3376
  await this.writeVersionSidecar(path, version);
3342
3377
  }
3378
+ /**
3379
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
3380
+ *
3381
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
3382
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
3383
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
3384
+ *
3385
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
3386
+ * 与内部写描述符 / 元数据的行为一致。
3387
+ */
3388
+ async writeRepoFile(path, data) {
3389
+ this.assertNotDisposed();
3390
+ const p = path.startsWith("/") ? path : `/${path}`;
3391
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
3392
+ await this.ensureDir(p);
3393
+ await this.cachedFS.writeFile(p, bytes);
3394
+ await this.clearTombstonesForWrite(p);
3395
+ const author = `${this.appId}/${this.nodeId}`;
3396
+ try {
3397
+ const version = await incrementVersion(this.fullFS, p, bytes, author);
3398
+ await this.writeVersionSidecar(p, version);
3399
+ } catch (err) {
3400
+ log5.warn(`[ConfigRepo] writeRepoFile: version sidecar failed for ${p}:`, err);
3401
+ }
3402
+ }
3343
3403
  async readMetaFile(path) {
3344
3404
  try {
3345
3405
  const raw = await this.cachedFS.readFile(path);
@@ -4563,7 +4623,10 @@ var AppDataGroupImpl = class {
4563
4623
  }
4564
4624
  this.fs = createChrootFS(this.localFS, "/", {
4565
4625
  hiddenPrefixes: [META_DIR, CONFIG_DIR],
4566
- onWrite: (path, data) => this.recordVersion(path, data),
4626
+ onWrite: async (path, data) => {
4627
+ await this.clearTombstonesForWrite(path);
4628
+ await this.recordVersion(path, data);
4629
+ },
4567
4630
  onUnlink: (path) => this.deleteFile(path),
4568
4631
  onRmdir: (path) => this.deleteFile(path)
4569
4632
  });
@@ -4719,6 +4782,34 @@ var AppDataGroupImpl = class {
4719
4782
  this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
4720
4783
  }
4721
4784
  }
4785
+ /**
4786
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
4787
+ *
4788
+ * 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
4789
+ * 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
4790
+ */
4791
+ async clearTombstonesForWrite(filePath) {
4792
+ try {
4793
+ const tombstones = await this.tombstones.list();
4794
+ const normalized = normalizeTombstonePath(filePath);
4795
+ const affected = tombstones.filter((t) => {
4796
+ if (!t.path) return false;
4797
+ if (t.path === normalized) return true;
4798
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
4799
+ });
4800
+ if (affected.length === 0) return;
4801
+ for (const tombstone of affected) await this.tombstones.remove(tombstone);
4802
+ this.refreshSyncExclusions(await this.tombstones.list());
4803
+ log5.log(
4804
+ `[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
4805
+ );
4806
+ } catch (err) {
4807
+ log5.warn(
4808
+ `[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
4809
+ err
4810
+ );
4811
+ }
4812
+ }
4722
4813
  async confirmTombstones() {
4723
4814
  try {
4724
4815
  await this.tombstones.confirm(this.tombstoneTargets());
@@ -28963,6 +28963,40 @@ var ZenFSConfig = (() => {
28963
28963
  invalidateTombstoneCache() {
28964
28964
  this.tombstoneCache = null;
28965
28965
  }
28966
+ /**
28967
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
28968
+ *
28969
+ * 墓碑表达的是「删除意图」,而同一路径被重新写入是更强的意图。只靠
28970
+ * `isPathRecreatedAfterTombstone` 的 mtime 判定要等到下一轮 tombstone pass 才
28971
+ * 解除排除表:这段窗口里新写入既进不了同步,又可能在 process 里被再删一次。
28972
+ * 因此在写入路径上即时撤销,并立即刷新排除表。
28973
+ */
28974
+ async clearTombstonesForWrite(filePath) {
28975
+ let tombstones;
28976
+ try {
28977
+ tombstones = await this.readTombstones();
28978
+ } catch {
28979
+ return;
28980
+ }
28981
+ const normalized = normalizeTombstonePath(filePath);
28982
+ const affected = tombstones.filter((t) => {
28983
+ if (!t.path) return false;
28984
+ if (t.path === normalized) return true;
28985
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
28986
+ });
28987
+ if (affected.length === 0) return;
28988
+ for (const tombstone of affected) {
28989
+ try {
28990
+ await this.cachedFS.unlink(tombstonePathFor(tombstone.path, TOMBSTONES_DIR));
28991
+ } catch {
28992
+ }
28993
+ }
28994
+ this.invalidateTombstoneCache();
28995
+ await this.readTombstones();
28996
+ log9.log(
28997
+ `[ConfigRepo] cleared ${affected.length} tombstone(s) on write: ${normalized}`
28998
+ );
28999
+ }
28966
29000
  /**
28967
29001
  * 判定墓碑目标路径是否在删除之后被重新创建。
28968
29002
  *
@@ -29731,6 +29765,7 @@ var ZenFSConfig = (() => {
29731
29765
  async persistConfig(fullPath, bytes) {
29732
29766
  await this.ensureDir(fullPath);
29733
29767
  await this.cachedFS.writeFile(fullPath, bytes);
29768
+ await this.clearTombstonesForWrite(fullPath);
29734
29769
  const author = `${this.appId}/${this.nodeId}`;
29735
29770
  const version2 = await incrementVersion(this.fullFS, fullPath, bytes, author);
29736
29771
  await this.writeVersionSidecar(fullPath, version2);
@@ -29872,6 +29907,31 @@ var ZenFSConfig = (() => {
29872
29907
  const version2 = await incrementVersion(this.fullFS, path, bytes, author);
29873
29908
  await this.writeVersionSidecar(path, version2);
29874
29909
  }
29910
+ /**
29911
+ * 写仓库根级文件(`/.config/...`、`/.meta/...`、`/shared/...` 等,不是 app 载荷)。
29912
+ *
29913
+ * 与 `setConfig()` 的区别:`setConfig(path)` 会把路径拼成 `/${appId}${path}`,
29914
+ * 是给应用自己的配置键用的;根级文件必须落在 cachedFS 的真实路径上,否则编辑
29915
+ * 会写进 `/admin/.config/...` 之类的影子目录(读的地方看不到,文件"改了又没改")。
29916
+ *
29917
+ * 落盘后按同一套机制记录 `.version` 边车(作者为 `appId/nodeId`),
29918
+ * 与内部写描述符 / 元数据的行为一致。
29919
+ */
29920
+ async writeRepoFile(path, data) {
29921
+ this.assertNotDisposed();
29922
+ const p = path.startsWith("/") ? path : `/${path}`;
29923
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
29924
+ await this.ensureDir(p);
29925
+ await this.cachedFS.writeFile(p, bytes);
29926
+ await this.clearTombstonesForWrite(p);
29927
+ const author = `${this.appId}/${this.nodeId}`;
29928
+ try {
29929
+ const version2 = await incrementVersion(this.fullFS, p, bytes, author);
29930
+ await this.writeVersionSidecar(p, version2);
29931
+ } catch (err2) {
29932
+ log9.warn(`[ConfigRepo] writeRepoFile: version sidecar failed for ${p}:`, err2);
29933
+ }
29934
+ }
29875
29935
  async readMetaFile(path) {
29876
29936
  try {
29877
29937
  const raw = await this.cachedFS.readFile(path);
@@ -31095,7 +31155,10 @@ var ZenFSConfig = (() => {
31095
31155
  }
31096
31156
  this.fs = createChrootFS(this.localFS, "/", {
31097
31157
  hiddenPrefixes: [META_DIR, CONFIG_DIR],
31098
- onWrite: (path, data) => this.recordVersion(path, data),
31158
+ onWrite: async (path, data) => {
31159
+ await this.clearTombstonesForWrite(path);
31160
+ await this.recordVersion(path, data);
31161
+ },
31099
31162
  onUnlink: (path) => this.deleteFile(path),
31100
31163
  onRmdir: (path) => this.deleteFile(path)
31101
31164
  });
@@ -31251,6 +31314,34 @@ var ZenFSConfig = (() => {
31251
31314
  this.tombstoneExcludePrefixes.push(tombstone.path, `${tombstone.path}/`);
31252
31315
  }
31253
31316
  }
31317
+ /**
31318
+ * 写入成功即撤销该路径(及其被删祖先目录)上的墓碑。
31319
+ *
31320
+ * 与配置组同一语义:墓碑是删除意图,重新写入是更强的意图;只靠 mtime 判定
31321
+ * 要等下一轮 tombstone pass 才解除排除,期间写入既不参与同步又可能被再删。
31322
+ */
31323
+ async clearTombstonesForWrite(filePath) {
31324
+ try {
31325
+ const tombstones = await this.tombstones.list();
31326
+ const normalized = normalizeTombstonePath(filePath);
31327
+ const affected = tombstones.filter((t) => {
31328
+ if (!t.path) return false;
31329
+ if (t.path === normalized) return true;
31330
+ return isDirectoryTombstone(t) && normalized.startsWith(`${t.path}/`);
31331
+ });
31332
+ if (affected.length === 0) return;
31333
+ for (const tombstone of affected) await this.tombstones.remove(tombstone);
31334
+ this.refreshSyncExclusions(await this.tombstones.list());
31335
+ log9.log(
31336
+ `[AppDataGroup:${this.groupId}] cleared ${affected.length} tombstone(s) on write: ${normalized}`
31337
+ );
31338
+ } catch (err2) {
31339
+ log9.warn(
31340
+ `[AppDataGroup:${this.groupId}] clear tombstones on write failed for ${filePath}:`,
31341
+ err2
31342
+ );
31343
+ }
31344
+ }
31254
31345
  async confirmTombstones() {
31255
31346
  try {
31256
31347
  await this.tombstones.confirm(this.tombstoneTargets());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zen-fs-config",
3
- "version": "0.7.6",
3
+ "version": "0.7.8",
4
4
  "description": "Distributed config management library built on ZenFS, zen-fs-cache, and zen-fs-sync",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",