@remnic/core 9.3.678 → 9.3.680

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.
Files changed (39) hide show
  1. package/dist/access-cli.js +4 -4
  2. package/dist/access-http.js +7 -7
  3. package/dist/access-mcp.js +6 -6
  4. package/dist/access-schema.js +3 -3
  5. package/dist/access-service.js +4 -4
  6. package/dist/{capsule-crypto-7FJQINUR.js → capsule-crypto-YO5QJ6L3.js} +2 -2
  7. package/dist/{chunk-K2JYO6QV.js → chunk-5TEYIXMP.js} +3 -3
  8. package/dist/{chunk-2NLLXCJG.js → chunk-BXLOS5AJ.js} +2 -2
  9. package/dist/{chunk-ARV3AUOM.js → chunk-DL6H3D7S.js} +2 -2
  10. package/dist/{chunk-X7Y7WX73.js → chunk-DQEMWVMT.js} +1 -1
  11. package/dist/{chunk-UNZLU2MX.js → chunk-DWQPM67F.js} +4 -4
  12. package/dist/{chunk-UDJLF3BO.js → chunk-JI6HWBYL.js} +2 -2
  13. package/dist/{chunk-4PPMUNV5.js → chunk-OBM7EVFU.js} +3 -3
  14. package/dist/{chunk-KQAFEZQX.js → chunk-VDX2J7OX.js} +2 -2
  15. package/dist/{chunk-PCGCQTU6.js → chunk-W67ZZDHO.js} +10 -10
  16. package/dist/cli.js +11 -11
  17. package/dist/contradiction/index.js +4 -4
  18. package/dist/index.js +15 -15
  19. package/dist/schemas.d.ts +22 -22
  20. package/dist/transfer/backup.js +2 -2
  21. package/dist/transfer/capsule-export.js +2 -2
  22. package/dist/transfer/capsule-import.js +2 -2
  23. package/dist/transfer/types.d.ts +18 -18
  24. package/dist/utils/serialize-mutations.d.ts +122 -0
  25. package/dist/utils/serialize-mutations.js +287 -0
  26. package/dist/utils/serialize-mutations.js.map +1 -0
  27. package/package.json +12 -2
  28. package/src/utils/serialize-mutations.test.ts +1047 -0
  29. package/src/utils/serialize-mutations.ts +679 -0
  30. /package/dist/{capsule-crypto-7FJQINUR.js.map → capsule-crypto-YO5QJ6L3.js.map} +0 -0
  31. /package/dist/{chunk-K2JYO6QV.js.map → chunk-5TEYIXMP.js.map} +0 -0
  32. /package/dist/{chunk-2NLLXCJG.js.map → chunk-BXLOS5AJ.js.map} +0 -0
  33. /package/dist/{chunk-ARV3AUOM.js.map → chunk-DL6H3D7S.js.map} +0 -0
  34. /package/dist/{chunk-X7Y7WX73.js.map → chunk-DQEMWVMT.js.map} +0 -0
  35. /package/dist/{chunk-UNZLU2MX.js.map → chunk-DWQPM67F.js.map} +0 -0
  36. /package/dist/{chunk-UDJLF3BO.js.map → chunk-JI6HWBYL.js.map} +0 -0
  37. /package/dist/{chunk-4PPMUNV5.js.map → chunk-OBM7EVFU.js.map} +0 -0
  38. /package/dist/{chunk-KQAFEZQX.js.map → chunk-VDX2J7OX.js.map} +0 -0
  39. /package/dist/{chunk-PCGCQTU6.js.map → chunk-W67ZZDHO.js.map} +0 -0
package/dist/schemas.d.ts CHANGED
@@ -275,12 +275,12 @@ declare const EntityMentionSchema: z.ZodObject<{
275
275
  title: z.ZodString;
276
276
  facts: z.ZodArray<z.ZodString, "many">;
277
277
  }, "strip", z.ZodTypeAny, {
278
- key: string;
279
278
  title: string;
279
+ key: string;
280
280
  facts: string[];
281
281
  }, {
282
- key: string;
283
282
  title: string;
283
+ key: string;
284
284
  facts: string[];
285
285
  }>, "many">>>;
