epiq 1.16.0 → 1.16.1

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,17 @@
1
+ #!/usr/bin/env node
2
+ import{a as F}from"./chunk-SCSGIFUR.js";import{$ as vn,A as ee,B as Et,D as on,E as rn,F as nn,G as sn,H as an,I as ln,J as mn,K as cn,M as dn,N as un,P as pn,Q as fn,R as gn,S as yn,T as io,U as Ct,V as hn,W as bn,Y as xn,Z as wn,a as Dr,b as pe,ba as Sn,c as ie,ca as In,d as Or,e as Ur,ea as Tn,f as Gr,fa as En,g as $r,ga as Pt,h as Fr,ha as At,i as Hr,ia as Cn,j as kr,ja as Pn,ka as An,l as Wr,la as so,m as Vr,ma as ao,n as Kr,na as Nn,oa as Ae,p as Yr,pa as lo,q as qr,qa as Mn,r as Jr,ra as Rn,s as Xr,t as zr,ta as Bn,u as Qr,ua as Ln,v as Zr,va as jn,w as en,y as tn,z as Tt}from"./chunk-5E42KQM3.js";import{$ as zo,$b as vt,Ab as ne,Ac as Lr,Bb as dr,Bc as jr,Cb as ur,Cc as q,Da as Qo,Db as b,E as ro,Eb as pr,Fb as ht,G as ko,Ib as Ce,Ic as _r,Ka as $e,Kb as fr,L as Wo,La as Zo,Lb as ue,P as Vo,Pb as bt,Q as Ko,Qb as xt,Ra as de,T as ct,Ta as Ee,U as Te,Ub as gr,V as Yo,Vb as yr,Wb as hr,X as H,Xb as br,Y as qo,Yb as wt,Z as Jo,Zb as xr,_ as Xo,_b as wr,a as _o,aa as dt,ab as er,ac as vr,b as st,ba as Ge,bb as tr,bc as Sr,c as at,cb as or,cc as Ir,da as ut,db as gt,ea as pt,fc as Tr,g as lt,gb as yt,gc as Er,hb as rr,hc as Cr,ia as ft,ic as Pr,j as Do,k as oe,l as Oo,mc as Ar,n as Ie,nc as no,o as re,oc as Nr,p as Uo,pc as St,q as Ue,qb as nr,qc as It,r as m,rb as ir,rc as Mr,s as Go,sb as sr,sc as Rr,t as $o,tb as ar,tc as Q,u as Fo,ub as lr,uc as Pe,v as Ho,w as oo,wc as O,x as mt,xc as Fe,yb as mr,zb as cr,zc as Br}from"./chunk-GOROXQFX.js";import{f as it,g as jo}from"./chunk-WUCQWBQE.js";import{b as G,c as T,d as h,e as $}from"./chunk-5RIQL7P4.js";import z from"chalk";import{render as Dl}from"ink";import Ol from"meow";import Ul from"react";import gs from"node:os";import ys from"node:path";import He from"chalk";var Nt=["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557","\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551","\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551\u2584\u2584 \u2588\u2588\u2551","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D","\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2580\u2580\u255D "];var Mt=" ",On=He.hex(m.secondary2),_n=He.hex(m.gray),hs=()=>{let t=Nt[0].length+Nt.length*2;return Nt.map((o,n)=>Array.from(o).map((s,u)=>{let[r,f,y]=$o((u+n*2)/t);return He.rgb(r,f,y)(s)}).join(""))},bs=e=>{let t=gs.homedir();return e===t||e.startsWith(t+ys.sep)?"~"+e.slice(t.length):e},Dn=(e,t)=>`${Mt}${He.hex(m.accent)("\u279C")} ${On(e.padEnd(9))}${t}`,mo=({url:e,repoRoot:t,version:o,reused:n})=>["",...hs().map(s=>Mt+s),"",`${Mt}${On("gui")} ${_n(`\xB7 v${o}`)}`,"",Dn("Local",He.hex(m.accent).bold(e)),Dn("Project",bs(t)),"",Mt+_n(n?"already running for this project \xB7 opened in your browser":"press ctrl+c to stop"),""].join(`
3
+ `);import{spawn as xs}from"node:child_process";import ke from"node:process";var Un=(e=ke.platform,t=ke.env)=>e==="darwin"||e==="win32"||!!(t.DISPLAY||t.WAYLAND_DISPLAY||t.BROWSER),Gn=e=>{let t=ke.platform==="darwin"?"open":ke.platform==="win32"?"cmd":"xdg-open",o=ke.platform==="win32"?["/c","start","",e]:[e];try{let n=xs(t,o,{detached:!0,stdio:"ignore"});n.on("error",s=>{logger.info(`[gui] could not open a browser: ${s.message}`)}),n.unref()}catch(n){logger.info(`[gui] could not open a browser: ${String(n)}`)}};import{readFile as hi,stat as ca}from"node:fs/promises";import{createHash as da}from"node:crypto";import ua from"node:http";import xe from"node:path";import{fileURLToPath as pa}from"node:url";import ws from"node:fs";import $n from"node:path";var We=Number(process.env.EPIQ_GUI_PORT)||3710,co="/api/instance",uo="epiq",Rt=e=>{try{return ws.realpathSync($n.resolve(e))}catch{return $n.resolve(e)}},vs=e=>{let t=e;return typeof t=="object"&&t!==null&&t.app===uo&&typeof t.repoRoot=="string"&&typeof t.version=="string"&&typeof t.pid=="number"},Fn=async(e,t=500)=>{let o=new AbortController,n=setTimeout(()=>o.abort(),t);try{let s=await fetch(`http://127.0.0.1:${e}${co}`,{signal:o.signal});if(!s.ok)return null;let u=await s.json();return vs(u)?u:null}catch{return null}finally{clearTimeout(n)}};var Ss=6e4,Hn=e=>{let t,o=!1,n=!1,s=0,u=()=>{let g=Oo();return h(g)?(st.error(g.message),null):g.value},r=()=>{let g=u();if(!g)return!1;let l=Ie();return h(l)?!1:!!g.autoSync&&Ar(l.value)===null},f=()=>{let g=_o(u()?.autoSyncDebounceMs);return Math.max(0,g-(Date.now()-s))},y=async()=>{if(!(o||n)&&r()){n=!0,s=Date.now();try{await pe(async()=>{if(ie().mode!=="live")return!1;let l=await Et({repoRoot:e.project.repoRoot});return await e.publisher.publishIfLogMoved(),!h(l)})&&e.onReposFetch?.(Ss)}finally{n=!1,p()}}};function p(){o||!r()||n||t||(t=setTimeout(()=>{t=void 0,y()},f()))}return p(),{queueSync:p,reschedule:()=>{t&&(clearTimeout(t),t=void 0),p()},dispose:()=>{o=!0,t&&clearTimeout(t)}}};var Bt=(e,t)=>{let o,n=!1,s=async()=>{let u=Date.now();try{await e()}catch(r){logger.error("[watch] check threw",r)}n||(o=setTimeout(s,Math.max(t,Date.now()-u)))};return o=setTimeout(s,t),()=>{n=!0,o&&clearTimeout(o)}};var Is=/^(```|~~~)[^\n]*\n[\s\S]*?\n\1[ \t]*$/gm,Ts=/^(?:```|~~~)[\s\S]*$/m,Es=/^[ \t]*\|?[ \t]*:?-{2,}:?[ \t]*(?:\|[ \t]*:?-{2,}:?[ \t]*)*\|?[ \t]*$/gm,Cs=/^[ \t]*\|.*$/gm,Ps=/!\[[^\]]*\]\([^)]*\)/g,As=/\[([^\]]*)\]\([^)]*\)/g,Ns=/^[ \t]*(?:[#>]+[ \t]*|[-*+][ \t]+|\d+[.)][ \t]+)/gm,Ms=/^[ \t]*(?:-{3,}|\*{3,}|_{3,})[ \t]*$/gm,Rs=/[*`~]/g,Bs=/(?<![0-9A-Za-z])_|_(?![0-9A-Za-z])/g,Ls=e=>Xo(e.replace(Is," ").replace(Ts," ").replace(Ps," ").replace(As,"$1").replace(Ms," ").replace(Es," ").replace(Cs,t=>t.replaceAll("|"," ")).replace(Ns,"").replace(Rs,"").replace(Bs,"")),js=.5,kn=(e,t)=>{if(t<=0)return"";let o=Ls(e);if(o.length<=t)return o;let n="\u2026",s=t-n.length;if(s<=0)return n.slice(0,t);let u=o.slice(0,s),r=u.lastIndexOf(" ");return`${(r>=s*js?u.slice(0,r):u).trimEnd()}${n}`};var _s=e=>({...e,boards:(e.boards??[]).map(t=>({...t,swimlanes:(t.swimlanes??[]).map(o=>({...o,issues:(o.issues??[]).map(n=>({...n,description:""}))}))})),commentsByIssueId:Object.fromEntries(Object.entries(e.commentsByIssueId??{}).filter(([,t])=>t.length>0).map(([t,o])=>[t,o.map(n=>({...n,body:""}))])),attachmentsByIssueId:Object.fromEntries(Object.entries(e.attachmentsByIssueId??{}).filter(([,t])=>t.length>0))}),be=e=>h(e)?e:T(e.message,_s(e.value)),Ds=(e,t)=>(e.boards??[]).flatMap(o=>o.swimlanes??[]).flatMap(o=>o.issues??[]).find(o=>o.id===t),Wn=(e,t)=>{let o=Ds(e,t);return{issueId:t,description:o?.description??"",comments:e.commentsByIssueId?.[t]??[]}},Os=280,Vn=(e,t)=>({issueId:e,excerpt:kn(t,Os)});var Us=1e3,Kn=e=>{let t=oe(e.repoRoot);if(h(t))return null;let o=lt({repoRoot:t.value});return h(o)?null:o.value},Yn=e=>{let t=()=>{let r=Kn(e.project);return r===null?null:$e(r)},o=()=>{let r=or(e.project.repoRoot);return h(r)?null:JSON.stringify([r.value.live,r.value.overLimit])},n=o(),s=t();return{publishIfLogMoved:async()=>{let r=Kn(e.project);if(r===null||await gt(r))return;let f=$e(r);if(f===s)return;s=f;let y=be(await ee({repoRoot:e.project.repoRoot}));if(h(y))return;ue({type:"state",payload:y});let p=o();p!==null&&p!==n&&(n=p,ue({type:"repos:changed"}))}}},qn=(e,t=Us)=>Bt(()=>pe(async()=>{ie().mode==="live"&&await e.publishIfLogMoved()}),t);var Gs=new Set(["127.0.0.1","[::1]","localhost","epiq.localhost"]),po=(e,t)=>{if(!e)return!1;if(e==="null")return!0;let o;try{o=new URL(e)}catch{return!0}return o.protocol!=="http:"||o.port!==String(t)?!0:!Gs.has(o.hostname)},Jn=(e,t)=>e.method==="GET"||e.method==="HEAD"?null:po(e.origin,t)?{status:403,message:"Cross-origin request"}:e.method==="POST"&&!(e.contentType??"").toLowerCase().startsWith("application/json")?{status:415,message:"Expected content-type: application/json"}:null;import{WebSocketServer as sa}from"ws";var Fs=new RegExp(`^[0-9A-Z]{${7}}$`),Hs=e=>{let t=e.indexOf(" ");if(t===-1)return null;let o=e.slice(0,t).toUpperCase();return Fs.test(o)?o:null},ks=e=>{let t={};for(let o of e){let n=Hs(o.subject),s=new Set([...n?[n]:[],...o.refs??[]]);for(let u of s)(t[u]??=[]).push({time:o.time,insertions:o.insertions,deletions:o.deletions})}return t},Xn=async(e={})=>{let t=await yt({repoRoot:e.repoRoot});return h(t)?t:T("Collected commits by ref",ks(t.value))};var Ws="Filed here",zn=(e,t)=>e.set(t,(e.get(t)??0)+1),Qn=(e,t,o)=>[...e.entries()].map(([n,s])=>({laneId:n,title:n===null?Ws:o(n),count:s,share:t===0?0:s/t})).sort((n,s)=>s.count-n.count||n.title.localeCompare(s.title)),Zn=(e,t,o)=>{let n=new Map,s=new Map,u=0,r=0;for(let f of t)for(let[y,p]of f.entries()){if(p!==e)continue;u++,zn(n,f[y-1]??null);let g=f[y+1];g!==void 0&&(r++,zn(s,g))}return{arrived:u,departed:r,arrivesFrom:Qn(n,u,o),movesOnTo:Qn(s,r,o)}};var Ve=1440*60*1e3,Vs=({laneIds:e,journeys:t,now:o,days:n})=>{let s=o-(n-1)*Ve,u=new Map(e.map(r=>[r,Array.from({length:n},()=>[])]));for(let r of t)for(let[f,y]of r.entries()){let p=u.get(y.laneId);if(!p)continue;let g=r[f+1]?.enteredAt,l=Math.max(0,Math.ceil((y.enteredAt-s)/Ve)),d=g===void 0?n-1:Math.min(n-1,Math.ceil((g-s)/Ve)-1);for(let a=l;a<=d;a++)p[a].push(s+a*Ve-y.enteredAt)}return Object.fromEntries([...u].map(([r,f])=>[r,f.map((y,p)=>({t:s+p*Ve,median:Ln(y.sort((g,l)=>g-l)),count:y.length}))]))},ei=({laneId:e,journeys:t,now:o,days:n})=>Vs({laneIds:[e],journeys:t,now:o,days:n})[e];var Ks=40,Ys=30,qs=()=>({tickets:0,commits:0,insertions:0,deletions:0}),Js=async(e,t)=>{let o=qs();for(let n of t.slice(0,Ks)){let s=await Ct({repoRoot:e,idOrRef:de(n)});h(s)||s.value.shape.commits===0||(o.tickets++,o.commits+=s.value.shape.commits,o.insertions+=s.value.shape.insertions,o.deletions+=s.value.shape.deletions)}return o},ti=async e=>{let t=kr();if(h(t))return t;let{nodes:o}=t.value;if(!o[e.swimlaneId])return G("Swimlane not found");let s=Object.values(o).filter(ct),u=s.map(y=>Dr(y.log??[],ro(y.id))),r=Zn(e.swimlaneId,u.map(y=>y.map(p=>p.laneId)),y=>o[y]?.title??"Elsewhere"),f=s.filter(y=>y.parentNodeId===e.swimlaneId).map(y=>y.id);return T("Derived swimlane stats",{swimlaneId:e.swimlaneId,createdAt:ro(e.swimlaneId),...r,stayTrend:ei({laneId:e.swimlaneId,journeys:u,now:Date.now(),days:Ys}),code:await Js(e.repoRoot,f)})};var oi=new Set(["sync","email:link","email:unlink","repo:connect","repo:disconnect","issues:create","board:create","board:edit:title","swimlane:create","swimlane:edit:title","board:edit:description","swimlane:edit:description","swimlane:rule:set","goal:edit:description","swimlane:delete","swimlane:move","issues:move","issue:close","issue:reopen","issue:edit:title","issue:edit:description","issue:tag:add","issue:tag:remove","issue:goal:set","goal:create","goal:rename","goal:remove","contributor:remove","tag:remove","issue:assignee:add","issue:assignee:remove","issue:comment:add","issue:comment:delete"]);var ri=e=>{let t=Ge({exclude:e});return h(t)?[]:t.value.map(o=>({projectId:o.projectId,name:dt(o.root),root:o.root,lastOpenedAt:o.lastOpenedAt}))},ni=e=>{let t=Ge();if(h(t))return G(t.message);let o=t.value.find(n=>n.root===e);return o?T("Resolved recent project",o.root):G(`Not a recent project: ${e}`)};import{z as c}from"zod";var v=c.string().min(1),ii=c.discriminatedUnion("at",[c.object({at:c.literal("start")}),c.object({at:c.literal("end")}),c.object({at:c.literal("before"),sibling:v}),c.object({at:c.literal("after"),sibling:v})]),ae=c.number().finite(),w=(e,t)=>c.object({type:c.literal(e),payload:t}),le=e=>c.object({type:c.literal(e)}),Xs=c.discriminatedUnion("type",[le("state:get"),le("issues:list"),le("sync"),le("time-travel:live"),le("diff-stats:get"),w("project:open",c.object({root:c.string().min(1)})),w("issues:create",c.object({title:c.string(),parentId:v,description:c.string().optional(),tagNames:c.array(c.string()).optional()})),w("board:create",c.object({title:c.string()})),w("board:edit:title",c.object({boardId:v,title:c.string()})),w("swimlane:create",c.object({title:c.string(),boardId:v})),w("swimlane:edit:title",c.object({swimlaneId:v,title:c.string()})),w("board:edit:description",c.object({boardId:v,description:c.string()})),w("swimlane:edit:description",c.object({swimlaneId:v,description:c.string()})),w("swimlane:rule:set",c.object({swimlaneId:v,rule:c.string().min(1).max(64),on:c.boolean()})),w("goal:edit:description",c.object({goalId:v,description:c.string()})),w("swimlane:delete",c.object({swimlaneId:v})),w("swimlane:move",c.object({swimlaneId:v,boardId:v,position:ii.optional()})),w("issues:move",c.object({issueId:v,parentId:v,position:ii.optional()})),w("issue:edit:title",c.object({issueId:v,title:c.string()})),w("issue:edit:description",c.object({issueId:v,description:c.string()})),w("issue:tag:add",c.object({issueId:v,tagName:c.string()})),w("issue:goal:set",c.object({issueId:v,goal:v.nullable()})),w("goal:create",c.object({name:c.string(),issueId:v.optional()})),w("goal:rename",c.object({goalId:v,name:c.string()})),w("goal:remove",c.object({goalId:v})),w("issue:tag:remove",c.object({issueId:v,tagId:v})),w("contributor:remove",c.object({contributorId:v})),w("tag:remove",c.object({tagId:v})),c.object({type:c.literal("contributors:get"),payload:c.object({boardId:v.optional()}).optional()}),w("issue:assignee:add",c.object({issueId:v,assigneeId:v.optional(),assigneeName:c.string().optional(),createUnlinked:c.boolean().optional()})),w("issue:assignee:remove",c.object({issueId:v,assigneeId:v})),w("issue:close",c.object({issueId:v})),w("issue:reopen",c.object({issueId:v})),w("issue:comment:add",c.object({issueId:v,body:c.string()})),w("issue:comment:delete",c.object({issueId:v,commentId:v})),w("issue:comment:edit",c.object({issueId:v,commentId:v,body:c.string()})),w("issue:get",c.object({issueId:v})),w("issue:preview:get",c.object({issueId:v})),c.object({type:c.literal("timeline:get"),payload:c.object({start:ae.optional(),end:ae.optional(),boardId:v.optional(),requestId:c.number().finite().optional()}).optional()}),c.object({type:c.literal("commits:get"),payload:c.object({start:ae.optional(),end:ae.optional(),requestId:c.number().finite().optional()}).optional()}),w("time-travel:scrub",c.object({targetTime:ae})),w("time-travel:checkout-event",c.object({eventId:c.string().min(1)})),w("commit:inspect",c.object({sha:c.string(),repo:c.string().max(80).optional()})),le("repos:get"),w("repo:preview",c.object({url:c.string().min(1).max(mt),branches:c.enum(["default","all"]).optional(),since:c.string().max(20).optional(),label:c.string().max(24).optional()})),w("repo:preview:cancel",c.union([c.object({repo:c.string().min(1).max(80)}),c.object({url:c.string().min(1).max(mt)})])),w("repo:connect",c.object({url:c.string().min(1).max(mt),branches:c.enum(["default","all"]).optional(),since:c.string().max(20).optional(),label:c.string().max(24).optional()})),w("repo:disconnect",c.object({repo:c.string().min(1).max(2e3)})),c.object({type:c.literal("emails:get")}),w("email:link",c.object({email:c.string().min(1).max(254),contributorId:c.string().min(1).optional()})),w("email:unlink",c.object({email:c.string().min(1).max(254),contributorId:c.string().min(1).optional()})),w("commit:diff:get",c.object({sha:c.string(),repo:c.string().max(80).optional()})),w("issue:commits:get",c.object({issueId:v})),w("issue:squashed-diff:get",c.object({issueId:v,asOfTime:ae.optional()})),w("issue:stats:get",c.object({issueId:v,asOfTime:ae.optional()})),w("swimlane:stats:get",c.object({swimlaneId:v})),w("goal:stats:get",c.object({goalId:v,key:c.string().max(200),asOfTime:ae.optional()})),w("goal:commits:get",c.object({goalId:v,key:c.string().max(200),asOfTime:ae.optional()})),w("board:overview:get",c.object({boardId:v})),le("me:stats:get"),le("settings:get"),le("version:get"),w("settings:set",c.object({autoSync:c.boolean().optional(),autoSyncIntervalMs:c.number().finite().optional()}))]);var si=e=>{let t=Xs.safeParse(e);return t.success?{ok:!0,message:t.data}:{ok:!1,error:`Invalid message: ${t.error.issues.map(n=>`${n.path.join(".")||"<root>"}: ${n.message}`).join(", ")}`}};var zs="https://registry.npmjs.org/epiq/latest",Qs="https://api.github.com/repos/ljtn/epiq/releases?per_page=30",Zs="https://raw.githubusercontent.com/ljtn/epiq/main/install.sh";var ai=new Map,fo=new Map;var yo=/^v?\d+\.\d+\.\d+$/,go=e=>e.replace(/^v/,""),Ne=(e,t)=>{let o=go(e).split(".").map(Number),n=go(t).split(".").map(Number);for(let s=0;s<Math.max(o.length,n.length);s++){let u=o[s]??0,r=n[s]??0;if(u>r)return 1;if(u<r)return-1}return 0},ea=()=>process.env.IS_CI==="true"||process.env.EPIQ_NO_UPDATE_CHECK==="1",ta=async e=>{try{let t=await fetch(e,{signal:AbortSignal.timeout(5e3),headers:{accept:"application/json"}});return t.ok?await t.json():null}catch{return null}},ci=(e,t=()=>!0)=>{let o=ai.get(e);if(o&&Date.now()-o.at<o.ttl)return Promise.resolve(o.body);let n=fo.get(e);if(n)return n;let s=ta(e).then(u=>(ai.set(e,{at:Date.now(),ttl:u!==null&&t(u)?864e5:36e5,body:u}),fo.delete(e),u));return fo.set(e,s),s},ho=async e=>{if(ea())return{current:e,latest:null,updateAvailable:!1};let t=await ci(zs),o=typeof t?.version=="string"&&yo.test(t.version)?t.version:null;return{current:e,latest:o,updateAvailable:o?Ne(o,e)>0:!1}},oa=e=>{let t=[],o=null;for(let n of e.replace(/\r/g,"").split(`
4
+ `)){let s=n.trimEnd();if(s.trim())if(/^[-*] /.test(s.trimStart())&&!/^\s{2,}/.test(s))o||(o={title:null,items:[]},t.push(o)),o.items.push(s.trimStart().slice(2).trim());else if(/^\s+/.test(s)&&o?.items.length)o.items[o.items.length-1]+=` ${s.trim()}`;else{if(yo.test(s.trim())&&t.length===0)continue;o={title:s.replace(/^#+\s*/,"").trim(),items:[]},t.push(o)}}return t.filter(n=>n.items.length>0)},ra=e=>{let t=e;return typeof t?.tag_name!="string"||!yo.test(t.tag_name)||t.draft||t.prerelease?null:{version:go(t.tag_name),url:typeof t.html_url=="string"?t.html_url:"",publishedAt:typeof t.published_at=="string"&&!Number.isNaN(Date.parse(t.published_at))?t.published_at:null,sections:typeof t.body=="string"?oa(t.body):[]}},li=e=>Array.isArray(e)?e.map(ra).filter(t=>!!t):[],na=async e=>li(await ci(Qs,t=>li(t).some(o=>Ne(o.version,e)===0))),ia=(e,t,o)=>e.filter(n=>Ne(n.version,t)>0&&Ne(n.version,o)<=0).sort((n,s)=>Ne(s.version,n.version)),mi={script:`curl -fsSL ${Zs} | sh`,npm:"npm install --global epiq@latest"},di=async e=>{let t=await ho(e);if(!t.updateAvailable||!t.latest)return{...t,releases:[],currentPublishedAt:null,commands:mi};let o=await na(t.latest);return{...t,releases:ia(o,e,t.latest),currentPublishedAt:o.find(n=>Ne(n.version,e)===0)?.publishedAt??null,commands:mi}};var aa=1024*1024,bo=()=>{ue({type:"state",payload:be(Tt())})},ui=()=>{ue({type:"repos:changed"})},xo=async(e,t)=>{la(await Bn({repoRoot:e,minIntervalMs:t}))},la=e=>{h(e)||(e.value.some(t=>t.changed)&&ui(),e.value.some(t=>t.changed||!t.ok)&&ue({type:"repos:fetched"}))},S=(e,t)=>{e.send(JSON.stringify(t))},Ke=async(e,t)=>{let o=be(await ee({repoRoot:t}));return h(o)&&o.message===Do?S(e,{type:"state:unavailable",payload:{message:o.message,repoRoot:t,recentProjects:ri(t)}}):S(e,{type:"state",payload:o})},ma=async(e,t)=>{let o=()=>S(e,{type:"state",payload:be(Tt())});if(ie().mode!=="live")return o();let n=await ee({repoRoot:t});return ie().mode!=="live"?o():S(e,{type:"state",payload:be(n)})},E=async(e,t,o,n,s)=>{if(S(e,{type:n,payload:s}),h(s))return S(e,{type:"failed",payload:s.message});o(),ma(e,t)},pi=(e,t,{onStateChanged:o,onSyncSettingsChanged:n,getPort:s})=>{new sa({server:e,path:"/ws",maxPayload:aa,verifyClient:r=>!po(r.origin,s())}).on("connection",r=>{fr(r),r.on("message",async f=>{let y=async l=>{let{type:d}=l,a=t.repoRoot;if(d==="project:open"){let i=ni(l.payload.root);return S(r,{type:"project:open:result",payload:i}),h(i)?void 0:(t.repoRoot=i.value,Ke(r,i.value))}if(d==="timeline:get"){let{requestId:i,...x}=l.payload??{};return S(r,{type:"timeline",requestId:i,payload:await Or({repoRoot:a,...x})})}if(d==="issue:get"){let i=l.payload?.issueId,x=Tt(),L=ln(i);return S(r,{type:"issue",payload:h(x)?x:T("Issue detail",{...Wn(x.value,i),history:h(L)?[]:L.value})})}if(d==="issue:preview:get"){let{issueId:i}=l.payload,x=tn(i);return S(r,{type:"issue:preview:result",payload:{issueId:i,result:h(x)?x:T("Issue preview",Vn(i,x.value))}})}if(d==="commits:get"){let{requestId:i,...x}=l.payload??{};return S(r,{type:"commits",requestId:i,payload:io(await yt({repoRoot:a,...x}))})}if(d==="emails:get")return S(r,{type:"emails",payload:await so({repoRoot:a}),suggestions:await ao({repoRoot:a})});if(d==="email:link"||d==="email:unlink"){let x=await(d==="email:link"?Pn:An)({repoRoot:a,...l.payload});return S(r,{type:"emails",payload:await so({repoRoot:a}),suggestions:await ao({repoRoot:a}),lastAction:h(x)?{ok:!1,message:x.message}:{ok:!0,message:x.message}}),E(r,a,o,`${d}:result`,x)}if(d==="me:stats:get")return S(r,{type:"me:stats",payload:await Nn({repoRoot:a})});if(d==="version:get")return S(r,{type:"version",payload:await di(F)});if(d==="settings:get")return S(r,{type:"settings",payload:no()});if(d==="settings:set"){let i=Nr({enabled:l.payload.autoSync,intervalMs:l.payload.autoSyncIntervalMs});return h(i)||n(),S(r,{type:"settings",payload:h(i)?no():i,lastAction:h(i)?{ok:!1,message:i.message}:{ok:!0,message:i.message}})}if(d==="commit:inspect")return S(r,{type:"commit:inspect:result",payload:await lr({repoRoot:a,sha:l.payload.sha,repo:l.payload.repo})});if(d==="commit:diff:get"){let{sha:i,repo:x}=l.payload;return S(r,{type:"commit:diff:result",payload:{sha:i,repo:x,result:await sr({repoRoot:a,sha:i,repo:x})}})}if(d==="repos:get"){let i=await nr(a);return S(r,{type:"repos",payload:await Ae({repoRoot:a}),own:i})}if(d==="repo:preview"){let i=await lo({repoRoot:a,...l.payload,previewOnly:!0});return S(r,{type:"repos",for:d,url:l.payload.url.trim(),payload:h(i)?await Ae({repoRoot:a}):i,preview:h(i)?null:i.value.preview??null,lastAction:{ok:!h(i),message:i.message}})}if(d==="repo:preview:cancel")return Rn(l.payload),S(r,{type:"repos",for:d,payload:await Ae({repoRoot:a}),preview:null});if(d==="repo:connect"||d==="repo:disconnect"){let i=d==="repo:connect"?await lo({repoRoot:a,...l.payload,confirm:!0}):await Mn({repoRoot:a,...l.payload});return S(r,{type:"repos",for:d,payload:h(i)?await Ae({repoRoot:a}):i,preview:null,lastAction:{ok:!h(i),message:i.message}}),h(i)?S(r,{type:`${d}:result`,payload:i}):(!h(i)&&i.message!==er&&!i.message.startsWith(tr)&&ui(),E(r,a,o,`${d}:result`,i))}if(d==="issue:commits:get"){let{issueId:i}=l.payload;return S(r,{type:"issue:commits:result",payload:{issueId:i,result:await ir(a,io(await rr({repoRoot:a,ref:de(i)})))}})}if(d==="issue:squashed-diff:get"){let{issueId:i,asOfTime:x}=l.payload;return S(r,{type:"issue:squashed-diff:result",payload:{issueId:i,asOfTime:x??null,result:await ar({repoRoot:a,ref:de(i),end:x})}})}if(d==="issue:stats:get"){let{issueId:i,asOfTime:x}=l.payload;return S(r,{type:"issue:stats:result",payload:{issueId:i,asOfTime:x??null,result:await Ct({repoRoot:a,idOrRef:de(i),end:x})}})}if(d==="diff-stats:get")return S(r,{type:"diff-stats",payload:await Xn({repoRoot:a})});if(d==="swimlane:stats:get"){let{swimlaneId:i}=l.payload;return S(r,{type:"swimlane:stats:result",payload:{swimlaneId:i,result:await ti({repoRoot:a,swimlaneId:i})}})}if(d==="goal:stats:get"){let{goalId:i,key:x,asOfTime:L}=l.payload;return S(r,{type:"goal:stats:result",payload:{goalId:i,key:x,result:await hn({repoRoot:a,goal:i,end:L})}})}if(d==="goal:commits:get"){let{goalId:i,key:x,asOfTime:L}=l.payload;return S(r,{type:"goal:commits:result",payload:{goalId:i,key:x,result:await bn({repoRoot:a,goal:i,end:L})}})}if(d==="board:overview:get"){let{boardId:i}=l.payload;return S(r,{type:"board:overview:result",payload:{boardId:i,result:jn({boardId:i})}})}if(d==="time-travel:scrub"){let i=await Ur({repoRoot:a,targetTime:l.payload.targetTime});return S(r,{type:"time-travel:result",payload:i}),h(i)?void 0:bo()}if(d==="time-travel:checkout-event"){let i=await Gr({repoRoot:a,eventId:l.payload.eventId});return S(r,{type:"time-travel:result",payload:i}),h(i)?void 0:bo()}if(d==="time-travel:live"){let i=await $r({repoRoot:a});return S(r,{type:"time-travel:result",payload:i}),h(i)?void 0:bo()}if(d==="state:get")return Ke(r,a);if(d==="sync"){let i=await Et({repoRoot:a});return S(r,{type:"sync:result",payload:i}),o(),h(i)||xo(a),Ke(r,a)}if(d==="issue:comment:add"){let i=await Pt({repoRoot:a,...l.payload});return E(r,a,o,"issue:comment:add:result",i)}if(d==="issue:comment:edit"){let i=await Cn({repoRoot:a,...l.payload});return E(r,a,o,"issue:comment:edit:result",i)}if(d==="issue:comment:delete"){let i=await At({repoRoot:a,...l.payload});return S(r,{type:"issue:comment:delete:result",payload:i}),h(i)?S(r,{type:"failed",payload:i.message}):(o(),Ke(r,a))}if(d==="issue:edit:description"){let i=await mn({repoRoot:a,...l.payload});return E(r,a,o,"issue:edit:description:result",i)}if(d==="issue:edit:title"){let i=await cn({repoRoot:a,...l.payload});return E(r,a,o,"issue:edit:title:result",i)}if(d==="issue:tag:add"){let i=await xn({repoRoot:a,...l.payload});return E(r,a,o,"issue:tag:add:result",i)}if(d==="issue:goal:set")return E(r,a,o,"issue:goal:set:result",await Yr({repoRoot:a,...l.payload}));if(d==="goal:create")return E(r,a,o,"goal:create:result",await qr({repoRoot:a,...l.payload}));if(d==="goal:rename")return E(r,a,o,"goal:rename:result",await Jr({repoRoot:a,...l.payload}));if(d==="goal:remove")return E(r,a,o,"goal:remove:result",await Xr({repoRoot:a,...l.payload}));if(d==="issue:tag:remove"){let i=await vn({repoRoot:a,...l.payload});return E(r,a,o,"issue:tag:remove:result",i)}if(d==="contributor:remove"){let i=await In({repoRoot:a,...l.payload});return E(r,a,o,"contributor:remove:result",i)}if(d==="tag:remove"){let i=await wn({repoRoot:a,...l.payload});return E(r,a,o,"tag:remove:result",i)}if(d==="contributors:get")return S(r,{type:"contributors",boardId:l.payload?.boardId,payload:await Tn({repoRoot:a,...l.payload})});if(d==="issue:assignee:add"){let i=await Sn({repoRoot:a,...l.payload});return E(r,a,o,"issue:assignee:add:result",i)}if(d==="issue:assignee:remove"){let i=await En({repoRoot:a,...l.payload});return E(r,a,o,"issue:assignee:remove:result",i)}if(d==="issues:list")return S(r,{type:"issues",payload:await on({repoRoot:a})});if(d==="issues:create"){let i=await rn({...l.payload,repoRoot:a});return S(r,{type:"issues:create:result",payload:i}),h(i)?ue({type:"failed",payload:i.message}):(o(),Ke(r,a))}if(d==="board:create"){let i=await dn({...l.payload,repoRoot:a});return E(r,a,o,"board:create:result",i)}if(d==="board:edit:title"){let i=await un({...l.payload,repoRoot:a});return E(r,a,o,"board:edit:title:result",i)}if(d==="swimlane:create"){let i=await pn({...l.payload,repoRoot:a});return E(r,a,o,"swimlane:create:result",i)}if(d==="swimlane:edit:title"){let i=await fn({...l.payload,repoRoot:a});return E(r,a,o,"swimlane:edit:title:result",i)}if(d==="board:edit:description"){let i=await Wr({...l.payload,repoRoot:a});return E(r,a,o,"board:edit:description:result",i)}if(d==="swimlane:edit:description"){let i=await Vr({...l.payload,repoRoot:a});return E(r,a,o,"swimlane:edit:description:result",i)}if(d==="swimlane:rule:set"){let i=await zr({...l.payload,repoRoot:a});return E(r,a,o,"swimlane:rule:set:result",i)}if(d==="goal:edit:description"){let i=await Kr({repoRoot:a,goal:l.payload.goalId,description:l.payload.description});return E(r,a,o,"goal:edit:description:result",i)}if(d==="swimlane:delete"){let i=await yn({...l.payload,repoRoot:a});return E(r,a,o,"swimlane:delete:result",i)}if(d==="swimlane:move"){if(!l.payload.position)return S(r,{type:"error",message:"Missing move position"});let i=await gn({...l.payload,repoRoot:a});return E(r,a,o,"swimlane:move:result",i)}if(d==="issues:move"){if(!l.payload.position)return S(r,{type:"error",message:"Missing move position"});let i=await an({...l.payload,repoRoot:a});return E(r,a,o,"issues:move:result",i)}if(d==="issue:close"){let i=await nn({repoRoot:a,issueId:l.payload.issueId});return E(r,a,o,"issue:close:result",i)}if(d==="issue:reopen"){let i=await sn({repoRoot:a,issueId:l.payload.issueId});return E(r,a,o,"issue:reopen:result",i)}return S(r,{type:"error",message:"Unknown message type"})},p,g=async l=>{if(p!=="repo:connect"&&p!=="repo:disconnect"&&p!=="repo:preview")return S(r,{type:"error",message:l});S(r,{type:"repos",for:p,payload:await Ae({repoRoot:t.repoRoot}),preview:null,lastAction:{ok:!1,message:l}}),p!=="repo:preview"&&S(r,{type:`${p}:result`,payload:G(l)})};try{let l=JSON.parse(f.toString());p=l?.type;let d=si(l);if(!d.ok)return await g(d.error);let a=d.message;return oi.has(a.type)?await pe(async()=>ie().mode!=="live"?S(r,{type:"failed",payload:"Read-only while viewing history"}):y(a)):await y(a)}catch(l){return g(l instanceof Error?l.message:String(l))}})})};var fa=xe.dirname(pa(import.meta.url)),ga=process.env.IS_LOCAL==="true"?xe.resolve(process.cwd(),"dist/gui"):xe.join(fa,"gui"),Lt,ya=async()=>(Lt===void 0&&(Lt=await import("node:sea").catch(()=>null)),Lt?.isSea()?Lt:null),R=(e,t,o)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(o))},ha=e=>R(e,409,{isError:!0,message:"Read-only while viewing history"}),jt=(e,t)=>pe(async()=>ie().mode!=="live"?ha(e):t()),fi=async(e,t=1024*1024)=>new Promise((o,n)=>{let s=[],u=0;e.on("data",r=>{if(u+=r.length,u>t){e.destroy(),n(new Error("Request body too large"));return}s.push(r)}),e.on("end",()=>{let r=Buffer.concat(s).toString("utf8");try{o(r?JSON.parse(r):{})}catch{n(new Error("Invalid JSON body"))}}),e.on("error",n)}),ba=2*1024*1024,xa={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},wa=e=>e.endsWith(".html")?"text/html; charset=utf-8":e.endsWith(".js")?"text/javascript; charset=utf-8":e.endsWith(".css")?"text/css; charset=utf-8":e.endsWith(".json")?"application/json; charset=utf-8":e.endsWith(".ico")?"image/x-icon":e.endsWith(".woff2")?"font/woff2":"application/octet-stream",gi=new Map,va=e=>`"${da("sha1").update(e).digest("base64url")}"`,Sa=async e=>{try{let{size:t,mtimeMs:o}=await ca(e);return`${t}:${o}`}catch{return null}},Ia=e=>{try{return decodeURIComponent(e)}catch{return null}},yi=async(e,t,o)=>{let n=e==="/"?"/index.html":Ia(e);if(n===null)return R(o,404,{isError:!0,message:"Not found"});let s=n.replace(/^\/+/,""),u=xe.resolve(ga),r=xe.resolve(u,s),f=xe.relative(u,r);if(f.startsWith("..")||xe.isAbsolute(f))return R(o,403,{isError:!0,message:"Forbidden"});let y=await ya(),p=y?"sea":await Sa(r),g=p===null?void 0:gi.get(f),l=g&&g.stamp===p?g.etag:null;if(l&&t.headers["if-none-match"]===l)return o.writeHead(304,{etag:l,"cache-control":"no-cache"}),o.end();try{let d=y?Buffer.from(y.getAsset(`gui/${f}`)):await hi(r),a=l??va(d);return p!==null&&gi.set(f,{stamp:p,etag:a}),o.writeHead(200,{"content-type":wa(r),etag:a,"cache-control":"no-cache"}),o.end(d)}catch{return R(o,404,{isError:!0,message:`Not found: ${s}`})}},Ta=async(e,t=We)=>new Promise((o,n)=>{let s=u=>{let r=y=>{if(e.off("listening",f),y.code==="EADDRINUSE"&&u===t){e.removeListener("error",r),s(0);return}n(y)},f=()=>{e.off("error",r);let y=e.address();if(!y||typeof y=="string"){n(new Error("Unable to resolve address"));return}o(y.port)};e.once("error",r),e.once("listening",f),e.listen(u,"127.0.0.1")};s(t)}),bi=async e=>{_r(!1);let t=0,o={repoRoot:e.repoRoot},n=ua.createServer((p,g)=>{s(p,g).catch(l=>(logger.error(`[gui] ${p.method} ${p.url}: ${l instanceof Error?l.message:String(l)}`),g.headersSent?g.end():R(g,500,{isError:!0,message:"Internal error"})))});async function s(p,g){let l=new URL(p.url??"/","http://127.0.0.1"),d=Jn({method:p.method,origin:p.headers.origin,contentType:p.headers["content-type"]},t);if(d)return R(g,d.status,{isError:!0,message:d.message});if(p.method==="GET"&&l.pathname===co)return R(g,200,{app:uo,repoRoot:Rt(o.repoRoot),version:F,pid:process.pid});if(l.pathname==="/api/state")return R(g,200,await ee({repoRoot:o.repoRoot}));if(p.method==="POST"&&l.pathname==="/api/comments")try{let a=await fi(p);if(!a.issueId||!a.body?.trim())return R(g,400,{isError:!0,message:"Missing issueId or body"});let i=a.issueId,x=a.body;return await jt(g,async()=>{let L=await Pt({repoRoot:o.repoRoot,issueId:i,body:x});return h(L)?R(g,400,{isError:!0,message:L.message}):R(g,200,await ee({repoRoot:o.repoRoot}))})}catch(a){return R(g,400,{isError:!0,message:a instanceof Error?a.message:"Unable to add comment"})}if(p.method==="POST"&&l.pathname==="/api/attachments")try{let a=await fi(p,ba);if(!a.issueId||!a.dataBase64)return R(g,400,{isError:!0,message:"Missing issueId or dataBase64"});let i=a.issueId,x=a.dataBase64,L=a.name??"";return await jt(g,async()=>{let D=await Qr({repoRoot:o.repoRoot,issueId:i,name:L,dataBase64:x});return h(D)?R(g,400,{isError:!0,message:D.message}):R(g,200,{...await ee({repoRoot:o.repoRoot}),attachment:D.value})})}catch(a){return R(g,400,{isError:!0,message:a instanceof Error?a.message:"Unable to add attachment"})}if(p.method==="DELETE"&&l.pathname.startsWith("/api/attachments/")){let a=decodeURIComponent(l.pathname.replace("/api/attachments/",""));return a?jt(g,async()=>{let i=await Zr({repoRoot:o.repoRoot,attachmentId:a});return h(i)?R(g,400,{isError:!0,message:i.message}):R(g,200,await ee({repoRoot:o.repoRoot}))}):R(g,400,{isError:!0,message:"Missing attachment id"})}if(p.method==="GET"&&l.pathname.startsWith("/media/")){let a=decodeURIComponent(l.pathname.replace("/media/","")),i=await en({repoRoot:o.repoRoot,fileName:a});if(h(i))return R(g,404,{isError:!0,message:i.message});try{let x=await hi(i.value.filePath);return g.writeHead(200,{"content-type":xa[i.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),g.end(x)}catch{return R(g,404,{isError:!0,message:"Attachment blob not found"})}}if(p.method==="DELETE"&&l.pathname.startsWith("/api/comments/")){let a=decodeURIComponent(l.pathname.replace("/api/comments/",""));return a?jt(g,async()=>{let i=await At({repoRoot:o.repoRoot,commentId:a});return h(i)?R(g,400,{isError:!0,message:i.message}):R(g,200,await ee({repoRoot:o.repoRoot}))}):R(g,400,{isError:!0,message:"Missing comment id"})}return l.pathname.startsWith("/board/")||l.pathname==="/log"?yi("/",p,g):yi(l.pathname,p,g)}try{t=await Ta(n)}catch(p){return G(p instanceof Error?`Unable to start GUI server: ${p.message}`:`Unable to start GUI server: ${String(p)}`)}let u=Yn({project:o}),r=Hn({project:o,publisher:u,onReposFetch:p=>xo(o.repoRoot,p)}),f=qn(u);pi(n,o,{onStateChanged:()=>r.queueSync(),onSyncSettingsChanged:()=>r.reschedule(),getPort:()=>t}),n.on("close",()=>{r.dispose(),f()});let y=n.address();return!y||typeof y=="string"?(n.close(),G("Unable to resolve GUI server address")):T("Started GUI server",{url:`http://epiq.localhost:${y.port}${e.boardId?`/board/${e.boardId}`:""}`,server:n})};var xi=async e=>{let t=f=>{e.open!==!1&&Un()&&Gn(f)},o=it({});if(h(o))return G(o.message);let n=Ie();$(n)&&Ue(n.value);let s=await Fn(We);if(s&&s.repoRoot===Rt(e.repoRoot)){let f=`http://127.0.0.1:${We}`;return console.log(mo({url:f,repoRoot:e.repoRoot,version:F,reused:!0})),t(f),T("Reused running GUI",{url:f})}let u=await bi({repoRoot:e.repoRoot,boardId:""});if(h(u))return u;let{url:r}=u.value;return console.log(mo({url:r,repoRoot:e.repoRoot,version:F,reused:!1})),t(r),T("Started GUI",{url:r})};import{Box as ce}from"ink";import M from"react";import{Box as wo,Text as Ye}from"ink";import te,{useEffect as Ea,useMemo as Ca}from"react";import{ulid as Pa}from"ulid";var wi=({text:e,match:t,color:o,highlightColor:n=m.secondary,dimColor:s=!1})=>{if(!t)return te.createElement(Ye,{color:o,dimColor:s},e);let u=e.toLowerCase(),r=t.toLowerCase(),f=u.indexOf(r);return f===-1?te.createElement(Ye,{color:o,dimColor:s},e):te.createElement(Ye,{color:o,dimColor:s},e.slice(0,f),te.createElement(Ye,{backgroundColor:n,bold:!0},e.slice(f,f+t.length)),e.slice(f+t.length))},vi=Pa(),Aa=e=>`${e}`,Na=e=>{let{pendingNavTarget:t}=Sr();if(!t)return[];let{breadCrumb:o,contextNode:n,selectedNode:s}=t,u=new Set(Qo(ft.NONE,{breadCrumb:o,contextNode:n,readOnly:Q().readOnly,selectedNode:s}));return[...new Set(Object.values(ft))].filter(r=>r!=="move").filter(r=>r.length>0).filter(r=>r!==ft.PALETTE).map(r=>{let f=hr(r),y=Mr.find(p=>p.intent===f);return{command:r,description:y?.description??`[${r}] Run command`,isAvailable:u.has(r)}}).filter(r=>r.command.toLowerCase().startsWith(e)||e.length>=2&&r.description.toLowerCase().includes(e)).sort((r,f)=>r.isAvailable!==f.isAvailable?r.isAvailable?-1:1:r.command.localeCompare(f.command))},Ma=e=>Ee.text({id:vi,parentNodeId:e,rank:"000000",name:"Command Palette",readonly:!0,isVirtual:!0}),Ra=(e,t,o)=>Ee.text({id:Aa(e.command),parentNodeId:o,rank:String(t).padStart(6,"0"),name:e.command,disabled:!e.isAvailable,readonly:!0,isVirtual:!0}),vo=[],Ba=e=>{Si();let t=q.createNode(Ma(Q().rootNodeId));h(t)||!Te(t.value)||(vo=[t.value,...e.map((o,n)=>Ra(o,n,vi)).map(q.createNode).filter($).map(({value:o})=>o).filter(Te)],Ce.navigate({contextNode:t.value,selectedIndex:0}))},Si=()=>{let e=vo.map(t=>t.id);vo=[];for(let t of e)q.deleteNode(t)};function Ii({width:e,height:t}){let n=ur().value.trim().toLowerCase(),s=Ca(()=>Na(n),[n]);Ea(()=>(Ba(s),()=>{Si()}),[s]);let u=Q().selectedIndex;return te.createElement(wo,{flexDirection:"column",width:e,height:t-2},te.createElement(wt,{height:t-4,itemHeight:3,selectedIndex:u},s.map((r,f)=>{let y=f===u,p=r.isAvailable?m.accent:m.secondary2,g=r.isAvailable?"":"[unavailable] ";return te.createElement(wo,{key:r.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:m.secondary,borderStyle:"single"},te.createElement(Ye,{color:p,dimColor:!r.isAvailable},y?"\u276F ":" ",te.createElement(wi,{text:zo(r.command),match:n,color:p,dimColor:!r.isAvailable})),te.createElement(wo,{paddingLeft:2},te.createElement(wi,{text:g+r.description,match:n.length>=2?n:"",color:y&&r.isAvailable?m.primary:m.secondary2,dimColor:!r.isAvailable})))})))}import{Box as Ya}from"ink";import Ot from"react";import Je from"chalk";import{Box as qe,Text as Pi}from"ink";import we,{useEffect as Ai,useMemo as La,useState as Ni}from"react";var Me=["\u2803","\u2806","\u2830","\u2818"],Ti=120,Ei=({isPalette:e,isPending:t,frame:o})=>{if(t){let n=(o%Me.length+Me.length)%Me.length;return Me[n]}return e?"?":":"},Ci=({infoMessage:e,isPending:t})=>t&&e.includes(cr)?"":e;var Mi=Je.hex(m.secondary),ja=Je.inverse,_a=Je.inverse.hex(m.secondary2),Da={hint:"",hints:[],overlap:0,remainder:""},Bi=({value:e,command:t})=>{if(!t)return null;let o=e.trimStart(),s=e.length-o.length;return e.slice(s,s+t.length)!==t?null:{start:s,end:s+t.length}},Oa=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let o=Go(t);return{bg:n=>Je.bgHex(o).black(n),bgCursor:n=>Je.bgHex(o).inverse.black(n)}}return oo(t)},Ua=({value:e,command:t,modifier:o})=>{if(!t||!o)return null;let n=Bi({value:e,command:t});if(!n)return null;let u=e.slice(n.end).match(/^\s*/)?.[0].length??0,r=n.end+u;return e.slice(r,r+o.length)!==o?null:{start:r,end:r+o.length}},Ri=()=>({value:ne.value,cursorPosition:ne.cursorPosition,commandIsPending:ne.commandIsPending,autoCompletion:ne.commandMeta.autoCompletion??Da,infoMessage:ne.commandMeta.infoMessage,validationStatus:ne.commandMeta.validity,command:ne.commandMeta.command,inputString:ne.commandMeta.inputString,modifier:ne.commandMeta.modifier}),Ga=(e,t)=>e.value===t.value&&e.cursorPosition===t.cursorPosition&&e.commandIsPending===t.commandIsPending&&e.infoMessage===t.infoMessage&&e.autoCompletion.hint===t.autoCompletion.hint&&e.autoCompletion.overlap===t.autoCompletion.overlap&&e.autoCompletion.remainder===t.autoCompletion.remainder&&e.validationStatus===t.validationStatus&&e.command===t.command&&e.modifier===t.modifier&&e.inputString===t.inputString,Li=({width:e,mode:t})=>{let[o,n]=Ni(Ri());Ai(()=>{let B=()=>{let C=Ri();n(I=>Ga(I,C)?I:C)},P=dr(B);return B(),()=>{P()}},[]);let{value:s,cursorPosition:u,infoMessage:r,commandIsPending:f,autoCompletion:y,command:p,modifier:g,validationStatus:l}=o,d=f&&l===mr.Invalid,a=Ci({infoMessage:r,isPending:f}),[i,x]=Ni(0);Ai(()=>{if(!f){x(0);return}let B=setInterval(()=>{x(P=>(P+1)%Me.length)},Ti);return()=>{clearInterval(B)}},[f]);let L=Ei({isPalette:t===H.PALETTE,isPending:f,frame:i}),D=La(()=>{let B=Math.max(0,Math.min(u,s.length)),P=Bi({value:s,command:p}),C=Ua({value:s,command:p,modifier:g}),I=p?oo(p):null,V=Oa({command:p,modifier:g}),Se=(K,Y)=>{let eo=P&&Y>=P.start&&Y<P.end,to=C&&Y>=C.start&&Y<C.end;return eo&&I?I.fg(K):to&&V?V.bg(K):K},De=(K,Y)=>{let eo=P&&Y>=P.start&&Y<P.end,to=C&&Y>=C.start&&Y<C.end;return eo&&I?I.fgCursor(K):to&&V?V.bgCursor(K):ja(K)},he=s.slice(0,B),Z=s[B]??" ",Oe=B<s.length?s.slice(B+1):"",nt=Array.from(he).map((K,Y)=>Se(K,Y)).join(""),Bo=De(Z,B),Lo=Array.from(Oe).map((K,Y)=>Se(K,B+1+Y)).join("");if(y.hint){let K=y.hint[y.overlap]??Z;Bo=_a(K),Lo=Mi(y.remainder.slice(1)+Oe)}return nt+Bo+Lo},[s,u,y,p,g]);return we.createElement(qe,{flexDirection:"column",justifyContent:"flex-start"},we.createElement(qe,{flexDirection:"column",paddingX:1,borderColor:m.secondary,borderStyle:"round",width:e},we.createElement(qe,{height:1,flexWrap:"nowrap"},we.createElement(qe,{flexShrink:0},we.createElement(Pi,{wrap:"truncate-start"},Mi(L),D)),a&&we.createElement(qe,{flexShrink:1,minWidth:0},we.createElement(Pi,{wrap:"truncate",color:d?m.red:m.secondary2},` ${a} `)))))};import{Box as $a,Text as Xe}from"ink";import Re from"react";var ji=" ",Fa=({keys:e,label:t})=>e.length+1+t.length,Ha=(e,t)=>{let o=[],n=0;for(let s of e){let r=(o.length>0?ji.length:0)+Fa(s);if(n+r>t-4)break;o.push(s),n+=r}return o},_i=({width:e,availableHints:t})=>{let o=Ha(t,e);return Re.createElement($a,{width:e,borderStyle:"round",borderColor:m.secondary,paddingX:1},o.length?Re.createElement(Xe,{wrap:"truncate"},o.map(({keys:s,label:u},r)=>Re.createElement(Xe,{key:`${s}-${u}`},r>0?ji:"",Re.createElement(Xe,{color:m.accent},s),Re.createElement(Xe,{color:m.secondary2}," ",u)))):Re.createElement(Xe,{color:m.secondary2},"\xA0"))};import{Box as ka,Text as _t}from"ink";import ze,{useEffect as Wa,useRef as Be,useState as Va}from"react";var Ka=40,Dt=.3,So="\u2500",Di=1,Oi=16,Ui=({width:e})=>{let{replay:t}=O(),o=t!==null,n=t?Math.min(1,Math.max(0,t.progress)):0,u=Math.max(4,e-6),r=u*Di,[f,y]=Va(0),p=Be(n);p.current=n;let g=Be(0),l=Be(0),d=Be(0),a=Be(0),i=Be(0);if(Wa(()=>{if(!o){g.current=0,d.current=0,a.current=0,i.current=0,y(0);return}g.current=p.current,l.current=Date.now(),d.current=p.current;let P=setInterval(()=>{let C=Date.now(),I=p.current;if(I!==d.current){let Z=I-d.current,Oe=C-l.current;if(Z<0)a.current=0,i.current=0;else if(Z>0&&Oe>0){let nt=Z/Oe;a.current=a.current===0?nt:a.current*(1-Dt)+nt*Dt,i.current=i.current===0?Z:i.current*(1-Dt)+Z*Dt}g.current=I,l.current=C,d.current=I}let V=C-l.current,Se=Math.min(i.current,a.current*V),De=Math.min(1,g.current+Se),he=Math.round(De*r);y(Z=>Z===he?Z:he)},Ka);return()=>clearInterval(P)},[o,r]),!t)return null;let x=P=>{let C=u>1?P/(u-1):0,I=Math.round(C*(Oi-1))/(Oi-1);return Ho(I)},L=Math.min(u,Math.floor(f/Di)),D=[];for(let P=0;P<L;P++){let C=x(P),I=D[D.length-1];I&&I.color===C?I.text+=So:D.push({text:So,color:C})}let B=So.repeat(Math.max(0,u-L));return ze.createElement(ka,{width:e,borderStyle:"round",borderColor:m.secondary,paddingX:1,columnGap:1},ze.createElement(_t,{color:m.secondary2},"\u25B6"),ze.createElement(_t,null,D.map((P,C)=>ze.createElement(_t,{key:C,color:P.color},P.text)),ze.createElement(_t,{color:m.secondary,dimColor:!0},B)))};var Qe=({width:e,mode:t,availableHints:o})=>{let{timeMode:n}=O(),s=t===H.COMMAND_LINE||t===H.PALETTE;return Ot.createElement(Ya,null,s?Ot.createElement(Li,{width:e,mode:t}):n==="replay"?Ot.createElement(Ui,{width:e}):Ot.createElement(_i,{width:e,mode:t,availableHints:o}))};import{Box as fe,Text as Le}from"ink";import k,{useEffect as qa,useMemo as Ja}from"react";import{ulid as Gi}from"ulid";var Gt=Gi(),Xa=()=>[...new Set([...Q().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(Rr).filter(e=>e!==null).sort(({keys:e},{keys:t})=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(({keys:e,label:t})=>({keys:e,action:t})),za=e=>Ee.text({id:Gt,parentNodeId:e,rank:"000000",name:"Help",isVirtual:!0,readonly:!0}),Qa=(e,t,o)=>Ee.text({id:Gi(),parentNodeId:o,rank:String(t).padStart(6,"0"),name:e.keys,readonly:!0,isVirtual:!0}),Ut=[],$i=()=>{let e=Ut.filter(o=>o.id!==Gt).map(o=>o.id),t=Ut.filter(o=>o.id===Gt).map(o=>o.id);Ut=[];for(let o of[...e,...t])q.deleteNode(o)},Za=e=>{$i();let t=q.createNode(za(Q().rootNodeId));if(h(t)||!Te(t.value))return logger.error("Could not attach help nodes");Ut=[t.value,...e.map((o,n)=>Qa(o,n,Gt)).map(q.createNode).filter($).map(({value:o})=>o).filter(Te)],Ce.navigate({contextNode:t.value,selectedIndex:0})},Fi=({width:e,height:t})=>{let o=Ja(()=>Xa(),[]);qa(()=>(Za(o),()=>{$i()}),[o]);let n=Q().selectedIndex;return k.createElement(fe,{flexDirection:"column",marginTop:3,borderColor:m.secondary,borderStyle:"round",width:e,height:t-2},k.createElement(fe,{paddingX:1,justifyContent:"center"},k.createElement(Le,{color:m.accent},"Help"),k.createElement(Le,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),k.createElement(fe,{paddingX:1,marginTop:1},k.createElement(fe,{width:20,justifyContent:"flex-end"},k.createElement(Le,{color:m.secondary},"Key(s)")),k.createElement(fe,{flexGrow:1,width:40,paddingLeft:2},k.createElement(Le,{color:m.secondary},"Action"))),k.createElement(wt,{height:t-7,itemHeight:1,selectedIndex:n},o.map(({keys:s,action:u},r)=>{let f=r===n;return k.createElement(fe,{paddingX:1,key:`${s}-${u}-${r}`,flexDirection:"row"},k.createElement(fe,{width:20,justifyContent:"flex-end"},k.createElement(Le,{color:m.accent},s)),k.createElement(fe,{flexGrow:1,width:40,paddingLeft:2},k.createElement(Le,{color:f?m.primary:m.secondary2},u)))})))};import{Box as je,Text as W}from"ink";import A,{useEffect as el,useState as Io}from"react";var $t=({index:e,email:t,note:o,noteColor:n})=>A.createElement(je,null,A.createElement(W,{color:m.accent},e===void 0?" ":` ${e}.`),A.createElement(W,null," ",t),o&&A.createElement(W,{color:n??m.secondary2},` ${o}`)),Hi=({height:e})=>{let[t,o]=Io([]),[n,s]=Io([]),[u,r]=Io(null),{userName:f,gitEmail:y,gitName:p,userId:g}=re();return el(()=>{let l=!0;return(async()=>{let a=Pe(),i=oe(process.cwd());if(h(a)||h(i)||!g)return;let x=a.value.emailLinks,L=Ko(x,g);o(L.map(C=>({email:C,others:Vo(x,C).filter(I=>I!==g).map(I=>a.value.contributors[I]?.name??I)})));let D=at(i.value),B=await St({repoRoot:i.value,stateBranch:h(D)?void 0:D.value,names:[f,p],links:x});if(!l)return;if(h(B)){r(B.message);return}let P=It(B.value);ut(P.map(C=>C.email)),s(P)})(),()=>{l=!1}},[g,f,p,y]),A.createElement(je,{height:e-4,flexDirection:"column",paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:m.secondary,rowGap:1},A.createElement(je,null,A.createElement(W,{color:m.accent,bold:!0},f??"Not configured"),A.createElement(W,{color:m.secondary2}," on this board")),u&&A.createElement(W,{color:m.red},u),A.createElement(je,{flexDirection:"column"},A.createElement(W,{color:m.secondary2},"CLAIMED"),t.length===0?A.createElement($t,{email:"Nothing claimed \u2014 your commits show the name git signed them with.",note:""}):t.map(l=>A.createElement($t,{key:l.email,email:l.email,note:l.others.length>0?`CONTESTED: also ${l.others.join(", ")}, resolves to nobody`:l.email===y?"your git identity here":void 0,noteColor:l.others.length>0?m.yellow:void 0}))),A.createElement(je,{flexDirection:"column"},A.createElement(W,{color:m.secondary2},"UNCLAIMED IN THIS HISTORY"),n.length===0?A.createElement($t,{email:"Nothing left to claim here."}):n.map(l=>A.createElement($t,{key:l.email,email:l.email,note:`${l.commits} commit${l.commits===1?"":"s"} as ${l.names.join(", ")||"unknown"}`}))),A.createElement(je,{flexDirection:"column"},A.createElement(W,{color:m.secondary2},A.createElement(W,{color:m.accent},"[enter]")," writes a claim for the first into the command line, to confirm or change."),A.createElement(W,{color:m.secondary2},A.createElement(W,{color:m.accent},":config emails")," claims by address,",A.createElement(W,{color:m.accent}," :config emails-unclaim "),"gives one back."),A.createElement(W,{color:m.secondary2},A.createElement(W,{color:m.accent},"[esc]")," to close")))};import tl from"chalk";import{Box as ve,Text as U}from"ink";import N from"react";var ol=8,rl=()=>{let e=Ge({exclude:process.cwd()});return h(e)?[]:e.value.slice(0,ol)},ki=({width:e,height:t})=>{let o=rl();return N.createElement(ve,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:m.secondary,rowGap:1},N.createElement(U,{color:m.accent,bold:!0},"Initialize project"),N.createElement(U,null,`This folder is not an ${tl.hex(m.accent)("epiq")} project yet.`),N.createElement(U,{color:m.primary},"To start tracking issues here, we need to initialize a new",N.createElement(U,{color:m.primary,backgroundColor:m.secondary}," .epiq/project.json "),"file in this repository."),N.createElement(ve,{marginTop:1,flexDirection:"column"},N.createElement(ve,null,N.createElement(U,{color:m.accent}," "),N.createElement(U,{color:m.primary},"Type "),N.createElement(U,{backgroundColor:m.secondary}," :init "))),N.createElement(ve,{marginTop:1},N.createElement(U,{color:m.secondary2},"This will create, commit and push "),N.createElement(U,{color:m.primary,backgroundColor:m.secondary}," .epiq/project.json ")),o.length>0&&N.createElement(ve,{marginTop:1,flexDirection:"column"},N.createElement(U,{color:m.accent,bold:!0},"Or open a recent project"),o.map((n,s)=>N.createElement(ve,{key:n.projectId},N.createElement(U,{color:m.accent},` ${s+1} `),N.createElement(U,{color:m.primary},dt(n.root)),N.createElement(U,{color:m.secondary2},` ${n.root}`))),N.createElement(ve,{marginTop:1},N.createElement(U,{color:m.accent}," "),N.createElement(U,{color:m.primary},"Type "),N.createElement(U,{backgroundColor:m.secondary}," :open 1 "),N.createElement(U,{color:m.secondary2}," or "),N.createElement(U,{backgroundColor:m.secondary}," :open <path> "))))};import{Box as Ht,Text as X}from"ink";import j from"react";import{Box as Ft,Text as me}from"ink";import J,{useEffect as nl,useState as Wi}from"react";var Vi=()=>{let[e,t]=Wi(null),[o,n]=Wi(null);return nl(()=>{let s=!0;return(async()=>{let r=Pe(),f=oe(process.cwd());if(h(r)||h(f))return;let y=at(f.value),{userName:p,gitName:g}=re(),l=await St({repoRoot:f.value,stateBranch:h(y)?void 0:y.value,names:[p,g],links:r.value.emailLinks});if(!s)return;if(h(l)){n(l.message);return}let d=It(l.value);ut(d.map(a=>a.email)),t(d)})(),()=>{s=!1}},[]),o?J.createElement(Ft,{marginTop:1},J.createElement(me,{color:m.red},o)):e===null?null:e.length===0?J.createElement(Ft,{marginTop:1},J.createElement(me,{color:m.secondary2},"No unclaimed addresses in this history \u2014 type",J.createElement(me,{color:m.accent}," :config emails none "),"to move on.")):J.createElement(Ft,{flexDirection:"column",marginTop:1},e.map(s=>J.createElement(me,{key:s.email},J.createElement(me,{color:m.accent}," \xB7 "),J.createElement(me,null,s.email),J.createElement(me,{color:m.secondary2},` ${s.commits} commit${s.commits===1?"":"s"} as ${s.names.join(", ")||"unknown"}`))),J.createElement(Ft,{marginTop:1},J.createElement(me,{color:m.secondary2},"Claim yours by address, or",J.createElement(me,{color:m.accent}," none "),"to skip.")))};var il=({isDone:e,command:t,value:o,verb:n="Type",hint:s})=>j.createElement(Ht,null,j.createElement(X,{color:m.accent,dimColor:e},e?" \u2714 ":" "),j.createElement(X,{dimColor:e},n," "),j.createElement(X,{backgroundColor:m.secondary,dimColor:e}," "+t+" "),o!==void 0&&j.createElement(j.Fragment,null,j.createElement(X,{dimColor:e}," "),j.createElement(X,{color:m.secondary,dimColor:e},"<"+o+">")),s),sl=(e,t)=>e.length===0?void 0:Jo(e.join(", "),Math.max(12,t-34)),al=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function To({width:e,height:t}){let{isSetPreferredEditor:o,isSetUserName:n,userName:s,preferredEditor:u,autoSync:r,isSetAutoSync:f,isSetEmails:y,claimedEmails:p,emailSetupDeclined:g}=pt(),l=[{key:"username",done:n,command:":config username",value:s,message:"First, choose your username."},{key:"editor",done:o,command:":config editor",value:u,message:"Nice. Now pick your editor."},{key:"autosync",done:f,command:":config autosync",value:r,message:"Almost there. Configure auto sync."},{key:"emails",done:y,command:":config emails",value:g?"declined":sl(p,e),message:"Last one. Claim the git addresses whose commits are yours, so the board calls them by your name."}],d=l.findIndex(i=>!i.done),a=d===-1?void 0:l[d];return j.createElement(Ht,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:m.secondary,rowGap:1},j.createElement(X,{color:m.accent,bold:!0},"Welcome! \u{1F539}"),j.createElement(X,null,"Let's get you started - it's a breeze."),j.createElement(X,{color:m.secondary2},"Remember - you can always search available commands by typing:",j.createElement(X,{color:m.accent}," ? ")),a&&j.createElement(X,{color:m.secondary2},a.message),j.createElement(Ht,{flexDirection:"column"},l.map((i,x)=>{if(!(d===-1||x<=d))return null;let D=x===d,B=D&&d===0;return j.createElement(Ht,{key:i.key,flexDirection:"column",marginBottom:1},j.createElement(il,{isDone:i.done,command:B?":config us":i.command,value:i.done?al(i.value):void 0,verb:D&&!B?"Waiting:":"Type",hint:B?j.createElement(X,{color:m.secondary2}," then ",j.createElement(X,{color:m.accent},"tab")," to auto-complete ",j.createElement(X,{backgroundColor:m.secondary},` ${i.command.split(" ").pop()} `)):void 0}),i.key==="emails"&&!i.done&&j.createElement(Vi,null))})))}import Yt from"chalk";import{Box as tt,Text as _e}from"ink";import _ from"react";import{Box as kt,Text as Ki}from"ink";import ge from"react";import ll from"chalk";var ml=e=>(q.getTag(e)?.name??"").length+3,cl=e=>{let t=q.getContributor(e);return(t?t.name:"").length+3},Yi=({width:e})=>{let{viewMode:t}=re(),o=O(),{breadCrumb:n,contextNode:s,selectedIndex:u,renderedChildrenIndex:r}=o,f=r[s.id]?.[u],y=Lr(f?.id??s.id,"TICKET"),p=$(y)?y.value:void 0,g=(p?.props.tags??[]).filter(I=>q.getTag(I)),l=p?.props.assignees??[],d=p?.parentNodeId?!jr(s.id,p.parentNodeId)&&t==="dense":!1,a=n.map((I,V)=>{let Se=V===n.length-1,De=ht(I.id),he=Se?De?.[u]?.title:void 0;return`${V?" / ":""}${I.title??""}${he?` \u25B8 ${he}`:""}`}).join(""),i=p?q.getCommentsByIssue(p.id):[],x=i.length?String(i.length).length+11:0,L=d?g.reduce((I,V)=>I+ml(V),0)+l.reduce((I,V)=>I+cl(V),0)+x:0,D=f?.id!=null&&!(t==="wide"&&ct(f)),B=Math.max(0,e-L),P=a.substring(0,B)+(D?ll.hex(m.secondary2).dim(` ${de(f.id)}`):""),C=d?[...g.map(I=>ge.createElement(kt,{key:`tag-${I}`,paddingLeft:1},ge.createElement(wr,{id:I}))),...l.map(I=>ge.createElement(kt,{key:`assignee-${I}`,paddingLeft:1},ge.createElement(xr,{id:I}))),i.length?ge.createElement(kt,{key:"comments",paddingLeft:1},ge.createElement(Ki,{color:m.accent},"[",i.length," comment",i.length===1?"":"s","]")):null]:[];return ge.createElement(kt,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},ge.createElement(Ki,{color:m.secondary2},P),C)};import{Box as dl,Text as qi}from"ink";import Wt from"react";var ul=({filters:e})=>Wt.createElement(dl,{columnGap:1},Wt.createElement(qi,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:o,operator:n})=>Wt.createElement(qi,{backgroundColor:"black",color:"white"},` ${o}${n}"${t}" `))),Ji=Wt.memo(ul);import{Box as pl,Text as Vt}from"ink";import Ze from"react";function Xi(){let{eventLog:e,unappliedEvents:t}=O(),o=e.at(-1)?.id,n=ko(o??""),s=$(n)?vt(n.value):"INVALID DATE";return Ze.createElement(pl,{paddingLeft:1},Ze.createElement(Vt,{backgroundColor:m.accent,color:m.secondary}," Readonly "),Ze.createElement(Vt,{color:m.accent}," "+t.length+" edits ago at "+s+"."),Ze.createElement(Vt,{color:m.accent}," Resume with "),Ze.createElement(Vt,{backgroundColor:m.accent,color:m.secondary}," ",":peek now"," "))}import{Box as fl,Text as Eo}from"ink";import Kt from"react";function zi(){let{replay:e}=O();if(!e)return null;let{appliedCount:t,totalCount:o,currentTime:n}=e;return Kt.createElement(fl,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},Kt.createElement(Eo,{backgroundColor:m.accent,color:m.secondary}," \u25B6 REPLAY "),Kt.createElement(Eo,{color:m.secondary2},vt(new Date(n))),Kt.createElement(Eo,{color:m.accent},`${t}/${o} edits`))}import Co from"chalk";import{Box as gl,Text as Qi}from"ink";import Po,{useEffect as yl,useState as hl}from"react";var bl=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],xl=150,Zi=12,wl=.36;function es({syncStatus:e,autoSync:t}){let[o,n]=hl(0);yl(()=>{if(e.status!=="syncing"){n(0);return}let f=0,y=setInterval(()=>{f+=1;let p=(Math.sin(f*wl)+1)/2,g=Math.round(p*(Zi-1));n(l=>l===g?l:g)},xl);return()=>clearInterval(y)},[e.status]);let s={synced:" ",failed:"---",offline:"off",syncing:"...",pending:"idle"},r={synced:m.secondary2,failed:m.yellow,offline:m.secondary2,pending:m.secondary2,syncing:Fo(bl,o/(Zi-1))??""}[e.status];return Po.createElement(gl,null,Po.createElement(Qi,null,Co.hex(m.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Po.createElement(Qi,null,Co.hex(r)("\u25CF")+Co.hex(m.secondary2).dim(` ${s[e.status].padEnd(4)} `)))}import et from"chalk";import{Text as ts}from"ink";import os,{useEffect as vl,useState as Sl}from"react";var Il=(e,t)=>{let o=e.split("."),n=t.split("."),s=n.findIndex((u,r)=>u!=o[r]);return n.map((u,r)=>r>=s?et.hex(m.accent).dim(u):et.hex(m.secondary).dim(u)).join(et.hex(m.secondary2).dim("."))};function rs(){let[e,t]=Sl({current:F,latest:null,updateAvailable:!1});return vl(()=>{let o=!0;return ho(F).then(n=>{o&&t(n)}),()=>{o=!1}},[]),!e.updateAvailable||!e.latest?os.createElement(ts,{dimColor:!0,color:m.secondary2},F+" "):os.createElement(ts,null,et.hex(m.secondary2).dim(F),et.hex(m.accent).dim(" \u2197 "),Il(F,e.latest))}function ot({filters:e,hideBreadCrumb:t=!1}){let{timeMode:o,syncStatus:n,mode:s,replay:u}=O(),{userName:r,preferredEditor:f,autoSync:y}=re(),p=64,g=process.stdout.columns-p-8,l=t||o==="replay",d=u?qo(u.currentLabel,Math.max(0,g)):"";return _.createElement(tt,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},o==="replay"?_.createElement(tt,{paddingLeft:1},_.createElement(_e,{color:m.secondary2},d)):l?_.createElement(_e,null," "):s===H.PALETTE?_.createElement(tt,null,_.createElement(_e,{color:m.accent},"Command Palette"),_.createElement(_e,{dimColor:!0,color:m.secondary2}," ","- search, select and press enter")):_.createElement(tt,{paddingLeft:1},e.length>0?_.createElement(Ji,{filters:e}):_.createElement(Yi,{width:g})),o==="live"?_.createElement(tt,{columnGap:1,paddingRight:2,"max-width":p,overflow:"hidden",justifyContent:"flex-end"},_.createElement(es,{autoSync:!!y,syncStatus:n}),_.createElement(_e,null,Yt.hex(m.secondary2).dim("Mode: ")+Yt.hex(m.secondary2).dim(s.padEnd(8," "))," "),_.createElement(ns,{icon:"@",value:r}),_.createElement(ns,{icon:"\u276F",value:f}),_.createElement(rs,null)):"",o==="peek"?_.createElement(Xi,null):"",o==="replay"?_.createElement(zi,null):"")}function ns({icon:e,value:t}){return _.createElement(_e,null,Yt.dim(e)+Yt.hex(m.accent)(` ${t??"-"} `))}import{Box as Tl,Text as El}from"ink";import rt from"react";import{Box as qt,Text as Ao}from"ink";import ye from"react";function No(){let e=O(),t=e.nodes[e.rootNodeId],s=process.stdout.rows-1-3,u=process.stdout.columns||120,r=t?.id?Fe(t?.id):[];return ye.createElement(qt,{flexDirection:"column",height:s,padding:1,borderStyle:"round",borderColor:m.secondary,width:u},ye.createElement(qt,{padding:1,paddingTop:0,paddingBottom:0},ye.createElement(Ao,null,"Select a board:")),ye.createElement(qt,{padding:1,flexDirection:"column"},r.map((f,y)=>{let p=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===y,l=Fe(f.id).flatMap(({id:d})=>ht(d)).length;return ye.createElement(qt,{key:f.id??y},ye.createElement(Ao,{color:p?m.accent:m.secondary2},ye.createElement(br,{isSelected:p})),ye.createElement(Ao,{color:p?m.accent:m.secondary2},f.title," (",l," issues)",f.readonly?" \u{1F512}":""))})))}var Cl=({contextNode:e,selectedIndex:t,breadCrumb:o,mode:n,viewMode:s,height:u,width:r})=>{let{renderedChildrenIndex:f}=O(),y=o.find(({context:d})=>d==="BOARD"),l=u-1-3;return rt.createElement(Tl,{flexDirection:"row"},e.context==="WORKSPACE"?rt.createElement(No,null):y?rt.createElement(vr,{height:l,width:r,swimlanes:(f[y.id]??[]).filter(d=>d!==void 0&&Yo(d)),contextNode:e,selectedIndex:t,breadCrumb:o,viewMode:s,mode:n}):rt.createElement(El,null))},is=rt.memo(Cl);import{useEffect as Pl}from"react";var Al=e=>{Pl(()=>{if(!e)return;let t,o=!1,n=()=>{if(o)return;let{autoSyncIntervalMs:s,userName:u,preferredEditor:r}=re();r&&u&&s&&(t=setTimeout(()=>{if(o)return;let{readOnly:f,mode:y}=Q();y==="default"&&!f&&yr(),n()},s))};return n(),()=>{o=!0,t&&clearTimeout(t)}},[e])},ss=({autoSync:e})=>(Al(e),null);import{useEffect as Nl}from"react";var as=()=>{let e=oe(process.cwd());return h(e)?T("No project here",null):lt({repoRoot:e.value})},ls=async()=>{let e=as();if(h(e))return G(e.message);if(e.value===null)return T("No project here",null);let t=e.value,o=await gt(t);if(!Br())return T("State not initialized",null);let n=Pe();if(h(n))return T("State not initialized",null);let{mode:s,readOnly:u,timeMode:r,syncStatus:f,selectedNode:y,contextNode:p}=n.value;if(Tr())return T("Project loading",null);let g=as();return h(g)||g.value!==t?T("Project changed",null):s!==H.DEFAULT||u||r!=="live"?T("Skipped while not on the live board",null):y?.isVirtual||p?.isVirtual?T("Skipped on a virtual node",null):f?.status==="syncing"?T("Sync in progress",null):o?T("Worktree held by a sync",null):$e(t)===Zo(t)?T("Log unchanged",null):(st.debug("[watch] event log moved, reloading state"),gr(t))};var Ml=1e3,ms=()=>(Nl(()=>Bt(ls,Ml),[]),null);function Mo({width:e,height:t}){let o=O(),{autoSync:n,viewMode:s}=Uo(),u=o.filters;if(o.mode===H.HELP)return M.createElement(ce,{flexDirection:"column"},M.createElement(Fi,{width:e,height:t}));if(o.mode===H.IDENTITY)return M.createElement(ce,{flexDirection:"column"},M.createElement(Hi,{width:e,height:t}));if(o.mode===H.PALETTE)return M.createElement(ce,{flexDirection:"column"},M.createElement(ot,{filters:u}),M.createElement(Ii,{width:e,height:t-2}),M.createElement(Qe,{width:e,mode:o.mode,availableHints:o.availableHints}));let{isSetupDone:r}=pt(),f=!r,y=r&&!o.hasProjectDefinition;if(f)return M.createElement(ce,{flexDirection:"column"},M.createElement(ce,{flexDirection:"column"},M.createElement(ot,{hideBreadCrumb:!0,filters:u}),M.createElement(To,{height:t,width:e})),M.createElement(Qe,{width:e,mode:o.mode,availableHints:[]}));if(y)return M.createElement(ce,{flexDirection:"column"},M.createElement(ce,{flexDirection:"column"},M.createElement(ot,{hideBreadCrumb:!0,filters:u}),M.createElement(ki,{height:t,width:e})),M.createElement(Qe,{width:e,mode:o.mode,availableHints:[]}));let p=Wo(o.breadCrumb??[],"BOARD");if($(p)){let g=p.value.id,l=Fe(g).length,d=3,a=Math.floor(e/d),i=Math.floor(e/Math.max(l,1));e=Math.min(i,a)*Math.max(l,d)}return M.createElement(ce,{flexDirection:"column"},M.createElement(ss,{autoSync:n}),M.createElement(ms,null),M.createElement(ce,{flexDirection:"column"},M.createElement(ot,{filters:u}),M.createElement(is,{width:e,height:t,contextNode:o.contextNode,selectedIndex:o.selectedIndex,breadCrumb:o.breadCrumb,viewMode:s??"dense",mode:o.mode})),M.createElement(Qe,{width:e,mode:o.mode,availableHints:o.availableHints}))}import Rl from"readline";var Jt,Xt,se,Bl=new Set([b.MoveCursorLeft,b.EraseInputWord,b.MoveCursorLeftOfWord,b.MoveCursorRight,b.MoveCursorRightOfWord,b.NavToPreviousContainer,b.NavToNextContainer,b.NavPreviousItem,b.NavNextItem,b.NavPreviousItemJump,b.NavNextItemJump,b.SetViewDense,b.SetViewWide,b.Confirm,b.Exit,b.Yank,b.InitCommandLine,b.InitCommandPalette,b.ExitCommandLine,b.CaptureInput,b.EraseInput,b.EraseInputWord,b.HideHelp,b.ViewHelp,b.SetViewDense,b.SetViewWide,b.GetLastCommandFromHistory,b.GetNextCommandFromHistory,b.AutoCompleteCommand]),Ll=new Set([b.NavPreviousItem,b.NavNextItem,b.NavPreviousItemJump,b.NavNextItemJump,b.NavToPreviousContainer,b.NavToNextContainer,b.Confirm,b.Exit,b.InitCommandPalette,b.InitMove,b.MoveNextItem,b.MovePreviousItem,b.MoveNextItemJump,b.MovePreviousItemJump,b.MoveToNextContainer,b.MoveToPreviousContainer,b.Delete,b.AddItem,b.EditTitle,b.EditDescription,b.ConfirmMove,b.Edit,b.ViewHelp,b.Yank]),cs=async e=>{if(e.ctrl&&e.name==="c")return Ce.exit();let{actionIndex:t,mode:o,readOnly:n,timeMode:s}=Q(),u=pr(e,o);if(!u||n&&!Bl.has(u)||s==="replay"&&o===H.DEFAULT&&Ll.has(u))return;let r=t[o]?.[u];if(r?.action)try{await r.action(r,e)}catch(f){logger.error(f)}},jl=()=>async function(t,o){o.name!=="escape"&&(se&&(clearTimeout(se),se=void 0),await cs(o))},_l=()=>async function(t){if(t.length===1&&t[0]===27){se&&clearTimeout(se),se=setTimeout(()=>{cs({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),se=void 0},25);return}se&&(clearTimeout(se),se=void 0)};function ds(){Jt&&process.stdin.removeListener("keypress",Jt),Xt&&process.stdin.removeListener("data",Xt),Jt=jl(),Xt=_l(),Rl.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Xt),process.stdin.on("keypress",Jt)}async function us(){try{let e=it({});if(h(e))return bt(0,e.message);let t=Ie();$(t)&&Ue(t.value);let o=oe(process.cwd());Ue({gitEmail:await Fr(process.cwd()),gitName:await Hr(process.cwd())});let n=$(o)?await Er(o.value):Pr();if(h(n))return n;let s=Ro();return h(s)?bt(6,s.message):(ds(),$(o)&&Cr(o.value),T("Booted Epiq",void 0))}catch(e){return bt(0,xt(e))}}Ir();var Gl=`${z.bold("Epiq CLI")}
5
+
6
+ ${z.dim("Boot in directory:")}
7
+ ${z.cyan("$ epiq")}
8
+
9
+ ${z.dim("Launch GUI:")}
10
+ ${z.cyan("$ epiq gui")}
11
+ ${z.cyan("$ epiq gui --no-open")} ${z.dim("no browser")}
12
+
13
+ ${z.dim("Act as somebody other than the configured user:")}
14
+ ${z.cyan("$ epiq --as claude")}
15
+ `,Zt=Ol(Gl,{importMeta:import.meta,version:F,flags:{init:{type:"boolean",default:!1},as:{type:"string"},open:{type:"boolean",default:!0}}}),zt=Zt.input[0];zt&&zt!=="gui"&&(console.error(z.red(`Unknown command: ${zt}`)),process.exit(1));if(Zt.flags.as!==void 0){let e=jo(Zt.flags.as,"--as");h(e)&&(console.error(z.red(e.message)),process.exit(1))}var ps=process.stdout.columns||120,fs=process.stdout.rows||20,Qt=null,$l=e=>{try{return Qt?(Qt.rerender(e),T("Rerendered app",void 0)):(Qt=Dl(e),T("Rendered app",void 0))}catch(t){return G(`Unable to render app: ${xt(t)}`)}},Ro=()=>$l(Ul.createElement(Mo,{width:ps,height:fs}));process.stdout.on("resize",()=>{if(ps=process.stdout.columns||120,fs=process.stdout.rows||20,!Qt)return;let e=Ro();h(e)&&logger.info(`[boot:resize] ${e.message}`)});if(zt==="gui"){let e=await xi({repoRoot:process.cwd(),open:Zt.flags.open});h(e)&&(console.error(z.red(`Failed to start Epiq GUI:
16
+ ${e.message}`)),process.exitCode=1)}else{console.clear();let e=await us();h(e)&&(logger.info(e.message),console.error(z.red(`Failed to boot Epiq:
17
+ ${e.message}`)),process.exitCode=1)}export{Ro as renderApp};
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as t}from"./chunk-BGP4XGKD.js";var r=`epiq-mcp ${t}
2
+ import{a as t}from"./chunk-SCSGIFUR.js";var r=`epiq-mcp ${t}
3
3
 
4
4
  Usage: epiq-mcp [name]
5
5
 
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import{$a as w,A as qt,Aa as vt,B as Vt,Ba as vo,C as Yt,Ca as ht,Cc as _,D as ye,Dc as Jo,E as O,Ea as ho,Ec as Qo,F as Jt,Fa as bt,G as Qt,Ga as Ue,Gb as me,H as te,Ha as bo,Hb as we,I as Zt,Ia as Ro,J as D,Ja as Se,Jb as pe,K as We,Ka as ze,La as yo,M as Ae,Ma as Ao,Mb as $o,N as eo,Na as Rt,Nb as Wo,O as to,Oa as yt,Ob as jo,P as mt,Pa as y,Q as oo,Qa as To,R as so,Ra as A,Rb as Ho,S as no,Sa as So,Sb as Uo,T as F,Tb as zo,Ua as At,V as U,Va as ue,W as $,Wa as wo,Xa as ce,Ya as oe,Za as Eo,_ as C,_a as xo,b as Fe,c as le,ca as ro,d as _e,e as Ge,eb as Co,ec as Ko,f as jt,fa as k,fb as Bo,g as Q,ga as io,ha as ao,hb as Lo,i as Ht,ib as Ke,jb as No,jc as Xo,k as $e,ka as lo,kb as ko,kc as Tt,la as uo,lb as Po,lc as qo,ma as je,mb as Oo,n as ee,na as He,nb as Mo,o as Ut,oa as Te,ob as Do,pa as pt,pb as Fo,pc as qe,q as ct,qa as ft,qc as Vo,ra as gt,rb as _o,s as zt,sa as de,ta as co,tc as Yo,ua as It,uc as Ve,va as mo,vb as Xe,vc as St,wa as po,wb as Go,xa as fo,xb as M,y as Kt,ya as go,yc as wt,z as Xt,za as Io,zc as Ye}from"./chunk-GOROXQFX.js";import{g as Wt}from"./chunk-WUCQWBQE.js";import{b as d,c as m,d as l}from"./chunk-5RIQL7P4.js";var an=e=>e.payload??{},Et=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,We),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(Vt(e.action))return[i,Yt(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(" ")},xt=(e,t)=>e?D(e,t.get(e)):null,bn=(e,t)=>{let o=e.payload;return{actor:xt(e.userId,t),tag:xt(es(e),t),assignee:xt(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,...Et(e).byId]),s=ln(e),n=dn(e),a=e.map(c=>un(c,n)),r=gn(e),i=fn(e,a),u=os(e),f=Jt(e.map(c=>te(c)));return e.flatMap((c,I)=>{let v=f[I]??null;return v===null?[]:[{id:c.id,t:v,action:c.action,label:hn(c,o,s,a[I]??null,r[I]??null),issue:a[I]??null,target:mn(c),...i[I],board:u[I]??null,...bn(c,o)}]}).sort((c,I)=>c.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===k?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===k||o&&r.board!==o||(s[n]=r.lane)}return s},Sn=e=>Et(e).lanes,Ee=null,is=e=>{let t=ze(e);if(Ee&&Ee.root===e&&Ee.signature===t)return m("Timeline entries, cached",Ee.index);let o=oe(e);if(l(o))return d(o.message);let s=yn(o.value,ce(e)),n={entries:s,lanes:An(s),laneNames:Sn(o.value)};return Ee={root:e,signature:t,index:n},m("Timeline entries, built",n)};var as=1e5,wn=2e4,Je=null,ls=Promise.resolve(),us=e=>{let t=ls.then(e,e);return ls=t.then(()=>{},()=>{}),t},Qe=e=>{let t=Se(e);return l(t)?t:Q({repoRoot:t.value})},z=()=>{if(!Ye())return{mode:"live",asOfTime:null};let{timeMode:e}=Yo();return e==="live"?{mode:"live",asOfTime:null}:{mode:"scrub",asOfTime:Je}},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},ra=async(e={})=>{let t=Qe(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 m("Empty time window",{bucketMs:0,buckets:[],capped:!1,events:[],lanesAtStart:{},laneNames:o.value.laneNames,closedLane:k,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),c=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)/c)),T=r+b*c;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 m("Computed event timeline",{bucketMs:c,buckets:v,capped:h,events:h?[]:f,lanesAtStart:rs(o.value.lanes,r,e.boardId),laneNames:o.value.laneNames,closedLane:k,earliest:r,latest:a})},cs=e=>{let t=oe(e);if(l(t))return d(t.message);let o=wt();if(l(o))return d(o.message);Je=null;let s=At(t.value),{fatal:n,skipped:a}=Rt(s);return n.length>0?d(n.map(r=>r.message).join(", ")):(yt(a),St({readOnly:!1,readOnlyReason:void 0,timeMode:"live",unappliedEvents:[],replay:null}),m("Restored live state",!0))},En=(e,t)=>{Je=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=Qe(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=wt();if(l(a))return a;let r=At(s),{fatal:i,skipped:u}=Rt(r);return i.length>0?En(t.value,i.map(f=>f.message).join(", ")):(yt(u),St({readOnly:!0,timeMode:"peek",unappliedEvents:n,replay:null}),Je=e.targetTime,m("Checked out historical state",{asOfTime:e.targetTime}))}),ia=async e=>{let t=Qe(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})},aa=(e={})=>us(async()=>{let t=Qe(e.repoRoot);if(l(t))return d(t.message);let o=cs(t.value);return l(o)?d(o.message):m("Returned to live state",!0)});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 Ge({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=Ae(u)||null)}return ms.set(e,{name:s,email:n,readAt:Date.now()}),{name:s,email:n}},fs=async e=>(await ps(e)).email,fe=async e=>(await ps(e)).name;var se=e=>{let t=$e(e??process.cwd());return l(t)?d(t.message):m("Resolved Epiq repo root",t.value)},Ze=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(!(Ze!==null&&Ze.repoRoot===o.value&&Ze.stateBranchRoot===s.value&&Bn.existsSync(Ht(s.value)))){let c=await Ho({repoRoot:o.value,stateBranchName:n.value});if(l(c))return d(c.message);let I=await Uo({repoRoot:o.value,stateBranchRoot:s.value,stateBranchName:n.value});if(l(I))return d(I.message);Ze={repoRoot:o.value,stateBranchRoot:s.value}}if(t?.pull??!1){let c=await _e({cwd:s.value,args:["pull","--ff-only"]});l(c)&&Fe.info(3,c.message)}let r={repoRoot:o.value,stateBranchRoot:s.value},i=ee();l(i)||ct(i.value),ct({gitEmail:await fs(o.value),gitName:await fe(o.value)});let u=ze(s.value);if(yo(s.value)===u&&Ye()&&z().mode==="live")return m("Booted Epiq state, unchanged",r);let f=ue(s.value);if(l(f))return d(f.message);let g=pe(f.value.events,f.value.unreadable);return l(g)?d(g.message):(Ao(s.value,u),m("Booted Epiq state",r))},W=()=>{let e=ee();return l(e)?d(e.message):e.value.userId?e.value.userName?m("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=Ve();return l(e)?d(e.message):e},L=e=>Ln(e,{pull:!1}),R=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:m("Booted",{boot:t.value,actor:o.value,state:s.value})};import{ulid as Nn}from"ulid";var N=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"):m("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"):U(o)?o.readonly?d("Swimlane is readonly"):m("Found swimlane",o):d("Target must be a swimlane")},xe=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"):m("Found board",o):d("Target must be a board")};var Ct=e=>{if(!e)return;let t=B();if(l(t))return;let o=t.value.nodes[e];if(!o||!($(o)||U(o)))return;let s=o.props?.description;return s?.trim()?s:void 0},et=e=>{let t=Ct(e);return t?{laneDescription:t}:{}},Ce=e=>{let t=Ct(e);return t?{boardDescription:t}:{}},ge=e=>{let t=Ct(e);return t?{description:t}:{}},Be=({node:e,label:t,max:o,description:s,actor:n,stateBranchRoot:a,action:r="edit.description"})=>{let i=Go(s),u=M(t,i,o);if(u)return d(u);if(z().mode!=="live")return d(`Cannot edit the ${t.toLowerCase()} while time travelling`);let f={id:e.id,ref:A(e.id),description:i};if((e.props?.description??"")===i)return m("No changes made",f);let g={id:Nn(),...y(n),action:r,payload:{id:e.id,md:i}},c=w([g],a);return l(c)?d(c.message):m(`Edited ${t.toLowerCase()}`,f)},kn=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=xe(e.boardId);return l(o)?o:Be({node:o.value,label:"Board description",max:Xe("board"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},Pn=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);return l(o)?o:Be({node:o.value,label:"Swimlane description",max:Xe("swimlane"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},On=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=de(e.goal);return o?Be({node:{id:o.id,props:{description:o.description}},label:"Goal description",action:"edit.goal.description",max:Xe("goal"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot}):d(`No goal called or with the id "${e.goal}"`)};import{ulid as Le}from"ulid";var Bt=e=>({id:e.id,name:C(e.name),color:mo(e)}),Ne=e=>{let t=co(e);return t?{goal:Bt(t)}:{}},gs=e=>({...Bt(e),...vt(e.id),...e.description&&{description:e.description}}),Is=()=>ft().map(gs),Mn=async(e={})=>{let t=await L(e.repoRoot);return l(t)?t:m("Listed goals",ft().map(o=>({...gs(o),boards:fo(o.id).map(s=>({id:s,ref:A(s)}))})))},tt=e=>Io(e).map(t=>({...Bt(t),...vt(t.id),members:go(t.id,e).map(o=>({id:o.id,done:vo(o)}))})),ot=(e,t,o)=>{let s=w(t,e);return l(s)?d(s.message):m("Saved",o)},Dn=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(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=de(e.goal);if(!u){let f=await vs({repoRoot:e.repoRoot,name:e.goal,issueId:s.id});return l(f)?f:m(`Created goal "${f.value.name}"`,n)}a=u.id}let r=It(s,a);if(r.length===0)return m("No changes made",n);let i=y(t.value.actor);return ot(t.value.boot.stateBranchRoot,r.map(u=>({id:Le(),...i,...u})),n)},vs=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=gt(e.name),s=ht(o);if(s)return d(s);let n=y(t.value.actor),a=Le(),r=[{id:a,...n,action:"create.goal",payload:{id:a,name:o}}];if(e.issueId){let i=N(e.issueId);if(l(i))return i;let u=i.value;for(let f of It(u,a))r.push({id:Le(),...n,...f})}return ot(t.value.boot.stateBranchRoot,r,{id:a,name:o})},Fn=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=pt(e.goalId);if(!o)return d("Goal not found");let s=gt(e.name);if(s===o.name)return m("No changes made",{id:o.id,name:s});let n=ht(s,o.id);return n?d(n):ot(t.value.boot.stateBranchRoot,[{id:Le(),...y(t.value.actor),action:"rename.goal",payload:{id:o.id,name:s}}],{id:o.id,name:s})},_n=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=pt(e.goalId);return o?ot(t.value.boot.stateBranchRoot,[{id:Le(),...y(t.value.actor),action:"tombstone.goal",payload:{id:o.id}}],{id:o.id,name:o.name}):d("Goal not found")};import{ulid as Gn}from"ulid";var st=e=>{let t=lo(e);return t.length>0?{rules:t}:{}},$n=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);if(l(o))return o;let s=o.value,n=uo(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 m(n.message,a);let r=w([{id:Gn(),...y(t.value.actor),...n.value}],t.value.boot.stateBranchRoot);return l(r)?d(r.message):m(e.on?"Added lane rule":"Removed lane rule",a)};import Wn from"node:fs";import jn from"node:path";import{ulid as Lt}from"ulid";var Hn=e=>{if(e.filePath)try{return m("Read attachment file",{data:Wn.readFileSync(e.filePath),name:e.name??jn.basename(e.filePath)})}catch(t){return d(`Unable to read ${e.filePath}: ${t instanceof Error?t.message:String(t)}`)}return e.dataBase64?m("Decoded attachment data",{data:Buffer.from(e.dataBase64,"base64"),name:e.name??"image"}):d("Provide either filePath or dataBase64")},nt=()=>{let e=ee();return l(e)?bt:e.value.attachmentMaxKb??bt},Un=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(e.issueId);if(l(o))return o;let s=Hn(e);if(l(s))return s;let n=bo(t.value.boot.stateBranchRoot,s.value.data,nt());if(l(n))return n;let a=C(s.value.name).trim()||"image",r=Lt(),i={id:Lt(),...y(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 m("Added issue attachment",{id:r,issueId:e.issueId,fileName:f,bytes:n.value.bytes,markdown:ho(a,f)})},zn=async e=>{let t=await R(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=N(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 m("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let a={id:Lt(),...y(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):m("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Kn=async e=>{let t=await L(e.repoRoot);return l(t)?t:Ro(t.value.stateBranchRoot,e.fileName,nt())};var Xn=e=>{switch(e.action){case"add.issue":case"move.node":case"close.issue":case"reopen.issue":return e.payload.parent;default:return null}},Nt=(e,t)=>{let o=[];for(let s of e){let n=Xn(s);if(n===null||n===o.at(-1)?.laneId)continue;let a=te(s);o.push({laneId:n,enteredAt:a===null?t:ye(a)})}return o},hs=(e,t)=>e.reduce((o,s)=>{let n=te(s);return n===null?o:Math.max(o,ye(n))},t),ke=(e,t)=>Nt(e,t).at(-1)?.enteredAt??t;var ne=e=>io(e).map(t=>D(t.id,t.name)),qn=e=>_.getCommentsByIssue(e).sort((t,o)=>t.id<o.id?-1:t.id>o.id?1:0).map(t=>({id:t.id,author:Zt(t.authorId,_.getContributor(t.authorId)?.name),createdAt:O(t.id),body:t.md})),re=e=>ao(e).map(({id:t,name:o})=>D(t,o)),Vn=3,Yn=3,Jn=400,Qn=200,Zn=" \u2026 [cut: call epiq_issue_get with allComments: true to read the rest]",er=e=>{let t=e.split(`
5
+ `).slice(0,Yn).join(`
6
+ `).slice(0,Jn);return e.length-t.length<Qn?e:`${t}${Zn}`},bs=(e,t=!1)=>{let o=qn(e),s=o.length-Vn;return t||s<=0?{comments:o}:{comments:o.map((n,a)=>a<s?{...n,body:er(n.body)}:n),olderComments:`The first ${s} show their first lines only: pass allComments to read them whole`}};var tr=async(e={})=>{let t=await L(e.repoRoot);if(l(t))return t;let o=B();return l(o)?o:m("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})},or=365*24*60*60*1e3,sr=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return m("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()-or,r=new Map,i=new Map;for(let p of s)if(!p.isDeleted){if(U(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===k&&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={},c=_.getCommentsGroupedByIssue();for(let p of s.filter(F))p.isDeleted||!u.has(p.id)||(g[p.id]=(c.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 m("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,...ge(p.id),goals:tt(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:ke(T.log??[],O(T.id)),lastEventAt:hs(T.log??[],O(T.id)),readonly:!!T.readonly||o,tags:ne(T),assignees:re(T),...Ne(T),parentNodeId:T.parentNodeId,isClosed:T.parentNodeId===k,boardIds:Te(T)})),parentNodeId:b.parentNodeId,...ge(b.id),...st(b),countsDone:He(b.id),doneByName:je(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:zt(f.value.userName??"")},commentsByIssueId:g,attachmentsByIssueId:v,attachmentMaxKb:nt(),timeTravel:t})},Rs=null,nr=e=>{if(e===Rs)return;let t=ro({root:e});if(l(t)){Fe.info(t.message);return}Rs=e},rr=async(e={})=>{if(z().mode!=="live")return kt();let t=await L(e.repoRoot);return l(t)?t:(nr(t.value.repoRoot),kt())},ir=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(),m("Synced",s.value))};import{ulid as K}from"ulid";var Pe=e=>{let t=[...new Set([...e.issueIds??[],...e.issueId?[e.issueId]:[]])];return t.length?m("Resolved targets",t):d("Provide issueId or issueIds")},Ie=(e,t)=>{let o=t.done.length,s=`${e} ${o} issue${o===1?"":"s"}`+(t.failed.length?`, ${t.failed.length} failed`:"");return o?m(s,t):d(`${s}: ${t.failed.map(n=>`${n.ref} ${n.reason}`).join("; ")}`)},Oe=(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 ar=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 m("Found issue",{id:i.id,ref:A(i.id),title:C(i.title),description:i.props.description??"",createdAt:O(i.id),enteredLaneAt:ke(i.log??[],O(i.id)),parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===k,boardIds:Te(i),readonly:!!i.readonly,tags:ne(i),assignees:re(i),...Ne(i),...bs(i.id,e.allComments),...et(i.parentNodeId)})},Ts=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();async function lr(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!==k).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?m("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)}))):m("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:ke(i.log??[],O(i.id)),parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===k,boardIds:Te(i),readonly:!!i.readonly,tags:ne(i),assignees:re(i),...Ne(i)})))}var dr=async e=>{let t=await R(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=we(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(),...y(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(),...y(t.value.actor),action:"create.tag",payload:{id:T,name:h}}),u.push({id:K(),...y(t.value.actor),action:"add.issue.tag",payload:{id:f,tag:T}}),g.push({id:T,name:h})}let c=[];for(let v of e.assigneeNames??[]){let h=C(v).trim();if(!h||c.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(),...y(t.value.actor),action:"create.contributor",payload:{id:T,name:h}}),u.push({id:K(),...y(t.value.actor),action:"add.issue.assignee",payload:{id:f,assignee:T}}),c.push({id:T,name:h})}let I=w(u,t.value.boot.stateBranchRoot);return l(I)?d(I.message):m("Created issue",{id:f,ref:A(f),title:o,parentId:e.parentId,description:s,tags:g,assignees:c,...et(e.parentId),...Ce(t.value.state.nodes[e.parentId]?.parentNodeId)})},ur=(e,t,o)=>{let s=N(e);if(l(s))return s;let n=me(k,e,{at:"end"},t,o);if(l(n))return n;let a={id:K(),...y(t),action:"close.issue",payload:{id:e,parent:k,rank:n.value}},r=w([a],o);return l(r)?d(r.message):m("Closed issue",{id:e,ref:A(e)})};async function cr(e){let t=await L(e.repoRoot);if(l(t))return t;let o=W();if(l(o))return o;let s=Pe(e);if(l(s))return s;let n=a=>ur(a,o.value,t.value.stateBranchRoot);return e.issueIds?Ie("Closed",Oe(s.value,n)):n(s.value[0])}var mr=async e=>{let t=await R(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!==k)return d("Issue is not closed");let s=Xo(o);if(!s)return d("Unable to resolve previous parent from issue history");if(s===k)return d("Previous parent resolves to closed swimlane");let n=j(s);if(l(n))return n;let a=n.value,r=me(a.id,o.id,{at:"end"},t.value.actor,t.value.boot.stateBranchRoot);if(l(r))return r;let i={id:K(),...y(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):m("Reopened issue",{id:o.id,ref:A(o.id),parentId:a.id})},pr=(e,t,o,s)=>{let n=N(e);if(l(n))return n;let a=j(t.parentId);if(l(a))return a;let r=me(t.parentId,e,t.position??{at:"end"},o,s);if(l(r))return r;let i={id:K(),...y(o),action:"move.node",payload:{id:e,parent:t.parentId,rank:r.value}},u=w([i],s);return l(u)?d(u.message):m("Moved issue",{id:e,ref:A(e),parentId:t.parentId})};async function fr(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=ue(s.value);if(l(n))return n;let a=pe(n.value.events,n.value.unreadable);if(l(a))return a;let r=Pe(e);if(l(r))return r;let i=(()=>{let g=B();if(l(g))return()=>({});let{nodes:c}=g.value,I=p=>p?c[p]?.parentNodeId:void 0,v=I(e.parentId),h=r.value.some(p=>I(c[p]?.parentNodeId)!==v);return()=>({...et(e.parentId),...h?Ce(v):{}})})(),u=g=>pr(g,e,o.value,s.value);if(!e.issueIds){let g=u(r.value[0]);return l(g)?g:m(g.message,{...g.value,...i()})}let f=Ie("Moved",Oe(r.value,u));return l(f)?f:m(f.message,{...f.value,...i()})}var gr=e=>{let t=B();if(l(t))return t;let o=t.value.nodes[e];return o?m("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")},Ir=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(e.issueId);return l(o)?o:Be({node:o.value,label:"Issue description",max:2e4,description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},vr=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(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 m("No changes made",{id:e.issueId,ref:A(e.issueId),title:n});let r={id:K(),...y(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):m("Edited issue title",{id:e.issueId,ref:A(e.issueId),title:n})};import{ulid as Z}from"ulid";var hr=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,...ge(n.id),goals:tt(n.id)}));return m("Listed boards",s)},br=async e=>{let t=await R(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=we(o.id,t.value.actor,t.value.boot.stateBranchRoot);if(l(a))return a;let r=Z(),i={id:Z(),...y(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):m("Created board",{id:r,ref:A(r),title:s})},Rr=async e=>{let t=await R(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 m("No changes made",{id:e.boardId,ref:A(e.boardId),title:s});let a={id:Z(),...y(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):m("Edited board title",{id:e.boardId,ref:A(e.boardId),title:s})},yr=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===k,readonly:!!n.readonly,...ge(n.id),...U(n)?st(n):{},countsDone:He(n.id),doneByName:U(n)&&je(n)}));return m("Listed swimlanes",s)},Ar=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=xe(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=we(e.boardId,t.value.actor,t.value.boot.stateBranchRoot);if(l(a))return a;let r=Z(),i={id:Z(),...y(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):m("Created swimlane",{id:r,ref:A(r),title:s,boardId:e.boardId})},Tr=async e=>{let t=await R(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 m("No changes made",{id:e.swimlaneId,ref:A(e.swimlaneId),title:n});let r={id:Z(),...y(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):m("Edited swimlane title",{id:e.swimlaneId,ref:A(e.swimlaneId),title:n})},Sr=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=ue(s.value);if(l(n))return n;let a=pe(n.value.events,n.value.unreadable);if(l(a))return a;let r=j(e.swimlaneId);if(l(r))return r;let i=xe(e.boardId);if(l(i))return i;let u=me(e.boardId,e.swimlaneId,e.position??{at:"end"},o.value,s.value);if(l(u))return u;let f={id:Z(),...y(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):m("Moved swimlane",{id:e.swimlaneId,ref:A(e.swimlaneId),boardId:e.boardId})},wr=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=j(e.swimlaneId);if(l(o))return o;let s={id:Z(),...y(t.value.actor),action:"delete.node",payload:{id:e.swimlaneId}},n=w([s],t.value.boot.stateBranchRoot);return l(n)?d(n.message):m("Deleted swimlane",{id:e.swimlaneId,ref:A(e.swimlaneId)})};var V=e=>({path:e.path,sha:e.shas[e.shas.length-1]??""});var Er=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=>Er(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:[["/*","*/"]]},H={line:["#"],block:[]},Mt={line:["--"],block:[]},ve={line:[],block:[["<!--","-->"]]},xr={line:[],block:[]},S=(e,t)=>({name:e,comment:t}),rt=S("TypeScript",P),it=S("JavaScript",P),Es={ts:rt,tsx:rt,mts:rt,cts:rt,js:it,jsx:it,mjs:it,cjs:it,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",Mt),hs:S("Haskell",Mt),sql:S("SQL",Mt),ex:S("Elixir",H),exs:S("Elixir",H),pl:S("Perl",H),r:S("R",H),jl:S("Julia",H),sh:S("Shell",H),bash:S("Shell",H),zsh:S("Shell",H),vue:S("Vue",ve),svelte:S("Svelte",ve),html:S("HTML",ve),xml:S("XML",ve),md:S("Markdown",ve),mdx:S("Markdown",ve),css:S("CSS",{line:[],block:[["/*","*/"]]}),scss:S("CSS",P),less:S("CSS",P),yml:S("YAML",H),yaml:S("YAML",H),toml:S("TOML",H),ini:S("INI",H),json:S("JSON",xr)},Cr="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??Cr,Me=e=>Es[xs(e)]?.comment??null,Br=[/\.(test|spec)\.[a-z0-9]+$/i,/(^|\/)test_[^/]+\.py$/,/_test\.[a-z0-9]+$/i,/(^|\/)conftest\.py$/,/Tests?\.(java|kt|cs|scala)$/],Lr=/(^|\/)(tests?|__tests__|spec|specs|e2e|src\/test|features)\//i,he=e=>Lr.test(e)||Br.some(t=>t.test(e)),Nr=/(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|Cargo\.lock|go\.sum|poetry\.lock|Gemfile\.lock|composer\.lock)$/,kr=/(^|\/)(node_modules|dist|build|out|target|vendor|coverage|\.next|__snapshots__)\//,Pr=/(\.min\.(js|css)|\.map|\.snap|\.pb\.go|_pb2\.py)$/,X=e=>Nr.test(e)||kr.test(e)||Pr.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),Or=/\b(it|test|describe|context|suite)\.skip\b|\bx(it|describe|test)\s*\(|@pytest\.mark\.skip|@unittest\.skip|\bt\.Skip\s*\(|@(Ignore|Disabled)\b/,Mr=/\b(it|test|describe|context|suite)\.only\b|\bf(it|describe|test)\s*\(/,Ns=e=>Or.test(e),ks=e=>Mr.test(e);var Ps=/\b(TODO|FIXME|HACK|XXX)\b/,Dr=/[;{}]\s*$|^\s*(const|let|var|function|def|class|if|for|while|return|import|export|await|print)\b.*[=(]/,Dt=(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"},Fr=(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 c=Me(g.path);if(!c||c.line.length===0&&c.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=Dt(h,c);if(Ps.test(h)&&r++,p==="blank"){a++;continue}if(p==="comment"){s++,v.comment++,c&&Dr.test(Fr(h,c))&&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,c])=>({name:g,commentLines:c.comment,codeLines:c.code,share:c.comment+c.code===0?0:c.comment/(c.comment+c.code),repoShare:t?.get(g)??null})).sort((g,c)=>c.commentLines+c.codeLines-(g.commentLines+g.codeLines)),commentLines:s,codeLines:n,blankLines:a,share:f===0?0:s/f,todoLinesAdded:r,todoLinesRemoved:i,commentedOutCodeLines:u}};var _r=/\bconsole\.(log|debug|dir)\s*\(|\bdebugger\b|^\s*print\s*\(|\bfmt\.Print(ln|f)?\s*\(|\bSystem\.out\.print|\bdbg!\s*\(/,at=6,Ft=10,Gr=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)},$r=(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)},Wr=e=>{if(e.length<at*2)return 0;let t=new Map,o=new Array(e.length).fill(!1);for(let s=0;s+at<=e.length;s++){let n=e.slice(s,s+at);if(n.some(i=>i.text.length<3))continue;let a=n.map(i=>i.text).join(`
7
+ `),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<at;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 c=g.added.map(h=>h.text),I=Gr(c),v=g.status!=="deleted";for(let h of c){_r.test(h)&&a++;let p=$r(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,Ft),dependencyManifests:o.slice(0,Ft),buildOrCiPaths:s.slice(0,Ft),docsTouched:n,debugPrintLinesAdded:a,maxIndentLevels:r,deepestFile:i,duplicatedLines:Wr(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,he(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 jr=200,_t=2e5,Hr=5e4,Ur=25,Fs=64*1024*1024,Gt="",zr=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/,Kr=/^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",Xr=()=>({byPath:new Map,insertions:0,deletions:0,selfChurn:0,retainedLines:0}),qr=(e,t)=>{let o=e.byPath,s="",n=null,a=null,r=null,i=!1,u=0,f=(c,I)=>I==="modified"&&c==="added"?"added":I,g=(c,I)=>{let v=o.get(c);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:c,status:I,binary:!1,added:[],addedCount:0,removed:0,removedLines:[],shas:[s]},pendingByText:new Map};return o.set(c,p),p};for(let c of t.split(`
8
+ `)){if(c.startsWith(Gt)){s=c.slice(Gt.length).trim(),n=null,a=null,r=null,i=!1;continue}if(c.startsWith("diff --git ")){n=null,r=null,i=!0,a=Kr.exec(c)?.[1]??null;continue}if(i&&c.startsWith("Binary files ")&&a){let[,v=""]=/^Binary files (.*) differ$/.exec(c)??[],[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&&c.startsWith("--- ")){r=_s(c.slice(4),"a/");continue}if(i&&c.startsWith("+++ ")){let v=_s(c.slice(4),"b/"),h=v??r??a;h&&(n=g(h,Gs(r,v)));continue}let I=zr.exec(c);if(I){u=Number(I[1]),i=!1;continue}if(n){if(c.startsWith("+")){let v=c.slice(1);e.insertions++,n.entry.addedCount++,e.retainedLines<_t&&(n.entry.added.push({sha:s,line:u,text:v}),e.retainedLines++),n.pendingByText.size<Hr&&n.pendingByText.set(v,(n.pendingByText.get(v)??0)+1),u++;continue}if(c.startsWith("-")){let v=c.slice(1);e.deletions++,n.entry.removed++,e.retainedLines<_t&&(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))}}}},Vr=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 m("No commits to scan",{files:[],insertions:0,deletions:0,selfChurn:0,scannedCommits:0,truncated:!1});let s=t.slice(0,jr).reverse(),n=Xr(),a=0,r=0,i=!1,u=[];for(let g of s){let c=o(g),I=u[u.length-1];I&&I.cwd===c&&I.shas.length<Ur?I.shas.push(g):u.push({cwd:c,shas:[g]})}for(let{cwd:g,shas:c}of u){let I=await _e({cwd:g,maxOutput:Math.max(1,Fs-a),keepPartial:!0,args:["-c","core.quotePath=false","show","--unified=0","--no-renames","--no-color",`--format=${Gt}%H`,...c]});if(l(I)){if(g!==e)continue;return d(I.message)}if(qr(n,I.value.stdout),a+=I.value.stdout.length,r+=c.length,I.value.truncated||a>Fs){i=!0;break}}let f=Vr(n);return m("Scanned ticket patch",{files:f.files,insertions:f.insertions,deletions:f.deletions,selfChurn:f.selfChurn,scannedCommits:r,truncated:i||r<t.length||f.retainedLines>=_t})};var Yr=40,Jr=/^\d{6} blob ([0-9a-f]{40})\t(.+)$/,Ws=async({repoRoot:e,sha:t})=>{let o=await Ge({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(`
9
+ `)){let c=Jr.exec(g);if(!c)continue;let[,I="",v=""]=c;if(X(v))continue;let h=ae(v);if(s.add(h),he(v)||!Me(v))continue;let p=n.get(h)??[];p.length<Yr&&(p.push({blob:I,path:v}),n.set(h,p))}let a=[...n.values()].flat(),r=await jt(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:c}of a){let I=i.get(g);if(I===void 0)continue;let v=Me(c),h=ae(c),p=u.get(h)??{comment:0,code:0};for(let b of I.split(`
10
+ `)){let T=Dt(b,v);T==="comment"&&p.comment++,T==="code"&&p.code++}u.set(h,p)}let f=new Map;for(let[g,c]of u){let I=c.comment+c.code;I>0&&f.set(g,c.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))&&he(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)Ns(u)&&a++,ks(u)&&r++}return{testLinesAdded:t,testLinesRemoved:o,addedTestFiles:s,deletedTestFiles:n,skippedTestLinesAdded:a,focusedTestLinesAdded:r}};var Qr=e=>e.reduce((t,o)=>t===null||o.time<t.time?o:t,null),Hs=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(c=>[c.sha,c.repo])),r=c=>n(a.get(c))??e,i=await $s({repoRoot:e,shas:o.map(c=>c.sha),cwdOf:r});if(l(i))return d(i.message);let u=i.value,f=Qr(o),g=f?await Ws({repoRoot:r(f.sha),sha:f.sha}):null;return m("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 lt=e=>{if(l(e))return e;let t=Ve(),o=l(t)?{}:t.value.emailLinks,s=l(t)?{}:t.value.contributors,n=so(o),a=e.value.map(r=>({...r,authorIdentity:qo({authorName:r.author,authorEmail:r.authorEmail,owners:n,registry:s})}));return m(e.message,a)};var ei=32,De=new Map;var ti=(e,t)=>{if(De.set(e,t),De.size>ei){let o=De.keys().next();o.done||De.delete(o.value)}return t},Us=e=>{let t=lt(e);return l(t)?d(t.message):m("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=De.get(s);if(n)return m("Derived issue stats",n);let a=await Hs({repoRoot:e,ref:t,commits:o});return l(a)?d(a.message):m("Derived issue stats",ti(s,a.value))},Lc=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=Us(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=Us(await Ke({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=de(e);return o?m("Found goal",{id:o.id,refs:po(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})},oi=async e=>{let t=qs(e.goal);return l(t)?t:_o(e.repoRoot,lt(await Ke({repoRoot:e.repoRoot,refs:t.value.refs,end:e.end})))},si=async e=>{let t=await L(e.repoRoot);return l(t)?t:Vs({repoRoot:t.value.repoRoot,goal:e.goal})};import{ulid as be}from"ulid";async function ni(e){let t=await L(e.repoRoot);if(l(t))return t;let o=W();if(l(o))return o;let s=Pe(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=Oe(s.value,N);if(!e.issueIds&&r.failed[0])return d(r.failed[0].reason);if(r.done.length===0)return d(Ie("Tagged",r).message);let i=_.findTagByName(n),u=i?.id??be(),f=[...i?[]:[{id:be(),...y(o.value),action:"create.tag",payload:{id:u,name:n}}],...r.done.map(({id:v})=>({id:be(),...y(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 c={id:u,name:n};if(!e.issueIds)return m("Added issue tag",{...r.done[0],tag:c});let I=Ie("Tagged",r);return l(I)?I:m(I.message,{...I.value,tag:c})}var ri=async e=>{let t=await R(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:be(),...y(t.value.actor),action:"tombstone.tag",payload:{id:e.tagId}}],n=w(s,t.value.boot.stateBranchRoot);return l(n)?d(n.message):m("Deleted tag",{id:o.id,name:o.name})},ii=async e=>{let t=await R(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:be(),...y(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):m("Restored tag",{id:o.id,name:o.name})},ai=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(e.issueId);if(l(o))return o;if(!t.value.state.tags[e.tagId])return d("Tag not found");let s={id:be(),...y(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):m("Removed issue tag",{id:e.issueId,ref:A(e.issueId),tagId:e.tagId})};import{ulid as J}from"ulid";var li=async e=>{let t=Wt(e.name,"name");if(l(t))return d(t.message);let o=await R(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(),...y(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}=Ce(r.id);return i?[{id:r.id,title:C(r.title),boardDescription:i}]:[]});return m(`Assumed ${s.userName}`,{...s,registered:!n,...a.length?{boards:a}:{}})},Ys=async(e,t)=>{let o=ce(e).get(t);return o===void 0?void 0:{id:t,name:o}},di=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(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(),...y(t.value.actor),action:"create.contributor",payload:{id:p.id,name:p.name}}],{id:J(),...y(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):m("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=Tt({events:t.value.state.eventLog??[],registry:t.value.state.contributors,logFileNames:ce(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,c=[...!!t.value.state.contributors[u]?[]:[{id:J(),...y(t.value.actor),action:"create.contributor",payload:{id:u,name:f}}],{id:J(),...y(t.value.actor),action:"add.issue.assignee",payload:{id:e.issueId,assignee:u}}],I=w(c,t.value.boot.stateBranchRoot);return l(I)?d(I.message):m("Added issue assignee",{id:e.issueId,ref:A(e.issueId),assignee:{id:u,name:f}})},ui=async e=>{let t=await R(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(),...y(t.value.actor),action:"tombstone.contributor",payload:{id:e.contributorId}}],a=w(n,t.value.boot.stateBranchRoot);return l(a)?d(a.message):m("Tombstoned contributor",{id:e.contributorId,name:We})},ci=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},mi=async e=>{let t=await R(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 ci(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(),...y(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):m("Restored contributor",{id:e.contributorId,name:s})},pi=async(e={})=>{let t=await R(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=Tt({events:s,registry:r,logFileNames:ce(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 m("Listed board contributors",i)},fi=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(e.issueId);if(l(o))return o;if(!t.value.state.contributors[e.assigneeId])return d("Assignee not found");let s={id:J(),...y(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):m("Removed issue assignee",{id:e.issueId,ref:A(e.issueId),assigneeId:e.assigneeId})};import{ulid as ut}from"ulid";var gi=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=N(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=ut(),a={id:ut(),...y(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):m("Added issue comment",{id:n,issueId:e.issueId,body:s})},Ii=async e=>{let t=await R(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=N(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 m("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let a={id:ut(),...y(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):m("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},vi=async e=>{let t=await R(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=N(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:ut(),...y(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):m("Edited issue comment",{id:e.commentId,issueId:o.payload.issue,body:a})};import{ulid as Js}from"ulid";var hi=async e=>{let t=await R(e.repoRoot);if(l(t))return t;if(!eo(e.email))return d(`Not an email address: ${e.email}`);let o=Ae(e.email),s=e.contributorId??t.value.actor.userId;if(!t.value.state.contributors[s])return d(`Unknown contributor: ${s}`);let n=mt(t.value.state.emailLinks,o);if(n.includes(s))return m(`${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):m(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})},bi=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let o=Ae(e.email),s=e.contributorId??t.value.actor.userId,n=t.value.state.emailLinks[to(o,s)];if(!n||n.tombstoned)return d(`No such link: ${o} to ${s}`);if(!no(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):m(`Unclaimed ${o}`,{contributor:s,email:o})},Ri=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 c of Object.values(s)){if(c.tombstoned)continue;let I=a.get(c.email)??new Set;I.add(c.contributor),a.set(c.email,I)}let r=[...a.entries()].map(([c,I])=>({email:c,contested:I.size>1,claimants:[...I].map(v=>D(v,n[v]?.name))})).sort((c,I)=>c.email.localeCompare(I.email)),i=W(),u=l(i)?[]:oo(s,i.value.userId),f=Ut().gitEmail,g=f?mt(s,f).filter(c=>l(i)||c!==i.value.userId):[];return m("Listed contributor emails",{emails:r,mine:u,git:f?{email:f,linkedToMe:u.includes(f),heldByOthers:g.map(c=>D(c,n[c]?.name))}:null})},yi=async(e={})=>{let t=await R(e.repoRoot);if(l(t))return t;let{userId:o,userName:s}=t.value.actor,n=le(t.value.boot.repoRoot),a=await qe({repoRoot:t.value.boot.repoRoot,stateBranch:l(n)?void 0:n.value,names:[s,await fe(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 m(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 $t=e=>{let t=No(e);return l(t)?d(t.message):m("Listed repos",{repos:t.value,claimedBytes:Do(e),limit:Xt,allowLocal:Kt()})},Ai=async(e={})=>{let t=Se(e.repoRoot);return l(t)?d(t.message):$t(t.value)},Ti=async e=>{let t=await R(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=$t(o);return l(n)?d(n.message):m(s.message,{...n.value,...s.value.kind==="preview"?{preview:s.value.preview}:{}})},Si=async e=>{let t=await R(e.repoRoot);if(l(t))return t;let{repoRoot:o}=t.value.boot,s=ko({repoRoot:o,actorId:t.value.actor.userId,repo:e.repo});if(l(s))return d(s.message);let n=$t(o);return l(n)?d(n.message):m(s.message,n.value)},wi=e=>(Mo("repo"in e?e.repo:qt(e.url.trim())),m("Cancelled",null)),Ei=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?m(`${e.message} \xB7 still fetching other repos; epiq_repo_list shows how they stand`,e.value):l(n)||n.value.length===0?e:m([e.message,Oo(n.value)].filter(Boolean).join(" \xB7 "),{...e.value,repos:n.value})},Qs=async(e={})=>{let t=Se(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=Qt(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 xi=async(e={})=>{let t=await R(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 qe({repoRoot:t.value.boot.repoRoot,stateBranch:l(a)?void 0:a.value,names:[s,await fe(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 m("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 Ci=8,Bi=(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()})},Li=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:Nt(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(ye(x,n),n)},c=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(Re=>Re.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((Re,rn)=>i(Re.laneId)?[{laneId:Re.laneId,ms:x[rn+1].enteredAt-Re.enteredAt}]:[]);return[{closedAt:G,leadTime:G-E.createdAt,sentBack:c(x),stays:nn}]}),v=Bi(n,Ci),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:Li(p.map(E=>E.leadTime)),sentBackShare:p.length===0?null:p.filter(E=>E.sentBack).length/p.length,laneTime:on}};var Ni=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=>U(r)&&r.parentNodeId===s.id),a=n.filter(r=>!r.isDeleted).sort((r,i)=>r.rank.localeCompare(i.rank));return m("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{Nt as a,us as b,z as c,ra as d,xn as e,ia as f,aa as g,fs as h,fe as i,B as j,L as k,kn as l,Pn as m,On as n,Mn as o,Dn as p,vs as q,Fn as r,_n as s,$n as t,Un as u,zn as v,Kn as w,tr as x,sr as y,kt as z,rr as A,ir as B,ar as C,lr as D,dr as E,cr as F,mr as G,fr as H,gr as I,Ir as J,vr as K,hr as L,br as M,Rr as N,yr as O,Ar as P,Tr as Q,Sr as R,wr as S,lt as T,Lc as U,Vs as V,oi as W,si as X,ni as Y,ri as Z,ii as _,ai as $,li as aa,di as ba,ui as ca,mi as da,pi as ea,fi as fa,gi as ga,Ii as ha,vi as ia,hi as ja,bi as ka,Ri as la,yi as ma,xi as na,Ai as oa,Ti as pa,Si as qa,wi as ra,Ei as sa,Qs as ta,en as ua,Ni as va};