@unbrained/pm-cli 2026.10.17 → 2026.10.18

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 (188) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +25 -0
  3. package/dist/cli/register-list-query.js +2 -2
  4. package/dist/cli-bundle/bundle-manifest.json +1 -1
  5. package/dist/cli-bundle/chunks/{chunk-3QKI3XNX.js → chunk-4GA4MUTE.js} +2 -2
  6. package/dist/cli-bundle/chunks/{chunk-X2ONXFBP.js → chunk-4V6ONLI6.js} +2 -2
  7. package/dist/cli-bundle/chunks/{chunk-B5QVGCZX.js → chunk-6VZKYJW7.js} +2 -2
  8. package/dist/cli-bundle/chunks/chunk-7PATQWTH.js +20 -0
  9. package/dist/cli-bundle/chunks/{chunk-W3KZ22DW.js → chunk-7WIEAGDS.js} +2 -2
  10. package/dist/cli-bundle/chunks/{chunk-EA2CG7UM.js → chunk-AETP4JEM.js} +2 -2
  11. package/dist/cli-bundle/chunks/{chunk-6ZDKKOKM.js → chunk-FIJOSX2C.js} +2 -2
  12. package/dist/cli-bundle/chunks/{chunk-VMCSTFSO.js → chunk-LUKVNL72.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-J4LPQCET.js → chunk-OJ77ZQN3.js} +2 -2
  14. package/dist/cli-bundle/chunks/{chunk-O4YBC3OM.js → chunk-PYRREEUB.js} +30 -30
  15. package/dist/cli-bundle/chunks/chunk-RHQJ6VWC.js +237 -0
  16. package/dist/cli-bundle/chunks/{chunk-OZCSXX4D.js → chunk-RNABUEFB.js} +2 -2
  17. package/dist/cli-bundle/chunks/{chunk-HY7FQ7QX.js → chunk-TO6CIV4C.js} +2 -2
  18. package/dist/cli-bundle/chunks/{chunk-JS3B2M4D.js → chunk-ZZED447K.js} +2 -2
  19. package/dist/cli-bundle/chunks/{register-list-query-RU3QZSAQ.js → register-list-query-PUCVYYBD.js} +7 -7
  20. package/dist/cli-bundle/chunks/{register-mutation-EQYMT32A.js → register-mutation-GGGVBXD5.js} +2 -2
  21. package/dist/cli-bundle/chunks/{register-operations-VXBGE4XI.js → register-operations-NRZ6Q4QE.js} +2 -2
  22. package/dist/cli-bundle/chunks/{register-setup-UUDEGFRO.js → register-setup-MV3P3YSF.js} +2 -2
  23. package/dist/cli-bundle/focused-chunks/{chunk-LDKX4KYJ.js → chunk-2MPQUMTF.js} +2 -2
  24. package/dist/cli-bundle/focused-chunks/{chunk-MBQF6HT6.js → chunk-5UKCSZWT.js} +2 -2
  25. package/dist/cli-bundle/focused-chunks/{chunk-FTUZ3JF2.js → chunk-A4ZHHTEX.js} +2 -2
  26. package/dist/cli-bundle/focused-chunks/{chunk-JXR6UKFM.js → chunk-B4YLP5ZB.js} +2 -2
  27. package/dist/cli-bundle/focused-chunks/{chunk-NZO7GOXD.js → chunk-BFEMT5U3.js} +16 -16
  28. package/dist/cli-bundle/focused-chunks/{chunk-QOSVJDOO.js → chunk-FW7CSSKL.js} +61 -61
  29. package/dist/cli-bundle/focused-chunks/{chunk-AH6NX6GM.js → chunk-HYPRPSYD.js} +2 -2
  30. package/dist/cli-bundle/focused-chunks/{chunk-RBLSY6ML.js → chunk-IRVL4UXR.js} +2 -2
  31. package/dist/cli-bundle/focused-chunks/{chunk-RHTH5ILM.js → chunk-L55KQ2KT.js} +2 -2
  32. package/dist/cli-bundle/focused-chunks/{chunk-PYC7BF6Z.js → chunk-MASIOFPG.js} +2 -2
  33. package/dist/cli-bundle/focused-chunks/chunk-RJ3EIHDU.js +26 -0
  34. package/dist/cli-bundle/focused-chunks/chunk-SEL4Z2OO.js +167 -0
  35. package/dist/cli-bundle/focused-chunks/{chunk-2IOHHNRT.js → chunk-TB7F4FCR.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/{chunk-UNTQE37U.js → chunk-TZUIBG3P.js} +2 -2
  37. package/dist/cli-bundle/focused-chunks/{chunk-E33QA7PK.js → chunk-Z7YIFCNE.js} +2 -2
  38. package/dist/cli-bundle/focused-chunks/{chunk-SIGIGZCG.js → chunk-ZDBS2DCT.js} +2 -2
  39. package/dist/cli-bundle/main.js +2 -2
  40. package/dist/cli-bundle/sdk-authoring.js +1 -1
  41. package/dist/cli-bundle/sdk-contracts.js +1 -1
  42. package/dist/cli-bundle/sdk-core.js +16 -16
  43. package/dist/cli-bundle/sdk-governance.js +1 -1
  44. package/dist/cli-bundle/sdk-graph.js +1 -1
  45. package/dist/cli-bundle/sdk-merge.js +50 -49
  46. package/dist/cli-bundle/sdk-query.js +1 -1
  47. package/dist/cli-bundle/sdk-runtime.js +1 -1
  48. package/dist/cli-bundle/sdk-testing.js +1 -1
  49. package/dist/cli-bundle/sdk.js +1 -1
  50. package/dist/core/history/event-index.d.ts +8 -1
  51. package/dist/core/history/event-index.js +19 -18
  52. package/dist/core/item/item-format.js +1 -1
  53. package/dist/core/lock/lock.d.ts +8 -1
  54. package/dist/core/lock/lock.js +3 -3
  55. package/dist/core/output/output.js +2 -2
  56. package/dist/core/store/paths.js +1 -1
  57. package/dist/core/telemetry/policy.d.ts +2 -0
  58. package/dist/core/telemetry/policy.js +1 -1
  59. package/dist/core/telemetry/runtime.d.ts +5 -3
  60. package/dist/core/telemetry/runtime.js +3 -3
  61. package/dist/sdk/governance/health/projection.d.ts +37 -0
  62. package/dist/sdk/governance/health/projection.js +2 -0
  63. package/dist/sdk/governance/health.d.ts +7 -18
  64. package/dist/sdk/governance/health.js +2 -2
  65. package/dist/sdk/mutation-events.js +1 -1
  66. package/dist/sdk/public-surface.json +1 -1
  67. package/dist/sdk/query/list.d.ts +2 -0
  68. package/dist/sdk/query/list.js +1 -1
  69. package/dist/types.d.ts +2 -2
  70. package/dist/types.js +1 -1
  71. package/docs/COMMANDS.md +26 -0
  72. package/docs/CONFIGURATION.md +22 -1
  73. package/docs/DEVELOPMENT_DEPENDENCY_SECURITY.md +22 -3
  74. package/docs/OUTPUT_PROJECTION_CONTRACTS.md +10 -0
  75. package/docs/RELEASING.md +8 -1
  76. package/docs/SDK_CONTEXT_COORDINATION.md +71 -7
  77. package/docs/SDK_STORAGE_LIFECYCLE.md +24 -2
  78. package/docs/TESTING.md +8 -0
  79. package/docs/examples/ci/github-actions-pm-extension-gate.yml +1 -1
  80. package/docs/examples/ci/gitlab-ci-pm-extension-gate.yml +1 -1
  81. package/docs/examples/ci/jenkins-pm-extension-gate.Jenkinsfile +1 -1
  82. package/marketplace.json +1 -1
  83. package/node_modules/@opentelemetry/core/package.json +2 -1
  84. package/node_modules/@opentelemetry/instrumentation/package.json +2 -1
  85. package/node_modules/@opentelemetry/resources/package.json +2 -1
  86. package/node_modules/@opentelemetry/sdk-trace/package.json +2 -1
  87. package/node_modules/@opentelemetry/sdk-trace-base/package.json +2 -1
  88. package/node_modules/@sentry/core/build/cjs/client.js +5 -4
  89. package/node_modules/@sentry/core/build/cjs/tracing/ai/gen-ai-attributes.js +0 -4
  90. package/node_modules/@sentry/core/build/cjs/tracing/ai/utils.js +33 -23
  91. package/node_modules/@sentry/core/build/cjs/tracing/anthropic-ai/index.js +7 -6
  92. package/node_modules/@sentry/core/build/cjs/tracing/anthropic-ai/streaming.js +3 -1
  93. package/node_modules/@sentry/core/build/cjs/tracing/google-genai/index.js +13 -14
  94. package/node_modules/@sentry/core/build/cjs/tracing/google-genai/streaming.js +6 -1
  95. package/node_modules/@sentry/core/build/cjs/tracing/langchain/utils.js +71 -21
  96. package/node_modules/@sentry/core/build/cjs/tracing/langgraph/utils.js +23 -33
  97. package/node_modules/@sentry/core/build/cjs/tracing/openai/streaming.js +6 -0
  98. package/node_modules/@sentry/core/build/cjs/tracing/openai/utils.js +11 -0
  99. package/node_modules/@sentry/core/build/cjs/tracing/workers-ai/utils.js +1 -1
  100. package/node_modules/@sentry/core/build/cjs/utils/eventUtils.js +4 -0
  101. package/node_modules/@sentry/core/build/cjs/utils/prepareEvent.js +2 -2
  102. package/node_modules/@sentry/core/build/cjs/utils/version.js +1 -1
  103. package/node_modules/@sentry/core/build/esm/client.js +6 -5
  104. package/node_modules/@sentry/core/build/esm/package.json +1 -1
  105. package/node_modules/@sentry/core/build/esm/tracing/ai/gen-ai-attributes.js +1 -3
  106. package/node_modules/@sentry/core/build/esm/tracing/ai/utils.js +34 -24
  107. package/node_modules/@sentry/core/build/esm/tracing/anthropic-ai/index.js +8 -7
  108. package/node_modules/@sentry/core/build/esm/tracing/anthropic-ai/streaming.js +3 -1
  109. package/node_modules/@sentry/core/build/esm/tracing/google-genai/index.js +15 -16
  110. package/node_modules/@sentry/core/build/esm/tracing/google-genai/streaming.js +6 -1
  111. package/node_modules/@sentry/core/build/esm/tracing/langchain/utils.js +73 -24
  112. package/node_modules/@sentry/core/build/esm/tracing/langgraph/utils.js +24 -34
  113. package/node_modules/@sentry/core/build/esm/tracing/openai/streaming.js +6 -0
  114. package/node_modules/@sentry/core/build/esm/tracing/openai/utils.js +11 -0
  115. package/node_modules/@sentry/core/build/esm/tracing/workers-ai/utils.js +2 -2
  116. package/node_modules/@sentry/core/build/esm/utils/eventUtils.js +4 -1
  117. package/node_modules/@sentry/core/build/esm/utils/prepareEvent.js +2 -2
  118. package/node_modules/@sentry/core/build/esm/utils/version.js +1 -1
  119. package/node_modules/@sentry/core/build/types/tracing/ai/utils.d.ts +3 -7
  120. package/node_modules/@sentry/core/build/types/tracing/anthropic-ai/types.d.ts +2 -2
  121. package/node_modules/@sentry/core/build/types/tracing/langchain/types.d.ts +15 -0
  122. package/node_modules/@sentry/core/build/types/tracing/langchain/utils.d.ts +1 -0
  123. package/node_modules/@sentry/core/build/types/tracing/langgraph/utils.d.ts +2 -0
  124. package/node_modules/@sentry/core/build/types/tracing/openai/types.d.ts +2 -0
  125. package/node_modules/@sentry/core/build/types/utils/eventUtils.d.ts +2 -1
  126. package/node_modules/@sentry/core/build/types-ts3.8/tracing/ai/utils.d.ts +3 -7
  127. package/node_modules/@sentry/core/build/types-ts3.8/tracing/anthropic-ai/types.d.ts +2 -2
  128. package/node_modules/@sentry/core/build/types-ts3.8/tracing/langchain/types.d.ts +15 -0
  129. package/node_modules/@sentry/core/build/types-ts3.8/tracing/langchain/utils.d.ts +1 -0
  130. package/node_modules/@sentry/core/build/types-ts3.8/tracing/langgraph/utils.d.ts +2 -0
  131. package/node_modules/@sentry/core/build/types-ts3.8/tracing/openai/types.d.ts +2 -0
  132. package/node_modules/@sentry/core/build/types-ts3.8/utils/eventUtils.d.ts +2 -1
  133. package/node_modules/@sentry/core/package.json +1 -1
  134. package/node_modules/@sentry/node/build/esm/package.json +1 -1
  135. package/node_modules/@sentry/node/package.json +5 -5
  136. package/node_modules/@sentry/node-core/build/cjs/integrations/anr/index.js +1 -1
  137. package/node_modules/@sentry/node-core/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
  138. package/node_modules/@sentry/node-core/build/esm/integrations/anr/index.js +1 -1
  139. package/node_modules/@sentry/node-core/build/esm/integrations/anr/worker-script.js +2 -2
  140. package/node_modules/@sentry/node-core/build/esm/integrations/local-variables/local-variables-async.js +1 -1
  141. package/node_modules/@sentry/node-core/build/esm/integrations/local-variables/worker-script.js +1 -1
  142. package/node_modules/@sentry/node-core/build/esm/package.json +1 -1
  143. package/node_modules/@sentry/node-core/package.json +10 -4
  144. package/node_modules/@sentry/opentelemetry/build/esm/package.json +1 -1
  145. package/node_modules/@sentry/opentelemetry/package.json +5 -2
  146. package/node_modules/@sentry/server-utils/build/THIRD-PARTY-LICENSES.txt +55 -55
  147. package/node_modules/@sentry/server-utils/build/esm/package.json +1 -1
  148. package/node_modules/@sentry/server-utils/package.json +2 -2
  149. package/node_modules/@toon-format/toon/README.md +10 -41
  150. package/node_modules/@toon-format/toon/dist/index.d.mts +12 -36
  151. package/node_modules/@toon-format/toon/dist/index.mjs +134 -202
  152. package/node_modules/@toon-format/toon/package.json +2 -2
  153. package/node_modules/debug/package.json +3 -0
  154. package/node_modules/fdir/package.json +3 -0
  155. package/node_modules/has-flag/index.d.ts +39 -0
  156. package/node_modules/has-flag/index.js +8 -0
  157. package/node_modules/has-flag/license +9 -0
  158. package/node_modules/has-flag/package.json +46 -0
  159. package/node_modules/has-flag/readme.md +89 -0
  160. package/node_modules/supports-color/browser.js +5 -0
  161. package/node_modules/supports-color/index.js +135 -0
  162. package/node_modules/supports-color/license +9 -0
  163. package/node_modules/supports-color/package.json +53 -0
  164. package/node_modules/supports-color/readme.md +76 -0
  165. package/package.json +4 -4
  166. package/packages/pm-beads/package.json +1 -1
  167. package/packages/pm-calendar/package.json +1 -1
  168. package/packages/pm-command-kit/package.json +1 -1
  169. package/packages/pm-digital-twin/package.json +1 -1
  170. package/packages/pm-governance-audit/package.json +1 -1
  171. package/packages/pm-guide-shell/package.json +1 -1
  172. package/packages/pm-kanban/package.json +1 -1
  173. package/packages/pm-lifecycle-hooks/package.json +1 -1
  174. package/packages/pm-linked-test-adapters/package.json +1 -1
  175. package/packages/pm-search-advanced/package.json +1 -1
  176. package/packages/pm-templates/package.json +1 -1
  177. package/packages/pm-todos/package.json +1 -1
  178. package/packages/pm-vcs/package.json +1 -1
  179. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  180. package/plugins/pm-claude/package.json +1 -1
  181. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  182. package/plugins/pm-codex/package.json +1 -1
  183. package/plugins/pm-codex/plugin.json +1 -1
  184. package/runtime-dependencies.json +1 -1
  185. package/dist/cli-bundle/chunks/chunk-4PNPDT2N.js +0 -236
  186. package/dist/cli-bundle/chunks/chunk-X53HM753.js +0 -20
  187. package/dist/cli-bundle/focused-chunks/chunk-5JEFDEL3.js +0 -166
  188. package/dist/cli-bundle/focused-chunks/chunk-TRFVAWF2.js +0 -26
@@ -1,4 +1,4 @@
1
- import{$ as re,$c as ke,$f as xe,Ab as wn,Bi as oe,Cb as ji,Db as Li,Ej as la,Fj as kn,G as Ii,Gb as Fi,Gi as A,Hi as Se,L as un,N as Ai,Nb as Mi,Oi as Ee,Om as pa,Pm as je,Q as fn,Qm as st,R as h,Rm as ma,Si as na,Sm as ua,T as f,Ta as Oi,Ti as ia,Tm as se,Ua as Ci,Ui as $e,Um as Be,V as k,Va as U,Vc as vn,Vi as aa,Vm as fa,W as Tt,Wc as Hi,Wi as ra,Wm as pe,X as ne,Xc as Pt,Xl as da,Xo as Lt,Y as G,Zc as be,ba as K,bb as N,be as Xi,cb as Pi,cd as Ki,ce as rt,db as Ri,eb as Ni,ed as Rt,eo as ha,fa as de,fc as Gi,fd as Vi,gc as Ui,gd as Yi,hc as zi,hj as oa,k as Ei,ka as Ti,kc as Ji,lc as qi,mj as sa,ng as I,of as T,og as X,pg as Zi,qd as W,qg as Y,qi as bn,rg as ie,rh as ea,si as ta,sj as ca,tc as Wi,tg as Qi,ti as We,ua as Ot,va as hn,vc as Bi,vf as V,vg as ot,vj as Dt,w as $i,wa as gn,wb as Ct,wh as B,wj as jt,xb as Di,xg as Nt,yb as yn,yc as Ne,z as At,zb as _n,zd as H,zj as De}from"./chunk-4PNPDT2N.js";import{mkdir as Ks,readFile as Vs}from"node:fs/promises";import wa 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]="1fae5539-4eb8-5eba-bfd6-a191c89448ec")}catch{}})();var xn=class extends Error{constructor(t="Workspace transaction interrupted"){super(t),this.name="WorkspaceTransactionInterruptedError"}},Ys="sdk-workspace-transaction",Xs=/^[a-zA-Z0-9._-]+$/,Zs=30,Qs=3e3;function va(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n||!Xs.test(n))throw new TypeError(`${t} must match [a-zA-Z0-9._-]+`);return n}function ga(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n)throw new TypeError(`${t} must be non-empty`);return n}function ec(e){return{pmRoot:ga(e.pmRoot,"Transaction pmRoot"),transactionId:va(e.transactionId,"Transaction id"),author:ga(e.author,"Transaction author")}}function ya(e,t,n){let i=e??t;if(!Number.isInteger(i)||i<=0)throw new TypeError(`${n} must be a positive integer`);return i}function ba(e,t){return wa.join(e,"transactions","sdk",`${t}.json`)}async function Ie(e,t){t.updatedAt=T();let n=ba(e,t.transactionId);await Ks(wa.dirname(n),{recursive:!0}),await re(n,`${JSON.stringify(t,null,2)}
1
+ import{$ as re,$c as ke,$f as xe,Ab as wn,Bi as oe,Cb as ji,Db as Li,Ej as la,Fj as kn,G as Ii,Gb as Fi,Gi as A,Hi as Se,L as un,N as Ai,Nb as Mi,Oi as Ee,Om as pa,Pm as je,Q as fn,Qm as st,R as h,Rm as ma,Si as na,Sm as ua,T as f,Ta as Oi,Ti as ia,Tm as se,Ua as Ci,Ui as $e,Um as Be,V as k,Va as U,Vc as vn,Vi as aa,Vm as fa,W as Tt,Wc as Hi,Wi as ra,Wm as pe,X as ne,Xc as Pt,Xl as da,Xo as Lt,Y as G,Zc as be,ba as K,bb as N,be as Xi,cb as Pi,cd as Ki,ce as rt,db as Ri,eb as Ni,ed as Rt,eo as ha,fa as de,fc as Gi,fd as Vi,gc as Ui,gd as Yi,hc as zi,hj as oa,k as Ei,ka as Ti,kc as Ji,lc as qi,mj as sa,ng as I,of as T,og as X,pg as Zi,qd as W,qg as Y,qi as bn,rg as ie,rh as ea,si as ta,sj as ca,tc as Wi,tg as Qi,ti as We,ua as Ot,va as hn,vc as Bi,vf as V,vg as ot,vj as Dt,w as $i,wa as gn,wb as Ct,wh as B,wj as jt,xb as Di,xg as Nt,yb as yn,yc as Ne,z as At,zb as _n,zd as H,zj as De}from"./chunk-RHQJ6VWC.js";import{mkdir as Ks,readFile as Vs}from"node:fs/promises";import wa 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]="1fae5539-4eb8-5eba-bfd6-a191c89448ec")}catch{}})();var xn=class extends Error{constructor(t="Workspace transaction interrupted"){super(t),this.name="WorkspaceTransactionInterruptedError"}},Ys="sdk-workspace-transaction",Xs=/^[a-zA-Z0-9._-]+$/,Zs=30,Qs=3e3;function va(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n||!Xs.test(n))throw new TypeError(`${t} must match [a-zA-Z0-9._-]+`);return n}function ga(e,t){if(typeof e!="string")throw new TypeError(`${t} must be a string`);let n=e.trim();if(!n)throw new TypeError(`${t} must be non-empty`);return n}function ec(e){return{pmRoot:ga(e.pmRoot,"Transaction pmRoot"),transactionId:va(e.transactionId,"Transaction id"),author:ga(e.author,"Transaction author")}}function ya(e,t,n){let i=e??t;if(!Number.isInteger(i)||i<=0)throw new TypeError(`${n} must be a positive integer`);return i}function ba(e,t){return wa.join(e,"transactions","sdk",`${t}.json`)}async function Ie(e,t){t.updatedAt=T();let n=ba(e,t.transactionId);await Ks(wa.dirname(n),{recursive:!0}),await re(n,`${JSON.stringify(t,null,2)}
2
2
  `)}function tc(e){return Number.isInteger(e.attempt)&&typeof e.author=="string"&&typeof e.createdAt=="string"&&typeof e.updatedAt=="string"}function Le(e){return Object.assign(Object.create(null),e)}function nc(e,t){try{let n=JSON.stringify(e,(i,a)=>{if(typeof a=="number"&&!Number.isFinite(a))throw new TypeError(`${t} contains a non-finite number`);if(a===void 0||typeof a=="function"||typeof a=="symbol")throw new TypeError(`${t} contains a non-JSON value`);return a});return JSON.parse(n)}catch(n){throw new TypeError(`${t} must be JSON serializable`,{cause:n})}}function Sn(e,t){return e===void 0?void 0:nc(e,t)}function En(e,t,n,i){let a=Sn(n,i);a===void 0?delete e[t]:e[t]=a}function _a(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function $n(e,t){return Array.isArray(e)&&new Set(e).size===e.length&&e.every(n=>typeof n=="string"&&t.includes(n))}function ic(e,t){if(!$n(e.startedStepIds,t)||!$n(e.completedStepIds,t)||!_a(e.results)||!_a(e.compensationData))return!1;let n=e.startedStepIds,i=new Set(n),a=e.completedStepIds,r=new Set(a);return Object.keys(e.compensationData).some(o=>!i.has(o))||Object.keys(e.results).some(o=>!r.has(o))?!1:e.status==="committed"?t.every(o=>r.has(o)):e.status!=="compensated"||r.size===0&&i.size===0}function Ft(e,t){return new f(`Workspace transaction ${e} journal is invalid (${t})`,h.CONFLICT,{code:"transaction_journal_invalid",required:"A valid durable journal is required before transaction recovery can continue.",why:"Corrupt journal data cannot establish which steps applied or still require compensation.",nextSteps:["Preserve the journal and inspect its integrity or restore a verified backup before retrying.","Do not switch to a new transaction id to bypass an unreadable journal; previously applied work may remain."]})}function ac(e){return new f(`Workspace transaction ${e} journal does not match the supplied plan`,h.CONFLICT,{code:"transaction_plan_mismatch",required:"Replay the exact plan that started this transaction, or start a new transaction with a different id.",why:"A journal records the plan it is resuming; applying a different plan under the same id could skip or duplicate steps.",nextSteps:["Re-run with the original document to resume or replay it.","Pass --transaction-id <new-id> (or a new transactionId over MCP) to commit the changed plan as its own transaction.","Run pm ops gc --scope transactions --dry-run to inspect abandoned journals before pruning them."]})}function rc(e,t,n){let i;try{i=JSON.parse(e)}catch{throw Ft(t,"invalid JSON")}if(!i||typeof i!="object"||Array.isArray(i))throw Ft(t,"expected an object");let a=i;if(!(a.schemaVersion===1&&a.transactionId===t))throw Ft(t,"schema version or transaction id does not match the journal file");let r=a.stepIds;if(!Array.isArray(r)||!$n(r,r)||!ic(a,r)||!tc(a)||typeof a.status!="string"||!["applying","compensating","compensated","committed"].includes(a.status))throw Ft(t,"invalid lifecycle, metadata, status or step ids");if(!(a.status==="compensated"||r.length===n.length&&r.every((o,s)=>o===n[s])))throw ac(t);return{...a,results:Le(a.results),compensationData:Le(a.compensationData)}}async function oc(e,t,n,i,a){let r=a,o=r!==void 0;if(r?.status==="compensating"&&await ka(e,r),r===void 0||r.status==="compensated"){let s=T();r={schemaVersion:1,transactionId:t,author:n,status:"applying",attempt:(r?.attempt??0)+1,createdAt:r?.createdAt??s,updatedAt:s,stepIds:i,startedStepIds:[],completedStepIds:[],results:Le(),compensationData:Le()},await Ie(e.pmRoot,r),await ye(e,r,"prepared")}return{journal:r,recovered:o}}async function sc(e,t,n){try{await lc(t,e.steps),await Ie(e.pmRoot,t);let i=new Set(t.completedStepIds),a=new Set(t.startedStepIds);for(let r of e.steps){if(i.has(r.id))continue;let o=await r.inspect(),s=Sn(o.result,`Step ${r.id} result`);if(o.state!=="applied"){let l=await r.prepareCompensation?.();En(t.compensationData,r.id,l,`Step ${r.id} compensation data`),a.add(r.id),t.startedStepIds=e.steps.map(d=>d.id).filter(d=>a.has(d)),await Ie(e.pmRoot,t);let c=await r.apply();s=Sn(c,`Step ${r.id} result`)}await ye(e,t,"step_applied",r.id),i.add(r.id),t.completedStepIds=e.steps.map(l=>l.id).filter(l=>i.has(l)),En(t.results,r.id,s,`Step ${r.id} result`),await Ie(e.pmRoot,t),await ye(e,t,"step_recorded",r.id)}return await ye(e,t,"committing"),t.status="committed",await Ie(e.pmRoot,t),await ye(e,t,"committed"),{transactionId:t.transactionId,status:"committed",recovered:n,results:Le(t.results)}}catch(i){if(i instanceof xn||t.status==="committed")throw i;try{await ka(e,t)}catch(a){throw new AggregateError([i,a],`Workspace transaction failed and compensation failed: ${String(a)}`,{cause:a})}throw i}}async function cc(e,t,n){try{return rc(await Vs(ba(e,t),"utf8"),t,n)}catch(i){if(i!==null&&typeof i=="object"&&"code"in i&&ne(i))return;throw i}}async function ye(e,t,n,i){await e.onTransition?.({transactionId:t.transactionId,attempt:t.attempt,transition:n,...i===void 0?{}:{stepId:i}})}async function lc(e,t){let n=new Set,i=Le();for(let a of t){let r=await a.inspect();r.state==="applied"&&(n.add(a.id),En(i,a.id,r.result,`Step ${a.id} result`))}e.results=i,e.completedStepIds=t.map(a=>a.id).filter(a=>n.has(a))}async function ka(e,t){t.status="compensating",await Ie(e.pmRoot,t),await ye(e,t,"compensating");let n=new Set(t.completedStepIds),i=new Set(t.startedStepIds);for(let a of[...e.steps].reverse()){if(!i.has(a.id)&&!n.has(a.id))continue;let r;try{r=i.has(a.id)&&(await a.inspect()).state==="applied"}catch{r=i.has(a.id)}r&&(await ye(e,t,"step_compensating",a.id),await a.compensate(t.compensationData[a.id])),n.delete(a.id),i.delete(a.id),t.completedStepIds=e.steps.map(o=>o.id).filter(o=>n.has(o)),t.startedStepIds=e.steps.map(o=>o.id).filter(o=>i.has(o)),delete t.results[a.id],delete t.compensationData[a.id],await Ie(e.pmRoot,t),await ye(e,t,"step_compensated",a.id)}t.status="compensated",await Ie(e.pmRoot,t),await ye(e,t,"compensated")}async function xa(e){let{pmRoot:t,transactionId:n,author:i}=ec(e),a=ya(e.lockTtlSeconds,Zs,"Transaction lock TTL"),r=ya(e.lockWaitMs,Qs,"Transaction lock wait"),o=[...e.steps];if(o.length===0)throw new TypeError("Workspace transaction requires at least one step");let s=o.map(d=>{let p=va(d.id,"Transaction step id");if(p!==d.id)throw new TypeError("Transaction step id must not contain surrounding whitespace");return p});if(new Set(s).size!==s.length)throw new TypeError("Workspace transaction step ids must be unique");let l={...e,pmRoot:t,transactionId:n,author:i,steps:o,lockTtlSeconds:a,lockWaitMs:r},c=await V(t,Ys,a,i,!1,!1,r);try{let d=await cc(t,n,s),p=d!==void 0;if(d?.status==="committed")return{transactionId:n,status:"committed",recovered:!0,results:Le(d.results)};let m=await oc(l,n,i,s,d);return await sc(l,m.journal,p||m.recovered)}finally{await c()}}import dc from"node:fs/promises";import pc 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]="7be00b26-4a56-5399-94f6-f2f67cc5c1e6")}catch{}})();function In(e){return pc.join(e,"extension-migrations.json")}function Sa(e,t){let n=e.definition.id;return typeof n=="string"&&n.trim().length>0?n.trim():`migration-${String(t+1).padStart(3,"0")}`}function Ea(e,t){return`${e.layer}:${e.name}:${t}`}async function mc(e){let t=In(e);if(!await k(t))return{version:1,updated_at:"",entries:[]};let n=JSON.parse(await dc.readFile(t,"utf8"));return{version:1,updated_at:typeof n.updated_at=="string"?n.updated_at:"",entries:Array.isArray(n.entries)?n.entries.filter(i=>typeof i?.key=="string"&&(i.status==="applied"||i.status==="failed")):[]}}async function uc(e,t){let n=await mc(e),i=new Map(n.entries.map(a=>[a.key,a]));return t.forEach((a,r)=>{let o=Sa(a,r),s=i.get(Ea(a,o));s&&(a.definition.status=s.status,s.status==="failed"?a.definition.reason=s.error:(delete a.definition.reason,delete a.definition.error,delete a.definition.message))}),n}async function fc(e){let t=await uc(e.pmRoot,e.migrations),n=new Map(t.entries.map(d=>[d.key,d])),i=[],a=!1,r=e.migrations.map((d,p)=>({migration:d,index:p})).filter(({migration:d})=>e.scope===void 0||d.layer===e.scope);for(let{migration:d,index:p}of r){let m=Sa(d,p),g=Ea(d,m),y=n.get(g),_=String(d.definition.status??"pending").toLowerCase(),u=y?.status??(_==="applied"||_==="failed"?_:"pending");if(u==="applied"){i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"skipped"});continue}if(e.dryRun===!0){i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"pending"});continue}let w=d.runtime_definition?.run??d.definition.run;if(typeof w!="function"){i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"pending"});continue}let v=new Date().toISOString();try{await Promise.resolve(w({id:m,command:"migration",layer:d.layer,extension:d.name,pm_root:e.pmRoot,status:u}));let x={key:g,layer:d.layer,extension:d.name,id:m,status:"applied",attempted_at:v};n.set(g,x),d.definition.status="applied",delete d.definition.reason,delete d.definition.error,delete d.definition.message,i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"applied"}),a=!0}catch(x){let S=x instanceof Error?x.message:String(x),O={key:g,layer:d.layer,extension:d.name,id:m,status:"failed",attempted_at:v,error:S};n.set(g,O),d.definition.status="failed",d.definition.reason=S,i.push({key:g,layer:d.layer,extension:d.name,id:m,before:u,outcome:"failed",error:S}),a=!0}}if(a){let d=await A(e.pmRoot),p={version:1,updated_at:new Date().toISOString(),entries:[...n.values()].sort((m,g)=>m.key.localeCompare(g.key))};await We({pmRoot:e.pmRoot,filePath:In(e.pmRoot),raw:`${JSON.stringify(p,null,2)}
3
3
  `,op:"extension_migrations_apply",author:e.author,lockTtlSeconds:d.locks.ttl_seconds,lockWaitMs:d.locks.wait_ms})}let o=i.filter(d=>d.outcome==="pending").length,s=i.filter(d=>d.outcome==="applied").length,l=i.filter(d=>d.outcome==="skipped").length,c=i.filter(d=>d.outcome==="failed").length;return{ok:c===0,dry_run:e.dryRun===!0,state_path:In(e.pmRoot),total:i.length,pending_count:o,applied_count:s,skipped_count:l,failed_count:c,migrations:i}}async function $a(e){let t=await A(e.resolvedRoots.settings_root),n=await be({pmRoot:e.resolvedRoots.pm_root,settings:t,cwd:process.cwd(),noExtensions:e.global.noExtensions===!0}),i=await ke(n);e.warnings.push(...n.warnings,...i.warnings);let a=await fc({pmRoot:e.resolvedRoots.pm_root,migrations:i.registrations.migrations,author:typeof e.global.author=="string"&&e.global.author.trim().length>0?e.global.author.trim():"pm-extension-migration",dryRun:e.options.dryRun===!0,...e.scope==="global"?{scope:"global"}:{}});return e.withResult({migration:a,load_failure_count:n.failed.length,activation_failure_count:i.failed.length},a.ok)}import{readFile as hc,writeFile as gc}from"node:fs/promises";import ct 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]="1de99e25-e132-5071-833e-37361b4cc7e6")}catch{}})();var Aa="# pm-cli:runtime-cache:start",An="# pm-cli:runtime-cache:end",Ta=".agents/pm",yc=["runtime/","search/","locks/","transactions/","checkpoints/"],_c=["search/eval-queries.json"];async function Ia(e){try{return await e()}catch(t){throw t instanceof Error&&"code"in t&&typeof t.code=="string"&&["EACCES","EPERM","EROFS"].includes(t.code)?new f("The workspace .gitignore is not writable.",h.GENERIC_FAILURE,{code:"init_gitignore_unwritable",reason:t.code.toLowerCase(),required:"Grant the current user read and write access to the workspace .gitignore before initialization.",why:"pm init must publish its managed runtime-cache ignore fence without replacing unrelated entries.",nextSteps:["Grant read and write access to the workspace .gitignore and rerun pm init.","If the workspace is intentionally read-only, initialize pm in a writable workspace or clone."]}):t}}function Oa(e){return e.replaceAll("\\","/").replace(/^\.\/+/,"").replace(/\/+$/,"")}function Tn(e){let t=e.replaceAll("\\","/");return ct.isAbsolute(e)||t===".."||t.startsWith("../")}function wc(e=Ta){let t=Oa(e);return[Aa,...yc.map(n=>n==="search/"?`${t}/${n}*`:`${t}/${n}`),..._c.map(n=>`!${t}/${n}`),An].join(`
4
4
  `)}async function Ca(e,t={}){let n=ct.join(e,".gitignore"),i=Ta;if(t.pmRoot!==void 0){let c=Oa(ct.relative(ct.resolve(e),ct.resolve(t.pmRoot)));if(Tn(c))return{path:n,changed:!1};c.length>0&&(i=c)}let a="";try{a=await Ia(()=>hc(n,"utf8"))}catch(c){if(!(c instanceof Error&&"code"in c&&ne(c)))throw c}let r=a.indexOf(Aa),o=a.indexOf(An),s=(r>=0&&o>=r?`${a.slice(0,r)}${a.slice(o+An.length)}`:a).trimEnd(),l=`${s.length>0?`${s}
@@ -77,4 +77,4 @@ Agent guidance check
77
77
  `),Q.write(`Telemetry helps improve reliability and can be disabled anytime via pm config.
78
78
  `);let l=t?"Y/n":"y/N",c=await n.question(`Enable telemetry for this project? [${l}] `),d=Ns(c,t);return Q.write(`
79
79
  `),{prefix:a,preset:s,telemetry_enabled:d}}finally{n.close()}}function Qu(e){return{presetFromOption:bi(e.preset),useDefaults:e.defaults===!0,authorFromOption:Os(e.author),installBundledPackages:e.withPackages===!0,agentGuidanceMode:Rs(e.agentGuidance),typePreset:Ts(e.typePreset)}}function ef(e){let t=[];return e.prefixArg!==void 0&&e.settings.id_prefix!==e.normalizedPrefix&&t.push("id_prefix"),e.presetFromOption!==void 0&&e.settings.governance.preset!==e.presetFromOption&&t.push("governance_preset"),e.authorFromOption!==void 0&&e.settings.author_default!==e.authorFromOption&&t.push("author_default"),t}function tf(e,t,n,i){if(t.length===0||n)return;let a=i.discovery==="ancestor";throw new f(`${a?`No tracker exists in ${i.requested_cwd}; pm init found an ancestor tracker at ${i.tracker_root}. `:""}Refusing to update existing tracker settings at ${e} without --force.`,h.USAGE,{code:"init_existing_settings_requires_force",type:"urn:pm-cli:error:init_existing_settings_requires_force",required:`--force for ${t.join(", ")}`,why:a?"Ancestor discovery is useful for normal commands, but init must make the selected existing workspace explicit before changing its identity or policy settings.":"pm init is safe to rerun, but changing id prefix, governance preset, or default author on an existing tracker can corrupt long-lived project context when an agent meant to initialize a sandbox path.",resolved_path:i.tracker_root,requested_path:i.requested_cwd,suggested_path:i.suggested_current_tracker_root,examples:["pm init --yes","pm init ./sandbox-pm --yes",...a?['pm init <name> --yes --pm-path "$PWD/.agents/pm"']:[],"pm init acme --yes --force"],nextSteps:[...a?['To create a new tracker in the current directory, rerun with --pm-path "$PWD/.agents/pm".']:[],"If you meant to initialize a sandbox tracker, pass a path-like positional such as ./sandbox-pm or /tmp/pm-test.","If you intentionally want to rewrite this existing tracker's init-managed settings, rerun with --force."]})}function nf(e){let t=!1;return e.prefixArg!==void 0&&e.settings.id_prefix!==e.normalizedPrefix&&(e.settings.id_prefix=e.normalizedPrefix,e.warnings.push(`updated:id_prefix:${e.normalizedPrefix}`),t=!0),e.presetFromOption!==void 0&&e.settings.governance.preset!==e.presetFromOption&&(ki(e.settings,e.presetFromOption),e.warnings.push(`updated:governance_preset:${e.presetFromOption}`),t=!0),e.authorFromOption!==void 0&&e.settings.author_default!==e.authorFromOption&&(e.settings.author_default=e.authorFromOption,e.warnings.push(`updated:author_default:${e.authorFromOption}`),t=!0),t}async function af(e){let t=await A(e.pmRoot);e.warnings.push(`already_exists:${e.settingsPath}`);let n=ef({settings:t,normalizedPrefix:e.normalizedPrefix,prefixArg:e.prefixArg,presetFromOption:e.normalizedOptions.presetFromOption,authorFromOption:e.normalizedOptions.authorFromOption});return tf(e.settingsPath,n,e.options.force===!0,e.target),nf({settings:t,normalizedPrefix:e.normalizedPrefix,prefixArg:e.prefixArg,presetFromOption:e.normalizedOptions.presetFromOption,authorFromOption:e.normalizedOptions.authorFromOption,warnings:e.warnings})&&await Se(e.pmRoot,t),{settings:t,normalizedPrefix:e.normalizedPrefix,chosenPreset:e.normalizedOptions.presetFromOption,wizardUsed:!1}}async function rf(e){let t=e.normalizedPrefix,n=e.normalizedOptions.presetFromOption,i,a=!1;if(e.normalizedOptions.presetFromOption===void 0&&!e.normalizedOptions.useDefaults&&process.stdin.isTTY===!0&&process.stdout.isTTY===!0){let l=await Gs(t,fn.telemetry.enabled);t=l.prefix,n=l.preset,i=l.telemetry_enabled,a=!0}let r=n??"minimal",o=Yu();o.id_prefix=t,ki(o,r);let s=ea()?.trim()||void 0;return o.author_default=e.normalizedOptions.authorFromOption??s??"",i!==void 0&&(o.telemetry.enabled=i,o.telemetry.first_run_prompt_completed=!0),await Se(e.pmRoot,o),{settings:o,normalizedPrefix:t,chosenPreset:n,wizardUsed:a}}async function Es(e){return e.settingsExists?await af(e):await rf({pmRoot:e.pmRoot,normalizedPrefix:e.normalizedPrefix,normalizedOptions:e.normalizedOptions})}async function of(e){let t=await Ss({pm_root:e.pmRoot,cwd:e.cwd,mode:e.agentGuidanceMode,interactive:process.stdin.isTTY===!0&&process.stdout.isTTY===!0,settings:e.settings});return e.warnings.push(...t.warnings),t.settings_changed&&await Se(e.pmRoot,e.settings),{...t.summary,next_steps:t.next_steps}}async function sf(e,t){let n=[],i=[],a=await Qi(e,t.schema);for(let r of a.created_paths)n.push(r),i.push(...await H({path:r,scope:"project",op:"init:runtime_schema_file"}));return{createdDirs:n,warnings:i}}async function cf(e){if(e.typePreset===void 0)return;let t=await js(e.pmRoot,e.settings,e.typePreset);return e.warnings.push(`registered_type_preset:${e.typePreset}`),e.warnings.push(...await H({path:t.file,scope:"project",op:"init:type_preset"})),t}async function lf(e){let t=U(e.settings,W()).folders.filter(i=>!un.includes(i)),n=await Ms(e.pmRoot,t);e.createdDirs.push(...n.createdDirs),e.warnings.push(...n.warnings)}function df(e){let t=F.resolve(e.tracker_root),n=F.dirname(t);return F.basename(t)==="pm"&&F.basename(n)===".agents"?F.dirname(n):e.workspace_root}async function pf(e,t,n,i){if(!e)return;let a=await mi("all",{install:!0,project:!0},{...t,path:n});i.push(...a.warnings);let r=Ds(a),o=r.packages.filter(s=>!s.ok).map(s=>s.alias);if(!r.installed_all||o.length>0)throw new f(`pm init --with-packages did not install all bundled packages successfully${o.length>0?`: ${o.join(", ")}`:"."}`,h.GENERIC_FAILURE);return r}function Us(e){let t=i=>rt([...e.target.mode==="workspace-discovery"?[]:["--pm-path",e.target.tracker_root],...i]),n=[`Create your first item: ${t(["create","--type","Task","--title","<title>"])}`,`List active items: ${t(["list"])}`,`Get agent-friendly project context: ${t(["context"])}`];e.installBundledPackages?n.push(`Explore newly-available commands: ${t(["cal"])}, ${t(["templates"])}, ${t(["guide"])}`):(n.push(`Add optional packages for richer workflows: ${t(["install","calendar","--project"])}, ${t(["install","templates","--project"])}, ${t(["install","guide-shell","--project"])}`),n.push(`Or install everything bundled: ${t(["init","--with-packages"])} (idempotent on re-run)`)),e.registeredTypePreset&&n.push(`Inspect registered preset types: ${t(["schema","list"])}, ${t(["schema","show",e.registeredTypePreset.registered[0]??e.registeredTypePreset.updated[0]])}`),n.push("Supported agent harnesses are attributed automatically; use --author or PM_AUTHOR only when an explicit identity override is required.");for(let i of e.agentGuidanceNextSteps){let a=e.target.mode==="workspace-discovery"?i:i.replace(/\bpm (?=[a-z])/g,()=>`${t([])} `);n.includes(a)||n.push(a)}return n}async function zs(e,t,n,i=Dn){if(t===null){n.push("merge_fence_skipped:not_git_repository:run pm merge install after moving the tracker into a Git repository");return}try{let a=await i({pmRoot:e,workspaceRoot:t});a.gitattributes.changed&&n.push(`updated:merge_fence:${a.gitattributes.path}`)}catch(a){if(!(a instanceof f))throw a;n.push(`merge_fence_skipped:install_failed:${a.context.code??"pm_error"}:${a.message}:run pm merge install after resolving the Git repository error`)}}async function mf(e,t,n,i){if(e==null||n==="status")return;let a=await Ca(e,{pmRoot:t});a.changed&&i.push(`updated:gitignore:${a.path}`)}async function hb(e,t,n={}){let i=t[Ku],a=typeof i=="string"?i:process.cwd(),r=Cs(a,t,e,n.workspace),o=r.pmRoot;e=Ps(r.prefixArg,n.idPrefix);let s=Qu(n);await Fs(o,r.target.mode==="tracker-path",n.force===!0);let l=[],c=[],d=F.join(o,"settings.json"),p=await k(d),m;p&&(m=await Es({pmRoot:o,settingsPath:d,settingsExists:p,normalizedPrefix:Ee(e),prefixArg:e,options:n,normalizedOptions:s,warnings:c,target:r.target}));let g=await Ms(o,un);l.push(...g.createdDirs),c.push(...g.warnings),m??=await Es({pmRoot:o,settingsPath:d,settingsExists:p,normalizedPrefix:Ee(e),prefixArg:e,options:n,normalizedOptions:s,warnings:c,target:r.target});let{settings:y}=m,_=df(r.target),u=await Gt(_??F.dirname(o)),w=_??u,v=await of({pmRoot:o,cwd:w??a,agentGuidanceMode:s.agentGuidanceMode,settings:y,warnings:c}),x=await sf(o,y);l.push(...x.createdDirs),c.push(...x.warnings);let S=await cf({pmRoot:o,settings:y,typePreset:s.typePreset,warnings:c});S&&(y=await A(o)),await lf({pmRoot:o,settings:y,createdDirs:l,warnings:c}),await mf(w,o,s.agentGuidanceMode,c),!p&&n.mergeFence!==!1&&s.agentGuidanceMode!=="status"&&await zs(o,u,c);let O=await pf(s.installBundledPackages,t,o,c),ae=Us({installBundledPackages:s.installBundledPackages,registeredTypePreset:S,agentGuidanceNextSteps:v.next_steps,target:r.target});return{ok:!0,path:o,target:r.target,settings:y,created_dirs:l,warnings:c,governance_preset:y.governance.preset,wizard_used:m.wizardUsed,...S?{registered_type_preset:S}:{},...O?{installed_packages:O}:{},next_steps:ae,agent_guidance:v}}export{xn as a,ec as b,xa as c,In as d,mc as e,uc as f,fc as g,$a as h,Tp as i,Aa as j,An as k,yc as l,wc as m,Ca as n,He as o,bc as p,kc as q,Ra as r,Mt as s,Cc as t,lt as u,La as v,jc as w,Gt as x,Nn as y,Ja as z,dh as A,ph as B,qa as C,mh as D,Dn as E,ar as F,Xe as G,Ze as H,rr as I,tr as J,Ve as K,Ye as L,nr as M,Gc as N,hh as O,wh as P,Ba as Q,Jc as R,jh as S,pr as T,hr as U,Al as V,Tl as W,F_ as X,U_ as Y,z_ as Z,xt as _,J_ as $,q_ as aa,W_ as ba,B_ as ca,H_ as da,K_ as ea,V_ as fa,Y_ as ga,X_ as ha,Z_ as ia,Q_ as ja,ew as ka,tw as la,nw as ma,iw as na,aw as oa,rw as pa,ow as qa,sw as ra,cw as sa,lw as ta,dw as ua,pw as va,mw as wa,uw as xa,ee as ya,b as za,zn as Aa,Bl as Ba,fe as Ca,Jt as Da,Ol as Ea,pt as Fa,qt as Ga,Or as Ha,Mr as Ia,ti as Ja,Zr as Ka,Oy as La,Xp as Ma,Ro as Na,No as Oa,si as Pa,po as Qa,Sp as Ra,mm as Sa,uo as Ta,mi as Ua,ms as Va,Jv as Wa,Ss as Xa,Ku as Ya,ub as Za,fb as _a,hb as $a};
