epiq 1.4.0 → 1.4.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.
package/dist/gui/main.js CHANGED
@@ -25305,7 +25305,7 @@ var User = ({
25305
25305
  );
25306
25306
 
25307
25307
  // source/version.ts
25308
- var EPIQ_VERSION = "1.4.0";
25308
+ var EPIQ_VERSION = "1.4.1";
25309
25309
 
25310
25310
  // source/gui/client/components/Header.tsx
25311
25311
  var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
package/dist/index.js CHANGED
@@ -57,7 +57,7 @@ ${c}
57
57
  `,Ni.writeFileSync(t,n,"utf8"),se.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),u("Local epiq paths ignored",!0)};var hv=async e=>{let t=await F({cwd:e,args:["status","--porcelain"]});return d(t)?t:u("Checked git diff",t.value.stdout.trim().length>0)},ne=(e,t)=>a(`[${e}] ${t}`),Zc=async()=>{V("");let e=Sn(),t=await gt(process.cwd());if(d(t))return ne(1,t.message);let n=t.value,r=await jr(n);if(d(r))return ne(2,r.message);if(r.value)return ne(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await hv(n);if(d(o))return ne(2.5,o.message);if(o.value)return ne(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(Bs(n))return ne(4,"Epiq project already initialized");let s=Vt();if(!s.isSetupDone||!s.userName)return ne(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=K(),c=i.userName,l=i.userId;if(!l||!c)return ne(5,"Missing Epiq user id");let m=e.stateBranch,p=await Vr({repoRoot:n,branch:m});if(d(p))return ne(6,p.message);if(p.value)return ne(6,`State branch already exists: ${m}`);let f=await Hs({repoRoot:n,stateBranchName:m});if(d(f))return ne(6,f.message);let g=zr();if(d(g))return ne(7,g.message);let I=Qc.join(Kr(),e.projectId),S=await cn({repoRoot:n,stateBranchRoot:I,stateBranchName:m});if(d(S))return ne(8,S.message);let R=Qc.join(I,".epiq");yv.mkdirSync(R,{recursive:!0});let A=Md({userId:l,userName:c});if(d(A))return ne(9,A.message);for(let Ss of A.value){let ra=mo({event:Ss,rootDir:I});if(d(ra))return ne(9,ra.message)}let P=await Jr({stateBranchRoot:I,eventFileName:un({userId:l,userName:c})});if(d(P))return ne(10,P.message);let _=await Nn({cwd:I,message:"[epiq:init]"});if(d(_))return ne(10,_.message);let w=await Jc(n);if(d(w))return ne(11,w.message);let W=sa({repoRoot:n,fileContents:e});if(d(W))return ne(12,W.message);let H=await le.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d(H))return ne(13,H.message);let D=await le.commit({cwd:n,message:"[epiq:init-project]"});if(d(D))return ne(13,D.message);let $="Project initialized!",Ye=await F({cwd:n,args:["push","-u","origin","HEAD"]});d(Ye)&&($+=` Warn: [init:14] ${Ye.message}`);let we=await sr({repoRoot:n,stateBranchRoot:I});d(we)&&($+=` Warn: [init:15] ${we.message}`);let ge=st(A.value).filter(d);if(ge.length>0)return ne(16,ge.map(Ss=>Ss.message).join(`
58
58
  `));let me=We();if(d(me))return ne(16,me.message);let{rootNodeId:Gn,nodes:Kn}=me.value,na=Kn[Gn];return na?(M.navigate({contextNode:na,selectedIndex:0}),C({hasProjectDefinition:!0,mode:y.DEFAULT}),u($,null)):ne(16,"Unable to resolve initialized root node")};import{ulid as bv}from"ulid";import{ulid as xv}from"ulid";var el=null,Zt=()=>structuredClone(el),Cr=e=>{el=e},tl=()=>{let{contextNode:e,selectedIndex:t}=v(),r=Y(e.id)[t];return r?u("Resolved selected child",r):a("Target node not found")},Ri=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Y(t).filter(o=>o.id!==e);return po(r,n)},nl=({id:e,parentId:t,position:n={at:"end"}})=>{let r=ie();if(d(r))return a("Unable to resolve user ID");let o=Ri({parentId:t,id:e,position:n});return d(o)?o:u("Created pending move state",{id:xv(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},rl=e=>{Cr(e);let t=jt(e,!0);return d(t)?t:u("Node moved successfully",t.value)};function Ai(e){let t=tl();if(d(t))return t;let{contextNode:n,nodes:r}=v();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=Y(o.id),i=s.findIndex(({id:m})=>m===n.id);if(i<0)return a("Current node not found among siblings");let c=s[i+e];if(!c)return a("Missing sibling node");let l=nl({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(l)?l:rl(l.value)}function Ti(e){let t=tl();if(d(t))return t;let{contextNode:n,selectedIndex:r}=v(),s=Y(n.id)[r+e];if(!s)return a("Missing sibling node");let i=nl({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:rl(i.value)}var ol=()=>{let e=Zt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=v().nodes[n];if(!r)return a("Move parent not found");let o=Y(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(M.navigate({contextNode:r,selectedIndex:o}),u("Synchronized navigation to moved node",null))},Ho=(e,t="Moved preview")=>{if(d(e))return e;let n=ol();return d(n)?n:(C({mode:y.MOVE}),u(t,null))},sl=async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=X().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=Y(n.id)[r];if(!o)return C({mode:y.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let s=Y(o.parentNodeId),i=s.findIndex(({id:f})=>f===o.id);if(i===-1)return a("Target not found among siblings");let c=s[i-1],l=s[i+1],m=l!=null?{at:"before",sibling:l.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=Ri({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(Cr({id:bv(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),C({mode:y.MOVE}),u("Move initialized",null))}if(t==="next")return Ho(Ti(1));if(t==="previous")return Ho(Ti(-1));if(t==="to-next")return Ho(Ai(1));if(t==="to-previous")return Ho(Ai(-1));if(t==="confirm"){let s=Zt();if(!s)return a("No pending move to confirm");let i=await yt();if(d(i))return i;let c=U([s],i.value);if(d(c))return c;let l=ol();return d(l)?l:(Cr(null),C({mode:y.DEFAULT}),u("Moved item",null))}return t==="cancel"?(Cr(null),C({mode:y.DEFAULT}),u("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Wo}from"ulid";import{monotonicFactory as Iv,ulid as Ev}from"ulid";var Sv=Iv(),jo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Sv();return u("Created issue events",[{id:Ev(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var il=async(e,t)=>{let n=ie();if(d(n))return a("Unable to resolve user ID");let r=await yt();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=v(),l=m=>{let p=U([m],o);if(d(p))return p;let f=E.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let g=E.getNode(f.parentNodeId);return g?(M.navigate({contextNode:g,selectedIndex:E.getSiblings(f.parentNodeId).findIndex(({id:I})=>I===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),p=E.getNode(m);if(!p)return a("Workspace not found");let f=Pn(p.id,n.value,o);return d(f)?f:l({id:Wo(),action:"add.board",payload:{id:Wo(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Ue(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Pn(m.value.id,n.value,o);return d(p)?p:l({id:Wo(),action:"add.swimlane",payload:{id:Wo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=z(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let _=Ue(s,"SWIMLANE");return d(_)?null:_.value})();if(!p)return a("Unable to add issue in this context");let f=Pn(p.id,n.value,o);if(d(f))return f;let g=jo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(g))return g;let I=g.value,S=U([...I],o);if(d(S))return S;if(!S.value[0])return a("Issue creation failed");let P=I.find(_=>_.action==="add.issue")?.payload.id;return P?(M.navigate({contextNode:p,selectedIndex:E.getSiblings(p.id).findIndex(({id:_})=>_===P)}),u("Issue created",null)):a("Unable to determine ticket id")}return u("Success",null)};var Vo=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=v(),s=uo(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,l=it();if(d(l))return l;let p=st(i).filter(d);if(p.length>0)return it(),C(o),a(p.map(g=>g.message).join(", "));let f=v().nodes[e];return f?(M.navigate({contextNode:f,selectedIndex:r}),u("",{unappliedEvents:c})):(it(),C(o),a("Board did not exist at that date"))};var Cv=20,Nv=16,Rv=150,Go=null,Ko=null;var bn=()=>{Go!==null&&(clearInterval(Go),Go=null),Ko!==null&&(clearTimeout(Ko),Ko=null)},al=()=>{bn(),C({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Av=e=>{let t=[],n=0;for(let o=0;o<e.length;o++){let s=o===0?0:Math.max(0,e[o]-e[o-1]);n+=Math.sqrt(s),t[o]=n}let r=n;return t.map((o,s)=>r>0?o/r:(s+1)/e.length)},dl=({events:e,startTime:t,durationMs:n})=>{bn();let r=e.length,o=e.map(f=>zt(f)??t),s=o[r-1]??Date.now(),i=Av(o),c=Math.max(1,Math.round(n*Cv/1e3)),l=Math.max(Math.round(n/c),Nv),m=0,p=0;C({mode:y.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),Go=setInterval(()=>{m++;let f=m/c,g=[],I;for(;p<r&&i[p]<=f;){let R=e[p],A=jt(R);if(d(A)){al();return}g.push(...qs(R)),I=R,p++}if(p>=r||m>=c){for(;p<r;p++){let A=jt(e[p]);if(d(A))break}let R=v().replay;C({unappliedEvents:[],replay:R&&{...R,progress:1,appliedCount:r}}),bn(),Ko=setTimeout(al,Rv);return}let S=v().replay;C({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:I?zt(I)??S?.currentTime??t:S?.currentTime??t,currentLabel:I?cd(I):S?.currentLabel??"",flashNodeIds:I?[...new Set(g)]:S?.flashNodeIds??[]}})},l)};var cl=async()=>{let e=Ue(v().breadCrumb,"BOARD");if(d(e))return e;let t=await gt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Re({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=X().commandMeta;if(bn(),r==="now"){let c=je(n.value);if(d(c))return a(c.message);let l=it();if(d(l))return l;let p=st(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(C({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),u("Peeking now",!0))}let s;if(r==="prev"){let c=v().eventLog.at(-1),l=zt(c);if(l===null)return a("No previous event to peek");s=l}else if(r==="next"){let c=v().unappliedEvents.at(0),l=zt(c);if(l===null)return a("No next event to peek");s=l+1}else{let c=gn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Vo({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(C({mode:y.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),u("Peeking",!0))};var ll=async()=>{let e=Ue(v().breadCrumb,"BOARD");if(d(e))return e;let t=await gt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Re({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=X().commandMeta,{dateInput:s,durationInput:i}=Eo(r,o);if(bn(),v().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=gn(s);if(!c)return a("Invalid replay date");let l=i?Io(i):15e3;if(l===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=v(),f=Vo({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:g}=f.value;return g.length===0?(it(),C(p),u("Nothing to replay from that point",!0)):(dl({events:g,startTime:m,durationMs:l}),u("Replaying board history",!0))};import wv from"zod";var ul=()=>{let e=X().commandMeta.inputString,t=wv.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=Qe({autoSyncDebounceMs:t.data});return d(n)?n:(Me({autoSyncIntervalMs:t.data}),C({mode:y.DEFAULT}),u(`Auto sync interval set to ${t.data}ms`,null))};var ml=()=>{let e=X().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=Ud(e),n=Qe({autoSync:t});return d(n)?n:(Me({autoSync:t}),C({mode:y.DEFAULT}),u(`Auto sync set to "${e}"`,null))};var pl=()=>{let e=X().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Qe({logLevel:e});return d(n)?n:(Me({logLevel:e}),C({mode:y.DEFAULT}),u(`Auto sync set to "${e}"`,null))};import{spawn as Mv}from"node:child_process";var Pv=()=>{switch(process.platform){case"darwin":return{command:"pbcopy",args:[]};case"win32":return{command:"clip",args:[]};default:return process.env.WAYLAND_DISPLAY?{command:"wl-copy",args:[]}:{command:"xclip",args:["-selection","clipboard"]}}},fl=async e=>new Promise(t=>{let{command:n,args:r}=Pv();try{let o=Mv(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?u("Copied to clipboard",null):a(`Clipboard tool failed (${n})`))),o.stdin.on("error",()=>{}),o.stdin.write(e),o.stdin.end()}catch{t(a(`Clipboard tool not available (${n})`))}});var Nr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await fl(e);return d(n)?n:u(`Copied ${t} to clipboard`,null)},gl=async e=>{let{breadCrumb:t,selectedNode:n}=v(),r=fr({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case ye.REF:return Nr(He(o.id),"ref");case ye.TITLE:return Nr(o.title,"title");case ye.DESCRIPTION:return r?Nr(r.props?.description??"","description"):a("No issue in scope");case ye.TAGS:{if(!r)return a("No issue in scope");let s=Gt(r).map(({name:i})=>i);return Nr(s.join(", "),"tags")}case ye.ASSIGNEES:{if(!r)return a("No issue in scope");let s=Kt(r).map(({name:i})=>i);return Nr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var vl=async()=>{V(""),C({mode:y.DEFAULT});let e=We();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");C({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await vo();return d(t)?(C({syncStatus:{msg:t.message,status:"failed"}}),t):(C({mode:y.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Lv=e=>e.action==="add.issue.comment",yl=e=>Object.values(v().tags).find(t=>t.name===e),hl=()=>{let{eventLog:e=[],contributors:t}=v(),n=new Map,r=new Set;for(let o of e)o.userId&&(n.set(o.userId,o.userName??""),r.add(o.userId));for(let o of Object.values(t)){if(o.tombstoned){n.set(o.id,o.name);continue}n.set(o.id,Fn(o.name,n.get(o.id))??o.name)}return[...n.entries()].map(([o,s])=>({id:o,name:s,isExternal:!r.has(o)}))},kt=async()=>{let e=await yt();return d(e)?e:u("Resolved persist root",e.value)},zo=[{systemOnly:!0,intent:k.Move,description:"Internal move-state command",mode:y.COMMAND_LINE,action:sl},{intent:k.Delete,description:"Delete the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await kt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=T(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=v().nodes[i];if(!c||!T(c))return a("Unable to resolve comment issue");let l=c.log?.filter(Lv).find(m=>m.payload.id===s);return l?l.payload.author!==e.value.userId?a("You can only delete your own comments"):U([{id:Be(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return U([{id:Be(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:y.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=X().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ae(b.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return pe(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:y.DEFAULT})),u("Filter updated",null)}},{intent:k.ViewHelp,description:"Open the help screen",mode:y.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return Qt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),C({mode:y.HELP}),u("Viewing help",null)}},{intent:k.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!T(r))return a("Cannot close in this context");let o=v().nodes[ve];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await kt();if(d(s))return s;let i=s.value,c=mn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let l=U([{id:Be(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(l)?l:u("Issue closed",null)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?u("Resolved ticket",r):At(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=v().nodes[ve];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!T(s))return a("Target node is not issue");let c=Oo(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let l=v().nodes[c];if(!l)return a("Previous parent no longer exists");let m=await kt();if(d(m))return m;let p=m.value,f=mn(l.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let g=U([{id:Be(),action:"reopen.issue",payload:{id:s.id,parent:l.id,rank:f.value},...e.value}],p);return d(g)?g:u("Issue reopened",null)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Init,description:"Initialize Epiq in the current git repository",mode:y.COMMAND_LINE,action:Zc},{intent:k.NewItem,description:"Create a new board, swimlane, or issue",mode:y.COMMAND_LINE,action:il,onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Rename,description:"Rename the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=z(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=vc();if(!o)return a("Provide a title");let s=await kt();return d(s)?s:U([{id:Be(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.UntagTicket,description:"Remove a tag from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=yl(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=v();if(!s)return a("Invalid untag target");let i=At(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!T(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(o.id))return a("Issue is not tagged with that tag");let m=await kt();return d(m)?m:U([{id:Be(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.TagTicket,description:"Add or create a tag on the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=v();if(!o)return a("Invalid tag target");let s=At(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!T(i))return a("Target node is not issue");let c=await kt();if(d(c))return c;let l=yl(r),m=l?.id??Be();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):U([...l?[]:[{id:Be(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:Be(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.AssignUserToTicket,description:"Assign a user to the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let o=r.startsWith("!"),s=(o?r.slice(1):r).trim();if(!s)return a("Provide an assignee");let{selectedIndex:i,contextNode:c}=v(),l=z(c.id)[i];if(!l)return a("Invalid assign target");let m=At(l.id,"TICKET");if(d(m))return a("Unable to assign issue in this context");let p=m.value;if(!T(p))return a("Target node is not issue");let f=await kt();if(d(f))return f;let g=hl(),I=!o&&s.toLowerCase()==="me",S,R;if(I)S=e.value.userId,R=g.find(_=>_.id===S)?.name??e.value.userName;else{let _=g.filter(W=>W.name===s);if(_.length>1)return a(`"${s}" matches ${_.length} contributors (${_.map(W=>W.id).join(", ")}). Assign from the GUI to choose by id.`);let w=_[0];if(!w&&!o)return a(`No contributor named "${s}". Use "!${s}" to add them as an external assignee.`);S=w?.id??Be(),R=w?.name??s}if((p.props.assignees??[]).includes(S))return a("Assignee already assigned");let P=!!v().contributors[S];return U([...P?[]:[{id:Be(),action:"create.contributor",payload:{id:S,name:R},...e.value}],{id:Be(),action:"add.issue.assignee",payload:{id:p.id,assignee:S},...e.value}],f.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=ie();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=X().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let{selectedNode:o}=v();if(!o)return a("Invalid unassign target");let s=At(o.id,"TICKET");if(d(s))return a("Unable to unassign in this context");let i=s.value;if(!T(i))return a("Target node is not issue");let c=i.props.assignees??[],l=r.toLowerCase()==="me",m=l?c.filter(g=>g===e.value.userId):hl().filter(g=>g.name===r&&c.includes(g.id)).map(g=>g.id);if(m.length>1)return a(`"${r}" matches ${m.length} assignees (${m.join(", ")}). Unassign from the GUI to choose by id.`);let p=m[0];if(!p)return a(l?"Issue is not assigned to you":`Issue is not assigned to "${r}"`);let f=await kt();return d(f)?f:U([{id:Be(),action:"remove.issue.assignee",payload:{id:i.id,assignee:p},...e.value}],f.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Comment,description:"Add a comment to the selected issue",mode:y.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>Dn)return a(`Cannot exceed ${Dn} characters`);let r=ie();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=v(),i=Ue([...o,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let l=c.context==="TICKET"?u("Resolved ticket",c):At(c.id,"TICKET");if(d(l))return a("Unable to comment on issue in this context");let m=l.value;if(!T(m))return a("Target node is not issue");let p=await kt();return d(p)?p:U([{id:Be(),action:"add.issue.comment",payload:{id:Be(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Sync,description:"Pull, commit, and push Epiq state",mode:y.COMMAND_LINE,action:vl},{intent:k.Peek,description:"View board state at another point in time",mode:y.COMMAND_LINE,action:cl},{intent:k.Replay,description:"Replay board history forward from a point in time",mode:y.COMMAND_LINE,action:ll},{intent:k.Export,description:"Export the current board layout to markdown",mode:y.COMMAND_LINE,action:async()=>{let e=await Hc();return d(e)?e:(C({mode:y.DEFAULT}),u("Export successful",!0))}},{intent:k.Exit,description:"Exit the application",mode:y.COMMAND_LINE,action:async()=>(M.exit(),u("Exit successful",!0))},{intent:k.Edit,description:"Edit title or description",mode:y.COMMAND_LINE,action:async(e,t)=>Xc(t),onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:y.COMMAND_LINE,action:async(e,t)=>gl(t),onSuccess:()=>C({mode:y.DEFAULT})},{intent:k.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:y.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case re.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??Be();if(!i||!c)return a("Unable to resolve user name or id");let l=Qe({userName:i,userId:c,preferredEditor:o??""});return d(l)?l:(Me({userName:i,userId:c}),C({mode:y.DEFAULT}),u(`Username set to "${i}"`,null))}case re.EDITOR:{if(!n)return a("No editor provided");let r=Qe({preferredEditor:n});return d(r)?r:(Me({preferredEditor:n}),C({mode:y.DEFAULT}),u(`Editor configuration set to "${n}"`,null))}case re.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Qe({viewMode:n});return d(r)?r:(Me({viewMode:n}),C({mode:y.DEFAULT}),u(`View set to "${n}"`,null))}case re.AUTOSYNC:return ml();case re.LOG_LEVEL:return pl();case re.SYNC_DEBOUNCE_MS:return ul();case re.ATTACHMENT_MAX_KB:return Xd();default:return a("Unknown config command")}}},{intent:k.Coffee,description:"Sponsor the development of Epiq!",mode:y.COMMAND_LINE,action:()=>{let e=X().commandMeta.modifier;return e==="custom"?Sr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Sr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),V(""),u("Thanks you!",null)}}];var kv=new Set(["peek","replay","filter","view-help","yank"]),St=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=X();if(!t)return a("No command to confirm");if(!e&&n===bt.Invalid)return a("Invalid command");let s=wo(t);uc();let{readOnly:i}=v();if(i&&!kv.has(s))return hr({status:Bt.Fail,message:"Command not available in readonly state",value:null});let c=zo.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return hr({status:Bt.Fail,message:"Command not found",value:null});let l;try{l=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return hr({status:Bt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(l)?hr(l):(mc({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&ho(),l)};var qo=[{intent:x.Exit,mode:y.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(C({mode:y.COMMAND_LINE}),V("move cancel"),St({isForceExecutedBySystem:!0}))},{intent:x.InitMove,mode:y.DEFAULT,description:"[m] move (init/confirm)",action:()=>(C({mode:y.COMMAND_LINE}),V("move start"),St({isForceExecutedBySystem:!0}))},{intent:x.ConfirmMove,mode:y.MOVE,action:()=>(C({mode:y.COMMAND_LINE}),V("move confirm"),St({isForceExecutedBySystem:!0}))}],Yo=[{intent:x.MovePreviousItem,mode:y.MOVE,action:()=>Zt()?(C({mode:y.COMMAND_LINE}),V("move previous"),St({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveNextItem,mode:y.MOVE,action:()=>Zt()?(C({mode:y.COMMAND_LINE}),V("move next"),St({isForceExecutedBySystem:!0})):a("No pending move")}],xl=[{intent:x.MoveToNextContainer,mode:y.MOVE,action:()=>Zt()?(C({mode:y.COMMAND_LINE}),V("move to-next"),St({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveToPreviousContainer,mode:y.MOVE,action:()=>Zt()?(C({mode:y.COMMAND_LINE}),V("move to-previous"),St({isForceExecutedBySystem:!0})):a("No pending move")}];var bl={[B.WORKSPACE]:[...qo,...Yo],[B.BOARD]:[...qo,...Yo],[B.SWIMLANE]:[...qo,...Yo,...xl],[B.TICKET]:[],[B.FIELD]:[],[B.FIELD_LIST]:[],[B.TEXT]:[],[B.COMMENT]:[]};import Dv from"node:fs";import Bv from"node:path";var Il=e=>{let t=_e(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Re({repoRoot:t.value});if(d(n))return a(n.message);let r=kn(e.hash,e.ext),o=Bv.join(nr(n.value),r);return Dv.existsSync(o)?(Sr(o),u(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var El=()=>{V("");let{pendingNavTarget:e}=Jt();C({mode:y.DEFAULT}),e&&M.navigate(e),Qt({pendingNavTarget:void 0})},Sl=[{intent:x.ExitCommandLine,mode:y.HELP,action:()=>(El(),u("Exiting help",null))},{intent:x.Exit,mode:y.HELP,action:()=>(El(),u("Closed help",null))},{intent:x.NavPreviousItem,mode:y.HELP,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),u("Navigating to previous help item",null))},{intent:x.NavNextItem,mode:y.HELP,action:()=>(M.navigateToNextItem(),u("Navigating to next help item",null))},{intent:x.NavToPreviousContainer,mode:y.HELP,action:()=>(M.navigateToPreviousContainer(),u("Navigating to previous help container",null))},{intent:x.NavToNextContainer,mode:y.HELP,action:()=>(M.navigateToNextContainer(),u("Navigating to next help container",null))}];var Fv=e=>{C({mode:y.COMMAND_LINE});let{pendingNavTarget:t}=Jt();t&&M.navigate(t),Qt({pendingNavTarget:void 0}),V(`${e} `)},Cl=()=>{V("");let{pendingNavTarget:e}=Jt();e&&M.navigate(e),Qt({pendingNavTarget:void 0}),C({mode:y.DEFAULT})},Nl=[{intent:x.InitCommandPalette,mode:y.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{V("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return Qt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),C({mode:y.PALETTE}),u("Opening command palette",null)}},{intent:x.Confirm,mode:y.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!Ot(e))return a("Command only applicable on text nodes");if(e.props.disabled)return a("Command is not available in this context");let t=e.title;return t?(Fv(t),u("Selected command",t)):u("No command selected",null)}},{intent:x.ExitCommandLine,mode:y.PALETTE,action:()=>(Cl(),u("Exiting palette",null))},{intent:x.Exit,mode:y.PALETTE,action:()=>(Cl(),u("Closed command palette",null))},{intent:x.NavPreviousItem,mode:y.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),u("Navigating to previous item",null))},{intent:x.NavNextItem,mode:y.PALETTE,action:()=>(M.navigateToNextItem(),u("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:y.PALETTE,action:()=>(M.navigateToPreviousContainer(),u("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:y.PALETTE,action:()=>(M.navigateToNextContainer(),u("Navigating to next container",null))}];var Rl=[...Sl,...Nl,{intent:x.AddItem,mode:y.DEFAULT,description:"[n] new...",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.NEW} `),u("Adding new item",null))},{intent:x.Delete,mode:y.DEFAULT,description:"[d] delete",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.DELETE} `),u("Deleting item",null))},{intent:x.InitCommandLine,mode:y.DEFAULT,description:"[:] focus command line",action:()=>(C({mode:y.COMMAND_LINE}),V(""),u("Entering command line mode",null))},{intent:x.Confirm,mode:y.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!Y(e?.id??"")?.length){let r=e?E.getAttachment(e.id):void 0;if(r)return Il(r);if(e?.title===Z.DESCRIPTION)return C({mode:y.COMMAND_LINE}),V(`${b.EDIT} description `),u("Propose command",!0);if(e?.title===Z.ASSIGNEES)return C({mode:y.COMMAND_LINE}),V(`${b.ASSIGN} `),u("Propose command",!0);if(e?.title===Z.TAGS)return C({mode:y.COMMAND_LINE}),V(`${b.TAG} `),u("Propose command",!0);if(t.title===Z.DESCRIPTION&&e?.context==="TEXT")return C({mode:y.COMMAND_LINE}),V(`${b.EDIT} description `),u("Propose command",!0)}return M.enterChildNode(),u("Entering context",null)}},{intent:x.Yank,mode:y.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=v(),t=e?.title===Z.DESCRIPTION?ye.DESCRIPTION:e?.title===Z.TAGS?ye.TAGS:e?.title===Z.ASSIGNEES?ye.ASSIGNEES:ye.REF,r=ae(b.YANK).includes(t)?t:ye.REF;return C({mode:y.COMMAND_LINE}),V(`${b.YANK} ${r}`),u("Propose command",!0)}},{intent:x.EditTitle,mode:y.DEFAULT,description:"[r] rename title",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.EDIT} title ${v().selectedNode?.title}`),u("Exiting context",null))},{intent:x.EditDescription,mode:y.DEFAULT,description:"[e] edit description",action:()=>(C({mode:y.COMMAND_LINE}),V(`${b.EDIT} description `),u("Exiting context",null))},{intent:x.Exit,mode:y.DEFAULT,description:"[q] exit context",action:()=>(M.enterParentNode(),u("Exiting context",null))},{intent:x.NavPreviousItem,mode:y.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),u("Navigating to previous item",null))},{intent:x.NavNextItem,mode:y.DEFAULT,action:()=>(M.navigateToNextItem(),u("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:y.DEFAULT,action:()=>(M.navigateToPreviousContainer(),u("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:y.DEFAULT,action:()=>(M.navigateToNextContainer(),u("Navigating to next container",null))}];var Uv=500,Ov=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Al=e=>{let t=Ov(e);t&&To(n=>(n+t).slice(0,Uv))};var _v=[y.COMMAND_LINE,y.PALETTE],$v=e=>[{intent:x.MoveCursorLeft,mode:e,action:()=>(ui(-1),u("Moving cursor left",null))},{intent:x.MoveCursorRight,mode:e,action:()=>(ui(1),u("Moving cursor right",null))},{intent:x.MoveCursorLeftOfWord,mode:e,action:()=>(mi("left"),u("Moving cursor left of word",null))},{intent:x.MoveCursorRightOfWord,mode:e,action:()=>(mi("right"),u("Moving cursor right of word",null))},{intent:x.AutoCompleteCommand,mode:e,action:()=>(To((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=v().selectedNode?.title??""),r+o}),u("Auto-completing command",null))},{intent:x.CaptureInput,mode:e,action:(t,{sequence:n})=>(Al(n??""),u("Capturing input",null))},{intent:x.EraseInput,mode:e,action:()=>(cc(),u("Erasing input",null))},{intent:x.EraseInputWord,mode:e,action:()=>(lc(),u("Erasing input word",null))}],Tl=[{intent:x.Confirm,mode:y.COMMAND_LINE,action:()=>(St(),u("Executing command",null))},{intent:x.ViewHelp,mode:y.DEFAULT,action:()=>(C({mode:y.HELP}),u("Viewing help",null))},..._v.flatMap($v),{intent:x.ExitCommandLine,mode:y.COMMAND_LINE,action:()=>(C({mode:y.DEFAULT}),u("Exiting command line",null))},{intent:x.GetLastCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(pc(),u("Getting last command from history",null))},{intent:x.GetNextCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(fc(),u("Getting next command from history",null))}];import Pl from"chalk";var Xo=Pl.dim.hex(h.secondary2)(": for command line"),wl="q to exit",Ml=`${Pl.hex(h.accent)("m")} to confirm`,wi={[B.WORKSPACE]:[Xo],[B.BOARD]:[Xo],[B.BOARD+y.COMMAND_LINE]:[Xo],[B.SWIMLANE]:[Xo],[B.TICKET+y.HELP]:[wl],[B.SWIMLANE+y.HELP]:[wl],[B.TICKET]:[],[B.FIELD]:[],[B.SWIMLANE+y.MOVE]:[Ml],[B.TICKET+y.MOVE]:[Ml]};var Rr=e=>e.trim().toLocaleLowerCase(),Hv=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},jv=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>{let r=t[n];return r?qt(n,r.name):void 0}).filter(n=>!!n)},Ll=(e,t)=>{let n=Rr(t.value);if(!n)return!0;switch(t.target){case"title":return Rr(e.title??"").includes(n);case"description":return Rr(e.props.description??"").includes(n);case"tag":return Hv(e).map(Rr).some(o=>o.includes(n));case"assignee":return jv(e).map(Rr).some(o=>o.includes(n));case"ref":return Za(e.id,t.value);default:return!0}};function kl(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],s=r;for(;s&&(o.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=o[o.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),u("Breadcrumb built",o))}var Dl=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t};var In,Mi,Pi=new Set,Bl=()=>{for(let e of Pi)e()},Vv=e=>(Pi.add(e),()=>Pi.delete(e));function Fl(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let c=o[t];if(!c)return a("Unable to derive state, contextNode not found");let l=kl(t,o,r);if(d(l))return logger.error(l.message),l;let m=l.value,{context:p}=c,f=wi[p+n]??wi[p]??[],g=[...Rl,...bl[p]??[],...Tl],I=Dl(g),S=Gv(o,s),R=S[t]?.[e.selectedIndex]??null;return u("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:g,actionIndex:I,selectedNode:R,renderedChildrenIndex:S})}var v=()=>{if(!In)throw new Error("State not initialized. Call initWorkspaceState() first.");return In},We=()=>In?u("Retrieved state",In):a("State not initialized. Call initWorkspaceState() first.");function cr(e){Mi=e;let t=_e(process.cwd()),n=!1;if(!d(t)){let s=ut(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:y.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],replay:null,timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{},attachments:{}},o=Fl(r);return d(o)?o:(In=o.value,Bl(),u("State initialized",null))}function pe(e){let t=v(),n=e(t),r=Fl(n);return d(r)?a(r.message??"Unable to update state"):(In=r.value,Bl(),u("State updated",null))}var C=e=>pe(t=>({...t,...e}));var j=()=>Wv(Vv,v,v),Gv=(e,t)=>{let n={};for(let r of Object.values(e))T(r)&&t.length>0&&!t.every(o=>Ll(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,s)=>{let i=e[o.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},z=e=>v()?.renderedChildrenIndex[e]??[],it=()=>Mi?cr(Mi):a("Cannot reset state: no initial workspace found"),Wt=()=>In!==void 0;var Li=e=>{Wt()&&(C({syncStatus:e}),Ut({type:"sync-status",payload:e}))},Jo=(e="Syncing...")=>{Li({status:"syncing",msg:e})},Qo=(e="Synced")=>{Li({status:"synced",msg:e})},ki=e=>{Li({status:"failed",msg:e})},et=e=>(ki(e),a(e));import{decodeTime as AD}from"ulid";var Kv=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=J("getRepoRootDir",await gt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=J("getStateBranchRoot",Re({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=J("ensureInitialCommit",await Da(r));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:r,stateBranchRoot:s,ensureUpstream:t});let c=J("bootstrapStateBranchStorage",await Ua({repoRoot:r,stateBranchRoot:s,ensureUpstream:t}));if(d(c))return a(c.message);logger.debug("[sync] bootstrap result",{bootstrapped:c.value,stateBranchRoot:s}),logger.debug("[sync] checking state branch git operation",{stateBranchRoot:s});let l=J("hasInProgressGitOperation(stateBranchRoot)",await jr(s));if(d(l))return a(l.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:l.value}),l.value)return logger.info("[sync] state branch git operation in progress"),a("Cannot sync while a git operation is in progress in the state branch");logger.debug("[sync] ensuring state branch layout",{repoRoot:r,stateBranchRoot:s});let m=J("ensureStateBranchLayout",Ia(r,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}),u("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},zv=async({repoRoot:e,stateBranchRoot:t,ownEventFileName:n})=>{logger.debug("[sync] committing own event file from state branch",{ownEventFileName:n,stateBranchRoot:t}),logger.debug("[sync] staging own event file",{stateBranchRoot:t,ownEventFileName:n});let r=J("stageStateBranchOwnEventFile",await Jr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=J("stageStateBranchMediaFiles",await Ba({stateBranchRoot:t}));if(d(o))return a(o.message);let s=J("hasStagedChanges(after stage)",await fa(t));if(d(s))return a(s.message);if(logger.debug("[sync] state branch change check after stage result",{changed:s.value}),!s.value)return logger.info("[sync] no own event file changes to commit"),u("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=J("createStateBranchSyncCommit",await Fa({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),u("Committed own event file",{createdCommit:!0,commitSha:i.value}))},yo=async({cwd:e=process.cwd(),ownEventFileName:t})=>{if(logger.debug("[sync] syncEpiqWithRemote:start",{cwd:e,ownEventFileName:t}),t.includes("/")||t.includes("\\"))return logger.error("[sync] invalid own event file name: contains path separator",{ownEventFileName:t}),a("Own event file must be a file name, not a path");if(!t.endsWith(".jsonl"))return logger.error("[sync] invalid own event file name: missing .jsonl suffix",{ownEventFileName:t}),a("Own event file must end with .jsonl");Jo();let n=J("ensureSyncReady",await Kv({cwd:e,ensureUpstream:!0}));if(d(n))return et(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=J("isDetachedHead(stateBranchRoot)",await ga(o));if(d(i))return et(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return et("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,l,m=!1,p=!1,f=J("getStateBranch",Cn(r));if(d(f))return et(f.message);let g=f.value;logger.debug("[sync] resolved state branch",{stateBranch:g,stateBranchRoot:o});let I=J("commitOwnEventFileToStateBranch",await zv({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(I))return et(I.message);c=I.value.createdCommit,l=I.value.commitSha;let S=J("pullBranchRebaseIfPresent",await Ps({cwd:o,branch:g}));if(d(S))return et(S.message);if(m=S.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let R=J("pushStateBranch",await sr({stateBranchRoot:o,repoRoot:r}));if(d(R)&&pa(R.message)){let A=J("pullBranchRebaseIfPresent(retry)",await Ps({cwd:o,branch:g}));if(d(A))return et(A.message);m=m||A.value,R=J("pushStateBranch(retry)",await sr({stateBranchRoot:o,repoRoot:r}))}if(d(R))return et(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let R=J("git rev-parse HEAD",await F({args:["rev-parse","HEAD"],cwd:o}));if(d(R))return et(R.message);l=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",l)}return Qo(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),u("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:l,pulled:m,pushed:p,bootstrapped:s})};import{existsSync as Di}from"node:fs";import{chmod as Bi}from"node:fs/promises";import jl from"node:os";import Hn from"node:path";var Ul=(e,t)=>e.reduce((n,r)=>r<n?r:n,t);var Ol=1e5,Zo=null,_l=Promise.resolve(),en=e=>{let t=_l.then(e,e);return _l=t.then(()=>{},()=>{}),t},Fi=e=>{let t=_e(e??process.cwd());return d(t)?a(t.message):u("Resolved Epiq repo root",t.value)},Ui=e=>{let t=Fi(e);return d(t)?t:Re({repoRoot:t.value})},at=()=>{if(!Wt())return{mode:"live",asOfTime:null};let{timeMode:e}=v();return e==="live"?{mode:"live",asOfTime:null}:{mode:"scrub",asOfTime:Zo}},Oi=(e,t)=>{let n=new Map,r=new Set,o=i=>{let c=new Set,l=i;for(;l&&!c.has(l);){if(r.has(l))return l;c.add(l),l=n.get(l)}return null},s=[];for(let i of e){let c=i.payload,l=c?.id;l&&(i.action==="add.board"&&r.add(l),c.parent&&n.set(l,c.parent),(l===t||o(l)===t)&&s.push(i))}return s},Wl=async(e={})=>{let t=Ui(e.repoRoot);if(d(t))return a(t.message);let n=je(t.value);if(d(n))return a(n.message);let o=(e.boardId?Oi(n.value,e.boardId):n.value).map(zt).filter(g=>g!==null),s=Date.now(),i=e.end??s,c=e.start??Ul(o,i);if(i<=c)return u("Empty time window",{bucketMs:0,buckets:[],earliest:c,latest:i});let l=o.filter(g=>g>=c&&g<i).sort((g,I)=>g-I),m=Math.max(1,Math.ceil((i-c)/Ol)),p=new Map;for(let g of l){let I=Math.min(Ol-1,Math.floor((g-c)/m)),S=c+I*m;p.set(S,(p.get(S)??0)+1)}let f=[...p.entries()].sort(([g],[I])=>g-I).map(([g,I])=>({t:g,count:I}));return u("Computed event timeline",{bucketMs:m,buckets:f,earliest:c,latest:i})},Ar="",$l="",Vl=async(e={})=>{let t=Fi(e.repoRoot);if(d(t))return a(t.message);let n=ut(t.value);if(d(n))return a(n.message);let r=await F({cwd:t.value,args:["log","--branches","--not",n.value.stateBranch,...e.start!==void 0?[`--since=@${Math.floor(e.start/1e3)}`]:[],...e.end!==void 0?[`--until=@${Math.floor(e.end/1e3)}`]:[],"--shortstat",`--format=${$l}%H${Ar}%at${Ar}%an${Ar}%s`]});if(d(r))return a(r.message);let o=r.value.stdout.split($l).filter(s=>s.trim().length>0).map(s=>{let[i,...c]=s.split(`
59
59
  `),[l,m,p,...f]=(i??"").split(Ar);if(!l||!m)return null;let g=c.join(" "),I=Number(/(\d+) insertion/.exec(g)?.[1]??0),S=Number(/(\d+) deletion/.exec(g)?.[1]??0);return{sha:l,time:Number(m)*1e3,author:p??"unknown",subject:f.join(Ar),linesChanged:I+S}}).filter(s=>s!==null);return u("Computed commit timeline",o)},qv=e=>/^[0-9a-f]{7,40}$/i.test(e),Yv=async(e,t)=>{let n=await F({cwd:e,args:["show",t]});if(d(n))return a(n.message);let r=Hn.join(jl.tmpdir(),"epiq","commit-diffs");be.mkDir(r);let o=Hn.join(r,`${t}.diff`);return Di(o)||(be.writeToFile(o,n.value.stdout),await Bi(o,292)),Yc(o)},Xv=12,Jv=800,Hl=async(e,t,n)=>{let r=await F({cwd:e,args:["show",`${t}:${n}`]});return d(r)?"":r.value.stdout},Qv=async(e,t,n)=>{let r=await F({cwd:e,args:["diff-tree","--no-commit-id","--name-only","-r",t]});if(d(r))return a(r.message);let o=r.value.stdout.split(`
60
- `).map(f=>f.trim()).filter(Boolean);if(o.length===0)return a("No changed files found for this commit");if(o.length>Xv)return a(`Commit touches ${o.length} files \u2014 too many for a side-by-side view`);let s=Hn.join(jl.tmpdir(),"epiq","commit-diffs",t),i=await Promise.all(o.map(async(f,g)=>{let[I,S]=await Promise.all([Hl(e,`${t}~1`,f),Hl(e,t,f)]),R=Hn.basename(f),A=Hn.join(s,String(g),"before",R),P=Hn.join(s,String(g),"after",R);return Di(A)||(be.writeToFile(A,I),await Bi(A,292)),Di(P)||(be.writeToFile(P,S),await Bi(P,292)),{beforePath:A,afterPath:P}})),[c,...l]=i;if(!c)return a("No changed files found for this commit");let m=await Si(n,c.beforePath,c.afterPath,"new");if(d(m)||l.length===0)return m;await new Promise(f=>setTimeout(f,Jv));let p=await Promise.all(l.map(({beforePath:f,afterPath:g})=>Si(n,f,g,"reuse")));for(let f of p)d(f)&&logger.error(`Failed to open an additional diff tab for ${t}: ${f.message}`);return m},Gl=async e=>{if(!qv(e.sha))return a("Invalid commit sha");let t=Fi(e.repoRoot);if(d(t))return a(t.message);let n=t.value,r=$o()[0];if(r&&Ei(r)){let o=await Qv(n,e.sha,r);if(!d(o))return o;logger.error(`Side-by-side diff failed for ${e.sha}, falling back to unified diff: ${o.message}`)}return Yv(n,e.sha)},Kl=e=>{let t=je(e);if(d(t))return a(t.message);let n=it();if(d(n))return a(n.message);Zo=null;let o=st(t.value).filter(d);return o.length>0?a(o.map(s=>s.message).join(", ")):(C({readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),u("Restored live state",!0))},Zv=(e,t)=>{Zo=null;let n=Kl(e);return d(n)?a(`${t} (recovery to live also failed: ${n.message})`):a(t)},zl=e=>en(async()=>{let t=Ui(e.repoRoot);if(d(t))return a(t.message);let n=uo(t.value,e.targetTime);if(d(n))return a(n.message);let{appliedEvents:r,unappliedEvents:o}=n.value,s=it();if(d(s))return s;let c=st(r).filter(d);return c.length>0?Zv(t.value,c.map(l=>l.message).join(", ")):(C({readOnly:!0,timeMode:"peek",unappliedEvents:o,replay:null}),Zo=e.targetTime,u("Checked out historical state",{asOfTime:e.targetTime}))}),ql=(e={})=>en(async()=>{let t=Ui(e.repoRoot);if(d(t))return a(t.message);let n=Kl(t.value);return d(n)?a(n.message):u("Returned to live state",!0)});var _i=()=>{let e=Ft();return d(e)?xt:e.value.attachmentMaxKb??xt},$i=e=>{let t=_e(e??process.cwd());return d(t)?a(t.message):u("Resolved Epiq repo root",t.value)},Ne=async(e,t)=>{let n=$i(e);if(d(n))return n;let r=Re({repoRoot:n.value});if(d(r))return a(r.message);let o=Sn(),s=await cn({repoRoot:n.value,stateBranchRoot:r.value,stateBranchName:o.stateBranch});if(d(s))return a(s.message);if(t?.pull??!1){let l=await F({cwd:r.value,args:["pull","--ff-only"]});d(l)&&se.info(3,l.message)}let i=je(r.value);if(d(i))return a(i.message);let c=pn(i.value);return d(c)?a(c.message):u("Booted Epiq state",{repoRoot:n.value,stateBranchRoot:r.value})},Ae=()=>{let e=Ft();return d(e)?a(e.message):e.value.userId?e.value.userName?u("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},Fe=()=>{let e=We();return d(e)?a(e.message):e},Xl=e=>(e.props.tags??[]).map(t=>E.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ue(t.name)})),Hi=()=>{let e=We(),t=d(e)?[]:e.value.eventLog??[],n=new Map;for(let r of t)r.userId&&r.userName&&n.set(r.userId,r.userName);return n},Jl=(e,t)=>{let n=new Map(e);for(let r of Object.values(t)){if(r.tombstoned){n.set(r.id,r.name);continue}n.set(r.id,Fn(r.name,n.get(r.id))??r.name)}return n},Ql=(e,t=new Map)=>(e.props.assignees??[]).map(n=>E.getContributor(n)).filter(n=>n!=null).map(n=>{let r=n.tombstoned?n.name:Fn(n.name,t.get(n.id))??n.name;return{id:n.id,name:r,color:ue(r)}});var Zl=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Fe();if(d(n))return n;let r=n.value.nodes,o=Hi(),s=Object.values(r).filter(T).filter(i=>!i.isDeleted).filter(i=>e.includeClosed||i.parentNodeId!==ve).filter(i=>e.boardId?(i.parentNodeId?r[i.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).map(i=>({id:i.id,ref:He(i.id),title:Ze(i.title),description:i.props.description??"",parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===ve,readonly:!!i.readonly,tags:Xl(i),assignees:Ql(i,o)}));return u("Listed issues",s)},eu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=Pn(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let s=jo({name:e.title,parent:e.parentId,user:n.value,rank:o.value});if(d(s))return s;let i=[...s.value],c=i.find(f=>f.action==="add.issue")?.payload.id;if(!c)return a("Unable to determine created issue id");e.description&&i.push({id:q(),...n.value,action:"edit.description",payload:{id:c,md:e.description}});let l=[];for(let f of e.tagNames??[]){let g=Ze(f).trim();if(!g||l.some(R=>R.name===g))continue;let I=Object.values(r.value.tags).find(R=>R.name===g),S=I?.id??q();I||i.push({id:q(),...n.value,action:"create.tag",payload:{id:S,name:g}}),i.push({id:q(),...n.value,action:"add.issue.tag",payload:{id:c,tag:S}}),l.push({id:S,name:g})}let m=[];for(let f of e.assigneeNames??[]){let g=Ze(f).trim();if(!g||m.some(R=>R.name===g))continue;let I=Object.values(r.value.contributors).find(R=>R.name===g),S=I?.id??q();I||i.push({id:q(),...n.value,action:"create.contributor",payload:{id:S,name:g}}),i.push({id:q(),...n.value,action:"add.issue.assignee",payload:{id:c,assignee:S}}),m.push({id:S,name:g})}let p=U(i,t.value.stateBranchRoot);return d(p)?a(p.message):u("Created issue",{id:c,title:e.title,parentId:e.parentId,description:e.description??"",tags:l,assignees:m})},tu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=mn(ve,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:q(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ve,rank:r.value}},s=U([o],t.value.stateBranchRoot);return d(s)?a(s.message):u("Closed issue",{id:e.issueId})},nu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Target node is not issue");if(o.parentNodeId!==ve)return a("Issue is not closed");let s=Oo(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ve)return a("Previous parent resolves to closed swimlane");let i=r.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=mn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let l={id:q(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=U([l],t.value.stateBranchRoot);return d(m)?a(m.message):u("Reopened issue",{id:o.id,parentId:i.id})},ru=async e=>{let t=$i(e.repoRoot);if(d(t))return t;let n=Ae();if(d(n))return n;let r=Re({repoRoot:t.value});if(d(r))return r;let o=je(r.value);if(d(o))return o;let s=pn(o.value);if(d(s))return s;let i=mn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:q(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},l=U([c],r.value);return d(l)?a(l.message):u("Moved issue",{id:e.issueId,parentId:e.parentId})};var es=async(e={})=>{Jo();let t=$i(e.repoRoot);if(d(t))return a("Sync failed");let n=Ae();if(d(n))return n;let r=await yo({cwd:t.value,ownEventFileName:un(n.value)});return d(r)?(ki(r.message),r):(Qo(),u("Synced",r.value))};var Tr=()=>{let e=Fe();if(d(e))return e;let t=at(),n=t.mode!=="live",r=Object.values(e.value.nodes),o=r.filter(g=>Zr(g)&&!g.isDeleted),s=Hi(),i=new Map,c=new Map;for(let g of r)if(!g.isDeleted){if(_t(g)&&g.parentNodeId){let I=i.get(g.parentNodeId)??[];I.push(g),i.set(g.parentNodeId,I)}if(T(g)&&g.parentNodeId){let I=c.get(g.parentNodeId)??[];I.push(g),c.set(g.parentNodeId,I)}}let l=Ft();if(d(l))return l;let m={};for(let g of r.filter(T))g.isDeleted||(m[g.id]=E.getCommentsByIssue(g.id).map(I=>{let S=E.getContributor(I.authorId);return{id:I.id,issueId:I.issue,body:I.md,author:{id:I.authorId,name:S?.name??"Unknown",color:ue(S?.name??I.authorId)},createdAt:Yl(I.id)}}));let p=new Map;for(let g of e.value.eventLog)g.action==="add.issue.attachment"&&p.set(g.payload.id,g.payload.author);let f={};for(let g of r.filter(T))g.isDeleted||(f[g.id]=E.getAttachmentsByIssue(g.id).map(I=>({id:I.id,issueId:I.issue,name:I.name,fileName:kn(I.hash,I.ext),bytes:I.bytes,createdAt:Yl(I.id),canDelete:p.get(I.id)===l.value.userId})));return u("Retrieved Epiq GUI state",{boards:o.sort((g,I)=>g.rank.localeCompare(I.rank)).map(g=>({id:g.id,ref:He(g.id),title:g.title,swimlanes:(i.get(g.id)??[]).sort((I,S)=>I.rank.localeCompare(S.rank)).map(I=>({id:I.id,title:I.title,readonly:!!I.readonly||n,issues:(c.get(I.id)??[]).sort((S,R)=>S.rank.localeCompare(R.rank)).map(S=>({id:S.id,ref:He(S.id),title:Ze(S.title),description:S.props.description??"",readonly:!!S.readonly||n,tags:Xl(S),assignees:Ql(S,s),parentNodeId:S.parentNodeId,isClosed:S.parentNodeId===ve})),parentNodeId:I.parentNodeId}))})),tags:Object.values(e.value.tags).map(g=>({...g,color:ue(g.name)})),contributors:Object.values(e.value.contributors).map(g=>({...g,color:ue(g.name)})),user:{name:l.value.userName??"",id:l.value.userId??"",color:ue(l.value.userName??"")},commentsByIssueId:m,attachmentsByIssueId:f,attachmentMaxKb:_i(),timeTravel:t})},dt=async(e={})=>{if(at().mode!=="live")return Tr();let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:Tr()},ou=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=o.props.description??"";if(s===e.description)return u("No changes made",{id:e.issueId,description:s});let i={id:q(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue description",{id:e.issueId,description:e.description})},su=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Ze(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return u("No changes made",{id:e.issueId,title:s});let i={id:q(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue title",{id:e.issueId,title:s})},iu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Ze(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(r.value.tags).find(p=>p.name===s),c=i?.id??q(),l=[...i?[]:[{id:q(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:q(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=U(l,t.value.stateBranchRoot);return d(m)?a(m.message):u("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},au=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Untag target must be an issue");if(o.readonly)return a("Cannot untag readonly issue");if(!r.value.tags[e.tagId])return a("Tag not found");let s={id:q(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue tag",{id:e.issueId,tagId:e.tagId})},du=async(e,t)=>{let n=je(e);if(d(n))return;let r;for(let o of n.value)o.userId===t&&(r=o.userName??r);return r===void 0?void 0:{id:t,name:r}},cu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=e.self?n.value.userId:e.assigneeId;if(s){let R=r.value.contributors[s],A=R?void 0:await du(t.value.stateBranchRoot,s);if(!R&&!A)return a("Unknown assignee id");let P=R??A,_=[...R?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:P.id,name:P.name}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:P.id}}],w=U(_,t.value.stateBranchRoot);return d(w)?a(w.message):u("Added issue assignee",{id:e.issueId,assignee:{id:P.id,name:P.name}})}let i=Ze(e.assigneeName??"").trim();if(!i)return a("Provide assigneeId, self or assigneeName");let l=[...Jl(Hi(),r.value.contributors).entries()].filter(([,R])=>R===i);if(l.length>1)return a(`"${i}" matches ${l.length} contributors (${l.map(([R])=>R).join(", ")}). Assign by assigneeId to choose.`);let m=l[0];if(!m&&!e.createUnlinked)return a(`No contributor named "${i}". Assign by id, or pass createUnlinked to add them as an external assignee.`);let[p=q(),f=i]=m??[],I=[...!!r.value.contributors[p]?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:p,name:f}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:p}}],S=U(I,t.value.stateBranchRoot);return d(S)?a(S.message):u("Added issue assignee",{id:e.issueId,assignee:{id:p,name:f}})},lu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;if(!r.value.contributors[e.contributorId])return a("Contributor not found");if(await du(t.value.stateBranchRoot,e.contributorId))return a("Cannot remove a contributor who has authored events \u2014 their name appears throughout the log");let i=[{id:q(),...n.value,action:"tombstone.contributor",payload:{id:e.contributorId}}],c=U(i,t.value.stateBranchRoot);return d(c)?a(c.message):u("Tombstoned contributor",{id:e.contributorId,name:to})};var uu=async(e={})=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=je(t.value.stateBranchRoot);if(d(o))return a(o.message);let s=e.boardId?Oi(o.value,e.boardId):o.value,i=new Map,c=new Set,l=new Set;for(let g of o.value)g.userId&&l.add(g.userId);for(let g of s)g.userId&&(i.set(g.userId,g.userName??""),c.add(g.userId));let m=r.value.contributors,f=[...Jl(i,m).entries()].map(([g,I])=>({id:g,name:I,color:ue(I),isSelf:g===n.value.userId,isExternal:!c.has(g),isRemoved:m[g]?.tombstoned===!0,hasAuthoredAnywhere:l.has(g)}));return u("Listed board contributors",f)},mu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Unassign target must be an issue");if(o.readonly)return a("Cannot unassign readonly issue");if(!r.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:q(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},ts=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Comment target must be an issue");if(o.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=q(),c={id:q(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Added issue comment",{id:i,issueId:e.issueId,body:s})},ns=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!o)return a("Unable to resolve comment");if(o.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!T(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return u("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},pu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Attachment target must be an issue");if(o.readonly)return a("Cannot attach to readonly issue");let s=Buffer.from(e.dataBase64??"","base64"),i=qd(t.value.stateBranchRoot,s,_i());if(d(i))return i;let c=Ze(e.name??"").trim()||"image",l=q(),m={id:q(),...n.value,action:"add.issue.attachment",payload:{id:l,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=U([m],t.value.stateBranchRoot);return d(p)?a(p.message):u("Added issue attachment",{id:l,issueId:e.issueId,fileName:kn(i.value.hash,i.value.ext),bytes:i.value.bytes})},fu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.attachment"&&m.payload.id===e.attachmentId);if(!o)return a("Unable to resolve attachment");if(o.payload.author!==n.value.userId)return a("You can only delete your own attachments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!T(s))return a("Attachment target must be an issue");if(s.readonly)return a("Cannot delete attachment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.attachment"&&m.payload.id===e.attachmentId))return u("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},gu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:Yd(t.value.stateBranchRoot,e.fileName,_i())};var vu=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=rr();if(d(p))return se.error(p.message);let{autoSync:f,userName:g,preferredEditor:I}=p.value;return!!(f&&g&&I)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await en(async()=>{at().mode==="live"&&(await es({repoRoot:e.repoRoot}),Ut({type:"state",payload:await dt({repoRoot:e.repoRoot})}))})}finally{o=!1,s&&(s=!1,c())}}},l=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=rr();if(d(p))return se.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:l,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as ey}from"ws";var ty=new Set(["sync","issues:create","issues:move","issue:close","issue:reopen","issue:edit:title","issue:edit:description","issue:tag:add","issue:tag:remove","contributor:remove","issue:assignee:add","issue:assignee:remove","issue:comment:add","issue:comment:delete"]),yu=()=>{let e=Tr();Ut({type:"state",payload:e})},de=(e,t)=>{e.send(JSON.stringify(t))},rs=async(e,t)=>de(e,{type:"state",payload:await dt({repoRoot:t})}),ny=async(e,t)=>{let n=()=>de(e,{type:"state",payload:Tr()});if(at().mode!=="live")return n();let r=await dt({repoRoot:t});return at().mode!=="live"?n():de(e,{type:"state",payload:r})},ct=async(e,t,n,r,o)=>{if(de(e,{type:r,payload:o}),d(o))return de(e,{type:"failed",payload:o.message});n(),ny(e,t)},hu=(e,t,{onStateChanged:n})=>{new ey({server:e,path:"/ws"}).on("connection",o=>{Oa(o),o.on("message",async s=>{let i=async c=>{let{type:l}=c;if(l==="timeline:get"){let{requestId:m,...p}=c.payload??{};return de(o,{type:"timeline",requestId:m,payload:await Wl({repoRoot:t,...p})})}if(l==="commits:get"){let{requestId:m,...p}=c.payload??{};return de(o,{type:"commits",requestId:m,payload:await Vl({repoRoot:t,...p})})}if(l==="commit:inspect")return de(o,{type:"commit:inspect:result",payload:await Gl({repoRoot:t,sha:c.payload.sha})});if(l==="time-travel:scrub"){let m=await zl({repoRoot:t,targetTime:c.payload.targetTime});return de(o,{type:"time-travel:result",payload:m}),d(m)?void 0:yu()}if(l==="time-travel:live"){let m=await ql({repoRoot:t});return de(o,{type:"time-travel:result",payload:m}),d(m)?void 0:yu()}if(l==="state:get")return rs(o,t);if(l==="sync"){let m=await es({repoRoot:t});return de(o,{type:"sync:result",payload:m}),n(),rs(o,t)}if(l==="issue:comment:add"){let m=await ts({repoRoot:t,...c.payload});return ct(o,t,n,"issue:comment:add:result",m)}if(l==="issue:comment:delete"){let m=await ns({repoRoot:t,...c.payload});return de(o,{type:"issue:comment:delete:result",payload:m}),d(m)?de(o,{type:"failed",payload:m.message}):(n(),rs(o,t))}if(l==="issue:edit:description"){let m=await ou({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:description:result",m)}if(l==="issue:edit:title"){let m=await su({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:title:result",m)}if(l==="issue:tag:add"){let m=await iu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:add:result",m)}if(l==="issue:tag:remove"){let m=await au({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:remove:result",m)}if(l==="contributor:remove"){let m=await lu({repoRoot:t,...c.payload});return ct(o,t,n,"contributor:remove:result",m)}if(l==="contributors:get")return de(o,{type:"contributors",payload:await uu({repoRoot:t,...c.payload})});if(l==="issue:assignee:add"){let m=await cu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:add:result",m)}if(l==="issue:assignee:remove"){let m=await mu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:remove:result",m)}if(l==="issues:list")return de(o,{type:"issues",payload:await Zl({repoRoot:t})});if(l==="issues:create"){let m=await eu({...c.payload,repoRoot:t});return de(o,{type:"issues:create:result",payload:m}),d(m)?Ut({type:"failed",payload:m.message}):(Ut({type:"issue:created",payload:m.value}),n(),rs(o,t))}if(l==="issues:move"){if(!c.payload.position)return de(o,{type:"error",message:"Missing move position"});let m=await ru({...c.payload,repoRoot:t});return ct(o,t,n,"issues:move:result",m)}if(l==="issue:close"){if(!c.payload.issueId)return de(o,{type:"error",message:"Missing issueId"});let m=await tu({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:close:result",m)}if(l==="issue:reopen"){if(!c.payload.issueId)return de(o,{type:"error",message:"Missing issueId"});let m=await nu({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:reopen:result",m)}return de(o,{type:"error",message:"Unknown message type"})};try{let c=JSON.parse(s.toString());return ty.has(c.type)?await en(async()=>at().mode!=="live"?de(o,{type:"failed",payload:"Read-only while viewing history"}):i(c)):await i(c)}catch(c){return de(o,{type:"error",message:c instanceof Error?c.message:String(c)})}})})};var sy=En.dirname(oy(import.meta.url)),iy=process.env.IS_LOCAL==="true"?En.resolve(process.cwd(),"dist/gui"):En.join(sy,"gui"),os,ay=async()=>(os===void 0&&(os=await import("node:sea").catch(()=>null)),os?.isSea()?os:null),fe=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},dy=e=>fe(e,409,{isError:!0,message:"Read-only while viewing history"}),ss=(e,t)=>en(async()=>at().mode!=="live"?dy(e):t()),xu=async(e,t=1024*1024)=>new Promise((n,r)=>{let o="",s=0;e.on("data",i=>{if(s+=i.length,s>t){e.destroy(),r(new Error("Request body too large"));return}o+=i}),e.on("end",()=>{try{n(o?JSON.parse(o):{})}catch{r(new Error("Invalid JSON body"))}}),e.on("error",r)}),cy=2*1024*1024,ly={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},uy=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":"application/octet-stream",bu=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=En.resolve(iy),o=En.resolve(r,n),s=En.relative(r,o);if(s.startsWith("..")||En.isAbsolute(s))return fe(t,403,{isError:!0,message:"Forbidden"});let i=await ay();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await Iu(o);return t.writeHead(200,{"content-type":uy(o)}),t.end(c)}catch{return fe(t,404,{isError:!0,message:`Not found: ${n}`})}},my=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=l=>{if(e.off("listening",c),l.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(l)},c=()=>{e.off("error",i);let l=e.address();if(!l||typeof l=="string"){r(new Error("Unable to resolve address"));return}n(l.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),Eu=async e=>{let t=ry.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return fe(s,200,await dt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await xu(o);if(!c.issueId||!c.body?.trim())return fe(s,400,{isError:!0,message:"Missing issueId or body"});let l=c.issueId,m=c.body;return await ss(s,async()=>{let p=await ts({repoRoot:e.repoRoot,issueId:l,body:m});return d(p)?fe(s,400,{isError:!0,message:p.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="POST"&&i.pathname==="/api/attachments")try{let c=await xu(o,cy);if(!c.issueId||!c.dataBase64)return fe(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let l=c.issueId,m=c.dataBase64,p=c.name??"";return await ss(s,async()=>{let f=await pu({repoRoot:e.repoRoot,issueId:l,name:p,dataBase64:m});return d(f)?fe(s,400,{isError:!0,message:f.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add attachment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/attachments/")){let c=decodeURIComponent(i.pathname.replace("/api/attachments/",""));return c?ss(s,async()=>{let l=await fu({repoRoot:e.repoRoot,attachmentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing attachment id"})}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),l=await gu({repoRoot:e.repoRoot,fileName:c});if(d(l))return fe(s,404,{isError:!0,message:l.message});try{let m=await Iu(l.value.filePath);return s.writeHead(200,{"content-type":ly[l.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return fe(s,404,{isError:!0,message:"Attachment blob not found"})}}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));return c?ss(s,async()=>{let l=await ns({repoRoot:e.repoRoot,commentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing comment id"})}return i.pathname.startsWith("/board/")?bu("/",s):bu(i.pathname,s)});try{await my(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=vu({repoRoot:e.repoRoot});hu(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):u("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Su=async e=>{let t=Ft();Q(t)&&Me(t.value);let n=await Eu({...e,boardId:""});if(d(n))return n;let{url:r}=n.value;return console.log(`Epiq GUI running at ${py.cyan(r)}`),La(r),u("Started GUI",{url:r})};import{Box as sn}from"ink";import ce from"react";import{Box as ji,Text as wr}from"ink";import lt,{useEffect as fy,useMemo as gy}from"react";import{ulid as vy}from"ulid";var Cu=({text:e,match:t,color:n,highlightColor:r=h.secondary,dimColor:o=!1})=>{if(!t)return lt.createElement(wr,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?lt.createElement(wr,{color:n,dimColor:o},e):lt.createElement(wr,{color:n,dimColor:o},e.slice(0,c),lt.createElement(wr,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Nu=vy(),yy=e=>`${e}`,hy=e=>{let{pendingNavTarget:t}=Jt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ae(b.NONE,{breadCrumb:n,contextNode:r,readOnly:v().readOnly,selectedNode:o}));return[...new Set(Object.values(b))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==b.PALETTE).map(i=>{let c=wo(i),l=zo.find(m=>m.intent===c);return{command:i,description:l?.description??`[${i}] Run command`,isAvailable:s.has(i)}}).filter(i=>i.command.toLowerCase().startsWith(e)||e.length>=2&&i.description.toLowerCase().includes(e)).sort((i,c)=>i.isAvailable!==c.isAvailable?i.isAvailable?-1:1:i.command.localeCompare(c.command))},xy=e=>ee.text({id:Nu,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),by=(e,t,n)=>ee.text({id:yy(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Wi=[],Iy=e=>{Ru();let t=E.createNode(xy(v().rootNodeId));d(t)||!Ot(t.value)||(Wi=[t.value,...e.map((n,r)=>by(n,r,Nu)).map(E.createNode).filter(Q).map(({value:n})=>n).filter(Ot)],M.navigate({contextNode:t.value,selectedIndex:0}))},Ru=()=>{let e=Wi.map(t=>t.id);Wi=[];for(let t of e)E.deleteNode(t)};function Au({width:e,height:t}){let r=gc().value.trim().toLowerCase(),o=gy(()=>hy(r),[r]);fy(()=>(Iy(o),()=>{Ru()}),[o]);let s=v().selectedIndex;return lt.createElement(ji,{flexDirection:"column",width:e,height:t-2},lt.createElement(tt,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let l=c===s,m=i.isAvailable?h.accent:h.secondary2,p=i.isAvailable?"":"[unavailable] ";return lt.createElement(ji,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:h.secondary,borderStyle:"single"},lt.createElement(wr,{color:m,dimColor:!i.isAvailable},l?"\u276F ":" ",lt.createElement(Cu,{text:Va(i.command),match:r,color:m,dimColor:!i.isAvailable})),lt.createElement(ji,{paddingLeft:2},lt.createElement(Cu,{text:p+i.description,match:r.length>=2?r:"",color:l&&i.isAvailable?h.primary:h.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Oy}from"ink";import ds from"react";import Pr from"chalk";import{Box as Vi,Text as Tu}from"ink";import Mr,{useEffect as Ey,useMemo as Sy,useState as Cy}from"react";var wu=Pr.hex(h.secondary),Ny=Pr.inverse,Ry=Pr.inverse.hex(h.secondary2),Ay={hint:"",hints:[],overlap:0,remainder:""},Pu=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},Ty=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=ue(t);return{bg:r=>Pr.bgHex(n).black(r),bgCursor:r=>Pr.bgHex(n).inverse.black(r)}}return zs(t)},wy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Pu({value:e,command:t});if(!r)return null;let s=e.slice(r.end).match(/^\s*/)?.[0].length??0,i=r.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},Mu=()=>({value:Le.value,cursorPosition:Le.cursorPosition,commandIsPending:Le.commandIsPending,autoCompletion:Le.commandMeta.autoCompletion??Ay,infoMessage:Le.commandMeta.infoMessage,validationStatus:Le.commandMeta.validity,command:Le.commandMeta.command,inputString:Le.commandMeta.inputString,modifier:Le.commandMeta.modifier}),My=(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,Lu=({width:e,mode:t})=>{let[n,r]=Cy(Mu());Ey(()=>{let S=()=>{let A=Mu();r(P=>My(P,A)?P:A)},R=li(S);return S(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:l,command:m,modifier:p,validationStatus:f}=n,g=c&&f===bt.Invalid,I=Sy(()=>{let S=Math.max(0,Math.min(s,o.length)),R=Pu({value:o,command:m}),A=wy({value:o,command:m,modifier:p}),P=m?zs(m):null,_=Ty({command:m,modifier:p}),w=(ge,me)=>{let Gn=R&&me>=R.start&&me<R.end,Kn=A&&me>=A.start&&me<A.end;return Gn&&P?P.fg(ge):Kn&&_?_.bg(ge):ge},W=(ge,me)=>{let Gn=R&&me>=R.start&&me<R.end,Kn=A&&me>=A.start&&me<A.end;return Gn&&P?P.fgCursor(ge):Kn&&_?_.bgCursor(ge):Ny(ge)},H=o.slice(0,S),D=o[S]??" ",$=S<o.length?o.slice(S+1):"",Ye=Array.from(H).map((ge,me)=>w(ge,me)).join(""),we=W(D,S),Xe=Array.from($).map((ge,me)=>w(ge,S+1+me)).join("");if(l.hint){let ge=l.hint[l.overlap]??D;we=Ry(ge),Xe=wu(l.remainder.slice(1)+$)}return wu(t===y.PALETTE?"?":":")+Ye+we+Xe},[o,s,l,m,p]);return Mr.createElement(Vi,{flexDirection:"column",justifyContent:"flex-start"},Mr.createElement(Vi,{flexDirection:"column",paddingX:1,borderColor:h.secondary,borderStyle:"round",width:e},Mr.createElement(Vi,null,Mr.createElement(Tu,null,I),i&&Mr.createElement(Tu,{wrap:"truncate",color:g?h.red:h.secondary2},` ${i} `))))};import{Box as Py,Text as Ly}from"ink";import ku from"react";var ky=(e,t)=>{let n=[],r=0;for(let o of e){let i=(n.length>0?" | ":"").length+o.length;if(r+i>t-4)break;n.push(o),r+=i}return n},Du=({width:e,availableHints:t})=>{let n=ky(t,e).join(" | ");return ku.createElement(Py,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1},ku.createElement(Ly,{color:h.secondary2},n.length?n:"\xA0"))};import{Box as Dy,Text as is}from"ink";import Lr,{useEffect as By,useRef as jn,useState as Fy}from"react";var Uy=40,as=.3,Gi="\u2500",Bu=1,Fu=16,Uu=({width:e})=>{let{replay:t}=j(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*Bu,[c,l]=Fy(0),m=jn(r);m.current=r;let p=jn(0),f=jn(0),g=jn(0),I=jn(0),S=jn(0);if(By(()=>{if(!n){p.current=0,g.current=0,I.current=0,S.current=0,l(0);return}p.current=m.current,f.current=Date.now(),g.current=m.current;let w=setInterval(()=>{let W=Date.now(),H=m.current;if(H!==g.current){let Xe=H-g.current,ge=W-f.current;if(Xe<0)I.current=0,S.current=0;else if(Xe>0&&ge>0){let me=Xe/ge;I.current=I.current===0?me:I.current*(1-as)+me*as,S.current=S.current===0?Xe:S.current*(1-as)+Xe*as}p.current=H,f.current=W,g.current=H}let D=W-f.current,$=Math.min(S.current,I.current*D),Ye=Math.min(1,p.current+$),we=Math.round(Ye*i);l(Xe=>Xe===we?Xe:we)},Uy);return()=>clearInterval(w)},[n,i]),!t)return null;let R=w=>{let W=s>1?w/(s-1):0,H=Math.round(W*(Fu-1))/(Fu-1);return no(H)},A=Math.min(s,Math.floor(c/Bu)),P=[];for(let w=0;w<A;w++){let W=R(w),H=P[P.length-1];H&&H.color===W?H.text+=Gi:P.push({text:Gi,color:W})}let _=Gi.repeat(Math.max(0,s-A));return Lr.createElement(Dy,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1,columnGap:1},Lr.createElement(is,{color:h.secondary2},"\u25B6"),Lr.createElement(is,null,P.map((w,W)=>Lr.createElement(is,{key:W,color:w.color},w.text)),Lr.createElement(is,{color:h.secondary,dimColor:!0},_)))};var kr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=j(),o=t===y.COMMAND_LINE||t===y.PALETTE;return ds.createElement(Oy,null,o?ds.createElement(Lu,{width:e,mode:t}):r==="replay"?ds.createElement(Uu,{width:e}):ds.createElement(Du,{width:e,mode:t,availableHints:n}))};import{Box as tn,Text as Wn}from"ink";import Oe,{useEffect as _y,useMemo as $y}from"react";import{ulid as Ou}from"ulid";var ls=Ou(),Hy=()=>[...new Set([...v().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),jy=e=>ee.text({id:ls,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Wy=(e,t,n)=>ee.text({id:Ou(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),cs=[],_u=()=>{let e=cs.filter(n=>n.id!==ls).map(n=>n.id),t=cs.filter(n=>n.id===ls).map(n=>n.id);cs=[];for(let n of[...e,...t])E.deleteNode(n)},Vy=e=>{_u();let t=E.createNode(jy(v().rootNodeId));if(d(t)||!Ot(t.value))return logger.error("Could not attach help nodes");cs=[t.value,...e.map((n,r)=>Wy(n,r,ls)).map(E.createNode).filter(Q).map(({value:n})=>n).filter(Ot)],M.navigate({contextNode:t.value,selectedIndex:0})},$u=({width:e,height:t})=>{let n=$y(()=>Hy(),[]);_y(()=>(Vy(n),()=>{_u()}),[n]);let r=v().selectedIndex;return Oe.createElement(tn,{flexDirection:"column",marginTop:3,borderColor:h.secondary,borderStyle:"round",width:e,height:t-2},Oe.createElement(tn,{paddingX:1,justifyContent:"center"},Oe.createElement(Wn,{color:h.accent},"Help"),Oe.createElement(Wn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),Oe.createElement(tn,{paddingX:1,marginTop:1},Oe.createElement(tn,{width:20,justifyContent:"flex-end"},Oe.createElement(Wn,{color:h.secondary},"Key(s)")),Oe.createElement(tn,{flexGrow:1,width:40,paddingLeft:2},Oe.createElement(Wn,{color:h.secondary},"Action"))),Oe.createElement(tt,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return Oe.createElement(tn,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},Oe.createElement(tn,{width:20,justifyContent:"flex-end"},Oe.createElement(Wn,{color:h.accent},o)),Oe.createElement(tn,{flexGrow:1,width:40,paddingLeft:2},Oe.createElement(Wn,{color:c?h.primary:h.secondary2},s)))})))};import Gy from"chalk";import{Box as us,Text as Dt}from"ink";import qe from"react";var Hu=({width:e,height:t})=>qe.createElement(us,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},qe.createElement(Dt,{color:h.accent,bold:!0},"Initialize project"),qe.createElement(Dt,null,`This folder is not an ${Gy.hex(h.accent)("epiq")} project yet.`),qe.createElement(Dt,{color:h.primary},"To start tracking issues here, we need to initialize a new",qe.createElement(Dt,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json "),"file in this repository."),qe.createElement(us,{marginTop:1,flexDirection:"column"},qe.createElement(us,null,qe.createElement(Dt,{color:h.accent}," "),qe.createElement(Dt,{color:h.primary},"Type "),qe.createElement(Dt,{backgroundColor:h.secondary}," :init "))),qe.createElement(us,{marginTop:1},qe.createElement(Dt,{color:h.secondary2},"This will create, commit and push "),qe.createElement(Dt,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json ")));import{Box as ms,Text as Ct}from"ink";import Te from"react";var Ky=({isDone:e,command:t,value:n})=>Te.createElement(ms,null,Te.createElement(Ct,{color:h.accent,dimColor:e},e?" \u2714 ":" "),Te.createElement(Ct,{dimColor:e},"Type "),Te.createElement(Ct,{backgroundColor:h.secondary,dimColor:e}," "+t+" "),n!==void 0&&Te.createElement(Te.Fragment,null,Te.createElement(Ct,{dimColor:e}," "),Te.createElement(Ct,{color:h.secondary,dimColor:e},"<"+n+">"))),zy=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Ki({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Vt(),l=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:s,message:"Nice. Now pick your editor."},{key:"autosync",done:c,command:":config autosync",value:i,message:"Almost there. Configure auto sync."}],m=l.findIndex(f=>!f.done),p=m===-1?void 0:l[m];return Te.createElement(ms,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},Te.createElement(Ct,{color:h.accent,bold:!0},"Welcome! \u{1F539}"),Te.createElement(Ct,null,"Let's get you started - it's a breeze."),Te.createElement(Ct,{color:h.secondary2},"Remember - you can always search available commands by typing:",Te.createElement(Ct,{color:h.accent}," ? ")),p&&Te.createElement(Ct,{color:h.secondary2},p.message),Te.createElement(ms,{flexDirection:"column"},l.map((f,g)=>m===-1||g<=m?Te.createElement(ms,{key:f.key,marginBottom:1},Te.createElement(Ky,{isDone:f.done,command:f.command,value:f.done?zy(f.value):void 0})):null)))}import ys from"chalk";import{Box as Br,Text as Vn}from"ink";import xe from"react";import{Box as ps,Text as ju}from"ink";import nn from"react";import qy from"chalk";var Yy=e=>(E.getTag(e)?.name??"").length+3,Xy=e=>{let t=E.getContributor(e);return(t?qt(e,t.name):"").length+3},Wu=({width:e})=>{let{viewMode:t}=K(),n=j(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],l=At(c?.id??o.id,"TICKET"),m=Q(l)?l.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],g=m?.parentNodeId?!Vs(o.id,m.parentNodeId)&&t==="dense":!1,I=r.map((H,D)=>{let $=D===r.length-1,Ye=Y(H.id),we=$?Ye?.[s]?.title:void 0;return`${D?" / ":""}${H.title??""}${we?` \u25B8 ${we}`:""}`}).join(""),S=m?E.getCommentsByIssue(m.id):[],R=S.length?String(S.length).length+11:0,A=g?p.reduce((H,D)=>H+Yy(D),0)+f.reduce((H,D)=>H+Xy(D),0)+R:0,P=c?.id!=null&&!(t==="wide"&&T(c)),_=Math.max(0,e-A),w=I.substring(0,_)+(P?qy.hex(h.secondary2).dim(` ${He(c.id)}`):""),W=g?[...p.map(H=>nn.createElement(ps,{key:`tag-${H}`,paddingLeft:1},nn.createElement(Un,{id:H}))),...f.map(H=>nn.createElement(ps,{key:`assignee-${H}`,paddingLeft:1},nn.createElement(Yt,{id:H}))),S.length?nn.createElement(ps,{key:"comments",paddingLeft:1},nn.createElement(ju,{color:h.accent},"[",S.length," comment",S.length===1?"":"s","]")):null]:[];return nn.createElement(ps,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},nn.createElement(ju,{color:h.secondary2},w),W)};import{Box as Jy,Text as Vu}from"ink";import fs from"react";var Qy=({filters:e})=>fs.createElement(Jy,{columnGap:1},fs.createElement(Vu,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>fs.createElement(Vu,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Gu=fs.memo(Qy);import{Box as Zy,Text as gs}from"ink";import Dr from"react";function Ku(){let{eventLog:e,unappliedEvents:t}=j(),n=e.at(-1)?.id,r=Co(n??""),o=Q(r)?io(r.value):"INVALID DATE";return Dr.createElement(Zy,{paddingLeft:1},Dr.createElement(gs,{backgroundColor:h.accent,color:h.secondary}," Readonly "),Dr.createElement(gs,{color:h.accent}," "+t.length+" edits ago at "+o+"."),Dr.createElement(gs,{color:h.accent}," Resume with "),Dr.createElement(gs,{backgroundColor:h.accent,color:h.secondary}," ",":peek now"," "))}import{Box as eh,Text as zi}from"ink";import vs from"react";function zu(){let{replay:e}=j();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return vs.createElement(eh,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},vs.createElement(zi,{backgroundColor:h.accent,color:h.secondary}," \u25B6 REPLAY "),vs.createElement(zi,{color:h.secondary2},io(new Date(r))),vs.createElement(zi,{color:h.accent},`${t}/${n} edits`))}import qi from"chalk";import{Box as th,Text as qu}from"ink";import Yi,{useEffect as nh,useState as rh}from"react";var oh=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],sh=150,Yu=12,ih=.36,Xu=e=>{let t=e.replace("#","");return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}},ah=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},dh=(e,t,n)=>{let r=Xu(e),o=Xu(t);return ah({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},ch=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,s=e[r],i=e[Math.min(r+1,e.length-1)];return dh(s,i,o)};function Ju({syncStatus:e,autoSync:t}){let[n,r]=rh(0);nh(()=>{if(e.status!=="syncing"){r(0);return}let c=0,l=setInterval(()=>{c+=1;let m=(Math.sin(c*ih)+1)/2,p=Math.round(m*(Yu-1));r(f=>f===p?f:p)},sh);return()=>clearInterval(l)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:h.secondary2,failed:h.yellow,pending:h.secondary2,syncing:ch(oh,n/(Yu-1))??""}[e.status];return Yi.createElement(th,null,Yi.createElement(qu,null,qi.hex(h.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Yi.createElement(qu,null,qi.hex(i)("\u25CF")+qi.hex(h.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import nm from"chalk";import{Text as rm}from"ink";import om,{useEffect as ph,useState as fh}from"react";var rn="1.4.0";import Xi from"chalk";var lh="https://registry.npmjs.org/epiq/latest",Ji=null,Qu=0,uh=1e3*60*60*24,Zu=e=>e.replace(/^v/,""),mh=(e,t)=>{let n=Zu(e).split(".").map(Number),r=Zu(t).split(".").map(Number);for(let o=0;o<Math.max(n.length,r.length);o++){let s=n[o]??0,i=r[o]??0;if(s>i)return 1;if(s<i)return-1}return 0},em=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Ji&&Date.now()-Qu<uh)return Ji;try{let t=await fetch(lh);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let r=(await t.json()).version??null,o={current:e,latest:r,updateAvailable:r?mh(r,e)>0:!1};return Ji=o,Qu=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},tm=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Xi.hex(h.accent).dim(s):Xi.hex(h.secondary).dim(s)).join(Xi.hex(h.secondary2).dim("."))};function sm(){let[e,t]=fh({current:rn,latest:null,updateAvailable:!1});return ph(()=>{let n=!0;return em(rn).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?om.createElement(rm,{dimColor:!0,color:h.secondary2},rn+" "):om.createElement(rm,null,nm.hex(h.secondary2).dim(rn),nm.hex(h.accent).dim(" \u2197 "),tm(rn,e.latest))}function Fr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=j(),{userName:i,preferredEditor:c,autoSync:l}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",g=s?ln(s.currentLabel,Math.max(0,p)):"";return xe.createElement(Br,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?xe.createElement(Br,{paddingLeft:1},xe.createElement(Vn,{color:h.secondary2},g)):f?xe.createElement(Vn,null," "):o===y.PALETTE?xe.createElement(Br,null,xe.createElement(Vn,{color:h.accent},"Command Palette"),xe.createElement(Vn,{dimColor:!0,color:h.secondary2}," ","- search, select and press enter")):xe.createElement(Br,{paddingLeft:1},e.length>0?xe.createElement(Gu,{filters:e}):xe.createElement(Wu,{width:p})),n==="live"?xe.createElement(Br,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},xe.createElement(Ju,{autoSync:!!l,syncStatus:r}),xe.createElement(Vn,null,ys.hex(h.secondary2).dim("Mode: ")+ys.hex(h.secondary2).dim(o.padEnd(8," "))," "),xe.createElement(im,{icon:"@",value:i}),xe.createElement(im,{icon:"\u276F",value:c}),xe.createElement(sm,null)):"",n==="peek"?xe.createElement(Ku,null):"",n==="replay"?xe.createElement(zu,null):"")}function im({icon:e,value:t}){return xe.createElement(Vn,null,ys.dim(e)+ys.hex(h.accent)(` ${t??"-"} `))}import{Box as gh,Text as vh}from"ink";import Ur from"react";import{Box as hs,Text as Qi}from"ink";import on from"react";function Zi(){let e=j(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?z(t?.id):[];return on.createElement(hs,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:h.secondary,width:s},on.createElement(hs,{padding:1,paddingTop:0,paddingBottom:0},on.createElement(Qi,null,"Select a board:")),on.createElement(hs,{padding:1,flexDirection:"column"},i.map((c,l)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===l,f=z(c.id).flatMap(({id:g})=>Y(g)).length;return on.createElement(hs,{key:c.id??l},on.createElement(Qi,{color:m?h.accent:h.secondary2},on.createElement(ke,{isSelected:m})),on.createElement(Qi,{color:m?h.accent:h.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var yh=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=j(),l=n.find(({context:g})=>g==="BOARD"),f=s-1-3;return Ur.createElement(gh,{flexDirection:"row"},e.context==="WORKSPACE"?Ur.createElement(Zi,null):l?Ur.createElement(Uo,{height:f,width:i,swimlanes:(c[l.id]??[]).filter(g=>g!==void 0&&_t(g)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):Ur.createElement(vh,null))},am=Ur.memo(yh);import{useEffect as hh}from"react";var xh=e=>{hh(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=K();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:l}=v();l==="default"&&!c&&ho(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},dm=({autoSync:e})=>(xh(e),null);function ea({width:e,height:t}){let n=j(),{autoSync:r,viewMode:o}=Pa(),s=n.filters;if(n.mode===y.HELP)return ce.createElement(sn,{flexDirection:"column"},ce.createElement($u,{width:e,height:t}));if(n.mode===y.PALETTE)return ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{filters:s}),ce.createElement(Au,{width:e,height:t-2}),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Vt(),c=!i,l=i&&!n.hasProjectDefinition;if(c)return ce.createElement(sn,{flexDirection:"column"},ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{hideBreadCrumb:!0,filters:s}),ce.createElement(Ki,{height:t,width:e})),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(l)return ce.createElement(sn,{flexDirection:"column"},ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{hideBreadCrumb:!0,filters:s}),ce.createElement(Hu,{height:t,width:e})),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Ue(n.breadCrumb??[],"BOARD");if(Q(m)){let p=m.value.id,f=z(p).length,g=3,I=Math.floor(e/g),S=Math.floor(e/Math.max(f,1));e=Math.min(S,I)*Math.max(f,g)}return ce.createElement(sn,{flexDirection:"column"},ce.createElement(dm,{autoSync:r}),ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{filters:s}),ce.createElement(am,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import bh from"readline";var xs,bs,Nt,Ih=new Set([x.MoveCursorLeft,x.EraseInputWord,x.MoveCursorLeftOfWord,x.MoveCursorRight,x.MoveCursorRightOfWord,x.NavToPreviousContainer,x.NavToNextContainer,x.NavPreviousItem,x.NavNextItem,x.SetViewDense,x.SetViewWide,x.Confirm,x.Exit,x.Yank,x.InitCommandLine,x.InitCommandPalette,x.ExitCommandLine,x.CaptureInput,x.EraseInput,x.EraseInputWord,x.HideHelp,x.ViewHelp,x.SetViewDense,x.SetViewWide,x.GetLastCommandFromHistory,x.GetNextCommandFromHistory,x.AutoCompleteCommand]),Eh=new Set([x.NavPreviousItem,x.NavNextItem,x.NavToPreviousContainer,x.NavToNextContainer,x.Confirm,x.Exit,x.InitCommandPalette,x.InitMove,x.MoveNextItem,x.MovePreviousItem,x.MoveToNextContainer,x.MoveToPreviousContainer,x.Delete,x.AddItem,x.EditTitle,x.EditDescription,x.ConfirmMove,x.Edit,x.ViewHelp,x.Yank]),cm=async e=>{if(e.ctrl&&e.name==="c")return M.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=v(),s=yc(e,n);if(!s||r&&!Ih.has(s)||o==="replay"&&n===y.DEFAULT&&Eh.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},Sh=()=>async function(t,n){n.name!=="escape"&&(Nt&&(clearTimeout(Nt),Nt=void 0),await cm(n))},Ch=()=>async function(t){if(t.length===1&&t[0]===27){Nt&&clearTimeout(Nt),Nt=setTimeout(()=>{cm({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),Nt=void 0},25);return}Nt&&(clearTimeout(Nt),Nt=void 0)};function lm(){xs&&process.stdin.removeListener("keypress",xs),bs&&process.stdin.removeListener("data",bs),xs=Sh(),bs=Ch(),bh.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",bs),process.stdin.on("keypress",xs)}async function um(){try{let e=Ft();Q(e)&&Me(e.value);let t=_e(process.cwd()),n=[];if(Q(t)){let s=Re({repoRoot:t.value});if(d(s))return fn(3,s.message);let i=Sn(),c=await cn({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return fn(3,c.message);let l=await F({cwd:s.value,args:["pull","--ff-only"]});d(l)&&logger.info(3,l.message);let m=je(s.value);if(d(m))return fn(3,m.message);n=m.value}let r=pn(n);if(d(r))return fn(4,r.message);C({hasProjectDefinition:Q(t),hasInitializingEvents:!!n.length});let o=ta();return d(o)?fn(6,o.message):(lm(),u("Booted Epiq",void 0))}catch(e){return fn(0,go(e))}}Wc();var Th=`${an.bold("Epiq CLI")}
60
+ `).map(f=>f.trim()).filter(Boolean);if(o.length===0)return a("No changed files found for this commit");if(o.length>Xv)return a(`Commit touches ${o.length} files \u2014 too many for a side-by-side view`);let s=Hn.join(jl.tmpdir(),"epiq","commit-diffs",t),i=await Promise.all(o.map(async(f,g)=>{let[I,S]=await Promise.all([Hl(e,`${t}~1`,f),Hl(e,t,f)]),R=Hn.basename(f),A=Hn.join(s,String(g),"before",R),P=Hn.join(s,String(g),"after",R);return Di(A)||(be.writeToFile(A,I),await Bi(A,292)),Di(P)||(be.writeToFile(P,S),await Bi(P,292)),{beforePath:A,afterPath:P}})),[c,...l]=i;if(!c)return a("No changed files found for this commit");let m=await Si(n,c.beforePath,c.afterPath,"new");if(d(m)||l.length===0)return m;await new Promise(f=>setTimeout(f,Jv));let p=await Promise.all(l.map(({beforePath:f,afterPath:g})=>Si(n,f,g,"reuse")));for(let f of p)d(f)&&logger.error(`Failed to open an additional diff tab for ${t}: ${f.message}`);return m},Gl=async e=>{if(!qv(e.sha))return a("Invalid commit sha");let t=Fi(e.repoRoot);if(d(t))return a(t.message);let n=t.value,r=$o()[0];if(r&&Ei(r)){let o=await Qv(n,e.sha,r);if(!d(o))return o;logger.error(`Side-by-side diff failed for ${e.sha}, falling back to unified diff: ${o.message}`)}return Yv(n,e.sha)},Kl=e=>{let t=je(e);if(d(t))return a(t.message);let n=it();if(d(n))return a(n.message);Zo=null;let o=st(t.value).filter(d);return o.length>0?a(o.map(s=>s.message).join(", ")):(C({readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),u("Restored live state",!0))},Zv=(e,t)=>{Zo=null;let n=Kl(e);return d(n)?a(`${t} (recovery to live also failed: ${n.message})`):a(t)},zl=e=>en(async()=>{let t=Ui(e.repoRoot);if(d(t))return a(t.message);let n=uo(t.value,e.targetTime);if(d(n))return a(n.message);let{appliedEvents:r,unappliedEvents:o}=n.value,s=it();if(d(s))return s;let c=st(r).filter(d);return c.length>0?Zv(t.value,c.map(l=>l.message).join(", ")):(C({readOnly:!0,timeMode:"peek",unappliedEvents:o,replay:null}),Zo=e.targetTime,u("Checked out historical state",{asOfTime:e.targetTime}))}),ql=(e={})=>en(async()=>{let t=Ui(e.repoRoot);if(d(t))return a(t.message);let n=Kl(t.value);return d(n)?a(n.message):u("Returned to live state",!0)});var _i=()=>{let e=Ft();return d(e)?xt:e.value.attachmentMaxKb??xt},$i=e=>{let t=_e(e??process.cwd());return d(t)?a(t.message):u("Resolved Epiq repo root",t.value)},Ne=async(e,t)=>{let n=$i(e);if(d(n))return n;let r=Re({repoRoot:n.value});if(d(r))return a(r.message);let o=Sn(),s=await cn({repoRoot:n.value,stateBranchRoot:r.value,stateBranchName:o.stateBranch});if(d(s))return a(s.message);if(t?.pull??!1){let l=await F({cwd:r.value,args:["pull","--ff-only"]});d(l)&&se.info(3,l.message)}let i=je(r.value);if(d(i))return a(i.message);let c=pn(i.value);return d(c)?a(c.message):u("Booted Epiq state",{repoRoot:n.value,stateBranchRoot:r.value})},Ae=()=>{let e=Ft();return d(e)?a(e.message):e.value.userId?e.value.userName?u("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},Fe=()=>{let e=We();return d(e)?a(e.message):e},Xl=e=>(e.props.tags??[]).map(t=>E.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ue(t.name)})),Hi=()=>{let e=We(),t=d(e)?[]:e.value.eventLog??[],n=new Map;for(let r of t)r.userId&&r.userName&&n.set(r.userId,r.userName);return n},Jl=(e,t)=>{let n=new Map(e);for(let r of Object.values(t)){if(r.tombstoned){n.set(r.id,r.name);continue}n.set(r.id,Fn(r.name,n.get(r.id))??r.name)}return n},Ql=(e,t=new Map)=>(e.props.assignees??[]).map(n=>E.getContributor(n)).filter(n=>n!=null).map(n=>{let r=n.tombstoned?n.name:Fn(n.name,t.get(n.id))??n.name;return{id:n.id,name:r,color:ue(r)}});var Zl=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Fe();if(d(n))return n;let r=n.value.nodes,o=Hi(),s=Object.values(r).filter(T).filter(i=>!i.isDeleted).filter(i=>e.includeClosed||i.parentNodeId!==ve).filter(i=>e.boardId?(i.parentNodeId?r[i.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).map(i=>({id:i.id,ref:He(i.id),title:Ze(i.title),description:i.props.description??"",parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===ve,readonly:!!i.readonly,tags:Xl(i),assignees:Ql(i,o)}));return u("Listed issues",s)},eu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=Pn(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let s=jo({name:e.title,parent:e.parentId,user:n.value,rank:o.value});if(d(s))return s;let i=[...s.value],c=i.find(f=>f.action==="add.issue")?.payload.id;if(!c)return a("Unable to determine created issue id");e.description&&i.push({id:q(),...n.value,action:"edit.description",payload:{id:c,md:e.description}});let l=[];for(let f of e.tagNames??[]){let g=Ze(f).trim();if(!g||l.some(R=>R.name===g))continue;let I=Object.values(r.value.tags).find(R=>R.name===g),S=I?.id??q();I||i.push({id:q(),...n.value,action:"create.tag",payload:{id:S,name:g}}),i.push({id:q(),...n.value,action:"add.issue.tag",payload:{id:c,tag:S}}),l.push({id:S,name:g})}let m=[];for(let f of e.assigneeNames??[]){let g=Ze(f).trim();if(!g||m.some(R=>R.name===g))continue;let I=Object.values(r.value.contributors).find(R=>R.name===g),S=I?.id??q();I||i.push({id:q(),...n.value,action:"create.contributor",payload:{id:S,name:g}}),i.push({id:q(),...n.value,action:"add.issue.assignee",payload:{id:c,assignee:S}}),m.push({id:S,name:g})}let p=U(i,t.value.stateBranchRoot);return d(p)?a(p.message):u("Created issue",{id:c,title:e.title,parentId:e.parentId,description:e.description??"",tags:l,assignees:m})},tu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=mn(ve,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:q(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ve,rank:r.value}},s=U([o],t.value.stateBranchRoot);return d(s)?a(s.message):u("Closed issue",{id:e.issueId})},nu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Target node is not issue");if(o.parentNodeId!==ve)return a("Issue is not closed");let s=Oo(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ve)return a("Previous parent resolves to closed swimlane");let i=r.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=mn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let l={id:q(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=U([l],t.value.stateBranchRoot);return d(m)?a(m.message):u("Reopened issue",{id:o.id,parentId:i.id})},ru=async e=>{let t=$i(e.repoRoot);if(d(t))return t;let n=Ae();if(d(n))return n;let r=Re({repoRoot:t.value});if(d(r))return r;let o=je(r.value);if(d(o))return o;let s=pn(o.value);if(d(s))return s;let i=mn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:q(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},l=U([c],r.value);return d(l)?a(l.message):u("Moved issue",{id:e.issueId,parentId:e.parentId})};var es=async(e={})=>{Jo();let t=$i(e.repoRoot);if(d(t))return a("Sync failed");let n=Ae();if(d(n))return n;let r=await yo({cwd:t.value,ownEventFileName:un(n.value)});return d(r)?(ki(r.message),r):(Qo(),u("Synced",r.value))};var Tr=()=>{let e=Fe();if(d(e))return e;let t=at(),n=t.mode!=="live",r=Object.values(e.value.nodes),o=r.filter(g=>Zr(g)&&!g.isDeleted),s=Hi(),i=new Map,c=new Map;for(let g of r)if(!g.isDeleted){if(_t(g)&&g.parentNodeId){let I=i.get(g.parentNodeId)??[];I.push(g),i.set(g.parentNodeId,I)}if(T(g)&&g.parentNodeId){let I=c.get(g.parentNodeId)??[];I.push(g),c.set(g.parentNodeId,I)}}let l=Ft();if(d(l))return l;let m={};for(let g of r.filter(T))g.isDeleted||(m[g.id]=E.getCommentsByIssue(g.id).map(I=>{let S=E.getContributor(I.authorId);return{id:I.id,issueId:I.issue,body:I.md,author:{id:I.authorId,name:S?.name??"Unknown",color:ue(S?.name??I.authorId)},createdAt:Yl(I.id)}}));let p=new Map;for(let g of e.value.eventLog)g.action==="add.issue.attachment"&&p.set(g.payload.id,g.payload.author);let f={};for(let g of r.filter(T))g.isDeleted||(f[g.id]=E.getAttachmentsByIssue(g.id).map(I=>({id:I.id,issueId:I.issue,name:I.name,fileName:kn(I.hash,I.ext),bytes:I.bytes,createdAt:Yl(I.id),canDelete:p.get(I.id)===l.value.userId})));return u("Retrieved Epiq GUI state",{boards:o.sort((g,I)=>g.rank.localeCompare(I.rank)).map(g=>({id:g.id,ref:He(g.id),title:g.title,swimlanes:(i.get(g.id)??[]).sort((I,S)=>I.rank.localeCompare(S.rank)).map(I=>({id:I.id,title:I.title,readonly:!!I.readonly||n,issues:(c.get(I.id)??[]).sort((S,R)=>S.rank.localeCompare(R.rank)).map(S=>({id:S.id,ref:He(S.id),title:Ze(S.title),description:S.props.description??"",readonly:!!S.readonly||n,tags:Xl(S),assignees:Ql(S,s),parentNodeId:S.parentNodeId,isClosed:S.parentNodeId===ve})),parentNodeId:I.parentNodeId}))})),tags:Object.values(e.value.tags).map(g=>({...g,color:ue(g.name)})),contributors:Object.values(e.value.contributors).map(g=>({...g,color:ue(g.name)})),user:{name:l.value.userName??"",id:l.value.userId??"",color:ue(l.value.userName??"")},commentsByIssueId:m,attachmentsByIssueId:f,attachmentMaxKb:_i(),timeTravel:t})},dt=async(e={})=>{if(at().mode!=="live")return Tr();let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:Tr()},ou=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=o.props.description??"";if(s===e.description)return u("No changes made",{id:e.issueId,description:s});let i={id:q(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue description",{id:e.issueId,description:e.description})},su=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Ze(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return u("No changes made",{id:e.issueId,title:s});let i={id:q(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=U([i],t.value.stateBranchRoot);return d(c)?a(c.message):u("Edited issue title",{id:e.issueId,title:s})},iu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Ze(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(r.value.tags).find(p=>p.name===s),c=i?.id??q(),l=[...i?[]:[{id:q(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:q(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=U(l,t.value.stateBranchRoot);return d(m)?a(m.message):u("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},au=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Untag target must be an issue");if(o.readonly)return a("Cannot untag readonly issue");if(!r.value.tags[e.tagId])return a("Tag not found");let s={id:q(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue tag",{id:e.issueId,tagId:e.tagId})},du=async(e,t)=>{let n=je(e);if(d(n))return;let r;for(let o of n.value)o.userId===t&&(r=o.userName??r);return r===void 0?void 0:{id:t,name:r}},cu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=e.self?n.value.userId:e.assigneeId;if(s){let R=r.value.contributors[s],A=R?void 0:await du(t.value.stateBranchRoot,s);if(!R&&!A)return a("Unknown assignee id");let P=R??A,_=[...R?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:P.id,name:P.name}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:P.id}}],w=U(_,t.value.stateBranchRoot);return d(w)?a(w.message):u("Added issue assignee",{id:e.issueId,assignee:{id:P.id,name:P.name}})}let i=Ze(e.assigneeName??"").trim();if(!i)return a("Provide assigneeId, self or assigneeName");let l=[...Jl(Hi(),r.value.contributors).entries()].filter(([,R])=>R===i);if(l.length>1)return a(`"${i}" matches ${l.length} contributors (${l.map(([R])=>R).join(", ")}). Assign by assigneeId to choose.`);let m=l[0];if(!m&&!e.createUnlinked)return a(`No contributor named "${i}". Assign by id, or pass createUnlinked to add them as an external assignee.`);let[p=q(),f=i]=m??[],I=[...!!r.value.contributors[p]?[]:[{id:q(),...n.value,action:"create.contributor",payload:{id:p,name:f}}],{id:q(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:p}}],S=U(I,t.value.stateBranchRoot);return d(S)?a(S.message):u("Added issue assignee",{id:e.issueId,assignee:{id:p,name:f}})},lu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;if(!r.value.contributors[e.contributorId])return a("Contributor not found");if(await du(t.value.stateBranchRoot,e.contributorId))return a("Cannot remove a contributor who has authored events \u2014 their name appears throughout the log");let i=[{id:q(),...n.value,action:"tombstone.contributor",payload:{id:e.contributorId}}],c=U(i,t.value.stateBranchRoot);return d(c)?a(c.message):u("Tombstoned contributor",{id:e.contributorId,name:to})};var uu=async(e={})=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=je(t.value.stateBranchRoot);if(d(o))return a(o.message);let s=e.boardId?Oi(o.value,e.boardId):o.value,i=new Map,c=new Set,l=new Set;for(let g of o.value)g.userId&&l.add(g.userId);for(let g of s)g.userId&&(i.set(g.userId,g.userName??""),c.add(g.userId));let m=r.value.contributors,f=[...Jl(i,m).entries()].map(([g,I])=>({id:g,name:I,color:ue(I),isSelf:g===n.value.userId,isExternal:!c.has(g),isRemoved:m[g]?.tombstoned===!0,hasAuthoredAnywhere:l.has(g)}));return u("Listed board contributors",f)},mu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Unassign target must be an issue");if(o.readonly)return a("Cannot unassign readonly issue");if(!r.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:q(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=U([s],t.value.stateBranchRoot);return d(i)?a(i.message):u("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},ts=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Comment target must be an issue");if(o.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=q(),c={id:q(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Added issue comment",{id:i,issueId:e.issueId,body:s})},ns=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!o)return a("Unable to resolve comment");if(o.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!T(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return u("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},pu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!T(o))return a("Attachment target must be an issue");if(o.readonly)return a("Cannot attach to readonly issue");let s=Buffer.from(e.dataBase64??"","base64"),i=qd(t.value.stateBranchRoot,s,_i());if(d(i))return i;let c=Ze(e.name??"").trim()||"image",l=q(),m={id:q(),...n.value,action:"add.issue.attachment",payload:{id:l,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=U([m],t.value.stateBranchRoot);return d(p)?a(p.message):u("Added issue attachment",{id:l,issueId:e.issueId,fileName:kn(i.value.hash,i.value.ext),bytes:i.value.bytes})},fu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});if(d(t))return t;let n=Ae();if(d(n))return n;let r=Fe();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.attachment"&&m.payload.id===e.attachmentId);if(!o)return a("Unable to resolve attachment");if(o.payload.author!==n.value.userId)return a("You can only delete your own attachments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!T(s))return a("Attachment target must be an issue");if(s.readonly)return a("Cannot delete attachment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.attachment"&&m.payload.id===e.attachmentId))return u("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:q(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},l=U([c],t.value.stateBranchRoot);return d(l)?a(l.message):u("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},gu=async e=>{let t=await Ne(e.repoRoot,{pull:!1});return d(t)?t:Yd(t.value.stateBranchRoot,e.fileName,_i())};var vu=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=rr();if(d(p))return se.error(p.message);let{autoSync:f,userName:g,preferredEditor:I}=p.value;return!!(f&&g&&I)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await en(async()=>{at().mode==="live"&&(await es({repoRoot:e.repoRoot}),Ut({type:"state",payload:await dt({repoRoot:e.repoRoot})}))})}finally{o=!1,s&&(s=!1,c())}}},l=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=rr();if(d(p))return se.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:l,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as ey}from"ws";var ty=new Set(["sync","issues:create","issues:move","issue:close","issue:reopen","issue:edit:title","issue:edit:description","issue:tag:add","issue:tag:remove","contributor:remove","issue:assignee:add","issue:assignee:remove","issue:comment:add","issue:comment:delete"]),yu=()=>{let e=Tr();Ut({type:"state",payload:e})},de=(e,t)=>{e.send(JSON.stringify(t))},rs=async(e,t)=>de(e,{type:"state",payload:await dt({repoRoot:t})}),ny=async(e,t)=>{let n=()=>de(e,{type:"state",payload:Tr()});if(at().mode!=="live")return n();let r=await dt({repoRoot:t});return at().mode!=="live"?n():de(e,{type:"state",payload:r})},ct=async(e,t,n,r,o)=>{if(de(e,{type:r,payload:o}),d(o))return de(e,{type:"failed",payload:o.message});n(),ny(e,t)},hu=(e,t,{onStateChanged:n})=>{new ey({server:e,path:"/ws"}).on("connection",o=>{Oa(o),o.on("message",async s=>{let i=async c=>{let{type:l}=c;if(l==="timeline:get"){let{requestId:m,...p}=c.payload??{};return de(o,{type:"timeline",requestId:m,payload:await Wl({repoRoot:t,...p})})}if(l==="commits:get"){let{requestId:m,...p}=c.payload??{};return de(o,{type:"commits",requestId:m,payload:await Vl({repoRoot:t,...p})})}if(l==="commit:inspect")return de(o,{type:"commit:inspect:result",payload:await Gl({repoRoot:t,sha:c.payload.sha})});if(l==="time-travel:scrub"){let m=await zl({repoRoot:t,targetTime:c.payload.targetTime});return de(o,{type:"time-travel:result",payload:m}),d(m)?void 0:yu()}if(l==="time-travel:live"){let m=await ql({repoRoot:t});return de(o,{type:"time-travel:result",payload:m}),d(m)?void 0:yu()}if(l==="state:get")return rs(o,t);if(l==="sync"){let m=await es({repoRoot:t});return de(o,{type:"sync:result",payload:m}),n(),rs(o,t)}if(l==="issue:comment:add"){let m=await ts({repoRoot:t,...c.payload});return ct(o,t,n,"issue:comment:add:result",m)}if(l==="issue:comment:delete"){let m=await ns({repoRoot:t,...c.payload});return de(o,{type:"issue:comment:delete:result",payload:m}),d(m)?de(o,{type:"failed",payload:m.message}):(n(),rs(o,t))}if(l==="issue:edit:description"){let m=await ou({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:description:result",m)}if(l==="issue:edit:title"){let m=await su({repoRoot:t,...c.payload});return ct(o,t,n,"issue:edit:title:result",m)}if(l==="issue:tag:add"){let m=await iu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:add:result",m)}if(l==="issue:tag:remove"){let m=await au({repoRoot:t,...c.payload});return ct(o,t,n,"issue:tag:remove:result",m)}if(l==="contributor:remove"){let m=await lu({repoRoot:t,...c.payload});return ct(o,t,n,"contributor:remove:result",m)}if(l==="contributors:get")return de(o,{type:"contributors",payload:await uu({repoRoot:t,...c.payload})});if(l==="issue:assignee:add"){let m=await cu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:add:result",m)}if(l==="issue:assignee:remove"){let m=await mu({repoRoot:t,...c.payload});return ct(o,t,n,"issue:assignee:remove:result",m)}if(l==="issues:list")return de(o,{type:"issues",payload:await Zl({repoRoot:t})});if(l==="issues:create"){let m=await eu({...c.payload,repoRoot:t});return de(o,{type:"issues:create:result",payload:m}),d(m)?Ut({type:"failed",payload:m.message}):(Ut({type:"issue:created",payload:m.value}),n(),rs(o,t))}if(l==="issues:move"){if(!c.payload.position)return de(o,{type:"error",message:"Missing move position"});let m=await ru({...c.payload,repoRoot:t});return ct(o,t,n,"issues:move:result",m)}if(l==="issue:close"){if(!c.payload.issueId)return de(o,{type:"error",message:"Missing issueId"});let m=await tu({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:close:result",m)}if(l==="issue:reopen"){if(!c.payload.issueId)return de(o,{type:"error",message:"Missing issueId"});let m=await nu({repoRoot:t,issueId:c.payload.issueId});return ct(o,t,n,"issue:reopen:result",m)}return de(o,{type:"error",message:"Unknown message type"})};try{let c=JSON.parse(s.toString());return ty.has(c.type)?await en(async()=>at().mode!=="live"?de(o,{type:"failed",payload:"Read-only while viewing history"}):i(c)):await i(c)}catch(c){return de(o,{type:"error",message:c instanceof Error?c.message:String(c)})}})})};var sy=En.dirname(oy(import.meta.url)),iy=process.env.IS_LOCAL==="true"?En.resolve(process.cwd(),"dist/gui"):En.join(sy,"gui"),os,ay=async()=>(os===void 0&&(os=await import("node:sea").catch(()=>null)),os?.isSea()?os:null),fe=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},dy=e=>fe(e,409,{isError:!0,message:"Read-only while viewing history"}),ss=(e,t)=>en(async()=>at().mode!=="live"?dy(e):t()),xu=async(e,t=1024*1024)=>new Promise((n,r)=>{let o="",s=0;e.on("data",i=>{if(s+=i.length,s>t){e.destroy(),r(new Error("Request body too large"));return}o+=i}),e.on("end",()=>{try{n(o?JSON.parse(o):{})}catch{r(new Error("Invalid JSON body"))}}),e.on("error",r)}),cy=2*1024*1024,ly={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},uy=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":"application/octet-stream",bu=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=En.resolve(iy),o=En.resolve(r,n),s=En.relative(r,o);if(s.startsWith("..")||En.isAbsolute(s))return fe(t,403,{isError:!0,message:"Forbidden"});let i=await ay();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await Iu(o);return t.writeHead(200,{"content-type":uy(o)}),t.end(c)}catch{return fe(t,404,{isError:!0,message:`Not found: ${n}`})}},my=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=l=>{if(e.off("listening",c),l.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(l)},c=()=>{e.off("error",i);let l=e.address();if(!l||typeof l=="string"){r(new Error("Unable to resolve address"));return}n(l.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),Eu=async e=>{let t=ry.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return fe(s,200,await dt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await xu(o);if(!c.issueId||!c.body?.trim())return fe(s,400,{isError:!0,message:"Missing issueId or body"});let l=c.issueId,m=c.body;return await ss(s,async()=>{let p=await ts({repoRoot:e.repoRoot,issueId:l,body:m});return d(p)?fe(s,400,{isError:!0,message:p.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="POST"&&i.pathname==="/api/attachments")try{let c=await xu(o,cy);if(!c.issueId||!c.dataBase64)return fe(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let l=c.issueId,m=c.dataBase64,p=c.name??"";return await ss(s,async()=>{let f=await pu({repoRoot:e.repoRoot,issueId:l,name:p,dataBase64:m});return d(f)?fe(s,400,{isError:!0,message:f.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))})}catch(c){return fe(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add attachment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/attachments/")){let c=decodeURIComponent(i.pathname.replace("/api/attachments/",""));return c?ss(s,async()=>{let l=await fu({repoRoot:e.repoRoot,attachmentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing attachment id"})}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),l=await gu({repoRoot:e.repoRoot,fileName:c});if(d(l))return fe(s,404,{isError:!0,message:l.message});try{let m=await Iu(l.value.filePath);return s.writeHead(200,{"content-type":ly[l.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return fe(s,404,{isError:!0,message:"Attachment blob not found"})}}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));return c?ss(s,async()=>{let l=await ns({repoRoot:e.repoRoot,commentId:c});return d(l)?fe(s,400,{isError:!0,message:l.message}):fe(s,200,await dt({repoRoot:e.repoRoot}))}):fe(s,400,{isError:!0,message:"Missing comment id"})}return i.pathname.startsWith("/board/")?bu("/",s):bu(i.pathname,s)});try{await my(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=vu({repoRoot:e.repoRoot});hu(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):u("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Su=async e=>{let t=Ft();Q(t)&&Me(t.value);let n=await Eu({...e,boardId:""});if(d(n))return n;let{url:r}=n.value;return console.log(`Epiq GUI running at ${py.cyan(r)}`),La(r),u("Started GUI",{url:r})};import{Box as sn}from"ink";import ce from"react";import{Box as ji,Text as wr}from"ink";import lt,{useEffect as fy,useMemo as gy}from"react";import{ulid as vy}from"ulid";var Cu=({text:e,match:t,color:n,highlightColor:r=h.secondary,dimColor:o=!1})=>{if(!t)return lt.createElement(wr,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?lt.createElement(wr,{color:n,dimColor:o},e):lt.createElement(wr,{color:n,dimColor:o},e.slice(0,c),lt.createElement(wr,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Nu=vy(),yy=e=>`${e}`,hy=e=>{let{pendingNavTarget:t}=Jt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ae(b.NONE,{breadCrumb:n,contextNode:r,readOnly:v().readOnly,selectedNode:o}));return[...new Set(Object.values(b))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==b.PALETTE).map(i=>{let c=wo(i),l=zo.find(m=>m.intent===c);return{command:i,description:l?.description??`[${i}] Run command`,isAvailable:s.has(i)}}).filter(i=>i.command.toLowerCase().startsWith(e)||e.length>=2&&i.description.toLowerCase().includes(e)).sort((i,c)=>i.isAvailable!==c.isAvailable?i.isAvailable?-1:1:i.command.localeCompare(c.command))},xy=e=>ee.text({id:Nu,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),by=(e,t,n)=>ee.text({id:yy(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Wi=[],Iy=e=>{Ru();let t=E.createNode(xy(v().rootNodeId));d(t)||!Ot(t.value)||(Wi=[t.value,...e.map((n,r)=>by(n,r,Nu)).map(E.createNode).filter(Q).map(({value:n})=>n).filter(Ot)],M.navigate({contextNode:t.value,selectedIndex:0}))},Ru=()=>{let e=Wi.map(t=>t.id);Wi=[];for(let t of e)E.deleteNode(t)};function Au({width:e,height:t}){let r=gc().value.trim().toLowerCase(),o=gy(()=>hy(r),[r]);fy(()=>(Iy(o),()=>{Ru()}),[o]);let s=v().selectedIndex;return lt.createElement(ji,{flexDirection:"column",width:e,height:t-2},lt.createElement(tt,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let l=c===s,m=i.isAvailable?h.accent:h.secondary2,p=i.isAvailable?"":"[unavailable] ";return lt.createElement(ji,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:h.secondary,borderStyle:"single"},lt.createElement(wr,{color:m,dimColor:!i.isAvailable},l?"\u276F ":" ",lt.createElement(Cu,{text:Va(i.command),match:r,color:m,dimColor:!i.isAvailable})),lt.createElement(ji,{paddingLeft:2},lt.createElement(Cu,{text:p+i.description,match:r.length>=2?r:"",color:l&&i.isAvailable?h.primary:h.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Oy}from"ink";import ds from"react";import Pr from"chalk";import{Box as Vi,Text as Tu}from"ink";import Mr,{useEffect as Ey,useMemo as Sy,useState as Cy}from"react";var wu=Pr.hex(h.secondary),Ny=Pr.inverse,Ry=Pr.inverse.hex(h.secondary2),Ay={hint:"",hints:[],overlap:0,remainder:""},Pu=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},Ty=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=ue(t);return{bg:r=>Pr.bgHex(n).black(r),bgCursor:r=>Pr.bgHex(n).inverse.black(r)}}return zs(t)},wy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Pu({value:e,command:t});if(!r)return null;let s=e.slice(r.end).match(/^\s*/)?.[0].length??0,i=r.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},Mu=()=>({value:Le.value,cursorPosition:Le.cursorPosition,commandIsPending:Le.commandIsPending,autoCompletion:Le.commandMeta.autoCompletion??Ay,infoMessage:Le.commandMeta.infoMessage,validationStatus:Le.commandMeta.validity,command:Le.commandMeta.command,inputString:Le.commandMeta.inputString,modifier:Le.commandMeta.modifier}),My=(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,Lu=({width:e,mode:t})=>{let[n,r]=Cy(Mu());Ey(()=>{let S=()=>{let A=Mu();r(P=>My(P,A)?P:A)},R=li(S);return S(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:l,command:m,modifier:p,validationStatus:f}=n,g=c&&f===bt.Invalid,I=Sy(()=>{let S=Math.max(0,Math.min(s,o.length)),R=Pu({value:o,command:m}),A=wy({value:o,command:m,modifier:p}),P=m?zs(m):null,_=Ty({command:m,modifier:p}),w=(ge,me)=>{let Gn=R&&me>=R.start&&me<R.end,Kn=A&&me>=A.start&&me<A.end;return Gn&&P?P.fg(ge):Kn&&_?_.bg(ge):ge},W=(ge,me)=>{let Gn=R&&me>=R.start&&me<R.end,Kn=A&&me>=A.start&&me<A.end;return Gn&&P?P.fgCursor(ge):Kn&&_?_.bgCursor(ge):Ny(ge)},H=o.slice(0,S),D=o[S]??" ",$=S<o.length?o.slice(S+1):"",Ye=Array.from(H).map((ge,me)=>w(ge,me)).join(""),we=W(D,S),Xe=Array.from($).map((ge,me)=>w(ge,S+1+me)).join("");if(l.hint){let ge=l.hint[l.overlap]??D;we=Ry(ge),Xe=wu(l.remainder.slice(1)+$)}return wu(t===y.PALETTE?"?":":")+Ye+we+Xe},[o,s,l,m,p]);return Mr.createElement(Vi,{flexDirection:"column",justifyContent:"flex-start"},Mr.createElement(Vi,{flexDirection:"column",paddingX:1,borderColor:h.secondary,borderStyle:"round",width:e},Mr.createElement(Vi,null,Mr.createElement(Tu,null,I),i&&Mr.createElement(Tu,{wrap:"truncate",color:g?h.red:h.secondary2},` ${i} `))))};import{Box as Py,Text as Ly}from"ink";import ku from"react";var ky=(e,t)=>{let n=[],r=0;for(let o of e){let i=(n.length>0?" | ":"").length+o.length;if(r+i>t-4)break;n.push(o),r+=i}return n},Du=({width:e,availableHints:t})=>{let n=ky(t,e).join(" | ");return ku.createElement(Py,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1},ku.createElement(Ly,{color:h.secondary2},n.length?n:"\xA0"))};import{Box as Dy,Text as is}from"ink";import Lr,{useEffect as By,useRef as jn,useState as Fy}from"react";var Uy=40,as=.3,Gi="\u2500",Bu=1,Fu=16,Uu=({width:e})=>{let{replay:t}=j(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*Bu,[c,l]=Fy(0),m=jn(r);m.current=r;let p=jn(0),f=jn(0),g=jn(0),I=jn(0),S=jn(0);if(By(()=>{if(!n){p.current=0,g.current=0,I.current=0,S.current=0,l(0);return}p.current=m.current,f.current=Date.now(),g.current=m.current;let w=setInterval(()=>{let W=Date.now(),H=m.current;if(H!==g.current){let Xe=H-g.current,ge=W-f.current;if(Xe<0)I.current=0,S.current=0;else if(Xe>0&&ge>0){let me=Xe/ge;I.current=I.current===0?me:I.current*(1-as)+me*as,S.current=S.current===0?Xe:S.current*(1-as)+Xe*as}p.current=H,f.current=W,g.current=H}let D=W-f.current,$=Math.min(S.current,I.current*D),Ye=Math.min(1,p.current+$),we=Math.round(Ye*i);l(Xe=>Xe===we?Xe:we)},Uy);return()=>clearInterval(w)},[n,i]),!t)return null;let R=w=>{let W=s>1?w/(s-1):0,H=Math.round(W*(Fu-1))/(Fu-1);return no(H)},A=Math.min(s,Math.floor(c/Bu)),P=[];for(let w=0;w<A;w++){let W=R(w),H=P[P.length-1];H&&H.color===W?H.text+=Gi:P.push({text:Gi,color:W})}let _=Gi.repeat(Math.max(0,s-A));return Lr.createElement(Dy,{width:e,borderStyle:"round",borderColor:h.secondary,paddingX:1,columnGap:1},Lr.createElement(is,{color:h.secondary2},"\u25B6"),Lr.createElement(is,null,P.map((w,W)=>Lr.createElement(is,{key:W,color:w.color},w.text)),Lr.createElement(is,{color:h.secondary,dimColor:!0},_)))};var kr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=j(),o=t===y.COMMAND_LINE||t===y.PALETTE;return ds.createElement(Oy,null,o?ds.createElement(Lu,{width:e,mode:t}):r==="replay"?ds.createElement(Uu,{width:e}):ds.createElement(Du,{width:e,mode:t,availableHints:n}))};import{Box as tn,Text as Wn}from"ink";import Oe,{useEffect as _y,useMemo as $y}from"react";import{ulid as Ou}from"ulid";var ls=Ou(),Hy=()=>[...new Set([...v().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),jy=e=>ee.text({id:ls,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Wy=(e,t,n)=>ee.text({id:Ou(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),cs=[],_u=()=>{let e=cs.filter(n=>n.id!==ls).map(n=>n.id),t=cs.filter(n=>n.id===ls).map(n=>n.id);cs=[];for(let n of[...e,...t])E.deleteNode(n)},Vy=e=>{_u();let t=E.createNode(jy(v().rootNodeId));if(d(t)||!Ot(t.value))return logger.error("Could not attach help nodes");cs=[t.value,...e.map((n,r)=>Wy(n,r,ls)).map(E.createNode).filter(Q).map(({value:n})=>n).filter(Ot)],M.navigate({contextNode:t.value,selectedIndex:0})},$u=({width:e,height:t})=>{let n=$y(()=>Hy(),[]);_y(()=>(Vy(n),()=>{_u()}),[n]);let r=v().selectedIndex;return Oe.createElement(tn,{flexDirection:"column",marginTop:3,borderColor:h.secondary,borderStyle:"round",width:e,height:t-2},Oe.createElement(tn,{paddingX:1,justifyContent:"center"},Oe.createElement(Wn,{color:h.accent},"Help"),Oe.createElement(Wn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),Oe.createElement(tn,{paddingX:1,marginTop:1},Oe.createElement(tn,{width:20,justifyContent:"flex-end"},Oe.createElement(Wn,{color:h.secondary},"Key(s)")),Oe.createElement(tn,{flexGrow:1,width:40,paddingLeft:2},Oe.createElement(Wn,{color:h.secondary},"Action"))),Oe.createElement(tt,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return Oe.createElement(tn,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},Oe.createElement(tn,{width:20,justifyContent:"flex-end"},Oe.createElement(Wn,{color:h.accent},o)),Oe.createElement(tn,{flexGrow:1,width:40,paddingLeft:2},Oe.createElement(Wn,{color:c?h.primary:h.secondary2},s)))})))};import Gy from"chalk";import{Box as us,Text as Dt}from"ink";import qe from"react";var Hu=({width:e,height:t})=>qe.createElement(us,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},qe.createElement(Dt,{color:h.accent,bold:!0},"Initialize project"),qe.createElement(Dt,null,`This folder is not an ${Gy.hex(h.accent)("epiq")} project yet.`),qe.createElement(Dt,{color:h.primary},"To start tracking issues here, we need to initialize a new",qe.createElement(Dt,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json "),"file in this repository."),qe.createElement(us,{marginTop:1,flexDirection:"column"},qe.createElement(us,null,qe.createElement(Dt,{color:h.accent}," "),qe.createElement(Dt,{color:h.primary},"Type "),qe.createElement(Dt,{backgroundColor:h.secondary}," :init "))),qe.createElement(us,{marginTop:1},qe.createElement(Dt,{color:h.secondary2},"This will create, commit and push "),qe.createElement(Dt,{color:h.primary,backgroundColor:h.secondary}," .epiq/project.json ")));import{Box as ms,Text as Ct}from"ink";import Te from"react";var Ky=({isDone:e,command:t,value:n})=>Te.createElement(ms,null,Te.createElement(Ct,{color:h.accent,dimColor:e},e?" \u2714 ":" "),Te.createElement(Ct,{dimColor:e},"Type "),Te.createElement(Ct,{backgroundColor:h.secondary,dimColor:e}," "+t+" "),n!==void 0&&Te.createElement(Te.Fragment,null,Te.createElement(Ct,{dimColor:e}," "),Te.createElement(Ct,{color:h.secondary,dimColor:e},"<"+n+">"))),zy=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Ki({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Vt(),l=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:s,message:"Nice. Now pick your editor."},{key:"autosync",done:c,command:":config autosync",value:i,message:"Almost there. Configure auto sync."}],m=l.findIndex(f=>!f.done),p=m===-1?void 0:l[m];return Te.createElement(ms,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:h.secondary,rowGap:1},Te.createElement(Ct,{color:h.accent,bold:!0},"Welcome! \u{1F539}"),Te.createElement(Ct,null,"Let's get you started - it's a breeze."),Te.createElement(Ct,{color:h.secondary2},"Remember - you can always search available commands by typing:",Te.createElement(Ct,{color:h.accent}," ? ")),p&&Te.createElement(Ct,{color:h.secondary2},p.message),Te.createElement(ms,{flexDirection:"column"},l.map((f,g)=>m===-1||g<=m?Te.createElement(ms,{key:f.key,marginBottom:1},Te.createElement(Ky,{isDone:f.done,command:f.command,value:f.done?zy(f.value):void 0})):null)))}import ys from"chalk";import{Box as Br,Text as Vn}from"ink";import xe from"react";import{Box as ps,Text as ju}from"ink";import nn from"react";import qy from"chalk";var Yy=e=>(E.getTag(e)?.name??"").length+3,Xy=e=>{let t=E.getContributor(e);return(t?qt(e,t.name):"").length+3},Wu=({width:e})=>{let{viewMode:t}=K(),n=j(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],l=At(c?.id??o.id,"TICKET"),m=Q(l)?l.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],g=m?.parentNodeId?!Vs(o.id,m.parentNodeId)&&t==="dense":!1,I=r.map((H,D)=>{let $=D===r.length-1,Ye=Y(H.id),we=$?Ye?.[s]?.title:void 0;return`${D?" / ":""}${H.title??""}${we?` \u25B8 ${we}`:""}`}).join(""),S=m?E.getCommentsByIssue(m.id):[],R=S.length?String(S.length).length+11:0,A=g?p.reduce((H,D)=>H+Yy(D),0)+f.reduce((H,D)=>H+Xy(D),0)+R:0,P=c?.id!=null&&!(t==="wide"&&T(c)),_=Math.max(0,e-A),w=I.substring(0,_)+(P?qy.hex(h.secondary2).dim(` ${He(c.id)}`):""),W=g?[...p.map(H=>nn.createElement(ps,{key:`tag-${H}`,paddingLeft:1},nn.createElement(Un,{id:H}))),...f.map(H=>nn.createElement(ps,{key:`assignee-${H}`,paddingLeft:1},nn.createElement(Yt,{id:H}))),S.length?nn.createElement(ps,{key:"comments",paddingLeft:1},nn.createElement(ju,{color:h.accent},"[",S.length," comment",S.length===1?"":"s","]")):null]:[];return nn.createElement(ps,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},nn.createElement(ju,{color:h.secondary2},w),W)};import{Box as Jy,Text as Vu}from"ink";import fs from"react";var Qy=({filters:e})=>fs.createElement(Jy,{columnGap:1},fs.createElement(Vu,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>fs.createElement(Vu,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Gu=fs.memo(Qy);import{Box as Zy,Text as gs}from"ink";import Dr from"react";function Ku(){let{eventLog:e,unappliedEvents:t}=j(),n=e.at(-1)?.id,r=Co(n??""),o=Q(r)?io(r.value):"INVALID DATE";return Dr.createElement(Zy,{paddingLeft:1},Dr.createElement(gs,{backgroundColor:h.accent,color:h.secondary}," Readonly "),Dr.createElement(gs,{color:h.accent}," "+t.length+" edits ago at "+o+"."),Dr.createElement(gs,{color:h.accent}," Resume with "),Dr.createElement(gs,{backgroundColor:h.accent,color:h.secondary}," ",":peek now"," "))}import{Box as eh,Text as zi}from"ink";import vs from"react";function zu(){let{replay:e}=j();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return vs.createElement(eh,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},vs.createElement(zi,{backgroundColor:h.accent,color:h.secondary}," \u25B6 REPLAY "),vs.createElement(zi,{color:h.secondary2},io(new Date(r))),vs.createElement(zi,{color:h.accent},`${t}/${n} edits`))}import qi from"chalk";import{Box as th,Text as qu}from"ink";import Yi,{useEffect as nh,useState as rh}from"react";var oh=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],sh=150,Yu=12,ih=.36,Xu=e=>{let t=e.replace("#","");return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}},ah=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},dh=(e,t,n)=>{let r=Xu(e),o=Xu(t);return ah({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},ch=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,s=e[r],i=e[Math.min(r+1,e.length-1)];return dh(s,i,o)};function Ju({syncStatus:e,autoSync:t}){let[n,r]=rh(0);nh(()=>{if(e.status!=="syncing"){r(0);return}let c=0,l=setInterval(()=>{c+=1;let m=(Math.sin(c*ih)+1)/2,p=Math.round(m*(Yu-1));r(f=>f===p?f:p)},sh);return()=>clearInterval(l)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:h.secondary2,failed:h.yellow,pending:h.secondary2,syncing:ch(oh,n/(Yu-1))??""}[e.status];return Yi.createElement(th,null,Yi.createElement(qu,null,qi.hex(h.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Yi.createElement(qu,null,qi.hex(i)("\u25CF")+qi.hex(h.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import nm from"chalk";import{Text as rm}from"ink";import om,{useEffect as ph,useState as fh}from"react";var rn="1.4.1";import Xi from"chalk";var lh="https://registry.npmjs.org/epiq/latest",Ji=null,Qu=0,uh=1e3*60*60*24,Zu=e=>e.replace(/^v/,""),mh=(e,t)=>{let n=Zu(e).split(".").map(Number),r=Zu(t).split(".").map(Number);for(let o=0;o<Math.max(n.length,r.length);o++){let s=n[o]??0,i=r[o]??0;if(s>i)return 1;if(s<i)return-1}return 0},em=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Ji&&Date.now()-Qu<uh)return Ji;try{let t=await fetch(lh);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let r=(await t.json()).version??null,o={current:e,latest:r,updateAvailable:r?mh(r,e)>0:!1};return Ji=o,Qu=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},tm=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Xi.hex(h.accent).dim(s):Xi.hex(h.secondary).dim(s)).join(Xi.hex(h.secondary2).dim("."))};function sm(){let[e,t]=fh({current:rn,latest:null,updateAvailable:!1});return ph(()=>{let n=!0;return em(rn).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?om.createElement(rm,{dimColor:!0,color:h.secondary2},rn+" "):om.createElement(rm,null,nm.hex(h.secondary2).dim(rn),nm.hex(h.accent).dim(" \u2197 "),tm(rn,e.latest))}function Fr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=j(),{userName:i,preferredEditor:c,autoSync:l}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",g=s?ln(s.currentLabel,Math.max(0,p)):"";return xe.createElement(Br,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?xe.createElement(Br,{paddingLeft:1},xe.createElement(Vn,{color:h.secondary2},g)):f?xe.createElement(Vn,null," "):o===y.PALETTE?xe.createElement(Br,null,xe.createElement(Vn,{color:h.accent},"Command Palette"),xe.createElement(Vn,{dimColor:!0,color:h.secondary2}," ","- search, select and press enter")):xe.createElement(Br,{paddingLeft:1},e.length>0?xe.createElement(Gu,{filters:e}):xe.createElement(Wu,{width:p})),n==="live"?xe.createElement(Br,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},xe.createElement(Ju,{autoSync:!!l,syncStatus:r}),xe.createElement(Vn,null,ys.hex(h.secondary2).dim("Mode: ")+ys.hex(h.secondary2).dim(o.padEnd(8," "))," "),xe.createElement(im,{icon:"@",value:i}),xe.createElement(im,{icon:"\u276F",value:c}),xe.createElement(sm,null)):"",n==="peek"?xe.createElement(Ku,null):"",n==="replay"?xe.createElement(zu,null):"")}function im({icon:e,value:t}){return xe.createElement(Vn,null,ys.dim(e)+ys.hex(h.accent)(` ${t??"-"} `))}import{Box as gh,Text as vh}from"ink";import Ur from"react";import{Box as hs,Text as Qi}from"ink";import on from"react";function Zi(){let e=j(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?z(t?.id):[];return on.createElement(hs,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:h.secondary,width:s},on.createElement(hs,{padding:1,paddingTop:0,paddingBottom:0},on.createElement(Qi,null,"Select a board:")),on.createElement(hs,{padding:1,flexDirection:"column"},i.map((c,l)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===l,f=z(c.id).flatMap(({id:g})=>Y(g)).length;return on.createElement(hs,{key:c.id??l},on.createElement(Qi,{color:m?h.accent:h.secondary2},on.createElement(ke,{isSelected:m})),on.createElement(Qi,{color:m?h.accent:h.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var yh=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=j(),l=n.find(({context:g})=>g==="BOARD"),f=s-1-3;return Ur.createElement(gh,{flexDirection:"row"},e.context==="WORKSPACE"?Ur.createElement(Zi,null):l?Ur.createElement(Uo,{height:f,width:i,swimlanes:(c[l.id]??[]).filter(g=>g!==void 0&&_t(g)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):Ur.createElement(vh,null))},am=Ur.memo(yh);import{useEffect as hh}from"react";var xh=e=>{hh(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=K();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:l}=v();l==="default"&&!c&&ho(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},dm=({autoSync:e})=>(xh(e),null);function ea({width:e,height:t}){let n=j(),{autoSync:r,viewMode:o}=Pa(),s=n.filters;if(n.mode===y.HELP)return ce.createElement(sn,{flexDirection:"column"},ce.createElement($u,{width:e,height:t}));if(n.mode===y.PALETTE)return ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{filters:s}),ce.createElement(Au,{width:e,height:t-2}),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Vt(),c=!i,l=i&&!n.hasProjectDefinition;if(c)return ce.createElement(sn,{flexDirection:"column"},ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{hideBreadCrumb:!0,filters:s}),ce.createElement(Ki,{height:t,width:e})),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(l)return ce.createElement(sn,{flexDirection:"column"},ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{hideBreadCrumb:!0,filters:s}),ce.createElement(Hu,{height:t,width:e})),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Ue(n.breadCrumb??[],"BOARD");if(Q(m)){let p=m.value.id,f=z(p).length,g=3,I=Math.floor(e/g),S=Math.floor(e/Math.max(f,1));e=Math.min(S,I)*Math.max(f,g)}return ce.createElement(sn,{flexDirection:"column"},ce.createElement(dm,{autoSync:r}),ce.createElement(sn,{flexDirection:"column"},ce.createElement(Fr,{filters:s}),ce.createElement(am,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ce.createElement(kr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import bh from"readline";var xs,bs,Nt,Ih=new Set([x.MoveCursorLeft,x.EraseInputWord,x.MoveCursorLeftOfWord,x.MoveCursorRight,x.MoveCursorRightOfWord,x.NavToPreviousContainer,x.NavToNextContainer,x.NavPreviousItem,x.NavNextItem,x.SetViewDense,x.SetViewWide,x.Confirm,x.Exit,x.Yank,x.InitCommandLine,x.InitCommandPalette,x.ExitCommandLine,x.CaptureInput,x.EraseInput,x.EraseInputWord,x.HideHelp,x.ViewHelp,x.SetViewDense,x.SetViewWide,x.GetLastCommandFromHistory,x.GetNextCommandFromHistory,x.AutoCompleteCommand]),Eh=new Set([x.NavPreviousItem,x.NavNextItem,x.NavToPreviousContainer,x.NavToNextContainer,x.Confirm,x.Exit,x.InitCommandPalette,x.InitMove,x.MoveNextItem,x.MovePreviousItem,x.MoveToNextContainer,x.MoveToPreviousContainer,x.Delete,x.AddItem,x.EditTitle,x.EditDescription,x.ConfirmMove,x.Edit,x.ViewHelp,x.Yank]),cm=async e=>{if(e.ctrl&&e.name==="c")return M.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=v(),s=yc(e,n);if(!s||r&&!Ih.has(s)||o==="replay"&&n===y.DEFAULT&&Eh.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},Sh=()=>async function(t,n){n.name!=="escape"&&(Nt&&(clearTimeout(Nt),Nt=void 0),await cm(n))},Ch=()=>async function(t){if(t.length===1&&t[0]===27){Nt&&clearTimeout(Nt),Nt=setTimeout(()=>{cm({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),Nt=void 0},25);return}Nt&&(clearTimeout(Nt),Nt=void 0)};function lm(){xs&&process.stdin.removeListener("keypress",xs),bs&&process.stdin.removeListener("data",bs),xs=Sh(),bs=Ch(),bh.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",bs),process.stdin.on("keypress",xs)}async function um(){try{let e=Ft();Q(e)&&Me(e.value);let t=_e(process.cwd()),n=[];if(Q(t)){let s=Re({repoRoot:t.value});if(d(s))return fn(3,s.message);let i=Sn(),c=await cn({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return fn(3,c.message);let l=await F({cwd:s.value,args:["pull","--ff-only"]});d(l)&&logger.info(3,l.message);let m=je(s.value);if(d(m))return fn(3,m.message);n=m.value}let r=pn(n);if(d(r))return fn(4,r.message);C({hasProjectDefinition:Q(t),hasInitializingEvents:!!n.length});let o=ta();return d(o)?fn(6,o.message):(lm(),u("Booted Epiq",void 0))}catch(e){return fn(0,go(e))}}Wc();var Th=`${an.bold("Epiq CLI")}
61
61
 
62
62
  ${an.dim("Boot in directory:")}
63
63
  ${an.cyan("$ epiq")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "EPIQ - ergonomic, distributed CLI-first issue tracker TUI ready for the agentic era",