@remnic/core 9.35.2 → 9.35.3

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 (203) hide show
  1. package/dist/access-admin-ops-surface.d.ts +5 -5
  2. package/dist/access-admin-ops-surface.js +19 -18
  3. package/dist/access-authorization-probe.d.ts +5 -5
  4. package/dist/access-authorization-probe.js +20 -19
  5. package/dist/access-boundary.d.ts +5 -5
  6. package/dist/access-boundary.js +19 -18
  7. package/dist/access-cli.js +39 -38
  8. package/dist/access-cli.js.map +1 -1
  9. package/dist/access-extraction-force-flush.d.ts +5 -5
  10. package/dist/access-extraction-force-flush.js +19 -18
  11. package/dist/access-http-lcm-compaction.d.ts +5 -5
  12. package/dist/access-http-lifecycle-flush.d.ts +5 -5
  13. package/dist/access-http.d.ts +5 -5
  14. package/dist/access-http.js +24 -23
  15. package/dist/access-identity-continuity-surface.d.ts +4 -4
  16. package/dist/access-identity-continuity-surface.js +19 -18
  17. package/dist/access-lcm-surface.d.ts +5 -5
  18. package/dist/access-lcm-surface.js +19 -18
  19. package/dist/access-mcp.d.ts +5 -5
  20. package/dist/access-mcp.js +22 -21
  21. package/dist/access-namespace-preflight.js +19 -18
  22. package/dist/access-observe-write-surface.d.ts +5 -5
  23. package/dist/access-observe-write-surface.js +19 -18
  24. package/dist/access-operations-batch.js +20 -19
  25. package/dist/access-operations.d.ts +5 -5
  26. package/dist/access-operations.js +21 -20
  27. package/dist/access-recall-concurrency.d.ts +5 -5
  28. package/dist/access-recall-concurrency.js +19 -18
  29. package/dist/access-recall-response.d.ts +5 -5
  30. package/dist/access-recall-response.js +19 -18
  31. package/dist/access-recall-surface.d.ts +5 -5
  32. package/dist/access-recall-surface.js +19 -18
  33. package/dist/access-schema.d.ts +4 -4
  34. package/dist/{access-service-D9zIBlpp.d.ts → access-service-C2WYT1pO.d.ts} +3 -3
  35. package/dist/access-service-helpers.d.ts +5 -5
  36. package/dist/access-service.d.ts +5 -5
  37. package/dist/access-service.js +19 -18
  38. package/dist/access-surface-catalog.d.ts +5 -5
  39. package/dist/access-wearables-meetings-surface.d.ts +2 -2
  40. package/dist/bootstrap.d.ts +4 -4
  41. package/dist/briefing.d.ts +1 -1
  42. package/dist/briefing.js +10 -9
  43. package/dist/buffer.d.ts +1 -1
  44. package/dist/{capsule-merge-2H2IUTBT.js → capsule-merge-IDWJPCWK.js} +77 -8
  45. package/dist/capsule-merge-IDWJPCWK.js.map +1 -0
  46. package/dist/causal-consolidation.js +11 -10
  47. package/dist/causal-consolidation.js.map +1 -1
  48. package/dist/{chunk-65ZPVYTA.js → chunk-3CE77VAP.js} +55 -5
  49. package/dist/chunk-3CE77VAP.js.map +1 -0
  50. package/dist/chunk-4J7G5SY4.js +338 -0
  51. package/dist/chunk-4J7G5SY4.js.map +1 -0
  52. package/dist/{chunk-EO7X2LDK.js → chunk-4TAD3B56.js} +2 -2
  53. package/dist/{chunk-QHYB4MJV.js → chunk-5ZGHUWTT.js} +2 -2
  54. package/dist/{chunk-TCIWHK3N.js → chunk-6D5D5A4M.js} +5 -5
  55. package/dist/{chunk-BIXWNHIL.js → chunk-6TF4M2LB.js} +5 -5
  56. package/dist/{chunk-FHYGLITW.js → chunk-AKELMJO2.js} +217 -45
  57. package/dist/{chunk-FHYGLITW.js.map → chunk-AKELMJO2.js.map} +1 -1
  58. package/dist/{chunk-FBUE6PD3.js → chunk-BEQOZOYZ.js} +21 -4
  59. package/dist/chunk-BEQOZOYZ.js.map +1 -0
  60. package/dist/{chunk-SA3WJJF2.js → chunk-BGLDKAYY.js} +2 -2
  61. package/dist/{chunk-OPRP6Q4Z.js → chunk-DKKZ6SO2.js} +3 -3
  62. package/dist/{chunk-6TAUHL33.js → chunk-DLVPUX7U.js} +10 -2
  63. package/dist/chunk-DLVPUX7U.js.map +1 -0
  64. package/dist/{chunk-QNWXCJ76.js → chunk-ENTCVTQR.js} +18 -1
  65. package/dist/{chunk-QNWXCJ76.js.map → chunk-ENTCVTQR.js.map} +1 -1
  66. package/dist/{chunk-AEPYA55F.js → chunk-FE7MUX7M.js} +2 -2
  67. package/dist/{chunk-GHR7WHZX.js → chunk-GORHSN5C.js} +2 -2
  68. package/dist/{chunk-7TEZUUGM.js → chunk-HUS2XN3T.js} +2 -2
  69. package/dist/{chunk-XWDZQIYU.js → chunk-IJAQCBGV.js} +2 -2
  70. package/dist/{chunk-TJLLYV2X.js → chunk-IMEXE4XS.js} +7 -7
  71. package/dist/{chunk-IZXTZ7BF.js → chunk-JYLN6KHH.js} +6 -6
  72. package/dist/{chunk-HEVWWPTL.js → chunk-LH3KXIBJ.js} +17 -17
  73. package/dist/{chunk-EH5U2YCX.js → chunk-M3DBB2ND.js} +2 -2
  74. package/dist/{chunk-XABS455Y.js → chunk-NBAEGFXT.js} +5 -5
  75. package/dist/{chunk-T4HH5Q3U.js → chunk-OJRLTZQM.js} +3 -3
  76. package/dist/{chunk-7ZHGPX56.js → chunk-PRP3M5Y3.js} +2 -2
  77. package/dist/{chunk-Y2ZD2RVG.js → chunk-PYTUBWAS.js} +2 -2
  78. package/dist/{chunk-4TGZCYHH.js → chunk-Q3CVY7LV.js} +1954 -1642
  79. package/dist/chunk-Q3CVY7LV.js.map +1 -0
  80. package/dist/{chunk-PH3ZWL3W.js → chunk-Q53RLEW7.js} +2 -2
  81. package/dist/{chunk-Y6OWJ3V5.js → chunk-RY2XZTFN.js} +2 -2
  82. package/dist/{chunk-2SHIWGY7.js → chunk-RY7CHVGE.js} +2 -2
  83. package/dist/{chunk-7VUAG236.js → chunk-T3FVAHM7.js} +4 -4
  84. package/dist/{chunk-2LTDWSR6.js → chunk-TSH56VPU.js} +2 -2
  85. package/dist/{chunk-J6SLNQRO.js → chunk-UBWOCQ3I.js} +6 -2
  86. package/dist/chunk-UBWOCQ3I.js.map +1 -0
  87. package/dist/{chunk-5FHE4JI7.js → chunk-VEUVON5I.js} +2 -2
  88. package/dist/{chunk-KEWUNL7P.js → chunk-WET4M3R6.js} +2 -2
  89. package/dist/{chunk-SLPLPGJQ.js → chunk-WL2S2UBB.js} +5 -5
  90. package/dist/{chunk-AHZYNPLX.js → chunk-YVMVVE4B.js} +2 -2
  91. package/dist/{chunk-5HTAJCTO.js → chunk-ZB3YODID.js} +15 -15
  92. package/dist/{cli-mFX-QQvx.d.ts → cli-jkmzdT8P.d.ts} +3 -3
  93. package/dist/cli.d.ts +6 -6
  94. package/dist/cli.js +34 -33
  95. package/dist/compounding/engine.d.ts +1 -1
  96. package/dist/compounding/engine.js +10 -9
  97. package/dist/connectors/codex-materialize-runner.js +10 -9
  98. package/dist/connectors/index.js +10 -9
  99. package/dist/consolidation-provenance-check.d.ts +1 -1
  100. package/dist/consolidation-provenance-check.js +8 -2
  101. package/dist/consolidation-undo.d.ts +1 -1
  102. package/dist/consolidation-undo.js +10 -1
  103. package/dist/consolidation-undo.js.map +1 -1
  104. package/dist/contradiction/index.d.ts +1 -1
  105. package/dist/corpus-watermark.js +12 -11
  106. package/dist/entity-retrieval.d.ts +1 -1
  107. package/dist/entity-retrieval.js +10 -9
  108. package/dist/explicit-capture.d.ts +4 -4
  109. package/dist/explicit-capture.js +6 -3
  110. package/dist/extraction.js +10 -9
  111. package/dist/{forget-4UY2EOKH.js → forget-DNAJ66ZD.js} +2 -2
  112. package/dist/index.d.ts +10 -10
  113. package/dist/index.js +39 -38
  114. package/dist/maintenance/memory-governance.js +10 -9
  115. package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +1 -1
  116. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +10 -9
  117. package/dist/maintenance/rebuild-memory-projection.d.ts +1 -1
  118. package/dist/maintenance/rebuild-memory-projection.js +11 -10
  119. package/dist/{maintenance-70Wq118b.d.ts → maintenance-Ha9Dg93M.d.ts} +1 -1
  120. package/dist/mcp-memory-inspector-app.d.ts +5 -5
  121. package/dist/memory-worth-outcomes.d.ts +1 -1
  122. package/dist/namespaces/migrate.d.ts +1 -1
  123. package/dist/namespaces/migrate.js +11 -10
  124. package/dist/namespaces/storage.d.ts +1 -1
  125. package/dist/namespaces/storage.js +10 -9
  126. package/dist/offline-sync-impression-drain.js +3 -3
  127. package/dist/operator-doctor-corpus.js +13 -12
  128. package/dist/operator-toolkit.d.ts +1 -1
  129. package/dist/operator-toolkit.js +17 -16
  130. package/dist/orchestration/compression-guideline-coordinator.d.ts +1 -1
  131. package/dist/orchestration/maintenance.d.ts +2 -2
  132. package/dist/orchestration/maintenance.js +15 -14
  133. package/dist/{orchestrator-BH8LT-NX.d.ts → orchestrator-DV_u9bfx.d.ts} +3 -3
  134. package/dist/orchestrator.d.ts +4 -4
  135. package/dist/orchestrator.js +39 -38
  136. package/dist/page-versioning.js +7 -1
  137. package/dist/semantic-consolidation.js +11 -10
  138. package/dist/semantic-rule-promotion.js +10 -9
  139. package/dist/semantic-rule-verifier.js +10 -9
  140. package/dist/{service-CrxXHz5T.d.ts → service-JxXXY-Eh.d.ts} +1 -1
  141. package/dist/source-agent-qualifier.js +10 -9
  142. package/dist/{storage-CyWa1Jm6.d.ts → storage-BbH4HDUS.d.ts} +30 -26
  143. package/dist/storage.d.ts +1 -1
  144. package/dist/storage.js +9 -8
  145. package/dist/temporal-supersession.d.ts +1 -1
  146. package/dist/tier-migration.d.ts +1 -1
  147. package/dist/transfer/capsule-import.js +8 -2
  148. package/dist/verified-recall.js +10 -9
  149. package/package.json +2 -2
  150. package/src/binary-lifecycle/pipeline.ts +52 -1
  151. package/src/consolidation-undo.ts +4 -0
  152. package/src/curation/index.ts +41 -5
  153. package/src/lifecycle/tombstones.ts +40 -0
  154. package/src/maintenance/memory-governance.ts +4 -0
  155. package/src/page-versioning.ts +16 -1
  156. package/src/review/index.ts +97 -13
  157. package/src/spaces/index.ts +127 -6
  158. package/src/storage/citation-hash-source.ts +97 -0
  159. package/src/storage/entity-canonical-id-lock.ts +33 -0
  160. package/src/storage/entity-canonical-id-migration-adapter.ts +8 -4
  161. package/src/storage/entity-canonical-id-migration.ts +129 -77
  162. package/src/storage/entity-canonical-id-references.ts +557 -0
  163. package/src/storage/entity-ref-repair.ts +171 -0
  164. package/src/storage/entity-store.ts +163 -2
  165. package/src/storage/tombstone-blocked-capture-sync.ts +18 -0
  166. package/src/storage.ts +363 -396
  167. package/src/transfer/capsule-import.ts +91 -3
  168. package/src/transfer/capsule-merge.ts +128 -10
  169. package/dist/capsule-merge-2H2IUTBT.js.map +0 -1
  170. package/dist/chunk-4TGZCYHH.js.map +0 -1
  171. package/dist/chunk-65ZPVYTA.js.map +0 -1
  172. package/dist/chunk-6TAUHL33.js.map +0 -1
  173. package/dist/chunk-FBUE6PD3.js.map +0 -1
  174. package/dist/chunk-J6SLNQRO.js.map +0 -1
  175. /package/dist/{chunk-EO7X2LDK.js.map → chunk-4TAD3B56.js.map} +0 -0
  176. /package/dist/{chunk-QHYB4MJV.js.map → chunk-5ZGHUWTT.js.map} +0 -0
  177. /package/dist/{chunk-TCIWHK3N.js.map → chunk-6D5D5A4M.js.map} +0 -0
  178. /package/dist/{chunk-BIXWNHIL.js.map → chunk-6TF4M2LB.js.map} +0 -0
  179. /package/dist/{chunk-SA3WJJF2.js.map → chunk-BGLDKAYY.js.map} +0 -0
  180. /package/dist/{chunk-OPRP6Q4Z.js.map → chunk-DKKZ6SO2.js.map} +0 -0
  181. /package/dist/{chunk-AEPYA55F.js.map → chunk-FE7MUX7M.js.map} +0 -0
  182. /package/dist/{chunk-GHR7WHZX.js.map → chunk-GORHSN5C.js.map} +0 -0
  183. /package/dist/{chunk-7TEZUUGM.js.map → chunk-HUS2XN3T.js.map} +0 -0
  184. /package/dist/{chunk-XWDZQIYU.js.map → chunk-IJAQCBGV.js.map} +0 -0
  185. /package/dist/{chunk-TJLLYV2X.js.map → chunk-IMEXE4XS.js.map} +0 -0
  186. /package/dist/{chunk-IZXTZ7BF.js.map → chunk-JYLN6KHH.js.map} +0 -0
  187. /package/dist/{chunk-HEVWWPTL.js.map → chunk-LH3KXIBJ.js.map} +0 -0
  188. /package/dist/{chunk-EH5U2YCX.js.map → chunk-M3DBB2ND.js.map} +0 -0
  189. /package/dist/{chunk-XABS455Y.js.map → chunk-NBAEGFXT.js.map} +0 -0
  190. /package/dist/{chunk-T4HH5Q3U.js.map → chunk-OJRLTZQM.js.map} +0 -0
  191. /package/dist/{chunk-7ZHGPX56.js.map → chunk-PRP3M5Y3.js.map} +0 -0
  192. /package/dist/{chunk-Y2ZD2RVG.js.map → chunk-PYTUBWAS.js.map} +0 -0
  193. /package/dist/{chunk-PH3ZWL3W.js.map → chunk-Q53RLEW7.js.map} +0 -0
  194. /package/dist/{chunk-Y6OWJ3V5.js.map → chunk-RY2XZTFN.js.map} +0 -0
  195. /package/dist/{chunk-2SHIWGY7.js.map → chunk-RY7CHVGE.js.map} +0 -0
  196. /package/dist/{chunk-7VUAG236.js.map → chunk-T3FVAHM7.js.map} +0 -0
  197. /package/dist/{chunk-2LTDWSR6.js.map → chunk-TSH56VPU.js.map} +0 -0
  198. /package/dist/{chunk-5FHE4JI7.js.map → chunk-VEUVON5I.js.map} +0 -0
  199. /package/dist/{chunk-KEWUNL7P.js.map → chunk-WET4M3R6.js.map} +0 -0
  200. /package/dist/{chunk-SLPLPGJQ.js.map → chunk-WL2S2UBB.js.map} +0 -0
  201. /package/dist/{chunk-AHZYNPLX.js.map → chunk-YVMVVE4B.js.map} +0 -0
  202. /package/dist/{chunk-5HTAJCTO.js.map → chunk-ZB3YODID.js.map} +0 -0
  203. /package/dist/{forget-4UY2EOKH.js.map → forget-DNAJ66ZD.js.map} +0 -0
