@unbrained/pm-cli 2026.7.20 → 2026.7.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +11 -0
- package/dist/cli/commander-usage.d.ts +1 -1
- package/dist/cli/commander-usage.js +5 -5
- package/dist/cli/commander-usage.js.map +1 -1
- package/dist/cli/commands/completion.js +13 -5
- package/dist/cli/commands/completion.js.map +1 -1
- package/dist/cli/commands/contracts.js +4 -3
- package/dist/cli/commands/contracts.js.map +1 -1
- package/dist/cli/error-guidance.d.ts +2 -0
- package/dist/cli/error-guidance.js +7 -2
- package/dist/cli/error-guidance.js.map +1 -1
- package/dist/cli/main.d.ts +1 -5
- package/dist/cli/main.js +12 -50
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/register-list-query.js +13 -3
- package/dist/cli/register-list-query.js.map +1 -1
- package/dist/cli/register-mutation.js +45 -3
- package/dist/cli/register-mutation.js.map +1 -1
- package/dist/cli/register-structured-mutation.d.ts +14 -0
- package/dist/cli/register-structured-mutation.js +62 -0
- package/dist/cli/register-structured-mutation.js.map +1 -0
- package/dist/cli/registration-helpers.js +5 -3
- package/dist/cli/registration-helpers.js.map +1 -1
- package/dist/cli-bundle/bundle-manifest.json +280 -296
- package/dist/cli-bundle/chunks/{append-E6V54WOQ.js → append-7OVFYR3C.js} +3 -3
- package/dist/cli-bundle/chunks/{append-NNJ3EFIT.js → append-DFETHAZL.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-C3KD7U3T.js → chunk-2L6ZP22J.js} +241 -10
- package/dist/cli-bundle/chunks/chunk-2L6ZP22J.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-KZEANWJS.js → chunk-4PUUNQDV.js} +98 -30
- package/dist/cli-bundle/chunks/chunk-4PUUNQDV.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-RDV4ZFYS.js → chunk-4QOB7L7I.js} +7 -9
- package/dist/cli-bundle/chunks/{chunk-RDV4ZFYS.js.map → chunk-4QOB7L7I.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-3LPFHE3P.js → chunk-4QSQ6XDK.js} +62 -20
- package/dist/cli-bundle/chunks/chunk-4QSQ6XDK.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-QJKL5PHS.js → chunk-7656MAUL.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-3AO5VSDR.js → chunk-7RW4JCU2.js} +328 -6
- package/dist/cli-bundle/chunks/chunk-7RW4JCU2.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-X6K5XTTN.js → chunk-7W2UAXXT.js} +5 -5
- package/dist/cli-bundle/chunks/{chunk-SSKOQNMS.js → chunk-ABWCF646.js} +9 -11
- package/dist/cli-bundle/chunks/{chunk-SSKOQNMS.js.map → chunk-ABWCF646.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-WVA4DVNV.js → chunk-ADBTSVGK.js} +71 -33
- package/dist/cli-bundle/chunks/chunk-ADBTSVGK.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-J4FBIFU6.js → chunk-AELMUANP.js} +12 -6
- package/dist/cli-bundle/chunks/chunk-AELMUANP.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-4F6BWJ4J.js → chunk-AMJPSANK.js} +57 -36
- package/dist/cli-bundle/chunks/chunk-AMJPSANK.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-6VIJ7UA5.js → chunk-AS4SAZ5R.js} +850 -819
- package/dist/cli-bundle/chunks/chunk-AS4SAZ5R.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-SG74J6MV.js → chunk-ATBCUC7Y.js} +574 -5
- package/dist/cli-bundle/chunks/chunk-ATBCUC7Y.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-5OK4UGFV.js → chunk-BXNDKOR2.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-KSPWRNVP.js → chunk-CPX275C6.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-JH2ZSLO3.js → chunk-DZRV2OPA.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-L7BH7IWU.js → chunk-E5XMKOSB.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-CQTQKUUV.js → chunk-EWJWSNRU.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-DAQ45GCS.js → chunk-F2LBF7XJ.js} +22 -15
- package/dist/cli-bundle/chunks/chunk-F2LBF7XJ.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-6XMUURSS.js → chunk-FJIFFBJX.js} +64 -33
- package/dist/cli-bundle/chunks/chunk-FJIFFBJX.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-E7ICD63T.js → chunk-FO6OSVEN.js} +4 -6
- package/dist/cli-bundle/chunks/{chunk-E7ICD63T.js.map → chunk-FO6OSVEN.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-3MCTMJXI.js → chunk-FPBMLYPI.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UZDQXNUB.js → chunk-FSE2IKJQ.js} +46 -5
- package/dist/cli-bundle/chunks/chunk-FSE2IKJQ.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-IX677TRO.js → chunk-GKX4NJ7U.js} +8 -10
- package/dist/cli-bundle/chunks/{chunk-IX677TRO.js.map → chunk-GKX4NJ7U.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-DVDBQA3B.js → chunk-GTK4DTEW.js} +5 -5
- package/dist/cli-bundle/chunks/chunk-H7EAER5L.js +974 -0
- package/dist/cli-bundle/chunks/chunk-H7EAER5L.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-5UX66S6U.js → chunk-ICDAQ4TD.js} +316 -8
- package/dist/cli-bundle/chunks/chunk-ICDAQ4TD.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-YQQNAKW3.js → chunk-JFD5LPMI.js} +6 -8
- package/dist/cli-bundle/chunks/{chunk-YQQNAKW3.js.map → chunk-JFD5LPMI.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-QANSTTC7.js → chunk-JXCW2TI2.js} +6 -8
- package/dist/cli-bundle/chunks/{chunk-QANSTTC7.js.map → chunk-JXCW2TI2.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-GSJSM5BJ.js → chunk-K36WV5J6.js} +76 -13
- package/dist/cli-bundle/chunks/chunk-K36WV5J6.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-GVI6FAFG.js → chunk-K55VMLSS.js} +7 -5
- package/dist/cli-bundle/chunks/chunk-K55VMLSS.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-GIQSU6S2.js → chunk-KBLZ3AA5.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-XJF7CDNH.js → chunk-KH44WBAT.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-GV2262OF.js → chunk-LAV26CQG.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-VDO2JMD4.js → chunk-LVC72YRD.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-3VY6MIEO.js → chunk-LZYP423P.js} +35 -6
- package/dist/cli-bundle/chunks/chunk-LZYP423P.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-ZYPFOO3L.js → chunk-MATHDCGG.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-OV7MSW3I.js → chunk-MWQ2HC2A.js} +99 -31
- package/dist/cli-bundle/chunks/chunk-MWQ2HC2A.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-NHT3F4WZ.js → chunk-NUF7ROFH.js} +840 -816
- package/dist/cli-bundle/chunks/chunk-NUF7ROFH.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-AOEOYL3S.js → chunk-O4BCOJTZ.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-RJO3YAFM.js → chunk-OCUBRA6D.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-5IZJWSDB.js → chunk-OG5DVFMA.js} +22 -15
- package/dist/cli-bundle/chunks/chunk-OG5DVFMA.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-I577UHC7.js → chunk-OR42SO64.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-ZOJ3LR7O.js → chunk-OY7DMU5P.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HEWM6CEN.js → chunk-P7MTHPJQ.js} +50 -9
- package/dist/cli-bundle/chunks/chunk-P7MTHPJQ.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-2BO4CA46.js → chunk-PFNHX655.js} +236 -12
- package/dist/cli-bundle/chunks/{chunk-2BO4CA46.js.map → chunk-PFNHX655.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-ZV2NTVMJ.js → chunk-PONKZPCJ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-THAOZG4U.js → chunk-PQSEQD6E.js} +8 -6
- package/dist/cli-bundle/chunks/chunk-PQSEQD6E.js.map +1 -0
- package/dist/cli-bundle/chunks/chunk-PWDEHT3L.js +991 -0
- package/dist/cli-bundle/chunks/chunk-PWDEHT3L.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-UX6SSO2I.js → chunk-PZC2FUOQ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-WUVEBQW6.js → chunk-QG4GFLQ6.js} +3 -5
- package/dist/cli-bundle/chunks/{chunk-WUVEBQW6.js.map → chunk-QG4GFLQ6.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-VQIHNHMJ.js → chunk-QIH77CAG.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-R3EWPG4A.js → chunk-QJIKE24M.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-QLZ643FM.js → chunk-QOOTOD3W.js} +10 -12
- package/dist/cli-bundle/chunks/{chunk-QLZ643FM.js.map → chunk-QOOTOD3W.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-MYSS5H2A.js → chunk-R3P6FZJW.js} +5 -7
- package/dist/cli-bundle/chunks/{chunk-MYSS5H2A.js.map → chunk-R3P6FZJW.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-G3COA6GS.js → chunk-RNPZYNHS.js} +56 -35
- package/dist/cli-bundle/chunks/chunk-RNPZYNHS.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-T44FMVRL.js → chunk-RPESLSO5.js} +62 -20
- package/dist/cli-bundle/chunks/chunk-RPESLSO5.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-INSTSQNZ.js → chunk-SY4SFZSD.js} +595 -3
- package/dist/cli-bundle/chunks/chunk-SY4SFZSD.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-HB3P4M52.js → chunk-TRSHFPRZ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HRW7GF6T.js → chunk-UCBDQI5E.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-4U4Z6AHI.js → chunk-V22ZPOKN.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-JM6YAXTR.js → chunk-VHXHVTUU.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-LPEYZRUR.js → chunk-VJQG4BIM.js} +35 -6
- package/dist/cli-bundle/chunks/chunk-VJQG4BIM.js.map +1 -0
- package/dist/cli-bundle/chunks/{chunk-D6NXDNP3.js → chunk-VLRGDBLY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-JAPE62Y5.js → chunk-VNTCM3VW.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-FDHPAVVB.js → chunk-VXOOB6YX.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-GFQP7HAZ.js → chunk-VZIZB6QH.js} +3 -5
- package/dist/cli-bundle/chunks/{chunk-GFQP7HAZ.js.map → chunk-VZIZB6QH.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-HQ3SB4CN.js → chunk-X3W65QK3.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-RZJLNXFG.js → chunk-XJTABV3X.js} +3 -3
- package/dist/cli-bundle/chunks/{chunk-GVT754PX.js → chunk-YCIUJJOD.js} +11 -5
- package/dist/cli-bundle/chunks/chunk-YCIUJJOD.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-IJNK6WW2.js → chunk-Z75ONV25.js} +75 -12
- package/dist/cli-bundle/chunks/chunk-Z75ONV25.js.map +7 -0
- package/dist/cli-bundle/chunks/{chunk-4L23AGQ7.js → chunk-Z7VWXXJM.js} +5 -7
- package/dist/cli-bundle/chunks/{chunk-4L23AGQ7.js.map → chunk-Z7VWXXJM.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-YBT7O4KT.js → chunk-ZTVA4KLN.js} +4 -6
- package/dist/cli-bundle/chunks/{chunk-YBT7O4KT.js.map → chunk-ZTVA4KLN.js.map} +1 -1
- package/dist/cli-bundle/chunks/{chunk-TYHJDFYW.js → chunk-ZVZGXPQ5.js} +2 -2
- package/dist/cli-bundle/chunks/{close-many-SDA426VT.js → close-many-5RZXVN4J.js} +5 -6
- package/dist/cli-bundle/chunks/{close-many-UTZANOCQ.js → close-many-RZVTUGBG.js} +5 -6
- package/dist/cli-bundle/chunks/{comments-LZN6FXXC.js → comments-TPU7QRBL.js} +4 -4
- package/dist/cli-bundle/chunks/{comments-VBQ345ND.js → comments-Z4KV6FU3.js} +4 -4
- package/dist/cli-bundle/chunks/{create-GG4RBCGC.js → create-EIFBIVNQ.js} +6 -6
- package/dist/cli-bundle/chunks/{create-JBC5KUW6.js → create-RGSPN5GD.js} +6 -6
- package/dist/cli-bundle/chunks/{deps-FI4O6NQS.js → deps-UH5EQQUY.js} +3 -3
- package/dist/cli-bundle/chunks/{deps-DELOO4TL.js → deps-YG7UF3VR.js} +3 -3
- package/dist/cli-bundle/chunks/{docs-6Z2MP526.js → docs-G32TK6XS.js} +4 -4
- package/dist/cli-bundle/chunks/{docs-2UYBP5D6.js → docs-JWWNRC27.js} +4 -4
- package/dist/cli-bundle/chunks/{files-HKEAN5MA.js → files-3H32UQ4K.js} +4 -4
- package/dist/cli-bundle/chunks/{files-HEUGSJZL.js → files-4ALMCSKB.js} +4 -4
- package/dist/cli-bundle/chunks/{history-compact-7NDVP3PT.js → history-compact-77BT2LUB.js} +3 -4
- package/dist/cli-bundle/chunks/{history-compact-65YVN5DB.js → history-compact-VCKGTX64.js} +3 -4
- package/dist/cli-bundle/chunks/{history-redact-7YBL4XSG.js → history-redact-LJPZPNFA.js} +2 -3
- package/dist/cli-bundle/chunks/{history-redact-IZGNJBU4.js → history-redact-PWTTJ3XS.js} +2 -3
- package/dist/cli-bundle/chunks/{history-repair-7M4PYQUH.js → history-repair-I7CBNCV3.js} +5 -6
- package/dist/cli-bundle/chunks/{history-repair-GNGETJLI.js → history-repair-YTDZRK5E.js} +5 -6
- package/dist/cli-bundle/chunks/{learnings-3YXDRWFT.js → learnings-CYNOICKR.js} +4 -4
- package/dist/cli-bundle/chunks/{learnings-ALC6IMNL.js → learnings-KTYW3AL7.js} +4 -4
- package/dist/cli-bundle/chunks/{notes-7JMLQ447.js → notes-FGO63FXL.js} +4 -4
- package/dist/cli-bundle/chunks/{notes-JFCLTC5C.js → notes-ZERD3KB2.js} +4 -4
- package/dist/cli-bundle/chunks/{plan-T3XB3WTK.js → plan-OFJUBIM5.js} +7 -7
- package/dist/cli-bundle/chunks/{plan-KOIPWVOZ.js → plan-SGCDDTYR.js} +7 -7
- package/dist/cli-bundle/chunks/{profile-OILJHKUW.js → profile-3THJPIQY.js} +4 -5
- package/dist/cli-bundle/chunks/{profile-RJXA7PGS.js → profile-XEZAMMBW.js} +4 -5
- package/dist/cli-bundle/chunks/{register-list-query-CFVG75P3.js → register-list-query-BR435Q2H.js} +19 -16
- package/dist/cli-bundle/chunks/register-list-query-BR435Q2H.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-list-query-E7UVY4TN.js → register-list-query-RWTWLOBE.js} +18 -15
- package/dist/cli-bundle/chunks/register-list-query-RWTWLOBE.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-mutation-IQ55E25C.js → register-mutation-HLWC2WNP.js} +167 -31
- package/dist/cli-bundle/chunks/register-mutation-HLWC2WNP.js.map +1 -0
- package/dist/cli-bundle/chunks/{register-mutation-4VJTXBZW.js → register-mutation-ZJX5AZM5.js} +173 -30
- package/dist/cli-bundle/chunks/register-mutation-ZJX5AZM5.js.map +7 -0
- package/dist/cli-bundle/chunks/{register-operations-AR7RMX4W.js → register-operations-744YBJMV.js} +23 -25
- package/dist/cli-bundle/chunks/{register-operations-AR7RMX4W.js.map → register-operations-744YBJMV.js.map} +1 -1
- package/dist/cli-bundle/chunks/{register-operations-NOLZGORC.js → register-operations-UEBJH6AN.js} +21 -23
- package/dist/cli-bundle/chunks/{register-operations-NOLZGORC.js.map → register-operations-UEBJH6AN.js.map} +1 -1
- package/dist/cli-bundle/chunks/{register-setup-EYZ7VTPZ.js → register-setup-5DA4UZXI.js} +7 -8
- package/dist/cli-bundle/chunks/{register-setup-EYZ7VTPZ.js.map → register-setup-5DA4UZXI.js.map} +1 -1
- package/dist/cli-bundle/chunks/{register-setup-BB77VUEE.js → register-setup-6H25M3BH.js} +9 -10
- package/dist/cli-bundle/chunks/{register-setup-BB77VUEE.js.map → register-setup-6H25M3BH.js.map} +1 -1
- package/dist/cli-bundle/chunks/{restore-ZH65GZFB.js → restore-6TDVSATY.js} +4 -5
- package/dist/cli-bundle/chunks/{restore-L6IAGOD7.js → restore-RSL7C7LO.js} +4 -5
- package/dist/cli-bundle/chunks/{schema-4ERWM5QJ.js → schema-HFXFSGPG.js} +2 -3
- package/dist/cli-bundle/chunks/{schema-55DL3Q52.js → schema-TPVTIJPO.js} +2 -3
- package/dist/cli-bundle/chunks/{update-FW6FKDOP.js → update-LJZCL5SI.js} +7 -7
- package/dist/cli-bundle/chunks/{update-TJHSPRPT.js → update-SIA7LH5Y.js} +7 -7
- package/dist/cli-bundle/chunks/{update-many-PWXX5WHO.js → update-many-BDBZVGQL.js} +11 -12
- package/dist/cli-bundle/chunks/{update-many-NNALYQCN.js → update-many-MOY3A5B3.js} +11 -12
- package/dist/cli-bundle/main.js +60 -85
- package/dist/cli-bundle/main.js.map +2 -2
- package/dist/cli-bundle/sdk-runtime.js +37 -37
- package/dist/cli-bundle/sdk.js +126 -291
- package/dist/cli-bundle/sdk.js.map +4 -4
- package/dist/core/item/parse.d.ts +1 -1
- package/dist/core/item/parse.js +13 -7
- package/dist/core/item/parse.js.map +1 -1
- package/dist/core/output/mutation-projection.d.ts +2 -0
- package/dist/core/output/mutation-projection.js +33 -2
- package/dist/core/output/mutation-projection.js.map +1 -1
- package/dist/core/output/output.d.ts +4 -0
- package/dist/core/output/output.js +18 -13
- package/dist/core/output/output.js.map +1 -1
- package/dist/core/shared/command-types.d.ts +4 -0
- package/dist/core/shared/command-types.js +2 -2
- package/dist/core/shared/command-types.js.map +1 -1
- package/dist/mcp/server.js +39 -4
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tool-definitions.js +45 -4
- package/dist/mcp/tool-definitions.js.map +1 -1
- package/dist/sdk/cli-bootstrap.d.ts +2 -0
- package/dist/sdk/cli-bootstrap.js +20 -27
- package/dist/sdk/cli-bootstrap.js.map +1 -1
- package/dist/sdk/cli-contracts/enum-contracts.d.ts +2 -2
- package/dist/sdk/cli-contracts/enum-contracts.js +7 -2
- package/dist/sdk/cli-contracts/enum-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
- package/dist/sdk/cli-contracts/flag-contracts.js +21 -2
- package/dist/sdk/cli-contracts/flag-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-option-contracts.js +10 -2
- package/dist/sdk/cli-contracts/tool-option-contracts.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-parameter-tables.js +16 -3
- package/dist/sdk/cli-contracts/tool-parameter-tables.js.map +1 -1
- package/dist/sdk/cli-contracts/tool-schema.js +6 -2
- package/dist/sdk/cli-contracts/tool-schema.js.map +1 -1
- package/dist/sdk/cli-contracts.d.ts +1 -1
- package/dist/sdk/cli-contracts.js +3 -3
- package/dist/sdk/cli-contracts.js.map +1 -1
- package/dist/sdk/cli-program.js +4 -2
- package/dist/sdk/cli-program.js.map +1 -1
- package/dist/sdk/dependencies.d.ts +3 -2
- package/dist/sdk/dependencies.js +13 -12
- package/dist/sdk/dependencies.js.map +1 -1
- package/dist/sdk/error-runtime.d.ts +10 -0
- package/dist/sdk/error-runtime.js +59 -0
- package/dist/sdk/error-runtime.js.map +1 -0
- package/dist/sdk/graph/analytics.d.ts +9 -0
- package/dist/sdk/graph/analytics.js +24 -13
- package/dist/sdk/graph/analytics.js.map +1 -1
- package/dist/sdk/graph/assembly.d.ts +39 -0
- package/dist/sdk/graph/assembly.js +92 -12
- package/dist/sdk/graph/assembly.js.map +1 -1
- package/dist/sdk/graph/cache.d.ts +4 -1
- package/dist/sdk/graph/cache.js +17 -4
- package/dist/sdk/graph/cache.js.map +1 -1
- package/dist/sdk/graph/centrality.d.ts +82 -0
- package/dist/sdk/graph/centrality.js +259 -0
- package/dist/sdk/graph/centrality.js.map +1 -0
- package/dist/sdk/graph/durable-cache.d.ts +71 -0
- package/dist/sdk/graph/durable-cache.js +205 -0
- package/dist/sdk/graph/durable-cache.js.map +1 -0
- package/dist/sdk/graph/governance.d.ts +69 -1
- package/dist/sdk/graph/governance.js +143 -35
- package/dist/sdk/graph/governance.js.map +1 -1
- package/dist/sdk/graph/index.d.ts +7 -4
- package/dist/sdk/graph/index.js +8 -5
- package/dist/sdk/graph/index.js.map +1 -1
- package/dist/sdk/graph/mutation-advisory.d.ts +35 -4
- package/dist/sdk/graph/mutation-advisory.js +124 -35
- package/dist/sdk/graph/mutation-advisory.js.map +1 -1
- package/dist/sdk/graph/remediation.js +12 -2
- package/dist/sdk/graph/remediation.js.map +1 -1
- package/dist/sdk/graph/run.d.ts +133 -2
- package/dist/sdk/graph/run.js +217 -8
- package/dist/sdk/graph/run.js.map +1 -1
- package/dist/sdk/graph/scheduling.d.ts +59 -0
- package/dist/sdk/graph/scheduling.js +125 -0
- package/dist/sdk/graph/scheduling.js.map +1 -0
- package/dist/sdk/graph/traversal.d.ts +11 -0
- package/dist/sdk/graph/traversal.js +16 -2
- package/dist/sdk/graph/traversal.js.map +1 -1
- package/dist/sdk/index.d.ts +4 -0
- package/dist/sdk/index.js +6 -2
- package/dist/sdk/index.js.map +1 -1
- package/dist/sdk/runtime-input.js +7 -2
- package/dist/sdk/runtime-input.js.map +1 -1
- package/dist/sdk/runtime-primitives.d.ts +10 -0
- package/dist/sdk/runtime-primitives.js +14 -0
- package/dist/sdk/runtime-primitives.js.map +1 -0
- package/dist/sdk/runtime.d.ts +15 -0
- package/dist/sdk/runtime.js +16 -3
- package/dist/sdk/runtime.js.map +1 -1
- package/dist/sdk/structured-mutations.d.ts +21 -0
- package/dist/sdk/structured-mutations.js +375 -0
- package/dist/sdk/structured-mutations.js.map +1 -0
- package/docs/COMMANDS.md +85 -5
- package/docs/RELATIONSHIP_GRAPH.md +48 -7
- package/docs/SDK.md +78 -3
- package/marketplace.json +2 -2
- package/package.json +1 -1
- package/packages/pm-beads/package.json +1 -1
- package/packages/pm-calendar/package.json +1 -1
- package/packages/pm-command-kit/package.json +1 -1
- package/packages/pm-governance-audit/package.json +1 -1
- package/packages/pm-guide-shell/package.json +1 -1
- package/packages/pm-kanban/package.json +1 -1
- package/packages/pm-lifecycle-hooks/package.json +1 -1
- package/packages/pm-linked-test-adapters/package.json +1 -1
- package/packages/pm-search-advanced/package.json +1 -1
- package/packages/pm-templates/package.json +1 -1
- package/packages/pm-todos/package.json +1 -1
- package/packages/pm-vcs/package.json +1 -1
- package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pm-claude/README.md +5 -3
- package/plugins/pm-claude/commands/pm-init.md +1 -1
- package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
- package/dist/cli-bundle/chunks/chunk-3AO5VSDR.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-3LPFHE3P.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-3VY6MIEO.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-4F6BWJ4J.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-5IZJWSDB.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-5UX66S6U.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-6C2ZZX5Z.js +0 -286
- package/dist/cli-bundle/chunks/chunk-6C2ZZX5Z.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-6VIJ7UA5.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-6XMUURSS.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-C3KD7U3T.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-CFHAODHQ.js +0 -334
- package/dist/cli-bundle/chunks/chunk-CFHAODHQ.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-DAQ45GCS.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-E6LEMURX.js +0 -249
- package/dist/cli-bundle/chunks/chunk-E6LEMURX.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-G3COA6GS.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-GSJSM5BJ.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-GVI6FAFG.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-GVT754PX.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-HEWM6CEN.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-IJNK6WW2.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-INSTSQNZ.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-J4FBIFU6.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-KZEANWJS.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-LPEYZRUR.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-NHT3F4WZ.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-OV7MSW3I.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-P7JTWYLH.js +0 -246
- package/dist/cli-bundle/chunks/chunk-P7JTWYLH.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-R5U2VZ3K.js +0 -344
- package/dist/cli-bundle/chunks/chunk-R5U2VZ3K.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-SG74J6MV.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-T44FMVRL.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-THAOZG4U.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-UQLXSG72.js +0 -289
- package/dist/cli-bundle/chunks/chunk-UQLXSG72.js.map +0 -7
- package/dist/cli-bundle/chunks/chunk-UZDQXNUB.js.map +0 -1
- package/dist/cli-bundle/chunks/chunk-WVA4DVNV.js.map +0 -7
- package/dist/cli-bundle/chunks/register-list-query-CFVG75P3.js.map +0 -1
- package/dist/cli-bundle/chunks/register-list-query-E7UVY4TN.js.map +0 -7
- package/dist/cli-bundle/chunks/register-mutation-4VJTXBZW.js.map +0 -7
- package/dist/cli-bundle/chunks/register-mutation-IQ55E25C.js.map +0 -1
- /package/dist/cli-bundle/chunks/{append-E6V54WOQ.js.map → append-7OVFYR3C.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{append-NNJ3EFIT.js.map → append-DFETHAZL.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-QJKL5PHS.js.map → chunk-7656MAUL.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-X6K5XTTN.js.map → chunk-7W2UAXXT.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-5OK4UGFV.js.map → chunk-BXNDKOR2.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-KSPWRNVP.js.map → chunk-CPX275C6.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-JH2ZSLO3.js.map → chunk-DZRV2OPA.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-L7BH7IWU.js.map → chunk-E5XMKOSB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-CQTQKUUV.js.map → chunk-EWJWSNRU.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-3MCTMJXI.js.map → chunk-FPBMLYPI.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-DVDBQA3B.js.map → chunk-GTK4DTEW.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-GIQSU6S2.js.map → chunk-KBLZ3AA5.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-XJF7CDNH.js.map → chunk-KH44WBAT.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-GV2262OF.js.map → chunk-LAV26CQG.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-VDO2JMD4.js.map → chunk-LVC72YRD.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-ZYPFOO3L.js.map → chunk-MATHDCGG.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-AOEOYL3S.js.map → chunk-O4BCOJTZ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-RJO3YAFM.js.map → chunk-OCUBRA6D.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-I577UHC7.js.map → chunk-OR42SO64.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-ZOJ3LR7O.js.map → chunk-OY7DMU5P.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-ZV2NTVMJ.js.map → chunk-PONKZPCJ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-UX6SSO2I.js.map → chunk-PZC2FUOQ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-VQIHNHMJ.js.map → chunk-QIH77CAG.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-R3EWPG4A.js.map → chunk-QJIKE24M.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-HB3P4M52.js.map → chunk-TRSHFPRZ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-HRW7GF6T.js.map → chunk-UCBDQI5E.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-4U4Z6AHI.js.map → chunk-V22ZPOKN.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-JM6YAXTR.js.map → chunk-VHXHVTUU.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-D6NXDNP3.js.map → chunk-VLRGDBLY.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-JAPE62Y5.js.map → chunk-VNTCM3VW.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-FDHPAVVB.js.map → chunk-VXOOB6YX.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-HQ3SB4CN.js.map → chunk-X3W65QK3.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-RZJLNXFG.js.map → chunk-XJTABV3X.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{chunk-TYHJDFYW.js.map → chunk-ZVZGXPQ5.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{close-many-SDA426VT.js.map → close-many-5RZXVN4J.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{close-many-UTZANOCQ.js.map → close-many-RZVTUGBG.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{comments-LZN6FXXC.js.map → comments-TPU7QRBL.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{comments-VBQ345ND.js.map → comments-Z4KV6FU3.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{create-GG4RBCGC.js.map → create-EIFBIVNQ.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{create-JBC5KUW6.js.map → create-RGSPN5GD.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{deps-FI4O6NQS.js.map → deps-UH5EQQUY.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{deps-DELOO4TL.js.map → deps-YG7UF3VR.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{docs-6Z2MP526.js.map → docs-G32TK6XS.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{docs-2UYBP5D6.js.map → docs-JWWNRC27.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{files-HKEAN5MA.js.map → files-3H32UQ4K.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{files-HEUGSJZL.js.map → files-4ALMCSKB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{history-compact-7NDVP3PT.js.map → history-compact-77BT2LUB.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{history-compact-65YVN5DB.js.map → history-compact-VCKGTX64.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{history-redact-7YBL4XSG.js.map → history-redact-LJPZPNFA.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{history-redact-IZGNJBU4.js.map → history-redact-PWTTJ3XS.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{history-repair-7M4PYQUH.js.map → history-repair-I7CBNCV3.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{history-repair-GNGETJLI.js.map → history-repair-YTDZRK5E.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{learnings-3YXDRWFT.js.map → learnings-CYNOICKR.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{learnings-ALC6IMNL.js.map → learnings-KTYW3AL7.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{notes-7JMLQ447.js.map → notes-FGO63FXL.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{notes-JFCLTC5C.js.map → notes-ZERD3KB2.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{plan-T3XB3WTK.js.map → plan-OFJUBIM5.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{plan-KOIPWVOZ.js.map → plan-SGCDDTYR.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{profile-OILJHKUW.js.map → profile-3THJPIQY.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{profile-RJXA7PGS.js.map → profile-XEZAMMBW.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{restore-ZH65GZFB.js.map → restore-6TDVSATY.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{restore-L6IAGOD7.js.map → restore-RSL7C7LO.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{schema-4ERWM5QJ.js.map → schema-HFXFSGPG.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{schema-55DL3Q52.js.map → schema-TPVTIJPO.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-FW6FKDOP.js.map → update-LJZCL5SI.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-TJHSPRPT.js.map → update-SIA7LH5Y.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-many-PWXX5WHO.js.map → update-many-BDBZVGQL.js.map} +0 -0
- /package/dist/cli-bundle/chunks/{update-many-NNALYQCN.js.map → update-many-MOY3A5B3.js.map} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../../sdk/merge/three-way.ts", "../../../../../../../../sdk/merge/driver.ts", "../../../../../../../../sdk/structured-mutations.ts", "../../../../../../../../sdk/item-transaction.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * @module sdk/merge/three-way\n *\n * Field-aware three-way merge primitives for every mergeable tracker artifact\n * class: append-only history JSONL streams, item documents (TOON or\n * JSON+Markdown), and key-level JSON configuration/schema files. These\n * primitives are pure (content in, content out) so the CLI merge driver, the\n * MCP surface, and package integrations all share one merge semantics\n * definition for multi-branch agent workflows.\n */\nimport {\n historyEntriesToRaw,\n reanchorHistoryEntries,\n} from \"../../core/history/replay.js\";\nimport {\n canonicalDocument,\n parseItemDocument,\n serializeItemDocument,\n type ItemDocumentFormatOptions,\n} from \"../../core/item/item-format.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport { findFirstMergeConflictMarker } from \"../../core/shared/conflict-markers.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { stableStringify } from \"../../core/shared/serialization.js\";\nimport { compareTimestampStrings } from \"../../core/shared/time.js\";\nimport type {\n HistoryEntry,\n ItemDocument,\n ItemMetadata,\n} from \"../../types/index.js\";\n\n/** Restricts which side of a three-way merge wins an unresolvable conflict. */\nexport type MergePreferredSide = \"ours\" | \"theirs\";\n\n/** Restricts the strategy labels reported by the history stream merge. */\nexport type HistoryMergeStrategy =\n | \"identical\"\n | \"fast_forward_ours\"\n | \"fast_forward_theirs\"\n | \"union_reanchor\";\n\n/** Documents the history stream merge result payload exchanged by command, SDK, and package integrations. */\nexport interface HistoryMergeResult {\n /** Merged JSONL content ready to be written as the resolved history stream. */\n merged: string;\n /** Strategy the merge used: identical inputs, one-sided fast-forward, or a deterministic union with a re-anchored hash chain. */\n strategy: HistoryMergeStrategy;\n /** Number of entries shared by both sides before their streams diverged. */\n common_entries: number;\n /** Number of divergent entries contributed by the ours side. */\n entries_from_ours: number;\n /** Number of divergent entries contributed by the theirs side. */\n entries_from_theirs: number;\n /** Total entries in the merged stream. */\n entries_total: number;\n /** Whether the merged chain required hash re-anchoring (true for every union merge). */\n reanchored: boolean;\n}\n\nfunction parseHistoryJsonl(raw: string, label: string): HistoryEntry[] {\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `History merge input (${label}) contains unresolved conflict markers at line ${conflictMarker.line}. Merge drivers must receive clean per-side versions.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n const entries: HistoryEntry[] = [];\n for (const [index, rawLine] of raw.split(/\\r?\\n/).entries()) {\n const line = rawLine.trim();\n if (!line) {\n continue;\n }\n try {\n const parsed = JSON.parse(line) as unknown;\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n throw new TypeError(\"history entry must be an object\");\n }\n entries.push(parsed as HistoryEntry);\n } catch {\n throw new PmCliError(\n `History merge input (${label}) contains invalid JSON at line ${index + 1}.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n }\n return entries;\n}\n\nfunction historyEntryIdentity(entry: HistoryEntry): string {\n return stableStringify({\n ts: entry.ts,\n author: entry.author,\n op: entry.op,\n patch: entry.patch,\n message: entry.message ?? null,\n });\n}\n\nfunction commonHistoryPrefixLength(\n ours: HistoryEntry[],\n theirs: HistoryEntry[],\n): number {\n const limit = Math.min(ours.length, theirs.length);\n let shared = 0;\n while (\n shared < limit &&\n historyEntryIdentity(ours[shared]) === historyEntryIdentity(theirs[shared])\n ) {\n shared += 1;\n }\n return shared;\n}\n\n/**\n * Deterministically merge two diverged versions of one append-only history\n * JSONL stream. Identical streams and one-sided fast-forwards keep the winning\n * side byte-for-byte; genuinely diverged streams are merged as the shared\n * prefix plus both suffixes ordered by timestamp (ours-first on ties), then\n * hash re-anchored so the resulting chain verifies again. No side's events are\n * ever discarded: content divergence is preserved for the post-merge\n * reconciliation pass (`pm validate` + `pm history-repair`) instead of being\n * silently resolved by last-writer-wins.\n */\nexport function mergeHistoryStreams(\n baseRaw: string,\n oursRaw: string,\n theirsRaw: string,\n): HistoryMergeResult {\n parseHistoryJsonl(baseRaw, \"base\");\n const ours = parseHistoryJsonl(oursRaw, \"ours\");\n const theirs = parseHistoryJsonl(theirsRaw, \"theirs\");\n const shared = commonHistoryPrefixLength(ours, theirs);\n\n if (shared === ours.length && shared === theirs.length) {\n return {\n merged: historyEntriesToRaw(ours),\n strategy: \"identical\",\n common_entries: shared,\n entries_from_ours: 0,\n entries_from_theirs: 0,\n entries_total: ours.length,\n reanchored: false,\n };\n }\n if (shared === theirs.length) {\n return {\n merged: historyEntriesToRaw(ours),\n strategy: \"fast_forward_ours\",\n common_entries: shared,\n entries_from_ours: ours.length - shared,\n entries_from_theirs: 0,\n entries_total: ours.length,\n reanchored: false,\n };\n }\n if (shared === ours.length) {\n return {\n merged: historyEntriesToRaw(theirs),\n strategy: \"fast_forward_theirs\",\n common_entries: shared,\n entries_from_ours: 0,\n entries_from_theirs: theirs.length - shared,\n entries_total: theirs.length,\n reanchored: false,\n };\n }\n\n const oursSuffix = ours.slice(shared);\n const seenIdentities = new Set(oursSuffix.map(historyEntryIdentity));\n const theirsSuffix = theirs\n .slice(shared)\n .filter((entry) => !seenIdentities.has(historyEntryIdentity(entry)));\n const mergedSuffix = [...oursSuffix, ...theirsSuffix].sort((left, right) => {\n const byTs = compareTimestampStrings(left.ts, right.ts);\n if (byTs !== 0) {\n return byTs;\n }\n const leftFromOurs = seenIdentities.has(historyEntryIdentity(left));\n const rightFromOurs = seenIdentities.has(historyEntryIdentity(right));\n if (leftFromOurs !== rightFromOurs) {\n return Number(rightFromOurs) - Number(leftFromOurs);\n }\n return historyEntryIdentity(left).localeCompare(historyEntryIdentity(right));\n });\n const reanchored = reanchorHistoryEntries([\n ...ours.slice(0, shared),\n ...mergedSuffix,\n ]);\n return {\n merged: historyEntriesToRaw(reanchored.entries),\n strategy: \"union_reanchor\",\n common_entries: shared,\n entries_from_ours: oursSuffix.length,\n entries_from_theirs: theirsSuffix.length,\n entries_total: reanchored.entries.length,\n reanchored: true,\n };\n}\n\n/** Documents the relationship event stream merge result payload exchanged by command, SDK, and package integrations. */\nexport interface RelationshipStreamMergeResult {\n /** Merged JSONL content with consecutively renumbered `sequence` values, ready to be written as the resolved event store. */\n merged: string;\n /** Strategy the merge used: identical inputs, one-sided fast-forward, or a deterministic union with renumbered sequences. */\n strategy: HistoryMergeStrategy;\n /** Number of events shared by both sides before their streams diverged. */\n common_entries: number;\n /** Number of divergent events contributed by the ours side. */\n entries_from_ours: number;\n /** Number of divergent events contributed by the theirs side. */\n entries_from_theirs: number;\n /** Total events in the merged stream. */\n entries_total: number;\n /** Whether merged events required sequence renumbering (true for every union merge). */\n reanchored: boolean;\n}\n\ninterface RelationshipStreamEvent {\n /** Globally unique event identity used for prefix detection and suffix deduplication. */\n eventId: string;\n /** One-based append sequence; rewritten consecutively in the merged stream. */\n sequence: number;\n /** ISO timestamp used to order divergent suffixes deterministically. */\n timestamp?: string;\n /** Remaining event payload fields, preserved verbatim. */\n [key: string]: unknown;\n}\n\nfunction parseRelationshipJsonl(\n raw: string,\n label: string,\n): RelationshipStreamEvent[] {\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `Relationship merge input (${label}) contains unresolved conflict markers at line ${conflictMarker.line}. Merge drivers must receive clean per-side versions.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n const events: RelationshipStreamEvent[] = [];\n for (const [index, rawLine] of raw.split(/\\r?\\n/).entries()) {\n const line = rawLine.trim();\n if (!line) {\n continue;\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(line) as unknown;\n } catch {\n throw new PmCliError(\n `Relationship merge input (${label}) contains invalid JSON at line ${index + 1}.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n Array.isArray(parsed) ||\n typeof (parsed as { eventId?: unknown }).eventId !== \"string\" ||\n typeof (parsed as { sequence?: unknown }).sequence !== \"number\"\n ) {\n throw new PmCliError(\n `Relationship merge input (${label}) line ${index + 1} is not a relationship event (eventId + sequence required).`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n events.push(parsed as RelationshipStreamEvent);\n }\n return events;\n}\n\nfunction relationshipEventsToRaw(events: RelationshipStreamEvent[]): string {\n return events.length === 0\n ? \"\"\n : `${events.map((event) => JSON.stringify(event)).join(\"\\n\")}\\n`;\n}\n\nfunction renumberRelationshipEvents(\n events: RelationshipStreamEvent[],\n): RelationshipStreamEvent[] {\n return events.map((event, index) => ({ ...event, sequence: index + 1 }));\n}\n\n/**\n * Deterministically merge two diverged versions of one append-only\n * relationship event JSONL store. The store's loader enforces strictly\n * consecutive one-based `sequence` values, so a plain text union of two\n * diverged streams is always unreadable; this merge keeps the shared prefix,\n * unions both divergent suffixes by `eventId` (ordered by event timestamp,\n * ours-first on ties), and renumbers every merged sequence consecutively so\n * the resulting stream loads again. No side's events are ever discarded.\n */\nexport function mergeRelationshipEventStreams(\n baseRaw: string,\n oursRaw: string,\n theirsRaw: string,\n): RelationshipStreamMergeResult {\n parseRelationshipJsonl(baseRaw, \"base\");\n const ours = parseRelationshipJsonl(oursRaw, \"ours\");\n const theirs = parseRelationshipJsonl(theirsRaw, \"theirs\");\n const limit = Math.min(ours.length, theirs.length);\n let shared = 0;\n while (shared < limit && ours[shared].eventId === theirs[shared].eventId) {\n shared += 1;\n }\n\n if (shared === ours.length && shared === theirs.length) {\n return {\n merged: relationshipEventsToRaw(ours),\n strategy: \"identical\",\n common_entries: shared,\n entries_from_ours: 0,\n entries_from_theirs: 0,\n entries_total: ours.length,\n reanchored: false,\n };\n }\n if (shared === theirs.length) {\n return {\n merged: relationshipEventsToRaw(ours),\n strategy: \"fast_forward_ours\",\n common_entries: shared,\n entries_from_ours: ours.length - shared,\n entries_from_theirs: 0,\n entries_total: ours.length,\n reanchored: false,\n };\n }\n if (shared === ours.length) {\n return {\n merged: relationshipEventsToRaw(theirs),\n strategy: \"fast_forward_theirs\",\n common_entries: shared,\n entries_from_ours: 0,\n entries_from_theirs: theirs.length - shared,\n entries_total: theirs.length,\n reanchored: false,\n };\n }\n\n const oursSuffix = ours.slice(shared);\n const oursEventIds = new Set(oursSuffix.map((event) => event.eventId));\n const theirsSuffix = theirs\n .slice(shared)\n .filter((event) => !oursEventIds.has(event.eventId));\n const mergedSuffix = [...oursSuffix, ...theirsSuffix].sort((left, right) => {\n if (left.timestamp !== undefined && right.timestamp !== undefined) {\n const byTs = compareTimestampStrings(left.timestamp, right.timestamp);\n if (byTs !== 0) {\n return byTs;\n }\n } else if (left.timestamp === undefined && right.timestamp !== undefined) {\n return 1;\n } else if (left.timestamp !== undefined) {\n return -1;\n }\n const leftFromOurs = oursEventIds.has(left.eventId);\n const rightFromOurs = oursEventIds.has(right.eventId);\n if (leftFromOurs !== rightFromOurs) {\n return Number(rightFromOurs) - Number(leftFromOurs);\n }\n // Array.prototype.sort is stable: returning zero preserves each side's\n // original append order when its events share a timestamp.\n return 0;\n });\n const merged = renumberRelationshipEvents([\n ...ours.slice(0, shared),\n ...mergedSuffix,\n ]);\n return {\n merged: relationshipEventsToRaw(merged),\n strategy: \"union_reanchor\",\n common_entries: shared,\n entries_from_ours: oursSuffix.length,\n entries_from_theirs: theirsSuffix.length,\n entries_total: merged.length,\n reanchored: true,\n };\n}\n\n/**\n * Item metadata collections merged by element-identity set semantics instead\n * of whole-field three-way comparison: concurrent commutative appends from two\n * branches (notes on A, tags on B, a test run on each) must merge cleanly.\n * Element identity is the stable serialization of the normalized element, so\n * an element edited on one side counts as remove-old + add-new and both sides'\n * contributions survive. Plan collections are deliberately excluded: plan\n * steps carry cross-element ordering invariants that set-union would corrupt,\n * so they stay under scalar three-way semantics with explicit conflicts.\n */\nexport const ITEM_UNION_COLLECTION_FIELDS = [\n \"tags\",\n \"dependencies\",\n \"comments\",\n \"notes\",\n \"learnings\",\n \"files\",\n \"tests\",\n \"test_runs\",\n \"docs\",\n \"reminders\",\n \"events\",\n] as const;\n\n/** Item metadata fields resolved by deterministic latest-timestamp-wins instead of three-way conflict, so disjoint-field edits never conflict on the shared freshness scalar every mutation rewrites. */\nexport const ITEM_LATEST_TIMESTAMP_FIELDS = [\"updated_at\"] as const;\n\n/** Documents the item document merge result payload exchanged by command, SDK, and package integrations. */\nexport interface ItemDocumentMergeResult {\n /** Serialized merged item document (always parseable; count headers recomputed by canonical serialization). */\n merged: string;\n /** Metadata fields (plus `body`) where both sides changed to different values; resolved toward the preferred side. */\n conflict_fields: string[];\n /** Fields taken from the theirs side by clean three-way resolution. */\n fields_from_theirs: string[];\n /** Collection fields that merged by element-identity union. */\n union_fields: string[];\n /** Which side unresolvable conflicts were resolved toward. */\n preferred: MergePreferredSide;\n}\n\nfunction jsonEquals(left: unknown, right: unknown): boolean {\n return stableStringify(left ?? null) === stableStringify(right ?? null);\n}\n\nfunction unionCollection(\n base: unknown,\n ours: unknown,\n theirs: unknown,\n): unknown[] {\n const toEntries = (value: unknown): unknown[] =>\n Array.isArray(value) ? value : [];\n const baseIds = new Set(toEntries(base).map((entry) => stableStringify(entry)));\n const oursEntries = toEntries(ours);\n const oursIds = new Set(oursEntries.map((entry) => stableStringify(entry)));\n const theirsEntries = toEntries(theirs);\n const theirsIds = new Set(\n theirsEntries.map((entry) => stableStringify(entry)),\n );\n const merged = oursEntries.filter((entry) => {\n const identity = stableStringify(entry);\n // An element kept by ours survives unless theirs deleted it (present in\n // base, absent from theirs).\n return !baseIds.has(identity) || theirsIds.has(identity);\n });\n for (const entry of theirsEntries) {\n const identity = stableStringify(entry);\n if (!oursIds.has(identity) && !baseIds.has(identity)) {\n merged.push(entry);\n }\n }\n return merged;\n}\n\nfunction latestTimestamp(ours: unknown, theirs: unknown): unknown {\n return compareTimestampStrings(String(ours), String(theirs)) >= 0\n ? ours\n : theirs;\n}\n\ninterface ScalarMergeOutcome {\n value: unknown;\n from_theirs: boolean;\n conflict: boolean;\n}\n\nfunction mergeScalarThreeWay(\n base: unknown,\n ours: unknown,\n theirs: unknown,\n preferred: MergePreferredSide,\n): ScalarMergeOutcome {\n if (jsonEquals(ours, theirs)) {\n return { value: ours, from_theirs: false, conflict: false };\n }\n if (jsonEquals(base, ours)) {\n return { value: theirs, from_theirs: true, conflict: false };\n }\n if (jsonEquals(base, theirs)) {\n return { value: ours, from_theirs: false, conflict: false };\n }\n return {\n value: preferred === \"theirs\" ? theirs : ours,\n from_theirs: preferred === \"theirs\",\n conflict: true,\n };\n}\n\nfunction toMetadataRecord(document: ItemDocument): Record<string, unknown> {\n return { ...(document.metadata as unknown as Record<string, unknown>) };\n}\n\nfunction parseItemMergeSide(\n raw: string,\n label: string,\n options: ItemDocumentFormatOptions,\n): ItemDocument {\n try {\n return canonicalDocument(parseItemDocument(raw, options), options);\n } catch (error) {\n throw new PmCliError(\n `Item merge input (${label}) is not a readable item document: ${String(error)}`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n}\n\ninterface ItemMetadataMergeAccumulator {\n /** Merged metadata values keyed by canonical field name. */\n merged: Record<string, unknown>;\n /** Scalar fields where both sides diverged from the base. */\n conflictFields: string[];\n /** Scalar fields cleanly selected from the other branch. */\n fieldsFromTheirs: string[];\n /** Collection fields whose final union differs from ours. */\n unionFields: string[];\n}\n\nfunction mergeItemMetadataRecords(\n baseRecord: Record<string, unknown>,\n oursRecord: Record<string, unknown>,\n theirsRecord: Record<string, unknown>,\n preferred: MergePreferredSide,\n): ItemMetadataMergeAccumulator {\n const unionFieldSet = new Set<string>(ITEM_UNION_COLLECTION_FIELDS);\n const latestFieldSet = new Set<string>(ITEM_LATEST_TIMESTAMP_FIELDS);\n const fieldNames = [\n ...new Set([...Object.keys(oursRecord), ...Object.keys(theirsRecord)]),\n ].sort((left, right) => left.localeCompare(right));\n const accumulator: ItemMetadataMergeAccumulator = {\n merged: {},\n conflictFields: [],\n fieldsFromTheirs: [],\n unionFields: [],\n };\n\n for (const field of fieldNames) {\n const baseValue = baseRecord[field];\n const oursValue = oursRecord[field];\n const theirsValue = theirsRecord[field];\n if (unionFieldSet.has(field)) {\n const union = unionCollection(baseValue, oursValue, theirsValue);\n // `fieldNames` is derived from both records' own keys, so a collection\n // reached here is declared by at least one side. Preserve even an empty\n // result (`tags` is required) so serialization never drops it.\n accumulator.merged[field] = union;\n if (!jsonEquals(union, oursValue)) {\n accumulator.unionFields.push(field);\n }\n continue;\n }\n if (latestFieldSet.has(field)) {\n accumulator.merged[field] = latestTimestamp(oursValue, theirsValue);\n continue;\n }\n const outcome = mergeScalarThreeWay(\n baseValue,\n oursValue,\n theirsValue,\n preferred,\n );\n if (outcome.value !== undefined) {\n accumulator.merged[field] = outcome.value;\n }\n if (outcome.conflict) {\n accumulator.conflictFields.push(field);\n } else if (outcome.from_theirs) {\n accumulator.fieldsFromTheirs.push(field);\n }\n }\n return accumulator;\n}\n\n/**\n * Field-aware three-way merge of one tracker item document. Commutative\n * collections (notes, tags, tests, ...) union by element identity so\n * concurrent appends never conflict; `updated_at` resolves to the latest\n * timestamp so disjoint-field edits never collide on the shared freshness\n * scalar; every other metadata field and the body use classic three-way\n * resolution. Unresolvable both-sides-changed conflicts are resolved toward\n * the preferred side but reported in `conflict_fields`, and the merged output\n * is always canonically serialized — count-prefixed TOON array headers are\n * recomputed, so the hand-resolution corruption class (stale `notes[N]`\n * headers) cannot be produced by this merge.\n */\nexport function mergeItemDocuments(\n baseRaw: string,\n oursRaw: string,\n theirsRaw: string,\n options: ItemDocumentFormatOptions & {\n /** Side that wins unresolvable conflicts (default \"ours\"). */\n preferred?: MergePreferredSide;\n } = {},\n): ItemDocumentMergeResult {\n const preferred: MergePreferredSide = options.preferred ?? \"ours\";\n // An empty base means both branches created the file independently\n // (add/add); three-way falls back to treating every differing field as an\n // ours/theirs decision, which the scalar resolver already models.\n const hasBase = baseRaw.trim().length > 0;\n const ours = parseItemMergeSide(oursRaw, \"ours\", options);\n const theirs = parseItemMergeSide(theirsRaw, \"theirs\", options);\n const base = hasBase ? parseItemMergeSide(baseRaw, \"base\", options) : ours;\n\n const baseRecord = hasBase\n ? toMetadataRecord(base)\n : ({} as Record<string, unknown>);\n const oursRecord = toMetadataRecord(ours);\n const theirsRecord = toMetadataRecord(theirs);\n const { merged, conflictFields, fieldsFromTheirs, unionFields } =\n mergeItemMetadataRecords(baseRecord, oursRecord, theirsRecord, preferred);\n\n const bodyOutcome = mergeScalarThreeWay(\n hasBase ? base.body : \"\",\n ours.body,\n theirs.body,\n preferred,\n );\n if (bodyOutcome.conflict) {\n conflictFields.push(\"body\");\n } else if (bodyOutcome.from_theirs) {\n fieldsFromTheirs.push(\"body\");\n }\n\n const mergedRaw = serializeItemDocument(\n {\n metadata: merged as unknown as ItemMetadata,\n body: bodyOutcome.value as string,\n },\n options,\n );\n return {\n merged: mergedRaw,\n conflict_fields: conflictFields,\n fields_from_theirs: fieldsFromTheirs,\n union_fields: unionFields,\n preferred,\n };\n}\n\n/** Documents the JSON document merge result payload exchanged by command, SDK, and package integrations. */\nexport interface JsonDocumentMergeResult {\n /** Serialized merged JSON document (two-space indent, trailing newline — the tracker's canonical config style). */\n merged: string;\n /** Dotted key paths where both sides changed to different values; resolved toward the preferred side. */\n conflict_paths: string[];\n /** Dotted key paths taken from the theirs side by clean three-way resolution. */\n paths_from_theirs: string[];\n /** Which side unresolvable conflicts were resolved toward. */\n preferred: MergePreferredSide;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value)\n );\n}\n\nfunction parseJsonSide(raw: string, label: string): unknown {\n const conflictMarker = findFirstMergeConflictMarker(raw);\n if (conflictMarker) {\n throw new PmCliError(\n `JSON merge input (${label}) contains unresolved conflict markers at line ${conflictMarker.line}.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n if (raw.trim().length === 0) {\n return undefined;\n }\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n throw new PmCliError(\n `JSON merge input (${label}) is not valid JSON.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n}\n\nfunction mergeJsonValue(\n base: unknown,\n ours: unknown,\n theirs: unknown,\n preferred: MergePreferredSide,\n pathPrefix: string,\n conflictPaths: string[],\n pathsFromTheirs: string[],\n): unknown {\n if (jsonEquals(ours, theirs)) {\n return ours;\n }\n if (isPlainObject(ours) && isPlainObject(theirs)) {\n const baseObject = isPlainObject(base) ? base : {};\n const merged: Record<string, unknown> = {};\n const keys = [\n ...new Set([...Object.keys(ours), ...Object.keys(theirs)]),\n ].sort((left, right) => left.localeCompare(right));\n for (const key of keys) {\n const childPath = pathPrefix.length > 0 ? `${pathPrefix}.${key}` : key;\n const child = mergeJsonKey(\n baseObject,\n ours,\n theirs,\n key,\n preferred,\n childPath,\n conflictPaths,\n pathsFromTheirs,\n );\n if (child !== undefined) {\n merged[key] = child;\n }\n }\n return merged;\n }\n const outcome = mergeScalarThreeWay(base, ours, theirs, preferred);\n if (outcome.conflict) {\n conflictPaths.push(pathPrefix);\n } else if (outcome.from_theirs) {\n pathsFromTheirs.push(pathPrefix);\n }\n return outcome.value;\n}\n\nfunction mergeJsonKey(\n base: Record<string, unknown>,\n ours: Record<string, unknown>,\n theirs: Record<string, unknown>,\n key: string,\n preferred: MergePreferredSide,\n childPath: string,\n conflictPaths: string[],\n pathsFromTheirs: string[],\n): unknown {\n const inOurs = Object.prototype.hasOwnProperty.call(ours, key);\n const inTheirs = Object.prototype.hasOwnProperty.call(theirs, key);\n const inBase = Object.prototype.hasOwnProperty.call(base, key);\n if (inOurs && inTheirs) {\n return mergeJsonValue(\n base[key],\n ours[key],\n theirs[key],\n preferred,\n childPath,\n conflictPaths,\n pathsFromTheirs,\n );\n }\n if (inOurs) {\n // Present only in ours: either ours added it (keep) or theirs deleted it\n // (honor the delete when ours left it untouched from base).\n if (inBase && jsonEquals(base[key], ours[key])) {\n pathsFromTheirs.push(childPath);\n return undefined;\n }\n if (inBase) {\n conflictPaths.push(childPath);\n return preferred === \"theirs\" ? undefined : ours[key];\n }\n return ours[key];\n }\n // Present only in theirs (mirror of the branch above).\n if (inBase && jsonEquals(base[key], theirs[key])) {\n return undefined;\n }\n if (inBase) {\n conflictPaths.push(childPath);\n return preferred === \"theirs\" ? theirs[key] : undefined;\n }\n pathsFromTheirs.push(childPath);\n return theirs[key];\n}\n\n/**\n * Key-level three-way merge for the tracker's single-file JSON configuration\n * artifacts (`settings.json`, `schema/*.json`). Nested objects merge\n * recursively per key so two branches editing disjoint settings never\n * conflict; both-sides-changed leaf values resolve toward the preferred side\n * and are reported in `conflict_paths`. The output is always valid JSON, so a\n * merged configuration can never regress into the silent-defaults fallback\n * that raw conflict markers cause.\n */\nexport function mergeJsonDocuments(\n baseRaw: string,\n oursRaw: string,\n theirsRaw: string,\n options: {\n /** Side that wins unresolvable conflicts (default \"ours\"). */\n preferred?: MergePreferredSide;\n } = {},\n): JsonDocumentMergeResult {\n const preferred: MergePreferredSide = options.preferred ?? \"ours\";\n const base = parseJsonSide(baseRaw, \"base\");\n const ours = parseJsonSide(oursRaw, \"ours\");\n const theirs = parseJsonSide(theirsRaw, \"theirs\");\n const conflictPaths: string[] = [];\n const pathsFromTheirs: string[] = [];\n const merged = mergeJsonValue(\n base,\n ours,\n theirs,\n preferred,\n \"\",\n conflictPaths,\n pathsFromTheirs,\n );\n return {\n merged: `${JSON.stringify(merged ?? null, null, 2)}\\n`,\n conflict_paths: conflictPaths,\n paths_from_theirs: pathsFromTheirs,\n preferred,\n };\n}\n", "/**\n * @module sdk/merge/driver\n *\n * File-level git merge driver runner for tracker artifacts. Git invokes the\n * driver with the base (%O), ours (%A), and theirs (%B) temporary files; the\n * driver writes the merged content back to the ours path and reports whether\n * unresolvable conflicts remain. Conflicted artifacts are still written as\n * parseable documents (resolved toward the preferred side) so a conflicted\n * merge never corrupts tracker storage the way raw conflict markers do.\n */\nimport { readFile, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { getActiveExtensionRegistrations } from \"../../core/extensions/index.js\";\nimport { collectRegisteredItemFieldNames } from \"../../core/extensions/item-fields.js\";\nimport { pathExists } from \"../../core/fs/fs-utils.js\";\nimport { EXIT_CODE } from \"../../core/shared/constants.js\";\nimport type { GlobalOptions } from \"../../core/shared/command-types.js\";\nimport { PmCliError } from \"../../core/shared/errors.js\";\nimport { nowIso } from \"../../core/shared/time.js\";\nimport { getSettingsPath, resolvePmRoot } from \"../../core/store/paths.js\";\nimport { readSettings } from \"../../core/store/settings.js\";\nimport type { ItemFormat, PmSettings } from \"../../types/index.js\";\nimport {\n mergeHistoryStreams,\n mergeItemDocuments,\n mergeJsonDocuments,\n mergeRelationshipEventStreams,\n type MergePreferredSide,\n} from \"./three-way.js\";\n\n/** Supported values accepted by the merge driver artifact contract across CLI, SDK, and MCP surfaces. */\nexport const MERGE_DRIVER_ARTIFACT_VALUES = [\n \"item\",\n \"history\",\n \"relationship\",\n \"json\",\n] as const;\n/** Restricts merge driver artifact values accepted by command, SDK, and storage contracts. */\nexport type MergeDriverArtifact = (typeof MERGE_DRIVER_ARTIFACT_VALUES)[number];\n\n/** Documents the merge driver options payload exchanged by command, SDK, and package integrations. */\nexport interface MergeDriverOptions {\n /** Artifact class being merged: item document, history JSONL stream, relationship event JSONL store, or key-level JSON config. */\n artifact: string;\n /** Path to the common-ancestor version (git %O). */\n basePath: string;\n /** Path to the current-branch version (git %A); also the default output path per the git merge-driver protocol. */\n oursPath: string;\n /** Path to the other-branch version (git %B). */\n theirsPath: string;\n /** Optional explicit output path overriding the git default of writing to the ours path. */\n outputPath?: string;\n /** Original repository-relative item path supplied by Git as `%P`, used to detect item format when temporary side paths lack extensions. */\n itemPath?: string;\n /** Side that wins unresolvable conflicts (default \"ours\"). */\n prefer?: string;\n}\n\n/** Documents the merge driver result payload exchanged by command, SDK, and package integrations. */\nexport interface MergeDriverResult {\n /** Whether the merge completed without unresolvable conflicts. */\n ok: boolean;\n /** Artifact class that was merged. */\n artifact: MergeDriverArtifact;\n /** Path the merged content was written to. */\n output_path: string;\n /** Side unresolvable conflicts were resolved toward. */\n preferred: MergePreferredSide;\n /** Unresolvable conflict labels: metadata field names (item), dotted key paths (json). Empty for history merges. */\n conflicts: string[];\n /** History-merge strategy and entry accounting; present only for the history artifact. */\n history?: {\n strategy: string;\n common_entries: number;\n entries_from_ours: number;\n entries_from_theirs: number;\n entries_total: number;\n reanchored: boolean;\n };\n /** Relationship-event-merge strategy and accounting; present only for the relationship artifact. */\n relationship?: {\n strategy: string;\n common_entries: number;\n entries_from_ours: number;\n entries_from_theirs: number;\n entries_total: number;\n reanchored: boolean;\n };\n /** Item-merge field accounting; present only for the item artifact. */\n item?: {\n fields_from_theirs: string[];\n union_fields: string[];\n };\n /** JSON-merge key accounting; present only for the json artifact. */\n json?: {\n paths_from_theirs: string[];\n };\n /** Guidance for resolving remaining conflicts or verifying the merged workspace. */\n guidance: string[];\n /** ISO 8601 timestamp recording when generated occurred. */\n generated_at: string;\n}\n\nfunction resolveArtifact(value: string): MergeDriverArtifact {\n const normalized = value.trim().toLowerCase();\n if (\n (MERGE_DRIVER_ARTIFACT_VALUES as readonly string[]).includes(normalized)\n ) {\n return normalized as MergeDriverArtifact;\n }\n throw new PmCliError(\n `Unknown merge artifact \"${value}\". Supported values: ${MERGE_DRIVER_ARTIFACT_VALUES.join(\", \")}.`,\n EXIT_CODE.USAGE,\n );\n}\n\nfunction resolvePreferredSide(value: string | undefined): MergePreferredSide {\n if (value === undefined) {\n return \"ours\";\n }\n const normalized = value.trim().toLowerCase();\n if (normalized === \"ours\" || normalized === \"theirs\") {\n return normalized;\n }\n throw new PmCliError(\n `Unknown --prefer value \"${value}\". Supported values: ours, theirs.`,\n EXIT_CODE.USAGE,\n );\n}\n\nasync function readSideFile(filePath: string, label: string): Promise<string> {\n try {\n return await readFile(filePath, \"utf8\");\n } catch {\n throw new PmCliError(\n `Cannot read merge ${label} file at ${filePath}.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n}\n\n/**\n * Load the workspace settings when a tracker is initialized at the resolved pm\n * root, or fall back to format defaults when the driver runs outside a tracker\n * (git can invoke merge drivers before `pm init`, e.g. while rebasing the\n * commit that introduces the tracker).\n */\nasync function loadOptionalSettings(\n global: GlobalOptions,\n): Promise<PmSettings | null> {\n const pmRoot = resolvePmRoot(process.cwd(), global.path);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n return null;\n }\n return readSettings(pmRoot);\n}\n\nfunction itemFormatForPath(\n filePath: string,\n settings: PmSettings | null,\n): ItemFormat {\n if (filePath.endsWith(\".md\")) {\n return \"json_markdown\";\n }\n if (filePath.endsWith(\".toon\")) {\n return \"toon\";\n }\n return settings?.item_format ?? \"toon\";\n}\n\n/**\n * Execute one git merge-driver invocation for a tracker artifact. Reads the\n * three per-side versions, applies the artifact's field-aware merge semantics,\n * writes the merged content (parseable even when conflicted) to the output\n * path, and reports remaining conflicts so the CLI can exit non-zero and let\n * git mark the path unmerged.\n */\nexport async function runMergeDriver(\n options: MergeDriverOptions,\n global: GlobalOptions,\n): Promise<MergeDriverResult> {\n const artifact = resolveArtifact(options.artifact);\n const preferred = resolvePreferredSide(options.prefer);\n const outputPath = path.resolve(options.outputPath ?? options.oursPath);\n const [baseRaw, oursRaw, theirsRaw] = await Promise.all([\n readSideFile(options.basePath, \"base\"),\n readSideFile(options.oursPath, \"ours\"),\n readSideFile(options.theirsPath, \"theirs\"),\n ]);\n\n let merged: string;\n const conflicts: string[] = [];\n const result: Partial<MergeDriverResult> = {};\n if (artifact === \"history\") {\n const historyMerge = mergeHistoryStreams(baseRaw, oursRaw, theirsRaw);\n merged = historyMerge.merged;\n result.history = {\n strategy: historyMerge.strategy,\n common_entries: historyMerge.common_entries,\n entries_from_ours: historyMerge.entries_from_ours,\n entries_from_theirs: historyMerge.entries_from_theirs,\n entries_total: historyMerge.entries_total,\n reanchored: historyMerge.reanchored,\n };\n } else if (artifact === \"relationship\") {\n const relationshipMerge = mergeRelationshipEventStreams(\n baseRaw,\n oursRaw,\n theirsRaw,\n );\n merged = relationshipMerge.merged;\n result.relationship = {\n strategy: relationshipMerge.strategy,\n common_entries: relationshipMerge.common_entries,\n entries_from_ours: relationshipMerge.entries_from_ours,\n entries_from_theirs: relationshipMerge.entries_from_theirs,\n entries_total: relationshipMerge.entries_total,\n reanchored: relationshipMerge.reanchored,\n };\n } else if (artifact === \"item\") {\n const settings = await loadOptionalSettings(global);\n const itemMerge = mergeItemDocuments(baseRaw, oursRaw, theirsRaw, {\n format: itemFormatForPath(options.itemPath ?? outputPath, settings),\n schema: settings?.schema,\n extensionFieldNames: collectRegisteredItemFieldNames(\n getActiveExtensionRegistrations(),\n ),\n preferred,\n });\n merged = itemMerge.merged;\n conflicts.push(...itemMerge.conflict_fields);\n result.item = {\n fields_from_theirs: itemMerge.fields_from_theirs,\n union_fields: itemMerge.union_fields,\n };\n } else {\n const jsonMerge = mergeJsonDocuments(baseRaw, oursRaw, theirsRaw, {\n preferred,\n });\n merged = jsonMerge.merged;\n conflicts.push(...jsonMerge.conflict_paths);\n result.json = {\n paths_from_theirs: jsonMerge.paths_from_theirs,\n };\n }\n\n await writeFile(outputPath, merged, \"utf8\");\n const guidance: string[] = [];\n if (conflicts.length > 0) {\n guidance.push(\n `Both branches changed ${conflicts.join(\", \")}; the ${preferred} value was kept. Review the merged file, re-apply the losing change if needed, then \"git add\" it.`,\n );\n }\n if (artifact === \"history\" && result.history?.reanchored) {\n guidance.push(\n 'The merged history chain was re-anchored. Run \"pm validate --check-history-drift\" and \"pm history-repair --all\" after the merge to reconcile item state with merged history.',\n );\n }\n return {\n ok: conflicts.length === 0,\n artifact,\n output_path: outputPath,\n preferred,\n conflicts,\n ...result,\n guidance,\n generated_at: nowIso(),\n };\n}\n", "/**\n * @module sdk/structured-mutations\n *\n * Parses agent-authored JSON mutation payloads into the public atomic item\n * transaction contract and normalizes full item documents for CLI round trips.\n */\nimport { EXIT_CODE } from \"../core/shared/constants.js\";\nimport { PmCliError } from \"../core/shared/errors.js\";\nimport { levenshteinDistanceWithinLimit } from \"../core/shared/levenshtein.js\";\nimport { CLOSE_FLAG_CONTRACTS } from \"./cli-contracts/flag-contracts.js\";\nimport {\n CREATE_COMMANDER_OPTION_REGISTRATION_CONTRACTS,\n UPDATE_COMMANDER_OPTION_REGISTRATION_CONTRACTS,\n} from \"./cli-contracts/commander-mutation-options.js\";\nimport type { PmClientFullMutationOptions } from \"./runtime.js\";\nimport type { BulkItemMutation } from \"./item-transaction.js\";\n\nconst MUTATION_ROW_KEYS = [\"op\", \"id\", \"reason\", \"options\"] as const;\nconst ITEM_ENVELOPE_KEYS = [\n \"item\",\n \"linked\",\n \"schedule\",\n \"claim_state\",\n \"children\",\n] as const;\nconst READ_ONLY_ITEM_KEYS = new Set([\n \"created_at\",\n \"updated_at\",\n \"closed_at\",\n \"version\",\n \"format_version\",\n \"path\",\n \"author\",\n]);\nconst UPDATE_READ_ONLY_ITEM_KEYS = new Set([...READ_ONLY_ITEM_KEYS, \"id\"]);\nconst ITEM_FIELD_KEYS = new Set([\n \"id\",\n \"title\",\n \"description\",\n \"type\",\n \"status\",\n \"priority\",\n \"tags\",\n \"body\",\n \"deadline\",\n \"estimated_minutes\",\n \"acceptance_criteria\",\n \"definition_of_ready\",\n \"order\",\n \"rank\",\n \"goal\",\n \"objective\",\n \"value\",\n \"impact\",\n \"outcome\",\n \"why_now\",\n \"assignee\",\n \"parent\",\n \"reviewer\",\n \"risk\",\n \"confidence\",\n \"sprint\",\n \"release\",\n \"blocked_by\",\n \"blocked_reason\",\n \"unblock_note\",\n \"reporter\",\n \"severity\",\n \"environment\",\n \"repro_steps\",\n \"resolution\",\n \"expected_result\",\n \"actual_result\",\n \"affected_version\",\n \"fixed_version\",\n \"component\",\n \"regression\",\n \"customer_impact\",\n \"close_reason\",\n \"dependencies\",\n \"comments\",\n \"notes\",\n \"learnings\",\n \"files\",\n \"tests\",\n \"docs\",\n \"reminders\",\n \"events\",\n \"type_options\",\n]);\nconst MUTATION_OPTION_KEYS: Readonly<\n Record<BulkItemMutation[\"op\"], readonly string[]>\n> = {\n create: CREATE_COMMANDER_OPTION_REGISTRATION_CONTRACTS.map(\n (contract) => contract.target,\n ),\n update: UPDATE_COMMANDER_OPTION_REGISTRATION_CONTRACTS.map(\n (contract) => contract.target,\n ),\n close: CLOSE_FLAG_CONTRACTS.map((contract) =>\n contract.flag\n .slice(2)\n .replaceAll(/-([a-z])/gu, (_match, letter: string) =>\n letter.toUpperCase(),\n ),\n ).filter((key) => key !== \"reason\"),\n};\n\n/** Validated transaction controls shared by atomic CLI and MCP adapters. */\nexport interface AtomicMutationControls {\n /** Compensation policy applied to created items when a later step fails. */\n createCompensation?: \"close\" | \"delete\";\n /** Workspace transaction lock lifetime in seconds. */\n lockTtlSeconds?: number;\n /** Maximum time to wait for the workspace transaction lock. */\n lockWaitMs?: number;\n}\n\n/** Validate and normalize atomic transaction controls at every transport boundary. */\nexport function parseAtomicMutationControls(\n value: Record<string, unknown>,\n): AtomicMutationControls {\n const controls: AtomicMutationControls = {};\n const compensation = value.createCompensation;\n if (compensation !== undefined) {\n if (compensation !== \"close\" && compensation !== \"delete\") {\n throw new PmCliError(\n \"createCompensation must be close or delete.\",\n EXIT_CODE.USAGE,\n );\n }\n controls.createCompensation = compensation;\n }\n for (const key of [\"lockTtlSeconds\", \"lockWaitMs\"] as const) {\n const raw = value[key];\n if (raw === undefined) continue;\n const parsed =\n typeof raw === \"number\" ||\n (typeof raw === \"string\" && raw.trim().length > 0)\n ? Number(raw)\n : Number.NaN;\n if (!Number.isSafeInteger(parsed) || parsed <= 0) {\n throw new PmCliError(\n `${key} must be a positive safe integer.`,\n EXIT_CODE.USAGE,\n );\n }\n controls[key] = parsed;\n }\n return controls;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\nfunction nearestKey(\n key: string,\n candidates: readonly string[],\n): string | undefined {\n const limit = Math.max(1, Math.min(3, Math.floor(key.length / 4) + 1));\n let best: { key: string; distance: number } | undefined;\n for (const candidate of candidates) {\n const distance = levenshteinDistanceWithinLimit(key, candidate, limit);\n if (distance !== null && (best === undefined || distance < best.distance)) {\n best = { key: candidate, distance };\n }\n }\n return best?.key;\n}\n\nfunction unknownKeyError(\n scope: string,\n key: string,\n candidates: readonly string[],\n): PmCliError {\n const suggestion = nearestKey(key, candidates);\n return new PmCliError(\n suggestion === undefined\n ? `${scope} does not recognize key \"${key}\". Allowed keys: ${candidates.join(\", \")}.`\n : `${scope} does not recognize key \"${key}\". Did you mean \"${suggestion}\"?`,\n EXIT_CODE.USAGE,\n {\n code: \"stdin_json_unknown_key\",\n required: `Use documented ${scope} keys only.`,\n why: \"Strict structured input prevents silent typos from creating incomplete or unintended mutations.\",\n nextSteps: [\n suggestion === undefined\n ? `Remove or correct \"${key}\".`\n : `Replace \"${key}\" with \"${suggestion}\".`,\n ],\n },\n );\n}\n\nfunction parseJsonValue(input: string, label: string): unknown {\n try {\n return JSON.parse(input) as unknown;\n } catch (error: unknown) {\n const detail = error instanceof Error ? error.message : String(error);\n throw new PmCliError(\n `${label} must be valid JSON: ${detail}`,\n EXIT_CODE.USAGE,\n {\n code: \"stdin_json_invalid\",\n required: `Pipe one valid JSON ${label.toLowerCase()} into stdin.`,\n why: \"Structured mutation input must parse deterministically before any tracker write begins.\",\n },\n );\n }\n}\n\nfunction validateMutationObject(\n value: unknown,\n index: number,\n): Record<string, unknown> {\n if (!isPlainObject(value)) {\n throw new PmCliError(\n `Mutation ${index + 1} must be an object.`,\n EXIT_CODE.USAGE,\n );\n }\n for (const key of Object.keys(value)) {\n if (\n !MUTATION_ROW_KEYS.includes(key as (typeof MUTATION_ROW_KEYS)[number])\n ) {\n throw unknownKeyError(`mutation ${index + 1}`, key, MUTATION_ROW_KEYS);\n }\n }\n return value;\n}\n\nfunction validateMutationOptions(\n options: unknown,\n op: BulkItemMutation[\"op\"],\n index: number,\n): Record<string, unknown> | undefined {\n if (options === undefined) return undefined;\n if (!isPlainObject(options)) {\n throw new PmCliError(\n `Mutation ${index + 1} options must be an object.`,\n EXIT_CODE.USAGE,\n );\n }\n for (const key of Object.keys(options)) {\n if (!MUTATION_OPTION_KEYS[op].includes(key)) {\n throw unknownKeyError(\n `mutation ${index + 1} ${op} options`,\n key,\n MUTATION_OPTION_KEYS[op],\n );\n }\n }\n return options;\n}\n\nfunction validateMutationRow(value: unknown, index: number): BulkItemMutation {\n const mutation = validateMutationObject(value, index);\n const { op, id, reason } = mutation;\n if (op !== \"create\" && op !== \"update\" && op !== \"close\") {\n throw new PmCliError(\n `Mutation ${index + 1} op must be create, update, or close.`,\n EXIT_CODE.USAGE,\n );\n }\n const options = validateMutationOptions(mutation.options, op, index);\n if (typeof id !== \"string\" || id.trim().length === 0) {\n throw new PmCliError(\n `Mutation ${index + 1} requires a non-empty id.`,\n EXIT_CODE.USAGE,\n );\n }\n const normalizedId = id.trim();\n if (op === \"close\") {\n if (typeof reason !== \"string\" || reason.trim().length === 0) {\n throw new PmCliError(\n `Mutation ${index + 1} close requires a non-empty reason.`,\n EXIT_CODE.USAGE,\n );\n }\n return {\n op,\n id: normalizedId,\n reason: reason.trim(),\n ...(options === undefined\n ? {}\n : { options: options as PmClientFullMutationOptions }),\n };\n }\n if (!isPlainObject(options)) {\n throw new PmCliError(\n `Mutation ${index + 1} ${op} requires an options object.`,\n EXIT_CODE.USAGE,\n );\n }\n return {\n op,\n id: normalizedId,\n options: options as PmClientFullMutationOptions,\n };\n}\n\n/** Parse a JSON array, or an object containing `mutations`, into an atomic mutation batch. */\nexport function parseItemMutationBatch(input: string): BulkItemMutation[] {\n const parsed = parseJsonValue(input, \"Mutation batch\");\n const rows = Array.isArray(parsed)\n ? parsed\n : isPlainObject(parsed) && Array.isArray(parsed.mutations)\n ? parsed.mutations\n : undefined;\n if (rows === undefined || rows.length === 0) {\n throw new PmCliError(\n \"Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.\",\n EXIT_CODE.USAGE,\n );\n }\n return rows.map((row, index) => validateMutationRow(row, index));\n}\n\nfunction serializePairs(\n value: Record<string, unknown>,\n keys: readonly string[],\n): string {\n return keys\n .filter((key) => value[key] !== undefined && value[key] !== null)\n .map((key) => {\n const rendered = String(value[key]);\n return `${key}=${/[\",\\n\\r\\\\]/u.test(rendered) ? JSON.stringify(rendered) : rendered}`;\n })\n .join(\",\");\n}\n\nfunction serializeObjectArray(\n value: unknown,\n keys: readonly string[],\n label: string,\n): string[] | undefined {\n if (value === undefined) return undefined;\n if (!Array.isArray(value) || !value.every(isPlainObject)) {\n throw new PmCliError(\n `${label} must be an array of objects.`,\n EXIT_CODE.USAGE,\n );\n }\n return value.map((entry) => serializePairs(entry, keys));\n}\n\nfunction scalarItemOption(key: string, value: unknown): unknown {\n if (\n key === \"tags\" &&\n Array.isArray(value) &&\n value.every((entry) => typeof entry === \"string\")\n ) {\n return JSON.stringify(value);\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n return value;\n}\n\nfunction appendFacetOptions(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n skipPersistedAnnotations = false,\n): void {\n const mappings: ReadonlyArray<readonly [string, string, readonly string[]]> =\n [\n [\"dependencies\", \"dep\", [\"id\", \"kind\", \"created_at\", \"author\"]],\n [\"comments\", \"comment\", [\"text\", \"created_at\", \"author\"]],\n [\"notes\", \"note\", [\"text\", \"created_at\", \"author\"]],\n [\"learnings\", \"learning\", [\"text\", \"created_at\", \"author\"]],\n [\"files\", \"file\", [\"path\", \"scope\", \"note\"]],\n [\"tests\", \"test\", [\"command\", \"scope\", \"timeout_seconds\"]],\n [\"docs\", \"doc\", [\"path\", \"scope\", \"note\"]],\n [\"reminders\", \"reminder\", [\"at\", \"text\", \"created_at\"]],\n [\"events\", \"event\", [\"start_at\", \"end_at\", \"title\", \"location\"]],\n [\"type_options\", \"typeOption\", [\"key\", \"value\"]],\n ];\n for (const [sourceKey, targetKey, keys] of mappings) {\n const sourceValue = source[sourceKey];\n const serialized = serializeObjectArray(\n skipPersistedAnnotations &&\n [\"comments\", \"notes\", \"learnings\"].includes(sourceKey) &&\n Array.isArray(sourceValue)\n ? sourceValue.filter(\n (entry) =>\n !isPlainObject(entry) || entry.created_at === undefined,\n )\n : sourceValue,\n keys,\n sourceKey,\n );\n if (serialized !== undefined && serialized.length > 0)\n target[targetKey] = serialized;\n }\n}\n\nfunction validateItemDocumentKeys(\n parsed: Record<string, unknown>,\n envelope: boolean,\n): void {\n for (const key of Object.keys(parsed)) {\n if (envelope) {\n if (\n !ITEM_ENVELOPE_KEYS.includes(key as (typeof ITEM_ENVELOPE_KEYS)[number])\n )\n throw unknownKeyError(\"item envelope\", key, ITEM_ENVELOPE_KEYS);\n continue;\n }\n if (\n !ITEM_FIELD_KEYS.has(key) &&\n nearestKey(key, [...ITEM_FIELD_KEYS]) === undefined &&\n nearestKey(key, ITEM_ENVELOPE_KEYS) === \"item\"\n )\n throw unknownKeyError(\"item envelope\", key, ITEM_ENVELOPE_KEYS);\n }\n}\n\nfunction resolveItemDocument(parsed: Record<string, unknown>): {\n item: Record<string, unknown>;\n linked?: Record<string, unknown>;\n} {\n const envelope = Object.hasOwn(parsed, \"item\");\n validateItemDocumentKeys(parsed, envelope);\n const item = envelope ? parsed.item : parsed;\n if (!isPlainObject(item)) {\n throw new PmCliError(\n \"Item document item must be an object.\",\n EXIT_CODE.USAGE,\n );\n }\n return {\n item,\n ...(envelope && isPlainObject(parsed.linked)\n ? { linked: parsed.linked }\n : {}),\n };\n}\n\nfunction appendItemDocumentEntry(\n documentOptions: Record<string, unknown>,\n key: string,\n value: unknown,\n mode: \"create\" | \"update\",\n): void {\n const readOnlyKeys =\n mode === \"update\" ? UPDATE_READ_ONLY_ITEM_KEYS : READ_ONLY_ITEM_KEYS;\n if (readOnlyKeys.has(key)) return;\n if (!ITEM_FIELD_KEYS.has(key)) {\n const suggestion = nearestKey(key, [...ITEM_FIELD_KEYS]);\n if (suggestion !== undefined)\n throw unknownKeyError(\"item document\", key, [...ITEM_FIELD_KEYS]);\n const fields = Array.isArray(documentOptions.field)\n ? (documentOptions.field as string[])\n : [];\n fields.push(\n serializePairs(\n {\n key,\n value: typeof value === \"string\" ? value : JSON.stringify(value),\n },\n [\"key\", \"value\"],\n ),\n );\n documentOptions.field = fields;\n return;\n }\n if (\n [\n \"dependencies\",\n \"comments\",\n \"notes\",\n \"learnings\",\n \"files\",\n \"tests\",\n \"docs\",\n \"reminders\",\n \"events\",\n \"type_options\",\n ].includes(key)\n )\n return;\n documentOptions[\n key.replaceAll(/_([a-z])/gu, (_match, letter: string) =>\n letter.toUpperCase(),\n )\n ] = scalarItemOption(key, value);\n}\n\n/**\n * Convert a direct item JSON document or `pm get --json` envelope into the\n * create/update option shape. Explicit CLI flags override document values.\n */\nexport function itemDocumentToMutationOptions(\n input: string,\n mode: \"create\" | \"update\",\n explicitOptions: Record<string, unknown> = {},\n): Record<string, unknown> {\n const parsed = parseJsonValue(input, \"Item document\");\n if (!isPlainObject(parsed)) {\n throw new PmCliError(\n \"Item document must be a JSON object.\",\n EXIT_CODE.USAGE,\n );\n }\n const { item, linked } = resolveItemDocument(parsed);\n const documentOptions: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(item)) {\n appendItemDocumentEntry(documentOptions, key, value, mode);\n }\n appendFacetOptions(documentOptions, item, mode === \"update\");\n if (linked !== undefined) appendFacetOptions(documentOptions, linked);\n return {\n ...documentOptions,\n ...Object.fromEntries(\n Object.entries(explicitOptions).filter(\n ([, value]) => value !== undefined,\n ),\n ),\n stdinJson: undefined,\n };\n}\n\n/** Validate an already-decoded MCP mutation array through the same strict parser as CLI stdin. */\nexport function validateItemMutationRows(value: unknown): BulkItemMutation[] {\n return parseItemMutationBatch(JSON.stringify(value));\n}\n", "/**\n * @module sdk/item-transaction\n *\n * Provides the bulk item-mutation convenience layer over\n * `commitWorkspaceTransaction`: atomic, resumable create/update/close batches\n * with correct-by-construction inspection and compensation wiring.\n */\nimport path from \"node:path\";\nimport { EXIT_CODE } from \"../core/shared/constants.js\";\nimport { PmCliError } from \"../core/shared/errors.js\";\nimport { readHistoryEntries } from \"./history-read.js\";\nimport {\n close,\n create,\n deleteItem,\n get,\n restore,\n update,\n type PmClientFullMutationOptions,\n} from \"./runtime.js\";\nimport {\n commitWorkspaceTransaction,\n type CommitWorkspaceTransactionOptions,\n type WorkspaceTransactionJsonValue,\n type WorkspaceTransactionStep,\n type WorkspaceTransactionStepInspection,\n} from \"./workspace-transaction.js\";\n\n/**\n * One atomic item creation inside a bulk mutation batch. The explicit `id`\n * doubles as the idempotency key: recovery treats an existing item with this id\n * as the already-applied result, so ids must be stable and transaction-owned.\n */\nexport interface BulkItemCreateMutation {\n /** Discriminates the creation operation. */\n op: \"create\";\n /** Explicit stable item id (normalized with the configured id_prefix). */\n id: string;\n /** Creation options forwarded to the public `create` runtime primitive. */\n options: PmClientFullMutationOptions;\n}\n\n/** One atomic item update inside a bulk mutation batch. */\nexport interface BulkItemUpdateMutation {\n /** Discriminates the update operation. */\n op: \"update\";\n /** Target item id. */\n id: string;\n /** Update options forwarded to the public `update` runtime primitive. */\n options: PmClientFullMutationOptions;\n}\n\n/** One atomic item closure inside a bulk mutation batch. */\nexport interface BulkItemCloseMutation {\n /** Discriminates the close operation. */\n op: \"close\";\n /** Target item id. */\n id: string;\n /** Close reason recorded on the item. */\n reason: string;\n /** Close options forwarded to the public `close` runtime primitive. */\n options?: PmClientFullMutationOptions;\n}\n\n/** Union of the item mutations a bulk transaction batch can carry. */\nexport type BulkItemMutation =\n | BulkItemCreateMutation\n | BulkItemUpdateMutation\n | BulkItemCloseMutation;\n\n/** Options accepted by the bulk item-mutation transaction helper. */\nexport interface CommitItemMutationsOptions {\n /** Tracker root that owns the journal and workspace-wide writer lock. */\n pmRoot: string;\n /** Stable idempotency key reused to recover an interrupted batch. */\n transactionId: string;\n /** Attributable actor recorded in the journal and forwarded to mutations. */\n author: string;\n /** Ordered item mutations; compensations run in reverse order. */\n mutations: readonly BulkItemMutation[];\n /**\n * Compensation strategy for created items: `close` (default) preserves the\n * item and its history with an explanatory close reason, `delete` removes\n * the item document (its history stream is retained by `pm delete`).\n */\n createCompensation?: \"close\" | \"delete\";\n /** Lock lifetime in seconds; size this above the longest expected attempt. */\n lockTtlSeconds?: number;\n /** Maximum time to wait for the workspace writer lock. */\n lockWaitMs?: number;\n /** Optional transition observer used by telemetry and deterministic crash tests. */\n onTransition?: CommitWorkspaceTransactionOptions[\"onTransition\"];\n}\n\n/** Journal-safe outcome recorded for one committed bulk item mutation. */\nexport interface BulkItemMutationOutcome {\n /** Canonical id of the mutated item. */\n id: string;\n /** Operation the batch applied for this item. */\n op: BulkItemMutation[\"op\"];\n}\n\n/** Successful durable result of a bulk item-mutation transaction. */\nexport interface CommitItemMutationsResult {\n /** Stable transaction identifier. */\n transactionId: string;\n /** Final durable state. */\n status: \"committed\";\n /** Whether an interrupted journal was resumed. */\n recovered: boolean;\n /** One outcome per mutation, keyed by the derived transaction step id. */\n results: Record<string, BulkItemMutationOutcome>;\n}\n\ninterface LocatedItemSnapshot {\n id: string;\n closedAt: string | undefined;\n updatedAt: string;\n}\n\n/** Read one item's transaction-relevant fields, mapping not-found to undefined. */\nasync function readItemSnapshot(\n pmRoot: string,\n id: string,\n): Promise<LocatedItemSnapshot | undefined> {\n try {\n const located = await get(id, {}, { pmRoot });\n const item = located.item as {\n id: string;\n closed_at?: string;\n updated_at: string;\n };\n return {\n id: item.id,\n closedAt: item.closed_at,\n updatedAt: item.updated_at,\n };\n } catch (error) {\n if (\n error instanceof PmCliError &&\n error.exitCode === EXIT_CODE.NOT_FOUND\n ) {\n return undefined;\n }\n throw error;\n }\n}\n\n/** Derive a journal-safe step id from one mutation's position and target. */\nfunction deriveStepId(mutation: BulkItemMutation, index: number): string {\n const sanitizedTarget = mutation.id.replaceAll(/[^a-zA-Z0-9._-]/gu, \"_\");\n return `${index + 1}-${mutation.op}-${sanitizedTarget}`;\n}\n\n/** Build the durable history-message marker for one bulk mutation phase. */\nfunction bulkHistoryMarker(\n transactionId: string,\n stepId: string,\n phase: \"apply\" | \"compensate\",\n): string {\n return `bulk-item-transaction ${transactionId} ${stepId} ${phase}`;\n}\n\n/**\n * Report whether an update step's forward mutation is durably applied. Updates\n * cannot be inferred from field values (a moving target), so the applied apply\n * marker in the item's immutable history is the source of truth; a later\n * compensate marker means the mutation was rolled back and must re-apply.\n */\nasync function isUpdateMarkerApplied(\n pmRoot: string,\n canonicalId: string,\n transactionId: string,\n stepId: string,\n): Promise<boolean> {\n const entries = await readHistoryEntries(\n path.join(pmRoot, \"history\", `${canonicalId}.jsonl`),\n canonicalId,\n );\n const applyMarker = bulkHistoryMarker(transactionId, stepId, \"apply\");\n const compensateMarker = bulkHistoryMarker(transactionId, stepId, \"compensate\");\n for (let index = entries.length - 1; index >= 0; index -= 1) {\n const message = entries[index].message;\n if (message === applyMarker) {\n return true;\n }\n if (message === compensateMarker) {\n return false;\n }\n }\n return false;\n}\n\n/** Capture the restore target used to compensate an update or close mutation. */\nasync function prepareRestoreCompensation(\n pmRoot: string,\n mutation: BulkItemMutation,\n): Promise<WorkspaceTransactionJsonValue> {\n const snapshot = await readItemSnapshot(pmRoot, mutation.id);\n if (snapshot?.updatedAt === undefined) {\n throw new PmCliError(\n `Bulk ${mutation.op} target ${mutation.id} does not exist or has no restorable version`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n return { target_updated_at: snapshot.updatedAt };\n}\n\n/** Idempotently restore an item to its captured pre-mutation version. */\nasync function compensateByRestore(\n config: { pmRoot: string; author: string; transactionId: string },\n itemId: string,\n stepId: string,\n data: WorkspaceTransactionJsonValue | undefined,\n): Promise<void> {\n const target =\n data !== null && typeof data === \"object\" && !Array.isArray(data)\n ? data.target_updated_at\n : undefined;\n if (typeof target !== \"string\") {\n return;\n }\n if ((await readItemSnapshot(config.pmRoot, itemId)) === undefined) {\n return;\n }\n await restore(\n itemId,\n target,\n {\n force: true,\n author: config.author,\n message: bulkHistoryMarker(config.transactionId, stepId, \"compensate\"),\n },\n { pmRoot: config.pmRoot },\n );\n}\n\n/** Build the workspace-transaction step for one item creation. */\nfunction buildCreateStep(\n config: {\n pmRoot: string;\n author: string;\n transactionId: string;\n createCompensation: \"close\" | \"delete\";\n },\n mutation: BulkItemCreateMutation,\n stepId: string,\n): WorkspaceTransactionStep {\n return {\n id: stepId,\n async inspect(): Promise<WorkspaceTransactionStepInspection> {\n const snapshot = await readItemSnapshot(config.pmRoot, mutation.id);\n if (snapshot === undefined) {\n return { state: \"pending\" };\n }\n return { state: \"applied\", result: { id: snapshot.id, op: \"create\" } };\n },\n async apply(): Promise<WorkspaceTransactionJsonValue> {\n const created = await create(\n { ...mutation.options, author: config.author, id: mutation.id },\n { pmRoot: config.pmRoot },\n );\n const createdItem = created.item as Record<string, unknown>;\n return { id: String(createdItem.id), op: \"create\" };\n },\n async compensate(): Promise<void> {\n const snapshot = await readItemSnapshot(config.pmRoot, mutation.id);\n if (snapshot === undefined) {\n return;\n }\n if (config.createCompensation === \"delete\") {\n await deleteItem(\n mutation.id,\n {\n force: true,\n author: config.author,\n message: `Compensate interrupted bulk transaction ${config.transactionId}`,\n },\n { pmRoot: config.pmRoot },\n );\n return;\n }\n if (snapshot.closedAt !== undefined) {\n return;\n }\n await close(\n mutation.id,\n `Compensated: interrupted bulk transaction ${config.transactionId}`,\n { force: true, author: config.author },\n { pmRoot: config.pmRoot },\n );\n },\n };\n}\n\n/** Build the workspace-transaction step for one item update. */\nfunction buildUpdateStep(\n config: { pmRoot: string; author: string; transactionId: string },\n mutation: BulkItemUpdateMutation,\n stepId: string,\n): WorkspaceTransactionStep {\n return {\n id: stepId,\n async inspect(): Promise<WorkspaceTransactionStepInspection> {\n const snapshot = await readItemSnapshot(config.pmRoot, mutation.id);\n if (snapshot === undefined) {\n return { state: \"pending\" };\n }\n const applied = await isUpdateMarkerApplied(\n config.pmRoot,\n snapshot.id,\n config.transactionId,\n stepId,\n );\n if (!applied) {\n return { state: \"pending\" };\n }\n return { state: \"applied\", result: { id: snapshot.id, op: \"update\" } };\n },\n async prepareCompensation(): Promise<WorkspaceTransactionJsonValue> {\n return prepareRestoreCompensation(config.pmRoot, mutation);\n },\n async apply(): Promise<WorkspaceTransactionJsonValue> {\n const updated = await update(\n mutation.id,\n {\n ...mutation.options,\n author: config.author,\n message: bulkHistoryMarker(config.transactionId, stepId, \"apply\"),\n },\n { pmRoot: config.pmRoot },\n );\n const updatedItem = updated.item as Record<string, unknown>;\n return { id: String(updatedItem.id), op: \"update\" };\n },\n async compensate(\n data?: WorkspaceTransactionJsonValue,\n ): Promise<void> {\n await compensateByRestore(config, mutation.id, stepId, data);\n },\n };\n}\n\n/** Build the workspace-transaction step for one item closure. */\nfunction buildCloseStep(\n config: { pmRoot: string; author: string; transactionId: string },\n mutation: BulkItemCloseMutation,\n stepId: string,\n): WorkspaceTransactionStep {\n return {\n id: stepId,\n // An already-terminal target counts as applied: closing it again would\n // fight legitimate prior closure, and recovery must adopt completed work.\n async inspect(): Promise<WorkspaceTransactionStepInspection> {\n const snapshot = await readItemSnapshot(config.pmRoot, mutation.id);\n if (snapshot?.closedAt === undefined) {\n return { state: \"pending\" };\n }\n return { state: \"applied\", result: { id: snapshot.id, op: \"close\" } };\n },\n async prepareCompensation(): Promise<WorkspaceTransactionJsonValue> {\n return prepareRestoreCompensation(config.pmRoot, mutation);\n },\n async apply(): Promise<WorkspaceTransactionJsonValue> {\n const closed = await close(\n mutation.id,\n mutation.reason,\n { ...mutation.options, author: config.author },\n { pmRoot: config.pmRoot },\n );\n const closedItem = closed.item as Record<string, unknown>;\n return { id: String(closedItem.id), op: \"close\" };\n },\n async compensate(\n data?: WorkspaceTransactionJsonValue,\n ): Promise<void> {\n await compensateByRestore(config, mutation.id, stepId, data);\n },\n };\n}\n\n/** Convert one validated bulk mutation into its workspace-transaction step. */\nfunction buildStepForMutation(\n config: {\n pmRoot: string;\n author: string;\n transactionId: string;\n createCompensation: \"close\" | \"delete\";\n },\n mutation: BulkItemMutation,\n index: number,\n): WorkspaceTransactionStep {\n const stepId = deriveStepId(mutation, index);\n if (mutation.op === \"create\") {\n return buildCreateStep(config, mutation, stepId);\n }\n if (mutation.op === \"update\") {\n return buildUpdateStep(config, mutation, stepId);\n }\n return buildCloseStep(config, mutation, stepId);\n}\n\n/** Reject malformed bulk mutation rows before any journal or lock work. */\nfunction assertValidBulkMutation(\n mutation: BulkItemMutation,\n index: number,\n): void {\n if (\n mutation === null ||\n typeof mutation !== \"object\" ||\n Array.isArray(mutation)\n ) {\n throw new TypeError(`Bulk mutation ${index + 1} must be an object`);\n }\n if (![\"create\", \"update\", \"close\"].includes(mutation.op)) {\n throw new TypeError(\n `Bulk mutation ${index + 1} op must be create, update, or close`,\n );\n }\n if (typeof mutation.id !== \"string\" || mutation.id.trim().length === 0) {\n throw new TypeError(`Bulk mutation ${index + 1} requires a non-empty id`);\n }\n if (\n mutation.op === \"close\" &&\n (typeof mutation.reason !== \"string\" || mutation.reason.trim().length === 0)\n ) {\n throw new TypeError(\n `Bulk close mutation ${index + 1} requires a non-empty reason`,\n );\n }\n}\n\n/**\n * Commit an ordered batch of item create/update/close mutations atomically\n * (all-or-nothing) in one durable workspace transaction. This is the\n * high-level companion to `commitWorkspaceTransaction`: instead of\n * hand-writing `inspect`/`prepareCompensation`/`apply`/`compensate` for the\n * ubiquitous bulk import/sync case, callers describe the mutations and the\n * helper wires the crash-consistency contract — exists-by-id inspection for\n * creates, version-restore compensation for updates and closes, and\n * close-or-delete compensation for creates. A stable `transactionId` makes\n * interrupted batches resumable across processes and agents.\n */\nexport async function commitItemMutations(\n options: CommitItemMutationsOptions,\n): Promise<CommitItemMutationsResult> {\n const mutations = [...options.mutations];\n if (mutations.length === 0) {\n throw new TypeError(\"Bulk item transaction requires at least one mutation\");\n }\n for (const [index, mutation] of mutations.entries()) {\n assertValidBulkMutation(mutation, index);\n }\n const createCompensation = options.createCompensation ?? \"close\";\n if (![\"close\", \"delete\"].includes(createCompensation)) {\n throw new TypeError(\n \"Bulk item transaction createCompensation must be close or delete\",\n );\n }\n const stepConfig = {\n pmRoot: options.pmRoot,\n author: options.author,\n transactionId: options.transactionId,\n createCompensation,\n };\n const committed = await commitWorkspaceTransaction({\n pmRoot: options.pmRoot,\n transactionId: options.transactionId,\n author: options.author,\n steps: mutations.map((mutation, index) =>\n buildStepForMutation(stepConfig, mutation, index),\n ),\n ...(options.lockTtlSeconds === undefined\n ? {}\n : { lockTtlSeconds: options.lockTtlSeconds }),\n ...(options.lockWaitMs === undefined\n ? {}\n : { lockWaitMs: options.lockWaitMs }),\n ...(options.onTransition === undefined\n ? {}\n : { onTransition: options.onTransition }),\n });\n const results: Record<string, BulkItemMutationOutcome> = {};\n for (const [stepId, value] of Object.entries(committed.results)) {\n // Journal values round-trip this module's own step outputs, which are\n // always {id, op} objects — the cast restores the concrete outcome shape.\n results[stepId] = value as unknown as BulkItemMutationOutcome;\n }\n return {\n transactionId: committed.transactionId,\n status: \"committed\",\n recovered: committed.recovered,\n results,\n };\n}\n\n/** Public contract for test only item transaction internals, shared with white-box specs. */\nexport const _testOnlyItemTransaction = {\n buildCreateStep,\n bulkHistoryMarker,\n comp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ChB,OAAO,UAAU,IAAI,CAAC,UAAU,UAC9B,qBAAqB,YAAY,UAAU,KAAK,CAAC;IAEnD,GAAI,QAAQ,mBAAmB,SAC3B,CAAA,IACA,EAAE,gBAAgB,QAAQ,eAAc;IAC5C,GAAI,QAAQ,eAAe,SACvB,CAAA,IACA,EAAE,YAAY,QAAQ,WAAU;IACpC,GAAI,QAAQ,iBAAiB,SACzB,CAAA,IACA,EAAE,cAAc,QAAQ,aAAY;GACzC;AACD,QAAM,UAAmD,CAAA;AACzD,aAAW,CAAC,QAAQ,KAAK,KAAK,OAAO,QAAQ,UAAU,OAAO,GAAG;AAG/D,YAAQ,MAAM,IAAI;EACpB;AACA,SAAO;IACL,eAAe,UAAU;IACzB,QAAQ;IACR,WAAW,UAAU;IACrB;;AAEJ;AAGO,IAAM,2BAA2B;EACtC;EACA;EACA;EACA;EACA;EACA;;",
|
|
6
|
+
"names": ["global", "isPlainObject", "path", "path"]
|
|
7
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
createStdinTokenResolver,
|
|
5
5
|
parseCsvKv
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AELMUANP.js";
|
|
7
7
|
import {
|
|
8
8
|
parseLimit
|
|
9
9
|
} from "./chunk-K4CI6Y45.js";
|
|
@@ -323,6 +323,6 @@ export {
|
|
|
323
323
|
runAnnotationCommand,
|
|
324
324
|
resolveAnnotationIndex
|
|
325
325
|
};
|
|
326
|
-
//# sourceMappingURL=chunk-
|
|
326
|
+
//# sourceMappingURL=chunk-TRSHFPRZ.js.map
|
|
327
327
|
|
|
328
328
|
//# debugId=2d594eeb-b3b9-55ff-80ae-8acbfeadd295
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
} from "./chunk-OWXOPDHD.js";
|
|
18
18
|
import {
|
|
19
19
|
runRestore
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-R3P6FZJW.js";
|
|
21
21
|
import {
|
|
22
22
|
resolveAuthor
|
|
23
23
|
} from "./chunk-CUFW7ITY.js";
|
|
@@ -399,6 +399,6 @@ export {
|
|
|
399
399
|
runCloseMany,
|
|
400
400
|
_testOnly
|
|
401
401
|
};
|
|
402
|
-
//# sourceMappingURL=chunk-
|
|
402
|
+
//# sourceMappingURL=chunk-UCBDQI5E.js.map
|
|
403
403
|
|
|
404
404
|
//# debugId=25f9bc90-a71d-54c0-916a-8c3972f6df68
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
readManagedExtensionState,
|
|
3
3
|
runExtension
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FO6OSVEN.js";
|
|
5
5
|
import {
|
|
6
6
|
normalizeParentReferencePolicy,
|
|
7
7
|
normalizeSprintReleaseFormatPolicy
|
|
@@ -1528,4 +1528,4 @@ export {
|
|
|
1528
1528
|
_testOnlyConfigCommand,
|
|
1529
1529
|
runUpgrade
|
|
1530
1530
|
};
|
|
1531
|
-
//# sourceMappingURL=chunk-
|
|
1531
|
+
//# sourceMappingURL=chunk-V22ZPOKN.js.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
parseAnnotationTextInput,
|
|
3
3
|
resolveAnnotationInput,
|
|
4
4
|
runAnnotationCommand
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-X3W65QK3.js";
|
|
6
6
|
|
|
7
7
|
// dist/cli/commands/learnings.js
|
|
8
8
|
!(function() {
|
|
@@ -35,4 +35,4 @@ async function runLearnings(id, options, global2) {
|
|
|
35
35
|
export {
|
|
36
36
|
runLearnings
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-VHXHVTUU.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
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]="96f03a19-9c65-508e-a60b-793c28248a9d")}catch(e){}}();
|
|
3
3
|
import {
|
|
4
4
|
runActiveCommandOverride,
|
|
5
5
|
runActiveRendererOverride,
|
|
@@ -73,6 +73,26 @@ function projectIdOnlyResult(result) {
|
|
|
73
73
|
}
|
|
74
74
|
return status ? { id, status } : { id };
|
|
75
75
|
}
|
|
76
|
+
function projectCompactMutationEnvelope(result) {
|
|
77
|
+
if (!isPlainObject(result) || !isPlainObject(result.item))
|
|
78
|
+
return null;
|
|
79
|
+
if (typeof result.item.id !== "string")
|
|
80
|
+
return null;
|
|
81
|
+
const changedFields = result[CHANGED_FIELDS_KEY];
|
|
82
|
+
if (!Array.isArray(changedFields))
|
|
83
|
+
return null;
|
|
84
|
+
const compact = {
|
|
85
|
+
id: result.item.id,
|
|
86
|
+
...typeof result.item.status === "string" ? { status: result.item.status } : {},
|
|
87
|
+
changed_field_count: changedFields.length
|
|
88
|
+
};
|
|
89
|
+
const closeReason = typeof result.close_reason === "string" ? result.close_reason : typeof result.item.close_reason === "string" ? result.item.close_reason : void 0;
|
|
90
|
+
if (closeReason !== void 0)
|
|
91
|
+
compact.close_reason = closeReason;
|
|
92
|
+
if (Array.isArray(result.warnings) && result.warnings.length > 0)
|
|
93
|
+
compact.warnings = result.warnings;
|
|
94
|
+
return compact;
|
|
95
|
+
}
|
|
76
96
|
function compactUpdateManyRows(envelope) {
|
|
77
97
|
const rows = isUpdateManyMutationEnvelope(envelope) ? envelope[ROWS_KEY] : void 0;
|
|
78
98
|
if (!Array.isArray(rows)) {
|
|
@@ -99,6 +119,11 @@ function projectMutationResult(result, options = {}) {
|
|
|
99
119
|
return idOnly;
|
|
100
120
|
}
|
|
101
121
|
}
|
|
122
|
+
if (options.compactEnvelope === true) {
|
|
123
|
+
const compact = projectCompactMutationEnvelope(result);
|
|
124
|
+
if (compact !== null)
|
|
125
|
+
return compact;
|
|
126
|
+
}
|
|
102
127
|
const mode = options.changedFields ?? "full";
|
|
103
128
|
if (mode === "full" || !isPlainObject(result)) {
|
|
104
129
|
return result;
|
|
@@ -300,8 +325,11 @@ function renderDefaultMarkdownResult(value) {
|
|
|
300
325
|
return `${lines.join("\n")}
|
|
301
326
|
`;
|
|
302
327
|
}
|
|
328
|
+
function resolveOutputFormat(options) {
|
|
329
|
+
return options.json === true || options.json === void 0 && options.defaultOutputFormat === "json" ? "json" : "toon";
|
|
330
|
+
}
|
|
303
331
|
function formatEffectiveOutput(effectiveResult, nativeOutput, options) {
|
|
304
|
-
const format = options
|
|
332
|
+
const format = resolveOutputFormat(options);
|
|
305
333
|
const serviceOverride = nativeOutput ? { handled: false, result: effectiveResult } : runActiveServiceOverrideSync("output_format", {
|
|
306
334
|
command: options.command,
|
|
307
335
|
args: options.commandArgs,
|
|
@@ -329,7 +357,8 @@ function formatEffectiveOutput(effectiveResult, nativeOutput, options) {
|
|
|
329
357
|
`;
|
|
330
358
|
}
|
|
331
359
|
if (format === "json") {
|
|
332
|
-
|
|
360
|
+
const jsonResult = options.lean === true ? compactToonValue(outputResult) ?? null : outputResult;
|
|
361
|
+
return `${JSON.stringify(jsonResult, null, 2)}
|
|
333
362
|
`;
|
|
334
363
|
}
|
|
335
364
|
const compactedToon = compactToonValue(outputResult);
|
|
@@ -348,7 +377,7 @@ function formatOutput(result, options) {
|
|
|
348
377
|
return suppressedOutput ? "" : formatEffectiveOutput(effectiveResult, nativeOutput, options);
|
|
349
378
|
}
|
|
350
379
|
function printResult(result, options) {
|
|
351
|
-
const projected = options.idOnly ? projectMutationResult(result, { idOnly: true }) : options.noChangedFields ? projectMutationResult(result, { changedFields: "compact" }) : result;
|
|
380
|
+
const projected = options.idOnly ? projectMutationResult(result, { idOnly: true }) : options.fullChangedFields ? result : options.noChangedFields ? projectMutationResult(result, { changedFields: "compact" }) : projectMutationResult(result, { compactEnvelope: true });
|
|
352
381
|
const rendered = formatOutput(projected, options);
|
|
353
382
|
if (options.quiet) {
|
|
354
383
|
return;
|
|
@@ -373,6 +402,6 @@ export {
|
|
|
373
402
|
printResult,
|
|
374
403
|
printError
|
|
375
404
|
};
|
|
376
|
-
//# sourceMappingURL=chunk-
|
|
405
|
+
//# sourceMappingURL=chunk-VJQG4BIM.js.map
|
|
377
406
|
|
|
378
|
-
//# debugId=
|
|
407
|
+
//# debugId=96f03a19-9c65-508e-a60b-793c28248a9d
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../core/output/output-control.ts","../../../../../../../../core/output/mutation-projection.ts","../../../../../../../../core/output/output.ts"],"sourcesContent":["/**\n * @module core/output/output-control\n *\n * Defines the structural protocol for commands that own their output stream.\n */\n\nconst SUPPRESS_HOST_OUTPUT_KEY = \"__pm_suppress_host_output\";\n\n/** Collision-resistant wire marker understood by pm hosts when a package already emitted output. */\nexport const SUPPRESS_HOST_OUTPUT_MARKER =\n \"@unbrained/pm-cli:suppress-host-output:v1\";\n\n/** A handled result that tells a pm host not to render or write another payload. */\nexport interface SuppressedHostOutput<TResult = unknown> {\n /** Explicit protocol marker consumed by CLI and SDK-built presentation hosts. */\n readonly __pm_suppress_host_output: typeof SUPPRESS_HOST_OUTPUT_MARKER;\n /** Optional structured result retained for hooks, telemetry, and embedding hosts. */\n readonly result?: TResult;\n}\n\n/** Return from a command/exporter after it has written its own streaming, binary, or pre-rendered output. */\nexport function suppressHostOutput<TResult = undefined>(\n result?: TResult,\n): SuppressedHostOutput<TResult> {\n return result === undefined\n ? { __pm_suppress_host_output: SUPPRESS_HOST_OUTPUT_MARKER }\n : { __pm_suppress_host_output: SUPPRESS_HOST_OUTPUT_MARKER, result };\n}\n\n/** Detect the public suppression result without relying on object identity across package boundaries. */\nexport function isHostOutputSuppressed(\n value: unknown,\n): value is SuppressedHostOutput {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n (value as Record<string, unknown>)[SUPPRESS_HOST_OUTPUT_KEY] ===\n SUPPRESS_HOST_OUTPUT_MARKER\n );\n}\n","/**\n * Shared projection helper for mutation command results.\n *\n * Mutation commands (create/update/close/append/update-many) return a result\n * envelope that carries a `changed_fields` string array. On create this array simply\n * re-lists every field the command just set, which the item echo above it already\n * shows, so for high-volume agent loops it is ~50% redundant payload. This helper\n * lets the CLI (`--no-changed-fields`) and the MCP agent path trim that array down\n * to a deterministic `changed_field_count` without losing mutation evidence.\n *\n * Compaction is deliberately scoped to the mutation envelope only:\n * - the envelope's own top-level `changed_fields` (create/update/close/append), and\n * - `rows[*].changed_fields` (update-many reports its delta per row).\n * It does NOT recurse into arbitrary nested objects, so unrelated payloads that\n * legitimately carry `changed_fields` (for example `pm history --diff` entries, or a\n * custom runtime metadata field) are left untouched.\n *\n * The helper is pure and side-effect free, reused by both the output layer and the\n * MCP server, and returns the original reference unchanged when nothing is compacted.\n */\n\n/** Controls whether mutation output keeps full changed fields or compact counts. */\nexport type ChangedFieldsMode = \"full\" | \"compact\";\n\n/** Documents the mutation projection options payload exchanged by command, SDK, and package integrations. */\nexport interface MutationProjectionOptions {\n /** Defaults to \"full\" (unchanged output). \"compact\" drops the array, keeping a count. */\n changedFields?: ChangedFieldsMode;\n /** Return the default agent envelope: id, status, changed-field count, and close reason. */\n compactEnvelope?: boolean;\n /** Return only id/status for single-item mutation envelopes. */\n idOnly?: boolean;\n}\n\nconst CHANGED_FIELDS_KEY = \"changed_fields\";\nconst CHANGED_FIELD_COUNT_KEY = \"changed_field_count\";\nconst ROWS_KEY = \"rows\";\nconst UPDATE_MANY_MUTATION_MODES = new Set([\"apply\", \"rollback\"]);\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const proto = Object.getPrototypeOf(value);\n return proto === null || proto === Object.prototype;\n}\n\n/** Replace a single envelope's own top-level `changed_fields` array with a count. */\nfunction compactOwnChangedFields(\n envelope: Record<string, unknown>,\n): Record<string, unknown> | null {\n const changedFields = envelope[CHANGED_FIELDS_KEY];\n if (!Array.isArray(changedFields)) {\n return null;\n }\n const projected: Record<string, unknown> =\n Object.getPrototypeOf(envelope) === null ? Object.create(null) : {};\n for (const [key, value] of Object.entries(envelope)) {\n if (key !== CHANGED_FIELDS_KEY) {\n projected[key] = value;\n }\n }\n projected[CHANGED_FIELD_COUNT_KEY] = changedFields.length;\n return projected;\n}\n\nfunction isMutationEnvelope(value: Record<string, unknown>): boolean {\n return \"item\" in value && Array.isArray(value[CHANGED_FIELDS_KEY]);\n}\n\nfunction isUpdateManyMutationEnvelope(value: Record<string, unknown>): boolean {\n return (\n typeof value.mode === \"string\" &&\n UPDATE_MANY_MUTATION_MODES.has(value.mode) &&\n Array.isArray(value[ROWS_KEY])\n );\n}\n\nfunction replaceRows(\n envelope: Record<string, unknown>,\n rows: unknown[],\n): Record<string, unknown> {\n const projected: Record<string, unknown> =\n Object.getPrototypeOf(envelope) === null ? Object.create(null) : {};\n Object.assign(projected, envelope);\n projected[ROWS_KEY] = rows;\n return projected;\n}\n\nfunction projectIdOnlyResult(result: unknown): unknown | null {\n if (!isPlainObject(result)) {\n return null;\n }\n // Plan mutations wrap the mutated subject under \"plan\" instead of \"item\";\n // both shapes honor the root --id-only contract (id + status).\n const subject = isPlainObject(result.item)\n ? result.item\n : isPlainObject(result.plan)\n ? result.plan\n : null;\n if (subject === null) {\n return null;\n }\n const id = typeof subject.id === \"string\" ? subject.id : undefined;\n const status =\n typeof subject.status === \"string\" ? subject.status : undefined;\n if (!id) {\n return null;\n }\n return status ? { id, status } : { id };\n}\n\nfunction projectCompactMutationEnvelope(result: unknown): unknown | null {\n if (!isPlainObject(result) || !isPlainObject(result.item)) return null;\n if (typeof result.item.id !== \"string\") return null;\n const changedFields = result[CHANGED_FIELDS_KEY];\n if (!Array.isArray(changedFields)) return null;\n const compact: Record<string, unknown> = {\n id: result.item.id,\n ...(typeof result.item.status === \"string\"\n ? { status: result.item.status }\n : {}),\n changed_field_count: changedFields.length,\n };\n const closeReason =\n typeof result.close_reason === \"string\"\n ? result.close_reason\n : typeof result.item.close_reason === \"string\"\n ? result.item.close_reason\n : undefined;\n if (closeReason !== undefined) compact.close_reason = closeReason;\n if (Array.isArray(result.warnings) && result.warnings.length > 0)\n compact.warnings = result.warnings;\n return compact;\n}\n\nfunction compactUpdateManyRows(envelope: Record<string, unknown>): {\n projected: Record<string, unknown>;\n changed: boolean;\n} {\n const rows = isUpdateManyMutationEnvelope(envelope)\n ? envelope[ROWS_KEY]\n : undefined;\n if (!Array.isArray(rows)) {\n return { projected: envelope, changed: false };\n }\n let rowsChanged = false;\n const nextRows = rows.map((row) => {\n if (!isPlainObject(row)) {\n return row;\n }\n const compactedRow = compactOwnChangedFields(row);\n if (compactedRow) {\n rowsChanged = true;\n return compactedRow;\n }\n return row;\n });\n return rowsChanged\n ? { projected: replaceRows(envelope, nextRows), changed: true }\n : { projected: envelope, changed: false };\n}\n\n/** Returns a copy of a mutation result with the envelope `changed_fields` arrays replaced by `changed_field_count` when compact mode is requested. Inputs that are not a mutation envelope (or full mode) are returned unchanged (same reference). */\nexport function projectMutationResult(\n result: unknown,\n options: MutationProjectionOptions = {},\n): unknown {\n if (options.idOnly === true) {\n const idOnly = projectIdOnlyResult(result);\n if (idOnly !== null) {\n return idOnly;\n }\n }\n\n if (options.compactEnvelope === true) {\n const compact = projectCompactMutationEnvelope(result);\n if (compact !== null) return compact;\n }\n\n const mode = options.changedFields ?? \"full\";\n if (mode === \"full\" || !isPlainObject(result)) {\n return result;\n }\n\n let changed = false;\n let projected: Record<string, unknown> = result;\n\n const compactedTop = isMutationEnvelope(result)\n ? compactOwnChangedFields(result)\n : null;\n if (compactedTop !== null) {\n projected = compactedTop;\n changed = true;\n }\n\n const rowProjection = compactUpdateManyRows(projected);\n if (rowProjection.changed) {\n projected = rowProjection.projected;\n changed = true;\n }\n\n return changed ? projected : result;\n}\n","/**\n * @module core/output/output\n *\n * Formats compact human and machine output for Output.\n */\nimport {\n runActiveCommandOverride,\n runActiveRendererOverride,\n runActiveServiceOverrideSync,\n setActiveCommandResult,\n} from \"../extensions/index.js\";\nimport { EXIT_CODE } from \"../shared/constants.js\";\nimport { isHostOutputSuppressed } from \"./output-control.js\";\nimport { projectMutationResult } from \"./mutation-projection.js\";\n\n/** Documents the output options payload exchanged by command, SDK, and package integrations. */\nexport interface OutputOptions {\n /** Value that configures or reports json for this contract. */\n json?: boolean;\n /** Value that configures or reports quiet for this contract. */\n quiet?: boolean;\n /** When true, mutation results drop the verbose changed_fields array (keeps changed_field_count). */\n noChangedFields?: boolean;\n /** When true, preserve the legacy full mutation envelope and changed-fields array. */\n fullChangedFields?: boolean;\n /** When true, single-item mutation results print only id and status. */\n idOnly?: boolean;\n /** When true, JSON output omits null, undefined, and empty containers recursively. */\n lean?: boolean;\n /** Fallback output format used when callers do not provide an override. */\n defaultOutputFormat?: \"toon\" | \"json\";\n /** Value that configures or reports command for this contract. */\n command?: string;\n /** Value that configures or reports command args for this contract. */\n commandArgs?: string[];\n /** Inputs that customize the command operation. */\n commandOptions?: Record<string, unknown>;\n /** Value that configures or reports pm root for this contract. */\n pmRoot?: string;\n}\n\ninterface NodeLikeError {\n code?: string;\n}\n\nconst NATIVE_OUTPUT_MARKER = \"__pm_native_output\";\n\nlet streamErrorHandlersInstalled = false;\ntype OutputStreamTarget = \"stdout\" | \"stderr\";\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction shouldUseNativeOutput(result: unknown): boolean {\n return isPlainObject(result) && result[NATIVE_OUTPUT_MARKER] === true;\n}\n\nfunction stripNativeOutputMarker<T>(result: T): T {\n if (!isPlainObject(result) || result[NATIVE_OUTPUT_MARKER] !== true) {\n return result;\n }\n const { [NATIVE_OUTPUT_MARKER]: _marker, ...rest } = result;\n return rest as T;\n}\n\nfunction isBrokenPipeError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n (error as NodeLikeError).code === \"EPIPE\"\n );\n}\n\nfunction markStdoutBrokenPipeExitCode(): void {\n if (\n process.exitCode === undefined ||\n process.exitCode === EXIT_CODE.SUCCESS\n ) {\n process.exitCode = EXIT_CODE.SUCCESS;\n }\n}\n\nfunction markStderrBrokenPipeExitCode(): void {\n if (\n process.exitCode === undefined ||\n process.exitCode === EXIT_CODE.SUCCESS\n ) {\n process.exitCode = EXIT_CODE.GENERIC_FAILURE;\n }\n}\n\nfunction markBrokenPipeExitCode(target: OutputStreamTarget): void {\n if (target === \"stdout\") {\n markStdoutBrokenPipeExitCode();\n return;\n }\n markStderrBrokenPipeExitCode();\n}\n\nfunction handleUnhandledStreamError(error: unknown): void {\n const unhandled = error instanceof Error ? error : new Error(String(error));\n setImmediate(() => {\n throw unhandled;\n });\n}\n\nfunction installStreamErrorHandlers(): void {\n if (streamErrorHandlersInstalled) {\n return;\n }\n streamErrorHandlersInstalled = true;\n process.stdout.on(\"error\", (error: unknown) => {\n if (isBrokenPipeError(error)) {\n markBrokenPipeExitCode(\"stdout\");\n return;\n }\n handleUnhandledStreamError(error);\n });\n process.stderr.on(\"error\", (error: unknown) => {\n if (isBrokenPipeError(error)) {\n markBrokenPipeExitCode(\"stderr\");\n return;\n }\n handleUnhandledStreamError(error);\n });\n}\n\nfunction writeToStream(target: OutputStreamTarget, text: string): boolean {\n installStreamErrorHandlers();\n try {\n if (target === \"stdout\") {\n process.stdout.write(text);\n } else {\n process.stderr.write(text);\n }\n return true;\n } catch (error: unknown) {\n if (isBrokenPipeError(error)) {\n markBrokenPipeExitCode(target);\n return false;\n }\n throw error;\n }\n}\n\n/** Implements write stdout for the public runtime surface of this module. */\nexport function writeStdout(text: string): boolean {\n return writeToStream(\"stdout\", text);\n}\n\n/** Implements write stderr for the public runtime surface of this module. */\nexport function writeStderr(text: string): boolean {\n return writeToStream(\"stderr\", text);\n}\n\nfunction renderScalar(value: unknown): string {\n if (typeof value === \"string\") return JSON.stringify(value);\n if (typeof value === \"number\" || typeof value === \"boolean\")\n return String(value);\n if (value === null) return \"null\";\n return JSON.stringify(value);\n}\n\nfunction compactToonValue(value: unknown): unknown | undefined {\n if (value === null || value === undefined) {\n return undefined;\n }\n\n if (Array.isArray(value)) {\n const compactedEntries = value\n .map((entry) => compactToonValue(entry))\n .filter((entry): entry is unknown => entry !== undefined);\n return compactedEntries.length > 0 ? compactedEntries : undefined;\n }\n\n if (isPlainObject(value)) {\n const compacted: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value)) {\n const compactedEntry = compactToonValue(entry);\n if (compactedEntry !== undefined) {\n compacted[key] = compactedEntry;\n }\n }\n return Object.keys(compacted).length > 0 ? compacted : undefined;\n }\n\n return value;\n}\n\nfunction renderToonValue(value: unknown, depth: number): string {\n const indent = \" \".repeat(depth);\n\n if (Array.isArray(value)) {\n if (value.length === 0) return \"[]\";\n return value\n .map((entry) => {\n if (!isPlainObject(entry) && !Array.isArray(entry)) {\n return `${indent}- ${renderScalar(entry)}`;\n }\n const rendered = renderToonValue(entry, depth + 1);\n const lines = rendered.split(\"\\n\");\n const [firstLine, ...rest] = lines;\n if (rest.length === 0) {\n return `${indent}- ${firstLine.trimStart()}`;\n }\n return `${indent}- ${firstLine.trimStart()}\\n${rest.join(\"\\n\")}`;\n })\n .join(\"\\n\");\n }\n\n if (isPlainObject(value)) {\n const entries = Object.entries(value);\n if (entries.length === 0) return \"{}\";\n return entries\n .map(([key, entry]) => {\n if (!isPlainObject(entry) && !Array.isArray(entry)) {\n return `${indent}${key}: ${renderScalar(entry)}`;\n }\n if (Array.isArray(entry) && entry.length === 0) {\n return `${indent}${key}: []`;\n }\n if (isPlainObject(entry) && Object.keys(entry).length === 0) {\n return `${indent}${key}: {}`;\n }\n return `${indent}${key}:\\n${renderToonValue(entry, depth + 1)}`;\n })\n .join(\"\\n\");\n }\n\n return `${indent}${renderScalar(value)}`;\n}\n\nfunction renderDefaultMarkdownResult(value: unknown): string | null {\n if (!isPlainObject(value) || value.output_default !== \"markdown\") {\n return null;\n }\n if (\n typeof value.view !== \"string\" ||\n !Array.isArray(value.events) ||\n !Array.isArray(value.days)\n ) {\n return null;\n }\n const lines = [`# pm calendar (${value.view})`, \"\"];\n const summary = isPlainObject(value.summary) ? value.summary : {};\n lines.push(`- events: ${String(summary.events ?? 0)}`);\n lines.push(\"\");\n if (value.events.length === 0) {\n lines.push(\"No calendar events matched the selected filters.\");\n return `${lines.join(\"\\n\")}\\n`;\n }\n for (const event of value.events) {\n if (!isPlainObject(event)) {\n continue;\n }\n const kind = typeof event.kind === \"string\" ? event.kind : \"event\";\n const title = typeof event.item_title === \"string\" ? event.item_title : \"\";\n const itemId = typeof event.item_id === \"string\" ? event.item_id : \"\";\n const reminderText =\n typeof event.reminder_text === \"string\" && event.reminder_text.length > 0\n ? ` ${event.reminder_text}`\n : \"\";\n lines.push(`- [${kind}] ${itemId} ${title}${reminderText}`.trim());\n }\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nfunction resolveOutputFormat(options: OutputOptions): \"json\" | \"toon\" {\n return options.json === true ||\n (options.json === undefined && options.defaultOutputFormat === \"json\")\n ? \"json\"\n : \"toon\";\n}\n\n/** Formats a command result after command-level output ownership is resolved. */\nfunction formatEffectiveOutput(\n effectiveResult: unknown,\n nativeOutput: boolean,\n options: OutputOptions,\n): string {\n const format = resolveOutputFormat(options);\n const serviceOverride = nativeOutput\n ? { handled: false, result: effectiveResult }\n : runActiveServiceOverrideSync(\"output_format\", {\n command: options.command,\n args: options.commandArgs,\n command_options: options.commandOptions,\n global: { ...options },\n pm_root: options.pmRoot,\n format,\n options: { ...options },\n result: effectiveResult,\n });\n if (serviceOverride.handled && typeof serviceOverride.result === \"string\") {\n return serviceOverride.result.endsWith(\"\\n\")\n ? serviceOverride.result\n : `${serviceOverride.result}\\n`;\n }\n const outputResult = serviceOverride.handled\n ? serviceOverride.result\n : effectiveResult;\n if (format === \"toon\") {\n const markdownDefault = renderDefaultMarkdownResult(outputResult);\n if (markdownDefault !== null) {\n return markdownDefault;\n }\n }\n const rendererOverride = nativeOutput\n ? { rendered: null }\n : runActiveRendererOverride(format, outputResult);\n if (rendererOverride.rendered !== null) {\n return rendererOverride.rendered.endsWith(\"\\n\")\n ? rendererOverride.rendered\n : `${rendererOverride.rendered}\\n`;\n }\n if (format === \"json\") {\n const jsonResult =\n options.lean === true\n ? (compactToonValue(outputResult) ?? null)\n : outputResult;\n return `${JSON.stringify(jsonResult, null, 2)}\\n`;\n }\n const compactedToon = compactToonValue(outputResult);\n if (compactedToon === undefined) {\n return \"{}\\n\";\n }\n return `${renderToonValue(compactedToon, 0)}\\n`;\n}\n\n/** Implements format output for the public runtime surface of this module. */\nexport function formatOutput(result: unknown, options: OutputOptions): string {\n const commandOverride = runActiveCommandOverride(result);\n const suppressedOutput = isHostOutputSuppressed(commandOverride.result)\n ? commandOverride.result\n : null;\n const nativeOutput = shouldUseNativeOutput(commandOverride.result);\n const effectiveResult = suppressedOutput\n ? suppressedOutput.result\n : stripNativeOutputMarker(commandOverride.result);\n setActiveCommandResult(effectiveResult);\n return suppressedOutput\n ? \"\"\n : formatEffectiveOutput(effectiveResult, nativeOutput, options);\n}\n\n/** Implements print result for the public runtime surface of this module. */\nexport function printResult(result: unknown, options: OutputOptions): void {\n const projected = options.idOnly\n ? projectMutationResult(result, { idOnly: true })\n : options.fullChangedFields\n ? result\n : options.noChangedFields\n ? projectMutationResult(result, { changedFields: \"compact\" })\n : projectMutationResult(result, { compactEnvelope: true });\n const rendered = formatOutput(projected, options);\n if (options.quiet) {\n return;\n }\n writeStdout(rendered);\n}\n\n/** Implements print error for the public runtime surface of this module. */\nexport function printError(message: string): void {\n const override = runActiveServiceOverrideSync(\"error_format\", {\n message,\n });\n const rendered =\n override.handled && typeof override.result === \"string\"\n ? override.result\n : message;\n writeStderr(rendered.endsWith(\"\\n\") ? rendered : `${rendered}\\n`);\n}\n\n/** Public contract for output test only, shared by SDK and presentation-layer consumers. */\nexport const outputTestOnly = {\n compactToonValue,\n renderToonValue,\n};\n"],"names":["isPlainObject"],"mappings":";;;;;;;;;;;;;AAMA,IAAM,2BAA2B;AAG1B,IAAM,8BACX;AAWI,SAAU,mBACd,QAAgB;AAEhB,SAAO,WAAW,SACd,EAAE,2BAA2B,4BAA2B,IACxD,EAAE,2BAA2B,6BAA6B,OAAM;AACtE;AAGM,SAAU,uBACd,OAAc;AAEd,SACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACnB,MAAkC,wBAAwB,MACzD;AAEN;;;ACNA,IAAM,qBAAqB;AAC3B,IAAM,0BAA0B;AAChC,IAAM,WAAW;AACjB,IAAM,6BAA6B,oBAAI,IAAI,CAAC,SAAS,UAAU,CAAC;AAEhE,SAAS,cAAc,OAAc;AACnC,MAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK,GAAG;AACvE,WAAO;EACT;AACA,QAAM,QAAQ,OAAO,eAAe,KAAK;AACzC,SAAO,UAAU,QAAQ,UAAU,OAAO;AAC5C;AAGA,SAAS,wBACP,UAAiC;AAEjC,QAAM,gBAAgB,SAAS,kBAAkB;AACjD,MAAI,CAAC,MAAM,QAAQ,aAAa,GAAG;AACjC,WAAO;EACT;AACA,QAAM,YACJ,OAAO,eAAe,QAAQ,MAAM,OAAO,uBAAO,OAAO,IAAI,IAAI,CAAA;AACnE,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACnD,QAAI,QAAQ,oBAAoB;AAC9B,gBAAU,GAAG,IAAI;IACnB;EACF;AACA,YAAU,uBAAuB,IAAI,cAAc;AACnD,SAAO;AACT;AAEA,SAAS,mBAAmB,OAA8B;AACxD,SAAO,UAAU,SAAS,MAAM,QAAQ,MAAM,kBAA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QAAM,mBAAmB,uBAAuB,gBAAgB,MAAM,IAClE,gBAAgB,SAChB;AACJ,QAAM,eAAe,sBAAsB,gBAAgB,MAAM;AACjE,QAAM,kBAAkB,mBACpB,iBAAiB,SACjB,wBAAwB,gBAAgB,MAAM;AAClD,yBAAuB,eAAe;AACtC,SAAO,mBACH,KACA,sBAAsB,iBAAiB,cAAc,OAAO;AAClE;AAGM,SAAU,YAAY,QAAiB,SAAsB;AACjE,QAAM,YAAY,QAAQ,SACtB,sBAAsB,QAAQ,EAAE,QAAQ,KAAI,CAAE,IAC9C,QAAQ,oBACN,SACA,QAAQ,kBACN,sBAAsB,QAAQ,EAAE,eAAe,UAAS,CAAE,IAC1D,sBAAsB,QAAQ,EAAE,iBAAiB,KAAI,CAAE;AAC/D,QAAM,WAAW,aAAa,WAAW,OAAO;AAChD,MAAI,QAAQ,OAAO;AACjB;EACF;AACA,cAAY,QAAQ;AACtB;AAGM,SAAU,WAAW,SAAe;AACxC,QAAM,WAAW,6BAA6B,gBAAgB;IAC5D;GACD;AACD,QAAM,WACJ,SAAS,WAAW,OAAO,SAAS,WAAW,WAC3C,SAAS,SACT;AACN,cAAY,SAAS,SAAS,IAAI,IAAI,WAAW,GAAG,QAAQ;CAAI;AAClE","debugId":"96f03a19-9c65-508e-a60b-793c28248a9d"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runCreate
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-4PUUNQDV.js";
|
|
4
4
|
import {
|
|
5
5
|
splitCommaList
|
|
6
6
|
} from "./chunk-D6HZN36B.js";
|
|
@@ -1493,4 +1493,4 @@ export {
|
|
|
1493
1493
|
resolvePlanTemplateSteps,
|
|
1494
1494
|
runPlan
|
|
1495
1495
|
};
|
|
1496
|
-
//# sourceMappingURL=chunk-
|
|
1496
|
+
//# sourceMappingURL=chunk-VLRGDBLY.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CREATE_COMMANDER_REPEATABLE_OPTION_CONTRACTS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-P7MTHPJQ.js";
|
|
4
4
|
import {
|
|
5
5
|
ensureTypeFolderScaffold
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7RW4JCU2.js";
|
|
7
7
|
import {
|
|
8
8
|
lintProjectProfile,
|
|
9
9
|
resolveProfileCatalog,
|
|
@@ -875,4 +875,4 @@ export {
|
|
|
875
875
|
formatProfileLintHuman,
|
|
876
876
|
formatProfileApplyHuman
|
|
877
877
|
};
|
|
878
|
-
//# sourceMappingURL=chunk-
|
|
878
|
+
//# sourceMappingURL=chunk-VNTCM3VW.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
renameArtifactsResultKey,
|
|
5
5
|
runLinkedArtifacts,
|
|
6
6
|
sortLinkedArtifacts
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-OCUBRA6D.js";
|
|
8
8
|
import {
|
|
9
9
|
resolveAuthor
|
|
10
10
|
} from "./chunk-YRYYFGV3.js";
|
|
@@ -314,4 +314,4 @@ export {
|
|
|
314
314
|
runFiles,
|
|
315
315
|
runFilesDiscover
|
|
316
316
|
};
|
|
317
|
-
//# sourceMappingURL=chunk-
|
|
317
|
+
//# sourceMappingURL=chunk-VXOOB6YX.js.map
|
|
@@ -2,12 +2,10 @@ import {
|
|
|
2
2
|
ensureMaterializedHistoryTarget,
|
|
3
3
|
readHistoryEntries,
|
|
4
4
|
replayHistoryToTarget,
|
|
5
|
+
replayToCanonicalItemDocument,
|
|
5
6
|
resolveHistorySubject,
|
|
6
7
|
resolveHistoryTarget
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import {
|
|
9
|
-
replayToCanonicalItemDocument
|
|
10
|
-
} from "./chunk-E6LEMURX.js";
|
|
8
|
+
} from "./chunk-2L6ZP22J.js";
|
|
11
9
|
import {
|
|
12
10
|
getActiveExtensionRegistrations,
|
|
13
11
|
readSettings
|
|
@@ -63,4 +61,4 @@ async function getItemAt(id, target, options = {}) {
|
|
|
63
61
|
export {
|
|
64
62
|
getItemAt
|
|
65
63
|
};
|
|
66
|
-
//# sourceMappingURL=chunk-
|
|
64
|
+
//# sourceMappingURL=chunk-VZIZB6QH.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../../sdk/history-read.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * @module sdk/history-read\n *\n * Public, mutation-free item time-travel reads backed by the same verified\n * replay kernel used by `pm restore`. Integrators can use this primitive as a\n * building block for provenance browsers, immutable records, and VCS-like\n * systems without acquiring locks or appending history.\n */\nimport { getActiveExtensionRegistrations } from \"../core/extensions/index.js\";\nimport { pathExists } from \"../core/fs/fs-utils.js\";\nimport {\n applyHistoryPatch,\n ensureMaterializedHistoryTarget,\n extractPatchFailureContext,\n replayHistoryToTarget,\n resolveHistoryTarget,\n type ResolvedHistoryTarget,\n} from \"../core/history/projection.js\";\nimport { readHistoryEntries } from \"../core/history/read.js\";\nimport { replayToCanonicalItemDocument } from \"../core/history/replay.js\";\nimport { resolveItemTypeRegistry } from \"../core/item/type-registry.js\";\nimport { EXIT_CODE } from \"../core/shared/constants.js\";\nimport { PmCliError } from \"../core/shared/errors.js\";\nimport { getSettingsPath, resolvePmRoot } from \"../core/store/paths.js\";\nimport { readSettings } from \"../core/store/settings.js\";\nimport type { ItemDocument } from \"../types/index.js\";\nimport { resolveHistorySubject } from \"./history-redact.js\";\n\n/** Workspace resolution controls accepted by {@link getItemAt}. */\nexport interface GetItemAtOptions {\n /** Explicit tracker root, equivalent to the CLI global `--pm-path`. */\n pmRoot?: string;\n /** Working directory used when discovering the nearest tracker. */\n cwd?: string;\n}\n\n/** Verified historical item projection returned by {@link getItemAt}. */\nexport interface GetItemAtResult {\n /** Reconstructed canonical item document at the selected version. */\n document: ItemDocument;\n /** Always true, preventing consumers from confusing this with current state. */\n reconstructed: true;\n /** One-based version included in the projection. */\n as_of_version: number;\n /** Timestamp of the final included history entry. */\n as_of_timestamp: string;\n /** Normalized target resolution metadata shared with restore. */\n target: ResolvedHistoryTarget;\n /** Total number of entries currently available in the stream. */\n history_length: number;\n}\n\n/**\n * Reconstruct one item at a one-based version or ISO timestamp without locks,\n * item writes, history writes, or derived-index mutations.\n */\nexport async function getItemAt(\n id: string,\n target: string,\n options: GetItemAtOptions = {},\n): Promise<GetItemAtResult> {\n const pmRoot = resolvePmRoot(options.cwd ?? process.cwd(), options.pmRoot);\n if (!(await pathExists(getSettingsPath(pmRoot)))) {\n throw new PmCliError(\n `Tracker is not initialized at ${pmRoot}. Run pm init first.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n const settings = await readSettings(pmRoot);\n const typeRegistry = resolveItemTypeRegistry(\n settings,\n getActiveExtensionRegistrations(),\n );\n const subject = await resolveHistorySubject(\n pmRoot,\n id,\n settings,\n typeRegistry.type_to_folder,\n );\n const history = await readHistoryEntries(subject.historyPath, subject.id);\n if (history.length === 0) {\n throw new PmCliError(\n `No history exists for ${subject.id}; point-in-time reads are unavailable.`,\n EXIT_CODE.NOT_FOUND,\n );\n }\n const resolvedTarget = resolveHistoryTarget(target, history);\n const replay = ensureMaterializedHistoryTarget(\n replayHistoryToTarget(history, resolvedTarget.historyIndex),\n resolvedTarget,\n );\n const document = replayToCanonicalItemDocument(replay, {\n schema: settings.schema,\n });\n if (document.metadata.id !== subject.id) {\n throw new PmCliError(\n `History target resolved to item ${document.metadata.id}, expected ${subject.id}.`,\n EXIT_CODE.GENERIC_FAILURE,\n );\n }\n const targetEntry = history[resolvedTarget.historyIndex];\n return {\n document,\n reconstructed: true,\n as_of_version: resolvedTarget.historyIndex + 1,\n as_of_timestamp: targetEntry.ts,\n target: resolvedTarget,\n history_length: history.length,\n };\n}\n\nexport {\n applyHistoryPatch,\n ensureMaterializedHistoryTarget,\n extractPatchFailureContext,\n readHistoryEntries,\n replayHistoryToTar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|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YCIUJJOD.js";
|
|
5
5
|
import {
|
|
6
6
|
parseLimit
|
|
7
7
|
} from "./chunk-UVN66B3M.js";
|
|
@@ -328,4 +328,4 @@ export {
|
|
|
328
328
|
runAnnotationCommand,
|
|
329
329
|
resolveAnnotationIndex
|
|
330
330
|
};
|
|
331
|
-
//# sourceMappingURL=chunk-
|
|
331
|
+
//# sourceMappingURL=chunk-X3W65QK3.js.map
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
requireStringOption,
|
|
28
28
|
resolvePriority,
|
|
29
29
|
resolveRuntimeUnsetFieldDefinition
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-MWQ2HC2A.js";
|
|
31
31
|
import {
|
|
32
32
|
assertParentReferenceIsNotSelf,
|
|
33
33
|
normalizeParentReferenceValue,
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
parseOptionalNumber,
|
|
55
55
|
parseTags,
|
|
56
56
|
splitAcceptanceCriteria
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-AELMUANP.js";
|
|
58
58
|
import {
|
|
59
59
|
runClose
|
|
60
60
|
} from "./chunk-OWXOPDHD.js";
|
|
@@ -1698,6 +1698,6 @@ export {
|
|
|
1698
1698
|
runUpdate,
|
|
1699
1699
|
_testOnlyUpdateCommand
|
|
1700
1700
|
};
|
|
1701
|
-
//# sourceMappingURL=chunk-
|
|
1701
|
+
//# sourceMappingURL=chunk-XJTABV3X.js.map
|
|
1702
1702
|
|
|
1703
1703
|
//# debugId=f7652cf1-aaa9-5fe4-97b5-23dcce2a9d9f
|