@unbrained/pm-cli 2026.8.19 → 2026.8.20

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 (146) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/CHANGELOG.md +19 -0
  3. package/dist/cli/register-list-query.js +12 -10
  4. package/dist/cli/register-structured-mutation.d.ts +2 -0
  5. package/dist/cli/register-structured-mutation.js +29 -6
  6. package/dist/cli-bundle/bundle-manifest.json +151 -143
  7. package/dist/cli-bundle/chunks/{chunk-4THEB6PD.js → chunk-2RDVGYWE.js} +12 -12
  8. package/dist/cli-bundle/chunks/{chunk-BHYMXLAE.js → chunk-4GB2LTOQ.js} +2 -2
  9. package/dist/cli-bundle/chunks/{chunk-TOXJM4WA.js → chunk-7BRF2BX2.js} +2 -2
  10. package/dist/cli-bundle/chunks/chunk-BLVQHFSY.js +35 -0
  11. package/dist/cli-bundle/chunks/chunk-CU25EQVV.js +5 -0
  12. package/dist/cli-bundle/chunks/{chunk-4NRRH7AM.js → chunk-K3EN3LK2.js} +2 -2
  13. package/dist/cli-bundle/chunks/{chunk-OIOKV6NO.js → chunk-L4LGPBJU.js} +49 -49
  14. package/dist/cli-bundle/chunks/chunk-RS3IV2R6.js +197 -0
  15. package/dist/cli-bundle/chunks/chunk-TSMWLCHS.js +3 -0
  16. package/dist/cli-bundle/chunks/chunk-US2ZQW2M.js +77 -0
  17. package/dist/cli-bundle/chunks/{chunk-QXSH7BLM.js → chunk-XYDDWBZN.js} +2 -2
  18. package/dist/cli-bundle/chunks/register-list-query-JSAQCVOC.js +11 -0
  19. package/dist/cli-bundle/chunks/{register-mutation-AUWVCW4M.js → register-mutation-XJPAW63D.js} +20 -20
  20. package/dist/cli-bundle/chunks/{register-operations-PZQPHXW5.js → register-operations-DSOSB2XQ.js} +2 -2
  21. package/dist/cli-bundle/chunks/{register-setup-I4LUHGVW.js → register-setup-QUR6QL2C.js} +2 -2
  22. package/dist/cli-bundle/focused-chunks/{chunk-DKPLYW3L.js → chunk-325UXIO7.js} +2 -2
  23. package/dist/cli-bundle/focused-chunks/chunk-5L7M4AI7.js +2 -0
  24. package/dist/cli-bundle/focused-chunks/{chunk-EF6ZS5GH.js → chunk-6AHG2YW7.js} +2 -2
  25. package/dist/cli-bundle/focused-chunks/{chunk-MCZXYZAF.js → chunk-AZBACT5T.js} +2 -2
  26. package/dist/cli-bundle/focused-chunks/{chunk-VXDSU5MC.js → chunk-BLJCGGID.js} +2 -2
  27. package/dist/cli-bundle/focused-chunks/chunk-FUREQLQN.js +18 -0
  28. package/dist/cli-bundle/focused-chunks/{chunk-US7VEYZG.js → chunk-G3C5ERXG.js} +2 -2
  29. package/dist/cli-bundle/focused-chunks/{chunk-ZBIQQYMI.js → chunk-GXWQBE3T.js} +2 -2
  30. package/dist/cli-bundle/focused-chunks/{chunk-JDOMQ7VQ.js → chunk-JWKEDZJI.js} +3 -3
  31. package/dist/cli-bundle/focused-chunks/chunk-KYZ6JGPL.js +155 -0
  32. package/dist/cli-bundle/focused-chunks/{chunk-ESISGDAY.js → chunk-M32HFIQB.js} +2 -2
  33. package/dist/cli-bundle/focused-chunks/{chunk-EXBCLIBU.js → chunk-OM65KHGF.js} +2 -2
  34. package/dist/cli-bundle/focused-chunks/chunk-Q47EX4DI.js +2 -0
  35. package/dist/cli-bundle/focused-chunks/{chunk-BJRYFVSH.js → chunk-RIHDMCUM.js} +2 -2
  36. package/dist/cli-bundle/focused-chunks/chunk-T4ZFY7ZJ.js +16 -0
  37. package/dist/cli-bundle/focused-chunks/chunk-TDR5OGG3.js +2 -0
  38. package/dist/cli-bundle/focused-chunks/{chunk-ODHQEECS.js → chunk-UGSS4F5X.js} +2 -2
  39. package/dist/cli-bundle/focused-chunks/chunk-Z3PLWSGM.js +2 -0
  40. package/dist/cli-bundle/main.js +2 -2
  41. package/dist/cli-bundle/sdk-authoring.js +1 -1
  42. package/dist/cli-bundle/sdk-contracts.js +2 -2
  43. package/dist/cli-bundle/sdk-core.js +41 -41
  44. package/dist/cli-bundle/sdk-governance.js +1 -1
  45. package/dist/cli-bundle/sdk-graph.js +1 -1
  46. package/dist/cli-bundle/sdk-merge.js +31 -31
  47. package/dist/cli-bundle/sdk-query.js +1 -1
  48. package/dist/cli-bundle/sdk-runtime.js +1 -1
  49. package/dist/cli-bundle/sdk-testing.js +1 -1
  50. package/dist/cli-bundle/sdk.js +5 -5
  51. package/dist/core/output/mutation-projection.js +26 -2
  52. package/dist/core/shared/constants.d.ts +1 -5
  53. package/dist/core/shared/constants.js +3 -81
  54. package/dist/core/shared/item-metadata-contract.d.ts +14 -0
  55. package/dist/core/shared/item-metadata-contract.js +90 -0
  56. package/dist/core/store/item-store.d.ts +60 -0
  57. package/dist/core/store/item-store.js +22 -5
  58. package/dist/sdk/agent/closed-domain-contracts.d.ts +25 -0
  59. package/dist/sdk/agent/closed-domain-contracts.js +140 -0
  60. package/dist/sdk/agent/refusal-closure.d.ts +13 -1
  61. package/dist/sdk/agent/refusal-closure.js +45 -3
  62. package/dist/sdk/agent/refusal-reachability.d.ts +26 -0
  63. package/dist/sdk/agent/refusal-reachability.js +26 -2
  64. package/dist/sdk/agent-capability-contracts.js +6 -11
  65. package/dist/sdk/cli-contracts/completeness.js +8 -2
  66. package/dist/sdk/cli-contracts/enum-contracts.d.ts +4 -2
  67. package/dist/sdk/cli-contracts/enum-contracts.js +16 -6
  68. package/dist/sdk/cli-contracts/flag-contracts.d.ts +2 -0
  69. package/dist/sdk/cli-contracts/flag-contracts.js +11 -2
  70. package/dist/sdk/cli-contracts/flag-lexicon-contracts.d.ts +19 -2
  71. package/dist/sdk/cli-contracts/flag-lexicon-contracts.js +105 -5
  72. package/dist/sdk/cli-contracts/grammar-contracts.d.ts +2 -2
  73. package/dist/sdk/cli-contracts/grammar-contracts.js +5 -2
  74. package/dist/sdk/cli-contracts/runtime-contracts.js +7 -3
  75. package/dist/sdk/cli-contracts/tool-schema.js +7 -2
  76. package/dist/sdk/cli-contracts.d.ts +2 -2
  77. package/dist/sdk/cli-contracts.js +4 -4
  78. package/dist/sdk/contracts.d.ts +1 -0
  79. package/dist/sdk/contracts.js +3 -2
  80. package/dist/sdk/core.d.ts +1 -1
  81. package/dist/sdk/core.js +3 -3
  82. package/dist/sdk/generated/generated-error-code-catalog-part-1.js +74 -2
  83. package/dist/sdk/generated/generated-error-code-catalog-part-2.js +112 -40
  84. package/dist/sdk/index.d.ts +5 -3
  85. package/dist/sdk/index.js +6 -4
  86. package/dist/sdk/init-agent-guidance.d.ts +5 -3
  87. package/dist/sdk/init-agent-guidance.js +69 -9
  88. package/dist/sdk/lifecycle/mcp-actions.d.ts +18 -0
  89. package/dist/sdk/lifecycle/mcp-actions.js +52 -0
  90. package/dist/sdk/lifecycle/reopen.d.ts +44 -0
  91. package/dist/sdk/lifecycle/reopen.js +69 -0
  92. package/dist/sdk/lifecycle/update.d.ts +31 -0
  93. package/dist/sdk/lifecycle/update.js +95 -13
  94. package/dist/sdk/query/get.d.ts +1 -1
  95. package/dist/sdk/query/get.js +18 -52
  96. package/dist/sdk/query/list.d.ts +7 -21
  97. package/dist/sdk/query/list.js +35 -49
  98. package/dist/sdk/query/projection-contracts.d.ts +33 -0
  99. package/dist/sdk/query/projection-contracts.js +185 -0
  100. package/dist/sdk/query/search-contracts.d.ts +2 -1
  101. package/dist/sdk/query/search-contracts.js +18 -87
  102. package/dist/sdk/query/search.d.ts +15 -0
  103. package/dist/sdk/query/search.js +31 -5
  104. package/dist/sdk/runtime-primitives.d.ts +1 -1
  105. package/dist/sdk/runtime-primitives.js +3 -3
  106. package/dist/sdk/runtime.d.ts +6 -0
  107. package/dist/sdk/runtime.js +18 -14
  108. package/dist/sdk/similarity.d.ts +13 -0
  109. package/dist/sdk/similarity.js +32 -6
  110. package/docs/COMMANDS.md +13 -1
  111. package/docs/README.md +1 -0
  112. package/docs/RECURRENCE_RECOVERY_CONTRACTS.md +114 -0
  113. package/docs/SDK.md +10 -2
  114. package/docs/SDK_CONTEXT_INTEGRITY.md +45 -0
  115. package/docs/generated/AGENT_COMMAND_SURFACE.md +1 -1
  116. package/docs/performance/sdk-entrypoint-import-costs.md +14 -21
  117. package/marketplace.json +2 -2
  118. package/package.json +5 -5
  119. package/packages/pm-beads/package.json +1 -1
  120. package/packages/pm-calendar/package.json +1 -1
  121. package/packages/pm-command-kit/package.json +1 -1
  122. package/packages/pm-digital-twin/package.json +1 -1
  123. package/packages/pm-governance-audit/package.json +1 -1
  124. package/packages/pm-guide-shell/package.json +1 -1
  125. package/packages/pm-kanban/package.json +1 -1
  126. package/packages/pm-lifecycle-hooks/package.json +1 -1
  127. package/packages/pm-linked-test-adapters/package.json +1 -1
  128. package/packages/pm-search-advanced/package.json +1 -1
  129. package/packages/pm-templates/package.json +1 -1
  130. package/packages/pm-todos/package.json +1 -1
  131. package/packages/pm-vcs/package.json +1 -1
  132. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  133. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  134. package/sdk/public-surface.json +387 -25
  135. package/dist/cli-bundle/chunks/chunk-GWMXAQOD.js +0 -197
  136. package/dist/cli-bundle/chunks/chunk-HVFQTLYM.js +0 -35
  137. package/dist/cli-bundle/chunks/chunk-OI4XI562.js +0 -5
  138. package/dist/cli-bundle/chunks/chunk-SARFF5H5.js +0 -3
  139. package/dist/cli-bundle/chunks/chunk-YBMRWW4E.js +0 -77
  140. package/dist/cli-bundle/chunks/register-list-query-Y56KINDU.js +0 -11
  141. package/dist/cli-bundle/focused-chunks/chunk-34QBIYZI.js +0 -155
  142. package/dist/cli-bundle/focused-chunks/chunk-L623ZPNK.js +0 -2
  143. package/dist/cli-bundle/focused-chunks/chunk-PRHY2IMX.js +0 -18
  144. package/dist/cli-bundle/focused-chunks/chunk-RZU5U6Q7.js +0 -2
  145. package/dist/cli-bundle/focused-chunks/chunk-YBMGXBFV.js +0 -16
  146. package/dist/cli-bundle/focused-chunks/chunk-YLVBJ6GF.js +0 -2