package/dist/cli.js CHANGED
@@ -90,7 +90,7 @@ import {
90
90
  runWorkProductStatusCliCommand,
91
91
  runWorkProjectCliCommand,
92
92
  runWorkTaskCliCommand
93
- } from "./chunk-HEVWWPTL.js";
93
+ } from "./chunk-LH3KXIBJ.js";
94
94
  import "./chunk-MMACM5G2.js";
95
95
  import "./chunk-54BGIBCR.js";
96
96
  import "./chunk-H4CKS5B2.js";
@@ -111,8 +111,8 @@ import "./chunk-XL24QQ63.js";
111
111
  import "./chunk-EEC4PCG5.js";
112
112
  import "./chunk-PYIFUBRK.js";
113
113
  import "./chunk-MNB5RMAY.js";
114
- import "./chunk-XABS455Y.js";
115
- import "./chunk-OPRP6Q4Z.js";
114
+ import "./chunk-NBAEGFXT.js";
115
+ import "./chunk-DKKZ6SO2.js";
116
116
  import "./chunk-DX3XRGLH.js";
117
117
  import "./chunk-P65YJEEL.js";
118
118
  import "./chunk-MC6XO7T4.js";
@@ -120,23 +120,23 @@ import "./chunk-KJTKLXTH.js";
120
120
  import "./chunk-GQL52GQ5.js";
121
121
  import "./chunk-HSSERO3E.js";
122
122
  import "./chunk-NOUJNHWG.js";
123
- import "./chunk-EO7X2LDK.js";
123
+ import "./chunk-4TAD3B56.js";
124
124
  import "./chunk-2F6NP3NT.js";
125
125
  import "./chunk-TERNBNJB.js";
126
126
  import "./chunk-OJP3N7UK.js";
127
- import "./chunk-KEWUNL7P.js";
128
- import "./chunk-7ZHGPX56.js";
127
+ import "./chunk-WET4M3R6.js";
128
+ import "./chunk-PRP3M5Y3.js";
129
129
  import "./chunk-6BNE62PM.js";
130
130
  import "./chunk-ZRWB5D4H.js";
131
131
  import "./chunk-HYQJQGD3.js";
132
132
  import "./chunk-DMT2RGAZ.js";
133
133
  import "./chunk-33JBK2XP.js";
134
- import "./chunk-TJLLYV2X.js";
135
- import "./chunk-TCIWHK3N.js";
134
+ import "./chunk-IMEXE4XS.js";
135
+ import "./chunk-6D5D5A4M.js";
136
136
  import "./chunk-KFY3SGN7.js";
137
137
  import "./chunk-3T74IZB3.js";
138
138
  import "./chunk-CMTINOFS.js";
139
- import "./chunk-AHZYNPLX.js";
139
+ import "./chunk-YVMVVE4B.js";
140
140
  import "./chunk-WDISJRMG.js";
141
141
  import "./chunk-UR6PBX2J.js";
142
142
  import "./chunk-6GUG4YNM.js";
@@ -153,7 +153,7 @@ import "./chunk-AUDJPF4N.js";
153
153
  import "./chunk-44442YCH.js";
154
154
  import "./chunk-Y4Z4I6WK.js";
155
155
  import "./chunk-OKTXM5H4.js";
156
- import "./chunk-2LTDWSR6.js";
156
+ import "./chunk-TSH56VPU.js";
157
157
  import "./chunk-LMDRGRJ2.js";
158
158
  import "./chunk-B7RWBZXW.js";
159
159
  import "./chunk-YBPYIAA5.js";
@@ -168,7 +168,7 @@ import "./chunk-OO42R444.js";
168
168
  import "./chunk-PIG4WJFQ.js";
169
169
  import "./chunk-KFZY2OFH.js";
170
170
  import "./chunk-LBJBNWS2.js";
171
- import "./chunk-SLPLPGJQ.js";
171
+ import "./chunk-WL2S2UBB.js";
172
172
  import "./chunk-V7IZKJI3.js";
173
173
  import "./chunk-SEDEKFYQ.js";
174
174
  import "./chunk-RKNJBZ55.js";
@@ -178,11 +178,11 @@ import "./chunk-42NQ7AVG.js";
178
178
  import "./chunk-TMSXWOBZ.js";
179
179
  import "./chunk-7RXCMVFQ.js";
180
180
  import "./chunk-MKQBXQKU.js";
181
- import "./chunk-5FHE4JI7.js";
181
+ import "./chunk-VEUVON5I.js";
182
182
  import "./chunk-57QKLRBV.js";
183
183
  import "./chunk-D24OXEPB.js";
184
- import "./chunk-GHR7WHZX.js";
185
- import "./chunk-T4HH5Q3U.js";
184
+ import "./chunk-GORHSN5C.js";
185
+ import "./chunk-OJRLTZQM.js";
186
186
  import "./chunk-HNZKVLAN.js";
187
187
  import "./chunk-EQWEIIKQ.js";
188
188
  import "./chunk-UTRO5UJU.js";
@@ -196,11 +196,11 @@ import "./chunk-WWUVONGW.js";
196
196
  import "./chunk-5IVLTFOV.js";
197
197
  import "./chunk-VCD4PSK2.js";
198
198
  import "./chunk-OADWQ5CR.js";
199
- import "./chunk-EH5U2YCX.js";
200
- import "./chunk-5HTAJCTO.js";
199
+ import "./chunk-M3DBB2ND.js";
200
+ import "./chunk-ZB3YODID.js";
201
201
  import "./chunk-GDASG7NC.js";
202
202
  import "./chunk-GDB4J2H3.js";
203
- import "./chunk-65ZPVYTA.js";
203
+ import "./chunk-3CE77VAP.js";
204
204
  import "./chunk-VQ7B2Q6M.js";
205
205
  import "./chunk-PJSK6OJM.js";
206
206
  import "./chunk-GNVZQ5JN.js";
@@ -213,11 +213,11 @@ import "./chunk-MYXWPG5O.js";
213
213
  import "./chunk-SOBJ6NEY.js";
214
214
  import "./chunk-KWU6MAD4.js";
215
215
  import "./chunk-AHVEHR6K.js";
216
- import "./chunk-J6SLNQRO.js";
216
+ import "./chunk-UBWOCQ3I.js";
217
217
  import "./chunk-ICP53SKG.js";
218
218
  import "./chunk-AQEJKOKI.js";
219
219
  import "./chunk-6HMYUWXR.js";
220
- import "./chunk-7TEZUUGM.js";
220
+ import "./chunk-HUS2XN3T.js";
221
221
  import "./chunk-R6YJI3HE.js";
