@unbrained/pm-cli 2026.8.4 → 2026.8.6
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 +53 -13
- package/dist/cli/error-guidance.js +4 -4
- package/dist/cli/main.js +12 -37
- package/dist/cli/register-setup.d.ts +1 -1
- package/dist/cli/register-setup.js +46 -20
- package/dist/cli/register-structured-mutation.d.ts +2 -0
- package/dist/cli/register-structured-mutation.js +124 -12
- package/dist/cli-bundle/bundle-manifest.json +397 -397
- package/dist/cli-bundle/chunks/append-XAJ5Z4XS.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-QVO3VTA4.js → chunk-343QETLI.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-Q5F6OI7C.js → chunk-3KFVGGRE.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-6S7I3UKV.js → chunk-3ZJRFYY2.js} +19 -19
- package/dist/cli-bundle/chunks/{chunk-NFF3JAQR.js → chunk-4AVFKHHC.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-5H47J5FG.js → chunk-4OVGQW22.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-D2MBVMVE.js → chunk-5PBP2ZP3.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-5ZKQPA44.js +2 -0
- package/dist/cli-bundle/chunks/chunk-A3XQ7VPU.js +2 -0
- package/dist/cli-bundle/chunks/chunk-AJE3AHPD.js +8 -0
- package/dist/cli-bundle/chunks/{chunk-2POYGY53.js → chunk-AOBDLU4T.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-PYYPQLHC.js → chunk-AYRUGRNS.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-QMWUL66F.js → chunk-BP6EMEDP.js} +5 -5
- package/dist/cli-bundle/chunks/{chunk-UVZREFZU.js → chunk-C3YABSJK.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-RB65T4RX.js → chunk-CA3BURYF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-KIKLF2W4.js → chunk-D7I3TUGV.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-PQXEB7W4.js → chunk-DQGJ2RWT.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-OB7TRZ2G.js → chunk-DWOAOZHZ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-SVDH5CHC.js → chunk-E7BFPLUZ.js} +4 -4
- package/dist/cli-bundle/chunks/{chunk-CGY5I2GO.js → chunk-F4NREH3G.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-DCJ6CM6F.js → chunk-FDBRXV25.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-NM5G7RLU.js → chunk-GU3TSEHD.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-HS7OVAUN.js +164 -0
- package/dist/cli-bundle/chunks/{chunk-CU5ENFNP.js → chunk-JFZIS6JF.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-GOICHIX4.js → chunk-JQ4NZ5EB.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HE3DZFN4.js → chunk-L6LGKJX3.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-BLINBTMX.js → chunk-M357ZCOR.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-NRDKVOUE.js → chunk-M4VEE3FK.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HTYC76A4.js → chunk-MCS73BKB.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-BKMZTZYL.js → chunk-MDTH7SAE.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-H6FITE7D.js → chunk-NE5VRDAI.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-NPUJ7OLK.js → chunk-OXY3SJ3N.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-PECV7L5T.js +2 -0
- package/dist/cli-bundle/chunks/{chunk-KH4GVBMC.js → chunk-Q3VOP62W.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-FQ4EFFDU.js → chunk-QJ7C3JIW.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-VH2EAGUG.js → chunk-R6LSRGPS.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-HQ2WU7OY.js → chunk-R6RKEYYW.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-PA5XRN2A.js → chunk-RAFUN7IX.js} +4 -4
- package/dist/cli-bundle/chunks/chunk-RUAU5OSH.js +2 -0
- package/dist/cli-bundle/chunks/chunk-SD3YXU2U.js +56 -0
- package/dist/cli-bundle/chunks/{chunk-JMKVCQSE.js → chunk-SV3YQ4RY.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-B5ZLCD5Z.js → chunk-SVV3DQES.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-J4EPW4GT.js → chunk-SXECIECW.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-T45OHXDW.js +8 -0
- package/dist/cli-bundle/chunks/{chunk-NH35JNK5.js → chunk-TPKDJ5WL.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-ZSH4GNBH.js → chunk-UVVXHGYS.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-V663653R.js +20 -0
- package/dist/cli-bundle/chunks/{chunk-5PZGZMPG.js → chunk-WSI5KZQJ.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-3XZYTRPC.js → chunk-XPOQQJTX.js} +2 -2
- package/dist/cli-bundle/chunks/{chunk-UJHUR3LZ.js → chunk-YCCDXBNU.js} +2 -2
- package/dist/cli-bundle/chunks/chunk-ZFBWCKYF.js +2 -0
- package/dist/cli-bundle/chunks/close-DI66JMSB.js +2 -0
- package/dist/cli-bundle/chunks/close-many-VFKT6U3O.js +2 -0
- package/dist/cli-bundle/chunks/comments-E73HIEZJ.js +2 -0
- package/dist/cli-bundle/chunks/copy-WBYVLCPC.js +2 -0
- package/dist/cli-bundle/chunks/{create-RLLCBCXM.js → create-TG67IVFI.js} +2 -2
- package/dist/cli-bundle/chunks/delete-6XKUVVQN.js +2 -0
- package/dist/cli-bundle/chunks/{deps-J4ONTF4X.js → deps-AJUGP2OH.js} +2 -2
- package/dist/cli-bundle/chunks/{docs-YL2DJ4WD.js → docs-QOCLDRKJ.js} +2 -2
- package/dist/cli-bundle/chunks/{files-NGNAIYKK.js → files-3ST5TY64.js} +2 -2
- package/dist/cli-bundle/chunks/focus-R2AWS63Y.js +2 -0
- package/dist/cli-bundle/chunks/{history-compact-HW62K5XP.js → history-compact-7BJFML4S.js} +2 -2
- package/dist/cli-bundle/chunks/{history-redact-HVBKUJOW.js → history-redact-WJN3HYXR.js} +2 -2
- package/dist/cli-bundle/chunks/{history-repair-OPNBH5JJ.js → history-repair-XDNZUB7F.js} +2 -2
- package/dist/cli-bundle/chunks/{learnings-F36PZXT6.js → learnings-SZMUPVNA.js} +2 -2
- package/dist/cli-bundle/chunks/{profile-N3XMWBM7.js → profile-KL53JIAC.js} +2 -2
- package/dist/cli-bundle/chunks/{register-list-query-BKGHBI7Y.js → register-list-query-QH7ONPKU.js} +2 -2
- package/dist/cli-bundle/chunks/register-mutation-OCRQNZK4.js +20 -0
- package/dist/cli-bundle/chunks/register-operations-HIBJXRGB.js +2 -0
- package/dist/cli-bundle/chunks/register-setup-QWBQ6HBS.js +2 -0
- package/dist/cli-bundle/chunks/restore-FXA5QPM7.js +2 -0
- package/dist/cli-bundle/chunks/{schema-4PJQMGUY.js → schema-QJ27OTRV.js} +2 -2
- package/dist/cli-bundle/chunks/update-7GBO4SXG.js +2 -0
- package/dist/cli-bundle/chunks/update-many-VF6ZKQUO.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-27DK4A5O.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-4JC3AOGS.js +8 -0
- package/dist/cli-bundle/focused-chunks/chunk-6KDHXURF.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-74CWP3A4.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-7AZDTGPA.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-7YTZ7A4E.js +2 -0
- package/dist/cli-bundle/focused-chunks/{chunk-ONIX2KKW.js → chunk-CL3NB7VW.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-EAXXF2HW.js +4 -0
- package/dist/cli-bundle/focused-chunks/{chunk-L6A4NVQC.js → chunk-EYO4F74Z.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-GEYU23YS.js +153 -0
- package/dist/cli-bundle/focused-chunks/{chunk-DQ4PLKEE.js → chunk-GIERI4YU.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-GSW2Y7VZ.js +5 -0
- package/dist/cli-bundle/focused-chunks/{chunk-WVGJAD7L.js → chunk-LKQXXO62.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-UFCPSWIL.js → chunk-MBBMTDD3.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-OYTK4VNH.js → chunk-ME4XVOBJ.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-RO5BQFG3.js → chunk-N7QN3NE6.js} +2 -2
- package/dist/cli-bundle/focused-chunks/chunk-QL5H3AQH.js +2 -0
- package/dist/cli-bundle/focused-chunks/chunk-TQMFQYXR.js +29 -0
- package/dist/cli-bundle/focused-chunks/{chunk-SQXVGHMH.js → chunk-XNVXIQ4B.js} +2 -2
- package/dist/cli-bundle/focused-chunks/{chunk-BOGRY7M6.js → chunk-YHDCGUIW.js} +10 -10
- package/dist/cli-bundle/focused-chunks/{chunk-K37BB4JL.js → chunk-YLPZHWX7.js} +2 -2
- package/dist/cli-bundle/main.js +13 -13
- package/dist/cli-bundle/sdk-authoring.js +1 -1
- package/dist/cli-bundle/sdk-contracts.js +1 -1
- package/dist/cli-bundle/sdk-core.js +28 -28
- package/dist/cli-bundle/sdk-governance.js +1 -1
- package/dist/cli-bundle/sdk-graph.js +1 -1
- package/dist/cli-bundle/sdk-merge.js +1 -1
- package/dist/cli-bundle/sdk-query.js +1 -1
- package/dist/cli-bundle/sdk-runtime.js +1 -1
- package/dist/cli-bundle/sdk-testing.js +1 -1
- package/dist/cli-bundle/sdk.js +1 -1
- package/dist/core/extensions/activation-summary.d.ts +4 -0
- package/dist/core/extensions/activation-summary.js +5 -2
- package/dist/core/extensions/contribution-inventory.d.ts +1 -0
- package/dist/core/extensions/contribution-inventory.js +35 -2
- package/dist/core/extensions/extension-hook-runtime.js +5 -3
- package/dist/core/extensions/extension-types.d.ts +18 -1
- package/dist/core/extensions/extension-types.js +2 -2
- package/dist/core/extensions/loader.js +8 -13
- package/dist/core/extensions/preflight-ownership.d.ts +5 -0
- package/dist/core/extensions/preflight-ownership.js +42 -0
- package/dist/core/item/item-format.js +14 -20
- package/dist/core/shared/constants.js +3 -2
- package/dist/core/store/item-store.js +2 -2
- package/dist/core/store/settings.js +2 -2
- package/dist/mcp/server.js +12 -6
- package/dist/mcp/tool-definitions.js +14 -7
- package/dist/sdk/cli-contracts/agent-output-contracts.d.ts +18 -18
- package/dist/sdk/cli-contracts/agent-output-contracts.js +51 -23
- package/dist/sdk/cli-contracts/commander-mutation-options.js +26 -2
- package/dist/sdk/cli-contracts/flag-contracts.d.ts +4 -0
- package/dist/sdk/cli-contracts/flag-contracts.js +34 -2
- package/dist/sdk/cli-contracts/registration-helpers.js +4 -2
- package/dist/sdk/cli-contracts/runtime-contracts.d.ts +10 -2
- package/dist/sdk/cli-contracts/runtime-contracts.js +21 -5
- package/dist/sdk/cli-contracts/tool-schema.js +4 -2
- package/dist/sdk/cli-contracts.d.ts +2 -2
- package/dist/sdk/cli-contracts.js +4 -4
- package/dist/sdk/cli-program.js +3 -3
- package/dist/sdk/compose.d.ts +2 -2
- package/dist/sdk/compose.js +7 -2
- package/dist/sdk/contracts.d.ts +1 -0
- package/dist/sdk/contracts.js +3 -2
- package/dist/sdk/define.d.ts +3 -1
- package/dist/sdk/define.js +3 -8
- package/dist/sdk/dependency-provenance.d.ts +2 -0
- package/dist/sdk/dependency-provenance.js +7 -3
- package/dist/sdk/error-code-catalog.d.ts +23 -0
- package/dist/sdk/error-code-catalog.js +25 -5
- package/dist/sdk/extension/install-sources.d.ts +43 -5
- package/dist/sdk/extension/install-sources.js +36 -2
- package/dist/sdk/extension/migrations.d.ts +114 -0
- package/dist/sdk/extension/migrations.js +175 -0
- package/dist/sdk/extension/scaffold.js +14 -9
- package/dist/sdk/extension/source-resolution.d.ts +50 -0
- package/dist/sdk/extension/source-resolution.js +66 -0
- package/dist/sdk/extension.d.ts +5 -1
- package/dist/sdk/extension.js +24 -26
- package/dist/sdk/generated-error-code-catalog.js +499 -3
- package/dist/sdk/governance/health.js +11 -2
- package/dist/sdk/graph/governance.js +3 -3
- package/dist/sdk/graph/remediation.js +3 -3
- package/dist/sdk/graph/run.js +4 -8
- package/dist/sdk/index.d.ts +7 -2
- package/dist/sdk/index.js +9 -4
- package/dist/sdk/item-transaction.d.ts +51 -6
- package/dist/sdk/item-transaction.js +132 -22
- package/dist/sdk/lifecycle/create.d.ts +4 -0
- package/dist/sdk/lifecycle/create.js +26 -10
- package/dist/sdk/lifecycle-policy.d.ts +9 -0
- package/dist/sdk/lifecycle-policy.js +22 -9
- package/dist/sdk/merge/driver.js +6 -3
- package/dist/sdk/output-contracts.d.ts +67 -0
- package/dist/sdk/output-contracts.js +173 -0
- package/dist/sdk/package-import-adapters.js +2 -2
- package/dist/sdk/package-migrations.d.ts +10 -0
- package/dist/sdk/package-migrations.js +21 -0
- package/dist/sdk/runtime.d.ts +2 -0
- package/dist/sdk/runtime.js +6 -2
- package/dist/sdk/structured-mutations.d.ts +23 -0
- package/dist/sdk/structured-mutations.js +219 -10
- package/dist/sdk/workspace-snapshot.js +58 -12
- package/dist/sdk/workspace.js +30 -4
- package/docs/COMMANDS.md +49 -10
- package/docs/EXTENSIONS.md +3 -3
- package/docs/EXTENSION_LIFECYCLE.md +46 -0
- package/docs/MERGE_SAFETY.md +2 -0
- package/docs/PR_REVIEW_LOOP.md +10 -4
- package/docs/README.md +23 -22
- package/docs/RELEASING.md +36 -23
- package/docs/SCRIPTING.md +32 -9
- package/docs/SDK.md +122 -14
- package/docs/SELF_DESCRIBING_CONTEXT_CONTRACTS.md +13 -0
- package/docs/TESTING.md +25 -0
- package/docs/examples/sdk-contract-consumer/README.md +11 -1
- package/docs/examples/sdk-contract-consumer/package.json +2 -1
- package/docs/examples/sdk-contract-consumer/parse-receipt.mjs +22 -0
- package/marketplace.json +2 -2
- package/package.json +5 -4
- 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-digital-twin/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-codex/.codex-plugin/plugin.json +1 -1
- package/sdk/public-surface.json +508 -32
- package/dist/cli-bundle/chunks/append-DHBRLHHS.js +0 -2
- package/dist/cli-bundle/chunks/chunk-2INN52SU.js +0 -8
- package/dist/cli-bundle/chunks/chunk-377OOXUF.js +0 -55
- package/dist/cli-bundle/chunks/chunk-6RSK4IFN.js +0 -20
- package/dist/cli-bundle/chunks/chunk-ASJJKA57.js +0 -2
- package/dist/cli-bundle/chunks/chunk-IYAVULRN.js +0 -2
- package/dist/cli-bundle/chunks/chunk-JDPKBV5P.js +0 -2
- package/dist/cli-bundle/chunks/chunk-RRQBHQOV.js +0 -2
- package/dist/cli-bundle/chunks/chunk-SULWTPQO.js +0 -8
- package/dist/cli-bundle/chunks/chunk-V5K52PYW.js +0 -164
- package/dist/cli-bundle/chunks/chunk-XBLOD5TZ.js +0 -2
- package/dist/cli-bundle/chunks/close-VLHNN6YB.js +0 -2
- package/dist/cli-bundle/chunks/close-many-LSJNZKU6.js +0 -2
- package/dist/cli-bundle/chunks/comments-AAIA6A6X.js +0 -2
- package/dist/cli-bundle/chunks/copy-Z7YMLEHN.js +0 -2
- package/dist/cli-bundle/chunks/delete-KNOHHQJM.js +0 -2
- package/dist/cli-bundle/chunks/focus-LFRCGALV.js +0 -2
- package/dist/cli-bundle/chunks/register-mutation-GU3DCECN.js +0 -20
- package/dist/cli-bundle/chunks/register-operations-PTWH727R.js +0 -2
- package/dist/cli-bundle/chunks/register-setup-KWV6UD77.js +0 -2
- package/dist/cli-bundle/chunks/restore-4HZSLILR.js +0 -2
- package/dist/cli-bundle/chunks/update-E6LPS5IV.js +0 -2
- package/dist/cli-bundle/chunks/update-many-OSIC6KRO.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-2VIIXOAD.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-5MTKO7TV.js +0 -153
- package/dist/cli-bundle/focused-chunks/chunk-6GIZK7VQ.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-AOP2WIZZ.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-C2QSL62X.js +0 -28
- package/dist/cli-bundle/focused-chunks/chunk-CL75YW32.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-E7OFMWGT.js +0 -8
- package/dist/cli-bundle/focused-chunks/chunk-I5F5UK3Q.js +0 -2
- package/dist/cli-bundle/focused-chunks/chunk-QM2BIVK7.js +0 -4
- package/dist/cli-bundle/focused-chunks/chunk-T5TSY36R.js +0 -5
- package/dist/cli-bundle/focused-chunks/chunk-VT6BF2IX.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{$a as P,Ba as tt,Ia as et,K as V,Ka as rt,L as S,P as W,Pa as nt,Qa as ot,Xa as it,Za as st,ab as D,ea as Y,fa as X,ga as J,k as z,ma as p,n as C,pa as K,ra as _,ta as d,ua as L,ya as Q,za as Z}from"./chunk-5MTKO7TV.js";import{D as M,J as G,M as B,N as q,P as j,p as k,q as H,r as m}from"./chunk-QM2BIVK7.js";import{Y as c,Z as l}from"./chunk-CL75YW32.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="47c087c2-124a-58b7-a5c9-09403235f4a2")}catch{}})();function yt(t,e){let n=-1;return t.forEach((r,o)=>{let i=Date.parse(r.ts);if(!Number.isFinite(i))throw new l(`History for this item contains invalid timestamp at entry ${o+1}.`,c.GENERIC_FAILURE);i<=e&&(n=o)}),n}function wt(t){let e=t[0]?.ts??null,n=t.at(-1)?.ts??null,r={code:"history_target_out_of_range",required:"Choose a target within the available item history.",why:"Point-in-time reads and restores can only reconstruct recorded versions.",examples:[],nextSteps:["Run pm history <id> to inspect available versions and timestamps."],valid_range:{first_version:null,last_version:null,first_timestamp:e,last_timestamp:n}};return n!==null&&(r.examples=["1",String(t.length),n],r.valid_range.first_version=1,r.valid_range.last_version=t.length),{guidance:r,lastTimestamp:n}}function pt(t,e){let n={};if(e instanceof Error&&e.message.trim().length>0&&(n.reason=e.message.trim()),typeof e!="object"||e===null)return n;let r=e;if(typeof r.index=="number"&&Number.isInteger(r.index)&&r.index>=0&&(n.patchIndex=r.index),typeof r.operation=="object"&&r.operation!==null){let o=r.operation;Object.assign(n,Object.fromEntries(["op","path","from"].flatMap(i=>{let s=o[i];return typeof s=="string"?[[i,s]]:[]})))}if(n.patchIndex!==void 0){let o=t[n.patchIndex];o&&(n.op??=o.op,n.path??=o.path,n.from??=o.from)}return n}function Mt(t,e,n={}){let r=t.trim(),o=n.errorSubject??"history",i=o==="restore"?"Restore":"History",{guidance:s,lastTimestamp:a}=wt(e);if(!r)throw new l(`Missing ${o} target. Use a timestamp or version number.`,c.USAGE,s);if(/^\d+$/.test(r)){let u=Number(r);if(!Number.isSafeInteger(u)||u<1||u>e.length)throw new l(`${i} version must be between 1 and ${e.length} for this item.`,c.USAGE,s);return{kind:"version",raw:r,historyIndex:u-1}}let h=Date.parse(r);if(!Number.isFinite(h))throw new l(`Invalid ${o} target "${t}". Use a positive version number or ISO timestamp.`,c.USAGE,s);let f=yt(e,h);if(f<0||n.allowFutureTimestamp!==!0&&h>Date.parse(a))throw new l(o==="restore"?`No history entries exist at or before timestamp ${r}.`:`No history entry exists at timestamp ${r}.`,c.USAGE,s);return{kind:"timestamp",raw:r,historyIndex:f}}function A(t,e,n,r){let o=Q(t,e);if(o.ok)return o.document;let i=pt(e,o.error),s=[`history_op=${r}`,i.patchIndex===void 0?null:`patch_index=${i.patchIndex}`,i.op?`op=${i.op}`:null,i.path?`path=${i.path}`:null,i.from?`from=${i.from}`:null].filter(a=>a!==null);throw new l(`Failed to apply history patch at entry ${n} (${s.join(", ")}). ${i.reason??String(o.error)}`,c.GENERIC_FAILURE)}function Gt(t,e){let n=structuredClone(_);for(let r=0;r<=e;r+=1){let o=t[r];if(!o)throw new l(`History target entry ${r+1} does not exist.`,c.USAGE);if(d(n)!==o.before_hash)throw new l(`History hash mismatch before replay at entry ${r+1}.`,c.GENERIC_FAILURE);if(n=A(n,o.patch,r+1,o.op),d(n)!==o.after_hash)throw new l(`History hash mismatch after replay at entry ${r+1}.`,c.GENERIC_FAILURE)}return n}function Bt(t,e){if(Object.keys(t.metadata).length>0)return t;throw new l(`History target ${e.raw} resolves to a deleted state; choose a version or timestamp where the item exists.`,c.USAGE)}import U from"node:fs/promises";import gt from"node:fs/promises";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="a2ec9f1a-aae2-59d5-8c9a-7acd8bf5a7a2")}catch{}})();function It(t){if(!t.itemDocument)return[];let e=t.itemDocument.metadata?.assignee?.trim();if(!e||e===t.author||t.force)return[];let n=et(t.settings);if(n.ownership_enforcement==="strict")throw new l(`Item ${t.subjectId} is assigned to ${e}. Use --force to override.`,c.CONFLICT);return n.ownership_enforcement==="warn"?[`ownership_warning:assignee_conflict:${t.subjectId}:${e}`]:[]}async function _t(t){let e=await H(t.subject.historyPath);if(e!==t.historyRawBeforeLock)throw new l(`History for ${t.subject.id} changed while waiting for lock; retry ${t.operation}.`,c.CONFLICT);let n=await P(t.pmRoot,t.subject.id,t.settings.id_prefix,t.settings.item_format,t.typeRegistry.type_to_folder),r=n?await D(n,{schema:t.settings.schema}):null;if((r?.raw??null)!==(t.currentItemRawBeforeLock??null))throw new l(`Item ${t.subject.id} changed while waiting for lock; retry ${t.operation}.`,c.CONFLICT);return{historyRawUnderLock:e,locatedUnderLock:n,loadedItemUnderLock:r}}async function Zt(t){let e=t.writeHistoryRaw??m;try{await e(t.historyPath,t.nextHistoryRaw),await p(t.historyPath)}catch(n){try{t.historyRawUnderLock===null?await gt.rm(t.historyPath,{force:!0}):await e(t.historyPath,t.historyRawUnderLock),await p(t.historyPath)}catch(r){throw new AggregateError([n,r],`History rewrite failed and rollback also failed: ${String(n)}`)}throw n}}async function at(t){let e=[...It({itemDocument:t.itemDocument,subjectId:t.subject.id,author:t.author,force:t.force,settings:t.settings})],n=await W(t.pmRoot,t.subject.id,t.settings.locks.ttl_seconds,t.author,!!t.force,t.settings.governance.force_required_for_stale_lock,t.settings.locks.wait_ms);try{let r=await _t({pmRoot:t.pmRoot,subject:t.subject,settings:t.settings,typeRegistry:t.typeRegistry,historyRawBeforeLock:t.historyRawBeforeLock,currentItemRawBeforeLock:t.currentItemRawBeforeLock,operation:t.operation});return await t.applyRewrite(r),t.applyPostRewrite&&e.push(...await t.applyPostRewrite(r)),e}finally{await n()}}(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="cd2a27ec-0f12-591d-ab34-529ddda05063")}catch{}})();function ct(t){return Array.isArray(t)?t:typeof t=="string"?[t]:[]}function xt(t){let e=[];for(let n of t)e.includes(n)||e.push(n);return e.includes("g")||e.push("g"),e.join("")}function bt(t){let e=t.trim();if(e.length===0)throw new l("history-redact --regex requires a non-empty pattern.",c.USAGE);let n=e,r="g";if(e.startsWith("/")&&e.length>1){let o=e.lastIndexOf("/");o>0&&(n=e.slice(1,o),r=xt(e.slice(o+1)))}if(n.length===0)throw new l("history-redact --regex cannot use an empty pattern.",c.USAGE);try{new RegExp(n,r)}catch{throw new l("Invalid --regex value; provide a valid JavaScript regular expression.",c.USAGE)}return{kind:"regex",source:n,flags:r}}function Rt(t,e){let n=[...new Set(ct(t).map(i=>i.trim()))].filter(i=>i.length>0).map(i=>({kind:"literal",value:i})),r=[...new Set(ct(e).map(i=>i.trim()))].filter(i=>i.length>0).map(bt),o=[...n,...r];if(o.length===0)throw new l("history-redact requires at least one matcher via --literal or --regex.",c.USAGE,{code:"missing_required_argument",required:"Provide --literal <value> and/or --regex <pattern>.",examples:['pm history-redact pm-a1b2 --literal "[redacted_path_prefix]/private"','pm history-redact pm-a1b2 --regex "/192\\\\.168\\\\.[0-9.]+/g" --replacement "[scrubbed_ip]"']});return o}function Et(t,e,n){if(e.length===0)return{value:t,replacements:0};let r=0,o=0;for(;r<=t.length;){let i=t.indexOf(e,r);if(i===-1)break;o+=1,r=i+Math.max(1,e.length)}return o===0?{value:t,replacements:0}:{value:t.split(e).join(n),replacements:o}}function vt(t,e,n){let r=new RegExp(e.source,e.flags),o=[...t.matchAll(r)];return o.length===0?{value:t,replacements:0}:{value:t.replace(r,n),replacements:o.length}}function lt(t,e,n){let r=t,o=0;for(let i of e){let s=i.kind==="literal"?Et(r,i.value,n):vt(r,i,n);r=s.value,o+=s.replacements}return{value:r,replacements:o}}function F(t,e,n){if(typeof t=="string")return lt(t,e,n);if(Array.isArray(t)){let r=0;return{value:t.map(i=>{let s=F(i,e,n);return r+=s.replacements,s.value}),replacements:r}}if(typeof t=="object"&&t!==null){let r=0,o={};for(let[i,s]of Object.entries(t)){let a=F(s,e,n);r+=a.replacements,o[i]=a.value}return{value:o,replacements:r}}return{value:t,replacements:0}}function kt(t){let e=structuredClone(_),n=0,r=0;for(let o=0;o<t.length;o+=1){let i=t[o];d(e)!==i.before_hash&&(n+=1),e=A(e,i.patch,o+1,i.op),d(e)!==i.after_hash&&(r+=1)}return{hashMismatchesBefore:n,hashMismatchesAfter:r,finalDocument:e}}function Ht(t,e,n){let r=0,o=!1,i=t.message;if(typeof t.message=="string"){let a=lt(t.message,e,n);i=a.value,r+=a.replacements,a.replacements>0&&(o=!0)}let s=t.patch.map(a=>{if(!Object.prototype.hasOwnProperty.call(a,"value"))return a;let h=F(a.value,e,n);return r+=h.replacements,h.replacements>0?(o=!0,{...a,value:h.value}):a});return{entry:{...t,message:i,patch:s},replacements:r,changed:o}}function Pt(t,e,n){let r=structuredClone(_),o=0,i=0,s=[];for(let a=0;a<t.length;a+=1){let h=Ht(t[a],e,n);i+=h.replacements,h.changed&&(o+=1);let f=d(r);r=A(r,h.entry.patch,a+1,h.entry.op);let u=d(r);s.push({...h.entry,before_hash:f,after_hash:u})}return{entries:s,finalDocument:r,entriesChanged:o,replacements:i}}function Dt(t){return Object.keys(t.metadata).length>0}async function At(t,e){let n=t.located?.itemPath??null;if(!t.located)return{raw:null,path:n,document:null};let r=await D(t.located,{schema:e.schema});return{raw:r.raw,path:n,document:r.document}}function Tt(t){if(!Dt(t.finalDocument))return{raw:null,path:null,document:null};let e=X(L(t.finalDocument),{schema:t.settings.schema});if(e.metadata.id!==t.subject.id)throw new l("history-redact would change the item id; narrow your patterns.",c.USAGE);return{document:e,path:q(t.pmRoot,e.metadata.type,t.subject.id,"toon",t.typeToFolder),raw:Y(e,{format:"toon",schema:t.settings.schema})}}function $t(t,e){return typeof t.message=="string"&&t.message.trim().length>0?t.message:`history-redact replaced ${e.replacements} match(es) across ${e.entriesChanged} entr${e.entriesChanged===1?"y":"ies"}.`}function jt(t){let e=[...t.rewritten.entries];if(t.dryRun||!t.changed)return{rewrittenEntries:e,auditEntryAdded:!1};let n=t.nextItemDocument??L(t.rewritten.finalDocument);return e.push(K({nowIso:S(),author:t.author,op:"history_redact",before:n,after:n,message:t.message})),{rewrittenEntries:e,auditEntryAdded:!0}}async function Ct(t){let e=[];return at({pmRoot:t.pmRoot,subject:t.subject,settings:t.settings,typeRegistry:t.typeRegistry,historyRawBeforeLock:t.historyRawBeforeLock,currentItemRawBeforeLock:t.currentItem.raw,operation:"history-redact",author:t.author,force:t.force,itemDocument:t.currentItem.document,applyRewrite:async({historyRawUnderLock:n})=>{let r=await it(t.pmRoot,t.author),o=new Set;t.currentItem.path&&o.add(t.currentItem.path),t.nextItem.path&&o.add(t.nextItem.path);let i=new Map;t.currentItem.path&&t.currentItem.raw!==null&&i.set(t.currentItem.path,t.currentItem.raw);let s=()=>{};try{try{t.nextItem.path&&t.nextItem.raw!==null&&t.nextItem.raw!==t.currentItem.raw&&await m(t.nextItem.path,t.nextItem.raw),t.currentItem.path&&(!t.nextItem.path||t.nextItem.path!==t.currentItem.path)&&await U.rm(t.currentItem.path,{force:!0}),await m(t.subject.historyPath,tt(t.rewrittenEntries))}catch(h){try{await St(t.subject.historyPath,n,o,i)}finally{await p(t.subject.historyPath)}throw h}await p(t.subject.historyPath);let a=t.nextItem.path??t.currentItem.path;a&&(e=await st({pmRoot:t.pmRoot,preferredFormat:t.settings.item_format,typeToFolder:t.typeRegistry.type_to_folder,schema:t.settings.schema,itemPath:a,...t.currentItem.path?{previousItemPath:t.currentItem.path}:{},document:t.nextItem.document}))}finally{await r().catch(a=>{s=()=>{throw a}})}s()},applyPostRewrite:async()=>[...e,...await Lt(t.subject.historyPath,[t.nextItem.path,t.currentItem.path])]})}async function St(t,e,n,r){e===null?await U.rm(t,{force:!0}):await m(t,e);for(let o of n){let i=r.get(o);i===void 0?await U.rm(o,{force:!0}):await m(o,i)}}async function Lt(t,e){let n=[],r=new Set(e.filter(o=>o!==null));for(let o of r)n.push(...await C({path:o,scope:"project",op:"history_redact"}));return n.push(...await C({path:t,scope:"project",op:"history_redact:history"})),n}async function Ut(t,e,n,r){let o=await P(t,e,n.id_prefix,n.item_format,r);if(o)return{id:o.id,historyPath:j(t,o.id),located:o};let i=ot(e,n.id_prefix),s=nt(e),a=i===s?[i]:[i,s];for(let h of a){let f=j(t,h);if(await k(f))return{id:h,historyPath:f,located:null}}throw new l(`Item ${e} not found`,c.NOT_FOUND)}async function xe(t,e,n){let r=G(process.cwd(),n.path);if(!await k(B(r)))throw new l(`Tracker is not initialized at ${r}. Run pm init first.`,c.NOT_FOUND);let o=await rt(r),i=M(o,z()),s=e.replacement??"",a=s.length===0,h=a?"[redacted]":s,f=Rt(e.literal,e.regex),u=await Ut(r,t,o,i.type_to_folder);if(!await k(u.historyPath))throw new l(`No history stream exists for ${u.id}.`,c.NOT_FOUND);let ht=await H(u.historyPath),x=await J(u.historyPath,u.id);if(x.length===0)throw new l(`No history entries exist for ${u.id}; nothing to redact.`,c.USAGE);let b=kt(x),y=Pt(x,f,h),T=b.hashMismatchesBefore+b.hashMismatchesAfter,$=!!e.dryRun,R=y.replacements>0,E=[];T>0&&E.push(`history_redact_preexisting_hash_mismatches:${T}`),R||E.push("history_redact_no_matches");let g=await At(u,o),w=Tt({pmRoot:r,subject:u,settings:o,typeToFolder:i.type_to_folder,finalDocument:y.finalDocument}),ut=(g.path??null)!==(w.path??null)||(g.raw??null)!==(w.raw??null),N=V(e.author,o.author_default),ft=$t(e,y),{rewrittenEntries:O,auditEntryAdded:dt}=jt({rewritten:y,dryRun:$,changed:R,nextItemDocument:w.document,author:N,message:ft}),v=Z(O);if(!v.ok)throw new l(`history-redact produced an invalid rewritten chain (${v.errors.join(", ")}).`,c.GENERIC_FAILURE);return!$&&R&&E.push(...await Ct({pmRoot:r,subject:u,settings:o,typeRegistry:i,historyRawBeforeLock:ht,currentItem:g,nextItem:w,author:N,force:e.force,rewrittenEntries:O})),{id:u.id,dry_run:$,changed:R,patterns:{literal_count:f.filter(I=>I.kind==="literal").length,regex_count:f.filter(I=>I.kind==="regex").length,total_count:f.length,replacement_is_default:a},history:{path:u.historyPath,entries_scanned:x.length,entries_changed:y.entriesChanged,replacements:y.replacements,hash_mismatches_before:b.hashMismatchesBefore,hash_mismatches_after:b.hashMismatchesAfter,preexisting_hash_mismatches:T,audit_entry_added:dt,verify_ok:v.ok,verify_errors:v.errors},item:{existed_before:g.path!==null,exists_after:w.path!==null,path_before:g.path,path_after:w.path,changed:ut},warnings:[...new Set(E)].sort((I,mt)=>I.localeCompare(mt)),generated_at:S()}}export{Mt as a,A as b,Gt as c,Bt as d,Zt as e,at as f,Ut as g,xe as h};
|
|
2
|
-
//# sourceMappingURL=chunk-
|
|
1
|
+
import{$a as P,Ba as tt,Ia as et,K as V,Ka as rt,L as S,P as W,Pa as nt,Qa as ot,Xa as it,Za as st,ab as D,ea as Y,fa as X,ga as J,k as z,ma as p,n as C,pa as K,ra as _,ta as d,ua as L,ya as Q,za as Z}from"./chunk-GEYU23YS.js";import{D as M,J as G,M as B,N as q,P as j,p as k,q as H,r as m}from"./chunk-EAXXF2HW.js";import{Y as c,Z as l}from"./chunk-7AZDTGPA.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="47c087c2-124a-58b7-a5c9-09403235f4a2")}catch{}})();function yt(t,e){let n=-1;return t.forEach((r,o)=>{let i=Date.parse(r.ts);if(!Number.isFinite(i))throw new l(`History for this item contains invalid timestamp at entry ${o+1}.`,c.GENERIC_FAILURE);i<=e&&(n=o)}),n}function wt(t){let e=t[0]?.ts??null,n=t.at(-1)?.ts??null,r={code:"history_target_out_of_range",required:"Choose a target within the available item history.",why:"Point-in-time reads and restores can only reconstruct recorded versions.",examples:[],nextSteps:["Run pm history <id> to inspect available versions and timestamps."],valid_range:{first_version:null,last_version:null,first_timestamp:e,last_timestamp:n}};return n!==null&&(r.examples=["1",String(t.length),n],r.valid_range.first_version=1,r.valid_range.last_version=t.length),{guidance:r,lastTimestamp:n}}function pt(t,e){let n={};if(e instanceof Error&&e.message.trim().length>0&&(n.reason=e.message.trim()),typeof e!="object"||e===null)return n;let r=e;if(typeof r.index=="number"&&Number.isInteger(r.index)&&r.index>=0&&(n.patchIndex=r.index),typeof r.operation=="object"&&r.operation!==null){let o=r.operation;Object.assign(n,Object.fromEntries(["op","path","from"].flatMap(i=>{let s=o[i];return typeof s=="string"?[[i,s]]:[]})))}if(n.patchIndex!==void 0){let o=t[n.patchIndex];o&&(n.op??=o.op,n.path??=o.path,n.from??=o.from)}return n}function Mt(t,e,n={}){let r=t.trim(),o=n.errorSubject??"history",i=o==="restore"?"Restore":"History",{guidance:s,lastTimestamp:a}=wt(e);if(!r)throw new l(`Missing ${o} target. Use a timestamp or version number.`,c.USAGE,s);if(/^\d+$/.test(r)){let u=Number(r);if(!Number.isSafeInteger(u)||u<1||u>e.length)throw new l(`${i} version must be between 1 and ${e.length} for this item.`,c.USAGE,s);return{kind:"version",raw:r,historyIndex:u-1}}let h=Date.parse(r);if(!Number.isFinite(h))throw new l(`Invalid ${o} target "${t}". Use a positive version number or ISO timestamp.`,c.USAGE,s);let f=yt(e,h);if(f<0||n.allowFutureTimestamp!==!0&&h>Date.parse(a))throw new l(o==="restore"?`No history entries exist at or before timestamp ${r}.`:`No history entry exists at timestamp ${r}.`,c.USAGE,s);return{kind:"timestamp",raw:r,historyIndex:f}}function A(t,e,n,r){let o=Q(t,e);if(o.ok)return o.document;let i=pt(e,o.error),s=[`history_op=${r}`,i.patchIndex===void 0?null:`patch_index=${i.patchIndex}`,i.op?`op=${i.op}`:null,i.path?`path=${i.path}`:null,i.from?`from=${i.from}`:null].filter(a=>a!==null);throw new l(`Failed to apply history patch at entry ${n} (${s.join(", ")}). ${i.reason??String(o.error)}`,c.GENERIC_FAILURE)}function Gt(t,e){let n=structuredClone(_);for(let r=0;r<=e;r+=1){let o=t[r];if(!o)throw new l(`History target entry ${r+1} does not exist.`,c.USAGE);if(d(n)!==o.before_hash)throw new l(`History hash mismatch before replay at entry ${r+1}.`,c.GENERIC_FAILURE);if(n=A(n,o.patch,r+1,o.op),d(n)!==o.after_hash)throw new l(`History hash mismatch after replay at entry ${r+1}.`,c.GENERIC_FAILURE)}return n}function Bt(t,e){if(Object.keys(t.metadata).length>0)return t;throw new l(`History target ${e.raw} resolves to a deleted state; choose a version or timestamp where the item exists.`,c.USAGE)}import U from"node:fs/promises";import gt from"node:fs/promises";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="a2ec9f1a-aae2-59d5-8c9a-7acd8bf5a7a2")}catch{}})();function It(t){if(!t.itemDocument)return[];let e=t.itemDocument.metadata?.assignee?.trim();if(!e||e===t.author||t.force)return[];let n=et(t.settings);if(n.ownership_enforcement==="strict")throw new l(`Item ${t.subjectId} is assigned to ${e}. Use --force to override.`,c.CONFLICT);return n.ownership_enforcement==="warn"?[`ownership_warning:assignee_conflict:${t.subjectId}:${e}`]:[]}async function _t(t){let e=await H(t.subject.historyPath);if(e!==t.historyRawBeforeLock)throw new l(`History for ${t.subject.id} changed while waiting for lock; retry ${t.operation}.`,c.CONFLICT);let n=await P(t.pmRoot,t.subject.id,t.settings.id_prefix,t.settings.item_format,t.typeRegistry.type_to_folder),r=n?await D(n,{schema:t.settings.schema}):null;if((r?.raw??null)!==(t.currentItemRawBeforeLock??null))throw new l(`Item ${t.subject.id} changed while waiting for lock; retry ${t.operation}.`,c.CONFLICT);return{historyRawUnderLock:e,locatedUnderLock:n,loadedItemUnderLock:r}}async function Zt(t){let e=t.writeHistoryRaw??m;try{await e(t.historyPath,t.nextHistoryRaw),await p(t.historyPath)}catch(n){try{t.historyRawUnderLock===null?await gt.rm(t.historyPath,{force:!0}):await e(t.historyPath,t.historyRawUnderLock),await p(t.historyPath)}catch(r){throw new AggregateError([n,r],`History rewrite failed and rollback also failed: ${String(n)}`)}throw n}}async function at(t){let e=[...It({itemDocument:t.itemDocument,subjectId:t.subject.id,author:t.author,force:t.force,settings:t.settings})],n=await W(t.pmRoot,t.subject.id,t.settings.locks.ttl_seconds,t.author,!!t.force,t.settings.governance.force_required_for_stale_lock,t.settings.locks.wait_ms);try{let r=await _t({pmRoot:t.pmRoot,subject:t.subject,settings:t.settings,typeRegistry:t.typeRegistry,historyRawBeforeLock:t.historyRawBeforeLock,currentItemRawBeforeLock:t.currentItemRawBeforeLock,operation:t.operation});return await t.applyRewrite(r),t.applyPostRewrite&&e.push(...await t.applyPostRewrite(r)),e}finally{await n()}}(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new t.Error().stack;e&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[e]="cd2a27ec-0f12-591d-ab34-529ddda05063")}catch{}})();function ct(t){return Array.isArray(t)?t:typeof t=="string"?[t]:[]}function xt(t){let e=[];for(let n of t)e.includes(n)||e.push(n);return e.includes("g")||e.push("g"),e.join("")}function bt(t){let e=t.trim();if(e.length===0)throw new l("history-redact --regex requires a non-empty pattern.",c.USAGE);let n=e,r="g";if(e.startsWith("/")&&e.length>1){let o=e.lastIndexOf("/");o>0&&(n=e.slice(1,o),r=xt(e.slice(o+1)))}if(n.length===0)throw new l("history-redact --regex cannot use an empty pattern.",c.USAGE);try{new RegExp(n,r)}catch{throw new l("Invalid --regex value; provide a valid JavaScript regular expression.",c.USAGE)}return{kind:"regex",source:n,flags:r}}function Rt(t,e){let n=[...new Set(ct(t).map(i=>i.trim()))].filter(i=>i.length>0).map(i=>({kind:"literal",value:i})),r=[...new Set(ct(e).map(i=>i.trim()))].filter(i=>i.length>0).map(bt),o=[...n,...r];if(o.length===0)throw new l("history-redact requires at least one matcher via --literal or --regex.",c.USAGE,{code:"missing_required_argument",required:"Provide --literal <value> and/or --regex <pattern>.",examples:['pm history-redact pm-a1b2 --literal "[redacted_path_prefix]/private"','pm history-redact pm-a1b2 --regex "/192\\\\.168\\\\.[0-9.]+/g" --replacement "[scrubbed_ip]"']});return o}function Et(t,e,n){if(e.length===0)return{value:t,replacements:0};let r=0,o=0;for(;r<=t.length;){let i=t.indexOf(e,r);if(i===-1)break;o+=1,r=i+Math.max(1,e.length)}return o===0?{value:t,replacements:0}:{value:t.split(e).join(n),replacements:o}}function vt(t,e,n){let r=new RegExp(e.source,e.flags),o=[...t.matchAll(r)];return o.length===0?{value:t,replacements:0}:{value:t.replace(r,n),replacements:o.length}}function lt(t,e,n){let r=t,o=0;for(let i of e){let s=i.kind==="literal"?Et(r,i.value,n):vt(r,i,n);r=s.value,o+=s.replacements}return{value:r,replacements:o}}function F(t,e,n){if(typeof t=="string")return lt(t,e,n);if(Array.isArray(t)){let r=0;return{value:t.map(i=>{let s=F(i,e,n);return r+=s.replacements,s.value}),replacements:r}}if(typeof t=="object"&&t!==null){let r=0,o={};for(let[i,s]of Object.entries(t)){let a=F(s,e,n);r+=a.replacements,o[i]=a.value}return{value:o,replacements:r}}return{value:t,replacements:0}}function kt(t){let e=structuredClone(_),n=0,r=0;for(let o=0;o<t.length;o+=1){let i=t[o];d(e)!==i.before_hash&&(n+=1),e=A(e,i.patch,o+1,i.op),d(e)!==i.after_hash&&(r+=1)}return{hashMismatchesBefore:n,hashMismatchesAfter:r,finalDocument:e}}function Ht(t,e,n){let r=0,o=!1,i=t.message;if(typeof t.message=="string"){let a=lt(t.message,e,n);i=a.value,r+=a.replacements,a.replacements>0&&(o=!0)}let s=t.patch.map(a=>{if(!Object.prototype.hasOwnProperty.call(a,"value"))return a;let h=F(a.value,e,n);return r+=h.replacements,h.replacements>0?(o=!0,{...a,value:h.value}):a});return{entry:{...t,message:i,patch:s},replacements:r,changed:o}}function Pt(t,e,n){let r=structuredClone(_),o=0,i=0,s=[];for(let a=0;a<t.length;a+=1){let h=Ht(t[a],e,n);i+=h.replacements,h.changed&&(o+=1);let f=d(r);r=A(r,h.entry.patch,a+1,h.entry.op);let u=d(r);s.push({...h.entry,before_hash:f,after_hash:u})}return{entries:s,finalDocument:r,entriesChanged:o,replacements:i}}function Dt(t){return Object.keys(t.metadata).length>0}async function At(t,e){let n=t.located?.itemPath??null;if(!t.located)return{raw:null,path:n,document:null};let r=await D(t.located,{schema:e.schema});return{raw:r.raw,path:n,document:r.document}}function Tt(t){if(!Dt(t.finalDocument))return{raw:null,path:null,document:null};let e=X(L(t.finalDocument),{schema:t.settings.schema});if(e.metadata.id!==t.subject.id)throw new l("history-redact would change the item id; narrow your patterns.",c.USAGE);return{document:e,path:q(t.pmRoot,e.metadata.type,t.subject.id,"toon",t.typeToFolder),raw:Y(e,{format:"toon",schema:t.settings.schema})}}function $t(t,e){return typeof t.message=="string"&&t.message.trim().length>0?t.message:`history-redact replaced ${e.replacements} match(es) across ${e.entriesChanged} entr${e.entriesChanged===1?"y":"ies"}.`}function jt(t){let e=[...t.rewritten.entries];if(t.dryRun||!t.changed)return{rewrittenEntries:e,auditEntryAdded:!1};let n=t.nextItemDocument??L(t.rewritten.finalDocument);return e.push(K({nowIso:S(),author:t.author,op:"history_redact",before:n,after:n,message:t.message})),{rewrittenEntries:e,auditEntryAdded:!0}}async function Ct(t){let e=[];return at({pmRoot:t.pmRoot,subject:t.subject,settings:t.settings,typeRegistry:t.typeRegistry,historyRawBeforeLock:t.historyRawBeforeLock,currentItemRawBeforeLock:t.currentItem.raw,operation:"history-redact",author:t.author,force:t.force,itemDocument:t.currentItem.document,applyRewrite:async({historyRawUnderLock:n})=>{let r=await it(t.pmRoot,t.author),o=new Set;t.currentItem.path&&o.add(t.currentItem.path),t.nextItem.path&&o.add(t.nextItem.path);let i=new Map;t.currentItem.path&&t.currentItem.raw!==null&&i.set(t.currentItem.path,t.currentItem.raw);let s=()=>{};try{try{t.nextItem.path&&t.nextItem.raw!==null&&t.nextItem.raw!==t.currentItem.raw&&await m(t.nextItem.path,t.nextItem.raw),t.currentItem.path&&(!t.nextItem.path||t.nextItem.path!==t.currentItem.path)&&await U.rm(t.currentItem.path,{force:!0}),await m(t.subject.historyPath,tt(t.rewrittenEntries))}catch(h){try{await St(t.subject.historyPath,n,o,i)}finally{await p(t.subject.historyPath)}throw h}await p(t.subject.historyPath);let a=t.nextItem.path??t.currentItem.path;a&&(e=await st({pmRoot:t.pmRoot,preferredFormat:t.settings.item_format,typeToFolder:t.typeRegistry.type_to_folder,schema:t.settings.schema,itemPath:a,...t.currentItem.path?{previousItemPath:t.currentItem.path}:{},document:t.nextItem.document}))}finally{await r().catch(a=>{s=()=>{throw a}})}s()},applyPostRewrite:async()=>[...e,...await Lt(t.subject.historyPath,[t.nextItem.path,t.currentItem.path])]})}async function St(t,e,n,r){e===null?await U.rm(t,{force:!0}):await m(t,e);for(let o of n){let i=r.get(o);i===void 0?await U.rm(o,{force:!0}):await m(o,i)}}async function Lt(t,e){let n=[],r=new Set(e.filter(o=>o!==null));for(let o of r)n.push(...await C({path:o,scope:"project",op:"history_redact"}));return n.push(...await C({path:t,scope:"project",op:"history_redact:history"})),n}async function Ut(t,e,n,r){let o=await P(t,e,n.id_prefix,n.item_format,r);if(o)return{id:o.id,historyPath:j(t,o.id),located:o};let i=ot(e,n.id_prefix),s=nt(e),a=i===s?[i]:[i,s];for(let h of a){let f=j(t,h);if(await k(f))return{id:h,historyPath:f,located:null}}throw new l(`Item ${e} not found`,c.NOT_FOUND)}async function xe(t,e,n){let r=G(process.cwd(),n.path);if(!await k(B(r)))throw new l(`Tracker is not initialized at ${r}. Run pm init first.`,c.NOT_FOUND);let o=await rt(r),i=M(o,z()),s=e.replacement??"",a=s.length===0,h=a?"[redacted]":s,f=Rt(e.literal,e.regex),u=await Ut(r,t,o,i.type_to_folder);if(!await k(u.historyPath))throw new l(`No history stream exists for ${u.id}.`,c.NOT_FOUND);let ht=await H(u.historyPath),x=await J(u.historyPath,u.id);if(x.length===0)throw new l(`No history entries exist for ${u.id}; nothing to redact.`,c.USAGE);let b=kt(x),y=Pt(x,f,h),T=b.hashMismatchesBefore+b.hashMismatchesAfter,$=!!e.dryRun,R=y.replacements>0,E=[];T>0&&E.push(`history_redact_preexisting_hash_mismatches:${T}`),R||E.push("history_redact_no_matches");let g=await At(u,o),w=Tt({pmRoot:r,subject:u,settings:o,typeToFolder:i.type_to_folder,finalDocument:y.finalDocument}),ut=(g.path??null)!==(w.path??null)||(g.raw??null)!==(w.raw??null),N=V(e.author,o.author_default),ft=$t(e,y),{rewrittenEntries:O,auditEntryAdded:dt}=jt({rewritten:y,dryRun:$,changed:R,nextItemDocument:w.document,author:N,message:ft}),v=Z(O);if(!v.ok)throw new l(`history-redact produced an invalid rewritten chain (${v.errors.join(", ")}).`,c.GENERIC_FAILURE);return!$&&R&&E.push(...await Ct({pmRoot:r,subject:u,settings:o,typeRegistry:i,historyRawBeforeLock:ht,currentItem:g,nextItem:w,author:N,force:e.force,rewrittenEntries:O})),{id:u.id,dry_run:$,changed:R,patterns:{literal_count:f.filter(I=>I.kind==="literal").length,regex_count:f.filter(I=>I.kind==="regex").length,total_count:f.length,replacement_is_default:a},history:{path:u.historyPath,entries_scanned:x.length,entries_changed:y.entriesChanged,replacements:y.replacements,hash_mismatches_before:b.hashMismatchesBefore,hash_mismatches_after:b.hashMismatchesAfter,preexisting_hash_mismatches:T,audit_entry_added:dt,verify_ok:v.ok,verify_errors:v.errors},item:{existed_before:g.path!==null,exists_after:w.path!==null,path_before:g.path,path_after:w.path,changed:ut},warnings:[...new Set(E)].sort((I,mt)=>I.localeCompare(mt)),generated_at:S()}}export{Mt as a,A as b,Gt as c,Bt as d,Zt as e,at as f,Ut as g,xe as h};
|
|
2
|
+
//# sourceMappingURL=chunk-GIERI4YU.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{X as we,l as pe,t as T,u as ye,v as ge,w as _e}from"./chunk-YHDCGUIW.js";import{e as fe,f as me,g as he}from"./chunk-GIERI4YU.js";import{a as M}from"./chunk-ME4XVOBJ.js";import{Aa as j,Ba as I,K as re,Ka as x,L as S,M as P,ab as ue,ba as D,da as ne,db as le,ea as ie,fa as oe,ga as se,k as F,la as ae,n as te,ta as O,wa as ce,xa as de,za as B}from"./chunk-GEYU23YS.js";import{D as L,J as C,M as k,h as Z,p as E,q as ee}from"./chunk-EAXXF2HW.js";import{Y as y,Z as g,aa as w}from"./chunk-7AZDTGPA.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="582576df-8dbe-5f93-890b-5d872669dfe8")}catch{}})();function U(e,t){let n=D(e);if(n)throw new g(`History merge input (${t}) contains unresolved conflict markers at line ${n.line}. Merge drivers must receive clean per-side versions.`,y.GENERIC_FAILURE);let r=[];for(let[o,a]of e.split(/\r?\n/).entries()){let i=a.trim();if(i)try{let d=JSON.parse(i);if(typeof d!="object"||d===null||Array.isArray(d))throw new TypeError("history entry must be an object");r.push(d)}catch{throw new g(`History merge input (${t}) contains invalid JSON at line ${o+1}.`,y.GENERIC_FAILURE)}}return r}function v(e){return w({ts:e.ts,author:e.author,op:e.op,patch:e.patch,message:e.message??null})}function Ne(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&v(e[r])===v(t[r]);)r+=1;return r}function Re(e,t,n){U(e,"base");let r=U(t,"ours"),o=U(n,"theirs"),a=Ne(r,o);if(a===r.length&&a===o.length)return{merged:I(r),strategy:"identical",common_entries:a,entries_from_ours:0,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(a===o.length)return{merged:I(r),strategy:"fast_forward_ours",common_entries:a,entries_from_ours:r.length-a,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(a===r.length)return{merged:I(o),strategy:"fast_forward_theirs",common_entries:a,entries_from_ours:0,entries_from_theirs:o.length-a,entries_total:o.length,reanchored:!1};let i=r.slice(a),d=new Set(i.map(v)),c=o.slice(a).filter(u=>!d.has(v(u))),m=[...i,...c].sort((u,f)=>{let l=P(u.ts,f.ts);if(l!==0)return l;let h=d.has(v(u)),p=d.has(v(f));return h!==p?Number(p)-Number(h):v(u).localeCompare(v(f))}),s=j([...r.slice(0,a),...m]);return{merged:I(s.entries),strategy:"union_reanchor",common_entries:a,entries_from_ours:i.length,entries_from_theirs:c.length,entries_total:s.entries.length,reanchored:!0}}function J(e,t){let n=D(e);if(n)throw new g(`Relationship merge input (${t}) contains unresolved conflict markers at line ${n.line}. Merge drivers must receive clean per-side versions.`,y.GENERIC_FAILURE);let r=[];for(let[o,a]of e.split(/\r?\n/).entries()){let i=a.trim();if(!i)continue;let d;try{d=JSON.parse(i)}catch{throw new g(`Relationship merge input (${t}) contains invalid JSON at line ${o+1}.`,y.GENERIC_FAILURE)}if(typeof d!="object"||d===null||Array.isArray(d)||typeof d.eventId!="string"||typeof d.sequence!="number")throw new g(`Relationship merge input (${t}) line ${o+1} is not a relationship event (eventId + sequence required).`,y.GENERIC_FAILURE);r.push(d)}return r}function H(e){return e.length===0?"":`${e.map(t=>JSON.stringify(t)).join(`
|
|
2
|
+
`)}
|
|
3
|
+
`}function $e(e){return e.map((t,n)=>({...t,sequence:n+1}))}function ve(e,t,n){J(e,"base");let r=J(t,"ours"),o=J(n,"theirs"),a=Math.min(r.length,o.length),i=0;for(;i<a&&r[i].eventId===o[i].eventId;)i+=1;if(i===r.length&&i===o.length)return{merged:H(r),strategy:"identical",common_entries:i,entries_from_ours:0,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(i===o.length)return{merged:H(r),strategy:"fast_forward_ours",common_entries:i,entries_from_ours:r.length-i,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(i===r.length)return{merged:H(o),strategy:"fast_forward_theirs",common_entries:i,entries_from_ours:0,entries_from_theirs:o.length-i,entries_total:o.length,reanchored:!1};let d=r.slice(i),c=new Set(d.map(f=>f.eventId)),m=o.slice(i).filter(f=>!c.has(f.eventId)),s=[...d,...m].sort((f,l)=>{if(f.timestamp!==void 0&&l.timestamp!==void 0){let _=P(f.timestamp,l.timestamp);if(_!==0)return _}else{if(f.timestamp===void 0&&l.timestamp!==void 0)return 1;if(f.timestamp!==void 0)return-1}let h=c.has(f.eventId),p=c.has(l.eventId);return h!==p?Number(p)-Number(h):0}),u=$e([...r.slice(0,i),...s]);return{merged:H(u),strategy:"union_reanchor",common_entries:i,entries_from_ours:d.length,entries_from_theirs:m.length,entries_total:u.length,reanchored:!0}}var Pe=["tags","dependencies","comments","notes","learnings","files","tests","test_runs","docs","reminders","events"],De=["updated_at"];function b(e,t){return w(e??null)===w(t??null)}function je(e,t,n){let r=s=>Array.isArray(s)?s:[],o=new Set(r(e).map(s=>w(s))),a=r(t),i=new Set(a.map(s=>w(s))),d=r(n),c=new Set(d.map(s=>w(s))),m=a.filter(s=>{let u=w(s);return!o.has(u)||c.has(u)});for(let s of d){let u=w(s);!i.has(u)&&!o.has(u)&&m.push(s)}return m}function Me(e,t){return P(String(e),String(t))>=0?e:t}function q(e,t,n,r){return b(t,n)?{value:t,from_theirs:!1,conflict:!1}:b(e,t)?{value:n,from_theirs:!0,conflict:!1}:b(e,n)?{value:t,from_theirs:!1,conflict:!1}:{value:r==="theirs"?n:t,from_theirs:r==="theirs",conflict:!0}}function G(e){return{...e.metadata}}function z(e,t,n){try{return oe(ne(e,n),n)}catch(r){throw new g(`Item merge input (${t}) is not a readable item document: ${String(r)}`,y.GENERIC_FAILURE)}}function He(e,t,n,r){let o=new Set(Pe),a=new Set(De),i=[...new Set([...Object.keys(t),...Object.keys(n)])].sort((c,m)=>c.localeCompare(m)),d={merged:{},conflictFields:[],fieldsFromTheirs:[],unionFields:[],conflictDecisions:[]};for(let c of i){let m=e[c],s=t[c],u=n[c];if(o.has(c)){let l=je(m,s,u);d.merged[c]=l,b(l,s)||d.unionFields.push(c);continue}if(a.has(c)){d.merged[c]=Me(s,u);continue}let f=q(m,s,u,r);f.value!==void 0&&(d.merged[c]=f.value),f.conflict?(d.conflictFields.push(c),d.conflictDecisions.push({field:c,base:m,ours:s,theirs:u,retained:f.value,discarded:r==="theirs"?s:u})):f.from_theirs&&d.fieldsFromTheirs.push(c)}return d}function Ie(e,t,n,r={}){let o=r.preferred??"ours",a=e.trim().length>0,i=z(t,"ours",r),d=z(n,"theirs",r),c=a?z(e,"base",r):i,m=a?G(c):{},s=G(i),u=G(d),{merged:f,conflictFields:l,fieldsFromTheirs:h,unionFields:p,conflictDecisions:_}=He(m,s,u,o),R=q(a?c.body:"",i.body,d.body,o);return R.conflict?(l.push("body"),_.push({field:"body",base:a?c.body:"",ours:i.body,theirs:d.body,retained:R.value,discarded:o==="theirs"?i.body:d.body})):R.from_theirs&&h.push("body"),{merged:ie({metadata:f,body:R.value},r),conflict_fields:l,fields_from_theirs:h,union_fields:p,conflict_decisions:_,preferred:o}}function V(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e,t){let n=D(e);if(n)throw new g(`JSON merge input (${t}) contains unresolved conflict markers at line ${n.line}.`,y.GENERIC_FAILURE);if(e.trim().length!==0)try{return JSON.parse(e)}catch{throw new g(`JSON merge input (${t}) is not valid JSON.`,y.GENERIC_FAILURE)}}function Le(e,t,n){if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(n))return null;let r=m=>{let s=new Map;for(let u of m){let f=w(u);s.set(f,(s.get(f)??0)+1)}return s},o=r(e),a=r(t),i=r(n);for(let[m,s]of o)if((a.get(m)??0)<s||(i.get(m)??0)<s)return null;let d=new Map(a),c=[];for(let m of n){let s=w(m),u=d.get(s)??0;u>0?d.set(s,u-1):c.push(m)}return{merged:[...t,...c],acceptedTheirs:c.length>0}}function Be(e,t,n,r,o,a,i){if(!V(t)||!V(n))return null;let d=V(e)?e:{},c={},m=[...new Set([...Object.keys(t),...Object.keys(n)])].sort((s,u)=>s.localeCompare(u));for(let s of m){let u=o.length>0?`${o}.${s}`:s,f=Ue(d,t,n,s,r,u,a,i);f!==void 0&&(c[s]=f)}return c}function be(e,t,n,r,o,a,i){if(b(t,n))return t;let d=Le(e,t,n);if(d!==null)return d.acceptedTheirs&&i.push(o),d.merged;let c=Be(e,t,n,r,o,a,i);if(c!==null)return c;let m=q(e,t,n,r);return m.conflict?a.push(o):m.from_theirs&&i.push(o),m.value}function Ue(e,t,n,r,o,a,i,d){let c=Object.prototype.hasOwnProperty.call(t,r),m=Object.prototype.hasOwnProperty.call(n,r),s=Object.prototype.hasOwnProperty.call(e,r);if(c&&m)return be(e[r],t[r],n[r],o,a,i,d);if(c){if(s&&b(e[r],t[r])){d.push(a);return}return s?(i.push(a),o==="theirs"?void 0:t[r]):t[r]}if(!(s&&b(e[r],n[r])))return s?(i.push(a),o==="theirs"?n[r]:void 0):(d.push(a),n[r])}function Ee(e,t,n,r={}){let o=r.preferred??"ours",a=W(e,"base"),i=W(t,"ours"),d=W(n,"theirs"),c=[],m=[],s=be(a,i,d,o,"",c,m);return{merged:`${JSON.stringify(s??null,null,2)}
|
|
4
|
+
`,conflict_paths:c,paths_from_theirs:m,preferred:o}}import{readFile as Je,writeFile as Ge}from"node:fs/promises";import ze from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="182fee45-4de8-502d-8aec-84b5b8e4aecb")}catch{}})();var Se=["item","history","relationship","json"];function Ve(e){let t=e.trim().toLowerCase();if(Se.includes(t))return t;throw new g(`Unknown merge artifact "${e}". Supported values: ${Se.join(", ")}.`,y.USAGE)}function We(e){if(e===void 0)return"ours";let t=e.trim().toLowerCase();if(t==="ours"||t==="theirs")return t;throw new g(`Unknown --prefer value "${e}". Supported values: ours, theirs.`,y.USAGE)}async function X(e,t){try{return await Je(e,"utf8")}catch{throw new g(`Cannot read merge ${t} file at ${e}.`,y.NOT_FOUND)}}async function qe(e){let t=C(process.cwd(),e.path);return await E(k(t))?x(t):null}function Xe(e,t){return e.endsWith(".md")?"json_markdown":e.endsWith(".toon")?"toon":t?.item_format??"toon"}async function It(e,t){let n=Ve(e.artifact),r=We(e.prefer),o=ze.resolve(e.outputPath??e.oursPath),[a,i,d]=await Promise.all([X(e.basePath,"base"),X(e.oursPath,"ours"),X(e.theirsPath,"theirs")]),c,m,s=[],u={};if(n==="history"){let l=Re(a,i,d);c=l.merged,u.history={strategy:l.strategy,common_entries:l.common_entries,entries_from_ours:l.entries_from_ours,entries_from_theirs:l.entries_from_theirs,entries_total:l.entries_total,reanchored:l.reanchored}}else if(n==="relationship"){let l=ve(a,i,d);c=l.merged,u.relationship={strategy:l.strategy,common_entries:l.common_entries,entries_from_ours:l.entries_from_ours,entries_from_theirs:l.entries_from_theirs,entries_total:l.entries_total,reanchored:l.reanchored}}else if(n==="item"){let l=await qe(t),h=Ie(a,i,d,{format:Xe(e.itemPath??o,l),schema:l?.schema,extensionFieldNames:Z(F()),preferred:r});c=h.merged,s.push(...h.conflict_fields),u.item={fields_from_theirs:h.fields_from_theirs,union_fields:h.union_fields},e.itemPath!==void 0&&(m={cwd:process.cwd(),itemPath:e.itemPath,preferred:r,fieldsFromTheirs:h.fields_from_theirs,unionFields:h.union_fields,decisions:h.conflict_decisions})}else{let l=Ee(a,i,d,{preferred:r});c=l.merged,s.push(...l.conflict_paths),u.json={paths_from_theirs:l.paths_from_theirs}}if(await Ge(o,c,"utf8"),m!==void 0){let l=await ye(m);l!==null&&(u.receipt=T(l))}let f=[];if(s.length>0){let l=u.receipt===void 0?'Run "pm merge report" to inspect clone-local merge evidence.':`Run "pm merge report" and correlate receipt ${u.receipt.receipt_id} with item ${u.receipt.item_id}; clone-local discarded values are never copied into this result.`;f.push(`Both branches changed ${s.join(", ")}; the ${r} value was kept. ${l} Review the merged file, re-apply the losing change if needed, then "git add" it.`)}return n==="history"&&u.history?.reanchored&&f.push('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.'),{ok:s.length===0,artifact:n,output_path:o,preferred:r,conflicts:s,...u,guidance:f,generated_at:S()}}import Ce from"fast-json-patch";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="dd5ab9c3-bc6f-59f1-be89-ad0ab2abe7b5")}catch{}})();function Oe(e,t){return t==="body"?e.body:e.metadata[t]}function K(e,t){if(e===void 0||Object.is(e,t))return!0;if(Array.isArray(e)){if(!Array.isArray(t))return!1;let r=new Set;return e.every(o=>{let a=t.findIndex((i,d)=>!r.has(d)&&K(o,i));return a<0?!1:(r.add(a),!0)})}if(e===null||t===null||typeof e!="object"||typeof t!="object"||Array.isArray(t))return!1;let n=t;return Object.entries(e).every(([r,o])=>Object.hasOwn(n,r)&&K(o,n[r]))}function Ae(e,t){let n=new Set(t),r=[];for(let o=e.length-1;o>=0&&n.size>0;o-=1){let a=e[o],i=new Set;for(let c of de(a.patch))i.add(M(c.path)),c.from&&i.add(M(c.from));let d=[...n].filter(c=>i.has(c));if(d.length!==0){for(let c of d)n.delete(c);r.push({index:o+1,ts:a.ts,author:a.author,op:a.op,fields:d.sort((c,m)=>c.localeCompare(m))})}}return r.reverse()}function Ke(e,t,n){let r=Ce.compare(t,n);if(r.length===0)return;let o=new Set;for(let h of r)o.add(M(h.path));let a=new Set([...o].filter(h=>K(Oe(t,h),Oe(n,h)))),i=new Set([...o].filter(h=>!a.has(h))),d=Ae(e,i),c=Ae(e,a),m=[...o].sort((h,p)=>h.localeCompare(p)),s=[...i].sort((h,p)=>h.localeCompare(p)),u=[...a].sort((h,p)=>h.localeCompare(p)),f=[...new Set(d.map(h=>h.author))].sort((h,p)=>h.localeCompare(p)),l=[...new Set(c.map(h=>h.author))].sort((h,p)=>h.localeCompare(p));return{reconciled_field_count:o.size,reconciled_fields:m,reverted_field_count:i.size,reverted_fields:s,discarded_events:d,discarded_authors:f,preserved_field_count:a.size,preserved_fields:u,preserved_events:c,preserved_authors:l,recovery_hint:d.length>0?"Reconciliation keeps the on-disk item and overwrites these replayed mutations. To recover one, inspect it with pm history <id> --diff --field <field>, then re-apply the lost value with pm update.":null}}async function Qe(e,t,n){let r=e.located?.itemPath??null,o=e.located?await ue(e.located,{schema:t.schema}):null;if(!o)return{currentItemReplay:null,currentItemPath:r,matchedChainBefore:null,currentItemRawBeforeLock:null,loadedItem:null};let a=ce(o.document),i=n[n.length-1]?.after_hash;return{currentItemReplay:a,currentItemPath:r,matchedChainBefore:O(a)===i,currentItemRawBeforeLock:o.raw,loadedItem:o}}function Ye(e){return typeof e.message=="string"&&e.message.trim().length>0?e.message:`history-repair re-anchored ${e.entriesRehashed} entr${e.entriesRehashed===1?"y":"ies"}${e.entriesPatchRepaired>0?`, repaired ${e.entriesPatchRepaired} patch(es)`:""}${e.reconcileNeeded?", reconciled chain with on-disk item":""}.`}function Ze(e){let t=[...e.reanchorEntries];if(!e.changed)return{rewrittenEntries:t,auditEntryAdded:!1};let n=e.reconcileNeeded&&e.currentItemReplay?e.currentItemReplay:e.finalReplay;return t.push({ts:S(),author:e.author,op:e.auditOperation,patch:e.reconcileNeeded&&e.currentItemReplay?Ce.compare(e.finalReplay,e.currentItemReplay):[],before_hash:O(e.finalReplay),after_hash:O(n),message:e.message,...e.auditContext===void 0?{}:{context:e.auditContext}}),{rewrittenEntries:t,auditEntryAdded:!0}}function et(e,t){let n=[];return e||n.push("history_repair_no_changes"),t>0&&n.push(`history_repair_skipped_unresolvable_ops:${t}`),n}async function tt(e){return me({pmRoot:e.pmRoot,subject:e.subject,settings:e.settings,typeRegistry:e.typeRegistry,historyRawBeforeLock:e.historyRawBeforeLock,currentItemRawBeforeLock:e.currentItemRawBeforeLock,operation:"history-repair",author:e.author,force:e.force,itemDocument:e.loadedItem?.document??null,applyRewrite:async({historyRawUnderLock:t})=>fe({historyPath:e.historyPath,nextHistoryRaw:I(e.rewrittenEntries),historyRawUnderLock:t}),applyPostRewrite:async()=>te({path:e.historyPath,scope:"project",op:"history_repair:history"})})}async function Q(e,t,n){let r=C(process.cwd(),n.path);if(!await E(k(r)))throw new g(`Tracker is not initialized at ${r}. Run pm init first.`,y.NOT_FOUND);let o=await x(r),a=L(o,F()),i=await he(r,e,o,a.type_to_folder);if(!await E(i.historyPath))throw new g(`No history stream exists for ${i.id}.`,y.NOT_FOUND);let d=await ee(i.historyPath),c=await se(i.historyPath,i.id);if(c.length===0)throw new g(`No history entries exist for ${i.id}; nothing to repair.`,y.USAGE);let m=B(c),s=j(c),u=await Qe(i,o,c),f=s.finalDocument,l=u.currentItemReplay!==null&&O(f)!==O(u.currentItemReplay),h=l&&u.currentItemReplay?Ke(s.entries,f,u.currentItemReplay):void 0,p=[s.entriesRehashed>0,s.entriesPatchRepaired>0,l,t.forceAuditEntry===!0].some(Boolean),_=re(t.author,o.author_default),R=!!t.dryRun,A=Ye({message:t.message,entriesRehashed:s.entriesRehashed,entriesPatchRepaired:s.entriesPatchRepaired,reconcileNeeded:l}),{rewrittenEntries:Y,auditEntryAdded:Fe}=Ze({reanchorEntries:s.entries,changed:p,reconcileNeeded:l,currentItemReplay:u.currentItemReplay,finalReplay:f,author:_,message:A,auditOperation:t.auditOperation??"history_repair",auditContext:t.auditContext}),N=B(Y);if(!N.ok)throw new g(`history-repair produced an invalid rewritten chain (${N.errors.join(", ")}).`,y.GENERIC_FAILURE);let $=et(p,s.skippedOps);return h&&h.discarded_events.length>0&&($.push(`history_repair_reconcile_discards_events:${h.discarded_events.length}`),$.push(`history_repair_discarded_authors:${h.discarded_authors.join(",")}`)),p&&!R&&$.push(...await tt({pmRoot:r,subject:i,settings:o,typeRegistry:a,historyRawBeforeLock:d,currentItemRawBeforeLock:u.currentItemRawBeforeLock,author:_,force:t.force,loadedItem:u.loadedItem,historyPath:i.historyPath,rewrittenEntries:Y})),{id:i.id,dry_run:R,changed:p,history:{path:i.historyPath,entries_scanned:c.length,chain_drift_before:!m.ok,entries_rehashed:s.entriesRehashed,entries_patch_repaired:s.entriesPatchRepaired,converted_replace_to_add:s.convertedReplaceToAdd,skipped_ops:s.skippedOps,reconciled_with_item:l,audit_entry_added:Fe,verify_ok:N.ok,verify_errors:N.errors},item:{exists:u.currentItemPath!==null,path:u.currentItemPath,matched_chain_before:u.matchedChainBefore},...h?{reconciliation:h}:{},warnings:[...new Set($)].sort((xe,Te)=>xe.localeCompare(Te)),generated_at:S()}}function Ut(e,t){if(t&&e!==void 0)throw new g("history-repair: <id> and --all are mutually exclusive; pass an item id to repair one stream or --all to repair every drifted stream.",y.USAGE);if(!t&&e===void 0)throw new g("history-repair: provide an item <id> or pass --all to repair every drifted stream.",y.USAGE)}async function ke(e,t){let n=C(process.cwd(),t.path);if(!await E(k(n)))throw new g(`Tracker is not initialized at ${n}. Run pm init first.`,y.NOT_FOUND);let r=await x(n),o=L(r,F()),a=[],i=await le(n,r.item_format,o.type_to_folder,a,r.schema,{forceSourceScan:!0}),d=await pe(n,i),c=[],m=[],s={repaired:0,skipped_clean:0,failed:0};for(let u of d.driftedItems)try{let f=await Q(u,{...e,auditContext:e.auditContextById?.[u],auditContextById:void 0},t),l=f.changed?"repaired":"skipped_clean";s[l]+=1,m.push(...f.warnings.map(h=>`${u}:${h}`)),c.push({id:u,outcome:l,entries_rehashed:f.history.entries_rehashed,entries_patch_repaired:f.history.entries_patch_repaired,reconciled_with_item:f.history.reconciled_with_item,...f.reconciliation?{reconciliation:f.reconciliation}:{},warnings:f.warnings})}catch(f){s.failed+=1,c.push({id:u,outcome:"failed",error:f instanceof Error?f.message:String(f)})}return e.dryRun||await ae(n),{all:!0,dry_run:!!e.dryRun,scanned_streams:i.length,drifted_streams:d.driftedItems.length,streams:c,totals:s,warnings:[...new Set([...a,...m])].sort((u,f)=>u.localeCompare(f)),generated_at:S()}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b2f34565-7664-5612-815d-949b8b1d4f90")}catch{}})();async function Wt(e,t){let n=e.dryRun===!0,r=await ge(process.cwd()),o=r.reduce((p,_)=>((p[_.item_id]??=[]).push(_),p),{}),a=Object.fromEntries(Object.entries(o).map(([p,_])=>[p,{merge:{receipts:_.map(T)}}])),i=await ke({dryRun:n,author:e.author??t.author,message:e.message??"post-merge reconciliation of field-aware tracker history",force:e.force,auditOperation:"merge_reconcile",auditContextById:a},t),d=new Set(i.streams.map(p=>p.id)),c=Object.keys(o).filter(p=>!d.has(p));(await Promise.allSettled(c.map(p=>Q(p,{dryRun:n,author:e.author??t.author,message:e.message??"record field-aware branch merge provenance",force:e.force,auditOperation:"merge_reconcile",auditContext:a[p],forceAuditEntry:!0},t)))).forEach((p,_)=>{let R=c[_];if(p.status==="fulfilled"){let A=p.value.changed?"repaired":"skipped_clean";i.streams.push({id:R,outcome:A,entries_rehashed:p.value.history.entries_rehashed,entries_patch_repaired:p.value.history.entries_patch_repaired,reconciled_with_item:p.value.history.reconciled_with_item,warnings:p.value.warnings}),i.totals[A]+=1}else i.streams.push({id:R,outcome:"failed",error:p.reason instanceof Error?p.reason.message:String(p.reason)}),i.totals.failed+=1});let s=0;!n&&i.totals.failed===0&&(await Promise.all(r.map(p=>_e(process.cwd(),p))),s=r.length);let u=await we({checkHistoryDrift:!0,checkStorageIntegrity:!0},t),f=u.checks.every(p=>p.status==="ok"),l=i.totals.failed===0&&f,h=n?["Review repair.streams, then rerun pm merge reconcile without --dry-run to apply audited repairs.","No Git hook is installed automatically; invoke this command from an explicit post-merge hook only when your repository policy opts in."]:l?["Reconciliation is complete; commit changed history streams with the merge result.","Rerun pm merge reconcile --dry-run after future tracker-data merges as a non-mutating integrity check."]:["Reconciliation remains incomplete; inspect repair failures and non-green validation checks before retrying.","Do not commit repaired history streams as reconciled until pm merge reconcile returns ok=true."];return{ok:l,dry_run:n,repair:i,receipts:{pending_before:r.length,reconciled:s,summaries:r.map(T)},validation:u,guidance:h,generated_at:u.generated_at}}export{Re as a,ve as b,Pe as c,De as d,Ie as e,Ee as f,Se as g,It as h,Q as i,Ut as j,ke as k,Wt as l};
|
|
5
|
+
//# sourceMappingURL=chunk-GSW2Y7VZ.js.map
|