@unbrained/pm-cli 2026.7.14 → 2026.7.16

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 (708) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +54 -0
  3. package/README.md +14 -11
  4. package/dist/cli/argv-utils.d.ts +1 -4
  5. package/dist/cli/argv-utils.js +3 -13
  6. package/dist/cli/argv-utils.js.map +1 -1
  7. package/dist/cli/bootstrap-args.d.ts +6 -4
  8. package/dist/cli/bootstrap-args.js +51 -16
  9. package/dist/cli/bootstrap-args.js.map +1 -1
  10. package/dist/cli/bundle-integrity.d.ts +49 -0
  11. package/dist/cli/bundle-integrity.js +111 -0
  12. package/dist/cli/bundle-integrity.js.map +1 -0
  13. package/dist/cli/commands/completion.js +7 -2
  14. package/dist/cli/commands/completion.js.map +1 -1
  15. package/dist/cli/commands/config.d.ts +6 -163
  16. package/dist/cli/commands/config.js +4 -1133
  17. package/dist/cli/commands/config.js.map +1 -1
  18. package/dist/cli/commands/context.d.ts +2 -4
  19. package/dist/cli/commands/context.js +10 -85
  20. package/dist/cli/commands/context.js.map +1 -1
  21. package/dist/cli/commands/create.d.ts +1 -0
  22. package/dist/cli/commands/create.js +3 -2
  23. package/dist/cli/commands/create.js.map +1 -1
  24. package/dist/cli/commands/extension/describe.d.ts +2 -91
  25. package/dist/cli/commands/extension/describe.js +4 -142
  26. package/dist/cli/commands/extension/describe.js.map +1 -1
  27. package/dist/cli/commands/extension/scaffold.d.ts +2 -36
  28. package/dist/cli/commands/extension/scaffold.js +4 -2435
  29. package/dist/cli/commands/extension/scaffold.js.map +1 -1
  30. package/dist/cli/commands/extension/shared.d.ts +2 -28
  31. package/dist/cli/commands/extension/shared.js +4 -130
  32. package/dist/cli/commands/extension/shared.js.map +1 -1
  33. package/dist/cli/commands/extension.d.ts +3 -400
  34. package/dist/cli/commands/extension.js +4 -2183
  35. package/dist/cli/commands/extension.js.map +1 -1
  36. package/dist/cli/commands/gc.d.ts +6 -56
  37. package/dist/cli/commands/gc.js +4 -270
  38. package/dist/cli/commands/gc.js.map +1 -1
  39. package/dist/cli/commands/get.d.ts +18 -5
  40. package/dist/cli/commands/get.js +117 -58
  41. package/dist/cli/commands/get.js.map +1 -1
  42. package/dist/cli/commands/health.d.ts +6 -184
  43. package/dist/cli/commands/health.js +4 -1747
  44. package/dist/cli/commands/health.js.map +1 -1
  45. package/dist/cli/commands/history-compact.d.ts +4 -139
  46. package/dist/cli/commands/history-compact.js +5 -510
  47. package/dist/cli/commands/history-compact.js.map +1 -1
  48. package/dist/cli/commands/history-redact.d.ts +8 -120
  49. package/dist/cli/commands/history-redact.js +6 -581
  50. package/dist/cli/commands/history-redact.js.map +1 -1
  51. package/dist/cli/commands/history-repair.d.ts +7 -89
  52. package/dist/cli/commands/history-repair.js +5 -257
  53. package/dist/cli/commands/history-repair.js.map +1 -1
  54. package/dist/cli/commands/history.d.ts +1 -2
  55. package/dist/cli/commands/history.js +6 -48
  56. package/dist/cli/commands/history.js.map +1 -1
  57. package/dist/cli/commands/index.d.ts +1 -0
  58. package/dist/cli/commands/index.js +3 -2
  59. package/dist/cli/commands/index.js.map +1 -1
  60. package/dist/cli/commands/init-agent-guidance.d.ts +6 -113
  61. package/dist/cli/commands/init-agent-guidance.js +4 -431
  62. package/dist/cli/commands/init-agent-guidance.js.map +1 -1
  63. package/dist/cli/commands/init.d.ts +6 -181
  64. package/dist/cli/commands/init.js +4 -690
  65. package/dist/cli/commands/init.js.map +1 -1
  66. package/dist/cli/commands/next.js +3 -3
  67. package/dist/cli/commands/next.js.map +1 -1
  68. package/dist/cli/commands/profile.d.ts +4 -174
  69. package/dist/cli/commands/profile.js +4 -425
  70. package/dist/cli/commands/profile.js.map +1 -1
  71. package/dist/cli/commands/restore.d.ts +4 -19
  72. package/dist/cli/commands/restore.js +9 -158
  73. package/dist/cli/commands/restore.js.map +1 -1
  74. package/dist/cli/commands/schema.d.ts +7 -507
  75. package/dist/cli/commands/schema.js +5 -1254
  76. package/dist/cli/commands/schema.js.map +1 -1
  77. package/dist/cli/commands/test.d.ts +2 -4
  78. package/dist/cli/commands/test.js +7 -97
  79. package/dist/cli/commands/test.js.map +1 -1
  80. package/dist/cli/commands/validate.d.ts +9 -249
  81. package/dist/cli/commands/validate.js +9 -2150
  82. package/dist/cli/commands/validate.js.map +1 -1
  83. package/dist/cli/extension-command-help.js +18 -4
  84. package/dist/cli/extension-command-help.js.map +1 -1
  85. package/dist/cli/extension-command-options.js +3 -3
  86. package/dist/cli/extension-command-options.js.map +1 -1
  87. package/dist/cli/help-content.js +7 -3
  88. package/dist/cli/help-content.js.map +1 -1
  89. package/dist/cli/main.js +20 -30
  90. package/dist/cli/main.js.map +1 -1
  91. package/dist/cli/register-list-query.js +4 -2
  92. package/dist/cli/register-list-query.js.map +1 -1
  93. package/dist/cli/register-mutation.js +11 -3
  94. package/dist/cli/register-mutation.js.map +1 -1
  95. package/dist/cli/register-setup.js +4 -2
  96. package/dist/cli/register-setup.js.map +1 -1
  97. package/dist/cli/registration-helpers.js +3 -2
  98. package/dist/cli/registration-helpers.js.map +1 -1
  99. package/dist/cli-bundle/bundle-manifest.json +782 -0
  100. package/dist/cli-bundle/chunks/{append-PVZJDM6J.js → append-OJQFUQ4T.js} +5 -5
  101. package/dist/cli-bundle/chunks/append-UZVHUO74.js +11 -0
  102. package/dist/cli-bundle/chunks/{chunk-MQZ3PLCF.js → chunk-2IFFUZLC.js} +2 -2
  103. package/dist/cli-bundle/chunks/{chunk-P6MYFH6K.js → chunk-2JKGO6QX.js} +4 -4
  104. package/dist/cli-bundle/chunks/{chunk-X3GYR4P2.js → chunk-2NCIPMQP.js} +2 -2
  105. package/dist/cli-bundle/chunks/{chunk-Q7E6OYZK.js → chunk-2VPAVL7O.js} +2 -2
  106. package/dist/cli-bundle/chunks/{chunk-DRNJPEPQ.js → chunk-2WSE6PO2.js} +4 -4
  107. package/dist/cli-bundle/chunks/{chunk-FDSBDNYE.js → chunk-34L5OT3Y.js} +2 -2
  108. package/dist/cli-bundle/chunks/{chunk-TH7U4KLY.js → chunk-3AUGG2DP.js} +3 -3
  109. package/dist/cli-bundle/chunks/{chunk-NKW36AMT.js → chunk-3CLU2XZO.js} +4 -4
  110. package/dist/cli-bundle/chunks/{chunk-N3CMP4NI.js → chunk-3S5QVM5H.js} +43 -7
  111. package/dist/cli-bundle/chunks/chunk-3S5QVM5H.js.map +1 -0
  112. package/dist/cli-bundle/chunks/chunk-3U7ZR6M4.js +64 -0
  113. package/dist/cli-bundle/chunks/chunk-3U7ZR6M4.js.map +7 -0
  114. package/dist/cli-bundle/chunks/{chunk-ABRCOSDC.js → chunk-3WM75PWC.js} +3 -3
  115. package/dist/cli-bundle/chunks/chunk-4223PVZT.js +121 -0
  116. package/dist/cli-bundle/chunks/chunk-4223PVZT.js.map +7 -0
  117. package/dist/cli-bundle/chunks/{chunk-5URI7TPJ.js → chunk-4XQ3BDV4.js} +281 -164
  118. package/dist/cli-bundle/chunks/chunk-4XQ3BDV4.js.map +7 -0
  119. package/dist/cli-bundle/chunks/{chunk-X6BVXQ52.js → chunk-5JLUII3O.js} +13 -13
  120. package/dist/cli-bundle/chunks/{chunk-MKL4CP2I.js → chunk-5ZSLZLDN.js} +631 -246
  121. package/dist/cli-bundle/chunks/chunk-5ZSLZLDN.js.map +1 -0
  122. package/dist/cli-bundle/chunks/{chunk-Q37E63AM.js → chunk-6CFNAVTF.js} +21 -141
  123. package/dist/cli-bundle/chunks/chunk-6CFNAVTF.js.map +7 -0
  124. package/dist/cli-bundle/chunks/{chunk-3TL7WOEF.js → chunk-6N2VXVTQ.js} +2 -2
  125. package/dist/cli-bundle/chunks/{chunk-ERL2YFJ2.js → chunk-6S3YSUYG.js} +3 -3
  126. package/dist/cli-bundle/chunks/{chunk-ZUKSZVBW.js → chunk-7B67ZL4N.js} +8 -7
  127. package/dist/cli-bundle/chunks/chunk-7B67ZL4N.js.map +7 -0
  128. package/dist/cli-bundle/chunks/{chunk-IA3YFTXT.js → chunk-7PIWCHTW.js} +11 -13
  129. package/dist/cli-bundle/chunks/chunk-7PIWCHTW.js.map +1 -0
  130. package/dist/cli-bundle/chunks/{chunk-BPD26E3P.js → chunk-7Z4LKRS4.js} +291 -81
  131. package/dist/cli-bundle/chunks/chunk-7Z4LKRS4.js.map +1 -0
  132. package/dist/cli-bundle/chunks/{chunk-IFZA4VB5.js → chunk-AHVTB5I5.js} +4 -4
  133. package/dist/cli-bundle/chunks/{chunk-DO5RGJXT.js → chunk-APRVSW2O.js} +3 -3
  134. package/dist/cli-bundle/chunks/{chunk-NAQYVWSQ.js → chunk-B7PE22W6.js} +4 -4
  135. package/dist/cli-bundle/chunks/{chunk-MD6ULIPJ.js → chunk-BCOFWYW4.js} +3 -3
  136. package/dist/cli-bundle/chunks/{chunk-KADLSPIU.js → chunk-BEP7WJA2.js} +4 -4
  137. package/dist/cli-bundle/chunks/chunk-BKVG6XOA.js +1114 -0
  138. package/dist/cli-bundle/chunks/chunk-BKVG6XOA.js.map +7 -0
  139. package/dist/cli-bundle/chunks/{chunk-AFWZRL7M.js → chunk-BSEQUTQP.js} +2 -2
  140. package/dist/cli-bundle/chunks/{chunk-AFWZRL7M.js.map → chunk-BSEQUTQP.js.map} +2 -2
  141. package/dist/cli-bundle/chunks/{chunk-OBDLEQG5.js → chunk-CRVF2JDM.js} +10 -10
  142. package/dist/cli-bundle/chunks/{chunk-FJZDA6MS.js → chunk-DM4H7FP4.js} +3 -3
  143. package/dist/cli-bundle/chunks/chunk-DUT67M43.js +5 -0
  144. package/dist/cli-bundle/chunks/{chunk-44LNIULG.js → chunk-DYH63FX7.js} +4 -4
  145. package/dist/cli-bundle/chunks/{chunk-LWTIRS3Y.js → chunk-E2OJMKML.js} +306 -82
  146. package/dist/cli-bundle/chunks/chunk-E2OJMKML.js.map +7 -0
  147. package/dist/cli-bundle/chunks/{chunk-HAMLIWAF.js → chunk-EAB64KLB.js} +4 -4
  148. package/dist/cli-bundle/chunks/{chunk-CIOZ376P.js → chunk-EACOH7AU.js} +10 -10
  149. package/dist/cli-bundle/chunks/{chunk-HL7V2PHX.js → chunk-EH2OPHBI.js} +10 -10
  150. package/dist/cli-bundle/chunks/{chunk-HL7V2PHX.js.map → chunk-EH2OPHBI.js.map} +1 -1
  151. package/dist/cli-bundle/chunks/{chunk-QK2ZN6UL.js → chunk-EJEXHTY5.js} +2 -2
  152. package/dist/cli-bundle/chunks/{chunk-WQUEHPZB.js → chunk-EYLCSJAI.js} +2 -2
  153. package/dist/cli-bundle/chunks/{chunk-655STMGA.js → chunk-FMBNM2EN.js} +2 -2
  154. package/dist/cli-bundle/chunks/{chunk-RMF3IOYQ.js → chunk-FNSPG7MU.js} +12 -12
  155. package/dist/cli-bundle/chunks/{chunk-5CT5BW6E.js → chunk-GM5QHQU6.js} +46 -40
  156. package/dist/cli-bundle/chunks/chunk-GM5QHQU6.js.map +7 -0
  157. package/dist/cli-bundle/chunks/{chunk-FTQLW4JD.js → chunk-GOSLKLFE.js} +418 -24
  158. package/dist/cli-bundle/chunks/chunk-GOSLKLFE.js.map +1 -0
  159. package/dist/cli-bundle/chunks/{chunk-KB726FMH.js → chunk-H2Z3FYXQ.js} +4 -4
  160. package/dist/cli-bundle/chunks/chunk-H3EIEWGR.js +162 -0
  161. package/dist/cli-bundle/chunks/chunk-H3EIEWGR.js.map +1 -0
  162. package/dist/cli-bundle/chunks/{chunk-2QIQGYPW.js → chunk-H5APFTHZ.js} +53 -10
  163. package/dist/cli-bundle/chunks/chunk-H5APFTHZ.js.map +7 -0
  164. package/dist/cli-bundle/chunks/chunk-HDH3JUGG.js +118 -0
  165. package/dist/cli-bundle/chunks/chunk-HDH3JUGG.js.map +1 -0
  166. package/dist/cli-bundle/chunks/{chunk-ZAYYDNB3.js → chunk-HO4KXD6I.js} +22 -142
  167. package/dist/cli-bundle/chunks/chunk-HO4KXD6I.js.map +1 -0
  168. package/dist/cli-bundle/chunks/{chunk-ILLUE5DI.js → chunk-HYB5AZ63.js} +203 -62
  169. package/dist/cli-bundle/chunks/{chunk-ILLUE5DI.js.map → chunk-HYB5AZ63.js.map} +3 -3
  170. package/dist/cli-bundle/chunks/{chunk-BN62TO2S.js → chunk-IA5FKNII.js} +2 -2
  171. package/dist/cli-bundle/chunks/{chunk-JL7WZ4O2.js → chunk-IG3SWA4A.js} +33 -9
  172. package/dist/cli-bundle/chunks/chunk-IG3SWA4A.js.map +7 -0
  173. package/dist/cli-bundle/chunks/{chunk-W6HZ55JO.js → chunk-IJIICKVW.js} +2 -2
  174. package/dist/cli-bundle/chunks/{chunk-IGED7NH2.js → chunk-ILX33QXL.js} +668 -251
  175. package/dist/cli-bundle/chunks/chunk-ILX33QXL.js.map +7 -0
  176. package/dist/cli-bundle/chunks/{chunk-UGTVWL3E.js → chunk-INU6DKT5.js} +47 -41
  177. package/dist/cli-bundle/chunks/chunk-INU6DKT5.js.map +1 -0
  178. package/dist/cli-bundle/chunks/{chunk-UB2QYSTO.js → chunk-J5AOEGDC.js} +26 -18
  179. package/dist/cli-bundle/chunks/chunk-J5AOEGDC.js.map +1 -0
  180. package/dist/cli-bundle/chunks/{chunk-4DY4KPQI.js → chunk-J6364LFM.js} +1330 -937
  181. package/dist/cli-bundle/chunks/chunk-J6364LFM.js.map +7 -0
  182. package/dist/cli-bundle/chunks/{chunk-DVOLZJ3C.js → chunk-J6EY5V4N.js} +1295 -939
  183. package/dist/cli-bundle/chunks/chunk-J6EY5V4N.js.map +1 -0
  184. package/dist/cli-bundle/chunks/chunk-JFTKLTEF.js +1097 -0
  185. package/dist/cli-bundle/chunks/chunk-JFTKLTEF.js.map +1 -0
  186. package/dist/cli-bundle/chunks/{chunk-M7EWN4TF.js → chunk-JOUQZENX.js} +3 -3
  187. package/dist/cli-bundle/chunks/{chunk-J4NZOP3I.js → chunk-JXQUXVMI.js} +9 -8
  188. package/dist/cli-bundle/chunks/chunk-JXQUXVMI.js.map +1 -0
  189. package/dist/cli-bundle/chunks/{chunk-2FNWQXZ2.js → chunk-JYFOV7FC.js} +4 -4
  190. package/dist/cli-bundle/chunks/{chunk-HLHSQ5CA.js → chunk-K2X6U4UA.js} +4 -4
  191. package/dist/cli-bundle/chunks/{chunk-6OTZMORS.js → chunk-K3WII2ME.js} +27 -27
  192. package/dist/cli-bundle/chunks/chunk-K3WII2ME.js.map +7 -0
  193. package/dist/cli-bundle/chunks/{chunk-M6ASXYCU.js → chunk-KG44YSKD.js} +4 -4
  194. package/dist/cli-bundle/chunks/{chunk-YVKE5ZDM.js → chunk-KPMKHGEA.js} +4 -4
  195. package/dist/cli-bundle/chunks/{chunk-QASRVKUQ.js → chunk-LPYWLWDS.js} +257 -163
  196. package/dist/cli-bundle/chunks/chunk-LPYWLWDS.js.map +1 -0
  197. package/dist/cli-bundle/chunks/{chunk-RGXD5JJR.js → chunk-LSG2U345.js} +19 -12
  198. package/dist/cli-bundle/chunks/chunk-LSG2U345.js.map +7 -0
  199. package/dist/cli-bundle/chunks/chunk-MIQDDLB5.js +5 -0
  200. package/dist/cli-bundle/chunks/{chunk-UJ4HJYWL.js → chunk-NLDFBC6J.js} +2 -2
  201. package/dist/cli-bundle/chunks/{chunk-WRKB56FC.js → chunk-NP22ERDF.js} +3 -3
  202. package/dist/cli-bundle/chunks/{chunk-YQYG2V23.js → chunk-NU3IMIEA.js} +2 -2
  203. package/dist/cli-bundle/chunks/{chunk-3I3LRT2G.js → chunk-NVPZIJVR.js} +2 -2
  204. package/dist/cli-bundle/chunks/{chunk-JAF4TUQ7.js → chunk-ODALILG3.js} +2 -2
  205. package/dist/cli-bundle/chunks/{chunk-CDJYP7OQ.js → chunk-ONG5V5CI.js} +190 -63
  206. package/dist/cli-bundle/chunks/chunk-ONG5V5CI.js.map +1 -0
  207. package/dist/cli-bundle/chunks/{chunk-QZ7LT3XE.js → chunk-ONREO4ST.js} +3 -3
  208. package/dist/cli-bundle/chunks/chunk-OW4JWD5M.js +61 -0
  209. package/dist/cli-bundle/chunks/chunk-OW4JWD5M.js.map +1 -0
  210. package/dist/cli-bundle/chunks/{chunk-3CMRNVTO.js → chunk-P74IZQ7A.js} +12 -12
  211. package/dist/cli-bundle/chunks/chunk-PENXZX3U.js +172 -0
  212. package/dist/cli-bundle/chunks/chunk-PENXZX3U.js.map +7 -0
  213. package/dist/cli-bundle/chunks/{chunk-ZTRBSABY.js → chunk-PGY23YTC.js} +3 -3
  214. package/dist/cli-bundle/chunks/{chunk-H2QBAKLQ.js → chunk-PMOSXADO.js} +3 -3
  215. package/dist/cli-bundle/chunks/chunk-PNTULOGU.js +9 -0
  216. package/dist/cli-bundle/chunks/{chunk-GSEADLRH.js → chunk-Q7A43DS4.js} +2 -2
  217. package/dist/cli-bundle/chunks/{chunk-QSPARJWF.js → chunk-QEHQ2GVG.js} +2 -2
  218. package/dist/cli-bundle/chunks/{chunk-VJTAEIPC.js → chunk-QIPLHNP7.js} +7 -7
  219. package/dist/cli-bundle/chunks/{chunk-GXXC7QSK.js → chunk-QKECXBBG.js} +3 -3
  220. package/dist/cli-bundle/chunks/{chunk-GXXC7QSK.js.map → chunk-QKECXBBG.js.map} +1 -1
  221. package/dist/cli-bundle/chunks/{chunk-K7WNZ7KD.js → chunk-QKJGPFAF.js} +3 -3
  222. package/dist/cli-bundle/chunks/{chunk-F7PSHRNO.js → chunk-QKXHFPYM.js} +27 -10
  223. package/dist/cli-bundle/chunks/chunk-QKXHFPYM.js.map +1 -0
  224. package/dist/cli-bundle/chunks/{chunk-ZNP64HOW.js → chunk-RLCHOOHC.js} +2 -2
  225. package/dist/cli-bundle/chunks/{chunk-IAPHYPRL.js → chunk-RMLWNPH2.js} +2 -2
  226. package/dist/cli-bundle/chunks/{chunk-UVBA6F5A.js → chunk-RRM5JYJC.js} +2 -2
  227. package/dist/cli-bundle/chunks/{chunk-6IIVBC56.js → chunk-S6MQESFR.js} +4 -4
  228. package/dist/cli-bundle/chunks/{chunk-QABYZYLU.js → chunk-SDQLJWBO.js} +4 -4
  229. package/dist/cli-bundle/chunks/{chunk-ANSJHDOZ.js → chunk-SELVXEZK.js} +2 -2
  230. package/dist/cli-bundle/chunks/{chunk-DYEX6NFH.js → chunk-TD3LVC7D.js} +438 -23
  231. package/dist/cli-bundle/chunks/chunk-TD3LVC7D.js.map +7 -0
  232. package/dist/cli-bundle/chunks/{chunk-WD6MSYMP.js → chunk-TKOVBP6C.js} +2 -2
  233. package/dist/cli-bundle/chunks/{chunk-TZ2PSLLT.js → chunk-TQSZFPIS.js} +4 -4
  234. package/dist/cli-bundle/chunks/{chunk-WPAWZW7S.js → chunk-TSMHDIW4.js} +2 -2
  235. package/dist/cli-bundle/chunks/{chunk-TZRTLMWM.js → chunk-UFXU44HV.js} +4 -4
  236. package/dist/cli-bundle/chunks/{chunk-TWLDBKQU.js → chunk-ULTHRDBP.js} +3 -3
  237. package/dist/cli-bundle/chunks/{chunk-OI4S4KCI.js → chunk-UMOPHQSU.js} +9 -9
  238. package/dist/cli-bundle/chunks/{chunk-OI4S4KCI.js.map → chunk-UMOPHQSU.js.map} +2 -2
  239. package/dist/cli-bundle/chunks/{chunk-RA5AIAMP.js → chunk-UOHFKBUV.js} +3 -3
  240. package/dist/cli-bundle/chunks/{chunk-PHKP3AGR.js → chunk-UWQHLMEB.js} +35 -18
  241. package/dist/cli-bundle/chunks/chunk-UWQHLMEB.js.map +7 -0
  242. package/dist/cli-bundle/chunks/{chunk-6TTOHMTB.js → chunk-UXONS674.js} +45 -112
  243. package/dist/cli-bundle/chunks/chunk-UXONS674.js.map +1 -0
  244. package/dist/cli-bundle/chunks/{chunk-4RXTMU57.js → chunk-UY2ACEMF.js} +7 -7
  245. package/dist/cli-bundle/chunks/{chunk-6PKA3SJQ.js → chunk-WQPUU7XD.js} +19 -28
  246. package/dist/cli-bundle/chunks/chunk-WQPUU7XD.js.map +1 -0
  247. package/dist/cli-bundle/chunks/{chunk-7TQMR6LK.js → chunk-WT3ZEOGH.js} +70 -20
  248. package/dist/cli-bundle/chunks/chunk-WT3ZEOGH.js.map +7 -0
  249. package/dist/cli-bundle/chunks/{chunk-FIGXOCEQ.js → chunk-WUJQK4YV.js} +4 -4
  250. package/dist/cli-bundle/chunks/{chunk-T4BRCB6Z.js → chunk-XSJUSQAE.js} +2 -2
  251. package/dist/cli-bundle/chunks/{chunk-6MHSBDGD.js → chunk-XXXF6PAQ.js} +50 -117
  252. package/dist/cli-bundle/chunks/chunk-XXXF6PAQ.js.map +7 -0
  253. package/dist/cli-bundle/chunks/{chunk-UKUIIBDW.js → chunk-YAQEBNY7.js} +4 -4
  254. package/dist/cli-bundle/chunks/{chunk-7QDSYUMF.js → chunk-YAROI3PD.js} +44 -21
  255. package/dist/cli-bundle/chunks/chunk-YAROI3PD.js.map +1 -0
  256. package/dist/cli-bundle/chunks/{chunk-E2WC6S4P.js → chunk-YBLZ2VE7.js} +13 -13
  257. package/dist/cli-bundle/chunks/{chunk-Y72FV7RM.js → chunk-YCQET3OT.js} +2 -2
  258. package/dist/cli-bundle/chunks/chunk-YUSOJDWM.js +9 -0
  259. package/dist/cli-bundle/chunks/chunk-YXSHIAUJ.js +58 -0
  260. package/dist/cli-bundle/chunks/chunk-YXSHIAUJ.js.map +1 -0
  261. package/dist/cli-bundle/chunks/{chunk-FS6UM5WH.js → chunk-ZI6VQWQ7.js} +4 -4
  262. package/dist/cli-bundle/chunks/chunk-ZKRZY773.js +68 -0
  263. package/dist/cli-bundle/chunks/chunk-ZKRZY773.js.map +7 -0
  264. package/dist/cli-bundle/chunks/{close-LZECOMHO.js → close-CWODTPKG.js} +5 -5
  265. package/dist/cli-bundle/chunks/close-W6LI2PKM.js +12 -0
  266. package/dist/cli-bundle/chunks/{close-many-ZHI6A5TN.js → close-many-CQFUY7MR.js} +15 -13
  267. package/dist/cli-bundle/chunks/close-many-DLDDVSH5.js +23 -0
  268. package/dist/cli-bundle/chunks/comments-E3TNTK24.js +13 -0
  269. package/dist/cli-bundle/chunks/{comments-AJWRTFZ5.js → comments-WGLHR7LB.js} +7 -7
  270. package/dist/cli-bundle/chunks/{copy-GMXYKBXT.js → copy-LXVDXH7B.js} +4 -4
  271. package/dist/cli-bundle/chunks/copy-Q5ZJPUKR.js +9 -0
  272. package/dist/cli-bundle/chunks/{create-F53OBTOU.js → create-J5U6ND4K.js} +9 -9
  273. package/dist/cli-bundle/chunks/{create-HU4Q7RJX.js → create-LBVCYMEG.js} +9 -9
  274. package/dist/cli-bundle/chunks/{delete-GSDZLTRC.js → delete-PMJBNY5G.js} +4 -4
  275. package/dist/cli-bundle/chunks/delete-WNHB3LYW.js +10 -0
  276. package/dist/cli-bundle/chunks/{deps-WWB7P2GT.js → deps-JZ7TMVCB.js} +7 -4
  277. package/dist/cli-bundle/chunks/{deps-U57I7EAK.js → deps-OA26IS25.js} +7 -4
  278. package/dist/cli-bundle/chunks/{docs-MQIY2ZQS.js → docs-FEWB2DQB.js} +6 -6
  279. package/dist/cli-bundle/chunks/docs-HA2AIDBB.js +14 -0
  280. package/dist/cli-bundle/chunks/{files-TBZD7V6H.js → files-6YFBJRBG.js} +6 -6
  281. package/dist/cli-bundle/chunks/{files-TTY6N2AV.js → files-EFIWKFTM.js} +6 -6
  282. package/dist/cli-bundle/chunks/{focus-XT6YVFFX.js → focus-4QJR7FOQ.js} +5 -5
  283. package/dist/cli-bundle/chunks/focus-POIW5LTJ.js +10 -0
  284. package/dist/cli-bundle/chunks/{history-compact-KKVUWB4V.js → history-compact-CKRPDTJN.js} +6 -10
  285. package/dist/cli-bundle/chunks/history-compact-FWG2C7FZ.js +16 -0
  286. package/dist/cli-bundle/chunks/history-redact-BB3TGDAE.js +15 -0
  287. package/dist/cli-bundle/chunks/{history-redact-3DVZOILD.js → history-redact-D225BHOZ.js} +5 -6
  288. package/dist/cli-bundle/chunks/history-repair-6GEAM7HE.js +16 -0
  289. package/dist/cli-bundle/chunks/{history-repair-ITDUMK4N.js → history-repair-RQXKQHL4.js} +6 -8
  290. package/dist/cli-bundle/chunks/{learnings-FGO3NSFW.js → learnings-JLNLCOL5.js} +7 -7
  291. package/dist/cli-bundle/chunks/learnings-RSNLSWDC.js +13 -0
  292. package/dist/cli-bundle/chunks/notes-2WDH6DXU.js +13 -0
  293. package/dist/cli-bundle/chunks/{notes-NQ6RXVW6.js → notes-GB47XXQQ.js} +7 -7
  294. package/dist/cli-bundle/chunks/plan-DOVI2VMW.js +24 -0
  295. package/dist/cli-bundle/chunks/{plan-2NNEO46V.js → plan-VDCJ2PCN.js} +10 -10
  296. package/dist/cli-bundle/chunks/{profile-AAQUU6T3.js → profile-FAU7NZML.js} +10 -10
  297. package/dist/cli-bundle/chunks/{profile-U725ATWZ.js → profile-IVXQEL3D.js} +10 -10
  298. package/dist/cli-bundle/chunks/{register-list-query-BUWCYHBT.js → register-list-query-DKA3EH5D.js} +22 -19
  299. package/dist/cli-bundle/chunks/register-list-query-DKA3EH5D.js.map +7 -0
  300. package/dist/cli-bundle/chunks/{register-list-query-KTZ6AGE7.js → register-list-query-UL4UKBBN.js} +23 -20
  301. package/dist/cli-bundle/chunks/register-list-query-UL4UKBBN.js.map +1 -0
  302. package/dist/cli-bundle/chunks/{register-mutation-UELYYOR7.js → register-mutation-ARFHRW55.js} +36 -32
  303. package/dist/cli-bundle/chunks/{register-mutation-UELYYOR7.js.map → register-mutation-ARFHRW55.js.map} +2 -2
  304. package/dist/cli-bundle/chunks/{register-mutation-4FMGJJF7.js → register-mutation-RBBJ52DK.js} +37 -33
  305. package/dist/cli-bundle/chunks/register-mutation-RBBJ52DK.js.map +1 -0
  306. package/dist/cli-bundle/chunks/{register-operations-JVW24J2Y.js → register-operations-ZIBBRSED.js} +41 -39
  307. package/dist/cli-bundle/chunks/{register-operations-JVW24J2Y.js.map → register-operations-ZIBBRSED.js.map} +1 -1
  308. package/dist/cli-bundle/chunks/{register-operations-ISUX6LY5.js → register-operations-ZUJ5JWPE.js} +39 -37
  309. package/dist/cli-bundle/chunks/{register-operations-ISUX6LY5.js.map → register-operations-ZUJ5JWPE.js.map} +1 -1
  310. package/dist/cli-bundle/chunks/{register-setup-5XNGKJ22.js → register-setup-BCVLFEYS.js} +29 -17
  311. package/dist/cli-bundle/chunks/{register-setup-5XNGKJ22.js.map → register-setup-BCVLFEYS.js.map} +2 -2
  312. package/dist/cli-bundle/chunks/{register-setup-ZTNY6S7R.js → register-setup-TDCGWIOS.js} +19 -18
  313. package/dist/cli-bundle/chunks/{register-setup-ZTNY6S7R.js.map → register-setup-TDCGWIOS.js.map} +1 -1
  314. package/dist/cli-bundle/chunks/{restore-B3BAB6X2.js → restore-25DLT2Q2.js} +6 -6
  315. package/dist/cli-bundle/chunks/restore-YPMVUUEX.js +14 -0
  316. package/dist/cli-bundle/chunks/{schema-U7IM2DXV.js → schema-FNU3WE4O.js} +7 -6
  317. package/dist/cli-bundle/chunks/{schema-LZNUYHDB.js → schema-NBCM3RAD.js} +7 -6
  318. package/dist/cli-bundle/chunks/update-WWBYOPXO.js +21 -0
  319. package/dist/cli-bundle/chunks/update-WWBYOPXO.js.map +7 -0
  320. package/dist/cli-bundle/chunks/{update-Q3UCILNR.js → update-XHSIAIXE.js} +12 -12
  321. package/dist/cli-bundle/chunks/update-XHSIAIXE.js.map +1 -0
  322. package/dist/cli-bundle/chunks/update-many-OUGIU5SF.js +32 -0
  323. package/dist/cli-bundle/chunks/update-many-OUGIU5SF.js.map +7 -0
  324. package/dist/cli-bundle/chunks/update-many-TA7NGQBO.js +36 -0
  325. package/dist/cli-bundle/chunks/update-many-TA7NGQBO.js.map +1 -0
  326. package/dist/cli-bundle/main.js +826 -43
  327. package/dist/cli-bundle/main.js.map +4 -4
  328. package/dist/cli-bundle/sdk-runtime.js +70 -57
  329. package/dist/cli-bundle/sdk-testing.js +6 -6
  330. package/dist/cli-bundle/sdk.js +876 -74
  331. package/dist/cli-bundle/sdk.js.map +4 -4
  332. package/dist/cli.js +5 -4
  333. package/dist/cli.js.map +1 -1
  334. package/dist/core/diagnostics/remediation.js +12 -2
  335. package/dist/core/diagnostics/remediation.js.map +1 -1
  336. package/dist/core/history/projection.d.ts +39 -0
  337. package/dist/core/history/projection.js +164 -0
  338. package/dist/core/history/projection.js.map +1 -0
  339. package/dist/core/history/read.d.ts +3 -0
  340. package/dist/core/history/read.js +55 -0
  341. package/dist/core/history/read.js.map +1 -0
  342. package/dist/core/output/output-control.d.ts +18 -0
  343. package/dist/core/output/output-control.js +26 -0
  344. package/dist/core/output/output-control.js.map +1 -0
  345. package/dist/core/output/output.js +20 -8
  346. package/dist/core/output/output.js.map +1 -1
  347. package/dist/core/sentry/helpers.js +10 -2
  348. package/dist/core/sentry/helpers.js.map +1 -1
  349. package/dist/core/shared/command-types.d.ts +2 -0
  350. package/dist/core/shared/command-types.js +2 -2
  351. package/dist/core/shared/command-types.js.map +1 -1
  352. package/dist/core/shared/errors.d.ts +11 -0
  353. package/dist/core/shared/errors.js +2 -2
  354. package/dist/core/shared/errors.js.map +1 -1
  355. package/dist/mcp/server.d.ts +2 -2
  356. package/dist/mcp/tool-definitions.js +5 -5
  357. package/dist/mcp/tool-definitions.js.map +1 -1
  358. package/dist/sdk/author-attribution.d.ts +35 -0
  359. package/dist/sdk/author-attribution.js +118 -0
  360. package/dist/sdk/author-attribution.js.map +1 -0
  361. package/dist/sdk/cli-contracts/command-aliases.d.ts +7 -0
  362. package/dist/sdk/cli-contracts/command-aliases.js +17 -0
  363. package/dist/sdk/cli-contracts/command-aliases.js.map +1 -0
  364. package/dist/sdk/cli-contracts/flag-contracts.js +5 -2
  365. package/dist/sdk/cli-contracts/flag-contracts.js.map +1 -1
  366. package/dist/sdk/cli-contracts/tool-option-contracts.js +6 -2
  367. package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -1
  368. package/dist/sdk/cli-contracts/tool-parameter-tables.js +21 -2
  369. package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
  370. package/dist/sdk/cli-contracts/tool-schema.js +3 -3
  371. package/dist/sdk/cli-contracts/tool-schema.js.map +1 -1
  372. package/dist/sdk/cli-contracts.d.ts +1 -0
  373. package/dist/sdk/cli-contracts.js +3 -2
  374. package/dist/sdk/cli-contracts.js.map +1 -1
  375. package/dist/sdk/cli-program.d.ts +8 -0
  376. package/dist/sdk/cli-program.js +39 -0
  377. package/dist/sdk/cli-program.js.map +1 -0
  378. package/dist/sdk/command-line.d.ts +11 -0
  379. package/dist/sdk/command-line.js +40 -0
  380. package/dist/sdk/command-line.js.map +1 -0
  381. package/dist/sdk/config.d.ts +163 -0
  382. package/dist/sdk/config.js +1087 -0
  383. package/dist/sdk/config.js.map +1 -0
  384. package/dist/sdk/context-relevance.d.ts +21 -0
  385. package/dist/sdk/context-relevance.js +70 -2
  386. package/dist/sdk/context-relevance.js.map +1 -1
  387. package/dist/sdk/dependencies.d.ts +15 -2
  388. package/dist/sdk/dependencies.js +97 -8
  389. package/dist/sdk/dependencies.js.map +1 -1
  390. package/dist/{cli/commands → sdk}/extension/bundled-catalog.d.ts +1 -1
  391. package/dist/{cli/commands → sdk}/extension/bundled-catalog.js +12 -12
  392. package/dist/sdk/extension/bundled-catalog.js.map +1 -0
  393. package/dist/sdk/extension/concurrency.d.ts +7 -0
  394. package/dist/sdk/extension/concurrency.js +26 -0
  395. package/dist/sdk/extension/concurrency.js.map +1 -0
  396. package/dist/sdk/extension/describe.d.ts +91 -0
  397. package/dist/sdk/extension/describe.js +144 -0
  398. package/dist/sdk/extension/describe.js.map +1 -0
  399. package/dist/{cli/commands → sdk}/extension/doctor.d.ts +3 -3
  400. package/dist/{cli/commands → sdk}/extension/doctor.js +7 -7
  401. package/dist/sdk/extension/doctor.js.map +1 -0
  402. package/dist/sdk/extension/install-runtime.d.ts +26 -0
  403. package/dist/sdk/extension/install-runtime.js +269 -0
  404. package/dist/sdk/extension/install-runtime.js.map +1 -0
  405. package/dist/sdk/extension/install-snapshot.d.ts +23 -0
  406. package/dist/sdk/extension/install-snapshot.js +66 -0
  407. package/dist/sdk/extension/install-snapshot.js.map +1 -0
  408. package/dist/{cli/commands → sdk}/extension/install-sources.d.ts +3 -3
  409. package/dist/{cli/commands → sdk}/extension/install-sources.js +15 -12
  410. package/dist/sdk/extension/install-sources.js.map +1 -0
  411. package/dist/{cli/commands → sdk}/extension/managed-state.js +6 -6
  412. package/dist/sdk/extension/managed-state.js.map +1 -0
  413. package/dist/sdk/extension/scaffold.d.ts +36 -0
  414. package/dist/sdk/extension/scaffold.js +2436 -0
  415. package/dist/sdk/extension/scaffold.js.map +1 -0
  416. package/dist/sdk/extension/shared.d.ts +28 -0
  417. package/dist/sdk/extension/shared.js +140 -0
  418. package/dist/sdk/extension/shared.js.map +1 -0
  419. package/dist/sdk/extension/update-check.d.ts +15 -0
  420. package/dist/sdk/extension/update-check.js +68 -0
  421. package/dist/sdk/extension/update-check.js.map +1 -0
  422. package/dist/sdk/extension.d.ts +367 -0
  423. package/dist/sdk/extension.js +2174 -0
  424. package/dist/sdk/extension.js.map +1 -0
  425. package/dist/sdk/governance/gc.d.ts +56 -0
  426. package/dist/sdk/governance/gc.js +276 -0
  427. package/dist/sdk/governance/gc.js.map +1 -0
  428. package/dist/sdk/governance/health.d.ts +187 -0
  429. package/dist/sdk/governance/health.js +1796 -0
  430. package/dist/sdk/governance/health.js.map +1 -0
  431. package/dist/sdk/governance/validate.d.ts +255 -0
  432. package/dist/sdk/governance/validate.js +2175 -0
  433. package/dist/sdk/governance/validate.js.map +1 -0
  434. package/dist/sdk/history-compact.d.ts +142 -0
  435. package/dist/sdk/history-compact.js +508 -0
  436. package/dist/sdk/history-compact.js.map +1 -0
  437. package/dist/sdk/history-mcp.d.ts +17 -0
  438. package/dist/sdk/history-mcp.js +68 -0
  439. package/dist/sdk/history-mcp.js.map +1 -0
  440. package/dist/sdk/history-read.d.ts +31 -0
  441. package/dist/sdk/history-read.js +58 -0
  442. package/dist/sdk/history-read.js.map +1 -0
  443. package/dist/sdk/history-redact.d.ts +120 -0
  444. package/dist/sdk/history-redact.js +577 -0
  445. package/dist/sdk/history-redact.js.map +1 -0
  446. package/dist/sdk/history-repair.d.ts +89 -0
  447. package/dist/sdk/history-repair.js +263 -0
  448. package/dist/sdk/history-repair.js.map +1 -0
  449. package/dist/sdk/index.d.ts +25 -1
  450. package/dist/sdk/index.js +27 -3
  451. package/dist/sdk/index.js.map +1 -1
  452. package/dist/sdk/init-agent-guidance.d.ts +113 -0
  453. package/dist/sdk/init-agent-guidance.js +437 -0
  454. package/dist/sdk/init-agent-guidance.js.map +1 -0
  455. package/dist/sdk/init.d.ts +186 -0
  456. package/dist/sdk/init.js +733 -0
  457. package/dist/sdk/init.js.map +1 -0
  458. package/dist/sdk/invocation-author.d.ts +2 -0
  459. package/dist/sdk/invocation-author.js +39 -0
  460. package/dist/sdk/invocation-author.js.map +1 -0
  461. package/dist/sdk/item-children.d.ts +45 -0
  462. package/dist/sdk/item-children.js +75 -0
  463. package/dist/sdk/item-children.js.map +1 -0
  464. package/dist/sdk/item-schedule.d.ts +26 -0
  465. package/dist/sdk/item-schedule.js +28 -0
  466. package/dist/sdk/item-schedule.js.map +1 -0
  467. package/dist/sdk/output.d.ts +7 -0
  468. package/dist/sdk/output.js +11 -0
  469. package/dist/sdk/output.js.map +1 -0
  470. package/dist/sdk/pagination.d.ts +4 -1
  471. package/dist/sdk/pagination.js +13 -5
  472. package/dist/sdk/pagination.js.map +1 -1
  473. package/dist/sdk/profile.d.ts +176 -0
  474. package/dist/sdk/profile.js +431 -0
  475. package/dist/sdk/profile.js.map +1 -0
  476. package/dist/sdk/relationship-analytics.d.ts +108 -0
  477. package/dist/sdk/relationship-analytics.js +292 -0
  478. package/dist/sdk/relationship-analytics.js.map +1 -0
  479. package/dist/sdk/relationship-context.d.ts +67 -0
  480. package/dist/sdk/relationship-context.js +207 -0
  481. package/dist/sdk/relationship-context.js.map +1 -0
  482. package/dist/sdk/relationship-history.d.ts +109 -0
  483. package/dist/sdk/relationship-history.js +401 -0
  484. package/dist/sdk/relationship-history.js.map +1 -0
  485. package/dist/sdk/relationships.d.ts +145 -0
  486. package/dist/sdk/relationships.js +551 -0
  487. package/dist/sdk/relationships.js.map +1 -0
  488. package/dist/sdk/runtime-input.d.ts +10 -0
  489. package/dist/sdk/runtime-input.js +60 -0
  490. package/dist/sdk/runtime-input.js.map +1 -0
  491. package/dist/sdk/runtime.d.ts +31 -8
  492. package/dist/sdk/runtime.js +61 -57
  493. package/dist/sdk/runtime.js.map +1 -1
  494. package/dist/sdk/schema.d.ts +507 -0
  495. package/dist/sdk/schema.js +1269 -0
  496. package/dist/sdk/schema.js.map +1 -0
  497. package/dist/{cli/commands → sdk}/templates.d.ts +1 -1
  498. package/dist/{cli/commands → sdk}/templates.js +9 -9
  499. package/dist/sdk/templates.js.map +1 -0
  500. package/dist/{cli/commands → sdk}/test/linked-command-detection.d.ts +10 -2
  501. package/dist/sdk/test/linked-command-detection.js +525 -0
  502. package/dist/sdk/test/linked-command-detection.js.map +1 -0
  503. package/docs/COMMANDS.md +58 -40
  504. package/docs/EXTENSIONS.md +10 -1
  505. package/docs/RELATIONSHIP_GRAPH.md +113 -0
  506. package/docs/RELEASING.md +2 -0
  507. package/docs/SDK.md +156 -9
  508. package/docs/SDK_CUSTOMIZATION_PRIMITIVES.md +79 -0
  509. package/marketplace.json +2 -2
  510. package/package.json +3 -2
  511. package/packages/pm-beads/package.json +1 -1
  512. package/packages/pm-calendar/package.json +1 -1
  513. package/packages/pm-command-kit/package.json +1 -1
  514. package/packages/pm-governance-audit/extensions/governance-audit/runtime-utils.ts +76 -16
  515. package/packages/pm-governance-audit/extensions/governance-audit/sdk.ts +8 -0
  516. package/packages/pm-governance-audit/package.json +1 -1
  517. package/packages/pm-guide-shell/package.json +1 -1
  518. package/packages/pm-kanban/package.json +1 -1
  519. package/packages/pm-lifecycle-hooks/package.json +1 -1
  520. package/packages/pm-linked-test-adapters/package.json +1 -1
  521. package/packages/pm-search-advanced/package.json +1 -1
  522. package/packages/pm-templates/package.json +1 -1
  523. package/packages/pm-todos/package.json +1 -1
  524. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  525. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  526. package/scripts/bundle-cli.mjs +66 -23
  527. package/dist/cli/commands/extension/bundled-catalog.js.map +0 -1
  528. package/dist/cli/commands/extension/doctor.js.map +0 -1
  529. package/dist/cli/commands/extension/install-sources.js.map +0 -1
  530. package/dist/cli/commands/extension/managed-state.js.map +0 -1
  531. package/dist/cli/commands/templates.js.map +0 -1
  532. package/dist/cli/commands/test/linked-command-detection.js +0 -248
  533. package/dist/cli/commands/test/linked-command-detection.js.map +0 -1
  534. package/dist/cli-bundle/chunks/append-DYQWQK2J.js +0 -11
  535. package/dist/cli-bundle/chunks/chunk-2GA3NK35.js +0 -530
  536. package/dist/cli-bundle/chunks/chunk-2GA3NK35.js.map +0 -1
  537. package/dist/cli-bundle/chunks/chunk-2QIQGYPW.js.map +0 -7
  538. package/dist/cli-bundle/chunks/chunk-4DY4KPQI.js.map +0 -7
  539. package/dist/cli-bundle/chunks/chunk-4WREH7RT.js +0 -554
  540. package/dist/cli-bundle/chunks/chunk-4WREH7RT.js.map +0 -7
  541. package/dist/cli-bundle/chunks/chunk-5CT5BW6E.js.map +0 -7
  542. package/dist/cli-bundle/chunks/chunk-5URI7TPJ.js.map +0 -7
  543. package/dist/cli-bundle/chunks/chunk-6MHSBDGD.js.map +0 -7
  544. package/dist/cli-bundle/chunks/chunk-6OTZMORS.js.map +0 -7
  545. package/dist/cli-bundle/chunks/chunk-6PKA3SJQ.js.map +0 -1
  546. package/dist/cli-bundle/chunks/chunk-6TTOHMTB.js.map +0 -1
  547. package/dist/cli-bundle/chunks/chunk-7QDSYUMF.js.map +0 -1
  548. package/dist/cli-bundle/chunks/chunk-7TQMR6LK.js.map +0 -7
  549. package/dist/cli-bundle/chunks/chunk-B5DZYTT3.js +0 -312
  550. package/dist/cli-bundle/chunks/chunk-B5DZYTT3.js.map +0 -7
  551. package/dist/cli-bundle/chunks/chunk-BPD26E3P.js.map +0 -1
  552. package/dist/cli-bundle/chunks/chunk-CDJYP7OQ.js.map +0 -1
  553. package/dist/cli-bundle/chunks/chunk-DBZVUJTK.js +0 -858
  554. package/dist/cli-bundle/chunks/chunk-DBZVUJTK.js.map +0 -1
  555. package/dist/cli-bundle/chunks/chunk-DVOLZJ3C.js.map +0 -1
  556. package/dist/cli-bundle/chunks/chunk-DYEX6NFH.js.map +0 -7
  557. package/dist/cli-bundle/chunks/chunk-F7PSHRNO.js.map +0 -1
  558. package/dist/cli-bundle/chunks/chunk-FO7GMJKG.js +0 -875
  559. package/dist/cli-bundle/chunks/chunk-FO7GMJKG.js.map +0 -7
  560. package/dist/cli-bundle/chunks/chunk-FTQLW4JD.js.map +0 -1
  561. package/dist/cli-bundle/chunks/chunk-IA3YFTXT.js.map +0 -1
  562. package/dist/cli-bundle/chunks/chunk-IGED7NH2.js.map +0 -7
  563. package/dist/cli-bundle/chunks/chunk-J4NZOP3I.js.map +0 -1
  564. package/dist/cli-bundle/chunks/chunk-JL7WZ4O2.js.map +0 -7
  565. package/dist/cli-bundle/chunks/chunk-L24HCJFC.js +0 -309
  566. package/dist/cli-bundle/chunks/chunk-L24HCJFC.js.map +0 -1
  567. package/dist/cli-bundle/chunks/chunk-LWTIRS3Y.js.map +0 -7
  568. package/dist/cli-bundle/chunks/chunk-MKL4CP2I.js.map +0 -1
  569. package/dist/cli-bundle/chunks/chunk-N3CMP4NI.js.map +0 -1
  570. package/dist/cli-bundle/chunks/chunk-PHKP3AGR.js.map +0 -7
  571. package/dist/cli-bundle/chunks/chunk-Q37E63AM.js.map +0 -7
  572. package/dist/cli-bundle/chunks/chunk-QASRVKUQ.js.map +0 -1
  573. package/dist/cli-bundle/chunks/chunk-RGXD5JJR.js.map +0 -7
  574. package/dist/cli-bundle/chunks/chunk-UB2QYSTO.js.map +0 -1
  575. package/dist/cli-bundle/chunks/chunk-UGTVWL3E.js.map +0 -1
  576. package/dist/cli-bundle/chunks/chunk-ZAYYDNB3.js.map +0 -1
  577. package/dist/cli-bundle/chunks/chunk-ZUKSZVBW.js.map +0 -7
  578. package/dist/cli-bundle/chunks/close-RI4JQQHU.js +0 -12
  579. package/dist/cli-bundle/chunks/close-many-LY2XJ52M.js +0 -21
  580. package/dist/cli-bundle/chunks/comments-35M273DN.js +0 -13
  581. package/dist/cli-bundle/chunks/copy-NPYM7M7U.js +0 -9
  582. package/dist/cli-bundle/chunks/delete-ODRWJWAM.js +0 -10
  583. package/dist/cli-bundle/chunks/docs-G7N4E2JO.js +0 -14
  584. package/dist/cli-bundle/chunks/focus-U5TRVCRS.js +0 -10
  585. package/dist/cli-bundle/chunks/history-compact-M7GHYVFN.js +0 -20
  586. package/dist/cli-bundle/chunks/history-redact-JIHZLHDP.js +0 -16
  587. package/dist/cli-bundle/chunks/history-repair-NAFCHLH7.js +0 -18
  588. package/dist/cli-bundle/chunks/learnings-SONGPSHI.js +0 -13
  589. package/dist/cli-bundle/chunks/notes-BSD53H2W.js +0 -13
  590. package/dist/cli-bundle/chunks/plan-AWLYGBNV.js +0 -24
  591. package/dist/cli-bundle/chunks/register-list-query-BUWCYHBT.js.map +0 -7
  592. package/dist/cli-bundle/chunks/register-list-query-KTZ6AGE7.js.map +0 -1
  593. package/dist/cli-bundle/chunks/register-mutation-4FMGJJF7.js.map +0 -1
  594. package/dist/cli-bundle/chunks/restore-66GLMHIX.js +0 -14
  595. package/dist/cli-bundle/chunks/update-2XGHIVQ2.js +0 -21
  596. package/dist/cli-bundle/chunks/update-many-75K57FS3.js +0 -34
  597. package/dist/cli-bundle/chunks/update-many-U42YA445.js +0 -30
  598. /package/dist/cli-bundle/chunks/{append-PVZJDM6J.js.map → append-OJQFUQ4T.js.map} +0 -0
  599. /package/dist/cli-bundle/chunks/{append-DYQWQK2J.js.map → append-UZVHUO74.js.map} +0 -0
  600. /package/dist/cli-bundle/chunks/{chunk-MQZ3PLCF.js.map → chunk-2IFFUZLC.js.map} +0 -0
  601. /package/dist/cli-bundle/chunks/{chunk-P6MYFH6K.js.map → chunk-2JKGO6QX.js.map} +0 -0
  602. /package/dist/cli-bundle/chunks/{chunk-X3GYR4P2.js.map → chunk-2NCIPMQP.js.map} +0 -0
  603. /package/dist/cli-bundle/chunks/{chunk-Q7E6OYZK.js.map → chunk-2VPAVL7O.js.map} +0 -0
  604. /package/dist/cli-bundle/chunks/{chunk-DRNJPEPQ.js.map → chunk-2WSE6PO2.js.map} +0 -0
  605. /package/dist/cli-bundle/chunks/{chunk-FDSBDNYE.js.map → chunk-34L5OT3Y.js.map} +0 -0
  606. /package/dist/cli-bundle/chunks/{chunk-TH7U4KLY.js.map → chunk-3AUGG2DP.js.map} +0 -0
  607. /package/dist/cli-bundle/chunks/{chunk-NKW36AMT.js.map → chunk-3CLU2XZO.js.map} +0 -0
  608. /package/dist/cli-bundle/chunks/{chunk-ABRCOSDC.js.map → chunk-3WM75PWC.js.map} +0 -0
  609. /package/dist/cli-bundle/chunks/{chunk-X6BVXQ52.js.map → chunk-5JLUII3O.js.map} +0 -0
  610. /package/dist/cli-bundle/chunks/{chunk-3TL7WOEF.js.map → chunk-6N2VXVTQ.js.map} +0 -0
  611. /package/dist/cli-bundle/chunks/{chunk-ERL2YFJ2.js.map → chunk-6S3YSUYG.js.map} +0 -0
  612. /package/dist/cli-bundle/chunks/{chunk-IFZA4VB5.js.map → chunk-AHVTB5I5.js.map} +0 -0
  613. /package/dist/cli-bundle/chunks/{chunk-DO5RGJXT.js.map → chunk-APRVSW2O.js.map} +0 -0
  614. /package/dist/cli-bundle/chunks/{chunk-NAQYVWSQ.js.map → chunk-B7PE22W6.js.map} +0 -0
  615. /package/dist/cli-bundle/chunks/{chunk-MD6ULIPJ.js.map → chunk-BCOFWYW4.js.map} +0 -0
  616. /package/dist/cli-bundle/chunks/{chunk-KADLSPIU.js.map → chunk-BEP7WJA2.js.map} +0 -0
  617. /package/dist/cli-bundle/chunks/{chunk-OBDLEQG5.js.map → chunk-CRVF2JDM.js.map} +0 -0
  618. /package/dist/cli-bundle/chunks/{chunk-FJZDA6MS.js.map → chunk-DM4H7FP4.js.map} +0 -0
  619. /package/dist/cli-bundle/chunks/{close-LZECOMHO.js.map → chunk-DUT67M43.js.map} +0 -0
  620. /package/dist/cli-bundle/chunks/{chunk-44LNIULG.js.map → chunk-DYH63FX7.js.map} +0 -0
  621. /package/dist/cli-bundle/chunks/{chunk-HAMLIWAF.js.map → chunk-EAB64KLB.js.map} +0 -0
  622. /package/dist/cli-bundle/chunks/{chunk-CIOZ376P.js.map → chunk-EACOH7AU.js.map} +0 -0
  623. /package/dist/cli-bundle/chunks/{chunk-QK2ZN6UL.js.map → chunk-EJEXHTY5.js.map} +0 -0
  624. /package/dist/cli-bundle/chunks/{chunk-WQUEHPZB.js.map → chunk-EYLCSJAI.js.map} +0 -0
  625. /package/dist/cli-bundle/chunks/{chunk-655STMGA.js.map → chunk-FMBNM2EN.js.map} +0 -0
  626. /package/dist/cli-bundle/chunks/{chunk-RMF3IOYQ.js.map → chunk-FNSPG7MU.js.map} +0 -0
  627. /package/dist/cli-bundle/chunks/{chunk-KB726FMH.js.map → chunk-H2Z3FYXQ.js.map} +0 -0
  628. /package/dist/cli-bundle/chunks/{chunk-BN62TO2S.js.map → chunk-IA5FKNII.js.map} +0 -0
  629. /package/dist/cli-bundle/chunks/{chunk-W6HZ55JO.js.map → chunk-IJIICKVW.js.map} +0 -0
  630. /package/dist/cli-bundle/chunks/{chunk-M7EWN4TF.js.map → chunk-JOUQZENX.js.map} +0 -0
  631. /package/dist/cli-bundle/chunks/{chunk-2FNWQXZ2.js.map → chunk-JYFOV7FC.js.map} +0 -0
  632. /package/dist/cli-bundle/chunks/{chunk-HLHSQ5CA.js.map → chunk-K2X6U4UA.js.map} +0 -0
  633. /package/dist/cli-bundle/chunks/{chunk-M6ASXYCU.js.map → chunk-KG44YSKD.js.map} +0 -0
  634. /package/dist/cli-bundle/chunks/{chunk-YVKE5ZDM.js.map → chunk-KPMKHGEA.js.map} +0 -0
  635. /package/dist/cli-bundle/chunks/{close-many-ZHI6A5TN.js.map → chunk-MIQDDLB5.js.map} +0 -0
  636. /package/dist/cli-bundle/chunks/{chunk-UJ4HJYWL.js.map → chunk-NLDFBC6J.js.map} +0 -0
  637. /package/dist/cli-bundle/chunks/{chunk-WRKB56FC.js.map → chunk-NP22ERDF.js.map} +0 -0
  638. /package/dist/cli-bundle/chunks/{chunk-YQYG2V23.js.map → chunk-NU3IMIEA.js.map} +0 -0
  639. /package/dist/cli-bundle/chunks/{chunk-3I3LRT2G.js.map → chunk-NVPZIJVR.js.map} +0 -0
  640. /package/dist/cli-bundle/chunks/{chunk-JAF4TUQ7.js.map → chunk-ODALILG3.js.map} +0 -0
  641. /package/dist/cli-bundle/chunks/{chunk-QZ7LT3XE.js.map → chunk-ONREO4ST.js.map} +0 -0
  642. /package/dist/cli-bundle/chunks/{chunk-3CMRNVTO.js.map → chunk-P74IZQ7A.js.map} +0 -0
  643. /package/dist/cli-bundle/chunks/{chunk-ZTRBSABY.js.map → chunk-PGY23YTC.js.map} +0 -0
  644. /package/dist/cli-bundle/chunks/{chunk-H2QBAKLQ.js.map → chunk-PMOSXADO.js.map} +0 -0
  645. /package/dist/cli-bundle/chunks/{close-RI4JQQHU.js.map → chunk-PNTULOGU.js.map} +0 -0
  646. /package/dist/cli-bundle/chunks/{chunk-GSEADLRH.js.map → chunk-Q7A43DS4.js.map} +0 -0
  647. /package/dist/cli-bundle/chunks/{chunk-QSPARJWF.js.map → chunk-QEHQ2GVG.js.map} +0 -0
  648. /package/dist/cli-bundle/chunks/{chunk-VJTAEIPC.js.map → chunk-QIPLHNP7.js.map} +0 -0
  649. /package/dist/cli-bundle/chunks/{chunk-K7WNZ7KD.js.map → chunk-QKJGPFAF.js.map} +0 -0
  650. /package/dist/cli-bundle/chunks/{chunk-ZNP64HOW.js.map → chunk-RLCHOOHC.js.map} +0 -0
  651. /package/dist/cli-bundle/chunks/{chunk-IAPHYPRL.js.map → chunk-RMLWNPH2.js.map} +0 -0
  652. /package/dist/cli-bundle/chunks/{chunk-UVBA6F5A.js.map → chunk-RRM5JYJC.js.map} +0 -0
  653. /package/dist/cli-bundle/chunks/{chunk-6IIVBC56.js.map → chunk-S6MQESFR.js.map} +0 -0
  654. /package/dist/cli-bundle/chunks/{chunk-QABYZYLU.js.map → chunk-SDQLJWBO.js.map} +0 -0
  655. /package/dist/cli-bundle/chunks/{chunk-ANSJHDOZ.js.map → chunk-SELVXEZK.js.map} +0 -0
  656. /package/dist/cli-bundle/chunks/{chunk-WD6MSYMP.js.map → chunk-TKOVBP6C.js.map} +0 -0
  657. /package/dist/cli-bundle/chunks/{chunk-TZ2PSLLT.js.map → chunk-TQSZFPIS.js.map} +0 -0
  658. /package/dist/cli-bundle/chunks/{chunk-WPAWZW7S.js.map → chunk-TSMHDIW4.js.map} +0 -0
  659. /package/dist/cli-bundle/chunks/{chunk-TZRTLMWM.js.map → chunk-UFXU44HV.js.map} +0 -0
  660. /package/dist/cli-bundle/chunks/{chunk-TWLDBKQU.js.map → chunk-ULTHRDBP.js.map} +0 -0
  661. /package/dist/cli-bundle/chunks/{chunk-RA5AIAMP.js.map → chunk-UOHFKBUV.js.map} +0 -0
  662. /package/dist/cli-bundle/chunks/{chunk-4RXTMU57.js.map → chunk-UY2ACEMF.js.map} +0 -0
  663. /package/dist/cli-bundle/chunks/{chunk-FIGXOCEQ.js.map → chunk-WUJQK4YV.js.map} +0 -0
  664. /package/dist/cli-bundle/chunks/{chunk-T4BRCB6Z.js.map → chunk-XSJUSQAE.js.map} +0 -0
  665. /package/dist/cli-bundle/chunks/{chunk-UKUIIBDW.js.map → chunk-YAQEBNY7.js.map} +0 -0
  666. /package/dist/cli-bundle/chunks/{chunk-E2WC6S4P.js.map → chunk-YBLZ2VE7.js.map} +0 -0
  667. /package/dist/cli-bundle/chunks/{chunk-Y72FV7RM.js.map → chunk-YCQET3OT.js.map} +0 -0
  668. /package/dist/cli-bundle/chunks/{close-many-LY2XJ52M.js.map → chunk-YUSOJDWM.js.map} +0 -0
  669. /package/dist/cli-bundle/chunks/{chunk-FS6UM5WH.js.map → chunk-ZI6VQWQ7.js.map} +0 -0
  670. /package/dist/cli-bundle/chunks/{comments-AJWRTFZ5.js.map → close-CWODTPKG.js.map} +0 -0
  671. /package/dist/cli-bundle/chunks/{comments-35M273DN.js.map → close-W6LI2PKM.js.map} +0 -0
  672. /package/dist/cli-bundle/chunks/{copy-GMXYKBXT.js.map → close-many-CQFUY7MR.js.map} +0 -0
  673. /package/dist/cli-bundle/chunks/{copy-NPYM7M7U.js.map → close-many-DLDDVSH5.js.map} +0 -0
  674. /package/dist/cli-bundle/chunks/{create-F53OBTOU.js.map → comments-E3TNTK24.js.map} +0 -0
  675. /package/dist/cli-bundle/chunks/{create-HU4Q7RJX.js.map → comments-WGLHR7LB.js.map} +0 -0
  676. /package/dist/cli-bundle/chunks/{delete-GSDZLTRC.js.map → copy-LXVDXH7B.js.map} +0 -0
  677. /package/dist/cli-bundle/chunks/{delete-ODRWJWAM.js.map → copy-Q5ZJPUKR.js.map} +0 -0
  678. /package/dist/cli-bundle/chunks/{deps-U57I7EAK.js.map → create-J5U6ND4K.js.map} +0 -0
  679. /package/dist/cli-bundle/chunks/{deps-WWB7P2GT.js.map → create-LBVCYMEG.js.map} +0 -0
  680. /package/dist/cli-bundle/chunks/{docs-MQIY2ZQS.js.map → delete-PMJBNY5G.js.map} +0 -0
  681. /package/dist/cli-bundle/chunks/{docs-G7N4E2JO.js.map → delete-WNHB3LYW.js.map} +0 -0
  682. /package/dist/cli-bundle/chunks/{files-TTY6N2AV.js.map → deps-JZ7TMVCB.js.map} +0 -0
  683. /package/dist/cli-bundle/chunks/{files-TBZD7V6H.js.map → deps-OA26IS25.js.map} +0 -0
  684. /package/dist/cli-bundle/chunks/{focus-XT6YVFFX.js.map → docs-FEWB2DQB.js.map} +0 -0
  685. /package/dist/cli-bundle/chunks/{focus-U5TRVCRS.js.map → docs-HA2AIDBB.js.map} +0 -0
  686. /package/dist/cli-bundle/chunks/{history-compact-M7GHYVFN.js.map → files-6YFBJRBG.js.map} +0 -0
  687. /package/dist/cli-bundle/chunks/{history-compact-KKVUWB4V.js.map → files-EFIWKFTM.js.map} +0 -0
  688. /package/dist/cli-bundle/chunks/{history-redact-3DVZOILD.js.map → focus-4QJR7FOQ.js.map} +0 -0
  689. /package/dist/cli-bundle/chunks/{history-redact-JIHZLHDP.js.map → focus-POIW5LTJ.js.map} +0 -0
  690. /package/dist/cli-bundle/chunks/{history-repair-ITDUMK4N.js.map → history-compact-CKRPDTJN.js.map} +0 -0
  691. /package/dist/cli-bundle/chunks/{history-repair-NAFCHLH7.js.map → history-compact-FWG2C7FZ.js.map} +0 -0
  692. /package/dist/cli-bundle/chunks/{learnings-SONGPSHI.js.map → history-redact-BB3TGDAE.js.map} +0 -0
  693. /package/dist/cli-bundle/chunks/{learnings-FGO3NSFW.js.map → history-redact-D225BHOZ.js.map} +0 -0
  694. /package/dist/cli-bundle/chunks/{notes-BSD53H2W.js.map → history-repair-6GEAM7HE.js.map} +0 -0
  695. /package/dist/cli-bundle/chunks/{notes-NQ6RXVW6.js.map → history-repair-RQXKQHL4.js.map} +0 -0
  696. /package/dist/cli-bundle/chunks/{plan-2NNEO46V.js.map → learnings-JLNLCOL5.js.map} +0 -0
  697. /package/dist/cli-bundle/chunks/{plan-AWLYGBNV.js.map → learnings-RSNLSWDC.js.map} +0 -0
  698. /package/dist/cli-bundle/chunks/{profile-U725ATWZ.js.map → notes-2WDH6DXU.js.map} +0 -0
  699. /package/dist/cli-bundle/chunks/{profile-AAQUU6T3.js.map → notes-GB47XXQQ.js.map} +0 -0
  700. /package/dist/cli-bundle/chunks/{restore-66GLMHIX.js.map → plan-DOVI2VMW.js.map} +0 -0
  701. /package/dist/cli-bundle/chunks/{restore-B3BAB6X2.js.map → plan-VDCJ2PCN.js.map} +0 -0
  702. /package/dist/cli-bundle/chunks/{schema-U7IM2DXV.js.map → profile-FAU7NZML.js.map} +0 -0
  703. /package/dist/cli-bundle/chunks/{schema-LZNUYHDB.js.map → profile-IVXQEL3D.js.map} +0 -0
  704. /package/dist/cli-bundle/chunks/{update-Q3UCILNR.js.map → restore-25DLT2Q2.js.map} +0 -0
  705. /package/dist/cli-bundle/chunks/{update-2XGHIVQ2.js.map → restore-YPMVUUEX.js.map} +0 -0
  706. /package/dist/cli-bundle/chunks/{update-many-75K57FS3.js.map → schema-FNU3WE4O.js.map} +0 -0
  707. /package/dist/cli-bundle/chunks/{update-many-U42YA445.js.map → schema-NBCM3RAD.js.map} +0 -0
  708. /package/dist/{cli/commands → sdk}/extension/managed-state.d.ts +0 -0