222
222
  import "./chunk-ULARSG5Z.js";
223
223
  import "./chunk-XOQSEF7X.js";
@@ -230,10 +230,10 @@ import "./chunk-7TWUCYER.js";
230
230
  import "./chunk-EMDLM3LW.js";
231
231
  import "./chunk-NLE6TSLG.js";
232
232
  import "./chunk-QDW3E4RD.js";
233
- import "./chunk-PH3ZWL3W.js";
233
+ import "./chunk-Q53RLEW7.js";
234
234
  import "./chunk-C37ZRXX7.js";
235
- import "./chunk-SA3WJJF2.js";
236
- import "./chunk-2SHIWGY7.js";
235
+ import "./chunk-BGLDKAYY.js";
236
+ import "./chunk-RY7CHVGE.js";
237
237
  import "./chunk-IOQFPVGY.js";
238
238
  import "./chunk-UZQCNOPS.js";
239
239
  import "./chunk-ES36HTSC.js";
@@ -244,7 +244,7 @@ import "./chunk-S2BBISHU.js";
244
244
  import "./chunk-W7IGLX4G.js";
245
245
  import "./chunk-CINZGPSJ.js";
246
246
  import "./chunk-CYEPCZN5.js";
247
- import "./chunk-Y2ZD2RVG.js";
247
+ import "./chunk-PYTUBWAS.js";
248
248
  import "./chunk-LEPOP46W.js";
249
249
  import "./chunk-72A4L5JJ.js";
250
250
  import "./chunk-A7Q43EUZ.js";
@@ -264,20 +264,18 @@ import "./chunk-64UDOIMI.js";
264
264
  import "./chunk-O75CRYGF.js";
265
265
  import "./chunk-OD4FM2U7.js";
266
266
  import "./chunk-ZY2MNJR6.js";
267
- import "./chunk-QHYB4MJV.js";
267
+ import "./chunk-5ZGHUWTT.js";
268
268
  import "./chunk-KSXJOC4F.js";
269
269
  import "./chunk-NRV4Y3PM.js";
270
- import "./chunk-BIXWNHIL.js";
271
- import "./chunk-4TGZCYHH.js";
270
+ import "./chunk-6TF4M2LB.js";
271
+ import "./chunk-Q3CVY7LV.js";
272
272
  import "./chunk-UHVXE24Y.js";
273
- import "./chunk-QNWXCJ76.js";
273
+ import "./chunk-ENTCVTQR.js";
274
274
  import "./chunk-WIPEXG6R.js";
275
- import "./chunk-DNHVPZOD.js";
276
- import "./chunk-6CIAGZ6X.js";
277
275
  import "./chunk-HKF5VASQ.js";
278
276
  import "./chunk-J6A3CX5N.js";
279
277
  import "./chunk-HXDWZFNP.js";
280
- import "./chunk-7VUAG236.js";
278
+ import "./chunk-T3FVAHM7.js";
281
279
  import "./chunk-EGGE52UU.js";
282
280
  import "./chunk-ILGC6JH6.js";
283
281
  import "./chunk-SCU65EZI.js";
@@ -285,20 +283,23 @@ import "./chunk-WRJVB3C2.js";
285
283
  import "./chunk-GCASGYIO.js";
286
284
  import "./chunk-DM2T26WE.js";
287
285
  import "./chunk-LDXUBPMO.js";
288
- import "./chunk-FBUE6PD3.js";
286
+ import "./chunk-BEQOZOYZ.js";
289
287
  import "./chunk-CGASUJVP.js";
290
288
  import "./chunk-R3DJVOSM.js";
291
289
  import "./chunk-BT7NVCML.js";
292
- import "./chunk-FFAZ2XFU.js";
293
290
  import "./chunk-3CSX3ETE.js";
294
291
  import "./chunk-RL6NEVXT.js";
295
292
  import "./chunk-JYIJNNN3.js";
296
293
  import "./chunk-AAD2ZS6P.js";
297
294
  import "./chunk-YXZG5TVN.js";
298
295
  import "./chunk-G7D6GZ5J.js";
299
- import "./chunk-6TAUHL33.js";
296
+ import "./chunk-DLVPUX7U.js";
300
297
  import "./chunk-IJ7HK452.js";
301
298
  import "./chunk-PDJTHRAW.js";
299
+ import "./chunk-4J7G5SY4.js";
300
+ import "./chunk-DNHVPZOD.js";
301
+ import "./chunk-6CIAGZ6X.js";
302
+ import "./chunk-FFAZ2XFU.js";
302
303
  import "./chunk-W5H6ZRPT.js";
303
304
  import "./chunk-XMMESCPD.js";
304
305
  import "./chunk-42JKGUFJ.js";
@@ -1,4 +1,4 @@
1
- import { S as StorageManager } from '../storage-CyWa1Jm6.js';
1
+ import { S as StorageManager } from '../storage-BbH4HDUS.js';
2
2
  import { P as PluginConfig } from '../types-5398p7Zm.js';
3
3
  import { SharedFeedbackEntry } from '../shared-context/manager.js';
4
4
  import { QmdConfigProjection } from '../capabilities.js';
@@ -1,19 +1,17 @@
1
1
  import {
2
2
  CompoundingEngine,
3
3
  defaultTierMigrationCycleBudget
4
- } from "../chunk-XWDZQIYU.js";
4
+ } from "../chunk-IJAQCBGV.js";
5
5
  import "../chunk-AS7YMSL6.js";
6
6
  import "../chunk-FQC3DHH2.js";
7
- import "../chunk-4TGZCYHH.js";
7
+ import "../chunk-Q3CVY7LV.js";
8
8
  import "../chunk-UHVXE24Y.js";
9
- import "../chunk-QNWXCJ76.js";
9
+ import "../chunk-ENTCVTQR.js";
10
10
  import "../chunk-WIPEXG6R.js";
11
- import "../chunk-DNHVPZOD.js";
12
- import "../chunk-6CIAGZ6X.js";
13
11
  import "../chunk-HKF5VASQ.js";
14
12
  import "../chunk-J6A3CX5N.js";
15
13
  import "../chunk-HXDWZFNP.js";
16
- import "../chunk-7VUAG236.js";
14
+ import "../chunk-T3FVAHM7.js";
17
15
  import "../chunk-EGGE52UU.js";
18
16
  import "../chunk-ILGC6JH6.js";
19
17
  import "../chunk-SCU65EZI.js";
@@ -21,20 +19,23 @@ import "../chunk-WRJVB3C2.js";
21
19
  import "../chunk-GCASGYIO.js";
22
20
  import "../chunk-DM2T26WE.js";
23
21
  import "../chunk-LDXUBPMO.js";
24
- import "../chunk-FBUE6PD3.js";
22
+ import "../chunk-BEQOZOYZ.js";
25
23
  import "../chunk-CGASUJVP.js";
26
24
  import "../chunk-R3DJVOSM.js";
27
25
  import "../chunk-BT7NVCML.js";
28
- import "../chunk-FFAZ2XFU.js";
29
26
  import "../chunk-3CSX3ETE.js";
30
27
  import "../chunk-RL6NEVXT.js";
31
28
  import "../chunk-JYIJNNN3.js";
32
29
  import "../chunk-AAD2ZS6P.js";
33
30
  import "../chunk-YXZG5TVN.js";
34
31
  import "../chunk-G7D6GZ5J.js";
35
- import "../chunk-6TAUHL33.js";
32
+ import "../chunk-DLVPUX7U.js";
36
33
  import "../chunk-IJ7HK452.js";
37
34
  import "../chunk-PDJTHRAW.js";
35
+ import "../chunk-4J7G5SY4.js";
36
+ import "../chunk-DNHVPZOD.js";
37
+ import "../chunk-6CIAGZ6X.js";
38
+ import "../chunk-FFAZ2XFU.js";
38
39
  import "../chunk-W5H6ZRPT.js";
39
40
  import "../chunk-XMMESCPD.js";
40
41
  import "../chunk-42JKGUFJ.js";
@@ -1,18 +1,16 @@
1
1
  import {
2
2
  runCodexMaterialize,
3
3
  runPostConsolidationMaterialize
4
- } from "../chunk-QHYB4MJV.js";
4
+ } from "../chunk-5ZGHUWTT.js";
5
5
  import "../chunk-KSXJOC4F.js";
6
- import "../chunk-4TGZCYHH.js";
6
+ import "../chunk-Q3CVY7LV.js";
7
7
  import "../chunk-UHVXE24Y.js";
8
- import "../chunk-QNWXCJ76.js";
8
+ import "../chunk-ENTCVTQR.js";
9
9
  import "../chunk-WIPEXG6R.js";
10
- import "../chunk-DNHVPZOD.js";
11
- import "../chunk-6CIAGZ6X.js";
12
10
  import "../chunk-HKF5VASQ.js";
13
11
  import "../chunk-J6A3CX5N.js";
14
12
  import "../chunk-HXDWZFNP.js";
15
- import "../chunk-7VUAG236.js";
13
+ import "../chunk-T3FVAHM7.js";
16
14
  import "../chunk-EGGE52UU.js";
17
15
  import "../chunk-ILGC6JH6.js";
18
16
  import "../chunk-SCU65EZI.js";
@@ -20,20 +18,23 @@ import "../chunk-WRJVB3C2.js";
20
18
  import "../chunk-GCASGYIO.js";
21
19
  import "../chunk-DM2T26WE.js";
22
20
  import "../chunk-LDXUBPMO.js";
23
- import "../chunk-FBUE6PD3.js";
21
+ import "../chunk-BEQOZOYZ.js";
24
22
  import "../chunk-CGASUJVP.js";
25
23
  import "../chunk-R3DJVOSM.js";
26
24
  import "../chunk-BT7NVCML.js";
27
- import "../chunk-FFAZ2XFU.js";
28
25
  import "../chunk-3CSX3ETE.js";
29
26
  import "../chunk-RL6NEVXT.js";
30
27
  import "../chunk-JYIJNNN3.js";
31
28
  import "../chunk-AAD2ZS6P.js";
32
29
  import "../chunk-YXZG5TVN.js";
33
30
  import "../chunk-G7D6GZ5J.js";
34
- import "../chunk-6TAUHL33.js";
31
+ import "../chunk-DLVPUX7U.js";
35
32
  import "../chunk-IJ7HK452.js";
36
33
  import "../chunk-PDJTHRAW.js";
34
+ import "../chunk-4J7G5SY4.js";
35
+ import "../chunk-DNHVPZOD.js";
36
+ import "../chunk-6CIAGZ6X.js";
37
+ import "../chunk-FFAZ2XFU.js";
37
38
  import "../chunk-W5H6ZRPT.js";
38
39
  import "../chunk-XMMESCPD.js";
39
40
  import "../chunk-42JKGUFJ.js";
@@ -30,7 +30,7 @@ import "../chunk-EMDLM3LW.js";
30
30
  import "../chunk-O75CRYGF.js";
