epiq 1.15.2 → 1.16.0

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.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import{$a as w,A as Xt,Aa as Io,B as qt,Ba as vo,C as Vt,Ca as It,Cc as _,D as Re,Dc as Jo,E as O,Ea as ho,Ec as Qo,F as Yt,Fa as vt,G as Jt,Ga as Ue,Gb as ce,H as te,Ha as bo,Hb as Se,I as Qt,Ia as Ro,J as D,Ja as Te,Jb as me,K as Ge,Ka as He,La as yo,M as ye,Ma as Ao,Mb as $o,N as Zt,Na as ht,Nb as Wo,O as eo,Oa as bt,Ob as jo,P as ct,Pa as R,Q as to,Qa as To,R as oo,Ra as A,Rb as Uo,S as so,Sa as So,Sb as Ho,T as F,Tb as zo,Ua as Rt,V as H,Va as de,W as $,Wa as wo,Xa as ue,Ya as oe,Za as Eo,_ as C,_a as xo,b as Me,c as le,ca as no,d as De,e as Fe,eb as Co,ec as Ko,f as Wt,fa as N,fb as Bo,g as Q,ga as ro,ha as io,hb as Lo,i as jt,ib as ze,jb as ko,jc as Xo,k as _e,ka as ao,kb as No,kc as At,la as lo,lb as Po,lc as qo,ma as $e,mb as Oo,n as ee,na as We,nb as Mo,o as Ut,oa as Ae,ob as Do,pa as mt,pb as Fo,pc as Ke,q as ut,qa as pt,qc as Vo,ra as ft,rb as _o,s as Ht,sa as je,ta as uo,tc as Yo,ua as gt,uc as Xe,va as co,vb as yt,vc as Tt,wa as mo,wb as Go,xa as po,xb as M,y as zt,ya as fo,yc as St,z as Kt,za as go,zc as qe}from"./chunk-4BPR3FGA.js";import{g as $t}from"./chunk-WUCQWBQE.js";import{b as d,c,d as l}from"./chunk-5RIQL7P4.js";var an=e=>e.payload??{},wt=e=>{let t=new Map,o={},s=new Set,n=new Set,a=new Set;for(let r of e){let{id:i,name:u}=an(r);if(i)switch(r.action){case"create.contributor":case"create.tag":t.set(i,u??""),s.add(i),n.delete(i);break;case"rename.contributor":u!==void 0&&s.has(i)&&!n.has(i)&&t.set(i,u);break;case"tombstone.contributor":s.has(i)&&(t.set(i,Ge),n.add(i));break;case"restore.contributor":case"restore.tag":u!==void 0&&s.has(i)&&(t.set(i,u),n.delete(i));break;case"add.board":u!==void 0&&(t.set(i,u),a.add(i));break;case"add.swimlane":u!==void 0&&(t.set(i,u),a.add(i),o[i]=u);break;case"edit.title":u!==void 0&&a.has(i)&&(t.set(i,u),i in o&&(o[i]=u));break;default:break}}return{byId:t,lanes:o}};var ln=e=>{let t=new Map,o=new Map;for(let s of e){let n=s.payload;!n?.id||!n.parent||(s.action==="move.node"&&t.set(s.id,o.get(n.id)),o.set(n.id,n.parent))}return t},es=e=>{let t=e.payload;return e.action==="tombstone.tag"||e.action==="restore.tag"?t?.id:t?.tag},dn=e=>{let t=new Set,o=new Map;for(let s of e){let n=s.payload,a=n?.id;a&&(s.action==="add.issue"&&t.add(a),n.parent&&o.set(a,n.parent))}return{issueIds:t,parentById:o}},un=(e,{issueIds:t,parentById:o})=>{let s=e.payload;if(s?.issue)return s.issue;let n=new Set,a=s?.id;for(;a!==void 0&&!n.has(a);){if(t.has(a))return a;n.add(a),a=o.get(a)}return null},cn=new Set(["add.issue.comment","edit.issue.comment","delete.issue.comment"]),mn=e=>cn.has(e.action)?e.payload?.id??null:null,pn=new Set(["add.issue","move.node","close.issue","reopen.issue"]),fn=(e,t)=>{let o=new Map;return e.map((s,n)=>{let a=t[n]??null;if(a===null)return{lane:null,laneBefore:null};let r=s.payload,i=null;if(pn.has(s.action)&&r?.id===a&&r.parent){let u=o.get(a);u!==void 0&&u!==r.parent&&(i=u),o.set(a,r.parent)}return{lane:o.get(a)??null,laneBefore:i}})},gn=e=>{let t=new Map,o=new Map;return e.map(s=>{let{id:n,name:a}=s.payload??{};if(!n)return null;s.action==="add.board"&&t.set(n,"board"),s.action==="add.swimlane"&&t.set(n,"swimlane");let r=t.get(n);if(!r)return null;let i={kind:r,name:o.get(n)??a};return(s.action==="edit.title"||s.action.startsWith("add."))&&a!==void 0&&o.set(n,a),i})},Zo=90,In=e=>{let t=e.trim().split(`
3
+ `)[0]?.trim()??"";return t.length>Zo?`${t.slice(0,Zo).trimEnd()}\u2026`:t},ts=({kind:e,name:t})=>t===void 0?e:`${e} "${t}"`,vn=(e,t,o,s)=>{let{name:n,parent:a}=e.payload??{},r=ts(t);switch(e.action){case"move.node":{if(t.kind==="board"||!a)return`Moved ${r}`;let i=o.get(a);return i?s.get(e.id)===a?`Moved ${r} within ${i}`:`Moved ${r} to ${i}`:`Moved ${r}`}case"edit.title":return n===void 0?`Renamed ${r}`:`Renamed ${r} to "${n}"`;case"delete.node":return`Deleted ${r}`;case"lock.node":return`Locked ${r}`;default:return null}},hn=(e,t,o,s,n)=>{let a=e.payload,r=es(e),i=e.action?Jo(e.action):"";if(a?.md!==void 0){let f=In(a.md),g=e.action==="edit.description"&&!s&&n?`${i} of ${ts(n)}`:i;return f?`${g}: ${f}`:g}if(n&&!s){let f=vn(e,n,t,o);if(f)return f}if(e.action==="move.node"&&a?.parent){let f=t.get(a.parent),g=s?`${A(s)} moved`:"Moved";return f?o.get(e.id)===a.parent?`${g} within ${f}`:`${g} to ${f}`:s?g:i}if((e.action==="close.issue"||e.action==="reopen.issue")&&s)return`${A(s)} ${i.toLowerCase()}`;if(qt(e.action))return[i,Vt(e)].filter(Boolean).join(" ");let u=r!==void 0?t.get(r)??"":a?.assignee!==void 0?t.get(a.assignee)??"":a?.email!==void 0?a.email:a?.name!==void 0?`"${a.name}"`:"";return[i,u].filter(Boolean).join(" ")},Et=(e,t)=>e?D(e,t.get(e)):null,bn=(e,t)=>{let o=e.payload;return{actor:Et(e.userId,t),tag:Et(es(e),t),assignee:Et(o?.assignee,t)}},os=e=>{let t=new Map,o=new Set,s=n=>{let a=new Set,r=n;for(;r&&!a.has(r);){if(o.has(r))return r;a.add(r),r=t.get(r)}return null};return e.map(n=>{let a=n.payload,r=a?.id;if(!r)return null;n.action==="add.board"&&o.add(r);let i=n.action==="close.issue"?s(r):null,u=a.parent??a.issue;return u&&t.set(r,u),i!==null?i:o.has(r)?r:s(r)})},ss=e=>Rn.has(e),Rn=new Set(["create.contributor","rename.contributor","tombstone.contributor","restore.contributor","link.contributor.user","link.contributor.email","unlink.contributor.email","connect.repo","edit.repo","disconnect.repo","create.tag","tombstone.tag","restore.tag"]),ns=(e,t)=>{let o=os(e);return e.filter((s,n)=>o[n]===t)},yn=(e,t=new Map)=>{let o=new Map([...t,...wt(e).byId]),s=ln(e),n=dn(e),a=e.map(m=>un(m,n)),r=gn(e),i=fn(e,a),u=os(e),f=Yt(e.map(m=>te(m)));return e.flatMap((m,I)=>{let v=f[I]??null;return v===null?[]:[{id:m.id,t:v,action:m.action,label:hn(m,o,s,a[I]??null,r[I]??null),issue:a[I]??null,target:mn(m),...i[I],board:u[I]??null,...bn(m,o)}]}).sort((m,I)=>m.t-I.t)},An=e=>{let t=new Map;for(let s of e){if(s.issue===null||s.lane===null)continue;let n=t.get(s.issue)??[],a=n[n.length-1];(a===void 0||a.lane!==s.lane)&&(n.push({t:s.t,lane:s.lane,board:s.board}),t.set(s.issue,n))}let o=new Map;for(let[s,n]of t){let a=n[n.length-1];o.set(s,{changes:n,from:n[0].t,closedFrom:a.lane===N?a.t:null})}return o},Tn=(e,t)=>{let o=0,s=e.length;for(;o<s;){let n=o+s>>1;e[n].t<t?o=n+1:s=n}return e[o-1]},rs=(e,t,o)=>{let s={};for(let[n,a]of e){if(a.from>=t||a.closedFrom!==null&&a.closedFrom<t)continue;let r=Tn(a.changes,t);r===void 0||r.lane===N||o&&r.board!==o||(s[n]=r.lane)}return s},Sn=e=>wt(e).lanes,we=null,is=e=>{let t=He(e);if(we&&we.root===e&&we.signature===t)return c("Timeline entries, cached",we.index);let o=oe(e);if(l(o))return d(o.message);let s=yn(o.value,ue(e)),n={entries:s,lanes:An(s),laneNames:Sn(o.value)};return we={root:e,signature:t,index:n},c("Timeline entries, built",n)};var as=1e5,wn=2e4,Ve=null,ls=Promise.resolve(),us=e=>{let t=ls.then(e,e);return ls=t.then(()=>{},()=>{}),t},Ye=e=>{let t=Te(e);return l(t)?t:Q({repoRoot:t.value})},z=()=>{if(!qe())return{mode:"live",asOfTime:null};let{timeMode:e}=Yo();return e==="live"?{mode:"live",asOfTime:null}:{mode:"scrub",asOfTime:Ve}},ds=(e,t)=>{let o=0,s=e.length;for(;o<s;){let n=o+s>>1;e[n].t<t?o=n+1:s=n}return o},Ji=async(e={})=>{let t=Ye(e.repoRoot);if(l(t))return d(t.message);let o=is(t.value);if(l(o))return d(o.message);let s=o.value.entries,n=Date.now(),a=e.end??n,r=e.start??s[0]?.t??a;if(a<=r)return c("Empty time window",{bucketMs:0,buckets:[],capped:!1,events:[],lanesAtStart:{},laneNames:o.value.laneNames,closedLane:N,earliest:r,latest:a});let i=ds(s,r),u=ds(s,a),f=s.slice(i,u).filter(p=>!e.boardId||p.board===e.boardId||ss(p.action)),g=f.map(p=>p.t),m=Math.max(1,Math.ceil((a-r)/as)),I=new Map;for(let p of g){let b=Math.min(as-1,Math.floor((p-r)/m)),T=r+b*m;I.set(T,(I.get(T)??0)+1)}let v=[...I.entries()].sort(([p],[b])=>p-b).map(([p,b])=>({t:p,count:b})),h=f.length>wn;return c("Computed event timeline",{bucketMs:m,buckets:v,capped:h,events:h?[]:f,lanesAtStart:rs(o.value.lanes,r,e.boardId),laneNames:o.value.laneNames,closedLane:N,earliest:r,latest:a})},cs=e=>{let t=oe(e);if(l(t))return d(t.message);let o=St();if(l(o))return d(o.message);Ve=null;let s=Rt(t.value),{fatal:n,skipped:a}=ht(s);return n.length>0?d(n.map(r=>r.message).join(", ")):(bt(a),Tt({readOnly:!1,readOnlyReason:void 0,timeMode:"live",unappliedEvents:[],replay:null}),c("Restored live state",!0))},En=(e,t)=>{Ve=null;let o=cs(e);return l(o)?d(`${t} (recovery to live also failed: ${o.message})`):d(t)},xn=e=>us(async()=>{let t=Ye(e.repoRoot);if(l(t))return d(t.message);let o=Eo(t.value,e.targetTime);if(l(o))return d(o.message);let{appliedEvents:s,unappliedEvents:n}=o.value,a=St();if(l(a))return a;let r=Rt(s),{fatal:i,skipped:u}=ht(r);return i.length>0?En(t.value,i.map(f=>f.message).join(", ")):(bt(u),Tt({readOnly:!0,timeMode:"peek",unappliedEvents:n,replay:null}),Ve=e.targetTime,c("Checked out historical state",{asOfTime:e.targetTime}))}),Qi=async e=>{let t=Ye(e.repoRoot);if(l(t))return d(t.message);let o=xo(t.value);if(l(o))return d(o.message);let s=o.value.get(e.eventId)??null;return s===null?d("Event not found in the log"):xn({repoRoot:e.repoRoot,targetTime:s+1})},Zi=(e={})=>us(async()=>{let t=Ye(e.repoRoot);if(l(t))return d(t.message);let o=cs(t.value);return l(o)?d(o.message):c("Returned to live state",!0)});import{ulid as kn}from"ulid";import Bn from"node:fs";var ms=new Map,Cn=3e4,ps=async e=>{let t=ms.get(e);if(t&&Date.now()-t.readAt<Cn)return{name:t.name,email:t.email};let o=await Fe({args:["config","--get-regexp","^user\\.(name|email)$"],cwd:e}),s=null,n=null;if(o.exitCode===0)for(let a of(o.stdout??"").split(`
4
+ `)){let r=a.indexOf(" ");if(r===-1)continue;let i=a.slice(0,r),u=a.slice(r+1);i==="user.name"&&(s=u.trim()||null),i==="user.email"&&(n=ye(u)||null)}return ms.set(e,{name:s,email:n,readAt:Date.now()}),{name:s,email:n}},fs=async e=>(await ps(e)).email,pe=async e=>(await ps(e)).name;var se=e=>{let t=_e(e??process.cwd());return l(t)?d(t.message):c("Resolved Epiq repo root",t.value)},Je=null,Ln=async(e,t)=>{let o=se(e);if(l(o))return o;let s=Q({repoRoot:o.value});if(l(s))return d(s.message);let n=le(o.value);if(l(n))return d(n.message);if(!(Je!==null&&Je.repoRoot===o.value&&Je.stateBranchRoot===s.value&&Bn.existsSync(jt(s.value)))){let m=await Uo({repoRoot:o.value,stateBranchName:n.value});if(l(m))return d(m.message);let I=await Ho({repoRoot:o.value,stateBranchRoot:s.value,stateBranchName:n.value});if(l(I))return d(I.message);Je={repoRoot:o.value,stateBranchRoot:s.value}}if(t?.pull??!1){let m=await De({cwd:s.value,args:["pull","--ff-only"]});l(m)&&Me.info(3,m.message)}let r={repoRoot:o.value,stateBranchRoot:s.value},i=ee();l(i)||ut(i.value),ut({gitEmail:await fs(o.value),gitName:await pe(o.value)});let u=He(s.value);if(yo(s.value)===u&&qe()&&z().mode==="live")return c("Booted Epiq state, unchanged",r);let f=de(s.value);if(l(f))return d(f.message);let g=me(f.value.events,f.value.unreadable);return l(g)?d(g.message):(Ao(s.value,u),c("Booted Epiq state",r))},W=()=>{let e=ee();return l(e)?d(e.message):e.value.userId?e.value.userName?c("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):d("Unable to retrieve user name"):d("Unable to retrieve user id")},B=()=>{let e=Xe();return l(e)?d(e.message):e},L=e=>Ln(e,{pull:!1}),y=async e=>{let t=await L(e);if(l(t))return t;let o=W();if(l(o))return o;let s=B();return l(s)?s:c("Booted",{boot:t.value,actor:o.value,state:s.value})};var k=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return!o||o.isDeleted?d("Issue not found"):F(o)?o.readonly?d("Issue is readonly"):c("Found issue",o):d("Target must be an issue")},j=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return!o||o.isDeleted?d("Swimlane not found"):H(o)?o.readonly?d("Swimlane is readonly"):c("Found swimlane",o):d("Target must be a swimlane")},Ee=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return!o||o.isDeleted?d("Board not found"):$(o)?o.readonly?d("Board is readonly"):c("Found board",o):d("Target must be a board")};var xt=e=>{if(!e)return;let t=B();if(l(t))return;let o=t.value.nodes[e];if(!o||!($(o)||H(o)))return;let s=o.props?.description;return s?.trim()?s:void 0},Qe=e=>{let t=xt(e);return t?{laneDescription:t}:{}},xe=e=>{let t=xt(e);return t?{boardDescription:t}:{}},fe=e=>{let t=xt(e);return t?{description:t}:{}},Ze=({node:e,label:t,max:o,description:s,actor:n,stateBranchRoot:a})=>{let r=Go(s),i=M(t,r,o);if(i)return d(i);if(z().mode!=="live")return d(`Cannot edit the ${t.toLowerCase()} while time travelling`);let u={id:e.id,ref:A(e.id),description:r};if((e.props?.description??"")===r)return c("No changes made",u);let f={id:kn(),...R(n),action:"edit.description",payload:{id:e.id,md:r}},g=w([f],a);return l(g)?d(g.message):c(`Edited ${t.toLowerCase()}`,u)},Nn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=Ee(e.boardId);return l(o)?o:Ze({node:o.value,label:"Board description",max:yt("board"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},Pn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);return l(o)?o:Ze({node:o.value,label:"Swimlane description",max:yt("swimlane"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})};import{ulid as Ce}from"ulid";var gs=e=>({id:e.id,name:C(e.name),color:co(e)}),Be=e=>{let t=uo(e);return t?{goal:gs(t)}:{}},Ct=e=>({...gs(e),...Io(e.id)}),Is=()=>pt().map(Ct),On=async(e={})=>{let t=await L(e.repoRoot);return l(t)?t:c("Listed goals",pt().map(o=>({...Ct(o),boards:po(o.id).map(s=>({id:s,ref:A(s)}))})))},et=e=>go(e).map(t=>({...Ct(t),members:fo(t.id,e).map(o=>({id:o.id,done:vo(o)}))})),tt=(e,t,o)=>{let s=w(t,e);return l(s)?d(s.message):c("Saved",o)},Mn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;let s=o.value,n={id:s.id,ref:A(s.id)},a;if(e.goal!==null){let u=je(e.goal);if(!u){let f=await vs({repoRoot:e.repoRoot,name:e.goal,issueId:s.id});return l(f)?f:c(`Created goal "${f.value.name}"`,n)}a=u.id}let r=gt(s,a);if(r.length===0)return c("No changes made",n);let i=R(t.value.actor);return tt(t.value.boot.stateBranchRoot,r.map(u=>({id:Ce(),...i,...u})),n)},vs=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=ft(e.name),s=It(o);if(s)return d(s);let n=R(t.value.actor),a=Ce(),r=[{id:a,...n,action:"create.goal",payload:{id:a,name:o}}];if(e.issueId){let i=k(e.issueId);if(l(i))return i;let u=i.value;for(let f of gt(u,a))r.push({id:Ce(),...n,...f})}return tt(t.value.boot.stateBranchRoot,r,{id:a,name:o})},Dn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=mt(e.goalId);if(!o)return d("Goal not found");let s=ft(e.name);if(s===o.name)return c("No changes made",{id:o.id,name:s});let n=It(s,o.id);return n?d(n):tt(t.value.boot.stateBranchRoot,[{id:Ce(),...R(t.value.actor),action:"rename.goal",payload:{id:o.id,name:s}}],{id:o.id,name:s})},Fn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=mt(e.goalId);return o?tt(t.value.boot.stateBranchRoot,[{id:Ce(),...R(t.value.actor),action:"tombstone.goal",payload:{id:o.id}}],{id:o.id,name:o.name}):d("Goal not found")};import{ulid as _n}from"ulid";var ot=e=>{let t=ao(e);return t.length>0?{rules:t}:{}},Gn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);if(l(o))return o;let s=o.value,n=lo(s,e.rule,e.on);if(l(n))return n;let a={id:s.id,ref:A(s.id),rule:e.rule};if(!n.value)return c(n.message,a);let r=w([{id:_n(),...R(t.value.actor),...n.value}],t.value.boot.stateBranchRoot);return l(r)?d(r.message):c(e.on?"Added lane rule":"Removed lane rule",a)};import $n from"node:fs";import Wn from"node:path";import{ulid as Bt}from"ulid";var jn=e=>{if(e.filePath)try{return c("Read attachment file",{data:$n.readFileSync(e.filePath),name:e.name??Wn.basename(e.filePath)})}catch(t){return d(`Unable to read ${e.filePath}: ${t instanceof Error?t.message:String(t)}`)}return e.dataBase64?c("Decoded attachment data",{data:Buffer.from(e.dataBase64,"base64"),name:e.name??"image"}):d("Provide either filePath or dataBase64")},st=()=>{let e=ee();return l(e)?vt:e.value.attachmentMaxKb??vt},Un=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;let s=jn(e);if(l(s))return s;let n=bo(t.value.boot.stateBranchRoot,s.value.data,st());if(l(n))return n;let a=C(s.value.name).trim()||"image",r=Bt(),i={id:Bt(),...R(t.value.actor),action:"add.issue.attachment",payload:{id:r,issue:e.issueId,author:t.value.actor.userId,hash:n.value.hash,ext:n.value.ext,name:a,bytes:n.value.bytes}},u=w([i],t.value.boot.stateBranchRoot);if(l(u))return d(u.message);let f=Ue(n.value.hash,n.value.ext);return c("Added issue attachment",{id:r,issueId:e.issueId,fileName:f,bytes:n.value.bytes,markdown:ho(a,f)})},Hn=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.eventLog.find(i=>i.action==="add.issue.attachment"&&i.payload.id===e.attachmentId);if(!o)return d("Unable to resolve attachment");if(o.payload.author!==t.value.actor.userId)return d("You can only delete your own attachments");let s=k(o.payload.issue);if(l(s))return s;if(t.value.state.eventLog.some(i=>i.action==="delete.issue.attachment"&&i.payload.id===e.attachmentId))return c("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let a={id:Bt(),...R(t.value.actor),action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},r=w([a],t.value.boot.stateBranchRoot);return l(r)?d(r.message):c("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},zn=async e=>{let t=await L(e.repoRoot);return l(t)?t:Ro(t.value.stateBranchRoot,e.fileName,st())};var Kn=e=>{switch(e.action){case"add.issue":case"move.node":case"close.issue":case"reopen.issue":return e.payload.parent;default:return null}},Lt=(e,t)=>{let o=[];for(let s of e){let n=Kn(s);if(n===null||n===o.at(-1)?.laneId)continue;let a=te(s);o.push({laneId:n,enteredAt:a===null?t:Re(a)})}return o},hs=(e,t)=>e.reduce((o,s)=>{let n=te(s);return n===null?o:Math.max(o,Re(n))},t),Le=(e,t)=>Lt(e,t).at(-1)?.enteredAt??t;var ne=e=>ro(e).map(t=>D(t.id,t.name)),bs=e=>_.getCommentsByIssue(e).sort((t,o)=>t.id<o.id?-1:t.id>o.id?1:0).map(t=>({id:t.id,author:Qt(t.authorId,_.getContributor(t.authorId)?.name),createdAt:O(t.id),body:t.md})),re=e=>io(e).map(({id:t,name:o})=>D(t,o));var Xn=async(e={})=>{let t=await L(e.repoRoot);if(l(t))return t;let o=B();return l(o)?o:c("Retrieved Epiq state",{root:t.value.repoRoot,stateBranchRoot:t.value.stateBranchRoot,nodes:o.value.nodes,rootNodeId:o.value.rootNodeId,contextNode:o.value.contextNode,selectedIndex:o.value.selectedIndex,eventLog:o.value.eventLog})},qn=365*24*60*60*1e3,Vn=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return c("Issue description",o&&F(o)&&!o.isDeleted?o.props.description??"":"")},kt=()=>{let e=B();if(l(e))return e;let t=z(),o=t.mode!=="live",s=Object.values(e.value.nodes),n=s.filter(p=>$(p)&&!p.isDeleted),a=Date.now()-qn,r=new Map,i=new Map;for(let p of s)if(!p.isDeleted){if(H(p)&&p.parentNodeId){let b=r.get(p.parentNodeId)??[];b.push(p),r.set(p.parentNodeId,b)}if(F(p)&&p.parentNodeId){if(p.parentNodeId===N&&O(p.id)<a)continue;let b=i.get(p.parentNodeId)??[];b.push(p),i.set(p.parentNodeId,b)}}let u=new Set;for(let p of i.values())for(let b of p)u.add(b.id);let f=ee();if(l(f))return f;let g={},m=_.getCommentsGroupedByIssue();for(let p of s.filter(F))p.isDeleted||!u.has(p.id)||(g[p.id]=(m.get(p.id)??[]).map(b=>{let T=_.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:D(b.authorId,T?.name),createdAt:O(b.id)}}));let I=new Map;for(let p of e.value.eventLog)p.action==="add.issue.attachment"&&I.set(p.payload.id,p.payload.author);let v={},h=_.getAttachmentsGroupedByIssue();for(let p of s.filter(F))p.isDeleted||!u.has(p.id)||(v[p.id]=(h.get(p.id)??[]).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Ue(b.hash,b.ext),bytes:b.bytes,createdAt:O(b.id),canDelete:I.get(b.id)===f.value.userId})));return c("Retrieved Epiq GUI state",{boards:n.sort((p,b)=>p.rank.localeCompare(b.rank)).map(p=>({id:p.id,ref:A(p.id),title:p.title,readonly:!!p.readonly||o,...fe(p.id),goals:et(p.id),swimlanes:(r.get(p.id)??[]).sort((b,T)=>b.rank.localeCompare(T.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly||o,issues:(i.get(b.id)??[]).sort((T,Y)=>T.rank.localeCompare(Y.rank)).map(T=>({id:T.id,ref:A(T.id),title:C(T.title),description:T.props.description??"",createdAt:O(T.id),enteredLaneAt:Le(T.log??[],O(T.id)),lastEventAt:hs(T.log??[],O(T.id)),readonly:!!T.readonly||o,tags:ne(T),assignees:re(T),...Be(T),parentNodeId:T.parentNodeId,isClosed:T.parentNodeId===N,boardIds:Ae(T)})),parentNodeId:b.parentNodeId,...fe(b.id),...ot(b),countsDone:We(b.id),doneByName:$e(b)}))})),tags:_.getTags().map(p=>({...p,...D(p.id,p.name)})),goals:Is(),contributors:Object.values(e.value.contributors).map(p=>({...p,...D(p.id,p.name)})),user:{id:f.value.userId??"",name:f.value.userName??"",color:Ht(f.value.userName??"")},commentsByIssueId:g,attachmentsByIssueId:v,attachmentMaxKb:st(),timeTravel:t})},Rs=null,Yn=e=>{if(e===Rs)return;let t=no({root:e});if(l(t)){Me.info(t.message);return}Rs=e},Jn=async(e={})=>{if(z().mode!=="live")return kt();let t=await L(e.repoRoot);return l(t)?t:(Yn(t.value.repoRoot),kt())},Qn=async(e={})=>{$o();let t=se(e.repoRoot);if(l(t))return d("Sync failed");let o=W();if(l(o))return o;let s=await zo({cwd:t.value,ownEventFileName:To(o.value)});return l(s)?(jo(s.message),s):(Wo(),c("Synced",s.value))};import{ulid as K}from"ulid";var ke=e=>{let t=[...new Set([...e.issueIds??[],...e.issueId?[e.issueId]:[]])];return t.length?c("Resolved targets",t):d("Provide issueId or issueIds")},ge=(e,t)=>{let o=t.done.length,s=`${e} ${o} issue${o===1?"":"s"}`+(t.failed.length?`, ${t.failed.length} failed`:"");return o?c(s,t):d(`${s}: ${t.failed.map(n=>`${n.ref} ${n.reason}`).join("; ")}`)},Ne=(e,t)=>{let o={done:[],failed:[]};for(let s of e){let n=t(s);l(n)?o.failed.push({id:s,ref:A(s),reason:n.message}):o.done.push({id:s,ref:A(s)})}return o};var Zn=async e=>{let t=await L(e.repoRoot);if(l(t))return t;let o=B();if(l(o))return o;let s=e.idOrRef.trim();if(!s)return d("Provide an issue id or ref");let n=Object.values(o.value.nodes).filter(F).filter(u=>!u.isDeleted),a=n.find(u=>u.id===s),r=a?[a]:n.filter(u=>So(u.id,s));if(r.length===0)return d(`No issue matches "${s}"`);if(r.length>1)return d(`"${s}" matches ${r.length} issues: ${r.map(u=>`${A(u.id)} (${C(u.title)})`).join(", ")}. Use a full ref or id.`);let i=r[0];return c("Found issue",{id:i.id,ref:A(i.id),title:C(i.title),description:i.props.description??"",createdAt:O(i.id),enteredLaneAt:Le(i.log??[],O(i.id)),parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===N,boardIds:Ae(i),readonly:!!i.readonly,tags:ne(i),assignees:re(i),...Be(i),comments:bs(i.id),...Qe(i.parentNodeId)})},Ts=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();async function er(e){let t=await L(e.repoRoot);if(l(t))return t;let o=B();if(l(o))return o;let s=o.value.nodes,n=e.query?.trim().toLowerCase(),a=Object.values(s).filter(F).filter(i=>!i.isDeleted).filter(i=>e.includeClosed||i.parentNodeId!==N).filter(i=>e.boardId?(i.parentNodeId?s[i.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).filter(i=>!e.swimlaneId||i.parentNodeId===e.swimlaneId).filter(i=>!e.tag||ne(i).some(u=>Ts(u.name,e.tag))).filter(i=>!e.assignee||re(i).some(u=>Ts(u.name,e.assignee))).filter(i=>!n||i.title.toLowerCase().includes(n)||(i.props.description??"").toLowerCase().includes(n)),r=i=>C((i.parentNodeId?s[i.parentNodeId]?.title:void 0)??"");return e.brief?c("Listed issues",a.map(i=>({id:i.id,ref:A(i.id),title:C(i.title),swimlane:r(i),tags:ne(i).map(u=>u.name),assignees:re(i).map(u=>u.name)}))):c("Listed issues",a.map(i=>({id:i.id,ref:A(i.id),title:C(i.title),description:i.props.description??"",createdAt:O(i.id),enteredLaneAt:Le(i.log??[],O(i.id)),parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===N,boardIds:Ae(i),readonly:!!i.readonly,tags:ne(i),assignees:re(i),...Be(i)})))}var tr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=C(e.title);if(!o)return d("Issue title cannot be empty");let s=e.description??"",n=M("Issue title",o,300)??M("Issue description",s,2e4);if(n)return d(n);if((e.tagNames?.length??0)>20)return d(`Cannot set more than ${20} tags at once`);if((e.assigneeNames?.length??0)>20)return d(`Cannot set more than ${20} assignees at once`);let a=j(e.parentId);if(l(a))return a;let r=Se(e.parentId,t.value.actor,t.value.boot.stateBranchRoot);if(l(r))return r;let i=Ko({name:o,parent:e.parentId,user:t.value.actor,rank:r.value});if(l(i))return i;let u=[...i.value],f=u.find(v=>v.action==="add.issue")?.payload.id;if(!f)return d("Unable to determine created issue id");s&&u.push({id:K(),...R(t.value.actor),action:"edit.description",payload:{id:f,md:s}});let g=[];for(let v of e.tagNames??[]){let h=C(v).trim();if(!h||g.some(Y=>Y.name===h))continue;let p=M("Tag name",h,60);if(p)return d(p);let b=_.findTagByName(h),T=b?.id??K();b||u.push({id:K(),...R(t.value.actor),action:"create.tag",payload:{id:T,name:h}}),u.push({id:K(),...R(t.value.actor),action:"add.issue.tag",payload:{id:f,tag:T}}),g.push({id:T,name:h})}let m=[];for(let v of e.assigneeNames??[]){let h=C(v).trim();if(!h||m.some(Y=>Y.name===h))continue;let p=M("Assignee name",h,80);if(p)return d(p);let b=Object.values(t.value.state.contributors).find(Y=>Y.name===h),T=b?.id??K();b||u.push({id:K(),...R(t.value.actor),action:"create.contributor",payload:{id:T,name:h}}),u.push({id:K(),...R(t.value.actor),action:"add.issue.assignee",payload:{id:f,assignee:T}}),m.push({id:T,name:h})}let I=w(u,t.value.boot.stateBranchRoot);return l(I)?d(I.message):c("Created issue",{id:f,ref:A(f),title:o,parentId:e.parentId,description:s,tags:g,assignees:m,...Qe(e.parentId),...xe(t.value.state.nodes[e.parentId]?.parentNodeId)})},or=(e,t,o)=>{let s=k(e);if(l(s))return s;let n=ce(N,e,{at:"end"},t,o);if(l(n))return n;let a={id:K(),...R(t),action:"close.issue",payload:{id:e,parent:N,rank:n.value}},r=w([a],o);return l(r)?d(r.message):c("Closed issue",{id:e,ref:A(e)})};async function sr(e){let t=await L(e.repoRoot);if(l(t))return t;let o=W();if(l(o))return o;let s=ke(e);if(l(s))return s;let n=a=>or(a,o.value,t.value.stateBranchRoot);return e.issueIds?ge("Closed",Ne(s.value,n)):n(s.value[0])}var nr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.nodes[e.issueId];if(!o||o.isDeleted)return d("Issue not found");if(!F(o))return d("Target must be an issue");if(o.parentNodeId!==N)return d("Issue is not closed");let s=Xo(o);if(!s)return d("Unable to resolve previous parent from issue history");if(s===N)return d("Previous parent resolves to closed swimlane");let n=j(s);if(l(n))return n;let a=n.value,r=ce(a.id,o.id,{at:"end"},t.value.actor,t.value.boot.stateBranchRoot);if(l(r))return r;let i={id:K(),...R(t.value.actor),action:"reopen.issue",payload:{id:o.id,parent:a.id,rank:r.value}},u=w([i],t.value.boot.stateBranchRoot);return l(u)?d(u.message):c("Reopened issue",{id:o.id,ref:A(o.id),parentId:a.id})},rr=(e,t,o,s)=>{let n=k(e);if(l(n))return n;let a=j(t.parentId);if(l(a))return a;let r=ce(t.parentId,e,t.position??{at:"end"},o,s);if(l(r))return r;let i={id:K(),...R(o),action:"move.node",payload:{id:e,parent:t.parentId,rank:r.value}},u=w([i],s);return l(u)?d(u.message):c("Moved issue",{id:e,ref:A(e),parentId:t.parentId})};async function ir(e){let t=se(e.repoRoot);if(l(t))return t;let o=W();if(l(o))return o;let s=Q({repoRoot:t.value});if(l(s))return s;let n=de(s.value);if(l(n))return n;let a=me(n.value.events,n.value.unreadable);if(l(a))return a;let r=ke(e);if(l(r))return r;let i=(()=>{let g=B();if(l(g))return()=>({});let{nodes:m}=g.value,I=p=>p?m[p]?.parentNodeId:void 0,v=I(e.parentId),h=r.value.some(p=>I(m[p]?.parentNodeId)!==v);return()=>({...Qe(e.parentId),...h?xe(v):{}})})(),u=g=>rr(g,e,o.value,s.value);if(!e.issueIds){let g=u(r.value[0]);return l(g)?g:c(g.message,{...g.value,...i()})}let f=ge("Moved",Ne(r.value,u));return l(f)?f:c(f.message,{...f.value,...i()})}var ar=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return o?c("Read issue history",(o.log??[]).map(s=>({id:s.id,t:O(s.id),action:s.action,label:Qo(s),...s.action==="move.node"?{parentId:s.payload.parent}:{},actor:D(s.userId,t.value.contributors[s.userId]?.name)}))):d("Issue not found")},lr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);return l(o)?o:Ze({node:o.value,label:"Issue description",max:2e4,description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},dr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;let s=o.value,n=C(e.title);if(!n.trim())return d("Issue title cannot be empty");let a=M("Issue title",n,300);if(a)return d(a);if(s.title===n)return c("No changes made",{id:e.issueId,ref:A(e.issueId),title:n});let r={id:K(),...R(t.value.actor),action:"edit.title",payload:{id:e.issueId,name:n}},i=w([r],t.value.boot.stateBranchRoot);return l(i)?d(i.message):c("Edited issue title",{id:e.issueId,ref:A(e.issueId),title:n})};import{ulid as Z}from"ulid";var ur=async(e={})=>{let t=await L(e.repoRoot);if(l(t))return t;let o=B();if(l(o))return o;let s=Object.values(o.value.nodes).filter(n=>n.context==="BOARD"&&!n.isDeleted).map(n=>({id:n.id,ref:A(n.id),title:n.title,parentId:n.parentNodeId,readonly:!!n.readonly,...fe(n.id),goals:et(n.id)}));return c("Listed boards",s)},cr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.nodes[t.value.state.rootNodeId];if(!o)return d("Workspace not found");if(z().mode!=="live")return d("Cannot add a board while time travelling");let s=C(e.title);if(!s.trim())return d("Board title cannot be empty");let n=M("Board title",s,300);if(n)return d(n);let a=Se(o.id,t.value.actor,t.value.boot.stateBranchRoot);if(l(a))return a;let r=Z(),i={id:Z(),...R(t.value.actor),action:"add.board",payload:{id:r,name:s,parent:o.id,rank:a.value}},u=w([i],t.value.boot.stateBranchRoot);return l(u)?d(u.message):c("Created board",{id:r,ref:A(r),title:s})},mr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.nodes[e.boardId];if(!o||o.isDeleted)return d("Board not found");if(!$(o))return d("Edit target must be a board");if(o.readonly)return d("Cannot edit readonly board");if(z().mode!=="live")return d("Cannot rename a board while time travelling");let s=C(e.title);if(!s.trim())return d("Board title cannot be empty");let n=M("Board title",s,300);if(n)return d(n);if(o.title===s)return c("No changes made",{id:e.boardId,ref:A(e.boardId),title:s});let a={id:Z(),...R(t.value.actor),action:"edit.title",payload:{id:e.boardId,name:s}},r=w([a],t.value.boot.stateBranchRoot);return l(r)?d(r.message):c("Edited board title",{id:e.boardId,ref:A(e.boardId),title:s})},pr=async(e={})=>{let t=await L(e.repoRoot);if(l(t))return t;let o=B();if(l(o))return o;let s=Object.values(o.value.nodes).filter(n=>n.context==="SWIMLANE"&&!n.isDeleted).filter(n=>!e.boardId||n.parentNodeId===e.boardId).map(n=>({id:n.id,title:n.title,boardId:n.parentNodeId,isClosed:n.id===N,readonly:!!n.readonly,...fe(n.id),...H(n)?ot(n):{},countsDone:We(n.id),doneByName:H(n)&&$e(n)}));return c("Listed swimlanes",s)},fr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=Ee(e.boardId);if(l(o))return o;if(z().mode!=="live")return d("Cannot add a swimlane while time travelling");let s=C(e.title);if(!s.trim())return d("Swimlane title cannot be empty");let n=M("Swimlane title",s,300);if(n)return d(n);let a=Se(e.boardId,t.value.actor,t.value.boot.stateBranchRoot);if(l(a))return a;let r=Z(),i={id:Z(),...R(t.value.actor),action:"add.swimlane",payload:{id:r,name:s,parent:e.boardId,rank:a.value}},u=w([i],t.value.boot.stateBranchRoot);return l(u)?d(u.message):c("Created swimlane",{id:r,ref:A(r),title:s,boardId:e.boardId})},gr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);if(l(o))return o;let s=o.value,n=C(e.title);if(!n.trim())return d("Swimlane title cannot be empty");let a=M("Swimlane title",n,300);if(a)return d(a);if(s.title===n)return c("No changes made",{id:e.swimlaneId,ref:A(e.swimlaneId),title:n});let r={id:Z(),...R(t.value.actor),action:"edit.title",payload:{id:e.swimlaneId,name:n}},i=w([r],t.value.boot.stateBranchRoot);return l(i)?d(i.message):c("Edited swimlane title",{id:e.swimlaneId,ref:A(e.swimlaneId),title:n})},Ir=async e=>{let t=se(e.repoRoot);if(l(t))return t;let o=W();if(l(o))return o;let s=Q({repoRoot:t.value});if(l(s))return s;let n=de(s.value);if(l(n))return n;let a=me(n.value.events,n.value.unreadable);if(l(a))return a;let r=j(e.swimlaneId);if(l(r))return r;let i=Ee(e.boardId);if(l(i))return i;let u=ce(e.boardId,e.swimlaneId,e.position??{at:"end"},o.value,s.value);if(l(u))return u;let f={id:Z(),...R(o.value),action:"move.node",payload:{id:e.swimlaneId,parent:e.boardId,rank:u.value}},g=w([f],s.value);return l(g)?d(g.message):c("Moved swimlane",{id:e.swimlaneId,ref:A(e.swimlaneId),boardId:e.boardId})},vr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);if(l(o))return o;let s={id:Z(),...R(t.value.actor),action:"delete.node",payload:{id:e.swimlaneId}},n=w([s],t.value.boot.stateBranchRoot);return l(n)?d(n.message):c("Deleted swimlane",{id:e.swimlaneId,ref:A(e.swimlaneId)})};var V=e=>({path:e.path,sha:e.shas[e.shas.length-1]??""});var hr=e=>{let t=e.lastIndexOf("/");return t===-1?".":e.slice(0,t)},ws=({commits:e,patch:t})=>{let o=e.map(r=>r.time),n=t.files.map(r=>({...V(r),changed:r.addedCount+r.removed})).reduce((r,i)=>r===null||i.changed>r.changed?i:r,null),a=t.insertions+t.deletions;return{commits:e.length,authors:[...new Set(e.map(r=>r.author))].sort(),firstCommitAt:o.length?Math.min(...o):null,lastCommitAt:o.length?Math.max(...o):null,files:t.files.length,filesAdded:t.files.filter(r=>r.status==="added").length,filesModified:t.files.filter(r=>r.status==="modified").length,filesDeleted:t.files.filter(r=>r.status==="deleted").length,binaryFiles:t.files.filter(r=>r.binary).length,directories:new Set(t.files.map(r=>hr(r.path))).size,insertions:t.insertions,deletions:t.deletions,net:t.insertions-t.deletions,largestFile:n,concentration:n&&a>0?n.changed/a:0,selfChurn:t.selfChurn,truncated:t.truncated}};var P={line:["//"],block:[["/*","*/"]]},U={line:["#"],block:[]},Ot={line:["--"],block:[]},Ie={line:[],block:[["<!--","-->"]]},br={line:[],block:[]},S=(e,t)=>({name:e,comment:t}),nt=S("TypeScript",P),rt=S("JavaScript",P),Es={ts:nt,tsx:nt,mts:nt,cts:nt,js:rt,jsx:rt,mjs:rt,cjs:rt,py:S("Python",{line:["#"],block:[['"""','"""']]}),rb:S("Ruby",{line:["#"],block:[["=begin","=end"]]}),go:S("Go",P),rs:S("Rust",P),java:S("Java",P),kt:S("Kotlin",P),swift:S("Swift",P),c:S("C",P),h:S("C",P),cc:S("C++",P),cpp:S("C++",P),hpp:S("C++",P),cs:S("C#",P),php:S("PHP",P),scala:S("Scala",P),dart:S("Dart",P),lua:S("Lua",Ot),hs:S("Haskell",Ot),sql:S("SQL",Ot),ex:S("Elixir",U),exs:S("Elixir",U),pl:S("Perl",U),r:S("R",U),jl:S("Julia",U),sh:S("Shell",U),bash:S("Shell",U),zsh:S("Shell",U),vue:S("Vue",Ie),svelte:S("Svelte",Ie),html:S("HTML",Ie),xml:S("XML",Ie),md:S("Markdown",Ie),mdx:S("Markdown",Ie),css:S("CSS",{line:[],block:[["/*","*/"]]}),scss:S("CSS",P),less:S("CSS",P),yml:S("YAML",U),yaml:S("YAML",U),toml:S("TOML",U),ini:S("INI",U),json:S("JSON",br)},Rr="Other",xs=e=>{let t=e.slice(e.lastIndexOf("/")+1),o=t.lastIndexOf(".");return o<=0?"":t.slice(o+1).toLowerCase()},ae=e=>Es[xs(e)]?.name??Rr,Pe=e=>Es[xs(e)]?.comment??null,yr=[/\.(test|spec)\.[a-z0-9]+$/i,/(^|\/)test_[^/]+\.py$/,/_test\.[a-z0-9]+$/i,/(^|\/)conftest\.py$/,/Tests?\.(java|kt|cs|scala)$/],Ar=/(^|\/)(tests?|__tests__|spec|specs|e2e|src\/test|features)\//i,ve=e=>Ar.test(e)||yr.some(t=>t.test(e)),Tr=/(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|Cargo\.lock|go\.sum|poetry\.lock|Gemfile\.lock|composer\.lock)$/,Sr=/(^|\/)(node_modules|dist|build|out|target|vendor|coverage|\.next|__snapshots__)\//,wr=/(\.min\.(js|css)|\.map|\.snap|\.pb\.go|_pb2\.py)$/,X=e=>Tr.test(e)||Sr.test(e)||wr.test(e),Cs=e=>/(^|\/)(package\.json|go\.mod|Cargo\.toml|requirements[^/]*\.txt|pyproject\.toml|Gemfile|composer\.json|pom\.xml|build\.gradle(\.kts)?)$/.test(e),Bs=e=>/(^|\/)\.github\/workflows\//.test(e)||/(^|\/)(Dockerfile|docker-compose[^/]*\.ya?ml|Makefile|Jenkinsfile|\.gitlab-ci\.yml)$/.test(e)||/\.tf$/.test(e),Ls=e=>/\.(md|mdx|rst|txt)$/i.test(e)||/(^|\/)docs?\//i.test(e),Er=/\b(it|test|describe|context|suite)\.skip\b|\bx(it|describe|test)\s*\(|@pytest\.mark\.skip|@unittest\.skip|\bt\.Skip\s*\(|@(Ignore|Disabled)\b/,xr=/\b(it|test|describe|context|suite)\.only\b|\bf(it|describe|test)\s*\(/,ks=e=>Er.test(e),Ns=e=>xr.test(e);var Ps=/\b(TODO|FIXME|HACK|XXX)\b/,Cr=/[;{}]\s*$|^\s*(const|let|var|function|def|class|if|for|while|return|import|export|await|print)\b.*[=(]/,Mt=(e,t)=>{let o=e.trim();return o===""?"blank":t&&(t.line.some(s=>o.startsWith(s))||t.block.some(([s])=>o.startsWith(s))||t.block.some(([s])=>s==="/*")&&(o.startsWith("*")||o.startsWith("*/")))?"comment":"code"},Br=(e,t)=>{let o=e.trim();for(let s of[...t.line,...t.block.flat(),"*"])if(o.startsWith(s)){o=o.slice(s.length).trim();break}return o},Os=({patch:e,repoShareByLanguage:t})=>{let o=new Map,s=0,n=0,a=0,r=0,i=0,u=0;for(let g of e.files){if(g.binary||X(g.path))continue;let m=Pe(g.path);if(!m||m.line.length===0&&m.block.length===0)continue;let I=ae(g.path),v=o.get(I)??{comment:0,code:0};for(let{text:h}of g.added){let p=Mt(h,m);if(Ps.test(h)&&r++,p==="blank"){a++;continue}if(p==="comment"){s++,v.comment++,m&&Cr.test(Br(h,m))&&u++;continue}n++,v.code++}for(let{text:h}of g.removedLines)Ps.test(h)&&i++;o.set(I,v)}let f=s+n;return{byLanguage:[...o.entries()].map(([g,m])=>({name:g,commentLines:m.comment,codeLines:m.code,share:m.comment+m.code===0?0:m.comment/(m.comment+m.code),repoShare:t?.get(g)??null})).sort((g,m)=>m.commentLines+m.codeLines-(g.commentLines+g.codeLines)),commentLines:s,codeLines:n,blankLines:a,share:f===0?0:s/f,todoLinesAdded:r,todoLinesRemoved:i,commentedOutCodeLines:u}};var Lr=/\bconsole\.(log|debug|dir)\s*\(|\bdebugger\b|^\s*print\s*\(|\bfmt\.Print(ln|f)?\s*\(|\bSystem\.out\.print|\bdbg!\s*\(/,it=6,Dt=10,kr=e=>{let t=0;for(let o of e){if(o.trim()===""||o.startsWith(" "))continue;let s=o.length-o.trimStart().length;s>0&&(t===0||s<t)&&(t=s)}return Math.min(Math.max(t,2),8)},Nr=(e,t)=>{let o=e.length-e.trimStart().length;if(o===0)return 0;let s=e.slice(0,o).split(" ").length-1;return s>0?s:Math.floor(o/t)},Pr=e=>{if(e.length<it*2)return 0;let t=new Map,o=new Array(e.length).fill(!1);for(let s=0;s+it<=e.length;s++){let n=e.slice(s,s+it);if(n.some(i=>i.text.length<3))continue;let a=n.map(i=>i.text).join(`
5
+ `),r=t.get(a);if(r===void 0){t.set(a,{...n[0],at:s});continue}if(r.file!==n[0]?.file)for(let i=0;i<it;i++)o[r.at+i]=!0,o[s+i]=!0}return o.filter(Boolean).length},Ms=({patch:e})=>{let t=[],o=[],s=[],n=!1,a=0,r=0,i=null,u=[];for(let[f,g]of e.files.entries()){if(X(g.path)&&t.push(V(g)),Cs(g.path)&&o.push(V(g)),Bs(g.path)&&s.push(V(g)),Ls(g.path)&&(n=!0),g.binary||X(g.path))continue;let m=g.added.map(h=>h.text),I=kr(m),v=g.status!=="deleted";for(let h of m){Lr.test(h)&&a++;let p=Nr(h,I);p>r&&(r=p,i=V(g)),v&&u.push({text:h.trim(),file:f})}u.push({text:" ",file:f})}return{generatedPaths:t.slice(0,Dt),dependencyManifests:o.slice(0,Dt),buildOrCiPaths:s.slice(0,Dt),docsTouched:n,debugPrintLinesAdded:a,maxIndentLevels:r,deepestFile:i,duplicatedLines:Pr(u)}};var Ds=({patch:e,languagesBefore:t})=>{let o=new Map,s=0;for(let r of e.files){if(r.binary)continue;let i=r.addedCount+r.removed;if(X(r.path)){s+=i;continue}let u=ae(r.path),f=o.get(u)??{name:u,added:0,removed:0,addedInTests:0,share:0};f.added+=r.addedCount,f.removed+=r.removed,ve(r.path)&&(f.addedInTests+=r.addedCount),o.set(u,f)}let n=[...o.values()].reduce((r,i)=>r+i.added+i.removed,0),a=[...o.values()].map(r=>({...r,share:n===0?0:(r.added+r.removed)/n})).sort((r,i)=>i.added+i.removed-(r.added+r.removed));return{languages:a,introduced:t===null?[]:a.filter(r=>!t.has(r.name)).map(r=>r.name),generatedLines:s}};var Or=200,Ft=2e5,Mr=5e4,Dr=25,Fs=64*1024*1024,_t="",Fr=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/,_r=/^diff --git a\/(.+) b\/\1$/,_s=(e,t)=>e==="/dev/null"?null:e.startsWith(t)?e.slice(2):e,Gs=(e,t)=>e===null?"added":t===null?"deleted":"modified",Gr=()=>({byPath:new Map,insertions:0,deletions:0,selfChurn:0,retainedLines:0}),$r=(e,t)=>{let o=e.byPath,s="",n=null,a=null,r=null,i=!1,u=0,f=(m,I)=>I==="modified"&&m==="added"?"added":I,g=(m,I)=>{let v=o.get(m);if(v)return v.entry.status=f(v.entry.status,I),v.entry.shas.includes(s)||v.entry.shas.push(s),v;let p={entry:{path:m,status:I,binary:!1,added:[],addedCount:0,removed:0,removedLines:[],shas:[s]},pendingByText:new Map};return o.set(m,p),p};for(let m of t.split(`
6
+ `)){if(m.startsWith(_t)){s=m.slice(_t.length).trim(),n=null,a=null,r=null,i=!1;continue}if(m.startsWith("diff --git ")){n=null,r=null,i=!0,a=_r.exec(m)?.[1]??null;continue}if(i&&m.startsWith("Binary files ")&&a){let[,v=""]=/^Binary files (.*) differ$/.exec(m)??[],[h="",p=""]=v.split(" and ");n=g(a,Gs(h==="/dev/null"?null:h,p==="/dev/null"?null:p)),n.entry.binary=!0;continue}if(i&&m.startsWith("--- ")){r=_s(m.slice(4),"a/");continue}if(i&&m.startsWith("+++ ")){let v=_s(m.slice(4),"b/"),h=v??r??a;h&&(n=g(h,Gs(r,v)));continue}let I=Fr.exec(m);if(I){u=Number(I[1]),i=!1;continue}if(n){if(m.startsWith("+")){let v=m.slice(1);e.insertions++,n.entry.addedCount++,e.retainedLines<Ft&&(n.entry.added.push({sha:s,line:u,text:v}),e.retainedLines++),n.pendingByText.size<Mr&&n.pendingByText.set(v,(n.pendingByText.get(v)??0)+1),u++;continue}if(m.startsWith("-")){let v=m.slice(1);e.deletions++,n.entry.removed++,e.retainedLines<Ft&&(n.entry.removedLines.push({sha:s,line:0,text:v}),e.retainedLines++);let h=n.pendingByText.get(v)??0;h>0&&v.trim().length>2&&(e.selfChurn++,n.pendingByText.set(v,h-1))}}}},Wr=e=>({files:[...e.byPath.values()].map(t=>t.entry),insertions:e.insertions,deletions:e.deletions,selfChurn:e.selfChurn,retainedLines:e.retainedLines});var $s=async({repoRoot:e,shas:t,cwdOf:o=()=>e})=>{if(t.length===0)return c("No commits to scan",{files:[],insertions:0,deletions:0,selfChurn:0,scannedCommits:0,truncated:!1});let s=t.slice(0,Or).reverse(),n=Gr(),a=0,r=0,i=!1,u=[];for(let g of s){let m=o(g),I=u[u.length-1];I&&I.cwd===m&&I.shas.length<Dr?I.shas.push(g):u.push({cwd:m,shas:[g]})}for(let{cwd:g,shas:m}of u){let I=await De({cwd:g,maxOutput:Math.max(1,Fs-a),keepPartial:!0,args:["-c","core.quotePath=false","show","--unified=0","--no-renames","--no-color",`--format=${_t}%H`,...m]});if(l(I)){if(g!==e)continue;return d(I.message)}if($r(n,I.value.stdout),a+=I.value.stdout.length,r+=m.length,I.value.truncated||a>Fs){i=!0;break}}let f=Wr(n);return c("Scanned ticket patch",{files:f.files,insertions:f.insertions,deletions:f.deletions,selfChurn:f.selfChurn,scannedCommits:r,truncated:i||r<t.length||f.retainedLines>=Ft})};var jr=40,Ur=/^\d{6} blob ([0-9a-f]{40})\t(.+)$/,Ws=async({repoRoot:e,sha:t})=>{let o=await Fe({cwd:e,args:["-c","core.quotePath=false","ls-tree","-r",`${t}~1`]});if(o.exitCode!==0)return null;let s=new Set,n=new Map;for(let g of o.stdout.split(`
7
+ `)){let m=Ur.exec(g);if(!m)continue;let[,I="",v=""]=m;if(X(v))continue;let h=ae(v);if(s.add(h),ve(v)||!Pe(v))continue;let p=n.get(h)??[];p.length<jr&&(p.push({blob:I,path:v}),n.set(h,p))}let a=[...n.values()].flat(),r=await Wt(a.map(g=>g.blob),e);if(l(r))return{languages:s,commentShareByLanguage:new Map};let i=r.value,u=new Map;for(let{blob:g,path:m}of a){let I=i.get(g);if(I===void 0)continue;let v=Pe(m),h=ae(m),p=u.get(h)??{comment:0,code:0};for(let b of I.split(`
8
+ `)){let T=Mt(b,v);T==="comment"&&p.comment++,T==="code"&&p.code++}u.set(h,p)}let f=new Map;for(let[g,m]of u){let I=m.comment+m.code;I>0&&f.set(g,m.comment/I)}return{languages:s,commentShareByLanguage:f}};var js=({patch:e})=>{let t=0,o=0,s=[],n=[],a=0,r=0;for(let i of e.files)if(!(i.binary||X(i.path))&&ve(i.path)){t+=i.addedCount,o+=i.removed,i.status==="added"&&s.push(V(i)),i.status==="deleted"&&n.push(V(i));for(let{text:u}of i.added)ks(u)&&a++,Ns(u)&&r++}return{testLinesAdded:t,testLinesRemoved:o,addedTestFiles:s,deletedTestFiles:n,skippedTestLinesAdded:a,focusedTestLinesAdded:r}};var Hr=e=>e.reduce((t,o)=>t===null||o.time<t.time?o:t,null),Us=async({repoRoot:e,ref:t,commits:o})=>{let s=await Co(e);if(l(s))return d(s.message);let n=Bo(s.value),a=new Map(o.map(m=>[m.sha,m.repo])),r=m=>n(a.get(m))??e,i=await $s({repoRoot:e,shas:o.map(m=>m.sha),cwdOf:r});if(l(i))return d(i.message);let u=i.value,f=Hr(o),g=f?await Ws({repoRoot:r(f.sha),sha:f.sha}):null;return c("Derived issue stats",{ref:t,shape:ws({commits:o,patch:u}),languages:Ds({patch:u,languagesBefore:g?.languages??null}),tests:js({patch:u}),comments:Os({patch:u,repoShareByLanguage:g?.commentShareByLanguage??null}),flags:Ms({patch:u})})};var at=e=>{if(l(e))return e;let t=Xe(),o=l(t)?{}:t.value.emailLinks,s=l(t)?{}:t.value.contributors,n=oo(o),a=e.value.map(r=>({...r,authorIdentity:qo({authorName:r.author,authorEmail:r.authorEmail,owners:n,registry:s})}));return c(e.message,a)};var Kr=32,Oe=new Map;var Xr=(e,t)=>{if(Oe.set(e,t),Oe.size>Kr){let o=Oe.keys().next();o.done||Oe.delete(o.value)}return t},Hs=e=>{let t=at(e);return l(t)?d(t.message):c("Matched commits by ref",t.value.map(o=>({sha:o.sha,...o.repo?{repo:o.repo}:{},time:o.time,author:o.authorIdentity?.resolved?o.authorIdentity.name:o.author,subject:o.subject})))},zs=e=>{let t=_e(e??process.cwd());return l(t)?d(t.message):t},Ks=async(e,t,o)=>{let s=[e,t,o.map(r=>`${r.sha}:${r.author}`).join(",")].join(" "),n=Oe.get(s);if(n)return c("Derived issue stats",n);let a=await Us({repoRoot:e,ref:t,commits:o});return l(a)?d(a.message):c("Derived issue stats",Xr(s,a.value))},yc=async(e={idOrRef:""})=>{let t=e.idOrRef.trim();if(!t)return d("idOrRef must not be empty");let o=t.length>7?A(t):t.toUpperCase(),s=zs(e.repoRoot);if(l(s))return s;let n=Hs(await Lo({repoRoot:s.value,ref:o,end:e.end}));return l(n)?n:Ks(s.value,o,n.value)},Xs=async e=>{let t=zs(e.repoRoot);if(l(t))return t;let o=Hs(await ze({repoRoot:t.value,refs:e.refs,end:e.end}));return l(o)?o:Ks(t.value,e.label,o.value)};var qs=e=>{let t=B();if(l(t))return t;let o=je(e);return o?c("Found goal",{id:o.id,refs:mo(o.id).map(s=>A(s.id))}):d(`No goal called or with the id "${e}"`)},Vs=async e=>{let t=qs(e.goal);return l(t)?t:Xs({repoRoot:e.repoRoot,label:t.value.id,refs:t.value.refs,end:e.end})},qr=async e=>{let t=qs(e.goal);return l(t)?t:_o(e.repoRoot,at(await ze({repoRoot:e.repoRoot,refs:t.value.refs,end:e.end})))},Vr=async e=>{let t=await L(e.repoRoot);return l(t)?t:Vs({repoRoot:t.value.repoRoot,goal:e.goal})};import{ulid as he}from"ulid";async function Yr(e){let t=await L(e.repoRoot);if(l(t))return t;let o=W();if(l(o))return o;let s=ke(e);if(l(s))return s;let n=C(e.tagName).trim();if(!n)return d("Tag name cannot be empty");let a=M("Tag name",n,60);if(a)return d(a);let r=Ne(s.value,k);if(!e.issueIds&&r.failed[0])return d(r.failed[0].reason);if(r.done.length===0)return d(ge("Tagged",r).message);let i=_.findTagByName(n),u=i?.id??he(),f=[...i?[]:[{id:he(),...R(o.value),action:"create.tag",payload:{id:u,name:n}}],...r.done.map(({id:v})=>({id:he(),...R(o.value),action:"add.issue.tag",payload:{id:v,tag:u}}))],g=w(f,t.value.stateBranchRoot);if(l(g))return d(g.message);let m={id:u,name:n};if(!e.issueIds)return c("Added issue tag",{...r.done[0],tag:m});let I=ge("Tagged",r);return l(I)?I:c(I.message,{...I.value,tag:m})}var Jr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.tags[e.tagId];if(!o)return d("Tag not found");if(o.tombstoned)return d("Tag is already deleted");let s=[{id:he(),...R(t.value.actor),action:"tombstone.tag",payload:{id:e.tagId}}],n=w(s,t.value.boot.stateBranchRoot);return l(n)?d(n.message):c("Deleted tag",{id:o.id,name:o.name})},Qr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.tags[e.tagId];if(!o)return d("Tag not found");if(!o.tombstoned)return d("Tag is not deleted");if(_.findTagByName(o.name))return d(`Cannot restore: another tag is already named "${o.name}"`);let s=[{id:he(),...R(t.value.actor),action:"restore.tag",payload:{id:e.tagId,name:o.name}}],n=w(s,t.value.boot.stateBranchRoot);return l(n)?d(n.message):c("Restored tag",{id:o.id,name:o.name})},Zr=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;if(!t.value.state.tags[e.tagId])return d("Tag not found");let s={id:he(),...R(t.value.actor),action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},n=w([s],t.value.boot.stateBranchRoot);return l(n)?d(n.message):c("Removed issue tag",{id:e.issueId,ref:A(e.issueId),tagId:e.tagId})};import{ulid as J}from"ulid";var ei=async e=>{let t=$t(e.name,"name");if(l(t))return d(t.message);let o=await y(e.repoRoot);if(l(o))return o;let s=o.value.actor,n=!!o.value.state.contributors[s.userId];if(!n){let r=w([{id:J(),...R(s),action:"create.contributor",payload:{id:s.userId,name:s.userName}}],o.value.boot.stateBranchRoot);if(l(r))return d(r.message)}let a=Object.values(o.value.state.nodes).filter(r=>$(r)&&!r.isDeleted).flatMap(r=>{let{boardDescription:i}=xe(r.id);return i?[{id:r.id,title:C(r.title),boardDescription:i}]:[]});return c(`Assumed ${s.userName}`,{...s,registered:!n,...a.length?{boards:a}:{}})},Ys=async(e,t)=>{let o=ue(e).get(t);return o===void 0?void 0:{id:t,name:o}},ti=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;let s=e.self?t.value.actor.userId:e.assigneeId;if(s){let v=t.value.state.contributors[s],h=v?void 0:await Ys(t.value.boot.stateBranchRoot,s);if(!v&&!h)return d("Unknown assignee id");let p=v??h,b=[...v?[]:[{id:J(),...R(t.value.actor),action:"create.contributor",payload:{id:p.id,name:p.name}}],{id:J(),...R(t.value.actor),action:"add.issue.assignee",payload:{id:e.issueId,assignee:p.id}}],T=w(b,t.value.boot.stateBranchRoot);return l(T)?d(T.message):c("Added issue assignee",{id:e.issueId,ref:A(e.issueId),assignee:{id:p.id,name:p.name}})}let n=C(e.assigneeName??"").trim();if(!n)return d("Provide assigneeId, self or assigneeName");let a=M("Assignee name",n,80);if(a)return d(a);let r=At({events:t.value.state.eventLog??[],registry:t.value.state.contributors,logFileNames:ue(t.value.boot.stateBranchRoot)}).filter(v=>v.name===n);if(r.length>1)return d(`"${n}" matches ${r.length} contributors (${r.map(({id:v})=>v).join(", ")}). Assign by assigneeId to choose.`);let i=r[0];if(!i&&!e.createUnlinked)return d(`No contributor named "${n}". Assign by id, or pass createUnlinked to add them as an external assignee.`);let u=i?.id??J(),f=i?.name??n,m=[...!!t.value.state.contributors[u]?[]:[{id:J(),...R(t.value.actor),action:"create.contributor",payload:{id:u,name:f}}],{id:J(),...R(t.value.actor),action:"add.issue.assignee",payload:{id:e.issueId,assignee:u}}],I=w(m,t.value.boot.stateBranchRoot);return l(I)?d(I.message):c("Added issue assignee",{id:e.issueId,ref:A(e.issueId),assignee:{id:u,name:f}})},oi=async e=>{let t=await y(e.repoRoot);if(l(t))return t;if(!t.value.state.contributors[e.contributorId])return d("Contributor not found");if(await Ys(t.value.boot.stateBranchRoot,e.contributorId))return d("Cannot remove a contributor who has authored events \u2014 their name appears throughout the log");let n=[{id:J(),...R(t.value.actor),action:"tombstone.contributor",payload:{id:e.contributorId}}],a=w(n,t.value.boot.stateBranchRoot);return l(a)?d(a.message):c("Tombstoned contributor",{id:e.contributorId,name:Ge})},si=async(e,t)=>{let o=oe(e);if(l(o))return;let s;for(let n of o.value){if(n.action!=="create.contributor")continue;let a=n.payload;a.id===t&&a.name&&(s=a.name)}return s},ni=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.contributors[e.contributorId];if(!o)return d("Contributor not found");if(!o.tombstoned)return d("Contributor is not tombstoned");let s=await si(t.value.boot.stateBranchRoot,e.contributorId);if(!s)return d("Cannot restore this contributor \u2014 no original name found in the event log");let n=[{id:J(),...R(t.value.actor),action:"restore.contributor",payload:{id:e.contributorId,name:s}}],a=w(n,t.value.boot.stateBranchRoot);return l(a)?d(a.message):c("Restored contributor",{id:e.contributorId,name:s})},ri=async(e={})=>{let t=await y(e.repoRoot);if(l(t))return t;let o=oe(t.value.boot.stateBranchRoot);if(l(o))return d(o.message);let s=e.boardId?ns(o.value,e.boardId):o.value,n=new Set,a=wo(t.value.boot.stateBranchRoot);if(l(a))return d(a.message);for(let u of a.value)u.userId&&n.add(u.userId);let r=t.value.state.contributors,i=At({events:s,registry:r,logFileNames:ue(t.value.boot.stateBranchRoot)}).map(({id:u,name:f,isExternal:g})=>({...D(u,f),isSelf:u===t.value.actor.userId,isExternal:g,isRemoved:r[u]?.tombstoned===!0,hasAuthoredAnywhere:n.has(u)}));return c("Listed board contributors",i)},ii=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;if(!t.value.state.contributors[e.assigneeId])return d("Assignee not found");let s={id:J(),...R(t.value.actor),action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},n=w([s],t.value.boot.stateBranchRoot);return l(n)?d(n.message):c("Removed issue assignee",{id:e.issueId,ref:A(e.issueId),assigneeId:e.assigneeId})};import{ulid as dt}from"ulid";var ai=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=k(e.issueId);if(l(o))return o;let s=e.body.trim();if(!s)return d("Comment cannot be empty");if(s.length>4e3)return d(`Comment cannot exceed ${4e3} characters (got ${s.length})`);let n=dt(),a={id:dt(),...R(t.value.actor),action:"add.issue.comment",payload:{id:n,issue:e.issueId,md:s,author:t.value.actor.userId}},r=w([a],t.value.boot.stateBranchRoot);return l(r)?d(r.message):c("Added issue comment",{id:n,issueId:e.issueId,body:s})},li=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.eventLog.find(i=>i.action==="add.issue.comment"&&i.payload.id===e.commentId);if(!o)return d("Unable to resolve comment");if(o.payload.author!==t.value.actor.userId)return d("You can only delete your own comments");let s=k(o.payload.issue);if(l(s))return s;if(t.value.state.eventLog.some(i=>i.action==="delete.issue.comment"&&i.payload.id===e.commentId))return c("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let a={id:dt(),...R(t.value.actor),action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},r=w([a],t.value.boot.stateBranchRoot);return l(r)?d(r.message):c("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},di=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=t.value.state.eventLog.find(u=>u.action==="add.issue.comment"&&u.payload.id===e.commentId);if(!o)return d("Unable to resolve comment");if(o.payload.author!==t.value.actor.userId)return d("You can only edit your own comments");let s=k(o.payload.issue);if(l(s))return s;if(t.value.state.eventLog.some(u=>u.action==="delete.issue.comment"&&u.payload.id===e.commentId))return d("Comment was deleted");let a=e.body.trim();if(!a)return d("Comment cannot be empty");if(a.length>4e3)return d(`Comment cannot exceed ${4e3} characters (got ${a.length})`);let r={id:dt(),...R(t.value.actor),action:"edit.issue.comment",payload:{id:e.commentId,issue:o.payload.issue,md:a}},i=w([r],t.value.boot.stateBranchRoot);return l(i)?d(i.message):c("Edited issue comment",{id:e.commentId,issueId:o.payload.issue,body:a})};import{ulid as Js}from"ulid";var ui=async e=>{let t=await y(e.repoRoot);if(l(t))return t;if(!Zt(e.email))return d(`Not an email address: ${e.email}`);let o=ye(e.email),s=e.contributorId??t.value.actor.userId;if(!t.value.state.contributors[s])return d(`Unknown contributor: ${s}`);let n=ct(t.value.state.emailLinks,o);if(n.includes(s))return c(`${o} is already yours`,{contributor:s,email:o,contested:n.filter(r=>r!==s)});let a=w([{id:Js(),action:"link.contributor.email",payload:{contributor:s,email:o},userId:t.value.actor.userId}],t.value.boot.stateBranchRoot);return l(a)?d(a.message):c(n.length>0?`Claimed ${o}, but somebody else claims it too, so it now resolves to neither of you`:`Claimed ${o}`,{contributor:s,email:o,contested:n})},ci=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let o=ye(e.email),s=e.contributorId??t.value.actor.userId,n=t.value.state.emailLinks[eo(o,s)];if(!n||n.tombstoned)return d(`No such link: ${o} to ${s}`);if(!so(t.value.actor.userId,n))return d("Only whoever made a claim, or the contributor it names, may undo it");let a=w([{id:Js(),action:"unlink.contributor.email",payload:{contributor:s,email:o},userId:t.value.actor.userId}],t.value.boot.stateBranchRoot);return l(a)?d(a.message):c(`Unclaimed ${o}`,{contributor:s,email:o})},mi=async(e={})=>{let t=await L(e.repoRoot);if(l(t))return t;let o=B();if(l(o))return o;let{emailLinks:s,contributors:n}=o.value,a=new Map;for(let m of Object.values(s)){if(m.tombstoned)continue;let I=a.get(m.email)??new Set;I.add(m.contributor),a.set(m.email,I)}let r=[...a.entries()].map(([m,I])=>({email:m,contested:I.size>1,claimants:[...I].map(v=>D(v,n[v]?.name))})).sort((m,I)=>m.email.localeCompare(I.email)),i=W(),u=l(i)?[]:to(s,i.value.userId),f=Ut().gitEmail,g=f?ct(s,f).filter(m=>l(i)||m!==i.value.userId):[];return c("Listed contributor emails",{emails:r,mine:u,git:f?{email:f,linkedToMe:u.includes(f),heldByOthers:g.map(m=>D(m,n[m]?.name))}:null})},pi=async(e={})=>{let t=await y(e.repoRoot);if(l(t))return t;let{userId:o,userName:s}=t.value.actor,n=le(t.value.boot.repoRoot),a=await Ke({repoRoot:t.value.boot.repoRoot,stateBranch:l(n)?void 0:n.value,names:[s,await pe(t.value.boot.repoRoot)],links:t.value.state.emailLinks});if(l(a))return a;let r=Vo(a.value),i=r.filter(u=>u.looksLikeYours);return c(r.length===0?"No unclaimed addresses in this history":`${r.length} unclaimed address(es) in this history, ${i.length>0?`${i.length} of which look like yours`:"none obviously yours"}. Show them to the user and link only the ones they confirm; each is a permanent event that replicates to every clone.`,{contributor:o,candidates:r,likely:i.length})};var Gt=e=>{let t=ko(e);return l(t)?d(t.message):c("Listed repos",{repos:t.value,claimedBytes:Do(e),limit:Kt,allowLocal:zt()})},fi=async(e={})=>{let t=Te(e.repoRoot);return l(t)?d(t.message):Gt(t.value)},gi=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let{repoRoot:o}=t.value.boot,s=await Fo({repoRoot:o,actorId:t.value.actor.userId,url:e.url,branches:e.branches,since:e.since,label:e.label,mode:e.previewOnly?"preview":e.confirm?"confirm":"auto"});if(l(s))return d(s.message);let n=Gt(o);return l(n)?d(n.message):c(s.message,{...n.value,...s.value.kind==="preview"?{preview:s.value.preview}:{}})},Ii=async e=>{let t=await y(e.repoRoot);if(l(t))return t;let{repoRoot:o}=t.value.boot,s=No({repoRoot:o,actorId:t.value.actor.userId,repo:e.repo});if(l(s))return d(s.message);let n=Gt(o);return l(n)?d(n.message):c(s.message,n.value)},vi=e=>(Mo("repo"in e?e.repo:Xt(e.url.trim())),c("Cancelled",null)),hi=async(e,t={},o=2e4)=>{if(l(e))return e;let s,n=await Promise.race([Qs(t),new Promise(a=>{s=setTimeout(()=>a(null),o)})]);return clearTimeout(s),n===null?c(`${e.message} \xB7 still fetching other repos; epiq_repo_list shows how they stand`,e.value):l(n)||n.value.length===0?e:c([e.message,Oo(n.value)].filter(Boolean).join(" \xB7 "),{...e.value,repos:n.value})},Qs=async(e={})=>{let t=Te(e.repoRoot);return l(t)?d(t.message):Po({repoRoot:t.value,minIntervalMs:e.minIntervalMs})};var Zs=(e,t)=>{let o=0,s=0,n=null;for(let a of e){if(a.userId!==t)continue;a.action==="add.issue"&&o++,a.action==="add.issue.comment"&&s++;let r=Jt(a.id);if(l(r))continue;let i=r.value.getTime();(n===null||i<n)&&(n=i)}return{tickets:o,comments:s,joinedAt:n}};var bi=async(e={})=>{let t=await y(e.repoRoot);if(l(t))return t;let{userId:o,userName:s}=t.value.actor,n=Zs(t.value.state.eventLog,o),a=le(t.value.boot.repoRoot),r=await Ke({repoRoot:t.value.boot.repoRoot,stateBranch:l(a)?void 0:a.value,names:[s,await pe(t.value.boot.repoRoot)],links:t.value.state.emailLinks}),i=l(r)?[]:r.value.filter(u=>u.claimedBy.length===1&&u.claimedBy[0]===o);return c("Derived personal stats",{...n,scanned:!l(r),commits:i.reduce((u,f)=>u+f.commits,0),claimedEmails:i.length})};var en=e=>{if(e.length===0)return null;let t=Math.floor(e.length/2);return e.length%2===0?(e[t-1]+e[t])/2:e[t]};var Ri=8,yi=(e,t)=>{let o=new Date(e);return o.setHours(0,0,0,0),o.setDate(o.getDate()-(o.getDay()+6)%7),Array.from({length:t},(s,n)=>{let a=new Date(o);return a.setDate(o.getDate()-7*(t-1-n)),a.getTime()})},Ai=e=>en([...e].sort((t,o)=>t-o)),tn=({boardId:e,lanes:t,formerLaneIds:o=[],tickets:s,now:n})=>{let a=new Map(t.map((E,x)=>[E.id,x])),r=new Set(o),i=E=>E!=null&&(a.has(E)||r.has(E)),f=s.map(E=>({ticket:E,visits:Lt(E.log,E.createdAt)})).filter(({visits:E})=>E.some(x=>i(x.laneId))),g=E=>{let x=te(E);return x===null?null:Math.min(Re(x,n),n)},m=E=>{let x=E.flatMap(q=>{let G=a.get(q.laneId);return G===void 0?[]:[G]});return x.some((q,G)=>G>0&&q<x[G-1])},I=f.flatMap(({ticket:E,visits:x})=>{let q=E.log.findLast(be=>be.action==="close.issue");if(!q||i(E.parentNodeId))return[];let G=g(q),sn=x.at(-2)?.laneId;if(G===null||!i(sn))return[];let nn=x.slice(0,-1).flatMap((be,rn)=>i(be.laneId)?[{laneId:be.laneId,ms:x[rn+1].enteredAt-be.enteredAt}]:[]);return[{closedAt:G,leadTime:G-E.createdAt,sentBack:m(x),stays:nn}]}),v=yi(n,Ri),h=v[0],p=I.filter(E=>E.closedAt>=h),b=v.map((E,x)=>{let q=v[x+1]??1/0;return{t:E,closed:p.filter(G=>G.closedAt>=E&&G.closedAt<q).length}}),T=new Map;for(let{stays:E}of p)for(let{laneId:x,ms:q}of E)T.set(x,(T.get(x)??0)+q);let Y=t.reduce((E,x)=>E+(T.get(x.id)??0),0),on=t.flatMap(E=>{let x=T.get(E.id)??0;return x<=0?[]:[{laneId:E.id,title:E.title,meanMs:x/p.length,share:x/Y}]});return{boardId:e,throughput:b,filed:f.filter(({ticket:E,visits:x})=>E.createdAt>=h&&i(x[0]?.laneId)).length,closed:p.length,medianLeadTimeMs:Ai(p.map(E=>E.leadTime)),sentBackShare:p.length===0?null:p.filter(E=>E.sentBack).length/p.length,laneTime:on}};var Ti=e=>{let t=B();if(l(t))return t;let o=Object.values(t.value.nodes),s=o.find(r=>r.id===e.boardId);if(!s||s.isDeleted||!$(s))return d("Board not found");let n=o.filter(r=>H(r)&&r.parentNodeId===s.id),a=n.filter(r=>!r.isDeleted).sort((r,i)=>r.rank.localeCompare(i.rank));return c("Derived board overview",tn({boardId:s.id,lanes:a,formerLaneIds:n.filter(r=>r.isDeleted).map(r=>r.id),tickets:o.filter(r=>!r.isDeleted).filter(F).map(r=>({id:r.id,parentNodeId:r.parentNodeId,log:r.log??[],createdAt:O(r.id)})),now:Date.now()}))};export{Lt as a,us as b,z as c,Ji as d,xn as e,Qi as f,Zi as g,fs as h,pe as i,B as j,Nn as k,Pn as l,On as m,Mn as n,vs as o,Dn as p,Fn as q,Gn as r,Un as s,Hn as t,zn as u,Xn as v,Vn as w,kt as x,Jn as y,Qn as z,Zn as A,er as B,tr as C,sr as D,nr as E,ir as F,ar as G,lr as H,dr as I,ur as J,cr as K,mr as L,pr as M,fr as N,gr as O,Ir as P,vr as Q,at as R,yc as S,Vs as T,qr as U,Vr as V,Yr as W,Jr as X,Qr as Y,Zr as Z,ei as _,ti as $,oi as aa,ni as ba,ri as ca,ii as da,ai as ea,li as fa,di as ga,ui as ha,ci as ia,mi as ja,pi as ka,bi as la,fi as ma,gi as na,Ii as oa,vi as pa,hi as qa,Qs as ra,en as sa,Ti as ta};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ var o="1.16.0";export{o as a};