@unbrained/pm-cli 2026.5.30 → 2026.6.5
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.
- package/CHANGELOG.md +152 -0
- package/dist/cli/argv-utils.js +7 -3
- package/dist/cli/argv-utils.js.map +1 -1
- package/dist/cli/bootstrap-args.d.ts +1 -0
- package/dist/cli/bootstrap-args.js +23 -3
- package/dist/cli/bootstrap-args.js.map +1 -1
- package/dist/cli/commands/calendar.js +96 -10
- package/dist/cli/commands/calendar.js.map +1 -1
- package/dist/cli/commands/close-many.d.ts +63 -0
- package/dist/cli/commands/close-many.js +302 -0
- package/dist/cli/commands/close-many.js.map +1 -0
- package/dist/cli/commands/completion.d.ts +1 -0
- package/dist/cli/commands/completion.js +241 -27
- package/dist/cli/commands/completion.js.map +1 -1
- package/dist/cli/commands/config.d.ts +4 -4
- package/dist/cli/commands/config.js +115 -3
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/contracts.js +191 -162
- package/dist/cli/commands/contracts.js.map +1 -1
- package/dist/cli/commands/create.d.ts +1 -0
- package/dist/cli/commands/create.js +109 -116
- package/dist/cli/commands/create.js.map +1 -1
- package/dist/cli/commands/extension/doctor.d.ts +12 -0
- package/dist/cli/commands/extension/doctor.js +97 -2
- package/dist/cli/commands/extension/doctor.js.map +1 -1
- package/dist/cli/commands/extension/install-sources.d.ts +2 -0
- package/dist/cli/commands/extension/install-sources.js +11 -4
- package/dist/cli/commands/extension/install-sources.js.map +1 -1
- package/dist/cli/commands/extension/scaffold.js +49 -48
- package/dist/cli/commands/extension/scaffold.js.map +1 -1
- package/dist/cli/commands/extension.js +51 -23
- package/dist/cli/commands/extension.js.map +1 -1
- package/dist/cli/commands/get.js +7 -7
- package/dist/cli/commands/get.js.map +1 -1
- package/dist/cli/commands/health.js +38 -3
- package/dist/cli/commands/health.js.map +1 -1
- package/dist/cli/commands/index.d.ts +2 -1
- package/dist/cli/commands/index.js +4 -3
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +10 -0
- package/dist/cli/commands/init.js +107 -4
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/list.d.ts +5 -0
- package/dist/cli/commands/list.js +58 -26
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/reindex.js +164 -48
- package/dist/cli/commands/reindex.js.map +1 -1
- package/dist/cli/commands/repeatable-metadata-parsers.d.ts +15 -0
- package/dist/cli/commands/repeatable-metadata-parsers.js +120 -0
- package/dist/cli/commands/repeatable-metadata-parsers.js.map +1 -0
- package/dist/cli/commands/restore.js +25 -4
- package/dist/cli/commands/restore.js.map +1 -1
- package/dist/cli/commands/schema.d.ts +122 -1
- package/dist/cli/commands/schema.js +536 -6
- package/dist/cli/commands/schema.js.map +1 -1
- package/dist/cli/commands/search.d.ts +18 -0
- package/dist/cli/commands/search.js +56 -12
- package/dist/cli/commands/search.js.map +1 -1
- package/dist/cli/commands/test.js +4 -3
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/commands/update-many.js +69 -140
- package/dist/cli/commands/update-many.js.map +1 -1
- package/dist/cli/commands/update.d.ts +2 -0
- package/dist/cli/commands/update.js +138 -119
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +1 -0
- package/dist/cli/commands/validate.js +63 -33
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/error-guidance.js +26 -3
- package/dist/cli/error-guidance.js.map +1 -1
- package/dist/cli/help-content.js +82 -3
- package/dist/cli/help-content.js.map +1 -1
- package/dist/cli/main.js +377 -23
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/register-list-query.js +16 -12
- package/dist/cli/register-list-query.js.map +1 -1
- package/dist/cli/register-mutation.js +217 -47
- package/dist/cli/register-mutation.js.map +1 -1
- package/dist/cli/register-operations.js +34 -25
- package/dist/cli/register-operations.js.map +1 -1
- package/dist/cli/register-setup.js +8 -8
- package/dist/cli/register-setup.js.map +1 -1
- package/dist/cli/registration-helpers.js +35 -5
- package/dist/cli/registration-helpers.js.map +1 -1
- package/dist/cli/search-refresh.d.ts +2 -0
- package/dist/cli/search-refresh.js +13 -0
- package/dist/cli/search-refresh.js.map +1 -0
- package/dist/cli-bundle/chunks/activity-3RWRRNOW.js +20 -0
- package/dist/cli-bundle/chunks/activity-3RWRRNOW.js.map +1 -0
- package/dist/cli-bundle/chunks/activity-P5BUMWP3.js +16 -0
- package/dist/cli-bundle/chunks/activity-P5BUMWP3.js.map +7 -0
- package/dist/cli-bundle/chunks/aggregate-J35K7WZB.js +206 -0
- package/dist/cli-bundle/chunks/aggregate-J35K7WZB.js.map +1 -0
- package/dist/cli-bundle/chunks/aggregate-OOAGKWRG.js +209 -0
- package/dist/cli-bundle/chunks/aggregate-OOAGKWRG.js.map +7 -0
- package/dist/cli-bundle/chunks/append-5JE3YGXU.js +72 -0
- package/dist/cli-bundle/chunks/append-5JE3YGXU.js.map +7 -0
- package/dist/cli-bundle/chunks/append-PNN6UIBZ.js +69 -0
- package/dist/cli-bundle/chunks/append-PNN6UIBZ.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-26KTVXJW.js +218 -0
- package/dist/cli-bundle/chunks/chunk-26KTVXJW.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-3HUE7XOF.js +27 -0
- package/dist/cli-bundle/chunks/chunk-3HUE7XOF.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-3OH4DAEB.js +761 -0
- package/dist/cli-bundle/chunks/chunk-3OH4DAEB.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-4LTBNUYT.js +5553 -0
- package/dist/cli-bundle/chunks/chunk-4LTBNUYT.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-4PJQSECJ.js +634 -0
- package/dist/cli-bundle/chunks/chunk-4PJQSECJ.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-4QCR4QW3.js +1832 -0
- package/dist/cli-bundle/chunks/chunk-4QCR4QW3.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-5IRA6IYD.js +1891 -0
- package/dist/cli-bundle/chunks/chunk-5IRA6IYD.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-5KB4X7YY.js +412 -0
- package/dist/cli-bundle/chunks/chunk-5KB4X7YY.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-5PAOPUZX.js +182 -0
- package/dist/cli-bundle/chunks/chunk-5PAOPUZX.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-7K24QB23.js +698 -0
- package/dist/cli-bundle/chunks/chunk-7K24QB23.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-A6PEXMYN.js +380 -0
- package/dist/cli-bundle/chunks/chunk-A6PEXMYN.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-ASQM3IF5.js +230 -0
- package/dist/cli-bundle/chunks/chunk-ASQM3IF5.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-ATBVS6WW.js +185 -0
- package/dist/cli-bundle/chunks/chunk-ATBVS6WW.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-AXXKLVTW.js +332 -0
- package/dist/cli-bundle/chunks/chunk-AXXKLVTW.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-B3N4TKNL.js +1681 -0
- package/dist/cli-bundle/chunks/chunk-B3N4TKNL.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-PB2YU2E3.js → chunk-BNL6S7QH.js} +28 -70
- package/dist/cli-bundle/chunks/chunk-BNL6S7QH.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-CCUFLH4J.js +154 -0
- package/dist/cli-bundle/chunks/chunk-CCUFLH4J.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-CJDQB2ED.js +341 -0
- package/dist/cli-bundle/chunks/chunk-CJDQB2ED.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-CWT53EYT.js +1340 -0
- package/dist/cli-bundle/chunks/chunk-CWT53EYT.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-D3WUNETC.js +349 -0
- package/dist/cli-bundle/chunks/chunk-D3WUNETC.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-D5X7N6FI.js +1714 -0
- package/dist/cli-bundle/chunks/chunk-D5X7N6FI.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-DFIZGAI5.js +550 -0
- package/dist/cli-bundle/chunks/chunk-DFIZGAI5.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-DFUSXJDE.js +1704 -0
- package/dist/cli-bundle/chunks/chunk-DFUSXJDE.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-EAOG77HM.js +56 -0
- package/dist/cli-bundle/chunks/chunk-EAOG77HM.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-EHXPIKKP.js +2988 -0
- package/dist/cli-bundle/chunks/chunk-EHXPIKKP.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-FVXM3GKS.js +128 -0
- package/dist/cli-bundle/chunks/chunk-FVXM3GKS.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-G5BACLYH.js +454 -0
- package/dist/cli-bundle/chunks/chunk-G5BACLYH.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-GCAVRLGE.js +383 -0
- package/dist/cli-bundle/chunks/chunk-GCAVRLGE.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-GFWHHMVV.js +57 -0
- package/dist/cli-bundle/chunks/chunk-GFWHHMVV.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-GNHVV4SY.js +3860 -0
- package/dist/cli-bundle/chunks/chunk-GNHVV4SY.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-GPGAYASV.js +346 -0
- package/dist/cli-bundle/chunks/chunk-GPGAYASV.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-HPH6X4ZZ.js +1356 -0
- package/dist/cli-bundle/chunks/chunk-HPH6X4ZZ.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-HZOS2UG5.js +342 -0
- package/dist/cli-bundle/chunks/chunk-HZOS2UG5.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-IUV734HF.js +17 -0
- package/dist/cli-bundle/chunks/chunk-IUV734HF.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-J27KIHTG.js +15 -0
- package/dist/cli-bundle/chunks/chunk-J27KIHTG.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-JB4RGL4V.js +185 -0
- package/dist/cli-bundle/chunks/chunk-JB4RGL4V.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-JQI2HE55.js +130 -0
- package/dist/cli-bundle/chunks/chunk-JQI2HE55.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-K47WAYQV.js +60 -0
- package/dist/cli-bundle/chunks/chunk-K47WAYQV.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-KA24HME7.js +79 -0
- package/dist/cli-bundle/chunks/chunk-KA24HME7.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-KBG47ZOY.js +1325 -0
- package/dist/cli-bundle/chunks/chunk-KBG47ZOY.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-KCMIYKTA.js +242 -0
- package/dist/cli-bundle/chunks/chunk-KCMIYKTA.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-KK6YPGH3.js +221 -0
- package/dist/cli-bundle/chunks/chunk-KK6YPGH3.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-LDJK7SHN.js +157 -0
- package/dist/cli-bundle/chunks/chunk-LDJK7SHN.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-LXYVKYMQ.js +24 -0
- package/dist/cli-bundle/chunks/chunk-LXYVKYMQ.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-MISYRLEP.js +80 -0
- package/dist/cli-bundle/chunks/chunk-MISYRLEP.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-N5YF3VFN.js +457 -0
- package/dist/cli-bundle/chunks/chunk-N5YF3VFN.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-NQP3ECKF.js +173 -0
- package/dist/cli-bundle/chunks/chunk-NQP3ECKF.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-O5IBJE6S.js +338 -0
- package/dist/cli-bundle/chunks/chunk-O5IBJE6S.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-O7IWB35H.js +18 -0
- package/dist/cli-bundle/chunks/chunk-O7IWB35H.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-OIQIXTNB.js +3040 -0
- package/dist/cli-bundle/chunks/chunk-OIQIXTNB.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-ORTLYVA4.js +751 -0
- package/dist/cli-bundle/chunks/chunk-ORTLYVA4.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-OUF3ARDX.js +1861 -0
- package/dist/cli-bundle/chunks/chunk-OUF3ARDX.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-QAJBIGRA.js +20 -0
- package/dist/cli-bundle/chunks/chunk-QAJBIGRA.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-RANZIID5.js +176 -0
- package/dist/cli-bundle/chunks/chunk-RANZIID5.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-RQAWLSUU.js +140 -0
- package/dist/cli-bundle/chunks/chunk-RQAWLSUU.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-S3CV7JGJ.js +233 -0
- package/dist/cli-bundle/chunks/chunk-S3CV7JGJ.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-SRVKTWPR.js +5705 -0
- package/dist/cli-bundle/chunks/chunk-SRVKTWPR.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-SSFMJCPF.js +76 -0
- package/dist/cli-bundle/chunks/chunk-SSFMJCPF.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-SZQCER6S.js +631 -0
- package/dist/cli-bundle/chunks/chunk-SZQCER6S.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-T2ORWB6D.js +540 -0
- package/dist/cli-bundle/chunks/chunk-T2ORWB6D.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-TBQVUNVH.js +422 -0
- package/dist/cli-bundle/chunks/chunk-TBQVUNVH.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-RJONRNXN.js → chunk-TK633IVD.js} +51 -32
- package/dist/cli-bundle/chunks/chunk-TK633IVD.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-TQ3ZK6VD.js +131 -0
- package/dist/cli-bundle/chunks/chunk-TQ3ZK6VD.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-UFCG3SWR.js +119 -0
- package/dist/cli-bundle/chunks/chunk-UFCG3SWR.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-UOVLWB47.js +1664 -0
- package/dist/cli-bundle/chunks/chunk-UOVLWB47.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-V3JQ4IPL.js +186 -0
- package/dist/cli-bundle/chunks/chunk-V3JQ4IPL.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-VGO2T3TY.js +182 -0
- package/dist/cli-bundle/chunks/chunk-VGO2T3TY.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-WIKR7KFL.js +189 -0
- package/dist/cli-bundle/chunks/chunk-WIKR7KFL.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-XG7RJYHV.js +1385 -0
- package/dist/cli-bundle/chunks/chunk-XG7RJYHV.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-XSLQSXAH.js +53 -0
- package/dist/cli-bundle/chunks/chunk-XSLQSXAH.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-XX5LRINW.js +90 -0
- package/dist/cli-bundle/chunks/chunk-XX5LRINW.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-Y2AKE2HS.js +252 -0
- package/dist/cli-bundle/chunks/chunk-Y2AKE2HS.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-ZQ4F6EC4.js +3898 -0
- package/dist/cli-bundle/chunks/chunk-ZQ4F6EC4.js.map +7 -0
- package/dist/cli-bundle/chunks/chunk-ZRVSMOMR.js +1809 -0
- package/dist/cli-bundle/chunks/chunk-ZRVSMOMR.js.map +1 -0
- package/dist/cli-bundle/chunks/claim-AZLP7YFO.js +132 -0
- package/dist/cli-bundle/chunks/claim-AZLP7YFO.js.map +7 -0
- package/dist/cli-bundle/chunks/claim-ZFA7HKU4.js +129 -0
- package/dist/cli-bundle/chunks/claim-ZFA7HKU4.js.map +1 -0
- package/dist/cli-bundle/chunks/close-65DFYAVS.js +17 -0
- package/dist/cli-bundle/chunks/close-65DFYAVS.js.map +1 -0
- package/dist/cli-bundle/chunks/close-RMHQ3KWH.js +13 -0
- package/dist/cli-bundle/chunks/close-RMHQ3KWH.js.map +7 -0
- package/dist/cli-bundle/chunks/close-many-AKPZNSGI.js +311 -0
- package/dist/cli-bundle/chunks/close-many-AKPZNSGI.js.map +1 -0
- package/dist/cli-bundle/chunks/close-many-UKZSQGM7.js +314 -0
- package/dist/cli-bundle/chunks/close-many-UKZSQGM7.js.map +7 -0
- package/dist/cli-bundle/chunks/comments-AGBNSJJH.js +103 -0
- package/dist/cli-bundle/chunks/comments-AGBNSJJH.js.map +7 -0
- package/dist/cli-bundle/chunks/comments-CJWXQI7X.js +100 -0
- package/dist/cli-bundle/chunks/comments-CJWXQI7X.js.map +1 -0
- package/dist/cli-bundle/chunks/config-5ON3ADRH.js +1688 -0
- package/dist/cli-bundle/chunks/config-5ON3ADRH.js.map +7 -0
- package/dist/cli-bundle/chunks/config-DDPYIA6J.js +1671 -0
- package/dist/cli-bundle/chunks/config-DDPYIA6J.js.map +1 -0
- package/dist/cli-bundle/chunks/context-E6U3DWVM.js +1471 -0
- package/dist/cli-bundle/chunks/context-E6U3DWVM.js.map +7 -0
- package/dist/cli-bundle/chunks/context-ZOJEN5VT.js +1461 -0
- package/dist/cli-bundle/chunks/context-ZOJEN5VT.js.map +1 -0
- package/dist/cli-bundle/chunks/contracts-CXSFM45B.js +1277 -0
- package/dist/cli-bundle/chunks/contracts-CXSFM45B.js.map +7 -0
- package/dist/cli-bundle/chunks/contracts-LCSX5R53.js +1274 -0
- package/dist/cli-bundle/chunks/contracts-LCSX5R53.js.map +1 -0
- package/dist/cli-bundle/chunks/create-ATONSAZW.js +27 -0
- package/dist/cli-bundle/chunks/create-ATONSAZW.js.map +7 -0
- package/dist/cli-bundle/chunks/create-WYFKN2U4.js +31 -0
- package/dist/cli-bundle/chunks/create-WYFKN2U4.js.map +1 -0
- package/dist/cli-bundle/chunks/delete-RONNH4F4.js +58 -0
- package/dist/cli-bundle/chunks/delete-RONNH4F4.js.map +7 -0
- package/dist/cli-bundle/chunks/delete-ZXWC56WO.js +55 -0
- package/dist/cli-bundle/chunks/delete-ZXWC56WO.js.map +1 -0
- package/dist/cli-bundle/chunks/deps-EHXIFOZR.js +225 -0
- package/dist/cli-bundle/chunks/deps-EHXIFOZR.js.map +1 -0
- package/dist/cli-bundle/chunks/deps-WII3O4HB.js +228 -0
- package/dist/cli-bundle/chunks/deps-WII3O4HB.js.map +7 -0
- package/dist/cli-bundle/chunks/docs-JMVCFNHH.js +34 -0
- package/dist/cli-bundle/chunks/docs-JMVCFNHH.js.map +7 -0
- package/dist/cli-bundle/chunks/docs-PDREIMLS.js +31 -0
- package/dist/cli-bundle/chunks/docs-PDREIMLS.js.map +1 -0
- package/dist/cli-bundle/chunks/extension-B4ROVWJD.js +28 -0
- package/dist/cli-bundle/chunks/extension-B4ROVWJD.js.map +1 -0
- package/dist/cli-bundle/chunks/extension-G6UXSM5S.js +24 -0
- package/dist/cli-bundle/chunks/extension-G6UXSM5S.js.map +7 -0
- package/dist/cli-bundle/chunks/files-2PN7UM2D.js +282 -0
- package/dist/cli-bundle/chunks/files-2PN7UM2D.js.map +1 -0
- package/dist/cli-bundle/chunks/files-MXYS5W4M.js +285 -0
- package/dist/cli-bundle/chunks/files-MXYS5W4M.js.map +7 -0
- package/dist/cli-bundle/chunks/gc-GT552UJH.js +178 -0
- package/dist/cli-bundle/chunks/gc-GT552UJH.js.map +1 -0
- package/dist/cli-bundle/chunks/gc-QNBRJG6H.js +181 -0
- package/dist/cli-bundle/chunks/gc-QNBRJG6H.js.map +7 -0
- package/dist/cli-bundle/chunks/get-CINFEUIY.js +197 -0
- package/dist/cli-bundle/chunks/get-CINFEUIY.js.map +7 -0
- package/dist/cli-bundle/chunks/get-WXMLRG7M.js +194 -0
- package/dist/cli-bundle/chunks/get-WXMLRG7M.js.map +1 -0
- package/dist/cli-bundle/chunks/health-5VPOJQ53.js +1258 -0
- package/dist/cli-bundle/chunks/health-5VPOJQ53.js.map +1 -0
- package/dist/cli-bundle/chunks/health-IT5DBPRJ.js +1261 -0
- package/dist/cli-bundle/chunks/health-IT5DBPRJ.js.map +7 -0
- package/dist/cli-bundle/chunks/history-6FC4H6HI.js +20 -0
- package/dist/cli-bundle/chunks/history-6FC4H6HI.js.map +7 -0
- package/dist/cli-bundle/chunks/history-FLZIP7PM.js +24 -0
- package/dist/cli-bundle/chunks/history-FLZIP7PM.js.map +1 -0
- package/dist/cli-bundle/chunks/history-redact-SSZBAD76.js +23 -0
- package/dist/cli-bundle/chunks/history-redact-SSZBAD76.js.map +1 -0
- package/dist/cli-bundle/chunks/history-redact-XKYEZDBL.js +19 -0
- package/dist/cli-bundle/chunks/history-redact-XKYEZDBL.js.map +7 -0
- package/dist/cli-bundle/chunks/history-repair-KC5ZOJRZ.js +196 -0
- package/dist/cli-bundle/chunks/history-repair-KC5ZOJRZ.js.map +7 -0
- package/dist/cli-bundle/chunks/history-repair-X7CO5JJZ.js +193 -0
- package/dist/cli-bundle/chunks/history-repair-X7CO5JJZ.js.map +1 -0
- package/dist/cli-bundle/chunks/init-6MRFVOLH.js +20 -0
- package/dist/cli-bundle/chunks/init-6MRFVOLH.js.map +1 -0
- package/dist/cli-bundle/chunks/init-KHX3FEEM.js +16 -0
- package/dist/cli-bundle/chunks/init-KHX3FEEM.js.map +7 -0
- package/dist/cli-bundle/chunks/learnings-A3CLB5CO.js +47 -0
- package/dist/cli-bundle/chunks/learnings-A3CLB5CO.js.map +7 -0
- package/dist/cli-bundle/chunks/learnings-DCX55BNX.js +44 -0
- package/dist/cli-bundle/chunks/learnings-DCX55BNX.js.map +1 -0
- package/dist/cli-bundle/chunks/list-53LZ2AEO.js +20 -0
- package/dist/cli-bundle/chunks/list-53LZ2AEO.js.map +7 -0
- package/dist/cli-bundle/chunks/list-DBRECOG4.js +24 -0
- package/dist/cli-bundle/chunks/list-DBRECOG4.js.map +1 -0
- package/dist/cli-bundle/chunks/notes-42LIC3UE.js +47 -0
- package/dist/cli-bundle/chunks/notes-42LIC3UE.js.map +7 -0
- package/dist/cli-bundle/chunks/notes-P5O3VMQ3.js +44 -0
- package/dist/cli-bundle/chunks/notes-P5O3VMQ3.js.map +1 -0
- package/dist/cli-bundle/chunks/plan-HDQXEUKD.js +1174 -0
- package/dist/cli-bundle/chunks/plan-HDQXEUKD.js.map +7 -0
- package/dist/cli-bundle/chunks/plan-IGTE3WOJ.js +1171 -0
- package/dist/cli-bundle/chunks/plan-IGTE3WOJ.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-list-query-EIVQ5FMR.js → register-list-query-AG3XKXWL.js} +25 -18
- package/dist/cli-bundle/chunks/register-list-query-AG3XKXWL.js.map +7 -0
- package/dist/cli-bundle/chunks/register-list-query-EMNSIUO4.js +227 -0
- package/dist/cli-bundle/chunks/register-list-query-EMNSIUO4.js.map +1 -0
- package/dist/cli-bundle/chunks/register-mutation-M3YS6XDO.js +813 -0
- package/dist/cli-bundle/chunks/register-mutation-M3YS6XDO.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-mutation-RSZNPSGI.js → register-mutation-RSMT6DPK.js} +160 -39
- package/dist/cli-bundle/chunks/register-mutation-RSMT6DPK.js.map +7 -0
- package/dist/cli-bundle/chunks/register-operations-KYUOOOOD.js +370 -0
- package/dist/cli-bundle/chunks/register-operations-KYUOOOOD.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-operations-APUSYDMR.js → register-operations-Q54JQZUN.js} +50 -32
- package/dist/cli-bundle/chunks/register-operations-Q54JQZUN.js.map +7 -0
- package/dist/cli-bundle/chunks/register-setup-DI6P7X75.js +242 -0
- package/dist/cli-bundle/chunks/register-setup-DI6P7X75.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-setup-OZOKSMPJ.js → register-setup-YJKIQRKA.js} +21 -13
- package/dist/cli-bundle/chunks/register-setup-YJKIQRKA.js.map +7 -0
- package/dist/cli-bundle/chunks/restore-2XVTBLKQ.js +21 -0
- package/dist/cli-bundle/chunks/restore-2XVTBLKQ.js.map +1 -0
- package/dist/cli-bundle/chunks/restore-JL5QIH7H.js +17 -0
- package/dist/cli-bundle/chunks/restore-JL5QIH7H.js.map +7 -0
- package/dist/cli-bundle/chunks/schema-LVXZWFGY.js +770 -0
- package/dist/cli-bundle/chunks/schema-LVXZWFGY.js.map +1 -0
- package/dist/cli-bundle/chunks/schema-V6BX65Q2.js +780 -0
- package/dist/cli-bundle/chunks/schema-V6BX65Q2.js.map +7 -0
- package/dist/cli-bundle/chunks/search-5A3BMFA7.js +1144 -0
- package/dist/cli-bundle/chunks/search-5A3BMFA7.js.map +7 -0
- package/dist/cli-bundle/chunks/search-C7NPB7G7.js +1127 -0
- package/dist/cli-bundle/chunks/search-C7NPB7G7.js.map +1 -0
- package/dist/cli-bundle/chunks/stats-FNLYVXTB.js +120 -0
- package/dist/cli-bundle/chunks/stats-FNLYVXTB.js.map +1 -0
- package/dist/cli-bundle/chunks/stats-Y2CBTZSL.js +123 -0
- package/dist/cli-bundle/chunks/stats-Y2CBTZSL.js.map +7 -0
- package/dist/cli-bundle/chunks/test-OFYONO3C.js +35 -0
- package/dist/cli-bundle/chunks/test-OFYONO3C.js.map +1 -0
- package/dist/cli-bundle/chunks/test-RJ4ZF35X.js +31 -0
- package/dist/cli-bundle/chunks/test-RJ4ZF35X.js.map +7 -0
- package/dist/cli-bundle/chunks/test-all-EEMKNTGU.js +331 -0
- package/dist/cli-bundle/chunks/test-all-EEMKNTGU.js.map +7 -0
- package/dist/cli-bundle/chunks/test-all-OJE6CIO7.js +328 -0
- package/dist/cli-bundle/chunks/test-all-OJE6CIO7.js.map +1 -0
- package/dist/cli-bundle/chunks/test-runs-IPOPFOAF.js +929 -0
- package/dist/cli-bundle/chunks/test-runs-IPOPFOAF.js.map +1 -0
- package/dist/cli-bundle/chunks/test-runs-L2M7WKH7.js +939 -0
- package/dist/cli-bundle/chunks/test-runs-L2M7WKH7.js.map +7 -0
- package/dist/cli-bundle/chunks/update-6YEHPVXH.js +25 -0
- package/dist/cli-bundle/chunks/update-6YEHPVXH.js.map +1 -0
- package/dist/cli-bundle/chunks/update-PYLVHMRD.js +21 -0
- package/dist/cli-bundle/chunks/update-PYLVHMRD.js.map +7 -0
- package/dist/cli-bundle/chunks/update-many-322CCH2L.js +608 -0
- package/dist/cli-bundle/chunks/update-many-322CCH2L.js.map +7 -0
- package/dist/cli-bundle/chunks/update-many-DYWGW57M.js +605 -0
- package/dist/cli-bundle/chunks/update-many-DYWGW57M.js.map +1 -0
- package/dist/cli-bundle/chunks/upgrade-2U727SAM.js +269 -0
- package/dist/cli-bundle/chunks/upgrade-2U727SAM.js.map +7 -0
- package/dist/cli-bundle/chunks/upgrade-3W3RVSNM.js +266 -0
- package/dist/cli-bundle/chunks/upgrade-3W3RVSNM.js.map +1 -0
- package/dist/cli-bundle/chunks/validate-GZ24NYHO.js +1120 -0
- package/dist/cli-bundle/chunks/validate-GZ24NYHO.js.map +1 -0
- package/dist/cli-bundle/chunks/validate-ZFVWPEEN.js +1123 -0
- package/dist/cli-bundle/chunks/validate-ZFVWPEEN.js.map +7 -0
- package/dist/cli-bundle/main.js +615 -121
- package/dist/cli-bundle/main.js.map +4 -4
- package/dist/core/checkpoint/mutation-checkpoint.d.ts +44 -0
- package/dist/core/checkpoint/mutation-checkpoint.js +119 -0
- package/dist/core/checkpoint/mutation-checkpoint.js.map +1 -0
- package/dist/core/config/positional-value.js +4 -2
- package/dist/core/config/positional-value.js.map +1 -1
- package/dist/core/diagnostics/remediation.d.ts +73 -0
- package/dist/core/diagnostics/remediation.js +328 -0
- package/dist/core/diagnostics/remediation.js.map +1 -0
- package/dist/core/extensions/extension-hook-runtime.js +9 -2
- package/dist/core/extensions/extension-hook-runtime.js.map +1 -1
- package/dist/core/extensions/extension-types.d.ts +60 -4
- package/dist/core/extensions/extension-types.js +2 -2
- package/dist/core/extensions/extension-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +5 -1
- package/dist/core/extensions/index.js +61 -2
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/item-fields.d.ts +5 -1
- package/dist/core/extensions/item-fields.js +126 -4
- package/dist/core/extensions/item-fields.js.map +1 -1
- package/dist/core/extensions/loader.js +283 -8
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/item/item-format.d.ts +3 -2
- package/dist/core/item/item-format.js +15 -10
- package/dist/core/item/item-format.js.map +1 -1
- package/dist/core/item/item-type-definition.js +6 -2
- package/dist/core/item/item-type-definition.js.map +1 -1
- package/dist/core/item/status-filter.d.ts +29 -0
- package/dist/core/item/status-filter.js +97 -0
- package/dist/core/item/status-filter.js.map +1 -0
- package/dist/core/item/type-registry.d.ts +4 -0
- package/dist/core/item/type-registry.js +12 -2
- package/dist/core/item/type-registry.js.map +1 -1
- package/dist/core/output/output.js +17 -5
- package/dist/core/output/output.js.map +1 -1
- package/dist/core/schema/item-types-file.d.ts +15 -0
- package/dist/core/schema/item-types-file.js +27 -2
- package/dist/core/schema/item-types-file.js.map +1 -1
- package/dist/core/schema/runtime-field-filters.js +4 -3
- package/dist/core/schema/runtime-field-filters.js.map +1 -1
- package/dist/core/schema/runtime-field-values.d.ts +1 -1
- package/dist/core/schema/runtime-field-values.js +10 -4
- package/dist/core/schema/runtime-field-values.js.map +1 -1
- package/dist/core/schema/runtime-schema.js +75 -2
- package/dist/core/schema/runtime-schema.js.map +1 -1
- package/dist/core/schema/status-defs-file.d.ts +113 -0
- package/dist/core/schema/status-defs-file.js +260 -0
- package/dist/core/schema/status-defs-file.js.map +1 -0
- package/dist/core/schema/type-workflows.d.ts +64 -0
- package/dist/core/schema/type-workflows.js +98 -0
- package/dist/core/schema/type-workflows.js.map +1 -0
- package/dist/core/search/background-refresh.d.ts +53 -0
- package/dist/core/search/background-refresh.js +286 -0
- package/dist/core/search/background-refresh.js.map +1 -0
- package/dist/core/search/cache.d.ts +23 -2
- package/dist/core/search/cache.js +135 -30
- package/dist/core/search/cache.js.map +1 -1
- package/dist/core/search/http-client.d.ts +2 -2
- package/dist/core/search/http-client.js +2 -2
- package/dist/core/search/http-client.js.map +1 -1
- package/dist/core/search/vector-stores.d.ts +1 -0
- package/dist/core/search/vector-stores.js +69 -15
- package/dist/core/search/vector-stores.js.map +1 -1
- package/dist/core/search/vectorization-metadata.d.ts +13 -0
- package/dist/core/search/vectorization-metadata.js +65 -0
- package/dist/core/search/vectorization-metadata.js.map +1 -0
- package/dist/core/shared/constants.d.ts +2 -2
- package/dist/core/shared/constants.js +2 -3
- package/dist/core/shared/constants.js.map +1 -1
- package/dist/core/shared/serialization.d.ts +1 -0
- package/dist/core/shared/serialization.js +86 -2
- package/dist/core/shared/serialization.js.map +1 -1
- package/dist/core/store/front-matter-cache.js +14 -5
- package/dist/core/store/front-matter-cache.js.map +1 -1
- package/dist/core/store/item-format-migration.js +25 -15
- package/dist/core/store/item-format-migration.js.map +1 -1
- package/dist/core/store/item-store.d.ts +2 -0
- package/dist/core/store/item-store.js +61 -6
- package/dist/core/store/item-store.js.map +1 -1
- package/dist/core/store/settings-validator.js +22 -2
- package/dist/core/store/settings-validator.js.map +1 -1
- package/dist/core/store/settings.js +40 -5
- package/dist/core/store/settings.js.map +1 -1
- package/dist/core/telemetry/consent.js +3 -3
- package/dist/core/telemetry/consent.js.map +1 -1
- package/dist/core/telemetry/observability.js +4 -3
- package/dist/core/telemetry/observability.js.map +1 -1
- package/dist/core/telemetry/runtime.d.ts +10 -0
- package/dist/core/telemetry/runtime.js +86 -2
- package/dist/core/telemetry/runtime.js.map +1 -1
- package/dist/mcp/server.js +221 -12
- package/dist/mcp/server.js.map +1 -1
- package/dist/sdk/cli-contracts/commander-mutation-options.js +16 -2
- package/dist/sdk/cli-contracts/commander-mutation-options.js.map +1 -1
- package/dist/sdk/cli-contracts/commander-types.js +7 -2
- package/dist/sdk/cli-contracts/commander-types.js.map +1 -1
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +2 -2
- package/dist/sdk/cli-contracts/enum-contracts.js +4 -2
- package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-option-contracts.d.ts +1 -0
- package/dist/sdk/cli-contracts/tool-option-contracts.js +53 -3
- package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +37 -8
- package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
- package/dist/sdk/cli-contracts.d.ts +19 -1
- package/dist/sdk/cli-contracts.js +211 -18
- package/dist/sdk/cli-contracts.js.map +1 -1
- package/dist/sdk/errors.d.ts +22 -0
- package/dist/sdk/errors.js +46 -0
- package/dist/sdk/errors.js.map +1 -0
- package/dist/sdk/index.d.ts +2 -1
- package/dist/sdk/index.js +3 -2
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/package-import-adapters.js +14 -3
- package/dist/sdk/package-import-adapters.js.map +1 -1
- package/dist/sdk/runtime.d.ts +1 -0
- package/dist/sdk/runtime.js +3 -2
- package/dist/sdk/runtime.js.map +1 -1
- package/dist/sdk/testing.d.ts +77 -0
- package/dist/sdk/testing.js +239 -0
- package/dist/sdk/testing.js.map +1 -0
- package/dist/types.d.ts +26 -1
- package/dist/types.js +3 -2
- package/dist/types.js.map +1 -1
- package/docs/AGENT_GUIDE.md +21 -2
- package/docs/COMMANDS.md +85 -5
- package/docs/CONFIGURATION.md +49 -2
- package/docs/EXTENSIONS.md +118 -6
- package/docs/QUICKSTART.md +2 -0
- package/docs/RELEASING.md +3 -3
- package/docs/SDK.md +273 -1
- package/docs/TESTING.md +17 -0
- package/docs/examples/policy-restricted-extension/manifest.json +1 -0
- package/docs/examples/starter-extension/index.js +9 -1
- package/docs/examples/starter-extension/manifest.json +1 -0
- package/package.json +12 -7
- package/packages/pm-beads/extensions/beads/index.js +2 -4
- package/packages/pm-beads/extensions/beads/index.ts +43 -33
- package/packages/pm-beads/extensions/beads/manifest.json +12 -1
- package/packages/pm-calendar/README.md +6 -0
- package/packages/pm-calendar/extensions/calendar/index.js +6 -1
- package/packages/pm-calendar/extensions/calendar/index.ts +6 -1
- package/packages/pm-calendar/extensions/calendar/manifest.json +6 -1
- package/packages/pm-governance-audit/extensions/governance-audit/manifest.json +6 -1
- package/packages/pm-guide-shell/README.md +4 -0
- package/packages/pm-guide-shell/extensions/guide-shell/index.js +22 -0
- package/packages/pm-guide-shell/extensions/guide-shell/index.ts +22 -0
- package/packages/pm-guide-shell/extensions/guide-shell/manifest.json +6 -1
- package/packages/pm-guide-shell/extensions/guide-shell/runtime.js +74 -3
- package/packages/pm-guide-shell/extensions/guide-shell/runtime.ts +84 -4
- package/packages/pm-lifecycle-hooks/README.md +29 -0
- package/packages/pm-lifecycle-hooks/extensions/lifecycle-hooks/index.js +18 -0
- package/packages/pm-lifecycle-hooks/extensions/lifecycle-hooks/index.ts +20 -0
- package/packages/pm-lifecycle-hooks/extensions/lifecycle-hooks/manifest.json +9 -0
- package/packages/pm-lifecycle-hooks/package.json +52 -0
- package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/manifest.json +13 -1
- package/packages/pm-search-advanced/extensions/search-advanced/index.js +69 -1
- package/packages/pm-search-advanced/extensions/search-advanced/index.ts +91 -2
- package/packages/pm-search-advanced/extensions/search-advanced/manifest.json +13 -1
- package/packages/pm-templates/extensions/templates/manifest.json +6 -1
- package/packages/pm-todos/extensions/todos/index.js +3 -7
- package/packages/pm-todos/extensions/todos/index.ts +55 -42
- package/packages/pm-todos/extensions/todos/manifest.json +13 -1
- package/scripts/bundle-cli.mjs +121 -17
- package/dist/cli-bundle/chunks/chunk-PB2YU2E3.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-RJONRNXN.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-SW5BMMCU.js +0 -13864
- package/dist/cli-bundle/chunks/chunk-SW5BMMCU.js.map +0 -7
- package/dist/cli-bundle/chunks/commands-XJ4TJ5UN.js +0 -24225
- package/dist/cli-bundle/chunks/commands-XJ4TJ5UN.js.map +0 -7
- package/dist/cli-bundle/chunks/register-list-query-EIVQ5FMR.js.map +0 -7
- package/dist/cli-bundle/chunks/register-mutation-RSZNPSGI.js.map +0 -7
- package/dist/cli-bundle/chunks/register-operations-APUSYDMR.js.map +0 -7
- package/dist/cli-bundle/chunks/register-setup-OZOKSMPJ.js.map +0 -7
|
@@ -0,0 +1,2988 @@
|
|
|
1
|
+
|
|
2
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e39bfbe4-484e-5544-affb-f1f6fbd63030")}catch(e){}}();
|
|
3
|
+
import {
|
|
4
|
+
splitCommaList
|
|
5
|
+
} from "./chunk-LXYVKYMQ.js";
|
|
6
|
+
import {
|
|
7
|
+
nowIso
|
|
8
|
+
} from "./chunk-NQP3ECKF.js";
|
|
9
|
+
import {
|
|
10
|
+
EXIT_CODE,
|
|
11
|
+
EXTENSION_CAPABILITY_CONTRACT,
|
|
12
|
+
KNOWN_EXTENSION_CAPABILITIES,
|
|
13
|
+
PmCliError,
|
|
14
|
+
activateExtensions,
|
|
15
|
+
isPathWithinDirectory,
|
|
16
|
+
loadExtensions,
|
|
17
|
+
nextExtensionReloadToken,
|
|
18
|
+
parseLegacyExtensionCapabilityAliasWarning,
|
|
19
|
+
parseUnknownExtensionCapabilityWarning,
|
|
20
|
+
pathExists,
|
|
21
|
+
readSettings,
|
|
22
|
+
resolveExtensionRoots,
|
|
23
|
+
resolveGlobalPmRoot,
|
|
24
|
+
resolvePmPackageRootFromModule,
|
|
25
|
+
resolvePmRoot,
|
|
26
|
+
writeSettings
|
|
27
|
+
} from "./chunk-4LTBNUYT.js";
|
|
28
|
+
|
|
29
|
+
// dist/cli/commands/extension.js
|
|
30
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
31
|
+
import fs7 from "node:fs/promises";
|
|
32
|
+
import os2 from "node:os";
|
|
33
|
+
import path7 from "node:path";
|
|
34
|
+
import { promisify as promisify2 } from "node:util";
|
|
35
|
+
|
|
36
|
+
// dist/cli/commands/extension/shared.js
|
|
37
|
+
import fs from "node:fs/promises";
|
|
38
|
+
import path from "node:path";
|
|
39
|
+
var DEFAULT_EXTENSION_PRIORITY = 100;
|
|
40
|
+
function normalizeStringList(values) {
|
|
41
|
+
return [...new Set(values.map((value) => value.trim()).filter((value) => value.length > 0))].sort((left, right) => left.localeCompare(right));
|
|
42
|
+
}
|
|
43
|
+
function normalizeExtensionNameForMatch(value) {
|
|
44
|
+
return value.trim().toLowerCase();
|
|
45
|
+
}
|
|
46
|
+
function normalizeManagedDirectoryName(name) {
|
|
47
|
+
const normalized = name.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
48
|
+
if (normalized.length === 0) {
|
|
49
|
+
throw new PmCliError("Extension manifest name must resolve to a non-empty directory name.", EXIT_CODE.USAGE);
|
|
50
|
+
}
|
|
51
|
+
if (normalized === "." || normalized === "..") {
|
|
52
|
+
throw new PmCliError('Extension manifest name must not resolve to "." or "..".', EXIT_CODE.USAGE);
|
|
53
|
+
}
|
|
54
|
+
return normalized;
|
|
55
|
+
}
|
|
56
|
+
function parseExtensionManifest(raw) {
|
|
57
|
+
if (typeof raw !== "object" || raw === null) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const candidate = raw;
|
|
61
|
+
if (typeof candidate.name !== "string" || candidate.name.trim().length === 0) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (typeof candidate.version !== "string" || candidate.version.trim().length === 0) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (typeof candidate.entry !== "string" || candidate.entry.trim().length === 0) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
let priority = DEFAULT_EXTENSION_PRIORITY;
|
|
71
|
+
if (candidate.priority !== void 0 && candidate.priority !== null) {
|
|
72
|
+
if (typeof candidate.priority !== "number" || !Number.isInteger(candidate.priority)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
priority = candidate.priority;
|
|
76
|
+
}
|
|
77
|
+
let capabilities = [];
|
|
78
|
+
if (candidate.capabilities !== void 0 && candidate.capabilities !== null) {
|
|
79
|
+
if (!Array.isArray(candidate.capabilities) || candidate.capabilities.some((value) => typeof value !== "string")) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
capabilities = normalizeStringList(candidate.capabilities.map((value) => String(value).toLowerCase()));
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
name: candidate.name.trim(),
|
|
86
|
+
version: candidate.version.trim(),
|
|
87
|
+
entry: candidate.entry.trim(),
|
|
88
|
+
priority,
|
|
89
|
+
capabilities
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function isCanonicalPathWithinDirectory(directory, targetPath) {
|
|
93
|
+
const [resolvedDirectory, resolvedTargetPath] = await Promise.all([fs.realpath(directory), fs.realpath(targetPath)]);
|
|
94
|
+
return isPathWithinDirectory(resolvedDirectory, resolvedTargetPath);
|
|
95
|
+
}
|
|
96
|
+
async function validateExtensionDirectory(directory) {
|
|
97
|
+
const manifestPath = path.join(directory, "manifest.json");
|
|
98
|
+
if (!await pathExists(manifestPath)) {
|
|
99
|
+
throw new PmCliError(`Extension manifest is missing at "${manifestPath}".`, EXIT_CODE.USAGE);
|
|
100
|
+
}
|
|
101
|
+
let parsedManifest;
|
|
102
|
+
try {
|
|
103
|
+
parsedManifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
|
|
104
|
+
} catch (error) {
|
|
105
|
+
throw new PmCliError(`Failed to parse extension manifest at "${manifestPath}": ${error instanceof Error ? error.message : String(error)}`, EXIT_CODE.USAGE);
|
|
106
|
+
}
|
|
107
|
+
const manifest = parseExtensionManifest(parsedManifest);
|
|
108
|
+
if (!manifest) {
|
|
109
|
+
throw new PmCliError(`Extension manifest at "${manifestPath}" is invalid.`, EXIT_CODE.USAGE);
|
|
110
|
+
}
|
|
111
|
+
const entryPath = path.resolve(directory, manifest.entry);
|
|
112
|
+
if (!isPathWithinDirectory(directory, entryPath)) {
|
|
113
|
+
throw new PmCliError(`Extension entry "${manifest.entry}" resolves outside extension directory "${directory}".`, EXIT_CODE.USAGE);
|
|
114
|
+
}
|
|
115
|
+
if (!await pathExists(entryPath)) {
|
|
116
|
+
throw new PmCliError(`Extension entry file is missing at "${entryPath}".`, EXIT_CODE.USAGE);
|
|
117
|
+
}
|
|
118
|
+
if (!await isCanonicalPathWithinDirectory(directory, entryPath)) {
|
|
119
|
+
throw new PmCliError(`Extension entry "${manifest.entry}" resolves outside extension directory after symlink resolution.`, EXIT_CODE.USAGE);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
directory,
|
|
123
|
+
manifest_path: manifestPath,
|
|
124
|
+
entry_path: entryPath,
|
|
125
|
+
manifest
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// dist/cli/commands/extension/managed-state.js
|
|
130
|
+
import fs2 from "node:fs/promises";
|
|
131
|
+
import path2 from "node:path";
|
|
132
|
+
var MANAGED_EXTENSION_STATE_FILENAME = ".managed-extensions.json";
|
|
133
|
+
var MANAGED_EXTENSION_STATE_VERSION = 1;
|
|
134
|
+
function resolveManagedExtensionStatePath(extensionsRoot) {
|
|
135
|
+
return path2.join(extensionsRoot, MANAGED_EXTENSION_STATE_FILENAME);
|
|
136
|
+
}
|
|
137
|
+
function createEmptyManagedExtensionState() {
|
|
138
|
+
return {
|
|
139
|
+
version: MANAGED_EXTENSION_STATE_VERSION,
|
|
140
|
+
updated_at: nowIso(),
|
|
141
|
+
entries: []
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function sortManagedEntries(entries) {
|
|
145
|
+
return [...entries].sort((left, right) => {
|
|
146
|
+
const byScope = left.scope.localeCompare(right.scope);
|
|
147
|
+
if (byScope !== 0) {
|
|
148
|
+
return byScope;
|
|
149
|
+
}
|
|
150
|
+
const byName = left.name.localeCompare(right.name);
|
|
151
|
+
if (byName !== 0) {
|
|
152
|
+
return byName;
|
|
153
|
+
}
|
|
154
|
+
return left.directory.localeCompare(right.directory);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function managedExtensionSourcesEquivalent(left, right) {
|
|
158
|
+
if (left.kind !== right.kind || left.input !== right.input || left.location !== right.location) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
if (left.kind === "npm" && right.kind === "npm") {
|
|
162
|
+
return left.package === right.package && left.version === right.version;
|
|
163
|
+
}
|
|
164
|
+
if (left.kind === "github" && right.kind === "github") {
|
|
165
|
+
return left.repository === right.repository && left.ref === right.ref && left.subpath === right.subpath && left.commit === right.commit;
|
|
166
|
+
}
|
|
167
|
+
if (left.kind === "builtin" && right.kind === "builtin") {
|
|
168
|
+
return left.name === right.name;
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
function normalizeManagedState(raw) {
|
|
173
|
+
if (typeof raw !== "object" || raw === null) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const candidate = raw;
|
|
177
|
+
if (candidate.version !== MANAGED_EXTENSION_STATE_VERSION || !Array.isArray(candidate.entries)) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const entries = [];
|
|
181
|
+
for (const rawEntry of candidate.entries) {
|
|
182
|
+
if (typeof rawEntry !== "object" || rawEntry === null) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const entry = rawEntry;
|
|
186
|
+
if (typeof entry.name !== "string" || entry.name.trim().length === 0 || typeof entry.directory !== "string" || entry.directory.trim().length === 0 || entry.scope !== "project" && entry.scope !== "global" || typeof entry.manifest_version !== "string" || typeof entry.manifest_entry !== "string" || !Array.isArray(entry.capabilities) || entry.capabilities.some((value) => typeof value !== "string") || typeof entry.installed_at !== "string" || typeof entry.updated_at !== "string" || typeof entry.source !== "object" || entry.source === null) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const source = entry.source;
|
|
190
|
+
if (source.kind !== "local" && source.kind !== "github" && source.kind !== "npm" && source.kind !== "builtin" || typeof source.input !== "string" || typeof source.location !== "string") {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
entries.push({
|
|
194
|
+
name: entry.name.trim(),
|
|
195
|
+
directory: entry.directory.trim(),
|
|
196
|
+
scope: entry.scope,
|
|
197
|
+
manifest_version: entry.manifest_version,
|
|
198
|
+
manifest_entry: entry.manifest_entry,
|
|
199
|
+
capabilities: normalizeStringList(entry.capabilities),
|
|
200
|
+
installed_at: entry.installed_at,
|
|
201
|
+
updated_at: entry.updated_at,
|
|
202
|
+
source: {
|
|
203
|
+
kind: source.kind,
|
|
204
|
+
input: source.input,
|
|
205
|
+
location: source.location,
|
|
206
|
+
name: typeof source.name === "string" ? source.name : void 0,
|
|
207
|
+
package: typeof source.package === "string" ? source.package : void 0,
|
|
208
|
+
version: typeof source.version === "string" ? source.version : void 0,
|
|
209
|
+
repository: typeof source.repository === "string" ? source.repository : void 0,
|
|
210
|
+
owner: typeof source.owner === "string" ? source.owner : void 0,
|
|
211
|
+
repo: typeof source.repo === "string" ? source.repo : void 0,
|
|
212
|
+
ref: typeof source.ref === "string" ? source.ref : void 0,
|
|
213
|
+
subpath: typeof source.subpath === "string" ? source.subpath : void 0,
|
|
214
|
+
commit: typeof source.commit === "string" ? source.commit : void 0
|
|
215
|
+
},
|
|
216
|
+
last_update_check_at: typeof entry.last_update_check_at === "string" ? entry.last_update_check_at : void 0,
|
|
217
|
+
last_update_remote_commit: typeof entry.last_update_remote_commit === "string" ? entry.last_update_remote_commit : void 0,
|
|
218
|
+
update_available: typeof entry.update_available === "boolean" || entry.update_available === null ? entry.update_available : void 0,
|
|
219
|
+
update_error: typeof entry.update_error === "string" ? entry.update_error : void 0
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
version: MANAGED_EXTENSION_STATE_VERSION,
|
|
224
|
+
updated_at: typeof candidate.updated_at === "string" ? candidate.updated_at : nowIso(),
|
|
225
|
+
entries: sortManagedEntries(entries)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
async function readManagedExtensionState(extensionsRoot) {
|
|
229
|
+
const statePath = resolveManagedExtensionStatePath(extensionsRoot);
|
|
230
|
+
const fallback = createEmptyManagedExtensionState();
|
|
231
|
+
try {
|
|
232
|
+
const raw = await fs2.readFile(statePath, "utf8");
|
|
233
|
+
const parsed = JSON.parse(raw);
|
|
234
|
+
const normalized = normalizeManagedState(parsed);
|
|
235
|
+
if (!normalized) {
|
|
236
|
+
throw new PmCliError(`Managed extension state file "${statePath}" has an invalid schema. Repair or remove it before mutating extension state.`, EXIT_CODE.GENERIC_FAILURE);
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
path: statePath,
|
|
240
|
+
state: normalized,
|
|
241
|
+
warnings: []
|
|
242
|
+
};
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (error instanceof PmCliError) {
|
|
245
|
+
throw error;
|
|
246
|
+
}
|
|
247
|
+
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
|
|
248
|
+
return {
|
|
249
|
+
path: statePath,
|
|
250
|
+
state: fallback,
|
|
251
|
+
warnings: []
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
throw new PmCliError(`Managed extension state file "${statePath}" could not be read. Repair or remove it before mutating extension state.`, EXIT_CODE.GENERIC_FAILURE);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async function writeManagedExtensionState(extensionsRoot, state) {
|
|
258
|
+
const statePath = resolveManagedExtensionStatePath(extensionsRoot);
|
|
259
|
+
const normalized = {
|
|
260
|
+
version: MANAGED_EXTENSION_STATE_VERSION,
|
|
261
|
+
updated_at: nowIso(),
|
|
262
|
+
entries: sortManagedEntries(state.entries)
|
|
263
|
+
};
|
|
264
|
+
await fs2.mkdir(extensionsRoot, { recursive: true });
|
|
265
|
+
await fs2.writeFile(statePath, `${JSON.stringify(normalized, null, 2)}
|
|
266
|
+
`, "utf8");
|
|
267
|
+
}
|
|
268
|
+
function upsertManagedEntry(state, entry) {
|
|
269
|
+
const updatedEntries = state.entries.filter((candidate) => normalizeExtensionNameForMatch(candidate.name) !== normalizeExtensionNameForMatch(entry.name) && normalizeExtensionNameForMatch(candidate.directory) !== normalizeExtensionNameForMatch(entry.directory));
|
|
270
|
+
updatedEntries.push(entry);
|
|
271
|
+
return {
|
|
272
|
+
...state,
|
|
273
|
+
updated_at: nowIso(),
|
|
274
|
+
entries: sortManagedEntries(updatedEntries)
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// dist/cli/commands/extension/install-sources.js
|
|
279
|
+
import { execFile } from "node:child_process";
|
|
280
|
+
import fs4 from "node:fs/promises";
|
|
281
|
+
import os from "node:os";
|
|
282
|
+
import path4 from "node:path";
|
|
283
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
284
|
+
import { promisify } from "node:util";
|
|
285
|
+
|
|
286
|
+
// dist/core/packages/manifest.js
|
|
287
|
+
import fs3 from "node:fs/promises";
|
|
288
|
+
import path3 from "node:path";
|
|
289
|
+
var PM_PACKAGE_RESOURCE_KINDS = [
|
|
290
|
+
"extensions",
|
|
291
|
+
"docs",
|
|
292
|
+
"examples"
|
|
293
|
+
];
|
|
294
|
+
var PM_PACKAGE_CONVENTIONAL_RESOURCE_ROOTS = Object.freeze({
|
|
295
|
+
extensions: Object.freeze([
|
|
296
|
+
".agents/pm/extensions",
|
|
297
|
+
"extensions",
|
|
298
|
+
".custom/pm-extensions",
|
|
299
|
+
".custom/pm-extension"
|
|
300
|
+
]),
|
|
301
|
+
docs: Object.freeze([
|
|
302
|
+
"docs",
|
|
303
|
+
"documentation"
|
|
304
|
+
]),
|
|
305
|
+
examples: Object.freeze([
|
|
306
|
+
"examples",
|
|
307
|
+
"docs/examples"
|
|
308
|
+
])
|
|
309
|
+
});
|
|
310
|
+
function isKnownPackageResourceKind(value) {
|
|
311
|
+
return PM_PACKAGE_RESOURCE_KINDS.includes(value);
|
|
312
|
+
}
|
|
313
|
+
function normalizePackageResourceEntries(kind, raw) {
|
|
314
|
+
if (raw === void 0 || raw === null) {
|
|
315
|
+
return [];
|
|
316
|
+
}
|
|
317
|
+
const entries = Array.isArray(raw) ? raw : [raw];
|
|
318
|
+
const normalized = [];
|
|
319
|
+
for (const entry of entries) {
|
|
320
|
+
if (typeof entry !== "string" || entry.trim().length === 0) {
|
|
321
|
+
throw new PmCliError(`Package manifest field pm.${kind} must contain string paths.`, EXIT_CODE.USAGE);
|
|
322
|
+
}
|
|
323
|
+
normalized.push(entry.trim());
|
|
324
|
+
}
|
|
325
|
+
return [...new Set(normalized)].sort((left, right) => left.localeCompare(right));
|
|
326
|
+
}
|
|
327
|
+
function normalizePackageResourceMap(raw) {
|
|
328
|
+
if (raw === void 0 || raw === null) {
|
|
329
|
+
return {};
|
|
330
|
+
}
|
|
331
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
332
|
+
throw new PmCliError("Package manifest field pm must be an object.", EXIT_CODE.USAGE);
|
|
333
|
+
}
|
|
334
|
+
const resources = {};
|
|
335
|
+
const candidate = raw;
|
|
336
|
+
for (const [key, value] of Object.entries(candidate)) {
|
|
337
|
+
if (!isKnownPackageResourceKind(key)) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
const entries = normalizePackageResourceEntries(key, value);
|
|
341
|
+
if (entries.length > 0) {
|
|
342
|
+
resources[key] = entries;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return resources;
|
|
346
|
+
}
|
|
347
|
+
function readStringField(source, key) {
|
|
348
|
+
const value = source[key];
|
|
349
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
350
|
+
}
|
|
351
|
+
function normalizeStringArray(raw) {
|
|
352
|
+
if (!Array.isArray(raw)) {
|
|
353
|
+
return void 0;
|
|
354
|
+
}
|
|
355
|
+
const values = raw.map((value) => typeof value === "string" ? value.trim() : "").filter((value) => value.length > 0);
|
|
356
|
+
return values.length > 0 ? [...new Set(values)].sort((left, right) => left.localeCompare(right)) : void 0;
|
|
357
|
+
}
|
|
358
|
+
function readUrlLikeField(raw) {
|
|
359
|
+
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
360
|
+
return raw.trim();
|
|
361
|
+
}
|
|
362
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw)) {
|
|
363
|
+
const value = raw.url;
|
|
364
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
365
|
+
}
|
|
366
|
+
return void 0;
|
|
367
|
+
}
|
|
368
|
+
function normalizeCatalogLinks(raw) {
|
|
369
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
370
|
+
return void 0;
|
|
371
|
+
}
|
|
372
|
+
const source = raw;
|
|
373
|
+
const links = {
|
|
374
|
+
docs: readStringField(source, "docs"),
|
|
375
|
+
npm: readStringField(source, "npm"),
|
|
376
|
+
repository: readStringField(source, "repository"),
|
|
377
|
+
report: readStringField(source, "report")
|
|
378
|
+
};
|
|
379
|
+
return Object.values(links).some((value) => typeof value === "string") ? links : void 0;
|
|
380
|
+
}
|
|
381
|
+
function normalizeCatalogMedia(raw) {
|
|
382
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
383
|
+
return void 0;
|
|
384
|
+
}
|
|
385
|
+
const source = raw;
|
|
386
|
+
const media = {
|
|
387
|
+
image: readStringField(source, "image"),
|
|
388
|
+
video: readStringField(source, "video")
|
|
389
|
+
};
|
|
390
|
+
return Object.values(media).some((value) => typeof value === "string") ? media : void 0;
|
|
391
|
+
}
|
|
392
|
+
function normalizePackageCatalogMetadata(raw) {
|
|
393
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
394
|
+
return void 0;
|
|
395
|
+
}
|
|
396
|
+
const source = raw;
|
|
397
|
+
const catalog = {
|
|
398
|
+
display_name: readStringField(source, "display_name") ?? readStringField(source, "displayName"),
|
|
399
|
+
category: readStringField(source, "category"),
|
|
400
|
+
summary: readStringField(source, "summary"),
|
|
401
|
+
links: normalizeCatalogLinks(source.links),
|
|
402
|
+
media: normalizeCatalogMedia(source.media),
|
|
403
|
+
tags: normalizeStringArray(source.tags)
|
|
404
|
+
};
|
|
405
|
+
return Object.values(catalog).some((value) => value !== void 0) ? catalog : void 0;
|
|
406
|
+
}
|
|
407
|
+
async function readPmPackageManifest(packageRoot) {
|
|
408
|
+
const packageJsonPath = path3.join(packageRoot, "package.json");
|
|
409
|
+
if (!await pathExists(packageJsonPath)) {
|
|
410
|
+
return {
|
|
411
|
+
source: "convention",
|
|
412
|
+
resources: {}
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
let parsed;
|
|
416
|
+
try {
|
|
417
|
+
parsed = JSON.parse(await fs3.readFile(packageJsonPath, "utf8"));
|
|
418
|
+
} catch (error) {
|
|
419
|
+
throw new PmCliError(`Failed to parse package manifest at "${packageJsonPath}": ${String(error)}`, EXIT_CODE.USAGE);
|
|
420
|
+
}
|
|
421
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
422
|
+
throw new PmCliError(`Package manifest at "${packageJsonPath}" must be a JSON object.`, EXIT_CODE.USAGE);
|
|
423
|
+
}
|
|
424
|
+
const packageJson = parsed;
|
|
425
|
+
const pmManifest = packageJson.pm;
|
|
426
|
+
const hasPmManifest = pmManifest !== void 0 && pmManifest !== null;
|
|
427
|
+
const pmManifestRecord = typeof pmManifest === "object" && pmManifest !== null && !Array.isArray(pmManifest) ? pmManifest : {};
|
|
428
|
+
return {
|
|
429
|
+
source: hasPmManifest ? "pm" : "convention",
|
|
430
|
+
package_json_path: packageJsonPath,
|
|
431
|
+
package_name: typeof packageJson.name === "string" ? packageJson.name : void 0,
|
|
432
|
+
package_version: typeof packageJson.version === "string" ? packageJson.version : void 0,
|
|
433
|
+
package_private: packageJson.private === true,
|
|
434
|
+
package_description: typeof packageJson.description === "string" ? packageJson.description : void 0,
|
|
435
|
+
package_keywords: normalizeStringArray(packageJson.keywords),
|
|
436
|
+
package_homepage: typeof packageJson.homepage === "string" ? packageJson.homepage : void 0,
|
|
437
|
+
package_repository_url: readUrlLikeField(packageJson.repository),
|
|
438
|
+
package_bugs_url: readUrlLikeField(packageJson.bugs),
|
|
439
|
+
aliases: normalizeStringArray(pmManifestRecord.aliases),
|
|
440
|
+
resources: normalizePackageResourceMap(pmManifest),
|
|
441
|
+
catalog: normalizePackageCatalogMetadata(pmManifestRecord.catalog)
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
async function listExtensionManifestDirectories(parentDirectory) {
|
|
445
|
+
if (!await pathExists(parentDirectory)) {
|
|
446
|
+
return [];
|
|
447
|
+
}
|
|
448
|
+
const entries = await fs3.readdir(parentDirectory, { withFileTypes: true });
|
|
449
|
+
const candidates = [];
|
|
450
|
+
for (const entry of entries) {
|
|
451
|
+
if (!entry.isDirectory()) {
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const directory = path3.join(parentDirectory, entry.name);
|
|
455
|
+
if (await pathExists(path3.join(directory, "manifest.json"))) {
|
|
456
|
+
candidates.push(directory);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return candidates.sort((left, right) => left.localeCompare(right));
|
|
460
|
+
}
|
|
461
|
+
async function collectPackageExtensionDirectories(packageRoot) {
|
|
462
|
+
if (await pathExists(path3.join(packageRoot, "manifest.json"))) {
|
|
463
|
+
return [packageRoot];
|
|
464
|
+
}
|
|
465
|
+
const manifest = await readPmPackageManifest(packageRoot);
|
|
466
|
+
const manifestEntries = manifest.resources.extensions ?? [];
|
|
467
|
+
const discovered = /* @__PURE__ */ new Set();
|
|
468
|
+
for (const entry of manifestEntries) {
|
|
469
|
+
if (entry.includes("*") || entry.startsWith("!")) {
|
|
470
|
+
throw new PmCliError(`Package extension entry "${entry}" uses a glob/exclusion pattern. pm package installs currently require concrete extension paths or directories.`, EXIT_CODE.USAGE);
|
|
471
|
+
}
|
|
472
|
+
const absolute = path3.resolve(packageRoot, entry);
|
|
473
|
+
if (!isPathWithinDirectory(packageRoot, absolute)) {
|
|
474
|
+
throw new PmCliError(`Package extension entry "${entry}" resolves outside package root.`, EXIT_CODE.USAGE);
|
|
475
|
+
}
|
|
476
|
+
if (await pathExists(path3.join(absolute, "manifest.json"))) {
|
|
477
|
+
discovered.add(absolute);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
for (const child of await listExtensionManifestDirectories(absolute)) {
|
|
481
|
+
discovered.add(child);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (manifestEntries.length === 0) {
|
|
485
|
+
for (const root of PM_PACKAGE_CONVENTIONAL_RESOURCE_ROOTS.extensions) {
|
|
486
|
+
for (const child of await listExtensionManifestDirectories(path3.join(packageRoot, root))) {
|
|
487
|
+
discovered.add(child);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return [...discovered].sort((left, right) => left.localeCompare(right));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// dist/cli/commands/extension/install-sources.js
|
|
495
|
+
var execFileAsync = promisify(execFile);
|
|
496
|
+
function parseGithubPathSpec(pathSpec, input, refOverride) {
|
|
497
|
+
const segments = pathSpec.split("/").map((segment) => segment.trim()).filter((segment) => segment.length > 0);
|
|
498
|
+
if (segments.length < 2) {
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
const owner = segments[0];
|
|
502
|
+
const repo = segments[1].replace(/\.git$/i, "");
|
|
503
|
+
if (owner.length === 0 || repo.length === 0) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
const tail = segments.slice(2);
|
|
507
|
+
let ref;
|
|
508
|
+
let subpath;
|
|
509
|
+
if (tail[0] === "tree" && tail.length >= 2) {
|
|
510
|
+
ref = tail[1];
|
|
511
|
+
subpath = tail.slice(2).join("/");
|
|
512
|
+
} else if (tail.length > 0) {
|
|
513
|
+
subpath = tail.join("/");
|
|
514
|
+
}
|
|
515
|
+
if (typeof refOverride === "string" && refOverride.trim().length > 0) {
|
|
516
|
+
ref = refOverride.trim();
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
kind: "github",
|
|
520
|
+
input,
|
|
521
|
+
owner,
|
|
522
|
+
repo,
|
|
523
|
+
repository: `https://github.com/${owner}/${repo}.git`,
|
|
524
|
+
ref,
|
|
525
|
+
subpath: subpath && subpath.length > 0 ? subpath : void 0
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function parseExtensionInstallSource(input, options = {}) {
|
|
529
|
+
const normalizedInput = input.trim();
|
|
530
|
+
if (normalizedInput.length === 0) {
|
|
531
|
+
throw new PmCliError("Extension source is required for --install.", EXIT_CODE.USAGE);
|
|
532
|
+
}
|
|
533
|
+
const refOverride = typeof options.ref === "string" && options.ref.trim().length > 0 ? options.ref.trim() : void 0;
|
|
534
|
+
if (normalizedInput.startsWith("npm:")) {
|
|
535
|
+
const spec = normalizedInput.slice("npm:".length).trim();
|
|
536
|
+
if (spec.length === 0) {
|
|
537
|
+
throw new PmCliError('npm package source must include a package spec after "npm:".', EXIT_CODE.USAGE);
|
|
538
|
+
}
|
|
539
|
+
if (options.forceGithub) {
|
|
540
|
+
throw new PmCliError('Options "--gh/--github" cannot be combined with npm: package sources.', EXIT_CODE.USAGE);
|
|
541
|
+
}
|
|
542
|
+
if (refOverride) {
|
|
543
|
+
throw new PmCliError('Option "--ref" cannot be combined with npm: package sources.', EXIT_CODE.USAGE);
|
|
544
|
+
}
|
|
545
|
+
return {
|
|
546
|
+
kind: "npm",
|
|
547
|
+
input: normalizedInput,
|
|
548
|
+
spec
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
const maybeGithubByUrl = (() => {
|
|
552
|
+
try {
|
|
553
|
+
const parsed = new URL(normalizedInput);
|
|
554
|
+
if (parsed.hostname !== "github.com") {
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
const pathSpec = parsed.pathname.replace(/^\/+/, "");
|
|
558
|
+
return parseGithubPathSpec(pathSpec, normalizedInput, refOverride);
|
|
559
|
+
} catch {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
})();
|
|
563
|
+
if (maybeGithubByUrl) {
|
|
564
|
+
return maybeGithubByUrl;
|
|
565
|
+
}
|
|
566
|
+
const strippedDomainInput = normalizedInput.startsWith("github.com/") ? normalizedInput.slice("github.com/".length) : null;
|
|
567
|
+
if (strippedDomainInput) {
|
|
568
|
+
const parsed = parseGithubPathSpec(strippedDomainInput, normalizedInput, refOverride);
|
|
569
|
+
if (!parsed) {
|
|
570
|
+
throw new PmCliError(`Invalid GitHub source "${normalizedInput}".`, EXIT_CODE.USAGE);
|
|
571
|
+
}
|
|
572
|
+
return parsed;
|
|
573
|
+
}
|
|
574
|
+
if (options.forceGithub) {
|
|
575
|
+
const parsed = parseGithubPathSpec(normalizedInput, normalizedInput, refOverride);
|
|
576
|
+
if (!parsed) {
|
|
577
|
+
throw new PmCliError(`Invalid GitHub shorthand "${normalizedInput}".`, EXIT_CODE.USAGE);
|
|
578
|
+
}
|
|
579
|
+
return parsed;
|
|
580
|
+
}
|
|
581
|
+
if (/^https?:\/\//i.test(normalizedInput)) {
|
|
582
|
+
throw new PmCliError(`Unsupported extension source URL "${normalizedInput}". Supported remote source host: github.com.`, EXIT_CODE.USAGE);
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
kind: "local",
|
|
586
|
+
input: normalizedInput,
|
|
587
|
+
absolute_path: path4.resolve(process.cwd(), normalizedInput)
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
async function runGitCommand(args) {
|
|
591
|
+
try {
|
|
592
|
+
const result = await execFileAsync("git", args, { encoding: "utf8" });
|
|
593
|
+
return (result.stdout ?? "").trim();
|
|
594
|
+
} catch (error) {
|
|
595
|
+
const stderr = typeof error === "object" && error !== null && "stderr" in error ? String(error.stderr) : "";
|
|
596
|
+
const message = stderr.trim().length > 0 ? stderr.trim() : error instanceof Error ? error.message : String(error);
|
|
597
|
+
throw new PmCliError(`Git command failed: git ${args.join(" ")}
|
|
598
|
+
${message}`, EXIT_CODE.GENERIC_FAILURE);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
function resolveNpmCommandName(platform = process.platform) {
|
|
602
|
+
return platform === "win32" ? "npm.cmd" : "npm";
|
|
603
|
+
}
|
|
604
|
+
function shouldRunNpmCommandInShell(platform = process.platform) {
|
|
605
|
+
return platform === "win32";
|
|
606
|
+
}
|
|
607
|
+
async function runNpmCommand(args, cwd) {
|
|
608
|
+
const npmCommand = resolveNpmCommandName();
|
|
609
|
+
try {
|
|
610
|
+
const result = await execFileAsync(npmCommand, args, { cwd, encoding: "utf8", shell: shouldRunNpmCommandInShell() });
|
|
611
|
+
return (result.stdout ?? "").trim();
|
|
612
|
+
} catch (error) {
|
|
613
|
+
const stderr = typeof error === "object" && error !== null && "stderr" in error ? String(error.stderr) : "";
|
|
614
|
+
const message = stderr.trim().length > 0 ? stderr.trim() : error instanceof Error ? error.message : String(error);
|
|
615
|
+
throw new PmCliError(`npm command failed: ${npmCommand} ${args.join(" ")}
|
|
616
|
+
${message}`, EXIT_CODE.GENERIC_FAILURE);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
async function resolveLocalNpmPackagePath(spec) {
|
|
620
|
+
if (path4.isAbsolute(spec) || spec.startsWith(".") || spec.startsWith("..")) {
|
|
621
|
+
const absolutePath = path4.resolve(process.cwd(), spec);
|
|
622
|
+
return await pathExists(absolutePath) ? absolutePath : null;
|
|
623
|
+
}
|
|
624
|
+
try {
|
|
625
|
+
const parsed = new URL(spec);
|
|
626
|
+
if (parsed.protocol === "file:") {
|
|
627
|
+
const absolutePath = fileURLToPath(parsed);
|
|
628
|
+
return await pathExists(absolutePath) ? absolutePath : null;
|
|
629
|
+
}
|
|
630
|
+
} catch {
|
|
631
|
+
}
|
|
632
|
+
if (!/^[a-z][a-z0-9+.-]*:/i.test(spec)) {
|
|
633
|
+
const absolutePath = path4.resolve(process.cwd(), spec);
|
|
634
|
+
if (await pathExists(absolutePath)) {
|
|
635
|
+
return absolutePath;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
async function resolveNpmPackSpec(spec) {
|
|
641
|
+
const localPath = await resolveLocalNpmPackagePath(spec);
|
|
642
|
+
if (localPath) {
|
|
643
|
+
return pathToFileURL(localPath).href;
|
|
644
|
+
}
|
|
645
|
+
const localFileAlias = normalizeNpmLocalFileAliasSpec(spec);
|
|
646
|
+
if (localFileAlias !== spec) {
|
|
647
|
+
return localFileAlias;
|
|
648
|
+
}
|
|
649
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(spec)) {
|
|
650
|
+
return spec;
|
|
651
|
+
}
|
|
652
|
+
return spec;
|
|
653
|
+
}
|
|
654
|
+
function normalizeNpmLocalFileAliasSpec(spec, cwd = process.cwd()) {
|
|
655
|
+
const marker = "@file:";
|
|
656
|
+
const markerIndex = spec.lastIndexOf(marker);
|
|
657
|
+
if (markerIndex <= 0) {
|
|
658
|
+
return spec;
|
|
659
|
+
}
|
|
660
|
+
const packageName = spec.slice(0, markerIndex);
|
|
661
|
+
const target = spec.slice(markerIndex + marker.length);
|
|
662
|
+
if (packageName.trim().length === 0 || target.trim().length === 0 || target.startsWith("//")) {
|
|
663
|
+
return spec;
|
|
664
|
+
}
|
|
665
|
+
const absolutePath = path4.isAbsolute(target) || path4.win32.isAbsolute(target) ? target : path4.resolve(cwd, target);
|
|
666
|
+
return `${packageName}@${pathToFileURL(absolutePath).href}`;
|
|
667
|
+
}
|
|
668
|
+
function parsePackedNpmPackage(stdout, packDirectory) {
|
|
669
|
+
try {
|
|
670
|
+
const parsed = JSON.parse(stdout);
|
|
671
|
+
const first = Array.isArray(parsed) ? parsed[0] : void 0;
|
|
672
|
+
if (first && typeof first.filename === "string" && first.filename.trim().length > 0) {
|
|
673
|
+
return {
|
|
674
|
+
tarball: path4.resolve(packDirectory, first.filename),
|
|
675
|
+
package: typeof first.name === "string" ? first.name : void 0,
|
|
676
|
+
version: typeof first.version === "string" ? first.version : void 0
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
} catch {
|
|
680
|
+
}
|
|
681
|
+
const lastLine = stdout.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0).at(-1);
|
|
682
|
+
if (!lastLine) {
|
|
683
|
+
throw new PmCliError("npm pack did not report a tarball filename.", EXIT_CODE.GENERIC_FAILURE);
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
tarball: path4.resolve(packDirectory, lastLine)
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
async function resolveNpmSourceDirectory(source) {
|
|
690
|
+
const localPackageRoot = await resolveLocalNpmPackagePath(source.spec);
|
|
691
|
+
if (localPackageRoot) {
|
|
692
|
+
const packageJsonPath = path4.join(localPackageRoot, "package.json");
|
|
693
|
+
const packageJson = await pathExists(packageJsonPath) ? JSON.parse(await fs4.readFile(packageJsonPath, "utf8")) : {};
|
|
694
|
+
return {
|
|
695
|
+
directory: await resolvePackageExtensionDirectory(localPackageRoot, source.input),
|
|
696
|
+
package: typeof packageJson.name === "string" ? packageJson.name : void 0,
|
|
697
|
+
version: typeof packageJson.version === "string" ? packageJson.version : void 0,
|
|
698
|
+
cleanup: async () => {
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
const tempRoot = await fs4.mkdtemp(path4.join(os.tmpdir(), "pm-npm-package-source-"));
|
|
703
|
+
const packDirectory = path4.join(tempRoot, "pack");
|
|
704
|
+
const extractDirectory = path4.join(tempRoot, "extract");
|
|
705
|
+
await fs4.mkdir(packDirectory, { recursive: true });
|
|
706
|
+
await fs4.mkdir(extractDirectory, { recursive: true });
|
|
707
|
+
try {
|
|
708
|
+
const packSpec = await resolveNpmPackSpec(source.spec);
|
|
709
|
+
const packStdout = await runNpmCommand(["pack", packSpec, "--json", "--pack-destination", packDirectory]);
|
|
710
|
+
const packed = parsePackedNpmPackage(packStdout, packDirectory);
|
|
711
|
+
await execFileAsync("tar", ["-xzf", packed.tarball, "-C", extractDirectory], { encoding: "utf8" });
|
|
712
|
+
const packageRoot = path4.join(extractDirectory, "package");
|
|
713
|
+
await installNpmPackageRuntimeDependencies(packageRoot);
|
|
714
|
+
const directory = await resolvePackageExtensionDirectory(packageRoot, source.input);
|
|
715
|
+
return {
|
|
716
|
+
directory,
|
|
717
|
+
package: packed.package,
|
|
718
|
+
version: packed.version,
|
|
719
|
+
cleanup: async () => {
|
|
720
|
+
await fs4.rm(tempRoot, { recursive: true, force: true });
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
} catch (error) {
|
|
724
|
+
await fs4.rm(tempRoot, { recursive: true, force: true });
|
|
725
|
+
throw error;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
async function installNpmPackageRuntimeDependencies(packageRoot) {
|
|
729
|
+
const packageJsonPath = path4.join(packageRoot, "package.json");
|
|
730
|
+
if (!await pathExists(packageJsonPath)) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
let parsed;
|
|
734
|
+
try {
|
|
735
|
+
parsed = JSON.parse(await fs4.readFile(packageJsonPath, "utf8"));
|
|
736
|
+
} catch {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const manifest = parsed;
|
|
743
|
+
const dependencySpecs = runtimeDependencyInstallSpecs(manifest);
|
|
744
|
+
if (dependencySpecs.length === 0) {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
const runtimeOnlyManifest = { ...parsed };
|
|
748
|
+
delete runtimeOnlyManifest.devDependencies;
|
|
749
|
+
await fs4.writeFile(packageJsonPath, `${JSON.stringify(runtimeOnlyManifest, null, 2)}
|
|
750
|
+
`, "utf8");
|
|
751
|
+
await Promise.all([
|
|
752
|
+
fs4.rm(path4.join(packageRoot, "package-lock.json"), { force: true }),
|
|
753
|
+
fs4.rm(path4.join(packageRoot, "npm-shrinkwrap.json"), { force: true })
|
|
754
|
+
]);
|
|
755
|
+
await runNpmCommand(["install", "--ignore-scripts", "--no-audit", "--fund=false", "--package-lock=false", "--no-save", ...dependencySpecs], packageRoot);
|
|
756
|
+
}
|
|
757
|
+
function runtimeDependencyInstallSpecs(manifest) {
|
|
758
|
+
const specs = /* @__PURE__ */ new Map();
|
|
759
|
+
for (const dependencyMap of [manifest.dependencies, manifest.optionalDependencies, manifest.peerDependencies]) {
|
|
760
|
+
if (typeof dependencyMap !== "object" || dependencyMap === null) {
|
|
761
|
+
continue;
|
|
762
|
+
}
|
|
763
|
+
for (const [name, version] of Object.entries(dependencyMap)) {
|
|
764
|
+
if (typeof version !== "string" || version.trim().length === 0 || specs.has(name)) {
|
|
765
|
+
continue;
|
|
766
|
+
}
|
|
767
|
+
specs.set(name, `${name}@${version.trim()}`);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return [...specs.values()];
|
|
771
|
+
}
|
|
772
|
+
async function resolvePackageExtensionDirectory(packageRoot, sourceLabel) {
|
|
773
|
+
const discovered = await collectPackageExtensionDirectories(packageRoot);
|
|
774
|
+
if (discovered.length === 1) {
|
|
775
|
+
return discovered[0];
|
|
776
|
+
}
|
|
777
|
+
if (discovered.length > 1) {
|
|
778
|
+
const choices = discovered.map((entry) => path4.relative(packageRoot, entry).replaceAll(path4.sep, "/")).sort((left, right) => left.localeCompare(right));
|
|
779
|
+
throw new PmCliError(`Package source "${sourceLabel}" contains multiple extension manifests. Provide an explicit extension path. Candidates: ${choices.join(", ")}`, EXIT_CODE.USAGE);
|
|
780
|
+
}
|
|
781
|
+
throw new PmCliError(`Unable to locate a pm extension manifest in package source "${sourceLabel}". Package installs currently activate only extension resources, so add package.json pm.extensions or an extensions/ directory. Metadata-only resources like pm.docs/pm.examples are catalog metadata and do not activate commands.`, EXIT_CODE.USAGE);
|
|
782
|
+
}
|
|
783
|
+
async function resolveGithubSourceDirectory(cloneDirectory, source) {
|
|
784
|
+
const candidatePaths = [];
|
|
785
|
+
if (source.subpath) {
|
|
786
|
+
candidatePaths.push(source.subpath);
|
|
787
|
+
candidatePaths.push(path4.posix.join(".agents/pm/extensions", source.subpath));
|
|
788
|
+
candidatePaths.push(path4.posix.join(".custom/pm-extensions", source.subpath));
|
|
789
|
+
candidatePaths.push(path4.posix.join(".custom/pm-extension", source.subpath));
|
|
790
|
+
}
|
|
791
|
+
for (const candidate of candidatePaths) {
|
|
792
|
+
const absolute = path4.resolve(cloneDirectory, candidate);
|
|
793
|
+
if (!isPathWithinDirectory(cloneDirectory, absolute)) {
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
if (await pathExists(path4.join(absolute, "manifest.json"))) {
|
|
797
|
+
return { directory: absolute, resolved_subpath: candidate };
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
if (await pathExists(path4.join(cloneDirectory, "manifest.json"))) {
|
|
801
|
+
return { directory: cloneDirectory, resolved_subpath: "." };
|
|
802
|
+
}
|
|
803
|
+
const discoveredDirectory = await resolvePackageExtensionDirectory(cloneDirectory, source.input);
|
|
804
|
+
return {
|
|
805
|
+
directory: discoveredDirectory,
|
|
806
|
+
resolved_subpath: path4.relative(cloneDirectory, discoveredDirectory).replaceAll(path4.sep, "/")
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
async function resolveInstallSource(source) {
|
|
810
|
+
if (source.kind === "local") {
|
|
811
|
+
let localStats;
|
|
812
|
+
try {
|
|
813
|
+
localStats = await fs4.stat(source.absolute_path);
|
|
814
|
+
} catch {
|
|
815
|
+
throw new PmCliError(`Local extension source does not exist: "${source.absolute_path}".`, EXIT_CODE.NOT_FOUND);
|
|
816
|
+
}
|
|
817
|
+
if (!localStats.isDirectory()) {
|
|
818
|
+
throw new PmCliError(`Local extension source must be a directory: "${source.absolute_path}".`, EXIT_CODE.USAGE);
|
|
819
|
+
}
|
|
820
|
+
const directory = await resolvePackageExtensionDirectory(source.absolute_path, source.input);
|
|
821
|
+
return {
|
|
822
|
+
source,
|
|
823
|
+
directory
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
if (source.kind === "npm") {
|
|
827
|
+
const resolved = await resolveNpmSourceDirectory(source);
|
|
828
|
+
return {
|
|
829
|
+
source,
|
|
830
|
+
directory: resolved.directory,
|
|
831
|
+
cleanup: resolved.cleanup,
|
|
832
|
+
resolved_subpath: path4.relative(path4.dirname(resolved.directory), resolved.directory).replaceAll(path4.sep, "/"),
|
|
833
|
+
npm_package: resolved.package,
|
|
834
|
+
npm_version: resolved.version
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
const cloneDirectory = await fs4.mkdtemp(path4.join(os.tmpdir(), "pm-extension-source-"));
|
|
838
|
+
const cloneArgs = ["clone", "--depth", "1"];
|
|
839
|
+
if (source.ref) {
|
|
840
|
+
cloneArgs.push("--branch", source.ref);
|
|
841
|
+
}
|
|
842
|
+
cloneArgs.push(source.repository, cloneDirectory);
|
|
843
|
+
try {
|
|
844
|
+
await runGitCommand(cloneArgs);
|
|
845
|
+
const commit = await runGitCommand(["-C", cloneDirectory, "rev-parse", "HEAD"]);
|
|
846
|
+
const resolved = await resolveGithubSourceDirectory(cloneDirectory, source);
|
|
847
|
+
return {
|
|
848
|
+
source,
|
|
849
|
+
directory: resolved.directory,
|
|
850
|
+
resolved_subpath: resolved.resolved_subpath,
|
|
851
|
+
commit,
|
|
852
|
+
cleanup: async () => {
|
|
853
|
+
await fs4.rm(cloneDirectory, { recursive: true, force: true });
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
} catch (error) {
|
|
857
|
+
await fs4.rm(cloneDirectory, { recursive: true, force: true });
|
|
858
|
+
throw error;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
async function areDirectoriesEquivalent(left, right) {
|
|
862
|
+
if (!await pathExists(left) || !await pathExists(right)) {
|
|
863
|
+
return false;
|
|
864
|
+
}
|
|
865
|
+
const [leftRealPath, rightRealPath] = await Promise.all([fs4.realpath(left), fs4.realpath(right)]);
|
|
866
|
+
return leftRealPath === rightRealPath;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// dist/cli/commands/extension/bundled-catalog.js
|
|
870
|
+
import fs5 from "node:fs/promises";
|
|
871
|
+
import path5 from "node:path";
|
|
872
|
+
var PM_PACKAGE_ROOT_ENV = "PM_CLI_PACKAGE_ROOT";
|
|
873
|
+
var LEGACY_BUNDLED_PACKAGE_ALIASES = {
|
|
874
|
+
beads: {
|
|
875
|
+
package_directory: "pm-beads",
|
|
876
|
+
legacy_extension_directory: "beads"
|
|
877
|
+
},
|
|
878
|
+
todos: {
|
|
879
|
+
package_directory: "pm-todos",
|
|
880
|
+
legacy_extension_directory: "todos"
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
var BUNDLED_PACKAGE_INSTALL_ALL_TARGETS = /* @__PURE__ */ new Set(["*", "all"]);
|
|
884
|
+
function resolvePackageRootCandidates() {
|
|
885
|
+
const candidates = [];
|
|
886
|
+
const envRoot = process.env[PM_PACKAGE_ROOT_ENV];
|
|
887
|
+
if (typeof envRoot === "string" && envRoot.trim().length > 0) {
|
|
888
|
+
candidates.push(path5.resolve(envRoot.trim()));
|
|
889
|
+
}
|
|
890
|
+
candidates.push(resolvePmPackageRootFromModule(import.meta.url, ["../../../.."]));
|
|
891
|
+
return [...new Set(candidates)];
|
|
892
|
+
}
|
|
893
|
+
async function resolveBundledExtensionAliasSource(input) {
|
|
894
|
+
const normalized = input.trim().toLowerCase();
|
|
895
|
+
const packageRoot = await resolveBundledPackageRoot(normalized);
|
|
896
|
+
if (packageRoot) {
|
|
897
|
+
return packageRoot;
|
|
898
|
+
}
|
|
899
|
+
const alias = LEGACY_BUNDLED_PACKAGE_ALIASES[normalized];
|
|
900
|
+
if (!alias) {
|
|
901
|
+
return null;
|
|
902
|
+
}
|
|
903
|
+
for (const packageRoot2 of resolvePackageRootCandidates()) {
|
|
904
|
+
const legacyExtensionPath = path5.join(packageRoot2, ".agents", "pm", "extensions", alias.legacy_extension_directory);
|
|
905
|
+
if (await pathExists(path5.join(legacyExtensionPath, "manifest.json"))) {
|
|
906
|
+
return legacyExtensionPath;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
function isBundledPackageInstallAllTarget(input) {
|
|
912
|
+
return BUNDLED_PACKAGE_INSTALL_ALL_TARGETS.has(input.trim().toLowerCase());
|
|
913
|
+
}
|
|
914
|
+
function derivePackageAlias(packageDirectory) {
|
|
915
|
+
return packageDirectory.replace(/^pm-/i, "").trim().toLowerCase();
|
|
916
|
+
}
|
|
917
|
+
async function collectBundledPackageEntries() {
|
|
918
|
+
const entriesByAlias = /* @__PURE__ */ new Map();
|
|
919
|
+
for (const packageRoot of resolvePackageRootCandidates()) {
|
|
920
|
+
const packagesRoot = path5.join(packageRoot, "packages");
|
|
921
|
+
if (!await pathExists(packagesRoot)) {
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
const entries = await fs5.readdir(packagesRoot, { withFileTypes: true });
|
|
925
|
+
for (const entry of entries) {
|
|
926
|
+
if (!entry.isDirectory() || !entry.name.startsWith("pm-")) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const candidateRoot = path5.join(packagesRoot, entry.name);
|
|
930
|
+
if (!await pathExists(path5.join(candidateRoot, "package.json"))) {
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
const manifest = await readPmPackageManifest(candidateRoot);
|
|
934
|
+
const aliases = manifest.aliases && manifest.aliases.length > 0 ? manifest.aliases : [derivePackageAlias(entry.name)];
|
|
935
|
+
for (const alias of aliases) {
|
|
936
|
+
const normalizedAlias = alias.trim().toLowerCase();
|
|
937
|
+
if (normalizedAlias.length === 0 || entriesByAlias.has(normalizedAlias)) {
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
entriesByAlias.set(normalizedAlias, {
|
|
941
|
+
alias: normalizedAlias,
|
|
942
|
+
package_directory: entry.name,
|
|
943
|
+
package_root: candidateRoot
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
for (const [alias, legacy] of Object.entries(LEGACY_BUNDLED_PACKAGE_ALIASES)) {
|
|
949
|
+
if (entriesByAlias.has(alias)) {
|
|
950
|
+
continue;
|
|
951
|
+
}
|
|
952
|
+
for (const packageRoot of resolvePackageRootCandidates()) {
|
|
953
|
+
const packagePath = path5.join(packageRoot, "packages", legacy.package_directory);
|
|
954
|
+
if (await pathExists(path5.join(packagePath, "package.json"))) {
|
|
955
|
+
entriesByAlias.set(alias, {
|
|
956
|
+
alias,
|
|
957
|
+
package_directory: legacy.package_directory,
|
|
958
|
+
package_root: packagePath
|
|
959
|
+
});
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return [...entriesByAlias.values()].sort((left, right) => left.alias.localeCompare(right.alias));
|
|
965
|
+
}
|
|
966
|
+
async function listBundledPackageAliases() {
|
|
967
|
+
return (await collectBundledPackageEntries()).map((entry) => entry.alias);
|
|
968
|
+
}
|
|
969
|
+
async function resolveBundledPackageRoot(alias) {
|
|
970
|
+
const normalized = alias.trim().toLowerCase();
|
|
971
|
+
const entry = (await collectBundledPackageEntries()).find((candidate) => candidate.alias === normalized);
|
|
972
|
+
return entry?.package_root ?? null;
|
|
973
|
+
}
|
|
974
|
+
async function resolveBundledAliasManifestName(input) {
|
|
975
|
+
const bundledAliasSource = await resolveBundledExtensionAliasSource(input);
|
|
976
|
+
if (!bundledAliasSource) {
|
|
977
|
+
return null;
|
|
978
|
+
}
|
|
979
|
+
try {
|
|
980
|
+
const extensionDirectories = await collectPackageExtensionDirectories(bundledAliasSource);
|
|
981
|
+
if (extensionDirectories.length !== 1) {
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
const validated = await validateExtensionDirectory(extensionDirectories[0]);
|
|
985
|
+
return validated.manifest.name;
|
|
986
|
+
} catch {
|
|
987
|
+
return null;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
async function buildBundledPackageCatalog(scope, global, options = {}) {
|
|
991
|
+
const roots = resolveExtensionRoots(resolvePmRoot(process.cwd(), global.path), process.cwd());
|
|
992
|
+
const selectedRoot = scope === "global" ? roots.global : roots.project;
|
|
993
|
+
const managedStateRead = await readManagedExtensionState(selectedRoot);
|
|
994
|
+
const installedLocations = new Set(managedStateRead.state.entries.filter((entry) => entry.scope === scope).filter((entry) => entry.source.kind !== "builtin").map((entry) => path5.resolve(entry.source.location)));
|
|
995
|
+
const installedBuiltinAliases = new Set(managedStateRead.state.entries.filter((entry) => entry.scope === scope && entry.source.kind === "builtin").flatMap((entry) => [entry.source.name, entry.source.input, entry.source.location]).filter((value) => typeof value === "string" && value.trim().length > 0).map((value) => value.trim().toLowerCase()));
|
|
996
|
+
const packages = [];
|
|
997
|
+
for (const alias of await listBundledPackageAliases()) {
|
|
998
|
+
const packageRoot = await resolveBundledPackageRoot(alias);
|
|
999
|
+
const installScopeFlag = scope === "global" ? "--global" : "--project";
|
|
1000
|
+
if (!packageRoot) {
|
|
1001
|
+
packages.push({
|
|
1002
|
+
alias,
|
|
1003
|
+
bundled: true,
|
|
1004
|
+
available: false,
|
|
1005
|
+
installed: false,
|
|
1006
|
+
install_target: alias,
|
|
1007
|
+
install_command: `pm install ${alias} ${installScopeFlag}`
|
|
1008
|
+
});
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
const manifest = await readPmPackageManifest(packageRoot);
|
|
1012
|
+
const repository = manifest.catalog?.links?.repository ?? manifest.package_repository_url;
|
|
1013
|
+
const report = manifest.catalog?.links?.report ?? manifest.package_bugs_url;
|
|
1014
|
+
const docs = manifest.catalog?.links?.docs ?? manifest.package_homepage;
|
|
1015
|
+
const npm = manifest.catalog?.links?.npm ?? (manifest.package_name && manifest.package_private !== true ? `https://www.npmjs.com/package/${encodeURIComponent(manifest.package_name)}` : void 0);
|
|
1016
|
+
const metadataOnlyResources = Object.fromEntries(PM_PACKAGE_RESOURCE_KINDS.filter((resourceKind) => resourceKind !== "extensions").map((resourceKind) => [resourceKind, manifest.resources[resourceKind] ?? []]).filter(([, entries]) => Array.isArray(entries) && entries.length > 0));
|
|
1017
|
+
packages.push({
|
|
1018
|
+
alias,
|
|
1019
|
+
bundled: true,
|
|
1020
|
+
available: true,
|
|
1021
|
+
installed: installedBuiltinAliases.has(alias) || installedLocations.has(path5.resolve(packageRoot)),
|
|
1022
|
+
install_target: alias,
|
|
1023
|
+
install_command: `pm install ${alias} ${installScopeFlag}`,
|
|
1024
|
+
package_name: manifest.package_name,
|
|
1025
|
+
package_version: manifest.package_version,
|
|
1026
|
+
description: manifest.catalog?.summary ?? manifest.package_description,
|
|
1027
|
+
keywords: manifest.package_keywords ?? [],
|
|
1028
|
+
resources: manifest.resources,
|
|
1029
|
+
installable_resources: {
|
|
1030
|
+
extensions: manifest.resources.extensions ?? []
|
|
1031
|
+
},
|
|
1032
|
+
metadata_only_resources: metadataOnlyResources,
|
|
1033
|
+
catalog: {
|
|
1034
|
+
display_name: manifest.catalog?.display_name,
|
|
1035
|
+
category: manifest.catalog?.category,
|
|
1036
|
+
tags: manifest.catalog?.tags ?? manifest.package_keywords ?? [],
|
|
1037
|
+
links: {
|
|
1038
|
+
docs,
|
|
1039
|
+
npm,
|
|
1040
|
+
repository,
|
|
1041
|
+
report
|
|
1042
|
+
},
|
|
1043
|
+
media: manifest.catalog?.media
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
const fields = parsePackageCatalogFields(options.fields);
|
|
1048
|
+
const outputPackages = fields ? packages.map((entry) => projectPackageCatalogEntry(entry, fields)) : packages;
|
|
1049
|
+
return {
|
|
1050
|
+
total: outputPackages.length,
|
|
1051
|
+
scope,
|
|
1052
|
+
installable_resource_kinds: ["extensions"],
|
|
1053
|
+
metadata_only_resource_kinds: PM_PACKAGE_RESOURCE_KINDS.filter((resourceKind) => resourceKind !== "extensions"),
|
|
1054
|
+
packages: outputPackages
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
var PACKAGE_CATALOG_FIELD_KEYS = /* @__PURE__ */ new Set([
|
|
1058
|
+
"alias",
|
|
1059
|
+
"bundled",
|
|
1060
|
+
"available",
|
|
1061
|
+
"installed",
|
|
1062
|
+
"install_target",
|
|
1063
|
+
"install_command",
|
|
1064
|
+
"package_name",
|
|
1065
|
+
"package_version",
|
|
1066
|
+
"description",
|
|
1067
|
+
"keywords",
|
|
1068
|
+
"resources",
|
|
1069
|
+
"installable_resources",
|
|
1070
|
+
"metadata_only_resources",
|
|
1071
|
+
"catalog",
|
|
1072
|
+
"category",
|
|
1073
|
+
"display_name"
|
|
1074
|
+
]);
|
|
1075
|
+
function parsePackageCatalogFields(raw) {
|
|
1076
|
+
if (raw === void 0) {
|
|
1077
|
+
return void 0;
|
|
1078
|
+
}
|
|
1079
|
+
const fields = splitCommaList(raw);
|
|
1080
|
+
if (fields.length === 0) {
|
|
1081
|
+
throw new PmCliError("Package catalog --fields requires a comma-separated list of field names", EXIT_CODE.USAGE);
|
|
1082
|
+
}
|
|
1083
|
+
const unknown = fields.filter((field) => !PACKAGE_CATALOG_FIELD_KEYS.has(field));
|
|
1084
|
+
if (unknown.length > 0) {
|
|
1085
|
+
throw new PmCliError(`Unknown package catalog --fields value(s): ${unknown.join(", ")}`, EXIT_CODE.USAGE, {
|
|
1086
|
+
examples: [
|
|
1087
|
+
"pm package list --project --fields alias,installed,install_command",
|
|
1088
|
+
"pm package catalog --project --fields alias,package_name,category"
|
|
1089
|
+
]
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
return fields;
|
|
1093
|
+
}
|
|
1094
|
+
function projectPackageCatalogEntry(entry, fields) {
|
|
1095
|
+
const projected = {};
|
|
1096
|
+
for (const field of fields) {
|
|
1097
|
+
if (field === "category") {
|
|
1098
|
+
projected[field] = entry.catalog?.category ?? null;
|
|
1099
|
+
} else if (field === "display_name") {
|
|
1100
|
+
projected[field] = entry.catalog?.display_name ?? null;
|
|
1101
|
+
} else {
|
|
1102
|
+
projected[field] = entry[field] ?? null;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
return projected;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// dist/cli/commands/extension/scaffold.js
|
|
1109
|
+
import fs6 from "node:fs/promises";
|
|
1110
|
+
import path6 from "node:path";
|
|
1111
|
+
var SCAFFOLD_MANIFEST_VERSION = 1;
|
|
1112
|
+
var SCAFFOLD_PM_MIN_VERSION = "2026.5.0";
|
|
1113
|
+
function buildStarterExtensionScaffoldFiles(extensionName, commandName, vocabulary) {
|
|
1114
|
+
const packageName = `pm-${extensionName}`;
|
|
1115
|
+
const manifest = `${JSON.stringify({
|
|
1116
|
+
name: extensionName,
|
|
1117
|
+
version: "0.1.0",
|
|
1118
|
+
entry: "./index.js",
|
|
1119
|
+
capabilities: ["commands"],
|
|
1120
|
+
manifest_version: SCAFFOLD_MANIFEST_VERSION,
|
|
1121
|
+
pm_min_version: SCAFFOLD_PM_MIN_VERSION
|
|
1122
|
+
}, null, 2)}
|
|
1123
|
+
`;
|
|
1124
|
+
const entrypoint = [
|
|
1125
|
+
'/** @param {import("@unbrained/pm-cli/sdk").ExtensionApi} api */',
|
|
1126
|
+
"export function activate(api) {",
|
|
1127
|
+
" api.registerCommand({",
|
|
1128
|
+
` name: ${JSON.stringify(commandName)},`,
|
|
1129
|
+
' description: "Starter scaffold command. Replace with your own behavior.",',
|
|
1130
|
+
" run: async (context) => ({",
|
|
1131
|
+
" ok: true,",
|
|
1132
|
+
` source: ${JSON.stringify(extensionName)},`,
|
|
1133
|
+
" command: context.command,",
|
|
1134
|
+
' message: "Starter extension scaffold is active.",',
|
|
1135
|
+
" }),",
|
|
1136
|
+
" });",
|
|
1137
|
+
"}",
|
|
1138
|
+
"",
|
|
1139
|
+
"export default {",
|
|
1140
|
+
" activate,",
|
|
1141
|
+
"};",
|
|
1142
|
+
""
|
|
1143
|
+
].join("\n");
|
|
1144
|
+
if (vocabulary === "package") {
|
|
1145
|
+
const packageJson = `${JSON.stringify({
|
|
1146
|
+
name: packageName,
|
|
1147
|
+
version: "0.1.0",
|
|
1148
|
+
private: true,
|
|
1149
|
+
type: "module",
|
|
1150
|
+
keywords: ["pm-package"],
|
|
1151
|
+
peerDependencies: {
|
|
1152
|
+
"@unbrained/pm-cli": "*"
|
|
1153
|
+
},
|
|
1154
|
+
pm: {
|
|
1155
|
+
aliases: [extensionName],
|
|
1156
|
+
extensions: ["."],
|
|
1157
|
+
docs: ["README.md"],
|
|
1158
|
+
examples: ["README.md"],
|
|
1159
|
+
catalog: {
|
|
1160
|
+
display_name: extensionName,
|
|
1161
|
+
category: "workflow",
|
|
1162
|
+
summary: "Starter pm package scaffold.",
|
|
1163
|
+
tags: ["starter"]
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}, null, 2)}
|
|
1167
|
+
`;
|
|
1168
|
+
const packageReadme = [
|
|
1169
|
+
`# ${packageName}`,
|
|
1170
|
+
"",
|
|
1171
|
+
"Generated by `pm package init`.",
|
|
1172
|
+
"",
|
|
1173
|
+
"## Included Files",
|
|
1174
|
+
"- `package.json`: package metadata and `pm` resource manifest.",
|
|
1175
|
+
"- `manifest.json`: extension metadata and capabilities.",
|
|
1176
|
+
"- `index.js`: starter command registration using the `commands` capability.",
|
|
1177
|
+
"",
|
|
1178
|
+
"## Quick Start",
|
|
1179
|
+
"```bash",
|
|
1180
|
+
"pm install --project <package-path>",
|
|
1181
|
+
`pm ${commandName}`,
|
|
1182
|
+
"pm package doctor --project --detail summary",
|
|
1183
|
+
"```",
|
|
1184
|
+
"",
|
|
1185
|
+
"## Compatibility Bounds",
|
|
1186
|
+
"`manifest.json` cannot hold comments, so the version-compatibility fields are documented here:",
|
|
1187
|
+
`- \`manifest_version\` (integer): manifest schema generation. Leave at \`${SCAFFOLD_MANIFEST_VERSION}\` unless you adopt a newer manifest schema.`,
|
|
1188
|
+
`- \`pm_min_version\` (string): lowest pm CLI version that may load this package. Scaffolded as \`${SCAFFOLD_PM_MIN_VERSION}\`. The loader blocks the package on older CLIs.`,
|
|
1189
|
+
"- `pm_max_version` (string, optional): highest pm CLI version that may load this package. Add it to block CLIs that are newer than the version you have validated against. The loader blocks the package when the CLI exceeds this bound.",
|
|
1190
|
+
"",
|
|
1191
|
+
"## Notes",
|
|
1192
|
+
"- Keep simple starter runtime behavior at the package root so local installs work without dependency bootstrapping.",
|
|
1193
|
+
"- Move larger runtimes into subdirectories only after adding package dependencies and validating `pm package doctor`.",
|
|
1194
|
+
"- Add capabilities to the extension manifest only when the entrypoint uses the matching SDK API.",
|
|
1195
|
+
"- Use `@unbrained/pm-cli/sdk` as the public SDK import for richer package runtimes.",
|
|
1196
|
+
""
|
|
1197
|
+
].join("\n");
|
|
1198
|
+
return {
|
|
1199
|
+
"package.json": packageJson,
|
|
1200
|
+
"manifest.json": manifest,
|
|
1201
|
+
"index.js": entrypoint,
|
|
1202
|
+
"README.md": packageReadme
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
const readme = [
|
|
1206
|
+
`# ${extensionName}`,
|
|
1207
|
+
"",
|
|
1208
|
+
"Generated by `pm extension init`.",
|
|
1209
|
+
"",
|
|
1210
|
+
"## Included Files",
|
|
1211
|
+
"- `manifest.json`: extension metadata and capabilities.",
|
|
1212
|
+
"- `index.js`: starter command registration using the `commands` capability.",
|
|
1213
|
+
"",
|
|
1214
|
+
"## Quick Start",
|
|
1215
|
+
"```bash",
|
|
1216
|
+
"pm extension --install --project <scaffold-path>",
|
|
1217
|
+
`pm ${commandName}`,
|
|
1218
|
+
"pm extension --doctor --project --detail summary",
|
|
1219
|
+
"```",
|
|
1220
|
+
"",
|
|
1221
|
+
"## Compatibility Bounds",
|
|
1222
|
+
"`manifest.json` cannot hold comments, so the version-compatibility fields are documented here:",
|
|
1223
|
+
`- \`manifest_version\` (integer): manifest schema generation. Leave at \`${SCAFFOLD_MANIFEST_VERSION}\` unless you adopt a newer manifest schema.`,
|
|
1224
|
+
`- \`pm_min_version\` (string): lowest pm CLI version that may load this extension. Scaffolded as \`${SCAFFOLD_PM_MIN_VERSION}\`. The loader blocks the extension on older CLIs.`,
|
|
1225
|
+
"- `pm_max_version` (string, optional): highest pm CLI version that may load this extension. Add it to block CLIs that are newer than the version you have validated against. The loader blocks the extension when the CLI exceeds this bound.",
|
|
1226
|
+
"",
|
|
1227
|
+
"## Notes",
|
|
1228
|
+
"- This scaffold uses ESM exports so it works in package scopes with `type: module`.",
|
|
1229
|
+
"- Update `manifest.json` capabilities and `index.js` command behavior as your extension evolves.",
|
|
1230
|
+
""
|
|
1231
|
+
].join("\n");
|
|
1232
|
+
return {
|
|
1233
|
+
"manifest.json": manifest,
|
|
1234
|
+
"index.js": entrypoint,
|
|
1235
|
+
"README.md": readme
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
async function scaffoldExtensionProject(target, vocabulary = "extension") {
|
|
1239
|
+
const normalizedTarget = target.trim();
|
|
1240
|
+
const targetPath = path6.resolve(process.cwd(), normalizedTarget);
|
|
1241
|
+
const extensionName = normalizeManagedDirectoryName(path6.basename(targetPath));
|
|
1242
|
+
const commandName = `${extensionName} ping`;
|
|
1243
|
+
const scaffoldFiles = buildStarterExtensionScaffoldFiles(extensionName, commandName, vocabulary);
|
|
1244
|
+
let createdDirectory = false;
|
|
1245
|
+
if (await pathExists(targetPath)) {
|
|
1246
|
+
const existingTargetStats = await fs6.stat(targetPath);
|
|
1247
|
+
if (!existingTargetStats.isDirectory()) {
|
|
1248
|
+
throw new PmCliError(`Scaffold target "${targetPath}" exists and is not a directory.`, EXIT_CODE.CONFLICT);
|
|
1249
|
+
}
|
|
1250
|
+
} else {
|
|
1251
|
+
await fs6.mkdir(targetPath, { recursive: true });
|
|
1252
|
+
createdDirectory = true;
|
|
1253
|
+
}
|
|
1254
|
+
for (const [relativePath, content] of Object.entries(scaffoldFiles)) {
|
|
1255
|
+
const absolutePath = path6.join(targetPath, relativePath);
|
|
1256
|
+
if (!await pathExists(absolutePath)) {
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
const existingContent = await fs6.readFile(absolutePath, "utf8");
|
|
1260
|
+
if (existingContent !== content) {
|
|
1261
|
+
throw new PmCliError(`Scaffold file "${relativePath}" already exists with different content in "${targetPath}". Choose a new target path or remove conflicting files.`, EXIT_CODE.CONFLICT);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
const files = [];
|
|
1265
|
+
for (const [relativePath, content] of Object.entries(scaffoldFiles)) {
|
|
1266
|
+
const absolutePath = path6.join(targetPath, relativePath);
|
|
1267
|
+
if (await pathExists(absolutePath)) {
|
|
1268
|
+
files.push({
|
|
1269
|
+
path: relativePath,
|
|
1270
|
+
status: "unchanged"
|
|
1271
|
+
});
|
|
1272
|
+
continue;
|
|
1273
|
+
}
|
|
1274
|
+
await fs6.mkdir(path6.dirname(absolutePath), { recursive: true });
|
|
1275
|
+
await fs6.writeFile(absolutePath, content, "utf8");
|
|
1276
|
+
files.push({
|
|
1277
|
+
path: relativePath,
|
|
1278
|
+
status: "created"
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
return {
|
|
1282
|
+
extension_name: extensionName,
|
|
1283
|
+
command_name: commandName,
|
|
1284
|
+
target_path: targetPath,
|
|
1285
|
+
created_directory: createdDirectory,
|
|
1286
|
+
files
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// dist/cli/commands/extension/doctor.js
|
|
1291
|
+
function applyDoctorRuntimeActivationState(extensions, loadResult, activationResult) {
|
|
1292
|
+
const loadedNames = new Set(loadResult.loaded.map((entry) => normalizeExtensionNameForMatch(entry.name)));
|
|
1293
|
+
const loadFailedNames = new Set(loadResult.failed.map((entry) => normalizeExtensionNameForMatch(entry.name)));
|
|
1294
|
+
const activationFailedNames = new Set(activationResult.failed.map((entry) => normalizeExtensionNameForMatch(entry.name)));
|
|
1295
|
+
const commandPathsByExtension = /* @__PURE__ */ new Map();
|
|
1296
|
+
const actionPathsByExtension = /* @__PURE__ */ new Map();
|
|
1297
|
+
const addCommandPath = (extensionName, commandPath) => {
|
|
1298
|
+
const normalizedName = normalizeExtensionNameForMatch(extensionName);
|
|
1299
|
+
const normalizedCommandPath = commandPath.trim();
|
|
1300
|
+
if (normalizedName.length === 0 || normalizedCommandPath.length === 0) {
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
const existing = commandPathsByExtension.get(normalizedName) ?? /* @__PURE__ */ new Set();
|
|
1304
|
+
existing.add(normalizedCommandPath);
|
|
1305
|
+
commandPathsByExtension.set(normalizedName, existing);
|
|
1306
|
+
};
|
|
1307
|
+
const addActionPath = (extensionName, actionPath) => {
|
|
1308
|
+
const normalizedName = normalizeExtensionNameForMatch(extensionName);
|
|
1309
|
+
const normalizedActionPath = actionPath.trim();
|
|
1310
|
+
if (normalizedName.length === 0 || normalizedActionPath.length === 0) {
|
|
1311
|
+
return;
|
|
1312
|
+
}
|
|
1313
|
+
const existing = actionPathsByExtension.get(normalizedName) ?? /* @__PURE__ */ new Set();
|
|
1314
|
+
existing.add(normalizedActionPath);
|
|
1315
|
+
actionPathsByExtension.set(normalizedName, existing);
|
|
1316
|
+
};
|
|
1317
|
+
for (const registration of activationResult.registrations.commands) {
|
|
1318
|
+
addCommandPath(registration.name, registration.command);
|
|
1319
|
+
addActionPath(registration.name, registration.action);
|
|
1320
|
+
}
|
|
1321
|
+
for (const handler of activationResult.commands.handlers) {
|
|
1322
|
+
addCommandPath(handler.name, handler.command);
|
|
1323
|
+
}
|
|
1324
|
+
for (const override of activationResult.commands.overrides) {
|
|
1325
|
+
addCommandPath(override.name, override.command);
|
|
1326
|
+
}
|
|
1327
|
+
const sortedPaths = (values) => {
|
|
1328
|
+
if (!values || values.size === 0) {
|
|
1329
|
+
return void 0;
|
|
1330
|
+
}
|
|
1331
|
+
return [...values].sort((left, right) => left.localeCompare(right));
|
|
1332
|
+
};
|
|
1333
|
+
return extensions.map((entry) => {
|
|
1334
|
+
const normalizedName = normalizeExtensionNameForMatch(entry.name);
|
|
1335
|
+
const commandPaths = sortedPaths(commandPathsByExtension.get(normalizedName));
|
|
1336
|
+
const actionPaths = sortedPaths(actionPathsByExtension.get(normalizedName));
|
|
1337
|
+
const runtimeMetadata = {
|
|
1338
|
+
...commandPaths ? { command_paths: commandPaths } : {},
|
|
1339
|
+
...actionPaths ? { action_paths: actionPaths } : {}
|
|
1340
|
+
};
|
|
1341
|
+
if (!entry.enabled) {
|
|
1342
|
+
return {
|
|
1343
|
+
...entry,
|
|
1344
|
+
runtime_active: false,
|
|
1345
|
+
activation_status: "not_loaded",
|
|
1346
|
+
...runtimeMetadata
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
if (loadFailedNames.has(normalizedName) || activationFailedNames.has(normalizedName)) {
|
|
1350
|
+
return {
|
|
1351
|
+
...entry,
|
|
1352
|
+
runtime_active: false,
|
|
1353
|
+
activation_status: "failed",
|
|
1354
|
+
...runtimeMetadata
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
if (loadedNames.has(normalizedName)) {
|
|
1358
|
+
return {
|
|
1359
|
+
...entry,
|
|
1360
|
+
runtime_active: true,
|
|
1361
|
+
activation_status: "ok",
|
|
1362
|
+
...runtimeMetadata
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
return {
|
|
1366
|
+
...entry,
|
|
1367
|
+
runtime_active: false,
|
|
1368
|
+
activation_status: "not_loaded",
|
|
1369
|
+
...runtimeMetadata
|
|
1370
|
+
};
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
function summarizePolicyWarnings(warnings) {
|
|
1374
|
+
let warningCount = 0;
|
|
1375
|
+
let violationCount = 0;
|
|
1376
|
+
let blockedCount = 0;
|
|
1377
|
+
for (const warning of warnings) {
|
|
1378
|
+
if (!warning.startsWith("extension_policy_")) {
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
warningCount += 1;
|
|
1382
|
+
if (warning.startsWith("extension_policy_violation_")) {
|
|
1383
|
+
violationCount += 1;
|
|
1384
|
+
continue;
|
|
1385
|
+
}
|
|
1386
|
+
if (warning.startsWith("extension_policy_blocked_")) {
|
|
1387
|
+
blockedCount += 1;
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
return {
|
|
1391
|
+
warning_count: warningCount,
|
|
1392
|
+
violation_count: violationCount,
|
|
1393
|
+
blocked_count: blockedCount
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
function lifecycleFlagCommand(options, action) {
|
|
1397
|
+
return options.vocabulary === "package" ? `pm package --${action}` : `pm extension --${action}`;
|
|
1398
|
+
}
|
|
1399
|
+
var REGISTRATION_COLLISION_WARNING_CODES = /* @__PURE__ */ new Set([
|
|
1400
|
+
"extension_command_handler_collision",
|
|
1401
|
+
"extension_command_override_collision",
|
|
1402
|
+
"extension_command_override_handler_overlap",
|
|
1403
|
+
"extension_parser_override_collision",
|
|
1404
|
+
"extension_preflight_override_collision",
|
|
1405
|
+
"extension_renderer_collision",
|
|
1406
|
+
"extension_service_override_collision"
|
|
1407
|
+
]);
|
|
1408
|
+
function isRegistrationCollisionWarning(warning) {
|
|
1409
|
+
return REGISTRATION_COLLISION_WARNING_CODES.has(warningCode(warning));
|
|
1410
|
+
}
|
|
1411
|
+
function isExtensionLayer(value) {
|
|
1412
|
+
return value === "project" || value === "global";
|
|
1413
|
+
}
|
|
1414
|
+
function parseRegistrationCollisionWarning(warning) {
|
|
1415
|
+
const parts = warning.split(":");
|
|
1416
|
+
const code = parts[0];
|
|
1417
|
+
if (!code || !REGISTRATION_COLLISION_WARNING_CODES.has(code)) {
|
|
1418
|
+
return null;
|
|
1419
|
+
}
|
|
1420
|
+
const winnerLayer = parts.at(-4);
|
|
1421
|
+
const winnerName = parts.at(-3)?.trim();
|
|
1422
|
+
const displacedLayer = parts.at(-2);
|
|
1423
|
+
const displacedName = parts.at(-1)?.trim();
|
|
1424
|
+
if (!isExtensionLayer(winnerLayer) || !isExtensionLayer(displacedLayer) || !winnerName || !displacedName) {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
return {
|
|
1428
|
+
code,
|
|
1429
|
+
winner: { layer: winnerLayer, name: winnerName },
|
|
1430
|
+
displaced: { layer: displacedLayer, name: displacedName }
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
function collectRegistrationCollisionExtensionNames(warnings) {
|
|
1434
|
+
const names = /* @__PURE__ */ new Set();
|
|
1435
|
+
for (const warning of warnings) {
|
|
1436
|
+
const parsed = parseRegistrationCollisionWarning(warning);
|
|
1437
|
+
if (!parsed) {
|
|
1438
|
+
continue;
|
|
1439
|
+
}
|
|
1440
|
+
names.add(parsed.winner.name);
|
|
1441
|
+
names.add(parsed.displaced.name);
|
|
1442
|
+
}
|
|
1443
|
+
return [...names].sort((left, right) => left.localeCompare(right));
|
|
1444
|
+
}
|
|
1445
|
+
function buildRegistrationCollisionRemediation(warnings, commands) {
|
|
1446
|
+
const registrationCollisionWarnings = warnings.filter(isRegistrationCollisionWarning);
|
|
1447
|
+
if (registrationCollisionWarnings.length === 0) {
|
|
1448
|
+
return null;
|
|
1449
|
+
}
|
|
1450
|
+
const collisionNames = collectRegistrationCollisionExtensionNames(registrationCollisionWarnings);
|
|
1451
|
+
const collisionNameText = collisionNames.length > 0 ? ` Conflicting extensions: ${collisionNames.join(", ")}.` : "";
|
|
1452
|
+
return `Extension registration collisions or handler/override overlaps detected.${collisionNameText} Single-winner surfaces can hide earlier package behavior. Deactivate one conflicting package with ${commands.deactivate}, or scope registration surfaces in extensions.policy.extension_overrides, then rerun ${commands.doctor}.`;
|
|
1453
|
+
}
|
|
1454
|
+
function classifyDoctorLoadFailureWarnings(loadFailures) {
|
|
1455
|
+
const warnings = [];
|
|
1456
|
+
for (const failure of loadFailures) {
|
|
1457
|
+
const normalizedError = failure.error.toLowerCase();
|
|
1458
|
+
if (normalizedError.includes("cannot find package '@unbrained/pm-cli'") || normalizedError.includes('cannot find module "@unbrained/pm-cli"') || normalizedError.includes("cannot find module '@unbrained/pm-cli'")) {
|
|
1459
|
+
warnings.push(`extension_load_failed_sdk_dependency_missing:${failure.name}`);
|
|
1460
|
+
}
|
|
1461
|
+
if (normalizedError.includes("cannot use import statement outside a module") || normalizedError.includes("to load an es module") || normalizedError.includes("must use import to load es module")) {
|
|
1462
|
+
warnings.push(`extension_load_failed_module_mode_mismatch:${failure.name}`);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
|
|
1466
|
+
}
|
|
1467
|
+
function classifyDoctorActivationFailureWarnings(activationFailures = []) {
|
|
1468
|
+
const failures = Array.isArray(activationFailures) ? activationFailures : [];
|
|
1469
|
+
const warnings = [];
|
|
1470
|
+
for (const failure of failures) {
|
|
1471
|
+
if (!failure || typeof failure.name !== "string") {
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
const missingCapability = failure.trace?.missing_capability ?? failure.trace?.capability;
|
|
1475
|
+
if (typeof missingCapability === "string" && missingCapability.trim().length > 0) {
|
|
1476
|
+
warnings.push(`extension_capability_missing:${failure.name}:${missingCapability.trim().toLowerCase()}`);
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
return [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
|
|
1480
|
+
}
|
|
1481
|
+
function buildExtensionTriageSummary(scope, warnings, extensions, options = {}) {
|
|
1482
|
+
const normalizedWarnings = [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
|
|
1483
|
+
const managedTotal = extensions.filter((entry) => entry.managed).length;
|
|
1484
|
+
const enabledTotal = extensions.filter((entry) => entry.enabled).length;
|
|
1485
|
+
const activeTotal = extensions.filter((entry) => entry.active).length;
|
|
1486
|
+
const updateAvailableTotal = extensions.filter((entry) => entry.update_available === true).length;
|
|
1487
|
+
const unmanagedExtensions = extensions.filter((entry) => entry.managed === false);
|
|
1488
|
+
const unmanagedExpectedExtensions = unmanagedExtensions.filter((entry) => isExpectedUnmanagedExtension(entry)).map((entry) => entry.name).sort((left, right) => left.localeCompare(right));
|
|
1489
|
+
const unmanagedActionRequiredExtensions = unmanagedExtensions.filter((entry) => !isExpectedUnmanagedExtension(entry)).map((entry) => entry.name).sort((left, right) => left.localeCompare(right));
|
|
1490
|
+
const updateCheckStatusTotals = {
|
|
1491
|
+
checked: 0,
|
|
1492
|
+
skipped_unmanaged: 0,
|
|
1493
|
+
skipped_non_github: 0,
|
|
1494
|
+
failed: 0,
|
|
1495
|
+
not_checked: 0
|
|
1496
|
+
};
|
|
1497
|
+
for (const entry of extensions) {
|
|
1498
|
+
updateCheckStatusTotals[entry.update_check_status] += 1;
|
|
1499
|
+
}
|
|
1500
|
+
const updateCheckFailedTotal = updateCheckStatusTotals.failed;
|
|
1501
|
+
const skippedUnmanagedTotal = updateCheckStatusTotals.skipped_unmanaged;
|
|
1502
|
+
const skippedNonGithubTotal = updateCheckStatusTotals.skipped_non_github;
|
|
1503
|
+
const updateHealthPartial = unmanagedActionRequiredExtensions.length > 0;
|
|
1504
|
+
const updateHealthCoverage = updateHealthPartial ? "partial" : "full";
|
|
1505
|
+
const partialCoverageWarnings = updateHealthPartial ? [`extension_update_health_partial_coverage:skipped_unmanaged:${unmanagedActionRequiredExtensions.length}`] : [];
|
|
1506
|
+
const effectiveWarnings = [.../* @__PURE__ */ new Set([...normalizedWarnings, ...partialCoverageWarnings])].sort((left, right) => left.localeCompare(right));
|
|
1507
|
+
const warningCodes = [...new Set(effectiveWarnings.map((value) => warningCode(value)))].sort((left, right) => left.localeCompare(right));
|
|
1508
|
+
const policyWarnings = summarizePolicyWarnings(effectiveWarnings);
|
|
1509
|
+
const scopeFlag = scope === "global" ? "--global" : "--project";
|
|
1510
|
+
const remediation = [];
|
|
1511
|
+
if (normalizedWarnings.length > 0) {
|
|
1512
|
+
const registrationCollisionRemediation = buildRegistrationCollisionRemediation(normalizedWarnings, {
|
|
1513
|
+
deactivate: `${lifecycleFlagCommand(options, "deactivate")} <name> ${scopeFlag}`,
|
|
1514
|
+
doctor: `${lifecycleFlagCommand(options, "doctor")} ${scopeFlag} --detail deep --trace`
|
|
1515
|
+
});
|
|
1516
|
+
if (registrationCollisionRemediation) {
|
|
1517
|
+
remediation.push(registrationCollisionRemediation);
|
|
1518
|
+
}
|
|
1519
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_manifest_"))) {
|
|
1520
|
+
remediation.push(`Run ${lifecycleFlagCommand(options, "explore")} ${scopeFlag} to inspect discovered manifests and directories.`);
|
|
1521
|
+
}
|
|
1522
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_capability_unknown:"))) {
|
|
1523
|
+
remediation.push(`Unknown extension capabilities detected. Allowed capabilities: ${KNOWN_EXTENSION_CAPABILITIES.join(", ")}. Review extension_capability_unknown warning details for suggested replacements.`);
|
|
1524
|
+
}
|
|
1525
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_capability_legacy_alias:"))) {
|
|
1526
|
+
remediation.push("Legacy extension capability aliases were auto-remapped to canonical capabilities. Update manifests to canonical names (migration/validation -> schema).");
|
|
1527
|
+
}
|
|
1528
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_capability_missing:"))) {
|
|
1529
|
+
remediation.push(`Extension activation failed because code registered a surface missing from manifest capabilities. Run ${lifecycleFlagCommand(options, "doctor")} ${scopeFlag} --detail deep --trace and add the reported missing_capability to manifest.json before publishing.`);
|
|
1530
|
+
}
|
|
1531
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_command_definition_legacy_handler_alias:"))) {
|
|
1532
|
+
remediation.push("Extension command definitions using legacy handler were auto-remapped. Update command definitions to use run: (context) => ... for forward compatibility.");
|
|
1533
|
+
}
|
|
1534
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_output_service_override_global:") || warning.startsWith("extension_output_renderer_override_global:"))) {
|
|
1535
|
+
remediation.push("Global output service/renderer overrides are active. For output_format, return context.payload/null/undefined unless the extension owns the command. For renderers, return null for unrelated payloads so pm falls back to native rendering.");
|
|
1536
|
+
}
|
|
1537
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_load_failed_sdk_dependency_missing:"))) {
|
|
1538
|
+
remediation.push(`Detected extension load failures caused by missing SDK dependency resolution. Ensure extension package dependencies include "@unbrained/pm-cli" and reinstall dependencies before running ${lifecycleFlagCommand(options, "doctor")} ${scopeFlag}.`);
|
|
1539
|
+
}
|
|
1540
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_load_failed_module_mode_mismatch:"))) {
|
|
1541
|
+
remediation.push(`Detected extension module-mode mismatches. For ESM-based extension entries/imports, set package.json "type": "module" or use an explicit .mjs entry and rerun ${lifecycleFlagCommand(options, "doctor")} ${scopeFlag}.`);
|
|
1542
|
+
}
|
|
1543
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_pm_min_version_") || warning.startsWith("extension_pm_max_version_"))) {
|
|
1544
|
+
remediation.push(`Extension pm version-bound warnings detected. Align each package manifest's pm_min_version/pm_max_version with the installed pm CLI version (see the warning's required/allowed=...:current=... details), or upgrade/downgrade the pm CLI to satisfy the declared bounds, then rerun ${lifecycleFlagCommand(options, "doctor")} ${scopeFlag}.`);
|
|
1545
|
+
}
|
|
1546
|
+
if (updateCheckFailedTotal > 0) {
|
|
1547
|
+
remediation.push(`Run ${lifecycleFlagCommand(options, "manage")} ${scopeFlag} after validating network and repository access.`);
|
|
1548
|
+
}
|
|
1549
|
+
if (normalizedWarnings.some((warning) => warning.startsWith("extension_manager_state_"))) {
|
|
1550
|
+
remediation.push(`Review and repair ${scope} managed extension state file if schema/read warnings persist.`);
|
|
1551
|
+
}
|
|
1552
|
+
if (policyWarnings.warning_count > 0) {
|
|
1553
|
+
remediation.push("Extension governance policy warnings detected. Review settings.extensions.policy mode and allow/block lists to confirm intended capabilities and registration surfaces.");
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
if (updateHealthPartial) {
|
|
1557
|
+
remediation.push(`Update-check coverage is partial because unmanaged extensions need adoption. Adopt existing installs via ${lifecycleFlagCommand(options, "manage")} ${scopeFlag} --fix-managed-state (or ${lifecycleFlagCommand(options, "adopt-all")} ${scopeFlag}, ${lifecycleFlagCommand(options, "adopt")} <name> ${scopeFlag}, or reinstall via ${lifecycleFlagCommand(options, "install")} ${scopeFlag} <source>).`);
|
|
1558
|
+
} else if (skippedUnmanagedTotal > 0) {
|
|
1559
|
+
remediation.push(`Loaded unmanaged extensions are currently treated as informational. Use ${lifecycleFlagCommand(options, "manage")} ${scopeFlag} --fix-managed-state to adopt them for update checks.`);
|
|
1560
|
+
}
|
|
1561
|
+
if (skippedNonGithubTotal > 0) {
|
|
1562
|
+
remediation.push(`Non-GitHub managed extensions are skipped by update checks. Use doctor output for non-update diagnostics.`);
|
|
1563
|
+
}
|
|
1564
|
+
if (updateAvailableTotal > 0) {
|
|
1565
|
+
remediation.push(`Update available managed extensions via ${lifecycleFlagCommand(options, "install")} ${scopeFlag} <source>.`);
|
|
1566
|
+
}
|
|
1567
|
+
if (remediation.length === 0) {
|
|
1568
|
+
remediation.push(`No immediate action required. Re-run ${lifecycleFlagCommand(options, "manage")} ${scopeFlag} after extension changes.`);
|
|
1569
|
+
}
|
|
1570
|
+
return {
|
|
1571
|
+
status: effectiveWarnings.length === 0 ? "ok" : "warn",
|
|
1572
|
+
warning_count: effectiveWarnings.length,
|
|
1573
|
+
warning_codes: warningCodes,
|
|
1574
|
+
warnings: effectiveWarnings,
|
|
1575
|
+
policy_warning_count: policyWarnings.warning_count,
|
|
1576
|
+
policy_violation_count: policyWarnings.violation_count,
|
|
1577
|
+
policy_blocked_count: policyWarnings.blocked_count,
|
|
1578
|
+
total_extensions: extensions.length,
|
|
1579
|
+
managed_total: managedTotal,
|
|
1580
|
+
enabled_total: enabledTotal,
|
|
1581
|
+
active_total: activeTotal,
|
|
1582
|
+
update_available_total: updateAvailableTotal,
|
|
1583
|
+
update_health_coverage: updateHealthCoverage,
|
|
1584
|
+
update_health_partial: updateHealthPartial,
|
|
1585
|
+
unmanaged_loaded_extension_count: unmanagedExtensions.length,
|
|
1586
|
+
unmanaged_loaded_extensions: unmanagedExtensions.map((entry) => entry.name).sort((left, right) => left.localeCompare(right)),
|
|
1587
|
+
unmanaged_expected_extension_count: unmanagedExpectedExtensions.length,
|
|
1588
|
+
unmanaged_expected_extensions: unmanagedExpectedExtensions,
|
|
1589
|
+
unmanaged_action_required_extension_count: unmanagedActionRequiredExtensions.length,
|
|
1590
|
+
unmanaged_action_required_extensions: unmanagedActionRequiredExtensions,
|
|
1591
|
+
update_check_status_totals: updateCheckStatusTotals,
|
|
1592
|
+
update_check_failed_total: updateCheckFailedTotal,
|
|
1593
|
+
top_warnings: effectiveWarnings.slice(0, 8),
|
|
1594
|
+
remediation
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
function parseDoctorDetailMode(raw) {
|
|
1598
|
+
if (!raw || raw.trim().length === 0) {
|
|
1599
|
+
return "summary";
|
|
1600
|
+
}
|
|
1601
|
+
const normalized = raw.trim().toLowerCase();
|
|
1602
|
+
if (normalized === "summary" || normalized === "deep") {
|
|
1603
|
+
return normalized;
|
|
1604
|
+
}
|
|
1605
|
+
throw new PmCliError(`Invalid --detail value "${raw}". Expected summary or deep.`, EXIT_CODE.USAGE);
|
|
1606
|
+
}
|
|
1607
|
+
function warningCode(value) {
|
|
1608
|
+
const normalized = value.trim();
|
|
1609
|
+
const separator = normalized.indexOf(":");
|
|
1610
|
+
if (separator === -1) {
|
|
1611
|
+
return normalized;
|
|
1612
|
+
}
|
|
1613
|
+
return normalized.slice(0, separator);
|
|
1614
|
+
}
|
|
1615
|
+
function collectUnknownCapabilityGuidance(warnings) {
|
|
1616
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1617
|
+
const guidance = [];
|
|
1618
|
+
for (const warning of warnings) {
|
|
1619
|
+
const parsedDetails = (() => {
|
|
1620
|
+
const unknownWarning = parseUnknownExtensionCapabilityWarning(warning);
|
|
1621
|
+
if (unknownWarning) {
|
|
1622
|
+
return [unknownWarning];
|
|
1623
|
+
}
|
|
1624
|
+
return parseLegacyExtensionCapabilityAliasWarning(warning);
|
|
1625
|
+
})();
|
|
1626
|
+
for (const parsed of parsedDetails) {
|
|
1627
|
+
const key = `${parsed.layer}:${parsed.name}:${parsed.capability}`;
|
|
1628
|
+
if (seen.has(key)) {
|
|
1629
|
+
continue;
|
|
1630
|
+
}
|
|
1631
|
+
seen.add(key);
|
|
1632
|
+
guidance.push(parsed);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return guidance;
|
|
1636
|
+
}
|
|
1637
|
+
function buildCapabilityContractMetadata() {
|
|
1638
|
+
return {
|
|
1639
|
+
version: EXTENSION_CAPABILITY_CONTRACT.version,
|
|
1640
|
+
capabilities: [...EXTENSION_CAPABILITY_CONTRACT.capabilities],
|
|
1641
|
+
legacy_aliases: { ...EXTENSION_CAPABILITY_CONTRACT.legacy_aliases }
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
function isExpectedUnmanagedExtension(entry) {
|
|
1645
|
+
const normalizedName = normalizeExtensionNameForMatch(entry.name);
|
|
1646
|
+
const normalizedDirectory = normalizeExtensionNameForMatch(entry.directory);
|
|
1647
|
+
if (normalizedName.startsWith("builtin-")) {
|
|
1648
|
+
return true;
|
|
1649
|
+
}
|
|
1650
|
+
return normalizedDirectory === "beads" || normalizedDirectory === "todos";
|
|
1651
|
+
}
|
|
1652
|
+
function buildDoctorConsistencySummary(scope, installedExtensions, loadedExtensions, failedLoads, disabledByFlag) {
|
|
1653
|
+
if (scope !== "project" || disabledByFlag) {
|
|
1654
|
+
return {
|
|
1655
|
+
warnings: [],
|
|
1656
|
+
summary: {
|
|
1657
|
+
active_project_count: 0,
|
|
1658
|
+
loaded_project_count: 0,
|
|
1659
|
+
active_project_names: [],
|
|
1660
|
+
loaded_project_names: [],
|
|
1661
|
+
missing_active_project_names: []
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
const activeProjectNames = [
|
|
1666
|
+
...new Set(installedExtensions.filter((entry) => entry.active).map((entry) => normalizeExtensionNameForMatch(entry.name)))
|
|
1667
|
+
].sort((left, right) => left.localeCompare(right));
|
|
1668
|
+
const loadedProjectNames = [
|
|
1669
|
+
...new Set(loadedExtensions.filter((entry) => entry.layer === "project").map((entry) => normalizeExtensionNameForMatch(entry.name)))
|
|
1670
|
+
].sort((left, right) => left.localeCompare(right));
|
|
1671
|
+
const failedLoadNames = new Set(failedLoads.map((entry) => normalizeExtensionNameForMatch(entry.name)));
|
|
1672
|
+
const missingActiveProjectNames = activeProjectNames.filter((name) => !loadedProjectNames.includes(name) && !failedLoadNames.has(name)).sort((left, right) => left.localeCompare(right));
|
|
1673
|
+
const warnings = missingActiveProjectNames.length > 0 ? [`extension_doctor_consistency_active_not_loaded:${missingActiveProjectNames.join(",")}`] : [];
|
|
1674
|
+
return {
|
|
1675
|
+
warnings,
|
|
1676
|
+
summary: {
|
|
1677
|
+
active_project_count: activeProjectNames.length,
|
|
1678
|
+
loaded_project_count: loadedProjectNames.length,
|
|
1679
|
+
active_project_names: activeProjectNames,
|
|
1680
|
+
loaded_project_names: loadedProjectNames,
|
|
1681
|
+
missing_active_project_names: missingActiveProjectNames
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
// dist/cli/commands/extension.js
|
|
1687
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
1688
|
+
var EXTENSION_INSTALL_COPY_ATTEMPTS = 3;
|
|
1689
|
+
var EXTENSION_INSTALL_LOCK_ATTEMPTS = 120;
|
|
1690
|
+
var EXTENSION_INSTALL_LOCK_DELAY_MS = 250;
|
|
1691
|
+
var EXTENSION_INSTALL_LOCK_STALE_MS = 12e4;
|
|
1692
|
+
var NATIVE_OUTPUT_MARKER = "__pm_native_output";
|
|
1693
|
+
function buildExtensionPolicyDetails(policy) {
|
|
1694
|
+
const overrides = (policy.extension_overrides ?? []).map((override) => ({
|
|
1695
|
+
name: override.name.trim(),
|
|
1696
|
+
disabled: override.disabled === true ? true : void 0,
|
|
1697
|
+
require_trusted: override.require_trusted === true ? true : void 0,
|
|
1698
|
+
require_provenance: override.require_provenance === true ? true : void 0,
|
|
1699
|
+
sandbox_profile: override.sandbox_profile,
|
|
1700
|
+
allowed_capabilities: normalizeStringList(override.allowed_capabilities ?? []),
|
|
1701
|
+
blocked_capabilities: normalizeStringList(override.blocked_capabilities ?? []),
|
|
1702
|
+
allowed_surfaces: normalizeStringList(override.allowed_surfaces ?? []),
|
|
1703
|
+
blocked_surfaces: normalizeStringList(override.blocked_surfaces ?? []),
|
|
1704
|
+
allowed_commands: normalizeStringList(override.allowed_commands ?? []),
|
|
1705
|
+
blocked_commands: normalizeStringList(override.blocked_commands ?? []),
|
|
1706
|
+
allowed_actions: normalizeStringList(override.allowed_actions ?? []),
|
|
1707
|
+
blocked_actions: normalizeStringList(override.blocked_actions ?? []),
|
|
1708
|
+
allowed_services: normalizeStringList(override.allowed_services ?? []),
|
|
1709
|
+
blocked_services: normalizeStringList(override.blocked_services ?? [])
|
|
1710
|
+
})).filter((override) => override.name.length > 0).sort((left, right) => left.name.localeCompare(right.name));
|
|
1711
|
+
return {
|
|
1712
|
+
mode: policy.mode,
|
|
1713
|
+
trust_mode: policy.trust_mode,
|
|
1714
|
+
require_provenance: policy.require_provenance === true,
|
|
1715
|
+
trusted_extensions: normalizeStringList(policy.trusted_extensions ?? []),
|
|
1716
|
+
default_sandbox_profile: policy.default_sandbox_profile ?? "none",
|
|
1717
|
+
allowed_extensions: normalizeStringList(policy.allowed_extensions ?? []),
|
|
1718
|
+
blocked_extensions: normalizeStringList(policy.blocked_extensions ?? []),
|
|
1719
|
+
allowed_capabilities: normalizeStringList(policy.allowed_capabilities ?? []),
|
|
1720
|
+
blocked_capabilities: normalizeStringList(policy.blocked_capabilities ?? []),
|
|
1721
|
+
allowed_surfaces: normalizeStringList(policy.allowed_surfaces ?? []),
|
|
1722
|
+
blocked_surfaces: normalizeStringList(policy.blocked_surfaces ?? []),
|
|
1723
|
+
allowed_commands: normalizeStringList(policy.allowed_commands ?? []),
|
|
1724
|
+
blocked_commands: normalizeStringList(policy.blocked_commands ?? []),
|
|
1725
|
+
allowed_actions: normalizeStringList(policy.allowed_actions ?? []),
|
|
1726
|
+
blocked_actions: normalizeStringList(policy.blocked_actions ?? []),
|
|
1727
|
+
allowed_services: normalizeStringList(policy.allowed_services ?? []),
|
|
1728
|
+
blocked_services: normalizeStringList(policy.blocked_services ?? []),
|
|
1729
|
+
extension_overrides: overrides.map((override) => ({
|
|
1730
|
+
name: override.name,
|
|
1731
|
+
...override.disabled === true ? { disabled: true } : {},
|
|
1732
|
+
...override.require_trusted === true ? { require_trusted: true } : {},
|
|
1733
|
+
...override.require_provenance === true ? { require_provenance: true } : {},
|
|
1734
|
+
...override.sandbox_profile ? { sandbox_profile: override.sandbox_profile } : {},
|
|
1735
|
+
...override.allowed_capabilities.length > 0 ? { allowed_capabilities: override.allowed_capabilities } : {},
|
|
1736
|
+
...override.blocked_capabilities.length > 0 ? { blocked_capabilities: override.blocked_capabilities } : {},
|
|
1737
|
+
...override.allowed_surfaces.length > 0 ? { allowed_surfaces: override.allowed_surfaces } : {},
|
|
1738
|
+
...override.blocked_surfaces.length > 0 ? { blocked_surfaces: override.blocked_surfaces } : {},
|
|
1739
|
+
...override.allowed_commands.length > 0 ? { allowed_commands: override.allowed_commands } : {},
|
|
1740
|
+
...override.blocked_commands.length > 0 ? { blocked_commands: override.blocked_commands } : {},
|
|
1741
|
+
...override.allowed_actions.length > 0 ? { allowed_actions: override.allowed_actions } : {},
|
|
1742
|
+
...override.blocked_actions.length > 0 ? { blocked_actions: override.blocked_actions } : {},
|
|
1743
|
+
...override.allowed_services.length > 0 ? { allowed_services: override.allowed_services } : {},
|
|
1744
|
+
...override.blocked_services.length > 0 ? { blocked_services: override.blocked_services } : {}
|
|
1745
|
+
}))
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
function isRetriableExtensionInstallCopyError(error) {
|
|
1749
|
+
if (typeof error !== "object" || error === null || !("code" in error)) {
|
|
1750
|
+
return false;
|
|
1751
|
+
}
|
|
1752
|
+
const code = error.code;
|
|
1753
|
+
return code === "EEXIST" || code === "ENOTEMPTY" || code === "ENOENT";
|
|
1754
|
+
}
|
|
1755
|
+
function isErrnoCode(error, code) {
|
|
1756
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
1757
|
+
}
|
|
1758
|
+
function sleep(ms) {
|
|
1759
|
+
return new Promise((resolve) => {
|
|
1760
|
+
setTimeout(resolve, ms);
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
async function copyExtensionDirectoryForInstall(sourceDirectory, destinationDirectory, copyDirectory = fs7.cp) {
|
|
1764
|
+
for (let attempt = 1; attempt <= EXTENSION_INSTALL_COPY_ATTEMPTS; attempt += 1) {
|
|
1765
|
+
try {
|
|
1766
|
+
if (await pathExists(destinationDirectory)) {
|
|
1767
|
+
await fs7.rm(destinationDirectory, { recursive: true, force: true });
|
|
1768
|
+
}
|
|
1769
|
+
await copyExtensionDirectoryWithoutSelfNesting(sourceDirectory, destinationDirectory, copyDirectory);
|
|
1770
|
+
return;
|
|
1771
|
+
} catch (error) {
|
|
1772
|
+
if (!isRetriableExtensionInstallCopyError(error) || attempt === EXTENSION_INSTALL_COPY_ATTEMPTS) {
|
|
1773
|
+
throw error;
|
|
1774
|
+
}
|
|
1775
|
+
await sleep(EXTENSION_INSTALL_LOCK_DELAY_MS);
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
async function copyExtensionDirectoryWithoutSelfNesting(sourceDirectory, destinationDirectory, copyDirectory) {
|
|
1780
|
+
const resolvedSource = path7.resolve(sourceDirectory);
|
|
1781
|
+
const resolvedDestination = path7.resolve(destinationDirectory);
|
|
1782
|
+
if (resolvedSource === resolvedDestination) {
|
|
1783
|
+
return;
|
|
1784
|
+
}
|
|
1785
|
+
if (!isPathWithinDirectory(resolvedSource, resolvedDestination)) {
|
|
1786
|
+
await copyDirectory(sourceDirectory, destinationDirectory, { recursive: true, force: true });
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
const stagingRoot = await fs7.mkdtemp(path7.join(os2.tmpdir(), "pm-extension-copy-"));
|
|
1790
|
+
const stagedDirectory = path7.join(stagingRoot, "extension");
|
|
1791
|
+
try {
|
|
1792
|
+
await copyDirectory(sourceDirectory, stagedDirectory, { recursive: true, force: true });
|
|
1793
|
+
await copyDirectory(stagedDirectory, destinationDirectory, { recursive: true, force: true });
|
|
1794
|
+
} finally {
|
|
1795
|
+
await fs7.rm(stagingRoot, { recursive: true, force: true });
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
async function withExtensionInstallLock(settingsRoot, destinationDirectoryName, run) {
|
|
1799
|
+
const lockRoot = path7.join(settingsRoot, "runtime", "extension-install-locks");
|
|
1800
|
+
const lockPath = path7.join(lockRoot, `${destinationDirectoryName}.lock`);
|
|
1801
|
+
await fs7.mkdir(lockRoot, { recursive: true });
|
|
1802
|
+
let acquired = false;
|
|
1803
|
+
for (let attempt = 1; attempt <= EXTENSION_INSTALL_LOCK_ATTEMPTS; attempt += 1) {
|
|
1804
|
+
try {
|
|
1805
|
+
await fs7.mkdir(lockPath);
|
|
1806
|
+
acquired = true;
|
|
1807
|
+
await fs7.writeFile(path7.join(lockPath, "owner.json"), `${JSON.stringify({ pid: process.pid, created_at: nowIso(), destination: destinationDirectoryName }, null, 2)}
|
|
1808
|
+
`, "utf8");
|
|
1809
|
+
break;
|
|
1810
|
+
} catch (error) {
|
|
1811
|
+
if (!isErrnoCode(error, "EEXIST")) {
|
|
1812
|
+
throw error;
|
|
1813
|
+
}
|
|
1814
|
+
const stat = await fs7.stat(lockPath).catch(() => null);
|
|
1815
|
+
if (stat && Date.now() - stat.mtimeMs > EXTENSION_INSTALL_LOCK_STALE_MS) {
|
|
1816
|
+
await fs7.rm(lockPath, { recursive: true, force: true });
|
|
1817
|
+
continue;
|
|
1818
|
+
}
|
|
1819
|
+
await sleep(EXTENSION_INSTALL_LOCK_DELAY_MS);
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
if (!acquired) {
|
|
1823
|
+
throw new PmCliError(`Timed out waiting for extension install lock for "${destinationDirectoryName}".`, EXIT_CODE.CONFLICT);
|
|
1824
|
+
}
|
|
1825
|
+
try {
|
|
1826
|
+
return await run();
|
|
1827
|
+
} finally {
|
|
1828
|
+
await fs7.rm(lockPath, { recursive: true, force: true }).catch(() => void 0);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
async function resolveInstalledExtensionCandidate(installed, extensionTarget) {
|
|
1832
|
+
const lookupValues = [extensionTarget];
|
|
1833
|
+
const bundledAliasManifestName = await resolveBundledAliasManifestName(extensionTarget);
|
|
1834
|
+
if (bundledAliasManifestName) {
|
|
1835
|
+
lookupValues.push(bundledAliasManifestName);
|
|
1836
|
+
}
|
|
1837
|
+
const normalizedLookups = [...new Set(lookupValues.map((value) => normalizeExtensionNameForMatch(value)).filter((value) => value.length > 0))];
|
|
1838
|
+
for (const lookup of normalizedLookups) {
|
|
1839
|
+
const byName = installed.find((entry) => normalizeExtensionNameForMatch(entry.name) === lookup);
|
|
1840
|
+
if (byName) {
|
|
1841
|
+
return byName;
|
|
1842
|
+
}
|
|
1843
|
+
const byDirectory = installed.find((entry) => normalizeExtensionNameForMatch(entry.directory) === lookup);
|
|
1844
|
+
if (byDirectory) {
|
|
1845
|
+
return byDirectory;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
return void 0;
|
|
1849
|
+
}
|
|
1850
|
+
function isExtensionEnabled(settings, name) {
|
|
1851
|
+
const normalizedName = name.trim();
|
|
1852
|
+
const enabled = new Set(normalizeStringList(settings.extensions.enabled));
|
|
1853
|
+
const disabled = new Set(normalizeStringList(settings.extensions.disabled));
|
|
1854
|
+
if (disabled.has(normalizedName)) {
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
if (enabled.size === 0) {
|
|
1858
|
+
return true;
|
|
1859
|
+
}
|
|
1860
|
+
return enabled.has(normalizedName);
|
|
1861
|
+
}
|
|
1862
|
+
function ensureActivated(settings, name) {
|
|
1863
|
+
const normalizedName = name.trim();
|
|
1864
|
+
const enabled = new Set(normalizeStringList(settings.extensions.enabled));
|
|
1865
|
+
const disabled = new Set(normalizeStringList(settings.extensions.disabled));
|
|
1866
|
+
const previousEnabled = [...enabled];
|
|
1867
|
+
const previousDisabled = [...disabled];
|
|
1868
|
+
disabled.delete(normalizedName);
|
|
1869
|
+
if (enabled.size > 0) {
|
|
1870
|
+
enabled.add(normalizedName);
|
|
1871
|
+
}
|
|
1872
|
+
settings.extensions.enabled = [...enabled].sort((left, right) => left.localeCompare(right));
|
|
1873
|
+
settings.extensions.disabled = [...disabled].sort((left, right) => left.localeCompare(right));
|
|
1874
|
+
return settings.extensions.enabled.join("\0") !== previousEnabled.join("\0") || settings.extensions.disabled.join("\0") !== previousDisabled.join("\0");
|
|
1875
|
+
}
|
|
1876
|
+
function ensureDeactivated(settings, name) {
|
|
1877
|
+
const normalizedName = name.trim();
|
|
1878
|
+
const enabled = new Set(normalizeStringList(settings.extensions.enabled));
|
|
1879
|
+
const disabled = new Set(normalizeStringList(settings.extensions.disabled));
|
|
1880
|
+
const previousEnabled = [...enabled];
|
|
1881
|
+
const previousDisabled = [...disabled];
|
|
1882
|
+
enabled.delete(normalizedName);
|
|
1883
|
+
disabled.add(normalizedName);
|
|
1884
|
+
settings.extensions.enabled = [...enabled].sort((left, right) => left.localeCompare(right));
|
|
1885
|
+
settings.extensions.disabled = [...disabled].sort((left, right) => left.localeCompare(right));
|
|
1886
|
+
return settings.extensions.enabled.join("\0") !== previousEnabled.join("\0") || settings.extensions.disabled.join("\0") !== previousDisabled.join("\0");
|
|
1887
|
+
}
|
|
1888
|
+
function clearExtensionState(settings, name) {
|
|
1889
|
+
const normalizedName = name.trim();
|
|
1890
|
+
const enabled = new Set(normalizeStringList(settings.extensions.enabled));
|
|
1891
|
+
const disabled = new Set(normalizeStringList(settings.extensions.disabled));
|
|
1892
|
+
const previousEnabled = [...enabled];
|
|
1893
|
+
const previousDisabled = [...disabled];
|
|
1894
|
+
enabled.delete(normalizedName);
|
|
1895
|
+
disabled.delete(normalizedName);
|
|
1896
|
+
settings.extensions.enabled = [...enabled].sort((left, right) => left.localeCompare(right));
|
|
1897
|
+
settings.extensions.disabled = [...disabled].sort((left, right) => left.localeCompare(right));
|
|
1898
|
+
return settings.extensions.enabled.join("\0") !== previousEnabled.join("\0") || settings.extensions.disabled.join("\0") !== previousDisabled.join("\0");
|
|
1899
|
+
}
|
|
1900
|
+
function resolveAction(target, options) {
|
|
1901
|
+
const selected = [...new Set([
|
|
1902
|
+
options.install ? "install" : null,
|
|
1903
|
+
options.uninstall ? "uninstall" : null,
|
|
1904
|
+
options.explore ? "explore" : null,
|
|
1905
|
+
options.manage ? "manage" : null,
|
|
1906
|
+
options.reload ? "reload" : null,
|
|
1907
|
+
options.doctor ? "doctor" : null,
|
|
1908
|
+
options.catalog ? "catalog" : null,
|
|
1909
|
+
options.init ? "init" : null,
|
|
1910
|
+
options.scaffold ? "init" : null,
|
|
1911
|
+
options.adopt ? "adopt" : null,
|
|
1912
|
+
options.adoptAll ? "adopt-all" : null,
|
|
1913
|
+
options.activate ? "activate" : null,
|
|
1914
|
+
options.deactivate ? "deactivate" : null
|
|
1915
|
+
].filter((value) => value !== null))];
|
|
1916
|
+
if (selected.length === 0) {
|
|
1917
|
+
if (typeof target === "string" && target.trim().toLowerCase() === "doctor") {
|
|
1918
|
+
return "doctor";
|
|
1919
|
+
}
|
|
1920
|
+
if (typeof target === "string" && target.trim().toLowerCase() === "reload") {
|
|
1921
|
+
return "reload";
|
|
1922
|
+
}
|
|
1923
|
+
if (typeof target === "string" && target.trim().toLowerCase() === "catalog") {
|
|
1924
|
+
return "catalog";
|
|
1925
|
+
}
|
|
1926
|
+
if (typeof target === "string" && (target.trim().toLowerCase() === "init" || target.trim().toLowerCase() === "scaffold")) {
|
|
1927
|
+
return "init";
|
|
1928
|
+
}
|
|
1929
|
+
if (typeof target === "string" && target.trim().toLowerCase() === "explore") {
|
|
1930
|
+
return "explore";
|
|
1931
|
+
}
|
|
1932
|
+
if (typeof target === "string" && target.trim().toLowerCase() === "manage") {
|
|
1933
|
+
return "manage";
|
|
1934
|
+
}
|
|
1935
|
+
if (typeof target === "string" && (target.trim().toLowerCase() === "list" || target.trim() === "")) {
|
|
1936
|
+
return "explore";
|
|
1937
|
+
}
|
|
1938
|
+
if (target === void 0) {
|
|
1939
|
+
return "explore";
|
|
1940
|
+
}
|
|
1941
|
+
throw new PmCliError("One action flag is required. Use one of: --install, --uninstall, --explore, --manage, --reload, --doctor, --catalog, --init/--scaffold, --adopt, --adopt-all, --activate, --deactivate. Bare `pm package` and `pm extension` default to --explore.", EXIT_CODE.USAGE);
|
|
1942
|
+
}
|
|
1943
|
+
if (selected.length > 1) {
|
|
1944
|
+
throw new PmCliError("Extension action flags are mutually exclusive.", EXIT_CODE.USAGE);
|
|
1945
|
+
}
|
|
1946
|
+
return selected[0];
|
|
1947
|
+
}
|
|
1948
|
+
function resolveScope(options) {
|
|
1949
|
+
const projectLike = options.project === true || options.local === true;
|
|
1950
|
+
const global = options.global === true;
|
|
1951
|
+
if (projectLike && global) {
|
|
1952
|
+
throw new PmCliError('Options "--project/--local" and "--global" are mutually exclusive.', EXIT_CODE.USAGE);
|
|
1953
|
+
}
|
|
1954
|
+
return global ? "global" : "project";
|
|
1955
|
+
}
|
|
1956
|
+
function resolveUpdateCheckResolution(managedEntry) {
|
|
1957
|
+
if (!managedEntry) {
|
|
1958
|
+
return {
|
|
1959
|
+
status: "skipped_unmanaged",
|
|
1960
|
+
reason: "extension_not_managed"
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
if (managedEntry.source.kind !== "github") {
|
|
1964
|
+
return {
|
|
1965
|
+
status: "skipped_non_github",
|
|
1966
|
+
reason: `managed_source_kind_${managedEntry.source.kind}`
|
|
1967
|
+
};
|
|
1968
|
+
}
|
|
1969
|
+
const updateError = typeof managedEntry.update_error === "string" ? managedEntry.update_error.trim() : "";
|
|
1970
|
+
if (updateError.length > 0) {
|
|
1971
|
+
return {
|
|
1972
|
+
status: "failed",
|
|
1973
|
+
reason: updateError
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1976
|
+
if (typeof managedEntry.last_update_check_at === "string" && managedEntry.last_update_check_at.trim().length > 0) {
|
|
1977
|
+
if (managedEntry.update_available === true) {
|
|
1978
|
+
return {
|
|
1979
|
+
status: "checked",
|
|
1980
|
+
reason: "update_available"
|
|
1981
|
+
};
|
|
1982
|
+
}
|
|
1983
|
+
if (managedEntry.update_available === false) {
|
|
1984
|
+
return {
|
|
1985
|
+
status: "checked",
|
|
1986
|
+
reason: "up_to_date"
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
return {
|
|
1990
|
+
status: "checked",
|
|
1991
|
+
reason: "checked_without_commit_baseline"
|
|
1992
|
+
};
|
|
1993
|
+
}
|
|
1994
|
+
return {
|
|
1995
|
+
status: "not_checked",
|
|
1996
|
+
reason: "no_update_check_recorded"
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
async function listInstalledExtensions(extensionsRoot, scope, settings, state) {
|
|
2000
|
+
if (!await pathExists(extensionsRoot)) {
|
|
2001
|
+
return {
|
|
2002
|
+
extensions: [],
|
|
2003
|
+
warnings: []
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
const entries = await fs7.readdir(extensionsRoot, { withFileTypes: true });
|
|
2007
|
+
const directories = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort((left, right) => left.localeCompare(right));
|
|
2008
|
+
const managedByName = /* @__PURE__ */ new Map();
|
|
2009
|
+
const managedByDirectory = /* @__PURE__ */ new Map();
|
|
2010
|
+
for (const managedEntry of state.entries) {
|
|
2011
|
+
managedByName.set(normalizeExtensionNameForMatch(managedEntry.name), managedEntry);
|
|
2012
|
+
managedByDirectory.set(normalizeExtensionNameForMatch(managedEntry.directory), managedEntry);
|
|
2013
|
+
}
|
|
2014
|
+
const warnings = [];
|
|
2015
|
+
const summaries = [];
|
|
2016
|
+
for (const directoryName of directories) {
|
|
2017
|
+
const extensionDirectory = path7.join(extensionsRoot, directoryName);
|
|
2018
|
+
const manifestPath = path7.join(extensionDirectory, "manifest.json");
|
|
2019
|
+
if (!await pathExists(manifestPath)) {
|
|
2020
|
+
warnings.push(`extension_manifest_missing:${scope}:${directoryName}`);
|
|
2021
|
+
const managedEntry2 = managedByDirectory.get(normalizeExtensionNameForMatch(directoryName));
|
|
2022
|
+
const updateCheck2 = resolveUpdateCheckResolution(managedEntry2);
|
|
2023
|
+
const enabled2 = managedEntry2 ? isExtensionEnabled(settings, managedEntry2.name) : false;
|
|
2024
|
+
summaries.push({
|
|
2025
|
+
name: managedEntry2?.name ?? directoryName,
|
|
2026
|
+
directory: directoryName,
|
|
2027
|
+
version: managedEntry2?.manifest_version ?? "unknown",
|
|
2028
|
+
entry: managedEntry2?.manifest_entry ?? "unknown",
|
|
2029
|
+
scope,
|
|
2030
|
+
active: enabled2,
|
|
2031
|
+
enabled: enabled2,
|
|
2032
|
+
runtime_active: null,
|
|
2033
|
+
activation_status: "unknown",
|
|
2034
|
+
managed: Boolean(managedEntry2),
|
|
2035
|
+
source: managedEntry2?.source,
|
|
2036
|
+
update_available: managedEntry2?.update_available,
|
|
2037
|
+
last_update_check_at: managedEntry2?.last_update_check_at,
|
|
2038
|
+
last_update_remote_commit: managedEntry2?.last_update_remote_commit,
|
|
2039
|
+
update_error: managedEntry2?.update_error,
|
|
2040
|
+
update_check_status: updateCheck2.status,
|
|
2041
|
+
update_check_reason: updateCheck2.reason
|
|
2042
|
+
});
|
|
2043
|
+
continue;
|
|
2044
|
+
}
|
|
2045
|
+
let rawManifest;
|
|
2046
|
+
try {
|
|
2047
|
+
rawManifest = JSON.parse(await fs7.readFile(manifestPath, "utf8"));
|
|
2048
|
+
} catch {
|
|
2049
|
+
warnings.push(`extension_manifest_invalid_json:${scope}:${directoryName}`);
|
|
2050
|
+
continue;
|
|
2051
|
+
}
|
|
2052
|
+
const manifest = parseExtensionManifest(rawManifest);
|
|
2053
|
+
if (!manifest) {
|
|
2054
|
+
warnings.push(`extension_manifest_invalid:${scope}:${directoryName}`);
|
|
2055
|
+
continue;
|
|
2056
|
+
}
|
|
2057
|
+
const managedEntry = managedByName.get(normalizeExtensionNameForMatch(manifest.name)) ?? managedByDirectory.get(normalizeExtensionNameForMatch(directoryName));
|
|
2058
|
+
const updateCheck = resolveUpdateCheckResolution(managedEntry);
|
|
2059
|
+
const enabled = isExtensionEnabled(settings, manifest.name);
|
|
2060
|
+
summaries.push({
|
|
2061
|
+
name: manifest.name,
|
|
2062
|
+
directory: directoryName,
|
|
2063
|
+
version: manifest.version,
|
|
2064
|
+
entry: manifest.entry,
|
|
2065
|
+
scope,
|
|
2066
|
+
active: enabled,
|
|
2067
|
+
enabled,
|
|
2068
|
+
runtime_active: null,
|
|
2069
|
+
activation_status: "unknown",
|
|
2070
|
+
managed: Boolean(managedEntry),
|
|
2071
|
+
source: managedEntry?.source,
|
|
2072
|
+
update_available: managedEntry?.update_available,
|
|
2073
|
+
last_update_check_at: managedEntry?.last_update_check_at,
|
|
2074
|
+
last_update_remote_commit: managedEntry?.last_update_remote_commit,
|
|
2075
|
+
update_error: managedEntry?.update_error,
|
|
2076
|
+
update_check_status: updateCheck.status,
|
|
2077
|
+
update_check_reason: updateCheck.reason
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
return {
|
|
2081
|
+
extensions: summaries.sort((left, right) => left.name.localeCompare(right.name)),
|
|
2082
|
+
warnings: warnings.sort((left, right) => left.localeCompare(right))
|
|
2083
|
+
};
|
|
2084
|
+
}
|
|
2085
|
+
async function checkGithubUpdate(source) {
|
|
2086
|
+
const checkedAt = nowIso();
|
|
2087
|
+
if (source.kind !== "github" || !source.repository) {
|
|
2088
|
+
return {
|
|
2089
|
+
checked_at: checkedAt,
|
|
2090
|
+
available: null,
|
|
2091
|
+
error: "not_a_github_managed_source"
|
|
2092
|
+
};
|
|
2093
|
+
}
|
|
2094
|
+
try {
|
|
2095
|
+
const ref = source.ref && source.ref.trim().length > 0 ? source.ref.trim() : "HEAD";
|
|
2096
|
+
const output = await runGitCommand(["ls-remote", source.repository, ref]);
|
|
2097
|
+
const firstLine = output.split(/\r?\n/).map((line) => line.trim()).find((line) => line.length > 0);
|
|
2098
|
+
if (!firstLine) {
|
|
2099
|
+
return {
|
|
2100
|
+
checked_at: checkedAt,
|
|
2101
|
+
available: null,
|
|
2102
|
+
error: "no_remote_reference_found"
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
const [remoteCommit] = firstLine.split(/\s+/);
|
|
2106
|
+
if (typeof remoteCommit !== "string" || remoteCommit.length === 0) {
|
|
2107
|
+
return {
|
|
2108
|
+
checked_at: checkedAt,
|
|
2109
|
+
available: null,
|
|
2110
|
+
error: "invalid_remote_reference"
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
if (typeof source.commit === "string" && source.commit.trim().length > 0) {
|
|
2114
|
+
return {
|
|
2115
|
+
checked_at: checkedAt,
|
|
2116
|
+
remote_commit: remoteCommit,
|
|
2117
|
+
available: remoteCommit !== source.commit.trim()
|
|
2118
|
+
};
|
|
2119
|
+
}
|
|
2120
|
+
return {
|
|
2121
|
+
checked_at: checkedAt,
|
|
2122
|
+
remote_commit: remoteCommit,
|
|
2123
|
+
available: null,
|
|
2124
|
+
error: "missing_installed_commit"
|
|
2125
|
+
};
|
|
2126
|
+
} catch (error) {
|
|
2127
|
+
return {
|
|
2128
|
+
checked_at: checkedAt,
|
|
2129
|
+
available: null,
|
|
2130
|
+
error: error instanceof Error ? error.message : String(error)
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
async function adoptUnmanagedExtensions(extensionsRoot, scope, installedExtensions, state) {
|
|
2135
|
+
const unmanagedCandidates = installedExtensions.filter((entry) => !entry.managed);
|
|
2136
|
+
const sortedCandidates = [...unmanagedCandidates].sort((left, right) => {
|
|
2137
|
+
const byName = left.name.localeCompare(right.name);
|
|
2138
|
+
if (byName !== 0) {
|
|
2139
|
+
return byName;
|
|
2140
|
+
}
|
|
2141
|
+
return left.directory.localeCompare(right.directory);
|
|
2142
|
+
});
|
|
2143
|
+
let nextState = state;
|
|
2144
|
+
const adoptedEntries = [];
|
|
2145
|
+
for (const candidate of sortedCandidates) {
|
|
2146
|
+
const extensionDirectory = path7.join(extensionsRoot, candidate.directory);
|
|
2147
|
+
const validated = await validateExtensionDirectory(extensionDirectory);
|
|
2148
|
+
const now = nowIso();
|
|
2149
|
+
const sourceRecord = {
|
|
2150
|
+
kind: "local",
|
|
2151
|
+
input: candidate.name,
|
|
2152
|
+
location: extensionDirectory
|
|
2153
|
+
};
|
|
2154
|
+
nextState = upsertManagedEntry(nextState, {
|
|
2155
|
+
name: validated.manifest.name,
|
|
2156
|
+
directory: candidate.directory,
|
|
2157
|
+
scope,
|
|
2158
|
+
manifest_version: validated.manifest.version,
|
|
2159
|
+
manifest_entry: validated.manifest.entry,
|
|
2160
|
+
capabilities: [...validated.manifest.capabilities],
|
|
2161
|
+
installed_at: now,
|
|
2162
|
+
updated_at: now,
|
|
2163
|
+
source: sourceRecord
|
|
2164
|
+
});
|
|
2165
|
+
adoptedEntries.push({
|
|
2166
|
+
name: validated.manifest.name,
|
|
2167
|
+
directory: candidate.directory,
|
|
2168
|
+
version: validated.manifest.version,
|
|
2169
|
+
entry: validated.manifest.entry,
|
|
2170
|
+
source: sourceRecord
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
if (adoptedEntries.length > 0) {
|
|
2174
|
+
await writeManagedExtensionState(extensionsRoot, nextState);
|
|
2175
|
+
}
|
|
2176
|
+
return {
|
|
2177
|
+
state: nextState,
|
|
2178
|
+
adopted_entries: adoptedEntries,
|
|
2179
|
+
unmanaged_candidates: sortedCandidates,
|
|
2180
|
+
already_managed_count: installedExtensions.length - unmanagedCandidates.length
|
|
2181
|
+
};
|
|
2182
|
+
}
|
|
2183
|
+
function resolveExtensionRootsForScope(scope, global) {
|
|
2184
|
+
const pmRoot = resolvePmRoot(process.cwd(), global.path);
|
|
2185
|
+
const roots = resolveExtensionRoots(pmRoot, process.cwd());
|
|
2186
|
+
const settingsRoot = scope === "global" ? resolveGlobalPmRoot(process.cwd()) : pmRoot;
|
|
2187
|
+
const selectedRoot = scope === "global" ? roots.global : roots.project;
|
|
2188
|
+
return {
|
|
2189
|
+
pm_root: pmRoot,
|
|
2190
|
+
scope,
|
|
2191
|
+
settings_root: settingsRoot,
|
|
2192
|
+
selected_root: selectedRoot,
|
|
2193
|
+
roots
|
|
2194
|
+
};
|
|
2195
|
+
}
|
|
2196
|
+
function resolveGithubOption(options) {
|
|
2197
|
+
if (typeof options.gh === "string" && typeof options.github === "string" && options.gh.trim() !== options.github.trim()) {
|
|
2198
|
+
throw new PmCliError('Options "--gh" and "--github" must match when both are provided.', EXIT_CODE.USAGE);
|
|
2199
|
+
}
|
|
2200
|
+
if (typeof options.gh === "string" && options.gh.trim().length > 0) {
|
|
2201
|
+
return options.gh.trim();
|
|
2202
|
+
}
|
|
2203
|
+
if (typeof options.github === "string" && options.github.trim().length > 0) {
|
|
2204
|
+
return options.github.trim();
|
|
2205
|
+
}
|
|
2206
|
+
return void 0;
|
|
2207
|
+
}
|
|
2208
|
+
function requireTarget(target, action) {
|
|
2209
|
+
const normalized = target?.trim();
|
|
2210
|
+
if (!normalized) {
|
|
2211
|
+
if (action === "init") {
|
|
2212
|
+
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);
|
|
2213
|
+
}
|
|
2214
|
+
throw new PmCliError(`Action "${action}" requires an extension name or source target argument.`, EXIT_CODE.USAGE);
|
|
2215
|
+
}
|
|
2216
|
+
return normalized;
|
|
2217
|
+
}
|
|
2218
|
+
function collectGlobalOutputOverrideDoctorWarnings(activationResult) {
|
|
2219
|
+
const warnings = [];
|
|
2220
|
+
for (const entry of activationResult.services.overrides) {
|
|
2221
|
+
if (entry.service !== "output_format") {
|
|
2222
|
+
continue;
|
|
2223
|
+
}
|
|
2224
|
+
warnings.push(`extension_output_service_override_global:${entry.service}:${entry.layer}:${entry.name}`);
|
|
2225
|
+
}
|
|
2226
|
+
for (const entry of activationResult.renderers.overrides) {
|
|
2227
|
+
warnings.push(`extension_output_renderer_override_global:${entry.format}:${entry.layer}:${entry.name}`);
|
|
2228
|
+
}
|
|
2229
|
+
return [...new Set(warnings)].sort((left, right) => left.localeCompare(right));
|
|
2230
|
+
}
|
|
2231
|
+
async function runExtension(target, options, global) {
|
|
2232
|
+
const action = resolveAction(target, options);
|
|
2233
|
+
if ((options.strictExit === true || options.failOnWarn === true) && action !== "doctor") {
|
|
2234
|
+
throw new PmCliError("--strict-exit and --fail-on-warn are only valid with --doctor.", EXIT_CODE.USAGE);
|
|
2235
|
+
}
|
|
2236
|
+
if (options.trace === true && action !== "doctor") {
|
|
2237
|
+
throw new PmCliError("--trace is only valid with --doctor.", EXIT_CODE.USAGE);
|
|
2238
|
+
}
|
|
2239
|
+
if (options.watch === true && action !== "reload") {
|
|
2240
|
+
throw new PmCliError("--watch is only valid with --reload.", EXIT_CODE.USAGE);
|
|
2241
|
+
}
|
|
2242
|
+
if (options.runtimeProbe === true && action !== "manage") {
|
|
2243
|
+
throw new PmCliError("--runtime-probe is only valid with --manage.", EXIT_CODE.USAGE);
|
|
2244
|
+
}
|
|
2245
|
+
if (options.fixManagedState === true && action !== "manage" && action !== "doctor") {
|
|
2246
|
+
throw new PmCliError("--fix-managed-state is only valid with --manage or --doctor.", EXIT_CODE.USAGE);
|
|
2247
|
+
}
|
|
2248
|
+
const normalizedTarget = (() => {
|
|
2249
|
+
const normalizedInput = target?.trim().toLowerCase();
|
|
2250
|
+
if (action === "doctor" && normalizedInput === "doctor") {
|
|
2251
|
+
return void 0;
|
|
2252
|
+
}
|
|
2253
|
+
if (action === "reload" && normalizedInput === "reload") {
|
|
2254
|
+
return void 0;
|
|
2255
|
+
}
|
|
2256
|
+
if (action === "catalog" && normalizedInput === "catalog") {
|
|
2257
|
+
return void 0;
|
|
2258
|
+
}
|
|
2259
|
+
const inferredInitAlias = action === "init" && options.init !== true && options.scaffold !== true && (normalizedInput === "init" || normalizedInput === "scaffold");
|
|
2260
|
+
if (inferredInitAlias) {
|
|
2261
|
+
return void 0;
|
|
2262
|
+
}
|
|
2263
|
+
return target;
|
|
2264
|
+
})();
|
|
2265
|
+
const scope = resolveScope(options);
|
|
2266
|
+
const resolvedRoots = resolveExtensionRootsForScope(scope, global);
|
|
2267
|
+
const warnings = [];
|
|
2268
|
+
const withResult = (details) => {
|
|
2269
|
+
const result = {
|
|
2270
|
+
ok: true,
|
|
2271
|
+
action,
|
|
2272
|
+
scope,
|
|
2273
|
+
roots: action === "catalog" && typeof options.fields === "string" && options.fields.trim().length > 0 ? {
|
|
2274
|
+
project: "project",
|
|
2275
|
+
global: "global",
|
|
2276
|
+
selected: scope,
|
|
2277
|
+
settings_root: "project"
|
|
2278
|
+
} : {
|
|
2279
|
+
project: resolvedRoots.roots.project,
|
|
2280
|
+
global: resolvedRoots.roots.global,
|
|
2281
|
+
selected: resolvedRoots.selected_root,
|
|
2282
|
+
settings_root: resolvedRoots.settings_root
|
|
2283
|
+
},
|
|
2284
|
+
warnings: [...new Set(warnings)].sort((left, right) => left.localeCompare(right)),
|
|
2285
|
+
details
|
|
2286
|
+
};
|
|
2287
|
+
if (action === "doctor") {
|
|
2288
|
+
Object.defineProperty(result, NATIVE_OUTPUT_MARKER, {
|
|
2289
|
+
value: true,
|
|
2290
|
+
enumerable: false,
|
|
2291
|
+
configurable: false
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
return result;
|
|
2295
|
+
};
|
|
2296
|
+
if (action === "init") {
|
|
2297
|
+
const githubOption = resolveGithubOption(options);
|
|
2298
|
+
if (githubOption !== void 0 || typeof options.ref === "string" && options.ref.trim().length > 0) {
|
|
2299
|
+
throw new PmCliError('Action "init" does not accept --gh/--github/--ref options.', EXIT_CODE.USAGE);
|
|
2300
|
+
}
|
|
2301
|
+
const scaffoldTarget = requireTarget(normalizedTarget, action);
|
|
2302
|
+
const scaffold = await scaffoldExtensionProject(scaffoldTarget, options.vocabulary ?? "extension");
|
|
2303
|
+
const quotedTargetPath = JSON.stringify(scaffold.target_path);
|
|
2304
|
+
return withResult({
|
|
2305
|
+
scaffolded: scaffold.created_directory || scaffold.files.some((entry) => entry.status === "created"),
|
|
2306
|
+
extension: {
|
|
2307
|
+
name: scaffold.extension_name,
|
|
2308
|
+
command: scaffold.command_name
|
|
2309
|
+
},
|
|
2310
|
+
target_path: scaffold.target_path,
|
|
2311
|
+
created_directory: scaffold.created_directory,
|
|
2312
|
+
files: scaffold.files,
|
|
2313
|
+
next_steps: [
|
|
2314
|
+
`Install the scaffold: ${options.vocabulary === "package" ? "pm install --project" : "pm extension --install --project"} ${quotedTargetPath}`,
|
|
2315
|
+
`Smoke-test command path: pm ${scaffold.command_name}`,
|
|
2316
|
+
`Run diagnostics: ${options.vocabulary === "package" ? "pm package doctor" : "pm extension --doctor"} --project --detail summary`
|
|
2317
|
+
]
|
|
2318
|
+
});
|
|
2319
|
+
}
|
|
2320
|
+
if (action === "reload") {
|
|
2321
|
+
if (normalizedTarget !== void 0) {
|
|
2322
|
+
throw new PmCliError('Action "reload" does not accept a target argument.', EXIT_CODE.USAGE);
|
|
2323
|
+
}
|
|
2324
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2325
|
+
const reloadToken = nextExtensionReloadToken();
|
|
2326
|
+
const reloaded = await loadExtensions({
|
|
2327
|
+
pmRoot: resolvedRoots.settings_root,
|
|
2328
|
+
settings,
|
|
2329
|
+
cwd: process.cwd(),
|
|
2330
|
+
noExtensions: global.noExtensions,
|
|
2331
|
+
reload_token: reloadToken,
|
|
2332
|
+
cache_bust: true
|
|
2333
|
+
});
|
|
2334
|
+
warnings.push(...reloaded.warnings);
|
|
2335
|
+
const activation = await activateExtensions(reloaded);
|
|
2336
|
+
warnings.push(...activation.warnings);
|
|
2337
|
+
const details = {
|
|
2338
|
+
reload: {
|
|
2339
|
+
token: reloadToken,
|
|
2340
|
+
cache_bust: true,
|
|
2341
|
+
watch: options.watch === true
|
|
2342
|
+
},
|
|
2343
|
+
loaded_count: reloaded.loaded.length,
|
|
2344
|
+
failed_count: reloaded.failed.length,
|
|
2345
|
+
activated_count: Math.max(0, reloaded.loaded.length - activation.failed.length),
|
|
2346
|
+
activation_failed_count: activation.failed.length,
|
|
2347
|
+
loaded_extensions: reloaded.loaded.map((entry) => ({
|
|
2348
|
+
name: entry.name,
|
|
2349
|
+
layer: entry.layer,
|
|
2350
|
+
version: entry.version
|
|
2351
|
+
})),
|
|
2352
|
+
failed_extensions: reloaded.failed.map((entry) => ({
|
|
2353
|
+
name: entry.name,
|
|
2354
|
+
layer: entry.layer,
|
|
2355
|
+
error: entry.error
|
|
2356
|
+
})),
|
|
2357
|
+
activation_failures: activation.failed.map((entry) => ({
|
|
2358
|
+
name: entry.name,
|
|
2359
|
+
layer: entry.layer,
|
|
2360
|
+
error: entry.error
|
|
2361
|
+
}))
|
|
2362
|
+
};
|
|
2363
|
+
if (options.watch === true) {
|
|
2364
|
+
warnings.push("extension_reload_watch_hint:watch_mode_requested_non_interactive_single_pass_only");
|
|
2365
|
+
}
|
|
2366
|
+
return withResult(details);
|
|
2367
|
+
}
|
|
2368
|
+
if (action === "catalog") {
|
|
2369
|
+
if (typeof normalizedTarget === "string" && normalizedTarget.length > 0 && normalizedTarget !== "catalog") {
|
|
2370
|
+
throw new PmCliError('Action "catalog" does not accept a package target.', EXIT_CODE.USAGE);
|
|
2371
|
+
}
|
|
2372
|
+
return withResult(await buildBundledPackageCatalog(scope, global, options));
|
|
2373
|
+
}
|
|
2374
|
+
if (action === "install") {
|
|
2375
|
+
const githubOption = resolveGithubOption(options);
|
|
2376
|
+
const explicitSourceInput = githubOption ?? requireTarget(normalizedTarget, action);
|
|
2377
|
+
if (typeof githubOption !== "string" && isBundledPackageInstallAllTarget(explicitSourceInput)) {
|
|
2378
|
+
if (typeof options.ref === "string" && options.ref.trim().length > 0) {
|
|
2379
|
+
throw new PmCliError('Action "install all" does not accept --ref.', EXIT_CODE.USAGE);
|
|
2380
|
+
}
|
|
2381
|
+
const aliases = await listBundledPackageAliases();
|
|
2382
|
+
const packages = [];
|
|
2383
|
+
for (const alias of aliases) {
|
|
2384
|
+
packages.push({
|
|
2385
|
+
alias,
|
|
2386
|
+
result: await runExtension(alias, { ...options, install: true }, global)
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2389
|
+
for (const entry of packages) {
|
|
2390
|
+
warnings.push(...entry.result.warnings);
|
|
2391
|
+
}
|
|
2392
|
+
return withResult({
|
|
2393
|
+
installed_all: true,
|
|
2394
|
+
installed_count: packages.length,
|
|
2395
|
+
packages: packages.map((entry) => ({
|
|
2396
|
+
alias: entry.alias,
|
|
2397
|
+
ok: entry.result.ok,
|
|
2398
|
+
extension: entry.result.details.extension,
|
|
2399
|
+
source: entry.result.details.source,
|
|
2400
|
+
destination_path: entry.result.details.destination_path,
|
|
2401
|
+
activated: entry.result.details.activated,
|
|
2402
|
+
settings_changed: entry.result.details.settings_changed,
|
|
2403
|
+
warnings: entry.result.warnings
|
|
2404
|
+
}))
|
|
2405
|
+
});
|
|
2406
|
+
}
|
|
2407
|
+
const bundledAliasSource = typeof githubOption === "string" ? null : await resolveBundledExtensionAliasSource(explicitSourceInput);
|
|
2408
|
+
const bundledAliasName = bundledAliasSource === null ? null : explicitSourceInput.trim().toLowerCase();
|
|
2409
|
+
const sourceInput = bundledAliasSource ?? explicitSourceInput;
|
|
2410
|
+
const installSource = parseExtensionInstallSource(sourceInput, {
|
|
2411
|
+
forceGithub: typeof githubOption === "string",
|
|
2412
|
+
ref: options.ref
|
|
2413
|
+
});
|
|
2414
|
+
const resolvedSource = await resolveInstallSource(installSource);
|
|
2415
|
+
try {
|
|
2416
|
+
const validated = await validateExtensionDirectory(resolvedSource.directory);
|
|
2417
|
+
const destinationDirectoryName = normalizeManagedDirectoryName(validated.manifest.name);
|
|
2418
|
+
return await withExtensionInstallLock(resolvedRoots.settings_root, destinationDirectoryName, async () => {
|
|
2419
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2420
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2421
|
+
warnings.push(...managedStateRead.warnings);
|
|
2422
|
+
const destinationDirectory = path7.join(resolvedRoots.selected_root, destinationDirectoryName);
|
|
2423
|
+
const destinationExists = await pathExists(destinationDirectory);
|
|
2424
|
+
const installInPlace = await areDirectoriesEquivalent(validated.directory, destinationDirectory);
|
|
2425
|
+
await fs7.mkdir(resolvedRoots.selected_root, { recursive: true });
|
|
2426
|
+
if (!installInPlace) {
|
|
2427
|
+
await copyExtensionDirectoryForInstall(validated.directory, destinationDirectory);
|
|
2428
|
+
}
|
|
2429
|
+
const sourceRecord = bundledAliasName ? {
|
|
2430
|
+
kind: "builtin",
|
|
2431
|
+
input: bundledAliasName,
|
|
2432
|
+
location: bundledAliasName,
|
|
2433
|
+
name: bundledAliasName
|
|
2434
|
+
} : installSource.kind === "local" ? {
|
|
2435
|
+
kind: "local",
|
|
2436
|
+
input: installSource.input,
|
|
2437
|
+
location: installSource.absolute_path
|
|
2438
|
+
} : installSource.kind === "npm" ? {
|
|
2439
|
+
kind: "npm",
|
|
2440
|
+
input: installSource.input,
|
|
2441
|
+
location: resolvedSource.resolved_subpath ?? ".",
|
|
2442
|
+
package: resolvedSource.npm_package,
|
|
2443
|
+
version: resolvedSource.npm_version
|
|
2444
|
+
} : {
|
|
2445
|
+
kind: "github",
|
|
2446
|
+
input: installSource.input,
|
|
2447
|
+
location: resolvedSource.resolved_subpath ?? installSource.subpath ?? ".",
|
|
2448
|
+
repository: installSource.repository,
|
|
2449
|
+
owner: installSource.owner,
|
|
2450
|
+
repo: installSource.repo,
|
|
2451
|
+
ref: installSource.ref,
|
|
2452
|
+
subpath: resolvedSource.resolved_subpath ?? installSource.subpath,
|
|
2453
|
+
commit: resolvedSource.commit
|
|
2454
|
+
};
|
|
2455
|
+
const now = nowIso();
|
|
2456
|
+
const existingManagedEntry = managedStateRead.state.entries.find((entry) => normalizeExtensionNameForMatch(entry.name) === normalizeExtensionNameForMatch(validated.manifest.name));
|
|
2457
|
+
const sourceUnchanged = existingManagedEntry !== void 0 && existingManagedEntry.manifest_version === validated.manifest.version && managedExtensionSourcesEquivalent(existingManagedEntry.source, sourceRecord);
|
|
2458
|
+
const managedState = upsertManagedEntry(managedStateRead.state, {
|
|
2459
|
+
name: validated.manifest.name,
|
|
2460
|
+
directory: destinationDirectoryName,
|
|
2461
|
+
scope,
|
|
2462
|
+
manifest_version: validated.manifest.version,
|
|
2463
|
+
manifest_entry: validated.manifest.entry,
|
|
2464
|
+
capabilities: [...validated.manifest.capabilities],
|
|
2465
|
+
installed_at: existingManagedEntry?.installed_at ?? now,
|
|
2466
|
+
updated_at: sourceUnchanged ? existingManagedEntry.updated_at : now,
|
|
2467
|
+
source: sourceRecord
|
|
2468
|
+
});
|
|
2469
|
+
await writeManagedExtensionState(resolvedRoots.selected_root, managedState);
|
|
2470
|
+
const activationChanged = ensureActivated(settings, validated.manifest.name);
|
|
2471
|
+
if (activationChanged) {
|
|
2472
|
+
await writeSettings(resolvedRoots.settings_root, settings, "settings:write");
|
|
2473
|
+
}
|
|
2474
|
+
return withResult({
|
|
2475
|
+
extension: {
|
|
2476
|
+
name: validated.manifest.name,
|
|
2477
|
+
version: validated.manifest.version,
|
|
2478
|
+
entry: validated.manifest.entry,
|
|
2479
|
+
capabilities: validated.manifest.capabilities,
|
|
2480
|
+
directory: destinationDirectoryName
|
|
2481
|
+
},
|
|
2482
|
+
source: sourceRecord,
|
|
2483
|
+
destination_path: destinationDirectory,
|
|
2484
|
+
overwritten: destinationExists && !installInPlace,
|
|
2485
|
+
installed_in_place: installInPlace,
|
|
2486
|
+
activated: true,
|
|
2487
|
+
settings_changed: activationChanged
|
|
2488
|
+
});
|
|
2489
|
+
});
|
|
2490
|
+
} finally {
|
|
2491
|
+
if (resolvedSource.cleanup) {
|
|
2492
|
+
await resolvedSource.cleanup();
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
if (action === "adopt-all") {
|
|
2497
|
+
if (normalizedTarget !== void 0) {
|
|
2498
|
+
throw new PmCliError('Action "adopt-all" does not accept a target argument.', EXIT_CODE.USAGE);
|
|
2499
|
+
}
|
|
2500
|
+
const githubOption = resolveGithubOption(options);
|
|
2501
|
+
if (githubOption !== void 0 || typeof options.ref === "string" && options.ref.trim().length > 0) {
|
|
2502
|
+
throw new PmCliError('Action "adopt-all" does not accept --gh/--github/--ref options.', EXIT_CODE.USAGE);
|
|
2503
|
+
}
|
|
2504
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2505
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2506
|
+
warnings.push(...managedStateRead.warnings);
|
|
2507
|
+
const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
|
|
2508
|
+
warnings.push(...installed.warnings);
|
|
2509
|
+
const adoption = await adoptUnmanagedExtensions(resolvedRoots.selected_root, scope, installed.extensions, managedStateRead.state);
|
|
2510
|
+
const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, adoption.state);
|
|
2511
|
+
warnings.push(...refreshedInstalled.warnings);
|
|
2512
|
+
const triage = buildExtensionTriageSummary(scope, warnings, refreshedInstalled.extensions, options);
|
|
2513
|
+
warnings.push(...triage.warnings);
|
|
2514
|
+
const adoptedDetails = adoption.adopted_entries.map((entry) => {
|
|
2515
|
+
const refreshedEntry = refreshedInstalled.extensions.find((candidate) => normalizeExtensionNameForMatch(candidate.name) === normalizeExtensionNameForMatch(entry.name) && normalizeExtensionNameForMatch(candidate.directory) === normalizeExtensionNameForMatch(entry.directory)) ?? refreshedInstalled.extensions.find((candidate) => normalizeExtensionNameForMatch(candidate.directory) === normalizeExtensionNameForMatch(entry.directory));
|
|
2516
|
+
return {
|
|
2517
|
+
...entry,
|
|
2518
|
+
update_check_status: refreshedEntry?.update_check_status ?? null,
|
|
2519
|
+
update_check_reason: refreshedEntry?.update_check_reason ?? null
|
|
2520
|
+
};
|
|
2521
|
+
});
|
|
2522
|
+
return withResult({
|
|
2523
|
+
adopted_all: adoptedDetails.length > 0,
|
|
2524
|
+
adopted_count: adoptedDetails.length,
|
|
2525
|
+
already_managed_count: adoption.already_managed_count,
|
|
2526
|
+
extensions: adoptedDetails,
|
|
2527
|
+
triage,
|
|
2528
|
+
warning_codes: triage.warning_codes,
|
|
2529
|
+
update_health_partial: triage.update_health_partial,
|
|
2530
|
+
update_health_coverage: triage.update_health_coverage
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
if (action === "adopt") {
|
|
2534
|
+
const extensionTarget = requireTarget(normalizedTarget, action);
|
|
2535
|
+
const githubOption = resolveGithubOption(options);
|
|
2536
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2537
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2538
|
+
warnings.push(...managedStateRead.warnings);
|
|
2539
|
+
const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
|
|
2540
|
+
warnings.push(...installed.warnings);
|
|
2541
|
+
const candidate = await resolveInstalledExtensionCandidate(installed.extensions, extensionTarget);
|
|
2542
|
+
if (!candidate) {
|
|
2543
|
+
throw new PmCliError(`Installed extension "${extensionTarget}" was not found in ${scope} scope.`, EXIT_CODE.NOT_FOUND);
|
|
2544
|
+
}
|
|
2545
|
+
if (candidate.managed) {
|
|
2546
|
+
return withResult({
|
|
2547
|
+
adopted: false,
|
|
2548
|
+
already_managed: true,
|
|
2549
|
+
extension: {
|
|
2550
|
+
name: candidate.name,
|
|
2551
|
+
directory: candidate.directory
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
}
|
|
2555
|
+
const extensionDirectory = path7.join(resolvedRoots.selected_root, candidate.directory);
|
|
2556
|
+
const validated = await validateExtensionDirectory(extensionDirectory);
|
|
2557
|
+
const now = nowIso();
|
|
2558
|
+
const sourceRecord = githubOption === void 0 ? {
|
|
2559
|
+
kind: "local",
|
|
2560
|
+
input: extensionTarget,
|
|
2561
|
+
location: extensionDirectory
|
|
2562
|
+
} : (() => {
|
|
2563
|
+
const parsed = parseExtensionInstallSource(githubOption, {
|
|
2564
|
+
forceGithub: true,
|
|
2565
|
+
ref: options.ref
|
|
2566
|
+
});
|
|
2567
|
+
if (parsed.kind !== "github") {
|
|
2568
|
+
throw new PmCliError(`Invalid GitHub shorthand "${githubOption}".`, EXIT_CODE.USAGE);
|
|
2569
|
+
}
|
|
2570
|
+
return {
|
|
2571
|
+
kind: "github",
|
|
2572
|
+
input: parsed.input,
|
|
2573
|
+
location: parsed.subpath ?? ".",
|
|
2574
|
+
repository: parsed.repository,
|
|
2575
|
+
owner: parsed.owner,
|
|
2576
|
+
repo: parsed.repo,
|
|
2577
|
+
ref: parsed.ref,
|
|
2578
|
+
subpath: parsed.subpath
|
|
2579
|
+
};
|
|
2580
|
+
})();
|
|
2581
|
+
const managedState = upsertManagedEntry(managedStateRead.state, {
|
|
2582
|
+
name: validated.manifest.name,
|
|
2583
|
+
directory: candidate.directory,
|
|
2584
|
+
scope,
|
|
2585
|
+
manifest_version: validated.manifest.version,
|
|
2586
|
+
manifest_entry: validated.manifest.entry,
|
|
2587
|
+
capabilities: [...validated.manifest.capabilities],
|
|
2588
|
+
installed_at: now,
|
|
2589
|
+
updated_at: now,
|
|
2590
|
+
source: sourceRecord
|
|
2591
|
+
});
|
|
2592
|
+
await writeManagedExtensionState(resolvedRoots.selected_root, managedState);
|
|
2593
|
+
const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedState);
|
|
2594
|
+
warnings.push(...refreshedInstalled.warnings);
|
|
2595
|
+
const refreshedEntry = refreshedInstalled.extensions.find((entry) => normalizeExtensionNameForMatch(entry.name) === normalizeExtensionNameForMatch(validated.manifest.name)) ?? refreshedInstalled.extensions.find((entry) => normalizeExtensionNameForMatch(entry.directory) === normalizeExtensionNameForMatch(candidate.directory));
|
|
2596
|
+
return withResult({
|
|
2597
|
+
adopted: true,
|
|
2598
|
+
extension: {
|
|
2599
|
+
name: validated.manifest.name,
|
|
2600
|
+
directory: candidate.directory,
|
|
2601
|
+
version: validated.manifest.version,
|
|
2602
|
+
entry: validated.manifest.entry
|
|
2603
|
+
},
|
|
2604
|
+
source: sourceRecord,
|
|
2605
|
+
update_check_status: refreshedEntry?.update_check_status ?? null,
|
|
2606
|
+
update_check_reason: refreshedEntry?.update_check_reason ?? null
|
|
2607
|
+
});
|
|
2608
|
+
}
|
|
2609
|
+
if (action === "uninstall") {
|
|
2610
|
+
const extensionTarget = requireTarget(normalizedTarget, action);
|
|
2611
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2612
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2613
|
+
warnings.push(...managedStateRead.warnings);
|
|
2614
|
+
const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
|
|
2615
|
+
warnings.push(...installed.warnings);
|
|
2616
|
+
const candidate = await resolveInstalledExtensionCandidate(installed.extensions, extensionTarget);
|
|
2617
|
+
if (!candidate) {
|
|
2618
|
+
throw new PmCliError(`Installed extension "${extensionTarget}" was not found in ${scope} scope.`, EXIT_CODE.NOT_FOUND);
|
|
2619
|
+
}
|
|
2620
|
+
const destinationDirectory = path7.join(resolvedRoots.selected_root, candidate.directory);
|
|
2621
|
+
await fs7.rm(destinationDirectory, { recursive: true, force: true });
|
|
2622
|
+
const updatedState = {
|
|
2623
|
+
...managedStateRead.state,
|
|
2624
|
+
updated_at: nowIso(),
|
|
2625
|
+
entries: managedStateRead.state.entries.filter((entry) => normalizeExtensionNameForMatch(entry.name) !== normalizeExtensionNameForMatch(candidate.name) && normalizeExtensionNameForMatch(entry.directory) !== normalizeExtensionNameForMatch(candidate.directory))
|
|
2626
|
+
};
|
|
2627
|
+
await writeManagedExtensionState(resolvedRoots.selected_root, updatedState);
|
|
2628
|
+
const stateChanged = clearExtensionState(settings, candidate.name);
|
|
2629
|
+
if (stateChanged) {
|
|
2630
|
+
await writeSettings(resolvedRoots.settings_root, settings, "settings:write");
|
|
2631
|
+
}
|
|
2632
|
+
return withResult({
|
|
2633
|
+
removed: true,
|
|
2634
|
+
extension: {
|
|
2635
|
+
name: candidate.name,
|
|
2636
|
+
directory: candidate.directory
|
|
2637
|
+
},
|
|
2638
|
+
destination_path: destinationDirectory,
|
|
2639
|
+
settings_changed: stateChanged
|
|
2640
|
+
});
|
|
2641
|
+
}
|
|
2642
|
+
if (action === "activate" || action === "deactivate") {
|
|
2643
|
+
const extensionTarget = requireTarget(normalizedTarget, action);
|
|
2644
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2645
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2646
|
+
warnings.push(...managedStateRead.warnings);
|
|
2647
|
+
const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
|
|
2648
|
+
warnings.push(...installed.warnings);
|
|
2649
|
+
const candidate = await resolveInstalledExtensionCandidate(installed.extensions, extensionTarget);
|
|
2650
|
+
if (!candidate) {
|
|
2651
|
+
throw new PmCliError(`Installed extension "${extensionTarget}" was not found in ${scope} scope.`, EXIT_CODE.NOT_FOUND);
|
|
2652
|
+
}
|
|
2653
|
+
const settingsChanged = action === "activate" ? ensureActivated(settings, candidate.name) : ensureDeactivated(settings, candidate.name);
|
|
2654
|
+
if (settingsChanged) {
|
|
2655
|
+
await writeSettings(resolvedRoots.settings_root, settings, "settings:write");
|
|
2656
|
+
}
|
|
2657
|
+
return withResult({
|
|
2658
|
+
extension: {
|
|
2659
|
+
name: candidate.name,
|
|
2660
|
+
directory: candidate.directory
|
|
2661
|
+
},
|
|
2662
|
+
active: action === "activate",
|
|
2663
|
+
settings_changed: settingsChanged,
|
|
2664
|
+
settings: {
|
|
2665
|
+
enabled: [...settings.extensions.enabled],
|
|
2666
|
+
disabled: [...settings.extensions.disabled]
|
|
2667
|
+
}
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
if (action === "doctor") {
|
|
2671
|
+
if (normalizedTarget && normalizedTarget.trim().length > 0) {
|
|
2672
|
+
throw new PmCliError('Action "doctor" does not accept a target argument.', EXIT_CODE.USAGE);
|
|
2673
|
+
}
|
|
2674
|
+
const detailMode = parseDoctorDetailMode(options.detail);
|
|
2675
|
+
const includeTrace = options.trace === true;
|
|
2676
|
+
if (includeTrace && detailMode !== "deep") {
|
|
2677
|
+
throw new PmCliError("--trace requires --detail deep with --doctor.", EXIT_CODE.USAGE);
|
|
2678
|
+
}
|
|
2679
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2680
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2681
|
+
warnings.push(...managedStateRead.warnings);
|
|
2682
|
+
const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
|
|
2683
|
+
warnings.push(...installed.warnings);
|
|
2684
|
+
let managedState = managedStateRead.state;
|
|
2685
|
+
const managedStateFix = options.fixManagedState === true ? await adoptUnmanagedExtensions(resolvedRoots.selected_root, scope, installed.extensions, managedStateRead.state) : null;
|
|
2686
|
+
if (managedStateFix) {
|
|
2687
|
+
managedState = managedStateFix.state;
|
|
2688
|
+
}
|
|
2689
|
+
const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedState);
|
|
2690
|
+
warnings.push(...refreshedInstalled.warnings);
|
|
2691
|
+
const loadResult = await loadExtensions({
|
|
2692
|
+
pmRoot: resolvedRoots.pm_root,
|
|
2693
|
+
settings,
|
|
2694
|
+
cwd: process.cwd(),
|
|
2695
|
+
noExtensions: global.noExtensions === true
|
|
2696
|
+
});
|
|
2697
|
+
const activationResult = await activateExtensions({
|
|
2698
|
+
...loadResult,
|
|
2699
|
+
loaded: loadResult.loaded
|
|
2700
|
+
});
|
|
2701
|
+
warnings.push(...loadResult.warnings);
|
|
2702
|
+
warnings.push(...classifyDoctorLoadFailureWarnings(loadResult.failed));
|
|
2703
|
+
warnings.push(...activationResult.warnings);
|
|
2704
|
+
warnings.push(...classifyDoctorActivationFailureWarnings(activationResult.failed));
|
|
2705
|
+
warnings.push(...collectGlobalOutputOverrideDoctorWarnings(activationResult));
|
|
2706
|
+
const runtimeInstalledExtensions = applyDoctorRuntimeActivationState(refreshedInstalled.extensions, loadResult, activationResult);
|
|
2707
|
+
const doctorConsistency = buildDoctorConsistencySummary(scope, runtimeInstalledExtensions, loadResult.loaded.map((entry) => ({ layer: entry.layer, name: entry.name })), loadResult.failed.map((entry) => ({ name: entry.name })), loadResult.disabled_by_flag);
|
|
2708
|
+
warnings.push(...doctorConsistency.warnings);
|
|
2709
|
+
const updateCheckWarnings = runtimeInstalledExtensions.filter((entry) => entry.update_check_status === "failed").map((entry) => `extension_update_check_failed:${entry.name}`);
|
|
2710
|
+
warnings.push(...updateCheckWarnings);
|
|
2711
|
+
const triage = buildExtensionTriageSummary(scope, warnings, runtimeInstalledExtensions, options);
|
|
2712
|
+
warnings.push(...triage.warnings);
|
|
2713
|
+
const normalizedWarnings = [...triage.warnings];
|
|
2714
|
+
const policySummary = {
|
|
2715
|
+
mode: loadResult.policy.mode,
|
|
2716
|
+
trust_mode: loadResult.policy.trust_mode,
|
|
2717
|
+
require_provenance: loadResult.policy.require_provenance,
|
|
2718
|
+
default_sandbox_profile: loadResult.policy.default_sandbox_profile,
|
|
2719
|
+
trusted_extensions_count: loadResult.policy.trusted_extensions.length,
|
|
2720
|
+
allowed_extensions_count: loadResult.policy.allowed_extensions.length,
|
|
2721
|
+
blocked_extensions_count: loadResult.policy.blocked_extensions.length,
|
|
2722
|
+
allowed_capabilities_count: loadResult.policy.allowed_capabilities.length,
|
|
2723
|
+
blocked_capabilities_count: loadResult.policy.blocked_capabilities.length,
|
|
2724
|
+
allowed_surfaces_count: loadResult.policy.allowed_surfaces.length,
|
|
2725
|
+
blocked_surfaces_count: loadResult.policy.blocked_surfaces.length,
|
|
2726
|
+
allowed_commands_count: loadResult.policy.allowed_commands.length,
|
|
2727
|
+
blocked_commands_count: loadResult.policy.blocked_commands.length,
|
|
2728
|
+
allowed_actions_count: loadResult.policy.allowed_actions.length,
|
|
2729
|
+
blocked_actions_count: loadResult.policy.blocked_actions.length,
|
|
2730
|
+
allowed_services_count: loadResult.policy.allowed_services.length,
|
|
2731
|
+
blocked_services_count: loadResult.policy.blocked_services.length,
|
|
2732
|
+
extension_override_count: loadResult.policy.extension_overrides.length
|
|
2733
|
+
};
|
|
2734
|
+
const capabilityGuidance = collectUnknownCapabilityGuidance(normalizedWarnings);
|
|
2735
|
+
const capabilityContract = buildCapabilityContractMetadata();
|
|
2736
|
+
const warningCodes = triage.warning_codes;
|
|
2737
|
+
const remediation = [
|
|
2738
|
+
...new Set([
|
|
2739
|
+
...triage.remediation,
|
|
2740
|
+
...loadResult.failed.length > 0 ? [
|
|
2741
|
+
options.vocabulary === "package" ? "Run pm package explore --project and pm package explore --global to inspect load failures." : "Run pm extension --explore --project and pm extension --explore --global to inspect load failures."
|
|
2742
|
+
] : [],
|
|
2743
|
+
...activationResult.failed.length > 0 ? [
|
|
2744
|
+
options.vocabulary === "package" ? "Review activation failures in pm package doctor --detail deep output." : "Review activation failures in pm extension --doctor --detail deep output."
|
|
2745
|
+
] : [],
|
|
2746
|
+
...managedStateFix && managedStateFix.adopted_entries.length > 0 ? [`Managed-state fix adopted ${managedStateFix.adopted_entries.length} extension(s).`] : []
|
|
2747
|
+
].map((entry) => entry.trim()).filter((entry) => entry.length > 0))
|
|
2748
|
+
];
|
|
2749
|
+
const summary = {
|
|
2750
|
+
status: triage.status,
|
|
2751
|
+
scope,
|
|
2752
|
+
warning_count: triage.warning_count,
|
|
2753
|
+
warning_codes: warningCodes,
|
|
2754
|
+
total_extensions: runtimeInstalledExtensions.length,
|
|
2755
|
+
managed_total: runtimeInstalledExtensions.filter((entry) => entry.managed).length,
|
|
2756
|
+
enabled_total: runtimeInstalledExtensions.filter((entry) => entry.enabled).length,
|
|
2757
|
+
active_total: runtimeInstalledExtensions.filter((entry) => entry.active).length,
|
|
2758
|
+
unmanaged_loaded_extension_count: triage.unmanaged_loaded_extension_count,
|
|
2759
|
+
unmanaged_action_required_extension_count: triage.unmanaged_action_required_extension_count,
|
|
2760
|
+
unmanaged_expected_extension_count: triage.unmanaged_expected_extension_count,
|
|
2761
|
+
runtime_active_total: runtimeInstalledExtensions.filter((entry) => entry.runtime_active === true).length,
|
|
2762
|
+
activation_status_totals: {
|
|
2763
|
+
ok: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "ok").length,
|
|
2764
|
+
failed: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "failed").length,
|
|
2765
|
+
not_loaded: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "not_loaded").length,
|
|
2766
|
+
unknown: runtimeInstalledExtensions.filter((entry) => entry.activation_status === "unknown").length
|
|
2767
|
+
},
|
|
2768
|
+
unknown_capability_count: capabilityGuidance.length,
|
|
2769
|
+
capability_contract_version: capabilityContract.version,
|
|
2770
|
+
update_available_total: runtimeInstalledExtensions.filter((entry) => entry.update_available === true).length,
|
|
2771
|
+
update_health_coverage: triage.update_health_coverage,
|
|
2772
|
+
update_health_partial: triage.update_health_partial,
|
|
2773
|
+
update_check_failed_total: runtimeInstalledExtensions.filter((entry) => entry.update_check_status === "failed").length,
|
|
2774
|
+
load_failure_count: loadResult.failed.length,
|
|
2775
|
+
activation_failure_count: activationResult.failed.length,
|
|
2776
|
+
blocking_failure_count: loadResult.failed.length + activationResult.failed.length,
|
|
2777
|
+
has_blocking_failures: loadResult.failed.length + activationResult.failed.length > 0,
|
|
2778
|
+
consistency_warning_count: doctorConsistency.warnings.length,
|
|
2779
|
+
trace_enabled: includeTrace,
|
|
2780
|
+
policy: policySummary,
|
|
2781
|
+
remediation
|
|
2782
|
+
};
|
|
2783
|
+
const managedStateFixSummary = managedStateFix ? {
|
|
2784
|
+
requested: true,
|
|
2785
|
+
applied: managedStateFix.adopted_entries.length > 0,
|
|
2786
|
+
adopted_count: managedStateFix.adopted_entries.length,
|
|
2787
|
+
already_managed_count: managedStateFix.already_managed_count,
|
|
2788
|
+
adopted_extensions: managedStateFix.adopted_entries.map((entry) => entry.name)
|
|
2789
|
+
} : {
|
|
2790
|
+
requested: false,
|
|
2791
|
+
applied: false,
|
|
2792
|
+
adopted_count: 0,
|
|
2793
|
+
already_managed_count: refreshedInstalled.extensions.filter((entry) => entry.managed).length,
|
|
2794
|
+
adopted_extensions: []
|
|
2795
|
+
};
|
|
2796
|
+
const details = {
|
|
2797
|
+
mode: detailMode,
|
|
2798
|
+
summary,
|
|
2799
|
+
triage,
|
|
2800
|
+
trace_enabled: includeTrace,
|
|
2801
|
+
capability_contract: capabilityContract,
|
|
2802
|
+
capability_guidance: capabilityGuidance,
|
|
2803
|
+
managed_state_fix: managedStateFixSummary,
|
|
2804
|
+
policy: loadResult.policy
|
|
2805
|
+
};
|
|
2806
|
+
if (detailMode === "deep") {
|
|
2807
|
+
const activationFailedDetails = includeTrace ? activationResult.failed : activationResult.failed.map((entry) => {
|
|
2808
|
+
const { trace: _trace, ...rest } = entry;
|
|
2809
|
+
return rest;
|
|
2810
|
+
});
|
|
2811
|
+
details.deep = {
|
|
2812
|
+
warnings: normalizedWarnings,
|
|
2813
|
+
warning_codes: warningCodes,
|
|
2814
|
+
capability_contract: capabilityContract,
|
|
2815
|
+
capability_guidance: capabilityGuidance,
|
|
2816
|
+
trace_enabled: includeTrace,
|
|
2817
|
+
managed_state: {
|
|
2818
|
+
path: managedStateRead.path,
|
|
2819
|
+
count: managedState.entries.length,
|
|
2820
|
+
entries: managedState.entries
|
|
2821
|
+
},
|
|
2822
|
+
installed_extensions: runtimeInstalledExtensions,
|
|
2823
|
+
load: {
|
|
2824
|
+
roots: loadResult.roots,
|
|
2825
|
+
policy: loadResult.policy,
|
|
2826
|
+
warnings: loadResult.warnings,
|
|
2827
|
+
failed: loadResult.failed,
|
|
2828
|
+
loaded: loadResult.loaded.map((entry) => ({
|
|
2829
|
+
layer: entry.layer,
|
|
2830
|
+
directory: entry.directory,
|
|
2831
|
+
name: entry.name,
|
|
2832
|
+
version: entry.version,
|
|
2833
|
+
entry: entry.entry,
|
|
2834
|
+
priority: entry.priority
|
|
2835
|
+
}))
|
|
2836
|
+
},
|
|
2837
|
+
activation: {
|
|
2838
|
+
failed: activationFailedDetails,
|
|
2839
|
+
warnings: activationResult.warnings,
|
|
2840
|
+
hook_counts: activationResult.hook_counts,
|
|
2841
|
+
registration_counts: activationResult.registration_counts,
|
|
2842
|
+
parser_override_count: activationResult.parser_override_count,
|
|
2843
|
+
preflight_override_count: activationResult.preflight_override_count,
|
|
2844
|
+
service_override_count: activationResult.service_override_count,
|
|
2845
|
+
renderer_override_count: activationResult.renderer_override_count
|
|
2846
|
+
},
|
|
2847
|
+
consistency: doctorConsistency.summary
|
|
2848
|
+
};
|
|
2849
|
+
if (includeTrace) {
|
|
2850
|
+
details.deep.trace = {
|
|
2851
|
+
activation_failures: activationResult.failed.filter((entry) => entry.trace !== void 0).map((entry) => ({
|
|
2852
|
+
layer: entry.layer,
|
|
2853
|
+
name: entry.name,
|
|
2854
|
+
entry_path: entry.entry_path,
|
|
2855
|
+
error: entry.error,
|
|
2856
|
+
method: entry.trace?.method,
|
|
2857
|
+
command: entry.trace?.command,
|
|
2858
|
+
capability: entry.trace?.capability,
|
|
2859
|
+
missing_capability: entry.trace?.missing_capability,
|
|
2860
|
+
registration_index: entry.trace?.registration_index,
|
|
2861
|
+
expected_schema: entry.trace?.expected_schema,
|
|
2862
|
+
hint: entry.trace?.hint,
|
|
2863
|
+
received: entry.trace?.received
|
|
2864
|
+
}))
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
return withResult(details);
|
|
2869
|
+
}
|
|
2870
|
+
if (action === "explore" || action === "manage") {
|
|
2871
|
+
const settings = await readSettings(resolvedRoots.settings_root);
|
|
2872
|
+
const configuredPolicy = buildExtensionPolicyDetails(settings.extensions.policy);
|
|
2873
|
+
const managedStateRead = await readManagedExtensionState(resolvedRoots.selected_root);
|
|
2874
|
+
warnings.push(...managedStateRead.warnings);
|
|
2875
|
+
const installed = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedStateRead.state);
|
|
2876
|
+
warnings.push(...installed.warnings);
|
|
2877
|
+
let managedState = managedStateRead.state;
|
|
2878
|
+
const managedStateFix = action === "manage" && options.fixManagedState === true ? await adoptUnmanagedExtensions(resolvedRoots.selected_root, scope, installed.extensions, managedStateRead.state) : null;
|
|
2879
|
+
if (managedStateFix) {
|
|
2880
|
+
managedState = managedStateFix.state;
|
|
2881
|
+
}
|
|
2882
|
+
if (action === "manage") {
|
|
2883
|
+
const updates = await Promise.all(managedState.entries.map(async (entry) => {
|
|
2884
|
+
if (entry.source.kind !== "github") {
|
|
2885
|
+
return entry;
|
|
2886
|
+
}
|
|
2887
|
+
const updateStatus = await checkGithubUpdate(entry.source);
|
|
2888
|
+
return {
|
|
2889
|
+
...entry,
|
|
2890
|
+
last_update_check_at: updateStatus.checked_at,
|
|
2891
|
+
last_update_remote_commit: updateStatus.remote_commit,
|
|
2892
|
+
update_available: updateStatus.available,
|
|
2893
|
+
update_error: updateStatus.error
|
|
2894
|
+
};
|
|
2895
|
+
}));
|
|
2896
|
+
managedState = {
|
|
2897
|
+
...managedState,
|
|
2898
|
+
updated_at: nowIso(),
|
|
2899
|
+
entries: sortManagedEntries(updates)
|
|
2900
|
+
};
|
|
2901
|
+
await writeManagedExtensionState(resolvedRoots.selected_root, managedState);
|
|
2902
|
+
}
|
|
2903
|
+
const refreshedInstalled = await listInstalledExtensions(resolvedRoots.selected_root, scope, settings, managedState);
|
|
2904
|
+
warnings.push(...refreshedInstalled.warnings);
|
|
2905
|
+
if (action === "manage") {
|
|
2906
|
+
const updateWarnings = refreshedInstalled.extensions.filter((entry) => entry.update_check_status === "failed").map((entry) => `extension_update_check_failed:${entry.name}`);
|
|
2907
|
+
warnings.push(...updateWarnings);
|
|
2908
|
+
}
|
|
2909
|
+
let runtimeProbeSummary;
|
|
2910
|
+
let runtimeInstalledExtensions = refreshedInstalled.extensions;
|
|
2911
|
+
if (action === "explore" || options.runtimeProbe === true) {
|
|
2912
|
+
const loadResult = await loadExtensions({
|
|
2913
|
+
pmRoot: resolvedRoots.pm_root,
|
|
2914
|
+
settings,
|
|
2915
|
+
cwd: process.cwd(),
|
|
2916
|
+
noExtensions: global.noExtensions === true
|
|
2917
|
+
});
|
|
2918
|
+
const activationResult = await activateExtensions({
|
|
2919
|
+
...loadResult,
|
|
2920
|
+
loaded: loadResult.loaded
|
|
2921
|
+
});
|
|
2922
|
+
warnings.push(...loadResult.warnings);
|
|
2923
|
+
warnings.push(...activationResult.warnings);
|
|
2924
|
+
runtimeInstalledExtensions = applyDoctorRuntimeActivationState(refreshedInstalled.extensions, loadResult, activationResult);
|
|
2925
|
+
runtimeProbeSummary = {
|
|
2926
|
+
requested: true,
|
|
2927
|
+
executed: true,
|
|
2928
|
+
reason: action === "explore" ? "explore_defaults_to_runtime_probe" : "runtime_probe_requested",
|
|
2929
|
+
load_failure_count: loadResult.failed.length,
|
|
2930
|
+
activation_failure_count: activationResult.failed.length,
|
|
2931
|
+
warning_count: [.../* @__PURE__ */ new Set([...loadResult.warnings, ...activationResult.warnings])].length,
|
|
2932
|
+
policy: loadResult.policy
|
|
2933
|
+
};
|
|
2934
|
+
} else if (action === "manage") {
|
|
2935
|
+
runtimeProbeSummary = {
|
|
2936
|
+
requested: false,
|
|
2937
|
+
executed: false
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
const triage = buildExtensionTriageSummary(scope, warnings, runtimeInstalledExtensions, options);
|
|
2941
|
+
warnings.push(...triage.warnings);
|
|
2942
|
+
const details = {
|
|
2943
|
+
total: runtimeInstalledExtensions.length,
|
|
2944
|
+
managed_total: runtimeInstalledExtensions.filter((entry) => entry.managed).length,
|
|
2945
|
+
enabled_total: runtimeInstalledExtensions.filter((entry) => entry.enabled).length,
|
|
2946
|
+
active_total: runtimeInstalledExtensions.filter((entry) => entry.active).length,
|
|
2947
|
+
extensions: runtimeInstalledExtensions,
|
|
2948
|
+
triage,
|
|
2949
|
+
policy: configuredPolicy
|
|
2950
|
+
};
|
|
2951
|
+
if (action === "explore") {
|
|
2952
|
+
details.runtime_probe = runtimeProbeSummary;
|
|
2953
|
+
}
|
|
2954
|
+
if (action === "manage") {
|
|
2955
|
+
details.runtime_probe = runtimeProbeSummary;
|
|
2956
|
+
details.managed_state_fix = managedStateFix !== null ? {
|
|
2957
|
+
requested: true,
|
|
2958
|
+
applied: managedStateFix.adopted_entries.length > 0,
|
|
2959
|
+
adopted_count: managedStateFix.adopted_entries.length,
|
|
2960
|
+
adopted_extensions: managedStateFix.adopted_entries.map((entry) => entry.name),
|
|
2961
|
+
already_managed_count: managedStateFix.already_managed_count
|
|
2962
|
+
} : {
|
|
2963
|
+
requested: false,
|
|
2964
|
+
applied: false,
|
|
2965
|
+
adopted_count: 0,
|
|
2966
|
+
adopted_extensions: [],
|
|
2967
|
+
already_managed_count: runtimeInstalledExtensions.filter((entry) => entry.managed).length
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
return withResult(details);
|
|
2971
|
+
}
|
|
2972
|
+
throw new PmCliError(`Unsupported extension action "${action}".`, EXIT_CODE.USAGE);
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
export {
|
|
2976
|
+
parseExtensionManifest,
|
|
2977
|
+
validateExtensionDirectory,
|
|
2978
|
+
resolveManagedExtensionStatePath,
|
|
2979
|
+
readManagedExtensionState,
|
|
2980
|
+
writeManagedExtensionState,
|
|
2981
|
+
parseExtensionInstallSource,
|
|
2982
|
+
buildRegistrationCollisionRemediation,
|
|
2983
|
+
copyExtensionDirectoryForInstall,
|
|
2984
|
+
runExtension
|
|
2985
|
+
};
|
|
2986
|
+
//# sourceMappingURL=chunk-EHXPIKKP.js.map
|
|
2987
|
+
|
|
2988
|
+
//# debugId=e39bfbe4-484e-5544-affb-f1f6fbd63030
|