80
- //# sourceMappingURL=chunk-OZCSXX4D.js.map
80
+ //# sourceMappingURL=chunk-RNABUEFB.js.map
@@ -1,2 +1,2 @@
1
- import{a as he}from"./chunk-W3KZ22DW.js";import{Rb as je,Sb as Fe,Ub as V,Xb as Pe,Ya as z,Zb as Ge,_b as xe,a as ye,uc as qe}from"./chunk-6ZDKKOKM.js";import{yc as De}from"./chunk-O4YBC3OM.js";import{b as Oe,c as J}from"./chunk-OZCSXX4D.js";import{Ag as Ee,Ai as Te,F as se,Gi as M,I as A,L as ce,Mk as Re,Oi as Ae,Q as de,Qi as O,R as u,Sk as ke,T as c,Va as x,X as G,Z as ue,Zg as Se,Zi as Ie,_ as I,cb as pe,fp as Ce,hc as me,ip as Ne,km as $e,mm as Ue,og as we,pd as fe,qd as q,qg as K,rg as ge,tb as le,ug as ve,wi as be,xg as _e,yg as E,yh as L,zj as Me}from"./chunk-4PNPDT2N.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="4175f7f5-a689-5d05-982a-f92e21bc83e7")}catch{}})();import Xe 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 S=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...se,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function R(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return S.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 k(e,t,n){let i=e?.estimatedMinutes;if(!(i===void 0||typeof i=="string"))throw new c(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,u.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]="78df5b0f-51cd-5c24-a1ee-a1d8433be5df")}catch{}})();var W=["op","id","reason","options","unique","match"],St=[...W,"ref"],Ke=[...St,"item"],bt="mutate-",Le="row-",Je=["schema_version","mutations"],Ze="[a-z][a-z0-9._-]{0,63}",ze=new RegExp(`^${Ze}$`,"u"),Qe=new RegExp(`(^|,)id=@(${Ze})(?=,|$)`,"gu"),Ve=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),$=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],et=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Tt=new Set([...et,"completed_at","id"]),tt={create:Ce.map(e=>e.target),update:Ne.map(e=>e.target),close:Re.map(e=>Ve(e.flag)).filter(e=>e!=="reason"),release:ke.map(e=>Ve(e.flag))};function nt(e){let t=Xe.createHash("sha256").update(e).digest("hex");return`${bt}${t.slice(0,24)}`}function vi(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new c("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let i of["lockTtlSeconds","lockWaitMs"]){let r=e[i];if(r===void 0)continue;let o=typeof r=="number"||typeof r=="string"&&r.trim().length>0?Number(r):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new c(`${i} must be a positive safe integer.`,u.USAGE);t[i]=o}return t}function f(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function U(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),i;for(let r of t){let o=me(e,r,n);o!==null&&(i===void 0||o<i.distance)&&(i={key:r,distance:o})}return i?.key}function b(e,t,n){let i=U(t,n);return new c(i===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${i}"?`,u.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:[i===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${i}".`]})}function H(e,t){try{return JSON.parse(e)}catch(n){let i=n instanceof Error?n.message:String(n);throw new c(`${t} must be valid JSON: ${i}`,u.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 At(e,t){if(!f(e))throw new c(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!W.includes(n))throw b(`mutation ${t+1}`,n,W);return e}function It(e,t,n,i){if(e===void 0)return;if(!f(e))throw new c(`Mutation ${n+1} options must be an object.`,u.USAGE);let r=[...tt[t],...ot(t,i)];for(let o of Object.keys(e))if(!r.includes(o))throw b(`mutation ${n+1} ${t} options`,o,r);return k(e,t,n),e}function We(e,t,n,i){if(e===void 0)return;let r=i==="unique"?"create":"update";if(t!==r)throw new c(`Mutation ${n+1} ${i} is only valid for ${r} operations.`,u.USAGE);let o=f(e)&&typeof e.key=="string"?e.key.trim():"";if(!f(e)||o.length===0||e.value===void 0||e.value===null)throw new c(`Mutation ${n+1} ${i} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Mt(e,t,n){let i=At(e,t),{op:r,id:o,reason:a}=i;if(r!=="create"&&r!=="update"&&r!=="close"&&r!=="release")throw new c(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=It(i.options,r,t,n),d=We(i.unique,r,t,"unique"),p=We(i.match,r,t,"match");if(typeof o!="string"||o.trim().length===0)throw new c(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let l=o.trim();if(r==="close"){if(typeof a!="string"||a.trim().length===0)throw new c(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:r,id:l,reason:a.trim(),...s===void 0?{}:{options:s}}}if(r==="release")return{op:r,id:l,...s===void 0?{}:{options:s}};if(!f(s))throw new c(`Mutation ${t+1} ${r} requires an options object.`,u.USAGE);return{op:r,id:l,options:s,...d===void 0?{}:{unique:d},...p===void 0?{}:{match:p}}}function it(e,t={}){let n=H(e,"Mutation batch"),i=Array.isArray(n)?n:f(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(i===void 0||i.length===0)throw new c("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let r=t.runtimeFields??[];return i.map((o,a)=>{let s=Mt(o,a,r);return s.options!==void 0&&$e(s.options),s})}function Ot(e,t,n){let i=Xe.createHash("sha256").update(e).update("\0").update(t).digest("hex"),r=BigInt(`0x${i.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Ae(n)}${r}`}function Be(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),i=t[n];if(i===void 0)throw new c(`Unknown mutation reference "${e}".`,u.USAGE);return i}function Ye(e,t){if(typeof e!="string")return e;let n=e.replace(Qe,(i,r,o)=>{let a=t[o];if(a===void 0)throw new c(`Unknown mutation reference "@${o}".`,u.USAGE);return`${r}id=${a}`});if(/(^|,)id=@/u.test(n))throw new c(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function Rt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(Qe)].map(t=>t[1]).filter(t=>t!==void 0)}function kt(e,t){let n=new Map;for(let[a,s]of e.entries()){let d=t[a];if(d===void 0)continue;let p=f(s.options)?s.options:{},l=Array.isArray(p.dep)?p.dep:p.dep===void 0?[]:[p.dep];n.set(d,[p.parent,p.blockedBy,...l].flatMap(Rt))}let i=new Set,r=new Set,o=a=>{if(i.has(a))throw new c(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!r.has(a)){i.add(a);for(let s of n.get(a))n.has(s)&&o(s);i.delete(a),r.add(a)}};for(let a of n.keys())o(a)}function $t(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}}}),i=n[0];if(!i.ok&&(i.line.startsWith("[")||i.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&f(o.value)))return null;let r=[];for(let o of n){if(!o.ok)throw new c(`Mutation document line ${o.number} must be one valid JSON object: ${he(o.error)}`,u.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(!f(o.value))throw new c(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);r.push(o.value)}return r}function Ut(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Ct(e){let t;try{t=H(e,"Mutation document")}catch(n){let i=$t(e);if(i===null)throw n;return{schema_version:1,mutations:i}}return Array.isArray(t)?{schema_version:1,mutations:t}:f(t)&&!Ut(t)?{schema_version:1,mutations:[t]}:t}function Nt(e,t){let n=Object.hasOwn(e,"op")?Dt(e,t):jt(e,t);if(n.op==="create"&&n.id===void 0&&f(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new c(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function Dt(e,t){for(let n of Object.keys(e))if(!Ke.includes(n))throw b(`mutation ${t+1}`,n,Ke);if(e.item!==void 0&&e.op!=="create")throw new c(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new c(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function jt(e,t){let{ref:n,id:i,item:r,...o}=e,a=r!==void 0?r:o;if(r!==void 0&&Object.keys(o).length>0)throw new c(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!f(a))throw new c(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...i===void 0?{}:{id:i},item:a}}function Ft(e){let t=Ct(e);if(!f(t))throw new c("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!Je.includes(n))throw b("mutation document",n,Je);if(t.schema_version!==void 0&&t.schema_version!==1)throw new c("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new c("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,i)=>{if(!f(n))throw new c(`Mutation ${i+1} must be an object.`,u.USAGE);return Nt(n,i)})}function Pt(e,t,n){let i=new Set(Object.values(st(t,n,Object.create(null))));for(let r of t)r.op==="create"&&typeof r.id=="string"&&r.id.trim().length>0&&i.add(O(r.id,n.idPrefix));return{...e,existing:e.existing.filter(r=>!i.has(r.id))}}function Gt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,i]of e.entries()){if(i.op!=="create"||i.ref!==void 0||typeof i.id=="string"&&i.id.trim().length>0)continue;let r=`${Le}${n+1}`;if(t.has(r))throw new c(`Mutation ${n+1} receives the synthesized ref "${r}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${Le}<n> aliases are reserved for rows without one.`,u.USAGE);i.ref=r}}function rt(e,t,n){let i=Qt(JSON.stringify(e),t,{},n);return delete i.stdinJson,delete i.documentAnnotationSnapshot,i}function ot(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>E(n))}function xt(e,t){for(let n of e)f(n.item)&&(n.options=rt(n.item,"create",t),delete n.item)}function at(e,t){return t.some(n=>n.metadata_key===e)?e:R(e)}function B(e,t,n){let i=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(f(e.item)){if(e.item[t]!==void 0)return e.item[t];if(at(i,n)===t&&e.item[i]!==void 0)return e.item[i]}let r=f(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&r[E(o)]!==void 0?r[E(o)]:r[t]!==void 0?r[t]:r[i]!==void 0?r[i]:(Array.isArray(r.field)?r.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function qt(e,t){return e<t?-1:+(e!==t)}function Y(e){return Array.isArray(e)?e.map(Y):f(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>qt(t,n)).map(([t,n])=>[t,Y(n)])):e}function g(e){return typeof e=="string"?e.trim():JSON.stringify(Y(e))}function Kt(e,t,n,i,r){let o=t.key.trim();if(o.length===0)throw new c("Upsert key must be a non-empty field name.",u.USAGE);let a=Lt(t.existing),s=new Map,d=new Set;for(let[p,l]of e.entries()){if(l.op!=="create")continue;let y=Jt(l,o,p,s,i),w=zt(a.get(y)??[],o,y);if(w===void 0){l.unique={key:o,value:B(l,o,i)};continue}let h=O(w,n);typeof l.ref=="string"&&(r[l.ref]=h),Vt(l,h,i,{key:o,value:B(l,o,i)}),d.add(p)}return d}function Lt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let i=g(n.value);t.set(i,[...t.get(i)??[],n.id])}return t}function Jt(e,t,n,i,r){let o=B(e,t,r);if(o==null||o==="")throw new c(`Mutation ${n+1} is missing the upsert key "${t}".`,u.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=g(o),s=i.get(a);if(s!==void 0)throw new c(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,u.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 i.set(a,n),a}function zt(e,t,n){if(e.length>1)throw new c(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,u.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 Vt(e,t,n,i){let r=new Set([...tt.update,...ot("update",n)]),o=f(e.item)?rt(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>r.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=i}function st(e,t,n){for(let[i,r]of e.entries())if(r.ref!==void 0){if(r.op!=="create")throw new c(`Mutation ${i+1} ref is only valid for create operations.`,u.USAGE);if(typeof r.ref!="string"||!ze.test(r.ref))throw new c(`Mutation ${i+1} ref must match ${ze.source}.`,u.USAGE);if(n[r.ref]!==void 0)throw new c(`Duplicate mutation ref "${r.ref}".`,u.USAGE);n[r.ref]=typeof r.id=="string"&&r.id.trim().length>0?O(r.id,t.idPrefix):Ot(t.transactionId,r.ref,t.idPrefix)}return n}function ct(e,t){let n=Ft(e);Gt(n);let i=n.map(l=>typeof l.ref=="string"?l.ref:void 0),r=Object.create(null),o=t.upsert===void 0?new Set:Kt(n,Pt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],r);xt(n,t.runtimeFields??[]),st(n,t,r),kt(n,i);let a=n.map(l=>{let y={...l},w=typeof y.ref=="string"?y.ref:void 0;if(delete y.ref,w!==void 0?y.id=r[w]:y.id=Be(y.id,r),f(y.options)){let h={...y.options};for(let _ of["parent","blockedBy"])h[_]!==void 0&&(h[_]=Be(h[_],r));Array.isArray(h.dep)?h.dep=h.dep.map(_=>Ye(_,r)):h.dep!==void 0&&(h.dep=Ye(h.dep,r)),y.options=h}return y}),s=it(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),d=s.filter(l=>l.op==="create").map(l=>l.id);if(new Set(d).size!==d.length)throw new c("Duplicate resolved create id in mutation document.",u.USAGE);let p=s.map((l,y)=>{let w=i[y];return{index:y,...typeof w=="string"?{ref:w}:{},id:l.id,op:l.op,...o.has(y)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:r,rows:p}}function Wt(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let i=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(i)?JSON.stringify(i):i}`}).join(",")}function Bt(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(f))throw new c(`${n} must be an array of objects.`,u.USAGE);return e.map(i=>Wt(i,t))}}function Yt(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 He(e,t,n=!1){for(let[i,r,o]of De){let a=t[i],s=Bt(n&&["comments","notes","learnings"].includes(i)&&Array.isArray(a)?a.filter(d=>!f(d)||d.created_at===void 0):a,o,i);s!==void 0&&s.length>0&&(e[r]=s)}}function Ht(e,t){for(let n of Object.keys(e)){if(t){if(!$.includes(n))throw b("item envelope",n,$);continue}if(!S.has(n)&&U(n,[...S])===void 0&&U(n,$)==="item")throw b("item envelope",n,$)}}function Xt(e){let t=Object.hasOwn(e,"item");Ht(e,t);let n=t?e.item:e;if(!f(n))throw new c("Item document item must be an object.",u.USAGE);return{item:n,...t&&f(e.linked)?{linked:e.linked}:{}}}function Zt(e,t,n,i,r,o){if((i==="update"?Tt:et).has(t))return;let a=r.find(s=>s.metadata_key===t&&s.commands.includes(i));if(a!==void 0){let s=Ee(o,a);e[E(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!S.has(t)){if(U(t,[...S])!==void 0)throw b("item document",t,[...S]);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,d)=>d.toUpperCase())]=Yt(t,n))}function Qt(e,t,n={},i=[]){let r=H(e,"Item document");if(!f(r))throw new c("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=Xt(r),s={};for(let[d,p]of Object.entries(o)){let l=at(d,i);l!==d&&Object.hasOwn(o,l)||Zt(s,l,p,t,i,n)}if(He(s,o,t==="update"),a!==void 0&&He(s,a),t==="update"){let d=Object.fromEntries(["comments","notes","learnings"].filter(p=>Object.hasOwn(o,p)).map(p=>[p,o[p].filter(l=>f(l)&&l.created_at!==void 0)]));Object.keys(d).length>0&&(s.documentAnnotationSnapshot=d)}return{...s,...Object.fromEntries(Object.entries(n).filter(([,d])=>d!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0}}function _i(e){return it(JSON.stringify(e))}import ee from"node:crypto";import{constants as X}from"node:fs";import{cp as en,lstat as ut,mkdir as tn,mkdtemp as pt,open as nn,readdir as rn,realpath as lt,rm as mt,stat as te,writeFile as ft}from"node:fs/promises";import{tmpdir as yt}from"node:os";import m 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]="03112259-10b6-53a9-8e6b-e541ac8c7d5d")}catch{}})();async function ne(e,t){if(!Te(e))return{schema:K(t.schema),typeDefinitionsFromFile:[]};let n=await mn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function ie(e,t,n,i){let r=x({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},q());return(await Me(e,t.item_format,r.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[i];return a==null?[]:[{id:o.id,value:a}]})}function ht(e){let t=new Map,n=async i=>{let r=await M(e),o=await ne(e,r),a=new Map;for(let s of await ie(e,r,o,i)){let d=g(s.value);a.set(d,[...a.get(d)??[],s.id])}return a};return{lookup(i){let r=t.get(i)??n(i);return t.set(i,r),r},async recordCreate(i){for(let[r,o]of t){let a=i[r];if(a==null)continue;let s=await o,d=g(a);s.set(d,[...s.get(d)??[],String(i.id)])}},invalidate(){t.clear()}}}async function on(e,t){let n=g(t.value),i=(await e.lookup(t.key)).get(n)??[];if(i.length!==0)throw new c(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${i.join(", ")}; the plan was resolved before it existed.`,u.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 an(e,t,n){let i=e.metadata[n.key],r=g(n.value);if(g(i)!==r)throw new c(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(r)}; the plan selected it before the key changed.`,u.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 dt(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 j(e,t){let n={...e,...t};return e===void 0?n:Ue(e,n)}async function v(e,t){try{let n=(await z(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 c&&n.exitCode===u.NOT_FOUND)return;throw n}}function re(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),i=ee.createHash("sha256").update(le(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${i}`}function sn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function T(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function F(e,t,n,i){let r=await L(m.join(e,"history",`${t}.jsonl`),t),o=T(n,i,"apply"),a=T(n,i,"compensate");for(let s=r.length-1;s>=0;s-=1){let d=r[s].message;if(d===o)return!0;if(d===a)return!1}return!1}async function oe(e,t){let n=await v(e,t.id);if(n?.updatedAt===void 0)throw new c(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);return{target_updated_at:n.updatedAt}}async function P(e,t,n,i){let r=i!==null&&typeof i=="object"&&!Array.isArray(i)?i.target_updated_at:void 0;typeof r=="string"&&await v(e.pmRoot,t)!==void 0&&await xe(t,r,{force:!0,author:e.author,message:T(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot})}function wt(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);if(i===void 0)return{state:"pending"};if(i.closedAt!==void 0){let r=await L(m.join(e.pmRoot,"history",`${i.id}.jsonl`),i.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(r.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 c(`Created item ${i.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:i.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 ${i.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:i.id,op:"create"}}},async apply(){t.unique!==void 0&&await on(e.uniqueIndex,t.unique);let i=(await je(j(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot})).item;return await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){let i=await v(e.pmRoot,t.id);if(i!==void 0){if(e.createCompensation==="delete"){await Ge(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}i.closedAt===void 0&&await V(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function cn(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=()=>Fe(t.id,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),r=t.match,o=(r===void 0?await i():await Ie({pmRoot:e.pmRoot,id:String((await z(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:a=>an(a,t.id,r)},i)).item;return e.uniqueIndex.invalidate(),{id:String(o.id),op:"update"}},async compensate(i){await P(e,t.id,n,i)}}}function dn(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"close"}}:i.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:i.id,op:"close"}}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=(await V(t.id,t.reason,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(i.id),op:"close"}},async compensate(i){await P(e,t.id,n,i)}}}function un(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"release"}}:i.assignee!==void 0||i.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:i.id,op:"release"}}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=(await Pe(t.id,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(i.id),op:"release"}},async compensate(i){await P(e,t.id,n,i)}}}function gt(e,t,n){let i=re(t,n);switch(t.op){case"create":return wt(e,t,i);case"update":return cn(e,t,i);case"close":return dn(e,t,i);case"release":return un(e,t,i)}}function pn(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&&!dt(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&&!dt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);k(e.options,e.op,t)}function vt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,i]of e.entries()){if(pn(i,n),i.op!=="create"||i.unique===void 0)continue;let{key:r,value:o}=i.unique,a=t.get(r)??new Map,s=g(o),d=a.get(s);if(d!==void 0)throw new c(`Bulk create mutations ${d+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${r}".`,u.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(r,a)}}async function Z(e,t,n){try{return await n()}catch(i){throw i instanceof c?new c(i.message,i.exitCode,{...i.context,transaction_operation:{index:t,op:e.op,id:e.id}}):i}}function _t(e,t,n,i){let r=m.relative(e,t);return["locks","runtime","search"].includes(r.split(m.sep)[0])?i.some(o=>r===o||r.startsWith(`${o}${m.sep}`)||o.startsWith(`${r}${m.sep}`)):r===""||n===void 0||n.some(o=>r===o||r.startsWith(`${o}${m.sep}`)||o.startsWith(`${r}${m.sep}`))}async function N(e){let t=await ut(e);if(t.isSymbolicLink())await te(e);else if(t.isDirectory()||t.isFile())return t;throw I()}async function ln(e){let t=await nn(e,X.O_RDONLY|X.O_NOFOLLOW|X.O_NONBLOCK);try{let n=await t.stat();if(!n.isFile())throw I();let i=ee.createHash("sha256");if(n.size>0)for await(let r of t.createReadStream({highWaterMark:64*1024,end:n.size-1,autoClose:!1}))i.update(r);return i.digest()}finally{await t.close()}}async function Q(e,t,n){let i=ee.createHash("sha256");async function r(o){for(let a of(await rn(o)).sort()){let s=m.join(o,a);_t(e,s,t,n)&&((await N(s)).isDirectory()?await r(s):(i.update(JSON.stringify(m.relative(e,s))),i.update(await ln(s))))}}return await r(e),i.digest("hex")}function C(){return new c("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ae(e){if(!G(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),i=n;for(;;)try{let r=await ut(i);return i!==n&&r.isDirectory()}catch(r){if(!G(r))return!1;let o=m.dirname(i);if(o===i)return!1;i=o}}async function D(e,t){let n=m.join(e,t);try{let i=e;for(let r of t.split(m.sep).slice(0,-1))i=m.join(i,r),await N(i);if(!(await N(n)).isFile())throw I();return await ue(n,I())}catch(i){if(await ae(i))return;throw i}}async function Et(e,t,n,i){let r=K(n);for(let[o,a]of Object.entries(r.files)){let s=m.relative(e,ge(e,a,we[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new c("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",u.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});r.files[o]=s;let d=await D(e,s);if(i?.set(s,d),d!==void 0){let p=m.join(t,s);await tn(m.dirname(p),{recursive:!0}),await ft(p,d)}}return ve(t,r)}async function mn(e,t){await te(e);let n=await pt(m.join(yt(),"pm-schema-plan-"));try{let i=await lt(e);return await Et(i,m.join(n,"configuration"),t)}catch(i){throw await ae(i)?C():i}finally{await mt(n,{recursive:!0,force:!0})}}async function fn(e,t,n){let i=new Map,r=await D(e,A);i.set(A,r);let o;try{o=JSON.parse(r??"null")}catch{o=null}let a=be(o),s=a.success?a.data:void 0,d=await Et(e,t,s?.schema,i),p=d.schema,l=m.relative(e,Se(e));i.set(l,await D(e,l));let y=x({...de,item_types:{definitions:[...s?.item_types?.definitions??[],...d.type_definitions_from_file??[]]}},n),w=pe(e)===e?[...ce.filter(Boolean),A,ye,"transactions",...y.folders,...i.keys()].map(_=>m.normalize(_)):void 0,h=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:p.files}});return{configuration:i,ownedPaths:w,stagedSettings:h,registryFolders:y.folders}}async function yn(e,t,n){await te(e);try{let i=await lt(e),r=await fn(i,m.join(m.dirname(t),"configuration"),n),o=[...r.configuration.keys(),...r.registryFolders].map(p=>m.normalize(p)),a=await Q(i,r.ownedPaths,o);await en(i,t,{recursive:!0,dereference:!1,filter:async p=>_t(i,p,r.ownedPaths,o)?(await N(p),!0):!1});let[s,d]=await Promise.all([Q(i,r.ownedPaths,o),Q(t,r.ownedPaths,o)]);if(a!==s||a!==d)throw C();for(let[p,l]of r.configuration)if(await D(t,p)!==l)throw C();r.stagedSettings!==void 0&&await ft(m.join(t,A),r.stagedSettings)}catch(i){throw await ae(i)?C():i}}async function Wi(e){let t=Oe(e),n=[...e.mutations];vt(n);let i=q(),r=await pt(m.join(yt(),"pm-transaction-preview-")),o=m.join(r,"tracker");try{await yn(t.pmRoot,o,i);let a=!1;return await qe({path:o,noExtensions:!0},async()=>{fe(i);let s={...t,pmRoot:o,createCompensation:"close",uniqueIndex:ht(o)},d=n.map((p,l)=>{let y=gt(s,p,l);return{...y,inspect:()=>Z(p,l,()=>y.inspect()),prepareCompensation:()=>Z(p,l,async()=>y.prepareCompensation?.()),apply:()=>Z(p,l,()=>y.apply())}});await J({...t,pmRoot:o,steps:d,onTransition:({transition:p})=>{p==="committed"&&(a=!0)}})}),{validated:a,state:a?"staged_snapshot":"replayed_committed_plan",unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks"]}}finally{await mt(r,{recursive:!0,force:!0})}}async function hn(e){let t=[...e.mutations];vt(t);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n,uniqueIndex:ht(e.pmRoot)},r=await J({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((a,s)=>gt(i,a,s)),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),o={};for(let[a,s]of t.entries()){let d=re(s,a),p=r.results[d];o[sn(s,a)]=p}return{transactionId:r.transactionId,status:"committed",recovered:r.recovered,results:o}}function wn(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 Bi(e){return hn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:wn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Yi={buildCreateStep:wt,bulkHistoryMarker:T,compensateByRestore:P,deriveStepId:re,isUpdateMarkerApplied:F,readItemSnapshot:v};(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]="3c45eeb2-58f2-58f9-ad24-e439967b99ef")}catch{}})();async function rr(e){let t=e.upsertKey?.trim();if(t!==void 0&&t.length===0)throw new c("Upsert key must be a non-empty field name.",u.USAGE);let n=e.settings??await M(e.pmRoot),i=e.transactionId?.trim()??"",r=i.length>0?i:nt(e.input),o=await ne(e.pmRoot,n),a=_e(o.schema).definitions,s=(a.find(p=>p.metadata_key===t)??a.find(p=>p.key===t||E(p)===t))?.metadata_key??R(t),d=s===void 0?void 0:{key:s,existing:await ie(e.pmRoot,n,o,s)};return{...ct(e.input,{transactionId:r,idPrefix:n.id_prefix,runtimeFields:a,...d===void 0?{}:{upsert:d}}),transaction_id:r,transaction_id_source:i.length>0?"explicit":"derived",...d===void 0?{}:{upsert_key:d.key}}}export{nt as a,vi as b,it as c,g as d,ct as e,Qt as f,_i as g,ne as h,ie as i,mn as j,Wi as k,hn as l,wn as m,Bi as n,Yi as o,rr as p};
2
- //# sourceMappingURL=chunk-HY7FQ7QX.js.map
1
+ import{a as he}from"./chunk-7WIEAGDS.js";import{Rb as je,Sb as Fe,Ub as V,Xb as Pe,Ya as z,Zb as Ge,_b as xe,a as ye,uc as qe}from"./chunk-FIJOSX2C.js";import{yc as De}from"./chunk-PYRREEUB.js";import{b as Oe,c as J}from"./chunk-RNABUEFB.js";import{Ag as Ee,Ai as Te,F as se,Gi as M,I as A,L as ce,Mk as Re,Oi as Ae,Q as de,Qi as O,R as u,Sk as ke,T as c,Va as x,X as G,Z as ue,Zg as Se,Zi as Ie,_ as I,cb as pe,fp as Ce,hc as me,ip as Ne,km as $e,mm as Ue,og as we,pd as fe,qd as q,qg as K,rg as ge,tb as le,ug as ve,wi as be,xg as _e,yg as E,yh as L,zj as Me}from"./chunk-RHQJ6VWC.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="4175f7f5-a689-5d05-982a-f92e21bc83e7")}catch{}})();import Xe 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 S=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...se,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function R(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return S.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 k(e,t,n){let i=e?.estimatedMinutes;if(!(i===void 0||typeof i=="string"))throw new c(`Mutation ${n+1} ${t} option "estimatedMinutes" must be a string.`,u.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]="78df5b0f-51cd-5c24-a1ee-a1d8433be5df")}catch{}})();var W=["op","id","reason","options","unique","match"],St=[...W,"ref"],Ke=[...St,"item"],bt="mutate-",Le="row-",Je=["schema_version","mutations"],Ze="[a-z][a-z0-9._-]{0,63}",ze=new RegExp(`^${Ze}$`,"u"),Qe=new RegExp(`(^|,)id=@(${Ze})(?=,|$)`,"gu"),Ve=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),$=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],et=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Tt=new Set([...et,"completed_at","id"]),tt={create:Ce.map(e=>e.target),update:Ne.map(e=>e.target),close:Re.map(e=>Ve(e.flag)).filter(e=>e!=="reason"),release:ke.map(e=>Ve(e.flag))};function nt(e){let t=Xe.createHash("sha256").update(e).digest("hex");return`${bt}${t.slice(0,24)}`}function vi(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new c("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let i of["lockTtlSeconds","lockWaitMs"]){let r=e[i];if(r===void 0)continue;let o=typeof r=="number"||typeof r=="string"&&r.trim().length>0?Number(r):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new c(`${i} must be a positive safe integer.`,u.USAGE);t[i]=o}return t}function f(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function U(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),i;for(let r of t){let o=me(e,r,n);o!==null&&(i===void 0||o<i.distance)&&(i={key:r,distance:o})}return i?.key}function b(e,t,n){let i=U(t,n);return new c(i===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${i}"?`,u.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:[i===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${i}".`]})}function H(e,t){try{return JSON.parse(e)}catch(n){let i=n instanceof Error?n.message:String(n);throw new c(`${t} must be valid JSON: ${i}`,u.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 At(e,t){if(!f(e))throw new c(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!W.includes(n))throw b(`mutation ${t+1}`,n,W);return e}function It(e,t,n,i){if(e===void 0)return;if(!f(e))throw new c(`Mutation ${n+1} options must be an object.`,u.USAGE);let r=[...tt[t],...ot(t,i)];for(let o of Object.keys(e))if(!r.includes(o))throw b(`mutation ${n+1} ${t} options`,o,r);return k(e,t,n),e}function We(e,t,n,i){if(e===void 0)return;let r=i==="unique"?"create":"update";if(t!==r)throw new c(`Mutation ${n+1} ${i} is only valid for ${r} operations.`,u.USAGE);let o=f(e)&&typeof e.key=="string"?e.key.trim():"";if(!f(e)||o.length===0||e.value===void 0||e.value===null)throw new c(`Mutation ${n+1} ${i} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Mt(e,t,n){let i=At(e,t),{op:r,id:o,reason:a}=i;if(r!=="create"&&r!=="update"&&r!=="close"&&r!=="release")throw new c(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=It(i.options,r,t,n),d=We(i.unique,r,t,"unique"),p=We(i.match,r,t,"match");if(typeof o!="string"||o.trim().length===0)throw new c(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let l=o.trim();if(r==="close"){if(typeof a!="string"||a.trim().length===0)throw new c(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:r,id:l,reason:a.trim(),...s===void 0?{}:{options:s}}}if(r==="release")return{op:r,id:l,...s===void 0?{}:{options:s}};if(!f(s))throw new c(`Mutation ${t+1} ${r} requires an options object.`,u.USAGE);return{op:r,id:l,options:s,...d===void 0?{}:{unique:d},...p===void 0?{}:{match:p}}}function it(e,t={}){let n=H(e,"Mutation batch"),i=Array.isArray(n)?n:f(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(i===void 0||i.length===0)throw new c("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let r=t.runtimeFields??[];return i.map((o,a)=>{let s=Mt(o,a,r);return s.options!==void 0&&$e(s.options),s})}function Ot(e,t,n){let i=Xe.createHash("sha256").update(e).update("\0").update(t).digest("hex"),r=BigInt(`0x${i.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${Ae(n)}${r}`}function Be(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),i=t[n];if(i===void 0)throw new c(`Unknown mutation reference "${e}".`,u.USAGE);return i}function Ye(e,t){if(typeof e!="string")return e;let n=e.replace(Qe,(i,r,o)=>{let a=t[o];if(a===void 0)throw new c(`Unknown mutation reference "@${o}".`,u.USAGE);return`${r}id=${a}`});if(/(^|,)id=@/u.test(n))throw new c(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function Rt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(Qe)].map(t=>t[1]).filter(t=>t!==void 0)}function kt(e,t){let n=new Map;for(let[a,s]of e.entries()){let d=t[a];if(d===void 0)continue;let p=f(s.options)?s.options:{},l=Array.isArray(p.dep)?p.dep:p.dep===void 0?[]:[p.dep];n.set(d,[p.parent,p.blockedBy,...l].flatMap(Rt))}let i=new Set,r=new Set,o=a=>{if(i.has(a))throw new c(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!r.has(a)){i.add(a);for(let s of n.get(a))n.has(s)&&o(s);i.delete(a),r.add(a)}};for(let a of n.keys())o(a)}function $t(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}}}),i=n[0];if(!i.ok&&(i.line.startsWith("[")||i.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&f(o.value)))return null;let r=[];for(let o of n){if(!o.ok)throw new c(`Mutation document line ${o.number} must be one valid JSON object: ${he(o.error)}`,u.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(!f(o.value))throw new c(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);r.push(o.value)}return r}function Ut(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Ct(e){let t;try{t=H(e,"Mutation document")}catch(n){let i=$t(e);if(i===null)throw n;return{schema_version:1,mutations:i}}return Array.isArray(t)?{schema_version:1,mutations:t}:f(t)&&!Ut(t)?{schema_version:1,mutations:[t]}:t}function Nt(e,t){let n=Object.hasOwn(e,"op")?Dt(e,t):jt(e,t);if(n.op==="create"&&n.id===void 0&&f(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new c(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function Dt(e,t){for(let n of Object.keys(e))if(!Ke.includes(n))throw b(`mutation ${t+1}`,n,Ke);if(e.item!==void 0&&e.op!=="create")throw new c(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new c(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function jt(e,t){let{ref:n,id:i,item:r,...o}=e,a=r!==void 0?r:o;if(r!==void 0&&Object.keys(o).length>0)throw new c(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!f(a))throw new c(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...i===void 0?{}:{id:i},item:a}}function Ft(e){let t=Ct(e);if(!f(t))throw new c("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!Je.includes(n))throw b("mutation document",n,Je);if(t.schema_version!==void 0&&t.schema_version!==1)throw new c("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new c("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,i)=>{if(!f(n))throw new c(`Mutation ${i+1} must be an object.`,u.USAGE);return Nt(n,i)})}function Pt(e,t,n){let i=new Set(Object.values(st(t,n,Object.create(null))));for(let r of t)r.op==="create"&&typeof r.id=="string"&&r.id.trim().length>0&&i.add(O(r.id,n.idPrefix));return{...e,existing:e.existing.filter(r=>!i.has(r.id))}}function Gt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,i]of e.entries()){if(i.op!=="create"||i.ref!==void 0||typeof i.id=="string"&&i.id.trim().length>0)continue;let r=`${Le}${n+1}`;if(t.has(r))throw new c(`Mutation ${n+1} receives the synthesized ref "${r}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${Le}<n> aliases are reserved for rows without one.`,u.USAGE);i.ref=r}}function rt(e,t,n){let i=Qt(JSON.stringify(e),t,{},n);return delete i.stdinJson,delete i.documentAnnotationSnapshot,i}function ot(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>E(n))}function xt(e,t){for(let n of e)f(n.item)&&(n.options=rt(n.item,"create",t),delete n.item)}function at(e,t){return t.some(n=>n.metadata_key===e)?e:R(e)}function B(e,t,n){let i=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(f(e.item)){if(e.item[t]!==void 0)return e.item[t];if(at(i,n)===t&&e.item[i]!==void 0)return e.item[i]}let r=f(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&r[E(o)]!==void 0?r[E(o)]:r[t]!==void 0?r[t]:r[i]!==void 0?r[i]:(Array.isArray(r.field)?r.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function qt(e,t){return e<t?-1:+(e!==t)}function Y(e){return Array.isArray(e)?e.map(Y):f(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>qt(t,n)).map(([t,n])=>[t,Y(n)])):e}function g(e){return typeof e=="string"?e.trim():JSON.stringify(Y(e))}function Kt(e,t,n,i,r){let o=t.key.trim();if(o.length===0)throw new c("Upsert key must be a non-empty field name.",u.USAGE);let a=Lt(t.existing),s=new Map,d=new Set;for(let[p,l]of e.entries()){if(l.op!=="create")continue;let y=Jt(l,o,p,s,i),w=zt(a.get(y)??[],o,y);if(w===void 0){l.unique={key:o,value:B(l,o,i)};continue}let h=O(w,n);typeof l.ref=="string"&&(r[l.ref]=h),Vt(l,h,i,{key:o,value:B(l,o,i)}),d.add(p)}return d}function Lt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let i=g(n.value);t.set(i,[...t.get(i)??[],n.id])}return t}function Jt(e,t,n,i,r){let o=B(e,t,r);if(o==null||o==="")throw new c(`Mutation ${n+1} is missing the upsert key "${t}".`,u.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=g(o),s=i.get(a);if(s!==void 0)throw new c(`Mutations ${s+1} and ${n+1} share the upsert key value ${JSON.stringify(a)} for "${t}".`,u.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 i.set(a,n),a}function zt(e,t,n){if(e.length>1)throw new c(`Upsert key "${t}" value ${JSON.stringify(n)} matches ${e.length} existing items: ${e.join(", ")}.`,u.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 Vt(e,t,n,i){let r=new Set([...tt.update,...ot("update",n)]),o=f(e.item)?rt(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>r.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=i}function st(e,t,n){for(let[i,r]of e.entries())if(r.ref!==void 0){if(r.op!=="create")throw new c(`Mutation ${i+1} ref is only valid for create operations.`,u.USAGE);if(typeof r.ref!="string"||!ze.test(r.ref))throw new c(`Mutation ${i+1} ref must match ${ze.source}.`,u.USAGE);if(n[r.ref]!==void 0)throw new c(`Duplicate mutation ref "${r.ref}".`,u.USAGE);n[r.ref]=typeof r.id=="string"&&r.id.trim().length>0?O(r.id,t.idPrefix):Ot(t.transactionId,r.ref,t.idPrefix)}return n}function ct(e,t){let n=Ft(e);Gt(n);let i=n.map(l=>typeof l.ref=="string"?l.ref:void 0),r=Object.create(null),o=t.upsert===void 0?new Set:Kt(n,Pt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],r);xt(n,t.runtimeFields??[]),st(n,t,r),kt(n,i);let a=n.map(l=>{let y={...l},w=typeof y.ref=="string"?y.ref:void 0;if(delete y.ref,w!==void 0?y.id=r[w]:y.id=Be(y.id,r),f(y.options)){let h={...y.options};for(let _ of["parent","blockedBy"])h[_]!==void 0&&(h[_]=Be(h[_],r));Array.isArray(h.dep)?h.dep=h.dep.map(_=>Ye(_,r)):h.dep!==void 0&&(h.dep=Ye(h.dep,r)),y.options=h}return y}),s=it(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),d=s.filter(l=>l.op==="create").map(l=>l.id);if(new Set(d).size!==d.length)throw new c("Duplicate resolved create id in mutation document.",u.USAGE);let p=s.map((l,y)=>{let w=i[y];return{index:y,...typeof w=="string"?{ref:w}:{},id:l.id,op:l.op,...o.has(y)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:r,rows:p}}function Wt(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let i=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(i)?JSON.stringify(i):i}`}).join(",")}function Bt(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(f))throw new c(`${n} must be an array of objects.`,u.USAGE);return e.map(i=>Wt(i,t))}}function Yt(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 He(e,t,n=!1){for(let[i,r,o]of De){let a=t[i],s=Bt(n&&["comments","notes","learnings"].includes(i)&&Array.isArray(a)?a.filter(d=>!f(d)||d.created_at===void 0):a,o,i);s!==void 0&&s.length>0&&(e[r]=s)}}function Ht(e,t){for(let n of Object.keys(e)){if(t){if(!$.includes(n))throw b("item envelope",n,$);continue}if(!S.has(n)&&U(n,[...S])===void 0&&U(n,$)==="item")throw b("item envelope",n,$)}}function Xt(e){let t=Object.hasOwn(e,"item");Ht(e,t);let n=t?e.item:e;if(!f(n))throw new c("Item document item must be an object.",u.USAGE);return{item:n,...t&&f(e.linked)?{linked:e.linked}:{}}}function Zt(e,t,n,i,r,o){if((i==="update"?Tt:et).has(t))return;let a=r.find(s=>s.metadata_key===t&&s.commands.includes(i));if(a!==void 0){let s=Ee(o,a);e[E(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!S.has(t)){if(U(t,[...S])!==void 0)throw b("item document",t,[...S]);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,d)=>d.toUpperCase())]=Yt(t,n))}function Qt(e,t,n={},i=[]){let r=H(e,"Item document");if(!f(r))throw new c("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=Xt(r),s={};for(let[d,p]of Object.entries(o)){let l=at(d,i);l!==d&&Object.hasOwn(o,l)||Zt(s,l,p,t,i,n)}if(He(s,o,t==="update"),a!==void 0&&He(s,a),t==="update"){let d=Object.fromEntries(["comments","notes","learnings"].filter(p=>Object.hasOwn(o,p)).map(p=>[p,o[p].filter(l=>f(l)&&l.created_at!==void 0)]));Object.keys(d).length>0&&(s.documentAnnotationSnapshot=d)}return{...s,...Object.fromEntries(Object.entries(n).filter(([,d])=>d!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0}}function _i(e){return it(JSON.stringify(e))}import ee from"node:crypto";import{constants as X}from"node:fs";import{cp as en,lstat as ut,mkdir as tn,mkdtemp as pt,open as nn,readdir as rn,realpath as lt,rm as mt,stat as te,writeFile as ft}from"node:fs/promises";import{tmpdir as yt}from"node:os";import m 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]="03112259-10b6-53a9-8e6b-e541ac8c7d5d")}catch{}})();async function ne(e,t){if(!Te(e))return{schema:K(t.schema),typeDefinitionsFromFile:[]};let n=await mn(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function ie(e,t,n,i){let r=x({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},q());return(await Me(e,t.item_format,r.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[i];return a==null?[]:[{id:o.id,value:a}]})}function ht(e){let t=new Map,n=async i=>{let r=await M(e),o=await ne(e,r),a=new Map;for(let s of await ie(e,r,o,i)){let d=g(s.value);a.set(d,[...a.get(d)??[],s.id])}return a};return{lookup(i){let r=t.get(i)??n(i);return t.set(i,r),r},async recordCreate(i){for(let[r,o]of t){let a=i[r];if(a==null)continue;let s=await o,d=g(a);s.set(d,[...s.get(d)??[],String(i.id)])}},invalidate(){t.clear()}}}async function on(e,t){let n=g(t.value),i=(await e.lookup(t.key)).get(n)??[];if(i.length!==0)throw new c(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${i.join(", ")}; the plan was resolved before it existed.`,u.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 an(e,t,n){let i=e.metadata[n.key],r=g(n.value);if(g(i)!==r)throw new c(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(r)}; the plan selected it before the key changed.`,u.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 dt(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 j(e,t){let n={...e,...t};return e===void 0?n:Ue(e,n)}async function v(e,t){try{let n=(await z(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 c&&n.exitCode===u.NOT_FOUND)return;throw n}}function re(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),i=ee.createHash("sha256").update(le(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${i}`}function sn(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function T(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function F(e,t,n,i){let r=await L(m.join(e,"history",`${t}.jsonl`),t),o=T(n,i,"apply"),a=T(n,i,"compensate");for(let s=r.length-1;s>=0;s-=1){let d=r[s].message;if(d===o)return!0;if(d===a)return!1}return!1}async function oe(e,t){let n=await v(e,t.id);if(n?.updatedAt===void 0)throw new c(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);return{target_updated_at:n.updatedAt}}async function P(e,t,n,i){let r=i!==null&&typeof i=="object"&&!Array.isArray(i)?i.target_updated_at:void 0;typeof r=="string"&&await v(e.pmRoot,t)!==void 0&&await xe(t,r,{force:!0,author:e.author,message:T(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot})}function wt(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);if(i===void 0)return{state:"pending"};if(i.closedAt!==void 0){let r=await L(m.join(e.pmRoot,"history",`${i.id}.jsonl`),i.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(r.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 c(`Created item ${i.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:i.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 ${i.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:i.id,op:"create"}}},async apply(){t.unique!==void 0&&await on(e.uniqueIndex,t.unique);let i=(await je(j(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot})).item;return await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){let i=await v(e.pmRoot,t.id);if(i!==void 0){if(e.createCompensation==="delete"){await Ge(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}i.closedAt===void 0&&await V(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function cn(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=()=>Fe(t.id,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),r=t.match,o=(r===void 0?await i():await Ie({pmRoot:e.pmRoot,id:String((await z(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:a=>an(a,t.id,r)},i)).item;return e.uniqueIndex.invalidate(),{id:String(o.id),op:"update"}},async compensate(i){await P(e,t.id,n,i)}}}function dn(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"close"}}:i.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:i.id,op:"close"}}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=(await V(t.id,t.reason,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(i.id),op:"close"}},async compensate(i){await P(e,t.id,n,i)}}}function un(e,t,n){return{id:n,async inspect(){let i=await v(e.pmRoot,t.id);return i===void 0?{state:"pending"}:await F(e.pmRoot,i.id,e.transactionId,n)?{state:"applied",result:{id:i.id,op:"release"}}:i.assignee!==void 0||i.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:i.id,op:"release"}}},async prepareCompensation(){return oe(e.pmRoot,t)},async apply(){let i=(await Pe(t.id,j(t.options,{author:e.author,message:T(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(i.id),op:"release"}},async compensate(i){await P(e,t.id,n,i)}}}function gt(e,t,n){let i=re(t,n);switch(t.op){case"create":return wt(e,t,i);case"update":return cn(e,t,i);case"close":return dn(e,t,i);case"release":return un(e,t,i)}}function pn(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&&!dt(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&&!dt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);k(e.options,e.op,t)}function vt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,i]of e.entries()){if(pn(i,n),i.op!=="create"||i.unique===void 0)continue;let{key:r,value:o}=i.unique,a=t.get(r)??new Map,s=g(o),d=a.get(s);if(d!==void 0)throw new c(`Bulk create mutations ${d+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${r}".`,u.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(r,a)}}async function Z(e,t,n){try{return await n()}catch(i){throw i instanceof c?new c(i.message,i.exitCode,{...i.context,transaction_operation:{index:t,op:e.op,id:e.id}}):i}}function _t(e,t,n,i){let r=m.relative(e,t);return["locks","runtime","search"].includes(r.split(m.sep)[0])?i.some(o=>r===o||r.startsWith(`${o}${m.sep}`)||o.startsWith(`${r}${m.sep}`)):r===""||n===void 0||n.some(o=>r===o||r.startsWith(`${o}${m.sep}`)||o.startsWith(`${r}${m.sep}`))}async function N(e){let t=await ut(e);if(t.isSymbolicLink())await te(e);else if(t.isDirectory()||t.isFile())return t;throw I()}async function ln(e){let t=await nn(e,X.O_RDONLY|X.O_NOFOLLOW|X.O_NONBLOCK);try{let n=await t.stat();if(!n.isFile())throw I();let i=ee.createHash("sha256");if(n.size>0)for await(let r of t.createReadStream({highWaterMark:64*1024,end:n.size-1,autoClose:!1}))i.update(r);return i.digest()}finally{await t.close()}}async function Q(e,t,n){let i=ee.createHash("sha256");async function r(o){for(let a of(await rn(o)).sort()){let s=m.join(o,a);_t(e,s,t,n)&&((await N(s)).isDirectory()?await r(s):(i.update(JSON.stringify(m.relative(e,s))),i.update(await ln(s))))}}return await r(e),i.digest("hex")}function C(){return new c("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ae(e){if(!G(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),i=n;for(;;)try{let r=await ut(i);return i!==n&&r.isDirectory()}catch(r){if(!G(r))return!1;let o=m.dirname(i);if(o===i)return!1;i=o}}async function D(e,t){let n=m.join(e,t);try{let i=e;for(let r of t.split(m.sep).slice(0,-1))i=m.join(i,r),await N(i);if(!(await N(n)).isFile())throw I();return await ue(n,I())}catch(i){if(await ae(i))return;throw i}}async function Et(e,t,n,i){let r=K(n);for(let[o,a]of Object.entries(r.files)){let s=m.relative(e,ge(e,a,we[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new c("Transaction preview requires schema files inside the selected tracker root; relocate the configured schema file before retrying.",u.USAGE,{code:"transaction_preview_external_schema",field:`schema.files.${o}`});r.files[o]=s;let d=await D(e,s);if(i?.set(s,d),d!==void 0){let p=m.join(t,s);await tn(m.dirname(p),{recursive:!0}),await ft(p,d)}}return ve(t,r)}async function mn(e,t){await te(e);let n=await pt(m.join(yt(),"pm-schema-plan-"));try{let i=await lt(e);return await Et(i,m.join(n,"configuration"),t)}catch(i){throw await ae(i)?C():i}finally{await mt(n,{recursive:!0,force:!0})}}async function fn(e,t,n){let i=new Map,r=await D(e,A);i.set(A,r);let o;try{o=JSON.parse(r??"null")}catch{o=null}let a=be(o),s=a.success?a.data:void 0,d=await Et(e,t,s?.schema,i),p=d.schema,l=m.relative(e,Se(e));i.set(l,await D(e,l));let y=x({...de,item_types:{definitions:[...s?.item_types?.definitions??[],...d.type_definitions_from_file??[]]}},n),w=pe(e)===e?[...ce.filter(Boolean),A,ye,"transactions",...y.folders,...i.keys()].map(_=>m.normalize(_)):void 0,h=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:p.files}});return{configuration:i,ownedPaths:w,stagedSettings:h,registryFolders:y.folders}}async function yn(e,t,n){await te(e);try{let i=await lt(e),r=await fn(i,m.join(m.dirname(t),"configuration"),n),o=[...r.configuration.keys(),...r.registryFolders].map(p=>m.normalize(p)),a=await Q(i,r.ownedPaths,o);await en(i,t,{recursive:!0,dereference:!1,filter:async p=>_t(i,p,r.ownedPaths,o)?(await N(p),!0):!1});let[s,d]=await Promise.all([Q(i,r.ownedPaths,o),Q(t,r.ownedPaths,o)]);if(a!==s||a!==d)throw C();for(let[p,l]of r.configuration)if(await D(t,p)!==l)throw C();r.stagedSettings!==void 0&&await ft(m.join(t,A),r.stagedSettings)}catch(i){throw await ae(i)?C():i}}async function Wi(e){let t=Oe(e),n=[...e.mutations];vt(n);let i=q(),r=await pt(m.join(yt(),"pm-transaction-preview-")),o=m.join(r,"tracker");try{await yn(t.pmRoot,o,i);let a=!1;return await qe({path:o,noExtensions:!0},async()=>{fe(i);let s={...t,pmRoot:o,createCompensation:"close",uniqueIndex:ht(o)},d=n.map((p,l)=>{let y=gt(s,p,l);return{...y,inspect:()=>Z(p,l,()=>y.inspect()),prepareCompensation:()=>Z(p,l,async()=>y.prepareCompensation?.()),apply:()=>Z(p,l,()=>y.apply())}});await J({...t,pmRoot:o,steps:d,onTransition:({transition:p})=>{p==="committed"&&(a=!0)}})}),{validated:a,state:a?"staged_snapshot":"replayed_committed_plan",unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks"]}}finally{await mt(r,{recursive:!0,force:!0})}}async function hn(e){let t=[...e.mutations];vt(t);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let i={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n,uniqueIndex:ht(e.pmRoot)},r=await J({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((a,s)=>gt(i,a,s)),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}}),o={};for(let[a,s]of t.entries()){let d=re(s,a),p=r.results[d];o[sn(s,a)]=p}return{transactionId:r.transactionId,status:"committed",recovered:r.recovered,results:o}}function wn(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 Bi(e){return hn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:wn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var Yi={buildCreateStep:wt,bulkHistoryMarker:T,compensateByRestore:P,deriveStepId:re,isUpdateMarkerApplied:F,readItemSnapshot:v};(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]="3c45eeb2-58f2-58f9-ad24-e439967b99ef")}catch{}})();async function rr(e){let t=e.upsertKey?.trim();if(t!==void 0&&t.length===0)throw new c("Upsert key must be a non-empty field name.",u.USAGE);let n=e.settings??await M(e.pmRoot),i=e.transactionId?.trim()??"",r=i.length>0?i:nt(e.input),o=await ne(e.pmRoot,n),a=_e(o.schema).definitions,s=(a.find(p=>p.metadata_key===t)??a.find(p=>p.key===t||E(p)===t))?.metadata_key??R(t),d=s===void 0?void 0:{key:s,existing:await ie(e.pmRoot,n,o,s)};return{...ct(e.input,{transactionId:r,idPrefix:n.id_prefix,runtimeFields:a,...d===void 0?{}:{upsert:d}}),transaction_id:r,transaction_id_source:i.length>0?"explicit":"derived",...d===void 0?{}:{upsert_key:d.key}}}export{nt as a,vi as b,it as c,g as d,ct as e,Qt as f,_i as g,ne as h,ie as i,mn as j,Wi as k,hn as l,wn as m,Bi as n,Yi as o,rr as p};
2
+ //# sourceMappingURL=chunk-TO6CIV4C.js.map