286
286
  }, "strip", z.ZodTypeAny, {
@@ -288,8 +288,8 @@ declare const EntityMentionSchema: z.ZodObject<{
288
288
  name: string;
289
289
  facts: string[];
290
290
  structuredSections?: {
291
- key: string;
292
291
  title: string;
292
+ key: string;
293
293
  facts: string[];
294
294
  }[] | null | undefined;
295
295
  promptedByQuestion?: string | null | undefined;
@@ -298,8 +298,8 @@ declare const EntityMentionSchema: z.ZodObject<{
298
298
  name: string;
299
299
  facts: string[];
300
300
  structuredSections?: {
301
- key: string;
302
301
  title: string;
302
+ key: string;
303
303
  facts: string[];
304
304
  }[] | null | undefined;
305
305
  promptedByQuestion?: string | null | undefined;
@@ -584,12 +584,12 @@ declare const ProactiveExtractionResultSchema: z.ZodObject<{
584
584
  title: z.ZodString;
585
585
  facts: z.ZodArray<z.ZodString, "many">;
586
586
  }, "strip", z.ZodTypeAny, {
587
- key: string;
588
587
  title: string;
588
+ key: string;
589
589
  facts: string[];
590
590
  }, {
591
- key: string;
592
591
  title: string;
592
+ key: string;
593
593
  facts: string[];
594
594
  }>, "many">>>;
595
595
  }, "strip", z.ZodTypeAny, {
@@ -597,8 +597,8 @@ declare const ProactiveExtractionResultSchema: z.ZodObject<{
597
597
  name: string;
598
598
  facts: string[];
599
599
  structuredSections?: {
600
- key: string;
601
600
  title: string;
601
+ key: string;
602
602
  facts: string[];
603
603
  }[] | null | undefined;
604
604
  promptedByQuestion?: string | null | undefined;
@@ -607,8 +607,8 @@ declare const ProactiveExtractionResultSchema: z.ZodObject<{
607
607
  name: string;
608
608
  facts: string[];
609
609
  structuredSections?: {
610
- key: string;
611
610
  title: string;
611
+ key: string;
612
612
  facts: string[];
613
613
  }[] | null | undefined;
614
614
  promptedByQuestion?: string | null | undefined;
@@ -665,8 +665,8 @@ declare const ProactiveExtractionResultSchema: z.ZodObject<{
665
665
  name: string;
666
666
  facts: string[];
667
667
  structuredSections?: {
668
- key: string;
669
668
  title: string;
669
+ key: string;
670
670
  facts: string[];
671
671
  }[] | null | undefined;
672
672
  promptedByQuestion?: string | null | undefined;
@@ -714,8 +714,8 @@ declare const ProactiveExtractionResultSchema: z.ZodObject<{
714
714
  name: string;
715
715
  facts: string[];
716
716
  structuredSections?: {
717
- key: string;
718
717
  title: string;
718
+ key: string;
719
719
  facts: string[];
720
720
  }[] | null | undefined;
721
721
  promptedByQuestion?: string | null | undefined;
@@ -952,12 +952,12 @@ declare const ExtractionResultSchema: z.ZodObject<{
952
952
  title: z.ZodString;
953
953
  facts: z.ZodArray<z.ZodString, "many">;
954
954
  }, "strip", z.ZodTypeAny, {
955
- key: string;
956
955
  title: string;
956
+ key: string;
957
957
  facts: string[];
958
958
  }, {
959
- key: string;
960
959
  title: string;
960
+ key: string;
961
961
  facts: string[];
962
962
  }>, "many">>>;
963
963
  }, "strip", z.ZodTypeAny, {
@@ -965,8 +965,8 @@ declare const ExtractionResultSchema: z.ZodObject<{
965
965
  name: string;
966
966
  facts: string[];
967
967
  structuredSections?: {
968
- key: string;
969
968
  title: string;
969
+ key: string;
970
970
  facts: string[];
971
971
  }[] | null | undefined;
972
972
  promptedByQuestion?: string | null | undefined;
@@ -975,8 +975,8 @@ declare const ExtractionResultSchema: z.ZodObject<{
975
975
  name: string;
976
976
  facts: string[];
977
977
  structuredSections?: {
978
- key: string;
979
978
  title: string;
979
+ key: string;
980
980
  facts: string[];
981
981
  }[] | null | undefined;
982
982
  promptedByQuestion?: string | null | undefined;
@@ -1047,8 +1047,8 @@ declare const ExtractionResultSchema: z.ZodObject<{
1047
1047
  name: string;
1048
1048
  facts: string[];
1049
1049
  structuredSections?: {
1050
- key: string;
1051
1050
  title: string;
1051
+ key: string;
1052
1052
  facts: string[];
1053
1053
  }[] | null | undefined;
1054
1054
  promptedByQuestion?: string | null | undefined;
@@ -1102,8 +1102,8 @@ declare const ExtractionResultSchema: z.ZodObject<{
1102
1102
  name: string;
1103
1103
  facts: string[];
1104
1104
  structuredSections?: {
1105
- key: string;
1106
1105
  title: string;
1106
+ key: string;
1107
1107
  facts: string[];
1108
1108
  }[] | null | undefined;
1109
1109
  promptedByQuestion?: string | null | undefined;
@@ -1172,12 +1172,12 @@ declare const ConsolidationResultSchema: z.ZodObject<{
1172
1172
  title: z.ZodString;
1173
1173
  facts: z.ZodArray<z.ZodString, "many">;
1174
1174
  }, "strip", z.ZodTypeAny, {
1175
- key: string;
1176
1175
  title: string;
1176
+ key: string;
1177
1177
  facts: string[];
1178
1178
  }, {
1179
- key: string;
1180
1179
  title: string;
1180
+ key: string;
1181
1181
  facts: string[];
1182
1182
  }>, "many">>>;
1183
1183
  }, "strip", z.ZodTypeAny, {
@@ -1185,8 +1185,8 @@ declare const ConsolidationResultSchema: z.ZodObject<{
1185
1185
  name: string;
1186
1186
  facts: string[];
1187
1187
  structuredSections?: {
1188
- key: string;
1189
1188
  title: string;
1189
+ key: string;
1190
1190
  facts: string[];
1191
1191
  }[] | null | undefined;
1192
1192
  promptedByQuestion?: string | null | undefined;
@@ -1195,8 +1195,8 @@ declare const ConsolidationResultSchema: z.ZodObject<{
1195
1195
  name: string;
1196
1196
  facts: string[];
1197
1197
  structuredSections?: {
1198
- key: string;
1199
1198
  title: string;
1199
+ key: string;
1200
1200
  facts: string[];
1201
1201
  }[] | null | undefined;
1202
1202
  promptedByQuestion?: string | null | undefined;
@@ -1215,8 +1215,8 @@ declare const ConsolidationResultSchema: z.ZodObject<{
1215
1215
  name: string;
1216
1216
  facts: string[];
1217
1217
  structuredSections?: {
1218
- key: string;
1219
1218
  title: string;
1219
+ key: string;
1220
1220
  facts: string[];
1221
1221
  }[] | null | undefined;
1222
1222
  promptedByQuestion?: string | null | undefined;
@@ -1235,8 +1235,8 @@ declare const ConsolidationResultSchema: z.ZodObject<{
1235
1235
  name: string;
1236
1236
  facts: string[];
1237
1237
  structuredSections?: {
1238
- key: string;
1239
1238
  title: string;
1239
+ key: string;
1240
1240
  facts: string[];
1241
1241
  }[] | null | undefined;
1242
1242
  promptedByQuestion?: string | null | undefined;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  backupMemoryDir
3
- } from "../chunk-2NLLXCJG.js";
3
+ } from "../chunk-BXLOS5AJ.js";
4
4
  import "../chunk-765K3SAT.js";
5
- import "../chunk-X7Y7WX73.js";
5
+ import "../chunk-DQEMWVMT.js";
6
6
  import "../chunk-J4EB7DNW.js";
7
7
  import "../chunk-UI3NYK34.js";
8
8
  import "../chunk-GCGJW34D.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  exportCapsule,
3
3
  isValidCapsuleSince
4
- } from "../chunk-KQAFEZQX.js";
4
+ } from "../chunk-VDX2J7OX.js";
5
5
  import "../chunk-WEHSQBFR.js";
6
- import "../chunk-X7Y7WX73.js";
6
+ import "../chunk-DQEMWVMT.js";
7
7
  import "../chunk-J4EB7DNW.js";
8
8
  import "../chunk-UI3NYK34.js";
9
9
  import "../chunk-GCGJW34D.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  importCapsule
3
- } from "../chunk-ARV3AUOM.js";
3
+ } from "../chunk-DL6H3D7S.js";
4
4
  import "../chunk-VF4XKTX3.js";
5
5
  import "../chunk-WEHSQBFR.js";
6
- import "../chunk-X7Y7WX73.js";
6
+ import "../chunk-DQEMWVMT.js";
7
7
  import "../chunk-GCGJW34D.js";
8
8
  import "../chunk-BJMBJZ2Y.js";
9
9
  import "../chunk-UKJAGEXH.js";
@@ -313,34 +313,34 @@ declare const CapsuleBlockSchema: z.ZodObject<{
313
313
  peerProfiles: boolean;
314
314
  }>;
315
315
  }, "strip", z.ZodTypeAny, {
316
+ schemaVersion: string;
316
317
  includes: {
317
318
  procedural: boolean;
318
319
  taxonomy: boolean;
319
320
  identityAnchors: boolean;
320
321
  peerProfiles: boolean;
321
322
  };
322
- schemaVersion: string;
323
323
  id: string;
324
324
  description: string;
325
325
  version: string;
326
+ parentCapsule: string | null;
326
327
  parent: {
327
328
  version: string;
328
329
  capsuleId: string;
329
330
  forkRoot: string;
330
331
  } | null;
331
- parentCapsule: string | null;
332
332
  retrievalPolicy: {
333
333
  tierWeights: Record<string, number>;
334
334
  directAnswerEnabled: boolean;
335
335
  };
336
336
  }, {
337
+ schemaVersion: string;
337
338
  includes: {
338
339
  procedural: boolean;
339
340
  taxonomy: boolean;
340
341
  identityAnchors: boolean;
341
342
  peerProfiles: boolean;
342
343
  };
343
- schemaVersion: string;
344
344
  id: string;
345
345
  description: string;
346
346
  version: string;
@@ -464,34 +464,34 @@ declare const ExportManifestV2Schema: z.ZodObject<{
464
464
  peerProfiles: boolean;
465
465
  }>;
466
466
  }, "strip", z.ZodTypeAny, {
467
+ schemaVersion: string;
467
468
  includes: {
468
469
  procedural: boolean;
469
470
  taxonomy: boolean;
470
471
  identityAnchors: boolean;
471
472
  peerProfiles: boolean;
472
473
  };
473
- schemaVersion: string;
474
474
  id: string;
475
475
  description: string;
476
476
  version: string;
477
+ parentCapsule: string | null;
477
478
  parent: {
478
479
  version: string;
479
480
  capsuleId: string;
480
481
  forkRoot: string;
481
482
  } | null;
482
- parentCapsule: string | null;
483
483
  retrievalPolicy: {
484
484
  tierWeights: Record<string, number>;
485
485
  directAnswerEnabled: boolean;
486
486
  };
487
487
  }, {
488
+ schemaVersion: string;
488
489
  includes: {
489
490
  procedural: boolean;
490
491
  taxonomy: boolean;
491
492
  identityAnchors: boolean;
492
493
  peerProfiles: boolean;
493
494
  };
494
- schemaVersion: string;
495
495
  id: string;
496
496
  description: string;
497
497
  version: string;
@@ -518,22 +518,22 @@ declare const ExportManifestV2Schema: z.ZodObject<{
518
518
  pluginVersion: string;
519
519
  includesTranscripts: boolean;
520
520
  capsule: {
521
+ schemaVersion: string;
521
522
  includes: {
522
523
  procedural: boolean;
523
524
  taxonomy: boolean;
524
525
  identityAnchors: boolean;
525
526
  peerProfiles: boolean;
526
527
  };
527
- schemaVersion: string;
528
528
  id: string;
529
529
  description: string;
530
530
  version: string;
531
+ parentCapsule: string | null;
531
532
  parent: {
532
533
  version: string;
533
534
  capsuleId: string;
534
535
  forkRoot: string;
535
536
  } | null;
536
- parentCapsule: string | null;
537
537
  retrievalPolicy: {
538
538
  tierWeights: Record<string, number>;
539
539
  directAnswerEnabled: boolean;
@@ -551,13 +551,13 @@ declare const ExportManifestV2Schema: z.ZodObject<{
551
551
  pluginVersion: string;
552
552
  includesTranscripts: boolean;
553
553
  capsule: {
554
+ schemaVersion: string;
554
555
  includes: {
555
556
  procedural: boolean;
556
557
  taxonomy: boolean;
557
558
  identityAnchors: boolean;
558
559
  peerProfiles: boolean;
559
560
  };
560
- schemaVersion: string;
561
561
  id: string;
562
562
  description: string;
563
563
  version: string;
@@ -683,34 +683,34 @@ declare const ExportBundleV2Schema: z.ZodObject<{
683
683
  peerProfiles: boolean;
684
684
  }>;
685
685
  }, "strip", z.ZodTypeAny, {
686
+ schemaVersion: string;
686
687
  includes: {
687
688
  procedural: boolean;
688
689
  taxonomy: boolean;
689
690
  identityAnchors: boolean;
690
691
  peerProfiles: boolean;
691
692
  };
692
- schemaVersion: string;
693
693
  id: string;
694
694
  description: string;
695
695
  version: string;
696
+ parentCapsule: string | null;
696
697
  parent: {
697
698
  version: string;
698
699
  capsuleId: string;
699
700
  forkRoot: string;
700
701
  } | null;
701
- parentCapsule: string | null;
702
702
  retrievalPolicy: {
703
703
  tierWeights: Record<string, number>;
704
704
  directAnswerEnabled: boolean;
705
705
  };
706
706
  }, {
707
+ schemaVersion: string;
707
708
  includes: {
708
709
  procedural: boolean;
709
710
  taxonomy: boolean;
710
711
  identityAnchors: boolean;
711
712
  peerProfiles: boolean;
712
713
  };
713
- schemaVersion: string;
714
714
  id: string;
715
715
  description: string;
716
716
  version: string;
@@ -737,22 +737,22 @@ declare const ExportBundleV2Schema: z.ZodObject<{
737
737
  pluginVersion: string;
738
738
  includesTranscripts: boolean;
739
739
  capsule: {
740
+ schemaVersion: string;
740
741
  includes: {
741
742
  procedural: boolean;
742
743
  taxonomy: boolean;
743
744
  identityAnchors: boolean;
744
745
  peerProfiles: boolean;
745
746
  };
746
- schemaVersion: string;
747
747
  id: string;
748
748
  description: string;
749
749
  version: string;
750
+ parentCapsule: string | null;
750
751
  parent: {
751
752
  version: string;
752
753
  capsuleId: string;
753
754
  forkRoot: string;
754
755
  } | null;
755
- parentCapsule: string | null;
756
756
  retrievalPolicy: {
757
757
  tierWeights: Record<string, number>;
758
758
  directAnswerEnabled: boolean;
@@ -770,13 +770,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
770
770
  pluginVersion: string;
771
771
  includesTranscripts: boolean;
772
772
  capsule: {
773
+ schemaVersion: string;
773
774
  includes: {
774
775
  procedural: boolean;
775
776
  taxonomy: boolean;
776
777
  identityAnchors: boolean;
777
778
  peerProfiles: boolean;
778
779
  };
779
- schemaVersion: string;
780
780
  id: string;
781
781
  description: string;
782
782
  version: string;
@@ -815,22 +815,22 @@ declare const ExportBundleV2Schema: z.ZodObject<{
815
815
  pluginVersion: string;
816
816
  includesTranscripts: boolean;
817
817
  capsule: {
818
+ schemaVersion: string;
818
819
  includes: {
819
820
  procedural: boolean;
820
821
  taxonomy: boolean;
821
822
  identityAnchors: boolean;
822
823
  peerProfiles: boolean;
823
824
  };
824
- schemaVersion: string;
825
825
  id: string;
826
826
  description: string;
827
827
  version: string;
828
+ parentCapsule: string | null;
828
829
  parent: {
829
830
  version: string;
830
831
  capsuleId: string;
831
832
  forkRoot: string;
832
833
  } | null;
833
- parentCapsule: string | null;
834
834
  retrievalPolicy: {
835
835
  tierWeights: Record<string, number>;
836
836
  directAnswerEnabled: boolean;
@@ -854,13 +854,13 @@ declare const ExportBundleV2Schema: z.ZodObject<{
854
854
  pluginVersion: string;
855
855
  includesTranscripts: boolean;
856
856
  capsule: {
857
+ schemaVersion: string;
857
858
  includes: {
858
859
  procedural: boolean;
859
860
  taxonomy: boolean;
860
861
  identityAnchors: boolean;
861
862
  peerProfiles: boolean;
862
863
  };
863
- schemaVersion: string;
864
864
  id: string;
865
865
  description: string;
866
866
  version: string;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Instance-scoped keyed serializer. Holds the per-key chain map so that all
3
+ * tasks queued under the same key on the SAME serializer run strictly in order.
4
+ *
5
+ * The map is instance-scoped (not module-level) so tests can construct a fresh
6
+ * serializer per case and avoid cross-test contamination, and so adopters that
7
+ * want isolation (e.g. one serializer per storage root) can have it. The free
8
+ * {@link serializeMutations} export delegates to a single shared default
9
+ * instance for callers that want process-wide serialization.
10
+ */
11
+ declare class MutationSerializer {
12
+ private readonly chains;
13
+ /**
14
+ * Run `task` strictly after every other task already queued under `key` on
15
+ * this serializer has settled.
16
+ *
17
+ * Rejection recovery (rule #40, mirroring the catalog's `queueCritical`):
18
+ * if a prior task rejects, later tasks STILL RUN, while the rejecting task's
19
+ * error is surfaced to ITS OWN caller. Concretely, the recovered tail is
20
+ * `run.then(noop, noop)` — never a bare `.then(fn)`, which would let one
21
+ * failure kill every queued task behind it.
22
+ *
23
+ * No unbounded growth: when a chain's last task settles and no newer task
24
+ * chained onto it, its entry is deleted (the storage router's
25
+ * `inFlightResolved` marker-then-clear discipline).
26
+ */
27
+ serialize<T>(key: string, task: () => Promise<T>): Promise<T>;
28
+ /**
29
+ * Test-only: the number of keys with a not-yet-cleaned chain. Used to assert
30
+ * the no-unbounded-growth invariant. Not part of the public contract.
31
+ */
32
+ pendingKeysForTest(): number;
33
+ }
34
+ /**
35
+ * Free-function entry point (issue #1524 signature). Serializes `task` against
36
+ * every other task queued under `key` across the whole process, via a shared
37
+ * default {@link MutationSerializer}. For isolated/testable serialization,
38
+ * construct a `MutationSerializer` directly.
39
+ */
40
+ declare function serializeMutations<T>(key: string, task: () => Promise<T>): Promise<T>;
41
+ /** Options for {@link withHeldFileLock}. */
42
+ interface HeldFileLockOptions {
43
+ /**
44
+ * A lock whose mtime is older than this (in ms) is treated as a crashed
45
+ * holder and broken. Required — there is no safe default, since the right
46
+ * value depends on how long the guarded critical section can legitimately
47
+ * run.
48
+ */
49
+ readonly staleMs: number;
50
+ /**
51
+ * Bounded acquisition: give up trying to acquire a busy lock after this long
52
+ * (ms) and invoke `task(false)` best-effort WITHOUT holding the lock, rather
53
+ * than blocking forever or crashing the primary op. Default 5000ms (matches
54
+ * the namespace catalog's `REBUILD_LOCK_MAX_WAIT_MS`).
55
+ */
56
+ readonly maxWaitMs?: number;
57
+ /**
58
+ * Poll interval (ms) while waiting for a busy lock to clear. Default 50ms.
59
+ */
60
+ readonly pollMs?: number;
61
+ /**
62
+ * While WE hold the lock, refresh its mtime on this cadence (ms) so a
63
+ * legitimately long task is not mistaken for a crashed holder and broken out
64
+ * from under. Default `floor(staleMs / 3)` (at least 100ms), mirroring the
65
+ * catalog heartbeat ratio. Must be comfortably below `staleMs`.
66
+ */
67
+ readonly heartbeatMs?: number;
68
+ /**
69
+ * Test seam (NG7Bg, #1506 round 28): fires AFTER a lock is judged stale and
70
+ * BEFORE the re-verify + unlink, simulating a replacement lock being created
71
+ * in the race window. No-op in production.
72
+ */
73
+ readonly onBeforeBreakStaleUnlinkForTest?: () => Promise<void> | void;
74
+ /**
75
+ * Test seam (codex P2): fires AFTER the release rename moves the lock to a
76
+ * trash path and BEFORE the ownership re-verify/restore — simulating a third
77
+ * contender acquiring the (now-empty) lockPath in the race window. No-op in
78
+ * production. Used to prove the pre-check prevents the rename entirely.
79
+ */
80
+ readonly onAfterReleaseRenameForTest?: () => Promise<void> | void;
81
+ /**
82
+ * Best-effort hook for non-fatal lock warnings (heartbeat refresh failure,
83
+ * release-time ownership check failure). Never throws into the caller. If
84
+ * omitted, warnings are swallowed (the lock is advisory; release/heartbeat
85
+ * failures must never crash the guarded op).
86
+ */
87
+ readonly onLockWarning?: (message: string, err: unknown) => void;
88
+ }
89
+ /**
90
+ * Run `task` under an exclusive on-disk lock at `lockPath`.
91
+ *
92
+ * Cross-process mutex via `open(lockPath, "wx")` (atomic exclusive create).
93
+ * While held, a heartbeat timer refreshes the lock's mtime so a legitimately
94
+ * long task is not mistaken for a crashed holder and broken out from under. A
95
+ * lock older than `opts.staleMs` is treated as stale and broken — but
96
+ * REPLACEMENT-SAFE (NG7Bg): we capture the stale lock's identity (full content
97
+ * line: `<pid> <owner-uuid> <iso>`) when judging it stale, then RE-READ and
98
+ * RE-STAT immediately before `unlink`, deleting only if byte-identical AND
99
+ * still stale. A replacement lock created in the window has a different owner
100
+ * id / timestamp, so its content differs and is left untouched.
101
+ *
102
+ * `task` receives `acquired: boolean` — `true` when we hold the lock, `false`
103
+ * when acquisition timed out (best-effort). The signature takes
104
+ * `(acquired) => Promise<T>` rather than the issue's sketched `() => Promise<T>`
105
+ * so this can be the SINGLE lock home (issue: "do NOT leave two lock
106
+ * implementations; pick one home"): the catalog's touch path needs to DROP on
107
+ * timeout, which requires knowing whether the lock was acquired. A caller that
108
+ * ignores the flag is still assignable (`() => Promise<T>` ⊆
109
+ * `(acquired: boolean) => Promise<T>` in TypeScript).
110
+ *
111
+ * Release is ownership-checked: we only `unlink` a lock whose content still
112
+ * identifies THIS acquirer (same owner id), so a replacement created after we
113
+ * stopped heartbeating is never destroyed — mirroring the catalog's
114
+ * `rebuildLockHeldBySelf`.
115
+ *
116
+ * ADOPTION NOTE: lock only the brief final read-merge-write window, never a
117
+ * long scan — a scan-length lock makes concurrent writers time out and
118
+ * silently drop work (catalog round 5, codex/cursor P2).
119
+ */
120
+ declare function withHeldFileLock<T>(lockPath: string, opts: HeldFileLockOptions, task: (acquired: boolean) => Promise<T>): Promise<T>;
121
+
122
+ export { type HeldFileLockOptions, MutationSerializer, serializeMutations, withHeldFileLock };