@@ -0,0 +1,2174 @@
1
+ /**
2
+ * @module sdk/extension
3
+ *
4
+ * Implements the pm extension command surface and its agent-facing runtime behavior.
5
+ */
6
+
7
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="fe21d8bd-795f-5bed-b4fc-e6efe6ee6120")}catch(e){}}();
8
+ import fs from "node:fs/promises";
9
+ import path from "node:path";
10
+ import { activateExtensions, createSerialQueue, loadExtensions, nextExtensionReloadToken, } from "../core/extensions/index.js";
11
+ import { resolveExtensionRoots } from "../core/extensions/loader.js";
12
+ import { pathExists } from "../core/fs/fs-utils.js";
13
+ import { resolvePmPackageRootFromModule } from "../core/packages/root.js";
14
+ import { EXIT_CODE } from "../core/shared/constants.js";
15
+ import { PmCliError } from "../core/shared/errors.js";
16
+ import { levenshteinDistanceWithinLimit } from "../core/shared/levenshtein.js";
17
+ import { nowIso } from "../core/shared/time.js";
18
+ import { resolveGlobalPmRoot, resolvePmRoot, } from "../core/store/paths.js";
19
+ import { readSettings, writeSettings } from "../core/store/settings.js";
20
+ import { quoteCommandArg, renderPmCommand } from "./command-line.js";
21
+ import { ensureTypeFolderScaffold } from "./schema.js";
22
+ // Cohesive helper groups now live in ./extension/* sibling modules. They are
23
+ // imported for the command wiring that stays here and re-exported below so
24
+ // existing import sites (sdk barrels, upgrade.ts, tests) keep importing the
25
+ // public surface (runExtension, managed-state read/write, install-source
26
+ // parsing, …) from "./extension.js" unchanged.
27
+ import { normalizeStringList, normalizeExtensionNameForMatch, normalizeManagedDirectoryName, parseExtensionManifest, validateExtensionDirectory, } from "./extension/shared.js";
28
+ import { sortManagedEntries, managedExtensionSourcesEquivalent, readManagedExtensionState, writeManagedExtensionState, upsertManagedEntry, resolveManagedExtensionStatePath, } from "./extension/managed-state.js";
29
+ import { parseExtensionInstallSource, resolveInstallSource, areDirectoriesEquivalent, } from "./extension/install-sources.js";
30
+ import { resolveBundledExtensionAliasSource, resolveBundledPackageNpmName, isBundledPackageInstallAllTarget, listBundledPackageAliases, resolveBundledAliasManifestName, buildBundledPackageCatalog, } from "./extension/bundled-catalog.js";
31
+ import { scaffoldExtensionProject } from "./extension/scaffold.js";
32
+ import { buildExtensionDescribeResult } from "./extension/describe.js";
33
+ import { applyDoctorRuntimeActivationState, classifyDoctorLoadFailureWarnings, classifyDoctorActivationFailureWarnings, classifyUnusedCapabilityWarnings, buildExtensionTriageSummary, parseDoctorDetailMode, collectUnknownCapabilityGuidance, buildCapabilityContractMetadata, buildDoctorConsistencySummary, } from "./extension/doctor.js";
34
+ import { copyExtensionDirectoryForInstall, copyExtensionDirectoryWithoutSelfNesting, ensureExtensionModuleTypeMarker, isErrnoCode, isRetriableExtensionInstallCopyError, resolveCanonicalExtensionInstallDestination, withExtensionInstallLock, } from "./extension/install-runtime.js";
35
+ import { mapWithFixedConcurrency } from "./extension/concurrency.js";
36
+ import { checkGithubUpdate } from "./extension/update-check.js";
37
+ import { captureExtensionInstallSnapshot, readOptionalMetadataFile, restoreExtensionInstallSnapshot, } from "./extension/install-snapshot.js";
38
+ // Re-export the public surface that lives in sibling modules but was previously
39
+ // exported from this file (used by sdk barrels, upgrade.ts, and tests).
40
+ export { parseExtensionManifest, validateExtensionDirectory, readManagedExtensionState, writeManagedExtensionState, resolveManagedExtensionStatePath, parseExtensionInstallSource, copyExtensionDirectoryForInstall, resolveCanonicalExtensionInstallDestination, };
41
+ const GITHUB_UPDATE_CHECK_CONCURRENCY = 4;
42
+ const LIFECYCLE_ACTION_TARGETS = [
43
+ ["install", "install", "--install"],
44
+ ["uninstall", "uninstall", "--uninstall"],
45
+ ["explore", "explore", "--explore"],
46
+ ["list", "explore", "--explore"],
47
+ ["manage", "manage", "--manage"],
48
+ ["describe", "describe", "--describe"],
49
+ ["reload", "reload", "--reload"],
50
+ ["doctor", "doctor", "--doctor"],
51
+ ["catalog", "catalog", "--catalog"],
52
+ ["init", "init", "--init"],
53
+ ["scaffold", "init", "--scaffold"],
54
+ ["adopt", "adopt", "--adopt"],
55
+ ["adopt-all", "adopt-all", "--adopt-all"],
56
+ ["activate", "activate", "--activate"],
57
+ ["deactivate", "deactivate", "--deactivate"],
58
+ ];
59
+ const LIFECYCLE_ACTION_FLAG_HINT = LIFECYCLE_ACTION_TARGETS.map(([, , flag]) => flag)
60
+ .filter((flag, index, flags) => flags.indexOf(flag) === index)
61
+ .join(", ");
62
+ const LIFECYCLE_ACTION_FLAGS = {
63
+ install: "--install",
64
+ uninstall: "--uninstall",
65
+ explore: "--explore",
66
+ manage: "--manage",
67
+ describe: "--describe",
68
+ reload: "--reload",
69
+ doctor: "--doctor",
70
+ catalog: "--catalog",
71
+ adopt: "--adopt",
72
+ "adopt-all": "--adopt-all",
73
+ activate: "--activate",
74
+ deactivate: "--deactivate",
75
+ init: "--init",
76
+ };
77
+ const NATIVE_OUTPUT_MARKER = "__pm_native_output";
78
+ const EXTENSION_POLICY_ROOT_LIST_FIELDS = [
79
+ "trusted_extensions",
80
+ "allowed_extensions",
81
+ "blocked_extensions",
82
+ "allowed_capabilities",
83
+ "blocked_capabilities",
84
+ "allowed_surfaces",
85
+ "blocked_surfaces",
86
+ "allowed_commands",
87
+ "blocked_commands",
88
+ "allowed_actions",
89
+ "blocked_actions",
90
+ "allowed_services",
91
+ "blocked_services",
92
+ ];
93
+ const EXTENSION_POLICY_OVERRIDE_LIST_FIELDS = [
94
+ "allowed_capabilities",
95
+ "blocked_capabilities",
96
+ "allowed_surfaces",
97
+ "blocked_surfaces",
98
+ "allowed_commands",
99
+ "blocked_commands",
100
+ "allowed_actions",
101
+ "blocked_actions",
102
+ "allowed_services",
103
+ "blocked_services",
104
+ ];
105
+ const EXTENSION_POLICY_OVERRIDE_BOOLEAN_FIELDS = [
106
+ "disabled",
107
+ "require_trusted",
108
+ "require_provenance",
109
+ ];
110
+ const DEFAULT_EXTENSION_POLICY_DETAILS = {
111
+ mode: "off",
112
+ trust_mode: "off",
113
+ require_provenance: false,
114
+ trusted_extensions: [],
115
+ default_sandbox_profile: "none",
116
+ allowed_extensions: [],
117
+ blocked_extensions: [],
118
+ allowed_capabilities: [],
119
+ blocked_capabilities: [],
120
+ allowed_surfaces: [],
121
+ blocked_surfaces: [],
122
+ allowed_commands: [],
123
+ blocked_commands: [],
124
+ allowed_actions: [],
125
+ blocked_actions: [],
126
+ allowed_services: [],
127
+ blocked_services: [],
128
+ extension_overrides: [],
129
+ };
130
+ /** Normalize every root-level extension policy list into a stable unique sequence. */
131
+ const normalizePolicyRootLists = (policy) => {
132
+ const safePolicy = policy ?? DEFAULT_EXTENSION_POLICY_DETAILS;
133
+ const lists = {};
134
+ for (const field of EXTENSION_POLICY_ROOT_LIST_FIELDS) {
135
+ lists[field] = normalizeStringList(safePolicy[field] ?? []);
136
+ }
137
+ return lists;
138
+ };
139
+ /** Attach only populated override lists so diagnostics remain compact. */
140
+ const appendNonEmptyPolicyLists = (target, lists) => {
141
+ for (const field of EXTENSION_POLICY_OVERRIDE_LIST_FIELDS) {
142
+ if (lists[field].length > 0) {
143
+ target[field] = lists[field];
144
+ }
145
+ }
146
+ return target;
147
+ };
148
+ /** Attach explicitly enabled scalar fields to one normalized extension override. */
149
+ const appendEnabledPolicyScalars = (target, override) => {
150
+ for (const field of EXTENSION_POLICY_OVERRIDE_BOOLEAN_FIELDS) {
151
+ if (override[field] === true) {
152
+ target[field] = true;
153
+ }
154
+ }
155
+ if (override.sandbox_profile) {
156
+ target.sandbox_profile = override.sandbox_profile;
157
+ }
158
+ return target;
159
+ };
160
+ /** Normalize every list field from one extension policy override. */
161
+ const normalizePolicyOverrideLists = (override) => {
162
+ const lists = {};
163
+ for (const field of EXTENSION_POLICY_OVERRIDE_LIST_FIELDS) {
164
+ lists[field] = normalizeStringList(override[field] ?? []);
165
+ }
166
+ return lists;
167
+ };
168
+ /** Build deterministic diagnostic details for one valid named extension override. */
169
+ const buildExtensionPolicyOverrideDetails = (override) => {
170
+ const name = typeof override.name === "string" ? override.name.trim() : "";
171
+ if (name.length === 0) {
172
+ return null;
173
+ }
174
+ return appendNonEmptyPolicyLists(appendEnabledPolicyScalars({ name }, override), normalizePolicyOverrideLists(override));
175
+ };
176
+ /** Normalize and sort all named extension policy overrides. */
177
+ const normalizeExtensionPolicyOverrides = (overrides) => (overrides ?? [])
178
+ .map((override) => buildExtensionPolicyOverrideDetails(override))
179
+ .filter((override) => override !== null)
180
+ .sort((left, right) => left.name.localeCompare(right.name));
181
+ /** Build the normalized extension policy representation exposed by diagnostics. */
182
+ const buildExtensionPolicyDetails = (policy) => {
183
+ const safePolicy = Object.assign({}, DEFAULT_EXTENSION_POLICY_DETAILS, policy ?? {});
184
+ const rootLists = normalizePolicyRootLists(policy);
185
+ const overrides = normalizeExtensionPolicyOverrides(safePolicy.extension_overrides);
186
+ return {
187
+ mode: safePolicy.mode,
188
+ trust_mode: safePolicy.trust_mode,
189
+ require_provenance: safePolicy.require_provenance === true,
190
+ trusted_extensions: rootLists.trusted_extensions,
191
+ default_sandbox_profile: safePolicy.default_sandbox_profile,
192
+ allowed_extensions: rootLists.allowed_extensions,
193
+ blocked_extensions: rootLists.blocked_extensions,
194
+ allowed_capabilities: rootLists.allowed_capabilities,
195
+ blocked_capabilities: rootLists.blocked_capabilities,
196
+ allowed_surfaces: rootLists.allowed_surfaces,
197
+ blocked_surfaces: rootLists.blocked_surfaces,
198
+ allowed_commands: rootLists.allowed_commands,
199
+ blocked_commands: rootLists.blocked_commands,
200
+ allowed_actions: rootLists.allowed_actions,
201
+ blocked_actions: rootLists.blocked_actions,
202
+ allowed_services: rootLists.allowed_services,
203
+ blocked_services: rootLists.blocked_services,
204
+ extension_overrides: overrides,
205
+ };
206
+ };
207
+ /** Resolve a lifecycle target against managed extension names, aliases, and directories. */
208
+ const resolveInstalledExtensionCandidate = async (installed, extensionTarget) => {
209
+ const lookupValues = [extensionTarget];
210
+ const bundledAliasManifestName = await resolveBundledAliasManifestName(extensionTarget);
211
+ if (bundledAliasManifestName) {
212
+ lookupValues.push(bundledAliasManifestName);
213
+ }
214
+ const normalizedLookups = [
215
+ ...new Set(lookupValues
216
+ .map((value) => normalizeExtensionNameForMatch(value))
217
+ .filter((value) => value.length > 0)),
218
+ ];
219
+ for (const lookup of normalizedLookups) {
220
+ const byName = installed.find((entry) => normalizeExtensionNameForMatch(entry.name) === lookup);
221
+ if (byName) {
222
+ return byName;
223
+ }
224
+ const byDirectory = installed.find((entry) => normalizeExtensionNameForMatch(entry.directory) === lookup);
225
+ if (byDirectory) {
226
+ return byDirectory;
227
+ }
228
+ }
229
+ return undefined;
230
+ };
231
+ /** Return whether one extension is enabled after explicit enabled and disabled settings are applied. */
232
+ const isExtensionEnabled = (settings, name) => {
233
+ const normalizedName = name.trim();
234
+ const enabled = new Set(normalizeStringList(settings.extensions.enabled));
235
+ const disabled = new Set(normalizeStringList(settings.extensions.disabled));
236
+ if (disabled.has(normalizedName)) {
237
+ return false;
238
+ }
239
+ if (enabled.size === 0) {
240
+ return true;
241
+ }
242
+ return enabled.has(normalizedName);
243
+ };
244
+ /** Mutate extension settings to activate one name and report whether persisted state changed. */
245
+ const ensureActivated = (settings, name) => {
246
+ const normalizedName = name.trim();
247
+ const enabled = new Set(normalizeStringList(settings.extensions.enabled));
248
+ const disabled = new Set(normalizeStringList(settings.extensions.disabled));
249
+ const previousEnabled = [...enabled];
250
+ const previousDisabled = [...disabled];
251
+ disabled.delete(normalizedName);
252
+ if (enabled.size > 0) {
253
+ enabled.add(normalizedName);
254
+ }
255
+ settings.extensions.enabled = [...enabled].sort((left, right) => left.localeCompare(right));
256
+ settings.extensions.disabled = [...disabled].sort((left, right) => left.localeCompare(right));
257
+ return (settings.extensions.enabled.join("\u0000") !==
258
+ previousEnabled.join("\u0000") ||
259
+ settings.extensions.disabled.join("\u0000") !==
260
+ previousDisabled.join("\u0000"));
261
+ };
262
+ /** Mutate extension settings to deactivate one name and report whether persisted state changed. */
263
+ const ensureDeactivated = (settings, name) => {
264
+ const normalizedName = name.trim();
265
+ const enabled = new Set(normalizeStringList(settings.extensions.enabled));
266
+ const disabled = new Set(normalizeStringList(settings.extensions.disabled));
267
+ const previousEnabled = [...enabled];
268
+ const previousDisabled = [...disabled];
269
+ enabled.delete(normalizedName);
270
+ disabled.add(normalizedName);
271
+ settings.extensions.enabled = [...enabled].sort((left, right) => left.localeCompare(right));
272
+ settings.extensions.disabled = [...disabled].sort((left, right) => left.localeCompare(right));
273
+ return (settings.extensions.enabled.join("\u0000") !==
274
+ previousEnabled.join("\u0000") ||
275
+ settings.extensions.disabled.join("\u0000") !==
276
+ previousDisabled.join("\u0000"));
277
+ };
278
+ /** Remove one extension from explicit enabled and disabled settings and report whether state changed. */
279
+ const clearExtensionState = (settings, name) => {
280
+ const normalizedName = name.trim();
281
+ const enabled = new Set(normalizeStringList(settings.extensions.enabled));
282
+ const disabled = new Set(normalizeStringList(settings.extensions.disabled));
283
+ const previousEnabled = [...enabled];
284
+ const previousDisabled = [...disabled];
285
+ enabled.delete(normalizedName);
286
+ disabled.delete(normalizedName);
287
+ settings.extensions.enabled = [...enabled].sort((left, right) => left.localeCompare(right));
288
+ settings.extensions.disabled = [...disabled].sort((left, right) => left.localeCompare(right));
289
+ return (settings.extensions.enabled.join("\u0000") !==
290
+ previousEnabled.join("\u0000") ||
291
+ settings.extensions.disabled.join("\u0000") !==
292
+ previousDisabled.join("\u0000"));
293
+ };
294
+ /** Return the nearest valid lifecycle action and flag for one user-provided target. */
295
+ const suggestLifecycleActionTarget = (target) => {
296
+ const normalizedTarget = target.trim().toLowerCase();
297
+ const maxDistance = Math.min(2, Math.max(1, Math.ceil(normalizedTarget.length / 4)));
298
+ const nearest = LIFECYCLE_ACTION_TARGETS.map(([candidate, action, flag]) => ({
299
+ action,
300
+ flag,
301
+ distance: levenshteinDistanceWithinLimit(normalizedTarget, candidate, maxDistance),
302
+ }))
303
+ .filter((entry) => entry.distance !== null)
304
+ .sort((left, right) => left.distance - right.distance)[0];
305
+ return nearest ? { action: nearest.action, flag: nearest.flag } : null;
306
+ };
307
+ /** Build structured recovery guidance for an unknown extension lifecycle action. */
308
+ const buildUnknownLifecycleActionError = (target, options) => {
309
+ const noun = options.vocabulary === "package" ? "package" : "extension";
310
+ const suggestion = suggestLifecycleActionTarget(target);
311
+ if (!suggestion) {
312
+ return new PmCliError(`One action flag is required. Use one of: ${LIFECYCLE_ACTION_FLAG_HINT}. Bare \`pm package\` and \`pm extension\` default to --explore.`, EXIT_CODE.USAGE);
313
+ }
314
+ const command = `pm ${noun} ${suggestion.flag}`;
315
+ return new PmCliError(`Unknown ${noun} lifecycle action "${target}". Did you mean "${suggestion.flag}"?`, EXIT_CODE.USAGE, {
316
+ code: "unknown_lifecycle_action",
317
+ required: `Use one of: ${LIFECYCLE_ACTION_FLAG_HINT}.`,
318
+ examples: [command, `pm ${noun} --help`],
319
+ recovery: {
320
+ attempted_command: `pm ${noun} ${target}`,
321
+ suggested_retry: command,
322
+ fallback_candidates: [
323
+ {
324
+ source: "lifecycle_action",
325
+ command,
326
+ reason: `nearest lifecycle action for "${target}"`,
327
+ },
328
+ ],
329
+ },
330
+ });
331
+ };
332
+ // Maps each boolean action flag to the lifecycle action it selects. `scaffold`
333
+ // aliases `init` and `adoptAll` selects `adopt-all`; every other flag maps to its
334
+ // like-named action. Dispatching through the table keeps `resolveAction` flat.
335
+ const EXTENSION_ACTION_FLAG_SELECTORS = [
336
+ ["install", "install"],
337
+ ["uninstall", "uninstall"],
338
+ ["explore", "explore"],
339
+ ["manage", "manage"],
340
+ ["describe", "describe"],
341
+ ["reload", "reload"],
342
+ ["doctor", "doctor"],
343
+ ["catalog", "catalog"],
344
+ ["init", "init"],
345
+ ["scaffold", "init"],
346
+ ["adopt", "adopt"],
347
+ ["adoptAll", "adopt-all"],
348
+ ["activate", "activate"],
349
+ ["deactivate", "deactivate"],
350
+ ];
351
+ /** Positional lifecycle shorthand mapped to the canonical extension action. */
352
+ const IMPLICIT_EXTENSION_ACTIONS = {
353
+ doctor: "doctor",
354
+ reload: "reload",
355
+ catalog: "catalog",
356
+ init: "init",
357
+ scaffold: "init",
358
+ explore: "explore",
359
+ manage: "manage",
360
+ list: "explore",
361
+ "": "explore",
362
+ };
363
+ /** Map a bare positional token (already trimmed and lower-cased) to the lifecycle action it implies for `pm extension <token>` / `pm package <token>`: the `doctor`/`reload`/`catalog`/`init`/`scaffold`/`explore`/`manage` keywords, with `list` and the empty string both meaning `explore`. Returns `null` for anything else so the caller can raise a did-you-mean error. */
364
+ const resolveImplicitActionFromTarget = (normalizedTarget) => IMPLICIT_EXTENSION_ACTIONS[normalizedTarget] ?? null;
365
+ /** Resolve mutually exclusive lifecycle flags and positional shorthand into one extension action. */
366
+ const resolveAction = (target, options) => {
367
+ const selected = [
368
+ ...new Set(EXTENSION_ACTION_FLAG_SELECTORS.filter(([flag]) => options[flag] === true).map(([, mappedAction]) => mappedAction)),
369
+ ];
370
+ if (selected.length === 0) {
371
+ if (target === undefined) {
372
+ return "explore";
373
+ }
374
+ const implicitAction = resolveImplicitActionFromTarget(target.trim().toLowerCase());
375
+ if (implicitAction) {
376
+ return implicitAction;
377
+ }
378
+ throw buildUnknownLifecycleActionError(target, options);
379
+ }
380
+ if (selected.length > 1) {
381
+ throw new PmCliError("Extension action flags are mutually exclusive.", EXIT_CODE.USAGE);
382
+ }
383
+ return selected[0];
384
+ };
385
+ /** Resolve project or global extension scope while rejecting conflicting scope flags. */
386
+ const resolveScope = (options) => {
387
+ const projectLike = options.project === true || options.local === true;
388
+ const global = options.global === true;
389
+ if (projectLike && global) {
390
+ throw new PmCliError('Options "--project/--local" and "--global" are mutually exclusive.', EXIT_CODE.USAGE);
391
+ }
392
+ return global ? "global" : "project";
393
+ };
394
+ /** Ordered update-check policies from unmanaged and non-GitHub cases through recorded outcomes. */
395
+ const EXTENSION_UPDATE_CHECK_RESOLVERS = [
396
+ (managedEntry) => managedEntry
397
+ ? null
398
+ : {
399
+ status: "skipped_unmanaged",
400
+ reason: "extension_not_managed",
401
+ },
402
+ (managedEntry) => managedEntry && managedEntry.source.kind !== "github"
403
+ ? {
404
+ status: "skipped_non_github",
405
+ reason: `managed_source_kind_${managedEntry.source.kind}`,
406
+ }
407
+ : null,
408
+ (managedEntry) => {
409
+ const updateError = typeof managedEntry?.update_error === "string"
410
+ ? managedEntry.update_error.trim()
411
+ : "";
412
+ return updateError.length > 0
413
+ ? { status: "failed", reason: updateError }
414
+ : null;
415
+ },
416
+ (managedEntry) => {
417
+ const entry = managedEntry;
418
+ const checkedAt = typeof entry.last_update_check_at === "string"
419
+ ? entry.last_update_check_at.trim()
420
+ : "";
421
+ if (checkedAt.length === 0) {
422
+ return null;
423
+ }
424
+ const reason = {
425
+ true: "update_available",
426
+ false: "up_to_date",
427
+ }[String(entry.update_available)] ?? "checked_without_commit_baseline";
428
+ return { status: "checked", reason };
429
+ },
430
+ ];
431
+ /** Project managed-source update metadata into one deterministic update-check result. */
432
+ const resolveUpdateCheckResolution = (managedEntry) => {
433
+ for (const resolve of EXTENSION_UPDATE_CHECK_RESOLVERS) {
434
+ const resolution = resolve(managedEntry);
435
+ if (resolution) {
436
+ return resolution;
437
+ }
438
+ }
439
+ return {
440
+ status: "not_checked",
441
+ reason: "no_update_check_recorded",
442
+ };
443
+ };
444
+ /**
445
+ * Assemble a {@link ManagedExtensionSummary} from a directory's resolved identity
446
+ * (name/version/entry/enabled state) and its managed-state record, projecting the
447
+ * managed-source provenance and the resolved update-check status. Runtime
448
+ * activation fields default to "not yet probed" (`runtime_active: null`,
449
+ * `activation_status: "unknown"`) so a later runtime probe can overlay live state.
450
+ */
451
+ const buildInstalledExtensionSummary = (identity, scope, managedEntry, updateCheck) => {
452
+ const managed = managedEntry ?? {};
453
+ return {
454
+ name: identity.name,
455
+ directory: identity.directory,
456
+ version: identity.version,
457
+ entry: identity.entry,
458
+ scope,
459
+ active: identity.enabled,
460
+ enabled: identity.enabled,
461
+ runtime_active: null,
462
+ activation_status: "unknown",
463
+ managed: Boolean(managedEntry),
464
+ source: managed.source,
465
+ update_available: managed.update_available,
466
+ last_update_check_at: managed.last_update_check_at,
467
+ last_update_remote_commit: managed.last_update_remote_commit,
468
+ update_error: managed.update_error,
469
+ update_check_status: updateCheck.status,
470
+ update_check_reason: updateCheck.reason,
471
+ };
472
+ };
473
+ /** Project the degraded summary retained for a directory without a manifest. */
474
+ const buildMissingManifestInspection = (directoryName, scope, settings, managedEntry) => {
475
+ const managed = Object.assign({
476
+ name: directoryName,
477
+ manifest_version: "unknown",
478
+ manifest_entry: "unknown",
479
+ }, managedEntry);
480
+ const enabled = managedEntry
481
+ ? isExtensionEnabled(settings, managedEntry.name)
482
+ : false;
483
+ return {
484
+ warning: `extension_manifest_missing:${scope}:${directoryName}`,
485
+ summary: buildInstalledExtensionSummary({
486
+ name: managed.name,
487
+ directory: directoryName,
488
+ version: managed.manifest_version,
489
+ entry: managed.manifest_entry,
490
+ enabled,
491
+ }, scope, managedEntry, resolveUpdateCheckResolution(managedEntry)),
492
+ };
493
+ };
494
+ /** Inspect one installed extension directory and project its manifest or warning. */
495
+ const inspectInstalledExtensionDirectory = async (extensionsRoot, directoryName, scope, settings, managedByName, managedByDirectory) => {
496
+ const extensionDirectory = path.join(extensionsRoot, directoryName);
497
+ const manifestPath = path.join(extensionDirectory, "manifest.json");
498
+ const managedDirectoryEntry = managedByDirectory.get(normalizeExtensionNameForMatch(directoryName));
499
+ if (!(await pathExists(manifestPath))) {
500
+ return buildMissingManifestInspection(directoryName, scope, settings, managedDirectoryEntry);
501
+ }
502
+ const invalidJson = Symbol("invalid-extension-manifest-json");
503
+ const rawManifest = await fs
504
+ .readFile(manifestPath, "utf8")
505
+ .then((contents) => JSON.parse(contents))
506
+ .catch(() => invalidJson);
507
+ if (rawManifest === invalidJson) {
508
+ return {
509
+ warning: `extension_manifest_invalid_json:${scope}:${directoryName}`,
510
+ };
511
+ }
512
+ const manifest = parseExtensionManifest(rawManifest);
513
+ if (!manifest) {
514
+ return { warning: `extension_manifest_invalid:${scope}:${directoryName}` };
515
+ }
516
+ const managedEntry = managedByName.get(normalizeExtensionNameForMatch(manifest.name)) ??
517
+ managedByDirectory.get(normalizeExtensionNameForMatch(directoryName));
518
+ return {
519
+ summary: buildInstalledExtensionSummary({
520
+ name: manifest.name,
521
+ directory: directoryName,
522
+ version: manifest.version,
523
+ entry: manifest.entry,
524
+ enabled: isExtensionEnabled(settings, manifest.name),
525
+ }, scope, managedEntry, resolveUpdateCheckResolution(managedEntry)),
526
+ };
527
+ };
528
+ /** List managed and unmanaged extensions with activation, update, and command summaries. */
529
+ const listInstalledExtensions = async (extensionsRoot, scope, settings, state) => {
530
+ if (!(await pathExists(extensionsRoot))) {
531
+ return {
532
+ extensions: [],
533
+ warnings: [],
534
+ };
535
+ }
536
+ const entries = await fs.readdir(extensionsRoot, { withFileTypes: true });
537
+ const directories = entries
538
+ .filter((entry) => entry.isDirectory())
539
+ .map((entry) => entry.name)
540
+ .sort((left, right) => left.localeCompare(right));
541
+ const managedByName = new Map(state.entries.map((managedEntry) => [
542
+ normalizeExtensionNameForMatch(managedEntry.name),
543
+ managedEntry,
544
+ ]));
545
+ const managedByDirectory = new Map(state.entries.map((managedEntry) => [
546
+ normalizeExtensionNameForMatch(managedEntry.directory),
547
+ managedEntry,
548
+ ]));
549
+ const warnings = [];
550
+ const summaries = [];
551
+ for (const directoryName of directories) {
552
+ const inspected = await inspectInstalledExtensionDirectory(extensionsRoot, directoryName, scope, settings, managedByName, managedByDirectory);
553
+ if (inspected.warning) {
554
+ warnings.push(inspected.warning);
555
+ }
556
+ if (inspected.summary) {
557
+ summaries.push(inspected.summary);
558
+ }
559
+ }
560
+ return {
561
+ extensions: summaries.sort((left, right) => left.name.localeCompare(right.name)),
562
+ warnings: warnings.sort((left, right) => left.localeCompare(right)),
563
+ };
564
+ };
565
+ const extensionRuntimeProbeQueue = createSerialQueue();
566
+ /** Return stable runtime command paths registered by one extension. */
567
+ const summarizeRuntimeCommandPathsForExtension = (extensionName, installed) => {
568
+ const normalizedName = normalizeExtensionNameForMatch(extensionName);
569
+ const entry = installed.find((candidate) => normalizeExtensionNameForMatch(candidate.name) === normalizedName);
570
+ return {
571
+ command_paths: [...(entry?.command_paths ?? [])].sort((left, right) => left.localeCompare(right)),
572
+ action_paths: [...(entry?.action_paths ?? [])].sort((left, right) => left.localeCompare(right)),
573
+ };
574
+ };
575
+ /** Resolve the package vocabulary name used in extension command discovery. */
576
+ const resolveCommandDiscoveryPackageName = (extensionName, source) => [source.package, source.kind === "builtin" ? source.name : undefined]
577
+ .find((candidate) => candidate?.trim())
578
+ ?.trim() ?? extensionName;
579
+ /** Build post-install command discovery and activation guidance for one extension. */
580
+ const buildInstallCommandDiscovery = (extensionName, source, commandSummary, activationFailure) => {
581
+ const helpCommands = commandSummary.command_paths.map((commandPath) => `pm ${commandPath} --help`);
582
+ const sdkDependencyMissing = activationFailure?.error.toLowerCase().includes("@unbrained/pm-cli") ===
583
+ true;
584
+ const nextSteps = commandSummary.command_paths.length > 0
585
+ ? [...helpCommands]
586
+ : [
587
+ "Run pm package doctor --project --detail deep if expected package commands are missing.",
588
+ ];
589
+ if (sdkDependencyMissing) {
590
+ nextSteps.unshift("Install @unbrained/pm-cli in the target workspace so declarative package runtime imports resolve, then reinstall the package.");
591
+ }
592
+ return {
593
+ package_name: resolveCommandDiscoveryPackageName(extensionName, source),
594
+ extension_name: extensionName,
595
+ command_paths: commandSummary.command_paths,
596
+ action_paths: commandSummary.action_paths,
597
+ help_commands: helpCommands,
598
+ next_steps: nextSteps,
599
+ ...(sdkDependencyMissing ? { sdk_dependency_status: "missing" } : {}),
600
+ };
601
+ };
602
+ /** Project one activation failure into a bounded diagnostic summary. */
603
+ const summarizeActivationFailureForDiagnostics = (failure) => {
604
+ const trace = failure.trace;
605
+ const summary = {
606
+ layer: failure.layer,
607
+ name: failure.name,
608
+ entry_path: failure.entry_path,
609
+ error: failure.error,
610
+ };
611
+ if (!trace)
612
+ return summary;
613
+ summary.trace = Object.fromEntries(Object.entries(trace).filter(([, value]) => value !== undefined));
614
+ if (trace.missing_capability) {
615
+ summary.missing_capability = trace.missing_capability;
616
+ }
617
+ if (trace.hint)
618
+ summary.hint = trace.hint;
619
+ return summary;
620
+ };
621
+ /** Collect activation failures that match one extension identity. */
622
+ const collectActivationFailureDiagnostics = (failures) => {
623
+ return failures
624
+ .map((failure) => summarizeActivationFailureForDiagnostics(failure))
625
+ .sort((left, right) => `${left.layer}:${left.name}`.localeCompare(`${right.layer}:${right.name}`));
626
+ };
627
+ /** Find the first activation failure matching one normalized extension name. */
628
+ const findActivationFailureByName = (extensionName, failures, layer) => {
629
+ const normalizedName = normalizeExtensionNameForMatch(extensionName);
630
+ return failures.find((failure) => (layer === undefined || failure.layer === layer) &&
631
+ normalizeExtensionNameForMatch(failure.name) === normalizedName);
632
+ };
633
+ /** Resolve post-install runtime activation status from load and activation evidence. */
634
+ const resolveInstallRuntimeActivationStatus = (extensionName, scope, runtimeInstalled, installActivationFailure) => {
635
+ const runtimeInstalledExtension = runtimeInstalled.find((entry) => entry.scope === scope &&
636
+ normalizeExtensionNameForMatch(entry.name) ===
637
+ normalizeExtensionNameForMatch(extensionName));
638
+ return (runtimeInstalledExtension?.activation_status ??
639
+ (installActivationFailure ? "failed" : "unknown"));
640
+ };
641
+ /** Probe a temporary installed extension for runtime command registrations. */
642
+ const probeRuntimeCommandPathsForInstall = (pmRoot, settings, refreshedInstalled, global) => {
643
+ return extensionRuntimeProbeQueue.enqueue(async () => {
644
+ const originalPackageRoot = process.env.PM_CLI_PACKAGE_ROOT;
645
+ process.env.PM_CLI_PACKAGE_ROOT = resolvePmPackageRootFromModule(import.meta.url, ["../.."]);
646
+ try {
647
+ const loadResult = await loadExtensions({
648
+ pmRoot,
649
+ settings,
650
+ cwd: process.cwd(),
651
+ noExtensions: global.noExtensions === true,
652
+ reload_token: nextExtensionReloadToken(),
653
+ cache_bust: true,
654
+ });
655
+ const activationResult = await activateExtensions({
656
+ ...loadResult,
657
+ loaded: loadResult.loaded,
658
+ });
659
+ const runtimeFailures = [
660
+ ...loadResult.failed.map((failure) => ({
661
+ layer: failure.layer,
662
+ name: failure.name,
663
+ entry_path: failure.entry_path,
664
+ error: failure.error,
665
+ })),
666
+ ...collectActivationFailureDiagnostics(activationResult.failed),
667
+ ];
668
+ return {
669
+ installed: applyDoctorRuntimeActivationState(refreshedInstalled, loadResult, activationResult),
670
+ warnings: [...loadResult.warnings, ...activationResult.warnings],
671
+ activation_failures: runtimeFailures,
672
+ extensions_disabled: loadResult.disabled_by_flag,
673
+ item_type_registrations: activationResult.registrations.item_types,
674
+ };
675
+ }
676
+ finally {
677
+ if (originalPackageRoot === undefined) {
678
+ delete process.env.PM_CLI_PACKAGE_ROOT;
679
+ }
680
+ else {
681
+ process.env.PM_CLI_PACKAGE_ROOT = originalPackageRoot;
682
+ }
683
+ }
684
+ });
685
+ };
686
+ /** Adopt unmanaged extension directories into deterministic managed state. */
687
+ const adoptUnmanagedExtensions = async (extensionsRoot, scope, installedExtensions, state) => {
688
+ const unmanagedCandidates = installedExtensions.filter((entry) => !entry.managed);
689
+ const sortedCandidates = [...unmanagedCandidates].sort((left, right) => {
690
+ const byName = left.name.localeCompare(right.name);
691
+ if (byName !== 0) {
692
+ return byName;
693
+ }
694
+ return left.directory.localeCompare(right.directory);
695
+ });
696
+ let nextState = state;
697
+ const adoptedEntries = [];
698
+ for (const candidate of sortedCandidates) {
699
+ const extensionDirectory = path.join(extensionsRoot, candidate.directory);
700
+ const validated = await validateExtensionDirectory(extensionDirectory);
701
+ const now = nowIso();
702
+ const sourceRecord = {
703
+ kind: "local",
704
+ input: candidate.name,
705
+ location: extensionDirectory,
706
+ };
707
+ nextState = upsertManagedEntry(nextState, {
708
+ name: validated.manifest.name,
709
+ directory: candidate.directory,
710
+ scope,
711
+ manifest_version: validated.manifest.version,
712
+ manifest_entry: validated.manifest.entry,
713
+ capabilities: [...validated.manifest.capabilities],
714
+ installed_at: now,
715
+ updated_at: now,
716
+ source: sourceRecord,
717
+ });
718
+ adoptedEntries.push({
719
+ name: validated.manifest.name,
720
+ directory: candidate.directory,
721
+ version: validated.manifest.version,
722
+ entry: validated.manifest.entry,
723
+ source: sourceRecord,
724
+ });
725
+ }
726
+ if (adoptedEntries.length > 0) {
727
+ await writeManagedExtensionState(extensionsRoot, nextState);
728
+ }
729
+ return {
730
+ state: nextState,
731
+ adopted_entries: adoptedEntries,
732
+ unmanaged_candidates: sortedCandidates,
733
+ already_managed_count: installedExtensions.length - unmanagedCandidates.length,
734
+ };
735
+ };
736
+ /** Resolve project and global extension roots for one lifecycle scope. */
737
+ const resolveExtensionRootsForScope = (scope, global) => {
738
+ const pmRoot = resolvePmRoot(process.cwd(), global.path);
739
+ const roots = resolveExtensionRoots(pmRoot, process.cwd());
740
+ const settingsRoot = scope === "global" ? resolveGlobalPmRoot(process.cwd()) : pmRoot;
741
+ const selectedRoot = scope === "global" ? roots.global : roots.project;
742
+ return {
743
+ pm_root: pmRoot,
744
+ scope,
745
+ settings_root: settingsRoot,
746
+ selected_root: selectedRoot,
747
+ roots,
748
+ };
749
+ };
750
+ /** Normalize the GitHub repository option accepted by extension lifecycle actions. */
751
+ const resolveGithubOption = (options) => {
752
+ const values = [options.gh, options.github]
753
+ .filter((value) => typeof value === "string")
754
+ .map((value) => value.trim())
755
+ .filter(Boolean);
756
+ const uniqueValues = [...new Set(values)];
757
+ if (uniqueValues.length > 1) {
758
+ throw new PmCliError('Options "--gh" and "--github" must match when both are provided.', EXIT_CODE.USAGE);
759
+ }
760
+ return uniqueValues[0];
761
+ };
762
+ /** Return the canonical command-line flag for one extension lifecycle action. */
763
+ const getLifecycleActionFlag = (action) => {
764
+ return LIFECYCLE_ACTION_FLAGS[action];
765
+ };
766
+ /** Throw structured recovery guidance for a missing lifecycle target. */
767
+ const throwMissingLifecycleTarget = (action, options) => {
768
+ const noun = options.vocabulary === "package" ? "package" : "extension";
769
+ const targetName = action === "install" ? "source" : "name";
770
+ const targetLabel = `${noun} ${targetName}`;
771
+ const actionFlag = getLifecycleActionFlag(action);
772
+ const commandTarget = `<${targetName}>`;
773
+ const command = `pm ${noun} ${actionFlag} ${commandTarget}`;
774
+ throw new PmCliError(`Action "${action}" requires ${targetLabel} input.`, EXIT_CODE.USAGE, {
775
+ code: "missing_lifecycle_target",
776
+ required: `Provide a ${targetName} target for ${action}.`,
777
+ examples: [
778
+ `pm ${noun} ${action} ${commandTarget}`,
779
+ command,
780
+ `pm ${noun} --help`,
781
+ ],
782
+ recovery: {
783
+ attempted_command: `pm ${noun} ${action}`,
784
+ suggested_retry: command,
785
+ fallback_candidates: [
786
+ {
787
+ source: "lifecycle_action",
788
+ command,
789
+ reason: `flag-form ${action} command with required ${targetName} target`,
790
+ },
791
+ ],
792
+ },
793
+ });
794
+ };
795
+ /** Return a required lifecycle target or throw structured usage guidance. */
796
+ const requireTarget = (target, action, options = {}) => {
797
+ const normalized = target?.trim();
798
+ if (normalized)
799
+ return normalized;
800
+ if (action === "init") {
801
+ throw new PmCliError('Action "init" requires a scaffold target path (for example: pm package init ./my-package or pm extension init ./my-extension).', EXIT_CODE.USAGE);
802
+ }
803
+ return throwMissingLifecycleTarget(action, options);
804
+ };
805
+ /** Collect doctor warnings for unsafe global output override registrations. */
806
+ const collectGlobalOutputOverrideDoctorWarnings = (activationResult) => {
807
+ const warnings = [];
808
+ for (const entry of activationResult.services.overrides) {
809
+ if (entry.service !== "output_format") {
810
+ continue;
811
+ }
812
+ warnings.push(`extension_output_service_override_global:${entry.service}:${entry.layer}:${entry.name}`);
813
+ }
814
+ for (const entry of activationResult.renderers.overrides) {
815
+ warnings.push(`extension_output_renderer_override_global:${entry.format}:${entry.layer}:${entry.name}`);
816
+ }
817
+ return [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
818
+ };
819
+ /**
820
+ * Doctor advisory: flag loaded extensions that contribute GLOBAL schema (custom
821
+ * item types or fields) yet also declare narrow `activation.commands`.
822
+ *
823
+ * Custom item types and fields must be present for the built-in commands the
824
+ * extension does not own and cannot enumerate (`pm create <type>`,
825
+ * `pm list --type <type>`, `pm validate`). Declaring `activation.commands` gates
826
+ * lazy activation to only the listed command paths, so the package never
827
+ * activates for those built-ins and its custom type silently fails to register —
828
+ * a quiet footgun (decision pm-halx). The `schema` scaffold deliberately omits
829
+ * the field; this advisory catches hand-authored packages that do not. It is
830
+ * doctor-only and non-blocking — `pm health` does not surface it — so the author
831
+ * can either drop `activation.commands` or, when the schema is intentionally
832
+ * command-scoped, knowingly ignore the hint.
833
+ */
834
+ const collectSchemaNarrowActivationDoctorWarnings = (loadResult, activationResult) => {
835
+ const schemaContributors = new Set([
836
+ ...activationResult.registrations.item_types.map((entry) => ({
837
+ entry,
838
+ count: entry.types.length,
839
+ })),
840
+ ...activationResult.registrations.item_fields.map((entry) => ({
841
+ entry,
842
+ count: entry.fields.length,
843
+ })),
844
+ ]
845
+ .filter(({ count }) => count > 0)
846
+ .map(({ entry }) => `${entry.layer}:${normalizeExtensionNameForMatch(entry.name)}`));
847
+ return loadResult.loaded
848
+ .filter((extension) => (extension.activation?.commands ?? []).length > 0)
849
+ .filter((extension) => schemaContributors.has(`${extension.layer}:${normalizeExtensionNameForMatch(extension.name)}`))
850
+ .map((extension) => `extension_schema_narrow_activation:${extension.layer}:${extension.name}`)
851
+ .filter((warning, index, warnings) => warnings.indexOf(warning) === index)
852
+ .sort((left, right) => left.localeCompare(right));
853
+ };
854
+ /** Reject option/action combinations that are only meaningful for a specific lifecycle action — `--trace`/`--strict-exit`/`--fail-on-warn` require `--doctor`, `--watch` requires `--reload`, `--runtime-probe` requires `--manage`, `--fix-managed-state` requires `--manage`/`--doctor`, and `--capability`/`--declarative` require `--init`/`--scaffold`. Each guard pairs a "flag is set" predicate with the action(s) that permit it and throws a USAGE error on the first mismatch. */
855
+ const assertExtensionActionOptionScope = (action, options) => {
856
+ const guards = [
857
+ {
858
+ triggered: options.strictExit === true || options.failOnWarn === true,
859
+ allowed: action === "doctor",
860
+ message: "--strict-exit and --fail-on-warn are only valid with --doctor.",
861
+ },
862
+ {
863
+ triggered: options.trace === true,
864
+ allowed: action === "doctor",
865
+ message: "--trace is only valid with --doctor.",
866
+ },
867
+ {
868
+ triggered: options.watch === true,
869
+ allowed: action === "reload",
870
+ message: "--watch is only valid with --reload.",
871
+ },
872
+ {
873
+ triggered: options.runtimeProbe === true,
874
+ allowed: action === "manage",
875
+ message: "--runtime-probe is only valid with --manage.",
876
+ },
877
+ {
878
+ triggered: options.fixManagedState === true,
879
+ allowed: action === "manage" || action === "doctor",
880
+ message: "--fix-managed-state is only valid with --manage or --doctor.",
881
+ },
882
+ {
883
+ triggered: options.isolated === true || options.ignoreGlobal === true,
884
+ allowed: action === "doctor",
885
+ message: "--isolated and --ignore-global are only valid with --doctor.",
886
+ },
887
+ {
888
+ triggered: options.capability !== undefined,
889
+ allowed: action === "init",
890
+ message: "--capability is only valid with --init/--scaffold.",
891
+ },
892
+ {
893
+ triggered: options.declarative === true,
894
+ allowed: action === "init",
895
+ message: "--declarative is only valid with --init/--scaffold.",
896
+ },
897
+ ];
898
+ const invalidGuard = guards.find((guard) => guard.triggered && !guard.allowed);
899
+ if (invalidGuard) {
900
+ throw new PmCliError(invalidGuard.message, EXIT_CODE.USAGE);
901
+ }
902
+ };
903
+ /* c8 ignore start -- alias-normalization matrix is covered by resolveAction tests; this only rewrites positional aliases */
904
+ /** Collapse a positional target that merely repeats the action keyword (`pm extension doctor`, `reload`, `catalog`, or `init`/`scaffold`) to `undefined` so the action handlers treat it as "no target" rather than an extension name; otherwise the original target is returned unchanged. */
905
+ const resolveNormalizedExtensionTarget = (target, action, options) => {
906
+ const normalizedInput = String(target ?? "")
907
+ .trim()
908
+ .toLowerCase();
909
+ const explicitInitAction = [options.init, options.scaffold].includes(true);
910
+ const aliases = {
911
+ doctor: ["doctor"],
912
+ reload: ["reload"],
913
+ catalog: ["catalog"],
914
+ init: explicitInitAction ? [] : ["init", "scaffold"],
915
+ };
916
+ return (aliases[action] ?? []).includes(normalizedInput) ? undefined : target;
917
+ };
918
+ /* c8 ignore stop */
919
+ /** Resolve stable roots for lifecycle results, including field-projected catalogs. */
920
+ const resolveExtensionResultRoots = (ctx) => {
921
+ const projectedCatalog = [
922
+ ctx.action === "catalog",
923
+ typeof ctx.options.fields === "string",
924
+ String(ctx.options.fields).trim().length > 0,
925
+ ].every(Boolean);
926
+ return projectedCatalog
927
+ ? {
928
+ project: "project",
929
+ global: "global",
930
+ selected: ctx.scope,
931
+ settings_root: "project",
932
+ }
933
+ : {
934
+ project: ctx.resolvedRoots.roots.project,
935
+ global: ctx.resolvedRoots.roots.global,
936
+ selected: ctx.resolvedRoots.selected_root,
937
+ settings_root: ctx.resolvedRoots.settings_root,
938
+ };
939
+ };
940
+ /** Build and mark one canonical lifecycle result envelope. */
941
+ const buildExtensionActionResult = (ctx, details, ok) => {
942
+ const result = {
943
+ ok,
944
+ action: ctx.action,
945
+ scope: ctx.scope,
946
+ roots: resolveExtensionResultRoots(ctx),
947
+ warnings: [...new Set(ctx.warnings)].sort((left, right) => left.localeCompare(right)),
948
+ details,
949
+ };
950
+ if (ctx.action === "doctor") {
951
+ Object.defineProperty(result, NATIVE_OUTPUT_MARKER, {
952
+ value: true,
953
+ enumerable: false,
954
+ configurable: false,
955
+ });
956
+ }
957
+ return result;
958
+ };
959
+ /**
960
+ * Entry point for the `pm extension` / `pm package` command surface. Resolves the
961
+ * requested lifecycle action and scope, rejects out-of-scope option usage,
962
+ * normalizes positional aliases, then dispatches to the matching action handler —
963
+ * each of which reads and writes managed-extension state, runtime-probes, and
964
+ * returns the canonical {@link ExtensionCommandResult}. `--doctor` results are
965
+ * flagged for native (non-JSON-wrapped) output.
966
+ */
967
+ export const runExtension = async (target, options, global) => {
968
+ const action = resolveAction(target, options);
969
+ assertExtensionActionOptionScope(action, options);
970
+ const normalizedTarget = resolveNormalizedExtensionTarget(target, action, options);
971
+ const scope = resolveScope(options);
972
+ const resolvedRoots = resolveExtensionRootsForScope(scope, global);
973
+ const warnings = [];
974
+ const actionContext = {
975
+ action,
976
+ normalizedTarget,
977
+ scope,
978
+ resolvedRoots,
979
+ warnings,
980
+ options,
981
+ global,
982
+ };
983
+ /** Build the canonical lifecycle result envelope for this invocation. */
984
+ const withResult = (details, ok = true) => buildExtensionActionResult(actionContext, details, ok);
985
+ const ctx = {
986
+ ...actionContext,
987
+ withResult,
988
+ };
989
+ return await dispatchExtensionAction(ctx);
990
+ };
991
+ /** Build copy-pasteable setup and validation guidance for a fresh scaffold. */
992
+ const buildExtensionScaffoldNextSteps = (scaffold, options) => {
993
+ const vocabulary = options.vocabulary ?? "extension";
994
+ const shellTargetPath = scaffold.target_path.replace(/\\/g, "/");
995
+ const quotedShellTargetPath = quoteCommandArg(shellTargetPath);
996
+ const dependencySteps = {
997
+ package: `Install dependencies: cd ${quotedShellTargetPath}, then run "npm install"`,
998
+ extension: `Install type-check dependencies: cd ${quotedShellTargetPath}, then run "npm install -D typescript @types/node @unbrained/pm-cli"`,
999
+ };
1000
+ const validationSteps = {
1001
+ package: `Validate the package: cd ${quotedShellTargetPath}, then run "npm run typecheck" and "npm test"`,
1002
+ extension: `Type-check the source (optional): cd ${quotedShellTargetPath}, then run "npx tsc --noEmit"`,
1003
+ };
1004
+ const declarativeGuidance = [];
1005
+ if ([vocabulary === "package", options.declarative === true].every(Boolean)) {
1006
+ declarativeGuidance.push("Ensure the target workspace can resolve @unbrained/pm-cli before installing this declarative package.");
1007
+ }
1008
+ return [
1009
+ dependencySteps[vocabulary],
1010
+ ...declarativeGuidance,
1011
+ `Install the scaffold: ${renderPmCommand(vocabulary === "package"
1012
+ ? ["install", "--project", shellTargetPath]
1013
+ : ["extension", "--install", "--project", shellTargetPath])}`,
1014
+ `Smoke-test command path: pm ${scaffold.command_name}`,
1015
+ validationSteps[vocabulary],
1016
+ `Run diagnostics: ${vocabulary === "package" ? "pm package doctor" : "pm extension --doctor"} --project --detail summary`,
1017
+ ];
1018
+ };
1019
+ /** Scaffold a new extension project from normalized lifecycle options. */
1020
+ const runExtensionInitAction = async (ctx) => {
1021
+ const { action, normalizedTarget, options, withResult } = ctx;
1022
+ const githubOption = resolveGithubOption(options);
1023
+ const disallowedSourceOptions = [githubOption, options.ref]
1024
+ .filter((value) => typeof value === "string")
1025
+ .map((value) => value.trim())
1026
+ .filter(Boolean);
1027
+ if (disallowedSourceOptions.length > 0) {
1028
+ throw new PmCliError('Action "init" does not accept --gh/--github/--ref options.', EXIT_CODE.USAGE);
1029
+ }
1030
+ const scaffoldTarget = requireTarget(normalizedTarget, action, options);
1031
+ const scaffold = await scaffoldExtensionProject(scaffoldTarget, options.vocabulary ?? "extension", options.capability, options.declarative === true);
1032
+ return withResult({
1033
+ scaffolded: scaffold.created_directory ||
1034
+ scaffold.files.some((entry) => entry.status === "created"),
1035
+ extension: {
1036
+ name: scaffold.extension_name,
1037
+ command: scaffold.command_name,
1038
+ },
1039
+ capability: scaffold.capability,
1040
+ style: scaffold.style,
1041
+ target_path: scaffold.target_path,
1042
+ created_directory: scaffold.created_directory,
1043
+ files: scaffold.files,
1044
+ next_steps: buildExtensionScaffoldNextSteps(scaffold, options),
1045
+ });
1046
+ };
1047
+ /** Reload extension runtime state and report the new generation token. */
1048
+ const runExtensionReloadAction = async (ctx) => {
1049
+ const { normalizedTarget, resolvedRoots, warnings, options, global, withResult, } = ctx;
1050
+ if (normalizedTarget !== undefined) {
1051
+ throw new PmCliError('Action "reload" does not accept a target argument.', EXIT_CODE.USAGE);
1052
+ }
1053
+ const settings = await readSettings(resolvedRoots.settings_root);
1054
+ const reloadToken = nextExtensionReloadToken();
1055
+ const reloaded = await loadExtensions({
1056
+ pmRoot: resolvedRoots.settings_root,
1057
+ settings,
1058
+ cwd: process.cwd(),
1059
+ noExtensions: global.noExtensions,
1060
+ reload_token: reloadToken,
1061
+ cache_bust: true,
1062
+ });
1063
+ warnings.push(...reloaded.warnings);
1064
+ const activation = await activateExtensions(reloaded);
1065
+ warnings.push(...activation.warnings);
1066
+ const details = {
1067
+ reload: {
1068
+ token: reloadToken,
1069
+ cache_bust: true,
1070
+ watch: options.watch === true,
1071
+ },
1072
+ loaded_count: reloaded.loaded.length,
1073
+ failed_count: reloaded.failed.length,
1074
+ activated_count: Math.max(0, reloaded.loaded.length - activation.failed.length),
1075
+ activation_failed_count: activation.failed.length,
1076
+ loaded_extensions: reloaded.loaded.map((entry) => ({
1077
+ name: entry.name,
1078
+ layer: entry.layer,
1079
+ version: entry.version,
1080
+ })),
1081
+ failed_extensions: reloaded.failed.map((entry) => ({
1082
+ name: entry.name,
1083
+ layer: entry.layer,
1084
+ error: entry.error,
1085
+ })),
1086
+ activation_failures: activation.failed.map((entry) => ({
1087
+ name: entry.name,
1088
+ layer: entry.layer,
1089
+ error: entry.error,
1090
+ })),
1091
+ };
1092
+ if (options.watch === true) {
1093
+ warnings.push("extension_reload_watch_hint:watch_mode_requested_non_interactive_single_pass_only");
1094
+ }
1095
+ return withResult(details);
1096
+ };
1097
+ /** List bundled and installed extension catalog entries. */
1098
+ const runExtensionCatalogAction = async (ctx) => {
1099
+ const { normalizedTarget, scope, options, global, withResult } = ctx;
1100
+ if (typeof normalizedTarget === "string" &&
1101
+ normalizedTarget.length > 0 &&
1102
+ normalizedTarget !== "catalog") {
1103
+ throw new PmCliError('Action "catalog" does not accept a package target.', EXIT_CODE.USAGE);
1104
+ }
1105
+ return withResult(await buildBundledPackageCatalog(scope, global, options));
1106
+ };
1107
+ /* c8 ignore start -- source-shape branch combinations are exercised in install-source focused tests */
1108
+ /** Build managed provenance for a bundled first-party extension alias. */
1109
+ const buildBundledInstallManagedSource = (alias, packageName) => ({
1110
+ kind: "builtin",
1111
+ input: alias,
1112
+ location: alias,
1113
+ name: alias,
1114
+ ...(packageName === null ? {} : { package: packageName }),
1115
+ });
1116
+ /** Build managed provenance for a local extension source. */
1117
+ const buildLocalInstallManagedSource = (source) => ({
1118
+ kind: "local",
1119
+ input: source.input,
1120
+ location: source.absolute_path,
1121
+ });
1122
+ /** Build managed provenance for an npm extension source. */
1123
+ const buildNpmInstallManagedSource = (source, resolved) => ({
1124
+ kind: "npm",
1125
+ input: source.input,
1126
+ location: resolved.resolved_subpath ?? ".",
1127
+ package: resolved.npm_package,
1128
+ version: resolved.npm_version,
1129
+ });
1130
+ /** Build managed provenance for a GitHub extension source. */
1131
+ const buildGithubInstallManagedSource = (source, resolved) => ({
1132
+ kind: "github",
1133
+ input: source.input,
1134
+ location: resolved.resolved_subpath ?? source.subpath ?? ".",
1135
+ repository: source.repository,
1136
+ owner: source.owner,
1137
+ repo: source.repo,
1138
+ ref: source.ref,
1139
+ subpath: resolved.resolved_subpath ?? source.subpath,
1140
+ commit: resolved.commit,
1141
+ });
1142
+ /** Build the persisted managed-source record for an install from its resolved shape: a bundled builtin alias, a local path, an npm package, or (the default) a GitHub repository, capturing the location/commit/subpath provenance the manage and upgrade flows later read back. */
1143
+ const buildInstallManagedSource = (bundledAliasName, bundledPackageName, installSource, resolvedSource) => {
1144
+ if (bundledAliasName) {
1145
+ return buildBundledInstallManagedSource(bundledAliasName, bundledPackageName);
1146
+ }
1147
+ if (installSource.kind === "local") {
1148
+ return buildLocalInstallManagedSource(installSource);
1149
+ }
1150
+ if (installSource.kind === "npm") {
1151
+ return buildNpmInstallManagedSource(installSource, resolvedSource);
1152
+ }
1153
+ return buildGithubInstallManagedSource(installSource, resolvedSource);
1154
+ };
1155
+ /** Preserve original install time and only advance update time when source content changed. */
1156
+ const resolveManagedInstallTimestamps = (existing, manifestVersion, source, now) => {
1157
+ if (!existing)
1158
+ return { installed_at: now, updated_at: now };
1159
+ if (existing.manifest_version !== manifestVersion) {
1160
+ return { installed_at: existing.installed_at, updated_at: now };
1161
+ }
1162
+ if (!managedExtensionSourcesEquivalent(existing.source, source)) {
1163
+ return { installed_at: existing.installed_at, updated_at: now };
1164
+ }
1165
+ return {
1166
+ installed_at: existing.installed_at,
1167
+ updated_at: existing.updated_at,
1168
+ };
1169
+ };
1170
+ /** Copy and persist one validated extension before its runtime activation probe. */
1171
+ const persistExtensionInstall = async (ctx, input) => {
1172
+ const { scope, resolvedRoots, warnings } = ctx;
1173
+ const { validated, destinationDirectoryName } = input;
1174
+ const settings = await readSettings(resolvedRoots.settings_root);
1175
+ const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
1176
+ warnings.push(...managedStateRead.warnings);
1177
+ const destinationDirectory = path.join(resolvedRoots.selected_root, destinationDirectoryName);
1178
+ const destinationExists = await pathExists(destinationDirectory);
1179
+ const installInPlace = await areDirectoriesEquivalent(validated.directory, destinationDirectory);
1180
+ await fs.mkdir(resolvedRoots.selected_root, { recursive: true });
1181
+ const backupRoot = await fs.mkdtemp(path.join(resolvedRoots.selected_root, ".pm-extension-install-backup-"));
1182
+ const backupDirectory = path.join(backupRoot, "destination");
1183
+ try {
1184
+ const snapshot = await captureExtensionInstallSnapshot(resolvedRoots.selected_root, resolvedRoots.settings_root, destinationDirectory, destinationExists, backupDirectory);
1185
+ const sourceRecord = buildInstallManagedSource(input.bundledAliasName, input.bundledPackageName, input.installSource, input.resolvedSource);
1186
+ const existingManagedEntry = managedStateRead.state.entries.find((entry) => normalizeExtensionNameForMatch(entry.name) ===
1187
+ normalizeExtensionNameForMatch(validated.manifest.name));
1188
+ const timestamps = resolveManagedInstallTimestamps(existingManagedEntry, validated.manifest.version, sourceRecord, nowIso());
1189
+ const managedState = upsertManagedEntry(managedStateRead.state, {
1190
+ name: validated.manifest.name,
1191
+ directory: destinationDirectoryName,
1192
+ scope,
1193
+ manifest_version: validated.manifest.version,
1194
+ manifest_entry: validated.manifest.entry,
1195
+ capabilities: [...validated.manifest.capabilities],
1196
+ ...timestamps,
1197
+ source: sourceRecord,
1198
+ });
1199
+ const activationChanged = ensureActivated(settings, validated.manifest.name);
1200
+ try {
1201
+ if (!installInPlace) {
1202
+ await copyExtensionDirectoryForInstall(validated.directory, destinationDirectory);
1203
+ }
1204
+ await ensureExtensionModuleTypeMarker(destinationDirectory);
1205
+ await writeManagedExtensionState(resolvedRoots.selected_root, managedState);
1206
+ if (activationChanged) {
1207
+ await writeSettings(resolvedRoots.settings_root, settings, "settings:write");
1208
+ }
1209
+ }
1210
+ catch (error) {
1211
+ try {
1212
+ await restoreExtensionInstallSnapshot(snapshot);
1213
+ }
1214
+ catch (rollbackError) {
1215
+ throw new AggregateError([error, rollbackError], `Extension install failed: ${String(error)}; rollback failed: ${String(rollbackError)}`, { cause: rollbackError });
1216
+ }
1217
+ throw error;
1218
+ }
1219
+ return {
1220
+ settings,
1221
+ managedState,
1222
+ sourceRecord,
1223
+ destinationDirectory,
1224
+ destinationExists,
1225
+ installInPlace,
1226
+ activationChanged,
1227
+ };
1228
+ }
1229
+ finally {
1230
+ await fs
1231
+ .rm(backupRoot, { recursive: true, force: true })
1232
+ .catch(() => undefined);
1233
+ }
1234
+ };
1235
+ /** Scaffold project folders contributed by item types from the installed extension. */
1236
+ const scaffoldInstalledExtensionItemTypes = async (ctx, extensionName, registrations) => {
1237
+ const definitions = registrations
1238
+ .filter((entry) => normalizeExtensionNameForMatch(entry.name) ===
1239
+ normalizeExtensionNameForMatch(extensionName))
1240
+ .flatMap((entry) => entry.types.map((type) => ({ name: type.name, folder: type.folder })));
1241
+ if (ctx.scope === "project" && definitions.length > 0) {
1242
+ await ensureTypeFolderScaffold(ctx.resolvedRoots.pm_root, definitions, ctx.warnings, "install:type-folder");
1243
+ }
1244
+ return definitions;
1245
+ };
1246
+ /** Resolve post-install activation state, warnings, and health verification. */
1247
+ const buildInstalledExtensionActivation = (ctx, extensionName, runtimeProbe, commandSummary, installedItemTypes) => {
1248
+ const failure = findActivationFailureByName(extensionName, runtimeProbe.activation_failures, ctx.scope);
1249
+ const status = resolveInstallRuntimeActivationStatus(extensionName, ctx.scope, runtimeProbe.installed, failure);
1250
+ const activated = [!runtimeProbe.extensions_disabled, status === "ok"].every(Boolean);
1251
+ if (!activated) {
1252
+ ctx.warnings.push(`extension_install_activation_failed:${ctx.scope}:${extensionName}:${status}`);
1253
+ }
1254
+ const healthByActivation = {
1255
+ true: { status: "ok", blocking_failure_count: 0 },
1256
+ false: { status: "degraded", blocking_failure_count: 1 },
1257
+ };
1258
+ return {
1259
+ activated,
1260
+ status,
1261
+ failure,
1262
+ verification: {
1263
+ status: healthByActivation[String(activated)].status,
1264
+ target_pm_root: ctx.resolvedRoots.pm_root,
1265
+ activation_status: status,
1266
+ activated,
1267
+ registered_commands: commandSummary.command_paths,
1268
+ registered_actions: commandSummary.action_paths,
1269
+ registered_item_types: installedItemTypes,
1270
+ health: healthByActivation[String(activated)],
1271
+ },
1272
+ };
1273
+ };
1274
+ /** Run the install body while holding the scope-wide install lock: read settings and managed state, copy the validated extension into the scope root unless it is already installed in place, upsert the managed entry and activation state, scaffold any contributed item-type folders, runtime-probe the freshly installed command paths, and return the install result envelope. */
1275
+ const performExtensionInstallUnderLock = async (ctx, input) => {
1276
+ const { scope, resolvedRoots, warnings, global, withResult } = ctx;
1277
+ const { validated, destinationDirectoryName } = input;
1278
+ const persisted = await persistExtensionInstall(ctx, input);
1279
+ const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, persisted.settings, persisted.managedState);
1280
+ warnings.push(...refreshedInstalled.warnings);
1281
+ const runtimeProbe = await probeRuntimeCommandPathsForInstall(resolvedRoots.pm_root, persisted.settings, refreshedInstalled.extensions, global);
1282
+ warnings.push(...runtimeProbe.warnings);
1283
+ // Scaffold the folders for any item types the installed package contributes
1284
+ // so the tracker is immediately healthy — matching `pm schema add-type` and
1285
+ // `pm profile apply`, the other paths that register a type. Without this a
1286
+ // freshly-installed schema package leaves a `missing_directory` health
1287
+ // warning until the first item of its type is created. Scoped to project
1288
+ // installs, where `pm_root` is unambiguously the tracker the type folders
1289
+ // belong to; a global install is not tied to one tracker, so its folders are
1290
+ // created lazily on first use in each project.
1291
+ const installedItemTypeDefinitions = await scaffoldInstalledExtensionItemTypes(ctx, validated.manifest.name, runtimeProbe.item_type_registrations);
1292
+ const commandSummary = summarizeRuntimeCommandPathsForExtension(validated.manifest.name, runtimeProbe.installed);
1293
+ const activation = buildInstalledExtensionActivation(ctx, validated.manifest.name, runtimeProbe, commandSummary, installedItemTypeDefinitions);
1294
+ return withResult({
1295
+ extension: {
1296
+ name: validated.manifest.name,
1297
+ version: validated.manifest.version,
1298
+ entry: validated.manifest.entry,
1299
+ capabilities: validated.manifest.capabilities,
1300
+ directory: destinationDirectoryName,
1301
+ },
1302
+ source: persisted.sourceRecord,
1303
+ destination_path: persisted.destinationDirectory,
1304
+ overwritten: [
1305
+ persisted.destinationExists,
1306
+ !persisted.installInPlace,
1307
+ ].every(Boolean),
1308
+ installed_in_place: persisted.installInPlace,
1309
+ activated: activation.activated,
1310
+ settings_changed: persisted.activationChanged,
1311
+ runtime_activation_status: activation.status,
1312
+ command_paths: commandSummary.command_paths,
1313
+ action_paths: commandSummary.action_paths,
1314
+ command_discovery: buildInstallCommandDiscovery(validated.manifest.name, persisted.sourceRecord, commandSummary, activation.failure),
1315
+ verification: activation.verification,
1316
+ activation_diagnostics: {
1317
+ failed_count: runtimeProbe.activation_failures.length,
1318
+ failed: runtimeProbe.activation_failures,
1319
+ installed_extension_failed: activation.failure ?? null,
1320
+ },
1321
+ }, activation.activated);
1322
+ };
1323
+ /** Install every bundled first-party package alias and aggregate verification. */
1324
+ const runBundledExtensionInstallAll = async (ctx) => {
1325
+ const { options, global, warnings, withResult } = ctx;
1326
+ if (typeof options.ref === "string" && options.ref.trim().length > 0) {
1327
+ throw new PmCliError('Action "install all" does not accept --ref.', EXIT_CODE.USAGE);
1328
+ }
1329
+ const packages = [];
1330
+ for (const alias of await listBundledPackageAliases()) {
1331
+ packages.push({
1332
+ alias,
1333
+ result: await runExtension(alias, { ...options, install: true }, global),
1334
+ });
1335
+ }
1336
+ warnings.push(...packages.flatMap((entry) => entry.result.warnings));
1337
+ const installedAll = packages.every((entry) => entry.result.ok);
1338
+ return withResult({
1339
+ installed_all: installedAll,
1340
+ installed_count: packages.filter((entry) => entry.result.ok).length,
1341
+ failed_count: packages.filter((entry) => !entry.result.ok).length,
1342
+ packages: packages.map((entry) => {
1343
+ const details = entry.result.details;
1344
+ return {
1345
+ alias: entry.alias,
1346
+ ok: entry.result.ok,
1347
+ extension: details.extension,
1348
+ source: details.source,
1349
+ destination_path: details.destination_path,
1350
+ activated: details.activated,
1351
+ settings_changed: details.settings_changed,
1352
+ command_paths: details.command_paths,
1353
+ action_paths: details.action_paths,
1354
+ command_discovery: details.command_discovery,
1355
+ verification: details.verification,
1356
+ runtime_activation_status: details.runtime_activation_status,
1357
+ activation_diagnostics: details.activation_diagnostics,
1358
+ warnings: entry.result.warnings,
1359
+ };
1360
+ }),
1361
+ }, installedAll);
1362
+ };
1363
+ /** Resolve bundled-alias provenance before installing one extension source. */
1364
+ const resolveSingleExtensionInstallSource = async (explicitSourceInput, githubOption, ref) => {
1365
+ /* c8 ignore start -- github/local alias-source split is exercised in install-action integration tests */
1366
+ const bundledAliasSource = typeof githubOption === "string"
1367
+ ? null
1368
+ : await resolveBundledExtensionAliasSource(explicitSourceInput);
1369
+ /* c8 ignore stop */
1370
+ const bundledAliasName = bundledAliasSource === null
1371
+ ? null
1372
+ : explicitSourceInput.trim().toLowerCase();
1373
+ const bundledPackageName = bundledAliasName === null
1374
+ ? null
1375
+ : await resolveBundledPackageNpmName(bundledAliasName);
1376
+ const sourceInput = bundledAliasSource ?? explicitSourceInput;
1377
+ /* c8 ignore start -- install-source branch combinations are covered in install-sources focused tests */
1378
+ const installSource = parseExtensionInstallSource(sourceInput, {
1379
+ forceGithub: typeof githubOption === "string",
1380
+ ref,
1381
+ });
1382
+ /* c8 ignore stop */
1383
+ return { bundledAliasName, bundledPackageName, installSource };
1384
+ };
1385
+ /** Install one resolved source and clean transient source material afterward. */
1386
+ const runSingleExtensionInstall = async (ctx, explicitSourceInput, githubOption) => {
1387
+ const { resolvedRoots } = ctx;
1388
+ const { bundledAliasName, bundledPackageName, installSource } = await resolveSingleExtensionInstallSource(explicitSourceInput, githubOption, ctx.options.ref);
1389
+ const resolvedSource = await resolveInstallSource(installSource);
1390
+ try {
1391
+ const validated = await validateExtensionDirectory(resolvedSource.directory);
1392
+ const destinationDirectoryName = normalizeManagedDirectoryName(validated.manifest.name);
1393
+ return await withExtensionInstallLock(resolvedRoots.settings_root, destinationDirectoryName, () => performExtensionInstallUnderLock(ctx, {
1394
+ validated,
1395
+ destinationDirectoryName,
1396
+ bundledAliasName,
1397
+ bundledPackageName,
1398
+ installSource,
1399
+ resolvedSource,
1400
+ }));
1401
+ }
1402
+ finally {
1403
+ /* c8 ignore start -- cleanup hooks are only present for transient install sources */
1404
+ if (resolvedSource.cleanup) {
1405
+ await resolvedSource.cleanup();
1406
+ }
1407
+ /* c8 ignore stop */
1408
+ }
1409
+ };
1410
+ /** Install one extension source under the owner-bound lifecycle lock. */
1411
+ const runExtensionInstallAction = async (ctx) => {
1412
+ const githubOption = resolveGithubOption(ctx.options);
1413
+ const explicitSourceInput = githubOption ??
1414
+ requireTarget(ctx.normalizedTarget, ctx.action, ctx.options);
1415
+ if ([
1416
+ githubOption === undefined,
1417
+ isBundledPackageInstallAllTarget(explicitSourceInput),
1418
+ ].every(Boolean)) {
1419
+ return runBundledExtensionInstallAll(ctx);
1420
+ }
1421
+ return runSingleExtensionInstall(ctx, explicitSourceInput, githubOption);
1422
+ };
1423
+ /** Adopt every eligible unmanaged extension in the selected scope. */
1424
+ const runExtensionAdoptAllAction = async (ctx) => {
1425
+ const { normalizedTarget, scope, resolvedRoots, warnings, options, withResult, } = ctx;
1426
+ if (normalizedTarget !== undefined) {
1427
+ throw new PmCliError('Action "adopt-all" does not accept a target argument.', EXIT_CODE.USAGE);
1428
+ }
1429
+ const githubOption = resolveGithubOption(options);
1430
+ if (githubOption !== undefined ||
1431
+ (typeof options.ref === "string" && options.ref.trim().length > 0)) {
1432
+ throw new PmCliError('Action "adopt-all" does not accept --gh/--github/--ref options.', EXIT_CODE.USAGE);
1433
+ }
1434
+ const settings = await readSettings(resolvedRoots.settings_root);
1435
+ const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
1436
+ warnings.push(...managedStateRead.warnings);
1437
+ const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
1438
+ warnings.push(...installed.warnings);
1439
+ const adoption = await adoptUnmanagedExtensions(resolvedRoots.selected_root, scope, installed.extensions, managedStateRead.state);
1440
+ const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, adoption.state);
1441
+ warnings.push(...refreshedInstalled.warnings);
1442
+ const triage = buildExtensionTriageSummary(scope, warnings, refreshedInstalled.extensions, options);
1443
+ warnings.push(...triage.warnings);
1444
+ /* c8 ignore start -- refresh-entry optional metadata is display-only and exercised indirectly */
1445
+ const refreshedByIdentity = new Map(refreshedInstalled.extensions.map((entry) => [
1446
+ `${normalizeExtensionNameForMatch(entry.name)}:${normalizeExtensionNameForMatch(entry.directory)}`,
1447
+ entry,
1448
+ ]));
1449
+ const refreshedByDirectory = new Map(refreshedInstalled.extensions.map((entry) => [
1450
+ normalizeExtensionNameForMatch(entry.directory),
1451
+ entry,
1452
+ ]));
1453
+ const adoptedDetails = adoption.adopted_entries.map((entry) => {
1454
+ const normalizedDirectory = normalizeExtensionNameForMatch(entry.directory);
1455
+ const refreshedEntry = refreshedByIdentity.get(`${normalizeExtensionNameForMatch(entry.name)}:${normalizedDirectory}`) ?? refreshedByDirectory.get(normalizedDirectory);
1456
+ return { ...entry, ...projectExtensionUpdateCheck(refreshedEntry) };
1457
+ });
1458
+ /* c8 ignore stop */
1459
+ /* c8 ignore start -- adopt-all summary booleans are deterministic mirrors of adoptedDetails length */
1460
+ return withResult({
1461
+ adopted_all: adoptedDetails.length > 0,
1462
+ adopted_count: adoptedDetails.length,
1463
+ already_managed_count: adoption.already_managed_count,
1464
+ extensions: adoptedDetails,
1465
+ triage,
1466
+ warning_codes: triage.warning_codes,
1467
+ update_health_partial: triage.update_health_partial,
1468
+ update_health_coverage: triage.update_health_coverage,
1469
+ });
1470
+ /* c8 ignore stop */
1471
+ };
1472
+ /** Project nullable update-check metadata for adopt result payloads. */
1473
+ const projectExtensionUpdateCheck = (entry) => {
1474
+ return {
1475
+ update_check_status: entry?.update_check_status ?? null,
1476
+ update_check_reason: entry?.update_check_reason ?? null,
1477
+ };
1478
+ };
1479
+ /** Resolve local or GitHub provenance for an adopted extension. */
1480
+ const buildAdoptedExtensionSource = (githubOption, extensionTarget, extensionDirectory, ref) => {
1481
+ if (githubOption === undefined) {
1482
+ return {
1483
+ kind: "local",
1484
+ input: extensionTarget,
1485
+ location: extensionDirectory,
1486
+ };
1487
+ }
1488
+ const parsed = parseExtensionInstallSource(githubOption, {
1489
+ forceGithub: true,
1490
+ ref,
1491
+ });
1492
+ /* c8 ignore start -- forceGithub guarantees a github-kind install source */
1493
+ if (parsed.kind !== "github") {
1494
+ throw new PmCliError(`Invalid GitHub shorthand "${githubOption}".`, EXIT_CODE.USAGE);
1495
+ }
1496
+ /* c8 ignore stop */
1497
+ return {
1498
+ kind: "github",
1499
+ input: parsed.input,
1500
+ location: parsed.subpath ?? ".",
1501
+ repository: parsed.repository,
1502
+ owner: parsed.owner,
1503
+ repo: parsed.repo,
1504
+ ref: parsed.ref,
1505
+ subpath: parsed.subpath,
1506
+ };
1507
+ };
1508
+ /** Adopt one unmanaged extension into managed lifecycle state. */
1509
+ const runExtensionAdoptAction = async (ctx) => {
1510
+ const { action, normalizedTarget, scope, resolvedRoots, warnings, options, withResult, } = ctx;
1511
+ const extensionTarget = requireTarget(normalizedTarget, action, options);
1512
+ const githubOption = resolveGithubOption(options);
1513
+ const settings = await readSettings(resolvedRoots.settings_root);
1514
+ const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
1515
+ warnings.push(...managedStateRead.warnings);
1516
+ const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
1517
+ warnings.push(...installed.warnings);
1518
+ const candidate = await resolveInstalledExtensionCandidate(installed.extensions, extensionTarget);
1519
+ if (!candidate) {
1520
+ throw new PmCliError(`Installed extension "${extensionTarget}" was not found in ${scope} scope.`, EXIT_CODE.NOT_FOUND);
1521
+ }
1522
+ if (candidate.managed) {
1523
+ return withResult({
1524
+ adopted: false,
1525
+ already_managed: true,
1526
+ extension: {
1527
+ name: candidate.name,
1528
+ directory: candidate.directory,
1529
+ },
1530
+ });
1531
+ }
1532
+ const extensionDirectory = path.join(resolvedRoots.selected_root, candidate.directory);
1533
+ const validated = await validateExtensionDirectory(extensionDirectory);
1534
+ const now = nowIso();
1535
+ const sourceRecord = buildAdoptedExtensionSource(githubOption, extensionTarget, extensionDirectory, options.ref);
1536
+ const managedState = upsertManagedEntry(managedStateRead.state, {
1537
+ name: validated.manifest.name,
1538
+ directory: candidate.directory,
1539
+ scope,
1540
+ manifest_version: validated.manifest.version,
1541
+ manifest_entry: validated.manifest.entry,
1542
+ capabilities: [...validated.manifest.capabilities],
1543
+ installed_at: now,
1544
+ updated_at: now,
1545
+ source: sourceRecord,
1546
+ });
1547
+ await writeManagedExtensionState(resolvedRoots.selected_root, managedState);
1548
+ const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedState);
1549
+ warnings.push(...refreshedInstalled.warnings);
1550
+ /* c8 ignore start -- fallback only matters if a manifest renames between adopt and refresh */
1551
+ const refreshedEntry = refreshedInstalled.extensions.find((entry) => normalizeExtensionNameForMatch(entry.name) ===
1552
+ normalizeExtensionNameForMatch(validated.manifest.name)) ??
1553
+ refreshedInstalled.extensions.find((entry) => normalizeExtensionNameForMatch(entry.directory) ===
1554
+ normalizeExtensionNameForMatch(candidate.directory));
1555
+ /* c8 ignore stop */
1556
+ /* c8 ignore start -- adopt result mirrors refreshedEntry optionals for display only */
1557
+ return withResult({
1558
+ adopted: true,
1559
+ extension: {
1560
+ name: validated.manifest.name,
1561
+ directory: candidate.directory,
1562
+ version: validated.manifest.version,
1563
+ entry: validated.manifest.entry,
1564
+ },
1565
+ source: sourceRecord,
1566
+ ...projectExtensionUpdateCheck(refreshedEntry),
1567
+ });
1568
+ /* c8 ignore stop */
1569
+ };
1570
+ /** Resolve a required installed extension or throw structured not-found guidance. */
1571
+ const resolveRequiredInstalledExtension = async (ctx) => {
1572
+ const { action, normalizedTarget, scope, resolvedRoots, warnings, options } = ctx;
1573
+ const extensionTarget = requireTarget(normalizedTarget, action, options);
1574
+ const settings = await readSettings(resolvedRoots.settings_root);
1575
+ const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
1576
+ warnings.push(...managedStateRead.warnings);
1577
+ const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
1578
+ warnings.push(...installed.warnings);
1579
+ const candidate = await resolveInstalledExtensionCandidate(installed.extensions, extensionTarget);
1580
+ if (!candidate) {
1581
+ throw new PmCliError(`Installed extension "${extensionTarget}" was not found in ${scope} scope.`, EXIT_CODE.NOT_FOUND);
1582
+ }
1583
+ return { settings, managedStateRead, candidate };
1584
+ };
1585
+ /** Uninstall one managed extension and update lifecycle state. */
1586
+ const runExtensionUninstallAction = async (ctx) => {
1587
+ const { resolvedRoots, withResult } = ctx;
1588
+ const { settings, managedStateRead, candidate } = await resolveRequiredInstalledExtension(ctx);
1589
+ const destinationDirectory = path.join(resolvedRoots.selected_root, candidate.directory);
1590
+ await fs.rm(destinationDirectory, { recursive: true, force: true });
1591
+ const updatedState = {
1592
+ ...managedStateRead.state,
1593
+ updated_at: nowIso(),
1594
+ /* c8 ignore start -- uninstall filter keeps both name+directory guards for legacy managed-state migrations */
1595
+ entries: managedStateRead.state.entries.filter((entry) => normalizeExtensionNameForMatch(entry.name) !==
1596
+ normalizeExtensionNameForMatch(candidate.name) &&
1597
+ normalizeExtensionNameForMatch(entry.directory) !==
1598
+ normalizeExtensionNameForMatch(candidate.directory)),
1599
+ /* c8 ignore stop */
1600
+ };
1601
+ await writeManagedExtensionState(resolvedRoots.selected_root, updatedState);
1602
+ const stateChanged = clearExtensionState(settings, candidate.name);
1603
+ if (stateChanged) {
1604
+ await writeSettings(resolvedRoots.settings_root, settings, "settings:write");
1605
+ }
1606
+ return withResult({
1607
+ removed: true,
1608
+ extension: {
1609
+ name: candidate.name,
1610
+ directory: candidate.directory,
1611
+ },
1612
+ destination_path: destinationDirectory,
1613
+ settings_changed: stateChanged,
1614
+ });
1615
+ };
1616
+ /** Activate or deactivate one installed extension and persist the resulting state. */
1617
+ const runExtensionActivateDeactivateAction = async (ctx) => {
1618
+ const { action, resolvedRoots, withResult } = ctx;
1619
+ const { settings, candidate } = await resolveRequiredInstalledExtension(ctx);
1620
+ const settingsChanged = action === "activate"
1621
+ ? ensureActivated(settings, candidate.name)
1622
+ : ensureDeactivated(settings, candidate.name);
1623
+ if (settingsChanged) {
1624
+ await writeSettings(resolvedRoots.settings_root, settings, "settings:write");
1625
+ }
1626
+ return withResult({
1627
+ extension: {
1628
+ name: candidate.name,
1629
+ directory: candidate.directory,
1630
+ },
1631
+ active: action === "activate",
1632
+ settings_changed: settingsChanged,
1633
+ settings: {
1634
+ enabled: [...settings.extensions.enabled],
1635
+ disabled: [...settings.extensions.disabled],
1636
+ },
1637
+ });
1638
+ };
1639
+ /** Assemble the doctor remediation hints: the triage remediations, vocabulary-aware advice to inspect load failures and activation failures, and a note when a managed-state fix adopted entries. Blank entries are trimmed and the list is de-duplicated. */
1640
+ const buildDoctorRemediation = (baseRemediation, loadFailureCount, activationFailureCount, vocabulary, managedStateFix, isolationHint) => {
1641
+ const noun = vocabulary === "package" ? "package" : "extension";
1642
+ const doctorAction = { package: "doctor", extension: "--doctor" }[noun];
1643
+ const adoptedCount = managedStateFix?.adopted_entries.length ?? 0;
1644
+ const conditionalEntries = [
1645
+ [isolationHint !== null, isolationHint ?? ""],
1646
+ [
1647
+ loadFailureCount > 0,
1648
+ `Run pm ${noun} explore --project and pm ${noun} explore --global to inspect load failures.`,
1649
+ ],
1650
+ [
1651
+ activationFailureCount > 0,
1652
+ `Review activation failures in pm ${noun} ${doctorAction} --detail deep output.`,
1653
+ ],
1654
+ [
1655
+ adoptedCount > 0,
1656
+ `Managed-state fix adopted ${adoptedCount} extension(s).`,
1657
+ ],
1658
+ ];
1659
+ return [
1660
+ ...new Set([
1661
+ ...baseRemediation,
1662
+ ...conditionalEntries
1663
+ .filter(([include]) => include)
1664
+ .map(([, entry]) => entry),
1665
+ ]
1666
+ .map((entry) => entry.trim())
1667
+ .filter((entry) => entry.length > 0)),
1668
+ ];
1669
+ };
1670
+ /** Return whether doctor details contain any global-layer diagnostics. */
1671
+ const hasGlobalLayerDiagnostics = (loadResult) => {
1672
+ return (loadResult.loaded.some((entry) => entry.layer === "global") ||
1673
+ loadResult.failed.some((entry) => entry.layer === "global") ||
1674
+ loadResult.warnings.some((warning) => warning.includes(":global:")));
1675
+ };
1676
+ /** Build the project-isolation remediation hint for global extension conflicts. */
1677
+ const buildDoctorIsolationHint = (scope, isolated, vocabulary, loadResult) => {
1678
+ if (scope !== "project" ||
1679
+ isolated ||
1680
+ !hasGlobalLayerDiagnostics(loadResult)) {
1681
+ return null;
1682
+ }
1683
+ const noun = vocabulary === "package" ? "package" : "extension";
1684
+ return (`Global ${noun} registrations are included in project diagnostics. ` +
1685
+ `For hermetic ${noun} smoke tests, rerun pm ${noun} doctor --project --isolated --detail deep --trace, ` +
1686
+ "or set PM_GLOBAL_PATH to a temporary directory for the whole test process.");
1687
+ };
1688
+ /** Validate doctor-only arguments and return normalized execution switches. */
1689
+ const resolveDoctorInvocationOptions = (target, scope, options) => {
1690
+ if (String(target ?? "").trim().length > 0) {
1691
+ throw new PmCliError('Action "doctor" does not accept a target argument.', EXIT_CODE.USAGE);
1692
+ }
1693
+ const isolated = [options.isolated, options.ignoreGlobal].includes(true);
1694
+ if ([isolated, scope === "global"].every(Boolean)) {
1695
+ throw new PmCliError("--isolated and --ignore-global are only valid with project-scope doctor diagnostics.", EXIT_CODE.USAGE);
1696
+ }
1697
+ const detailMode = parseDoctorDetailMode(options.detail);
1698
+ const includeTrace = options.trace === true;
1699
+ if ([includeTrace, detailMode !== "deep"].every(Boolean)) {
1700
+ throw new PmCliError("--trace requires --detail deep with --doctor.", EXIT_CODE.USAGE);
1701
+ }
1702
+ return { isolated, detailMode, includeTrace };
1703
+ };
1704
+ /** Optionally adopt unmanaged entries requested by doctor and return effective state. */
1705
+ const applyDoctorManagedStateFix = async (ctx, installed, state) => {
1706
+ if (ctx.options.fixManagedState !== true)
1707
+ return { state, fix: null };
1708
+ const fix = await adoptUnmanagedExtensions(ctx.resolvedRoots.selected_root, ctx.scope, installed, state);
1709
+ return { state: fix.state, fix };
1710
+ };
1711
+ /** Build the doctor isolation block shared by summary and details output so the over-the-wire payload stays identical for extension and package vocabulary. */
1712
+ const buildDoctorIsolationMetadata = (scope, isolated, vocabulary, loadResult) => {
1713
+ const noun = vocabulary === "package" ? "package" : "extension";
1714
+ if (scope !== "project") {
1715
+ return {
1716
+ isolated,
1717
+ global_extensions_included: false,
1718
+ global_diagnostics_present: hasGlobalLayerDiagnostics(loadResult),
1719
+ rerun_command: null,
1720
+ pm_global_path_recipe: null,
1721
+ };
1722
+ }
1723
+ const isolatedCommand = `pm ${noun} doctor --project --isolated --detail deep --trace`;
1724
+ return {
1725
+ isolated,
1726
+ global_extensions_included: !isolated,
1727
+ global_diagnostics_present: hasGlobalLayerDiagnostics(loadResult),
1728
+ rerun_command: isolated ? null : isolatedCommand,
1729
+ pm_global_path_recipe: `PM_GLOBAL_PATH=$(mktemp -d) pm ${noun} doctor --project --detail deep --trace`,
1730
+ };
1731
+ };
1732
+ /** Run extension integrity, activation, policy, and isolation diagnostics. */
1733
+ const runExtensionDoctorAction = async (ctx) => {
1734
+ const { normalizedTarget, scope, resolvedRoots, warnings, options, global, withResult, } = ctx;
1735
+ const { isolated, detailMode, includeTrace } = resolveDoctorInvocationOptions(normalizedTarget, scope, options);
1736
+ const settings = await readSettings(resolvedRoots.settings_root);
1737
+ const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
1738
+ warnings.push(...managedStateRead.warnings);
1739
+ const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
1740
+ warnings.push(...installed.warnings);
1741
+ const { state: managedState, fix: managedStateFix } = await applyDoctorManagedStateFix(ctx, installed.extensions, managedStateRead.state);
1742
+ const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedState);
1743
+ warnings.push(...refreshedInstalled.warnings);
1744
+ const loadResult = await loadExtensions({
1745
+ pmRoot: resolvedRoots.pm_root,
1746
+ settings,
1747
+ cwd: process.cwd(),
1748
+ noExtensions: global.noExtensions === true,
1749
+ ignoreGlobalExtensions: isolated,
1750
+ });
1751
+ const activationResult = await activateExtensions({
1752
+ ...loadResult,
1753
+ loaded: loadResult.loaded,
1754
+ });
1755
+ warnings.push(...loadResult.warnings);
1756
+ warnings.push(...classifyDoctorLoadFailureWarnings(loadResult.failed));
1757
+ warnings.push(...activationResult.warnings);
1758
+ warnings.push(...classifyDoctorActivationFailureWarnings(activationResult.failed));
1759
+ warnings.push(...classifyUnusedCapabilityWarnings(loadResult, activationResult));
1760
+ warnings.push(...collectGlobalOutputOverrideDoctorWarnings(activationResult));
1761
+ warnings.push(...collectSchemaNarrowActivationDoctorWarnings(loadResult, activationResult));
1762
+ const runtimeInstalledExtensions = applyDoctorRuntimeActivationState(refreshedInstalled.extensions, loadResult, activationResult);
1763
+ const doctorConsistency = buildDoctorConsistencySummary(scope, runtimeInstalledExtensions, loadResult.loaded.map((entry) => ({
1764
+ layer: entry.layer,
1765
+ name: entry.name,
1766
+ })), loadResult.failed.map((entry) => ({ name: entry.name })), loadResult.disabled_by_flag);
1767
+ warnings.push(...doctorConsistency.warnings);
1768
+ const updateCheckWarnings = runtimeInstalledExtensions
1769
+ .filter((entry) => entry.update_check_status === "failed")
1770
+ .map((entry) => `extension_update_check_failed:${entry.name}`);
1771
+ warnings.push(...updateCheckWarnings);
1772
+ const triage = buildExtensionTriageSummary(scope, warnings, runtimeInstalledExtensions, options);
1773
+ warnings.push(...triage.warnings);
1774
+ const normalizedWarnings = [...triage.warnings];
1775
+ const policySummary = {
1776
+ mode: loadResult.policy.mode,
1777
+ trust_mode: loadResult.policy.trust_mode,
1778
+ require_provenance: loadResult.policy.require_provenance,
1779
+ default_sandbox_profile: loadResult.policy.default_sandbox_profile,
1780
+ // Honest trust model (ADR pm-6ef3): keep this caveat to one concise line.
1781
+ sandbox_enforcement: "advisory: sandbox_profile/permissions are declaration-based load gates, not runtime isolation (ADR pm-6ef3)",
1782
+ trusted_extensions_count: loadResult.policy.trusted_extensions.length,
1783
+ allowed_extensions_count: loadResult.policy.allowed_extensions.length,
1784
+ blocked_extensions_count: loadResult.policy.blocked_extensions.length,
1785
+ allowed_capabilities_count: loadResult.policy.allowed_capabilities.length,
1786
+ blocked_capabilities_count: loadResult.policy.blocked_capabilities.length,
1787
+ allowed_surfaces_count: loadResult.policy.allowed_surfaces.length,
1788
+ blocked_surfaces_count: loadResult.policy.blocked_surfaces.length,
1789
+ allowed_commands_count: loadResult.policy.allowed_commands.length,
1790
+ blocked_commands_count: loadResult.policy.blocked_commands.length,
1791
+ allowed_actions_count: loadResult.policy.allowed_actions.length,
1792
+ blocked_actions_count: loadResult.policy.blocked_actions.length,
1793
+ allowed_services_count: loadResult.policy.allowed_services.length,
1794
+ blocked_services_count: loadResult.policy.blocked_services.length,
1795
+ extension_override_count: loadResult.policy.extension_overrides.length,
1796
+ };
1797
+ const capabilityGuidance = collectUnknownCapabilityGuidance(normalizedWarnings);
1798
+ const capabilityContract = buildCapabilityContractMetadata();
1799
+ const warningCodes = triage.warning_codes;
1800
+ const isolationHint = buildDoctorIsolationHint(scope, isolated, options.vocabulary, loadResult);
1801
+ const remediation = buildDoctorRemediation(triage.remediation, loadResult.failed.length, activationResult.failed.length, options.vocabulary, managedStateFix, isolationHint);
1802
+ const isolation = buildDoctorIsolationMetadata(scope, isolated, options.vocabulary, loadResult);
1803
+ const summary = {
1804
+ status: triage.status,
1805
+ scope,
1806
+ warning_count: triage.warning_count,
1807
+ warning_codes: warningCodes,
1808
+ total_extensions: runtimeInstalledExtensions.length,
1809
+ managed_total: runtimeInstalledExtensions.filter((entry) => entry.managed)
1810
+ .length,
1811
+ enabled_total: runtimeInstalledExtensions.filter((entry) => entry.enabled)
1812
+ .length,
1813
+ active_total: runtimeInstalledExtensions.filter((entry) => entry.active)
1814
+ .length,
1815
+ unmanaged_loaded_extension_count: triage.unmanaged_loaded_extension_count,
1816
+ unmanaged_action_required_extension_count: triage.unmanaged_action_required_extension_count,
1817
+ unmanaged_expected_extension_count: triage.unmanaged_expected_extension_count,
1818
+ runtime_active_total: runtimeInstalledExtensions.filter((entry) => entry.runtime_active === true).length,
1819
+ activation_status_totals: {
1820
+ ok: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "ok").length,
1821
+ failed: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "failed").length,
1822
+ not_loaded: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "not_loaded").length,
1823
+ unknown: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "unknown").length,
1824
+ },
1825
+ unknown_capability_count: capabilityGuidance.length,
1826
+ capability_contract_version: capabilityContract.version,
1827
+ update_available_total: runtimeInstalledExtensions.filter((entry) => entry.update_available === true).length,
1828
+ update_health_coverage: triage.update_health_coverage,
1829
+ update_health_partial: triage.update_health_partial,
1830
+ update_check_failed_total: runtimeInstalledExtensions.filter((entry) => entry.update_check_status === "failed").length,
1831
+ load_failure_count: loadResult.failed.length,
1832
+ activation_failure_count: activationResult.failed.length,
1833
+ blocking_failure_count: loadResult.failed.length + activationResult.failed.length,
1834
+ has_blocking_failures: loadResult.failed.length + activationResult.failed.length > 0,
1835
+ consistency_warning_count: doctorConsistency.warnings.length,
1836
+ trace_enabled: includeTrace,
1837
+ isolation,
1838
+ policy: policySummary,
1839
+ remediation,
1840
+ };
1841
+ const managedStateFixSummary = managedStateFix
1842
+ ? {
1843
+ requested: true,
1844
+ applied: managedStateFix.adopted_entries.length > 0,
1845
+ adopted_count: managedStateFix.adopted_entries.length,
1846
+ already_managed_count: managedStateFix.already_managed_count,
1847
+ adopted_extensions: managedStateFix.adopted_entries.map((entry) => entry.name),
1848
+ }
1849
+ : {
1850
+ requested: false,
1851
+ applied: false,
1852
+ adopted_count: 0,
1853
+ already_managed_count: refreshedInstalled.extensions.filter((entry) => entry.managed).length,
1854
+ adopted_extensions: [],
1855
+ };
1856
+ const details = {
1857
+ mode: detailMode,
1858
+ summary,
1859
+ triage,
1860
+ trace_enabled: includeTrace,
1861
+ capability_contract: capabilityContract,
1862
+ capability_guidance: capabilityGuidance,
1863
+ managed_state_fix: managedStateFixSummary,
1864
+ isolation,
1865
+ policy: loadResult.policy,
1866
+ };
1867
+ if (detailMode === "deep") {
1868
+ const activationFailedDetails = includeTrace
1869
+ ? activationResult.failed
1870
+ : activationResult.failed.map((entry) => {
1871
+ const { trace: _trace, ...rest } = entry;
1872
+ return rest;
1873
+ });
1874
+ details.deep = {
1875
+ warnings: normalizedWarnings,
1876
+ warning_codes: warningCodes,
1877
+ capability_contract: capabilityContract,
1878
+ capability_guidance: capabilityGuidance,
1879
+ trace_enabled: includeTrace,
1880
+ managed_state: {
1881
+ path: managedStateRead.path,
1882
+ count: managedState.entries.length,
1883
+ entries: managedState.entries,
1884
+ },
1885
+ installed_extensions: runtimeInstalledExtensions,
1886
+ load: {
1887
+ roots: loadResult.roots,
1888
+ policy: loadResult.policy,
1889
+ warnings: loadResult.warnings,
1890
+ failed: loadResult.failed,
1891
+ loaded: loadResult.loaded.map((entry) => ({
1892
+ layer: entry.layer,
1893
+ directory: entry.directory,
1894
+ name: entry.name,
1895
+ version: entry.version,
1896
+ entry: entry.entry,
1897
+ priority: entry.priority,
1898
+ })),
1899
+ },
1900
+ activation: {
1901
+ failed: activationFailedDetails,
1902
+ warnings: activationResult.warnings,
1903
+ hook_counts: activationResult.hook_counts,
1904
+ registration_counts: activationResult.registration_counts,
1905
+ parser_override_count: activationResult.parser_override_count,
1906
+ preflight_override_count: activationResult.preflight_override_count,
1907
+ service_override_count: activationResult.service_override_count,
1908
+ renderer_override_count: activationResult.renderer_override_count,
1909
+ },
1910
+ consistency: doctorConsistency.summary,
1911
+ };
1912
+ if (includeTrace) {
1913
+ details.deep.trace = {
1914
+ activation_failures: activationResult.failed
1915
+ .filter((entry) => entry.trace !== undefined)
1916
+ .map((entry) => ({
1917
+ layer: entry.layer,
1918
+ name: entry.name,
1919
+ entry_path: entry.entry_path,
1920
+ error: entry.error,
1921
+ method: entry.trace.method,
1922
+ command: entry.trace.command,
1923
+ capability: entry.trace.capability,
1924
+ missing_capability: entry.trace.missing_capability,
1925
+ registration_index: entry.trace.registration_index,
1926
+ expected_schema: entry.trace.expected_schema,
1927
+ hint: entry.trace.hint,
1928
+ received: entry.trace.received,
1929
+ })),
1930
+ };
1931
+ }
1932
+ }
1933
+ return withResult(details);
1934
+ };
1935
+ /** Describe one installed extension and its runtime registrations. */
1936
+ const runExtensionDescribeAction = async (ctx) => {
1937
+ const { normalizedTarget, scope, resolvedRoots, warnings, options, global, withResult, } = ctx;
1938
+ const settings = await readSettings(resolvedRoots.settings_root);
1939
+ const loadResult = await loadExtensions({
1940
+ pmRoot: resolvedRoots.pm_root,
1941
+ settings,
1942
+ cwd: process.cwd(),
1943
+ noExtensions: global.noExtensions === true,
1944
+ });
1945
+ const activationResult = await activateExtensions(loadResult);
1946
+ warnings.push(...loadResult.warnings);
1947
+ warnings.push(...activationResult.warnings);
1948
+ const describeResult = buildExtensionDescribeResult(normalizedTarget, loadResult, activationResult);
1949
+ if (normalizedTarget !== undefined &&
1950
+ describeResult.extensions.length === 0) {
1951
+ const noun = options.vocabulary === "package" ? "package" : "extension";
1952
+ const loadedNames = [
1953
+ ...new Set(loadResult.loaded.map((entry) => options.vocabulary === "package" &&
1954
+ typeof entry.source_package === "string" &&
1955
+ entry.source_package.trim().length > 0
1956
+ ? entry.source_package.trim()
1957
+ : entry.name)),
1958
+ ].sort((left, right) => left.localeCompare(right));
1959
+ const loadedHint = loadedNames.length > 0
1960
+ ? ` Loaded ${noun} names: ${loadedNames.join(", ")}.`
1961
+ : "";
1962
+ throw new PmCliError(`No loaded ${noun} named "${normalizedTarget}" was found in ${scope} scope.${loadedHint} Run pm ${noun} explore to list discovered ${noun}s.`, EXIT_CODE.NOT_FOUND);
1963
+ }
1964
+ return withResult({
1965
+ target: describeResult.target,
1966
+ total: describeResult.total,
1967
+ extensions: describeResult.extensions,
1968
+ union: describeResult.union,
1969
+ });
1970
+ };
1971
+ /* c8 ignore start -- explore/manage action split is validated by dedicated command-action tests */
1972
+ /** Apply manage-only adoption and remote update checks to managed extension state. */
1973
+ const prepareExploreManageState = async (ctx, installed, initialState) => {
1974
+ let state = initialState;
1975
+ let fix = null;
1976
+ if ([ctx.action === "manage", ctx.options.fixManagedState === true].every(Boolean)) {
1977
+ fix = await adoptUnmanagedExtensions(ctx.resolvedRoots.selected_root, ctx.scope, installed, initialState);
1978
+ state = fix.state;
1979
+ }
1980
+ if (ctx.action === "manage") {
1981
+ const entries = await mapWithFixedConcurrency(state.entries, GITHUB_UPDATE_CHECK_CONCURRENCY, async (entry) => {
1982
+ if (entry.source.kind !== "github")
1983
+ return entry;
1984
+ const updateStatus = await checkGithubUpdate(entry.source);
1985
+ return {
1986
+ ...entry,
1987
+ last_update_check_at: updateStatus.checked_at,
1988
+ last_update_remote_commit: updateStatus.remote_commit,
1989
+ update_available: updateStatus.available,
1990
+ update_error: updateStatus.error,
1991
+ };
1992
+ });
1993
+ state = {
1994
+ ...state,
1995
+ updated_at: nowIso(),
1996
+ entries: sortManagedEntries(entries),
1997
+ };
1998
+ await writeManagedExtensionState(ctx.resolvedRoots.selected_root, state);
1999
+ }
2000
+ return { state, fix };
2001
+ };
2002
+ /** Runtime-probe explore by default and manage only when explicitly requested. */
2003
+ const probeExploreManageRuntime = async (ctx, settings, installed) => {
2004
+ const requested = [
2005
+ ctx.action === "explore",
2006
+ ctx.options.runtimeProbe === true,
2007
+ ].includes(true);
2008
+ if (!requested) {
2009
+ return {
2010
+ installed,
2011
+ failures: undefined,
2012
+ summary: { requested: false, executed: false },
2013
+ };
2014
+ }
2015
+ const loadResult = await loadExtensions({
2016
+ pmRoot: ctx.resolvedRoots.pm_root,
2017
+ settings,
2018
+ cwd: process.cwd(),
2019
+ noExtensions: ctx.global.noExtensions === true,
2020
+ });
2021
+ const activationResult = await activateExtensions({
2022
+ ...loadResult,
2023
+ loaded: loadResult.loaded,
2024
+ });
2025
+ ctx.warnings.push(...loadResult.warnings, ...activationResult.warnings);
2026
+ return {
2027
+ installed: applyDoctorRuntimeActivationState(installed, loadResult, activationResult),
2028
+ failures: collectActivationFailureDiagnostics(activationResult.failed),
2029
+ summary: {
2030
+ requested: true,
2031
+ executed: true,
2032
+ reason: ctx.action === "explore"
2033
+ ? "explore_defaults_to_runtime_probe"
2034
+ : "runtime_probe_requested",
2035
+ load_failure_count: loadResult.failed.length,
2036
+ activation_failure_count: activationResult.failed.length,
2037
+ warning_count: [
2038
+ ...new Set([...loadResult.warnings, ...activationResult.warnings]),
2039
+ ].length,
2040
+ policy: loadResult.policy,
2041
+ },
2042
+ };
2043
+ };
2044
+ /** Project manage-only adoption details without coupling them to runtime probing. */
2045
+ const projectExploreManageFix = (fix, installed) => fix
2046
+ ? {
2047
+ requested: true,
2048
+ applied: fix.adopted_entries.length > 0,
2049
+ adopted_count: fix.adopted_entries.length,
2050
+ adopted_extensions: fix.adopted_entries.map((entry) => entry.name),
2051
+ already_managed_count: fix.already_managed_count,
2052
+ }
2053
+ : {
2054
+ requested: false,
2055
+ applied: false,
2056
+ adopted_count: 0,
2057
+ adopted_extensions: [],
2058
+ already_managed_count: installed.filter((entry) => entry.managed)
2059
+ .length,
2060
+ };
2061
+ /** Explore installed extensions or mutate managed lifecycle state. */
2062
+ const runExtensionExploreManageAction = async (ctx) => {
2063
+ const { action, scope, resolvedRoots, warnings, options, withResult } = ctx;
2064
+ const settings = await readSettings(resolvedRoots.settings_root);
2065
+ const configuredPolicy = buildExtensionPolicyDetails(settings.extensions.policy);
2066
+ const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
2067
+ warnings.push(...managedStateRead.warnings);
2068
+ const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
2069
+ warnings.push(...installed.warnings);
2070
+ const { state: managedState, fix: managedStateFix } = await prepareExploreManageState(ctx, installed.extensions, managedStateRead.state);
2071
+ const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedState);
2072
+ warnings.push(...refreshedInstalled.warnings);
2073
+ if (action === "manage") {
2074
+ const updateWarnings = refreshedInstalled.extensions
2075
+ .filter((entry) => entry.update_check_status === "failed")
2076
+ .map((entry) => `extension_update_check_failed:${entry.name}`);
2077
+ warnings.push(...updateWarnings);
2078
+ }
2079
+ const runtimeProbe = await probeExploreManageRuntime(ctx, settings, refreshedInstalled.extensions);
2080
+ const runtimeInstalledExtensions = runtimeProbe.installed;
2081
+ const triage = buildExtensionTriageSummary(scope, warnings, runtimeInstalledExtensions, options);
2082
+ warnings.push(...triage.warnings);
2083
+ const details = {
2084
+ total: runtimeInstalledExtensions.length,
2085
+ managed_total: runtimeInstalledExtensions.filter((entry) => entry.managed)
2086
+ .length,
2087
+ enabled_total: runtimeInstalledExtensions.filter((entry) => entry.enabled)
2088
+ .length,
2089
+ active_total: runtimeInstalledExtensions.filter((entry) => entry.active)
2090
+ .length,
2091
+ extensions: runtimeInstalledExtensions,
2092
+ triage,
2093
+ policy: configuredPolicy,
2094
+ };
2095
+ if (runtimeProbe.failures !== undefined) {
2096
+ details.activation_diagnostics = {
2097
+ failed_count: runtimeProbe.failures.length,
2098
+ failed: runtimeProbe.failures,
2099
+ };
2100
+ }
2101
+ if (action === "explore") {
2102
+ details.runtime_probe = runtimeProbe.summary;
2103
+ }
2104
+ if (action === "manage") {
2105
+ details.runtime_probe = runtimeProbe.summary;
2106
+ details.managed_state_fix = projectExploreManageFix(managedStateFix, runtimeInstalledExtensions);
2107
+ }
2108
+ return withResult(details);
2109
+ };
2110
+ /* c8 ignore stop */
2111
+ // Dispatch table from lifecycle action to its handler. `explore`/`manage` and
2112
+ // `activate`/`deactivate` share a handler that branches on `ctx.action`; the
2113
+ // closed ExtensionCommandAction union guarantees every action has an entry, so
2114
+ // runExtension needs no unsupported-action fallthrough.
2115
+ const EXTENSION_ACTION_HANDLERS = {
2116
+ init: runExtensionInitAction,
2117
+ install: runExtensionInstallAction,
2118
+ uninstall: runExtensionUninstallAction,
2119
+ explore: runExtensionExploreManageAction,
2120
+ manage: runExtensionExploreManageAction,
2121
+ describe: runExtensionDescribeAction,
2122
+ reload: runExtensionReloadAction,
2123
+ doctor: runExtensionDoctorAction,
2124
+ catalog: runExtensionCatalogAction,
2125
+ adopt: runExtensionAdoptAction,
2126
+ "adopt-all": runExtensionAdoptAllAction,
2127
+ activate: runExtensionActivateDeactivateAction,
2128
+ deactivate: runExtensionActivateDeactivateAction,
2129
+ };
2130
+ /** Identify lifecycle actions that mutate shared settings or managed-extension state. */
2131
+ const requiresExtensionStateLock = (ctx) => [
2132
+ ctx.action === "uninstall",
2133
+ ctx.action === "manage",
2134
+ ctx.action === "adopt",
2135
+ ctx.action === "adopt-all",
2136
+ ctx.action === "activate",
2137
+ ctx.action === "deactivate",
2138
+ [ctx.action === "doctor", ctx.options.fixManagedState === true].every(Boolean),
2139
+ ].some(Boolean);
2140
+ /** Dispatch one normalized lifecycle action through the complete handler table. */
2141
+ const dispatchExtensionAction = (ctx) => requiresExtensionStateLock(ctx)
2142
+ ? withExtensionInstallLock(ctx.resolvedRoots.settings_root, `${ctx.action}-state`, () => EXTENSION_ACTION_HANDLERS[ctx.action](ctx))
2143
+ : EXTENSION_ACTION_HANDLERS[ctx.action](ctx);
2144
+ /** Public contract for test only, shared by SDK and presentation-layer consumers. */
2145
+ export const _testOnly = {
2146
+ adoptUnmanagedExtensions,
2147
+ buildAdoptedExtensionSource,
2148
+ buildExtensionPolicyDetails,
2149
+ buildInstallCommandDiscovery,
2150
+ checkGithubUpdate,
2151
+ clearExtensionState,
2152
+ collectActivationFailureDiagnostics,
2153
+ findActivationFailureByName,
2154
+ resolveInstallRuntimeActivationStatus,
2155
+ collectGlobalOutputOverrideDoctorWarnings,
2156
+ collectSchemaNarrowActivationDoctorWarnings,
2157
+ copyExtensionDirectoryWithoutSelfNesting,
2158
+ isErrnoCode,
2159
+ isRetriableExtensionInstallCopyError,
2160
+ listInstalledExtensions,
2161
+ mapWithFixedConcurrency,
2162
+ projectExtensionUpdateCheck,
2163
+ readOptionalMetadataFile,
2164
+ requireTarget,
2165
+ resolveAction,
2166
+ resolveCommandDiscoveryPackageName,
2167
+ resolveGithubOption,
2168
+ resolveInstalledExtensionCandidate,
2169
+ resolveScope,
2170
+ resolveUpdateCheckResolution,
2171
+ withExtensionInstallLock,
2172
+ };
2173
+ //# sourceMappingURL=extension.js.map
2174
+ //# debugId=fe21d8bd-795f-5bed-b4fc-e6efe6ee6120