@unbrained/pm-cli 2026.11.15 → 2026.11.16

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 (181) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/error-guidance.js +2 -2
  3. package/dist/cli/help-content.js +2 -2
  4. package/dist/cli/register-operations.js +1 -1
  5. package/dist/cli-bundle/bundle-manifest.json +1 -1
  6. package/dist/cli-bundle/chunks/{chunk-TESRFVGF.js → chunk-2D26HRXB.js} +2 -2
  7. package/dist/cli-bundle/chunks/{chunk-VWKLTHYQ.js → chunk-2WNORBVN.js} +36 -25
  8. package/dist/cli-bundle/chunks/{chunk-J6L3Q5J4.js → chunk-4I7YG3VZ.js} +2 -2
  9. package/dist/cli-bundle/chunks/{chunk-QZNDEZYI.js → chunk-4WIVCOA7.js} +2 -2
  10. package/dist/cli-bundle/chunks/chunk-A3WCP4TU.js +6 -0
  11. package/dist/cli-bundle/chunks/chunk-AB5S6TWE.js +124 -0
  12. package/dist/cli-bundle/chunks/{chunk-KLWGIEDC.js → chunk-BV7J3LRH.js} +3 -3
  13. package/dist/cli-bundle/chunks/{chunk-GCSKHCYK.js → chunk-DZWRNL6R.js} +2 -2
  14. package/dist/cli-bundle/chunks/{chunk-KSLPRST2.js → chunk-E4BQRZF2.js} +3 -3
  15. package/dist/cli-bundle/chunks/chunk-ERD2RYWM.js +31 -0
  16. package/dist/cli-bundle/chunks/chunk-F7P42FL5.js +9 -0
  17. package/dist/cli-bundle/chunks/{chunk-E4B2HWH7.js → chunk-FZ4XWWLO.js} +23 -23
  18. package/dist/cli-bundle/chunks/{chunk-7AODVNHX.js → chunk-I3T2FVUA.js} +2 -2
  19. package/dist/cli-bundle/chunks/{chunk-PMIGRSNZ.js → chunk-IGEBFNWE.js} +2 -2
  20. package/dist/cli-bundle/chunks/{chunk-YLPZE2TK.js → chunk-IYICNCK2.js} +2 -2
  21. package/dist/cli-bundle/chunks/chunk-J257NZRD.js +20 -0
  22. package/dist/cli-bundle/chunks/{chunk-Q6GBRK27.js → chunk-JD3XWF66.js} +2 -2
  23. package/dist/cli-bundle/chunks/{chunk-FSE624WQ.js → chunk-JLHD7OQ2.js} +2 -2
  24. package/dist/cli-bundle/chunks/{chunk-DBUBX4DL.js → chunk-KGOGLKL2.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-ZWUS65LN.js → chunk-LC4DJVXR.js} +2 -2
  26. package/dist/cli-bundle/chunks/{chunk-LC6DL446.js → chunk-NHNM3GIP.js} +2 -2
  27. package/dist/cli-bundle/chunks/{chunk-ZVDXGAYV.js → chunk-NYN5OR2T.js} +2 -2
  28. package/dist/cli-bundle/chunks/{chunk-6UTBX62V.js → chunk-OFZQEQ6X.js} +2 -2
  29. package/dist/cli-bundle/chunks/{chunk-GAFALSR2.js → chunk-QGL5IAP4.js} +3 -3
  30. package/dist/cli-bundle/chunks/{chunk-HMVZSXB4.js → chunk-R24NZ2TB.js} +2 -2
  31. package/dist/cli-bundle/chunks/{chunk-S5UXBECQ.js → chunk-VJLZHOTP.js} +2 -2
  32. package/dist/cli-bundle/chunks/{chunk-YJNY5MKP.js → chunk-VO2HSB5F.js} +2 -2
  33. package/dist/cli-bundle/chunks/{indexed-receipt-blobs-42Y2CSEQ.js → indexed-receipt-blobs-HNLN6UXH.js} +2 -2
  34. package/dist/cli-bundle/chunks/{item-revision-JCEDTAVX.js → item-revision-PSOL5I4H.js} +2 -2
  35. package/dist/cli-bundle/chunks/item-transaction-55QTCU2M.js +2 -0
  36. package/dist/cli-bundle/chunks/{mutation-actor-IQHBRFAJ.js → mutation-actor-BDBBH3ZS.js} +2 -2
  37. package/dist/cli-bundle/chunks/{mutation-admission-DF6BFGG6.js → mutation-admission-WUN7JYVJ.js} +2 -2
  38. package/dist/cli-bundle/chunks/{register-list-query-DNKPQB76.js → register-list-query-AESCVO6H.js} +2 -2
  39. package/dist/cli-bundle/chunks/{register-mutation-WVTDFLEF.js → register-mutation-SKCEP5QU.js} +2 -2
  40. package/dist/cli-bundle/chunks/register-operations-ZT4OYCF3.js +2 -0
  41. package/dist/cli-bundle/chunks/{register-setup-2RTG3LII.js → register-setup-JVWNS2TY.js} +2 -2
  42. package/dist/cli-bundle/chunks/{settlement-hook-W5ULPKIE.js → settlement-hook-MVVVUIVZ.js} +2 -2
  43. package/dist/cli-bundle/chunks/{stage-YFNK7U26.js → stage-RMU3JAWM.js} +2 -2
  44. package/dist/cli-bundle/focused-chunks/{chunk-YZUBG4W2.js → chunk-3WVMEA2A.js} +3 -3
  45. package/dist/cli-bundle/focused-chunks/{chunk-CZZKAGHE.js → chunk-5UVJOAUP.js} +6 -6
  46. package/dist/cli-bundle/focused-chunks/{chunk-EALGFJRP.js → chunk-5WQ3LNUK.js} +3 -3
  47. package/dist/cli-bundle/focused-chunks/chunk-6E4X7MQA.js +26 -0
  48. package/dist/cli-bundle/focused-chunks/{chunk-JE3MFEQZ.js → chunk-7SEPCQV2.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/{chunk-XQZKGTZV.js → chunk-7XHE335U.js} +2 -2
  50. package/dist/cli-bundle/focused-chunks/{chunk-52H6AELE.js → chunk-BEHIMEV2.js} +2 -2
  51. package/dist/cli-bundle/focused-chunks/{chunk-JXA77YIV.js → chunk-CZFZCSOX.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/{chunk-W2KIQ7RF.js → chunk-DFBHW7HP.js} +3 -3
  53. package/dist/cli-bundle/focused-chunks/{chunk-WGYR3X6O.js → chunk-DZMP3VYQ.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/chunk-HHMMIHZP.js +2 -0
  55. package/dist/cli-bundle/focused-chunks/{chunk-LSWUTTE6.js → chunk-HPC2M6JD.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/{chunk-2UQFFVQK.js → chunk-HR5FEUUL.js} +2 -2
  57. package/dist/cli-bundle/focused-chunks/{chunk-S6GTALM4.js → chunk-J7ESCE7M.js} +3 -3
  58. package/dist/cli-bundle/focused-chunks/chunk-KRNF3WTC.js +3 -0
  59. package/dist/cli-bundle/focused-chunks/{chunk-DXMQ32EH.js → chunk-KWZLY35A.js} +2 -2
  60. package/dist/cli-bundle/focused-chunks/{chunk-Z6HCQYSW.js → chunk-M4IA4LC6.js} +2 -2
  61. package/dist/cli-bundle/focused-chunks/{chunk-YTNUUEY6.js → chunk-NASE6JC2.js} +2 -2
  62. package/dist/cli-bundle/focused-chunks/chunk-ONM2R32I.js +65 -0
  63. package/dist/cli-bundle/focused-chunks/{chunk-QXOFSZR6.js → chunk-PDXSMSO5.js} +2 -2
  64. package/dist/cli-bundle/focused-chunks/{chunk-BSY6FZ3Y.js → chunk-PEL4SQXV.js} +2 -2
  65. package/dist/cli-bundle/focused-chunks/{chunk-DRBXOAGY.js → chunk-QJ647CQE.js} +2 -2
  66. package/dist/cli-bundle/focused-chunks/chunk-SFATIM77.js +12 -0
  67. package/dist/cli-bundle/focused-chunks/{chunk-7GCAZJT4.js → chunk-UBBTBNUY.js} +2 -2
  68. package/dist/cli-bundle/focused-chunks/{chunk-UPUIDGNJ.js → chunk-ZCN35TCK.js} +2 -2
  69. package/dist/cli-bundle/focused-chunks/chunk-ZSQ2FT22.js +44 -0
  70. package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-LSBWMXKS.js → indexed-receipt-blobs-ADMQXF3N.js} +2 -2
  71. package/dist/cli-bundle/focused-chunks/{item-revision-YO7YGQYE.js → item-revision-GNKYO6GZ.js} +2 -2
  72. package/dist/cli-bundle/focused-chunks/{item-transaction-7A3Q4CAJ.js → item-transaction-AUUQHR5Z.js} +2 -2
  73. package/dist/cli-bundle/focused-chunks/{mutation-actor-UQHBNHOF.js → mutation-actor-OBRD7HFZ.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/{mutation-admission-G565NLPE.js → mutation-admission-6TX3EOJX.js} +2 -2
  75. package/dist/cli-bundle/focused-chunks/{settlement-hook-UXN76GMA.js → settlement-hook-5U2M75BY.js} +2 -2
  76. package/dist/cli-bundle/focused-chunks/{stage-F3YJGNRK.js → stage-LERF2YJU.js} +2 -2
  77. package/dist/cli-bundle/main.js +6 -6
  78. package/dist/cli-bundle/sdk-authoring.js +1 -1
  79. package/dist/cli-bundle/sdk-contracts.js +2 -2
  80. package/dist/cli-bundle/sdk-core.js +1 -1
  81. package/dist/cli-bundle/sdk-governance.js +1 -1
  82. package/dist/cli-bundle/sdk-graph.js +1 -1
  83. package/dist/cli-bundle/sdk-merge.js +57 -57
  84. package/dist/cli-bundle/sdk-query.js +1 -1
  85. package/dist/cli-bundle/sdk-runtime.js +1 -1
  86. package/dist/cli-bundle/sdk-testing.js +1 -1
  87. package/dist/cli-bundle/sdk.js +11 -11
  88. package/dist/core/diagnostics/remediation.js +1 -1
  89. package/dist/core/output/mutation-projection.js +1 -1
  90. package/dist/core/shared/errors.d.ts +22 -0
  91. package/dist/core/shared/errors.js +1 -1
  92. package/dist/core/store/item-store.d.ts +15 -4
  93. package/dist/core/store/item-store.js +1 -1
  94. package/dist/core/telemetry/policy.d.ts +21 -2
  95. package/dist/core/telemetry/policy.js +1 -1
  96. package/dist/sdk/cli-contracts/flag-contracts.js +1 -1
  97. package/dist/sdk/cli-contracts/flag-lexicon-contracts.js +1 -1
  98. package/dist/sdk/cli-contracts/tool-parameter-tables.js +1 -1
  99. package/dist/sdk/cli-contracts/tool-schema.d.ts +1 -1
  100. package/dist/sdk/cli-contracts/tool-schema.js +1 -1
  101. package/dist/sdk/completion/bash.js +1 -1
  102. package/dist/sdk/completion/fish.js +2 -1
  103. package/dist/sdk/completion/zsh.js +12 -2
  104. package/dist/sdk/flag-invocation-contracts.js +1 -1
  105. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -1
  106. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +1 -1
  107. package/dist/sdk/governance/health.js +2 -2
  108. package/dist/sdk/governance/in-progress-work-health.d.ts +49 -0
  109. package/dist/sdk/governance/in-progress-work-health.js +2 -0
  110. package/dist/sdk/governance/stale-work.d.ts +143 -2
  111. package/dist/sdk/governance/stale-work.js +1 -1
  112. package/dist/sdk/governance.d.ts +1 -1
  113. package/dist/sdk/governance.js +1 -1
  114. package/dist/sdk/history-compact.js +1 -1
  115. package/dist/sdk/index.d.ts +1 -1
  116. package/dist/sdk/index.js +1 -1
  117. package/dist/sdk/lifecycle/claim.d.ts +46 -3
  118. package/dist/sdk/lifecycle/claim.js +1 -1
  119. package/dist/sdk/lifecycle/task-composition.js +1 -1
  120. package/dist/sdk/ownership-source.d.ts +32 -0
  121. package/dist/sdk/ownership-source.js +1 -1
  122. package/dist/sdk/public-surface.json +1 -1
  123. package/dist/sdk/query/context.d.ts +5 -1
  124. package/dist/sdk/query/context.js +2 -2
  125. package/dist/sdk/query/next.d.ts +19 -3
  126. package/dist/sdk/query/next.js +1 -1
  127. package/dist/sdk/runtime-input.js +1 -1
  128. package/dist/sdk/runtime-primitives.d.ts +1 -1
  129. package/dist/sdk/runtime-primitives.js +1 -1
  130. package/docs/AGENT_GUIDE.md +2 -0
  131. package/docs/COMMANDS.md +22 -0
  132. package/docs/CONFIGURATION.md +20 -7
  133. package/docs/LIFECYCLE_COMMANDS.md +8 -1
  134. package/docs/MUTATION_INTEGRITY.md +79 -1
  135. package/docs/SDK.md +28 -0
  136. package/docs/generated/FLAG_LEXICON_BUDGETS.md +2 -2
  137. package/marketplace.json +1 -1
  138. package/node_modules/commander/Readme.md +6 -32
  139. package/node_modules/commander/index.js +1 -1
  140. package/node_modules/commander/lib/command.js +22 -9
  141. package/node_modules/commander/lib/help.js +6 -2
  142. package/node_modules/commander/lib/option.js +1 -1
  143. package/node_modules/commander/package.json +2 -1
  144. package/node_modules/commander/typings/index.d.ts +6 -3
  145. package/node_modules/semver/classes/range.js +2 -2
  146. package/node_modules/semver/internal/constants.js +30 -0
  147. package/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  148. package/node_modules/semver/package.json +1 -1
  149. package/package.json +3 -3
  150. package/packages/pm-beads/package.json +1 -1
  151. package/packages/pm-calendar/package.json +1 -1
  152. package/packages/pm-command-kit/package.json +1 -1
  153. package/packages/pm-digital-twin/package.json +1 -1
  154. package/packages/pm-governance-audit/package.json +1 -1
  155. package/packages/pm-guide-shell/package.json +1 -1
  156. package/packages/pm-kanban/package.json +1 -1
  157. package/packages/pm-lifecycle-hooks/package.json +1 -1
  158. package/packages/pm-linked-test-adapters/package.json +1 -1
  159. package/packages/pm-search-advanced/package.json +1 -1
  160. package/packages/pm-templates/package.json +1 -1
  161. package/packages/pm-todos/package.json +1 -1
  162. package/packages/pm-vcs/package.json +1 -1
  163. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  164. package/plugins/pm-claude/package.json +1 -1
  165. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  166. package/plugins/pm-codex/package.json +1 -1
  167. package/plugins/pm-codex/plugin.json +1 -1
  168. package/runtime-dependencies.json +1 -1
  169. package/dist/cli-bundle/chunks/chunk-ASGAELBQ.js +0 -9
  170. package/dist/cli-bundle/chunks/chunk-E74OMFBZ.js +0 -6
  171. package/dist/cli-bundle/chunks/chunk-FYOIH56R.js +0 -20
  172. package/dist/cli-bundle/chunks/chunk-IXV5UM4U.js +0 -31
  173. package/dist/cli-bundle/chunks/chunk-NAX554KY.js +0 -124
  174. package/dist/cli-bundle/chunks/item-transaction-BSMGKZ4S.js +0 -2
  175. package/dist/cli-bundle/chunks/register-operations-NR5MTT5T.js +0 -2
  176. package/dist/cli-bundle/focused-chunks/chunk-63FM3TIG.js +0 -26
  177. package/dist/cli-bundle/focused-chunks/chunk-FK2X6MJY.js +0 -44
  178. package/dist/cli-bundle/focused-chunks/chunk-JRRHN2PZ.js +0 -12
  179. package/dist/cli-bundle/focused-chunks/chunk-LQZ5F6LE.js +0 -3
  180. package/dist/cli-bundle/focused-chunks/chunk-RMCODWHZ.js +0 -65
  181. package/dist/cli-bundle/focused-chunks/chunk-WVYXR3YX.js +0 -2
@@ -1,2 +1,2 @@
1
- import{ga as p,ha as i,ia as v,ja as _}from"./chunk-E4B2HWH7.js";import{Oa as h}from"./chunk-KSLPRST2.js";import u from"node:fs/promises";import c from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="846100a9-4314-5f7c-b892-fa16e09bee5b")}catch{}})();function f(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}function y(e){return e!=="invalid"&&e!=="unreadable"}function j(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw new SyntaxError("Invalid settings object");let r=t.extensions;if(r===void 0)return{enabled:[],disabled:[]};if(typeof r!="object"||r===null||Array.isArray(r))throw new SyntaxError("Invalid extensions settings");let n=r;if(n.enabled!==void 0&&(!Array.isArray(n.enabled)||!n.enabled.every(a=>typeof a=="string"))||n.disabled!==void 0&&(!Array.isArray(n.disabled)||!n.disabled.every(a=>typeof a=="string")))throw new SyntaxError("Invalid extension enablement lists");return{enabled:n.enabled??[],disabled:n.disabled??[]}}async function S(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{status:"absent",enabled:[],disabled:[]}:{status:"unreadable",enabled:[],disabled:[],error:{code:"settings_unreadable",path:e}}}try{return{status:"ok",...j(t)}}catch{return{status:"invalid",enabled:[],disabled:[],error:{code:"settings_invalid",path:e}}}}async function A(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){if(f(r))try{if((await u.stat(c.dirname(e))).isDirectory())return{status:"absent",entries:[]}}catch(n){if(f(n))return{status:"absent",entries:[]}}return{status:"unreadable",entries:[],error:{code:"managed_state_unreadable",path:e}}}try{let r=JSON.parse(t),n=_(r);if(!n||typeof r!="object"||r===null||!Array.isArray(r.entries)||n.entries.length!==r.entries.length)throw new SyntaxError("Invalid managed extension state");return{status:"ok",entries:n.entries}}catch{return{status:"invalid",entries:[],error:{code:"managed_state_invalid",path:e}}}}async function I(e){try{return{directories:(await u.readdir(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,r)=>t.localeCompare(r))}}catch(t){return f(t)?{directories:[]}:{directories:[],error:{code:"extensions_unreadable",path:e}}}}async function D(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{manifest:null,error:{code:"manifest_invalid",path:e}}:{manifest:null,error:{code:"manifest_unreadable",path:e}}}try{let r=v(JSON.parse(t));return r?{manifest:r}:{manifest:null,error:{code:"manifest_invalid",path:e}}}catch{return{manifest:null,error:{code:"manifest_invalid",path:e}}}}function M(e){let t=e.manifest?.name??e.directory,r=new Set(p(e.settings.enabled)),n=new Set(p(e.settings.disabled)),a=!y(e.settings.status)||!e.manifest?null:!n.has(t)&&(r.size===0||r.has(t)),o=y(e.managed.status)?e.managed.entries.some(d=>i(d.name)===i(t)||i(d.directory)===i(e.directory)):null;return{name:t,directory:e.directory,scope:e.scope,installed:!0,status:e.manifest?a===!1?"inactive":"installed":"malformed_manifest",configured_enabled:a,managed:o,runtime_active:null,...e.manifest?{version:e.manifest.version}:{}}}async function R(e){let t=e.scope??"project",r=t==="global"?h(e.cwd??process.cwd()):e.pmRoot,n=c.join(r,"extensions"),a=await S(c.join(r,"settings.json")),o=await A(c.join(n,".managed-extensions.json")),d=await I(n),l=[];for(let s of[a,o,d])s.error&&l.push(s.error);let m=e.name?.trim(),b=[];for(let s of d.directories){let x=c.join(n,s,"manifest.json"),g=await D(x);g.error&&l.push(g.error);let w=M({directory:s,scope:t,manifest:g.manifest,settings:a,managed:o});m&&![w.name,s].some(E=>i(E)===i(m))||b.push(w)}return m&&b.length===0&&l.every(s=>s.code!=="extensions_unreadable")&&b.push({name:m,directory:null,scope:t,installed:!1,status:"absent",configured_enabled:y(a.status)?!1:null,managed:y(o.status)?!1:null,runtime_active:null}),{scope:t,complete:l.length===0,settings_status:a.status,managed_state_status:o.status,extensions:b,errors:l}}export{R as a};
2
- //# sourceMappingURL=chunk-7AODVNHX.js.map
1
+ import{ga as p,ha as i,ia as v,ja as _}from"./chunk-FZ4XWWLO.js";import{Oa as h}from"./chunk-E4BQRZF2.js";import u from"node:fs/promises";import c from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="846100a9-4314-5f7c-b892-fa16e09bee5b")}catch{}})();function f(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}function y(e){return e!=="invalid"&&e!=="unreadable"}function j(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw new SyntaxError("Invalid settings object");let r=t.extensions;if(r===void 0)return{enabled:[],disabled:[]};if(typeof r!="object"||r===null||Array.isArray(r))throw new SyntaxError("Invalid extensions settings");let n=r;if(n.enabled!==void 0&&(!Array.isArray(n.enabled)||!n.enabled.every(a=>typeof a=="string"))||n.disabled!==void 0&&(!Array.isArray(n.disabled)||!n.disabled.every(a=>typeof a=="string")))throw new SyntaxError("Invalid extension enablement lists");return{enabled:n.enabled??[],disabled:n.disabled??[]}}async function S(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{status:"absent",enabled:[],disabled:[]}:{status:"unreadable",enabled:[],disabled:[],error:{code:"settings_unreadable",path:e}}}try{return{status:"ok",...j(t)}}catch{return{status:"invalid",enabled:[],disabled:[],error:{code:"settings_invalid",path:e}}}}async function A(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){if(f(r))try{if((await u.stat(c.dirname(e))).isDirectory())return{status:"absent",entries:[]}}catch(n){if(f(n))return{status:"absent",entries:[]}}return{status:"unreadable",entries:[],error:{code:"managed_state_unreadable",path:e}}}try{let r=JSON.parse(t),n=_(r);if(!n||typeof r!="object"||r===null||!Array.isArray(r.entries)||n.entries.length!==r.entries.length)throw new SyntaxError("Invalid managed extension state");return{status:"ok",entries:n.entries}}catch{return{status:"invalid",entries:[],error:{code:"managed_state_invalid",path:e}}}}async function I(e){try{return{directories:(await u.readdir(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,r)=>t.localeCompare(r))}}catch(t){return f(t)?{directories:[]}:{directories:[],error:{code:"extensions_unreadable",path:e}}}}async function D(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{manifest:null,error:{code:"manifest_invalid",path:e}}:{manifest:null,error:{code:"manifest_unreadable",path:e}}}try{let r=v(JSON.parse(t));return r?{manifest:r}:{manifest:null,error:{code:"manifest_invalid",path:e}}}catch{return{manifest:null,error:{code:"manifest_invalid",path:e}}}}function M(e){let t=e.manifest?.name??e.directory,r=new Set(p(e.settings.enabled)),n=new Set(p(e.settings.disabled)),a=!y(e.settings.status)||!e.manifest?null:!n.has(t)&&(r.size===0||r.has(t)),o=y(e.managed.status)?e.managed.entries.some(d=>i(d.name)===i(t)||i(d.directory)===i(e.directory)):null;return{name:t,directory:e.directory,scope:e.scope,installed:!0,status:e.manifest?a===!1?"inactive":"installed":"malformed_manifest",configured_enabled:a,managed:o,runtime_active:null,...e.manifest?{version:e.manifest.version}:{}}}async function R(e){let t=e.scope??"project",r=t==="global"?h(e.cwd??process.cwd()):e.pmRoot,n=c.join(r,"extensions"),a=await S(c.join(r,"settings.json")),o=await A(c.join(n,".managed-extensions.json")),d=await I(n),l=[];for(let s of[a,o,d])s.error&&l.push(s.error);let m=e.name?.trim(),b=[];for(let s of d.directories){let x=c.join(n,s,"manifest.json"),g=await D(x);g.error&&l.push(g.error);let w=M({directory:s,scope:t,manifest:g.manifest,settings:a,managed:o});m&&![w.name,s].some(E=>i(E)===i(m))||b.push(w)}return m&&b.length===0&&l.every(s=>s.code!=="extensions_unreadable")&&b.push({name:m,directory:null,scope:t,installed:!1,status:"absent",configured_enabled:y(a.status)?!1:null,managed:y(o.status)?!1:null,runtime_active:null}),{scope:t,complete:l.length===0,settings_status:a.status,managed_state_status:o.status,extensions:b,errors:l}}export{R as a};
2
+ //# sourceMappingURL=chunk-I3T2FVUA.js.map
@@ -1,2 +1,2 @@
1
- import{$a as ne,Ub as Ze,Vb as Qe,Xb as re,_b as et,a as We,ac as tt,bc as nt,xc as rt}from"./chunk-VWKLTHYQ.js";import{u as Xe}from"./chunk-E74OMFBZ.js";import{tc as He}from"./chunk-IXV5UM4U.js";import{m as Ye}from"./chunk-S5UXBECQ.js";import{b as U,c as ee,d as Je,e as te,f as ze}from"./chunk-E4B2HWH7.js";import{ra as Be,wb as j,xa as Ve,zb as D}from"./chunk-ASGAELBQ.js";import{Lb as Ke,Mc as Le,Va as Q,d as Oe,gb as N,ia as Pe,ka as C,t as Ae,u as Te,v as z}from"./chunk-NAX554KY.js";import{B as E,I as X,Md as Ge,Qd as xe,X as Fe,Xd as qe,dd as I,id as Z,r as Ue,t as H,u as je,va as T,x as De}from"./chunk-KLWGIEDC.js";import{De as Ce,Ea as V,Ee as Ne,Id as Re,Na as ke,Zb as Me,a as Ee,qe as Ie,re as Y}from"./chunk-KSLPRST2.js";import{A as p,C as u,G as B,I as $e,J as M,l as _e,q as k,t as Se,y as be}from"./chunk-LC6DL446.js";import pe from"node:crypto";import{constants as ce}from"node:fs";import{cp as Sn,lstat as At,mkdir as bn,mkdtemp as Tt,open as En,readdir as On,realpath as $t,rm as kt,stat as le,writeFile as Mt}from"node:fs/promises";import{tmpdir as Rt}from"node:os";import m from"node:path";import ft from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="01728cbc-2037-50d2-8318-5f106714b8da")}catch{}})();var O=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",..._e,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function it(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return O.has(t)?t:e}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="6456f85b-e076-5048-9c21-03d477267259")}catch{}})();function F(e,t,n){let r=e?.estimatedMinutes;if(!(r===void 0||typeof r=="string"))throw new u(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,p.USAGE,{code:"mutation_option_value_invalid",required:'Pass estimatedMinutes as a string, for example "45", in raw mutation options.',why:"Raw options use the create/update command option types; item documents accept numeric estimated_minutes instead.",nextSteps:["Quote the estimatedMinutes value or use an item document with numeric estimated_minutes, then retry the transaction."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="37abb7b8-a5c3-5bdd-ad3a-9dc5189e834f")}catch{}})();var ie=["op","id","reason","options","unique","match"],Pt=[...ie,"ref"],ot=[...Pt,"item"],Gt="mutate-",at="row-",st=["schema_version","mutations"],ht="[a-z][a-z0-9._-]{0,63}",ct=new RegExp(`^${ht}$`,"u"),yt=new RegExp(`(^|,)id=@(${ht})(?=,|$)`,"gu"),dt=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),P=["item","item_hash","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],wt=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count","pm_format_version","claim_principal","test_runs","deferred_fields"]),xt=new Set([...wt,"completed_at","id"]),gt={create:j.map(e=>e.target),update:D.map(e=>e.target),close:Be.map(e=>dt(e.flag)).filter(e=>e!=="reason"),release:Ve.map(e=>dt(e.flag))};function pr(e){let t=ft.createHash("sha256").update(e).digest("hex");return`${Gt}${t.slice(0,24)}`}function lr(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new u("createCompensation must be close or delete.",p.USAGE);t.createCompensation=n}for(let r of["lockTtlSeconds","lockWaitMs"]){let i=e[r];if(i===void 0)continue;let o=typeof i=="number"||typeof i=="string"&&i.trim().length>0?Number(i):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new u(`${r} must be a positive safe integer.`,p.USAGE);t[r]=o}return t}function w(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function G(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=Me(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function A(e,t,n){let r=G(t,n);return new u(r===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${r}"?`,p.USAGE,{code:"stdin_json_unknown_key",required:`Use documented ${e} keys only.`,why:"Strict structured input prevents silent typos from creating incomplete or unintended mutations.",nextSteps:[r===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${r}".`]})}function se(e,t){try{return JSON.parse(e)}catch(n){let r=n instanceof Error?n.message:String(n);throw new u(`${t} must be valid JSON: ${r}`,p.USAGE,{code:"stdin_json_invalid",required:`Pipe one valid JSON ${t.toLowerCase()} into stdin.`,why:"Structured mutation input must parse deterministically before any tracker write begins."})}}function qt(e,t){if(!w(e))throw new u(`Mutation ${t+1} must be an object.`,p.USAGE);for(let n of Object.keys(e))if(!ie.includes(n))throw A(`mutation ${t+1}`,n,ie);return e}function Kt(e,t,n,r){if(e===void 0)return;if(!w(e))throw new u(`Mutation ${n+1} options must be an object.`,p.USAGE);let i=[...gt[t],...St(t,r)];for(let o of Object.keys(e))if(!i.includes(o))throw A(`mutation ${n+1} ${t} options`,o,i);return F(e,t,n),e}function ut(e,t,n,r){if(e===void 0)return;let i=r==="unique"?"create":"update";if(t!==i)throw new u(`Mutation ${n+1} ${r} is only valid for ${i} operations.`,p.USAGE);let o=w(e)&&typeof e.key=="string"?e.key.trim():"";if(!w(e)||o.length===0||e.value===void 0||e.value===null)throw new u(`Mutation ${n+1} ${r} must be an object with a non-empty key and a value.`,p.USAGE);return{key:o,value:e.value}}function Lt(e,t,n){let r=qt(e,t),{op:i,id:o,reason:a}=r;if(i!=="create"&&i!=="update"&&i!=="close"&&i!=="release")throw new u(`Mutation ${t+1} op must be create, update, close, or release.`,p.USAGE);let s=Kt(r.options,i,t,n),c=ut(r.unique,i,t,"unique"),d=ut(r.match,i,t,"match");if(typeof o!="string"||o.trim().length===0)throw new u(`Mutation ${t+1} requires a non-empty id.`,p.USAGE);let l=o.trim();if(i==="close"){if(typeof a!="string"||a.trim().length===0)throw new u(`Mutation ${t+1} close requires a non-empty reason.`,p.USAGE);return{op:i,id:l,reason:a.trim(),...s===void 0?{}:{options:s}}}if(i==="release")return{op:i,id:l,...s===void 0?{}:{options:s}};if(!w(s))throw new u(`Mutation ${t+1} ${i} requires an options object.`,p.USAGE);return{op:i,id:l,options:s,...c===void 0?{}:{unique:c},...d===void 0?{}:{match:d}}}function vt(e,t={}){let n=se(e,"Mutation batch"),r=Array.isArray(n)?n:w(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(r===void 0||r.length===0)throw new u("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",p.USAGE);let i=t.runtimeFields??[];return r.map((o,a)=>{let s=Lt(o,a,i);return s.options!==void 0&&Ae(s.options),s})}function Wt(e,t,n){let r=ft.createHash("sha256").update(e).update("\0").update(t).digest("hex"),i=BigInt(`0x${r.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Pe(n)}${i}`}function pt(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),r=t[n];if(r===void 0)throw new u(`Unknown mutation reference "${e}".`,p.USAGE);return r}function lt(e,t){if(typeof e!="string")return e;let n=e.replace(yt,(r,i,o)=>{let a=t[o];if(a===void 0)throw new u(`Unknown mutation reference "@${o}".`,p.USAGE);return`${i}id=${a}`});if(/(^|,)id=@/u.test(n))throw new u(`Malformed mutation reference in dependency "${e}".`,p.USAGE);return n}function Jt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(yt)].map(t=>t[1]).filter(t=>t!==void 0)}function zt(e,t){let n=new Map;for(let[a,s]of e.entries()){let c=t[a];if(c===void 0)continue;let d=w(s.options)?s.options:{},l=Array.isArray(d.dep)?d.dep:d.dep===void 0?[]:[d.dep];n.set(c,[d.parent,d.blockedBy,...l].flatMap(Jt))}let r=new Set,i=new Set,o=a=>{if(r.has(a))throw new u(`Mutation reference cycle includes "@${a}".`,p.USAGE);if(!i.has(a)){r.add(a);for(let s of n.get(a))n.has(s)&&o(s);r.delete(a),i.add(a)}};for(let a of n.keys())o(a)}function Bt(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),r=n[0];if(!r.ok&&(r.line.startsWith("[")||r.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&w(o.value)))return null;let i=[];for(let o of n){if(!o.ok)throw new u(`Mutation document line ${o.number} must be one valid JSON object: ${Le(o.error)}`,p.USAGE,{code:"stdin_json_invalid",required:"Provide one JSON object per line (JSON Lines), a JSON array, or a {schema_version, mutations} document.",why:"Structured mutation input must parse deterministically before any tracker write begins."});if(!w(o.value))throw new u(`Mutation document line ${o.number} must be a JSON object.`,p.USAGE);i.push(o.value)}return i}function Vt(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Yt(e){let t;try{t=se(e,"Mutation document")}catch(n){let r=Bt(e);if(r===null)throw n;return{schema_version:1,mutations:r}}return Array.isArray(t)?{schema_version:1,mutations:t}:w(t)&&!Vt(t)?{schema_version:1,mutations:[t]}:t}function Ht(e,t){let n=Object.hasOwn(e,"op")?Xt(e,t):Zt(e,t);if(n.op==="create"&&n.id===void 0&&w(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new u(`Mutation ${t+1} item id must be a string.`,p.USAGE);n.id=n.item.id}return n}function Xt(e,t){for(let n of Object.keys(e))if(!ot.includes(n))throw A(`mutation ${t+1}`,n,ot);if(e.item!==void 0&&e.op!=="create")throw new u(`Mutation ${t+1} item documents are only valid for create operations.`,p.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new u(`Mutation ${t+1} must declare either item or options, not both.`,p.USAGE);return{...e}}function Zt(e,t){let{ref:n,id:r,item:i,...o}=e,a=i!==void 0?i:o;if(i!==void 0&&Object.keys(o).length>0)throw new u(`Mutation ${t+1} must not mix item document keys with top-level fields.`,p.USAGE);if(!w(a))throw new u(`Mutation ${t+1} item document must be an object.`,p.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...r===void 0?{}:{id:r},item:a}}function Qt(e){let t=Yt(e);if(!w(t))throw new u("Mutation document must be a JSON array or object.",p.USAGE);for(let n of Object.keys(t))if(!st.includes(n))throw A("mutation document",n,st);if(t.schema_version!==void 0&&t.schema_version!==1)throw new u("Mutation document schema_version must be 1.",p.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new u("Mutation document requires a non-empty mutations array.",p.USAGE);return t.mutations.map((n,r)=>{if(!w(n))throw new u(`Mutation ${r+1} must be an object.`,p.USAGE);return Ht(n,r)})}function en(e,t,n){let r=new Set(Object.values(Et(t,n,Object.create(null))));for(let i of t)i.op==="create"&&typeof i.id=="string"&&i.id.trim().length>0&&r.add(C(i.id,n.idPrefix));return{...e,existing:e.existing.filter(i=>!r.has(i.id))}}function tn(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,r]of e.entries()){if(r.op!=="create"||r.ref!==void 0||typeof r.id=="string"&&r.id.trim().length>0)continue;let i=`${at}${n+1}`;if(t.has(i))throw new u(`Mutation ${n+1} receives the synthesized ref "${i}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${at}<n> aliases are reserved for rows without one.`,p.USAGE);r.ref=i}}function _t(e,t,n){let r=_n(JSON.stringify(e),t,{},n);return delete r.stdinJson,delete r.documentAnnotationSnapshot,r}function St(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>E(n))}function nn(e,t){for(let n of e)w(n.item)&&(n.options=_t(n.item,"create",t),delete n.item)}function bt(e,t){return t.some(n=>n.metadata_key===e)?e:it(e)}function oe(e,t,n){let r=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(w(e.item)){if(e.item[t]!==void 0)return e.item[t];if(bt(r,n)===t&&e.item[r]!==void 0)return e.item[r]}let i=w(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&i[E(o)]!==void 0?i[E(o)]:i[t]!==void 0?i[t]:i[r]!==void 0?i[r]:(Array.isArray(i.field)?i.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function rn(e,t){return e<t?-1:+(e!==t)}function ae(e){return Array.isArray(e)?e.map(ae):w(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>rn(t,n)).map(([t,n])=>[t,ae(n)])):e}function _(e){return typeof e=="string"?e.trim():JSON.stringify(ae(e))}function on(e,t,n,r,i){let o=t.key.trim();if(o.length===0)throw new u("Upsert key must be a non-empty field name.",p.USAGE);let a=an(t.existing),s=new Map,c=new Set;for(let[d,l]of e.entries()){if(l.op!=="create")continue;let f=sn(l,o,d,s,r),y=cn(a.get(f)??[],o,f);if(y===void 0){l.unique={key:o,value:oe(l,o,r)};continue}let h=C(y,n);typeof l.ref=="string"&&(i[l.ref]=h),dn(l,h,r,{key:o,value:oe(l,o,r)}),c.add(d)}return c}function an(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let r=_(n.value);t.set(r,[...t.get(r)??[],n.id])}return t}function sn(e,t,n,r,i){let o=oe(e,t,i);if(o==null||o==="")throw new u(`Mutation ${n+1} is missing the upsert key "${t}".`,p.USAGE,{code:"upsert_key_missing",required:`Every create record must carry a non-empty "${t}" value when --upsert-key ${t} is set.`,why:"Keyed upsert identifies existing items by that field; a record without it cannot be matched or safely created."});let a=_(o),s=r.get(a);if(s!==void 0)throw new u(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,p.USAGE,{code:"upsert_key_duplicate",required:"Each record must carry a distinct upsert key value within one batch.",why:"Two records with the same key would race for the same existing item."});return r.set(a,n),a}function cn(e,t,n){if(e.length>1)throw new u(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,p.CONFLICT,{code:"upsert_key_ambiguous",required:"Resolve the duplicate existing items or choose a key that is unique per item.",why:"An ambiguous key cannot select one item to update without guessing."});return e[0]}function dn(e,t,n,r){let i=new Set([...gt.update,...St("update",n)]),o=w(e.item)?_t(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>i.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=r}function Et(e,t,n){for(let[r,i]of e.entries())if(i.ref!==void 0){if(i.op!=="create")throw new u(`Mutation ${r+1} ref is only valid for create operations.`,p.USAGE);if(typeof i.ref!="string"||!ct.test(i.ref))throw new u(`Mutation ${r+1} ref must match ${ct.source}.`,p.USAGE);if(n[i.ref]!==void 0)throw new u(`Duplicate mutation ref "${i.ref}".`,p.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?C(i.id,t.idPrefix):Wt(t.transactionId,i.ref,t.idPrefix)}return n}function mr(e,t){let n=Qt(e);tn(n);let r=n.map(l=>typeof l.ref=="string"?l.ref:void 0),i=Object.create(null),o=t.upsert===void 0?new Set:on(n,en(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],i);nn(n,t.runtimeFields??[]),Et(n,t,i),zt(n,r);let a=n.map(l=>{let f={...l},y=typeof f.ref=="string"?f.ref:void 0;if(delete f.ref,y!==void 0?f.id=i[y]:f.id=pt(f.id,i),w(f.options)){let h={...f.options};for(let g of["parent","blockedBy"])h[g]!==void 0&&(h[g]=pt(h[g],i));Array.isArray(h.dep)?h.dep=h.dep.map(g=>lt(g,i)):h.dep!==void 0&&(h.dep=lt(h.dep,i)),f.options=h}return f}),s=vt(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),c=s.filter(l=>l.op==="create").map(l=>l.id);if(new Set(c).size!==c.length)throw new u("Duplicate resolved create id in mutation document.",p.USAGE);let d=s.map((l,f)=>{let y=r[f];return{index:f,...typeof y=="string"?{ref:y}:{},id:l.id,op:l.op,...o.has(f)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:i,rows:d}}function un(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let r=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(r)?JSON.stringify(r):r}`}).join(",")}function pn(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(w))throw new u(`${n} must be an array of objects.`,p.USAGE);return e.map(r=>un(r,t))}}function ln(e,t){return e==="tags"&&Array.isArray(t)&&t.every(n=>typeof n=="string")?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"?String(t):t}function mt(e,t,n=!1){for(let[r,i,o]of He){let a=t[r],s=pn(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(a)?a.filter(c=>!w(c)||c.created_at===void 0):a,o,r);s!==void 0&&s.length>0&&(e[i]=s)}}function mn(e,t){for(let n of Object.keys(e)){if(t){if(!P.includes(n))throw A("item envelope",n,P);continue}if(!O.has(n)&&G(n,[...O])===void 0&&G(n,P)==="item")throw A("item envelope",n,P)}}function fn(e){let t=Object.hasOwn(e,"item");mn(e,t);let n=t?e.item:e;if(!w(n))throw new u("Item document item must be an object.",p.USAGE);return{item:n,...t&&w(e.linked)?{linked:e.linked}:{}}}function hn(e,t,n,r,i,o){if((r==="update"?xt:wt).has(t))return;let a=i.find(s=>s.metadata_key===t&&s.commands.includes(r));if(a!==void 0){let s=X(o,a);e[E(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!O.has(t)){if(G(t,[...O])!==void 0)throw A("item document",t,[...O]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,c)=>c.toUpperCase())]=ln(t,n))}function yn(e){return{command_to_fields:new Map([["create",e.filter(t=>t.commands.includes("create"))]])}}function wn(e,t,n,r){let i=r.filter(d=>d.commands.includes("create")),o=new Set([...Fe.filter(d=>t.has(d.option)).map(d=>d.field),...i.filter(d=>t.has(E(d))).map(d=>d.metadata_key),...Ye(Array.isArray(n)?n.map(String):[],yn(i)).metadataKeys]),a=(Array.isArray(e)?e:[]).filter(w).filter(d=>typeof d.field=="string"&&!o.has(d.field));if(a.length===0)return{};let s=a.map(d=>typeof d.reason=="string"?d.reason.trim():""),c=a.map(d=>d.field);return t.has("deferReason")?{defer:c}:s.every(d=>d.length>0)?{defer:c,deferReason:[...new Set(s)].join("; ")}:{defer:c}}function gn(e,t,n){let r=new Set(Object.entries(e).filter(([,o])=>o!==void 0).map(([o])=>o)),i=t==="create"?j:D;for(let{target:o,keys:a}of i)a.some(s=>r.has(s))&&r.add(o);for(let o of n.filter(a=>a.commands.includes(t)))X(e,o)!==void 0&&r.add(E(o));return r}function vn(e,t,n){let r=t==="create"?j:D;for(let{target:i}of r)i!=="field"&&n.has(i)&&delete e[i]}function _n(e,t,n={},r=[]){let i=se(e,"Item document");if(!w(i))throw new u("Item document must be a JSON object.",p.USAGE);let{item:o,linked:a}=fn(i),s={};for(let[f,y]of Object.entries(o)){let h=bt(f,r);h!==f&&Object.hasOwn(o,h)||hn(s,h,y,t,r,n)}mt(s,o,t==="update"),a!==void 0&&mt(s,a);let c=gn(n,t,r);if(vn(s,t,c),t==="create"&&!c.has("defer")&&Object.assign(s,wn(o.deferred_fields,c,n.unset,r)),t==="update"){let f=Object.fromEntries(["comments","notes","learnings"].filter(y=>Object.hasOwn(o,y)&&!c.has(y.slice(0,-1))).map(y=>[y,o[y].filter(h=>w(h)&&h.created_at!==void 0)]));Object.keys(f).length>0&&(s.documentAnnotationSnapshot=f)}let d={...s,...Object.fromEntries(Object.entries(n).filter(([,f])=>f!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0},l=Object.keys(s).filter(f=>!c.has(f));return Te(Oe(d,l),l)}function fr(e){return vt(JSON.stringify(e))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="5bde03cb-def4-549f-89d5-6822bd2235e6")}catch{}})();async function An(e,t){if(!xe(e))return{schema:H(t.schema),typeDefinitionsFromFile:[]};let n=await Fn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function Tn(e,t,n,r){let i=V({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},Y());return(await Ke(e,t.item_format,i.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[r];return a==null?[]:[{id:o.id,value:a}]})}function me(e){let t=new Map,n=async r=>{let i=await qe(e),o=await An(e,i),a=new Map;for(let s of await Tn(e,i,o,r)){let c=_(s.value);a.set(c,[...a.get(c)??[],s.id])}return a};return{lookup(r){let i=t.get(r)??n(r);return t.set(r,i),i},async recordCreate(r){for(let[i,o]of t){let a=r[i];if(a==null)continue;let s=await o,c=_(a);s.set(c,[...s.get(c)??[],String(r.id)])}},invalidate(){t.clear()}}}async function $n(e,t){let n=_(t.value),r=(await e.lookup(t.key)).get(n)??[];if(r.length!==0)throw new u(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${r.join(", ")}; the plan was resolved before it existed.`,p.CONFLICT,{code:"upsert_key_conflict",required:"Re-plan the document so the row updates the existing item instead of creating a duplicate.",why:"Keyed upsert is resolved before the writer lock, so every remaining create is re-checked under the lock; concurrent imports therefore cannot create two items for one key value.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan turns the row into an update of the existing item.","Inspect the existing item first when its content should win over the document row."]})}function kn(e,t,n){let r=e.metadata[n.key],i=_(n.value);if(_(r)!==i)throw new u(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(i)}; the plan selected it before the key changed.`,p.CONFLICT,{code:"upsert_match_changed",required:"Re-plan the document so the row is resolved against the current key values.",why:"Keyed upsert selects its target before the writer lock, so the update re-reads the key under the lock instead of updating a mismatched item blindly.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan creates or re-targets the row from the current key values."]})}function Ot(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=e;return typeof t.key=="string"&&t.key.trim().length>0&&t.value!==void 0&&t.value!==null}function L(e,t){let n={...e,...t};return e===void 0?n:z(e,n)}async function b(e,t){try{let n=(await ne(t,{},{pmRoot:e})).item;return{id:n.id,closedAt:n.closed_at,updatedAt:n.updated_at,assignee:n.assignee,claimPrincipal:n.claim_principal}}catch(n){if(n instanceof u&&n.exitCode===p.NOT_FOUND)return;throw n}}function fe(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=pe.createHash("sha256").update(Ee(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function Mn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function v(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}function he(e,t){return e===t||(e?.startsWith(`${t} | `)??!1)}async function R(e,t,n,r){let i=await T(m.join(e,"history",`${t}.jsonl`),t),o=v(n,r,"apply"),a=v(n,r,"compensate");for(let s=i.length-1;s>=0;s-=1){let c=i[s].message;if(he(c,o))return!0;if(c===a)return!1}return!1}async function ye(e,t){let n=await b(e,t.id);if(n?.updatedAt===void 0)throw new u(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,p.NOT_FOUND);let r=await T(m.join(e,"history",`${n.id}.jsonl`),n.id);if(r.length===0)throw new u(`Bulk ${t.op} target ${t.id} has no restorable history`,p.NOT_FOUND);return{target_updated_at:n.updatedAt,target_version:String(Q(r)+r.length),target_history_hash:I(r),target_history_length:r.length}}function $(e,t,n){return new u(`Transaction ${e.transactionId} cannot safely compensate incomplete step ${n}; review item ${t} history before recovery.`,p.CONFLICT,{code:"transaction_partial_mutation",item_id:t,required:"Reconcile the item's partial or intervening changes before resuming this transaction.",why:"The retained history does not prove exclusive ownership of the changes to undo. The journal remains compensating instead of claiming a rollback or overwriting another writer.",nextSteps:[`Run pm history ${t} and inspect this transaction's retained compensation data before explicitly restoring or reconciling the item.`]})}function It(e,t){let n=`bulk-item-transaction ${t} `;return[e.message,e.context?.item_transaction_step].some(r=>typeof r=="string"&&r.startsWith(n))}function Rn(e,t,n){let{expectedHistory:r,length:i,version:o}=t;if(I(e)===r)return!1;if(typeof i!="number"||!Number.isSafeInteger(i)||i<1||I(e.slice(0,i))!==r||o!==String(Q(e)+i))throw $(n,n.itemId,n.stepId);let a=v(n.transactionId,n.stepId,"apply"),s=e.slice(i),c=y=>he(y.message,a)||y.context?.item_transaction_step===a,d=v(n.transactionId,n.stepId,"compensate");if(s.filter(y=>c(y)||y.message===d).at(-1)?.message===d)return!1;let l=s.filter(c);if(l.length===0)return!1;let f=e.at(-1).after_hash===l.at(-1).after_hash&&s.every(y=>It(y,n.transactionId));if(l.length!==s.length&&!f)throw $(n,n.itemId,n.stepId);return!0}async function W(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;if(i===void 0||typeof i.target_updated_at!="string")return;let o=i.target_updated_at,a=await b(e.pmRoot,t);if(a===void 0)return;let s=await T(m.join(e.pmRoot,"history",`${a.id}.jsonl`),a.id),c=i.target_history_hash;if(typeof c=="string"){if(!Rn(s,{expectedHistory:c,length:i.target_history_length,version:i.target_version},{...e,itemId:a.id,stepId:n}))return}else{if(a.updatedAt===o)return;if(!await R(e.pmRoot,a.id,e.transactionId,n))throw $(e,a.id,n)}let d=()=>nt(t,typeof i.target_version=="string"?i.target_version:o,{force:!0,author:e.author,message:v(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot});await N({pmRoot:e.pmRoot,id:a.id,validate:l=>{if(Z(l)!==s.at(-1).after_hash)throw $(e,a.id,n)}},d)}function Ct(e,t,n){return{id:n,async inspect(){let r=await b(e.pmRoot,t.id);if(r===void 0)return{state:"pending"};if(r.closedAt!==void 0){let i=await T(m.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(i.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new u(`Created item ${r.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,p.CONFLICT,{code:"transaction_create_compensated",item_id:r.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${r.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:r.id,op:"create"}}},async apply(){t.unique!==void 0&&await $n(e.uniqueIndex,t.unique);let r=await Ze(L(t.options,{author:e.author,id:t.id,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=r.item;return e.onCreateWarnings?.(String(i.id),r.warnings),await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){await In(e,t.id,n)}}}async function In(e,t,n){let r=await b(e.pmRoot,t);if(r===void 0||e.createCompensation==="close"&&r.closedAt!==void 0)return;let i=await T(m.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=v(e.transactionId,n,"apply"),a=v(e.transactionId,n,"compensate"),s=i.filter(c=>he(c.message,o)||c.message===a).at(-1);if(s?.message!==a){if(s===void 0||!i.every(c=>It(c,e.transactionId)))throw $(e,r.id,n);await N({pmRoot:e.pmRoot,id:r.id,validate:c=>{if(Z(c)!==i.at(-1).after_hash)throw $(e,r.id,n)}},async()=>{let c={force:!0,author:e.author,message:a};e.createCompensation==="delete"?await tt(t,c,{pmRoot:e.pmRoot}):await re(t,`Compensated: interrupted bulk transaction ${e.transactionId}`,{...c,validateClose:"off"},{pmRoot:e.pmRoot})})}}function Cn(e,t,n){return{id:n,compensatePending:!0,async inspect(){let r=await b(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return ye(e.pmRoot,t)},async apply(){let r=()=>Qe(t.id,L(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=t.match,o=i,a=(await N({pmRoot:e.pmRoot,id:String((await ne(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:s=>{o!==void 0&&kn(s,t.id,o)},committed:s=>{i!==void 0&&(o={key:i.key,value:structuredClone(s.metadata[i.key])})},historyContext:{item_transaction_step:v(e.transactionId,n,"apply")}},r)).item;return e.uniqueIndex.invalidate(),{id:String(a.id),op:"update"}},async compensate(r){await W(e,t.id,n,r)}}}function Nn(e,t,n){return{id:n,async inspect(){let r=await b(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"close"}}:r.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"close"}}},async prepareCompensation(){return ye(e.pmRoot,t)},async apply(){let r=(await re(t.id,t.reason,L(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"close"}},async compensate(r){await W(e,t.id,n,r)}}}function Un(e,t,n){return{id:n,async inspect(){let r=await b(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"release"}}:r.assignee!==void 0||r.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"release"}}},async prepareCompensation(){return ye(e.pmRoot,t)},async apply(){let r=(await et(t.id,L(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"release"}},async compensate(r){await W(e,t.id,n,r)}}}function we(e,t,n){let r=fe(t,n);switch(t.op){case"create":return Ct(e,t,r);case"update":return Cn(e,t,r);case"close":return Nn(e,t,r);case"release":return Un(e,t,r)}}function jn(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`Bulk mutation ${t+1} must be an object`);if(!["create","update","close","release"].includes(e.op))throw new TypeError(`Bulk mutation ${t+1} op must be create, update, close, or release`);if(typeof e.id!="string"||e.id.trim().length===0)throw new TypeError(`Bulk mutation ${t+1} requires a non-empty id`);if(e.op==="close"&&(typeof e.reason!="string"||e.reason.trim().length===0))throw new TypeError(`Bulk close mutation ${t+1} requires a non-empty reason`);if(e.op==="create"&&e.unique!==void 0&&!Ot(e.unique))throw new TypeError(`Bulk create mutation ${t+1} unique must be an object with a non-empty key and a value`);if(e.op==="update"&&e.match!==void 0&&!Ot(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);F(e.options,e.op,t)}function Nt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,r]of e.entries()){if(jn(r,n),r.op!=="create"||r.unique===void 0)continue;let{key:i,value:o}=r.unique,a=t.get(i)??new Map,s=_(o),c=a.get(s);if(c!==void 0)throw new u(`Bulk create mutations ${c+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${i}".`,p.USAGE,{code:"upsert_key_duplicate",required:"Each create must carry a distinct unique key value within one batch.",why:"Direct SDK batches must preserve the same uniqueness invariant as planned document rows."});a.set(s,n),t.set(i,a)}}function Ut(e){let t=[...e];return Nt(t),t.map(n=>{let r=structuredClone(n);return n.options!==void 0&&r.options!==void 0&&z(n.options,r.options),r})}function jt(e,t=""){return e===null||typeof e!="object"?[]:Object.entries(e).flatMap(([n,r])=>{let i=`${t}/${n.replaceAll("~","~0").replaceAll("/","~1")}`;return/^(created_at|updated_at|closed_at|completed_at|timestamp)$/u.test(n)?[i]:jt(r,i)})}async function de(e,t,n){try{return await n()}catch(r){throw r instanceof u?new u(r.message,r.exitCode,{...r.context,transaction_operation:{index:t,op:e.op,id:e.id}}):r}}function Dt(e,t,n,r){let i=m.relative(e,t),o=i.split(m.sep);return o[0]==="extensions"&&o[2]==="node_modules"&&!r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))?!1:["locks","runtime","search"].includes(i.split(m.sep)[0])?r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`)):i===""||n===void 0||n.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))}async function q(e,t){let n=await At(t);if(n.isSymbolicLink())await le(t);else if(n.isDirectory()||n.isFile())return n;throw M(m.relative(e,t))}async function Dn(e,t){let n=await En(t,ce.O_RDONLY|ce.O_NOFOLLOW|ce.O_NONBLOCK);try{let r=await n.stat();if(!r.isFile())throw M(m.relative(e,t));let i=pe.createHash("sha256");if(r.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:r.size-1,autoClose:!1}))i.update(o);return i.digest()}finally{await n.close()}}async function ue(e,t,n){let r=pe.createHash("sha256");async function i(o){for(let a of(await On(o)).sort()){let s=m.join(o,a);Dt(e,s,t,n)&&((await q(e,s)).isDirectory()?await i(s):(r.update(JSON.stringify(m.relative(e,s))),r.update(await Dn(e,s))))}}return await i(e),r.digest("hex")}function x(){return new u("Tracker changed while preparing the transaction preview; retry against stable state.",p.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ge(e){if(!B(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),r=n;for(;;)try{let i=await At(r);return r!==n&&i.isDirectory()}catch(i){if(!B(i))return!1;let o=m.dirname(r);if(o===r)return!1;r=o}}async function K(e,t){let n=m.join(e,t);try{let r=e;for(let i of t.split(m.sep).slice(0,-1))r=m.join(r,i),await q(e,r);if(!(await q(e,n)).isFile())throw M(t);return await $e(n,M(t))}catch(r){if(await ge(r))return;throw r}}async function Ft(e,t,n,r){let i=H(n);for(let[o,a]of Object.entries(i.files)){let s=m.relative(e,je(e,a,Ue[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new u("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",p.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});i.files[o]=s;let c=await K(e,s);if(r?.set(s,c),c!==void 0){let d=m.join(t,s);await bn(m.dirname(d),{recursive:!0}),await Mt(d,c)}}return De(t,i)}async function Fn(e,t){await le(e);let n=await Tt(m.join(Rt(),"pm-schema-plan-"));try{let r=await $t(e);return await Ft(r,m.join(n,"configuration"),t)}catch(r){throw await ge(r)?x():r}finally{await kt(n,{recursive:!0,force:!0})}}async function Pn(e,t,n){let r=new Map,i=await K(e,k);r.set(k,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let a=Ge(o),s=a.success?a.data:void 0,c=await Ft(e,t,s?.schema,r),d=c.schema,l=m.relative(e,Re(e));r.set(l,await K(e,l));let f=V({...be,item_types:{definitions:[...s?.item_types?.definitions??[],...c.type_definitions_from_file??[]]}},n),y=ke(e)===e?[...Se.filter(Boolean),k,We,"transactions",...f.folders,...r.keys()].map(g=>m.normalize(g)):void 0,h=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:d.files}});return{configuration:r,ownedPaths:y,stagedSettings:h,registryFolders:f.folders}}async function Gn(e,t,n){await le(e);try{let r=await $t(e),i=await Pn(r,m.join(m.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(d=>m.normalize(d)),a=await ue(r,i.ownedPaths,o);await Sn(r,t,{recursive:!0,dereference:!1,filter:async d=>Dt(r,d,i.ownedPaths,o)?(await q(r,d),!0):!1});let[s,c]=await Promise.all([ue(r,i.ownedPaths,o),ue(t,i.ownedPaths,o)]);if(a!==s||a!==c)throw x();for(let[d,l]of i.configuration)if(await K(t,d)!==l)throw x();i.stagedSettings!==void 0&&await Mt(m.join(t,k),i.stagedSettings)}catch(r){throw await ge(r)?x():r}}async function Wr(e){let t=U(e),n=Ut(e.mutations),r=Y(),i=Ne(),o=await Tt(m.join(Rt(),"pm-transaction-preview-")),a=m.join(o,"tracker");try{await Gn(t.pmRoot,a,r);let s=!1,c=[],d=[],l=new Set;return await Ce(i,()=>rt({path:a,noExtensions:!0},async()=>{Ie(r);let f={...t,pmRoot:a,createCompensation:"close",uniqueIndex:me(a)},y=n.map((h,g)=>{let S=we({...f,onCreateWarnings:(J,ve)=>{ve.length>0&&c.push({index:g,id:J,op:"create",warnings:ve})}},h,g);return{...S,inspect:()=>de(h,g,()=>S.inspect()),prepareCompensation:()=>de(h,g,async()=>S.prepareCompensation?.()),apply:()=>de(h,g,async()=>{let J=await S.apply();return l.add(g),J})}});if(await ee({...t,pmRoot:a,steps:y,onTransition:({transition:h})=>{h==="committed"&&(s=!0)}}),s)for(let[h,g]of n.entries()){let S=(await Xe(g.id,{path:a},{full:!0})).item;d.push({index:h,id:String(S.id),op:g.op,execution:l.has(h)?"applied":"adopted",item:S,commit_time_fields:jt(S)})}})),{records:d,validated:s,state:s?"staged_snapshot":"replayed_committed_plan",warnings:c,unresolved_commit_constraints:["concurrent_tracker_changes","extension_write_hooks","derived_extension_dependencies_excluded","generated_timestamps_and_provenance"]}}finally{await kt(o,{recursive:!0,force:!0})}}async function xn(e){let t=U(e),n=Ut(e.mutations),r=e.createCompensation??"close";if(!["close","delete"].includes(r))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={...t,createCompensation:r,uniqueIndex:me(t.pmRoot)},o=await ee({...t,steps:n.map((s,c)=>we(i,s,c)),recoveryData:JSON.parse(JSON.stringify({kind:"item-mutations-v1",mutations:n,createCompensation:r})),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),a={};for(let[s,c]of n.entries()){let d=fe(c,s),l=o.results[d];a[Mn(c,s)]=l}return{transactionId:o.transactionId,status:"committed",recovered:o.recovered,results:a}}function qn(e){let t=[];return e.evidence!==void 0&&Object.keys(e.evidence).length>0&&t.push({op:"update",id:e.id,options:e.evidence}),t.push({op:"close",id:e.id,reason:e.reason,...e.closeOptions===void 0?{}:{options:e.closeOptions}},{op:"release",id:e.id,...e.releaseOptions===void 0?{}:{options:e.releaseOptions}}),t}function Jr(e){return xn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:qn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var zr={buildCreateStep:Ct,bulkHistoryMarker:v,compensateByRestore:W,deriveStepId:fe,isUpdateMarkerApplied:R,readItemSnapshot:b};async function Br(e,t){let n=await Je(e,t);return n===void 0?void 0:{journal:n,planDigest:te(n)}}function Kn(e,t){let n=t.recoveryData;if(n===null||typeof n!="object"||Array.isArray(n)||n.kind!=="item-mutations-v1"||!Array.isArray(n.mutations)||!["close","delete"].includes(String(n.createCompensation)))throw new u("Transaction has no supported item recovery plan",p.CONFLICT,{code:"transaction_recovery_plan_missing",required:"Resume with the original plan and its original adapter.",why:"Legacy or foreign journals cannot safely reconstruct item compensation."});let r=n.mutations;Nt(r);let i={...e,createCompensation:n.createCompensation,uniqueIndex:me(e.pmRoot)};return r.map((o,a)=>we(i,o,a))}async function Vr(e){let t=U(e),n=await ze({...e,...t,resolveSteps:r=>Kn({...e,...t},r)});return{journal:n,planDigest:te(n)}}export{it as a,pr as b,lr as c,vt as d,_ as e,mr as f,_n as g,fr as h,An as i,Tn as j,Fn as k,Wr as l,xn as m,qn as n,Jr as o,zr as p,Br as q,Vr as r};
2
- //# sourceMappingURL=chunk-PMIGRSNZ.js.map
1
+ import{$a as ne,Ub as Ze,Vb as Qe,Xb as re,_b as et,a as We,ac as tt,bc as nt,xc as rt}from"./chunk-2WNORBVN.js";import{u as Xe}from"./chunk-A3WCP4TU.js";import{wc as He}from"./chunk-ERD2RYWM.js";import{m as Ye}from"./chunk-VJLZHOTP.js";import{b as U,c as ee,d as Je,e as te,f as ze}from"./chunk-FZ4XWWLO.js";import{ra as Be,wb as j,xa as Ve,zb as D}from"./chunk-F7P42FL5.js";import{Lb as Ke,Lc as Le,Va as Q,d as Oe,gb as N,ia as Pe,ka as C,t as Ae,u as Te,v as z}from"./chunk-AB5S6TWE.js";import{B as E,I as X,Md as Ge,Qd as xe,X as Fe,Xd as qe,dd as I,id as Z,r as Ue,t as H,u as je,va as T,x as De}from"./chunk-BV7J3LRH.js";import{De as Ce,Ea as V,Ee as Ne,Id as Re,Na as ke,Zb as Me,a as Ee,qe as Ie,re as Y}from"./chunk-E4BQRZF2.js";import{A as p,C as u,G as B,I as $e,J as M,l as _e,q as k,t as Se,y as be}from"./chunk-NHNM3GIP.js";import pe from"node:crypto";import{constants as ce}from"node:fs";import{cp as Sn,lstat as At,mkdir as bn,mkdtemp as Tt,open as En,readdir as On,realpath as $t,rm as kt,stat as le,writeFile as Mt}from"node:fs/promises";import{tmpdir as Rt}from"node:os";import m from"node:path";import ft from"node:crypto";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="01728cbc-2037-50d2-8318-5f106714b8da")}catch{}})();var O=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",..._e,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function it(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return O.has(t)?t:e}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="6456f85b-e076-5048-9c21-03d477267259")}catch{}})();function F(e,t,n){let r=e?.estimatedMinutes;if(!(r===void 0||typeof r=="string"))throw new u(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,p.USAGE,{code:"mutation_option_value_invalid",required:'Pass estimatedMinutes as a string, for example "45", in raw mutation options.',why:"Raw options use the create/update command option types; item documents accept numeric estimated_minutes instead.",nextSteps:["Quote the estimatedMinutes value or use an item document with numeric estimated_minutes, then retry the transaction."]})}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="37abb7b8-a5c3-5bdd-ad3a-9dc5189e834f")}catch{}})();var ie=["op","id","reason","options","unique","match"],Pt=[...ie,"ref"],ot=[...Pt,"item"],Gt="mutate-",at="row-",st=["schema_version","mutations"],ht="[a-z][a-z0-9._-]{0,63}",ct=new RegExp(`^${ht}$`,"u"),yt=new RegExp(`(^|,)id=@(${ht})(?=,|$)`,"gu"),dt=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),P=["item","item_hash","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],wt=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count","pm_format_version","claim_principal","test_runs","deferred_fields"]),xt=new Set([...wt,"completed_at","id"]),gt={create:j.map(e=>e.target),update:D.map(e=>e.target),close:Be.map(e=>dt(e.flag)).filter(e=>e!=="reason"),release:Ve.map(e=>dt(e.flag))};function pr(e){let t=ft.createHash("sha256").update(e).digest("hex");return`${Gt}${t.slice(0,24)}`}function lr(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new u("createCompensation must be close or delete.",p.USAGE);t.createCompensation=n}for(let r of["lockTtlSeconds","lockWaitMs"]){let i=e[r];if(i===void 0)continue;let o=typeof i=="number"||typeof i=="string"&&i.trim().length>0?Number(i):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new u(`${r} must be a positive safe integer.`,p.USAGE);t[r]=o}return t}function w(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function G(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=Me(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function A(e,t,n){let r=G(t,n);return new u(r===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${r}"?`,p.USAGE,{code:"stdin_json_unknown_key",required:`Use documented ${e} keys only.`,why:"Strict structured input prevents silent typos from creating incomplete or unintended mutations.",nextSteps:[r===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${r}".`]})}function se(e,t){try{return JSON.parse(e)}catch(n){let r=n instanceof Error?n.message:String(n);throw new u(`${t} must be valid JSON: ${r}`,p.USAGE,{code:"stdin_json_invalid",required:`Pipe one valid JSON ${t.toLowerCase()} into stdin.`,why:"Structured mutation input must parse deterministically before any tracker write begins."})}}function qt(e,t){if(!w(e))throw new u(`Mutation ${t+1} must be an object.`,p.USAGE);for(let n of Object.keys(e))if(!ie.includes(n))throw A(`mutation ${t+1}`,n,ie);return e}function Kt(e,t,n,r){if(e===void 0)return;if(!w(e))throw new u(`Mutation ${n+1} options must be an object.`,p.USAGE);let i=[...gt[t],...St(t,r)];for(let o of Object.keys(e))if(!i.includes(o))throw A(`mutation ${n+1} ${t} options`,o,i);return F(e,t,n),e}function ut(e,t,n,r){if(e===void 0)return;let i=r==="unique"?"create":"update";if(t!==i)throw new u(`Mutation ${n+1} ${r} is only valid for ${i} operations.`,p.USAGE);let o=w(e)&&typeof e.key=="string"?e.key.trim():"";if(!w(e)||o.length===0||e.value===void 0||e.value===null)throw new u(`Mutation ${n+1} ${r} must be an object with a non-empty key and a value.`,p.USAGE);return{key:o,value:e.value}}function Lt(e,t,n){let r=qt(e,t),{op:i,id:o,reason:a}=r;if(i!=="create"&&i!=="update"&&i!=="close"&&i!=="release")throw new u(`Mutation ${t+1} op must be create, update, close, or release.`,p.USAGE);let s=Kt(r.options,i,t,n),c=ut(r.unique,i,t,"unique"),d=ut(r.match,i,t,"match");if(typeof o!="string"||o.trim().length===0)throw new u(`Mutation ${t+1} requires a non-empty id.`,p.USAGE);let l=o.trim();if(i==="close"){if(typeof a!="string"||a.trim().length===0)throw new u(`Mutation ${t+1} close requires a non-empty reason.`,p.USAGE);return{op:i,id:l,reason:a.trim(),...s===void 0?{}:{options:s}}}if(i==="release")return{op:i,id:l,...s===void 0?{}:{options:s}};if(!w(s))throw new u(`Mutation ${t+1} ${i} requires an options object.`,p.USAGE);return{op:i,id:l,options:s,...c===void 0?{}:{unique:c},...d===void 0?{}:{match:d}}}function vt(e,t={}){let n=se(e,"Mutation batch"),r=Array.isArray(n)?n:w(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(r===void 0||r.length===0)throw new u("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",p.USAGE);let i=t.runtimeFields??[];return r.map((o,a)=>{let s=Lt(o,a,i);return s.options!==void 0&&Ae(s.options),s})}function Wt(e,t,n){let r=ft.createHash("sha256").update(e).update("\0").update(t).digest("hex"),i=BigInt(`0x${r.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Pe(n)}${i}`}function pt(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),r=t[n];if(r===void 0)throw new u(`Unknown mutation reference "${e}".`,p.USAGE);return r}function lt(e,t){if(typeof e!="string")return e;let n=e.replace(yt,(r,i,o)=>{let a=t[o];if(a===void 0)throw new u(`Unknown mutation reference "@${o}".`,p.USAGE);return`${i}id=${a}`});if(/(^|,)id=@/u.test(n))throw new u(`Malformed mutation reference in dependency "${e}".`,p.USAGE);return n}function Jt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(yt)].map(t=>t[1]).filter(t=>t!==void 0)}function zt(e,t){let n=new Map;for(let[a,s]of e.entries()){let c=t[a];if(c===void 0)continue;let d=w(s.options)?s.options:{},l=Array.isArray(d.dep)?d.dep:d.dep===void 0?[]:[d.dep];n.set(c,[d.parent,d.blockedBy,...l].flatMap(Jt))}let r=new Set,i=new Set,o=a=>{if(r.has(a))throw new u(`Mutation reference cycle includes "@${a}".`,p.USAGE);if(!i.has(a)){r.add(a);for(let s of n.get(a))n.has(s)&&o(s);r.delete(a),i.add(a)}};for(let a of n.keys())o(a)}function Bt(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),r=n[0];if(!r.ok&&(r.line.startsWith("[")||r.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&w(o.value)))return null;let i=[];for(let o of n){if(!o.ok)throw new u(`Mutation document line ${o.number} must be one valid JSON object: ${Le(o.error)}`,p.USAGE,{code:"stdin_json_invalid",required:"Provide one JSON object per line (JSON Lines), a JSON array, or a {schema_version, mutations} document.",why:"Structured mutation input must parse deterministically before any tracker write begins."});if(!w(o.value))throw new u(`Mutation document line ${o.number} must be a JSON object.`,p.USAGE);i.push(o.value)}return i}function Vt(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Yt(e){let t;try{t=se(e,"Mutation document")}catch(n){let r=Bt(e);if(r===null)throw n;return{schema_version:1,mutations:r}}return Array.isArray(t)?{schema_version:1,mutations:t}:w(t)&&!Vt(t)?{schema_version:1,mutations:[t]}:t}function Ht(e,t){let n=Object.hasOwn(e,"op")?Xt(e,t):Zt(e,t);if(n.op==="create"&&n.id===void 0&&w(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new u(`Mutation ${t+1} item id must be a string.`,p.USAGE);n.id=n.item.id}return n}function Xt(e,t){for(let n of Object.keys(e))if(!ot.includes(n))throw A(`mutation ${t+1}`,n,ot);if(e.item!==void 0&&e.op!=="create")throw new u(`Mutation ${t+1} item documents are only valid for create operations.`,p.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new u(`Mutation ${t+1} must declare either item or options, not both.`,p.USAGE);return{...e}}function Zt(e,t){let{ref:n,id:r,item:i,...o}=e,a=i!==void 0?i:o;if(i!==void 0&&Object.keys(o).length>0)throw new u(`Mutation ${t+1} must not mix item document keys with top-level fields.`,p.USAGE);if(!w(a))throw new u(`Mutation ${t+1} item document must be an object.`,p.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...r===void 0?{}:{id:r},item:a}}function Qt(e){let t=Yt(e);if(!w(t))throw new u("Mutation document must be a JSON array or object.",p.USAGE);for(let n of Object.keys(t))if(!st.includes(n))throw A("mutation document",n,st);if(t.schema_version!==void 0&&t.schema_version!==1)throw new u("Mutation document schema_version must be 1.",p.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new u("Mutation document requires a non-empty mutations array.",p.USAGE);return t.mutations.map((n,r)=>{if(!w(n))throw new u(`Mutation ${r+1} must be an object.`,p.USAGE);return Ht(n,r)})}function en(e,t,n){let r=new Set(Object.values(Et(t,n,Object.create(null))));for(let i of t)i.op==="create"&&typeof i.id=="string"&&i.id.trim().length>0&&r.add(C(i.id,n.idPrefix));return{...e,existing:e.existing.filter(i=>!r.has(i.id))}}function tn(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,r]of e.entries()){if(r.op!=="create"||r.ref!==void 0||typeof r.id=="string"&&r.id.trim().length>0)continue;let i=`${at}${n+1}`;if(t.has(i))throw new u(`Mutation ${n+1} receives the synthesized ref "${i}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${at}<n> aliases are reserved for rows without one.`,p.USAGE);r.ref=i}}function _t(e,t,n){let r=_n(JSON.stringify(e),t,{},n);return delete r.stdinJson,delete r.documentAnnotationSnapshot,r}function St(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>E(n))}function nn(e,t){for(let n of e)w(n.item)&&(n.options=_t(n.item,"create",t),delete n.item)}function bt(e,t){return t.some(n=>n.metadata_key===e)?e:it(e)}function oe(e,t,n){let r=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(w(e.item)){if(e.item[t]!==void 0)return e.item[t];if(bt(r,n)===t&&e.item[r]!==void 0)return e.item[r]}let i=w(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&i[E(o)]!==void 0?i[E(o)]:i[t]!==void 0?i[t]:i[r]!==void 0?i[r]:(Array.isArray(i.field)?i.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function rn(e,t){return e<t?-1:+(e!==t)}function ae(e){return Array.isArray(e)?e.map(ae):w(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>rn(t,n)).map(([t,n])=>[t,ae(n)])):e}function _(e){return typeof e=="string"?e.trim():JSON.stringify(ae(e))}function on(e,t,n,r,i){let o=t.key.trim();if(o.length===0)throw new u("Upsert key must be a non-empty field name.",p.USAGE);let a=an(t.existing),s=new Map,c=new Set;for(let[d,l]of e.entries()){if(l.op!=="create")continue;let f=sn(l,o,d,s,r),y=cn(a.get(f)??[],o,f);if(y===void 0){l.unique={key:o,value:oe(l,o,r)};continue}let h=C(y,n);typeof l.ref=="string"&&(i[l.ref]=h),dn(l,h,r,{key:o,value:oe(l,o,r)}),c.add(d)}return c}function an(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let r=_(n.value);t.set(r,[...t.get(r)??[],n.id])}return t}function sn(e,t,n,r,i){let o=oe(e,t,i);if(o==null||o==="")throw new u(`Mutation ${n+1} is missing the upsert key "${t}".`,p.USAGE,{code:"upsert_key_missing",required:`Every create record must carry a non-empty "${t}" value when --upsert-key ${t} is set.`,why:"Keyed upsert identifies existing items by that field; a record without it cannot be matched or safely created."});let a=_(o),s=r.get(a);if(s!==void 0)throw new u(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,p.USAGE,{code:"upsert_key_duplicate",required:"Each record must carry a distinct upsert key value within one batch.",why:"Two records with the same key would race for the same existing item."});return r.set(a,n),a}function cn(e,t,n){if(e.length>1)throw new u(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,p.CONFLICT,{code:"upsert_key_ambiguous",required:"Resolve the duplicate existing items or choose a key that is unique per item.",why:"An ambiguous key cannot select one item to update without guessing."});return e[0]}function dn(e,t,n,r){let i=new Set([...gt.update,...St("update",n)]),o=w(e.item)?_t(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>i.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=r}function Et(e,t,n){for(let[r,i]of e.entries())if(i.ref!==void 0){if(i.op!=="create")throw new u(`Mutation ${r+1} ref is only valid for create operations.`,p.USAGE);if(typeof i.ref!="string"||!ct.test(i.ref))throw new u(`Mutation ${r+1} ref must match ${ct.source}.`,p.USAGE);if(n[i.ref]!==void 0)throw new u(`Duplicate mutation ref "${i.ref}".`,p.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?C(i.id,t.idPrefix):Wt(t.transactionId,i.ref,t.idPrefix)}return n}function mr(e,t){let n=Qt(e);tn(n);let r=n.map(l=>typeof l.ref=="string"?l.ref:void 0),i=Object.create(null),o=t.upsert===void 0?new Set:on(n,en(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],i);nn(n,t.runtimeFields??[]),Et(n,t,i),zt(n,r);let a=n.map(l=>{let f={...l},y=typeof f.ref=="string"?f.ref:void 0;if(delete f.ref,y!==void 0?f.id=i[y]:f.id=pt(f.id,i),w(f.options)){let h={...f.options};for(let g of["parent","blockedBy"])h[g]!==void 0&&(h[g]=pt(h[g],i));Array.isArray(h.dep)?h.dep=h.dep.map(g=>lt(g,i)):h.dep!==void 0&&(h.dep=lt(h.dep,i)),f.options=h}return f}),s=vt(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),c=s.filter(l=>l.op==="create").map(l=>l.id);if(new Set(c).size!==c.length)throw new u("Duplicate resolved create id in mutation document.",p.USAGE);let d=s.map((l,f)=>{let y=r[f];return{index:f,...typeof y=="string"?{ref:y}:{},id:l.id,op:l.op,...o.has(f)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:i,rows:d}}function un(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let r=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(r)?JSON.stringify(r):r}`}).join(",")}function pn(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(w))throw new u(`${n} must be an array of objects.`,p.USAGE);return e.map(r=>un(r,t))}}function ln(e,t){return e==="tags"&&Array.isArray(t)&&t.every(n=>typeof n=="string")?JSON.stringify(t):typeof t=="number"||typeof t=="boolean"?String(t):t}function mt(e,t,n=!1){for(let[r,i,o]of He){let a=t[r],s=pn(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(a)?a.filter(c=>!w(c)||c.created_at===void 0):a,o,r);s!==void 0&&s.length>0&&(e[i]=s)}}function mn(e,t){for(let n of Object.keys(e)){if(t){if(!P.includes(n))throw A("item envelope",n,P);continue}if(!O.has(n)&&G(n,[...O])===void 0&&G(n,P)==="item")throw A("item envelope",n,P)}}function fn(e){let t=Object.hasOwn(e,"item");mn(e,t);let n=t?e.item:e;if(!w(n))throw new u("Item document item must be an object.",p.USAGE);return{item:n,...t&&w(e.linked)?{linked:e.linked}:{}}}function hn(e,t,n,r,i,o){if((r==="update"?xt:wt).has(t))return;let a=i.find(s=>s.metadata_key===t&&s.commands.includes(r));if(a!==void 0){let s=X(o,a);e[E(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!O.has(t)){if(G(t,[...O])!==void 0)throw A("item document",t,[...O]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,c)=>c.toUpperCase())]=ln(t,n))}function yn(e){return{command_to_fields:new Map([["create",e.filter(t=>t.commands.includes("create"))]])}}function wn(e,t,n,r){let i=r.filter(d=>d.commands.includes("create")),o=new Set([...Fe.filter(d=>t.has(d.option)).map(d=>d.field),...i.filter(d=>t.has(E(d))).map(d=>d.metadata_key),...Ye(Array.isArray(n)?n.map(String):[],yn(i)).metadataKeys]),a=(Array.isArray(e)?e:[]).filter(w).filter(d=>typeof d.field=="string"&&!o.has(d.field));if(a.length===0)return{};let s=a.map(d=>typeof d.reason=="string"?d.reason.trim():""),c=a.map(d=>d.field);return t.has("deferReason")?{defer:c}:s.every(d=>d.length>0)?{defer:c,deferReason:[...new Set(s)].join("; ")}:{defer:c}}function gn(e,t,n){let r=new Set(Object.entries(e).filter(([,o])=>o!==void 0).map(([o])=>o)),i=t==="create"?j:D;for(let{target:o,keys:a}of i)a.some(s=>r.has(s))&&r.add(o);for(let o of n.filter(a=>a.commands.includes(t)))X(e,o)!==void 0&&r.add(E(o));return r}function vn(e,t,n){let r=t==="create"?j:D;for(let{target:i}of r)i!=="field"&&n.has(i)&&delete e[i]}function _n(e,t,n={},r=[]){let i=se(e,"Item document");if(!w(i))throw new u("Item document must be a JSON object.",p.USAGE);let{item:o,linked:a}=fn(i),s={};for(let[f,y]of Object.entries(o)){let h=bt(f,r);h!==f&&Object.hasOwn(o,h)||hn(s,h,y,t,r,n)}mt(s,o,t==="update"),a!==void 0&&mt(s,a);let c=gn(n,t,r);if(vn(s,t,c),t==="create"&&!c.has("defer")&&Object.assign(s,wn(o.deferred_fields,c,n.unset,r)),t==="update"){let f=Object.fromEntries(["comments","notes","learnings"].filter(y=>Object.hasOwn(o,y)&&!c.has(y.slice(0,-1))).map(y=>[y,o[y].filter(h=>w(h)&&h.created_at!==void 0)]));Object.keys(f).length>0&&(s.documentAnnotationSnapshot=f)}let d={...s,...Object.fromEntries(Object.entries(n).filter(([,f])=>f!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0},l=Object.keys(s).filter(f=>!c.has(f));return Te(Oe(d,l),l)}function fr(e){return vt(JSON.stringify(e))}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="5bde03cb-def4-549f-89d5-6822bd2235e6")}catch{}})();async function An(e,t){if(!xe(e))return{schema:H(t.schema),typeDefinitionsFromFile:[]};let n=await Fn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function Tn(e,t,n,r){let i=V({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},Y());return(await Ke(e,t.item_format,i.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[r];return a==null?[]:[{id:o.id,value:a}]})}function me(e){let t=new Map,n=async r=>{let i=await qe(e),o=await An(e,i),a=new Map;for(let s of await Tn(e,i,o,r)){let c=_(s.value);a.set(c,[...a.get(c)??[],s.id])}return a};return{lookup(r){let i=t.get(r)??n(r);return t.set(r,i),i},async recordCreate(r){for(let[i,o]of t){let a=r[i];if(a==null)continue;let s=await o,c=_(a);s.set(c,[...s.get(c)??[],String(r.id)])}},invalidate(){t.clear()}}}async function $n(e,t){let n=_(t.value),r=(await e.lookup(t.key)).get(n)??[];if(r.length!==0)throw new u(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${r.join(", ")}; the plan was resolved before it existed.`,p.CONFLICT,{code:"upsert_key_conflict",required:"Re-plan the document so the row updates the existing item instead of creating a duplicate.",why:"Keyed upsert is resolved before the writer lock, so every remaining create is re-checked under the lock; concurrent imports therefore cannot create two items for one key value.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan turns the row into an update of the existing item.","Inspect the existing item first when its content should win over the document row."]})}function kn(e,t,n){let r=e.metadata[n.key],i=_(n.value);if(_(r)!==i)throw new u(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(i)}; the plan selected it before the key changed.`,p.CONFLICT,{code:"upsert_match_changed",required:"Re-plan the document so the row is resolved against the current key values.",why:"Keyed upsert selects its target before the writer lock, so the update re-reads the key under the lock instead of updating a mismatched item blindly.",nextSteps:["Re-run pm item mutate with the same document and --upsert-key; the re-plan creates or re-targets the row from the current key values."]})}function Ot(e){if(e===null||typeof e!="object"||Array.isArray(e))return!1;let t=e;return typeof t.key=="string"&&t.key.trim().length>0&&t.value!==void 0&&t.value!==null}function L(e,t){let n={...e,...t};return e===void 0?n:z(e,n)}async function b(e,t){try{let n=(await ne(t,{},{pmRoot:e})).item;return{id:n.id,closedAt:n.closed_at,updatedAt:n.updated_at,assignee:n.assignee,claimPrincipal:n.claim_principal}}catch(n){if(n instanceof u&&n.exitCode===p.NOT_FOUND)return;throw n}}function fe(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=pe.createHash("sha256").update(Ee(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function Mn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function v(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}function he(e,t){return e===t||(e?.startsWith(`${t} | `)??!1)}async function R(e,t,n,r){let i=await T(m.join(e,"history",`${t}.jsonl`),t),o=v(n,r,"apply"),a=v(n,r,"compensate");for(let s=i.length-1;s>=0;s-=1){let c=i[s].message;if(he(c,o))return!0;if(c===a)return!1}return!1}async function ye(e,t){let n=await b(e,t.id);if(n?.updatedAt===void 0)throw new u(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,p.NOT_FOUND);let r=await T(m.join(e,"history",`${n.id}.jsonl`),n.id);if(r.length===0)throw new u(`Bulk ${t.op} target ${t.id} has no restorable history`,p.NOT_FOUND);return{target_updated_at:n.updatedAt,target_version:String(Q(r)+r.length),target_history_hash:I(r),target_history_length:r.length}}function $(e,t,n){return new u(`Transaction ${e.transactionId} cannot safely compensate incomplete step ${n}; review item ${t} history before recovery.`,p.CONFLICT,{code:"transaction_partial_mutation",item_id:t,required:"Reconcile the item's partial or intervening changes before resuming this transaction.",why:"The retained history does not prove exclusive ownership of the changes to undo. The journal remains compensating instead of claiming a rollback or overwriting another writer.",nextSteps:[`Run pm history ${t} and inspect this transaction's retained compensation data before explicitly restoring or reconciling the item.`]})}function It(e,t){let n=`bulk-item-transaction ${t} `;return[e.message,e.context?.item_transaction_step].some(r=>typeof r=="string"&&r.startsWith(n))}function Rn(e,t,n){let{expectedHistory:r,length:i,version:o}=t;if(I(e)===r)return!1;if(typeof i!="number"||!Number.isSafeInteger(i)||i<1||I(e.slice(0,i))!==r||o!==String(Q(e)+i))throw $(n,n.itemId,n.stepId);let a=v(n.transactionId,n.stepId,"apply"),s=e.slice(i),c=y=>he(y.message,a)||y.context?.item_transaction_step===a,d=v(n.transactionId,n.stepId,"compensate");if(s.filter(y=>c(y)||y.message===d).at(-1)?.message===d)return!1;let l=s.filter(c);if(l.length===0)return!1;let f=e.at(-1).after_hash===l.at(-1).after_hash&&s.every(y=>It(y,n.transactionId));if(l.length!==s.length&&!f)throw $(n,n.itemId,n.stepId);return!0}async function W(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;if(i===void 0||typeof i.target_updated_at!="string")return;let o=i.target_updated_at,a=await b(e.pmRoot,t);if(a===void 0)return;let s=await T(m.join(e.pmRoot,"history",`${a.id}.jsonl`),a.id),c=i.target_history_hash;if(typeof c=="string"){if(!Rn(s,{expectedHistory:c,length:i.target_history_length,version:i.target_version},{...e,itemId:a.id,stepId:n}))return}else{if(a.updatedAt===o)return;if(!await R(e.pmRoot,a.id,e.transactionId,n))throw $(e,a.id,n)}let d=()=>nt(t,typeof i.target_version=="string"?i.target_version:o,{force:!0,author:e.author,message:v(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot});await N({pmRoot:e.pmRoot,id:a.id,validate:l=>{if(Z(l)!==s.at(-1).after_hash)throw $(e,a.id,n)}},d)}function Ct(e,t,n){return{id:n,async inspect(){let r=await b(e.pmRoot,t.id);if(r===void 0)return{state:"pending"};if(r.closedAt!==void 0){let i=await T(m.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(i.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new u(`Created item ${r.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,p.CONFLICT,{code:"transaction_create_compensated",item_id:r.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${r.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:r.id,op:"create"}}},async apply(){t.unique!==void 0&&await $n(e.uniqueIndex,t.unique);let r=await Ze(L(t.options,{author:e.author,id:t.id,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=r.item;return e.onCreateWarnings?.(String(i.id),r.warnings),await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){await In(e,t.id,n)}}}async function In(e,t,n){let r=await b(e.pmRoot,t);if(r===void 0||e.createCompensation==="close"&&r.closedAt!==void 0)return;let i=await T(m.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=v(e.transactionId,n,"apply"),a=v(e.transactionId,n,"compensate"),s=i.filter(c=>he(c.message,o)||c.message===a).at(-1);if(s?.message!==a){if(s===void 0||!i.every(c=>It(c,e.transactionId)))throw $(e,r.id,n);await N({pmRoot:e.pmRoot,id:r.id,validate:c=>{if(Z(c)!==i.at(-1).after_hash)throw $(e,r.id,n)}},async()=>{let c={force:!0,author:e.author,message:a};e.createCompensation==="delete"?await tt(t,c,{pmRoot:e.pmRoot}):await re(t,`Compensated: interrupted bulk transaction ${e.transactionId}`,{...c,validateClose:"off"},{pmRoot:e.pmRoot})})}}function Cn(e,t,n){return{id:n,compensatePending:!0,async inspect(){let r=await b(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return ye(e.pmRoot,t)},async apply(){let r=()=>Qe(t.id,L(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=t.match,o=i,a=(await N({pmRoot:e.pmRoot,id:String((await ne(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:s=>{o!==void 0&&kn(s,t.id,o)},committed:s=>{i!==void 0&&(o={key:i.key,value:structuredClone(s.metadata[i.key])})},historyContext:{item_transaction_step:v(e.transactionId,n,"apply")}},r)).item;return e.uniqueIndex.invalidate(),{id:String(a.id),op:"update"}},async compensate(r){await W(e,t.id,n,r)}}}function Nn(e,t,n){return{id:n,async inspect(){let r=await b(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"close"}}:r.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"close"}}},async prepareCompensation(){return ye(e.pmRoot,t)},async apply(){let r=(await re(t.id,t.reason,L(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"close"}},async compensate(r){await W(e,t.id,n,r)}}}function Un(e,t,n){return{id:n,async inspect(){let r=await b(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"release"}}:r.assignee!==void 0||r.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"release"}}},async prepareCompensation(){return ye(e.pmRoot,t)},async apply(){let r=(await et(t.id,L(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"release"}},async compensate(r){await W(e,t.id,n,r)}}}function we(e,t,n){let r=fe(t,n);switch(t.op){case"create":return Ct(e,t,r);case"update":return Cn(e,t,r);case"close":return Nn(e,t,r);case"release":return Un(e,t,r)}}function jn(e,t){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(`Bulk mutation ${t+1} must be an object`);if(!["create","update","close","release"].includes(e.op))throw new TypeError(`Bulk mutation ${t+1} op must be create, update, close, or release`);if(typeof e.id!="string"||e.id.trim().length===0)throw new TypeError(`Bulk mutation ${t+1} requires a non-empty id`);if(e.op==="close"&&(typeof e.reason!="string"||e.reason.trim().length===0))throw new TypeError(`Bulk close mutation ${t+1} requires a non-empty reason`);if(e.op==="create"&&e.unique!==void 0&&!Ot(e.unique))throw new TypeError(`Bulk create mutation ${t+1} unique must be an object with a non-empty key and a value`);if(e.op==="update"&&e.match!==void 0&&!Ot(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);F(e.options,e.op,t)}function Nt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,r]of e.entries()){if(jn(r,n),r.op!=="create"||r.unique===void 0)continue;let{key:i,value:o}=r.unique,a=t.get(i)??new Map,s=_(o),c=a.get(s);if(c!==void 0)throw new u(`Bulk create mutations ${c+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${i}".`,p.USAGE,{code:"upsert_key_duplicate",required:"Each create must carry a distinct unique key value within one batch.",why:"Direct SDK batches must preserve the same uniqueness invariant as planned document rows."});a.set(s,n),t.set(i,a)}}function Ut(e){let t=[...e];return Nt(t),t.map(n=>{let r=structuredClone(n);return n.options!==void 0&&r.options!==void 0&&z(n.options,r.options),r})}function jt(e,t=""){return e===null||typeof e!="object"?[]:Object.entries(e).flatMap(([n,r])=>{let i=`${t}/${n.replaceAll("~","~0").replaceAll("/","~1")}`;return/^(created_at|updated_at|closed_at|completed_at|timestamp)$/u.test(n)?[i]:jt(r,i)})}async function de(e,t,n){try{return await n()}catch(r){throw r instanceof u?new u(r.message,r.exitCode,{...r.context,transaction_operation:{index:t,op:e.op,id:e.id}}):r}}function Dt(e,t,n,r){let i=m.relative(e,t),o=i.split(m.sep);return o[0]==="extensions"&&o[2]==="node_modules"&&!r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))?!1:["locks","runtime","search"].includes(i.split(m.sep)[0])?r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`)):i===""||n===void 0||n.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))}async function q(e,t){let n=await At(t);if(n.isSymbolicLink())await le(t);else if(n.isDirectory()||n.isFile())return n;throw M(m.relative(e,t))}async function Dn(e,t){let n=await En(t,ce.O_RDONLY|ce.O_NOFOLLOW|ce.O_NONBLOCK);try{let r=await n.stat();if(!r.isFile())throw M(m.relative(e,t));let i=pe.createHash("sha256");if(r.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:r.size-1,autoClose:!1}))i.update(o);return i.digest()}finally{await n.close()}}async function ue(e,t,n){let r=pe.createHash("sha256");async function i(o){for(let a of(await On(o)).sort()){let s=m.join(o,a);Dt(e,s,t,n)&&((await q(e,s)).isDirectory()?await i(s):(r.update(JSON.stringify(m.relative(e,s))),r.update(await Dn(e,s))))}}return await i(e),r.digest("hex")}function x(){return new u("Tracker changed while preparing the transaction preview; retry against stable state.",p.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ge(e){if(!B(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),r=n;for(;;)try{let i=await At(r);return r!==n&&i.isDirectory()}catch(i){if(!B(i))return!1;let o=m.dirname(r);if(o===r)return!1;r=o}}async function K(e,t){let n=m.join(e,t);try{let r=e;for(let i of t.split(m.sep).slice(0,-1))r=m.join(r,i),await q(e,r);if(!(await q(e,n)).isFile())throw M(t);return await $e(n,M(t))}catch(r){if(await ge(r))return;throw r}}async function Ft(e,t,n,r){let i=H(n);for(let[o,a]of Object.entries(i.files)){let s=m.relative(e,je(e,a,Ue[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new u("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",p.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});i.files[o]=s;let c=await K(e,s);if(r?.set(s,c),c!==void 0){let d=m.join(t,s);await bn(m.dirname(d),{recursive:!0}),await Mt(d,c)}}return De(t,i)}async function Fn(e,t){await le(e);let n=await Tt(m.join(Rt(),"pm-schema-plan-"));try{let r=await $t(e);return await Ft(r,m.join(n,"configuration"),t)}catch(r){throw await ge(r)?x():r}finally{await kt(n,{recursive:!0,force:!0})}}async function Pn(e,t,n){let r=new Map,i=await K(e,k);r.set(k,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let a=Ge(o),s=a.success?a.data:void 0,c=await Ft(e,t,s?.schema,r),d=c.schema,l=m.relative(e,Re(e));r.set(l,await K(e,l));let f=V({...be,item_types:{definitions:[...s?.item_types?.definitions??[],...c.type_definitions_from_file??[]]}},n),y=ke(e)===e?[...Se.filter(Boolean),k,We,"transactions",...f.folders,...r.keys()].map(g=>m.normalize(g)):void 0,h=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:d.files}});return{configuration:r,ownedPaths:y,stagedSettings:h,registryFolders:f.folders}}async function Gn(e,t,n){await le(e);try{let r=await $t(e),i=await Pn(r,m.join(m.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(d=>m.normalize(d)),a=await ue(r,i.ownedPaths,o);await Sn(r,t,{recursive:!0,dereference:!1,filter:async d=>Dt(r,d,i.ownedPaths,o)?(await q(r,d),!0):!1});let[s,c]=await Promise.all([ue(r,i.ownedPaths,o),ue(t,i.ownedPaths,o)]);if(a!==s||a!==c)throw x();for(let[d,l]of i.configuration)if(await K(t,d)!==l)throw x();i.stagedSettings!==void 0&&await Mt(m.join(t,k),i.stagedSettings)}catch(r){throw await ge(r)?x():r}}async function Wr(e){let t=U(e),n=Ut(e.mutations),r=Y(),i=Ne(),o=await Tt(m.join(Rt(),"pm-transaction-preview-")),a=m.join(o,"tracker");try{await Gn(t.pmRoot,a,r);let s=!1,c=[],d=[],l=new Set;return await Ce(i,()=>rt({path:a,noExtensions:!0},async()=>{Ie(r);let f={...t,pmRoot:a,createCompensation:"close",uniqueIndex:me(a)},y=n.map((h,g)=>{let S=we({...f,onCreateWarnings:(J,ve)=>{ve.length>0&&c.push({index:g,id:J,op:"create",warnings:ve})}},h,g);return{...S,inspect:()=>de(h,g,()=>S.inspect()),prepareCompensation:()=>de(h,g,async()=>S.prepareCompensation?.()),apply:()=>de(h,g,async()=>{let J=await S.apply();return l.add(g),J})}});if(await ee({...t,pmRoot:a,steps:y,onTransition:({transition:h})=>{h==="committed"&&(s=!0)}}),s)for(let[h,g]of n.entries()){let S=(await Xe(g.id,{path:a},{full:!0})).item;d.push({index:h,id:String(S.id),op:g.op,execution:l.has(h)?"applied":"adopted",item:S,commit_time_fields:jt(S)})}})),{records:d,validated:s,state:s?"staged_snapshot":"replayed_committed_plan",warnings:c,unresolved_commit_constraints:["concurrent_tracker_changes","extension_write_hooks","derived_extension_dependencies_excluded","generated_timestamps_and_provenance"]}}finally{await kt(o,{recursive:!0,force:!0})}}async function xn(e){let t=U(e),n=Ut(e.mutations),r=e.createCompensation??"close";if(!["close","delete"].includes(r))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={...t,createCompensation:r,uniqueIndex:me(t.pmRoot)},o=await ee({...t,steps:n.map((s,c)=>we(i,s,c)),recoveryData:JSON.parse(JSON.stringify({kind:"item-mutations-v1",mutations:n,createCompensation:r})),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),a={};for(let[s,c]of n.entries()){let d=fe(c,s),l=o.results[d];a[Mn(c,s)]=l}return{transactionId:o.transactionId,status:"committed",recovered:o.recovered,results:a}}function qn(e){let t=[];return e.evidence!==void 0&&Object.keys(e.evidence).length>0&&t.push({op:"update",id:e.id,options:e.evidence}),t.push({op:"close",id:e.id,reason:e.reason,...e.closeOptions===void 0?{}:{options:e.closeOptions}},{op:"release",id:e.id,...e.releaseOptions===void 0?{}:{options:e.releaseOptions}}),t}function Jr(e){return xn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:qn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var zr={buildCreateStep:Ct,bulkHistoryMarker:v,compensateByRestore:W,deriveStepId:fe,isUpdateMarkerApplied:R,readItemSnapshot:b};async function Br(e,t){let n=await Je(e,t);return n===void 0?void 0:{journal:n,planDigest:te(n)}}function Kn(e,t){let n=t.recoveryData;if(n===null||typeof n!="object"||Array.isArray(n)||n.kind!=="item-mutations-v1"||!Array.isArray(n.mutations)||!["close","delete"].includes(String(n.createCompensation)))throw new u("Transaction has no supported item recovery plan",p.CONFLICT,{code:"transaction_recovery_plan_missing",required:"Resume with the original plan and its original adapter.",why:"Legacy or foreign journals cannot safely reconstruct item compensation."});let r=n.mutations;Nt(r);let i={...e,createCompensation:n.createCompensation,uniqueIndex:me(e.pmRoot)};return r.map((o,a)=>we(i,o,a))}async function Vr(e){let t=U(e),n=await ze({...e,...t,resolveSteps:r=>Kn({...e,...t},r)});return{journal:n,planDigest:te(n)}}export{it as a,pr as b,lr as c,vt as d,_ as e,mr as f,_n as g,fr as h,An as i,Tn as j,Fn as k,Wr as l,xn as m,qn as n,Jr as o,zr as p,Br as q,Vr as r};
2
+ //# sourceMappingURL=chunk-IGEBFNWE.js.map
@@ -1,2 +1,2 @@
1
- import{lb as h}from"./chunk-ASGAELBQ.js";import{Qc as U,Ra as L,Sa as W,a as w,b as k,c as F,d as A,e as g,f as C}from"./chunk-KLWGIEDC.js";import{Kb as $,Lb as R,Qb as V,Zb as v,ae as G,be as S,fb as D,nc as B,oc as z,u as N,v as p,x as E,y as M,z as I}from"./chunk-KSLPRST2.js";import{A as y,C as _}from"./chunk-LC6DL446.js";import{Command as ae}from"commander";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a851f5ac-99a5-5061-a0c3-a08d898ea20b")}catch{}})();function nt(e){return new ae().name("pm").description("Universal, flexible, extensible, agent-optimized project management CLI for any project or programming language.").version(e).showHelpAfterError(!1).allowExcessArguments(!1).allowUnknownOption(!1).configureOutput({writeOut:t=>{U(t)},writeErr:()=>{}}).option("--json","Output JSON instead of TOON; mutations emit a flat receipt with top-level id/status/changed_field_count while reads use documented entity or collection envelopes").option("--lean","Omit null and empty containers from JSON output").option("--token-accounting","Attach a bounded per-section token-cost receipt to command output").option("--output-include <fields>","Retain comma-separated fields or sections in read output").option("--output-limit <count>","Bound rows in read output").option("--output-budget <tokens|unbounded>","Bound estimated tokens in read output or explicitly disable the default ceiling").option("--output-format <toon|json>","Select the result encoding for reads and mutations").option("--output-session <state>","Carry a JSON session budget and served-item ledger across read calls").option("--output-cursor <cursor>","Resume continuation_kind=output_cursor").option("--output-row-contract","Include row selectors, encoding metadata, and read-output receipts").option("--quiet","Suppress stdout output").option("--no-changed-fields","Omit the changed_fields array from mutation output (keeps changed_field_count)").option("--full-changed-fields","Restore the legacy full mutation envelope and changed_fields array").option("--id-only","Print only id and status for single-item mutation output").option("--pm-path <dir>","Explicit tracker storage path for this command (preferred over --path)").option("--path <dir>","Backward-compatible alias for --pm-path; this is the tracker storage path, not a workspace cwd").option("--no-extensions","Disable extension loading").option("--no-pager","Disable pager integration for help and long output").option("--explain","Render extended rationale and examples in help output").option("--all","Reveal every public command and compatibility alias").option("--profile","Print deterministic timing diagnostics").option("--author <id>","Override mutation author for this invocation").option("--expect-hash <revision>","Refuse writes to the named item unless it is still at this item_hash from pm get (a bare hash names the command's <id>; guard each other item with <id>=<item_hash>, repeatable)",(t,n)=>[...n??[],t]).exitOverride()}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8efedca0-725e-520f-ad06-825a0cccddaa")}catch{}})();var j=new Set(["append","claim","close","close-task","comments","copy","delete","deps","docs","files","focus","get","history","history-compact","history-redact","history-repair","learnings","notes","pause-task","release","restore","start-task","test","update"]),q=new Map([["files","discover"],["item","complete"]]),le=new Map([["append",1],["close",1],["close-task",1],["comments",1],["item complete",1],["learnings",1],["notes",1],["restore",1]]);function K(e){let t=p(e?.trim().toLowerCase()??"");return j.has(t)||q.has(t)}function ce(e,t,n){let o=j.has(n)?t+1:void 0,s=g(e.slice(t+1));if(s===void 0)return o;let r=t+1+s,a=`${n} ${e[r]}`,i=p(a);return i===a?n==="item"&&e[r]==="complete"?r+1:o:K(i)?P(e,r,i):void 0}function P(e,t,n){if(["history","context","ctx","update","close","item"].includes(n))return ce(e,t,n);let o=q.get(n);if(o===void 0)return t+1;let s=e[t+1]?.toLowerCase()===o;return t+(s?2:1)}function ue(e){let t=new Map;for(let n of h(e))for(let o of[n.flag,n.short,...n.aliases??[]])o&&t.set(o,n);return t}function de(e){let t=[];for(let n=0;n<e.length;n+=1){let o=e[n];if(o==="--")break;o==="--id"?(t.push({index:n,consumed:2,value:e[n+1]}),n+=1):o.startsWith("--id=")&&t.push({index:n,consumed:1,value:o.slice(5)})}return t}function fe(e,t,n){if(e.indexOf("=")>=0||t===void 0||t.startsWith("-"))return!1;let o=n.get(e);return o!==void 0&&o.value_type!=="boolean"}function pe(e,t,n,o,s){let r=0;for(let a=t;a<e.length;a+=1){let i=e[a];if(i==="--")break;if(i==="--id"){a+=1;continue}if(!i.startsWith("--id=")){if(!i.startsWith("-")){if(a<o)return!0;r+=1;continue}fe(i,e[a+1],s)&&(a+=1)}}return r>(le.get(p(n))??0)}function Y(e){let t=g(e),n=t===void 0?void 0:e[t]?.toLowerCase();if(n!=="context"&&n!=="ctx"&&!K(n))return{argv:[...e],changed:!1,conflict:!1};let o=P(e,t,n);if(o===void 0)return{argv:[...e],changed:!1,conflict:!1};let s=o>t+1?`${p(e.slice(t,o-1).join(" "))} ${e[o-1]}`:n,r=ue(s),a=de(e),i=a[0];if(!i||!i.value?.trim())return{argv:[...e],changed:!1,conflict:!1};if(a.length>1||pe(e,o,s,i.index,r))return{argv:[...e],changed:!1,conflict:!0,itemId:i.value};let l=[...e.slice(0,i.index),...e.slice(i.index+i.consumed)],c=g(l),u=P(l,c,n);return l.splice(u,0,i.value),{argv:l,changed:!0,conflict:!1,itemId:i.value}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7b271a35-800c-52bf-9368-0410e76b8d4e")}catch{}})();var me=new Set(["--output-include","--output-limit","--output-budget","--output-format","--output-session","--output-cursor"]),he=new Set(["toon","json"]);function ge(e,t,n){let o=e[t];if(k.has(o))return n.booleanFlags.add(o),1;let s=o.indexOf("="),r=s>0?o.slice(0,s):o;if(!w.has(r))return 1;let a=s>0?o.slice(s+1):void 0,i=a===void 0&&A(r,e[t+1]),l=a??(i?e[t+1]:void 0);return r==="--author"?n.author=l??"":typeof l=="string"&&l.length>0&&(me.has(r)?n.outputValues:n.pathValues).set(r,l),i?2:1}function be(e){return e.outputValues.get("--output-format")!=="toon"&&(e.booleanFlags.has("--json")||e.outputValues.get("--output-format")==="json"||e.pathValues.get("--format")?.trim().toLowerCase()==="json")}function ye(e){let t={booleanFlags:new Set,outputValues:new Map,pathValues:new Map},n=0;for(;n<e.length&&e[n]!=="--";)n+=ge(e,n,t);return{path:t.pathValues.get("--pm-path")??t.pathValues.get("--path"),noExtensions:t.booleanFlags.has("--no-extensions")||["history attest","history-attest"].includes(ee(e)??""),noPager:t.booleanFlags.has("--no-pager"),json:be(t),quiet:t.booleanFlags.has("--quiet"),lean:t.booleanFlags.has("--lean"),tokenAccounting:t.booleanFlags.has("--token-accounting"),...t.booleanFlags.has("--output-row-contract")?{outputRowContract:!0}:{},...t.outputValues.get("--output-include")===void 0?{}:{outputInclude:t.outputValues.get("--output-include")},...t.outputValues.get("--output-limit")===void 0?{}:{outputLimit:t.outputValues.get("--output-limit")},...t.outputValues.get("--output-budget")===void 0?{}:{outputBudget:t.outputValues.get("--output-budget")},...he.has(t.outputValues.get("--output-format"))?{outputFormat:t.outputValues.get("--output-format")}:{},...t.outputValues.get("--output-session")===void 0?{}:{outputSession:t.outputValues.get("--output-session")},...t.outputValues.get("--output-cursor")===void 0?{}:{outputCursor:t.outputValues.get("--output-cursor")},...t.author===""?{authorMissingValue:!0}:t.author!==void 0?{author:t.author}:{}}}function Z(e){let t=[],n=0;for(;n<e.length;){let o=e[n];if(o==="--")break;if(k.has(o)||o==="--profile"||o==="--id-only"||o==="--full-changed-fields"||o==="--explain"){n+=1;continue}if(w.has(o)){n+=A(o,e[n+1])?2:1;continue}if(F(o)){n+=1;continue}t.push(o),n+=1}return t}function _e(e){let t=Z(e);if(t[0]?.trim().toLowerCase()==="help"){let o=[];for(let s=1;s<t.length;s+=1){let r=t[s];if(r.startsWith("-"))break;o.push(r.trim().toLowerCase())}return{requested:!0,commandPathTokens:o}}if(t.findIndex(o=>o==="--help"||o==="-h")<0)return{requested:!1,commandPathTokens:[]};let n=[];for(let o of t){if(o.startsWith("-"))break;n.push(o.trim().toLowerCase())}return{requested:!0,commandPathTokens:n}}function T(e){return g(e)}function we(e){return C(e)}function Ie(e,t){return t.noPager?!0:process.stdout.isTTY===!0?!1:_e(e).requested}function bt(e){let t=["PAGER","MANPAGER","GIT_PAGER","LESS"],n=t.map(r=>process.env[r]),o=()=>{for(let[r,a]of t.entries()){let i=n[r];i===void 0?delete process.env[a]:process.env[a]=i}},s=ye(e);return Ie(e,s)&&(process.env.PAGER="cat",process.env.MANPAGER="cat",process.env.GIT_PAGER="cat",(typeof process.env.LESS!="string"||process.env.LESS.trim().length===0)&&(process.env.LESS="FRX")),o}var ke=new Set(["install","uninstall","explore","manage","doctor","adopt","adopt-all","activate","deactivate"]);function Ce(e){let t=T(e);if(t===void 0||e[t]!=="extension")return[...e];let n=e[t+1];if(!n||n.startsWith("-"))return[...e];if(!ke.has(n))return[...e];if(e.includes("--help")||e.includes("-h"))return[...e];let o=`--${n}`;return e.includes(o)?[...e]:[...e.slice(0,t+1),o,...e.slice(t+2)]}var ve=new Set(["pm","pm-cli"]);function Se(e,t){let n=T(e);if(n===void 0)return e;let o=e[n];return ve.has(o.trim().toLowerCase())?(t.push({from:o,to:[],reason:"executable_alias",confidence:"high"}),[...e.slice(0,n),...e.slice(n+1)]):e}function Te(e,t){let n=T(e);if(n!==void 0&&e[n]==="help"){let i=T(e.slice(n+1));n=i===void 0?void 0:n+1+i}if(n===void 0)return e;let o=e[n],s=M[o.trim().toLowerCase()];if(!s)return e;let r=s.split(" "),a=[...e.slice(0,n),...r,...e.slice(n+1)];return t.push({from:o,to:r,reason:"command_alias",confidence:"high"}),a}function x(e){return e.replace(/^--?/,"").replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function X(e){return x(e).replace(/-/g,"")}function J(e,t,n){let o=e.get(t);if(o===void 0){e.set(t,n);return}o!==n&&e.set(t,null)}function xe(e){let t=[],n=o=>{typeof o=="string"&&o.startsWith("--")&&t.push(o)};n(e.flag);for(let o of e.aliases??[])n(o);return t}function Oe(e,t){let n=t??h(e),o=new Map,s=new Map,r=new Map,a=new Set;for(let i of n){let l=xe(i);if(l.length===0)continue;let c=`--${x(l[0])}`;for(let d of l)J(o,x(d),c),J(s,X(d),c);let u=X(c);r.has(c)||r.set(c,u),i.list===!0&&a.add(c)}return{canonicalByNormalized:o,canonicalByCompact:s,canonicalComparables:[...r.entries()].map(([i,l])=>({canonicalFlag:i,comparable:l})),listCanonicalFlags:a}}function H(e,t){let n=x(e),o=t.canonicalByNormalized.get(n);if(typeof o=="string")return{flag:o,reason:"flag_alias",confidence:"high"};let s=n.replace(/-/g,""),r=t.canonicalByCompact.get(s);if(typeof r=="string")return{flag:r,reason:"flag_alias",confidence:"high"};let a=s.length>=8?2:1,i=Number.POSITIVE_INFINITY,l,c=!1;for(let u of t.canonicalComparables){let d=v(s,u.comparable,a);if(d!==null){if(d<i){i=d,l=u.canonicalFlag,c=!1;continue}d===i&&l!==u.canonicalFlag&&(c=!0)}}return!l||c||!Number.isFinite(i)||i<=0?null:{flag:l,reason:"flag_typo",confidence:i>=2?"medium":"high"}}function yt(e){let t=[`${e}s`];return e.endsWith("y")&&e.length>1&&t.push(`${e.slice(0,-1)}ies`),t}function Ee(e,t=!1){if(t||e.includes("://"))return null;let n=e.match(/^([A-Za-z][A-Za-z0-9_-]{1,63})([:=])(.*)$/);if(!n)return null;let o=n[1],s=n[3];return s.length===0?null:{key:o,value:s}}function Ae(e,t,n=!1){if(n||!e.startsWith("--"))return{tokens:[e]};let o=e.indexOf("="),s=o>=0?e.slice(0,o):e,r=o>=0?e.slice(o+1):void 0,a=H(s,t);if(!a)return{tokens:[e]};let i=r===void 0?a.flag:`${a.flag}=${r}`;return i===e?{tokens:[e]}:{tokens:[i],event:{from:e,to:[i],reason:a.reason,confidence:a.confidence}}}function Le(e){let t=new Set,n=!1;for(let o=0;o<e.length;o+=1){if(n){t.add(o),n=!1;continue}let s=e[o];n=s==="--path"||s==="--pm-path"}return t}function Pe(e){if(!e.startsWith("--"))return null;let t=e.indexOf("=");return t<0?{flag:e}:{flag:e.slice(0,t),inlineValue:e.slice(t+1)}}function Ne(e,t,n){n.push(e[t]);let o=e[t+1];return typeof o=="string"&&o!=="--"?(n.push(o),t+2):t+1}function Me(e,t,n,o){if(n.inlineValue!==void 0)return{originalTokens:[e[t]],value:n.inlineValue,consumed:1};let s=[],r=t+1;for(;r<e.length&&e[r]!=="--"&&!e[r].startsWith("-")&&(s.length===0||o.has(n.flag));)s.push(e[r]),r+=1;let a=s.length===0?1:1+s.length;return{originalTokens:e.slice(t,t+a),value:s.length===0?void 0:s.join(","),consumed:a}}function Fe(e,t,n,o){let s=e.get(n);if(s){s.values.push(o.value),s.occurrences+=1;return}e.set(n,{outputIndex:t.length,originalTokens:o.originalTokens,values:[o.value],occurrences:1}),t.push(null)}function De(e,t){let n=[],o=[];for(let[s,r]of e){if(!(r.occurrences>=2||t.has(s)&&r.originalTokens.length>2)){o.push({outputIndex:r.outputIndex,tokens:r.originalTokens});continue}let a=`${s}=${r.values.join(",")}`;o.push({outputIndex:r.outputIndex,tokens:[a]}),n.push({from:`${s} (x${r.occurrences})`,to:[a],reason:"list_merge",confidence:"high"})}return{events:n,splices:o}}function $e(e,t){t.sort((n,o)=>o.outputIndex-n.outputIndex);for(let n of t)e.splice(n.outputIndex,1,...n.tokens)}function Re(e,t,n=new Set,o=new Set){if(t.size===0)return{argv:[...e],events:[]};let s=[],r=new Map,a=0;for(;a<e.length;){let c=e[a];if(c==="--"){s.push(...e.slice(a));break}if(n.has(c)){a=Ne(e,a,s);continue}let u=Pe(c);if(!u||!t.has(u.flag)){s.push(c),a+=1;continue}let d=Me(e,a,u,o);if(d.value===void 0){s.push(c),a+=d.consumed;continue}Fe(r,s,u.flag,{originalTokens:d.originalTokens,value:d.value}),a+=d.consumed}let{events:i,splices:l}=De(r,o);return $e(s,l),{argv:s,events:i}}var Q=new Map([["--add",new Set(["command","cmd","path"])],["--remove",new Set(["command","path"])]]);function Ve(e,t){if(e!=="test"||t.length<2)return!1;let n=t[t.length-1],o=t[t.length-2],s=Q.get(o);return s!==void 0&&s.has(n)}function Be(e,t,n){if(t!=="test")return e;let o=[],s=0;for(;s<e.length;){let r=e[s];if(r==="--")return o.push(...e.slice(s)),o;let a=Q.get(r),i=a?e[s+1]:void 0;if(!a||typeof i!="string"||!a.has(i)){o.push(r),s+=1;continue}let l=s+2;for(;l<e.length&&!e[l].startsWith("-");)l+=1;if(l-(s+2)!==1){o.push(r),s+=1;continue}let c=e[s+2],u=`${i}=${c}`;o.push(r,u),n.push({from:`${r} ${i} ${c}`,to:[r,u],reason:"bare_key_value",confidence:"high"}),s+=3}return o}function ze(e,t,n,o){let s=[],r=Le(e);for(let a=0;a<e.length;a+=1){let i=e[a];if(i==="--"){s.push(...e.slice(a));break}let l=r.has(a),c=s[s.length-1];if(i.startsWith("--")){let b=Ae(i,t,l);s.push(...b.tokens),b.event&&o.push(b.event);continue}let u=Ee(i,l);if(!u||typeof c=="string"&&c.startsWith("-")&&!c.includes("=")||["search","comments","notes","learnings"].includes(n)||Ve(n,s)){s.push(i);continue}let d=H(u.key,t);if(!d){s.push(i);continue}let m=u.value.startsWith("-")?[`${d.flag}=${u.value}`]:[d.flag,u.value];s.push(...m),o.push({from:i,to:m,reason:"bare_key_value",confidence:d.confidence})}return s}function Ge(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--verify"){let o=e[t+1];if(o===void 0||o==="--")throw new _("history attest --verify requires a bundle file.",y.USAGE);e.splice(t,2,`--verify=${o}`)}else(w.has(n)||n==="--output"||n==="--hash-algorithm")&&(t+=1)}}function We(e,t){if(!e.some(o=>o==="--help"||o==="-h"))return;let n=new Set(h(t).flatMap(o=>[o.flag,...o.aliases??[],...o.short===void 0?[]:[o.short]]));for(let o=0;o<e.length;o+=1){let s=e[o];if(s==="--")break;s!=="--help"&&s!=="-h"||n.has(e[o-1])&&!k.has(e[o-1])&&(e[o-1]=s)}}function _t(e){let t=[],n=Se(e,t),o=Ce(n);(o.length!==n.length||o.some((b,re)=>b!==n[re]))&&t.push({from:n.join(" "),to:[...o],reason:"legacy_extension_action",confidence:"high"});let s=Te(o,t),r=Y(s);if(r.conflict)throw new _("Provide the item id either positionally or with --id, not both.",y.USAGE);r.changed&&t.push({from:`--id ${r.itemId}`,to:[r.itemId],reason:"item_id_alias",confidence:"high"});let a=we(r.argv),i=ee(r.argv),l=p(i??a??""),c=Oe(i??a),u=ze(r.argv,c,l,t),d=Be(u,l,t),m=Re(d,c.listCanonicalFlags,w,a==="create"?new Set(["--tags"]):new Set);for(let b of m.events)t.push(b);return We(m.argv,i??a),i==="history attest"&&Ge(m.argv),{argv:m.argv,commandName:a,trace:t}}function ee(e){let t=Z(e),n=t[0]?.trim().toLowerCase(),o=t[1]?.trim().toLowerCase(),s=N(t);return s?s.canonical:(n==="extension"||n==="package"||n==="packages")&&typeof o=="string"&&o.length>0&&!o.startsWith("-")?`${n} ${o}`:n}function wt(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--type"){let o=e[t+1];if(typeof o=="string"&&o.trim().length>0)return o.trim();continue}if(n.startsWith("--type=")){let o=n.slice(7).trim();if(o.length>0)return o}}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="fb625cd9-f8a8-56cf-88ab-abef64051497")}catch{}})();function St(e){if(e===void 0)return()=>{};let t=e.trim();if(t.length===0)throw new _("--author requires a non-empty value.",y.USAGE,{code:"missing_required_argument",nextSteps:["Pass an explicit author identifier with --author <id>."]});let n=G();S(t);let o=!1;return()=>{o||(o=!0,n===void 0?S(void 0):S(n))}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d0e60f7e-e0a8-5ef4-9af7-4a1f102ccb7d")}catch{}})();var f=Object.freeze({clock:"PM_CLOCK",tickMs:"PM_CLOCK_TICK_MS",seed:"PM_SEED"});function O(e,t,n,o){return new _(e,y.USAGE,{code:"invalid_reproducible_process_environment",reason:t,field:n,required:`${f.clock} and ${f.seed}; ${f.tickMs} is optional`,nextSteps:[`Set ${f.clock} to an ISO-8601 instant with Z or a numeric UTC offset and ${f.seed} to a non-empty reproducibility seed.`,`Optionally set ${f.tickMs} to a non-negative integer; it defaults to 1.`,"Unset all three variables to retain normal wall-clock and cryptographic-random behavior."],recovery:{recovery_mode:"compact",provided_fields:o,missing_required_fields:t==="incomplete"?[f.clock,f.seed].filter(s=>!o.includes(s)):void 0}})}function Ue(e){let t=e[f.clock],n=e[f.tickMs],o=e[f.seed],s=[[f.clock,t],[f.tickMs,n],[f.seed,o]].filter(a=>a[1]!==void 0).map(([a])=>a);if(s.length===0)return;if(t===void 0||o===void 0)throw O("Reproducible process execution requires PM_CLOCK and PM_SEED together.","incomplete",t===void 0?f.clock:f.seed,s);if(o.trim().length===0)throw O(`${f.seed} must not be empty.`,"invalid_value",f.seed,s);if(!V(t))throw O(`${f.clock} must be a valid ISO-8601 instant with Z or a numeric UTC offset.`,"invalid_value",f.clock,s);let r=n===void 0?1:Number(n);if(n?.trim().length===0||!Number.isSafeInteger(r)||r<0)throw O(`${f.tickMs} must be a non-negative integer.`,"invalid_value",f.tickMs,s);return $({clock:t,seed:o,tickMs:r})}function je(e){let t=Ue(e);return t===void 0?n=>n():R(t)}async function Lt(e,t){return je(e)(t)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="94bdb20f-d193-5767-91f2-8207169b82d1")}catch{}})();var te=new Set([...Object.values(B),...z,"--full","--brief","--compact","--summary","--fields","--section","--token-budget"]),ne=new Set(["--full-changed-fields","--no-changed-fields","--id-only"]);function zt(e,t){if(!["block","unblock"].includes(e)||t.includes(e)||!t.includes("update"))return;let n=new Set(h("update").map(o=>o.flag));if((e==="block"?["--blocked-by","--blocked-reason"]:["--unset","--unblock-note"]).every(o=>n.has(o)))return e==="block"?{examples:[["update","<item-id>","--blocked-by","<blocker-id>","--blocked-reason","<reason>"]],nextSteps:["Choose the actual item and blocker identifiers before running update. --blocked-by records the blocker field and its blocked_by relationship."]}:{examples:[["update","<item-id>","--unset","blocked-by","--unset","blocked-reason","--unblock-note","<note>"]],nextSteps:[`Inspect the item's blockers before running update. --unset blocked-by removes the blocker field and the blocked_by rows naming it; other blocked_by relationships stay, so remove one with --dep-remove "id=<id>,kind=blocked_by" or all with --dep-remove kind=blocked_by. --unset blocked-reason clears the stale reason. --unblock-note alone records a note and does not unblock the item.`,"If your project also uses a blocked lifecycle status, choose its appropriate next status separately with update --status."]}}function qe(e,t){let n=e.includes("="),o=n?e.slice(e.indexOf("=")+1):t;if(!(!o||o.startsWith("--")))return{consumed:n?1:2,replacement:["--from",o],conflicts:["--from"]}}var Ke=["--depth","--output-include","--fields","--section","--for"];function Ye(e){let t=L(p(e.trim().toLowerCase()));if(t===void 0)return;let n=h(t),o=n.flatMap(a=>[a.flag,...a.aliases??[]]),s=[...W(t).keys()].filter(a=>o.includes(`--${a}`)),r=[...n.find(a=>a.flag==="--depth")?.values??[]];if(!(s.length===0&&r.length===0))return{command:t,modes:s,depth_values:r,declared_flags:o}}function Gt(e){return[...e.depth_values.length>0?[`--depth ${e.depth_values.join("|")}`]:[],...e.modes.map(t=>`--${t}`)].join(", ")}function Xe(e,t,n,o){let s=Ye(e);if(s===void 0||s.declared_flags.includes(t))return;let r=[...Ke,...s.modes.map(i=>`--${i}`)].filter(i=>i!==t);if(t==="--depth"){let i=n.includes("="),l=(i?n.slice(n.indexOf("=")+1):o)?.trim().toLowerCase();if(!l)return;let c=i?1:2;return s.modes.includes(l)?{consumed:c,replacement:[`--${l}`],conflicts:r}:l==="standard"?{consumed:c,replacement:[],conflicts:r}:void 0}let a=t.slice(2);return n===t&&s.depth_values.includes(a)?{consumed:1,replacement:["--depth",a],conflicts:r}:void 0}function Je(e,t,n,o){return t==="--since"&&e==="activity"?qe(n,o):t==="--toon"&&n===t?{consumed:1,replacement:["--output-format","toon"],conflicts:["--json","--format","--output-format","--stream"]}:Xe(e,t,n,o)}function Ze(e){let t=g(e);if(t===void 0)return;let n=e[t].trim().toLowerCase(),o=`${n} ${e[t+1]?.trim().toLowerCase()??""}`,s=p(o);return s!==o.trim()?s:n==="ctx"?"context":p(n)}function Wt(e,t,n){let o=e==="ctx"?"context":p(e);if(L(o)===void 0||t.includes("--")||Ze(t)!==o)return;let s=n.split("=",1)[0],r=t.flatMap((d,m)=>d===s||d.startsWith(`${s}=`)?[m]:[]);if(r.length!==1)return;let a=r[0],i=Je(o,s,t[a],t[a+1]);if(!i)return;let{replacement:l,consumed:c,conflicts:u}=i;if(!t.some(d=>u.includes(d.split("=",1)[0])))return[...t.slice(0,a),...l,...t.slice(a+c)]}function oe(e){let t=e.split("=",1)[0].replaceAll("_","-");return te.has(t)||t.length>=5&&[...te].some(n=>n.startsWith(t))}function Ut(e,t){let n=e.split("=",1)[0].replaceAll("_","-");return oe(n)?!ne.has(t):ne.has(n)?!oe(t):!0}function se(e){return e.trim().match(/--[a-z0-9][a-z0-9_-]*/i)?.[0]?.replaceAll("_","-").toLowerCase()}function jt(e){if(!(!Array.isArray(e)||e.length===0))return C(e)}function He(e,t){let n=se(t);if(!n)return;let o=h(e).find(s=>s.flag===n||s.aliases?.includes(n));return o?o.value_type==="boolean"?null:`<${o.value_name??"value"}>`:"<value>"}function qt(e,t,n){let o=[...e],s=o.indexOf("--"),r=s<0?o.length:s;for(let a of n){let i=se(a);if(!i||o.slice(0,r).some(u=>u===i||u.startsWith(`${i}=`)))continue;let l=He(t,i),c=l?[i,l]:[i];o.splice(r,0,...c),r+=c.length}return o.length===e.length?void 0:D(o)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="bd9a8d3b-bc6f-5309-a3fb-7e5f41ef9dab")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="12066389-daef-5fce-b7a6-0ecffa926d66")}catch{}})();function Qt(e,t){let n=e.trim().split(/\s+/u);if(!(n.length<2||t.includes(n.join(" "))))for(let o=1;o<n.length;o+=1){if(!t.includes(n.slice(0,o).join(" ")))return;let s=n.slice(o).join(" "),r=I(s),a=new Set(t.filter(i=>i===s||i.endsWith(` ${s}`)||i===r?.canonical).map(i=>I(i)?.canonical??i).filter(i=>t.includes(i)));if(a.size>0)return a.size===1?[...a][0]:void 0}}var Qe={add:["create","append"],fetch:["get"],inspect:["get","health"],log:["history","comments","notes"],ls:["list"],pause:["release"],read:["get"],remove:["delete"],rm:["delete"],show:["get"],start:["start-task"]};function ie(e,t){let n=e.trim().toLowerCase(),o=t.trim().toLowerCase();if(o.length===0)return Number.POSITIVE_INFINITY;let s=n.split(" "),r=Qe[o]?.indexOf(p(n));if(r!==void 0&&r>=0)return r;if(n===o)return 10;if(s.includes(o))return 11;if(s.some(l=>l.startsWith(o)))return 12;let a=o.length>=5?2:1,i=Number.POSITIVE_INFINITY;for(let l of s){let c=v(l,o,a);c!==null&&(i=Math.min(i,c))}return Number.isFinite(i)?20+i:n.includes(o)?30:Number.POSITIVE_INFINITY}function en(e,t){return e.map(n=>({path:n,score:ie(n,t)})).filter(n=>Number.isFinite(n.score)).sort((n,o)=>n.score!==o.score?n.score-o.score:n.path===o.path?0:n.path<o.path?-1:1).map(n=>n.path)}function tn(e,t,n){let o=new Set(t),s=E.filter(i=>i.lifecycle==="deprecated").slice().sort((i,l)=>l.alias.length-i.alias.length),r=[],a=e.flatMap(i=>{let l=s.find(u=>i===u.alias||i.startsWith(`${u.alias} `)),c=i;if(l){let u=i.slice(l.alias.length);if(!o.has(`${l.canonical}${u}`))return[];c=`${l.canonical_argv.join(" ")}${u}`}return n!==void 0&&ie(i,n)<10&&r.push(c),[c]});return[...new Set(r.length>0?r:a)]}export{nt as a,K as b,Y as c,ye as d,Z as e,_e as f,T as g,we as h,bt as i,Ce as j,yt as k,Re as l,Be as m,_t as n,wt as o,St as p,f as q,Ue as r,je as s,Lt as t,zt as u,Ye as v,Gt as w,Wt as x,oe as y,Ut as z,jt as A,He as B,qt as C,Qt as D,ie as E,en as F,tn as G};
2
- //# sourceMappingURL=chunk-YLPZE2TK.js.map
1
+ import{lb as h}from"./chunk-F7P42FL5.js";import{Qc as U,Ra as L,Sa as W,a as w,b as k,c as F,d as A,e as g,f as C}from"./chunk-BV7J3LRH.js";import{Kb as $,Lb as R,Qb as V,Zb as v,ae as G,be as S,fb as D,nc as B,oc as z,u as N,v as p,x as E,y as M,z as I}from"./chunk-E4BQRZF2.js";import{A as y,C as _}from"./chunk-NHNM3GIP.js";import{Command as ae}from"commander";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a851f5ac-99a5-5061-a0c3-a08d898ea20b")}catch{}})();function nt(e){return new ae().name("pm").description("Universal, flexible, extensible, agent-optimized project management CLI for any project or programming language.").version(e).showHelpAfterError(!1).allowExcessArguments(!1).allowUnknownOption(!1).configureOutput({writeOut:t=>{U(t)},writeErr:()=>{}}).option("--json","Output JSON instead of TOON; mutations emit a flat receipt with top-level id/status/changed_field_count while reads use documented entity or collection envelopes").option("--lean","Omit null and empty containers from JSON output").option("--token-accounting","Attach a bounded per-section token-cost receipt to command output").option("--output-include <fields>","Retain comma-separated fields or sections in read output").option("--output-limit <count>","Bound rows in read output").option("--output-budget <tokens|unbounded>","Bound estimated tokens in read output or explicitly disable the default ceiling").option("--output-format <toon|json>","Select the result encoding for reads and mutations").option("--output-session <state>","Carry a JSON session budget and served-item ledger across read calls").option("--output-cursor <cursor>","Resume continuation_kind=output_cursor").option("--output-row-contract","Include row selectors, encoding metadata, and read-output receipts").option("--quiet","Suppress stdout output").option("--no-changed-fields","Omit the changed_fields array from mutation output (keeps changed_field_count)").option("--full-changed-fields","Restore the legacy full mutation envelope and changed_fields array").option("--id-only","Print only id and status for single-item mutation output").option("--pm-path <dir>","Explicit tracker storage path for this command (preferred over --path)").option("--path <dir>","Backward-compatible alias for --pm-path; this is the tracker storage path, not a workspace cwd").option("--no-extensions","Disable extension loading").option("--no-pager","Disable pager integration for help and long output").option("--explain","Render extended rationale and examples in help output").option("--all","Reveal every public command and compatibility alias").option("--profile","Print deterministic timing diagnostics").option("--author <id>","Override mutation author for this invocation").option("--expect-hash <revision>","Refuse writes to the named item unless it is still at this item_hash from pm get (a bare hash names the command's <id>; guard each other item with <id>=<item_hash>, repeatable)",(t,n)=>[...n??[],t]).exitOverride()}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8efedca0-725e-520f-ad06-825a0cccddaa")}catch{}})();var j=new Set(["append","claim","close","close-task","comments","copy","delete","deps","docs","files","focus","get","history","history-compact","history-redact","history-repair","learnings","notes","pause-task","release","restore","start-task","test","update"]),q=new Map([["files","discover"],["item","complete"]]),le=new Map([["append",1],["close",1],["close-task",1],["comments",1],["item complete",1],["learnings",1],["notes",1],["restore",1]]);function K(e){let t=p(e?.trim().toLowerCase()??"");return j.has(t)||q.has(t)}function ce(e,t,n){let o=j.has(n)?t+1:void 0,s=g(e.slice(t+1));if(s===void 0)return o;let r=t+1+s,a=`${n} ${e[r]}`,i=p(a);return i===a?n==="item"&&e[r]==="complete"?r+1:o:K(i)?P(e,r,i):void 0}function P(e,t,n){if(["history","context","ctx","update","close","item"].includes(n))return ce(e,t,n);let o=q.get(n);if(o===void 0)return t+1;let s=e[t+1]?.toLowerCase()===o;return t+(s?2:1)}function ue(e){let t=new Map;for(let n of h(e))for(let o of[n.flag,n.short,...n.aliases??[]])o&&t.set(o,n);return t}function de(e){let t=[];for(let n=0;n<e.length;n+=1){let o=e[n];if(o==="--")break;o==="--id"?(t.push({index:n,consumed:2,value:e[n+1]}),n+=1):o.startsWith("--id=")&&t.push({index:n,consumed:1,value:o.slice(5)})}return t}function fe(e,t,n){if(e.indexOf("=")>=0||t===void 0||t.startsWith("-"))return!1;let o=n.get(e);return o!==void 0&&o.value_type!=="boolean"}function pe(e,t,n,o,s){let r=0;for(let a=t;a<e.length;a+=1){let i=e[a];if(i==="--")break;if(i==="--id"){a+=1;continue}if(!i.startsWith("--id=")){if(!i.startsWith("-")){if(a<o)return!0;r+=1;continue}fe(i,e[a+1],s)&&(a+=1)}}return r>(le.get(p(n))??0)}function Y(e){let t=g(e),n=t===void 0?void 0:e[t]?.toLowerCase();if(n!=="context"&&n!=="ctx"&&!K(n))return{argv:[...e],changed:!1,conflict:!1};let o=P(e,t,n);if(o===void 0)return{argv:[...e],changed:!1,conflict:!1};let s=o>t+1?`${p(e.slice(t,o-1).join(" "))} ${e[o-1]}`:n,r=ue(s),a=de(e),i=a[0];if(!i||!i.value?.trim())return{argv:[...e],changed:!1,conflict:!1};if(a.length>1||pe(e,o,s,i.index,r))return{argv:[...e],changed:!1,conflict:!0,itemId:i.value};let l=[...e.slice(0,i.index),...e.slice(i.index+i.consumed)],c=g(l),u=P(l,c,n);return l.splice(u,0,i.value),{argv:l,changed:!0,conflict:!1,itemId:i.value}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7b271a35-800c-52bf-9368-0410e76b8d4e")}catch{}})();var me=new Set(["--output-include","--output-limit","--output-budget","--output-format","--output-session","--output-cursor"]),he=new Set(["toon","json"]);function ge(e,t,n){let o=e[t];if(k.has(o))return n.booleanFlags.add(o),1;let s=o.indexOf("="),r=s>0?o.slice(0,s):o;if(!w.has(r))return 1;let a=s>0?o.slice(s+1):void 0,i=a===void 0&&A(r,e[t+1]),l=a??(i?e[t+1]:void 0);return r==="--author"?n.author=l??"":typeof l=="string"&&l.length>0&&(me.has(r)?n.outputValues:n.pathValues).set(r,l),i?2:1}function be(e){return e.outputValues.get("--output-format")!=="toon"&&(e.booleanFlags.has("--json")||e.outputValues.get("--output-format")==="json"||e.pathValues.get("--format")?.trim().toLowerCase()==="json")}function ye(e){let t={booleanFlags:new Set,outputValues:new Map,pathValues:new Map},n=0;for(;n<e.length&&e[n]!=="--";)n+=ge(e,n,t);return{path:t.pathValues.get("--pm-path")??t.pathValues.get("--path"),noExtensions:t.booleanFlags.has("--no-extensions")||["history attest","history-attest"].includes(ee(e)??""),noPager:t.booleanFlags.has("--no-pager"),json:be(t),quiet:t.booleanFlags.has("--quiet"),lean:t.booleanFlags.has("--lean"),tokenAccounting:t.booleanFlags.has("--token-accounting"),...t.booleanFlags.has("--output-row-contract")?{outputRowContract:!0}:{},...t.outputValues.get("--output-include")===void 0?{}:{outputInclude:t.outputValues.get("--output-include")},...t.outputValues.get("--output-limit")===void 0?{}:{outputLimit:t.outputValues.get("--output-limit")},...t.outputValues.get("--output-budget")===void 0?{}:{outputBudget:t.outputValues.get("--output-budget")},...he.has(t.outputValues.get("--output-format"))?{outputFormat:t.outputValues.get("--output-format")}:{},...t.outputValues.get("--output-session")===void 0?{}:{outputSession:t.outputValues.get("--output-session")},...t.outputValues.get("--output-cursor")===void 0?{}:{outputCursor:t.outputValues.get("--output-cursor")},...t.author===""?{authorMissingValue:!0}:t.author!==void 0?{author:t.author}:{}}}function Z(e){let t=[],n=0;for(;n<e.length;){let o=e[n];if(o==="--")break;if(k.has(o)||o==="--profile"||o==="--id-only"||o==="--full-changed-fields"||o==="--explain"){n+=1;continue}if(w.has(o)){n+=A(o,e[n+1])?2:1;continue}if(F(o)){n+=1;continue}t.push(o),n+=1}return t}function _e(e){let t=Z(e);if(t[0]?.trim().toLowerCase()==="help"){let o=[];for(let s=1;s<t.length;s+=1){let r=t[s];if(r.startsWith("-"))break;o.push(r.trim().toLowerCase())}return{requested:!0,commandPathTokens:o}}if(t.findIndex(o=>o==="--help"||o==="-h")<0)return{requested:!1,commandPathTokens:[]};let n=[];for(let o of t){if(o.startsWith("-"))break;n.push(o.trim().toLowerCase())}return{requested:!0,commandPathTokens:n}}function T(e){return g(e)}function we(e){return C(e)}function Ie(e,t){return t.noPager?!0:process.stdout.isTTY===!0?!1:_e(e).requested}function bt(e){let t=["PAGER","MANPAGER","GIT_PAGER","LESS"],n=t.map(r=>process.env[r]),o=()=>{for(let[r,a]of t.entries()){let i=n[r];i===void 0?delete process.env[a]:process.env[a]=i}},s=ye(e);return Ie(e,s)&&(process.env.PAGER="cat",process.env.MANPAGER="cat",process.env.GIT_PAGER="cat",(typeof process.env.LESS!="string"||process.env.LESS.trim().length===0)&&(process.env.LESS="FRX")),o}var ke=new Set(["install","uninstall","explore","manage","doctor","adopt","adopt-all","activate","deactivate"]);function Ce(e){let t=T(e);if(t===void 0||e[t]!=="extension")return[...e];let n=e[t+1];if(!n||n.startsWith("-"))return[...e];if(!ke.has(n))return[...e];if(e.includes("--help")||e.includes("-h"))return[...e];let o=`--${n}`;return e.includes(o)?[...e]:[...e.slice(0,t+1),o,...e.slice(t+2)]}var ve=new Set(["pm","pm-cli"]);function Se(e,t){let n=T(e);if(n===void 0)return e;let o=e[n];return ve.has(o.trim().toLowerCase())?(t.push({from:o,to:[],reason:"executable_alias",confidence:"high"}),[...e.slice(0,n),...e.slice(n+1)]):e}function Te(e,t){let n=T(e);if(n!==void 0&&e[n]==="help"){let i=T(e.slice(n+1));n=i===void 0?void 0:n+1+i}if(n===void 0)return e;let o=e[n],s=M[o.trim().toLowerCase()];if(!s)return e;let r=s.split(" "),a=[...e.slice(0,n),...r,...e.slice(n+1)];return t.push({from:o,to:r,reason:"command_alias",confidence:"high"}),a}function x(e){return e.replace(/^--?/,"").replace(/_/g,"-").replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function X(e){return x(e).replace(/-/g,"")}function J(e,t,n){let o=e.get(t);if(o===void 0){e.set(t,n);return}o!==n&&e.set(t,null)}function xe(e){let t=[],n=o=>{typeof o=="string"&&o.startsWith("--")&&t.push(o)};n(e.flag);for(let o of e.aliases??[])n(o);return t}function Oe(e,t){let n=t??h(e),o=new Map,s=new Map,r=new Map,a=new Set;for(let i of n){let l=xe(i);if(l.length===0)continue;let c=`--${x(l[0])}`;for(let d of l)J(o,x(d),c),J(s,X(d),c);let u=X(c);r.has(c)||r.set(c,u),i.list===!0&&a.add(c)}return{canonicalByNormalized:o,canonicalByCompact:s,canonicalComparables:[...r.entries()].map(([i,l])=>({canonicalFlag:i,comparable:l})),listCanonicalFlags:a}}function H(e,t){let n=x(e),o=t.canonicalByNormalized.get(n);if(typeof o=="string")return{flag:o,reason:"flag_alias",confidence:"high"};let s=n.replace(/-/g,""),r=t.canonicalByCompact.get(s);if(typeof r=="string")return{flag:r,reason:"flag_alias",confidence:"high"};let a=s.length>=8?2:1,i=Number.POSITIVE_INFINITY,l,c=!1;for(let u of t.canonicalComparables){let d=v(s,u.comparable,a);if(d!==null){if(d<i){i=d,l=u.canonicalFlag,c=!1;continue}d===i&&l!==u.canonicalFlag&&(c=!0)}}return!l||c||!Number.isFinite(i)||i<=0?null:{flag:l,reason:"flag_typo",confidence:i>=2?"medium":"high"}}function yt(e){let t=[`${e}s`];return e.endsWith("y")&&e.length>1&&t.push(`${e.slice(0,-1)}ies`),t}function Ee(e,t=!1){if(t||e.includes("://"))return null;let n=e.match(/^([A-Za-z][A-Za-z0-9_-]{1,63})([:=])(.*)$/);if(!n)return null;let o=n[1],s=n[3];return s.length===0?null:{key:o,value:s}}function Ae(e,t,n=!1){if(n||!e.startsWith("--"))return{tokens:[e]};let o=e.indexOf("="),s=o>=0?e.slice(0,o):e,r=o>=0?e.slice(o+1):void 0,a=H(s,t);if(!a)return{tokens:[e]};let i=r===void 0?a.flag:`${a.flag}=${r}`;return i===e?{tokens:[e]}:{tokens:[i],event:{from:e,to:[i],reason:a.reason,confidence:a.confidence}}}function Le(e){let t=new Set,n=!1;for(let o=0;o<e.length;o+=1){if(n){t.add(o),n=!1;continue}let s=e[o];n=s==="--path"||s==="--pm-path"}return t}function Pe(e){if(!e.startsWith("--"))return null;let t=e.indexOf("=");return t<0?{flag:e}:{flag:e.slice(0,t),inlineValue:e.slice(t+1)}}function Ne(e,t,n){n.push(e[t]);let o=e[t+1];return typeof o=="string"&&o!=="--"?(n.push(o),t+2):t+1}function Me(e,t,n,o){if(n.inlineValue!==void 0)return{originalTokens:[e[t]],value:n.inlineValue,consumed:1};let s=[],r=t+1;for(;r<e.length&&e[r]!=="--"&&!e[r].startsWith("-")&&(s.length===0||o.has(n.flag));)s.push(e[r]),r+=1;let a=s.length===0?1:1+s.length;return{originalTokens:e.slice(t,t+a),value:s.length===0?void 0:s.join(","),consumed:a}}function Fe(e,t,n,o){let s=e.get(n);if(s){s.values.push(o.value),s.occurrences+=1;return}e.set(n,{outputIndex:t.length,originalTokens:o.originalTokens,values:[o.value],occurrences:1}),t.push(null)}function De(e,t){let n=[],o=[];for(let[s,r]of e){if(!(r.occurrences>=2||t.has(s)&&r.originalTokens.length>2)){o.push({outputIndex:r.outputIndex,tokens:r.originalTokens});continue}let a=`${s}=${r.values.join(",")}`;o.push({outputIndex:r.outputIndex,tokens:[a]}),n.push({from:`${s} (x${r.occurrences})`,to:[a],reason:"list_merge",confidence:"high"})}return{events:n,splices:o}}function $e(e,t){t.sort((n,o)=>o.outputIndex-n.outputIndex);for(let n of t)e.splice(n.outputIndex,1,...n.tokens)}function Re(e,t,n=new Set,o=new Set){if(t.size===0)return{argv:[...e],events:[]};let s=[],r=new Map,a=0;for(;a<e.length;){let c=e[a];if(c==="--"){s.push(...e.slice(a));break}if(n.has(c)){a=Ne(e,a,s);continue}let u=Pe(c);if(!u||!t.has(u.flag)){s.push(c),a+=1;continue}let d=Me(e,a,u,o);if(d.value===void 0){s.push(c),a+=d.consumed;continue}Fe(r,s,u.flag,{originalTokens:d.originalTokens,value:d.value}),a+=d.consumed}let{events:i,splices:l}=De(r,o);return $e(s,l),{argv:s,events:i}}var Q=new Map([["--add",new Set(["command","cmd","path"])],["--remove",new Set(["command","path"])]]);function Ve(e,t){if(e!=="test"||t.length<2)return!1;let n=t[t.length-1],o=t[t.length-2],s=Q.get(o);return s!==void 0&&s.has(n)}function Be(e,t,n){if(t!=="test")return e;let o=[],s=0;for(;s<e.length;){let r=e[s];if(r==="--")return o.push(...e.slice(s)),o;let a=Q.get(r),i=a?e[s+1]:void 0;if(!a||typeof i!="string"||!a.has(i)){o.push(r),s+=1;continue}let l=s+2;for(;l<e.length&&!e[l].startsWith("-");)l+=1;if(l-(s+2)!==1){o.push(r),s+=1;continue}let c=e[s+2],u=`${i}=${c}`;o.push(r,u),n.push({from:`${r} ${i} ${c}`,to:[r,u],reason:"bare_key_value",confidence:"high"}),s+=3}return o}function ze(e,t,n,o){let s=[],r=Le(e);for(let a=0;a<e.length;a+=1){let i=e[a];if(i==="--"){s.push(...e.slice(a));break}let l=r.has(a),c=s[s.length-1];if(i.startsWith("--")){let b=Ae(i,t,l);s.push(...b.tokens),b.event&&o.push(b.event);continue}let u=Ee(i,l);if(!u||typeof c=="string"&&c.startsWith("-")&&!c.includes("=")||["search","comments","notes","learnings"].includes(n)||Ve(n,s)){s.push(i);continue}let d=H(u.key,t);if(!d){s.push(i);continue}let m=u.value.startsWith("-")?[`${d.flag}=${u.value}`]:[d.flag,u.value];s.push(...m),o.push({from:i,to:m,reason:"bare_key_value",confidence:d.confidence})}return s}function Ge(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--verify"){let o=e[t+1];if(o===void 0||o==="--")throw new _("history attest --verify requires a bundle file.",y.USAGE);e.splice(t,2,`--verify=${o}`)}else(w.has(n)||n==="--output"||n==="--hash-algorithm")&&(t+=1)}}function We(e,t){if(!e.some(o=>o==="--help"||o==="-h"))return;let n=new Set(h(t).flatMap(o=>[o.flag,...o.aliases??[],...o.short===void 0?[]:[o.short]]));for(let o=0;o<e.length;o+=1){let s=e[o];if(s==="--")break;s!=="--help"&&s!=="-h"||n.has(e[o-1])&&!k.has(e[o-1])&&(e[o-1]=s)}}function _t(e){let t=[],n=Se(e,t),o=Ce(n);(o.length!==n.length||o.some((b,re)=>b!==n[re]))&&t.push({from:n.join(" "),to:[...o],reason:"legacy_extension_action",confidence:"high"});let s=Te(o,t),r=Y(s);if(r.conflict)throw new _("Provide the item id either positionally or with --id, not both.",y.USAGE);r.changed&&t.push({from:`--id ${r.itemId}`,to:[r.itemId],reason:"item_id_alias",confidence:"high"});let a=we(r.argv),i=ee(r.argv),l=p(i??a??""),c=Oe(i??a),u=ze(r.argv,c,l,t),d=Be(u,l,t),m=Re(d,c.listCanonicalFlags,w,a==="create"?new Set(["--tags"]):new Set);for(let b of m.events)t.push(b);return We(m.argv,i??a),i==="history attest"&&Ge(m.argv),{argv:m.argv,commandName:a,trace:t}}function ee(e){let t=Z(e),n=t[0]?.trim().toLowerCase(),o=t[1]?.trim().toLowerCase(),s=N(t);return s?s.canonical:(n==="extension"||n==="package"||n==="packages")&&typeof o=="string"&&o.length>0&&!o.startsWith("-")?`${n} ${o}`:n}function wt(e){for(let t=0;t<e.length;t+=1){let n=e[t];if(n==="--")break;if(n==="--type"){let o=e[t+1];if(typeof o=="string"&&o.trim().length>0)return o.trim();continue}if(n.startsWith("--type=")){let o=n.slice(7).trim();if(o.length>0)return o}}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="fb625cd9-f8a8-56cf-88ab-abef64051497")}catch{}})();function St(e){if(e===void 0)return()=>{};let t=e.trim();if(t.length===0)throw new _("--author requires a non-empty value.",y.USAGE,{code:"missing_required_argument",nextSteps:["Pass an explicit author identifier with --author <id>."]});let n=G();S(t);let o=!1;return()=>{o||(o=!0,n===void 0?S(void 0):S(n))}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d0e60f7e-e0a8-5ef4-9af7-4a1f102ccb7d")}catch{}})();var f=Object.freeze({clock:"PM_CLOCK",tickMs:"PM_CLOCK_TICK_MS",seed:"PM_SEED"});function O(e,t,n,o){return new _(e,y.USAGE,{code:"invalid_reproducible_process_environment",reason:t,field:n,required:`${f.clock} and ${f.seed}; ${f.tickMs} is optional`,nextSteps:[`Set ${f.clock} to an ISO-8601 instant with Z or a numeric UTC offset and ${f.seed} to a non-empty reproducibility seed.`,`Optionally set ${f.tickMs} to a non-negative integer; it defaults to 1.`,"Unset all three variables to retain normal wall-clock and cryptographic-random behavior."],recovery:{recovery_mode:"compact",provided_fields:o,missing_required_fields:t==="incomplete"?[f.clock,f.seed].filter(s=>!o.includes(s)):void 0}})}function Ue(e){let t=e[f.clock],n=e[f.tickMs],o=e[f.seed],s=[[f.clock,t],[f.tickMs,n],[f.seed,o]].filter(a=>a[1]!==void 0).map(([a])=>a);if(s.length===0)return;if(t===void 0||o===void 0)throw O("Reproducible process execution requires PM_CLOCK and PM_SEED together.","incomplete",t===void 0?f.clock:f.seed,s);if(o.trim().length===0)throw O(`${f.seed} must not be empty.`,"invalid_value",f.seed,s);if(!V(t))throw O(`${f.clock} must be a valid ISO-8601 instant with Z or a numeric UTC offset.`,"invalid_value",f.clock,s);let r=n===void 0?1:Number(n);if(n?.trim().length===0||!Number.isSafeInteger(r)||r<0)throw O(`${f.tickMs} must be a non-negative integer.`,"invalid_value",f.tickMs,s);return $({clock:t,seed:o,tickMs:r})}function je(e){let t=Ue(e);return t===void 0?n=>n():R(t)}async function Lt(e,t){return je(e)(t)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="94bdb20f-d193-5767-91f2-8207169b82d1")}catch{}})();var te=new Set([...Object.values(B),...z,"--full","--brief","--compact","--summary","--fields","--section","--token-budget"]),ne=new Set(["--full-changed-fields","--no-changed-fields","--id-only"]);function zt(e,t){if(!["block","unblock"].includes(e)||t.includes(e)||!t.includes("update"))return;let n=new Set(h("update").map(o=>o.flag));if((e==="block"?["--blocked-by","--blocked-reason"]:["--unset","--unblock-note"]).every(o=>n.has(o)))return e==="block"?{examples:[["update","<item-id>","--blocked-by","<blocker-id>","--blocked-reason","<reason>"]],nextSteps:["Choose the actual item and blocker identifiers before running update. --blocked-by records the blocker field and its blocked_by relationship."]}:{examples:[["update","<item-id>","--unset","blocked-by","--unset","blocked-reason","--unblock-note","<note>"]],nextSteps:[`Inspect the item's blockers before running update. --unset blocked-by removes the blocker field and the blocked_by rows naming it; other blocked_by relationships stay, so remove one with --dep-remove "id=<id>,kind=blocked_by" or all with --dep-remove kind=blocked_by. --unset blocked-reason clears the stale reason. --unblock-note alone records a note and does not unblock the item.`,"If your project also uses a blocked lifecycle status, choose its appropriate next status separately with update --status."]}}function qe(e,t){let n=e.includes("="),o=n?e.slice(e.indexOf("=")+1):t;if(!(!o||o.startsWith("--")))return{consumed:n?1:2,replacement:["--from",o],conflicts:["--from"]}}var Ke=["--depth","--output-include","--fields","--section","--for"];function Ye(e){let t=L(p(e.trim().toLowerCase()));if(t===void 0)return;let n=h(t),o=n.flatMap(a=>[a.flag,...a.aliases??[]]),s=[...W(t).keys()].filter(a=>o.includes(`--${a}`)),r=[...n.find(a=>a.flag==="--depth")?.values??[]];if(!(s.length===0&&r.length===0))return{command:t,modes:s,depth_values:r,declared_flags:o}}function Gt(e){return[...e.depth_values.length>0?[`--depth ${e.depth_values.join("|")}`]:[],...e.modes.map(t=>`--${t}`)].join(", ")}function Xe(e,t,n,o){let s=Ye(e);if(s===void 0||s.declared_flags.includes(t))return;let r=[...Ke,...s.modes.map(i=>`--${i}`)].filter(i=>i!==t);if(t==="--depth"){let i=n.includes("="),l=(i?n.slice(n.indexOf("=")+1):o)?.trim().toLowerCase();if(!l)return;let c=i?1:2;return s.modes.includes(l)?{consumed:c,replacement:[`--${l}`],conflicts:r}:l==="standard"?{consumed:c,replacement:[],conflicts:r}:void 0}let a=t.slice(2);return n===t&&s.depth_values.includes(a)?{consumed:1,replacement:["--depth",a],conflicts:r}:void 0}function Je(e,t,n,o){return t==="--since"&&e==="activity"?qe(n,o):t==="--toon"&&n===t?{consumed:1,replacement:["--output-format","toon"],conflicts:["--json","--format","--output-format","--stream"]}:Xe(e,t,n,o)}function Ze(e){let t=g(e);if(t===void 0)return;let n=e[t].trim().toLowerCase(),o=`${n} ${e[t+1]?.trim().toLowerCase()??""}`,s=p(o);return s!==o.trim()?s:n==="ctx"?"context":p(n)}function Wt(e,t,n){let o=e==="ctx"?"context":p(e);if(L(o)===void 0||t.includes("--")||Ze(t)!==o)return;let s=n.split("=",1)[0],r=t.flatMap((d,m)=>d===s||d.startsWith(`${s}=`)?[m]:[]);if(r.length!==1)return;let a=r[0],i=Je(o,s,t[a],t[a+1]);if(!i)return;let{replacement:l,consumed:c,conflicts:u}=i;if(!t.some(d=>u.includes(d.split("=",1)[0])))return[...t.slice(0,a),...l,...t.slice(a+c)]}function oe(e){let t=e.split("=",1)[0].replaceAll("_","-");return te.has(t)||t.length>=5&&[...te].some(n=>n.startsWith(t))}function Ut(e,t){let n=e.split("=",1)[0].replaceAll("_","-");return oe(n)?!ne.has(t):ne.has(n)?!oe(t):!0}function se(e){return e.trim().match(/--[a-z0-9][a-z0-9_-]*/i)?.[0]?.replaceAll("_","-").toLowerCase()}function jt(e){if(!(!Array.isArray(e)||e.length===0))return C(e)}function He(e,t){let n=se(t);if(!n)return;let o=h(e).find(s=>s.flag===n||s.aliases?.includes(n));return o?o.value_type==="boolean"?null:`<${o.value_name??"value"}>`:"<value>"}function qt(e,t,n){let o=[...e],s=o.indexOf("--"),r=s<0?o.length:s;for(let a of n){let i=se(a);if(!i||o.slice(0,r).some(u=>u===i||u.startsWith(`${i}=`)))continue;let l=He(t,i),c=l?[i,l]:[i];o.splice(r,0,...c),r+=c.length}return o.length===e.length?void 0:D(o)}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="bd9a8d3b-bc6f-5309-a3fb-7e5f41ef9dab")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="12066389-daef-5fce-b7a6-0ecffa926d66")}catch{}})();function Qt(e,t){let n=e.trim().split(/\s+/u);if(!(n.length<2||t.includes(n.join(" "))))for(let o=1;o<n.length;o+=1){if(!t.includes(n.slice(0,o).join(" ")))return;let s=n.slice(o).join(" "),r=I(s),a=new Set(t.filter(i=>i===s||i.endsWith(` ${s}`)||i===r?.canonical).map(i=>I(i)?.canonical??i).filter(i=>t.includes(i)));if(a.size>0)return a.size===1?[...a][0]:void 0}}var Qe={add:["create","append"],fetch:["get"],inspect:["get","health"],log:["history","comments","notes"],ls:["list"],pause:["release"],read:["get"],remove:["delete"],rm:["delete"],show:["get"],start:["start-task"]};function ie(e,t){let n=e.trim().toLowerCase(),o=t.trim().toLowerCase();if(o.length===0)return Number.POSITIVE_INFINITY;let s=n.split(" "),r=Qe[o]?.indexOf(p(n));if(r!==void 0&&r>=0)return r;if(n===o)return 10;if(s.includes(o))return 11;if(s.some(l=>l.startsWith(o)))return 12;let a=o.length>=5?2:1,i=Number.POSITIVE_INFINITY;for(let l of s){let c=v(l,o,a);c!==null&&(i=Math.min(i,c))}return Number.isFinite(i)?20+i:n.includes(o)?30:Number.POSITIVE_INFINITY}function en(e,t){return e.map(n=>({path:n,score:ie(n,t)})).filter(n=>Number.isFinite(n.score)).sort((n,o)=>n.score!==o.score?n.score-o.score:n.path===o.path?0:n.path<o.path?-1:1).map(n=>n.path)}function tn(e,t,n){let o=new Set(t),s=E.filter(i=>i.lifecycle==="deprecated").slice().sort((i,l)=>l.alias.length-i.alias.length),r=[],a=e.flatMap(i=>{let l=s.find(u=>i===u.alias||i.startsWith(`${u.alias} `)),c=i;if(l){let u=i.slice(l.alias.length);if(!o.has(`${l.canonical}${u}`))return[];c=`${l.canonical_argv.join(" ")}${u}`}return n!==void 0&&ie(i,n)<10&&r.push(c),[c]});return[...new Set(r.length>0?r:a)]}export{nt as a,K as b,Y as c,ye as d,Z as e,_e as f,T as g,we as h,bt as i,Ce as j,yt as k,Re as l,Be as m,_t as n,wt as o,St as p,f as q,Ue as r,je as s,Lt as t,zt as u,Ye as v,Gt as w,Wt as x,oe as y,Ut as z,jt as A,He as B,qt as C,Qt as D,ie as E,en as F,tn as G};
2
+ //# sourceMappingURL=chunk-IYICNCK2.js.map