@unbrained/pm-cli 2026.7.6 → 2026.7.7

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 (666) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/cli/commands/annotation-command.d.ts +1 -0
  3. package/dist/cli/commands/annotation-command.js +29 -2
  4. package/dist/cli/commands/annotation-command.js.map +1 -1
  5. package/dist/cli/commands/comments.js +3 -4
  6. package/dist/cli/commands/comments.js.map +1 -1
  7. package/dist/cli/commands/extension/bundled-catalog.d.ts +3 -0
  8. package/dist/cli/commands/extension/bundled-catalog.js +38 -28
  9. package/dist/cli/commands/extension/bundled-catalog.js.map +1 -1
  10. package/dist/cli/commands/extension/install-sources.js +81 -18
  11. package/dist/cli/commands/extension/install-sources.js.map +1 -1
  12. package/dist/cli/commands/health.js +9 -5
  13. package/dist/cli/commands/health.js.map +1 -1
  14. package/dist/cli/commands/learnings.js +5 -3
  15. package/dist/cli/commands/learnings.js.map +1 -1
  16. package/dist/cli/commands/notes.js +5 -3
  17. package/dist/cli/commands/notes.js.map +1 -1
  18. package/dist/cli/commands/reindex.js +4 -3
  19. package/dist/cli/commands/reindex.js.map +1 -1
  20. package/dist/cli/commands/search.js +3 -3
  21. package/dist/cli/commands/search.js.map +1 -1
  22. package/dist/cli/commands/test.d.ts +9 -0
  23. package/dist/cli/commands/test.js +144 -105
  24. package/dist/cli/commands/test.js.map +1 -1
  25. package/dist/cli/extension-command-help.js +10 -2
  26. package/dist/cli/extension-command-help.js.map +1 -1
  27. package/dist/cli/register-list-query.d.ts +1 -1
  28. package/dist/cli/register-list-query.js +18 -27
  29. package/dist/cli/register-list-query.js.map +1 -1
  30. package/dist/cli/register-operations.d.ts +0 -8
  31. package/dist/cli/register-operations.js +41 -46
  32. package/dist/cli/register-operations.js.map +1 -1
  33. package/dist/cli/register-setup.js +113 -13
  34. package/dist/cli/register-setup.js.map +1 -1
  35. package/dist/cli/registration-helpers.d.ts +5 -1
  36. package/dist/cli/registration-helpers.js +14 -2
  37. package/dist/cli/registration-helpers.js.map +1 -1
  38. package/dist/cli-bundle/chunks/append-F7WPGIQL.js +11 -0
  39. package/dist/cli-bundle/chunks/{gc-2DNMPXMC.js → append-PVCTBVJG.js} +8 -9
  40. package/dist/cli-bundle/chunks/{chunk-EGAP5OWD.js → chunk-2APXX4TZ.js} +16 -14
  41. package/dist/cli-bundle/chunks/chunk-2APXX4TZ.js.map +1 -0
  42. package/dist/cli-bundle/chunks/{chunk-R5BMJX33.js → chunk-2LEJGRQ7.js} +2 -2
  43. package/dist/cli-bundle/chunks/{chunk-AZYGZGGI.js → chunk-2TILG6F2.js} +3 -3
  44. package/dist/cli-bundle/chunks/{chunk-SMB7RV23.js → chunk-3G6UMXT3.js} +6 -8
  45. package/dist/cli-bundle/chunks/{chunk-SMB7RV23.js.map → chunk-3G6UMXT3.js.map} +1 -1
  46. package/dist/cli-bundle/chunks/{chunk-GJ7QC5DJ.js → chunk-3TYOW6RR.js} +8 -8
  47. package/dist/cli-bundle/chunks/{chunk-B6DUFX6H.js → chunk-3X542TEY.js} +7 -7
  48. package/dist/cli-bundle/chunks/{chunk-B6XS3R3O.js → chunk-42LXP4VO.js} +12 -16
  49. package/dist/cli-bundle/chunks/{chunk-B6XS3R3O.js.map → chunk-42LXP4VO.js.map} +1 -1
  50. package/dist/cli-bundle/chunks/{chunk-CL36D4PC.js → chunk-43SIHQND.js} +36 -15
  51. package/dist/cli-bundle/chunks/chunk-43SIHQND.js.map +7 -0
  52. package/dist/cli-bundle/chunks/{chunk-7D7OOEYG.js → chunk-43UQN754.js} +10 -14
  53. package/dist/cli-bundle/chunks/{chunk-7D7OOEYG.js.map → chunk-43UQN754.js.map} +1 -1
  54. package/dist/cli-bundle/chunks/{chunk-ALFPSEWO.js → chunk-43YSKY75.js} +4 -6
  55. package/dist/cli-bundle/chunks/{chunk-ALFPSEWO.js.map → chunk-43YSKY75.js.map} +1 -1
  56. package/dist/cli-bundle/chunks/{chunk-NO442GWJ.js → chunk-4BKDAEDF.js} +5 -5
  57. package/dist/cli-bundle/chunks/{chunk-NO442GWJ.js.map → chunk-4BKDAEDF.js.map} +2 -2
  58. package/dist/cli-bundle/chunks/{chunk-4LELACOL.js → chunk-4IQKDKGE.js} +15 -23
  59. package/dist/cli-bundle/chunks/{chunk-4LELACOL.js.map → chunk-4IQKDKGE.js.map} +1 -1
  60. package/dist/cli-bundle/chunks/{chunk-F3K4JGFD.js → chunk-4MZOKTI2.js} +6 -8
  61. package/dist/cli-bundle/chunks/{chunk-F3K4JGFD.js.map → chunk-4MZOKTI2.js.map} +1 -1
  62. package/dist/cli-bundle/chunks/{chunk-D2XRLB55.js → chunk-52NS7JDP.js} +14 -20
  63. package/dist/cli-bundle/chunks/{chunk-D2XRLB55.js.map → chunk-52NS7JDP.js.map} +1 -1
  64. package/dist/cli-bundle/chunks/{chunk-IX5BXEMX.js → chunk-565WYS5W.js} +12 -16
  65. package/dist/cli-bundle/chunks/{chunk-IX5BXEMX.js.map → chunk-565WYS5W.js.map} +1 -1
  66. package/dist/cli-bundle/chunks/{chunk-UH7T2DAX.js → chunk-5FIQ4EX3.js} +12 -18
  67. package/dist/cli-bundle/chunks/{chunk-UH7T2DAX.js.map → chunk-5FIQ4EX3.js.map} +1 -1
  68. package/dist/cli-bundle/chunks/{chunk-DMRNBQOI.js → chunk-6G6O3OPQ.js} +256 -36
  69. package/dist/cli-bundle/chunks/chunk-6G6O3OPQ.js.map +1 -0
  70. package/dist/cli-bundle/chunks/{chunk-G64OCSKU.js → chunk-6LCJRGPD.js} +9 -13
  71. package/dist/cli-bundle/chunks/{chunk-G64OCSKU.js.map → chunk-6LCJRGPD.js.map} +1 -1
  72. package/dist/cli-bundle/chunks/{chunk-7WBAJSS6.js → chunk-6UQCNWFV.js} +6 -8
  73. package/dist/cli-bundle/chunks/{chunk-7WBAJSS6.js.map → chunk-6UQCNWFV.js.map} +1 -1
  74. package/dist/cli-bundle/chunks/{chunk-ZSUS2OD3.js → chunk-6XTSYPPO.js} +1216 -387
  75. package/dist/cli-bundle/chunks/chunk-6XTSYPPO.js.map +7 -0
  76. package/dist/cli-bundle/chunks/chunk-7ML7JONU.js +5434 -0
  77. package/dist/cli-bundle/chunks/chunk-7ML7JONU.js.map +1 -0
  78. package/dist/cli-bundle/chunks/{chunk-ZZD4J5XY.js → chunk-7PNQA24K.js} +30 -36
  79. package/dist/cli-bundle/chunks/{chunk-ZZD4J5XY.js.map → chunk-7PNQA24K.js.map} +1 -1
  80. package/dist/cli-bundle/chunks/{chunk-JJP45OEI.js → chunk-7VQ3JJN5.js} +2 -2
  81. package/dist/cli-bundle/chunks/{chunk-OGWQ2IEP.js → chunk-7Y5N34HX.js} +8 -12
  82. package/dist/cli-bundle/chunks/{chunk-OGWQ2IEP.js.map → chunk-7Y5N34HX.js.map} +1 -1
  83. package/dist/cli-bundle/chunks/{chunk-MWMVPCIE.js → chunk-AGAVEDIE.js} +7 -7
  84. package/dist/cli-bundle/chunks/{chunk-22KBU3MW.js → chunk-AJUON7E6.js} +3 -3
  85. package/dist/cli-bundle/chunks/{chunk-ZJ262CED.js → chunk-ARKHKYYS.js} +13 -21
  86. package/dist/cli-bundle/chunks/{chunk-ZJ262CED.js.map → chunk-ARKHKYYS.js.map} +1 -1
  87. package/dist/cli-bundle/chunks/{chunk-46CUF5L6.js → chunk-C5ACVMOI.js} +99 -51
  88. package/dist/cli-bundle/chunks/chunk-C5ACVMOI.js.map +7 -0
  89. package/dist/cli-bundle/chunks/{chunk-LPSSSDJR.js → chunk-CJQM7O7R.js} +16 -20
  90. package/dist/cli-bundle/chunks/{chunk-LPSSSDJR.js.map → chunk-CJQM7O7R.js.map} +1 -1
  91. package/dist/cli-bundle/chunks/{chunk-GBAX2ZAQ.js → chunk-D2DCTFTL.js} +10 -12
  92. package/dist/cli-bundle/chunks/{chunk-GBAX2ZAQ.js.map → chunk-D2DCTFTL.js.map} +1 -1
  93. package/dist/cli-bundle/chunks/{chunk-XHET7YUZ.js → chunk-DDDWVPID.js} +8 -10
  94. package/dist/cli-bundle/chunks/{chunk-XHET7YUZ.js.map → chunk-DDDWVPID.js.map} +1 -1
  95. package/dist/cli-bundle/chunks/{chunk-HIHMT6WS.js → chunk-DG6BSXZ7.js} +5 -5
  96. package/dist/cli-bundle/chunks/{chunk-HIHMT6WS.js.map → chunk-DG6BSXZ7.js.map} +2 -2
  97. package/dist/cli-bundle/chunks/{chunk-IWVU4C2F.js → chunk-DR2V5OIV.js} +3 -3
  98. package/dist/cli-bundle/chunks/{chunk-ZGK4L4JM.js → chunk-E3LWJUGF.js} +4 -6
  99. package/dist/cli-bundle/chunks/{chunk-ZGK4L4JM.js.map → chunk-E3LWJUGF.js.map} +1 -1
  100. package/dist/cli-bundle/chunks/{chunk-XUC7PI2H.js → chunk-E3YQFSFE.js} +6 -10
  101. package/dist/cli-bundle/chunks/{chunk-XUC7PI2H.js.map → chunk-E3YQFSFE.js.map} +1 -1
  102. package/dist/cli-bundle/chunks/{chunk-XG625QP4.js → chunk-EDO7VXSO.js} +2 -2
  103. package/dist/cli-bundle/chunks/{chunk-MA4SM3QZ.js → chunk-EIUBK2LT.js} +12 -18
  104. package/dist/cli-bundle/chunks/{chunk-MA4SM3QZ.js.map → chunk-EIUBK2LT.js.map} +1 -1
  105. package/dist/cli-bundle/chunks/{chunk-YN7Y6DQZ.js → chunk-EMXPI36L.js} +14 -20
  106. package/dist/cli-bundle/chunks/{chunk-YN7Y6DQZ.js.map → chunk-EMXPI36L.js.map} +1 -1
  107. package/dist/cli-bundle/chunks/{chunk-MLIYFOE7.js → chunk-EOUVR7JN.js} +12 -8
  108. package/dist/cli-bundle/chunks/chunk-EOUVR7JN.js.map +1 -0
  109. package/dist/cli-bundle/chunks/{chunk-Y4M7CPQP.js → chunk-EVEPHNXJ.js} +4 -4
  110. package/dist/cli-bundle/chunks/{chunk-M7JNBQAD.js → chunk-F6MT7KKE.js} +4 -6
  111. package/dist/cli-bundle/chunks/{chunk-M7JNBQAD.js.map → chunk-F6MT7KKE.js.map} +1 -1
  112. package/dist/cli-bundle/chunks/{chunk-W3DSJQIO.js → chunk-F6YC2A6X.js} +7 -11
  113. package/dist/cli-bundle/chunks/{chunk-W3DSJQIO.js.map → chunk-F6YC2A6X.js.map} +1 -1
  114. package/dist/cli-bundle/chunks/chunk-FILL6BB2.js +5514 -0
  115. package/dist/cli-bundle/chunks/chunk-FILL6BB2.js.map +7 -0
  116. package/dist/cli-bundle/chunks/{chunk-JDDLOQAE.js → chunk-FN6SB4HU.js} +2 -2
  117. package/dist/cli-bundle/chunks/chunk-GH73UOSJ.js +5359 -0
  118. package/dist/cli-bundle/chunks/chunk-GH73UOSJ.js.map +1 -0
  119. package/dist/cli-bundle/chunks/{chunk-EKFNL33R.js → chunk-GLS6VMWI.js} +37 -16
  120. package/dist/cli-bundle/chunks/chunk-GLS6VMWI.js.map +1 -0
  121. package/dist/cli-bundle/chunks/{chunk-HOVCGJSD.js → chunk-GPIDUMMN.js} +9 -11
  122. package/dist/cli-bundle/chunks/{chunk-HOVCGJSD.js.map → chunk-GPIDUMMN.js.map} +1 -1
  123. package/dist/cli-bundle/chunks/{chunk-SQOIV3OQ.js → chunk-GTM5HQL4.js} +11 -15
  124. package/dist/cli-bundle/chunks/{chunk-SQOIV3OQ.js.map → chunk-GTM5HQL4.js.map} +1 -1
  125. package/dist/cli-bundle/chunks/{chunk-24YG75HI.js → chunk-H2SMKL2N.js} +8 -8
  126. package/dist/cli-bundle/chunks/{chunk-QLMX7SRD.js → chunk-HHEWQXPD.js} +6 -6
  127. package/dist/cli-bundle/chunks/chunk-HHEWQXPD.js.map +7 -0
  128. package/dist/cli-bundle/chunks/{chunk-EGY6JBQ3.js → chunk-HX6QXV5P.js} +2 -2
  129. package/dist/cli-bundle/chunks/{chunk-4ZBE5GUN.js → chunk-I74FMIWA.js} +10 -16
  130. package/dist/cli-bundle/chunks/{chunk-4ZBE5GUN.js.map → chunk-I74FMIWA.js.map} +1 -1
  131. package/dist/cli-bundle/chunks/{chunk-3N6RRO2Q.js → chunk-IDIBF4E2.js} +20 -24
  132. package/dist/cli-bundle/chunks/{chunk-3N6RRO2Q.js.map → chunk-IDIBF4E2.js.map} +1 -1
  133. package/dist/cli-bundle/chunks/{chunk-6QBJLYBP.js → chunk-II7R6KD4.js} +8 -7
  134. package/dist/cli-bundle/chunks/{chunk-6QBJLYBP.js.map → chunk-II7R6KD4.js.map} +1 -1
  135. package/dist/cli-bundle/chunks/chunk-J2VGADNG.js +10320 -0
  136. package/dist/cli-bundle/chunks/chunk-J2VGADNG.js.map +1 -0
  137. package/dist/cli-bundle/chunks/{chunk-FT3QTERD.js → chunk-J7BOLHAV.js} +5 -7
  138. package/dist/cli-bundle/chunks/{chunk-FT3QTERD.js.map → chunk-J7BOLHAV.js.map} +1 -1
  139. package/dist/cli-bundle/chunks/{chunk-GANUTS7W.js → chunk-KTGJ2CBU.js} +4 -6
  140. package/dist/cli-bundle/chunks/{chunk-GANUTS7W.js.map → chunk-KTGJ2CBU.js.map} +1 -1
  141. package/dist/cli-bundle/chunks/{chunk-LK6XLOGP.js → chunk-LCFJ7XAM.js} +22 -2
  142. package/dist/cli-bundle/chunks/{chunk-LK6XLOGP.js.map → chunk-LCFJ7XAM.js.map} +3 -3
  143. package/dist/cli-bundle/chunks/{chunk-3UJRFJ5R.js → chunk-LZQU6XJG.js} +28 -34
  144. package/dist/cli-bundle/chunks/{chunk-3UJRFJ5R.js.map → chunk-LZQU6XJG.js.map} +1 -1
  145. package/dist/cli-bundle/chunks/{chunk-L5PSPMZ4.js → chunk-M62RO3XK.js} +10 -14
  146. package/dist/cli-bundle/chunks/{chunk-L5PSPMZ4.js.map → chunk-M62RO3XK.js.map} +1 -1
  147. package/dist/cli-bundle/chunks/{chunk-CFB33L7W.js → chunk-MCEUKJKW.js} +12 -14
  148. package/dist/cli-bundle/chunks/{chunk-CFB33L7W.js.map → chunk-MCEUKJKW.js.map} +1 -1
  149. package/dist/cli-bundle/chunks/{chunk-TKD5VCTD.js → chunk-MHNMCDWR.js} +343 -195
  150. package/dist/cli-bundle/chunks/chunk-MHNMCDWR.js.map +1 -0
  151. package/dist/cli-bundle/chunks/{chunk-O6AWCQRQ.js → chunk-MRFWUSVA.js} +4 -6
  152. package/dist/cli-bundle/chunks/{chunk-O6AWCQRQ.js.map → chunk-MRFWUSVA.js.map} +1 -1
  153. package/dist/cli-bundle/chunks/{chunk-SQYJ4HF2.js → chunk-N6ZHDLUY.js} +6 -8
  154. package/dist/cli-bundle/chunks/{chunk-SQYJ4HF2.js.map → chunk-N6ZHDLUY.js.map} +1 -1
  155. package/dist/cli-bundle/chunks/{chunk-ZWBEPGD7.js → chunk-NWWL22C7.js} +7 -9
  156. package/dist/cli-bundle/chunks/{chunk-ZWBEPGD7.js.map → chunk-NWWL22C7.js.map} +1 -1
  157. package/dist/cli-bundle/chunks/{chunk-Y46GD4IX.js → chunk-P3MJJW7P.js} +2 -2
  158. package/dist/cli-bundle/chunks/{chunk-MVYWGY2A.js → chunk-PDXJXEZJ.js} +2 -2
  159. package/dist/cli-bundle/chunks/{chunk-SGMFPXKR.js → chunk-Q64AYQYW.js} +10 -12
  160. package/dist/cli-bundle/chunks/{chunk-SGMFPXKR.js.map → chunk-Q64AYQYW.js.map} +1 -1
  161. package/dist/cli-bundle/chunks/{chunk-EBRZZ54H.js → chunk-QDABF2RB.js} +26 -34
  162. package/dist/cli-bundle/chunks/{chunk-EBRZZ54H.js.map → chunk-QDABF2RB.js.map} +1 -1
  163. package/dist/cli-bundle/chunks/{chunk-TULGS6X6.js → chunk-QFBSP3NI.js} +529 -46
  164. package/dist/cli-bundle/chunks/chunk-QFBSP3NI.js.map +1 -0
  165. package/dist/cli-bundle/chunks/{chunk-GDDAGPWJ.js → chunk-RB3KLPAH.js} +10 -14
  166. package/dist/cli-bundle/chunks/{chunk-GDDAGPWJ.js.map → chunk-RB3KLPAH.js.map} +1 -1
  167. package/dist/cli-bundle/chunks/{chunk-3VHSI5FL.js → chunk-RY7PTTUB.js} +94 -53
  168. package/dist/cli-bundle/chunks/chunk-RY7PTTUB.js.map +1 -0
  169. package/dist/cli-bundle/chunks/{chunk-COSPOP7H.js → chunk-S547WBYG.js} +343 -195
  170. package/dist/cli-bundle/chunks/chunk-S547WBYG.js.map +7 -0
  171. package/dist/cli-bundle/chunks/{chunk-NZEHECMW.js → chunk-S5BNGFN5.js} +24 -32
  172. package/dist/cli-bundle/chunks/{chunk-NZEHECMW.js.map → chunk-S5BNGFN5.js.map} +1 -1
  173. package/dist/cli-bundle/chunks/{chunk-MVSP7WGJ.js → chunk-S6VC2A2K.js} +8 -12
  174. package/dist/cli-bundle/chunks/{chunk-MVSP7WGJ.js.map → chunk-S6VC2A2K.js.map} +1 -1
  175. package/dist/cli-bundle/chunks/{chunk-45FYNUFJ.js → chunk-SIM5JDON.js} +6 -6
  176. package/dist/cli-bundle/chunks/{chunk-45FYNUFJ.js.map → chunk-SIM5JDON.js.map} +1 -1
  177. package/dist/cli-bundle/chunks/{chunk-VPIM42PC.js → chunk-SY75LYXR.js} +11 -7
  178. package/dist/cli-bundle/chunks/chunk-SY75LYXR.js.map +7 -0
  179. package/dist/cli-bundle/chunks/{chunk-K46RF36U.js → chunk-TEISGNSH.js} +7 -7
  180. package/dist/cli-bundle/chunks/chunk-TEISGNSH.js.map +1 -0
  181. package/dist/cli-bundle/chunks/{chunk-AGHMOTGM.js → chunk-TEKZOS7M.js} +2 -2
  182. package/dist/cli-bundle/chunks/{chunk-W572BIEB.js → chunk-TGUK6XN6.js} +14 -18
  183. package/dist/cli-bundle/chunks/{chunk-W572BIEB.js.map → chunk-TGUK6XN6.js.map} +1 -1
  184. package/dist/cli-bundle/chunks/{chunk-E42XTBSP.js → chunk-TNC6MZUD.js} +8 -12
  185. package/dist/cli-bundle/chunks/{chunk-E42XTBSP.js.map → chunk-TNC6MZUD.js.map} +1 -1
  186. package/dist/cli-bundle/chunks/chunk-TZLYO4PP.js +10498 -0
  187. package/dist/cli-bundle/chunks/chunk-TZLYO4PP.js.map +7 -0
  188. package/dist/cli-bundle/chunks/{chunk-57NWPFF2.js → chunk-UO7XAZK6.js} +17 -4
  189. package/dist/cli-bundle/chunks/chunk-UO7XAZK6.js.map +1 -0
  190. package/dist/cli-bundle/chunks/{chunk-JVH7QBVV.js → chunk-V5ZWKJNY.js} +2 -2
  191. package/dist/cli-bundle/chunks/{chunk-I36Y7PCE.js → chunk-VGO73OCK.js} +6 -6
  192. package/dist/cli-bundle/chunks/{chunk-I36Y7PCE.js.map → chunk-VGO73OCK.js.map} +1 -1
  193. package/dist/cli-bundle/chunks/{chunk-KUOOJR35.js → chunk-VLEA2UTQ.js} +2 -2
  194. package/dist/cli-bundle/chunks/{chunk-RCQZK2GO.js → chunk-W5HXHC7C.js} +7 -9
  195. package/dist/cli-bundle/chunks/{chunk-RCQZK2GO.js.map → chunk-W5HXHC7C.js.map} +1 -1
  196. package/dist/cli-bundle/chunks/{chunk-MUH7A3FD.js → chunk-WCWVEXGA.js} +2 -2
  197. package/dist/cli-bundle/chunks/chunk-X47MKQXU.js +6690 -0
  198. package/dist/cli-bundle/chunks/chunk-X47MKQXU.js.map +7 -0
  199. package/dist/cli-bundle/chunks/{chunk-NB7RLQFW.js → chunk-XBX5CBRQ.js} +5 -7
  200. package/dist/cli-bundle/chunks/{chunk-NB7RLQFW.js.map → chunk-XBX5CBRQ.js.map} +1 -1
  201. package/dist/cli-bundle/chunks/{chunk-SCUR7K7N.js → chunk-XC3X7BQR.js} +541 -44
  202. package/dist/cli-bundle/chunks/chunk-XC3X7BQR.js.map +7 -0
  203. package/dist/cli-bundle/chunks/{chunk-CRVYGJUI.js → chunk-XHCVAZGM.js} +13 -17
  204. package/dist/cli-bundle/chunks/{chunk-CRVYGJUI.js.map → chunk-XHCVAZGM.js.map} +1 -1
  205. package/dist/cli-bundle/chunks/{chunk-XB7KFVFI.js → chunk-XPMXPR7K.js} +7 -9
  206. package/dist/cli-bundle/chunks/{chunk-XB7KFVFI.js.map → chunk-XPMXPR7K.js.map} +1 -1
  207. package/dist/cli-bundle/chunks/{chunk-4CJFCTLM.js → chunk-XS2TMNXR.js} +6 -8
  208. package/dist/cli-bundle/chunks/{chunk-4CJFCTLM.js.map → chunk-XS2TMNXR.js.map} +1 -1
  209. package/dist/cli-bundle/chunks/{chunk-HFDADVJZ.js → chunk-XXIYUTLK.js} +10 -14
  210. package/dist/cli-bundle/chunks/{chunk-HFDADVJZ.js.map → chunk-XXIYUTLK.js.map} +1 -1
  211. package/dist/cli-bundle/chunks/{chunk-EOKXK3R3.js → chunk-XZWL7VNE.js} +1220 -398
  212. package/dist/cli-bundle/chunks/chunk-XZWL7VNE.js.map +1 -0
  213. package/dist/cli-bundle/chunks/chunk-Y5IKRUEM.js +6624 -0
  214. package/dist/cli-bundle/chunks/chunk-Y5IKRUEM.js.map +1 -0
  215. package/dist/cli-bundle/chunks/{chunk-6LLVNJXT.js → chunk-Y7KYVCZM.js} +12 -18
  216. package/dist/cli-bundle/chunks/{chunk-6LLVNJXT.js.map → chunk-Y7KYVCZM.js.map} +1 -1
  217. package/dist/cli-bundle/chunks/{chunk-VIIUS6N6.js → chunk-YCVWWIKY.js} +16 -14
  218. package/dist/cli-bundle/chunks/chunk-YCVWWIKY.js.map +7 -0
  219. package/dist/cli-bundle/chunks/{chunk-CFNGIXZP.js → chunk-YH5NBDFA.js} +22 -26
  220. package/dist/cli-bundle/chunks/{chunk-CFNGIXZP.js.map → chunk-YH5NBDFA.js.map} +1 -1
  221. package/dist/cli-bundle/chunks/chunk-YNCFP5AR.js +5509 -0
  222. package/dist/cli-bundle/chunks/chunk-YNCFP5AR.js.map +7 -0
  223. package/dist/cli-bundle/chunks/{chunk-NC33K5ZS.js → chunk-YPD7SQ5P.js} +7 -6
  224. package/dist/cli-bundle/chunks/{chunk-NC33K5ZS.js.map → chunk-YPD7SQ5P.js.map} +2 -2
  225. package/dist/cli-bundle/chunks/{chunk-NGXQ3PFT.js → chunk-YPMZMKN7.js} +2 -2
  226. package/dist/cli-bundle/chunks/{chunk-KGFUY7WN.js → chunk-YTD5GICJ.js} +4 -4
  227. package/dist/cli-bundle/chunks/{chunk-W6DYWXPQ.js → chunk-ZNEG2UDO.js} +261 -34
  228. package/dist/cli-bundle/chunks/{chunk-W6DYWXPQ.js.map → chunk-ZNEG2UDO.js.map} +4 -4
  229. package/dist/cli-bundle/chunks/{chunk-7DT4WSH2.js → chunk-ZO7CLOY2.js} +3 -3
  230. package/dist/cli-bundle/chunks/{close-2SSSHHUZ.js → close-3YYQ5OG2.js} +5 -9
  231. package/dist/cli-bundle/chunks/close-Z3Q4U7TS.js +12 -0
  232. package/dist/cli-bundle/chunks/close-many-3L2RXH3M.js +22 -0
  233. package/dist/cli-bundle/chunks/close-many-D366FTIG.js +26 -0
  234. package/dist/cli-bundle/chunks/comments-54XDJNFE.js +17 -0
  235. package/dist/cli-bundle/chunks/comments-HGHC2PN6.js +13 -0
  236. package/dist/cli-bundle/chunks/{copy-32ROBIDL.js → copy-44RT5GDW.js} +4 -8
  237. package/dist/cli-bundle/chunks/copy-UGMUGHZA.js +9 -0
  238. package/dist/cli-bundle/chunks/{create-E77SDCUP.js → create-4GWJWPXG.js} +9 -14
  239. package/dist/cli-bundle/chunks/create-AZXCUYKP.js +25 -0
  240. package/dist/cli-bundle/chunks/delete-Y6SXIQ4X.js +10 -0
  241. package/dist/cli-bundle/chunks/{delete-RA5KTCLB.js → delete-YQ2VPXNF.js} +4 -8
  242. package/dist/cli-bundle/chunks/{deps-32SU7HO5.js → deps-BU5EBJDU.js} +4 -8
  243. package/dist/cli-bundle/chunks/deps-FMANWFRP.js +13 -0
  244. package/dist/cli-bundle/chunks/{docs-RRUPT7O2.js → docs-OQBSJNIA.js} +6 -10
  245. package/dist/cli-bundle/chunks/docs-VNPBZXEL.js +14 -0
  246. package/dist/cli-bundle/chunks/files-72HZEBOE.js +18 -0
  247. package/dist/cli-bundle/chunks/{files-PYKR2UUG.js → files-HTSB2KJG.js} +6 -10
  248. package/dist/cli-bundle/chunks/{contracts-NYPEW2G4.js → focus-FOG4ALC2.js} +7 -9
  249. package/dist/cli-bundle/chunks/focus-SUTMKXGX.js +10 -0
  250. package/dist/cli-bundle/chunks/{history-compact-3MNXLKAT.js → history-compact-M6IFAMBP.js} +9 -13
  251. package/dist/cli-bundle/chunks/history-compact-NEXRPP2O.js +21 -0
  252. package/dist/cli-bundle/chunks/{history-redact-P6DYF55G.js → history-redact-NQX3OGZP.js} +7 -11
  253. package/dist/cli-bundle/chunks/history-redact-WQJBZ3PX.js +17 -0
  254. package/dist/cli-bundle/chunks/history-repair-CBHMHAJO.js +19 -0
  255. package/dist/cli-bundle/chunks/{history-repair-ZJQFMWPD.js → history-repair-NHOJG7WO.js} +9 -13
  256. package/dist/cli-bundle/chunks/learnings-M64NTSOR.js +13 -0
  257. package/dist/cli-bundle/chunks/{append-BGML6VLD.js → learnings-T63JGKKN.js} +9 -11
  258. package/dist/cli-bundle/chunks/notes-73WE2UV2.js +13 -0
  259. package/dist/cli-bundle/chunks/notes-U7L6HQQ2.js +17 -0
  260. package/dist/cli-bundle/chunks/plan-OSCNYFGC.js +24 -0
  261. package/dist/cli-bundle/chunks/{plan-CHVE7PBR.js → plan-TN537L24.js} +10 -15
  262. package/dist/cli-bundle/chunks/{profile-ZXGSKBJD.js → profile-MHAMXMHQ.js} +9 -13
  263. package/dist/cli-bundle/chunks/{profile-LD23PSI6.js → profile-TIGLAKJ7.js} +9 -13
  264. package/dist/cli-bundle/chunks/{register-list-query-OEYQHFXO.js → register-list-query-OHXD7G5N.js} +41 -33
  265. package/dist/cli-bundle/chunks/register-list-query-OHXD7G5N.js.map +7 -0
  266. package/dist/cli-bundle/chunks/{register-list-query-B42JCCOI.js → register-list-query-ZCRABAPN.js} +42 -34
  267. package/dist/cli-bundle/chunks/register-list-query-ZCRABAPN.js.map +1 -0
  268. package/dist/cli-bundle/chunks/{register-mutation-IAEST26S.js → register-mutation-P3G4XP6Q.js} +36 -41
  269. package/dist/cli-bundle/chunks/{register-mutation-IAEST26S.js.map → register-mutation-P3G4XP6Q.js.map} +1 -1
  270. package/dist/cli-bundle/chunks/{register-mutation-3QXIHCQG.js → register-mutation-XX4H56PE.js} +34 -39
  271. package/dist/cli-bundle/chunks/{register-mutation-3QXIHCQG.js.map → register-mutation-XX4H56PE.js.map} +1 -1
  272. package/dist/cli-bundle/chunks/{chunk-5BMM6XQY.js → register-operations-V6PIYEDU.js} +79 -46
  273. package/dist/cli-bundle/chunks/register-operations-V6PIYEDU.js.map +1 -0
  274. package/dist/cli-bundle/chunks/{chunk-Z3U3U5KD.js → register-operations-V6VKTG54.js} +78 -45
  275. package/dist/cli-bundle/chunks/register-operations-V6VKTG54.js.map +7 -0
  276. package/dist/cli-bundle/chunks/{register-setup-3ZVVX2VN.js → register-setup-6RVAWT6W.js} +129 -29
  277. package/dist/cli-bundle/chunks/register-setup-6RVAWT6W.js.map +7 -0
  278. package/dist/cli-bundle/chunks/{register-setup-Q6KFNIOZ.js → register-setup-6YVUSQYD.js} +130 -30
  279. package/dist/cli-bundle/chunks/register-setup-6YVUSQYD.js.map +1 -0
  280. package/dist/cli-bundle/chunks/{restore-5RQHAPMA.js → restore-HC3YSWF7.js} +7 -11
  281. package/dist/cli-bundle/chunks/restore-LFAMMRYZ.js +15 -0
  282. package/dist/cli-bundle/chunks/{schema-HBORFC6B.js → schema-DAGSYO6E.js} +6 -10
  283. package/dist/cli-bundle/chunks/{schema-245WW4G2.js → schema-UBXJCQAC.js} +6 -10
  284. package/dist/cli-bundle/chunks/update-CJGG5WMV.js +21 -0
  285. package/dist/cli-bundle/chunks/update-LKD64AFP.js +25 -0
  286. package/dist/cli-bundle/chunks/update-many-G4SM7BHC.js +31 -0
  287. package/dist/cli-bundle/chunks/update-many-VLIV3D7R.js +35 -0
  288. package/dist/cli-bundle/main.js +29 -31
  289. package/dist/cli-bundle/main.js.map +2 -2
  290. package/dist/cli-bundle/sdk-runtime.js +129 -107
  291. package/dist/cli-bundle/sdk-testing.js +7 -8
  292. package/dist/cli-bundle/sdk.js +122 -117
  293. package/dist/cli-bundle/sdk.js.map +2 -2
  294. package/dist/core/history/drift-scan.js +3 -8
  295. package/dist/core/history/drift-scan.js.map +1 -1
  296. package/dist/core/output/mutation-projection.js +11 -5
  297. package/dist/core/output/mutation-projection.js.map +1 -1
  298. package/dist/core/search/cache.js +3 -3
  299. package/dist/core/search/cache.js.map +1 -1
  300. package/dist/core/search/semantic-defaults.d.ts +2 -0
  301. package/dist/core/search/semantic-defaults.js +11 -4
  302. package/dist/core/search/semantic-defaults.js.map +1 -1
  303. package/dist/core/search/vector-stores.d.ts +1 -1
  304. package/dist/core/search/vector-stores.js +33 -7
  305. package/dist/core/search/vector-stores.js.map +1 -1
  306. package/dist/mcp/server.d.ts +1 -1
  307. package/dist/sdk/cli-contracts/flag-contracts.js +7 -7
  308. package/dist/sdk/cli-contracts/flag-contracts.js.map +1 -1
  309. package/dist/sdk/cli-contracts/tool-schema.js +9 -7
  310. package/dist/sdk/cli-contracts/tool-schema.js.map +1 -1
  311. package/dist/sdk/index.d.ts +1 -1
  312. package/dist/sdk/index.js +3 -3
  313. package/dist/sdk/index.js.map +1 -1
  314. package/dist/sdk/runtime.d.ts +151 -8
  315. package/dist/sdk/runtime.js +255 -14
  316. package/dist/sdk/runtime.js.map +1 -1
  317. package/dist/sdk/start-task-status.d.ts +13 -0
  318. package/dist/sdk/start-task-status.js +19 -0
  319. package/dist/sdk/start-task-status.js.map +1 -0
  320. package/docs/COMMANDS.md +10 -1
  321. package/docs/SDK.md +35 -0
  322. package/docs/TESTING.md +3 -0
  323. package/package.json +1 -1
  324. package/dist/cli-bundle/chunks/activity-WJCGCYPU.js +0 -18
  325. package/dist/cli-bundle/chunks/activity-Z6QUAUSG.js +0 -22
  326. package/dist/cli-bundle/chunks/aggregate-BDM6EIAR.js +0 -25
  327. package/dist/cli-bundle/chunks/aggregate-VQ2DHU3S.js +0 -21
  328. package/dist/cli-bundle/chunks/append-RKJYPU74.js +0 -15
  329. package/dist/cli-bundle/chunks/chunk-2XG4IZON.js +0 -218
  330. package/dist/cli-bundle/chunks/chunk-2XG4IZON.js.map +0 -7
  331. package/dist/cli-bundle/chunks/chunk-37E72CNS.js +0 -217
  332. package/dist/cli-bundle/chunks/chunk-37E72CNS.js.map +0 -1
  333. package/dist/cli-bundle/chunks/chunk-3GCS5SKL.js +0 -228
  334. package/dist/cli-bundle/chunks/chunk-3GCS5SKL.js.map +0 -1
  335. package/dist/cli-bundle/chunks/chunk-3KTN6IBA.js +0 -2330
  336. package/dist/cli-bundle/chunks/chunk-3KTN6IBA.js.map +0 -7
  337. package/dist/cli-bundle/chunks/chunk-3VHSI5FL.js.map +0 -1
  338. package/dist/cli-bundle/chunks/chunk-425E4QL5.js +0 -278
  339. package/dist/cli-bundle/chunks/chunk-425E4QL5.js.map +0 -7
  340. package/dist/cli-bundle/chunks/chunk-46CUF5L6.js.map +0 -7
  341. package/dist/cli-bundle/chunks/chunk-4BU75MF4.js +0 -87
  342. package/dist/cli-bundle/chunks/chunk-4BU75MF4.js.map +0 -7
  343. package/dist/cli-bundle/chunks/chunk-4HIFVN7N.js +0 -249
  344. package/dist/cli-bundle/chunks/chunk-4HIFVN7N.js.map +0 -7
  345. package/dist/cli-bundle/chunks/chunk-4IWYTWGF.js +0 -819
  346. package/dist/cli-bundle/chunks/chunk-4IWYTWGF.js.map +0 -1
  347. package/dist/cli-bundle/chunks/chunk-4MZVRJOE.js +0 -279
  348. package/dist/cli-bundle/chunks/chunk-4MZVRJOE.js.map +0 -1
  349. package/dist/cli-bundle/chunks/chunk-57NWPFF2.js.map +0 -1
  350. package/dist/cli-bundle/chunks/chunk-5AJXHQM7.js +0 -268
  351. package/dist/cli-bundle/chunks/chunk-5AJXHQM7.js.map +0 -1
  352. package/dist/cli-bundle/chunks/chunk-5BMM6XQY.js.map +0 -1
  353. package/dist/cli-bundle/chunks/chunk-5GZ7TDD6.js +0 -1868
  354. package/dist/cli-bundle/chunks/chunk-5GZ7TDD6.js.map +0 -7
  355. package/dist/cli-bundle/chunks/chunk-5VAA4YHR.js +0 -1749
  356. package/dist/cli-bundle/chunks/chunk-5VAA4YHR.js.map +0 -7
  357. package/dist/cli-bundle/chunks/chunk-64YKRTSV.js +0 -1961
  358. package/dist/cli-bundle/chunks/chunk-64YKRTSV.js.map +0 -1
  359. package/dist/cli-bundle/chunks/chunk-7C2O74AE.js +0 -23
  360. package/dist/cli-bundle/chunks/chunk-7C2O74AE.js.map +0 -7
  361. package/dist/cli-bundle/chunks/chunk-B7FRNMYN.js +0 -421
  362. package/dist/cli-bundle/chunks/chunk-B7FRNMYN.js.map +0 -1
  363. package/dist/cli-bundle/chunks/chunk-C5JBZRPU.js +0 -1985
  364. package/dist/cli-bundle/chunks/chunk-C5JBZRPU.js.map +0 -7
  365. package/dist/cli-bundle/chunks/chunk-CL36D4PC.js.map +0 -7
  366. package/dist/cli-bundle/chunks/chunk-COSPOP7H.js.map +0 -7
  367. package/dist/cli-bundle/chunks/chunk-COWTDV6B.js +0 -3461
  368. package/dist/cli-bundle/chunks/chunk-COWTDV6B.js.map +0 -7
  369. package/dist/cli-bundle/chunks/chunk-DEWEK6AN.js +0 -1858
  370. package/dist/cli-bundle/chunks/chunk-DEWEK6AN.js.map +0 -1
  371. package/dist/cli-bundle/chunks/chunk-DMRNBQOI.js.map +0 -1
  372. package/dist/cli-bundle/chunks/chunk-E3SZTQ4K.js +0 -1932
  373. package/dist/cli-bundle/chunks/chunk-E3SZTQ4K.js.map +0 -1
  374. package/dist/cli-bundle/chunks/chunk-EGAP5OWD.js.map +0 -1
  375. package/dist/cli-bundle/chunks/chunk-EKFNL33R.js.map +0 -1
  376. package/dist/cli-bundle/chunks/chunk-ENGQOEUY.js +0 -1704
  377. package/dist/cli-bundle/chunks/chunk-ENGQOEUY.js.map +0 -1
  378. package/dist/cli-bundle/chunks/chunk-EOKXK3R3.js.map +0 -1
  379. package/dist/cli-bundle/chunks/chunk-FLZSGSQR.js +0 -231
  380. package/dist/cli-bundle/chunks/chunk-FLZSGSQR.js.map +0 -7
  381. package/dist/cli-bundle/chunks/chunk-FOUYJE4A.js +0 -2090
  382. package/dist/cli-bundle/chunks/chunk-FOUYJE4A.js.map +0 -1
  383. package/dist/cli-bundle/chunks/chunk-G24G7ZAV.js +0 -1570
  384. package/dist/cli-bundle/chunks/chunk-G24G7ZAV.js.map +0 -1
  385. package/dist/cli-bundle/chunks/chunk-GEYZ4G4O.js +0 -239
  386. package/dist/cli-bundle/chunks/chunk-GEYZ4G4O.js.map +0 -1
  387. package/dist/cli-bundle/chunks/chunk-GPLPTGOV.js +0 -530
  388. package/dist/cli-bundle/chunks/chunk-GPLPTGOV.js.map +0 -7
  389. package/dist/cli-bundle/chunks/chunk-GZRDYONU.js +0 -1005
  390. package/dist/cli-bundle/chunks/chunk-GZRDYONU.js.map +0 -7
  391. package/dist/cli-bundle/chunks/chunk-HN6NSXNW.js +0 -277
  392. package/dist/cli-bundle/chunks/chunk-HN6NSXNW.js.map +0 -7
  393. package/dist/cli-bundle/chunks/chunk-IQNVQHOP.js +0 -309
  394. package/dist/cli-bundle/chunks/chunk-IQNVQHOP.js.map +0 -7
  395. package/dist/cli-bundle/chunks/chunk-JINYH2DB.js +0 -371
  396. package/dist/cli-bundle/chunks/chunk-JINYH2DB.js.map +0 -7
  397. package/dist/cli-bundle/chunks/chunk-JQXPY7DN.js +0 -2257
  398. package/dist/cli-bundle/chunks/chunk-JQXPY7DN.js.map +0 -7
  399. package/dist/cli-bundle/chunks/chunk-K46RF36U.js.map +0 -1
  400. package/dist/cli-bundle/chunks/chunk-KERMZVY5.js +0 -371
  401. package/dist/cli-bundle/chunks/chunk-KERMZVY5.js.map +0 -7
  402. package/dist/cli-bundle/chunks/chunk-KSRUHV2H.js +0 -76
  403. package/dist/cli-bundle/chunks/chunk-KSRUHV2H.js.map +0 -1
  404. package/dist/cli-bundle/chunks/chunk-LP3HSFZ2.js +0 -140
  405. package/dist/cli-bundle/chunks/chunk-LP3HSFZ2.js.map +0 -1
  406. package/dist/cli-bundle/chunks/chunk-MAWDPCJW.js +0 -1601
  407. package/dist/cli-bundle/chunks/chunk-MAWDPCJW.js.map +0 -1
  408. package/dist/cli-bundle/chunks/chunk-MFAZSEM5.js +0 -1031
  409. package/dist/cli-bundle/chunks/chunk-MFAZSEM5.js.map +0 -1
  410. package/dist/cli-bundle/chunks/chunk-MFSCBT5Q.js +0 -995
  411. package/dist/cli-bundle/chunks/chunk-MFSCBT5Q.js.map +0 -1
  412. package/dist/cli-bundle/chunks/chunk-ML5X7DP2.js +0 -296
  413. package/dist/cli-bundle/chunks/chunk-ML5X7DP2.js.map +0 -1
  414. package/dist/cli-bundle/chunks/chunk-MLIYFOE7.js.map +0 -1
  415. package/dist/cli-bundle/chunks/chunk-MR6FJ7LL.js +0 -2043
  416. package/dist/cli-bundle/chunks/chunk-MR6FJ7LL.js.map +0 -7
  417. package/dist/cli-bundle/chunks/chunk-MXYA5SAJ.js +0 -2033
  418. package/dist/cli-bundle/chunks/chunk-MXYA5SAJ.js.map +0 -1
  419. package/dist/cli-bundle/chunks/chunk-N745W3B3.js +0 -1604
  420. package/dist/cli-bundle/chunks/chunk-N745W3B3.js.map +0 -7
  421. package/dist/cli-bundle/chunks/chunk-NMP5I3I5.js +0 -1615
  422. package/dist/cli-bundle/chunks/chunk-NMP5I3I5.js.map +0 -7
  423. package/dist/cli-bundle/chunks/chunk-NNHHXJB2.js +0 -20
  424. package/dist/cli-bundle/chunks/chunk-NNHHXJB2.js.map +0 -1
  425. package/dist/cli-bundle/chunks/chunk-PZUGEOPS.js +0 -143
  426. package/dist/cli-bundle/chunks/chunk-PZUGEOPS.js.map +0 -7
  427. package/dist/cli-bundle/chunks/chunk-QLMX7SRD.js.map +0 -7
  428. package/dist/cli-bundle/chunks/chunk-QX6HM775.js +0 -398
  429. package/dist/cli-bundle/chunks/chunk-QX6HM775.js.map +0 -7
  430. package/dist/cli-bundle/chunks/chunk-QZ342C63.js +0 -220
  431. package/dist/cli-bundle/chunks/chunk-QZ342C63.js.map +0 -7
  432. package/dist/cli-bundle/chunks/chunk-R2EMWY7Q.js +0 -368
  433. package/dist/cli-bundle/chunks/chunk-R2EMWY7Q.js.map +0 -1
  434. package/dist/cli-bundle/chunks/chunk-RFNYTESG.js +0 -520
  435. package/dist/cli-bundle/chunks/chunk-RFNYTESG.js.map +0 -1
  436. package/dist/cli-bundle/chunks/chunk-RKQOO2UM.js +0 -79
  437. package/dist/cli-bundle/chunks/chunk-RKQOO2UM.js.map +0 -7
  438. package/dist/cli-bundle/chunks/chunk-RQLT6ZWB.js +0 -282
  439. package/dist/cli-bundle/chunks/chunk-RQLT6ZWB.js.map +0 -7
  440. package/dist/cli-bundle/chunks/chunk-S3JS6YVZ.js +0 -274
  441. package/dist/cli-bundle/chunks/chunk-S3JS6YVZ.js.map +0 -1
  442. package/dist/cli-bundle/chunks/chunk-SCUR7K7N.js.map +0 -7
  443. package/dist/cli-bundle/chunks/chunk-SHQY2IDC.js +0 -1977
  444. package/dist/cli-bundle/chunks/chunk-SHQY2IDC.js.map +0 -7
  445. package/dist/cli-bundle/chunks/chunk-SPZ6DOGY.js +0 -1041
  446. package/dist/cli-bundle/chunks/chunk-SPZ6DOGY.js.map +0 -7
  447. package/dist/cli-bundle/chunks/chunk-T42JWV3F.js +0 -822
  448. package/dist/cli-bundle/chunks/chunk-T42JWV3F.js.map +0 -7
  449. package/dist/cli-bundle/chunks/chunk-TKD5VCTD.js.map +0 -1
  450. package/dist/cli-bundle/chunks/chunk-TULGS6X6.js.map +0 -1
  451. package/dist/cli-bundle/chunks/chunk-TZXRBVAM.js +0 -2306
  452. package/dist/cli-bundle/chunks/chunk-TZXRBVAM.js.map +0 -1
  453. package/dist/cli-bundle/chunks/chunk-VIIUS6N6.js.map +0 -7
  454. package/dist/cli-bundle/chunks/chunk-VPIM42PC.js.map +0 -7
  455. package/dist/cli-bundle/chunks/chunk-VQRSPVME.js +0 -368
  456. package/dist/cli-bundle/chunks/chunk-VQRSPVME.js.map +0 -1
  457. package/dist/cli-bundle/chunks/chunk-VY3VQ22F.js +0 -84
  458. package/dist/cli-bundle/chunks/chunk-VY3VQ22F.js.map +0 -1
  459. package/dist/cli-bundle/chunks/chunk-WG34ZNQQ.js +0 -3423
  460. package/dist/cli-bundle/chunks/chunk-WG34ZNQQ.js.map +0 -1
  461. package/dist/cli-bundle/chunks/chunk-WLSM645P.js +0 -2247
  462. package/dist/cli-bundle/chunks/chunk-WLSM645P.js.map +0 -1
  463. package/dist/cli-bundle/chunks/chunk-WRTENIX3.js +0 -215
  464. package/dist/cli-bundle/chunks/chunk-WRTENIX3.js.map +0 -1
  465. package/dist/cli-bundle/chunks/chunk-WSBLYDWV.js +0 -388
  466. package/dist/cli-bundle/chunks/chunk-WSBLYDWV.js.map +0 -1
  467. package/dist/cli-bundle/chunks/chunk-XC5BURG2.js +0 -306
  468. package/dist/cli-bundle/chunks/chunk-XC5BURG2.js.map +0 -1
  469. package/dist/cli-bundle/chunks/chunk-XDB7RWQT.js +0 -424
  470. package/dist/cli-bundle/chunks/chunk-XDB7RWQT.js.map +0 -7
  471. package/dist/cli-bundle/chunks/chunk-Y6BK55A3.js +0 -2128
  472. package/dist/cli-bundle/chunks/chunk-Y6BK55A3.js.map +0 -7
  473. package/dist/cli-bundle/chunks/chunk-Z3U3U5KD.js.map +0 -7
  474. package/dist/cli-bundle/chunks/chunk-ZO3XKAOP.js +0 -299
  475. package/dist/cli-bundle/chunks/chunk-ZO3XKAOP.js.map +0 -7
  476. package/dist/cli-bundle/chunks/chunk-ZSUS2OD3.js.map +0 -7
  477. package/dist/cli-bundle/chunks/claim-RFS7BROJ.js +0 -19
  478. package/dist/cli-bundle/chunks/claim-XP5AWZ5H.js +0 -23
  479. package/dist/cli-bundle/chunks/close-GEANHQ2J.js +0 -16
  480. package/dist/cli-bundle/chunks/close-many-CMZW7ITN.js +0 -31
  481. package/dist/cli-bundle/chunks/close-many-ZFDIG6M7.js +0 -27
  482. package/dist/cli-bundle/chunks/comments-MFSYVNNU.js +0 -21
  483. package/dist/cli-bundle/chunks/comments-XUBPXDYX.js +0 -17
  484. package/dist/cli-bundle/chunks/config-D7XQMONX.js +0 -18
  485. package/dist/cli-bundle/chunks/config-T4FHBSYN.js +0 -22
  486. package/dist/cli-bundle/chunks/context-DIU275XI.js +0 -48
  487. package/dist/cli-bundle/chunks/context-JCOYB4LZ.js +0 -44
  488. package/dist/cli-bundle/chunks/contracts-BVO7CSLK.js +0 -12
  489. package/dist/cli-bundle/chunks/copy-NAGLGMHZ.js +0 -13
  490. package/dist/cli-bundle/chunks/create-4V7SWNBB.js +0 -30
  491. package/dist/cli-bundle/chunks/delete-NQI5OSKN.js +0 -14
  492. package/dist/cli-bundle/chunks/deps-T7SCWXEX.js +0 -17
  493. package/dist/cli-bundle/chunks/docs-WL2IWGWV.js +0 -18
  494. package/dist/cli-bundle/chunks/eval-NF2J5SHR.js +0 -23
  495. package/dist/cli-bundle/chunks/eval-SKDT3MZU.js +0 -27
  496. package/dist/cli-bundle/chunks/extension-LAXKCAYE.js +0 -42
  497. package/dist/cli-bundle/chunks/extension-ZISPBRBC.js +0 -38
  498. package/dist/cli-bundle/chunks/files-EWRQHGIS.js +0 -22
  499. package/dist/cli-bundle/chunks/focus-4T7TM4MT.js +0 -18
  500. package/dist/cli-bundle/chunks/focus-L3YUASOD.js +0 -14
  501. package/dist/cli-bundle/chunks/gc-2PCTYYRI.js +0 -12
  502. package/dist/cli-bundle/chunks/get-7DMITJ3G.js +0 -23
  503. package/dist/cli-bundle/chunks/get-VKQXCXLL.js +0 -19
  504. package/dist/cli-bundle/chunks/health-CVSTAR2F.js +0 -31
  505. package/dist/cli-bundle/chunks/health-TV3GKTFN.js +0 -35
  506. package/dist/cli-bundle/chunks/history-D4JUX5XV.js +0 -20
  507. package/dist/cli-bundle/chunks/history-D4JUX5XV.js.map +0 -7
  508. package/dist/cli-bundle/chunks/history-LQ2UWZTE.js +0 -24
  509. package/dist/cli-bundle/chunks/history-LQ2UWZTE.js.map +0 -1
  510. package/dist/cli-bundle/chunks/history-compact-3MNXLKAT.js.map +0 -1
  511. package/dist/cli-bundle/chunks/history-compact-QWEO32FP.js +0 -25
  512. package/dist/cli-bundle/chunks/history-compact-QWEO32FP.js.map +0 -7
  513. package/dist/cli-bundle/chunks/history-redact-3OIVBVIY.js +0 -21
  514. package/dist/cli-bundle/chunks/history-redact-3OIVBVIY.js.map +0 -7
  515. package/dist/cli-bundle/chunks/history-redact-P6DYF55G.js.map +0 -1
  516. package/dist/cli-bundle/chunks/history-repair-I3E73UGQ.js +0 -23
  517. package/dist/cli-bundle/chunks/history-repair-I3E73UGQ.js.map +0 -7
  518. package/dist/cli-bundle/chunks/history-repair-ZJQFMWPD.js.map +0 -1
  519. package/dist/cli-bundle/chunks/init-C3LJPWQZ.js +0 -30
  520. package/dist/cli-bundle/chunks/init-C3LJPWQZ.js.map +0 -1
  521. package/dist/cli-bundle/chunks/init-J3DPGWQI.js +0 -26
  522. package/dist/cli-bundle/chunks/init-J3DPGWQI.js.map +0 -7
  523. package/dist/cli-bundle/chunks/learnings-5BO2SNDW.js +0 -21
  524. package/dist/cli-bundle/chunks/learnings-5BO2SNDW.js.map +0 -1
  525. package/dist/cli-bundle/chunks/learnings-OGP4JB4I.js +0 -17
  526. package/dist/cli-bundle/chunks/learnings-OGP4JB4I.js.map +0 -7
  527. package/dist/cli-bundle/chunks/list-O5NZVSPN.js +0 -36
  528. package/dist/cli-bundle/chunks/list-O5NZVSPN.js.map +0 -1
  529. package/dist/cli-bundle/chunks/list-Z55YCNTC.js +0 -32
  530. package/dist/cli-bundle/chunks/list-Z55YCNTC.js.map +0 -7
  531. package/dist/cli-bundle/chunks/next-GBNTGXFC.js +0 -28
  532. package/dist/cli-bundle/chunks/next-GBNTGXFC.js.map +0 -7
  533. package/dist/cli-bundle/chunks/next-QKW7PTKE.js +0 -32
  534. package/dist/cli-bundle/chunks/next-QKW7PTKE.js.map +0 -1
  535. package/dist/cli-bundle/chunks/notes-R5FZTKWF.js +0 -17
  536. package/dist/cli-bundle/chunks/notes-R5FZTKWF.js.map +0 -7
  537. package/dist/cli-bundle/chunks/notes-WCGIULVG.js +0 -21
  538. package/dist/cli-bundle/chunks/notes-WCGIULVG.js.map +0 -1
  539. package/dist/cli-bundle/chunks/plan-ADISFYH4.js +0 -29
  540. package/dist/cli-bundle/chunks/plan-ADISFYH4.js.map +0 -7
  541. package/dist/cli-bundle/chunks/plan-CHVE7PBR.js.map +0 -1
  542. package/dist/cli-bundle/chunks/profile-LD23PSI6.js.map +0 -7
  543. package/dist/cli-bundle/chunks/profile-ZXGSKBJD.js.map +0 -1
  544. package/dist/cli-bundle/chunks/register-list-query-B42JCCOI.js.map +0 -1
  545. package/dist/cli-bundle/chunks/register-list-query-OEYQHFXO.js.map +0 -7
  546. package/dist/cli-bundle/chunks/register-operations-I3M3U7DS.js +0 -19
  547. package/dist/cli-bundle/chunks/register-operations-I3M3U7DS.js.map +0 -7
  548. package/dist/cli-bundle/chunks/register-operations-UHKENLZV.js +0 -23
  549. package/dist/cli-bundle/chunks/register-operations-UHKENLZV.js.map +0 -1
  550. package/dist/cli-bundle/chunks/register-setup-3ZVVX2VN.js.map +0 -7
  551. package/dist/cli-bundle/chunks/register-setup-Q6KFNIOZ.js.map +0 -1
  552. package/dist/cli-bundle/chunks/restore-5RQHAPMA.js.map +0 -1
  553. package/dist/cli-bundle/chunks/restore-PNEIBBLW.js +0 -19
  554. package/dist/cli-bundle/chunks/restore-PNEIBBLW.js.map +0 -7
  555. package/dist/cli-bundle/chunks/scheduling-shortcuts-4G56YHVQ.js +0 -29
  556. package/dist/cli-bundle/chunks/scheduling-shortcuts-4G56YHVQ.js.map +0 -1
  557. package/dist/cli-bundle/chunks/scheduling-shortcuts-75DULBYP.js +0 -25
  558. package/dist/cli-bundle/chunks/scheduling-shortcuts-75DULBYP.js.map +0 -7
  559. package/dist/cli-bundle/chunks/schema-245WW4G2.js.map +0 -1
  560. package/dist/cli-bundle/chunks/schema-HBORFC6B.js.map +0 -7
  561. package/dist/cli-bundle/chunks/search-AOZC5SIK.js +0 -34
  562. package/dist/cli-bundle/chunks/search-AOZC5SIK.js.map +0 -7
  563. package/dist/cli-bundle/chunks/search-DRXPGHD7.js +0 -38
  564. package/dist/cli-bundle/chunks/search-DRXPGHD7.js.map +0 -1
  565. package/dist/cli-bundle/chunks/stats-NJG4NLHG.js +0 -21
  566. package/dist/cli-bundle/chunks/stats-NJG4NLHG.js.map +0 -1
  567. package/dist/cli-bundle/chunks/stats-RG6AG4N2.js +0 -17
  568. package/dist/cli-bundle/chunks/stats-RG6AG4N2.js.map +0 -7
  569. package/dist/cli-bundle/chunks/telemetry-HQC2JJIF.js +0 -14
  570. package/dist/cli-bundle/chunks/telemetry-HQC2JJIF.js.map +0 -7
  571. package/dist/cli-bundle/chunks/telemetry-MPNL3HHY.js +0 -18
  572. package/dist/cli-bundle/chunks/telemetry-MPNL3HHY.js.map +0 -1
  573. package/dist/cli-bundle/chunks/test-6CMOCWUC.js +0 -39
  574. package/dist/cli-bundle/chunks/test-6CMOCWUC.js.map +0 -7
  575. package/dist/cli-bundle/chunks/test-RI7XHBZL.js +0 -43
  576. package/dist/cli-bundle/chunks/test-RI7XHBZL.js.map +0 -1
  577. package/dist/cli-bundle/chunks/test-all-7R7YRZIA.js +0 -29
  578. package/dist/cli-bundle/chunks/test-all-7R7YRZIA.js.map +0 -7
  579. package/dist/cli-bundle/chunks/test-all-QEIORFYW.js +0 -33
  580. package/dist/cli-bundle/chunks/test-all-QEIORFYW.js.map +0 -1
  581. package/dist/cli-bundle/chunks/test-runs-5Y2BOU2S.js +0 -28
  582. package/dist/cli-bundle/chunks/test-runs-5Y2BOU2S.js.map +0 -1
  583. package/dist/cli-bundle/chunks/test-runs-PVGC3GRZ.js +0 -24
  584. package/dist/cli-bundle/chunks/test-runs-PVGC3GRZ.js.map +0 -7
  585. package/dist/cli-bundle/chunks/update-QVJDFEAP.js +0 -30
  586. package/dist/cli-bundle/chunks/update-QVJDFEAP.js.map +0 -1
  587. package/dist/cli-bundle/chunks/update-VQVHAY6X.js +0 -26
  588. package/dist/cli-bundle/chunks/update-VQVHAY6X.js.map +0 -7
  589. package/dist/cli-bundle/chunks/update-many-S7XWBSB3.js +0 -37
  590. package/dist/cli-bundle/chunks/update-many-S7XWBSB3.js.map +0 -7
  591. package/dist/cli-bundle/chunks/update-many-YIYW6XQ6.js +0 -41
  592. package/dist/cli-bundle/chunks/update-many-YIYW6XQ6.js.map +0 -1
  593. package/dist/cli-bundle/chunks/upgrade-OPRXA56R.js +0 -24
  594. package/dist/cli-bundle/chunks/upgrade-OPRXA56R.js.map +0 -7
  595. package/dist/cli-bundle/chunks/upgrade-WH4BTQLX.js +0 -28
  596. package/dist/cli-bundle/chunks/upgrade-WH4BTQLX.js.map +0 -1
  597. package/dist/cli-bundle/chunks/validate-4NTXSB62.js +0 -36
  598. package/dist/cli-bundle/chunks/validate-4NTXSB62.js.map +0 -1
  599. package/dist/cli-bundle/chunks/validate-MUFXQZMI.js +0 -32
  600. package/dist/cli-bundle/chunks/validate-MUFXQZMI.js.map +0 -7
  601. /package/dist/cli-bundle/chunks/{activity-WJCGCYPU.js.map → append-F7WPGIQL.js.map} +0 -0
  602. /package/dist/cli-bundle/chunks/{activity-Z6QUAUSG.js.map → append-PVCTBVJG.js.map} +0 -0
  603. /package/dist/cli-bundle/chunks/{chunk-R5BMJX33.js.map → chunk-2LEJGRQ7.js.map} +0 -0
  604. /package/dist/cli-bundle/chunks/{chunk-AZYGZGGI.js.map → chunk-2TILG6F2.js.map} +0 -0
  605. /package/dist/cli-bundle/chunks/{chunk-GJ7QC5DJ.js.map → chunk-3TYOW6RR.js.map} +0 -0
  606. /package/dist/cli-bundle/chunks/{chunk-B6DUFX6H.js.map → chunk-3X542TEY.js.map} +0 -0
  607. /package/dist/cli-bundle/chunks/{chunk-JJP45OEI.js.map → chunk-7VQ3JJN5.js.map} +0 -0
  608. /package/dist/cli-bundle/chunks/{chunk-MWMVPCIE.js.map → chunk-AGAVEDIE.js.map} +0 -0
  609. /package/dist/cli-bundle/chunks/{chunk-22KBU3MW.js.map → chunk-AJUON7E6.js.map} +0 -0
  610. /package/dist/cli-bundle/chunks/{chunk-IWVU4C2F.js.map → chunk-DR2V5OIV.js.map} +0 -0
  611. /package/dist/cli-bundle/chunks/{chunk-XG625QP4.js.map → chunk-EDO7VXSO.js.map} +0 -0
  612. /package/dist/cli-bundle/chunks/{chunk-Y4M7CPQP.js.map → chunk-EVEPHNXJ.js.map} +0 -0
  613. /package/dist/cli-bundle/chunks/{chunk-JDDLOQAE.js.map → chunk-FN6SB4HU.js.map} +0 -0
  614. /package/dist/cli-bundle/chunks/{chunk-24YG75HI.js.map → chunk-H2SMKL2N.js.map} +0 -0
  615. /package/dist/cli-bundle/chunks/{chunk-EGY6JBQ3.js.map → chunk-HX6QXV5P.js.map} +0 -0
  616. /package/dist/cli-bundle/chunks/{chunk-Y46GD4IX.js.map → chunk-P3MJJW7P.js.map} +0 -0
  617. /package/dist/cli-bundle/chunks/{chunk-MVYWGY2A.js.map → chunk-PDXJXEZJ.js.map} +0 -0
  618. /package/dist/cli-bundle/chunks/{chunk-AGHMOTGM.js.map → chunk-TEKZOS7M.js.map} +0 -0
  619. /package/dist/cli-bundle/chunks/{chunk-JVH7QBVV.js.map → chunk-V5ZWKJNY.js.map} +0 -0
  620. /package/dist/cli-bundle/chunks/{chunk-KUOOJR35.js.map → chunk-VLEA2UTQ.js.map} +0 -0
  621. /package/dist/cli-bundle/chunks/{chunk-MUH7A3FD.js.map → chunk-WCWVEXGA.js.map} +0 -0
  622. /package/dist/cli-bundle/chunks/{chunk-NGXQ3PFT.js.map → chunk-YPMZMKN7.js.map} +0 -0
  623. /package/dist/cli-bundle/chunks/{chunk-KGFUY7WN.js.map → chunk-YTD5GICJ.js.map} +0 -0
  624. /package/dist/cli-bundle/chunks/{chunk-7DT4WSH2.js.map → chunk-ZO7CLOY2.js.map} +0 -0
  625. /package/dist/cli-bundle/chunks/{aggregate-BDM6EIAR.js.map → close-3YYQ5OG2.js.map} +0 -0
  626. /package/dist/cli-bundle/chunks/{aggregate-VQ2DHU3S.js.map → close-Z3Q4U7TS.js.map} +0 -0
  627. /package/dist/cli-bundle/chunks/{append-RKJYPU74.js.map → close-many-3L2RXH3M.js.map} +0 -0
  628. /package/dist/cli-bundle/chunks/{append-BGML6VLD.js.map → close-many-D366FTIG.js.map} +0 -0
  629. /package/dist/cli-bundle/chunks/{claim-XP5AWZ5H.js.map → comments-54XDJNFE.js.map} +0 -0
  630. /package/dist/cli-bundle/chunks/{claim-RFS7BROJ.js.map → comments-HGHC2PN6.js.map} +0 -0
  631. /package/dist/cli-bundle/chunks/{close-2SSSHHUZ.js.map → copy-44RT5GDW.js.map} +0 -0
  632. /package/dist/cli-bundle/chunks/{close-GEANHQ2J.js.map → copy-UGMUGHZA.js.map} +0 -0
  633. /package/dist/cli-bundle/chunks/{close-many-CMZW7ITN.js.map → create-4GWJWPXG.js.map} +0 -0
  634. /package/dist/cli-bundle/chunks/{close-many-ZFDIG6M7.js.map → create-AZXCUYKP.js.map} +0 -0
  635. /package/dist/cli-bundle/chunks/{comments-XUBPXDYX.js.map → delete-Y6SXIQ4X.js.map} +0 -0
  636. /package/dist/cli-bundle/chunks/{comments-MFSYVNNU.js.map → delete-YQ2VPXNF.js.map} +0 -0
  637. /package/dist/cli-bundle/chunks/{config-T4FHBSYN.js.map → deps-BU5EBJDU.js.map} +0 -0
  638. /package/dist/cli-bundle/chunks/{config-D7XQMONX.js.map → deps-FMANWFRP.js.map} +0 -0
  639. /package/dist/cli-bundle/chunks/{context-DIU275XI.js.map → docs-OQBSJNIA.js.map} +0 -0
  640. /package/dist/cli-bundle/chunks/{context-JCOYB4LZ.js.map → docs-VNPBZXEL.js.map} +0 -0
  641. /package/dist/cli-bundle/chunks/{contracts-BVO7CSLK.js.map → files-72HZEBOE.js.map} +0 -0
  642. /package/dist/cli-bundle/chunks/{contracts-NYPEW2G4.js.map → files-HTSB2KJG.js.map} +0 -0
  643. /package/dist/cli-bundle/chunks/{copy-32ROBIDL.js.map → focus-FOG4ALC2.js.map} +0 -0
  644. /package/dist/cli-bundle/chunks/{copy-NAGLGMHZ.js.map → focus-SUTMKXGX.js.map} +0 -0
  645. /package/dist/cli-bundle/chunks/{create-E77SDCUP.js.map → history-compact-M6IFAMBP.js.map} +0 -0
  646. /package/dist/cli-bundle/chunks/{create-4V7SWNBB.js.map → history-compact-NEXRPP2O.js.map} +0 -0
  647. /package/dist/cli-bundle/chunks/{delete-RA5KTCLB.js.map → history-redact-NQX3OGZP.js.map} +0 -0
  648. /package/dist/cli-bundle/chunks/{delete-NQI5OSKN.js.map → history-redact-WQJBZ3PX.js.map} +0 -0
  649. /package/dist/cli-bundle/chunks/{deps-T7SCWXEX.js.map → history-repair-CBHMHAJO.js.map} +0 -0
  650. /package/dist/cli-bundle/chunks/{deps-32SU7HO5.js.map → history-repair-NHOJG7WO.js.map} +0 -0
  651. /package/dist/cli-bundle/chunks/{docs-WL2IWGWV.js.map → learnings-M64NTSOR.js.map} +0 -0
  652. /package/dist/cli-bundle/chunks/{docs-RRUPT7O2.js.map → learnings-T63JGKKN.js.map} +0 -0
  653. /package/dist/cli-bundle/chunks/{eval-NF2J5SHR.js.map → notes-73WE2UV2.js.map} +0 -0
  654. /package/dist/cli-bundle/chunks/{eval-SKDT3MZU.js.map → notes-U7L6HQQ2.js.map} +0 -0
  655. /package/dist/cli-bundle/chunks/{extension-ZISPBRBC.js.map → plan-OSCNYFGC.js.map} +0 -0
  656. /package/dist/cli-bundle/chunks/{extension-LAXKCAYE.js.map → plan-TN537L24.js.map} +0 -0
  657. /package/dist/cli-bundle/chunks/{files-PYKR2UUG.js.map → profile-MHAMXMHQ.js.map} +0 -0
  658. /package/dist/cli-bundle/chunks/{files-EWRQHGIS.js.map → profile-TIGLAKJ7.js.map} +0 -0
  659. /package/dist/cli-bundle/chunks/{focus-4T7TM4MT.js.map → restore-HC3YSWF7.js.map} +0 -0
  660. /package/dist/cli-bundle/chunks/{focus-L3YUASOD.js.map → restore-LFAMMRYZ.js.map} +0 -0
  661. /package/dist/cli-bundle/chunks/{gc-2PCTYYRI.js.map → schema-DAGSYO6E.js.map} +0 -0
  662. /package/dist/cli-bundle/chunks/{gc-2DNMPXMC.js.map → schema-UBXJCQAC.js.map} +0 -0
  663. /package/dist/cli-bundle/chunks/{get-VKQXCXLL.js.map → update-CJGG5WMV.js.map} +0 -0
  664. /package/dist/cli-bundle/chunks/{get-7DMITJ3G.js.map → update-LKD64AFP.js.map} +0 -0
  665. /package/dist/cli-bundle/chunks/{health-CVSTAR2F.js.map → update-many-G4SM7BHC.js.map} +0 -0
  666. /package/dist/cli-bundle/chunks/{health-TV3GKTFN.js.map → update-many-VLIV3D7R.js.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../cli/commands/history-redact.ts","../../../../../../../../core/history/history-rewrite.ts"],"sourcesContent":["/**\n * @module cli/commands/history-redact\n *\n * Implements the pm history redact command surface and its agent-facing runtime behavior.\n */\nimport fs from \"node:fs/promises\";\nimport { pathExists, readFileIfExists, writeFileAtomic } from \"../../core/fs/fs-utils.js\";\nimport { createHistoryEntry } from \"../../core/history/history.js\";\nimport { executeHistoryRewrite } from \"../../core/history/history-rewrite.js\";\nimport {\n EMPTY_REPLAY_DOCUMENT,\n historyEntriesToRaw,\n replayHash,\n replayToItemDocument,\n tryApplyReplayPatch,\n verifyHistoryChain,\n type ReplayDocument,\n} from \"../../core/history/replay.js\";\nimport { normalizeItemId, normalizeRawItemId } from \"../../core/item/id.js\";\nimport { canonicalDocument, serializeItemDocument } from \"../../core/item/item-format.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { nowIso } from \"../../core/shared/time.js\";\nimport { getActiveExtensionRegistrations, runActiveOnWriteHooks } from \"../../core/extensions/index.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getItemPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { resolveAuthor } from \"../../core/shared/author.js\";\nimport type { HistoryEntry, HistoryPatchOp, ItemDocument } from \"../../types/index.js\";\nimport { readHistoryEntries } from \"./history.js\";\n\n/**\n * Documents the history redact command options payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRedactCommandOptions {\n literal?: string[] | string;\n regex?: string[] | string;\n replacement?: string;\n dryRun?: boolean;\n author?: string;\n message?: string;\n force?: boolean;\n}\n\ninterface RegexRule {\n kind: \"regex\";\n source: string;\n flags: string;\n label: string;\n}\n\ninterface LiteralRule {\n kind: \"literal\";\n value: string;\n label: string;\n}\n\ntype RedactionRule = RegexRule | LiteralRule;\n\ninterface RedactionRewriteResult {\n entries: HistoryEntry[];\n finalDocument: ReplayDocument;\n entriesChanged: number;\n replacements: number;\n}\n\ninterface HistoryIntegritySnapshot {\n hashMismatchesBefore: number;\n hashMismatchesAfter: number;\n finalDocument: ReplayDocument;\n}\n\ninterface HistoryRedactCurrentItem {\n raw: string | null;\n path: string | null;\n document: ItemDocument | null;\n}\n\ninterface HistoryRedactNextItem {\n raw: string | null;\n path: string | null;\n document: ItemDocument | null;\n}\n\n/**\n * Documents the history subject payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistorySubject {\n id: string;\n historyPath: string;\n located: Awaited<ReturnType<typeof locateItem>>;\n}\n\n/**\n * Documents the history redact result payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRedactResult {\n id: string;\n dry_run: boolean;\n changed: boolean;\n patterns: {\n literals: string[];\n regex: string[];\n replacement: string;\n };\n history: {\n path: string;\n entries_scanned: number;\n entries_changed: number;\n replacements: number;\n hash_mismatches_before: number;\n hash_mismatches_after: number;\n preexisting_hash_mismatches: number;\n audit_entry_added: boolean;\n verify_ok: boolean;\n verify_errors: string[];\n };\n item: {\n existed_before: boolean;\n exists_after: boolean;\n path_before: string | null;\n path_after: string | null;\n changed: boolean;\n };\n warnings: string[];\n generated_at: string;\n}\n\nfunction normalizeStringArrayInput(value: string[] | string | undefined): string[] {\n if (Array.isArray(value)) {\n return value;\n }\n if (typeof value === \"string\") {\n return [value];\n }\n return [];\n}\n\nfunction normalizeRegexFlags(flags: string): string {\n const unique: string[] = [];\n for (const token of flags) {\n if (!unique.includes(token)) {\n unique.push(token);\n }\n }\n if (!unique.includes(\"g\")) {\n unique.push(\"g\");\n }\n return unique.join(\"\");\n}\n\nfunction parseRegexRule(spec: string): RegexRule {\n const trimmed = spec.trim();\n if (trimmed.length === 0) {\n throw new PmCliError(\"history-redact --regex requires a non-empty pattern.\", EXIT_CODE.USAGE);\n }\n\n let source = trimmed;\n let flags = \"g\";\n if (trimmed.startsWith(\"/\") && trimmed.length > 1) {\n /* c8 ignore start -- bare-slash regex literals are rejected earlier in argument validation. */\n const slashIndex = trimmed.lastIndexOf(\"/\");\n if (slashIndex > 0) {\n source = trimmed.slice(1, slashIndex);\n flags = normalizeRegexFlags(trimmed.slice(slashIndex + 1));\n }\n /* c8 ignore stop */\n }\n if (source.length === 0) {\n throw new PmCliError(\"history-redact --regex cannot use an empty pattern.\", EXIT_CODE.USAGE);\n }\n try {\n new RegExp(source, flags);\n } catch (error) {\n /* c8 ignore start -- RegExp constructor failures are normalized in higher-level parser tests. */\n throw new PmCliError(\n `Invalid --regex value \"${spec}\": ${error instanceof Error ? error.message : String(error)}`,\n EXIT_CODE.USAGE,\n );\n /* c8 ignore stop */\n }\n\n return {\n kind: \"regex\",\n source,\n flags,\n label: `/${source}/${flags}`,\n };\n}\n\nfunction buildRedactionRules(\n literalInput: string[] | string | undefined,\n regexInput: string[] | string | undefined,\n): RedactionRule[] {\n const literalRules = [...new Set(normalizeStringArrayInput(literalInput).map((entry) => entry.trim()))]\n .filter((entry) => entry.length > 0)\n .map<LiteralRule>((entry) => ({\n kind: \"literal\",\n value: entry,\n label: entry,\n }));\n const regexRules = [...new Set(normalizeStringArrayInput(regexInput).map((entry) => entry.trim()))]\n .filter((entry) => entry.length > 0)\n .map(parseRegexRule);\n\n const rules = [...literalRules, ...regexRules];\n if (rules.length === 0) {\n throw new PmCliError(\n \"history-redact requires at least one matcher via --literal or --regex.\",\n EXIT_CODE.USAGE,\n {\n code: \"missing_required_argument\",\n required: \"Provide --literal <value> and/or --regex <pattern>.\",\n examples: [\n 'pm history-redact pm-a1b2 --literal \"[redacted_path_prefix]/private\"',\n 'pm history-redact pm-a1b2 --regex \"/192\\\\\\\\.168\\\\\\\\.[0-9.]+/g\" --replacement \"[scrubbed_ip]\"',\n ],\n },\n );\n }\n return rules;\n}\n\nfunction applyLiteralRule(value: string, literal: string, replacement: string): { value: string; replacements: number } {\n if (literal.length === 0) {\n return { value, replacements: 0 };\n }\n let cursor = 0;\n let replacements = 0;\n while (cursor <= value.length) {\n const index = value.indexOf(literal, cursor);\n if (index === -1) {\n break;\n }\n replacements += 1;\n cursor = index + Math.max(1, literal.length);\n }\n if (replacements === 0) {\n return { value, replacements: 0 };\n }\n return {\n value: value.split(literal).join(replacement),\n replacements,\n };\n}\n\nfunction applyRegexRule(value: string, rule: RegexRule, replacement: string): { value: string; replacements: number } {\n const regex = new RegExp(rule.source, rule.flags);\n const matches = [...value.matchAll(regex)];\n if (matches.length === 0) {\n return { value, replacements: 0 };\n }\n return {\n value: value.replace(regex, replacement),\n replacements: matches.length,\n };\n}\n\nfunction redactStringValue(value: string, rules: RedactionRule[], replacement: string): { value: string; replacements: number } {\n let next = value;\n let replacements = 0;\n for (const rule of rules) {\n const result =\n rule.kind === \"literal\"\n ? applyLiteralRule(next, rule.value, replacement)\n : applyRegexRule(next, rule, replacement);\n next = result.value;\n replacements += result.replacements;\n }\n return {\n value: next,\n replacements,\n };\n}\n\nfunction redactUnknownValue(value: unknown, rules: RedactionRule[], replacement: string): { value: unknown; replacements: number } {\n if (typeof value === \"string\") {\n return redactStringValue(value, rules, replacement);\n }\n if (Array.isArray(value)) {\n let replacements = 0;\n const nextValues = value.map((entry) => {\n const redacted = redactUnknownValue(entry, rules, replacement);\n replacements += redacted.replacements;\n return redacted.value;\n });\n return {\n value: nextValues,\n replacements,\n };\n }\n if (typeof value === \"object\" && value !== null) {\n let replacements = 0;\n const nextRecord: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n const redacted = redactUnknownValue(entry, rules, replacement);\n replacements += redacted.replacements;\n nextRecord[key] = redacted.value;\n }\n return {\n value: nextRecord,\n replacements,\n };\n }\n return {\n value,\n replacements: 0,\n };\n}\n\nfunction applyHistoryPatch(current: ReplayDocument, patch: HistoryPatchOp[], entryNumber: number, op: string): ReplayDocument {\n const result = tryApplyReplayPatch(current, patch);\n /* c8 ignore start -- invalid patch replay paths are covered by replay helper tests. */\n if (!result.ok) {\n throw new PmCliError(\n `history-redact failed to apply patch at entry ${entryNumber} (op=${op}): ${\n result.error instanceof Error ? result.error.message : String(result.error)\n }`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n /* c8 ignore stop */\n return result.document;\n}\n\nfunction inspectHistoryIntegrity(entries: HistoryEntry[]): HistoryIntegritySnapshot {\n let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);\n let hashMismatchesBefore = 0;\n let hashMismatchesAfter = 0;\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n if (replayHash(replay) !== entry.before_hash) {\n hashMismatchesBefore += 1;\n }\n replay = applyHistoryPatch(replay, entry.patch, index + 1, entry.op);\n /* c8 ignore start -- after-hash mismatch branch is exercised in dedicated history integrity tests. */\n if (replayHash(replay) !== entry.after_hash) {\n hashMismatchesAfter += 1;\n }\n /* c8 ignore stop */\n }\n return {\n hashMismatchesBefore,\n hashMismatchesAfter,\n finalDocument: replay,\n };\n}\n\nfunction redactHistoryEntry(entry: HistoryEntry, rules: RedactionRule[], replacement: string): {\n entry: HistoryEntry;\n replacements: number;\n changed: boolean;\n} {\n let replacements = 0;\n let changed = false;\n let nextMessage = entry.message;\n\n if (typeof entry.message === \"string\") {\n const redactedMessage = redactStringValue(entry.message, rules, replacement);\n nextMessage = redactedMessage.value;\n replacements += redactedMessage.replacements;\n if (redactedMessage.replacements > 0) {\n changed = true;\n }\n }\n\n const nextPatch = entry.patch.map((operation) => {\n /* c8 ignore start -- patch operations without `value` are covered in lower-level patch adapters. */\n if (!Object.prototype.hasOwnProperty.call(operation, \"value\")) {\n return operation;\n }\n /* c8 ignore stop */\n const redactedValue = redactUnknownValue(operation.value, rules, replacement);\n replacements += redactedValue.replacements;\n if (redactedValue.replacements > 0) {\n changed = true;\n return {\n ...operation,\n value: redactedValue.value,\n };\n }\n return operation;\n });\n\n return {\n entry: {\n ...entry,\n message: nextMessage,\n patch: nextPatch,\n },\n replacements,\n changed,\n };\n}\n\nfunction rewriteHistoryEntries(entries: HistoryEntry[], rules: RedactionRule[], replacement: string): RedactionRewriteResult {\n let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);\n let entriesChanged = 0;\n let replacements = 0;\n const rewrittenEntries: HistoryEntry[] = [];\n\n for (let index = 0; index < entries.length; index += 1) {\n const redacted = redactHistoryEntry(entries[index], rules, replacement);\n replacements += redacted.replacements;\n if (redacted.changed) {\n entriesChanged += 1;\n }\n const beforeHash = replayHash(replay);\n replay = applyHistoryPatch(replay, redacted.entry.patch, index + 1, redacted.entry.op);\n const afterHash = replayHash(replay);\n rewrittenEntries.push({\n ...redacted.entry,\n before_hash: beforeHash,\n after_hash: afterHash,\n });\n }\n\n return {\n entries: rewrittenEntries,\n finalDocument: replay,\n entriesChanged,\n replacements,\n };\n}\n\nfunction hasItemMetadata(replay: ReplayDocument): boolean {\n return Object.keys(replay.metadata).length > 0;\n}\n\nasync function loadHistoryRedactCurrentItem(\n subject: HistorySubject,\n settings: Awaited<ReturnType<typeof readSettings>>,\n): Promise<HistoryRedactCurrentItem> {\n const currentItemPath = subject.located?.itemPath ?? null;\n if (!subject.located) {\n return { raw: null, path: currentItemPath, document: null };\n }\n const loaded = await readLocatedItem(subject.located, { schema: settings.schema });\n return { raw: loaded.raw, path: currentItemPath, document: loaded.document };\n}\n\nfunction resolveHistoryRedactNextItem(params: {\n pmRoot: string;\n subject: HistorySubject;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeToFolder: Record<string, string>;\n finalDocument: ReplayDocument;\n}): HistoryRedactNextItem {\n if (!hasItemMetadata(params.finalDocument)) {\n return { raw: null, path: null, document: null };\n }\n const canonical = canonicalDocument(replayToItemDocument(params.finalDocument), { schema: params.settings.schema });\n if (canonical.metadata.id !== params.subject.id) {\n throw new PmCliError(\n `history-redact would change item id from ${params.subject.id} to ${canonical.metadata.id}; narrow your patterns.`,\n EXIT_CODE.USAGE,\n );\n }\n return {\n document: canonical,\n path: getItemPath(params.pmRoot, canonical.metadata.type, params.subject.id, \"toon\", params.typeToFolder),\n raw: serializeItemDocument(canonical, {\n format: \"toon\",\n schema: params.settings.schema,\n }),\n };\n}\n\n/* v8 ignore start -- message passthrough/plural formatting is deterministic around covered redaction outcomes */\nfunction buildHistoryRedactMessage(options: HistoryRedactCommandOptions, rewritten: RedactionRewriteResult): string {\n if (typeof options.message === \"string\" && options.message.trim().length > 0) {\n return options.message;\n }\n return `history-redact replaced ${rewritten.replacements} match(es) across ${rewritten.entriesChanged} entr${\n rewritten.entriesChanged === 1 ? \"y\" : \"ies\"\n }.`;\n}\n/* v8 ignore stop */\n\nfunction buildHistoryRedactEntries(params: {\n rewritten: RedactionRewriteResult;\n dryRun: boolean;\n changed: boolean;\n nextItemDocument: ItemDocument | null;\n author: string;\n message: string;\n}): { rewrittenEntries: HistoryEntry[]; auditEntryAdded: boolean } {\n const rewrittenEntries = [...params.rewritten.entries];\n if (params.dryRun || !params.changed) {\n return { rewrittenEntries, auditEntryAdded: false };\n }\n /* c8 ignore next -- fallback replay-to-item conversion runs only when rewritten final metadata is absent. */\n const finalDocument = params.nextItemDocument ?? replayToItemDocument(params.rewritten.finalDocument);\n rewrittenEntries.push(\n createHistoryEntry({\n nowIso: nowIso(),\n author: params.author,\n op: \"history_redact\",\n before: finalDocument,\n after: finalDocument,\n message: params.message,\n }),\n );\n return { rewrittenEntries, auditEntryAdded: true };\n}\n\nasync function applyHistoryRedactRewrite(params: {\n pmRoot: string;\n subject: HistorySubject;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeRegistry: ReturnType<typeof resolveItemTypeRegistry>;\n historyRawBeforeLock: string | null;\n currentItem: HistoryRedactCurrentItem;\n nextItem: HistoryRedactNextItem;\n author: string;\n force: boolean | undefined;\n rewrittenEntries: HistoryEntry[];\n}): Promise<string[]> {\n return executeHistoryRewrite({\n pmRoot: params.pmRoot,\n subject: params.subject,\n settings: params.settings,\n typeRegistry: params.typeRegistry,\n historyRawBeforeLock: params.historyRawBeforeLock,\n currentItemRawBeforeLock: params.currentItem.raw,\n operation: \"history-redact\",\n author: params.author,\n force: params.force,\n itemDocument: params.currentItem.document,\n applyRewrite: async ({ historyRawUnderLock }) => {\n const affectedItemPaths = new Set<string>();\n if (params.currentItem.path) {\n affectedItemPaths.add(params.currentItem.path);\n }\n if (params.nextItem.path) {\n affectedItemPaths.add(params.nextItem.path);\n }\n const itemSnapshots = new Map<string, string>();\n if (params.currentItem.path && params.currentItem.raw !== null) {\n itemSnapshots.set(params.currentItem.path, params.currentItem.raw);\n }\n try {\n /* c8 ignore next -- item-write diff branch requires path and content divergence under lock races. */\n if (params.nextItem.path && params.nextItem.raw !== null && params.nextItem.raw !== params.currentItem.raw) {\n await writeFileAtomic(params.nextItem.path, params.nextItem.raw);\n }\n if (params.currentItem.path && (!params.nextItem.path || params.nextItem.path !== params.currentItem.path)) {\n await fs.rm(params.currentItem.path, { force: true });\n }\n await writeFileAtomic(params.subject.historyPath, historyEntriesToRaw(params.rewrittenEntries));\n } catch (error) {\n await rollbackHistoryRedactRewrite(params.subject.historyPath, historyRawUnderLock, affectedItemPaths, itemSnapshots);\n throw error;\n }\n },\n applyPostRewrite: async () => runHistoryRedactWriteHooks(params.subject.historyPath, [\n params.nextItem.path,\n params.currentItem.path,\n ]),\n });\n}\n\nasync function rollbackHistoryRedactRewrite(\n historyPath: string,\n historyRawUnderLock: string | null,\n affectedItemPaths: Set<string>,\n itemSnapshots: Map<string, string>,\n): Promise<void> {\n /* c8 ignore start -- no-history-under-lock rollback path is exercised in lock-race integration tests. */\n if (historyRawUnderLock === null) {\n await fs.rm(historyPath, { force: true });\n } else {\n await writeFileAtomic(historyPath, historyRawUnderLock);\n }\n /* c8 ignore stop */\n for (const itemPath of affectedItemPaths) {\n const snapshot = itemSnapshots.get(itemPath);\n /* c8 ignore start -- missing snapshot rollback occurs only for create/delete race permutations. */\n if (snapshot === undefined) {\n await fs.rm(itemPath, { force: true });\n } else {\n await writeFileAtomic(itemPath, snapshot);\n }\n /* c8 ignore stop */\n }\n}\n\nasync function runHistoryRedactWriteHooks(historyPath: string, itemHookPaths: Array<string | null>): Promise<string[]> {\n const hookWarnings: string[] = [];\n const uniqueItemHookPaths = new Set(itemHookPaths.filter((itemPath): itemPath is string => itemPath !== null));\n for (const itemHookPath of uniqueItemHookPaths) {\n hookWarnings.push(\n ...(await runActiveOnWriteHooks({\n path: itemHookPath,\n scope: \"project\",\n op: \"history_redact\",\n })),\n );\n }\n hookWarnings.push(\n ...(await runActiveOnWriteHooks({\n path: historyPath,\n scope: \"project\",\n op: \"history_redact:history\",\n })),\n );\n return hookWarnings;\n}\n\n/**\n * Implements resolve history subject for the public runtime surface of this module.\n */\nexport async function resolveHistorySubject(\n pmRoot: string,\n id: string,\n settings: Awaited<ReturnType<typeof readSettings>>,\n typeToFolder: Record<string, string>,\n): Promise<HistorySubject> {\n const located = await locateItem(pmRoot, id, settings.id_prefix, settings.item_format, typeToFolder);\n if (located) {\n return {\n id: located.id,\n historyPath: getHistoryPath(pmRoot, located.id),\n located,\n };\n }\n\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const rawNormalizedId = normalizeRawItemId(id);\n const candidateIds = normalizedId === rawNormalizedId ? [normalizedId] : [normalizedId, rawNormalizedId];\n for (const candidateId of candidateIds) {\n const historyPath = getHistoryPath(pmRoot, candidateId);\n if (await pathExists(historyPath)) {\n return {\n id: candidateId,\n historyPath,\n located: null,\n };\n }\n }\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n}\n\n/**\n * Implements run history redact for the public runtime surface of this module.\n */\nexport async function runHistoryRedact(\n id: string,\n options: HistoryRedactCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRedactResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const replacement = typeof options.replacement === \"string\" && options.replacement.length > 0 ? options.replacement : \"[redacted]\";\n const rules = buildRedactionRules(options.literal, options.regex);\n const subject = await resolveHistorySubject(pmRoot, id, settings, typeRegistry.type_to_folder);\n\n if (!(await pathExists(subject.historyPath))) {\n throw new PmCliError(`No history stream exists for ${subject.id}.`, EXIT_CODE.NOT_FOUND);\n }\n const historyRawBeforeLock = await readFileIfExists(subject.historyPath);\n const historyEntries = await readHistoryEntries(subject.historyPath, subject.id);\n if (historyEntries.length === 0) {\n throw new PmCliError(`No history entries exist for ${subject.id}; nothing to redact.`, EXIT_CODE.USAGE);\n }\n\n const integritySnapshot = inspectHistoryIntegrity(historyEntries);\n const rewritten = rewriteHistoryEntries(historyEntries, rules, replacement);\n const preexistingHashMismatches = integritySnapshot.hashMismatchesBefore + integritySnapshot.hashMismatchesAfter;\n const dryRun = Boolean(options.dryRun);\n const changed = rewritten.replacements > 0;\n const warnings: string[] = [];\n if (preexistingHashMismatches > 0) {\n warnings.push(`history_redact_preexisting_hash_mismatches:${preexistingHashMismatches}`);\n }\n if (!changed) {\n warnings.push(\"history_redact_no_matches\");\n }\n\n const currentItem = await loadHistoryRedactCurrentItem(subject, settings);\n const nextItem = resolveHistoryRedactNextItem({\n pmRoot,\n subject,\n settings,\n typeToFolder: typeRegistry.type_to_folder,\n finalDocument: rewritten.finalDocument,\n });\n\n const itemChanged =\n /* c8 ignore next -- null-coalescing item-path comparison branch is exercised in broader command integration coverage. */\n (currentItem.path ?? null) !== (nextItem.path ?? null) ||\n /* c8 ignore next -- null-coalescing item-content comparison branch is exercised in broader command integration coverage. */\n (currentItem.raw ?? null) !== (nextItem.raw ?? null);\n\n const author = resolveAuthor(options.author, settings.author_default);\n const redactionMessage = buildHistoryRedactMessage(options, rewritten);\n const { rewrittenEntries, auditEntryAdded } = buildHistoryRedactEntries({\n rewritten,\n dryRun,\n changed,\n nextItemDocument: nextItem.document,\n author,\n message: redactionMessage,\n });\n const historyVerify = verifyHistoryChain(rewrittenEntries);\n /* c8 ignore start -- invalid rewritten chains are covered by history verification unit tests. */\n if (!historyVerify.ok) {\n throw new PmCliError(\n `history-redact produced an invalid rewritten chain (${historyVerify.errors.join(\", \")}).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n /* c8 ignore stop */\n\n if (!dryRun && changed) {\n warnings.push(\n ...(await applyHistoryRedactRewrite({\n pmRoot,\n subject,\n settings,\n typeRegistry,\n historyRawBeforeLock,\n currentItem,\n nextItem,\n author,\n force: options.force,\n rewrittenEntries,\n })),\n );\n }\n\n return {\n id: subject.id,\n dry_run: dryRun,\n changed,\n patterns: {\n literals: rules.filter((rule): rule is LiteralRule => rule.kind === \"literal\").map((rule) => rule.value),\n regex: rules.filter((rule): rule is RegexRule => rule.kind === \"regex\").map((rule) => `/${rule.source}/${rule.flags}`),\n replacement,\n },\n history: {\n path: subject.historyPath,\n entries_scanned: historyEntries.length,\n entries_changed: rewritten.entriesChanged,\n replacements: rewritten.replacements,\n hash_mismatches_before: integritySnapshot.hashMismatchesBefore,\n hash_mismatches_after: integritySnapshot.hashMismatchesAfter,\n preexisting_hash_mismatches: preexistingHashMismatches,\n audit_entry_added: auditEntryAdded,\n verify_ok: historyVerify.ok,\n verify_errors: historyVerify.errors,\n },\n item: {\n existed_before: currentItem.path !== null,\n exists_after: nextItem.path !== null,\n path_before: currentItem.path,\n path_after: nextItem.path,\n changed: itemChanged,\n },\n /* c8 ignore next -- warning dedupe ordering is covered indirectly by command-level smoke tests. */\n warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),\n generated_at: nowIso(),\n };\n}\n\nexport const _testOnly = {\n applyLiteralRule,\n applyRegexRule,\n buildRedactionRules,\n hasItemMetadata,\n normalizeRegexFlags,\n normalizeStringArrayInput,\n parseRegexRule,\n redactStringValue,\n redactUnknownValue,\n};\n","/**\n * @module core/history/history-rewrite\n *\n * Implements append-only history and replay behavior for History Rewrite.\n */\nimport fs from \"node:fs/promises\";\nimport { readFileIfExists, writeFileAtomic } from \"../fs/fs-utils.js\";\nimport type { ItemTypeRegistry } from \"../item/type-registry.js\";\nimport { acquireLock } from \"../lock/lock.js\";\nimport { EXIT_CODE } from \"../shared/constants.js\";\nimport { PmCliError } from \"../shared/errors.js\";\nimport { locateItem, readLocatedItem } from \"../store/item-store.js\";\nimport { resolveGovernanceKnobs } from \"../store/settings.js\";\nimport type { ItemDocument, PmSettings } from \"../../types/index.js\";\n\ntype LoadedItem = Awaited<ReturnType<typeof readLocatedItem>>;\ntype HistoryRawWriter = (filePath: string, content: string) => Promise<void>;\n\n/**\n * Documents the history rewrite subject payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRewriteSubject {\n id: string;\n historyPath: string;\n}\n\n/**\n * Documents the history rewrite ownership params payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRewriteOwnershipParams {\n itemDocument: ItemDocument | null;\n subjectId: string;\n author: string;\n force: boolean | undefined;\n settings: PmSettings;\n}\n\n/**\n * Apply ownership_enforcement governance to a history-rewriting operation.\n * Returns the warning(s) the caller should append (empty when no conflict or strict-throws).\n * Throws PmCliError(CONFLICT) in strict mode when the assignee conflicts and --force is not set.\n */\nexport function checkHistoryRewriteOwnership(params: HistoryRewriteOwnershipParams): string[] {\n if (!params.itemDocument) return [];\n const assigned = params.itemDocument.metadata?.assignee?.trim();\n if (!assigned || assigned === params.author || params.force) return [];\n\n const governance = resolveGovernanceKnobs(params.settings);\n if (governance.ownership_enforcement === \"strict\") {\n throw new PmCliError(\n `Item ${params.subjectId} is assigned to ${assigned}. Use --force to override.`,\n EXIT_CODE.CONFLICT,\n );\n }\n if (governance.ownership_enforcement === \"warn\") {\n return [`ownership_warning:assignee_conflict:${params.subjectId}:${assigned}`];\n }\n return [];\n}\n\n/**\n * Documents the verify history rewrite drift params payload exchanged by command, SDK, and package integrations.\n */\nexport interface VerifyHistoryRewriteDriftParams {\n pmRoot: string;\n subject: HistoryRewriteSubject;\n settings: PmSettings;\n typeRegistry: ItemTypeRegistry;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n /** Short operation name used in the conflict message (e.g. \"history-redact\"). */\n operation: string;\n}\n\n/**\n * Documents the verified history rewrite state payload exchanged by command, SDK, and package integrations.\n */\nexport interface VerifiedHistoryRewriteState {\n historyRawUnderLock: string | null;\n locatedUnderLock: Awaited<ReturnType<typeof locateItem>>;\n loadedItemUnderLock: LoadedItem | null;\n}\n\n/**\n * Re-read the history stream and the located item document under the acquired lock and\n * compare both with the pre-lock raw snapshots. Throws PmCliError(CONFLICT) if either\n * diverged while waiting for the lock so the caller surfaces an actionable retry.\n */\nexport async function verifyHistoryRewriteNoDrift(\n params: VerifyHistoryRewriteDriftParams,\n): Promise<VerifiedHistoryRewriteState> {\n const historyRawUnderLock = await readFileIfExists(params.subject.historyPath);\n if (historyRawUnderLock !== params.historyRawBeforeLock) {\n throw new PmCliError(\n `History for ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`,\n EXIT_CODE.CONFLICT,\n );\n }\n const locatedUnderLock = await locateItem(\n params.pmRoot,\n params.subject.id,\n params.settings.id_prefix,\n params.settings.item_format,\n params.typeRegistry.type_to_folder,\n );\n const loadedItemUnderLock = locatedUnderLock\n ? await readLocatedItem(locatedUnderLock, { schema: params.settings.schema })\n : null;\n if ((loadedItemUnderLock?.raw ?? null) !== (params.currentItemRawBeforeLock ?? null)) {\n throw new PmCliError(\n `Item ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`,\n EXIT_CODE.CONFLICT,\n );\n }\n return { historyRawUnderLock, locatedUnderLock, loadedItemUnderLock };\n}\n\n/**\n * Documents the execute history rewrite params payload exchanged by command, SDK, and package integrations.\n */\nexport interface ExecuteHistoryRewriteParams {\n pmRoot: string;\n subject: HistoryRewriteSubject;\n settings: PmSettings;\n typeRegistry: ItemTypeRegistry;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n /** Short operation name used in conflict guidance (e.g. \"history-redact\"). */\n operation: string;\n author: string;\n force: boolean | undefined;\n itemDocument: ItemDocument | null;\n applyRewrite: (verified: VerifiedHistoryRewriteState) => Promise<void>;\n applyPostRewrite?: (verified: VerifiedHistoryRewriteState) => Promise<string[]>;\n}\n\n/**\n * Writes the rewritten history stream and restores the under-lock snapshot on failure.\n */\nexport async function writeHistoryRawWithRollback(params: {\n historyPath: string;\n nextHistoryRaw: string;\n historyRawUnderLock: string | null;\n writeHistoryRaw?: HistoryRawWriter;\n}): Promise<void> {\n const writeHistoryRaw = params.writeHistoryRaw ?? writeFileAtomic;\n try {\n await writeHistoryRaw(params.historyPath, params.nextHistoryRaw);\n } catch (error) {\n try {\n if (params.historyRawUnderLock === null) {\n await fs.rm(params.historyPath, { force: true });\n } else {\n await writeHistoryRaw(params.historyPath, params.historyRawUnderLock);\n }\n } catch (rollbackError) {\n throw new AggregateError(\n [error, rollbackError],\n `History rewrite failed and rollback also failed: ${String(error)}`,\n );\n }\n throw error;\n }\n}\n\n/**\n * Shared lock/verify/ownership orchestration for history-rewrite commands.\n * Callers provide the operation-specific write/rollback logic and optional\n * post-write hook execution while this helper enforces the common governance +\n * lock sequencing contract.\n */\nexport async function executeHistoryRewrite(params: ExecuteHistoryRewriteParams): Promise<string[]> {\n const warnings = [...checkHistoryRewriteOwnership({\n itemDocument: params.itemDocument,\n subjectId: params.subject.id,\n author: params.author,\n force: params.force,\n settings: params.settings,\n })];\n const releaseLock = await acquireLock(\n params.pmRoot,\n params.subject.id,\n params.settings.locks.ttl_seconds,\n params.author,\n Boolean(params.force),\n params.settings.governance.force_required_for_stale_lock,\n params.settings.locks.wait_ms,\n );\n try {\n const verified = await verifyHistoryRewriteNoDrift({\n pmRoot: params.pmRoot,\n subject: params.subject,\n settings: params.settings,\n typeRegistry: params.typeRegistry,\n historyRawBeforeLock: params.historyRawBeforeLock,\n currentItemRawBeforeLock: params.currentItemRawBeforeLock,\n operation: params.operation,\n });\n await params.applyRewrite(verified);\n if (params.applyPostRewrite) {\n warnings.push(...(await params.applyPostRewrite(verified)));\n }\n return warnings;\n } finally {\n await releaseLock();\n }\n}\n"],"names":["fs","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAOA,SAAQ;;;ACAf,OAAO,QAAQ;AAqCT,SAAU,6BAA6B,QAAqC;AAChF,MAAI,CAAC,OAAO;AAAc,WAAO,CAAA;AACjC,QAAM,WAAW,OAAO,aAAa,UAAU,UAAU,KAAI;AAC7D,MAAI,CAAC,YAAY,aAAa,OAAO,UAAU,OAAO;AAAO,WAAO,CAAA;AAEpE,QAAM,aAAa,uBAAuB,OAAO,QAAQ;AACzD,MAAI,WAAW,0BAA0B,UAAU;AACjD,UAAM,IAAI,WACR,QAAQ,OAAO,SAAS,mBAAmB,QAAQ,8BACnD,UAAU,QAAQ;EAEtB;AACA,MAAI,WAAW,0BAA0B,QAAQ;AAC/C,WAAO,CAAC,uCAAuC,OAAO,SAAS,IAAI,QAAQ,EAAE;EAC/E;AACA,SAAO,CAAA;AACT;AA8BA,eAAsB,4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ACP,MAAM,QAAQ;MACd,iBAAiB,eAAe;MAChC,iBAAiB,UAAU;MAC3B,cAAc,UAAU;MACxB,wBAAwB,kBAAkB;MAC1C,uBAAuB,kBAAkB;MACzC,6BAA6B;MAC7B,mBAAmB;MACnB,WAAW,cAAc;MACzB,eAAe,cAAc;;IAE/B,MAAM;MACJ,gBAAgB,YAAY,SAAS;MACrC,cAAc,SAAS,SAAS;MAChC,aAAa,YAAY;MACzB,YAAY,SAAS;MACrB,SAAS;;;IAGX,UAAU,CAAC,GAAG,IAAI,IAAI,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,UAAU,KAAK,cAAc,KAAK,CAAC;IAChF,cAAc,OAAM;;AAExB;AAEO,IAAM,YAAY;EACvB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA","debugId":"486ead3c-861e-5236-bc1f-af9094097a77"}
