@unbrained/pm-cli 2026.6.19 → 2026.6.21

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 (545) hide show
  1. package/CHANGELOG.md +328 -258
  2. package/README.md +1 -1
  3. package/dist/cli/bootstrap-args.d.ts +12 -1
  4. package/dist/cli/bootstrap-args.js +20 -9
  5. package/dist/cli/bootstrap-args.js.map +1 -1
  6. package/dist/cli/commander-usage.js +31 -25
  7. package/dist/cli/commander-usage.js.map +1 -1
  8. package/dist/cli/commands/completion.js +3 -3
  9. package/dist/cli/commands/completion.js.map +1 -1
  10. package/dist/cli/commands/contracts.js +4 -3
  11. package/dist/cli/commands/contracts.js.map +1 -1
  12. package/dist/cli/commands/eval.d.ts +62 -0
  13. package/dist/cli/commands/eval.js +158 -0
  14. package/dist/cli/commands/eval.js.map +1 -0
  15. package/dist/cli/commands/extension/install-sources.d.ts +12 -0
  16. package/dist/cli/commands/extension/install-sources.js +77 -10
  17. package/dist/cli/commands/extension/install-sources.js.map +1 -1
  18. package/dist/cli/commands/extension/scaffold.js +49 -3
  19. package/dist/cli/commands/extension/scaffold.js.map +1 -1
  20. package/dist/cli/commands/extension.js +9 -2
  21. package/dist/cli/commands/extension.js.map +1 -1
  22. package/dist/cli/commands/gc.d.ts +12 -1
  23. package/dist/cli/commands/gc.js +53 -6
  24. package/dist/cli/commands/gc.js.map +1 -1
  25. package/dist/cli/commands/health.js +27 -9
  26. package/dist/cli/commands/health.js.map +1 -1
  27. package/dist/cli/commands/index.d.ts +1 -0
  28. package/dist/cli/commands/index.js +3 -2
  29. package/dist/cli/commands/index.js.map +1 -1
  30. package/dist/cli/commands/linked-artifacts.js +13 -3
  31. package/dist/cli/commands/linked-artifacts.js.map +1 -1
  32. package/dist/cli/commands/list.js +12 -9
  33. package/dist/cli/commands/list.js.map +1 -1
  34. package/dist/cli/commands/plan.js +2 -2
  35. package/dist/cli/commands/plan.js.map +1 -1
  36. package/dist/cli/commands/restore.js +5 -11
  37. package/dist/cli/commands/restore.js.map +1 -1
  38. package/dist/cli/commands/search.d.ts +39 -1
  39. package/dist/cli/commands/search.js +89 -12
  40. package/dist/cli/commands/search.js.map +1 -1
  41. package/dist/cli/commands/update.js +96 -58
  42. package/dist/cli/commands/update.js.map +1 -1
  43. package/dist/cli/commands/validate.d.ts +1 -1
  44. package/dist/cli/commands/validate.js +44 -2
  45. package/dist/cli/commands/validate.js.map +1 -1
  46. package/dist/cli/extension-command-help.d.ts +9 -0
  47. package/dist/cli/extension-command-help.js +13 -2
  48. package/dist/cli/extension-command-help.js.map +1 -1
  49. package/dist/cli/extension-command-options.d.ts +8 -0
  50. package/dist/cli/extension-command-options.js +27 -2
  51. package/dist/cli/extension-command-options.js.map +1 -1
  52. package/dist/cli/help-content.js +15 -2
  53. package/dist/cli/help-content.js.map +1 -1
  54. package/dist/cli/main.d.ts +12 -0
  55. package/dist/cli/main.js +49 -9
  56. package/dist/cli/main.js.map +1 -1
  57. package/dist/cli/register-list-query.js +34 -4
  58. package/dist/cli/register-list-query.js.map +1 -1
  59. package/dist/cli/register-operations.js +3 -3
  60. package/dist/cli/register-operations.js.map +1 -1
  61. package/dist/cli-bundle/chunks/activity-CIHV64UC.js +18 -0
  62. package/dist/cli-bundle/chunks/{activity-XJ7WRNWS.js → activity-KW3IRP44.js} +11 -11
  63. package/dist/cli-bundle/chunks/{aggregate-LBCWF6UJ.js → aggregate-3ZKQG5SW.js} +10 -10
  64. package/dist/cli-bundle/chunks/{aggregate-OFT4YVB6.js → aggregate-FIGQEIL3.js} +10 -10
  65. package/dist/cli-bundle/chunks/{append-BP2ARHOK.js → append-EWJYJ7CH.js} +8 -8
  66. package/dist/cli-bundle/chunks/{append-5U3XR5SD.js → append-QEOLX3XB.js} +8 -8
  67. package/dist/cli-bundle/chunks/{chunk-CSRFOIHG.js → chunk-2EIMPCE4.js} +3 -3
  68. package/dist/cli-bundle/chunks/{chunk-MAKOMXVM.js → chunk-2GCDRRIF.js} +106 -67
  69. package/dist/cli-bundle/chunks/chunk-2GCDRRIF.js.map +1 -0
  70. package/dist/cli-bundle/chunks/{search-AZR2JITW.js → chunk-2PKHRP6G.js} +190 -22
  71. package/dist/cli-bundle/chunks/chunk-2PKHRP6G.js.map +7 -0
  72. package/dist/cli-bundle/chunks/{chunk-YWAYOWDQ.js → chunk-32R4PIC6.js} +118 -15
  73. package/dist/cli-bundle/chunks/chunk-32R4PIC6.js.map +1 -0
  74. package/dist/cli-bundle/chunks/{chunk-II3WDRCM.js → chunk-37QXHBIB.js} +3 -3
  75. package/dist/cli-bundle/chunks/{chunk-UCNEPMPY.js → chunk-3EWSGA7N.js} +105 -66
  76. package/dist/cli-bundle/chunks/chunk-3EWSGA7N.js.map +7 -0
  77. package/dist/cli-bundle/chunks/{chunk-UMTPQMEG.js → chunk-3MDHREEV.js} +3 -3
  78. package/dist/cli-bundle/chunks/{chunk-I2VJM36R.js → chunk-434HM6Z5.js} +21 -21
  79. package/dist/cli-bundle/chunks/chunk-434HM6Z5.js.map +1 -0
  80. package/dist/cli-bundle/chunks/{chunk-Y4IBSEQ2.js → chunk-52OCIDPG.js} +20 -8
  81. package/dist/cli-bundle/chunks/chunk-52OCIDPG.js.map +1 -0
  82. package/dist/cli-bundle/chunks/{chunk-DJ3YYLHG.js → chunk-5FIEHKEX.js} +5 -5
  83. package/dist/cli-bundle/chunks/{chunk-OURX4WVG.js → chunk-5IDI42VV.js} +7 -7
  84. package/dist/cli-bundle/chunks/{chunk-UA4ANRJY.js → chunk-5PCI3UBT.js} +119 -16
  85. package/dist/cli-bundle/chunks/chunk-5PCI3UBT.js.map +7 -0
  86. package/dist/cli-bundle/chunks/{chunk-RVG3WLY3.js → chunk-5QICDWMV.js} +2 -2
  87. package/dist/cli-bundle/chunks/{chunk-LIVRA6VG.js → chunk-6CJWZAN7.js} +7 -7
  88. package/dist/cli-bundle/chunks/{chunk-AVMSP2HH.js → chunk-6H4LF7AO.js} +2 -2
  89. package/dist/cli-bundle/chunks/{chunk-B2NEFANY.js → chunk-6M4RJS4M.js} +3 -3
  90. package/dist/cli-bundle/chunks/{chunk-4BFNWAMQ.js → chunk-6ZXM2XNF.js} +29 -12
  91. package/dist/cli-bundle/chunks/chunk-6ZXM2XNF.js.map +7 -0
  92. package/dist/cli-bundle/chunks/{chunk-A5JPMD4Q.js → chunk-76Z3YSHV.js} +2 -2
  93. package/dist/cli-bundle/chunks/{chunk-5NS6TJ2F.js → chunk-7D3SAQXM.js} +2 -2
  94. package/dist/cli-bundle/chunks/{chunk-DVUU3AHP.js → chunk-A4Z7ZOL5.js} +17 -6
  95. package/dist/cli-bundle/chunks/chunk-A4Z7ZOL5.js.map +1 -0
  96. package/dist/cli-bundle/chunks/{chunk-2E3KSWFG.js → chunk-AIS5PGI3.js} +2 -2
  97. package/dist/cli-bundle/chunks/{chunk-47BYN6CA.js → chunk-AZMOLBN3.js} +7 -7
  98. package/dist/cli-bundle/chunks/{chunk-DYZKSIVX.js → chunk-B473GZWW.js} +3 -3
  99. package/dist/cli-bundle/chunks/{chunk-RNWE2HZR.js → chunk-C3AZ5ZML.js} +15 -15
  100. package/dist/cli-bundle/chunks/{chunk-S673PVHD.js → chunk-C4N5I7ZW.js} +3 -3
  101. package/dist/cli-bundle/chunks/{chunk-TYQBGXH2.js → chunk-CF55WVVS.js} +2 -2
  102. package/dist/cli-bundle/chunks/{chunk-4EOS35RL.js → chunk-CZPXY7UW.js} +3 -3
  103. package/dist/cli-bundle/chunks/{chunk-MPEWACTG.js → chunk-CZUB4XWO.js} +2 -2
  104. package/dist/cli-bundle/chunks/{chunk-22YA6GCA.js → chunk-D7FYS6PG.js} +2 -2
  105. package/dist/cli-bundle/chunks/{chunk-5SRID7DV.js → chunk-EBH56IXK.js} +29 -12
  106. package/dist/cli-bundle/chunks/chunk-EBH56IXK.js.map +1 -0
  107. package/dist/cli-bundle/chunks/{chunk-UIMLAFOE.js → chunk-F5NZWFSW.js} +7 -7
  108. package/dist/cli-bundle/chunks/{chunk-PSWSQHM7.js → chunk-F7K5GWP3.js} +15 -19
  109. package/dist/cli-bundle/chunks/chunk-F7K5GWP3.js.map +1 -0
  110. package/dist/cli-bundle/chunks/{chunk-H3DP6OUM.js → chunk-FKBDKV7Y.js} +3 -3
  111. package/dist/cli-bundle/chunks/{chunk-SO2IOH37.js → chunk-FRUFKWNK.js} +2 -2
  112. package/dist/cli-bundle/chunks/{chunk-7R5YKVKO.js → chunk-FWPDUYEY.js} +7 -7
  113. package/dist/cli-bundle/chunks/{search-2JX776KX.js → chunk-GMHPNNYG.js} +184 -23
  114. package/dist/cli-bundle/chunks/chunk-GMHPNNYG.js.map +1 -0
  115. package/dist/cli-bundle/chunks/{chunk-USVOBLGB.js → chunk-GOZUHWFD.js} +2 -2
  116. package/dist/cli-bundle/chunks/{chunk-ZBVYKWT2.js → chunk-H7NJZWG2.js} +15 -15
  117. package/dist/cli-bundle/chunks/{chunk-FPQA4ZMA.js → chunk-HC4AWIKT.js} +18 -7
  118. package/dist/cli-bundle/chunks/chunk-HC4AWIKT.js.map +7 -0
  119. package/dist/cli-bundle/chunks/{chunk-4L7Q4OVT.js → chunk-HCU6WUSY.js} +9 -9
  120. package/dist/cli-bundle/chunks/{chunk-2RI3BDFK.js → chunk-HIP7WVTL.js} +10 -9
  121. package/dist/cli-bundle/chunks/chunk-HIP7WVTL.js.map +7 -0
  122. package/dist/cli-bundle/chunks/{chunk-5QLHQK7V.js → chunk-HMOADQVT.js} +26 -26
  123. package/dist/cli-bundle/chunks/chunk-HMOADQVT.js.map +7 -0
  124. package/dist/cli-bundle/chunks/{chunk-K5TD74VU.js → chunk-J4MYYSOL.js} +19 -7
  125. package/dist/cli-bundle/chunks/chunk-J4MYYSOL.js.map +7 -0
  126. package/dist/cli-bundle/chunks/{chunk-GDOTTY2S.js → chunk-JINYH2DB.js} +40 -2
  127. package/dist/cli-bundle/chunks/chunk-JINYH2DB.js.map +7 -0
  128. package/dist/cli-bundle/chunks/{chunk-EMFDZ7N3.js → chunk-LEU5GHRC.js} +55 -5
  129. package/dist/cli-bundle/chunks/chunk-LEU5GHRC.js.map +1 -0
  130. package/dist/cli-bundle/chunks/{chunk-PRUB7RI4.js → chunk-LUWW7L4B.js} +3 -3
  131. package/dist/cli-bundle/chunks/{chunk-N7LDJRB4.js → chunk-M5XALUSL.js} +2 -2
  132. package/dist/cli-bundle/chunks/{chunk-NPNNW5TU.js → chunk-N5ZJACJ6.js} +8 -8
  133. package/dist/cli-bundle/chunks/{chunk-NNMBNN6Q.js → chunk-NB3PYLQ6.js} +7 -5
  134. package/dist/cli-bundle/chunks/{chunk-USKTNI7P.js → chunk-NIGXMNNI.js} +2 -2
  135. package/dist/cli-bundle/chunks/{chunk-GL3QKIET.js → chunk-NIUEXCFS.js} +6 -6
  136. package/dist/cli-bundle/chunks/{chunk-OUG4CL4H.js → chunk-NJHMAJ6N.js} +8 -8
  137. package/dist/cli-bundle/chunks/{chunk-2K56AWDP.js → chunk-NJN7LL7U.js} +5 -5
  138. package/dist/cli-bundle/chunks/{chunk-5P2LQV2F.js → chunk-NSBZ2CKF.js} +2 -2
  139. package/dist/cli-bundle/chunks/{chunk-ZZEM2PH7.js → chunk-NXS7ZKAK.js} +19 -14
  140. package/dist/cli-bundle/chunks/chunk-NXS7ZKAK.js.map +1 -0
  141. package/dist/cli-bundle/chunks/{chunk-XV6N3QND.js → chunk-O47BPOPC.js} +2 -2
  142. package/dist/cli-bundle/chunks/{chunk-X26ODPU4.js → chunk-OFYMIDF2.js} +14 -18
  143. package/dist/cli-bundle/chunks/chunk-OFYMIDF2.js.map +7 -0
  144. package/dist/cli-bundle/chunks/{chunk-QCHNPN24.js → chunk-OTHIWLMB.js} +7 -5
  145. package/dist/cli-bundle/chunks/{chunk-YVYJQR6S.js → chunk-PFSRUHDH.js} +9 -9
  146. package/dist/cli-bundle/chunks/{chunk-M35R7LFX.js → chunk-PP2U4NMT.js} +5 -5
  147. package/dist/cli-bundle/chunks/{chunk-ZGEWEO7B.js → chunk-PUH4D67U.js} +2 -2
  148. package/dist/cli-bundle/chunks/{chunk-LEC57E7K.js → chunk-Q2J2HJUN.js} +2 -2
  149. package/dist/cli-bundle/chunks/{chunk-QSH34DSQ.js → chunk-QGG32QHW.js} +61 -4
  150. package/dist/cli-bundle/chunks/chunk-QGG32QHW.js.map +7 -0
  151. package/dist/cli-bundle/chunks/{chunk-QG6M6XQE.js → chunk-QQHISQBJ.js} +3 -3
  152. package/dist/cli-bundle/chunks/{chunk-BQVESTOG.js → chunk-QZTWBFXJ.js} +2 -2
  153. package/dist/cli-bundle/chunks/{chunk-COHNQLB2.js → chunk-R2EMWY7Q.js} +41 -3
  154. package/dist/cli-bundle/chunks/chunk-R2EMWY7Q.js.map +1 -0
  155. package/dist/cli-bundle/chunks/{chunk-5LZPDRFW.js → chunk-RLK7P77C.js} +5 -5
  156. package/dist/cli-bundle/chunks/{chunk-QTWWHFI3.js → chunk-RVHYI7SL.js} +8 -8
  157. package/dist/cli-bundle/chunks/{chunk-FVZSUIN5.js → chunk-SBGXDO7A.js} +3 -3
  158. package/dist/cli-bundle/chunks/{chunk-VP4Z36GO.js → chunk-SRYYRVPB.js} +2 -2
  159. package/dist/cli-bundle/chunks/{chunk-X7RKOJXL.js → chunk-SX75ADBK.js} +6 -6
  160. package/dist/cli-bundle/chunks/{chunk-MTDEEUGV.js → chunk-TKBHZPKD.js} +3 -3
  161. package/dist/cli-bundle/chunks/{chunk-HMQMRHQJ.js → chunk-UEMNL33O.js} +8 -8
  162. package/dist/cli-bundle/chunks/{chunk-SDUZTZ55.js → chunk-UPE3CDD7.js} +7 -7
  163. package/dist/cli-bundle/chunks/{chunk-VG3B2CYD.js → chunk-UV6IYE5U.js} +2 -2
  164. package/dist/cli-bundle/chunks/{chunk-YOGXK3ON.js → chunk-WQ7NIVDK.js} +18 -13
  165. package/dist/cli-bundle/chunks/chunk-WQ7NIVDK.js.map +7 -0
  166. package/dist/cli-bundle/chunks/{chunk-MTGMNUMJ.js → chunk-YCJX76PW.js} +2 -2
  167. package/dist/cli-bundle/chunks/{chunk-FP7YLQ52.js → chunk-Z6T4PQI2.js} +11 -10
  168. package/dist/cli-bundle/chunks/chunk-Z6T4PQI2.js.map +1 -0
  169. package/dist/cli-bundle/chunks/{claim-2BSYPJTJ.js → claim-RC56YUWG.js} +10 -10
  170. package/dist/cli-bundle/chunks/{claim-EZ6JKY5X.js → claim-THOJ6CMV.js} +10 -10
  171. package/dist/cli-bundle/chunks/close-DNMHGOCX.js +15 -0
  172. package/dist/cli-bundle/chunks/{close-3TSX6BYF.js → close-SG5MNCVQ.js} +8 -8
  173. package/dist/cli-bundle/chunks/{close-many-HB4UFCS3.js → close-many-3L3AQZBU.js} +15 -15
  174. package/dist/cli-bundle/chunks/{close-many-B7DBVA46.js → close-many-DKQLBGLV.js} +15 -15
  175. package/dist/cli-bundle/chunks/{comments-M7PAINZT.js → comments-M7ZOZNBX.js} +10 -10
  176. package/dist/cli-bundle/chunks/{comments-X7M7XM6I.js → comments-SKWMDWCW.js} +10 -10
  177. package/dist/cli-bundle/chunks/{config-YICACPHA.js → config-7CK62S7T.js} +30 -10
  178. package/dist/cli-bundle/chunks/config-7CK62S7T.js.map +1 -0
  179. package/dist/cli-bundle/chunks/{config-UWF3KRP5.js → config-OZCUABPB.js} +29 -9
  180. package/dist/cli-bundle/chunks/config-OZCUABPB.js.map +7 -0
  181. package/dist/cli-bundle/chunks/{context-EGUGU4K7.js → context-OEC366TO.js} +13 -13
  182. package/dist/cli-bundle/chunks/{context-V32ZAPL6.js → context-PUG2A7RC.js} +13 -13
  183. package/dist/cli-bundle/chunks/{contracts-B2YWYUV5.js → contracts-3THOLA7L.js} +10 -8
  184. package/dist/cli-bundle/chunks/contracts-3THOLA7L.js.map +7 -0
  185. package/dist/cli-bundle/chunks/{contracts-7G553BHP.js → contracts-N65FXEOL.js} +10 -8
  186. package/dist/cli-bundle/chunks/contracts-N65FXEOL.js.map +1 -0
  187. package/dist/cli-bundle/chunks/{copy-NWFFRYWM.js → copy-6QLHILAC.js} +7 -7
  188. package/dist/cli-bundle/chunks/{copy-RMLXLZOL.js → copy-JPX7VZCH.js} +7 -7
  189. package/dist/cli-bundle/chunks/create-NNP6TSFO.js +30 -0
  190. package/dist/cli-bundle/chunks/{create-GK4MX2LJ.js → create-Y54ZVVZH.js} +14 -14
  191. package/dist/cli-bundle/chunks/{delete-RMGNIL2S.js → delete-63PCMQAJ.js} +7 -7
  192. package/dist/cli-bundle/chunks/{delete-EFQLVEAS.js → delete-GDSMGAGJ.js} +7 -7
  193. package/dist/cli-bundle/chunks/{deps-WKHUPVD3.js → deps-T4ZF5G54.js} +7 -7
  194. package/dist/cli-bundle/chunks/{deps-K2I7QV4Y.js → deps-XYQ73XRH.js} +7 -7
  195. package/dist/cli-bundle/chunks/{docs-3FXRDYA7.js → docs-C75YIXHC.js} +10 -9
  196. package/dist/cli-bundle/chunks/{docs-3FXRDYA7.js.map → docs-C75YIXHC.js.map} +1 -1
  197. package/dist/cli-bundle/chunks/{docs-2H2UGIT6.js → docs-EHNPDWUL.js} +12 -11
  198. package/dist/cli-bundle/chunks/{docs-2H2UGIT6.js.map → docs-EHNPDWUL.js.map} +1 -1
  199. package/dist/cli-bundle/chunks/eval-3WKDTRMH.js +276 -0
  200. package/dist/cli-bundle/chunks/eval-3WKDTRMH.js.map +1 -0
  201. package/dist/cli-bundle/chunks/eval-GTENKE24.js +286 -0
  202. package/dist/cli-bundle/chunks/eval-GTENKE24.js.map +7 -0
  203. package/dist/cli-bundle/chunks/{extension-4LPTFTV4.js → extension-46NWACO3.js} +5 -5
  204. package/dist/cli-bundle/chunks/{extension-ASUPTDCC.js → extension-D5FDZ2CO.js} +5 -5
  205. package/dist/cli-bundle/chunks/{files-TXEQOA7C.js → files-DSZBOSSN.js} +12 -11
  206. package/dist/cli-bundle/chunks/{files-TXEQOA7C.js.map → files-DSZBOSSN.js.map} +1 -1
  207. package/dist/cli-bundle/chunks/{files-UAZFB3EA.js → files-X3H7CCBQ.js} +10 -9
  208. package/dist/cli-bundle/chunks/{files-UAZFB3EA.js.map → files-X3H7CCBQ.js.map} +1 -1
  209. package/dist/cli-bundle/chunks/{focus-UGROAMAX.js → focus-5STQXDPU.js} +8 -8
  210. package/dist/cli-bundle/chunks/{focus-ELOPN2SR.js → focus-MDVPOWB5.js} +8 -8
  211. package/dist/cli-bundle/chunks/gc-ZC7JHBG7.js +395 -0
  212. package/dist/cli-bundle/chunks/gc-ZC7JHBG7.js.map +7 -0
  213. package/dist/cli-bundle/chunks/gc-ZMST3WQP.js +385 -0
  214. package/dist/cli-bundle/chunks/gc-ZMST3WQP.js.map +1 -0
  215. package/dist/cli-bundle/chunks/{get-OTXPLWYW.js → get-J2IPJRZW.js} +11 -11
  216. package/dist/cli-bundle/chunks/{get-IWZ7IMPS.js → get-NT7L2HUZ.js} +11 -11
  217. package/dist/cli-bundle/chunks/{health-PPTJ7XKW.js → health-IVMA3XQC.js} +38 -26
  218. package/dist/cli-bundle/chunks/health-IVMA3XQC.js.map +1 -0
  219. package/dist/cli-bundle/chunks/{health-JEBESKID.js → health-WOYBR3KU.js} +37 -25
  220. package/dist/cli-bundle/chunks/health-WOYBR3KU.js.map +7 -0
  221. package/dist/cli-bundle/chunks/{history-HNWBUDMI.js → history-RLH2QCRO.js} +10 -10
  222. package/dist/cli-bundle/chunks/history-WX3MGFS2.js +20 -0
  223. package/dist/cli-bundle/chunks/{history-compact-MMQC7MCW.js → history-compact-UXDIFC33.js} +12 -12
  224. package/dist/cli-bundle/chunks/{history-compact-EQXVPK3V.js → history-compact-ZBEBGJM7.js} +12 -12
  225. package/dist/cli-bundle/chunks/{history-redact-UBDHBEJE.js → history-redact-P7I7AWMB.js} +11 -11
  226. package/dist/cli-bundle/chunks/history-redact-YQGU3XRA.js +21 -0
  227. package/dist/cli-bundle/chunks/{history-repair-GMMHFAGH.js → history-repair-52KINVIK.js} +12 -12
  228. package/dist/cli-bundle/chunks/{history-repair-7DSDRPMX.js → history-repair-RM5ITLU5.js} +12 -12
  229. package/dist/cli-bundle/chunks/{init-QGK4JFF6.js → init-2BNZOO6F.js} +10 -10
  230. package/dist/cli-bundle/chunks/init-SC2P6CHP.js +20 -0
  231. package/dist/cli-bundle/chunks/{learnings-DR53TWRA.js → learnings-W6F3FIPL.js} +10 -10
  232. package/dist/cli-bundle/chunks/{learnings-A6DGBMG3.js → learnings-YGYVHWJK.js} +10 -10
  233. package/dist/cli-bundle/chunks/{list-LJ5DBXC3.js → list-K6FPV4J4.js} +10 -10
  234. package/dist/cli-bundle/chunks/{list-KOJN23UL.js → list-KPAYU5KZ.js} +10 -10
  235. package/dist/cli-bundle/chunks/{notes-7VLTHKPW.js → notes-PU74EPKV.js} +10 -10
  236. package/dist/cli-bundle/chunks/{notes-K5I3TAYR.js → notes-YTD6ZILW.js} +10 -10
  237. package/dist/cli-bundle/chunks/{plan-X3STKLED.js → plan-FNXHXRCI.js} +15 -15
  238. package/dist/cli-bundle/chunks/plan-FNXHXRCI.js.map +7 -0
  239. package/dist/cli-bundle/chunks/{plan-BK3OMLGP.js → plan-GEQYUCBW.js} +16 -16
  240. package/dist/cli-bundle/chunks/plan-GEQYUCBW.js.map +1 -0
  241. package/dist/cli-bundle/chunks/{register-list-query-XDLFESU7.js → register-list-query-PHWYHENI.js} +43 -22
  242. package/dist/cli-bundle/chunks/register-list-query-PHWYHENI.js.map +1 -0
  243. package/dist/cli-bundle/chunks/{register-list-query-FUMXPWZ4.js → register-list-query-QI45RMKN.js} +42 -21
  244. package/dist/cli-bundle/chunks/register-list-query-QI45RMKN.js.map +7 -0
  245. package/dist/cli-bundle/chunks/{register-mutation-RXRX4P7D.js → register-mutation-X3BUOQEL.js} +33 -33
  246. package/dist/cli-bundle/chunks/{register-mutation-ZAGVKMBQ.js → register-mutation-YINRTS7L.js} +33 -33
  247. package/dist/cli-bundle/chunks/{register-operations-DGSHCS75.js → register-operations-E5JEASRK.js} +35 -35
  248. package/dist/cli-bundle/chunks/register-operations-E5JEASRK.js.map +1 -0
  249. package/dist/cli-bundle/chunks/{register-operations-6UURPZN5.js → register-operations-MIDTRW7S.js} +34 -34
  250. package/dist/cli-bundle/chunks/{register-operations-6UURPZN5.js.map → register-operations-MIDTRW7S.js.map} +2 -2
  251. package/dist/cli-bundle/chunks/{register-setup-LTJG52WP.js → register-setup-DYBFLEZX.js} +15 -15
  252. package/dist/cli-bundle/chunks/{register-setup-2FEGSFLM.js → register-setup-EG2U6CEU.js} +15 -15
  253. package/dist/cli-bundle/chunks/restore-5KHR2YYQ.js +19 -0
  254. package/dist/cli-bundle/chunks/{restore-SJUWYOCK.js → restore-XQYSWBV7.js} +11 -11
  255. package/dist/cli-bundle/chunks/{scheduling-shortcuts-VWAMP2S2.js → scheduling-shortcuts-HJMTEXKE.js} +14 -14
  256. package/dist/cli-bundle/chunks/{scheduling-shortcuts-W4F2LKHW.js → scheduling-shortcuts-NNT5ASZR.js} +14 -14
  257. package/dist/cli-bundle/chunks/{schema-N5ETYD4P.js → schema-263RI4WW.js} +9 -9
  258. package/dist/cli-bundle/chunks/{schema-DXQRIEFM.js → schema-TZXW6XWD.js} +9 -9
  259. package/dist/cli-bundle/chunks/search-LECJYSXE.js +33 -0
  260. package/dist/cli-bundle/chunks/search-SFRJOVDG.js +37 -0
  261. package/dist/cli-bundle/chunks/{stats-ZFESFVQC.js → stats-N7ER2PNK.js} +8 -8
  262. package/dist/cli-bundle/chunks/{stats-J563NJBY.js → stats-VPBGSRQH.js} +8 -8
  263. package/dist/cli-bundle/chunks/{telemetry-BNGLIFEM.js → telemetry-L6K3BUIQ.js} +4 -4
  264. package/dist/cli-bundle/chunks/{telemetry-SC7HPRXX.js → telemetry-PP3FUNBU.js} +4 -4
  265. package/dist/cli-bundle/chunks/{test-47UQGEXE.js → test-3EGNS3T5.js} +15 -15
  266. package/dist/cli-bundle/chunks/{test-55RJCGRU.js → test-RQCTSWUK.js} +15 -15
  267. package/dist/cli-bundle/chunks/{test-all-DN6KG4FX.js → test-all-NJ5V2QFS.js} +15 -15
  268. package/dist/cli-bundle/chunks/{test-all-5SFTTRNL.js → test-all-ZHFAWNC3.js} +15 -15
  269. package/dist/cli-bundle/chunks/{test-runs-NHRBT7SN.js → test-runs-AJHR6IQF.js} +5 -5
  270. package/dist/cli-bundle/chunks/{test-runs-DZEDJ4GH.js → test-runs-GN3C6GOI.js} +5 -5
  271. package/dist/cli-bundle/chunks/update-6YXOGHRT.js +24 -0
  272. package/dist/cli-bundle/chunks/update-6YXOGHRT.js.map +7 -0
  273. package/dist/cli-bundle/chunks/update-V33YUBRP.js +28 -0
  274. package/dist/cli-bundle/chunks/update-V33YUBRP.js.map +1 -0
  275. package/dist/cli-bundle/chunks/{update-many-IRNV3OTG.js → update-many-N2AN6ZDH.js} +23 -23
  276. package/dist/cli-bundle/chunks/{update-many-OKYWFCBO.js → update-many-RYQ64CFW.js} +23 -23
  277. package/dist/cli-bundle/chunks/{upgrade-KP4I45V5.js → upgrade-TJXFLZIX.js} +5 -5
  278. package/dist/cli-bundle/chunks/{upgrade-3RIAFQIK.js → upgrade-VPCIYAVW.js} +5 -5
  279. package/dist/cli-bundle/chunks/{validate-GVY4VE43.js → validate-JMNWEUYF.js} +62 -24
  280. package/dist/cli-bundle/chunks/validate-JMNWEUYF.js.map +1 -0
  281. package/dist/cli-bundle/chunks/{validate-ADKGN37M.js → validate-PHKIYGSY.js} +61 -23
  282. package/dist/cli-bundle/chunks/validate-PHKIYGSY.js.map +7 -0
  283. package/dist/cli-bundle/main.js +133 -55
  284. package/dist/cli-bundle/main.js.map +2 -2
  285. package/dist/core/checkpoint/checkpoint-gc.d.ts +69 -0
  286. package/dist/core/checkpoint/checkpoint-gc.js +175 -0
  287. package/dist/core/checkpoint/checkpoint-gc.js.map +1 -0
  288. package/dist/core/config/nested-settings.js +22 -2
  289. package/dist/core/config/nested-settings.js.map +1 -1
  290. package/dist/core/diagnostics/remediation.js +40 -2
  291. package/dist/core/diagnostics/remediation.js.map +1 -1
  292. package/dist/core/extensions/extension-types.d.ts +0 -9
  293. package/dist/core/extensions/extension-types.js +2 -27
  294. package/dist/core/extensions/extension-types.js.map +1 -1
  295. package/dist/core/fs/fs-utils.d.ts +17 -1
  296. package/dist/core/fs/fs-utils.js +19 -3
  297. package/dist/core/fs/fs-utils.js.map +1 -1
  298. package/dist/core/history/drift-scan.d.ts +17 -5
  299. package/dist/core/history/drift-scan.js +22 -14
  300. package/dist/core/history/drift-scan.js.map +1 -1
  301. package/dist/core/history/replay.d.ts +7 -0
  302. package/dist/core/history/replay.js +11 -6
  303. package/dist/core/history/replay.js.map +1 -1
  304. package/dist/core/item/item-format-version.d.ts +87 -0
  305. package/dist/core/item/item-format-version.js +85 -0
  306. package/dist/core/item/item-format-version.js.map +1 -0
  307. package/dist/core/item/item-format.js +8 -2
  308. package/dist/core/item/item-format.js.map +1 -1
  309. package/dist/core/item/status-filter.d.ts +7 -3
  310. package/dist/core/item/status-filter.js +26 -5
  311. package/dist/core/item/status-filter.js.map +1 -1
  312. package/dist/core/search/bm25.d.ts +113 -0
  313. package/dist/core/search/bm25.js +178 -0
  314. package/dist/core/search/bm25.js.map +1 -0
  315. package/dist/core/search/eval.d.ts +114 -0
  316. package/dist/core/search/eval.js +217 -0
  317. package/dist/core/search/eval.js.map +1 -0
  318. package/dist/core/sentry/instrument.d.ts +14 -0
  319. package/dist/core/sentry/instrument.js +43 -3
  320. package/dist/core/sentry/instrument.js.map +1 -1
  321. package/dist/core/shared/constants.js +6 -2
  322. package/dist/core/shared/constants.js.map +1 -1
  323. package/dist/core/store/paths.js +4 -3
  324. package/dist/core/store/paths.js.map +1 -1
  325. package/dist/core/store/settings-validator.d.ts +7 -0
  326. package/dist/core/store/settings-validator.js +10 -2
  327. package/dist/core/store/settings-validator.js.map +1 -1
  328. package/dist/core/store/settings.js +6 -2
  329. package/dist/core/store/settings.js.map +1 -1
  330. package/dist/mcp/tool-definitions.js +4 -3
  331. package/dist/mcp/tool-definitions.js.map +1 -1
  332. package/dist/sdk/cli-contracts/enum-contracts.d.ts +1 -1
  333. package/dist/sdk/cli-contracts/enum-contracts.js +3 -2
  334. package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -1
  335. package/dist/sdk/cli-contracts/tool-parameter-tables.js +4 -4
  336. package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
  337. package/dist/sdk/cli-contracts.d.ts +1 -0
  338. package/dist/sdk/cli-contracts.js +11 -2
  339. package/dist/sdk/cli-contracts.js.map +1 -1
  340. package/dist/sdk/index.d.ts +2 -2
  341. package/dist/sdk/index.js +3 -3
  342. package/dist/sdk/index.js.map +1 -1
  343. package/dist/sdk/runtime.d.ts +1 -0
  344. package/dist/sdk/runtime.js +3 -2
  345. package/dist/sdk/runtime.js.map +1 -1
  346. package/dist/sdk/testing.d.ts +48 -1
  347. package/dist/sdk/testing.js +98 -2
  348. package/dist/sdk/testing.js.map +1 -1
  349. package/dist/types.d.ts +26 -0
  350. package/dist/types.js +2 -2
  351. package/dist/types.js.map +1 -1
  352. package/docs/AGENT_GUIDE.md +1 -0
  353. package/docs/ARCHITECTURE.md +126 -11
  354. package/docs/CLAUDE_CODE_PLUGIN.md +5 -13
  355. package/docs/COMMANDS.md +57 -5
  356. package/docs/CONFIGURATION.md +39 -0
  357. package/docs/EXTENSIONS.md +2 -2
  358. package/docs/MIGRATION_CLI_SIMPLIFICATION.md +9 -2
  359. package/docs/QUICKSTART.md +2 -0
  360. package/docs/README.md +2 -0
  361. package/docs/RELEASING.md +2 -1
  362. package/docs/SDK.md +80 -1
  363. package/docs/TESTING.md +18 -0
  364. package/package.json +4 -3
  365. package/packages/pm-command-kit/README.md +4 -0
  366. package/packages/pm-todos/extensions/todos/index.js +2 -0
  367. package/packages/pm-todos/extensions/todos/index.ts +2 -0
  368. package/packages/pm-todos/extensions/todos/runtime.js +192 -9
  369. package/packages/pm-todos/extensions/todos/runtime.ts +211 -8
  370. package/dist/cli-bundle/chunks/activity-62I26XZB.js +0 -18
  371. package/dist/cli-bundle/chunks/chunk-2RI3BDFK.js.map +0 -7
  372. package/dist/cli-bundle/chunks/chunk-4BFNWAMQ.js.map +0 -7
  373. package/dist/cli-bundle/chunks/chunk-5QLHQK7V.js.map +0 -7
  374. package/dist/cli-bundle/chunks/chunk-5SRID7DV.js.map +0 -1
  375. package/dist/cli-bundle/chunks/chunk-COHNQLB2.js.map +0 -1
  376. package/dist/cli-bundle/chunks/chunk-DVUU3AHP.js.map +0 -1
  377. package/dist/cli-bundle/chunks/chunk-EMFDZ7N3.js.map +0 -1
  378. package/dist/cli-bundle/chunks/chunk-FP7YLQ52.js.map +0 -1
  379. package/dist/cli-bundle/chunks/chunk-FPQA4ZMA.js.map +0 -7
  380. package/dist/cli-bundle/chunks/chunk-GDOTTY2S.js.map +0 -7
  381. package/dist/cli-bundle/chunks/chunk-I2VJM36R.js.map +0 -1
  382. package/dist/cli-bundle/chunks/chunk-K5TD74VU.js.map +0 -7
  383. package/dist/cli-bundle/chunks/chunk-MAKOMXVM.js.map +0 -1
  384. package/dist/cli-bundle/chunks/chunk-PSWSQHM7.js.map +0 -1
  385. package/dist/cli-bundle/chunks/chunk-QSH34DSQ.js.map +0 -7
  386. package/dist/cli-bundle/chunks/chunk-UA4ANRJY.js.map +0 -7
  387. package/dist/cli-bundle/chunks/chunk-UCNEPMPY.js.map +0 -7
  388. package/dist/cli-bundle/chunks/chunk-X26ODPU4.js.map +0 -7
  389. package/dist/cli-bundle/chunks/chunk-Y4IBSEQ2.js.map +0 -1
  390. package/dist/cli-bundle/chunks/chunk-YOGXK3ON.js.map +0 -7
  391. package/dist/cli-bundle/chunks/chunk-YWAYOWDQ.js.map +0 -1
  392. package/dist/cli-bundle/chunks/chunk-ZZEM2PH7.js.map +0 -1
  393. package/dist/cli-bundle/chunks/close-TQZK43Z5.js +0 -15
  394. package/dist/cli-bundle/chunks/config-UWF3KRP5.js.map +0 -7
  395. package/dist/cli-bundle/chunks/config-YICACPHA.js.map +0 -1
  396. package/dist/cli-bundle/chunks/contracts-7G553BHP.js.map +0 -1
  397. package/dist/cli-bundle/chunks/contracts-B2YWYUV5.js.map +0 -7
  398. package/dist/cli-bundle/chunks/create-UZLJXHLA.js +0 -30
  399. package/dist/cli-bundle/chunks/gc-5RTYXLQU.js +0 -211
  400. package/dist/cli-bundle/chunks/gc-5RTYXLQU.js.map +0 -7
  401. package/dist/cli-bundle/chunks/gc-FK5732EK.js +0 -208
  402. package/dist/cli-bundle/chunks/gc-FK5732EK.js.map +0 -1
  403. package/dist/cli-bundle/chunks/health-JEBESKID.js.map +0 -7
  404. package/dist/cli-bundle/chunks/health-PPTJ7XKW.js.map +0 -1
  405. package/dist/cli-bundle/chunks/history-TKTULEVE.js +0 -20
  406. package/dist/cli-bundle/chunks/history-redact-SPIFIXVY.js +0 -21
  407. package/dist/cli-bundle/chunks/init-A6FTZ5UC.js +0 -20
  408. package/dist/cli-bundle/chunks/plan-BK3OMLGP.js.map +0 -1
  409. package/dist/cli-bundle/chunks/plan-X3STKLED.js.map +0 -7
  410. package/dist/cli-bundle/chunks/register-list-query-FUMXPWZ4.js.map +0 -7
  411. package/dist/cli-bundle/chunks/register-list-query-XDLFESU7.js.map +0 -1
  412. package/dist/cli-bundle/chunks/register-operations-DGSHCS75.js.map +0 -1
  413. package/dist/cli-bundle/chunks/restore-PI3WM4GK.js +0 -19
  414. package/dist/cli-bundle/chunks/search-2JX776KX.js.map +0 -1
  415. package/dist/cli-bundle/chunks/search-AZR2JITW.js.map +0 -7
  416. package/dist/cli-bundle/chunks/update-2BZEAI7B.js +0 -24
  417. package/dist/cli-bundle/chunks/update-GCNLER2H.js +0 -28
  418. package/dist/cli-bundle/chunks/validate-ADKGN37M.js.map +0 -7
  419. package/dist/cli-bundle/chunks/validate-GVY4VE43.js.map +0 -1
  420. /package/dist/cli-bundle/chunks/{activity-62I26XZB.js.map → activity-CIHV64UC.js.map} +0 -0
  421. /package/dist/cli-bundle/chunks/{activity-XJ7WRNWS.js.map → activity-KW3IRP44.js.map} +0 -0
  422. /package/dist/cli-bundle/chunks/{aggregate-LBCWF6UJ.js.map → aggregate-3ZKQG5SW.js.map} +0 -0
  423. /package/dist/cli-bundle/chunks/{aggregate-OFT4YVB6.js.map → aggregate-FIGQEIL3.js.map} +0 -0
  424. /package/dist/cli-bundle/chunks/{append-BP2ARHOK.js.map → append-EWJYJ7CH.js.map} +0 -0
  425. /package/dist/cli-bundle/chunks/{append-5U3XR5SD.js.map → append-QEOLX3XB.js.map} +0 -0
  426. /package/dist/cli-bundle/chunks/{chunk-CSRFOIHG.js.map → chunk-2EIMPCE4.js.map} +0 -0
  427. /package/dist/cli-bundle/chunks/{chunk-II3WDRCM.js.map → chunk-37QXHBIB.js.map} +0 -0
  428. /package/dist/cli-bundle/chunks/{chunk-UMTPQMEG.js.map → chunk-3MDHREEV.js.map} +0 -0
  429. /package/dist/cli-bundle/chunks/{chunk-DJ3YYLHG.js.map → chunk-5FIEHKEX.js.map} +0 -0
  430. /package/dist/cli-bundle/chunks/{chunk-OURX4WVG.js.map → chunk-5IDI42VV.js.map} +0 -0
  431. /package/dist/cli-bundle/chunks/{chunk-RVG3WLY3.js.map → chunk-5QICDWMV.js.map} +0 -0
  432. /package/dist/cli-bundle/chunks/{chunk-LIVRA6VG.js.map → chunk-6CJWZAN7.js.map} +0 -0
  433. /package/dist/cli-bundle/chunks/{chunk-AVMSP2HH.js.map → chunk-6H4LF7AO.js.map} +0 -0
  434. /package/dist/cli-bundle/chunks/{chunk-B2NEFANY.js.map → chunk-6M4RJS4M.js.map} +0 -0
  435. /package/dist/cli-bundle/chunks/{chunk-A5JPMD4Q.js.map → chunk-76Z3YSHV.js.map} +0 -0
  436. /package/dist/cli-bundle/chunks/{chunk-5NS6TJ2F.js.map → chunk-7D3SAQXM.js.map} +0 -0
  437. /package/dist/cli-bundle/chunks/{chunk-2E3KSWFG.js.map → chunk-AIS5PGI3.js.map} +0 -0
  438. /package/dist/cli-bundle/chunks/{chunk-47BYN6CA.js.map → chunk-AZMOLBN3.js.map} +0 -0
  439. /package/dist/cli-bundle/chunks/{chunk-DYZKSIVX.js.map → chunk-B473GZWW.js.map} +0 -0
  440. /package/dist/cli-bundle/chunks/{chunk-RNWE2HZR.js.map → chunk-C3AZ5ZML.js.map} +0 -0
  441. /package/dist/cli-bundle/chunks/{chunk-S673PVHD.js.map → chunk-C4N5I7ZW.js.map} +0 -0
  442. /package/dist/cli-bundle/chunks/{chunk-TYQBGXH2.js.map → chunk-CF55WVVS.js.map} +0 -0
  443. /package/dist/cli-bundle/chunks/{chunk-4EOS35RL.js.map → chunk-CZPXY7UW.js.map} +0 -0
  444. /package/dist/cli-bundle/chunks/{chunk-MPEWACTG.js.map → chunk-CZUB4XWO.js.map} +0 -0
  445. /package/dist/cli-bundle/chunks/{chunk-22YA6GCA.js.map → chunk-D7FYS6PG.js.map} +0 -0
  446. /package/dist/cli-bundle/chunks/{chunk-UIMLAFOE.js.map → chunk-F5NZWFSW.js.map} +0 -0
  447. /package/dist/cli-bundle/chunks/{chunk-H3DP6OUM.js.map → chunk-FKBDKV7Y.js.map} +0 -0
  448. /package/dist/cli-bundle/chunks/{chunk-SO2IOH37.js.map → chunk-FRUFKWNK.js.map} +0 -0
  449. /package/dist/cli-bundle/chunks/{chunk-7R5YKVKO.js.map → chunk-FWPDUYEY.js.map} +0 -0
  450. /package/dist/cli-bundle/chunks/{chunk-USVOBLGB.js.map → chunk-GOZUHWFD.js.map} +0 -0
  451. /package/dist/cli-bundle/chunks/{chunk-ZBVYKWT2.js.map → chunk-H7NJZWG2.js.map} +0 -0
  452. /package/dist/cli-bundle/chunks/{chunk-4L7Q4OVT.js.map → chunk-HCU6WUSY.js.map} +0 -0
  453. /package/dist/cli-bundle/chunks/{chunk-PRUB7RI4.js.map → chunk-LUWW7L4B.js.map} +0 -0
  454. /package/dist/cli-bundle/chunks/{chunk-N7LDJRB4.js.map → chunk-M5XALUSL.js.map} +0 -0
  455. /package/dist/cli-bundle/chunks/{chunk-NPNNW5TU.js.map → chunk-N5ZJACJ6.js.map} +0 -0
  456. /package/dist/cli-bundle/chunks/{chunk-NNMBNN6Q.js.map → chunk-NB3PYLQ6.js.map} +0 -0
  457. /package/dist/cli-bundle/chunks/{chunk-USKTNI7P.js.map → chunk-NIGXMNNI.js.map} +0 -0
  458. /package/dist/cli-bundle/chunks/{chunk-GL3QKIET.js.map → chunk-NIUEXCFS.js.map} +0 -0
  459. /package/dist/cli-bundle/chunks/{chunk-OUG4CL4H.js.map → chunk-NJHMAJ6N.js.map} +0 -0
  460. /package/dist/cli-bundle/chunks/{chunk-2K56AWDP.js.map → chunk-NJN7LL7U.js.map} +0 -0
  461. /package/dist/cli-bundle/chunks/{chunk-5P2LQV2F.js.map → chunk-NSBZ2CKF.js.map} +0 -0
  462. /package/dist/cli-bundle/chunks/{chunk-XV6N3QND.js.map → chunk-O47BPOPC.js.map} +0 -0
  463. /package/dist/cli-bundle/chunks/{chunk-QCHNPN24.js.map → chunk-OTHIWLMB.js.map} +0 -0
  464. /package/dist/cli-bundle/chunks/{chunk-YVYJQR6S.js.map → chunk-PFSRUHDH.js.map} +0 -0
  465. /package/dist/cli-bundle/chunks/{chunk-M35R7LFX.js.map → chunk-PP2U4NMT.js.map} +0 -0
  466. /package/dist/cli-bundle/chunks/{chunk-ZGEWEO7B.js.map → chunk-PUH4D67U.js.map} +0 -0
  467. /package/dist/cli-bundle/chunks/{chunk-LEC57E7K.js.map → chunk-Q2J2HJUN.js.map} +0 -0
  468. /package/dist/cli-bundle/chunks/{chunk-QG6M6XQE.js.map → chunk-QQHISQBJ.js.map} +0 -0
  469. /package/dist/cli-bundle/chunks/{chunk-BQVESTOG.js.map → chunk-QZTWBFXJ.js.map} +0 -0
  470. /package/dist/cli-bundle/chunks/{chunk-5LZPDRFW.js.map → chunk-RLK7P77C.js.map} +0 -0
  471. /package/dist/cli-bundle/chunks/{chunk-QTWWHFI3.js.map → chunk-RVHYI7SL.js.map} +0 -0
  472. /package/dist/cli-bundle/chunks/{chunk-FVZSUIN5.js.map → chunk-SBGXDO7A.js.map} +0 -0
  473. /package/dist/cli-bundle/chunks/{chunk-VP4Z36GO.js.map → chunk-SRYYRVPB.js.map} +0 -0
  474. /package/dist/cli-bundle/chunks/{chunk-X7RKOJXL.js.map → chunk-SX75ADBK.js.map} +0 -0
  475. /package/dist/cli-bundle/chunks/{chunk-MTDEEUGV.js.map → chunk-TKBHZPKD.js.map} +0 -0
  476. /package/dist/cli-bundle/chunks/{chunk-HMQMRHQJ.js.map → chunk-UEMNL33O.js.map} +0 -0
  477. /package/dist/cli-bundle/chunks/{chunk-SDUZTZ55.js.map → chunk-UPE3CDD7.js.map} +0 -0
  478. /package/dist/cli-bundle/chunks/{chunk-VG3B2CYD.js.map → chunk-UV6IYE5U.js.map} +0 -0
  479. /package/dist/cli-bundle/chunks/{chunk-MTGMNUMJ.js.map → chunk-YCJX76PW.js.map} +0 -0
  480. /package/dist/cli-bundle/chunks/{claim-2BSYPJTJ.js.map → claim-RC56YUWG.js.map} +0 -0
  481. /package/dist/cli-bundle/chunks/{claim-EZ6JKY5X.js.map → claim-THOJ6CMV.js.map} +0 -0
  482. /package/dist/cli-bundle/chunks/{close-TQZK43Z5.js.map → close-DNMHGOCX.js.map} +0 -0
  483. /package/dist/cli-bundle/chunks/{close-3TSX6BYF.js.map → close-SG5MNCVQ.js.map} +0 -0
  484. /package/dist/cli-bundle/chunks/{close-many-HB4UFCS3.js.map → close-many-3L3AQZBU.js.map} +0 -0
  485. /package/dist/cli-bundle/chunks/{close-many-B7DBVA46.js.map → close-many-DKQLBGLV.js.map} +0 -0
  486. /package/dist/cli-bundle/chunks/{comments-M7PAINZT.js.map → comments-M7ZOZNBX.js.map} +0 -0
  487. /package/dist/cli-bundle/chunks/{comments-X7M7XM6I.js.map → comments-SKWMDWCW.js.map} +0 -0
  488. /package/dist/cli-bundle/chunks/{context-EGUGU4K7.js.map → context-OEC366TO.js.map} +0 -0
  489. /package/dist/cli-bundle/chunks/{context-V32ZAPL6.js.map → context-PUG2A7RC.js.map} +0 -0
  490. /package/dist/cli-bundle/chunks/{copy-NWFFRYWM.js.map → copy-6QLHILAC.js.map} +0 -0
  491. /package/dist/cli-bundle/chunks/{copy-RMLXLZOL.js.map → copy-JPX7VZCH.js.map} +0 -0
  492. /package/dist/cli-bundle/chunks/{create-UZLJXHLA.js.map → create-NNP6TSFO.js.map} +0 -0
  493. /package/dist/cli-bundle/chunks/{create-GK4MX2LJ.js.map → create-Y54ZVVZH.js.map} +0 -0
  494. /package/dist/cli-bundle/chunks/{delete-RMGNIL2S.js.map → delete-63PCMQAJ.js.map} +0 -0
  495. /package/dist/cli-bundle/chunks/{delete-EFQLVEAS.js.map → delete-GDSMGAGJ.js.map} +0 -0
  496. /package/dist/cli-bundle/chunks/{deps-WKHUPVD3.js.map → deps-T4ZF5G54.js.map} +0 -0
  497. /package/dist/cli-bundle/chunks/{deps-K2I7QV4Y.js.map → deps-XYQ73XRH.js.map} +0 -0
  498. /package/dist/cli-bundle/chunks/{extension-4LPTFTV4.js.map → extension-46NWACO3.js.map} +0 -0
  499. /package/dist/cli-bundle/chunks/{extension-ASUPTDCC.js.map → extension-D5FDZ2CO.js.map} +0 -0
  500. /package/dist/cli-bundle/chunks/{focus-UGROAMAX.js.map → focus-5STQXDPU.js.map} +0 -0
  501. /package/dist/cli-bundle/chunks/{focus-ELOPN2SR.js.map → focus-MDVPOWB5.js.map} +0 -0
  502. /package/dist/cli-bundle/chunks/{get-OTXPLWYW.js.map → get-J2IPJRZW.js.map} +0 -0
  503. /package/dist/cli-bundle/chunks/{get-IWZ7IMPS.js.map → get-NT7L2HUZ.js.map} +0 -0
  504. /package/dist/cli-bundle/chunks/{history-HNWBUDMI.js.map → history-RLH2QCRO.js.map} +0 -0
  505. /package/dist/cli-bundle/chunks/{history-TKTULEVE.js.map → history-WX3MGFS2.js.map} +0 -0
  506. /package/dist/cli-bundle/chunks/{history-compact-MMQC7MCW.js.map → history-compact-UXDIFC33.js.map} +0 -0
  507. /package/dist/cli-bundle/chunks/{history-compact-EQXVPK3V.js.map → history-compact-ZBEBGJM7.js.map} +0 -0
  508. /package/dist/cli-bundle/chunks/{history-redact-UBDHBEJE.js.map → history-redact-P7I7AWMB.js.map} +0 -0
  509. /package/dist/cli-bundle/chunks/{history-redact-SPIFIXVY.js.map → history-redact-YQGU3XRA.js.map} +0 -0
  510. /package/dist/cli-bundle/chunks/{history-repair-GMMHFAGH.js.map → history-repair-52KINVIK.js.map} +0 -0
  511. /package/dist/cli-bundle/chunks/{history-repair-7DSDRPMX.js.map → history-repair-RM5ITLU5.js.map} +0 -0
  512. /package/dist/cli-bundle/chunks/{init-QGK4JFF6.js.map → init-2BNZOO6F.js.map} +0 -0
  513. /package/dist/cli-bundle/chunks/{init-A6FTZ5UC.js.map → init-SC2P6CHP.js.map} +0 -0
  514. /package/dist/cli-bundle/chunks/{learnings-DR53TWRA.js.map → learnings-W6F3FIPL.js.map} +0 -0
  515. /package/dist/cli-bundle/chunks/{learnings-A6DGBMG3.js.map → learnings-YGYVHWJK.js.map} +0 -0
  516. /package/dist/cli-bundle/chunks/{list-LJ5DBXC3.js.map → list-K6FPV4J4.js.map} +0 -0
  517. /package/dist/cli-bundle/chunks/{list-KOJN23UL.js.map → list-KPAYU5KZ.js.map} +0 -0
  518. /package/dist/cli-bundle/chunks/{notes-7VLTHKPW.js.map → notes-PU74EPKV.js.map} +0 -0
  519. /package/dist/cli-bundle/chunks/{notes-K5I3TAYR.js.map → notes-YTD6ZILW.js.map} +0 -0
  520. /package/dist/cli-bundle/chunks/{register-mutation-RXRX4P7D.js.map → register-mutation-X3BUOQEL.js.map} +0 -0
  521. /package/dist/cli-bundle/chunks/{register-mutation-ZAGVKMBQ.js.map → register-mutation-YINRTS7L.js.map} +0 -0
  522. /package/dist/cli-bundle/chunks/{register-setup-LTJG52WP.js.map → register-setup-DYBFLEZX.js.map} +0 -0
  523. /package/dist/cli-bundle/chunks/{register-setup-2FEGSFLM.js.map → register-setup-EG2U6CEU.js.map} +0 -0
  524. /package/dist/cli-bundle/chunks/{restore-PI3WM4GK.js.map → restore-5KHR2YYQ.js.map} +0 -0
  525. /package/dist/cli-bundle/chunks/{restore-SJUWYOCK.js.map → restore-XQYSWBV7.js.map} +0 -0
  526. /package/dist/cli-bundle/chunks/{scheduling-shortcuts-VWAMP2S2.js.map → scheduling-shortcuts-HJMTEXKE.js.map} +0 -0
  527. /package/dist/cli-bundle/chunks/{scheduling-shortcuts-W4F2LKHW.js.map → scheduling-shortcuts-NNT5ASZR.js.map} +0 -0
  528. /package/dist/cli-bundle/chunks/{schema-N5ETYD4P.js.map → schema-263RI4WW.js.map} +0 -0
  529. /package/dist/cli-bundle/chunks/{schema-DXQRIEFM.js.map → schema-TZXW6XWD.js.map} +0 -0
  530. /package/dist/cli-bundle/chunks/{test-55RJCGRU.js.map → search-LECJYSXE.js.map} +0 -0
  531. /package/dist/cli-bundle/chunks/{test-47UQGEXE.js.map → search-SFRJOVDG.js.map} +0 -0
  532. /package/dist/cli-bundle/chunks/{stats-ZFESFVQC.js.map → stats-N7ER2PNK.js.map} +0 -0
  533. /package/dist/cli-bundle/chunks/{stats-J563NJBY.js.map → stats-VPBGSRQH.js.map} +0 -0
  534. /package/dist/cli-bundle/chunks/{telemetry-BNGLIFEM.js.map → telemetry-L6K3BUIQ.js.map} +0 -0
  535. /package/dist/cli-bundle/chunks/{telemetry-SC7HPRXX.js.map → telemetry-PP3FUNBU.js.map} +0 -0
  536. /package/dist/cli-bundle/chunks/{update-GCNLER2H.js.map → test-3EGNS3T5.js.map} +0 -0
  537. /package/dist/cli-bundle/chunks/{update-2BZEAI7B.js.map → test-RQCTSWUK.js.map} +0 -0
  538. /package/dist/cli-bundle/chunks/{test-all-DN6KG4FX.js.map → test-all-NJ5V2QFS.js.map} +0 -0
  539. /package/dist/cli-bundle/chunks/{test-all-5SFTTRNL.js.map → test-all-ZHFAWNC3.js.map} +0 -0
  540. /package/dist/cli-bundle/chunks/{test-runs-NHRBT7SN.js.map → test-runs-AJHR6IQF.js.map} +0 -0
  541. /package/dist/cli-bundle/chunks/{test-runs-DZEDJ4GH.js.map → test-runs-GN3C6GOI.js.map} +0 -0
  542. /package/dist/cli-bundle/chunks/{update-many-IRNV3OTG.js.map → update-many-N2AN6ZDH.js.map} +0 -0
  543. /package/dist/cli-bundle/chunks/{update-many-OKYWFCBO.js.map → update-many-RYQ64CFW.js.map} +0 -0
  544. /package/dist/cli-bundle/chunks/{upgrade-KP4I45V5.js.map → upgrade-TJXFLZIX.js.map} +0 -0
  545. /package/dist/cli-bundle/chunks/{upgrade-3RIAFQIK.js.map → upgrade-VPCIYAVW.js.map} +0 -0