31
31
  import {
32
32
  runCodexMaterialize
33
- } from "../chunk-QHYB4MJV.js";
33
+ } from "../chunk-5ZGHUWTT.js";
34
34
  import {
35
35
  MATERIALIZE_VERSION,
36
36
  SENTINEL_FILE,
@@ -46,16 +46,14 @@ import {
46
46
  truncateToTokenBudget,
47
47
  validateMemoryMd
48
48
  } from "../chunk-KSXJOC4F.js";
49
- import "../chunk-4TGZCYHH.js";
49
+ import "../chunk-Q3CVY7LV.js";
50
50
  import "../chunk-UHVXE24Y.js";
51
- import "../chunk-QNWXCJ76.js";
51
+ import "../chunk-ENTCVTQR.js";
52
52
  import "../chunk-WIPEXG6R.js";
53
- import "../chunk-DNHVPZOD.js";
54
- import "../chunk-6CIAGZ6X.js";
55
53
  import "../chunk-HKF5VASQ.js";
56
54
  import "../chunk-J6A3CX5N.js";
57
55
  import "../chunk-HXDWZFNP.js";
58
- import "../chunk-7VUAG236.js";
56
+ import "../chunk-T3FVAHM7.js";
59
57
  import "../chunk-EGGE52UU.js";
60
58
  import "../chunk-ILGC6JH6.js";
61
59
  import "../chunk-SCU65EZI.js";
@@ -63,20 +61,23 @@ import "../chunk-WRJVB3C2.js";
63
61
  import "../chunk-GCASGYIO.js";
64
62
  import "../chunk-DM2T26WE.js";
65
63
  import "../chunk-LDXUBPMO.js";
66
- import "../chunk-FBUE6PD3.js";
64
+ import "../chunk-BEQOZOYZ.js";
67
65
  import "../chunk-CGASUJVP.js";
68
66
  import "../chunk-R3DJVOSM.js";
69
67
  import "../chunk-BT7NVCML.js";
70
- import "../chunk-FFAZ2XFU.js";
71
68
  import "../chunk-3CSX3ETE.js";
72
69
  import "../chunk-RL6NEVXT.js";
73
70
  import "../chunk-JYIJNNN3.js";
74
71
  import "../chunk-AAD2ZS6P.js";
75
72
  import "../chunk-YXZG5TVN.js";
76
73
  import "../chunk-G7D6GZ5J.js";
77
- import "../chunk-6TAUHL33.js";
74
+ import "../chunk-DLVPUX7U.js";
78
75
  import "../chunk-IJ7HK452.js";
79
76
  import "../chunk-PDJTHRAW.js";
77
+ import "../chunk-4J7G5SY4.js";
78
+ import "../chunk-DNHVPZOD.js";
79
+ import "../chunk-6CIAGZ6X.js";
80
+ import "../chunk-FFAZ2XFU.js";
80
81
  import "../chunk-W5H6ZRPT.js";
81
82
  import "../chunk-XMMESCPD.js";
82
83
  import "../chunk-42JKGUFJ.js";
@@ -1,4 +1,4 @@
1
- import { S as StorageManager } from './storage-CyWa1Jm6.js';
1
+ import { S as StorageManager } from './storage-BbH4HDUS.js';
2
2
  import './types-5398p7Zm.js';
3
3
  import './message-parts/index.js';
4
4
  import './bounded-jsonl-state.js';
@@ -1,13 +1,19 @@
1
1
  import {
2
2
  runConsolidationProvenanceCheck
3
- } from "./chunk-2LTDWSR6.js";
3
+ } from "./chunk-TSH56VPU.js";
4
4
  import "./chunk-G7D6GZ5J.js";
5
- import "./chunk-6TAUHL33.js";
5
+ import "./chunk-DLVPUX7U.js";
6
6
  import "./chunk-IJ7HK452.js";
7
7
  import "./chunk-PDJTHRAW.js";
8
+ import "./chunk-4J7G5SY4.js";
9
+ import "./chunk-DNHVPZOD.js";
10
+ import "./chunk-6CIAGZ6X.js";
11
+ import "./chunk-FFAZ2XFU.js";
8
12
  import "./chunk-XMMESCPD.js";
9
13
  import "./chunk-42JKGUFJ.js";
14
+ import "./chunk-5UZXUTVO.js";
10
15
  import "./chunk-VS2IYZRU.js";
16
+ import "./chunk-3WCASNQZ.js";
11
17
  import "./chunk-PZ5AY32C.js";
12
18
  export {
13
19
  runConsolidationProvenanceCheck
@@ -1,4 +1,4 @@
1
- import { S as StorageManager } from './storage-CyWa1Jm6.js';
1
+ import { S as StorageManager } from './storage-BbH4HDUS.js';
2
2
  import { VersioningConfig } from './page-versioning.js';
3
3
  import './types-5398p7Zm.js';
4
4
  import './message-parts/index.js';
@@ -1,13 +1,21 @@
1
1
  import {
2
2
  getVersion
3
- } from "./chunk-6TAUHL33.js";
3
+ } from "./chunk-DLVPUX7U.js";
4
4
  import {
5
5
  bumpMemoryCorpusVersionForDir
6
6
  } from "./chunk-IJ7HK452.js";
7
7
  import "./chunk-PDJTHRAW.js";
8
+ import {
9
+ requestEntityCanonicalIdReconcile
10
+ } from "./chunk-4J7G5SY4.js";
11
+ import "./chunk-DNHVPZOD.js";
12
+ import "./chunk-6CIAGZ6X.js";
13
+ import "./chunk-FFAZ2XFU.js";
8
14
  import "./chunk-XMMESCPD.js";
9
15
  import "./chunk-42JKGUFJ.js";
16
+ import "./chunk-5UZXUTVO.js";
10
17
  import "./chunk-VS2IYZRU.js";
18
+ import "./chunk-3WCASNQZ.js";
11
19
  import "./chunk-PZ5AY32C.js";
12
20
 
13
21
  // src/consolidation-undo.ts