1
+ {"version":3,"sources":["../../../../../../../../cli/commands/history-redact.ts","../../../../../../../../core/history/history-rewrite.ts"],"sourcesContent":["/**\n * @module cli/commands/history-redact\n *\n * Implements the pm history redact command surface and its agent-facing runtime behavior.\n */\nimport fs from \"node:fs/promises\";\nimport { pathExists, readFileIfExists, writeFileAtomic } from \"../../core/fs/fs-utils.js\";\nimport { createHistoryEntry } from \"../../core/history/history.js\";\nimport { executeHistoryRewrite } from \"../../core/history/history-rewrite.js\";\nimport {\n EMPTY_REPLAY_DOCUMENT,\n historyEntriesToRaw,\n replayHash,\n replayToItemDocument,\n tryApplyReplayPatch,\n verifyHistoryChain,\n type ReplayDocument,\n} from \"../../core/history/replay.js\";\nimport { normalizeItemId, normalizeRawItemId } from \"../../core/item/id.js\";\nimport { canonicalDocument, serializeItemDocument } from \"../../core/item/item-format.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { nowIso } from \"../../core/shared/time.js\";\nimport { getActiveExtensionRegistrations, runActiveOnWriteHooks } from \"../../core/extensions/index.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getItemPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { resolveAuthor } from \"../../core/shared/author.js\";\nimport type { HistoryEntry, HistoryPatchOp, ItemDocument } from \"../../types/index.js\";\nimport { readHistoryEntries } from \"./history.js\";\n\n/**\n * Documents the history redact command options payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRedactCommandOptions {\n literal?: string[] | string;\n regex?: string[] | string;\n replacement?: string;\n dryRun?: boolean;\n author?: string;\n message?: string;\n force?: boolean;\n}\n\ninterface RegexRule {\n kind: \"regex\";\n source: string;\n flags: string;\n label: string;\n}\n\ninterface LiteralRule {\n kind: \"literal\";\n value: string;\n label: string;\n}\n\ntype RedactionRule = RegexRule | LiteralRule;\n\ninterface RedactionRewriteResult {\n entries: HistoryEntry[];\n finalDocument: ReplayDocument;\n entriesChanged: number;\n replacements: number;\n}\n\ninterface HistoryIntegritySnapshot {\n hashMismatchesBefore: number;\n hashMismatchesAfter: number;\n finalDocument: ReplayDocument;\n}\n\ninterface HistoryRedactCurrentItem {\n raw: string | null;\n path: string | null;\n document: ItemDocument | null;\n}\n\ninterface HistoryRedactNextItem {\n raw: string | null;\n path: string | null;\n document: ItemDocument | null;\n}\n\n/**\n * Documents the history subject payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistorySubject {\n id: string;\n historyPath: string;\n located: Awaited<ReturnType<typeof locateItem>>;\n}\n\n/**\n * Documents the history redact result payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRedactResult {\n id: string;\n dry_run: boolean;\n changed: boolean;\n patterns: {\n literals: string[];\n regex: string[];\n replacement: string;\n };\n history: {\n path: string;\n entries_scanned: number;\n entries_changed: number;\n replacements: number;\n hash_mismatches_before: number;\n hash_mismatches_after: number;\n preexisting_hash_mismatches: number;\n audit_entry_added: boolean;\n verify_ok: boolean;\n verify_errors: string[];\n };\n item: {\n existed_before: boolean;\n exists_after: boolean;\n path_before: string | null;\n path_after: string | null;\n changed: boolean;\n };\n warnings: string[];\n generated_at: string;\n}\n\nfunction normalizeStringArrayInput(value: string[] | string | undefined): string[] {\n if (Array.isArray(value)) {\n return value;\n }\n if (typeof value === \"string\") {\n return [value];\n }\n return [];\n}\n\nfunction normalizeRegexFlags(flags: string): string {\n const unique: string[] = [];\n for (const token of flags) {\n if (!unique.includes(token)) {\n unique.push(token);\n }\n }\n if (!unique.includes(\"g\")) {\n unique.push(\"g\");\n }\n return unique.join(\"\");\n}\n\nfunction parseRegexRule(spec: string): RegexRule {\n const trimmed = spec.trim();\n if (trimmed.length === 0) {\n throw new PmCliError(\"history-redact --regex requires a non-empty pattern.\", EXIT_CODE.USAGE);\n }\n\n let source = trimmed;\n let flags = \"g\";\n if (trimmed.startsWith(\"/\") && trimmed.length > 1) {\n /* c8 ignore start -- bare-slash regex literals are rejected earlier in argument validation. */\n const slashIndex = trimmed.lastIndexOf(\"/\");\n if (slashIndex > 0) {\n source = trimmed.slice(1, slashIndex);\n flags = normalizeRegexFlags(trimmed.slice(slashIndex + 1));\n }\n /* c8 ignore stop */\n }\n if (source.length === 0) {\n throw new PmCliError(\"history-redact --regex cannot use an empty pattern.\", EXIT_CODE.USAGE);\n }\n try {\n new RegExp(source, flags);\n } catch (error) {\n /* c8 ignore start -- RegExp constructor failures are normalized in higher-level parser tests. */\n throw new PmCliError(\n `Invalid --regex value \"${spec}\": ${error instanceof Error ? error.message : String(error)}`,\n EXIT_CODE.USAGE,\n );\n /* c8 ignore stop */\n }\n\n return {\n kind: \"regex\",\n source,\n flags,\n label: `/${source}/${flags}`,\n };\n}\n\nfunction buildRedactionRules(\n literalInput: string[] | string | undefined,\n regexInput: string[] | string | undefined,\n): RedactionRule[] {\n const literalRules = [...new Set(normalizeStringArrayInput(literalInput).map((entry) => entry.trim()))]\n .filter((entry) => entry.length > 0)\n .map<LiteralRule>((entry) => ({\n kind: \"literal\",\n value: entry,\n label: entry,\n }));\n const regexRules = [...new Set(normalizeStringArrayInput(regexInput).map((entry) => entry.trim()))]\n .filter((entry) => entry.length > 0)\n .map(parseRegexRule);\n\n const rules = [...literalRules, ...regexRules];\n if (rules.length === 0) {\n throw new PmCliError(\n \"history-redact requires at least one matcher via --literal or --regex.\",\n EXIT_CODE.USAGE,\n {\n code: \"missing_required_argument\",\n required: \"Provide --literal <value> and/or --regex <pattern>.\",\n examples: [\n 'pm history-redact pm-a1b2 --literal \"[redacted_path_prefix]/private\"',\n 'pm history-redact pm-a1b2 --regex \"/192\\\\\\\\.168\\\\\\\\.[0-9.]+/g\" --replacement \"[scrubbed_ip]\"',\n ],\n },\n );\n }\n return rules;\n}\n\nfunction applyLiteralRule(value: string, literal: string, replacement: string): { value: string; replacements: number } {\n if (literal.length === 0) {\n return { value, replacements: 0 };\n }\n let cursor = 0;\n let replacements = 0;\n while (cursor <= value.length) {\n const index = value.indexOf(literal, cursor);\n if (index === -1) {\n break;\n }\n replacements += 1;\n cursor = index + Math.max(1, literal.length);\n }\n if (replacements === 0) {\n return { value, replacements: 0 };\n }\n return {\n value: value.split(literal).join(replacement),\n replacements,\n };\n}\n\nfunction applyRegexRule(value: string, rule: RegexRule, replacement: string): { value: string; replacements: number } {\n const regex = new RegExp(rule.source, rule.flags);\n const matches = [...value.matchAll(regex)];\n if (matches.length === 0) {\n return { value, replacements: 0 };\n }\n return {\n value: value.replace(regex, replacement),\n replacements: matches.length,\n };\n}\n\nfunction redactStringValue(value: string, rules: RedactionRule[], replacement: string): { value: string; replacements: number } {\n let next = value;\n let replacements = 0;\n for (const rule of rules) {\n const result =\n rule.kind === \"literal\"\n ? applyLiteralRule(next, rule.value, replacement)\n : applyRegexRule(next, rule, replacement);\n next = result.value;\n replacements += result.replacements;\n }\n return {\n value: next,\n replacements,\n };\n}\n\nfunction redactUnknownValue(value: unknown, rules: RedactionRule[], replacement: string): { value: unknown; replacements: number } {\n if (typeof value === \"string\") {\n return redactStringValue(value, rules, replacement);\n }\n if (Array.isArray(value)) {\n let replacements = 0;\n const nextValues = value.map((entry) => {\n const redacted = redactUnknownValue(entry, rules, replacement);\n replacements += redacted.replacements;\n return redacted.value;\n });\n return {\n value: nextValues,\n replacements,\n };\n }\n if (typeof value === \"object\" && value !== null) {\n let replacements = 0;\n const nextRecord: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n const redacted = redactUnknownValue(entry, rules, replacement);\n replacements += redacted.replacements;\n nextRecord[key] = redacted.value;\n }\n return {\n value: nextRecord,\n replacements,\n };\n }\n return {\n value,\n replacements: 0,\n };\n}\n\nfunction applyHistoryPatch(current: ReplayDocument, patch: HistoryPatchOp[], entryNumber: number, op: string): ReplayDocument {\n const result = tryApplyReplayPatch(current, patch);\n /* c8 ignore start -- invalid patch replay paths are covered by replay helper tests. */\n if (!result.ok) {\n throw new PmCliError(\n `history-redact failed to apply patch at entry ${entryNumber} (op=${op}): ${\n result.error instanceof Error ? result.error.message : String(result.error)\n }`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n /* c8 ignore stop */\n return result.document;\n}\n\nfunction inspectHistoryIntegrity(entries: HistoryEntry[]): HistoryIntegritySnapshot {\n let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);\n let hashMismatchesBefore = 0;\n let hashMismatchesAfter = 0;\n for (let index = 0; index < entries.length; index += 1) {\n const entry = entries[index];\n if (replayHash(replay) !== entry.before_hash) {\n hashMismatchesBefore += 1;\n }\n replay = applyHistoryPatch(replay, entry.patch, index + 1, entry.op);\n /* c8 ignore start -- after-hash mismatch branch is exercised in dedicated history integrity tests. */\n if (replayHash(replay) !== entry.after_hash) {\n hashMismatchesAfter += 1;\n }\n /* c8 ignore stop */\n }\n return {\n hashMismatchesBefore,\n hashMismatchesAfter,\n finalDocument: replay,\n };\n}\n\nfunction redactHistoryEntry(entry: HistoryEntry, rules: RedactionRule[], replacement: string): {\n entry: HistoryEntry;\n replacements: number;\n changed: boolean;\n} {\n let replacements = 0;\n let changed = false;\n let nextMessage = entry.message;\n\n if (typeof entry.message === \"string\") {\n const redactedMessage = redactStringValue(entry.message, rules, replacement);\n nextMessage = redactedMessage.value;\n replacements += redactedMessage.replacements;\n if (redactedMessage.replacements > 0) {\n changed = true;\n }\n }\n\n const nextPatch = entry.patch.map((operation) => {\n /* c8 ignore start -- patch operations without `value` are covered in lower-level patch adapters. */\n if (!Object.prototype.hasOwnProperty.call(operation, \"value\")) {\n return operation;\n }\n /* c8 ignore stop */\n const redactedValue = redactUnknownValue(operation.value, rules, replacement);\n replacements += redactedValue.replacements;\n if (redactedValue.replacements > 0) {\n changed = true;\n return {\n ...operation,\n value: redactedValue.value,\n };\n }\n return operation;\n });\n\n return {\n entry: {\n ...entry,\n message: nextMessage,\n patch: nextPatch,\n },\n replacements,\n changed,\n };\n}\n\nfunction rewriteHistoryEntries(entries: HistoryEntry[], rules: RedactionRule[], replacement: string): RedactionRewriteResult {\n let replay = structuredClone(EMPTY_REPLAY_DOCUMENT);\n let entriesChanged = 0;\n let replacements = 0;\n const rewrittenEntries: HistoryEntry[] = [];\n\n for (let index = 0; index < entries.length; index += 1) {\n const redacted = redactHistoryEntry(entries[index], rules, replacement);\n replacements += redacted.replacements;\n if (redacted.changed) {\n entriesChanged += 1;\n }\n const beforeHash = replayHash(replay);\n replay = applyHistoryPatch(replay, redacted.entry.patch, index + 1, redacted.entry.op);\n const afterHash = replayHash(replay);\n rewrittenEntries.push({\n ...redacted.entry,\n before_hash: beforeHash,\n after_hash: afterHash,\n });\n }\n\n return {\n entries: rewrittenEntries,\n finalDocument: replay,\n entriesChanged,\n replacements,\n };\n}\n\nfunction hasItemMetadata(replay: ReplayDocument): boolean {\n return Object.keys(replay.metadata).length > 0;\n}\n\nasync function loadHistoryRedactCurrentItem(\n subject: HistorySubject,\n settings: Awaited<ReturnType<typeof readSettings>>,\n): Promise<HistoryRedactCurrentItem> {\n const currentItemPath = subject.located?.itemPath ?? null;\n if (!subject.located) {\n return { raw: null, path: currentItemPath, document: null };\n }\n const loaded = await readLocatedItem(subject.located, { schema: settings.schema });\n return { raw: loaded.raw, path: currentItemPath, document: loaded.document };\n}\n\nfunction resolveHistoryRedactNextItem(params: {\n pmRoot: string;\n subject: HistorySubject;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeToFolder: Record<string, string>;\n finalDocument: ReplayDocument;\n}): HistoryRedactNextItem {\n if (!hasItemMetadata(params.finalDocument)) {\n return { raw: null, path: null, document: null };\n }\n const canonical = canonicalDocument(replayToItemDocument(params.finalDocument), { schema: params.settings.schema });\n if (canonical.metadata.id !== params.subject.id) {\n throw new PmCliError(\n `history-redact would change item id from ${params.subject.id} to ${canonical.metadata.id}; narrow your patterns.`,\n EXIT_CODE.USAGE,\n );\n }\n return {\n document: canonical,\n path: getItemPath(params.pmRoot, canonical.metadata.type, params.subject.id, \"toon\", params.typeToFolder),\n raw: serializeItemDocument(canonical, {\n format: \"toon\",\n schema: params.settings.schema,\n }),\n };\n}\n\n/* v8 ignore start -- message passthrough/plural formatting is deterministic around covered redaction outcomes */\nfunction buildHistoryRedactMessage(options: HistoryRedactCommandOptions, rewritten: RedactionRewriteResult): string {\n if (typeof options.message === \"string\" && options.message.trim().length > 0) {\n return options.message;\n }\n return `history-redact replaced ${rewritten.replacements} match(es) across ${rewritten.entriesChanged} entr${\n rewritten.entriesChanged === 1 ? \"y\" : \"ies\"\n }.`;\n}\n/* v8 ignore stop */\n\nfunction buildHistoryRedactEntries(params: {\n rewritten: RedactionRewriteResult;\n dryRun: boolean;\n changed: boolean;\n nextItemDocument: ItemDocument | null;\n author: string;\n message: string;\n}): { rewrittenEntries: HistoryEntry[]; auditEntryAdded: boolean } {\n const rewrittenEntries = [...params.rewritten.entries];\n if (params.dryRun || !params.changed) {\n return { rewrittenEntries, auditEntryAdded: false };\n }\n /* c8 ignore next -- fallback replay-to-item conversion runs only when rewritten final metadata is absent. */\n const finalDocument = params.nextItemDocument ?? replayToItemDocument(params.rewritten.finalDocument);\n rewrittenEntries.push(\n createHistoryEntry({\n nowIso: nowIso(),\n author: params.author,\n op: \"history_redact\",\n before: finalDocument,\n after: finalDocument,\n message: params.message,\n }),\n );\n return { rewrittenEntries, auditEntryAdded: true };\n}\n\nasync function applyHistoryRedactRewrite(params: {\n pmRoot: string;\n subject: HistorySubject;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeRegistry: ReturnType<typeof resolveItemTypeRegistry>;\n historyRawBeforeLock: string | null;\n currentItem: HistoryRedactCurrentItem;\n nextItem: HistoryRedactNextItem;\n author: string;\n force: boolean | undefined;\n rewrittenEntries: HistoryEntry[];\n}): Promise<string[]> {\n return executeHistoryRewrite({\n pmRoot: params.pmRoot,\n subject: params.subject,\n settings: params.settings,\n typeRegistry: params.typeRegistry,\n historyRawBeforeLock: params.historyRawBeforeLock,\n currentItemRawBeforeLock: params.currentItem.raw,\n operation: \"history-redact\",\n author: params.author,\n force: params.force,\n itemDocument: params.currentItem.document,\n applyRewrite: async ({ historyRawUnderLock }) => {\n const affectedItemPaths = new Set<string>();\n if (params.currentItem.path) {\n affectedItemPaths.add(params.currentItem.path);\n }\n if (params.nextItem.path) {\n affectedItemPaths.add(params.nextItem.path);\n }\n const itemSnapshots = new Map<string, string>();\n if (params.currentItem.path && params.currentItem.raw !== null) {\n itemSnapshots.set(params.currentItem.path, params.currentItem.raw);\n }\n try {\n /* c8 ignore next -- item-write diff branch requires path and content divergence under lock races. */\n if (params.nextItem.path && params.nextItem.raw !== null && params.nextItem.raw !== params.currentItem.raw) {\n await writeFileAtomic(params.nextItem.path, params.nextItem.raw);\n }\n if (params.currentItem.path && (!params.nextItem.path || params.nextItem.path !== params.currentItem.path)) {\n await fs.rm(params.currentItem.path, { force: true });\n }\n await writeFileAtomic(params.subject.historyPath, historyEntriesToRaw(params.rewrittenEntries));\n } catch (error) {\n await rollbackHistoryRedactRewrite(params.subject.historyPath, historyRawUnderLock, affectedItemPaths, itemSnapshots);\n throw error;\n }\n },\n applyPostRewrite: async () => runHistoryRedactWriteHooks(params.subject.historyPath, [\n params.nextItem.path,\n params.currentItem.path,\n ]),\n });\n}\n\nasync function rollbackHistoryRedactRewrite(\n historyPath: string,\n historyRawUnderLock: string | null,\n affectedItemPaths: Set<string>,\n itemSnapshots: Map<string, string>,\n): Promise<void> {\n /* c8 ignore start -- no-history-under-lock rollback path is exercised in lock-race integration tests. */\n if (historyRawUnderLock === null) {\n await fs.rm(historyPath, { force: true });\n } else {\n await writeFileAtomic(historyPath, historyRawUnderLock);\n }\n /* c8 ignore stop */\n for (const itemPath of affectedItemPaths) {\n const snapshot = itemSnapshots.get(itemPath);\n /* c8 ignore start -- missing snapshot rollback occurs only for create/delete race permutations. */\n if (snapshot === undefined) {\n await fs.rm(itemPath, { force: true });\n } else {\n await writeFileAtomic(itemPath, snapshot);\n }\n /* c8 ignore stop */\n }\n}\n\nasync function runHistoryRedactWriteHooks(historyPath: string, itemHookPaths: Array<string | null>): Promise<string[]> {\n const hookWarnings: string[] = [];\n const uniqueItemHookPaths = new Set(itemHookPaths.filter((itemPath): itemPath is string => itemPath !== null));\n for (const itemHookPath of uniqueItemHookPaths) {\n hookWarnings.push(\n ...(await runActiveOnWriteHooks({\n path: itemHookPath,\n scope: \"project\",\n op: \"history_redact\",\n })),\n );\n }\n hookWarnings.push(\n ...(await runActiveOnWriteHooks({\n path: historyPath,\n scope: \"project\",\n op: \"history_redact:history\",\n })),\n );\n return hookWarnings;\n}\n\n/**\n * Implements resolve history subject for the public runtime surface of this module.\n */\nexport async function resolveHistorySubject(\n pmRoot: string,\n id: string,\n settings: Awaited<ReturnType<typeof readSettings>>,\n typeToFolder: Record<string, string>,\n): Promise<HistorySubject> {\n const located = await locateItem(pmRoot, id, settings.id_prefix, settings.item_format, typeToFolder);\n if (located) {\n return {\n id: located.id,\n historyPath: getHistoryPath(pmRoot, located.id),\n located,\n };\n }\n\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const rawNormalizedId = normalizeRawItemId(id);\n const candidateIds = normalizedId === rawNormalizedId ? [normalizedId] : [normalizedId, rawNormalizedId];\n for (const candidateId of candidateIds) {\n const historyPath = getHistoryPath(pmRoot, candidateId);\n if (await pathExists(historyPath)) {\n return {\n id: candidateId,\n historyPath,\n located: null,\n };\n }\n }\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n}\n\n/**\n * Implements run history redact for the public runtime surface of this module.\n */\nexport async function runHistoryRedact(\n id: string,\n options: HistoryRedactCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRedactResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const replacement = typeof options.replacement === \"string\" && options.replacement.length > 0 ? options.replacement : \"[redacted]\";\n const rules = buildRedactionRules(options.literal, options.regex);\n const subject = await resolveHistorySubject(pmRoot, id, settings, typeRegistry.type_to_folder);\n\n if (!(await pathExists(subject.historyPath))) {\n throw new PmCliError(`No history stream exists for ${subject.id}.`, EXIT_CODE.NOT_FOUND);\n }\n const historyRawBeforeLock = await readFileIfExists(subject.historyPath);\n const historyEntries = await readHistoryEntries(subject.historyPath, subject.id);\n if (historyEntries.length === 0) {\n throw new PmCliError(`No history entries exist for ${subject.id}; nothing to redact.`, EXIT_CODE.USAGE);\n }\n\n const integritySnapshot = inspectHistoryIntegrity(historyEntries);\n const rewritten = rewriteHistoryEntries(historyEntries, rules, replacement);\n const preexistingHashMismatches = integritySnapshot.hashMismatchesBefore + integritySnapshot.hashMismatchesAfter;\n const dryRun = Boolean(options.dryRun);\n const changed = rewritten.replacements > 0;\n const warnings: string[] = [];\n if (preexistingHashMismatches > 0) {\n warnings.push(`history_redact_preexisting_hash_mismatches:${preexistingHashMismatches}`);\n }\n if (!changed) {\n warnings.push(\"history_redact_no_matches\");\n }\n\n const currentItem = await loadHistoryRedactCurrentItem(subject, settings);\n const nextItem = resolveHistoryRedactNextItem({\n pmRoot,\n subject,\n settings,\n typeToFolder: typeRegistry.type_to_folder,\n finalDocument: rewritten.finalDocument,\n });\n\n const itemChanged =\n /* c8 ignore next -- null-coalescing item-path comparison branch is exercised in broader command integration coverage. */\n (currentItem.path ?? null) !== (nextItem.path ?? null) ||\n /* c8 ignore next -- null-coalescing item-content comparison branch is exercised in broader command integration coverage. */\n (currentItem.raw ?? null) !== (nextItem.raw ?? null);\n\n const author = resolveAuthor(options.author, settings.author_default);\n const redactionMessage = buildHistoryRedactMessage(options, rewritten);\n const { rewrittenEntries, auditEntryAdded } = buildHistoryRedactEntries({\n rewritten,\n dryRun,\n changed,\n nextItemDocument: nextItem.document,\n author,\n message: redactionMessage,\n });\n const historyVerify = verifyHistoryChain(rewrittenEntries);\n /* c8 ignore start -- invalid rewritten chains are covered by history verification unit tests. */\n if (!historyVerify.ok) {\n throw new PmCliError(\n `history-redact produced an invalid rewritten chain (${historyVerify.errors.join(\", \")}).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n /* c8 ignore stop */\n\n if (!dryRun && changed) {\n warnings.push(\n ...(await applyHistoryRedactRewrite({\n pmRoot,\n subject,\n settings,\n typeRegistry,\n historyRawBeforeLock,\n currentItem,\n nextItem,\n author,\n force: options.force,\n rewrittenEntries,\n })),\n );\n }\n\n return {\n id: subject.id,\n dry_run: dryRun,\n changed,\n patterns: {\n literals: rules.filter((rule): rule is LiteralRule => rule.kind === \"literal\").map((rule) => rule.value),\n regex: rules.filter((rule): rule is RegexRule => rule.kind === \"regex\").map((rule) => `/${rule.source}/${rule.flags}`),\n replacement,\n },\n history: {\n path: subject.historyPath,\n entries_scanned: historyEntries.length,\n entries_changed: rewritten.entriesChanged,\n replacements: rewritten.replacements,\n hash_mismatches_before: integritySnapshot.hashMismatchesBefore,\n hash_mismatches_after: integritySnapshot.hashMismatchesAfter,\n preexisting_hash_mismatches: preexistingHashMismatches,\n audit_entry_added: auditEntryAdded,\n verify_ok: historyVerify.ok,\n verify_errors: historyVerify.errors,\n },\n item: {\n existed_before: currentItem.path !== null,\n exists_after: nextItem.path !== null,\n path_before: currentItem.path,\n path_after: nextItem.path,\n changed: itemChanged,\n },\n /* c8 ignore next -- warning dedupe ordering is covered indirectly by command-level smoke tests. */\n warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),\n generated_at: nowIso(),\n };\n}\n\nexport const _testOnly = {\n applyLiteralRule,\n applyRegexRule,\n buildRedactionRules,\n hasItemMetadata,\n normalizeRegexFlags,\n normalizeStringArrayInput,\n parseRegexRule,\n redactStringValue,\n redactUnknownValue,\n};\n","/**\n * @module core/history/history-rewrite\n *\n * Implements append-only history and replay behavior for History Rewrite.\n */\nimport fs from \"node:fs/promises\";\nimport { readFileIfExists, writeFileAtomic } from \"../fs/fs-utils.js\";\nimport type { ItemTypeRegistry } from \"../item/type-registry.js\";\nimport { acquireLock } from \"../lock/lock.js\";\nimport { EXIT_CODE } from \"../shared/constants.js\";\nimport { PmCliError } from \"../shared/errors.js\";\nimport { locateItem, readLocatedItem } from \"../store/item-store.js\";\nimport { resolveGovernanceKnobs } from \"../store/settings.js\";\nimport type { ItemDocument, PmSettings } from \"../../types/index.js\";\n\ntype LoadedItem = Awaited<ReturnType<typeof readLocatedItem>>;\ntype HistoryRawWriter = (filePath: string, content: string) => Promise<void>;\n\n/**\n * Documents the history rewrite subject payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRewriteSubject {\n id: string;\n historyPath: string;\n}\n\n/**\n * Documents the history rewrite ownership params payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryRewriteOwnershipParams {\n itemDocument: ItemDocument | null;\n subjectId: string;\n author: string;\n force: boolean | undefined;\n settings: PmSettings;\n}\n\n/**\n * Apply ownership_enforcement governance to a history-rewriting operation.\n * Returns the warning(s) the caller should append (empty when no conflict or strict-throws).\n * Throws PmCliError(CONFLICT) in strict mode when the assignee conflicts and --force is not set.\n */\nexport function checkHistoryRewriteOwnership(params: HistoryRewriteOwnershipParams): string[] {\n if (!params.itemDocument) return [];\n const assigned = params.itemDocument.metadata?.assignee?.trim();\n if (!assigned || assigned === params.author || params.force) return [];\n\n const governance = resolveGovernanceKnobs(params.settings);\n if (governance.ownership_enforcement === \"strict\") {\n throw new PmCliError(\n `Item ${params.subjectId} is assigned to ${assigned}. Use --force to override.`,\n EXIT_CODE.CONFLICT,\n );\n }\n if (governance.ownership_enforcement === \"warn\") {\n return [`ownership_warning:assignee_conflict:${params.subjectId}:${assigned}`];\n }\n return [];\n}\n\n/**\n * Documents the verify history rewrite drift params payload exchanged by command, SDK, and package integrations.\n */\nexport interface VerifyHistoryRewriteDriftParams {\n pmRoot: string;\n subject: HistoryRewriteSubject;\n settings: PmSettings;\n typeRegistry: ItemTypeRegistry;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n /** Short operation name used in the conflict message (e.g. \"history-redact\"). */\n operation: string;\n}\n\n/**\n * Documents the verified history rewrite state payload exchanged by command, SDK, and package integrations.\n */\nexport interface VerifiedHistoryRewriteState {\n historyRawUnderLock: string | null;\n locatedUnderLock: Awaited<ReturnType<typeof locateItem>>;\n loadedItemUnderLock: LoadedItem | null;\n}\n\n/**\n * Re-read the history stream and the located item document under the acquired lock and\n * compare both with the pre-lock raw snapshots. Throws PmCliError(CONFLICT) if either\n * diverged while waiting for the lock so the caller surfaces an actionable retry.\n */\nexport async function verifyHistoryRewriteNoDrift(\n params: VerifyHistoryRewriteDriftParams,\n): Promise<VerifiedHistoryRewriteState> {\n const historyRawUnderLock = await readFileIfExists(params.subject.historyPath);\n if (historyRawUnderLock !== params.historyRawBeforeLock) {\n throw new PmCliError(\n `History for ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`,\n EXIT_CODE.CONFLICT,\n );\n }\n const locatedUnderLock = await locateItem(\n params.pmRoot,\n params.subject.id,\n params.settings.id_prefix,\n params.settings.item_format,\n params.typeRegistry.type_to_folder,\n );\n const loadedItemUnderLock = locatedUnderLock\n ? await readLocatedItem(locatedUnderLock, { schema: params.settings.schema })\n : null;\n if ((loadedItemUnderLock?.raw ?? null) !== (params.currentItemRawBeforeLock ?? null)) {\n throw new PmCliError(\n `Item ${params.subject.id} changed while waiting for lock; retry ${params.operation}.`,\n EXIT_CODE.CONFLICT,\n );\n }\n return { historyRawUnderLock, locatedUnderLock, loadedItemUnderLock };\n}\n\n/**\n * Documents the execute history rewrite params payload exchanged by command, SDK, and package integrations.\n */\nexport interface ExecuteHistoryRewriteParams {\n pmRoot: string;\n subject: HistoryRewriteSubject;\n settings: PmSettings;\n typeRegistry: ItemTypeRegistry;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n /** Short operation name used in conflict guidance (e.g. \"history-redact\"). */\n operation: string;\n author: string;\n force: boolean | undefined;\n itemDocument: ItemDocument | null;\n applyRewrite: (verified: VerifiedHistoryRewriteState) => Promise<void>;\n applyPostRewrite?: (verified: VerifiedHistoryRewriteState) => Promise<string[]>;\n}\n\n/**\n * Writes the rewritten history stream and restores the under-lock snapshot on failure.\n */\nexport async function writeHistoryRawWithRollback(params: {\n historyPath: string;\n nextHistoryRaw: string;\n historyRawUnderLock: string | null;\n writeHistoryRaw?: HistoryRawWriter;\n}): Promise<void> {\n const writeHistoryRaw = params.writeHistoryRaw ?? writeFileAtomic;\n try {\n await writeHistoryRaw(params.historyPath, params.nextHistoryRaw);\n } catch (error) {\n try {\n if (params.historyRawUnderLock === null) {\n await fs.rm(params.historyPath, { force: true });\n } else {\n await writeHistoryRaw(params.historyPath, params.historyRawUnderLock);\n }\n } catch (rollbackError) {\n throw new AggregateError(\n [error, rollbackError],\n `History rewrite failed and rollback also failed: ${String(error)}`,\n );\n }\n throw error;\n }\n}\n\n/**\n * Shared lock/verify/ownership orchestration for history-rewrite commands.\n * Callers provide the operation-specific write/rollback logic and optional\n * post-write hook execution while this helper enforces the common governance +\n * lock sequencing contract.\n */\nexport async function executeHistoryRewrite(params: ExecuteHistoryRewriteParams): Promise<string[]> {\n const warnings = [...checkHistoryRewriteOwnership({\n itemDocument: params.itemDocument,\n subjectId: params.subject.id,\n author: params.author,\n force: params.force,\n settings: params.settings,\n })];\n const releaseLock = await acquireLock(\n params.pmRoot,\n params.subject.id,\n params.settings.locks.ttl_seconds,\n params.author,\n Boolean(params.force),\n params.settings.governance.force_required_for_stale_lock,\n params.settings.locks.wait_ms,\n );\n try {\n const verified = await verifyHistoryRewriteNoDrift({\n pmRoot: params.pmRoot,\n subject: params.subject,\n settings: params.settings,\n typeRegistry: params.typeRegistry,\n historyRawBeforeLock: params.historyRawBeforeLock,\n currentItemRawBeforeLock: params.currentItemRawBeforeLock,\n operation: params.operation,\n });\n await params.applyRewrite(verified);\n if (params.applyPostRewrite) {\n warnings.push(...(await params.applyPostRewrite(verified)));\n }\n return warnings;\n } finally {\n await releaseLock();\n }\n}\n"],"names":["fs","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAOA,SAAQ;;;ACAf,OAAO,QAAQ;AAqCT,SAAU,6BAA6B,QAAqC;AAChF,MAAI,CAAC,OAAO;AAAc,WAAO,CAAA;AACjC,QAAM,WAAW,OAAO,aAAa,UAAU,UAAU,KAAI;AAC7D,MAAI,CAAC,YAAY,aAAa,OAAO,UAAU,OAAO;AAAO,WAAO,CAAA;AAEpE,QAAM,aAAa,uBAAuB,OAAO,QAAQ;AACzD,MAAI,WAAW,0BAA0B,UAAU;AACjD,UAAM,IAAI,WACR,QAAQ,OAAO,SAAS,mBAAmB,QAAQ,8BACnD,UAAU,QAAQ;EAEtB;AACA,MAAI,WAAW,0BAA0B,QAAQ;AAC/C,WAAO,CAAC,uCAAuC,OAAO,SAAS,IAAI,QAAQ,EAAE;EAC/E;AACA,SAAO,CAAA;AAC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rH;;IAEF,SAAS;MACP,MAAM,QAAQ;MACd,iBAAiB,eAAe;MAChC,iBAAiB,UAAU;MAC3B,cAAc,UAAU;MACxB,wBAAwB,kBAAkB;MAC1C,uBAAuB,kBAAkB;MACzC,6BAA6B;MAC7B,mBAAmB;MACnB,WAAW,cAAc;MACzB,eAAe,cAAc;;IAE/B,MAAM;MACJ,gBAAgB,YAAY,SAAS;MACrC,cAAc,SAAS,SAAS;MAChC,aAAa,YAAY;MACzB,YAAY,SAAS;MACrB,SAAS;;;IAGX,UAAU,CAAC,GAAG,IAAI,IAAI,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,UAAU,KAAK,cAAc,KAAK,CAAC;IAChF,cAAc,OAAM;;AAExB;AAEO,IAAM,YAAY;EACvB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA","debugId":"dfca79bb-75b6-55a7-84b0-07b24f504e5b"}
@@ -1,31 +1,27 @@
1
1
 
2
- !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]="15bc3f9a-c760-5d79-a131-2fd2ff96728b")}catch(e){}}();
2
+ !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]="f014e953-a40b-5dbe-9ce5-75463eb41eb7")}catch(e){}}();
3
3
  import {
4
4
  cloneEmptyReplayDocument,
5
5
  normalizeReplayPatchOps,
6
6
  tryApplyReplayPatch,
7
7
  verifyHistoryChain
8
- } from "./chunk-OGWQ2IEP.js";
8
+ } from "./chunk-7Y5N34HX.js";
9
9
  import {
10
10
  parseLimit
11
- } from "./chunk-22KBU3MW.js";
11
+ } from "./chunk-AJUON7E6.js";
12
12
  import {
13
+ PmCliError,
13
14
  enforceHistoryStreamPolicyForItem,
15
+ findFirstMergeConflictMarker,
16
+ getActiveExtensionRegistrations,
14
17
  hashDocument,
15
18
  hashEmptyDocument,
16
19
  locateItem,
17
- readLocatedItem
18
- } from "./chunk-ENGQOEUY.js";
19
- import {
20
- findFirstMergeConflictMarker,
21
- normalizeItemId
22
- } from "./chunk-G24G7ZAV.js";
23
- import {
24
- PmCliError,
25
- getActiveExtensionRegistrations,
20
+ normalizeItemId,
21
+ readLocatedItem,
26
22
  readSettings,
27
23
  runActiveOnReadHooks
28
- } from "./chunk-E3SZTQ4K.js";
24
+ } from "./chunk-GH73UOSJ.js";
29
25
  import {
30
26
  EXIT_CODE,
31
27
  getHistoryPath,
@@ -34,7 +30,7 @@ import {
34
30
  readFileIfExists,
35
31
  resolveItemTypeRegistry,
36
32
  resolvePmRoot
37
- } from "./chunk-57NWPFF2.js";
33
+ } from "./chunk-UO7XAZK6.js";
38
34
 
