@unbrained/pm-cli 2026.7.20 → 2026.7.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (421) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +11 -0
  3. package/dist/cli/commander-usage.d.ts +1 -1
  4. package/dist/cli/commander-usage.js +5 -5
  5. package/dist/cli/commander-usage.js.map +1 -1
  6. package/dist/cli/commands/completion.js +13 -5
  7. package/dist/cli/commands/completion.js.map +1 -1
  8. package/dist/cli/commands/contracts.js +4 -3
  9. package/dist/cli/commands/contracts.js.map +1 -1
  10. package/dist/cli/error-guidance.d.ts +2 -0
  11. package/dist/cli/error-guidance.js +7 -2
  12. package/dist/cli/error-guidance.js.map +1 -1
  13. package/dist/cli/main.d.ts +1 -5
  14. package/dist/cli/main.js +12 -50
  15. package/dist/cli/main.js.map +1 -1
  16. package/dist/cli/register-list-query.js +13 -3
  17. package/dist/cli/register-list-query.js.map +1 -1
  18. package/dist/cli/register-mutation.js +45 -3
  19. package/dist/cli/register-mutation.js.map +1 -1
  20. package/dist/cli/register-structured-mutation.d.ts +14 -0
  21. package/dist/cli/register-structured-mutation.js +62 -0
  22. package/dist/cli/register-structured-mutation.js.map +1 -0
  23. package/dist/cli/registration-helpers.js +5 -3
  24. package/dist/cli/registration-helpers.js.map +1 -1
  25. package/dist/cli-bundle/bundle-manifest.json +280 -296
  26. package/dist/cli-bundle/chunks/{append-E6V54WOQ.js → append-7OVFYR3C.js} +3 -3
  27. package/dist/cli-bundle/chunks/{append-NNJ3EFIT.js → append-DFETHAZL.js} +3 -3
  28. package/dist/cli-bundle/chunks/{chunk-C3KD7U3T.js → chunk-2L6ZP22J.js} +241 -10
  29. package/dist/cli-bundle/chunks/chunk-2L6ZP22J.js.map +7 -0
  30. package/dist/cli-bundle/chunks/{chunk-KZEANWJS.js → chunk-4PUUNQDV.js} +98 -30
  31. package/dist/cli-bundle/chunks/chunk-4PUUNQDV.js.map +7 -0
  32. package/dist/cli-bundle/chunks/{chunk-RDV4ZFYS.js → chunk-4QOB7L7I.js} +7 -9
  33. package/dist/cli-bundle/chunks/{chunk-RDV4ZFYS.js.map → chunk-4QOB7L7I.js.map} +1 -1
  34. package/dist/cli-bundle/chunks/{chunk-3LPFHE3P.js → chunk-4QSQ6XDK.js} +62 -20
  35. package/dist/cli-bundle/chunks/chunk-4QSQ6XDK.js.map +1 -0
  36. package/dist/cli-bundle/chunks/{chunk-QJKL5PHS.js → chunk-7656MAUL.js} +2 -2
  37. package/dist/cli-bundle/chunks/{chunk-3AO5VSDR.js → chunk-7RW4JCU2.js} +328 -6
  38. package/dist/cli-bundle/chunks/chunk-7RW4JCU2.js.map +7 -0
  39. package/dist/cli-bundle/chunks/{chunk-X6K5XTTN.js → chunk-7W2UAXXT.js} +5 -5
  40. package/dist/cli-bundle/chunks/{chunk-SSKOQNMS.js → chunk-ABWCF646.js} +9 -11
  41. package/dist/cli-bundle/chunks/{chunk-SSKOQNMS.js.map → chunk-ABWCF646.js.map} +1 -1
  42. package/dist/cli-bundle/chunks/{chunk-WVA4DVNV.js → chunk-ADBTSVGK.js} +71 -33
  43. package/dist/cli-bundle/chunks/chunk-ADBTSVGK.js.map +7 -0
  44. package/dist/cli-bundle/chunks/{chunk-J4FBIFU6.js → chunk-AELMUANP.js} +12 -6
  45. package/dist/cli-bundle/chunks/chunk-AELMUANP.js.map +1 -0
  46. package/dist/cli-bundle/chunks/{chunk-4F6BWJ4J.js → chunk-AMJPSANK.js} +57 -36
  47. package/dist/cli-bundle/chunks/chunk-AMJPSANK.js.map +7 -0
  48. package/dist/cli-bundle/chunks/{chunk-6VIJ7UA5.js → chunk-AS4SAZ5R.js} +850 -819
  49. package/dist/cli-bundle/chunks/chunk-AS4SAZ5R.js.map +7 -0
  50. package/dist/cli-bundle/chunks/{chunk-SG74J6MV.js → chunk-ATBCUC7Y.js} +574 -5
  51. package/dist/cli-bundle/chunks/chunk-ATBCUC7Y.js.map +1 -0
  52. package/dist/cli-bundle/chunks/{chunk-5OK4UGFV.js → chunk-BXNDKOR2.js} +3 -3
  53. package/dist/cli-bundle/chunks/{chunk-KSPWRNVP.js → chunk-CPX275C6.js} +2 -2
  54. package/dist/cli-bundle/chunks/{chunk-JH2ZSLO3.js → chunk-DZRV2OPA.js} +2 -2
  55. package/dist/cli-bundle/chunks/{chunk-L7BH7IWU.js → chunk-E5XMKOSB.js} +2 -2
  56. package/dist/cli-bundle/chunks/{chunk-CQTQKUUV.js → chunk-EWJWSNRU.js} +3 -3
  57. package/dist/cli-bundle/chunks/{chunk-DAQ45GCS.js → chunk-F2LBF7XJ.js} +22 -15
  58. package/dist/cli-bundle/chunks/chunk-F2LBF7XJ.js.map +7 -0
  59. package/dist/cli-bundle/chunks/{chunk-6XMUURSS.js → chunk-FJIFFBJX.js} +64 -33
  60. package/dist/cli-bundle/chunks/chunk-FJIFFBJX.js.map +1 -0
  61. package/dist/cli-bundle/chunks/{chunk-E7ICD63T.js → chunk-FO6OSVEN.js} +4 -6
  62. package/dist/cli-bundle/chunks/{chunk-E7ICD63T.js.map → chunk-FO6OSVEN.js.map} +1 -1
  63. package/dist/cli-bundle/chunks/{chunk-3MCTMJXI.js → chunk-FPBMLYPI.js} +2 -2
  64. package/dist/cli-bundle/chunks/{chunk-UZDQXNUB.js → chunk-FSE2IKJQ.js} +46 -5
  65. package/dist/cli-bundle/chunks/chunk-FSE2IKJQ.js.map +1 -0
  66. package/dist/cli-bundle/chunks/{chunk-IX677TRO.js → chunk-GKX4NJ7U.js} +8 -10
  67. package/dist/cli-bundle/chunks/{chunk-IX677TRO.js.map → chunk-GKX4NJ7U.js.map} +1 -1
  68. package/dist/cli-bundle/chunks/{chunk-DVDBQA3B.js → chunk-GTK4DTEW.js} +5 -5
  69. package/dist/cli-bundle/chunks/chunk-H7EAER5L.js +974 -0
  70. package/dist/cli-bundle/chunks/chunk-H7EAER5L.js.map +1 -0
  71. package/dist/cli-bundle/chunks/{chunk-5UX66S6U.js → chunk-ICDAQ4TD.js} +316 -8
  72. package/dist/cli-bundle/chunks/chunk-ICDAQ4TD.js.map +1 -0
  73. package/dist/cli-bundle/chunks/{chunk-YQQNAKW3.js → chunk-JFD5LPMI.js} +6 -8
  74. package/dist/cli-bundle/chunks/{chunk-YQQNAKW3.js.map → chunk-JFD5LPMI.js.map} +1 -1
  75. package/dist/cli-bundle/chunks/{chunk-QANSTTC7.js → chunk-JXCW2TI2.js} +6 -8
  76. package/dist/cli-bundle/chunks/{chunk-QANSTTC7.js.map → chunk-JXCW2TI2.js.map} +1 -1
  77. package/dist/cli-bundle/chunks/{chunk-GSJSM5BJ.js → chunk-K36WV5J6.js} +76 -13
  78. package/dist/cli-bundle/chunks/chunk-K36WV5J6.js.map +1 -0
  79. package/dist/cli-bundle/chunks/{chunk-GVI6FAFG.js → chunk-K55VMLSS.js} +7 -5
  80. package/dist/cli-bundle/chunks/chunk-K55VMLSS.js.map +7 -0
  81. package/dist/cli-bundle/chunks/{chunk-GIQSU6S2.js → chunk-KBLZ3AA5.js} +2 -2
  82. package/dist/cli-bundle/chunks/{chunk-XJF7CDNH.js → chunk-KH44WBAT.js} +2 -2
  83. package/dist/cli-bundle/chunks/{chunk-GV2262OF.js → chunk-LAV26CQG.js} +2 -2
  84. package/dist/cli-bundle/chunks/{chunk-VDO2JMD4.js → chunk-LVC72YRD.js} +2 -2
  85. package/dist/cli-bundle/chunks/{chunk-3VY6MIEO.js → chunk-LZYP423P.js} +35 -6
  86. package/dist/cli-bundle/chunks/chunk-LZYP423P.js.map +7 -0
  87. package/dist/cli-bundle/chunks/{chunk-ZYPFOO3L.js → chunk-MATHDCGG.js} +3 -3
  88. package/dist/cli-bundle/chunks/{chunk-OV7MSW3I.js → chunk-MWQ2HC2A.js} +99 -31
  89. package/dist/cli-bundle/chunks/chunk-MWQ2HC2A.js.map +1 -0
  90. package/dist/cli-bundle/chunks/{chunk-NHT3F4WZ.js → chunk-NUF7ROFH.js} +840 -816
  91. package/dist/cli-bundle/chunks/chunk-NUF7ROFH.js.map +1 -0
  92. package/dist/cli-bundle/chunks/{chunk-AOEOYL3S.js → chunk-O4BCOJTZ.js} +3 -3
  93. package/dist/cli-bundle/chunks/{chunk-RJO3YAFM.js → chunk-OCUBRA6D.js} +2 -2
  94. package/dist/cli-bundle/chunks/{chunk-5IZJWSDB.js → chunk-OG5DVFMA.js} +22 -15
  95. package/dist/cli-bundle/chunks/chunk-OG5DVFMA.js.map +1 -0
  96. package/dist/cli-bundle/chunks/{chunk-I577UHC7.js → chunk-OR42SO64.js} +2 -2
  97. package/dist/cli-bundle/chunks/{chunk-ZOJ3LR7O.js → chunk-OY7DMU5P.js} +2 -2
  98. package/dist/cli-bundle/chunks/{chunk-HEWM6CEN.js → chunk-P7MTHPJQ.js} +50 -9
  99. package/dist/cli-bundle/chunks/chunk-P7MTHPJQ.js.map +7 -0
  100. package/dist/cli-bundle/chunks/{chunk-2BO4CA46.js → chunk-PFNHX655.js} +236 -12
  101. package/dist/cli-bundle/chunks/{chunk-2BO4CA46.js.map → chunk-PFNHX655.js.map} +1 -1
  102. package/dist/cli-bundle/chunks/{chunk-ZV2NTVMJ.js → chunk-PONKZPCJ.js} +2 -2
  103. package/dist/cli-bundle/chunks/{chunk-THAOZG4U.js → chunk-PQSEQD6E.js} +8 -6
  104. package/dist/cli-bundle/chunks/chunk-PQSEQD6E.js.map +1 -0
  105. package/dist/cli-bundle/chunks/chunk-PWDEHT3L.js +991 -0
  106. package/dist/cli-bundle/chunks/chunk-PWDEHT3L.js.map +7 -0
  107. package/dist/cli-bundle/chunks/{chunk-UX6SSO2I.js → chunk-PZC2FUOQ.js} +2 -2
  108. package/dist/cli-bundle/chunks/{chunk-WUVEBQW6.js → chunk-QG4GFLQ6.js} +3 -5
  109. package/dist/cli-bundle/chunks/{chunk-WUVEBQW6.js.map → chunk-QG4GFLQ6.js.map} +1 -1
  110. package/dist/cli-bundle/chunks/{chunk-VQIHNHMJ.js → chunk-QIH77CAG.js} +2 -2
  111. package/dist/cli-bundle/chunks/{chunk-R3EWPG4A.js → chunk-QJIKE24M.js} +2 -2
  112. package/dist/cli-bundle/chunks/{chunk-QLZ643FM.js → chunk-QOOTOD3W.js} +10 -12
  113. package/dist/cli-bundle/chunks/{chunk-QLZ643FM.js.map → chunk-QOOTOD3W.js.map} +1 -1
  114. package/dist/cli-bundle/chunks/{chunk-MYSS5H2A.js → chunk-R3P6FZJW.js} +5 -7
  115. package/dist/cli-bundle/chunks/{chunk-MYSS5H2A.js.map → chunk-R3P6FZJW.js.map} +1 -1
  116. package/dist/cli-bundle/chunks/{chunk-G3COA6GS.js → chunk-RNPZYNHS.js} +56 -35
  117. package/dist/cli-bundle/chunks/chunk-RNPZYNHS.js.map +1 -0
  118. package/dist/cli-bundle/chunks/{chunk-T44FMVRL.js → chunk-RPESLSO5.js} +62 -20
  119. package/dist/cli-bundle/chunks/chunk-RPESLSO5.js.map +7 -0
  120. package/dist/cli-bundle/chunks/{chunk-INSTSQNZ.js → chunk-SY4SFZSD.js} +595 -3
  121. package/dist/cli-bundle/chunks/chunk-SY4SFZSD.js.map +7 -0
  122. package/dist/cli-bundle/chunks/{chunk-HB3P4M52.js → chunk-TRSHFPRZ.js} +2 -2
  123. package/dist/cli-bundle/chunks/{chunk-HRW7GF6T.js → chunk-UCBDQI5E.js} +2 -2
  124. package/dist/cli-bundle/chunks/{chunk-4U4Z6AHI.js → chunk-V22ZPOKN.js} +2 -2
  125. package/dist/cli-bundle/chunks/{chunk-JM6YAXTR.js → chunk-VHXHVTUU.js} +2 -2
  126. package/dist/cli-bundle/chunks/{chunk-LPEYZRUR.js → chunk-VJQG4BIM.js} +35 -6
  127. package/dist/cli-bundle/chunks/chunk-VJQG4BIM.js.map +1 -0
  128. package/dist/cli-bundle/chunks/{chunk-D6NXDNP3.js → chunk-VLRGDBLY.js} +2 -2
  129. package/dist/cli-bundle/chunks/{chunk-JAPE62Y5.js → chunk-VNTCM3VW.js} +3 -3
  130. package/dist/cli-bundle/chunks/{chunk-FDHPAVVB.js → chunk-VXOOB6YX.js} +2 -2
  131. package/dist/cli-bundle/chunks/{chunk-GFQP7HAZ.js → chunk-VZIZB6QH.js} +3 -5
  132. package/dist/cli-bundle/chunks/{chunk-GFQP7HAZ.js.map → chunk-VZIZB6QH.js.map} +1 -1
  133. package/dist/cli-bundle/chunks/{chunk-HQ3SB4CN.js → chunk-X3W65QK3.js} +2 -2
  134. package/dist/cli-bundle/chunks/{chunk-RZJLNXFG.js → chunk-XJTABV3X.js} +3 -3
  135. package/dist/cli-bundle/chunks/{chunk-GVT754PX.js → chunk-YCIUJJOD.js} +11 -5
  136. package/dist/cli-bundle/chunks/chunk-YCIUJJOD.js.map +7 -0
  137. package/dist/cli-bundle/chunks/{chunk-IJNK6WW2.js → chunk-Z75ONV25.js} +75 -12
  138. package/dist/cli-bundle/chunks/chunk-Z75ONV25.js.map +7 -0
  139. package/dist/cli-bundle/chunks/{chunk-4L23AGQ7.js → chunk-Z7VWXXJM.js} +5 -7
  140. package/dist/cli-bundle/chunks/{chunk-4L23AGQ7.js.map → chunk-Z7VWXXJM.js.map} +1 -1
  141. package/dist/cli-bundle/chunks/{chunk-YBT7O4KT.js → chunk-ZTVA4KLN.js} +4 -6
  142. package/dist/cli-bundle/chunks/{chunk-YBT7O4KT.js.map → chunk-ZTVA4KLN.js.map} +1 -1
  143. package/dist/cli-bundle/chunks/{chunk-TYHJDFYW.js → chunk-ZVZGXPQ5.js} +2 -2
  144. package/dist/cli-bundle/chunks/{close-many-SDA426VT.js → close-many-5RZXVN4J.js} +5 -6
  145. package/dist/cli-bundle/chunks/{close-many-UTZANOCQ.js → close-many-RZVTUGBG.js} +5 -6
  146. package/dist/cli-bundle/chunks/{comments-LZN6FXXC.js → comments-TPU7QRBL.js} +4 -4
  147. package/dist/cli-bundle/chunks/{comments-VBQ345ND.js → comments-Z4KV6FU3.js} +4 -4
  148. package/dist/cli-bundle/chunks/{create-GG4RBCGC.js → create-EIFBIVNQ.js} +6 -6
  149. package/dist/cli-bundle/chunks/{create-JBC5KUW6.js → create-RGSPN5GD.js} +6 -6
  150. package/dist/cli-bundle/chunks/{deps-FI4O6NQS.js → deps-UH5EQQUY.js} +3 -3
  151. package/dist/cli-bundle/chunks/{deps-DELOO4TL.js → deps-YG7UF3VR.js} +3 -3
  152. package/dist/cli-bundle/chunks/{docs-6Z2MP526.js → docs-G32TK6XS.js} +4 -4
  153. package/dist/cli-bundle/chunks/{docs-2UYBP5D6.js → docs-JWWNRC27.js} +4 -4
  154. package/dist/cli-bundle/chunks/{files-HKEAN5MA.js → files-3H32UQ4K.js} +4 -4
  155. package/dist/cli-bundle/chunks/{files-HEUGSJZL.js → files-4ALMCSKB.js} +4 -4
  156. package/dist/cli-bundle/chunks/{history-compact-7NDVP3PT.js → history-compact-77BT2LUB.js} +3 -4
  157. package/dist/cli-bundle/chunks/{history-compact-65YVN5DB.js → history-compact-VCKGTX64.js} +3 -4
  158. package/dist/cli-bundle/chunks/{history-redact-7YBL4XSG.js → history-redact-LJPZPNFA.js} +2 -3
  159. package/dist/cli-bundle/chunks/{history-redact-IZGNJBU4.js → history-redact-PWTTJ3XS.js} +2 -3
  160. package/dist/cli-bundle/chunks/{history-repair-7M4PYQUH.js → history-repair-I7CBNCV3.js} +5 -6
  161. package/dist/cli-bundle/chunks/{history-repair-GNGETJLI.js → history-repair-YTDZRK5E.js} +5 -6
  162. package/dist/cli-bundle/chunks/{learnings-3YXDRWFT.js → learnings-CYNOICKR.js} +4 -4
  163. package/dist/cli-bundle/chunks/{learnings-ALC6IMNL.js → learnings-KTYW3AL7.js} +4 -4
  164. package/dist/cli-bundle/chunks/{notes-7JMLQ447.js → notes-FGO63FXL.js} +4 -4
  165. package/dist/cli-bundle/chunks/{notes-JFCLTC5C.js → notes-ZERD3KB2.js} +4 -4
  166. package/dist/cli-bundle/chunks/{plan-T3XB3WTK.js → plan-OFJUBIM5.js} +7 -7
  167. package/dist/cli-bundle/chunks/{plan-KOIPWVOZ.js → plan-SGCDDTYR.js} +7 -7
  168. package/dist/cli-bundle/chunks/{profile-OILJHKUW.js → profile-3THJPIQY.js} +4 -5
  169. package/dist/cli-bundle/chunks/{profile-RJXA7PGS.js → profile-XEZAMMBW.js} +4 -5
  170. package/dist/cli-bundle/chunks/{register-list-query-CFVG75P3.js → register-list-query-BR435Q2H.js} +19 -16
  171. package/dist/cli-bundle/chunks/register-list-query-BR435Q2H.js.map +1 -0
  172. package/dist/cli-bundle/chunks/{register-list-query-E7UVY4TN.js → register-list-query-RWTWLOBE.js} +18 -15
  173. package/dist/cli-bundle/chunks/register-list-query-RWTWLOBE.js.map +7 -0
  174. package/dist/cli-bundle/chunks/{register-mutation-IQ55E25C.js → register-mutation-HLWC2WNP.js} +167 -31
  175. package/dist/cli-bundle/chunks/register-mutation-HLWC2WNP.js.map +1 -0
  176. package/dist/cli-bundle/chunks/{register-mutation-4VJTXBZW.js → register-mutation-ZJX5AZM5.js} +173 -30
  177. package/dist/cli-bundle/chunks/register-mutation-ZJX5AZM5.js.map +7 -0
  178. package/dist/cli-bundle/chunks/{register-operations-AR7RMX4W.js → register-operations-744YBJMV.js} +23 -25
  179. package/dist/cli-bundle/chunks/{register-operations-AR7RMX4W.js.map → register-operations-744YBJMV.js.map} +1 -1
  180. package/dist/cli-bundle/chunks/{register-operations-NOLZGORC.js → register-operations-UEBJH6AN.js} +21 -23
  181. package/dist/cli-bundle/chunks/{register-operations-NOLZGORC.js.map → register-operations-UEBJH6AN.js.map} +1 -1
  182. package/dist/cli-bundle/chunks/{register-setup-EYZ7VTPZ.js → register-setup-5DA4UZXI.js} +7 -8
  183. package/dist/cli-bundle/chunks/{register-setup-EYZ7VTPZ.js.map → register-setup-5DA4UZXI.js.map} +1 -1
  184. package/dist/cli-bundle/chunks/{register-setup-BB77VUEE.js → register-setup-6H25M3BH.js} +9 -10
  185. package/dist/cli-bundle/chunks/{register-setup-BB77VUEE.js.map → register-setup-6H25M3BH.js.map} +1 -1
  186. package/dist/cli-bundle/chunks/{restore-ZH65GZFB.js → restore-6TDVSATY.js} +4 -5
  187. package/dist/cli-bundle/chunks/{restore-L6IAGOD7.js → restore-RSL7C7LO.js} +4 -5
  188. package/dist/cli-bundle/chunks/{schema-4ERWM5QJ.js → schema-HFXFSGPG.js} +2 -3
  189. package/dist/cli-bundle/chunks/{schema-55DL3Q52.js → schema-TPVTIJPO.js} +2 -3
  190. package/dist/cli-bundle/chunks/{update-FW6FKDOP.js → update-LJZCL5SI.js} +7 -7
  191. package/dist/cli-bundle/chunks/{update-TJHSPRPT.js → update-SIA7LH5Y.js} +7 -7
  192. package/dist/cli-bundle/chunks/{update-many-PWXX5WHO.js → update-many-BDBZVGQL.js} +11 -12
  193. package/dist/cli-bundle/chunks/{update-many-NNALYQCN.js → update-many-MOY3A5B3.js} +11 -12
  194. package/dist/cli-bundle/main.js +60 -85
  195. package/dist/cli-bundle/main.js.map +2 -2
  196. package/dist/cli-bundle/sdk-runtime.js +37 -37
  197. package/dist/cli-bundle/sdk.js +126 -291
  198. package/dist/cli-bundle/sdk.js.map +4 -4
  199. package/dist/core/item/parse.d.ts +1 -1
  200. package/dist/core/item/parse.js +13 -7
  201. package/dist/core/item/parse.js.map +1 -1
  202. package/dist/core/output/mutation-projection.d.ts +2 -0
  203. package/dist/core/output/mutation-projection.js +33 -2
  204. package/dist/core/output/mutation-projection.js.map +1 -1
  205. package/dist/core/output/output.d.ts +4 -0
  206. package/dist/core/output/output.js +18 -13
  207. package/dist/core/output/output.js.map +1 -1
  208. package/dist/core/shared/command-types.d.ts +4 -0
  209. package/dist/core/shared/command-types.js +2 -2
  210. package/dist/core/shared/command-types.js.map +1 -1
  211. package/dist/mcp/server.js +39 -4
  212. package/dist/mcp/server.js.map +1 -1
  213. package/dist/mcp/tool-definitions.js +45 -4
  214. package/dist/mcp/tool-definitions.js.map +1 -1
  215. package/dist/sdk/cli-bootstrap.d.ts +2 -0
  216. package/dist/sdk/cli-bootstrap.js +20 -27
  217. package/dist/sdk/cli-bootstrap.js.map +1 -1
  218. package/dist/sdk/cli-contracts/enum-contracts.d.ts +2 -2
  219. package/dist/sdk/cli-contracts/enum-contracts.js +7 -2
  220. package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -1
  221. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  222. package/dist/sdk/cli-contracts/flag-contracts.js +21 -2
  223. package/dist/sdk/cli-contracts/flag-contracts.js.map +1 -1
  224. package/dist/sdk/cli-contracts/tool-option-contracts.js +10 -2
  225. package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -1
  226. package/dist/sdk/cli-contracts/tool-parameter-tables.js +16 -3
  227. package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
  228. package/dist/sdk/cli-contracts/tool-schema.js +6 -2
  229. package/dist/sdk/cli-contracts/tool-schema.js.map +1 -1
  230. package/dist/sdk/cli-contracts.d.ts +1 -1
  231. package/dist/sdk/cli-contracts.js +3 -3
  232. package/dist/sdk/cli-contracts.js.map +1 -1
  233. package/dist/sdk/cli-program.js +4 -2
  234. package/dist/sdk/cli-program.js.map +1 -1
  235. package/dist/sdk/dependencies.d.ts +3 -2
  236. package/dist/sdk/dependencies.js +13 -12
  237. package/dist/sdk/dependencies.js.map +1 -1
  238. package/dist/sdk/error-runtime.d.ts +10 -0
  239. package/dist/sdk/error-runtime.js +59 -0
  240. package/dist/sdk/error-runtime.js.map +1 -0
  241. package/dist/sdk/graph/analytics.d.ts +9 -0
  242. package/dist/sdk/graph/analytics.js +24 -13
  243. package/dist/sdk/graph/analytics.js.map +1 -1
  244. package/dist/sdk/graph/assembly.d.ts +39 -0
  245. package/dist/sdk/graph/assembly.js +92 -12
  246. package/dist/sdk/graph/assembly.js.map +1 -1
  247. package/dist/sdk/graph/cache.d.ts +4 -1
  248. package/dist/sdk/graph/cache.js +17 -4
  249. package/dist/sdk/graph/cache.js.map +1 -1
  250. package/dist/sdk/graph/centrality.d.ts +82 -0
  251. package/dist/sdk/graph/centrality.js +259 -0
  252. package/dist/sdk/graph/centrality.js.map +1 -0
  253. package/dist/sdk/graph/durable-cache.d.ts +71 -0
  254. package/dist/sdk/graph/durable-cache.js +205 -0
  255. package/dist/sdk/graph/durable-cache.js.map +1 -0
  256. package/dist/sdk/graph/governance.d.ts +69 -1
  257. package/dist/sdk/graph/governance.js +143 -35
  258. package/dist/sdk/graph/governance.js.map +1 -1
  259. package/dist/sdk/graph/index.d.ts +7 -4
  260. package/dist/sdk/graph/index.js +8 -5
  261. package/dist/sdk/graph/index.js.map +1 -1
  262. package/dist/sdk/graph/mutation-advisory.d.ts +35 -4
  263. package/dist/sdk/graph/mutation-advisory.js +124 -35
  264. package/dist/sdk/graph/mutation-advisory.js.map +1 -1
  265. package/dist/sdk/graph/remediation.js +12 -2
  266. package/dist/sdk/graph/remediation.js.map +1 -1
  267. package/dist/sdk/graph/run.d.ts +133 -2
  268. package/dist/sdk/graph/run.js +217 -8
  269. package/dist/sdk/graph/run.js.map +1 -1
  270. package/dist/sdk/graph/scheduling.d.ts +59 -0
  271. package/dist/sdk/graph/scheduling.js +125 -0
  272. package/dist/sdk/graph/scheduling.js.map +1 -0
  273. package/dist/sdk/graph/traversal.d.ts +11 -0
  274. package/dist/sdk/graph/traversal.js +16 -2
  275. package/dist/sdk/graph/traversal.js.map +1 -1
  276. package/dist/sdk/index.d.ts +4 -0
  277. package/dist/sdk/index.js +6 -2
  278. package/dist/sdk/index.js.map +1 -1
  279. package/dist/sdk/runtime-input.js +7 -2
  280. package/dist/sdk/runtime-input.js.map +1 -1
  281. package/dist/sdk/runtime-primitives.d.ts +10 -0
  282. package/dist/sdk/runtime-primitives.js +14 -0
  283. package/dist/sdk/runtime-primitives.js.map +1 -0
  284. package/dist/sdk/runtime.d.ts +15 -0
  285. package/dist/sdk/runtime.js +16 -3
  286. package/dist/sdk/runtime.js.map +1 -1
  287. package/dist/sdk/structured-mutations.d.ts +21 -0
  288. package/dist/sdk/structured-mutations.js +375 -0
  289. package/dist/sdk/structured-mutations.js.map +1 -0
  290. package/docs/COMMANDS.md +85 -5
  291. package/docs/RELATIONSHIP_GRAPH.md +48 -7
  292. package/docs/SDK.md +78 -3
  293. package/marketplace.json +2 -2
  294. package/package.json +1 -1
  295. package/packages/pm-beads/package.json +1 -1
  296. package/packages/pm-calendar/package.json +1 -1
  297. package/packages/pm-command-kit/package.json +1 -1
  298. package/packages/pm-governance-audit/package.json +1 -1
  299. package/packages/pm-guide-shell/package.json +1 -1
  300. package/packages/pm-kanban/package.json +1 -1
  301. package/packages/pm-lifecycle-hooks/package.json +1 -1
  302. package/packages/pm-linked-test-adapters/package.json +1 -1
  303. package/packages/pm-search-advanced/package.json +1 -1
  304. package/packages/pm-templates/package.json +1 -1
  305. package/packages/pm-todos/package.json +1 -1
  306. package/packages/pm-vcs/package.json +1 -1
  307. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  308. package/plugins/pm-claude/README.md +5 -3
  309. package/plugins/pm-claude/commands/pm-init.md +1 -1
  310. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  311. package/dist/cli-bundle/chunks/chunk-3AO5VSDR.js.map +0 -7
  312. package/dist/cli-bundle/chunks/chunk-3LPFHE3P.js.map +0 -1
  313. package/dist/cli-bundle/chunks/chunk-3VY6MIEO.js.map +0 -7
  314. package/dist/cli-bundle/chunks/chunk-4F6BWJ4J.js.map +0 -7
  315. package/dist/cli-bundle/chunks/chunk-5IZJWSDB.js.map +0 -1
  316. package/dist/cli-bundle/chunks/chunk-5UX66S6U.js.map +0 -1
  317. package/dist/cli-bundle/chunks/chunk-6C2ZZX5Z.js +0 -286
  318. package/dist/cli-bundle/chunks/chunk-6C2ZZX5Z.js.map +0 -1
  319. package/dist/cli-bundle/chunks/chunk-6VIJ7UA5.js.map +0 -7
  320. package/dist/cli-bundle/chunks/chunk-6XMUURSS.js.map +0 -1
  321. package/dist/cli-bundle/chunks/chunk-C3KD7U3T.js.map +0 -7
  322. package/dist/cli-bundle/chunks/chunk-CFHAODHQ.js +0 -334
  323. package/dist/cli-bundle/chunks/chunk-CFHAODHQ.js.map +0 -1
  324. package/dist/cli-bundle/chunks/chunk-DAQ45GCS.js.map +0 -7
  325. package/dist/cli-bundle/chunks/chunk-E6LEMURX.js +0 -249
  326. package/dist/cli-bundle/chunks/chunk-E6LEMURX.js.map +0 -7
  327. package/dist/cli-bundle/chunks/chunk-G3COA6GS.js.map +0 -1
  328. package/dist/cli-bundle/chunks/chunk-GSJSM5BJ.js.map +0 -1
  329. package/dist/cli-bundle/chunks/chunk-GVI6FAFG.js.map +0 -7
  330. package/dist/cli-bundle/chunks/chunk-GVT754PX.js.map +0 -7
  331. package/dist/cli-bundle/chunks/chunk-HEWM6CEN.js.map +0 -7
  332. package/dist/cli-bundle/chunks/chunk-IJNK6WW2.js.map +0 -7
  333. package/dist/cli-bundle/chunks/chunk-INSTSQNZ.js.map +0 -7
  334. package/dist/cli-bundle/chunks/chunk-J4FBIFU6.js.map +0 -1
  335. package/dist/cli-bundle/chunks/chunk-KZEANWJS.js.map +0 -7
  336. package/dist/cli-bundle/chunks/chunk-LPEYZRUR.js.map +0 -1
  337. package/dist/cli-bundle/chunks/chunk-NHT3F4WZ.js.map +0 -1
  338. package/dist/cli-bundle/chunks/chunk-OV7MSW3I.js.map +0 -1
  339. package/dist/cli-bundle/chunks/chunk-P7JTWYLH.js +0 -246
  340. package/dist/cli-bundle/chunks/chunk-P7JTWYLH.js.map +0 -1
  341. package/dist/cli-bundle/chunks/chunk-R5U2VZ3K.js +0 -344
  342. package/dist/cli-bundle/chunks/chunk-R5U2VZ3K.js.map +0 -7
  343. package/dist/cli-bundle/chunks/chunk-SG74J6MV.js.map +0 -1
  344. package/dist/cli-bundle/chunks/chunk-T44FMVRL.js.map +0 -7
  345. package/dist/cli-bundle/chunks/chunk-THAOZG4U.js.map +0 -1
  346. package/dist/cli-bundle/chunks/chunk-UQLXSG72.js +0 -289
  347. package/dist/cli-bundle/chunks/chunk-UQLXSG72.js.map +0 -7
  348. package/dist/cli-bundle/chunks/chunk-UZDQXNUB.js.map +0 -1
  349. package/dist/cli-bundle/chunks/chunk-WVA4DVNV.js.map +0 -7
  350. package/dist/cli-bundle/chunks/register-list-query-CFVG75P3.js.map +0 -1
  351. package/dist/cli-bundle/chunks/register-list-query-E7UVY4TN.js.map +0 -7
  352. package/dist/cli-bundle/chunks/register-mutation-4VJTXBZW.js.map +0 -7
  353. package/dist/cli-bundle/chunks/register-mutation-IQ55E25C.js.map +0 -1
  354. /package/dist/cli-bundle/chunks/{append-E6V54WOQ.js.map → append-7OVFYR3C.js.map} +0 -0
  355. /package/dist/cli-bundle/chunks/{append-NNJ3EFIT.js.map → append-DFETHAZL.js.map} +0 -0
  356. /package/dist/cli-bundle/chunks/{chunk-QJKL5PHS.js.map → chunk-7656MAUL.js.map} +0 -0
  357. /package/dist/cli-bundle/chunks/{chunk-X6K5XTTN.js.map → chunk-7W2UAXXT.js.map} +0 -0
  358. /package/dist/cli-bundle/chunks/{chunk-5OK4UGFV.js.map → chunk-BXNDKOR2.js.map} +0 -0
  359. /package/dist/cli-bundle/chunks/{chunk-KSPWRNVP.js.map → chunk-CPX275C6.js.map} +0 -0
  360. /package/dist/cli-bundle/chunks/{chunk-JH2ZSLO3.js.map → chunk-DZRV2OPA.js.map} +0 -0
  361. /package/dist/cli-bundle/chunks/{chunk-L7BH7IWU.js.map → chunk-E5XMKOSB.js.map} +0 -0
  362. /package/dist/cli-bundle/chunks/{chunk-CQTQKUUV.js.map → chunk-EWJWSNRU.js.map} +0 -0
  363. /package/dist/cli-bundle/chunks/{chunk-3MCTMJXI.js.map → chunk-FPBMLYPI.js.map} +0 -0
  364. /package/dist/cli-bundle/chunks/{chunk-DVDBQA3B.js.map → chunk-GTK4DTEW.js.map} +0 -0
  365. /package/dist/cli-bundle/chunks/{chunk-GIQSU6S2.js.map → chunk-KBLZ3AA5.js.map} +0 -0
  366. /package/dist/cli-bundle/chunks/{chunk-XJF7CDNH.js.map → chunk-KH44WBAT.js.map} +0 -0
  367. /package/dist/cli-bundle/chunks/{chunk-GV2262OF.js.map → chunk-LAV26CQG.js.map} +0 -0
  368. /package/dist/cli-bundle/chunks/{chunk-VDO2JMD4.js.map → chunk-LVC72YRD.js.map} +0 -0
  369. /package/dist/cli-bundle/chunks/{chunk-ZYPFOO3L.js.map → chunk-MATHDCGG.js.map} +0 -0
  370. /package/dist/cli-bundle/chunks/{chunk-AOEOYL3S.js.map → chunk-O4BCOJTZ.js.map} +0 -0
  371. /package/dist/cli-bundle/chunks/{chunk-RJO3YAFM.js.map → chunk-OCUBRA6D.js.map} +0 -0
  372. /package/dist/cli-bundle/chunks/{chunk-I577UHC7.js.map → chunk-OR42SO64.js.map} +0 -0
  373. /package/dist/cli-bundle/chunks/{chunk-ZOJ3LR7O.js.map → chunk-OY7DMU5P.js.map} +0 -0
  374. /package/dist/cli-bundle/chunks/{chunk-ZV2NTVMJ.js.map → chunk-PONKZPCJ.js.map} +0 -0
  375. /package/dist/cli-bundle/chunks/{chunk-UX6SSO2I.js.map → chunk-PZC2FUOQ.js.map} +0 -0
  376. /package/dist/cli-bundle/chunks/{chunk-VQIHNHMJ.js.map → chunk-QIH77CAG.js.map} +0 -0
  377. /package/dist/cli-bundle/chunks/{chunk-R3EWPG4A.js.map → chunk-QJIKE24M.js.map} +0 -0
  378. /package/dist/cli-bundle/chunks/{chunk-HB3P4M52.js.map → chunk-TRSHFPRZ.js.map} +0 -0
  379. /package/dist/cli-bundle/chunks/{chunk-HRW7GF6T.js.map → chunk-UCBDQI5E.js.map} +0 -0
  380. /package/dist/cli-bundle/chunks/{chunk-4U4Z6AHI.js.map → chunk-V22ZPOKN.js.map} +0 -0
  381. /package/dist/cli-bundle/chunks/{chunk-JM6YAXTR.js.map → chunk-VHXHVTUU.js.map} +0 -0
  382. /package/dist/cli-bundle/chunks/{chunk-D6NXDNP3.js.map → chunk-VLRGDBLY.js.map} +0 -0
  383. /package/dist/cli-bundle/chunks/{chunk-JAPE62Y5.js.map → chunk-VNTCM3VW.js.map} +0 -0
  384. /package/dist/cli-bundle/chunks/{chunk-FDHPAVVB.js.map → chunk-VXOOB6YX.js.map} +0 -0
  385. /package/dist/cli-bundle/chunks/{chunk-HQ3SB4CN.js.map → chunk-X3W65QK3.js.map} +0 -0
  386. /package/dist/cli-bundle/chunks/{chunk-RZJLNXFG.js.map → chunk-XJTABV3X.js.map} +0 -0
  387. /package/dist/cli-bundle/chunks/{chunk-TYHJDFYW.js.map → chunk-ZVZGXPQ5.js.map} +0 -0
  388. /package/dist/cli-bundle/chunks/{close-many-SDA426VT.js.map → close-many-5RZXVN4J.js.map} +0 -0
  389. /package/dist/cli-bundle/chunks/{close-many-UTZANOCQ.js.map → close-many-RZVTUGBG.js.map} +0 -0
  390. /package/dist/cli-bundle/chunks/{comments-LZN6FXXC.js.map → comments-TPU7QRBL.js.map} +0 -0
  391. /package/dist/cli-bundle/chunks/{comments-VBQ345ND.js.map → comments-Z4KV6FU3.js.map} +0 -0
  392. /package/dist/cli-bundle/chunks/{create-GG4RBCGC.js.map → create-EIFBIVNQ.js.map} +0 -0
  393. /package/dist/cli-bundle/chunks/{create-JBC5KUW6.js.map → create-RGSPN5GD.js.map} +0 -0
  394. /package/dist/cli-bundle/chunks/{deps-FI4O6NQS.js.map → deps-UH5EQQUY.js.map} +0 -0
  395. /package/dist/cli-bundle/chunks/{deps-DELOO4TL.js.map → deps-YG7UF3VR.js.map} +0 -0
  396. /package/dist/cli-bundle/chunks/{docs-6Z2MP526.js.map → docs-G32TK6XS.js.map} +0 -0
  397. /package/dist/cli-bundle/chunks/{docs-2UYBP5D6.js.map → docs-JWWNRC27.js.map} +0 -0
  398. /package/dist/cli-bundle/chunks/{files-HKEAN5MA.js.map → files-3H32UQ4K.js.map} +0 -0
  399. /package/dist/cli-bundle/chunks/{files-HEUGSJZL.js.map → files-4ALMCSKB.js.map} +0 -0
  400. /package/dist/cli-bundle/chunks/{history-compact-7NDVP3PT.js.map → history-compact-77BT2LUB.js.map} +0 -0
  401. /package/dist/cli-bundle/chunks/{history-compact-65YVN5DB.js.map → history-compact-VCKGTX64.js.map} +0 -0
  402. /package/dist/cli-bundle/chunks/{history-redact-7YBL4XSG.js.map → history-redact-LJPZPNFA.js.map} +0 -0
  403. /package/dist/cli-bundle/chunks/{history-redact-IZGNJBU4.js.map → history-redact-PWTTJ3XS.js.map} +0 -0
  404. /package/dist/cli-bundle/chunks/{history-repair-7M4PYQUH.js.map → history-repair-I7CBNCV3.js.map} +0 -0
  405. /package/dist/cli-bundle/chunks/{history-repair-GNGETJLI.js.map → history-repair-YTDZRK5E.js.map} +0 -0
  406. /package/dist/cli-bundle/chunks/{learnings-3YXDRWFT.js.map → learnings-CYNOICKR.js.map} +0 -0
  407. /package/dist/cli-bundle/chunks/{learnings-ALC6IMNL.js.map → learnings-KTYW3AL7.js.map} +0 -0
  408. /package/dist/cli-bundle/chunks/{notes-7JMLQ447.js.map → notes-FGO63FXL.js.map} +0 -0
  409. /package/dist/cli-bundle/chunks/{notes-JFCLTC5C.js.map → notes-ZERD3KB2.js.map} +0 -0
  410. /package/dist/cli-bundle/chunks/{plan-T3XB3WTK.js.map → plan-OFJUBIM5.js.map} +0 -0
  411. /package/dist/cli-bundle/chunks/{plan-KOIPWVOZ.js.map → plan-SGCDDTYR.js.map} +0 -0
  412. /package/dist/cli-bundle/chunks/{profile-OILJHKUW.js.map → profile-3THJPIQY.js.map} +0 -0
  413. /package/dist/cli-bundle/chunks/{profile-RJXA7PGS.js.map → profile-XEZAMMBW.js.map} +0 -0
  414. /package/dist/cli-bundle/chunks/{restore-ZH65GZFB.js.map → restore-6TDVSATY.js.map} +0 -0
  415. /package/dist/cli-bundle/chunks/{restore-L6IAGOD7.js.map → restore-RSL7C7LO.js.map} +0 -0
  416. /package/dist/cli-bundle/chunks/{schema-4ERWM5QJ.js.map → schema-HFXFSGPG.js.map} +0 -0
  417. /package/dist/cli-bundle/chunks/{schema-55DL3Q52.js.map → schema-TPVTIJPO.js.map} +0 -0
  418. /package/dist/cli-bundle/chunks/{update-FW6FKDOP.js.map → update-LJZCL5SI.js.map} +0 -0
  419. /package/dist/cli-bundle/chunks/{update-TJHSPRPT.js.map → update-SIA7LH5Y.js.map} +0 -0
  420. /package/dist/cli-bundle/chunks/{update-many-PWXX5WHO.js.map → update-many-BDBZVGQL.js.map} +0 -0
  421. /package/dist/cli-bundle/chunks/{update-many-NNALYQCN.js.map → update-many-MOY3A5B3.js.map} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../../sdk/graph/traversal.ts", "../../../../../../../../sdk/graph/analytics.ts", "../../../../../../../../sdk/graph/governance.ts"],