@@ -1,4 +1,4 @@
1
- import{a as ki,c as Wn,d as Bn,e as Zo,g as Qo,h as Si,i as es,j as At,k as Rt,l as ts,m as ns,n as Ei,o as rs,p as It,q as Ct,r as is,s as as,t as Ai}from"./chunk-EXBCLIBU.js";import{e as Xn,f as Ri}from"./chunk-DKPLYW3L.js";import{C as Kn,a as Ho,g as bi,i as Jo}from"./chunk-MCZXYZAF.js";import{Z as Xs,l as Ks,n as Ys}from"./chunk-BJRYFVSH.js";import{$ as zs,Aa as Js,Ba as Vs,Da as Di,I as lr,J as Ds,K as $i,L as an,N as Ti,R as Ps,S as Ns,T as Ms,U as Ls,V as dr,X as Fs,Y as js,Z as Us,_ as ht,aa as Nt,ba as qs,ca as Oi,da as Mt,e as Is,ea as Gs,f as Cs,fa as Ws,g as $s,t as nn,u as Ts,ua as Bs,v as rn,va as ur,w as Os,za as Hs}from"./chunk-PRHY2IMX.js";import{a as Vo,b as Hn,c as xi,d as Ko,e as Yo,f as We,g as Jn,h as Xo,i as it}from"./chunk-ESISGDAY.js";import{$a as ks,Ab as Rs,Ba as ys,Na as ws,Sa as ue,Ta as nr,U as Y,Ua as vs,V as $,Va as Ci,Wa as rr,Xa as ir,Ya as ar,Za as bs,_ as de,_a as Te,ab as I,b as ps,bb as or,d as fs,db as xs,ea as gs,fa as Qn,ia as er,ib as Ss,ja as _s,jb as Es,l as z,ma as $t,o as re,oa as Tt,ob as sr,q as He,qb as As,r as hs,ra as tr,rb as Ot,s as Zn,sb as Dt,tb as Pt,ub as Je,vb as cr,yb as ft,za as Ii}from"./chunk-34QBIYZI.js";import{Ba as vi,Ca as Wo,Da as Bo,E as Mo,Ea as Et,F as Lo,G as q,Ga as Ne,Ia as Me,Ka as se,L as tn,La as Ae,M as L,N as pt,Na as we,O as qn,Oa as Le,P as K,R as Fo,S as Gn,Sa as Be,Ua as Vn,W as Z,Ya as Yn,Z as jo,Za as cs,_a as ls,a as Io,ba as Uo,d as Co,e as $o,ea as _i,ga as yi,h as St,p as gi,q as A,r as zn,s as j,sa as zo,t as X,ta as qo,u as le,x as ye,y as Ee,z as No}from"./chunk-JDOMQ7VQ.js";import{a as ds,b as us,d as ms}from"./chunk-ODHQEECS.js";import{N as To,P as Oo,R as Do,U as Po,V as Un,Y as _,Z as y,a as Fn,aa as oe,ba as Go,ca as wi,d as jn,fa as os,oa as ss,t as hi}from"./chunk-RZU5U6Q7.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]="d2d5135a-8110-527e-8530-653b25b792a4")}catch{}})();var N=class extends TypeError{constructor(t){super(t),this.name="AssuranceMutationRefusalError"}},ve=class extends TypeError{context;constructor(t,n={}){super(t),this.name="AssuranceEvaluationRefusalError",this.context=n}},Fe=class extends TypeError{measurement_id;source_kind;field;check;constructor(t,n){super(t),this.name="AssuranceSourceResolutionError",this.measurement_id=n.measurement_id,this.source_kind=n.source_kind,this.field=n.field,this.check=n.check}};async function Lt(e){try{return await e()}catch(t){throw t instanceof N?new y(t.message,_.USAGE,{code:"invalid_argument_value",reason:"assurance_mutation_refused"}):t}}async function Zs(e){try{return await e()}catch(t){throw t instanceof ve?new y(t.message,_.USAGE,{code:"invalid_argument_value",reason:"assurance_evaluation_refused",...t.context}):t}}import{createHash as kp}from"node:crypto";import xp 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]="b911b43d-d14d-5e4f-a35e-5020b1a84542")}catch{}})();var Ft=1e3;(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]="2bf52d6d-7e4f-5ec5-86bd-3e817ef521bb")}catch{}})();var ec=1,gt=["pre-commit","pre-push","pre-merge","ci","pre-release","post-release","scheduled","on-claim","on-close"],Pi=["items","dependency_kind","graph","validate","health","history","links","provider","derived"],Sp=["ceiling","floor","equals","zero","monotone_nondecreasing","monotone_nonincreasing","subset_of"],Ep=/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/,mr=30,pr=5e3,tc=4,Ap=50;function Ve(e,t){if(!Ep.test(e))throw new N(`${t} must be a stable lowercase id`)}function Rp(e,t){if(!Number.isFinite(e)||e<0)throw new N(`${t} must be a finite non-negative number`)}function on(e){let t=Sp.filter(i=>e[i]!==void 0);if(t.length!==1)throw new N(`assertion ${e.id} must declare exactly one polarity`);let n=t[0],r=e[n];return{polarity:n,value:n==="zero"?0:r}}function Ni(e,t){return oe(e)===oe(t)}function nc(e,t){if(t.polarity==="equals")return Ni(e,t.value);if(t.polarity==="subset_of"){if(!Array.isArray(e)||!Array.isArray(t.value))return!1;let r=t.value;return e.every(i=>r.includes(i))}if(typeof e!="number")return!1;let n=t.value;return t.polarity==="ceiling"||t.polarity==="monotone_nonincreasing"?e<=n:t.polarity==="floor"||t.polarity==="monotone_nondecreasing"?e>=n:e===0}function rc(e){let t=on(e),n=e.negative_control.cases;return n.some(r=>r.expected==="pass")&&n.some(r=>r.expected==="fail")&&n.every(r=>nc(r.observed,t)===(r.expected==="pass"))}function Ip(e,t){if(e.polarity!==t.polarity)return!0;if(typeof e.value=="number"&&typeof t.value=="number")return e.polarity==="ceiling"||e.polarity==="monotone_nonincreasing"?t.value>e.value:e.polarity==="floor"||e.polarity==="monotone_nondecreasing"?t.value<e.value:t.value!==e.value;if(e.polarity==="subset_of"){let n=e.value,r=t.value;return!Array.isArray(n)||!Array.isArray(r)||r.some(i=>!n.includes(i))}return!Ni(e.value,t.value)}function Cp(e,t){if(e.measurement_id!==t.measurement_id||e.owner_item_id!==t.owner_item_id||oe(e.scope)!==oe(t.scope))return!0;let n={observe:0,warn:1,block:2},r=(e.lifetime??"hold")==="hold"&&(t.lifetime??"hold")==="retire";return Ip(on(e),on(t))||n[t.enforcement]<n[e.enforcement]||r}function $p(e){if(e.state!==void 0&&!(e.state==="present"||e.state==="missing"))throw new N("items source state must be present or missing");let t=Object.hasOwn(e,"equals"),n=e.state!==void 0,r=Number(t)+Number(n);if(e.field!==void 0&&r!==1)throw new N("items source with field requires exactly one of equals or state");if(e.field===void 0&&r!==0)throw new N("items source equals/state requires field")}function Mi(e){Ve(e.id,"measurement.id"),e.max_cost!==void 0&&Rp(e.max_cost,"measurement.max_cost");let t=e.source;if(Object.prototype.toString.call(t)!=="[object Object]")throw new N(`measurement.source.kind must be one of ${Pi.join(", ")}`);let n=Reflect.get(t,"kind");if(!Pi.includes(n))throw new N(`measurement.source.kind must be one of ${Pi.join(", ")}`);let r=t;if(r.kind==="items"&&$p(r),r.kind==="dependency_kind"&&(typeof r.dependency_kind!="string"||r.dependency_kind.trim().length===0))throw new N("dependency_kind source requires dependency_kind");if((r.kind==="graph"||r.kind==="validate"||r.kind==="health")&&(typeof r.field!="string"||r.field.trim().length===0))throw new N(`${r.kind} source requires field`);return r.kind==="provider"&&(Ve(r.provider,"provider source provider"),Ve(r.key,"provider source key")),e}function Li(e){if(Ve(e.id,"assertion.id"),Ve(e.measurement_id,"assertion.measurement_id"),typeof e.owner_item_id!="string"||e.owner_item_id.trim().length===0)throw new N("assertion.owner_item_id is required");let t=on(e);if(typeof t.value=="number"&&!Number.isFinite(t.value))throw new N(`assertion.${t.polarity} must be a finite number`);if(e.lifetime==="retire"&&(typeof e.retire_reason!="string"||e.retire_reason.trim().length===0))throw new N("retired assertion requires retire_reason");e.scope.kind==="filter"&&Ve(e.scope.measurement_id,"assertion.scope.measurement_id");let n=e.negative_control?.cases;if(!Array.isArray(n)||!n.some(r=>r.expected==="pass")||!n.some(r=>r.expected==="fail"))throw new N("assertion negative control requires pass and fail cases");if(!rc(e))throw new N(`assertion ${e.id} negative control does not prove its bound`);return e}function Tp(e){if(!Array.isArray(e.allowed_providers))throw new N("gate provider_policy.allowed_providers must be an array");for(let t of e.allowed_providers)Ve(t,"gate.provider_policy.allowed_provider");if(typeof e.triggers!="object"||e.triggers===null||Array.isArray(e.triggers))throw new N("gate provider_policy.triggers must be an object");for(let[t,n]of Object.entries(e.triggers)){if(!gt.includes(t))throw new N(`gate provider policy has unknown trigger ${t}`);if(typeof n!="object"||n===null||!["low","medium","high"].includes(n.max_cost_class)||typeof n.allow_network!="boolean")throw new N(`gate provider policy trigger ${t} is invalid`)}}function ic(e){if(Ve(e.id,"gate.id"),!Array.isArray(e.assertion_ids))throw new N("gate.assertion_ids is required and must be an array");if(e.assertion_ids.length===0)throw new N("gate requires at least one assertion");for(let t of e.assertion_ids)Ve(t,"gate.assertion_id");if(!Array.isArray(e.triggers))throw new N(`gate.triggers is required and must be an array of ${gt.join(", ")}`);if(e.triggers.length===0)throw new N("gate requires at least one trigger");for(let t of e.triggers)if(!gt.includes(t))throw new N(`gate trigger must be one of ${gt.join(", ")}`);return e.provider_policy&&Tp(e.provider_policy),e}function jt(e){if(e.version!==ec)throw new N(`unsupported assurance document version ${String(e.version)}`);let t=new Set;for(let r of e.measurements){if(Mi(r),t.has(`measurement:${r.id}`))throw new N(`duplicate measurement ${r.id}`);t.add(`measurement:${r.id}`)}for(let r of e.assertions){if(Li(r),t.has(`assertion:${r.id}`))throw new N(`duplicate assertion ${r.id}`);t.add(`assertion:${r.id}`)}for(let r of e.gates){ic(r);let i=r.assertion_ids.filter(a=>!e.assertions.some(o=>o.id===a));if(i.length>0)throw new N(`gate ${r.id} references missing assertions: ${i.join(", ")}`);if(t.has(`gate:${r.id}`))throw new N(`duplicate gate ${r.id}`);t.add(`gate:${r.id}`)}let n=new Set(e.measurements.map(r=>r.id));for(let[r,i]of ac(e))if(!n.has(r))throw new N(`${i.join(", ")} references missing measurement ${r}`);return e}function Fi(e,t){if("measurement"in e){t.push(e.measurement);return}if("operator"in e)for(let n of e.operands)Fi(n,t)}function ac(e){let t=new Map,n=(r,i)=>{let a=t.get(r)??[];a.push(i),t.set(r,a)};for(let r of e.assertions)n(r.measurement_id,`assertion ${r.id}`),r.scope.kind==="filter"&&n(r.scope.measurement_id,`assertion ${r.id} scope`);for(let r of e.measurements){if(r.source.kind!=="derived")continue;let i=[];Fi(r.source.expression,i);for(let a of i)n(a,`derived measurement ${r.id}`)}return t}function Op(e,t){let n=e.assertion_ids.flatMap(a=>{let o=t.assertions.find(s=>s.id===a);return[o.measurement_id,...o.scope.kind==="filter"?[o.scope.measurement_id]:[]]}),r=new Set,i=new Set;for(;n.length>0;){let a=n.pop();if(r.has(a))continue;r.add(a);let o=t.measurements.find(s=>s.id===a);o.source.kind==="provider"?i.add(o.source.provider):o.source.kind==="derived"&&Fi(o.source.expression,n)}return i}function sn(){return{version:ec,measurements:[],assertions:[],gates:[]}}function Dp(e,t){let n=t.items.filter(r=>(e.statuses===void 0||e.statuses.includes(r.status))&&(e.types===void 0||e.types.includes(r.type))&&(e.tags===void 0||e.tags.every(i=>r.tags?.includes(i)))&&(e.field===void 0||(()=>{let i=r[e.field];if(e.state!==void 0){let a=i==null||i===""||Array.isArray(i)&&i.length===0;return e.state==="missing"?a:!a}return Ni(i,e.equals)})()));return{value:n.length,population_size:t.items.length,cost:t.items.length,contributors:n.map(r=>r.id)}}function Pp(e,t){let n=[],r=yi(e.dependency_kind)??e.dependency_kind.trim().toLowerCase();for(let i of t.items)for(let a of i.dependencies??[])(yi(a.kind)??a.kind.trim().toLowerCase())===r&&n.push(`${i.id}->${a.id}`);return{value:n.length,population_size:t.items.length,cost:t.items.length,contributors:n}}function Np(e,t){return{value:t.history.filter(r=>(e.op===void 0||r.op===e.op)&&(e.author===void 0||r.author===e.author)&&(e.harness===void 0||r.agent_harness===e.harness)&&(e.model===void 0||r.agent_model===e.model)).length,population_size:t.history.length,cost:t.history.length}}function Mp(e,t){let n=t.items.filter(r=>{let i=r[e.link],a=Array.isArray(i)&&i.length>0;return e.state==="present"?a:!a});return{value:n.length,population_size:t.items.length,cost:t.items.length,contributors:n.map(r=>r.id)}}function Lp(e,t){let n=e.source;return n.kind==="items"?Dp(n,t):n.kind==="dependency_kind"?Pp(n,t):n.kind==="history"?Np(n,t):n.kind==="links"?Mp(n,t):null}function oc(e,t){return e.reduce((n,r)=>({units:n.units+r.units,items_scanned:n.items_scanned+r.items_scanned,history_entries:n.history_entries+r.history_entries,provider_calls:n.provider_calls+r.provider_calls,duration_ms:t}),{units:0,items_scanned:0,history_entries:0,provider_calls:0,duration_ms:t})}function Fp(e,t){if(t.length===0)throw new TypeError(`derived ${e} requires operands`);if(e==="add")return t.reduce((n,r)=>n+r,0);if(e==="subtract")return t.slice(1).reduce((n,r)=>n-r,t[0]);if(e==="multiply")return t.reduce((n,r)=>n*r,1);if(e==="divide"){if(t.slice(1).includes(0))throw new TypeError("derived divide cannot divide by zero");return t.slice(1).reduce((n,r)=>n/r,t[0])}return e==="min"?Math.min(...t):Math.max(...t)}async function sc(e,t,n){let r=new Array(e.length),i=0,a=Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let o=i;i+=1,r[o]=await n(e[o],o)}});return await Promise.all(a),r}async function cc(e,t,n,r,i){if("literal"in e)return{value:e.literal,costs:[],population_size:0,contributors:[]};if("measurement"in e){let o=n.find(l=>l.id===e.measurement);if(!o)throw new TypeError(`derived measurement references missing ${e.measurement}`);let s=await lc(o,t,n,r,i);if(typeof s.value!="number")throw new TypeError(`derived measurement ${o.id} is not numeric`);let c=i.charged.has(o.id)?[]:[s.cost];return i.charged.add(o.id),{value:s.value,costs:c,population_size:s.population_size,contributors:s.contributors}}let a=await sc(e.operands,tc,o=>cc(o,t,n,r,i));return{value:Fp(e.operator,a.map(o=>o.value)),costs:a.flatMap(o=>o.costs),population_size:Math.max(0,...a.map(o=>o.population_size)),contributors:[...new Set(a.flatMap(o=>o.contributors))]}}async function jp(e,t,n,r,i){Mi(e);let a=Date.now(),o,s=[],c=0;if(e.source.kind==="derived"){let u=await cc(e.source.expression,t,n,[...r,e.id],i);o={value:u.value,population_size:u.population_size,cost:0,contributors:u.contributors},s=u.costs}else{let u=Lp(e,t);u!==null?o=u:(o=await t.external(e.source),c=1)}let l={units:o.cost,items_scanned:e.source.kind==="items"||e.source.kind==="dependency_kind"||e.source.kind==="links"?t.items.length:0,history_entries:e.source.kind==="history"?t.history.length:0,provider_calls:c,duration_ms:Date.now()-a},d=oc([...s,l],Date.now()-a);if(e.max_cost!==void 0&&d.units>e.max_cost)throw new ve(`measurement ${e.id} exceeded cost ceiling ${e.max_cost} with ${d.units}`);return{id:e.id,definition_fingerprint:`sha256:${kp("sha256").update(oe(e)).digest("hex")}`,value:o.value,population_size:o.population_size,cost:d,contributors:o.contributors??[]}}function lc(e,t,n,r,i){if(r.includes(e.id))throw new TypeError(`derived measurement cycle: ${[...r,e.id].join(" -> ")}`);let a=i.cache.get(e.id);if(a)return a;let o=jp(e,t,n,r,i).catch(s=>{if(s instanceof Fe&&s.measurement_id===void 0){let c={measurement_id:e.id,source_kind:s.source_kind,field:s.field,...s.check?{check:s.check}:{}},l=new Fe(s.message,c);throw l.cause=s,l}throw s});return i.cache.set(e.id,o),o}async function ji(e,t,n=[e]){return lc(e,t,n,[],{cache:new Map,charged:new Set})}function Up(e,t){return typeof e!="number"||typeof t.value!="number"?null:t.polarity==="ceiling"||t.polarity==="monotone_nonincreasing"?t.value-e:(t.polarity==="floor"||t.polarity==="monotone_nondecreasing",e-t.value)}function zp(e,t,n={}){Li(e);let r=on(e),i=e.lifetime==="retire"&&n.owner_terminal===!0;return{assertion_id:e.id,measurement_id:e.measurement_id,measurement_definition_fingerprint:t.definition_fingerprint,scope:e.scope,population_size:t.population_size,observed:t.value,bound:r,distance:Up(t.value,r),verdict:i?"retired":nc(t.value,r)?"pass":"fail",enforcement:e.enforcement,negative_control_proven:rc(e),cost:t.cost,contributors:t.contributors}}function qp(e,t,n,r){let i=Op(e,t);if(i.size===0)return;let a=e.provider_policy,o=a?.triggers[r];if(!a||!o)throw new ve(`assurance gate ${e.id} refuses provider execution at trigger ${r} without an explicit provider policy`);let s=new Set(a.allowed_providers),c={low:0,medium:1,high:2};for(let l of i){if(!s.has(l))throw new ve(`assurance gate ${e.id} refuses provider ${l}`);let d=n.provider_capabilities?.[l];if(!d)throw new ve(`assurance provider ${l} has no declared capabilities`);if(c[d.cost_class]>c[o.max_cost_class])throw new ve(`assurance gate ${e.id} refuses ${d.cost_class}-cost provider ${l} at trigger ${r}`);if(d.network&&!o.allow_network)throw new ve(`assurance gate ${e.id} refuses network provider ${l} at trigger ${r}`)}}async function Qs(e,t,n,r,i){try{return await ji(n,r,i)}catch(a){if(a instanceof Fe){let o=a.check?` check ${a.check}`:"",s=a.measurement_id??n.id,c=new ve(`assurance gate ${e} assertion ${t} measurement ${s} source ${a.source_kind}${o} field ${a.field} could not resolve: ${a.message}`,{gate_id:e,assertion_id:t,measurement_id:s,source_kind:a.source_kind,field:a.field,...a.check?{check:a.check}:{}});throw c.cause=a,c}throw a}}async function dc(e,t,n,r){jt(t);let i=t.gates.find(c=>c.id===e);if(!i)throw new ve(`assurance gate ${e} not found`);if(!i.triggers.includes(r.trigger))throw new ve(`assurance gate ${e} does not declare trigger ${r.trigger}`);qp(i,t,n,r.trigger);let a=await sc(i.assertion_ids,tc,async c=>{let l=t.assertions.find(f=>f.id===c),d=t.measurements.find(f=>f.id===l.measurement_id),u=n;if(l.scope.kind==="active"){let f=new Set(n.terminal_statuses??["closed","canceled"]);u={...n,items:n.items.filter(g=>!f.has(g.status))}}else if(l.scope.kind==="filter"){let f=l.scope.measurement_id,g=t.measurements.find(v=>v.id===f),h=await Qs(i.id,l.id,g,n,t.measurements),w=new Set(h.contributors);u={...n,items:n.items.filter(v=>w.has(v.id))}}let m=n.items.find(f=>f.id===l.owner_item_id),p=m!==void 0&&new Set(n.terminal_statuses??["closed","canceled"]).has(m.status);return zp(l,await Qs(i.id,l.id,d,u,t.measurements),{owner_terminal:p})}),o=a.some(c=>c.verdict==="fail"&&c.enforcement==="block"),s=a.some(c=>c.verdict==="fail"&&c.enforcement==="warn");return{gate_id:i.id,tree_id:n.tree_id,trigger:r.trigger,dry_run:r.dry_run===!0,evaluated_at:new Date().toISOString(),verdict:o?"block":s?"warn":"pass",exit_code:o?1:0,assertions:a,assertions_total:a.length,row_contract:{row_keys:["assertions"],jq_selector:".assertions[]"},cost:oc(a.map(c=>c.cost),Math.max(0,...a.map(c=>c.cost.duration_ms)))}}function fr(e){return xp.join(e,"assurance.json")}async function uc(e){let t=await X(fr(e));return t===null?sn():hr(t)}function hr(e){try{return jt(JSON.parse(e))}catch(t){throw new y("The assurance registry is invalid. Repair or restore .agents/pm/assurance.json and retry.",_.GENERIC_FAILURE,{code:"assurance_registry_invalid",reason:String(t),nextSteps:["Restore a valid assurance.json from version control or repair its declaration references.","Run pm assurance list measurement after the repair."]})}}function gr(e,t){return t==="measurement"?e.measurements:t==="assertion"?e.assertions:e.gates}function Gp(e,t){e==="measurement"?Mi(t):e==="assertion"?Li(t):ic(t)}async function cn(e,t){let n=structuredClone(gr(await uc(e),t));return{items:n,count:n.length,row_contract:{row_keys:["items"],jq_selector:".items[]"}}}async function Ui(e,t,n){let r=gr(await uc(e),t).find(i=>i.id===n);if(!r)throw new TypeError(`assurance ${t} ${n} not found`);return structuredClone(r)}async function _r(e,t,n,r={}){Gp(t,n);let i=await I(e),a=Y(r.author,i.author_default),o=await ir({pmRoot:e,filePath:fr(e),op:`assurance:${t}:put`,author:a,message:r.message,lockTtlSeconds:mr,lockWaitMs:pr,mutate:s=>{let c=s===null?sn():hr(s),l=gr(c,t),d=l.findIndex(m=>m.id===n.id),u=d<0?"created":"updated";if(t==="assertion"&&d>=0&&Cp(l[d],n)){let m=n.authorization_decision;if(!m||!r.authorized_decision_ids?.includes(m))throw new N(`loosening assertion ${n.id} requires a verified authorization_decision`)}return d<0?l.push(structuredClone(n)):l[d]=structuredClone(n),jt(c),{raw:`${JSON.stringify(c,null,2)}
1
+ import{a as ki,c as Wn,d as Bn,e as Zo,g as Qo,h as Si,i as es,j as At,k as Rt,l as ts,m as ns,n as Ei,o as rs,p as It,q as Ct,r as is,s as as,t as Ai}from"./chunk-OM65KHGF.js";import{e as Xn,f as Ri}from"./chunk-325UXIO7.js";import{C as Kn,a as Ho,g as bi,i as Jo}from"./chunk-AZBACT5T.js";import{Z as Xs,l as Ks,n as Ys}from"./chunk-RIHDMCUM.js";import{$ as zs,Aa as Js,Ba as Vs,Da as Di,I as lr,J as Ds,K as $i,L as an,N as Ti,R as Ps,S as Ns,T as Ms,U as Ls,V as dr,X as Fs,Y as js,Z as Us,_ as ht,aa as Nt,ba as qs,ca as Oi,da as Mt,e as Is,ea as Gs,f as Cs,fa as Ws,g as $s,t as nn,u as Ts,ua as Bs,v as rn,va as ur,w as Os,za as Hs}from"./chunk-FUREQLQN.js";import{a as Vo,b as Hn,c as xi,d as Ko,e as Yo,f as We,g as Jn,h as Xo,i as it}from"./chunk-M32HFIQB.js";import{$a as ks,Ba as ys,Bb as Rs,Na as ws,Sa as ue,Ta as nr,U as Y,Ua as vs,V as $,Va as Ci,Wa as rr,Xa as ir,Ya as ar,Za as bs,_ as de,_a as Te,ab as I,b as ps,bb as or,d as fs,db as xs,ea as gs,fa as Qn,ia as er,ib as Ss,ja as _s,jb as Es,l as z,ma as $t,o as re,oa as Tt,ob as sr,q as He,qb as As,r as hs,ra as tr,rb as Ot,s as Zn,sb as Dt,tb as Pt,ub as Je,vb as cr,za as Ii,zb as ft}from"./chunk-KYZ6JGPL.js";import{Ba as vi,Ca as Wo,Da as Bo,E as Mo,Ea as Et,F as Lo,G as q,Ga as Ne,Ia as Me,Ka as se,L as tn,La as Ae,M as L,N as pt,Na as we,O as qn,Oa as Le,P as K,R as Fo,S as Gn,Sa as Be,Ua as Vn,W as Z,Ya as Yn,Z as jo,Za as cs,_a as ls,a as Io,ba as Uo,d as Co,e as $o,ea as _i,ga as yi,h as St,p as gi,q as A,r as zn,s as j,sa as zo,t as X,ta as qo,u as le,x as ye,y as Ee,z as No}from"./chunk-JWKEDZJI.js";import{a as ds,b as us,d as ms}from"./chunk-UGSS4F5X.js";import{O as To,Q as Oo,S as Do,U as Po,V as Un,Y as _,Z as y,a as Fn,aa as oe,ba as Go,ca as wi,d as jn,fa as os,oa as ss,t as hi}from"./chunk-Q47EX4DI.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]="d2d5135a-8110-527e-8530-653b25b792a4")}catch{}})();var N=class extends TypeError{constructor(t){super(t),this.name="AssuranceMutationRefusalError"}},ve=class extends TypeError{context;constructor(t,n={}){super(t),this.name="AssuranceEvaluationRefusalError",this.context=n}},Fe=class extends TypeError{measurement_id;source_kind;field;check;constructor(t,n){super(t),this.name="AssuranceSourceResolutionError",this.measurement_id=n.measurement_id,this.source_kind=n.source_kind,this.field=n.field,this.check=n.check}};async function Lt(e){try{return await e()}catch(t){throw t instanceof N?new y(t.message,_.USAGE,{code:"invalid_argument_value",reason:"assurance_mutation_refused"}):t}}async function Zs(e){try{return await e()}catch(t){throw t instanceof ve?new y(t.message,_.USAGE,{code:"invalid_argument_value",reason:"assurance_evaluation_refused",...t.context}):t}}import{createHash as kp}from"node:crypto";import xp 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]="b911b43d-d14d-5e4f-a35e-5020b1a84542")}catch{}})();var Ft=1e3;(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]="2bf52d6d-7e4f-5ec5-86bd-3e817ef521bb")}catch{}})();var ec=1,gt=["pre-commit","pre-push","pre-merge","ci","pre-release","post-release","scheduled","on-claim","on-close"],Pi=["items","dependency_kind","graph","validate","health","history","links","provider","derived"],Sp=["ceiling","floor","equals","zero","monotone_nondecreasing","monotone_nonincreasing","subset_of"],Ep=/^[a-z0-9]+(?:[._-][a-z0-9]+)*$/,mr=30,pr=5e3,tc=4,Ap=50;function Ve(e,t){if(!Ep.test(e))throw new N(`${t} must be a stable lowercase id`)}function Rp(e,t){if(!Number.isFinite(e)||e<0)throw new N(`${t} must be a finite non-negative number`)}function on(e){let t=Sp.filter(i=>e[i]!==void 0);if(t.length!==1)throw new N(`assertion ${e.id} must declare exactly one polarity`);let n=t[0],r=e[n];return{polarity:n,value:n==="zero"?0:r}}function Ni(e,t){return oe(e)===oe(t)}function nc(e,t){if(t.polarity==="equals")return Ni(e,t.value);if(t.polarity==="subset_of"){if(!Array.isArray(e)||!Array.isArray(t.value))return!1;let r=t.value;return e.every(i=>r.includes(i))}if(typeof e!="number")return!1;let n=t.value;return t.polarity==="ceiling"||t.polarity==="monotone_nonincreasing"?e<=n:t.polarity==="floor"||t.polarity==="monotone_nondecreasing"?e>=n:e===0}function rc(e){let t=on(e),n=e.negative_control.cases;return n.some(r=>r.expected==="pass")&&n.some(r=>r.expected==="fail")&&n.every(r=>nc(r.observed,t)===(r.expected==="pass"))}function Ip(e,t){if(e.polarity!==t.polarity)return!0;if(typeof e.value=="number"&&typeof t.value=="number")return e.polarity==="ceiling"||e.polarity==="monotone_nonincreasing"?t.value>e.value:e.polarity==="floor"||e.polarity==="monotone_nondecreasing"?t.value<e.value:t.value!==e.value;if(e.polarity==="subset_of"){let n=e.value,r=t.value;return!Array.isArray(n)||!Array.isArray(r)||r.some(i=>!n.includes(i))}return!Ni(e.value,t.value)}function Cp(e,t){if(e.measurement_id!==t.measurement_id||e.owner_item_id!==t.owner_item_id||oe(e.scope)!==oe(t.scope))return!0;let n={observe:0,warn:1,block:2},r=(e.lifetime??"hold")==="hold"&&(t.lifetime??"hold")==="retire";return Ip(on(e),on(t))||n[t.enforcement]<n[e.enforcement]||r}function $p(e){if(e.state!==void 0&&!(e.state==="present"||e.state==="missing"))throw new N("items source state must be present or missing");let t=Object.hasOwn(e,"equals"),n=e.state!==void 0,r=Number(t)+Number(n);if(e.field!==void 0&&r!==1)throw new N("items source with field requires exactly one of equals or state");if(e.field===void 0&&r!==0)throw new N("items source equals/state requires field")}function Mi(e){Ve(e.id,"measurement.id"),e.max_cost!==void 0&&Rp(e.max_cost,"measurement.max_cost");let t=e.source;if(Object.prototype.toString.call(t)!=="[object Object]")throw new N(`measurement.source.kind must be one of ${Pi.join(", ")}`);let n=Reflect.get(t,"kind");if(!Pi.includes(n))throw new N(`measurement.source.kind must be one of ${Pi.join(", ")}`);let r=t;if(r.kind==="items"&&$p(r),r.kind==="dependency_kind"&&(typeof r.dependency_kind!="string"||r.dependency_kind.trim().length===0))throw new N("dependency_kind source requires dependency_kind");if((r.kind==="graph"||r.kind==="validate"||r.kind==="health")&&(typeof r.field!="string"||r.field.trim().length===0))throw new N(`${r.kind} source requires field`);return r.kind==="provider"&&(Ve(r.provider,"provider source provider"),Ve(r.key,"provider source key")),e}function Li(e){if(Ve(e.id,"assertion.id"),Ve(e.measurement_id,"assertion.measurement_id"),typeof e.owner_item_id!="string"||e.owner_item_id.trim().length===0)throw new N("assertion.owner_item_id is required");let t=on(e);if(typeof t.value=="number"&&!Number.isFinite(t.value))throw new N(`assertion.${t.polarity} must be a finite number`);if(e.lifetime==="retire"&&(typeof e.retire_reason!="string"||e.retire_reason.trim().length===0))throw new N("retired assertion requires retire_reason");e.scope.kind==="filter"&&Ve(e.scope.measurement_id,"assertion.scope.measurement_id");let n=e.negative_control?.cases;if(!Array.isArray(n)||!n.some(r=>r.expected==="pass")||!n.some(r=>r.expected==="fail"))throw new N("assertion negative control requires pass and fail cases");if(!rc(e))throw new N(`assertion ${e.id} negative control does not prove its bound`);return e}function Tp(e){if(!Array.isArray(e.allowed_providers))throw new N("gate provider_policy.allowed_providers must be an array");for(let t of e.allowed_providers)Ve(t,"gate.provider_policy.allowed_provider");if(typeof e.triggers!="object"||e.triggers===null||Array.isArray(e.triggers))throw new N("gate provider_policy.triggers must be an object");for(let[t,n]of Object.entries(e.triggers)){if(!gt.includes(t))throw new N(`gate provider policy has unknown trigger ${t}`);if(typeof n!="object"||n===null||!["low","medium","high"].includes(n.max_cost_class)||typeof n.allow_network!="boolean")throw new N(`gate provider policy trigger ${t} is invalid`)}}function ic(e){if(Ve(e.id,"gate.id"),!Array.isArray(e.assertion_ids))throw new N("gate.assertion_ids is required and must be an array");if(e.assertion_ids.length===0)throw new N("gate requires at least one assertion");for(let t of e.assertion_ids)Ve(t,"gate.assertion_id");if(!Array.isArray(e.triggers))throw new N(`gate.triggers is required and must be an array of ${gt.join(", ")}`);if(e.triggers.length===0)throw new N("gate requires at least one trigger");for(let t of e.triggers)if(!gt.includes(t))throw new N(`gate trigger must be one of ${gt.join(", ")}`);return e.provider_policy&&Tp(e.provider_policy),e}function jt(e){if(e.version!==ec)throw new N(`unsupported assurance document version ${String(e.version)}`);let t=new Set;for(let r of e.measurements){if(Mi(r),t.has(`measurement:${r.id}`))throw new N(`duplicate measurement ${r.id}`);t.add(`measurement:${r.id}`)}for(let r of e.assertions){if(Li(r),t.has(`assertion:${r.id}`))throw new N(`duplicate assertion ${r.id}`);t.add(`assertion:${r.id}`)}for(let r of e.gates){ic(r);let i=r.assertion_ids.filter(a=>!e.assertions.some(o=>o.id===a));if(i.length>0)throw new N(`gate ${r.id} references missing assertions: ${i.join(", ")}`);if(t.has(`gate:${r.id}`))throw new N(`duplicate gate ${r.id}`);t.add(`gate:${r.id}`)}let n=new Set(e.measurements.map(r=>r.id));for(let[r,i]of ac(e))if(!n.has(r))throw new N(`${i.join(", ")} references missing measurement ${r}`);return e}function Fi(e,t){if("measurement"in e){t.push(e.measurement);return}if("operator"in e)for(let n of e.operands)Fi(n,t)}function ac(e){let t=new Map,n=(r,i)=>{let a=t.get(r)??[];a.push(i),t.set(r,a)};for(let r of e.assertions)n(r.measurement_id,`assertion ${r.id}`),r.scope.kind==="filter"&&n(r.scope.measurement_id,`assertion ${r.id} scope`);for(let r of e.measurements){if(r.source.kind!=="derived")continue;let i=[];Fi(r.source.expression,i);for(let a of i)n(a,`derived measurement ${r.id}`)}return t}function Op(e,t){let n=e.assertion_ids.flatMap(a=>{let o=t.assertions.find(s=>s.id===a);return[o.measurement_id,...o.scope.kind==="filter"?[o.scope.measurement_id]:[]]}),r=new Set,i=new Set;for(;n.length>0;){let a=n.pop();if(r.has(a))continue;r.add(a);let o=t.measurements.find(s=>s.id===a);o.source.kind==="provider"?i.add(o.source.provider):o.source.kind==="derived"&&Fi(o.source.expression,n)}return i}function sn(){return{version:ec,measurements:[],assertions:[],gates:[]}}function Dp(e,t){let n=t.items.filter(r=>(e.statuses===void 0||e.statuses.includes(r.status))&&(e.types===void 0||e.types.includes(r.type))&&(e.tags===void 0||e.tags.every(i=>r.tags?.includes(i)))&&(e.field===void 0||(()=>{let i=r[e.field];if(e.state!==void 0){let a=i==null||i===""||Array.isArray(i)&&i.length===0;return e.state==="missing"?a:!a}return Ni(i,e.equals)})()));return{value:n.length,population_size:t.items.length,cost:t.items.length,contributors:n.map(r=>r.id)}}function Pp(e,t){let n=[],r=yi(e.dependency_kind)??e.dependency_kind.trim().toLowerCase();for(let i of t.items)for(let a of i.dependencies??[])(yi(a.kind)??a.kind.trim().toLowerCase())===r&&n.push(`${i.id}->${a.id}`);return{value:n.length,population_size:t.items.length,cost:t.items.length,contributors:n}}function Np(e,t){return{value:t.history.filter(r=>(e.op===void 0||r.op===e.op)&&(e.author===void 0||r.author===e.author)&&(e.harness===void 0||r.agent_harness===e.harness)&&(e.model===void 0||r.agent_model===e.model)).length,population_size:t.history.length,cost:t.history.length}}function Mp(e,t){let n=t.items.filter(r=>{let i=r[e.link],a=Array.isArray(i)&&i.length>0;return e.state==="present"?a:!a});return{value:n.length,population_size:t.items.length,cost:t.items.length,contributors:n.map(r=>r.id)}}function Lp(e,t){let n=e.source;return n.kind==="items"?Dp(n,t):n.kind==="dependency_kind"?Pp(n,t):n.kind==="history"?Np(n,t):n.kind==="links"?Mp(n,t):null}function oc(e,t){return e.reduce((n,r)=>({units:n.units+r.units,items_scanned:n.items_scanned+r.items_scanned,history_entries:n.history_entries+r.history_entries,provider_calls:n.provider_calls+r.provider_calls,duration_ms:t}),{units:0,items_scanned:0,history_entries:0,provider_calls:0,duration_ms:t})}function Fp(e,t){if(t.length===0)throw new TypeError(`derived ${e} requires operands`);if(e==="add")return t.reduce((n,r)=>n+r,0);if(e==="subtract")return t.slice(1).reduce((n,r)=>n-r,t[0]);if(e==="multiply")return t.reduce((n,r)=>n*r,1);if(e==="divide"){if(t.slice(1).includes(0))throw new TypeError("derived divide cannot divide by zero");return t.slice(1).reduce((n,r)=>n/r,t[0])}return e==="min"?Math.min(...t):Math.max(...t)}async function sc(e,t,n){let r=new Array(e.length),i=0,a=Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let o=i;i+=1,r[o]=await n(e[o],o)}});return await Promise.all(a),r}async function cc(e,t,n,r,i){if("literal"in e)return{value:e.literal,costs:[],population_size:0,contributors:[]};if("measurement"in e){let o=n.find(l=>l.id===e.measurement);if(!o)throw new TypeError(`derived measurement references missing ${e.measurement}`);let s=await lc(o,t,n,r,i);if(typeof s.value!="number")throw new TypeError(`derived measurement ${o.id} is not numeric`);let c=i.charged.has(o.id)?[]:[s.cost];return i.charged.add(o.id),{value:s.value,costs:c,population_size:s.population_size,contributors:s.contributors}}let a=await sc(e.operands,tc,o=>cc(o,t,n,r,i));return{value:Fp(e.operator,a.map(o=>o.value)),costs:a.flatMap(o=>o.costs),population_size:Math.max(0,...a.map(o=>o.population_size)),contributors:[...new Set(a.flatMap(o=>o.contributors))]}}async function jp(e,t,n,r,i){Mi(e);let a=Date.now(),o,s=[],c=0;if(e.source.kind==="derived"){let u=await cc(e.source.expression,t,n,[...r,e.id],i);o={value:u.value,population_size:u.population_size,cost:0,contributors:u.contributors},s=u.costs}else{let u=Lp(e,t);u!==null?o=u:(o=await t.external(e.source),c=1)}let l={units:o.cost,items_scanned:e.source.kind==="items"||e.source.kind==="dependency_kind"||e.source.kind==="links"?t.items.length:0,history_entries:e.source.kind==="history"?t.history.length:0,provider_calls:c,duration_ms:Date.now()-a},d=oc([...s,l],Date.now()-a);if(e.max_cost!==void 0&&d.units>e.max_cost)throw new ve(`measurement ${e.id} exceeded cost ceiling ${e.max_cost} with ${d.units}`);return{id:e.id,definition_fingerprint:`sha256:${kp("sha256").update(oe(e)).digest("hex")}`,value:o.value,population_size:o.population_size,cost:d,contributors:o.contributors??[]}}function lc(e,t,n,r,i){if(r.includes(e.id))throw new TypeError(`derived measurement cycle: ${[...r,e.id].join(" -> ")}`);let a=i.cache.get(e.id);if(a)return a;let o=jp(e,t,n,r,i).catch(s=>{if(s instanceof Fe&&s.measurement_id===void 0){let c={measurement_id:e.id,source_kind:s.source_kind,field:s.field,...s.check?{check:s.check}:{}},l=new Fe(s.message,c);throw l.cause=s,l}throw s});return i.cache.set(e.id,o),o}async function ji(e,t,n=[e]){return lc(e,t,n,[],{cache:new Map,charged:new Set})}function Up(e,t){return typeof e!="number"||typeof t.value!="number"?null:t.polarity==="ceiling"||t.polarity==="monotone_nonincreasing"?t.value-e:(t.polarity==="floor"||t.polarity==="monotone_nondecreasing",e-t.value)}function zp(e,t,n={}){Li(e);let r=on(e),i=e.lifetime==="retire"&&n.owner_terminal===!0;return{assertion_id:e.id,measurement_id:e.measurement_id,measurement_definition_fingerprint:t.definition_fingerprint,scope:e.scope,population_size:t.population_size,observed:t.value,bound:r,distance:Up(t.value,r),verdict:i?"retired":nc(t.value,r)?"pass":"fail",enforcement:e.enforcement,negative_control_proven:rc(e),cost:t.cost,contributors:t.contributors}}function qp(e,t,n,r){let i=Op(e,t);if(i.size===0)return;let a=e.provider_policy,o=a?.triggers[r];if(!a||!o)throw new ve(`assurance gate ${e.id} refuses provider execution at trigger ${r} without an explicit provider policy`);let s=new Set(a.allowed_providers),c={low:0,medium:1,high:2};for(let l of i){if(!s.has(l))throw new ve(`assurance gate ${e.id} refuses provider ${l}`);let d=n.provider_capabilities?.[l];if(!d)throw new ve(`assurance provider ${l} has no declared capabilities`);if(c[d.cost_class]>c[o.max_cost_class])throw new ve(`assurance gate ${e.id} refuses ${d.cost_class}-cost provider ${l} at trigger ${r}`);if(d.network&&!o.allow_network)throw new ve(`assurance gate ${e.id} refuses network provider ${l} at trigger ${r}`)}}async function Qs(e,t,n,r,i){try{return await ji(n,r,i)}catch(a){if(a instanceof Fe){let o=a.check?` check ${a.check}`:"",s=a.measurement_id??n.id,c=new ve(`assurance gate ${e} assertion ${t} measurement ${s} source ${a.source_kind}${o} field ${a.field} could not resolve: ${a.message}`,{gate_id:e,assertion_id:t,measurement_id:s,source_kind:a.source_kind,field:a.field,...a.check?{check:a.check}:{}});throw c.cause=a,c}throw a}}async function dc(e,t,n,r){jt(t);let i=t.gates.find(c=>c.id===e);if(!i)throw new ve(`assurance gate ${e} not found`);if(!i.triggers.includes(r.trigger))throw new ve(`assurance gate ${e} does not declare trigger ${r.trigger}`);qp(i,t,n,r.trigger);let a=await sc(i.assertion_ids,tc,async c=>{let l=t.assertions.find(f=>f.id===c),d=t.measurements.find(f=>f.id===l.measurement_id),u=n;if(l.scope.kind==="active"){let f=new Set(n.terminal_statuses??["closed","canceled"]);u={...n,items:n.items.filter(g=>!f.has(g.status))}}else if(l.scope.kind==="filter"){let f=l.scope.measurement_id,g=t.measurements.find(v=>v.id===f),h=await Qs(i.id,l.id,g,n,t.measurements),w=new Set(h.contributors);u={...n,items:n.items.filter(v=>w.has(v.id))}}let m=n.items.find(f=>f.id===l.owner_item_id),p=m!==void 0&&new Set(n.terminal_statuses??["closed","canceled"]).has(m.status);return zp(l,await Qs(i.id,l.id,d,u,t.measurements),{owner_terminal:p})}),o=a.some(c=>c.verdict==="fail"&&c.enforcement==="block"),s=a.some(c=>c.verdict==="fail"&&c.enforcement==="warn");return{gate_id:i.id,tree_id:n.tree_id,trigger:r.trigger,dry_run:r.dry_run===!0,evaluated_at:new Date().toISOString(),verdict:o?"block":s?"warn":"pass",exit_code:o?1:0,assertions:a,assertions_total:a.length,row_contract:{row_keys:["assertions"],jq_selector:".assertions[]"},cost:oc(a.map(c=>c.cost),Math.max(0,...a.map(c=>c.cost.duration_ms)))}}function fr(e){return xp.join(e,"assurance.json")}async function uc(e){let t=await X(fr(e));return t===null?sn():hr(t)}function hr(e){try{return jt(JSON.parse(e))}catch(t){throw new y("The assurance registry is invalid. Repair or restore .agents/pm/assurance.json and retry.",_.GENERIC_FAILURE,{code:"assurance_registry_invalid",reason:String(t),nextSteps:["Restore a valid assurance.json from version control or repair its declaration references.","Run pm assurance list measurement after the repair."]})}}function gr(e,t){return t==="measurement"?e.measurements:t==="assertion"?e.assertions:e.gates}function Gp(e,t){e==="measurement"?Mi(t):e==="assertion"?Li(t):ic(t)}async function cn(e,t){let n=structuredClone(gr(await uc(e),t));return{items:n,count:n.length,row_contract:{row_keys:["items"],jq_selector:".items[]"}}}async function Ui(e,t,n){let r=gr(await uc(e),t).find(i=>i.id===n);if(!r)throw new TypeError(`assurance ${t} ${n} not found`);return structuredClone(r)}async function _r(e,t,n,r={}){Gp(t,n);let i=await I(e),a=Y(r.author,i.author_default),o=await ir({pmRoot:e,filePath:fr(e),op:`assurance:${t}:put`,author:a,message:r.message,lockTtlSeconds:mr,lockWaitMs:pr,mutate:s=>{let c=s===null?sn():hr(s),l=gr(c,t),d=l.findIndex(m=>m.id===n.id),u=d<0?"created":"updated";if(t==="assertion"&&d>=0&&Cp(l[d],n)){let m=n.authorization_decision;if(!m||!r.authorized_decision_ids?.includes(m))throw new N(`loosening assertion ${n.id} requires a verified authorization_decision`)}return d<0?l.push(structuredClone(n)):l[d]=structuredClone(n),jt(c),{raw:`${JSON.stringify(c,null,2)}
2
2
  `,result:{changed:!0,action:u,kind:t,id:n.id}}}});return{...o.result,changed:o.changed}}async function zi(e,t,n={}){let r=sn();r.measurements=structuredClone(t.measurements),r.assertions=structuredClone(t.assertions),r.gates=structuredClone(t.gates),jt(r);let i=await I(e),a=Y(n.author,i.author_default),o=await ir({pmRoot:e,filePath:fr(e),op:"assurance:bundle:apply",author:a,message:n.message,lockTtlSeconds:mr,lockWaitMs:pr,mutate:s=>{let c=s===null?sn():hr(s),l=[],d=[],u=(m,p,f)=>{for(let g of p){let h=m.find(w=>w.id===g.id);if(!h){m.push(structuredClone(g)),l.push(`${f}:${g.id}`);continue}if(oe(h)!==oe(g))throw new N(`assurance bundle refuses to replace divergent ${f} ${g.id}`);d.push(`${f}:${g.id}`)}};return u(c.measurements,r.measurements,"measurement"),u(c.assertions,r.assertions,"assertion"),u(c.gates,r.gates,"gate"),jt(c),{raw:`${JSON.stringify(c,null,2)}