39
35
  // dist/core/history/history-diff.js
40
36
  function decodeJsonPointerSegment(segment) {
@@ -262,6 +258,6 @@ export {
262
258
  readHistoryEntries,
263
259
  runHistory
264
260
  };
265
- //# sourceMappingURL=chunk-IX5BXEMX.js.map
261
+ //# sourceMappingURL=chunk-565WYS5W.js.map
266
262
 
267
- //# debugId=15bc3f9a-c760-5d79-a131-2fd2ff96728b
263
+ //# debugId=f014e953-a40b-5dbe-9ce5-75463eb41eb7
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../core/history/history-diff.ts","../../../../../../../../cli/commands/history.ts"],"sourcesContent":["/**\n * @module core/history/history-diff\n *\n * Implements append-only history and replay behavior for History Diff.\n */\nimport { cloneEmptyReplayDocument, tryApplyReplayPatch, type ReplayDocument } from \"./replay.js\";\nimport type { HistoryEntry } from \"../../types/index.js\";\n\n/**\n * Documents the history field change payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryFieldChange {\n field: string;\n // before and after are the raw field values captured by replaying the history chain.\n // `undefined` is intentional: it signals that the field was absent in the document at\n // that point (e.g. after a JSON-Patch `remove` op). JSON serialization will omit\n // undefined values, which correctly communicates \"field did not exist\".\n before: unknown;\n after: unknown;\n}\n\n/**\n * Documents the history diff value entry payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryDiffValueEntry {\n /** 1-based position in the FULL stream (fullEntries index + 1). */\n index: number;\n ts: string;\n op: string;\n author: string;\n /** Number of JSON-patch operations in this entry (entry.patch.length). */\n patch_ops: number;\n /** Unique field names touched by this entry, sorted by localeCompare. */\n changed_fields: string[];\n /** Per-field before/after values, sorted by field name (localeCompare). */\n changes: HistoryFieldChange[];\n}\n\n// ---------------------------------------------------------------------------\n// JSON-Pointer helpers (ported from src/cli/commands/history.ts so the\n// orchestrator can replace the private copy there with an import from here).\n// ---------------------------------------------------------------------------\n\nfunction decodeJsonPointerSegment(segment: string): string {\n return segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n}\n\n/**\n * Map a JSON-Patch path string to a human-readable changed-field name.\n *\n * Rules (in priority order):\n * - \"/body\" or \"/body/…\" → \"body\"\n * - \"/metadata/…\" or \"/front_matter/…\"\n * with a first segment → that decoded segment (e.g. \"status\")\n * without a first segment (bare prefix) → \"metadata\"\n * - \"/\" (root pointer, empty segment after strip) → \"root\"\n * - anything else → decoded first path segment\n */\nexport function patchPathToChangedField(path: string): string {\n if (path === \"/body\" || path.startsWith(\"/body/\")) return \"body\";\n if (\n path === \"/metadata\" ||\n path.startsWith(\"/metadata/\") ||\n path === \"/front_matter\" ||\n path.startsWith(\"/front_matter/\")\n ) {\n const segment = path.replace(/^\\/(?:metadata|front_matter)\\/?/, \"\").split(\"/\")[0];\n if (!segment) return \"metadata\";\n return decodeJsonPointerSegment(segment);\n }\n const segment = path.replace(/^\\//, \"\").split(\"/\")[0];\n return segment ? decodeJsonPointerSegment(segment) : \"root\";\n}\n\n// ---------------------------------------------------------------------------\n// Field-value reader\n// ---------------------------------------------------------------------------\n\n/**\n * Extract the before/after value for a logical field from a replay document.\n *\n * - \"body\" → doc.body\n * - \"metadata\" → doc.metadata (the whole object, for a bare /metadata replace)\n * - \"root\" → the whole document (for a bare \"/\" patch op)\n * - other → doc.metadata[field] (may be undefined when the field was absent)\n */\nfunction readFieldValue(doc: ReplayDocument, field: string): unknown {\n if (field === \"body\") return doc.body;\n if (field === \"metadata\") return doc.metadata;\n if (field === \"root\") return doc;\n return doc.metadata[field];\n}\n\n// ---------------------------------------------------------------------------\n// Main export\n// ---------------------------------------------------------------------------\n\n/**\n * Replay a full history entry stream and produce enriched diff entries with\n * per-field before/after values.\n *\n * @param fullEntries The complete ordered history chain to replay.\n * @param options.windowStartIndex 0-based index into fullEntries at which the\n * DISPLAYED window begins. Entries before this index are still replayed (so\n * state is accurate) but are not emitted. Defaults to 0.\n * @param options.field When supplied, only entries that changed this field are\n * emitted, and each emitted entry's `changes` and `changed_fields` are\n * restricted to that single field.\n */\nexport function computeHistoryDiff(\n fullEntries: HistoryEntry[],\n options?: { windowStartIndex?: number; field?: string },\n): HistoryDiffValueEntry[] {\n const windowStartIndex = options?.windowStartIndex ?? 0;\n const fieldFilter = options?.field;\n\n if (fullEntries.length === 0 || windowStartIndex >= fullEntries.length) {\n return [];\n }\n\n let current = cloneEmptyReplayDocument();\n const result: HistoryDiffValueEntry[] = [];\n\n for (let p = 0; p < fullEntries.length; p += 1) {\n const entry = fullEntries[p];\n\n // Capture before state.\n const beforeDoc = current;\n\n // Attempt to apply patch.\n const applied = tryApplyReplayPatch(current, entry.patch);\n let afterDoc: ReplayDocument;\n if (applied.ok) {\n afterDoc = applied.document;\n current = afterDoc;\n } else {\n // Patch failed — use before state as after (cannot trust partial result).\n // Do NOT advance current; keep prior replay state.\n afterDoc = beforeDoc;\n }\n\n // Collect changed field names from patch paths (and from: paths for move/copy).\n const changedFieldSet = new Set<string>();\n for (const patchOp of entry.patch) {\n changedFieldSet.add(patchPathToChangedField(patchOp.path));\n if (patchOp.from !== undefined) {\n changedFieldSet.add(patchPathToChangedField(patchOp.from));\n }\n }\n const sortedFields = [...changedFieldSet].sort((a, b) => a.localeCompare(b));\n\n // Only emit entries in the display window.\n if (p >= windowStartIndex) {\n // Apply field filter: skip this entry entirely if it doesn't touch the\n // requested field; otherwise narrow down to only that field.\n if (fieldFilter !== undefined) {\n if (!changedFieldSet.has(fieldFilter)) {\n // This entry does not touch the requested field — skip it.\n continue;\n }\n // Emit only the filtered field.\n const change: HistoryFieldChange = {\n field: fieldFilter,\n before: readFieldValue(beforeDoc, fieldFilter),\n after: readFieldValue(afterDoc, fieldFilter),\n };\n result.push({\n index: p + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: entry.patch.length,\n changed_fields: [fieldFilter],\n changes: [change],\n });\n } else {\n // Emit all changed fields.\n const changes: HistoryFieldChange[] = sortedFields.map((field) => ({\n field,\n before: readFieldValue(beforeDoc, field),\n after: readFieldValue(afterDoc, field),\n }));\n result.push({\n index: p + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: entry.patch.length,\n changed_fields: sortedFields,\n changes,\n });\n }\n }\n }\n\n return result;\n}\n","/**\n * @module cli/commands/history\n *\n * Implements the pm history command surface and its agent-facing runtime behavior.\n */\nimport { pathExists, readFileIfExists } from \"../../core/fs/fs-utils.js\";\nimport { computeHistoryDiff, patchPathToChangedField, type HistoryDiffValueEntry } from \"../../core/history/history-diff.js\";\nimport { hashDocument, hashEmptyDocument } from \"../../core/history/history.js\";\nimport { normalizeReplayPatchOps, verifyHistoryChain } from \"../../core/history/replay.js\";\nimport { enforceHistoryStreamPolicyForItem } from \"../../core/history/history-stream-policy.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport { findFirstMergeConflictMarker } from \"../../core/shared/conflict-markers.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { getActiveExtensionRegistrations, runActiveOnReadHooks } from \"../../core/extensions/index.js\";\nimport { normalizeItemId } from \"../../core/item/id.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { parseLimit } from \"../shared-parsers.js\";\nimport type { HistoryEntry } from \"../../types/index.js\";\n\nexport { verifyHistoryChain } from \"../../core/history/replay.js\";\n\n/**\n * Documents the history command options payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryCommandOptions {\n limit?: string;\n diff?: boolean;\n /** Restrict --diff to a single field's before/after transitions (implies --diff). */\n field?: string;\n verify?: boolean;\n compact?: boolean;\n}\n\n/**\n * Documents the history diff entry payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryDiffEntry {\n index: number;\n ts: string;\n op: string;\n author: string;\n patch_ops: number;\n changed_fields: string[];\n}\n\n/**\n * Documents the history verification result payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryVerificationResult {\n ok: boolean;\n entries: number;\n errors: string[];\n latest_after_hash?: string;\n current_item_hash?: string;\n current_matches_latest?: boolean;\n}\n\n/**\n * Documents the history result payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryResult {\n id: string;\n history: HistoryEntry[];\n compact_history?: HistoryDiffEntry[];\n compact: boolean;\n count: number;\n limit: number | null;\n diff?: HistoryDiffValueEntry[];\n verification?: HistoryVerificationResult;\n}\n\nfunction limitEntries<T>(values: T[], limit: number | undefined): T[] {\n if (limit === undefined) return values;\n return values.slice(Math.max(0, values.length - limit));\n}\n\nfunction buildDiffEntries(entries: HistoryEntry[], startIndex: number): HistoryDiffEntry[] {\n return entries.map((entry, index) => {\n const changedFields = new Set<string>();\n const patch = normalizeReplayPatchOps(entry.patch);\n for (const op of patch) {\n changedFields.add(patchPathToChangedField(op.path));\n if (op.from) {\n changedFields.add(patchPathToChangedField(op.from));\n }\n }\n return {\n index: startIndex + index + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: patch.length,\n changed_fields: [...changedFields].sort((left, right) => left.localeCompare(right)),\n };\n });\n}\n\n/**\n * Implements read history entries for the public runtime surface of this module.\n */\nexport async function readHistoryEntries(historyPath: string, itemId: string): Promise<HistoryEntry[]> {\n const raw = await readFileIfExists(historyPath);\n if (raw === null) {\n return [];\n }\n await runActiveOnReadHooks({\n path: historyPath,\n scope: \"project\",\n });\n if (raw.trim() === \"\") {\n return [];\n }\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `History for ${itemId} contains merge conflict markers at line ${conflictMarker.line} (${conflictMarker.marker}). Resolve <<<<<<< ======= >>>>>>> markers and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n {\n code: \"history_merge_conflict_markers_detected\",\n required: \"Repair the history stream by resolving merge-conflict markers.\",\n why: \"Conflict markers break JSONL parsing and invalidate deterministic audit history.\",\n examples: [`pm history ${itemId}`, `pm restore ${itemId} <timestamp-or-version>`],\n nextSteps: [\"Resolve or restore the history file, then rerun the command.\"],\n },\n );\n }\n\n const entries: HistoryEntry[] = [];\n const lines = raw.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index]?.trim();\n if (!line) continue;\n try {\n entries.push(JSON.parse(line) as HistoryEntry);\n } catch {\n throw new PmCliError(\n `History for ${itemId} contains invalid JSON at line ${index + 1}. Repair or restore the history stream and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n }\n return entries;\n}\n\n/**\n * Implements run history for the public runtime surface of this module.\n */\nexport async function runHistory(id: string, options: HistoryCommandOptions, global: GlobalOptions): Promise<HistoryResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const limit = parseLimit(options.limit);\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const located = await locateItem(\n pmRoot,\n normalizedId,\n settings.id_prefix,\n settings.item_format,\n typeRegistry.type_to_folder,\n );\n const resolvedId = located?.id ?? normalizedId;\n const historyPath = getHistoryPath(pmRoot, resolvedId);\n if (!located && !(await pathExists(historyPath))) {\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n }\n /* c8 ignore next -- resolved ids in command tests always map to located items. */\n if (located) {\n await enforceHistoryStreamPolicyForItem({\n pmRoot,\n settings,\n itemId: located.id,\n commandLabel: \"history\",\n });\n }\n\n const fullHistory = await readHistoryEntries(historyPath, resolvedId);\n const history = limitEntries(fullHistory, limit);\n const compact = options.compact === true;\n const compactHistory = compact ? buildDiffEntries(history, Math.max(0, fullHistory.length - history.length)) : undefined;\n const result: HistoryResult = {\n id: resolvedId,\n history: compact ? [] : history,\n compact_history: compactHistory,\n compact,\n count: history.length,\n limit: limit ?? null,\n };\n\n if (options.diff || options.field !== undefined) {\n // --diff replays the full chain to surface per-field before/after values for\n // the displayed window (the latest --limit entries). --field narrows to a\n // single field's transitions (\"when did status change?\"). Unlike the compact\n // projection above, the value diff is independent of the compact/full toggle.\n result.diff = computeHistoryDiff(fullHistory, {\n windowStartIndex: Math.max(0, fullHistory.length - history.length),\n field: options.field,\n });\n }\n\n if (options.verify) {\n const verification = verifyHistoryChain(fullHistory);\n /* c8 ignore next -- verify path operates on non-empty streams in command-level coverage. */\n const latestAfterHash = fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : hashEmptyDocument();\n let currentItemHash: string | undefined;\n let currentMatchesLatest: boolean | undefined;\n const errors = [...verification.errors];\n\n /* c8 ignore next -- verify command paths currently execute with located on-disk items. */\n if (located) {\n const loaded = await readLocatedItem(located, { schema: settings.schema });\n currentItemHash = hashDocument(loaded.document);\n currentMatchesLatest = currentItemHash === latestAfterHash;\n if (!currentMatchesLatest) {\n errors.push(\"verify_failed:current_item_hash_mismatch\");\n }\n }\n\n result.verification = {\n ok: errors.length === 0,\n entries: fullHistory.length,\n errors,\n /* c8 ignore next -- empty-history verification payloads are covered by lower-level stream tests. */\n latest_after_hash: fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : undefined,\n current_item_hash: currentItemHash,\n current_matches_latest: currentMatchesLatest,\n };\n }\n\n return result;\n}\n"],"names":["segment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAS,yBAAyB,SAAe;AAC/C,SAAO,QAAQ,WAAW,MAAM,GAAG,EAAE,WAAW,MAAM,GAAG;AAC3D;AAaM,SAAU,wBAAwB,MAAY;AAClD,MAAI,SAAS,WAAW,KAAK,WAAW,QAAQ;AAAG,WAAO;AAC1D,MACE,SAAS,eACT,KAAK,WAAW,YAAY,KAC5B,SAAS,mBACT,KAAK,WAAW,gBAAgB,GAChC;AACA,UAAMA,WAAU,KAAK,QAAQ,mCAAmC,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AAChF,QAAI,CAACA;AAAS,aAAO;AACrB,WAAO,yBAAyBA,QAAO;EACzC;AACA,QAAM,UAAU,KAAK,QAAQ,OAAO,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACpD,SAAO,UAAU,yBAAyB,OAAO,IAAI;AACvD;AAcA,SAAS,eAAe,KAAqB,OAAa;AACxD,MAAI,UAAU;AAAQ,WAAO,IAAI;AACjC,MAAI,UAAU;AAAY,WAAO,IAAI;AACrC,MAAI,UAAU;AAAQ,WAAO;AAC7B,SAAO,IAAI,SAAS,KAAK;AAC3B;AAkBM,SAAU,mBACd,aACA,SAAuD;AAEvD,QAAM,mBAAmB,SAAS,oBAAoB;AACtD,QAAM,cAAc,SAAS;AAE7B,MAAI,YAAY,WAAW,KAAK,oBAAoB,YAAY,QAAQ;AACtE,WAAO,CAAA;EACT;AAEA,MAAI,UAAU,yBAAwB;AACtC,QAAM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M,SAAwB;IAC5B,IAAI;IACJ,SAAS,UAAU,CAAA,IAAK;IACxB,iBAAiB;IACjB;IACA,OAAO,QAAQ;IACf,OAAO,SAAS;;AAGlB,MAAI,QAAQ,QAAQ,QAAQ,UAAU,QAAW;AAK/C,WAAO,OAAO,mBAAmB,aAAa;MAC5C,kBAAkB,KAAK,IAAI,GAAG,YAAY,SAAS,QAAQ,MAAM;MACjE,OAAO,QAAQ;KAChB;EACH;AAEA,MAAI,QAAQ,QAAQ;AAClB,UAAM,eAAe,mBAAmB,WAAW;AAEnD,UAAM,kBAAkB,YAAY,SAAS,IAAI,YAAY,YAAY,SAAS,CAAC,EAAE,aAAa,kBAAiB;AACnH,QAAI;AACJ,QAAI;AACJ,UAAM,SAAS,CAAC,GAAG,aAAa,MAAM;AAGtC,QAAI,SAAS;AACX,YAAM,SAAS,MAAM,gBAAgB,SAAS,EAAE,QAAQ,SAAS,OAAM,CAAE;AACzE,wBAAkB,aAAa,OAAO,QAAQ;AAC9C,6BAAuB,oBAAoB;AAC3C,UAAI,CAAC,sBAAsB;AACzB,eAAO,KAAK,0CAA0C;MACxD;IACF;AAEA,WAAO,eAAe;MACpB,IAAI,OAAO,WAAW;MACtB,SAAS,YAAY;MACrB;;MAEA,mBAAmB,YAAY,SAAS,IAAI,YAAY,YAAY,SAAS,CAAC,EAAE,aAAa;MAC7F,mBAAmB;MACnB,wBAAwB;;EAE5B;AAEA,SAAO;AACT","debugId":"15bc3f9a-c760-5d79-a131-2fd2ff96728b"}
1
+ {"version":3,"sources":["../../../../../../../../core/history/history-diff.ts","../../../../../../../../cli/commands/history.ts"],"sourcesContent":["/**\n * @module core/history/history-diff\n *\n * Implements append-only history and replay behavior for History Diff.\n */\nimport { cloneEmptyReplayDocument, tryApplyReplayPatch, type ReplayDocument } from \"./replay.js\";\nimport type { HistoryEntry } from \"../../types/index.js\";\n\n/**\n * Documents the history field change payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryFieldChange {\n field: string;\n // before and after are the raw field values captured by replaying the history chain.\n // `undefined` is intentional: it signals that the field was absent in the document at\n // that point (e.g. after a JSON-Patch `remove` op). JSON serialization will omit\n // undefined values, which correctly communicates \"field did not exist\".\n before: unknown;\n after: unknown;\n}\n\n/**\n * Documents the history diff value entry payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryDiffValueEntry {\n /** 1-based position in the FULL stream (fullEntries index + 1). */\n index: number;\n ts: string;\n op: string;\n author: string;\n /** Number of JSON-patch operations in this entry (entry.patch.length). */\n patch_ops: number;\n /** Unique field names touched by this entry, sorted by localeCompare. */\n changed_fields: string[];\n /** Per-field before/after values, sorted by field name (localeCompare). */\n changes: HistoryFieldChange[];\n}\n\n// ---------------------------------------------------------------------------\n// JSON-Pointer helpers (ported from src/cli/commands/history.ts so the\n// orchestrator can replace the private copy there with an import from here).\n// ---------------------------------------------------------------------------\n\nfunction decodeJsonPointerSegment(segment: string): string {\n return segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\");\n}\n\n/**\n * Map a JSON-Patch path string to a human-readable changed-field name.\n *\n * Rules (in priority order):\n * - \"/body\" or \"/body/…\" → \"body\"\n * - \"/metadata/…\" or \"/front_matter/…\"\n * with a first segment → that decoded segment (e.g. \"status\")\n * without a first segment (bare prefix) → \"metadata\"\n * - \"/\" (root pointer, empty segment after strip) → \"root\"\n * - anything else → decoded first path segment\n */\nexport function patchPathToChangedField(path: string): string {\n if (path === \"/body\" || path.startsWith(\"/body/\")) return \"body\";\n if (\n path === \"/metadata\" ||\n path.startsWith(\"/metadata/\") ||\n path === \"/front_matter\" ||\n path.startsWith(\"/front_matter/\")\n ) {\n const segment = path.replace(/^\\/(?:metadata|front_matter)\\/?/, \"\").split(\"/\")[0];\n if (!segment) return \"metadata\";\n return decodeJsonPointerSegment(segment);\n }\n const segment = path.replace(/^\\//, \"\").split(\"/\")[0];\n return segment ? decodeJsonPointerSegment(segment) : \"root\";\n}\n\n// ---------------------------------------------------------------------------\n// Field-value reader\n// ---------------------------------------------------------------------------\n\n/**\n * Extract the before/after value for a logical field from a replay document.\n *\n * - \"body\" → doc.body\n * - \"metadata\" → doc.metadata (the whole object, for a bare /metadata replace)\n * - \"root\" → the whole document (for a bare \"/\" patch op)\n * - other → doc.metadata[field] (may be undefined when the field was absent)\n */\nfunction readFieldValue(doc: ReplayDocument, field: string): unknown {\n if (field === \"body\") return doc.body;\n if (field === \"metadata\") return doc.metadata;\n if (field === \"root\") return doc;\n return doc.metadata[field];\n}\n\n// ---------------------------------------------------------------------------\n// Main export\n// ---------------------------------------------------------------------------\n\n/**\n * Replay a full history entry stream and produce enriched diff entries with\n * per-field before/after values.\n *\n * @param fullEntries The complete ordered history chain to replay.\n * @param options.windowStartIndex 0-based index into fullEntries at which the\n * DISPLAYED window begins. Entries before this index are still replayed (so\n * state is accurate) but are not emitted. Defaults to 0.\n * @param options.field When supplied, only entries that changed this field are\n * emitted, and each emitted entry's `changes` and `changed_fields` are\n * restricted to that single field.\n */\nexport function computeHistoryDiff(\n fullEntries: HistoryEntry[],\n options?: { windowStartIndex?: number; field?: string },\n): HistoryDiffValueEntry[] {\n const windowStartIndex = options?.windowStartIndex ?? 0;\n const fieldFilter = options?.field;\n\n if (fullEntries.length === 0 || windowStartIndex >= fullEntries.length) {\n return [];\n }\n\n let current = cloneEmptyReplayDocument();\n const result: HistoryDiffValueEntry[] = [];\n\n for (let p = 0; p < fullEntries.length; p += 1) {\n const entry = fullEntries[p];\n\n // Capture before state.\n const beforeDoc = current;\n\n // Attempt to apply patch.\n const applied = tryApplyReplayPatch(current, entry.patch);\n let afterDoc: ReplayDocument;\n if (applied.ok) {\n afterDoc = applied.document;\n current = afterDoc;\n } else {\n // Patch failed — use before state as after (cannot trust partial result).\n // Do NOT advance current; keep prior replay state.\n afterDoc = beforeDoc;\n }\n\n // Collect changed field names from patch paths (and from: paths for move/copy).\n const changedFieldSet = new Set<string>();\n for (const patchOp of entry.patch) {\n changedFieldSet.add(patchPathToChangedField(patchOp.path));\n if (patchOp.from !== undefined) {\n changedFieldSet.add(patchPathToChangedField(patchOp.from));\n }\n }\n const sortedFields = [...changedFieldSet].sort((a, b) => a.localeCompare(b));\n\n // Only emit entries in the display window.\n if (p >= windowStartIndex) {\n // Apply field filter: skip this entry entirely if it doesn't touch the\n // requested field; otherwise narrow down to only that field.\n if (fieldFilter !== undefined) {\n if (!changedFieldSet.has(fieldFilter)) {\n // This entry does not touch the requested field — skip it.\n continue;\n }\n // Emit only the filtered field.\n const change: HistoryFieldChange = {\n field: fieldFilter,\n before: readFieldValue(beforeDoc, fieldFilter),\n after: readFieldValue(afterDoc, fieldFilter),\n };\n result.push({\n index: p + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: entry.patch.length,\n changed_fields: [fieldFilter],\n changes: [change],\n });\n } else {\n // Emit all changed fields.\n const changes: HistoryFieldChange[] = sortedFields.map((field) => ({\n field,\n before: readFieldValue(beforeDoc, field),\n after: readFieldValue(afterDoc, field),\n }));\n result.push({\n index: p + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: entry.patch.length,\n changed_fields: sortedFields,\n changes,\n });\n }\n }\n }\n\n return result;\n}\n","/**\n * @module cli/commands/history\n *\n * Implements the pm history command surface and its agent-facing runtime behavior.\n */\nimport { pathExists, readFileIfExists } from \"../../core/fs/fs-utils.js\";\nimport { computeHistoryDiff, patchPathToChangedField, type HistoryDiffValueEntry } from \"../../core/history/history-diff.js\";\nimport { hashDocument, hashEmptyDocument } from \"../../core/history/history.js\";\nimport { normalizeReplayPatchOps, verifyHistoryChain } from \"../../core/history/replay.js\";\nimport { enforceHistoryStreamPolicyForItem } from \"../../core/history/history-stream-policy.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport { findFirstMergeConflictMarker } from \"../../core/shared/conflict-markers.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { getActiveExtensionRegistrations, runActiveOnReadHooks } from \"../../core/extensions/index.js\";\nimport { normalizeItemId } from \"../../core/item/id.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { parseLimit } from \"../shared-parsers.js\";\nimport type { HistoryEntry } from \"../../types/index.js\";\n\nexport { verifyHistoryChain } from \"../../core/history/replay.js\";\n\n/**\n * Documents the history command options payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryCommandOptions {\n limit?: string;\n diff?: boolean;\n /** Restrict --diff to a single field's before/after transitions (implies --diff). */\n field?: string;\n verify?: boolean;\n compact?: boolean;\n}\n\n/**\n * Documents the history diff entry payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryDiffEntry {\n index: number;\n ts: string;\n op: string;\n author: string;\n patch_ops: number;\n changed_fields: string[];\n}\n\n/**\n * Documents the history verification result payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryVerificationResult {\n ok: boolean;\n entries: number;\n errors: string[];\n latest_after_hash?: string;\n current_item_hash?: string;\n current_matches_latest?: boolean;\n}\n\n/**\n * Documents the history result payload exchanged by command, SDK, and package integrations.\n */\nexport interface HistoryResult {\n id: string;\n history: HistoryEntry[];\n compact_history?: HistoryDiffEntry[];\n compact: boolean;\n count: number;\n limit: number | null;\n diff?: HistoryDiffValueEntry[];\n verification?: HistoryVerificationResult;\n}\n\nfunction limitEntries<T>(values: T[], limit: number | undefined): T[] {\n if (limit === undefined) return values;\n return values.slice(Math.max(0, values.length - limit));\n}\n\nfunction buildDiffEntries(entries: HistoryEntry[], startIndex: number): HistoryDiffEntry[] {\n return entries.map((entry, index) => {\n const changedFields = new Set<string>();\n const patch = normalizeReplayPatchOps(entry.patch);\n for (const op of patch) {\n changedFields.add(patchPathToChangedField(op.path));\n if (op.from) {\n changedFields.add(patchPathToChangedField(op.from));\n }\n }\n return {\n index: startIndex + index + 1,\n ts: entry.ts,\n op: entry.op,\n author: entry.author,\n patch_ops: patch.length,\n changed_fields: [...changedFields].sort((left, right) => left.localeCompare(right)),\n };\n });\n}\n\n/**\n * Implements read history entries for the public runtime surface of this module.\n */\nexport async function readHistoryEntries(historyPath: string, itemId: string): Promise<HistoryEntry[]> {\n const raw = await readFileIfExists(historyPath);\n if (raw === null) {\n return [];\n }\n await runActiveOnReadHooks({\n path: historyPath,\n scope: \"project\",\n });\n if (raw.trim() === \"\") {\n return [];\n }\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `History for ${itemId} contains merge conflict markers at line ${conflictMarker.line} (${conflictMarker.marker}). Resolve <<<<<<< ======= >>>>>>> markers and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n {\n code: \"history_merge_conflict_markers_detected\",\n required: \"Repair the history stream by resolving merge-conflict markers.\",\n why: \"Conflict markers break JSONL parsing and invalidate deterministic audit history.\",\n examples: [`pm history ${itemId}`, `pm restore ${itemId} <timestamp-or-version>`],\n nextSteps: [\"Resolve or restore the history file, then rerun the command.\"],\n },\n );\n }\n\n const entries: HistoryEntry[] = [];\n const lines = raw.split(/\\r?\\n/);\n for (let index = 0; index < lines.length; index += 1) {\n const line = lines[index]?.trim();\n if (!line) continue;\n try {\n entries.push(JSON.parse(line) as HistoryEntry);\n } catch {\n throw new PmCliError(\n `History for ${itemId} contains invalid JSON at line ${index + 1}. Repair or restore the history stream and retry.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n }\n return entries;\n}\n\n/**\n * Implements run history for the public runtime surface of this module.\n */\nexport async function runHistory(id: string, options: HistoryCommandOptions, global: GlobalOptions): Promise<HistoryResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const limit = parseLimit(options.limit);\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const located = await locateItem(\n pmRoot,\n normalizedId,\n settings.id_prefix,\n settings.item_format,\n typeRegistry.type_to_folder,\n );\n const resolvedId = located?.id ?? normalizedId;\n const historyPath = getHistoryPath(pmRoot, resolvedId);\n if (!located && !(await pathExists(historyPath))) {\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n }\n /* c8 ignore next -- resolved ids in command tests always map to located items. */\n if (located) {\n await enforceHistoryStreamPolicyForItem({\n pmRoot,\n settings,\n itemId: located.id,\n commandLabel: \"history\",\n });\n }\n\n const fullHistory = await readHistoryEntries(historyPath, resolvedId);\n const history = limitEntries(fullHistory, limit);\n const compact = options.compact === true;\n const compactHistory = compact ? buildDiffEntries(history, Math.max(0, fullHistory.length - history.length)) : undefined;\n const result: HistoryResult = {\n id: resolvedId,\n history: compact ? [] : history,\n compact_history: compactHistory,\n compact,\n count: history.length,\n limit: limit ?? null,\n };\n\n if (options.diff || options.field !== undefined) {\n // --diff replays the full chain to surface per-field before/after values for\n // the displayed window (the latest --limit entries). --field narrows to a\n // single field's transitions (\"when did status change?\"). Unlike the compact\n // projection above, the value diff is independent of the compact/full toggle.\n result.diff = computeHistoryDiff(fullHistory, {\n windowStartIndex: Math.max(0, fullHistory.length - history.length),\n field: options.field,\n });\n }\n\n if (options.verify) {\n const verification = verifyHistoryChain(fullHistory);\n /* c8 ignore next -- verify path operates on non-empty streams in command-level coverage. */\n const latestAfterHash = fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : hashEmptyDocument();\n let currentItemHash: string | undefined;\n let currentMatchesLatest: boolean | undefined;\n const errors = [...verification.errors];\n\n /* c8 ignore next -- verify command paths currently execute with located on-disk items. */\n if (located) {\n const loaded = await readLocatedItem(located, { schema: settings.schema });\n currentItemHash = hashDocument(loaded.document);\n currentMatchesLatest = currentItemHash === latestAfterHash;\n if (!currentMatchesLatest) {\n errors.push(\"verify_failed:current_item_hash_mismatch\");\n }\n }\n\n result.verification = {\n ok: errors.length === 0,\n entries: fullHistory.length,\n errors,\n /* c8 ignore next -- empty-history verification payloads are covered by lower-level stream tests. */\n latest_after_hash: fullHistory.length > 0 ? fullHistory[fullHistory.length - 1].after_hash : undefined,\n current_item_hash: currentItemHash,\n current_matches_latest: currentMatchesLatest,\n };\n }\n\n return result;\n}\n"],"names":["segment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAS,yBAAyB,SAAe;AAC/C,SAAO,QAAQ,WAAW,MAAM,GAAG,EAAE,WAAW,MAAM,GAAG;AAC3D;AAaM,SAAU,wBAAwB,MAAY;AAClD,MAAI,SAAS,WAAW,KAAK,WAAW,QAAQ;AAAG,WAAO;AAC1D,MACE,SAAS,eACT,KAAK,WAAW,YAAY,KAC5B,SAAS,mBACT,KAAK,WAAW,gBAAgB,GAChC;AACA,UAAMA,WAAU,KAAK,QAAQ,mCAAmC,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AAChF,QAAI,CAACA;AAAS,aAAO;AACrB,WAAO,yBAAyBA,QAAO;EACzC;AACA,QAAM,UAAU,KAAK,QAAQ,OAAO,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AACpD,SAAO,UAAU,yBAAyB,OAAO,IAAI;AACvD;AAcA,SAAS,eAAe,KAAqB,OAAa;AACxD,MAAI,UAAU;AAAQ,WAAO,IAAI;AACjC,MAAI,UAAU;AAAY,WAAO,IAAI;AACrC,MAAI,UAAU;AAAQ,WAAO;AAC7B,SAAO,IAAI,SAAS,KAAK;AAC3B;AAkBM,SAAU,mBACd,aACA,SAAuD;AAEvD,QAAM,mBAAmB,SAAS,oBAAoB;AACtD,QAAM,cAAc,SAAS;AAE7B,MAAI,YAAY,WAAW,KAAK,oBAAoB,YAAY,QAAQ;AACtE,WAAO,CAAA;EAC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AS,QAAQ,MAAM,CAAC,IAAI;AAC/G,QAAM,SAAwB;IAC5B,IAAI;IACJ,SAAS,UAAU,CAAA,IAAK;IACxB,iBAAiB;IACjB;IACA,OAAO,QAAQ;IACf,OAAO,SAAS;;AAGlB,MAAI,QAAQ,QAAQ,QAAQ,UAAU,QAAW;AAK/C,WAAO,OAAO,mBAAmB,aAAa;MAC5C,kBAAkB,KAAK,IAAI,GAAG,YAAY,SAAS,QAAQ,MAAM;MACjE,OAAO,QAAQ;KAChB;EACH;AAEA,MAAI,QAAQ,QAAQ;AAClB,UAAM,eAAe,mBAAmB,WAAW;AAEnD,UAAM,kBAAkB,YAAY,SAAS,IAAI,YAAY,YAAY,SAAS,CAAC,EAAE,aAAa,kBAAiB;AACnH,QAAI;AACJ,QAAI;AACJ,UAAM,SAAS,CAAC,GAAG,aAAa,MAAM;AAGtC,QAAI,SAAS;AACX,YAAM,SAAS,MAAM,gBAAgB,SAAS,EAAE,QAAQ,SAAS,OAAM,CAAE;AACzE,wBAAkB,aAAa,OAAO,QAAQ;AAC9C,6BAAuB,oBAAoB;AAC3C,UAAI,CAAC,sBAAsB;AACzB,eAAO,KAAK,0CAA0C;MACxD;IACF;AAEA,WAAO,eAAe;MACpB,IAAI,OAAO,WAAW;MACtB,SAAS,YAAY;MACrB;;MAEA,mBAAmB,YAAY,SAAS,IAAI,YAAY,YAAY,SAAS,CAAC,EAAE,aAAa;MAC7F,mBAAmB;MACnB,wBAAwB;;EAE5B;AAEA,SAAO;AACT","debugId":"f014e953-a40b-5dbe-9ce5-75463eb41eb7"}
@@ -1,30 +1,24 @@
1
1
 
2
- !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]="d3a80b6a-fc91-5d8c-b2d8-b25844e554b1")}catch(e){}}();
2
+ !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]="f43959c9-8f61-58f1-94d9-103aa022b9cf")}catch(e){}}();
3
3
  import {
4
+ PmCliError,
4
5
  acquireLock,
5
6
  appendHistoryEntry,
6
7
  buildItemNotFoundError,
8
+ canonicalDocument,
7
9
  collectRegisteredItemFieldNames,
8
10
  createHistoryEntry,
9
- locateItem,
10
- readLocatedItem
11
- } from "./chunk-ENGQOEUY.js";
12
- import {
13
- canonicalDocument,
14
11
  generateItemId,
15
- serializeItemDocument
16
- } from "./chunk-G24G7ZAV.js";
17
- import {
18
- nowIso
19
- } from "./chunk-3GCS5SKL.js";
20
- import {
21
- PmCliError,
22
12
  getActiveExtensionRegistrations,
13
+ locateItem,
14
+ nowIso,
23
15
  projectAfterCommandItemSnapshot,
16
+ readLocatedItem,
24
17
  readSettings,
25
18
  recordAfterCommandAffectedItem,
26
- runActiveOnWriteHooks
27
- } from "./chunk-E3SZTQ4K.js";
19
+ runActiveOnWriteHooks,
20
+ serializeItemDocument
21
+ } from "./chunk-GH73UOSJ.js";
28
22
  import {
29
23
  EXIT_CODE,
30
24
  FRONT_MATTER_KEY_ORDER,
@@ -37,7 +31,7 @@ import {
37
31
  resolvePmRoot,
38
32
  resolveRuntimeStatusRegistry,
39
33
  writeFileAtomic
40
- } from "./chunk-57NWPFF2.js";
34
+ } from "./chunk-UO7XAZK6.js";
41
35
 
