epiq 1.2.0 → 1.2.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 +14 -13
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/gui/main.js
CHANGED
|
@@ -24911,7 +24911,7 @@ var User = ({
|
|
|
24911
24911
|
);
|
|
24912
24912
|
|
|
24913
24913
|
// source/version.ts
|
|
24914
|
-
var EPIQ_VERSION = "1.2.
|
|
24914
|
+
var EPIQ_VERSION = "1.2.1";
|
|
24915
24915
|
|
|
24916
24916
|
// source/gui/client/components/Header.tsx
|
|
24917
24917
|
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
|
|
@@ -26226,19 +26226,20 @@ var getResultValue = (payload) => {
|
|
|
26226
26226
|
}
|
|
26227
26227
|
return payload;
|
|
26228
26228
|
};
|
|
26229
|
-
var
|
|
26230
|
-
|
|
26231
|
-
|
|
26232
|
-
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
);
|
|
26236
|
-
if (issue) return issue;
|
|
26237
|
-
}
|
|
26238
|
-
}
|
|
26239
|
-
return null;
|
|
26229
|
+
var findByRefOrId = (nodes, refOrId) => {
|
|
26230
|
+
const byId = nodes.find((node) => node.id === refOrId);
|
|
26231
|
+
if (byId) return byId;
|
|
26232
|
+
const ref = refOrId.replace(/-/g, "").toUpperCase();
|
|
26233
|
+
const byRef = nodes.filter((node) => node.ref === ref);
|
|
26234
|
+
return byRef.length === 1 ? byRef[0] ?? null : null;
|
|
26240
26235
|
};
|
|
26241
|
-
var
|
|
26236
|
+
var findIssue = (state, issueRefOrId) => findByRefOrId(
|
|
26237
|
+
state.boards.flatMap(
|
|
26238
|
+
(board) => board.swimlanes.flatMap((swimlane) => swimlane.issues)
|
|
26239
|
+
),
|
|
26240
|
+
issueRefOrId
|
|
26241
|
+
);
|
|
26242
|
+
var findBoard = (state, boardRefOrId) => findByRefOrId(state.boards, boardRefOrId);
|
|
26242
26243
|
var updateIssueInGuiState = (state, issueId, updateIssue) => ({
|
|
26243
26244
|
...state,
|
|
26244
26245
|
boards: state.boards.map((board) => ({
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ ${m}
|
|
|
54
54
|
|
|
55
55
|
${c}
|
|
56
56
|
`,$s.writeFileSync(t,n,"utf8"),re.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),l("Local epiq paths ignored",!0)};var mf=async e=>{let t=await U({cwd:e,args:["status","--porcelain"]});return d(t)?t:l("Checked git diff",t.value.stdout.trim().length>0)},Y=(e,t)=>a(`[${e}] ${t}`),Gd=async()=>{_("");let e=dn(),t=await Ye(process.cwd());if(d(t))return Y(1,t.message);let n=t.value,r=await yr(n);if(d(r))return Y(2,r.message);if(r.value)return Y(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await mf(n);if(d(o))return Y(2.5,o.message);if(o.value)return Y(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(Vo(n))return Y(4,"Epiq project already initialized");let s=wt();if(!s.isSetupDone||!s.userName)return Y(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=H(),c=i.userName,u=i.userId;if(!u||!c)return Y(5,"Missing Epiq user id");let m=e.stateBranch,p=await xr({repoRoot:n,branch:m});if(d(p))return Y(6,p.message);if(p.value)return Y(6,`State branch already exists: ${m}`);let v=await ns({repoRoot:n,stateBranchName:m});if(d(v))return Y(6,v.message);let I=Cr();if(d(I))return Y(7,I.message);let S=Vd.join(br(),e.projectId),N=await Gt({repoRoot:n,stateBranchRoot:S,stateBranchName:m});if(d(N))return Y(8,N.message);let T=Vd.join(S,".epiq");uf.mkdirSync(T,{recursive:!0});let k=wa({userId:u,userName:c});if(d(k))return Y(9,k.message);for(let Ho of k.value){let ui=Fr({event:Ho,rootDir:S});if(d(ui))return Y(9,ui.message)}let O=await Er({stateBranchRoot:S,eventFileName:Yt({userId:u,userName:c})});if(d(O))return Y(10,O.message);let V=await ln({cwd:S,message:"[epiq:init]"});if(d(V))return Y(10,V.message);let R=await jd(n);if(d(R))return Y(11,R.message);let A=vi({repoRoot:n,fileContents:e});if(d(A))return Y(12,A.message);let G=await oe.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d(G))return Y(13,G.message);let Re=await oe.commit({cwd:n,message:"[epiq:init-project]"});if(d(Re))return Y(13,Re.message);let Ae="Project initialized!",Ge=await U({cwd:n,args:["push","-u","origin","HEAD"]});d(Ge)&&(Ae+=` Warn: [init:14] ${Ge.message}`);let de=await Fn({repoRoot:n,stateBranchRoot:S});d(de)&&(Ae+=` Warn: [init:15] ${de.message}`);let lt=Tt(k.value).filter(d);if(lt.length>0)return Y(16,lt.map(Ho=>Ho.message).join(`
|
|
57
|
-
`));let ze=We();if(d(ze))return Y(16,ze.message);let{rootNodeId:Dl,nodes:Fl}=ze.value,li=Fl[Dl];return li?(M.navigate({contextNode:li,selectedIndex:0}),C({hasProjectDefinition:!0,mode:g.DEFAULT}),l(Ae,null)):Y(16,"Unable to resolve initialized root node")};import{ulid as ff}from"ulid";import{ulid as pf}from"ulid";var zd=null,Bt=()=>structuredClone(zd),Zn=e=>{zd=e},Kd=()=>{let{contextNode:e,selectedIndex:t}=f(),r=z(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},Ws=({id:e,parentId:t,position:n={at:"end"}})=>{let r=z(t).filter(o=>o.id!==e);return Br(r,n)},qd=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Z();if(d(r))return a("Unable to resolve user ID");let o=Ws({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:pf(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Yd=e=>{Zn(e);let t=At(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function Hs(e){let t=Kd();if(d(t))return t;let{contextNode:n,nodes:r}=f();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=z(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=qd({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Yd(u.value)}function js(e){let t=Kd();if(d(t))return t;let{contextNode:n,selectedIndex:r}=f(),s=z(n.id)[r+e];if(!s)return a("Missing sibling node");let i=qd({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Yd(i.value)}var Xd=()=>{let e=Bt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=f().nodes[n];if(!r)return a("Move parent not found");let o=z(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(M.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},lo=(e,t="Moved preview")=>{if(d(e))return e;let n=Xd();return d(n)?n:(C({mode:g.MOVE}),l(t,null))},Jd=async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=q().commandMeta,{contextNode:n,selectedIndex:r}=f(),o=z(n.id)[r];if(!o)return C({mode:g.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=z(o.parentNodeId),i=s.findIndex(({id:v})=>v===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=Ws({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(Zn({id:ff(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),C({mode:g.MOVE}),l("Move initialized",null))}if(t==="next")return lo(js(1));if(t==="previous")return lo(js(-1));if(t==="to-next")return lo(Hs(1));if(t==="to-previous")return lo(Hs(-1));if(t==="confirm"){let s=Bt();if(!s)return a("No pending move to confirm");let i=await qe();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=Xd();return d(u)?u:(Zn(null),C({mode:g.DEFAULT}),l("Moved item",null))}return t==="cancel"?(Zn(null),C({mode:g.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as mo}from"ulid";import{monotonicFactory as gf,ulid as vf}from"ulid";var yf=gf(),uo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=yf();return l("Created issue events",[{id:vf(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Qd=async(e,t)=>{let n=Z();if(d(n))return a("Unable to resolve user ID");let r=await qe();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}=f(),u=m=>{let p=B([m],o);if(d(p))return p;let v=b.getNode(p.value[0].result.id);if(!v)return a("Created node not found");if(!v.parentNodeId)return p;let I=b.getNode(v.parentNodeId);return I?(M.navigate({contextNode:I,selectedIndex:b.getSiblings(v.parentNodeId).findIndex(({id:S})=>S===v.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=f(),p=b.getNode(m);if(!p)return a("Workspace not found");let v=yn(p.id,n.value,o);return d(v)?v:u({id:mo(),action:"add.board",payload:{id:mo(),name:t.inputString,parent:p.id,rank:v.value},...n.value})}if(t.modifier==="swimlane"){let m=be(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=yn(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=W(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let V=be(s,"SWIMLANE");return d(V)?null:V.value})();if(!p)return a("Unable to add issue in this context");let v=yn(p.id,n.value,o);if(d(v))return v;let I=uo({name:t.inputString,parent:p.id,rank:v.value,user:n.value});if(d(I))return I;let S=I.value,N=B([...S],o);if(d(N))return N;if(!N.value[0])return a("Issue creation failed");let O=S.find(V=>V.action==="add.issue")?.payload.id;return O?(M.navigate({contextNode:p,selectedIndex:b.getSiblings(p.id).findIndex(({id:V})=>V===O)}),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=f(),s=ma(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=Ut();if(d(u))return u;let p=Tt(i).filter(d);if(p.length>0)return Ut(),C(o),a(p.map(I=>I.message).join(", "));let v=f().nodes[e];return v?(M.navigate({contextNode:v,selectedIndex:r}),l("",{unappliedEvents:c})):(Ut(),C(o),a("Board did not exist at that date"))};var hf=20,xf=16,If=150,fo=null,go=null;var on=()=>{fo!==null&&(clearInterval(fo),fo=null),go!==null&&(clearTimeout(go),go=null)},Zd=()=>{on(),C({mode:g.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},bf=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)},ec=({events:e,startTime:t,durationMs:n})=>{on();let r=e.length,o=e.map(v=>vn(v)??t),s=o[r-1]??Date.now(),i=bf(o),c=Math.max(1,Math.round(n*hf/1e3)),u=Math.max(Math.round(n/c),xf),m=0,p=0;C({mode:g.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),fo=setInterval(()=>{m++;let v=m/c,I=[],S;for(;p<r&&i[p]<=v;){let T=e[p],k=At(T);if(d(k)){Zd();return}I.push(...us(T)),S=T,p++}if(p>=r||m>=c){for(;p<r;p++){let k=At(e[p]);if(d(k))break}let T=f().replay;C({unappliedEvents:[],replay:T&&{...T,progress:1,appliedCount:r}}),on(),go=setTimeout(Zd,If);return}let N=f().replay;C({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,v),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:S?vn(S)??N?.currentTime??t:N?.currentTime??t,currentLabel:S?aa(S):N?.currentLabel??"",flashNodeIds:S?[...new Set(I)]:N?.flashNodeIds??[]}})},u)};var tc=async()=>{let e=be(f().breadCrumb,"BOARD");if(d(e))return e;let t=await Ye(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Te({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=q().commandMeta;if(on(),r==="now"){let c=ft(n.value);if(d(c))return a(c.message);let u=Ut();if(d(u))return u;let p=Tt(c.value).filter(d);return p.length>0?a(p.map(v=>v.message).join(", ")):(C({mode:g.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=f().eventLog.at(-1),u=vn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=f().unappliedEvents.at(0),u=vn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=Zt(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:(C({mode:g.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var nc=async()=>{let e=be(f().breadCrumb,"BOARD");if(d(e))return e;let t=await Ye(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Te({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=q().commandMeta,{dateInput:s,durationInput:i}=Gr(r,o);if(on(),f().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=Zt(s);if(!c)return a("Invalid replay date");let u=i?Vr(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=f(),v=po({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(v))return v;let{unappliedEvents:I}=v.value;return I.length===0?(Ut(),C(p),l("Nothing to replay from that point",!0)):(ec({events:I,startTime:m,durationMs:u}),l("Replaying board history",!0))};import Ef from"zod";var rc=()=>{let e=q().commandMeta.inputString,t=Ef.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=xt({autoSyncDebounceMs:t.data});return d(n)?n:(_e({autoSyncIntervalMs:t.data}),C({mode:g.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var oc=()=>{let e=q().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=Ba(e),n=xt({autoSync:t});return d(n)?n:(_e({autoSync:t}),C({mode:g.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var sc=()=>{let e=q().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=xt({logLevel:e});return d(n)?n:(_e({logLevel:e}),C({mode:g.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var ic=async()=>{_(""),C({mode:g.DEFAULT});let e=We();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");C({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await _r();return d(t)?(C({syncStatus:{msg:t.message,status:"failed"}}),t):(C({mode:g.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Sf=e=>e.action==="add.issue.comment",ac=e=>Object.values(f().tags).find(t=>t.name===e),dc=e=>Object.values(f().contributors).find(t=>t.name===e),It=async()=>{let e=await qe();return d(e)?e:l("Resolved persist root",e.value)},vo=[{systemOnly:!0,intent:L.Move,description:"Internal move-state command",mode:g.COMMAND_LINE,action:Jd},{intent:L.Delete,description:"Delete the currently selected node",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await It();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=w(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=f().nodes[i];if(!c||!w(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Sf).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:xe(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:xe(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:g.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=q().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>le(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 fe(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:g.DEFAULT})),l("Filter updated",null)}},{intent:L.ViewHelp,description:"Open the help screen",mode:g.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=f();return Ft({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),C({mode:g.HELP}),l("Viewing help",null)}},{intent:L.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!w(r))return a("Cannot close in this context");let o=f().nodes[ce];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await It();if(d(s))return s;let i=s.value,c=Xt(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:xe(),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:()=>C({mode:g.DEFAULT})},{intent:L.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):pt(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=f().nodes[ce];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!w(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=f().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await It();if(d(m))return m;let p=m.value,v=Xt(u.id,s.id,{at:"end"},e.value,p);if(d(v))return v;let I=B([{id:xe(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:v.value},...e.value}],p);return d(I)?I:l("Issue reopened",null)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Init,description:"Initialize Epiq in the current git repository",mode:g.COMMAND_LINE,action:Gd},{intent:L.NewItem,description:"Create a new board, swimlane, or issue",mode:g.COMMAND_LINE,action:Qd,onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Rename,description:"itle] Rename the currently selected node",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=cd();if(!o)return a("Provide a title");let s=await It();return d(s)?s:B([{id:xe(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.UntagTicket,description:"Remove a tag from the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=ac(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=f();if(!s)return a("Invalid untag target");let i=pt(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!w(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 It();return d(m)?m:B([{id:xe(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.TagTicket,description:"Add or create a tag on the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=f();if(!o)return a("Invalid tag target");let s=pt(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!w(i))return a("Target node is not issue");let c=await It();if(d(c))return c;let u=ac(r),m=u?.id??xe();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:xe(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:xe(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.AssignUserToTicket,description:"Assign a user to the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=f(),i=W(s.id)[o];if(!i)return a("Invalid assign target");let c=pt(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!w(u))return a("Target node is not issue");let m=await It();if(d(m))return m;let p=dc(r),v=p?.id??xe();return(u.props.assignees??[]).includes(v)?a("Assignee already assigned"):B([...p?[]:[{id:xe(),action:"create.contributor",payload:{id:v,name:r},...e.value}],{id:xe(),action:"add.issue.assignee",payload:{id:u.id,assignee:v},...e.value}],m.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=dc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=f();if(!s)return a("Invalid unassign target");let i=pt(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!w(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 It();return d(m)?m:B([{id:xe(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Comment,description:"Add a comment to the selected issue",mode:g.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>In)return a(`Cannot exceed ${In} characters`);let r=Z();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=f(),i=be([...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):pt(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!w(m))return a("Target node is not issue");let p=await It();return d(p)?p:B([{id:xe(),action:"add.issue.comment",payload:{id:xe(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Sync,description:"Pull, commit, and push Epiq state",mode:g.COMMAND_LINE,action:ic},{intent:L.Peek,description:"View board state at another point in time",mode:g.COMMAND_LINE,action:tc},{intent:L.Replay,description:"Replay board history forward from a point in time",mode:g.COMMAND_LINE,action:nc},{intent:L.Export,description:"Export the current board layout to markdown",mode:g.COMMAND_LINE,action:async()=>{let e=await Md();return d(e)?e:(C({mode:g.DEFAULT}),l("Export successful",!0))}},{intent:L.Exit,description:"Exit the application",mode:g.COMMAND_LINE,action:async()=>(M.exit(),l("Exit successful",!0))},{intent:L.Edit,description:"Edit title or description",mode:g.COMMAND_LINE,action:async(e,t)=>Hd(t),onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:g.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case ae.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=H(),i=n||s,c=r??xe();if(!i||!c)return a("Unable to resolve user name or id");let u=xt({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(_e({userName:i,userId:c}),C({mode:g.DEFAULT}),l(`Username set to "${i}"`,null))}case ae.EDITOR:{if(!n)return a("No editor provided");let r=xt({preferredEditor:n});return d(r)?r:(_e({preferredEditor:n}),C({mode:g.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case ae.VIEW:return n!=="wide"&&n!=="dense"?a("Invalid view mode"):(_e({viewMode:n}),l(`View set to "${n}"`,null));case ae.AUTOSYNC:return oc();case ae.LOG_LEVEL:return sc();case ae.SYNC_DEBOUNCE_MS:return rc();default:return a("Unknown config command")}}},{intent:L.Coffee,description:"Sponsor the development of Epiq!",mode:g.COMMAND_LINE,action:()=>{let e=q().commandMeta.modifier;return e==="custom"?Os("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Os(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),_(""),l("Thanks you!",null)}}];var Nf=new Set(["peek","replay","filter","view-help"]),st=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=q();if(!t)return a("No command to confirm");if(!e&&n===Mt.Invalid)return a("Invalid command");let s=Jr(t);od();let{readOnly:i}=f();if(i&&!Nf.has(s))return zn({status:Ct.Fail,message:"Command not available in readonly state",value:null});let c=vo.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return zn({status:Ct.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return zn({status:Ct.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?zn(u):(sd({addToHistory:!e}),c.onSuccess?.(),H().autoSync&&Wr(),u)};var yo=[{intent:h.Exit,mode:g.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(C({mode:g.COMMAND_LINE}),_("move cancel"),st({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:g.DEFAULT,description:"[m] move (init/confirm)",action:()=>(C({mode:g.COMMAND_LINE}),_("move start"),st({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:g.MOVE,action:()=>(C({mode:g.COMMAND_LINE}),_("move confirm"),st({isForceExecutedBySystem:!0}))}],ho=[{intent:h.MovePreviousItem,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move previous"),st({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move next"),st({isForceExecutedBySystem:!0})):a("No pending move")}],cc=[{intent:h.MoveToNextContainer,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move to-next"),st({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move to-previous"),st({isForceExecutedBySystem:!0})):a("No pending move")}];var lc={[P.WORKSPACE]:[...yo,...ho],[P.BOARD]:[...yo,...ho],[P.SWIMLANE]:[...yo,...ho,...cc],[P.TICKET]:[],[P.FIELD]:[],[P.FIELD_LIST]:[],[P.TEXT]:[],[P.COMMENT]:[]};var uc=()=>{_("");let{pendingNavTarget:e}=Dt();C({mode:g.DEFAULT}),e&&M.navigate(e),Ft({pendingNavTarget:void 0})},mc=[{intent:h.ExitCommandLine,mode:g.HELP,action:()=>(uc(),l("Exiting help",null))},{intent:h.Exit,mode:g.HELP,action:()=>(uc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:g.HELP,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:g.HELP,action:()=>(M.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:g.HELP,action:()=>(M.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:g.HELP,action:()=>(M.navigateToNextContainer(),l("Navigating to next help container",null))}];var Rf=e=>{C({mode:g.COMMAND_LINE});let{pendingNavTarget:t}=Dt();t&&M.navigate(t),Ft({pendingNavTarget:void 0}),_(`${e} `)},pc=()=>{_("");let{pendingNavTarget:e}=Dt();e&&M.navigate(e),Ft({pendingNavTarget:void 0}),C({mode:g.DEFAULT})},fc=[{intent:h.InitCommandPalette,mode:g.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{_("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=f();return Ft({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),C({mode:g.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:g.PALETTE,action:()=>{let{selectedNode:e}=f();if(!e||!St(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?(Rf(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:g.PALETTE,action:()=>(pc(),l("Exiting palette",null))},{intent:h.Exit,mode:g.PALETTE,action:()=>(pc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:g.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:g.PALETTE,action:()=>(M.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:g.PALETTE,action:()=>(M.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:g.PALETTE,action:()=>(M.navigateToNextContainer(),l("Navigating to next container",null))}];var gc=[...mc,...fc,{intent:h.AddItem,mode:g.DEFAULT,description:"[n] new...",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:g.DEFAULT,description:"[d] delete",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:g.DEFAULT,description:"[:] focus command line",action:()=>(C({mode:g.COMMAND_LINE}),_(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:g.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=f();if(!z(e?.id??"")?.length){if(e?.title===se.DESCRIPTION)return C({mode:g.COMMAND_LINE}),_(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===se.ASSIGNEES)return C({mode:g.COMMAND_LINE}),_(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===se.TAGS)return C({mode:g.COMMAND_LINE}),_(`${x.TAG} `),l("Propose command",!0);if(t.title===se.DESCRIPTION&&e?.context==="TEXT")return C({mode:g.COMMAND_LINE}),_(`${x.EDIT} description `),l("Propose command",!0)}return M.enterChildNode(),l("Entering context",null)}},{intent:h.EditTitle,mode:g.DEFAULT,description:"[r] rename title",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.EDIT} title ${f().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:g.DEFAULT,description:"[e] edit description",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:g.DEFAULT,description:"[q] exit context",action:()=>(M.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:g.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:g.DEFAULT,action:()=>(M.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:g.DEFAULT,action:()=>(M.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:g.DEFAULT,action:()=>(M.navigateToNextContainer(),l("Navigating to next container",null))}];var Af=500,Tf=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),vc=e=>{let t=Tf(e);t&&Xr(n=>(n+t).slice(0,Af))};var wf=[g.COMMAND_LINE,g.PALETTE],Mf=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(As(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(As(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Ts("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Ts("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(Xr((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=f().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(vc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>(nd(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(rd(),l("Erasing input word",null))}],yc=[{intent:h.Confirm,mode:g.COMMAND_LINE,action:()=>(st(),l("Executing command",null))},{intent:h.ViewHelp,mode:g.DEFAULT,action:()=>(C({mode:g.HELP}),l("Viewing help",null))},...wf.flatMap(Mf),{intent:h.ExitCommandLine,mode:g.COMMAND_LINE,action:()=>(C({mode:g.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:g.COMMAND_LINE,action:()=>(id(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:g.COMMAND_LINE,action:()=>(ad(),l("Getting next command from history",null))}];import Ic from"chalk";var xo=Ic.dim.hex(y.secondary2)(": for command line"),hc="q to exit",xc=`${Ic.hex(y.accent)("m")} to confirm`,Vs={[P.WORKSPACE]:[xo],[P.BOARD]:[xo],[P.BOARD+g.COMMAND_LINE]:[xo],[P.SWIMLANE]:[xo],[P.TICKET+g.HELP]:[hc],[P.SWIMLANE+g.HELP]:[hc],[P.TICKET]:[],[P.FIELD]:[],[P.SWIMLANE+g.MOVE]:[xc],[P.TICKET+g.MOVE]:[xc]};var er=e=>e.trim().toLocaleLowerCase(),Pf=e=>{let{tags:t}=f();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Lf=e=>{let{contributors:t}=f();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},bc=(e,t)=>{let n=er(t.value);if(!n)return!0;switch(t.target){case"title":return er(e.title??"").includes(n);case"description":return er(e.props.description??"").includes(n);case"tag":return Pf(e).map(er).some(o=>o.includes(n));case"assignee":return Lf(e).map(er).some(o=>o.includes(n));case"ref":return Qi(e.id,t.value);default:return!0}};function Cc(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 Ec=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 sn,Gs,zs=new Set,Sc=()=>{for(let e of zs)e()},Df=e=>(zs.add(e),()=>zs.delete(e));function Nc(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=Cc(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,v=Vs[p+n]??Vs[p]??[],I=[...gc,...lc[p]??[],...yc],S=Ec(I),N=Ff(o,s),T=N[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:v,availableActions:I,actionIndex:S,selectedNode:T,renderedChildrenIndex:N})}var f=()=>{if(!sn)throw new Error("State not initialized. Call initWorkspaceState() first.");return sn},We=()=>sn?l("Retrieved state",sn):a("State not initialized. Call initWorkspaceState() first.");function $n(e){Gs=e;let t=Ke(process.cwd()),n=!1;if(!d(t)){let s=Et(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:g.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:{}},o=Nc(r);return d(o)?o:(sn=o.value,Sc(),l("State initialized",null))}function fe(e){let t=f(),n=e(t),r=Nc(n);return d(r)?a(r.message??"Unable to update state"):(sn=r.value,Sc(),l("State updated",null))}var C=e=>fe(t=>({...t,...e}));var $=()=>kf(Df,f,f),Ff=(e,t)=>{let n={};for(let r of Object.values(e))w(r)&&t.length>0&&!t.every(o=>bc(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},W=e=>f()?.renderedChildrenIndex[e]??[],Ut=()=>Gs?$n(Gs):a("Cannot reset state: no initial workspace found"),xn=()=>sn!==void 0;var Ks=e=>{xn()&&(C({syncStatus:e}),zt({type:"sync-status",payload:e}))},Io=(e="Syncing...")=>{Ks({status:"syncing",msg:e})},bo=(e="Synced")=>{Ks({status:"synced",msg:e})},qs=e=>{Ks({status:"failed",msg:e})},He=e=>(qs(e),a(e));import{decodeTime as PM}from"ulid";var Bf=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=K("getRepoRootDir",await Ye(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=K("getStateBranchRoot",Te({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=K("ensureInitialCommit",await Di(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=K("bootstrapStateBranchStorage",await Bi({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=K("hasInProgressGitOperation(stateBranchRoot)",await yr(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=K("ensureStateBranchLayout",Pi(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}))},Uf=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=K("stageStateBranchOwnEventFile",await Er({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=K("hasStagedChanges(after stage)",await Ni(t));if(d(o))return a(o.message);if(logger.debug("[sync] state branch change check after stage result",{changed:o.value}),!o.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 s=K("createStateBranchSyncCommit",await Fi({repoRoot:e,stateBranchRoot:t}));return d(s)?a(s.message):(logger.debug("[sync] created sync commit",s.value),l("Committed own event file",{createdCommit:!0,commitSha:s.value}))},$r=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");Io();let n=K("ensureSyncReady",await Bf({cwd:e,ensureUpstream:!0}));if(d(n))return He(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=K("isDetachedHead(stateBranchRoot)",await Ri(o));if(d(i))return He(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return He("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,v=K("getStateBranch",cn(r));if(d(v))return He(v.message);let I=v.value;logger.debug("[sync] resolved state branch",{stateBranch:I,stateBranchRoot:o});let S=K("commitOwnEventFileToStateBranch",await Uf({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(S))return He(S.message);c=S.value.createdCommit,u=S.value.commitSha;let N=K("pullBranchRebaseIfPresent",await Qo({cwd:o,branch:I}));if(d(N))return He(N.message);if(m=N.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let T=K("pushStateBranch",await Fn({stateBranchRoot:o,repoRoot:r}));if(d(T)&&Si(T.message)){let k=K("pullBranchRebaseIfPresent(retry)",await Qo({cwd:o,branch:I}));if(d(k))return He(k.message);m=m||k.value,T=K("pushStateBranch(retry)",await Fn({stateBranchRoot:o,repoRoot:r}))}if(d(T))return He(T.message);p=T.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let T=K("git rev-parse HEAD",await U({args:["rev-parse","HEAD"],cwd:o}));if(d(T))return He(T.message);u=T.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return bo(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 Ys=e=>{let t=Ke(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},ke=async e=>{let t=Ys(e);if(d(t))return t;let n=Te({repoRoot:t.value});if(d(n))return a(n.message);let r=dn(),o=await Gt({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:r.stateBranch});if(d(o))return a(o.message);let s=await U({cwd:n.value,args:["pull","--ff-only"]});d(s)&&re.info(3,s.message);let i=ft(n.value);if(d(i))return a(i.message);let c=Jt(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},De=()=>{let e=Qn();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=We();return d(e)?a(e.message):e},Rc=e=>(e.props.tags??[]).map(t=>b.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ie(t.name)})),Ac=e=>(e.props.assignees??[]).map(t=>b.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ie(t.name)}));var Tc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes).filter(w).filter(o=>e.includeClosed||o.parentNodeId!==ce).map(o=>({id:o.id,ref:et(o.id),title:Rt(o.title),description:o.props.description??"",parentNodeId:o.parentNodeId,isClosed:o.parentNodeId===ce,readonly:!!o.readonly,tags:Rc(o),assignees:Ac(o)}));return l("Listed issues",r)},wc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();if(d(n))return n;let r=yn(e.parentId,n.value,t.value.stateBranchRoot);if(d(r))return r;let o=uo({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")},Mc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();if(d(n))return n;let r=Xt(ce,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:Ie(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ce,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},Pc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Target node is not issue");if(o.parentNodeId!==ce)return a("Issue is not closed");let s=ao(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ce)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=Xt(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:Ie(),...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})},Lc=async e=>{let t=Ys(e.repoRoot);if(d(t))return t;let n=De();if(d(n))return n;let r=Te({repoRoot:t.value});if(d(r))return r;let o=ft(r.value);if(d(o))return o;let s=Jt(o.value);if(d(s))return s;let i=Xt(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:Ie(),...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})},Co=async(e={})=>{Io();let t=Ys(e.repoRoot);if(d(t))return a("Sync failed");let n=De();if(d(n))return n;let r=await $r({cwd:t.value,ownEventFileName:Yt(n.value)});return d(r)?(qs(r.message),r):(bo(),l("Synced",r.value))};var Ot=async(e={})=>{let t=await ke(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(m=>Nr(m)&&!m.isDeleted),s=new Map,i=new Map;for(let m of r)if(!m.isDeleted){if(Nt(m)&&m.parentNodeId){let p=s.get(m.parentNodeId)??[];p.push(m),s.set(m.parentNodeId,p)}if(w(m)&&m.parentNodeId){let p=i.get(m.parentNodeId)??[];p.push(m),i.set(m.parentNodeId,p)}}let c=Qn();if(d(c))return c;let u={};for(let m of r.filter(w))m.isDeleted||(u[m.id]=b.getCommentsByIssue(m.id).map(p=>{let v=b.getContributor(p.authorId);return{id:p.id,issueId:p.issue,body:p.md,author:{id:p.authorId,name:v?.name??"Unknown",color:ie(v?.name??p.authorId)},createdAt:Of(p.id)}}));return l("Retrieved Epiq GUI state",{boards:o.sort((m,p)=>m.rank.localeCompare(p.rank)).map(m=>({id:m.id,ref:et(m.id),title:m.title,swimlanes:(s.get(m.id)??[]).sort((p,v)=>p.rank.localeCompare(v.rank)).map(p=>({id:p.id,title:p.title,readonly:!!p.readonly,issues:(i.get(p.id)??[]).sort((v,I)=>v.rank.localeCompare(I.rank)).map(v=>({id:v.id,ref:et(v.id),title:Rt(v.title),description:v.props.description??"",readonly:!!v.readonly,tags:Rc(v),assignees:Ac(v),parentNodeId:v.parentNodeId,isClosed:v.parentNodeId===ce})),parentNodeId:p.parentNodeId}))})),tags:Object.values(n.value.tags).map(m=>({...m,color:ie(m.name)})),contributors:Object.values(n.value.contributors).map(m=>({...m,color:ie(m.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:ie(c.value.userName??"")},commentsByIssueId:u})},kc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})},Dc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Rt(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:Ie(),...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})},Fc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Rt(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??Ie(),u=[...i?[]:[{id:Ie(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:Ie(),...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}})},Bc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})},Uc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=Rt(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??Ie(),u=[...i?[]:[{id:Ie(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:Ie(),...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}})},Oc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})},Eo=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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=Ie(),c={id:Ie(),...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})},So=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})};var _c=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=Jn();if(d(p))return re.error(p.message);let{autoSync:v,userName:I,preferredEditor:S}=p.value;return!!(v&&I&&S)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await Co({repoRoot:e.repoRoot}),zt({type:"state",payload:await Ot({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=Jn();if(d(p))return re.error(p.message);let{autoSyncDebounceMs:v}=p.value;i()&&(t=setTimeout(()=>{c(),m()},v??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as _f}from"ws";var Fe=(e,t)=>{e.send(JSON.stringify(t))},tr=async(e,t)=>Fe(e,{type:"state",payload:await Ot({repoRoot:t})}),it=async(e,t,n,r,o)=>{if(Fe(e,{type:r,payload:o}),d(o))return Fe(e,{type:"failed",payload:o.message});n(),tr(e,t)},$c=(e,t,{onStateChanged:n})=>{new _f({server:e,path:"/ws"}).on("connection",o=>{Ui(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return tr(o,t);if(c==="sync"){let u=await Co({repoRoot:t});return Fe(o,{type:"sync:result",payload:u}),n(),tr(o,t)}if(c==="issue:comment:add"){let u=await Eo({repoRoot:t,...i.payload});return it(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await So({repoRoot:t,...i.payload});return Fe(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Fe(o,{type:"failed",payload:u.message}):(n(),tr(o,t))}if(c==="issue:edit:description"){let u=await kc({repoRoot:t,...i.payload});return it(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await Dc({repoRoot:t,...i.payload});return it(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await Fc({repoRoot:t,...i.payload});return it(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await Bc({repoRoot:t,...i.payload});return it(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await Uc({repoRoot:t,...i.payload});return it(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await Oc({repoRoot:t,...i.payload});return it(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Fe(o,{type:"issues",payload:await Tc({repoRoot:t})});if(c==="issues:create"){let u=await wc({...i.payload,repoRoot:t});return Fe(o,{type:"issues:create:result",payload:u}),d(u)?zt({type:"failed",payload:u.message}):(zt({type:"issue:created",payload:u.value}),n(),tr(o,t))}if(c==="issues:move"){if(!i.payload.position)return Fe(o,{type:"error",message:"Missing move position"});let u=await Lc({...i.payload,repoRoot:t});return it(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Fe(o,{type:"error",message:"Missing issueId"});let u=await Mc({repoRoot:t,issueId:i.payload.issueId});return it(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Fe(o,{type:"error",message:"Missing issueId"});let u=await Pc({repoRoot:t,issueId:i.payload.issueId});return it(o,t,n,"issue:reopen:result",u)}return Fe(o,{type:"error",message:"Unknown message type"})}catch(i){return Fe(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var jf=an.dirname(Hf(import.meta.url)),Vf=process.env.IS_LOCAL==="true"?an.resolve(process.cwd(),"dist/gui"):an.join(jf,"gui"),at=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Gf=async e=>new Promise((t,n)=>{let r="";e.on("data",o=>{r+=o}),e.on("end",()=>{try{t(r?JSON.parse(r):{})}catch{n(new Error("Invalid JSON body"))}}),e.on("error",n)}),zf=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",Wc=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=an.resolve(Vf),o=an.resolve(r,n),s=an.relative(r,o);if(s.startsWith("..")||an.isAbsolute(s))return at(t,403,{isError:!0,message:"Forbidden"});try{let i=await $f(o);return t.writeHead(200,{"content-type":zf(o)}),t.end(i)}catch{return at(t,404,{isError:!0,message:`Not found: ${n}`})}},Kf=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)}),Hc=async e=>{let t=Wf.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return at(s,200,await Ot({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Gf(o);if(!c.issueId||!c.body?.trim())return at(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Eo({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?at(s,400,u):at(s,200,await Ot({repoRoot:e.repoRoot}))}catch(c){return at(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return at(s,400,{isError:!0,message:"Missing comment id"});let u=await So({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?at(s,400,u):at(s,200,await Ot({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Wc("/",s):Wc(i.pathname,s)});try{await Kf(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=_c({repoRoot:e.repoRoot});$c(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 jc=async e=>{let t=await Hc({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${qf.cyan(n)}`),mi(n),l("Started GUI",{url:n})};import{Box as jt}from"ink";import ee from"react";import{Box as Xs,Text as nr}from"ink";import Ve,{useEffect as Yf,useMemo as Xf}from"react";import{ulid as Jf}from"ulid";var Vc=({text:e,match:t,color:n,highlightColor:r=y.secondary,dimColor:o=!1})=>{if(!t)return Ve.createElement(nr,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?Ve.createElement(nr,{color:n,dimColor:o},e):Ve.createElement(nr,{color:n,dimColor:o},e.slice(0,c),Ve.createElement(nr,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Gc=Jf(),Qf=e=>`${e}`,Zf=e=>{let{pendingNavTarget:t}=Dt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(le(x.NONE,{breadCrumb:n,contextNode:r,readOnly:f().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=Jr(i),u=vo.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))},eg=e=>Q.text({id:Gc,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),tg=(e,t,n)=>Q.text({id:Qf(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Js=[],ng=e=>{zc();let t=b.createNode(eg(f().rootNodeId));d(t)||!St(t.value)||(Js=[t.value,...e.map((n,r)=>tg(n,r,Gc)).map(b.createNode).filter(te).map(({value:n})=>n).filter(St)],M.navigate({contextNode:t.value,selectedIndex:0}))},zc=()=>{let e=Js.map(t=>t.id);Js=[];for(let t of e)b.deleteNode(t)};function Kc({width:e,height:t}){let r=dd().value.trim().toLowerCase(),o=Xf(()=>Zf(r),[r]);Yf(()=>(ng(o),()=>{zc()}),[o]);let s=f().selectedIndex;return Ve.createElement(Xs,{flexDirection:"column",width:e,height:t-2},Ve.createElement(rt,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?y.accent:y.secondary2,p=i.isAvailable?"":"[unavailable] ";return Ve.createElement(Xs,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},Ve.createElement(nr,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",Ve.createElement(Vc,{text:ji(i.command),match:r,color:m,dimColor:!i.isAvailable})),Ve.createElement(Xs,{paddingLeft:2},Ve.createElement(Vc,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?y.primary:y.secondary2,dimColor:!i.isAvailable})))})))}import{Box as xg}from"ink";import Ao from"react";import or from"chalk";import{Box as Qs,Text as qc}from"ink";import rr,{useEffect as rg,useMemo as og,useState as sg}from"react";var Yc=or.hex(y.secondary),ig=or.inverse,ag=or.inverse.hex(y.secondary2),dg={hint:"",hints:[],overlap:0,remainder:""},Jc=({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}},cg=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=ie(t);return{bg:r=>or.bgHex(n).black(r),bgCursor:r=>or.bgHex(n).inverse.black(r)}}return cs(t)},lg=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Jc({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}},Xc=()=>({value:he.value,cursorPosition:he.cursorPosition,commandIsPending:he.commandIsPending,autoCompletion:he.commandMeta.autoCompletion??dg,infoMessage:he.commandMeta.infoMessage,validationStatus:he.commandMeta.validity,command:he.commandMeta.command,inputString:he.commandMeta.inputString,modifier:he.commandMeta.modifier}),ug=(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,Qc=({width:e,mode:t})=>{let[n,r]=sg(Xc());rg(()=>{let I=()=>{let N=Xc();r(T=>ug(T,N)?T:N)},S=Rs(I);return I(),()=>{S()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p}=n,v=og(()=>{let I=Math.max(0,Math.min(s,o.length)),S=Jc({value:o,command:m}),N=lg({value:o,command:m,modifier:p}),T=m?cs(m):null,k=cg({command:m,modifier:p}),O=(de,X)=>{let lt=S&&X>=S.start&&X<S.end,ze=N&&X>=N.start&&X<N.end;return lt&&T?T.fg(de):ze&&k?k.bg(de):de},V=(de,X)=>{let lt=S&&X>=S.start&&X<S.end,ze=N&&X>=N.start&&X<N.end;return lt&&T?T.fgCursor(de):ze&&k?k.bgCursor(de):ig(de)},R=o.slice(0,I),A=o[I]??" ",G=I<o.length?o.slice(I+1):"",Re=Array.from(R).map((de,X)=>O(de,X)).join(""),Ae=V(A,I),Ge=Array.from(G).map((de,X)=>O(de,I+1+X)).join("");if(u.hint){let de=u.hint[u.overlap]??A;Ae=ag(de),Ge=Yc(u.remainder.slice(1)+G)}return Yc(t===g.PALETTE?"?":":")+Re+Ae+Ge},[o,s,u,m,p]);return rr.createElement(Qs,{flexDirection:"column",justifyContent:"flex-start"},rr.createElement(Qs,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},rr.createElement(Qs,null,rr.createElement(qc,null,v),i&&rr.createElement(qc,{wrap:"truncate",color:c?y.red:y.secondary2},` ${i} `))))};import{Box as mg,Text as pg}from"ink";import Zc from"react";var fg=(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},el=({width:e,availableHints:t})=>{let n=fg(t,e).join(" | ");return Zc.createElement(mg,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},Zc.createElement(pg,{color:y.secondary2},n.length?n:"\xA0"))};import{Box as gg,Text as No}from"ink";import sr,{useEffect as vg,useRef as Nn,useState as yg}from"react";var hg=40,Ro=.3,Zs="\u2500",tl=1,nl=16,rl=({width:e})=>{let{replay:t}=$(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*tl,[c,u]=yg(0),m=Nn(r);m.current=r;let p=Nn(0),v=Nn(0),I=Nn(0),S=Nn(0),N=Nn(0);if(vg(()=>{if(!n){p.current=0,I.current=0,S.current=0,N.current=0,u(0);return}p.current=m.current,v.current=Date.now(),I.current=m.current;let R=setInterval(()=>{let A=Date.now(),G=m.current;if(G!==I.current){let X=G-I.current,lt=A-v.current;if(X<0)S.current=0,N.current=0;else if(X>0&<>0){let ze=X/lt;S.current=S.current===0?ze:S.current*(1-Ro)+ze*Ro,N.current=N.current===0?X:N.current*(1-Ro)+X*Ro}p.current=G,v.current=A,I.current=G}let Re=A-v.current,Ae=Math.min(N.current,S.current*Re),Ge=Math.min(1,p.current+Ae),de=Math.round(Ge*i);u(X=>X===de?X:de)},hg);return()=>clearInterval(R)},[n,i]),!t)return null;let T=R=>{let A=s>1?R/(s-1):0,G=Math.round(A*(nl-1))/(nl-1);return Ar(G)},k=Math.min(s,Math.floor(c/tl)),O=[];for(let R=0;R<k;R++){let A=T(R),G=O[O.length-1];G&&G.color===A?G.text+=Zs:O.push({text:Zs,color:A})}let V=Zs.repeat(Math.max(0,s-k));return sr.createElement(gg,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1,columnGap:1},sr.createElement(No,{color:y.secondary2},"\u25B6"),sr.createElement(No,null,O.map((R,A)=>sr.createElement(No,{key:A,color:R.color},R.text)),sr.createElement(No,{color:y.secondary,dimColor:!0},V)))};var ir=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=$(),o=t===g.COMMAND_LINE||t===g.PALETTE;return Ao.createElement(xg,null,o?Ao.createElement(Qc,{width:e,mode:t}):r==="replay"?Ao.createElement(rl,{width:e}):Ao.createElement(el,{width:e,mode:t,availableHints:n}))};import{Box as _t,Text as Rn}from"ink";import Ee,{useEffect as Ig,useMemo as bg}from"react";import{ulid as ol}from"ulid";var wo=ol(),Cg=()=>[...new Set([...f().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})),Eg=e=>Q.text({id:wo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Sg=(e,t,n)=>Q.text({id:ol(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),To=[],sl=()=>{let e=To.filter(n=>n.id!==wo).map(n=>n.id),t=To.filter(n=>n.id===wo).map(n=>n.id);To=[];for(let n of[...e,...t])b.deleteNode(n)},Ng=e=>{sl();let t=b.createNode(Eg(f().rootNodeId));if(d(t)||!St(t.value))return logger.error("Could not attach help nodes");To=[t.value,...e.map((n,r)=>Sg(n,r,wo)).map(b.createNode).filter(te).map(({value:n})=>n).filter(St)],M.navigate({contextNode:t.value,selectedIndex:0})},il=({width:e,height:t})=>{let n=bg(()=>Cg(),[]);Ig(()=>(Ng(n),()=>{sl()}),[n]);let r=f().selectedIndex;return Ee.createElement(_t,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},Ee.createElement(_t,{paddingX:1,justifyContent:"center"},Ee.createElement(Rn,{color:y.accent},"Help"),Ee.createElement(Rn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),Ee.createElement(_t,{paddingX:1,marginTop:1},Ee.createElement(_t,{width:20,justifyContent:"flex-end"},Ee.createElement(Rn,{color:y.secondary},"Key(s)")),Ee.createElement(_t,{flexGrow:1,width:40,paddingLeft:2},Ee.createElement(Rn,{color:y.secondary},"Action"))),Ee.createElement(rt,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return Ee.createElement(_t,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},Ee.createElement(_t,{width:20,justifyContent:"flex-end"},Ee.createElement(Rn,{color:y.accent},o)),Ee.createElement(_t,{flexGrow:1,width:40,paddingLeft:2},Ee.createElement(Rn,{color:c?y.primary:y.secondary2},s)))})))};import Rg from"chalk";import{Box as Mo,Text as bt}from"ink";import Be from"react";var al=({width:e,height:t})=>Be.createElement(Mo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Be.createElement(bt,{color:y.accent,bold:!0},"Initialize project"),Be.createElement(bt,null,`This folder is not an ${Rg.hex(y.accent)("epiq")} project yet.`),Be.createElement(bt,{color:y.primary},"To start tracking issues here, we need to initialize a new",Be.createElement(bt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),Be.createElement(Mo,{marginTop:1,flexDirection:"column"},Be.createElement(Mo,null,Be.createElement(bt,{color:y.accent}," "),Be.createElement(bt,{color:y.primary},"Type "),Be.createElement(bt,{backgroundColor:y.secondary}," :init "))),Be.createElement(Mo,{marginTop:1},Be.createElement(bt,{color:y.secondary2},"This will create, commit and push "),Be.createElement(bt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as Po,Text as dt}from"ink";import pe from"react";var Ag=({isDone:e,command:t,value:n})=>pe.createElement(Po,null,pe.createElement(dt,{color:y.accent,dimColor:e},e?" \u2714 ":" "),pe.createElement(dt,{dimColor:e},"Type "),pe.createElement(dt,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&pe.createElement(pe.Fragment,null,pe.createElement(dt,{dimColor:e}," "),pe.createElement(dt,{color:y.secondary,dimColor:e},"<"+n+">"))),Tg=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function ei({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=wt(),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(v=>!v.done),p=m===-1?void 0:u[m];return pe.createElement(Po,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},pe.createElement(dt,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),pe.createElement(dt,null,"Let's get you started - it's a breeze."),pe.createElement(dt,{color:y.secondary2},"Remember - you can always search available commands by typing:",pe.createElement(dt,{color:y.accent}," ? ")),p&&pe.createElement(dt,{color:y.secondary2},p.message),pe.createElement(Po,{flexDirection:"column"},u.map((v,I)=>m===-1||I<=m?pe.createElement(Po,{key:v.key,marginBottom:1},pe.createElement(Ag,{isDone:v.done,command:v.command,value:v.done?Tg(v.value):void 0})):null)))}import Bo from"chalk";import{Box as dr,Text as An}from"ink";import me from"react";import{Box as Lo,Text as dl}from"ink";import $t from"react";import wg from"chalk";var Mg=e=>(b.getTag(e)?.name??"").length+3,Pg=e=>(b.getContributor(e)?.name??"").length+3,cl=({width:e})=>{let{viewMode:t}=H(),n=$(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=pt(c?.id??o.id,"TICKET"),m=te(u)?u.value:void 0,p=m?.props.tags??[],v=m?.props.assignees??[],I=m?.parentNodeId?!is(o.id,m.parentNodeId)&&t==="dense":!1,S=r.map((A,G)=>{let Re=G===r.length-1,Ae=z(A.id),Ge=Re?Ae?.[s]?.title:void 0;return`${G?" / ":""}${A.title??""}${Ge?` \u25B8 ${Ge}`:""}`}).join(""),N=m?b.getCommentsByIssue(m.id):[],T=N.length?String(N.length).length+11:0,k=I?p.reduce((A,G)=>A+Mg(G),0)+v.reduce((A,G)=>A+Pg(G),0)+T:0,O=Math.max(0,e-k),V=S.substring(0,O)+(c?.id?wg.hex(y.secondary2).dim(` #${et(c.id)}`):""),R=I?[...p.map(A=>$t.createElement(Lo,{key:`tag-${A}`,paddingLeft:1},$t.createElement(Cn,{id:A}))),...v.map(A=>$t.createElement(Lo,{key:`assignee-${A}`,paddingLeft:1},$t.createElement(Pt,{id:A}))),N.length?$t.createElement(Lo,{key:"comments",paddingLeft:1},$t.createElement(dl,{color:y.accent},"[",N.length," comment",N.length===1?"":"s","]")):null]:[];return $t.createElement(Lo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},$t.createElement(dl,{color:y.secondary2},V),R)};import{Box as Lg,Text as ll}from"ink";import ko from"react";var kg=({filters:e})=>ko.createElement(Lg,{columnGap:1},ko.createElement(ll,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>ko.createElement(ll,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),ul=ko.memo(kg);import{Box as Dg,Text as Do}from"ink";import ar from"react";function ml(){let{eventLog:e,unappliedEvents:t}=$(),n=e.at(-1)?.id,r=Lr(n??""),o=te(r)?Pr(r.value):"INVALID DATE";return ar.createElement(Dg,{paddingLeft:1},ar.createElement(Do,{backgroundColor:y.accent,color:y.secondary}," Readonly "),ar.createElement(Do,{color:y.accent}," "+t.length+" edits ago at "+o+"."),ar.createElement(Do,{color:y.accent}," Resume with "),ar.createElement(Do,{backgroundColor:y.accent,color:y.secondary}," ",":peek now"," "))}import{Box as Fg,Text as ti}from"ink";import Fo from"react";function pl(){let{replay:e}=$();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return Fo.createElement(Fg,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},Fo.createElement(ti,{backgroundColor:y.accent,color:y.secondary}," \u25B6 REPLAY "),Fo.createElement(ti,{color:y.secondary2},Pr(new Date(r))),Fo.createElement(ti,{color:y.accent},`${t}/${n} edits`))}import ni from"chalk";import{Box as Bg,Text as fl}from"ink";import ri,{useEffect as Ug,useState as Og}from"react";var _g=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],$g=150,gl=12,Wg=.36,vl=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)}},Hg=({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)}`},jg=(e,t,n)=>{let r=vl(e),o=vl(t);return Hg({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Vg=(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 jg(s,i,o)};function yl({syncStatus:e,autoSync:t}){let[n,r]=Og(0);Ug(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*Wg)+1)/2,p=Math.round(m*(gl-1));r(v=>v===p?v:p)},$g);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:Vg(_g,n/(gl-1))??""}[e.status];return ri.createElement(Bg,null,ri.createElement(fl,null,ni.hex(y.secondary2).dim(t?"Sync (auto): ":"Sync: ")),ri.createElement(fl,null,ni.hex(i)("\u25CF")+ni.hex(y.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import Cl from"chalk";import{Text as El}from"ink";import Sl,{useEffect as qg,useState as Yg}from"react";var Wt="1.2.0";import oi from"chalk";var Gg="https://registry.npmjs.org/epiq/latest",si=null,hl=0,zg=1e3*60*60*24,xl=e=>e.replace(/^v/,""),Kg=(e,t)=>{let n=xl(e).split(".").map(Number),r=xl(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},Il=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(si&&Date.now()-hl<zg)return si;try{let t=await fetch(Gg);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?Kg(r,e)>0:!1};return si=o,hl=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},bl=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?oi.hex(y.accent).dim(s):oi.hex(y.secondary).dim(s)).join(oi.hex(y.secondary2).dim("."))};function Nl(){let[e,t]=Yg({current:Wt,latest:null,updateAvailable:!1});return qg(()=>{let n=!0;return Il(Wt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?Sl.createElement(El,{dimColor:!0,color:y.secondary2},Wt+" "):Sl.createElement(El,null,Cl.hex(y.secondary2).dim(Wt),Cl.hex(y.accent).dim(" \u2197 "),bl(Wt,e.latest))}function cr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=$(),{userName:i,preferredEditor:c,autoSync:u}=H(),m=64,p=process.stdout.columns-m-8,v=t||n==="replay",I=s?mn(s.currentLabel,Math.max(0,p)):"";return me.createElement(dr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?me.createElement(dr,{paddingLeft:1},me.createElement(An,{color:y.secondary2},I)):v?me.createElement(An,null," "):o===g.PALETTE?me.createElement(dr,null,me.createElement(An,{color:y.accent},"Command Palette"),me.createElement(An,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):me.createElement(dr,{paddingLeft:1},e.length>0?me.createElement(ul,{filters:e}):me.createElement(cl,{width:p})),n==="live"?me.createElement(dr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},me.createElement(yl,{autoSync:!!u,syncStatus:r}),me.createElement(An,null,Bo.hex(y.secondary2).dim("Mode: ")+Bo.hex(y.secondary2).dim(o.padEnd(8," "))," "),me.createElement(Rl,{icon:"@",value:i}),me.createElement(Rl,{icon:"\u276F",value:c}),me.createElement(Nl,null)):"",n==="peek"?me.createElement(ml,null):"",n==="replay"?me.createElement(pl,null):"")}function Rl({icon:e,value:t}){return me.createElement(An,null,Bo.dim(e)+Bo.hex(y.accent)(` ${t??"-"} `))}import{Box as Xg,Text as Jg}from"ink";import lr from"react";import{Box as Uo,Text as ii}from"ink";import Ht from"react";function ai(){let e=$(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?W(t?.id):[];return Ht.createElement(Uo,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:y.secondary,width:s},Ht.createElement(Uo,{padding:1,paddingTop:0,paddingBottom:0},Ht.createElement(ii,null,"Select a board:")),Ht.createElement(Uo,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,v=W(c.id).flatMap(({id:I})=>z(I)).length;return Ht.createElement(Uo,{key:c.id??u},Ht.createElement(ii,{color:m?y.accent:y.secondary2},Ht.createElement(Ce,{isSelected:m})),Ht.createElement(ii,{color:m?y.accent:y.secondary2},c.title," (",v," issues)",c.readonly?" \u{1F512}":""))})))}var Qg=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=$(),u=n.find(({context:I})=>I==="BOARD"),v=s-1-3;return lr.createElement(Xg,{flexDirection:"row"},e.context==="WORKSPACE"?lr.createElement(ai,null):u?lr.createElement(so,{height:v,width:i,swimlanes:(c[u.id]??[]).filter(I=>I!==void 0&&Nt(I)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):lr.createElement(Jg,null))},Al=lr.memo(Qg);import{useEffect as Zg}from"react";var ev=e=>{Zg(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=H();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=f();u==="default"&&!c&&Wr(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},Tl=({autoSync:e})=>(ev(e),null);function di({width:e,height:t}){let n=$(),{autoSync:r,viewMode:o}=Yi(),s=n.filters;if(n.mode===g.HELP)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(il,{width:e,height:t}));if(n.mode===g.PALETTE)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{filters:s}),ee.createElement(Kc,{width:e,height:t-2}),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=wt(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{hideBreadCrumb:!0,filters:s}),ee.createElement(ei,{height:t,width:e})),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{hideBreadCrumb:!0,filters:s}),ee.createElement(al,{height:t,width:e})),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=be(n.breadCrumb??[],"BOARD");if(te(m)){let p=m.value.id,v=W(p).length,I=3,S=Math.floor(e/I),N=Math.floor(e/Math.max(v,1));e=Math.min(N,S)*Math.max(v,I)}return ee.createElement(jt,{flexDirection:"column"},ee.createElement(Tl,{autoSync:r}),ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{filters:s}),ee.createElement(Al,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}))}import tv from"readline";var Oo,_o,ct,nv=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.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]),rv=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]),wl=async e=>{if(e.ctrl&&e.name==="c")return M.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=f(),s=ld(e,n);if(!s||r&&!nv.has(s)||o==="replay"&&n===g.DEFAULT&&rv.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},ov=()=>async function(t,n){n.name!=="escape"&&(ct&&(clearTimeout(ct),ct=void 0),await wl(n))},sv=()=>async function(t){if(t.length===1&&t[0]===27){ct&&clearTimeout(ct),ct=setTimeout(()=>{wl({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),ct=void 0},25);return}ct&&(clearTimeout(ct),ct=void 0)};function Ml(){Oo&&process.stdin.removeListener("keypress",Oo),_o&&process.stdin.removeListener("data",_o),Oo=ov(),_o=sv(),tv.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",_o),process.stdin.on("keypress",Oo)}async function Pl(){try{let e=Qn();te(e)&&_e(e.value);let t=Ke(process.cwd()),n=[];if(te(t)){let s=Te({repoRoot:t.value});if(d(s))return Qt(3,s.message);let i=dn(),c=await Gt({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return Qt(3,c.message);let u=await U({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=ft(s.value);if(d(m))return Qt(3,m.message);n=m.value}let r=Jt(n);if(d(r))return Qt(4,r.message);C({hasProjectDefinition:te(t),hasInitializingEvents:!!n.length});let o=ci();return d(o)?Qt(6,o.message):(Ml(),l("Booted Epiq",void 0))}catch(e){return Qt(0,Or(e))}}_d();var cv=`${Vt.bold("Epiq CLI")}
|
|
57
|
+
`));let ze=We();if(d(ze))return Y(16,ze.message);let{rootNodeId:Dl,nodes:Fl}=ze.value,li=Fl[Dl];return li?(M.navigate({contextNode:li,selectedIndex:0}),C({hasProjectDefinition:!0,mode:g.DEFAULT}),l(Ae,null)):Y(16,"Unable to resolve initialized root node")};import{ulid as ff}from"ulid";import{ulid as pf}from"ulid";var zd=null,Bt=()=>structuredClone(zd),Zn=e=>{zd=e},Kd=()=>{let{contextNode:e,selectedIndex:t}=f(),r=z(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},Ws=({id:e,parentId:t,position:n={at:"end"}})=>{let r=z(t).filter(o=>o.id!==e);return Br(r,n)},qd=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Z();if(d(r))return a("Unable to resolve user ID");let o=Ws({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:pf(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Yd=e=>{Zn(e);let t=At(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function Hs(e){let t=Kd();if(d(t))return t;let{contextNode:n,nodes:r}=f();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=z(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=qd({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Yd(u.value)}function js(e){let t=Kd();if(d(t))return t;let{contextNode:n,selectedIndex:r}=f(),s=z(n.id)[r+e];if(!s)return a("Missing sibling node");let i=qd({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Yd(i.value)}var Xd=()=>{let e=Bt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=f().nodes[n];if(!r)return a("Move parent not found");let o=z(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(M.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},lo=(e,t="Moved preview")=>{if(d(e))return e;let n=Xd();return d(n)?n:(C({mode:g.MOVE}),l(t,null))},Jd=async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=q().commandMeta,{contextNode:n,selectedIndex:r}=f(),o=z(n.id)[r];if(!o)return C({mode:g.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=z(o.parentNodeId),i=s.findIndex(({id:v})=>v===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=Ws({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(Zn({id:ff(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),C({mode:g.MOVE}),l("Move initialized",null))}if(t==="next")return lo(js(1));if(t==="previous")return lo(js(-1));if(t==="to-next")return lo(Hs(1));if(t==="to-previous")return lo(Hs(-1));if(t==="confirm"){let s=Bt();if(!s)return a("No pending move to confirm");let i=await qe();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=Xd();return d(u)?u:(Zn(null),C({mode:g.DEFAULT}),l("Moved item",null))}return t==="cancel"?(Zn(null),C({mode:g.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as mo}from"ulid";import{monotonicFactory as gf,ulid as vf}from"ulid";var yf=gf(),uo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=yf();return l("Created issue events",[{id:vf(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Qd=async(e,t)=>{let n=Z();if(d(n))return a("Unable to resolve user ID");let r=await qe();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}=f(),u=m=>{let p=B([m],o);if(d(p))return p;let v=b.getNode(p.value[0].result.id);if(!v)return a("Created node not found");if(!v.parentNodeId)return p;let I=b.getNode(v.parentNodeId);return I?(M.navigate({contextNode:I,selectedIndex:b.getSiblings(v.parentNodeId).findIndex(({id:S})=>S===v.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=f(),p=b.getNode(m);if(!p)return a("Workspace not found");let v=yn(p.id,n.value,o);return d(v)?v:u({id:mo(),action:"add.board",payload:{id:mo(),name:t.inputString,parent:p.id,rank:v.value},...n.value})}if(t.modifier==="swimlane"){let m=be(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=yn(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=W(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let V=be(s,"SWIMLANE");return d(V)?null:V.value})();if(!p)return a("Unable to add issue in this context");let v=yn(p.id,n.value,o);if(d(v))return v;let I=uo({name:t.inputString,parent:p.id,rank:v.value,user:n.value});if(d(I))return I;let S=I.value,N=B([...S],o);if(d(N))return N;if(!N.value[0])return a("Issue creation failed");let O=S.find(V=>V.action==="add.issue")?.payload.id;return O?(M.navigate({contextNode:p,selectedIndex:b.getSiblings(p.id).findIndex(({id:V})=>V===O)}),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=f(),s=ma(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=Ut();if(d(u))return u;let p=Tt(i).filter(d);if(p.length>0)return Ut(),C(o),a(p.map(I=>I.message).join(", "));let v=f().nodes[e];return v?(M.navigate({contextNode:v,selectedIndex:r}),l("",{unappliedEvents:c})):(Ut(),C(o),a("Board did not exist at that date"))};var hf=20,xf=16,If=150,fo=null,go=null;var on=()=>{fo!==null&&(clearInterval(fo),fo=null),go!==null&&(clearTimeout(go),go=null)},Zd=()=>{on(),C({mode:g.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},bf=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)},ec=({events:e,startTime:t,durationMs:n})=>{on();let r=e.length,o=e.map(v=>vn(v)??t),s=o[r-1]??Date.now(),i=bf(o),c=Math.max(1,Math.round(n*hf/1e3)),u=Math.max(Math.round(n/c),xf),m=0,p=0;C({mode:g.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),fo=setInterval(()=>{m++;let v=m/c,I=[],S;for(;p<r&&i[p]<=v;){let T=e[p],k=At(T);if(d(k)){Zd();return}I.push(...us(T)),S=T,p++}if(p>=r||m>=c){for(;p<r;p++){let k=At(e[p]);if(d(k))break}let T=f().replay;C({unappliedEvents:[],replay:T&&{...T,progress:1,appliedCount:r}}),on(),go=setTimeout(Zd,If);return}let N=f().replay;C({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,v),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:S?vn(S)??N?.currentTime??t:N?.currentTime??t,currentLabel:S?aa(S):N?.currentLabel??"",flashNodeIds:S?[...new Set(I)]:N?.flashNodeIds??[]}})},u)};var tc=async()=>{let e=be(f().breadCrumb,"BOARD");if(d(e))return e;let t=await Ye(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Te({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=q().commandMeta;if(on(),r==="now"){let c=ft(n.value);if(d(c))return a(c.message);let u=Ut();if(d(u))return u;let p=Tt(c.value).filter(d);return p.length>0?a(p.map(v=>v.message).join(", ")):(C({mode:g.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=f().eventLog.at(-1),u=vn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=f().unappliedEvents.at(0),u=vn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=Zt(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:(C({mode:g.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var nc=async()=>{let e=be(f().breadCrumb,"BOARD");if(d(e))return e;let t=await Ye(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Te({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=q().commandMeta,{dateInput:s,durationInput:i}=Gr(r,o);if(on(),f().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=Zt(s);if(!c)return a("Invalid replay date");let u=i?Vr(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=f(),v=po({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(v))return v;let{unappliedEvents:I}=v.value;return I.length===0?(Ut(),C(p),l("Nothing to replay from that point",!0)):(ec({events:I,startTime:m,durationMs:u}),l("Replaying board history",!0))};import Ef from"zod";var rc=()=>{let e=q().commandMeta.inputString,t=Ef.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=xt({autoSyncDebounceMs:t.data});return d(n)?n:(_e({autoSyncIntervalMs:t.data}),C({mode:g.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var oc=()=>{let e=q().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=Ba(e),n=xt({autoSync:t});return d(n)?n:(_e({autoSync:t}),C({mode:g.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var sc=()=>{let e=q().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=xt({logLevel:e});return d(n)?n:(_e({logLevel:e}),C({mode:g.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var ic=async()=>{_(""),C({mode:g.DEFAULT});let e=We();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");C({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await _r();return d(t)?(C({syncStatus:{msg:t.message,status:"failed"}}),t):(C({mode:g.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Sf=e=>e.action==="add.issue.comment",ac=e=>Object.values(f().tags).find(t=>t.name===e),dc=e=>Object.values(f().contributors).find(t=>t.name===e),It=async()=>{let e=await qe();return d(e)?e:l("Resolved persist root",e.value)},vo=[{systemOnly:!0,intent:L.Move,description:"Internal move-state command",mode:g.COMMAND_LINE,action:Jd},{intent:L.Delete,description:"Delete the currently selected node",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await It();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=w(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=f().nodes[i];if(!c||!w(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Sf).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:xe(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:xe(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:g.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=q().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>le(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 fe(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:g.DEFAULT})),l("Filter updated",null)}},{intent:L.ViewHelp,description:"Open the help screen",mode:g.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=f();return Ft({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),C({mode:g.HELP}),l("Viewing help",null)}},{intent:L.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!w(r))return a("Cannot close in this context");let o=f().nodes[ce];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await It();if(d(s))return s;let i=s.value,c=Xt(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:xe(),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:()=>C({mode:g.DEFAULT})},{intent:L.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):pt(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=f().nodes[ce];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!w(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=f().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await It();if(d(m))return m;let p=m.value,v=Xt(u.id,s.id,{at:"end"},e.value,p);if(d(v))return v;let I=B([{id:xe(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:v.value},...e.value}],p);return d(I)?I:l("Issue reopened",null)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Init,description:"Initialize Epiq in the current git repository",mode:g.COMMAND_LINE,action:Gd},{intent:L.NewItem,description:"Create a new board, swimlane, or issue",mode:g.COMMAND_LINE,action:Qd,onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Rename,description:"itle] Rename the currently selected node",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=f(),r=W(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=cd();if(!o)return a("Provide a title");let s=await It();return d(s)?s:B([{id:xe(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.UntagTicket,description:"Remove a tag from the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=ac(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=f();if(!s)return a("Invalid untag target");let i=pt(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!w(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 It();return d(m)?m:B([{id:xe(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.TagTicket,description:"Add or create a tag on the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=f();if(!o)return a("Invalid tag target");let s=pt(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!w(i))return a("Target node is not issue");let c=await It();if(d(c))return c;let u=ac(r),m=u?.id??xe();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:xe(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:xe(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.AssignUserToTicket,description:"Assign a user to the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=f(),i=W(s.id)[o];if(!i)return a("Invalid assign target");let c=pt(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!w(u))return a("Target node is not issue");let m=await It();if(d(m))return m;let p=dc(r),v=p?.id??xe();return(u.props.assignees??[]).includes(v)?a("Assignee already assigned"):B([...p?[]:[{id:xe(),action:"create.contributor",payload:{id:v,name:r},...e.value}],{id:xe(),action:"add.issue.assignee",payload:{id:u.id,assignee:v},...e.value}],m.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:g.COMMAND_LINE,action:async()=>{let e=Z();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=dc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=f();if(!s)return a("Invalid unassign target");let i=pt(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!w(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 It();return d(m)?m:B([{id:xe(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Comment,description:"Add a comment to the selected issue",mode:g.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>In)return a(`Cannot exceed ${In} characters`);let r=Z();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=f(),i=be([...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):pt(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!w(m))return a("Target node is not issue");let p=await It();return d(p)?p:B([{id:xe(),action:"add.issue.comment",payload:{id:xe(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Sync,description:"Pull, commit, and push Epiq state",mode:g.COMMAND_LINE,action:ic},{intent:L.Peek,description:"View board state at another point in time",mode:g.COMMAND_LINE,action:tc},{intent:L.Replay,description:"Replay board history forward from a point in time",mode:g.COMMAND_LINE,action:nc},{intent:L.Export,description:"Export the current board layout to markdown",mode:g.COMMAND_LINE,action:async()=>{let e=await Md();return d(e)?e:(C({mode:g.DEFAULT}),l("Export successful",!0))}},{intent:L.Exit,description:"Exit the application",mode:g.COMMAND_LINE,action:async()=>(M.exit(),l("Exit successful",!0))},{intent:L.Edit,description:"Edit title or description",mode:g.COMMAND_LINE,action:async(e,t)=>Hd(t),onSuccess:()=>C({mode:g.DEFAULT})},{intent:L.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:g.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case ae.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=H(),i=n||s,c=r??xe();if(!i||!c)return a("Unable to resolve user name or id");let u=xt({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(_e({userName:i,userId:c}),C({mode:g.DEFAULT}),l(`Username set to "${i}"`,null))}case ae.EDITOR:{if(!n)return a("No editor provided");let r=xt({preferredEditor:n});return d(r)?r:(_e({preferredEditor:n}),C({mode:g.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case ae.VIEW:return n!=="wide"&&n!=="dense"?a("Invalid view mode"):(_e({viewMode:n}),l(`View set to "${n}"`,null));case ae.AUTOSYNC:return oc();case ae.LOG_LEVEL:return sc();case ae.SYNC_DEBOUNCE_MS:return rc();default:return a("Unknown config command")}}},{intent:L.Coffee,description:"Sponsor the development of Epiq!",mode:g.COMMAND_LINE,action:()=>{let e=q().commandMeta.modifier;return e==="custom"?Os("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Os(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),_(""),l("Thanks you!",null)}}];var Nf=new Set(["peek","replay","filter","view-help"]),st=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=q();if(!t)return a("No command to confirm");if(!e&&n===Mt.Invalid)return a("Invalid command");let s=Jr(t);od();let{readOnly:i}=f();if(i&&!Nf.has(s))return zn({status:Ct.Fail,message:"Command not available in readonly state",value:null});let c=vo.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return zn({status:Ct.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return zn({status:Ct.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?zn(u):(sd({addToHistory:!e}),c.onSuccess?.(),H().autoSync&&Wr(),u)};var yo=[{intent:h.Exit,mode:g.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(C({mode:g.COMMAND_LINE}),_("move cancel"),st({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:g.DEFAULT,description:"[m] move (init/confirm)",action:()=>(C({mode:g.COMMAND_LINE}),_("move start"),st({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:g.MOVE,action:()=>(C({mode:g.COMMAND_LINE}),_("move confirm"),st({isForceExecutedBySystem:!0}))}],ho=[{intent:h.MovePreviousItem,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move previous"),st({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move next"),st({isForceExecutedBySystem:!0})):a("No pending move")}],cc=[{intent:h.MoveToNextContainer,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move to-next"),st({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:g.MOVE,action:()=>Bt()?(C({mode:g.COMMAND_LINE}),_("move to-previous"),st({isForceExecutedBySystem:!0})):a("No pending move")}];var lc={[P.WORKSPACE]:[...yo,...ho],[P.BOARD]:[...yo,...ho],[P.SWIMLANE]:[...yo,...ho,...cc],[P.TICKET]:[],[P.FIELD]:[],[P.FIELD_LIST]:[],[P.TEXT]:[],[P.COMMENT]:[]};var uc=()=>{_("");let{pendingNavTarget:e}=Dt();C({mode:g.DEFAULT}),e&&M.navigate(e),Ft({pendingNavTarget:void 0})},mc=[{intent:h.ExitCommandLine,mode:g.HELP,action:()=>(uc(),l("Exiting help",null))},{intent:h.Exit,mode:g.HELP,action:()=>(uc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:g.HELP,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:g.HELP,action:()=>(M.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:g.HELP,action:()=>(M.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:g.HELP,action:()=>(M.navigateToNextContainer(),l("Navigating to next help container",null))}];var Rf=e=>{C({mode:g.COMMAND_LINE});let{pendingNavTarget:t}=Dt();t&&M.navigate(t),Ft({pendingNavTarget:void 0}),_(`${e} `)},pc=()=>{_("");let{pendingNavTarget:e}=Dt();e&&M.navigate(e),Ft({pendingNavTarget:void 0}),C({mode:g.DEFAULT})},fc=[{intent:h.InitCommandPalette,mode:g.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{_("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=f();return Ft({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),C({mode:g.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:g.PALETTE,action:()=>{let{selectedNode:e}=f();if(!e||!St(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?(Rf(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:g.PALETTE,action:()=>(pc(),l("Exiting palette",null))},{intent:h.Exit,mode:g.PALETTE,action:()=>(pc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:g.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:g.PALETTE,action:()=>(M.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:g.PALETTE,action:()=>(M.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:g.PALETTE,action:()=>(M.navigateToNextContainer(),l("Navigating to next container",null))}];var gc=[...mc,...fc,{intent:h.AddItem,mode:g.DEFAULT,description:"[n] new...",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:g.DEFAULT,description:"[d] delete",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:g.DEFAULT,description:"[:] focus command line",action:()=>(C({mode:g.COMMAND_LINE}),_(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:g.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=f();if(!z(e?.id??"")?.length){if(e?.title===se.DESCRIPTION)return C({mode:g.COMMAND_LINE}),_(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===se.ASSIGNEES)return C({mode:g.COMMAND_LINE}),_(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===se.TAGS)return C({mode:g.COMMAND_LINE}),_(`${x.TAG} `),l("Propose command",!0);if(t.title===se.DESCRIPTION&&e?.context==="TEXT")return C({mode:g.COMMAND_LINE}),_(`${x.EDIT} description `),l("Propose command",!0)}return M.enterChildNode(),l("Entering context",null)}},{intent:h.EditTitle,mode:g.DEFAULT,description:"[r] rename title",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.EDIT} title ${f().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:g.DEFAULT,description:"[e] edit description",action:()=>(C({mode:g.COMMAND_LINE}),_(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:g.DEFAULT,description:"[q] exit context",action:()=>(M.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:g.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(M.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:g.DEFAULT,action:()=>(M.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:g.DEFAULT,action:()=>(M.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:g.DEFAULT,action:()=>(M.navigateToNextContainer(),l("Navigating to next container",null))}];var Af=500,Tf=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),vc=e=>{let t=Tf(e);t&&Xr(n=>(n+t).slice(0,Af))};var wf=[g.COMMAND_LINE,g.PALETTE],Mf=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(As(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(As(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Ts("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Ts("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(Xr((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=f().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(vc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>(nd(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(rd(),l("Erasing input word",null))}],yc=[{intent:h.Confirm,mode:g.COMMAND_LINE,action:()=>(st(),l("Executing command",null))},{intent:h.ViewHelp,mode:g.DEFAULT,action:()=>(C({mode:g.HELP}),l("Viewing help",null))},...wf.flatMap(Mf),{intent:h.ExitCommandLine,mode:g.COMMAND_LINE,action:()=>(C({mode:g.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:g.COMMAND_LINE,action:()=>(id(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:g.COMMAND_LINE,action:()=>(ad(),l("Getting next command from history",null))}];import Ic from"chalk";var xo=Ic.dim.hex(y.secondary2)(": for command line"),hc="q to exit",xc=`${Ic.hex(y.accent)("m")} to confirm`,Vs={[P.WORKSPACE]:[xo],[P.BOARD]:[xo],[P.BOARD+g.COMMAND_LINE]:[xo],[P.SWIMLANE]:[xo],[P.TICKET+g.HELP]:[hc],[P.SWIMLANE+g.HELP]:[hc],[P.TICKET]:[],[P.FIELD]:[],[P.SWIMLANE+g.MOVE]:[xc],[P.TICKET+g.MOVE]:[xc]};var er=e=>e.trim().toLocaleLowerCase(),Pf=e=>{let{tags:t}=f();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Lf=e=>{let{contributors:t}=f();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},bc=(e,t)=>{let n=er(t.value);if(!n)return!0;switch(t.target){case"title":return er(e.title??"").includes(n);case"description":return er(e.props.description??"").includes(n);case"tag":return Pf(e).map(er).some(o=>o.includes(n));case"assignee":return Lf(e).map(er).some(o=>o.includes(n));case"ref":return Qi(e.id,t.value);default:return!0}};function Cc(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 Ec=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 sn,Gs,zs=new Set,Sc=()=>{for(let e of zs)e()},Df=e=>(zs.add(e),()=>zs.delete(e));function Nc(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=Cc(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,v=Vs[p+n]??Vs[p]??[],I=[...gc,...lc[p]??[],...yc],S=Ec(I),N=Ff(o,s),T=N[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:v,availableActions:I,actionIndex:S,selectedNode:T,renderedChildrenIndex:N})}var f=()=>{if(!sn)throw new Error("State not initialized. Call initWorkspaceState() first.");return sn},We=()=>sn?l("Retrieved state",sn):a("State not initialized. Call initWorkspaceState() first.");function $n(e){Gs=e;let t=Ke(process.cwd()),n=!1;if(!d(t)){let s=Et(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:g.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:{}},o=Nc(r);return d(o)?o:(sn=o.value,Sc(),l("State initialized",null))}function fe(e){let t=f(),n=e(t),r=Nc(n);return d(r)?a(r.message??"Unable to update state"):(sn=r.value,Sc(),l("State updated",null))}var C=e=>fe(t=>({...t,...e}));var $=()=>kf(Df,f,f),Ff=(e,t)=>{let n={};for(let r of Object.values(e))w(r)&&t.length>0&&!t.every(o=>bc(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},W=e=>f()?.renderedChildrenIndex[e]??[],Ut=()=>Gs?$n(Gs):a("Cannot reset state: no initial workspace found"),xn=()=>sn!==void 0;var Ks=e=>{xn()&&(C({syncStatus:e}),zt({type:"sync-status",payload:e}))},Io=(e="Syncing...")=>{Ks({status:"syncing",msg:e})},bo=(e="Synced")=>{Ks({status:"synced",msg:e})},qs=e=>{Ks({status:"failed",msg:e})},He=e=>(qs(e),a(e));import{decodeTime as PM}from"ulid";var Bf=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=K("getRepoRootDir",await Ye(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=K("getStateBranchRoot",Te({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=K("ensureInitialCommit",await Di(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=K("bootstrapStateBranchStorage",await Bi({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=K("hasInProgressGitOperation(stateBranchRoot)",await yr(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=K("ensureStateBranchLayout",Pi(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}))},Uf=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=K("stageStateBranchOwnEventFile",await Er({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=K("hasStagedChanges(after stage)",await Ni(t));if(d(o))return a(o.message);if(logger.debug("[sync] state branch change check after stage result",{changed:o.value}),!o.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 s=K("createStateBranchSyncCommit",await Fi({repoRoot:e,stateBranchRoot:t}));return d(s)?a(s.message):(logger.debug("[sync] created sync commit",s.value),l("Committed own event file",{createdCommit:!0,commitSha:s.value}))},$r=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");Io();let n=K("ensureSyncReady",await Bf({cwd:e,ensureUpstream:!0}));if(d(n))return He(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=K("isDetachedHead(stateBranchRoot)",await Ri(o));if(d(i))return He(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return He("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,v=K("getStateBranch",cn(r));if(d(v))return He(v.message);let I=v.value;logger.debug("[sync] resolved state branch",{stateBranch:I,stateBranchRoot:o});let S=K("commitOwnEventFileToStateBranch",await Uf({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(S))return He(S.message);c=S.value.createdCommit,u=S.value.commitSha;let N=K("pullBranchRebaseIfPresent",await Qo({cwd:o,branch:I}));if(d(N))return He(N.message);if(m=N.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let T=K("pushStateBranch",await Fn({stateBranchRoot:o,repoRoot:r}));if(d(T)&&Si(T.message)){let k=K("pullBranchRebaseIfPresent(retry)",await Qo({cwd:o,branch:I}));if(d(k))return He(k.message);m=m||k.value,T=K("pushStateBranch(retry)",await Fn({stateBranchRoot:o,repoRoot:r}))}if(d(T))return He(T.message);p=T.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let T=K("git rev-parse HEAD",await U({args:["rev-parse","HEAD"],cwd:o}));if(d(T))return He(T.message);u=T.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return bo(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 Ys=e=>{let t=Ke(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},ke=async e=>{let t=Ys(e);if(d(t))return t;let n=Te({repoRoot:t.value});if(d(n))return a(n.message);let r=dn(),o=await Gt({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:r.stateBranch});if(d(o))return a(o.message);let s=await U({cwd:n.value,args:["pull","--ff-only"]});d(s)&&re.info(3,s.message);let i=ft(n.value);if(d(i))return a(i.message);let c=Jt(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},De=()=>{let e=Qn();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=We();return d(e)?a(e.message):e},Rc=e=>(e.props.tags??[]).map(t=>b.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ie(t.name)})),Ac=e=>(e.props.assignees??[]).map(t=>b.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:ie(t.name)}));var Tc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes).filter(w).filter(o=>e.includeClosed||o.parentNodeId!==ce).map(o=>({id:o.id,ref:et(o.id),title:Rt(o.title),description:o.props.description??"",parentNodeId:o.parentNodeId,isClosed:o.parentNodeId===ce,readonly:!!o.readonly,tags:Rc(o),assignees:Ac(o)}));return l("Listed issues",r)},wc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();if(d(n))return n;let r=yn(e.parentId,n.value,t.value.stateBranchRoot);if(d(r))return r;let o=uo({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")},Mc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();if(d(n))return n;let r=Xt(ce,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:Ie(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ce,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},Pc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Target node is not issue");if(o.parentNodeId!==ce)return a("Issue is not closed");let s=ao(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ce)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=Xt(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:Ie(),...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})},Lc=async e=>{let t=Ys(e.repoRoot);if(d(t))return t;let n=De();if(d(n))return n;let r=Te({repoRoot:t.value});if(d(r))return r;let o=ft(r.value);if(d(o))return o;let s=Jt(o.value);if(d(s))return s;let i=Xt(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:Ie(),...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})},Co=async(e={})=>{Io();let t=Ys(e.repoRoot);if(d(t))return a("Sync failed");let n=De();if(d(n))return n;let r=await $r({cwd:t.value,ownEventFileName:Yt(n.value)});return d(r)?(qs(r.message),r):(bo(),l("Synced",r.value))};var Ot=async(e={})=>{let t=await ke(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(m=>Nr(m)&&!m.isDeleted),s=new Map,i=new Map;for(let m of r)if(!m.isDeleted){if(Nt(m)&&m.parentNodeId){let p=s.get(m.parentNodeId)??[];p.push(m),s.set(m.parentNodeId,p)}if(w(m)&&m.parentNodeId){let p=i.get(m.parentNodeId)??[];p.push(m),i.set(m.parentNodeId,p)}}let c=Qn();if(d(c))return c;let u={};for(let m of r.filter(w))m.isDeleted||(u[m.id]=b.getCommentsByIssue(m.id).map(p=>{let v=b.getContributor(p.authorId);return{id:p.id,issueId:p.issue,body:p.md,author:{id:p.authorId,name:v?.name??"Unknown",color:ie(v?.name??p.authorId)},createdAt:Of(p.id)}}));return l("Retrieved Epiq GUI state",{boards:o.sort((m,p)=>m.rank.localeCompare(p.rank)).map(m=>({id:m.id,ref:et(m.id),title:m.title,swimlanes:(s.get(m.id)??[]).sort((p,v)=>p.rank.localeCompare(v.rank)).map(p=>({id:p.id,title:p.title,readonly:!!p.readonly,issues:(i.get(p.id)??[]).sort((v,I)=>v.rank.localeCompare(I.rank)).map(v=>({id:v.id,ref:et(v.id),title:Rt(v.title),description:v.props.description??"",readonly:!!v.readonly,tags:Rc(v),assignees:Ac(v),parentNodeId:v.parentNodeId,isClosed:v.parentNodeId===ce})),parentNodeId:p.parentNodeId}))})),tags:Object.values(n.value.tags).map(m=>({...m,color:ie(m.name)})),contributors:Object.values(n.value.contributors).map(m=>({...m,color:ie(m.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:ie(c.value.userName??"")},commentsByIssueId:u})},kc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})},Dc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=Rt(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:Ie(),...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})},Fc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=Rt(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??Ie(),u=[...i?[]:[{id:Ie(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:Ie(),...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}})},Bc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})},Uc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=Rt(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??Ie(),u=[...i?[]:[{id:Ie(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:Ie(),...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}})},Oc=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})},Eo=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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=Ie(),c={id:Ie(),...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})},So=async e=>{let t=await ke(e.repoRoot);if(d(t))return t;let n=De();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(!w(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:Ie(),...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})};var _c=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=Jn();if(d(p))return re.error(p.message);let{autoSync:v,userName:I,preferredEditor:S}=p.value;return!!(v&&I&&S)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await Co({repoRoot:e.repoRoot}),zt({type:"state",payload:await Ot({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=Jn();if(d(p))return re.error(p.message);let{autoSyncDebounceMs:v}=p.value;i()&&(t=setTimeout(()=>{c(),m()},v??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as _f}from"ws";var Fe=(e,t)=>{e.send(JSON.stringify(t))},tr=async(e,t)=>Fe(e,{type:"state",payload:await Ot({repoRoot:t})}),it=async(e,t,n,r,o)=>{if(Fe(e,{type:r,payload:o}),d(o))return Fe(e,{type:"failed",payload:o.message});n(),tr(e,t)},$c=(e,t,{onStateChanged:n})=>{new _f({server:e,path:"/ws"}).on("connection",o=>{Ui(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return tr(o,t);if(c==="sync"){let u=await Co({repoRoot:t});return Fe(o,{type:"sync:result",payload:u}),n(),tr(o,t)}if(c==="issue:comment:add"){let u=await Eo({repoRoot:t,...i.payload});return it(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await So({repoRoot:t,...i.payload});return Fe(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Fe(o,{type:"failed",payload:u.message}):(n(),tr(o,t))}if(c==="issue:edit:description"){let u=await kc({repoRoot:t,...i.payload});return it(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await Dc({repoRoot:t,...i.payload});return it(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await Fc({repoRoot:t,...i.payload});return it(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await Bc({repoRoot:t,...i.payload});return it(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await Uc({repoRoot:t,...i.payload});return it(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await Oc({repoRoot:t,...i.payload});return it(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Fe(o,{type:"issues",payload:await Tc({repoRoot:t})});if(c==="issues:create"){let u=await wc({...i.payload,repoRoot:t});return Fe(o,{type:"issues:create:result",payload:u}),d(u)?zt({type:"failed",payload:u.message}):(zt({type:"issue:created",payload:u.value}),n(),tr(o,t))}if(c==="issues:move"){if(!i.payload.position)return Fe(o,{type:"error",message:"Missing move position"});let u=await Lc({...i.payload,repoRoot:t});return it(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Fe(o,{type:"error",message:"Missing issueId"});let u=await Mc({repoRoot:t,issueId:i.payload.issueId});return it(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Fe(o,{type:"error",message:"Missing issueId"});let u=await Pc({repoRoot:t,issueId:i.payload.issueId});return it(o,t,n,"issue:reopen:result",u)}return Fe(o,{type:"error",message:"Unknown message type"})}catch(i){return Fe(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var jf=an.dirname(Hf(import.meta.url)),Vf=process.env.IS_LOCAL==="true"?an.resolve(process.cwd(),"dist/gui"):an.join(jf,"gui"),at=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Gf=async e=>new Promise((t,n)=>{let r="";e.on("data",o=>{r+=o}),e.on("end",()=>{try{t(r?JSON.parse(r):{})}catch{n(new Error("Invalid JSON body"))}}),e.on("error",n)}),zf=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",Wc=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=an.resolve(Vf),o=an.resolve(r,n),s=an.relative(r,o);if(s.startsWith("..")||an.isAbsolute(s))return at(t,403,{isError:!0,message:"Forbidden"});try{let i=await $f(o);return t.writeHead(200,{"content-type":zf(o)}),t.end(i)}catch{return at(t,404,{isError:!0,message:`Not found: ${n}`})}},Kf=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)}),Hc=async e=>{let t=Wf.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return at(s,200,await Ot({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Gf(o);if(!c.issueId||!c.body?.trim())return at(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Eo({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?at(s,400,u):at(s,200,await Ot({repoRoot:e.repoRoot}))}catch(c){return at(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return at(s,400,{isError:!0,message:"Missing comment id"});let u=await So({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?at(s,400,u):at(s,200,await Ot({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Wc("/",s):Wc(i.pathname,s)});try{await Kf(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=_c({repoRoot:e.repoRoot});$c(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 jc=async e=>{let t=await Hc({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${qf.cyan(n)}`),mi(n),l("Started GUI",{url:n})};import{Box as jt}from"ink";import ee from"react";import{Box as Xs,Text as nr}from"ink";import Ve,{useEffect as Yf,useMemo as Xf}from"react";import{ulid as Jf}from"ulid";var Vc=({text:e,match:t,color:n,highlightColor:r=y.secondary,dimColor:o=!1})=>{if(!t)return Ve.createElement(nr,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?Ve.createElement(nr,{color:n,dimColor:o},e):Ve.createElement(nr,{color:n,dimColor:o},e.slice(0,c),Ve.createElement(nr,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},Gc=Jf(),Qf=e=>`${e}`,Zf=e=>{let{pendingNavTarget:t}=Dt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(le(x.NONE,{breadCrumb:n,contextNode:r,readOnly:f().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=Jr(i),u=vo.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))},eg=e=>Q.text({id:Gc,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),tg=(e,t,n)=>Q.text({id:Qf(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Js=[],ng=e=>{zc();let t=b.createNode(eg(f().rootNodeId));d(t)||!St(t.value)||(Js=[t.value,...e.map((n,r)=>tg(n,r,Gc)).map(b.createNode).filter(te).map(({value:n})=>n).filter(St)],M.navigate({contextNode:t.value,selectedIndex:0}))},zc=()=>{let e=Js.map(t=>t.id);Js=[];for(let t of e)b.deleteNode(t)};function Kc({width:e,height:t}){let r=dd().value.trim().toLowerCase(),o=Xf(()=>Zf(r),[r]);Yf(()=>(ng(o),()=>{zc()}),[o]);let s=f().selectedIndex;return Ve.createElement(Xs,{flexDirection:"column",width:e,height:t-2},Ve.createElement(rt,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?y.accent:y.secondary2,p=i.isAvailable?"":"[unavailable] ";return Ve.createElement(Xs,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},Ve.createElement(nr,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",Ve.createElement(Vc,{text:ji(i.command),match:r,color:m,dimColor:!i.isAvailable})),Ve.createElement(Xs,{paddingLeft:2},Ve.createElement(Vc,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?y.primary:y.secondary2,dimColor:!i.isAvailable})))})))}import{Box as xg}from"ink";import Ao from"react";import or from"chalk";import{Box as Qs,Text as qc}from"ink";import rr,{useEffect as rg,useMemo as og,useState as sg}from"react";var Yc=or.hex(y.secondary),ig=or.inverse,ag=or.inverse.hex(y.secondary2),dg={hint:"",hints:[],overlap:0,remainder:""},Jc=({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}},cg=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=ie(t);return{bg:r=>or.bgHex(n).black(r),bgCursor:r=>or.bgHex(n).inverse.black(r)}}return cs(t)},lg=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=Jc({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}},Xc=()=>({value:he.value,cursorPosition:he.cursorPosition,commandIsPending:he.commandIsPending,autoCompletion:he.commandMeta.autoCompletion??dg,infoMessage:he.commandMeta.infoMessage,validationStatus:he.commandMeta.validity,command:he.commandMeta.command,inputString:he.commandMeta.inputString,modifier:he.commandMeta.modifier}),ug=(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,Qc=({width:e,mode:t})=>{let[n,r]=sg(Xc());rg(()=>{let I=()=>{let N=Xc();r(T=>ug(T,N)?T:N)},S=Rs(I);return I(),()=>{S()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p}=n,v=og(()=>{let I=Math.max(0,Math.min(s,o.length)),S=Jc({value:o,command:m}),N=lg({value:o,command:m,modifier:p}),T=m?cs(m):null,k=cg({command:m,modifier:p}),O=(de,X)=>{let lt=S&&X>=S.start&&X<S.end,ze=N&&X>=N.start&&X<N.end;return lt&&T?T.fg(de):ze&&k?k.bg(de):de},V=(de,X)=>{let lt=S&&X>=S.start&&X<S.end,ze=N&&X>=N.start&&X<N.end;return lt&&T?T.fgCursor(de):ze&&k?k.bgCursor(de):ig(de)},R=o.slice(0,I),A=o[I]??" ",G=I<o.length?o.slice(I+1):"",Re=Array.from(R).map((de,X)=>O(de,X)).join(""),Ae=V(A,I),Ge=Array.from(G).map((de,X)=>O(de,I+1+X)).join("");if(u.hint){let de=u.hint[u.overlap]??A;Ae=ag(de),Ge=Yc(u.remainder.slice(1)+G)}return Yc(t===g.PALETTE?"?":":")+Re+Ae+Ge},[o,s,u,m,p]);return rr.createElement(Qs,{flexDirection:"column",justifyContent:"flex-start"},rr.createElement(Qs,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},rr.createElement(Qs,null,rr.createElement(qc,null,v),i&&rr.createElement(qc,{wrap:"truncate",color:c?y.red:y.secondary2},` ${i} `))))};import{Box as mg,Text as pg}from"ink";import Zc from"react";var fg=(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},el=({width:e,availableHints:t})=>{let n=fg(t,e).join(" | ");return Zc.createElement(mg,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},Zc.createElement(pg,{color:y.secondary2},n.length?n:"\xA0"))};import{Box as gg,Text as No}from"ink";import sr,{useEffect as vg,useRef as Nn,useState as yg}from"react";var hg=40,Ro=.3,Zs="\u2500",tl=1,nl=16,rl=({width:e})=>{let{replay:t}=$(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*tl,[c,u]=yg(0),m=Nn(r);m.current=r;let p=Nn(0),v=Nn(0),I=Nn(0),S=Nn(0),N=Nn(0);if(vg(()=>{if(!n){p.current=0,I.current=0,S.current=0,N.current=0,u(0);return}p.current=m.current,v.current=Date.now(),I.current=m.current;let R=setInterval(()=>{let A=Date.now(),G=m.current;if(G!==I.current){let X=G-I.current,lt=A-v.current;if(X<0)S.current=0,N.current=0;else if(X>0&<>0){let ze=X/lt;S.current=S.current===0?ze:S.current*(1-Ro)+ze*Ro,N.current=N.current===0?X:N.current*(1-Ro)+X*Ro}p.current=G,v.current=A,I.current=G}let Re=A-v.current,Ae=Math.min(N.current,S.current*Re),Ge=Math.min(1,p.current+Ae),de=Math.round(Ge*i);u(X=>X===de?X:de)},hg);return()=>clearInterval(R)},[n,i]),!t)return null;let T=R=>{let A=s>1?R/(s-1):0,G=Math.round(A*(nl-1))/(nl-1);return Ar(G)},k=Math.min(s,Math.floor(c/tl)),O=[];for(let R=0;R<k;R++){let A=T(R),G=O[O.length-1];G&&G.color===A?G.text+=Zs:O.push({text:Zs,color:A})}let V=Zs.repeat(Math.max(0,s-k));return sr.createElement(gg,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1,columnGap:1},sr.createElement(No,{color:y.secondary2},"\u25B6"),sr.createElement(No,null,O.map((R,A)=>sr.createElement(No,{key:A,color:R.color},R.text)),sr.createElement(No,{color:y.secondary,dimColor:!0},V)))};var ir=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=$(),o=t===g.COMMAND_LINE||t===g.PALETTE;return Ao.createElement(xg,null,o?Ao.createElement(Qc,{width:e,mode:t}):r==="replay"?Ao.createElement(rl,{width:e}):Ao.createElement(el,{width:e,mode:t,availableHints:n}))};import{Box as _t,Text as Rn}from"ink";import Ee,{useEffect as Ig,useMemo as bg}from"react";import{ulid as ol}from"ulid";var wo=ol(),Cg=()=>[...new Set([...f().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})),Eg=e=>Q.text({id:wo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Sg=(e,t,n)=>Q.text({id:ol(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),To=[],sl=()=>{let e=To.filter(n=>n.id!==wo).map(n=>n.id),t=To.filter(n=>n.id===wo).map(n=>n.id);To=[];for(let n of[...e,...t])b.deleteNode(n)},Ng=e=>{sl();let t=b.createNode(Eg(f().rootNodeId));if(d(t)||!St(t.value))return logger.error("Could not attach help nodes");To=[t.value,...e.map((n,r)=>Sg(n,r,wo)).map(b.createNode).filter(te).map(({value:n})=>n).filter(St)],M.navigate({contextNode:t.value,selectedIndex:0})},il=({width:e,height:t})=>{let n=bg(()=>Cg(),[]);Ig(()=>(Ng(n),()=>{sl()}),[n]);let r=f().selectedIndex;return Ee.createElement(_t,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},Ee.createElement(_t,{paddingX:1,justifyContent:"center"},Ee.createElement(Rn,{color:y.accent},"Help"),Ee.createElement(Rn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),Ee.createElement(_t,{paddingX:1,marginTop:1},Ee.createElement(_t,{width:20,justifyContent:"flex-end"},Ee.createElement(Rn,{color:y.secondary},"Key(s)")),Ee.createElement(_t,{flexGrow:1,width:40,paddingLeft:2},Ee.createElement(Rn,{color:y.secondary},"Action"))),Ee.createElement(rt,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return Ee.createElement(_t,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},Ee.createElement(_t,{width:20,justifyContent:"flex-end"},Ee.createElement(Rn,{color:y.accent},o)),Ee.createElement(_t,{flexGrow:1,width:40,paddingLeft:2},Ee.createElement(Rn,{color:c?y.primary:y.secondary2},s)))})))};import Rg from"chalk";import{Box as Mo,Text as bt}from"ink";import Be from"react";var al=({width:e,height:t})=>Be.createElement(Mo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Be.createElement(bt,{color:y.accent,bold:!0},"Initialize project"),Be.createElement(bt,null,`This folder is not an ${Rg.hex(y.accent)("epiq")} project yet.`),Be.createElement(bt,{color:y.primary},"To start tracking issues here, we need to initialize a new",Be.createElement(bt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),Be.createElement(Mo,{marginTop:1,flexDirection:"column"},Be.createElement(Mo,null,Be.createElement(bt,{color:y.accent}," "),Be.createElement(bt,{color:y.primary},"Type "),Be.createElement(bt,{backgroundColor:y.secondary}," :init "))),Be.createElement(Mo,{marginTop:1},Be.createElement(bt,{color:y.secondary2},"This will create, commit and push "),Be.createElement(bt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as Po,Text as dt}from"ink";import pe from"react";var Ag=({isDone:e,command:t,value:n})=>pe.createElement(Po,null,pe.createElement(dt,{color:y.accent,dimColor:e},e?" \u2714 ":" "),pe.createElement(dt,{dimColor:e},"Type "),pe.createElement(dt,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&pe.createElement(pe.Fragment,null,pe.createElement(dt,{dimColor:e}," "),pe.createElement(dt,{color:y.secondary,dimColor:e},"<"+n+">"))),Tg=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function ei({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=wt(),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(v=>!v.done),p=m===-1?void 0:u[m];return pe.createElement(Po,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},pe.createElement(dt,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),pe.createElement(dt,null,"Let's get you started - it's a breeze."),pe.createElement(dt,{color:y.secondary2},"Remember - you can always search available commands by typing:",pe.createElement(dt,{color:y.accent}," ? ")),p&&pe.createElement(dt,{color:y.secondary2},p.message),pe.createElement(Po,{flexDirection:"column"},u.map((v,I)=>m===-1||I<=m?pe.createElement(Po,{key:v.key,marginBottom:1},pe.createElement(Ag,{isDone:v.done,command:v.command,value:v.done?Tg(v.value):void 0})):null)))}import Bo from"chalk";import{Box as dr,Text as An}from"ink";import me from"react";import{Box as Lo,Text as dl}from"ink";import $t from"react";import wg from"chalk";var Mg=e=>(b.getTag(e)?.name??"").length+3,Pg=e=>(b.getContributor(e)?.name??"").length+3,cl=({width:e})=>{let{viewMode:t}=H(),n=$(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=pt(c?.id??o.id,"TICKET"),m=te(u)?u.value:void 0,p=m?.props.tags??[],v=m?.props.assignees??[],I=m?.parentNodeId?!is(o.id,m.parentNodeId)&&t==="dense":!1,S=r.map((A,G)=>{let Re=G===r.length-1,Ae=z(A.id),Ge=Re?Ae?.[s]?.title:void 0;return`${G?" / ":""}${A.title??""}${Ge?` \u25B8 ${Ge}`:""}`}).join(""),N=m?b.getCommentsByIssue(m.id):[],T=N.length?String(N.length).length+11:0,k=I?p.reduce((A,G)=>A+Mg(G),0)+v.reduce((A,G)=>A+Pg(G),0)+T:0,O=Math.max(0,e-k),V=S.substring(0,O)+(c?.id?wg.hex(y.secondary2).dim(` #${et(c.id)}`):""),R=I?[...p.map(A=>$t.createElement(Lo,{key:`tag-${A}`,paddingLeft:1},$t.createElement(Cn,{id:A}))),...v.map(A=>$t.createElement(Lo,{key:`assignee-${A}`,paddingLeft:1},$t.createElement(Pt,{id:A}))),N.length?$t.createElement(Lo,{key:"comments",paddingLeft:1},$t.createElement(dl,{color:y.accent},"[",N.length," comment",N.length===1?"":"s","]")):null]:[];return $t.createElement(Lo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},$t.createElement(dl,{color:y.secondary2},V),R)};import{Box as Lg,Text as ll}from"ink";import ko from"react";var kg=({filters:e})=>ko.createElement(Lg,{columnGap:1},ko.createElement(ll,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>ko.createElement(ll,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),ul=ko.memo(kg);import{Box as Dg,Text as Do}from"ink";import ar from"react";function ml(){let{eventLog:e,unappliedEvents:t}=$(),n=e.at(-1)?.id,r=Lr(n??""),o=te(r)?Pr(r.value):"INVALID DATE";return ar.createElement(Dg,{paddingLeft:1},ar.createElement(Do,{backgroundColor:y.accent,color:y.secondary}," Readonly "),ar.createElement(Do,{color:y.accent}," "+t.length+" edits ago at "+o+"."),ar.createElement(Do,{color:y.accent}," Resume with "),ar.createElement(Do,{backgroundColor:y.accent,color:y.secondary}," ",":peek now"," "))}import{Box as Fg,Text as ti}from"ink";import Fo from"react";function pl(){let{replay:e}=$();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return Fo.createElement(Fg,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},Fo.createElement(ti,{backgroundColor:y.accent,color:y.secondary}," \u25B6 REPLAY "),Fo.createElement(ti,{color:y.secondary2},Pr(new Date(r))),Fo.createElement(ti,{color:y.accent},`${t}/${n} edits`))}import ni from"chalk";import{Box as Bg,Text as fl}from"ink";import ri,{useEffect as Ug,useState as Og}from"react";var _g=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],$g=150,gl=12,Wg=.36,vl=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)}},Hg=({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)}`},jg=(e,t,n)=>{let r=vl(e),o=vl(t);return Hg({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Vg=(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 jg(s,i,o)};function yl({syncStatus:e,autoSync:t}){let[n,r]=Og(0);Ug(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*Wg)+1)/2,p=Math.round(m*(gl-1));r(v=>v===p?v:p)},$g);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:Vg(_g,n/(gl-1))??""}[e.status];return ri.createElement(Bg,null,ri.createElement(fl,null,ni.hex(y.secondary2).dim(t?"Sync (auto): ":"Sync: ")),ri.createElement(fl,null,ni.hex(i)("\u25CF")+ni.hex(y.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import Cl from"chalk";import{Text as El}from"ink";import Sl,{useEffect as qg,useState as Yg}from"react";var Wt="1.2.1";import oi from"chalk";var Gg="https://registry.npmjs.org/epiq/latest",si=null,hl=0,zg=1e3*60*60*24,xl=e=>e.replace(/^v/,""),Kg=(e,t)=>{let n=xl(e).split(".").map(Number),r=xl(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},Il=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(si&&Date.now()-hl<zg)return si;try{let t=await fetch(Gg);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?Kg(r,e)>0:!1};return si=o,hl=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},bl=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?oi.hex(y.accent).dim(s):oi.hex(y.secondary).dim(s)).join(oi.hex(y.secondary2).dim("."))};function Nl(){let[e,t]=Yg({current:Wt,latest:null,updateAvailable:!1});return qg(()=>{let n=!0;return Il(Wt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?Sl.createElement(El,{dimColor:!0,color:y.secondary2},Wt+" "):Sl.createElement(El,null,Cl.hex(y.secondary2).dim(Wt),Cl.hex(y.accent).dim(" \u2197 "),bl(Wt,e.latest))}function cr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=$(),{userName:i,preferredEditor:c,autoSync:u}=H(),m=64,p=process.stdout.columns-m-8,v=t||n==="replay",I=s?mn(s.currentLabel,Math.max(0,p)):"";return me.createElement(dr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?me.createElement(dr,{paddingLeft:1},me.createElement(An,{color:y.secondary2},I)):v?me.createElement(An,null," "):o===g.PALETTE?me.createElement(dr,null,me.createElement(An,{color:y.accent},"Command Palette"),me.createElement(An,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):me.createElement(dr,{paddingLeft:1},e.length>0?me.createElement(ul,{filters:e}):me.createElement(cl,{width:p})),n==="live"?me.createElement(dr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},me.createElement(yl,{autoSync:!!u,syncStatus:r}),me.createElement(An,null,Bo.hex(y.secondary2).dim("Mode: ")+Bo.hex(y.secondary2).dim(o.padEnd(8," "))," "),me.createElement(Rl,{icon:"@",value:i}),me.createElement(Rl,{icon:"\u276F",value:c}),me.createElement(Nl,null)):"",n==="peek"?me.createElement(ml,null):"",n==="replay"?me.createElement(pl,null):"")}function Rl({icon:e,value:t}){return me.createElement(An,null,Bo.dim(e)+Bo.hex(y.accent)(` ${t??"-"} `))}import{Box as Xg,Text as Jg}from"ink";import lr from"react";import{Box as Uo,Text as ii}from"ink";import Ht from"react";function ai(){let e=$(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?W(t?.id):[];return Ht.createElement(Uo,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:y.secondary,width:s},Ht.createElement(Uo,{padding:1,paddingTop:0,paddingBottom:0},Ht.createElement(ii,null,"Select a board:")),Ht.createElement(Uo,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,v=W(c.id).flatMap(({id:I})=>z(I)).length;return Ht.createElement(Uo,{key:c.id??u},Ht.createElement(ii,{color:m?y.accent:y.secondary2},Ht.createElement(Ce,{isSelected:m})),Ht.createElement(ii,{color:m?y.accent:y.secondary2},c.title," (",v," issues)",c.readonly?" \u{1F512}":""))})))}var Qg=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=$(),u=n.find(({context:I})=>I==="BOARD"),v=s-1-3;return lr.createElement(Xg,{flexDirection:"row"},e.context==="WORKSPACE"?lr.createElement(ai,null):u?lr.createElement(so,{height:v,width:i,swimlanes:(c[u.id]??[]).filter(I=>I!==void 0&&Nt(I)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):lr.createElement(Jg,null))},Al=lr.memo(Qg);import{useEffect as Zg}from"react";var ev=e=>{Zg(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=H();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=f();u==="default"&&!c&&Wr(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},Tl=({autoSync:e})=>(ev(e),null);function di({width:e,height:t}){let n=$(),{autoSync:r,viewMode:o}=Yi(),s=n.filters;if(n.mode===g.HELP)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(il,{width:e,height:t}));if(n.mode===g.PALETTE)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{filters:s}),ee.createElement(Kc,{width:e,height:t-2}),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=wt(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{hideBreadCrumb:!0,filters:s}),ee.createElement(ei,{height:t,width:e})),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return ee.createElement(jt,{flexDirection:"column"},ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{hideBreadCrumb:!0,filters:s}),ee.createElement(al,{height:t,width:e})),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=be(n.breadCrumb??[],"BOARD");if(te(m)){let p=m.value.id,v=W(p).length,I=3,S=Math.floor(e/I),N=Math.floor(e/Math.max(v,1));e=Math.min(N,S)*Math.max(v,I)}return ee.createElement(jt,{flexDirection:"column"},ee.createElement(Tl,{autoSync:r}),ee.createElement(jt,{flexDirection:"column"},ee.createElement(cr,{filters:s}),ee.createElement(Al,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ee.createElement(ir,{width:e,mode:n.mode,availableHints:n.availableHints}))}import tv from"readline";var Oo,_o,ct,nv=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.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]),rv=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]),wl=async e=>{if(e.ctrl&&e.name==="c")return M.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=f(),s=ld(e,n);if(!s||r&&!nv.has(s)||o==="replay"&&n===g.DEFAULT&&rv.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},ov=()=>async function(t,n){n.name!=="escape"&&(ct&&(clearTimeout(ct),ct=void 0),await wl(n))},sv=()=>async function(t){if(t.length===1&&t[0]===27){ct&&clearTimeout(ct),ct=setTimeout(()=>{wl({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),ct=void 0},25);return}ct&&(clearTimeout(ct),ct=void 0)};function Ml(){Oo&&process.stdin.removeListener("keypress",Oo),_o&&process.stdin.removeListener("data",_o),Oo=ov(),_o=sv(),tv.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",_o),process.stdin.on("keypress",Oo)}async function Pl(){try{let e=Qn();te(e)&&_e(e.value);let t=Ke(process.cwd()),n=[];if(te(t)){let s=Te({repoRoot:t.value});if(d(s))return Qt(3,s.message);let i=dn(),c=await Gt({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return Qt(3,c.message);let u=await U({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=ft(s.value);if(d(m))return Qt(3,m.message);n=m.value}let r=Jt(n);if(d(r))return Qt(4,r.message);C({hasProjectDefinition:te(t),hasInitializingEvents:!!n.length});let o=ci();return d(o)?Qt(6,o.message):(Ml(),l("Booted Epiq",void 0))}catch(e){return Qt(0,Or(e))}}_d();var cv=`${Vt.bold("Epiq CLI")}
|
|
58
58
|
|
|
59
59
|
${Vt.dim("Boot in directory:")}
|
|
60
60
|
${Vt.cyan("$ epiq")}
|