@unbrained/pm-cli 2026.8.13 → 2026.8.15

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 (194) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +165 -113
  3. package/dist/cli/commander-usage.js +17 -4
  4. package/dist/cli/error-guidance.d.ts +2 -0
  5. package/dist/cli/error-guidance.js +52 -25
  6. package/dist/cli/main.js +40 -3
  7. package/dist/cli/register-mutation.js +4 -2
  8. package/dist/cli/register-operations.js +5 -5
  9. package/dist/cli-bundle/bundle-manifest.json +146 -178
  10. package/dist/cli-bundle/chunks/{chunk-F7FJYGK3.js → chunk-24GAV7XL.js} +2 -2
  11. package/dist/cli-bundle/chunks/chunk-AIM6VT2N.js +13 -0
  12. package/dist/cli-bundle/chunks/chunk-DSWDLTDR.js +197 -0
  13. package/dist/cli-bundle/chunks/{chunk-Q47C67TQ.js → chunk-J42EGKDK.js} +2 -2
  14. package/dist/cli-bundle/chunks/chunk-KIEGUBYQ.js +2 -0
  15. package/dist/cli-bundle/chunks/{chunk-3ZMOWAFM.js → chunk-KLKYLSDX.js} +2 -2
  16. package/dist/cli-bundle/chunks/{chunk-QGTUPEU5.js → chunk-LJHOAVGI.js} +59 -59
  17. package/dist/cli-bundle/chunks/chunk-MEM2ZS3O.js +5 -0
  18. package/dist/cli-bundle/chunks/chunk-QHPCJWEJ.js +35 -0
  19. package/dist/cli-bundle/chunks/{chunk-YLBAPY22.js → chunk-WLPDLNEZ.js} +2 -2
  20. package/dist/cli-bundle/chunks/{register-list-query-4HIZ7EA3.js → register-list-query-CT3LFDDN.js} +2 -2
  21. package/dist/cli-bundle/chunks/{register-mutation-W64FZ5HN.js → register-mutation-NWEVA5YS.js} +3 -3
  22. package/dist/cli-bundle/chunks/register-operations-AHIAG5KM.js +2 -0
  23. package/dist/cli-bundle/chunks/{register-setup-634MFRXU.js → register-setup-ZJZFVAKE.js} +2 -2
  24. package/dist/cli-bundle/focused-chunks/chunk-4X57RE4U.js +2 -0
  25. package/dist/cli-bundle/focused-chunks/chunk-6XKF3PGV.js +18 -0
  26. package/dist/cli-bundle/focused-chunks/chunk-7NJ4QYQ2.js +2 -0
  27. package/dist/cli-bundle/focused-chunks/{chunk-I75MANL7.js → chunk-EXZA4257.js} +2 -2
  28. package/dist/cli-bundle/focused-chunks/chunk-ITAUHSO6.js +50 -0
  29. package/dist/cli-bundle/focused-chunks/{chunk-OOYYKQWX.js → chunk-KLVUMNXJ.js} +2 -2
  30. package/dist/cli-bundle/focused-chunks/{chunk-2RI2FESN.js → chunk-KT5XMYSX.js} +2 -2
  31. package/dist/cli-bundle/focused-chunks/{chunk-E3AVJ655.js → chunk-KTKH4IMG.js} +2 -2
  32. package/dist/cli-bundle/focused-chunks/chunk-M67F5AIN.js +8 -0
  33. package/dist/cli-bundle/focused-chunks/{chunk-3DJSGWVB.js → chunk-NSPYTG6G.js} +2 -2
  34. package/dist/cli-bundle/focused-chunks/chunk-OKA6ELTL.js +2 -0
  35. package/dist/cli-bundle/focused-chunks/chunk-PUISBOPP.js +2 -0
  36. package/dist/cli-bundle/focused-chunks/chunk-QLNMCESQ.js +155 -0
  37. package/dist/cli-bundle/focused-chunks/{chunk-IIS2FRKL.js → chunk-SLKC6QLJ.js} +2 -2
  38. package/dist/cli-bundle/focused-chunks/chunk-U65UC4G3.js +2 -0
  39. package/dist/cli-bundle/focused-chunks/chunk-WTSER4WJ.js +16 -0
  40. package/dist/cli-bundle/focused-chunks/{chunk-2JP7W7GO.js → chunk-ZMFXQ7VF.js} +2 -2
  41. package/dist/cli-bundle/main.js +13 -13
  42. package/dist/cli-bundle/sdk-authoring.js +1 -1
  43. package/dist/cli-bundle/sdk-contracts.js +1 -1
  44. package/dist/cli-bundle/sdk-core.js +41 -41
  45. package/dist/cli-bundle/sdk-governance.js +1 -1
  46. package/dist/cli-bundle/sdk-graph.js +1 -1
  47. package/dist/cli-bundle/sdk-merge.js +110 -1
  48. package/dist/cli-bundle/sdk-query.js +1 -1
  49. package/dist/cli-bundle/sdk-runtime.js +1 -1
  50. package/dist/cli-bundle/sdk-testing.js +1 -1
  51. package/dist/cli-bundle/sdk.js +2 -2
  52. package/dist/core/diagnostics/remediation.js +7 -2
  53. package/dist/core/extensions/reserved-host-flags.js +3 -2
  54. package/dist/core/history/drift-scan.d.ts +6 -0
  55. package/dist/core/history/drift-scan.js +74 -50
  56. package/dist/core/history/replay.d.ts +14 -1
  57. package/dist/core/history/replay.js +45 -8
  58. package/dist/core/history/workspace-history.d.ts +59 -0
  59. package/dist/core/history/workspace-history.js +197 -10
  60. package/dist/core/output/output.d.ts +2 -0
  61. package/dist/core/output/output.js +13 -4
  62. package/dist/core/shared/command-types.d.ts +2 -0
  63. package/dist/core/shared/command-types.js +2 -2
  64. package/dist/core/shared/errors.d.ts +12 -0
  65. package/dist/core/shared/errors.js +2 -2
  66. package/dist/mcp/tool-definitions.js +9 -5
  67. package/dist/sdk/agent/refusal-reachability.d.ts +61 -0
  68. package/dist/sdk/agent/refusal-reachability.js +91 -3
  69. package/dist/sdk/cli-bootstrap.d.ts +2 -0
  70. package/dist/sdk/cli-bootstrap.js +7 -2
  71. package/dist/sdk/cli-contracts/completeness.js +3 -2
  72. package/dist/sdk/cli-contracts/flag-contracts.js +3 -2
  73. package/dist/sdk/cli-contracts/registration-helpers.js +3 -2
  74. package/dist/sdk/cli-contracts/runtime-contracts.d.ts +11 -1
  75. package/dist/sdk/cli-contracts/runtime-contracts.js +176 -65
  76. package/dist/sdk/cli-contracts/tool-parameter-tables.js +15 -5
  77. package/dist/sdk/cli-contracts/tool-schema.js +10 -3
  78. package/dist/sdk/cli-program.js +4 -3
  79. package/dist/sdk/context-relevance.js +12 -4
  80. package/dist/sdk/core.d.ts +2 -2
  81. package/dist/sdk/core.js +3 -3
  82. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +26 -2
  83. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +50 -26
  84. package/dist/sdk/governance/assurance-action.d.ts +7 -1
  85. package/dist/sdk/governance/assurance-action.js +7 -6
  86. package/dist/sdk/governance/assurance-mutation-error.d.ts +42 -1
  87. package/dist/sdk/governance/assurance-mutation-error.js +27 -3
  88. package/dist/sdk/governance/assurance-runtime.js +12 -11
  89. package/dist/sdk/governance/assurance.d.ts +9 -0
  90. package/dist/sdk/governance/assurance.js +82 -16
  91. package/dist/sdk/governance/extension-host-version.d.ts +25 -0
  92. package/dist/sdk/governance/extension-host-version.js +105 -0
  93. package/dist/sdk/governance/health.d.ts +32 -1
  94. package/dist/sdk/governance/health.js +132 -28
  95. package/dist/sdk/governance/provenance-health.d.ts +27 -0
  96. package/dist/sdk/governance/provenance-health.js +95 -3
  97. package/dist/sdk/governance/validate-history-drift.d.ts +7 -0
  98. package/dist/sdk/governance/validate-history-drift.js +68 -0
  99. package/dist/sdk/governance/validate.js +9 -52
  100. package/dist/sdk/governance.d.ts +6 -0
  101. package/dist/sdk/governance.js +8 -2
  102. package/dist/sdk/graph/assembly.d.ts +23 -0
  103. package/dist/sdk/graph/assembly.js +54 -2
  104. package/dist/sdk/graph/durable-cache.js +50 -20
  105. package/dist/sdk/graph/governance-contracts.d.ts +1 -1
  106. package/dist/sdk/graph/governance-contracts.js +4 -2
  107. package/dist/sdk/graph/governance.d.ts +21 -1
  108. package/dist/sdk/graph/governance.js +94 -32
  109. package/dist/sdk/graph/index.d.ts +2 -2
  110. package/dist/sdk/graph/index.js +4 -4
  111. package/dist/sdk/graph/mutation-advisory.js +15 -7
  112. package/dist/sdk/graph/remediation.js +12 -2
  113. package/dist/sdk/history-read.d.ts +8 -0
  114. package/dist/sdk/history-read.js +2 -2
  115. package/dist/sdk/history-repair.d.ts +13 -1
  116. package/dist/sdk/history-repair.js +62 -18
  117. package/dist/sdk/index.d.ts +1 -1
  118. package/dist/sdk/index.js +3 -3
  119. package/dist/sdk/linked-artifacts.js +16 -5
  120. package/dist/sdk/pagination.d.ts +15 -0
  121. package/dist/sdk/pagination.js +9 -5
  122. package/dist/sdk/query/context.d.ts +5 -1
  123. package/dist/sdk/query/context.js +14 -5
  124. package/dist/sdk/query/history.js +20 -3
  125. package/dist/sdk/read-output/continuation.d.ts +11 -0
  126. package/dist/sdk/read-output/continuation.js +132 -0
  127. package/dist/sdk/read-output-budget.d.ts +3 -1
  128. package/dist/sdk/read-output-budget.js +24 -13
  129. package/dist/sdk/read-output-contracts.d.ts +127 -7
  130. package/dist/sdk/read-output-contracts.js +381 -35
  131. package/dist/sdk/read-output-rows.d.ts +13 -0
  132. package/dist/sdk/read-output-rows.js +60 -2
  133. package/dist/sdk/runtime-input.js +4 -2
  134. package/dist/sdk/runtime-primitives.d.ts +1 -1
  135. package/dist/sdk/runtime-primitives.js +3 -3
  136. package/dist/sdk/runtime.js +5 -3
  137. package/docs/ASSURANCE.md +68 -2
  138. package/docs/COMMANDS.md +39 -4
  139. package/docs/READ_OUTPUT_CONTRACTS.md +85 -8
  140. package/docs/RELATIONSHIP_GRAPH.md +20 -5
  141. package/docs/RELEASING.md +42 -5
  142. package/docs/SDK.md +12 -5
  143. package/docs/SDK_CONTEXT_INTEGRITY.md +94 -1
  144. package/docs/TESTING.md +23 -1
  145. package/docs/performance/sdk-entrypoint-import-costs.md +20 -13
  146. package/marketplace.json +2 -2
  147. package/package.json +7 -7
  148. package/packages/pm-beads/extensions/beads/index.ts +1 -0
  149. package/packages/pm-beads/package.json +1 -1
  150. package/packages/pm-calendar/extensions/calendar/index.ts +1 -0
  151. package/packages/pm-calendar/package.json +1 -1
  152. package/packages/pm-command-kit/package.json +1 -1
  153. package/packages/pm-digital-twin/extensions/digital-twin/index.ts +7 -0
  154. package/packages/pm-digital-twin/package.json +1 -1
  155. package/packages/pm-governance-audit/extensions/governance-audit/index.ts +4 -0
  156. package/packages/pm-governance-audit/package.json +1 -1
  157. package/packages/pm-guide-shell/extensions/guide-shell/index.ts +5 -0
  158. package/packages/pm-guide-shell/package.json +1 -1
  159. package/packages/pm-kanban/package.json +1 -1
  160. package/packages/pm-lifecycle-hooks/package.json +1 -1
  161. package/packages/pm-linked-test-adapters/extensions/linked-test-adapters/index.ts +6 -0
  162. package/packages/pm-linked-test-adapters/package.json +1 -1
  163. package/packages/pm-search-advanced/extensions/search-advanced/index.ts +2 -0
  164. package/packages/pm-search-advanced/package.json +1 -1
  165. package/packages/pm-templates/extensions/templates/index.ts +4 -0
  166. package/packages/pm-templates/package.json +1 -1
  167. package/packages/pm-todos/extensions/todos/index.ts +2 -0
  168. package/packages/pm-todos/package.json +1 -1
  169. package/packages/pm-vcs/extensions/vcs/index.ts +7 -0
  170. package/packages/pm-vcs/package.json +1 -1
  171. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  172. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  173. package/scripts/bundle-cli.mjs +17 -4
  174. package/sdk/public-surface.json +1283 -157
  175. package/dist/cli-bundle/chunks/chunk-DEDU3DG7.js +0 -196
  176. package/dist/cli-bundle/chunks/chunk-DL5M5J3V.js +0 -13
  177. package/dist/cli-bundle/chunks/chunk-HIUZVCMN.js +0 -5
  178. package/dist/cli-bundle/chunks/chunk-IMGIN7R6.js +0 -2
  179. package/dist/cli-bundle/chunks/chunk-TF3TPKPR.js +0 -34
  180. package/dist/cli-bundle/chunks/register-operations-C44ET7R5.js +0 -2
  181. package/dist/cli-bundle/focused-chunks/chunk-27N23W6M.js +0 -31
  182. package/dist/cli-bundle/focused-chunks/chunk-3BNVU6LC.js +0 -8
  183. package/dist/cli-bundle/focused-chunks/chunk-6MLIRBLV.js +0 -5
  184. package/dist/cli-bundle/focused-chunks/chunk-6XYLENDV.js +0 -155
  185. package/dist/cli-bundle/focused-chunks/chunk-CP4K4WFS.js +0 -2
  186. package/dist/cli-bundle/focused-chunks/chunk-EBTNSFYE.js +0 -2
  187. package/dist/cli-bundle/focused-chunks/chunk-HC2OL2H2.js +0 -2
  188. package/dist/cli-bundle/focused-chunks/chunk-NFHFZH2Z.js +0 -2
  189. package/dist/cli-bundle/focused-chunks/chunk-OGC4XSBC.js +0 -17
  190. package/dist/cli-bundle/focused-chunks/chunk-PKPOZXLL.js +0 -2
  191. package/dist/cli-bundle/focused-chunks/chunk-QDZUABWL.js +0 -2
  192. package/dist/cli-bundle/focused-chunks/chunk-QQX5TDFT.js +0 -16
  193. package/dist/cli-bundle/focused-chunks/chunk-TEZIXMTH.js +0 -2
  194. package/dist/cli-bundle/focused-chunks/chunk-WEH6NSL6.js +0 -18