42
36
  // dist/cli/commands/copy.js
43
37
  function selectAuthor(explicitAuthor, settingsAuthor) {
@@ -176,6 +170,6 @@ async function runCopy(sourceId, options, global) {
176
170
  export {
177
171
  runCopy
178
172
  };
179
- //# sourceMappingURL=chunk-UH7T2DAX.js.map
173
+ //# sourceMappingURL=chunk-5FIQ4EX3.js.map
180
174
 
181
- //# debugId=d3a80b6a-fc91-5d8c-b2d8-b25844e554b1
175
+ //# debugId=f43959c9-8f61-58f1-94d9-103aa022b9cf
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../cli/commands/copy.ts"],"sourcesContent":["/**\n * @module cli/commands/copy\n *\n * Implements the pm copy command surface and its agent-facing runtime behavior.\n */\nimport { pathExists, removeFileIfExists, writeFileAtomic } from \"../../core/fs/fs-utils.js\";\nimport { appendHistoryEntry, createHistoryEntry } from \"../../core/history/history.js\";\nimport { generateItemId } from \"../../core/item/id.js\";\nimport { canonicalDocument, serializeItemDocument } from \"../../core/item/item-format.js\";\nimport { acquireLock } from \"../../core/lock/lock.js\";\nimport {\n getActiveExtensionRegistrations,\n projectAfterCommandItemSnapshot,\n recordAfterCommandAffectedItem,\n runActiveOnWriteHooks,\n} from \"../../core/extensions/index.js\";\nimport { collectRegisteredItemFieldNames } from \"../../core/extensions/item-fields.js\";\nimport { resolveRuntimeStatusRegistry } from \"../../core/schema/runtime-schema.js\";\nimport { EXIT_CODE, FRONT_MATTER_KEY_ORDER } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { nowIso } from \"../../core/shared/time.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { buildItemNotFoundError, locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getItemPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport type { ItemDocument, ItemMetadata } from \"../../types/index.js\";\n\n/**\n * Documents the copy options payload exchanged by command, SDK, and package integrations.\n */\nexport interface CopyOptions {\n title?: string;\n author?: string;\n message?: string;\n}\n\n/**\n * Documents the copy result payload exchanged by command, SDK, and package integrations.\n */\nexport interface CopyResult {\n source_id: string;\n item: ItemMetadata;\n changed_fields: string[];\n warnings: string[];\n}\n\nfunction selectAuthor(explicitAuthor: string | undefined, settingsAuthor: string): string {\n const candidate = explicitAuthor ?? process.env.PM_AUTHOR ?? settingsAuthor;\n const trimmed = candidate.trim();\n return trimmed.length > 0 ? trimmed : \"unknown\";\n}\n\nfunction buildChangedFields(frontMatter: ItemMetadata, body: string): string[] {\n const changed = [\n ...new Set([\n ...FRONT_MATTER_KEY_ORDER.filter((key) => frontMatter[key] !== undefined),\n ...Object.keys(frontMatter).filter((key) => frontMatter[key] !== undefined),\n ...(body.length > 0 ? [\"body\"] : []),\n ]),\n ];\n return changed.sort((left, right) => left.localeCompare(right));\n}\n\nfunction buildCopyMessage(sourceId: string, message: string | undefined): string {\n const suffix = `copied_from=${sourceId}`;\n if (!message) {\n return suffix;\n }\n const trimmed = message.trim();\n return trimmed.length > 0 ? `${trimmed} | ${suffix}` : suffix;\n}\n\n/**\n * Implements run copy for the public runtime surface of this module.\n */\nexport async function runCopy(sourceId: string, options: CopyOptions, global: GlobalOptions): Promise<CopyResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const located = await locateItem(pmRoot, sourceId, settings.id_prefix, settings.item_format, typeRegistry.type_to_folder);\n if (!located) {\n throw await buildItemNotFoundError(pmRoot, sourceId, settings.id_prefix, typeRegistry.type_to_folder);\n }\n const sourceLoaded = await readLocatedItem(located, { schema: settings.schema });\n const sourceMetadata = sourceLoaded.document.metadata;\n const copiedAt = nowIso();\n const author = selectAuthor(options.author, settings.author_default);\n const newId = await generateItemId(pmRoot, settings.id_prefix);\n const statusRegistry = resolveRuntimeStatusRegistry(settings.schema);\n const titleOverride = options.title?.trim();\n if (titleOverride !== undefined && titleOverride.length === 0) {\n throw new PmCliError(\"Copy --title must not be empty\", EXIT_CODE.USAGE);\n }\n\n const copiedMetadata: ItemMetadata = {\n ...(sourceMetadata as Record<string, unknown>),\n id: newId,\n title: titleOverride ?? sourceMetadata.title,\n status: statusRegistry.open_status,\n created_at: copiedAt,\n updated_at: copiedAt,\n } as ItemMetadata;\n delete copiedMetadata.closed_at;\n delete copiedMetadata.close_reason;\n delete copiedMetadata.test_runs;\n\n const extensionFieldNames = collectRegisteredItemFieldNames(getActiveExtensionRegistrations());\n const copiedDocument = canonicalDocument(\n {\n metadata: copiedMetadata,\n body: sourceLoaded.document.body,\n },\n {\n schema: settings.schema,\n extensionFieldNames,\n },\n );\n const changedFields = buildChangedFields(copiedDocument.metadata, copiedDocument.body);\n const itemPath = getItemPath(pmRoot, copiedDocument.metadata.type, newId, settings.item_format, typeRegistry.type_to_folder);\n const historyPath = getHistoryPath(pmRoot, newId);\n const lockRelease = await acquireLock(\n pmRoot,\n newId,\n settings.locks.ttl_seconds,\n author,\n false,\n settings.governance.force_required_for_stale_lock,\n settings.locks.wait_ms,\n );\n const beforeDocument: ItemDocument = {\n metadata: {} as ItemMetadata,\n body: \"\",\n };\n\n let hookWarnings: string[] = [];\n try {\n await writeFileAtomic(\n itemPath,\n serializeItemDocument(copiedDocument, {\n format: settings.item_format,\n schema: settings.schema,\n extensionFieldNames,\n }),\n );\n try {\n const historyEntry = createHistoryEntry({\n nowIso: copiedAt,\n author,\n op: \"create\",\n before: beforeDocument,\n after: copiedDocument,\n message: buildCopyMessage(located.id, options.message),\n });\n await appendHistoryEntry(historyPath, historyEntry);\n } catch (error: unknown) {\n await removeFileIfExists(itemPath);\n throw error;\n }\n\n hookWarnings = [\n ...(await runActiveOnWriteHooks({\n path: itemPath,\n scope: \"project\",\n op: \"create\",\n item_id: copiedDocument.metadata.id,\n item_type: copiedDocument.metadata.type,\n before: beforeDocument,\n after: copiedDocument,\n changed_fields: changedFields,\n })),\n ...(await runActiveOnWriteHooks({\n path: historyPath,\n scope: \"project\",\n op: \"create:history\",\n item_id: copiedDocument.metadata.id,\n item_type: copiedDocument.metadata.type,\n before: beforeDocument,\n after: copiedDocument,\n changed_fields: changedFields,\n })),\n ];\n recordAfterCommandAffectedItem({\n id: copiedDocument.metadata.id,\n op: \"create\",\n item_type: copiedDocument.metadata.type,\n status: copiedDocument.metadata.status,\n current: projectAfterCommandItemSnapshot(copiedDocument.metadata, changedFields),\n changed_fields: changedFields,\n });\n } finally {\n await lockRelease();\n }\n\n return {\n source_id: located.id,\n item: structuredClone(copiedDocument.metadata),\n changed_fields: changedFields,\n warnings: hookWarnings,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAS,aAAa,gBAAoC,gBAAsB;AAC9E,QAAM,YAAY,kBAAkB,QAAQ,IAAI,aAAa;AAC7D,QAAM,UAAU,UAAU,KAAI;AAC9B,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,mBAAmB,aAA2B,MAAY;AACjE,QAAM,UAAU;IACd,GAAG,oBAAI,IAAI;MACT,GAAG,uBAAuB,OAAO,CAAC,QAAQ,YAAY,GAAG,MAAM,MAAS;MACxE,GAAG,OAAO,KAAK,WAAW,EAAE,OAAO,CAAC,QAAQ,YAAY,GAAG,MAAM,MAAS;MAC1E,GAAI,KAAK,SAAS,IAAI,CAAC,MAAM,IAAI,CAAA;KAClC;;AAEH,SAAO,QAAQ,KAAK,CAAC,MAAM,UAAU,KAAK,cAAc,KAAK,CAAC;AAChE;AAEA,SAAS,iBAAiB,UAAkB,SAA2B;AACrE,QAAM,SAAS,eAAe,QAAQ;AACtC,MAAI,CAAC,SAAS;AACZ,WAAO;EACT;AACA,QAAM,UAAU,QAAQ,KAAI;AAC5B,SAAO,QAAQ,SAAS,IAAI,GAAG,OAAO,MAAM,MAAM,KAAK;AACzD;AAKA,eAAsB,QAAQ,UAAkB,SAAsB,QAAqB;AACzF,QAAM,SAAS,cAAc,QAAQ,IAAG,GAAI,OAAO,IAAI;AACvD,MAAI,CAAE,MAAM,WAAW,gBAAgB,MAAM,CAAC,GAAI;AAChD,U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xB,QACA,OACA,SAAS,MAAM,aACf,QACA,OACA,SAAS,WAAW,+BACpB,SAAS,MAAM,OAAO;AAExB,QAAM,iBAA+B;IACnC,UAAU,CAAA;IACV,MAAM;;AAGR,MAAI,eAAyB,CAAA;AAC7B,MAAI;AACF,UAAM,gBACJ,UACA,sBAAsB,gBAAgB;MACpC,QAAQ,SAAS;MACjB,QAAQ,SAAS;MACjB;KACD,CAAC;AAEJ,QAAI;AACF,YAAM,eAAe,mBAAmB;QACtC,QAAQ;QACR;QACA,IAAI;QACJ,QAAQ;QACR,OAAO;QACP,SAAS,iBAAiB,QAAQ,IAAI,QAAQ,OAAO;OACtD;AACD,YAAM,mBAAmB,aAAa,YAAY;IACpD,SAAS,OAAgB;AACvB,YAAM,mBAAmB,QAAQ;AACjC,YAAM;IACR;AAEA,mBAAe;MACb,GAAI,MAAM,sBAAsB;QAC9B,MAAM;QACN,OAAO;QACP,IAAI;QACJ,SAAS,eAAe,SAAS;QACjC,WAAW,eAAe,SAAS;QACnC,QAAQ;QACR,OAAO;QACP,gBAAgB;OACjB;MACD,GAAI,MAAM,sBAAsB;QAC9B,MAAM;QACN,OAAO;QACP,IAAI;QACJ,SAAS,eAAe,SAAS;QACjC,WAAW,eAAe,SAAS;QACnC,QAAQ;QACR,OAAO;QACP,gBAAgB;OACjB;;AAEH,mCAA+B;MAC7B,IAAI,eAAe,SAAS;MAC5B,IAAI;MACJ,WAAW,eAAe,SAAS;MACnC,QAAQ,eAAe,SAAS;MAChC,SAAS,gCAAgC,eAAe,UAAU,aAAa;MAC/E,gBAAgB;KACjB;EACH;AACE,UAAM,YAAW;EACnB;AAEA,SAAO;IACL,WAAW,QAAQ;IACnB,MAAM,gBAAgB,eAAe,QAAQ;IAC7C,gBAAgB;IAChB,UAAU;;AAEd","debugId":"d3a80b6a-fc91-5d8c-b2d8-b25844e554b1"}
1
+ {"version":3,"sources":["../../../../../../../../cli/commands/copy.ts"],"sourcesContent":["/**\n * @module cli/commands/copy\n *\n * Implements the pm copy command surface and its agent-facing runtime behavior.\n */\nimport { pathExists, removeFileIfExists, writeFileAtomic } from \"../../core/fs/fs-utils.js\";\nimport { appendHistoryEntry, createHistoryEntry } from \"../../core/history/history.js\";\nimport { generateItemId } from \"../../core/item/id.js\";\nimport { canonicalDocument, serializeItemDocument } from \"../../core/item/item-format.js\";\nimport { acquireLock } from \"../../core/lock/lock.js\";\nimport {\n getActiveExtensionRegistrations,\n projectAfterCommandItemSnapshot,\n recordAfterCommandAffectedItem,\n runActiveOnWriteHooks,\n} from \"../../core/extensions/index.js\";\nimport { collectRegisteredItemFieldNames } from \"../../core/extensions/item-fields.js\";\nimport { resolveRuntimeStatusRegistry } from \"../../core/schema/runtime-schema.js\";\nimport { EXIT_CODE, FRONT_MATTER_KEY_ORDER } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { nowIso } from \"../../core/shared/time.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { buildItemNotFoundError, locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport { getHistoryPath, getItemPath, getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport type { ItemDocument, ItemMetadata } from \"../../types/index.js\";\n\n/**\n * Documents the copy options payload exchanged by command, SDK, and package integrations.\n */\nexport interface CopyOptions {\n title?: string;\n author?: string;\n message?: string;\n}\n\n/**\n * Documents the copy result payload exchanged by command, SDK, and package integrations.\n */\nexport interface CopyResult {\n source_id: string;\n item: ItemMetadata;\n changed_fields: string[];\n warnings: string[];\n}\n\nfunction selectAuthor(explicitAuthor: string | undefined, settingsAuthor: string): string {\n const candidate = explicitAuthor ?? process.env.PM_AUTHOR ?? settingsAuthor;\n const trimmed = candidate.trim();\n return trimmed.length > 0 ? trimmed : \"unknown\";\n}\n\nfunction buildChangedFields(frontMatter: ItemMetadata, body: string): string[] {\n const changed = [\n ...new Set([\n ...FRONT_MATTER_KEY_ORDER.filter((key) => frontMatter[key] !== undefined),\n ...Object.keys(frontMatter).filter((key) => frontMatter[key] !== undefined),\n ...(body.length > 0 ? [\"body\"] : []),\n ]),\n ];\n return changed.sort((left, right) => left.localeCompare(right));\n}\n\nfunction buildCopyMessage(sourceId: string, message: string | undefined): string {\n const suffix = `copied_from=${sourceId}`;\n if (!message) {\n return suffix;\n }\n const trimmed = message.trim();\n return trimmed.length > 0 ? `${trimmed} | ${suffix}` : suffix;\n}\n\n/**\n * Implements run copy for the public runtime surface of this module.\n */\nexport async function runCopy(sourceId: string, options: CopyOptions, global: GlobalOptions): Promise<CopyResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(`Tracker is not initialized at ${pmRoot}. Run pm init first.`, EXIT_CODE.NOT_FOUND);\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(settings, getActiveExtensionRegistrations());\n const located = await locateItem(pmRoot, sourceId, settings.id_prefix, settings.item_format, typeRegistry.type_to_folder);\n if (!located) {\n throw await buildItemNotFoundError(pmRoot, sourceId, settings.id_prefix, typeRegistry.type_to_folder);\n }\n const sourceLoaded = await readLocatedItem(located, { schema: settings.schema });\n const sourceMetadata = sourceLoaded.document.metadata;\n const copiedAt = nowIso();\n const author = selectAuthor(options.author, settings.author_default);\n const newId = await generateItemId(pmRoot, settings.id_prefix);\n const statusRegistry = resolveRuntimeStatusRegistry(settings.schema);\n const titleOverride = options.title?.trim();\n if (titleOverride !== undefined && titleOverride.length === 0) {\n throw new PmCliError(\"Copy --title must not be empty\", EXIT_CODE.USAGE);\n }\n\n const copiedMetadata: ItemMetadata = {\n ...(sourceMetadata as Record<string, unknown>),\n id: newId,\n title: titleOverride ?? sourceMetadata.title,\n status: statusRegistry.open_status,\n created_at: copiedAt,\n updated_at: copiedAt,\n } as ItemMetadata;\n delete copiedMetadata.closed_at;\n delete copiedMetadata.close_reason;\n delete copiedMetadata.test_runs;\n\n const extensionFieldNames = collectRegisteredItemFieldNames(getActiveExtensionRegistrations());\n const copiedDocument = canonicalDocument(\n {\n metadata: copiedMetadata,\n body: sourceLoaded.document.body,\n },\n {\n schema: settings.schema,\n extensionFieldNames,\n },\n );\n const changedFields = buildChangedFields(copiedDocument.metadata, copiedDocument.body);\n const itemPath = getItemPath(pmRoot, copiedDocument.metadata.type, newId, settings.item_format, typeRegistry.type_to_folder);\n const historyPath = getHistoryPath(pmRoot, newId);\n const lockRelease = await acquireLock(\n pmRoot,\n newId,\n settings.locks.ttl_seconds,\n author,\n false,\n settings.governance.force_required_for_stale_lock,\n settings.locks.wait_ms,\n );\n const beforeDocument: ItemDocument = {\n metadata: {} as ItemMetadata,\n body: \"\",\n };\n\n let hookWarnings: string[] = [];\n try {\n await writeFileAtomic(\n itemPath,\n serializeItemDocument(copiedDocument, {\n format: settings.item_format,\n schema: settings.schema,\n extensionFieldNames,\n }),\n );\n try {\n const historyEntry = createHistoryEntry({\n nowIso: copiedAt,\n author,\n op: \"create\",\n before: beforeDocument,\n after: copiedDocument,\n message: buildCopyMessage(located.id, options.message),\n });\n await appendHistoryEntry(historyPath, historyEntry);\n } catch (error: unknown) {\n await removeFileIfExists(itemPath);\n throw error;\n }\n\n hookWarnings = [\n ...(await runActiveOnWriteHooks({\n path: itemPath,\n scope: \"project\",\n op: \"create\",\n item_id: copiedDocument.metadata.id,\n item_type: copiedDocument.metadata.type,\n before: beforeDocument,\n after: copiedDocument,\n changed_fields: changedFields,\n })),\n ...(await runActiveOnWriteHooks({\n path: historyPath,\n scope: \"project\",\n op: \"create:history\",\n item_id: copiedDocument.metadata.id,\n item_type: copiedDocument.metadata.type,\n before: beforeDocument,\n after: copiedDocument,\n changed_fields: changedFields,\n })),\n ];\n recordAfterCommandAffectedItem({\n id: copiedDocument.metadata.id,\n op: \"create\",\n item_type: copiedDocument.metadata.type,\n status: copiedDocument.metadata.status,\n current: projectAfterCommandItemSnapshot(copiedDocument.metadata, changedFields),\n changed_fields: changedFields,\n });\n } finally {\n await lockRelease();\n }\n\n return {\n source_id: located.id,\n item: structuredClone(copiedDocument.metadata),\n changed_fields: changedFields,\n warnings: hookWarnings,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,SAAS,aAAa,gBAAoC,gBAAsB;AAC9E,QAAM,YAAY,kBAAkB,QAAQ,IAAI,aAAa;AAC7D,QAAM,UAAU,UAAU,KAAI;AAC9B,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,SAAS,mBAAmB,aAA2B,MAAY;AACjE,QAAM,UAAU;IACd,GAAG,oBAAI,IAAI;MACT,GAAG,uBAAuB,OAAO,CAAC,QAAQ,YAAY,GAAG,MAAM,MAAS;MACxE,GAAG,OAAO,KAAK,WAAW,EAAE,OAAO,CAAC,QAAQ,YAAY,GAAG,MAAM,MAAS;MAC1E,GAAI,KAAK,SAAS,IAAI,CAAC,MAAM,IAAI,CAAA;KAClC;;AAEH,SAAO,QAAQ,KAAK,CAAC,MAAM,UAAU,KAAK,cAAc,KAAK,CAAC;AAChE;AAEA,SAAS,iBAAiB,UAAkB,SAA2B;AACrE,QAAM,SAAS,eAAe,QAAQ;AACtC,MAAI,CAAC,SAAS;AACZ,WAAO;EACT;AACA,QAAM,UAAU,QAAQ,KAAI;AAC5B,SAAO,QAAQ,SAAS,IAAI,GAAG,OAAO,MAAM,MAAM,KAAK;AACzD;AAKA,eAAsB,QAAQ,UAAkB,SAAsB,QAAqB;AACzF,QAAM,SAAS,cAAc,QAAQ,IAAG,GAAI,OAAO,IAAI;AACvD,MAAI,CAAE,MAAM,WAAW,gBAAgB,MAAM,CAAC,GAAI;AAChD,UAAM,IAAI,WAAW,iCAAiC,MAAM,wBAAwB,UAAU,SAAS;EACzG;AAEA,QAAM,WAAW,MAAM,aAAa,MAAM;AAC1C,QAAM,eAAe,wBAAwB,UAAU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