epiq 0.7.5 → 0.7.7
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/readme.md +16 -2
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 = "0.7.
|
|
24914
|
+
var EPIQ_VERSION = "0.7.7";
|
|
24915
24915
|
|
|
24916
24916
|
// source/gui/client/components/Header.tsx
|
|
24917
24917
|
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ ${m}
|
|
|
54
54
|
|
|
55
55
|
${c}
|
|
56
56
|
`,xs.writeFileSync(t,n,"utf8"),te.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),l("Local epiq paths ignored",!0)};var Rp=async e=>{let t=await B({cwd:e,args:["status","--porcelain"]});return d(t)?t:l("Checked git diff",t.value.stdout.trim().length>0)},K=(e,t)=>a(`[${e}] ${t}`),vd=async()=>{W("");let e=tn(),t=await xt(process.cwd());if(d(t))return K(1,t.message);let n=t.value,o=await ao(n);if(d(o))return K(2,o.message);if(o.value)return K(2,`Cannot initialize Epiq while a git operation is in progress: ${o.value}`);let r=await Rp(n);if(d(r))return K(2.5,r.message);if(r.value)return K(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(Er(n))return K(4,"Epiq project already initialized");let s=Nt();if(!s.isSetupDone||!s.userName)return K(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=_(),c=i.userName,u=i.userId;if(!u||!c)return K(5,"Missing Epiq user id");let m=e.stateBranch,p=await lo({repoRoot:n,branch:m});if(d(p))return K(6,p.message);if(p.value)return K(6,`State branch already exists: ${m}`);let v=await Br({repoRoot:n,stateBranchName:m});if(d(v))return K(6,v.message);let S=po();if(d(S))return K(7,S.message);let N=fd.join(mo(),e.projectId),E=await Wt({repoRoot:n,stateBranchRoot:N,stateBranchName:m});if(d(E))return K(8,E.message);let R=fd.join(N,".epiq");Ep.mkdirSync(R,{recursive:!0});let M=ra({userId:u,userName:c});if(d(M))return K(9,M.message);for(let Sr of M.value){let Hs=Eo({event:Sr,rootDir:N});if(d(Hs))return K(9,Hs.message)}let D=await go({stateBranchRoot:N,eventFileName:Vt({userId:u,userName:c})});if(d(D))return K(10,D.message);let j=await on({cwd:N,message:"[epiq:init]"});if(d(j))return K(10,j.message);let O=await gd(n);if(d(O))return K(11,O.message);let k=qs({repoRoot:n,fileContents:e});if(d(k))return K(12,k.message);let Ne=await ne.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d(Ne))return K(13,Ne.message);let ft=await ne.commit({cwd:n,message:"[epiq:init-project]"});if(d(ft))return K(13,ft.message);let vt="Project initialized!",yt=await B({cwd:n,args:["push","-u","origin","HEAD"]});d(yt)&&(vt+=` Warn: [init:14] ${yt.message}`);let le=await En({repoRoot:n,stateBranchRoot:N});d(le)&&(vt+=` Warn: [init:15] ${le.message}`);let en=Ht(M.value).filter(d);if(en.length>0)return K(16,en.map(Sr=>Sr.message).join(`
|
|
57
|
-
`));let Ot=Ue();if(d(Ot))return K(16,Ot.message);let{rootNodeId:Jc,nodes:Qc}=Ot.value,js=Qc[Jc];return js?(A.navigate({contextNode:js,selectedIndex:0}),C({hasProjectDefinition:!0,mode:f.DEFAULT}),l(vt,null)):K(16,"Unable to resolve initialized root node")};import{ulid as Ap}from"ulid";import{ulid as Tp}from"ulid";var yd=null,Pt=()=>structuredClone(yd),Hn=e=>{yd=e},hd=()=>{let{contextNode:e,selectedIndex:t}=g(),o=H(e.id)[t];return o?l("Resolved selected child",o):a("Target node not found")},Is=({id:e,parentId:t,position:n={at:"end"}})=>{let o=H(t).filter(r=>r.id!==e);return Ro(o,n)},xd=({id:e,parentId:t,position:n={at:"end"}})=>{let o=X();if(d(o))return a("Unable to resolve user ID");let r=Is({parentId:t,id:e,position:n});return d(r)?r:l("Created pending move state",{id:Tp(),...o.value,action:"move.node",payload:{id:e,parent:t,rank:r.value.rank}})},Id=e=>{Hn(e);let t=Mn(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function bs(e){let t=hd();if(d(t))return t;let{contextNode:n,nodes:o}=g();if(!n.parentNodeId)return a("Missing parent node id");let r=o[n.parentNodeId];if(!r)return a("Missing parent node");let s=H(r.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=xd({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Id(u.value)}function Cs(e){let t=hd();if(d(t))return t;let{contextNode:n,selectedIndex:o}=g(),s=H(n.id)[o+e];if(!s)return a("Missing sibling node");let i=xd({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Id(i.value)}var bd=()=>{let e=Pt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,o=g().nodes[n];if(!o)return a("Move parent not found");let r=H(n).findIndex(s=>s.id===t);return r===-1?a("Moved node not found among rendered children"):(A.navigate({contextNode:o,selectedIndex:r}),l("Synchronized navigation to moved node",null))},Jo=(e,t="Moved preview")=>{if(d(e))return e;let n=bd();return d(n)?n:(C({mode:f.MOVE}),l(t,null))},Cd=async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=q().commandMeta,{contextNode:n,selectedIndex:o}=g(),r=H(n.id)[o];if(!r)return C({mode:f.DEFAULT}),a("No move target");if(t==="start"){if(r.readonly)return a("Target node is read-only");if(o===-1)return a("No item selected");if(!r.parentNodeId)return a("Target has no parent");let s=H(r.parentNodeId),i=s.findIndex(({id:v})=>v===r.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=Is({parentId:r.parentNodeId,id:r.id,position:m});return d(p)?p:(Hn({id:Ap(),action:"move.node",payload:{id:r.id,parent:r.parentNodeId,rank:p.value.rank},...e.value}),C({mode:f.MOVE}),l("Move initialized",null))}if(t==="next")return Jo(Cs(1));if(t==="previous")return Jo(Cs(-1));if(t==="to-next")return Jo(bs(1));if(t==="to-previous")return Jo(bs(-1));if(t==="confirm"){let s=Pt();if(!s)return a("No pending move to confirm");let i=await Ve();if(d(i))return i;let c=F([s],i.value);if(d(c))return c;let u=bd();return d(u)?u:(Hn(null),C({mode:f.DEFAULT}),l("Moved item",null))}return t==="cancel"?(Hn(null),C({mode:f.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Zo}from"ulid";import{monotonicFactory as wp,ulid as Mp}from"ulid";var Pp=wp(),Qo=({name:e,parent:t,rank:n,user:{userId:o,userName:r}})=>{let s=Pp();return l("Created issue events",[{id:Mp(),userId:o,userName:r,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Sd=async(e,t)=>{let n=X();if(d(n))return a("Unable to resolve user ID");let o=await Ve();if(d(o))return o;let r=o.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=g(),u=m=>{let p=F([m],r);if(d(p))return p;let v=I.getNode(p.value[0].result.id);if(!v)return a("Created node not found");if(!v.parentNodeId)return p;let S=I.getNode(v.parentNodeId);return S?(A.navigate({contextNode:S,selectedIndex:I.getSiblings(v.parentNodeId).findIndex(({id:N})=>N===v.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let v=cn(p.id,n.value,r);return d(v)?v:u({id:Zo(),action:"add.board",payload:{id:Zo(),name:t.inputString,parent:p.id,rank:v.value},...n.value})}if(t.modifier==="swimlane"){let m=Ee(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=cn(m.value.id,n.value,r);return d(p)?p:u({id:Zo(),action:"add.swimlane",payload:{id:Zo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=$(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Ee(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let v=cn(p.id,n.value,r);if(d(v))return v;let S=Qo({name:t.inputString,parent:p.id,rank:v.value,user:n.value});if(d(S))return S;let N=S.value,E=F([...N],r);if(d(E))return E;if(!E.value[0])return a("Issue creation failed");let D=N.find(j=>j.action==="add.issue")?.payload.id;return D?(A.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===D)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Nd=async()=>{let e=Ee(g().breadCrumb,"BOARD");if(d(e))return e;let t=await xt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=We({repoRoot:t.value});if(d(n))throw new Error(n.message);let{modifier:o,inputString:r}=q().commandMeta;if(o==="now"){let R=at(n.value);if(d(R))return a(R.message);let M=Vn();if(d(M))return M;let j=Ht(R.value).filter(d);return j.length>0?a(j.map(O=>O.message).join(", ")):(C({mode:f.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),l("Peeking now",!0))}let s;if(o==="prev"){let R=g().eventLog.at(-1),M=Vr(R);if(M===null)return a("No previous event to peek");s=M}else if(o==="next"){let R=g().unappliedEvents.at(0),M=Vr(R);if(M===null)return a("No next event to peek");s=M+1}else{let R=Do(o||r);if(!R)return a("Invalid peek date");s=R.getTime()}let i=g(),c=e.value.id,u=_i(n.value,s);if(d(u))return a(u.message);let{appliedEvents:m,unappliedEvents:p}=u.value,v=Vn();if(d(v))return v;let N=Ht(m).filter(d);if(N.length>0)return Vn(),C(i),a(N.map(R=>R.message).join(", "));let E=g().nodes[c];return E?(A.navigate({contextNode:E,selectedIndex:0}),C({mode:f.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:p}),l("Peeking",!0)):(Vn(),C(i),a("Board did not exist at peek date"))};import Lp from"zod";var Ed=()=>{let e=q().commandMeta.inputString,t=Lp.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=mt({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),C({mode:f.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Rd=()=>{let e=q().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=ua(e),n=mt({autoSync:t});return d(n)?n:(Fe({autoSync:t}),C({mode:f.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Td=()=>{let e=q().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=mt({logLevel:e});return d(n)?n:(Fe({logLevel:e}),C({mode:f.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Ad=async()=>{W(""),C({mode:f.DEFAULT});let e=Ue();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 wo();return d(t)?(C({syncStatus:{msg:t.message,status:"failed"}}),t):(C({mode:f.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var kp=e=>e.action==="add.issue.comment",wd=e=>Object.values(g().tags).find(t=>t.name===e),Md=e=>Object.values(g().contributors).find(t=>t.name===e),pt=async()=>{let e=await Ve();return d(e)?e:l("Resolved persist root",e.value)},er=[{systemOnly:!0,intent:P.Move,description:"Internal move-state command",mode:f.COMMAND_LINE,action:Cd},{intent:P.Delete,description:"Delete the currently selected node",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Unable to resolve child to delete");let r=await pt();if(d(r))return r;if(o.context==="COMMENT"){let s=o.id,i=T(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!T(c))return a("Unable to resolve comment issue");let u=c.log?.filter(kp).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):F([{id:fe(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],r.value):a("Unable to resolve comment")}return F([{id:fe(),action:"delete.node",payload:{id:o.id},...e.value}],r.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:f.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=q().commandMeta,n=/(!=|=)/,[o]=e.split(n);if(!o||!(i=>ae(h.FILTER).map(c=>c.split(n)[0]).includes(i))(o))return a("Invalid filter modifier");let s={target:o,operator:"=",value:t.trim()};return ue(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:f.DEFAULT})),l("Filter updated",null)}},{intent:P.ViewHelp,description:"Open the help screen",mode:f.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:o}=g();return Mt({pendingNavTarget:{contextNode:e,breadCrumb:o,selectedIndex:t,selectedNode:n}}),C({mode:f.HELP}),l("Viewing help",null)}},{intent:P.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Unable to close issue, no target found");if(!T(o))return a("Cannot close in this context");let r=g().nodes[ie];if(!r)return a("Unable to locate closed swimlane");if(o.parentNodeId===r.id)return a("Issue is already closed");let s=await pt();if(d(s))return s;let i=s.value,c=Gt(r.id,o.id,{at:"end"},e.value,i);if(d(c))return c;let u=F([{id:fe(),action:"close.issue",payload:{id:o.id,parent:r.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Unable to reopen issue, no target found");let r=o.context==="TICKET"?l("Resolved ticket",o):it(o.id,"TICKET");if(d(r))return a("Cannot reopen in this context");let s=r.value,i=g().nodes[ie];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!T(s))return a("Target node is not issue");let c=Yo(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await pt();if(d(m))return m;let p=m.value,v=Gt(u.id,s.id,{at:"end"},e.value,p);if(d(v))return v;let S=F([{id:fe(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:v.value},...e.value}],p);return d(S)?S:l("Issue reopened",null)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Init,description:"Initialize Epiq in the current git repository",mode:f.COMMAND_LINE,action:vd},{intent:P.NewItem,description:"Create a new board, swimlane, or issue",mode:f.COMMAND_LINE,action:Sd,onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Rename,description:"itle] Rename the currently selected node",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Missing node");if(o.readonly)return a("Cannot rename readonly node");let r=Fa();if(!r)return a("Provide a title");let s=await pt();return d(s)?s:F([{id:fe(),action:"edit.title",payload:{id:o.id,name:r},...e.value}],s.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.UntagTicket,description:"Remove a tag from the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide a tag");let r=wd(o);if(!r)return a(`Tag "${o}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=it(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!T(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(r.id))return a("Issue is not tagged with that tag");let m=await pt();return d(m)?m:F([{id:fe(),action:"remove.issue.tag",payload:{id:c.id,tag:r.id},...e.value}],m.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.TagTicket,description:"Add or create a tag on the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide a tag");let{selectedNode:r}=g();if(!r)return a("Invalid tag target");let s=it(r.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!T(i))return a("Target node is not issue");let c=await pt();if(d(c))return c;let u=wd(o),m=u?.id??fe();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):F([...u?[]:[{id:fe(),action:"create.tag",payload:{id:m,name:o},...e.value}],{id:fe(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.AssignUserToTicket,description:"Assign a user to the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide an assignee");let{selectedIndex:r,contextNode:s}=g(),i=$(s.id)[r];if(!i)return a("Invalid assign target");let c=it(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!T(u))return a("Target node is not issue");let m=await pt();if(d(m))return m;let p=Md(o),v=p?.id??fe();return(u.props.assignees??[]).includes(v)?a("Assignee already assigned"):F([...p?[]:[{id:fe(),action:"create.contributor",payload:{id:v,name:o},...e.value}],{id:fe(),action:"add.issue.assignee",payload:{id:u.id,assignee:v},...e.value}],m.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide an assignee to remove");let r=Md(o);if(!r)return a(`Assignee "${o}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=it(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!T(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(r.id))return a(`Issue is not assigned to "${o}"`);let m=await pt();return d(m)?m:F([{id:fe(),action:"remove.issue.assignee",payload:{id:c.id,assignee:r.id},...e.value}],m.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Comment,description:"Add a comment to the selected issue",mode:f.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>mn)return a(`Cannot exceed ${mn} characters`);let o=X();if(d(o))return a("Unable to resolve user ID");let{breadCrumb:r,selectedNode:s}=g(),i=Ee([...r,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let u=c.context==="TICKET"?l("Resolved ticket",c):it(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!T(m))return a("Target node is not issue");let p=await pt();return d(p)?p:F([{id:fe(),action:"add.issue.comment",payload:{id:fe(),issue:m.id,author:o.value.userId,md:n},...o.value}],p.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Sync,description:"Pull, commit, and push Epiq state",mode:f.COMMAND_LINE,action:Ad},{intent:P.Peek,description:"View board state at another point in time",mode:f.COMMAND_LINE,action:Nd},{intent:P.Export,description:"Export the current board layout to markdown",mode:f.COMMAND_LINE,action:async()=>{let e=await td();return d(e)?e:(C({mode:f.DEFAULT}),l("Export successful",!0))}},{intent:P.Exit,description:"Exit the application",mode:f.COMMAND_LINE,action:async()=>(A.exit(),l("Exit successful",!0))},{intent:P.Edit,description:"Edit title or description",mode:f.COMMAND_LINE,action:async(e,t)=>pd(t),onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:f.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case se.USERNAME:{let{userId:o,preferredEditor:r,userName:s}=_(),i=n||s,c=o??fe();if(!i||!c)return a("Unable to resolve user name or id");let u=mt({userName:i,userId:c,preferredEditor:r??""});return d(u)?u:(Fe({userName:i,userId:c}),C({mode:f.DEFAULT}),l(`Username set to "${i}"`,null))}case se.EDITOR:{if(!n)return a("No editor provided");let o=mt({preferredEditor:n});return d(o)?o:(Fe({preferredEditor:n}),C({mode:f.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case se.VIEW:return n!=="wide"&&n!=="dense"?a("Invalid view mode"):(Fe({viewMode:n}),l(`View set to "${n}"`,null));case se.AUTOSYNC:return Rd();case se.LOG_LEVEL:return Td();case se.SYNC_DEBOUNCE_MS:return Ed();default:return a("Unknown config command")}}},{intent:P.Coffee,description:"Sponsor the development of Epiq!",mode:f.COMMAND_LINE,action:()=>{let e=q().commandMeta.modifier;return e==="custom"?ys("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):ys(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var Dp=new Set(["peek","filter","view-help"]),Ze=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:o,inputString:r}}=q();if(!t)return a("No command to confirm");if(!e&&n===Et.Invalid)return a("Invalid command");let s=$o(t);Ma();let{readOnly:i}=g();if(i&&!Dp.has(s))return Un({status:ht.Fail,message:"Command not available in readonly state",value:null});let c=er.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return Un({status:ht.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:r,modifier:o})}catch(m){return Un({status:ht.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?Un(u):(Pa({addToHistory:!e}),c.onSuccess?.(),_().autoSync&&Po(),u)};var tr=[{intent:x.Exit,mode:f.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(C({mode:f.COMMAND_LINE}),W("move cancel"),Ze({isForceExecutedBySystem:!0}))},{intent:x.InitMove,mode:f.DEFAULT,description:"[m] move (init/confirm)",action:()=>(C({mode:f.COMMAND_LINE}),W("move start"),Ze({isForceExecutedBySystem:!0}))},{intent:x.ConfirmMove,mode:f.MOVE,action:()=>(C({mode:f.COMMAND_LINE}),W("move confirm"),Ze({isForceExecutedBySystem:!0}))}],nr=[{intent:x.MovePreviousItem,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move previous"),Ze({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveNextItem,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move next"),Ze({isForceExecutedBySystem:!0})):a("No pending move")}],Pd=[{intent:x.MoveToNextContainer,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move to-next"),Ze({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveToPreviousContainer,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move to-previous"),Ze({isForceExecutedBySystem:!0})):a("No pending move")}];var Ld={[w.WORKSPACE]:[...tr,...nr],[w.BOARD]:[...tr,...nr],[w.SWIMLANE]:[...tr,...nr,...Pd],[w.TICKET]:[],[w.FIELD]:[],[w.FIELD_LIST]:[],[w.TEXT]:[],[w.COMMENT]:[]};var kd=()=>{W("");let{pendingNavTarget:e}=wt();C({mode:f.DEFAULT}),e&&A.navigate(e),Mt({pendingNavTarget:void 0})},Dd=[{intent:x.ExitCommandLine,mode:f.HELP,action:()=>(kd(),l("Exiting help",null))},{intent:x.Exit,mode:f.HELP,action:()=>(kd(),l("Closed help",null))},{intent:x.NavPreviousItem,mode:f.HELP,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:x.NavNextItem,mode:f.HELP,action:()=>(A.navigateToNextItem(),l("Navigating to next help item",null))},{intent:x.NavToPreviousContainer,mode:f.HELP,action:()=>(A.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:x.NavToNextContainer,mode:f.HELP,action:()=>(A.navigateToNextContainer(),l("Navigating to next help container",null))}];var Fp=e=>{C({mode:f.COMMAND_LINE});let{pendingNavTarget:t}=wt();t&&A.navigate(t),Mt({pendingNavTarget:void 0}),W(`${e} `)},Fd=()=>{W("");let{pendingNavTarget:e}=wt();e&&A.navigate(e),Mt({pendingNavTarget:void 0}),C({mode:f.DEFAULT})},Bd=[{intent:x.InitCommandPalette,mode:f.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:o}=g();return Mt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:o}}),C({mode:f.PALETTE}),l("Opening command palette",null)}},{intent:x.Confirm,mode:f.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!bt(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?(Fp(t),l("Selected command",t)):l("No command selected",null)}},{intent:x.ExitCommandLine,mode:f.PALETTE,action:()=>(Fd(),l("Exiting palette",null))},{intent:x.Exit,mode:f.PALETTE,action:()=>(Fd(),l("Closed command palette",null))},{intent:x.NavPreviousItem,mode:f.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:x.NavNextItem,mode:f.PALETTE,action:()=>(A.navigateToNextItem(),l("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:f.PALETTE,action:()=>(A.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:f.PALETTE,action:()=>(A.navigateToNextContainer(),l("Navigating to next container",null))}];var Ud=[...Dd,...Bd,{intent:x.AddItem,mode:f.DEFAULT,description:"[n] new...",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.NEW} `),l("Adding new item",null))},{intent:x.Delete,mode:f.DEFAULT,description:"[d] delete",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.DELETE} `),l("Deleting item",null))},{intent:x.InitCommandLine,mode:f.DEFAULT,description:"[:] focus command line",action:()=>(C({mode:f.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:x.Confirm,mode:f.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!H(e?.id??"")?.length){if(e?.title===oe.DESCRIPTION)return C({mode:f.COMMAND_LINE}),W(`${h.EDIT} description `),l("Propose command",!0);if(e?.title===oe.ASSIGNEES)return C({mode:f.COMMAND_LINE}),W(`${h.ASSIGN} `),l("Propose command",!0);if(e?.title===oe.TAGS)return C({mode:f.COMMAND_LINE}),W(`${h.TAG} `),l("Propose command",!0);if(t.title===oe.DESCRIPTION&&e?.context==="TEXT")return C({mode:f.COMMAND_LINE}),W(`${h.EDIT} description `),l("Propose command",!0)}return A.enterChildNode(),l("Entering context",null)}},{intent:x.EditTitle,mode:f.DEFAULT,description:"[r] rename title",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:x.EditDescription,mode:f.DEFAULT,description:"[e] edit description",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.EDIT} description `),l("Exiting context",null))},{intent:x.Exit,mode:f.DEFAULT,description:"[q] exit context",action:()=>(A.enterParentNode(),l("Exiting context",null))},{intent:x.NavPreviousItem,mode:f.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:x.NavNextItem,mode:f.DEFAULT,action:()=>(A.navigateToNextItem(),l("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:f.DEFAULT,action:()=>(A.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:f.DEFAULT,action:()=>(A.navigateToNextContainer(),l("Navigating to next container",null))}];var Bp=500,Up=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Od=e=>{let t=Up(e);t&&Wo(n=>(n+t).slice(0,Bp))};var Op=[f.COMMAND_LINE,f.PALETTE],Wp=e=>[{intent:x.MoveCursorLeft,mode:e,action:()=>(is(-1),l("Moving cursor left",null))},{intent:x.MoveCursorRight,mode:e,action:()=>(is(1),l("Moving cursor right",null))},{intent:x.MoveCursorLeftOfWord,mode:e,action:()=>(as("left"),l("Moving cursor left of word",null))},{intent:x.MoveCursorRightOfWord,mode:e,action:()=>(as("right"),l("Moving cursor right of word",null))},{intent:x.AutoCompleteCommand,mode:e,action:()=>(Wo((t,{remainder:n})=>{let o=n?t+n:t,r="";return o==="edit title "&&(r=g().selectedNode?.title??""),o+r}),l("Auto-completing command",null))},{intent:x.CaptureInput,mode:e,action:(t,{sequence:n})=>(Od(n??""),l("Capturing input",null))},{intent:x.EraseInput,mode:e,action:()=>(Aa(),l("Erasing input",null))},{intent:x.EraseInputWord,mode:e,action:()=>(wa(),l("Erasing input word",null))}],Wd=[{intent:x.Confirm,mode:f.COMMAND_LINE,action:()=>(Ze(),l("Executing command",null))},{intent:x.ViewHelp,mode:f.DEFAULT,action:()=>(C({mode:f.HELP}),l("Viewing help",null))},...Op.flatMap(Wp),{intent:x.ExitCommandLine,mode:f.COMMAND_LINE,action:()=>(C({mode:f.DEFAULT}),l("Exiting command line",null))},{intent:x.GetLastCommandFromHistory,mode:f.COMMAND_LINE,action:()=>(La(),l("Getting last command from history",null))},{intent:x.GetNextCommandFromHistory,mode:f.COMMAND_LINE,action:()=>(ka(),l("Getting next command from history",null))}];import jd from"chalk";var or=jd.dim.hex(y.secondary2)(": for command line"),$d="q to exit",_d=`${jd.hex(y.accent)("m")} to confirm`,Ss={[w.WORKSPACE]:[or],[w.BOARD]:[or],[w.BOARD+f.COMMAND_LINE]:[or],[w.SWIMLANE]:[or],[w.TICKET+f.HELP]:[$d],[w.SWIMLANE+f.HELP]:[$d],[w.TICKET]:[],[w.FIELD]:[],[w.SWIMLANE+f.MOVE]:[_d],[w.TICKET+f.MOVE]:[_d]};var Gn=e=>e.trim().toLocaleLowerCase(),$p=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},_p=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},Hd=(e,t)=>{let n=Gn(t.value);if(!n)return!0;switch(t.target){case"title":return Gn(e.title??"").includes(n);case"description":return Gn(e.props.description??"").includes(n);case"tag":return $p(e).map(Gn).some(r=>r.includes(n));case"assignee":return _p(e).map(Gn).some(r=>r.includes(n));default:return!0}};function Vd(e,t,n){let o=t[e];if(!o)return a("buildBreadCrumb(): current node not found");let r=[],s=o;for(;s&&(r.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=r[r.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(r.reverse(),l("Breadcrumb built",r))}var Gd=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 Qt,Ns,Es=new Set,zd=()=>{for(let e of Es)e()},Hp=e=>(Es.add(e),()=>Es.delete(e));function Kd(e){let{contextNodeId:t,mode:n,rootNodeId:o,nodes:r,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!o)return a("derive(): rootNode is missing");if(!r[o])return a("derive(): unable to find root node");let c=r[t];if(!c)return a("Unable to derive state, contextNode not found");let u=Vd(t,r,o);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,v=Ss[p+n]??Ss[p]??[],S=[...Ud,...Ld[p]??[],...Wd],N=Gd(S),E=Vp(r,s),R=E[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:v,availableActions:S,actionIndex:N,selectedNode:R,renderedChildrenIndex:E})}var g=()=>{if(!Qt)throw new Error("State not initialized. Call initWorkspaceState() first.");return Qt},Ue=()=>Qt?l("Retrieved state",Qt):a("State not initialized. Call initWorkspaceState() first.");function Pn(e){Ns=e;let t=He(process.cwd()),n=!1;if(!d(t)){let s=It(t.value);if(d(s))return a(s.message);n=!0}let o={readOnly:!1,filters:[],tags:{},contributors:{},mode:f.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{}},r=Kd(o);return d(r)?r:(Qt=r.value,zd(),l("State initialized",null))}function ue(e){let t=g(),n=e(t),o=Kd(n);return d(o)?a(o.message??"Unable to update state"):(Qt=o.value,zd(),l("State updated",null))}var C=e=>ue(t=>({...t,...e}));var z=()=>jp(Hp,g,g),Vp=(e,t)=>{let n={};for(let o of Object.values(e))T(o)&&t.length>0&&!t.every(r=>Hd(o,r))||!o.parentNodeId||o.isDeleted||((!o.parentNodeId||!n[o.parentNodeId])&&(n[o.parentNodeId]=[]),n[o.parentNodeId].push(o));for(let o of Object.keys(n))n[o].sort((r,s)=>{let i=e[r.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},$=e=>g()?.renderedChildrenIndex[e]??[],Vn=()=>Ns?Pn(Ns):a("Cannot reset state: no initial workspace found"),un=()=>Qt!==void 0;var Rs=e=>{un()&&(C({syncStatus:e}),$t({type:"sync-status",payload:e}))},rr=(e="Syncing...")=>{Rs({status:"syncing",msg:e})},sr=(e="Synced")=>{Rs({status:"synced",msg:e})},Ts=e=>{Rs({status:"failed",msg:e})},Oe=e=>(Ts(e),a(e));import{decodeTime as QA}from"ulid";var Gp=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=G("getRepoRootDir",await xt(e));if(d(n))return a(n.message);let o=n.value;logger.debug("[sync] repo root",o);let r=G("getStateBranchRoot",We({repoRoot:o}));if(d(r))return a(r.message);let s=r.value;logger.debug("[sync] state branch root",s);let i=G("ensureInitialCommit",await pi(o));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:o,stateBranchRoot:s,ensureUpstream:t});let c=G("bootstrapStateBranchStorage",await fi({repoRoot:o,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=G("hasInProgressGitOperation(stateBranchRoot)",await ao(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:o,stateBranchRoot:s});let m=G("ensureStateBranchLayout",li(o,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:o,stateBranchRoot:s,bootstrapped:c.value}),l("Sync preconditions satisfied",{repoRoot:o,stateBranchRoot:s,bootstrapped:c.value}))},zp=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 o=G("stageStateBranchOwnEventFile",await go({stateBranchRoot:t,eventFileName:n}));if(d(o))return a(o.message);let r=G("hasStagedChanges(after stage)",await ri(t));if(d(r))return a(r.message);if(logger.debug("[sync] state branch change check after stage result",{changed:r.value}),!r.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=G("createStateBranchSyncCommit",await gi({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}))},Mo=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");rr();let n=G("ensureSyncReady",await Gp({cwd:e,ensureUpstream:!0}));if(d(n))return Oe(n.message);let{repoRoot:o,stateBranchRoot:r,bootstrapped:s}=n.value,i=G("isDetachedHead(stateBranchRoot)",await si(r));if(d(i))return Oe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Oe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,v=G("getStateBranch",nn(o));if(d(v))return Oe(v.message);let S=v.value;logger.debug("[sync] resolved state branch",{stateBranch:S,stateBranchRoot:r});let N=G("commitOwnEventFileToStateBranch",await zp({repoRoot:o,stateBranchRoot:r,ownEventFileName:t}));if(d(N))return Oe(N.message);c=N.value.createdCommit,u=N.value.commitSha;let E=G("pullBranchRebaseIfPresent",await kr({cwd:r,branch:S}));if(d(E))return Oe(E.message);if(m=E.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:r});let R=G("pushStateBranch",await En({stateBranchRoot:r,repoRoot:o}));if(d(R)&&oi(R.message)){let M=G("pullBranchRebaseIfPresent(retry)",await kr({cwd:r,branch:S}));if(d(M))return Oe(M.message);m=m||M.value,R=G("pushStateBranch(retry)",await En({stateBranchRoot:r,repoRoot:o}))}if(d(R))return Oe(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:r});let R=G("git rev-parse HEAD",await B({args:["rev-parse","HEAD"],cwd:r}));if(d(R))return Oe(R.message);u=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return sr(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:o,stateBranchRoot:r,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var As=e=>{let t=He(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},we=async e=>{let t=As(e);if(d(t))return t;let n=We({repoRoot:t.value});if(d(n))return a(n.message);let o=tn(),r=await Wt({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:o.stateBranch});if(d(r))return a(r.message);let s=await B({cwd:n.value,args:["pull","--ff-only"]});d(s)&&te.info(3,s.message);let i=at(n.value);if(d(i))return a(i.message);let c=zt(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},Me=()=>{let e=jn();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")},_e=()=>{let e=Ue();return d(e)?a(e.message):e},qd=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:re(t.name)})),Yd=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:re(t.name)}));var Xd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=_e();if(d(n))return n;let o=Object.values(n.value.nodes).filter(T).filter(r=>e.includeClosed||r.parentNodeId!==ie).map(r=>({id:r.id,title:St(r.title),description:r.props.description??"",parentNodeId:r.parentNodeId,isClosed:r.parentNodeId===ie,readonly:!!r.readonly,tags:qd(r),assignees:Yd(r)}));return l("Listed issues",o)},Jd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=cn(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let r=Qo({name:e.title,parent:e.parentId,user:n.value,rank:o.value});if(d(r))return r;let s=r.value,i=F([...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")},Qd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=Gt(ie,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(o))return o;let r={id:ve(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ie,rank:o.value}},s=F([r],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},Zd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Target node is not issue");if(r.parentNodeId!==ie)return a("Issue is not closed");let s=Yo(r);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ie)return a("Previous parent resolves to closed swimlane");let i=o.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=Gt(i.id,r.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:ve(),...n.value,action:"reopen.issue",payload:{id:r.id,parent:i.id,rank:c.value}},m=F([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:r.id,parentId:i.id})},ec=async e=>{let t=As(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=We({repoRoot:t.value});if(d(o))return o;let r=at(o.value);if(d(r))return r;let s=zt(r.value);if(d(s))return s;let i=Gt(e.parentId,e.issueId,e.position??{at:"end"},n.value,o.value);if(d(i))return i;let c={id:ve(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=F([c],o.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})},ir=async(e={})=>{rr();let t=As(e.repoRoot);if(d(t))return a("Sync failed");let n=Me();if(d(n))return n;let o=await Mo({cwd:t.value,ownEventFileName:Vt(n.value)});return d(o)?(Ts(o.message),o):(sr(),l("Synced",o.value))};var Lt=async(e={})=>{let t=await we(e.repoRoot);if(d(t))return t;let n=_e();if(d(n))return n;let o=Object.values(n.value.nodes),r=o.filter(m=>vo(m)&&!m.isDeleted),s=new Map,i=new Map;for(let m of o)if(!m.isDeleted){if(Ct(m)&&m.parentNodeId){let p=s.get(m.parentNodeId)??[];p.push(m),s.set(m.parentNodeId,p)}if(T(m)&&m.parentNodeId){let p=i.get(m.parentNodeId)??[];p.push(m),i.set(m.parentNodeId,p)}}let c=jn();if(d(c))return c;let u={};for(let m of o.filter(T))m.isDeleted||(u[m.id]=I.getCommentsByIssue(m.id).map(p=>{let v=I.getContributor(p.authorId);return{id:p.id,issueId:p.issue,body:p.md,author:{id:p.authorId,name:v?.name??"Unknown",color:re(v?.name??p.authorId)},createdAt:Kp(p.id)}}));return l("Retrieved Epiq GUI state",{boards:r.sort((m,p)=>m.rank.localeCompare(p.rank)).map(m=>({id: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,S)=>v.rank.localeCompare(S.rank)).map(v=>({id:v.id,title:St(v.title),description:v.props.description??"",readonly:!!v.readonly,tags:qd(v),assignees:Yd(v),parentNodeId:v.parentNodeId,isClosed:v.parentNodeId===ie})),parentNodeId:p.parentNodeId}))})),tags:Object.values(n.value.tags).map(m=>({...m,color:re(m.name)})),contributors:Object.values(n.value.contributors).map(m=>({...m,color:re(m.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:re(c.value.userName??"")},commentsByIssueId:u})},tc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Edit target must be an issue");if(r.readonly)return a("Cannot edit readonly issue");let s=r.props.description??"";if(s===e.description)return l("No changes made",{id:e.issueId,description:s});let i={id:ve(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=F([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},nc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Edit target must be an issue");if(r.readonly)return a("Cannot edit readonly issue");let s=St(e.title);if(!s.trim())return a("Issue title cannot be empty");if(r.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:ve(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=F([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},oc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Tag target must be an issue");if(r.readonly)return a("Cannot tag readonly issue");let s=St(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(o.value.tags).find(p=>p.name===s),c=i?.id??ve(),u=[...i?[]:[{id:ve(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:ve(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=F(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},rc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Untag target must be an issue");if(r.readonly)return a("Cannot untag readonly issue");if(!o.value.tags[e.tagId])return a("Tag not found");let s={id:ve(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=F([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},sc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Assign target must be an issue");if(r.readonly)return a("Cannot assign readonly issue");let s=St(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(o.value.contributors).find(p=>p.name===s),c=i?.id??ve(),u=[...i?[]:[{id:ve(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:ve(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=F(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},ic=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Unassign target must be an issue");if(r.readonly)return a("Cannot unassign readonly issue");if(!o.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:ve(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=F([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},ar=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Comment target must be an issue");if(r.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=ve(),c={id:ve(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=F([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},dr=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!r)return a("Unable to resolve comment");if(r.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=o.value.nodes[r.payload.issue];if(!s)return a("Issue not found");if(!T(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(o.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return l("Comment already deleted",{id:e.commentId,issueId:r.payload.issue});let c={id:ve(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:r.payload.issue}},u=F([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:r.payload.issue})};var ac=e=>{let t,n,o=!1,r=!1,s=!1,i=()=>{let p=_n();if(d(p))return te.error(p.message);let{autoSync:v,userName:S,preferredEditor:N}=p.value;return!!(v&&S&&N)},c=async()=>{if(!o){if(r){s=!0;return}r=!0;try{await ir({repoRoot:e.repoRoot}),$t({type:"state",payload:await Lt({repoRoot:e.repoRoot})})}finally{r=!1,s&&(s=!1,c())}}},u=(p=750)=>{o||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(o)return;let p=_n();if(d(p))return te.error(p.message);let{autoSyncDebounceMs:v}=p.value;i()&&(t=setTimeout(()=>{c(),m()},v??15e3))};return m(),{scheduleSync:u,dispose:()=>{o=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as qp}from"ws";var Pe=(e,t)=>{e.send(JSON.stringify(t))},zn=async(e,t)=>Pe(e,{type:"state",payload:await Lt({repoRoot:t})}),et=async(e,t,n,o,r)=>{if(Pe(e,{type:o,payload:r}),d(r))return Pe(e,{type:"failed",payload:r.message});n(),zn(e,t)},dc=(e,t,{onStateChanged:n})=>{new qp({server:e,path:"/ws"}).on("connection",r=>{vi(r),r.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return zn(r,t);if(c==="sync"){let u=await ir({repoRoot:t});return Pe(r,{type:"sync:result",payload:u}),n(),zn(r,t)}if(c==="issue:comment:add"){let u=await ar({repoRoot:t,...i.payload});return et(r,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await dr({repoRoot:t,...i.payload});return Pe(r,{type:"issue:comment:delete:result",payload:u}),d(u)?Pe(r,{type:"failed",payload:u.message}):(n(),zn(r,t))}if(c==="issue:edit:description"){let u=await tc({repoRoot:t,...i.payload});return et(r,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await nc({repoRoot:t,...i.payload});return et(r,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await oc({repoRoot:t,...i.payload});return et(r,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await rc({repoRoot:t,...i.payload});return et(r,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await sc({repoRoot:t,...i.payload});return et(r,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await ic({repoRoot:t,...i.payload});return et(r,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Pe(r,{type:"issues",payload:await Xd({repoRoot:t})});if(c==="issues:create"){let u=await Jd({...i.payload,repoRoot:t});return Pe(r,{type:"issues:create:result",payload:u}),d(u)?$t({type:"failed",payload:u.message}):($t({type:"issue:created",payload:u.value}),n(),zn(r,t))}if(c==="issues:move"){if(!i.payload.position)return Pe(r,{type:"error",message:"Missing move position"});let u=await ec({...i.payload,repoRoot:t});return et(r,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Pe(r,{type:"error",message:"Missing issueId"});let u=await Qd({repoRoot:t,issueId:i.payload.issueId});return et(r,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Pe(r,{type:"error",message:"Missing issueId"});let u=await Zd({repoRoot:t,issueId:i.payload.issueId});return et(r,t,n,"issue:reopen:result",u)}return Pe(r,{type:"error",message:"Unknown message type"})}catch(i){return Pe(r,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Qp=Zt.dirname(Jp(import.meta.url)),Zp=process.env.IS_LOCAL==="true"?Zt.resolve(process.cwd(),"dist/gui"):Zt.join(Qp,"gui"),tt=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},eg=async e=>new Promise((t,n)=>{let o="";e.on("data",r=>{o+=r}),e.on("end",()=>{try{t(o?JSON.parse(o):{})}catch{n(new Error("Invalid JSON body"))}}),e.on("error",n)}),tg=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",cc=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),o=Zt.resolve(Zp),r=Zt.resolve(o,n),s=Zt.relative(o,r);if(s.startsWith("..")||Zt.isAbsolute(s))return tt(t,403,{isError:!0,message:"Forbidden"});try{let i=await Yp(r);return t.writeHead(200,{"content-type":tg(r)}),t.end(i)}catch{return tt(t,404,{isError:!0,message:`Not found: ${n}`})}},ng=async(e,t=3710)=>new Promise((n,o)=>{let r=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),r(0);return}o(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){o(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")};r(t)}),lc=async e=>{let t=Xp.createServer(async(r,s)=>{let i=new URL(r.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return tt(s,200,await Lt({repoRoot:e.repoRoot}));if(r.method==="POST"&&i.pathname==="/api/comments")try{let c=await eg(r);if(!c.issueId||!c.body?.trim())return tt(s,400,{isError:!0,message:"Missing issueId or body"});let u=await ar({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?tt(s,400,u):tt(s,200,await Lt({repoRoot:e.repoRoot}))}catch(c){return tt(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(r.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return tt(s,400,{isError:!0,message:"Missing comment id"});let u=await dr({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?tt(s,400,u):tt(s,200,await Lt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?cc("/",s):cc(i.pathname,s)});try{await ng(t)}catch(r){return a(r instanceof Error?`Unable to start GUI server: ${r.message}`:`Unable to start GUI server: ${String(r)}`)}let n=ac({repoRoot:e.repoRoot});dc(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let o=t.address();return!o||typeof o=="string"?(t.close(),a("Unable to resolve GUI server address")):l("Started GUI server",{url:`http://epiq.localhost:${o.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var uc=async e=>{let t=await lc({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${og.cyan(n)}`),Vs(n),l("Started GUI",{url:n})};import{Box as Bt}from"ink";import Q from"react";import{Box as ws,Text as Kn}from"ink";import je,{useEffect as rg,useMemo as sg}from"react";import{ulid as ig}from"ulid";var mc=({text:e,match:t,color:n,highlightColor:o=y.secondary,dimColor:r=!1})=>{if(!t)return je.createElement(Kn,{color:n,dimColor:r},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?je.createElement(Kn,{color:n,dimColor:r},e):je.createElement(Kn,{color:n,dimColor:r},e.slice(0,c),je.createElement(Kn,{backgroundColor:o,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},pc=ig(),ag=e=>`${e}`,dg=e=>{let{pendingNavTarget:t}=wt();if(!t)return[];let{breadCrumb:n,contextNode:o,selectedNode:r}=t,s=new Set(ae(h.NONE,{breadCrumb:n,contextNode:o,readOnly:g().readOnly,selectedNode:r}));return[...new Set(Object.values(h))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==h.PALETTE).map(i=>{let c=$o(i),u=er.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))},cg=e=>Y.text({id:pc,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),lg=(e,t,n)=>Y.text({id:ag(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Ms=[],ug=e=>{gc();let t=I.createNode(cg(g().rootNodeId));d(t)||!bt(t.value)||(Ms=[t.value,...e.map((n,o)=>lg(n,o,pc)).map(I.createNode).filter(Z).map(({value:n})=>n).filter(bt)],A.navigate({contextNode:t.value,selectedIndex:0}))},gc=()=>{let e=Ms.map(t=>t.id);Ms=[];for(let t of e)I.deleteNode(t)};function fc({width:e,height:t}){let o=Da().value.trim().toLowerCase(),r=sg(()=>dg(o),[o]);rg(()=>(ug(r),()=>{gc()}),[r]);let s=g().selectedIndex;return je.createElement(ws,{flexDirection:"column",width:e,height:t-2},je.createElement(Je,{height:t-4,itemHeight:3,selectedIndex:s},r.map((i,c)=>{let u=c===s,m=i.isAvailable?y.accent:y.secondary2,p=i.isAvailable?"":"[unavailable] ";return je.createElement(ws,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},je.createElement(Kn,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",je.createElement(mc,{text:Ci(i.command),match:o,color:m,dimColor:!i.isAvailable})),je.createElement(ws,{paddingLeft:2},je.createElement(mc,{text:p+i.description,match:o.length>=2?o:"",color:u&&i.isAvailable?y.primary:y.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Ng}from"ink";import Ls from"react";import Yn from"chalk";import{Box as Ps,Text as vc}from"ink";import qn,{useEffect as mg,useMemo as pg,useState as gg}from"react";var yc=Yn.hex(y.secondary),fg=Yn.inverse,vg=Yn.inverse.hex(y.secondary2),yg={hint:"",hints:[],overlap:0,remainder:""},xc=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),r=e.length-n.length;return e.slice(r,r+t.length)!==t?null:{start:r,end:r+t.length}},hg=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=re(t);return{bg:o=>Yn.bgHex(n).black(o),bgCursor:o=>Yn.bgHex(n).inverse.black(o)}}return Hr(t)},xg=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let o=xc({value:e,command:t});if(!o)return null;let s=e.slice(o.end).match(/^\s*/)?.[0].length??0,i=o.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},hc=()=>({value:ge.value,cursorPosition:ge.cursorPosition,commandIsPending:ge.commandIsPending,autoCompletion:ge.commandMeta.autoCompletion??yg,infoMessage:ge.commandMeta.infoMessage,validationStatus:ge.commandMeta.validity,command:ge.commandMeta.command,inputString:ge.commandMeta.inputString,modifier:ge.commandMeta.modifier}),Ig=(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,Ic=({width:e,mode:t})=>{let[n,o]=gg(hc());mg(()=>{let S=()=>{let E=hc();o(R=>Ig(R,E)?R:E)},N=ss(S);return S(),()=>{N()}},[]);let{value:r,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p}=n,v=pg(()=>{let S=Math.max(0,Math.min(s,r.length)),N=xc({value:r,command:m}),E=xg({value:r,command:m,modifier:p}),R=m?Hr(m):null,M=hg({command:m,modifier:p}),D=(le,be)=>{let en=N&&be>=N.start&&be<N.end,Ot=E&&be>=E.start&&be<E.end;return en&&R?R.fg(le):Ot&&M?M.bg(le):le},j=(le,be)=>{let en=N&&be>=N.start&&be<N.end,Ot=E&&be>=E.start&&be<E.end;return en&&R?R.fgCursor(le):Ot&&M?M.bgCursor(le):fg(le)},O=r.slice(0,S),k=r[S]??" ",Ne=S<r.length?r.slice(S+1):"",ft=Array.from(O).map((le,be)=>D(le,be)).join(""),vt=j(k,S),yt=Array.from(Ne).map((le,be)=>D(le,S+1+be)).join("");if(u.hint){let le=u.hint[u.overlap]??k;vt=vg(le),yt=yc(u.remainder.slice(1)+Ne)}return yc(t===f.PALETTE?"?":":")+ft+vt+yt},[r,s,u,m,p]);return qn.createElement(Ps,{flexDirection:"column",justifyContent:"flex-start"},qn.createElement(Ps,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},qn.createElement(Ps,null,qn.createElement(vc,null,v),i&&qn.createElement(vc,{wrap:"truncate",color:c?y.red:y.secondary2},` ${i} `))))};import{Box as bg,Text as Cg}from"ink";import bc from"react";var Sg=(e,t)=>{let n=[],o=0;for(let r of e){let i=(n.length>0?" | ":"").length+r.length;if(o+i>t-4)break;n.push(r),o+=i}return n},Cc=({width:e,availableHints:t})=>{let n=Sg(t,e).join(" | ");return bc.createElement(bg,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},bc.createElement(Cg,{color:y.secondary2},n.length?n:"\xA0"))};var Xn=({width:e,mode:t,availableHints:n})=>{let o=[],r=0;for(let s of n){let c=(o.length>0?" | ":"").length+s.length;if(r+c>e+2)break;o.push(s),r+=c}return Ls.createElement(Ng,null,t===f.COMMAND_LINE||t===f.PALETTE?Ls.createElement(Ic,{width:e,mode:t}):Ls.createElement(Cc,{width:e,mode:t,availableHints:n}))};import{Box as kt,Text as vn}from"ink";import Ie,{useEffect as Eg,useMemo as Rg}from"react";import{ulid as Sc}from"ulid";var lr=Sc(),Tg=()=>[...new Set([...g().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),o=t?.replace("[",""),r=n?.trim();return[o,r]}).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})),Ag=e=>Y.text({id:lr,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),wg=(e,t,n)=>Y.text({id:Sc(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),cr=[],Nc=()=>{let e=cr.filter(n=>n.id!==lr).map(n=>n.id),t=cr.filter(n=>n.id===lr).map(n=>n.id);cr=[];for(let n of[...e,...t])I.deleteNode(n)},Mg=e=>{Nc();let t=I.createNode(Ag(g().rootNodeId));if(d(t)||!bt(t.value))return logger.error("Could not attach help nodes");cr=[t.value,...e.map((n,o)=>wg(n,o,lr)).map(I.createNode).filter(Z).map(({value:n})=>n).filter(bt)],A.navigate({contextNode:t.value,selectedIndex:0})},Ec=({width:e,height:t})=>{let n=Rg(()=>Tg(),[]);Eg(()=>(Mg(n),()=>{Nc()}),[n]);let o=g().selectedIndex;return Ie.createElement(kt,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},Ie.createElement(kt,{paddingX:1,justifyContent:"center"},Ie.createElement(vn,{color:y.accent},"Help"),Ie.createElement(vn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),Ie.createElement(kt,{paddingX:1,marginTop:1},Ie.createElement(kt,{width:20,justifyContent:"flex-end"},Ie.createElement(vn,{color:y.secondary},"Key(s)")),Ie.createElement(kt,{flexGrow:1,width:40,paddingLeft:2},Ie.createElement(vn,{color:y.secondary},"Action"))),Ie.createElement(Je,{height:t-7,itemHeight:1,selectedIndex:o},n.map(({keys:r,action:s},i)=>{let c=i===o;return Ie.createElement(kt,{paddingX:1,key:`${r}-${s}-${i}`,flexDirection:"row"},Ie.createElement(kt,{width:20,justifyContent:"flex-end"},Ie.createElement(vn,{color:y.accent},r)),Ie.createElement(kt,{flexGrow:1,width:40,paddingLeft:2},Ie.createElement(vn,{color:c?y.primary:y.secondary2},s)))})))};import Pg from"chalk";import{Box as ur,Text as gt}from"ink";import Le from"react";var Rc=({width:e,height:t})=>Le.createElement(ur,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Le.createElement(gt,{color:y.accent,bold:!0},"Initialize project"),Le.createElement(gt,null,`This folder is not an ${Pg.hex(y.accent)("epiq")} project yet.`),Le.createElement(gt,{color:y.primary},"To start tracking issues here, we need to initialize a new",Le.createElement(gt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),Le.createElement(ur,{marginTop:1,flexDirection:"column"},Le.createElement(ur,null,Le.createElement(gt,{color:y.accent}," "),Le.createElement(gt,{color:y.primary},"Type "),Le.createElement(gt,{backgroundColor:y.secondary}," :init "))),Le.createElement(ur,{marginTop:1},Le.createElement(gt,{color:y.secondary2},"This will create, commit and push "),Le.createElement(gt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as mr,Text as nt}from"ink";import ce from"react";var Lg=({isDone:e,command:t,value:n})=>ce.createElement(mr,null,ce.createElement(nt,{color:y.accent,dimColor:e},e?" \u2714 ":" "),ce.createElement(nt,{dimColor:e},"Type "),ce.createElement(nt,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&ce.createElement(ce.Fragment,null,ce.createElement(nt,{dimColor:e}," "),ce.createElement(nt,{color:y.secondary,dimColor:e},"<"+n+">"))),kg=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function ks({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:o,userName:r,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Nt(),u=[{key:"username",done:o,command:":config username",value:r,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 ce.createElement(mr,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},ce.createElement(nt,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),ce.createElement(nt,null,"Let's get you started - it's a breeze."),ce.createElement(nt,{color:y.secondary2},"Remember - you can always search available commands by typing:",ce.createElement(nt,{color:y.accent}," ? ")),p&&ce.createElement(nt,{color:y.secondary2},p.message),ce.createElement(mr,{flexDirection:"column"},u.map((v,S)=>m===-1||S<=m?ce.createElement(mr,{key:v.key,marginBottom:1},ce.createElement(Lg,{isDone:v.done,command:v.command,value:v.done?kg(v.value):void 0})):null)))}import yr from"chalk";import{Box as vr,Text as Qn}from"ink";import ye from"react";import{Box as pr,Text as Tc}from"ink";import Dt from"react";var Dg=e=>(I.getTag(e)?.name??"").length+3,Fg=e=>(I.getContributor(e)?.name??"").length+3,Ac=({width:e})=>{let{viewMode:t}=_(),n=z(),{breadCrumb:o,contextNode:r,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[r.id]?.[s],u=it(c?.id??r.id,"TICKET"),m=Z(u)?u.value:void 0,p=m?.props.tags??[],v=m?.props.assignees??[],S=m?.parentNodeId?!$r(r.id,m.parentNodeId)&&t==="dense":!1,N=o.map((k,Ne)=>{let ft=Ne===o.length-1,vt=H(k.id),yt=ft?vt?.[s]?.title:void 0;return`${Ne?" / ":""}${k.title??""}${yt?` \u25B8 ${yt}`:""}`}).join(""),E=m?I.getCommentsByIssue(m.id):[],R=E.length?String(E.length).length+11:0,M=S?p.reduce((k,Ne)=>k+Dg(Ne),0)+v.reduce((k,Ne)=>k+Fg(Ne),0)+R:0,D=Math.max(0,e-M),j=N.substring(0,D),O=S?[...p.map(k=>Dt.createElement(pr,{key:`tag-${k}`,paddingLeft:1},Dt.createElement(gn,{id:k}))),...v.map(k=>Dt.createElement(pr,{key:`assignee-${k}`,paddingLeft:1},Dt.createElement(Rt,{id:k}))),E.length?Dt.createElement(pr,{key:"comments",paddingLeft:1},Dt.createElement(Tc,{color:y.accent},"[",E.length," comment",E.length===1?"":"s","]")):null]:[];return Dt.createElement(pr,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},Dt.createElement(Tc,{color:y.secondary2},j),O)};import{Box as Bg,Text as wc}from"ink";import gr from"react";var Ug=({filters:e})=>gr.createElement(Bg,{columnGap:1},gr.createElement(wc,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:o})=>gr.createElement(wc,{backgroundColor:"black",color:"white"},` ${n}${o}"${t}" `))),Mc=gr.memo(Ug);import{Box as Og,Text as fr}from"ink";import Jn from"react";function Pc(){let{eventLog:e,unappliedEvents:t}=z(),n=e.at(-1)?.id,o=Co(n??""),r=Z(o)?Fi(o.value):"INVALID DATE";return Jn.createElement(Og,{paddingLeft:1},Jn.createElement(fr,{backgroundColor:y.accent,color:y.secondary}," Readonly "),Jn.createElement(fr,{color:y.accent}," "+t.length+" edits ago at "+r+"."),Jn.createElement(fr,{color:y.accent}," Resume with "),Jn.createElement(fr,{backgroundColor:y.accent,color:y.secondary}," ",":peek now"," "))}import Ds from"chalk";import{Box as Wg,Text as Lc}from"ink";import Fs,{useEffect as $g,useState as _g}from"react";var jg=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],kc=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 o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`},Vg=(e,t,n)=>{let o=kc(e),r=kc(t);return Hg({r:o.r+(r.r-o.r)*n,g:o.g+(r.g-o.g)*n,b:o.b+(r.b-o.b)*n})},Gg=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),o=Math.floor(n),r=n-o,s=e[o],i=e[Math.min(o+1,e.length-1)];return Vg(s,i,r)};function Dc({syncStatus:e,autoSync:t}){let[n,o]=_g(0);$g(()=>{if(e.status!=="syncing"){o(0);return}let c=setInterval(()=>{o(u=>u+1)},50);return()=>clearInterval(c)},[e.status]);let r={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:Gg(jg,(Math.sin(n*.12)+1)/2)??""}[e.status];return Fs.createElement(Wg,null,Fs.createElement(Lc,null,Ds.hex(y.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Fs.createElement(Lc,null,Ds.hex(i)("\u25CF")+Ds.hex(y.secondary2).dim(` ${r[e.status].padEnd(4)} `)))}import Wc from"chalk";import{Text as $c}from"ink";import _c,{useEffect as Yg,useState as Xg}from"react";var yn="0.7.5";import Bs from"chalk";var zg="https://registry.npmjs.org/epiq/latest",Us=null,Fc=0,Kg=1e3*60*60*24,Bc=e=>e.replace(/^v/,""),qg=(e,t)=>{let n=Bc(e).split(".").map(Number),o=Bc(t).split(".").map(Number);for(let r=0;r<Math.max(n.length,o.length);r++){let s=n[r]??0,i=o[r]??0;if(s>i)return 1;if(s<i)return-1}return 0},Uc=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Us&&Date.now()-Fc<Kg)return Us;try{let t=await fetch(zg);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let o=(await t.json()).version??null,r={current:e,latest:o,updateAvailable:o?qg(o,e)>0:!1};return Us=r,Fc=Date.now(),r}catch{return{current:e,latest:null,updateAvailable:!1}}},Oc=(e,t)=>{let n=e.split("."),o=t.split("."),r=o.findIndex((s,i)=>s!=n[i]);return o.map((s,i)=>i>=r?Bs.hex(y.accent).dim(s):Bs.hex(y.secondary).dim(s)).join(Bs.hex(y.secondary2).dim("."))};function jc(){let[e,t]=Xg({current:yn,latest:null,updateAvailable:!1});return Yg(()=>{let n=!0;return Uc(yn).then(o=>{n&&t(o)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?_c.createElement($c,{dimColor:!0,color:y.secondary2},yn+" "):_c.createElement($c,null,Wc.hex(y.secondary2).dim(yn),Wc.hex(y.accent).dim(" \u2197 "),Oc(yn,e.latest))}function Zn({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:o,mode:r}=z(),{userName:s,preferredEditor:i,autoSync:c}=_(),u=64,m=process.stdout.columns-u-8;return ye.createElement(vr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},t?ye.createElement(Qn,null," "):r===f.PALETTE?ye.createElement(vr,null,ye.createElement(Qn,{color:y.accent},"Command Palette"),ye.createElement(Qn,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):ye.createElement(vr,{paddingLeft:1},e.length>0?ye.createElement(Mc,{filters:e}):ye.createElement(Ac,{width:m})),n==="live"?ye.createElement(vr,{columnGap:1,paddingRight:2,"max-width":u,overflow:"hidden",justifyContent:"flex-end"},ye.createElement(Dc,{autoSync:!!c,syncStatus:o}),ye.createElement(Qn,null,yr.hex(y.secondary2).dim("Mode: ")+yr.hex(y.secondary2).dim(r.padEnd(8," "))," "),ye.createElement(Hc,{icon:"@",value:s}),ye.createElement(Hc,{icon:"\u276F",value:i}),ye.createElement(jc,null)):"",n==="peek"?ye.createElement(Pc,null):"")}function Hc({icon:e,value:t}){return ye.createElement(Qn,null,yr.dim(e)+yr.hex(y.accent)(` ${t??"-"} `))}import{Box as Jg,Text as Qg}from"ink";import eo from"react";import{Box as hr,Text as Os}from"ink";import Ft from"react";function Ws(){let e=z(),t=e.nodes[e.rootNodeId],r=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?$(t?.id):[];return Ft.createElement(hr,{flexDirection:"column",height:r,padding:1,borderStyle:"round",borderColor:y.secondary,width:s},Ft.createElement(hr,{padding:1,paddingTop:0,paddingBottom:0},Ft.createElement(Os,null,"Select a board:")),Ft.createElement(hr,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,v=$(c.id).flatMap(({id:S})=>H(S)).length;return Ft.createElement(hr,{key:c.id??u},Ft.createElement(Os,{color:m?y.accent:y.secondary2},Ft.createElement(xe,{isSelected:m})),Ft.createElement(Os,{color:m?y.accent:y.secondary2},c.title," (",v," issues)",c.readonly?" \u{1F512}":""))})))}var Zg=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:o,viewMode:r,height:s,width:i})=>{let{renderedChildrenIndex:c}=z(),u=n.find(({context:S})=>S==="BOARD"),v=s-1-3;return eo.createElement(Jg,{flexDirection:"row"},e.context==="WORKSPACE"?eo.createElement(Ws,null):u?eo.createElement(Ko,{height:v,width:i,swimlanes:(c[u.id]??[]).filter(S=>S!==void 0&&Ct(S)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:r,mode:o}):eo.createElement(Qg,null))},Vc=eo.memo(Zg);import{useEffect as ef}from"react";var tf=e=>{ef(()=>{if(!e)return;let t,n=!1,o=()=>{if(n)return;let{autoSyncIntervalMs:r,userName:s,preferredEditor:i}=_();i&&s&&r&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=g();u==="default"&&!c&&Po(),o()},r))};return o(),()=>{n=!0,t&&clearTimeout(t)}},[e])},Gc=({autoSync:e})=>(tf(e),null);function $s({width:e,height:t}){let n=z(),{autoSync:o,viewMode:r}=Ai(),s=n.filters;if(n.mode===f.HELP)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Ec,{width:e,height:t}));if(n.mode===f.PALETTE)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{filters:s}),Q.createElement(fc,{width:e,height:t-2}),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Nt(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{hideBreadCrumb:!0,filters:s}),Q.createElement(ks,{height:t,width:e})),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{hideBreadCrumb:!0,filters:s}),Q.createElement(Rc,{height:t,width:e})),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Ee(n.breadCrumb??[],"BOARD");if(Z(m)){let p=m.value.id,v=$(p).length,S=3,N=Math.floor(e/S),E=Math.floor(e/Math.max(v,1));e=Math.min(E,N)*Math.max(v,S)}return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Gc,{autoSync:o}),Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{filters:s}),Q.createElement(Vc,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:r??"dense",mode:n.mode})),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}))}import nf from"readline";var xr,Ir,ot,of=new Set([x.MoveCursorLeft,x.EraseInputWord,x.MoveCursorLeftOfWord,x.MoveCursorRight,x.MoveCursorRightOfWord,x.NavToPreviousContainer,x.NavToNextContainer,x.NavPreviousItem,x.NavNextItem,x.SetViewDense,x.SetViewWide,x.Confirm,x.Exit,x.InitCommandLine,x.InitCommandPalette,x.ExitCommandLine,x.CaptureInput,x.EraseInput,x.EraseInputWord,x.HideHelp,x.ViewHelp,x.SetViewDense,x.SetViewWide,x.GetLastCommandFromHistory,x.GetNextCommandFromHistory,x.AutoCompleteCommand]),zc=async e=>{if(e.ctrl&&e.name==="c")return A.exit();let{actionIndex:t,mode:n,readOnly:o}=g(),r=Ba(e,n);if(!r||o&&!of.has(r))return;let s=t[n]?.[r];if(s?.action)try{await s.action(s,e)}catch(i){logger.error(i)}},rf=()=>async function(t,n){n.name!=="escape"&&(ot&&(clearTimeout(ot),ot=void 0),await zc(n))},sf=()=>async function(t){if(t.length===1&&t[0]===27){ot&&clearTimeout(ot),ot=setTimeout(()=>{zc({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),ot=void 0},25);return}ot&&(clearTimeout(ot),ot=void 0)};function Kc(){xr&&process.stdin.removeListener("keypress",xr),Ir&&process.stdin.removeListener("data",Ir),xr=rf(),Ir=sf(),nf.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Ir),process.stdin.on("keypress",xr)}async function qc(){try{let e=jn();Z(e)&&Fe(e.value);let t=He(process.cwd()),n=[];if(Z(t)){let s=We({repoRoot:t.value});if(d(s))return Kt(3,s.message);let i=tn(),c=await Wt({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return Kt(3,c.message);let u=await B({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=at(s.value);if(d(m))return Kt(3,m.message);n=m.value}let o=zt(n);if(d(o))return Kt(4,o.message);C({hasProjectDefinition:Z(t),hasInitializingEvents:!!n.length});let r=_s();return d(r)?Kt(6,r.message):(Kc(),l("Booted Epiq",void 0))}catch(e){return Kt(0,Ao(e))}}ld();var lf=`${Ut.bold("Epiq CLI")}
|
|
57
|
+
`));let Ot=Ue();if(d(Ot))return K(16,Ot.message);let{rootNodeId:Jc,nodes:Qc}=Ot.value,js=Qc[Jc];return js?(A.navigate({contextNode:js,selectedIndex:0}),C({hasProjectDefinition:!0,mode:f.DEFAULT}),l(vt,null)):K(16,"Unable to resolve initialized root node")};import{ulid as Ap}from"ulid";import{ulid as Tp}from"ulid";var yd=null,Pt=()=>structuredClone(yd),Hn=e=>{yd=e},hd=()=>{let{contextNode:e,selectedIndex:t}=g(),o=H(e.id)[t];return o?l("Resolved selected child",o):a("Target node not found")},Is=({id:e,parentId:t,position:n={at:"end"}})=>{let o=H(t).filter(r=>r.id!==e);return Ro(o,n)},xd=({id:e,parentId:t,position:n={at:"end"}})=>{let o=X();if(d(o))return a("Unable to resolve user ID");let r=Is({parentId:t,id:e,position:n});return d(r)?r:l("Created pending move state",{id:Tp(),...o.value,action:"move.node",payload:{id:e,parent:t,rank:r.value.rank}})},Id=e=>{Hn(e);let t=Mn(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function bs(e){let t=hd();if(d(t))return t;let{contextNode:n,nodes:o}=g();if(!n.parentNodeId)return a("Missing parent node id");let r=o[n.parentNodeId];if(!r)return a("Missing parent node");let s=H(r.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=xd({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Id(u.value)}function Cs(e){let t=hd();if(d(t))return t;let{contextNode:n,selectedIndex:o}=g(),s=H(n.id)[o+e];if(!s)return a("Missing sibling node");let i=xd({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Id(i.value)}var bd=()=>{let e=Pt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,o=g().nodes[n];if(!o)return a("Move parent not found");let r=H(n).findIndex(s=>s.id===t);return r===-1?a("Moved node not found among rendered children"):(A.navigate({contextNode:o,selectedIndex:r}),l("Synchronized navigation to moved node",null))},Jo=(e,t="Moved preview")=>{if(d(e))return e;let n=bd();return d(n)?n:(C({mode:f.MOVE}),l(t,null))},Cd=async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=q().commandMeta,{contextNode:n,selectedIndex:o}=g(),r=H(n.id)[o];if(!r)return C({mode:f.DEFAULT}),a("No move target");if(t==="start"){if(r.readonly)return a("Target node is read-only");if(o===-1)return a("No item selected");if(!r.parentNodeId)return a("Target has no parent");let s=H(r.parentNodeId),i=s.findIndex(({id:v})=>v===r.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=Is({parentId:r.parentNodeId,id:r.id,position:m});return d(p)?p:(Hn({id:Ap(),action:"move.node",payload:{id:r.id,parent:r.parentNodeId,rank:p.value.rank},...e.value}),C({mode:f.MOVE}),l("Move initialized",null))}if(t==="next")return Jo(Cs(1));if(t==="previous")return Jo(Cs(-1));if(t==="to-next")return Jo(bs(1));if(t==="to-previous")return Jo(bs(-1));if(t==="confirm"){let s=Pt();if(!s)return a("No pending move to confirm");let i=await Ve();if(d(i))return i;let c=F([s],i.value);if(d(c))return c;let u=bd();return d(u)?u:(Hn(null),C({mode:f.DEFAULT}),l("Moved item",null))}return t==="cancel"?(Hn(null),C({mode:f.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Zo}from"ulid";import{monotonicFactory as wp,ulid as Mp}from"ulid";var Pp=wp(),Qo=({name:e,parent:t,rank:n,user:{userId:o,userName:r}})=>{let s=Pp();return l("Created issue events",[{id:Mp(),userId:o,userName:r,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Sd=async(e,t)=>{let n=X();if(d(n))return a("Unable to resolve user ID");let o=await Ve();if(d(o))return o;let r=o.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=g(),u=m=>{let p=F([m],r);if(d(p))return p;let v=I.getNode(p.value[0].result.id);if(!v)return a("Created node not found");if(!v.parentNodeId)return p;let S=I.getNode(v.parentNodeId);return S?(A.navigate({contextNode:S,selectedIndex:I.getSiblings(v.parentNodeId).findIndex(({id:N})=>N===v.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let v=cn(p.id,n.value,r);return d(v)?v:u({id:Zo(),action:"add.board",payload:{id:Zo(),name:t.inputString,parent:p.id,rank:v.value},...n.value})}if(t.modifier==="swimlane"){let m=Ee(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=cn(m.value.id,n.value,r);return d(p)?p:u({id:Zo(),action:"add.swimlane",payload:{id:Zo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=$(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Ee(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let v=cn(p.id,n.value,r);if(d(v))return v;let S=Qo({name:t.inputString,parent:p.id,rank:v.value,user:n.value});if(d(S))return S;let N=S.value,E=F([...N],r);if(d(E))return E;if(!E.value[0])return a("Issue creation failed");let D=N.find(j=>j.action==="add.issue")?.payload.id;return D?(A.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===D)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Nd=async()=>{let e=Ee(g().breadCrumb,"BOARD");if(d(e))return e;let t=await xt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=We({repoRoot:t.value});if(d(n))throw new Error(n.message);let{modifier:o,inputString:r}=q().commandMeta;if(o==="now"){let R=at(n.value);if(d(R))return a(R.message);let M=Vn();if(d(M))return M;let j=Ht(R.value).filter(d);return j.length>0?a(j.map(O=>O.message).join(", ")):(C({mode:f.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),l("Peeking now",!0))}let s;if(o==="prev"){let R=g().eventLog.at(-1),M=Vr(R);if(M===null)return a("No previous event to peek");s=M}else if(o==="next"){let R=g().unappliedEvents.at(0),M=Vr(R);if(M===null)return a("No next event to peek");s=M+1}else{let R=Do(o||r);if(!R)return a("Invalid peek date");s=R.getTime()}let i=g(),c=e.value.id,u=_i(n.value,s);if(d(u))return a(u.message);let{appliedEvents:m,unappliedEvents:p}=u.value,v=Vn();if(d(v))return v;let N=Ht(m).filter(d);if(N.length>0)return Vn(),C(i),a(N.map(R=>R.message).join(", "));let E=g().nodes[c];return E?(A.navigate({contextNode:E,selectedIndex:0}),C({mode:f.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:p}),l("Peeking",!0)):(Vn(),C(i),a("Board did not exist at peek date"))};import Lp from"zod";var Ed=()=>{let e=q().commandMeta.inputString,t=Lp.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=mt({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),C({mode:f.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Rd=()=>{let e=q().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=ua(e),n=mt({autoSync:t});return d(n)?n:(Fe({autoSync:t}),C({mode:f.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Td=()=>{let e=q().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=mt({logLevel:e});return d(n)?n:(Fe({logLevel:e}),C({mode:f.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Ad=async()=>{W(""),C({mode:f.DEFAULT});let e=Ue();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 wo();return d(t)?(C({syncStatus:{msg:t.message,status:"failed"}}),t):(C({mode:f.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var kp=e=>e.action==="add.issue.comment",wd=e=>Object.values(g().tags).find(t=>t.name===e),Md=e=>Object.values(g().contributors).find(t=>t.name===e),pt=async()=>{let e=await Ve();return d(e)?e:l("Resolved persist root",e.value)},er=[{systemOnly:!0,intent:P.Move,description:"Internal move-state command",mode:f.COMMAND_LINE,action:Cd},{intent:P.Delete,description:"Delete the currently selected node",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Unable to resolve child to delete");let r=await pt();if(d(r))return r;if(o.context==="COMMENT"){let s=o.id,i=T(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!T(c))return a("Unable to resolve comment issue");let u=c.log?.filter(kp).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):F([{id:fe(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],r.value):a("Unable to resolve comment")}return F([{id:fe(),action:"delete.node",payload:{id:o.id},...e.value}],r.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:f.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=q().commandMeta,n=/(!=|=)/,[o]=e.split(n);if(!o||!(i=>ae(h.FILTER).map(c=>c.split(n)[0]).includes(i))(o))return a("Invalid filter modifier");let s={target:o,operator:"=",value:t.trim()};return ue(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:f.DEFAULT})),l("Filter updated",null)}},{intent:P.ViewHelp,description:"Open the help screen",mode:f.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:o}=g();return Mt({pendingNavTarget:{contextNode:e,breadCrumb:o,selectedIndex:t,selectedNode:n}}),C({mode:f.HELP}),l("Viewing help",null)}},{intent:P.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Unable to close issue, no target found");if(!T(o))return a("Cannot close in this context");let r=g().nodes[ie];if(!r)return a("Unable to locate closed swimlane");if(o.parentNodeId===r.id)return a("Issue is already closed");let s=await pt();if(d(s))return s;let i=s.value,c=Gt(r.id,o.id,{at:"end"},e.value,i);if(d(c))return c;let u=F([{id:fe(),action:"close.issue",payload:{id:o.id,parent:r.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Unable to reopen issue, no target found");let r=o.context==="TICKET"?l("Resolved ticket",o):it(o.id,"TICKET");if(d(r))return a("Cannot reopen in this context");let s=r.value,i=g().nodes[ie];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!T(s))return a("Target node is not issue");let c=Yo(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await pt();if(d(m))return m;let p=m.value,v=Gt(u.id,s.id,{at:"end"},e.value,p);if(d(v))return v;let S=F([{id:fe(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:v.value},...e.value}],p);return d(S)?S:l("Issue reopened",null)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Init,description:"Initialize Epiq in the current git repository",mode:f.COMMAND_LINE,action:vd},{intent:P.NewItem,description:"Create a new board, swimlane, or issue",mode:f.COMMAND_LINE,action:Sd,onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Rename,description:"itle] Rename the currently selected node",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),o=$(t.id)[n];if(!o)return a("Missing node");if(o.readonly)return a("Cannot rename readonly node");let r=Fa();if(!r)return a("Provide a title");let s=await pt();return d(s)?s:F([{id:fe(),action:"edit.title",payload:{id:o.id,name:r},...e.value}],s.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.UntagTicket,description:"Remove a tag from the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide a tag");let r=wd(o);if(!r)return a(`Tag "${o}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=it(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!T(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(r.id))return a("Issue is not tagged with that tag");let m=await pt();return d(m)?m:F([{id:fe(),action:"remove.issue.tag",payload:{id:c.id,tag:r.id},...e.value}],m.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.TagTicket,description:"Add or create a tag on the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide a tag");let{selectedNode:r}=g();if(!r)return a("Invalid tag target");let s=it(r.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!T(i))return a("Target node is not issue");let c=await pt();if(d(c))return c;let u=wd(o),m=u?.id??fe();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):F([...u?[]:[{id:fe(),action:"create.tag",payload:{id:m,name:o},...e.value}],{id:fe(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.AssignUserToTicket,description:"Assign a user to the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide an assignee");let{selectedIndex:r,contextNode:s}=g(),i=$(s.id)[r];if(!i)return a("Invalid assign target");let c=it(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!T(u))return a("Target node is not issue");let m=await pt();if(d(m))return m;let p=Md(o),v=p?.id??fe();return(u.props.assignees??[]).includes(v)?a("Assignee already assigned"):F([...p?[]:[{id:fe(),action:"create.contributor",payload:{id:v,name:o},...e.value}],{id:fe(),action:"add.issue.assignee",payload:{id:u.id,assignee:v},...e.value}],m.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:f.COMMAND_LINE,action:async()=>{let e=X();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=q().commandMeta,o=(t||n).trim();if(!o)return a("Provide an assignee to remove");let r=Md(o);if(!r)return a(`Assignee "${o}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=it(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!T(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(r.id))return a(`Issue is not assigned to "${o}"`);let m=await pt();return d(m)?m:F([{id:fe(),action:"remove.issue.assignee",payload:{id:c.id,assignee:r.id},...e.value}],m.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Comment,description:"Add a comment to the selected issue",mode:f.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>mn)return a(`Cannot exceed ${mn} characters`);let o=X();if(d(o))return a("Unable to resolve user ID");let{breadCrumb:r,selectedNode:s}=g(),i=Ee([...r,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let u=c.context==="TICKET"?l("Resolved ticket",c):it(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!T(m))return a("Target node is not issue");let p=await pt();return d(p)?p:F([{id:fe(),action:"add.issue.comment",payload:{id:fe(),issue:m.id,author:o.value.userId,md:n},...o.value}],p.value)},onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Sync,description:"Pull, commit, and push Epiq state",mode:f.COMMAND_LINE,action:Ad},{intent:P.Peek,description:"View board state at another point in time",mode:f.COMMAND_LINE,action:Nd},{intent:P.Export,description:"Export the current board layout to markdown",mode:f.COMMAND_LINE,action:async()=>{let e=await td();return d(e)?e:(C({mode:f.DEFAULT}),l("Export successful",!0))}},{intent:P.Exit,description:"Exit the application",mode:f.COMMAND_LINE,action:async()=>(A.exit(),l("Exit successful",!0))},{intent:P.Edit,description:"Edit title or description",mode:f.COMMAND_LINE,action:async(e,t)=>pd(t),onSuccess:()=>C({mode:f.DEFAULT})},{intent:P.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:f.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case se.USERNAME:{let{userId:o,preferredEditor:r,userName:s}=_(),i=n||s,c=o??fe();if(!i||!c)return a("Unable to resolve user name or id");let u=mt({userName:i,userId:c,preferredEditor:r??""});return d(u)?u:(Fe({userName:i,userId:c}),C({mode:f.DEFAULT}),l(`Username set to "${i}"`,null))}case se.EDITOR:{if(!n)return a("No editor provided");let o=mt({preferredEditor:n});return d(o)?o:(Fe({preferredEditor:n}),C({mode:f.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case se.VIEW:return n!=="wide"&&n!=="dense"?a("Invalid view mode"):(Fe({viewMode:n}),l(`View set to "${n}"`,null));case se.AUTOSYNC:return Rd();case se.LOG_LEVEL:return Td();case se.SYNC_DEBOUNCE_MS:return Ed();default:return a("Unknown config command")}}},{intent:P.Coffee,description:"Sponsor the development of Epiq!",mode:f.COMMAND_LINE,action:()=>{let e=q().commandMeta.modifier;return e==="custom"?ys("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):ys(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var Dp=new Set(["peek","filter","view-help"]),Ze=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:o,inputString:r}}=q();if(!t)return a("No command to confirm");if(!e&&n===Et.Invalid)return a("Invalid command");let s=$o(t);Ma();let{readOnly:i}=g();if(i&&!Dp.has(s))return Un({status:ht.Fail,message:"Command not available in readonly state",value:null});let c=er.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return Un({status:ht.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:r,modifier:o})}catch(m){return Un({status:ht.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?Un(u):(Pa({addToHistory:!e}),c.onSuccess?.(),_().autoSync&&Po(),u)};var tr=[{intent:x.Exit,mode:f.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(C({mode:f.COMMAND_LINE}),W("move cancel"),Ze({isForceExecutedBySystem:!0}))},{intent:x.InitMove,mode:f.DEFAULT,description:"[m] move (init/confirm)",action:()=>(C({mode:f.COMMAND_LINE}),W("move start"),Ze({isForceExecutedBySystem:!0}))},{intent:x.ConfirmMove,mode:f.MOVE,action:()=>(C({mode:f.COMMAND_LINE}),W("move confirm"),Ze({isForceExecutedBySystem:!0}))}],nr=[{intent:x.MovePreviousItem,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move previous"),Ze({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveNextItem,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move next"),Ze({isForceExecutedBySystem:!0})):a("No pending move")}],Pd=[{intent:x.MoveToNextContainer,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move to-next"),Ze({isForceExecutedBySystem:!0})):a("No pending move")},{intent:x.MoveToPreviousContainer,mode:f.MOVE,action:()=>Pt()?(C({mode:f.COMMAND_LINE}),W("move to-previous"),Ze({isForceExecutedBySystem:!0})):a("No pending move")}];var Ld={[w.WORKSPACE]:[...tr,...nr],[w.BOARD]:[...tr,...nr],[w.SWIMLANE]:[...tr,...nr,...Pd],[w.TICKET]:[],[w.FIELD]:[],[w.FIELD_LIST]:[],[w.TEXT]:[],[w.COMMENT]:[]};var kd=()=>{W("");let{pendingNavTarget:e}=wt();C({mode:f.DEFAULT}),e&&A.navigate(e),Mt({pendingNavTarget:void 0})},Dd=[{intent:x.ExitCommandLine,mode:f.HELP,action:()=>(kd(),l("Exiting help",null))},{intent:x.Exit,mode:f.HELP,action:()=>(kd(),l("Closed help",null))},{intent:x.NavPreviousItem,mode:f.HELP,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:x.NavNextItem,mode:f.HELP,action:()=>(A.navigateToNextItem(),l("Navigating to next help item",null))},{intent:x.NavToPreviousContainer,mode:f.HELP,action:()=>(A.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:x.NavToNextContainer,mode:f.HELP,action:()=>(A.navigateToNextContainer(),l("Navigating to next help container",null))}];var Fp=e=>{C({mode:f.COMMAND_LINE});let{pendingNavTarget:t}=wt();t&&A.navigate(t),Mt({pendingNavTarget:void 0}),W(`${e} `)},Fd=()=>{W("");let{pendingNavTarget:e}=wt();e&&A.navigate(e),Mt({pendingNavTarget:void 0}),C({mode:f.DEFAULT})},Bd=[{intent:x.InitCommandPalette,mode:f.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:o}=g();return Mt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:o}}),C({mode:f.PALETTE}),l("Opening command palette",null)}},{intent:x.Confirm,mode:f.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!bt(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?(Fp(t),l("Selected command",t)):l("No command selected",null)}},{intent:x.ExitCommandLine,mode:f.PALETTE,action:()=>(Fd(),l("Exiting palette",null))},{intent:x.Exit,mode:f.PALETTE,action:()=>(Fd(),l("Closed command palette",null))},{intent:x.NavPreviousItem,mode:f.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:x.NavNextItem,mode:f.PALETTE,action:()=>(A.navigateToNextItem(),l("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:f.PALETTE,action:()=>(A.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:f.PALETTE,action:()=>(A.navigateToNextContainer(),l("Navigating to next container",null))}];var Ud=[...Dd,...Bd,{intent:x.AddItem,mode:f.DEFAULT,description:"[n] new...",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.NEW} `),l("Adding new item",null))},{intent:x.Delete,mode:f.DEFAULT,description:"[d] delete",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.DELETE} `),l("Deleting item",null))},{intent:x.InitCommandLine,mode:f.DEFAULT,description:"[:] focus command line",action:()=>(C({mode:f.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:x.Confirm,mode:f.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!H(e?.id??"")?.length){if(e?.title===oe.DESCRIPTION)return C({mode:f.COMMAND_LINE}),W(`${h.EDIT} description `),l("Propose command",!0);if(e?.title===oe.ASSIGNEES)return C({mode:f.COMMAND_LINE}),W(`${h.ASSIGN} `),l("Propose command",!0);if(e?.title===oe.TAGS)return C({mode:f.COMMAND_LINE}),W(`${h.TAG} `),l("Propose command",!0);if(t.title===oe.DESCRIPTION&&e?.context==="TEXT")return C({mode:f.COMMAND_LINE}),W(`${h.EDIT} description `),l("Propose command",!0)}return A.enterChildNode(),l("Entering context",null)}},{intent:x.EditTitle,mode:f.DEFAULT,description:"[r] rename title",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:x.EditDescription,mode:f.DEFAULT,description:"[e] edit description",action:()=>(C({mode:f.COMMAND_LINE}),W(`${h.EDIT} description `),l("Exiting context",null))},{intent:x.Exit,mode:f.DEFAULT,description:"[q] exit context",action:()=>(A.enterParentNode(),l("Exiting context",null))},{intent:x.NavPreviousItem,mode:f.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:x.NavNextItem,mode:f.DEFAULT,action:()=>(A.navigateToNextItem(),l("Navigating to next item",null))},{intent:x.NavToPreviousContainer,mode:f.DEFAULT,action:()=>(A.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:x.NavToNextContainer,mode:f.DEFAULT,action:()=>(A.navigateToNextContainer(),l("Navigating to next container",null))}];var Bp=500,Up=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Od=e=>{let t=Up(e);t&&Wo(n=>(n+t).slice(0,Bp))};var Op=[f.COMMAND_LINE,f.PALETTE],Wp=e=>[{intent:x.MoveCursorLeft,mode:e,action:()=>(is(-1),l("Moving cursor left",null))},{intent:x.MoveCursorRight,mode:e,action:()=>(is(1),l("Moving cursor right",null))},{intent:x.MoveCursorLeftOfWord,mode:e,action:()=>(as("left"),l("Moving cursor left of word",null))},{intent:x.MoveCursorRightOfWord,mode:e,action:()=>(as("right"),l("Moving cursor right of word",null))},{intent:x.AutoCompleteCommand,mode:e,action:()=>(Wo((t,{remainder:n})=>{let o=n?t+n:t,r="";return o==="edit title "&&(r=g().selectedNode?.title??""),o+r}),l("Auto-completing command",null))},{intent:x.CaptureInput,mode:e,action:(t,{sequence:n})=>(Od(n??""),l("Capturing input",null))},{intent:x.EraseInput,mode:e,action:()=>(Aa(),l("Erasing input",null))},{intent:x.EraseInputWord,mode:e,action:()=>(wa(),l("Erasing input word",null))}],Wd=[{intent:x.Confirm,mode:f.COMMAND_LINE,action:()=>(Ze(),l("Executing command",null))},{intent:x.ViewHelp,mode:f.DEFAULT,action:()=>(C({mode:f.HELP}),l("Viewing help",null))},...Op.flatMap(Wp),{intent:x.ExitCommandLine,mode:f.COMMAND_LINE,action:()=>(C({mode:f.DEFAULT}),l("Exiting command line",null))},{intent:x.GetLastCommandFromHistory,mode:f.COMMAND_LINE,action:()=>(La(),l("Getting last command from history",null))},{intent:x.GetNextCommandFromHistory,mode:f.COMMAND_LINE,action:()=>(ka(),l("Getting next command from history",null))}];import jd from"chalk";var or=jd.dim.hex(y.secondary2)(": for command line"),$d="q to exit",_d=`${jd.hex(y.accent)("m")} to confirm`,Ss={[w.WORKSPACE]:[or],[w.BOARD]:[or],[w.BOARD+f.COMMAND_LINE]:[or],[w.SWIMLANE]:[or],[w.TICKET+f.HELP]:[$d],[w.SWIMLANE+f.HELP]:[$d],[w.TICKET]:[],[w.FIELD]:[],[w.SWIMLANE+f.MOVE]:[_d],[w.TICKET+f.MOVE]:[_d]};var Gn=e=>e.trim().toLocaleLowerCase(),$p=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},_p=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},Hd=(e,t)=>{let n=Gn(t.value);if(!n)return!0;switch(t.target){case"title":return Gn(e.title??"").includes(n);case"description":return Gn(e.props.description??"").includes(n);case"tag":return $p(e).map(Gn).some(r=>r.includes(n));case"assignee":return _p(e).map(Gn).some(r=>r.includes(n));default:return!0}};function Vd(e,t,n){let o=t[e];if(!o)return a("buildBreadCrumb(): current node not found");let r=[],s=o;for(;s&&(r.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=r[r.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(r.reverse(),l("Breadcrumb built",r))}var Gd=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 Qt,Ns,Es=new Set,zd=()=>{for(let e of Es)e()},Hp=e=>(Es.add(e),()=>Es.delete(e));function Kd(e){let{contextNodeId:t,mode:n,rootNodeId:o,nodes:r,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!o)return a("derive(): rootNode is missing");if(!r[o])return a("derive(): unable to find root node");let c=r[t];if(!c)return a("Unable to derive state, contextNode not found");let u=Vd(t,r,o);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,v=Ss[p+n]??Ss[p]??[],S=[...Ud,...Ld[p]??[],...Wd],N=Gd(S),E=Vp(r,s),R=E[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:v,availableActions:S,actionIndex:N,selectedNode:R,renderedChildrenIndex:E})}var g=()=>{if(!Qt)throw new Error("State not initialized. Call initWorkspaceState() first.");return Qt},Ue=()=>Qt?l("Retrieved state",Qt):a("State not initialized. Call initWorkspaceState() first.");function Pn(e){Ns=e;let t=He(process.cwd()),n=!1;if(!d(t)){let s=It(t.value);if(d(s))return a(s.message);n=!0}let o={readOnly:!1,filters:[],tags:{},contributors:{},mode:f.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{}},r=Kd(o);return d(r)?r:(Qt=r.value,zd(),l("State initialized",null))}function ue(e){let t=g(),n=e(t),o=Kd(n);return d(o)?a(o.message??"Unable to update state"):(Qt=o.value,zd(),l("State updated",null))}var C=e=>ue(t=>({...t,...e}));var z=()=>jp(Hp,g,g),Vp=(e,t)=>{let n={};for(let o of Object.values(e))T(o)&&t.length>0&&!t.every(r=>Hd(o,r))||!o.parentNodeId||o.isDeleted||((!o.parentNodeId||!n[o.parentNodeId])&&(n[o.parentNodeId]=[]),n[o.parentNodeId].push(o));for(let o of Object.keys(n))n[o].sort((r,s)=>{let i=e[r.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},$=e=>g()?.renderedChildrenIndex[e]??[],Vn=()=>Ns?Pn(Ns):a("Cannot reset state: no initial workspace found"),un=()=>Qt!==void 0;var Rs=e=>{un()&&(C({syncStatus:e}),$t({type:"sync-status",payload:e}))},rr=(e="Syncing...")=>{Rs({status:"syncing",msg:e})},sr=(e="Synced")=>{Rs({status:"synced",msg:e})},Ts=e=>{Rs({status:"failed",msg:e})},Oe=e=>(Ts(e),a(e));import{decodeTime as QA}from"ulid";var Gp=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=G("getRepoRootDir",await xt(e));if(d(n))return a(n.message);let o=n.value;logger.debug("[sync] repo root",o);let r=G("getStateBranchRoot",We({repoRoot:o}));if(d(r))return a(r.message);let s=r.value;logger.debug("[sync] state branch root",s);let i=G("ensureInitialCommit",await pi(o));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:o,stateBranchRoot:s,ensureUpstream:t});let c=G("bootstrapStateBranchStorage",await fi({repoRoot:o,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=G("hasInProgressGitOperation(stateBranchRoot)",await ao(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:o,stateBranchRoot:s});let m=G("ensureStateBranchLayout",li(o,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:o,stateBranchRoot:s,bootstrapped:c.value}),l("Sync preconditions satisfied",{repoRoot:o,stateBranchRoot:s,bootstrapped:c.value}))},zp=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 o=G("stageStateBranchOwnEventFile",await go({stateBranchRoot:t,eventFileName:n}));if(d(o))return a(o.message);let r=G("hasStagedChanges(after stage)",await ri(t));if(d(r))return a(r.message);if(logger.debug("[sync] state branch change check after stage result",{changed:r.value}),!r.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=G("createStateBranchSyncCommit",await gi({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}))},Mo=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");rr();let n=G("ensureSyncReady",await Gp({cwd:e,ensureUpstream:!0}));if(d(n))return Oe(n.message);let{repoRoot:o,stateBranchRoot:r,bootstrapped:s}=n.value,i=G("isDetachedHead(stateBranchRoot)",await si(r));if(d(i))return Oe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Oe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,v=G("getStateBranch",nn(o));if(d(v))return Oe(v.message);let S=v.value;logger.debug("[sync] resolved state branch",{stateBranch:S,stateBranchRoot:r});let N=G("commitOwnEventFileToStateBranch",await zp({repoRoot:o,stateBranchRoot:r,ownEventFileName:t}));if(d(N))return Oe(N.message);c=N.value.createdCommit,u=N.value.commitSha;let E=G("pullBranchRebaseIfPresent",await kr({cwd:r,branch:S}));if(d(E))return Oe(E.message);if(m=E.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:r});let R=G("pushStateBranch",await En({stateBranchRoot:r,repoRoot:o}));if(d(R)&&oi(R.message)){let M=G("pullBranchRebaseIfPresent(retry)",await kr({cwd:r,branch:S}));if(d(M))return Oe(M.message);m=m||M.value,R=G("pushStateBranch(retry)",await En({stateBranchRoot:r,repoRoot:o}))}if(d(R))return Oe(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:r});let R=G("git rev-parse HEAD",await B({args:["rev-parse","HEAD"],cwd:r}));if(d(R))return Oe(R.message);u=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return sr(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:o,stateBranchRoot:r,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var As=e=>{let t=He(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},we=async e=>{let t=As(e);if(d(t))return t;let n=We({repoRoot:t.value});if(d(n))return a(n.message);let o=tn(),r=await Wt({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:o.stateBranch});if(d(r))return a(r.message);let s=await B({cwd:n.value,args:["pull","--ff-only"]});d(s)&&te.info(3,s.message);let i=at(n.value);if(d(i))return a(i.message);let c=zt(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},Me=()=>{let e=jn();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")},_e=()=>{let e=Ue();return d(e)?a(e.message):e},qd=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:re(t.name)})),Yd=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:re(t.name)}));var Xd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=_e();if(d(n))return n;let o=Object.values(n.value.nodes).filter(T).filter(r=>e.includeClosed||r.parentNodeId!==ie).map(r=>({id:r.id,title:St(r.title),description:r.props.description??"",parentNodeId:r.parentNodeId,isClosed:r.parentNodeId===ie,readonly:!!r.readonly,tags:qd(r),assignees:Yd(r)}));return l("Listed issues",o)},Jd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=cn(e.parentId,n.value,t.value.stateBranchRoot);if(d(o))return o;let r=Qo({name:e.title,parent:e.parentId,user:n.value,rank:o.value});if(d(r))return r;let s=r.value,i=F([...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")},Qd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=Gt(ie,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(o))return o;let r={id:ve(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:ie,rank:o.value}},s=F([r],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},Zd=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Target node is not issue");if(r.parentNodeId!==ie)return a("Issue is not closed");let s=Yo(r);if(!s)return a("Unable to resolve previous parent from issue history");if(s===ie)return a("Previous parent resolves to closed swimlane");let i=o.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=Gt(i.id,r.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:ve(),...n.value,action:"reopen.issue",payload:{id:r.id,parent:i.id,rank:c.value}},m=F([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:r.id,parentId:i.id})},ec=async e=>{let t=As(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=We({repoRoot:t.value});if(d(o))return o;let r=at(o.value);if(d(r))return r;let s=zt(r.value);if(d(s))return s;let i=Gt(e.parentId,e.issueId,e.position??{at:"end"},n.value,o.value);if(d(i))return i;let c={id:ve(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=F([c],o.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})},ir=async(e={})=>{rr();let t=As(e.repoRoot);if(d(t))return a("Sync failed");let n=Me();if(d(n))return n;let o=await Mo({cwd:t.value,ownEventFileName:Vt(n.value)});return d(o)?(Ts(o.message),o):(sr(),l("Synced",o.value))};var Lt=async(e={})=>{let t=await we(e.repoRoot);if(d(t))return t;let n=_e();if(d(n))return n;let o=Object.values(n.value.nodes),r=o.filter(m=>vo(m)&&!m.isDeleted),s=new Map,i=new Map;for(let m of o)if(!m.isDeleted){if(Ct(m)&&m.parentNodeId){let p=s.get(m.parentNodeId)??[];p.push(m),s.set(m.parentNodeId,p)}if(T(m)&&m.parentNodeId){let p=i.get(m.parentNodeId)??[];p.push(m),i.set(m.parentNodeId,p)}}let c=jn();if(d(c))return c;let u={};for(let m of o.filter(T))m.isDeleted||(u[m.id]=I.getCommentsByIssue(m.id).map(p=>{let v=I.getContributor(p.authorId);return{id:p.id,issueId:p.issue,body:p.md,author:{id:p.authorId,name:v?.name??"Unknown",color:re(v?.name??p.authorId)},createdAt:Kp(p.id)}}));return l("Retrieved Epiq GUI state",{boards:r.sort((m,p)=>m.rank.localeCompare(p.rank)).map(m=>({id: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,S)=>v.rank.localeCompare(S.rank)).map(v=>({id:v.id,title:St(v.title),description:v.props.description??"",readonly:!!v.readonly,tags:qd(v),assignees:Yd(v),parentNodeId:v.parentNodeId,isClosed:v.parentNodeId===ie})),parentNodeId:p.parentNodeId}))})),tags:Object.values(n.value.tags).map(m=>({...m,color:re(m.name)})),contributors:Object.values(n.value.contributors).map(m=>({...m,color:re(m.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:re(c.value.userName??"")},commentsByIssueId:u})},tc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Edit target must be an issue");if(r.readonly)return a("Cannot edit readonly issue");let s=r.props.description??"";if(s===e.description)return l("No changes made",{id:e.issueId,description:s});let i={id:ve(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=F([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},nc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Edit target must be an issue");if(r.readonly)return a("Cannot edit readonly issue");let s=St(e.title);if(!s.trim())return a("Issue title cannot be empty");if(r.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:ve(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=F([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},oc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Tag target must be an issue");if(r.readonly)return a("Cannot tag readonly issue");let s=St(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(o.value.tags).find(p=>p.name===s),c=i?.id??ve(),u=[...i?[]:[{id:ve(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:ve(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=F(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},rc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Untag target must be an issue");if(r.readonly)return a("Cannot untag readonly issue");if(!o.value.tags[e.tagId])return a("Tag not found");let s={id:ve(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=F([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},sc=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Assign target must be an issue");if(r.readonly)return a("Cannot assign readonly issue");let s=St(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(o.value.contributors).find(p=>p.name===s),c=i?.id??ve(),u=[...i?[]:[{id:ve(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:ve(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=F(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},ic=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Unassign target must be an issue");if(r.readonly)return a("Cannot unassign readonly issue");if(!o.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:ve(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=F([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},ar=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.nodes[e.issueId];if(!r)return a("Issue not found");if(!T(r))return a("Comment target must be an issue");if(r.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=ve(),c={id:ve(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=F([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},dr=async e=>{let t=await we(e.repoRoot);if(d(t))return t;let n=Me();if(d(n))return n;let o=_e();if(d(o))return o;let r=o.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!r)return a("Unable to resolve comment");if(r.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=o.value.nodes[r.payload.issue];if(!s)return a("Issue not found");if(!T(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(o.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return l("Comment already deleted",{id:e.commentId,issueId:r.payload.issue});let c={id:ve(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:r.payload.issue}},u=F([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:r.payload.issue})};var ac=e=>{let t,n,o=!1,r=!1,s=!1,i=()=>{let p=_n();if(d(p))return te.error(p.message);let{autoSync:v,userName:S,preferredEditor:N}=p.value;return!!(v&&S&&N)},c=async()=>{if(!o){if(r){s=!0;return}r=!0;try{await ir({repoRoot:e.repoRoot}),$t({type:"state",payload:await Lt({repoRoot:e.repoRoot})})}finally{r=!1,s&&(s=!1,c())}}},u=(p=750)=>{o||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(o)return;let p=_n();if(d(p))return te.error(p.message);let{autoSyncDebounceMs:v}=p.value;i()&&(t=setTimeout(()=>{c(),m()},v??15e3))};return m(),{scheduleSync:u,dispose:()=>{o=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as qp}from"ws";var Pe=(e,t)=>{e.send(JSON.stringify(t))},zn=async(e,t)=>Pe(e,{type:"state",payload:await Lt({repoRoot:t})}),et=async(e,t,n,o,r)=>{if(Pe(e,{type:o,payload:r}),d(r))return Pe(e,{type:"failed",payload:r.message});n(),zn(e,t)},dc=(e,t,{onStateChanged:n})=>{new qp({server:e,path:"/ws"}).on("connection",r=>{vi(r),r.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return zn(r,t);if(c==="sync"){let u=await ir({repoRoot:t});return Pe(r,{type:"sync:result",payload:u}),n(),zn(r,t)}if(c==="issue:comment:add"){let u=await ar({repoRoot:t,...i.payload});return et(r,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await dr({repoRoot:t,...i.payload});return Pe(r,{type:"issue:comment:delete:result",payload:u}),d(u)?Pe(r,{type:"failed",payload:u.message}):(n(),zn(r,t))}if(c==="issue:edit:description"){let u=await tc({repoRoot:t,...i.payload});return et(r,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await nc({repoRoot:t,...i.payload});return et(r,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await oc({repoRoot:t,...i.payload});return et(r,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await rc({repoRoot:t,...i.payload});return et(r,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await sc({repoRoot:t,...i.payload});return et(r,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await ic({repoRoot:t,...i.payload});return et(r,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Pe(r,{type:"issues",payload:await Xd({repoRoot:t})});if(c==="issues:create"){let u=await Jd({...i.payload,repoRoot:t});return Pe(r,{type:"issues:create:result",payload:u}),d(u)?$t({type:"failed",payload:u.message}):($t({type:"issue:created",payload:u.value}),n(),zn(r,t))}if(c==="issues:move"){if(!i.payload.position)return Pe(r,{type:"error",message:"Missing move position"});let u=await ec({...i.payload,repoRoot:t});return et(r,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Pe(r,{type:"error",message:"Missing issueId"});let u=await Qd({repoRoot:t,issueId:i.payload.issueId});return et(r,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Pe(r,{type:"error",message:"Missing issueId"});let u=await Zd({repoRoot:t,issueId:i.payload.issueId});return et(r,t,n,"issue:reopen:result",u)}return Pe(r,{type:"error",message:"Unknown message type"})}catch(i){return Pe(r,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Qp=Zt.dirname(Jp(import.meta.url)),Zp=process.env.IS_LOCAL==="true"?Zt.resolve(process.cwd(),"dist/gui"):Zt.join(Qp,"gui"),tt=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},eg=async e=>new Promise((t,n)=>{let o="";e.on("data",r=>{o+=r}),e.on("end",()=>{try{t(o?JSON.parse(o):{})}catch{n(new Error("Invalid JSON body"))}}),e.on("error",n)}),tg=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",cc=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),o=Zt.resolve(Zp),r=Zt.resolve(o,n),s=Zt.relative(o,r);if(s.startsWith("..")||Zt.isAbsolute(s))return tt(t,403,{isError:!0,message:"Forbidden"});try{let i=await Yp(r);return t.writeHead(200,{"content-type":tg(r)}),t.end(i)}catch{return tt(t,404,{isError:!0,message:`Not found: ${n}`})}},ng=async(e,t=3710)=>new Promise((n,o)=>{let r=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),r(0);return}o(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){o(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")};r(t)}),lc=async e=>{let t=Xp.createServer(async(r,s)=>{let i=new URL(r.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return tt(s,200,await Lt({repoRoot:e.repoRoot}));if(r.method==="POST"&&i.pathname==="/api/comments")try{let c=await eg(r);if(!c.issueId||!c.body?.trim())return tt(s,400,{isError:!0,message:"Missing issueId or body"});let u=await ar({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?tt(s,400,u):tt(s,200,await Lt({repoRoot:e.repoRoot}))}catch(c){return tt(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(r.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return tt(s,400,{isError:!0,message:"Missing comment id"});let u=await dr({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?tt(s,400,u):tt(s,200,await Lt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?cc("/",s):cc(i.pathname,s)});try{await ng(t)}catch(r){return a(r instanceof Error?`Unable to start GUI server: ${r.message}`:`Unable to start GUI server: ${String(r)}`)}let n=ac({repoRoot:e.repoRoot});dc(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let o=t.address();return!o||typeof o=="string"?(t.close(),a("Unable to resolve GUI server address")):l("Started GUI server",{url:`http://epiq.localhost:${o.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var uc=async e=>{let t=await lc({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${og.cyan(n)}`),Vs(n),l("Started GUI",{url:n})};import{Box as Bt}from"ink";import Q from"react";import{Box as ws,Text as Kn}from"ink";import je,{useEffect as rg,useMemo as sg}from"react";import{ulid as ig}from"ulid";var mc=({text:e,match:t,color:n,highlightColor:o=y.secondary,dimColor:r=!1})=>{if(!t)return je.createElement(Kn,{color:n,dimColor:r},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?je.createElement(Kn,{color:n,dimColor:r},e):je.createElement(Kn,{color:n,dimColor:r},e.slice(0,c),je.createElement(Kn,{backgroundColor:o,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},pc=ig(),ag=e=>`${e}`,dg=e=>{let{pendingNavTarget:t}=wt();if(!t)return[];let{breadCrumb:n,contextNode:o,selectedNode:r}=t,s=new Set(ae(h.NONE,{breadCrumb:n,contextNode:o,readOnly:g().readOnly,selectedNode:r}));return[...new Set(Object.values(h))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==h.PALETTE).map(i=>{let c=$o(i),u=er.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))},cg=e=>Y.text({id:pc,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),lg=(e,t,n)=>Y.text({id:ag(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Ms=[],ug=e=>{gc();let t=I.createNode(cg(g().rootNodeId));d(t)||!bt(t.value)||(Ms=[t.value,...e.map((n,o)=>lg(n,o,pc)).map(I.createNode).filter(Z).map(({value:n})=>n).filter(bt)],A.navigate({contextNode:t.value,selectedIndex:0}))},gc=()=>{let e=Ms.map(t=>t.id);Ms=[];for(let t of e)I.deleteNode(t)};function fc({width:e,height:t}){let o=Da().value.trim().toLowerCase(),r=sg(()=>dg(o),[o]);rg(()=>(ug(r),()=>{gc()}),[r]);let s=g().selectedIndex;return je.createElement(ws,{flexDirection:"column",width:e,height:t-2},je.createElement(Je,{height:t-4,itemHeight:3,selectedIndex:s},r.map((i,c)=>{let u=c===s,m=i.isAvailable?y.accent:y.secondary2,p=i.isAvailable?"":"[unavailable] ";return je.createElement(ws,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},je.createElement(Kn,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",je.createElement(mc,{text:Ci(i.command),match:o,color:m,dimColor:!i.isAvailable})),je.createElement(ws,{paddingLeft:2},je.createElement(mc,{text:p+i.description,match:o.length>=2?o:"",color:u&&i.isAvailable?y.primary:y.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Ng}from"ink";import Ls from"react";import Yn from"chalk";import{Box as Ps,Text as vc}from"ink";import qn,{useEffect as mg,useMemo as pg,useState as gg}from"react";var yc=Yn.hex(y.secondary),fg=Yn.inverse,vg=Yn.inverse.hex(y.secondary2),yg={hint:"",hints:[],overlap:0,remainder:""},xc=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),r=e.length-n.length;return e.slice(r,r+t.length)!==t?null:{start:r,end:r+t.length}},hg=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=re(t);return{bg:o=>Yn.bgHex(n).black(o),bgCursor:o=>Yn.bgHex(n).inverse.black(o)}}return Hr(t)},xg=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let o=xc({value:e,command:t});if(!o)return null;let s=e.slice(o.end).match(/^\s*/)?.[0].length??0,i=o.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},hc=()=>({value:ge.value,cursorPosition:ge.cursorPosition,commandIsPending:ge.commandIsPending,autoCompletion:ge.commandMeta.autoCompletion??yg,infoMessage:ge.commandMeta.infoMessage,validationStatus:ge.commandMeta.validity,command:ge.commandMeta.command,inputString:ge.commandMeta.inputString,modifier:ge.commandMeta.modifier}),Ig=(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,Ic=({width:e,mode:t})=>{let[n,o]=gg(hc());mg(()=>{let S=()=>{let E=hc();o(R=>Ig(R,E)?R:E)},N=ss(S);return S(),()=>{N()}},[]);let{value:r,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p}=n,v=pg(()=>{let S=Math.max(0,Math.min(s,r.length)),N=xc({value:r,command:m}),E=xg({value:r,command:m,modifier:p}),R=m?Hr(m):null,M=hg({command:m,modifier:p}),D=(le,be)=>{let en=N&&be>=N.start&&be<N.end,Ot=E&&be>=E.start&&be<E.end;return en&&R?R.fg(le):Ot&&M?M.bg(le):le},j=(le,be)=>{let en=N&&be>=N.start&&be<N.end,Ot=E&&be>=E.start&&be<E.end;return en&&R?R.fgCursor(le):Ot&&M?M.bgCursor(le):fg(le)},O=r.slice(0,S),k=r[S]??" ",Ne=S<r.length?r.slice(S+1):"",ft=Array.from(O).map((le,be)=>D(le,be)).join(""),vt=j(k,S),yt=Array.from(Ne).map((le,be)=>D(le,S+1+be)).join("");if(u.hint){let le=u.hint[u.overlap]??k;vt=vg(le),yt=yc(u.remainder.slice(1)+Ne)}return yc(t===f.PALETTE?"?":":")+ft+vt+yt},[r,s,u,m,p]);return qn.createElement(Ps,{flexDirection:"column",justifyContent:"flex-start"},qn.createElement(Ps,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},qn.createElement(Ps,null,qn.createElement(vc,null,v),i&&qn.createElement(vc,{wrap:"truncate",color:c?y.red:y.secondary2},` ${i} `))))};import{Box as bg,Text as Cg}from"ink";import bc from"react";var Sg=(e,t)=>{let n=[],o=0;for(let r of e){let i=(n.length>0?" | ":"").length+r.length;if(o+i>t-4)break;n.push(r),o+=i}return n},Cc=({width:e,availableHints:t})=>{let n=Sg(t,e).join(" | ");return bc.createElement(bg,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},bc.createElement(Cg,{color:y.secondary2},n.length?n:"\xA0"))};var Xn=({width:e,mode:t,availableHints:n})=>{let o=[],r=0;for(let s of n){let c=(o.length>0?" | ":"").length+s.length;if(r+c>e+2)break;o.push(s),r+=c}return Ls.createElement(Ng,null,t===f.COMMAND_LINE||t===f.PALETTE?Ls.createElement(Ic,{width:e,mode:t}):Ls.createElement(Cc,{width:e,mode:t,availableHints:n}))};import{Box as kt,Text as vn}from"ink";import Ie,{useEffect as Eg,useMemo as Rg}from"react";import{ulid as Sc}from"ulid";var lr=Sc(),Tg=()=>[...new Set([...g().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),o=t?.replace("[",""),r=n?.trim();return[o,r]}).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})),Ag=e=>Y.text({id:lr,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),wg=(e,t,n)=>Y.text({id:Sc(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),cr=[],Nc=()=>{let e=cr.filter(n=>n.id!==lr).map(n=>n.id),t=cr.filter(n=>n.id===lr).map(n=>n.id);cr=[];for(let n of[...e,...t])I.deleteNode(n)},Mg=e=>{Nc();let t=I.createNode(Ag(g().rootNodeId));if(d(t)||!bt(t.value))return logger.error("Could not attach help nodes");cr=[t.value,...e.map((n,o)=>wg(n,o,lr)).map(I.createNode).filter(Z).map(({value:n})=>n).filter(bt)],A.navigate({contextNode:t.value,selectedIndex:0})},Ec=({width:e,height:t})=>{let n=Rg(()=>Tg(),[]);Eg(()=>(Mg(n),()=>{Nc()}),[n]);let o=g().selectedIndex;return Ie.createElement(kt,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},Ie.createElement(kt,{paddingX:1,justifyContent:"center"},Ie.createElement(vn,{color:y.accent},"Help"),Ie.createElement(vn,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),Ie.createElement(kt,{paddingX:1,marginTop:1},Ie.createElement(kt,{width:20,justifyContent:"flex-end"},Ie.createElement(vn,{color:y.secondary},"Key(s)")),Ie.createElement(kt,{flexGrow:1,width:40,paddingLeft:2},Ie.createElement(vn,{color:y.secondary},"Action"))),Ie.createElement(Je,{height:t-7,itemHeight:1,selectedIndex:o},n.map(({keys:r,action:s},i)=>{let c=i===o;return Ie.createElement(kt,{paddingX:1,key:`${r}-${s}-${i}`,flexDirection:"row"},Ie.createElement(kt,{width:20,justifyContent:"flex-end"},Ie.createElement(vn,{color:y.accent},r)),Ie.createElement(kt,{flexGrow:1,width:40,paddingLeft:2},Ie.createElement(vn,{color:c?y.primary:y.secondary2},s)))})))};import Pg from"chalk";import{Box as ur,Text as gt}from"ink";import Le from"react";var Rc=({width:e,height:t})=>Le.createElement(ur,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},Le.createElement(gt,{color:y.accent,bold:!0},"Initialize project"),Le.createElement(gt,null,`This folder is not an ${Pg.hex(y.accent)("epiq")} project yet.`),Le.createElement(gt,{color:y.primary},"To start tracking issues here, we need to initialize a new",Le.createElement(gt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),Le.createElement(ur,{marginTop:1,flexDirection:"column"},Le.createElement(ur,null,Le.createElement(gt,{color:y.accent}," "),Le.createElement(gt,{color:y.primary},"Type "),Le.createElement(gt,{backgroundColor:y.secondary}," :init "))),Le.createElement(ur,{marginTop:1},Le.createElement(gt,{color:y.secondary2},"This will create, commit and push "),Le.createElement(gt,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as mr,Text as nt}from"ink";import ce from"react";var Lg=({isDone:e,command:t,value:n})=>ce.createElement(mr,null,ce.createElement(nt,{color:y.accent,dimColor:e},e?" \u2714 ":" "),ce.createElement(nt,{dimColor:e},"Type "),ce.createElement(nt,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&ce.createElement(ce.Fragment,null,ce.createElement(nt,{dimColor:e}," "),ce.createElement(nt,{color:y.secondary,dimColor:e},"<"+n+">"))),kg=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function ks({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:o,userName:r,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Nt(),u=[{key:"username",done:o,command:":config username",value:r,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 ce.createElement(mr,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},ce.createElement(nt,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),ce.createElement(nt,null,"Let's get you started - it's a breeze."),ce.createElement(nt,{color:y.secondary2},"Remember - you can always search available commands by typing:",ce.createElement(nt,{color:y.accent}," ? ")),p&&ce.createElement(nt,{color:y.secondary2},p.message),ce.createElement(mr,{flexDirection:"column"},u.map((v,S)=>m===-1||S<=m?ce.createElement(mr,{key:v.key,marginBottom:1},ce.createElement(Lg,{isDone:v.done,command:v.command,value:v.done?kg(v.value):void 0})):null)))}import yr from"chalk";import{Box as vr,Text as Qn}from"ink";import ye from"react";import{Box as pr,Text as Tc}from"ink";import Dt from"react";var Dg=e=>(I.getTag(e)?.name??"").length+3,Fg=e=>(I.getContributor(e)?.name??"").length+3,Ac=({width:e})=>{let{viewMode:t}=_(),n=z(),{breadCrumb:o,contextNode:r,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[r.id]?.[s],u=it(c?.id??r.id,"TICKET"),m=Z(u)?u.value:void 0,p=m?.props.tags??[],v=m?.props.assignees??[],S=m?.parentNodeId?!$r(r.id,m.parentNodeId)&&t==="dense":!1,N=o.map((k,Ne)=>{let ft=Ne===o.length-1,vt=H(k.id),yt=ft?vt?.[s]?.title:void 0;return`${Ne?" / ":""}${k.title??""}${yt?` \u25B8 ${yt}`:""}`}).join(""),E=m?I.getCommentsByIssue(m.id):[],R=E.length?String(E.length).length+11:0,M=S?p.reduce((k,Ne)=>k+Dg(Ne),0)+v.reduce((k,Ne)=>k+Fg(Ne),0)+R:0,D=Math.max(0,e-M),j=N.substring(0,D),O=S?[...p.map(k=>Dt.createElement(pr,{key:`tag-${k}`,paddingLeft:1},Dt.createElement(gn,{id:k}))),...v.map(k=>Dt.createElement(pr,{key:`assignee-${k}`,paddingLeft:1},Dt.createElement(Rt,{id:k}))),E.length?Dt.createElement(pr,{key:"comments",paddingLeft:1},Dt.createElement(Tc,{color:y.accent},"[",E.length," comment",E.length===1?"":"s","]")):null]:[];return Dt.createElement(pr,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},Dt.createElement(Tc,{color:y.secondary2},j),O)};import{Box as Bg,Text as wc}from"ink";import gr from"react";var Ug=({filters:e})=>gr.createElement(Bg,{columnGap:1},gr.createElement(wc,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:o})=>gr.createElement(wc,{backgroundColor:"black",color:"white"},` ${n}${o}"${t}" `))),Mc=gr.memo(Ug);import{Box as Og,Text as fr}from"ink";import Jn from"react";function Pc(){let{eventLog:e,unappliedEvents:t}=z(),n=e.at(-1)?.id,o=Co(n??""),r=Z(o)?Fi(o.value):"INVALID DATE";return Jn.createElement(Og,{paddingLeft:1},Jn.createElement(fr,{backgroundColor:y.accent,color:y.secondary}," Readonly "),Jn.createElement(fr,{color:y.accent}," "+t.length+" edits ago at "+r+"."),Jn.createElement(fr,{color:y.accent}," Resume with "),Jn.createElement(fr,{backgroundColor:y.accent,color:y.secondary}," ",":peek now"," "))}import Ds from"chalk";import{Box as Wg,Text as Lc}from"ink";import Fs,{useEffect as $g,useState as _g}from"react";var jg=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],kc=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 o=r=>Math.round(Math.max(0,Math.min(255,r))).toString(16).padStart(2,"0");return`#${o(e)}${o(t)}${o(n)}`},Vg=(e,t,n)=>{let o=kc(e),r=kc(t);return Hg({r:o.r+(r.r-o.r)*n,g:o.g+(r.g-o.g)*n,b:o.b+(r.b-o.b)*n})},Gg=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),o=Math.floor(n),r=n-o,s=e[o],i=e[Math.min(o+1,e.length-1)];return Vg(s,i,r)};function Dc({syncStatus:e,autoSync:t}){let[n,o]=_g(0);$g(()=>{if(e.status!=="syncing"){o(0);return}let c=setInterval(()=>{o(u=>u+1)},50);return()=>clearInterval(c)},[e.status]);let r={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:Gg(jg,(Math.sin(n*.12)+1)/2)??""}[e.status];return Fs.createElement(Wg,null,Fs.createElement(Lc,null,Ds.hex(y.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Fs.createElement(Lc,null,Ds.hex(i)("\u25CF")+Ds.hex(y.secondary2).dim(` ${r[e.status].padEnd(4)} `)))}import Wc from"chalk";import{Text as $c}from"ink";import _c,{useEffect as Yg,useState as Xg}from"react";var yn="0.7.7";import Bs from"chalk";var zg="https://registry.npmjs.org/epiq/latest",Us=null,Fc=0,Kg=1e3*60*60*24,Bc=e=>e.replace(/^v/,""),qg=(e,t)=>{let n=Bc(e).split(".").map(Number),o=Bc(t).split(".").map(Number);for(let r=0;r<Math.max(n.length,o.length);r++){let s=n[r]??0,i=o[r]??0;if(s>i)return 1;if(s<i)return-1}return 0},Uc=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Us&&Date.now()-Fc<Kg)return Us;try{let t=await fetch(zg);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let o=(await t.json()).version??null,r={current:e,latest:o,updateAvailable:o?qg(o,e)>0:!1};return Us=r,Fc=Date.now(),r}catch{return{current:e,latest:null,updateAvailable:!1}}},Oc=(e,t)=>{let n=e.split("."),o=t.split("."),r=o.findIndex((s,i)=>s!=n[i]);return o.map((s,i)=>i>=r?Bs.hex(y.accent).dim(s):Bs.hex(y.secondary).dim(s)).join(Bs.hex(y.secondary2).dim("."))};function jc(){let[e,t]=Xg({current:yn,latest:null,updateAvailable:!1});return Yg(()=>{let n=!0;return Uc(yn).then(o=>{n&&t(o)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?_c.createElement($c,{dimColor:!0,color:y.secondary2},yn+" "):_c.createElement($c,null,Wc.hex(y.secondary2).dim(yn),Wc.hex(y.accent).dim(" \u2197 "),Oc(yn,e.latest))}function Zn({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:o,mode:r}=z(),{userName:s,preferredEditor:i,autoSync:c}=_(),u=64,m=process.stdout.columns-u-8;return ye.createElement(vr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},t?ye.createElement(Qn,null," "):r===f.PALETTE?ye.createElement(vr,null,ye.createElement(Qn,{color:y.accent},"Command Palette"),ye.createElement(Qn,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):ye.createElement(vr,{paddingLeft:1},e.length>0?ye.createElement(Mc,{filters:e}):ye.createElement(Ac,{width:m})),n==="live"?ye.createElement(vr,{columnGap:1,paddingRight:2,"max-width":u,overflow:"hidden",justifyContent:"flex-end"},ye.createElement(Dc,{autoSync:!!c,syncStatus:o}),ye.createElement(Qn,null,yr.hex(y.secondary2).dim("Mode: ")+yr.hex(y.secondary2).dim(r.padEnd(8," "))," "),ye.createElement(Hc,{icon:"@",value:s}),ye.createElement(Hc,{icon:"\u276F",value:i}),ye.createElement(jc,null)):"",n==="peek"?ye.createElement(Pc,null):"")}function Hc({icon:e,value:t}){return ye.createElement(Qn,null,yr.dim(e)+yr.hex(y.accent)(` ${t??"-"} `))}import{Box as Jg,Text as Qg}from"ink";import eo from"react";import{Box as hr,Text as Os}from"ink";import Ft from"react";function Ws(){let e=z(),t=e.nodes[e.rootNodeId],r=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?$(t?.id):[];return Ft.createElement(hr,{flexDirection:"column",height:r,padding:1,borderStyle:"round",borderColor:y.secondary,width:s},Ft.createElement(hr,{padding:1,paddingTop:0,paddingBottom:0},Ft.createElement(Os,null,"Select a board:")),Ft.createElement(hr,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,v=$(c.id).flatMap(({id:S})=>H(S)).length;return Ft.createElement(hr,{key:c.id??u},Ft.createElement(Os,{color:m?y.accent:y.secondary2},Ft.createElement(xe,{isSelected:m})),Ft.createElement(Os,{color:m?y.accent:y.secondary2},c.title," (",v," issues)",c.readonly?" \u{1F512}":""))})))}var Zg=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:o,viewMode:r,height:s,width:i})=>{let{renderedChildrenIndex:c}=z(),u=n.find(({context:S})=>S==="BOARD"),v=s-1-3;return eo.createElement(Jg,{flexDirection:"row"},e.context==="WORKSPACE"?eo.createElement(Ws,null):u?eo.createElement(Ko,{height:v,width:i,swimlanes:(c[u.id]??[]).filter(S=>S!==void 0&&Ct(S)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:r,mode:o}):eo.createElement(Qg,null))},Vc=eo.memo(Zg);import{useEffect as ef}from"react";var tf=e=>{ef(()=>{if(!e)return;let t,n=!1,o=()=>{if(n)return;let{autoSyncIntervalMs:r,userName:s,preferredEditor:i}=_();i&&s&&r&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=g();u==="default"&&!c&&Po(),o()},r))};return o(),()=>{n=!0,t&&clearTimeout(t)}},[e])},Gc=({autoSync:e})=>(tf(e),null);function $s({width:e,height:t}){let n=z(),{autoSync:o,viewMode:r}=Ai(),s=n.filters;if(n.mode===f.HELP)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Ec,{width:e,height:t}));if(n.mode===f.PALETTE)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{filters:s}),Q.createElement(fc,{width:e,height:t-2}),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Nt(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{hideBreadCrumb:!0,filters:s}),Q.createElement(ks,{height:t,width:e})),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{hideBreadCrumb:!0,filters:s}),Q.createElement(Rc,{height:t,width:e})),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Ee(n.breadCrumb??[],"BOARD");if(Z(m)){let p=m.value.id,v=$(p).length,S=3,N=Math.floor(e/S),E=Math.floor(e/Math.max(v,1));e=Math.min(E,N)*Math.max(v,S)}return Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Gc,{autoSync:o}),Q.createElement(Bt,{flexDirection:"column"},Q.createElement(Zn,{filters:s}),Q.createElement(Vc,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:r??"dense",mode:n.mode})),Q.createElement(Xn,{width:e,mode:n.mode,availableHints:n.availableHints}))}import nf from"readline";var xr,Ir,ot,of=new Set([x.MoveCursorLeft,x.EraseInputWord,x.MoveCursorLeftOfWord,x.MoveCursorRight,x.MoveCursorRightOfWord,x.NavToPreviousContainer,x.NavToNextContainer,x.NavPreviousItem,x.NavNextItem,x.SetViewDense,x.SetViewWide,x.Confirm,x.Exit,x.InitCommandLine,x.InitCommandPalette,x.ExitCommandLine,x.CaptureInput,x.EraseInput,x.EraseInputWord,x.HideHelp,x.ViewHelp,x.SetViewDense,x.SetViewWide,x.GetLastCommandFromHistory,x.GetNextCommandFromHistory,x.AutoCompleteCommand]),zc=async e=>{if(e.ctrl&&e.name==="c")return A.exit();let{actionIndex:t,mode:n,readOnly:o}=g(),r=Ba(e,n);if(!r||o&&!of.has(r))return;let s=t[n]?.[r];if(s?.action)try{await s.action(s,e)}catch(i){logger.error(i)}},rf=()=>async function(t,n){n.name!=="escape"&&(ot&&(clearTimeout(ot),ot=void 0),await zc(n))},sf=()=>async function(t){if(t.length===1&&t[0]===27){ot&&clearTimeout(ot),ot=setTimeout(()=>{zc({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),ot=void 0},25);return}ot&&(clearTimeout(ot),ot=void 0)};function Kc(){xr&&process.stdin.removeListener("keypress",xr),Ir&&process.stdin.removeListener("data",Ir),xr=rf(),Ir=sf(),nf.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Ir),process.stdin.on("keypress",xr)}async function qc(){try{let e=jn();Z(e)&&Fe(e.value);let t=He(process.cwd()),n=[];if(Z(t)){let s=We({repoRoot:t.value});if(d(s))return Kt(3,s.message);let i=tn(),c=await Wt({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return Kt(3,c.message);let u=await B({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=at(s.value);if(d(m))return Kt(3,m.message);n=m.value}let o=zt(n);if(d(o))return Kt(4,o.message);C({hasProjectDefinition:Z(t),hasInitializingEvents:!!n.length});let r=_s();return d(r)?Kt(6,r.message):(Kc(),l("Booted Epiq",void 0))}catch(e){return Kt(0,Ao(e))}}ld();var lf=`${Ut.bold("Epiq CLI")}
|
|
58
58
|
|
|
59
59
|
${Ut.dim("Boot in directory:")}
|
|
60
60
|
${Ut.cyan("$ epiq")}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -56,13 +56,27 @@ These design choices result in a system that is:
|
|
|
56
56
|
|
|
57
57
|
## Installation
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
### Quick install
|
|
60
|
+
|
|
61
|
+
A single self-contained binary — no Node.js required:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
curl -fsSL https://raw.githubusercontent.com/ljtn/epiq/main/install.sh | sh
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Supports macOS (Intel & Apple Silicon) and Linux (x64 & arm64).
|
|
68
|
+
|
|
69
|
+
Installs to `~/.local/bin` by default. Override with `EPIQ_INSTALL_DIR` (or `XDG_BIN_HOME`); pin a version with `EPIQ_VERSION=v0.7.5`.
|
|
70
|
+
|
|
71
|
+
### Via npm
|
|
72
|
+
|
|
73
|
+
If you already have Node.js (18+):
|
|
60
74
|
|
|
61
75
|
```bash
|
|
62
76
|
npm install --global epiq
|
|
63
77
|
```
|
|
64
78
|
|
|
65
|
-
Verify
|
|
79
|
+
### Verify
|
|
66
80
|
|
|
67
81
|
```bash
|
|
68
82
|
epiq --version
|