@unbrained/pm-cli 2026.12.2 → 2026.12.3

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 (157) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/commander-usage.js +4 -4
  3. package/dist/cli/expected-revisions.js +1 -1
  4. package/dist/cli/extension-command-help.js +4 -4
  5. package/dist/cli/main.js +5 -5
  6. package/dist/cli/runtime/invocation-rewrites.js +1 -1
  7. package/dist/cli/runtime-field-commands.js +2 -0
  8. package/dist/cli-bundle/bundle-manifest.json +1 -1
  9. package/dist/cli-bundle/chunks/chunk-3ESBFEQC.js +2 -0
  10. package/dist/cli-bundle/chunks/chunk-46AZP5QW.js +2 -0
  11. package/dist/cli-bundle/chunks/{chunk-OBPO6V7H.js → chunk-5WTBF4M4.js} +2 -2
  12. package/dist/cli-bundle/chunks/{chunk-3KEMIPKG.js → chunk-6TOZQ5BQ.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-4YYFY33T.js → chunk-AHVOEE7F.js} +2 -2
  14. package/dist/cli-bundle/chunks/chunk-CQHB3ZZH.js +2 -0
  15. package/dist/cli-bundle/chunks/chunk-DZPOS3YT.js +2 -0
  16. package/dist/cli-bundle/chunks/{chunk-ROTEELDL.js → chunk-E5ADC3HT.js} +65 -65
  17. package/dist/cli-bundle/chunks/{chunk-SY5C3U32.js → chunk-E5HO7HWP.js} +2 -2
  18. package/dist/cli-bundle/chunks/{chunk-3HKPVOAN.js → chunk-EDJ3KR2H.js} +2 -2
  19. package/dist/cli-bundle/chunks/{chunk-TKUG2X24.js → chunk-FWQNWPIV.js} +2 -2
  20. package/dist/cli-bundle/chunks/{chunk-7NAO7I75.js → chunk-H4U3LEOD.js} +2 -2
  21. package/dist/cli-bundle/chunks/{chunk-MZZ4ZJ5Z.js → chunk-HNMED75Y.js} +2 -2
  22. package/dist/cli-bundle/chunks/{chunk-SDXCJZKB.js → chunk-HPCMM74Q.js} +22 -22
  23. package/dist/cli-bundle/chunks/{chunk-WSEIEDEK.js → chunk-ITM4AMVM.js} +2 -2
  24. package/dist/cli-bundle/chunks/{chunk-Q6K7HWZ7.js → chunk-IW4A3I4N.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-7V65VACG.js → chunk-JJ73G5UT.js} +2 -2
  26. package/dist/cli-bundle/chunks/chunk-L4HMFRHB.js +2 -0
  27. package/dist/cli-bundle/chunks/{chunk-GOEQXVOI.js → chunk-LTQWPQ7H.js} +2 -2
  28. package/dist/cli-bundle/chunks/{chunk-UNBW2LF3.js → chunk-MRT3ADO4.js} +2 -2
  29. package/dist/cli-bundle/chunks/{chunk-ZL6J6JYT.js → chunk-PBMLIV74.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-G6TARHFK.js → chunk-PJMGWJKU.js} +2 -2
  31. package/dist/cli-bundle/chunks/chunk-Q2HMDV56.js +9 -0
  32. package/dist/cli-bundle/chunks/{chunk-OXC5KBIQ.js → chunk-RRBNCL63.js} +2 -2
  33. package/dist/cli-bundle/chunks/{chunk-CBUC4X7Q.js → chunk-TDOF7BKO.js} +3 -3
  34. package/dist/cli-bundle/chunks/chunk-UXEZXGAD.js +113 -0
  35. package/dist/cli-bundle/chunks/{chunk-PCDTWL6V.js → chunk-W7HA65EO.js} +2 -2
  36. package/dist/cli-bundle/chunks/{chunk-I4SPJQQI.js → chunk-XGNUDSCG.js} +3 -3
  37. package/dist/cli-bundle/chunks/{chunk-AHV3CSQG.js → chunk-XKJ5NWQ7.js} +2 -2
  38. package/dist/cli-bundle/chunks/{field-option-collisions-BBGTV7AD.js → field-option-collisions-DXKTKW6J.js} +2 -2
  39. package/dist/cli-bundle/chunks/item-revision-DXEF4XBU.js +2 -0
  40. package/dist/cli-bundle/chunks/item-transaction-EANA7V4W.js +2 -0
  41. package/dist/cli-bundle/chunks/{linked-resource-value-list-ZBIY4H23.js → linked-resource-value-list-5JRGUDUB.js} +2 -2
  42. package/dist/cli-bundle/chunks/{mutation-actor-NHN33ITJ.js → mutation-actor-S5G7FMNG.js} +2 -2
  43. package/dist/cli-bundle/chunks/{mutation-admission-PGKJTCG6.js → mutation-admission-HQVNPOXV.js} +2 -2
  44. package/dist/cli-bundle/chunks/{register-list-query-7S5QWDTI.js → register-list-query-SQF5PSJ4.js} +2 -2
  45. package/dist/cli-bundle/chunks/{register-mutation-EK6DVIQK.js → register-mutation-4AQ4CEBL.js} +2 -2
  46. package/dist/cli-bundle/chunks/{register-operations-6MURXE4V.js → register-operations-76P7OM4P.js} +2 -2
  47. package/dist/cli-bundle/chunks/{register-setup-RW26X3GJ.js → register-setup-T6OEOZK3.js} +2 -2
  48. package/dist/cli-bundle/chunks/{stage-4ZCF74G4.js → stage-KUICZHSF.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/{chunk-4SCFAWAW.js → chunk-3LHBKFPD.js} +2 -2
  50. package/dist/cli-bundle/focused-chunks/chunk-4DDXERKN.js +2 -0
  51. package/dist/cli-bundle/focused-chunks/{chunk-JPZGC3W4.js → chunk-4YU75CWI.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/{chunk-TXTPAFHJ.js → chunk-5JQVPQMN.js} +2 -2
  53. package/dist/cli-bundle/focused-chunks/{chunk-KNBGHCIP.js → chunk-5Z4DXYBZ.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/chunk-7DOP5HEZ.js +44 -0
  55. package/dist/cli-bundle/focused-chunks/{chunk-TR22GU7M.js → chunk-AX4RBJ7B.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/{chunk-7A6SEZEY.js → chunk-BEHQCHQV.js} +2 -2
  57. package/dist/cli-bundle/focused-chunks/chunk-BUIF6CMZ.js +2 -0
  58. package/dist/cli-bundle/focused-chunks/chunk-E2IWEJL5.js +3 -0
  59. package/dist/cli-bundle/focused-chunks/chunk-GBU7GKNJ.js +2 -0
  60. package/dist/cli-bundle/focused-chunks/{chunk-EQCQTYKO.js → chunk-K35KTBDZ.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/{chunk-VQIC3UZB.js → chunk-KNST4PGF.js} +2 -2
  62. package/dist/cli-bundle/focused-chunks/{chunk-P2H3GTJK.js → chunk-L2XJB5PK.js} +2 -2
  63. package/dist/cli-bundle/focused-chunks/chunk-L6NOGC4N.js +100 -0
  64. package/dist/cli-bundle/focused-chunks/{chunk-VK3IE3TS.js → chunk-LWIIDPAV.js} +2 -2
  65. package/dist/cli-bundle/focused-chunks/{chunk-6IY5CVGJ.js → chunk-M54BMYG4.js} +2 -2
  66. package/dist/cli-bundle/focused-chunks/{chunk-6BKT6XQN.js → chunk-NEK7RX3N.js} +2 -2
  67. package/dist/cli-bundle/focused-chunks/{chunk-BHNBPCHP.js → chunk-OKGWIW6C.js} +2 -2
  68. package/dist/cli-bundle/focused-chunks/{chunk-2DGKVXFT.js → chunk-RFDSSOTZ.js} +2 -2
  69. package/dist/cli-bundle/focused-chunks/chunk-SSX5YBDC.js +2 -0
  70. package/dist/cli-bundle/focused-chunks/{chunk-OG57ESZK.js → chunk-TIEQVIFN.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/{chunk-3COWDIPX.js → chunk-VEUBDQDP.js} +2 -2
  72. package/dist/cli-bundle/focused-chunks/{chunk-2UWKU2BQ.js → chunk-WDHNPNHX.js} +3 -3
  73. package/dist/cli-bundle/focused-chunks/{field-option-collisions-2C6DLUC4.js → field-option-collisions-32X7FP3H.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/item-revision-GUYSVVQD.js +2 -0
  75. package/dist/cli-bundle/focused-chunks/{item-transaction-LQLQLZE7.js → item-transaction-MLKHZPL7.js} +2 -2
  76. package/dist/cli-bundle/focused-chunks/{mutation-actor-DJMZUIZI.js → mutation-actor-RDZJTRW2.js} +2 -2
  77. package/dist/cli-bundle/focused-chunks/{mutation-admission-SDWQVVHN.js → mutation-admission-IQB6XL75.js} +2 -2
  78. package/dist/cli-bundle/focused-chunks/{stage-QBZIK3T5.js → stage-AA7LORZ2.js} +2 -2
  79. package/dist/cli-bundle/main.js +27 -27
  80. package/dist/cli-bundle/sdk-authoring.js +1 -1
  81. package/dist/cli-bundle/sdk-contracts.js +1 -1
  82. package/dist/cli-bundle/sdk-core.js +1 -1
  83. package/dist/cli-bundle/sdk-governance.js +1 -1
  84. package/dist/cli-bundle/sdk-graph.js +1 -1
  85. package/dist/cli-bundle/sdk-merge.js +63 -63
  86. package/dist/cli-bundle/sdk-query.js +1 -1
  87. package/dist/cli-bundle/sdk-runtime.js +1 -1
  88. package/dist/cli-bundle/sdk-testing.js +1 -1
  89. package/dist/cli-bundle/sdk.js +9 -9
  90. package/dist/core/extensions/loader.d.ts +8 -0
  91. package/dist/core/extensions/loader.js +1 -1
  92. package/dist/core/item/actionability.js +1 -1
  93. package/dist/core/output/output.js +16 -16
  94. package/dist/mcp/server.js +1 -1
  95. package/dist/sdk/cli-contracts/enum-contracts.d.ts +25 -1
  96. package/dist/sdk/cli-contracts/enum-contracts.js +1 -1
  97. package/dist/sdk/cli-contracts/flag-contracts.d.ts +1 -1
  98. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  99. package/dist/sdk/cli-contracts/runtime-contracts.js +1 -1
  100. package/dist/sdk/cli-contracts/tool-parameter-tables.js +1 -1
  101. package/dist/sdk/cli-contracts/tool-schema.js +1 -1
  102. package/dist/sdk/context-intent-contracts.js +1 -1
  103. package/dist/sdk/lifecycle/expect-hash-admission.d.ts +27 -8
  104. package/dist/sdk/lifecycle/expect-hash-admission.js +1 -1
  105. package/dist/sdk/lifecycle/item-revision.d.ts +12 -4
  106. package/dist/sdk/lifecycle/item-revision.js +1 -1
  107. package/dist/sdk/output-projection.d.ts +1 -1
  108. package/dist/sdk/output-projection.js +1 -1
  109. package/dist/sdk/public-surface.json +1 -1
  110. package/dist/sdk/read-output/surfaces.js +1 -1
  111. package/dist/sdk/runtime/schema.js +1 -1
  112. package/dist/sdk/runtime-input.d.ts +6 -0
  113. package/dist/sdk/runtime-input.js +1 -1
  114. package/dist/sdk/runtime-primitives.d.ts +1 -1
  115. package/dist/sdk/runtime-primitives.js +1 -1
  116. package/dist/sdk/runtime.js +1 -1
  117. package/docs/COMMANDS.md +23 -5
  118. package/docs/EXTENSIONS.md +1 -1
  119. package/docs/SDK.md +15 -2
  120. package/marketplace.json +1 -1
  121. package/package.json +1 -1
  122. package/packages/pm-beads/package.json +1 -1
  123. package/packages/pm-calendar/package.json +1 -1
  124. package/packages/pm-command-kit/package.json +1 -1
  125. package/packages/pm-digital-twin/package.json +1 -1
  126. package/packages/pm-governance-audit/package.json +1 -1
  127. package/packages/pm-guide-shell/package.json +1 -1
  128. package/packages/pm-kanban/package.json +1 -1
  129. package/packages/pm-lifecycle-hooks/package.json +1 -1
  130. package/packages/pm-linked-test-adapters/package.json +1 -1
  131. package/packages/pm-search-advanced/package.json +1 -1
  132. package/packages/pm-templates/package.json +1 -1
  133. package/packages/pm-todos/package.json +1 -1
  134. package/packages/pm-vcs/package.json +1 -1
  135. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  136. package/plugins/pm-claude/package.json +1 -1
  137. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  138. package/plugins/pm-codex/package.json +1 -1
  139. package/plugins/pm-codex/plugin.json +1 -1
  140. package/runtime-dependencies.json +1 -1
  141. package/dist/cli-bundle/chunks/chunk-A5ZEMOVR.js +0 -2
  142. package/dist/cli-bundle/chunks/chunk-C6WM6ZN4.js +0 -9
  143. package/dist/cli-bundle/chunks/chunk-HZZLSBIJ.js +0 -2
  144. package/dist/cli-bundle/chunks/chunk-L2ZSSMYY.js +0 -2
  145. package/dist/cli-bundle/chunks/chunk-NRQCBUYD.js +0 -113
  146. package/dist/cli-bundle/chunks/chunk-QDV7S2QS.js +0 -2
  147. package/dist/cli-bundle/chunks/chunk-V2S4XAX3.js +0 -2
  148. package/dist/cli-bundle/chunks/item-revision-3LENTXYF.js +0 -2
  149. package/dist/cli-bundle/chunks/item-transaction-56J5OCHA.js +0 -2
  150. package/dist/cli-bundle/focused-chunks/chunk-HTDYNY4L.js +0 -2
  151. package/dist/cli-bundle/focused-chunks/chunk-J72TRWR5.js +0 -44
  152. package/dist/cli-bundle/focused-chunks/chunk-N64AC5G6.js +0 -100
  153. package/dist/cli-bundle/focused-chunks/chunk-QZRYGYTI.js +0 -2
  154. package/dist/cli-bundle/focused-chunks/chunk-SQMOF65W.js +0 -2
  155. package/dist/cli-bundle/focused-chunks/chunk-T3ILWAEV.js +0 -2
  156. package/dist/cli-bundle/focused-chunks/chunk-W4JMV7GF.js +0 -3
  157. package/dist/cli-bundle/focused-chunks/item-revision-723XCQPS.js +0 -2
@@ -1,4 +1,4 @@
1
- import{a as et,b as te}from"./chunk-3AZOATC2.js";import{$b as Xe,Ib as Ke,Nb as I,Ub as Ge,Xb as Ye,bc as N,fb as j,gh as Qe,hf as G,if as Y,kh as Ze,xa as Be,za as Je}from"./chunk-NRQCBUYD.js";import{p as $e,r as q}from"./chunk-GSLOAEY2.js";import{Q as H,a as S,b as x,d as u,x as Ue}from"./chunk-I4SPJQQI.js";import{D as We,P as B,V as J,Z as K,aa as He,r as Ve}from"./chunk-TE6FBDHP.js";import{A as p,C as h,E as Fe,F as ee,H as E,J as De,K as ye,L as U,v as Me,y as c,z as $}from"./chunk-K672XXGQ.js";import tt from"node:fs/promises";import M from"node:path";var C="_workspace";function R(e){return M.join(e,"history",`${C}.jsonl`)}function we(e,t){return{metadata:{id:C,title:"Workspace state",description:"Audited singleton workspace document state.",type:"Chore",status:"open",priority:2,tags:["workspace-history"],created_at:t,updated_at:t,documents:e},body:""}}function z(e,t=e.length){let n=Ge();for(let r of e.slice(0,t))n=Xe(n,r.patch).document;return Ye(n)}function F(e){return"documents"in e.metadata&&typeof e.metadata.documents=="object"&&e.metadata.documents!==null&&!Array.isArray(e.metadata.documents)?e.metadata.documents:{}}function D(e){throw new h(`Workspace history verification failed: ${e.join(", ")}`,p.CONFLICT,{code:"workspace_history_chain_invalid",reason:"workspace_history_chain_verification_failed",verification_errors:[...e],required:"Repair the _workspace history chain before reading, reconciling, restoring, or appending audited singleton state.",why:"Continuing against an unverifiable append-only stream could hide or compound workspace state corruption.",examples:["pm history _workspace --verify --json","pm validate --check-history-drift --fix-hints --json"],nextSteps:["Inspect the exact verification_errors and preserve the corrupt stream as evidence.","Use the history-drift remediation returned by validate before retrying the refused operation."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify --json"}})}function ne(e,t){let n=M.resolve(t),r=M.relative(e,n).replaceAll("\\","/");if(r.length===0||r===".."||r.startsWith("../")||M.isAbsolute(r))throw new TypeError("Workspace history document path must stay inside the tracker root");return{documentPath:r,absolutePath:n}}async function hr(e){let t=await I(R(e),C),n=N(t);n.ok||D(n.errors);let r=F(t.length===0?$:z(t)),o=[],i=[],a=[],s=[];for(let l of Object.keys(r).sort()){let d;try{let _=ne(e,M.resolve(e,l));if(d=await E(_.absolutePath),d===null){a.push(l);continue}let f=JSON.parse(d);(S(f)===S(r[l])?o:i).push(l)}catch{s.push(l)}}return{ok:i.length===0&&a.length===0&&s.length===0,document_count:Object.keys(r).length,matching_documents:o,mismatched_documents:i,missing_documents:a,unreadable_documents:s}}async function nt(e){let t=R(e.pmRoot),n=await I(t,C),r=N(n);r.ok||D(r.errors);let o=e.idempotencyKey===void 0?void 0:n.find(f=>f.op===`${e.op}:${e.idempotencyKey}`);if(o)return{entry:o,historyPath:t};let i=H(),a=n.length===0?$:z(n),s=F(a),l=s[e.documentPath];if(l!==void 0&&S(l)!==S(e.before))throw new h(`Workspace history state for "${e.documentPath}" changed outside the audited mutation path.`,p.CONFLICT,{code:"workspace_history_state_conflict",reason:"out_of_band_workspace_state",required:"Reconcile the singleton document with its matching _workspace history state before retrying the mutation.",why:"Accepting the write would make the append-only audit stream describe a state that was not actually observed.",examples:["pm history _workspace --verify","pm validate --check-history-drift --fix-hints"],nextSteps:["Review the version-control change that altered the singleton and preserve the intended document plus its matching workspace history.","Rerun the original mutation only after the on-disk singleton agrees with the latest audited workspace state."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify"}});let d=we({...s,[e.documentPath]:e.after},n.length===0?i:a.metadata.created_at),_=G({nowIso:i,author:e.author,op:e.idempotencyKey===void 0?e.op:`${e.op}:${e.idempotencyKey}`,before:a,after:d,message:e.message});return await Y(t,_),{entry:_,historyPath:t}}async function yr(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await nt(e)}finally{await t()}}async function wr(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let n=R(e.pmRoot),r=await I(n,C),o=N(r);o.ok||D(o.errors);let i=r.length===0?$:z(r),a=G({nowIso:H(),author:e.author,op:e.op,before:i,after:i,message:e.message,context:e.context});return await Y(n,a),{entry:a,historyPath:n}}finally{await t()}}async function rt(e,t){if(t===e.raw)return!1;let n=t===null?null:JSON.parse(t),r=JSON.parse(e.raw);await U(e.filePath,e.raw);try{(t!==null||e.recordCreation!==!1)&&await nt({pmRoot:e.pmRoot,documentPath:M.relative(e.pmRoot,e.filePath).replaceAll("\\","/"),before:n,after:r,op:e.op,idempotencyKey:e.idempotencyKey,author:e.author,lockTtlSeconds:e.lockTtlSeconds,lockWaitMs:e.lockWaitMs,message:e.message})}catch(o){throw t===null?await tt.rm(e.filePath,{force:!0}):await U(e.filePath,t),o}return!0}async function ot(e){let{documentPath:t}=ne(e.pmRoot,e.filePath),n=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let r=await E(e.filePath);if(e.dryRun===!0||e.idempotencyKey!==void 0){let i=await I(R(e.pmRoot),C),a=N(i);a.ok||D(a.errors);let s=F(i.length===0?$:z(i))[t];if(s!==void 0&&S(s)!==S(r===null?null:JSON.parse(r)))throw new h(`Workspace history state for "${t}" changed outside the audited mutation path.`,p.CONFLICT,{code:"workspace_history_state_conflict"});if(e.idempotencyKey!==void 0&&i.some(l=>l.op===`${e.op}:${e.idempotencyKey}`))return{changed:!1,result:void 0,replayed:!0}}let o=await e.mutate(r);return JSON.parse(o.raw),e.dryRun===!0?{changed:r!==o.raw,result:o.result}:{changed:await rt({...e,raw:o.raw},r),result:o.result}}finally{await n()}}async function kr(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await rt(e,await E(e.filePath))}finally{await t()}}async function gr(e){let t=e.authorizationDecision.trim();if(!t)throw new TypeError("Workspace history reconciliation requires an authorization decision");let n=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let{documentPath:r,absolutePath:o}=ne(e.pmRoot,e.filePath),i=R(e.pmRoot),a=await I(i,C),s=N(a);s.ok||D(s.errors);let l=z(a),d=F(l);if(!Object.hasOwn(d,r))throw new TypeError(`Workspace history does not govern document ${r}`);let _=await E(o);if(_===null)throw new TypeError(`Workspace history document is missing: ${r}`);let f=JSON.parse(_);if(S(d[r])===S(f))return{changed:!1,historyPath:i};let w=H(),W=G({nowIso:w,author:e.author,op:e.op,before:l,after:we({...d,[r]:f},l.metadata.created_at),message:e.message,context:{reason:"out_of_band_workspace_state_reconciliation",document_path:r,authorization_decision:t}});return await Y(i,W),{changed:!0,entry:W,historyPath:i}}finally{await n()}}async function br(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let{documentPath:n,absolutePath:r}=ne(e.pmRoot,e.filePath),o=await I(R(e.pmRoot),C),i=N(o);if(i.ok||D(i.errors),!Number.isInteger(e.targetVersion)||e.targetVersion<1||e.targetVersion>o.length)throw new TypeError(`Invalid workspace history target version: ${String(e.targetVersion)}`);let a=F(z(o,e.targetVersion))[n];if(a===void 0)throw new TypeError(`Workspace history version ${e.targetVersion} does not contain ${n}`);let s=await E(r),l=`${JSON.stringify(a,null,2)}
1
+ import{a as et,b as te}from"./chunk-3AZOATC2.js";import{Aa as Be,Ca as Je,Lb as Ke,Qb as I,Xb as Ge,_b as Ye,cc as Xe,ec as N,ib as j,kf as G,kh as Qe,lf as Y,oh as Ze}from"./chunk-UXEZXGAD.js";import{p as $e,r as q}from"./chunk-GSLOAEY2.js";import{Q as H,a as S,b as x,d as u,x as Ue}from"./chunk-XGNUDSCG.js";import{D as We,P as B,V as J,Z as K,aa as He,r as Ve}from"./chunk-TE6FBDHP.js";import{A as p,C as h,E as Fe,F as ee,H as E,J as De,K as ye,L as U,v as Me,y as c,z as $}from"./chunk-K672XXGQ.js";import tt from"node:fs/promises";import M from"node:path";var C="_workspace";function R(e){return M.join(e,"history",`${C}.jsonl`)}function we(e,t){return{metadata:{id:C,title:"Workspace state",description:"Audited singleton workspace document state.",type:"Chore",status:"open",priority:2,tags:["workspace-history"],created_at:t,updated_at:t,documents:e},body:""}}function z(e,t=e.length){let n=Ge();for(let r of e.slice(0,t))n=Xe(n,r.patch).document;return Ye(n)}function F(e){return"documents"in e.metadata&&typeof e.metadata.documents=="object"&&e.metadata.documents!==null&&!Array.isArray(e.metadata.documents)?e.metadata.documents:{}}function D(e){throw new h(`Workspace history verification failed: ${e.join(", ")}`,p.CONFLICT,{code:"workspace_history_chain_invalid",reason:"workspace_history_chain_verification_failed",verification_errors:[...e],required:"Repair the _workspace history chain before reading, reconciling, restoring, or appending audited singleton state.",why:"Continuing against an unverifiable append-only stream could hide or compound workspace state corruption.",examples:["pm history _workspace --verify --json","pm validate --check-history-drift --fix-hints --json"],nextSteps:["Inspect the exact verification_errors and preserve the corrupt stream as evidence.","Use the history-drift remediation returned by validate before retrying the refused operation."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify --json"}})}function ne(e,t){let n=M.resolve(t),r=M.relative(e,n).replaceAll("\\","/");if(r.length===0||r===".."||r.startsWith("../")||M.isAbsolute(r))throw new TypeError("Workspace history document path must stay inside the tracker root");return{documentPath:r,absolutePath:n}}async function hr(e){let t=await I(R(e),C),n=N(t);n.ok||D(n.errors);let r=F(t.length===0?$:z(t)),o=[],i=[],a=[],s=[];for(let l of Object.keys(r).sort()){let d;try{let _=ne(e,M.resolve(e,l));if(d=await E(_.absolutePath),d===null){a.push(l);continue}let f=JSON.parse(d);(S(f)===S(r[l])?o:i).push(l)}catch{s.push(l)}}return{ok:i.length===0&&a.length===0&&s.length===0,document_count:Object.keys(r).length,matching_documents:o,mismatched_documents:i,missing_documents:a,unreadable_documents:s}}async function nt(e){let t=R(e.pmRoot),n=await I(t,C),r=N(n);r.ok||D(r.errors);let o=e.idempotencyKey===void 0?void 0:n.find(f=>f.op===`${e.op}:${e.idempotencyKey}`);if(o)return{entry:o,historyPath:t};let i=H(),a=n.length===0?$:z(n),s=F(a),l=s[e.documentPath];if(l!==void 0&&S(l)!==S(e.before))throw new h(`Workspace history state for "${e.documentPath}" changed outside the audited mutation path.`,p.CONFLICT,{code:"workspace_history_state_conflict",reason:"out_of_band_workspace_state",required:"Reconcile the singleton document with its matching _workspace history state before retrying the mutation.",why:"Accepting the write would make the append-only audit stream describe a state that was not actually observed.",examples:["pm history _workspace --verify","pm validate --check-history-drift --fix-hints"],nextSteps:["Review the version-control change that altered the singleton and preserve the intended document plus its matching workspace history.","Rerun the original mutation only after the on-disk singleton agrees with the latest audited workspace state."],recovery:{recovery_mode:"compact",next_best_command:"pm history _workspace --verify"}});let d=we({...s,[e.documentPath]:e.after},n.length===0?i:a.metadata.created_at),_=G({nowIso:i,author:e.author,op:e.idempotencyKey===void 0?e.op:`${e.op}:${e.idempotencyKey}`,before:a,after:d,message:e.message});return await Y(t,_),{entry:_,historyPath:t}}async function yr(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await nt(e)}finally{await t()}}async function wr(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let n=R(e.pmRoot),r=await I(n,C),o=N(r);o.ok||D(o.errors);let i=r.length===0?$:z(r),a=G({nowIso:H(),author:e.author,op:e.op,before:i,after:i,message:e.message,context:e.context});return await Y(n,a),{entry:a,historyPath:n}}finally{await t()}}async function rt(e,t){if(t===e.raw)return!1;let n=t===null?null:JSON.parse(t),r=JSON.parse(e.raw);await U(e.filePath,e.raw);try{(t!==null||e.recordCreation!==!1)&&await nt({pmRoot:e.pmRoot,documentPath:M.relative(e.pmRoot,e.filePath).replaceAll("\\","/"),before:n,after:r,op:e.op,idempotencyKey:e.idempotencyKey,author:e.author,lockTtlSeconds:e.lockTtlSeconds,lockWaitMs:e.lockWaitMs,message:e.message})}catch(o){throw t===null?await tt.rm(e.filePath,{force:!0}):await U(e.filePath,t),o}return!0}async function ot(e){let{documentPath:t}=ne(e.pmRoot,e.filePath),n=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let r=await E(e.filePath);if(e.dryRun===!0||e.idempotencyKey!==void 0){let i=await I(R(e.pmRoot),C),a=N(i);a.ok||D(a.errors);let s=F(i.length===0?$:z(i))[t];if(s!==void 0&&S(s)!==S(r===null?null:JSON.parse(r)))throw new h(`Workspace history state for "${t}" changed outside the audited mutation path.`,p.CONFLICT,{code:"workspace_history_state_conflict"});if(e.idempotencyKey!==void 0&&i.some(l=>l.op===`${e.op}:${e.idempotencyKey}`))return{changed:!1,result:void 0,replayed:!0}}let o=await e.mutate(r);return JSON.parse(o.raw),e.dryRun===!0?{changed:r!==o.raw,result:o.result}:{changed:await rt({...e,raw:o.raw},r),result:o.result}}finally{await n()}}async function kr(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{return await rt(e,await E(e.filePath))}finally{await t()}}async function gr(e){let t=e.authorizationDecision.trim();if(!t)throw new TypeError("Workspace history reconciliation requires an authorization decision");let n=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let{documentPath:r,absolutePath:o}=ne(e.pmRoot,e.filePath),i=R(e.pmRoot),a=await I(i,C),s=N(a);s.ok||D(s.errors);let l=z(a),d=F(l);if(!Object.hasOwn(d,r))throw new TypeError(`Workspace history does not govern document ${r}`);let _=await E(o);if(_===null)throw new TypeError(`Workspace history document is missing: ${r}`);let f=JSON.parse(_);if(S(d[r])===S(f))return{changed:!1,historyPath:i};let w=H(),W=G({nowIso:w,author:e.author,op:e.op,before:l,after:we({...d,[r]:f},l.metadata.created_at),message:e.message,context:{reason:"out_of_band_workspace_state_reconciliation",document_path:r,authorization_decision:t}});return await Y(i,W),{changed:!0,entry:W,historyPath:i}}finally{await n()}}async function br(e){let t=await j(e.pmRoot,"workspace-history",e.lockTtlSeconds,e.author,!1,!1,e.lockWaitMs);try{let{documentPath:n,absolutePath:r}=ne(e.pmRoot,e.filePath),o=await I(R(e.pmRoot),C),i=N(o);if(i.ok||D(i.errors),!Number.isInteger(e.targetVersion)||e.targetVersion<1||e.targetVersion>o.length)throw new TypeError(`Invalid workspace history target version: ${String(e.targetVersion)}`);let a=F(z(o,e.targetVersion))[n];if(a===void 0)throw new TypeError(`Workspace history version ${e.targetVersion} does not contain ${n}`);let s=await E(r),l=`${JSON.stringify(a,null,2)}
2
2
  `;if(s===l)return{document_path:n,restored_from_version:e.targetVersion,changed:!1};let d=z(o),_=H(),f=G({nowIso:_,author:e.author,op:e.op,before:d,after:we({...F(d),[n]:a},d.metadata.created_at),message:e.message,context:{reason:"workspace_state_restore",document_path:n,restored_from_version:e.targetVersion,replaced_out_of_band_state:!0}});await U(r,l);try{await Y(R(e.pmRoot),f)}catch(w){throw s===null?await tt.rm(r,{force:!0}):await U(r,s),w}return{document_path:n,restored_from_version:e.targetVersion,changed:!0}}finally{await t()}}import{AsyncLocalStorage as Qt}from"node:async_hooks";import{lstat as Zt,realpath as pt}from"node:fs/promises";import ht from"node:path";function re(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ke(e,t,n,r=[]){if(x(e,t)&&(r.length>0||re(n)))return n;if(x(e,n)||x(t,n))return t;if((e===void 0||re(e))&&re(t)&&re(n)){let o=e??{},i=new Set([...Object.keys(o),...Object.keys(t),...Object.keys(n)]);return Object.fromEntries([...i].flatMap(a=>{let s=ke(Object.hasOwn(o,a)?o[a]:void 0,Object.hasOwn(t,a)?t[a]:void 0,Object.hasOwn(n,a)?n[a]:void 0,[...r,a]);return s===void 0?[]:[[a,s]]}))}throw new h(`Settings changed concurrently at ${r.join(".")||"<root>"}; read the latest settings and reapply the intended change.`,p.CONFLICT,{reason:"stale_settings_snapshot",required:"Read a fresh settings snapshot and reapply the intended change.",why:"Another writer changed the same setting after this snapshot was read.",examples:["pm config project export --json"],nextSteps:["Read the current settings, then retry the original config operation."]})}var Jt={Epic:2880,Feature:480,Story:480,Milestone:2880,Task:120,Issue:60,Bug:60,Chore:30,Decision:15,Plan:120},it=120;function ge(e){return typeof e=="number"&&Number.isFinite(e)&&e>0}function st(e){let t=new Map;for(let[n,r]of Object.entries(e))t.set(n.toLowerCase(),r);return t}var Kt=st(Jt),at=new WeakMap;function Gt(e){let t=at.get(e);if(t)return t;let n=st(e);return at.set(e,n),n}function Or(e,t){let n=(e??"").trim().toLowerCase();if(n.length===0)return it;if(t){let o=Gt(t).get(n);if(ge(o))return Math.floor(o)}let r=Kt.get(n);return ge(r)?Math.floor(r):it}function be(e){let t={};if(e===null||typeof e!="object"||Array.isArray(e))return t;for(let[n,r]of Object.entries(e)){let o=n.trim();o.length===0||!ge(r)||(t[o]=Math.floor(r))}return t}import{stat as Yt}from"node:fs/promises";var oe=new Map;function ct(e){return[...new Set(e.map(t=>t.trim()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}async function Xt(e){try{let t=await Yt(e);return{path:e,mtime_ms:t.mtimeMs,size:t.size}}catch{return{path:e,mtime_ms:null,size:null}}}async function O(e){let t=ct(e),n=await Promise.all(t.map(r=>Xt(r)));return n.sort((r,o)=>r.path.localeCompare(o.path)),n}function X(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],o=t[n];if(r.path!==o.path||r.mtime_ms!==o.mtime_ms||r.size!==o.size)return!1}return!0}function lt(e){return oe.get(e)}function ie(e,t){let n=ct(t.tracked_paths),r=[...t.signatures].map(o=>({path:o.path,mtime_ms:o.mtime_ms,size:o.size})).sort((o,i)=>o.path.localeCompare(i.path));oe.set(e,{tracked_paths:n,signatures:r,value:t.value})}function L(e){if(e){oe.delete(e);return}oe.clear()}var Ee=new Qt;async function Gr(e,t,n=()=>!0){let r=new Set([ht.resolve(e)]);try{r.add(await pt(e))}catch{}let o=!1,i=[r,()=>!o&&n()];try{return await Ee.run([...Ee.getStore()??[],i],t)}finally{o=!0}}function en(e){let t=ht.resolve(e);return Ee.getStore()?.some(([n,r])=>n.has(t)&&r())??!1}var tn="settings:write",yt=Symbol("pm.settings.persist_source"),wt=Symbol("pm.settings.fallback_origin"),kt=Symbol("pm.settings.fallback_baseline"),nn=128,rn=new Set(["off","advisory","strict"]);function dt(e){return structuredClone(Me[e])}function on(e){return e==="minimal"||e==="default"||e==="strict"||e==="custom"?e:c.governance.preset}var an=new Set(Ve);function gt(e){return an.has(e)}function ut(e,t){let n=typeof t.create_default_type=="string"?t.create_default_type.trim():void 0;return n&&n.length>0&&(e.create_default_type=n),(t.workflow_enforcement==="off"||t.workflow_enforcement==="warn"||t.workflow_enforcement==="strict")&&(e.workflow_enforcement=t.workflow_enforcement),gt(t.start_blocker_enforcement)&&(e.start_blocker_enforcement=t.start_blocker_enforcement),t.require_close_reason===!1&&(e.require_close_reason=!1),e.duplicate_detection_mode=t.duplicate_detection_mode,e.duplicate_detection_threshold=t.duplicate_detection_threshold,e.duplicate_detection_limit=t.duplicate_detection_limit,e}function sn(e){return e.preset==="custom"?ut({preset:"custom",ownership_enforcement:e.ownership_enforcement,create_mode_default:e.create_mode_default,close_validation_default:e.close_validation_default,parent_reference:e.parent_reference,metadata_profile:e.metadata_profile,force_required_for_stale_lock:e.force_required_for_stale_lock},e):ut({preset:e.preset},e)}function cn(e){let t=typeof e.create_default_type=="string"?e.create_default_type.trim():void 0,n={};t&&t.length>0&&(n.create_default_type=t),(e.workflow_enforcement==="off"||e.workflow_enforcement==="warn"||e.workflow_enforcement==="strict")&&(n.workflow_enforcement=e.workflow_enforcement),gt(e.start_blocker_enforcement)&&(n.start_blocker_enforcement=e.start_blocker_enforcement),typeof e.require_close_reason=="boolean"&&(n.require_close_reason=e.require_close_reason),rn.has(String(e.duplicate_detection_mode))&&(n.duplicate_detection_mode=e.duplicate_detection_mode);let r=e.duplicate_detection_threshold;[typeof r=="number",Number.isFinite(r),Number(r)>=0,Number(r)<=1].every(Boolean)&&(n.duplicate_detection_threshold=r);let o=e.duplicate_detection_limit;return[typeof o=="number",Number.isSafeInteger(o),Number(o)>=0,Number(o)<=20].every(Boolean)&&(n.duplicate_detection_limit=o),n}function bt(e){let t=e.governance??{},n=on(t.preset),r=cn(t);if(n==="custom"){let a=dt("default"),s=r.require_close_reason??a.require_close_reason;return{preset:n,ownership_enforcement:t.ownership_enforcement??a.ownership_enforcement,create_mode_default:t.create_mode_default??a.create_mode_default,close_validation_default:t.close_validation_default??a.close_validation_default,parent_reference:t.parent_reference??a.parent_reference,metadata_profile:t.metadata_profile??a.metadata_profile,force_required_for_stale_lock:t.force_required_for_stale_lock??a.force_required_for_stale_lock,...r,require_close_reason:s,duplicate_detection_mode:r.duplicate_detection_mode??a.duplicate_detection_mode,duplicate_detection_threshold:r.duplicate_detection_threshold??a.duplicate_detection_threshold,duplicate_detection_limit:r.duplicate_detection_limit??a.duplicate_detection_limit}}let o=dt(n),i=r.require_close_reason??o.require_close_reason;return{preset:n,...o,...r,require_close_reason:i}}function Te(){return structuredClone(c)}function xt(e){return e==="cache_only"||e==="semantic_configured"||e==="semantic_auto"?e:c.search.mutation_refresh_policy}function vt(e){return e==="auto"||e==="keyword"||e==="semantic"||e==="hybrid"?e:"auto"}function St(e){return typeof e=="boolean"?e:c.search.query_expansion.enabled}function Et(e){return typeof e!="string"?c.search.query_expansion.provider:e.trim()}function Ct(e){return typeof e=="boolean"?e:c.search.rerank.enabled}function Ot(e){return typeof e!="string"?c.search.rerank.model:e.trim()}function Tt(e){return typeof e=="number"&&Number.isFinite(e)&&Number.isInteger(e)&&e>0?e:c.search.rerank.top_k}function At(e){if(typeof e!="string")return c.vector_store.collection_name;let n=e.trim().replaceAll(/[^a-zA-Z0-9_-]/g,"_").slice(0,nn);return n.length>0?n:c.vector_store.collection_name}function xe(e){return{present:Array.isArray(e),values:Array.isArray(e)?structuredClone(e):[]}}function Pt(e,t){let n=e.schema,r=xe(n?.statuses),o=xe(n?.fields),i=xe(n?.type_workflows);return{persisted_settings:structuredClone(e),source_settings:structuredClone(e),has_source_item_type_definitions:Array.isArray(e.item_types?.definitions),source_item_type_definitions:V(e.item_types?.definitions),has_source_schema_statuses:r.present,source_schema_statuses:r.values,has_source_schema_fields:o.present,source_schema_fields:o.values,has_source_schema_type_workflows:i.present,source_schema_type_workflows:i.values,runtime_item_type_definitions:V(t.item_types?.definitions),runtime_schema_statuses:structuredClone(t.schema.statuses),runtime_schema_fields:structuredClone(t.schema.fields),runtime_schema_type_workflows:structuredClone(t.schema.type_workflows??[])}}function ce(e,t){Object.defineProperty(e,yt,{value:t,writable:!0,configurable:!0,enumerable:!1})}function Ae(e){let t=e[yt];if(!(!t||typeof t!="object"))return t}function Yr(e){let t=Ae(e);if(t){let n=structuredClone(t);n.source_settings.item_format=e.item_format,ce(e,n)}}function ae(e){let t=structuredClone(e.settings),n=Ae(e.settings);n&&ce(t,n);let r=Pe(e.settings);return r!==void 0&&jt(t,r),{settings:t,metadata:{has_explicit_item_format:e.metadata.has_explicit_item_format},warnings:[...e.warnings]}}function ln(e,t,n){let r=J(t);return[n,K(e,r.files.types,B.types),K(e,r.files.statuses,B.statuses),K(e,r.files.fields,B.fields),K(e,r.files.workflows,B.workflows)]}async function dn(e,t,n){let r=await O(t);ie(e,{tracked_paths:t,signatures:r,value:ae(n)})}async function un(e,t,n){try{await dn(e,t,n)}catch{L(e)}}function _t(e,t){return e.find(n=>n.path===t)}function _n(e,t,n){for(let r of n){let o=_t(e,r),i=_t(t,r);if(!o||!i||!X([o],[i]))return!1}return!0}async function ve(e,t,n,r,o){try{let i=await O(t);if(!_n(r,i,o)){L(e);return}ie(e,{tracked_paths:t,signatures:i,value:ae(n)})}catch{L(e)}}function fn(e,t){let n=J(e.schema),r=V(e.item_types?.definitions);if(!t)return{item_type_definitions:r,schema_statuses:n.statuses,schema_fields:n.fields,schema_type_workflows:n.type_workflows};let o=n.type_workflows??[],i=x(r,t.runtime_item_type_definitions),a=x(n.statuses,t.runtime_schema_statuses),s=x(n.fields,t.runtime_schema_fields),l=x(o,t.runtime_schema_type_workflows);return{item_type_definitions:i?t.has_source_item_type_definitions?V(t.source_item_type_definitions):[]:r,schema_statuses:a?t.has_source_schema_statuses?structuredClone(t.source_schema_statuses):[]:n.statuses,schema_fields:s?t.has_source_schema_fields?structuredClone(t.source_schema_fields):[]:n.fields,schema_type_workflows:l?t.has_source_schema_type_workflows?structuredClone(t.source_schema_type_workflows):void 0:n.type_workflows}}function jt(e,t){Object.defineProperty(e,wt,{value:t,writable:!0,configurable:!0,enumerable:!1})}function Xr(e){return Pe(e)!==void 0}function Pe(e){let t=e[wt];return typeof t=="string"?t:void 0}function mn(e){return e[kt]}function pn(e,t){Object.defineProperty(e,kt,{value:t,writable:!0,configurable:!0,enumerable:!1})}function v(e){let t=Te();return e!==void 0&&jt(t,e),{settings:t,metadata:{has_explicit_item_format:!1},warnings:e?[e]:[]}}function It(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=e.item_format;return t==="toon"||t==="json_markdown"}function Ce(e){return[...new Set((e??[]).map(t=>t.trim()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}function Nt(e){let t=c.agent_guidance,n=e?.template_version;return{prompt_completed:e?.prompt_completed===!0,declined:e?.declined===!0,declined_at:typeof e?.declined_at=="string"?e.declined_at:t.declined_at,template_version:typeof n=="number"&&Number.isInteger(n)&&n>0?n:t.template_version,last_checked_files:Ce(e?.last_checked_files??t.last_checked_files)}}function b(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}function hn(e){return e==="off"||e==="warn"||e==="enforce"?e:c.extensions.policy.mode}function yn(e){return e==="off"||e==="warn"||e==="enforce"?e:c.extensions.policy.trust_mode}function Rt(e){return e==="none"||e==="restricted"||e==="strict"?e:c.extensions.policy.default_sandbox_profile}function wn(e){let t=e.name.trim().toLowerCase();if(t.length===0)return null;let n={name:t};e.disabled===!0&&(n.disabled=!0),e.require_trusted===!0&&(n.require_trusted=!0),e.require_provenance===!0&&(n.require_provenance=!0),e.sandbox_profile!==void 0&&(n.sandbox_profile=Rt(e.sandbox_profile));let r=b(e.allowed_capabilities),o=b(e.blocked_capabilities),i=b(e.allowed_surfaces),a=b(e.blocked_surfaces),s=b(e.allowed_commands),l=b(e.blocked_commands),d=b(e.allowed_actions),_=b(e.blocked_actions),f=b(e.allowed_services),w=b(e.blocked_services);return r.length>0&&(n.allowed_capabilities=r),o.length>0&&(n.blocked_capabilities=o),i.length>0&&(n.allowed_surfaces=i),a.length>0&&(n.blocked_surfaces=a),s.length>0&&(n.allowed_commands=s),l.length>0&&(n.blocked_commands=l),d.length>0&&(n.allowed_actions=d),_.length>0&&(n.blocked_actions=_),f.length>0&&(n.allowed_services=f),w.length>0&&(n.blocked_services=w),n}function kn(e){let t=new Map;for(let n of e??[]){let r=wn(n);r&&t.set(r.name,r)}return[...t.values()].sort((n,r)=>n.name.localeCompare(r.name))}function Se(e){return e==="block"||e==="warn"?e:void 0}function gn(e){if(typeof e=="string")return Se(e);if(typeof e=="object"&&e!==null&&!Array.isArray(e)){let t=Se(e.global),n=Se(e.project);return t===void 0&&n===void 0?void 0:{...t!==void 0?{global:t}:{},...n!==void 0?{project:n}:{}}}}function k(e,t){return b(e?.[t]??c.extensions.policy[t])}function zt(e){let t=gn(e?.pm_max_version_exceeded_mode);return{mode:hn(e?.mode),trust_mode:yn(e?.trust_mode),...t!==void 0?{pm_max_version_exceeded_mode:t}:{},require_provenance:e?.require_provenance===!0,trusted_extensions:k(e,"trusted_extensions"),default_sandbox_profile:Rt(e?.default_sandbox_profile),allowed_extensions:k(e,"allowed_extensions"),blocked_extensions:k(e,"blocked_extensions"),allowed_capabilities:k(e,"allowed_capabilities"),blocked_capabilities:k(e,"blocked_capabilities"),allowed_surfaces:k(e,"allowed_surfaces"),blocked_surfaces:k(e,"blocked_surfaces"),allowed_commands:k(e,"allowed_commands"),blocked_commands:k(e,"blocked_commands"),allowed_actions:k(e,"allowed_actions"),blocked_actions:k(e,"blocked_actions"),allowed_services:k(e,"allowed_services"),blocked_services:k(e,"blocked_services"),extension_overrides:kn(e?.extension_overrides??c.extensions.policy.extension_overrides)}}function Lt(e){return[...new Set((e??[]).map(n=>n.trim().toLowerCase().replaceAll("-","_")))].filter(n=>n.length>0).sort((n,r)=>n.localeCompare(r)).filter(n=>["author","acceptance_criteria","estimated_minutes","close_reason","reviewer","risk","confidence","sprint","release"].includes(n))}function T(e){return[...new Set((e??[]).map(t=>t.trim().toLowerCase()).filter(t=>t.length>0))].sort((t,n)=>t.localeCompare(n))}function m(e,t){return e===void 0?t:e}function g(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function Oe(e){return Array.isArray(e)?e:[]}function bn(e,t,n){return{...t.validation,...e.validation,parent_reference:n.parent_reference,metadata_profile:n.metadata_profile,metadata_required_fields:Lt(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:T(e.validation?.lifecycle_stale_blocker_reason_patterns??t.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:T(e.validation?.lifecycle_closure_like_blocked_reason_patterns??t.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:T(e.validation?.lifecycle_closure_like_resolution_patterns??t.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:T(e.validation?.lifecycle_closure_like_actual_result_patterns??t.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:be(e.validation?.estimate_defaults_by_type)}}function xn(e,t){return{enabled:e.telemetry?.enabled??t.telemetry.enabled,first_run_prompt_completed:e.telemetry?.first_run_prompt_completed??t.telemetry.first_run_prompt_completed,capture_level:e.telemetry?.capture_level??t.telemetry.capture_level,endpoint:e.telemetry?.endpoint??t.telemetry.endpoint,installation_id:e.telemetry?.installation_id??t.telemetry.installation_id,retention_days:e.telemetry?.retention_days??t.telemetry.retention_days}}function vn(e,t){return{...t.search,...e.search,default_mode:vt(e.search?.default_mode),mutation_refresh_policy:xt(e.search?.mutation_refresh_policy),query_expansion:{...t.search.query_expansion,...e.search?.query_expansion,enabled:St(e.search?.query_expansion?.enabled),provider:Et(e.search?.query_expansion?.provider)},rerank:{...t.search.rerank,...e.search?.rerank,enabled:Ct(e.search?.rerank?.enabled),model:Ot(e.search?.rerank?.model),top_k:Tt(e.search?.rerank?.top_k)}}}function Sn(e,t){return{adapter:e.vector_store.adapter??t.vector_store.adapter,collection_name:At(e.vector_store.collection_name),qdrant:{...t.vector_store.qdrant,...e.vector_store.qdrant},lancedb:{...t.vector_store.lancedb,...e.vector_store.lancedb}}}function En(e,t){return e.item_format==="json_markdown"?"toon":e.item_format??t.item_format}function Cn(e,t){return{default_depth:e.context?.default_depth??t.context.default_depth,activity_limit:e.context?.activity_limit??t.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??t.context.stale_threshold_days,next_ranking_policy:e.context?.next_ranking_policy??t.context.next_ranking_policy,sections:{...t.context.sections,...e.context?.sections}}}function On(e,t){return{openai:{...t.providers.openai,...e.providers.openai},ollama:{...t.providers.ollama,...e.providers.ollama}}}async function Tn(e,t){let n=await He(e,t.schema);return{settings:{...t,item_types:{definitions:V([...t.item_types.definitions,...Oe(n.type_definitions_from_file)])},schema:n.schema},warnings:n.warnings}}function V(e){let t=(e??[]).map(r=>We(r)).filter(r=>r!==null),n=new Map;for(let r of t)n.set(r.name.toLowerCase(),r);return[...n.values()].sort((r,o)=>r.name.localeCompare(o.name))}function se(e){let t=Te(),n=bt({governance:e.governance??{preset:"default"}});return{...t,...e,item_format:En(e,t),locks:{...t.locks,...e.locks},ids:{...t.ids,...e.ids},agent_identity:structuredClone(e.agent_identity??t.agent_identity),mutation_guard:{...t.mutation_guard,...e.mutation_guard},checkpoints:{...t.checkpoints,...e.checkpoints},output:{...t.output,...e.output},ux:{...t.ux,...e.ux},history:{...t.history,...e.history,compact_policy:{...t.history.compact_policy,...e.history?.compact_policy}},validation:bn(e,t,n),governance:n,workflow:{definition_of_done:[...e.workflow?.definition_of_done??t.workflow.definition_of_done]},testing:{record_results_to_items:e.testing?.record_results_to_items??t.testing.record_results_to_items,allow_untrusted_linked_tests:e.testing?.allow_untrusted_linked_tests??t.testing.allow_untrusted_linked_tests},telemetry:xn(e,t),agent_guidance:Nt(e.agent_guidance??t.agent_guidance),item_types:{definitions:V(e.item_types?.definitions)},schema:J(e.schema??t.schema),context:Cn(e,t),extensions:{enabled:[...e.extensions.enabled],disabled:[...e.extensions.disabled],policy:zt(e.extensions.policy??t.extensions.policy)},search:vn(e,t),providers:On(e,t),vector_store:Sn(e,t)}}function An(e){e.agent_identity=u(e.agent_identity,["probes_enabled","identity_vocabulary","harness_signals"]);let t=e.agent_identity;Object.hasOwn(t,"identity_vocabulary")&&(t.identity_vocabulary=u(g(t.identity_vocabulary),["version","aliases"])),e.agent_identity.harness_signals=Oe(e.agent_identity.harness_signals).map(n=>u(g(n),["harness","environment_keys","model_environment_keys","session_environment_keys","provenance_environment_keys","provenance_resolvers","provenance_unavailable_dimensions","argv_markers","client_names"])),e.locks=u(e.locks,["ttl_seconds","wait_ms"]),e.ids=u(e.ids,["token_length"]),e.mutation_guard=u(e.mutation_guard,["require_attributed_author","secret_guard","stale_in_progress_hours"]),e.checkpoints=u(e.checkpoints,["retention_days"]),e.output=u(e.output,["default_format"]),e.ux=u(e.ux,["deprecation_hints"]),e.history=u(e.history,["missing_stream","compact_policy"]),e.validation=u(e.validation,["sprint_release_format","parent_reference","metadata_profile","metadata_required_fields","lifecycle_stale_blocker_reason_patterns","lifecycle_closure_like_blocked_reason_patterns","lifecycle_closure_like_resolution_patterns","lifecycle_closure_like_actual_result_patterns","estimate_defaults_by_type"]),e.governance=u(e.governance,["preset","ownership_enforcement","create_mode_default","close_validation_default","require_close_reason","parent_reference","metadata_profile","force_required_for_stale_lock","create_default_type","workflow_enforcement","duplicate_detection_mode","duplicate_detection_threshold","duplicate_detection_limit"]),e.workflow=u(e.workflow,["definition_of_done"]),e.testing=u(e.testing,["record_results_to_items","allow_untrusted_linked_tests"]),e.telemetry=u(e.telemetry,["enabled","first_run_prompt_completed","capture_level","endpoint","installation_id","retention_days"]),e.agent_guidance=u(e.agent_guidance,["prompt_completed","declined","declined_at","template_version","last_checked_files"]),e.item_types=u(e.item_types,["definitions"]),e.schema=u(e.schema,["version","files","statuses","fields","workflow","type_workflows","unknown_field_policy"]),e.schema.files=u(g(e.schema.files),["types","statuses","fields","workflows"]),e.schema.workflow=u(g(e.schema.workflow),["draft_status","open_status","in_progress_status","blocked_status","close_status","canceled_status"]),e.context=u(e.context,["default_depth","activity_limit","stale_threshold_days","next_ranking_policy","sections"]),e.context.sections=u(g(e.context.sections),["hierarchy","activity","progress","blockers","files","workload","staleness","tests"]),e.extensions=u(e.extensions,["enabled","disabled","policy"]),e.extensions.policy=u(g(e.extensions.policy),["mode","trust_mode","pm_max_version_exceeded_mode","require_provenance","trusted_extensions","default_sandbox_profile","allowed_extensions","blocked_extensions","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services","extension_overrides"]),e.extensions.policy.extension_overrides=Oe(e.extensions.policy.extension_overrides).map(n=>u(g(n),["name","disabled","require_trusted","require_provenance","sandbox_profile","allowed_capabilities","blocked_capabilities","allowed_surfaces","blocked_surfaces","allowed_commands","blocked_commands","allowed_actions","blocked_actions","allowed_services","blocked_services"])),e.search=u(e.search,["score_threshold","hybrid_semantic_weight","max_results","embedding_model","embedding_corpus_max_characters","embedding_batch_size","embedding_timeout_ms","scanner_max_batch_retries","provider","default_mode","mutation_refresh_policy","query_expansion","rerank"]),e.search.query_expansion=u(g(e.search.query_expansion),["enabled","provider"]),e.search.rerank=u(g(e.search.rerank),["enabled","model","top_k"]),e.providers=u(e.providers,["openai","ollama"]),e.providers.openai=u(g(e.providers.openai),["base_url","api_key","model"]),e.providers.ollama=u(g(e.providers.ollama),["base_url","model"]),e.vector_store=u(e.vector_store,["adapter","collection_name","qdrant","lancedb"]),e.vector_store.qdrant=u(g(e.vector_store.qdrant),["url","api_key"]),e.vector_store.lancedb=u(g(e.vector_store.lancedb),["path"])}function Pn(e){return{...e,locks:m(e.locks,c.locks),ids:m(e.ids,c.ids),agent_identity:m(e.agent_identity,c.agent_identity),mutation_guard:m(e.mutation_guard,c.mutation_guard),checkpoints:m(e.checkpoints,c.checkpoints),output:m(e.output,c.output),ux:m(e.ux,c.ux),history:m(e.history,c.history),validation:m(e.validation,c.validation),workflow:m(e.workflow,c.workflow),testing:m(e.testing,c.testing),telemetry:m(e.telemetry,c.telemetry),agent_guidance:m(e.agent_guidance,c.agent_guidance),item_types:m(e.item_types,c.item_types),schema:m(e.schema,c.schema),context:m(e.context,c.context),extensions:m(e.extensions,c.extensions),search:m(e.search,c.search),providers:m(e.providers,c.providers),vector_store:m(e.vector_store,c.vector_store)}}function jn(e,t){return{...e.validation,parent_reference:t.parent_reference,metadata_profile:t.metadata_profile,metadata_required_fields:Lt(e.validation?.metadata_required_fields),lifecycle_stale_blocker_reason_patterns:T(e.validation?.lifecycle_stale_blocker_reason_patterns??c.validation.lifecycle_stale_blocker_reason_patterns),lifecycle_closure_like_blocked_reason_patterns:T(e.validation?.lifecycle_closure_like_blocked_reason_patterns??c.validation.lifecycle_closure_like_blocked_reason_patterns),lifecycle_closure_like_resolution_patterns:T(e.validation?.lifecycle_closure_like_resolution_patterns??c.validation.lifecycle_closure_like_resolution_patterns),lifecycle_closure_like_actual_result_patterns:T(e.validation?.lifecycle_closure_like_actual_result_patterns??c.validation.lifecycle_closure_like_actual_result_patterns),estimate_defaults_by_type:be(e.validation?.estimate_defaults_by_type)}}function In(e){return{...c.search,...e.search,default_mode:vt(e.search?.default_mode),mutation_refresh_policy:xt(e.search?.mutation_refresh_policy),query_expansion:{...c.search.query_expansion,...e.search?.query_expansion,enabled:St(e.search?.query_expansion?.enabled),provider:Et(e.search?.query_expansion?.provider)},rerank:{...c.search.rerank,...e.search?.rerank,enabled:Ct(e.search?.rerank?.enabled),model:Ot(e.search?.rerank?.model),top_k:Tt(e.search?.rerank?.top_k)}}}function Nn(e){return{default_depth:e.context?.default_depth??c.context.default_depth,activity_limit:e.context?.activity_limit??c.context.activity_limit,stale_threshold_days:e.context?.stale_threshold_days??c.context.stale_threshold_days,next_ranking_policy:e.context?.next_ranking_policy??c.context.next_ranking_policy,sections:{...c.context.sections,...e.context?.sections}}}function Rn(e){return{...e.vector_store,adapter:e.vector_store?.adapter??c.vector_store.adapter,collection_name:At(e.vector_store?.collection_name),qdrant:{...e.vector_store?.qdrant},lancedb:{...e.vector_store?.lancedb}}}function zn(e,t,n,r){return{...e,item_format:"toon",validation:jn(e,t),governance:t,agent_guidance:Nt(e.agent_guidance),item_types:{definitions:r.item_type_definitions},schema:{...n,statuses:r.schema_statuses,fields:r.schema_fields,type_workflows:r.schema_type_workflows},search:In(e),context:Nn(e),extensions:{enabled:Ce(e.extensions?.enabled),disabled:Ce(e.extensions?.disabled),policy:zt(e.extensions?.policy)},vector_store:Rn(e)}}function qt(e,t){for(let n of Object.keys(t)){let r=Reflect.get(t,n),o=e[n];typeof r=="object"&&r!==null&&!Array.isArray(r)&&typeof o=="object"&&o!==null&&!Array.isArray(o)?qt(o,r):e[n]=structuredClone(r)}}function je(e,t,n){let r=new Set([...Object.keys(t),...Object.keys(n)]);for(let o of r){let i=t[o],a=n[o];if(!x(i,a)){if(a===void 0){delete e[o];continue}if(typeof i=="object"&&i!==null&&!Array.isArray(i)&&typeof a=="object"&&a!==null&&!Array.isArray(a)){let s=e[o],l=typeof s=="object"&&s!==null&&!Array.isArray(s)?s:{};je(l,i,a),Object.keys(l).length>0?e[o]=l:delete e[o];continue}e[o]=structuredClone(a)}}}var le=["version","id_prefix","ids","author_default","agent_identity","mutation_guard","item_format","locks","checkpoints","output","ux","history","validation","governance","workflow","testing","telemetry","agent_guidance","item_types","schema","context","extensions","search","providers","vector_store"];function ft(e,t){let n=Pn(e),r=bt(n),o=J(n.schema),i=fn(n,t),a=zn(n,r,o,i),s=u({...a,governance:sn(r)},le);return An(s),s}function Mt(e,t={}){let n=t.source===void 0?t.persist_source:Pt(t.source.validated,se(t.source.validated)),r=ft(e,n);if(n){let o=se(n.source_settings);o.item_types={definitions:structuredClone(n.runtime_item_type_definitions)},o.schema={...o.schema,statuses:structuredClone(n.runtime_schema_statuses),fields:structuredClone(n.runtime_schema_fields),type_workflows:structuredClone(n.runtime_schema_type_workflows)};let i=ft(o,n);t.source!==void 0&&qt(i,t.source.validated);let a=structuredClone(t.source===void 0?n.source_settings:t.source.raw);return je(a,i,r),`${JSON.stringify(u(a,le),null,2)}
3
3
  `}return`${JSON.stringify(r,null,2)}
4
4
  `}async function Ln(e){let t;try{t=await pt(e)}catch(s){if(ee(s))return v();throw s}let n=q(t),r;try{r=await Zt(n)}catch(s){if(ee(s))return v();throw s}if(!r.isFile())throw ye("settings.json");let o;try{o=await De(n,ye("settings.json"))}catch(s){if(ee(s))return v();throw s}let i;try{i=JSON.parse(o)}catch{return v("settings_read_invalid_json")}let a=te(i);return a.success?{settings:se(a.data),metadata:{has_explicit_item_format:It(i)},warnings:a.data.item_format==="json_markdown"?["settings_item_format_legacy_json_markdown_coerced_to_toon"]:[]}:v("settings_read_invalid_schema")}async function Ft(e){if(en(e))return Ln(e);let t=q(e),n=[t];await Ze({path:t,scope:"project"});let r=lt(e);if(r){let d=await O(r.tracked_paths);if(X(d,r.signatures))return ae(r.value)}let o=await O([t]),i;try{i=await E(t)}catch{return v("settings_read_fs_error")}if(i===null){let d=v();return await ve(e,[t],d,o,[t]),d}let a=await O([t]);if(!X(o,a))return L(e),Ft(e);let s;try{s=JSON.parse(i)}catch{let d=v("settings_read_invalid_json");return await ve(e,[t],d,a,[t]),d}let l=te(s);if(!l.success){let d=v("settings_read_invalid_schema");return await ve(e,[t],d,a,[t]),d}try{let d=se(l.data),_=ln(e,d.schema,t);n=_;let f=await O(_),w=await Tn(e,d),W=await O(_),he=w.settings;ce(he,Pt(l.data,he));let qe={settings:he,metadata:{has_explicit_item_format:It(s)},warnings:[...l.data.item_format==="json_markdown"?["settings_item_format_legacy_json_markdown_coerced_to_toon"]:[],...w.warnings]};return X(f,W)?ie(e,{tracked_paths:_,signatures:W,value:ae(qe)}):L(e),qe}catch{let d=v("settings_read_merge_failed");return await un(e,n,d),d}}function qn(e,t=[],n=null){let r=Ie(n)??{},o=t.filter(a=>!Object.hasOwn(r,a));if(o.length===0)return e;let i=JSON.parse(e);for(let a of o)Reflect.deleteProperty(i,a);return`${JSON.stringify(i,null,2)}
@@ -6,4 +6,4 @@ import{a as et,b as te}from"./chunk-3AZOATC2.js";import{$b as Xe,Ib as Ke,Nb as
6
6
  `}function Un(e){try{return JSON.parse(e)}catch{throw new h("Existing settings.json is malformed; the settings write was refused.",p.USAGE,{code:"settings_write_invalid_existing_json",reason:"existing_settings_json_malformed",why:"Writing defaults over malformed settings could destroy intended project configuration.",nextSteps:["Repair the syntax in .agents/pm/settings.json, then retry the original command.","Run pm health to confirm the settings warning has cleared."]})}}async function Qr(e){return(await Ft(e)).settings}async function Zr(e,t,n=tn,r={}){let o=r.assignedPaths??[];Dn(o);let i=q(e),a=Ae(t),s=a?void 0:Pe(t),l=Mt(t,{persist_source:a}),d=JSON.parse(l),_=!1;try{if(await ot({pmRoot:e,filePath:i,mutate:f=>{let w=f===null?null:Un(f);return f!==null&&r.skipIfStored?.(w)===!0?(_=!0,{raw:f,result:void 0}):s!==void 0&&f!==null?{raw:$n(w,d,s,o,mn(t)),result:void 0}:{raw:a?`${JSON.stringify(u(ke(a.persisted_settings,d,w),le),null,2)}
7
7
  `:qn(l,r.omitSections,w),result:void 0}},op:n,author:Ke(void 0,t.author_default),lockTtlSeconds:t.locks.ttl_seconds,lockWaitMs:t.locks.wait_ms,recordCreation:!1}),_)return;a?ce(t,{...a,persisted_settings:structuredClone(d)}):s!==void 0&&pn(t,structuredClone(d)),await Qe({path:i,scope:"project",op:n})}finally{L(e)}}import Vt from"node:fs";import Q from"node:path";import{createRequire as Hn}from"node:module";var Z="@unbrained/pm-cli",Bn=new Set(["append","claim","changelog","close","close-many","close-task","comments","config","copy","create","dedupe-merge","delete","deps","docs","extension","event","events","files","focus","gc","history-author-acknowledge","history-compact","history-redact","history-repair","init","install","item","learnings","meet","merge","normalize","notes","package","packages","pause-task","plan","profile","reindex","release","remind","restore","schema","start-task","test","test-all","test-runs","test-runs-worker","telemetry","templates","twin","update","update-many","upgrade","vcs","workspace"]),Wt=new Set(["--author","--expect-hash","--output-budget","--output-format","--output-include","--output-limit","--output-session","--path","--pm-path"]),Re=/\b(\d{4})\.(\d{1,2})\.(\d{1,2})(?:-(\d+))?\b/u,fe="2026.8.31";function y(e,t){return e.some(n=>t.includes(n.split("=",1)[0]))}function Ne(e,t){return["activate","adopt","adopt-all","deactivate","init","install","migrate","reload","uninstall"].includes(t[0]??"")||y(e,["--activate","--adopt","--adopt-all","--deactivate","--fix-managed-state","--init","--install","--output","--reload","--scaffold","--uninstall"])}var Jn={changelog:(e,t)=>{if(t[0]==="generate")return!y(e,["--check"]);let n=e.indexOf("export");return t[0]==="export"&&(y(e,["--output"])||n>=0&&e[n+1]!==void 0&&!e[n+1].startsWith("-"))},comments:e=>y(e,["--add","--delete","--edit","--file","--stdin"]),config:(e,t)=>(t[0]==="project"||t[0]==="global"?t[1]:t[0])==="set",deps:()=>!1,docs:e=>y(e,["--add","--add-glob","--migrate","--remove"]),duplicates:()=>!1,events:()=>!1,extension:Ne,files:(e,t)=>y(e,["--add","--add-glob","--migrate","--remove"])||t[0]==="discover"&&y(e,["--apply"]),health:e=>!y(e,["--check-only","--no-refresh","--skip-vectors"]),learnings:e=>y(e,["--add","--delete","--edit","--file","--stdin"]),merge:(e,t)=>t[0]!=="report",notes:e=>y(e,["--add","--delete","--edit","--file","--stdin"]),package:Ne,packages:Ne,profile:(e,t)=>t[0]==="apply",schema:(e,t)=>["add-field","add-status","add-type","remove-field","remove-status","remove-type","remap-status","rename-field","rename-type"].includes(t[0]??"")&&!(y(e,["--infer"])&&!y(e,["--apply"])),telemetry:(e,t)=>t.slice(0,2).some(n=>["clear","flush"].includes(n)),templates:(e,t)=>t[0]==="save",test:e=>y(e,["--update","--update-index","--add","--add-json","--background","--measure","--remove","--resume","--run","--stop"]),validate:e=>y(e,["--auto-fix","--prune-missing"]),vcs:(e,t)=>["abandon","create","merge","propose","ref-create"].includes(t[0]??""),workspace:(e,t)=>t[0]==="snapshot"&&["create","delete","restore"].includes(t[1]??"")};function ue(e){let t=e.match(Re);return t?[Number(t[1]),Number(t[2]),Number(t[3]),Number(t[4]??0)]:null}function A(e,t){let n=ue(e),r=ue(t);if(!n||!r)return null;for(let o=0;o<n.length;o+=1){let i=n[o]-r[o];if(i!==0)return Math.sign(i)}return 0}function de(e){return A(e,fe)!==-1?3:2}function Kn(e,t){if(t===3)return e.filter(n=>n.history_epoch_compatible===!1).map(n=>({...n,declaration:n.declaration??n.version})).sort((n,r)=>A(n.version,r.version))[0]}function _e(e){try{let t=JSON.parse(Vt.readFileSync(e,"utf8"));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:null}catch{return null}}function Gn(e){let t=[...e.matchAll(/(<=|<)\s*v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/gu)].map(r=>({inclusive:r[1]==="<=",version:r[2]})),n=e.match(/\b\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?\s+-\s+v?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/u);return n?[...t,{inclusive:!0,version:n[1]}]:t}function Yn(e){let t=e.split("||").map(n=>Gn(n));return{bounded:t.some(n=>n.length>0),compatible:t.some(n=>n.every(r=>{let o=A(fe,r.version);return o!==null&&(r.inclusive?o!==1:o===-1)}))}}function $t(e){return["dependencies","devDependencies","optionalDependencies","peerDependencies"].flatMap(t=>{let n=e[t];if(typeof n!="object"||n===null)return[];let r=n[Z];return typeof r=="string"?[r.trim()]:[]})}function Xn(e){return $t(e).flatMap(t=>{let n=/^[<!]/u.test(t)?void 0:t.match(Re)?.[0];if(!n)return[];let r=/^(?:=|v)?\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?$/u.test(t),o=Yn(t);return[{version:n,constraint:r?"exact":o.bounded?"range":"minimum",...r?{}:{declaration:t},history_epoch_compatible:r?A(n,fe)!==-1:o.compatible}]})}function Qn(e){let n=_e(Q.join(e,"package-lock.json"))?.packages;if(typeof n!="object"||n===null)return;let r=n["node_modules/@unbrained/pm-cli"];if(typeof r!="object"||r===null)return;let o=r.version;return typeof o=="string"?o:void 0}function Zn(e,t){try{let n=Vt.readFileSync(Q.join(e,t),"utf8").split(/\r?\n/u),r=n.findIndex(l=>l.includes(Z));if(r<0)return;let o=n[r].match(/^\s*/u)[0].length,i=[n[r]];for(let l=r+1;l<n.length;l+=1){let d=n[l],_=d.trim(),f=d.match(/^\s*/u)[0].length;if(_.length>0&&f<=o)break;i.push(d)}return i.join(`
8
8
  `).match(/^\s*version(?::\s*|\s+)["']?(\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?)/mu)?.[1]??i[0].match(Re)?.[0]}catch{return}}function Ut(e){let t=[],n=_e(Q.join(e,"package.json"));n&&t.push(...Xn(n).map(a=>({...a,source:"package.json"})));let o=_e(Q.join(e,"node_modules","@unbrained","pm-cli","package.json"))?.version;typeof o=="string"&&ue(o)&&t.push({version:o,source:"installed-package",constraint:"exact",history_epoch_compatible:de(o)===3});let i=Qn(e);i&&ue(i)&&t.push({version:i,source:"package-lock.json",constraint:"exact",history_epoch_compatible:de(i)===3});for(let a of["pnpm-lock.yaml","yarn.lock"]){let s=Zn(e,a);s&&t.push({version:s,source:a,constraint:"exact",history_epoch_compatible:de(s)===3})}return t}function er(e,t){if(t<=1)return;let{minVersion:n,lt:r}=Hn(import.meta.url)("semver"),o=$t(_e(Q.join(e,"package.json"))??{}).find(a=>{try{let s=n(a);return s!==null&&r(s,"2026.10.10")}catch{return!1}}),i=o===void 0?Ut(e).find(a=>A(a.version,"2026.10.10")===-1):{version:o,source:"package.json"};if(i)throw new h(`The project selects pm ${i.version}, which cannot safely refuse item format ${t}.`,p.CONFLICT,{code:"project_runtime_item_format_incompatible",reason:i.source,required:"Upgrade project pins, installed SDKs, CI hosts and Git merge drivers before writing guarded item formats.",nextSteps:["Use a pm runtime supporting the required item format throughout the project; preserve original item and history bytes, and never re-anchor history to satisfy an older host."]})}function co(e,t){let n=Je(e);n<=1||(er($e(t),n),e.pm_format_version=n)}function Ht(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(Wt.has(n)){t+=1;continue}if(!n.startsWith("-"))return{command:n.toLowerCase(),index:t}}}function tr(e){let t=Ht(e);if(!t||y(e,["--help","-h","--dry-run"]))return!1;let{command:n,index:r}=t,o=[];for(let a=r+1;a<e.length;a+=1){let s=e[a];if(Wt.has(s)){a+=1;continue}s.startsWith("-")||o.push(s.toLowerCase())}let i=Jn[n];return i?i(e,o):Bn.has(n)}function nr(e){let t=Ht(e.argv)?.command,n=tr(e.argv),r=Ut(e.projectRoot).filter(_=>A(_.version,e.executingVersion)!==null).sort((_,f)=>A(f.version,_.version)),o=r[0],i=o!==void 0&&A(e.executingVersion,o.version)===-1,a=de(e.executingVersion),s=Kn(r,a),l=n&&s!==void 0,d=i&&!n?{code:"project_runtime_stale_read",executing_version:e.executingVersion,project_version:o.version,source:o.source,message:"This read is using an older pm runtime than the project requires.",next_steps:[`Run the command through the project's installed ${Z} ${o.version}.`,"Install the project dependencies with its declared package manager if the local executable is missing."]}:void 0;return{compatible:!n||!i&&!l||e.allowStale===!0,executing_version:e.executingVersion,...o?{project_version:o.version,source:o.source}:{},...t?{command:t}:{},mutating:n,stale:i,history_epoch_incompatible:l,writer_item_hash_version:a,...s?{incompatible_project_version:s.declaration,incompatible_source:s.source}:{},...d?{warning:d}:{},override_applied:n&&(i||l)&&e.allowStale===!0}}function lo(e){let t=nr(e);if(t.compatible)return t;throw t.history_epoch_incompatible?new h(`pm ${t.executing_version} cannot write item-hash epoch ${t.writer_item_hash_version} into a project pinned to pm ${t.incompatible_project_version}.`,p.CONFLICT,{code:"project_runtime_history_epoch_incompatible",reason:t.incompatible_source,why:`The pinned runtime cannot read item_hash_version ${t.writer_item_hash_version}; allowing the write would break its health and validation gates.`,nextSteps:[`Upgrade the project's ${Z} pin to ${fe} or newer before mutating tracker history.`,"For an intentional coordinated migration only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.","Read-only commands remain available without an override."]}):new h(`pm ${t.executing_version} cannot mutate a project pinned to newer pm ${t.project_version}.`,p.CONFLICT,{code:"project_runtime_stale_mutation",reason:t.source,why:"An older runtime can write storage, history, and merge contracts it does not understand.",nextSteps:[`Run this command through the project's installed ${Z} ${t.project_version}.`,"For an intentional recovery only, set PM_ALLOW_STALE_CLI=1 for this invocation and record why.","Read-only commands remain available without an override."]})}import Le from"node:fs/promises";import me from"node:path";function P(e,t){return typeof e=="object"&&e!==null&&"code"in e&&e.code===t}function Bt(e){let t=["--pm-path",e,"init","--defaults","--agent-guidance","skip"];return{suggested_retry:Ue(t),suggested_retry_args:t}}function pe(e){return new h(`Tracker root is not a directory at ${e}.`,p.USAGE,{code:"tracker_root_not_directory",reason:"not_a_directory",resolved_path:e,nextSteps:["Pass a tracker directory, usually <workspace>/.agents/pm, rather than a file path."]})}function ze(e){return new h(`Tracker root is not readable at ${e}.`,p.GENERIC_FAILURE,{code:"tracker_root_unreadable",reason:"unreadable",resolved_path:e,nextSteps:["Grant read and directory-search permission to the tracker root, then retry."]})}async function rr(e){let t=me.resolve(e),n=me.parse(t).root,r=me.dirname(t);for(;r!==n;){let o;try{o=await Le.stat(r)}catch(i){if(P(i,"ENOTDIR"))throw pe(e);if(!P(i,"ENOENT"))throw i;r=me.dirname(r);continue}if(!o.isDirectory())throw pe(e);return}}async function or(e){let t;try{t=await Le.stat(e)}catch(n){throw P(n,"ENOENT")?(await rr(e),new h(`Tracker is not initialized at ${e}. Tracker root does not exist. Run pm init first.`,p.NOT_FOUND,{code:"tracker_root_missing",reason:"missing",resolved_path:e,nextSteps:["Confirm the tracker root path or initialize it with the emitted retry."],recovery:Bt(e)})):P(n,"ENOTDIR")?pe(e):P(n,"EACCES")||P(n,"EPERM")?ze(e):n}if(!t.isDirectory())throw pe(e);if(process.platform!=="win32"&&((t.mode&292)===0||(t.mode&73)===0))throw ze(e);try{await(await Le.opendir(e)).close()}catch(n){throw P(n,"EACCES")||P(n,"EPERM")?ze(e):n}}async function ko(e){if(await or(e),!await Fe(q(e)))throw new h(`Tracker is not initialized at ${e}. Run pm init first.`,p.NOT_FOUND,{code:"tracker_not_initialized",reason:"settings_missing",resolved_path:e,nextSteps:["Initialize the selected tracker root with the emitted retry."],recovery:Bt(e)})}export{C as a,R as b,hr as c,yr as d,wr as e,ot as f,kr as g,gr as h,br as i,Or as j,L as k,Gr as l,en as m,bt as n,Yr as o,Xr as p,Tn as q,se as r,Mt as s,Ft as t,Qr as u,Zr as v,fe as w,A as x,de as y,Ut as z,er as A,co as B,tr as C,nr as D,lo as E,Bt as F,or as G,ko as H};
9
- //# sourceMappingURL=chunk-OXC5KBIQ.js.map
9
+ //# sourceMappingURL=chunk-RRBNCL63.js.map
@@ -1,4 +1,4 @@
1
- import{A as ws,G as ln,e as Hr,f as qr,k as dn,l as Br,m as Wr,n as Es,p as xt,t as qe,u as Y,v as Tt}from"./chunk-OXC5KBIQ.js";import{a as gs}from"./chunk-3AZOATC2.js";import{$ as ns,$b as gt,$g as hs,Aa as as,Af as ms,Bb as Mr,Bf as zr,Cf as ps,Ea as kr,Fa as nn,Hb as Pr,I as Yi,Ib as _t,J as Gi,M as Ki,Ma as cs,Mf as wt,Nb as ht,Nf as Ur,Og as _s,Tb as yt,Ua as ce,Ub as ds,Va as pt,W as S,Wa as He,Xg as _e,Y as ft,Ye as Dr,Z as Ve,_ as b,a as Vi,ac as $r,bc as Et,cg as St,ch as an,dh as bt,e as Hi,fb as Ae,gb as Lr,gh as U,hf as on,i as qi,if as sn,j as Bi,ja as Te,jh as cn,kh as Ce,lh as ys,mc as ls,mh as Vr,nc as fs,ra as is,rh as un,yc as rn,yf as Fr,za as Nr,zb as us,zf as jr}from"./chunk-NRQCBUYD.js";import{c as Cr,d as Ir,e as Ji,f as Rr,g as dt,l as en,p as vr,q as pe,r as be,s as Ue,t as lt,u as W}from"./chunk-GSLOAEY2.js";import{A as Qi,F as es,I as tn,P as os,Q as F,b as at,da as Or,ea as ss,j as Wi,x as xe,z as Zi}from"./chunk-I4SPJQQI.js";import{G as ts,H as rs,I as mt,a as ut}from"./chunk-TE6FBDHP.js";import{A as p,B as Qt,C as _,D as Xi,E as $,G as D,H as I,L as A,M as Ar,N as ct,u as ee,z as Tr}from"./chunk-K672XXGQ.js";var Bl=new Set(["rename-type","rename-field","remap-status",...Vi]);function Wl(e,t){if(t&&!Bl.has(e))throw new _(`schema ${e} does not support --dry-run. Preview is supported for rename-type, rename-field, remap-status and workflow-policy actions. Remove --dry-run only when you intend to apply changes.`,p.USAGE,{code:"invalid_argument_value",examples:["pm schema rename-type Spike --to Experiment --dry-run"]})}var fn=new WeakSet,Yr=new WeakMap,bs=new WeakSet;function Gr(e){return bs.add(e),e}function Kr(e){return bs.has(e)}function At(e){fn.add(e);for(let[t,n]of Object.entries(e)){if(!Array.isArray(n))continue;let r=[...n];Reflect.set(e,t,r),fn.add(r)}return e}function xs(e,t){return fn.has(e)||t!==void 0&&Yr.get(e)?.has(t)===!0}function Yl(e,t){let n=new Set(t);Yr.set(e,n);for(let r of n){let o=Reflect.get(e,r);if(!Array.isArray(o))continue;let i=[...o];Reflect.set(e,r,i),fn.add(i)}return e}function Ts(e,t){if(Kr(e)&&Gr(t),xs(e))return At(t);let n=Yr.get(e);return n?Yl(t,n):t}function cT(e){return xs(e)?"sdk":"cli"}function Ss(e,t){return e==="cli"?`--${t}`:t.replace(/-([a-z])/gu,(n,r)=>r.toUpperCase())}function Ct(e){return`Pass unset: ["${e}"] to clear it`}function mn(e,t,n=""){return e==="cli"?`--${t} must not be empty${n}`:`${Ss("sdk",t)} must not be empty. ${Ct(t)}, or omit ${Ss("sdk",t)}.`}var ue="-",Cs=/^[A-Za-z0-9_.-]+$/u,Xr=new Set(["actual_result","body","cmd","command","customer_impact","description","environment","expected_result","impact","location","message","note","outcome","repro_steps","resolution","text","title","unblock_note","value","why_now"]);function Is(e,t){if(e.startsWith("```")||e.includes(`
1
+ import{A as ws,G as ln,e as Hr,f as qr,k as dn,l as Br,m as Wr,n as Es,p as xt,t as qe,u as Y,v as Tt}from"./chunk-RRBNCL63.js";import{a as gs}from"./chunk-3AZOATC2.js";import{$ as ft,$e as Dr,$g as _e,Bc as rn,Bf as Fr,Ca as Nr,Cb as us,Cf as jr,Da as as,Df as ms,Eb as Mr,Ef as zr,Ff as ps,Ha as kr,Ia as nn,Kb as Pr,L as Yi,Lb as _t,M as Gi,P as Ki,Pa as cs,Pf as wt,Qb as ht,Qf as Ur,Sg as _s,Wb as yt,Xa as ce,Xb as ds,Ya as pt,Z as S,Za as He,a as Vi,aa as Ve,ba as b,ca as ns,cc as gt,dc as $r,dh as hs,e as Hi,ec as Et,fg as St,gh as an,hh as bt,i as qi,ib as Ae,j as Bi,jb as Lr,kf as on,kh as U,lf as sn,ma as Te,nh as cn,oh as Ce,pc as ls,ph as ys,qc as fs,qh as Vr,ua as is,vh as un}from"./chunk-UXEZXGAD.js";import{c as Cr,d as Ir,e as Ji,f as Rr,g as dt,l as en,p as vr,q as pe,r as be,s as Ue,t as lt,u as W}from"./chunk-GSLOAEY2.js";import{A as Qi,F as es,I as tn,P as os,Q as F,b as at,da as Or,ea as ss,j as Wi,x as xe,z as Zi}from"./chunk-XGNUDSCG.js";import{G as ts,H as rs,I as mt,a as ut}from"./chunk-TE6FBDHP.js";import{A as p,B as Qt,C as _,D as Xi,E as $,G as D,H as I,L as A,M as Ar,N as ct,u as ee,z as Tr}from"./chunk-K672XXGQ.js";var Bl=new Set(["rename-type","rename-field","remap-status",...Vi]);function Wl(e,t){if(t&&!Bl.has(e))throw new _(`schema ${e} does not support --dry-run. Preview is supported for rename-type, rename-field, remap-status and workflow-policy actions. Remove --dry-run only when you intend to apply changes.`,p.USAGE,{code:"invalid_argument_value",examples:["pm schema rename-type Spike --to Experiment --dry-run"]})}var fn=new WeakSet,Yr=new WeakMap,bs=new WeakSet;function Gr(e){return bs.add(e),e}function Kr(e){return bs.has(e)}function At(e){fn.add(e);for(let[t,n]of Object.entries(e)){if(!Array.isArray(n))continue;let r=[...n];Reflect.set(e,t,r),fn.add(r)}return e}function xs(e,t){return fn.has(e)||t!==void 0&&Yr.get(e)?.has(t)===!0}function Yl(e,t){let n=new Set(t);Yr.set(e,n);for(let r of n){let o=Reflect.get(e,r);if(!Array.isArray(o))continue;let i=[...o];Reflect.set(e,r,i),fn.add(i)}return e}function Ts(e,t){if(Kr(e)&&Gr(t),xs(e))return At(t);let n=Yr.get(e);return n?Yl(t,n):t}function cT(e){return xs(e)?"sdk":"cli"}function Ss(e,t){return e==="cli"?`--${t}`:t.replace(/-([a-z])/gu,(n,r)=>r.toUpperCase())}function Ct(e){return`Pass unset: ["${e}"] to clear it`}function mn(e,t,n=""){return e==="cli"?`--${t} must not be empty${n}`:`${Ss("sdk",t)} must not be empty. ${Ct(t)}, or omit ${Ss("sdk",t)}.`}var ue="-",Cs=/^[A-Za-z0-9_.-]+$/u,Xr=new Set(["actual_result","body","cmd","command","customer_impact","description","environment","expected_result","impact","location","message","note","outcome","repro_steps","resolution","text","title","unblock_note","value","why_now"]);function Is(e,t){if(e.startsWith("```")||e.includes(`
2
2
  `))return!0;let n=t.map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|");return new RegExp(`^(?:[-*+]\\s+)?(?:${n})\\s*[:=]`,"i").test(e)}function Rs(e){let t=e.trim();if(t==="")return[];let r=(Zl(t)??t.split(",")).map(o=>o.trim()).filter(Boolean).map(o=>o.toLowerCase());return Array.from(new Set(r)).sort((o,i)=>o.localeCompare(i))}function vs(e){if(!Array.isArray(e)||e.length===0)return[];let t=[];for(let n of e)if(typeof n=="string")for(let r of Rs(n))t.push(r);return Array.from(new Set(t)).sort((n,r)=>n.localeCompare(r))}function Os(e){return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim().toLowerCase()).filter(Boolean):[]}function Gl(e){return typeof e!="string"?[]:e.split(";").map(t=>t.trim()).filter(Boolean)}function Kl(e,t,n){let r=e.map(s=>s.trim()).filter(Boolean);for(let s of t??[]){let a=s.trim();if(a.includes(";"))throw new _('Acceptance criteria added with --add-ac cannot contain ";" because semicolons delimit stored criteria',p.USAGE,{code:"acceptance_criteria_semicolon_forbidden",required:"Pass one semicolon-free criterion per --add-ac value",why:"A semicolon inside one criterion would be re-read as multiple criteria",nextSteps:["Split the text into repeated --add-ac values, or replace the semicolon with punctuation that is not the storage delimiter"]});a.length>0&&!r.includes(a)&&r.push(a)}let o=[],i=r;for(let s of n??[]){let a=s.trim();if(a.length!==0){if(!i.includes(a)){o.push(a);continue}i=i.filter(c=>c!==a)}}return{criteria:i,unmatchedRemovals:o}}function Xl(e,t){let n=Os(e);if(!t||t.length===0)return Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i));let r=new Set(n);for(let o of vs(t))r.add(o);return Array.from(r).sort((o,i)=>o.localeCompare(i))}function Jl(e,t){let n=Array.from(new Set(Os(e))).sort((o,i)=>o.localeCompare(i));if(!t||t.length===0)return n;let r=new Set(vs(t));return r.size===0?n:n.filter(o=>!r.has(o))}function Zl(e){if(!e.startsWith("["))return null;let t;try{t=JSON.parse(e)}catch{return null}return t.map(r=>typeof r=="string"||typeof r=="number"||typeof r=="boolean"?String(r):"").filter(r=>r.length>0)}function Jr(e){return e.replace(/\r\n/g,`
3
3
  `)}function Ns(e){let t=Jr(e).trim();if(!t.startsWith("```"))return e;let n=t.split(`
4
4
  `);return n.length<2||n.at(-1)?.trim()!=="```"?e:n.slice(1,-1).join(`
@@ -123,5 +123,5 @@ Enable telemetry now? [${e?"Y/n":"y/N"}] `,r=vb.createInterface({input:Ob,output
123
123
  `:"";for(let i=0;;i+=1)try{await A(Xt(e,n),o,{createParentDirectories:!se(process.env[fe])});return}catch(s){let a=pl[i];if(a===void 0||!Dl(s))throw s;await Fl(a)}}function Dl(e){if(typeof e!="object"||e===null||!("code"in e))return!1;let t=e.code;return t==="EACCES"||t==="EBUSY"||t==="EPERM"}function Fl(e){return new Promise(t=>{setTimeout(t,e)})}async function zx(e,t){let n={id:J.randomUUID(),endpoint:t.endpoint,payload:t.payload,enqueued_at:F(),attempts:0},r=JSON.stringify(n);r.length>wr||await Ar(Jt(e),r)}function Ux(e){let t=JSON.stringify([e.endpoint,e.enqueued_at,e.payload]);return J.createHash("sha256").update(t).digest("hex").slice(0,32)}function Fi(e){let t=[];for(let n of e.split(`
124
124
  `)){let r=n.trim();if(r.length!==0)try{let o=JSON.parse(r);o&&typeof o=="object"&&typeof o.endpoint=="string"&&o.endpoint.trim().length>0&&"payload"in o&&typeof o.attempts=="number"&&Number.isFinite(o.attempts)&&((typeof o.id!="string"||o.id.length===0)&&(o.id=Ux(o)),t.push(o))}catch{}}return t}function Vx(e,t){if(typeof e.enqueued_at!="string"||e.enqueued_at.trim().length===0)return!1;let n=Date.parse(e.enqueued_at);return Number.isNaN(n)?!1:n<t}function ji(e,t){let n=Pl(t),r=[],o=0;for(let i of e){if(JSON.stringify(i).length>wr||Vx(i,n)||i.attempts>=ml){o+=1;continue}r.push(i)}if(r.length>Qd){let i=r.length-Qd;return o+=i,{entries:r.slice(i),prunedCount:o}}return{entries:r,prunedCount:o}}async function Hx(e,t){let n=t.map(o=>JSON.stringify(o)).join(`
125
125
  `),r=n.length>0?`${n}
126
- `:"";for(let o=0;;o+=1)try{await A(Jt(e),r,{createParentDirectories:!se(process.env[fe])});return}catch(i){let s=pl[o];if(s===void 0||!Dl(i))throw i;await Fl(s)}}async function al(e,t,n,r){return we(async()=>{let o=await I(Jt(e)),i=o===null?[]:Fi(o),s=[];for(let c of i){if(n.has(c.id))continue;let u=r.get(c.id);s.push(u?{...c,attempts:u.attempts,next_attempt_after:u.next_attempt_after}:c)}let{entries:a}=ji(s,t);return await Hx(e,a),a.length},e)}async function qx(e,t){let n=await I(Jt(e));if(n===null||n.trim().length===0){await yr(e,{pending_otel_spans:0},null);return}let r=Fi(n),{entries:o,prunedCount:i}=ji(r,t),s=o.filter(g=>Di(g.next_attempt_after)).slice(0,Kb);if(s.length===0){let g=i>0?await al(e,t,new Set,new Map):o.length;await yr(e,{pending_otel_spans:g},null);return}let a=F(),c=new Set,u=new Map,d=0,l;await Promise.all(s.map(async g=>{try{let y=await Cl(g.endpoint,{"content-type":"application/json"},JSON.stringify(g.payload));if(y<200||y>=300)throw new Error(`local_otel_export_http_${y}`);c.add(g.id),d+=1}catch(y){l=y instanceof Error?O(Yn(y.message),"redacted"):"local_otel_export_failed";let h=g.attempts+1;u.set(g.id,{attempts:h,next_attempt_after:Ll(h)})}}));let f=await al(e,t,c,u),m={pending_otel_spans:f,last_otel_attempt_at:a};d>0&&(m.last_otel_success_at=a),l!==void 0?(m.last_otel_failure_at=a,m.last_otel_failure_error=l):f===0&&(m.last_otel_failure_at=void 0,m.last_otel_failure_error=void 0),await yr(e,m,null)}async function jl(e,t,n){try{await Gx(e,t,n)}catch{}try{await qx(e,n)}catch{}}async function Bx(e,t=rx,n=z().endpoint){try{let r=xx(e),o=await Hb(r,{withFileTypes:!0}),i=Date.now(),s=new Set([Bt("events.jsonl",n),Bt("state.json",n)]),a=c=>{if(!s.has(c))return/^\.events(?:\.[a-f0-9]{16})?\.jsonl\.\d+\.\d+\.[a-f0-9]+\.tmp$/.test(c)?i-Math.max(0,t):/^(?:events\.[a-f0-9]{16}\.jsonl|state\.[a-f0-9]{16}\.json)$/.test(c)?i-ox:void 0};await Promise.all(o.map(async c=>{let u=c.isFile()?a(c.name):void 0;if(u===void 0)return;let d=N.join(r,c.name);(await dl(d)).mtimeMs<u&&await vi(d,{force:!0})}))}catch{}}async function we(e,t=pe(process.cwd()),n=5e3){let r=rl.catch(()=>{}).then(()=>_s(async()=>{let o=await Ae(t,"telemetry-queue",60,"telemetry",!1,!1,n,{createParentDirectories:!se(process.env[fe])});try{return dn(t),await e()}finally{await o()}}));return rl=r.catch(()=>{}),r}async function xr(e,t=z().endpoint){let n=await I(Xt(e,t));return n===null||n.trim().length===0?[]:kl(n)}async function Ti(e,t,n,r=z().endpoint){return we(async()=>{let o=await xr(e,r),{entries:i}=br(o,n),s=i.filter(a=>!t.has(a.event.event_id));return await $l(e,s,r),s},e)}async function Wx(e,t,n,r,o=z().endpoint){return we(async()=>{let i=await xr(e,o),{entries:s}=br(i,r),a=s.map(c=>{if(!t.has(c.event.event_id))return c;let u=c.attempts+1;return{...c,attempts:u,last_attempt_at:n,next_attempt_after:Ll(u)}});return await $l(e,a,o),a},e)}function Yx(e,t){return t===null?e:Wn(e)}async function Gx(e,t,n){let r=z().endpoint;await Bx(e,void 0,r);let o=(r??t).trim(),i=Yx(o,r),s=h=>yr(e,h,r);if(o.length===0)return;let a=await I(Xt(e,r));if(a===null||a.trim().length===0){await s({endpoint:i,queue_entries:0});return}let c=kl(a);if(c.length===0){await s({endpoint:i,queue_entries:0});return}let{entries:u,prunedCount:d}=br(c,n);if(u.length===0){let h=await Ti(e,new Set,n,r);await s({endpoint:i,queue_entries:h.length});return}let l=u.filter(h=>Ml(h)).slice(0,Xb);if(l.length===0){let h=d>0?await Ti(e,new Set,n,r):u;await s({endpoint:i,queue_entries:h.length});return}let f=new Set(l.map(h=>h.event.event_id)),m=F(),g={"content-type":"application/json"},y=process.env.PM_TELEMETRY_INGEST_KEY?.trim();y&&(g["x-pm-telemetry-key"]=y);try{let h=await Cl(o,g,JSON.stringify({schema_version:Er,events:l.map(E=>E.event)}));if(h<200||h>=300)throw new Error(`telemetry_flush_http_${h}`)}catch(h){let E=await Wx(e,f,m,n,r),w=h instanceof Error?O(Yn(h.message),"redacted"):"telemetry_flush_failed";await s({endpoint:i,queue_entries:E.length,last_attempted_flush_at:m,last_failed_flush_at:m,last_failed_flush_error:w});return}try{let h=await Ti(e,f,n,r);await s({endpoint:i,queue_entries:h.length,last_attempted_flush_at:m,last_successful_flush_at:m,last_failed_flush_at:void 0,last_failed_flush_error:void 0})}catch(h){let E=h instanceof Error?O(Yn(h.message),"redacted"):"telemetry_flush_failed",w=await xr(e,r).catch(()=>u);await s({endpoint:i,queue_entries:w.length,last_attempted_flush_at:m,last_failed_flush_at:m,last_failed_flush_error:E})}}async function Kx(e){let t=ki(e);se(process.env[fe])||await bi(N.dirname(t),{recursive:!0});try{return await bi(t),!0}catch(n){if(typeof n!="object"||n===null||!("code"in n)||n.code!=="EEXIST")throw n}try{let n=await dl(t);return Date.now()-n.mtimeMs<_l?!1:(await vi(t,{recursive:!0,force:!0}),await bi(t),!0)}catch{return!1}}function Xx(e,t){try{return Date.now()-ul(e).mtimeMs<t}catch{return!1}}function zl(e){try{Vb(e,{recursive:!0,force:!0})}catch{}}function Jx(e){if(typeof e!="object"||e===null||!("code"in e))return;let t=e.code;return typeof t=="string"?t:void 0}function Zx(e){try{return Si(e),!0}catch(t){if(Jx(t)==="EEXIST"||!D(t))return!1}try{return Si(N.dirname(e),{recursive:!0}),Si(e),!0}catch{return!1}}function Qx(e){if(Xx(ki(e),_l))return!1;let t=gl(e);try{if(Date.now()-ul(t).mtimeMs<ix)return!1;zl(t)}catch(n){if(!D(n))return!1}return Zx(t)}function Ri(e){zl(gl(e))}async function eT(e,t,n){let r=await Kx(e);if(Ri(e),!r)return!1;try{await jl(e,t,n)}finally{try{await vi(ki(e),{recursive:!0,force:!0})}catch{}}return!0}async function cl(e,t){let n=new Set;try{let{entries:r}=br(await xr(e),t);for(let o of r.filter(Ml))n.add(`event:${o.event.event_id}`)}catch{}try{let r=await I(Jt(e));if(r!==null)for(let o of ji(Fi(r),t).entries)Di(o.next_attempt_after)&&n.add(`span:${o.id}`)}catch{}return n}function zi(e,t,n){if(!Wr(e)){if(Ax())return xi=xi.then(()=>jl(e,t,n)),xi;try{if(!Qx(e))return;let o=Ub(process.execPath,[Tx()],{detached:!0,stdio:"ignore",cwd:Oi.tmpdir(),env:{...process.env,PM_GLOBAL_PATH:e,[fe]:"1"}});o.on("error",()=>{Ri(e)}),o.unref()}catch{Ri(e)}}}async function TO(e=pe(process.cwd())){if(!K().telemetry_disabled)try{await Br(e,async()=>{let t=se(process.env[fe]),n=!0;for(;n;){if(!(await Y(e)).telemetry.enabled)return;let o=await we(()=>$i(e),e);if(!o)return;let i=t?await cl(e,o.retentionDays):new Set;if(!await eT(e,o.endpoint,o.retentionDays)||!t)return;let a=await cl(e,o.retentionDays);n=a.size>0&&(a.size!==i.size||[...a].some(c=>!i.has(c)))}},()=>se(process.env[fe]))}catch{}}async function tT(e){if(K().telemetry_disabled||e.command==="telemetry"&&e.args.some(t=>t.trim().toLowerCase()==="clear"))return null;try{let t=pe(process.cwd());if(!(await Y(t)).telemetry.enabled)return null;let r=e.global.noExtensions===!0||hs(e.command),o=await we(async()=>{let i=await $i(t);if(!i)return null;let{installationId:s,endpoint:a,retentionDays:c,captureLevel:u}=i,d=Il(e.pm_version),l=vl(e.global),f=j(s,e.pm_root),m=j(s,process.cwd()),g=kx(),y=F(),h={schema_version:Er,event_id:J.randomUUID(),event_type:"command_start",occurred_at:y,installation_id:s,session_id:Sr,command:e.command,payload:$x({captureLevel:u,context:e,pmVersion:d,sourceContext:l,pmRootHash:f,cwdHash:m,installationId:s})},E=await Zd(t,e.command,r);E===1&&await gr(t,h);let w=Pe(e.command),x={...E<1?{sample_rate:E}:{},started_at:y,started_at_ms:Date.now(),command:e.command,command_taxonomy:w,pm_version:d,source_context:l.source_context,source_context_source:l.source_context_source,installation_id:s,pm_root_hash:f,cwd_hash:m,endpoint:a,retention_days:c,global_pm_root:t,capture_level:u,otel_traces_endpoint:g??void 0,otel_trace_id:g?J.randomBytes(16).toString("hex"):void 0,otel_span_id:g?J.randomBytes(8).toString("hex"):void 0};return E<1&&hr.set(x,h),x},t,Ni);return o&&o.sample_rate===void 0&&zi(t,o.endpoint,o.retention_days),o}catch{return null}}async function nT(e,t){if(!(!e||K().telemetry_disabled))try{if(!await we(async()=>{let r=await Y(e.global_pm_root);if(K().telemetry_disabled||!r.telemetry.enabled||r.telemetry.installation_id!==e.installation_id)return hr.delete(e),!1;let o=hr.get(e),i=t.ok?e.sample_rate??1:1;if(o){if(hr.delete(e),J.randomBytes(6).readUIntBE(0,6)/281474976710656>=i)return!1;o.payload.sample_rate=i,await gr(e.global_pm_root,o)}let s=F(),a=Math.max(0,Date.now()-e.started_at_ms),c=Li(Zo({ok:t.ok,errorCode:t.error_code,errorMessage:t.error,exitCode:t.exit_code})),u=Rl({ok:t.ok,errorCode:c,errorCategory:t.error_category}),d=Mi(t.exit_code,t.ok),l=t.command_resolution??nt({ok:t.ok,errorCode:c,errorCategory:u}),f=t.resolution_stage??"execute",m={schema_version:Er,event_id:J.randomUUID(),event_type:"command_finish",occurred_at:s,installation_id:e.installation_id,session_id:Sr,command:e.command,payload:{...o?{sample_rate:i}:{},...Dx({captureLevel:e.capture_level,pmVersion:e.pm_version,sourceContext:{source_context:e.source_context,source_context_source:e.source_context_source},outcome:t,durationMs:a,startedAt:e.started_at,command:e.command,installationId:e.installation_id,commandTaxonomy:e.command_taxonomy,exitCode:d,errorCode:c,errorCategory:u,commandResolution:l,resolutionStage:f})}};await gr(e.global_pm_root,m);let g=Mx(e,{...t,exit_code:d,error_code:c,error_category:u},s,a,i);return g&&await zx(e.global_pm_root,g),!0},e.global_pm_root,Ni))return;await zi(e.global_pm_root,e.endpoint,e.retention_days)}catch{}}async function rT(e){if(!K().telemetry_disabled)try{let t=pe(process.cwd());if(!(await Y(t)).telemetry.enabled)return;let r=await we(async()=>{let o=await $i(t);if(!o)return null;let{installationId:i,captureLevel:s}=o,a=Il(e.pm_version),c=vl(e.global),u=j(i,e.pm_root),d=j(i,process.cwd()),l=F(),f=Li(Zo({ok:!1,errorCode:e.error_code,errorMessage:e.error_message,exitCode:e.exit_code})),m=e.error_category??Qt(f),g=Mi(e.exit_code,!1),y=e.command.trim().length>0?e.command:"<unknown>",h=Pe(y),E=e.command_resolution??nt({ok:!1,errorCode:f,errorCategory:m}),w=e.resolution_stage??"unknown",x={schema_version:Er,event_id:J.randomUUID(),event_type:"command_error",occurred_at:l,installation_id:i,session_id:Sr,command:O(y,"redacted"),payload:Fx({captureLevel:s,pmVersion:a,sourceContext:c,command:y,commandTaxonomy:h,commandResolution:E,resolutionStage:w,args:e.args,options:e.options,pmRootHash:u,cwdHash:d,installationId:i,errorCode:f,errorCategory:m,exitCode:g,errorMessage:e.error_message})};return await gr(t,x),o},t,Ni);r&&await zi(t,r.endpoint,r.retentionDays)}catch{}}function QL(e){let t=e?.trim()??"";return/^[A-Za-z][A-Za-z0-9+.-]*:\/\//u.test(t)||/^(?:github|gitlab|jira|linear):/iu.test(t)}function eM(e){let t=e?.trim().toLowerCase();return t==="global"||t==="external"}export{Wl as a,Kr as b,xs as c,Yl as d,cT as e,Ss as f,mn as g,Is as h,Rs as i,Gl as j,Kl as k,Xl as l,Jl as m,mT as n,Qr as o,of as p,pT as q,sf as r,_T as s,It as t,cf as u,Rt as v,hT as w,uf as x,pn as y,yT as z,Be as A,lf as B,ff as C,xT as D,to as E,TT as F,AT as G,vt as H,CT as I,Ps as J,bf as K,UT as L,Tf as M,Cf as N,Rf as O,vf as P,WT as Q,Nf as R,GT as S,Df as T,XT as U,Ff as V,jf as W,JT as X,no as Y,Hs as Z,qf as _,ro as $,Bf as aa,hn as ba,Ws as ca,em as da,Gs as ea,We as fa,de as ga,im as ha,vA as ia,am as ja,Xs as ka,cm as la,um as ma,lm as na,fm as oa,mm as pa,zA as qa,hm as ra,WA as sa,wm as ta,bm as ua,xm as va,Tm as wa,Am as xa,so as ya,Rm as za,tC as Aa,nC as Ba,rC as Ca,oC as Da,iC as Ea,sC as Fa,aC as Ga,km as Ha,Lm as Ia,Mm as Ja,Pm as Ka,$m as La,Dm as Ma,Ye as Na,pa as Oa,fp as Pa,RC as Qa,Ot as Ra,Sp as Sa,ba as Ta,lo as Ua,xa as Va,DC as Wa,xp as Xa,Ap as Ya,Cp as Za,Ip as _a,Rp as $a,fo as ab,tI as bb,jI as cb,uI as db,dI as eb,lI as fb,$a as gb,Bp as hb,So as ib,TI as jb,bo as kb,Ft as lb,Xe as mb,jt as nb,O_ as ob,Ga as pb,N_ as qb,gR as rb,Ao as sb,Ka as tb,V_ as ub,ER as vb,H_ as wb,q_ as xb,AR as yb,Pn as zb,rc as Ab,Ro as Bb,rh as Cb,oh as Db,RR as Eb,oc as Fb,Je as Gb,vo as Hb,No as Ib,zn as Jb,zR as Kb,jo as Lb,Vn as Mb,lc as Nb,Hn as Ob,zo as Pb,Uo as Qb,Vo as Rb,Ho as Sb,yc as Tb,gc as Ub,mc as Vb,ey as Wb,et as Xb,Bt as Yb,ry as Zb,Wn as _b,c0 as $b,K as ac,Le as bc,dy as cc,vc as dc,Oc as ec,Nc as fc,my as gc,p0 as hc,yy as ic,_0 as jc,h0 as kc,Wt as lc,Jc as mc,rg as nc,Yt as oc,O0 as pc,N0 as qc,og as rc,ig as sc,k0 as tc,L0 as uc,nt as vc,hg as wc,yg as xc,gg as yc,Eg as zc,xg as Ac,Tg as Bc,Cg as Cc,wS as Dc,xd as Ec,$S as Fc,md as Gc,DS as Hc,J0 as Ic,zS as Jc,US as Kc,Z0 as Lc,fi as Mc,Ad as Nc,Td as Oc,qS as Pc,BS as Qc,Cd as Rc,lv as Sc,fv as Tc,Nd as Uc,kd as Vc,Ld as Wc,mv as Xc,$d as Yc,ZS as Zc,Dd as _c,pv as $c,_v as ad,hv as bd,Fd as cd,yv as dd,eb as ed,tb as fd,nb as gd,sb as hd,cb as id,db as jd,lb as kd,_b as ld,yb as md,gb as nd,_r as od,Ib as pd,Rb as qd,Fb as rd,Er as sd,ml as td,we as ud,TO as vd,tT as wd,nT as xd,rT as yd,QL as zd,eM as Ad};
127
- //# sourceMappingURL=chunk-CBUC4X7Q.js.map
126
+ `:"";for(let o=0;;o+=1)try{await A(Jt(e),r,{createParentDirectories:!se(process.env[fe])});return}catch(i){let s=pl[o];if(s===void 0||!Dl(i))throw i;await Fl(s)}}async function al(e,t,n,r){return we(async()=>{let o=await I(Jt(e)),i=o===null?[]:Fi(o),s=[];for(let c of i){if(n.has(c.id))continue;let u=r.get(c.id);s.push(u?{...c,attempts:u.attempts,next_attempt_after:u.next_attempt_after}:c)}let{entries:a}=ji(s,t);return await Hx(e,a),a.length},e)}async function qx(e,t){let n=await I(Jt(e));if(n===null||n.trim().length===0){await yr(e,{pending_otel_spans:0},null);return}let r=Fi(n),{entries:o,prunedCount:i}=ji(r,t),s=o.filter(g=>Di(g.next_attempt_after)).slice(0,Kb);if(s.length===0){let g=i>0?await al(e,t,new Set,new Map):o.length;await yr(e,{pending_otel_spans:g},null);return}let a=F(),c=new Set,u=new Map,d=0,l;await Promise.all(s.map(async g=>{try{let y=await Cl(g.endpoint,{"content-type":"application/json"},JSON.stringify(g.payload));if(y<200||y>=300)throw new Error(`local_otel_export_http_${y}`);c.add(g.id),d+=1}catch(y){l=y instanceof Error?O(Yn(y.message),"redacted"):"local_otel_export_failed";let h=g.attempts+1;u.set(g.id,{attempts:h,next_attempt_after:Ll(h)})}}));let f=await al(e,t,c,u),m={pending_otel_spans:f,last_otel_attempt_at:a};d>0&&(m.last_otel_success_at=a),l!==void 0?(m.last_otel_failure_at=a,m.last_otel_failure_error=l):f===0&&(m.last_otel_failure_at=void 0,m.last_otel_failure_error=void 0),await yr(e,m,null)}async function jl(e,t,n){try{await Gx(e,t,n)}catch{}try{await qx(e,n)}catch{}}async function Bx(e,t=rx,n=z().endpoint){try{let r=xx(e),o=await Hb(r,{withFileTypes:!0}),i=Date.now(),s=new Set([Bt("events.jsonl",n),Bt("state.json",n)]),a=c=>{if(!s.has(c))return/^\.events(?:\.[a-f0-9]{16})?\.jsonl\.\d+\.\d+\.[a-f0-9]+\.tmp$/.test(c)?i-Math.max(0,t):/^(?:events\.[a-f0-9]{16}\.jsonl|state\.[a-f0-9]{16}\.json)$/.test(c)?i-ox:void 0};await Promise.all(o.map(async c=>{let u=c.isFile()?a(c.name):void 0;if(u===void 0)return;let d=N.join(r,c.name);(await dl(d)).mtimeMs<u&&await vi(d,{force:!0})}))}catch{}}async function we(e,t=pe(process.cwd()),n=5e3){let r=rl.catch(()=>{}).then(()=>_s(async()=>{let o=await Ae(t,"telemetry-queue",60,"telemetry",!1,!1,n,{createParentDirectories:!se(process.env[fe])});try{return dn(t),await e()}finally{await o()}}));return rl=r.catch(()=>{}),r}async function xr(e,t=z().endpoint){let n=await I(Xt(e,t));return n===null||n.trim().length===0?[]:kl(n)}async function Ti(e,t,n,r=z().endpoint){return we(async()=>{let o=await xr(e,r),{entries:i}=br(o,n),s=i.filter(a=>!t.has(a.event.event_id));return await $l(e,s,r),s},e)}async function Wx(e,t,n,r,o=z().endpoint){return we(async()=>{let i=await xr(e,o),{entries:s}=br(i,r),a=s.map(c=>{if(!t.has(c.event.event_id))return c;let u=c.attempts+1;return{...c,attempts:u,last_attempt_at:n,next_attempt_after:Ll(u)}});return await $l(e,a,o),a},e)}function Yx(e,t){return t===null?e:Wn(e)}async function Gx(e,t,n){let r=z().endpoint;await Bx(e,void 0,r);let o=(r??t).trim(),i=Yx(o,r),s=h=>yr(e,h,r);if(o.length===0)return;let a=await I(Xt(e,r));if(a===null||a.trim().length===0){await s({endpoint:i,queue_entries:0});return}let c=kl(a);if(c.length===0){await s({endpoint:i,queue_entries:0});return}let{entries:u,prunedCount:d}=br(c,n);if(u.length===0){let h=await Ti(e,new Set,n,r);await s({endpoint:i,queue_entries:h.length});return}let l=u.filter(h=>Ml(h)).slice(0,Xb);if(l.length===0){let h=d>0?await Ti(e,new Set,n,r):u;await s({endpoint:i,queue_entries:h.length});return}let f=new Set(l.map(h=>h.event.event_id)),m=F(),g={"content-type":"application/json"},y=process.env.PM_TELEMETRY_INGEST_KEY?.trim();y&&(g["x-pm-telemetry-key"]=y);try{let h=await Cl(o,g,JSON.stringify({schema_version:Er,events:l.map(E=>E.event)}));if(h<200||h>=300)throw new Error(`telemetry_flush_http_${h}`)}catch(h){let E=await Wx(e,f,m,n,r),w=h instanceof Error?O(Yn(h.message),"redacted"):"telemetry_flush_failed";await s({endpoint:i,queue_entries:E.length,last_attempted_flush_at:m,last_failed_flush_at:m,last_failed_flush_error:w});return}try{let h=await Ti(e,f,n,r);await s({endpoint:i,queue_entries:h.length,last_attempted_flush_at:m,last_successful_flush_at:m,last_failed_flush_at:void 0,last_failed_flush_error:void 0})}catch(h){let E=h instanceof Error?O(Yn(h.message),"redacted"):"telemetry_flush_failed",w=await xr(e,r).catch(()=>u);await s({endpoint:i,queue_entries:w.length,last_attempted_flush_at:m,last_failed_flush_at:m,last_failed_flush_error:E})}}async function Kx(e){let t=ki(e);se(process.env[fe])||await bi(N.dirname(t),{recursive:!0});try{return await bi(t),!0}catch(n){if(typeof n!="object"||n===null||!("code"in n)||n.code!=="EEXIST")throw n}try{let n=await dl(t);return Date.now()-n.mtimeMs<_l?!1:(await vi(t,{recursive:!0,force:!0}),await bi(t),!0)}catch{return!1}}function Xx(e,t){try{return Date.now()-ul(e).mtimeMs<t}catch{return!1}}function zl(e){try{Vb(e,{recursive:!0,force:!0})}catch{}}function Jx(e){if(typeof e!="object"||e===null||!("code"in e))return;let t=e.code;return typeof t=="string"?t:void 0}function Zx(e){try{return Si(e),!0}catch(t){if(Jx(t)==="EEXIST"||!D(t))return!1}try{return Si(N.dirname(e),{recursive:!0}),Si(e),!0}catch{return!1}}function Qx(e){if(Xx(ki(e),_l))return!1;let t=gl(e);try{if(Date.now()-ul(t).mtimeMs<ix)return!1;zl(t)}catch(n){if(!D(n))return!1}return Zx(t)}function Ri(e){zl(gl(e))}async function eT(e,t,n){let r=await Kx(e);if(Ri(e),!r)return!1;try{await jl(e,t,n)}finally{try{await vi(ki(e),{recursive:!0,force:!0})}catch{}}return!0}async function cl(e,t){let n=new Set;try{let{entries:r}=br(await xr(e),t);for(let o of r.filter(Ml))n.add(`event:${o.event.event_id}`)}catch{}try{let r=await I(Jt(e));if(r!==null)for(let o of ji(Fi(r),t).entries)Di(o.next_attempt_after)&&n.add(`span:${o.id}`)}catch{}return n}function zi(e,t,n){if(!Wr(e)){if(Ax())return xi=xi.then(()=>jl(e,t,n)),xi;try{if(!Qx(e))return;let o=Ub(process.execPath,[Tx()],{detached:!0,stdio:"ignore",cwd:Oi.tmpdir(),env:{...process.env,PM_GLOBAL_PATH:e,[fe]:"1"}});o.on("error",()=>{Ri(e)}),o.unref()}catch{Ri(e)}}}async function TO(e=pe(process.cwd())){if(!K().telemetry_disabled)try{await Br(e,async()=>{let t=se(process.env[fe]),n=!0;for(;n;){if(!(await Y(e)).telemetry.enabled)return;let o=await we(()=>$i(e),e);if(!o)return;let i=t?await cl(e,o.retentionDays):new Set;if(!await eT(e,o.endpoint,o.retentionDays)||!t)return;let a=await cl(e,o.retentionDays);n=a.size>0&&(a.size!==i.size||[...a].some(c=>!i.has(c)))}},()=>se(process.env[fe]))}catch{}}async function tT(e){if(K().telemetry_disabled||e.command==="telemetry"&&e.args.some(t=>t.trim().toLowerCase()==="clear"))return null;try{let t=pe(process.cwd());if(!(await Y(t)).telemetry.enabled)return null;let r=e.global.noExtensions===!0||hs(e.command),o=await we(async()=>{let i=await $i(t);if(!i)return null;let{installationId:s,endpoint:a,retentionDays:c,captureLevel:u}=i,d=Il(e.pm_version),l=vl(e.global),f=j(s,e.pm_root),m=j(s,process.cwd()),g=kx(),y=F(),h={schema_version:Er,event_id:J.randomUUID(),event_type:"command_start",occurred_at:y,installation_id:s,session_id:Sr,command:e.command,payload:$x({captureLevel:u,context:e,pmVersion:d,sourceContext:l,pmRootHash:f,cwdHash:m,installationId:s})},E=await Zd(t,e.command,r);E===1&&await gr(t,h);let w=Pe(e.command),x={...E<1?{sample_rate:E}:{},started_at:y,started_at_ms:Date.now(),command:e.command,command_taxonomy:w,pm_version:d,source_context:l.source_context,source_context_source:l.source_context_source,installation_id:s,pm_root_hash:f,cwd_hash:m,endpoint:a,retention_days:c,global_pm_root:t,capture_level:u,otel_traces_endpoint:g??void 0,otel_trace_id:g?J.randomBytes(16).toString("hex"):void 0,otel_span_id:g?J.randomBytes(8).toString("hex"):void 0};return E<1&&hr.set(x,h),x},t,Ni);return o&&o.sample_rate===void 0&&zi(t,o.endpoint,o.retention_days),o}catch{return null}}async function nT(e,t){if(!(!e||K().telemetry_disabled))try{if(!await we(async()=>{let r=await Y(e.global_pm_root);if(K().telemetry_disabled||!r.telemetry.enabled||r.telemetry.installation_id!==e.installation_id)return hr.delete(e),!1;let o=hr.get(e),i=t.ok?e.sample_rate??1:1;if(o){if(hr.delete(e),J.randomBytes(6).readUIntBE(0,6)/281474976710656>=i)return!1;o.payload.sample_rate=i,await gr(e.global_pm_root,o)}let s=F(),a=Math.max(0,Date.now()-e.started_at_ms),c=Li(Zo({ok:t.ok,errorCode:t.error_code,errorMessage:t.error,exitCode:t.exit_code})),u=Rl({ok:t.ok,errorCode:c,errorCategory:t.error_category}),d=Mi(t.exit_code,t.ok),l=t.command_resolution??nt({ok:t.ok,errorCode:c,errorCategory:u}),f=t.resolution_stage??"execute",m={schema_version:Er,event_id:J.randomUUID(),event_type:"command_finish",occurred_at:s,installation_id:e.installation_id,session_id:Sr,command:e.command,payload:{...o?{sample_rate:i}:{},...Dx({captureLevel:e.capture_level,pmVersion:e.pm_version,sourceContext:{source_context:e.source_context,source_context_source:e.source_context_source},outcome:t,durationMs:a,startedAt:e.started_at,command:e.command,installationId:e.installation_id,commandTaxonomy:e.command_taxonomy,exitCode:d,errorCode:c,errorCategory:u,commandResolution:l,resolutionStage:f})}};await gr(e.global_pm_root,m);let g=Mx(e,{...t,exit_code:d,error_code:c,error_category:u},s,a,i);return g&&await zx(e.global_pm_root,g),!0},e.global_pm_root,Ni))return;await zi(e.global_pm_root,e.endpoint,e.retention_days)}catch{}}async function rT(e){if(!K().telemetry_disabled)try{let t=pe(process.cwd());if(!(await Y(t)).telemetry.enabled)return;let r=await we(async()=>{let o=await $i(t);if(!o)return null;let{installationId:i,captureLevel:s}=o,a=Il(e.pm_version),c=vl(e.global),u=j(i,e.pm_root),d=j(i,process.cwd()),l=F(),f=Li(Zo({ok:!1,errorCode:e.error_code,errorMessage:e.error_message,exitCode:e.exit_code})),m=e.error_category??Qt(f),g=Mi(e.exit_code,!1),y=e.command.trim().length>0?e.command:"<unknown>",h=Pe(y),E=e.command_resolution??nt({ok:!1,errorCode:f,errorCategory:m}),w=e.resolution_stage??"unknown",x={schema_version:Er,event_id:J.randomUUID(),event_type:"command_error",occurred_at:l,installation_id:i,session_id:Sr,command:O(y,"redacted"),payload:Fx({captureLevel:s,pmVersion:a,sourceContext:c,command:y,commandTaxonomy:h,commandResolution:E,resolutionStage:w,args:e.args,options:e.options,pmRootHash:u,cwdHash:d,installationId:i,errorCode:f,errorCategory:m,exitCode:g,errorMessage:e.error_message})};return await gr(t,x),o},t,Ni);r&&await zi(t,r.endpoint,r.retentionDays)}catch{}}function eM(e){let t=e?.trim()??"";return/^[A-Za-z][A-Za-z0-9+.-]*:\/\//u.test(t)||/^(?:github|gitlab|jira|linear):/iu.test(t)}function tM(e){let t=e?.trim().toLowerCase();return t==="global"||t==="external"}export{Wl as a,Kr as b,xs as c,Yl as d,cT as e,Ss as f,mn as g,Is as h,Rs as i,Gl as j,Kl as k,Xl as l,Jl as m,mT as n,Qr as o,of as p,pT as q,sf as r,_T as s,It as t,cf as u,Rt as v,hT as w,uf as x,pn as y,yT as z,Be as A,lf as B,ff as C,xT as D,to as E,TT as F,AT as G,vt as H,CT as I,Ps as J,bf as K,UT as L,Tf as M,Cf as N,Rf as O,vf as P,WT as Q,Nf as R,GT as S,Df as T,XT as U,Ff as V,jf as W,JT as X,no as Y,Hs as Z,qf as _,ro as $,Bf as aa,hn as ba,Ws as ca,em as da,Gs as ea,We as fa,de as ga,im as ha,vA as ia,am as ja,Xs as ka,cm as la,um as ma,lm as na,fm as oa,mm as pa,zA as qa,hm as ra,WA as sa,wm as ta,bm as ua,xm as va,Tm as wa,Am as xa,so as ya,Rm as za,tC as Aa,nC as Ba,rC as Ca,oC as Da,iC as Ea,sC as Fa,aC as Ga,km as Ha,Lm as Ia,Mm as Ja,Pm as Ka,$m as La,Dm as Ma,Ye as Na,pa as Oa,fp as Pa,RC as Qa,Ot as Ra,Sp as Sa,ba as Ta,lo as Ua,xa as Va,DC as Wa,xp as Xa,Ap as Ya,Cp as Za,Ip as _a,Rp as $a,fo as ab,tI as bb,jI as cb,uI as db,dI as eb,lI as fb,$a as gb,Bp as hb,So as ib,TI as jb,bo as kb,Ft as lb,Xe as mb,jt as nb,O_ as ob,Ga as pb,N_ as qb,gR as rb,Ao as sb,Ka as tb,V_ as ub,ER as vb,H_ as wb,q_ as xb,AR as yb,Pn as zb,rc as Ab,Ro as Bb,rh as Cb,oh as Db,RR as Eb,oc as Fb,Je as Gb,vo as Hb,No as Ib,zn as Jb,zR as Kb,jo as Lb,Vn as Mb,lc as Nb,Hn as Ob,zo as Pb,Uo as Qb,Vo as Rb,Ho as Sb,yc as Tb,gc as Ub,mc as Vb,ey as Wb,et as Xb,Bt as Yb,ry as Zb,Wn as _b,c0 as $b,K as ac,Le as bc,dy as cc,vc as dc,Oc as ec,Nc as fc,my as gc,p0 as hc,yy as ic,_0 as jc,h0 as kc,Wt as lc,Jc as mc,rg as nc,Yt as oc,O0 as pc,N0 as qc,og as rc,ig as sc,k0 as tc,L0 as uc,nt as vc,hg as wc,yg as xc,gg as yc,Eg as zc,xg as Ac,Tg as Bc,Cg as Cc,wS as Dc,xd as Ec,$S as Fc,md as Gc,DS as Hc,J0 as Ic,zS as Jc,US as Kc,Z0 as Lc,fi as Mc,Ad as Nc,Td as Oc,qS as Pc,BS as Qc,Cd as Rc,lv as Sc,fv as Tc,Nd as Uc,kd as Vc,Ld as Wc,mv as Xc,$d as Yc,ZS as Zc,Dd as _c,pv as $c,_v as ad,hv as bd,Fd as cd,yv as dd,eb as ed,tb as fd,nb as gd,sb as hd,cb as id,db as jd,lb as kd,_b as ld,yb as md,gb as nd,_r as od,Ib as pd,Rb as qd,Fb as rd,Er as sd,ml as td,we as ud,TO as vd,tT as wd,nT as xd,rT as yd,eM as zd,tM as Ad};
127
+ //# sourceMappingURL=chunk-TDOF7BKO.js.map