4
+ "sourcesContent": ["/**\n * @module sdk/graph/traversal\n *\n * Registry-semantics graph traversal primitives layered over the bounded\n * relationship kernel: hierarchy walks (ancestors/descendants), execution-order\n * walks (predecessors/successors), and bounded simple-path enumeration. Every\n * query is deterministic, cancellable, resumable via an explicit cursor, and\n * reports exact cost and truncation metadata so agents can budget follow-up\n * calls without re-reading the workspace.\n */\nimport {\n RelationshipGraph,\n type RelationshipEdge,\n type RelationshipKindDefinition,\n type RelationshipNeighborEdge,\n type RelationshipQueryOptions,\n type RelationshipQueryResult,\n} from \"../relationships.js\";\n\n/**\n * Shared bounded-traversal controls extended with deterministic resumption.\n * Semantic hierarchy and ordering orientation comes from the relationship-kind\n * registry, so callers cannot supply the generic graph `direction` option.\n */\nexport interface GraphTraversalOptions extends Omit<\n RelationshipQueryOptions,\n \"direction\"\n> {\n /**\n * Resume emission after this previously returned node identifier. The\n * traversal re-walks the same deterministic sequence and starts emitting\n * after the cursor node; an identifier the sequence never reaches fails fast\n * instead of silently returning an empty page.\n */\n after?: string;\n}\n\n/** One enumerated simple path between two nodes. */\nexport interface RelationshipPath {\n /** Ordered node identifiers from source to target inclusive. */\n nodes: string[];\n /** Edges connecting consecutive path nodes, in traversal order. */\n edges: RelationshipEdge[];\n /** Number of edges in the path. */\n length: number;\n}\n\n/** Bounded-path enumeration controls. */\nexport interface GraphPathOptions extends RelationshipQueryOptions {\n /** Maximum number of returned paths; defaults to 5. */\n maxPaths?: number;\n /** Safety bound on expanded partial paths before truncation; defaults to 10000. */\n maxVisitedPaths?: number;\n}\n\n/** Default number of paths returned by bounded path enumeration. */\nconst DEFAULT_MAX_PATHS = 5;\n/** Default expansion-safety bound for bounded path enumeration. */\nconst DEFAULT_MAX_VISITED_PATHS = 10_000;\n/** Default depth bound applied to bounded path enumeration. */\nconst DEFAULT_PATH_MAX_DEPTH = 8;\n\n/** Require a finite non-negative integer for one path-enumeration bound. */\nfunction assertPathBound(name: string, value: number): void {\n if (!Number.isFinite(value) || !Number.isInteger(value) || value < 0)\n throw new TypeError(`Invalid path ${name} bound: ${String(value)}`);\n}\n\n/** Endpoint of a hierarchy edge that represents the structural parent. */\nexport function hierarchyParentEndpoint(\n edge: RelationshipEdge,\n definition: RelationshipKindDefinition,\n): string {\n // Custom hierarchy kinds may omit the direction; the registry documents the\n // source endpoint as the default parent.\n return definition.hierarchyDirection === \"target_parent\"\n ? edge.target\n : edge.source;\n}\n\n/** Endpoint of an ordering edge that must finish first. */\nexport function orderingPredecessorEndpoint(\n edge: RelationshipEdge,\n definition: RelationshipKindDefinition,\n): string {\n // Ordering kinds registered without explicit precedence default to\n // source-before-target, matching the execution-analytics interpretation.\n return (definition.precedence ?? \"source_before_target\") ===\n \"target_before_source\"\n ? edge.target\n : edge.source;\n}\n\n/**\n * Orient one ordering edge into its execution direction — the predecessor that\n * must finish first and the successor it gates — honoring the kind's declared\n * precedence so inverse spellings (`blocked_by`/`blocks`) agree. This is the\n * single ordering-orientation primitive shared by scheduling and degree\n * analytics.\n */\nexport function orientOrderingEdge(\n edge: RelationshipEdge,\n definition: RelationshipKindDefinition,\n): { predecessor: string; successor: string } {\n const predecessor = orderingPredecessorEndpoint(edge, definition);\n return {\n predecessor,\n successor: predecessor === edge.source ? edge.target : edge.source,\n };\n}\n\n/** Validate optional kind filters against one semantic edge family. */\nfunction resolveFamilyKinds(\n graph: RelationshipGraph,\n kinds: readonly string[] | undefined,\n family: \"hierarchy\" | \"ordering\",\n): Set<string> | undefined {\n if (kinds === undefined) return undefined;\n const registry = graph.registry();\n const resolved = new Set<string>();\n for (const kind of kinds) {\n const definition = registry.require(kind);\n if (!definition[family])\n throw new TypeError(\n `Relationship kind ${definition.kind} is not a ${family} kind`,\n );\n resolved.add(definition.kind);\n }\n return resolved;\n}\n\n/** Predicate deciding whether a neighbor row participates in one semantic walk. */\ntype SemanticNeighborPredicate = (\n row: RelationshipNeighborEdge,\n definition: RelationshipKindDefinition,\n nodeId: string,\n) => boolean;\n\n/** Mutable state for one bounded semantic breadth-first walk. */\ninterface SemanticWalkState {\n /** Nodes already discovered during the walk. */\n seen: Set<string>;\n /** Nodes emitted for the current page. */\n value: string[];\n /** Pending breadth-first nodes and their depths. */\n queue: { id: string; depth: number }[];\n /** Whether the optional cursor has been reached. */\n resumed: boolean;\n /** Whether a configured bound omitted reachable work. */\n truncated: boolean;\n}\n\n/** Mutable state for bounded simple-path enumeration. */\ninterface PathEnumerationState {\n /** Completed source-to-target paths. */\n value: RelationshipPath[];\n /** Partial simple paths pending expansion. */\n queue: { nodes: string[]; nodeSet: Set<string>; edges: RelationshipEdge[] }[];\n /** Total graph edges inspected by neighbor queries. */\n inspectedEdges: number;\n}\n\n/** Expand one node into its deterministic semantic neighbors. */\nfunction expandSemanticNeighbors(\n graph: RelationshipGraph,\n nodeId: string,\n familyKinds: Set<string> | undefined,\n family: \"hierarchy\" | \"ordering\",\n matches: SemanticNeighborPredicate,\n): { neighbors: string[]; inspectedEdges: number } {\n const registry = graph.registry();\n const rows = graph.neighborEdges(nodeId, {\n direction: \"both\",\n ...(familyKinds === undefined ? {} : { kinds: [...familyKinds] }),\n });\n const neighbors: string[] = [];\n const seen = new Set<string>();\n for (const row of rows.value) {\n const definition = registry.require(row.edge.kind);\n if (!definition[family]) continue;\n if (!matches(row, definition, nodeId)) continue;\n if (seen.has(row.id)) continue;\n seen.add(row.id);\n neighbors.push(row.id);\n }\n return { neighbors, inspectedEdges: rows.meta.inspectedEdges };\n}\n\n/** Append one semantic expansion and report whether the page limit was reached. */\nfunction appendSemanticExpansion(\n expansion: { neighbors: string[] },\n currentDepth: number,\n maxDepth: number,\n limit: number,\n after: string | undefined,\n state: SemanticWalkState,\n): boolean {\n if (currentDepth >= maxDepth) {\n if (expansion.neighbors.some((neighbor) => !state.seen.has(neighbor)))\n state.truncated = true;\n return false;\n }\n for (const neighbor of expansion.neighbors) {\n if (state.seen.has(neighbor)) continue;\n state.seen.add(neighbor);\n state.queue.push({ id: neighbor, depth: currentDepth + 1 });\n if (!state.resumed) {\n if (neighbor === after) state.resumed = true;\n continue;\n }\n if (state.value.length >= limit) {\n state.truncated = true;\n return true;\n }\n state.value.push(neighbor);\n }\n return false;\n}\n\n/** Run one deterministic bounded breadth-first semantic walk. */\nfunction boundedSemanticWalk(\n graph: RelationshipGraph,\n start: string,\n options: GraphTraversalOptions,\n family: \"hierarchy\" | \"ordering\",\n matches: SemanticNeighborPredicate,\n): RelationshipQueryResult<string[]> {\n if (!graph.hasNode(start))\n throw new TypeError(`Relationship node not found: ${start}`);\n const familyKinds = resolveFamilyKinds(graph, options.kinds, family);\n const limit = options.limit ?? Number.POSITIVE_INFINITY;\n const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;\n const after = options.after;\n const state: SemanticWalkState = {\n seen: new Set([start]),\n value: [],\n queue: [{ id: start, depth: 0 }],\n resumed: after === undefined,\n truncated: false,\n };\n let visitedNodes = 0;\n let inspectedEdges = 0;\n for (let index = 0; index < state.queue.length; index += 1) {\n options.signal?.throwIfAborted();\n const current = state.queue[index]!;\n visitedNodes += 1;\n const expansion = expandSemanticNeighbors(\n graph,\n current.id,\n familyKinds,\n family,\n matches,\n );\n inspectedEdges += expansion.inspectedEdges;\n if (\n appendSemanticExpansion(\n expansion,\n current.depth,\n maxDepth,\n limit,\n after,\n state,\n )\n )\n break;\n }\n if (!state.resumed)\n throw new TypeError(`Traversal cursor not found in sequence: ${after}`);\n return {\n value: state.value,\n meta: {\n visitedNodes,\n inspectedEdges,\n truncated: state.truncated,\n nextCursor: state.value.at(-1),\n },\n };\n}\n/** Validate one path endpoint against the indexed graph. */\nfunction assertPathEndpoint(graph: RelationshipGraph, id: string): void {\n if (!graph.hasNode(id))\n throw new TypeError(`Relationship node not found: ${id}`);\n}\n\n/** Return eligible simple-path continuations and account for inspected edges. */\nfunction readPathContinuations(\n graph: RelationshipGraph,\n partial: { nodes: string[]; nodeSet: Set<string>; edges: RelationshipEdge[] },\n options: GraphPathOptions,\n direction: \"outgoing\" | \"incoming\" | \"both\",\n state: PathEnumerationState,\n): ReturnType<RelationshipGraph[\"neighborEdges\"]>[\"value\"] {\n const rows = graph.neighborEdges(partial.nodes.at(-1)!, {\n direction,\n ...(options.kinds === undefined ? {} : { kinds: options.kinds }),\n });\n state.inspectedEdges += rows.meta.inspectedEdges;\n return rows.value.filter((row) => !partial.nodeSet.has(row.id));\n}\n\n/** Expand one partial simple path and report whether the probe cap was reached. */\nfunction expandPartialPath(\n graph: RelationshipGraph,\n partial: { nodes: string[]; nodeSet: Set<string>; edges: RelationshipEdge[] },\n target: string,\n options: GraphPathOptions,\n direction: \"outgoing\" | \"incoming\" | \"both\",\n probeLimit: number,\n state: PathEnumerationState,\n): boolean {\n for (const row of readPathContinuations(\n graph,\n partial,\n options,\n direction,\n state,\n )) {\n const nodes = [...partial.nodes, row.id];\n const nodeSet = new Set(partial.nodeSet).add(row.id);\n const edges = [...partial.edges, row.edge];\n if (row.id === target) {\n state.value.push({ nodes, edges, length: edges.length });\n if (state.value.length >= probeLimit) return true;\n } else {\n state.queue.push({ nodes, nodeSet, edges });\n }\n }\n return false;\n}\n\n/**\n * Return the bounded transitive hierarchy ancestors of one node in\n * breadth-first discovery order, honoring each hierarchy kind's declared\n * parent endpoint (so `parent` and inverse `child` spellings agree).\n */\nexport function hierarchyAncestors(\n graph: RelationshipGraph,\n id: string,\n options: GraphTraversalOptions = {},\n): RelationshipQueryResult<string[]> {\n return boundedSemanticWalk(\n graph,\n id,\n options,\n \"hierarchy\",\n (row, definition) =>\n hierarchyParentEndpoint(row.edge, definition) === row.id,\n );\n}\n\n/**\n * Return the bounded transitive hierarchy descendants of one node in\n * breadth-first discovery order, honoring each hierarchy kind's declared\n * parent endpoint.\n */\nexport function hierarchyDescendants(\n graph: RelationshipGraph,\n id: string,\n options: GraphTraversalOptions = {},\n): RelationshipQueryResult<string[]> {\n return boundedSemanticWalk(\n graph,\n id,\n options,\n \"hierarchy\",\n (row, definition, nodeId) =>\n hierarchyParentEndpoint(row.edge, definition) === nodeId,\n );\n}\n\n/**\n * Return the bounded transitive execution predecessors of one node — the work\n * that must finish before it — in breadth-first discovery order, honoring each\n * ordering kind's declared precedence (so `blocked_by` and inverse `blocks`\n * spellings agree).\n */\nexport function orderingPredecessors(\n graph: RelationshipGraph,\n id: string,\n options: GraphTraversalOptions = {},\n): RelationshipQueryResult<string[]> {\n return boundedSemanticWalk(\n graph,\n id,\n options,\n \"ordering\",\n (row, definition) =>\n orderingPredecessorEndpoint(row.edge, definition) === row.id,\n );\n}\n\n/**\n * Return the bounded transitive execution successors of one node — the work\n * this node gates — in breadth-first discovery order, honoring each ordering\n * kind's declared precedence.\n */\nexport function orderingSuccessors(\n graph: RelationshipGraph,\n id: string,\n options: GraphTraversalOptions = {},\n): RelationshipQueryResult<string[]> {\n return boundedSemanticWalk(\n graph,\n id,\n options,\n \"ordering\",\n (row, definition, nodeId) =>\n orderingPredecessorEndpoint(row.edge, definition) === nodeId,\n );\n}\n\n/** Run bounded non-zero path enumeration after public option validation. */\nfunction enumerateNonZeroRelationshipPaths(\n graph: RelationshipGraph,\n source: string,\n target: string,\n options: GraphPathOptions,\n maxPaths: number,\n maxVisitedPaths: number,\n maxDepth: number,\n direction: \"outgoing\" | \"incoming\" | \"both\",\n): RelationshipQueryResult<RelationshipPath[]> {\n const state: PathEnumerationState = {\n value: [],\n queue: [{ nodes: [source], nodeSet: new Set([source]), edges: [] }],\n inspectedEdges: 0,\n };\n let visitedNodes = 0;\n let truncated = false;\n const probeLimit = maxPaths + 1;\n for (let index = 0; index < state.queue.length; index += 1) {\n options.signal?.throwIfAborted();\n if (state.value.length >= probeLimit || visitedNodes >= maxVisitedPaths) {\n truncated = true;\n break;\n }\n const partial = state.queue[index]!;\n visitedNodes += 1;\n if (partial.edges.length >= maxDepth) {\n if (\n readPathContinuations(graph, partial, options, direction, state)\n .length > 0\n )\n truncated = true;\n continue;\n }\n if (\n expandPartialPath(\n graph,\n partial,\n target,\n options,\n direction,\n probeLimit,\n state,\n )\n ) {\n truncated = true;\n break;\n }\n }\n return {\n value: state.value.slice(0, maxPaths),\n meta: { visitedNodes, inspectedEdges: state.inspectedEdges, truncated },\n };\n}\n\n/**\n * Enumerate bounded simple paths between two nodes, shortest first and\n * lexicographic within equal length. Traversal honors direction and kind\n * filters, caps returned paths, and reports truncation when depth, path-count,\n * or the expansion-safety bound stops the search early.\n */\nexport function enumerateRelationshipPaths(\n graph: RelationshipGraph,\n source: string,\n target: string,\n options: GraphPathOptions = {},\n): RelationshipQueryResult<RelationshipPath[]> {\n assertPathEndpoint(graph, source);\n assertPathEndpoint(graph, target);\n const maxPaths = options.maxPaths ?? DEFAULT_MAX_PATHS;\n const maxVisitedPaths = options.maxVisitedPaths ?? DEFAULT_MAX_VISITED_PATHS;\n const maxDepth = options.maxDepth ?? DEFAULT_PATH_MAX_DEPTH;\n assertPathBound(\"maxPaths\", maxPaths);\n assertPathBound(\"maxVisitedPaths\", maxVisitedPaths);\n assertPathBound(\"maxDepth\", maxDepth);\n const direction = options.direction ?? \"outgoing\";\n options.signal?.throwIfAborted();\n for (const kind of options.kinds ?? []) graph.registry().require(kind);\n if (source === target) {\n if (maxPaths === 0) {\n return {\n value: [],\n meta: { visitedNodes: 1, inspectedEdges: 0, truncated: true },\n };\n }\n return {\n value: [{ nodes: [source], edges: [], length: 0 }],\n meta: { visitedNodes: 1, inspectedEdges: 0, truncated: false },\n };\n }\n return enumerateNonZeroRelationshipPaths(\n graph,\n source,\n target,\n options,\n maxPaths,\n maxVisitedPaths,\n maxDepth,\n direction,\n );\n}\n", "/**\n * @module sdk/graph/analytics\n *\n * Structural graph analytics beyond exact components: deterministic\n * label-propagation community detection over the undirected relationship\n * structure, transitively redundant edge discovery over ordering and\n * hierarchy families, and dominator (bottleneck) analysis over one node's\n * reachable subgraph. Every analysis is deterministic, cancellable, bounded,\n * and reports exact cost metadata so agents can budget follow-up reads\n * without re-scanning the workspace.\n */\nimport {\n RelationshipGraph,\n type RelationshipEdge,\n type RelationshipKindDefinition,\n type RelationshipNeighborEdge,\n type RelationshipQueryResult,\n type RelationshipTraversalDirection,\n} from \"../relationships.js\";\nimport {\n hierarchyParentEndpoint,\n orderingPredecessorEndpoint,\n} from \"./traversal.js\";\n\n/** Default label-propagation sweeps before reporting non-convergence. */\nconst DEFAULT_MAX_ITERATIONS = 16;\n/** Default minimum member count for a reported community. */\nconst DEFAULT_MIN_COMMUNITY_SIZE = 2;\n/** Default witness-path depth searched per candidate redundant edge. */\nconst DEFAULT_REDUNDANCY_MAX_DEPTH = 8;\n\n/** One detected relationship community. */\nexport interface RelationshipCommunity {\n /** Lexicographically smallest member id, naming the community. */\n representative: string;\n /** Total member count. */\n size: number;\n /** Sorted member node ids. */\n members: string[];\n}\n\n/** Bounded community-detection controls. */\nexport interface GraphCommunityOptions {\n /** Registered relationship kinds whose edges define adjacency. */\n kinds?: readonly string[];\n /** Maximum label-propagation sweeps before reporting non-convergence; defaults to 16. */\n maxIterations?: number;\n /** Minimum member count for a reported community; defaults to 2. */\n minSize?: number;\n /** Abort signal checked once per sweep. */\n signal?: AbortSignal;\n}\n\n/** Deterministic label-propagation community analysis. */\nexport interface RelationshipCommunityAnalysis {\n /** Detected communities, largest first and by representative within equal size. */\n communities: RelationshipCommunity[];\n /** Label-propagation sweeps executed. */\n iterations: number;\n /** Whether labels stabilized before the iteration bound stopped the sweep. */\n converged: boolean;\n}\n\n/** One stored edge implied by a longer same-family witness path. */\nexport interface RedundantRelationshipEdge {\n /** The stored redundant edge in its original spelling. */\n edge: RelationshipEdge;\n /** Semantic-orientation witness node path proving the implication, endpoints inclusive. */\n witness: string[];\n}\n\n/** Bounded redundancy-scan controls. */\nexport interface GraphRedundancyOptions {\n /** Directed ordering or hierarchy kinds to scan; defaults to every eligible registered kind. */\n kinds?: readonly string[];\n /** Maximum witness-path depth searched per edge; defaults to 8. */\n maxDepth?: number;\n /** Maximum reported redundant edges. */\n limit?: number;\n /** Abort signal checked once per scanned edge. */\n signal?: AbortSignal;\n}\n\n/** One reachable node with its immediate dominator and gating weight. */\nexport interface RelationshipDominatorRow {\n /** Reachable node id. */\n id: string;\n /** Immediate dominator appearing on every root-to-node path. */\n idom: string;\n /** Nodes strictly dominated by this node — its dominator-subtree size minus itself. */\n dominatedCount: number;\n}\n\n/** Bounded dominator-analysis controls. */\nexport interface GraphDominatorOptions {\n /** Registered relationship kinds whose edges define reachability. */\n kinds?: readonly string[];\n /** Traversal direction relative to each visited node; defaults to \"outgoing\". */\n direction?: RelationshipTraversalDirection;\n /** Maximum reachability depth from the root as a non-negative integer. */\n maxDepth?: number;\n /** Abort signal checked once per processed node. */\n signal?: AbortSignal;\n}\n\n/** Dominator-tree analysis of one node's reachable subgraph. */\nexport interface RelationshipDominatorAnalysis {\n /** Analyzed root id. */\n root: string;\n /** Reachable node count including the root. */\n reachableCount: number;\n /** Non-root reachable rows sorted by gating weight, then id. */\n rows: RelationshipDominatorRow[];\n}\n\n/** Require a positive integer for one analytics bound. */\nfunction assertPositiveBound(name: string, value: number): void {\n if (!Number.isInteger(value) || value < 1)\n throw new TypeError(`Invalid ${name} bound: ${String(value)}`);\n}\n\n/**\n * Invoke `visit` once per canonical-kind-matched edge, skipping self-loops.\n * Kind filters resolve to canonical spelling and match either the requested\n * kind or its inverse so directed families are selected by either spelling. The\n * resolved definition is passed alongside the edge so callers can distinguish\n * directed and undirected families. This is the single edge-selection primitive\n * shared by community, centrality, cut-structure, and degree builders.\n */\nexport function forEachMatchedRelationshipEdge(\n graph: RelationshipGraph,\n kinds: readonly string[] | undefined,\n visit: (\n edge: RelationshipEdge,\n definition: RelationshipKindDefinition,\n ) => void,\n): void {\n const registry = graph.registry();\n const wanted =\n kinds === undefined\n ? undefined\n : new Set(kinds.map((kind) => registry.require(kind).kind));\n for (const edge of graph.edges()) {\n if (edge.source === edge.target) continue;\n const definition = registry.require(edge.kind);\n if (\n wanted !== undefined &&\n !(\n wanted.has(definition.kind) ||\n (definition.inverse !== undefined && wanted.has(definition.inverse))\n )\n )\n continue;\n visit(edge, definition);\n }\n}\n\n/** Build the deterministic undirected multiset adjacency restricted to canonicalized kinds. */\nfunction buildUndirectedAdjacency(\n graph: RelationshipGraph,\n kinds: readonly string[] | undefined,\n): Map<string, string[]> {\n const adjacency = new Map<string, string[]>();\n forEachMatchedRelationshipEdge(graph, kinds, (edge) => {\n appendAdjacency(adjacency, edge.source, edge.target);\n appendAdjacency(adjacency, edge.target, edge.source);\n });\n for (const neighbors of adjacency.values()) neighbors.sort();\n return adjacency;\n}\n\n/** Append one neighbor to a node's adjacency list, creating the list on demand. */\nfunction appendAdjacency(\n adjacency: Map<string, string[]>,\n from: string,\n to: string,\n): void {\n const neighbors = adjacency.get(from);\n if (neighbors === undefined) adjacency.set(from, [to]);\n else neighbors.push(to);\n}\n\n/** Adopt the most frequent neighbor label with lexicographic tie-breaking. */\nfunction dominantNeighborLabel(\n neighbors: readonly string[],\n labels: Map<string, string>,\n): string {\n const counts = new Map<string, number>();\n for (const neighbor of neighbors) {\n const label = labels.get(neighbor)!;\n counts.set(label, (counts.get(label) ?? 0) + 1);\n }\n let best: string | undefined;\n let bestCount = 0;\n for (const [label, count] of counts) {\n if (count > bestCount || (count === bestCount && label < best!)) {\n best = label;\n bestCount = count;\n }\n }\n return best!;\n}\n\n/** Group stabilized labels into sorted communities meeting the size floor. */\nfunction collectCommunities(\n labels: Map<string, string>,\n minSize: number,\n): RelationshipCommunity[] {\n const groups = new Map<string, string[]>();\n for (const [id, label] of labels) {\n const members = groups.get(label);\n if (members === undefined) groups.set(label, [id]);\n else members.push(id);\n }\n const communities: RelationshipCommunity[] = [];\n for (const members of groups.values()) {\n if (members.length < minSize) continue;\n members.sort();\n communities.push({\n representative: members[0]!,\n size: members.length,\n members,\n });\n }\n return communities.sort(\n (left, right) =>\n right.size - left.size ||\n left.representative.localeCompare(right.representative),\n );\n}\n\n/**\n * Detect communities with deterministic asynchronous label propagation: nodes\n * are swept in sorted order, each adopting the most frequent label among its\n * neighbors with lexicographic tie-breaking, until labels stabilize or the\n * iteration bound stops the sweep. Adjacency is undirected — every\n * participating edge connects both endpoints symmetrically and parallel edges\n * weight their neighbor. `meta.truncated` reports non-convergence.\n */\nexport function detectRelationshipCommunities(\n graph: RelationshipGraph,\n options: GraphCommunityOptions = {},\n): RelationshipQueryResult<RelationshipCommunityAnalysis> {\n const maxIterations = options.maxIterations ?? DEFAULT_MAX_ITERATIONS;\n const minSize = options.minSize ?? DEFAULT_MIN_COMMUNITY_SIZE;\n assertPositiveBound(\"maxIterations\", maxIterations);\n assertPositiveBound(\"minSize\", minSize);\n const adjacency = buildUndirectedAdjacency(graph, options.kinds);\n const nodes = graph.nodes();\n const labels = new Map(nodes.map((id) => [id, id]));\n let iterations = 0;\n let converged = false;\n let visitedNodes = 0;\n let inspectedEdges = 0;\n while (iterations < maxIterations && !converged) {\n options.signal?.throwIfAborted();\n iterations += 1;\n converged = true;\n for (const id of nodes) {\n visitedNodes += 1;\n const neighbors = adjacency.get(id);\n if (neighbors === undefined) continue;\n inspectedEdges += neighbors.length;\n const dominant = dominantNeighborLabel(neighbors, labels);\n if (dominant !== labels.get(id)) {\n labels.set(id, dominant);\n converged = false;\n }\n }\n }\n return {\n value: {\n communities: collectCommunities(labels, minSize),\n iterations,\n converged,\n },\n meta: { visitedNodes, inspectedEdges, truncated: !converged },\n };\n}\n\n/** Decide whether a kind carries transitive semantics eligible for redundancy and duplicate analysis. */\nexport function isTransitiveKind(definition: RelationshipKindDefinition): boolean {\n return (\n definition.direction === \"directed\" &&\n (definition.ordering || definition.hierarchy)\n );\n}\n\n/** Family grouping key joining a directed kind with its inverse spelling. */\nexport function transitiveFamilyKey(definition: RelationshipKindDefinition): string {\n return definition.inverse !== undefined &&\n definition.inverse < definition.kind\n ? definition.inverse\n : definition.kind;\n}\n\n/** Orient one transitive edge into its semantic forward direction. */\nexport function orientTransitiveEdge(\n edge: RelationshipEdge,\n definition: RelationshipKindDefinition,\n): { from: string; to: string } {\n // Hierarchy families flow child -> parent; ordering families flow\n // predecessor -> successor, so inverse spellings land in one relation.\n const head = definition.hierarchy\n ? hierarchyParentEndpoint(edge, definition)\n : edge.source === orderingPredecessorEndpoint(edge, definition)\n ? edge.target\n : edge.source;\n return head === edge.target\n ? { from: edge.source, to: edge.target }\n : { from: edge.target, to: edge.source };\n}\n\n/** One semantically oriented transitive edge retaining its stored spelling. */\ninterface OrientedTransitiveEdge {\n /** Semantic tail node. */\n from: string;\n /** Semantic head node. */\n to: string;\n /** Original stored edge. */\n edge: RelationshipEdge;\n}\n\n/** Per-family oriented edges and their deterministic forward adjacency. */\ninterface TransitiveFamily {\n /** Deduplicated forward adjacency in semantic orientation, sorted after collection. */\n adjacency: Map<string, Set<string>>;\n /** Oriented edges in deterministic stored order. */\n records: OrientedTransitiveEdge[];\n}\n\n/** Resolve explicit redundancy kind filters into their family keys. */\nfunction resolveRedundancyFamilies(\n graph: RelationshipGraph,\n kinds: readonly string[] | undefined,\n): Set<string> | undefined {\n if (kinds === undefined) return undefined;\n const registry = graph.registry();\n const families = new Set<string>();\n for (const kind of kinds) {\n const definition = registry.require(kind);\n if (!isTransitiveKind(definition))\n throw new TypeError(\n `Relationship kind ${definition.kind} is not a directed ordering or hierarchy kind`,\n );\n families.add(transitiveFamilyKey(definition));\n }\n return families;\n}\n\n/** Group eligible stored edges into oriented per-family scan structures. */\nfunction collectTransitiveFamilies(\n graph: RelationshipGraph,\n wanted: Set<string> | undefined,\n): Map<string, TransitiveFamily> {\n const registry = graph.registry();\n const families = new Map<string, TransitiveFamily>();\n for (const edge of graph.edges()) {\n const definition = registry.require(edge.kind);\n if (!isTransitiveKind(definition)) continue;\n const key = transitiveFamilyKey(definition);\n if (wanted !== undefined && !wanted.has(key)) continue;\n const oriented = orientTransitiveEdge(edge, definition);\n if (oriented.from === oriented.to) continue;\n let family = families.get(key);\n if (family === undefined) {\n family = { adjacency: new Map(), records: [] };\n families.set(key, family);\n }\n const targets = family.adjacency.get(oriented.from);\n if (targets === undefined)\n family.adjacency.set(oriented.from, new Set([oriented.to]));\n else targets.add(oriented.to);\n family.records.push({ ...oriented, edge });\n }\n return families;\n}\n\n/** Freeze one family's adjacency sets into deterministic sorted lists. */\nfunction sortedFamilyAdjacency(\n family: TransitiveFamily,\n): Map<string, readonly string[]> {\n const sorted = new Map<string, readonly string[]>();\n for (const [from, targets] of family.adjacency)\n sorted.set(from, [...targets].sort());\n return sorted;\n}\n\n/** Rebuild the witness node path from breadth-first parent pointers. */\nfunction reconstructWitness(\n parents: Map<string, string>,\n from: string,\n tail: string,\n head: string,\n): string[] {\n const witness = [head];\n for (let node = tail; node !== from; node = parents.get(node)!)\n witness.push(node);\n witness.push(from);\n return witness.reverse();\n}\n\n/** Expand one witness frontier node; return the completed witness when the head is reached. */\nfunction expandWitnessFrontier(\n adjacency: Map<string, readonly string[]>,\n record: OrientedTransitiveEdge,\n current: { id: string; depth: number },\n parents: Map<string, string>,\n queue: { id: string; depth: number }[],\n cost: { visitedNodes: number; inspectedEdges: number },\n): string[] | undefined {\n for (const next of adjacency.get(current.id) ?? []) {\n cost.inspectedEdges += 1;\n // Skip the direct edge under test; deeper hops may still reach the head.\n if (current.depth === 0 && next === record.to) continue;\n if (parents.has(next)) continue;\n parents.set(next, current.id);\n if (next === record.to)\n return reconstructWitness(parents, record.from, current.id, next);\n queue.push({ id: next, depth: current.depth + 1 });\n }\n return undefined;\n}\n\n/** Search one bounded same-family witness path that implies a direct edge. */\nfunction findWitnessPath(\n adjacency: Map<string, readonly string[]>,\n record: OrientedTransitiveEdge,\n maxDepth: number,\n cost: { visitedNodes: number; inspectedEdges: number },\n): string[] | undefined {\n const parents = new Map<string, string>([[record.from, record.from]]);\n const queue = [{ id: record.from, depth: 0 }];\n for (let index = 0; index < queue.length; index += 1) {\n const current = queue[index]!;\n cost.visitedNodes += 1;\n if (current.depth >= maxDepth) continue;\n const witness = expandWitnessFrontier(\n adjacency,\n record,\n current,\n parents,\n queue,\n cost,\n );\n if (witness !== undefined) return witness;\n }\n return undefined;\n}\n\n/**\n * Find stored edges implied by a longer path of the same semantic family —\n * the transitive-reduction view of ordering and hierarchy relations. Each\n * family joins a directed kind with its inverse spelling in semantic\n * orientation, so `blocked_by` and `blocks` witness each other. The witness\n * search is breadth-first, shortest and lexicographic first, bounded by\n * `maxDepth` per edge; `meta.truncated` reports only the `limit` bound.\n */\nexport function findRedundantRelationshipEdges(\n graph: RelationshipGraph,\n options: GraphRedundancyOptions = {},\n): RelationshipQueryResult<RedundantRelationshipEdge[]> {\n const maxDepth = options.maxDepth ?? DEFAULT_REDUNDANCY_MAX_DEPTH;\n assertPositiveBound(\"maxDepth\", maxDepth);\n if (options.limit !== undefined) assertPositiveBound(\"limit\", options.limit);\n const limit = options.limit ?? Number.POSITIVE_INFINITY;\n const wanted = resolveRedundancyFamilies(graph, options.kinds);\n const families = collectTransitiveFamilies(graph, wanted);\n const value: RedundantRelationshipEdge[] = [];\n const cost = { visitedNodes: 0, inspectedEdges: 0 };\n let truncated = false;\n scan: for (const key of [...families.keys()].sort()) {\n const family = families.get(key)!;\n const adjacency = sortedFamilyAdjacency(family);\n for (const record of family.records) {\n options.signal?.throwIfAborted();\n const witness = findWitnessPath(adjacency, record, maxDepth, cost);\n if (witness === undefined) continue;\n if (value.length >= limit) {\n truncated = true;\n break scan;\n }\n value.push({ edge: record.edge, witness });\n }\n }\n return {\n value,\n meta: {\n visitedNodes: cost.visitedNodes,\n inspectedEdges: cost.inspectedEdges,\n truncated,\n },\n };\n}\n\n/** Reachability index of one root's directed subgraph. */\ninterface ReachableSubgraph {\n /** Reachable node ids in breadth-first discovery order. */\n order: string[];\n /** Deterministic successor lists per reachable node. */\n successors: Map<string, string[]>;\n /** Reachable predecessor sets per reachable node. */\n predecessors: Map<string, Set<string>>;\n /** Candidate edges inspected while indexing. */\n inspectedEdges: number;\n /** Whether the depth bound excluded reachable nodes. */\n truncated: boolean;\n}\n\n/** Mutable frontier state threaded through bounded reachability expansion. */\ninterface ReachabilityState {\n /** Nodes already discovered. */\n seen: Set<string>;\n /** Pending breadth-first nodes and their depths. */\n queue: { id: string; depth: number }[];\n /** Reachable predecessor sets per discovered node. */\n predecessors: Map<string, Set<string>>;\n /** Whether the depth bound excluded reachable nodes. */\n truncated: boolean;\n}\n\n/** Expand one node's neighbor rows into successors, predecessors, and frontier work. */\nfunction expandReachableNode(\n id: string,\n depth: number,\n rows: readonly RelationshipNeighborEdge[],\n maxDepth: number,\n state: ReachabilityState,\n): string[] {\n const nextSet = new Set<string>();\n const nexts: string[] = [];\n for (const row of rows) {\n if (row.id === id || nextSet.has(row.id)) continue;\n if (!state.seen.has(row.id)) {\n // A depth-boundary node keeps its edges to already-indexed nodes but\n // may not discover new ones; excluded discoveries mark truncation.\n if (depth >= maxDepth) {\n state.truncated = true;\n continue;\n }\n state.seen.add(row.id);\n state.queue.push({ id: row.id, depth: depth + 1 });\n }\n nextSet.add(row.id);\n nexts.push(row.id);\n let incoming = state.predecessors.get(row.id);\n if (incoming === undefined) {\n incoming = new Set();\n state.predecessors.set(row.id, incoming);\n }\n incoming.add(id);\n }\n return nexts;\n}\n\n/** Index the bounded reachable subgraph used by dominator analysis. */\nfunction indexReachableSubgraph(\n graph: RelationshipGraph,\n root: string,\n options: GraphDominatorOptions,\n): ReachableSubgraph {\n const direction = options.direction ?? \"outgoing\";\n const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;\n const order: string[] = [];\n const successors = new Map<string, string[]>();\n const state: ReachabilityState = {\n seen: new Set([root]),\n queue: [{ id: root, depth: 0 }],\n predecessors: new Map(),\n truncated: false,\n };\n let inspectedEdges = 0;\n for (let index = 0; index < state.queue.length; index += 1) {\n options.signal?.throwIfAborted();\n const { id, depth } = state.queue[index]!;\n order.push(id);\n const rows = graph.neighborEdges(id, {\n direction,\n ...(options.kinds === undefined ? {} : { kinds: options.kinds }),\n });\n inspectedEdges += rows.meta.inspectedEdges;\n successors.set(id, expandReachableNode(id, depth, rows.value, maxDepth, state));\n }\n return {\n order,\n successors,\n predecessors: state.predecessors,\n inspectedEdges,\n truncated: state.truncated,\n };\n}\n\n/** Compute the deterministic reverse postorder of one reachable subgraph. */\nfunction reversePostorder(subgraph: ReachableSubgraph, root: string): string[] {\n const postorder: string[] = [];\n const visited = new Set([root]);\n const stack = [{ id: root, index: 0 }];\n while (stack.length > 0) {\n const frame = stack.at(-1)!;\n const nexts = subgraph.successors.get(frame.id)!;\n if (frame.index < nexts.length) {\n const next = nexts[frame.index]!;\n frame.index += 1;\n if (!visited.has(next)) {\n visited.add(next);\n stack.push({ id: next, index: 0 });\n }\n } else {\n postorder.push(frame.id);\n stack.pop();\n }\n }\n return postorder.reverse();\n}\n\n/** Walk two dominator-tree fingers to their common ancestor by reverse-postorder number. */\nfunction intersectDominators(\n left: string,\n right: string,\n idom: Map<string, string>,\n ordinal: Map<string, number>,\n): string {\n let first = left;\n let second = right;\n while (first !== second) {\n while (ordinal.get(first)! > ordinal.get(second)!) first = idom.get(first)!;\n while (ordinal.get(second)! > ordinal.get(first)!) second = idom.get(second)!;\n }\n return first;\n}\n\n/** Fold one node's processed predecessors into its dominator candidate. */\nfunction dominatorCandidate(\n predecessors: ReadonlySet<string>,\n idom: Map<string, string>,\n ordinal: Map<string, number>,\n): string | undefined {\n let candidate: string | undefined;\n for (const pred of [...predecessors].sort()) {\n if (!idom.has(pred)) continue;\n candidate =\n candidate === undefined\n ? pred\n : intersectDominators(candidate, pred, idom, ordinal);\n }\n return candidate;\n}\n\n/** Run the Cooper–Harvey–Kennedy fixed-point over one reverse postorder. */\nfunction solveImmediateDominators(\n subgraph: ReachableSubgraph,\n root: string,\n order: readonly string[],\n ordinal: Map<string, number>,\n signal: AbortSignal | undefined,\n): Map<string, string> {\n const idom = new Map<string, string>([[root, root]]);\n let changed = true;\n while (changed) {\n changed = false;\n for (const id of order) {\n signal?.throwIfAborted();\n if (id === root) continue;\n // Every non-root node in the order was discovered through at least one\n // predecessor, so the set is always present.\n const candidate = dominatorCandidate(\n subgraph.predecessors.get(id)!,\n idom,\n ordinal,\n );\n if (candidate !== undefined && idom.get(id) !== candidate) {\n idom.set(id, candidate);\n changed = true;\n }\n }\n }\n return idom;\n}\n\n/**\n * Compute immediate dominators and gating weights over one node's reachable\n * subgraph using the Cooper–Harvey–Kennedy fixed-point. A node dominates the\n * work that every path from the root must pass through it to reach, so rows\n * with a positive `dominatedCount` are the structural bottlenecks of the\n * root's blast radius. Rows sort by gating weight, then id; `meta.truncated`\n * reports when the `maxDepth` bound excluded reachable nodes.\n */\nexport function computeRelationshipDominators(\n graph: RelationshipGraph,\n root: string,\n options: GraphDominatorOptions = {},\n): RelationshipQueryResult<RelationshipDominatorAnalysis> {\n if (!graph.hasNode(root))\n throw new TypeError(`Relationship node not found: ${root}`);\n if (\n options.maxDepth !== undefined &&\n (!Number.isInteger(options.maxDepth) || options.maxDepth < 0)\n )\n throw new TypeError(`Invalid maxDepth bound: ${String(options.maxDepth)}`);\n const subgraph = indexReachableSubgraph(graph, root, options);\n const order = reversePostorder(subgraph, root);\n const ordinal = new Map(order.map((id, index) => [id, index]));\n const idom = solveImmediateDominators(\n subgraph,\n root,\n order,\n ordinal,\n options.signal,\n );\n const subtreeSizes = new Map(order.map((id) => [id, 1]));\n for (let index = order.length - 1; index >= 0; index -= 1) {\n const id = order[index]!;\n if (id === root) continue;\n const parent = idom.get(id)!;\n subtreeSizes.set(parent, subtreeSizes.get(parent)! + subtreeSizes.get(id)!);\n }\n const rows = order\n .filter((id) => id !== root)\n .map((id) => ({\n id,\n idom: idom.get(id)!,\n dominatedCount: subtreeSizes.get(id)! - 1,\n }))\n .sort(\n (left, right) =>\n right.dominatedCount - left.dominatedCount ||\n left.id.localeCompare(right.id),\n );\n return {\n value: { root, reachableCount: subgraph.order.length, rows },\n meta: {\n visitedNodes: subgraph.order.length,\n inspectedEdges: subgraph.inspectedEdges,\n truncated: subgraph.truncated,\n },\n };\n}\n", "/**\n * @module sdk/graph/governance\n *\n * Policy-aware relationship-graph quality audit shared by validation, health,\n * and package governance surfaces. The audit inspects one assembled workspace\n * graph and reports machine-readable findings — integrity gaps, ordering\n * cycles, duplicated edge spellings, stale lifecycle blocks, and coverage\n * outliers — without inventing edges or assuming that sparse connectivity is\n * defective. Findings gate severity on lifecycle: contradictions confined to\n * terminal items downgrade to informational `legacy_*` codes because repairing\n * them would mutate closed history. Every finding names the violated policy,\n * carries a deterministic bounded sample, and proposes a safe next action so\n * agents can plan remediation without re-deriving context.\n */\nimport type { RelationshipEdge } from \"../relationships.js\";\nimport {\n isTransitiveKind,\n orientTransitiveEdge,\n transitiveFamilyKey,\n} from \"./analytics.js\";\nimport type { WorkspaceRelationshipAssembly } from \"./assembly.js\";\n\n/** Severity ladder shared by every relationship audit finding. */\nexport type RelationshipAuditSeverity = \"error\" | \"warning\" | \"info\";\n\n/** Machine-readable identifier for one relationship audit finding family. */\nexport type RelationshipAuditFindingCode =\n | \"missing_reference_active\"\n | \"missing_reference_terminal\"\n | \"legacy_no_blocker_sentinel\"\n | \"ordering_cycle\"\n | \"legacy_ordering_cycle\"\n | \"duplicate_edge\"\n | \"legacy_duplicate_edge\"\n | \"duplicate_dependency_row\"\n | \"legacy_duplicate_dependency_row\"\n | \"stale_lifecycle_block\"\n | \"isolated_active_node\"\n | \"sparse_active_node\";\n\n/** One policy-aware relationship audit finding with bounded evidence. */\nexport interface RelationshipAuditFinding {\n /** Machine-readable finding family identifier. */\n code: RelationshipAuditFindingCode;\n /** Severity of the violated policy. */\n severity: RelationshipAuditSeverity;\n /** Policy statement this finding violates. */\n policy: string;\n /** Human-readable summary including the affected count. */\n message: string;\n /** Total number of affected subjects, independent of sample bounding. */\n count: number;\n /** Deterministic bounded sample of affected subjects. */\n sample: string[];\n /** Whether {@link sample} was truncated by the configured sample bound. */\n sample_truncated: boolean;\n /** Safe machine-actionable next step; audits never invent or auto-apply edges. */\n remediation: string;\n}\n\n/** Per-item-type connectivity coverage inside a coverage profile. */\nexport interface RelationshipCoverageTypeProfile {\n /** Active nodes declaring this item type. */\n active: number;\n /** Active nodes of this type with no incident edges. */\n isolated: number;\n /** Active nodes of this type with at most one incident edge, isolates included. */\n degree_leq_one: number;\n}\n\n/** Aggregate structural coverage metrics for one assembled workspace graph. */\nexport interface RelationshipCoverageProfile {\n /** Total indexed nodes including materialized missing placeholders. */\n nodes: number;\n /** Total deduplicated indexed edges. */\n edges: number;\n /** Deterministic per-kind edge counts. */\n edges_by_kind: Record<string, number>;\n /** Nodes whose lifecycle status is active (non-terminal, non-missing). */\n active_nodes: number;\n /** Materialized placeholder nodes for referenced-but-absent items. */\n missing_nodes: number;\n /** Active nodes with no incident edges at all. */\n isolated_active_nodes: number;\n /** Active nodes with at most one incident edge, isolates included. */\n degree_leq_one_active_nodes: number;\n /** Deterministic per-type connectivity coverage; untyped nodes bucket under `(untyped)`. */\n coverage_by_type: Record<string, RelationshipCoverageTypeProfile>;\n}\n\n/** Tuning and policy inputs accepted by the relationship audit. */\nexport interface RelationshipAuditOptions {\n /** Terminal-lifecycle predicate; defaults to the built-in closed/canceled statuses. */\n isTerminal?: (status: string) => boolean;\n /** Blocked-lifecycle predicate for stale-block detection; defaults to `status === \"blocked\"`. */\n isBlocked?: (status: string) => boolean;\n /** Node identifiers that are explicitly valid isolates (roots, archives, scratch work). */\n exemptIsolates?: readonly string[];\n /** Item types whose active nodes are policy-valid isolates or sparse nodes (case-insensitive); they stay in the coverage profile but raise no coverage finding. */\n isolateExemptTypes?: readonly string[];\n /** Maximum sample entries retained per finding; defaults to 25. */\n maxSampleSize?: number;\n /** Abort signal checked between finding families. */\n signal?: AbortSignal;\n}\n\n/** Complete deterministic result of one relationship-graph audit. */\nexport interface RelationshipAuditReport {\n /** Findings ordered by severity, then code, then first sample subject. */\n findings: RelationshipAuditFinding[];\n /** Structural coverage metrics computed during the audit. */\n profile: RelationshipCoverageProfile;\n}\n\n/** Default bounded sample size applied to every finding family. */\nconst DEFAULT_MAX_SAMPLE_SIZE = 25;\n\n/** Rank used to order findings by decreasing severity. */\nconst SEVERITY_RANK: Record<RelationshipAuditSeverity, number> = {\n error: 0,\n warning: 1,\n info: 2,\n};\n\n/** Internal per-node lifecycle classification resolved once per audit. */\ninterface AuditNodeState {\n /** Original-case node identifier. */\n id: string;\n /** Raw lifecycle status string from assembly details. */\n status: string;\n /** Whether the node is a materialized missing placeholder. */\n missing: boolean;\n /** Whether the node's lifecycle status is terminal. */\n terminal: boolean;\n /** Declared item type, when the assembly carried one. */\n type?: string;\n}\n\n/** Mutable state shared by iterative Tarjan frames. */\ninterface TarjanState {\n /** Discovery index assigned to each visited node. */\n indexes: Map<string, number>;\n /** Lowest reachable discovery index per visited node. */\n lowLinks: Map<string, number>;\n /** Nodes that still belong to an unfinished component. */\n onStack: Set<string>;\n /** Component-membership stack. */\n stack: string[];\n /** Completed cyclic components. */\n components: string[][];\n /** Discovery index assigned to the next unseen node. */\n nextIndex: number;\n}\n\n/** One explicit depth-first frame used by iterative Tarjan traversal. */\ninterface TarjanFrame {\n /** Node currently being expanded. */\n node: string;\n /** Index of the next successor to inspect. */\n neighborIndex: number;\n}\n\n/** Build one finding with deterministic bounded sampling over sorted subjects. */\nfunction buildFinding(\n code: RelationshipAuditFindingCode,\n severity: RelationshipAuditSeverity,\n policy: string,\n describe: (count: number) => string,\n subjects: readonly string[],\n maxSampleSize: number,\n remediation: string,\n): RelationshipAuditFinding {\n const sorted = [...subjects].sort((left, right) => left.localeCompare(right));\n return {\n code,\n severity,\n policy,\n message: describe(sorted.length),\n count: sorted.length,\n sample: sorted.slice(0, maxSampleSize),\n sample_truncated: sorted.length > maxSampleSize,\n remediation,\n };\n}\n/** Resolve the ordering-only successor adjacency for cycle analysis. */\nfunction buildOrderingAdjacency(\n assembly: WorkspaceRelationshipAssembly,\n): Map<string, string[]> {\n const registry = assembly.graph.registry();\n const successors = new Map<string, string[]>();\n for (const edge of assembly.graph.edges()) {\n const definition = registry.require(edge.kind);\n if (!definition.ordering) continue;\n // Orient every ordering edge predecessor -> successor so inverse spellings\n // (blocked_by/blocks) land in one canonical execution-order digraph.\n const [predecessor, successor] =\n (definition.precedence ?? \"source_before_target\") ===\n \"target_before_source\"\n ? [edge.target, edge.source]\n : [edge.source, edge.target];\n const adjacent = successors.get(predecessor);\n if (adjacent) adjacent.push(successor);\n else successors.set(predecessor, [successor]);\n }\n for (const adjacent of successors.values())\n adjacent.sort((left, right) => left.localeCompare(right));\n return successors;\n}\n\n/** Register one newly discovered Tarjan node. */\nfunction registerTarjanNode(node: string, state: TarjanState): void {\n state.indexes.set(node, state.nextIndex);\n state.lowLinks.set(node, state.nextIndex);\n state.nextIndex += 1;\n state.stack.push(node);\n state.onStack.add(node);\n}\n\n/** Visit one pending successor, returning whether the frame had work left. */\nfunction visitNextTarjanNeighbor(\n frame: TarjanFrame,\n frames: TarjanFrame[],\n successors: Map<string, string[]>,\n state: TarjanState,\n): boolean {\n const neighbors = successors.get(frame.node) ?? [];\n if (frame.neighborIndex >= neighbors.length) return false;\n const neighbor = neighbors[frame.neighborIndex]!;\n frame.neighborIndex += 1;\n if (!state.indexes.has(neighbor)) {\n registerTarjanNode(neighbor, state);\n frames.push({ node: neighbor, neighborIndex: 0 });\n } else if (state.onStack.has(neighbor)) {\n state.lowLinks.set(\n frame.node,\n Math.min(state.lowLinks.get(frame.node)!, state.indexes.get(neighbor)!),\n );\n }\n return true;\n}\n\n/** Complete one Tarjan frame and emit its component when it is a root. */\nfunction completeTarjanFrame(\n frame: TarjanFrame,\n frames: TarjanFrame[],\n successors: Map<string, string[]>,\n state: TarjanState,\n): void {\n frames.pop();\n const parent = frames.at(-1);\n if (parent)\n state.lowLinks.set(\n parent.node,\n Math.min(\n state.lowLinks.get(parent.node)!,\n state.lowLinks.get(frame.node)!,\n ),\n );\n if (state.lowLinks.get(frame.node) !== state.indexes.get(frame.node)) return;\n const component: string[] = [];\n while (true) {\n const member = state.stack.pop()!;\n state.onStack.delete(member);\n component.push(member);\n if (member === frame.node) break;\n }\n if (\n component.length > 1 ||\n (component.length === 1 &&\n successors.get(component[0]!)?.includes(component[0]!))\n )\n state.components.push(\n component.sort((left, right) => left.localeCompare(right)),\n );\n}\n\n/**\n * Enumerate strongly connected components with more than one member (or a\n * self-loop) over an ordering-only successor digraph using an iterative Tarjan\n * traversal. Only order-bearing kinds should participate: associative kinds\n * such as `related` cannot create execution-order contradictions and stay out\n * of cycle analysis by policy. Exported so incremental consumers (mutation\n * advisories) share one cycle semantics with the workspace audit.\n */\nexport function collectOrderingCycles(\n successors: Map<string, string[]>,\n): string[][] {\n const state: TarjanState = {\n indexes: new Map(),\n lowLinks: new Map(),\n onStack: new Set(),\n stack: [],\n components: [],\n nextIndex: 0,\n };\n const roots = [...successors.keys()].sort((left, right) =>\n left.localeCompare(right),\n );\n for (const root of roots) {\n if (state.indexes.has(root)) continue;\n // Explicit frame stack keeps the traversal safe on deep dependency chains.\n const frames: TarjanFrame[] = [{ node: root, neighborIndex: 0 }];\n registerTarjanNode(root, state);\n while (frames.length > 0) {\n const frame = frames.at(-1)!;\n if (visitNextTarjanNeighbor(frame, frames, successors, state)) continue;\n completeTarjanFrame(frame, frames, successors, state);\n }\n }\n return state.components.sort((left, right) =>\n left[0]!.localeCompare(right[0]!),\n );\n}\n\n/** Format one dangling reference as a compact deterministic evidence string. */\nfunction formatDanglingReference(reference: {\n holder_id: string;\n target_id: string;\n kind: string;\n}): string {\n return `${reference.holder_id} -> ${reference.target_id} (${reference.kind})`;\n}\n\n/** Append one finding only when its subject collection is non-empty. */\nfunction appendFinding(\n findings: RelationshipAuditFinding[],\n subjects: readonly string[],\n maxSampleSize: number,\n code: RelationshipAuditFindingCode,\n severity: RelationshipAuditSeverity,\n policy: string,\n describe: (count: number) => string,\n remediation: string,\n): void {\n if (subjects.length === 0) return;\n findings.push(\n buildFinding(\n code,\n severity,\n policy,\n describe,\n subjects,\n maxSampleSize,\n remediation,\n ),\n );\n}\n\n/** Collect dangling-reference and retired-sentinel governance findings. */\nfunction collectIntegrityFindings(\n assembly: WorkspaceRelationshipAssembly,\n isTerminal: (status: string) => boolean,\n maxSampleSize: number,\n): RelationshipAuditFinding[] {\n const findings: RelationshipAuditFinding[] = [];\n const references = [\n ...assembly.dangling.active,\n ...assembly.dangling.legacy_terminal,\n ].filter((reference) => !reference.no_active_blocker_sentinel);\n appendFinding(\n findings,\n references\n .filter((reference) => !isTerminal(reference.holder_status))\n .map(formatDanglingReference),\n maxSampleSize,\n \"missing_reference_active\",\n \"error\",\n \"Active items must not reference absent targets; missing prerequisites distort scheduling.\",\n (count) => `${count} active dangling reference(s) to absent items`,\n \"Restore or re-create the referenced item, or remove/retype the reference on the holder.\",\n );\n appendFinding(\n findings,\n references\n .filter((reference) => isTerminal(reference.holder_status))\n .map(formatDanglingReference),\n maxSampleSize,\n \"missing_reference_terminal\",\n \"info\",\n \"Terminal items may retain historical references, but absent targets remain unexplainable context.\",\n (count) => `${count} terminal dangling reference(s) to absent items`,\n \"Leave as history debt or clean up in a dedicated changelog-safe closed-item batch.\",\n );\n appendFinding(\n findings,\n assembly.dangling.no_active_blocker_sentinels.map(formatDanglingReference),\n maxSampleSize,\n \"legacy_no_blocker_sentinel\",\n \"info\",\n \"The pre-structured-dependency no-active-blocker sentinel is retired; real edges carry blocker state.\",\n (count) => `${count} legacy no-active-blocker sentinel reference(s)`,\n \"Delete the sentinel reference; blocker state is derived from blocked_by edges.\",\n );\n return findings;\n}\n\n/** Decide whether one audited node still participates in active scheduling. */\nfunction isActiveAuditMember(\n member: string,\n nodeStates: Map<string, AuditNodeState>,\n): boolean {\n const state = nodeStates.get(member);\n // A trimmed or custom assembly may omit a member's details. Treat that\n // unknown lifecycle conservatively as active so contradictions are never\n // silently downgraded to legacy history debt.\n if (!state) return true;\n return !state.terminal;\n}\n\n/** Collect ordering-cycle and lifecycle-block governance findings. */\nfunction collectOrderingFindings(\n assembly: WorkspaceRelationshipAssembly,\n nodeStates: Map<string, AuditNodeState>,\n isBlocked: (status: string) => boolean,\n maxSampleSize: number,\n): RelationshipAuditFinding[] {\n const findings: RelationshipAuditFinding[] = [];\n const orderingAdjacency = buildOrderingAdjacency(assembly);\n for (const cycle of collectOrderingCycles(orderingAdjacency)) {\n // A cycle whose members are all terminal is a historical contradiction:\n // it cannot make live work unschedulable, and \"repairing\" it would touch\n // closed items (changelog drag), so it downgrades to informational debt.\n const active = cycle.some((member) =>\n isActiveAuditMember(member, nodeStates),\n );\n findings.push(\n active\n ? buildFinding(\n \"ordering_cycle\",\n \"error\",\n \"Order-bearing relationship kinds must stay acyclic; a cycle makes every member unschedulable.\",\n (count) => `execution-order cycle across ${count} item(s)`,\n cycle,\n maxSampleSize,\n \"Remove or retype one ordering edge inside the cycle, or split the work so precedence is linear.\",\n )\n : buildFinding(\n \"legacy_ordering_cycle\",\n \"info\",\n \"Ordering cycles between exclusively terminal items are historical contradictions with no scheduling effect.\",\n (count) =>\n `terminal-only execution-order cycle across ${count} item(s)`,\n cycle,\n maxSampleSize,\n \"Leave as history debt, or clean up in a dedicated changelog-safe closed-item batch; never repair closed items ad hoc.\",\n ),\n );\n }\n const predecessorsByNode = new Map<string, string[]>();\n for (const [predecessor, adjacent] of orderingAdjacency)\n for (const successor of adjacent) {\n const predecessors = predecessorsByNode.get(successor);\n if (predecessors) predecessors.push(predecessor);\n else predecessorsByNode.set(successor, [predecessor]);\n }\n const staleLifecycleBlocks = [...nodeStates.values()]\n .filter(\n (state) =>\n !state.missing &&\n !state.terminal &&\n isBlocked(state.status) &&\n !(predecessorsByNode.get(state.id) ?? []).some((predecessor) => {\n const predecessorState = nodeStates.get(predecessor);\n // A trimmed/custom assembly may omit predecessor details. Treat that\n // unknown state conservatively as potentially open instead of\n // falsely declaring the lifecycle block stale.\n return predecessorState === undefined || !predecessorState.terminal;\n }),\n )\n .map((state) => state.id);\n appendFinding(\n findings,\n staleLifecycleBlocks,\n maxSampleSize,\n \"stale_lifecycle_block\",\n \"warning\",\n \"A blocked lifecycle status must be backed by at least one open ordering predecessor.\",\n (count) => `${count} status-blocked item(s) with no open blocker edge`,\n \"Re-open the missing prerequisite as an edge, or move the item back to an active status.\",\n );\n return findings;\n}\n\n/** One duplicate-edge group in semantic orientation with its stored spellings. */\nexport interface DuplicateRelationshipEdgeGroup {\n /** Semantic tail node shared by every stored spelling. */\n from: string;\n /** Semantic head node shared by every stored spelling. */\n to: string;\n /** Stored parallel edges sorted by kind. */\n edges: RelationshipEdge[];\n}\n\n/** Format one duplicate-edge group as a compact deterministic evidence string. */\nexport function formatDuplicateEdgeGroup(\n group: DuplicateRelationshipEdgeGroup,\n): string {\n const kinds = group.edges\n .map((edge) => edge.kind)\n .sort((left, right) => left.localeCompare(right));\n return `${group.from} -> ${group.to} (${kinds.join(\" + \")})`;\n}\n\n/**\n * Collect the groups of parallel same-family stored edges over the directed\n * ordering and hierarchy families. Each family joins a kind with its inverse\n * spelling in semantic orientation, so a reciprocal pair such as\n * `A blocked_by B` plus `B blocks A` collapses onto one oriented endpoint\n * pair. Only groups holding at least two stored spellings are returned, in\n * deterministic orientation order with per-group edges sorted by kind, source,\n * then target — the exact stored identities remediation planning targets.\n */\nexport function collectDuplicateRelationshipEdgeGroups(\n assembly: WorkspaceRelationshipAssembly,\n): DuplicateRelationshipEdgeGroup[] {\n const registry = assembly.graph.registry();\n const groups = new Map<string, DuplicateRelationshipEdgeGroup>();\n for (const edge of assembly.graph.edges()) {\n const definition = registry.require(edge.kind);\n if (!isTransitiveKind(definition)) continue;\n const oriented = orientTransitiveEdge(edge, definition);\n if (oriented.from === oriented.to) continue;\n const key = `${transitiveFamilyKey(definition)}::${oriented.from}::${oriented.to}`;\n const group = groups.get(key);\n if (group) group.edges.push(edge);\n else groups.set(key, { ...oriented, edges: [edge] });\n }\n const duplicated = [...groups.values()].filter(\n (group) => group.edges.length >= 2,\n );\n // Within one oriented group every stored spelling has a distinct kind: a\n // same-kind restatement of the same oriented pair would carry identical\n // endpoints and is deduplicated by edge identity during graph construction.\n for (const group of duplicated)\n group.edges.sort((left, right) => left.kind.localeCompare(right.kind));\n return duplicated.sort(\n (left, right) =>\n left.from.localeCompare(right.from) || left.to.localeCompare(right.to),\n );\n}\n\n/**\n * Collect duplicate stored-edge findings from the oriented duplicate groups.\n * Transitive-reduction redundancy analysis deliberately skips the direct edge\n * under test, so these exact parallels are invisible there and this is the\n * only surface that reports them.\n */\nfunction collectDuplicateEdgeFindings(\n assembly: WorkspaceRelationshipAssembly,\n nodeStates: Map<string, AuditNodeState>,\n maxSampleSize: number,\n): RelationshipAuditFinding[] {\n const active: string[] = [];\n const legacy: string[] = [];\n for (const group of collectDuplicateRelationshipEdgeGroups(assembly)) {\n const subjects =\n isActiveAuditMember(group.from, nodeStates) ||\n isActiveAuditMember(group.to, nodeStates)\n ? active\n : legacy;\n subjects.push(formatDuplicateEdgeGroup(group));\n }\n const findings: RelationshipAuditFinding[] = [];\n appendFinding(\n findings,\n active,\n maxSampleSize,\n \"duplicate_edge\",\n \"info\",\n \"One semantic relationship should be stored once; parallel same-family spellings (reciprocal inverse pairs included) add no information and skew degree metrics.\",\n (count) => `${count} duplicated relationship(s) between active endpoints`,\n \"Remove all but one stored spelling of the relationship; keep the canonical direction the holder declared first.\",\n );\n appendFinding(\n findings,\n legacy,\n maxSampleSize,\n \"legacy_duplicate_edge\",\n \"info\",\n \"Duplicated spellings between exclusively terminal items are historical noise with no scheduling effect.\",\n (count) => `${count} duplicated relationship(s) between terminal endpoints`,\n \"Leave as history debt or clean up in a dedicated changelog-safe closed-item batch.\",\n );\n return findings;\n}\n\n/**\n * Collect storage-integrity findings for raw dependency rows whose exact\n * identity is stored more than once on one holder. Graph edge-identity dedup\n * hides these from every assembled-graph surface (duplicate_edge only covers\n * cross-spelling parallels), so the audit reports them from the pre-assembly\n * scan carried on the assembly.\n */\nfunction collectDuplicateRowFindings(\n assembly: WorkspaceRelationshipAssembly,\n maxSampleSize: number,\n): RelationshipAuditFinding[] {\n const active: string[] = [];\n const legacy: string[] = [];\n // Public/JSON-parsed assemblies produced before duplicate-row governance may omit this field.\n for (const row of assembly.duplicateRows ?? []) {\n (row.legacy_terminal ? legacy : active).push(\n `${row.holder_id} -> ${row.target_id} (${row.kind} x${row.occurrences})`,\n );\n }\n const findings: RelationshipAuditFinding[] = [];\n appendFinding(\n findings,\n active,\n maxSampleSize,\n \"duplicate_dependency_row\",\n \"warning\",\n \"One dependency row must be stored once per holder; identical repeated rows are a storage-layer defect invisible to the assembled graph.\",\n (count) =>\n `${count} exactly duplicated stored dependency row(s) on active holder(s)`,\n \"Remove the repeated rows so the dependency is stored exactly once; graph semantics are unchanged.\",\n );\n appendFinding(\n findings,\n legacy,\n maxSampleSize,\n \"legacy_duplicate_dependency_row\",\n \"info\",\n \"Identical repeated dependency rows on terminal holders are historical storage noise with no scheduling effect.\",\n (count) =>\n `${count} exactly duplicated stored dependency row(s) on terminal holder(s)`,\n \"Leave as history debt or clean up in a dedicated changelog-safe closed-item batch.\",\n );\n return findings;\n}\n\n/** Compute structural coverage metrics and coverage-policy findings. */\n/** Mutable coverage tallies accumulated across active graph nodes. */\ninterface CoverageTallies {\n /** Active node count. */\n active: number;\n /** Missing placeholder count. */\n missing: number;\n /** Isolated active node count. */\n isolated: number;\n /** Degree-at-most-one active node count, isolates included. */\n degreeLeqOne: number;\n /** Non-exempt isolate finding subjects. */\n isolates: string[];\n /** Non-exempt single-edge finding subjects. */\n sparse: string[];\n /** Per-type connectivity tallies. */\n byType: Map<string, RelationshipCoverageTypeProfile>;\n}\n\n/** Fold one active node's degree into the aggregate and per-type coverage tallies. */\nfunction tallyActiveCoverageNode(\n tallies: CoverageTallies,\n state: AuditNodeState,\n degree: number,\n exemptIsolates: Set<string>,\n isolateExemptTypes: Set<string>,\n): void {\n tallies.active += 1;\n const typeKey = state.type ?? \"(untyped)\";\n let typeProfile = tallies.byType.get(typeKey);\n if (!typeProfile) {\n typeProfile = { active: 0, isolated: 0, degree_leq_one: 0 };\n tallies.byType.set(typeKey, typeProfile);\n }\n typeProfile.active += 1;\n if (degree > 1) return;\n tallies.degreeLeqOne += 1;\n typeProfile.degree_leq_one += 1;\n if (degree === 0) {\n tallies.isolated += 1;\n typeProfile.isolated += 1;\n }\n if (\n exemptIsolates.has(state.id.toLowerCase()) ||\n isolateExemptTypes.has(typeKey.toLowerCase())\n )\n return;\n if (degree === 0) tallies.isolates.push(state.id);\n else tallies.sparse.push(state.id);\n}\n\nfunction collectCoverageReport(\n assembly: WorkspaceRelationshipAssembly,\n nodeStates: Map<string, AuditNodeState>,\n exemptIsolates: Set<string>,\n isolateExemptTypes: Set<string>,\n maxSampleSize: number,\n edgesByKind: Record<string, number>,\n): RelationshipAuditReport {\n const tallies: CoverageTallies = {\n active: 0,\n missing: 0,\n isolated: 0,\n degreeLeqOne: 0,\n isolates: [],\n sparse: [],\n byType: new Map(),\n };\n for (const id of assembly.graph.nodes()) {\n const state = nodeStates.get(id);\n /* c8 ignore next -- every graph node originates from assembly details by construction */\n if (!state) continue;\n if (state.missing) {\n tallies.missing += 1;\n continue;\n }\n if (state.terminal) continue;\n tallyActiveCoverageNode(\n tallies,\n state,\n assembly.graph.incidentEdges(id).length,\n exemptIsolates,\n isolateExemptTypes,\n );\n }\n const { isolates, sparse } = tallies;\n const findings: RelationshipAuditFinding[] = [];\n appendFinding(\n findings,\n isolates,\n maxSampleSize,\n \"isolated_active_node\",\n \"warning\",\n \"Active work should be reachable from the graph unless explicitly declared a valid isolate.\",\n (count) => `${count} active item(s) with no relationships`,\n \"Link the item to its parent, prerequisite, or origin — or register it as an exempt isolate.\",\n );\n appendFinding(\n findings,\n sparse,\n maxSampleSize,\n \"sparse_active_node\",\n \"info\",\n \"Active items with a single edge often miss an honest semantic partner; sparse is not automatically defective.\",\n (count) => `${count} active item(s) with exactly one relationship`,\n \"Investigate for an honest second edge (story->task, defect family, cross-epic complement); do not fabricate one.\",\n );\n return {\n findings,\n profile: {\n nodes: assembly.graph.nodes().length,\n edges: assembly.graph.edges().length,\n edges_by_kind: Object.fromEntries(\n Object.entries(edgesByKind).sort(([left], [right]) =>\n left.localeCompare(right),\n ),\n ),\n active_nodes: tallies.active,\n missing_nodes: tallies.missing,\n isolated_active_nodes: tallies.isolated,\n degree_leq_one_active_nodes: tallies.degreeLeqOne,\n coverage_by_type: Object.fromEntries(\n [...tallies.byType.entries()].sort(([left], [right]) =>\n left < right ? -1 : 1,\n ),\n ),\n },\n };\n}\n\n/**\n * Audit one assembled workspace relationship graph against the shared\n * governance policy and return deterministic machine-readable findings plus a\n * structural coverage profile.\n *\n * The audit is read-only and never proposes inventing an edge: integrity\n * findings report evidence for investigation, coverage findings honor explicit\n * isolate exemptions, and cycle findings enumerate the strongly connected\n * members so callers can decide which edge to retype, remove, or waive.\n */\nexport function auditWorkspaceRelationshipGraph(\n assembly: WorkspaceRelationshipAssembly,\n options: RelationshipAuditOptions = {},\n): RelationshipAuditReport {\n const isTerminal =\n options.isTerminal ??\n ((status: string) => status === \"closed\" || status === \"canceled\");\n const isBlocked =\n options.isBlocked ?? ((status: string) => status === \"blocked\");\n const maxSampleSize = options.maxSampleSize ?? DEFAULT_MAX_SAMPLE_SIZE;\n if (!Number.isInteger(maxSampleSize) || maxSampleSize < 1)\n throw new TypeError(\n `Invalid audit sample bound: ${String(options.maxSampleSize)}`,\n );\n const exemptIsolates = new Set(\n (options.exemptIsolates ?? [])\n .filter((id): id is string => typeof id === \"string\")\n .map((id) => id.trim().toLowerCase()),\n );\n const isolateExemptTypes = new Set(\n (options.isolateExemptTypes ?? [])\n .filter((type): type is string => typeof type === \"string\")\n .map((type) => type.trim().toLowerCase()),\n );\n const nodeStates = new Map<string, AuditNodeState>(\n assembly.details.map((detail) => [\n detail.id,\n {\n id: detail.id,\n status: detail.status,\n missing: assembly.missingIdSet.has(detail.id.toLowerCase()),\n terminal: isTerminal(detail.status),\n ...(detail.type === undefined ? {} : { type: detail.type }),\n },\n ]),\n );\n options.signal?.throwIfAborted();\n\n const edgesByKind: Record<string, number> = {};\n for (const edge of assembly.graph.edges())\n edgesByKind[edge.kind] = (edgesByKind[edge.kind] ?? 0) + 1;\n const findings = collectIntegrityFindings(\n assembly,\n isTerminal,\n maxSampleSize,\n );\n options.signal?.throwIfAborted();\n findings.push(\n ...collectOrderingFindings(assembly, nodeStates, isBlocked, maxSampleSize),\n );\n options.signal?.throwIfAborted();\n findings.push(\n ...collectDuplicateEdgeFindings(assembly, nodeStates, maxSampleSize),\n ...collectDuplicateRowFindings(assembly, maxSampleSize),\n );\n options.signal?.throwIfAborted();\n const coverage = collectCoverageReport(\n assembly,\n nodeStates,\n exemptIsolates,\n isolateExemptTypes,\n maxSampleSize,\n edgesByKind,\n );\n findings.push(...coverage.findings);\n\n findings.sort(\n (left, right) =>\n SEVERITY_RANK[left.severity] - SEVERITY_RANK[right.severity] ||\n left.code.localeCompare(right.code) ||\n left.sample[0]!.localeCompare(right.sample[0]!),\n );\n return {\n findings,\n profile: coverage.profile,\n };\n}\n\n/** One persisted point-in-time audit census used for temporal comparison. */\nexport interface RelationshipAuditSnapshot {\n /** ISO timestamp the snapshot was taken at. */\n saved_at: string;\n /** Workspace graph fingerprint of the audited item snapshot. */\n fingerprint: string;\n /** Affected-subject counts keyed by finding code at snapshot time. */\n affected_subjects_by_code: Record<string, number>;\n /** Structural coverage profile at snapshot time. */\n profile: RelationshipCoverageProfile;\n}\n\n/** Signed change between two audit snapshots; zero-change keys are dropped. */\nexport interface RelationshipAuditDelta {\n /** ISO timestamp of the baseline snapshot the delta is measured against. */\n baseline_saved_at: string;\n /** Whether both snapshots audited the identical workspace fingerprint. */\n same_snapshot: boolean;\n /** Signed affected-subject deltas keyed by finding code. */\n affected_subjects_by_code: Record<string, number>;\n /** Signed structural profile deltas. */\n profile: {\n /** Node-count change including missing placeholders. */\n nodes: number;\n /** Deduplicated edge-count change. */\n edges: number;\n /** Active-node-count change. */\n active_nodes: number;\n /** Missing-placeholder-count change. */\n missing_nodes: number;\n /** Isolated-active-node-count change. */\n isolated_active_nodes: number;\n /** Degree-at-most-one active-node-count change. */\n degree_leq_one_active_nodes: number;\n /** Signed per-kind edge-count deltas; unchanged kinds are dropped. */\n edges_by_kind: Record<string, number>;\n /** Signed per-type coverage deltas; unchanged types are dropped. */\n coverage_by_type: Record<string, RelationshipCoverageTypeProfile>;\n };\n}\n\n/** Subtract two count records, keeping only non-zero signed deltas in sorted key order. */\nfunction diffCountRecords(\n baseline: Record<string, number>,\n current: Record<string, number>,\n): Record<string, number> {\n const keys = [\n ...new Set([...Object.keys(baseline), ...Object.keys(current)]),\n ].sort();\n const deltas: Record<string, number> = {};\n for (const key of keys) {\n const delta = (current[key] ?? 0) - (baseline[key] ?? 0);\n if (delta !== 0) deltas[key] = delta;\n }\n return deltas;\n}\n\n/** Read per-type coverage defensively from current or legacy runtime snapshots. */\nfunction readSnapshotCoverageByType(\n snapshot: RelationshipAuditSnapshot,\n): Record<string, RelationshipCoverageTypeProfile> {\n return snapshot.profile.coverage_by_type ?? {};\n}\n\n/**\n * Compare two point-in-time audit snapshots and return the signed change in\n * findings and structural coverage. This is the temporal primitive behind\n * change-since-baseline audit reporting: agents track census drift across\n * sessions without re-deriving or storing full finding collections.\n */\nexport function diffRelationshipAuditSnapshots(\n baseline: RelationshipAuditSnapshot,\n current: RelationshipAuditSnapshot,\n): RelationshipAuditDelta {\n const coverageByType: Record<string, RelationshipCoverageTypeProfile> = {};\n // Public SDK callers may compare legacy or JSON-decoded snapshots created\n // before per-type coverage was added, even though current typed snapshots\n // always carry this field.\n const baselineCoverageByType = readSnapshotCoverageByType(baseline);\n const currentCoverageByType = readSnapshotCoverageByType(current);\n const typeKeys = [\n ...new Set([\n ...Object.keys(baselineCoverageByType),\n ...Object.keys(currentCoverageByType),\n ]),\n ].sort();\n for (const type of typeKeys) {\n const before = baselineCoverageByType[type];\n const after = currentCoverageByType[type];\n const delta = {\n active: (after?.active ?? 0) - (before?.active ?? 0),\n isolated: (after?.isolated ?? 0) - (before?.isolated ?? 0),\n degree_leq_one:\n (after?.degree_leq_one ?? 0) - (before?.degree_leq_one ?? 0),\n };\n if (Object.values(delta).some((value) => value !== 0))\n coverageByType[type] = delta;\n }\n return {\n baseline_saved_at: baseline.saved_at,\n same_snapshot: baseline.fingerprint === current.fingerprint,\n affected_subjects_by_code: diffCountRecords(\n baseline.affected_subjects_by_code,\n current.affected_subjects_by_code,\n ),\n profile: {\n nodes: current.profile.nodes - baseline.profile.nodes,\n edges: current.profile.edges - baseline.profile.edges,\n active_nodes:\n current.profile.active_nodes - baseline.profile.active_nodes,\n missing_nodes:\n current.profile.missing_nodes - baseline.profile.missing_nodes,\n isolated_active_nodes:\n current.profile.isolated_active_nodes -\n baseline.profile.isolated_active_nodes,\n degree_leq_one_active_nodes:\n current.profile.degree_leq_one_active_nodes -\n baseline.profile.degree_leq_one_active_nodes,\n edges_by_kind: diffCountRecords(\n baseline.profile.edges_by_kind,\n current.profile.edges_by_kind,\n ),\n coverage_by_type: coverageByType,\n },\n };\n}\n"],
5
+ "mappings": ";;;;;;;;AAwDA,IAAM,oBAAoB;AAE1B,IAAM,4BAA4B;AAElC,IAAM,yBAAyB;AAG/B,SAAS,gBAAgB,MAAc,OAAa;AAClD,MAAI,CAAC,OAAO,SAAS,KAAK,KAAK,CAAC,OAAO,UAAU,KAAK,KAAK,QAAQ;AACjE,UAAM,IAAI,UAAU,gBAAgB,IAAI,WAAW,OAAO,KAAK,CAAC,EAAE;AACtE;AAGM,SAAU,wBACd,MACA,YAAsC;AAItC,SAAO,WAAW,uBAAuB,kBACrC,KAAK,SACL,KAAK;A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e,IAAI,IAAI;EAC3B;AACA,SAAO;IACL,mBAAmB,SAAS;IAC5B,eAAe,SAAS,gBAAgB,QAAQ;IAChD,2BAA2B,iBACzB,SAAS,2BACT,QAAQ,yBAAyB;IAEnC,SAAS;MACP,OAAO,QAAQ,QAAQ,QAAQ,SAAS,QAAQ;MAChD,OAAO,QAAQ,QAAQ,QAAQ,SAAS,QAAQ;MAChD,cACE,QAAQ,QAAQ,eAAe,SAAS,QAAQ;MAClD,eACE,QAAQ,QAAQ,gBAAgB,SAAS,QAAQ;MACnD,uBACE,QAAQ,QAAQ,wBAChB,SAAS,QAAQ;MACnB,6BACE,QAAQ,QAAQ,8BAChB,SAAS,QAAQ;MACnB,eAAe,iBACb,SAAS,QAAQ,eACjB,QAAQ,QAAQ,aAAa;MAE/B,kBAAkB;;;AAGxB;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  renameArtifactsResultKey,
3
3
  runLinkedArtifacts