3
3
  `,result:{changed:l.length>0,created_ids:l,unchanged_ids:d}}}});return{...o.result,changed:o.changed}}async function mc(e,t,n,r={}){let i=await I(e),a=Y(r.author,i.author_default),o=await ir({pmRoot:e,filePath:fr(e),op:`assurance:${t}:remove`,author:a,message:r.message,lockTtlSeconds:mr,lockWaitMs:pr,mutate:s=>{let c=s===null?sn():hr(s);if(t==="measurement"){let u=ac(c).get(n);if(u&&u.length>0)throw new N(`assurance measurement ${n} is referenced by ${u.join(", ")}`)}if(t==="assertion"&&c.gates.some(u=>u.assertion_ids.includes(n)))throw new N(`assurance assertion ${n} is referenced by gate`);let l=gr(c,t),d=l.findIndex(u=>u.id===n);if(d<0)throw new N(`assurance ${t} ${n} not found`);return l.splice(d,1),jt(c),{raw:`${JSON.stringify(c,null,2)}
4
4
  `,result:{changed:!0,action:"removed",kind:t,id:n}}}});return{...o.result,changed:o.changed}}async function pc(e,t,n={}){if(t.dry_run)throw new TypeError("dry-run assurance verdicts are not persisted");let r=await I(e);await rr({pmRoot:e,op:"assurance:gate:verdict",author:Y(n.author,r.author_default),context:{assurance_verdict:t},message:n.message??`Assurance gate ${t.gate_id} returned ${t.verdict}`,lockTtlSeconds:mr,lockWaitMs:pr})}async function fc(e,t={}){let n=t.limit??Ap;if(!Number.isInteger(n)||n<1||n>Ft)throw new TypeError(`assurance verdict limit must be an integer from 1 through ${Ft}`);return(await tr(nr(e),ue)).reverse().filter(i=>i.op==="assurance:gate:verdict").map(i=>i.context?.assurance_verdict).filter(i=>typeof i=="object"&&i!==null&&"gate_id"in i).filter(i=>t.gate_id===void 0||i.gate_id===t.gate_id).slice(0,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]="05c29627-6763-5aee-8579-71e563a98780")}catch{}})();var wr=["software-delivery","research","agent-evaluation","operations"];function hc(e,t,n,r,i){return{id:e,measurement_id:t,owner_item_id:n,scope:{kind:"active"},ceiling:r,lifetime:"hold",enforcement:i,negative_control:{cases:[{observed:r,expected:"pass"},{observed:r+1,expected:"fail"}]}}}function yr(e,t,n,r,i){let a=`preset-${e}`,o=i.map(c=>({id:`${a}-missing-${c}`,description:`Active items missing ${c} evidence.`,source:{kind:"links",link:c,state:"missing"}})),s=o.map(c=>hc(`${c.id}-zero`,c.id,r,0,"warn"));return{id:e,title:t,description:n,declarations:{measurements:o,assertions:s,gates:[{id:`${a}-readiness`,description:n,assertion_ids:s.map(c=>c.id),triggers:["ci","scheduled"]}]}}}function vr(e,t){return e==="software-delivery"?yr(e,"Software delivery","Warn when active delivery work lacks executable tests or documentation.",t,["tests","docs"]):e==="research"?yr(e,"Research","Warn when active research work lacks reproducibility files or documentation.",t,["files","docs"]):e==="agent-evaluation"?yr(e,"Agent evaluation","Warn when active evaluation work lacks executable scenarios or recorded artifacts.",t,["tests","files"]):yr(e,"Operations","Warn when active operational work lacks runbook documentation or repair evidence.",t,["docs","files"])}function gc(e,t,n,r={}){return zi(e,vr(t,n).declarations,r)}async function _c(e,t){let n=new Set(e.terminal_statuses??["closed","canceled"]),r={...e,items:e.items.filter(a=>!n.has(a.status))};return await Promise.all(["files","tests","docs"].map(async a=>{let o={id:`derived-active-missing-${a}`,description:`Observed active items missing ${a} evidence.`,source:{kind:"links",link:a,state:"missing"}},c=(await ji(o,r)).value,l=hc(`${o.id}-ceiling`,o.id,t,c,"observe"),d=`active-missing-${a}`;return{id:d,population_size:r.items.length,scope:{kind:"active"},observed:c,declarations:{measurements:[o],assertions:[l],gates:[{id:`derived-${d}`,description:`Observe the accepted ${a} evidence baseline.`,assertion_ids:[l.id],triggers:["ci","scheduled"]}]}}}))}function yc(e,t,n={}){return zi(e,{measurements:t.flatMap(r=>r.declarations.measurements),assertions:t.flatMap(r=>r.declarations.assertions),gates:t.flatMap(r=>r.declarations.gates)},n)}async function wc(e,t,n,r={}){let i=t.enforcement==="observe"?"warn":"block";if(t.enforcement==="block"||n!==i)throw new TypeError(`assurance assertion ${t.id} promotion must be ${t.enforcement} -> ${i}`);return _r(e,"assertion",{...t,enforcement:n},{...r,message:r.message??`Promote assurance assertion ${t.id} from ${t.enforcement} to ${n}`})}import kc from"node:fs/promises";import{createRequire as Wp}from"node:module";import be 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]="c21b1a94-1d80-57c0-b090-c4831fc505a2")}catch{}})();function vc(e,t){let n=be.relative(t,e);if(n.length>0&&n!==".."&&!n.startsWith(`..${be.sep}`)&&!be.isAbsolute(n))return n.split(be.sep).join("/");let r=be.resolve(e),i=0xcbf29ce484222325n;for(let o=0;o<r.length;o+=1)i^=BigInt(r.charCodeAt(o)),i=BigInt.asUintN(64,i*0x100000001b3n);return`<external>/${i.toString(16).padStart(16,"0")}/${be.basename(be.dirname(e))}/package.json`}function Bp(e){return e.includes(`${be.sep}.pnpm${be.sep}`)?"pnpm":e.includes(`${be.sep}node_modules${be.sep}`)?"npm":"other"}async function bc(e){try{let t=JSON.parse(await kc.readFile(e,"utf8"));return t.name==="@unbrained/pm-cli"&&typeof t.version=="string"&&t.version.trim().length>0?t.version.trim():void 0}catch{return}}async function qi(e){try{return await kc.realpath(e)}catch{return be.resolve(e)}}async function xc(e,t,n=Ee(import.meta.url,["../../.."])){let r=await qi(t),i=await qi(be.join(n,"package.json")),a=await bc(i),o=new Map;a!==void 0&&o.set(i,{version:a,path:vc(i,r),layout:"host",consumers:["pm-cli-host"]});for(let l of e)try{let d=Wp(l.entry_path).resolve("@unbrained/pm-cli/package.json"),u=await qi(d),m=await bc(u);if(m===void 0)continue;let p=u,f=o.get(p);if(f){f.consumers.includes(l.name)||(f.consumers.push(l.name),f.consumers.sort((g,h)=>g.localeCompare(h)));continue}o.set(p,{version:m,path:vc(u,r),layout:Bp(u),consumers:[l.name]})}catch{}let s=[...o.values()].sort((l,d)=>l.path.localeCompare(d.path)),c=a===void 0?[]:s.filter(l=>l.version!==a);return{host_version:a??null,copies:s,mismatches:c,warnings:c.map(l=>`extension_host_pm_cli_version_skew:${a}:${l.version}:${l.consumers.join("+")}`)}}import{createHash as Tc}from"node:crypto";import dn from"node:fs/promises";import un from"node:path";import{Option as hE}from"commander";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="8d60b13c-c58a-506f-adc9-2414dd69edef")}catch{}})();function Hp(e,t){let n=[],r=new Set;for(let i of t.keys){if(!Object.hasOwn(e,i))continue;let a=e[i];if(a!=null){if(typeof a=="string"){n.push(a);continue}if(!Array.isArray(a)||!a.every(o=>typeof o=="string"))return;r.has(a)||(r.add(a),n.push(...a))}}return n.length>0?n.join("; "):void 0}function br(e,t){return e.find(r=>r.target===t)??{target:t,keys:[t]}}function P(e,t){return e[t]===!0?!0:void 0}function Ke(e,t){return e[t]===!1?!0:void 0}function Sc(e,t){return t.some(n=>e[n]===!0)?!0:void 0}function Ec(e,t){for(let[n,r]of Object.entries(t))n==="__proto__"||n==="constructor"||n==="prototype"||Object.hasOwn(e,n)||(e[n]=r)}function Ac(e){let t=i=>bi(e,br(Xn,i)),n=i=>Jo(e,br(Ri,i)),r={title:t("title"),description:t("description"),body:t("body"),status:t("status"),closeReason:t("closeReason"),priority:t("priority"),type:t("type"),tags:t("tags"),addTags:n("addTags"),removeTags:n("removeTags"),deadline:t("deadline"),estimatedMinutes:t("estimatedMinutes"),acceptanceCriteria:Hp(e,br(Ri,"acceptanceCriteria")),addAc:n("addAc"),removeAc:n("removeAc"),definitionOfReady:t("definitionOfReady"),order:t("order"),rank:t("rank"),goal:t("goal"),objective:t("objective"),value:t("value"),impact:t("impact"),outcome:t("outcome"),whyNow:t("whyNow"),author:t("author"),message:t("message"),force:!!e.force,ownershipMetadataBypass:e.ownershipMetadataBypass===!0?!0:void 0,ownershipDependencyBypass:e.ownershipDependencyBypass===!0?!0:void 0,assignee:t("assignee"),parent:t("parent"),allowUnresolvedDeps:Sc(e,["allowUnresolvedDeps","allow_unresolved_deps"])===!0,reviewer:t("reviewer"),risk:t("risk"),confidence:t("confidence"),sprint:t("sprint"),release:t("release"),blockedBy:t("blockedBy"),blockedReason:t("blockedReason"),unblockNote:t("unblockNote"),reporter:t("reporter"),severity:t("severity"),environment:t("environment"),reproSteps:t("reproSteps"),resolution:t("resolution"),expectedResult:t("expectedResult"),actualResult:t("actualResult"),affectedVersion:t("affectedVersion"),fixedVersion:t("fixedVersion"),component:t("component"),regression:e.regression===!0?"true":t("regression"),customerImpact:t("customerImpact"),dep:n("dep"),depRemove:n("depRemove"),replaceDeps:P(e,"replaceDeps"),replaceTests:P(e,"replaceTests"),replaceFiles:P(e,"replaceFiles"),replaceDocs:P(e,"replaceDocs"),comment:n("comment"),note:n("note"),learning:n("learning"),file:n("file"),test:n("test"),doc:n("doc"),reminder:n("reminder"),event:n("event"),typeOption:n("typeOption"),field:n("field"),unset:n("unset"),clearDeps:P(e,"clearDeps"),clearComments:P(e,"clearComments"),clearNotes:P(e,"clearNotes"),clearLearnings:P(e,"clearLearnings"),clearFiles:P(e,"clearFiles"),clearTests:P(e,"clearTests"),clearDocs:P(e,"clearDocs"),clearReminders:P(e,"clearReminders"),clearEvents:P(e,"clearEvents"),clearTypeOptions:P(e,"clearTypeOptions")};return Ec(r,e),r}function Q(e,t){let n=br(Ho,t),r=bi(e,n);if(r!==void 0)return r;for(let i of n.keys){let a=e[i];if(Array.isArray(a)){let o=a.filter(s=>typeof s=="string");if(o.length>0)return o.join(",")}if(t==="ids"&&typeof a=="string")return a;if(typeof a=="number"&&Number.isFinite(a))return String(a)}}function Jp(e){let t=P(e,"filterFilesMissing"),n=P(e,"filterDocsMissing");return{filterReviewerMissing:P(e,"filterReviewerMissing"),filterRiskMissing:P(e,"filterRiskMissing"),filterConfidenceMissing:P(e,"filterConfidenceMissing"),filterSprintMissing:P(e,"filterSprintMissing"),filterReleaseMissing:P(e,"filterReleaseMissing"),hasNotes:P(e,"hasNotes"),hasLearnings:P(e,"hasLearnings"),hasFiles:P(e,"hasFiles"),hasDocs:P(e,"hasDocs"),hasTests:P(e,"hasTests"),hasComments:P(e,"hasComments"),hasDeps:P(e,"hasDeps"),hasBody:P(e,"hasBody"),hasLinkedCommand:P(e,"hasLinkedCommand"),noNotes:Ke(e,"notes"),noLearnings:Ke(e,"learnings"),noFiles:Ke(e,"files")??t,filterFilesMissing:t,noDocs:Ke(e,"docs")??n,filterDocsMissing:n,noTests:Ke(e,"tests"),noComments:Ke(e,"comments"),noDeps:Ke(e,"deps"),emptyBody:P(e,"emptyBody"),noLinkedCommand:Ke(e,"linkedCommand")}}function Gi(e){let t={status:Q(e,"status"),type:Q(e,"type"),tag:Q(e,"tag"),priority:Q(e,"priority"),deadlineBefore:Q(e,"deadlineBefore"),deadlineAfter:Q(e,"deadlineAfter"),updatedAfter:Q(e,"updatedAfter"),updatedBefore:Q(e,"updatedBefore"),createdAfter:Q(e,"createdAfter"),createdBefore:Q(e,"createdBefore"),today:P(e,"today"),recent:P(e,"recent"),ids:Q(e,"ids"),assignee:Q(e,"assignee"),assigneeFilter:Q(e,"assigneeFilter"),parent:Q(e,"parent"),sprint:Q(e,"sprint"),release:Q(e,"release"),limit:Q(e,"limit"),offset:Q(e,"offset"),noTruncate:Ke(e,"truncate"),includeBody:P(e,"includeBody"),strictRead:P(e,"strictRead"),compact:P(e,"compact"),brief:P(e,"brief"),full:P(e,"full"),fields:Q(e,"fields"),sort:Q(e,"sort"),order:Q(e,"order"),tree:P(e,"tree"),treeDepth:Q(e,"treeDepth"),filterAcMissing:P(e,"filterAcMissing"),filterEstimatesMissing:Sc(e,["filterEstimatesMissing","filterEstimateMissing"]),filterResolutionMissing:P(e,"filterResolutionMissing"),filterMetadataMissing:P(e,"filterMetadataMissing"),...Jp(e)};return Ec(t,e),t}(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="0e153ece-4fc0-5134-97f0-c2315aff0031")}catch{}})();function C(e,t){let n=e[t];return typeof n=="string"&&n.trim().length>0?n:void 0}function ee(e,t){let n=e[t];return typeof n=="string"?n.trim().length>0?n:void 0:typeof n=="number"&&Number.isFinite(n)?String(n):void 0}function Vp(e,t){let n=e[t];return typeof n=="string"?n:typeof n=="number"&&Number.isFinite(n)?String(n):void 0}function ln(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Hi(e,t){if(typeof e=="number"){if(!Number.isInteger(e))throw new y(`${t} must be a finite integer.`,_.USAGE);return e}if(typeof e=="string"&&e.trim().length>0){let n=Number(e);if(!Number.isInteger(n))throw new y(`${t} must be a finite integer.`,_.USAGE);return n}}function SE(e,t){return typeof e.limit=="number"&&Number.isFinite(e.limit)?e.limit:typeof t.limit=="number"&&Number.isFinite(t.limit)?t.limit:C(e,"limit")??C(t,"limit")}function EE(e){let t=C(e,"outputFormat");return{json:!0,quiet:!0,author:C(e,"author"),path:C(e,"path"),noExtensions:e.noExtensions===!0||e.no_extensions===!0,noPager:!0,outputInclude:C(e,"outputInclude"),outputLimit:ee(e,"outputLimit"),outputBudget:ee(e,"outputBudget"),outputSession:C(e,"outputSession"),outputCursor:C(e,"outputCursor"),outputFormat:t==="json"||t==="toon"?t:void 0}}var Kp=new Set(["tags","blockedBy","blocked_by","skills","fields"]),Yp=new Set(["comment","note","learning","reminder","event","dep","depRemove","dep_remove","file","doc","test","unset","addGlob","add_glob","migrate","envSet","env_set","envClear","env_clear"]),Xp=new Set(["files","files-discover","docs","test","test-all"]),Zp=new Set(["claim","release","start-task","pause-task","close-task"]),Qp={list:["status","type","tag","priority","limit","offset"],search:["mode","status","type","tag","priority","limit"],create:["title","type","status","description","body","priority","tags","parent","createMode","create_mode","allowMissingParent","allowDuplicate"],update:["parent","allowMissingParent","completedAt"],copy:["allowDuplicate"],close:["duplicateOf","completedAt"],append:["body"]},ef=["outputInclude","outputLimit","outputBudget","outputFormat","outputSession","outputCursor"];function Ic(e,t){let n={},r=t!==void 0&&Xp.has(t),i=t==="files"||t==="files-discover"||t==="docs";for(let[a,o]of Object.entries(e)){if(Array.isArray(o)&&Kp.has(a)){n[a]=o.join(",");continue}if(a==="note"&&i){n[a]=o;continue}if(typeof o=="string"&&Yp.has(a)){n[a]=[o];continue}if(typeof o=="string"&&r&&(a==="add"||a==="remove")){n[a]=[o];continue}n[a]=o}return n}function AE(e,t){let n=Uo(e.options),r={},i=c=>{n[c]!==void 0||e[c]===void 0||(r[c]=e[c])};for(let c of Qp[t??""]??[])i(c);for(let c of ef)i(c);let a=Ic({...r,...n},t),o=C(e,"author"),s=t!==void 0&&Zp.has(t)?C(e,"assignee")??C(a,"assignee"):void 0;return o&&a.author===void 0?{...a,author:o}:s&&a.author===void 0?{...a,author:s}:a}function RE(e){if(e.addNote===void 0)return e;let t={...e};return t.note===void 0&&typeof t.addNote=="string"&&(t.note=t.addNote),delete t.addNote,t}function IE(e){let t={...e};return t.discoveryNote!==void 0&&t.note===void 0&&typeof t.discoveryNote=="string"&&(t.note=t.discoveryNote),delete t.discover,delete t.discoveryNote,t}function CE(e){let t=[],n=!0;for(let r of e.trim().toLowerCase()){if(r>="a"&&r<="z"||r>="0"&&r<="9"){t.push(r),n=!1;continue}n||(t.push("-"),n=!0)}return t.at(-1)==="-"&&t.pop(),t.join("")}function $E(e){return e.trim().toLowerCase().split(/\s+/).filter(Boolean).join(" ")}function Ji(e){return Array.isArray(e)?e.map(t=>String(t)).filter(t=>t.length>0):[]}function TE(e,t){let n=new Set(["action","args","author","cwd","fullChangedFields","id","options","path","query","reason","target"]),r={};for(let[a,o]of Object.entries(e))n.has(a)||(r[a]=o);let i={...r,...t};return delete i.args,i}function OE(e,t){return{changedFields:e.fullChangedFields===!0?"full":"compact",idOnly:e.idOnly===!0,runnerOptions:{...t}}}function Bi(e){return{type:ee(e,"filterType"),tag:ee(e,"filterTag"),priority:ee(e,"filterPriority"),deadlineBefore:ee(e,"filterDeadlineBefore"),deadlineAfter:ee(e,"filterDeadlineAfter"),updatedAfter:ee(e,"filterUpdatedAfter"),updatedBefore:ee(e,"filterUpdatedBefore"),createdAfter:ee(e,"filterCreatedAfter"),createdBefore:ee(e,"filterCreatedBefore"),ids:Vp(e,"ids"),assignee:ee(e,"filterAssignee"),assigneeFilter:ee(e,"filterAssigneeFilter")??ee(e,"filterAssignee_filter"),parent:ee(e,"filterParent"),sprint:ee(e,"filterSprint"),release:ee(e,"filterRelease"),limit:ee(e,"limit"),offset:ee(e,"offset")}}function Wi(e){if(typeof e=="string"&&e.trim().length>0)return e;if(Array.isArray(e))return Ji(e)}function kr(e){if(typeof e=="number"&&Number.isFinite(e)||typeof e=="string"&&e.trim().length>0)return e}function DE(e){let t=Wi(e.kind),n=Wi(e.exemptIsolate),r=Wi(e.exemptIsolateType);return{...t===void 0?{}:{kind:t},maxDepth:kr(e.maxDepth),limit:kr(e.limit),after:C(e,"after"),direction:C(e,"direction"),maxPaths:kr(e.maxPaths),sample:kr(e.sample),...n===void 0?{}:{exemptIsolate:n},...r===void 0?{}:{exemptIsolateType:r},saveBaseline:e.saveBaseline===!0,rebuild:e.rebuild===!0,clear:e.clear===!0,summary:e.summary===!0,...e.full===!0?{full:!0}:{}}}function PE(e){return{status:C(e,"filterStatus"),list:ln(e.list)?Gi(e.list):Bi(e),reason:C(e,"reason"),resolution:C(e,"resolution"),expectedResult:C(e,"expectedResult")??C(e,"expected_result")??C(e,"expected"),actualResult:C(e,"actualResult")??C(e,"actual_result")??C(e,"actual"),validateClose:C(e,"validateClose")??C(e,"validate_close"),author:C(e,"author"),message:C(e,"message"),force:e.force===!0?!0:void 0,dryRun:e.dryRun===!0||e.dry_run===!0?!0:void 0,rollback:C(e,"rollback"),checkpoint:e.checkpoint===!1||e.noCheckpoint===!0||e.no_checkpoint===!0?!1:void 0}}var tf=new Set(["filterStatus","filterType","filterTag","filterPriority","filterDeadlineBefore","filterDeadlineAfter","filterUpdatedAfter","filterUpdatedBefore","filterCreatedAfter","filterCreatedBefore","filterAssignee","filterAssigneeFilter","filterAssignee_filter","filterParent","filterSprint","filterRelease","ids","list","update","limit","offset","dryRun","dry_run","rollback","checkpoint","noCheckpoint","no_checkpoint"]);function Rc(e){let t={};for(let[n,r]of Object.entries(e))tf.has(n)||(t[n]=r);return Cc(t)}function Cc(e){let t=Ic(e,"update-many");for(let n of Xn)for(let r of n.keys){let i=t[r];typeof i=="number"&&Number.isFinite(i)&&(t[r]=String(i))}return Ac(t)}function NE(e){if(ln(e.list)||ln(e.update)){let t=ln(e.update)?e.update:Rc(e);return{status:ee(e,"filterStatus"),list:ln(e.list)?Gi(e.list):Bi(e),update:Cc(t),dryRun:e.dryRun===!0||e.dry_run===!0?!0:void 0,rollback:C(e,"rollback"),checkpoint:e.checkpoint===!1||e.noCheckpoint===!0||e.no_checkpoint===!0?!1:void 0}}return{status:ee(e,"filterStatus"),list:Bi(e),update:Rc(e),dryRun:e.dryRun===!0||e.dry_run===!0?!0:void 0,rollback:C(e,"rollback"),checkpoint:e.checkpoint===!1||e.noCheckpoint===!0||e.no_checkpoint===!0?!1:void 0}}(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]="b389e521-f689-5895-a5f4-08c3866b3ea3")}catch{}})();function Re(e,t){throw new y(e,_.USAGE,t)}var nf="2026-07-15T06:22:12.276Z",rf=Date.parse(nf),af=[["attributed","attributed"],["legacy_unknown","actionable_unknown"]],$c=e=>typeof e=="string"?e:"",Oc=e=>{let t=e??{},n=$c(t.author).trim().toLowerCase(),r=Number(["","unknown"].includes(n)),i=+(Date.parse($c(t.ts))>=rf);return af[r][i]};function Dc(e,t,n=20,r=new Set,i=!1){let a=[],o=[],s={legacy_unknown:0,actionable_unknown:0},c=Math.max(0,n),l=0,d=0,u=0;for(let[m,p]of t.split(/\r?\n/).entries()){let f;try{f=JSON.parse(p)}catch{continue}l+=1;let g=Oc(f);if(g!=="attributed"){if(d+=1,g==="actionable_unknown"&&r.has(`${e}:${m+1}`)){u+=1;continue}s[g]+=1,i&&g==="actionable_unknown"&&o.push({item_id:e,line:m+1}),a.length<c&&a.push({item_id:e,line:m+1})}}return{checked_events:l,unknown_event_count:d,legacy_unknown_event_count:s.legacy_unknown,actionable_unknown_event_count:s.actionable_unknown,acknowledged_actionable_event_count:u,samples:a,samples_truncated:s.legacy_unknown+s.actionable_unknown>a.length,actionable_events:o}}var BE=(e,t,n=20,r=new Set)=>Dc(e,t,n,r);function Pc(e){let t=new Set;for(let n of e.split(/\r?\n/)){let r;try{r=JSON.parse(n)}catch{continue}let a=(typeof r=="object"&&r!==null&&typeof r.context=="object"&&r.context!==null?r.context:{}).author_acknowledgment;if(!(typeof a!="object"||a===null||!Array.isArray(a.events)))for(let o of a.events)typeof o=="object"&&o!==null&&typeof o.item_id=="string"&&Number.isSafeInteger(o.line)&&t.add(`${o.item_id}:${String(o.line)}`)}return t}var mn=async(e,t=20,n=!1)=>{let r=un.join(e,"history"),i;try{i=(await dn.readdir(r)).filter(w=>w.endsWith(".jsonl")).sort((w,v)=>w.localeCompare(v))}catch{i=[]}let a=new Set,o=[],s=[],c=0,l=0,d=0,u=0,m=0,p=0,f="_workspace.jsonl",g=new Set;if(i.includes(f))try{g=Pc(await dn.readFile(un.join(r,f),"utf8"))}catch{g=new Set}for(let w of i){let v;try{v=await dn.readFile(un.join(r,w),"utf8")}catch{continue}let b=w.slice(0,-6),x=Dc(b,v,t-o.length,g,n);c+=1,l+=x.checked_events,d+=x.unknown_event_count,u+=x.legacy_unknown_event_count,m+=x.actionable_unknown_event_count,p+=x.acknowledged_actionable_event_count,x.unknown_event_count>0&&a.add(b),o.push(...x.samples),n&&s.push(...x.actionable_events)}let h=u+m;return{checked_streams:c,checked_events:l,unknown_event_count:d,legacy_unknown_event_count:u,actionable_unknown_event_count:m,acknowledged_actionable_event_count:p,affected_item_ids:[...a].sort((w,v)=>w.localeCompare(v)),samples:o,samples_truncated:h>o.length,...n?{actionable_events:s}:{}}};function of(e){return[...new Map(e.map(t=>[`${t.item_id}:${t.line}`,{item_id:t.item_id,line:t.line}])).values()].sort((t,n)=>t.item_id.localeCompare(n.item_id)||t.line-n.line)}async function sf(e){try{return Pc(await dn.readFile(un.join(e,"history","_workspace.jsonl"),"utf8"))}catch{return new Set}}function cf(e){return(e.item_id===ue||/^[a-z0-9][a-z0-9-]*$/iu.test(e.item_id))&&Number.isSafeInteger(e.line)&&e.line>=1}function lf(e,t,n){let r=n[e.line-1]??"",i;try{i=JSON.parse(r)}catch{Re(`Unknown-author acknowledgment target ${e.item_id}:${e.line} is not readable.`,{code:"history_author_acknowledge_target_unreadable"})}return Oc(i)!=="actionable_unknown"&&Re(`Author acknowledgment target ${e.item_id}:${e.line} is not an actionable unknown-author event.`,{code:"history_author_acknowledge_target_not_actionable"}),{...e,source_event_hash:Tc("sha256").update(r).digest("hex"),disposition:t.has(`${e.item_id}:${e.line}`)?"already_acknowledged":"actionable"}}async function Nc(e,t,n){let r=t.events??[],i=+(t.all_actionable===!0)+ +(r.length>0);i===0&&Re("Specify exactly one selector: events or all_actionable.",{code:"history_author_acknowledge_selector_required"}),i>1&&Re("Author acknowledgment accepts either explicit events or all_actionable, not both.",{code:"history_author_acknowledge_selector_conflict"}),(!Number.isSafeInteger(n)||n<0)&&Re("Author acknowledgment coordinate_limit must be a non-negative integer.",{code:"history_author_acknowledge_preview_limit_invalid"});let a=of(t.all_actionable===!0?(await mn(e,0,!0)).actionable_events:r),o=await sf(e),s=new Map;for(let m of a)if(cf(m)||Re(`Unknown-author acknowledgment target ${m.item_id}:${m.line} is not readable.`,{code:"history_author_acknowledge_target_unreadable"}),!s.has(m.item_id))try{s.set(m.item_id,(await dn.readFile(un.join(e,"history",`${m.item_id}.jsonl`),"utf8")).split(/\r?\n/u))}catch{Re(`Unknown-author acknowledgment target ${m.item_id}:${m.line} is not readable.`,{code:"history_author_acknowledge_target_unreadable"})}let c=a.map(m=>lf(m,o,s.get(m.item_id))),l=t.all_actionable===!0?"all_actionable":"events",d=Tc("sha256").update(JSON.stringify({version:1,selection:l,coordinates:c})).digest("hex"),u=c.filter(({disposition:m})=>m==="actionable").length;return{plan:{selection:{kind:l},selected_count:c.length,actionable_count:u,already_acknowledged_count:c.length-u,omitted_count:Math.max(0,c.length-n),coordinates:c.slice(0,n),plan_fingerprint:d},completeCoordinates:c}}async function HE(e,t,n=50){return(await Nc(e,t,n)).plan}function df(e,t){let n=e.length>0;return n&&t&&Re("Specify exactly one selector: repeat --event or pass --all-actionable.",{code:"history_author_acknowledge_selector_conflict",required:"Exactly one of --event or --all-actionable",examples:['pm history-author-acknowledge --event pm-a1b2:4 --attributed-author agent --reviewer maintainer --reason "Verified provenance"','pm history-author-acknowledge --all-actionable --attributed-author import-agent --reviewer maintainer --reason "Reviewed the complete actionable set"']}),!n&&!t&&Re("Specify exactly one selector: repeat --event or pass --all-actionable.",{code:"history_author_acknowledge_selector_required",required:"Exactly one of --event or --all-actionable",examples:['pm history-author-acknowledge --event pm-a1b2:4 --attributed-author agent --reviewer maintainer --reason "Verified provenance"','pm history-author-acknowledge --all-actionable --attributed-author import-agent --reviewer maintainer --reason "Reviewed the complete actionable set"']}),{events:uf(e),all_actionable:t}}function uf(e){return e.map(t=>{let n=t.lastIndexOf(":"),r=t.slice(0,n).trim(),i=Number(t.slice(n+1)),a=r===ue||/^[a-z0-9][a-z0-9-]*$/iu.test(r);return(n<1||!a||!Number.isSafeInteger(i)||i<1)&&Re(`history-author-acknowledge --event expects <item-id>:<one-based-line>, received "${t}".`,{code:"history_author_acknowledge_target_unreadable"}),{item_id:r,line:i}})}function JE(e,t){let n=df(Ji(t.historyEvent),t.allActionable===!0||t.all_actionable===!0);return mf(e,{events:n.events,all_actionable:n.all_actionable,dry_run:t.dryRun===!0||t.dry_run===!0,plan_fingerprint:C(t,"planFingerprint")??C(t,"plan_fingerprint"),coordinate_limit:typeof t.limit=="number"?t.limit:typeof t.limit=="string"?Number(t.limit):void 0,attributed_author:C(t,"attributedAuthor")??C(t,"attributed_author")??void 0,reviewer:C(t,"reviewer"),reason:C(t,"reason")})}async function mf(e,t){let n=t.reviewer?.trim()??"",r=t.attributed_author?.trim()??"",i=t.reason?.trim()??"",a=await Nc(e,t,t.coordinate_limit??50);if(t.dry_run===!0)return{dry_run:!0,mutated:!1,acknowledged:0,outcome:"preview",exit_code:_.SUCCESS,plan:a.plan};if([n.length>0,n.toLowerCase()!=="unknown",r.length>0,r.toLowerCase()!=="unknown",i.length>0].includes(!1)&&Re("Author acknowledgment requires events, reviewer, attributed_author, and reason.",{code:"history_author_acknowledge_required_values_missing"}),t.plan_fingerprint?.trim()||Re("Author acknowledgment apply requires plan_fingerprint from a fresh dry-run preview.",{code:"history_author_acknowledge_plan_fingerprint_required",recovery:{suggested_retry:"Rerun history-author-acknowledge with --dry-run, then pass --plan-fingerprint <value>."}}),t.plan_fingerprint.trim()!==a.plan.plan_fingerprint)throw new y("Author acknowledgment selection changed after preview; no history was mutated.",_.CONFLICT,{code:"history_author_acknowledge_plan_conflict",recovery:{suggested_retry:"Rerun history-author-acknowledge with --dry-run and apply the fresh plan_fingerprint."}});let s=a.completeCoordinates.filter(({disposition:u})=>a.plan.selection.kind==="events"||u==="actionable").map(({item_id:u,line:m})=>({item_id:u,line:m}));if(s.length===0)return{dry_run:!1,mutated:!1,acknowledged:0,outcome:"no_effect",exit_code:_.NO_EFFECT,plan:a.plan};let c=await I(e),l=await rr({pmRoot:e,op:"history:author-acknowledge",author:n,context:{author_acknowledgment:{events:s,attributed_author:r}},message:i,lockTtlSeconds:c.locks.ttl_seconds,lockWaitMs:c.locks.wait_ms}),d=a.plan.actionable_count>0&&a.plan.already_acknowledged_count>0?{outcome:"partial_effect",exit_code:_.PARTIAL_EFFECT}:{outcome:"effect",exit_code:_.SUCCESS};return{dry_run:!1,mutated:!0,acknowledged:s.length,...d,plan:a.plan,history_path:l.historyPath}}import Vi from"node:fs/promises";import Ki 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]="6efed404-acd2-5c3a-a008-856df67c8b77")}catch{}})();var pf=8388608,ff=new Set(["resolved","failed"]),hf=[{kind:"boolean",matches:e=>typeof e=="boolean"||typeof e=="string"&&/^(?:true|false)$/iu.test(e.trim())},{kind:"single_digit",matches:e=>typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=9||typeof e=="string"&&/^\d$/u.test(e.trim())}];function je(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Yi(e){return hf.find(t=>t.matches(e))?.kind}function XE(e){let t=new Map,n=0,r=0;return{entries:e.map(a=>{let o=je(a.agent_provenance)?a.agent_provenance:void 0;if(o===void 0)return a;let s={},c=!1;for(let[d,u]of Object.entries(o)){let m=je(u)?Yi(u.value):void 0;if(m===void 0){s[d]=u;continue}c=!0,r+=1;let p=a.agent_harness??"unknown",f=`${p}\0${d}\0${m}`,g=t.get(f)??{harness:p,dimension:d,kind:m,count:0};g.count+=1,t.set(f,g)}if(!c)return a;n+=1;let l={...a};return Object.keys(s).length===0?delete l.agent_provenance:l.agent_provenance=s,l}),receipt:{changed:n>0,events_changed:n,observations_removed:r,invalid_values:[...t.values()].sort((a,o)=>a.harness.localeCompare(o.harness)||a.dimension.localeCompare(o.dimension)||a.kind.localeCompare(o.kind))}}}async function ZE(e){let t=[];for(let n of await Mc(e))try{let r=await Vi.readFile(Ki.join(e,"history",n),"utf8");for(let i of r.split(`