@@ -380,6 +388,7 @@ async function runConsolidationUndo(options) {
380
388
  await mkdir(path.dirname(p.sourcePath), { recursive: true });
381
389
  await writeFile(p.sourcePath, p.content, { encoding: "utf-8", flag: "wx" });
382
390
  bumpMemoryCorpusVersionForDir(memoryDir);
391
+ await requestEntityCanonicalIdReconcile(path.join(memoryDir, "state"));
383
392
  result.restores.push({
384
393
  entry: p.entry,
385
394
  sourcePath: p.sourcePath,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/consolidation-undo.ts"],"sourcesContent":["/**\n * Consolidation undo (issue #561 PR 5).\n *\n * Reverts a consolidated memory by restoring each source memory from its\n * `derived_from` snapshot and archiving the target.\n *\n * Contract:\n * - Load the target memory markdown file via its absolute path.\n * - For every `\"<rel>:<version>\"` entry in `derived_from`, fetch the\n * snapshot content via `page-versioning.getVersion` and restore it\n * to the original relative path. If the restore target file\n * already exists, we skip overwriting it (the source was never\n * archived, or was re-created since) and record the skip.\n * - Archive the target with reason code `\"consolidation-undo\"` so the\n * lifecycle ledger records the undo.\n * - Dry-run mode produces the same plan without touching disk.\n *\n * The helper is kept pure over `StorageManager` so the CLI can reuse it\n * without additional wiring, and tests can exercise the plan logic\n * directly.\n */\n\nimport path from \"node:path\";\nimport { mkdir, writeFile, access, realpath, lstat } from \"node:fs/promises\";\nimport { constants as fsConstants } from \"node:fs\";\nimport type { StorageManager } from \"./storage.js\";\nimport type { VersioningConfig } from \"./page-versioning.js\";\nimport { bumpMemoryCorpusVersionForDir } from \"./memory-corpus-version.js\";\nimport { getVersion } from \"./page-versioning.js\";\n\n/**\n * Outcome of restoring a single `derived_from` source.\n */\nexport interface ConsolidationUndoRestore {\n /** The raw `\"<relpath>:<version>\"` entry from `derived_from`. */\n entry: string;\n /** Absolute path where the source would be / was restored. */\n sourcePath: string;\n /** What actually happened. */\n outcome:\n | \"restored\"\n | \"skipped_file_exists\"\n | \"skipped_non_regular_file\"\n | \"skipped_snapshot_missing\"\n | \"skipped_malformed_entry\"\n | \"skipped_outside_memory_dir\"\n | \"skipped_non_active_path\"\n | \"skipped_self_referential\"\n | \"skipped_write_failed\"\n | \"skipped_blocked_by_other_failures\"\n | \"skipped_dry_run\";\n /** Human-readable detail. */\n detail?: string;\n}\n\n/**\n * Plan + result of a `remnic consolidate undo` invocation.\n */\nexport interface ConsolidationUndoResult {\n /** Absolute path to the target memory. */\n targetPath: string;\n /** True when the target was archived successfully. */\n targetArchived: boolean;\n /** Per-source restore outcomes. */\n restores: ConsolidationUndoRestore[];\n /** Whether the run was a dry-run plan only. */\n dryRun: boolean;\n /** Fatal error, if any — the run bails early. */\n error?: string;\n}\n\nconst DERIVED_FROM_ENTRY_RE = /^(.+):(\\d+)$/;\n\nfunction parseEntry(entry: unknown): { pagePath: string; versionId: string } | null {\n // Non-string entries (PR #637 round-3 review, cursor Low) can arrive\n // from hostile on-disk frontmatter — guard against a .match() crash.\n if (typeof entry !== \"string\") return null;\n const match = entry.match(DERIVED_FROM_ENTRY_RE);\n if (!match) return null;\n return { pagePath: match[1], versionId: match[2] };\n}\n\n/**\n * Verify that `candidate` resolves inside `root` (defense against\n * path-traversal in `derived_from` entries and user-facing target\n * paths). Path-string normalization only; for symlink-aware checks\n * use `isInsideDirectoryRealpath`. Both paths are resolved to\n * absolute form before comparison so `..` segments, symlinks-as-\n * strings, and relative prefixes are normalized.\n */\nexport function isInsideDirectory(candidate: string, root: string): boolean {\n const normRoot = path.resolve(root);\n const normCandidate = path.resolve(candidate);\n const rel = path.relative(normRoot, normCandidate);\n if (rel.length === 0) return true;\n if (rel.startsWith(\"..\")) return false;\n if (path.isAbsolute(rel)) return false;\n return true;\n}\n\n/**\n * Symlink-aware containment check (PR #637 round-2 review, codex P1).\n *\n * `isInsideDirectory` only normalizes path strings — if a `derived_from`\n * entry resolves through a symlink inside `memoryDir` that points\n * outside, the string check passes but the subsequent `writeFile` would\n * land outside the memory tree. Use this guard for any path that is\n * about to be written.\n *\n * Walks every parent directory between `candidate` and `root`,\n * `realpath`-ing each segment that exists and rejecting when any\n * segment escapes `root`. Non-existent parents are resolved as the\n * canonicalized deepest-existing ancestor plus the trailing segments,\n * so a not-yet-created target file still gets the symlink check on its\n * existing parent directories.\n */\nexport async function isInsideDirectoryRealpath(\n candidate: string,\n root: string,\n): Promise<boolean> {\n if (!isInsideDirectory(candidate, root)) return false;\n // Reject raw `..` segments before canonicalization so that symlinks\n // cannot be hidden behind intermediate dot-dot components (PR #637\n // round-14 review, codex P1).\n const rawSegments = candidate.replace(/\\\\/g, \"/\").split(\"/\");\n if (rawSegments.some((s) => s === \"..\")) return false;\n let resolvedRoot: string;\n try {\n resolvedRoot = await realpath(path.resolve(root));\n } catch {\n return false;\n }\n const normCandidate = path.resolve(candidate);\n\n // Reject dangling symlinks (PR #637 round-3 review, codex P1).\n // If the candidate itself is a symlink (even if its target doesn't\n // exist), Node will follow it when we later call `writeFile`.\n // `lstat` inspects the link itself without dereferencing; if it\n // succeeds and reports a symlink, we treat the candidate as\n // unsafe. We must check every non-root ancestor too — a symlink\n // anywhere along the path lets an attacker redirect writes.\n const normRoot = path.resolve(root);\n const relFromRoot = path.relative(normRoot, normCandidate);\n const segments = relFromRoot.length > 0 ? relFromRoot.split(path.sep) : [];\n for (let i = 0; i <= segments.length; i++) {\n const probe = i === 0 ? normRoot : path.join(normRoot, ...segments.slice(0, i));\n try {\n const st = await lstat(probe);\n if (st.isSymbolicLink() && probe !== normRoot) {\n // A symlink on the path — resolve THIS segment and bail out\n // if the resolved target escapes `resolvedRoot`.\n let target: string;\n try {\n target = await realpath(probe);\n } catch {\n // Dangling symlink inside memoryDir — always unsafe.\n return false;\n }\n const rel = path.relative(resolvedRoot, target);\n if (rel.length === 0) continue;\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) return false;\n }\n } catch {\n // Segment doesn't exist yet — that's fine, fall through to the\n // textual containment verification below.\n }\n }\n\n // Walk up from the candidate until we hit a path that exists, then\n // realpath THAT and re-apply the trailing segments textually.\n const parts = normCandidate.split(path.sep);\n for (let i = parts.length; i > 0; i--) {\n const probe = parts.slice(0, i).join(path.sep) || path.sep;\n try {\n const resolved = await realpath(probe);\n // Re-join any trailing segments that didn't exist yet.\n const trailing = parts.slice(i).join(path.sep);\n const final = trailing.length > 0 ? path.join(resolved, trailing) : resolved;\n // Now apply the textual containment check against the canonical\n // `resolvedRoot`.\n const rel = path.relative(resolvedRoot, final);\n if (rel.length === 0) return true;\n if (rel.startsWith(\"..\")) return false;\n if (path.isAbsolute(rel)) return false;\n return true;\n } catch {\n continue;\n }\n }\n // Nothing along the path resolvable — treat as outside by default.\n return false;\n}\n\n/**\n * Directories under memoryDir that are NOT active memory locations.\n * A `derived_from` entry pointing into one of these should not be\n * counted as \"recovered_existing\" (PR #637 round-7 review, codex P2).\n * The versioning sidecar directory is included dynamically via the\n * `sidecarDir` parameter (PR #637 round-8 review, codex P2).\n */\nconst NON_ACTIVE_PREFIXES = [\"archive/\", \"state/\"];\n\n/**\n * Normalize a relative path by collapsing `.` and `..` segments so\n * that crafted entries like `\"facts/../archive/x.md\"` are reduced to\n * `\"archive/x.md\"` before the non-active-prefix check.\n */\nfunction normalizeRelativePath(p: string): string {\n // Normalize separators, split into segments, then resolve.\n const parts = p.replace(/\\\\/g, \"/\").split(\"/\");\n const resolved: string[] = [];\n for (const seg of parts) {\n if (seg === \"\" || seg === \".\") continue;\n if (seg === \"..\") {\n if (resolved.length > 0) resolved.pop();\n // If \"..\" pops past the root, we let the caller's containment\n // check catch it — don't silently drop.\n } else {\n resolved.push(seg);\n }\n }\n return resolved.join(\"/\");\n}\n\n/**\n * Check that a relative path (relative to memoryDir) points to an\n * active memory location rather than an internal/archive directory.\n * Returns `true` when the normalised `pagePath` does NOT start with\n * a known non-active prefix.\n *\n * @param pagePath Relative path from `derived_from` entry.\n * @param sidecarDir Optional versioning sidecar directory name\n * (e.g. `\".versions\"`). When provided, paths\n * under this directory are also rejected as\n * non-active.\n */\nexport function isActiveMemoryRelativePath(\n pagePath: string,\n sidecarDir?: string,\n): boolean {\n const normalized = normalizeRelativePath(pagePath);\n const prefixes = [...NON_ACTIVE_PREFIXES];\n if (sidecarDir) {\n const normSidecar = normalizeRelativePath(sidecarDir);\n prefixes.push(normSidecar + \"/\");\n }\n for (const prefix of prefixes) {\n if (normalized === prefix.slice(0, -1) || normalized.startsWith(prefix)) {\n return false;\n }\n }\n return true;\n}\n\nasync function isRegularFile(p: string): Promise<boolean> {\n try {\n const st = await lstat(p);\n return st.isFile();\n } catch {\n return false;\n }\n}\n\nasync function fileExists(p: string): Promise<boolean> {\n try {\n await access(p, fsConstants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Perform a consolidation-undo operation.\n *\n * @param options.storage Storage manager for the memory directory.\n * @param options.memoryDir Absolute memory directory root.\n * @param options.targetPath Absolute path to the consolidated memory.\n * @param options.versioning Page-versioning config (sidecarDir must\n * match the sidecar layout used when the\n * snapshots were created).\n * @param options.dryRun When true, compute the plan but do not\n * write or archive.\n */\nexport async function runConsolidationUndo(options: {\n storage: StorageManager;\n memoryDir: string;\n targetPath: string;\n versioning: VersioningConfig;\n dryRun?: boolean;\n}): Promise<ConsolidationUndoResult> {\n const { storage, memoryDir, targetPath, versioning } = options;\n const dryRun = options.dryRun === true;\n\n const result: ConsolidationUndoResult = {\n targetPath,\n targetArchived: false,\n restores: [],\n dryRun,\n };\n\n // Defense against path-traversal (PR #637 review, codex P1): refuse\n // to operate on a target outside the configured memory directory.\n // Archive moves and eventual unlink would otherwise let an operator\n // accidentally destroy an unrelated file with memory-like\n // frontmatter. Uses the realpath-aware check so a symlinked\n // directory inside `memoryDir` can't tunnel a target past the guard.\n if (!(await isInsideDirectoryRealpath(targetPath, memoryDir))) {\n result.error = `target path ${targetPath} is outside memory directory ${memoryDir}`;\n return result;\n }\n\n // Reject targets in non-active directories (archive/, state/,\n // versioning sidecar). A target inside `.versions/...` would be\n // a sidecar snapshot, not a real consolidated memory; archiving\n // it would silently delete version history (PR #637 round-8\n // review, codex P2).\n const targetRel = path.relative(memoryDir, targetPath);\n if (!isActiveMemoryRelativePath(targetRel, versioning.sidecarDir)) {\n result.error = `target path \"${targetRel}\" is inside a non-active directory — refusing to operate`;\n return result;\n }\n\n // Load the target memory. readMemoryByPath returns null when the file\n // is absent or unparseable — surface that as a fatal error because the\n // caller cannot continue without a derived_from list.\n const target = await storage.readMemoryByPath(targetPath);\n if (!target) {\n result.error = `could not load target memory at ${targetPath}`;\n return result;\n }\n\n const derivedFrom = target.frontmatter.derived_from;\n if (!Array.isArray(derivedFrom) || derivedFrom.length === 0) {\n result.error = \"target memory has no derived_from entries — nothing to undo\";\n return result;\n }\n\n // Two-pass plan + execute (PR #637 round-4 review, cursor Medium):\n // the undo is \"all-or-nothing\" both for the archive decision AND\n // for the per-source writes. First pass validates + loads every\n // snapshot into memory; second pass writes only if every source\n // would succeed. This prevents the previous eager-write behaviour\n // where a later-failing source would leave earlier sources already\n // written to disk alongside an unarchived consolidated target.\n type RestorePlan =\n | { kind: \"skip\"; restore: ConsolidationUndoRestore }\n | { kind: \"write\"; entry: string; sourcePath: string; content: string }\n | { kind: \"recovered_existing\"; entry: string; sourcePath: string };\n\n const plans: RestorePlan[] = [];\n for (const rawEntry of derivedFrom) {\n const entry = typeof rawEntry === \"string\" ? rawEntry : String(rawEntry);\n const parsed = parseEntry(rawEntry);\n if (!parsed) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath: \"\",\n outcome: \"skipped_malformed_entry\",\n detail: `expected \"<path>:<version>\" shape`,\n },\n });\n continue;\n }\n\n // Reject absolute paths in derived_from entries (PR #637 round-10\n // review, codex P1). An absolute pagePath would cause path.join to\n // ignore memoryDir, bypassing the active-directory guard downstream.\n if (path.isAbsolute(parsed.pagePath)) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath: parsed.pagePath,\n outcome: \"skipped_malformed_entry\",\n detail: `derived_from path must be relative, got absolute: \"${parsed.pagePath}\"`,\n },\n });\n continue;\n }\n\n const sourcePath = path.join(memoryDir, parsed.pagePath);\n\n if (!(await isInsideDirectoryRealpath(sourcePath, memoryDir))) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_outside_memory_dir\",\n detail: `resolved path escapes memory directory ${memoryDir}`,\n },\n });\n continue;\n }\n\n // Reject source paths inside non-active directories (archive/,\n // state/, versioning sidecar). A crafted or corrupted derived_from\n // entry like \"archive/2024-01-01/x.md:1\" would otherwise be counted\n // as \"recovered_existing\" even though no active memory was restored.\n // Also resolve symlinks before checking — a derived_from entry like\n // \"facts/link/stale.md:1\" where `facts/link` points to `archive/…`\n // must be caught (PR #637 round-8 review, cursor+codex).\n let resolvedRelative = parsed.pagePath;\n try {\n const realBase = await realpath(memoryDir);\n try {\n const realSource = await realpath(sourcePath);\n const rel = path.relative(realBase, realSource);\n if (!rel.startsWith(\"..\") && !path.isAbsolute(rel)) {\n resolvedRelative = rel.replace(/\\\\/g, \"/\");\n }\n } catch {\n // realpath on the leaf failed (file doesn't exist yet). Try\n // resolving the parent directory instead — if the parent is a\n // symlink into archive/state, the leaf would be written there\n // too (PR #637 round-12 review, codex P1).\n const parentDir = path.dirname(sourcePath);\n try {\n const realParent = await realpath(parentDir);\n const parentRel = path.relative(realBase, realParent);\n if (!parentRel.startsWith(\"..\") && !path.isAbsolute(parentRel)) {\n const leafName = path.basename(sourcePath);\n resolvedRelative = path.join(parentRel, leafName).replace(/\\\\/g, \"/\");\n }\n } catch {\n // Parent also doesn't exist — fall through to text path check\n }\n }\n } catch {\n // memoryDir realpath failed — use the text path\n }\n if (!isActiveMemoryRelativePath(parsed.pagePath, versioning.sidecarDir) ||\n !isActiveMemoryRelativePath(resolvedRelative, versioning.sidecarDir)) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_non_active_path\",\n detail: `source path \"${parsed.pagePath}\" is inside a non-active directory (archive/state/versions)`,\n },\n });\n continue;\n }\n\n // Reject self-referential derived_from entries (PR #637 round-9 review,\n // codex P1). If the source resolves to the same file as the target,\n // counting it as \"recovered\" would let undo archive the target without\n // restoring any independent source — leaving no active copy. This\n // guards against corrupted or manually-edited derived_from lists.\n if (path.resolve(sourcePath) === path.resolve(targetPath)) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_self_referential\",\n detail: `derived_from entry \"${entry}\" resolves to the same file as the target — refusing to count as recovered`,\n },\n });\n continue;\n }\n\n if (await isRegularFile(sourcePath)) {\n // Source is still active (regular file present) — nothing to\n // restore but this counts as \"recovered\" for the archive\n // decision. We require a regular file specifically (PR #637\n // round-5 review, codex P2): a directory, device node, or\n // symlink at the source path should not count as \"recovered\"\n // because a later read won't find the expected memory content.\n plans.push({ kind: \"recovered_existing\", entry, sourcePath });\n continue;\n }\n if (await fileExists(sourcePath)) {\n // Something other than a regular file is at the source path\n // (directory, device node, symlink). Refuse to overwrite AND\n // refuse to count as recovered (PR #637 round-5 review, codex\n // P2) — the operator needs to clean up manually. This is a\n // blocking skip: no source writes happen, target stays active.\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_non_regular_file\",\n detail: \"source path is occupied by a non-regular-file; refusing to proceed\",\n },\n });\n continue;\n }\n\n let snapshotContent: string;\n try {\n snapshotContent = await getVersion(\n sourcePath,\n parsed.versionId,\n versioning,\n memoryDir,\n );\n } catch {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_snapshot_missing\",\n detail: `no snapshot for version ${parsed.versionId}`,\n },\n });\n continue;\n }\n\n plans.push({ kind: \"write\", entry, sourcePath, content: snapshotContent });\n }\n\n // If any plan is a skip (anything other than \"write\" or\n // \"recovered_existing\"), the undo is over before it starts — no\n // writes happen. Reveal every per-source skip reason in the\n // result so operators can diagnose what went wrong.\n const skipped = plans.filter((p) => p.kind === \"skip\");\n if (skipped.length > 0) {\n for (const p of plans) {\n if (p.kind === \"skip\") {\n result.restores.push(p.restore);\n } else if (p.kind === \"write\") {\n // Announced-but-not-executed write — still record it so the\n // operator sees what would have been restored if the failed\n // sources had been recoverable.\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: dryRun ? \"skipped_dry_run\" : \"skipped_blocked_by_other_failures\",\n detail: dryRun\n ? \"would restore from snapshot (blocked by other failures)\"\n : \"snapshot available but undo aborted due to other failures\",\n });\n } else {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"source file already exists; no restore needed\",\n });\n }\n }\n const recovered = result.restores.filter(\n (r) => r.outcome === \"restored\" || r.outcome === \"skipped_file_exists\",\n ).length;\n if (recovered === 0) {\n result.error =\n \"no sources could be recovered (all snapshots missing or paths unsafe); target not archived to preserve data\";\n } else {\n result.error = `${skipped.length} of ${plans.length} sources could not be recovered; target not archived (undo is all-or-nothing)`;\n }\n return result;\n }\n\n // Deduplicate plans by sourcePath: duplicate derived_from entries for\n // the same source would cause the second wx-flagged write to fail with\n // EEXIST after the first succeeds. The first plan for each source wins;\n // subsequent duplicates are recorded as skipped. Applied before dry-run\n // so the preview accurately reflects what execution would do.\n const seenSourcePaths = new Set<string>();\n const dedupedPlans: RestorePlan[] = [];\n for (const p of plans) {\n if (p.kind === \"write\" || p.kind === \"recovered_existing\") {\n if (seenSourcePaths.has(p.sourcePath)) {\n dedupedPlans.push({\n kind: \"skip\",\n restore: {\n entry: p.kind === \"write\" ? p.entry : p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"duplicate derived_from entry — source already processed\",\n },\n });\n continue;\n }\n seenSourcePaths.add(p.sourcePath);\n }\n dedupedPlans.push(p);\n }\n\n // Dry-run: report what each plan would do.\n if (dryRun) {\n for (const p of dedupedPlans) {\n if (p.kind === \"write\") {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_dry_run\",\n detail: \"would restore from snapshot\",\n });\n } else if (p.kind === \"recovered_existing\") {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"source file already exists; no restore needed\",\n });\n } else if (p.kind === \"skip\" && p.restore) {\n result.restores.push(p.restore);\n }\n }\n return result;\n }\n\n // All validations passed — execute writes. A write failure here\n // is a filesystem problem rather than a provenance problem, but\n // any failure still aborts the archive.\n\n let writeFailed = false;\n for (const p of dedupedPlans) {\n if (p.kind === \"skip\") {\n // Dedup-generated skip entries and other pre-write skips.\n if (p.restore) result.restores.push(p.restore);\n continue;\n }\n if (p.kind === \"recovered_existing\") {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"source file already exists; no restore needed\",\n });\n continue;\n }\n if (p.kind === \"write\") {\n if (writeFailed) {\n // All-or-nothing: once a write fails, skip all remaining writes\n // so the target is not archived with partial source coverage.\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_blocked_by_other_failures\",\n detail: \"a prior source write failed; skipping remaining writes to honor all-or-nothing contract\",\n });\n continue;\n }\n try {\n await mkdir(path.dirname(p.sourcePath), { recursive: true });\n // Use exclusive create (wx / O_EXCL) so that if another process\n // recreates the source file between planning and execution, this\n // write fails with EEXIST instead of silently overwriting the new\n // file (PR #637 round-11 review, codex P1).\n await writeFile(p.sourcePath, p.content, { encoding: \"utf-8\", flag: \"wx\" });\n // Restore writes an active memory file back out-of-band (direct wx write,\n // not a StorageManager mutation). Bump the corpus sentinel per successful\n // restore so a warm hot-memories cache rescans — a later restore failure\n // returns before archiveMemory() runs, so without this the already-written\n // restores would stay invisible to recall until an unrelated mutation or\n // restart (esp. with hotMemoriesCacheTtlMs: 0). Issue #1902, Codex Medium.\n bumpMemoryCorpusVersionForDir(memoryDir);\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"restored\",\n });\n } catch (err) {\n writeFailed = true;\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_write_failed\",\n detail: `write failed: ${err instanceof Error ? err.message : String(err)}`,\n });\n }\n }\n }\n\n if (writeFailed) {\n result.error =\n \"one or more source writes failed mid-restore; target not archived to preserve data\";\n return result;\n }\n\n // Archive the target memory. archiveMemory returns null on\n // failure — surface that as a fatal error (PR #637 round-5 review,\n // codex P2) so automation doesn't mistake a half-undo for a clean\n // run. The already-completed restores still roll forward; the\n // result.restores list records what was written.\n const archivedAt = await storage.archiveMemory(target, {\n actor: \"consolidate-undo\",\n reasonCode: \"consolidation-undo\",\n });\n result.targetArchived = archivedAt !== null;\n if (!result.targetArchived) {\n result.error =\n \"sources restored successfully but archiving the consolidated target failed; inspect storage for manual cleanup\";\n }\n return result;\n}\n\n/**\n * Render a consolidation-undo result as a human-readable multi-line\n * string for the CLI. Extracted so tests can snapshot the formatting\n * without parsing stdout.\n */\nexport function formatConsolidationUndoResult(result: ConsolidationUndoResult): string {\n const lines: string[] = [];\n lines.push(`consolidate undo ${result.dryRun ? \"(dry run) \" : \"\"}→ ${result.targetPath}`);\n // Emit per-restore details BEFORE the error (PR #637 review, cursor\n // Medium): the \"no sources could be recovered\" error is set after\n // the restore loop ran, so operators need the per-source skip\n // reasons to diagnose which snapshots were missing / outside\n // memoryDir / malformed. Early-bail errors (unloadable target,\n // target outside memoryDir, no derived_from) run before the loop,\n // so `result.restores` is empty in those cases and this block is a\n // no-op.\n for (const r of result.restores) {\n lines.push(` - ${r.entry} → ${r.outcome}${r.detail ? ` (${r.detail})` : \"\"}`);\n }\n if (result.error) {\n lines.push(` ERROR: ${result.error}`);\n return lines.join(\"\\n\");\n }\n lines.push(\n result.dryRun\n ? \" (dry run — no files were modified, target not archived)\"\n : ` target archived: ${result.targetArchived ? \"yes\" : \"no\"}`,\n );\n return lines.join(\"\\n\");\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,OAAO,UAAU;AACjB,SAAS,OAAO,WAAW,QAAQ,UAAU,aAAa;AAC1D,SAAS,aAAa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,MAAM,EAAE,EAAE;AAAA,EAC/E;AACA,MAAI,OAAO,OAAO;AAChB,UAAM,KAAK,YAAY,OAAO,KAAK,EAAE;AACrC,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB;AACA,QAAM;AAAA,IACJ,OAAO,SACH,mEACA,sBAAsB,OAAO,iBAAiB,QAAQ,IAAI;AAAA,EAChE;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
1
+ {"version":3,"sources":["../src/consolidation-undo.ts"],"sourcesContent":["/**\n * Consolidation undo (issue #561 PR 5).\n *\n * Reverts a consolidated memory by restoring each source memory from its\n * `derived_from` snapshot and archiving the target.\n *\n * Contract:\n * - Load the target memory markdown file via its absolute path.\n * - For every `\"<rel>:<version>\"` entry in `derived_from`, fetch the\n * snapshot content via `page-versioning.getVersion` and restore it\n * to the original relative path. If the restore target file\n * already exists, we skip overwriting it (the source was never\n * archived, or was re-created since) and record the skip.\n * - Archive the target with reason code `\"consolidation-undo\"` so the\n * lifecycle ledger records the undo.\n * - Dry-run mode produces the same plan without touching disk.\n *\n * The helper is kept pure over `StorageManager` so the CLI can reuse it\n * without additional wiring, and tests can exercise the plan logic\n * directly.\n */\n\nimport path from \"node:path\";\nimport { mkdir, writeFile, access, realpath, lstat } from \"node:fs/promises\";\nimport { constants as fsConstants } from \"node:fs\";\nimport type { StorageManager } from \"./storage.js\";\nimport type { VersioningConfig } from \"./page-versioning.js\";\nimport { bumpMemoryCorpusVersionForDir } from \"./memory-corpus-version.js\";\nimport { requestEntityCanonicalIdReconcile } from \"./storage/entity-canonical-id-references.js\";\nimport { getVersion } from \"./page-versioning.js\";\n\n/**\n * Outcome of restoring a single `derived_from` source.\n */\nexport interface ConsolidationUndoRestore {\n /** The raw `\"<relpath>:<version>\"` entry from `derived_from`. */\n entry: string;\n /** Absolute path where the source would be / was restored. */\n sourcePath: string;\n /** What actually happened. */\n outcome:\n | \"restored\"\n | \"skipped_file_exists\"\n | \"skipped_non_regular_file\"\n | \"skipped_snapshot_missing\"\n | \"skipped_malformed_entry\"\n | \"skipped_outside_memory_dir\"\n | \"skipped_non_active_path\"\n | \"skipped_self_referential\"\n | \"skipped_write_failed\"\n | \"skipped_blocked_by_other_failures\"\n | \"skipped_dry_run\";\n /** Human-readable detail. */\n detail?: string;\n}\n\n/**\n * Plan + result of a `remnic consolidate undo` invocation.\n */\nexport interface ConsolidationUndoResult {\n /** Absolute path to the target memory. */\n targetPath: string;\n /** True when the target was archived successfully. */\n targetArchived: boolean;\n /** Per-source restore outcomes. */\n restores: ConsolidationUndoRestore[];\n /** Whether the run was a dry-run plan only. */\n dryRun: boolean;\n /** Fatal error, if any — the run bails early. */\n error?: string;\n}\n\nconst DERIVED_FROM_ENTRY_RE = /^(.+):(\\d+)$/;\n\nfunction parseEntry(entry: unknown): { pagePath: string; versionId: string } | null {\n // Non-string entries (PR #637 round-3 review, cursor Low) can arrive\n // from hostile on-disk frontmatter — guard against a .match() crash.\n if (typeof entry !== \"string\") return null;\n const match = entry.match(DERIVED_FROM_ENTRY_RE);\n if (!match) return null;\n return { pagePath: match[1], versionId: match[2] };\n}\n\n/**\n * Verify that `candidate` resolves inside `root` (defense against\n * path-traversal in `derived_from` entries and user-facing target\n * paths). Path-string normalization only; for symlink-aware checks\n * use `isInsideDirectoryRealpath`. Both paths are resolved to\n * absolute form before comparison so `..` segments, symlinks-as-\n * strings, and relative prefixes are normalized.\n */\nexport function isInsideDirectory(candidate: string, root: string): boolean {\n const normRoot = path.resolve(root);\n const normCandidate = path.resolve(candidate);\n const rel = path.relative(normRoot, normCandidate);\n if (rel.length === 0) return true;\n if (rel.startsWith(\"..\")) return false;\n if (path.isAbsolute(rel)) return false;\n return true;\n}\n\n/**\n * Symlink-aware containment check (PR #637 round-2 review, codex P1).\n *\n * `isInsideDirectory` only normalizes path strings — if a `derived_from`\n * entry resolves through a symlink inside `memoryDir` that points\n * outside, the string check passes but the subsequent `writeFile` would\n * land outside the memory tree. Use this guard for any path that is\n * about to be written.\n *\n * Walks every parent directory between `candidate` and `root`,\n * `realpath`-ing each segment that exists and rejecting when any\n * segment escapes `root`. Non-existent parents are resolved as the\n * canonicalized deepest-existing ancestor plus the trailing segments,\n * so a not-yet-created target file still gets the symlink check on its\n * existing parent directories.\n */\nexport async function isInsideDirectoryRealpath(\n candidate: string,\n root: string,\n): Promise<boolean> {\n if (!isInsideDirectory(candidate, root)) return false;\n // Reject raw `..` segments before canonicalization so that symlinks\n // cannot be hidden behind intermediate dot-dot components (PR #637\n // round-14 review, codex P1).\n const rawSegments = candidate.replace(/\\\\/g, \"/\").split(\"/\");\n if (rawSegments.some((s) => s === \"..\")) return false;\n let resolvedRoot: string;\n try {\n resolvedRoot = await realpath(path.resolve(root));\n } catch {\n return false;\n }\n const normCandidate = path.resolve(candidate);\n\n // Reject dangling symlinks (PR #637 round-3 review, codex P1).\n // If the candidate itself is a symlink (even if its target doesn't\n // exist), Node will follow it when we later call `writeFile`.\n // `lstat` inspects the link itself without dereferencing; if it\n // succeeds and reports a symlink, we treat the candidate as\n // unsafe. We must check every non-root ancestor too — a symlink\n // anywhere along the path lets an attacker redirect writes.\n const normRoot = path.resolve(root);\n const relFromRoot = path.relative(normRoot, normCandidate);\n const segments = relFromRoot.length > 0 ? relFromRoot.split(path.sep) : [];\n for (let i = 0; i <= segments.length; i++) {\n const probe = i === 0 ? normRoot : path.join(normRoot, ...segments.slice(0, i));\n try {\n const st = await lstat(probe);\n if (st.isSymbolicLink() && probe !== normRoot) {\n // A symlink on the path — resolve THIS segment and bail out\n // if the resolved target escapes `resolvedRoot`.\n let target: string;\n try {\n target = await realpath(probe);\n } catch {\n // Dangling symlink inside memoryDir — always unsafe.\n return false;\n }\n const rel = path.relative(resolvedRoot, target);\n if (rel.length === 0) continue;\n if (rel.startsWith(\"..\") || path.isAbsolute(rel)) return false;\n }\n } catch {\n // Segment doesn't exist yet — that's fine, fall through to the\n // textual containment verification below.\n }\n }\n\n // Walk up from the candidate until we hit a path that exists, then\n // realpath THAT and re-apply the trailing segments textually.\n const parts = normCandidate.split(path.sep);\n for (let i = parts.length; i > 0; i--) {\n const probe = parts.slice(0, i).join(path.sep) || path.sep;\n try {\n const resolved = await realpath(probe);\n // Re-join any trailing segments that didn't exist yet.\n const trailing = parts.slice(i).join(path.sep);\n const final = trailing.length > 0 ? path.join(resolved, trailing) : resolved;\n // Now apply the textual containment check against the canonical\n // `resolvedRoot`.\n const rel = path.relative(resolvedRoot, final);\n if (rel.length === 0) return true;\n if (rel.startsWith(\"..\")) return false;\n if (path.isAbsolute(rel)) return false;\n return true;\n } catch {\n continue;\n }\n }\n // Nothing along the path resolvable — treat as outside by default.\n return false;\n}\n\n/**\n * Directories under memoryDir that are NOT active memory locations.\n * A `derived_from` entry pointing into one of these should not be\n * counted as \"recovered_existing\" (PR #637 round-7 review, codex P2).\n * The versioning sidecar directory is included dynamically via the\n * `sidecarDir` parameter (PR #637 round-8 review, codex P2).\n */\nconst NON_ACTIVE_PREFIXES = [\"archive/\", \"state/\"];\n\n/**\n * Normalize a relative path by collapsing `.` and `..` segments so\n * that crafted entries like `\"facts/../archive/x.md\"` are reduced to\n * `\"archive/x.md\"` before the non-active-prefix check.\n */\nfunction normalizeRelativePath(p: string): string {\n // Normalize separators, split into segments, then resolve.\n const parts = p.replace(/\\\\/g, \"/\").split(\"/\");\n const resolved: string[] = [];\n for (const seg of parts) {\n if (seg === \"\" || seg === \".\") continue;\n if (seg === \"..\") {\n if (resolved.length > 0) resolved.pop();\n // If \"..\" pops past the root, we let the caller's containment\n // check catch it — don't silently drop.\n } else {\n resolved.push(seg);\n }\n }\n return resolved.join(\"/\");\n}\n\n/**\n * Check that a relative path (relative to memoryDir) points to an\n * active memory location rather than an internal/archive directory.\n * Returns `true` when the normalised `pagePath` does NOT start with\n * a known non-active prefix.\n *\n * @param pagePath Relative path from `derived_from` entry.\n * @param sidecarDir Optional versioning sidecar directory name\n * (e.g. `\".versions\"`). When provided, paths\n * under this directory are also rejected as\n * non-active.\n */\nexport function isActiveMemoryRelativePath(\n pagePath: string,\n sidecarDir?: string,\n): boolean {\n const normalized = normalizeRelativePath(pagePath);\n const prefixes = [...NON_ACTIVE_PREFIXES];\n if (sidecarDir) {\n const normSidecar = normalizeRelativePath(sidecarDir);\n prefixes.push(normSidecar + \"/\");\n }\n for (const prefix of prefixes) {\n if (normalized === prefix.slice(0, -1) || normalized.startsWith(prefix)) {\n return false;\n }\n }\n return true;\n}\n\nasync function isRegularFile(p: string): Promise<boolean> {\n try {\n const st = await lstat(p);\n return st.isFile();\n } catch {\n return false;\n }\n}\n\nasync function fileExists(p: string): Promise<boolean> {\n try {\n await access(p, fsConstants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Perform a consolidation-undo operation.\n *\n * @param options.storage Storage manager for the memory directory.\n * @param options.memoryDir Absolute memory directory root.\n * @param options.targetPath Absolute path to the consolidated memory.\n * @param options.versioning Page-versioning config (sidecarDir must\n * match the sidecar layout used when the\n * snapshots were created).\n * @param options.dryRun When true, compute the plan but do not\n * write or archive.\n */\nexport async function runConsolidationUndo(options: {\n storage: StorageManager;\n memoryDir: string;\n targetPath: string;\n versioning: VersioningConfig;\n dryRun?: boolean;\n}): Promise<ConsolidationUndoResult> {\n const { storage, memoryDir, targetPath, versioning } = options;\n const dryRun = options.dryRun === true;\n\n const result: ConsolidationUndoResult = {\n targetPath,\n targetArchived: false,\n restores: [],\n dryRun,\n };\n\n // Defense against path-traversal (PR #637 review, codex P1): refuse\n // to operate on a target outside the configured memory directory.\n // Archive moves and eventual unlink would otherwise let an operator\n // accidentally destroy an unrelated file with memory-like\n // frontmatter. Uses the realpath-aware check so a symlinked\n // directory inside `memoryDir` can't tunnel a target past the guard.\n if (!(await isInsideDirectoryRealpath(targetPath, memoryDir))) {\n result.error = `target path ${targetPath} is outside memory directory ${memoryDir}`;\n return result;\n }\n\n // Reject targets in non-active directories (archive/, state/,\n // versioning sidecar). A target inside `.versions/...` would be\n // a sidecar snapshot, not a real consolidated memory; archiving\n // it would silently delete version history (PR #637 round-8\n // review, codex P2).\n const targetRel = path.relative(memoryDir, targetPath);\n if (!isActiveMemoryRelativePath(targetRel, versioning.sidecarDir)) {\n result.error = `target path \"${targetRel}\" is inside a non-active directory — refusing to operate`;\n return result;\n }\n\n // Load the target memory. readMemoryByPath returns null when the file\n // is absent or unparseable — surface that as a fatal error because the\n // caller cannot continue without a derived_from list.\n const target = await storage.readMemoryByPath(targetPath);\n if (!target) {\n result.error = `could not load target memory at ${targetPath}`;\n return result;\n }\n\n const derivedFrom = target.frontmatter.derived_from;\n if (!Array.isArray(derivedFrom) || derivedFrom.length === 0) {\n result.error = \"target memory has no derived_from entries — nothing to undo\";\n return result;\n }\n\n // Two-pass plan + execute (PR #637 round-4 review, cursor Medium):\n // the undo is \"all-or-nothing\" both for the archive decision AND\n // for the per-source writes. First pass validates + loads every\n // snapshot into memory; second pass writes only if every source\n // would succeed. This prevents the previous eager-write behaviour\n // where a later-failing source would leave earlier sources already\n // written to disk alongside an unarchived consolidated target.\n type RestorePlan =\n | { kind: \"skip\"; restore: ConsolidationUndoRestore }\n | { kind: \"write\"; entry: string; sourcePath: string; content: string }\n | { kind: \"recovered_existing\"; entry: string; sourcePath: string };\n\n const plans: RestorePlan[] = [];\n for (const rawEntry of derivedFrom) {\n const entry = typeof rawEntry === \"string\" ? rawEntry : String(rawEntry);\n const parsed = parseEntry(rawEntry);\n if (!parsed) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath: \"\",\n outcome: \"skipped_malformed_entry\",\n detail: `expected \"<path>:<version>\" shape`,\n },\n });\n continue;\n }\n\n // Reject absolute paths in derived_from entries (PR #637 round-10\n // review, codex P1). An absolute pagePath would cause path.join to\n // ignore memoryDir, bypassing the active-directory guard downstream.\n if (path.isAbsolute(parsed.pagePath)) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath: parsed.pagePath,\n outcome: \"skipped_malformed_entry\",\n detail: `derived_from path must be relative, got absolute: \"${parsed.pagePath}\"`,\n },\n });\n continue;\n }\n\n const sourcePath = path.join(memoryDir, parsed.pagePath);\n\n if (!(await isInsideDirectoryRealpath(sourcePath, memoryDir))) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_outside_memory_dir\",\n detail: `resolved path escapes memory directory ${memoryDir}`,\n },\n });\n continue;\n }\n\n // Reject source paths inside non-active directories (archive/,\n // state/, versioning sidecar). A crafted or corrupted derived_from\n // entry like \"archive/2024-01-01/x.md:1\" would otherwise be counted\n // as \"recovered_existing\" even though no active memory was restored.\n // Also resolve symlinks before checking — a derived_from entry like\n // \"facts/link/stale.md:1\" where `facts/link` points to `archive/…`\n // must be caught (PR #637 round-8 review, cursor+codex).\n let resolvedRelative = parsed.pagePath;\n try {\n const realBase = await realpath(memoryDir);\n try {\n const realSource = await realpath(sourcePath);\n const rel = path.relative(realBase, realSource);\n if (!rel.startsWith(\"..\") && !path.isAbsolute(rel)) {\n resolvedRelative = rel.replace(/\\\\/g, \"/\");\n }\n } catch {\n // realpath on the leaf failed (file doesn't exist yet). Try\n // resolving the parent directory instead — if the parent is a\n // symlink into archive/state, the leaf would be written there\n // too (PR #637 round-12 review, codex P1).\n const parentDir = path.dirname(sourcePath);\n try {\n const realParent = await realpath(parentDir);\n const parentRel = path.relative(realBase, realParent);\n if (!parentRel.startsWith(\"..\") && !path.isAbsolute(parentRel)) {\n const leafName = path.basename(sourcePath);\n resolvedRelative = path.join(parentRel, leafName).replace(/\\\\/g, \"/\");\n }\n } catch {\n // Parent also doesn't exist — fall through to text path check\n }\n }\n } catch {\n // memoryDir realpath failed — use the text path\n }\n if (!isActiveMemoryRelativePath(parsed.pagePath, versioning.sidecarDir) ||\n !isActiveMemoryRelativePath(resolvedRelative, versioning.sidecarDir)) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_non_active_path\",\n detail: `source path \"${parsed.pagePath}\" is inside a non-active directory (archive/state/versions)`,\n },\n });\n continue;\n }\n\n // Reject self-referential derived_from entries (PR #637 round-9 review,\n // codex P1). If the source resolves to the same file as the target,\n // counting it as \"recovered\" would let undo archive the target without\n // restoring any independent source — leaving no active copy. This\n // guards against corrupted or manually-edited derived_from lists.\n if (path.resolve(sourcePath) === path.resolve(targetPath)) {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_self_referential\",\n detail: `derived_from entry \"${entry}\" resolves to the same file as the target — refusing to count as recovered`,\n },\n });\n continue;\n }\n\n if (await isRegularFile(sourcePath)) {\n // Source is still active (regular file present) — nothing to\n // restore but this counts as \"recovered\" for the archive\n // decision. We require a regular file specifically (PR #637\n // round-5 review, codex P2): a directory, device node, or\n // symlink at the source path should not count as \"recovered\"\n // because a later read won't find the expected memory content.\n plans.push({ kind: \"recovered_existing\", entry, sourcePath });\n continue;\n }\n if (await fileExists(sourcePath)) {\n // Something other than a regular file is at the source path\n // (directory, device node, symlink). Refuse to overwrite AND\n // refuse to count as recovered (PR #637 round-5 review, codex\n // P2) — the operator needs to clean up manually. This is a\n // blocking skip: no source writes happen, target stays active.\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_non_regular_file\",\n detail: \"source path is occupied by a non-regular-file; refusing to proceed\",\n },\n });\n continue;\n }\n\n let snapshotContent: string;\n try {\n snapshotContent = await getVersion(\n sourcePath,\n parsed.versionId,\n versioning,\n memoryDir,\n );\n } catch {\n plans.push({\n kind: \"skip\",\n restore: {\n entry,\n sourcePath,\n outcome: \"skipped_snapshot_missing\",\n detail: `no snapshot for version ${parsed.versionId}`,\n },\n });\n continue;\n }\n\n plans.push({ kind: \"write\", entry, sourcePath, content: snapshotContent });\n }\n\n // If any plan is a skip (anything other than \"write\" or\n // \"recovered_existing\"), the undo is over before it starts — no\n // writes happen. Reveal every per-source skip reason in the\n // result so operators can diagnose what went wrong.\n const skipped = plans.filter((p) => p.kind === \"skip\");\n if (skipped.length > 0) {\n for (const p of plans) {\n if (p.kind === \"skip\") {\n result.restores.push(p.restore);\n } else if (p.kind === \"write\") {\n // Announced-but-not-executed write — still record it so the\n // operator sees what would have been restored if the failed\n // sources had been recoverable.\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: dryRun ? \"skipped_dry_run\" : \"skipped_blocked_by_other_failures\",\n detail: dryRun\n ? \"would restore from snapshot (blocked by other failures)\"\n : \"snapshot available but undo aborted due to other failures\",\n });\n } else {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"source file already exists; no restore needed\",\n });\n }\n }\n const recovered = result.restores.filter(\n (r) => r.outcome === \"restored\" || r.outcome === \"skipped_file_exists\",\n ).length;\n if (recovered === 0) {\n result.error =\n \"no sources could be recovered (all snapshots missing or paths unsafe); target not archived to preserve data\";\n } else {\n result.error = `${skipped.length} of ${plans.length} sources could not be recovered; target not archived (undo is all-or-nothing)`;\n }\n return result;\n }\n\n // Deduplicate plans by sourcePath: duplicate derived_from entries for\n // the same source would cause the second wx-flagged write to fail with\n // EEXIST after the first succeeds. The first plan for each source wins;\n // subsequent duplicates are recorded as skipped. Applied before dry-run\n // so the preview accurately reflects what execution would do.\n const seenSourcePaths = new Set<string>();\n const dedupedPlans: RestorePlan[] = [];\n for (const p of plans) {\n if (p.kind === \"write\" || p.kind === \"recovered_existing\") {\n if (seenSourcePaths.has(p.sourcePath)) {\n dedupedPlans.push({\n kind: \"skip\",\n restore: {\n entry: p.kind === \"write\" ? p.entry : p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"duplicate derived_from entry — source already processed\",\n },\n });\n continue;\n }\n seenSourcePaths.add(p.sourcePath);\n }\n dedupedPlans.push(p);\n }\n\n // Dry-run: report what each plan would do.\n if (dryRun) {\n for (const p of dedupedPlans) {\n if (p.kind === \"write\") {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_dry_run\",\n detail: \"would restore from snapshot\",\n });\n } else if (p.kind === \"recovered_existing\") {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"source file already exists; no restore needed\",\n });\n } else if (p.kind === \"skip\" && p.restore) {\n result.restores.push(p.restore);\n }\n }\n return result;\n }\n\n // All validations passed — execute writes. A write failure here\n // is a filesystem problem rather than a provenance problem, but\n // any failure still aborts the archive.\n\n let writeFailed = false;\n for (const p of dedupedPlans) {\n if (p.kind === \"skip\") {\n // Dedup-generated skip entries and other pre-write skips.\n if (p.restore) result.restores.push(p.restore);\n continue;\n }\n if (p.kind === \"recovered_existing\") {\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_file_exists\",\n detail: \"source file already exists; no restore needed\",\n });\n continue;\n }\n if (p.kind === \"write\") {\n if (writeFailed) {\n // All-or-nothing: once a write fails, skip all remaining writes\n // so the target is not archived with partial source coverage.\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_blocked_by_other_failures\",\n detail: \"a prior source write failed; skipping remaining writes to honor all-or-nothing contract\",\n });\n continue;\n }\n try {\n await mkdir(path.dirname(p.sourcePath), { recursive: true });\n // Use exclusive create (wx / O_EXCL) so that if another process\n // recreates the source file between planning and execution, this\n // write fails with EEXIST instead of silently overwriting the new\n // file (PR #637 round-11 review, codex P1).\n await writeFile(p.sourcePath, p.content, { encoding: \"utf-8\", flag: \"wx\" });\n // Restore writes an active memory file back out-of-band (direct wx write,\n // not a StorageManager mutation). Bump the corpus sentinel per successful\n // restore so a warm hot-memories cache rescans — a later restore failure\n // returns before archiveMemory() runs, so without this the already-written\n // restores would stay invisible to recall until an unrelated mutation or\n // restart (esp. with hotMemoriesCacheTtlMs: 0). Issue #1902, Codex Medium.\n bumpMemoryCorpusVersionForDir(memoryDir);\n // Restored bytes predate the current migration journal and can carry\n // legacy entity references (issue #2213) — request one reconcile pass.\n await requestEntityCanonicalIdReconcile(path.join(memoryDir, \"state\"));\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"restored\",\n });\n } catch (err) {\n writeFailed = true;\n result.restores.push({\n entry: p.entry,\n sourcePath: p.sourcePath,\n outcome: \"skipped_write_failed\",\n detail: `write failed: ${err instanceof Error ? err.message : String(err)}`,\n });\n }\n }\n }\n\n if (writeFailed) {\n result.error =\n \"one or more source writes failed mid-restore; target not archived to preserve data\";\n return result;\n }\n\n // Archive the target memory. archiveMemory returns null on\n // failure — surface that as a fatal error (PR #637 round-5 review,\n // codex P2) so automation doesn't mistake a half-undo for a clean\n // run. The already-completed restores still roll forward; the\n // result.restores list records what was written.\n const archivedAt = await storage.archiveMemory(target, {\n actor: \"consolidate-undo\",\n reasonCode: \"consolidation-undo\",\n });\n result.targetArchived = archivedAt !== null;\n if (!result.targetArchived) {\n result.error =\n \"sources restored successfully but archiving the consolidated target failed; inspect storage for manual cleanup\";\n }\n return result;\n}\n\n/**\n * Render a consolidation-undo result as a human-readable multi-line\n * string for the CLI. Extracted so tests can snapshot the formatting\n * without parsing stdout.\n */\nexport function formatConsolidationUndoResult(result: ConsolidationUndoResult): string {\n const lines: string[] = [];\n lines.push(`consolidate undo ${result.dryRun ? \"(dry run) \" : \"\"}→ ${result.targetPath}`);\n // Emit per-restore details BEFORE the error (PR #637 review, cursor\n // Medium): the \"no sources could be recovered\" error is set after\n // the restore loop ran, so operators need the per-source skip\n // reasons to diagnose which snapshots were missing / outside\n // memoryDir / malformed. Early-bail errors (unloadable target,\n // target outside memoryDir, no derived_from) run before the loop,\n // so `result.restores` is empty in those cases and this block is a\n // no-op.\n for (const r of result.restores) {\n lines.push(` - ${r.entry} → ${r.outcome}${r.detail ? ` (${r.detail})` : \"\"}`);\n }\n if (result.error) {\n lines.push(` ERROR: ${result.error}`);\n return lines.join(\"\\n\");\n }\n lines.push(\n result.dryRun\n ? \" (dry run — no files were modified, target not archived)\"\n : ` target archived: ${result.targetArchived ? \"yes\" : \"no\"}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;AACzB,QAAM,KAAK,oBAAoB,OAAO,SAAS,eAAe,EAAE,UAAK,OAAO,UAAU,EAAE;AASxF,aAAW,KAAK,OAAO,UAAU;AAC/B,UAAM,KAAK,OAAO,EAAE,KAAK,WAAM,EAAE,OAAO,GAAG,EAAE,SAAS,KAAK,EAAE,MAAM,MAAM,EAAE,EAAE;AAAA,EAC/E;AACA,MAAI,OAAO,OAAO;AAChB,UAAM,KAAK,YAAY,OAAO,KAAK,EAAE;AACrC,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB;AACA,QAAM;AAAA,IACJ,OAAO,SACH,mEACA,sBAAsB,OAAO,iBAAiB,QAAQ,IAAI;AAAA,EAChE;AACA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
@@ -1,4 +1,4 @@
1
- import { S as StorageManager } from '../storage-CyWa1Jm6.js';
1
+ import { S as StorageManager } from '../storage-BbH4HDUS.js';
2
2
  import { x as MemoryStatus, P as PluginConfig, v as MemoryCategory } from '../types-5398p7Zm.js';
3
3
  import { S as SemanticDedupLookup } from '../semantic-TddhF0y7.js';
4
4
  import { LocalLlmClient } from '../local-llm.js';