4
- } from "./chunk-RJO3YAFM.js";
4
+ } from "./chunk-OCUBRA6D.js";
5
5
 
6
6
  // dist/sdk/docs.js
7
7
  !(function() {
@@ -24,4 +24,4 @@ async function runDocs(id, options, global2) {
24
24
  export {
25
25
  runDocs
26
26
  };
27
- //# sourceMappingURL=chunk-UX6SSO2I.js.map
27
+ //# sourceMappingURL=chunk-PZC2FUOQ.js.map
@@ -4,13 +4,11 @@ import {
4
4
  extractPatchFailureContext,
5
5
  readHistoryEntries,
6
6
  replayHistoryToTarget,
7
- resolveHistoryTarget
8
- } from "./chunk-C3KD7U3T.js";
9
- import {
10
7
  replayToCanonicalItemDocument,
11
8
  replayToItemDocument,
9
+ resolveHistoryTarget,
12
10
  toReplayDocument
13
- } from "./chunk-E6LEMURX.js";
11
+ } from "./chunk-2L6ZP22J.js";
14
12
  import {
15
13
  resolveAuthor
16
14
  } from "./chunk-YRYYFGV3.js";
@@ -317,4 +315,4 @@ export {
317
315
  runRestore,
318
316
  _testOnlyRestoreCommand
319
317
  };
320
- //# sourceMappingURL=chunk-WUVEBQW6.js.map
318
+ //# sourceMappingURL=chunk-QG4GFLQ6.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../../cli/commands/restore.ts"],
4
4
  "sourcesContent": ["/**\n * @module cli/commands/restore\n *\n * Implements the pm restore command surface and its agent-facing runtime behavior.\n */\nimport jsonPatch from \"fast-json-patch\";\nimport fs from \"node:fs/promises\";\nimport {\n pathExists,\n readFileIfExists,\n writeFileAtomic,\n} from \"../../core/fs/fs-utils.js\";\nimport {\n appendHistoryEntry,\n createHistoryEntry,\n} from \"../../core/history/history.js\";\nimport {\n replayToCanonicalItemDocument,\n replayToItemDocument,\n toReplayDocument,\n} from \"../../core/history/replay.js\";\nimport {\n applyHistoryPatch,\n ensureMaterializedHistoryTarget as ensureMaterializedRestoreTarget,\n extractPatchFailureContext,\n readHistoryEntries,\n replayHistoryToTarget as replayToTarget,\n resolveHistoryTarget,\n} from \"../../sdk/history-read.js\";\nimport { enforceHistoryStreamPolicyForItem } from \"../../core/history/history-stream-policy.js\";\nimport { normalizeItemId, normalizeRawItemId } from \"../../core/item/id.js\";\nimport {\n canonicalDocument,\n serializeItemDocument,\n} from \"../../core/item/item-format.js\";\nimport { resolveItemTypeRegistry } from \"../../core/item/type-registry.js\";\nimport { acquireLock } from \"../../core/lock/lock.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 {\n getActiveExtensionRegistrations,\n projectAfterCommandItemSnapshot,\n recordAfterCommandAffectedItem,\n runActiveOnWriteHooks,\n} from \"../../core/extensions/index.js\";\nimport { locateItem, readLocatedItem } from \"../../core/store/item-store.js\";\nimport {\n getHistoryPath,\n getItemPath,\n getSettingsPath,\n resolvePmRoot,\n} from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport { resolveAuthor } from \"../../core/shared/author.js\";\nimport type {\n HistoryEntry,\n HistoryPatchOp,\n ItemDocument,\n ItemMetadata,\n} from \"../../types/index.js\";\n\ninterface ResolvedRestoreSubject {\n id: string;\n historyPath: string;\n located: Awaited<ReturnType<typeof locateItem>>;\n historyPolicyWarnings: string[];\n}\n\ninterface RestoreCurrentState {\n document: ItemDocument;\n originalRaw: string | null;\n}\n\n/** Documents the restore command options payload exchanged by command, SDK, and package integrations. */\nexport interface RestoreCommandOptions {\n /** Value that configures or reports author for this contract. */\n author?: string;\n /** Human-readable explanation suitable for logs and agent-facing output. */\n message?: string;\n /** Value that configures or reports force for this contract. */\n force?: boolean;\n}\n\n/** Documents the restore result payload exchanged by command, SDK, and package integrations. */\nexport interface RestoreResult {\n /** Value that configures or reports item for this contract. */\n item: ItemMetadata;\n /** Value that configures or reports restored from for this contract. */\n restored_from: {\n kind: \"version\" | \"timestamp\";\n target: string;\n history_index: number;\n entry_ts: string;\n entry_op: string;\n };\n /** Value that configures or reports changed fields for this contract. */\n changed_fields: string[];\n /** Value that configures or reports warnings for this contract. */\n warnings: string[];\n}\n\n/** Resolve restore targets with the command's established wording and at-or-before timestamp semantics. */\nfunction ensureReplayTarget(target: string, history: readonly HistoryEntry[]) {\n return resolveHistoryTarget(target, history, {\n errorSubject: \"restore\",\n allowFutureTimestamp: true,\n });\n}\n\nfunction replayCurrentDocument(history: HistoryEntry[]): ItemDocument {\n const currentReplay = replayToTarget(history, history.length - 1);\n if (Object.keys(currentReplay.metadata).length === 0) {\n return {\n metadata: {} as ItemMetadata,\n body: currentReplay.body,\n };\n }\n return canonicalDocument(replayToItemDocument(currentReplay));\n}\n\nasync function resolveRestoreSubject(\n pmRoot: string,\n id: string,\n settings: Awaited<ReturnType<typeof readSettings>>,\n typeToFolder: Record<string, string>,\n): Promise<ResolvedRestoreSubject> {\n const located = await locateItem(\n pmRoot,\n id,\n settings.id_prefix,\n settings.item_format,\n typeToFolder,\n );\n if (located) {\n const historyPath = getHistoryPath(pmRoot, located.id);\n const historyPolicy = await enforceHistoryStreamPolicyForItem({\n pmRoot,\n settings,\n itemId: located.id,\n commandLabel: \"restore\",\n });\n return {\n id: located.id,\n historyPath,\n located,\n historyPolicyWarnings: historyPolicy.warnings,\n };\n }\n\n const normalizedId = normalizeItemId(id, settings.id_prefix);\n const rawNormalizedId = normalizeRawItemId(id);\n /* c8 ignore start -- raw-id fallback is covered by normalize-item-id utility tests. */\n const candidateIds =\n normalizedId === rawNormalizedId\n ? [normalizedId]\n : [normalizedId, rawNormalizedId];\n /* c8 ignore stop */\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 historyPolicyWarnings: [],\n };\n }\n }\n\n throw new PmCliError(`Item ${id} not found`, EXIT_CODE.NOT_FOUND);\n}\n\nfunction changedFields(\n beforeDocument: ItemDocument,\n afterDocument: ItemDocument,\n): string[] {\n const beforeReplay = toReplayDocument(beforeDocument);\n const afterReplay = toReplayDocument(afterDocument);\n const patch = jsonPatch.compare(\n beforeReplay,\n afterReplay,\n ) as HistoryPatchOp[];\n const fields = new Set<string>();\n\n for (const op of patch) {\n if (op.path === \"/body\" || op.path.startsWith(\"/body/\")) {\n fields.add(\"body\");\n continue;\n }\n const segment = op.path\n .replace(/^\\/(?:metadata|front_matter)\\/?/, \"\")\n .split(\"/\")[0];\n fields.add(segment.replaceAll(\"~1\", \"/\").replaceAll(\"~0\", \"~\"));\n }\n\n return Array.from(fields).sort((a, b) => a.localeCompare(b));\n}\n\nasync function loadRestoreStateUnderLock(params: {\n pmRoot: string;\n resolvedId: string;\n subject: ResolvedRestoreSubject;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeToFolder: Record<string, string>;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n}): Promise<{\n loadedItemUnderLock: Awaited<ReturnType<typeof readLocatedItem>> | null;\n existingItemPath: string | null;\n}> {\n const historyRawUnderLock = await readFileIfExists(\n params.subject.historyPath,\n );\n if (historyRawUnderLock !== params.historyRawBeforeLock) {\n throw new PmCliError(\n `History for ${params.resolvedId} changed while waiting for lock; retry restore.`,\n EXIT_CODE.CONFLICT,\n );\n }\n const locatedUnderLock = await locateItem(\n params.pmRoot,\n params.resolvedId,\n params.settings.id_prefix,\n params.settings.item_format,\n params.typeToFolder,\n );\n const loadedItemUnderLock = locatedUnderLock\n ? await readLocatedItem(locatedUnderLock, {\n schema: params.settings.schema,\n })\n : null;\n if ((loadedItemUnderLock?.raw ?? null) !== params.currentItemRawBeforeLock) {\n throw new PmCliError(\n `Item ${params.resolvedId} changed while waiting for lock; retry restore.`,\n EXIT_CODE.CONFLICT,\n );\n }\n return {\n loadedItemUnderLock,\n existingItemPath: locatedUnderLock?.itemPath ?? null,\n };\n}\n\nfunction resolveRestoreCurrentState(\n loadedItemUnderLock: Awaited<ReturnType<typeof readLocatedItem>> | null,\n history: HistoryEntry[],\n): RestoreCurrentState {\n if (loadedItemUnderLock) {\n return {\n document: loadedItemUnderLock.document,\n originalRaw: loadedItemUnderLock.raw,\n };\n }\n return { document: replayCurrentDocument(history), originalRaw: null };\n}\n\nfunction collectRestoreOwnershipWarnings(params: {\n document: ItemDocument;\n author: string;\n force: boolean | undefined;\n enforcement: \"strict\" | \"warn\" | \"none\";\n resolvedId: string;\n}): string[] {\n const assigned = params.document.metadata.assignee?.trim();\n const hasOwnershipConflict =\n assigned && assigned !== params.author && !params.force;\n if (!hasOwnershipConflict) {\n return [];\n }\n if (params.enforcement === \"strict\") {\n throw new PmCliError(\n `Item ${params.resolvedId} is assigned to ${assigned}. Use --force to override.`,\n EXIT_CODE.CONFLICT,\n );\n }\n return params.enforcement === \"warn\"\n ? [`ownership_warning:assignee_conflict:${params.resolvedId}:${assigned}`]\n : [];\n}\n\nasync function restorePreviousItemAfterHistoryFailure(params: {\n existingItemPath: string | null;\n resolvedOriginalRaw: string | null;\n restoredItemPath: string;\n}): Promise<void> {\n if (\n params.existingItemPath &&\n params.resolvedOriginalRaw !== null &&\n params.restoredItemPath !== params.existingItemPath\n ) {\n await writeFileAtomic(params.existingItemPath, params.resolvedOriginalRaw);\n await fs.rm(params.restoredItemPath, { force: true });\n return;\n }\n if (params.existingItemPath && params.resolvedOriginalRaw !== null) {\n await writeFileAtomic(params.existingItemPath, params.resolvedOriginalRaw);\n return;\n }\n await fs.rm(params.restoredItemPath, { force: true });\n}\n\nasync function runRestoreWriteHooks(params: {\n restoredItemPath: string;\n historyPath: string;\n before: ItemDocument;\n after: ItemDocument;\n}): Promise<string[]> {\n return [\n ...(await runActiveOnWriteHooks({\n path: params.restoredItemPath,\n scope: \"project\",\n op: \"restore\",\n item_id: params.after.metadata.id,\n item_type: params.after.metadata.type,\n before: params.before,\n after: params.after,\n changed_fields: [\"restored\"],\n })),\n ...(await runActiveOnWriteHooks({\n path: params.historyPath,\n scope: \"project\",\n op: \"restore:history\",\n item_id: params.after.metadata.id,\n item_type: params.after.metadata.type,\n before: params.before,\n after: params.after,\n changed_fields: [\"restored\"],\n })),\n ];\n}\n\n/** Implements run restore for the public runtime surface of this module. */\nexport async function runRestore(\n id: string,\n target: string,\n options: RestoreCommandOptions,\n global: GlobalOptions,\n): Promise<RestoreResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(\n `Tracker is not initialized at ${pmRoot}. Run pm init first.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(\n settings,\n getActiveExtensionRegistrations(),\n );\n const subject = await resolveRestoreSubject(\n pmRoot,\n id,\n settings,\n typeRegistry.type_to_folder,\n );\n const resolvedId = subject.id;\n const historyRawBeforeLock = await readFileIfExists(subject.historyPath);\n const history = await readHistoryEntries(subject.historyPath, resolvedId);\n if (history.length === 0) {\n throw new PmCliError(\n `No history exists for ${resolvedId}; restore is unavailable.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n\n const resolvedTarget = ensureReplayTarget(target, history);\n const replayDocument = ensureMaterializedRestoreTarget(\n replayToTarget(history, resolvedTarget.historyIndex),\n resolvedTarget,\n );\n const restoredDocument = replayToCanonicalItemDocument(replayDocument, {\n schema: settings.schema,\n });\n\n if (restoredDocument.metadata.id !== resolvedId) {\n throw new PmCliError(\n `Restore target resolved to item ${restoredDocument.metadata.id}, expected ${resolvedId}.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n const loadedItemBeforeLock = subject.located\n ? await readLocatedItem(subject.located, { schema: settings.schema })\n : null;\n const currentItemRawBeforeLock = loadedItemBeforeLock?.raw ?? null;\n\n const author = resolveAuthor(options.author, settings.author_default);\n const releaseLock = await acquireLock(\n pmRoot,\n resolvedId,\n settings.locks.ttl_seconds,\n author,\n Boolean(options.force),\n settings.governance.force_required_for_stale_lock,\n settings.locks.wait_ms,\n );\n\n try {\n const { loadedItemUnderLock, existingItemPath } =\n await loadRestoreStateUnderLock({\n pmRoot,\n resolvedId,\n subject,\n settings,\n typeToFolder: typeRegistry.type_to_folder,\n historyRawBeforeLock,\n currentItemRawBeforeLock,\n });\n const itemFormat = \"toon\";\n const currentState = resolveRestoreCurrentState(\n loadedItemUnderLock,\n history,\n );\n const ownershipWarnings = collectRestoreOwnershipWarnings({\n document: currentState.document,\n author,\n force: options.force,\n enforcement: settings.governance.ownership_enforcement,\n resolvedId,\n });\n\n const serializedRestore = serializeItemDocument(restoredDocument, {\n format: itemFormat,\n schema: settings.schema,\n });\n /* c8 ignore next -- restored item path typing is exercised in restore integration workflows. */\n const restoredItemPath = getItemPath(\n pmRoot,\n restoredDocument.metadata.type,\n resolvedId,\n itemFormat,\n typeRegistry.type_to_folder,\n );\n await writeFileAtomic(restoredItemPath, serializedRestore);\n if (existingItemPath && restoredItemPath !== existingItemPath) {\n await fs.rm(existingItemPath);\n }\n\n const historyEntry = createHistoryEntry({\n nowIso: nowIso(),\n author,\n op: \"restore\",\n before: currentState.document,\n after: restoredDocument,\n message: options.message,\n });\n\n try {\n await appendHistoryEntry(subject.historyPath, historyEntry);\n } catch (error: unknown) {\n await restorePreviousItemAfterHistoryFailure({\n existingItemPath,\n resolvedOriginalRaw: currentState.originalRaw,\n restoredItemPath,\n });\n throw error;\n }\n const restoreChangedFields = changedFields(\n currentState.document,\n restoredDocument,\n );\n const hookWarnings = await runRestoreWriteHooks({\n restoredItemPath,\n historyPath: subject.historyPath,\n before: currentState.document,\n after: restoredDocument,\n });\n recordAfterCommandAffectedItem({\n id: restoredDocument.metadata.id,\n op: \"restore\",\n item_type: restoredDocument.metadata.type,\n previous_status: currentState.document.metadata.status,\n status: restoredDocument.metadata.status,\n previous: projectAfterCommandItemSnapshot(\n currentState.document.metadata,\n restoreChangedFields,\n ),\n current: projectAfterCommandItemSnapshot(\n restoredDocument.metadata,\n restoreChangedFields,\n ),\n changed_fields: restoreChangedFields,\n });\n\n const targetEntry = history[resolvedTarget.historyIndex];\n return {\n item: restoredDocument.metadata,\n restored_from: {\n kind: resolvedTarget.kind,\n target: resolvedTarget.raw,\n history_index: resolvedTarget.historyIndex + 1,\n entry_ts: targetEntry.ts,\n entry_op: targetEntry.op,\n },\n changed_fields: restoreChangedFields,\n warnings: [\n ...subject.historyPolicyWarnings,\n ...ownershipWarnings,\n ...hookWarnings,\n ],\n };\n } finally {\n await releaseLock();\n }\n}\n\n/** Public contract for test only restore command, shared by SDK and presentation-layer consumers. */\nexport const _testOnlyRestoreCommand = {\n applyHistoryPatch,\n changedFields,\n ensureMaterializedRestoreTarget,\n ensureReplayTarget,\n extractPatchFailureContext,\n replayCurrentDocument,\n replayToTarget,\n resolveRestoreSubject,\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,eAAe;AACtB,OAAO,QAAQ;;;;;;;;AAkGf,SAAS,mBAAmB,QAAgB,SAAgC;AAC1E,SA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MAAM,eAAe;QACrB,QAAQ,eAAe;QACvB,eAAe,eAAe,eAAe;QAC7C,UAAU,YAAY;QACtB,UAAU,YAAY;;MAExB,gBAAgB;MAChB,UAAU;QACR,GAAG,QAAQ;QACX,GAAG;QACH,GAAG;;;EAGT;AACE,UAAM,YAAW;EACnB;AACF;AAGO,IAAM,0BAA0B;EACrC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;",
6
6
  "names": ["global"]
7
7
  }
@@ -4,7 +4,7 @@ import {
4
4
  parseAnnotationTextInput,
5
5
  resolveAnnotationInput,
6
6
  runAnnotationCommand
7
- } from "./chunk-HB3P4M52.js";
7
+ } from "./chunk-TRSHFPRZ.js";
8
8
 
9
9
  // dist/cli/commands/notes.js
10
10
  async function runNotes(id, options, global) {
@@ -30,6 +30,6 @@ async function runNotes(id, options, global) {
30
30
  export {
31
31
  runNotes
32
32
  };
33
- //# sourceMappingURL=chunk-VQIHNHMJ.js.map
33
+ //# sourceMappingURL=chunk-QIH77CAG.js.map
34
34
 
35
35
  //# debugId=1401c7cc-d6e7-5373-a39e-084832b21dc6
@@ -3,7 +3,7 @@
3
3
  import {
4
4
  cloneEmptyReplayDocument,
5
5
  tryApplyReplayPatch
6
- } from "./chunk-P7JTWYLH.js";
6
+ } from "./chunk-PFNHX655.js";
7
7
 
8
8
  // dist/core/history/history-diff.js
9
9
  function decodeJsonPointerSegment(segment) {
@@ -101,6 +101,6 @@ export {
101
101
  patchPathToChangedField,
102
102
  computeHistoryDiff
103
103
  };
104
- //# sourceMappingURL=chunk-R3EWPG4A.js.map
104
+ //# sourceMappingURL=chunk-QJIKE24M.js.map
105
105
 
106
106
  //# debugId=2058f7b4-d6fe-5ba6-9553-649698e75a38
@@ -1,25 +1,23 @@
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]="f3b67cc1-b842-5dc9-8268-23f54c3caea4")}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]="4343cdfe-e0a2-52a0-aa46-17221a2fba2d")}catch(e){}}();
3
3
  import {
4
4
  scanHistoryDrift
5
- } from "./chunk-ZV2NTVMJ.js";
5
+ } from "./chunk-PONKZPCJ.js";
6
6
  import {
7
7
  patchPathToChangedField
8
- } from "./chunk-R3EWPG4A.js";
8
+ } from "./chunk-QJIKE24M.js";
9
9
  import {
10
10
  executeHistoryRewrite,
11
- readHistoryEntries,
12
- resolveHistorySubject,
13
- writeHistoryRawWithRollback
14
- } from "./chunk-2BO4CA46.js";
15
- import {
16
11
  historyEntriesToRaw,
17
12
  normalizeReplayPatchOps,
13
+ readHistoryEntries,
18
14
  reanchorHistoryEntries,
19
15
  replayHash,
16
+ resolveHistorySubject,
20
17
  toReplayDocument,
21
- verifyHistoryChain
22
- } from "./chunk-P7JTWYLH.js";
18
+ verifyHistoryChain,
19
+ writeHistoryRawWithRollback
20
+ } from "./chunk-PFNHX655.js";
23
21
  import {
24
22
  getActiveExtensionRegistrations,
25
23
  listAllItemMetadataWithBody,
@@ -325,6 +323,6 @@ export {
325
323
  assertHistoryRepairTarget,
326
324
  runHistoryRepairAll
327
325
  };
328
- //# sourceMappingURL=chunk-QLZ643FM.js.map
326
+ //# sourceMappingURL=chunk-QOOTOD3W.js.map
329
327
 
330
- //# debugId=f3b67cc1-b842-5dc9-8268-23f54c3caea4
328
+ //# debugId=4343cdfe-e0a2-52a0-aa46-17221a2fba2d
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../sdk/history-repair.ts"],"sourcesContent":["/**\n * @module sdk/history-repair\n *\n * Implements the pm history repair command surface and its agent-facing runtime behavior.\n */\nimport jsonPatch from \"fast-json-patch\";\nimport { patchPathToChangedField } from \"../core/history/history-diff.js\";\nimport { pathExists, readFileIfExists } from \"../core/fs/fs-utils.js\";\nimport {\n executeHistoryRewrite,\n writeHistoryRawWithRollback,\n} from \"../core/history/history-rewrite.js\";\nimport {\n historyEntriesToRaw,\n normalizeReplayPatchOps,\n reanchorHistoryEntries,\n replayHash,\n toReplayDocument,\n verifyHistoryChain,\n type ReplayDocument,\n} from \"../core/history/replay.js\";\nimport { scanHistoryDrift } from \"../core/history/drift-scan.js\";\nimport { readHistoryEntries } from \"../core/history/read.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 {\n getActiveExtensionRegistrations,\n runActiveOnWriteHooks,\n} from \"../core/extensions/index.js\";\nimport {\n listAllItemMetadataWithBody,\n readLocatedItem,\n} from \"../core/store/item-store.js\";\nimport { getSettingsPath, resolvePmRoot } from \"../core/store/paths.js\";\nimport { readSettings } from \"../core/store/settings.js\";\nimport type {\n HistoryEntry,\n HistoryPatchOp,\n ItemMetadata,\n} from \"../types/index.js\";\nimport { resolveHistorySubject } from \"./history-redact.js\";\n\n/** Documents the history repair command options payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairCommandOptions {\n /** Value that configures or reports dry run for this contract. */\n dryRun?: boolean;\n /** Value that configures or reports author for this contract. */\n author?: string;\n /** Human-readable explanation suitable for logs and agent-facing output. */\n message?: string;\n /** Value that configures or reports force for this contract. */\n force?: boolean;\n}\n\n/** Documents the history repair result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairResult {\n /** Stable identifier used to reference this record across commands and storage. */\n id: string;\n /** Value that configures or reports dry run for this contract. */\n dry_run: boolean;\n /** Value that configures or reports changed for this contract. */\n changed: boolean;\n /** Value that configures or reports history for this contract. */\n history: {\n path: string;\n entries_scanned: number;\n chain_drift_before: boolean;\n entries_rehashed: number;\n entries_patch_repaired: number;\n converted_replace_to_add: number;\n skipped_ops: number;\n reconciled_with_item: boolean;\n audit_entry_added: boolean;\n verify_ok: boolean;\n verify_errors: string[];\n };\n /** Value that configures or reports item for this contract. */\n item: {\n exists: boolean;\n path: string | null;\n matched_chain_before: boolean | null;\n };\n /** Present when reconciling the chain with the on-disk item discards the replayed effect of earlier history events (GH-603): names the reverted fields and the authors whose mutations the reconciliation overwrites, so cross-author data loss after a lossy merge is loud instead of silent. */\n reconciliation?: HistoryRepairReconciliationReport;\n /** Value that configures or reports warnings for this contract. */\n warnings: string[];\n /** ISO 8601 timestamp recording when generated occurred. */\n generated_at: string;\n}\n\n/** Documents one history event whose replayed effect a repair reconciliation overwrites. */\nexport interface HistoryRepairDiscardedEvent {\n /** 1-based index of the event in the (re-anchored) history stream. */\n index: number;\n /** Timestamp of the discarded event. */\n ts: string;\n /** Author whose mutation the reconciliation overwrites. */\n author: string;\n /** Operation label of the discarded event. */\n op: string;\n /** Reverted fields this event last wrote. */\n fields: string[];\n}\n\n/** Documents the repair reconciliation data-loss report exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairReconciliationReport {\n /** Number of fields the reconciliation patch reverts relative to the replayed chain. */\n reverted_field_count: number;\n /** Fields whose replayed values the reconciliation overwrites with the on-disk item's values. */\n reverted_fields: string[];\n /** Newest history events that last wrote each reverted field — the mutations being discarded. */\n discarded_events: HistoryRepairDiscardedEvent[];\n /** Distinct authors whose mutations the reconciliation discards. */\n discarded_authors: string[];\n /** How to recover a discarded mutation instead of accepting the revert. */\n recovery_hint: string;\n}\n\n/** Compute which fields a chain-vs-item reconciliation reverts and which history events (and authors) last wrote them. The reconciliation patch rewrites the replayed final state into the on-disk item state, so any field it touches is a replayed mutation being overwritten — after a lossy merge resolution this is exactly the other branch's discarded work (GH-603). */\nexport function analyzeReconciliationDiscard(\n entries: HistoryEntry[],\n finalReplay: ReplayDocument,\n currentItemReplay: ReplayDocument,\n): HistoryRepairReconciliationReport | undefined {\n const reconcilePatch = jsonPatch.compare(\n finalReplay,\n currentItemReplay,\n ) as HistoryPatchOp[];\n if (reconcilePatch.length === 0) {\n return undefined;\n }\n const revertedFields = new Set<string>();\n for (const op of reconcilePatch) {\n revertedFields.add(patchPathToChangedField(op.path));\n }\n const remaining = new Set(revertedFields);\n const discardedEvents: HistoryRepairDiscardedEvent[] = [];\n for (let index = entries.length - 1; index >= 0 && remaining.size > 0; index -= 1) {\n const entry = entries[index];\n const entryFields = new Set<string>();\n for (const op of normalizeReplayPatchOps(entry.patch)) {\n entryFields.add(patchPathToChangedField(op.path));\n if (op.from) {\n entryFields.add(patchPathToChangedField(op.from));\n }\n }\n const overlap = [...remaining].filter((field) => entryFields.has(field));\n if (overlap.length === 0) {\n continue;\n }\n for (const field of overlap) {\n remaining.delete(field);\n }\n discardedEvents.push({\n index: index + 1,\n ts: entry.ts,\n author: entry.author,\n op: entry.op,\n fields: overlap.sort((left, right) => left.localeCompare(right)),\n });\n }\n discardedEvents.reverse();\n return {\n reverted_field_count: revertedFields.size,\n reverted_fields: [...revertedFields].sort((left, right) =>\n left.localeCompare(right),\n ),\n discarded_events: discardedEvents,\n discarded_authors: [\n ...new Set(discardedEvents.map((event) => event.author)),\n ].sort((left, right) => left.localeCompare(right)),\n recovery_hint:\n \"Reconciliation keeps the on-disk item and overwrites these replayed mutations. To recover one, inspect it with pm history <id> --diff --field <field>, then re-apply the lost value with pm update.\",\n };\n}\n\ninterface HistoryRepairItemReplayContext {\n currentItemReplay: ReplayDocument | null;\n currentItemPath: string | null;\n matchedChainBefore: boolean | null;\n currentItemRawBeforeLock: string | null;\n loadedItem: Awaited<ReturnType<typeof readLocatedItem>> | null;\n}\n\nfunction toAuthor(\n candidate: string | undefined,\n defaultAuthor: string,\n): string {\n /* c8 ignore next -- PM_AUTHOR fallback branch is environment-dependent in CI. */\n const resolved = candidate ?? process.env.PM_AUTHOR ?? defaultAuthor;\n const trimmed = resolved.trim();\n return trimmed.length > 0 ? trimmed : \"unknown\";\n}\n\nasync function loadHistoryRepairItemReplay(\n subject: Awaited<ReturnType<typeof resolveHistorySubject>>,\n settings: Awaited<ReturnType<typeof readSettings>>,\n historyEntries: HistoryEntry[],\n): Promise<HistoryRepairItemReplayContext> {\n const currentItemPath = subject.located?.itemPath ?? null;\n const loadedItem = subject.located\n ? await readLocatedItem(subject.located, { schema: settings.schema })\n : null;\n if (!loadedItem) {\n return {\n currentItemReplay: null,\n currentItemPath,\n matchedChainBefore: null,\n currentItemRawBeforeLock: null,\n loadedItem: null,\n };\n }\n const currentItemReplay = toReplayDocument(loadedItem.document);\n const lastOriginalAfterHash =\n historyEntries[historyEntries.length - 1]?.after_hash;\n return {\n currentItemReplay,\n currentItemPath,\n matchedChainBefore: replayHash(currentItemReplay) === lastOriginalAfterHash,\n currentItemRawBeforeLock: loadedItem.raw,\n loadedItem,\n };\n}\n\nfunction buildHistoryRepairMessage(params: {\n message: string | undefined;\n entriesRehashed: number;\n entriesPatchRepaired: number;\n reconcileNeeded: boolean;\n}): string {\n if (typeof params.message === \"string\" && params.message.trim().length > 0) {\n return params.message;\n }\n /* v8 ignore start -- message suffix/plural variants are deterministic formatting fallbacks around the covered repair outcomes */\n return `history-repair re-anchored ${params.entriesRehashed} entr${\n params.entriesRehashed === 1 ? \"y\" : \"ies\"\n }${params.entriesPatchRepaired > 0 ? `, repaired ${params.entriesPatchRepaired} patch(es)` : \"\"}${\n params.reconcileNeeded ? \", reconciled chain with on-disk item\" : \"\"\n }.`;\n /* v8 ignore stop */\n}\n\nfunction buildHistoryRepairEntries(params: {\n reanchorEntries: HistoryEntry[];\n changed: boolean;\n reconcileNeeded: boolean;\n currentItemReplay: ReplayDocument | null;\n finalReplay: ReplayDocument;\n author: string;\n message: string;\n}): { rewrittenEntries: HistoryEntry[]; auditEntryAdded: boolean } {\n const rewrittenEntries: HistoryEntry[] = [...params.reanchorEntries];\n if (!params.changed) {\n return { rewrittenEntries, auditEntryAdded: false };\n }\n const afterReplay =\n params.reconcileNeeded && params.currentItemReplay\n ? params.currentItemReplay\n : params.finalReplay;\n rewrittenEntries.push({\n ts: nowIso(),\n author: params.author,\n op: \"history_repair\",\n patch:\n params.reconcileNeeded && params.currentItemReplay\n ? (jsonPatch.compare(\n params.finalReplay,\n params.currentItemReplay,\n ) as HistoryPatchOp[])\n : [],\n before_hash: replayHash(params.finalReplay),\n after_hash: replayHash(afterReplay),\n message: params.message,\n });\n return { rewrittenEntries, auditEntryAdded: true };\n}\n\nfunction collectHistoryRepairWarnings(\n changed: boolean,\n skippedOps: number,\n): string[] {\n const warnings: string[] = [];\n if (!changed) {\n warnings.push(\"history_repair_no_changes\");\n }\n if (skippedOps > 0) {\n warnings.push(`history_repair_skipped_unresolvable_ops:${skippedOps}`);\n }\n return warnings;\n}\n\nasync function applyHistoryRepairRewrite(params: {\n pmRoot: string;\n subject: Awaited<ReturnType<typeof resolveHistorySubject>>;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeRegistry: ReturnType<typeof resolveItemTypeRegistry>;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n author: string;\n force: boolean | undefined;\n loadedItem: Awaited<ReturnType<typeof readLocatedItem>> | null;\n historyPath: string;\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.currentItemRawBeforeLock,\n operation: \"history-repair\",\n author: params.author,\n force: params.force,\n itemDocument: params.loadedItem?.document ?? null,\n applyRewrite: async ({ historyRawUnderLock }) =>\n writeHistoryRawWithRollback({\n historyPath: params.historyPath,\n nextHistoryRaw: historyEntriesToRaw(params.rewrittenEntries),\n historyRawUnderLock,\n }),\n applyPostRewrite: async () =>\n runActiveOnWriteHooks({\n path: params.historyPath,\n scope: \"project\",\n op: \"history_repair:history\",\n }),\n });\n}\n\n/** Implements run history repair for the public runtime surface of this module. */\nexport async function runHistoryRepair(\n id: string,\n options: HistoryRepairCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRepairResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(\n `Tracker is not initialized at ${pmRoot}. Run pm init first.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(\n settings,\n getActiveExtensionRegistrations(),\n );\n const subject = await resolveHistorySubject(\n pmRoot,\n id,\n settings,\n typeRegistry.type_to_folder,\n );\n\n if (!(await pathExists(subject.historyPath))) {\n throw new PmCliError(\n `No history stream exists for ${subject.id}.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n const historyRawBeforeLock = await readFileIfExists(subject.historyPath);\n const historyEntries = await readHistoryEntries(\n subject.historyPath,\n subject.id,\n );\n if (historyEntries.length === 0) {\n throw new PmCliError(\n `No history entries exist for ${subject.id}; nothing to repair.`,\n EXIT_CODE.USAGE,\n );\n }\n\n const chainBefore = verifyHistoryChain(historyEntries);\n const reanchor = reanchorHistoryEntries(historyEntries);\n\n const itemReplayContext = await loadHistoryRepairItemReplay(\n subject,\n settings,\n historyEntries,\n );\n\n const finalReplay = reanchor.finalDocument;\n const reconcileNeeded =\n itemReplayContext.currentItemReplay !== null &&\n replayHash(finalReplay) !== replayHash(itemReplayContext.currentItemReplay);\n // GH-603: reconciling toward the on-disk item can silently overwrite the\n // replayed effect of other authors' events (classic after a lossy merge).\n // Surface exactly what is being discarded before any write happens.\n const reconciliation =\n reconcileNeeded && itemReplayContext.currentItemReplay\n ? analyzeReconciliationDiscard(\n reanchor.entries,\n finalReplay,\n itemReplayContext.currentItemReplay,\n )\n : undefined;\n\n const changed =\n reanchor.entriesRehashed > 0 ||\n reanchor.entriesPatchRepaired > 0 ||\n reconcileNeeded;\n const author = toAuthor(options.author, settings.author_default);\n const dryRun = Boolean(options.dryRun);\n\n const repairMessage = buildHistoryRepairMessage({\n message: options.message,\n entriesRehashed: reanchor.entriesRehashed,\n entriesPatchRepaired: reanchor.entriesPatchRepaired,\n reconcileNeeded,\n });\n const { rewrittenEntries, auditEntryAdded } = buildHistoryRepairEntries({\n reanchorEntries: reanchor.entries,\n changed,\n reconcileNeeded,\n currentItemReplay: itemReplayContext.currentItemReplay,\n finalReplay,\n author,\n message: repairMessage,\n });\n\n const historyVerify = verifyHistoryChain(rewrittenEntries);\n if (!historyVerify.ok) {\n throw new PmCliError(\n `history-repair produced an invalid rewritten chain (${historyVerify.errors.join(\", \")}).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n\n const warnings = collectHistoryRepairWarnings(changed, reanchor.skippedOps);\n if (reconciliation) {\n warnings.push(\n `history_repair_reconcile_discards_events:${reconciliation.discarded_events.length}`,\n );\n warnings.push(\n `history_repair_discarded_authors:${reconciliation.discarded_authors.join(\",\")}`,\n );\n }\n\n if (changed && !dryRun) {\n warnings.push(\n ...(await applyHistoryRepairRewrite({\n pmRoot,\n subject,\n settings,\n typeRegistry,\n historyRawBeforeLock,\n currentItemRawBeforeLock: itemReplayContext.currentItemRawBeforeLock,\n author,\n force: options.force,\n loadedItem: itemReplayContext.loadedItem,\n historyPath: subject.historyPath,\n rewrittenEntries,\n })),\n );\n }\n\n return {\n id: subject.id,\n dry_run: dryRun,\n changed,\n history: {\n path: subject.historyPath,\n entries_scanned: historyEntries.length,\n chain_drift_before: !chainBefore.ok,\n entries_rehashed: reanchor.entriesRehashed,\n entries_patch_repaired: reanchor.entriesPatchRepaired,\n converted_replace_to_add: reanchor.convertedReplaceToAdd,\n skipped_ops: reanchor.skippedOps,\n reconciled_with_item: reconcileNeeded,\n audit_entry_added: auditEntryAdded,\n verify_ok: historyVerify.ok,\n verify_errors: historyVerify.errors,\n },\n item: {\n exists: itemReplayContext.currentItemPath !== null,\n path: itemReplayContext.currentItemPath,\n matched_chain_before: itemReplayContext.matchedChainBefore,\n },\n ...(reconciliation ? { reconciliation } : {}),\n warnings: [...new Set(warnings)].sort((left, right) =>\n left.localeCompare(right),\n ),\n generated_at: nowIso(),\n };\n}\n\n/** Documents the history repair all stream result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairAllStreamResult {\n /** Stable identifier used to reference this record across commands and storage. */\n id: string;\n /** Value that configures or reports outcome for this contract. */\n outcome: \"repaired\" | \"skipped_clean\" | \"failed\";\n /** Value that configures or reports entries rehashed for this contract. */\n entries_rehashed?: number;\n /** Value that configures or reports entries patch repaired for this contract. */\n entries_patch_repaired?: number;\n /** Value that configures or reports reconciled with item for this contract. */\n reconciled_with_item?: boolean;\n /** Cross-author data-loss detail when reconciliation overwrites replayed mutations. */\n reconciliation?: HistoryRepairReconciliationReport;\n /** Stream-specific repair warnings retained by the bulk workflow. */\n warnings?: string[];\n /** Value that configures or reports error for this contract. */\n error?: string;\n}\n\n/** Documents the history repair all result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairAllResult {\n /** Value that configures or reports all for this contract. */\n all: true;\n /** Value that configures or reports dry run for this contract. */\n dry_run: boolean;\n /** Value that configures or reports scanned streams for this contract. */\n scanned_streams: number;\n /** Value that configures or reports drifted streams for this contract. */\n drifted_streams: number;\n /** One compact row per drifted stream (clean streams are summarized by the counts only). */\n streams: HistoryRepairAllStreamResult[];\n /** Value that configures or reports totals for this contract. */\n totals: { repaired: number; skipped_clean: number; failed: number };\n /** Value that configures or reports warnings for this contract. */\n warnings: string[];\n /** ISO 8601 timestamp recording when generated occurred. */\n generated_at: string;\n}\n\n/** Enforce the `pm history-repair` target contract shared by the CLI and MCP surfaces: exactly one of an item `<id>` or `--all` must be provided. */\nexport function assertHistoryRepairTarget(\n id: string | undefined,\n all: boolean,\n): void {\n if (all && id !== undefined) {\n throw new PmCliError(\n \"history-repair: <id> and --all are mutually exclusive; pass an item id to repair one stream or --all to repair every drifted stream.\",\n EXIT_CODE.USAGE,\n );\n }\n if (!all && id === undefined) {\n throw new PmCliError(\n \"history-repair: provide an item <id> or pass --all to repair every drifted stream.\",\n EXIT_CODE.USAGE,\n );\n }\n}\n\n/** Bulk drift repair: scan every item's history stream with the same drift scan `pm health` uses, then run the audited single-stream repair (ownership check, lock, no-drift verification, audit marker) for each drifted stream. One failing stream never aborts the rest; failures are collected per row and the caller decides the exit code from `totals.failed`. */\nexport async function runHistoryRepairAll(\n options: HistoryRepairCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRepairAllResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(\n `Tracker is not initialized at ${pmRoot}. Run pm init first.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(\n settings,\n getActiveExtensionRegistrations(),\n );\n const itemReadWarnings: string[] = [];\n const items = await listAllItemMetadataWithBody(\n pmRoot,\n settings.item_format,\n typeRegistry.type_to_folder,\n itemReadWarnings,\n settings.schema,\n );\n const drift = await scanHistoryDrift(\n pmRoot,\n items as Array<ItemMetadata & { body: string }>,\n );\n\n const streams: HistoryRepairAllStreamResult[] = [];\n const repairWarnings: string[] = [];\n const totals = { repaired: 0, skipped_clean: 0, failed: 0 };\n for (const driftedId of drift.driftedItems) {\n try {\n const result = await runHistoryRepair(driftedId, options, global);\n /* c8 ignore next -- mixed repaired/clean outcomes depend on live drift composition. */\n const outcome = result.changed ? \"repaired\" : \"skipped_clean\";\n totals[outcome] += 1;\n repairWarnings.push(\n ...result.warnings.map((warning) => `${driftedId}:${warning}`),\n );\n streams.push({\n id: driftedId,\n outcome,\n entries_rehashed: result.history.entries_rehashed,\n entries_patch_repaired: result.history.entries_patch_repaired,\n reconciled_with_item: result.history.reconciled_with_item,\n ...(result.reconciliation\n ? { reconciliation: result.reconciliation }\n : {}),\n warnings: result.warnings,\n });\n } catch (error) {\n totals.failed += 1;\n streams.push({\n id: driftedId,\n outcome: \"failed\",\n /* c8 ignore next -- non-Error throws are normalized in defensive fallback. */\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n return {\n all: true,\n dry_run: Boolean(options.dryRun),\n scanned_streams: items.length,\n drifted_streams: drift.driftedItems.length,\n streams,\n totals,\n warnings: [...new Set([...itemReadWarnings, ...repairWarnings])].sort((left, right) =>\n left.localeCompare(right),\n ),\n generated_at: nowIso(),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,eAAe;AAqHhB,SAAU,6BACd,SACA,aACA,mBAAiC;AAEjC,QAAM,iBAAiB,UAAU,QAC/B,aACA,iBAAiB;AAEnB,MAAI,eAAe,WAAW,GAAG;AAC/B,WAAO;EACT;AACA,QAAM,iBAAiB,oBAAI,IAAG;AAC9B,aAAW,MAAM,gBAAgB;AAC/B,mBAAe,IAAI,wBAAwB,GAAG,IAAI,CAAC;EACrD;AACA,QAAM,YAAY,IAAI,IAAI,cAAc;AACxC,QAAM,kBAAiD,CAAA;AACvD,WAAS,QAAQ,QAAQ,SAAS,GAAG,SAAS,KAAK,UAAU,OAAO,GAAG,SAAS,GAAG;AACjF,UAAM,QAAQ,QAAQ,KAAK;AAC3B,UAAM,cAAc,oBAAI,IAAG;AAC3B,eAAW,MAAM,wBAAwB,MAAM,KAAK,GAAG;AACrD,kBAAY,IAAI,wBAAwB,GAAG,IAAI,CAAC;AAChD,UAAI,GAAG,MAAM;AACX,oBAAY,IAAI,wBAAwB,GAAG,IAAI,CAAC;MAClD;IACF;AACA,UAAM,UAAU,CAAC,GAAG,SAAS,EAAE,OAAO,CAAC,UAAU,YAAY,IAAI,KAAK,CAAC;AACvE,QAAI,QAAQ,WAAW,GAAG;AACxB;IACF;AACA,eAAW,SAAS,SAAS;AAC3B,gBAAU,OAAO,KAAK;IACxB;AACA,oBAAgB,KAAK;MACnB,OAAO,QAAQ;MACf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aAAO,UAAU;AACjB,cAAQ,KAAK;QACX,IAAI;QACJ,SAAS;;QAET,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;OAC7D;IACH;EACF;AAEA,SAAO;IACL,KAAK;IACL,SAAS,QAAQ,QAAQ,MAAM;IAC/B,iBAAiB,MAAM;IACvB,iBAAiB,MAAM,aAAa;IACpC;IACA;IACA,UAAU,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,kBAAkB,GAAG,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,UAC3E,KAAK,cAAc,KAAK,CAAC;IAE3B,cAAc,OAAM;;AAExB","debugId":"f3b67cc1-b842-5dc9-8268-23f54c3caea4"}
1
+ {"version":3,"sources":["../../../../../../../../sdk/history-repair.ts"],"sourcesContent":["/**\n * @module sdk/history-repair\n *\n * Implements the pm history repair command surface and its agent-facing runtime behavior.\n */\nimport jsonPatch from \"fast-json-patch\";\nimport { patchPathToChangedField } from \"../core/history/history-diff.js\";\nimport { pathExists, readFileIfExists } from \"../core/fs/fs-utils.js\";\nimport {\n executeHistoryRewrite,\n writeHistoryRawWithRollback,\n} from \"../core/history/history-rewrite.js\";\nimport {\n historyEntriesToRaw,\n normalizeReplayPatchOps,\n reanchorHistoryEntries,\n replayHash,\n toReplayDocument,\n verifyHistoryChain,\n type ReplayDocument,\n} from \"../core/history/replay.js\";\nimport { scanHistoryDrift } from \"../core/history/drift-scan.js\";\nimport { readHistoryEntries } from \"../core/history/read.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 {\n getActiveExtensionRegistrations,\n runActiveOnWriteHooks,\n} from \"../core/extensions/index.js\";\nimport {\n listAllItemMetadataWithBody,\n readLocatedItem,\n} from \"../core/store/item-store.js\";\nimport { getSettingsPath, resolvePmRoot } from \"../core/store/paths.js\";\nimport { readSettings } from \"../core/store/settings.js\";\nimport type {\n HistoryEntry,\n HistoryPatchOp,\n ItemMetadata,\n} from \"../types/index.js\";\nimport { resolveHistorySubject } from \"./history-redact.js\";\n\n/** Documents the history repair command options payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairCommandOptions {\n /** Value that configures or reports dry run for this contract. */\n dryRun?: boolean;\n /** Value that configures or reports author for this contract. */\n author?: string;\n /** Human-readable explanation suitable for logs and agent-facing output. */\n message?: string;\n /** Value that configures or reports force for this contract. */\n force?: boolean;\n}\n\n/** Documents the history repair result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairResult {\n /** Stable identifier used to reference this record across commands and storage. */\n id: string;\n /** Value that configures or reports dry run for this contract. */\n dry_run: boolean;\n /** Value that configures or reports changed for this contract. */\n changed: boolean;\n /** Value that configures or reports history for this contract. */\n history: {\n path: string;\n entries_scanned: number;\n chain_drift_before: boolean;\n entries_rehashed: number;\n entries_patch_repaired: number;\n converted_replace_to_add: number;\n skipped_ops: number;\n reconciled_with_item: boolean;\n audit_entry_added: boolean;\n verify_ok: boolean;\n verify_errors: string[];\n };\n /** Value that configures or reports item for this contract. */\n item: {\n exists: boolean;\n path: string | null;\n matched_chain_before: boolean | null;\n };\n /** Present when reconciling the chain with the on-disk item discards the replayed effect of earlier history events (GH-603): names the reverted fields and the authors whose mutations the reconciliation overwrites, so cross-author data loss after a lossy merge is loud instead of silent. */\n reconciliation?: HistoryRepairReconciliationReport;\n /** Value that configures or reports warnings for this contract. */\n warnings: string[];\n /** ISO 8601 timestamp recording when generated occurred. */\n generated_at: string;\n}\n\n/** Documents one history event whose replayed effect a repair reconciliation overwrites. */\nexport interface HistoryRepairDiscardedEvent {\n /** 1-based index of the event in the (re-anchored) history stream. */\n index: number;\n /** Timestamp of the discarded event. */\n ts: string;\n /** Author whose mutation the reconciliation overwrites. */\n author: string;\n /** Operation label of the discarded event. */\n op: string;\n /** Reverted fields this event last wrote. */\n fields: string[];\n}\n\n/** Documents the repair reconciliation data-loss report exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairReconciliationReport {\n /** Number of fields the reconciliation patch reverts relative to the replayed chain. */\n reverted_field_count: number;\n /** Fields whose replayed values the reconciliation overwrites with the on-disk item's values. */\n reverted_fields: string[];\n /** Newest history events that last wrote each reverted field — the mutations being discarded. */\n discarded_events: HistoryRepairDiscardedEvent[];\n /** Distinct authors whose mutations the reconciliation discards. */\n discarded_authors: string[];\n /** How to recover a discarded mutation instead of accepting the revert. */\n recovery_hint: string;\n}\n\n/** Compute which fields a chain-vs-item reconciliation reverts and which history events (and authors) last wrote them. The reconciliation patch rewrites the replayed final state into the on-disk item state, so any field it touches is a replayed mutation being overwritten — after a lossy merge resolution this is exactly the other branch's discarded work (GH-603). */\nexport function analyzeReconciliationDiscard(\n entries: HistoryEntry[],\n finalReplay: ReplayDocument,\n currentItemReplay: ReplayDocument,\n): HistoryRepairReconciliationReport | undefined {\n const reconcilePatch = jsonPatch.compare(\n finalReplay,\n currentItemReplay,\n ) as HistoryPatchOp[];\n if (reconcilePatch.length === 0) {\n return undefined;\n }\n const revertedFields = new Set<string>();\n for (const op of reconcilePatch) {\n revertedFields.add(patchPathToChangedField(op.path));\n }\n const remaining = new Set(revertedFields);\n const discardedEvents: HistoryRepairDiscardedEvent[] = [];\n for (let index = entries.length - 1; index >= 0 && remaining.size > 0; index -= 1) {\n const entry = entries[index];\n const entryFields = new Set<string>();\n for (const op of normalizeReplayPatchOps(entry.patch)) {\n entryFields.add(patchPathToChangedField(op.path));\n if (op.from) {\n entryFields.add(patchPathToChangedField(op.from));\n }\n }\n const overlap = [...remaining].filter((field) => entryFields.has(field));\n if (overlap.length === 0) {\n continue;\n }\n for (const field of overlap) {\n remaining.delete(field);\n }\n discardedEvents.push({\n index: index + 1,\n ts: entry.ts,\n author: entry.author,\n op: entry.op,\n fields: overlap.sort((left, right) => left.localeCompare(right)),\n });\n }\n discardedEvents.reverse();\n return {\n reverted_field_count: revertedFields.size,\n reverted_fields: [...revertedFields].sort((left, right) =>\n left.localeCompare(right),\n ),\n discarded_events: discardedEvents,\n discarded_authors: [\n ...new Set(discardedEvents.map((event) => event.author)),\n ].sort((left, right) => left.localeCompare(right)),\n recovery_hint:\n \"Reconciliation keeps the on-disk item and overwrites these replayed mutations. To recover one, inspect it with pm history <id> --diff --field <field>, then re-apply the lost value with pm update.\",\n };\n}\n\ninterface HistoryRepairItemReplayContext {\n currentItemReplay: ReplayDocument | null;\n currentItemPath: string | null;\n matchedChainBefore: boolean | null;\n currentItemRawBeforeLock: string | null;\n loadedItem: Awaited<ReturnType<typeof readLocatedItem>> | null;\n}\n\nfunction toAuthor(\n candidate: string | undefined,\n defaultAuthor: string,\n): string {\n /* c8 ignore next -- PM_AUTHOR fallback branch is environment-dependent in CI. */\n const resolved = candidate ?? process.env.PM_AUTHOR ?? defaultAuthor;\n const trimmed = resolved.trim();\n return trimmed.length > 0 ? trimmed : \"unknown\";\n}\n\nasync function loadHistoryRepairItemReplay(\n subject: Awaited<ReturnType<typeof resolveHistorySubject>>,\n settings: Awaited<ReturnType<typeof readSettings>>,\n historyEntries: HistoryEntry[],\n): Promise<HistoryRepairItemReplayContext> {\n const currentItemPath = subject.located?.itemPath ?? null;\n const loadedItem = subject.located\n ? await readLocatedItem(subject.located, { schema: settings.schema })\n : null;\n if (!loadedItem) {\n return {\n currentItemReplay: null,\n currentItemPath,\n matchedChainBefore: null,\n currentItemRawBeforeLock: null,\n loadedItem: null,\n };\n }\n const currentItemReplay = toReplayDocument(loadedItem.document);\n const lastOriginalAfterHash =\n historyEntries[historyEntries.length - 1]?.after_hash;\n return {\n currentItemReplay,\n currentItemPath,\n matchedChainBefore: replayHash(currentItemReplay) === lastOriginalAfterHash,\n currentItemRawBeforeLock: loadedItem.raw,\n loadedItem,\n };\n}\n\nfunction buildHistoryRepairMessage(params: {\n message: string | undefined;\n entriesRehashed: number;\n entriesPatchRepaired: number;\n reconcileNeeded: boolean;\n}): string {\n if (typeof params.message === \"string\" && params.message.trim().length > 0) {\n return params.message;\n }\n /* v8 ignore start -- message suffix/plural variants are deterministic formatting fallbacks around the covered repair outcomes */\n return `history-repair re-anchored ${params.entriesRehashed} entr${\n params.entriesRehashed === 1 ? \"y\" : \"ies\"\n }${params.entriesPatchRepaired > 0 ? `, repaired ${params.entriesPatchRepaired} patch(es)` : \"\"}${\n params.reconcileNeeded ? \", reconciled chain with on-disk item\" : \"\"\n }.`;\n /* v8 ignore stop */\n}\n\nfunction buildHistoryRepairEntries(params: {\n reanchorEntries: HistoryEntry[];\n changed: boolean;\n reconcileNeeded: boolean;\n currentItemReplay: ReplayDocument | null;\n finalReplay: ReplayDocument;\n author: string;\n message: string;\n}): { rewrittenEntries: HistoryEntry[]; auditEntryAdded: boolean } {\n const rewrittenEntries: HistoryEntry[] = [...params.reanchorEntries];\n if (!params.changed) {\n return { rewrittenEntries, auditEntryAdded: false };\n }\n const afterReplay =\n params.reconcileNeeded && params.currentItemReplay\n ? params.currentItemReplay\n : params.finalReplay;\n rewrittenEntries.push({\n ts: nowIso(),\n author: params.author,\n op: \"history_repair\",\n patch:\n params.reconcileNeeded && params.currentItemReplay\n ? (jsonPatch.compare(\n params.finalReplay,\n params.currentItemReplay,\n ) as HistoryPatchOp[])\n : [],\n before_hash: replayHash(params.finalReplay),\n after_hash: replayHash(afterReplay),\n message: params.message,\n });\n return { rewrittenEntries, auditEntryAdded: true };\n}\n\nfunction collectHistoryRepairWarnings(\n changed: boolean,\n skippedOps: number,\n): string[] {\n const warnings: string[] = [];\n if (!changed) {\n warnings.push(\"history_repair_no_changes\");\n }\n if (skippedOps > 0) {\n warnings.push(`history_repair_skipped_unresolvable_ops:${skippedOps}`);\n }\n return warnings;\n}\n\nasync function applyHistoryRepairRewrite(params: {\n pmRoot: string;\n subject: Awaited<ReturnType<typeof resolveHistorySubject>>;\n settings: Awaited<ReturnType<typeof readSettings>>;\n typeRegistry: ReturnType<typeof resolveItemTypeRegistry>;\n historyRawBeforeLock: string | null;\n currentItemRawBeforeLock: string | null;\n author: string;\n force: boolean | undefined;\n loadedItem: Awaited<ReturnType<typeof readLocatedItem>> | null;\n historyPath: string;\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.currentItemRawBeforeLock,\n operation: \"history-repair\",\n author: params.author,\n force: params.force,\n itemDocument: params.loadedItem?.document ?? null,\n applyRewrite: async ({ historyRawUnderLock }) =>\n writeHistoryRawWithRollback({\n historyPath: params.historyPath,\n nextHistoryRaw: historyEntriesToRaw(params.rewrittenEntries),\n historyRawUnderLock,\n }),\n applyPostRewrite: async () =>\n runActiveOnWriteHooks({\n path: params.historyPath,\n scope: \"project\",\n op: \"history_repair:history\",\n }),\n });\n}\n\n/** Implements run history repair for the public runtime surface of this module. */\nexport async function runHistoryRepair(\n id: string,\n options: HistoryRepairCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRepairResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(\n `Tracker is not initialized at ${pmRoot}. Run pm init first.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(\n settings,\n getActiveExtensionRegistrations(),\n );\n const subject = await resolveHistorySubject(\n pmRoot,\n id,\n settings,\n typeRegistry.type_to_folder,\n );\n\n if (!(await pathExists(subject.historyPath))) {\n throw new PmCliError(\n `No history stream exists for ${subject.id}.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n const historyRawBeforeLock = await readFileIfExists(subject.historyPath);\n const historyEntries = await readHistoryEntries(\n subject.historyPath,\n subject.id,\n );\n if (historyEntries.length === 0) {\n throw new PmCliError(\n `No history entries exist for ${subject.id}; nothing to repair.`,\n EXIT_CODE.USAGE,\n );\n }\n\n const chainBefore = verifyHistoryChain(historyEntries);\n const reanchor = reanchorHistoryEntries(historyEntries);\n\n const itemReplayContext = await loadHistoryRepairItemReplay(\n subject,\n settings,\n historyEntries,\n );\n\n const finalReplay = reanchor.finalDocument;\n const reconcileNeeded =\n itemReplayContext.currentItemReplay !== null &&\n replayHash(finalReplay) !== replayHash(itemReplayContext.currentItemReplay);\n // GH-603: reconciling toward the on-disk item can silently overwrite the\n // replayed effect of other authors' events (classic after a lossy merge).\n // Surface exactly what is being discarded before any write happens.\n const reconciliation =\n reconcileNeeded && itemReplayContext.currentItemReplay\n ? analyzeReconciliationDiscard(\n reanchor.entries,\n finalReplay,\n itemReplayContext.currentItemReplay,\n )\n : undefined;\n\n const changed =\n reanchor.entriesRehashed > 0 ||\n reanchor.entriesPatchRepaired > 0 ||\n reconcileNeeded;\n const author = toAuthor(options.author, settings.author_default);\n const dryRun = Boolean(options.dryRun);\n\n const repairMessage = buildHistoryRepairMessage({\n message: options.message,\n entriesRehashed: reanchor.entriesRehashed,\n entriesPatchRepaired: reanchor.entriesPatchRepaired,\n reconcileNeeded,\n });\n const { rewrittenEntries, auditEntryAdded } = buildHistoryRepairEntries({\n reanchorEntries: reanchor.entries,\n changed,\n reconcileNeeded,\n currentItemReplay: itemReplayContext.currentItemReplay,\n finalReplay,\n author,\n message: repairMessage,\n });\n\n const historyVerify = verifyHistoryChain(rewrittenEntries);\n if (!historyVerify.ok) {\n throw new PmCliError(\n `history-repair produced an invalid rewritten chain (${historyVerify.errors.join(\", \")}).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n\n const warnings = collectHistoryRepairWarnings(changed, reanchor.skippedOps);\n if (reconciliation) {\n warnings.push(\n `history_repair_reconcile_discards_events:${reconciliation.discarded_events.length}`,\n );\n warnings.push(\n `history_repair_discarded_authors:${reconciliation.discarded_authors.join(\",\")}`,\n );\n }\n\n if (changed && !dryRun) {\n warnings.push(\n ...(await applyHistoryRepairRewrite({\n pmRoot,\n subject,\n settings,\n typeRegistry,\n historyRawBeforeLock,\n currentItemRawBeforeLock: itemReplayContext.currentItemRawBeforeLock,\n author,\n force: options.force,\n loadedItem: itemReplayContext.loadedItem,\n historyPath: subject.historyPath,\n rewrittenEntries,\n })),\n );\n }\n\n return {\n id: subject.id,\n dry_run: dryRun,\n changed,\n history: {\n path: subject.historyPath,\n entries_scanned: historyEntries.length,\n chain_drift_before: !chainBefore.ok,\n entries_rehashed: reanchor.entriesRehashed,\n entries_patch_repaired: reanchor.entriesPatchRepaired,\n converted_replace_to_add: reanchor.convertedReplaceToAdd,\n skipped_ops: reanchor.skippedOps,\n reconciled_with_item: reconcileNeeded,\n audit_entry_added: auditEntryAdded,\n verify_ok: historyVerify.ok,\n verify_errors: historyVerify.errors,\n },\n item: {\n exists: itemReplayContext.currentItemPath !== null,\n path: itemReplayContext.currentItemPath,\n matched_chain_before: itemReplayContext.matchedChainBefore,\n },\n ...(reconciliation ? { reconciliation } : {}),\n warnings: [...new Set(warnings)].sort((left, right) =>\n left.localeCompare(right),\n ),\n generated_at: nowIso(),\n };\n}\n\n/** Documents the history repair all stream result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairAllStreamResult {\n /** Stable identifier used to reference this record across commands and storage. */\n id: string;\n /** Value that configures or reports outcome for this contract. */\n outcome: \"repaired\" | \"skipped_clean\" | \"failed\";\n /** Value that configures or reports entries rehashed for this contract. */\n entries_rehashed?: number;\n /** Value that configures or reports entries patch repaired for this contract. */\n entries_patch_repaired?: number;\n /** Value that configures or reports reconciled with item for this contract. */\n reconciled_with_item?: boolean;\n /** Cross-author data-loss detail when reconciliation overwrites replayed mutations. */\n reconciliation?: HistoryRepairReconciliationReport;\n /** Stream-specific repair warnings retained by the bulk workflow. */\n warnings?: string[];\n /** Value that configures or reports error for this contract. */\n error?: string;\n}\n\n/** Documents the history repair all result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryRepairAllResult {\n /** Value that configures or reports all for this contract. */\n all: true;\n /** Value that configures or reports dry run for this contract. */\n dry_run: boolean;\n /** Value that configures or reports scanned streams for this contract. */\n scanned_streams: number;\n /** Value that configures or reports drifted streams for this contract. */\n drifted_streams: number;\n /** One compact row per drifted stream (clean streams are summarized by the counts only). */\n streams: HistoryRepairAllStreamResult[];\n /** Value that configures or reports totals for this contract. */\n totals: { repaired: number; skipped_clean: number; failed: number };\n /** Value that configures or reports warnings for this contract. */\n warnings: string[];\n /** ISO 8601 timestamp recording when generated occurred. */\n generated_at: string;\n}\n\n/** Enforce the `pm history-repair` target contract shared by the CLI and MCP surfaces: exactly one of an item `<id>` or `--all` must be provided. */\nexport function assertHistoryRepairTarget(\n id: string | undefined,\n all: boolean,\n): void {\n if (all && id !== undefined) {\n throw new PmCliError(\n \"history-repair: <id> and --all are mutually exclusive; pass an item id to repair one stream or --all to repair every drifted stream.\",\n EXIT_CODE.USAGE,\n );\n }\n if (!all && id === undefined) {\n throw new PmCliError(\n \"history-repair: provide an item <id> or pass --all to repair every drifted stream.\",\n EXIT_CODE.USAGE,\n );\n }\n}\n\n/** Bulk drift repair: scan every item's history stream with the same drift scan `pm health` uses, then run the audited single-stream repair (ownership check, lock, no-drift verification, audit marker) for each drifted stream. One failing stream never aborts the rest; failures are collected per row and the caller decides the exit code from `totals.failed`. */\nexport async function runHistoryRepairAll(\n options: HistoryRepairCommandOptions,\n global: GlobalOptions,\n): Promise<HistoryRepairAllResult> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(\n `Tracker is not initialized at ${pmRoot}. Run pm init first.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(\n settings,\n getActiveExtensionRegistrations(),\n );\n const itemReadWarnings: string[] = [];\n const items = await listAllItemMetadataWithBody(\n pmRoot,\n settings.item_format,\n typeRegistry.type_to_folder,\n itemReadWarnings,\n settings.schema,\n );\n const drift = await scanHistoryDrift(\n pmRoot,\n items as Array<ItemMetadata & { body: string }>,\n );\n\n const streams: HistoryRepairAllStreamResult[] = [];\n const repairWarnings: string[] = [];\n const totals = { repaired: 0, skipped_clean: 0, failed: 0 };\n for (const driftedId of drift.driftedItems) {\n try {\n const result = await runHistoryRepair(driftedId, options, global);\n /* c8 ignore next -- mixed repaired/clean outcomes depend on live drift composition. */\n const outcome = result.changed ? \"repaired\" : \"skipped_clean\";\n totals[outcome] += 1;\n repairWarnings.push(\n ...result.warnings.map((warning) => `${driftedId}:${warning}`),\n );\n streams.push({\n id: driftedId,\n outcome,\n entries_rehashed: result.history.entries_rehashed,\n entries_patch_repaired: result.history.entries_patch_repaired,\n reconciled_with_item: result.history.reconciled_with_item,\n ...(result.reconciliation\n ? { reconciliation: result.reconciliation }\n : {}),\n warnings: result.warnings,\n });\n } catch (error) {\n totals.failed += 1;\n streams.push({\n id: driftedId,\n outcome: \"failed\",\n /* c8 ignore next -- non-Error throws are normalized in defensive fallback. */\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n return {\n all: true,\n dry_run: Boolean(options.dryRun),\n scanned_streams: items.length,\n drifted_streams: drift.driftedItems.length,\n streams,\n totals,\n warnings: [...new Set([...itemReadWarnings, ...repairWarnings])].sort((left, right) =>\n left.localeCompare(right),\n ),\n generated_at: nowIso(),\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,OAAO,eAAe;AAqHhB,SAAU,6BACd,SACA,aACA,mBAAiC;AAEjC,QAAM,iBAAiB,UAAU,QAC/B,aACA,iBAAiB;AAEnB,MAAI,eAAe,WAAW,GAAG;AAC/B,WAAO;EACT;AACA,QAAM,iBAAiB,oBAAI,IAAG;AAC9B,aAAW,MAAM,gBAAgB;AAC/B,mBAAe,IAAI,wBAAwB,GAAG,IAAI,CAAC;EACrD;AACA,QAAM,YAAY,IAAI,IAAI,cAA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