epiq 0.6.4 → 0.6.5

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.
Files changed (3) hide show
  1. package/dist/index.js +41 -41
  2. package/dist/mcp.js +1 -1
  3. package/package.json +16 -16
package/dist/mcp.js CHANGED
@@ -55,7 +55,7 @@ ${o.message}`):c("Staged state branch event file",void 0)},os=async({repoRoot:e,
55
55
  ${i.message}`):c("Pushed state branch",!0)},is=async({repoRoot:e,stateBranchRoot:t,ensureUpstream:n})=>{let r=!1,o=Xe(e);if(a(o))return o;let i=o.value,d=[ln(),await Bc({repoRoot:e,stateBranchName:i}),await _r({repoRoot:e,stateBranchRoot:t,stateBranchName:i}),await Wc({stateBranchRoot:t,stateBranchName:i}),await Po(t),n?await jc({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 Hc,ulid as Oe}from"ulid";var qt=Hc();function zc(){let e=Ie();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]=$(n.id),[o]=r?$(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 Kc(){let e=zc();return a(e)?e:A.navigate(e.value)}function ss({userId:e,userName:t}){let n=qt(),r=qt(),o=qt(),i=qt(),d=qt(),l=oe(void 0,void 0);if(a(l))return l;let u=oe(void 0,void 0);if(a(u))return u;let m=oe(u.value,void 0);if(a(m))return m;let g=oe(void 0,void 0);if(a(g))return g;let y=oe(g.value,void 0);if(a(y))return y;let N=oe(y.value,void 0);if(a(N))return N;let I=oe(void 0,void 0);return a(I)?I:c("Created default events",[{id:Oe(),userId:e,userName:t,action:"init.workspace",payload:{id:n,name:"Workspace",rank:l.value}},{id:Oe(),userId:e,userName:t,action:"add.board",payload:{id:r,name:"Default",parent:n,rank:u.value}},{id:Oe(),userId:e,userName:t,action:"add.swimlane",payload:{id:o,name:"Todo",parent:r,rank:g.value}},{id:Oe(),userId:e,userName:t,action:"add.swimlane",payload:{id:i,name:"In progress",parent:r,rank:y.value}},{id:Oe(),userId:e,userName:t,action:"add.swimlane",payload:{id:d,name:"Done",parent:r,rank:N.value}},{id:Oe(),userId:e,userName:t,action:"add.board",payload:{id:Un,name:"Closed",parent:n,rank:m.value}},{id:Oe(),userId:e,userName:t,action:"add.swimlane",payload:{id:re,name:"Closed",parent:Un,rank:I.value}},{id:Oe(),userId:e,userName:t,action:"lock.node",payload:{id:Un}},{id:Oe(),userId:e,userName:t,action:"lock.node",payload:{id:re}}])}function _n(e){if(!e.length){let r=de.workspace("temporary-uninitialized-workspace","Workspace","a0"),o=Vt(r);return a(o)?o:(h({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=it(e).filter(a);return n.length>0?s(`Materializing failed:
56
56
  ${n.map(r=>r.message).join(`
57
57
  `)}`):(Kc(),h({hasProjectDefinition:!0}),c("State booted successfully",null))}var Vc=async e=>{let t=await F({cwd:e,args:["status","--porcelain"]});return a(t)?t:c("Checked git diff",t.value.stdout.trim().length>0)},W=(e,t)=>s(`[${e}] ${t}`),ds=async()=>{let e=lo(),t=await We(process.cwd());if(a(t))return W(1,t.message);let n=t.value,r=await sn(n);if(a(r))return W(2,r.message);if(r.value)return W(2,"Cannot initialize Epiq while a git operation is in progress");let o=await Vc(n);if(a(o))return W(2.5,o.message);if(o.value)return W(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(dr(n))return W(4,"Epiq project already initialized");let i=vn();if(!i.isSetupDone||!i.userName)return W(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let d=K(),l=d.userName,u=d.userId;if(!u||!l)return W(5,"Missing Epiq user id");let m=e.stateBranch,g=await an({repoRoot:n,branch:m});if(a(g))return W(6,g.message);if(g.value)return W(6,`State branch already exists: ${m}`);let y=await Br({repoRoot:n,stateBranchName:m});if(a(y))return W(6,y.message);let N=ln();if(a(N))return W(7,N.message);let I=as.join(cn(),e.projectId),C=await _r({repoRoot:n,stateBranchRoot:I,stateBranchName:m});if(a(C))return W(8,C.message);let D=as.join(I,".epiq");qc.mkdirSync(D,{recursive:!0});let R=ss({userId:u,userName:l});if(a(R))return W(9,R.message);for(let Zn of R.value){let oo=On({event:Zn,rootDir:I});if(a(oo))return W(9,oo.message)}let M=await Bn({stateBranchRoot:I,eventFileName:ot({userId:u,userName:l})});if(a(M))return W(10,M.message);let B=await pt({cwd:I,message:"[epiq:init]"});if(a(B))return W(10,B.message);let te=await ts(n);if(a(te))return W(11,te.message);let le=mo({repoRoot:n,fileContents:e});if(a(le))return W(12,le.message);let ut=await z.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(a(ut))return W(13,ut.message);let At=await z.commit({cwd:n,message:"[epiq:init-project]"});if(a(At))return W(13,At.message);let we="Project initialized!",eo=await F({cwd:n,args:["push","-u","origin","HEAD"]});a(eo)&&(we+=` Warn: [init:14] ${eo.message}`);let to=await Kt({repoRoot:n,stateBranchRoot:I});a(to)&&(we+=` Warn: [init:15] ${to.message}`);let no=it(R.value).filter(a);if(no.length>0)return W(16,no.map(Zn=>Zn.message).join(`
58
- `));let Jn=Ie();if(a(Jn))return W(16,Jn.message);let{rootNodeId:ya,nodes:xa}=Jn.value,ro=xa[ya];return ro?(A.navigate({contextNode:ro,selectedIndex:0}),h({hasProjectDefinition:!0,mode:p.DEFAULT}),c(we,null)):W(16,"Unable to resolve initialized root node")};import{ulid as Yc}from"ulid";import{ulid as Gc}from"ulid";var cs=null,Ve=()=>structuredClone(cs),Gt=e=>{cs=e},ls=()=>{let{contextNode:e,selectedIndex:t}=v(),r=j(e.id)[t];return r?c("Resolved selected child",r):s("Target node not found")},$r=({id:e,parentId:t,position:n={at:"end"}})=>{let r=j(t).filter(o=>o.id!==e);return $n(r,n)},us=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q();if(a(r))return s("Unable to resolve user ID");let o=$r({parentId:t,id:e,position:n});return a(o)?o:c("Created pending move state",{id:Gc(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},ms=e=>{Gt(e);let t=Yt(e,!0);return a(t)?t:c("Node moved successfully",t.value)};function Wr(e){let t=ls();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=j(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=us({id:t.value.id,parentId:l.id,position:{at:"end"}});return a(u)?u:ms(u.value)}function jr(e){let t=ls();if(a(t))return t;let{contextNode:n,selectedIndex:r}=v(),i=j(n.id)[r+e];if(!i)return s("Missing sibling node");let d=us({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:i.id}});return a(d)?d:ms(d.value)}var ps=()=>{let e=Ve();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=j(n).findIndex(i=>i.id===t);return o===-1?s("Moved node not found among rendered children"):(A.navigate({contextNode:r,selectedIndex:o}),c("Synchronized navigation to moved node",null))},Wn=(e,t="Moved preview")=>{if(a(e))return e;let n=ps();return a(n)?n:(h({mode:p.MOVE}),c(t,null))},gs=async()=>{let e=q();if(a(e))return s("Unable to resolve user ID");let{modifier:t}=Z().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=j(n.id)[r];if(!o)return h({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=j(o.parentNodeId),d=i.findIndex(({id:y})=>y===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=$r({parentId:o.parentNodeId,id:o.id,position:m});return a(g)?g:(Gt({id:Yc(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:g.value.rank},...e.value}),h({mode:p.MOVE}),c("Move initialized",null))}if(t==="next")return Wn(jr(1));if(t==="previous")return Wn(jr(-1));if(t==="to-next")return Wn(Wr(1));if(t==="to-previous")return Wn(Wr(-1));if(t==="confirm"){let i=Ve();if(!i)return s("No pending move to confirm");let d=await he();if(a(d))return d;let l=Ee(i,d.value);if(a(l))return l;let u=ps();return a(u)?u:(Gt(null),h({mode:p.DEFAULT}),c("Moved item",null))}return t==="cancel"?(Gt(null),h({mode:p.DEFAULT}),c("Cancelling move",null)):s("Invalid move modifier")};import{ulid as Hn}from"ulid";import{monotonicFactory as Xc,ulid as Jc}from"ulid";var Zc=Xc(),jn=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let i=Zc();return c("Created issue events",[{id:Jc(),userId:r,userName:o,action:"add.issue",payload:{id:i,parent:t,name:e,rank:n}}])};var fs=async(e,t)=>{let n=q();if(a(n))return s("Unable to resolve user ID");let r=await he();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=Ee(m,o);if(a(g))return g;let y=E.getNode(g.value.result.id);if(!y)return s("Created node not found");if(!y.parentNodeId)return g;let N=E.getNode(y.parentNodeId);return N?(A.navigate({contextNode:N,selectedIndex:E.getSiblings(y.parentNodeId).findIndex(({id:I})=>I===y.id)}),g):s("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),g=E.getNode(m);if(!g)return s("Workspace not found");let y=It(g.id,n.value,o);return a(y)?y:u({id:Hn(),action:"add.board",payload:{id:Hn(),name:t.inputString,parent:g.id,rank:y.value},...n.value})}if(t.modifier==="swimlane"){let m=Se(i,"BOARD");if(a(m))return s("Unable to add swimlane in this context");let g=It(m.value.id,n.value,o);return a(g)?g:u({id:Hn(),action:"add.swimlane",payload:{id:Hn(),name:t.inputString,parent:m.value.id,rank:g.value},...n.value})}if(t.modifier==="issue"){let m=$(d.id)[l],g=d.context==="SWIMLANE"?d:d.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let B=Se(i,"SWIMLANE");return a(B)?null:B.value})();if(!g)return s("Unable to add issue in this context");let y=It(g.id,n.value,o);if(a(y))return y;let N=jn({name:t.inputString,parent:g.id,rank:y.value,user:n.value});if(a(N))return N;let I=N.value,C=St(I,o);if(C.some(B=>a(B)))return s("Issue create failed: "+C.filter(a).map(B=>B.message).filter(Boolean).join(", "));let D=C[0];if(!D||a(D))return s("Issue creation failed");let M=I.find(B=>B.action==="add.issue")?.payload.id;return M?(A.navigate({contextNode:g,selectedIndex:E.getSiblings(g.id).findIndex(({id:B})=>B===M)}),c("Issue created",null)):s("Unable to determine ticket id")}return c("Success",null)};var vs=async()=>{let e=Se(v().breadCrumb,"BOARD");if(a(e))return e;let t=await We(process.cwd());if(a(t))return s("Unable to locate repo root");let n=gt({repoRoot:t.value});if(a(n))throw new Error(n.message);let{modifier:r}=Z().commandMeta;if(r==="now"){let C=Et(n.value);if(a(C))return s(C.message);let D=Xt();if(a(D))return D;let M=it(C.value).filter(a);return M.length>0?s(M.map(B=>B.message).join(", ")):(h({mode:p.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),c("Peeking now",!0))}let o;if(r==="prev"){let C=v().eventLog.at(-1),D=vr(C);if(D===null)return s("No previous event to peek");o=D}else if(r==="next"){let C=v().unappliedEvents.at(0),D=vr(C);if(D===null)return s("No next event to peek");o=D+1}else{let C=hn(r);if(!C)return s("Invalid peek date");o=C.getTime()}let i=v(),d=e.value.id,l=qi(n.value,o);if(a(l))return s(l.message);let{appliedEvents:u,unappliedEvents:m}=l.value,g=Xt();if(a(g))return g;let N=it(u).filter(a);if(N.length>0)return Xt(),h(i),s(N.map(C=>C.message).join(", "));let I=v().nodes[d];return I?(A.navigate({contextNode:I,selectedIndex:0}),h({mode:p.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:m}),c("Peeking",!0)):(Xt(),h(i),s("Board did not exist at peek date"))};import Qc from"zod";var ys=()=>{let e=Z().commandMeta.inputString,t=Qc.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=rt({autoSyncDebounceMs:t.data});return a(n)?n:(je({autoSyncIntervalMs:t.data}),h({mode:p.DEFAULT}),c(`Auto sync interval set to ${t.data}ms`,null))};var xs=()=>{let e=Z().commandMeta.inputString.trim();if(e!=="yes"&&e!=="no")return s("Invalid response");let t=Ko(e),n=rt({autoSync:t});return a(n)?n:(je({autoSync:t}),h({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))};var hs=async()=>{U(()=>""),h({mode:p.DEFAULT});let e=Ie();if(a(e))return s(e.message);if(e.value.syncStatus.status==="syncing")return s("Sync already in progress");h({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await He();return a(t)?(h({syncStatus:{msg:t.message,status:"failed"}}),t):(h({mode:p.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};import{useSyncExternalStore as zh}from"react";var Hr,el=new Set,tl=()=>{for(let e of el)e()};var Ct=()=>{if(!Hr)throw new Error("Ui state not initialized. Call initUiState() first.");return Hr};var nl=e=>{let t=Ct();return Hr=e(t),tl(),c("UX state updated",null)},Ge=e=>nl(t=>({...t,...e}));var Es=e=>Object.values(v().tags).find(t=>t.name===e),Ns=e=>Object.values(v().contributors).find(t=>t.name===e),Is=[{systemOnly:!0,intent:T.Move,description:"Internal move-state command",mode:p.COMMAND_LINE,action:gs},{intent:T.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=$(t.id)[n];return r?fe({id:ce(),action:"delete.node",payload:{id:r.id},...e.value}):s("Unable to resolve child to delete")},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Z().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(d=>ee(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 ve(d=>({...d,filters:e==="clear"?[]:[...d.filters,i],mode:p.DEFAULT})),c("Filter updated",null)}},{intent:T.ViewHelp,description:"Open the help screen",mode:p.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return Ge({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),h({mode:p.HELP}),c("Viewing help",null)}},{intent:T.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=$(t.id)[n];if(!r)return s("Unable to close issue, no target found");if(!_(r))return s("Cannot close in this context");let o=v().nodes[re];if(!o)return s("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return s("Issue is already closed");let i=await he();if(a(i))return i;let d=i.value,l=bt(o.id,r.id,{at:"end"},e.value,d);if(a(l))return l;let u=await fe({id:ce(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:l.value},...e.value});return a(u)?u:c("Issue closed",null)},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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=$(t.id)[n];if(!r)return s("Unable to reopen issue, no target found");let o=r.context==="TICKET"?c("Resolved ticket",r):Rt(r.id,"TICKET");if(a(o))return s("Cannot reopen in this context");let i=o.value,d=v().nodes[re];if(!d)return s("Unable to locate closed swimlane");if(i.parentNodeId!==d.id)return s("Issue is not closed");if(!_(i))return s("Target node is not issue");let l=Ji(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 he();if(a(m))return m;let g=m.value,y=bt(u.id,i.id,{at:"end"},e.value,g);if(a(y))return y;let N=await fe({id:ce(),action:"reopen.issue",payload:{id:i.id,parent:u.id,rank:y.value},...e.value});return a(N)?N:c("Issue reopened",null)},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.Init,description:"Initialize Epiq in the current git repository",mode:p.COMMAND_LINE,action:ds},{intent:T.NewItem,description:"Create a new board, swimlane, or issue",mode:p.COMMAND_LINE,action:fs,onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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=$(t.id)[n];if(!r)return s("Missing node");if(r.readonly)return s("Cannot rename readonly node");let o=Ei();return o?fe({id:ce(),action:"edit.title",payload:{id:r.id,name:o},...e.value}):s("Provide a title")},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().commandMeta,r=(t||n).trim();if(!r)return s("Provide a tag");let o=Es(r);if(!o)return s(`Tag "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid untag target");let d=Rt(i.id,"TICKET");if(a(d))return s("Unable to untag issue in this context");let l=d.value;return _(l)?(l.props.tags??[]).includes(o.id)?fe({id:ce(),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:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().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=Rt(o.id,"TICKET");if(a(i))return s("Unable to tag issue in this context");let d=i.value;if(!_(d))return s("Target node is not issue");let l=Es(r),u;if(l)u=l.id;else{let g=ce(),y=await fe({id:ce(),action:"create.tag",payload:{id:g,name:r},...e.value});if(a(y))return y;u=y.value.result.id}return(d.props.tags??[]).includes(u)?s("Already tagged with that tag"):fe({id:ce(),action:"add.issue.tag",payload:{id:d.id,tag:u},...e.value})},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee");let{selectedIndex:o,contextNode:i}=v(),d=$(i.id)[o];if(!d)return s("Invalid assign target");let l=Rt(d.id,"TICKET");if(a(l))return s("Unable to assign issue in this context");let u=l.value;if(!_(u))return s("Target node is not issue");let m=Ns(r),g;if(m)g=m.id;else{let N=ce(),I=await fe({id:ce(),action:"create.contributor",payload:{id:N,name:r},...e.value});if(a(I))return I;g=I.value.result.id}return(u.props.assignees??[]).includes(g)?s("Assignee already assigned"):fe({id:ce(),action:"add.issue.assignee",payload:{id:u.id,assignee:g},...e.value})},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee to remove");let o=Ns(r);if(!o)return s(`Assignee "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid unassign target");let d=Rt(i.id,"TICKET");if(a(d))return s("Unable to unassign in this context");let l=d.value;return _(l)?(l.props.assignees??[]).includes(o.id)?fe({id:ce(),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:()=>h({mode:p.DEFAULT})},{intent:T.Sync,description:"Pull, commit, and push Epiq state",mode:p.COMMAND_LINE,action:hs},{intent:T.Peek,description:"View board state at another point in time",mode:p.COMMAND_LINE,action:vs},{intent:T.Export,description:"Export the current board layout to markdown",mode:p.COMMAND_LINE,action:async()=>{let e=await Di();return a(e)?e:(h({mode:p.DEFAULT}),c("Export successful",!0))}},{intent:T.Exit,description:"Exit the application",mode:p.COMMAND_LINE,action:async()=>(A.exit(),c("Exit successful",!0))},{intent:T.Edit,description:"Edit title or description",mode:p.COMMAND_LINE,action:async(e,t)=>{if(t.modifier===ze.DESCRIPTION)return es();if(t.modifier===ze.TITLE){let n=q();if(a(n))return s("Unable to resolve user ID");let{contextNode:r,selectedIndex:o}=v(),i=$(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?fe({id:ce(),action:"edit.title",payload:{id:i.id,name:d},...n.value}):s("Provide a title")}return s("Unknown edit command")},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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 J.USERNAME:{let{userId:r,preferredEditor:o,userName:i}=K(),d=n||i,l=r??ce();if(!d||!l)return s("Unable to resolve user name or id");let u=rt({userName:d,userId:l,preferredEditor:o??""});return a(u)?u:(je({userName:d,userId:l}),h({mode:p.DEFAULT}),c(`Username set to "${d}"`,null))}case J.EDITOR:{if(!n)return s("No editor provided");let r=rt({preferredEditor:n});return a(r)?r:(je({preferredEditor:n}),h({mode:p.DEFAULT}),c(`Editor configuration set to "${n}"`,null))}case J.VIEW:return n!=="wide"&&n!=="dense"?s("Invalid view mode"):(je({viewMode:n}),c(`View set to "${n}"`,null));case J.AUTOSYNC:return xs();case J.SYNC_DEBOUNCE_MS:return ys();default:return s("Unknown config command")}}}];var rl=new Set(["peek","filter","view-help"]),Ae=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Z();if(!t)return s("No command to confirm");if(!e&&n===et.Invalid)return s("Invalid command");let i=Ni(t);vi();let{readOnly:d}=v();if(d&&!rl.has(i))return $t({status:Ue.Fail,message:"Command not available in readonly state",value:null});let l=Is.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!l)return $t({status:Ue.Fail,message:"Command not found",value:null});let u;try{u=await l.action(l,{command:t,inputString:o,modifier:r})}catch(m){return $t({status:Ue.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return a(u)?$t(u):(yi({addToHistory:!e}),l.onSuccess?.(),K().autoSync&&jo(),u)};var zn=[{intent:S.Exit,mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>"move cancel"),Ae({isForceExecutedBySystem:!0}))},{intent:S.InitMove,mode:p.DEFAULT,description:"[m] move (init/confirm)",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>"move start"),Ae({isForceExecutedBySystem:!0}))},{intent:S.ConfirmMove,mode:p.MOVE,action:()=>(h({mode:p.COMMAND_LINE}),U(()=>"move confirm"),Ae({isForceExecutedBySystem:!0}))}],Kn=[{intent:S.MovePreviousItem,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move previous"),Ae({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveNextItem,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move next"),Ae({isForceExecutedBySystem:!0})):s("No pending move")}],Ss=[{intent:S.MoveToNextContainer,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move to-next"),Ae({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveToPreviousContainer,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move to-previous"),Ae({isForceExecutedBySystem:!0})):s("No pending move")}];var Cs={[b.WORKSPACE]:[...zn,...Kn],[b.BOARD]:[...zn,...Kn],[b.SWIMLANE]:[...zn,...Kn,...Ss],[b.TICKET]:[],[b.FIELD]:[],[b.FIELD_LIST]:[],[b.TEXT]:[]};var Rs=()=>{U(()=>"");let{pendingNavTarget:e}=Ct();h({mode:p.DEFAULT}),e&&A.navigate(e),Ge({pendingNavTarget:void 0})},bs=[{intent:S.ExitCommandLine,mode:p.HELP,action:()=>(Rs(),c("Exiting help",null))},{intent:S.Exit,mode:p.HELP,action:()=>(Rs(),c("Closed help",null))},{intent:S.NavPreviousItem,mode:p.HELP,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),c("Navigating to previous help item",null))},{intent:S.NavNextItem,mode:p.HELP,action:()=>(A.navigateToNextItem(),c("Navigating to next help item",null))},{intent:S.NavToPreviousContainer,mode:p.HELP,action:()=>(A.navigateToPreviousContainer(),c("Navigating to previous help container",null))},{intent:S.NavToNextContainer,mode:p.HELP,action:()=>(A.navigateToNextContainer(),c("Navigating to next help container",null))}];var ol=e=>{h({mode:p.COMMAND_LINE});let{pendingNavTarget:t}=Ct();t&&A.navigate(t),Ge({pendingNavTarget:void 0}),U(()=>`${e} `)},As=()=>{U(()=>"");let{pendingNavTarget:e}=Ct();e&&A.navigate(e),Ge({pendingNavTarget:void 0}),h({mode:p.DEFAULT})},ws=[{intent:S.InitCommandPalette,mode:p.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{U(()=>"");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return Ge({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),h({mode:p.PALETTE}),c("Opening command palette",null)}},{intent:S.Confirm,mode:p.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!io(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?(ol(t),c("Selected command",t)):c("No command selected",null)}},{intent:S.ExitCommandLine,mode:p.PALETTE,action:()=>(As(),c("Exiting palette",null))},{intent:S.Exit,mode:p.PALETTE,action:()=>(As(),c("Closed command palette",null))},{intent:S.NavPreviousItem,mode:p.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.PALETTE,action:()=>(A.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.PALETTE,action:()=>(A.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.PALETTE,action:()=>(A.navigateToNextContainer(),c("Navigating to next container",null))}];var Ts=[...bs,...ws,{intent:S.AddItem,mode:p.DEFAULT,description:"[n] new...",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.NEW} `),c("Adding new item",null))},{intent:S.Delete,mode:p.DEFAULT,description:"[d] delete",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.DELETE} `),c("Deleting item",null))},{intent:S.InitCommandLine,mode:p.DEFAULT,description:"[:] focus command line",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>""),c("Entering command line mode",null))},{intent:S.Confirm,mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!j(e?.id??"")?.length){if(e?.title===G.DESCRIPTION)return h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} description `),c("Propose command",!0);if(e?.title===G.ASSIGNEES)return h({mode:p.COMMAND_LINE}),U(()=>`${f.ASSIGN} `),c("Propose command",!0);if(e?.title===G.TAGS)return h({mode:p.COMMAND_LINE}),U(()=>`${f.TAG} `),c("Propose command",!0);if(t.title===G.DESCRIPTION&&e?.context==="TEXT")return h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} description `),c("Propose command",!0)}return A.enterChildNode(),c("Entering context",null)}},{intent:S.EditTitle,mode:p.DEFAULT,description:"[r] rename title",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} title ${v().selectedNode?.title}`),c("Exiting context",null))},{intent:S.EditDescription,mode:p.DEFAULT,description:"[e] edit description",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} description `),c("Exiting context",null))},{intent:S.Exit,mode:p.DEFAULT,description:"[q] exit context",action:()=>(h({mode:p.DEFAULT}),A.enterParentNode(),c("Exiting context",null))},{intent:S.NavPreviousItem,mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.DEFAULT,action:()=>(A.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.DEFAULT,action:()=>(A.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.DEFAULT,action:()=>(A.navigateToNextContainer(),c("Navigating to next container",null))}];var il=500,sl=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Ms=e=>{let t=sl(e);t&&U(n=>(n+t).slice(0,il))};var al=[p.COMMAND_LINE,p.PALETTE],dl=e=>[{intent:S.MoveCursorLeft,mode:e,action:()=>(Ir(-1),c("Moving cursor left",null))},{intent:S.MoveCursorRight,mode:e,action:()=>(Ir(1),c("Moving cursor right",null))},{intent:S.MoveCursorLeftOfWord,mode:e,action:()=>(Sr("left"),c("Moving cursor left of word",null))},{intent:S.MoveCursorRightOfWord,mode:e,action:()=>(Sr("right"),c("Moving cursor right of word",null))},{intent:S.AutoCompleteCommand,mode:e,action:()=>(U((t,{remainder:n})=>n?t+n:t),c("Auto-completing command",null))},{intent:S.CaptureInput,mode:e,action:(t,{sequence:n})=>(Ms(n??""),c("Capturing input",null))},{intent:S.EraseInput,mode:e,action:()=>(gi(),c("Erasing input",null))},{intent:S.EraseInputWord,mode:e,action:()=>(fi(),c("Erasing input word",null))}],Ps=[{intent:S.Confirm,mode:p.COMMAND_LINE,action:()=>(Ae(),c("Executing command",null))},{intent:S.ViewHelp,mode:p.DEFAULT,action:()=>(h({mode:p.HELP}),c("Viewing help",null))},...al.flatMap(dl),{intent:S.ExitCommandLine,mode:p.COMMAND_LINE,action:()=>(h({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:S.GetLastCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(xi(),c("Getting last command from history",null))},{intent:S.GetNextCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(hi(),c("Getting next command from history",null))}];import Ds from"chalk";var qn=Ds.dim.hex(w.secondary2)(": for command line"),ks="q to exit",Ls=`${Ds.hex(w.accent)("m")} to confirm`,zr={[b.WORKSPACE]:[qn],[b.BOARD]:[qn],[b.BOARD+p.COMMAND_LINE]:[qn],[b.SWIMLANE]:[qn],[b.TICKET+p.HELP]:[ks],[b.SWIMLANE+p.HELP]:[ks],[b.TICKET]:[],[b.FIELD]:[],[b.SWIMLANE+p.MOVE]:[Ls],[b.TICKET+p.MOVE]:[Ls]};var Jt=e=>e.trim().toLocaleLowerCase(),cl=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},ll=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},Fs=(e,t)=>{let n=Jt(t.value);if(!n)return!0;switch(t.target){case"title":return Jt(e.title??"").includes(n);case"description":return Jt(e.props.description??"").includes(n);case"tag":return cl(e).map(Jt).some(o=>o.includes(n));case"assignee":return ll(e).map(Jt).some(o=>o.includes(n));default:return!0}};function Os(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 Us=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,Kr,qr=new Set,Bs=()=>{for(let e of qr)e()},ml=e=>(qr.add(e),()=>qr.delete(e));function _s(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=Os(t,o,r);if(a(u))return logger.error(u.message),u;let m=u.value,{context:g}=l,y=zr[g+n]??zr[g]??[],N=[...Ts,...Cs[g]??[],...Ps],I=Us(N),C=pl(o,i),D=C[t]?.[e.selectedIndex]??null;return c("Derived successfully",{...e,contextNode:l,breadCrumb:m,availableHints:y,availableActions:N,actionIndex:I,selectedNode:D,renderedChildrenIndex:C})}var v=()=>{if(!st)throw new Error("State not initialized. Call initWorkspaceState() first.");return st},Ie=()=>st?c("Retrieved state",st):s("State not initialized. Call initWorkspaceState() first.");function Vt(e){Kr=e;let t=$e(process.cwd()),n=!1;if(!a(t)){let i=_e(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=_s(r);return a(o)?o:(st=o.value,Bs(),c("State initialized",null))}function ve(e){let t=v(),n=e(t),r=_s(n);return a(r)?s(r.message??"Unable to update state"):(st=r.value,Bs(),c("State updated",null))}var h=e=>ve(t=>({...t,...e}));var Re=()=>ul(ml,v,v),pl=(e,t)=>{let n={};for(let r of Object.values(e))_(r)&&t.length>0&&!t.every(o=>Fs(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},$=e=>v()?.renderedChildrenIndex[e]??[],Xt=()=>Kr?Vt(Kr):s("Cannot reset state: no initial workspace found"),vt=()=>st!==void 0;var Rt=(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}`)},gl=(e,t)=>{let{nodes:n}=v(),r=n[e];for(;r?.parentNodeId;){if(r.parentNodeId===t)return!0;r=n[r.parentNodeId]}return!1},at=(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"),E={deleteNode(e){ve(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=at(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=at(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 j(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=at(o,"move");if(d)return d;if(gl(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 j(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?(h({nodes:l}),c("Successfully tomb stoned",o)):s("Unable to delete undefined")},createContributor(e){let t=ve(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=at(r,"edit");if(o)return o;if(!_(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=at(r,"edit");if(o)return o;if(!_(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=at(r,"edit");if(o)return o;if(!_(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=at(r,"edit");if(o)return o;if(!_(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=ve(n=>({...n,tags:{...n.tags,[e.id]:e}}));return a(t)?s("Could not create tag"):c("Tag created",e)},createNode(e){let t=ve(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=ve(o=>({...o,nodes:{...o.nodes,[e]:n}}));return a(r)?s(r.message):c("Locked node",n)},updateNode(e){let t=ve(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 j(e)}};import dt from"chalk";import $s from"string-width";import{decodeTime as fl}from"ulid";var vl=(e,t)=>e+" ".repeat(Math.max(0,t-$s(e))),yl=(e,t)=>" ".repeat(Math.max(0,t-$s(e)))+e,xl=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`),hl=(e,t)=>t?e<t?"up":e>t?"down":null:null,El=(e,t)=>{let n=E.getNode(e.payload.parent),r=n?dt.dim.bgBlack(` ${n.title} `):"unknown",o=t.at(-1);if(o&&"parent"in o&&"rank"in o&&o.parent===e.payload.parent){let i=hl(e.payload.rank,o.rank);if(i)return`Moved ${i} in ${r}`}return`Moved issue to ${r}`},Nl=e=>{switch(e.action){case"add.issue.tag":{let t=v().tags[e.payload.tag];return t?dt.bgHex(Ce(t.name))(` ${t.name} `):"unknown tag"}case"remove.issue.tag":{let t=v().tags[e.payload.tag];return t?dt.bgHex(Ce(t.name))(` ${t.name} `):"unknown tag"}case"add.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?dt.hex(Ce(t.name))(` ${t.name} `):"unknown user"}case"remove.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?dt.hex(Ce(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""}},Il=e=>{let t=Jo(fl(e));return dt.gray(yl(t,8))},Sl=12,Cl=e=>vl(`${e}`,Sl),Ws=(e,t)=>{let n=Il(e.id),r=Cl(e.userName),o=dt.dim("\u203A"),i=e.action==="move.node"?El(e,t):[xl(e.action),Nl(e)].filter(Boolean).join(" ");return`${r} ${n} ${o} ${i}`};var Rl=e=>Ke(e,"description"),bl=e=>Ke(e,"assignees"),Al=e=>Ke(e,"tags"),wl=e=>Ke(e,"history"),js=({id:e,name:t,parentNodeId:n,rank:r,value:o,readonly:i=!1,childRenderAxis:d="horizontal"})=>{let l=E.getNode(e);if(!l){E.createNode({...de.field({id:e,name:t,parentNodeId:n,rank:r,props:{value:o},isVirtual:!0}),readonly:i,childRenderAxis:d});return}!Be(l)||!(l.title!==t||l.parentNodeId!==n||l.rank!==r||l.props.value!==o||l.readonly!==i||l.childRenderAxis!==d)||E.updateNode({...l,title:t,parentNodeId:n,rank:r,props:{...l.props,value:o},readonly:i,childRenderAxis:d})},Hs=({id:e,name:t,parentNodeId:n,rank:r,readonly:o=!1,childRenderAxis:i="horizontal"})=>{let d=E.getNode(e);if(!d){E.createNode({...de.fieldList({id:e,name:t,parentNodeId:n,rank:r,isVirtual:!0}),readonly:o,childRenderAxis:i});return}!Tt(d)||!(d.title!==t||d.parentNodeId!==n||d.rank!==r||d.readonly!==o||d.childRenderAxis!==i)||E.updateNode({...d,title:t,parentNodeId:n,rank:r,readonly:o,childRenderAxis:i})},zs=e=>{let t=xe(Te/4n),n=xe(Te/2n),r=xe(Te*3n/4n),o=xe(Te);a(t)||a(n)||a(r)||a(o)||(js({id:Rl(e.id),name:G.DESCRIPTION,parentNodeId:e.id,rank:t.value,value:e.props.description??"",childRenderAxis:"vertical"}),Hs({id:bl(e.id),name:G.ASSIGNEES,parentNodeId:e.id,rank:n.value,readonly:!0}),Hs({id:Al(e.id),name:G.TAGS,parentNodeId:e.id,rank:r.value,readonly:!0}),js({id:wl(e.id),name:G.HISTORY,parentNodeId:e.id,rank:o.value,value:Tl(e),readonly:!0,childRenderAxis:"vertical"}))},Tl=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=>Ws(r,n.get(r.action)??[])).join(`
58
+ `));let Jn=Ie();if(a(Jn))return W(16,Jn.message);let{rootNodeId:ya,nodes:xa}=Jn.value,ro=xa[ya];return ro?(A.navigate({contextNode:ro,selectedIndex:0}),h({hasProjectDefinition:!0,mode:p.DEFAULT}),c(we,null)):W(16,"Unable to resolve initialized root node")};import{ulid as Yc}from"ulid";import{ulid as Gc}from"ulid";var cs=null,Ve=()=>structuredClone(cs),Gt=e=>{cs=e},ls=()=>{let{contextNode:e,selectedIndex:t}=v(),r=j(e.id)[t];return r?c("Resolved selected child",r):s("Target node not found")},$r=({id:e,parentId:t,position:n={at:"end"}})=>{let r=j(t).filter(o=>o.id!==e);return $n(r,n)},us=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q();if(a(r))return s("Unable to resolve user ID");let o=$r({parentId:t,id:e,position:n});return a(o)?o:c("Created pending move state",{id:Gc(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},ms=e=>{Gt(e);let t=Yt(e,!0);return a(t)?t:c("Node moved successfully",t.value)};function Wr(e){let t=ls();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=j(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=us({id:t.value.id,parentId:l.id,position:{at:"end"}});return a(u)?u:ms(u.value)}function jr(e){let t=ls();if(a(t))return t;let{contextNode:n,selectedIndex:r}=v(),i=j(n.id)[r+e];if(!i)return s("Missing sibling node");let d=us({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:i.id}});return a(d)?d:ms(d.value)}var ps=()=>{let e=Ve();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=j(n).findIndex(i=>i.id===t);return o===-1?s("Moved node not found among rendered children"):(A.navigate({contextNode:r,selectedIndex:o}),c("Synchronized navigation to moved node",null))},Wn=(e,t="Moved preview")=>{if(a(e))return e;let n=ps();return a(n)?n:(h({mode:p.MOVE}),c(t,null))},gs=async()=>{let e=q();if(a(e))return s("Unable to resolve user ID");let{modifier:t}=Z().commandMeta,{contextNode:n,selectedIndex:r}=v(),o=j(n.id)[r];if(!o)return h({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=j(o.parentNodeId),d=i.findIndex(({id:y})=>y===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=$r({parentId:o.parentNodeId,id:o.id,position:m});return a(g)?g:(Gt({id:Yc(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:g.value.rank},...e.value}),h({mode:p.MOVE}),c("Move initialized",null))}if(t==="next")return Wn(jr(1));if(t==="previous")return Wn(jr(-1));if(t==="to-next")return Wn(Wr(1));if(t==="to-previous")return Wn(Wr(-1));if(t==="confirm"){let i=Ve();if(!i)return s("No pending move to confirm");let d=await he();if(a(d))return d;let l=Ee(i,d.value);if(a(l))return l;let u=ps();return a(u)?u:(Gt(null),h({mode:p.DEFAULT}),c("Moved item",null))}return t==="cancel"?(Gt(null),h({mode:p.DEFAULT}),c("Cancelling move",null)):s("Invalid move modifier")};import{ulid as Hn}from"ulid";import{monotonicFactory as Xc,ulid as Jc}from"ulid";var Zc=Xc(),jn=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let i=Zc();return c("Created issue events",[{id:Jc(),userId:r,userName:o,action:"add.issue",payload:{id:i,parent:t,name:e,rank:n}}])};var fs=async(e,t)=>{let n=q();if(a(n))return s("Unable to resolve user ID");let r=await he();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=Ee(m,o);if(a(g))return g;let y=E.getNode(g.value.result.id);if(!y)return s("Created node not found");if(!y.parentNodeId)return g;let N=E.getNode(y.parentNodeId);return N?(A.navigate({contextNode:N,selectedIndex:E.getSiblings(y.parentNodeId).findIndex(({id:I})=>I===y.id)}),g):s("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=v(),g=E.getNode(m);if(!g)return s("Workspace not found");let y=It(g.id,n.value,o);return a(y)?y:u({id:Hn(),action:"add.board",payload:{id:Hn(),name:t.inputString,parent:g.id,rank:y.value},...n.value})}if(t.modifier==="swimlane"){let m=Se(i,"BOARD");if(a(m))return s("Unable to add swimlane in this context");let g=It(m.value.id,n.value,o);return a(g)?g:u({id:Hn(),action:"add.swimlane",payload:{id:Hn(),name:t.inputString,parent:m.value.id,rank:g.value},...n.value})}if(t.modifier==="issue"){let m=$(d.id)[l],g=d.context==="SWIMLANE"?d:d.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let B=Se(i,"SWIMLANE");return a(B)?null:B.value})();if(!g)return s("Unable to add issue in this context");let y=It(g.id,n.value,o);if(a(y))return y;let N=jn({name:t.inputString,parent:g.id,rank:y.value,user:n.value});if(a(N))return N;let I=N.value,C=St(I,o);if(C.some(B=>a(B)))return s("Issue create failed: "+C.filter(a).map(B=>B.message).filter(Boolean).join(", "));let D=C[0];if(!D||a(D))return s("Issue creation failed");let M=I.find(B=>B.action==="add.issue")?.payload.id;return M?(A.navigate({contextNode:g,selectedIndex:E.getSiblings(g.id).findIndex(({id:B})=>B===M)}),c("Issue created",null)):s("Unable to determine ticket id")}return c("Success",null)};var vs=async()=>{let e=Se(v().breadCrumb,"BOARD");if(a(e))return e;let t=await We(process.cwd());if(a(t))return s("Unable to locate repo root");let n=gt({repoRoot:t.value});if(a(n))throw new Error(n.message);let{modifier:r}=Z().commandMeta;if(r==="now"){let C=Et(n.value);if(a(C))return s(C.message);let D=Xt();if(a(D))return D;let M=it(C.value).filter(a);return M.length>0?s(M.map(B=>B.message).join(", ")):(h({mode:p.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[]}),c("Peeking now",!0))}let o;if(r==="prev"){let C=v().eventLog.at(-1),D=vr(C);if(D===null)return s("No previous event to peek");o=D}else if(r==="next"){let C=v().unappliedEvents.at(0),D=vr(C);if(D===null)return s("No next event to peek");o=D+1}else{let C=hn(r);if(!C)return s("Invalid peek date");o=C.getTime()}let i=v(),d=e.value.id,l=qi(n.value,o);if(a(l))return s(l.message);let{appliedEvents:u,unappliedEvents:m}=l.value,g=Xt();if(a(g))return g;let N=it(u).filter(a);if(N.length>0)return Xt(),h(i),s(N.map(C=>C.message).join(", "));let I=v().nodes[d];return I?(A.navigate({contextNode:I,selectedIndex:0}),h({mode:p.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:m}),c("Peeking",!0)):(Xt(),h(i),s("Board did not exist at peek date"))};import Qc from"zod";var ys=()=>{let e=Z().commandMeta.inputString,t=Qc.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=rt({autoSyncDebounceMs:t.data});return a(n)?n:(je({autoSyncIntervalMs:t.data}),h({mode:p.DEFAULT}),c(`Auto sync interval set to ${t.data}ms`,null))};var xs=()=>{let e=Z().commandMeta.inputString.trim();if(e!=="yes"&&e!=="no")return s("Invalid response");let t=Ko(e),n=rt({autoSync:t});return a(n)?n:(je({autoSync:t}),h({mode:p.DEFAULT}),c(`Auto sync set to "${e}"`,null))};var hs=async()=>{U(()=>""),h({mode:p.DEFAULT});let e=Ie();if(a(e))return s(e.message);if(e.value.syncStatus.status==="syncing")return s("Sync already in progress");h({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await He();return a(t)?(h({syncStatus:{msg:t.message,status:"failed"}}),t):(h({mode:p.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};import{useSyncExternalStore as zh}from"react";var Hr,el=new Set,tl=()=>{for(let e of el)e()};var Ct=()=>{if(!Hr)throw new Error("Ui state not initialized. Call initUiState() first.");return Hr};var nl=e=>{let t=Ct();return Hr=e(t),tl(),c("UX state updated",null)},Ge=e=>nl(t=>({...t,...e}));var Es=e=>Object.values(v().tags).find(t=>t.name===e),Ns=e=>Object.values(v().contributors).find(t=>t.name===e),Is=[{systemOnly:!0,intent:T.Move,description:"Internal move-state command",mode:p.COMMAND_LINE,action:gs},{intent:T.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=$(t.id)[n];return r?fe({id:ce(),action:"delete.node",payload:{id:r.id},...e.value}):s("Unable to resolve child to delete")},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Z().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(d=>ee(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 ve(d=>({...d,filters:e==="clear"?[]:[...d.filters,i],mode:p.DEFAULT})),c("Filter updated",null)}},{intent:T.ViewHelp,description:"Open the help screen",mode:p.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return Ge({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),h({mode:p.HELP}),c("Viewing help",null)}},{intent:T.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=$(t.id)[n];if(!r)return s("Unable to close issue, no target found");if(!_(r))return s("Cannot close in this context");let o=v().nodes[re];if(!o)return s("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return s("Issue is already closed");let i=await he();if(a(i))return i;let d=i.value,l=bt(o.id,r.id,{at:"end"},e.value,d);if(a(l))return l;let u=await fe({id:ce(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:l.value},...e.value});return a(u)?u:c("Issue closed",null)},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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=$(t.id)[n];if(!r)return s("Unable to reopen issue, no target found");let o=r.context==="TICKET"?c("Resolved ticket",r):Rt(r.id,"TICKET");if(a(o))return s("Cannot reopen in this context");let i=o.value,d=v().nodes[re];if(!d)return s("Unable to locate closed swimlane");if(i.parentNodeId!==d.id)return s("Issue is not closed");if(!_(i))return s("Target node is not issue");let l=Ji(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 he();if(a(m))return m;let g=m.value,y=bt(u.id,i.id,{at:"end"},e.value,g);if(a(y))return y;let N=await fe({id:ce(),action:"reopen.issue",payload:{id:i.id,parent:u.id,rank:y.value},...e.value});return a(N)?N:c("Issue reopened",null)},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.Init,description:"Initialize Epiq in the current git repository",mode:p.COMMAND_LINE,action:ds},{intent:T.NewItem,description:"Create a new board, swimlane, or issue",mode:p.COMMAND_LINE,action:fs,onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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=$(t.id)[n];if(!r)return s("Missing node");if(r.readonly)return s("Cannot rename readonly node");let o=Ei();return o?fe({id:ce(),action:"edit.title",payload:{id:r.id,name:o},...e.value}):s("Provide a title")},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().commandMeta,r=(t||n).trim();if(!r)return s("Provide a tag");let o=Es(r);if(!o)return s(`Tag "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid untag target");let d=Rt(i.id,"TICKET");if(a(d))return s("Unable to untag issue in this context");let l=d.value;return _(l)?(l.props.tags??[]).includes(o.id)?fe({id:ce(),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:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().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=Rt(o.id,"TICKET");if(a(i))return s("Unable to tag issue in this context");let d=i.value;if(!_(d))return s("Target node is not issue");let l=Es(r),u;if(l)u=l.id;else{let g=ce(),y=await fe({id:ce(),action:"create.tag",payload:{id:g,name:r},...e.value});if(a(y))return y;u=y.value.result.id}return(d.props.tags??[]).includes(u)?s("Already tagged with that tag"):fe({id:ce(),action:"add.issue.tag",payload:{id:d.id,tag:u},...e.value})},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee");let{selectedIndex:o,contextNode:i}=v(),d=$(i.id)[o];if(!d)return s("Invalid assign target");let l=Rt(d.id,"TICKET");if(a(l))return s("Unable to assign issue in this context");let u=l.value;if(!_(u))return s("Target node is not issue");let m=Ns(r),g;if(m)g=m.id;else{let N=ce(),I=await fe({id:ce(),action:"create.contributor",payload:{id:N,name:r},...e.value});if(a(I))return I;g=I.value.result.id}return(u.props.assignees??[]).includes(g)?s("Assignee already assigned"):fe({id:ce(),action:"add.issue.assignee",payload:{id:u.id,assignee:g},...e.value})},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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}=Z().commandMeta,r=(t||n).trim();if(!r)return s("Provide an assignee to remove");let o=Ns(r);if(!o)return s(`Assignee "${r}" does not exist`);let{selectedNode:i}=v();if(!i)return s("Invalid unassign target");let d=Rt(i.id,"TICKET");if(a(d))return s("Unable to unassign in this context");let l=d.value;return _(l)?(l.props.assignees??[]).includes(o.id)?fe({id:ce(),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:()=>h({mode:p.DEFAULT})},{intent:T.Sync,description:"Pull, commit, and push Epiq state",mode:p.COMMAND_LINE,action:hs},{intent:T.Peek,description:"View board state at another point in time",mode:p.COMMAND_LINE,action:vs},{intent:T.Export,description:"Export the current board layout to markdown",mode:p.COMMAND_LINE,action:async()=>{let e=await Di();return a(e)?e:(h({mode:p.DEFAULT}),c("Export successful",!0))}},{intent:T.Exit,description:"Exit the application",mode:p.COMMAND_LINE,action:async()=>(A.exit(),c("Exit successful",!0))},{intent:T.Edit,description:"Edit title or description",mode:p.COMMAND_LINE,action:async(e,t)=>{if(t.modifier===ze.DESCRIPTION)return es();if(t.modifier===ze.TITLE){let n=q();if(a(n))return s("Unable to resolve user ID");let{contextNode:r,selectedIndex:o}=v(),i=$(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?fe({id:ce(),action:"edit.title",payload:{id:i.id,name:d},...n.value}):s("Provide a title")}return s("Unknown edit command")},onSuccess:()=>h({mode:p.DEFAULT})},{intent:T.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 J.USERNAME:{let{userId:r,preferredEditor:o,userName:i}=K(),d=n||i,l=r??ce();if(!d||!l)return s("Unable to resolve user name or id");let u=rt({userName:d,userId:l,preferredEditor:o??""});return a(u)?u:(je({userName:d,userId:l}),h({mode:p.DEFAULT}),c(`Username set to "${d}"`,null))}case J.EDITOR:{if(!n)return s("No editor provided");let r=rt({preferredEditor:n});return a(r)?r:(je({preferredEditor:n}),h({mode:p.DEFAULT}),c(`Editor configuration set to "${n}"`,null))}case J.VIEW:return n!=="wide"&&n!=="dense"?s("Invalid view mode"):(je({viewMode:n}),c(`View set to "${n}"`,null));case J.AUTOSYNC:return xs();case J.SYNC_DEBOUNCE_MS:return ys();default:return s("Unknown config command")}}}];var rl=new Set(["peek","filter","view-help"]),Ae=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Z();if(!t)return s("No command to confirm");if(!e&&n===et.Invalid)return s("Invalid command");let i=Ni(t);vi();let{readOnly:d}=v();if(d&&!rl.has(i))return $t({status:Ue.Fail,message:"Command not available in readonly state",value:null});let l=Is.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!l)return $t({status:Ue.Fail,message:"Command not found",value:null});let u;try{u=await l.action(l,{command:t,inputString:o,modifier:r})}catch(m){return $t({status:Ue.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return a(u)?$t(u):(yi({addToHistory:!e}),l.onSuccess?.(),K().autoSync&&jo(),u)};var zn=[{intent:S.Exit,mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>"move cancel"),Ae({isForceExecutedBySystem:!0}))},{intent:S.InitMove,mode:p.DEFAULT,description:"[m] move (init/confirm)",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>"move start"),Ae({isForceExecutedBySystem:!0}))},{intent:S.ConfirmMove,mode:p.MOVE,action:()=>(h({mode:p.COMMAND_LINE}),U(()=>"move confirm"),Ae({isForceExecutedBySystem:!0}))}],Kn=[{intent:S.MovePreviousItem,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move previous"),Ae({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveNextItem,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move next"),Ae({isForceExecutedBySystem:!0})):s("No pending move")}],Ss=[{intent:S.MoveToNextContainer,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move to-next"),Ae({isForceExecutedBySystem:!0})):s("No pending move")},{intent:S.MoveToPreviousContainer,mode:p.MOVE,action:()=>Ve()?(h({mode:p.COMMAND_LINE}),U(()=>"move to-previous"),Ae({isForceExecutedBySystem:!0})):s("No pending move")}];var Cs={[b.WORKSPACE]:[...zn,...Kn],[b.BOARD]:[...zn,...Kn],[b.SWIMLANE]:[...zn,...Kn,...Ss],[b.TICKET]:[],[b.FIELD]:[],[b.FIELD_LIST]:[],[b.TEXT]:[]};var Rs=()=>{U(()=>"");let{pendingNavTarget:e}=Ct();h({mode:p.DEFAULT}),e&&A.navigate(e),Ge({pendingNavTarget:void 0})},bs=[{intent:S.ExitCommandLine,mode:p.HELP,action:()=>(Rs(),c("Exiting help",null))},{intent:S.Exit,mode:p.HELP,action:()=>(Rs(),c("Closed help",null))},{intent:S.NavPreviousItem,mode:p.HELP,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),c("Navigating to previous help item",null))},{intent:S.NavNextItem,mode:p.HELP,action:()=>(A.navigateToNextItem(),c("Navigating to next help item",null))},{intent:S.NavToPreviousContainer,mode:p.HELP,action:()=>(A.navigateToPreviousContainer(),c("Navigating to previous help container",null))},{intent:S.NavToNextContainer,mode:p.HELP,action:()=>(A.navigateToNextContainer(),c("Navigating to next help container",null))}];var ol=e=>{h({mode:p.COMMAND_LINE});let{pendingNavTarget:t}=Ct();t&&A.navigate(t),Ge({pendingNavTarget:void 0}),U(()=>`${e} `)},As=()=>{U(()=>"");let{pendingNavTarget:e}=Ct();e&&A.navigate(e),Ge({pendingNavTarget:void 0}),h({mode:p.DEFAULT})},ws=[{intent:S.InitCommandPalette,mode:p.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{U(()=>"");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=v();return Ge({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),h({mode:p.PALETTE}),c("Opening command palette",null)}},{intent:S.Confirm,mode:p.PALETTE,action:()=>{let{selectedNode:e}=v();if(!e||!io(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?(ol(t),c("Selected command",t)):c("No command selected",null)}},{intent:S.ExitCommandLine,mode:p.PALETTE,action:()=>(As(),c("Exiting palette",null))},{intent:S.Exit,mode:p.PALETTE,action:()=>(As(),c("Closed command palette",null))},{intent:S.NavPreviousItem,mode:p.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.PALETTE,action:()=>(A.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.PALETTE,action:()=>(A.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.PALETTE,action:()=>(A.navigateToNextContainer(),c("Navigating to next container",null))}];var Ts=[...bs,...ws,{intent:S.AddItem,mode:p.DEFAULT,description:"[n] new...",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.NEW} `),c("Adding new item",null))},{intent:S.Delete,mode:p.DEFAULT,description:"[d] delete",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.DELETE} `),c("Deleting item",null))},{intent:S.InitCommandLine,mode:p.DEFAULT,description:"[:] focus command line",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>""),c("Entering command line mode",null))},{intent:S.Confirm,mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=v();if(!j(e?.id??"")?.length){if(e?.title===G.DESCRIPTION)return h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} description `),c("Propose command",!0);if(e?.title===G.ASSIGNEES)return h({mode:p.COMMAND_LINE}),U(()=>`${f.ASSIGN} `),c("Propose command",!0);if(e?.title===G.TAGS)return h({mode:p.COMMAND_LINE}),U(()=>`${f.TAG} `),c("Propose command",!0);if(t.title===G.DESCRIPTION&&e?.context==="TEXT")return h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} description `),c("Propose command",!0)}return A.enterChildNode(),c("Entering context",null)}},{intent:S.EditTitle,mode:p.DEFAULT,description:"[r] rename title",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} title ${v().selectedNode?.title}`),c("Exiting context",null))},{intent:S.EditDescription,mode:p.DEFAULT,description:"[e] edit description",action:()=>(h({mode:p.COMMAND_LINE}),U(()=>`${f.EDIT} description `),c("Exiting context",null))},{intent:S.Exit,mode:p.DEFAULT,description:"[q] exit context",action:()=>(A.enterParentNode(),c("Exiting context",null))},{intent:S.NavPreviousItem,mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(A.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:S.NavNextItem,mode:p.DEFAULT,action:()=>(A.navigateToNextItem(),c("Navigating to next item",null))},{intent:S.NavToPreviousContainer,mode:p.DEFAULT,action:()=>(A.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:S.NavToNextContainer,mode:p.DEFAULT,action:()=>(A.navigateToNextContainer(),c("Navigating to next container",null))}];var il=500,sl=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Ms=e=>{let t=sl(e);t&&U(n=>(n+t).slice(0,il))};var al=[p.COMMAND_LINE,p.PALETTE],dl=e=>[{intent:S.MoveCursorLeft,mode:e,action:()=>(Ir(-1),c("Moving cursor left",null))},{intent:S.MoveCursorRight,mode:e,action:()=>(Ir(1),c("Moving cursor right",null))},{intent:S.MoveCursorLeftOfWord,mode:e,action:()=>(Sr("left"),c("Moving cursor left of word",null))},{intent:S.MoveCursorRightOfWord,mode:e,action:()=>(Sr("right"),c("Moving cursor right of word",null))},{intent:S.AutoCompleteCommand,mode:e,action:()=>(U((t,{remainder:n})=>n?t+n:t),c("Auto-completing command",null))},{intent:S.CaptureInput,mode:e,action:(t,{sequence:n})=>(Ms(n??""),c("Capturing input",null))},{intent:S.EraseInput,mode:e,action:()=>(gi(),c("Erasing input",null))},{intent:S.EraseInputWord,mode:e,action:()=>(fi(),c("Erasing input word",null))}],Ps=[{intent:S.Confirm,mode:p.COMMAND_LINE,action:()=>(Ae(),c("Executing command",null))},{intent:S.ViewHelp,mode:p.DEFAULT,action:()=>(h({mode:p.HELP}),c("Viewing help",null))},...al.flatMap(dl),{intent:S.ExitCommandLine,mode:p.COMMAND_LINE,action:()=>(h({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:S.GetLastCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(xi(),c("Getting last command from history",null))},{intent:S.GetNextCommandFromHistory,mode:p.COMMAND_LINE,action:()=>(hi(),c("Getting next command from history",null))}];import Ds from"chalk";var qn=Ds.dim.hex(w.secondary2)(": for command line"),ks="q to exit",Ls=`${Ds.hex(w.accent)("m")} to confirm`,zr={[b.WORKSPACE]:[qn],[b.BOARD]:[qn],[b.BOARD+p.COMMAND_LINE]:[qn],[b.SWIMLANE]:[qn],[b.TICKET+p.HELP]:[ks],[b.SWIMLANE+p.HELP]:[ks],[b.TICKET]:[],[b.FIELD]:[],[b.SWIMLANE+p.MOVE]:[Ls],[b.TICKET+p.MOVE]:[Ls]};var Jt=e=>e.trim().toLocaleLowerCase(),cl=e=>{let{tags:t}=v();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},ll=e=>{let{contributors:t}=v();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},Fs=(e,t)=>{let n=Jt(t.value);if(!n)return!0;switch(t.target){case"title":return Jt(e.title??"").includes(n);case"description":return Jt(e.props.description??"").includes(n);case"tag":return cl(e).map(Jt).some(o=>o.includes(n));case"assignee":return ll(e).map(Jt).some(o=>o.includes(n));default:return!0}};function Os(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 Us=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,Kr,qr=new Set,Bs=()=>{for(let e of qr)e()},ml=e=>(qr.add(e),()=>qr.delete(e));function _s(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=Os(t,o,r);if(a(u))return logger.error(u.message),u;let m=u.value,{context:g}=l,y=zr[g+n]??zr[g]??[],N=[...Ts,...Cs[g]??[],...Ps],I=Us(N),C=pl(o,i),D=C[t]?.[e.selectedIndex]??null;return c("Derived successfully",{...e,contextNode:l,breadCrumb:m,availableHints:y,availableActions:N,actionIndex:I,selectedNode:D,renderedChildrenIndex:C})}var v=()=>{if(!st)throw new Error("State not initialized. Call initWorkspaceState() first.");return st},Ie=()=>st?c("Retrieved state",st):s("State not initialized. Call initWorkspaceState() first.");function Vt(e){Kr=e;let t=$e(process.cwd()),n=!1;if(!a(t)){let i=_e(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=_s(r);return a(o)?o:(st=o.value,Bs(),c("State initialized",null))}function ve(e){let t=v(),n=e(t),r=_s(n);return a(r)?s(r.message??"Unable to update state"):(st=r.value,Bs(),c("State updated",null))}var h=e=>ve(t=>({...t,...e}));var Re=()=>ul(ml,v,v),pl=(e,t)=>{let n={};for(let r of Object.values(e))_(r)&&t.length>0&&!t.every(o=>Fs(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},$=e=>v()?.renderedChildrenIndex[e]??[],Xt=()=>Kr?Vt(Kr):s("Cannot reset state: no initial workspace found"),vt=()=>st!==void 0;var Rt=(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}`)},gl=(e,t)=>{let{nodes:n}=v(),r=n[e];for(;r?.parentNodeId;){if(r.parentNodeId===t)return!0;r=n[r.parentNodeId]}return!1},at=(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"),E={deleteNode(e){ve(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=at(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=at(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 j(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=at(o,"move");if(d)return d;if(gl(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 j(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?(h({nodes:l}),c("Successfully tomb stoned",o)):s("Unable to delete undefined")},createContributor(e){let t=ve(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=at(r,"edit");if(o)return o;if(!_(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=at(r,"edit");if(o)return o;if(!_(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=at(r,"edit");if(o)return o;if(!_(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=at(r,"edit");if(o)return o;if(!_(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=ve(n=>({...n,tags:{...n.tags,[e.id]:e}}));return a(t)?s("Could not create tag"):c("Tag created",e)},createNode(e){let t=ve(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=ve(o=>({...o,nodes:{...o.nodes,[e]:n}}));return a(r)?s(r.message):c("Locked node",n)},updateNode(e){let t=ve(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 j(e)}};import dt from"chalk";import $s from"string-width";import{decodeTime as fl}from"ulid";var vl=(e,t)=>e+" ".repeat(Math.max(0,t-$s(e))),yl=(e,t)=>" ".repeat(Math.max(0,t-$s(e)))+e,xl=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`),hl=(e,t)=>t?e<t?"up":e>t?"down":null:null,El=(e,t)=>{let n=E.getNode(e.payload.parent),r=n?dt.dim.bgBlack(` ${n.title} `):"unknown",o=t.at(-1);if(o&&"parent"in o&&"rank"in o&&o.parent===e.payload.parent){let i=hl(e.payload.rank,o.rank);if(i)return`Moved ${i} in ${r}`}return`Moved issue to ${r}`},Nl=e=>{switch(e.action){case"add.issue.tag":{let t=v().tags[e.payload.tag];return t?dt.bgHex(Ce(t.name))(` ${t.name} `):"unknown tag"}case"remove.issue.tag":{let t=v().tags[e.payload.tag];return t?dt.bgHex(Ce(t.name))(` ${t.name} `):"unknown tag"}case"add.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?dt.hex(Ce(t.name))(` ${t.name} `):"unknown user"}case"remove.issue.assignee":{let t=v().contributors[e.payload.assignee];return t?dt.hex(Ce(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""}},Il=e=>{let t=Jo(fl(e));return dt.gray(yl(t,8))},Sl=12,Cl=e=>vl(`${e}`,Sl),Ws=(e,t)=>{let n=Il(e.id),r=Cl(e.userName),o=dt.dim("\u203A"),i=e.action==="move.node"?El(e,t):[xl(e.action),Nl(e)].filter(Boolean).join(" ");return`${r} ${n} ${o} ${i}`};var Rl=e=>Ke(e,"description"),bl=e=>Ke(e,"assignees"),Al=e=>Ke(e,"tags"),wl=e=>Ke(e,"history"),js=({id:e,name:t,parentNodeId:n,rank:r,value:o,readonly:i=!1,childRenderAxis:d="horizontal"})=>{let l=E.getNode(e);if(!l){E.createNode({...de.field({id:e,name:t,parentNodeId:n,rank:r,props:{value:o},isVirtual:!0}),readonly:i,childRenderAxis:d});return}!Be(l)||!(l.title!==t||l.parentNodeId!==n||l.rank!==r||l.props.value!==o||l.readonly!==i||l.childRenderAxis!==d)||E.updateNode({...l,title:t,parentNodeId:n,rank:r,props:{...l.props,value:o},readonly:i,childRenderAxis:d})},Hs=({id:e,name:t,parentNodeId:n,rank:r,readonly:o=!1,childRenderAxis:i="horizontal"})=>{let d=E.getNode(e);if(!d){E.createNode({...de.fieldList({id:e,name:t,parentNodeId:n,rank:r,isVirtual:!0}),readonly:o,childRenderAxis:i});return}!Tt(d)||!(d.title!==t||d.parentNodeId!==n||d.rank!==r||d.readonly!==o||d.childRenderAxis!==i)||E.updateNode({...d,title:t,parentNodeId:n,rank:r,readonly:o,childRenderAxis:i})},zs=e=>{let t=xe(Te/4n),n=xe(Te/2n),r=xe(Te*3n/4n),o=xe(Te);a(t)||a(n)||a(r)||a(o)||(js({id:Rl(e.id),name:G.DESCRIPTION,parentNodeId:e.id,rank:t.value,value:e.props.description??"",childRenderAxis:"vertical"}),Hs({id:bl(e.id),name:G.ASSIGNEES,parentNodeId:e.id,rank:n.value,readonly:!0}),Hs({id:Al(e.id),name:G.TAGS,parentNodeId:e.id,rank:r.value,readonly:!0}),js({id:wl(e.id),name:G.HISTORY,parentNodeId:e.id,rank:o.value,value:Tl(e),readonly:!0,childRenderAxis:"vertical"}))},Tl=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=>Ws(r,n.get(r.action)??[])).join(`
59
59
  `)};var P=(e,t)=>s(`${t.action.split(".").join(" ")+" failed, "+e.toLowerCase()}. Evt id: ${t.id}`),Ks=e=>{let t=E.getNode(e);!t||!_(t)||t.isDeleted||zs(t)},Ml=e=>{for(let t of e){Ks(t);let n=v().nodes[t]?.parentNodeId;n&&Ks(n)}},Pl=(e,t)=>{let n=E.getNode(e);n&&E.updateNode({...n,log:[...n.log??[],t]})},kl=e=>{let t=[e],n=v().nodes[e]?.parentNodeId;return n&&t.push(n),t},Ll=e=>{switch(e.action){case"delete.node":case"edit.description":return kl(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[]}},Dl=e=>{ve(t=>({...t,eventLog:[...t.eventLog,e]}))},Fl=e=>{let t=e.userId,n=e.userName;if(!t?.length||!n?.length)return P("Invalid user ID format",e);let r=E.createContributor({id:t,name:n});return a(r)?P(r.message,e):null},Ol=(e,t)=>{let n=Fl(e);if(n)return n;let r=[...new Set(Ll(e))];return t||(r.forEach(o=>Pl(o,e)),Dl(e)),Ml(r),null},Ul={"init.workspace":e=>{let{id:t,name:n,rank:r}=e.payload,o=de.workspace(t,n,r),i=Vt(o);if(a(i))return P(i.message,e);let d=E.createNode(o);return a(d)?P(d.message??"Failed to initialize workspace",e):Qn(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=E.createNode(de.workspace(t,n,r));return a(o)?P(o.message??"Failed to add workspace",e):Qn(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=E.createNode(de.board(t,n,r,o));return a(i)?P(i.message??"Unable to create board",e):so(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=E.createNode(de.swimlane(t,n,r,o));return a(i)?P(i.message??"Unable to create swimlane",e):Qt(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=E.createNode(de.ticket(t,n,r,o));return a(i)?P(i.message??"Unable to create issue",e):_(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=E.createNode(de.field({id:t,name:n,parentNodeId:r,rank:i,props:{value:o},childRenderAxis:n.includes(G.DESCRIPTION)?"vertical":"horizontal"}));return a(d)?P(d.message??`Unable to create field: ${n}`,e):Be(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(!E.getNode(t))return P(`Unable to locate node with id ${t}`,e);let o=E.renameNode(t,n);return a(o)?P(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=E.tombstoneNode(t);return a(n)?P(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=E.createTag({id:t,name:n});return a(r)?P(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=E.createContributor({id:t,name:n});return a(r)?P(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=E.tag(t,n);return a(r)?P(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=E.untag(t,n);return a(r)?P(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=E.assign(t,n);return a(r)?P(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=E.unassign(t,n);return a(r)?P(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=E.moveNodeToRank({id:t,parentId:n,rank:r});return a(o)?P(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=E.editValue(t,n);return a(r)?P(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=E.getNode(t);if(!o)return P("Unable to locate issue",e);if(!_(o))return P("Can only close issues",e);let i=E.getNode(re);if(!i)return P("Unable to locate target swimlane",e);if(n!==i.id)return P("Close target must be closed swimlane",e);let d=E.moveNodeToRank({id:t,parentId:n,rank:r});return a(d)?P(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=E.getNode(t);if(!o)return P("Unable to locate issue",e);if(!_(o))return P("Can only reopen issues",e);let i=E.getNode(re);if(!i)return P("Unable to locate closed swimlane",e);if(n===i.id)return P("Cannot reopen issue into closed swimlane",e);if(!E.getNode(n))return P("Reopen parent no longer exists",e);let l=E.moveNodeToRank({id:t,parentId:n,rank:r});return a(l)?P(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=E.lockNode(t);return a(n)?P(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=E.getNode(r);if(!i)return P(`Unable to locate node ${r}`,e);if(i.parentNodeId!==t)return P(`Node ${r} is not child of ${t}`,e);let d=E.updateNode({...i,rank:o});if(a(d))return P(d.message??"Unable to rebalance child",e)}return c("Rebalanced children",{action:e.action,result:{parent:t}})}};function Yt(e,t=!1){let n=Ul[e.action](e);if(a(n))return n;let r=Ol(e,t);return r||n}var it=e=>e.map(t=>Yt(t));function Ee(e,t){let n=Yt(e);if(n.status!==Ue.Success)return n;let r=On({event:e,rootDir:t});return a(r)?r:n}function St(e,t){return e.map(n=>Ee(n,t))}var fe=async e=>{let t=await he();return a(t)?t:Ee(e,t.value)};var qs=e=>$n(j(e),{at:"end"}),$n=(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(oe(void 0,void 0));switch(t.at){case"start":{let r=e[0];return r?n(oe(void 0,r.rank)):s("Unable to resolve first sibling")}case"end":{let r=e[e.length-1];return r?n(oe(r.rank,void 0)):s("Unable to resolve last sibling")}case"before":{let r=Vs(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(oe(o?.rank,i.rank)):s("Sibling not found")}case"after":{let r=Vs(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(oe(o.rank,i?.rank)):s("Sibling not found")}}},j=e=>Object.values(v().nodes).filter(t=>!!t&&!t.isDeleted&&t.parentNodeId===e).sort((t,n)=>t.rank.localeCompare(n.rank)),Vs=(e,t)=>e.findIndex(n=>n.id===t),Gs=(e,t,n={at:"end"})=>$n(j(t).filter(r=>r.id!==e),n),bt=(e,t,n,r,o)=>{let i=Gs(t,e,n);if(a(i))return i;if(!i.value.needsRebalance)return c("Resolved rank",i.value.rank);let d=er(e,r);if(a(d))return d;let l=Ee(d.value,o);if(a(l))return l;let u=Gs(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)},It=(e,t,n)=>{let r=qs(e);if(a(r))return r;if(!r.value.needsRebalance)return c("Resolved rank",r.value.rank);let o=er(e,t);if(a(o))return o;let i=Ee(o.value,n);if(a(i))return i;let d=qs(e);return a(d)?d:d.value.needsRebalance?s("Rank rebalance failed to create space"):c("Resolved rank after rebalance",d.value.rank)};var Xs=(e,t)=>t<=0?-1:Math.max(0,Math.min(e,t-1)),Js=()=>{let{contextNode:e,selectedIndex:t,selectedNode:n}=v();return{contextNodeId:e.id,selectedNodeId:n?.id??null,parentNodeId:e.id,selectedIndex:t}},Bl=e=>{let t=v().nodes[e];return!!t&&!t.isDeleted&&Be(t)&&t.childRenderAxis==="vertical"},Vn=(e,t)=>{let{nodes:n}=v(),r=n[e];if(!r||r.isDeleted)return!1;let o=$(r.id);return A.navigate({contextNode:r,selectedIndex:Xs(t,o.length)}),!0},Zs=e=>{let{nodes:t}=v(),n=t[e];if(!n||n.isDeleted)return!1;let r=n.parentNodeId;if(!r)return Vn(n.id,0);let o=t[r];if(!o||o.isDeleted)return!1;let d=j(o.id).findIndex(l=>l.id===n.id);return d>=0?(A.navigate({contextNode:o,selectedIndex:d}),!0):Zs(o.id)},Ys=e=>{let{nodes:t}=v(),n=e,r=new Set;for(;n&&!r.has(n);){if(r.add(n),Zs(n))return!0;n=t[n]?.parentNodeId}return!1},_l=e=>{if(!e)return!1;let t=v().nodes[e];return!!t&&!t.isDeleted},Qs=e=>{let{nodes:t,rootNodeId:n}=v();if(Bl(e.contextNodeId)&&Vn(e.contextNodeId,e.selectedIndex))return c("Restored navigation inside text container",null);if(_l(e.selectedNodeId)&&e.selectedNodeId&&Ys(e.selectedNodeId))return c("Restored navigation to selected node or ancestor",null);if(Vn(e.contextNodeId,e.selectedIndex))return c("Restored navigation to previous container",null);if(e.parentNodeId&&Vn(e.parentNodeId,e.selectedIndex))return c("Restored navigation to previous parent",null);if(Ys(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=$(r.id);return A.navigate({contextNode:r,selectedIndex:Xs(e.selectedIndex,o.length)}),c("Restored navigation to root",null)};var Vr=({status:e,msg:t})=>{vt()&&h({syncStatus:{status:e,msg:t}})},Gr=(e="Syncing...")=>{Vr({status:"syncing",msg:e})},Yr=(e="Synced")=>{Vr({status:"synced",msg:e})},$l=e=>{Vr({status:"failed",msg:e})},V=e=>($l(e),s(e));var k=(e,t)=>(a(t)&&logger.info(`[${e}]:failed`,t.message),t);import{decodeTime as Wl}from"ulid";var Zt=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)},Xr=e=>{let[t,n]=e.id;return`${t}:${n??""}`},ea=e=>{try{return Wl(e.id[0])}catch{return 0}},Jr=(e,t)=>{let n=new Map;for(let r of[...e,...t])n.set(Xr(r),r);return[...n.values()].sort((r,o)=>{let i=ea(r)-ea(o);return i!==0?i:Xr(r).localeCompare(Xr(o))})},Zr=e=>e.length===0?"":e.map(t=>JSON.stringify(t)).join(`
61
61
  `)+`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "0.6.4",
3
+ "version": "0.6.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "EPIQ - CLI based issue tracker",
@@ -32,20 +32,20 @@
32
32
  "build:npm": "node scripts/write-version.mjs && rm -rf ./dist && esbuild source/Index.tsx --bundle --packages=external --platform=node --format=esm --target=node18 --minify --outfile=dist/index.js --banner:js='#!/usr/bin/env node' && esbuild source/mcp/server.ts --bundle --packages=external --platform=node --format=esm --target=node18 --minify --outfile=dist/mcp.js --banner:js='#!/usr/bin/env node'",
33
33
  "build:sea:bundle": "node scripts/write-version.mjs && rm -rf ./dist && esbuild source/Index.tsx --bundle --platform=node --format=cjs --target=node18 --minify --outfile=dist/sea.cjs",
34
34
  "build:sea": "node --build-sea sea-config.json",
35
- "build:publish": "pnpm build:npm",
36
- "build:binary": "pnpm build:sea:bundle && pnpm build:sea",
35
+ "build:publish": "npm run build:npm",
36
+ "build:binary": "npm run build:sea:bundle && npm run build:sea",
37
37
  "watch:npm": "node scripts/write-version.mjs && rm -rf ./dist && node scripts/watch-npm.mjs",
38
38
  "dev": "IS_LOCAL=true tsc --watch --noEmit",
39
39
  "dev:start": "IS_LOCAL=true tsx source/Index.tsx",
40
40
  "start": "IS_LOCAL=true tsx source/Index.tsx",
41
41
  "test": "prettier --check \"**/*.{ts,tsx}\" && vitest run --coverage",
42
- "prepack": "pnpm build:publish",
42
+ "prepack": "npm run build:publish",
43
43
  "pack:check": "rm -f epiq-*.tgz && npm pack && FILE=$(ls -t epiq-*.tgz | head -n 1) && echo \"$FILE\" && tar -tf \"$FILE\"",
44
44
  "publish:dry": "rm -f epiq-*.tgz && npm pack && FILE=$(ls -t epiq-*.tgz | head -n 1) && npm publish --dry-run \"$FILE\"",
45
45
  "publish:tarball": "FILE=$(ls -t epiq-*.tgz | head -n 1) && echo \"Publishing $FILE\" && npm publish \"$FILE\"",
46
- "release": "pnpm pack:check && pnpm publish:tarball",
46
+ "release": "npm run pack:check && npm run publish:tarball",
47
47
  "start:mcp": "IS_LOCAL=true tsx source/mcp/server.ts",
48
- "inspect:mcp": "pnpm dlx @modelcontextprotocol/inspector",
48
+ "inspect:mcp": "npx @modelcontextprotocol/inspector",
49
49
  "lint": "eslint .",
50
50
  "lint:err": "eslint . --quiet"
51
51
  },
@@ -62,26 +62,26 @@
62
62
  "zod": "^4.3.6"
63
63
  },
64
64
  "devDependencies": {
65
- "@eslint/js": "^10.0.1",
65
+ "@eslint/js": "^9.39.1",
66
66
  "@sindresorhus/tsconfig": "^3.0.1",
67
67
  "@types/marked-terminal": "^6.1.1",
68
- "@types/node": "^25.5.0",
69
- "@types/react": "^18.0.32",
70
- "@typescript-eslint/eslint-plugin": "^8.59.2",
71
- "@typescript-eslint/parser": "^8.59.2",
68
+ "@types/node": "^22.15.0",
69
+ "@types/react": "^19.2.14",
70
+ "@typescript-eslint/eslint-plugin": "^8.46.0",
71
+ "@typescript-eslint/parser": "^8.46.0",
72
72
  "@vdemedes/prettier-config": "^2.0.1",
73
73
  "@vitest/coverage-v8": "4.1.2",
74
74
  "chalk": "^5.2.0",
75
75
  "esbuild": "^0.25.0",
76
- "eslint": "^10.3.0",
77
- "eslint-plugin-react": "^7.32.2",
78
- "eslint-plugin-react-hooks": "^4.6.0",
76
+ "eslint": "^9.39.1",
77
+ "eslint-plugin-react": "^7.37.5",
78
+ "eslint-plugin-react-hooks": "^7.0.1",
79
79
  "prettier": "^2.8.7",
80
80
  "ts-node": "^10.9.1",
81
81
  "tsx": "^4.20.3",
82
82
  "typescript": "^5.0.3",
83
- "typescript-eslint": "^8.59.2",
84
- "vitest": "^4.1.0"
83
+ "typescript-eslint": "^8.46.0",
84
+ "vitest": "4.1.2"
85
85
  },
86
86
  "prettier": "@vdemedes/prettier-config"
87
87
  }