@@ -4,7 +4,7 @@
4
4
  * Implements append-only history and replay behavior for Drift Scan.
5
5
  */
6
6
 
7
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8ca839bf-b395-5bbb-a3e4-6c20b5b58f5e")}catch(e){}}();
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a928aad0-855f-5c7f-aa00-77d698ddca80")}catch(e){}}();
8
8
  import fs from "fs/promises";
9
9
  import { createHash } from "node:crypto";
10
10
  import path from "node:path";
@@ -12,7 +12,7 @@ import { getHistoryPath } from "../store/paths.js";
12
12
  import { writeFileAtomic } from "../fs/fs-utils.js";
13
13
  import { hashDocument } from "./history.js";
14
14
  import { verifyHistoryChain } from "./replay.js";
15
- const DRIFT_CACHE_VERSION = 2;
15
+ const DRIFT_CACHE_VERSION = 3;
16
16
  const DRIFT_CACHE_FILENAME = "history-drift-cache.json";
17
17
  function getDriftCachePath(pmRoot) {
18
18
  return path.join(pmRoot, "runtime", DRIFT_CACHE_FILENAME);
@@ -79,13 +79,13 @@ async function verifyHistoryStream(historyPath) {
79
79
  * Scan every item's history stream for drift (missing/unreadable streams, broken
80
80
  * hash chains, and item/history hash mismatches).
81
81
  *
82
- * Full chain re-verification of a 17MB+ history tree is the dominant cost of
82
+ * Full chain re-verification of a large history tree is the dominant cost of
83
83
  * `pm health`. We cache the per-stream verification keyed by the history file's
84
- * mtime/ctime/size + content hash: metadata-stable replacements (same stat tuple)
85
- * can still happen, so each metadata hit recomputes a content hash guard before
86
- * trusting the cached chain/hash verification.
84
+ * mtime/ctime/size plus content hash. Strict callers keep recomputing the
85
+ * content hash on metadata hits; latency-sensitive health checks can opt into
86
+ * trusting the stat tuple and skip rereading unchanged streams.
87
87
  */
88
- export async function scanHistoryDrift(pmRoot, items) {
88
+ export async function scanHistoryDrift(pmRoot, items, options = {}) {
89
89
  const missingStreams = [];
90
90
  const unreadableStreams = [];
91
91
  const hashMismatches = [];
@@ -94,6 +94,9 @@ export async function scanHistoryDrift(pmRoot, items) {
94
94
  const previousEntries = cache?.entries ?? {};
95
95
  const nextEntries = {};
96
96
  let cacheDirty = false;
97
+ // Metadata mode does not open a stat-matched stream, so unreadable-after-stat
98
+ // failures are intentionally deferred to strict validate/history-repair scans.
99
+ const verifyCacheHitByContent = options.cacheHitVerification !== "metadata";
97
100
  for (const item of items) {
98
101
  const historyPath = getHistoryPath(pmRoot, item.id);
99
102
  let stat;
@@ -139,14 +142,19 @@ export async function scanHistoryDrift(pmRoot, items) {
139
142
  const canUseCache = metadataMatchesCache && cachedContentHash !== undefined;
140
143
  if (canUseCache && cached) {
141
144
  let currentContentHash;
142
- try {
143
- currentContentHash = await readHistoryContentHash(historyPath);
145
+ if (verifyCacheHitByContent) {
146
+ try {
147
+ currentContentHash = await readHistoryContentHash(historyPath);
148
+ }
149
+ catch {
150
+ unreadableStreams.push(item.id);
151
+ continue;
152
+ }
144
153
  }
145
- catch {
146
- unreadableStreams.push(item.id);
147
- continue;
154
+ else {
155
+ currentContentHash = cachedContentHash;
148
156
  }
149
- if (currentContentHash === cachedContentHash) {
157
+ if (!verifyCacheHitByContent || currentContentHash === cachedContentHash) {
150
158
  verification = {
151
159
  latestAfterHash: cached.latest_after_hash,
152
160
  chainOk: cached.chain_ok,
@@ -204,4 +212,4 @@ export async function scanHistoryDrift(pmRoot, items) {
204
212
  return { missingStreams, unreadableStreams, hashMismatches, chainMismatches, driftedItems };
205
213
  }
206
214
  //# sourceMappingURL=drift-scan.js.map
207
- //# debugId=8ca839bf-b395-5bbb-a3e4-6c20b5b58f5e
215
+ //# debugId=a928aad0-855f-5c7f-aa00-77d698ddca80
@@ -1 +1 @@
1
- {"version":3,"file":"drift-scan.js","sources":["core/history/drift-scan.ts"],"sourceRoot":"/","sourcesContent":["/**\n * @module core/history/drift-scan\n *\n * Implements append-only history and replay behavior for Drift Scan.\n */\nimport fs from \"fs/promises\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { getHistoryPath } from \"../store/paths.js\";\nimport { writeFileAtomic } from \"../fs/fs-utils.js\";\nimport { hashDocument } from \"./history.js\";\nimport { verifyHistoryChain } from \"./replay.js\";\nimport type { HistoryEntry, ItemMetadata } from \"../../types/index.js\";\n\n/**\n * Documents the drift scan result payload exchanged by command, SDK, and package integrations.\n */\nexport interface DriftScanResult {\n missingStreams: string[];\n unreadableStreams: string[];\n hashMismatches: string[];\n chainMismatches: string[];\n driftedItems: string[];\n}\n\nconst DRIFT_CACHE_VERSION = 2;\nconst DRIFT_CACHE_FILENAME = \"history-drift-cache.json\";\n\ninterface DriftCacheEntry {\n mtime_ms: number;\n ctime_ms: number;\n size: number;\n content_hash: string;\n latest_after_hash: string;\n chain_ok: boolean;\n}\n\ninterface DriftCacheEnvelope {\n version: number;\n entries: Record<string, DriftCacheEntry>;\n}\n\nfunction getDriftCachePath(pmRoot: string): string {\n return path.join(pmRoot, \"runtime\", DRIFT_CACHE_FILENAME);\n}\n\nasync function loadDriftCache(pmRoot: string): Promise<DriftCacheEnvelope | null> {\n try {\n const raw = await fs.readFile(getDriftCachePath(pmRoot), \"utf8\");\n const parsed = JSON.parse(raw) as DriftCacheEnvelope;\n if (parsed.version !== DRIFT_CACHE_VERSION || typeof parsed.entries !== \"object\" || parsed.entries === null) {\n return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n return typeof error === \"object\" && error !== null && \"code\" in error && (error as { code?: string }).code === code;\n}\n\ninterface StreamVerification {\n latestAfterHash: string;\n chainOk: boolean;\n contentHash: string;\n}\n\nfunction hashContent(raw: string): string {\n return createHash(\"sha256\").update(raw).digest(\"hex\");\n}\n\nasync function readHistoryContentHash(historyPath: string): Promise<string> {\n const raw = await fs.readFile(historyPath, \"utf8\");\n return hashContent(raw);\n}\n\n/**\n * Read and fully verify one history stream's hash chain. Returns null for an\n * empty/missing stream (caller records it as a missing stream).\n */\nasync function verifyHistoryStream(historyPath: string): Promise<StreamVerification | null> {\n const raw = await fs.readFile(historyPath, \"utf8\");\n const contentHash = hashContent(raw);\n if (raw.trim().length === 0) {\n return null;\n }\n const entries: HistoryEntry[] = [];\n let latestAfterHash: string | null = null;\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (trimmed.length === 0) {\n continue;\n }\n const parsed = JSON.parse(trimmed) as HistoryEntry;\n if (typeof parsed.after_hash !== \"string\" || parsed.after_hash.trim().length === 0) {\n throw new Error(\"missing after_hash\");\n }\n entries.push(parsed);\n latestAfterHash = parsed.after_hash;\n }\n /* c8 ignore start -- defensive guard for future history schema changes. */\n if (!latestAfterHash) {\n return null;\n }\n /* c8 ignore stop */\n return {\n latestAfterHash,\n chainOk: verifyHistoryChain(entries).ok,\n contentHash,\n };\n}\n\n/**\n * Scan every item's history stream for drift (missing/unreadable streams, broken\n * hash chains, and item/history hash mismatches).\n *\n * Full chain re-verification of a 17MB+ history tree is the dominant cost of\n * `pm health`. We cache the per-stream verification keyed by the history file's\n * mtime/ctime/size + content hash: metadata-stable replacements (same stat tuple)\n * can still happen, so each metadata hit recomputes a content hash guard before\n * trusting the cached chain/hash verification.\n */\nexport async function scanHistoryDrift(\n pmRoot: string,\n items: Array<ItemMetadata & { body: string }>,\n): Promise<DriftScanResult> {\n const missingStreams: string[] = [];\n const unreadableStreams: string[] = [];\n const hashMismatches: string[] = [];\n const chainMismatches: string[] = [];\n\n const cache = await loadDriftCache(pmRoot);\n const previousEntries: Record<string, DriftCacheEntry> = cache?.entries ?? {};\n const nextEntries: Record<string, DriftCacheEntry> = {};\n let cacheDirty = false;\n\n for (const item of items) {\n const historyPath = getHistoryPath(pmRoot, item.id);\n\n let stat: Awaited<ReturnType<typeof fs.stat>>;\n try {\n stat = await fs.stat(historyPath);\n } catch (error: unknown) {\n if (isErrno(error, \"ENOENT\")) {\n missingStreams.push(item.id);\n } else {\n unreadableStreams.push(item.id);\n }\n continue;\n }\n\n const loadStreamVerification = async (): Promise<StreamVerification | null | \"unreadable\"> => {\n try {\n return await verifyHistoryStream(historyPath);\n } catch {\n return \"unreadable\";\n }\n };\n\n const loadFreshVerification = async (): Promise<StreamVerification | null> => {\n const loaded = await loadStreamVerification();\n if (loaded === \"unreadable\") {\n unreadableStreams.push(item.id);\n return null;\n }\n if (!loaded) {\n missingStreams.push(item.id);\n return null;\n }\n return loaded;\n };\n\n const cached = previousEntries[item.id];\n let verification: StreamVerification;\n const metadataMatchesCache =\n cached !== undefined &&\n cached.mtime_ms === stat.mtimeMs &&\n cached.ctime_ms === stat.ctimeMs &&\n cached.size === stat.size;\n const cachedContentHash =\n typeof cached?.content_hash === \"string\" && cached.content_hash.length > 0 ? cached.content_hash : undefined;\n const canUseCache = metadataMatchesCache && cachedContentHash !== undefined;\n if (canUseCache && cached) {\n let currentContentHash: string;\n try {\n currentContentHash = await readHistoryContentHash(historyPath);\n } catch {\n unreadableStreams.push(item.id);\n continue;\n }\n if (currentContentHash === cachedContentHash) {\n verification = {\n latestAfterHash: cached.latest_after_hash,\n chainOk: cached.chain_ok,\n contentHash: currentContentHash,\n };\n } else {\n cacheDirty = true;\n const refreshed = await loadFreshVerification();\n if (!refreshed) {\n continue;\n }\n verification = refreshed;\n }\n } else {\n cacheDirty = true;\n const refreshed = await loadFreshVerification();\n if (!refreshed) {\n continue;\n }\n verification = refreshed;\n }\n\n if (!verification.chainOk) {\n chainMismatches.push(item.id);\n }\n nextEntries[item.id] = {\n mtime_ms: stat.mtimeMs,\n ctime_ms: stat.ctimeMs,\n size: stat.size,\n content_hash: verification.contentHash,\n latest_after_hash: verification.latestAfterHash,\n chain_ok: verification.chainOk,\n };\n\n const { body, ...frontMatter } = item;\n const currentHash = hashDocument({\n metadata: frontMatter as ItemMetadata,\n body,\n });\n if (currentHash !== verification.latestAfterHash) {\n hashMismatches.push(item.id);\n }\n }\n\n if (cacheDirty || Object.keys(previousEntries).length !== Object.keys(nextEntries).length) {\n const cachePath = getDriftCachePath(pmRoot);\n try {\n await fs.mkdir(path.dirname(cachePath), { recursive: true });\n await writeFileAtomic(cachePath, JSON.stringify({ version: DRIFT_CACHE_VERSION, entries: nextEntries }));\n } catch {\n // Best-effort cache write: a failed persist must never fail a health scan.\n }\n }\n\n const driftedItems = [...new Set([...missingStreams, ...unreadableStreams, ...hashMismatches, ...chainMismatches])].sort((a, b) =>\n a.localeCompare(b),\n );\n return { missingStreams, unreadableStreams, hashMismatches, chainMismatches, driftedItems };\n}\n"],"names":[],"mappings":"AAAA;;;;GAIG;;;AACH,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAcjD,MAAM,mBAAmB,GAAG,CAAC,CAA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iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7D,MAAM,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;QAC3G,CAAC;QAAC,MAAM,CAAC;YACP,2EAA2E;QAC7E,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,iBAAiB,EAAE,GAAG,cAAc,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAChI,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CACnB,CAAC;IACF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AAC9F,CAAC","debugId":"8ca839bf-b395-5bbb-a3e4-6c20b5b58f5e"}
1
+ {"version":3,"file":"drift-scan.js","sources":["core/history/drift-scan.ts"],"sourceRoot":"/","sourcesContent":["/**\n * @module core/history/drift-scan\n *\n * Implements append-only history and replay behavior for Drift Scan.\n */\nimport fs from \"fs/promises\";\nimport { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { getHistoryPath } from \"../store/paths.js\";\nimport { writeFileAtomic } from \"../fs/fs-utils.js\";\nimport { hashDocument } from \"./history.js\";\nimport { verifyHistoryChain } from \"./replay.js\";\nimport type { HistoryEntry, ItemMetadata } from \"../../types/index.js\";\n\n/**\n * Documents the drift scan result payload exchanged by command, SDK, and package integrations.\n */\nexport interface DriftScanResult {\n missingStreams: string[];\n unreadableStreams: string[];\n hashMismatches: string[];\n chainMismatches: string[];\n driftedItems: string[];\n}\n\nconst DRIFT_CACHE_VERSION = 3;\nconst DRIFT_CACHE_FILENAME = \"history-drift-cache.json\";\n\n/**\n * Controls how cached history stream verification is trusted when the file stat\n * tuple still matches a previous scan.\n */\nexport type DriftCacheHitVerification = \"content_hash\" | \"metadata\";\n\n/**\n * Documents the history drift scan options shared by health, validate, and\n * repair callers.\n */\nexport interface DriftScanOptions {\n cacheHitVerification?: DriftCacheHitVerification;\n}\n\ninterface DriftCacheEntry {\n mtime_ms: number;\n ctime_ms: number;\n size: number;\n content_hash: string;\n latest_after_hash: string;\n chain_ok: boolean;\n}\n\ninterface DriftCacheEnvelope {\n version: number;\n entries: Record<string, DriftCacheEntry>;\n}\n\nfunction getDriftCachePath(pmRoot: string): string {\n return path.join(pmRoot, \"runtime\", DRIFT_CACHE_FILENAME);\n}\n\nasync function loadDriftCache(pmRoot: string): Promise<DriftCacheEnvelope | null> {\n try {\n const raw = await fs.readFile(getDriftCachePath(pmRoot), \"utf8\");\n const parsed = JSON.parse(raw) as DriftCacheEnvelope;\n if (parsed.version !== DRIFT_CACHE_VERSION || typeof parsed.entries !== \"object\" || parsed.entries === null) {\n return null;\n }\n return parsed;\n } catch {\n return null;\n }\n}\n\nfunction isErrno(error: unknown, code: string): boolean {\n return typeof error === \"object\" && error !== null && \"code\" in error && (error as { code?: string }).code === code;\n}\n\ninterface StreamVerification {\n latestAfterHash: string;\n chainOk: boolean;\n contentHash: string;\n}\n\nfunction hashContent(raw: string): string {\n return createHash(\"sha256\").update(raw).digest(\"hex\");\n}\n\nasync function readHistoryContentHash(historyPath: string): Promise<string> {\n const raw = await fs.readFile(historyPath, \"utf8\");\n return hashContent(raw);\n}\n\n/**\n * Read and fully verify one history stream's hash chain. Returns null for an\n * empty/missing stream (caller records it as a missing stream).\n */\nasync function verifyHistoryStream(historyPath: string): Promise<StreamVerification | null> {\n const raw = await fs.readFile(historyPath, \"utf8\");\n const contentHash = hashContent(raw);\n if (raw.trim().length === 0) {\n return null;\n }\n const entries: HistoryEntry[] = [];\n let latestAfterHash: string | null = null;\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (trimmed.length === 0) {\n continue;\n }\n const parsed = JSON.parse(trimmed) as HistoryEntry;\n if (typeof parsed.after_hash !== \"string\" || parsed.after_hash.trim().length === 0) {\n throw new Error(\"missing after_hash\");\n }\n entries.push(parsed);\n latestAfterHash = parsed.after_hash;\n }\n /* c8 ignore start -- defensive guard for future history schema changes. */\n if (!latestAfterHash) {\n return null;\n }\n /* c8 ignore stop */\n return {\n latestAfterHash,\n chainOk: verifyHistoryChain(entries).ok,\n contentHash,\n };\n}\n\n/**\n * Scan every item's history stream for drift (missing/unreadable streams, broken\n * hash chains, and item/history hash mismatches).\n *\n * Full chain re-verification of a large history tree is the dominant cost of\n * `pm health`. We cache the per-stream verification keyed by the history file's\n * mtime/ctime/size plus content hash. Strict callers keep recomputing the\n * content hash on metadata hits; latency-sensitive health checks can opt into\n * trusting the stat tuple and skip rereading unchanged streams.\n */\nexport async function scanHistoryDrift(\n pmRoot: string,\n items: Array<ItemMetadata & { body: string }>,\n options: DriftScanOptions = {},\n): Promise<DriftScanResult> {\n const missingStreams: string[] = [];\n const unreadableStreams: string[] = [];\n const hashMismatches: string[] = [];\n const chainMismatches: string[] = [];\n\n const cache = await loadDriftCache(pmRoot);\n const previousEntries: Record<string, DriftCacheEntry> = cache?.entries ?? {};\n const nextEntries: Record<string, DriftCacheEntry> = {};\n let cacheDirty = false;\n // Metadata mode does not open a stat-matched stream, so unreadable-after-stat\n // failures are intentionally deferred to strict validate/history-repair scans.\n const verifyCacheHitByContent = options.cacheHitVerification !== \"metadata\";\n\n for (const item of items) {\n const historyPath = getHistoryPath(pmRoot, item.id);\n\n let stat: Awaited<ReturnType<typeof fs.stat>>;\n try {\n stat = await fs.stat(historyPath);\n } catch (error: unknown) {\n if (isErrno(error, \"ENOENT\")) {\n missingStreams.push(item.id);\n } else {\n unreadableStreams.push(item.id);\n }\n continue;\n }\n\n const loadStreamVerification = async (): Promise<StreamVerification | null | \"unreadable\"> => {\n try {\n return await verifyHistoryStream(historyPath);\n } catch {\n return \"unreadable\";\n }\n };\n\n const loadFreshVerification = async (): Promise<StreamVerification | null> => {\n const loaded = await loadStreamVerification();\n if (loaded === \"unreadable\") {\n unreadableStreams.push(item.id);\n return null;\n }\n if (!loaded) {\n missingStreams.push(item.id);\n return null;\n }\n return loaded;\n };\n\n const cached = previousEntries[item.id];\n let verification: StreamVerification;\n const metadataMatchesCache =\n cached !== undefined &&\n cached.mtime_ms === stat.mtimeMs &&\n cached.ctime_ms === stat.ctimeMs &&\n cached.size === stat.size;\n const cachedContentHash =\n typeof cached?.content_hash === \"string\" && cached.content_hash.length > 0 ? cached.content_hash : undefined;\n const canUseCache = metadataMatchesCache && cachedContentHash !== undefined;\n if (canUseCache && cached) {\n let currentContentHash: string;\n if (verifyCacheHitByContent) {\n try {\n currentContentHash = await readHistoryContentHash(historyPath);\n } catch {\n unreadableStreams.push(item.id);\n continue;\n }\n } else {\n currentContentHash = cachedContentHash;\n }\n if (!verifyCacheHitByContent || currentContentHash === cachedContentHash) {\n verification = {\n latestAfterHash: cached.latest_after_hash,\n chainOk: cached.chain_ok,\n contentHash: currentContentHash,\n };\n } else {\n cacheDirty = true;\n const refreshed = await loadFreshVerification();\n if (!refreshed) {\n continue;\n }\n verification = refreshed;\n }\n } else {\n cacheDirty = true;\n const refreshed = await loadFreshVerification();\n if (!refreshed) {\n continue;\n }\n verification = refreshed;\n }\n\n if (!verification.chainOk) {\n chainMismatches.push(item.id);\n }\n nextEntries[item.id] = {\n mtime_ms: stat.mtimeMs,\n ctime_ms: stat.ctimeMs,\n size: stat.size,\n content_hash: verification.contentHash,\n latest_after_hash: verification.latestAfterHash,\n chain_ok: verification.chainOk,\n };\n\n const { body, ...frontMatter } = item;\n const currentHash = hashDocument({\n metadata: frontMatter as ItemMetadata,\n body,\n });\n if (currentHash !== verification.latestAfterHash) {\n hashMismatches.push(item.id);\n }\n }\n\n if (cacheDirty || Object.keys(previousEntries).length !== Object.keys(nextEntries).length) {\n const cachePath = getDriftCachePath(pmRoot);\n try {\n await fs.mkdir(path.dirname(cachePath), { recursive: true });\n await writeFileAtomic(cachePath, JSON.stringify({ version: DRIFT_CACHE_VERSION, entries: nextEntries }));\n } catch {\n // Best-effort cache write: a failed persist must never fail a health scan.\n }\n }\n\n const driftedItems = [...new Set([...missingStreams, ...unreadableStreams, ...hashMismatches, ...chainMismatches])].sort((a, b) =>\n a.localeCompare(b),\n );\n return { missingStreams, unreadableStreams, hashMismatches, chainMismatches, driftedItems };\n}\n"],"names":[],"mappings":"AAAA;;;;GAIG;;;AACH,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAcjD,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AA8BxD,SAAS,iBAAiB,CAAC,MAAc;IACvC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,oBAAoB,CAAC,CAAC;AAC5D,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,MAAc;IAC1C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAuB,CAAC;QACrD,IAAI,MAAM,CAAC,OAAO,KAAK,mBAAmB,IA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,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;QAC3G,CAAC;QAAC,MAAM,CAAC;YACP,2EAA2E;QAC7E,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,cAAc,EAAE,GAAG,iBAAiB,EAAE,GAAG,cAAc,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAChI,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CACnB,CAAC;IACF,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC;AAC9F,CAAC","debugId":"a928aad0-855f-5c7f-aa00-77d698ddca80"}
@@ -1,3 +1,4 @@
1
+ import { canonicalDocument } from "../item/item-format.js";
1
2
  import type { HistoryEntry, HistoryPatchOp, ItemDocument } from "../../types/index.js";
2
3
  /**
3
4
  * Shared history replay/patch mechanics single-sourced for the history, restore,
@@ -24,6 +25,12 @@ export declare function replayHash(document: ReplayDocument): string;
24
25
  * Implements replay to item document for the public runtime surface of this module.
25
26
  */
26
27
  export declare function replayToItemDocument(document: ReplayDocument): ItemDocument;
28
+ /**
29
+ * Converts a materialized replay document into a canonical item document. Use
30
+ * this when callers have already rejected the empty/deleted replay state and
31
+ * need restored metadata validated through the normal front-matter rules.
32
+ */
33
+ export declare function replayToCanonicalItemDocument(document: ReplayDocument, options?: Parameters<typeof canonicalDocument>[1]): ItemDocument;
27
34
  /**
28
35
  * Canonicalize an item document into the ordered replay form used when comparing
29
36
  * a replayed chain against the on-disk item (restore + history-repair reconciliation).
@@ -4,7 +4,7 @@
4
4
  * Implements append-only history and replay behavior for Replay.
5
5
  */
6
6
 
7
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="33ca44a2-2bb0-5ce8-8e1f-2c17e0c4e500")}catch(e){}}();
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="cf6461d3-7d73-5aa9-afa3-65f14d708e4c")}catch(e){}}();
8
8
  import jsonPatch from "fast-json-patch";
9
9
  import { FRONT_MATTER_KEY_ORDER } from "../shared/constants.js";
10
10
  import { canonicalDocument } from "../item/item-format.js";
@@ -26,10 +26,7 @@ export function cloneEmptyReplayDocument() {
26
26
  */
27
27
  export function replayHash(document) {
28
28
  try {
29
- return hashDocument({
30
- metadata: document.metadata,
31
- body: document.body,
32
- });
29
+ return hashDocument(replayToItemDocument(document));
33
30
  }
34
31
  catch {
35
32
  // Legacy/malformed replay states (for example a stream whose first entry never
@@ -50,6 +47,14 @@ export function replayToItemDocument(document) {
50
47
  body: document.body,
51
48
  };
52
49
  }
50
+ /**
51
+ * Converts a materialized replay document into a canonical item document. Use
52
+ * this when callers have already rejected the empty/deleted replay state and
53
+ * need restored metadata validated through the normal front-matter rules.
54
+ */
55
+ export function replayToCanonicalItemDocument(document, options = {}) {
56
+ return canonicalDocument(replayToItemDocument(document), options);
57
+ }
53
58
  /**
54
59
  * Canonicalize an item document into the ordered replay form used when comparing
55
60
  * a replayed chain against the on-disk item (restore + history-repair reconciliation).
@@ -279,4 +284,4 @@ export function historyEntriesToRaw(entries) {
279
284
  return `${entries.map((entry) => JSON.stringify(entry)).join("\n")}\n`;
280
285
  }
281
286
  //# sourceMappingURL=replay.js.map
282
- //# debugId=33ca44a2-2bb0-5ce8-8e1f-2c17e0c4e500
287
+ //# debugId=cf6461d3-7d73-5aa9-afa3-65f14d708e4c
@@ -1 +1 @@
1
- {"version":3,"file":"replay.js","sources":["core/history/replay.ts"],"sourceRoot":"/","sourcesContent":["/**\n * @module core/history/replay\n *\n * Implements append-only history and replay behavior for Replay.\n */\nimport jsonPatch from \"fast-json-patch\";\nimport { FRONT_MATTER_KEY_ORDER } from \"../shared/constants.js\";\nimport { canonicalDocument } from \"../item/item-format.js\";\nimport { toItemRecord } from \"../item/item-record.js\";\nimport { orderObject, sha256Hex, stableStringify } from \"../shared/serialization.js\";\nimport { hashDocument } from \"./history.js\";\nimport type { HistoryEntry, HistoryPatchOp, ItemDocument, ItemMetadata } from \"../../types/index.js\";\n\n/**\n * Shared history replay/patch mechanics single-sourced for the history, restore,\n * history-redact, and history-repair commands plus the health/validate drift checks.\n *\n * Each command keeps its own thin error-formatting wrapper so the exact CLI error\n * contracts (restore's rich patch-failure context, redact's op tag, history's\n * generic message) are preserved; only the underlying replay/patch logic is shared.\n */\n\nexport interface ReplayDocument {\n metadata: Record<string, unknown>;\n body: string;\n}\n\nexport const EMPTY_REPLAY_DOCUMENT: ReplayDocument = {\n metadata: {},\n body: \"\",\n};\n\n/**\n * Implements clone empty replay document for the public runtime surface of this module.\n */\nexport function cloneEmptyReplayDocument(): ReplayDocument {\n return structuredClone(EMPTY_REPLAY_DOCUMENT);\n}\n\n/**\n * Implements replay hash for the public runtime surface of this module.\n */\nexport function replayHash(document: ReplayDocument): string {\n try {\n return hashDocument({\n metadata: document.metadata as unknown as ItemMetadata,\n body: document.body,\n });\n } catch {\n // Legacy/malformed replay states (for example a stream whose first entry never\n // established a full `create` document, so the canonicalizer cannot normalize it)\n // cannot be canonically hashed. Fall back to a deterministic structural hash so\n // re-anchor and verification stay internally consistent for these streams. Fully\n // formed documents always take the canonical path above, so valid streams are\n // unaffected.\n return sha256Hex(stableStringify({ replay_fallback: true, metadata: document.metadata, body: document.body }));\n }\n}\n\n/**\n * Implements replay to item document for the public runtime surface of this module.\n */\nexport function replayToItemDocument(document: ReplayDocument): ItemDocument {\n return {\n metadata: document.metadata as unknown as ItemMetadata,\n body: document.body,\n };\n}\n\n/**\n * Canonicalize an item document into the ordered replay form used when comparing\n * a replayed chain against the on-disk item (restore + history-repair reconciliation).\n */\nexport function toReplayDocument(document: ItemDocument): ReplayDocument {\n if (!document.metadata || Object.keys(document.metadata).length === 0) {\n return {\n metadata: {},\n body: document.body ?? \"\",\n };\n }\n const canonical = canonicalDocument(document);\n return {\n metadata: orderObject(toItemRecord(canonical.metadata), FRONT_MATTER_KEY_ORDER),\n body: canonical.body,\n };\n}\n\n/**\n * Implements normalize replay patch path for the public runtime surface of this module.\n */\nexport function normalizeReplayPatchPath(path: string): string {\n if (path === \"/front_matter\") {\n return \"/metadata\";\n }\n if (path.startsWith(\"/front_matter/\")) {\n return `/metadata/${path.slice(\"/front_matter/\".length)}`;\n }\n return path;\n}\n\nfunction isHistoryPatchOp(value: unknown): value is HistoryPatchOp {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { op?: unknown }).op === \"string\" &&\n typeof (value as { path?: unknown }).path === \"string\"\n );\n}\n\n/**\n * Implements normalize replay patch ops for the public runtime surface of this module.\n */\nexport function normalizeReplayPatchOps(patch: HistoryPatchOp[] | unknown): HistoryPatchOp[] {\n if (!Array.isArray(patch)) {\n return [];\n }\n return patch.filter(isHistoryPatchOp).map((operation) => ({\n ...operation,\n path: normalizeReplayPatchPath(operation.path),\n from: typeof operation.from === \"string\" ? normalizeReplayPatchPath(operation.from) : undefined,\n }));\n}\n\nfunction isReplayDocumentShape(value: unknown): value is { metadata: Record<string, unknown>; body: string } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"metadata\" in value &&\n \"body\" in value &&\n typeof (value as { body: unknown }).body === \"string\" &&\n typeof (value as { metadata: unknown }).metadata === \"object\" &&\n (value as { metadata: unknown }).metadata !== null\n );\n}\n\n/**\n * Restricts replay apply result values accepted by command, SDK, and storage contracts.\n */\nexport type ReplayApplyResult =\n | { ok: true; document: ReplayDocument }\n | { ok: false; error: unknown };\n\n/**\n * Strictly apply a history patch (front_matter->metadata normalized) to a replay\n * document. Returns a result envelope rather than throwing so each caller can\n * format its own error contract.\n */\nexport function tryApplyReplayPatch(current: ReplayDocument, patch: HistoryPatchOp[]): ReplayApplyResult {\n try {\n const normalizedPatch = normalizeReplayPatchOps(patch);\n const applied = jsonPatch.applyPatch(\n structuredClone(current),\n normalizedPatch as jsonPatch.Operation[],\n true,\n false,\n ).newDocument as unknown;\n if (!isReplayDocumentShape(applied)) {\n return { ok: false, error: new Error(\"history_replay_invalid_document_shape\") };\n }\n return { ok: true, document: { metadata: applied.metadata, body: applied.body } };\n } catch (error) {\n return { ok: false, error };\n }\n}\n\n/**\n * Deterministically verify a history chain: each entry's before_hash must equal\n * the prior replayed after_hash, the patch must strictly apply, and the recorded\n * after_hash must equal the replayed result.\n */\nexport function verifyHistoryChain(entries: HistoryEntry[]): { ok: boolean; errors: string[] } {\n let replay = cloneEmptyReplayDocument();\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n if (replayHash(replay) !== entry.before_hash) {\n return {\n ok: false,\n errors: [`verify_failed:before_hash_mismatch:entry_${index + 1}`],\n };\n }\n const applied = tryApplyReplayPatch(replay, entry.patch);\n if (!applied.ok) {\n return {\n ok: false,\n errors: [`verify_failed:patch_apply_failed:entry_${index + 1}`],\n };\n }\n replay = applied.document;\n if (replayHash(replay) !== entry.after_hash) {\n return {\n ok: false,\n errors: [`verify_failed:after_hash_mismatch:entry_${index + 1}`],\n };\n }\n }\n return { ok: true, errors: [] };\n}\n\n/**\n * Documents the lenient apply result payload exchanged by command, SDK, and package integrations.\n */\nexport interface LenientApplyResult {\n document: ReplayDocument;\n convertedReplaceToAdd: number;\n skippedOps: number;\n}\n\nfunction tryApplySingleOp(document: unknown, op: HistoryPatchOp): { ok: true; document: unknown } | { ok: false } {\n try {\n const applied = jsonPatch.applyPatch(\n structuredClone(document),\n [op as jsonPatch.Operation],\n true,\n false,\n ).newDocument as unknown;\n return { ok: true, document: applied };\n } catch {\n return { ok: false };\n }\n}\n\n/**\n * Apply a legacy patch op-by-op, recovering from drift that strict replay rejects:\n * a `replace` whose path no longer exists is retried as `add`, and any op that\n * still cannot apply against the current replay state is skipped. The resulting\n * document is what the repaired entry's recomputed patch should target.\n */\nexport function lenientApplyReplayPatch(current: ReplayDocument, patch: HistoryPatchOp[]): LenientApplyResult {\n let working: unknown = structuredClone(current);\n let convertedReplaceToAdd = 0;\n let skippedOps = 0;\n\n for (const op of normalizeReplayPatchOps(patch)) {\n const direct = tryApplySingleOp(working, op);\n if (direct.ok) {\n working = direct.document;\n continue;\n }\n if (op.op === \"replace\") {\n const asAdd = tryApplySingleOp(working, { ...op, op: \"add\" });\n if (asAdd.ok) {\n working = asAdd.document;\n convertedReplaceToAdd += 1;\n continue;\n }\n }\n skippedOps += 1;\n }\n\n const candidate = working as { metadata?: unknown; body?: unknown };\n const document: ReplayDocument = {\n metadata:\n typeof candidate.metadata === \"object\" && candidate.metadata !== null\n ? (candidate.metadata as Record<string, unknown>)\n : {},\n body: typeof candidate.body === \"string\" ? candidate.body : current.body,\n };\n return { document, convertedReplaceToAdd, skippedOps };\n}\n\n/**\n * Documents the reanchor entry detail payload exchanged by command, SDK, and package integrations.\n */\nexport interface ReanchorEntryDetail {\n index: number;\n rehashed: boolean;\n patch_repaired: boolean;\n converted_replace_to_add: number;\n skipped_ops: number;\n}\n\n/**\n * Documents the reanchor result payload exchanged by command, SDK, and package integrations.\n */\nexport interface ReanchorResult {\n entries: HistoryEntry[];\n finalDocument: ReplayDocument;\n entriesRehashed: number;\n entriesPatchRepaired: number;\n convertedReplaceToAdd: number;\n skippedOps: number;\n details: ReanchorEntryDetail[];\n}\n\n/**\n * Re-anchor a drifted history chain: replay every entry from empty, recompute the\n * before/after hashes, and only rewrite a patch when the original op set no longer\n * strictly applies (legacy drift). Clean entries keep their patch verbatim so the\n * on-disk diff stays minimal. The returned chain verifies via verifyHistoryChain.\n */\nexport function reanchorHistoryEntries(entries: HistoryEntry[]): ReanchorResult {\n let replay = cloneEmptyReplayDocument();\n const rewritten: HistoryEntry[] = [];\n const details: ReanchorEntryDetail[] = [];\n let entriesRehashed = 0;\n let entriesPatchRepaired = 0;\n let convertedReplaceToAdd = 0;\n let skippedOps = 0;\n\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n const beforeHash = replayHash(replay);\n const strict = tryApplyReplayPatch(replay, entry.patch);\n\n let next: ReplayDocument;\n let outPatch: HistoryPatchOp[];\n let patchRepaired = false;\n let entryConverted = 0;\n let entrySkipped = 0;\n\n if (strict.ok) {\n next = strict.document;\n outPatch = entry.patch;\n } else {\n const lenient = lenientApplyReplayPatch(replay, entry.patch);\n next = lenient.document;\n outPatch = jsonPatch.compare(replay, next) as HistoryPatchOp[];\n patchRepaired = true;\n entryConverted = lenient.convertedReplaceToAdd;\n entrySkipped = lenient.skippedOps;\n convertedReplaceToAdd += entryConverted;\n skippedOps += entrySkipped;\n entriesPatchRepaired += 1;\n }\n\n const afterHash = replayHash(next);\n const rehashed = beforeHash !== entry.before_hash || afterHash !== entry.after_hash;\n if (rehashed) {\n entriesRehashed += 1;\n }\n\n rewritten.push({\n ...entry,\n patch: outPatch,\n before_hash: beforeHash,\n after_hash: afterHash,\n });\n details.push({\n index: index + 1,\n rehashed,\n patch_repaired: patchRepaired,\n converted_replace_to_add: entryConverted,\n skipped_ops: entrySkipped,\n });\n replay = next;\n }\n\n return {\n entries: rewritten,\n finalDocument: replay,\n entriesRehashed,\n entriesPatchRepaired,\n convertedReplaceToAdd,\n skippedOps,\n details,\n };\n}\n\n/**\n * Implements history entries to raw for the public runtime surface of this module.\n */\nexport function historyEntriesToRaw(entries: HistoryEntry[]): string {\n if (entries.length === 0) {\n return \"\";\n }\n return `${entries.map((entry) => JSON.stringify(entry)).join(\"\\n\")}\\n`;\n}\n"],"names":[],"mappings":"AAAA;;;;GAIG;;;AACH,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,sBA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CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACzE,CAAC","debugId":"33ca44a2-2bb0-5ce8-8e1f-2c17e0c4e500"}
1
+ {"version":3,"file":"replay.js","sources":["core/history/replay.ts"],"sourceRoot":"/","sourcesContent":["/**\n * @module core/history/replay\n *\n * Implements append-only history and replay behavior for Replay.\n */\nimport jsonPatch from \"fast-json-patch\";\nimport { FRONT_MATTER_KEY_ORDER } from \"../shared/constants.js\";\nimport { canonicalDocument } from \"../item/item-format.js\";\nimport { toItemRecord } from \"../item/item-record.js\";\nimport { orderObject, sha256Hex, stableStringify } from \"../shared/serialization.js\";\nimport { hashDocument } from \"./history.js\";\nimport type { HistoryEntry, HistoryPatchOp, ItemDocument, ItemMetadata } from \"../../types/index.js\";\n\n/**\n * Shared history replay/patch mechanics single-sourced for the history, restore,\n * history-redact, and history-repair commands plus the health/validate drift checks.\n *\n * Each command keeps its own thin error-formatting wrapper so the exact CLI error\n * contracts (restore's rich patch-failure context, redact's op tag, history's\n * generic message) are preserved; only the underlying replay/patch logic is shared.\n */\n\nexport interface ReplayDocument {\n metadata: Record<string, unknown>;\n body: string;\n}\n\nexport const EMPTY_REPLAY_DOCUMENT: ReplayDocument = {\n metadata: {},\n body: \"\",\n};\n\n/**\n * Implements clone empty replay document for the public runtime surface of this module.\n */\nexport function cloneEmptyReplayDocument(): ReplayDocument {\n return structuredClone(EMPTY_REPLAY_DOCUMENT);\n}\n\n/**\n * Implements replay hash for the public runtime surface of this module.\n */\nexport function replayHash(document: ReplayDocument): string {\n try {\n return hashDocument(replayToItemDocument(document));\n } catch {\n // Legacy/malformed replay states (for example a stream whose first entry never\n // established a full `create` document, so the canonicalizer cannot normalize it)\n // cannot be canonically hashed. Fall back to a deterministic structural hash so\n // re-anchor and verification stay internally consistent for these streams. Fully\n // formed documents always take the canonical path above, so valid streams are\n // unaffected.\n return sha256Hex(stableStringify({ replay_fallback: true, metadata: document.metadata, body: document.body }));\n }\n}\n\n/**\n * Implements replay to item document for the public runtime surface of this module.\n */\nexport function replayToItemDocument(document: ReplayDocument): ItemDocument {\n return {\n metadata: document.metadata as ItemMetadata,\n body: document.body,\n };\n}\n\n/**\n * Converts a materialized replay document into a canonical item document. Use\n * this when callers have already rejected the empty/deleted replay state and\n * need restored metadata validated through the normal front-matter rules.\n */\nexport function replayToCanonicalItemDocument(\n document: ReplayDocument,\n options: Parameters<typeof canonicalDocument>[1] = {},\n): ItemDocument {\n return canonicalDocument(replayToItemDocument(document), options);\n}\n\n/**\n * Canonicalize an item document into the ordered replay form used when comparing\n * a replayed chain against the on-disk item (restore + history-repair reconciliation).\n */\nexport function toReplayDocument(document: ItemDocument): ReplayDocument {\n if (!document.metadata || Object.keys(document.metadata).length === 0) {\n return {\n metadata: {},\n body: document.body ?? \"\",\n };\n }\n const canonical = canonicalDocument(document);\n return {\n metadata: orderObject(toItemRecord(canonical.metadata), FRONT_MATTER_KEY_ORDER),\n body: canonical.body,\n };\n}\n\n/**\n * Implements normalize replay patch path for the public runtime surface of this module.\n */\nexport function normalizeReplayPatchPath(path: string): string {\n if (path === \"/front_matter\") {\n return \"/metadata\";\n }\n if (path.startsWith(\"/front_matter/\")) {\n return `/metadata/${path.slice(\"/front_matter/\".length)}`;\n }\n return path;\n}\n\nfunction isHistoryPatchOp(value: unknown): value is HistoryPatchOp {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { op?: unknown }).op === \"string\" &&\n typeof (value as { path?: unknown }).path === \"string\"\n );\n}\n\n/**\n * Implements normalize replay patch ops for the public runtime surface of this module.\n */\nexport function normalizeReplayPatchOps(patch: HistoryPatchOp[] | unknown): HistoryPatchOp[] {\n if (!Array.isArray(patch)) {\n return [];\n }\n return patch.filter(isHistoryPatchOp).map((operation) => ({\n ...operation,\n path: normalizeReplayPatchPath(operation.path),\n from: typeof operation.from === \"string\" ? normalizeReplayPatchPath(operation.from) : undefined,\n }));\n}\n\nfunction isReplayDocumentShape(value: unknown): value is { metadata: Record<string, unknown>; body: string } {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"metadata\" in value &&\n \"body\" in value &&\n typeof (value as { body: unknown }).body === \"string\" &&\n typeof (value as { metadata: unknown }).metadata === \"object\" &&\n (value as { metadata: unknown }).metadata !== null\n );\n}\n\n/**\n * Restricts replay apply result values accepted by command, SDK, and storage contracts.\n */\nexport type ReplayApplyResult =\n | { ok: true; document: ReplayDocument }\n | { ok: false; error: unknown };\n\n/**\n * Strictly apply a history patch (front_matter->metadata normalized) to a replay\n * document. Returns a result envelope rather than throwing so each caller can\n * format its own error contract.\n */\nexport function tryApplyReplayPatch(current: ReplayDocument, patch: HistoryPatchOp[]): ReplayApplyResult {\n try {\n const normalizedPatch = normalizeReplayPatchOps(patch);\n const applied = jsonPatch.applyPatch(\n structuredClone(current),\n normalizedPatch as jsonPatch.Operation[],\n true,\n false,\n ).newDocument as unknown;\n if (!isReplayDocumentShape(applied)) {\n return { ok: false, error: new Error(\"history_replay_invalid_document_shape\") };\n }\n return { ok: true, document: { metadata: applied.metadata, body: applied.body } };\n } catch (error) {\n return { ok: false, error };\n }\n}\n\n/**\n * Deterministically verify a history chain: each entry's before_hash must equal\n * the prior replayed after_hash, the patch must strictly apply, and the recorded\n * after_hash must equal the replayed result.\n */\nexport function verifyHistoryChain(entries: HistoryEntry[]): { ok: boolean; errors: string[] } {\n let replay = cloneEmptyReplayDocument();\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n if (replayHash(replay) !== entry.before_hash) {\n return {\n ok: false,\n errors: [`verify_failed:before_hash_mismatch:entry_${index + 1}`],\n };\n }\n const applied = tryApplyReplayPatch(replay, entry.patch);\n if (!applied.ok) {\n return {\n ok: false,\n errors: [`verify_failed:patch_apply_failed:entry_${index + 1}`],\n };\n }\n replay = applied.document;\n if (replayHash(replay) !== entry.after_hash) {\n return {\n ok: false,\n errors: [`verify_failed:after_hash_mismatch:entry_${index + 1}`],\n };\n }\n }\n return { ok: true, errors: [] };\n}\n\n/**\n * Documents the lenient apply result payload exchanged by command, SDK, and package integrations.\n */\nexport interface LenientApplyResult {\n document: ReplayDocument;\n convertedReplaceToAdd: number;\n skippedOps: number;\n}\n\nfunction tryApplySingleOp(document: unknown, op: HistoryPatchOp): { ok: true; document: unknown } | { ok: false } {\n try {\n const applied = jsonPatch.applyPatch(\n structuredClone(document),\n [op as jsonPatch.Operation],\n true,\n false,\n ).newDocument as unknown;\n return { ok: true, document: applied };\n } catch {\n return { ok: false };\n }\n}\n\n/**\n * Apply a legacy patch op-by-op, recovering from drift that strict replay rejects:\n * a `replace` whose path no longer exists is retried as `add`, and any op that\n * still cannot apply against the current replay state is skipped. The resulting\n * document is what the repaired entry's recomputed patch should target.\n */\nexport function lenientApplyReplayPatch(current: ReplayDocument, patch: HistoryPatchOp[]): LenientApplyResult {\n let working: unknown = structuredClone(current);\n let convertedReplaceToAdd = 0;\n let skippedOps = 0;\n\n for (const op of normalizeReplayPatchOps(patch)) {\n const direct = tryApplySingleOp(working, op);\n if (direct.ok) {\n working = direct.document;\n continue;\n }\n if (op.op === \"replace\") {\n const asAdd = tryApplySingleOp(working, { ...op, op: \"add\" });\n if (asAdd.ok) {\n working = asAdd.document;\n convertedReplaceToAdd += 1;\n continue;\n }\n }\n skippedOps += 1;\n }\n\n const candidate = working as { metadata?: unknown; body?: unknown };\n const document: ReplayDocument = {\n metadata:\n typeof candidate.metadata === \"object\" && candidate.metadata !== null\n ? (candidate.metadata as Record<string, unknown>)\n : {},\n body: typeof candidate.body === \"string\" ? candidate.body : current.body,\n };\n return { document, convertedReplaceToAdd, skippedOps };\n}\n\n/**\n * Documents the reanchor entry detail payload exchanged by command, SDK, and package integrations.\n */\nexport interface ReanchorEntryDetail {\n index: number;\n rehashed: boolean;\n patch_repaired: boolean;\n converted_replace_to_add: number;\n skipped_ops: number;\n}\n\n/**\n * Documents the reanchor result payload exchanged by command, SDK, and package integrations.\n */\nexport interface ReanchorResult {\n entries: HistoryEntry[];\n finalDocument: ReplayDocument;\n entriesRehashed: number;\n entriesPatchRepaired: number;\n convertedReplaceToAdd: number;\n skippedOps: number;\n details: ReanchorEntryDetail[];\n}\n\n/**\n * Re-anchor a drifted history chain: replay every entry from empty, recompute the\n * before/after hashes, and only rewrite a patch when the original op set no longer\n * strictly applies (legacy drift). Clean entries keep their patch verbatim so the\n * on-disk diff stays minimal. The returned chain verifies via verifyHistoryChain.\n */\nexport function reanchorHistoryEntries(entries: HistoryEntry[]): ReanchorResult {\n let replay = cloneEmptyReplayDocument();\n const rewritten: HistoryEntry[] = [];\n const details: ReanchorEntryDetail[] = [];\n let entriesRehashed = 0;\n let entriesPatchRepaired = 0;\n let convertedReplaceToAdd = 0;\n let skippedOps = 0;\n\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n const beforeHash = replayHash(replay);\n const strict = tryApplyReplayPatch(replay, entry.patch);\n\n let next: ReplayDocument;\n let outPatch: HistoryPatchOp[];\n let patchRepaired = false;\n let entryConverted = 0;\n let entrySkipped = 0;\n\n if (strict.ok) {\n next = strict.document;\n outPatch = entry.patch;\n } else {\n const lenient = lenientApplyReplayPatch(replay, entry.patch);\n next = lenient.document;\n outPatch = jsonPatch.compare(replay, next) as HistoryPatchOp[];\n patchRepaired = true;\n entryConverted = lenient.convertedReplaceToAdd;\n entrySkipped = lenient.skippedOps;\n convertedReplaceToAdd += entryConverted;\n skippedOps += entrySkipped;\n entriesPatchRepaired += 1;\n }\n\n const afterHash = replayHash(next);\n const rehashed = beforeHash !== entry.before_hash || afterHash !== entry.after_hash;\n if (rehashed) {\n entriesRehashed += 1;\n }\n\n rewritten.push({\n ...entry,\n patch: outPatch,\n before_hash: beforeHash,\n after_hash: afterHash,\n });\n details.push({\n index: index + 1,\n rehashed,\n patch_repaired: patchRepaired,\n converted_replace_to_add: entryConverted,\n skipped_ops: entrySkipped,\n });\n replay = next;\n }\n\n return {\n entries: rewritten,\n finalDocument: replay,\n entriesRehashed,\n entriesPatchRepaired,\n convertedReplaceToAdd,\n skippedOps,\n details,\n };\n}\n\n/**\n * Implements history entries to raw for the public runtime surface of this module.\n */\nexport function historyEntriesToRaw(entries: HistoryEntry[]): string {\n if (entries.length === 0) {\n return \"\";\n }\n return `${entries.map((entry) => JSON.stringify(entry)).join(\"\\n\")}\\n`;\n}\n"],"names":[],"mappings":"AAAA;;;;GAIG;;;AACH,OAAO,SAAS,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAiB5C,MAAM,CAAC,MAAM,qBAAqB,GAAmB;IACnD,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,EAAE;CACT,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,eAAe,CAAC,qBAAqB,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,QAAwB;IACjD,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtD,CAAC;IAAC,MAAM,CAAC;QACP,+EAA+E;QAC/E,kFAAkF;QAClF,gFAAgF;QAChF,iFAAiF;QACjF,8EAA8E;QAC9E,cAAc;QACd,OAAO,SAAS,CAAC,eAAe,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IACjH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAwB;IAC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AC;QACH,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACL,OAAO,EAAE,SAAS;QAClB,aAAa,EAAE,MAAM;QACrB,eAAe;QACf,oBAAoB;QACpB,qBAAqB;QACrB,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAuB;IACzD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACzE,CAAC","debugId":"cf6461d3-7d73-5aa9-afa3-65f14d708e4c"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * @module core/item/item-format-version
3
+ *
4
+ * Tracks the on-disk item front-matter format version so a future breaking
5
+ * storage change can tell already-current items apart from items that a staged
6
+ * migration must rewrite, without re-parsing and structurally guessing every
7
+ * file. The version is an explicit, monotonically increasing integer stamped in
8
+ * front-matter as `pm_format_version`.
9
+ *
10
+ * Token economy is a first-class constraint here: the baseline version (1) is
11
+ * the implicit default and is never serialized, so today's corpus gains zero
12
+ * bytes and zero churn. The field only materializes once an item reaches
13
+ * version 2 or higher. Absence of the field is therefore always interpreted as
14
+ * the baseline version, both now and after future bumps. The classification
15
+ * helpers below power the advisory `pm health` integrity surface and the
16
+ * `pm validate` format-version check.
17
+ */
18
+ import type { ItemMetadata } from "../../types/index.js";
19
+ /**
20
+ * The original (and implicit) item front-matter format version. Items missing a
21
+ * `pm_format_version` field are always treated as this version, so the baseline
22
+ * is never written to disk and adds no per-item token cost.
23
+ */
24
+ export declare const BASELINE_ITEM_FORMAT_VERSION = 1;
25
+ /**
26
+ * The format version this runtime writes and considers current. When a breaking
27
+ * front-matter change ships, bump this constant and add a migration that
28
+ * rewrites items whose {@link effectiveItemFormatVersion} is lower; items at or
29
+ * above it need no migration. It stays equal to
30
+ * {@link BASELINE_ITEM_FORMAT_VERSION} until the first such change.
31
+ */
32
+ export declare const CURRENT_ITEM_FORMAT_VERSION = 1;
33
+ /**
34
+ * Resolve the format version an item is effectively stored at. A present,
35
+ * positive-integer `pm_format_version` is taken verbatim (including versions
36
+ * ahead of this runtime, so they can be flagged rather than silently clamped);
37
+ * an absent, malformed, or sub-baseline value resolves to
38
+ * {@link BASELINE_ITEM_FORMAT_VERSION}.
39
+ */
40
+ export declare function effectiveItemFormatVersion(metadata: Pick<ItemMetadata, "pm_format_version">): number;
41
+ /**
42
+ * Reduce an item's `pm_format_version` to its persisted form: the baseline
43
+ * version (and any malformed or sub-baseline value) is dropped so it is never
44
+ * serialized, while versions at or above {@link BASELINE_ITEM_FORMAT_VERSION}
45
+ * plus one are preserved verbatim. This keeps the field absent for the entire
46
+ * current corpus and only writes it once an item genuinely advances past the
47
+ * implicit baseline.
48
+ */
49
+ export declare function normalizeItemFormatVersion(value: unknown): number | undefined;
50
+ /**
51
+ * Relationship between an item's stored format version and the runtime's
52
+ * current version: `outdated` (below current, a migration would rewrite it),
53
+ * `ahead` (above current, written by a newer pm than this one), or `current`.
54
+ */
55
+ export type ItemFormatVersionStatus = "current" | "outdated" | "ahead";
56
+ /**
57
+ * Classify a single stored format version against the runtime's current
58
+ * version. Defaults to {@link CURRENT_ITEM_FORMAT_VERSION}; the `current`
59
+ * parameter exists so callers (and tests) can evaluate against a hypothetical
60
+ * future version without mutating the module constant.
61
+ */
62
+ export declare function classifyItemFormatVersion(version: number, current?: number): ItemFormatVersionStatus;
63
+ /**
64
+ * One item's reference (id or relative path) paired with the format version it
65
+ * is stored at, used as input to {@link scanItemFormatVersions}.
66
+ */
67
+ export interface ItemFormatVersionScanEntry {
68
+ ref: string;
69
+ version: number;
70
+ }
71
+ /**
72
+ * Sorted references partitioned by how their stored format version compares to
73
+ * the runtime's current version. References at the current version are omitted
74
+ * from both lists.
75
+ */
76
+ export interface ItemFormatVersionScanResult {
77
+ outdated: string[];
78
+ ahead: string[];
79
+ }
80
+ /**
81
+ * Partition a set of items by format version into `outdated` (need migration)
82
+ * and `ahead` (written by a newer pm) reference lists, each sorted for stable
83
+ * diagnostics. Pushing all comparison branches into this pure, exhaustively
84
+ * tested helper lets `pm health` and `pm validate` emit findings by iterating
85
+ * the result lists, with no version-comparison branching of their own.
86
+ */
87
+ export declare function scanItemFormatVersions(entries: readonly ItemFormatVersionScanEntry[], current?: number): ItemFormatVersionScanResult;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The original (and implicit) item front-matter format version. Items missing a
3
+ * `pm_format_version` field are always treated as this version, so the baseline
4
+ * is never written to disk and adds no per-item token cost.
5
+ */
6
+
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f0e67d63-2f7b-5f4a-b441-7a499c82e0a8")}catch(e){}}();
8
+ export const BASELINE_ITEM_FORMAT_VERSION = 1;
9
+ /**
10
+ * The format version this runtime writes and considers current. When a breaking
11
+ * front-matter change ships, bump this constant and add a migration that
12
+ * rewrites items whose {@link effectiveItemFormatVersion} is lower; items at or
13
+ * above it need no migration. It stays equal to
14
+ * {@link BASELINE_ITEM_FORMAT_VERSION} until the first such change.
15
+ */
16
+ export const CURRENT_ITEM_FORMAT_VERSION = 1;
17
+ /**
18
+ * Resolve the format version an item is effectively stored at. A present,
19
+ * positive-integer `pm_format_version` is taken verbatim (including versions
20
+ * ahead of this runtime, so they can be flagged rather than silently clamped);
21
+ * an absent, malformed, or sub-baseline value resolves to
22
+ * {@link BASELINE_ITEM_FORMAT_VERSION}.
23
+ */
24
+ export function effectiveItemFormatVersion(metadata) {
25
+ const raw = metadata.pm_format_version;
26
+ if (typeof raw === "number" && Number.isInteger(raw) && raw >= BASELINE_ITEM_FORMAT_VERSION) {
27
+ return raw;
28
+ }
29
+ return BASELINE_ITEM_FORMAT_VERSION;
30
+ }
31
+ /**
32
+ * Reduce an item's `pm_format_version` to its persisted form: the baseline
33
+ * version (and any malformed or sub-baseline value) is dropped so it is never
34
+ * serialized, while versions at or above {@link BASELINE_ITEM_FORMAT_VERSION}
35
+ * plus one are preserved verbatim. This keeps the field absent for the entire
36
+ * current corpus and only writes it once an item genuinely advances past the
37
+ * implicit baseline.
38
+ */
39
+ export function normalizeItemFormatVersion(value) {
40
+ if (typeof value !== "number" || !Number.isInteger(value) || value <= BASELINE_ITEM_FORMAT_VERSION) {
41
+ return undefined;
42
+ }
43
+ return value;
44
+ }
45
+ /**
46
+ * Classify a single stored format version against the runtime's current
47
+ * version. Defaults to {@link CURRENT_ITEM_FORMAT_VERSION}; the `current`
48
+ * parameter exists so callers (and tests) can evaluate against a hypothetical
49
+ * future version without mutating the module constant.
50
+ */
51
+ export function classifyItemFormatVersion(version, current = CURRENT_ITEM_FORMAT_VERSION) {
52
+ if (version < current) {
53
+ return "outdated";
54
+ }
55
+ if (version > current) {
56
+ return "ahead";
57
+ }
58
+ return "current";
59
+ }
60
+ /**
61
+ * Partition a set of items by format version into `outdated` (need migration)
62
+ * and `ahead` (written by a newer pm) reference lists, each sorted for stable
63
+ * diagnostics. Pushing all comparison branches into this pure, exhaustively
64
+ * tested helper lets `pm health` and `pm validate` emit findings by iterating
65
+ * the result lists, with no version-comparison branching of their own.
66
+ */
67
+ export function scanItemFormatVersions(entries, current = CURRENT_ITEM_FORMAT_VERSION) {
68
+ const outdated = [];
69
+ const ahead = [];
70
+ for (const entry of entries) {
71
+ const status = classifyItemFormatVersion(entry.version, current);
72
+ if (status === "outdated") {
73
+ outdated.push(entry.ref);
74
+ }
75
+ else if (status === "ahead") {
76
+ ahead.push(entry.ref);
77
+ }
78
+ }
79
+ return {
80
+ outdated: outdated.sort((left, right) => left.localeCompare(right)),
81
+ ahead: ahead.sort((left, right) => left.localeCompare(right)),
82
+ };
83
+ }
84
+ //# sourceMappingURL=item-format-version.js.map
85
+ //# debugId=f0e67d63-2f7b-5f4a-b441-7a499c82e0a8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-format-version.js","sources":["core/item/item-format-version.ts"],"sourceRoot":"/","sourcesContent":["/**\n * @module core/item/item-format-version\n *\n * Tracks the on-disk item front-matter format version so a future breaking\n * storage change can tell already-current items apart from items that a staged\n * migration must rewrite, without re-parsing and structurally guessing every\n * file. The version is an explicit, monotonically increasing integer stamped in\n * front-matter as `pm_format_version`.\n *\n * Token economy is a first-class constraint here: the baseline version (1) is\n * the implicit default and is never serialized, so today's corpus gains zero\n * bytes and zero churn. The field only materializes once an item reaches\n * version 2 or higher. Absence of the field is therefore always interpreted as\n * the baseline version, both now and after future bumps. The classification\n * helpers below power the advisory `pm health` integrity surface and the\n * `pm validate` format-version check.\n */\nimport type { ItemMetadata } from \"../../types/index.js\";\n\n/**\n * The original (and implicit) item front-matter format version. Items missing a\n * `pm_format_version` field are always treated as this version, so the baseline\n * is never written to disk and adds no per-item token cost.\n */\nexport const BASELINE_ITEM_FORMAT_VERSION = 1;\n\n/**\n * The format version this runtime writes and considers current. When a breaking\n * front-matter change ships, bump this constant and add a migration that\n * rewrites items whose {@link effectiveItemFormatVersion} is lower; items at or\n * above it need no migration. It stays equal to\n * {@link BASELINE_ITEM_FORMAT_VERSION} until the first such change.\n */\nexport const CURRENT_ITEM_FORMAT_VERSION = 1;\n\n/**\n * Resolve the format version an item is effectively stored at. A present,\n * positive-integer `pm_format_version` is taken verbatim (including versions\n * ahead of this runtime, so they can be flagged rather than silently clamped);\n * an absent, malformed, or sub-baseline value resolves to\n * {@link BASELINE_ITEM_FORMAT_VERSION}.\n */\nexport function effectiveItemFormatVersion(metadata: Pick<ItemMetadata, \"pm_format_version\">): number {\n const raw = metadata.pm_format_version;\n if (typeof raw === \"number\" && Number.isInteger(raw) && raw >= BASELINE_ITEM_FORMAT_VERSION) {\n return raw;\n }\n return BASELINE_ITEM_FORMAT_VERSION;\n}\n\n/**\n * Reduce an item's `pm_format_version` to its persisted form: the baseline\n * version (and any malformed or sub-baseline value) is dropped so it is never\n * serialized, while versions at or above {@link BASELINE_ITEM_FORMAT_VERSION}\n * plus one are preserved verbatim. This keeps the field absent for the entire\n * current corpus and only writes it once an item genuinely advances past the\n * implicit baseline.\n */\nexport function normalizeItemFormatVersion(value: unknown): number | undefined {\n if (typeof value !== \"number\" || !Number.isInteger(value) || value <= BASELINE_ITEM_FORMAT_VERSION) {\n return undefined;\n }\n return value;\n}\n\n/**\n * Relationship between an item's stored format version and the runtime's\n * current version: `outdated` (below current, a migration would rewrite it),\n * `ahead` (above current, written by a newer pm than this one), or `current`.\n */\nexport type ItemFormatVersionStatus = \"current\" | \"outdated\" | \"ahead\";\n\n/**\n * Classify a single stored format version against the runtime's current\n * version. Defaults to {@link CURRENT_ITEM_FORMAT_VERSION}; the `current`\n * parameter exists so callers (and tests) can evaluate against a hypothetical\n * future version without mutating the module constant.\n */\nexport function classifyItemFormatVersion(\n version: number,\n current: number = CURRENT_ITEM_FORMAT_VERSION,\n): ItemFormatVersionStatus {\n if (version < current) {\n return \"outdated\";\n }\n if (version > current) {\n return \"ahead\";\n }\n return \"current\";\n}\n\n/**\n * One item's reference (id or relative path) paired with the format version it\n * is stored at, used as input to {@link scanItemFormatVersions}.\n */\nexport interface ItemFormatVersionScanEntry {\n ref: string;\n version: number;\n}\n\n/**\n * Sorted references partitioned by how their stored format version compares to\n * the runtime's current version. References at the current version are omitted\n * from both lists.\n */\nexport interface ItemFormatVersionScanResult {\n outdated: string[];\n ahead: string[];\n}\n\n/**\n * Partition a set of items by format version into `outdated` (need migration)\n * and `ahead` (written by a newer pm) reference lists, each sorted for stable\n * diagnostics. Pushing all comparison branches into this pure, exhaustively\n * tested helper lets `pm health` and `pm validate` emit findings by iterating\n * the result lists, with no version-comparison branching of their own.\n */\nexport function scanItemFormatVersions(\n entries: readonly ItemFormatVersionScanEntry[],\n current: number = CURRENT_ITEM_FORMAT_VERSION,\n): ItemFormatVersionScanResult {\n const outdated: string[] = [];\n const ahead: string[] = [];\n for (const entry of entries) {\n const status = classifyItemFormatVersion(entry.version, current);\n if (status === \"outdated\") {\n outdated.push(entry.ref);\n } else if (status === \"ahead\") {\n ahead.push(entry.ref);\n }\n }\n return {\n outdated: outdated.sort((left, right) => left.localeCompare(right)),\n ahead: ahead.sort((left, right) => left.localeCompare(right)),\n };\n}\n"],"names":[],"mappings":"AAmBA;;;;GAIG;;;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,QAAiD;IAC1F,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,CAAC;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,4BAA4B,EAAE,CAAC;QAC5F,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,4BAA4B,CAAC;AACtC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,4BAA4B,EAAE,CAAC;QACnG,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AASD;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAe,EACf,UAAkB,2BAA2B;IAE7C,IAAI,OAAO,GAAG,OAAO,EAAE,CAAC;QACtB,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,IAAI,OAAO,GAAG,OAAO,EAAE,CAAC;QACtB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAqBD;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAA8C,EAC9C,UAAkB,2BAA2B;IAE7C,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,yBAAyB,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjE,IAAI,MAAM,KAAK,UAAU,EAAE,CAAC;YAC1B,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;aAAM,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IACD,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACnE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;KAC9D,CAAC;AACJ,CAAC","debugId":"f0e67d63-2f7b-5f4a-b441-7a499c82e0a8"}
@@ -4,11 +4,12 @@
4
4
  * Defines item parsing, formatting, and lifecycle helpers for Item Format.
5
5
  */
6
6
 
7
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c295802c-f55f-56e8-afdc-257cdef6a4cb")}catch(e){}}();
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="777ea2a9-5aa6-5a90-abb5-a0b6052645f2")}catch(e){}}();
8
8
  import { encode as encodeToon } from "@toon-format/toon";
9
9
  import { CONFIDENCE_TEXT_VALUES, ISSUE_SEVERITY_VALUES, RECURRENCE_FREQUENCY_VALUES, RECURRENCE_WEEKDAY_VALUES, STATUS_VALUES, weekdayOrderIndex, } from "../../types/index.js";
10
10
  import { coerceRuntimeFieldValue } from "../schema/runtime-field-values.js";
11
11
  import { resolveRuntimeFieldRegistry, resolveRuntimeStatusRegistry, } from "../schema/runtime-schema.js";
12
+ import { BASELINE_ITEM_FORMAT_VERSION, normalizeItemFormatVersion } from "./item-format-version.js";
12
13
  import { normalizeStatusInput } from "./status.js";
13
14
  import { decodeToonItemContent } from "./toon-decode.js";
14
15
  import { EXIT_CODE, FRONT_MATTER_KEY_ORDER } from "../shared/constants.js";
@@ -129,6 +130,10 @@ function assertValidFrontMatter(frontMatter, runtimeContext) {
129
130
  }
130
131
  const itemType = record.type;
131
132
  assertFrontMatterCondition(typeof itemType === "string" && itemType.trim().length > 0, "type must be a non-empty string");
133
+ const formatVersion = record.pm_format_version;
134
+ if (formatVersion !== undefined) {
135
+ assertFrontMatterCondition(typeof formatVersion === "number" && Number.isInteger(formatVersion) && formatVersion >= BASELINE_ITEM_FORMAT_VERSION, `pm_format_version must be an integer >= ${BASELINE_ITEM_FORMAT_VERSION}`);
136
+ }
132
137
  const status = record.status;
133
138
  assertFrontMatterCondition(typeof status === "string" && status.trim().length > 0, "status must be a non-empty string");
134
139
  const statusRegistry = runtimeContext?.statusRegistry;
@@ -849,6 +854,7 @@ export function normalizeFrontMatter(frontMatter, options = {}) {
849
854
  title: frontMatter.title,
850
855
  description: frontMatter.description,
851
856
  type: frontMatter.type,
857
+ pm_format_version: normalizeItemFormatVersion(frontMatter.pm_format_version),
852
858
  source_type: frontMatter.source_type?.trim() || undefined,
853
859
  type_options: normalizeTypeOptions(frontMatter.type_options),
854
860
  status: normalizedStatus,
@@ -1149,4 +1155,4 @@ export const _testOnlyItemFormat = {
1149
1155
  sortTests,
1150
1156
  };
1151
1157
  //# sourceMappingURL=item-format.js.map
1152
- //# debugId=c295802c-f55f-56e8-afdc-257cdef6a4cb
1158
+ //# debugId=777ea2a9-5aa6-5a90-abb5-a0b6052645f2