epiq 0.6.18 → 0.6.19
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/index.js +1 -1
- package/dist/mcp.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ ${m}
|
|
|
54
54
|
|
|
55
55
|
${l}
|
|
56
56
|
`,Bo.writeFileSync(t,n,"utf8"),de.info(`Added ${i.join(", ")} to .gitignore (epiq local state)`),c("Local epiq paths ignored",!0)};var Zu=async e=>{let t=await k({cwd:e,args:["status","--porcelain"]});return d(t)?t:c("Checked git diff",t.value.stdout.trim().length>0)},j=(e,t)=>a(`[${e}] ${t}`),Pa=async()=>{F("");let e=Mn(),t=await Je(process.cwd());if(d(t))return j(1,t.message);let n=t.value,r=await Ln(n);if(d(r))return j(2,r.message);if(r.value)return j(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await Zu(n);if(d(o))return j(2.5,o.message);if(o.value)return j(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(Ur(n))return j(4,"Epiq project already initialized");let i=Ze();if(!i.isSetupDone||!i.userName)return j(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let s=$(),l=s.userName,u=s.userId;if(!u||!l)return j(5,"Missing Epiq user id");let m=e.stateBranch,g=await Dn({repoRoot:n,branch:m});if(d(g))return j(6,g.message);if(g.value)return j(6,`State branch already exists: ${m}`);let h=await po({repoRoot:n,stateBranchName:m});if(d(h))return j(6,h.message);let E=Bn();if(d(E))return j(7,E.message);let I=Ma.join(On(),e.projectId),S=await cn({repoRoot:n,stateBranchRoot:I,stateBranchName:m});if(d(S))return j(8,S.message);let A=Ma.join(I,".epiq");Qu.mkdirSync(A,{recursive:!0});let R=ys({userId:u,userName:l});if(d(R))return j(9,R.message);for(let Br of R.value){let ti=zn({event:Br,rootDir:I});if(d(ti))return j(9,ti.message)}let M=await Jn({stateBranchRoot:I,eventFileName:sn({userId:u,userName:l})});if(d(M))return j(10,M.message);let O=await wt({cwd:I,message:"[epiq:init]"});if(d(O))return j(10,O.message);let Ie=await wa(n);if(d(Ie))return j(11,Ie.message);let le=ii({repoRoot:n,fileContents:e});if(d(le))return j(12,le.message);let Kt=await G.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d(Kt))return j(13,Kt.message);let Sn=await G.commit({cwd:n,message:"[epiq:init-project]"});if(d(Sn))return j(13,Sn.message);let Rt="Project initialized!",zt=await k({cwd:n,args:["push","-u","origin","HEAD"]});d(zt)&&(Rt+=` Warn: [init:14] ${zt.message}`);let re=await ln({repoRoot:n,stateBranchRoot:I});d(re)&&(Rt+=` Warn: [init:15] ${re.message}`);let At=yt(R.value).filter(d);if(At.length>0)return j(16,At.map(Br=>Br.message).join(`
|
|
57
|
-
`));let ft=ot();if(d(ft))return j(16,ft.message);let{rootNodeId:Wd,nodes:Hd}=ft.value,ei=Hd[Wd];return ei?(T.navigate({contextNode:ei,selectedIndex:0}),N({hasProjectDefinition:!0,mode:p.DEFAULT}),c(Rt,null)):j(16,"Unable to resolve initialized root node")};import{ulid as tm}from"ulid";import{ulid as em}from"ulid";var La=null,ut=()=>structuredClone(La),gn=e=>{La=e},ka=()=>{let{contextNode:e,selectedIndex:t}=v(),r=U(e.id)[t];return r?c("Resolved selected child",r):a("Target node not found")},Uo=({id:e,parentId:t,position:n={at:"end"}})=>{let r=U(t).filter(o=>o.id!==e);return Gn(r,n)},Da=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Y();if(d(r))return a("Unable to resolve user ID");let o=Uo({parentId:t,id:e,position:n});return d(o)?o:c("Created pending move state",{id:em(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Fa=e=>{gn(e);let t=nn(e,!0);return d(t)?t:c("Node moved successfully",t.value)};function $o(e){let t=ka();if(d(t))return t;let{contextNode:n,nodes:r}=v();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let i=U(o.id),s=i.findIndex(({id:m})=>m===n.id);if(s<0)return a("Current node not found among siblings");let l=i[s+e];if(!l)return a("Missing sibling node");let u=Da({id:t.value.id,parentId:l.id,position:{at:"end"}});return d(u)?u:Fa(u.value)}function _o(e){let t=ka();if(d(t))return t;let{contextNode:n,selectedIndex:r}=v(),i=U(n.id)[r+e];if(!i)return a("Missing sibling node");let s=Da({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:i.id}});return d(s)?s:Fa(s.value)}var Oa=()=>{let e=ut();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=v().nodes[n];if(!r)return a("Move parent not found");let o=U(n).findIndex(i=>i.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),c("Synchronized navigation to moved node",null))},xr=(e,t="Moved preview")=>{if(d(e))return e;let n=Oa();return d(n)?n:(N({mode:p.MOVE}),c(t,null))},Ba=async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=V().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=U(n.id)[r];if(!o)return N({mode:p.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let i=U(o.parentNodeId),s=i.findIndex(({id:h})=>h===o.id);if(s===-1)return a("Target not found among siblings");let l=i[s-1],u=i[s+1],m=u!=null?{at:"before",sibling:u.id}:l!=null?{at:"after",sibling:l.id}:{at:"start"},g=Uo({parentId:o.parentNodeId,id:o.id,position:m});return d(g)?g:(gn({id:tm(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:g.value.rank},...e.value}),N({mode:p.MOVE}),c("Move initialized",null))}if(t==="next")return xr(_o(1));if(t==="previous")return xr(_o(-1));if(t==="to-next")return xr($o(1));if(t==="to-previous")return xr($o(-1));if(t==="confirm"){let i=ut();if(!i)return a("No pending move to confirm");let s=await Re();if(d(s))return s;let l=Te(i,s.value);if(d(l))return l;let u=Oa();return d(u)?u:(gn(null),N({mode:p.DEFAULT}),c("Moved item",null))}return t==="cancel"?(gn(null),N({mode:p.DEFAULT}),c("Cancelling move",null)):a("Invalid move modifier")};import{ulid as hr}from"ulid";import{monotonicFactory as nm,ulid as rm}from"ulid";var om=nm(),Ua=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let i=om();return c("Created issue events",[{id:rm(),userId:r,userName:o,action:"add.issue",payload:{id:i,parent:t,name:e,rank:n}}])};var $a=async(e,t)=>{let n=Y();if(d(n))return a("Unable to resolve user ID");let r=await Re();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:i,contextNode:s,selectedIndex:l}=v(),u=m=>{let g=Te(m,o);if(d(g))return g;let h=b.getNode(g.value.result.id);if(!h)return a("Created node not found");if(!h.parentNodeId)return g;let E=b.getNode(h.parentNodeId);return E?(T.navigate({contextNode:E,selectedIndex:b.getSiblings(h.parentNodeId).findIndex(({id:I})=>I===h.id)}),g):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),g=b.getNode(m);if(!g)return a("Workspace not found");let h=qn(g.id,n.value,o);return d(h)?h:u({id:hr(),action:"add.board",payload:{id:hr(),name:t.inputString,parent:g.id,rank:h.value},...n.value})}if(t.modifier==="swimlane"){let m=Ee(i,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let g=qn(m.value.id,n.value,o);return d(g)?g:u({id:hr(),action:"add.swimlane",payload:{id:hr(),name:t.inputString,parent:m.value.id,rank:g.value},...n.value})}if(t.modifier==="issue"){let m=_(s.id)[l],g=s.context==="SWIMLANE"?s:s.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let O=Ee(i,"SWIMLANE");return d(O)?null:O.value})();if(!g)return a("Unable to add issue in this context");let h=qn(g.id,n.value,o);if(d(h))return h;let E=Ua({name:t.inputString,parent:g.id,rank:h.value,user:n.value});if(d(E))return E;let I=E.value,S=ds(I,o);if(S.some(O=>d(O)))return a("Issue create failed: "+S.filter(d).map(O=>O.message).filter(Boolean).join(", "));let A=S[0];if(!A||d(A))return a("Issue creation failed");let M=I.find(O=>O.action==="add.issue")?.payload.id;return M?(T.navigate({contextNode:g,selectedIndex:b.getSiblings(g.id).findIndex(({id:O})=>O===M)}),c("Issue created",null)):a("Unable to determine ticket id")}return c("Success",null)};var _a=async()=>{let e=Ee(v().breadCrumb,"BOARD");if(d(e))return e;let t=await Je(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Xe({repoRoot:t.value});if(d(n))throw new Error(n.message);let{modifier:r}=V().commandMeta;if(r==="now"){let S=kt(n.value);if(d(S))return a(S.message);let A=fn();if(d(A))return A;let M=yt(S.value).filter(d);return M.length>0?a(M.map(O=>O.message).join(", ")):(N({mode:p.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),c("Peeking now",!0))}let o;if(r==="prev"){let S=v().eventLog.at(-1),A=ro(S);if(A===null)return a("No previous event to peek");o=A}else if(r==="next"){let S=v().unappliedEvents.at(0),A=ro(S);if(A===null)return a("No next event to peek");o=A+1}else{let S=nr(r);if(!S)return a("Invalid peek date");o=S.getTime()}let i=v(),s=e.value.id,l=rs(n.value,o);if(d(l))return a(l.message);let{appliedEvents:u,unappliedEvents:m}=l.value,g=fn();if(d(g))return g;let E=yt(u).filter(d);if(E.length>0)return fn(),N(i),a(E.map(S=>S.message).join(", "));let I=v().nodes[s];return I?(T.navigate({contextNode:I,selectedIndex:0}),N({mode:p.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:m}),c("Peeking",!0)):(fn(),N(i),a("Board did not exist at peek date"))};import im from"zod";var Wa=()=>{let e=V().commandMeta.inputString,t=im.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=ze({autoSyncDebounceMs:t.data});return d(n)?n:(Ce({autoSyncIntervalMs:t.data}),N({mode:p.DEFAULT}),c(`Auto sync interval set to ${t.data}ms`,null))};var Ha=()=>{let e=V().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=Ri(e),n=ze({autoSync:t});return d(n)?n:(Ce({autoSync:t}),N({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))};var ja=()=>{let e=V().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=ze({logLevel:e});return d(n)?n:(Ce({logLevel:e}),N({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))};var Va=async()=>{F(""),N({mode:p.DEFAULT});let e=ot();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");N({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await Qn();return d(t)?(N({syncStatus:{msg:t.message,status:"failed"}}),t):(N({mode:p.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Ka=e=>Object.values(v().tags).find(t=>t.name===e),za=e=>Object.values(v().contributors).find(t=>t.name===e),yr=[{systemOnly:!0,intent:P.Move,description:"Internal move-state command",mode:p.COMMAND_LINE,action:Ba},{intent:P.Delete,description:"Delete the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];return r?Se({id:fe(),action:"delete.node",payload:{id:r.id},...e.value}):a("Unable to resolve child to delete")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=V().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(s=>Z(x.FILTER).map(l=>l.split(n)[0]).includes(s))(r))return a("Invalid filter modifier");let i={target:r,operator:"=",value:t.trim()};return Ne(s=>({...s,filters:e==="clear"?[]:[...s.filters,i],mode:p.DEFAULT})),c("Filter updated",null)}},{intent:P.ViewHelp,description:"Open the help screen",mode:p.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return lt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),N({mode:p.HELP}),c("Viewing help",null)}},{intent:P.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!B(r))return a("Cannot close in this context");let o=v().nodes[He];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let i=await Re();if(d(i))return i;let s=i.value,l=lo(o.id,r.id,{at:"end"},e.value,s);if(d(l))return l;let u=await Se({id:fe(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:l.value},...e.value});return d(u)?u:c("Issue closed",null)},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?c("Resolved ticket",r):nt(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let i=o.value,s=v().nodes[He];if(!s)return a("Unable to locate closed swimlane");if(i.parentNodeId!==s.id)return a("Issue is not closed");if(!B(i))return a("Target node is not issue");let l=ba(i);if(!l)return a("Unable to resolve previous parent from issue history");if(l===s.id)return a("Previous parent resolves to closed swimlane");let u=v().nodes[l];if(!u)return a("Previous parent no longer exists");let m=await Re();if(d(m))return m;let g=m.value,h=lo(u.id,i.id,{at:"end"},e.value,g);if(d(h))return h;let E=await Se({id:fe(),action:"reopen.issue",payload:{id:i.id,parent:u.id,rank:h.value},...e.value});return d(E)?E:c("Issue reopened",null)},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Init,description:"Initialize Epiq in the current git repository",mode:p.COMMAND_LINE,action:Pa},{intent:P.NewItem,description:"Create a new board, swimlane, or issue",mode:p.COMMAND_LINE,action:$a,onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Rename,description:"itle] Rename the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=Js();return o?Se({id:fe(),action:"edit.title",payload:{id:r.id,name:o},...e.value}):a("Provide a title")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.UntagTicket,description:"Remove a tag from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Ka(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return a("Invalid untag target");let s=nt(i.id,"TICKET");if(d(s))return a("Unable to untag issue in this context");let l=s.value;return B(l)?(l.props.tags??[]).includes(o.id)?Se({id:fe(),action:"remove.issue.tag",payload:{id:l.id,tag:o.id},...e.value}):a("Issue is not tagged with that tag"):a("Target node is not issue")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.TagTicket,description:"Add or create a tag on the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=v();if(!o)return a("Invalid tag target");let i=nt(o.id,"TICKET");if(d(i))return a("Unable to tag issue in this context");let s=i.value;if(!B(s))return a("Target node is not issue");let l=Ka(r),u;if(l)u=l.id;else{let g=fe(),h=await Se({id:fe(),action:"create.tag",payload:{id:g,name:r},...e.value});if(d(h))return h;u=h.value.result.id}return(s.props.tags??[]).includes(u)?a("Already tagged with that tag"):Se({id:fe(),action:"add.issue.tag",payload:{id:s.id,tag:u},...e.value})},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.AssignUserToTicket,description:"Assign a user to the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:i}=v(),s=_(i.id)[o];if(!s)return a("Invalid assign target");let l=nt(s.id,"TICKET");if(d(l))return a("Unable to assign issue in this context");let u=l.value;if(!B(u))return a("Target node is not issue");let m=za(r),g;if(m)g=m.id;else{let E=fe(),I=await Se({id:fe(),action:"create.contributor",payload:{id:E,name:r},...e.value});if(d(I))return I;g=I.value.result.id}return(u.props.assignees??[]).includes(g)?a("Assignee already assigned"):Se({id:fe(),action:"add.issue.assignee",payload:{id:u.id,assignee:g},...e.value})},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=za(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return a("Invalid unassign target");let s=nt(i.id,"TICKET");if(d(s))return a("Unable to unassign in this context");let l=s.value;return B(l)?(l.props.assignees??[]).includes(o.id)?Se({id:fe(),action:"remove.issue.assignee",payload:{id:l.id,assignee:o.id},...e.value}):a(`Issue is not assigned to "${r}"`):a("Target node is not issue")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Sync,description:"Pull, commit, and push Epiq state",mode:p.COMMAND_LINE,action:Va},{intent:P.Peek,description:"View board state at another point in time",mode:p.COMMAND_LINE,action:_a},{intent:P.Export,description:"Export the current board layout to markdown",mode:p.COMMAND_LINE,action:async()=>{let e=await pa();return d(e)?e:(N({mode:p.DEFAULT}),c("Export successful",!0))}},{intent:P.Exit,description:"Exit the application",mode:p.COMMAND_LINE,action:async()=>(T.exit(),c("Exit successful",!0))},{intent:P.Edit,description:"Edit title or description",mode:p.COMMAND_LINE,action:async(e,t)=>{if(t.modifier===it.DESCRIPTION)return Ta();if(t.modifier===it.TITLE){let n=Y();if(d(n))return a("Unable to resolve user ID");let{contextNode:r,selectedIndex:o}=v(),i=_(r.id)[o];if(!i)return a("Missing node");if(i.readonly)return a("Cannot rename readonly node");let s=t.inputString.trim();return s?Se({id:fe(),action:"edit.title",payload:{id:i.id,name:s},...n.value}):a("Provide a title")}return a("Unknown edit command")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:p.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case X.USERNAME:{let{userId:r,preferredEditor:o,userName:i}=$(),s=n||i,l=r??fe();if(!s||!l)return a("Unable to resolve user name or id");let u=ze({userName:s,userId:l,preferredEditor:o??""});return d(u)?u:(Ce({userName:s,userId:l}),N({mode:p.DEFAULT}),c(`Username set to "${s}"`,null))}case X.EDITOR:{if(!n)return a("No editor provided");let r=ze({preferredEditor:n});return d(r)?r:(Ce({preferredEditor:n}),N({mode:p.DEFAULT}),c(`Editor configuration set to "${n}"`,null))}case X.VIEW:return n!=="wide"&&n!=="dense"?a("Invalid view mode"):(Ce({viewMode:n}),c(`View set to "${n}"`,null));case X.AUTOSYNC:return Ha();case X.LOG_LEVEL:return ja();case X.SYNC_DEBOUNCE_MS:return Wa();default:return a("Unknown config command")}}},{intent:P.Coffee,description:"Sponsor the development of Epiq!",mode:p.COMMAND_LINE,action:()=>{let e=V().commandMeta.modifier;return e==="custom"?Oo("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Oo(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),F(""),c("Thanks you!",null)}}];var sm=new Set(["peek","filter","view-help"]),Oe=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=V();if(!t)return a("No command to confirm");if(!e&&n===Nt.Invalid)return a("Invalid command");let i=ar(t);zs();let{readOnly:s}=v();if(s&&!sm.has(i))return mn({status:qe.Fail,message:"Command not available in readonly state",value:null});let l=yr.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!l)return mn({status:qe.Fail,message:"Command not found",value:null});let u;try{u=await l.action(l,{command:t,inputString:o,modifier:r})}catch(m){return mn({status:qe.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?mn(u):(Gs({addToHistory:!e}),l.onSuccess?.(),$().autoSync&&Zn(),u)};var Cr=[{intent:f.Exit,mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(N({mode:p.COMMAND_LINE}),F("move cancel"),Oe({isForceExecutedBySystem:!0}))},{intent:f.InitMove,mode:p.DEFAULT,description:"[m] move (init/confirm)",action:()=>(N({mode:p.COMMAND_LINE}),F("move start"),Oe({isForceExecutedBySystem:!0}))},{intent:f.ConfirmMove,mode:p.MOVE,action:()=>(N({mode:p.COMMAND_LINE}),F("move confirm"),Oe({isForceExecutedBySystem:!0}))}],Er=[{intent:f.MovePreviousItem,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move previous"),Oe({isForceExecutedBySystem:!0})):a("No pending move")},{intent:f.MoveNextItem,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move next"),Oe({isForceExecutedBySystem:!0})):a("No pending move")}],Ga=[{intent:f.MoveToNextContainer,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move to-next"),Oe({isForceExecutedBySystem:!0})):a("No pending move")},{intent:f.MoveToPreviousContainer,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move to-previous"),Oe({isForceExecutedBySystem:!0})):a("No pending move")}];var qa={[w.WORKSPACE]:[...Cr,...Er],[w.BOARD]:[...Cr,...Er],[w.SWIMLANE]:[...Cr,...Er,...Ga],[w.TICKET]:[],[w.FIELD]:[],[w.FIELD_LIST]:[],[w.TEXT]:[]};var Ya=()=>{F("");let{pendingNavTarget:e}=ct();N({mode:p.DEFAULT}),e&&T.navigate(e),lt({pendingNavTarget:void 0})},Xa=[{intent:f.ExitCommandLine,mode:p.HELP,action:()=>(Ya(),c("Exiting help",null))},{intent:f.Exit,mode:p.HELP,action:()=>(Ya(),c("Closed help",null))},{intent:f.NavPreviousItem,mode:p.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),c("Navigating to previous help item",null))},{intent:f.NavNextItem,mode:p.HELP,action:()=>(T.navigateToNextItem(),c("Navigating to next help item",null))},{intent:f.NavToPreviousContainer,mode:p.HELP,action:()=>(T.navigateToPreviousContainer(),c("Navigating to previous help container",null))},{intent:f.NavToNextContainer,mode:p.HELP,action:()=>(T.navigateToNextContainer(),c("Navigating to next help container",null))}];var am=e=>{N({mode:p.COMMAND_LINE});let{pendingNavTarget:t}=ct();t&&T.navigate(t),lt({pendingNavTarget:void 0}),F(`${e} `)},Ja=()=>{F("");let{pendingNavTarget:e}=ct();e&&T.navigate(e),lt({pendingNavTarget:void 0}),N({mode:p.DEFAULT})},Qa=[{intent:f.InitCommandPalette,mode:p.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{F("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return lt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),N({mode:p.PALETTE}),c("Opening command palette",null)}},{intent:f.Confirm,mode:p.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!et(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?(am(t),c("Selected command",t)):c("No command selected",null)}},{intent:f.ExitCommandLine,mode:p.PALETTE,action:()=>(Ja(),c("Exiting palette",null))},{intent:f.Exit,mode:p.PALETTE,action:()=>(Ja(),c("Closed command palette",null))},{intent:f.NavPreviousItem,mode:p.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:f.NavNextItem,mode:p.PALETTE,action:()=>(T.navigateToNextItem(),c("Navigating to next item",null))},{intent:f.NavToPreviousContainer,mode:p.PALETTE,action:()=>(T.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:f.NavToNextContainer,mode:p.PALETTE,action:()=>(T.navigateToNextContainer(),c("Navigating to next container",null))}];var Za=[...Xa,...Qa,{intent:f.AddItem,mode:p.DEFAULT,description:"[n] new...",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.NEW} `),c("Adding new item",null))},{intent:f.Delete,mode:p.DEFAULT,description:"[d] delete",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.DELETE} `),c("Deleting item",null))},{intent:f.InitCommandLine,mode:p.DEFAULT,description:"[:] focus command line",action:()=>(N({mode:p.COMMAND_LINE}),F(""),c("Entering command line mode",null))},{intent:f.Confirm,mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!U(e?.id??"")?.length){if(e?.title===Q.DESCRIPTION)return N({mode:p.COMMAND_LINE}),F(`${x.EDIT} description `),c("Propose command",!0);if(e?.title===Q.ASSIGNEES)return N({mode:p.COMMAND_LINE}),F(`${x.ASSIGN} `),c("Propose command",!0);if(e?.title===Q.TAGS)return N({mode:p.COMMAND_LINE}),F(`${x.TAG} `),c("Propose command",!0);if(t.title===Q.DESCRIPTION&&e?.context==="TEXT")return N({mode:p.COMMAND_LINE}),F(`${x.EDIT} description `),c("Propose command",!0)}return T.enterChildNode(),c("Entering context",null)}},{intent:f.EditTitle,mode:p.DEFAULT,description:"[r] rename title",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.EDIT} title ${v().selectedNode?.title}`),c("Exiting context",null))},{intent:f.EditDescription,mode:p.DEFAULT,description:"[e] edit description",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.EDIT} description `),c("Exiting context",null))},{intent:f.Exit,mode:p.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),c("Exiting context",null))},{intent:f.NavPreviousItem,mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:f.NavNextItem,mode:p.DEFAULT,action:()=>(T.navigateToNextItem(),c("Navigating to next item",null))},{intent:f.NavToPreviousContainer,mode:p.DEFAULT,action:()=>(T.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:f.NavToNextContainer,mode:p.DEFAULT,action:()=>(T.navigateToNextContainer(),c("Navigating to next container",null))}];var dm=500,cm=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),ed=e=>{let t=cm(e);t&&sr(n=>(n+t).slice(0,dm))};var lm=[p.COMMAND_LINE,p.PALETTE],um=e=>[{intent:f.MoveCursorLeft,mode:e,action:()=>(Io(-1),c("Moving cursor left",null))},{intent:f.MoveCursorRight,mode:e,action:()=>(Io(1),c("Moving cursor right",null))},{intent:f.MoveCursorLeftOfWord,mode:e,action:()=>(Ro("left"),c("Moving cursor left of word",null))},{intent:f.MoveCursorRightOfWord,mode:e,action:()=>(Ro("right"),c("Moving cursor right of word",null))},{intent:f.AutoCompleteCommand,mode:e,action:()=>(sr((t,{remainder:n})=>n?t+n:t),c("Auto-completing command",null))},{intent:f.CaptureInput,mode:e,action:(t,{sequence:n})=>(ed(n??""),c("Capturing input",null))},{intent:f.EraseInput,mode:e,action:()=>(Vs(),c("Erasing input",null))},{intent:f.EraseInputWord,mode:e,action:()=>(Ks(),c("Erasing input word",null))}],td=[{intent:f.Confirm,mode:p.COMMAND_LINE,action:()=>(Oe(),c("Executing command",null))},{intent:f.ViewHelp,mode:p.DEFAULT,action:()=>(N({mode:p.HELP}),c("Viewing help",null))},...lm.flatMap(um),{intent:f.ExitCommandLine,mode:p.COMMAND_LINE,action:()=>(N({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:f.GetLastCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(qs(),c("Getting last command from history",null))},{intent:f.GetNextCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(Ys(),c("Getting next command from history",null))}];import od from"chalk";var Nr=od.dim.hex(y.secondary2)(": for command line"),nd="q to exit",rd=`${od.hex(y.accent)("m")} to confirm`,Wo={[w.WORKSPACE]:[Nr],[w.BOARD]:[Nr],[w.BOARD+p.COMMAND_LINE]:[Nr],[w.SWIMLANE]:[Nr],[w.TICKET+p.HELP]:[nd],[w.SWIMLANE+p.HELP]:[nd],[w.TICKET]:[],[w.FIELD]:[],[w.SWIMLANE+p.MOVE]:[rd],[w.TICKET+p.MOVE]:[rd]};var vn=e=>e.trim().toLocaleLowerCase(),mm=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},pm=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},id=(e,t)=>{let n=vn(t.value);if(!n)return!0;switch(t.target){case"title":return vn(e.title??"").includes(n);case"description":return vn(e.props.description??"").includes(n);case"tag":return mm(e).map(vn).some(o=>o.includes(n));case"assignee":return pm(e).map(vn).some(o=>o.includes(n));default:return!0}};function sd(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],i=r;for(;i&&(o.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let s=o[o.length-1];return!s||s.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),c("Breadcrumb built",o))}var ad=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 St,Ho,jo=new Set,dd=()=>{for(let e of jo)e()},fm=e=>(jo.add(e),()=>jo.delete(e));function cd(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:i}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let l=o[t];if(!l)return a("Unable to derive state, contextNode not found");let u=sd(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:g}=l,h=Wo[g+n]??Wo[g]??[],E=[...Za,...qa[g]??[],...td],I=ad(E),S=vm(o,i),A=S[t]?.[e.selectedIndex]??null;return c("Derived successfully",{...e,contextNode:l,breadCrumb:m,availableHints:h,availableActions:E,actionIndex:I,selectedNode:A,renderedChildrenIndex:S})}var v=()=>{if(!St)throw new Error("State not initialized. Call initWorkspaceState() first.");return St},ot=()=>St?c("Retrieved state",St):a("State not initialized. Call initWorkspaceState() first.");function rn(e){Ho=e;let t=Ye(process.cwd()),n=!1;if(!d(t)){let i=Qe(t.value);if(d(i))return a(i.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:p.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},o=cd(r);return d(o)?o:(St=o.value,dd(),c("State initialized",null))}function Ne(e){let t=v(),n=e(t),r=cd(n);return d(r)?a(r.message??"Unable to update state"):(St=r.value,dd(),c("State updated",null))}var N=e=>Ne(t=>({...t,...e}));var K=()=>gm(fm,v,v),vm=(e,t)=>{let n={};for(let r of Object.values(e))B(r)&&t.length>0&&!t.every(o=>id(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,i)=>{let s=e[o.id],l=e[i.id];return!s||!l?0:s.rank.localeCompare(l.rank)});return n},_=e=>v()?.renderedChildrenIndex[e]??[],fn=()=>Ho?rn(Ho):a("Cannot reset state: no initial workspace found"),Dt=()=>St!==void 0;import{Box as Vo,Text as xn}from"ink";import Me,{useEffect as xm,useMemo as hm}from"react";import{ulid as ym}from"ulid";var ld=({text:e,match:t,color:n,highlightColor:r=y.secondary,dimColor:o=!1})=>{if(!t)return Me.createElement(xn,{color:n,dimColor:o},e);let i=e.toLowerCase(),s=t.toLowerCase(),l=i.indexOf(s);return l===-1?Me.createElement(xn,{color:n,dimColor:o},e):Me.createElement(xn,{color:n,dimColor:o},e.slice(0,l),Me.createElement(xn,{backgroundColor:r,bold:!0},e.slice(l,l+t.length)),e.slice(l+t.length))},ud=ym(),Cm=e=>`${e}`,Em=e=>{let{pendingNavTarget:t}=ct();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,i=new Set(Z(x.NONE,{breadCrumb:n,contextNode:r,readOnly:v().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(s=>s!=="move").filter(s=>s.length>0).filter(s=>s!==x.PALETTE).map(s=>{let l=ar(s),u=yr.find(m=>m.intent===l);return{command:s,description:u?.description??`[${s}] Run command`,isAvailable:i.has(s)}}).filter(s=>s.command.toLowerCase().startsWith(e)||e.length>=2&&s.description.toLowerCase().includes(e)).sort((s,l)=>s.isAvailable!==l.isAvailable?s.isAvailable?-1:1:s.command.localeCompare(l.command))},Nm=e=>q.text({id:ud,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),bm=(e,t,n)=>q.text({id:Cm(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Ko=[],Sm=e=>{md();let t=b.createNode(Nm(v().rootNodeId));d(t)||!et(t.value)||(Ko=[t.value,...e.map((n,r)=>bm(n,r,ud)).map(b.createNode).filter(J).map(({value:n})=>n).filter(et)],T.navigate({contextNode:t.value,selectedIndex:0}))},md=()=>{let e=Ko.map(t=>t.id);Ko=[];for(let t of e)b.deleteNode(t)};function pd({width:e,height:t}){let r=Xs().value.trim().toLowerCase(),o=hm(()=>Em(r),[r]);xm(()=>(Sm(o),()=>{md()}),[o]);let i=v().selectedIndex;return Me.createElement(Vo,{flexDirection:"column",width:e,height:t-2},Me.createElement(st,{height:t-4,itemHeight:3,selectedIndex:i},o.map((s,l)=>{let u=l===i,m=s.isAvailable?y.accent:y.secondary2,g=s.isAvailable?"":"[unavailable] ";return Me.createElement(Vo,{key:s.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},Me.createElement(xn,{color:m,dimColor:!s.isAvailable},u?"\u276F ":" ",Me.createElement(ld,{text:Di(s.command),match:r,color:m,dimColor:!s.isAvailable})),Me.createElement(Vo,{paddingLeft:2},Me.createElement(ld,{text:g+s.description,match:r.length>=2?r:"",color:u&&s.isAvailable?y.primary:y.secondary2,dimColor:!s.isAvailable})))})))}import{Box as Bm}from"ink";import Go from"react";import yn from"chalk";import{Box as zo,Text as gd}from"ink";import hn,{useEffect as Im,useMemo as Rm,useState as Am}from"react";var fd=yn.gray,Tm=yn.inverse,wm=yn.inverse.gray,Mm={hint:"",hints:[],overlap:0,remainder:""},xd=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},Pm=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=be(t);return{bg:r=>yn.bgHex(n).black(r),bgCursor:r=>yn.bgHex(n).inverse.black(r)}}return no(t)},Lm=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=xd({value:e,command:t});if(!r)return null;let i=e.slice(r.end).match(/^\s*/)?.[0].length??0,s=r.end+i;return e.slice(s,s+n.length)!==n?null:{start:s,end:s+n.length}},vd=()=>({value:se.value,cursorPosition:se.cursorPosition,commandIsPending:se.commandIsPending,autoCompletion:se.commandMeta.autoCompletion??Mm,infoMessage:se.commandMeta.infoMessage,validationStatus:se.commandMeta.validity,command:se.commandMeta.command,inputString:se.commandMeta.inputString,modifier:se.commandMeta.modifier}),km=(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,hd=({width:e,mode:t})=>{let[n,r]=Am(vd());Im(()=>{let E=()=>{let S=vd();r(A=>km(A,S)?A:S)},I=So(E);return E(),()=>{I()}},[]);let{value:o,cursorPosition:i,infoMessage:s,commandIsPending:l,autoCompletion:u,command:m,modifier:g}=n,h=Rm(()=>{let E=Math.max(0,Math.min(i,o.length)),I=xd({value:o,command:m}),S=Lm({value:o,command:m,modifier:g}),A=m?no(m):null,R=Pm({command:m,modifier:g}),M=(re,ue)=>{let At=I&&ue>=I.start&&ue<I.end,ft=S&&ue>=S.start&&ue<S.end;return At&&A?A.fg(re):ft&&R?R.bg(re):re},O=(re,ue)=>{let At=I&&ue>=I.start&&ue<I.end,ft=S&&ue>=S.start&&ue<S.end;return At&&A?A.fgCursor(re):ft&&R?R.bgCursor(re):Tm(re)},Ie=o.slice(0,E),le=o[E]??" ",Kt=E<o.length?o.slice(E+1):"",Sn=Array.from(Ie).map((re,ue)=>M(re,ue)).join(""),Rt=O(le,E),zt=Array.from(Kt).map((re,ue)=>M(re,E+1+ue)).join("");if(u.hint){let re=u.hint[u.overlap]??le;Rt=wm(re),zt=fd(u.remainder.slice(1)+Kt)}return fd(t===p.PALETTE?"?":":")+Sn+Rt+zt},[o,i,u,m,g]);return hn.createElement(zo,{flexDirection:"column",justifyContent:"flex-start"},hn.createElement(zo,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},hn.createElement(zo,null,hn.createElement(gd,null,h),s&&hn.createElement(gd,{wrap:"truncate",color:l?y.red:y.secondary2},` ${s} `))))};import{Box as Dm,Text as Fm}from"ink";import yd from"react";var Om=(e,t)=>{let n=[],r=0;for(let o of e){let s=(n.length>0?" | ":"").length+o.length;if(r+s>t-4)break;n.push(o),r+=s}return n},Cd=({width:e,availableHints:t})=>{let n=Om(t,e).join(" | ");return yd.createElement(Dm,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},yd.createElement(Fm,{color:y.secondary2},n.length?n:"\xA0"))};var Cn=({width:e,mode:t,availableHints:n})=>{let r=[],o=0;for(let i of n){let l=(r.length>0?" | ":"").length+i.length;if(o+l>e+2)break;r.push(i),o+=l}return Go.createElement(Bm,null,t===p.COMMAND_LINE||t===p.PALETTE?Go.createElement(hd,{width:e,mode:t}):Go.createElement(Cd,{width:e,mode:t,availableHints:n}))};import{Box as mt,Text as jt}from"ink";import ce,{useEffect as Um,useMemo as $m}from"react";import{ulid as Ed}from"ulid";var Sr=Ed(),_m=()=>[...new Set([...v().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),Wm=e=>q.text({id:Sr,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Hm=(e,t,n)=>q.text({id:Ed(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),br=[],Nd=()=>{let e=br.filter(n=>n.id!==Sr).map(n=>n.id),t=br.filter(n=>n.id===Sr).map(n=>n.id);br=[];for(let n of[...e,...t])b.deleteNode(n)},jm=e=>{Nd();let t=b.createNode(Wm(v().rootNodeId));if(d(t)||!et(t.value))return logger.error("Could not attach help nodes");br=[t.value,...e.map((n,r)=>Hm(n,r,Sr)).map(b.createNode).filter(J).map(({value:n})=>n).filter(et)],T.navigate({contextNode:t.value,selectedIndex:0})},bd=({width:e,height:t})=>{let n=$m(()=>_m(),[]);Um(()=>(jm(n),()=>{Nd()}),[n]);let r=v().selectedIndex;return ce.createElement(mt,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},ce.createElement(mt,{paddingX:1,justifyContent:"center"},ce.createElement(jt,{color:y.accent},"Help"),ce.createElement(jt,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),ce.createElement(mt,{paddingX:1,marginTop:1},ce.createElement(mt,{width:20,justifyContent:"flex-end"},ce.createElement(jt,{color:y.secondary},"Key(s)")),ce.createElement(mt,{flexGrow:1,width:40,paddingLeft:2},ce.createElement(jt,{color:y.secondary},"Action"))),ce.createElement(st,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:i},s)=>{let l=s===r;return ce.createElement(mt,{paddingX:1,key:`${o}-${i}-${s}`,flexDirection:"row"},ce.createElement(mt,{width:20,justifyContent:"flex-end"},ce.createElement(jt,{color:y.accent},o)),ce.createElement(mt,{flexGrow:1,width:40,paddingLeft:2},ce.createElement(jt,{color:l?y.primary:y.secondary2},i)))})))};import Vm from"chalk";import{Box as Ir,Text as Ge}from"ink";import xe from"react";var Sd=({width:e,height:t})=>xe.createElement(Ir,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},xe.createElement(Ge,{color:y.accent,bold:!0},"Initialize project"),xe.createElement(Ge,null,`This folder is not an ${Vm.hex(y.accent)("epiq")} project yet.`),xe.createElement(Ge,{color:y.primary},"To start tracking issues here, we need to initialize a new",xe.createElement(Ge,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),xe.createElement(Ir,{marginTop:1,flexDirection:"column"},xe.createElement(Ir,null,xe.createElement(Ge,{color:y.accent}," "),xe.createElement(Ge,{color:y.primary},"Type "),xe.createElement(Ge,{backgroundColor:y.secondary}," :init "))),xe.createElement(Ir,{marginTop:1},xe.createElement(Ge,{color:y.secondary2},"This will create, commit and push "),xe.createElement(Ge,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as Rr,Text as Be}from"ink";import ne from"react";var Km=({isDone:e,command:t,value:n})=>ne.createElement(Rr,null,ne.createElement(Be,{color:y.accent,dimColor:e},e?" \u2714 ":" "),ne.createElement(Be,{dimColor:e},"Type "),ne.createElement(Be,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&ne.createElement(ne.Fragment,null,ne.createElement(Be,{dimColor:e}," "),ne.createElement(Be,{color:y.secondary,dimColor:e},"<"+n+">"))),zm=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function qo({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:i,autoSync:s,isSetAutoSync:l}=Ze(),u=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:i,message:"Nice. Now pick your editor."},{key:"autosync",done:l,command:":config autosync",value:s,message:"Almost there. Configure auto sync."}],m=u.findIndex(h=>!h.done),g=m===-1?void 0:u[m];return ne.createElement(Rr,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},ne.createElement(Be,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),ne.createElement(Be,null,"Let's get you started - it's a breeze."),ne.createElement(Be,{color:y.secondary2},"Remember - you can always search available commands by typing:",ne.createElement(Be,{color:y.accent}," ? ")),g&&ne.createElement(Be,{color:y.secondary2},g.message),ne.createElement(Rr,{flexDirection:"column"},u.map((h,E)=>m===-1||E<=m?ne.createElement(Rr,{key:h.key,marginBottom:1},ne.createElement(Km,{isDone:h.done,command:h.command,value:h.done?zm(h.value):void 0})):null)))}import Pr from"chalk";import{Box as Mr,Text as Vt}from"ink";import ae from"react";var Id="0.6.18";import{Box as Ar,Text as Gm}from"ink";import It from"react";var Rd=({width:e})=>{let{viewMode:t}=$(),n=K(),{breadCrumb:r,contextNode:o,selectedIndex:i,renderedChildrenIndex:s}=n,l=s[o.id]?.[i],u=nt(l?.id??o.id,"TICKET"),m=J(u)?u.value:void 0,g=m?.props.tags??[],h=m?.props.assignees??[],E=m?.parentNodeId?!Qr(o.id,m.parentNodeId)&&t==="dense":!1,I=r.map((R,M)=>{let O=M===r.length-1,Ie=U(R.id),le=O?Ie?.[i]?.title:void 0;return`${M?" / ":""}${R.title??""}${le?` \u25B8 ${le}`:""}`}).join(""),S=g.reduce((R,M)=>R+(b.getTag(M)?.name.length??0)+4,0)+h.reduce((R,M)=>R+(b.getContributor(M)?.name.length??0)+4,0),A=e-S;return It.createElement(Ar,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},It.createElement(Ar,{overflow:"hidden",width:A},It.createElement(Gm,{wrap:"truncate-end",color:y.secondary2},I)),E?g.map(R=>It.createElement(Ar,{key:R,paddingLeft:1},It.createElement(_t,{id:R}))):null,E?h.map(R=>It.createElement(Ar,{key:R,paddingLeft:1},It.createElement($t,{id:R}))):null)};import{Box as qm,Text as Ad}from"ink";import Tr from"react";var Ym=({filters:e})=>Tr.createElement(qm,{columnGap:1},Tr.createElement(Ad,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Tr.createElement(Ad,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Td=Tr.memo(Ym);import{Box as Xm,Text as wr}from"ink";import En from"react";function wd(){let{eventLog:e,unappliedEvents:t}=K(),n=e.at(-1)?.id,r=Hn(n??""),o=J(r)?Xi(r.value):"INVALID DATE";return En.createElement(Xm,{paddingLeft:1},En.createElement(wr,{backgroundColor:y.accent}," Readonly "),En.createElement(wr,{color:y.accent}," "+t.length+" edits ago at "+o+"."),En.createElement(wr,{color:y.accent}," Resume with "),En.createElement(wr,{backgroundColor:y.accent}," :peek now "))}import Yo from"chalk";import{Box as Jm,Text as Md}from"ink";import Xo,{useEffect as Qm,useState as Zm}from"react";var ep=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],Pd=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)}},tp=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},np=(e,t,n)=>{let r=Pd(e),o=Pd(t);return tp({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},rp=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,i=e[r],s=e[Math.min(r+1,e.length-1)];return np(i,s,o)};function Ld({syncStatus:e,autoSync:t}){let[n,r]=Zm(0);Qm(()=>{if(e.status!=="syncing"){r(0);return}let l=setInterval(()=>{r(u=>u+1)},50);return()=>clearInterval(l)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},s={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:rp(ep,(Math.sin(n*.12)+1)/2)??""}[e.status];return Xo.createElement(Jm,null,Xo.createElement(Md,null,Yo.hex(y.secondary2).dim(t?"AutoSync: ":"Sync: ")),Xo.createElement(Md,null,Yo.hex(s)("\u25CF")+Yo.hex(y.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}function Nn({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o}=K(),{userName:i,preferredEditor:s,autoSync:l}=$(),u=64,m=process.stdout.columns-u-8;return ae.createElement(Mr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},t?ae.createElement(Vt,null," "):o===p.PALETTE?ae.createElement(Mr,null,ae.createElement(Vt,{color:y.accent},"Command Palette"),ae.createElement(Vt,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):ae.createElement(Mr,{paddingLeft:1},e.length>0?ae.createElement(Td,{filters:e}):ae.createElement(Rd,{width:m})),n==="live"?ae.createElement(Mr,{columnGap:1,paddingRight:2,"max-width":u,overflow:"hidden",justifyContent:"flex-end"},ae.createElement(Ld,{autoSync:!!l,syncStatus:r}),ae.createElement(Vt,null,Pr.hex(y.secondary2).dim("Mode: ")+Pr.hex(y.secondary2).dim(o.padEnd(8," "))," "),ae.createElement(kd,{icon:"@",value:i}),ae.createElement(kd,{icon:"\u276F",value:s}),ae.createElement(Vt,{dimColor:!0,color:y.secondary2},Id+" ")):"",n==="peek"?ae.createElement(wd,null):"")}function kd({icon:e,value:t}){return ae.createElement(Vt,null,Pr.dim(e)+Pr.hex(y.accent)(` ${t??"-"} `))}import{Box as op,Text as ip}from"ink";import bn from"react";import{Box as Lr,Text as Jo}from"ink";import pt from"react";function Qo(){let e=K(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,i=process.stdout.columns||120,s=t?.id?_(t?.id):[];return pt.createElement(Lr,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:y.secondary,width:i},pt.createElement(Lr,{padding:1,paddingTop:0,paddingBottom:0},pt.createElement(Jo,null,"Select a board:")),pt.createElement(Lr,{padding:1,flexDirection:"column"},s.map((l,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,h=_(l.id).flatMap(({id:E})=>U(E)).length;return pt.createElement(Lr,{key:l.id??u},pt.createElement(Jo,{color:m?y.accent:y.secondary2},pt.createElement(ge,{isSelected:m})),pt.createElement(Jo,{color:m?y.accent:y.secondary2},l.title," (",h," issues)",l.readonly?" \u{1F512}":""))})))}var sp=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:i,width:s})=>{let{renderedChildrenIndex:l}=K(),u=n.find(({context:E})=>E==="BOARD"),h=i-1-3;return bn.createElement(op,{flexDirection:"row"},e.context==="WORKSPACE"?bn.createElement(Qo,null):u?bn.createElement(gr,{height:h,width:s,swimlanes:(l[u.id]??[]).filter(E=>E!==void 0&&Mt(E)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):bn.createElement(ip,null))},Dd=bn.memo(sp);import{useEffect as ap}from"react";var dp=e=>{ap(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:i,preferredEditor:s}=$();s&&i&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:l,mode:u}=v();u==="default"&&!l&&Zn(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},Fd=({autoSync:e})=>(dp(e),null);function Zo({width:e,height:t}){let n=K(),{autoSync:r,viewMode:o}=bi(),i=n.filters;if(n.mode===p.HELP)return z.createElement(gt,{flexDirection:"column"},z.createElement(bd,{width:e,height:t}));if(n.mode===p.PALETTE)return z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{filters:i}),z.createElement(pd,{width:e,height:t-2}),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:s}=Ze(),l=!s,u=s&&!n.hasProjectDefinition;if(l)return z.createElement(gt,{flexDirection:"column"},z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{hideBreadCrumb:!0,filters:i}),z.createElement(qo,{height:t,width:e})),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return z.createElement(gt,{flexDirection:"column"},z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{hideBreadCrumb:!0,filters:i}),z.createElement(Sd,{height:t,width:e})),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Ee(n.breadCrumb??[],"BOARD");if(J(m)){let g=m.value.id,h=_(g).length,E=3,I=Math.floor(e/E),S=Math.floor(e/Math.max(h,1));e=Math.min(S,I)*Math.max(h,E)}return z.createElement(gt,{flexDirection:"column"},z.createElement(Fd,{autoSync:r}),z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{filters:i}),z.createElement(Dd,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}))}import cp from"readline";var kr,Dr,Ue,lp=new Set([f.MoveCursorLeft,f.EraseInputWord,f.MoveCursorLeftOfWord,f.MoveCursorRight,f.MoveCursorRightOfWord,f.NavToPreviousContainer,f.NavToNextContainer,f.NavPreviousItem,f.NavNextItem,f.SetViewDense,f.SetViewWide,f.Confirm,f.Exit,f.InitCommandLine,f.InitCommandPalette,f.ExitCommandLine,f.CaptureInput,f.EraseInput,f.EraseInputWord,f.HideHelp,f.ViewHelp,f.SetViewDense,f.SetViewWide,f.GetLastCommandFromHistory,f.GetNextCommandFromHistory,f.AutoCompleteCommand]),Od=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r}=v(),o=Qs(e,n);if(!o||r&&!lp.has(o))return;let i=t[n]?.[o];if(i?.action)try{await i.action(i,e)}catch(s){logger.error(s)}},up=()=>async function(t,n){n.name!=="escape"&&(Ue&&(clearTimeout(Ue),Ue=void 0),await Od(n))},mp=()=>async function(t){if(t.length===1&&t[0]===27){Ue&&clearTimeout(Ue),Ue=setTimeout(()=>{Od({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),Ue=void 0},25);return}Ue&&(clearTimeout(Ue),Ue=void 0)};function Bd(){kr&&process.stdin.removeListener("keypress",kr),Dr&&process.stdin.removeListener("data",Dr),kr=up(),Dr=mp(),cp.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Dr),process.stdin.on("keypress",kr)}Ia();gp(`${Fr.bold("Epiq CLI")}
|
|
57
|
+
`));let ft=ot();if(d(ft))return j(16,ft.message);let{rootNodeId:Wd,nodes:Hd}=ft.value,ei=Hd[Wd];return ei?(T.navigate({contextNode:ei,selectedIndex:0}),N({hasProjectDefinition:!0,mode:p.DEFAULT}),c(Rt,null)):j(16,"Unable to resolve initialized root node")};import{ulid as tm}from"ulid";import{ulid as em}from"ulid";var La=null,ut=()=>structuredClone(La),gn=e=>{La=e},ka=()=>{let{contextNode:e,selectedIndex:t}=v(),r=U(e.id)[t];return r?c("Resolved selected child",r):a("Target node not found")},Uo=({id:e,parentId:t,position:n={at:"end"}})=>{let r=U(t).filter(o=>o.id!==e);return Gn(r,n)},Da=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Y();if(d(r))return a("Unable to resolve user ID");let o=Uo({parentId:t,id:e,position:n});return d(o)?o:c("Created pending move state",{id:em(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Fa=e=>{gn(e);let t=nn(e,!0);return d(t)?t:c("Node moved successfully",t.value)};function $o(e){let t=ka();if(d(t))return t;let{contextNode:n,nodes:r}=v();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let i=U(o.id),s=i.findIndex(({id:m})=>m===n.id);if(s<0)return a("Current node not found among siblings");let l=i[s+e];if(!l)return a("Missing sibling node");let u=Da({id:t.value.id,parentId:l.id,position:{at:"end"}});return d(u)?u:Fa(u.value)}function _o(e){let t=ka();if(d(t))return t;let{contextNode:n,selectedIndex:r}=v(),i=U(n.id)[r+e];if(!i)return a("Missing sibling node");let s=Da({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:i.id}});return d(s)?s:Fa(s.value)}var Oa=()=>{let e=ut();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=v().nodes[n];if(!r)return a("Move parent not found");let o=U(n).findIndex(i=>i.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),c("Synchronized navigation to moved node",null))},xr=(e,t="Moved preview")=>{if(d(e))return e;let n=Oa();return d(n)?n:(N({mode:p.MOVE}),c(t,null))},Ba=async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=V().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=U(n.id)[r];if(!o)return N({mode:p.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let i=U(o.parentNodeId),s=i.findIndex(({id:h})=>h===o.id);if(s===-1)return a("Target not found among siblings");let l=i[s-1],u=i[s+1],m=u!=null?{at:"before",sibling:u.id}:l!=null?{at:"after",sibling:l.id}:{at:"start"},g=Uo({parentId:o.parentNodeId,id:o.id,position:m});return d(g)?g:(gn({id:tm(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:g.value.rank},...e.value}),N({mode:p.MOVE}),c("Move initialized",null))}if(t==="next")return xr(_o(1));if(t==="previous")return xr(_o(-1));if(t==="to-next")return xr($o(1));if(t==="to-previous")return xr($o(-1));if(t==="confirm"){let i=ut();if(!i)return a("No pending move to confirm");let s=await Re();if(d(s))return s;let l=Te(i,s.value);if(d(l))return l;let u=Oa();return d(u)?u:(gn(null),N({mode:p.DEFAULT}),c("Moved item",null))}return t==="cancel"?(gn(null),N({mode:p.DEFAULT}),c("Cancelling move",null)):a("Invalid move modifier")};import{ulid as hr}from"ulid";import{monotonicFactory as nm,ulid as rm}from"ulid";var om=nm(),Ua=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let i=om();return c("Created issue events",[{id:rm(),userId:r,userName:o,action:"add.issue",payload:{id:i,parent:t,name:e,rank:n}}])};var $a=async(e,t)=>{let n=Y();if(d(n))return a("Unable to resolve user ID");let r=await Re();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:i,contextNode:s,selectedIndex:l}=v(),u=m=>{let g=Te(m,o);if(d(g))return g;let h=b.getNode(g.value.result.id);if(!h)return a("Created node not found");if(!h.parentNodeId)return g;let E=b.getNode(h.parentNodeId);return E?(T.navigate({contextNode:E,selectedIndex:b.getSiblings(h.parentNodeId).findIndex(({id:I})=>I===h.id)}),g):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),g=b.getNode(m);if(!g)return a("Workspace not found");let h=qn(g.id,n.value,o);return d(h)?h:u({id:hr(),action:"add.board",payload:{id:hr(),name:t.inputString,parent:g.id,rank:h.value},...n.value})}if(t.modifier==="swimlane"){let m=Ee(i,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let g=qn(m.value.id,n.value,o);return d(g)?g:u({id:hr(),action:"add.swimlane",payload:{id:hr(),name:t.inputString,parent:m.value.id,rank:g.value},...n.value})}if(t.modifier==="issue"){let m=_(s.id)[l],g=s.context==="SWIMLANE"?s:s.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let O=Ee(i,"SWIMLANE");return d(O)?null:O.value})();if(!g)return a("Unable to add issue in this context");let h=qn(g.id,n.value,o);if(d(h))return h;let E=Ua({name:t.inputString,parent:g.id,rank:h.value,user:n.value});if(d(E))return E;let I=E.value,S=ds(I,o);if(S.some(O=>d(O)))return a("Issue create failed: "+S.filter(d).map(O=>O.message).filter(Boolean).join(", "));let A=S[0];if(!A||d(A))return a("Issue creation failed");let M=I.find(O=>O.action==="add.issue")?.payload.id;return M?(T.navigate({contextNode:g,selectedIndex:b.getSiblings(g.id).findIndex(({id:O})=>O===M)}),c("Issue created",null)):a("Unable to determine ticket id")}return c("Success",null)};var _a=async()=>{let e=Ee(v().breadCrumb,"BOARD");if(d(e))return e;let t=await Je(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Xe({repoRoot:t.value});if(d(n))throw new Error(n.message);let{modifier:r}=V().commandMeta;if(r==="now"){let S=kt(n.value);if(d(S))return a(S.message);let A=fn();if(d(A))return A;let M=yt(S.value).filter(d);return M.length>0?a(M.map(O=>O.message).join(", ")):(N({mode:p.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),c("Peeking now",!0))}let o;if(r==="prev"){let S=v().eventLog.at(-1),A=ro(S);if(A===null)return a("No previous event to peek");o=A}else if(r==="next"){let S=v().unappliedEvents.at(0),A=ro(S);if(A===null)return a("No next event to peek");o=A+1}else{let S=nr(r);if(!S)return a("Invalid peek date");o=S.getTime()}let i=v(),s=e.value.id,l=rs(n.value,o);if(d(l))return a(l.message);let{appliedEvents:u,unappliedEvents:m}=l.value,g=fn();if(d(g))return g;let E=yt(u).filter(d);if(E.length>0)return fn(),N(i),a(E.map(S=>S.message).join(", "));let I=v().nodes[s];return I?(T.navigate({contextNode:I,selectedIndex:0}),N({mode:p.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:m}),c("Peeking",!0)):(fn(),N(i),a("Board did not exist at peek date"))};import im from"zod";var Wa=()=>{let e=V().commandMeta.inputString,t=im.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=ze({autoSyncDebounceMs:t.data});return d(n)?n:(Ce({autoSyncIntervalMs:t.data}),N({mode:p.DEFAULT}),c(`Auto sync interval set to ${t.data}ms`,null))};var Ha=()=>{let e=V().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=Ri(e),n=ze({autoSync:t});return d(n)?n:(Ce({autoSync:t}),N({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))};var ja=()=>{let e=V().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=ze({logLevel:e});return d(n)?n:(Ce({logLevel:e}),N({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))};var Va=async()=>{F(""),N({mode:p.DEFAULT});let e=ot();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");N({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await Qn();return d(t)?(N({syncStatus:{msg:t.message,status:"failed"}}),t):(N({mode:p.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Ka=e=>Object.values(v().tags).find(t=>t.name===e),za=e=>Object.values(v().contributors).find(t=>t.name===e),yr=[{systemOnly:!0,intent:P.Move,description:"Internal move-state command",mode:p.COMMAND_LINE,action:Ba},{intent:P.Delete,description:"Delete the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];return r?Se({id:fe(),action:"delete.node",payload:{id:r.id},...e.value}):a("Unable to resolve child to delete")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=V().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(s=>Z(x.FILTER).map(l=>l.split(n)[0]).includes(s))(r))return a("Invalid filter modifier");let i={target:r,operator:"=",value:t.trim()};return Ne(s=>({...s,filters:e==="clear"?[]:[...s.filters,i],mode:p.DEFAULT})),c("Filter updated",null)}},{intent:P.ViewHelp,description:"Open the help screen",mode:p.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return lt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),N({mode:p.HELP}),c("Viewing help",null)}},{intent:P.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!B(r))return a("Cannot close in this context");let o=v().nodes[He];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let i=await Re();if(d(i))return i;let s=i.value,l=lo(o.id,r.id,{at:"end"},e.value,s);if(d(l))return l;let u=await Se({id:fe(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:l.value},...e.value});return d(u)?u:c("Issue closed",null)},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?c("Resolved ticket",r):nt(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let i=o.value,s=v().nodes[He];if(!s)return a("Unable to locate closed swimlane");if(i.parentNodeId!==s.id)return a("Issue is not closed");if(!B(i))return a("Target node is not issue");let l=ba(i);if(!l)return a("Unable to resolve previous parent from issue history");if(l===s.id)return a("Previous parent resolves to closed swimlane");let u=v().nodes[l];if(!u)return a("Previous parent no longer exists");let m=await Re();if(d(m))return m;let g=m.value,h=lo(u.id,i.id,{at:"end"},e.value,g);if(d(h))return h;let E=await Se({id:fe(),action:"reopen.issue",payload:{id:i.id,parent:u.id,rank:h.value},...e.value});return d(E)?E:c("Issue reopened",null)},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Init,description:"Initialize Epiq in the current git repository",mode:p.COMMAND_LINE,action:Pa},{intent:P.NewItem,description:"Create a new board, swimlane, or issue",mode:p.COMMAND_LINE,action:$a,onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Rename,description:"itle] Rename the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=_(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=Js();return o?Se({id:fe(),action:"edit.title",payload:{id:r.id,name:o},...e.value}):a("Provide a title")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.UntagTicket,description:"Remove a tag from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Ka(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return a("Invalid untag target");let s=nt(i.id,"TICKET");if(d(s))return a("Unable to untag issue in this context");let l=s.value;return B(l)?(l.props.tags??[]).includes(o.id)?Se({id:fe(),action:"remove.issue.tag",payload:{id:l.id,tag:o.id},...e.value}):a("Issue is not tagged with that tag"):a("Target node is not issue")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.TagTicket,description:"Add or create a tag on the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=v();if(!o)return a("Invalid tag target");let i=nt(o.id,"TICKET");if(d(i))return a("Unable to tag issue in this context");let s=i.value;if(!B(s))return a("Target node is not issue");let l=Ka(r),u;if(l)u=l.id;else{let g=fe(),h=await Se({id:fe(),action:"create.tag",payload:{id:g,name:r},...e.value});if(d(h))return h;u=h.value.result.id}return(s.props.tags??[]).includes(u)?a("Already tagged with that tag"):Se({id:fe(),action:"add.issue.tag",payload:{id:s.id,tag:u},...e.value})},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.AssignUserToTicket,description:"Assign a user to the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:i}=v(),s=_(i.id)[o];if(!s)return a("Invalid assign target");let l=nt(s.id,"TICKET");if(d(l))return a("Unable to assign issue in this context");let u=l.value;if(!B(u))return a("Target node is not issue");let m=za(r),g;if(m)g=m.id;else{let E=fe(),I=await Se({id:fe(),action:"create.contributor",payload:{id:E,name:r},...e.value});if(d(I))return I;g=I.value.result.id}return(u.props.assignees??[]).includes(g)?a("Assignee already assigned"):Se({id:fe(),action:"add.issue.assignee",payload:{id:u.id,assignee:g},...e.value})},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Y();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=V().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=za(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return a("Invalid unassign target");let s=nt(i.id,"TICKET");if(d(s))return a("Unable to unassign in this context");let l=s.value;return B(l)?(l.props.assignees??[]).includes(o.id)?Se({id:fe(),action:"remove.issue.assignee",payload:{id:l.id,assignee:o.id},...e.value}):a(`Issue is not assigned to "${r}"`):a("Target node is not issue")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Sync,description:"Pull, commit, and push Epiq state",mode:p.COMMAND_LINE,action:Va},{intent:P.Peek,description:"View board state at another point in time",mode:p.COMMAND_LINE,action:_a},{intent:P.Export,description:"Export the current board layout to markdown",mode:p.COMMAND_LINE,action:async()=>{let e=await pa();return d(e)?e:(N({mode:p.DEFAULT}),c("Export successful",!0))}},{intent:P.Exit,description:"Exit the application",mode:p.COMMAND_LINE,action:async()=>(T.exit(),c("Exit successful",!0))},{intent:P.Edit,description:"Edit title or description",mode:p.COMMAND_LINE,action:async(e,t)=>{if(t.modifier===it.DESCRIPTION)return Ta();if(t.modifier===it.TITLE){let n=Y();if(d(n))return a("Unable to resolve user ID");let{contextNode:r,selectedIndex:o}=v(),i=_(r.id)[o];if(!i)return a("Missing node");if(i.readonly)return a("Cannot rename readonly node");let s=t.inputString.trim();return s?Se({id:fe(),action:"edit.title",payload:{id:i.id,name:s},...n.value}):a("Provide a title")}return a("Unknown edit command")},onSuccess:()=>N({mode:p.DEFAULT})},{intent:P.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:p.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case X.USERNAME:{let{userId:r,preferredEditor:o,userName:i}=$(),s=n||i,l=r??fe();if(!s||!l)return a("Unable to resolve user name or id");let u=ze({userName:s,userId:l,preferredEditor:o??""});return d(u)?u:(Ce({userName:s,userId:l}),N({mode:p.DEFAULT}),c(`Username set to "${s}"`,null))}case X.EDITOR:{if(!n)return a("No editor provided");let r=ze({preferredEditor:n});return d(r)?r:(Ce({preferredEditor:n}),N({mode:p.DEFAULT}),c(`Editor configuration set to "${n}"`,null))}case X.VIEW:return n!=="wide"&&n!=="dense"?a("Invalid view mode"):(Ce({viewMode:n}),c(`View set to "${n}"`,null));case X.AUTOSYNC:return Ha();case X.LOG_LEVEL:return ja();case X.SYNC_DEBOUNCE_MS:return Wa();default:return a("Unknown config command")}}},{intent:P.Coffee,description:"Sponsor the development of Epiq!",mode:p.COMMAND_LINE,action:()=>{let e=V().commandMeta.modifier;return e==="custom"?Oo("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Oo(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),F(""),c("Thanks you!",null)}}];var sm=new Set(["peek","filter","view-help"]),Oe=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=V();if(!t)return a("No command to confirm");if(!e&&n===Nt.Invalid)return a("Invalid command");let i=ar(t);zs();let{readOnly:s}=v();if(s&&!sm.has(i))return mn({status:qe.Fail,message:"Command not available in readonly state",value:null});let l=yr.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!l)return mn({status:qe.Fail,message:"Command not found",value:null});let u;try{u=await l.action(l,{command:t,inputString:o,modifier:r})}catch(m){return mn({status:qe.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?mn(u):(Gs({addToHistory:!e}),l.onSuccess?.(),$().autoSync&&Zn(),u)};var Cr=[{intent:f.Exit,mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(N({mode:p.COMMAND_LINE}),F("move cancel"),Oe({isForceExecutedBySystem:!0}))},{intent:f.InitMove,mode:p.DEFAULT,description:"[m] move (init/confirm)",action:()=>(N({mode:p.COMMAND_LINE}),F("move start"),Oe({isForceExecutedBySystem:!0}))},{intent:f.ConfirmMove,mode:p.MOVE,action:()=>(N({mode:p.COMMAND_LINE}),F("move confirm"),Oe({isForceExecutedBySystem:!0}))}],Er=[{intent:f.MovePreviousItem,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move previous"),Oe({isForceExecutedBySystem:!0})):a("No pending move")},{intent:f.MoveNextItem,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move next"),Oe({isForceExecutedBySystem:!0})):a("No pending move")}],Ga=[{intent:f.MoveToNextContainer,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move to-next"),Oe({isForceExecutedBySystem:!0})):a("No pending move")},{intent:f.MoveToPreviousContainer,mode:p.MOVE,action:()=>ut()?(N({mode:p.COMMAND_LINE}),F("move to-previous"),Oe({isForceExecutedBySystem:!0})):a("No pending move")}];var qa={[w.WORKSPACE]:[...Cr,...Er],[w.BOARD]:[...Cr,...Er],[w.SWIMLANE]:[...Cr,...Er,...Ga],[w.TICKET]:[],[w.FIELD]:[],[w.FIELD_LIST]:[],[w.TEXT]:[]};var Ya=()=>{F("");let{pendingNavTarget:e}=ct();N({mode:p.DEFAULT}),e&&T.navigate(e),lt({pendingNavTarget:void 0})},Xa=[{intent:f.ExitCommandLine,mode:p.HELP,action:()=>(Ya(),c("Exiting help",null))},{intent:f.Exit,mode:p.HELP,action:()=>(Ya(),c("Closed help",null))},{intent:f.NavPreviousItem,mode:p.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),c("Navigating to previous help item",null))},{intent:f.NavNextItem,mode:p.HELP,action:()=>(T.navigateToNextItem(),c("Navigating to next help item",null))},{intent:f.NavToPreviousContainer,mode:p.HELP,action:()=>(T.navigateToPreviousContainer(),c("Navigating to previous help container",null))},{intent:f.NavToNextContainer,mode:p.HELP,action:()=>(T.navigateToNextContainer(),c("Navigating to next help container",null))}];var am=e=>{N({mode:p.COMMAND_LINE});let{pendingNavTarget:t}=ct();t&&T.navigate(t),lt({pendingNavTarget:void 0}),F(`${e} `)},Ja=()=>{F("");let{pendingNavTarget:e}=ct();e&&T.navigate(e),lt({pendingNavTarget:void 0}),N({mode:p.DEFAULT})},Qa=[{intent:f.InitCommandPalette,mode:p.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{F("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return lt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),N({mode:p.PALETTE}),c("Opening command palette",null)}},{intent:f.Confirm,mode:p.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!et(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?(am(t),c("Selected command",t)):c("No command selected",null)}},{intent:f.ExitCommandLine,mode:p.PALETTE,action:()=>(Ja(),c("Exiting palette",null))},{intent:f.Exit,mode:p.PALETTE,action:()=>(Ja(),c("Closed command palette",null))},{intent:f.NavPreviousItem,mode:p.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:f.NavNextItem,mode:p.PALETTE,action:()=>(T.navigateToNextItem(),c("Navigating to next item",null))},{intent:f.NavToPreviousContainer,mode:p.PALETTE,action:()=>(T.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:f.NavToNextContainer,mode:p.PALETTE,action:()=>(T.navigateToNextContainer(),c("Navigating to next container",null))}];var Za=[...Xa,...Qa,{intent:f.AddItem,mode:p.DEFAULT,description:"[n] new...",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.NEW} `),c("Adding new item",null))},{intent:f.Delete,mode:p.DEFAULT,description:"[d] delete",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.DELETE} `),c("Deleting item",null))},{intent:f.InitCommandLine,mode:p.DEFAULT,description:"[:] focus command line",action:()=>(N({mode:p.COMMAND_LINE}),F(""),c("Entering command line mode",null))},{intent:f.Confirm,mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!U(e?.id??"")?.length){if(e?.title===Q.DESCRIPTION)return N({mode:p.COMMAND_LINE}),F(`${x.EDIT} description `),c("Propose command",!0);if(e?.title===Q.ASSIGNEES)return N({mode:p.COMMAND_LINE}),F(`${x.ASSIGN} `),c("Propose command",!0);if(e?.title===Q.TAGS)return N({mode:p.COMMAND_LINE}),F(`${x.TAG} `),c("Propose command",!0);if(t.title===Q.DESCRIPTION&&e?.context==="TEXT")return N({mode:p.COMMAND_LINE}),F(`${x.EDIT} description `),c("Propose command",!0)}return T.enterChildNode(),c("Entering context",null)}},{intent:f.EditTitle,mode:p.DEFAULT,description:"[r] rename title",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.EDIT} title ${v().selectedNode?.title}`),c("Exiting context",null))},{intent:f.EditDescription,mode:p.DEFAULT,description:"[e] edit description",action:()=>(N({mode:p.COMMAND_LINE}),F(`${x.EDIT} description `),c("Exiting context",null))},{intent:f.Exit,mode:p.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),c("Exiting context",null))},{intent:f.NavPreviousItem,mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:f.NavNextItem,mode:p.DEFAULT,action:()=>(T.navigateToNextItem(),c("Navigating to next item",null))},{intent:f.NavToPreviousContainer,mode:p.DEFAULT,action:()=>(T.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:f.NavToNextContainer,mode:p.DEFAULT,action:()=>(T.navigateToNextContainer(),c("Navigating to next container",null))}];var dm=500,cm=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),ed=e=>{let t=cm(e);t&&sr(n=>(n+t).slice(0,dm))};var lm=[p.COMMAND_LINE,p.PALETTE],um=e=>[{intent:f.MoveCursorLeft,mode:e,action:()=>(Io(-1),c("Moving cursor left",null))},{intent:f.MoveCursorRight,mode:e,action:()=>(Io(1),c("Moving cursor right",null))},{intent:f.MoveCursorLeftOfWord,mode:e,action:()=>(Ro("left"),c("Moving cursor left of word",null))},{intent:f.MoveCursorRightOfWord,mode:e,action:()=>(Ro("right"),c("Moving cursor right of word",null))},{intent:f.AutoCompleteCommand,mode:e,action:()=>(sr((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=v().selectedNode?.title??""),r+o}),c("Auto-completing command",null))},{intent:f.CaptureInput,mode:e,action:(t,{sequence:n})=>(ed(n??""),c("Capturing input",null))},{intent:f.EraseInput,mode:e,action:()=>(Vs(),c("Erasing input",null))},{intent:f.EraseInputWord,mode:e,action:()=>(Ks(),c("Erasing input word",null))}],td=[{intent:f.Confirm,mode:p.COMMAND_LINE,action:()=>(Oe(),c("Executing command",null))},{intent:f.ViewHelp,mode:p.DEFAULT,action:()=>(N({mode:p.HELP}),c("Viewing help",null))},...lm.flatMap(um),{intent:f.ExitCommandLine,mode:p.COMMAND_LINE,action:()=>(N({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:f.GetLastCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(qs(),c("Getting last command from history",null))},{intent:f.GetNextCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(Ys(),c("Getting next command from history",null))}];import od from"chalk";var Nr=od.dim.hex(y.secondary2)(": for command line"),nd="q to exit",rd=`${od.hex(y.accent)("m")} to confirm`,Wo={[w.WORKSPACE]:[Nr],[w.BOARD]:[Nr],[w.BOARD+p.COMMAND_LINE]:[Nr],[w.SWIMLANE]:[Nr],[w.TICKET+p.HELP]:[nd],[w.SWIMLANE+p.HELP]:[nd],[w.TICKET]:[],[w.FIELD]:[],[w.SWIMLANE+p.MOVE]:[rd],[w.TICKET+p.MOVE]:[rd]};var vn=e=>e.trim().toLocaleLowerCase(),mm=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},pm=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},id=(e,t)=>{let n=vn(t.value);if(!n)return!0;switch(t.target){case"title":return vn(e.title??"").includes(n);case"description":return vn(e.props.description??"").includes(n);case"tag":return mm(e).map(vn).some(o=>o.includes(n));case"assignee":return pm(e).map(vn).some(o=>o.includes(n));default:return!0}};function sd(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],i=r;for(;i&&(o.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let s=o[o.length-1];return!s||s.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),c("Breadcrumb built",o))}var ad=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 St,Ho,jo=new Set,dd=()=>{for(let e of jo)e()},fm=e=>(jo.add(e),()=>jo.delete(e));function cd(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:i}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let l=o[t];if(!l)return a("Unable to derive state, contextNode not found");let u=sd(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:g}=l,h=Wo[g+n]??Wo[g]??[],E=[...Za,...qa[g]??[],...td],I=ad(E),S=vm(o,i),A=S[t]?.[e.selectedIndex]??null;return c("Derived successfully",{...e,contextNode:l,breadCrumb:m,availableHints:h,availableActions:E,actionIndex:I,selectedNode:A,renderedChildrenIndex:S})}var v=()=>{if(!St)throw new Error("State not initialized. Call initWorkspaceState() first.");return St},ot=()=>St?c("Retrieved state",St):a("State not initialized. Call initWorkspaceState() first.");function rn(e){Ho=e;let t=Ye(process.cwd()),n=!1;if(!d(t)){let i=Qe(t.value);if(d(i))return a(i.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:p.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},o=cd(r);return d(o)?o:(St=o.value,dd(),c("State initialized",null))}function Ne(e){let t=v(),n=e(t),r=cd(n);return d(r)?a(r.message??"Unable to update state"):(St=r.value,dd(),c("State updated",null))}var N=e=>Ne(t=>({...t,...e}));var K=()=>gm(fm,v,v),vm=(e,t)=>{let n={};for(let r of Object.values(e))B(r)&&t.length>0&&!t.every(o=>id(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,i)=>{let s=e[o.id],l=e[i.id];return!s||!l?0:s.rank.localeCompare(l.rank)});return n},_=e=>v()?.renderedChildrenIndex[e]??[],fn=()=>Ho?rn(Ho):a("Cannot reset state: no initial workspace found"),Dt=()=>St!==void 0;import{Box as Vo,Text as xn}from"ink";import Me,{useEffect as xm,useMemo as hm}from"react";import{ulid as ym}from"ulid";var ld=({text:e,match:t,color:n,highlightColor:r=y.secondary,dimColor:o=!1})=>{if(!t)return Me.createElement(xn,{color:n,dimColor:o},e);let i=e.toLowerCase(),s=t.toLowerCase(),l=i.indexOf(s);return l===-1?Me.createElement(xn,{color:n,dimColor:o},e):Me.createElement(xn,{color:n,dimColor:o},e.slice(0,l),Me.createElement(xn,{backgroundColor:r,bold:!0},e.slice(l,l+t.length)),e.slice(l+t.length))},ud=ym(),Cm=e=>`${e}`,Em=e=>{let{pendingNavTarget:t}=ct();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,i=new Set(Z(x.NONE,{breadCrumb:n,contextNode:r,readOnly:v().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(s=>s!=="move").filter(s=>s.length>0).filter(s=>s!==x.PALETTE).map(s=>{let l=ar(s),u=yr.find(m=>m.intent===l);return{command:s,description:u?.description??`[${s}] Run command`,isAvailable:i.has(s)}}).filter(s=>s.command.toLowerCase().startsWith(e)||e.length>=2&&s.description.toLowerCase().includes(e)).sort((s,l)=>s.isAvailable!==l.isAvailable?s.isAvailable?-1:1:s.command.localeCompare(l.command))},Nm=e=>q.text({id:ud,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),bm=(e,t,n)=>q.text({id:Cm(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),Ko=[],Sm=e=>{md();let t=b.createNode(Nm(v().rootNodeId));d(t)||!et(t.value)||(Ko=[t.value,...e.map((n,r)=>bm(n,r,ud)).map(b.createNode).filter(J).map(({value:n})=>n).filter(et)],T.navigate({contextNode:t.value,selectedIndex:0}))},md=()=>{let e=Ko.map(t=>t.id);Ko=[];for(let t of e)b.deleteNode(t)};function pd({width:e,height:t}){let r=Xs().value.trim().toLowerCase(),o=hm(()=>Em(r),[r]);xm(()=>(Sm(o),()=>{md()}),[o]);let i=v().selectedIndex;return Me.createElement(Vo,{flexDirection:"column",width:e,height:t-2},Me.createElement(st,{height:t-4,itemHeight:3,selectedIndex:i},o.map((s,l)=>{let u=l===i,m=s.isAvailable?y.accent:y.secondary2,g=s.isAvailable?"":"[unavailable] ";return Me.createElement(Vo,{key:s.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:y.secondary,borderStyle:"single"},Me.createElement(xn,{color:m,dimColor:!s.isAvailable},u?"\u276F ":" ",Me.createElement(ld,{text:Di(s.command),match:r,color:m,dimColor:!s.isAvailable})),Me.createElement(Vo,{paddingLeft:2},Me.createElement(ld,{text:g+s.description,match:r.length>=2?r:"",color:u&&s.isAvailable?y.primary:y.secondary2,dimColor:!s.isAvailable})))})))}import{Box as Bm}from"ink";import Go from"react";import yn from"chalk";import{Box as zo,Text as gd}from"ink";import hn,{useEffect as Im,useMemo as Rm,useState as Am}from"react";var fd=yn.gray,Tm=yn.inverse,wm=yn.inverse.gray,Mm={hint:"",hints:[],overlap:0,remainder:""},xd=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},Pm=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=be(t);return{bg:r=>yn.bgHex(n).black(r),bgCursor:r=>yn.bgHex(n).inverse.black(r)}}return no(t)},Lm=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=xd({value:e,command:t});if(!r)return null;let i=e.slice(r.end).match(/^\s*/)?.[0].length??0,s=r.end+i;return e.slice(s,s+n.length)!==n?null:{start:s,end:s+n.length}},vd=()=>({value:se.value,cursorPosition:se.cursorPosition,commandIsPending:se.commandIsPending,autoCompletion:se.commandMeta.autoCompletion??Mm,infoMessage:se.commandMeta.infoMessage,validationStatus:se.commandMeta.validity,command:se.commandMeta.command,inputString:se.commandMeta.inputString,modifier:se.commandMeta.modifier}),km=(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,hd=({width:e,mode:t})=>{let[n,r]=Am(vd());Im(()=>{let E=()=>{let S=vd();r(A=>km(A,S)?A:S)},I=So(E);return E(),()=>{I()}},[]);let{value:o,cursorPosition:i,infoMessage:s,commandIsPending:l,autoCompletion:u,command:m,modifier:g}=n,h=Rm(()=>{let E=Math.max(0,Math.min(i,o.length)),I=xd({value:o,command:m}),S=Lm({value:o,command:m,modifier:g}),A=m?no(m):null,R=Pm({command:m,modifier:g}),M=(re,ue)=>{let At=I&&ue>=I.start&&ue<I.end,ft=S&&ue>=S.start&&ue<S.end;return At&&A?A.fg(re):ft&&R?R.bg(re):re},O=(re,ue)=>{let At=I&&ue>=I.start&&ue<I.end,ft=S&&ue>=S.start&&ue<S.end;return At&&A?A.fgCursor(re):ft&&R?R.bgCursor(re):Tm(re)},Ie=o.slice(0,E),le=o[E]??" ",Kt=E<o.length?o.slice(E+1):"",Sn=Array.from(Ie).map((re,ue)=>M(re,ue)).join(""),Rt=O(le,E),zt=Array.from(Kt).map((re,ue)=>M(re,E+1+ue)).join("");if(u.hint){let re=u.hint[u.overlap]??le;Rt=wm(re),zt=fd(u.remainder.slice(1)+Kt)}return fd(t===p.PALETTE?"?":":")+Sn+Rt+zt},[o,i,u,m,g]);return hn.createElement(zo,{flexDirection:"column",justifyContent:"flex-start"},hn.createElement(zo,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},hn.createElement(zo,null,hn.createElement(gd,null,h),s&&hn.createElement(gd,{wrap:"truncate",color:l?y.red:y.secondary2},` ${s} `))))};import{Box as Dm,Text as Fm}from"ink";import yd from"react";var Om=(e,t)=>{let n=[],r=0;for(let o of e){let s=(n.length>0?" | ":"").length+o.length;if(r+s>t-4)break;n.push(o),r+=s}return n},Cd=({width:e,availableHints:t})=>{let n=Om(t,e).join(" | ");return yd.createElement(Dm,{width:e,borderStyle:"round",borderColor:y.secondary,paddingX:1},yd.createElement(Fm,{color:y.secondary2},n.length?n:"\xA0"))};var Cn=({width:e,mode:t,availableHints:n})=>{let r=[],o=0;for(let i of n){let l=(r.length>0?" | ":"").length+i.length;if(o+l>e+2)break;r.push(i),o+=l}return Go.createElement(Bm,null,t===p.COMMAND_LINE||t===p.PALETTE?Go.createElement(hd,{width:e,mode:t}):Go.createElement(Cd,{width:e,mode:t,availableHints:n}))};import{Box as mt,Text as jt}from"ink";import ce,{useEffect as Um,useMemo as $m}from"react";import{ulid as Ed}from"ulid";var Sr=Ed(),_m=()=>[...new Set([...v().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),Wm=e=>q.text({id:Sr,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),Hm=(e,t,n)=>q.text({id:Ed(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),br=[],Nd=()=>{let e=br.filter(n=>n.id!==Sr).map(n=>n.id),t=br.filter(n=>n.id===Sr).map(n=>n.id);br=[];for(let n of[...e,...t])b.deleteNode(n)},jm=e=>{Nd();let t=b.createNode(Wm(v().rootNodeId));if(d(t)||!et(t.value))return logger.error("Could not attach help nodes");br=[t.value,...e.map((n,r)=>Hm(n,r,Sr)).map(b.createNode).filter(J).map(({value:n})=>n).filter(et)],T.navigate({contextNode:t.value,selectedIndex:0})},bd=({width:e,height:t})=>{let n=$m(()=>_m(),[]);Um(()=>(jm(n),()=>{Nd()}),[n]);let r=v().selectedIndex;return ce.createElement(mt,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,height:t-2},ce.createElement(mt,{paddingX:1,justifyContent:"center"},ce.createElement(jt,{color:y.accent},"Help"),ce.createElement(jt,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),ce.createElement(mt,{paddingX:1,marginTop:1},ce.createElement(mt,{width:20,justifyContent:"flex-end"},ce.createElement(jt,{color:y.secondary},"Key(s)")),ce.createElement(mt,{flexGrow:1,width:40,paddingLeft:2},ce.createElement(jt,{color:y.secondary},"Action"))),ce.createElement(st,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:i},s)=>{let l=s===r;return ce.createElement(mt,{paddingX:1,key:`${o}-${i}-${s}`,flexDirection:"row"},ce.createElement(mt,{width:20,justifyContent:"flex-end"},ce.createElement(jt,{color:y.accent},o)),ce.createElement(mt,{flexGrow:1,width:40,paddingLeft:2},ce.createElement(jt,{color:l?y.primary:y.secondary2},i)))})))};import Vm from"chalk";import{Box as Ir,Text as Ge}from"ink";import xe from"react";var Sd=({width:e,height:t})=>xe.createElement(Ir,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},xe.createElement(Ge,{color:y.accent,bold:!0},"Initialize project"),xe.createElement(Ge,null,`This folder is not an ${Vm.hex(y.accent)("epiq")} project yet.`),xe.createElement(Ge,{color:y.primary},"To start tracking issues here, we need to initialize a new",xe.createElement(Ge,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json "),"file in this repository."),xe.createElement(Ir,{marginTop:1,flexDirection:"column"},xe.createElement(Ir,null,xe.createElement(Ge,{color:y.accent}," "),xe.createElement(Ge,{color:y.primary},"Type "),xe.createElement(Ge,{backgroundColor:y.secondary}," :init "))),xe.createElement(Ir,{marginTop:1},xe.createElement(Ge,{color:y.secondary2},"This will create, commit and push "),xe.createElement(Ge,{color:y.primary,backgroundColor:y.secondary}," .epiq/project.json ")));import{Box as Rr,Text as Be}from"ink";import ne from"react";var Km=({isDone:e,command:t,value:n})=>ne.createElement(Rr,null,ne.createElement(Be,{color:y.accent,dimColor:e},e?" \u2714 ":" "),ne.createElement(Be,{dimColor:e},"Type "),ne.createElement(Be,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n!==void 0&&ne.createElement(ne.Fragment,null,ne.createElement(Be,{dimColor:e}," "),ne.createElement(Be,{color:y.secondary,dimColor:e},"<"+n+">"))),zm=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function qo({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:i,autoSync:s,isSetAutoSync:l}=Ze(),u=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:i,message:"Nice. Now pick your editor."},{key:"autosync",done:l,command:":config autosync",value:s,message:"Almost there. Configure auto sync."}],m=u.findIndex(h=>!h.done),g=m===-1?void 0:u[m];return ne.createElement(Rr,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},ne.createElement(Be,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),ne.createElement(Be,null,"Let's get you started - it's a breeze."),ne.createElement(Be,{color:y.secondary2},"Remember - you can always search available commands by typing:",ne.createElement(Be,{color:y.accent}," ? ")),g&&ne.createElement(Be,{color:y.secondary2},g.message),ne.createElement(Rr,{flexDirection:"column"},u.map((h,E)=>m===-1||E<=m?ne.createElement(Rr,{key:h.key,marginBottom:1},ne.createElement(Km,{isDone:h.done,command:h.command,value:h.done?zm(h.value):void 0})):null)))}import Pr from"chalk";import{Box as Mr,Text as Vt}from"ink";import ae from"react";var Id="0.6.19";import{Box as Ar,Text as Gm}from"ink";import It from"react";var Rd=({width:e})=>{let{viewMode:t}=$(),n=K(),{breadCrumb:r,contextNode:o,selectedIndex:i,renderedChildrenIndex:s}=n,l=s[o.id]?.[i],u=nt(l?.id??o.id,"TICKET"),m=J(u)?u.value:void 0,g=m?.props.tags??[],h=m?.props.assignees??[],E=m?.parentNodeId?!Qr(o.id,m.parentNodeId)&&t==="dense":!1,I=r.map((R,M)=>{let O=M===r.length-1,Ie=U(R.id),le=O?Ie?.[i]?.title:void 0;return`${M?" / ":""}${R.title??""}${le?` \u25B8 ${le}`:""}`}).join(""),S=g.reduce((R,M)=>R+(b.getTag(M)?.name.length??0)+4,0)+h.reduce((R,M)=>R+(b.getContributor(M)?.name.length??0)+4,0),A=e-S;return It.createElement(Ar,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},It.createElement(Ar,{overflow:"hidden",width:A},It.createElement(Gm,{wrap:"truncate-end",color:y.secondary2},I)),E?g.map(R=>It.createElement(Ar,{key:R,paddingLeft:1},It.createElement(_t,{id:R}))):null,E?h.map(R=>It.createElement(Ar,{key:R,paddingLeft:1},It.createElement($t,{id:R}))):null)};import{Box as qm,Text as Ad}from"ink";import Tr from"react";var Ym=({filters:e})=>Tr.createElement(qm,{columnGap:1},Tr.createElement(Ad,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Tr.createElement(Ad,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Td=Tr.memo(Ym);import{Box as Xm,Text as wr}from"ink";import En from"react";function wd(){let{eventLog:e,unappliedEvents:t}=K(),n=e.at(-1)?.id,r=Hn(n??""),o=J(r)?Xi(r.value):"INVALID DATE";return En.createElement(Xm,{paddingLeft:1},En.createElement(wr,{backgroundColor:y.accent}," Readonly "),En.createElement(wr,{color:y.accent}," "+t.length+" edits ago at "+o+"."),En.createElement(wr,{color:y.accent}," Resume with "),En.createElement(wr,{backgroundColor:y.accent}," :peek now "))}import Yo from"chalk";import{Box as Jm,Text as Md}from"ink";import Xo,{useEffect as Qm,useState as Zm}from"react";var ep=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],Pd=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)}},tp=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},np=(e,t,n)=>{let r=Pd(e),o=Pd(t);return tp({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},rp=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,i=e[r],s=e[Math.min(r+1,e.length-1)];return np(i,s,o)};function Ld({syncStatus:e,autoSync:t}){let[n,r]=Zm(0);Qm(()=>{if(e.status!=="syncing"){r(0);return}let l=setInterval(()=>{r(u=>u+1)},50);return()=>clearInterval(l)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},s={synced:y.secondary2,failed:y.yellow,pending:y.secondary2,syncing:rp(ep,(Math.sin(n*.12)+1)/2)??""}[e.status];return Xo.createElement(Jm,null,Xo.createElement(Md,null,Yo.hex(y.secondary2).dim(t?"AutoSync: ":"Sync: ")),Xo.createElement(Md,null,Yo.hex(s)("\u25CF")+Yo.hex(y.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}function Nn({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o}=K(),{userName:i,preferredEditor:s,autoSync:l}=$(),u=64,m=process.stdout.columns-u-8;return ae.createElement(Mr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},t?ae.createElement(Vt,null," "):o===p.PALETTE?ae.createElement(Mr,null,ae.createElement(Vt,{color:y.accent},"Command Palette"),ae.createElement(Vt,{dimColor:!0,color:y.secondary2}," ","- search, select and press enter")):ae.createElement(Mr,{paddingLeft:1},e.length>0?ae.createElement(Td,{filters:e}):ae.createElement(Rd,{width:m})),n==="live"?ae.createElement(Mr,{columnGap:1,paddingRight:2,"max-width":u,overflow:"hidden",justifyContent:"flex-end"},ae.createElement(Ld,{autoSync:!!l,syncStatus:r}),ae.createElement(Vt,null,Pr.hex(y.secondary2).dim("Mode: ")+Pr.hex(y.secondary2).dim(o.padEnd(8," "))," "),ae.createElement(kd,{icon:"@",value:i}),ae.createElement(kd,{icon:"\u276F",value:s}),ae.createElement(Vt,{dimColor:!0,color:y.secondary2},Id+" ")):"",n==="peek"?ae.createElement(wd,null):"")}function kd({icon:e,value:t}){return ae.createElement(Vt,null,Pr.dim(e)+Pr.hex(y.accent)(` ${t??"-"} `))}import{Box as op,Text as ip}from"ink";import bn from"react";import{Box as Lr,Text as Jo}from"ink";import pt from"react";function Qo(){let e=K(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,i=process.stdout.columns||120,s=t?.id?_(t?.id):[];return pt.createElement(Lr,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:y.secondary,width:i},pt.createElement(Lr,{padding:1,paddingTop:0,paddingBottom:0},pt.createElement(Jo,null,"Select a board:")),pt.createElement(Lr,{padding:1,flexDirection:"column"},s.map((l,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,h=_(l.id).flatMap(({id:E})=>U(E)).length;return pt.createElement(Lr,{key:l.id??u},pt.createElement(Jo,{color:m?y.accent:y.secondary2},pt.createElement(ge,{isSelected:m})),pt.createElement(Jo,{color:m?y.accent:y.secondary2},l.title," (",h," issues)",l.readonly?" \u{1F512}":""))})))}var sp=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:i,width:s})=>{let{renderedChildrenIndex:l}=K(),u=n.find(({context:E})=>E==="BOARD"),h=i-1-3;return bn.createElement(op,{flexDirection:"row"},e.context==="WORKSPACE"?bn.createElement(Qo,null):u?bn.createElement(gr,{height:h,width:s,swimlanes:(l[u.id]??[]).filter(E=>E!==void 0&&Mt(E)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):bn.createElement(ip,null))},Dd=bn.memo(sp);import{useEffect as ap}from"react";var dp=e=>{ap(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:i,preferredEditor:s}=$();s&&i&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:l,mode:u}=v();u==="default"&&!l&&Zn(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},Fd=({autoSync:e})=>(dp(e),null);function Zo({width:e,height:t}){let n=K(),{autoSync:r,viewMode:o}=bi(),i=n.filters;if(n.mode===p.HELP)return z.createElement(gt,{flexDirection:"column"},z.createElement(bd,{width:e,height:t}));if(n.mode===p.PALETTE)return z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{filters:i}),z.createElement(pd,{width:e,height:t-2}),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:s}=Ze(),l=!s,u=s&&!n.hasProjectDefinition;if(l)return z.createElement(gt,{flexDirection:"column"},z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{hideBreadCrumb:!0,filters:i}),z.createElement(qo,{height:t,width:e})),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return z.createElement(gt,{flexDirection:"column"},z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{hideBreadCrumb:!0,filters:i}),z.createElement(Sd,{height:t,width:e})),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Ee(n.breadCrumb??[],"BOARD");if(J(m)){let g=m.value.id,h=_(g).length,E=3,I=Math.floor(e/E),S=Math.floor(e/Math.max(h,1));e=Math.min(S,I)*Math.max(h,E)}return z.createElement(gt,{flexDirection:"column"},z.createElement(Fd,{autoSync:r}),z.createElement(gt,{flexDirection:"column"},z.createElement(Nn,{filters:i}),z.createElement(Dd,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),z.createElement(Cn,{width:e,mode:n.mode,availableHints:n.availableHints}))}import cp from"readline";var kr,Dr,Ue,lp=new Set([f.MoveCursorLeft,f.EraseInputWord,f.MoveCursorLeftOfWord,f.MoveCursorRight,f.MoveCursorRightOfWord,f.NavToPreviousContainer,f.NavToNextContainer,f.NavPreviousItem,f.NavNextItem,f.SetViewDense,f.SetViewWide,f.Confirm,f.Exit,f.InitCommandLine,f.InitCommandPalette,f.ExitCommandLine,f.CaptureInput,f.EraseInput,f.EraseInputWord,f.HideHelp,f.ViewHelp,f.SetViewDense,f.SetViewWide,f.GetLastCommandFromHistory,f.GetNextCommandFromHistory,f.AutoCompleteCommand]),Od=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r}=v(),o=Qs(e,n);if(!o||r&&!lp.has(o))return;let i=t[n]?.[o];if(i?.action)try{await i.action(i,e)}catch(s){logger.error(s)}},up=()=>async function(t,n){n.name!=="escape"&&(Ue&&(clearTimeout(Ue),Ue=void 0),await Od(n))},mp=()=>async function(t){if(t.length===1&&t[0]===27){Ue&&clearTimeout(Ue),Ue=setTimeout(()=>{Od({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),Ue=void 0},25);return}Ue&&(clearTimeout(Ue),Ue=void 0)};function Bd(){kr&&process.stdin.removeListener("keypress",kr),Dr&&process.stdin.removeListener("data",Dr),kr=up(),Dr=mp(),cp.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Dr),process.stdin.on("keypress",kr)}Ia();gp(`${Fr.bold("Epiq CLI")}
|
|
58
58
|
|
|
59
59
|
${Fr.dim("Boot in directory:")}
|
|
60
60
|
${Fr.cyan("$ epiq")}
|
package/dist/mcp.js
CHANGED
|
@@ -55,7 +55,7 @@ ${o.message}`):c("Staged state branch event file",void 0)},_a=async({repoRoot:e,
|
|
|
55
55
|
${i.message}`):c("Pushed state branch",!0)},$a=async({repoRoot:e,stateBranchRoot:t,ensureUpstream:n})=>{let r=!1,o=ut(e);if(a(o))return o;let i=o.value,d=[Hn(),await rm({repoRoot:e,stateBranchName:i}),await Wo({repoRoot:e,stateBranchRoot:t,stateBranchName:i}),await sm({stateBranchRoot:t,stateBranchName:i}),await $i(t),n?await am({stateBranchRoot:t,repoRoot:e}):c("Skipped state branch upstream bootstrap",!1)];for(let l of d){if(a(l))return s(l.message);r=r||!!l.value}return c(n?"Bootstrapped state storage":"Bootstrapped state storage readonly",r)}});import{monotonicFactory as dm,ulid as Xe}from"ulid";function cm(){let e=Fe();if(a(e))return s("Unable to boot. State not initialized");let t=e.value,n=Object.values(t.nodes).find(i=>i.context==="WORKSPACE");if(!n)throw new Error("No workspace found in event log");let[r]=q(n.id),[o]=r?q(r.id):[];if(o){let i=t.renderedChildrenIndex?.[o.id]??[];return c("Resolved boot nav target",{contextNode:o,selectedIndex:i.length>0?0:-1})}else return r?c("Resolved boot nav target",{contextNode:r,selectedIndex:0}):n?c("Resolved boot nav target",{contextNode:n,selectedIndex:0}):c("Resolved boot nav target",{contextNode:t.nodes[t.rootNodeId],selectedIndex:0})}function lm(){let e=cm();return a(e)?e:L.navigate(e.value)}function Wa({userId:e,userName:t}){let n=Nn(),r=Nn(),o=Nn(),i=Nn(),d=Nn(),l=me(void 0,void 0);if(a(l))return l;let u=me(void 0,void 0);if(a(u))return u;let m=me(u.value,void 0);if(a(m))return m;let g=me(void 0,void 0);if(a(g))return g;let x=me(g.value,void 0);if(a(x))return x;let b=me(x.value,void 0);if(a(b))return b;let R=me(void 0,void 0);return a(R)?R:c("Created default events",[{id:Xe(),userId:e,userName:t,action:"init.workspace",payload:{id:n,name:"Workspace",rank:l.value}},{id:Xe(),userId:e,userName:t,action:"add.board",payload:{id:r,name:"Default",parent:n,rank:u.value}},{id:Xe(),userId:e,userName:t,action:"add.swimlane",payload:{id:o,name:"Todo",parent:r,rank:g.value}},{id:Xe(),userId:e,userName:t,action:"add.swimlane",payload:{id:i,name:"In progress",parent:r,rank:x.value}},{id:Xe(),userId:e,userName:t,action:"add.swimlane",payload:{id:d,name:"Done",parent:r,rank:b.value}},{id:Xe(),userId:e,userName:t,action:"add.board",payload:{id:Sr,name:"Closed",parent:n,rank:m.value}},{id:Xe(),userId:e,userName:t,action:"add.swimlane",payload:{id:ue,name:"Closed",parent:Sr,rank:R.value}},{id:Xe(),userId:e,userName:t,action:"lock.node",payload:{id:Sr}},{id:Xe(),userId:e,userName:t,action:"lock.node",payload:{id:ue}}])}function wr(e){if(!e.length){let r=ve.workspace("temporary-uninitialized-workspace","Workspace","a0"),o=In(r);return a(o)?o:(E({hasProjectDefinition:!1,mode:p.DEFAULT}),c("Booted uninitialized workspace placeholder",null))}if(!e.some(r=>r.action==="init.workspace"))return s("Initialized Epiq project has no workspace init event");let n=Nt(e).filter(a);return n.length>0?s(`Materializing failed:
|
|
56
56
|
${n.map(r=>r.message).join(`
|
|
57
57
|
`)}`):(lm(),E({hasProjectDefinition:!0}),c("State booted successfully",null))}var Nn,Tr=y(()=>{"use strict";Te();G();C();gn();T();At();Kt();xn();Nn=dm()});import um from"node:fs";import ja from"node:path";var mm,V,Ha,za=y(()=>{"use strict";Oa();On();Pt();Tt();jo();Te();cn();Tr();Kt();Me();G();C();wt();ie();ge();T();re();mm=async e=>{let t=await _({cwd:e,args:["status","--porcelain"]});return a(t)?t:c("Checked git diff",t.value.stdout.trim().length>0)},V=(e,t)=>s(`[${e}] ${t}`),Ha=async()=>{W("");let e=xi(),t=await nt(process.cwd());if(a(t))return V(1,t.message);let n=t.value,r=await _n(n);if(a(r))return V(2,r.message);if(r.value)return V(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await mm(n);if(a(o))return V(2.5,o.message);if(o.value)return V(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(Zr(n))return V(4,"Epiq project already initialized");let i=Jn();if(!i.isSetupDone||!i.userName)return V(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let d=Y(),l=d.userName,u=d.userId;if(!u||!l)return V(5,"Missing Epiq user id");let m=e.stateBranch,g=await $n({repoRoot:n,branch:m});if(a(g))return V(6,g.message);if(g.value)return V(6,`State branch already exists: ${m}`);let x=await $o({repoRoot:n,stateBranchName:m});if(a(x))return V(6,x.message);let b=Hn();if(a(b))return V(7,b.message);let R=ja.join(jn(),e.projectId),I=await Wo({repoRoot:n,stateBranchRoot:R,stateBranchName:m});if(a(I))return V(8,I.message);let k=ja.join(R,".epiq");um.mkdirSync(k,{recursive:!0});let A=Wa({userId:u,userName:l});if(a(A))return V(9,A.message);for(let Wr of A.value){let mi=Cr({event:Wr,rootDir:R});if(a(mi))return V(9,mi.message)}let U=await Ar({stateBranchRoot:R,eventFileName:ht({userId:u,userName:l})});if(a(U))return V(10,U.message);let j=await Mt({cwd:R,message:"[epiq:init]"});if(a(j))return V(10,j.message);let lt=await Da(n);if(a(lt))return V(11,lt.message);let Je=Ei({repoRoot:n,fileContents:e});if(a(Je))return V(12,Je.message);let si=await K.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(a(si))return V(13,si.message);let ai=await K.commit({cwd:n,message:"[epiq:init-project]"});if(a(ai))return V(13,ai.message);let _r="Project initialized!",di=await _({cwd:n,args:["push","-u","origin","HEAD"]});a(di)&&(_r+=` Warn: [init:14] ${di.message}`);let ci=await En({repoRoot:n,stateBranchRoot:R});a(ci)&&(_r+=` Warn: [init:15] ${ci.message}`);let li=Nt(A.value).filter(a);if(li.length>0)return V(16,li.map(Wr=>Wr.message).join(`
|
|
58
|
-
`));let $r=Fe();if(a($r))return V(16,$r.message);let{rootNodeId:Tc,nodes:Mc}=$r.value,ui=Mc[Tc];return ui?(L.navigate({contextNode:ui,selectedIndex:0}),E({hasProjectDefinition:!0,mode:p.DEFAULT}),c(_r,null)):V(16,"Unable to resolve initialized root node")}});import{ulid as pm}from"ulid";function zo(e){let t=qa();if(a(t))return t;let{contextNode:n,nodes:r}=v();if(!n.parentNodeId)return s("Missing parent node id");let o=r[n.parentNodeId];if(!o)return s("Missing parent node");let i=H(o.id),d=i.findIndex(({id:m})=>m===n.id);if(d<0)return s("Current node not found among siblings");let l=i[d+e];if(!l)return s("Missing sibling node");let u=Ka({id:t.value.id,parentId:l.id,position:{at:"end"}});return a(u)?u:Ga(u.value)}function Vo(e){let t=qa();if(a(t))return t;let{contextNode:n,selectedIndex:r}=v(),i=H(n.id)[r+e];if(!i)return s("Missing sibling node");let d=Ka({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:i.id}});return a(d)?d:Ga(d.value)}var Va,dt,bn,qa,Ho,Ka,Ga,qo=y(()=>{"use strict";Kt();Me();C();Se();T();Va=null,dt=()=>structuredClone(Va),bn=e=>{Va=e},qa=()=>{let{contextNode:e,selectedIndex:t}=v(),r=H(e.id)[t];return r?c("Resolved selected child",r):s("Target node not found")},Ho=({id:e,parentId:t,position:n={at:"end"}})=>{let r=H(t).filter(o=>o.id!==e);return Mr(r,n)},Ka=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Q();if(a(r))return s("Unable to resolve user ID");let o=Ho({parentId:t,id:e,position:n});return a(o)?o:c("Created pending move state",{id:pm(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Ga=e=>{bn(e);let t=Cn(e,!0);return a(t)?t:c("Node moved successfully",t.value)}});import{ulid as gm}from"ulid";var Ya,Lr,Xa,Ja=y(()=>{"use strict";Te();qo();Et();Me();G();C();Se();ie();T();re();Ya=()=>{let e=dt();if(!e)return s("No pending move state");let t=e.payload.id,n=e.payload.parent,r=v().nodes[n];if(!r)return s("Move parent not found");let o=H(n).findIndex(i=>i.id===t);return o===-1?s("Moved node not found among rendered children"):(L.navigate({contextNode:r,selectedIndex:o}),c("Synchronized navigation to moved node",null))},Lr=(e,t="Moved preview")=>{if(a(e))return e;let n=Ya();return a(n)?n:(E({mode:p.MOVE}),c(t,null))},Xa=async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t}=J().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=H(n.id)[r];if(!o)return E({mode:p.DEFAULT}),s("No move target");if(t==="start"){if(o.readonly)return s("Target node is read-only");if(r===-1)return s("No item selected");if(!o.parentNodeId)return s("Target has no parent");let i=H(o.parentNodeId),d=i.findIndex(({id:x})=>x===o.id);if(d===-1)return s("Target not found among siblings");let l=i[d-1],u=i[d+1],m=u!=null?{at:"before",sibling:u.id}:l!=null?{at:"after",sibling:l.id}:{at:"start"},g=Ho({parentId:o.parentNodeId,id:o.id,position:m});return a(g)?g:(bn({id:gm(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:g.value.rank},...e.value}),E({mode:p.MOVE}),c("Move initialized",null))}if(t==="next")return Lr(Vo(1));if(t==="previous")return Lr(Vo(-1));if(t==="to-next")return Lr(zo(1));if(t==="to-previous")return Lr(zo(-1));if(t==="confirm"){let i=dt();if(!i)return s("No pending move to confirm");let d=await Ae();if(a(d))return d;let l=Le(i,d.value);if(a(l))return l;let u=Ya();return a(u)?u:(bn(null),E({mode:p.DEFAULT}),c("Moved item",null))}return t==="cancel"?(bn(null),E({mode:p.DEFAULT}),c("Cancelling move",null)):s("Invalid move modifier")}});import{monotonicFactory as fm,ulid as vm}from"ulid";var ym,Pr,Ko=y(()=>{"use strict";C();ym=fm(),Pr=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let i=ym();return c("Created issue events",[{id:vm(),userId:r,userName:o,action:"add.issue",payload:{id:i,parent:t,name:e,rank:n}}])}});import{ulid as kr}from"ulid";var Qa,Za=y(()=>{"use strict";Te();Ko();Et();Me();un();C();ae();Se();T();re();Qa=async(e,t)=>{let n=Q();if(a(n))return s("Unable to resolve user ID");let r=await Ae();if(a(r))return r;let o=r.value;if(!t.inputString)return s(`provide a name for your ${t.modifier}`);let{breadCrumb:i,contextNode:d,selectedIndex:l}=v(),u=m=>{let g=Le(m,o);if(a(g))return g;let x=N.getNode(g.value.result.id);if(!x)return s("Created node not found");if(!x.parentNodeId)return g;let b=N.getNode(x.parentNodeId);return b?(L.navigate({contextNode:b,selectedIndex:N.getSiblings(x.parentNodeId).findIndex(({id:R})=>R===x.id)}),g):s("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),g=N.getNode(m);if(!g)return s("Workspace not found");let x=Gt(g.id,n.value,o);return a(x)?x:u({id:kr(),action:"add.board",payload:{id:kr(),name:t.inputString,parent:g.id,rank:x.value},...n.value})}if(t.modifier==="swimlane"){let m=De(i,"BOARD");if(a(m))return s("Unable to add swimlane in this context");let g=Gt(m.value.id,n.value,o);return a(g)?g:u({id:kr(),action:"add.swimlane",payload:{id:kr(),name:t.inputString,parent:m.value.id,rank:g.value},...n.value})}if(t.modifier==="issue"){let m=q(d.id)[l],g=d.context==="SWIMLANE"?d:d.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=De(i,"SWIMLANE");return a(j)?null:j.value})();if(!g)return s("Unable to add issue in this context");let x=Gt(g.id,n.value,o);if(a(x))return x;let b=Pr({name:t.inputString,parent:g.id,rank:x.value,user:n.value});if(a(b))return b;let R=b.value,I=It(R,o);if(I.some(j=>a(j)))return s("Issue create failed: "+I.filter(a).map(j=>j.message).filter(Boolean).join(", "));let k=I[0];if(!k||a(k))return s("Issue creation failed");let U=R.find(j=>j.action==="add.issue")?.payload.id;return U?(L.navigate({contextNode:g,selectedIndex:N.getSiblings(g.id).findIndex(({id:j})=>j===U)}),c("Issue created",null)):s("Unable to determine ticket id")}return c("Success",null)}});var ed,td=y(()=>{"use strict";Pt();Te();ir();vn();Kt();G();un();C();ie();T();rr();ed=async()=>{let e=De(v().breadCrumb,"BOARD");if(a(e))return e;let t=await nt(process.cwd());if(a(t))return s("Unable to locate repo root");let n=Lt({repoRoot:t.value});if(a(n))throw new Error(n.message);let{modifier:r}=J().commandMeta;if(r==="now"){let I=zt(n.value);if(a(I))return s(I.message);let k=Sn();if(a(k))return k;let U=Nt(I.value).filter(a);return U.length>0?s(U.map(j=>j.message).join(", ")):(E({mode:p.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),c("Peeking now",!0))}let o;if(r==="prev"){let I=v().eventLog.at(-1),k=ao(I);if(k===null)return s("No previous event to peek");o=k}else if(r==="next"){let I=v().unappliedEvents.at(0),k=ao(I);if(k===null)return s("No next event to peek");o=k+1}else{let I=nr(r);if(!I)return s("Invalid peek date");o=I.getTime()}let i=v(),d=e.value.id,l=Na(n.value,o);if(a(l))return s(l.message);let{appliedEvents:u,unappliedEvents:m}=l.value,g=Sn();if(a(g))return g;let b=Nt(u).filter(a);if(b.length>0)return Sn(),E(i),s(b.map(I=>I.message).join(", "));let R=v().nodes[d];return R?(L.navigate({contextNode:R,selectedIndex:0}),E({mode:p.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:m}),c("Peeking",!0)):(Sn(),E(i),s("Board did not exist at peek date"))}});import xm from"zod";var nd,rd=y(()=>{"use strict";Ht();G();C();ie();ge();T();nd=()=>{let e=J().commandMeta.inputString,t=xm.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return s("Auto sync duration must be a number of at least 3000 ms");let n=Ye({autoSyncDebounceMs:t.data});return a(n)?n:(ke({autoSyncIntervalMs:t.data}),E({mode:p.DEFAULT}),c(`Auto sync interval set to ${t.data}ms`,null))}});var od,id=y(()=>{"use strict";cn();Ht();G();C();ie();ge();T();od=()=>{let e=J().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return s("Invalid response");let t=os(e),n=Ye({autoSync:t});return a(n)?n:(ke({autoSync:t}),E({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))}});var sd,ad=y(()=>{"use strict";Ht();G();C();ie();ge();T();sd=()=>{let e=J().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return s("Invalid response");let n=Ye({logLevel:e});return a(n)?n:(ke({logLevel:e}),E({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))}});var dd,cd=y(()=>{"use strict";Xn();G();C();ie();T();dd=async()=>{W(""),E({mode:p.DEFAULT});let e=Fe();if(a(e))return s(e.message);if(e.value.syncStatus.status==="syncing")return s("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await qe();return a(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:p.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)}});import{ulid as ye}from"ulid";var ld,ud,md,pd=y(()=>{"use strict";ca();Te();Ht();Et();Me();wa();xn();G();Z();C();ae();Se();ie();ge();T();Rr();re();Ta();gt();yo();ln();Fa();za();Ja();Za();td();rd();id();ad();cd();ld=e=>Object.values(v().tags).find(t=>t.name===e),ud=e=>Object.values(v().contributors).find(t=>t.name===e),md=[{systemOnly:!0,intent:M.Move,description:"Internal move-state command",mode:p.COMMAND_LINE,action:Xa},{intent:M.Delete,description:"Delete the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];return r?Ie({id:ye(),action:"delete.node",payload:{id:r.id},...e.value}):s("Unable to resolve child to delete")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=J().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(d=>oe(f.FILTER).map(l=>l.split(n)[0]).includes(d))(r))return s("Invalid filter modifier");let i={target:r,operator:"=",value:t.trim()};return be(d=>({...d,filters:e==="clear"?[]:[...d.filters,i],mode:p.DEFAULT})),c("Filter updated",null)}},{intent:M.ViewHelp,description:"Open the help screen",mode:p.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return at({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:p.HELP}),c("Viewing help",null)}},{intent:M.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];if(!r)return s("Unable to close issue, no target found");if(!B(r))return s("Cannot close in this context");let o=v().nodes[ue];if(!o)return s("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return s("Issue is already closed");let i=await Ae();if(a(i))return i;let d=i.value,l=Xt(o.id,r.id,{at:"end"},e.value,d);if(a(l))return l;let u=await Ie({id:ye(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:l.value},...e.value});return a(u)?u:c("Issue closed",null)},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];if(!r)return s("Unable to reopen issue, no target found");let o=r.context==="TICKET"?c("Resolved ticket",r):Yt(r.id,"TICKET");if(a(o))return s("Cannot reopen in this context");let i=o.value,d=v().nodes[ue];if(!d)return s("Unable to locate closed swimlane");if(i.parentNodeId!==d.id)return s("Issue is not closed");if(!B(i))return s("Target node is not issue");let l=Aa(i);if(!l)return s("Unable to resolve previous parent from issue history");if(l===d.id)return s("Previous parent resolves to closed swimlane");let u=v().nodes[l];if(!u)return s("Previous parent no longer exists");let m=await Ae();if(a(m))return m;let g=m.value,x=Xt(u.id,i.id,{at:"end"},e.value,g);if(a(x))return x;let b=await Ie({id:ye(),action:"reopen.issue",payload:{id:i.id,parent:u.id,rank:x.value},...e.value});return a(b)?b:c("Issue reopened",null)},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Init,description:"Initialize Epiq in the current git repository",mode:p.COMMAND_LINE,action:Ha},{intent:M.NewItem,description:"Create a new board, swimlane, or issue",mode:p.COMMAND_LINE,action:Qa,onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Rename,description:"itle] Rename the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];if(!r)return s("Missing node");if(r.readonly)return s("Cannot rename readonly node");let o=Bs();return o?Ie({id:ye(),action:"edit.title",payload:{id:r.id,name:o},...e.value}):s("Provide a title")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.UntagTicket,description:"Remove a tag from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide a tag");let o=ld(r);if(!o)return s(`Tag "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid untag target");let d=Yt(i.id,"TICKET");if(a(d))return s("Unable to untag issue in this context");let l=d.value;return B(l)?(l.props.tags??[]).includes(o.id)?Ie({id:ye(),action:"remove.issue.tag",payload:{id:l.id,tag:o.id},...e.value}):s("Issue is not tagged with that tag"):s("Target node is not issue")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.TagTicket,description:"Add or create a tag on the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide a tag");let{selectedNode:o}=v();if(!o)return s("Invalid tag target");let i=Yt(o.id,"TICKET");if(a(i))return s("Unable to tag issue in this context");let d=i.value;if(!B(d))return s("Target node is not issue");let l=ld(r),u;if(l)u=l.id;else{let g=ye(),x=await Ie({id:ye(),action:"create.tag",payload:{id:g,name:r},...e.value});if(a(x))return x;u=x.value.result.id}return(d.props.tags??[]).includes(u)?s("Already tagged with that tag"):Ie({id:ye(),action:"add.issue.tag",payload:{id:d.id,tag:u},...e.value})},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.AssignUserToTicket,description:"Assign a user to the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee");let{selectedIndex:o,contextNode:i}=v(),d=q(i.id)[o];if(!d)return s("Invalid assign target");let l=Yt(d.id,"TICKET");if(a(l))return s("Unable to assign issue in this context");let u=l.value;if(!B(u))return s("Target node is not issue");let m=ud(r),g;if(m)g=m.id;else{let b=ye(),R=await Ie({id:ye(),action:"create.contributor",payload:{id:b,name:r},...e.value});if(a(R))return R;g=R.value.result.id}return(u.props.assignees??[]).includes(g)?s("Assignee already assigned"):Ie({id:ye(),action:"add.issue.assignee",payload:{id:u.id,assignee:g},...e.value})},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee to remove");let o=ud(r);if(!o)return s(`Assignee "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid unassign target");let d=Yt(i.id,"TICKET");if(a(d))return s("Unable to unassign in this context");let l=d.value;return B(l)?(l.props.assignees??[]).includes(o.id)?Ie({id:ye(),action:"remove.issue.assignee",payload:{id:l.id,assignee:o.id},...e.value}):s(`Issue is not assigned to "${r}"`):s("Target node is not issue")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Sync,description:"Pull, commit, and push Epiq state",mode:p.COMMAND_LINE,action:dd},{intent:M.Peek,description:"View board state at another point in time",mode:p.COMMAND_LINE,action:ed},{intent:M.Export,description:"Export the current board layout to markdown",mode:p.COMMAND_LINE,action:async()=>{let e=await da();return a(e)?e:(E({mode:p.DEFAULT}),c("Export successful",!0))}},{intent:M.Exit,description:"Exit the application",mode:p.COMMAND_LINE,action:async()=>(L.exit(),c("Exit successful",!0))},{intent:M.Edit,description:"Edit title or description",mode:p.COMMAND_LINE,action:async(e,t)=>{if(t.modifier===rt.DESCRIPTION)return ka();if(t.modifier===rt.TITLE){let n=Q();if(a(n))return s("Unable to resolve user ID");let{contextNode:r,selectedIndex:o}=v(),i=q(r.id)[o];if(!i)return s("Missing node");if(i.readonly)return s("Cannot rename readonly node");let d=t.inputString.trim();return d?Ie({id:ye(),action:"edit.title",payload:{id:i.id,name:d},...n.value}):s("Provide a title")}return s("Unknown edit command")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:p.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case X.USERNAME:{let{userId:r,preferredEditor:o,userName:i}=Y(),d=n||i,l=r??ye();if(!d||!l)return s("Unable to resolve user name or id");let u=Ye({userName:d,userId:l,preferredEditor:o??""});return a(u)?u:(ke({userName:d,userId:l}),E({mode:p.DEFAULT}),c(`Username set to "${d}"`,null))}case X.EDITOR:{if(!n)return s("No editor provided");let r=Ye({preferredEditor:n});return a(r)?r:(ke({preferredEditor:n}),E({mode:p.DEFAULT}),c(`Editor configuration set to "${n}"`,null))}case X.VIEW:return n!=="wide"&&n!=="dense"?s("Invalid view mode"):(ke({viewMode:n}),c(`View set to "${n}"`,null));case X.AUTOSYNC:return od();case X.LOG_LEVEL:return sd();case X.SYNC_DEBOUNCE_MS:return nd();default:return s("Unknown config command")}}},{intent:M.Coffee,description:"Sponsor the development of Epiq!",mode:p.COMMAND_LINE,action:()=>{let e=J().commandMeta.modifier;return e==="custom"?Bo("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Bo(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),c("Thanks you!",null)}}]});var hm,$e,Go=y(()=>{"use strict";Yn();dr();yo();pd();C();ie();ge();T();hm=new Set(["peek","filter","view-help"]),$e=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=J();if(!t)return s("No command to confirm");if(!e&&n===yt.Invalid)return s("Invalid command");let i=_s(t);Fs();let{readOnly:d}=v();if(d&&!hm.has(i))return pn({status:Qe.Fail,message:"Command not available in readonly state",value:null});let l=md.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!l)return pn({status:Qe.Fail,message:"Command not found",value:null});let u;try{u=await l.action(l,{command:t,inputString:o,modifier:r})}catch(m){return pn({status:Qe.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return a(u)?pn(u):(Ds({addToHistory:!e}),l.onSuccess?.(),Y().autoSync&&ts(),u)}});var Fr,Dr,gd,fd=y(()=>{"use strict";C();G();T();mt();Go();qo();ie();Fr=[{intent:S.Exit,mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:p.COMMAND_LINE}),W("move cancel"),$e({isForceExecutedBySystem:!0}))},{intent:S.InitMove,mode:p.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:p.COMMAND_LINE}),W("move start"),$e({isForceExecutedBySystem:!0}))},{intent:S.ConfirmMove,mode:p.MOVE,action:()=>(E({mode:p.COMMAND_LINE}),W("move confirm"),$e({isForceExecutedBySystem:!0}))}],Dr=[{intent:S.MovePreviousItem,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move previous"),$e({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveNextItem,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move next"),$e({isForceExecutedBySystem:!0})):s("No pending move")}],gd=[{intent:S.MoveToNextContainer,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move to-next"),$e({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveToPreviousContainer,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move to-previous"),$e({isForceExecutedBySystem:!0})):s("No pending move")}]});var vd,yd=y(()=>{"use strict";Z();fd();vd={[w.WORKSPACE]:[...Fr,...Dr],[w.BOARD]:[...Fr,...Dr],[w.SWIMLANE]:[...Fr,...Dr,...gd],[w.TICKET]:[],[w.FIELD]:[],[w.FIELD_LIST]:[],[w.TEXT]:[]}});var xd,hd,Ed=y(()=>{"use strict";G();C();ie();T();Rr();mt();Te();xd=()=>{W("");let{pendingNavTarget:e}=Vt();E({mode:p.DEFAULT}),e&&L.navigate(e),at({pendingNavTarget:void 0})},hd=[{intent:S.ExitCommandLine,mode:p.HELP,action:()=>(xd(),c("Exiting help",null))},{intent:S.Exit,mode:p.HELP,action:()=>(xd(),c("Closed help",null))},{intent:S.NavPreviousItem,mode:p.HELP,description:"[arrows/hjkl] navigate",action:()=>(L.navigateToPreviousItem(),c("Navigating to previous help item",null))},{intent:S.NavNextItem,mode:p.HELP,action:()=>(L.navigateToNextItem(),c("Navigating to next help item",null))},{intent:S.NavToPreviousContainer,mode:p.HELP,action:()=>(L.navigateToPreviousContainer(),c("Navigating to previous help container",null))},{intent:S.NavToNextContainer,mode:p.HELP,action:()=>(L.navigateToNextContainer(),c("Navigating to next help container",null))}]});var Em,Nd,Id,bd=y(()=>{"use strict";G();Z();C();ie();T();Rr();mt();Te();Em=e=>{E({mode:p.COMMAND_LINE});let{pendingNavTarget:t}=Vt();t&&L.navigate(t),at({pendingNavTarget:void 0}),W(`${e} `)},Nd=()=>{W("");let{pendingNavTarget:e}=Vt();e&&L.navigate(e),at({pendingNavTarget:void 0}),E({mode:p.DEFAULT})},Id=[{intent:S.InitCommandPalette,mode:p.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return at({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:p.PALETTE}),c("Opening command palette",null)}},{intent:S.Confirm,mode:p.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!pi(e))return s("Command only applicable on text nodes");if(e.props.disabled)return s("Command is not available in this context");let t=e.title;return t?(Em(t),c("Selected command",t)):c("No command selected",null)}},{intent:S.ExitCommandLine,mode:p.PALETTE,action:()=>(Nd(),c("Exiting palette",null))},{intent:S.Exit,mode:p.PALETTE,action:()=>(Nd(),c("Closed command palette",null))},{intent:S.NavPreviousItem,mode:p.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(L.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.PALETTE,action:()=>(L.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.PALETTE,action:()=>(L.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.PALETTE,action:()=>(L.navigateToNextContainer(),c("Navigating to next container",null))}]});var Cd,Sd=y(()=>{"use strict";gt();G();C();kt();Se();ie();T();mt();Ed();bd();Te();Cd=[...hd,...Id,{intent:S.AddItem,mode:p.DEFAULT,description:"[n] new...",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.NEW} `),c("Adding new item",null))},{intent:S.Delete,mode:p.DEFAULT,description:"[d] delete",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.DELETE} `),c("Deleting item",null))},{intent:S.InitCommandLine,mode:p.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:p.COMMAND_LINE}),W(""),c("Entering command line mode",null))},{intent:S.Confirm,mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!H(e?.id??"")?.length){if(e?.title===ee.DESCRIPTION)return E({mode:p.COMMAND_LINE}),W(`${f.EDIT} description `),c("Propose command",!0);if(e?.title===ee.ASSIGNEES)return E({mode:p.COMMAND_LINE}),W(`${f.ASSIGN} `),c("Propose command",!0);if(e?.title===ee.TAGS)return E({mode:p.COMMAND_LINE}),W(`${f.TAG} `),c("Propose command",!0);if(t.title===ee.DESCRIPTION&&e?.context==="TEXT")return E({mode:p.COMMAND_LINE}),W(`${f.EDIT} description `),c("Propose command",!0)}return L.enterChildNode(),c("Entering context",null)}},{intent:S.EditTitle,mode:p.DEFAULT,description:"[r] rename title",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.EDIT} title ${v().selectedNode?.title}`),c("Exiting context",null))},{intent:S.EditDescription,mode:p.DEFAULT,description:"[e] edit description",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.EDIT} description `),c("Exiting context",null))},{intent:S.Exit,mode:p.DEFAULT,description:"[q] exit context",action:()=>(L.enterParentNode(),c("Exiting context",null))},{intent:S.NavPreviousItem,mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(L.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.DEFAULT,action:()=>(L.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.DEFAULT,action:()=>(L.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.DEFAULT,action:()=>(L.navigateToNextContainer(),c("Navigating to next container",null))}]});var Nm,Im,Rd,Ad=y(()=>{"use strict";ie();Nm=500,Im=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Rd=e=>{let t=Im(e);t&&ur(n=>(n+t).slice(0,Nm))}});var bm,Cm,wd,Td=y(()=>{"use strict";Ad();G();C();ie();T();mt();Go();bm=[p.COMMAND_LINE,p.PALETTE],Cm=e=>[{intent:S.MoveCursorLeft,mode:e,action:()=>(fo(-1),c("Moving cursor left",null))},{intent:S.MoveCursorRight,mode:e,action:()=>(fo(1),c("Moving cursor right",null))},{intent:S.MoveCursorLeftOfWord,mode:e,action:()=>(vo("left"),c("Moving cursor left of word",null))},{intent:S.MoveCursorRightOfWord,mode:e,action:()=>(vo("right"),c("Moving cursor right of word",null))},{intent:S.AutoCompleteCommand,mode:e,action:()=>(ur((t,{remainder:n})=>n?t+n:t),c("Auto-completing command",null))},{intent:S.CaptureInput,mode:e,action:(t,{sequence:n})=>(Rd(n??""),c("Capturing input",null))},{intent:S.EraseInput,mode:e,action:()=>(Ps(),c("Erasing input",null))},{intent:S.EraseInputWord,mode:e,action:()=>(ks(),c("Erasing input word",null))}],wd=[{intent:S.Confirm,mode:p.COMMAND_LINE,action:()=>($e(),c("Executing command",null))},{intent:S.ViewHelp,mode:p.DEFAULT,action:()=>(E({mode:p.HELP}),c("Viewing help",null))},...bm.flatMap(Cm),{intent:S.ExitCommandLine,mode:p.COMMAND_LINE,action:()=>(E({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:S.GetLastCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(Os(),c("Getting last command from history",null))},{intent:S.GetNextCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(Us(),c("Getting next command from history",null))}]});import Pd from"chalk";var Or,Md,Ld,Yo,kd=y(()=>{"use strict";G();Z();xe();Or=Pd.dim.hex(P.secondary2)(": for command line"),Md="q to exit",Ld=`${Pd.hex(P.accent)("m")} to confirm`,Yo={[w.WORKSPACE]:[Or],[w.BOARD]:[Or],[w.BOARD+p.COMMAND_LINE]:[Or],[w.SWIMLANE]:[Or],[w.TICKET+p.HELP]:[Md],[w.SWIMLANE+p.HELP]:[Md],[w.TICKET]:[],[w.FIELD]:[],[w.SWIMLANE+p.MOVE]:[Ld],[w.TICKET+p.MOVE]:[Ld]}});var Rn,Sm,Rm,Fd,Dd=y(()=>{"use strict";T();Rn=e=>e.trim().toLocaleLowerCase(),Sm=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Rm=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},Fd=(e,t)=>{let n=Rn(t.value);if(!n)return!0;switch(t.target){case"title":return Rn(e.title??"").includes(n);case"description":return Rn(e.props.description??"").includes(n);case"tag":return Sm(e).map(Rn).some(o=>o.includes(n));case"assignee":return Rm(e).map(Rn).some(o=>o.includes(n));default:return!0}}});function Od(e,t,n){let r=t[e];if(!r)return s("buildBreadCrumb(): current node not found");let o=[],i=r;for(;i&&(o.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let d=o[o.length-1];return!d||d.id!==n?s("buildBreadCrumb(): node is not connected to root"):(o.reverse(),c("Breadcrumb built",o))}var Ud=y(()=>{"use strict";C()});var Bd,_d=y(()=>{"use strict";Bd=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t}});import{useSyncExternalStore as Am}from"react";function Wd(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:i}=e;if(!t)return s("derive(): contextNodeId is missing");if(!r)return s("derive(): rootNode is missing");if(!o[r])return s("derive(): unable to find root node");let l=o[t];if(!l)return s("Unable to derive state, contextNode not found");let u=Od(t,o,r);if(a(u))return logger.error(u.message),u;let m=u.value,{context:g}=l,x=Yo[g+n]??Yo[g]??[],b=[...Cd,...vd[g]??[],...wd],R=Bd(b),I=Tm(o,i),k=I[t]?.[e.selectedIndex]??null;return c("Derived successfully",{...e,contextNode:l,breadCrumb:m,availableHints:x,availableActions:b,actionIndex:R,selectedNode:k,renderedChildrenIndex:I})}function In(e){Xo=e;let t=tt(process.cwd()),n=!1;if(!a(t)){let i=et(t.value);if(a(i))return s(i.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:p.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},o=Wd(r);return a(o)?o:(bt=o.value,$d(),c("State initialized",null))}function be(e){let t=v(),n=e(t),r=Wd(n);return a(r)?s(r.message??"Unable to update state"):(bt=r.value,$d(),c("State updated",null))}var bt,Xo,Jo,$d,wm,v,Fe,E,Be,Tm,q,Sn,Ot,T=y(()=>{"use strict";yd();Sd();Td();kd();wt();G();Z();C();re();Dd();Ud();_d();Jo=new Set,$d=()=>{for(let e of Jo)e()},wm=e=>(Jo.add(e),()=>Jo.delete(e));v=()=>{if(!bt)throw new Error("State not initialized. Call initWorkspaceState() first.");return bt},Fe=()=>bt?c("Retrieved state",bt):s("State not initialized. Call initWorkspaceState() first.");E=e=>be(t=>({...t,...e})),Be=()=>Am(wm,v,v),Tm=(e,t)=>{let n={};for(let r of Object.values(e))B(r)&&t.length>0&&!t.every(o=>Fd(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,i)=>{let d=e[o.id],l=e[i.id];return!d||!l?0:d.rank.localeCompare(l.rank)});return n},q=e=>v()?.renderedChildrenIndex[e]??[],Sn=()=>Xo?In(Xo):s("Cannot reset state: no initial workspace found"),Ot=()=>bt!==void 0});var Yt,Mm,Ct,N,ae=y(()=>{"use strict";Z();C();T();Se();Yt=(e,t)=>{let{nodes:n}=v(),r=n[e];if(!r)return s("Node not found");if(r.context===t)return c("Resolved ancestor node",r);let o=r.parentNodeId?n[r.parentNodeId]:void 0;for(;o;){if(o.context===t)return c("Resolved ancestor node",o);o=o.parentNodeId?n[o.parentNodeId]:void 0}return s(`No ancestor found for context: ${t}`)},Mm=(e,t)=>{let{nodes:n}=v(),r=n[e];for(;r?.parentNodeId;){if(r.parentNodeId===t)return!0;r=n[r.parentNodeId]}return!1},Ct=(e,t)=>e?e.readonly?s({move:"Cannot move readonly node",rename:"Cannot rename readonly node",edit:"Cannot edit readonly node"}[t]):null:s("Node not found"),N={deleteNode(e){be(t=>{let n={...t.nodes};return delete n[e],{...t,nodes:n}})},editValue(e,t){let{nodes:n}=v(),r=n[e];if(!r)return s("Edit target node not found");let o=Ct(r,"edit");if(o)return o;let i={...r,props:{...r.props,description:t}};return this.updateNode(i),c("Issue description updated",{md:t})},renameNode(e,t){let n=this.getNode(e);if(!n)return s("Rename target node not found");let r=Ct(n,"rename");if(r)return r;let o={...n,title:t};return this.updateNode(o),c("Renamed node",o)},getExistingTags(){let{tags:e}=v();return[...new Set(Object.values(e).map(t=>t.name).filter(Boolean))]},getExistingAssignees(){let{contributors:e}=v();return[...new Set(Object.values(e).map(t=>t.name).filter(Boolean))]},getFieldByTitle(e,t){return H(e).find(n=>n.title===t)},moveNodeToRank({id:e,parentId:t,rank:n}){let{rootNodeId:r}=v(),o=this.getNode(e),i=this.getNode(t);if(!o)return s("Node not found");if(!i)return s("Target parent not found");if(r===e)return s("Cannot move root node");if(e===t)return s("Cannot move node into itself");let d=Ct(o,"move");if(d)return d;if(Mm(t,e))return s("Cannot move node into its own descendant");let l={...o,parentNodeId:t,rank:n};return this.updateNode(l),c("Moved node successfully",l)},tombstoneNode(e){let{nodes:t,contextNodeId:n,rootNodeId:r}=v(),o=this.getNode(e);if(!o)return s("Node not found");if(r===e)return s("Cannot delete root node");let i=new Set,d=u=>{let m=t[u];if(!(!m||i.has(u))){i.add(u);for(let g of H(m.id))d(g.id)}};d(e);let l={...structuredClone(t)};for(let u of i){if(!l[u])return s("Unable to locate node to delete");l[u]={...l[u],isDeleted:!0}}return n?(E({nodes:l}),c("Successfully tomb stoned",o)):s("Unable to delete undefined")},createContributor(e){let t=be(n=>({...n,contributors:{...n.contributors,[e.id]:e}}));return a(t)?s("Unable to create contributor"):c("Created contributor",e)},assign(e,t){let n=this.getContributor(t),r=this.getNode(e);if(!n)return s("Unable to assign contributor, missing contributor");if(!r)return s("Unable to assign contributor, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.assignees??[];if(i.includes(t))return s("Contributor already assigned");let d={...r,props:{...r.props,assignees:[...i,t]}};return this.updateNode(d),c("Assigned contributor",{assignee:t})},unassign(e,t){let n=this.getContributor(t),r=this.getNode(e);if(!n)return s("Unable to unassign, missing contributor");if(!r)return s("Unable to unassign, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.assignees??[];if(!i.includes(t))return c("Issue is not assigned to that contributor",{assignee:t});let d={...r,props:{...r.props,assignees:i.filter(l=>l!==t)}};return this.updateNode(d),c("Assignee removed",{assignee:t})},tag(e,t){let n=this.getTag(t),r=this.getNode(e);if(!n)return s("Unable to add tag, missing tag");if(!r)return s("Unable to add tag, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.tags??[];if(i.includes(t))return s("Tag already assigned");let d={...r,props:{...r.props,tags:[...i,t]}};return this.updateNode(d),c("Tag added",{tag:t})},untag(e,t){let n=this.getTag(t),r=this.getNode(e);if(!n)return s("Unable to remove tag, missing tag");if(!r)return s("Unable to remove tag, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.tags??[];if(!i.includes(t))return c("Issue is not tagged with that tag",{tag:t});let d={...r,props:{...r.props,tags:i.filter(l=>l!==t)}};return this.updateNode(d),c("Tag removed",{tag:t})},createTag(e){let t=be(n=>({...n,tags:{...n.tags,[e.id]:e}}));return a(t)?s("Could not create tag"):c("Tag created",e)},createNode(e){let t=be(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return a(t)?s("Unable to create node"):c("Node created",e)},lockNode(e){let t=this.getNode(e);if(!t)return s("Failed to locate node");let n={...t,readonly:!0},r=be(o=>({...o,nodes:{...o.nodes,[e]:n}}));return a(r)?s(r.message):c("Locked node",n)},updateNode(e){let t=be(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return a(t)?t:c("Updated node",e)},getContributor(e){return v().contributors[e]},getTag(e){return v().tags[e]},getNode(e){return v().nodes[e]},getSiblings(e){return H(e)}}});import St from"chalk";import jd from"string-width";import{decodeTime as Lm}from"ulid";var Pm,km,Fm,Dm,Om,Um,Bm,_m,$m,Hd,zd=y(()=>{"use strict";ae();T();vt();ir();Pm=(e,t)=>e+" ".repeat(Math.max(0,t-jd(e))),km=(e,t)=>" ".repeat(Math.max(0,t-jd(e)))+e,Fm=e=>({"add.issue":"Created with title","add.issue.assignee":"Assigned to","remove.issue.assignee":"Unassigned from","close.issue":"Closed","delete.node":"Deleted","edit.title":"Changed title to","edit.description":"Changed description","reopen.issue":"Reopened","add.issue.tag":"Tagged with","remove.issue.tag":"Removed tag","lock.node":"Locked node","move.node":"Moved issue"})[e]??(e.endsWith("e")?`${e}d`:`${e}ed`),Dm=(e,t)=>t?e<t?"up":e>t?"down":null:null,Om=(e,t)=>{let n=N.getNode(e.payload.parent),r=n?St.dim.bgBlack(` ${n.title} `):"unknown",o=t.at(-1);if(o&&"parent"in o&&"rank"in o&&o.parent===e.payload.parent){let i=Dm(e.payload.rank,o.rank);if(i)return`Moved ${i} in ${r}`}return`Moved issue to ${r}`},Um=e=>{switch(e.action){case"add.issue.tag":{let t=v().tags[e.payload.tag];return t?St.bgHex(Oe(t.name))(` ${t.name} `):"unknown tag"}case"remove.issue.tag":{let t=v().tags[e.payload.tag];return t?St.bgHex(Oe(t.name))(` ${t.name} `):"unknown tag"}case"add.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?St.hex(Oe(t.name))(` ${t.name} `):"unknown user"}case"remove.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?St.hex(Oe(t.name))(` ${t.name} `):"unknown user"}case"add.board":case"add.swimlane":case"add.issue":case"add.field":case"create.tag":case"create.contributor":case"edit.title":return`"${"name"in e.payload?e.payload.name:""}"`;default:return""}},Bm=e=>{let t=us(Lm(e));return St.gray(km(t,8))},_m=12,$m=e=>Pm(`${e}`,_m),Hd=(e,t)=>{let n=Bm(e.id),r=$m(e.userName),o=St.dim("\u203A"),i=e.action==="move.node"?Om(e,t):[Fm(e.action),Um(e)].filter(Boolean).join(" ");return`${r} ${n} ${o} ${i}`}});var Wm,jm,Hm,zm,Vd,qd,Kd,Vm,Gd=y(()=>{"use strict";zd();Z();C();kt();ae();gn();T();At();bo();Wm=e=>ot(e,"description"),jm=e=>ot(e,"assignees"),Hm=e=>ot(e,"tags"),zm=e=>ot(e,"history"),Vd=({id:e,name:t,parentNodeId:n,rank:r,value:o,readonly:i=!1,childRenderAxis:d="horizontal"})=>{let l=N.getNode(e);if(!l){let g=N.createNode({...ve.field({id:e,name:t,parentNodeId:n,rank:r,props:{value:o},isVirtual:!0}),readonly:i,childRenderAxis:d});return a(g)?g:c("Virtual field created",void 0)}if(!Ze(l))return s(`Existing virtual node ${e} is not a field`);if(!(l.title!==t||l.parentNodeId!==n||l.rank!==r||l.props.value!==o||l.readonly!==i||l.childRenderAxis!==d))return c("Virtual field unchanged",void 0);let m=N.updateNode({...l,title:t,parentNodeId:n,rank:r,props:{...l.props,value:o},readonly:i,childRenderAxis:d});return a(m)?m:c("Virtual field updated",void 0)},qd=({id:e,name:t,parentNodeId:n,rank:r,readonly:o=!1,childRenderAxis:i="horizontal"})=>{let d=N.getNode(e);if(!d){let m=N.createNode({...ve.fieldList({id:e,name:t,parentNodeId:n,rank:r,isVirtual:!0}),readonly:o,childRenderAxis:i});return a(m)?m:c("Virtual field list created",void 0)}if(!Qt(d))return s(`Existing virtual node ${e} is not a field list`);if(!(d.title!==t||d.parentNodeId!==n||d.rank!==r||d.readonly!==o||d.childRenderAxis!==i))return c("Virtual field list unchanged",void 0);let u=N.updateNode({...d,title:t,parentNodeId:n,rank:r,readonly:o,childRenderAxis:i});return a(u)?u:c("Virtual field list updated",void 0)},Kd=e=>{let t=Ce(He/4n),n=Ce(He/2n),r=Ce(He*3n/4n),o=Ce(He*7n/8n);if(a(t))return t;if(a(n))return n;if(a(r))return r;if(a(o))return o;let i=Vd({id:Wm(e.id),name:ee.DESCRIPTION,parentNodeId:e.id,rank:t.value,value:e.props.description??"",childRenderAxis:"vertical"});if(a(i))return i;let d=qd({id:jm(e.id),name:ee.ASSIGNEES,parentNodeId:e.id,rank:n.value,readonly:!0});if(a(d))return d;let l=qd({id:Hm(e.id),name:ee.TAGS,parentNodeId:e.id,rank:r.value,readonly:!0});if(a(l))return l;let u=Vd({id:zm(e.id),name:ee.HISTORY,parentNodeId:e.id,rank:o.value,value:Vm(e),readonly:!0,childRenderAxis:"vertical"});return a(u)?u:c("Ticket virtual nodes materialized",void 0)},Vm=e=>{let t=[...e.log].reverse(),n=new Map;for(let r of t){let o=n.get(r.action)??[];o.push(r.payload),n.set(r.action,o)}return t.map(r=>Hd(r,n.get(r.action)??[])).join(`
|
|
58
|
+
`));let $r=Fe();if(a($r))return V(16,$r.message);let{rootNodeId:Tc,nodes:Mc}=$r.value,ui=Mc[Tc];return ui?(L.navigate({contextNode:ui,selectedIndex:0}),E({hasProjectDefinition:!0,mode:p.DEFAULT}),c(_r,null)):V(16,"Unable to resolve initialized root node")}});import{ulid as pm}from"ulid";function zo(e){let t=qa();if(a(t))return t;let{contextNode:n,nodes:r}=v();if(!n.parentNodeId)return s("Missing parent node id");let o=r[n.parentNodeId];if(!o)return s("Missing parent node");let i=H(o.id),d=i.findIndex(({id:m})=>m===n.id);if(d<0)return s("Current node not found among siblings");let l=i[d+e];if(!l)return s("Missing sibling node");let u=Ka({id:t.value.id,parentId:l.id,position:{at:"end"}});return a(u)?u:Ga(u.value)}function Vo(e){let t=qa();if(a(t))return t;let{contextNode:n,selectedIndex:r}=v(),i=H(n.id)[r+e];if(!i)return s("Missing sibling node");let d=Ka({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:i.id}});return a(d)?d:Ga(d.value)}var Va,dt,bn,qa,Ho,Ka,Ga,qo=y(()=>{"use strict";Kt();Me();C();Se();T();Va=null,dt=()=>structuredClone(Va),bn=e=>{Va=e},qa=()=>{let{contextNode:e,selectedIndex:t}=v(),r=H(e.id)[t];return r?c("Resolved selected child",r):s("Target node not found")},Ho=({id:e,parentId:t,position:n={at:"end"}})=>{let r=H(t).filter(o=>o.id!==e);return Mr(r,n)},Ka=({id:e,parentId:t,position:n={at:"end"}})=>{let r=Q();if(a(r))return s("Unable to resolve user ID");let o=Ho({parentId:t,id:e,position:n});return a(o)?o:c("Created pending move state",{id:pm(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Ga=e=>{bn(e);let t=Cn(e,!0);return a(t)?t:c("Node moved successfully",t.value)}});import{ulid as gm}from"ulid";var Ya,Lr,Xa,Ja=y(()=>{"use strict";Te();qo();Et();Me();G();C();Se();ie();T();re();Ya=()=>{let e=dt();if(!e)return s("No pending move state");let t=e.payload.id,n=e.payload.parent,r=v().nodes[n];if(!r)return s("Move parent not found");let o=H(n).findIndex(i=>i.id===t);return o===-1?s("Moved node not found among rendered children"):(L.navigate({contextNode:r,selectedIndex:o}),c("Synchronized navigation to moved node",null))},Lr=(e,t="Moved preview")=>{if(a(e))return e;let n=Ya();return a(n)?n:(E({mode:p.MOVE}),c(t,null))},Xa=async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t}=J().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=H(n.id)[r];if(!o)return E({mode:p.DEFAULT}),s("No move target");if(t==="start"){if(o.readonly)return s("Target node is read-only");if(r===-1)return s("No item selected");if(!o.parentNodeId)return s("Target has no parent");let i=H(o.parentNodeId),d=i.findIndex(({id:x})=>x===o.id);if(d===-1)return s("Target not found among siblings");let l=i[d-1],u=i[d+1],m=u!=null?{at:"before",sibling:u.id}:l!=null?{at:"after",sibling:l.id}:{at:"start"},g=Ho({parentId:o.parentNodeId,id:o.id,position:m});return a(g)?g:(bn({id:gm(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:g.value.rank},...e.value}),E({mode:p.MOVE}),c("Move initialized",null))}if(t==="next")return Lr(Vo(1));if(t==="previous")return Lr(Vo(-1));if(t==="to-next")return Lr(zo(1));if(t==="to-previous")return Lr(zo(-1));if(t==="confirm"){let i=dt();if(!i)return s("No pending move to confirm");let d=await Ae();if(a(d))return d;let l=Le(i,d.value);if(a(l))return l;let u=Ya();return a(u)?u:(bn(null),E({mode:p.DEFAULT}),c("Moved item",null))}return t==="cancel"?(bn(null),E({mode:p.DEFAULT}),c("Cancelling move",null)):s("Invalid move modifier")}});import{monotonicFactory as fm,ulid as vm}from"ulid";var ym,Pr,Ko=y(()=>{"use strict";C();ym=fm(),Pr=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let i=ym();return c("Created issue events",[{id:vm(),userId:r,userName:o,action:"add.issue",payload:{id:i,parent:t,name:e,rank:n}}])}});import{ulid as kr}from"ulid";var Qa,Za=y(()=>{"use strict";Te();Ko();Et();Me();un();C();ae();Se();T();re();Qa=async(e,t)=>{let n=Q();if(a(n))return s("Unable to resolve user ID");let r=await Ae();if(a(r))return r;let o=r.value;if(!t.inputString)return s(`provide a name for your ${t.modifier}`);let{breadCrumb:i,contextNode:d,selectedIndex:l}=v(),u=m=>{let g=Le(m,o);if(a(g))return g;let x=N.getNode(g.value.result.id);if(!x)return s("Created node not found");if(!x.parentNodeId)return g;let b=N.getNode(x.parentNodeId);return b?(L.navigate({contextNode:b,selectedIndex:N.getSiblings(x.parentNodeId).findIndex(({id:R})=>R===x.id)}),g):s("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),g=N.getNode(m);if(!g)return s("Workspace not found");let x=Gt(g.id,n.value,o);return a(x)?x:u({id:kr(),action:"add.board",payload:{id:kr(),name:t.inputString,parent:g.id,rank:x.value},...n.value})}if(t.modifier==="swimlane"){let m=De(i,"BOARD");if(a(m))return s("Unable to add swimlane in this context");let g=Gt(m.value.id,n.value,o);return a(g)?g:u({id:kr(),action:"add.swimlane",payload:{id:kr(),name:t.inputString,parent:m.value.id,rank:g.value},...n.value})}if(t.modifier==="issue"){let m=q(d.id)[l],g=d.context==="SWIMLANE"?d:d.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=De(i,"SWIMLANE");return a(j)?null:j.value})();if(!g)return s("Unable to add issue in this context");let x=Gt(g.id,n.value,o);if(a(x))return x;let b=Pr({name:t.inputString,parent:g.id,rank:x.value,user:n.value});if(a(b))return b;let R=b.value,I=It(R,o);if(I.some(j=>a(j)))return s("Issue create failed: "+I.filter(a).map(j=>j.message).filter(Boolean).join(", "));let k=I[0];if(!k||a(k))return s("Issue creation failed");let U=R.find(j=>j.action==="add.issue")?.payload.id;return U?(L.navigate({contextNode:g,selectedIndex:N.getSiblings(g.id).findIndex(({id:j})=>j===U)}),c("Issue created",null)):s("Unable to determine ticket id")}return c("Success",null)}});var ed,td=y(()=>{"use strict";Pt();Te();ir();vn();Kt();G();un();C();ie();T();rr();ed=async()=>{let e=De(v().breadCrumb,"BOARD");if(a(e))return e;let t=await nt(process.cwd());if(a(t))return s("Unable to locate repo root");let n=Lt({repoRoot:t.value});if(a(n))throw new Error(n.message);let{modifier:r}=J().commandMeta;if(r==="now"){let I=zt(n.value);if(a(I))return s(I.message);let k=Sn();if(a(k))return k;let U=Nt(I.value).filter(a);return U.length>0?s(U.map(j=>j.message).join(", ")):(E({mode:p.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),c("Peeking now",!0))}let o;if(r==="prev"){let I=v().eventLog.at(-1),k=ao(I);if(k===null)return s("No previous event to peek");o=k}else if(r==="next"){let I=v().unappliedEvents.at(0),k=ao(I);if(k===null)return s("No next event to peek");o=k+1}else{let I=nr(r);if(!I)return s("Invalid peek date");o=I.getTime()}let i=v(),d=e.value.id,l=Na(n.value,o);if(a(l))return s(l.message);let{appliedEvents:u,unappliedEvents:m}=l.value,g=Sn();if(a(g))return g;let b=Nt(u).filter(a);if(b.length>0)return Sn(),E(i),s(b.map(I=>I.message).join(", "));let R=v().nodes[d];return R?(L.navigate({contextNode:R,selectedIndex:0}),E({mode:p.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:m}),c("Peeking",!0)):(Sn(),E(i),s("Board did not exist at peek date"))}});import xm from"zod";var nd,rd=y(()=>{"use strict";Ht();G();C();ie();ge();T();nd=()=>{let e=J().commandMeta.inputString,t=xm.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return s("Auto sync duration must be a number of at least 3000 ms");let n=Ye({autoSyncDebounceMs:t.data});return a(n)?n:(ke({autoSyncIntervalMs:t.data}),E({mode:p.DEFAULT}),c(`Auto sync interval set to ${t.data}ms`,null))}});var od,id=y(()=>{"use strict";cn();Ht();G();C();ie();ge();T();od=()=>{let e=J().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return s("Invalid response");let t=os(e),n=Ye({autoSync:t});return a(n)?n:(ke({autoSync:t}),E({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))}});var sd,ad=y(()=>{"use strict";Ht();G();C();ie();ge();T();sd=()=>{let e=J().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return s("Invalid response");let n=Ye({logLevel:e});return a(n)?n:(ke({logLevel:e}),E({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))}});var dd,cd=y(()=>{"use strict";Xn();G();C();ie();T();dd=async()=>{W(""),E({mode:p.DEFAULT});let e=Fe();if(a(e))return s(e.message);if(e.value.syncStatus.status==="syncing")return s("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await qe();return a(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:p.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)}});import{ulid as ye}from"ulid";var ld,ud,md,pd=y(()=>{"use strict";ca();Te();Ht();Et();Me();wa();xn();G();Z();C();ae();Se();ie();ge();T();Rr();re();Ta();gt();yo();ln();Fa();za();Ja();Za();td();rd();id();ad();cd();ld=e=>Object.values(v().tags).find(t=>t.name===e),ud=e=>Object.values(v().contributors).find(t=>t.name===e),md=[{systemOnly:!0,intent:M.Move,description:"Internal move-state command",mode:p.COMMAND_LINE,action:Xa},{intent:M.Delete,description:"Delete the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];return r?Ie({id:ye(),action:"delete.node",payload:{id:r.id},...e.value}):s("Unable to resolve child to delete")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=J().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(d=>oe(f.FILTER).map(l=>l.split(n)[0]).includes(d))(r))return s("Invalid filter modifier");let i={target:r,operator:"=",value:t.trim()};return be(d=>({...d,filters:e==="clear"?[]:[...d.filters,i],mode:p.DEFAULT})),c("Filter updated",null)}},{intent:M.ViewHelp,description:"Open the help screen",mode:p.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return at({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:p.HELP}),c("Viewing help",null)}},{intent:M.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];if(!r)return s("Unable to close issue, no target found");if(!B(r))return s("Cannot close in this context");let o=v().nodes[ue];if(!o)return s("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return s("Issue is already closed");let i=await Ae();if(a(i))return i;let d=i.value,l=Xt(o.id,r.id,{at:"end"},e.value,d);if(a(l))return l;let u=await Ie({id:ye(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:l.value},...e.value});return a(u)?u:c("Issue closed",null)},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];if(!r)return s("Unable to reopen issue, no target found");let o=r.context==="TICKET"?c("Resolved ticket",r):Yt(r.id,"TICKET");if(a(o))return s("Cannot reopen in this context");let i=o.value,d=v().nodes[ue];if(!d)return s("Unable to locate closed swimlane");if(i.parentNodeId!==d.id)return s("Issue is not closed");if(!B(i))return s("Target node is not issue");let l=Aa(i);if(!l)return s("Unable to resolve previous parent from issue history");if(l===d.id)return s("Previous parent resolves to closed swimlane");let u=v().nodes[l];if(!u)return s("Previous parent no longer exists");let m=await Ae();if(a(m))return m;let g=m.value,x=Xt(u.id,i.id,{at:"end"},e.value,g);if(a(x))return x;let b=await Ie({id:ye(),action:"reopen.issue",payload:{id:i.id,parent:u.id,rank:x.value},...e.value});return a(b)?b:c("Issue reopened",null)},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Init,description:"Initialize Epiq in the current git repository",mode:p.COMMAND_LINE,action:Ha},{intent:M.NewItem,description:"Create a new board, swimlane, or issue",mode:p.COMMAND_LINE,action:Qa,onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Rename,description:"itle] Rename the currently selected node",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=v(),r=q(t.id)[n];if(!r)return s("Missing node");if(r.readonly)return s("Cannot rename readonly node");let o=Bs();return o?Ie({id:ye(),action:"edit.title",payload:{id:r.id,name:o},...e.value}):s("Provide a title")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.UntagTicket,description:"Remove a tag from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide a tag");let o=ld(r);if(!o)return s(`Tag "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid untag target");let d=Yt(i.id,"TICKET");if(a(d))return s("Unable to untag issue in this context");let l=d.value;return B(l)?(l.props.tags??[]).includes(o.id)?Ie({id:ye(),action:"remove.issue.tag",payload:{id:l.id,tag:o.id},...e.value}):s("Issue is not tagged with that tag"):s("Target node is not issue")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.TagTicket,description:"Add or create a tag on the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide a tag");let{selectedNode:o}=v();if(!o)return s("Invalid tag target");let i=Yt(o.id,"TICKET");if(a(i))return s("Unable to tag issue in this context");let d=i.value;if(!B(d))return s("Target node is not issue");let l=ld(r),u;if(l)u=l.id;else{let g=ye(),x=await Ie({id:ye(),action:"create.tag",payload:{id:g,name:r},...e.value});if(a(x))return x;u=x.value.result.id}return(d.props.tags??[]).includes(u)?s("Already tagged with that tag"):Ie({id:ye(),action:"add.issue.tag",payload:{id:d.id,tag:u},...e.value})},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.AssignUserToTicket,description:"Assign a user to the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee");let{selectedIndex:o,contextNode:i}=v(),d=q(i.id)[o];if(!d)return s("Invalid assign target");let l=Yt(d.id,"TICKET");if(a(l))return s("Unable to assign issue in this context");let u=l.value;if(!B(u))return s("Target node is not issue");let m=ud(r),g;if(m)g=m.id;else{let b=ye(),R=await Ie({id:ye(),action:"create.contributor",payload:{id:b,name:r},...e.value});if(a(R))return R;g=R.value.result.id}return(u.props.assignees??[]).includes(g)?s("Assignee already assigned"):Ie({id:ye(),action:"add.issue.assignee",payload:{id:u.id,assignee:g},...e.value})},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:p.COMMAND_LINE,action:async()=>{let e=Q();if(a(e))return s("Unable to resolve user ID");let{modifier:t,inputString:n}=J().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee to remove");let o=ud(r);if(!o)return s(`Assignee "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid unassign target");let d=Yt(i.id,"TICKET");if(a(d))return s("Unable to unassign in this context");let l=d.value;return B(l)?(l.props.assignees??[]).includes(o.id)?Ie({id:ye(),action:"remove.issue.assignee",payload:{id:l.id,assignee:o.id},...e.value}):s(`Issue is not assigned to "${r}"`):s("Target node is not issue")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Sync,description:"Pull, commit, and push Epiq state",mode:p.COMMAND_LINE,action:dd},{intent:M.Peek,description:"View board state at another point in time",mode:p.COMMAND_LINE,action:ed},{intent:M.Export,description:"Export the current board layout to markdown",mode:p.COMMAND_LINE,action:async()=>{let e=await da();return a(e)?e:(E({mode:p.DEFAULT}),c("Export successful",!0))}},{intent:M.Exit,description:"Exit the application",mode:p.COMMAND_LINE,action:async()=>(L.exit(),c("Exit successful",!0))},{intent:M.Edit,description:"Edit title or description",mode:p.COMMAND_LINE,action:async(e,t)=>{if(t.modifier===rt.DESCRIPTION)return ka();if(t.modifier===rt.TITLE){let n=Q();if(a(n))return s("Unable to resolve user ID");let{contextNode:r,selectedIndex:o}=v(),i=q(r.id)[o];if(!i)return s("Missing node");if(i.readonly)return s("Cannot rename readonly node");let d=t.inputString.trim();return d?Ie({id:ye(),action:"edit.title",payload:{id:i.id,name:d},...n.value}):s("Provide a title")}return s("Unknown edit command")},onSuccess:()=>E({mode:p.DEFAULT})},{intent:M.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:p.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case X.USERNAME:{let{userId:r,preferredEditor:o,userName:i}=Y(),d=n||i,l=r??ye();if(!d||!l)return s("Unable to resolve user name or id");let u=Ye({userName:d,userId:l,preferredEditor:o??""});return a(u)?u:(ke({userName:d,userId:l}),E({mode:p.DEFAULT}),c(`Username set to "${d}"`,null))}case X.EDITOR:{if(!n)return s("No editor provided");let r=Ye({preferredEditor:n});return a(r)?r:(ke({preferredEditor:n}),E({mode:p.DEFAULT}),c(`Editor configuration set to "${n}"`,null))}case X.VIEW:return n!=="wide"&&n!=="dense"?s("Invalid view mode"):(ke({viewMode:n}),c(`View set to "${n}"`,null));case X.AUTOSYNC:return od();case X.LOG_LEVEL:return sd();case X.SYNC_DEBOUNCE_MS:return nd();default:return s("Unknown config command")}}},{intent:M.Coffee,description:"Sponsor the development of Epiq!",mode:p.COMMAND_LINE,action:()=>{let e=J().commandMeta.modifier;return e==="custom"?Bo("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):Bo(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),c("Thanks you!",null)}}]});var hm,$e,Go=y(()=>{"use strict";Yn();dr();yo();pd();C();ie();ge();T();hm=new Set(["peek","filter","view-help"]),$e=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=J();if(!t)return s("No command to confirm");if(!e&&n===yt.Invalid)return s("Invalid command");let i=_s(t);Fs();let{readOnly:d}=v();if(d&&!hm.has(i))return pn({status:Qe.Fail,message:"Command not available in readonly state",value:null});let l=md.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!l)return pn({status:Qe.Fail,message:"Command not found",value:null});let u;try{u=await l.action(l,{command:t,inputString:o,modifier:r})}catch(m){return pn({status:Qe.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return a(u)?pn(u):(Ds({addToHistory:!e}),l.onSuccess?.(),Y().autoSync&&ts(),u)}});var Fr,Dr,gd,fd=y(()=>{"use strict";C();G();T();mt();Go();qo();ie();Fr=[{intent:S.Exit,mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:p.COMMAND_LINE}),W("move cancel"),$e({isForceExecutedBySystem:!0}))},{intent:S.InitMove,mode:p.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:p.COMMAND_LINE}),W("move start"),$e({isForceExecutedBySystem:!0}))},{intent:S.ConfirmMove,mode:p.MOVE,action:()=>(E({mode:p.COMMAND_LINE}),W("move confirm"),$e({isForceExecutedBySystem:!0}))}],Dr=[{intent:S.MovePreviousItem,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move previous"),$e({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveNextItem,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move next"),$e({isForceExecutedBySystem:!0})):s("No pending move")}],gd=[{intent:S.MoveToNextContainer,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move to-next"),$e({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveToPreviousContainer,mode:p.MOVE,action:()=>dt()?(E({mode:p.COMMAND_LINE}),W("move to-previous"),$e({isForceExecutedBySystem:!0})):s("No pending move")}]});var vd,yd=y(()=>{"use strict";Z();fd();vd={[w.WORKSPACE]:[...Fr,...Dr],[w.BOARD]:[...Fr,...Dr],[w.SWIMLANE]:[...Fr,...Dr,...gd],[w.TICKET]:[],[w.FIELD]:[],[w.FIELD_LIST]:[],[w.TEXT]:[]}});var xd,hd,Ed=y(()=>{"use strict";G();C();ie();T();Rr();mt();Te();xd=()=>{W("");let{pendingNavTarget:e}=Vt();E({mode:p.DEFAULT}),e&&L.navigate(e),at({pendingNavTarget:void 0})},hd=[{intent:S.ExitCommandLine,mode:p.HELP,action:()=>(xd(),c("Exiting help",null))},{intent:S.Exit,mode:p.HELP,action:()=>(xd(),c("Closed help",null))},{intent:S.NavPreviousItem,mode:p.HELP,description:"[arrows/hjkl] navigate",action:()=>(L.navigateToPreviousItem(),c("Navigating to previous help item",null))},{intent:S.NavNextItem,mode:p.HELP,action:()=>(L.navigateToNextItem(),c("Navigating to next help item",null))},{intent:S.NavToPreviousContainer,mode:p.HELP,action:()=>(L.navigateToPreviousContainer(),c("Navigating to previous help container",null))},{intent:S.NavToNextContainer,mode:p.HELP,action:()=>(L.navigateToNextContainer(),c("Navigating to next help container",null))}]});var Em,Nd,Id,bd=y(()=>{"use strict";G();Z();C();ie();T();Rr();mt();Te();Em=e=>{E({mode:p.COMMAND_LINE});let{pendingNavTarget:t}=Vt();t&&L.navigate(t),at({pendingNavTarget:void 0}),W(`${e} `)},Nd=()=>{W("");let{pendingNavTarget:e}=Vt();e&&L.navigate(e),at({pendingNavTarget:void 0}),E({mode:p.DEFAULT})},Id=[{intent:S.InitCommandPalette,mode:p.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return at({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:p.PALETTE}),c("Opening command palette",null)}},{intent:S.Confirm,mode:p.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!pi(e))return s("Command only applicable on text nodes");if(e.props.disabled)return s("Command is not available in this context");let t=e.title;return t?(Em(t),c("Selected command",t)):c("No command selected",null)}},{intent:S.ExitCommandLine,mode:p.PALETTE,action:()=>(Nd(),c("Exiting palette",null))},{intent:S.Exit,mode:p.PALETTE,action:()=>(Nd(),c("Closed command palette",null))},{intent:S.NavPreviousItem,mode:p.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(L.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.PALETTE,action:()=>(L.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.PALETTE,action:()=>(L.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.PALETTE,action:()=>(L.navigateToNextContainer(),c("Navigating to next container",null))}]});var Cd,Sd=y(()=>{"use strict";gt();G();C();kt();Se();ie();T();mt();Ed();bd();Te();Cd=[...hd,...Id,{intent:S.AddItem,mode:p.DEFAULT,description:"[n] new...",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.NEW} `),c("Adding new item",null))},{intent:S.Delete,mode:p.DEFAULT,description:"[d] delete",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.DELETE} `),c("Deleting item",null))},{intent:S.InitCommandLine,mode:p.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:p.COMMAND_LINE}),W(""),c("Entering command line mode",null))},{intent:S.Confirm,mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!H(e?.id??"")?.length){if(e?.title===ee.DESCRIPTION)return E({mode:p.COMMAND_LINE}),W(`${f.EDIT} description `),c("Propose command",!0);if(e?.title===ee.ASSIGNEES)return E({mode:p.COMMAND_LINE}),W(`${f.ASSIGN} `),c("Propose command",!0);if(e?.title===ee.TAGS)return E({mode:p.COMMAND_LINE}),W(`${f.TAG} `),c("Propose command",!0);if(t.title===ee.DESCRIPTION&&e?.context==="TEXT")return E({mode:p.COMMAND_LINE}),W(`${f.EDIT} description `),c("Propose command",!0)}return L.enterChildNode(),c("Entering context",null)}},{intent:S.EditTitle,mode:p.DEFAULT,description:"[r] rename title",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.EDIT} title ${v().selectedNode?.title}`),c("Exiting context",null))},{intent:S.EditDescription,mode:p.DEFAULT,description:"[e] edit description",action:()=>(E({mode:p.COMMAND_LINE}),W(`${f.EDIT} description `),c("Exiting context",null))},{intent:S.Exit,mode:p.DEFAULT,description:"[q] exit context",action:()=>(L.enterParentNode(),c("Exiting context",null))},{intent:S.NavPreviousItem,mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(L.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.DEFAULT,action:()=>(L.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.DEFAULT,action:()=>(L.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.DEFAULT,action:()=>(L.navigateToNextContainer(),c("Navigating to next container",null))}]});var Nm,Im,Rd,Ad=y(()=>{"use strict";ie();Nm=500,Im=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Rd=e=>{let t=Im(e);t&&ur(n=>(n+t).slice(0,Nm))}});var bm,Cm,wd,Td=y(()=>{"use strict";Ad();G();C();ie();T();mt();Go();bm=[p.COMMAND_LINE,p.PALETTE],Cm=e=>[{intent:S.MoveCursorLeft,mode:e,action:()=>(fo(-1),c("Moving cursor left",null))},{intent:S.MoveCursorRight,mode:e,action:()=>(fo(1),c("Moving cursor right",null))},{intent:S.MoveCursorLeftOfWord,mode:e,action:()=>(vo("left"),c("Moving cursor left of word",null))},{intent:S.MoveCursorRightOfWord,mode:e,action:()=>(vo("right"),c("Moving cursor right of word",null))},{intent:S.AutoCompleteCommand,mode:e,action:()=>(ur((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=v().selectedNode?.title??""),r+o}),c("Auto-completing command",null))},{intent:S.CaptureInput,mode:e,action:(t,{sequence:n})=>(Rd(n??""),c("Capturing input",null))},{intent:S.EraseInput,mode:e,action:()=>(Ps(),c("Erasing input",null))},{intent:S.EraseInputWord,mode:e,action:()=>(ks(),c("Erasing input word",null))}],wd=[{intent:S.Confirm,mode:p.COMMAND_LINE,action:()=>($e(),c("Executing command",null))},{intent:S.ViewHelp,mode:p.DEFAULT,action:()=>(E({mode:p.HELP}),c("Viewing help",null))},...bm.flatMap(Cm),{intent:S.ExitCommandLine,mode:p.COMMAND_LINE,action:()=>(E({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:S.GetLastCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(Os(),c("Getting last command from history",null))},{intent:S.GetNextCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(Us(),c("Getting next command from history",null))}]});import Pd from"chalk";var Or,Md,Ld,Yo,kd=y(()=>{"use strict";G();Z();xe();Or=Pd.dim.hex(P.secondary2)(": for command line"),Md="q to exit",Ld=`${Pd.hex(P.accent)("m")} to confirm`,Yo={[w.WORKSPACE]:[Or],[w.BOARD]:[Or],[w.BOARD+p.COMMAND_LINE]:[Or],[w.SWIMLANE]:[Or],[w.TICKET+p.HELP]:[Md],[w.SWIMLANE+p.HELP]:[Md],[w.TICKET]:[],[w.FIELD]:[],[w.SWIMLANE+p.MOVE]:[Ld],[w.TICKET+p.MOVE]:[Ld]}});var Rn,Sm,Rm,Fd,Dd=y(()=>{"use strict";T();Rn=e=>e.trim().toLocaleLowerCase(),Sm=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Rm=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},Fd=(e,t)=>{let n=Rn(t.value);if(!n)return!0;switch(t.target){case"title":return Rn(e.title??"").includes(n);case"description":return Rn(e.props.description??"").includes(n);case"tag":return Sm(e).map(Rn).some(o=>o.includes(n));case"assignee":return Rm(e).map(Rn).some(o=>o.includes(n));default:return!0}}});function Od(e,t,n){let r=t[e];if(!r)return s("buildBreadCrumb(): current node not found");let o=[],i=r;for(;i&&(o.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let d=o[o.length-1];return!d||d.id!==n?s("buildBreadCrumb(): node is not connected to root"):(o.reverse(),c("Breadcrumb built",o))}var Ud=y(()=>{"use strict";C()});var Bd,_d=y(()=>{"use strict";Bd=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t}});import{useSyncExternalStore as Am}from"react";function Wd(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:i}=e;if(!t)return s("derive(): contextNodeId is missing");if(!r)return s("derive(): rootNode is missing");if(!o[r])return s("derive(): unable to find root node");let l=o[t];if(!l)return s("Unable to derive state, contextNode not found");let u=Od(t,o,r);if(a(u))return logger.error(u.message),u;let m=u.value,{context:g}=l,x=Yo[g+n]??Yo[g]??[],b=[...Cd,...vd[g]??[],...wd],R=Bd(b),I=Tm(o,i),k=I[t]?.[e.selectedIndex]??null;return c("Derived successfully",{...e,contextNode:l,breadCrumb:m,availableHints:x,availableActions:b,actionIndex:R,selectedNode:k,renderedChildrenIndex:I})}function In(e){Xo=e;let t=tt(process.cwd()),n=!1;if(!a(t)){let i=et(t.value);if(a(i))return s(i.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:p.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},o=Wd(r);return a(o)?o:(bt=o.value,$d(),c("State initialized",null))}function be(e){let t=v(),n=e(t),r=Wd(n);return a(r)?s(r.message??"Unable to update state"):(bt=r.value,$d(),c("State updated",null))}var bt,Xo,Jo,$d,wm,v,Fe,E,Be,Tm,q,Sn,Ot,T=y(()=>{"use strict";yd();Sd();Td();kd();wt();G();Z();C();re();Dd();Ud();_d();Jo=new Set,$d=()=>{for(let e of Jo)e()},wm=e=>(Jo.add(e),()=>Jo.delete(e));v=()=>{if(!bt)throw new Error("State not initialized. Call initWorkspaceState() first.");return bt},Fe=()=>bt?c("Retrieved state",bt):s("State not initialized. Call initWorkspaceState() first.");E=e=>be(t=>({...t,...e})),Be=()=>Am(wm,v,v),Tm=(e,t)=>{let n={};for(let r of Object.values(e))B(r)&&t.length>0&&!t.every(o=>Fd(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,i)=>{let d=e[o.id],l=e[i.id];return!d||!l?0:d.rank.localeCompare(l.rank)});return n},q=e=>v()?.renderedChildrenIndex[e]??[],Sn=()=>Xo?In(Xo):s("Cannot reset state: no initial workspace found"),Ot=()=>bt!==void 0});var Yt,Mm,Ct,N,ae=y(()=>{"use strict";Z();C();T();Se();Yt=(e,t)=>{let{nodes:n}=v(),r=n[e];if(!r)return s("Node not found");if(r.context===t)return c("Resolved ancestor node",r);let o=r.parentNodeId?n[r.parentNodeId]:void 0;for(;o;){if(o.context===t)return c("Resolved ancestor node",o);o=o.parentNodeId?n[o.parentNodeId]:void 0}return s(`No ancestor found for context: ${t}`)},Mm=(e,t)=>{let{nodes:n}=v(),r=n[e];for(;r?.parentNodeId;){if(r.parentNodeId===t)return!0;r=n[r.parentNodeId]}return!1},Ct=(e,t)=>e?e.readonly?s({move:"Cannot move readonly node",rename:"Cannot rename readonly node",edit:"Cannot edit readonly node"}[t]):null:s("Node not found"),N={deleteNode(e){be(t=>{let n={...t.nodes};return delete n[e],{...t,nodes:n}})},editValue(e,t){let{nodes:n}=v(),r=n[e];if(!r)return s("Edit target node not found");let o=Ct(r,"edit");if(o)return o;let i={...r,props:{...r.props,description:t}};return this.updateNode(i),c("Issue description updated",{md:t})},renameNode(e,t){let n=this.getNode(e);if(!n)return s("Rename target node not found");let r=Ct(n,"rename");if(r)return r;let o={...n,title:t};return this.updateNode(o),c("Renamed node",o)},getExistingTags(){let{tags:e}=v();return[...new Set(Object.values(e).map(t=>t.name).filter(Boolean))]},getExistingAssignees(){let{contributors:e}=v();return[...new Set(Object.values(e).map(t=>t.name).filter(Boolean))]},getFieldByTitle(e,t){return H(e).find(n=>n.title===t)},moveNodeToRank({id:e,parentId:t,rank:n}){let{rootNodeId:r}=v(),o=this.getNode(e),i=this.getNode(t);if(!o)return s("Node not found");if(!i)return s("Target parent not found");if(r===e)return s("Cannot move root node");if(e===t)return s("Cannot move node into itself");let d=Ct(o,"move");if(d)return d;if(Mm(t,e))return s("Cannot move node into its own descendant");let l={...o,parentNodeId:t,rank:n};return this.updateNode(l),c("Moved node successfully",l)},tombstoneNode(e){let{nodes:t,contextNodeId:n,rootNodeId:r}=v(),o=this.getNode(e);if(!o)return s("Node not found");if(r===e)return s("Cannot delete root node");let i=new Set,d=u=>{let m=t[u];if(!(!m||i.has(u))){i.add(u);for(let g of H(m.id))d(g.id)}};d(e);let l={...structuredClone(t)};for(let u of i){if(!l[u])return s("Unable to locate node to delete");l[u]={...l[u],isDeleted:!0}}return n?(E({nodes:l}),c("Successfully tomb stoned",o)):s("Unable to delete undefined")},createContributor(e){let t=be(n=>({...n,contributors:{...n.contributors,[e.id]:e}}));return a(t)?s("Unable to create contributor"):c("Created contributor",e)},assign(e,t){let n=this.getContributor(t),r=this.getNode(e);if(!n)return s("Unable to assign contributor, missing contributor");if(!r)return s("Unable to assign contributor, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.assignees??[];if(i.includes(t))return s("Contributor already assigned");let d={...r,props:{...r.props,assignees:[...i,t]}};return this.updateNode(d),c("Assigned contributor",{assignee:t})},unassign(e,t){let n=this.getContributor(t),r=this.getNode(e);if(!n)return s("Unable to unassign, missing contributor");if(!r)return s("Unable to unassign, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.assignees??[];if(!i.includes(t))return c("Issue is not assigned to that contributor",{assignee:t});let d={...r,props:{...r.props,assignees:i.filter(l=>l!==t)}};return this.updateNode(d),c("Assignee removed",{assignee:t})},tag(e,t){let n=this.getTag(t),r=this.getNode(e);if(!n)return s("Unable to add tag, missing tag");if(!r)return s("Unable to add tag, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.tags??[];if(i.includes(t))return s("Tag already assigned");let d={...r,props:{...r.props,tags:[...i,t]}};return this.updateNode(d),c("Tag added",{tag:t})},untag(e,t){let n=this.getTag(t),r=this.getNode(e);if(!n)return s("Unable to remove tag, missing tag");if(!r)return s("Unable to remove tag, missing target");let o=Ct(r,"edit");if(o)return o;if(!B(r))return s("Target is not an issue");let i=r.props.tags??[];if(!i.includes(t))return c("Issue is not tagged with that tag",{tag:t});let d={...r,props:{...r.props,tags:i.filter(l=>l!==t)}};return this.updateNode(d),c("Tag removed",{tag:t})},createTag(e){let t=be(n=>({...n,tags:{...n.tags,[e.id]:e}}));return a(t)?s("Could not create tag"):c("Tag created",e)},createNode(e){let t=be(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return a(t)?s("Unable to create node"):c("Node created",e)},lockNode(e){let t=this.getNode(e);if(!t)return s("Failed to locate node");let n={...t,readonly:!0},r=be(o=>({...o,nodes:{...o.nodes,[e]:n}}));return a(r)?s(r.message):c("Locked node",n)},updateNode(e){let t=be(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return a(t)?t:c("Updated node",e)},getContributor(e){return v().contributors[e]},getTag(e){return v().tags[e]},getNode(e){return v().nodes[e]},getSiblings(e){return H(e)}}});import St from"chalk";import jd from"string-width";import{decodeTime as Lm}from"ulid";var Pm,km,Fm,Dm,Om,Um,Bm,_m,$m,Hd,zd=y(()=>{"use strict";ae();T();vt();ir();Pm=(e,t)=>e+" ".repeat(Math.max(0,t-jd(e))),km=(e,t)=>" ".repeat(Math.max(0,t-jd(e)))+e,Fm=e=>({"add.issue":"Created with title","add.issue.assignee":"Assigned to","remove.issue.assignee":"Unassigned from","close.issue":"Closed","delete.node":"Deleted","edit.title":"Changed title to","edit.description":"Changed description","reopen.issue":"Reopened","add.issue.tag":"Tagged with","remove.issue.tag":"Removed tag","lock.node":"Locked node","move.node":"Moved issue"})[e]??(e.endsWith("e")?`${e}d`:`${e}ed`),Dm=(e,t)=>t?e<t?"up":e>t?"down":null:null,Om=(e,t)=>{let n=N.getNode(e.payload.parent),r=n?St.dim.bgBlack(` ${n.title} `):"unknown",o=t.at(-1);if(o&&"parent"in o&&"rank"in o&&o.parent===e.payload.parent){let i=Dm(e.payload.rank,o.rank);if(i)return`Moved ${i} in ${r}`}return`Moved issue to ${r}`},Um=e=>{switch(e.action){case"add.issue.tag":{let t=v().tags[e.payload.tag];return t?St.bgHex(Oe(t.name))(` ${t.name} `):"unknown tag"}case"remove.issue.tag":{let t=v().tags[e.payload.tag];return t?St.bgHex(Oe(t.name))(` ${t.name} `):"unknown tag"}case"add.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?St.hex(Oe(t.name))(` ${t.name} `):"unknown user"}case"remove.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?St.hex(Oe(t.name))(` ${t.name} `):"unknown user"}case"add.board":case"add.swimlane":case"add.issue":case"add.field":case"create.tag":case"create.contributor":case"edit.title":return`"${"name"in e.payload?e.payload.name:""}"`;default:return""}},Bm=e=>{let t=us(Lm(e));return St.gray(km(t,8))},_m=12,$m=e=>Pm(`${e}`,_m),Hd=(e,t)=>{let n=Bm(e.id),r=$m(e.userName),o=St.dim("\u203A"),i=e.action==="move.node"?Om(e,t):[Fm(e.action),Um(e)].filter(Boolean).join(" ");return`${r} ${n} ${o} ${i}`}});var Wm,jm,Hm,zm,Vd,qd,Kd,Vm,Gd=y(()=>{"use strict";zd();Z();C();kt();ae();gn();T();At();bo();Wm=e=>ot(e,"description"),jm=e=>ot(e,"assignees"),Hm=e=>ot(e,"tags"),zm=e=>ot(e,"history"),Vd=({id:e,name:t,parentNodeId:n,rank:r,value:o,readonly:i=!1,childRenderAxis:d="horizontal"})=>{let l=N.getNode(e);if(!l){let g=N.createNode({...ve.field({id:e,name:t,parentNodeId:n,rank:r,props:{value:o},isVirtual:!0}),readonly:i,childRenderAxis:d});return a(g)?g:c("Virtual field created",void 0)}if(!Ze(l))return s(`Existing virtual node ${e} is not a field`);if(!(l.title!==t||l.parentNodeId!==n||l.rank!==r||l.props.value!==o||l.readonly!==i||l.childRenderAxis!==d))return c("Virtual field unchanged",void 0);let m=N.updateNode({...l,title:t,parentNodeId:n,rank:r,props:{...l.props,value:o},readonly:i,childRenderAxis:d});return a(m)?m:c("Virtual field updated",void 0)},qd=({id:e,name:t,parentNodeId:n,rank:r,readonly:o=!1,childRenderAxis:i="horizontal"})=>{let d=N.getNode(e);if(!d){let m=N.createNode({...ve.fieldList({id:e,name:t,parentNodeId:n,rank:r,isVirtual:!0}),readonly:o,childRenderAxis:i});return a(m)?m:c("Virtual field list created",void 0)}if(!Qt(d))return s(`Existing virtual node ${e} is not a field list`);if(!(d.title!==t||d.parentNodeId!==n||d.rank!==r||d.readonly!==o||d.childRenderAxis!==i))return c("Virtual field list unchanged",void 0);let u=N.updateNode({...d,title:t,parentNodeId:n,rank:r,readonly:o,childRenderAxis:i});return a(u)?u:c("Virtual field list updated",void 0)},Kd=e=>{let t=Ce(He/4n),n=Ce(He/2n),r=Ce(He*3n/4n),o=Ce(He*7n/8n);if(a(t))return t;if(a(n))return n;if(a(r))return r;if(a(o))return o;let i=Vd({id:Wm(e.id),name:ee.DESCRIPTION,parentNodeId:e.id,rank:t.value,value:e.props.description??"",childRenderAxis:"vertical"});if(a(i))return i;let d=qd({id:jm(e.id),name:ee.ASSIGNEES,parentNodeId:e.id,rank:n.value,readonly:!0});if(a(d))return d;let l=qd({id:Hm(e.id),name:ee.TAGS,parentNodeId:e.id,rank:r.value,readonly:!0});if(a(l))return l;let u=Vd({id:zm(e.id),name:ee.HISTORY,parentNodeId:e.id,rank:o.value,value:Vm(e),readonly:!0,childRenderAxis:"vertical"});return a(u)?u:c("Ticket virtual nodes materialized",void 0)},Vm=e=>{let t=[...e.log].reverse(),n=new Map;for(let r of t){let o=n.get(r.action)??[];o.push(r.payload),n.set(r.action,o)}return t.map(r=>Hd(r,n.get(r.action)??[])).join(`
|
|
59
59
|
`)}});function Cn(e,t=!1){let n=Zm[e.action](e);if(a(n))return n;let r=Qm(e,t);return r||n}var D,Yd,qm,Km,Gm,Ym,Xm,Jm,Qm,Zm,Nt,Kt=y(()=>{"use strict";Z();C();kt();ae();gn();T();Gd();xn();D=(e,t)=>s(`${t.action.split(".").join(" ")+" failed, "+e.toLowerCase()}. Evt id: ${t.id}`),Yd=e=>{let t=N.getNode(e);if(!t||!B(t)||t.isDeleted)return null;let n=Kd(t);return a(n)?n:null},qm=e=>{for(let t of e){let n=Yd(t);if(n)return n;let r=v().nodes[t]?.parentNodeId;if(!r)continue;let o=Yd(r);if(o)return o}return null},Km=(e,t)=>{let n=N.getNode(e);n&&N.updateNode({...n,log:[...n.log??[],t]})},Gm=e=>{let t=[e],n=v().nodes[e]?.parentNodeId;return n&&t.push(n),t},Ym=e=>{switch(e.action){case"delete.node":case"edit.description":return Gm(e.payload.id);case"init.workspace":case"add.workspace":case"add.board":case"add.swimlane":case"add.issue":case"add.field":case"edit.title":case"lock.node":case"move.node":case"close.issue":case"reopen.issue":case"add.issue.tag":case"remove.issue.tag":case"add.issue.assignee":case"remove.issue.assignee":return[e.payload.id];case"rebalance.children":return Object.keys(e.payload.ranks);case"create.tag":case"create.contributor":default:return[]}},Xm=e=>{be(t=>({...t,eventLog:[...t.eventLog,e]}))},Jm=e=>{let t=e.userId,n=e.userName;return!t?.length||!n?.length?D("Invalid user ID format",e):c("Valid user",null)},Qm=(e,t)=>{let n=Jm(e);if(a(n))return n;let r=[...new Set(Ym(e))];t||(r.forEach(i=>Km(i,e)),Xm(e));let o=qm(r);return o||null},Zm={"init.workspace":e=>{let{id:t,name:n,rank:r}=e.payload,o=ve.workspace(t,n,r),i=In(o);if(a(i))return D(i.message,e);let d=N.createNode(o);return a(d)?D(d.message??"Failed to initialize workspace",e):jr(d.value)?c("Workspace initialized",{action:e.action,result:d.value}):s("Unexpected create node return value")},"add.workspace":e=>{let{id:t,name:n,rank:r}=e.payload,o=N.createNode(ve.workspace(t,n,r));return a(o)?D(o.message??"Failed to add workspace",e):jr(o.value)?c("Added workspace",{action:e.action,result:o.value}):s("Unexpected create node return value")},"add.board":e=>{let{id:t,name:n,parent:r,rank:o}=e.payload,i=N.createNode(ve.board(t,n,r,o));return a(i)?D(i.message??"Unable to create board",e):gi(i.value)?c("Added board",{action:e.action,result:i.value}):s("Unexpected create node return value")},"add.swimlane":e=>{let{id:t,name:n,parent:r,rank:o}=e.payload,i=N.createNode(ve.swimlane(t,n,r,o));return a(i)?D(i.message??"Unable to create swimlane",e):Mn(i.value)?c("Added swimlane",{action:e.action,result:i.value}):s("Unexpected create node return value")},"add.issue":e=>{let{id:t,name:n,parent:r,rank:o}=e.payload,i=N.createNode(ve.ticket(t,n,r,o));return a(i)?D(i.message??"Unable to create issue",e):B(i.value)?c("Added issue",{action:e.action,result:i.value}):s("Unexpected create node return value")},"add.field":e=>{let{id:t,name:n,parent:r,val:o,rank:i}=e.payload,d=N.createNode(ve.field({id:t,name:n,parentNodeId:r,rank:i,props:{value:o},childRenderAxis:n.includes(ee.DESCRIPTION)?"vertical":"horizontal"}));return a(d)?D(d.message??`Unable to create field: ${n}`,e):Ze(d.value)?c("Added field",{action:e.action,result:d.value}):s("Unexpected create node return value")},"edit.title":e=>{let{id:t,name:n}=e.payload;if(!N.getNode(t))return D(`Unable to locate node with id ${t}`,e);let o=N.renameNode(t,n);return a(o)?D(o.message??"Unable to edit title",e):c("Edited title",{action:e.action,result:o.value})},"delete.node":e=>{let{id:t}=e.payload,n=N.tombstoneNode(t);return a(n)?D(n.message??"Unable to delete node",e):c("Deleted node",{action:e.action,result:n.value})},"create.tag":e=>{let{id:t,name:n}=e.payload,r=N.createTag({id:t,name:n});return a(r)?D(r.message??"Unable to create tag",e):c("Tag added",{action:e.action,result:r.value})},"create.contributor":e=>{let{id:t,name:n}=e.payload,r=N.createContributor({id:t,name:n});return a(r)?D(r.message??"Unable to create contributor",e):c("Contributor created",{action:e.action,result:r.value})},"add.issue.tag":e=>{let{id:t,tag:n}=e.payload,r=N.tag(t,n);return a(r)?D(r.message??"Unable to tag issue",e):c("Issue tagged",{action:e.action,result:{tag:n}})},"remove.issue.tag":e=>{let{id:t,tag:n}=e.payload,r=N.untag(t,n);return a(r)?D(r.message??"Unable to untag issue",e):c("Issue untagged",{action:e.action,result:{tag:n}})},"add.issue.assignee":e=>{let{id:t,assignee:n}=e.payload,r=N.assign(t,n);return a(r)?D(r.message??"Unable to assign issue",e):c("Assigned successfully",{action:e.action,result:{assignee:n}})},"remove.issue.assignee":e=>{let{id:t,assignee:n}=e.payload,r=N.unassign(t,n);return a(r)?D(r.message??"Unable to unassign issue",e):c("Issue unassigned",{action:e.action,result:{assignee:n}})},"move.node":e=>{let{id:t,parent:n,rank:r}=e.payload,o=N.moveNodeToRank({id:t,parentId:n,rank:r});return a(o)?D(o.message??"Failed to move node",e):c("Moved node",{action:e.action,result:o.value})},"edit.description":e=>{let{id:t,md:n}=e.payload,r=N.editValue(t,n);return a(r)?D(r.message??"Unable to edit description",e):c("Set node value",{action:e.action,result:r.value})},"close.issue":e=>{let{id:t,parent:n,rank:r}=e.payload,o=N.getNode(t);if(!o)return D("Unable to locate issue",e);if(!B(o))return D("Can only close issues",e);let i=N.getNode(ue);if(!i)return D("Unable to locate target swimlane",e);if(n!==i.id)return D("Close target must be closed swimlane",e);let d=N.moveNodeToRank({id:t,parentId:n,rank:r});return a(d)?D(d.message??"Unable to close issue",e):c("Issue closed",{action:e.action,result:{id:t}})},"reopen.issue":e=>{let{id:t,parent:n,rank:r}=e.payload,o=N.getNode(t);if(!o)return D("Unable to locate issue",e);if(!B(o))return D("Can only reopen issues",e);let i=N.getNode(ue);if(!i)return D("Unable to locate closed swimlane",e);if(n===i.id)return D("Cannot reopen issue into closed swimlane",e);if(!N.getNode(n))return D("Reopen parent no longer exists",e);let l=N.moveNodeToRank({id:t,parentId:n,rank:r});return a(l)?D(l.message??"Unable to reopen issue",e):c("Issue reopened",{action:e.action,result:{id:t}})},"lock.node":e=>{let{id:t}=e.payload,n=N.lockNode(t);return a(n)?D(n.message??"Unable to lock node",e):c("Node locked",{action:e.action,result:n.value})},"rebalance.children":e=>{let{parent:t,ranks:n}=e.payload;for(let[r,o]of Object.entries(n)){let i=N.getNode(r);if(!i)return D(`Unable to locate node ${r}`,e);if(i.parentNodeId!==t)return D(`Node ${r} is not child of ${t}`,e);let d=N.updateNode({...i,rank:o});if(a(d))return D(d.message??"Unable to rebalance child",e)}return c("Rebalanced children",{action:e.action,result:{parent:t}})}};Nt=e=>e.map(t=>Cn(t))});function Le(e,t){let n=Cn(e);if(n.status!==Qe.Success)return n;let r=Cr({event:e,rootDir:t});return a(r)?r:n}function It(e,t){return e.map(n=>Le(n,t))}var Ie,Et=y(()=>{"use strict";C();re();Kt();Me();Ie=async e=>{let t=await Ae();return a(t)?t:Le(e,t.value)}});var Xd,Mr,H,Jd,Qd,Xt,Gt,Se=y(()=>{"use strict";yi();Et();C();T();At();Xd=e=>Mr(H(e),{at:"end"}),Mr=(e,t={at:"end"})=>{let n=r=>a(r)?c("Rank space exhausted",{rank:"",needsRebalance:!0}):c("Resolved rank",{rank:r.value,needsRebalance:!1});if(e.length===0)return n(me(void 0,void 0));switch(t.at){case"start":{let r=e[0];return r?n(me(void 0,r.rank)):s("Unable to resolve first sibling")}case"end":{let r=e[e.length-1];return r?n(me(r.rank,void 0)):s("Unable to resolve last sibling")}case"before":{let r=Jd(e,t.sibling);if(r<0)return s("Sibling not found");let o=r>0?e[r-1]:void 0,i=e[r];return i?n(me(o?.rank,i.rank)):s("Sibling not found")}case"after":{let r=Jd(e,t.sibling);if(r<0)return s("Sibling not found");let o=e[r],i=r<e.length-1?e[r+1]:void 0;return o?n(me(o.rank,i?.rank)):s("Sibling not found")}}},H=e=>Object.values(v().nodes).filter(t=>!!t&&!t.isDeleted&&t.parentNodeId===e).sort((t,n)=>t.rank.localeCompare(n.rank)),Jd=(e,t)=>e.findIndex(n=>n.id===t),Qd=(e,t,n={at:"end"})=>Mr(H(t).filter(r=>r.id!==e),n),Xt=(e,t,n,r,o)=>{let i=Qd(t,e,n);if(a(i))return i;if(!i.value.needsRebalance)return c("Resolved rank",i.value.rank);let d=Hr(e,r);if(a(d))return d;let l=Le(d.value,o);if(a(l))return l;let u=Qd(t,e,n);return a(u)?u:u.value.needsRebalance?s("Rank rebalance failed to create space"):c("Resolved rank after rebalance",u.value.rank)},Gt=(e,t,n)=>{let r=Xd(e);if(a(r))return r;if(!r.value.needsRebalance)return c("Resolved rank",r.value.rank);let o=Hr(e,t);if(a(o))return o;let i=Le(o.value,n);if(a(i))return i;let d=Xd(e);return a(d)?d:d.value.needsRebalance?s("Rank rebalance failed to create space"):c("Resolved rank after rebalance",d.value.rank)}});var ec,tc,ep,Ur,nc,Zd,tp,rc,oc=y(()=>{"use strict";Z();C();Se();T();Te();ec=(e,t)=>t<=0?-1:Math.max(0,Math.min(e,t-1)),tc=()=>{let{contextNode:e,selectedIndex:t,selectedNode:n}=v();return{contextNodeId:e.id,selectedNodeId:n?.id??null,parentNodeId:e.id,selectedIndex:t}},ep=e=>{let t=v().nodes[e];return!!t&&!t.isDeleted&&Ze(t)&&t.childRenderAxis==="vertical"},Ur=(e,t)=>{let{nodes:n}=v(),r=n[e];if(!r||r.isDeleted)return!1;let o=H(r.id);return L.navigate({contextNode:r,selectedIndex:ec(t,o.length)}),!0},nc=e=>{let{nodes:t}=v(),n=t[e];if(!n||n.isDeleted)return!1;let r=n.parentNodeId;if(!r)return Ur(n.id,0);let o=t[r];if(!o||o.isDeleted)return!1;let d=H(o.id).findIndex(l=>l.id===n.id);return d>=0?(L.navigate({contextNode:o,selectedIndex:d}),!0):nc(o.id)},Zd=e=>{let{nodes:t}=v(),n=e,r=new Set;for(;n&&!r.has(n);){if(r.add(n),nc(n))return!0;n=t[n]?.parentNodeId}return!1},tp=e=>{if(!e)return!1;let t=v().nodes[e];return!!t&&!t.isDeleted},rc=e=>{let{nodes:t,rootNodeId:n}=v();if(ep(e.contextNodeId)&&Ur(e.contextNodeId,e.selectedIndex))return c("Restored navigation inside text container",null);if(tp(e.selectedNodeId)&&e.selectedNodeId&&Zd(e.selectedNodeId))return c("Restored navigation to selected node or ancestor",null);if(Ur(e.contextNodeId,e.selectedIndex))return c("Restored navigation to previous container",null);if(e.parentNodeId&&Ur(e.parentNodeId,e.selectedIndex))return c("Restored navigation to previous parent",null);if(Zd(e.contextNodeId))return c("Restored navigation to previous container or ancestor",null);let r=t[n];if(!r||r.isDeleted)return s("Unable to restore navigation");let o=H(r.id);return L.navigate({contextNode:r,selectedIndex:ec(e.selectedIndex,o.length)}),c("Restored navigation to root",null)}});var $,Qo=y(()=>{"use strict";C();$=(e,t)=>(a(t)&&logger.info(`[${e}]:failed`,t.message),t)});var Zo,ei,ti,np,ce,ic=y(()=>{"use strict";C();T();Zo=({status:e,msg:t})=>{Ot()&&E({syncStatus:{status:e,msg:t}})},ei=(e="Syncing...")=>{Zo({status:"syncing",msg:e})},ti=(e="Synced")=>{Zo({status:"synced",msg:e})},np=e=>{Zo({status:"failed",msg:e})},ce=e=>(np(e),s(e))});import{decodeTime as rp}from"ulid";var ri,ni,sc,ac,dc,cc=y(()=>{"use strict";C();ri=e=>{let t=[];for(let n of e.split(`
|
|
60
60
|
`)){let r=n.trim();if(r)try{t.push(JSON.parse(r))}catch{return s("Failed to parse persisted events")}}return c("Parsed persisted events",t)},ni=e=>{let[t,n]=e.id;return`${t}:${n??""}`},sc=e=>{try{return rp(e.id[0])}catch{return 0}},ac=(e,t)=>{let n=new Map;for(let r of[...e,...t])n.set(ni(r),r);return[...n.values()].sort((r,o)=>{let i=sc(r)-sc(o);return i!==0?i:ni(r).localeCompare(ni(o))})},dc=e=>e.length===0?"":e.map(t=>JSON.stringify(t)).join(`
|
|
61
61
|
`)+`
|