@unbrained/pm-cli 2026.8.10 → 2026.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +102 -80
  3. package/dist/cli/commander-usage.js +79 -7
  4. package/dist/cli/error-guidance.d.ts +10 -0
  5. package/dist/cli/error-guidance.js +76 -25
  6. package/dist/cli/main.js +6 -2
  7. package/dist/cli/register-assurance.d.ts +8 -0
  8. package/dist/cli/register-assurance.js +52 -0
  9. package/dist/cli/register-files-lookup.js +14 -3
  10. package/dist/cli/register-mutation.js +30 -9
  11. package/dist/cli/register-operations.js +16 -11
  12. package/dist/cli-bundle/bundle-manifest.json +159 -159
  13. package/dist/cli-bundle/chunks/{chunk-TRWXF476.js → chunk-2OOU2AFH.js} +2 -2
  14. package/dist/cli-bundle/chunks/chunk-2RA2YTHJ.js +33 -0
  15. package/dist/cli-bundle/chunks/chunk-A2SJGHSI.js +3 -0
  16. package/dist/cli-bundle/chunks/chunk-DSKYD4LG.js +13 -0
  17. package/dist/cli-bundle/chunks/chunk-HC3GM6YY.js +194 -0
  18. package/dist/cli-bundle/chunks/chunk-IUNRVDAI.js +2 -0
  19. package/dist/cli-bundle/chunks/chunk-W7CPZGSB.js +2 -0
  20. package/dist/cli-bundle/chunks/{chunk-EBO7OUUE.js → chunk-WMEZHCFI.js} +59 -53
  21. package/dist/cli-bundle/chunks/{chunk-ETML5C6H.js → chunk-ZU34C3LH.js} +47 -47
  22. package/dist/cli-bundle/chunks/chunk-ZXOC6HG5.js +5 -0
  23. package/dist/cli-bundle/chunks/{register-list-query-OJ6ZXKV4.js → register-list-query-HAUXVUPY.js} +8 -8
  24. package/dist/cli-bundle/chunks/register-mutation-7Y5U7ABT.js +20 -0
  25. package/dist/cli-bundle/chunks/register-operations-EQX3DLAZ.js +2 -0
  26. package/dist/cli-bundle/chunks/{register-setup-S3KT2LTH.js → register-setup-NOCOOWQY.js} +2 -2
  27. package/dist/cli-bundle/focused-chunks/{chunk-34SX654S.js → chunk-23FTGO3W.js} +2 -2
  28. package/dist/cli-bundle/focused-chunks/{chunk-2COZ67XT.js → chunk-2DL3MRTD.js} +2 -2
  29. package/dist/cli-bundle/focused-chunks/chunk-3AYKXMYX.js +2 -0
  30. package/dist/cli-bundle/focused-chunks/chunk-4AHEC74N.js +2 -0
  31. package/dist/cli-bundle/focused-chunks/{chunk-7UN6BHHO.js → chunk-4H5IA6AV.js} +2 -2
  32. package/dist/cli-bundle/focused-chunks/chunk-4SV3ZKG3.js +16 -0
  33. package/dist/cli-bundle/focused-chunks/chunk-55BIB6DV.js +2 -0
  34. package/dist/cli-bundle/focused-chunks/chunk-6JW6Z2P5.js +8 -0
  35. package/dist/cli-bundle/focused-chunks/{chunk-IW43E4XL.js → chunk-BKPIY34S.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/chunk-D4PIWE6D.js +2 -0
  37. package/dist/cli-bundle/focused-chunks/{chunk-KR5RVXLQ.js → chunk-DPO7TEFX.js} +29 -29
  38. package/dist/cli-bundle/focused-chunks/{chunk-JMVA4HKR.js → chunk-E3KCL7AY.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/chunk-ERAAFLPS.js +153 -0
  40. package/dist/cli-bundle/focused-chunks/{chunk-RIIN5V4N.js → chunk-F6E4JZKG.js} +2 -2
  41. package/dist/cli-bundle/focused-chunks/chunk-FPSYO5ZG.js +18 -0
  42. package/dist/cli-bundle/focused-chunks/{chunk-M6RPIXKC.js → chunk-J5EKAIVD.js} +2 -2
  43. package/dist/cli-bundle/focused-chunks/{chunk-2EXI2DKR.js → chunk-KDH5OX3D.js} +2 -2
  44. package/dist/cli-bundle/focused-chunks/chunk-OJ3LVVIS.js +2 -0
  45. package/dist/cli-bundle/focused-chunks/{chunk-DZGAHZZV.js → chunk-TL5M2PAY.js} +2 -2
  46. package/dist/cli-bundle/focused-chunks/{chunk-75774JWP.js → chunk-UDAZWT25.js} +2 -2
  47. package/dist/cli-bundle/focused-chunks/chunk-VABB4L5Y.js +17 -0
  48. package/dist/cli-bundle/main.js +13 -13
  49. package/dist/cli-bundle/sdk-authoring.js +1 -1
  50. package/dist/cli-bundle/sdk-contracts.js +1 -1
  51. package/dist/cli-bundle/sdk-core.js +41 -39
  52. package/dist/cli-bundle/sdk-governance.js +1 -1
  53. package/dist/cli-bundle/sdk-graph.js +1 -1
  54. package/dist/cli-bundle/sdk-merge.js +1 -1
  55. package/dist/cli-bundle/sdk-query.js +1 -1
  56. package/dist/cli-bundle/sdk-runtime.js +1 -1
  57. package/dist/cli-bundle/sdk-testing.js +1 -1
  58. package/dist/cli-bundle/sdk.js +2 -2
  59. package/dist/core/session/session-state.d.ts +47 -0
  60. package/dist/core/session/session-state.js +207 -6
  61. package/dist/core/shared/author.d.ts +7 -1
  62. package/dist/core/shared/author.js +66 -46
  63. package/dist/core/shared/errors.d.ts +8 -0
  64. package/dist/core/shared/errors.js +2 -2
  65. package/dist/sdk/agent/refusal-reachability.d.ts +40 -0
  66. package/dist/sdk/agent/refusal-reachability.js +72 -0
  67. package/dist/sdk/agent/subcommand-recovery.d.ts +40 -0
  68. package/dist/sdk/agent/subcommand-recovery.js +84 -0
  69. package/dist/sdk/cli-bootstrap.d.ts +8 -0
  70. package/dist/sdk/cli-bootstrap.js +7 -7
  71. package/dist/sdk/cli-contracts/completeness.js +13 -3
  72. package/dist/sdk/cli-contracts/enum-contracts.d.ts +1 -1
  73. package/dist/sdk/cli-contracts/enum-contracts.js +3 -2
  74. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  75. package/dist/sdk/cli-contracts/flag-contracts.js +17 -2
  76. package/dist/sdk/cli-contracts/runtime-contracts.js +4 -3
  77. package/dist/sdk/cli-contracts/schemas/assurance-definition.d.ts +513 -0
  78. package/dist/sdk/cli-contracts/schemas/assurance-definition.js +251 -0
  79. package/dist/sdk/cli-contracts/tool-parameter-tables.js +79 -2
  80. package/dist/sdk/cli-contracts/tool-schema.d.ts +2 -2
  81. package/dist/sdk/cli-contracts/tool-schema.js +34 -4
  82. package/dist/sdk/cli-contracts.d.ts +1 -1
  83. package/dist/sdk/cli-contracts.js +3 -3
  84. package/dist/sdk/completion.js +9 -3
  85. package/dist/sdk/config.js +9 -3
  86. package/dist/sdk/context/semantic-session-attribution.d.ts +32 -0
  87. package/dist/sdk/context/semantic-session-attribution.js +83 -0
  88. package/dist/sdk/core-governance.d.ts +3 -1
  89. package/dist/sdk/core-governance.js +5 -3
  90. package/dist/sdk/core.d.ts +1 -1
  91. package/dist/sdk/core.js +2 -2
  92. package/dist/sdk/error-code-catalog.d.ts +13 -0
  93. package/dist/sdk/error-code-catalog.js +35 -2
  94. package/dist/sdk/extension.js +18 -17
  95. package/dist/sdk/files.d.ts +11 -0
  96. package/dist/sdk/files.js +82 -24
  97. package/dist/sdk/generated-error-code-catalog.js +32 -13
  98. package/dist/sdk/governance/assurance-action-contracts.d.ts +7 -0
  99. package/dist/sdk/governance/assurance-action-contracts.js +5 -0
  100. package/dist/sdk/governance/assurance-action.d.ts +70 -0
  101. package/dist/sdk/governance/assurance-action.js +198 -0
  102. package/dist/sdk/governance/assurance-limits.d.ts +7 -0
  103. package/dist/sdk/governance/assurance-limits.js +11 -0
  104. package/dist/sdk/governance/assurance-runtime.d.ts +20 -0
  105. package/dist/sdk/governance/assurance-runtime.js +131 -0
  106. package/dist/sdk/governance/assurance.d.ts +432 -0
  107. package/dist/sdk/governance/assurance.js +689 -0
  108. package/dist/sdk/graph/run.js +8 -3
  109. package/dist/sdk/index.d.ts +6 -1
  110. package/dist/sdk/index.js +8 -3
  111. package/dist/sdk/lifecycle/claim.js +18 -3
  112. package/dist/sdk/lifecycle/focus.js +13 -3
  113. package/dist/sdk/lifecycle/plan.js +8 -3
  114. package/dist/sdk/provenance.d.ts +38 -0
  115. package/dist/sdk/provenance.js +64 -2
  116. package/dist/sdk/query/context.js +19 -8
  117. package/dist/sdk/runtime-extended-actions.js +22 -5
  118. package/dist/sdk/runtime-primitives.d.ts +2 -0
  119. package/dist/sdk/runtime-primitives.js +4 -2
  120. package/dist/sdk/runtime.d.ts +4 -0
  121. package/dist/sdk/runtime.js +31 -27
  122. package/dist/sdk/telemetry.js +7 -4
  123. package/dist/sdk/traceability/runtime-files-lookup.d.ts +8 -0
  124. package/dist/sdk/traceability/runtime-files-lookup.js +33 -0
  125. package/dist/sdk/traceability/source-traceability.d.ts +102 -0
  126. package/dist/sdk/traceability/source-traceability.js +293 -0
  127. package/dist/types.d.ts +8 -2
  128. package/dist/types.js +2 -2
  129. package/docs/ASSURANCE.md +132 -0
  130. package/docs/README.md +1 -0
  131. package/docs/RELEASING.md +9 -5
  132. package/docs/SDK.md +12 -1
  133. package/docs/SDK_AGENT_SESSION_CONTEXT.md +40 -4
  134. package/docs/SDK_EVIDENCE_TRACEABILITY.md +39 -1
  135. package/docs/SDK_RUNTIME_BOUNDARIES.md +36 -1
  136. package/docs/TESTING.md +12 -9
  137. package/docs/generated/AGENT_COMMAND_SURFACE.md +1 -0
  138. package/marketplace.json +2 -2
  139. package/package.json +3 -3
  140. package/packages/pm-beads/package.json +1 -1
  141. package/packages/pm-calendar/package.json +1 -1
  142. package/packages/pm-command-kit/package.json +1 -1
  143. package/packages/pm-digital-twin/package.json +1 -1
  144. package/packages/pm-governance-audit/package.json +1 -1
  145. package/packages/pm-guide-shell/package.json +1 -1
  146. package/packages/pm-kanban/package.json +1 -1
  147. package/packages/pm-lifecycle-hooks/package.json +1 -1
  148. package/packages/pm-linked-test-adapters/package.json +1 -1
  149. package/packages/pm-search-advanced/package.json +1 -1
  150. package/packages/pm-templates/extensions/templates/index.ts +9 -3
  151. package/packages/pm-templates/package.json +1 -1
  152. package/packages/pm-todos/package.json +1 -1
  153. package/packages/pm-vcs/package.json +1 -1
  154. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  155. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  156. package/sdk/public-surface.json +840 -28
  157. package/dist/cli-bundle/chunks/chunk-2QYH4QMI.js +0 -30
  158. package/dist/cli-bundle/chunks/chunk-JUDU4RO4.js +0 -194
  159. package/dist/cli-bundle/chunks/chunk-JZSNADRR.js +0 -5
  160. package/dist/cli-bundle/chunks/chunk-MENWVGJW.js +0 -2
  161. package/dist/cli-bundle/chunks/chunk-S4EITGLA.js +0 -3
  162. package/dist/cli-bundle/chunks/chunk-TIGKWVLA.js +0 -13
  163. package/dist/cli-bundle/chunks/chunk-TSLDTJLQ.js +0 -2
  164. package/dist/cli-bundle/chunks/register-mutation-DKI7QC7O.js +0 -20
  165. package/dist/cli-bundle/chunks/register-operations-P5OGMT6I.js +0 -2
  166. package/dist/cli-bundle/focused-chunks/chunk-36FTZ2NT.js +0 -2
  167. package/dist/cli-bundle/focused-chunks/chunk-3CQECMKR.js +0 -16
  168. package/dist/cli-bundle/focused-chunks/chunk-CHIBMEZR.js +0 -8
  169. package/dist/cli-bundle/focused-chunks/chunk-FF4MNAYB.js +0 -153
  170. package/dist/cli-bundle/focused-chunks/chunk-GHTN2ILR.js +0 -2
  171. package/dist/cli-bundle/focused-chunks/chunk-I4YM2I7S.js +0 -2
  172. package/dist/cli-bundle/focused-chunks/chunk-IMDTEN7K.js +0 -2
  173. package/dist/cli-bundle/focused-chunks/chunk-KSNJG4KI.js +0 -16
  174. package/dist/cli-bundle/focused-chunks/chunk-MXYSIQ56.js +0 -18
  175. package/dist/cli-bundle/focused-chunks/chunk-RKWSCYYN.js +0 -2
@@ -1,5 +1,5 @@
1
- import{V as $,W as pe,X as ye,Y as ge,Z as _e,q as he,ya as we}from"./chunk-3CQECMKR.js";import{e as ue,f as fe,g as me}from"./chunk-34SX654S.js";import{g as L}from"./chunk-MXYSIQ56.js";import{Aa as U,Ba as M,Ca as b,L as te,M as C,Ma as x,N as D,ca as j,cb as de,ea as re,fa as ne,fb as le,ga as ie,ha as oe,k as T,ma as se,n as ee,ua as A,xa as ae,ya as ce}from"./chunk-FF4MNAYB.js";import{E as B,K as k,N as F,h as Y,p as O,r as Z}from"./chunk-2EXI2DKR.js";import{Y as g,Z as _,aa as R}from"./chunk-GHTN2ILR.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]="f6f04eec-0698-5e5b-a40e-de3a4be89f95")}catch{}})();function J(e,t){let n=j(e);if(n)throw new _(`History merge input (${t}) contains unresolved conflict markers at line ${n.line}. Merge drivers must receive clean per-side versions.`,g.GENERIC_FAILURE);let r=[];for(let[o,s]of e.split(/\r?\n/).entries()){let i=s.trim();if(i)try{let c=JSON.parse(i);if(typeof c!="object"||c===null||Array.isArray(c))throw new TypeError("history entry must be an object");r.push(c)}catch{throw new _(`History merge input (${t}) contains invalid JSON at line ${o+1}.`,g.GENERIC_FAILURE)}}return r}function I(e){return R({ts:e.ts,author:e.author,op:e.op,patch:e.patch,message:e.message??null})}function Pe(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&I(e[r])===I(t[r]);)r+=1;return r}function Re(e,t,n){J(e,"base");let r=J(t,"ours"),o=J(n,"theirs"),s=Pe(r,o);if(s===r.length&&s===o.length)return{merged:b(r),strategy:"identical",common_entries:s,entries_from_ours:0,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(s===o.length)return{merged:b(r),strategy:"fast_forward_ours",common_entries:s,entries_from_ours:r.length-s,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(s===r.length)return{merged:b(o),strategy:"fast_forward_theirs",common_entries:s,entries_from_ours:0,entries_from_theirs:o.length-s,entries_total:o.length,reanchored:!1};let i=r.slice(s),c=new Set(i.map(I)),d=o.slice(s).filter(l=>!c.has(I(l))),u=[...i,...d].sort((l,m)=>{let f=D(l.ts,m.ts);if(f!==0)return f;let h=c.has(I(l)),y=c.has(I(m));return h!==y?Number(y)-Number(h):I(l).localeCompare(I(m))}),a=M([...r.slice(0,s),...u]);return{merged:b(a.entries),strategy:"union_reanchor",common_entries:s,entries_from_ours:i.length,entries_from_theirs:d.length,entries_total:a.entries.length,reanchored:!0}}function G(e,t){let n=j(e);if(n)throw new _(`Relationship merge input (${t}) contains unresolved conflict markers at line ${n.line}. Merge drivers must receive clean per-side versions.`,g.GENERIC_FAILURE);let r=[];for(let[o,s]of e.split(/\r?\n/).entries()){let i=s.trim();if(!i)continue;let c;try{c=JSON.parse(i)}catch{throw new _(`Relationship merge input (${t}) contains invalid JSON at line ${o+1}.`,g.GENERIC_FAILURE)}if(typeof c!="object"||c===null||Array.isArray(c)||typeof c.eventId!="string"||typeof c.sequence!="number")throw new _(`Relationship merge input (${t}) line ${o+1} is not a relationship event (eventId + sequence required).`,g.GENERIC_FAILURE);r.push(c)}return r}function H(e){return e.length===0?"":`${e.map(t=>JSON.stringify(t)).join(`
1
+ import{Aa as we,V as $,W as pe,X as ye,Y as ge,Z as _e,b as he}from"./chunk-VABB4L5Y.js";import{e as ue,f as fe,g as me}from"./chunk-23FTGO3W.js";import{g as L}from"./chunk-FPSYO5ZG.js";import{Ca as A,Fa as ae,Ga as ce,Ia as U,Ja as M,Ka as b,T as te,U as C,Ua as x,V as D,k as T,ka as j,kb as de,ma as re,n as ee,na as ne,nb as le,oa as ie,pa as oe,ua as se}from"./chunk-ERAAFLPS.js";import{E as B,K as k,N as F,h as Y,p as O,r as Z}from"./chunk-KDH5OX3D.js";import{Y as g,Z as _,aa as R}from"./chunk-D4PIWE6D.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]="f6f04eec-0698-5e5b-a40e-de3a4be89f95")}catch{}})();function J(e,t){let n=j(e);if(n)throw new _(`History merge input (${t}) contains unresolved conflict markers at line ${n.line}. Merge drivers must receive clean per-side versions.`,g.GENERIC_FAILURE);let r=[];for(let[o,s]of e.split(/\r?\n/).entries()){let i=s.trim();if(i)try{let c=JSON.parse(i);if(typeof c!="object"||c===null||Array.isArray(c))throw new TypeError("history entry must be an object");r.push(c)}catch{throw new _(`History merge input (${t}) contains invalid JSON at line ${o+1}.`,g.GENERIC_FAILURE)}}return r}function I(e){return R({ts:e.ts,author:e.author,op:e.op,patch:e.patch,message:e.message??null})}function Pe(e,t){let n=Math.min(e.length,t.length),r=0;for(;r<n&&I(e[r])===I(t[r]);)r+=1;return r}function Re(e,t,n){J(e,"base");let r=J(t,"ours"),o=J(n,"theirs"),s=Pe(r,o);if(s===r.length&&s===o.length)return{merged:b(r),strategy:"identical",common_entries:s,entries_from_ours:0,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(s===o.length)return{merged:b(r),strategy:"fast_forward_ours",common_entries:s,entries_from_ours:r.length-s,entries_from_theirs:0,entries_total:r.length,reanchored:!1};if(s===r.length)return{merged:b(o),strategy:"fast_forward_theirs",common_entries:s,entries_from_ours:0,entries_from_theirs:o.length-s,entries_total:o.length,reanchored:!1};let i=r.slice(s),c=new Set(i.map(I)),d=o.slice(s).filter(l=>!c.has(I(l))),u=[...i,...d].sort((l,m)=>{let f=D(l.ts,m.ts);if(f!==0)return f;let h=c.has(I(l)),y=c.has(I(m));return h!==y?Number(y)-Number(h):I(l).localeCompare(I(m))}),a=M([...r.slice(0,s),...u]);return{merged:b(a.entries),strategy:"union_reanchor",common_entries:s,entries_from_ours:i.length,entries_from_theirs:d.length,entries_total:a.entries.length,reanchored:!0}}function G(e,t){let n=j(e);if(n)throw new _(`Relationship merge input (${t}) contains unresolved conflict markers at line ${n.line}. Merge drivers must receive clean per-side versions.`,g.GENERIC_FAILURE);let r=[];for(let[o,s]of e.split(/\r?\n/).entries()){let i=s.trim();if(!i)continue;let c;try{c=JSON.parse(i)}catch{throw new _(`Relationship merge input (${t}) contains invalid JSON at line ${o+1}.`,g.GENERIC_FAILURE)}if(typeof c!="object"||c===null||Array.isArray(c)||typeof c.eventId!="string"||typeof c.sequence!="number")throw new _(`Relationship merge input (${t}) line ${o+1} is not a relationship event (eventId + sequence required).`,g.GENERIC_FAILURE);r.push(c)}return r}function H(e){return e.length===0?"":`${e.map(t=>JSON.stringify(t)).join(`
2
2
  `)}
3
3
  `}function De(e){return e.map((t,n)=>({...t,sequence:n+1}))}function ve(e,t,n){G(e,"base");let r=G(t,"ours"),o=G(n,"theirs"),s=Math.min(r.length,o.length),i=0;for(;i<s&&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 c=r.slice(i),d=new Set(c.map(m=>m.eventId)),u=o.slice(i).filter(m=>!d.has(m.eventId)),a=[...c,...u].sort((m,f)=>{if(m.timestamp!==void 0&&f.timestamp!==void 0){let p=D(m.timestamp,f.timestamp);if(p!==0)return p}else{if(m.timestamp===void 0&&f.timestamp!==void 0)return 1;if(m.timestamp!==void 0)return-1}let h=d.has(m.eventId),y=d.has(f.eventId);return h!==y?Number(y)-Number(h):0}),l=De([...r.slice(0,i),...a]);return{merged:H(l),strategy:"union_reanchor",common_entries:i,entries_from_ours:c.length,entries_from_theirs:u.length,entries_total:l.length,reanchored:!0}}var je=["tags","dependencies","comments","notes","learnings","files","tests","test_runs","docs","reminders","events"],Me=["updated_at"];function E(e,t){return R(e??null)===R(t??null)}function Le(e,t,n){let r=a=>Array.isArray(a)?a:[],o=new Set(r(e).map(a=>R(a))),s=r(t),i=new Set(s.map(a=>R(a))),c=r(n),d=new Set(c.map(a=>R(a))),u=s.filter(a=>{let l=R(a);return!o.has(l)||d.has(l)});for(let a of c){let l=R(a);!i.has(l)&&!o.has(l)&&u.push(a)}return u}function He(e,t){return D(String(e),String(t))>=0?e:t}function Ie(e,t,n,r){return E(t,n)?{value:t,from_theirs:!1,conflict:!1}:E(e,t)?{value:n,from_theirs:!0,conflict:!1}:E(e,n)?{value:t,from_theirs:!1,conflict:!1}:{value:r==="theirs"?n:t,from_theirs:r==="theirs",conflict:!0}}function be(e,t,n,r,o){let s=Ie(e,t,n,r);if(!s.conflict||o==="preferred_side")return s;let i=R(n).localeCompare(R(t))<0;return{value:i?n:t,from_theirs:i,conflict:!0}}function z(e){return{...e.metadata}}function V(e,t,n){try{return ie(re(e,n),n)}catch(r){throw new _(`Item merge input (${t}) is not a readable item document: ${String(r)}`,g.GENERIC_FAILURE)}}function Be(e,t,n,r,o){let s=new Set(je),i=new Set(Me),c=[...new Set([...Object.keys(t),...Object.keys(n)])].sort((u,a)=>u.localeCompare(a)),d={merged:{},conflictFields:[],fieldsFromTheirs:[],unionFields:[],conflictDecisions:[]};for(let u of c){let a=e[u],l=t[u],m=n[u];if(s.has(u)){let h=Le(a,l,m);d.merged[u]=h,E(h,l)||d.unionFields.push(u);continue}if(i.has(u)){d.merged[u]=He(l,m);continue}let f=be(a,l,m,r,o);f.value!==void 0&&(d.merged[u]=f.value),f.conflict?(d.conflictFields.push(u),d.conflictDecisions.push({field:u,base:a,ours:l,theirs:m,retained:f.value,discarded:f.from_theirs?l:m})):f.from_theirs&&d.fieldsFromTheirs.push(u)}return d}function Ee(e,t,n,r={}){let o=r.preferred??"ours",s=r.conflictResolution??"preferred_side",i=e.trim().length>0,c=V(t,"ours",r),d=V(n,"theirs",r),u=i?V(e,"base",r):c,a=i?z(u):{},l=z(c),m=z(d),{merged:f,conflictFields:h,fieldsFromTheirs:y,unionFields:p,conflictDecisions:w}=Be(a,l,m,o,s),v=be(i?u.body:"",c.body,d.body,o,s);return v.conflict?(h.push("body"),w.push({field:"body",base:i?u.body:"",ours:c.body,theirs:d.body,retained:v.value,discarded:v.from_theirs?c.body:d.body})):v.from_theirs&&y.push("body"),{merged:ne({metadata:f,body:v.value},r),conflict_fields:h,fields_from_theirs:y,union_fields:p,conflict_decisions:w,preferred:o,conflict_resolution:s}}function W(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function q(e,t){let n=j(e);if(n)throw new _(`JSON merge input (${t}) contains unresolved conflict markers at line ${n.line}.`,g.GENERIC_FAILURE);if(e.trim().length!==0)try{return JSON.parse(e)}catch{throw new _(`JSON merge input (${t}) is not valid JSON.`,g.GENERIC_FAILURE)}}function Ue(e,t,n){if(!Array.isArray(e)||!Array.isArray(t)||!Array.isArray(n))return null;let r=u=>{let a=new Map;for(let l of u){let m=R(l);a.set(m,(a.get(m)??0)+1)}return a},o=r(e),s=r(t),i=r(n);for(let[u,a]of o)if((s.get(u)??0)<a||(i.get(u)??0)<a)return null;let c=new Map(s),d=[];for(let u of n){let a=R(u),l=c.get(a)??0;l>0?c.set(a,l-1):d.push(u)}return{merged:[...t,...d],acceptedTheirs:d.length>0}}function Je(e,t,n,r,o,s,i){if(!W(t)||!W(n))return null;let c=W(e)?e:{},d={},u=[...new Set([...Object.keys(t),...Object.keys(n)])].sort((a,l)=>a.localeCompare(l));for(let a of u){let l=o.length>0?`${o}.${a}`:a,m=Ge(c,t,n,a,r,l,s,i);m!==void 0&&(d[a]=m)}return d}function Se(e,t,n,r,o,s,i){if(E(t,n))return t;let c=Ue(e,t,n);if(c!==null)return c.acceptedTheirs&&i.push(o),c.merged;let d=Je(e,t,n,r,o,s,i);if(d!==null)return d;let u=Ie(e,t,n,r);return u.conflict?s.push(o):u.from_theirs&&i.push(o),u.value}function Ge(e,t,n,r,o,s,i,c){let d=Object.prototype.hasOwnProperty.call(t,r),u=Object.prototype.hasOwnProperty.call(n,r),a=Object.prototype.hasOwnProperty.call(e,r);if(d&&u)return Se(e[r],t[r],n[r],o,s,i,c);if(d){if(a&&E(e[r],t[r])){c.push(s);return}return a?(i.push(s),o==="theirs"?void 0:t[r]):t[r]}if(!(a&&E(e[r],n[r])))return a?(i.push(s),o==="theirs"?n[r]:void 0):(c.push(s),n[r])}function Oe(e,t,n,r={}){let o=r.preferred??"ours",s=q(e,"base"),i=q(t,"ours"),c=q(n,"theirs"),d=[],u=[],a=Se(s,i,c,o,"",d,u);return{merged:`${JSON.stringify(a??null,null,2)}
4
4
  `,conflict_paths:d,paths_from_theirs:u,preferred:o}}import{readFile as ze,writeFile as Ve}from"node:fs/promises";import We 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]="e739a603-35c5-5df9-8d4b-3bbc0fe3e4fd")}catch{}})();var Ce=["item","history","relationship","json"];function qe(e){let t=e.trim().toLowerCase();if(Ce.includes(t))return t;throw new _(`Unknown merge artifact "${e}". Supported values: ${Ce.join(", ")}.`,g.USAGE)}function Xe(e){if(e===void 0)return"ours";let t=e.trim().toLowerCase();if(t==="ours"||t==="theirs")return t;throw new _(`Unknown --prefer value "${e}". Supported values: ours, theirs.`,g.USAGE)}async function X(e,t){try{return await ze(e,"utf8")}catch{throw new _(`Cannot read merge ${t} file at ${e}.`,g.NOT_FOUND)}}async function Ke(e){let t=k(process.cwd(),e.path);return await O(F(t))?x(t):null}function Qe(e,t){return e.endsWith(".md")?"json_markdown":e.endsWith(".toon")?"toon":t?.item_format??"toon"}async function Et(e,t){let n=qe(e.artifact),r=Xe(e.prefer),o=We.resolve(e.outputPath??e.oursPath),[s,i,c]=await Promise.all([X(e.basePath,"base"),X(e.oursPath,"ours"),X(e.theirsPath,"theirs")]),d,u,a=[],l={};if(n==="history"){let f=Re(s,i,c);d=f.merged,l.history={strategy:f.strategy,common_entries:f.common_entries,entries_from_ours:f.entries_from_ours,entries_from_theirs:f.entries_from_theirs,entries_total:f.entries_total,reanchored:f.reanchored}}else if(n==="relationship"){let f=ve(s,i,c);d=f.merged,l.relationship={strategy:f.strategy,common_entries:f.common_entries,entries_from_ours:f.entries_from_ours,entries_from_theirs:f.entries_from_theirs,entries_total:f.entries_total,reanchored:f.reanchored}}else if(n==="item"){let f=await Ke(t),h=Ee(s,i,c,{format:Qe(e.itemPath??o,f),schema:f?.schema,extensionFieldNames:Y(T()),preferred:r,conflictResolution:"stable_value_order"});d=h.merged,a.push(...h.conflict_fields),l.item={fields_from_theirs:h.fields_from_theirs,union_fields:h.union_fields,conflict_resolution:"stable_value_order"},e.itemPath!==void 0&&(u={cwd:process.cwd(),itemPath:e.itemPath,preferred:r,conflictResolution:"stable_value_order",fieldsFromTheirs:h.fields_from_theirs,unionFields:h.union_fields,decisions:h.conflict_decisions})}else{let f=Oe(s,i,c,{preferred:r});d=f.merged,a.push(...f.conflict_paths),l.json={paths_from_theirs:f.paths_from_theirs}}if(await Ve(o,d,"utf8"),u!==void 0){let f=await pe(u);f!==null&&(l.receipt=$(f))}let m=[];if(a.length>0){let f=l.receipt===void 0?'Run "pm merge report" to inspect clone-local merge evidence.':`Run "pm merge report" and correlate receipt ${l.receipt.receipt_id} with item ${l.receipt.item_id}; clone-local discarded values are never copied into this result.`;m.push(`Both branches changed ${a.join(", ")}; the item driver kept the direction-independent stable value. ${f} Review the merged file, re-apply the discarded change if needed, then "git add" it.`)}return n==="history"&&l.history?.reanchored&&m.push('The merged history chain was re-anchored. Run "pm merge reconcile --dry-run" to inspect the complete post-merge repair, then "pm merge reconcile" to apply it; use --force only after explicitly accepting reported discards.'),{ok:a.length===0,artifact:n,output_path:o,preferred:r,conflicts:a,...l,guidance:m,generated_at:C()}}import Fe 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 Ae(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 s=t.findIndex((i,c)=>!r.has(c)&&K(o,i));return s<0?!1:(r.add(s),!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 ke(e,t){let n=new Set(t),r=[];for(let o=e.length-1;o>=0&&n.size>0;o-=1){let s=e[o],i=new Set;for(let d of ce(s.patch))i.add(L(d.path)),d.from&&i.add(L(d.from));let c=[...n].filter(d=>i.has(d));if(c.length!==0){for(let d of c)n.delete(d);r.push({index:o+1,ts:s.ts,author:s.author,op:s.op,fields:c.sort((d,u)=>d.localeCompare(u))})}}return r.reverse()}function Ye(e,t,n){let r=Fe.compare(t,n);if(r.length===0)return;let o=new Set;for(let h of r)o.add(L(h.path));let s=new Set([...o].filter(h=>K(Ae(t,h),Ae(n,h)))),i=new Set([...o].filter(h=>!s.has(h))),c=ke(e,i),d=ke(e,s),u=[...o].sort((h,y)=>h.localeCompare(y)),a=[...i].sort((h,y)=>h.localeCompare(y)),l=[...s].sort((h,y)=>h.localeCompare(y)),m=[...new Set(c.map(h=>h.author))].sort((h,y)=>h.localeCompare(y)),f=[...new Set(d.map(h=>h.author))].sort((h,y)=>h.localeCompare(y));return{reconciled_field_count:o.size,reconciled_fields:u,reverted_field_count:i.size,reverted_fields:a,discarded_events:c,discarded_authors:m,preserved_field_count:s.size,preserved_fields:l,preserved_events:d,preserved_authors:f,recovery_hint:c.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 Ze(e,t,n){let r=e.located?.itemPath??null,o=e.located?await de(e.located,{schema:t.schema}):null;if(!o)return{currentItemReplay:null,currentItemPath:r,matchedChainBefore:null,currentItemRawBeforeLock:null,loadedItem:null};let s=ae(o.document),i=n[n.length-1]?.after_hash;return{currentItemReplay:s,currentItemPath:r,matchedChainBefore:A(s)===i,currentItemRawBeforeLock:o.raw,loadedItem:o}}function et(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 tt(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:C(),author:e.author,op:e.auditOperation,patch:e.reconcileNeeded&&e.currentItemReplay?Fe.compare(e.finalReplay,e.currentItemReplay):[],before_hash:A(e.finalReplay),after_hash:A(n),message:e.message,...e.auditContext===void 0?{}:{context:e.auditContext}}),{rewrittenEntries:t,auditEntryAdded:!0}}function rt(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 nt(e){return fe({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})=>ue({historyPath:e.historyPath,nextHistoryRaw:b(e.rewrittenEntries),historyRawUnderLock:t}),applyPostRewrite:async()=>ee({path:e.historyPath,scope:"project",op:"history_repair:history"})})}async function Q(e,t,n){let r=k(process.cwd(),n.path);if(!await O(F(r)))throw new _(`Tracker is not initialized at ${r}. Run pm init first.`,g.NOT_FOUND);let o=await x(r),s=B(o,T()),i=await me(r,e,o,s.type_to_folder);if(!await O(i.historyPath))throw new _(`No history stream exists for ${i.id}.`,g.NOT_FOUND);let c=await Z(i.historyPath),d=await oe(i.historyPath,i.id);if(d.length===0)throw new _(`No history entries exist for ${i.id}; nothing to repair.`,g.USAGE);let u=U(d),a=M(d),l=await Ze(i,o,d),m=a.finalDocument,f=l.currentItemReplay!==null&&A(m)!==A(l.currentItemReplay),h=f&&l.currentItemReplay?Ye(a.entries,m,l.currentItemReplay):void 0,y=[a.entriesRehashed>0,a.entriesPatchRepaired>0,f,t.forceAuditEntry===!0].some(Boolean),p=te(t.author,o.author_default),w=!!t.dryRun,v=et({message:t.message,entriesRehashed:a.entriesRehashed,entriesPatchRepaired:a.entriesPatchRepaired,reconcileNeeded:f}),{rewrittenEntries:S,auditEntryAdded:xe}=tt({reanchorEntries:a.entries,changed:y,reconcileNeeded:f,currentItemReplay:l.currentItemReplay,finalReplay:m,author:p,message:v,auditOperation:t.auditOperation??"history_repair",auditContext:t.auditContext}),N=U(S);if(!N.ok)throw new _(`history-repair produced an invalid rewritten chain (${N.errors.join(", ")}).`,g.GENERIC_FAILURE);let P=rt(y,a.skippedOps);return h&&h.discarded_events.length>0&&(P.push(`history_repair_reconcile_discards_events:${h.discarded_events.length}`),P.push(`history_repair_discarded_authors:${h.discarded_authors.join(",")}`)),y&&!w&&P.push(...await nt({pmRoot:r,subject:i,settings:o,typeRegistry:s,historyRawBeforeLock:c,currentItemRawBeforeLock:l.currentItemRawBeforeLock,author:p,force:t.force,loadedItem:l.loadedItem,historyPath:i.historyPath,rewrittenEntries:S})),{id:i.id,dry_run:w,changed:y,history:{path:i.historyPath,entries_scanned:d.length,chain_drift_before:!u.ok,entries_rehashed:a.entriesRehashed,entries_patch_repaired:a.entriesPatchRepaired,converted_replace_to_add:a.convertedReplaceToAdd,skipped_ops:a.skippedOps,reconciled_with_item:f,audit_entry_added:xe,verify_ok:N.ok,verify_errors:N.errors},item:{exists:l.currentItemPath!==null,path:l.currentItemPath,matched_chain_before:l.matchedChainBefore},...h?{reconciliation:h}:{},warnings:[...new Set(P)].sort(($e,Ne)=>$e.localeCompare(Ne)),generated_at:C()}}function Gt(e,t){if(t&&e!==void 0)throw new _("history-repair: <id> and --all are mutually exclusive; pass an item id to repair one stream or --all to repair every drifted stream.",g.USAGE);if(!t&&e===void 0)throw new _("history-repair: provide an item <id> or pass --all to repair every drifted stream.",g.USAGE)}async function Te(e,t){let n=k(process.cwd(),t.path);if(!await O(F(n)))throw new _(`Tracker is not initialized at ${n}. Run pm init first.`,g.NOT_FOUND);let r=await x(n),o=B(r,T()),s=[],i=await le(n,r.item_format,o.type_to_folder,s,r.schema,{forceSourceScan:!0}),c=await he(n,i),d=[],u=[],a={repaired:0,skipped_clean:0,failed:0};for(let l of c.driftedItems)try{let m=await Q(l,{...e,auditContext:e.auditContextById?.[l],auditContextById:void 0},t),f=m.changed?"repaired":"skipped_clean";a[f]+=1,u.push(...m.warnings.map(h=>`${l}:${h}`)),d.push({id:l,outcome:f,entries_rehashed:m.history.entries_rehashed,entries_patch_repaired:m.history.entries_patch_repaired,reconciled_with_item:m.history.reconciled_with_item,...m.reconciliation?{reconciliation:m.reconciliation}:{},warnings:m.warnings})}catch(m){a.failed+=1,d.push({id:l,outcome:"failed",error:m instanceof Error?m.message:String(m)})}return e.dryRun||await se(n),{all:!0,dry_run:!!e.dryRun,scanned_streams:i.length,drifted_streams:c.driftedItems.length,streams:d,totals:a,warnings:[...new Set([...s,...u])].sort((l,m)=>l.localeCompare(m)),generated_at:C()}}(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]="c5620467-6c8c-5702-b742-57fba9e302c5")}catch{}})();async function Qt(e,t){let n=e.dryRun===!0,r=await ye(process.cwd(),{includeLossless:!0}),{pendingDecisions:o}=ge(r);if(!n&&e.force!==!0&&o.length>0)throw new _(`Merge reconciliation would accept ${o.length} receipt(s) containing discarded scalar values. Review pm merge report and rerun with --force only after deciding which values to retain or re-apply.`,g.CONFLICT,{code:"merge_reconcile_discards_require_acceptance",required:"Explicitly review every discarded field before accepting reconciliation.",nextSteps:o.map(p=>`Review receipt ${p.id} for ${p.item_id}: ${p.decisions.map(w=>w.field).join(", ")}.`),recovery:{suggested_retry:"pm merge reconcile --dry-run"}});let s=r.reduce((p,w)=>((p[w.item_id]??=[]).push(w),p),{}),i=Object.fromEntries(Object.entries(s).map(([p,w])=>[p,{merge:{receipts:w.map($)}}])),c=await Te({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:i},t),d=new Set(c.streams.map(p=>p.id)),u=Object.keys(s).filter(p=>!d.has(p));(await Promise.allSettled(u.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:i[p],forceAuditEntry:!0},t)))).forEach((p,w)=>{let v=u[w];if(p.status==="fulfilled"){let S=p.value.changed?"repaired":"skipped_clean";c.streams.push({id:v,outcome:S,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}),c.totals[S]+=1}else c.streams.push({id:v,outcome:"failed",error:p.reason instanceof Error?p.reason.message:String(p.reason)}),c.totals.failed+=1});let l=0;!n&&c.totals.failed===0&&(await Promise.all(r.map(p=>_e(process.cwd(),p))),l=r.length);let m=await we({checkHistoryDrift:!0,checkStorageIntegrity:!0},t),f=m.checks.every(p=>p.status==="ok"),h=c.totals.failed===0&&f,y=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."]:h?["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:h,dry_run:n,repair:c,receipts:{pending_before:r.length,reconciled:l,summaries:r.map($)},validation:m,guidance:y,generated_at:m.generated_at}}export{Re as a,ve as b,je as c,Me as d,Ee as e,Oe as f,Ce as g,Et as h,Q as i,Gt as j,Te as k,Qt as l};
5
- //# sourceMappingURL=chunk-JMVA4HKR.js.map
5
+ //# sourceMappingURL=chunk-E3KCL7AY.js.map