@@ -47,4 +47,4 @@ ${a}`,_.GENERIC_FAILURE)}}async function zx(){return No(import.meta.url,["../../
47
47
  `);ae(e.progressEnabled,"writing keyword artifacts"),await le(t,`${JSON.stringify(e.manifest,null,2)}
48
48
  `),await le(n,`${i}
49
49
  `);let a=[];if(e.mode!=="keyword")try{ae(e.progressEnabled,"writing vectorization status ledger"),await Gs(e.pmRoot,e.vectorizationLedgerEntries,e.vectorizationEmbeddingMetadata)}catch(o){a.push(`search_vectorization_status_ledger_write_failed:${o instanceof Error?o.message:String(o)}`)}return a}async function QD(e,t){let n=pS(e.mode),r=mS(e),i=e.full===!0;ae(r,`start mode=${n}`);let a=L(process.cwd(),t.path);if(!await A(K(a)))throw new y(`Tracker is not initialized at ${a}. Run pm init first.`,_.NOT_FOUND);let o=lr(await I(a)).settings,s=null;try{s=await de(a,Ds,o.locks.ttl_seconds,Y(void 0,"pm-reindex"),!1,o.governance.force_required_for_stale_lock,o.locks.wait_ms)}catch(c){throw c instanceof y&&c.exitCode===_.CONFLICT?new y("Another pm reindex run is already active for this project. Wait for it to finish before starting a new keyword, semantic, or hybrid reindex.",_.CONFLICT,{code:"reindex_already_running",type:"urn:pm-cli:error:reindex_already_running",why:"Semantic reindex can be expensive and duplicate runs compete for the same local embedding model and vector store.",nextSteps:["Check active pm reindex processes before starting another reindex.","Rerun with --progress when you need non-interactive visibility."]}):c}try{let c=gS(o),l=_S(o),d=xS({requestedMode:n,pmRoot:a,settings:o,extensionEmbedding:c,extensionVectorAdapter:l}),u=n;ae(r,"loading item corpus");let m=await SS({pmRoot:a,settings:o}),p=m.warnings,{documentCandidates:f,metadataDocuments:g}=m;ae(r,`loaded_items=${g.length}`);let h=$(),w=kS(u,h,g),v=Ln.join(a,So),b=Ln.join(a,Eo),x=u==="keyword"?await Ro(a,f,o.schema,p):g,R=[],k={},F=null,T=bS(u);if(u==="keyword"&&await ES({pmRoot:a,settings:o,forceFullSemantic:i,extensionEmbedding:c,reindexWarnings:p}),u!=="keyword"){let B=await OS({pmRoot:a,settings:o,requestedMode:n,activeEmbeddingProvider:d.activeEmbeddingProvider,activeVectorStore:d.activeVectorStore,extensionEmbedding:c,extensionVectorAdapter:l,documentCandidates:f,metadataDocuments:g,documentsForKeywordArtifacts:x,forceFullSemantic:i,reindexWarnings:p,semanticWarnings:R,semanticSummary:T,progressEnabled:r});x=B.documentsForKeywordArtifacts,k=B.vectorizationLedgerEntries,F=B.vectorizationEmbeddingMetadata}let E=await DS({pmRoot:a,mode:u,manifest:w,documentsForKeywordArtifacts:x,settings:o,vectorizationLedgerEntries:k,vectorizationEmbeddingMetadata:F,progressEnabled:r}),U=[...await re({path:v,scope:"project",op:"reindex:manifest"}),...await re({path:b,scope:"project",op:"reindex:embeddings"}),...await Zn({mode:u,total_items:g.length})];return ae(r,"done"),{ok:!0,mode:u,total_items:g.length,semantic:T,artifacts:{manifest:So,embeddings:Eo},warnings:[...p,...R,...E,...U],generated_at:h}}finally{await s?.()}}export{bA as a,vl as b,N as c,ve as d,Fe as e,Lt as f,Zs as g,ec as h,gt as i,Pi as j,Cp as k,Mi as l,Li as m,ic as n,jt as o,sn as p,ji as q,zp as r,dc as s,cn as t,Ui as u,_r as v,zi as w,mc as x,pc as y,fc as z,wr as A,vr as B,gc as C,_c as D,yc as E,wc as F,xr as G,xc as H,C as I,ee as J,Vp as K,Hi as L,SE as M,EE as N,Ic as O,AE as P,RE as Q,IE as R,CE as S,$E as T,Ji as U,TE as V,OE as W,Bi as X,DE as Y,PE as Z,Cc as _,NE as $,nf as aa,Oc as ba,BE as ca,mn as da,HE as ea,df as fa,uf as ga,JE as ha,mf as ia,Nf as ja,Mf as ka,_t as la,zA as ma,Gf as na,$h as oa,GR as pa,WR as qa,BR as ra,hn as sa,HR as ta,JR as ua,VR as va,KR as wa,YR as xa,XR as ya,ZR as za,QR as Aa,eI as Ba,tI as Ca,nI as Da,Ma as Ea,XE as Fa,ZE as Ga,Fc as Ha,gw as Ia,K$ as Ja,An as Ka,Hr as La,Y$ as Ma,X$ as Na,Iu as Oa,LT as Pa,$u as Qa,tm as Ra,KT as Sa,Pu as Ta,rm as Ua,q0 as Va,G0 as Wa,Tb as Xa,Ob as Ya,J0 as Za,V0 as _a,K0 as $a,Y0 as ab,Pb as bb,Nb as cb,Mb as db,X0 as eb,om as fb,Fb as gb,sm as hb,ao as ib,lm as jb,jb as kb,Ub as lb,zb as mb,ck as nb,zO as ob,Xm as pb,Dn as qb,oi as rb,_o as sb,ip as tb,ap as ub,iD as vb,_x as wb,op as xb,sp as yb,cp as zb,Tx as Ab,wD as Bb,AD as Cb,VD as Db,QD as Eb};
50
- //# sourceMappingURL=chunk-EF6ZS5GH.js.map
50
+ //# sourceMappingURL=chunk-6AHG2YW7.js.map