epiq 1.3.0 → 1.3.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
@@ -24871,7 +24871,10 @@ var Panel = ({
24871
24871
  style: {
24872
24872
  position: "relative",
24873
24873
  zIndex: 1,
24874
- height: "100%"
24874
+ height: "100%",
24875
+ display: "flex",
24876
+ flexDirection: "column",
24877
+ minHeight: 0
24875
24878
  },
24876
24879
  children
24877
24880
  }
@@ -24911,7 +24914,7 @@ var User = ({
24911
24914
  );
24912
24915
 
24913
24916
  // source/version.ts
24914
- var EPIQ_VERSION = "1.3.0";
24917
+ var EPIQ_VERSION = "1.3.1";
24915
24918
 
24916
24919
  // source/gui/client/components/Header.tsx
24917
24920
  var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
@@ -26335,6 +26338,7 @@ var SwimlaneColumn = ({
26335
26338
  {
26336
26339
  style: {
26337
26340
  height: 48,
26341
+ flexShrink: 0,
26338
26342
  display: "flex",
26339
26343
  fontSize: 12,
26340
26344
  justifyContent: "space-between",
@@ -26386,7 +26390,7 @@ var SwimlaneColumn = ({
26386
26390
  ]
26387
26391
  }
26388
26392
  ),
26389
- /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { style: { overflow: "auto", paddingTop: 4, flex: 1 }, children: swimlane.issues.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
26393
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { style: { overflow: "auto", paddingTop: 4, flex: 1, minHeight: 0 }, children: swimlane.issues.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_jsx_runtime18.Fragment, { children: [
26390
26394
  dropIndex === 0 && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DropIndicator, {}),
26391
26395
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
26392
26396
  "div",
package/dist/index.js CHANGED
@@ -55,7 +55,7 @@ ${m}
55
55
 
56
56
  ${c}
57
57
  `,si.writeFileSync(t,n,"utf8"),oe.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),l("Local epiq paths ignored",!0)};var yg=async e=>{let t=await _({cwd:e,args:["status","--porcelain"]});return d(t)?t:l("Checked git diff",t.value.stdout.trim().length>0)},ee=(e,t)=>a(`[${e}] ${t}`),Cc=async()=>{W("");let e=vn(),t=await dt(process.cwd());if(d(t))return ee(1,t.message);let n=t.value,r=await Fr(n);if(d(r))return ee(2,r.message);if(r.value)return ee(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await yg(n);if(d(o))return ee(2.5,o.message);if(o.value)return ee(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(cs(n))return ee(4,"Epiq project already initialized");let s=Ot();if(!s.isSetupDone||!s.userName)return ee(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=K(),c=i.userName,u=i.userId;if(!u||!c)return ee(5,"Missing Epiq user id");let m=e.stateBranch,p=await Ur({repoRoot:n,branch:m});if(d(p))return ee(6,p.message);if(p.value)return ee(6,`State branch already exists: ${m}`);let f=await bs({repoRoot:n,stateBranchName:m});if(d(f))return ee(6,f.message);let b=$r();if(d(b))return ee(7,b.message);let N=Ec.join(_r(),e.projectId),S=await en({repoRoot:n,stateBranchRoot:N,stateBranchName:m});if(d(S))return ee(8,S.message);let R=Ec.join(N,".epiq");gg.mkdirSync(R,{recursive:!0});let M=ed({userId:u,userName:c});if(d(M))return ee(9,M.message);for(let is of M.value){let Pi=eo({event:is,rootDir:N});if(d(Pi))return ee(9,Pi.message)}let U=await Wr({stateBranchRoot:N,eventFileName:on({userId:u,userName:c})});if(d(U))return ee(10,U.message);let j=await xn({cwd:N,message:"[epiq:init]"});if(d(j))return ee(10,j.message);let D=await Ic(n);if(d(D))return ee(11,D.message);let z=Bi({repoRoot:n,fileContents:e});if(d(z))return ee(12,z.message);let $=await de.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d($))return ee(13,$.message);let P=await de.commit({cwd:n,message:"[epiq:init-project]"});if(d(P))return ee(13,P.message);let O="Project initialized!",Ge=await _({cwd:n,args:["push","-u","origin","HEAD"]});d(Ge)&&(O+=` Warn: [init:14] ${Ge.message}`);let Ne=await Jn({repoRoot:n,stateBranchRoot:N});d(Ne)&&(O+=` Warn: [init:15] ${Ne.message}`);let ue=Ut(M.value).filter(d);if(ue.length>0)return ee(16,ue.map(is=>is.message).join(`
58
- `));let ce=Je();if(d(ce))return ee(16,ce.message);let{rootNodeId:$n,nodes:Hn}=ce.value,Mi=Hn[$n];return Mi?(T.navigate({contextNode:Mi,selectedIndex:0}),E({hasProjectDefinition:!0,mode:y.DEFAULT}),l(O,null)):ee(16,"Unable to resolve initialized root node")};import{ulid as hg}from"ulid";import{ulid as vg}from"ulid";var Nc=null,Kt=()=>structuredClone(Nc),vr=e=>{Nc=e},Sc=()=>{let{contextNode:e,selectedIndex:t}=g(),r=q(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},ii=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q(t).filter(o=>o.id!==e);return to(r,n)},Ac=({id:e,parentId:t,position:n={at:"end"}})=>{let r=se();if(d(r))return a("Unable to resolve user ID");let o=ii({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:vg(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Rc=e=>{vr(e);let t=Bt(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function ai(e){let t=Sc();if(d(t))return t;let{contextNode:n,nodes:r}=g();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=q(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 u=Ac({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Rc(u.value)}function di(e){let t=Sc();if(d(t))return t;let{contextNode:n,selectedIndex:r}=g(),s=q(n.id)[r+e];if(!s)return a("Missing sibling node");let i=Ac({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Rc(i.value)}var Tc=()=>{let e=Kt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=g().nodes[n];if(!r)return a("Move parent not found");let o=q(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},To=(e,t="Moved preview")=>{if(d(e))return e;let n=Tc();return d(n)?n:(E({mode:y.MOVE}),l(t,null))},wc=async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=Y().commandMeta,{contextNode:n,selectedIndex:r}=g(),o=q(n.id)[r];if(!o)return E({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=q(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],u=s[i+1],m=u!=null?{at:"before",sibling:u.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=ii({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(vr({id:hg(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),E({mode:y.MOVE}),l("Move initialized",null))}if(t==="next")return To(di(1));if(t==="previous")return To(di(-1));if(t==="to-next")return To(ai(1));if(t==="to-previous")return To(ai(-1));if(t==="confirm"){let s=Kt();if(!s)return a("No pending move to confirm");let i=await at();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=Tc();return d(u)?u:(vr(null),E({mode:y.DEFAULT}),l("Moved item",null))}return t==="cancel"?(vr(null),E({mode:y.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Mo}from"ulid";import{monotonicFactory as xg,ulid as bg}from"ulid";var Ig=xg(),wo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Ig();return l("Created issue events",[{id:bg(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Mc=async(e,t)=>{let n=se();if(d(n))return a("Unable to resolve user ID");let r=await at();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}=g(),u=m=>{let p=B([m],o);if(d(p))return p;let f=I.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let b=I.getNode(f.parentNodeId);return b?(T.navigate({contextNode:b,selectedIndex:I.getSiblings(f.parentNodeId).findIndex(({id:N})=>N===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let f=Sn(p.id,n.value,o);return d(f)?f:u({id:Mo(),action:"add.board",payload:{id:Mo(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Le(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Sn(m.value.id,n.value,o);return d(p)?p:u({id:Mo(),action:"add.swimlane",payload:{id:Mo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=G(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Le(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let f=Sn(p.id,n.value,o);if(d(f))return f;let b=wo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(b))return b;let N=b.value,S=B([...N],o);if(d(S))return S;if(!S.value[0])return a("Issue creation failed");let U=N.find(j=>j.action==="add.issue")?.payload.id;return U?(T.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===U)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Po=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=g(),s=Oa(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=Gt();if(d(u))return u;let p=Ut(i).filter(d);if(p.length>0)return Gt(),E(o),a(p.map(b=>b.message).join(", "));let f=g().nodes[e];return f?(T.navigate({contextNode:f,selectedIndex:r}),l("",{unappliedEvents:c})):(Gt(),E(o),a("Board did not exist at that date"))};var Eg=20,Cg=16,Ng=150,Lo=null,ko=null;var fn=()=>{Lo!==null&&(clearInterval(Lo),Lo=null),ko!==null&&(clearTimeout(ko),ko=null)},Pc=()=>{fn(),E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Sg=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)},Lc=({events:e,startTime:t,durationMs:n})=>{fn();let r=e.length,o=e.map(f=>Nn(f)??t),s=o[r-1]??Date.now(),i=Sg(o),c=Math.max(1,Math.round(n*Eg/1e3)),u=Math.max(Math.round(n/c),Cg),m=0,p=0;E({mode:y.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),Lo=setInterval(()=>{m++;let f=m/c,b=[],N;for(;p<r&&i[p]<=f;){let R=e[p],M=Bt(R);if(d(M)){Pc();return}b.push(...Ts(R)),N=R,p++}if(p>=r||m>=c){for(;p<r;p++){let M=Bt(e[p]);if(d(M))break}let R=g().replay;E({unappliedEvents:[],replay:R&&{...R,progress:1,appliedCount:r}}),fn(),ko=setTimeout(Pc,Ng);return}let S=g().replay;E({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:N?Nn(N)??S?.currentTime??t:S?.currentTime??t,currentLabel:N?Pa(N):S?.currentLabel??"",flashNodeIds:N?[...new Set(b)]:S?.flashNodeIds??[]}})},u)};var kc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta;if(fn(),r==="now"){let c=Et(n.value);if(d(c))return a(c.message);let u=Gt();if(d(u))return u;let p=Ut(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=g().eventLog.at(-1),u=Nn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=g().unappliedEvents.at(0),u=Nn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=cn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Po({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(E({mode:y.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var Dc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta,{dateInput:s,durationInput:i}=uo(r,o);if(fn(),g().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=cn(s);if(!c)return a("Invalid replay date");let u=i?lo(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=g(),f=Po({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:b}=f.value;return b.length===0?(Gt(),E(p),l("Nothing to replay from that point",!0)):(Lc({events:b,startTime:m,durationMs:u}),l("Replaying board history",!0))};import Rg from"zod";var Fc=()=>{let e=Y().commandMeta.inputString,t=Rg.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=Ze({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),E({mode:y.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Bc=()=>{let e=Y().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=ad(e),n=Ze({autoSync:t});return d(n)?n:(Fe({autoSync:t}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Uc=()=>{let e=Y().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Ze({logLevel:e});return d(n)?n:(Fe({logLevel:e}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};import{spawn as Tg}from"node:child_process";var wg=()=>{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"]}}},Oc=async e=>new Promise(t=>{let{command:n,args:r}=wg();try{let o=Tg(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?l("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 hr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await Oc(e);return d(n)?n:l(`Copied ${t} to clipboard`,null)},_c=async e=>{let{breadCrumb:t,selectedNode:n}=g(),r=ir({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case pe.REF:return hr(Ue(o.id),"ref");case pe.TITLE:return hr(o.title,"title");case pe.DESCRIPTION:return r?hr(r.props?.description??"","description"):a("No issue in scope");case pe.TAGS:{if(!r)return a("No issue in scope");let s=_t(r).map(({name:i})=>i);return hr(s.join(", "),"tags")}case pe.ASSIGNEES:{if(!r)return a("No issue in scope");let s=$t(r).map(({name:i})=>i);return hr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var $c=async()=>{W(""),E({mode:y.DEFAULT});let e=Je();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await oo();return d(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:y.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Mg=e=>e.action==="add.issue.comment",Hc=e=>Object.values(g().tags).find(t=>t.name===e),Wc=e=>Object.values(g().contributors).find(t=>t.name===e),wt=async()=>{let e=await at();return d(e)?e:l("Resolved persist root",e.value)},Do=[{systemOnly:!0,intent:w.Move,description:"Internal move-state command",mode:y.COMMAND_LINE,action:wc},{intent:w.Delete,description:"Delete the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await wt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=A(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!A(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Mg).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:we(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:we(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:y.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Y().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ie(x.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return he(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:y.DEFAULT})),l("Filter updated",null)}},{intent:w.ViewHelp,description:"Open the help screen",mode:y.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:y.HELP}),l("Viewing help",null)}},{intent:w.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!A(r))return a("Cannot close in this context");let o=g().nodes[me];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await wt();if(d(s))return s;let i=s.value,c=sn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:we(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):It(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=g().nodes[me];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!A(s))return a("Target node is not issue");let c=Ao(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 u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await wt();if(d(m))return m;let p=m.value,f=sn(u.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let b=B([{id:we(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:f.value},...e.value}],p);return d(b)?b:l("Issue reopened",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Init,description:"Initialize Epiq in the current git repository",mode:y.COMMAND_LINE,action:Cc},{intent:w.NewItem,description:"Create a new board, swimlane, or issue",mode:y.COMMAND_LINE,action:Mc,onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Rename,description:"Rename the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=zd();if(!o)return a("Provide a title");let s=await wt();return d(s)?s:B([{id:we(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UntagTicket,description:"Remove a tag from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Hc(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!A(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 wt();return d(m)?m:B([{id:we(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.TagTicket,description:"Add or create a tag on the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=g();if(!o)return a("Invalid tag target");let s=It(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!A(i))return a("Target node is not issue");let c=await wt();if(d(c))return c;let u=Hc(r),m=u?.id??we();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:we(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:we(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.AssignUserToTicket,description:"Assign a user to the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=g(),i=G(s.id)[o];if(!i)return a("Invalid assign target");let c=It(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!A(u))return a("Target node is not issue");let m=await wt();if(d(m))return m;let p=Wc(r),f=p?.id??we();return(u.props.assignees??[]).includes(f)?a("Assignee already assigned"):B([...p?[]:[{id:we(),action:"create.contributor",payload:{id:f,name:r},...e.value}],{id:we(),action:"add.issue.assignee",payload:{id:u.id,assignee:f},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=Wc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!A(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(o.id))return a(`Issue is not assigned to "${r}"`);let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.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>Pn)return a(`Cannot exceed ${Pn} characters`);let r=se();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=g(),i=Le([...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 u=c.context==="TICKET"?l("Resolved ticket",c):It(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!A(m))return a("Target node is not issue");let p=await wt();return d(p)?p:B([{id:we(),action:"add.issue.comment",payload:{id:we(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Sync,description:"Pull, commit, and push Epiq state",mode:y.COMMAND_LINE,action:$c},{intent:w.Peek,description:"View board state at another point in time",mode:y.COMMAND_LINE,action:kc},{intent:w.Replay,description:"Replay board history forward from a point in time",mode:y.COMMAND_LINE,action:Dc},{intent:w.Export,description:"Export the current board layout to markdown",mode:y.COMMAND_LINE,action:async()=>{let e=await gc();return d(e)?e:(E({mode:y.DEFAULT}),l("Export successful",!0))}},{intent:w.Exit,description:"Exit the application",mode:y.COMMAND_LINE,action:async()=>(T.exit(),l("Exit successful",!0))},{intent:w.Edit,description:"Edit title or description",mode:y.COMMAND_LINE,action:async(e,t)=>bc(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:y.COMMAND_LINE,action:async(e,t)=>_c(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.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 ne.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??we();if(!i||!c)return a("Unable to resolve user name or id");let u=Ze({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(Fe({userName:i,userId:c}),E({mode:y.DEFAULT}),l(`Username set to "${i}"`,null))}case ne.EDITOR:{if(!n)return a("No editor provided");let r=Ze({preferredEditor:n});return d(r)?r:(Fe({preferredEditor:n}),E({mode:y.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case ne.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Ze({viewMode:n});return d(r)?r:(Fe({viewMode:n}),E({mode:y.DEFAULT}),l(`View set to "${n}"`,null))}case ne.AUTOSYNC:return Bc();case ne.LOG_LEVEL:return Uc();case ne.SYNC_DEBOUNCE_MS:return Fc();case ne.ATTACHMENT_MAX_KB:return Rd();default:return a("Unknown config command")}}},{intent:w.Coffee,description:"Sponsor the development of Epiq!",mode:y.COMMAND_LINE,action:()=>{let e=Y().commandMeta.modifier;return e==="custom"?yr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):yr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var Pg=new Set(["peek","replay","filter","view-help","yank"]),yt=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Y();if(!t)return a("No command to confirm");if(!e&&n===pt.Invalid)return a("Invalid command");let s=ho(t);Wd();let{readOnly:i}=g();if(i&&!Pg.has(s))return ur({status:Pt.Fail,message:"Command not available in readonly state",value:null});let c=Do.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return ur({status:Pt.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return ur({status:Pt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?ur(u):(jd({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&io(),u)};var Fo=[{intent:h.Exit,mode:y.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:y.COMMAND_LINE}),W("move cancel"),yt({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:y.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:y.COMMAND_LINE}),W("move start"),yt({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:y.MOVE,action:()=>(E({mode:y.COMMAND_LINE}),W("move confirm"),yt({isForceExecutedBySystem:!0}))}],Bo=[{intent:h.MovePreviousItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move next"),yt({isForceExecutedBySystem:!0})):a("No pending move")}],jc=[{intent:h.MoveToNextContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-next"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")}];var Vc={[L.WORKSPACE]:[...Fo,...Bo],[L.BOARD]:[...Fo,...Bo],[L.SWIMLANE]:[...Fo,...Bo,...jc],[L.TICKET]:[],[L.FIELD]:[],[L.FIELD_LIST]:[],[L.TEXT]:[],[L.COMMENT]:[]};import Lg from"node:fs";import kg from"node:path";var Kc=e=>{let t=Ye(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=Mn(e.hash,e.ext),o=kg.join(Kn(n.value),r);return Lg.existsSync(o)?(yr(o),l(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var Gc=()=>{W("");let{pendingNavTarget:e}=jt();E({mode:y.DEFAULT}),e&&T.navigate(e),Vt({pendingNavTarget:void 0})},zc=[{intent:h.ExitCommandLine,mode:y.HELP,action:()=>(Gc(),l("Exiting help",null))},{intent:h.Exit,mode:y.HELP,action:()=>(Gc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:y.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:y.HELP,action:()=>(T.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:y.HELP,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:y.HELP,action:()=>(T.navigateToNextContainer(),l("Navigating to next help container",null))}];var Dg=e=>{E({mode:y.COMMAND_LINE});let{pendingNavTarget:t}=jt();t&&T.navigate(t),Vt({pendingNavTarget:void 0}),W(`${e} `)},qc=()=>{W("");let{pendingNavTarget:e}=jt();e&&T.navigate(e),Vt({pendingNavTarget:void 0}),E({mode:y.DEFAULT})},Yc=[{intent:h.InitCommandPalette,mode:y.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:y.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:y.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!kt(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?(Dg(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:y.PALETTE,action:()=>(qc(),l("Exiting palette",null))},{intent:h.Exit,mode:y.PALETTE,action:()=>(qc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:y.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.PALETTE,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.PALETTE,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.PALETTE,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Xc=[...zc,...Yc,{intent:h.AddItem,mode:y.DEFAULT,description:"[n] new...",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:y.DEFAULT,description:"[d] delete",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:y.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:y.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:y.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!q(e?.id??"")?.length){let r=e?I.getAttachment(e.id):void 0;if(r)return Kc(r);if(e?.title===J.DESCRIPTION)return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===J.ASSIGNEES)return E({mode:y.COMMAND_LINE}),W(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===J.TAGS)return E({mode:y.COMMAND_LINE}),W(`${x.TAG} `),l("Propose command",!0);if(t.title===J.DESCRIPTION&&e?.context==="TEXT")return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0)}return T.enterChildNode(),l("Entering context",null)}},{intent:h.Yank,mode:y.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=g(),t=e?.title===J.DESCRIPTION?pe.DESCRIPTION:e?.title===J.TAGS?pe.TAGS:e?.title===J.ASSIGNEES?pe.ASSIGNEES:pe.REF,r=ie(x.YANK).includes(t)?t:pe.REF;return E({mode:y.COMMAND_LINE}),W(`${x.YANK} ${r}`),l("Propose command",!0)}},{intent:h.EditTitle,mode:y.DEFAULT,description:"[r] rename title",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:y.DEFAULT,description:"[e] edit description",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:y.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:y.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.DEFAULT,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.DEFAULT,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.DEFAULT,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Fg=500,Bg=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Jc=e=>{let t=Bg(e);t&&vo(n=>(n+t).slice(0,Fg))};var Ug=[y.COMMAND_LINE,y.PALETTE],Og=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(qs(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(qs(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Ys("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Ys("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(vo((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=g().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(Jc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>($d(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(Hd(),l("Erasing input word",null))}],Qc=[{intent:h.Confirm,mode:y.COMMAND_LINE,action:()=>(yt(),l("Executing command",null))},{intent:h.ViewHelp,mode:y.DEFAULT,action:()=>(E({mode:y.HELP}),l("Viewing help",null))},...Ug.flatMap(Og),{intent:h.ExitCommandLine,mode:y.COMMAND_LINE,action:()=>(E({mode:y.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Vd(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Kd(),l("Getting next command from history",null))}];import tl from"chalk";var Uo=tl.dim.hex(v.secondary2)(": for command line"),Zc="q to exit",el=`${tl.hex(v.accent)("m")} to confirm`,ci={[L.WORKSPACE]:[Uo],[L.BOARD]:[Uo],[L.BOARD+y.COMMAND_LINE]:[Uo],[L.SWIMLANE]:[Uo],[L.TICKET+y.HELP]:[Zc],[L.SWIMLANE+y.HELP]:[Zc],[L.TICKET]:[],[L.FIELD]:[],[L.SWIMLANE+y.MOVE]:[el],[L.TICKET+y.MOVE]:[el]};var xr=e=>e.trim().toLocaleLowerCase(),_g=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},$g=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},nl=(e,t)=>{let n=xr(t.value);if(!n)return!0;switch(t.target){case"title":return xr(e.title??"").includes(n);case"description":return xr(e.props.description??"").includes(n);case"tag":return _g(e).map(xr).some(o=>o.includes(n));case"assignee":return $g(e).map(xr).some(o=>o.includes(n));case"ref":return ba(e.id,t.value);default:return!0}};function rl(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(),l("Breadcrumb built",o))}var ol=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 gn,li,ui=new Set,sl=()=>{for(let e of ui)e()},Wg=e=>(ui.add(e),()=>ui.delete(e));function il(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 u=rl(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,f=ci[p+n]??ci[p]??[],b=[...Xc,...Vc[p]??[],...Qc],N=ol(b),S=jg(o,s),R=S[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:b,actionIndex:N,selectedNode:R,renderedChildrenIndex:S})}var g=()=>{if(!gn)throw new Error("State not initialized. Call initWorkspaceState() first.");return gn},Je=()=>gn?l("Retrieved state",gn):a("State not initialized. Call initWorkspaceState() first.");function nr(e){li=e;let t=Ye(process.cwd()),n=!1;if(!d(t)){let s=Lt(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=il(r);return d(o)?o:(gn=o.value,sl(),l("State initialized",null))}function he(e){let t=g(),n=e(t),r=il(n);return d(r)?a(r.message??"Unable to update state"):(gn=r.value,sl(),l("State updated",null))}var E=e=>he(t=>({...t,...e}));var H=()=>Hg(Wg,g,g),jg=(e,t)=>{let n={};for(let r of Object.values(e))A(r)&&t.length>0&&!t.every(o=>nl(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},G=e=>g()?.renderedChildrenIndex[e]??[],Gt=()=>li?nr(li):a("Cannot reset state: no initial workspace found"),Rn=()=>gn!==void 0;var mi=e=>{Rn()&&(E({syncStatus:e}),tn({type:"sync-status",payload:e}))},Oo=(e="Syncing...")=>{mi({status:"syncing",msg:e})},_o=(e="Synced")=>{mi({status:"synced",msg:e})},pi=e=>{mi({status:"failed",msg:e})},Qe=e=>(pi(e),a(e));import{decodeTime as JL}from"ulid";var Vg=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=X("getRepoRootDir",await dt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=X("getStateBranchRoot",Pe({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=X("ensureInitialCommit",await ta(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=X("bootstrapStateBranchStorage",await oa({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 u=X("hasInProgressGitOperation(stateBranchRoot)",await Fr(s));if(d(u))return a(u.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:u.value}),u.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=X("ensureStateBranchLayout",Qi(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}),l("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},Kg=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=X("stageStateBranchOwnEventFile",await Wr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=X("stageStateBranchMediaFiles",await na({stateBranchRoot:t}));if(d(o))return a(o.message);let s=X("hasStagedChanges(after stage)",await Ki(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"),l("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=X("createStateBranchSyncCommit",await ra({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),l("Committed own event file",{createdCommit:!0,commitSha:i.value}))},so=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");Oo();let n=X("ensureSyncReady",await Vg({cwd:e,ensureUpstream:!0}));if(d(n))return Qe(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=X("isDetachedHead(stateBranchRoot)",await Gi(o));if(d(i))return Qe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Qe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,f=X("getStateBranch",hn(r));if(d(f))return Qe(f.message);let b=f.value;logger.debug("[sync] resolved state branch",{stateBranch:b,stateBranchRoot:o});let N=X("commitOwnEventFileToStateBranch",await Kg({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(N))return Qe(N.message);c=N.value.createdCommit,u=N.value.commitSha;let S=X("pullBranchRebaseIfPresent",await vs({cwd:o,branch:b}));if(d(S))return Qe(S.message);if(m=S.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let R=X("pushStateBranch",await Jn({stateBranchRoot:o,repoRoot:r}));if(d(R)&&Vi(R.message)){let M=X("pullBranchRebaseIfPresent(retry)",await vs({cwd:o,branch:b}));if(d(M))return Qe(M.message);m=m||M.value,R=X("pushStateBranch(retry)",await Jn({stateBranchRoot:o,repoRoot:r}))}if(d(R))return Qe(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let R=X("git rev-parse HEAD",await _({args:["rev-parse","HEAD"],cwd:o}));if(d(R))return Qe(R.message);u=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return _o(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var fi=()=>{let e=wn();return d(e)?mt:e.value.attachmentMaxKb??mt},gi=e=>{let t=Ye(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},Me=async e=>{let t=gi(e);if(d(t))return t;let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=vn(),o=await en({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:r.stateBranch});if(d(o))return a(o.message);let s=await _({cwd:n.value,args:["pull","--ff-only"]});d(s)&&oe.info(3,s.message);let i=Et(n.value);if(d(i))return a(i.message);let c=an(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},ke=()=>{let e=wn();return d(e)?a(e.message):e.value.userId?e.value.userName?l("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},je=()=>{let e=Je();return d(e)?a(e.message):e},dl=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)})),cl=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)}));var ll=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes).filter(A).filter(o=>e.includeClosed||o.parentNodeId!==me).map(o=>({id:o.id,ref:Ue(o.id),title:lt(o.title),description:o.props.description??"",parentNodeId:o.parentNodeId,isClosed:o.parentNodeId===me,readonly:!!o.readonly,tags:dl(o),assignees:cl(o)}));return l("Listed issues",r)},ul=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Sn(e.parentId,n.value,t.value.stateBranchRoot);if(d(r))return r;let o=wo({name:e.title,parent:e.parentId,user:n.value,rank:r.value});if(d(o))return o;let s=o.value,i=B([...s],t.value.stateBranchRoot);if(d(i))return a(i.message);let c=s.find(u=>u.action==="add.issue")?.payload.id;return c?l("Created issue",{id:c,title:e.title,parentId:e.parentId}):a("Unable to determine created issue id")},ml=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=sn(me,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:ge(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:me,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},pl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Target node is not issue");if(o.parentNodeId!==me)return a("Issue is not closed");let s=Ao(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===me)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=sn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:ge(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=B([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:o.id,parentId:i.id})},fl=async e=>{let t=gi(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Pe({repoRoot:t.value});if(d(r))return r;let o=Et(r.value);if(d(o))return o;let s=an(o.value);if(d(s))return s;let i=sn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:ge(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=B([c],r.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})},$o=async(e={})=>{Oo();let t=gi(e.repoRoot);if(d(t))return a("Sync failed");let n=ke();if(d(n))return n;let r=await so({cwd:t.value,ownEventFileName:on(n.value)});return d(r)?(pi(r.message),r):(_o(),l("Synced",r.value))};var vt=async(e={})=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes),o=r.filter(f=>Vr(f)&&!f.isDeleted),s=new Map,i=new Map;for(let f of r)if(!f.isDeleted){if(Dt(f)&&f.parentNodeId){let b=s.get(f.parentNodeId)??[];b.push(f),s.set(f.parentNodeId,b)}if(A(f)&&f.parentNodeId){let b=i.get(f.parentNodeId)??[];b.push(f),i.set(f.parentNodeId,b)}}let c=wn();if(d(c))return c;let u={};for(let f of r.filter(A))f.isDeleted||(u[f.id]=I.getCommentsByIssue(f.id).map(b=>{let N=I.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:{id:b.authorId,name:N?.name??"Unknown",color:le(N?.name??b.authorId)},createdAt:al(b.id)}}));let m=new Map;for(let f of n.value.eventLog)f.action==="add.issue.attachment"&&m.set(f.payload.id,f.payload.author);let p={};for(let f of r.filter(A))f.isDeleted||(p[f.id]=I.getAttachmentsByIssue(f.id).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Mn(b.hash,b.ext),bytes:b.bytes,createdAt:al(b.id),canDelete:m.get(b.id)===c.value.userId})));return l("Retrieved Epiq GUI state",{boards:o.sort((f,b)=>f.rank.localeCompare(b.rank)).map(f=>({id:f.id,ref:Ue(f.id),title:f.title,swimlanes:(s.get(f.id)??[]).sort((b,N)=>b.rank.localeCompare(N.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly,issues:(i.get(b.id)??[]).sort((N,S)=>N.rank.localeCompare(S.rank)).map(N=>({id:N.id,ref:Ue(N.id),title:lt(N.title),description:N.props.description??"",readonly:!!N.readonly,tags:dl(N),assignees:cl(N),parentNodeId:N.parentNodeId,isClosed:N.parentNodeId===me})),parentNodeId:b.parentNodeId}))})),tags:Object.values(n.value.tags).map(f=>({...f,color:le(f.name)})),contributors:Object.values(n.value.contributors).map(f=>({...f,color:le(f.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:le(c.value.userName??"")},commentsByIssueId:u,attachmentsByIssueId:p,attachmentMaxKb:fi()})},gl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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 l("No changes made",{id:e.issueId,description:s});let i={id:ge(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},yl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=lt(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:ge(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},vl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=lt(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??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},hl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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:ge(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},xl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=lt(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(r.value.contributors).find(p=>p.name===s),c=i?.id??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},bl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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:ge(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},Ho=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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=ge(),c={id:ge(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},Wo=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();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(!A(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 l("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},Il=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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=Sd(t.value.stateBranchRoot,s,fi());if(d(i))return i;let c=lt(e.name??"").trim()||"image",u=ge(),m={id:ge(),...n.value,action:"add.issue.attachment",payload:{id:u,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=B([m],t.value.stateBranchRoot);return d(p)?a(p.message):l("Added issue attachment",{id:u,issueId:e.issueId,fileName:Mn(i.value.hash,i.value.ext),bytes:i.value.bytes})},El=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();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(!A(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 l("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Cl=async e=>{let t=await Me(e.repoRoot);return d(t)?t:Ad(t.value.stateBranchRoot,e.fileName,fi())};var Nl=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=ar();if(d(p))return oe.error(p.message);let{autoSync:f,userName:b,preferredEditor:N}=p.value;return!!(f&&b&&N)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await $o({repoRoot:e.repoRoot}),tn({type:"state",payload:await vt({repoRoot:e.repoRoot})})}finally{o=!1,s&&(s=!1,c())}}},u=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=ar();if(d(p))return oe.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as Gg}from"ws";var Ve=(e,t)=>{e.send(JSON.stringify(t))},br=async(e,t)=>Ve(e,{type:"state",payload:await vt({repoRoot:t})}),ht=async(e,t,n,r,o)=>{if(Ve(e,{type:r,payload:o}),d(o))return Ve(e,{type:"failed",payload:o.message});n(),br(e,t)},Sl=(e,t,{onStateChanged:n})=>{new Gg({server:e,path:"/ws"}).on("connection",o=>{sa(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return br(o,t);if(c==="sync"){let u=await $o({repoRoot:t});return Ve(o,{type:"sync:result",payload:u}),n(),br(o,t)}if(c==="issue:comment:add"){let u=await Ho({repoRoot:t,...i.payload});return ht(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await Wo({repoRoot:t,...i.payload});return Ve(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Ve(o,{type:"failed",payload:u.message}):(n(),br(o,t))}if(c==="issue:edit:description"){let u=await gl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await yl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await vl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await hl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await xl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await bl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Ve(o,{type:"issues",payload:await ll({repoRoot:t})});if(c==="issues:create"){let u=await ul({...i.payload,repoRoot:t});return Ve(o,{type:"issues:create:result",payload:u}),d(u)?tn({type:"failed",payload:u.message}):(tn({type:"issue:created",payload:u.value}),n(),br(o,t))}if(c==="issues:move"){if(!i.payload.position)return Ve(o,{type:"error",message:"Missing move position"});let u=await fl({...i.payload,repoRoot:t});return ht(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await ml({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await pl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:reopen:result",u)}return Ve(o,{type:"error",message:"Unknown message type"})}catch(i){return Ve(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Yg=yn.dirname(qg(import.meta.url)),Xg=process.env.IS_LOCAL==="true"?yn.resolve(process.cwd(),"dist/gui"):yn.join(Yg,"gui"),ye=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Al=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)}),Jg=2*1024*1024,Qg={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},Zg=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",Rl=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=yn.resolve(Xg),o=yn.resolve(r,n),s=yn.relative(r,o);if(s.startsWith("..")||yn.isAbsolute(s))return ye(t,403,{isError:!0,message:"Forbidden"});try{let i=await Tl(o);return t.writeHead(200,{"content-type":Zg(o)}),t.end(i)}catch{return ye(t,404,{isError:!0,message:`Not found: ${n}`})}},ey=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){r(new Error("Unable to resolve address"));return}n(u.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),wl=async e=>{let t=zg.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return ye(s,200,await vt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Al(o);if(!c.issueId||!c.body?.trim())return ye(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Ho({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(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 Al(o,Jg);if(!c.issueId||!c.dataBase64)return ye(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let u=await Il({repoRoot:e.repoRoot,issueId:c.issueId,name:c.name??"",dataBase64:c.dataBase64});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(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/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing attachment id"});let u=await El({repoRoot:e.repoRoot,attachmentId:c});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),u=await Cl({repoRoot:e.repoRoot,fileName:c});if(d(u))return ye(s,404,{isError:!0,message:u.message});try{let m=await Tl(u.value.filePath);return s.writeHead(200,{"content-type":Qg[u.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return ye(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/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing comment id"});let u=await Wo({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Rl("/",s):Rl(i.pathname,s)});try{await ey(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Nl({repoRoot:e.repoRoot});Sl(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")):l("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Ml=async e=>{let t=await wl({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${ty.cyan(n)}`),Li(n),l("Started GUI",{url:n})};import{Box as Jt}from"ink";import ae from"react";import{Box as yi,Text as Ir}from"ink";import ot,{useEffect as ny,useMemo as ry}from"react";import{ulid as oy}from"ulid";var Pl=({text:e,match:t,color:n,highlightColor:r=v.secondary,dimColor:o=!1})=>{if(!t)return ot.createElement(Ir,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?ot.createElement(Ir,{color:n,dimColor:o},e):ot.createElement(Ir,{color:n,dimColor:o},e.slice(0,c),ot.createElement(Ir,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Ll=oy(),sy=e=>`${e}`,iy=e=>{let{pendingNavTarget:t}=jt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ie(x.NONE,{breadCrumb:n,contextNode:r,readOnly:g().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==x.PALETTE).map(i=>{let c=ho(i),u=Do.find(m=>m.intent===c);return{command:i,description:u?.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))},ay=e=>Q.text({id:Ll,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),dy=(e,t,n)=>Q.text({id:sy(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),vi=[],cy=e=>{kl();let t=I.createNode(ay(g().rootNodeId));d(t)||!kt(t.value)||(vi=[t.value,...e.map((n,r)=>dy(n,r,Ll)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0}))},kl=()=>{let e=vi.map(t=>t.id);vi=[];for(let t of e)I.deleteNode(t)};function Dl({width:e,height:t}){let r=Gd().value.trim().toLowerCase(),o=ry(()=>iy(r),[r]);ny(()=>(cy(o),()=>{kl()}),[o]);let s=g().selectedIndex;return ot.createElement(yi,{flexDirection:"column",width:e,height:t-2},ot.createElement(et,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?v.accent:v.secondary2,p=i.isAvailable?"":"[unavailable] ";return ot.createElement(yi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:v.secondary,borderStyle:"single"},ot.createElement(Ir,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",ot.createElement(Pl,{text:ua(i.command),match:r,color:m,dimColor:!i.isAvailable})),ot.createElement(yi,{paddingLeft:2},ot.createElement(Pl,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?v.primary:v.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Ay}from"ink";import Ko from"react";import Cr from"chalk";import{Box as hi,Text as Fl}from"ink";import Er,{useEffect as ly,useMemo as uy,useState as my}from"react";var Bl=Cr.hex(v.secondary),py=Cr.inverse,fy=Cr.inverse.hex(v.secondary2),gy={hint:"",hints:[],overlap:0,remainder:""},Ol=({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}},yy=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=le(t);return{bg:r=>Cr.bgHex(n).black(r),bgCursor:r=>Cr.bgHex(n).inverse.black(r)}}return Rs(t)},vy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Ol({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}},Ul=()=>({value:Ae.value,cursorPosition:Ae.cursorPosition,commandIsPending:Ae.commandIsPending,autoCompletion:Ae.commandMeta.autoCompletion??gy,infoMessage:Ae.commandMeta.infoMessage,validationStatus:Ae.commandMeta.validity,command:Ae.commandMeta.command,inputString:Ae.commandMeta.inputString,modifier:Ae.commandMeta.modifier}),hy=(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,_l=({width:e,mode:t})=>{let[n,r]=my(Ul());ly(()=>{let S=()=>{let M=Ul();r(U=>hy(U,M)?U:M)},R=zs(S);return S(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p,validationStatus:f}=n,b=c&&f===pt.Invalid,N=uy(()=>{let S=Math.max(0,Math.min(s,o.length)),R=Ol({value:o,command:m}),M=vy({value:o,command:m,modifier:p}),U=m?Rs(m):null,j=yy({command:m,modifier:p}),D=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fg(ue):Hn&&j?j.bg(ue):ue},z=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fgCursor(ue):Hn&&j?j.bgCursor(ue):py(ue)},$=o.slice(0,S),P=o[S]??" ",O=S<o.length?o.slice(S+1):"",Ge=Array.from($).map((ue,ce)=>D(ue,ce)).join(""),Ne=z(P,S),ze=Array.from(O).map((ue,ce)=>D(ue,S+1+ce)).join("");if(u.hint){let ue=u.hint[u.overlap]??P;Ne=fy(ue),ze=Bl(u.remainder.slice(1)+O)}return Bl(t===y.PALETTE?"?":":")+Ge+Ne+ze},[o,s,u,m,p]);return Er.createElement(hi,{flexDirection:"column",justifyContent:"flex-start"},Er.createElement(hi,{flexDirection:"column",paddingX:1,borderColor:v.secondary,borderStyle:"round",width:e},Er.createElement(hi,null,Er.createElement(Fl,null,N),i&&Er.createElement(Fl,{wrap:"truncate",color:b?v.red:v.secondary2},` ${i} `))))};import{Box as xy,Text as by}from"ink";import $l from"react";var Iy=(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},Hl=({width:e,availableHints:t})=>{let n=Iy(t,e).join(" | ");return $l.createElement(xy,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1},$l.createElement(by,{color:v.secondary2},n.length?n:"\xA0"))};import{Box as Ey,Text as jo}from"ink";import Nr,{useEffect as Cy,useRef as Un,useState as Ny}from"react";var Sy=40,Vo=.3,xi="\u2500",Wl=1,jl=16,Vl=({width:e})=>{let{replay:t}=H(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*Wl,[c,u]=Ny(0),m=Un(r);m.current=r;let p=Un(0),f=Un(0),b=Un(0),N=Un(0),S=Un(0);if(Cy(()=>{if(!n){p.current=0,b.current=0,N.current=0,S.current=0,u(0);return}p.current=m.current,f.current=Date.now(),b.current=m.current;let D=setInterval(()=>{let z=Date.now(),$=m.current;if($!==b.current){let ze=$-b.current,ue=z-f.current;if(ze<0)N.current=0,S.current=0;else if(ze>0&&ue>0){let ce=ze/ue;N.current=N.current===0?ce:N.current*(1-Vo)+ce*Vo,S.current=S.current===0?ze:S.current*(1-Vo)+ze*Vo}p.current=$,f.current=z,b.current=$}let P=z-f.current,O=Math.min(S.current,N.current*P),Ge=Math.min(1,p.current+O),Ne=Math.round(Ge*i);u(ze=>ze===Ne?ze:Ne)},Sy);return()=>clearInterval(D)},[n,i]),!t)return null;let R=D=>{let z=s>1?D/(s-1):0,$=Math.round(z*(jl-1))/(jl-1);return Gr($)},M=Math.min(s,Math.floor(c/Wl)),U=[];for(let D=0;D<M;D++){let z=R(D),$=U[U.length-1];$&&$.color===z?$.text+=xi:U.push({text:xi,color:z})}let j=xi.repeat(Math.max(0,s-M));return Nr.createElement(Ey,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1,columnGap:1},Nr.createElement(jo,{color:v.secondary2},"\u25B6"),Nr.createElement(jo,null,U.map((D,z)=>Nr.createElement(jo,{key:z,color:D.color},D.text)),Nr.createElement(jo,{color:v.secondary,dimColor:!0},j)))};var Sr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=H(),o=t===y.COMMAND_LINE||t===y.PALETTE;return Ko.createElement(Ay,null,o?Ko.createElement(_l,{width:e,mode:t}):r==="replay"?Ko.createElement(Vl,{width:e}):Ko.createElement(Hl,{width:e,mode:t,availableHints:n}))};import{Box as zt,Text as On}from"ink";import De,{useEffect as Ry,useMemo as Ty}from"react";import{ulid as Kl}from"ulid";var zo=Kl(),wy=()=>[...new Set([...g().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})),My=e=>Q.text({id:zo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Py=(e,t,n)=>Q.text({id:Kl(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),Go=[],Gl=()=>{let e=Go.filter(n=>n.id!==zo).map(n=>n.id),t=Go.filter(n=>n.id===zo).map(n=>n.id);Go=[];for(let n of[...e,...t])I.deleteNode(n)},Ly=e=>{Gl();let t=I.createNode(My(g().rootNodeId));if(d(t)||!kt(t.value))return logger.error("Could not attach help nodes");Go=[t.value,...e.map((n,r)=>Py(n,r,zo)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0})},zl=({width:e,height:t})=>{let n=Ty(()=>wy(),[]);Ry(()=>(Ly(n),()=>{Gl()}),[n]);let r=g().selectedIndex;return De.createElement(zt,{flexDirection:"column",marginTop:3,borderColor:v.secondary,borderStyle:"round",width:e,height:t-2},De.createElement(zt,{paddingX:1,justifyContent:"center"},De.createElement(On,{color:v.accent},"Help"),De.createElement(On,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),De.createElement(zt,{paddingX:1,marginTop:1},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.secondary},"Key(s)")),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:v.secondary},"Action"))),De.createElement(et,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return De.createElement(zt,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.accent},o)),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:c?v.primary:v.secondary2},s)))})))};import ky from"chalk";import{Box as qo,Text as Mt}from"ink";import Ke from"react";var ql=({width:e,height:t})=>Ke.createElement(qo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ke.createElement(Mt,{color:v.accent,bold:!0},"Initialize project"),Ke.createElement(Mt,null,`This folder is not an ${ky.hex(v.accent)("epiq")} project yet.`),Ke.createElement(Mt,{color:v.primary},"To start tracking issues here, we need to initialize a new",Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json "),"file in this repository."),Ke.createElement(qo,{marginTop:1,flexDirection:"column"},Ke.createElement(qo,null,Ke.createElement(Mt,{color:v.accent}," "),Ke.createElement(Mt,{color:v.primary},"Type "),Ke.createElement(Mt,{backgroundColor:v.secondary}," :init "))),Ke.createElement(qo,{marginTop:1},Ke.createElement(Mt,{color:v.secondary2},"This will create, commit and push "),Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json ")));import{Box as Yo,Text as xt}from"ink";import Ce from"react";var Dy=({isDone:e,command:t,value:n})=>Ce.createElement(Yo,null,Ce.createElement(xt,{color:v.accent,dimColor:e},e?" \u2714 ":" "),Ce.createElement(xt,{dimColor:e},"Type "),Ce.createElement(xt,{backgroundColor:v.secondary,dimColor:e}," "+t+" "),n!==void 0&&Ce.createElement(Ce.Fragment,null,Ce.createElement(xt,{dimColor:e}," "),Ce.createElement(xt,{color:v.secondary,dimColor:e},"<"+n+">"))),Fy=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function bi({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Ot(),u=[{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=u.findIndex(f=>!f.done),p=m===-1?void 0:u[m];return Ce.createElement(Yo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ce.createElement(xt,{color:v.accent,bold:!0},"Welcome! \u{1F539}"),Ce.createElement(xt,null,"Let's get you started - it's a breeze."),Ce.createElement(xt,{color:v.secondary2},"Remember - you can always search available commands by typing:",Ce.createElement(xt,{color:v.accent}," ? ")),p&&Ce.createElement(xt,{color:v.secondary2},p.message),Ce.createElement(Yo,{flexDirection:"column"},u.map((f,b)=>m===-1||b<=m?Ce.createElement(Yo,{key:f.key,marginBottom:1},Ce.createElement(Dy,{isDone:f.done,command:f.command,value:f.done?Fy(f.value):void 0})):null)))}import es from"chalk";import{Box as Rr,Text as _n}from"ink";import ve from"react";import{Box as Xo,Text as Yl}from"ink";import qt from"react";import By from"chalk";var Uy=e=>(I.getTag(e)?.name??"").length+3,Oy=e=>(I.getContributor(e)?.name??"").length+3,Xl=({width:e})=>{let{viewMode:t}=K(),n=H(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=It(c?.id??o.id,"TICKET"),m=te(u)?u.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],b=m?.parentNodeId?!Ns(o.id,m.parentNodeId)&&t==="dense":!1,N=r.map(($,P)=>{let O=P===r.length-1,Ge=q($.id),Ne=O?Ge?.[s]?.title:void 0;return`${P?" / ":""}${$.title??""}${Ne?` \u25B8 ${Ne}`:""}`}).join(""),S=m?I.getCommentsByIssue(m.id):[],R=S.length?String(S.length).length+11:0,M=b?p.reduce(($,P)=>$+Uy(P),0)+f.reduce(($,P)=>$+Oy(P),0)+R:0,U=c?.id!=null&&!(t==="wide"&&A(c)),j=Math.max(0,e-M),D=N.substring(0,j)+(U?By.hex(v.secondary2).dim(` ${Ue(c.id)}`):""),z=b?[...p.map($=>qt.createElement(Xo,{key:`tag-${$}`,paddingLeft:1},qt.createElement(kn,{id:$}))),...f.map($=>qt.createElement(Xo,{key:`assignee-${$}`,paddingLeft:1},qt.createElement(Ht,{id:$}))),S.length?qt.createElement(Xo,{key:"comments",paddingLeft:1},qt.createElement(Yl,{color:v.accent},"[",S.length," comment",S.length===1?"":"s","]")):null]:[];return qt.createElement(Xo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},qt.createElement(Yl,{color:v.secondary2},D),z)};import{Box as _y,Text as Jl}from"ink";import Jo from"react";var $y=({filters:e})=>Jo.createElement(_y,{columnGap:1},Jo.createElement(Jl,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Jo.createElement(Jl,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Ql=Jo.memo($y);import{Box as Hy,Text as Qo}from"ink";import Ar from"react";function Zl(){let{eventLog:e,unappliedEvents:t}=H(),n=e.at(-1)?.id,r=Xr(n??""),o=te(r)?Yr(r.value):"INVALID DATE";return Ar.createElement(Hy,{paddingLeft:1},Ar.createElement(Qo,{backgroundColor:v.accent,color:v.secondary}," Readonly "),Ar.createElement(Qo,{color:v.accent}," "+t.length+" edits ago at "+o+"."),Ar.createElement(Qo,{color:v.accent}," Resume with "),Ar.createElement(Qo,{backgroundColor:v.accent,color:v.secondary}," ",":peek now"," "))}import{Box as Wy,Text as Ii}from"ink";import Zo from"react";function eu(){let{replay:e}=H();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return Zo.createElement(Wy,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},Zo.createElement(Ii,{backgroundColor:v.accent,color:v.secondary}," \u25B6 REPLAY "),Zo.createElement(Ii,{color:v.secondary2},Yr(new Date(r))),Zo.createElement(Ii,{color:v.accent},`${t}/${n} edits`))}import Ei from"chalk";import{Box as jy,Text as tu}from"ink";import Ci,{useEffect as Vy,useState as Ky}from"react";var Gy=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],zy=150,nu=12,qy=.36,ru=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)}},Yy=({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)}`},Xy=(e,t,n)=>{let r=ru(e),o=ru(t);return Yy({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Jy=(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 Xy(s,i,o)};function ou({syncStatus:e,autoSync:t}){let[n,r]=Ky(0);Vy(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*qy)+1)/2,p=Math.round(m*(nu-1));r(f=>f===p?f:p)},zy);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:v.secondary2,failed:v.yellow,pending:v.secondary2,syncing:Jy(Gy,n/(nu-1))??""}[e.status];return Ci.createElement(jy,null,Ci.createElement(tu,null,Ei.hex(v.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Ci.createElement(tu,null,Ei.hex(i)("\u25CF")+Ei.hex(v.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import cu from"chalk";import{Text as lu}from"ink";import uu,{useEffect as tv,useState as nv}from"react";var Yt="1.3.0";import Ni from"chalk";var Qy="https://registry.npmjs.org/epiq/latest",Si=null,su=0,Zy=1e3*60*60*24,iu=e=>e.replace(/^v/,""),ev=(e,t)=>{let n=iu(e).split(".").map(Number),r=iu(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},au=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Si&&Date.now()-su<Zy)return Si;try{let t=await fetch(Qy);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?ev(r,e)>0:!1};return Si=o,su=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},du=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Ni.hex(v.accent).dim(s):Ni.hex(v.secondary).dim(s)).join(Ni.hex(v.secondary2).dim("."))};function mu(){let[e,t]=nv({current:Yt,latest:null,updateAvailable:!1});return tv(()=>{let n=!0;return au(Yt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?uu.createElement(lu,{dimColor:!0,color:v.secondary2},Yt+" "):uu.createElement(lu,null,cu.hex(v.secondary2).dim(Yt),cu.hex(v.accent).dim(" \u2197 "),du(Yt,e.latest))}function Tr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=H(),{userName:i,preferredEditor:c,autoSync:u}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",b=s?nn(s.currentLabel,Math.max(0,p)):"";return ve.createElement(Rr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?ve.createElement(Rr,{paddingLeft:1},ve.createElement(_n,{color:v.secondary2},b)):f?ve.createElement(_n,null," "):o===y.PALETTE?ve.createElement(Rr,null,ve.createElement(_n,{color:v.accent},"Command Palette"),ve.createElement(_n,{dimColor:!0,color:v.secondary2}," ","- search, select and press enter")):ve.createElement(Rr,{paddingLeft:1},e.length>0?ve.createElement(Ql,{filters:e}):ve.createElement(Xl,{width:p})),n==="live"?ve.createElement(Rr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},ve.createElement(ou,{autoSync:!!u,syncStatus:r}),ve.createElement(_n,null,es.hex(v.secondary2).dim("Mode: ")+es.hex(v.secondary2).dim(o.padEnd(8," "))," "),ve.createElement(pu,{icon:"@",value:i}),ve.createElement(pu,{icon:"\u276F",value:c}),ve.createElement(mu,null)):"",n==="peek"?ve.createElement(Zl,null):"",n==="replay"?ve.createElement(eu,null):"")}function pu({icon:e,value:t}){return ve.createElement(_n,null,es.dim(e)+es.hex(v.accent)(` ${t??"-"} `))}import{Box as rv,Text as ov}from"ink";import wr from"react";import{Box as ts,Text as Ai}from"ink";import Xt from"react";function Ri(){let e=H(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?G(t?.id):[];return Xt.createElement(ts,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:v.secondary,width:s},Xt.createElement(ts,{padding:1,paddingTop:0,paddingBottom:0},Xt.createElement(Ai,null,"Select a board:")),Xt.createElement(ts,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,f=G(c.id).flatMap(({id:b})=>q(b)).length;return Xt.createElement(ts,{key:c.id??u},Xt.createElement(Ai,{color:m?v.accent:v.secondary2},Xt.createElement(Re,{isSelected:m})),Xt.createElement(Ai,{color:m?v.accent:v.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var sv=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=H(),u=n.find(({context:b})=>b==="BOARD"),f=s-1-3;return wr.createElement(rv,{flexDirection:"row"},e.context==="WORKSPACE"?wr.createElement(Ri,null):u?wr.createElement(So,{height:f,width:i,swimlanes:(c[u.id]??[]).filter(b=>b!==void 0&&Dt(b)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):wr.createElement(ov,null))},fu=wr.memo(sv);import{useEffect as iv}from"react";var av=e=>{iv(()=>{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:u}=g();u==="default"&&!c&&io(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},gu=({autoSync:e})=>(av(e),null);function Ti({width:e,height:t}){let n=H(),{autoSync:r,viewMode:o}=va(),s=n.filters;if(n.mode===y.HELP)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(zl,{width:e,height:t}));if(n.mode===y.PALETTE)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(Dl,{width:e,height:t-2}),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Ot(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(bi,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(ql,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Le(n.breadCrumb??[],"BOARD");if(te(m)){let p=m.value.id,f=G(p).length,b=3,N=Math.floor(e/b),S=Math.floor(e/Math.max(f,1));e=Math.min(S,N)*Math.max(f,b)}return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(gu,{autoSync:r}),ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(fu,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import dv from"readline";var ns,rs,bt,cv=new Set([h.MoveCursorLeft,h.EraseInputWord,h.MoveCursorLeftOfWord,h.MoveCursorRight,h.MoveCursorRightOfWord,h.NavToPreviousContainer,h.NavToNextContainer,h.NavPreviousItem,h.NavNextItem,h.SetViewDense,h.SetViewWide,h.Confirm,h.Exit,h.Yank,h.InitCommandLine,h.InitCommandPalette,h.ExitCommandLine,h.CaptureInput,h.EraseInput,h.EraseInputWord,h.HideHelp,h.ViewHelp,h.SetViewDense,h.SetViewWide,h.GetLastCommandFromHistory,h.GetNextCommandFromHistory,h.AutoCompleteCommand]),lv=new Set([h.NavPreviousItem,h.NavNextItem,h.NavToPreviousContainer,h.NavToNextContainer,h.Confirm,h.Exit,h.InitCommandPalette,h.InitMove,h.MoveNextItem,h.MovePreviousItem,h.MoveToNextContainer,h.MoveToPreviousContainer,h.Delete,h.AddItem,h.EditTitle,h.EditDescription,h.ConfirmMove,h.Edit,h.ViewHelp,h.Yank]),yu=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=g(),s=qd(e,n);if(!s||r&&!cv.has(s)||o==="replay"&&n===y.DEFAULT&&lv.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},uv=()=>async function(t,n){n.name!=="escape"&&(bt&&(clearTimeout(bt),bt=void 0),await yu(n))},mv=()=>async function(t){if(t.length===1&&t[0]===27){bt&&clearTimeout(bt),bt=setTimeout(()=>{yu({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),bt=void 0},25);return}bt&&(clearTimeout(bt),bt=void 0)};function vu(){ns&&process.stdin.removeListener("keypress",ns),rs&&process.stdin.removeListener("data",rs),ns=uv(),rs=mv(),dv.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",rs),process.stdin.on("keypress",ns)}async function hu(){try{let e=wn();te(e)&&Fe(e.value);let t=Ye(process.cwd()),n=[];if(te(t)){let s=Pe({repoRoot:t.value});if(d(s))return dn(3,s.message);let i=vn(),c=await en({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return dn(3,c.message);let u=await _({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=Et(s.value);if(d(m))return dn(3,m.message);n=m.value}let r=an(n);if(d(r))return dn(4,r.message);E({hasProjectDefinition:te(t),hasInitializingEvents:!!n.length});let o=wi();return d(o)?dn(6,o.message):(vu(),l("Booted Epiq",void 0))}catch(e){return dn(0,ro(e))}}vc();var yv=`${Qt.bold("Epiq CLI")}
58
+ `));let ce=Je();if(d(ce))return ee(16,ce.message);let{rootNodeId:$n,nodes:Hn}=ce.value,Mi=Hn[$n];return Mi?(T.navigate({contextNode:Mi,selectedIndex:0}),E({hasProjectDefinition:!0,mode:y.DEFAULT}),l(O,null)):ee(16,"Unable to resolve initialized root node")};import{ulid as hg}from"ulid";import{ulid as vg}from"ulid";var Nc=null,Kt=()=>structuredClone(Nc),vr=e=>{Nc=e},Sc=()=>{let{contextNode:e,selectedIndex:t}=g(),r=q(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},ii=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q(t).filter(o=>o.id!==e);return to(r,n)},Ac=({id:e,parentId:t,position:n={at:"end"}})=>{let r=se();if(d(r))return a("Unable to resolve user ID");let o=ii({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:vg(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Rc=e=>{vr(e);let t=Bt(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function ai(e){let t=Sc();if(d(t))return t;let{contextNode:n,nodes:r}=g();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=q(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 u=Ac({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Rc(u.value)}function di(e){let t=Sc();if(d(t))return t;let{contextNode:n,selectedIndex:r}=g(),s=q(n.id)[r+e];if(!s)return a("Missing sibling node");let i=Ac({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Rc(i.value)}var Tc=()=>{let e=Kt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=g().nodes[n];if(!r)return a("Move parent not found");let o=q(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},To=(e,t="Moved preview")=>{if(d(e))return e;let n=Tc();return d(n)?n:(E({mode:y.MOVE}),l(t,null))},wc=async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=Y().commandMeta,{contextNode:n,selectedIndex:r}=g(),o=q(n.id)[r];if(!o)return E({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=q(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],u=s[i+1],m=u!=null?{at:"before",sibling:u.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=ii({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(vr({id:hg(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),E({mode:y.MOVE}),l("Move initialized",null))}if(t==="next")return To(di(1));if(t==="previous")return To(di(-1));if(t==="to-next")return To(ai(1));if(t==="to-previous")return To(ai(-1));if(t==="confirm"){let s=Kt();if(!s)return a("No pending move to confirm");let i=await at();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=Tc();return d(u)?u:(vr(null),E({mode:y.DEFAULT}),l("Moved item",null))}return t==="cancel"?(vr(null),E({mode:y.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Mo}from"ulid";import{monotonicFactory as xg,ulid as bg}from"ulid";var Ig=xg(),wo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Ig();return l("Created issue events",[{id:bg(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Mc=async(e,t)=>{let n=se();if(d(n))return a("Unable to resolve user ID");let r=await at();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}=g(),u=m=>{let p=B([m],o);if(d(p))return p;let f=I.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let b=I.getNode(f.parentNodeId);return b?(T.navigate({contextNode:b,selectedIndex:I.getSiblings(f.parentNodeId).findIndex(({id:N})=>N===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let f=Sn(p.id,n.value,o);return d(f)?f:u({id:Mo(),action:"add.board",payload:{id:Mo(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Le(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Sn(m.value.id,n.value,o);return d(p)?p:u({id:Mo(),action:"add.swimlane",payload:{id:Mo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=G(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Le(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let f=Sn(p.id,n.value,o);if(d(f))return f;let b=wo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(b))return b;let N=b.value,S=B([...N],o);if(d(S))return S;if(!S.value[0])return a("Issue creation failed");let U=N.find(j=>j.action==="add.issue")?.payload.id;return U?(T.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===U)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Po=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=g(),s=Oa(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=Gt();if(d(u))return u;let p=Ut(i).filter(d);if(p.length>0)return Gt(),E(o),a(p.map(b=>b.message).join(", "));let f=g().nodes[e];return f?(T.navigate({contextNode:f,selectedIndex:r}),l("",{unappliedEvents:c})):(Gt(),E(o),a("Board did not exist at that date"))};var Eg=20,Cg=16,Ng=150,Lo=null,ko=null;var fn=()=>{Lo!==null&&(clearInterval(Lo),Lo=null),ko!==null&&(clearTimeout(ko),ko=null)},Pc=()=>{fn(),E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Sg=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)},Lc=({events:e,startTime:t,durationMs:n})=>{fn();let r=e.length,o=e.map(f=>Nn(f)??t),s=o[r-1]??Date.now(),i=Sg(o),c=Math.max(1,Math.round(n*Eg/1e3)),u=Math.max(Math.round(n/c),Cg),m=0,p=0;E({mode:y.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),Lo=setInterval(()=>{m++;let f=m/c,b=[],N;for(;p<r&&i[p]<=f;){let R=e[p],M=Bt(R);if(d(M)){Pc();return}b.push(...Ts(R)),N=R,p++}if(p>=r||m>=c){for(;p<r;p++){let M=Bt(e[p]);if(d(M))break}let R=g().replay;E({unappliedEvents:[],replay:R&&{...R,progress:1,appliedCount:r}}),fn(),ko=setTimeout(Pc,Ng);return}let S=g().replay;E({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:N?Nn(N)??S?.currentTime??t:S?.currentTime??t,currentLabel:N?Pa(N):S?.currentLabel??"",flashNodeIds:N?[...new Set(b)]:S?.flashNodeIds??[]}})},u)};var kc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta;if(fn(),r==="now"){let c=Et(n.value);if(d(c))return a(c.message);let u=Gt();if(d(u))return u;let p=Ut(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=g().eventLog.at(-1),u=Nn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=g().unappliedEvents.at(0),u=Nn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=cn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Po({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(E({mode:y.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var Dc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta,{dateInput:s,durationInput:i}=uo(r,o);if(fn(),g().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=cn(s);if(!c)return a("Invalid replay date");let u=i?lo(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=g(),f=Po({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:b}=f.value;return b.length===0?(Gt(),E(p),l("Nothing to replay from that point",!0)):(Lc({events:b,startTime:m,durationMs:u}),l("Replaying board history",!0))};import Rg from"zod";var Fc=()=>{let e=Y().commandMeta.inputString,t=Rg.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=Ze({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),E({mode:y.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Bc=()=>{let e=Y().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=ad(e),n=Ze({autoSync:t});return d(n)?n:(Fe({autoSync:t}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Uc=()=>{let e=Y().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Ze({logLevel:e});return d(n)?n:(Fe({logLevel:e}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};import{spawn as Tg}from"node:child_process";var wg=()=>{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"]}}},Oc=async e=>new Promise(t=>{let{command:n,args:r}=wg();try{let o=Tg(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?l("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 hr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await Oc(e);return d(n)?n:l(`Copied ${t} to clipboard`,null)},_c=async e=>{let{breadCrumb:t,selectedNode:n}=g(),r=ir({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case pe.REF:return hr(Ue(o.id),"ref");case pe.TITLE:return hr(o.title,"title");case pe.DESCRIPTION:return r?hr(r.props?.description??"","description"):a("No issue in scope");case pe.TAGS:{if(!r)return a("No issue in scope");let s=_t(r).map(({name:i})=>i);return hr(s.join(", "),"tags")}case pe.ASSIGNEES:{if(!r)return a("No issue in scope");let s=$t(r).map(({name:i})=>i);return hr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var $c=async()=>{W(""),E({mode:y.DEFAULT});let e=Je();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await oo();return d(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:y.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Mg=e=>e.action==="add.issue.comment",Hc=e=>Object.values(g().tags).find(t=>t.name===e),Wc=e=>Object.values(g().contributors).find(t=>t.name===e),wt=async()=>{let e=await at();return d(e)?e:l("Resolved persist root",e.value)},Do=[{systemOnly:!0,intent:w.Move,description:"Internal move-state command",mode:y.COMMAND_LINE,action:wc},{intent:w.Delete,description:"Delete the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await wt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=A(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!A(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Mg).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:we(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:we(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:y.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Y().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ie(x.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return he(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:y.DEFAULT})),l("Filter updated",null)}},{intent:w.ViewHelp,description:"Open the help screen",mode:y.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:y.HELP}),l("Viewing help",null)}},{intent:w.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!A(r))return a("Cannot close in this context");let o=g().nodes[me];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await wt();if(d(s))return s;let i=s.value,c=sn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:we(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):It(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=g().nodes[me];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!A(s))return a("Target node is not issue");let c=Ao(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 u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await wt();if(d(m))return m;let p=m.value,f=sn(u.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let b=B([{id:we(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:f.value},...e.value}],p);return d(b)?b:l("Issue reopened",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Init,description:"Initialize Epiq in the current git repository",mode:y.COMMAND_LINE,action:Cc},{intent:w.NewItem,description:"Create a new board, swimlane, or issue",mode:y.COMMAND_LINE,action:Mc,onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Rename,description:"Rename the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=zd();if(!o)return a("Provide a title");let s=await wt();return d(s)?s:B([{id:we(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UntagTicket,description:"Remove a tag from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Hc(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!A(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 wt();return d(m)?m:B([{id:we(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.TagTicket,description:"Add or create a tag on the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=g();if(!o)return a("Invalid tag target");let s=It(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!A(i))return a("Target node is not issue");let c=await wt();if(d(c))return c;let u=Hc(r),m=u?.id??we();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:we(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:we(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.AssignUserToTicket,description:"Assign a user to the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=g(),i=G(s.id)[o];if(!i)return a("Invalid assign target");let c=It(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!A(u))return a("Target node is not issue");let m=await wt();if(d(m))return m;let p=Wc(r),f=p?.id??we();return(u.props.assignees??[]).includes(f)?a("Assignee already assigned"):B([...p?[]:[{id:we(),action:"create.contributor",payload:{id:f,name:r},...e.value}],{id:we(),action:"add.issue.assignee",payload:{id:u.id,assignee:f},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=Wc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!A(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(o.id))return a(`Issue is not assigned to "${r}"`);let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.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>Pn)return a(`Cannot exceed ${Pn} characters`);let r=se();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=g(),i=Le([...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 u=c.context==="TICKET"?l("Resolved ticket",c):It(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!A(m))return a("Target node is not issue");let p=await wt();return d(p)?p:B([{id:we(),action:"add.issue.comment",payload:{id:we(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Sync,description:"Pull, commit, and push Epiq state",mode:y.COMMAND_LINE,action:$c},{intent:w.Peek,description:"View board state at another point in time",mode:y.COMMAND_LINE,action:kc},{intent:w.Replay,description:"Replay board history forward from a point in time",mode:y.COMMAND_LINE,action:Dc},{intent:w.Export,description:"Export the current board layout to markdown",mode:y.COMMAND_LINE,action:async()=>{let e=await gc();return d(e)?e:(E({mode:y.DEFAULT}),l("Export successful",!0))}},{intent:w.Exit,description:"Exit the application",mode:y.COMMAND_LINE,action:async()=>(T.exit(),l("Exit successful",!0))},{intent:w.Edit,description:"Edit title or description",mode:y.COMMAND_LINE,action:async(e,t)=>bc(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:y.COMMAND_LINE,action:async(e,t)=>_c(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.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 ne.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??we();if(!i||!c)return a("Unable to resolve user name or id");let u=Ze({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(Fe({userName:i,userId:c}),E({mode:y.DEFAULT}),l(`Username set to "${i}"`,null))}case ne.EDITOR:{if(!n)return a("No editor provided");let r=Ze({preferredEditor:n});return d(r)?r:(Fe({preferredEditor:n}),E({mode:y.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case ne.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Ze({viewMode:n});return d(r)?r:(Fe({viewMode:n}),E({mode:y.DEFAULT}),l(`View set to "${n}"`,null))}case ne.AUTOSYNC:return Bc();case ne.LOG_LEVEL:return Uc();case ne.SYNC_DEBOUNCE_MS:return Fc();case ne.ATTACHMENT_MAX_KB:return Rd();default:return a("Unknown config command")}}},{intent:w.Coffee,description:"Sponsor the development of Epiq!",mode:y.COMMAND_LINE,action:()=>{let e=Y().commandMeta.modifier;return e==="custom"?yr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):yr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var Pg=new Set(["peek","replay","filter","view-help","yank"]),yt=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Y();if(!t)return a("No command to confirm");if(!e&&n===pt.Invalid)return a("Invalid command");let s=ho(t);Wd();let{readOnly:i}=g();if(i&&!Pg.has(s))return ur({status:Pt.Fail,message:"Command not available in readonly state",value:null});let c=Do.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return ur({status:Pt.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return ur({status:Pt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?ur(u):(jd({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&io(),u)};var Fo=[{intent:h.Exit,mode:y.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:y.COMMAND_LINE}),W("move cancel"),yt({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:y.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:y.COMMAND_LINE}),W("move start"),yt({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:y.MOVE,action:()=>(E({mode:y.COMMAND_LINE}),W("move confirm"),yt({isForceExecutedBySystem:!0}))}],Bo=[{intent:h.MovePreviousItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move next"),yt({isForceExecutedBySystem:!0})):a("No pending move")}],jc=[{intent:h.MoveToNextContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-next"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")}];var Vc={[L.WORKSPACE]:[...Fo,...Bo],[L.BOARD]:[...Fo,...Bo],[L.SWIMLANE]:[...Fo,...Bo,...jc],[L.TICKET]:[],[L.FIELD]:[],[L.FIELD_LIST]:[],[L.TEXT]:[],[L.COMMENT]:[]};import Lg from"node:fs";import kg from"node:path";var Kc=e=>{let t=Ye(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=Mn(e.hash,e.ext),o=kg.join(Kn(n.value),r);return Lg.existsSync(o)?(yr(o),l(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var Gc=()=>{W("");let{pendingNavTarget:e}=jt();E({mode:y.DEFAULT}),e&&T.navigate(e),Vt({pendingNavTarget:void 0})},zc=[{intent:h.ExitCommandLine,mode:y.HELP,action:()=>(Gc(),l("Exiting help",null))},{intent:h.Exit,mode:y.HELP,action:()=>(Gc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:y.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:y.HELP,action:()=>(T.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:y.HELP,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:y.HELP,action:()=>(T.navigateToNextContainer(),l("Navigating to next help container",null))}];var Dg=e=>{E({mode:y.COMMAND_LINE});let{pendingNavTarget:t}=jt();t&&T.navigate(t),Vt({pendingNavTarget:void 0}),W(`${e} `)},qc=()=>{W("");let{pendingNavTarget:e}=jt();e&&T.navigate(e),Vt({pendingNavTarget:void 0}),E({mode:y.DEFAULT})},Yc=[{intent:h.InitCommandPalette,mode:y.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:y.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:y.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!kt(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?(Dg(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:y.PALETTE,action:()=>(qc(),l("Exiting palette",null))},{intent:h.Exit,mode:y.PALETTE,action:()=>(qc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:y.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.PALETTE,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.PALETTE,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.PALETTE,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Xc=[...zc,...Yc,{intent:h.AddItem,mode:y.DEFAULT,description:"[n] new...",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:y.DEFAULT,description:"[d] delete",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:y.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:y.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:y.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!q(e?.id??"")?.length){let r=e?I.getAttachment(e.id):void 0;if(r)return Kc(r);if(e?.title===J.DESCRIPTION)return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===J.ASSIGNEES)return E({mode:y.COMMAND_LINE}),W(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===J.TAGS)return E({mode:y.COMMAND_LINE}),W(`${x.TAG} `),l("Propose command",!0);if(t.title===J.DESCRIPTION&&e?.context==="TEXT")return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0)}return T.enterChildNode(),l("Entering context",null)}},{intent:h.Yank,mode:y.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=g(),t=e?.title===J.DESCRIPTION?pe.DESCRIPTION:e?.title===J.TAGS?pe.TAGS:e?.title===J.ASSIGNEES?pe.ASSIGNEES:pe.REF,r=ie(x.YANK).includes(t)?t:pe.REF;return E({mode:y.COMMAND_LINE}),W(`${x.YANK} ${r}`),l("Propose command",!0)}},{intent:h.EditTitle,mode:y.DEFAULT,description:"[r] rename title",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:y.DEFAULT,description:"[e] edit description",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:y.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:y.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.DEFAULT,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.DEFAULT,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.DEFAULT,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Fg=500,Bg=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Jc=e=>{let t=Bg(e);t&&vo(n=>(n+t).slice(0,Fg))};var Ug=[y.COMMAND_LINE,y.PALETTE],Og=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(qs(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(qs(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Ys("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Ys("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(vo((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=g().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(Jc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>($d(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(Hd(),l("Erasing input word",null))}],Qc=[{intent:h.Confirm,mode:y.COMMAND_LINE,action:()=>(yt(),l("Executing command",null))},{intent:h.ViewHelp,mode:y.DEFAULT,action:()=>(E({mode:y.HELP}),l("Viewing help",null))},...Ug.flatMap(Og),{intent:h.ExitCommandLine,mode:y.COMMAND_LINE,action:()=>(E({mode:y.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Vd(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Kd(),l("Getting next command from history",null))}];import tl from"chalk";var Uo=tl.dim.hex(v.secondary2)(": for command line"),Zc="q to exit",el=`${tl.hex(v.accent)("m")} to confirm`,ci={[L.WORKSPACE]:[Uo],[L.BOARD]:[Uo],[L.BOARD+y.COMMAND_LINE]:[Uo],[L.SWIMLANE]:[Uo],[L.TICKET+y.HELP]:[Zc],[L.SWIMLANE+y.HELP]:[Zc],[L.TICKET]:[],[L.FIELD]:[],[L.SWIMLANE+y.MOVE]:[el],[L.TICKET+y.MOVE]:[el]};var xr=e=>e.trim().toLocaleLowerCase(),_g=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},$g=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},nl=(e,t)=>{let n=xr(t.value);if(!n)return!0;switch(t.target){case"title":return xr(e.title??"").includes(n);case"description":return xr(e.props.description??"").includes(n);case"tag":return _g(e).map(xr).some(o=>o.includes(n));case"assignee":return $g(e).map(xr).some(o=>o.includes(n));case"ref":return ba(e.id,t.value);default:return!0}};function rl(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(),l("Breadcrumb built",o))}var ol=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 gn,li,ui=new Set,sl=()=>{for(let e of ui)e()},Wg=e=>(ui.add(e),()=>ui.delete(e));function il(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 u=rl(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,f=ci[p+n]??ci[p]??[],b=[...Xc,...Vc[p]??[],...Qc],N=ol(b),S=jg(o,s),R=S[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:b,actionIndex:N,selectedNode:R,renderedChildrenIndex:S})}var g=()=>{if(!gn)throw new Error("State not initialized. Call initWorkspaceState() first.");return gn},Je=()=>gn?l("Retrieved state",gn):a("State not initialized. Call initWorkspaceState() first.");function nr(e){li=e;let t=Ye(process.cwd()),n=!1;if(!d(t)){let s=Lt(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=il(r);return d(o)?o:(gn=o.value,sl(),l("State initialized",null))}function he(e){let t=g(),n=e(t),r=il(n);return d(r)?a(r.message??"Unable to update state"):(gn=r.value,sl(),l("State updated",null))}var E=e=>he(t=>({...t,...e}));var H=()=>Hg(Wg,g,g),jg=(e,t)=>{let n={};for(let r of Object.values(e))A(r)&&t.length>0&&!t.every(o=>nl(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},G=e=>g()?.renderedChildrenIndex[e]??[],Gt=()=>li?nr(li):a("Cannot reset state: no initial workspace found"),Rn=()=>gn!==void 0;var mi=e=>{Rn()&&(E({syncStatus:e}),tn({type:"sync-status",payload:e}))},Oo=(e="Syncing...")=>{mi({status:"syncing",msg:e})},_o=(e="Synced")=>{mi({status:"synced",msg:e})},pi=e=>{mi({status:"failed",msg:e})},Qe=e=>(pi(e),a(e));import{decodeTime as JL}from"ulid";var Vg=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=X("getRepoRootDir",await dt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=X("getStateBranchRoot",Pe({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=X("ensureInitialCommit",await ta(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=X("bootstrapStateBranchStorage",await oa({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 u=X("hasInProgressGitOperation(stateBranchRoot)",await Fr(s));if(d(u))return a(u.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:u.value}),u.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=X("ensureStateBranchLayout",Qi(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}),l("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},Kg=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=X("stageStateBranchOwnEventFile",await Wr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=X("stageStateBranchMediaFiles",await na({stateBranchRoot:t}));if(d(o))return a(o.message);let s=X("hasStagedChanges(after stage)",await Ki(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"),l("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=X("createStateBranchSyncCommit",await ra({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),l("Committed own event file",{createdCommit:!0,commitSha:i.value}))},so=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");Oo();let n=X("ensureSyncReady",await Vg({cwd:e,ensureUpstream:!0}));if(d(n))return Qe(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=X("isDetachedHead(stateBranchRoot)",await Gi(o));if(d(i))return Qe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Qe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,f=X("getStateBranch",hn(r));if(d(f))return Qe(f.message);let b=f.value;logger.debug("[sync] resolved state branch",{stateBranch:b,stateBranchRoot:o});let N=X("commitOwnEventFileToStateBranch",await Kg({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(N))return Qe(N.message);c=N.value.createdCommit,u=N.value.commitSha;let S=X("pullBranchRebaseIfPresent",await vs({cwd:o,branch:b}));if(d(S))return Qe(S.message);if(m=S.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let R=X("pushStateBranch",await Jn({stateBranchRoot:o,repoRoot:r}));if(d(R)&&Vi(R.message)){let M=X("pullBranchRebaseIfPresent(retry)",await vs({cwd:o,branch:b}));if(d(M))return Qe(M.message);m=m||M.value,R=X("pushStateBranch(retry)",await Jn({stateBranchRoot:o,repoRoot:r}))}if(d(R))return Qe(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let R=X("git rev-parse HEAD",await _({args:["rev-parse","HEAD"],cwd:o}));if(d(R))return Qe(R.message);u=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return _o(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var fi=()=>{let e=wn();return d(e)?mt:e.value.attachmentMaxKb??mt},gi=e=>{let t=Ye(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},Me=async e=>{let t=gi(e);if(d(t))return t;let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=vn(),o=await en({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:r.stateBranch});if(d(o))return a(o.message);let s=await _({cwd:n.value,args:["pull","--ff-only"]});d(s)&&oe.info(3,s.message);let i=Et(n.value);if(d(i))return a(i.message);let c=an(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},ke=()=>{let e=wn();return d(e)?a(e.message):e.value.userId?e.value.userName?l("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},je=()=>{let e=Je();return d(e)?a(e.message):e},dl=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)})),cl=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)}));var ll=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes).filter(A).filter(o=>e.includeClosed||o.parentNodeId!==me).map(o=>({id:o.id,ref:Ue(o.id),title:lt(o.title),description:o.props.description??"",parentNodeId:o.parentNodeId,isClosed:o.parentNodeId===me,readonly:!!o.readonly,tags:dl(o),assignees:cl(o)}));return l("Listed issues",r)},ul=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Sn(e.parentId,n.value,t.value.stateBranchRoot);if(d(r))return r;let o=wo({name:e.title,parent:e.parentId,user:n.value,rank:r.value});if(d(o))return o;let s=o.value,i=B([...s],t.value.stateBranchRoot);if(d(i))return a(i.message);let c=s.find(u=>u.action==="add.issue")?.payload.id;return c?l("Created issue",{id:c,title:e.title,parentId:e.parentId}):a("Unable to determine created issue id")},ml=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=sn(me,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:ge(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:me,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},pl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Target node is not issue");if(o.parentNodeId!==me)return a("Issue is not closed");let s=Ao(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===me)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=sn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:ge(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=B([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:o.id,parentId:i.id})},fl=async e=>{let t=gi(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Pe({repoRoot:t.value});if(d(r))return r;let o=Et(r.value);if(d(o))return o;let s=an(o.value);if(d(s))return s;let i=sn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:ge(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=B([c],r.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})},$o=async(e={})=>{Oo();let t=gi(e.repoRoot);if(d(t))return a("Sync failed");let n=ke();if(d(n))return n;let r=await so({cwd:t.value,ownEventFileName:on(n.value)});return d(r)?(pi(r.message),r):(_o(),l("Synced",r.value))};var vt=async(e={})=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes),o=r.filter(f=>Vr(f)&&!f.isDeleted),s=new Map,i=new Map;for(let f of r)if(!f.isDeleted){if(Dt(f)&&f.parentNodeId){let b=s.get(f.parentNodeId)??[];b.push(f),s.set(f.parentNodeId,b)}if(A(f)&&f.parentNodeId){let b=i.get(f.parentNodeId)??[];b.push(f),i.set(f.parentNodeId,b)}}let c=wn();if(d(c))return c;let u={};for(let f of r.filter(A))f.isDeleted||(u[f.id]=I.getCommentsByIssue(f.id).map(b=>{let N=I.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:{id:b.authorId,name:N?.name??"Unknown",color:le(N?.name??b.authorId)},createdAt:al(b.id)}}));let m=new Map;for(let f of n.value.eventLog)f.action==="add.issue.attachment"&&m.set(f.payload.id,f.payload.author);let p={};for(let f of r.filter(A))f.isDeleted||(p[f.id]=I.getAttachmentsByIssue(f.id).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Mn(b.hash,b.ext),bytes:b.bytes,createdAt:al(b.id),canDelete:m.get(b.id)===c.value.userId})));return l("Retrieved Epiq GUI state",{boards:o.sort((f,b)=>f.rank.localeCompare(b.rank)).map(f=>({id:f.id,ref:Ue(f.id),title:f.title,swimlanes:(s.get(f.id)??[]).sort((b,N)=>b.rank.localeCompare(N.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly,issues:(i.get(b.id)??[]).sort((N,S)=>N.rank.localeCompare(S.rank)).map(N=>({id:N.id,ref:Ue(N.id),title:lt(N.title),description:N.props.description??"",readonly:!!N.readonly,tags:dl(N),assignees:cl(N),parentNodeId:N.parentNodeId,isClosed:N.parentNodeId===me})),parentNodeId:b.parentNodeId}))})),tags:Object.values(n.value.tags).map(f=>({...f,color:le(f.name)})),contributors:Object.values(n.value.contributors).map(f=>({...f,color:le(f.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:le(c.value.userName??"")},commentsByIssueId:u,attachmentsByIssueId:p,attachmentMaxKb:fi()})},gl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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 l("No changes made",{id:e.issueId,description:s});let i={id:ge(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},yl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=lt(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:ge(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},vl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=lt(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??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},hl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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:ge(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},xl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=lt(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(r.value.contributors).find(p=>p.name===s),c=i?.id??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},bl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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:ge(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},Ho=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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=ge(),c={id:ge(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},Wo=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();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(!A(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 l("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},Il=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(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=Sd(t.value.stateBranchRoot,s,fi());if(d(i))return i;let c=lt(e.name??"").trim()||"image",u=ge(),m={id:ge(),...n.value,action:"add.issue.attachment",payload:{id:u,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=B([m],t.value.stateBranchRoot);return d(p)?a(p.message):l("Added issue attachment",{id:u,issueId:e.issueId,fileName:Mn(i.value.hash,i.value.ext),bytes:i.value.bytes})},El=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();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(!A(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 l("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Cl=async e=>{let t=await Me(e.repoRoot);return d(t)?t:Ad(t.value.stateBranchRoot,e.fileName,fi())};var Nl=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=ar();if(d(p))return oe.error(p.message);let{autoSync:f,userName:b,preferredEditor:N}=p.value;return!!(f&&b&&N)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await $o({repoRoot:e.repoRoot}),tn({type:"state",payload:await vt({repoRoot:e.repoRoot})})}finally{o=!1,s&&(s=!1,c())}}},u=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=ar();if(d(p))return oe.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as Gg}from"ws";var Ve=(e,t)=>{e.send(JSON.stringify(t))},br=async(e,t)=>Ve(e,{type:"state",payload:await vt({repoRoot:t})}),ht=async(e,t,n,r,o)=>{if(Ve(e,{type:r,payload:o}),d(o))return Ve(e,{type:"failed",payload:o.message});n(),br(e,t)},Sl=(e,t,{onStateChanged:n})=>{new Gg({server:e,path:"/ws"}).on("connection",o=>{sa(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return br(o,t);if(c==="sync"){let u=await $o({repoRoot:t});return Ve(o,{type:"sync:result",payload:u}),n(),br(o,t)}if(c==="issue:comment:add"){let u=await Ho({repoRoot:t,...i.payload});return ht(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await Wo({repoRoot:t,...i.payload});return Ve(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Ve(o,{type:"failed",payload:u.message}):(n(),br(o,t))}if(c==="issue:edit:description"){let u=await gl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await yl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await vl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await hl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await xl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await bl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Ve(o,{type:"issues",payload:await ll({repoRoot:t})});if(c==="issues:create"){let u=await ul({...i.payload,repoRoot:t});return Ve(o,{type:"issues:create:result",payload:u}),d(u)?tn({type:"failed",payload:u.message}):(tn({type:"issue:created",payload:u.value}),n(),br(o,t))}if(c==="issues:move"){if(!i.payload.position)return Ve(o,{type:"error",message:"Missing move position"});let u=await fl({...i.payload,repoRoot:t});return ht(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await ml({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await pl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:reopen:result",u)}return Ve(o,{type:"error",message:"Unknown message type"})}catch(i){return Ve(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Yg=yn.dirname(qg(import.meta.url)),Xg=process.env.IS_LOCAL==="true"?yn.resolve(process.cwd(),"dist/gui"):yn.join(Yg,"gui"),ye=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Al=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)}),Jg=2*1024*1024,Qg={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},Zg=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",Rl=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=yn.resolve(Xg),o=yn.resolve(r,n),s=yn.relative(r,o);if(s.startsWith("..")||yn.isAbsolute(s))return ye(t,403,{isError:!0,message:"Forbidden"});try{let i=await Tl(o);return t.writeHead(200,{"content-type":Zg(o)}),t.end(i)}catch{return ye(t,404,{isError:!0,message:`Not found: ${n}`})}},ey=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){r(new Error("Unable to resolve address"));return}n(u.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),wl=async e=>{let t=zg.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return ye(s,200,await vt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Al(o);if(!c.issueId||!c.body?.trim())return ye(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Ho({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(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 Al(o,Jg);if(!c.issueId||!c.dataBase64)return ye(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let u=await Il({repoRoot:e.repoRoot,issueId:c.issueId,name:c.name??"",dataBase64:c.dataBase64});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(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/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing attachment id"});let u=await El({repoRoot:e.repoRoot,attachmentId:c});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),u=await Cl({repoRoot:e.repoRoot,fileName:c});if(d(u))return ye(s,404,{isError:!0,message:u.message});try{let m=await Tl(u.value.filePath);return s.writeHead(200,{"content-type":Qg[u.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return ye(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/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing comment id"});let u=await Wo({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Rl("/",s):Rl(i.pathname,s)});try{await ey(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Nl({repoRoot:e.repoRoot});Sl(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")):l("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Ml=async e=>{let t=await wl({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${ty.cyan(n)}`),Li(n),l("Started GUI",{url:n})};import{Box as Jt}from"ink";import ae from"react";import{Box as yi,Text as Ir}from"ink";import ot,{useEffect as ny,useMemo as ry}from"react";import{ulid as oy}from"ulid";var Pl=({text:e,match:t,color:n,highlightColor:r=v.secondary,dimColor:o=!1})=>{if(!t)return ot.createElement(Ir,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?ot.createElement(Ir,{color:n,dimColor:o},e):ot.createElement(Ir,{color:n,dimColor:o},e.slice(0,c),ot.createElement(Ir,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Ll=oy(),sy=e=>`${e}`,iy=e=>{let{pendingNavTarget:t}=jt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ie(x.NONE,{breadCrumb:n,contextNode:r,readOnly:g().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==x.PALETTE).map(i=>{let c=ho(i),u=Do.find(m=>m.intent===c);return{command:i,description:u?.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))},ay=e=>Q.text({id:Ll,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),dy=(e,t,n)=>Q.text({id:sy(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),vi=[],cy=e=>{kl();let t=I.createNode(ay(g().rootNodeId));d(t)||!kt(t.value)||(vi=[t.value,...e.map((n,r)=>dy(n,r,Ll)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0}))},kl=()=>{let e=vi.map(t=>t.id);vi=[];for(let t of e)I.deleteNode(t)};function Dl({width:e,height:t}){let r=Gd().value.trim().toLowerCase(),o=ry(()=>iy(r),[r]);ny(()=>(cy(o),()=>{kl()}),[o]);let s=g().selectedIndex;return ot.createElement(yi,{flexDirection:"column",width:e,height:t-2},ot.createElement(et,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?v.accent:v.secondary2,p=i.isAvailable?"":"[unavailable] ";return ot.createElement(yi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:v.secondary,borderStyle:"single"},ot.createElement(Ir,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",ot.createElement(Pl,{text:ua(i.command),match:r,color:m,dimColor:!i.isAvailable})),ot.createElement(yi,{paddingLeft:2},ot.createElement(Pl,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?v.primary:v.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Ay}from"ink";import Ko from"react";import Cr from"chalk";import{Box as hi,Text as Fl}from"ink";import Er,{useEffect as ly,useMemo as uy,useState as my}from"react";var Bl=Cr.hex(v.secondary),py=Cr.inverse,fy=Cr.inverse.hex(v.secondary2),gy={hint:"",hints:[],overlap:0,remainder:""},Ol=({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}},yy=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=le(t);return{bg:r=>Cr.bgHex(n).black(r),bgCursor:r=>Cr.bgHex(n).inverse.black(r)}}return Rs(t)},vy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Ol({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}},Ul=()=>({value:Ae.value,cursorPosition:Ae.cursorPosition,commandIsPending:Ae.commandIsPending,autoCompletion:Ae.commandMeta.autoCompletion??gy,infoMessage:Ae.commandMeta.infoMessage,validationStatus:Ae.commandMeta.validity,command:Ae.commandMeta.command,inputString:Ae.commandMeta.inputString,modifier:Ae.commandMeta.modifier}),hy=(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,_l=({width:e,mode:t})=>{let[n,r]=my(Ul());ly(()=>{let S=()=>{let M=Ul();r(U=>hy(U,M)?U:M)},R=zs(S);return S(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p,validationStatus:f}=n,b=c&&f===pt.Invalid,N=uy(()=>{let S=Math.max(0,Math.min(s,o.length)),R=Ol({value:o,command:m}),M=vy({value:o,command:m,modifier:p}),U=m?Rs(m):null,j=yy({command:m,modifier:p}),D=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fg(ue):Hn&&j?j.bg(ue):ue},z=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fgCursor(ue):Hn&&j?j.bgCursor(ue):py(ue)},$=o.slice(0,S),P=o[S]??" ",O=S<o.length?o.slice(S+1):"",Ge=Array.from($).map((ue,ce)=>D(ue,ce)).join(""),Ne=z(P,S),ze=Array.from(O).map((ue,ce)=>D(ue,S+1+ce)).join("");if(u.hint){let ue=u.hint[u.overlap]??P;Ne=fy(ue),ze=Bl(u.remainder.slice(1)+O)}return Bl(t===y.PALETTE?"?":":")+Ge+Ne+ze},[o,s,u,m,p]);return Er.createElement(hi,{flexDirection:"column",justifyContent:"flex-start"},Er.createElement(hi,{flexDirection:"column",paddingX:1,borderColor:v.secondary,borderStyle:"round",width:e},Er.createElement(hi,null,Er.createElement(Fl,null,N),i&&Er.createElement(Fl,{wrap:"truncate",color:b?v.red:v.secondary2},` ${i} `))))};import{Box as xy,Text as by}from"ink";import $l from"react";var Iy=(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},Hl=({width:e,availableHints:t})=>{let n=Iy(t,e).join(" | ");return $l.createElement(xy,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1},$l.createElement(by,{color:v.secondary2},n.length?n:"\xA0"))};import{Box as Ey,Text as jo}from"ink";import Nr,{useEffect as Cy,useRef as Un,useState as Ny}from"react";var Sy=40,Vo=.3,xi="\u2500",Wl=1,jl=16,Vl=({width:e})=>{let{replay:t}=H(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*Wl,[c,u]=Ny(0),m=Un(r);m.current=r;let p=Un(0),f=Un(0),b=Un(0),N=Un(0),S=Un(0);if(Cy(()=>{if(!n){p.current=0,b.current=0,N.current=0,S.current=0,u(0);return}p.current=m.current,f.current=Date.now(),b.current=m.current;let D=setInterval(()=>{let z=Date.now(),$=m.current;if($!==b.current){let ze=$-b.current,ue=z-f.current;if(ze<0)N.current=0,S.current=0;else if(ze>0&&ue>0){let ce=ze/ue;N.current=N.current===0?ce:N.current*(1-Vo)+ce*Vo,S.current=S.current===0?ze:S.current*(1-Vo)+ze*Vo}p.current=$,f.current=z,b.current=$}let P=z-f.current,O=Math.min(S.current,N.current*P),Ge=Math.min(1,p.current+O),Ne=Math.round(Ge*i);u(ze=>ze===Ne?ze:Ne)},Sy);return()=>clearInterval(D)},[n,i]),!t)return null;let R=D=>{let z=s>1?D/(s-1):0,$=Math.round(z*(jl-1))/(jl-1);return Gr($)},M=Math.min(s,Math.floor(c/Wl)),U=[];for(let D=0;D<M;D++){let z=R(D),$=U[U.length-1];$&&$.color===z?$.text+=xi:U.push({text:xi,color:z})}let j=xi.repeat(Math.max(0,s-M));return Nr.createElement(Ey,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1,columnGap:1},Nr.createElement(jo,{color:v.secondary2},"\u25B6"),Nr.createElement(jo,null,U.map((D,z)=>Nr.createElement(jo,{key:z,color:D.color},D.text)),Nr.createElement(jo,{color:v.secondary,dimColor:!0},j)))};var Sr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=H(),o=t===y.COMMAND_LINE||t===y.PALETTE;return Ko.createElement(Ay,null,o?Ko.createElement(_l,{width:e,mode:t}):r==="replay"?Ko.createElement(Vl,{width:e}):Ko.createElement(Hl,{width:e,mode:t,availableHints:n}))};import{Box as zt,Text as On}from"ink";import De,{useEffect as Ry,useMemo as Ty}from"react";import{ulid as Kl}from"ulid";var zo=Kl(),wy=()=>[...new Set([...g().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})),My=e=>Q.text({id:zo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Py=(e,t,n)=>Q.text({id:Kl(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),Go=[],Gl=()=>{let e=Go.filter(n=>n.id!==zo).map(n=>n.id),t=Go.filter(n=>n.id===zo).map(n=>n.id);Go=[];for(let n of[...e,...t])I.deleteNode(n)},Ly=e=>{Gl();let t=I.createNode(My(g().rootNodeId));if(d(t)||!kt(t.value))return logger.error("Could not attach help nodes");Go=[t.value,...e.map((n,r)=>Py(n,r,zo)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0})},zl=({width:e,height:t})=>{let n=Ty(()=>wy(),[]);Ry(()=>(Ly(n),()=>{Gl()}),[n]);let r=g().selectedIndex;return De.createElement(zt,{flexDirection:"column",marginTop:3,borderColor:v.secondary,borderStyle:"round",width:e,height:t-2},De.createElement(zt,{paddingX:1,justifyContent:"center"},De.createElement(On,{color:v.accent},"Help"),De.createElement(On,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),De.createElement(zt,{paddingX:1,marginTop:1},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.secondary},"Key(s)")),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:v.secondary},"Action"))),De.createElement(et,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return De.createElement(zt,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.accent},o)),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:c?v.primary:v.secondary2},s)))})))};import ky from"chalk";import{Box as qo,Text as Mt}from"ink";import Ke from"react";var ql=({width:e,height:t})=>Ke.createElement(qo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ke.createElement(Mt,{color:v.accent,bold:!0},"Initialize project"),Ke.createElement(Mt,null,`This folder is not an ${ky.hex(v.accent)("epiq")} project yet.`),Ke.createElement(Mt,{color:v.primary},"To start tracking issues here, we need to initialize a new",Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json "),"file in this repository."),Ke.createElement(qo,{marginTop:1,flexDirection:"column"},Ke.createElement(qo,null,Ke.createElement(Mt,{color:v.accent}," "),Ke.createElement(Mt,{color:v.primary},"Type "),Ke.createElement(Mt,{backgroundColor:v.secondary}," :init "))),Ke.createElement(qo,{marginTop:1},Ke.createElement(Mt,{color:v.secondary2},"This will create, commit and push "),Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json ")));import{Box as Yo,Text as xt}from"ink";import Ce from"react";var Dy=({isDone:e,command:t,value:n})=>Ce.createElement(Yo,null,Ce.createElement(xt,{color:v.accent,dimColor:e},e?" \u2714 ":" "),Ce.createElement(xt,{dimColor:e},"Type "),Ce.createElement(xt,{backgroundColor:v.secondary,dimColor:e}," "+t+" "),n!==void 0&&Ce.createElement(Ce.Fragment,null,Ce.createElement(xt,{dimColor:e}," "),Ce.createElement(xt,{color:v.secondary,dimColor:e},"<"+n+">"))),Fy=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function bi({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Ot(),u=[{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=u.findIndex(f=>!f.done),p=m===-1?void 0:u[m];return Ce.createElement(Yo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ce.createElement(xt,{color:v.accent,bold:!0},"Welcome! \u{1F539}"),Ce.createElement(xt,null,"Let's get you started - it's a breeze."),Ce.createElement(xt,{color:v.secondary2},"Remember - you can always search available commands by typing:",Ce.createElement(xt,{color:v.accent}," ? ")),p&&Ce.createElement(xt,{color:v.secondary2},p.message),Ce.createElement(Yo,{flexDirection:"column"},u.map((f,b)=>m===-1||b<=m?Ce.createElement(Yo,{key:f.key,marginBottom:1},Ce.createElement(Dy,{isDone:f.done,command:f.command,value:f.done?Fy(f.value):void 0})):null)))}import es from"chalk";import{Box as Rr,Text as _n}from"ink";import ve from"react";import{Box as Xo,Text as Yl}from"ink";import qt from"react";import By from"chalk";var Uy=e=>(I.getTag(e)?.name??"").length+3,Oy=e=>(I.getContributor(e)?.name??"").length+3,Xl=({width:e})=>{let{viewMode:t}=K(),n=H(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=It(c?.id??o.id,"TICKET"),m=te(u)?u.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],b=m?.parentNodeId?!Ns(o.id,m.parentNodeId)&&t==="dense":!1,N=r.map(($,P)=>{let O=P===r.length-1,Ge=q($.id),Ne=O?Ge?.[s]?.title:void 0;return`${P?" / ":""}${$.title??""}${Ne?` \u25B8 ${Ne}`:""}`}).join(""),S=m?I.getCommentsByIssue(m.id):[],R=S.length?String(S.length).length+11:0,M=b?p.reduce(($,P)=>$+Uy(P),0)+f.reduce(($,P)=>$+Oy(P),0)+R:0,U=c?.id!=null&&!(t==="wide"&&A(c)),j=Math.max(0,e-M),D=N.substring(0,j)+(U?By.hex(v.secondary2).dim(` ${Ue(c.id)}`):""),z=b?[...p.map($=>qt.createElement(Xo,{key:`tag-${$}`,paddingLeft:1},qt.createElement(kn,{id:$}))),...f.map($=>qt.createElement(Xo,{key:`assignee-${$}`,paddingLeft:1},qt.createElement(Ht,{id:$}))),S.length?qt.createElement(Xo,{key:"comments",paddingLeft:1},qt.createElement(Yl,{color:v.accent},"[",S.length," comment",S.length===1?"":"s","]")):null]:[];return qt.createElement(Xo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},qt.createElement(Yl,{color:v.secondary2},D),z)};import{Box as _y,Text as Jl}from"ink";import Jo from"react";var $y=({filters:e})=>Jo.createElement(_y,{columnGap:1},Jo.createElement(Jl,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Jo.createElement(Jl,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Ql=Jo.memo($y);import{Box as Hy,Text as Qo}from"ink";import Ar from"react";function Zl(){let{eventLog:e,unappliedEvents:t}=H(),n=e.at(-1)?.id,r=Xr(n??""),o=te(r)?Yr(r.value):"INVALID DATE";return Ar.createElement(Hy,{paddingLeft:1},Ar.createElement(Qo,{backgroundColor:v.accent,color:v.secondary}," Readonly "),Ar.createElement(Qo,{color:v.accent}," "+t.length+" edits ago at "+o+"."),Ar.createElement(Qo,{color:v.accent}," Resume with "),Ar.createElement(Qo,{backgroundColor:v.accent,color:v.secondary}," ",":peek now"," "))}import{Box as Wy,Text as Ii}from"ink";import Zo from"react";function eu(){let{replay:e}=H();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return Zo.createElement(Wy,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},Zo.createElement(Ii,{backgroundColor:v.accent,color:v.secondary}," \u25B6 REPLAY "),Zo.createElement(Ii,{color:v.secondary2},Yr(new Date(r))),Zo.createElement(Ii,{color:v.accent},`${t}/${n} edits`))}import Ei from"chalk";import{Box as jy,Text as tu}from"ink";import Ci,{useEffect as Vy,useState as Ky}from"react";var Gy=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],zy=150,nu=12,qy=.36,ru=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)}},Yy=({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)}`},Xy=(e,t,n)=>{let r=ru(e),o=ru(t);return Yy({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Jy=(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 Xy(s,i,o)};function ou({syncStatus:e,autoSync:t}){let[n,r]=Ky(0);Vy(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*qy)+1)/2,p=Math.round(m*(nu-1));r(f=>f===p?f:p)},zy);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:v.secondary2,failed:v.yellow,pending:v.secondary2,syncing:Jy(Gy,n/(nu-1))??""}[e.status];return Ci.createElement(jy,null,Ci.createElement(tu,null,Ei.hex(v.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Ci.createElement(tu,null,Ei.hex(i)("\u25CF")+Ei.hex(v.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import cu from"chalk";import{Text as lu}from"ink";import uu,{useEffect as tv,useState as nv}from"react";var Yt="1.3.1";import Ni from"chalk";var Qy="https://registry.npmjs.org/epiq/latest",Si=null,su=0,Zy=1e3*60*60*24,iu=e=>e.replace(/^v/,""),ev=(e,t)=>{let n=iu(e).split(".").map(Number),r=iu(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},au=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Si&&Date.now()-su<Zy)return Si;try{let t=await fetch(Qy);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?ev(r,e)>0:!1};return Si=o,su=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},du=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Ni.hex(v.accent).dim(s):Ni.hex(v.secondary).dim(s)).join(Ni.hex(v.secondary2).dim("."))};function mu(){let[e,t]=nv({current:Yt,latest:null,updateAvailable:!1});return tv(()=>{let n=!0;return au(Yt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?uu.createElement(lu,{dimColor:!0,color:v.secondary2},Yt+" "):uu.createElement(lu,null,cu.hex(v.secondary2).dim(Yt),cu.hex(v.accent).dim(" \u2197 "),du(Yt,e.latest))}function Tr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=H(),{userName:i,preferredEditor:c,autoSync:u}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",b=s?nn(s.currentLabel,Math.max(0,p)):"";return ve.createElement(Rr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?ve.createElement(Rr,{paddingLeft:1},ve.createElement(_n,{color:v.secondary2},b)):f?ve.createElement(_n,null," "):o===y.PALETTE?ve.createElement(Rr,null,ve.createElement(_n,{color:v.accent},"Command Palette"),ve.createElement(_n,{dimColor:!0,color:v.secondary2}," ","- search, select and press enter")):ve.createElement(Rr,{paddingLeft:1},e.length>0?ve.createElement(Ql,{filters:e}):ve.createElement(Xl,{width:p})),n==="live"?ve.createElement(Rr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},ve.createElement(ou,{autoSync:!!u,syncStatus:r}),ve.createElement(_n,null,es.hex(v.secondary2).dim("Mode: ")+es.hex(v.secondary2).dim(o.padEnd(8," "))," "),ve.createElement(pu,{icon:"@",value:i}),ve.createElement(pu,{icon:"\u276F",value:c}),ve.createElement(mu,null)):"",n==="peek"?ve.createElement(Zl,null):"",n==="replay"?ve.createElement(eu,null):"")}function pu({icon:e,value:t}){return ve.createElement(_n,null,es.dim(e)+es.hex(v.accent)(` ${t??"-"} `))}import{Box as rv,Text as ov}from"ink";import wr from"react";import{Box as ts,Text as Ai}from"ink";import Xt from"react";function Ri(){let e=H(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?G(t?.id):[];return Xt.createElement(ts,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:v.secondary,width:s},Xt.createElement(ts,{padding:1,paddingTop:0,paddingBottom:0},Xt.createElement(Ai,null,"Select a board:")),Xt.createElement(ts,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,f=G(c.id).flatMap(({id:b})=>q(b)).length;return Xt.createElement(ts,{key:c.id??u},Xt.createElement(Ai,{color:m?v.accent:v.secondary2},Xt.createElement(Re,{isSelected:m})),Xt.createElement(Ai,{color:m?v.accent:v.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var sv=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=H(),u=n.find(({context:b})=>b==="BOARD"),f=s-1-3;return wr.createElement(rv,{flexDirection:"row"},e.context==="WORKSPACE"?wr.createElement(Ri,null):u?wr.createElement(So,{height:f,width:i,swimlanes:(c[u.id]??[]).filter(b=>b!==void 0&&Dt(b)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):wr.createElement(ov,null))},fu=wr.memo(sv);import{useEffect as iv}from"react";var av=e=>{iv(()=>{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:u}=g();u==="default"&&!c&&io(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},gu=({autoSync:e})=>(av(e),null);function Ti({width:e,height:t}){let n=H(),{autoSync:r,viewMode:o}=va(),s=n.filters;if(n.mode===y.HELP)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(zl,{width:e,height:t}));if(n.mode===y.PALETTE)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(Dl,{width:e,height:t-2}),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Ot(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(bi,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(ql,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Le(n.breadCrumb??[],"BOARD");if(te(m)){let p=m.value.id,f=G(p).length,b=3,N=Math.floor(e/b),S=Math.floor(e/Math.max(f,1));e=Math.min(S,N)*Math.max(f,b)}return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(gu,{autoSync:r}),ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(fu,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import dv from"readline";var ns,rs,bt,cv=new Set([h.MoveCursorLeft,h.EraseInputWord,h.MoveCursorLeftOfWord,h.MoveCursorRight,h.MoveCursorRightOfWord,h.NavToPreviousContainer,h.NavToNextContainer,h.NavPreviousItem,h.NavNextItem,h.SetViewDense,h.SetViewWide,h.Confirm,h.Exit,h.Yank,h.InitCommandLine,h.InitCommandPalette,h.ExitCommandLine,h.CaptureInput,h.EraseInput,h.EraseInputWord,h.HideHelp,h.ViewHelp,h.SetViewDense,h.SetViewWide,h.GetLastCommandFromHistory,h.GetNextCommandFromHistory,h.AutoCompleteCommand]),lv=new Set([h.NavPreviousItem,h.NavNextItem,h.NavToPreviousContainer,h.NavToNextContainer,h.Confirm,h.Exit,h.InitCommandPalette,h.InitMove,h.MoveNextItem,h.MovePreviousItem,h.MoveToNextContainer,h.MoveToPreviousContainer,h.Delete,h.AddItem,h.EditTitle,h.EditDescription,h.ConfirmMove,h.Edit,h.ViewHelp,h.Yank]),yu=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=g(),s=qd(e,n);if(!s||r&&!cv.has(s)||o==="replay"&&n===y.DEFAULT&&lv.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},uv=()=>async function(t,n){n.name!=="escape"&&(bt&&(clearTimeout(bt),bt=void 0),await yu(n))},mv=()=>async function(t){if(t.length===1&&t[0]===27){bt&&clearTimeout(bt),bt=setTimeout(()=>{yu({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),bt=void 0},25);return}bt&&(clearTimeout(bt),bt=void 0)};function vu(){ns&&process.stdin.removeListener("keypress",ns),rs&&process.stdin.removeListener("data",rs),ns=uv(),rs=mv(),dv.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",rs),process.stdin.on("keypress",ns)}async function hu(){try{let e=wn();te(e)&&Fe(e.value);let t=Ye(process.cwd()),n=[];if(te(t)){let s=Pe({repoRoot:t.value});if(d(s))return dn(3,s.message);let i=vn(),c=await en({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return dn(3,c.message);let u=await _({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=Et(s.value);if(d(m))return dn(3,m.message);n=m.value}let r=an(n);if(d(r))return dn(4,r.message);E({hasProjectDefinition:te(t),hasInitializingEvents:!!n.length});let o=wi();return d(o)?dn(6,o.message):(vu(),l("Booted Epiq",void 0))}catch(e){return dn(0,ro(e))}}vc();var yv=`${Qt.bold("Epiq CLI")}
59
59
 
60
60
  ${Qt.dim("Boot in directory:")}
61
61
  ${Qt.cyan("$ epiq")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "1.3.0",
3
+ "version": "1.3.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",
package/readme.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  _Distributed terminal-native issue tracker backed by Git._
4
4
 
5
- [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-Epiq-pink?logo=github)](https://github.com/sponsors/ljtn)
6
-
7
5
  **[See docs →](https://ljtn.github.io/epiq/docs.html)**
8
6
 
9
7
  Issue tracking is a core part of software development, but it often becomes a painful context-switching exercise with poor ergonomics. Epiq provides issue tracking as a portable, integrated part of the development environment, with access to all the powerful tooling developers are used to.
@@ -46,7 +44,7 @@ These design choices result in a system that is:
46
44
  - Issue tracking — track work in tickets with name, description, tags, assignees, history log, etc.
47
45
  - Ergonomics — fast keyboard-driven UX, command line with history, syntax highlighting etc.
48
46
  - Command palette — press `?` to open a scrollable overview of all available commands and descriptions
49
- - Time travel — inspect your app 1h, 1 week or 1 year ago
47
+ - Time travel — inspect your board 1h, 1 week or 1 year ago
50
48
  - Filtering — query issues by description, tags, assignees, etc.
51
49
  - Autocompletion — minimize typing, stay in flow, reuse previous commands
52
50
  - Multi-user — collaborative synchronization via Git
@@ -251,5 +249,6 @@ Epiq follows a **local-first** model:
251
249
  > Frequent synchronization reduces divergence and keeps the system predictable
252
250
 
253
251
  ---
252
+ [![GitHub Sponsors](https://img.shields.io/badge/Sponsor-Epiq-pink?logo=github)](https://github.com/sponsors/ljtn)
254
253
 
255
254
  🫡 Never leave your editor!