@unbrained/pm-cli 2026.10.27 → 2026.10.28

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 (120) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +23 -0
  3. package/dist/cli/commander-usage.js +2 -2
  4. package/dist/cli/error-guidance.js +2 -2
  5. package/dist/cli-bundle/bundle-manifest.json +1 -1
  6. package/dist/cli-bundle/chunks/chunk-2J7I54MQ.js +2 -0
  7. package/dist/cli-bundle/chunks/{chunk-25MTQAHX.js → chunk-3KMYHYJV.js} +2 -2
  8. package/dist/cli-bundle/chunks/{chunk-UHKN6TJM.js → chunk-7V37RC2L.js} +44 -44
  9. package/dist/cli-bundle/chunks/{chunk-5PTMQBKJ.js → chunk-AHVN4GHF.js} +30 -29
  10. package/dist/cli-bundle/chunks/{chunk-QQYLNHZK.js → chunk-CS7QDSUX.js} +28 -28
  11. package/dist/cli-bundle/chunks/{chunk-34OQP43K.js → chunk-CXUQEZDX.js} +3 -3
  12. package/dist/cli-bundle/chunks/{chunk-X5TMR7KC.js → chunk-D3AIQZXF.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-NNIYQHYT.js → chunk-D6P6IBPN.js} +2 -2
  14. package/dist/cli-bundle/chunks/{chunk-HIX2OMEZ.js → chunk-DKLEDWVW.js} +2 -2
  15. package/dist/cli-bundle/chunks/{chunk-2XUDAQK5.js → chunk-DM3PICGU.js} +2 -2
  16. package/dist/cli-bundle/chunks/{chunk-32QK43XG.js → chunk-E5QBZ4HI.js} +2 -2
  17. package/dist/cli-bundle/chunks/{chunk-H434DKYU.js → chunk-JESLOJD7.js} +2 -2
  18. package/dist/cli-bundle/chunks/{chunk-57YPOOED.js → chunk-LWW4F4G2.js} +2 -2
  19. package/dist/cli-bundle/chunks/{chunk-O3LPT34G.js → chunk-PQLRKFPZ.js} +3 -3
  20. package/dist/cli-bundle/chunks/{chunk-ONC4BBQP.js → chunk-RZQNFHXO.js} +2 -2
  21. package/dist/cli-bundle/chunks/{chunk-ER7RLJW5.js → chunk-TH5KPAN4.js} +2 -2
  22. package/dist/cli-bundle/chunks/{chunk-F26MRQZY.js → chunk-XHONSCLJ.js} +6 -6
  23. package/dist/cli-bundle/chunks/{chunk-EKV5GP6P.js → chunk-YUBUNECD.js} +42 -42
  24. package/dist/cli-bundle/chunks/{chunk-OQOEBWHU.js → chunk-YYD5MNAV.js} +2 -2
  25. package/dist/cli-bundle/chunks/{chunk-Q55KZDNF.js → chunk-ZX3XMTZG.js} +2 -2
  26. package/dist/cli-bundle/chunks/{indexed-receipt-blobs-63WYG2PY.js → indexed-receipt-blobs-LHLE7PSG.js} +2 -2
  27. package/dist/cli-bundle/chunks/{mutation-admission-L3A6FSZ7.js → mutation-admission-GKDKHRTZ.js} +2 -2
  28. package/dist/cli-bundle/chunks/{register-list-query-YSQ7UTFI.js → register-list-query-MHJJUM6M.js} +2 -2
  29. package/dist/cli-bundle/chunks/{register-mutation-6HRXYASW.js → register-mutation-SN425O3R.js} +2 -2
  30. package/dist/cli-bundle/chunks/{register-operations-4O3YOYXF.js → register-operations-EYUIUGPW.js} +2 -2
  31. package/dist/cli-bundle/chunks/{register-setup-3WAXNDMY.js → register-setup-WUZ2ZSMY.js} +2 -2
  32. package/dist/cli-bundle/chunks/{settlement-hook-CRW6PVQK.js → settlement-hook-MN3Y7LVX.js} +2 -2
  33. package/dist/cli-bundle/chunks/{stage-I46WD4EN.js → stage-2FYJGGG3.js} +2 -2
  34. package/dist/cli-bundle/focused-chunks/chunk-3EHVI673.js +2 -0
  35. package/dist/cli-bundle/focused-chunks/{chunk-ZA6AEYIM.js → chunk-46WLWK73.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/{chunk-E5C24MCV.js → chunk-4GN2ZPT5.js} +2 -2
  37. package/dist/cli-bundle/focused-chunks/{chunk-NLZUI234.js → chunk-6L4KKRK7.js} +18 -18
  38. package/dist/cli-bundle/focused-chunks/{chunk-WDKZB3V6.js → chunk-6VDRAJYX.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/{chunk-KTXU5WU6.js → chunk-7SZPZOIC.js} +2 -2
  40. package/dist/cli-bundle/focused-chunks/{chunk-YQKLKRMW.js → chunk-B4ZQJEMT.js} +2 -2
  41. package/dist/cli-bundle/focused-chunks/{chunk-J67PFM3O.js → chunk-BZSACRVX.js} +3 -3
  42. package/dist/cli-bundle/focused-chunks/{chunk-Y57A4ZDI.js → chunk-C2GLO7HU.js} +3 -3
  43. package/dist/cli-bundle/focused-chunks/{chunk-R2MTHS2H.js → chunk-DRN4W3YJ.js} +2 -2
  44. package/dist/cli-bundle/focused-chunks/{chunk-TAFMNTA5.js → chunk-F6UQJJYB.js} +2 -2
  45. package/dist/cli-bundle/focused-chunks/{chunk-TGUOEOKP.js → chunk-I4X6AKOO.js} +2 -2
  46. package/dist/cli-bundle/focused-chunks/{chunk-SM2KGD4J.js → chunk-IQKLJFJE.js} +2 -2
  47. package/dist/cli-bundle/focused-chunks/{chunk-XK3XMZM4.js → chunk-JTCGDODH.js} +2 -2
  48. package/dist/cli-bundle/focused-chunks/{chunk-HWD63G54.js → chunk-L5GX2FGZ.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/{chunk-MVY6JDIH.js → chunk-LPWZERVD.js} +11 -11
  50. package/dist/cli-bundle/focused-chunks/{chunk-YW5GHQN2.js → chunk-ML5JIUM6.js} +2 -2
  51. package/dist/cli-bundle/focused-chunks/{chunk-YC6NCPLK.js → chunk-OASYSUOH.js} +16 -16
  52. package/dist/cli-bundle/focused-chunks/{chunk-BH7RE2ZY.js → chunk-ON5WFDCG.js} +2 -2
  53. package/dist/cli-bundle/focused-chunks/{chunk-4TXZBGOR.js → chunk-QUPGBO2L.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/{chunk-SYL73MEI.js → chunk-R3EA3SDW.js} +3 -3
  55. package/dist/cli-bundle/focused-chunks/{chunk-B266DDBJ.js → chunk-TUN4M757.js} +2 -2
  56. package/dist/cli-bundle/focused-chunks/{chunk-ZH7GTEWL.js → chunk-Z26ZPQH6.js} +2 -2
  57. package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-GAFC52LQ.js → indexed-receipt-blobs-5H6RMRTK.js} +2 -2
  58. package/dist/cli-bundle/focused-chunks/{mutation-admission-ENBFMV2X.js → mutation-admission-TM3SVU2O.js} +2 -2
  59. package/dist/cli-bundle/focused-chunks/{settlement-hook-PUYJJDFL.js → settlement-hook-LBVWWSCF.js} +2 -2
  60. package/dist/cli-bundle/focused-chunks/{stage-MAWZTM2H.js → stage-7ZBRX2Q2.js} +2 -2
  61. package/dist/cli-bundle/main.js +21 -21
  62. package/dist/cli-bundle/sdk-authoring.js +1 -1
  63. package/dist/cli-bundle/sdk-contracts.js +1 -1
  64. package/dist/cli-bundle/sdk-core.js +25 -24
  65. package/dist/cli-bundle/sdk-governance.js +1 -1
  66. package/dist/cli-bundle/sdk-graph.js +1 -1
  67. package/dist/cli-bundle/sdk-merge.js +46 -46
  68. package/dist/cli-bundle/sdk-query.js +1 -1
  69. package/dist/cli-bundle/sdk-runtime.js +1 -1
  70. package/dist/cli-bundle/sdk-testing.js +1 -1
  71. package/dist/cli-bundle/sdk.js +11 -11
  72. package/dist/core/item/priority.js +1 -1
  73. package/dist/core/shared/errors.d.ts +2 -0
  74. package/dist/core/shared/errors.js +1 -1
  75. package/dist/core/store/item-store.js +1 -1
  76. package/dist/sdk/agent/command-recovery.d.ts +5 -0
  77. package/dist/sdk/agent/command-recovery.js +1 -1
  78. package/dist/sdk/command-line.d.ts +6 -0
  79. package/dist/sdk/command-line.js +1 -1
  80. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +1 -1
  81. package/dist/sdk/index.d.ts +1 -1
  82. package/dist/sdk/index.js +1 -1
  83. package/dist/sdk/lifecycle/close.js +1 -1
  84. package/dist/sdk/lifecycle/create.js +1 -1
  85. package/dist/sdk/lifecycle/update-many.js +1 -1
  86. package/dist/sdk/lifecycle/update.js +1 -1
  87. package/dist/sdk/public-surface.json +1 -1
  88. package/dist/sdk/query/history.d.ts +4 -0
  89. package/dist/sdk/query/history.js +1 -1
  90. package/dist/sdk/runtime/actions.js +1 -1
  91. package/dist/sdk/runtime.js +1 -1
  92. package/dist/sdk/test/command-resolution.d.ts +5 -0
  93. package/dist/sdk/test/command-resolution.js +3 -0
  94. package/dist/sdk/test/execution.js +2 -2
  95. package/docs/COMMANDS.md +28 -1
  96. package/docs/SDK.md +40 -0
  97. package/docs/TESTING.md +28 -2
  98. package/marketplace.json +1 -1
  99. package/package.json +1 -1
  100. package/packages/pm-beads/package.json +1 -1
  101. package/packages/pm-calendar/package.json +1 -1
  102. package/packages/pm-command-kit/package.json +1 -1
  103. package/packages/pm-digital-twin/package.json +1 -1
  104. package/packages/pm-governance-audit/package.json +1 -1
  105. package/packages/pm-guide-shell/package.json +1 -1
  106. package/packages/pm-kanban/package.json +1 -1
  107. package/packages/pm-lifecycle-hooks/package.json +1 -1
  108. package/packages/pm-linked-test-adapters/package.json +1 -1
  109. package/packages/pm-search-advanced/package.json +1 -1
  110. package/packages/pm-templates/package.json +1 -1
  111. package/packages/pm-todos/package.json +1 -1
  112. package/packages/pm-vcs/package.json +1 -1
  113. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  114. package/plugins/pm-claude/package.json +1 -1
  115. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  116. package/plugins/pm-codex/package.json +1 -1
  117. package/plugins/pm-codex/plugin.json +1 -1
  118. package/runtime-dependencies.json +1 -1
  119. package/dist/cli-bundle/chunks/chunk-XERBUA6A.js +0 -2
  120. package/dist/cli-bundle/focused-chunks/chunk-U4UBQBS7.js +0 -2
@@ -1,2 +1,2 @@
1
- import{da as p,ea as i,fa as v,ga as _}from"./chunk-NNIYQHYT.js";import{za as h}from"./chunk-UHKN6TJM.js";import u from"node:fs/promises";import c from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="846100a9-4314-5f7c-b892-fa16e09bee5b")}catch{}})();function f(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}function y(e){return e!=="invalid"&&e!=="unreadable"}function j(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw new SyntaxError("Invalid settings object");let r=t.extensions;if(r===void 0)return{enabled:[],disabled:[]};if(typeof r!="object"||r===null||Array.isArray(r))throw new SyntaxError("Invalid extensions settings");let n=r;if(n.enabled!==void 0&&(!Array.isArray(n.enabled)||!n.enabled.every(a=>typeof a=="string"))||n.disabled!==void 0&&(!Array.isArray(n.disabled)||!n.disabled.every(a=>typeof a=="string")))throw new SyntaxError("Invalid extension enablement lists");return{enabled:n.enabled??[],disabled:n.disabled??[]}}async function S(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{status:"absent",enabled:[],disabled:[]}:{status:"unreadable",enabled:[],disabled:[],error:{code:"settings_unreadable",path:e}}}try{return{status:"ok",...j(t)}}catch{return{status:"invalid",enabled:[],disabled:[],error:{code:"settings_invalid",path:e}}}}async function A(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){if(f(r))try{if((await u.stat(c.dirname(e))).isDirectory())return{status:"absent",entries:[]}}catch(n){if(f(n))return{status:"absent",entries:[]}}return{status:"unreadable",entries:[],error:{code:"managed_state_unreadable",path:e}}}try{let r=JSON.parse(t),n=_(r);if(!n||typeof r!="object"||r===null||!Array.isArray(r.entries)||n.entries.length!==r.entries.length)throw new SyntaxError("Invalid managed extension state");return{status:"ok",entries:n.entries}}catch{return{status:"invalid",entries:[],error:{code:"managed_state_invalid",path:e}}}}async function I(e){try{return{directories:(await u.readdir(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,r)=>t.localeCompare(r))}}catch(t){return f(t)?{directories:[]}:{directories:[],error:{code:"extensions_unreadable",path:e}}}}async function D(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{manifest:null,error:{code:"manifest_invalid",path:e}}:{manifest:null,error:{code:"manifest_unreadable",path:e}}}try{let r=v(JSON.parse(t));return r?{manifest:r}:{manifest:null,error:{code:"manifest_invalid",path:e}}}catch{return{manifest:null,error:{code:"manifest_invalid",path:e}}}}function M(e){let t=e.manifest?.name??e.directory,r=new Set(p(e.settings.enabled)),n=new Set(p(e.settings.disabled)),a=!y(e.settings.status)||!e.manifest?null:!n.has(t)&&(r.size===0||r.has(t)),o=y(e.managed.status)?e.managed.entries.some(d=>i(d.name)===i(t)||i(d.directory)===i(e.directory)):null;return{name:t,directory:e.directory,scope:e.scope,installed:!0,status:e.manifest?a===!1?"inactive":"installed":"malformed_manifest",configured_enabled:a,managed:o,runtime_active:null,...e.manifest?{version:e.manifest.version}:{}}}async function R(e){let t=e.scope??"project",r=t==="global"?h(e.cwd??process.cwd()):e.pmRoot,n=c.join(r,"extensions"),a=await S(c.join(r,"settings.json")),o=await A(c.join(n,".managed-extensions.json")),d=await I(n),l=[];for(let s of[a,o,d])s.error&&l.push(s.error);let m=e.name?.trim(),b=[];for(let s of d.directories){let x=c.join(n,s,"manifest.json"),g=await D(x);g.error&&l.push(g.error);let w=M({directory:s,scope:t,manifest:g.manifest,settings:a,managed:o});m&&![w.name,s].some(E=>i(E)===i(m))||b.push(w)}return m&&b.length===0&&l.every(s=>s.code!=="extensions_unreadable")&&b.push({name:m,directory:null,scope:t,installed:!1,status:"absent",configured_enabled:y(a.status)?!1:null,managed:y(o.status)?!1:null,runtime_active:null}),{scope:t,complete:l.length===0,settings_status:a.status,managed_state_status:o.status,extensions:b,errors:l}}export{R as a};
2
- //# sourceMappingURL=chunk-OQOEBWHU.js.map
1
+ import{da as p,ea as i,fa as v,ga as _}from"./chunk-D6P6IBPN.js";import{za as h}from"./chunk-7V37RC2L.js";import u from"node:fs/promises";import c from"node:path";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="846100a9-4314-5f7c-b892-fa16e09bee5b")}catch{}})();function f(e){return typeof e=="object"&&e!==null&&"code"in e&&e.code==="ENOENT"}function y(e){return e!=="invalid"&&e!=="unreadable"}function j(e){let t=JSON.parse(e);if(typeof t!="object"||t===null||Array.isArray(t))throw new SyntaxError("Invalid settings object");let r=t.extensions;if(r===void 0)return{enabled:[],disabled:[]};if(typeof r!="object"||r===null||Array.isArray(r))throw new SyntaxError("Invalid extensions settings");let n=r;if(n.enabled!==void 0&&(!Array.isArray(n.enabled)||!n.enabled.every(a=>typeof a=="string"))||n.disabled!==void 0&&(!Array.isArray(n.disabled)||!n.disabled.every(a=>typeof a=="string")))throw new SyntaxError("Invalid extension enablement lists");return{enabled:n.enabled??[],disabled:n.disabled??[]}}async function S(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{status:"absent",enabled:[],disabled:[]}:{status:"unreadable",enabled:[],disabled:[],error:{code:"settings_unreadable",path:e}}}try{return{status:"ok",...j(t)}}catch{return{status:"invalid",enabled:[],disabled:[],error:{code:"settings_invalid",path:e}}}}async function A(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){if(f(r))try{if((await u.stat(c.dirname(e))).isDirectory())return{status:"absent",entries:[]}}catch(n){if(f(n))return{status:"absent",entries:[]}}return{status:"unreadable",entries:[],error:{code:"managed_state_unreadable",path:e}}}try{let r=JSON.parse(t),n=_(r);if(!n||typeof r!="object"||r===null||!Array.isArray(r.entries)||n.entries.length!==r.entries.length)throw new SyntaxError("Invalid managed extension state");return{status:"ok",entries:n.entries}}catch{return{status:"invalid",entries:[],error:{code:"managed_state_invalid",path:e}}}}async function I(e){try{return{directories:(await u.readdir(e,{withFileTypes:!0})).filter(t=>t.isDirectory()).map(t=>t.name).sort((t,r)=>t.localeCompare(r))}}catch(t){return f(t)?{directories:[]}:{directories:[],error:{code:"extensions_unreadable",path:e}}}}async function D(e){let t;try{t=await u.readFile(e,"utf8")}catch(r){return f(r)?{manifest:null,error:{code:"manifest_invalid",path:e}}:{manifest:null,error:{code:"manifest_unreadable",path:e}}}try{let r=v(JSON.parse(t));return r?{manifest:r}:{manifest:null,error:{code:"manifest_invalid",path:e}}}catch{return{manifest:null,error:{code:"manifest_invalid",path:e}}}}function M(e){let t=e.manifest?.name??e.directory,r=new Set(p(e.settings.enabled)),n=new Set(p(e.settings.disabled)),a=!y(e.settings.status)||!e.manifest?null:!n.has(t)&&(r.size===0||r.has(t)),o=y(e.managed.status)?e.managed.entries.some(d=>i(d.name)===i(t)||i(d.directory)===i(e.directory)):null;return{name:t,directory:e.directory,scope:e.scope,installed:!0,status:e.manifest?a===!1?"inactive":"installed":"malformed_manifest",configured_enabled:a,managed:o,runtime_active:null,...e.manifest?{version:e.manifest.version}:{}}}async function R(e){let t=e.scope??"project",r=t==="global"?h(e.cwd??process.cwd()):e.pmRoot,n=c.join(r,"extensions"),a=await S(c.join(r,"settings.json")),o=await A(c.join(n,".managed-extensions.json")),d=await I(n),l=[];for(let s of[a,o,d])s.error&&l.push(s.error);let m=e.name?.trim(),b=[];for(let s of d.directories){let x=c.join(n,s,"manifest.json"),g=await D(x);g.error&&l.push(g.error);let w=M({directory:s,scope:t,manifest:g.manifest,settings:a,managed:o});m&&![w.name,s].some(E=>i(E)===i(m))||b.push(w)}return m&&b.length===0&&l.every(s=>s.code!=="extensions_unreadable")&&b.push({name:m,directory:null,scope:t,installed:!1,status:"absent",configured_enabled:y(a.status)?!1:null,managed:y(o.status)?!1:null,runtime_active:null}),{scope:t,complete:l.length===0,settings_status:a.status,managed_state_status:o.status,extensions:b,errors:l}}export{R as a};
2
+ //# sourceMappingURL=chunk-YYD5MNAV.js.map
@@ -1,2 +1,2 @@
1
- import{a as _e}from"./chunk-25MTQAHX.js";import{$b as Le,Tb as Ge,Ub as qe,Wb as H,Zb as Ke,_a as Y,a as ve,ac as Je,wc as We}from"./chunk-EKV5GP6P.js";import{ac as xe}from"./chunk-5PTMQBKJ.js";import{b as Ce,c as B}from"./chunk-NNIYQHYT.js";import{Me as Fe,N as $e,Pe,_a as Ue,a as z,eb as Ne,g as ke,i as $,oc as De,qc as je,r as V}from"./chunk-QQYLNHZK.js";import{Db as we,Nc as ge,Oc as J,Pa as ye,Rg as Ae,Xh as O,ai as Me,fg as Ee,hg as W,ig as Se,lg as be,og as Te,pa as L,pg as S,pi as Re,qh as M,rg as Ie,ti as Oe,ya as he,zi as k}from"./chunk-UHKN6TJM.js";import{A as u,C as d,G as K,I as fe,J as A,l as pe,q as I,t as le,y as me}from"./chunk-ONC4BBQP.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 tt 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 b=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...pe,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function C(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return b.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 U(e,t,n){let r=e?.estimatedMinutes;if(!(r===void 0||typeof r=="string"))throw new d(`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]="7b430d12-7a5b-52c2-9a6b-e4c33a39da76")}catch{}})();var X=["op","id","reason","options","unique","match"],Mt=[...X,"ref"],ze=[...Mt,"item"],Rt="mutate-",Ve="row-",Be=["schema_version","mutations"],nt="[a-z][a-z0-9._-]{0,63}",Ye=new RegExp(`^${nt}$`,"u"),rt=new RegExp(`(^|,)id=@(${nt})(?=,|$)`,"gu"),He=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),N=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],it=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Ot=new Set([...it,"completed_at","id"]),ot={create:Fe.map(e=>e.target),update:Pe.map(e=>e.target),close:Ue.map(e=>He(e.flag)).filter(e=>e!=="reason"),release:Ne.map(e=>He(e.flag))};function at(e){let t=tt.createHash("sha256").update(e).digest("hex");return`${Rt}${t.slice(0,24)}`}function Ar(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new d("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let r of["lockTtlSeconds","lockWaitMs"]){let i=e[r];if(i===void 0)continue;let o=typeof i=="number"||typeof i=="string"&&i.trim().length>0?Number(i):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new d(`${r} must be a positive safe integer.`,u.USAGE);t[r]=o}return t}function h(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function D(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=we(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function T(e,t,n){let r=D(t,n);return new d(r===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${r}"?`,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:[r===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${r}".`]})}function ee(e,t){try{return JSON.parse(e)}catch(n){let r=n instanceof Error?n.message:String(n);throw new d(`${t} must be valid JSON: ${r}`,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 kt(e,t){if(!h(e))throw new d(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!X.includes(n))throw T(`mutation ${t+1}`,n,X);return e}function $t(e,t,n,r){if(e===void 0)return;if(!h(e))throw new d(`Mutation ${n+1} options must be an object.`,u.USAGE);let i=[...ot[t],...dt(t,r)];for(let o of Object.keys(e))if(!i.includes(o))throw T(`mutation ${n+1} ${t} options`,o,i);return U(e,t,n),e}function Xe(e,t,n,r){if(e===void 0)return;let i=r==="unique"?"create":"update";if(t!==i)throw new d(`Mutation ${n+1} ${r} is only valid for ${i} operations.`,u.USAGE);let o=h(e)&&typeof e.key=="string"?e.key.trim():"";if(!h(e)||o.length===0||e.value===void 0||e.value===null)throw new d(`Mutation ${n+1} ${r} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Ct(e,t,n){let r=kt(e,t),{op:i,id:o,reason:a}=r;if(i!=="create"&&i!=="update"&&i!=="close"&&i!=="release")throw new d(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=$t(r.options,i,t,n),c=Xe(r.unique,i,t,"unique"),l=Xe(r.match,i,t,"match");if(typeof o!="string"||o.trim().length===0)throw new d(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let p=o.trim();if(i==="close"){if(typeof a!="string"||a.trim().length===0)throw new d(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:i,id:p,reason:a.trim(),...s===void 0?{}:{options:s}}}if(i==="release")return{op:i,id:p,...s===void 0?{}:{options:s}};if(!h(s))throw new d(`Mutation ${t+1} ${i} requires an options object.`,u.USAGE);return{op:i,id:p,options:s,...c===void 0?{}:{unique:c},...l===void 0?{}:{match:l}}}function st(e,t={}){let n=ee(e,"Mutation batch"),r=Array.isArray(n)?n:h(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(r===void 0||r.length===0)throw new d("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let i=t.runtimeFields??[];return r.map((o,a)=>{let s=Ct(o,a,i);return s.options!==void 0&&De(s.options),s})}function Ut(e,t,n){let r=tt.createHash("sha256").update(e).update("\0").update(t).digest("hex"),i=BigInt(`0x${r.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${ke(n)}${i}`}function Ze(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),r=t[n];if(r===void 0)throw new d(`Unknown mutation reference "${e}".`,u.USAGE);return r}function Qe(e,t){if(typeof e!="string")return e;let n=e.replace(rt,(r,i,o)=>{let a=t[o];if(a===void 0)throw new d(`Unknown mutation reference "@${o}".`,u.USAGE);return`${i}id=${a}`});if(/(^|,)id=@/u.test(n))throw new d(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function Nt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(rt)].map(t=>t[1]).filter(t=>t!==void 0)}function Dt(e,t){let n=new Map;for(let[a,s]of e.entries()){let c=t[a];if(c===void 0)continue;let l=h(s.options)?s.options:{},p=Array.isArray(l.dep)?l.dep:l.dep===void 0?[]:[l.dep];n.set(c,[l.parent,l.blockedBy,...p].flatMap(Nt))}let r=new Set,i=new Set,o=a=>{if(r.has(a))throw new d(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!i.has(a)){r.add(a);for(let s of n.get(a))n.has(s)&&o(s);r.delete(a),i.add(a)}};for(let a of n.keys())o(a)}function jt(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),r=n[0];if(!r.ok&&(r.line.startsWith("[")||r.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&h(o.value)))return null;let i=[];for(let o of n){if(!o.ok)throw new d(`Mutation document line ${o.number} must be one valid JSON object: ${_e(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(!h(o.value))throw new d(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);i.push(o.value)}return i}function Ft(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Pt(e){let t;try{t=ee(e,"Mutation document")}catch(n){let r=jt(e);if(r===null)throw n;return{schema_version:1,mutations:r}}return Array.isArray(t)?{schema_version:1,mutations:t}:h(t)&&!Ft(t)?{schema_version:1,mutations:[t]}:t}function xt(e,t){let n=Object.hasOwn(e,"op")?Gt(e,t):qt(e,t);if(n.op==="create"&&n.id===void 0&&h(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new d(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function Gt(e,t){for(let n of Object.keys(e))if(!ze.includes(n))throw T(`mutation ${t+1}`,n,ze);if(e.item!==void 0&&e.op!=="create")throw new d(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new d(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function qt(e,t){let{ref:n,id:r,item:i,...o}=e,a=i!==void 0?i:o;if(i!==void 0&&Object.keys(o).length>0)throw new d(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!h(a))throw new d(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...r===void 0?{}:{id:r},item:a}}function Kt(e){let t=Pt(e);if(!h(t))throw new d("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!Be.includes(n))throw T("mutation document",n,Be);if(t.schema_version!==void 0&&t.schema_version!==1)throw new d("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new d("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,r)=>{if(!h(n))throw new d(`Mutation ${r+1} must be an object.`,u.USAGE);return xt(n,r)})}function Lt(e,t,n){let r=new Set(Object.values(pt(t,n,Object.create(null))));for(let i of t)i.op==="create"&&typeof i.id=="string"&&i.id.trim().length>0&&r.add($(i.id,n.idPrefix));return{...e,existing:e.existing.filter(i=>!r.has(i.id))}}function Jt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,r]of e.entries()){if(r.op!=="create"||r.ref!==void 0||typeof r.id=="string"&&r.id.trim().length>0)continue;let i=`${Ve}${n+1}`;if(t.has(i))throw new d(`Mutation ${n+1} receives the synthesized ref "${i}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${Ve}<n> aliases are reserved for rows without one.`,u.USAGE);r.ref=i}}function ct(e,t,n){let r=on(JSON.stringify(e),t,{},n);return delete r.stdinJson,delete r.documentAnnotationSnapshot,r}function dt(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>S(n))}function Wt(e,t){for(let n of e)h(n.item)&&(n.options=ct(n.item,"create",t),delete n.item)}function ut(e,t){return t.some(n=>n.metadata_key===e)?e:C(e)}function Z(e,t,n){let r=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(h(e.item)){if(e.item[t]!==void 0)return e.item[t];if(ut(r,n)===t&&e.item[r]!==void 0)return e.item[r]}let i=h(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&i[S(o)]!==void 0?i[S(o)]:i[t]!==void 0?i[t]:i[r]!==void 0?i[r]:(Array.isArray(i.field)?i.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function zt(e,t){return e<t?-1:+(e!==t)}function Q(e){return Array.isArray(e)?e.map(Q):h(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>zt(t,n)).map(([t,n])=>[t,Q(n)])):e}function _(e){return typeof e=="string"?e.trim():JSON.stringify(Q(e))}function Vt(e,t,n,r,i){let o=t.key.trim();if(o.length===0)throw new d("Upsert key must be a non-empty field name.",u.USAGE);let a=Bt(t.existing),s=new Map,c=new Set;for(let[l,p]of e.entries()){if(p.op!=="create")continue;let f=Yt(p,o,l,s,r),y=Ht(a.get(f)??[],o,f);if(y===void 0){p.unique={key:o,value:Z(p,o,r)};continue}let w=$(y,n);typeof p.ref=="string"&&(i[p.ref]=w),Xt(p,w,r,{key:o,value:Z(p,o,r)}),c.add(l)}return c}function Bt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let r=_(n.value);t.set(r,[...t.get(r)??[],n.id])}return t}function Yt(e,t,n,r,i){let o=Z(e,t,i);if(o==null||o==="")throw new d(`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=_(o),s=r.get(a);if(s!==void 0)throw new d(`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 r.set(a,n),a}function Ht(e,t,n){if(e.length>1)throw new d(`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 Xt(e,t,n,r){let i=new Set([...ot.update,...dt("update",n)]),o=h(e.item)?ct(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>i.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=r}function pt(e,t,n){for(let[r,i]of e.entries())if(i.ref!==void 0){if(i.op!=="create")throw new d(`Mutation ${r+1} ref is only valid for create operations.`,u.USAGE);if(typeof i.ref!="string"||!Ye.test(i.ref))throw new d(`Mutation ${r+1} ref must match ${Ye.source}.`,u.USAGE);if(n[i.ref]!==void 0)throw new d(`Duplicate mutation ref "${i.ref}".`,u.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?$(i.id,t.idPrefix):Ut(t.transactionId,i.ref,t.idPrefix)}return n}function lt(e,t){let n=Kt(e);Jt(n);let r=n.map(p=>typeof p.ref=="string"?p.ref:void 0),i=Object.create(null),o=t.upsert===void 0?new Set:Vt(n,Lt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],i);Wt(n,t.runtimeFields??[]),pt(n,t,i),Dt(n,r);let a=n.map(p=>{let f={...p},y=typeof f.ref=="string"?f.ref:void 0;if(delete f.ref,y!==void 0?f.id=i[y]:f.id=Ze(f.id,i),h(f.options)){let w={...f.options};for(let g of["parent","blockedBy"])w[g]!==void 0&&(w[g]=Ze(w[g],i));Array.isArray(w.dep)?w.dep=w.dep.map(g=>Qe(g,i)):w.dep!==void 0&&(w.dep=Qe(w.dep,i)),f.options=w}return f}),s=st(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),c=s.filter(p=>p.op==="create").map(p=>p.id);if(new Set(c).size!==c.length)throw new d("Duplicate resolved create id in mutation document.",u.USAGE);let l=s.map((p,f)=>{let y=r[f];return{index:f,...typeof y=="string"?{ref:y}:{},id:p.id,op:p.op,...o.has(f)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:i,rows:l}}function Zt(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let r=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(r)?JSON.stringify(r):r}`}).join(",")}function Qt(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(h))throw new d(`${n} must be an array of objects.`,u.USAGE);return e.map(r=>Zt(r,t))}}function en(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 et(e,t,n=!1){for(let[r,i,o]of xe){let a=t[r],s=Qt(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(a)?a.filter(c=>!h(c)||c.created_at===void 0):a,o,r);s!==void 0&&s.length>0&&(e[i]=s)}}function tn(e,t){for(let n of Object.keys(e)){if(t){if(!N.includes(n))throw T("item envelope",n,N);continue}if(!b.has(n)&&D(n,[...b])===void 0&&D(n,N)==="item")throw T("item envelope",n,N)}}function nn(e){let t=Object.hasOwn(e,"item");tn(e,t);let n=t?e.item:e;if(!h(n))throw new d("Item document item must be an object.",u.USAGE);return{item:n,...t&&h(e.linked)?{linked:e.linked}:{}}}function rn(e,t,n,r,i,o){if((r==="update"?Ot:it).has(t))return;let a=i.find(s=>s.metadata_key===t&&s.commands.includes(r));if(a!==void 0){let s=Ie(o,a);e[S(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!b.has(t)){if(D(t,[...b])!==void 0)throw T("item document",t,[...b]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,c)=>c.toUpperCase())]=en(t,n))}function on(e,t,n={},r=[]){let i=ee(e,"Item document");if(!h(i))throw new d("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=nn(i),s={};for(let[c,l]of Object.entries(o)){let p=ut(c,r);p!==c&&Object.hasOwn(o,p)||rn(s,p,l,t,r,n)}if(et(s,o,t==="update"),a!==void 0&&et(s,a),t==="update"){let c=Object.fromEntries(["comments","notes","learnings"].filter(l=>Object.hasOwn(o,l)).map(l=>[l,o[l].filter(p=>h(p)&&p.created_at!==void 0)]));Object.keys(c).length>0&&(s.documentAnnotationSnapshot=c)}return{...s,...Object.fromEntries(Object.entries(n).filter(([,c])=>c!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0}}function Mr(e){return st(JSON.stringify(e))}import ie from"node:crypto";import{constants as te}from"node:fs";import{cp as an,lstat as ft,mkdir as sn,mkdtemp as ht,open as cn,readdir as dn,realpath as yt,rm as wt,stat as oe,writeFile as gt}from"node:fs/promises";import{tmpdir as vt}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]="4d215571-44e3-5ce8-9644-47e42dd4b23e")}catch{}})();async function ae(e,t){if(!Oe(e))return{schema:W(t.schema),typeDefinitionsFromFile:[]};let n=await _n(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function se(e,t,n,r){let i=L({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},J());return(await $e(e,t.item_format,i.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[r];return a==null?[]:[{id:o.id,value:a}]})}function _t(e){let t=new Map,n=async r=>{let i=await k(e),o=await ae(e,i),a=new Map;for(let s of await se(e,i,o,r)){let c=_(s.value);a.set(c,[...a.get(c)??[],s.id])}return a};return{lookup(r){let i=t.get(r)??n(r);return t.set(r,i),i},async recordCreate(r){for(let[i,o]of t){let a=r[i];if(a==null)continue;let s=await o,c=_(a);s.set(c,[...s.get(c)??[],String(r.id)])}},invalidate(){t.clear()}}}async function un(e,t){let n=_(t.value),r=(await e.lookup(t.key)).get(n)??[];if(r.length!==0)throw new d(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${r.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 pn(e,t,n){let r=e.metadata[n.key],i=_(n.value);if(_(r)!==i)throw new d(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(i)}; 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 mt(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 G(e,t){let n={...e,...t};return e===void 0?n:je(e,n)}async function E(e,t){try{let n=(await Y(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 d&&n.exitCode===u.NOT_FOUND)return;throw n}}function ce(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=ie.createHash("sha256").update(ye(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function ln(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function v(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function R(e,t,n,r){let i=await M(m.join(e,"history",`${t}.jsonl`),t),o=v(n,r,"apply"),a=v(n,r,"compensate");for(let s=i.length-1;s>=0;s-=1){let c=i[s].message;if(c===o)return!0;if(c===a)return!1}return!1}async function de(e,t){let n=await E(e,t.id);if(n?.updatedAt===void 0)throw new d(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);let r=await M(m.join(e,"history",`${n.id}.jsonl`),n.id);if(r.length===0)throw new d(`Bulk ${t.op} target ${t.id} has no restorable history`,u.NOT_FOUND);return{target_updated_at:n.updatedAt,target_version:String(z(r)+r.length),target_history_hash:O(r),target_history_length:r.length}}function F(e,t,n){return new d(`Transaction ${e.transactionId} cannot safely compensate incomplete step ${n}; review item ${t} history before recovery.`,u.CONFLICT,{code:"transaction_partial_mutation",item_id:t,required:"Reconcile the item's partial or intervening changes before resuming this transaction.",why:"The retained history does not prove exclusive ownership of the changes to undo. The journal remains compensating instead of claiming a rollback or overwriting another writer.",nextSteps:[`Run pm history ${t} and inspect this transaction's retained compensation data before explicitly restoring or reconciling the item.`]})}function mn(e,t){let n=`bulk-item-transaction ${t} `;return[e.message,e.context?.item_transaction_step].some(r=>typeof r=="string"&&r.startsWith(n))}function fn(e,t,n){let{expectedHistory:r,length:i,version:o}=t;if(O(e)===r)return!1;if(typeof i!="number"||!Number.isSafeInteger(i)||i<1||O(e.slice(0,i))!==r||o!==String(z(e)+i))throw F(n,n.itemId,n.stepId);let a=v(n.transactionId,n.stepId,"apply"),s=e.slice(i),c=y=>y.message===a||y.context?.item_transaction_step===a,l=v(n.transactionId,n.stepId,"compensate");if(s.filter(y=>c(y)||y.message===l).at(-1)?.message===l)return!1;let p=s.filter(c);if(p.length===0)return!1;let f=e.at(-1).after_hash===p.at(-1).after_hash&&s.every(y=>mn(y,n.transactionId));if(p.length!==s.length&&!f)throw F(n,n.itemId,n.stepId);return!0}async function q(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;if(i===void 0||typeof i.target_updated_at!="string")return;let o=i.target_updated_at,a=await E(e.pmRoot,t);if(a===void 0)return;let s=await M(m.join(e.pmRoot,"history",`${a.id}.jsonl`),a.id),c=i.target_history_hash;if(typeof c=="string"){if(!fn(s,{expectedHistory:c,length:i.target_history_length,version:i.target_version},{...e,itemId:a.id,stepId:n}))return}else{if(a.updatedAt===o)return;if(!await R(e.pmRoot,a.id,e.transactionId,n))throw F(e,a.id,n)}let l=()=>Je(t,typeof i.target_version=="string"?i.target_version:o,{force:!0,author:e.author,message:v(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot});await V({pmRoot:e.pmRoot,id:a.id,validate:p=>{if(Me(p)!==s.at(-1).after_hash)throw F(e,a.id,n)}},l)}function Et(e,t,n){return{id:n,async inspect(){let r=await E(e.pmRoot,t.id);if(r===void 0)return{state:"pending"};if(r.closedAt!==void 0){let i=await M(m.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(i.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new d(`Created item ${r.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:r.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${r.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:r.id,op:"create"}}},async apply(){t.unique!==void 0&&await un(e.uniqueIndex,t.unique);let r=await Ge(G(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot}),i=r.item;return e.onCreateWarnings?.(String(i.id),r.warnings),await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){let r=await E(e.pmRoot,t.id);if(r!==void 0){if(e.createCompensation==="delete"){await Le(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}r.closedAt===void 0&&await H(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function hn(e,t,n){return{id:n,compensatePending:!0,async inspect(){let r=await E(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return de(e.pmRoot,t)},async apply(){let r=()=>qe(t.id,G(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=t.match,o=i,a=(await V({pmRoot:e.pmRoot,id:String((await Y(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:s=>{o!==void 0&&pn(s,t.id,o)},committed:s=>{i!==void 0&&(o={key:i.key,value:structuredClone(s.metadata[i.key])})},historyContext:{item_transaction_step:v(e.transactionId,n,"apply")}},r)).item;return e.uniqueIndex.invalidate(),{id:String(a.id),op:"update"}},async compensate(r){await q(e,t.id,n,r)}}}function yn(e,t,n){return{id:n,async inspect(){let r=await E(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"close"}}:r.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"close"}}},async prepareCompensation(){return de(e.pmRoot,t)},async apply(){let r=(await H(t.id,t.reason,G(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"close"}},async compensate(r){await q(e,t.id,n,r)}}}function wn(e,t,n){return{id:n,async inspect(){let r=await E(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"release"}}:r.assignee!==void 0||r.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"release"}}},async prepareCompensation(){return de(e.pmRoot,t)},async apply(){let r=(await Ke(t.id,G(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"release"}},async compensate(r){await q(e,t.id,n,r)}}}function St(e,t,n){let r=ce(t,n);switch(t.op){case"create":return Et(e,t,r);case"update":return hn(e,t,r);case"close":return yn(e,t,r);case"release":return wn(e,t,r)}}function gn(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&&!mt(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&&!mt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);U(e.options,e.op,t)}function bt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,r]of e.entries()){if(gn(r,n),r.op!=="create"||r.unique===void 0)continue;let{key:i,value:o}=r.unique,a=t.get(i)??new Map,s=_(o),c=a.get(s);if(c!==void 0)throw new d(`Bulk create mutations ${c+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${i}".`,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(i,a)}}async function ne(e,t,n){try{return await n()}catch(r){throw r instanceof d?new d(r.message,r.exitCode,{...r.context,transaction_operation:{index:t,op:e.op,id:e.id}}):r}}function Tt(e,t,n,r){let i=m.relative(e,t),o=i.split(m.sep);return o[0]==="extensions"&&o[2]==="node_modules"&&!r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))?!1:["locks","runtime","search"].includes(i.split(m.sep)[0])?r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`)):i===""||n===void 0||n.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))}async function P(e,t){let n=await ft(t);if(n.isSymbolicLink())await oe(t);else if(n.isDirectory()||n.isFile())return n;throw A(m.relative(e,t))}async function vn(e,t){let n=await cn(t,te.O_RDONLY|te.O_NOFOLLOW|te.O_NONBLOCK);try{let r=await n.stat();if(!r.isFile())throw A(m.relative(e,t));let i=ie.createHash("sha256");if(r.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:r.size-1,autoClose:!1}))i.update(o);return i.digest()}finally{await n.close()}}async function re(e,t,n){let r=ie.createHash("sha256");async function i(o){for(let a of(await dn(o)).sort()){let s=m.join(o,a);Tt(e,s,t,n)&&((await P(e,s)).isDirectory()?await i(s):(r.update(JSON.stringify(m.relative(e,s))),r.update(await vn(e,s))))}}return await i(e),r.digest("hex")}function j(){return new d("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ue(e){if(!K(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),r=n;for(;;)try{let i=await ft(r);return r!==n&&i.isDirectory()}catch(i){if(!K(i))return!1;let o=m.dirname(r);if(o===r)return!1;r=o}}async function x(e,t){let n=m.join(e,t);try{let r=e;for(let i of t.split(m.sep).slice(0,-1))r=m.join(r,i),await P(e,r);if(!(await P(e,n)).isFile())throw A(t);return await fe(n,A(t))}catch(r){if(await ue(r))return;throw r}}async function It(e,t,n,r){let i=W(n);for(let[o,a]of Object.entries(i.files)){let s=m.relative(e,Se(e,a,Ee[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new d("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}`});i.files[o]=s;let c=await x(e,s);if(r?.set(s,c),c!==void 0){let l=m.join(t,s);await sn(m.dirname(l),{recursive:!0}),await gt(l,c)}}return be(t,i)}async function _n(e,t){await oe(e);let n=await ht(m.join(vt(),"pm-schema-plan-"));try{let r=await yt(e);return await It(r,m.join(n,"configuration"),t)}catch(r){throw await ue(r)?j():r}finally{await wt(n,{recursive:!0,force:!0})}}async function En(e,t,n){let r=new Map,i=await x(e,I);r.set(I,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let a=Re(o),s=a.success?a.data:void 0,c=await It(e,t,s?.schema,r),l=c.schema,p=m.relative(e,Ae(e));r.set(p,await x(e,p));let f=L({...me,item_types:{definitions:[...s?.item_types?.definitions??[],...c.type_definitions_from_file??[]]}},n),y=he(e)===e?[...le.filter(Boolean),I,ve,"transactions",...f.folders,...r.keys()].map(g=>m.normalize(g)):void 0,w=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:l.files}});return{configuration:r,ownedPaths:y,stagedSettings:w,registryFolders:f.folders}}async function Sn(e,t,n){await oe(e);try{let r=await yt(e),i=await En(r,m.join(m.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(l=>m.normalize(l)),a=await re(r,i.ownedPaths,o);await an(r,t,{recursive:!0,dereference:!1,filter:async l=>Tt(r,l,i.ownedPaths,o)?(await P(r,l),!0):!1});let[s,c]=await Promise.all([re(r,i.ownedPaths,o),re(t,i.ownedPaths,o)]);if(a!==s||a!==c)throw j();for(let[l,p]of i.configuration)if(await x(t,l)!==p)throw j();i.stagedSettings!==void 0&&await gt(m.join(t,I),i.stagedSettings)}catch(r){throw await ue(r)?j():r}}async function At(e){let t=Ce(e),n=[...e.mutations];bt(n);let r=J(),i=await ht(m.join(vt(),"pm-transaction-preview-")),o=m.join(i,"tracker");try{await Sn(t.pmRoot,o,r);let a=!1,s=[];return await We({path:o,noExtensions:!0},async()=>{ge(r);let c={...t,pmRoot:o,createCompensation:"close",uniqueIndex:_t(o)},l=n.map((p,f)=>{let y=St({...c,onCreateWarnings:(w,g)=>{g.length>0&&s.push({index:f,id:w,op:"create",warnings:g})}},p,f);return{...y,inspect:()=>ne(p,f,()=>y.inspect()),prepareCompensation:()=>ne(p,f,async()=>y.prepareCompensation?.()),apply:()=>ne(p,f,()=>y.apply())}});await B({...t,pmRoot:o,steps:l,onTransition:({transition:p})=>{p==="committed"&&(a=!0)}})}),{validated:a,state:a?"staged_snapshot":"replayed_committed_plan",warnings:s,unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks","derived_extension_dependencies_excluded"]}}finally{await wt(i,{recursive:!0,force:!0})}}async function bn(e){let t=[...e.mutations];bt(t);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let r={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n,uniqueIndex:_t(e.pmRoot)},i=await B({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((a,s)=>St(r,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 c=ce(s,a),l=i.results[c];o[ln(s,a)]=l}return{transactionId:i.transactionId,status:"committed",recovered:i.recovered,results:o}}function Tn(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 ni(e){return bn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:Tn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var ri={buildCreateStep:Et,bulkHistoryMarker:v,compensateByRestore:q,deriveStepId:ce,isUpdateMarkerApplied:R,readItemSnapshot: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]="3041c268-69c8-58e5-8a68-eaaa3c0dbd3b")}catch{}})();async function li(e){let{plan:t}=e,n=await At({pmRoot:e.pmRoot,author:e.author,transactionId:t.transaction_id,mutations:t.mutations}),r=new Map(n.warnings.map(o=>[o.index,o.warnings])),i=t.rows.map(o=>{let a={...o};delete a.warnings;let s=r.get(o.index);return s!==void 0&&(a.warnings=s),a});return{validation:n,rows:i}}async function mi(e){let t=e.upsertKey?.trim();if(t!==void 0&&t.length===0)throw new d("Upsert key must be a non-empty field name.",u.USAGE);let n=e.settings??await k(e.pmRoot),r=e.transactionId?.trim()??"",i=r.length>0?r:at(e.input),o=await ae(e.pmRoot,n),a=Te(o.schema).definitions,s=(a.find(l=>l.metadata_key===t)??a.find(l=>l.key===t||S(l)===t))?.metadata_key??C(t),c=s===void 0?void 0:{key:s,existing:await se(e.pmRoot,n,o,s)};return{...lt(e.input,{transactionId:i,idPrefix:n.id_prefix,runtimeFields:a,...c===void 0?{}:{upsert:c}}),transaction_id:i,transaction_id_source:r.length>0?"explicit":"derived",...c===void 0?{}:{upsert_key:c.key}}}export{at as a,Ar as b,st as c,_ as d,lt as e,on as f,Mr as g,ae as h,se as i,_n as j,At as k,bn as l,Tn as m,ni as n,ri as o,li as p,mi as q};
2
- //# sourceMappingURL=chunk-Q55KZDNF.js.map
1
+ import{a as _e}from"./chunk-3KMYHYJV.js";import{$b as Le,Tb as Ge,Ub as qe,Wb as H,Zb as Ke,_a as Y,a as ve,ac as Je,wc as We}from"./chunk-YUBUNECD.js";import{ac as xe}from"./chunk-AHVN4GHF.js";import{b as Ce,c as B}from"./chunk-D6P6IBPN.js";import{Me as Fe,N as $e,Pe,_a as Ue,a as z,eb as Ne,g as ke,i as $,oc as De,qc as je,r as V}from"./chunk-CS7QDSUX.js";import{Bi as k,Db as we,Nc as ge,Oc as J,Pa as ye,Tg as Ae,Zh as O,ci as Me,hg as Ee,jg as W,kg as Se,ng as be,pa as L,qg as Te,rg as S,ri as Re,sh as M,tg as Ie,vi as Oe,ya as he}from"./chunk-7V37RC2L.js";import{A as u,C as d,G as K,I as fe,J as A,l as pe,q as I,t as le,y as me}from"./chunk-RZQNFHXO.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 tt 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 b=new Set(["id","title","description","type","status","priority","tags","body","deadline","estimated_minutes","acceptance_criteria","definition_of_ready","order","rank","assignee",...pe,"affected_version","fixed_version","component","regression","customer_impact","close_reason","completed_at","dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"]);function C(e){if(e===void 0)return;let t=e.replace(/[A-Z]/gu,n=>`_${n.toLowerCase()}`);return b.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 U(e,t,n){let r=e?.estimatedMinutes;if(!(r===void 0||typeof r=="string"))throw new d(`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]="7b430d12-7a5b-52c2-9a6b-e4c33a39da76")}catch{}})();var X=["op","id","reason","options","unique","match"],Mt=[...X,"ref"],ze=[...Mt,"item"],Rt="mutate-",Ve="row-",Be=["schema_version","mutations"],nt="[a-z][a-z0-9._-]{0,63}",Ye=new RegExp(`^${nt}$`,"u"),rt=new RegExp(`(^|,)id=@(${nt})(?=,|$)`,"gu"),He=e=>e.slice(2).replaceAll(/-([a-z])/gu,(t,n)=>n.toUpperCase()),N=["item","linked","schedule","claim_state","children","omission_receipt","row_contract","context_intent"],it=new Set(["created_at","updated_at","closed_at","version","format_version","path","author","collection_counts","notes_count","tests_count"]),Ot=new Set([...it,"completed_at","id"]),ot={create:Fe.map(e=>e.target),update:Pe.map(e=>e.target),close:Ue.map(e=>He(e.flag)).filter(e=>e!=="reason"),release:Ne.map(e=>He(e.flag))};function at(e){let t=tt.createHash("sha256").update(e).digest("hex");return`${Rt}${t.slice(0,24)}`}function Ar(e){let t={},n=e.createCompensation;if(n!==void 0){if(n!=="close"&&n!=="delete")throw new d("createCompensation must be close or delete.",u.USAGE);t.createCompensation=n}for(let r of["lockTtlSeconds","lockWaitMs"]){let i=e[r];if(i===void 0)continue;let o=typeof i=="number"||typeof i=="string"&&i.trim().length>0?Number(i):Number.NaN;if(!Number.isSafeInteger(o)||o<=0)throw new d(`${r} must be a positive safe integer.`,u.USAGE);t[r]=o}return t}function h(e){if(typeof e!="object"||e===null||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function D(e,t){let n=Math.max(1,Math.min(3,Math.floor(e.length/4)+1)),r;for(let i of t){let o=we(e,i,n);o!==null&&(r===void 0||o<r.distance)&&(r={key:i,distance:o})}return r?.key}function T(e,t,n){let r=D(t,n);return new d(r===void 0?`${e} does not recognize key "${t}". Allowed keys: ${n.join(", ")}.`:`${e} does not recognize key "${t}". Did you mean "${r}"?`,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:[r===void 0?`Remove or correct "${t}".`:`Replace "${t}" with "${r}".`]})}function ee(e,t){try{return JSON.parse(e)}catch(n){let r=n instanceof Error?n.message:String(n);throw new d(`${t} must be valid JSON: ${r}`,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 kt(e,t){if(!h(e))throw new d(`Mutation ${t+1} must be an object.`,u.USAGE);for(let n of Object.keys(e))if(!X.includes(n))throw T(`mutation ${t+1}`,n,X);return e}function $t(e,t,n,r){if(e===void 0)return;if(!h(e))throw new d(`Mutation ${n+1} options must be an object.`,u.USAGE);let i=[...ot[t],...dt(t,r)];for(let o of Object.keys(e))if(!i.includes(o))throw T(`mutation ${n+1} ${t} options`,o,i);return U(e,t,n),e}function Xe(e,t,n,r){if(e===void 0)return;let i=r==="unique"?"create":"update";if(t!==i)throw new d(`Mutation ${n+1} ${r} is only valid for ${i} operations.`,u.USAGE);let o=h(e)&&typeof e.key=="string"?e.key.trim():"";if(!h(e)||o.length===0||e.value===void 0||e.value===null)throw new d(`Mutation ${n+1} ${r} must be an object with a non-empty key and a value.`,u.USAGE);return{key:o,value:e.value}}function Ct(e,t,n){let r=kt(e,t),{op:i,id:o,reason:a}=r;if(i!=="create"&&i!=="update"&&i!=="close"&&i!=="release")throw new d(`Mutation ${t+1} op must be create, update, close, or release.`,u.USAGE);let s=$t(r.options,i,t,n),c=Xe(r.unique,i,t,"unique"),l=Xe(r.match,i,t,"match");if(typeof o!="string"||o.trim().length===0)throw new d(`Mutation ${t+1} requires a non-empty id.`,u.USAGE);let p=o.trim();if(i==="close"){if(typeof a!="string"||a.trim().length===0)throw new d(`Mutation ${t+1} close requires a non-empty reason.`,u.USAGE);return{op:i,id:p,reason:a.trim(),...s===void 0?{}:{options:s}}}if(i==="release")return{op:i,id:p,...s===void 0?{}:{options:s}};if(!h(s))throw new d(`Mutation ${t+1} ${i} requires an options object.`,u.USAGE);return{op:i,id:p,options:s,...c===void 0?{}:{unique:c},...l===void 0?{}:{match:l}}}function st(e,t={}){let n=ee(e,"Mutation batch"),r=Array.isArray(n)?n:h(n)&&Array.isArray(n.mutations)?n.mutations:void 0;if(r===void 0||r.length===0)throw new d("Mutation batch must be a non-empty JSON array or an object with a non-empty mutations array.",u.USAGE);let i=t.runtimeFields??[];return r.map((o,a)=>{let s=Ct(o,a,i);return s.options!==void 0&&De(s.options),s})}function Ut(e,t,n){let r=tt.createHash("sha256").update(e).update("\0").update(t).digest("hex"),i=BigInt(`0x${r.slice(0,16)}`).toString(36).padStart(13,"0").slice(-12);return`${ke(n)}${i}`}function Ze(e,t){if(typeof e!="string"||!e.startsWith("@"))return e;let n=e.slice(1),r=t[n];if(r===void 0)throw new d(`Unknown mutation reference "${e}".`,u.USAGE);return r}function Qe(e,t){if(typeof e!="string")return e;let n=e.replace(rt,(r,i,o)=>{let a=t[o];if(a===void 0)throw new d(`Unknown mutation reference "@${o}".`,u.USAGE);return`${i}id=${a}`});if(/(^|,)id=@/u.test(n))throw new d(`Malformed mutation reference in dependency "${e}".`,u.USAGE);return n}function Nt(e){return typeof e!="string"?[]:e.startsWith("@")?[e.slice(1)]:[...e.matchAll(rt)].map(t=>t[1]).filter(t=>t!==void 0)}function Dt(e,t){let n=new Map;for(let[a,s]of e.entries()){let c=t[a];if(c===void 0)continue;let l=h(s.options)?s.options:{},p=Array.isArray(l.dep)?l.dep:l.dep===void 0?[]:[l.dep];n.set(c,[l.parent,l.blockedBy,...p].flatMap(Nt))}let r=new Set,i=new Set,o=a=>{if(r.has(a))throw new d(`Mutation reference cycle includes "@${a}".`,u.USAGE);if(!i.has(a)){r.add(a);for(let s of n.get(a))n.has(s)&&o(s);r.delete(a),i.add(a)}};for(let a of n.keys())o(a)}function jt(e){let t=e.split(/\r?\n/u).map((o,a)=>({line:o.trim(),number:a+1})).filter(o=>o.line.length>0);if(t.length<2)return null;let n=t.map(o=>{try{return{...o,ok:!0,value:JSON.parse(o.line)}}catch(a){return{...o,ok:!1,error:a}}}),r=n[0];if(!r.ok&&(r.line.startsWith("[")||r.line==="{"||n.at(-1).line==="}")||!n.some(o=>o.ok&&h(o.value)))return null;let i=[];for(let o of n){if(!o.ok)throw new d(`Mutation document line ${o.number} must be one valid JSON object: ${_e(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(!h(o.value))throw new d(`Mutation document line ${o.number} must be a JSON object.`,u.USAGE);i.push(o.value)}return i}function Ft(e){return Object.hasOwn(e,"mutations")||Object.hasOwn(e,"schema_version")}function Pt(e){let t;try{t=ee(e,"Mutation document")}catch(n){let r=jt(e);if(r===null)throw n;return{schema_version:1,mutations:r}}return Array.isArray(t)?{schema_version:1,mutations:t}:h(t)&&!Ft(t)?{schema_version:1,mutations:[t]}:t}function xt(e,t){let n=Object.hasOwn(e,"op")?Gt(e,t):qt(e,t);if(n.op==="create"&&n.id===void 0&&h(n.item)&&n.item.id!==void 0){if(typeof n.item.id!="string")throw new d(`Mutation ${t+1} item id must be a string.`,u.USAGE);n.id=n.item.id}return n}function Gt(e,t){for(let n of Object.keys(e))if(!ze.includes(n))throw T(`mutation ${t+1}`,n,ze);if(e.item!==void 0&&e.op!=="create")throw new d(`Mutation ${t+1} item documents are only valid for create operations.`,u.USAGE);if(e.item!==void 0&&e.options!==void 0)throw new d(`Mutation ${t+1} must declare either item or options, not both.`,u.USAGE);return{...e}}function qt(e,t){let{ref:n,id:r,item:i,...o}=e,a=i!==void 0?i:o;if(i!==void 0&&Object.keys(o).length>0)throw new d(`Mutation ${t+1} must not mix item document keys with top-level fields.`,u.USAGE);if(!h(a))throw new d(`Mutation ${t+1} item document must be an object.`,u.USAGE);return{op:"create",...n===void 0?{}:{ref:n},...r===void 0?{}:{id:r},item:a}}function Kt(e){let t=Pt(e);if(!h(t))throw new d("Mutation document must be a JSON array or object.",u.USAGE);for(let n of Object.keys(t))if(!Be.includes(n))throw T("mutation document",n,Be);if(t.schema_version!==void 0&&t.schema_version!==1)throw new d("Mutation document schema_version must be 1.",u.USAGE);if(!Array.isArray(t.mutations)||t.mutations.length===0)throw new d("Mutation document requires a non-empty mutations array.",u.USAGE);return t.mutations.map((n,r)=>{if(!h(n))throw new d(`Mutation ${r+1} must be an object.`,u.USAGE);return xt(n,r)})}function Lt(e,t,n){let r=new Set(Object.values(pt(t,n,Object.create(null))));for(let i of t)i.op==="create"&&typeof i.id=="string"&&i.id.trim().length>0&&r.add($(i.id,n.idPrefix));return{...e,existing:e.existing.filter(i=>!r.has(i.id))}}function Jt(e){let t=new Set(e.map(n=>n.ref).filter(n=>typeof n=="string"));for(let[n,r]of e.entries()){if(r.op!=="create"||r.ref!==void 0||typeof r.id=="string"&&r.id.trim().length>0)continue;let i=`${Ve}${n+1}`;if(t.has(i))throw new d(`Mutation ${n+1} receives the synthesized ref "${i}", but another row declares that ref. Rename it or give mutation ${n+1} its own ref; ${Ve}<n> aliases are reserved for rows without one.`,u.USAGE);r.ref=i}}function ct(e,t,n){let r=on(JSON.stringify(e),t,{},n);return delete r.stdinJson,delete r.documentAnnotationSnapshot,r}function dt(e,t){return e!=="create"&&e!=="update"?[]:t.filter(n=>n.commands.includes(e)).map(n=>S(n))}function Wt(e,t){for(let n of e)h(n.item)&&(n.options=ct(n.item,"create",t),delete n.item)}function ut(e,t){return t.some(n=>n.metadata_key===e)?e:C(e)}function Z(e,t,n){let r=t.replaceAll(/_([a-z])/gu,(a,s)=>s.toUpperCase());if(h(e.item)){if(e.item[t]!==void 0)return e.item[t];if(ut(r,n)===t&&e.item[r]!==void 0)return e.item[r]}let i=h(e.options)?e.options:{},o=n.find(a=>a.metadata_key===t);return o!==void 0&&i[S(o)]!==void 0?i[S(o)]:i[t]!==void 0?i[t]:i[r]!==void 0?i[r]:(Array.isArray(i.field)?i.field:[]).map(String).find(a=>a.startsWith(`${t}=`))?.slice(t.length+1)}function zt(e,t){return e<t?-1:+(e!==t)}function Q(e){return Array.isArray(e)?e.map(Q):h(e)?Object.fromEntries(Object.entries(e).sort(([t],[n])=>zt(t,n)).map(([t,n])=>[t,Q(n)])):e}function _(e){return typeof e=="string"?e.trim():JSON.stringify(Q(e))}function Vt(e,t,n,r,i){let o=t.key.trim();if(o.length===0)throw new d("Upsert key must be a non-empty field name.",u.USAGE);let a=Bt(t.existing),s=new Map,c=new Set;for(let[l,p]of e.entries()){if(p.op!=="create")continue;let f=Yt(p,o,l,s,r),y=Ht(a.get(f)??[],o,f);if(y===void 0){p.unique={key:o,value:Z(p,o,r)};continue}let w=$(y,n);typeof p.ref=="string"&&(i[p.ref]=w),Xt(p,w,r,{key:o,value:Z(p,o,r)}),c.add(l)}return c}function Bt(e){let t=new Map;for(let n of e){if(n.value===void 0||n.value===null)continue;let r=_(n.value);t.set(r,[...t.get(r)??[],n.id])}return t}function Yt(e,t,n,r,i){let o=Z(e,t,i);if(o==null||o==="")throw new d(`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=_(o),s=r.get(a);if(s!==void 0)throw new d(`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 r.set(a,n),a}function Ht(e,t,n){if(e.length>1)throw new d(`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 Xt(e,t,n,r){let i=new Set([...ot.update,...dt("update",n)]),o=h(e.item)?ct(e.item,"update",n):Object.fromEntries(Object.entries(e.options).filter(([a])=>i.has(a)));delete e.item,delete e.ref,e.op="update",e.id=t,e.options=o,e.match=r}function pt(e,t,n){for(let[r,i]of e.entries())if(i.ref!==void 0){if(i.op!=="create")throw new d(`Mutation ${r+1} ref is only valid for create operations.`,u.USAGE);if(typeof i.ref!="string"||!Ye.test(i.ref))throw new d(`Mutation ${r+1} ref must match ${Ye.source}.`,u.USAGE);if(n[i.ref]!==void 0)throw new d(`Duplicate mutation ref "${i.ref}".`,u.USAGE);n[i.ref]=typeof i.id=="string"&&i.id.trim().length>0?$(i.id,t.idPrefix):Ut(t.transactionId,i.ref,t.idPrefix)}return n}function lt(e,t){let n=Kt(e);Jt(n);let r=n.map(p=>typeof p.ref=="string"?p.ref:void 0),i=Object.create(null),o=t.upsert===void 0?new Set:Vt(n,Lt(t.upsert,n,t),t.idPrefix,t.runtimeFields??[],i);Wt(n,t.runtimeFields??[]),pt(n,t,i),Dt(n,r);let a=n.map(p=>{let f={...p},y=typeof f.ref=="string"?f.ref:void 0;if(delete f.ref,y!==void 0?f.id=i[y]:f.id=Ze(f.id,i),h(f.options)){let w={...f.options};for(let g of["parent","blockedBy"])w[g]!==void 0&&(w[g]=Ze(w[g],i));Array.isArray(w.dep)?w.dep=w.dep.map(g=>Qe(g,i)):w.dep!==void 0&&(w.dep=Qe(w.dep,i)),f.options=w}return f}),s=st(JSON.stringify(a),{runtimeFields:t.runtimeFields??[]}),c=s.filter(p=>p.op==="create").map(p=>p.id);if(new Set(c).size!==c.length)throw new d("Duplicate resolved create id in mutation document.",u.USAGE);let l=s.map((p,f)=>{let y=r[f];return{index:f,...typeof y=="string"?{ref:y}:{},id:p.id,op:p.op,...o.has(f)?{upserted:!0}:{}}});return{schema_version:1,mutations:s,references:i,rows:l}}function Zt(e,t){return t.filter(n=>e[n]!==void 0&&e[n]!==null).map(n=>{let r=String(e[n]);return`${n}=${/[",\n\r\\]/u.test(r)?JSON.stringify(r):r}`}).join(",")}function Qt(e,t,n){if(e!==void 0){if(!Array.isArray(e)||!e.every(h))throw new d(`${n} must be an array of objects.`,u.USAGE);return e.map(r=>Zt(r,t))}}function en(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 et(e,t,n=!1){for(let[r,i,o]of xe){let a=t[r],s=Qt(n&&["comments","notes","learnings"].includes(r)&&Array.isArray(a)?a.filter(c=>!h(c)||c.created_at===void 0):a,o,r);s!==void 0&&s.length>0&&(e[i]=s)}}function tn(e,t){for(let n of Object.keys(e)){if(t){if(!N.includes(n))throw T("item envelope",n,N);continue}if(!b.has(n)&&D(n,[...b])===void 0&&D(n,N)==="item")throw T("item envelope",n,N)}}function nn(e){let t=Object.hasOwn(e,"item");tn(e,t);let n=t?e.item:e;if(!h(n))throw new d("Item document item must be an object.",u.USAGE);return{item:n,...t&&h(e.linked)?{linked:e.linked}:{}}}function rn(e,t,n,r,i,o){if((r==="update"?Ot:it).has(t))return;let a=i.find(s=>s.metadata_key===t&&s.commands.includes(r));if(a!==void 0){let s=Ie(o,a);e[S(a)]=s!==void 0?s:a.type==="array"||a.type==="object"?JSON.stringify(n):n;return}if(!b.has(t)){if(D(t,[...b])!==void 0)throw T("item document",t,[...b]);let s=Array.isArray(e.field)?e.field:[];s.push(`${t}=${typeof n=="string"?n:JSON.stringify(n)}`),e.field=s;return}["dependencies","comments","notes","learnings","files","tests","docs","reminders","events","type_options"].includes(t)||(e[t.replaceAll(/_([a-z])/gu,(s,c)=>c.toUpperCase())]=en(t,n))}function on(e,t,n={},r=[]){let i=ee(e,"Item document");if(!h(i))throw new d("Item document must be a JSON object.",u.USAGE);let{item:o,linked:a}=nn(i),s={};for(let[c,l]of Object.entries(o)){let p=ut(c,r);p!==c&&Object.hasOwn(o,p)||rn(s,p,l,t,r,n)}if(et(s,o,t==="update"),a!==void 0&&et(s,a),t==="update"){let c=Object.fromEntries(["comments","notes","learnings"].filter(l=>Object.hasOwn(o,l)).map(l=>[l,o[l].filter(p=>h(p)&&p.created_at!==void 0)]));Object.keys(c).length>0&&(s.documentAnnotationSnapshot=c)}return{...s,...Object.fromEntries(Object.entries(n).filter(([,c])=>c!==void 0)),...Array.isArray(s.field)&&Array.isArray(n.field)?{field:[...s.field,...n.field]}:{},stdinJson:void 0}}function Mr(e){return st(JSON.stringify(e))}import ie from"node:crypto";import{constants as te}from"node:fs";import{cp as an,lstat as ft,mkdir as sn,mkdtemp as ht,open as cn,readdir as dn,realpath as yt,rm as wt,stat as oe,writeFile as gt}from"node:fs/promises";import{tmpdir as vt}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]="4d215571-44e3-5ce8-9644-47e42dd4b23e")}catch{}})();async function ae(e,t){if(!Oe(e))return{schema:W(t.schema),typeDefinitionsFromFile:[]};let n=await _n(e,t.schema);return{schema:n.schema,typeDefinitionsFromFile:n.type_definitions_from_file??[]}}async function se(e,t,n,r){let i=L({...t,item_types:{...t.item_types,definitions:[...t.item_types?.definitions??[],...n.typeDefinitionsFromFile]}},J());return(await $e(e,t.item_format,i.type_to_folder,void 0,n.schema)).flatMap(o=>{let a=o[r];return a==null?[]:[{id:o.id,value:a}]})}function _t(e){let t=new Map,n=async r=>{let i=await k(e),o=await ae(e,i),a=new Map;for(let s of await se(e,i,o,r)){let c=_(s.value);a.set(c,[...a.get(c)??[],s.id])}return a};return{lookup(r){let i=t.get(r)??n(r);return t.set(r,i),i},async recordCreate(r){for(let[i,o]of t){let a=r[i];if(a==null)continue;let s=await o,c=_(a);s.set(c,[...s.get(c)??[],String(r.id)])}},invalidate(){t.clear()}}}async function un(e,t){let n=_(t.value),r=(await e.lookup(t.key)).get(n)??[];if(r.length!==0)throw new d(`Upsert key "${t.key}" value ${JSON.stringify(n)} now matches existing item ${r.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 pn(e,t,n){let r=e.metadata[n.key],i=_(n.value);if(_(r)!==i)throw new d(`Item ${t} no longer carries upsert key "${n.key}" value ${JSON.stringify(i)}; 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 mt(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 G(e,t){let n={...e,...t};return e===void 0?n:je(e,n)}async function E(e,t){try{let n=(await Y(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 d&&n.exitCode===u.NOT_FOUND)return;throw n}}function ce(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_"),r=ie.createHash("sha256").update(ye(e)).digest("hex").slice(0,12);return`${t+1}-${e.op}-${n}-${r}`}function ln(e,t){let n=e.id.replaceAll(/[^a-zA-Z0-9._-]/gu,"_");return`${t+1}-${e.op}-${n}`}function v(e,t,n){return`bulk-item-transaction ${e} ${t} ${n}`}async function R(e,t,n,r){let i=await M(m.join(e,"history",`${t}.jsonl`),t),o=v(n,r,"apply"),a=v(n,r,"compensate");for(let s=i.length-1;s>=0;s-=1){let c=i[s].message;if(c===o)return!0;if(c===a)return!1}return!1}async function de(e,t){let n=await E(e,t.id);if(n?.updatedAt===void 0)throw new d(`Bulk ${t.op} target ${t.id} does not exist or has no restorable version`,u.NOT_FOUND);let r=await M(m.join(e,"history",`${n.id}.jsonl`),n.id);if(r.length===0)throw new d(`Bulk ${t.op} target ${t.id} has no restorable history`,u.NOT_FOUND);return{target_updated_at:n.updatedAt,target_version:String(z(r)+r.length),target_history_hash:O(r),target_history_length:r.length}}function F(e,t,n){return new d(`Transaction ${e.transactionId} cannot safely compensate incomplete step ${n}; review item ${t} history before recovery.`,u.CONFLICT,{code:"transaction_partial_mutation",item_id:t,required:"Reconcile the item's partial or intervening changes before resuming this transaction.",why:"The retained history does not prove exclusive ownership of the changes to undo. The journal remains compensating instead of claiming a rollback or overwriting another writer.",nextSteps:[`Run pm history ${t} and inspect this transaction's retained compensation data before explicitly restoring or reconciling the item.`]})}function mn(e,t){let n=`bulk-item-transaction ${t} `;return[e.message,e.context?.item_transaction_step].some(r=>typeof r=="string"&&r.startsWith(n))}function fn(e,t,n){let{expectedHistory:r,length:i,version:o}=t;if(O(e)===r)return!1;if(typeof i!="number"||!Number.isSafeInteger(i)||i<1||O(e.slice(0,i))!==r||o!==String(z(e)+i))throw F(n,n.itemId,n.stepId);let a=v(n.transactionId,n.stepId,"apply"),s=e.slice(i),c=y=>y.message===a||y.context?.item_transaction_step===a,l=v(n.transactionId,n.stepId,"compensate");if(s.filter(y=>c(y)||y.message===l).at(-1)?.message===l)return!1;let p=s.filter(c);if(p.length===0)return!1;let f=e.at(-1).after_hash===p.at(-1).after_hash&&s.every(y=>mn(y,n.transactionId));if(p.length!==s.length&&!f)throw F(n,n.itemId,n.stepId);return!0}async function q(e,t,n,r){let i=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;if(i===void 0||typeof i.target_updated_at!="string")return;let o=i.target_updated_at,a=await E(e.pmRoot,t);if(a===void 0)return;let s=await M(m.join(e.pmRoot,"history",`${a.id}.jsonl`),a.id),c=i.target_history_hash;if(typeof c=="string"){if(!fn(s,{expectedHistory:c,length:i.target_history_length,version:i.target_version},{...e,itemId:a.id,stepId:n}))return}else{if(a.updatedAt===o)return;if(!await R(e.pmRoot,a.id,e.transactionId,n))throw F(e,a.id,n)}let l=()=>Je(t,typeof i.target_version=="string"?i.target_version:o,{force:!0,author:e.author,message:v(e.transactionId,n,"compensate")},{pmRoot:e.pmRoot});await V({pmRoot:e.pmRoot,id:a.id,validate:p=>{if(Me(p)!==s.at(-1).after_hash)throw F(e,a.id,n)}},l)}function Et(e,t,n){return{id:n,async inspect(){let r=await E(e.pmRoot,t.id);if(r===void 0)return{state:"pending"};if(r.closedAt!==void 0){let i=await M(m.join(e.pmRoot,"history",`${r.id}.jsonl`),r.id),o=`Compensated: interrupted bulk transaction ${e.transactionId}`;if(i.filter(a=>a.op==="close").at(-1)?.patch.some(a=>a.op==="add"||a.op==="replace"?a.path==="/metadata/close_reason"&&a.value===o:!1)??!1)throw new d(`Created item ${r.id} remains closed by transaction compensation; explicitly reopen or reconcile it before retrying.`,u.CONFLICT,{code:"transaction_create_compensated",item_id:r.id,required:"Review the compensated item and explicitly reopen it before retrying the same document.",why:"This item's latest closure belongs to transaction compensation. Automatically reopening it could overwrite later lifecycle decisions.",nextSteps:[`Run pm item reopen ${r.id} "Retry compensated creation" after reviewing its history, then retry the transaction.`]})}return{state:"applied",result:{id:r.id,op:"create"}}},async apply(){t.unique!==void 0&&await un(e.uniqueIndex,t.unique);let r=await Ge(G(t.options,{author:e.author,id:t.id}),{pmRoot:e.pmRoot}),i=r.item;return e.onCreateWarnings?.(String(i.id),r.warnings),await e.uniqueIndex.recordCreate(i),{id:String(i.id),op:"create"}},async compensate(){let r=await E(e.pmRoot,t.id);if(r!==void 0){if(e.createCompensation==="delete"){await Le(t.id,{force:!0,author:e.author,message:`Compensate interrupted bulk transaction ${e.transactionId}`},{pmRoot:e.pmRoot});return}r.closedAt===void 0&&await H(t.id,`Compensated: interrupted bulk transaction ${e.transactionId}`,{force:!0,author:e.author},{pmRoot:e.pmRoot})}}}}function hn(e,t,n){return{id:n,compensatePending:!0,async inspect(){let r=await E(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"update"}}:{state:"pending"}},async prepareCompensation(){return de(e.pmRoot,t)},async apply(){let r=()=>qe(t.id,G(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot}),i=t.match,o=i,a=(await V({pmRoot:e.pmRoot,id:String((await Y(t.id,{},{pmRoot:e.pmRoot})).item.id),validate:s=>{o!==void 0&&pn(s,t.id,o)},committed:s=>{i!==void 0&&(o={key:i.key,value:structuredClone(s.metadata[i.key])})},historyContext:{item_transaction_step:v(e.transactionId,n,"apply")}},r)).item;return e.uniqueIndex.invalidate(),{id:String(a.id),op:"update"}},async compensate(r){await q(e,t.id,n,r)}}}function yn(e,t,n){return{id:n,async inspect(){let r=await E(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"close"}}:r.closedAt===void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"close"}}},async prepareCompensation(){return de(e.pmRoot,t)},async apply(){let r=(await H(t.id,t.reason,G(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"close"}},async compensate(r){await q(e,t.id,n,r)}}}function wn(e,t,n){return{id:n,async inspect(){let r=await E(e.pmRoot,t.id);return r===void 0?{state:"pending"}:await R(e.pmRoot,r.id,e.transactionId,n)?{state:"applied",result:{id:r.id,op:"release"}}:r.assignee!==void 0||r.claimPrincipal!==void 0?{state:"pending"}:{state:"applied",result:{id:r.id,op:"release"}}},async prepareCompensation(){return de(e.pmRoot,t)},async apply(){let r=(await Ke(t.id,G(t.options,{author:e.author,message:v(e.transactionId,n,"apply")}),{pmRoot:e.pmRoot})).item;return e.uniqueIndex.invalidate(),{id:String(r.id),op:"release"}},async compensate(r){await q(e,t.id,n,r)}}}function St(e,t,n){let r=ce(t,n);switch(t.op){case"create":return Et(e,t,r);case"update":return hn(e,t,r);case"close":return yn(e,t,r);case"release":return wn(e,t,r)}}function gn(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&&!mt(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&&!mt(e.match))throw new TypeError(`Bulk update mutation ${t+1} match must be an object with a non-empty key and a value`);U(e.options,e.op,t)}function bt(e){if(e.length===0)throw new TypeError("Bulk item transaction requires at least one mutation");let t=new Map;for(let[n,r]of e.entries()){if(gn(r,n),r.op!=="create"||r.unique===void 0)continue;let{key:i,value:o}=r.unique,a=t.get(i)??new Map,s=_(o),c=a.get(s);if(c!==void 0)throw new d(`Bulk create mutations ${c+1} and ${n+1} share the upsert key value ${JSON.stringify(s)} for "${i}".`,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(i,a)}}async function ne(e,t,n){try{return await n()}catch(r){throw r instanceof d?new d(r.message,r.exitCode,{...r.context,transaction_operation:{index:t,op:e.op,id:e.id}}):r}}function Tt(e,t,n,r){let i=m.relative(e,t),o=i.split(m.sep);return o[0]==="extensions"&&o[2]==="node_modules"&&!r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))?!1:["locks","runtime","search"].includes(i.split(m.sep)[0])?r.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`)):i===""||n===void 0||n.some(a=>i===a||i.startsWith(`${a}${m.sep}`)||a.startsWith(`${i}${m.sep}`))}async function P(e,t){let n=await ft(t);if(n.isSymbolicLink())await oe(t);else if(n.isDirectory()||n.isFile())return n;throw A(m.relative(e,t))}async function vn(e,t){let n=await cn(t,te.O_RDONLY|te.O_NOFOLLOW|te.O_NONBLOCK);try{let r=await n.stat();if(!r.isFile())throw A(m.relative(e,t));let i=ie.createHash("sha256");if(r.size>0)for await(let o of n.createReadStream({highWaterMark:64*1024,end:r.size-1,autoClose:!1}))i.update(o);return i.digest()}finally{await n.close()}}async function re(e,t,n){let r=ie.createHash("sha256");async function i(o){for(let a of(await dn(o)).sort()){let s=m.join(o,a);Tt(e,s,t,n)&&((await P(e,s)).isDirectory()?await i(s):(r.update(JSON.stringify(m.relative(e,s))),r.update(await vn(e,s))))}}return await i(e),r.digest("hex")}function j(){return new d("Tracker changed while preparing the transaction preview; retry against stable state.",u.CONFLICT,{code:"transaction_preview_snapshot_changed"})}async function ue(e){if(!K(e))return!1;let t=e.path;if(typeof t!="string")return!1;let n=m.resolve(t),r=n;for(;;)try{let i=await ft(r);return r!==n&&i.isDirectory()}catch(i){if(!K(i))return!1;let o=m.dirname(r);if(o===r)return!1;r=o}}async function x(e,t){let n=m.join(e,t);try{let r=e;for(let i of t.split(m.sep).slice(0,-1))r=m.join(r,i),await P(e,r);if(!(await P(e,n)).isFile())throw A(t);return await fe(n,A(t))}catch(r){if(await ue(r))return;throw r}}async function It(e,t,n,r){let i=W(n);for(let[o,a]of Object.entries(i.files)){let s=m.relative(e,Se(e,a,Ee[o]));if(s===""||!m.resolve(e,s).startsWith(m.join(e,m.sep)))throw new d("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}`});i.files[o]=s;let c=await x(e,s);if(r?.set(s,c),c!==void 0){let l=m.join(t,s);await sn(m.dirname(l),{recursive:!0}),await gt(l,c)}}return be(t,i)}async function _n(e,t){await oe(e);let n=await ht(m.join(vt(),"pm-schema-plan-"));try{let r=await yt(e);return await It(r,m.join(n,"configuration"),t)}catch(r){throw await ue(r)?j():r}finally{await wt(n,{recursive:!0,force:!0})}}async function En(e,t,n){let r=new Map,i=await x(e,I);r.set(I,i);let o;try{o=JSON.parse(i??"null")}catch{o=null}let a=Re(o),s=a.success?a.data:void 0,c=await It(e,t,s?.schema,r),l=c.schema,p=m.relative(e,Ae(e));r.set(p,await x(e,p));let f=L({...me,item_types:{definitions:[...s?.item_types?.definitions??[],...c.type_definitions_from_file??[]]}},n),y=he(e)===e?[...le.filter(Boolean),I,ve,"transactions",...f.folders,...r.keys()].map(g=>m.normalize(g)):void 0,w=s===void 0?void 0:JSON.stringify({...o,schema:{...s.schema,files:l.files}});return{configuration:r,ownedPaths:y,stagedSettings:w,registryFolders:f.folders}}async function Sn(e,t,n){await oe(e);try{let r=await yt(e),i=await En(r,m.join(m.dirname(t),"configuration"),n),o=[...i.configuration.keys(),...i.registryFolders].map(l=>m.normalize(l)),a=await re(r,i.ownedPaths,o);await an(r,t,{recursive:!0,dereference:!1,filter:async l=>Tt(r,l,i.ownedPaths,o)?(await P(r,l),!0):!1});let[s,c]=await Promise.all([re(r,i.ownedPaths,o),re(t,i.ownedPaths,o)]);if(a!==s||a!==c)throw j();for(let[l,p]of i.configuration)if(await x(t,l)!==p)throw j();i.stagedSettings!==void 0&&await gt(m.join(t,I),i.stagedSettings)}catch(r){throw await ue(r)?j():r}}async function At(e){let t=Ce(e),n=[...e.mutations];bt(n);let r=J(),i=await ht(m.join(vt(),"pm-transaction-preview-")),o=m.join(i,"tracker");try{await Sn(t.pmRoot,o,r);let a=!1,s=[];return await We({path:o,noExtensions:!0},async()=>{ge(r);let c={...t,pmRoot:o,createCompensation:"close",uniqueIndex:_t(o)},l=n.map((p,f)=>{let y=St({...c,onCreateWarnings:(w,g)=>{g.length>0&&s.push({index:f,id:w,op:"create",warnings:g})}},p,f);return{...y,inspect:()=>ne(p,f,()=>y.inspect()),prepareCompensation:()=>ne(p,f,async()=>y.prepareCompensation?.()),apply:()=>ne(p,f,()=>y.apply())}});await B({...t,pmRoot:o,steps:l,onTransition:({transition:p})=>{p==="committed"&&(a=!0)}})}),{validated:a,state:a?"staged_snapshot":"replayed_committed_plan",warnings:s,unresolved_commit_constraints:["concurrent_tracker_changes","extension_mutation_guards_and_hooks","derived_extension_dependencies_excluded"]}}finally{await wt(i,{recursive:!0,force:!0})}}async function bn(e){let t=[...e.mutations];bt(t);let n=e.createCompensation??"close";if(!["close","delete"].includes(n))throw new TypeError("Bulk item transaction createCompensation must be close or delete");let r={pmRoot:e.pmRoot,author:e.author,transactionId:e.transactionId,createCompensation:n,uniqueIndex:_t(e.pmRoot)},i=await B({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,steps:t.map((a,s)=>St(r,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 c=ce(s,a),l=i.results[c];o[ln(s,a)]=l}return{transactionId:i.transactionId,status:"committed",recovered:i.recovered,results:o}}function Tn(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 ni(e){return bn({pmRoot:e.pmRoot,transactionId:e.transactionId,author:e.author,mutations:Tn(e),...e.lockTtlSeconds===void 0?{}:{lockTtlSeconds:e.lockTtlSeconds},...e.lockWaitMs===void 0?{}:{lockWaitMs:e.lockWaitMs},...e.onTransition===void 0?{}:{onTransition:e.onTransition}})}var ri={buildCreateStep:Et,bulkHistoryMarker:v,compensateByRestore:q,deriveStepId:ce,isUpdateMarkerApplied:R,readItemSnapshot: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]="3041c268-69c8-58e5-8a68-eaaa3c0dbd3b")}catch{}})();async function li(e){let{plan:t}=e,n=await At({pmRoot:e.pmRoot,author:e.author,transactionId:t.transaction_id,mutations:t.mutations}),r=new Map(n.warnings.map(o=>[o.index,o.warnings])),i=t.rows.map(o=>{let a={...o};delete a.warnings;let s=r.get(o.index);return s!==void 0&&(a.warnings=s),a});return{validation:n,rows:i}}async function mi(e){let t=e.upsertKey?.trim();if(t!==void 0&&t.length===0)throw new d("Upsert key must be a non-empty field name.",u.USAGE);let n=e.settings??await k(e.pmRoot),r=e.transactionId?.trim()??"",i=r.length>0?r:at(e.input),o=await ae(e.pmRoot,n),a=Te(o.schema).definitions,s=(a.find(l=>l.metadata_key===t)??a.find(l=>l.key===t||S(l)===t))?.metadata_key??C(t),c=s===void 0?void 0:{key:s,existing:await se(e.pmRoot,n,o,s)};return{...lt(e.input,{transactionId:i,idPrefix:n.id_prefix,runtimeFields:a,...c===void 0?{}:{upsert:c}}),transaction_id:i,transaction_id_source:r.length>0?"explicit":"derived",...c===void 0?{}:{upsert_key:c.key}}}export{at as a,Ar as b,st as c,_ as d,lt as e,on as f,Mr as g,ae as h,se as i,_n as j,At as k,bn as l,Tn as m,ni as n,ri as o,li as p,mi as q};
2
+ //# sourceMappingURL=chunk-ZX3XMTZG.js.map
@@ -1,4 +1,4 @@
1
- import{d as E}from"./chunk-ER7RLJW5.js";import{b as I}from"./chunk-VS565KBX.js";import"./chunk-ONC4BBQP.js";import"./chunk-XAWE4EAK.js";import{execFile as O}from"node:child_process";import{realpath as v}from"node:fs/promises";import b from"node:path";import{promisify as M}from"node:util";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new n.Error().stack;o&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[o]="5d2c2c37-5ff2-5dab-84f1-55a7fa8d5a27")}catch{}})();var w=M(O),x="[a-f0-9]{40}(?:[a-f0-9]{24})?",N=new RegExp(`^100(?:644|755) (${x}) 0$`,"u"),R=new RegExp(`^(${x}) blob (\\d+)$`,"u");async function _(n,o,a){let t=w("git",n,{...a,encoding:"buffer"}),e=t.child.stdin;return e!==null&&(e.on("error",()=>{t.child.kill()}),e.end(`${o.join(`
1
+ import{d as E}from"./chunk-TH5KPAN4.js";import{b as I}from"./chunk-VS565KBX.js";import"./chunk-RZQNFHXO.js";import"./chunk-XAWE4EAK.js";import{execFile as O}from"node:child_process";import{realpath as v}from"node:fs/promises";import b from"node:path";import{promisify as M}from"node:util";(function(){try{var n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new n.Error().stack;o&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[o]="5d2c2c37-5ff2-5dab-84f1-55a7fa8d5a27")}catch{}})();var w=M(O),x="[a-f0-9]{40}(?:[a-f0-9]{24})?",N=new RegExp(`^100(?:644|755) (${x}) 0$`,"u"),R=new RegExp(`^(${x}) blob (\\d+)$`,"u");async function _(n,o,a){let t=w("git",n,{...a,encoding:"buffer"}),e=t.child.stdin;return e!==null&&(e.on("error",()=>{t.child.kill()}),e.end(`${o.join(`
2
2
  `)}
3
3
  `)),(await t).stdout}function B(n,o){let a=new Map;for(let t of n.split("\0")){let e=t.indexOf(" "),i=t.slice(e+1),r=N.exec(t.slice(0,e));r!==null&&o.has(i)&&a.set(i,r[1])}return a}function D(n,o,a){let t=[],e=[],i=0;for(let r of n.trimEnd().split(/\r?\n/u)){let s=R.exec(r);if(s===null||!o.has(s[1]))continue;let c=Number(s[2]);!Number.isSafeInteger(c)||c>a||(e.length>0&&i+c+128>a&&(t.push(e),e=[],i=0),e.push({id:s[1],size:c}),i+=c+128)}return e.length>0&&t.push(e),t}function S(n,o,a){let t=0;for(let{id:e,size:i}of o){let r=n.indexOf(10,t)+1;if(r===0||n.subarray(t,r-1).toString("ascii")!==`${e} blob ${i}`||n[r+i]!==10)throw new Error("Invalid indexed receipt batch framing");a.set(e,n.subarray(r,r+i).toString("utf8")),t=r+i+1}if(t!==n.length)throw new Error("Unexpected indexed receipt batch data")}async function k(n,o,a,t,e,i={}){let r=I();r.GIT_NO_REPLACE_OBJECTS="1",e===void 0&&process.env.GIT_INDEX_FILE!==void 0&&(r.GIT_INDEX_FILE=b.resolve(process.env.GIT_INDEX_FILE));let s={cwd:n,env:r,windowsHide:!0,timeout:1e4,maxBuffer:t+256};try{let c=(await w("git",["rev-parse","--show-toplevel"],{...s,encoding:"utf8"})).stdout.trim(),[g,y]=await Promise.all([v(c),v(e??o)]),d=b.relative(g,e===void 0?y:b.resolve(e)).replaceAll("\\","/");if(E(d))return new Map;s.cwd=g;let m=new Map(a.map(f=>[`${d}/${f}`,f])),T=(await w("git",["ls-files","--stage","-z","--",`:(literal)${d}/`],{...s,encoding:"utf8"})).stdout,p=B(T,new Set(m.keys()));if(p.size===0)return new Map;let u=new Set(p.values()),$=(await _(["cat-file","--batch-check"],[...u],s)).toString("utf8"),l=new Map;for(let f of D($,u,t))S(await _(["cat-file","--batch"],f.map(h=>h.id),s),f,l);if(i.failOnReadError&&l.size!==u.size)throw new Error("Unable to read every indexed receipt blob");return new Map([...p].filter(([,f])=>l.has(f)).map(([f,h])=>[m.get(f),l.get(h)]))}catch(c){if(i.failOnReadError)throw c;return new Map}}export{k as readIndexedReceiptBlobs};
4
- //# sourceMappingURL=indexed-receipt-blobs-63WYG2PY.js.map
4
+ //# sourceMappingURL=indexed-receipt-blobs-LHLE7PSG.js.map
@@ -1,2 +1,2 @@
1
- import{a as E,f as N}from"./chunk-H434DKYU.js";import{Bb as C,Me as R,Pe as A,vb as y}from"./chunk-QQYLNHZK.js";import{Db as _,og as h,pg as w,rg as T,xa as g,zi as O}from"./chunk-UHKN6TJM.js";import{C as f}from"./chunk-ONC4BBQP.js";import"./chunk-XAWE4EAK.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new t.Error().stack;o&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[o]="d19ff816-7570-5e8a-a4de-ad2ca48f0df0")}catch{}})();function b(t,o,r,a=!1){let d=[...r].map(n=>({candidate:n,distance:_(o,n,3)})).filter(n=>n.distance!==null).sort((n,i)=>n.distance-i.distance||n.candidate.localeCompare(i.candidate))[0]?.candidate,s=a?`Put mutation fields under options (options.${o}).`:d?`Did you mean "${d}"?`:"Use the declared command options or the field option for registered item fields.";throw new f(`Unknown ${t} ${a?"argument":"option"} "${o}". ${s} No changes were made.`,2,{code:"invalid_argument_value",reason:"unknown_mutation_option",changed:!1,field:o,required:s,nextSteps:[s]})}async function j(t,o,r,a,d){if(E(o))return;let s=t==="create"?R:A,n=(t==="create"?y:C).map(({flag:e})=>e.slice(2).replace(/-([a-z])/gu,(m,v)=>v.toUpperCase())),i=new Set([...s.flatMap(e=>[e.target,...e.keys]),...n]),l=["outputInclude","outputLimit","outputBudget","outputFormat","outputSession","outputCursor"];for(let e of["author","message","force","fullChangedFields","idOnly",...l])i.add(e);let S=new Set(["action","options","path","cwd","author","force","noExtensions","no_extensions","fullChangedFields","idOnly",...l,...d,...t==="update"?["id"]:[]]);for(let e of Object.keys(o))S.has(e)||b(t,e,i,i.has(e));let u=o.options;if(u!==void 0&&!N(u))throw new f("Mutation options must be an object. No changes were made.",2,{code:"invalid_argument_value",changed:!1});let c=[...new Set([...Object.keys(u??{}),...Object.keys(r)])].filter(e=>!i.has(e));if(c.length===0)return;let p=h((await O(g(process.cwd(),a))).schema).command_to_fields.get(t)??[];for(let e of p)i.add(w(e));for(let e of c)p.some(m=>T({[e]:!0},m)===!0)||b(t,e,i)}export{j as assertNativeMutationOptions};
2
- //# sourceMappingURL=mutation-admission-L3A6FSZ7.js.map
1
+ import{a as E,f as N}from"./chunk-JESLOJD7.js";import{Bb as C,Me as R,Pe as A,vb as y}from"./chunk-CS7QDSUX.js";import{Bi as O,Db as _,qg as h,rg as w,tg as T,xa as g}from"./chunk-7V37RC2L.js";import{C as f}from"./chunk-RZQNFHXO.js";import"./chunk-XAWE4EAK.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},o=new t.Error().stack;o&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[o]="d19ff816-7570-5e8a-a4de-ad2ca48f0df0")}catch{}})();function b(t,o,r,a=!1){let d=[...r].map(n=>({candidate:n,distance:_(o,n,3)})).filter(n=>n.distance!==null).sort((n,i)=>n.distance-i.distance||n.candidate.localeCompare(i.candidate))[0]?.candidate,s=a?`Put mutation fields under options (options.${o}).`:d?`Did you mean "${d}"?`:"Use the declared command options or the field option for registered item fields.";throw new f(`Unknown ${t} ${a?"argument":"option"} "${o}". ${s} No changes were made.`,2,{code:"invalid_argument_value",reason:"unknown_mutation_option",changed:!1,field:o,required:s,nextSteps:[s]})}async function j(t,o,r,a,d){if(E(o))return;let s=t==="create"?R:A,n=(t==="create"?y:C).map(({flag:e})=>e.slice(2).replace(/-([a-z])/gu,(m,v)=>v.toUpperCase())),i=new Set([...s.flatMap(e=>[e.target,...e.keys]),...n]),l=["outputInclude","outputLimit","outputBudget","outputFormat","outputSession","outputCursor"];for(let e of["author","message","force","fullChangedFields","idOnly",...l])i.add(e);let S=new Set(["action","options","path","cwd","author","force","noExtensions","no_extensions","fullChangedFields","idOnly",...l,...d,...t==="update"?["id"]:[]]);for(let e of Object.keys(o))S.has(e)||b(t,e,i,i.has(e));let u=o.options;if(u!==void 0&&!N(u))throw new f("Mutation options must be an object. No changes were made.",2,{code:"invalid_argument_value",changed:!1});let c=[...new Set([...Object.keys(u??{}),...Object.keys(r)])].filter(e=>!i.has(e));if(c.length===0)return;let p=h((await O(g(process.cwd(),a))).schema).command_to_fields.get(t)??[];for(let e of p)i.add(w(e));for(let e of c)p.some(m=>T({[e]:!0},m)===!0)||b(t,e,i)}export{j as assertNativeMutationOptions};
2
+ //# sourceMappingURL=mutation-admission-GKDKHRTZ.js.map
@@ -1,4 +1,4 @@
1
- import{a as de}from"./chunk-2XUDAQK5.js";import"./chunk-DEZPZOQ7.js";import{b as g,c as I,d as D}from"./chunk-X5TMR7KC.js";import{L as ne,P as ie,U as ae,n as te,u as A,w as oe}from"./chunk-F26MRQZY.js";import{Gc as K,Sc as W,Uc as X,Wc as Y,Yb as V,Za as Q,Zc as Z,_c as ee,ad as re,bd as se,cd as le,ka as H}from"./chunk-O3LPT34G.js";import"./chunk-4D25HF3V.js";import{$f as M,Of as y,Rf as s,Tf as l,Zf as G,_f as L,ag as $,bg as N,cg as U,dg as B,eg as P,fd as R,fg as z,gd as q,gg as J}from"./chunk-QQYLNHZK.js";import"./chunk-SPPHDVZE.js";import"./chunk-IB7UB5TE.js";import{Df as j,Kf as v,Nf as f,Of as m,Tc as k,k as E,l as O,tf as _,xa as C,zi as T}from"./chunk-UHKN6TJM.js";import{A as c,C as u}from"./chunk-ONC4BBQP.js";import"./chunk-XAWE4EAK.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]="19d28e23-5337-5ec0-83e6-6e43b462ece7")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="69ca287f-eeb9-5e65-a3ba-be47ab223c04")}catch{}})();async function fe(e,t){let o=y(t),i=Date.now();if([e.raw,e.compact,e.full,e.provenance].filter(d=>d===!0).length>1)throw new u("Activity projection options are mutually exclusive. Use --raw, --compact, --provenance, or --full.",c.USAGE);let a=P(e.stream);if(a&&!o.json)throw new u("--stream requires --json output mode.",c.USAGE);let n=B(e),r=await V(a&&e.full!==!0&&e.provenance!==!0?{...n,raw:!0,compact:!0}:n,o);a?$(r,n,o):f(r,o),o.profile&&m(`profile:command=activity took_ms=${Date.now()-i}`)}function F(e){e.option("--id <value>","Filter by item ID").option("--op <value>","Filter by history operation").option("--author <value>","Filter by history author").option("--from <value>","Inclusive lower time bound (ISO or relative)").option("--to <value>","Exclusive upper time bound (ISO or relative)").option("--limit <n>","Maximum activity rows").option("--after <cursor>","Continue a fixed-window page").option("--unbounded","Return every matching row").option("--compact","Show compact event rows").option("--raw","Show the legacy compact per-event stream instead of the item digest").option("--full","Show full activity entries with JSON Patch payloads").option("--provenance","Show patch-free author, harness, instance, and extensible provenance").option("--provenance-summary","Include provenance counts").option("--harness <value>","Filter by harness (repeatable)",s).option("--agent-instance <value>","Filter by agent instance (repeatable)",s).option("--provenance-filter <dimension=value>","Filter exact provenance values (repeatable)",s).option("--stream [mode]","Emit line-delimited JSON rows (requires --json): rows|ndjson|jsonl").description("Show recent activity across items.").action(fe)}(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]="1a62fe05-4407-5e76-87fa-5109dcca5640")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="25c5349b-60d7-505b-98b0-3ed19e44b791")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b40cde4c-ca5a-522d-a731-52503c7e4fe0")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9212f45c-798d-5774-87ce-bb7d6ff5514a")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="deee1339-ac17-5ae9-8add-a9dd766d182e")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="de0fbee0-0bcf-5a46-9013-f7f883d3d0a3")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b662e21b-a163-5834-8789-65243f4c7c9c")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="5cc1722c-b797-5b95-a493-3925003ba72e")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="35c679a2-9d47-51fa-8bd2-175a4ec48d6b")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9c5f2e6d-c6a0-5ecf-b659-712fb5b37f3c")}catch{}})();function ye(e,t){return!t||t.size===0?!0:e==="context"?t.has("context")||t.has("ctx"):t.has(e)}function ce(e){if(e===void 0)return;if(typeof e!="string")throw new u("List --format must be one of csv|table|json|ndjson|toon",c.USAGE);let t=e.trim().toLowerCase();if(t==="csv"||t==="table"||t==="json"||t==="ndjson"||t==="toon")return t;throw new u("List --format must be one of csv|table|json|ndjson|toon",c.USAGE)}function S(e,t,o,i=!1){if(t===void 0)return o;if(typeof t!="string")throw new u(`${e} --format must be one of ${i?"json|ndjson|toon":"json|toon"}`,c.USAGE);let a=t.trim().toLowerCase();if(a!=="json"&&(a!=="ndjson"||!i)&&a!=="toon")throw new u(`${e} --format must be one of ${i?"json|ndjson|toon":"json|toon"}`,c.USAGE);if(o.json===!0&&a==="toon")throw new u(`${e} cannot combine --json with --format toon`,c.USAGE);return{...o,json:a==="json"||a==="ndjson"}}function he(e,t){j[t]==="brief"&&e.includeBody!==!0&&e.compact!==!0&&e.brief!==!0&&e.full!==!0&&e.fields===void 0&&(e.brief=!0)}function ue(e){e.option("--has-notes","Show only items that have notes").option("--has-learnings","Show only items that have learnings").option("--has-files","Show only items that have linked files").option("--has-docs","Show only items that have linked docs").option("--has-tests","Show only items that have linked tests").option("--has-comments","Show only items that have comments").option("--has-deps","Show only items that have dependencies").option("--has-body","Show only items that have a non-empty body").option("--has-linked-command","Show only items whose linked tests carry a runnable command").option("--no-notes","Show only items that have no notes").option("--no-learnings","Show only items that have no learnings").option("--no-files","Show only items that have no linked files").option("--filter-files-missing","Alias for --no-files").option("--no-docs","Show only items that have no linked docs").option("--filter-docs-missing","Alias for --no-docs").option("--no-tests","Show only items that have no linked tests").option("--no-comments","Show only items that have no comments").option("--no-deps","Show only items that have no dependencies").option("--empty-body","Show only items with an empty body").option("--no-linked-command","Show only items whose linked tests carry no runnable command").option("--filter-reviewer-missing","Show only items missing reviewer").option("--filter-risk-missing","Show only items missing risk").option("--filter-confidence-missing","Show only items missing confidence").option("--filter-sprint-missing","Show only items missing sprint").option("--filter-release-missing","Show only items missing release")}var ve={draft:{name:"list-draft",dependencyBlocked:!1},open:{name:"list-open",dependencyBlocked:!1},in_progress:{name:"list-in-progress",dependencyBlocked:!1},blocked:{name:"list-blocked",dependencyBlocked:!0},closed:{name:"list-closed",dependencyBlocked:!1},canceled:{name:"list-canceled",dependencyBlocked:!1}};function ge(e,t){let o=e.stream===!0,i=ce(e.format),a=i==="csv"||i==="table",n=i==="json"||i==="ndjson"||i==="toon"?S("List",e.format,t,!0):t;if(o&&!n.json)throw new u("--stream requires --json output mode.",c.USAGE);if((a||i==="ndjson")&&o)throw new u("--format csv|table|ndjson cannot be combined with --stream.",c.USAGE);return{streamMode:o,listFormat:i,effectiveGlobal:n}}function be(e,t,o){if(o.listFormat==="csv"||o.listFormat==="table"){k(t);let i=t.items,a=o.listFormat==="csv"?R(i):q(i);!o.effectiveGlobal.quiet&&a.length>0&&v(`${a}
1
+ import{a as de}from"./chunk-DM3PICGU.js";import"./chunk-DEZPZOQ7.js";import{b as g,c as I,d as D}from"./chunk-D3AIQZXF.js";import{L as ne,P as ie,U as ae,n as te,u as A,w as oe}from"./chunk-XHONSCLJ.js";import{Gc as K,Sc as W,Uc as X,Wc as Y,Yb as V,Za as Q,Zc as Z,_c as ee,ad as re,bd as se,cd as le,ka as H}from"./chunk-PQLRKFPZ.js";import"./chunk-4D25HF3V.js";import{$f as M,Of as y,Rf as s,Tf as l,Zf as G,_f as L,ag as $,bg as N,cg as U,dg as B,eg as P,fd as R,fg as z,gd as q,gg as J}from"./chunk-CS7QDSUX.js";import"./chunk-SPPHDVZE.js";import"./chunk-IB7UB5TE.js";import{Bi as T,Ff as j,Mf as v,Pf as f,Qf as m,Tc as k,k as E,l as O,vf as _,xa as C}from"./chunk-7V37RC2L.js";import{A as c,C as u}from"./chunk-RZQNFHXO.js";import"./chunk-XAWE4EAK.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]="19d28e23-5337-5ec0-83e6-6e43b462ece7")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="69ca287f-eeb9-5e65-a3ba-be47ab223c04")}catch{}})();async function fe(e,t){let o=y(t),i=Date.now();if([e.raw,e.compact,e.full,e.provenance].filter(d=>d===!0).length>1)throw new u("Activity projection options are mutually exclusive. Use --raw, --compact, --provenance, or --full.",c.USAGE);let a=P(e.stream);if(a&&!o.json)throw new u("--stream requires --json output mode.",c.USAGE);let n=B(e),r=await V(a&&e.full!==!0&&e.provenance!==!0?{...n,raw:!0,compact:!0}:n,o);a?$(r,n,o):f(r,o),o.profile&&m(`profile:command=activity took_ms=${Date.now()-i}`)}function F(e){e.option("--id <value>","Filter by item ID").option("--op <value>","Filter by history operation").option("--author <value>","Filter by history author").option("--from <value>","Inclusive lower time bound (ISO or relative)").option("--to <value>","Exclusive upper time bound (ISO or relative)").option("--limit <n>","Maximum activity rows").option("--after <cursor>","Continue a fixed-window page").option("--unbounded","Return every matching row").option("--compact","Show compact event rows").option("--raw","Show the legacy compact per-event stream instead of the item digest").option("--full","Show full activity entries with JSON Patch payloads").option("--provenance","Show patch-free author, harness, instance, and extensible provenance").option("--provenance-summary","Include provenance counts").option("--harness <value>","Filter by harness (repeatable)",s).option("--agent-instance <value>","Filter by agent instance (repeatable)",s).option("--provenance-filter <dimension=value>","Filter exact provenance values (repeatable)",s).option("--stream [mode]","Emit line-delimited JSON rows (requires --json): rows|ndjson|jsonl").description("Show recent activity across items.").action(fe)}(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]="1a62fe05-4407-5e76-87fa-5109dcca5640")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="25c5349b-60d7-505b-98b0-3ed19e44b791")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b40cde4c-ca5a-522d-a731-52503c7e4fe0")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9212f45c-798d-5774-87ce-bb7d6ff5514a")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="deee1339-ac17-5ae9-8add-a9dd766d182e")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="de0fbee0-0bcf-5a46-9013-f7f883d3d0a3")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="b662e21b-a163-5834-8789-65243f4c7c9c")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="5cc1722c-b797-5b95-a493-3925003ba72e")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="35c679a2-9d47-51fa-8bd2-175a4ec48d6b")}catch{}})();(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="9c5f2e6d-c6a0-5ecf-b659-712fb5b37f3c")}catch{}})();function ye(e,t){return!t||t.size===0?!0:e==="context"?t.has("context")||t.has("ctx"):t.has(e)}function ce(e){if(e===void 0)return;if(typeof e!="string")throw new u("List --format must be one of csv|table|json|ndjson|toon",c.USAGE);let t=e.trim().toLowerCase();if(t==="csv"||t==="table"||t==="json"||t==="ndjson"||t==="toon")return t;throw new u("List --format must be one of csv|table|json|ndjson|toon",c.USAGE)}function S(e,t,o,i=!1){if(t===void 0)return o;if(typeof t!="string")throw new u(`${e} --format must be one of ${i?"json|ndjson|toon":"json|toon"}`,c.USAGE);let a=t.trim().toLowerCase();if(a!=="json"&&(a!=="ndjson"||!i)&&a!=="toon")throw new u(`${e} --format must be one of ${i?"json|ndjson|toon":"json|toon"}`,c.USAGE);if(o.json===!0&&a==="toon")throw new u(`${e} cannot combine --json with --format toon`,c.USAGE);return{...o,json:a==="json"||a==="ndjson"}}function he(e,t){j[t]==="brief"&&e.includeBody!==!0&&e.compact!==!0&&e.brief!==!0&&e.full!==!0&&e.fields===void 0&&(e.brief=!0)}function ue(e){e.option("--has-notes","Show only items that have notes").option("--has-learnings","Show only items that have learnings").option("--has-files","Show only items that have linked files").option("--has-docs","Show only items that have linked docs").option("--has-tests","Show only items that have linked tests").option("--has-comments","Show only items that have comments").option("--has-deps","Show only items that have dependencies").option("--has-body","Show only items that have a non-empty body").option("--has-linked-command","Show only items whose linked tests carry a runnable command").option("--no-notes","Show only items that have no notes").option("--no-learnings","Show only items that have no learnings").option("--no-files","Show only items that have no linked files").option("--filter-files-missing","Alias for --no-files").option("--no-docs","Show only items that have no linked docs").option("--filter-docs-missing","Alias for --no-docs").option("--no-tests","Show only items that have no linked tests").option("--no-comments","Show only items that have no comments").option("--no-deps","Show only items that have no dependencies").option("--empty-body","Show only items with an empty body").option("--no-linked-command","Show only items whose linked tests carry no runnable command").option("--filter-reviewer-missing","Show only items missing reviewer").option("--filter-risk-missing","Show only items missing risk").option("--filter-confidence-missing","Show only items missing confidence").option("--filter-sprint-missing","Show only items missing sprint").option("--filter-release-missing","Show only items missing release")}var ve={draft:{name:"list-draft",dependencyBlocked:!1},open:{name:"list-open",dependencyBlocked:!1},in_progress:{name:"list-in-progress",dependencyBlocked:!1},blocked:{name:"list-blocked",dependencyBlocked:!0},closed:{name:"list-closed",dependencyBlocked:!1},canceled:{name:"list-canceled",dependencyBlocked:!1}};function ge(e,t){let o=e.stream===!0,i=ce(e.format),a=i==="csv"||i==="table",n=i==="json"||i==="ndjson"||i==="toon"?S("List",e.format,t,!0):t;if(o&&!n.json)throw new u("--stream requires --json output mode.",c.USAGE);if((a||i==="ndjson")&&o)throw new u("--format csv|table|ndjson cannot be combined with --stream.",c.USAGE);return{streamMode:o,listFormat:i,effectiveGlobal:n}}function be(e,t,o){if(o.listFormat==="csv"||o.listFormat==="table"){k(t);let i=t.items,a=o.listFormat==="csv"?R(i):q(i);!o.effectiveGlobal.quiet&&a.length>0&&v(`${a}
2
2
  `)}else if(o.listFormat==="ndjson"){k(t);let i=I(t.items);!o.effectiveGlobal.quiet&&i.length>0&&v(`${i}
3
3
  `)}else o.streamMode?M(e,t,o.effectiveGlobal):f(t,o.effectiveGlobal)}async function we(e){let t=y(e.actionCommand),o=e.aliasContract?{...t,command:e.aliasContract.canonical}:t,i=Date.now();e.aliasContract?.lifecycle==="deprecated"&&await T(C(process.cwd(),o.path)).then(me=>me.ux.deprecation_hints)&&m(O(e.aliasContract));let a=_("list",e.options),n=G(a),r=xe(e,n),{effectiveName:d,effectiveStatus:h,effectiveDependencyBlocked:p,effectiveExcludeTerminal:w}=r;he(n,e.name),Object.assign(n,{projectionCommand:d}),w&&(n.excludeTerminal=!0),n.dependencyBlocked=p;let x=ge(a,o),pe=await H(p?void 0:h,n,o);be("list",pe,x),o.profile&&m(`profile:command=list took_ms=${Date.now()-i}`)}function xe(e,t){let o=e.name,i=e.status,a=e.dependencyBlocked===!0,n=e.excludeTerminal===!0,r=t.status?.trim().toLowerCase(),d=e.name==="list"&&r!==void 0?ve[r]:void 0;return e.name==="list"&&(e.options.all===!0||r==="all"?(o="list-all",n=!1,t.status=void 0):r!==void 0&&d!==void 0&&(o=d.name,i=r,a=d.dependencyBlocked,n=!1,t.status=void 0)),(o==="list-open"||o==="list-in-progress")&&(t.lifecycleBucket=o==="list-open"?"open":"in_progress",i=void 0),{effectiveName:o,effectiveStatus:i,effectiveDependencyBlocked:a,effectiveExcludeTerminal:n}}function ke(e,t){let{name:o,description:i,status:a,excludeTerminal:n,allowStatusFilter:r,dependencyBlocked:d,aliasContract:h}=t,p=e.command(o,{hidden:h?.hidden===!0}).description(i);r&&p.option("--status <value>","Filter by status (repeatable or comma-separated; matches any; all selects every status)",s),o==="list"&&p.option("--all","Include every lifecycle status"),p.option("--for <intent>",`Apply a declared context intent projection. ${g("list","--for")}`).option("--token-budget <n>","Override the selected intent's maximum estimated output tokens").option("--type <value>","Filter by item type (repeatable or comma-separated; matches any)",s).option("--tag <value>","Filter by tag (repeatable or comma-separated; matches any)",s).option("--priority <value>","Filter by priority (repeatable or comma-separated; matches any)",s).option("--deadline-before <value>","Filter by deadline upper bound (ISO/date string or relative)").option("--deadline-after <value>","Filter by deadline lower bound (ISO/date string or relative)").option("--today","Filter to items updated since local midnight today").option("--recent","Filter to items updated in the last 7 days").option("--updated-after <value>","Updated since ISO timestamp or signed relative (-2h/-7d for past); use last-window ISO").option("--updated-before <value>","Filter by updated_at upper bound: ISO timestamp or signed relative (-2h/+1d)").option("--created-after <value>","Filter by created_at lower bound: ISO timestamp or signed relative (-2h/+1d)").option("--created-before <value>","Filter by created_at upper bound: ISO timestamp or signed relative (-2h/+1d)").option("--ids <value>","Filter by explicit item IDs (comma-separated or repeatable)").option("--assignee <value>","Filter by assignee",s).option("--assignee-filter <value>","Filter assignee presence: assigned|unassigned").option("--parent <value>","Filter by parent item ID").option("--sprint <value>","Filter by sprint",s).option("--release <value>","Filter by release",s).option("--filter-ac-missing","Show only items missing acceptance_criteria").option("--filter-estimates-missing","Show only items missing estimated_minutes").option("--filter-resolution-missing","Show only terminal items missing resolution").option("--filter-metadata-missing","Show only items missing any tracked metadata (AC, estimate, or resolution)").option("--limit <n>","Alias for --output-limit; --output-budget may cap rows").option("--offset <n>","Skip the first n matching rows before limit is applied").option("--after <cursor>","Query next_cursor; output_cursor uses --output-cursor").option("--no-truncate","Disable default token cap; explicit --limit and --output-budget apply").option("--include-body","Include item body in each returned list row").option("--strict-read","Fail closed if any item document or item directory cannot be read").option("--compact","Render compact list projection fields (mutually exclusive with --brief/--full/--fields)").option("--brief","Brief rows: id, status, type, title and leading sort field (priority by default; excludes --compact/--full/--fields)").option("--full","Render full list projection fields (mutually exclusive with --compact/--brief/--fields)").option("--fields <value>",`Render custom comma-separated list fields (mutually exclusive with --compact/--brief/--full). ${g(o,"--fields")}`).option("--sort <value>","Sort field: priority|deadline|updated_at|created_at|title|parent (aliases: updated, created)").option("--order <value>","Sort order: asc|desc (requires --sort)").option("--tree","Render rows in parent/child tree order").option("--tree-depth <n>","Maximum recursion depth with --tree (0 keeps root rows only)").option("--format <value>","Output render mode: csv|table (human export) or json|ndjson|toon (machine output override)").option("--stream","Emit line-delimited JSON rows (requires --json)"),ue(p),p.action(async(w,x)=>{await we({name:o,status:a,excludeTerminal:n,dependencyBlocked:d,options:w,actionCommand:x,aliasContract:h})}),l(p,"--tags <value>","Alias for --tag"),l(p,"--assignee_filter <value>","Alias for --assignee-filter"),l(p,"--tree_depth <n>","Alias for --tree-depth"),l(p,"--token_budget <n>","Alias for --token-budget"),l(p,"--filter-estimate-missing","Alias for --filter-estimates-missing")}async function _e(e,t){let o=y(t),i=Date.now(),a=await te(L(e),o);f(a,o),o.profile&&m(`profile:command=aggregate took_ms=${Date.now()-i}`)}async function Se(e,t){let o=y(t),i=Date.now(),a=z(_("context",e)),n=await X(a,o),r=K(a,o);if(r==="markdown")o.quiet||v(`${W(n)}
4
4
  `);else if(r==="ndjson"){k(n);let d=I([...n.high_level,...n.low_level,...n.blocked_fallback]);!o.quiet&&d.length>0&&v(`${d}
@@ -8,4 +8,4 @@ import{a as de}from"./chunk-2XUDAQK5.js";import"./chunk-DEZPZOQ7.js";import{b as
8
8
  `);return}for await(let a of se({...e,intervalMs:i}))o||v(`${D(a.events,{count:a.count,has_more:a.has_more,next_cursor:a.next_cursor??null,source:a.source,integrity:a.integrity,...a.verified_streams===void 0?{}:{verified_streams:a.verified_streams},heartbeat:a.count===0})}
9
9
  `)}function je(e){return e.cursor_mode==="row"?I(e.events):D(e.events,{count:e.count,has_more:e.has_more,next_cursor:e.next_cursor??null,source:e.source,integrity:e.integrity,...e.verified_streams===void 0?{}:{verified_streams:e.verified_streams},...e.provenance_summary===void 0?{}:{provenance_summary:e.provenance_summary}})}async function Te(e,t){let o=y(t),i=Date.now(),a=Oe(e,o.path);if(e.follow===!0){await Ce(a,e,o.quiet===!0);return}let n=await re(a);if(k(n),o.json){f(n,o),o.profile&&m(`profile:command=events took_ms=${Date.now()-i}`);return}let r=je(n);!o.quiet&&r.length>0&&v(`${r}
10
10
  `),o.profile&&m(`profile:command=events took_ms=${Date.now()-i}`)}async function Re(e,t,o,i,a){let n=y(a),r=Date.now(),d=await Q(e,t,o,{...Array.isArray(i.kind)?{kind:i.kind}:{},maxDepth:typeof i.maxDepth=="string"?i.maxDepth:void 0,limit:typeof i.limit=="string"?i.limit:void 0,after:typeof i.after=="string"?i.after:void 0,direction:typeof i.direction=="string"?i.direction:void 0,maxPaths:typeof i.maxPaths=="string"?i.maxPaths:void 0,sample:typeof i.sample=="string"?i.sample:void 0,...Array.isArray(i.exemptIsolate)?{exemptIsolate:i.exemptIsolate}:{},...Array.isArray(i.exemptIsolateType)?{exemptIsolateType:i.exemptIsolateType}:{},saveBaseline:i.saveBaseline===!0,rebuild:i.rebuild===!0,clear:i.clear===!0,summary:i.summary===!0,full:i.full===!0},n);f(d,n),n.profile&&m(`profile:command=graph took_ms=${Date.now()-r}`)}function At(e,t){let o=t?.commandFilter,i=n=>ye(n,o),a=[{name:"list",description:"List active items with optional lifecycle-status and project filters.",excludeTerminal:!0,allowStatusFilter:!0},{name:"list-all",description:"List all items with optional filters.",excludeTerminal:!1,allowStatusFilter:!0},{name:"list-draft",description:"List draft items with optional filters.",status:"draft"},{name:"list-open",description:"List open items with optional filters.",status:"open",excludeTerminal:!1,allowStatusFilter:!1},{name:"list-in-progress",description:"List in-progress items with optional filters.",status:"in_progress",excludeTerminal:!1,allowStatusFilter:!1},{name:"list-blocked",description:"List blocked items (blocked status or open blocked_by dependencies, matching pm next) with optional filters.",dependencyBlocked:!0,excludeTerminal:!1,allowStatusFilter:!1},{name:"list-closed",description:"List closed items with optional filters.",status:"closed"},{name:"list-canceled",description:"List canceled items with optional filters.",status:"canceled"}];for(let n of a)if(i(n.name)){let r=E(n.name);ke(e,{...n,...r?.registration==="commander"?{aliasContract:r}:{}})}if(i("aggregate")){let n=e.command("aggregate").description("Group item counts and numeric measures.").option("--set-mode <value>","Set grouping: element (default)|tuple").option("--limit <value>","Group page size (default: 50)").option("--after <value>","Continue with next_after cursor").option("--group-by <value>","Fields: parent,type,priority,status,assignee,tags,sprint,release (comma-separated)").option("--count","Counts (default)").option("--completion","Status counts and completion_pct").option("--sum <field>","Group numeric sum").option("--avg <field>","Group numeric average").option("--include-unparented","Keep unparented group").option("--status <value>","Item status").option("--type <value>","Item type").option("--tag <value>","Filter by tag").option("--priority <value>","Filter by priority").option("--deadline-before <value>","Latest deadline (ISO/date or relative)").option("--deadline-after <value>","Earliest deadline (ISO/date or relative)").option("--assignee <value>","Filter by assignee").option("--assignee-filter <value>","Assignee presence: assigned|unassigned").option("--parent <value>","Parent ID").option("--sprint <value>","Filter by sprint").option("--release <value>","Filter by release");l(n,"--include_unparented","Alias for --include-unparented"),l(n,"--assignee_filter <value>","Alias for --assignee-filter"),n.action(_e)}if(i("context")){let n=e.command("context").alias("ctx").description("Show a token-efficient project context snapshot for next-work decisions.").option("--for <intent>",`Apply a declared context intent projection. ${g("context","--for")}`).option("--date <value>","Anchor date/time for agenda window calculations (ISO/date string or relative)").option("--from <value>","Agenda lower bound (ISO/date string or relative)").option("--to <value>","Agenda upper bound (ISO/date string or relative)").option("--past","Include past agenda entries in bounded windows").option("--type <value>","Filter by item type").option("--tag <value>","Filter by tag").option("--priority <value>","Filter by priority").option("--assignee <value>","Filter by assignee").option("--assignee-filter <value>","Filter assignee presence: assigned|unassigned").option("--sprint <value>","Filter by sprint").option("--release <value>","Filter by release").option("--parent <id>","Scope the snapshot to one item's subtree (the item plus all descendants)").option("--limit <n>","Limit focus and agenda rows per section").option("--after <cursor>","Query next_cursor; output_cursor uses --output-cursor").option("--format <value>","Context output format override: markdown|toon|json|ndjson").option("--depth <value>","Context depth: brief|standard|deep|full (full = every section, no per-section cap)").option("--section <value...>","Include specific sections (repeatable; overrides --depth)").option("--fields <value>","Project focus rows to a comma-separated field subset (e.g. id,title,priority)").option("--activity-limit <n>","Limit recent activity entries (default: settings or 10)").option("--stale-threshold <value>","Staleness cutoff in days (e.g. 7 or 7d; default: settings or 7)").option("--explain-ranking","Include the scorer model, per-signal contributions, and ranked candidate ids").option("--token-budget <n>","Complete JSON/TOON response token ceiling").option("--no-extension-health","Omit the installed extension health summary").option("--no-tags","Omit tag arrays from context focus rows");l(n,"--assignee_filter <value>","Alias for --assignee-filter"),l(n,"--max-items <n>","Alias for --limit"),l(n,"--explain_ranking","Alias for --explain-ranking"),l(n,"--token_budget <n>","Alias for --token-budget"),n.action(Se)}if(i("next")){let n=e.command("next").description("Recommend the next actionable (unblocked, ready) work item with rationale + blocked companion.").option("--for <intent>",`Apply a declared context intent projection. ${g("next","--for")}`).option("--type <value>","Filter candidate items by type").option("--tag <value>","Filter candidate items by tag").option("--priority <value>","Filter candidate items by priority").option("--assignee <value>","Filter candidate items by assignee").option("--assignee-filter <value>","Filter assignee presence: assigned|unassigned").option("--sprint <value>","Filter candidate items by sprint").option("--release <value>","Filter candidate items by release").option("--parent <id>","Scope to one item's subtree (the item plus all descendants)").option("--limit <n>","Limit ready rows (default: 5; non-positive falls back to default)").option("--blocked-limit <n>","Limit blocked rows (default: same as --limit)").option("--ready-only","Omit the blocked companion list").option("--include-decisions","Include human-gated Decision items in the claimable ready queue").option("--include-gates","Include outcome gates in the ready queue").option("--include-containers","Include containers with unfinished descendants in the ready queue").option("--format <value>","Next output format override: markdown|toon|json").option("--explain-ranking","Include the scorer model, per-signal contributions, and ranked ready ids").option("--token-budget <n>","Maximum estimated tokens spent on the ranked ready queue");l(n,"--assignee_filter <value>","Alias for --assignee-filter"),l(n,"--blocked_limit <n>","Alias for --blocked-limit"),l(n,"--ready_only","Alias for --ready-only"),l(n,"--explain_ranking","Alias for --explain-ranking"),l(n,"--token_budget <n>","Alias for --token-budget"),n.action(Ie)}if(i("search")){let n=e.command("search").argument("<keywords...>","Keyword query tokens").description("Search items with keyword, semantic, or hybrid retrieval. Inline field:value tokens (tag:/status:/type:/priority:) in the query are parsed as filters, e.g. 'auth tag:area:search status:open'.").option("--for <intent>",`Apply a declared context intent projection. ${g("search","--for")}`).option("--token-budget <n>","Override the selected intent's maximum estimated output tokens").option("--mode <value>","Search mode: keyword|semantic|hybrid (default: auto)").option("--semantic","Shorthand for --mode semantic").option("--hybrid","Shorthand for --mode hybrid").option("--match-mode <value>","Token match mode: and|or|exact (default: or with all-terms ranking bonus; and = hard-require every token; exact = exact phrase)").option("--min-score <value>","Per-query minimum score threshold (finite number >= 0); overrides settings search.score_threshold for this query only").option("--count","Return only the count of matching items (post-filter/threshold, pre-limit); skips hit rows").option("--semantic-weight <value>","Override hybrid semantic weight for this query (0..1); invalid values fall back to settings").option("--include-linked","Include linked files, docs, and tests in the searchable corpus").option("--title-exact","Require exact normalized title match for the full query string").option("--phrase-exact","Require exact normalized phrase match in searchable text").option("--highlight","Emit per-field matched-text snippets (wrapped in \xAB\u2026\xBB) on each hit; off by default").option("--status <value>","Filter by status before query (all, open/closed/canceled aliases, or configured status id; CSV)").option("--type <value>","Filter by item type").option("--tag <value>","Filter by tag").option("--priority <value>","Filter by priority").option("--deadline-before <value>","Filter by deadline upper bound (ISO/date string or relative)").option("--deadline-after <value>","Filter by deadline lower bound (ISO/date string or relative)").option("--updated-after <value>",'Filter by updated_at lower bound: ISO timestamp or signed relative (e.g. "-2h"/"-7d" for the past)').option("--updated-before <value>","Filter by updated_at upper bound: ISO timestamp or signed relative (-2h/+1d)").option("--created-after <value>","Filter by created_at lower bound: ISO timestamp or signed relative (-2h/+1d)").option("--created-before <value>","Filter by created_at upper bound: ISO timestamp or signed relative (-2h/+1d)").option("--assignee <value>","Filter by assignee").option("--sprint <value>","Filter by sprint").option("--release <value>","Filter by release").option("--parent <value>","Filter by parent item ID").option("--compact","Render compact search hits (default; mutually exclusive with --full/--fields)").option("--full","Render full search hits with nested item payloads (mutually exclusive with --compact/--fields)").option("--fields <value>",`Render custom comma-separated search hit fields (mutually exclusive with --compact/--full). ${g("search","--fields")}`).option("--format <value>","Search output format override: json|ndjson|toon").option("--limit <n>","Limit returned item count").option("--after <cursor>","Query next_cursor; output_cursor uses --output-cursor");ue(n),n.action(Ae),l(n,"--tags <value>","Alias for --tag"),l(n,"--token_budget <n>","Alias for --token-budget")}if(i("eval")&&e.command("eval").description("Evaluate search relevance against a curated golden-query set: reports nDCG@k, MRR@k, precision@k, and recall@k per query plus the macro average. Use --fail-under as a CI gate.").option("--mode <value>","Default retrieval mode for queries without their own: keyword|semantic|hybrid (default: keyword)").option("--k <n>","Metric cutoff @k (positive integer; default: 10)").option("--fail-under <value>","Exit non-zero when aggregate nDCG@k falls below this threshold (0..1); CI gate").option("--queries <path>",`Query JSON (${ie}); default: search/eval-queries.json; errors show an example`).option("--format <value>","Eval output format override: json|toon").action(De),i("get")){let n=e.command("get").argument("<id>","Item id").option("--for <intent>",`Apply a declared context intent projection. ${g("get","--for")}`).option("--token-budget <n>","Override the selected intent's maximum estimated output tokens").option("--depth <value>","brief|standard|deep|full (default: standard)").option("--full","Full details and children for any type; excludes --depth/--fields").option("--fields <value>",`Render custom comma-separated item metadata fields. ${g("get","--fields")}`).option("--tree","Include descendants rooted at the requested item").option("--tree-depth <n>","Maximum subtree depth for --tree descendants").option("--at <version-or-timestamp>","Reconstruct a verified historical item state without mutating it").option("--format <value>","Get output format override: json|toon").description("Show item details by ID.").action(Fe);l(n,"--tree_depth <n>","Alias for --tree-depth"),l(n,"--token_budget <n>","Alias for --token-budget")}if(i("history")){let n=e.command("history").enablePositionalOptions().argument("<id>","Item id").option("--limit <n>","Latest n entries").option("--compact","Index, time, op, author, patch count, fields").option("--full","Full entries with JSON Patches").option("--provenance","Authors and provenance; no patches").option("--provenance-summary","Count provenance completeness").option("--harness <value>","Recorded/resolved harness (repeatable)",s).option("--agent-instance <value>","Agent instance (repeatable)",s).option("--provenance-filter <dimension=value>","Exact provenance match (repeatable)",s).option("--diff","Before/after field diffs").option("--field <name>","Filter changed field; implies --diff").option("--verify","Verify full chain and replay").option("--strict-exit","With --verify, fail on integrity errors").option("--fail-on-warn","Alias for --strict-exit").option("--format <value>","Output: json|toon").description("Show item history entries.").action(Ee);de(n,!0),F(n.command("activity"))}i("events")&&e.command("events").option("--since <cursor-or-timestamp>","Resume strictly after a durable cursor, or include events from an ISO timestamp").option("--type <value>","Filter by mutation operation (repeatable or comma-separated)",s).option("--author <value>","Filter by mutation author (repeatable or comma-separated)",s).option("--item <value>","Filter by item or workspace stream id (repeatable or comma-separated)",s).option("--limit <n>","Return at most 1,000 events (default: 100)").option("--cursor-mode <mode>","Cursors: batch trailer (default) or per-row").option("--full","Include each complete authoritative history entry").option("--verify","Verify selected authoritative history chains").option("--provenance","Include patch-free author, harness, instance, and extensible provenance").option("--provenance-summary","Include bounded provenance completeness counts").option("--harness <value>","Filter by recorded or vocabulary-resolved harness (repeatable)",s).option("--agent-instance <value>","Filter by privacy-safe agent instance (repeatable)",s).option("--provenance-filter <dimension=value>","Filter by an exact declared provenance value (repeatable)",s).option("--follow","Follow committed events as NDJSON").option("--interval-ms <n>","Empty-read delay while following (minimum: 10ms; default: 250ms)").description("Read mutation events as NDJSON with resumable cursors.").action(Te),i("activity")&&F(e.command("activity",{hidden:!0})),i("graph")&&e.command("graph").argument("<subcommand>","Graph query (ancestors, descendants, predecessors, successors, paths, impact, analyze, audit, communities, redundancy, dominators, slack, centrality, articulation, plan, index)").argument("[id]","Root item id (traversals, paths, impact, and dominators)").argument("[target]","Target item id (paths only)").option("--kind <value>","Restrict traversal to registered relationship kinds (repeatable or comma-separated)",s).option("--max-depth <value>","Maximum traversal depth (non-negative integer)").option("--limit <value>","Maximum returned rows per bounded collection").option("--after <value>","Resume a traversal after this previously returned node id").option("--direction <value>","Edge orientation for paths/impact (outgoing, incoming, or both)").option("--max-paths <value>","Maximum enumerated paths (paths only)").option("--sample <value>","Maximum evidence sample entries per audit finding (audit only)").option("--exempt-isolate <value>","Item ids treated as explicitly valid isolates by the audit (repeatable or comma-separated)",s).option("--exempt-isolate-type <value>","Item types whose active isolates are policy-valid for the audit (repeatable or comma-separated)",s).option("--save-baseline","Persist the audit census as the change-since-baseline comparison point (audit only)").option("--rebuild","Rebuild and warm the durable graph index (index only)").option("--clear","Delete the durable graph index (index only)").option("--summary","Return counts-first envelopes without row collections").option("--full","Return the complete graph row projection").description("Bounded workspace relationship-graph queries, analytics, and governance audit.").action(Re)}var Dt={resolveReadCommandOutputFormat:S,parseListFormat:ce};export{Dt as _testOnlyRegisterListQuery,At as registerListQueryCommands};
11
- //# sourceMappingURL=register-list-query-YSQ7UTFI.js.map
11
+ //# sourceMappingURL=register-list-query-MHJJUM6M.js.map