@unbrained/pm-cli 2026.8.29 → 2026.8.31

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 (136) hide show
  1. package/.agents/skills/HARNESS_COMPATIBILITY.md +1 -1
  2. package/.agents/skills/README.md +1 -1
  3. package/.agents/skills/pm-developer/SKILL.md +1 -1
  4. package/.agents/skills/pm-developer/references/COMMAND_PLAYBOOK.md +2 -2
  5. package/.agents/skills/pm-developer/references/MULTI_AGENT_MERGE.md +1 -1
  6. package/.agents/skills/pm-developer/references/TOKEN_BUDGETS.md +1 -1
  7. package/.agents/skills/pm-extensions/SKILL.md +2 -2
  8. package/.agents/skills/pm-extensions/references/AUTHORING.md +1 -1
  9. package/.agents/skills/pm-extensions/references/LIFECYCLE.md +1 -1
  10. package/.agents/skills/pm-sdk/SKILL.md +1 -1
  11. package/.agents/skills/pm-user/SKILL.md +2 -2
  12. package/.agents/skills/pm-user/references/WORKFLOWS.md +2 -2
  13. package/.claude-plugin/marketplace.json +2 -2
  14. package/AGENTS.md +1 -1
  15. package/CHANGELOG.md +24 -0
  16. package/dist/cli/register-list-query.js +32 -17
  17. package/dist/cli/register-operations.d.ts +2 -0
  18. package/dist/cli/register-operations.js +20 -9
  19. package/dist/cli-bundle/bundle-manifest.json +137 -137
  20. package/dist/cli-bundle/chunks/chunk-2XVV45NJ.js +35 -0
  21. package/dist/cli-bundle/chunks/{chunk-N6OR6FAR.js → chunk-3FCSFWZT.js} +12 -12
  22. package/dist/cli-bundle/chunks/{chunk-WS2GJQVG.js → chunk-52JXYSDW.js} +2 -2
  23. package/dist/cli-bundle/chunks/{chunk-TGNAA66W.js → chunk-5DH5XCJL.js} +2 -2
  24. package/dist/cli-bundle/chunks/{chunk-2UETTHY6.js → chunk-IEFJ3ZEB.js} +29 -29
  25. package/dist/cli-bundle/chunks/{chunk-MTTKAUBX.js → chunk-JIFYOJF7.js} +2 -2
  26. package/dist/cli-bundle/chunks/{chunk-3TEF3HM5.js → chunk-MWIN6OH2.js} +2 -2
  27. package/dist/cli-bundle/chunks/{chunk-GNWPTEBW.js → chunk-NW6LV3TU.js} +64 -64
  28. package/dist/cli-bundle/chunks/{chunk-7SKMLSMX.js → chunk-OUGDA7NR.js} +2 -2
  29. package/dist/cli-bundle/chunks/{chunk-2MKLQL2E.js → chunk-QZCIBZR3.js} +2 -2
  30. package/dist/cli-bundle/chunks/{chunk-CMIEDWAY.js → chunk-SXMHPK4V.js} +41 -41
  31. package/dist/cli-bundle/chunks/{register-list-query-OMKJ5ONN.js → register-list-query-7C7DKZ2U.js} +11 -11
  32. package/dist/cli-bundle/chunks/{register-mutation-QBSNCOY3.js → register-mutation-OI4BJLUX.js} +2 -2
  33. package/dist/cli-bundle/chunks/register-operations-IIMA5OKO.js +2 -0
  34. package/dist/cli-bundle/chunks/{register-setup-GLQ5SYV3.js → register-setup-52H36QCB.js} +2 -2
  35. package/dist/cli-bundle/focused-chunks/{chunk-HVQ22RC4.js → chunk-2FEZ5SKM.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/{chunk-Y3JJXRVK.js → chunk-4O4CJAR6.js} +5 -5
  37. package/dist/cli-bundle/focused-chunks/{chunk-RKOKG43G.js → chunk-APN4QN6R.js} +2 -2
  38. package/dist/cli-bundle/focused-chunks/{chunk-LYFWQMVC.js → chunk-BEVHCEWG.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/{chunk-3UMBF26I.js → chunk-BMD42PUG.js} +2 -2
  40. package/dist/cli-bundle/focused-chunks/{chunk-XXOWRJZ5.js → chunk-BPWJ4QM5.js} +2 -2
  41. package/dist/cli-bundle/focused-chunks/{chunk-G6PATS5E.js → chunk-EUTABA4M.js} +15 -15
  42. package/dist/cli-bundle/focused-chunks/{chunk-73EDXGYE.js → chunk-FOMZ6NG5.js} +2 -2
  43. package/dist/cli-bundle/focused-chunks/chunk-JCOOAUHK.js +51 -0
  44. package/dist/cli-bundle/focused-chunks/chunk-JEFKLWMM.js +2 -0
  45. package/dist/cli-bundle/focused-chunks/{chunk-JZYPPMXF.js → chunk-KB5OFSFD.js} +2 -2
  46. package/dist/cli-bundle/focused-chunks/{chunk-AD6ULRAF.js → chunk-QDFJIRKN.js} +4 -4
  47. package/dist/cli-bundle/focused-chunks/{chunk-THEPQMLX.js → chunk-SVXJYD6G.js} +2 -2
  48. package/dist/cli-bundle/focused-chunks/{chunk-3AVAWVZA.js → chunk-UN34D63M.js} +2 -2
  49. package/dist/cli-bundle/focused-chunks/{chunk-TDK3OCX3.js → chunk-VJ7EFMFL.js} +2 -2
  50. package/dist/cli-bundle/main.js +2 -2
  51. package/dist/cli-bundle/sdk-authoring.js +1 -1
  52. package/dist/cli-bundle/sdk-contracts.js +1 -1
  53. package/dist/cli-bundle/sdk-core.js +29 -29
  54. package/dist/cli-bundle/sdk-governance.js +1 -1
  55. package/dist/cli-bundle/sdk-graph.js +1 -1
  56. package/dist/cli-bundle/sdk-merge.js +33 -33
  57. package/dist/cli-bundle/sdk-query.js +1 -1
  58. package/dist/cli-bundle/sdk-runtime.js +1 -1
  59. package/dist/cli-bundle/sdk-testing.js +1 -1
  60. package/dist/cli-bundle/sdk.js +9 -9
  61. package/dist/core/schema/runtime-schema.d.ts +4 -0
  62. package/dist/core/schema/runtime-schema.js +60 -48
  63. package/dist/core/schema/status-defs-file.js +5 -2
  64. package/dist/mcp/legacy-adapter.d.ts +11 -2
  65. package/dist/mcp/legacy-adapter.js +26 -12
  66. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  67. package/dist/sdk/cli-contracts/flag-contracts.js +6 -2
  68. package/dist/sdk/cli-contracts/grammar-contracts.d.ts +1 -1
  69. package/dist/sdk/cli-contracts/grammar-contracts.js +12 -2
  70. package/dist/sdk/cli-contracts/runtime-contracts.js +3 -2
  71. package/dist/sdk/cli-contracts/tool-schema.js +11 -3
  72. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +14 -2
  73. package/dist/sdk/governance/health.js +17 -6
  74. package/dist/sdk/governance/status-role-diagnostics.d.ts +27 -0
  75. package/dist/sdk/governance/status-role-diagnostics.js +36 -0
  76. package/dist/sdk/governance/validate-normalization.d.ts +6 -0
  77. package/dist/sdk/governance/validate-normalization.js +37 -0
  78. package/dist/sdk/governance/validate.d.ts +1 -1
  79. package/dist/sdk/governance/validate.js +20 -35
  80. package/dist/sdk/governance/workspace-position.d.ts +69 -0
  81. package/dist/sdk/governance/workspace-position.js +164 -0
  82. package/dist/sdk/governance.d.ts +2 -0
  83. package/dist/sdk/governance.js +4 -2
  84. package/dist/sdk/index.d.ts +1 -1
  85. package/dist/sdk/index.js +3 -3
  86. package/dist/sdk/mcp/protocol.d.ts +10 -2
  87. package/dist/sdk/mcp/protocol.js +15 -4
  88. package/dist/sdk/query/context.js +11 -14
  89. package/dist/sdk/query/list.d.ts +2 -0
  90. package/dist/sdk/query/list.js +33 -12
  91. package/dist/sdk/runtime-extended-actions.js +8 -4
  92. package/dist/sdk/schema.js +12 -2
  93. package/dist/sdk/test/execution.d.ts +15 -0
  94. package/dist/sdk/test/execution.js +35 -27
  95. package/docs/AGENT_GUIDE.md +1 -1
  96. package/docs/AGENT_PROVENANCE_ADR.md +1 -1
  97. package/docs/AGENT_RUNTIME_PRIMITIVES.md +2 -2
  98. package/docs/CLAUDE_CODE_PLUGIN.md +3 -3
  99. package/docs/COMMANDS.md +12 -12
  100. package/docs/CONFIGURATION.md +1 -1
  101. package/docs/DEFECT_RECURRENCE.md +2 -0
  102. package/docs/MCP_2026_07_28.md +28 -8
  103. package/docs/MCP_2026_07_28_CONFORMANCE.md +1 -0
  104. package/docs/MCP_REMOTE_TRANSPORT_SECURITY.md +4 -2
  105. package/docs/ONBOARDING.md +1 -1
  106. package/docs/README.md +2 -1
  107. package/docs/READ_OUTPUT_CONTRACTS.md +1 -1
  108. package/docs/RECURRENCE_RECOVERY_CONTRACTS.md +1 -1
  109. package/docs/SDK.md +3 -3
  110. package/docs/TESTING.md +23 -14
  111. package/docs/WORKSPACE_POSITION_AND_LIFECYCLE.md +113 -0
  112. package/docs/examples/policy-restricted-extension/README.md +2 -2
  113. package/docs/examples/starter-extension/README.md +1 -1
  114. package/docs/generated/REFUSAL_CLOSURE_CENSUS.md +4 -3
  115. package/marketplace.json +2 -2
  116. package/package.json +4 -4
  117. package/packages/pm-beads/package.json +1 -1
  118. package/packages/pm-calendar/package.json +1 -1
  119. package/packages/pm-command-kit/package.json +1 -1
  120. package/packages/pm-digital-twin/package.json +1 -1
  121. package/packages/pm-governance-audit/package.json +1 -1
  122. package/packages/pm-guide-shell/package.json +1 -1
  123. package/packages/pm-kanban/package.json +1 -1
  124. package/packages/pm-lifecycle-hooks/package.json +1 -1
  125. package/packages/pm-linked-test-adapters/package.json +1 -1
  126. package/packages/pm-search-advanced/package.json +1 -1
  127. package/packages/pm-templates/package.json +1 -1
  128. package/packages/pm-todos/package.json +1 -1
  129. package/packages/pm-vcs/package.json +1 -1
  130. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  131. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  132. package/sdk/public-surface.json +171 -10
  133. package/dist/cli-bundle/chunks/chunk-7X6OZEIV.js +0 -34
  134. package/dist/cli-bundle/chunks/register-operations-UC77FQZC.js +0 -2
  135. package/dist/cli-bundle/focused-chunks/chunk-AXZ5AJAF.js +0 -50
  136. package/dist/cli-bundle/focused-chunks/chunk-LLNTHF5X.js +0 -2
@@ -1,4 +1,4 @@
1
- import{Ab as G,Cb as ke,Da as te,Ja as at,La as fe,Ma as Zt,Na as z,Oa as Ae,Sa as ve,Ua as ct,Xa as er,Y as Ie,Z as v,da as xe,ea as Qt,eb as tr,fa as Jt,fb as Ce,gb as C,hb as Re,l as ce,lb as dt,mb as re,o as q,oa as de,qa as ot,qb as lt,ta as it,tb as ut,ua as le,ub as ft,va as st,vb as mt,wa as ue,yb as rr,zb as B}from"./chunk-3UMBF26I.js";import{H as F,N as H,P as tt,Q as rt,R as se,S as Kt,T as Se,Ta as Te,W as w,Y as ae,Z as ee,_ as b,a as Ze,aa as Xt,r as P,t as Z,u as T,v as S,x as be}from"./chunk-AD6ULRAF.js";import{S as et,Y as u,Z as f,ba as nt}from"./chunk-Z2USIBR2.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 Mn(e,t="--limit"){if(e===void 0)return;let r=Number(e);if(!Number.isFinite(r)||r<0)throw new f(`${t} must be a non-negative number`,u.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 Nn=/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/,On=/\bnpm_[A-Za-z0-9]{36}\b/,Pn=/\bxox[baprs]-(?=[A-Za-z0-9-]{20,80}\b)(?=[A-Za-z0-9-]*\d)[A-Za-z0-9-]{20,80}\b/,$n=/-----BEGIN (?:[A-Z0-9]+ )?PRIVATE KEY-----/,Fn=/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/,nr=/\b(?:token|secret|password|passwd|api[_-]?key)\s*[:=]\s*["']?([A-Za-z0-9+/=_-]{24,})/gi,zn=[{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"}],ht=new Map(zn.map(e=>[e.action,e]));function Un(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 pt(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)=>pt(n,`${t}[${o}]`,r)):Object.entries(e).flatMap(([n,o])=>pt(o,`${t}.${n}`,r)))}function or(e){let t=[];for(let r of pt(e)){Nn.test(r.value)&&t.push({rule:"github_token",path:r.path}),On.test(r.value)&&t.push({rule:"npm_token",path:r.path}),Pn.test(r.value)&&t.push({rule:"slack_token",path:r.path}),$n.test(r.value)&&t.push({rule:"private_key",path:r.path}),Fn.test(r.value)&&t.push({rule:"aws_access_key",path:r.path}),nr.lastIndex=0;for(let n of r.value.matchAll(nr)){let o=n[1];if(Un(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 Vn(e){let t=e.author.trim()||"unknown";if(e.settings.require_attributed_author&&t.toLowerCase()==="unknown")throw new f("Mutation author is required by workspace policy.",u.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=or(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 f(`Mutation blocked by secret guard (${n}). No detected value was logged.`,u.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 jn(e){return ht.has(e.trim().toLowerCase())}function Hn(){return[...ht.keys()].sort((e,t)=>e.localeCompare(t))}function mc(e){return ht.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 qn(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function hc(e){return qn(e).split(/[^a-z0-9]+/).filter(t=>t.length>0)}function me(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 Bn=/\b[a-z][a-z0-9]*-\d+(?:-[a-z0-9]+)*\b/giu;function De(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function he(e){return[...new Set(De(e).match(/[\p{L}\p{N}]+/gu)??[])]}function pe(e){let t=De(e);return{normalized:t,tokens:he(t),issueCodes:[...new Set(t.match(Bn)?.map(r=>r.toLowerCase())??[])]}}function Le(e,t){return Me(pe(e),pe(t))}function Me(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:me(e.tokens,t.tokens),reason:"title_token_jaccard"}}import Gn 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 Ne(e){return(e??"in_progress").trim().toLowerCase().replaceAll("-","_")}function Yn(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 ir(e,t){let r=Math.max(1,Math.trunc(t.threshold_hours)),n=(t.now??new Date).getTime(),o=Ne(t.in_progress_status),i=[];for(let s of e){if(Ne(String(s.status))!==o||(s.assignee?.trim().length??0)>0)continue;let a=Yn(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 Wn(e,t,r){let n=new Map;return await Promise.all(t.filter(o=>Ne(String(o.status))===Ne(r.in_progress_status)&&(o.assignee?.trim().length??0)===0).map(async o=>{let i;try{i=await ue(Gn.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)})),ir(t,{...r,last_history_activity:o=>n.get(o.id)})}import{mkdir as Kn,readFile as Xn}from"node:fs/promises";import sr 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 Qn(e){let t=e.trim();if(!t)throw new f("--rollback requires a non-empty checkpoint ID",u.USAGE);if(!/^[a-zA-Z0-9._-]+$/.test(t))throw new f("--rollback checkpoint ID must match [a-zA-Z0-9._-]+",u.USAGE);return t}function Jn(e,t){let r=t.replace(/[-:.TZ]/g,"").slice(0,14),n=Math.random().toString(36).slice(2,8);return`${e}-${r}-${n}`}function ar(e,t){return sr.join(e,"checkpoints",t)}function cr(e,t,r){return sr.join(ar(e,t),`${r}.json`)}async function Zn(e,t,r,n){let o=ar(e,t);await Kn(o,{recursive:!0});let i=cr(e,t,r);return await S(i,`${JSON.stringify(n,null,2)}
1
+ import{Ab as G,Cb as ke,Da as te,Ja as at,La as fe,Ma as Zt,Na as z,Oa as Ae,Sa as ve,Ua as ct,Xa as er,Y as Ie,Z as v,da as xe,ea as Qt,eb as tr,fa as Jt,fb as Ce,gb as C,hb as Re,l as ce,lb as dt,mb as re,o as q,oa as de,qa as ot,qb as lt,ta as it,tb as ut,ua as le,ub as ft,va as st,vb as mt,wa as ue,yb as rr,zb as B}from"./chunk-BMD42PUG.js";import{H as F,N as H,P as tt,Q as rt,R as se,S as Kt,T as Se,Ta as Te,W as w,Y as ae,Z as ee,_ as b,a as Ze,aa as Xt,r as P,t as Z,u as T,v as S,x as be}from"./chunk-QDFJIRKN.js";import{S as et,Y as u,Z as f,ba as nt}from"./chunk-Z2USIBR2.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 Mn(e,t="--limit"){if(e===void 0)return;let r=Number(e);if(!Number.isFinite(r)||r<0)throw new f(`${t} must be a non-negative number`,u.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 Nn=/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/,On=/\bnpm_[A-Za-z0-9]{36}\b/,Pn=/\bxox[baprs]-(?=[A-Za-z0-9-]{20,80}\b)(?=[A-Za-z0-9-]*\d)[A-Za-z0-9-]{20,80}\b/,$n=/-----BEGIN (?:[A-Z0-9]+ )?PRIVATE KEY-----/,Fn=/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/,nr=/\b(?:token|secret|password|passwd|api[_-]?key)\s*[:=]\s*["']?([A-Za-z0-9+/=_-]{24,})/gi,zn=[{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"}],ht=new Map(zn.map(e=>[e.action,e]));function Un(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 pt(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)=>pt(n,`${t}[${o}]`,r)):Object.entries(e).flatMap(([n,o])=>pt(o,`${t}.${n}`,r)))}function or(e){let t=[];for(let r of pt(e)){Nn.test(r.value)&&t.push({rule:"github_token",path:r.path}),On.test(r.value)&&t.push({rule:"npm_token",path:r.path}),Pn.test(r.value)&&t.push({rule:"slack_token",path:r.path}),$n.test(r.value)&&t.push({rule:"private_key",path:r.path}),Fn.test(r.value)&&t.push({rule:"aws_access_key",path:r.path}),nr.lastIndex=0;for(let n of r.value.matchAll(nr)){let o=n[1];if(Un(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 Vn(e){let t=e.author.trim()||"unknown";if(e.settings.require_attributed_author&&t.toLowerCase()==="unknown")throw new f("Mutation author is required by workspace policy.",u.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=or(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 f(`Mutation blocked by secret guard (${n}). No detected value was logged.`,u.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 jn(e){return ht.has(e.trim().toLowerCase())}function Hn(){return[...ht.keys()].sort((e,t)=>e.localeCompare(t))}function mc(e){return ht.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 qn(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function hc(e){return qn(e).split(/[^a-z0-9]+/).filter(t=>t.length>0)}function me(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 Bn=/\b[a-z][a-z0-9]*-\d+(?:-[a-z0-9]+)*\b/giu;function De(e){return e.trim().toLowerCase().replace(/\s+/g," ")}function he(e){return[...new Set(De(e).match(/[\p{L}\p{N}]+/gu)??[])]}function pe(e){let t=De(e);return{normalized:t,tokens:he(t),issueCodes:[...new Set(t.match(Bn)?.map(r=>r.toLowerCase())??[])]}}function Le(e,t){return Me(pe(e),pe(t))}function Me(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:me(e.tokens,t.tokens),reason:"title_token_jaccard"}}import Gn 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 Ne(e){return(e??"in_progress").trim().toLowerCase().replaceAll("-","_")}function Yn(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 ir(e,t){let r=Math.max(1,Math.trunc(t.threshold_hours)),n=(t.now??new Date).getTime(),o=Ne(t.in_progress_status),i=[];for(let s of e){if(Ne(String(s.status))!==o||(s.assignee?.trim().length??0)>0)continue;let a=Yn(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 Wn(e,t,r){let n=new Map;return await Promise.all(t.filter(o=>Ne(String(o.status))===Ne(r.in_progress_status)&&(o.assignee?.trim().length??0)===0).map(async o=>{let i;try{i=await ue(Gn.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)})),ir(t,{...r,last_history_activity:o=>n.get(o.id)})}import{mkdir as Kn,readFile as Xn}from"node:fs/promises";import sr 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 Qn(e){let t=e.trim();if(!t)throw new f("--rollback requires a non-empty checkpoint ID",u.USAGE);if(!/^[a-zA-Z0-9._-]+$/.test(t))throw new f("--rollback checkpoint ID must match [a-zA-Z0-9._-]+",u.USAGE);return t}function Jn(e,t){let r=t.replace(/[-:.TZ]/g,"").slice(0,14),n=Math.random().toString(36).slice(2,8);return`${e}-${r}-${n}`}function ar(e,t){return sr.join(e,"checkpoints",t)}function cr(e,t,r){return sr.join(ar(e,t),`${r}.json`)}async function Zn(e,t,r,n){let o=ar(e,t);await Kn(o,{recursive:!0});let i=cr(e,t,r);return await S(i,`${JSON.stringify(n,null,2)}
2
2
  `),i}function eo(e,t){if(!Array.isArray(e.items))throw new f(`Checkpoint ${t} is missing items`,u.GENERIC_FAILURE);return e.items.map(r=>{if(!r||typeof r!="object")throw new f(`Checkpoint ${t} contains an invalid item entry`,u.GENERIC_FAILURE);let n=r;if(typeof n.id!="string"||n.id.trim().length===0)throw new f(`Checkpoint ${t} contains an item entry without ID`,u.GENERIC_FAILURE);if(typeof n.target_updated_at!="string"||n.target_updated_at.trim().length===0)throw new f(`Checkpoint ${t} contains an item entry without target_updated_at`,u.GENERIC_FAILURE);return{id:n.id.trim(),target_updated_at:n.target_updated_at.trim()}})}async function to(e,t,r,n){let o=Qn(r),i=cr(e,t,o);if(!await P(i))throw new f(`Checkpoint ${o} not found`,u.NOT_FOUND);let s=await Xn(i,"utf8"),a;try{a=JSON.parse(s)}catch(l){throw new f(`Checkpoint ${o} contains invalid JSON: ${b(l)}`,u.GENERIC_FAILURE)}if(!a||typeof a!="object")throw new f(`Checkpoint ${o} is invalid`,u.GENERIC_FAILURE);let c=a;if(c.schema_version!==n)throw new f(`Checkpoint ${o} has unsupported schema version`,u.GENERIC_FAILURE);let d=eo(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:v(),author:typeof c.author=="string"?c.author:"unknown"}}async function ro(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 U(e){if(typeof e!="string")return null;let t=e.trim().toLowerCase();return t.length>0?t:null}function Dc(e,t){let r=U(t);return!e||!r?null:[...e.assurance_providers??[]].reverse().find(n=>U(n.definition.id)===r)??null}function no(e,t){let r=U(t);return!e||!r?null:[...e.search_providers].reverse().find(o=>(U(o.runtime_definition?.name)??U(o.definition?.name))===r)??null}function oo(e,t){let r=U(t);return!e||!r?null:[...e.vector_store_adapters].reverse().find(o=>(U(o.runtime_definition?.name)??U(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]="80965b57-856c-5fef-a372-0c9f3766ada5")}catch{}})();var $="-",lr=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 Oc(e,t){if(e.startsWith("```")||e.includes(`
3
3
  `))return!0;let r=t.map(n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|");return new RegExp(`^(?:[-*+]\\s+)?(?:${r})\\s*[:=]`,"i").test(e)}function ur(e){let t=e.trim();if(t==="")return[];let n=(lo(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 fr(e){if(!Array.isArray(e)||e.length===0)return[];let t=[];for(let r of e)if(typeof r=="string")for(let n of ur(r))t.push(n);return Array.from(new Set(t)).sort((r,n)=>r.localeCompare(n))}function mr(e){return Array.isArray(e)?e.filter(t=>typeof t=="string").map(t=>t.trim().toLowerCase()).filter(Boolean):[]}function io(e){return typeof e!="string"?[]:e.split(";").map(t=>t.trim()).filter(Boolean)}function so(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 f('Acceptance criteria added with --add-ac cannot contain ";" because semicolons delimit stored criteria',u.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 ao(e,t){let r=mr(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 fr(t))n.add(o);return Array.from(n).sort((o,i)=>o.localeCompare(i))}function co(e,t){let r=Array.from(new Set(mr(e))).sort((o,i)=>o.localeCompare(i));if(!t||t.length===0)return r;let n=new Set(fr(t));return n.size===0?r:r.filter(o=>!n.has(o))}function lo(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 _t(e){return e.replace(/\r\n/g,`
4
4
  `)}function pr(e){let t=_t(e).trim();if(!t.startsWith("```"))return e;let r=t.split(`
@@ -17,4 +17,4 @@ ${i}`;continue}return null}return r}function ho(e,t){let r=pr(e).trim();if(!r)th
17
17
  `)){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=ya(o)),t.push(o))}catch{}}return t}function ga(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 bn(e,t){let r=yn(t),n=[],o=0;for(let i of e){if(JSON.stringify(i).length>en||ga(i,r)||i.attempts>=tn){o+=1;continue}n.push(i)}if(n.length>Yr){let i=n.length-Yr;return o+=i,{entries:n.slice(i),prunedCount:o}}return{entries:n,prunedCount:o}}async function wa(e,t){let r=t.map(o=>JSON.stringify(o)).join(`
18
18
  `),n=r.length>0?`${r}
19
19
  `:"";for(let o=0;;o+=1)try{await S(Ht(e),n);return}catch(i){let s=rn[o];if(s===void 0||!gn(i))throw i;await wn(s)}}async function Jr(e,t,r,n){return Bt(async()=>{let o=await T(Ht(e)),i=o===null?[]:En(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}=bn(s,t);return await wa(e,a),a.length})}async function Ea(e,t){let r=await T(Ht(e));if(r===null||r.trim().length===0){await N(e,{pending_otel_spans:0});return}let n=En(r),{entries:o,prunedCount:i}=bn(n,t),s=o.filter(_=>_n(_.next_attempt_after)).slice(0,Us);if(s.length===0){let _=i>0?await Jr(e,t,new Set,new Map):o.length;await N(e,{pending_otel_spans:_});return}let a=v(),c=new Set,d=new Map,l=0,m;await Promise.all(s.map(async _=>{try{let y=await mn(_.endpoint,{"content-type":"application/json"},JSON.stringify(_.payload));if(y<200||y>=300)throw new Error(`local_otel_export_http_${y}`);c.add(_.id),l+=1}catch(y){m=y instanceof Error?Ut(y.message,"redacted"):"local_otel_export_failed";let g=_.attempts+1;d.set(_.id,{attempts:g,next_attempt_after:hn(g)})}}));let h=await Jr(e,t,c,d),p={pending_otel_spans:h,last_otel_attempt_at:a};l>0&&(p.last_otel_success_at=a),m!==void 0?(p.last_otel_failure_at=a,p.last_otel_failure_error=m):h===0&&(p.last_otel_failure_at=void 0,p.last_otel_failure_error=void 0),await N(e,p)}async function ba(e,t,r){try{await xa(e,t,r)}catch{}try{await Ea(e,r)}catch{}}async function Sa(e,t=Ws){try{let r=sa(e),n=await Ns(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=k.join(r,i.name);(await Zr(s)).mtimeMs<o&&await jt(s,{force:!0})}))}catch{}}async function Bt(e){let t=Xr.catch(()=>{}).then(e);return Xr=t.catch(()=>{}),t}async function Gt(e){let t=await T(Xe(e));return t===null||t.trim().length===0?[]:pn(t)}async function Ta(e,t,r){return Bt(async()=>{let n=await Gt(e),{entries:o}=qt(n,r),i=o.filter(s=>!t.has(s.event.event_id));return await Ke(e,i),i})}async function Ia(e,t,r,n){return Bt(async()=>{let o=await Gt(e),{entries:i}=qt(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:hn(c)}});return await Ke(e,s),s})}async function xa(e,t,r){await Sa(e);let n=t.trim();if(n.length===0)return;let o=await T(Xe(e));if(o===null||o.trim().length===0){await N(e,{endpoint:n,queue_entries:0});return}let i=pn(o);if(i.length===0){await N(e,{endpoint:n,queue_entries:0});return}let{entries:s,prunedCount:a}=qt(i,r);if(s.length===0){await Ke(e,[]),await N(e,{endpoint:n,queue_entries:0});return}let c=s.filter(p=>ha(p)).slice(0,js);if(c.length===0){a>0&&await Ke(e,s),await N(e,{endpoint:n,queue_entries:s.length});return}let d=new Set(c.map(p=>p.event.event_id)),l=v(),m={"content-type":"application/json"},h=process.env.PM_TELEMETRY_INGEST_KEY?.trim();h&&(m["x-pm-telemetry-key"]=h);try{let p=await mn(n,m,JSON.stringify({schema_version:Vs,events:c.map(_=>_.event)}));if(p<200||p>=300)throw new Error(`telemetry_flush_http_${p}`)}catch(p){let _=await Ia(e,d,l,r),y=p instanceof Error?Ut(p.message,"redacted"):"telemetry_flush_failed";await N(e,{endpoint:n,queue_entries:_.length,last_attempted_flush_at:l,last_failed_flush_at:l,last_failed_flush_error:y});return}try{let p=await Ta(e,d,r);await N(e,{endpoint:n,queue_entries:p.length,last_attempted_flush_at:l,last_successful_flush_at:l,last_failed_flush_at:void 0,last_failed_flush_error:void 0})}catch(p){let _=p instanceof Error?Ut(p.message,"redacted"):"telemetry_flush_failed",y=await Gt(e).catch(()=>s);await N(e,{endpoint:n,queue_entries:y.length,last_attempted_flush_at:l,last_failed_flush_at:l,last_failed_flush_error:_})}}async function Aa(e){let t=sn(e);await zt(k.dirname(t),{recursive:!0});try{return await zt(t),!0}catch(r){if(typeof r!="object"||r===null||!("code"in r)||r.code!=="EEXIST")throw r}try{let r=await Zr(t);return Date.now()-r.mtimeMs<Ks?!1:(await jt(t,{recursive:!0,force:!0}),await zt(t),!0)}catch{return!1}}function va(e){try{Ms(e,{recursive:!0,force:!0})}catch{}}function Ca(e){va(aa(e))}async function Ra(e,t,r){let n=await Aa(e);if(Ca(e),!!n)try{await ba(e,t,r)}finally{try{await jt(sn(e),{recursive:!0,force:!0})}catch{}}}async function gu(e=tt(process.cwd())){if(!ma())try{if(!(await C(e)).telemetry.enabled)return;let{endpoint:r,retentionDays:n}=await pa(e);await Ra(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]="d45775e5-6826-521b-80b3-429ed22947d9")}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]="13c02696-29a7-598e-888a-3502fd88bfbe")}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]="33a43890-abcf-58fc-bf9d-bf2619d4cf35")}catch{}})();var ka=3,Sn=20,Da=.8,La=100,Tn=1e3,In=1e6;function Nh(e){return e===void 0?[]:[`likely_duplicates:${e.result.items.map(t=>t.id).join(",")}`,`likely_duplicate_recovery:${e.recovery.action}:${e.recovery.item_id}`]}async function Ma(e,t){let r=e.items[0],n=H(t.cwd??process.cwd(),t.pmRoot),o=Te((await C(n)).schema);return ot(r.status,o)?{action:"reopen",item_id:r.id,command:`pm item reopen ${r.id} "<recurrence reason>"`,args:["item","reopen",r.id,"<recurrence reason>"]}:{action:"reuse",item_id:r.id,command:`pm get ${r.id} --full`,args:["get",r.id,"--full"]}}function xn(e){let t=e.limit??ka,r=e.threshold??Da;if(!Number.isSafeInteger(t)||t<0||t>Sn)throw new f(`Similarity limit must be an integer from 0 to ${Sn}.`,u.USAGE);if(!Number.isFinite(r)||r<0||r>1)throw new f("Similarity threshold must be a number from 0 to 1.",u.USAGE);return{limit:t,threshold:r}}function Na(e){let t=e.limit??La;if(!Number.isSafeInteger(t)||t<0||t>Tn)throw new f(`Duplicate cluster limit must be an integer from 0 to ${Tn}.`,u.USAGE);let r=e.since===void 0?void 0:new Date(e.since);if(r&&Number.isNaN(r.getTime()))throw new f("Duplicate cluster --since must be a valid ISO timestamp.",u.USAGE);return{limit:t,since:r}}async function Oa(e,t){let r=H(e.cwd??process.cwd(),e.pmRoot),n=await C(r),o=F(n),i=e.statuses?.map(m=>m.trim().toLowerCase()).filter(Boolean);if(e.statuses!==void 0&&i?.length===0)throw new f("Duplicate cluster statuses must include at least one lifecycle status or all.",u.USAGE);let s=Te(n.schema),a=i?.map(m=>{if(m==="all")return m;let h=de(m,s);if(!h)throw new f(`Unknown duplicate-cluster status "${m}". Allowed: all, ${s.definitions.map(p=>p.id).join(", ")}.`,u.USAGE);return h}),c=a?.includes("all")===!0;if(c&&a?.some(m=>m!=="all"))throw new f('The "all" status cannot be combined with other statuses.',u.USAGE);let d=c?void 0:a,l=d?new Set(d):void 0;return{items:(await ke(r,n.item_format,o.type_to_folder,void 0,n.schema)).filter(m=>(!l||l.has(m.status))&&(!t||new Date(m.created_at).getTime()>=t.getTime())).sort((m,h)=>m.id.localeCompare(h.id)).map(m=>({item:m,prepared:pe(m.title)})),statuses:d}}function An(e,t=In){let r=new Set,n=[new Map,new Map,new Map];for(let[o,i]of e.entries()){let s=[[i.prepared.normalized],i.prepared.issueCodes,i.prepared.tokens];for(let[a,c]of s.entries())for(let d of c){let l=n[a].get(d)??[];for(let m of l)r.add(`${m}:${o}`);if(r.size>t)throw new f(`Duplicate sweep exceeded ${In} candidate pairs; narrow it with statuses or since.`,u.CONFLICT,{code:"duplicate_sweep_cost_limit",required:"Narrow the batch duplicate query until its deterministic candidate set fits the disclosed safety bound."});l.push(o),n[a].set(d,l)}}return r}var Oh={buildDuplicateClusters:Cn,collectDuplicateCandidatePairs:An,createDuplicateUnionFind:vn};function vn(e){let t=Array.from({length:e},(n,o)=>o);return{parent:t,findRoot:n=>{let o=n;for(;t[o]!==o;)o=t[o];for(;t[n]!==n;){let i=t[n];t[n]=o,n=i}return o}}}function Pa(e,t,r,n){let o=[];for(let i of t){let[s,a]=i.split(":").map(m=>Number.parseInt(m,10)),c=Me(e[s].prepared,e[a].prepared);if(c.score<r)continue;let d=n.findRoot(s),l=n.findRoot(a);d!==l&&(n.parent[l]=d),o.push({left_id:e[s].item.id,right_id:e[a].item.id,...c})}return o}function Cn(e,t,r,n){let o=new Map;for(let i of e.keys()){let s=r.findRoot(i),a=o.get(s)??[];a.push(i),o.set(s,a)}return[...o.values()].filter(i=>i.length>1).map(i=>{let s=new Set(i.map(c=>e[c].item.id)),a=t.filter(c=>s.has(c.left_id)&&s.has(c.right_id)).sort((c,d)=>d.score-c.score||c.left_id.localeCompare(d.left_id)||c.right_id.localeCompare(d.right_id));return{id:e[i[0]].item.id,items:i.map(c=>{let d=e[c].item;return{id:d.id,title:d.title,status:d.status,type:d.type}}),matches:a,max_score:a[0]?.score??0}}).sort((i,s)=>s.max_score-i.max_score||i.id.localeCompare(s.id)).slice(0,n)}function $a(e,t,r,n,o){return t.filter(i=>!r.has(i.id)).map(i=>({id:i.id,title:i.title,status:i.status,type:i.type,...Le(e,i.title)})).filter(i=>i.score>=n).sort((i,s)=>s.score-i.score||i.id.localeCompare(s.id)).slice(0,o)}async function Fa(e,t={}){let r=e.title.trim();if(r.length===0)throw new f("Similarity candidate title must not be empty.",u.USAGE);let{limit:n,threshold:o}=xn(t),i=H(t.cwd??process.cwd(),t.pmRoot),s=await C(i),a=F(s),c=await ft(i,Object.values(a.type_to_folder)),d=he(r),l=c&&d.length>0?await lt({pmRoot:i,expectedSourceCursor:c.source_cursor,query:d.map(p=>`"${p.replaceAll('"','""')}"`).join(" OR "),limit:Math.max(n*10,50)}):null,m=l===null?await ke(i,s.item_format,a.type_to_folder,void 0,s.schema):l.items,h=$a(r,m,new Set(e.excludeIds??[]),o,n);return{items:h,count:h.length,threshold:o,source:l?"persistent_index":"metadata_fallback"}}async function Ph(e={}){let{threshold:t}=xn({...e,limit:void 0}),{limit:r,since:n}=Na(e),{items:o,statuses:i}=await Oa(e,n),s=An(o),a=vn(o.length),c=Pa(o,s,t,a),d=Cn(o,c,a,r);return{clusters:d,count:d.length,threshold:t,source:"metadata_scan",filters:{statuses:i??null,since:e.since??null},cost:{item_count:o.length,candidate_pairs:s.size,scored_pairs:s.size}}}async function $h(e,t){if(t.mode==="off")return;let r=await Fa(e,t);if(r.count===0)return;let n=await Ma(r,t),o=t.mode==="strict"&&t.allowDuplicate===!0;if(t.mode==="strict"&&!o){let i=r.items.map(a=>`${a.id} (${a.status}): ${a.title}`).join("; "),s=n.action==="reopen"?"Reopen the canonical item":"Reuse the canonical item";throw new f(`Likely duplicate item(s) found: ${i}. ${s} or pass --allow-duplicate with explicit intent.`,u.CONFLICT,{code:"likely_duplicate",required:`${s}, or explicitly acknowledge the duplicate with --allow-duplicate.`,recovery:{suggested_flags:["--allow-duplicate"],suggested_retry:n.command,suggested_retry_args:n.args}})}return{mode:t.mode,bypassed:o,result:r,recovery: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]="47c087c2-124a-58b7-a5c9-09403235f4a2")}catch{}})();function za(e,t){let r=-1;return e.forEach((n,o)=>{let i=Date.parse(n.ts);if(!Number.isFinite(i))throw new f(`History for this item contains invalid timestamp at entry ${o+1}.`,u.GENERIC_FAILURE);i<=t&&(r=o)}),r}function Ua(e){let t=e[0]?.ts??null,r=e.at(-1)?.ts??null,n={code:"history_target_out_of_range",required:"Choose a target within the available item history.",why:"Point-in-time reads and restores can only reconstruct recorded versions.",examples:[],nextSteps:["Run pm history <id> to inspect available versions and timestamps."],valid_range:{first_version:null,last_version:null,first_timestamp:t,last_timestamp:r}};return r!==null&&(n.examples=["1",String(e.length),r],n.valid_range.first_version=1,n.valid_range.last_version=e.length),{guidance:n,lastTimestamp:r}}function Va(e,t){let r={};if(t instanceof Error&&t.message.trim().length>0&&(r.reason=t.message.trim()),typeof t!="object"||t===null)return r;let n=t;if(typeof n.index=="number"&&Number.isInteger(n.index)&&n.index>=0&&(r.patchIndex=n.index),typeof n.operation=="object"&&n.operation!==null){let o=n.operation;Object.assign(r,Object.fromEntries(["op","path","from"].flatMap(i=>{let s=o[i];return typeof s=="string"?[[i,s]]:[]})))}if(r.patchIndex!==void 0){let o=e[r.patchIndex];o&&(r.op??=o.op,r.path??=o.path,r.from??=o.from)}return r}function Hh(e,t,r={}){let n=e.trim(),o=r.errorSubject??"history",i=o==="restore"?"Restore":"History",{guidance:s,lastTimestamp:a}=Ua(t);if(!n)throw new f(`Missing ${o} target. Use a timestamp or version number.`,u.USAGE,s);if(/^\d+$/.test(n)){let l=Number(n);if(!Number.isSafeInteger(l)||l<1||l>t.length)throw new f(`${i} version must be between 1 and ${t.length} for this item.`,u.USAGE,s);return{kind:"version",raw:n,historyIndex:l-1}}let c=Date.parse(n);if(!Number.isFinite(c))throw new f(`Invalid ${o} target "${e}". Use a positive version number or ISO timestamp.`,u.USAGE,s);let d=za(t,c);if(d<0||r.allowFutureTimestamp!==!0&&c>Date.parse(a))throw new f(o==="restore"?`No history entries exist at or before timestamp ${n}.`:`No history entry exists at timestamp ${n}.`,u.USAGE,s);return{kind:"timestamp",raw:n,historyIndex:d}}function Qe(e,t,r,n){let o=ve(e,t);if(o.ok)return o.document;let i=Va(t,o.error),s=[`history_op=${n}`,i.patchIndex===void 0?null:`patch_index=${i.patchIndex}`,i.op?`op=${i.op}`:null,i.path?`path=${i.path}`:null,i.from?`from=${i.from}`:null].filter(a=>a!==null);throw new f(`Failed to apply history patch at entry ${r} (${s.join(", ")}). ${i.reason??String(o.error)}`,u.GENERIC_FAILURE)}function qh(e,t){let r=structuredClone(fe);for(let n=0;n<=t;n+=1){let o=e[n];if(!o)throw new f(`History target entry ${n+1} does not exist.`,u.USAGE);if(z(r)!==o.before_hash)throw new f(`History hash mismatch before replay at entry ${n+1}.`,u.GENERIC_FAILURE);if(r=Qe(r,o.patch,n+1,o.op),z(r)!==o.after_hash)throw new f(`History hash mismatch after replay at entry ${n+1}.`,u.GENERIC_FAILURE)}return r}function Bh(e,t){if(Object.keys(e.metadata).length>0)return e;throw new f(`History target ${t.raw} resolves to a deleted state; choose a version or timestamp where the item exists.`,u.USAGE)}import Yt from"node:fs/promises";import ja from"node:fs/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]="a2ec9f1a-aae2-59d5-8c9a-7acd8bf5a7a2")}catch{}})();function Ha(e){if(!e.itemDocument)return[];let t=e.itemDocument.metadata?.assignee?.trim();if(!t||t===e.author||e.force)return[];let r=tr(e.settings);if(r.ownership_enforcement==="strict")throw new f(`Item ${e.subjectId} is assigned to ${t}. Use --force to override.`,u.CONFLICT);return r.ownership_enforcement==="warn"?[`ownership_warning:assignee_conflict:${e.subjectId}:${t}`]:[]}async function qa(e){let t=await T(e.subject.historyPath);if(t!==e.historyRawBeforeLock)throw new f(`History for ${e.subject.id} changed while waiting for lock; retry ${e.operation}.`,u.CONFLICT);let r=await B(e.pmRoot,e.subject.id,e.settings.id_prefix,e.settings.item_format,e.typeRegistry.type_to_folder),n=r?await G(r,{schema:e.settings.schema}):null;if((n?.raw??null)!==(e.currentItemRawBeforeLock??null))throw new f(`Item ${e.subject.id} changed while waiting for lock; retry ${e.operation}.`,u.CONFLICT);return{historyRawUnderLock:t,locatedUnderLock:r,loadedItemUnderLock:n}}async function t_(e){let t=e.writeHistoryRaw??S;try{await t(e.historyPath,e.nextHistoryRaw),await te(e.historyPath)}catch(r){try{e.historyRawUnderLock===null?await ja.rm(e.historyPath,{force:!0}):await t(e.historyPath,e.historyRawUnderLock),await te(e.historyPath)}catch(n){throw new AggregateError([r,n],`History rewrite failed and rollback also failed: ${String(r)}`)}throw r}}async function Rn(e){let t=[...Ha({itemDocument:e.itemDocument,subjectId:e.subject.id,author:e.author,force:e.force,settings:e.settings})],r=await xe(e.pmRoot,e.subject.id,e.settings.locks.ttl_seconds,e.author,!!e.force,e.settings.governance.force_required_for_stale_lock,e.settings.locks.wait_ms);try{let n=await qa({pmRoot:e.pmRoot,subject:e.subject,settings:e.settings,typeRegistry:e.typeRegistry,historyRawBeforeLock:e.historyRawBeforeLock,currentItemRawBeforeLock:e.currentItemRawBeforeLock,operation:e.operation});return await e.applyRewrite(n),e.applyPostRewrite&&t.push(...await e.applyPostRewrite(n)),t}finally{await 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]="05b945f2-4f96-5f88-98ff-84cc856d0d57")}catch{}})();function kn(e){return Array.isArray(e)?e:typeof e=="string"?[e]:[]}function Ba(e){let t=[];for(let r of e)t.includes(r)||t.push(r);return t.includes("g")||t.push("g"),t.join("")}function Ga(e){let t=e.trim();if(t.length===0)throw new f("history-redact --regex requires a non-empty pattern.",u.USAGE);let r=t,n="g";if(t.startsWith("/")&&t.length>1){let o=t.lastIndexOf("/");o>0&&(r=t.slice(1,o),n=Ba(t.slice(o+1)))}if(r.length===0)throw new f("history-redact --regex cannot use an empty pattern.",u.USAGE);try{new RegExp(r,n)}catch{throw new f("Invalid --regex value; provide a valid JavaScript regular expression.",u.USAGE)}return{kind:"regex",source:r,flags:n}}function Ya(e,t){let r=[...new Set(kn(e).map(i=>i.trim()))].filter(i=>i.length>0).map(i=>({kind:"literal",value:i})),n=[...new Set(kn(t).map(i=>i.trim()))].filter(i=>i.length>0).map(Ga),o=[...r,...n];if(o.length===0)throw new f("history-redact requires at least one matcher via --literal or --regex.",u.USAGE,{code:"missing_required_argument",required:"Provide --literal <value> and/or --regex <pattern>.",examples:['pm history-redact pm-a1b2 --literal "[redacted_path_prefix]/private"','pm history-redact pm-a1b2 --regex "/192\\\\.168\\\\.[0-9.]+/g" --replacement "[scrubbed_ip]"']});return o}function Wa(e,t,r){if(t.length===0)return{value:e,replacements:0};let n=0,o=0;for(;n<=e.length;){let i=e.indexOf(t,n);if(i===-1)break;o+=1,n=i+Math.max(1,t.length)}return o===0?{value:e,replacements:0}:{value:e.split(t).join(r),replacements:o}}function Ka(e,t,r){let n=new RegExp(t.source,t.flags),o=[...e.matchAll(n)];return o.length===0?{value:e,replacements:0}:{value:e.replace(n,r),replacements:o.length}}function Dn(e,t,r){let n=e,o=0;for(let i of t){let s=i.kind==="literal"?Wa(n,i.value,r):Ka(n,i,r);n=s.value,o+=s.replacements}return{value:n,replacements:o}}function Wt(e,t,r){if(typeof e=="string")return Dn(e,t,r);if(Array.isArray(e)){let n=0;return{value:e.map(i=>{let s=Wt(i,t,r);return n+=s.replacements,s.value}),replacements:n}}if(typeof e=="object"&&e!==null){let n=0,o={};for(let[i,s]of Object.entries(e)){let a=Wt(s,t,r);n+=a.replacements,o[i]=a.value}return{value:o,replacements:n}}return{value:e,replacements:0}}function Xa(e){let t=structuredClone(fe),r=0,n=0;for(let o=0;o<e.length;o+=1){let i=e[o];z(t)!==i.before_hash&&(r+=1),t=Qe(t,i.patch,o+1,i.op),z(t)!==i.after_hash&&(n+=1)}return{hashMismatchesBefore:r,hashMismatchesAfter:n,finalDocument:t}}function Qa(e,t,r){let n=0,o=!1,i=e.message;if(typeof e.message=="string"){let a=Dn(e.message,t,r);i=a.value,n+=a.replacements,a.replacements>0&&(o=!0)}let s=e.patch.map(a=>{if(!Object.prototype.hasOwnProperty.call(a,"value"))return a;let c=Wt(a.value,t,r);return n+=c.replacements,c.replacements>0?(o=!0,{...a,value:c.value}):a});return{entry:{...e,message:i,patch:s},replacements:n,changed:o}}function Ja(e,t,r){let n=structuredClone(fe),o=0,i=0,s=[];for(let a=0;a<e.length;a+=1){let c=Qa(e[a],t,r);i+=c.replacements,c.changed&&(o+=1);let d=z(n);n=Qe(n,c.entry.patch,a+1,c.entry.op);let l=z(n);s.push({...c.entry,before_hash:d,after_hash:l})}return{entries:s,finalDocument:n,entriesChanged:o,replacements:i}}function Za(e){return Object.keys(e.metadata).length>0}async function ec(e,t){let r=e.located?.itemPath??null;if(!e.located)return{raw:null,path:r,document:null};let n=await G(e.located,{schema:t.schema});return{raw:n.raw,path:r,document:n.document}}function tc(e){if(!Za(e.finalDocument))return{raw:null,path:null,document:null};let t=st(Ae(e.finalDocument),{schema:e.settings.schema});if(t.metadata.id!==e.subject.id)throw new f("history-redact would change the item id; narrow your patterns.",u.USAGE);return{document:t,path:se(e.pmRoot,t.metadata.type,e.subject.id,"toon",e.typeToFolder),raw:le(t,{format:"toon",schema:e.settings.schema})}}function rc(e,t){return typeof e.message=="string"&&e.message.trim().length>0?e.message:`history-redact replaced ${t.replacements} match(es) across ${t.entriesChanged} entr${t.entriesChanged===1?"y":"ies"}.`}function nc(e){let t=[...e.rewritten.entries];if(e.dryRun||!e.changed)return{rewrittenEntries:t,auditEntryAdded:!1};let r=e.nextItemDocument??Ae(e.rewritten.finalDocument);return t.push(at({nowIso:v(),author:e.author,op:"history_redact",before:r,after:r,message:e.message})),{rewrittenEntries:t,auditEntryAdded:!0}}async function oc(e){let t=[];return Rn({pmRoot:e.pmRoot,subject:e.subject,settings:e.settings,typeRegistry:e.typeRegistry,historyRawBeforeLock:e.historyRawBeforeLock,currentItemRawBeforeLock:e.currentItem.raw,operation:"history-redact",author:e.author,force:e.force,itemDocument:e.currentItem.document,applyRewrite:async({historyRawUnderLock:r})=>{let n=await ut(e.pmRoot,e.author),o=new Set;e.currentItem.path&&o.add(e.currentItem.path),e.nextItem.path&&o.add(e.nextItem.path);let i=new Map;e.currentItem.path&&e.currentItem.raw!==null&&i.set(e.currentItem.path,e.currentItem.raw);let s=()=>{};try{try{e.nextItem.path&&e.nextItem.raw!==null&&e.nextItem.raw!==e.currentItem.raw&&await S(e.nextItem.path,e.nextItem.raw),e.currentItem.path&&(!e.nextItem.path||e.nextItem.path!==e.currentItem.path)&&await Yt.rm(e.currentItem.path,{force:!0}),await S(e.subject.historyPath,er(e.rewrittenEntries))}catch(c){try{await ic(e.subject.historyPath,r,o,i)}finally{await te(e.subject.historyPath)}throw c}await te(e.subject.historyPath);let a=e.nextItem.path??e.currentItem.path;a&&(t=await mt({pmRoot:e.pmRoot,preferredFormat:e.settings.item_format,typeToFolder:e.typeRegistry.type_to_folder,schema:e.settings.schema,itemPath:a,...e.currentItem.path?{previousItemPath:e.currentItem.path}:{},document:e.nextItem.document}))}finally{await n().catch(a=>{s=()=>{throw a}})}s()},applyPostRewrite:async()=>[...t,...await sc(e.subject.historyPath,[e.nextItem.path,e.currentItem.path])]})}async function ic(e,t,r,n){t===null?await Yt.rm(e,{force:!0}):await S(e,t);for(let o of r){let i=n.get(o);i===void 0?await Yt.rm(o,{force:!0}):await S(o,i)}}async function sc(e,t){let r=[],n=new Set(t.filter(o=>o!==null));for(let o of n)r.push(...await q({path:o,scope:"project",op:"history_redact"}));return r.push(...await q({path:e,scope:"project",op:"history_redact:history"})),r}async function ac(e,t,r,n){let o=await B(e,t,r.id_prefix,r.item_format,n);if(o)return{id:o.id,historyPath:Se(e,o.id),located:o};let i=re(t,r.id_prefix),s=dt(t),a=i===s?[i]:[i,s];for(let c of a){let d=Se(e,c);if(await P(d))return{id:c,historyPath:d,located:null}}throw new f(`Item ${t} not found`,u.NOT_FOUND)}async function I_(e,t,r){let n=H(process.cwd(),r.path);await rr(n);let o=await C(n),i=F(o,ce()),s=t.replacement??"",a=s.length===0,c=a?"[redacted]":s,d=Ya(t.literal,t.regex),l=await ac(n,e,o,i.type_to_folder);if(!await P(l.historyPath))throw new f(`No history stream exists for ${l.id}.`,u.NOT_FOUND);let m=await T(l.historyPath),h=await ue(l.historyPath,l.id);if(h.length===0)throw new f(`No history entries exist for ${l.id}; nothing to redact.`,u.USAGE);let p=Xa(h),_=Ja(h,d,c),y=p.hashMismatchesBefore+p.hashMismatchesAfter,g=!!t.dryRun,E=_.replacements>0,x=[];y>0&&x.push(`history_redact_preexisting_hash_mismatches:${y}`),E||x.push("history_redact_no_matches");let I=await ec(l,o),A=tc({pmRoot:n,subject:l,settings:o,typeToFolder:i.type_to_folder,finalDocument:_.finalDocument}),V=(I.path??null)!==(A.path??null)||(I.raw??null)!==(A.raw??null),O=Ie(t.author,o.author_default),Je=rc(t,_),{rewrittenEntries:J,auditEntryAdded:Ee}=nc({rewritten:_,dryRun:g,changed:E,nextItemDocument:A.document,author:O,message:Je}),ie=ct(J);if(!ie.ok)throw new f(`history-redact produced an invalid rewritten chain (${ie.errors.join(", ")}).`,u.GENERIC_FAILURE);return!g&&E&&x.push(...await oc({pmRoot:n,subject:l,settings:o,typeRegistry:i,historyRawBeforeLock:m,currentItem:I,nextItem:A,author:O,force:t.force,rewrittenEntries:J})),{id:l.id,dry_run:g,changed:E,patterns:{literal_count:d.filter(j=>j.kind==="literal").length,regex_count:d.filter(j=>j.kind==="regex").length,total_count:d.length,replacement_is_default:a},history:{path:l.historyPath,entries_scanned:h.length,entries_changed:_.entriesChanged,replacements:_.replacements,hash_mismatches_before:p.hashMismatchesBefore,hash_mismatches_after:p.hashMismatchesAfter,preexisting_hash_mismatches:y,audit_entry_added:Ee,verify_ok:ie.ok,verify_errors:ie.errors},item:{existed_before:I.path!==null,exists_after:A.path!==null,path_before:I.path,path_after:A.path,changed:V},warnings:[...new Set(x)].sort((j,Ln)=>j.localeCompare(Ln)),generated_at:v()}}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="412fc2d2-daee-5d87-82ab-5411a1503087")}catch{}})();function A_(e,t){let r=t??{};return e.filter(n=>r[n.id]!==n.updated_at).map(n=>n.id).sort((n,o)=>n.localeCompare(o))}export{Hh as a,Qe as b,qh as c,Bh as d,t_ as e,Rn as f,ac as g,I_ as h,Jn as i,Zn as j,to as k,ro as l,Dc as m,no as n,oo as o,Oc as p,ur as q,io as r,so as s,ao as t,co as u,ho as v,go as w,Pc as x,wo as y,_r as z,bo as A,So as B,$c as C,To as D,Oe as E,Fc as F,Pe as G,xo as H,Ao as I,yt as J,Co as K,gt as L,Ro as M,Zc as N,Do as O,gr as P,Lo as Q,Mo as R,Po as S,sd as T,zo as U,fd as V,Ho as W,Bo as X,Mn as Y,Go as Z,Yo as _,ze as $,hi as aa,Nd as ba,Et as ca,Cr as da,bt as ea,vi as fa,Ci as ga,$d as ha,Rr as ia,ne as ja,Tt as ka,xt as la,Mt as ma,Wd as na,Nt as oa,Ge as pa,Pr as qa,Ye as ra,Ot as sa,Pt as ta,$t as ua,Ft as va,jr as wa,Hr as xa,hl as ya,zn as za,or as Aa,Vn as Ba,jn as Ca,Hn as Da,mc as Ea,hc as Fa,me as Ga,De as Ha,he as Ia,pe as Ja,Le as Ka,Me as La,ir as Ma,Wn as Na,Is as Oa,vs as Pa,Rs as Qa,ks as Ra,Vs as Sa,tn as Ta,ea as Ua,gu as Va,A_ as Wa,Nh as Xa,Oh as Ya,Fa as Za,Ph as _a,$h as $a};
20
- //# sourceMappingURL=chunk-73EDXGYE.js.map
20
+ //# sourceMappingURL=chunk-FOMZ6NG5.js.map