@@ -1,18 +0,0 @@
1
- import{$ as gt,Ea as yt,Ka as Et,V as D,Xa as ee,Ya as W,Za as te,_ as ht,cb as re,ia as ve,l as Ce,na as Le,nb as ke,o as Z,oa as Re,ob as Me,qa as De}from"./chunk-6XYLENDV.js";import{F as Te,N as Se,O as xe,P as Ie,Q as pt,U as g,W as B,X as F,Y as b,_ as _t,a as we,p as $,r as Y,s as S,t as T,v as X}from"./chunk-2RI2FESN.js";import{R as be,Y as f,Z as p,ba as Ae}from"./chunk-CP4K4WFS.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]="b9581c92-5e8a-589d-9681-d4d014e6902b")}catch{}})();function Ur(e,t="--limit"){if(e===void 0)return;let r=Number(e);if(!Number.isFinite(r)||r<0)throw new p(`${t} must be a non-negative number`,f.USAGE);return Math.floor(r)}(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]="7775a1f2-5167-5853-a2c5-a44d46f8e80e")}catch{}})();var Vr=/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/,jr=/\bnpm_[A-Za-z0-9]{36}\b/,qr=/\bxox[baprs]-(?=[A-Za-z0-9-]{20,80}\b)(?=[A-Za-z0-9-]*\d)[A-Za-z0-9-]{20,80}\b/,Hr=/-----BEGIN (?:[A-Z0-9]+ )?PRIVATE KEY-----/,Yr=/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/,wt=/\b(?:token|secret|password|passwd|api[_-]?key)\s*[:=]\s*["']?([A-Za-z0-9+/=_-]{24,})/gi,Br=[{action:"append",history_scope:"item"},{action:"claim",history_scope:"item"},{action:"close",history_scope:"item"},{action:"close-many",history_scope:"item"},{action:"close-task",history_scope:"item"},{action:"comments",history_scope:"conditional"},{action:"config",history_scope:"conditional"},{action:"copy",history_scope:"item"},{action:"create",history_scope:"item"},{action:"delete",history_scope:"item"},{action:"deps",history_scope:"conditional"},{action:"discover",history_scope:"item"},{action:"docs",history_scope:"conditional"},{action:"files",history_scope:"conditional"},{action:"focus",history_scope:"conditional"},{action:"gc",history_scope:"conditional"},{action:"history-compact",history_scope:"history"},{action:"history-author-acknowledge",history_scope:"workspace"},{action:"history-redact",history_scope:"history"},{action:"history-repair",history_scope:"history"},{action:"init",history_scope:"workspace"},{action:"install",history_scope:"conditional"},{action:"learnings",history_scope:"conditional"},{action:"notes",history_scope:"conditional"},{action:"package",history_scope:"conditional"},{action:"pause-task",history_scope:"item"},{action:"plan",history_scope:"conditional"},{action:"profile",history_scope:"conditional"},{action:"release",history_scope:"item"},{action:"restore",history_scope:"item"},{action:"schema",history_scope:"conditional"},{action:"start-task",history_scope:"item"},{action:"templates",history_scope:"conditional"},{action:"test",history_scope:"conditional"},{action:"test-all",history_scope:"conditional"},{action:"update",history_scope:"item"},{action:"update-many",history_scope:"item"},{action:"upgrade",history_scope:"conditional"}],Oe=new Map(Br.map(e=>[e.action,e]));function Wr(e){let t=new Map;for(let n of e)t.set(n,(t.get(n)??0)+1);let r=0;for(let n of t.values()){let o=n/e.length;r-=o*Math.log2(o)}return r}function Ne(e,t="$",r=new WeakSet){return typeof e=="string"?[{path:t,value:e}]:typeof e!="object"||e===null?[]:r.has(e)?[]:(r.add(e),Array.isArray(e)?e.flatMap((n,o)=>Ne(n,`${t}[${o}]`,r)):Object.entries(e).flatMap(([n,o])=>Ne(o,`${t}.${n}`,r)))}function bt(e){let t=[];for(let r of Ne(e)){Vr.test(r.value)&&t.push({rule:"github_token",path:r.path}),jr.test(r.value)&&t.push({rule:"npm_token",path:r.path}),qr.test(r.value)&&t.push({rule:"slack_token",path:r.path}),Hr.test(r.value)&&t.push({rule:"private_key",path:r.path}),Yr.test(r.value)&&t.push({rule:"aws_access_key",path:r.path}),wt.lastIndex=0;for(let n of r.value.matchAll(wt)){let o=n[1];if(Wr(o)>=3.5){t.push({rule:"high_entropy_assignment",path:r.path});break}}}return t.filter((r,n,o)=>o.findIndex(i=>i.rule===r.rule&&i.path===r.path)===n)}function Gr(e){let t=e.author.trim()||"unknown";if(e.settings.require_attributed_author&&t.toLowerCase()==="unknown")throw new p("Mutation author is required by workspace policy.",f.USAGE,{code:"mutation_author_required",required:"Pass --author <id>, set PM_AUTHOR, or configure author_default.",nextSteps:["Retry with --author <stable-agent-id>.","Set PM_AUTHOR for this agent session."]});if(e.settings.secret_guard==="off")return{author:t,findings:[],warnings:[],override_applied:!1};let r;try{r=bt(e.payload)}catch{return{author:t,findings:[],warnings:["secret_guard_scan_failed_open"],override_applied:!1}}if(r.length===0)return{author:t,findings:r,warnings:[],override_applied:!1};let n=[...new Set(r.map(o=>o.rule))].sort().join(",");if(e.settings.secret_guard==="block"&&e.force!==!0)throw new p(`Mutation blocked by secret guard (${n}). No detected value was logged.`,f.CONFLICT,{code:"mutation_secret_guard_blocked",required:"Remove the credential-shaped content or retry with --force after explicit review.",nextSteps:["Replace the value with a secret-manager reference.","Use pm history-redact if equivalent content already entered history."],recovery:{recovery_mode:"compact",attempted_command:"pm <mutation> [REDACTED]",normalized_args:["[REDACTED]"],suggested_retry:"Remove credential-shaped content, then retry the mutation."}});return{author:t,findings:r,warnings:[`secret_guard_detected:${r.length}:rules=${n}`,...e.settings.secret_guard==="block"&&e.force===!0?["secret_guard_force_override"]:[]],override_applied:e.settings.secret_guard==="block"&&e.force===!0}}function Kr(e){return Oe.has(e.trim().toLowerCase())}function Qr(){return[...Oe.keys()].sort((e,t)=>e.localeCompare(t))}function Hs(e){return Oe.get(e.trim().toLowerCase())}(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]="3ad30a32-0f83-5473-b0a3-349e271d8378")}catch{}})();function Jr(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function Bs(e){return Jr(e).split(/[^a-z0-9]+/).filter(t=>t.length>0)}function ne(e,t){if(e.length===0&&t.length===0)return 1;if(e.length===0||t.length===0)return 0;let r=new Set(e),n=new Set(t),o=0;for(let s of r)n.has(s)&&(o+=1);let i=new Set([...r,...n]).size;return o/i}(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]="dff9b113-2b29-5154-afbf-f191f2f556a6")}catch{}})();var Xr=/\b[a-z][a-z0-9]*-\d+(?:-[a-z0-9]+)*\b/giu;function Pe(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function St(e){return[...new Set(Pe(e).match(/[\p{L}\p{N}]+/gu)??[])]}function Tt(e){let t=Pe(e);return{normalized:t,tokens:St(t),issueCodes:[...new Set(t.match(Xr)?.map(r=>r.toLowerCase())??[])]}}function Zr(e,t){return en(Tt(e),Tt(t))}function en(e,t){if(e.normalized===t.normalized)return{score:1,reason:"exact_title"};let r=new Set(e.issueCodes);return t.issueCodes.some(n=>r.has(n))?{score:.99,reason:"issue_code"}:{score:ne(e.tokens,t.tokens),reason:"title_token_jaccard"}}import tn 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]="376bb9d2-e202-57e7-86c8-d70a7d3fa7ab")}catch{}})();function oe(e){return(e??"in_progress").trim().toLowerCase().replaceAll("-","_")}function rn(e,t){return[e.updated_at,t].map(n=>({value:n,time:Date.parse(n??"")})).filter(n=>typeof n.value=="string"&&Number.isFinite(n.time)).sort((n,o)=>o.time-n.time)[0]?.value??e.updated_at}function xt(e,t){let r=Math.max(1,Math.trunc(t.threshold_hours)),n=(t.now??new Date).getTime(),o=oe(t.in_progress_status),i=[];for(let s of e){if(oe(String(s.status))!==o||(s.assignee?.trim().length??0)>0)continue;let a=rn(s,t.last_history_activity?.(s)),c=Date.parse(a);if(!Number.isFinite(c))continue;let d=Math.max(0,Math.floor((n-c)/36e5));d>=r&&i.push({id:s.id,last_activity_at:a,age_hours:d})}return i.sort((s,a)=>a.age_hours-s.age_hours||s.id.localeCompare(a.id)),{threshold_hours:r,count:i.length,items:i,remediation:"Claim active work with `pm claim <id>` or return abandoned work to open with `pm update <id> --status open`."}}async function nn(e,t,r){let n=new Map;return await Promise.all(t.filter(o=>oe(String(o.status))===oe(r.in_progress_status)&&(o.assignee?.trim().length??0)===0).map(async o=>{let i;try{i=await De(tn.join(e,"history",`${o.id}.jsonl`),o.id)}catch{return}let s=i.map(a=>a.ts).filter(a=>Number.isFinite(Date.parse(a))).sort((a,c)=>Date.parse(c)-Date.parse(a))[0];s&&n.set(o.id,s)})),xt(t,{...r,last_history_activity:o=>n.get(o.id)})}import{mkdir as on,readFile as sn}from"node:fs/promises";import It 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]="71a8cd89-54fc-5f8a-b93b-9e4a79bb34b6")}catch{}})();function an(e){let t=e.trim();if(!t)throw new p("--rollback requires a non-empty checkpoint ID",f.USAGE);if(!/^[a-zA-Z0-9._-]+$/.test(t))throw new p("--rollback checkpoint ID must match [a-zA-Z0-9._-]+",f.USAGE);return t}function cn(e,t){let r=t.replace(/[-:.TZ]/g,"").slice(0,14),n=Math.random().toString(36).slice(2,8);return`${e}-${r}-${n}`}function At(e,t){return It.join(e,"checkpoints",t)}function Ct(e,t,r){return It.join(At(e,t),`${r}.json`)}async function dn(e,t,r,n){let o=At(e,t);await on(o,{recursive:!0});let i=Ct(e,t,r);return await T(i,`${JSON.stringify(n,null,2)}
2
- `),i}function un(e,t){if(!Array.isArray(e.items))throw new p(`Checkpoint ${t} is missing items`,f.GENERIC_FAILURE);return e.items.map(r=>{if(!r||typeof r!="object")throw new p(`Checkpoint ${t} contains an invalid item entry`,f.GENERIC_FAILURE);let n=r;if(typeof n.id!="string"||n.id.trim().length===0)throw new p(`Checkpoint ${t} contains an item entry without ID`,f.GENERIC_FAILURE);if(typeof n.target_updated_at!="string"||n.target_updated_at.trim().length===0)throw new p(`Checkpoint ${t} contains an item entry without target_updated_at`,f.GENERIC_FAILURE);return{id:n.id.trim(),target_updated_at:n.target_updated_at.trim()}})}async function ln(e,t,r,n){let o=an(r),i=Ct(e,t,o);if(!await $(i))throw new p(`Checkpoint ${o} not found`,f.NOT_FOUND);let s=await sn(i,"utf8"),a;try{a=JSON.parse(s)}catch(u){throw new p(`Checkpoint ${o} contains invalid JSON: ${b(u)}`,f.GENERIC_FAILURE)}if(!a||typeof a!="object")throw new p(`Checkpoint ${o} is invalid`,f.GENERIC_FAILURE);let c=a;if(c.schema_version!==n)throw new p(`Checkpoint ${o} has unsupported schema version`,f.GENERIC_FAILURE);let d=un(c,o);return{record:c,items:d,path:i,id:typeof c.id=="string"?c.id:o,created_at:typeof c.created_at=="string"?c.created_at:D(),author:typeof c.author=="string"?c.author:"unknown"}}async function fn(e,t){let r=[],n=[];for(let o of e)try{let i=await t(o.id,o.target_updated_at);r.push({id:o.id,status:"restored",changed_fields:i.changed_fields,warnings:i.warnings}),n.push(o.id)}catch(i){r.push({id:o.id,status:"failed",error:b(i)})}return{rows:r,restored_ids:n,failed_count:r.filter(o=>o.status==="failed").length}}(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]="ab276268-7a98-5f97-b3f5-300dfd1b5ed5")}catch{}})();function k(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return t.length>0?t:null}function ca(e,t){let r=k(t);return!e||!r?null:[...e.assurance_providers??[]].reverse().find(n=>k(n.definition.id)===r)??null}function mn(e,t){let r=k(t);return!e||!r?null:[...e.search_providers].reverse().find(o=>(k(o.runtime_definition?.name)??k(o.definition?.name))===r)??null}function pn(e,t){let r=k(t);return!e||!r?null:[...e.vector_store_adapters].reverse().find(o=>(k(o.runtime_definition?.name)??k(o.definition?.name))===r)??null}(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]="19ff592c-0746-54e8-a304-2006f4845da2")}catch{}})();function vt(e){return e.replaceAll("~1","/").replaceAll("~0","~")}function ze(e){if(e==="/body"||e.startsWith("/body/"))return"body";if(e==="/metadata"||e.startsWith("/metadata/")||e==="/front_matter"||e.startsWith("/front_matter/")){let r=e.replace(/^\/(?:metadata|front_matter)\/?/,"").split("/")[0];return r?vt(r):"metadata"}let t=e.replace(/^\//,"").split("/")[0];return t?vt(t):"root"}function ie(e,t){return t==="body"?e.body:t==="metadata"?e.metadata:t==="root"?e:e.metadata[t]}function _n(e,t){let r=t?.windowStartIndex??0,n=t?.field;if(e.length===0||r>=e.length)return[];let o=yt(),i=[];for(let s=0;s<e.length;s+=1){let a=e[s],c=o,d=Et(o,a.patch),u;d.ok?(u=d.document,o=u):u=c;let m=new Set;for(let l of a.patch)m.add(ze(l.path)),l.from!==void 0&&m.add(ze(l.from));let _=[...m].sort((l,h)=>l.localeCompare(h));if(s>=r)if(n!==void 0){if(!m.has(n))continue;let l={field:n,before:ie(c,n),after:ie(u,n)};i.push({index:s+1,ts:a.ts,op:a.op,author:a.author,patch_ops:a.patch.length,changed_fields:[n],changes:[l]})}else{let l=_.map(h=>({field:h,before:ie(c,h),after:ie(u,h)}));i.push({index:s+1,ts:a.ts,op:a.op,author:a.author,patch_ops:a.patch.length,changed_fields:_,changes:l})}}return i}(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]="7426082f-94a6-5b4e-9748-d3faab2fe1d4")}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]="4a376062-2e23-5991-80a5-27183909caf3")}catch{}})();var hn=new Set(["none","null","undefined"]);function ya(e){let t=e?.trim().toLowerCase().replaceAll("-","_");if(t==="warn"||t==="strict_error")return t;if(t==="strict")return"strict_error";throw new p("Config set parent-reference-policy requires --policy with one of: warn, strict_error (alias: strict)",f.USAGE)}function gn(e){if(typeof e!="string")throw new p("--parent must be a string. Use --unset parent to clear this field.",f.USAGE);let t=e.trim();if(t.length===0)throw new p("--parent must not be empty. Use --parent none to unset.",f.USAGE);if(Lt(t))throw new p(`--parent must not use placeholder token "${t}". Use --unset parent to clear this field.`,f.USAGE);return t}function Lt(e){return hn.has(e.trim().toLowerCase())}function yn(e,t){if(t==="strict_error")throw new p(`Parent item "${e}" was not found. Create it first or use --parent none.`,f.USAGE);return{warnings:[`validation_warning:parent_reference_missing:${e}`]}}function En(e,t,r){let n=re(e,r),o=re(t,r);if(n!==o)return;let i=t!==o||e!==n?` (normalized from parent "${t}" and item "${e}")`:"";throw new p(`Parent item "${o}" cannot be the same as item "${n}"${i}. Use --unset parent to clear this field.`,f.USAGE)}(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]="d5003dd5-f208-5734-9711-dff935d8c851")}catch{}})();var U="-",Rt=new Set(["actual_result","body","cmd","command","customer_impact","description","environment","expected_result","impact","location","message","note","outcome","repro_steps","resolution","text","title","unblock_note","value","why_now"]);function Dt(e){let t=e.trim();if(t==="")return[];let n=(xn(t)??t.split(",")).map(o=>o.trim()).filter(Boolean).map(o=>o.toLowerCase());return Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i))}function kt(e){if(!Array.isArray(e)||e.length===0)return[];let t=[];for(let r of e)if(typeof r=="string")for(let n of Dt(r))t.push(n);return Array.from(new Set(t)).sort((r,n)=>r.localeCompare(n))}function Mt(e){return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim().toLowerCase()).filter(Boolean):[]}function wn(e){return typeof e!="string"?[]:e.split(";").map(t=>t.trim()).filter(Boolean)}function bn(e,t,r){let n=e.map(s=>s.trim()).filter(Boolean);for(let s of t??[]){let a=s.trim();if(a.includes(";"))throw new p('Acceptance criteria added with --add-ac cannot contain ";" because semicolons delimit stored criteria',f.USAGE,{code:"acceptance_criteria_semicolon_forbidden",required:"Pass one semicolon-free criterion per --add-ac value",why:"A semicolon inside one criterion would be re-read as multiple criteria",nextSteps:["Split the text into repeated --add-ac values, or replace the semicolon with punctuation that is not the storage delimiter"]});a.length>0&&!n.includes(a)&&n.push(a)}let o=[],i=n;for(let s of r??[]){let a=s.trim();if(a.length!==0){if(!i.includes(a)){o.push(a);continue}i=i.filter(c=>c!==a)}}return{criteria:i,unmatchedRemovals:o}}function Tn(e,t){let r=Mt(e);if(!t||t.length===0)return Array.from(new Set(r)).sort((o,i)=>o.localeCompare(i));let n=new Set(r);for(let o of kt(t))n.add(o);return Array.from(n).sort((o,i)=>o.localeCompare(i))}function Sn(e,t){let r=Array.from(new Set(Mt(e))).sort((o,i)=>o.localeCompare(i));if(!t||t.length===0)return r;let n=new Set(kt(t));return n.size===0?r:r.filter(o=>!n.has(o))}function xn(e){if(!e.startsWith("["))return null;let t;try{t=JSON.parse(e)}catch{return null}return t.map(n=>typeof n=="string"||typeof n=="number"||typeof n=="boolean"?String(n):"").filter(n=>n.length>0)}function $e(e){return e.replace(/\r\n/g,`
3
- `)}function Nt(e){let t=$e(e).trim();if(!t.startsWith("```"))return e;let r=t.split(`
4
- `);return r.length<2||r.at(-1)?.trim()!=="```"?e:r.slice(1,-1).join(`
5
- `)}function In(e){let t=[],r="",n=!1,o=!1;for(let i of e){if(o){r+=i,o=!1;continue}if(i==="\\"){r+=i,o=!0;continue}if(i==='"'){n=!n,r+=i;continue}if(i===","&&!n){t.push(r.trim()),r="";continue}r+=i}return r.trim()&&t.push(r.trim()),t}function Ot(e){let t=e.trim();if(t.startsWith('"')&&t.endsWith('"')){try{let r=JSON.parse(t);if(typeof r=="string")return r}catch{}return t.slice(1,-1).replace(/\\"/g,'"')}return e}function An(e){let t=e.indexOf("="),r=e.indexOf(":"),n=t>0,o=r>0;return n&&o?Math.min(t,r):n?t:o?r:-1}function Cn(e,t){if((t==="--add"||t==="--add-glob")&&(/[./\\]/.test(e)||/\.[a-z]{1,6}$/i.test(e.trim())))return"For file/doc paths use: path=<file-path>[,scope=project|global]. The scope field is optional and defaults to project (example: path=src/api.ts or path=README.md,scope=project). ";if(t!=="--event")return"";let r=e.toLowerCase(),n=r.includes("recur_")||r.includes("recurrence")?' Recurrence list values must stay in one field and use "|" delimiters (for example recur_by_weekday=mon|wed or recur_by_month_day=1|15).':"",o=r.includes("recur_byweekday")?" Use recur_by_weekday (with underscores) for weekday recurrence filters.":"";return`${n}${o}`}function vn(e,t){let r=e.replaceAll(/\s+/g," ").trim(),n=r.length>160?`${r.slice(0,157)}...`:r,o=Cn(e,t);return`Invalid ${t} value "${n}". Expected key=value entries separated by commas. `+o+`Also accepts markdown-style key/value lines (for example "- path: README.md"). Use ${t} ${U} to read piped stdin input.`}function Ln(e){let t=Nt(e).trim();if(t.length===0||!t.includes(`
6
- `)&&!t.startsWith("-")&&!t.startsWith("*")&&!t.startsWith("+"))return null;let r={},n,o=$e(t).split(`
7
- `).map(i=>i.trim()).filter(i=>i.length>0);for(let i of o){let s=i.match(/^(?:[-*+]\s+)?([a-zA-Z0-9_.-]+)\s*(=|:)\s*(.*)$/);if(s){let a=s[1].trim();r[a]=Ot(s[3].trim()),n=a;continue}if(n&&Rt.has(n.toLowerCase())){r[n]=`${r[n]}
8
- ${i}`;continue}return null}return r}function Rn(e,t){let r=Nt(e).trim();if(!r)throw new p(`${t} cannot be empty`,f.USAGE);let n=Ln(r);if(n)return n;let o={},i,s=In(r);for(let a of s){let c=An(a);if(c>0){let d=a.slice(0,c).trim(),u=Ot(a.slice(c+1).trim());o[d]=u,i=d;continue}if(i&&Rt.has(i.toLowerCase())){o[i]=`${o[i]},${a.trim()}`;continue}throw new p(vn(e,t),f.USAGE)}return o}var Dn=/^[A-Za-z]:[\\/]/,kn=/^(?:[-*+]\s+)?[A-Za-z_][A-Za-z0-9_.-]*\s*=/;function Mn(e){let t=e.trim();return Dn.test(t)?!1:kn.test(t)}function Nn(e,t,r){let n=new Set(r.map(i=>i.toLowerCase())),o=Object.keys(e).filter(i=>!n.has(i.toLowerCase()));if(o.length>0)throw new p(`${t} does not recognize key${o.length>1?"s":""} ${o.map(i=>`"${i}"`).join(", ")}. Allowed keys: ${r.join(", ")}.`,f.USAGE);for(let i of Object.keys(e)){let s=i.toLowerCase();if(s!==i){if(Object.hasOwn(e,s))throw new p(`${t} provides key "${i}" more than once after case normalization.`,f.USAGE);e[s]=e[i],delete e[i]}}}async function On(e){if(process.stdin.isTTY===!0)throw new p(`${e} value "${U}" requires piped stdin input. Pipe content into the command, or end manual stdin with Ctrl+D (Unix/macOS) or Ctrl+Z then Enter (Windows).`,f.USAGE);return process.stdin.setEncoding("utf8"),await new Promise((t,r)=>{let n="";process.stdin.on("data",o=>{n+=o}),process.stdin.on("end",()=>{t($e(n))}),process.stdin.on("error",o=>{r(o)})})}function Pn(){let e,t,r=async i=>{if(t&&t!==i)throw new p(`Only one option may use "${U}" stdin token per command invocation. Already used by ${t}.`,f.USAGE);return t=i,e||(e=On(i)),await e};return{resolveValue:async(i,s)=>{if(i!==void 0)return i.trim()!==U?i:await r(s)},resolveList:async(i,s)=>{if(!i)return;let a=i.map((u,m)=>u.trim()===U?m:-1).filter(u=>u>=0);if(a.length===0)return i;if(a.length>1)throw new p(`${s} accepts "${U}" stdin token at most once per command invocation`,f.USAGE);let c=await r(s),d=[...i];return d[a[0]]=c,d}}}function zn(e,t){let r=Number(e);if(!Number.isFinite(r))throw new p(`Invalid ${t} value "${e}"`,f.USAGE);return r}function $n(e,t){let r=e.trim(),n=Number(r);if(r===""||!Number.isInteger(n)||n<0)throw new p(`Invalid ${t} value "${e}". Expected a non-negative integer.`,f.USAGE);return n}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="806bf35f-dc7e-55a8-9bb9-64be87111c22")}catch{}})();var Fe={critical:0,high:1,medium:2,low:3,minimal:4},Fn=Object.keys(Fe),Un=`numbers 0..4 (0=critical, 1=high, 2=medium, 3=low, 4=minimal) or names (${Fn.join(", ")}), case-insensitive`;function se(e){return new p(`Invalid priority "${e}". Accepted values: ${Un}.`,f.USAGE)}function Vn(e){if(typeof e=="number"){if(Number.isInteger(e)&&e>=0&&e<=4)return e;throw se(String(e))}if(typeof e!="string")throw se(String(e));let t=e.trim();if(t.length===0)throw se(e);let r=t.toLowerCase();if(Object.prototype.hasOwnProperty.call(Fe,r))return Fe[r];if(/^[0-4]$/.test(t))return Number(t);throw se(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]="bf76a01e-7292-59df-94ca-1e41aaff7365")}catch{}})();var jn=/^[A-Za-z0-9][A-Za-z0-9._/-]*$/,qn=64;function va(e){let t=e?.trim().toLowerCase().replaceAll("-","_");if(t==="warn"||t==="strict_error")return t;if(t==="strict")return"strict_error";throw new p("Config set sprint-release-format-policy requires --policy with one of: warn, strict_error (alias: strict)",f.USAGE)}function Hn(e,t,r){let n=t.trim();if(n.length===0)throw new p(`--${e} must not be empty. Use --${e} none to unset.`,f.USAGE);if(n.length<=qn&&jn.test(n))return{value:n,warnings:[]};let i="Expected 1-64 characters matching [A-Za-z0-9][A-Za-z0-9._/-]* (no spaces).";if(r==="strict_error")throw new p(`Invalid --${e} value "${n}". ${i}`,f.USAGE);return{value:n,warnings:[`validation_warning:${e}_format:${n}`]}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d0e997bc-8bdb-5602-8606-73ecf77b2a35")}catch{}})();var Pt={open:"open_status",closed:"close_status",canceled:"canceled_status",cancelled:"canceled_status"},zt="all";function Na(e){if(typeof e!="string")return!1;let t=e.split(",").map(r=>r.trim().toLowerCase()).filter(r=>r.length>0);return t.length===1&&t[0]===zt}function Yn(e,t){let r=e.trim().toLowerCase();if(r.length===0)return;let n=Pt[r];return n?t[n]:ve(e,t)}function Bn(e){let t=new Set(Object.keys(Pt));for(let r of e.definitions){t.add(r.id);for(let n of r.aliases)t.add(n)}return[...t]}function Wn(e,t){let r=e.trim().toLowerCase(),n,o=Number.POSITIVE_INFINITY;for(let i of Bn(t)){let s=we(r,i.toLowerCase(),2);s!==null&&s<o&&(n=i,o=s)}return n}function Gn(e,t,r){if(typeof e!="string")return;let n=r?.strict===!0,o=r?.flagLabel??"--status",i=e.split(",").map(c=>c.trim()).filter(c=>c.length>0);if(i.length===0)return;if(i.filter(c=>c.trim().toLowerCase()===zt).length>0){if(i.length===1)return;throw new p(`Invalid ${o} value "all". Use it by itself, or omit ${o} to search every status.`,f.USAGE)}let a=[];for(let c of i){let d=Yn(c,t);if(d===void 0){if(n){let u=Wn(c,t);throw new p(`Invalid ${o} value "${c}". Use open|closed|canceled or a configured status id${u?`. Did you mean "${u}"?`:"."}`,f.USAGE)}a.push(c);continue}a.push(d)}return[...new Set(a)]}(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]="b7a167e0-3041-5056-a672-ea0a054ed8df")}catch{}})();var Kn={bug:"Issue",bugfix:"Issue",defect:"Issue",incident:"Issue",enhancement:"Feature",story:"Feature",userstory:"Feature","user-story":"Feature","user story":"Feature",change:"Chore",ticket:"Task",todo:"Task"};function Qn(e){if(e!==void 0)return Kn[e.trim().toLowerCase()]}(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]="6d11dc0f-e313-5b39-965d-6bc84ad52966")}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]="43a56374-808c-5fa6-bd6c-5d93175df0d2")}catch{}})();function $t(e,t){return Ae(e,t)}function Jn(e,t,r){let n={};for(let o of t.command_to_fields.get(r)??[]){let i=ht(e,o);i!==void 0&&(n[o.metadata_key]=gt(o,i))}return n}function Xn(e,t){for(let[r,n]of Object.entries(t)){let o=e[r];if(Array.isArray(n)){if(Array.isArray(o)){let i=o.map(a=>String(a));if(!n.map(a=>String(a)).every(a=>i.includes(a)))return!1;continue}if(!$t(o,n[n.length-1]))return!1;continue}if(!$t(o,n))return!1}return!0}import{spawnSync as Ut}from"node:child_process";(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]="12bfc6e7-8979-58e8-8276-98cc859f3e32")}catch{}})();var Zn="PM_DISABLE_OLLAMA_AUTO_DEFAULTS",eo="PM_OLLAMA_MODEL",to="http://localhost:11434",ro="qwen3-embedding:0.6b",no=".agents/pm/search/lancedb/",oo=1500,io=2500,so=/qwen.*(?:embed|embedding)|(?:embed|embedding).*qwen/i,ao=/embed|embedding/i,I=g;function co(){let e=I(process.env[Zn]);if(!e)return!1;let t=e.toLowerCase();return t==="1"||t==="true"||t==="yes"}function Ft(e){return e.some(t=>I(t)!==null)}function uo(e){let t=I(e);return!!(t&&t.toLowerCase()!=="ollama")}function lo(e){let t=I(e);return!!(t&&t.toLowerCase()!=="lancedb")}function fo(e){return uo(e.search?.provider)||lo(e.vector_store?.adapter)||Ft([e.providers?.openai?.base_url,e.providers?.openai?.model,e.providers?.openai?.api_key])?!0:Ft([e.vector_store?.qdrant?.url,e.vector_store?.qdrant?.api_key])}function mo(){let e=Ut("ollama",["--version"],{encoding:"utf8",timeout:oo});return e.error?!1:e.status===0}function po(e){let t=e.split(/\r?\n/).map(i=>i.trim()).filter(i=>i.length>0);if(t.length===0)return null;let r=t.map(i=>i.split(/\s+/)[0]?.trim()).filter(i=>!!(i&&i.length>0)).filter(i=>i.toUpperCase()!=="NAME");if(r.length===0)return null;let n=r.find(i=>so.test(i));return n||(r.find(i=>ao.test(i))??null)}function _o(e){let t=I(e.providers?.ollama?.model);if(t)return t;let r=I(process.env[eo]);if(r)return r;let n=Ut("ollama",["list"],{encoding:"utf8",timeout:io});if(!n.error&&n.status===0){let o=po(typeof n.stdout=="string"?n.stdout:"");if(o)return o}return null}function ho(e){return{baseUrl:I(e.providers?.ollama?.base_url)===null,model:I(e.providers?.ollama?.model)===null,lancedbPath:I(e.vector_store?.lancedb?.path)===null,embeddingModel:I(e.search?.embedding_model)===null}}function go(e){return e.baseUrl||e.model||e.lancedbPath||e.embeddingModel}function yo(e,t,r){if(!t.baseUrl&&!t.model)return;let n=e.providers??={},o=n.ollama??={};t.baseUrl&&(o.base_url=to),t.model&&(o.model=r)}function Eo(e,t){if(!t.lancedbPath)return;let r=e.vector_store??={},n=r.lancedb??={};n.path=no}function wo(e,t,r){if(!t.embeddingModel)return;let n=e.search??={};n.embedding_model=r}function ae(e){let t={settings:e,auto_ollama_defaults_applied:!1};if(co()||fo(e))return t;let r=ho(e);if(!go(r)||r.model&&!mo())return t;let n=structuredClone(e),o=_o(n);return o?(yo(n,r,o),Eo(n,r),wo(n,r,o),{settings:n,auto_ollama_defaults_applied:!0}):{...t,auto_ollama_defaults_skipped_reason:"no_installed_embedding_model",auto_ollama_defaults_remediation:`Run ollama pull ${ro} or configure providers.ollama.model explicitly (and search.embedding_model if you need an override).`}}(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]="d8d5f7e9-5293-564b-bc44-f5ba30336893")}catch{}})();var So="reindex";import tr 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]="b5ce7132-0024-5d42-9cb8-585933beb7c7")}catch{}})();var xo=3e4;function M(e,t,r=xo){let n=e??r;if(!Number.isFinite(n)||n<=0)throw new Error(`${t} timeout must be a positive finite number`);return Math.floor(n)}function N(e,t){if(e)return e;if(typeof globalThis.fetch=="function")return globalThis.fetch.bind(globalThis);throw new Error(`${t} execution requires a fetch implementation`)}async function Io(e){try{return(await e.text()).replaceAll(/\s+/g," ").trim()}catch(t){return`(failed to read response body: ${b(t)})`}}async function ce(e){let t=new AbortController,r=setTimeout(()=>{t.abort()},e.timeoutMs);try{let n;try{n=await e.fetcher(e.endpoint,{method:e.method,headers:e.headers,body:JSON.stringify(e.body),signal:t.signal})}catch(o){throw o instanceof Error&&o.name==="AbortError"?new Error(`${e.requestLabel} timed out after ${e.timeoutMs}ms`):new Error(`${e.requestLabel} execution failed: ${b(o)}`)}if(!n.ok){let o=await Io(n),i=o.length>0?`: ${o}`:"";throw new Error(`${e.requestLabel} failed with status ${n.status} ${n.statusText}${i}`)}try{return await n.json()}catch(o){throw new Error(`${e.responseLabel} JSON parse failed: ${b(o)}`)}}finally{clearTimeout(r)}}(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]="af754be6-8026-530a-8a20-b03d4ed742e1")}catch{}})();function rc(e,t){let r=g(e);if(!r)return"unconfigured";let n=g(t);return n&&n.toLowerCase()===r.toLowerCase()?"configured":"auto-detected"}function Ao(e){let t=B(e),r=t.toLowerCase();return r.endsWith("/embeddings")?t:r.endsWith("/v1")?`${t}/embeddings`:`${t}/v1/embeddings`}function qt(e){let t=e.search?.embedding_model;return g(t)||null}function Co(e){let t=g(e.providers?.openai?.base_url),r=g(e.providers?.openai?.model);if(!t||!r)return null;let n=qt(e),o=g(e.providers?.openai?.api_key);return{name:"openai",base_url:t,model:n??r,...o?{api_key:o}:{}}}function vo(e){let t=g(e.providers?.ollama?.base_url),r=g(e.providers?.ollama?.model);if(!t||!r)return null;let n=qt(e);return{name:"ollama",base_url:t,model:n??r}}function Ht(e){let t=(Array.isArray(e)?e:[e]).map(r=>r.trim()).filter(r=>r.length>0);if(t.length===0)throw new Error("Embedding input must include at least one non-empty string");return t}function Lo(e){let t=[],r=[],n=new Map;for(let o of e){let i=n.get(o);if(i===void 0){let s=t.length;t.push(o),n.set(o,s),r.push(s);continue}r.push(i)}return{uniqueInputs:t,originalToUniqueIndex:r}}function Ro(e){let t=e.map((n,o)=>({embedding:n.embedding,index:n.index,position:o}));if(t.some(n=>n.index!==void 0)){for(let n of t)if(!Number.isInteger(n.index))throw new TypeError(`OpenAI embedding response entry at position ${n.position} is missing a valid integer index`);return[...t].sort((n,o)=>{let i=n.index-o.index;return i!==0?i:n.position-o.position})}return t}function Ue(e){let t=Co(e),r=vo(e),n=[t,r].filter(a=>a!==null),o=g(e.search?.provider),i=o?o.toLowerCase():null;return{active:(i?n.find(a=>a.name===i):void 0)??n[0]??null,available:n}}function jt(e){let t=B(e.base_url);return e.name==="openai"?{provider:"openai",endpoint:Ao(t),model:e.model}:{provider:"ollama",endpoint:`${t}/api/embed`,model:e.model}}function Do(e,t){let r=Ht(t);return e.name==="openai"?{target:jt(e),method:"POST",headers:{"content-type":"application/json",...e.api_key?{authorization:`Bearer ${e.api_key}`}:{}},body:{model:e.model,input:r.length===1?r[0]:r}}:{target:jt(e),method:"POST",headers:{"content-type":"application/json"},body:{model:e.model,input:r}}}function ko(e,t){if(e.name==="openai"){let o=t.data;if(!Array.isArray(o)||o.length===0)throw new Error("OpenAI embedding response must include a non-empty data array");return Ro(o).map((s,a)=>{let c=s.embedding;if(!F(c))throw new Error(`OpenAI embedding response entry at index ${a} is missing a numeric embedding vector`);return[...c]})}let r=t.embedding;if(F(r))return[[...r]];let n=t.embeddings;if(Array.isArray(n)&&n.length>0)return n.map((o,i)=>{if(!F(o))throw new Error(`Ollama embedding response entry at index ${i} is missing a numeric embedding vector`);return[...o]});throw new Error("Ollama embedding response must include embedding or embeddings vectors")}async function Yt(e,t,r={}){let n=M(r.timeout_ms,"Embedding request"),o=N(r.fetcher,"Embedding request"),i=Ht(t),s=Lo(i),a=Do(e,s.uniqueInputs),c=await ce({endpoint:a.target.endpoint,method:a.method,headers:a.headers,body:a.body,timeoutMs:n,fetcher:o,requestLabel:"Embedding request",responseLabel:"Embedding response"}),d=ko(e,c);if(d.length!==s.uniqueInputs.length)throw new Error(`Embedding response cardinality mismatch: expected ${s.uniqueInputs.length} vector(s), received ${d.length}`);return s.originalToUniqueIndex.map(u=>[...d[u]])}(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]="61c0153b-8fa5-5c26-aa88-ca9807f2d160")}catch{}})();var de=["title","description","tags","status","type","priority","assignee","parent","goal","value","why_now","risk","confidence","estimated_minutes","acceptance_criteria","resolution","expected_result","actual_result","body","comments","notes","learnings","reminders","events","dependencies","plan"];function Ve(e){let t=e?.search?.corpus_fields;if(!Array.isArray(t))return[...de];let r=new Set(de),n=Array.from(new Set(t.filter(o=>typeof o=="string").map(o=>o.trim()).filter(o=>o.length>0&&r.has(o))));return n.length>0?n:[...de]}var Mo=8e3,je=3200,O="...[semantic corpus truncated]",No="search_embedding_corpus_max_characters_invalid:using_provider_default";function C(e){return e.map(t=>t==null?"":String(t).trim()).filter(t=>t.length>0).join(" ")}function Oo(e){return(e.reminders??[]).map(t=>C([t.at,t.text]))}function Po(e){return(e.events??[]).map(t=>C([t.start_at,t.end_at,t.title,t.description,t.location,t.all_day===!0?"all day":void 0,t.timezone,t.recurrence?.freq,t.recurrence?.interval,t.recurrence?.count,t.recurrence?.until,t.recurrence?.by_weekday?.join(" "),t.recurrence?.by_month_day?.join(" "),t.recurrence?.exdates?.join(" ")]))}function zo(e,t){e.push(t.title,t.body,t.status,t.owner,t.evidence,t.blocked_reason,t.superseded_by);for(let r of t.linked_items??[])e.push(`${r.kind} ${r.id}`,r.note);for(let r of t.files??[])e.push(r.path,r.note);for(let r of t.tests??[])e.push(r.command,r.path,r.note);for(let r of t.docs??[])e.push(r.path,r.note)}function $o(e,t){for(let r of t.plan_decisions??[])e.push(r.decision,r.rationale,r.evidence);for(let r of t.plan_discoveries??[])e.push(r.text);for(let r of t.plan_validation??[])e.push(r.text,r.command,r.expected)}function ic(e){let t=[];t.push(e.plan_mode,e.plan_scope,e.plan_harness,e.plan_resume_context);for(let r of e.plan_steps??[])zo(t,r);return $o(t,e),t.filter(r=>typeof r=="string"&&r.length>0).join(" ")}function Fo(e){let t=(e.plan_steps??[]).map(s=>C([s.order,s.id,s.title,s.body,s.status,s.owner,s.evidence,s.blocked_reason,s.superseded_by,(s.linked_items??[]).map(a=>C([a.kind,a.id,a.note])).join(" "),(s.files??[]).map(a=>C([a.path,a.note])).join(" "),(s.tests??[]).map(a=>C([a.command,a.path,a.note])).join(" "),(s.docs??[]).map(a=>C([a.path,a.note])).join(" ")])),r=(e.plan_decisions??[]).map(s=>C([s.decision,s.rationale,s.evidence,s.step_id])),n=(e.plan_discoveries??[]).map(s=>C([s.text,s.step_id])),o=(e.plan_validation??[]).map(s=>C([s.text,s.command,s.expected]));if([e.plan_mode,e.plan_scope,e.plan_harness,e.plan_resume_context,...t,...r,...n,...o].some(s=>s!==void 0))return{mode:e.plan_mode,scope:e.plan_scope,harness:e.plan_harness,resume_context:e.plan_resume_context,steps:t,decisions:r,discoveries:n,validation:o}}function A(e){return typeof e=="string"&&e.trim().length>0}var Uo={title:e=>e.metadata.title,description:e=>e.metadata.description,tags:e=>e.metadata.tags,status:e=>e.metadata.status,type:e=>e.metadata.type,priority:e=>typeof e.metadata.priority=="number"?e.metadata.priority:void 0,assignee:e=>A(e.metadata.assignee)?e.metadata.assignee:void 0,parent:e=>A(e.metadata.parent)?e.metadata.parent:void 0,goal:e=>A(e.metadata.goal)?e.metadata.goal:void 0,value:e=>A(e.metadata.value)?e.metadata.value:void 0,why_now:e=>A(e.metadata.why_now)?e.metadata.why_now:void 0,risk:e=>A(e.metadata.risk)?e.metadata.risk:void 0,confidence:e=>e.metadata.confidence!==void 0&&e.metadata.confidence!==null?e.metadata.confidence:void 0,estimated_minutes:e=>typeof e.metadata.estimated_minutes=="number"?e.metadata.estimated_minutes:void 0,acceptance_criteria:e=>A(e.metadata.acceptance_criteria)?e.metadata.acceptance_criteria:void 0,resolution:e=>A(e.metadata.resolution)?e.metadata.resolution:void 0,expected_result:e=>A(e.metadata.expected_result)?e.metadata.expected_result:void 0,actual_result:e=>A(e.metadata.actual_result)?e.metadata.actual_result:void 0,body:e=>e.body,comments:e=>(e.metadata.comments??[]).map(t=>t.text),notes:e=>(e.metadata.notes??[]).map(t=>t.text),learnings:e=>(e.metadata.learnings??[]).map(t=>t.text),reminders:e=>Oo(e.metadata),events:e=>Po(e.metadata),dependencies:e=>(e.metadata.dependencies??[]).map(t=>({id:t.id,kind:t.kind})),plan:e=>Fo(e.metadata)};function Bt(e,t={}){let r=t.fields??de,n={};for(let o of r){let i=Uo[o];if(!i)continue;let s=i(e);s!==void 0&&(n[o]=s)}return n}function Vo(e){return e?.trim().toLowerCase()==="ollama"?je:Mo}function V(e,t){let r=Vo(e),n=_t(t);return n!==null?{maxCharacters:n,warning:null}:{maxCharacters:r,warning:t==null?null:No}}function qe(e,t={}){let r=JSON.stringify(Bt(e,{fields:t.fields})),n=V(t.providerName,t.maxCharacters).maxCharacters;if(r.length<=n)return r;if(n<=O.length)return O.slice(0,n);let o=Math.max(0,n-O.length);return`${r.slice(0,o)}${O}`}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="2c518b97-bc75-5e3f-91e8-d6779d565558")}catch{}})();function jo(e,t){let r=e.search.embedding_batch_size,n=e.search.embedding_timeout_ms,o=e.search.scanner_max_batch_retries,i=Number.isFinite(r)&&r>0?Math.floor(r):1,s=Number.isFinite(n)&&n>0?Math.floor(n):3e4,a=Number.isFinite(o)&&o>=0?Math.floor(o):0;return{batchSize:i,timeoutMs:s,maxRetries:a,maxBatchInputCharacters:Number.POSITIVE_INFINITY,maxInputCharacters:t}}function qo(e,t,r){let n=[],o=[],i=0;for(let s of e){let a=o.length>=t,c=o.length>0&&Number.isFinite(r)&&i+s.length>r;(a||c)&&(n.push(o),o=[],i=0),o.push(s),i+=s.length}return n.push(o),n}function Ho(e,t){return e.name!=="ollama"?t:{...t,maxBatchInputCharacters:je}}function Yo(e,t){if(!Number.isFinite(t)||t<=0||e.length<=t)return e;let r=Math.max(0,t-O.length);return`${e.slice(0,r)}${O}`.slice(0,t)}function Wt(e){let t=b(e).toLowerCase();return t.includes("timed out")||t.includes("timeout")}function Bo(e,t,r,n,o,i){let s=`Embedding batch ${t} failed after ${o} attempt(s): ${b(i)}`,a=`provider=${e.name} model=${e.model} batch_size=${r} timeout_ms=${n}`;return Wt(i)?`${s} (${a}; guidance=check provider availability or lower search.embedding_batch_size, raise search.embedding_timeout_ms, or run keyword search while semantic indexing catches up)`:`${s} (${a})`}async function He(e,t,r,n,o,i){let s=null;for(let a=0;a<=o;a+=1)try{let c=await Yt(e,t,{timeout_ms:n});return a>0&&i.push(`search_embedding_batch_retry_succeeded:batch=${r}:attempt=${a+1}:size=${t.length}`),c}catch(c){if(s=c,Wt(c)&&t.length>1){let d=Math.ceil(t.length/2),u=t.slice(0,d),m=t.slice(d);return i.push(`search_embedding_batch_split_after_timeout:batch=${r}:size=${t.length}:parts=${u.length}|${m.length}`),[...await He(e,u,`${r}.1`,n,o,i),...await He(e,m,`${r}.2`,n,o,i)]}if(a<o){let d=Math.min(1e3*2**a,8e3);await new Promise(u=>setTimeout(u,d))}}throw new Error(Bo(e,r,t.length,n,o+1,s))}async function Ye(e,t,r,n={}){if(r.length===0)return{vectors:[],warnings:[]};let o=[],i=V(e.name,t.search.embedding_corpus_max_characters);i.warning&&o.push(i.warning);let s=Ho(e,jo(t,i.maxCharacters)),a=0,c=r.map(_=>{let l=Yo(_,s.maxInputCharacters);return l.length<_.length&&(a+=1),l});a>0&&o.push(`search_embedding_input_truncated:count=${a}:max_characters=${s.maxInputCharacters}`);let d=qo(c,s.batchSize,s.maxBatchInputCharacters),u=[],m=0;for(let _=0;_<d.length;_+=1){let l=d[_];n.onProgress?.({batch_index:_+1,batch_total:d.length,batch_size:l.length,completed_inputs:m,total_inputs:c.length,phase:"start"}),u.push(...await He(e,l,String(_+1),s.timeoutMs,s.maxRetries,o)),m+=l.length,n.onProgress?.({batch_index:_+1,batch_total:d.length,batch_size:l.length,completed_inputs:m,total_inputs:c.length,phase:"complete"})}return{vectors:u,warnings:o}}import{mkdir as Wo,readFile as Go,stat as Ge,unlink as Ko}from"node:fs/promises";import{basename as Gt,dirname as Be,isAbsolute as Qo,join as Jo,resolve as Ke}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]="98c8d03c-bdde-5ac4-b80d-395d885f7442")}catch{}})();var Qe="pm_items",Xo=/[^a-zA-Z0-9_-]/g,Zo=128,ei=".pm-cli-local-vectors",We=1,P=new Map;function K(e){return(g(e.collection_name)??Qe).replaceAll(Xo,"_").slice(0,Zo)}function ue(e){if(!F(e)||e.length===0)throw new Error("Vector values must be a non-empty numeric array");return[...e]}function Qt(e){if(!Number.isFinite(e)||e<=0)throw new Error("Vector query limit must be a positive number");return Math.floor(e)}function ti(e){let t=e.result;if(!Array.isArray(t))throw new TypeError("Qdrant query response must include a result array");let r=t.map((n,o)=>{let i=n.id,s=typeof i=="number"?String(i):i,a=g(s);if(!a)throw new Error(`Qdrant query response entry at index ${o} is missing a non-empty id`);let c=n.score;if(typeof c!="number"||!Number.isFinite(c))throw new TypeError(`Qdrant query response entry at index ${o} is missing a finite numeric score`);let d=n.payload;if(d!==void 0&&(typeof d!="object"||d===null||Array.isArray(d)))throw new Error(`Qdrant query response entry at index ${o} must provide payload as an object when set`);return{id:a,score:c,...d?{payload:d}:{}}});return r.sort((n,o)=>n.score!==o.score?o.score-n.score:n.id.localeCompare(o.id)),r}function Je(e){let t=g(e.result?.status);if(t)return{status:t};let r=g(e.status);if(r)return{status:r};throw new Error("Qdrant upsert response must include status metadata")}async function G(e,t,r,n,o){return await ce({endpoint:e,method:t.method,headers:t.headers,body:t.body,timeoutMs:r,fetcher:n,requestLabel:`Vector ${o} request`,responseLabel:`Vector ${o} response`})}function ri(e){let t=g(e.vector_store?.qdrant?.url);if(!t)return null;let r=g(e.vector_store?.collection_name),n=g(e.vector_store?.qdrant?.api_key);return{name:"qdrant",url:t,...r&&r!==Qe?{collection_name:r}:{},...n?{api_key:n}:{}}}function ni(e){let t=Ke(e),r=Be(t);return Gt(t)==="pm"&&Gt(r)===".agents"?Be(r):t}function oi(e,t){return!t||Qo(e)?e:Ke(ni(t),e)}function ii(e,t){let r=g(e.vector_store?.lancedb?.path);if(!r)return null;let n=g(e.vector_store?.collection_name);return{name:"lancedb",path:oi(r,t),...n&&n!==Qe?{collection_name:n}:{}}}function si(e){if(!Array.isArray(e)||e.length===0)throw new Error("Vector upsert records must include at least one entry");return e.map((t,r)=>{let n=g(t.id);if(!n)throw new Error(`Vector upsert record at index ${r} is missing a non-empty id`);let o=ue(t.vector),i=t.payload;if(i!==void 0&&(typeof i!="object"||i===null||Array.isArray(i)))throw new Error(`Vector upsert record at index ${r} must provide payload as an object when set`);return{id:n,vector:o,...i?{payload:i}:{}}})}function ai(e){if(!Array.isArray(e)||e.length===0)throw new Error("Vector delete ids must include at least one entry");let t=e.map((n,o)=>{let i=g(n);if(!i)throw new Error(`Vector delete id at index ${o} is missing a non-empty value`);return i}).sort((n,o)=>n.localeCompare(o)),r=[];for(let n of t)r.at(-1)!==n&&r.push(n);return r}function ci(e){return e.replace(/\/points\?wait=true$/,"/points/delete?wait=true")}function di(e){return e.replace(/\/points\?wait=true$/,"")}function le(e){return{"content-type":"application/json",...e.api_key?{"api-key":e.api_key}:{}}}function fe(e,t){return j(e,t)}function j(e,t){return Jo(Ke(e),ei,`${t}.json`)}function ui(e,t,r){let n=g(e.id);if(!n)throw new Error(`LanceDB local snapshot '${r}' record at index ${t} is missing a non-empty id`);let o=ue(e.vector),i=e.payload;if(i!==void 0&&(typeof i!="object"||i===null||Array.isArray(i)))throw new Error(`LanceDB local snapshot '${r}' record '${n}' must provide payload as an object when set`);return{id:n,vector:o,...i?{payload:i}:{}}}function li(e,t,r){let n;try{n=JSON.parse(r)}catch(c){throw new Error(`LanceDB local snapshot at '${e}' is not valid JSON: ${b(c)}`)}if(typeof n!="object"||n===null||Array.isArray(n))throw new Error(`LanceDB local snapshot at '${e}' must be a JSON object`);if(n.version!==We)throw new Error(`LanceDB local snapshot at '${e}' must include version=${We}`);let i=g(n.table);if(!i)throw new Error(`LanceDB local snapshot at '${e}' must include a non-empty table value`);if(i!==t)throw new Error(`LanceDB local snapshot at '${e}' table mismatch: expected '${t}', received '${i}'`);let s=n.records;if(!Array.isArray(s))throw new TypeError(`LanceDB local snapshot at '${e}' must include a records array`);let a=new Map;for(let c=0;c<s.length;c+=1){let d=ui(s[c],c,e);a.set(d.id,d)}return a}async function fi(e){try{let t=await Ge(e);return{mtimeMs:t.mtimeMs,size:t.size}}catch(t){if(!Y(t))throw t;return null}}function mi(e,t){if(!t)return null;if(t.mtimeMs===null&&t.size===null&&t.records.size===0)return t.records;let r=new Map;return P.set(e,{records:r,mtimeMs:null,size:null}),r}function pi(e,t){return e!==void 0&&t!==null&&e.mtimeMs===t.mtimeMs&&e.size===t.size}async function Xe(e,t){let r=fe(e,t),n=j(e,t),o=await fi(n),i=P.get(r);if(!o){let a=mi(r,i);if(a)return a}if(pi(i,o))return i.records;let s=new Map;try{let a=await Go(n,"utf8");s=li(n,t,a)}catch(a){if(!Y(a))throw a}return P.set(r,{records:s,mtimeMs:o?.mtimeMs??null,size:o?.size??null}),s}function _i(e){let t=[...e.values()];return t.sort((r,n)=>r.id.localeCompare(n.id)),t.map(r=>({id:r.id,vector:[...r.vector],...r.payload?{payload:r.payload}:{}}))}async function Jt(e){try{await Ko(e)}catch(t){if(!Y(t))throw new Error(`LanceDB local snapshot delete failed at '${e}': ${b(t)}`)}}async function Xt(e,t,r){let n=j(e,t);if(r.size===0){await Jt(n);return}let o=Be(n);try{await Wo(o,{recursive:!0})}catch(s){throw new Error(`LanceDB local snapshot directory create failed at '${o}': ${b(s)}`)}let i=`${JSON.stringify({version:We,table:t,records:_i(r)})}
9
- `;try{await T(n,i)}catch(s){throw new Error(`LanceDB local snapshot write failed at '${n}': ${b(s)}`)}}async function hi(e,t){let r=fe(e,t),n=j(e,t);await Jt(n),P.delete(r)}function Kt(e){let t=0;for(let r=0;r<e.length;r+=1)t+=e[r]*e[r];return Math.sqrt(t)}function gi(e,t){let r=0;for(let i=0;i<e.length;i+=1)r+=e[i]*t[i];let n=Kt(e),o=Kt(t);return n===0||o===0?0:r/(n*o)}function Ze(e,t){let r=ri(e),n=ii(e,t),o=[r,n].filter(c=>c!==null),i=g(e.vector_store?.adapter),s=i?i.toLowerCase():null;return{active:(s?o.find(c=>c.name===s):void 0)??o[0]??null,available:o}}function me(e){let t=K(e);if(e.name==="qdrant"){let o=B(e.url),i=encodeURIComponent(t);return{store:"qdrant",query_target:`${o}/collections/${i}/points/search`,upsert_target:`${o}/collections/${i}/points?wait=true`}}let r=encodeURIComponent(e.path),n=encodeURIComponent(t);return{store:"lancedb",query_target:`lancedb://${r}#${n}`,upsert_target:`lancedb://${r}#${n}`}}function yi(e,t,r){let n=me(e),o=ue(t),i=Qt(r);return e.name==="qdrant"?{target:n,method:"POST",headers:le(e),body:{vector:o,limit:i,with_payload:!0}}:{target:n,method:"LOCAL",headers:{},body:{table:K(e),vector:o,limit:i}}}function Ei(e,t){let r=me(e),n=si(t);return e.name==="qdrant"?{target:r,method:"POST",headers:le(e),body:{points:n}}:{target:r,method:"LOCAL",headers:{},body:{table:K(e),records:n}}}function wi(e,t){let r=me(e),n=ai(t);return e.name==="qdrant"?{target:r,method:"POST",headers:le(e),body:{points:n}}:{target:r,method:"LOCAL",headers:{},body:{table:K(e),ids:n}}}async function hc(e,t,r,n={}){let o=yi(e,t,r);if(o.method==="LOCAL"){let c=e,d=o.body,u=await Xe(c.path,d.table);if(u.size===0)return[];let m=ue(d.vector),_=Qt(d.limit),l=[],h=0;for(let y of u.values()){if(y.vector.length!==m.length){h++;continue}l.push({id:y.id,score:gi(m,y.vector),...y.payload?{payload:y.payload}:{}})}return h>0&&n.warnings&&n.warnings.push(`vector_dimension_mismatch:${h} records skipped (expected ${m.length} dimensions)`),l.sort((y,E)=>y.score!==E.score?E.score-y.score:y.id.localeCompare(E.id)),l.slice(0,_)}let i=M(n.timeout_ms,"Vector request"),s=N(n.fetcher,"Vector request"),a=await G(o.target.query_target,{method:"POST",headers:o.headers,body:o.body},i,s,"query");return ti(a)}async function et(e,t,r={}){let n=Ei(e,t);if(n.method==="LOCAL"){let a=e,c=n.body,d=fe(a.path,c.table),u=await Xe(a.path,c.table);for(let l of c.records)u.set(l.id,l);await Xt(a.path,c.table,u);let m=j(a.path,c.table),_=await Ge(m);return P.set(d,{records:u,mtimeMs:_.mtimeMs,size:_.size}),{status:"ok"}}let o=M(r.timeout_ms,"Vector request"),i=N(r.fetcher,"Vector request"),s=await G(n.target.upsert_target,{method:"POST",headers:n.headers,body:n.body},o,i,"upsert");return Je(s)}async function pe(e,t,r={}){let n=wi(e,t);if(n.method==="LOCAL"){let a=e,c=n.body,d=fe(a.path,c.table),u=await Xe(a.path,c.table);if(u.size===0)return{status:"ok"};for(let m of c.ids)u.delete(m);if(await Xt(a.path,c.table,u),u.size===0)P.delete(d);else{let m=j(a.path,c.table),_=await Ge(m);P.set(d,{records:u,mtimeMs:_.mtimeMs,size:_.size})}return{status:"ok"}}let o=M(r.timeout_ms,"Vector request"),i=N(r.fetcher,"Vector request"),s=await G(ci(n.target.upsert_target),{method:"POST",headers:n.headers,body:n.body},o,i,"delete");return Je(s)}async function Zt(e,t=[],r={},n){if(e.name==="lancedb")return await hi(e.path,K(e)),{status:"ok"};if(n!==void 0){if(!Number.isInteger(n)||n<=0)throw new Error("Vector reset dimension must be a positive integer when provided");let i=me(e),s=di(i.upsert_target),a=M(r.timeout_ms,"Vector request"),c=N(r.fetcher,"Vector request"),d=le(e);try{await G(s,{method:"DELETE",headers:d,body:{}},a,c,"delete")}catch(m){if(!b(m).includes("failed with status 404"))throw m}let u=await G(s,{method:"PUT",headers:d,body:{vectors:{size:n,distance:"Cosine"}}},a,c,"upsert");return Je(u)}let o=t.map(i=>i.trim()).filter(i=>i.length>0);return o.length===0?{status:"ok"}:await pe(e,o,r)}(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]="4b3ad5fc-0f86-5f20-a23b-19d447cb0973")}catch{}})();function _e(e,t){let r=g(e),n=g(t);return!r||!n?null:{provider:r,model:n}}function er(e){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))throw new Error("Vectorization embedding metadata must be an object when set");let t=_e(e.provider,e.model),r=e.vector_dimension;if(!t||typeof r!="number"||!Number.isInteger(r)||r<=0)throw new Error("Vectorization embedding metadata must include provider, model, and positive vector_dimension");return{...t,vector_dimension:r}}function tt(e,t){if(!Number.isInteger(t)||t<=0)throw new Error("Vectorization embedding metadata requires a positive vector dimension");return{provider:e.provider,model:e.model,vector_dimension:t}}function rt(e,t){return!e||e.provider!==t.provider||e.model!==t.model}function nt(e,t){return!!(e&&e.vector_dimension!==t)}function ot(e,t){if(e.length===0)throw new Error(`${t} returned no vectors`);let n=e[0].length;if(!Number.isInteger(n)||n<=0)throw new Error(`${t} returned an empty vector`);for(let o=1;o<e.length;o+=1)if(e[o]?.length!==n)throw new Error(`${t} returned mixed vector dimensions`);return n}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="7939a590-3662-5c66-99aa-3835a0dbaecc")}catch{}})();var rr="search/vectorization-status.json";function J(e){return[...new Set([...e].map(t=>t.trim()).filter(t=>t.length>0))].sort((t,r)=>t.localeCompare(r))}function nr(e){return typeof e=="string"&&e.trim().length>0&&Number.isFinite(Date.parse(e))}function or(e){let t=new Map;for(let[r,n]of Object.entries(e)){let o=r.trim();o.length===0||!nr(n)||t.set(o,n)}return Object.fromEntries([...t.entries()].sort((r,n)=>r[0].localeCompare(n[0])))}async function ir(e){let t=tr.join(e,rr),r=await S(t);if(r===null||r.trim().length===0)return{entries:{},embedding:null,warnings:[]};let n;try{n=JSON.parse(r)}catch{return{entries:{},embedding:null,warnings:["search_vectorization_status_ledger_invalid"]}}if(typeof n!="object"||n===null||n.version!==1||!Array.isArray(n.items))return{entries:{},embedding:null,warnings:["search_vectorization_status_ledger_invalid"]};let o=new Map;for(let s of n.items){if(typeof s!="object"||s===null)return{entries:{},embedding:null,warnings:["search_vectorization_status_ledger_invalid"]};let a=s.id,c=s.updated_at;if(typeof a!="string"||a.trim().length===0||!nr(c))return{entries:{},embedding:null,warnings:["search_vectorization_status_ledger_invalid"]};o.set(a.trim(),c)}let i=null;try{i=er(n.embedding)}catch{return{entries:{},embedding:null,warnings:["search_vectorization_status_ledger_invalid"]}}return{entries:Object.fromEntries([...o.entries()].sort((s,a)=>s[0].localeCompare(a[0]))),embedding:i,warnings:[]}}async function sr(e,t,r){let n=or(t),o=tr.join(e,rr),i=`${JSON.stringify({version:1,generated_at:D(),...r?{embedding:r}:{},items:Object.entries(n).map(([s,a])=>({id:s,updated_at:a}))},null,2)}
10
- `;await T(o,i)}function bi(e){return{id:e.id,type:e.type,status:e.status,priority:e.priority,updated_at:e.updated_at}}function Ti(e){let t=_e(e.name,e.model);if(!t)throw new Error("Embedding provider must include a provider name and model");return t}function Q(e,t){return{refreshed:[],skipped:e,warnings:[t]}}async function Si(e,t,r){if(!r.settings&&!await $(xe(e)))return Q(t,"search_semantic_refresh_skipped:settings_not_initialized");let n;try{if(r.settings)n=r.settings;else{let a=await ee(e),c=a.warnings.find(d=>d.startsWith("settings_read_"));if(c)return Q(t,`search_semantic_refresh_skipped:settings_read_failed:${c}`);n=a.settings}}catch(a){return Q(t,`search_semantic_refresh_skipped:settings_read_failed:${b(a)}`)}let o=r.apply_runtime_defaults?ae(n).settings:n,i=Ue(o).active;if(!i)return Q(t,"search_semantic_refresh_skipped:provider_unconfigured");let s=Ze(o,e).active;return s?{settings:o,provider:i,vectorStore:s}:Q(t,"search_semantic_refresh_skipped:vector_store_unconfigured")}async function xi(e,t,r,n,o,i){let s=[],a=new Set,c=new Set,d=[];for(let u of n){let m=await ke(e,u,t,r,o);if(!m){c.add(u);continue}try{let _=await Me(m,{schema:i});d.push({id:_.document.metadata.id,document:_.document})}catch(_){a.add(m.id),s.push(`search_semantic_refresh_item_read_failed:${m.id}:${b(_)}`)}}return d.sort((u,m)=>u.id.localeCompare(m.id)),{documents:d,missingIds:J(c),skippedIds:J(a),warnings:s}}async function Ii(e,t,r){let n=V(t.name,e.search.embedding_corpus_max_characters).maxCharacters,o=Ve(e),i=r.map(a=>qe(a.document,{providerName:t.name,maxCharacters:n,fields:o})),s=await Ye(t,e,i);return{vectors:s.vectors,vector_dimension:ot(s.vectors,"Semantic refresh embedding"),warnings:s.warnings}}async function Ai(e,t,r){return await et(e,t.map((n,o)=>({id:n.id,vector:r[o],payload:bi(n.document.metadata)}))),{refreshed:t.map(n=>n.id),skipped:[],warnings:[]}}async function Ci(e,t){if(t.length===0)return{refreshed:[],skipped:[],warnings:[]};try{return await pe(e,t),{refreshed:[],skipped:[],warnings:[]}}catch(r){return{refreshed:[],skipped:t,warnings:[`search_semantic_refresh_delete_failed:${b(r)}`]}}}async function zc(e,t,r={}){let n=J(t);if(n.length===0)return{refreshed:[],skipped:[],warnings:[]};let o=await Si(e,n,r);if(!("settings"in o))return o;let i=Te(o.settings,Ce()),s=await xi(e,o.settings.id_prefix,o.settings.item_format,n,i.type_to_folder,o.settings.schema),a=s.documents.length>0||s.missingIds.length>0?await ir(e):{entries:{},embedding:null,warnings:[]},c=Ti(o.provider),d=a.entries,u={refreshed:[],skipped:[],warnings:[]},m=a.embedding;if(s.documents.length>0)if(a.embedding&&rt(a.embedding,c))u={refreshed:[],skipped:s.documents.map(E=>E.id),warnings:["search_semantic_refresh_requires_reindex:embedding_identity_changed"]};else try{let E=await Ii(o.settings,o.provider,s.documents);if(nt(a.embedding,E.vector_dimension))u={refreshed:[],skipped:s.documents.map(w=>w.id),warnings:[...E.warnings,"search_semantic_refresh_requires_reindex:vector_dimension_changed"]};else{m=tt(c,E.vector_dimension);let w=await Ai(o.vectorStore,s.documents,E.vectors);u={refreshed:w.refreshed,skipped:w.skipped,warnings:[...E.warnings,...w.warnings]}}}catch(E){u={refreshed:[],skipped:s.documents.map(w=>w.id),warnings:[`search_semantic_refresh_failed:${b(E)}`]}}let _=await Ci(o.vectorStore,s.missingIds),l=new Set(u.refreshed),h=Object.fromEntries(s.documents.filter(E=>l.has(E.id)).map(E=>[E.id,E.document.metadata.updated_at])),y=[];if(Object.keys(h).length>0||s.missingIds.length>0){let E={...d,...or(h)};for(let w of s.missingIds)delete E[w];try{await sr(e,E,m)}catch(w){y.push(`search_vectorization_status_ledger_write_failed:${b(w)}`)}y.push(...a.warnings)}return{refreshed:J([...u.refreshed,..._.refreshed]),skipped:J([...s.skippedIds,...u.skipped,..._.skipped]),warnings:[...s.warnings,...u.warnings,..._.warnings,...y]}}import{createRequire as Li}from"node:module";(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]="8eb48648-6e55-5710-990e-6471c7cdcde0")}catch{}})();var Ri=/(?:token|secret|password|passwd|api[_-]?key|apikey|authorization|cookie|credentials|bearer|dsn)/i,Vc=new RegExp(`\\b(${Ri.source})\\s*[:=]\\s*([^\\s,;]+)`,"giu");var jc=Li(import.meta.url);(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]="e896db69-ed90-53f1-a227-e3d061b3bc8d")}catch{}})();var Yc=new Map([[f.USAGE,"invalid_command_usage"],[f.NOT_FOUND,"item_not_found"],[f.CONFLICT,"lock_conflict"],[f.DEPENDENCY_FAILED,"dependency_failed"]]);(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]="ffe56aed-b794-5bf4-99fd-e3c5fe065163")}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]="c43dd9f2-78ac-5c22-970a-0016a06b87b3")}catch{}})();var Zc=Object.freeze({"&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'","&amp;":"&"});(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]="0ce743d1-917a-5c96-b038-c95e3922bc48")}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]="868dfae8-2575-5d5f-8425-c7e68aefdc84")}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]="4ecab833-db06-5baa-bfe6-d28b4c97f85a")}catch{}})();function ki(e,t){if(e==null)return[];let r=t?.separators??/,/,o=e.split(r).map(a=>a.trim()).filter(a=>a.length>0),s=t?.unique!==!1?Array.from(new Set(o)):o;return t?.sort===!0?[...s].sort():s}import cr from"node:fs/promises";import he 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]="4baf0ef3-2412-51cf-9ade-18b5c6e610d1")}catch{}})();function Mi(e){return"json_markdown"}function dr(e,t){return he.relative(e,t).replaceAll("\\","/")}function Ni(e){return String(e).replaceAll(/[^a-zA-Z0-9._-]+/g,"_").slice(0,120)}async function Oi(e,t,r="item_format:migrate",n=be,o){if(t!=="toon")throw new Error("Only toon item-format migration targets are supported. Markdown item files are legacy read-only input.");let i=new Set,s=new Set,a=[],c=0,d=Mi(t),u=Object.entries(n);for(let[m,_]of u){let l=he.join(e,_),h=[];try{h=await cr.readdir(l)}catch{continue}let y=new Map;for(let w of h){let L=he.join(l,w),R=pt(L);if(!R)continue;let q=he.extname(w),H=w.slice(0,w.length-q.length).trim();if(H.length===0)continue;let z=y.get(H)??{};z[R]=L,y.set(H,z)}let E=[...y.keys()].sort((w,L)=>w.localeCompare(L));for(let w of E){let L=y.get(w);c+=1;let R=L[d];if(!R)continue;let q=L[t]??R,H=q===L[t]?t:d;try{let z=await cr.readFile(q,"utf8"),$r=Le(z,{format:H,schema:o,onWarning:Fr=>a.push(`item_format_migration_parse_warning:${w}:${Fr}`)}),Ee=Ie(e,m,w,t,n),mt=Re($r,{format:t,schema:o});await S(Ee)!==mt&&(await T(Ee,mt),a.push(...await Z({path:Ee,scope:"project",op:r})),i.add(w)),await X(R),s.add(dr(e,R)),a.push(...await Z({path:R,scope:"project",op:`${r}:remove`})),i.add(w)}catch(z){a.push(`item_format_migration_skipped:${dr(e,q)}:${Ni(z)}`)}}}return{target_format:t,scanned:c,migrated:[...i].sort((m,_)=>m.localeCompare(_)),removed:[...s].sort((m,_)=>m.localeCompare(_)),warnings:a}}(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]="f280c1df-b134-57c3-91f6-cbf5a37e6e31")}catch{}})();var Pi=new Set(["completed","superseded"]);function zi(e){return e!==void 0&&Pi.has(e)}function $i(e){if(e.type.trim().toLowerCase()!=="plan")return!1;let t=e.plan_steps??[];return t.length>0&&t.every(r=>r.status==="completed")}import pd from"node:readline/promises";(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]="6783b122-a1a8-5f86-9ac5-2c3e811622ed")}catch{}})();import at from"node:crypto";import{mkdirSync as Sd,rmSync as Vi,statSync as xd}from"node:fs";import{mkdir as it,readdir as ji,rm as ct,stat as hr}from"node:fs/promises";import{request as qi}from"node:http";import{request as Hi}from"node:https";import x 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]="26ea62d9-874d-5826-9822-83c5523b673b")}catch{}})();var Yi=x.join("runtime","telemetry","events.jsonl"),Bi=x.join("runtime","telemetry","state.json"),Wi=x.join("runtime","telemetry","otel-spans.jsonl"),Gi=8,ur=500,Ki=1;var Qi=100,Ji=36e5,Xi=3e4,lr=2e4,Zi=1e3,es=25e3,ts=864e5,gr=65536;var yr=15;var Er=[25,50,100,200],rs=3600*1e3,ns=6e4;var os="PM_TELEMETRY_DISABLED",is="PM_NO_TELEMETRY",fr=new Set(["1","true","yes","on"]);var ss="PM_TELEMETRY_HTTP_TIMEOUT_MS",as=globalThis.fetch,cs=["user","automation","test","dogfood"],zd=Promise.resolve(),mr=Promise.resolve();var $d=new Set(cs);var Fd=at.randomUUID();var wr="(?:token|secret|password|passwd|api[_-]?key|apikey|authorization|cookie|session|credentials|bearer|literals?|regex(?:es)?|replacements?)",ds=new RegExp(`\\b(${wr})\\s*([:=])\\s*([^\\s,;]+)`,"giu"),us=new RegExp(`(--${wr})(=|\\s+)([^\\s,;]+)`,"giu"),ls=/(^|[\s"'`(=])\/(?:[^\s"'`),;]+)/g,fs=/bearer\s+[a-z0-9._=-]+/giu,ms=/\b(?:10\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)|172\.(?:1[6-9]|2\d|3[01])\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)|192\.168\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.(?:25[0-5]|2[0-4]\d|[01]?\d?\d))\b/g;function ye(e){return x.join(e,Yi)}function dt(e){return x.join(e,Wi)}function ps(e){return x.dirname(ye(e))}function br(e){return x.join(e,Bi)}function Tr(e){return x.join(e,"runtime","telemetry","flush.lock")}function _s(e){return x.join(e,"runtime","telemetry","flush.spawn.lock")}async function hs(e){let t=await S(br(e));if(!t||t.trim().length===0)return{};try{let r=JSON.parse(t);return typeof r!="object"||r===null||Array.isArray(r)?{}:r}catch{return{}}}async function v(e,t){try{let n={...await hs(e),...t},o=Object.fromEntries(Object.entries(n).filter(([,i])=>i!==void 0).sort((i,s)=>i[0].localeCompare(s[0])));await T(br(e),`${JSON.stringify(o,null,2)}
11
- `)}catch{}}function Sr(e){return e.replaceAll(ds,(r,n,o)=>`${n}${o}[redacted]`).replaceAll(us,(r,n,o)=>`${n}${o}[redacted]`)}function xr(e){return e.replaceAll(ls,(t,r)=>`${r}[redacted_path]`)}function Ir(e){let t=e>=65&&e<=90,r=e>=97&&e<=122,n=e>=48&&e<=57;return t||r||n}function Ar(e){if(!e)return!1;let t=e.charCodeAt(0);return Ir(t)?!0:e==="."||e==="_"||e==="%"||e==="+"||e==="-"}function Cr(e){if(!e)return!1;let t=e.charCodeAt(0);return Ir(t)?!0:e==="."||e==="-"}function gs(e){let t=e.indexOf("@");if(t<=0||t!==e.lastIndexOf("@")||t===e.length-1)return!1;let r=e.slice(0,t),n=e.slice(t+1),o=n.lastIndexOf(".");if(o<=0||o===n.length-1||n.length-(o+1)<2)return!1;for(let i of r)if(!Ar(i))return!1;for(let i of n)if(!Cr(i))return!1;return!0}function ys(e){let t="",r=0;for(;r<e.length;){let n=e.indexOf("@",r);if(n<0){t+=e.slice(r);break}let o=n-1;for(;o>=r&&Ar(e[o]);)o-=1;o+=1;let i=n+1;for(;i<e.length&&Cr(e[i]);)i+=1;let s=e.slice(o,i);if(gs(s)){t+=e.slice(r,o),t+="[redacted_email]",r=i;continue}t+=e.slice(r,n+1),r=n+1}return t}function vr(e){return ys(e).replaceAll(fs,"bearer [redacted_token]").replaceAll(ms,"[redacted_ip]")}function Es(e){let t=vr(e),r=Sr(t),n=xr(r),o=n.trim();return o.startsWith("/")&&o.length>1?"[redacted_path]":n.length>512?`${n.slice(0,509)}...`:n}function ws(e){let t=vr(e),r=Sr(t),n=xr(r),o=n.trim();return o.startsWith("/")&&o.length>1?"[redacted_path]":n.length>2048?`${n.slice(0,2045)}...`:n}function st(e,t="redacted"){return t==="max"?ws(e):Es(e)}function pr(){let e=process.env[ss]?.trim();if(!e)return lr;let t=Number(e);return Number.isFinite(t)?Math.min(es,Math.max(Zi,Math.trunc(t))):lr}async function Lr(e,t,r){let n=new URL(e);if(globalThis.fetch!==as){let i=new AbortController,s,a=new Promise((c,d)=>{s=setTimeout(()=>{i.abort(),d(new Error("telemetry_http_timeout"))},pr())});try{return(await Promise.race([globalThis.fetch(e,{method:"POST",headers:t,body:r,signal:i.signal}),a])).status}finally{clearTimeout(s)}}let o=n.protocol==="https:"?Hi:n.protocol==="http:"?qi:void 0;if(!o)throw new Error(`telemetry_http_protocol_unsupported_${n.protocol}`);return new Promise((i,s)=>{let a=pr(),c={method:"POST",headers:{...t,"content-length":Buffer.byteLength(r)},signal:AbortSignal.timeout(a),autoSelectFamilyAttemptTimeout:Math.min(5e3,a)},d=o(n,c,u=>{u.once("error",s),u.once("end",()=>i(u.statusCode)),u.resume()});d.once("error",s),d.end(r)})}function bs(){return fr.has((process.env[os]??"").trim().toLowerCase())||fr.has((process.env[is]??"").trim().toLowerCase())}async function Ts(e){let t=await W(e),r=!1;return t.telemetry.installation_id.trim().length===0&&(t.telemetry.installation_id=at.randomUUID(),r=!0),r&&await te(e,t,"telemetry:install_id"),{installationId:t.telemetry.installation_id,endpoint:t.telemetry.endpoint,retentionDays:Math.max(1,Math.trunc(t.telemetry.retention_days))}}function Rr(e){let t=[];for(let r of e.split(`
12
- `)){let n=r.trim();if(n.length!==0)try{let o=JSON.parse(n);o&&typeof o=="object"&&o.event&&typeof o.event=="object"&&typeof o.attempts=="number"&&(o.client_schema_version===void 0||typeof o.client_schema_version=="number"&&Number.isFinite(o.client_schema_version))&&t.push(o)}catch{}}return t}function Dr(e){let t=Math.min(Xi*2**Math.max(e-1,0),Ji);return new Date(Date.now()+t).toISOString()}function kr(e){if(typeof e!="string"||e.trim().length===0)return!0;let t=Date.parse(e);return Number.isNaN(t)?!0:t<=Date.now()}function Ss(e){return kr(e.next_attempt_after)}function Mr(e){let t=Number.isFinite(e)?Math.max(1,Math.trunc(e)):1;return Date.now()-t*ts}function xs(e,t){let r=e.event?.occurred_at;if(typeof r!="string"||r.trim().length===0)return!1;let n=Date.parse(r);return Number.isNaN(n)?!1:n<t}function ut(e,t){let r=Mr(t),n=[],o=0;for(let i of e){if(JSON.stringify(i).length>gr||xs(i,r)||i.attempts>=yr){o+=1;continue}n.push(i)}return{entries:n,prunedCount:o}}async function ge(e,t){let r=t.map(o=>JSON.stringify(o)).join(`
13
- `),n=r.length>0?`${r}
14
- `:"";for(let o=0;;o+=1)try{await T(ye(e),n);return}catch(i){let s=Er[o];if(s===void 0||!Nr(i))throw i;await Or(s)}}function Nr(e){if(typeof e!="object"||e===null||!("code"in e))return!1;let t=e.code;return t==="EACCES"||t==="EBUSY"||t==="EPERM"}function Or(e){return new Promise(t=>{setTimeout(t,e)})}function Is(e){let t=JSON.stringify([e.endpoint,e.enqueued_at,e.payload]);return at.createHash("sha256").update(t).digest("hex").slice(0,32)}function Pr(e){let t=[];for(let r of e.split(`
15
- `)){let n=r.trim();if(n.length!==0)try{let o=JSON.parse(n);o&&typeof o=="object"&&typeof o.endpoint=="string"&&o.endpoint.trim().length>0&&"payload"in o&&typeof o.attempts=="number"&&Number.isFinite(o.attempts)&&((typeof o.id!="string"||o.id.length===0)&&(o.id=Is(o)),t.push(o))}catch{}}return t}function As(e,t){if(typeof e.enqueued_at!="string"||e.enqueued_at.trim().length===0)return!1;let r=Date.parse(e.enqueued_at);return Number.isNaN(r)?!1:r<t}function zr(e,t){let r=Mr(t),n=[],o=0;for(let i of e){if(JSON.stringify(i).length>gr||As(i,r)||i.attempts>=yr){o+=1;continue}n.push(i)}if(n.length>ur){let i=n.length-ur;return o+=i,{entries:n.slice(i),prunedCount:o}}return{entries:n,prunedCount:o}}async function Cs(e,t){let r=t.map(o=>JSON.stringify(o)).join(`
16
- `),n=r.length>0?`${r}
17
- `:"";for(let o=0;;o+=1)try{await T(dt(e),n);return}catch(i){let s=Er[o];if(s===void 0||!Nr(i))throw i;await Or(s)}}async function _r(e,t,r,n){return lt(async()=>{let o=await S(dt(e)),i=o===null?[]:Pr(o),s=[];for(let c of i){if(r.has(c.id))continue;let d=n.get(c.id);s.push(d?{...c,attempts:d.attempts,next_attempt_after:d.next_attempt_after}:c)}let{entries:a}=zr(s,t);return await Cs(e,a),a.length})}async function vs(e,t){let r=await S(dt(e));if(r===null||r.trim().length===0){await v(e,{pending_otel_spans:0});return}let n=Pr(r),{entries:o,prunedCount:i}=zr(n,t),s=o.filter(h=>kr(h.next_attempt_after)).slice(0,Gi);if(s.length===0){let h=i>0?await _r(e,t,new Set,new Map):o.length;await v(e,{pending_otel_spans:h});return}let a=D(),c=new Set,d=new Map,u=0,m;await Promise.all(s.map(async h=>{try{let y=await Lr(h.endpoint,{"content-type":"application/json"},JSON.stringify(h.payload));if(y<200||y>=300)throw new Error(`local_otel_export_http_${y}`);c.add(h.id),u+=1}catch(y){m=y instanceof Error?st(y.message,"redacted"):"local_otel_export_failed";let E=h.attempts+1;d.set(h.id,{attempts:E,next_attempt_after:Dr(E)})}}));let _=await _r(e,t,c,d),l={pending_otel_spans:_,last_otel_attempt_at:a};u>0&&(l.last_otel_success_at=a),m!==void 0?(l.last_otel_failure_at=a,l.last_otel_failure_error=m):_===0&&(l.last_otel_failure_at=void 0,l.last_otel_failure_error=void 0),await v(e,l)}async function Ls(e,t,r){try{await Ms(e,t,r)}catch{}try{await vs(e,r)}catch{}}async function Rs(e,t=rs){try{let r=ps(e),n=await ji(r,{withFileTypes:!0}),o=Date.now()-Math.max(0,t);await Promise.all(n.filter(i=>i.isFile()&&/^\.events\.jsonl\.\d+\.\d+\.[a-f0-9]+\.tmp$/.test(i.name)).map(async i=>{let s=x.join(r,i.name);(await hr(s)).mtimeMs<o&&await ct(s,{force:!0})}))}catch{}}async function lt(e){let t=mr.catch(()=>{}).then(e);return mr=t.catch(()=>{}),t}async function ft(e){let t=await S(ye(e));return t===null||t.trim().length===0?[]:Rr(t)}async function Ds(e,t,r){return lt(async()=>{let n=await ft(e),{entries:o}=ut(n,r),i=o.filter(s=>!t.has(s.event.event_id));return await ge(e,i),i})}async function ks(e,t,r,n){return lt(async()=>{let o=await ft(e),{entries:i}=ut(o,n),s=i.map(a=>{if(!t.has(a.event.event_id))return a;let c=a.attempts+1;return{...a,attempts:c,last_attempt_at:r,next_attempt_after:Dr(c)}});return await ge(e,s),s})}async function Ms(e,t,r){await Rs(e);let n=t.trim();if(n.length===0)return;let o=await S(ye(e));if(o===null||o.trim().length===0){await v(e,{endpoint:n,queue_entries:0});return}let i=Rr(o);if(i.length===0){await v(e,{endpoint:n,queue_entries:0});return}let{entries:s,prunedCount:a}=ut(i,r);if(s.length===0){await ge(e,[]),await v(e,{endpoint:n,queue_entries:0});return}let c=s.filter(l=>Ss(l)).slice(0,Qi);if(c.length===0){a>0&&await ge(e,s),await v(e,{endpoint:n,queue_entries:s.length});return}let d=new Set(c.map(l=>l.event.event_id)),u=D(),m={"content-type":"application/json"},_=process.env.PM_TELEMETRY_INGEST_KEY?.trim();_&&(m["x-pm-telemetry-key"]=_);try{let l=await Lr(n,m,JSON.stringify({schema_version:Ki,events:c.map(h=>h.event)}));if(l<200||l>=300)throw new Error(`telemetry_flush_http_${l}`)}catch(l){let h=await ks(e,d,u,r),y=l instanceof Error?st(l.message,"redacted"):"telemetry_flush_failed";await v(e,{endpoint:n,queue_entries:h.length,last_attempted_flush_at:u,last_failed_flush_at:u,last_failed_flush_error:y});return}try{let l=await Ds(e,d,r);await v(e,{endpoint:n,queue_entries:l.length,last_attempted_flush_at:u,last_successful_flush_at:u,last_failed_flush_at:void 0,last_failed_flush_error:void 0})}catch(l){let h=l instanceof Error?st(l.message,"redacted"):"telemetry_flush_failed",y=await ft(e).catch(()=>s);await v(e,{endpoint:n,queue_entries:y.length,last_attempted_flush_at:u,last_failed_flush_at:u,last_failed_flush_error:h})}}async function Ns(e){let t=Tr(e);await it(x.dirname(t),{recursive:!0});try{return await it(t),!0}catch(r){if(typeof r!="object"||r===null||!("code"in r)||r.code!=="EEXIST")throw r}try{let r=await hr(t);return Date.now()-r.mtimeMs<ns?!1:(await ct(t,{recursive:!0,force:!0}),await it(t),!0)}catch{return!1}}function Os(e){try{Vi(e,{recursive:!0,force:!0})}catch{}}function Ps(e){Os(_s(e))}async function zs(e,t,r){let n=await Ns(e);if(Ps(e),!!n)try{await Ls(e,t,r)}finally{try{await ct(Tr(e),{recursive:!0,force:!0})}catch{}}}async function Ud(e=Se(process.cwd())){if(!bs())try{if(!(await W(e)).telemetry.enabled)return;let{endpoint:r,retentionDays:n}=await Ts(e);await zs(e,r,n)}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]="78779372-1987-54d0-9ae4-775b52641a26")}catch{}})();export{cn as a,dn as b,ln as c,fn as d,ca as e,mn as f,pn as g,ze as h,_n as i,ya as j,gn as k,Lt as l,yn as m,En as n,Dt as o,wn as p,bn as q,Tn as r,Sn as s,Rn as t,Mn as u,Nn as v,Pn as w,zn as x,$n as y,Vn as z,va as A,Hn as B,Na as C,Gn as D,Qn as E,Ur as F,Jn as G,Xn as H,ae as I,So as J,rc as K,Ue as L,Yt as M,Ve as N,Oo as O,Po as P,ic as Q,Bt as R,V as S,qe as T,Ye as U,Ze as V,hc as W,et as X,pe as Y,Zt as Z,_e as _,tt as $,rt as aa,nt as ba,ot as ca,ir as da,sr as ea,zc as fa,Br as ga,bt as ha,Gr as ia,Kr as ja,Qr as ka,Hs as la,Bs as ma,ne as na,Pe as oa,St as pa,Tt as qa,Zr as ra,en as sa,xt as ta,nn as ua,ki as va,Oi as wa,zi as xa,$i as ya,Ki as za,yr as Aa,cs as Ba,Ud as Ca};
18
- //# sourceMappingURL=chunk-WEH6NSL6.js.map