epiq 0.2.1 → 0.2.3

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/cli.js +13 -11
  2. package/package.json +1 -1
  3. package/readme.md +7 -11
package/dist/cli.js CHANGED
@@ -1,18 +1,20 @@
1
1
  #!/usr/bin/env node
2
- import Ve from"fs";import Mn from"path";import Mr from"util";var wn=process.env.IS_LOCAL==="true",Ke=Mn.resolve(process.cwd(),".epiq","log","epiq.log"),Tn=1e3;function wr(){if(!wn||!Ve.existsSync(Ke))return;let t=Ve.readFileSync(Ke,"utf8").split(`
3
- `);if(t[t.length-1]===""&&t.pop(),t.length<=Tn)return;let n=t.slice(-Tn).join(`
4
- `)+`
5
- `;Ve.writeFileSync(Ke,n,"utf8")}function Ut(e,t,n=!1){if(!wn)return;let o=Mr.format(...t),r=new Date,s=`[${n?r.toISOString().slice(11,19):r.toISOString()}] ${e} ${o}
6
- `;Ve.mkdirSync(Mn.dirname(Ke),{recursive:!0}),Ve.appendFileSync(Ke,s,"utf8"),wr()}var Lr={info(...e){Ut("[Info]",e,!1)},debug(...e){Ut("->",e,!0)},error(...e){Ut("[Error]",[...e,new Error().stack],!1)}};globalThis.logger=Lr;import{render as Sr}from"ink";import $s from"meow";import et from"react";import{Box as Pt}from"ink";import X from"react";import{Box as Cs,Text as ys}from"ink";import Je from"react";var T={WORKSPACE:"WORKSPACE",BOARD:"BOARD",SWIMLANE:"SWIMLANE",TICKET:"TICKET",FIELD:"FIELD",FIELD_LIST:"FIELD_LIST",TEXT:"TEXT"};function he(e){return e.context==="TICKET"}function Ln(e){return e.context==="FIELD_LIST"}var Pn=e=>e.context==="SWIMLANE";import{useSyncExternalStore as Wi}from"react";var N={HELP:"help",NEW:"new",TAG:"tag",FILTER:"filter",ASSIGN:"assign",DELETE:"delete",RENAME:"rename",CLOSE_ISSUE:"close",RE_OPEN_ISSUE:"reopen",SET_EDITOR:"set:editor",SET_VIEW:"set:view",SET_USERNAME:"set:username",NONE:""},Q={None:"none",Invalid:"invalid",Valid:"valid"},Z={None:"none",Success:"success",Fail:"fail"},c=e=>({result:Z.Fail,message:e,data:null}),m=(e,t)=>({result:Z.Success,message:e,data:t}),Dn=()=>({result:Z.None,message:"No result",data:null}),x=e=>e.result==="fail",ue=e=>e.result==="success";var Se=24n,Pr=Se*4n,tt=(1n<<Pr)-1n,Dr=/^[0-9a-f]+$/;function Fn(e){if(!e||!Dr.test(e))throw new Error(`Invalid hex rank: ${e}`);return BigInt("0x"+e)}function nt(e,t=Se){if(e<0n)throw new Error("Negative rank not allowed");return e.toString(16).padStart(Number(t),"0")}function $e(e,t){if(!e&&!t)return nt(tt/2n,Se);let n=e?Fn(e):0n,o=t?Fn(t):tt;if(o<=n)return nt(tt/2n,Se);let r=(n+o)/2n;return r===n||r===o?"":nt(r,Se)}function G(){return nt(tt/2n,Se)}var H={workspace:(e,t)=>({id:e,title:t,rank:G(),isDeleted:!1,props:{},context:T.WORKSPACE,childRenderAxis:"vertical",parentNodeId:null,readonly:!0,log:[]}),board:(e,t,n,o=!1)=>({id:e,title:t,rank:G(),isDeleted:!1,props:{},context:T.BOARD,childRenderAxis:"horizontal",parentNodeId:n,readonly:o,log:[]}),swimlane:(e,t,n)=>({id:e,title:t,rank:G(),isDeleted:!1,props:{},context:T.SWIMLANE,childRenderAxis:"vertical",childNavigationAcrossParents:!0,parentNodeId:n,readonly:!1,log:[]}),field:(e,t,n,o={},r="horizontal")=>({id:e,title:t,rank:G(),isDeleted:!1,props:o,context:T.FIELD,childRenderAxis:r,parentNodeId:n,readonly:!1,log:[]}),ticket:(e,t,n)=>({id:e,title:t,rank:G(),isDeleted:!1,props:{},context:T.TICKET,childRenderAxis:"vertical",parentNodeId:n,readonly:!1,log:[]}),text:(e,t,n,o={})=>({id:e,title:t,rank:G(),isDeleted:!1,props:o,context:T.TEXT,childRenderAxis:"vertical",parentNodeId:n,readonly:!1,log:[]})};function ot(e,t){let n=Math.min(e.length,t.length),o=0;for(;o<n&&e[o]===t[o];)o++;return o}var rt=(e,t)=>t<=0?"":e.length<=t?e:t<=3?"...".slice(0,t):e.slice(0,t-3)+"...",it=e=>typeof e!="string"?"":e.replace(/[\x00-\x08\x0B-\x1F\x7F]/g,"").replace(/[\r\n\t]/g," ").replace(/\s+/g," ").trim();var P=e=>Object.values(f().nodes).filter(t=>!!t&&!t.isDeleted&&t.parentNodeId===e).sort((t,n)=>t.rank.localeCompare(n.rank)),Bn=(e,t)=>e.findIndex(n=>n.id===t),Wt=(e,t={at:"end"})=>{if(e.length===0)return m("Resolved rank",G());switch(t.at){case"start":{let n=e[0];return n?m("Resolved rank",$e(void 0,n.rank)):c("Unable to resolve first sibling")}case"end":{let n=e[e.length-1];return n?m("Resolved rank",$e(n.rank,void 0)):c("Unable to resolve last sibling")}case"before":{let n=Bn(e,t.sibling);if(n<0)return c("Sibling not found");let o=n>0?e[n-1]:void 0,r=e[n];return r?m("Resolved rank",$e(o?.rank,r.rank)):c("Sibling not found")}case"after":{let n=Bn(e,t.sibling);if(n<0)return c("Sibling not found");let o=e[n],r=n<e.length-1?e[n+1]:void 0;return o?m("Resolved rank",$e(o.rank,r?.rank)):c("Sibling not found")}}};var Te=(e,t)=>{let{nodes:n}=f(),o=n[e];if(!o)return c("Node not found");if(o.context===t)return m("Resolved ancestor node",o);let r=o.parentNodeId?n[o.parentNodeId]:void 0;for(;r;){if(r.context===t)return m("Resolved ancestor node",r);r=r.parentNodeId?n[r.parentNodeId]:void 0}return c(`No ancestor found for context: ${t}`)},_t=(e,t)=>{let{nodes:n}=f(),o=n[e];for(;o?.parentNodeId;){if(o.parentNodeId===t)return!0;o=n[o.parentNodeId]}return!1};function Fr(e){return it(e).replace(/\s+/g," ").trim()}function kn(e,t){if(!e)return[];let n=[],o=new Set,r=f(),{renderedChildrenIndex:i,tags:s,contributors:a}=r,d=l=>{let v=i[l.id];if(l.title===t&&Ln(l))for(let p of v??[]){if(!p)continue;let C=typeof p.props?.value=="string"?p.props.value:"",A=(t==="Tags"?s[C]?.name:t==="Assignees"?a[C]?.name:void 0)??p.title??String(p.props?.value??""),E=Fr(A),I=E.toLowerCase();E&&!o.has(I)&&(o.add(I),n.push(E))}for(let p of v??[])d(p)};return d(e),n.sort((l,v)=>l.localeCompare(v))}var Ht=(e,t)=>e?e.readonly?c({move:"Cannot move readonly node",rename:"Cannot rename readonly node",edit:"Cannot edit readonly node"}[t]):null:c("Node not found"),g={deleteNode(e){j(t=>{let n={...t.nodes};return delete n[e],{...t,nodes:n}})},editValue(e,t){let{nodes:n}=f(),o=n[e];if(!o)return c("Edit target node not found");let r=Ht(o,"edit");if(r)return r;let i={...o,props:{...o.props,value:t}};return g.updateNode(i),m("Issue description updated",{md:t})},renameNode(e,t){let n=this.getNode(e);if(!n)return c("Rename target node not found");let o=Ht(n,"rename");if(o)return o;let r={...n,title:t};return this.updateNode(r),m("Renamed node",r)},getExistingTags(){let{rootNodeId:e,nodes:t}=f(),n=t[e];return n?kn(n,"Tags"):[]},getExistingAssignees(){let{rootNodeId:e,nodes:t}=f(),n=t[e];return n?kn(n,"Assignees"):[]},getFieldByTitle(e,t){return P(e).find(n=>n.title===t)},moveNode({id:e,parentId:t,position:n={at:"end"},navigate:o=!0}){let{rootNodeId:r}=f(),i=this.getNode(e),s=this.getNode(t);if(!i)return c("Node not found");if(!s)return c("Target parent not found");if(r===e)return c("Cannot move root node");if(e===t)return c("Cannot move node into itself");let a=Ht(i,"move");if(a)return a;if(_t(t,e))return c("Cannot move node into its own descendant");let d=P(t).filter(p=>p.id!==e),l=Wt(d,n);if(x(l))return l;let v={...i,parentNodeId:t,rank:l.data};return o?this.updateNodeAndSelectInParent(v):this.updateNode(v),m("Moved node successfully",v)},tombstoneNode(e){let{nodes:t,currentNodeId:n,rootNodeId:o}=f(),r=this.getNode(e);if(!r)return c("Node not found");if(o===e)return c("Cannot delete root node");let i=new Set,s=l=>{let v=t[l];if(!(!v||i.has(l))){i.add(l);for(let p of P(v.id))s(p.id)}};s(e);let a={...structuredClone(t)};for(let l of i){if(!a[l])return c("Unable to locate node to delete");a[l]={...a[l],isDeleted:!0}}if(!n)return c("Unable to delete undefined");let d=i.has(n)?r.parentNodeId:n;return M({nodes:a,currentNodeId:d}),m("Successfully tomb stoned",r)},createContributor(e){let t=j(n=>({...n,contributors:{...n.contributors,[e.id]:e}}));return x(t)?c("Unable to create contributor"):m("Created contributor",e)},assign(e,t,n){let o=g.getContributor(t),r=g.getNode(e);if(!r||!o)return c("Unable assign contributor to issue");let i=this.getFieldByTitle(r.id,"Assignees");if(!i)return c("Unable to locate assignees field");if(P(i.id).some(d=>d.props?.value===t))return c("Contributor already assigned");let a=this.createNodeAtPosition(H.field(n,o.name,i.id,{value:t}));return x(a)?a:m("Assigned contributor",a.data)},createTag(e){let t=j(n=>({...n,tags:{...n.tags,[e.id]:e}}));return x(t)?c("Could not create tag"):m("Tag created",e)},tag(e,t,n){let o=g.getTag(t),r=g.getNode(e);if(!o)return c("Unable to add tag, missing tag");if(!r)return c("Unable to add tag, missing target");let i=this.getFieldByTitle(r.id,"Tags");if(!i)return c("Unable to locate tags field");if(P(i.id).some(d=>d.props?.value===t))return c("Tag already assigned");let a=this.createNodeAtPosition(H.field(n,o.name,i.id,{value:t}));return x(a)?a:m("Tag added",a.data)},createNodeAtPosition(e,t={at:"end"}){if(!e.parentNodeId){let i={...e,rank:G()};return this.createNode(i),m("Created node",i)}let n=P(e.parentNodeId),o=Wt(n,t);if(x(o))return o;let r={...e,rank:o.data};return this.createNode(r),m("Created node",r)},createNode(e){let t=j(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return x(t)?m("Node created",e):c("Unable to create node")},lockNode(e){let t=this.getNode(e);if(!t)return c("Failed to locate node");let n={...t,readonly:!0},o=j(r=>({...r,nodes:{...r.nodes,[e]:n}}));return x(o)?c(o.message):m("Locked node",n)},updateNode(e){let t=j(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return x(t)?m("Updated node",e):t},updateNodeAndSelectInParent(e){return j(t=>{let n={...t.nodes,[e.id]:e},o=Object.values(n).filter(r=>!r.isDeleted&&r.parentNodeId===e.parentNodeId).sort((r,i)=>r.rank.localeCompare(i.rank));return{...t,nodes:n,currentNodeId:e.parentNodeId,selectedIndex:o.findIndex(({id:r})=>r===e.id)}}),m("Updated and selected",e)},getContributor(e){return f().contributors[e]},getTag(e){return f().tags[e]},getNode(e){return f().nodes[e]},getSiblings:e=>Object.values(f().nodes).filter(t=>!t.isDeleted&&t.parentNodeId===e).sort((t,n)=>t.rank.localeCompare(n.rank))};var Rn=e=>{let t=e.log??[];for(let n=t.length-1;n>=0;n--){let o=t[n];if(o&&o.action==="close.issue"&&o.payload.id===e.id)return o.payload.parent}return null};var Br=["00KM6CZ900T7180RM46K0JAYNF","00JR3R8E00A1Z4X9FGP9DV0SM5"],[Me,st]=Br;var w=(e,t)=>c(`${t.split(".").join(" ")+" failed, "+e.toLowerCase()}`),kr={"init.workspace":({action:e,payload:t})=>{let{id:n,name:o}=t,r=H.workspace(n,o);Un(r);let i=g.createNodeAtPosition(r);return x(i)?w(i.message??"Failed to initialize workspace",e):m("Workspace initialized",{action:e,result:i.data})},"add.workspace":({action:e,payload:t})=>{let{id:n,name:o}=t,r=H.workspace(n,o),i=g.createNodeAtPosition(r);return x(i)?w(i.message??"Failed to add workspace",e):m("Added workspace",{action:e,result:i.data})},"add.board":({action:e,payload:t})=>{let{id:n,name:o,parent:r}=t,i=g.createNodeAtPosition(H.board(n,o,r));return x(i)?w(i.message??"Unable to create board",e):m("Added board",{action:e,result:i.data})},"add.swimlane":({action:e,payload:t})=>{let{id:n,name:o,parent:r}=t,i=g.createNodeAtPosition(H.swimlane(n,o,r));return x(i)?w(i.message??"Unable to create swimlane",e):m("Added swimlane",{action:e,result:i.data})},"add.issue":({action:e,payload:t})=>{let{id:n,name:o,parent:r}=t,i=g.createNodeAtPosition(H.ticket(n,o,r));return x(i)?w(i.message??"Unable to create issue",e):m("Added issue",{action:e,result:i.data})},"add.field":({action:e,payload:t})=>{let{id:n,name:o,parent:r,val:i}=t,s=g.createNodeAtPosition(H.field(n,o,r,{value:i},o.includes("Description")?"vertical":"horizontal"));return x(s)?w(s.message??`Unable to create field: ${o}`,e):m("Added field",{action:e,result:s.data})},"edit.title":({action:e,payload:t})=>{let{id:n,name:o}=t;if(!g.getNode(n))return w("Unable to locate node",e);let i=g.renameNode(n,o);return x(i)?w(i.message??"Unable to edit title",e):m("Edited title",{action:e,result:i.data})},"delete.node":({action:e,payload:t})=>{let{id:n}=t,o=g.tombstoneNode(n);return x(o)?w(o.message??"Unable to delete node",e):m("Deleted node",{action:e,result:o.data})},"create.tag":({action:e,payload:t})=>{let{id:n,name:o}=t,r=g.createTag({id:n,name:o});return x(r)?w(r.message??"Unable to create tag",e):m("Tag added",{action:e,result:r.data})},"create.contributor":({action:e,payload:t})=>{let{id:n,name:o}=t,r=g.createContributor({id:n,name:o});return x(r)?w(r.message??"Unable to create contributor",e):m("Contributor created",{action:e,result:r.data})},"tag.issue":({action:e,payload:t})=>{let{id:n,target:o,tagId:r}=t,i=g.tag(o,r,n);return x(i)?w(i.message??"Unable to tag issue",e):m("Issue tagged",{action:e,result:i.data})},"assign.issue":({action:e,payload:t})=>{let{id:n,contributor:o,target:r}=t,i=g.assign(r,o,n);return x(i)?w(i.message??"Unable to assign issue",e):m("Assigned successfully",{action:e,result:i.data})},"move.node":({action:e,payload:t})=>{let{id:n,parent:o,pos:r}=t,i=g.moveNode({id:n,parentId:o,position:r});return x(i)?w(i.message??"Failed to move node",e):m("Moved node",{action:e,result:i.data})},"edit.description":({action:e,payload:t})=>{let{id:n,md:o}=t,r=g.editValue(n,o);return x(r)?w(r.message??"Unable to edit description",e):m("Set node value",{action:e,result:r.data})},"close.issue":({action:e,payload:t})=>{let{id:n}=t,o=g.getNode(n);if(!o)return w("Unable to locate issue",e);if(!he(o))return w("Can only close issues",e);let r=g.getNode(Me);if(!r)return w("Unable to locate target swimlane",e);if(r.id===o.parentNodeId)return w("Cannot close closed issue",e);let s=g.moveNode({id:n,parentId:r.id,navigate:!1});return x(s)?w(s.message??"Unable to close issue",e):m("Issue closed",{action:e,result:s.data})},"reopen.issue":({action:e,payload:t})=>{let{id:n}=t,o=g.getNode(n);if(!o)return w("Unable to locate issue",e);if(!he(o))return w("Can only reopen issues",e);let r=g.getNode(Me);if(!r)return w("Unable to locate closed swimlane",e);if(!(o.parentNodeId===r.id))return w("Issue is not closed",e);let s=Rn(o);if(!s)return w("Unable to resolve previous parent from issue history",e);if(s===r.id)return w("Previous parent resolves to closed swimlane",e);if(!g.getNode(s))return w("Previous parent no longer exists",e);let d=g.moveNode({id:n,parentId:s,navigate:!1});return x(d)?w(d.message??"Unable to reopen issue",e):m("Issue reopened",{action:e,result:d.data})},"lock.node":({action:e,payload:t})=>{let{id:n}=t,o=g.lockNode(n);return x(o)?w(o.message??"Unable to lock node",e):m("Node locked",{action:e,result:o.data})}},Rr=(e,t)=>{let n=g.getNode(e);n&&g.updateNode({...n,log:[...n.log??[],t]})},Or=e=>{switch(e.action){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"delete.node":case"move.node":case"close.issue":case"reopen.issue":case"edit.description":return[e.payload.id];case"tag.issue":case"assign.issue":return[e.payload.id,e.payload.target];case"create.tag":case"create.contributor":default:return[]}};function we(e){let t=kr[e.action],n=t(e);if(!x(n)){let o=[...new Set(Or(e))];for(let r of o)Rr(r,e)}return n}var On=e=>e.map(t=>we(t));import $n from"node:fs";import zr from"node:os";import jn from"node:path";import{decodeTime as jr,monotonicFactory as Gr}from"ulid";var at={preferredEditor:null,userName:null},pe=()=>at,ze=e=>(at={...at,...e},at);var Wn=e=>({action:e.action,payload:e.payload});import Vt from"node:fs";import Hn from"node:path";import{ulid as Ur}from"ulid";var Wr=".epiq",Hr="events",_r=(e=process.cwd())=>Hn.join(e,Wr,Hr),Vr=e=>{let t=Object.keys(e).filter(n=>n!=="id");return t.length!==1?c(`Invalid persisted event: expected exactly 1 action key, got ${t.length}`):m("Resolved persisted action",t[0])},Kr=e=>{let t=Vr(e);if(x(t))return c(t.message);let n=t.data;if(!n)return c("Action key is undefined");let o=e[n];return m("Decoded persisted event",{id:e.id[0]??Ur(),action:n,payload:o,userId:J()})};function _n(e=process.cwd()){let t=_r(e);if(!Vt.existsSync(t))return[];let n=Vt.readdirSync(t).filter(r=>r.endsWith(".jsonl")).map(r=>Hn.join(t,r)),o=[];for(let r of n){let i=Vt.readFileSync(r,"utf8");for(let s of i.split(`
7
- `)){let a=s.trim();if(a)try{o.push(JSON.parse(a))}catch{}}}return $r(o)}function Vn(e=process.cwd()){return _n(e).map(Kr).filter(ue).map(({data:t})=>t)}function Kn(e=process.cwd()){return _n(e).at(-1)?.id[0]??null}var $r=e=>{let t=new Map(e.map(a=>[a.id[0],a])),n=new Map;for(let a of e){let d=a.id[1],l=n.get(d)??[];l.push(a),n.set(d,l)}for(let a of n.values())a.sort((d,l)=>{let[v]=d.id,[p]=l.id;return v.localeCompare(p)});let o=[],r=new Set,i=a=>{let d=n.get(a)??[];for(let l of d){let[v]=l.id;r.has(v)||(r.add(v),o.push(l),i(v))}};i(null);let s=[...e].filter(a=>{let[d]=a.id;return!r.has(d)}).sort((a,d)=>{let[l,v]=a.id,[p,C]=d.id,h=v===null||t.has(v),A=C===null||t.has(C);if(h&&!A)return-1;if(!h&&A)return 1;let E=(v??"").localeCompare(C??"");return E!==0?E:l.localeCompare(p)});return[...o,...s]};var zn=Gr(),qr=".epiq",Xr="events",Kt=e=>e.trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"unknown",J=()=>{let e=process.env.EPIQ_ACTOR_ID;if(e?.trim())return Kt(e);let t=pe().userName;if(t?.trim())return Kt(t);try{return Kt(zr.userInfo().username)}catch{return"unknown"}},Gn=(e=process.cwd())=>jn.join(e,qr,Xr),Jr=(e=process.cwd())=>{let t=J();return jn.join(Gn(e),`${t}.jsonl`)},Yr=(e,t)=>({[e.action]:e.payload,id:t});function qn(e,t=process.cwd()){try{let n=Gn(t),o=Jr(t);$n.mkdirSync(n,{recursive:!0});let r=Kn(t),i;if(r){let a=jr(r),d=Math.max(Date.now(),a+1);i=zn(d)}else i=zn();let s=Yr(Wn(e),[i,r]);return $n.appendFileSync(o,`${JSON.stringify(s)}
8
- `,"utf8"),m("Event persisted",{path:o,entry:s})}catch(n){let o=n instanceof Error?n.message:"Unknown persist error";return c(`Failed to persist event: ${o}`)}}function U(e){let t=we(e);if(t.result!==Z.Success)return t;let n=qn(e);return x(n)?n:t}function dt(e){return e.map(t=>U(t))}var u={DEFAULT:"default",MOVE:"move",HELP:"help",COMMAND_LINE:"command-line"};var Qr=(e,t)=>e.ctrl&&e.name==="w"||e.meta&&e.name==="backspace"||t==="",Zr=(e,t)=>e.meta&&e.name==="b"||t==="\x1Bb",ei=(e,t)=>e.meta&&e.name==="f"||t==="\x1Bf",Xn=(e,t)=>{if(Zr(e,e.sequence))return"MoveCursorLeftOfWord";if(ei(e,e.sequence))return"MoveCursorRightOfWord";if(Qr(e,e.sequence))return"EraseInputWord";switch(e.name){case"tab":return"autoCompleteCommand";case"up":return"getLastCommandFromHistory";case"down":return"getNextCommandFromHistory";case"left":return"MoveCursorLeft";case"right":return"MoveCursorRight";case"return":return"confirm";case"backspace":return t?"eraseInput":"exitCommandLine";case"escape":return"exitCommandLine";default:return"captureInput"}};var Jn=e=>{let t=new Map;for(let n of e)for(let o=1;o<=n.length;o++){let r=n.slice(0,o),i=t.get(r);i?i.push(n):t.set(r,[n])}return t},Yn=(e,t)=>t?e.get(t)??[]:[];var Qn=new WeakMap,ti=e=>{let t=Qn.get(e);return t||(t=Jn(e),Qn.set(e,t)),t};var Zn=({wordList:e,inputToMatch:t,overlapThreshold:n=1})=>{let o=t.toLowerCase();return Yn(ti(e),o).filter(i=>ot(o,i)>=n)};var eo=({inputToMatch:e,lastWord:t},n)=>{if(t.endsWith(" "))return{hint:"",hints:[],overlap:0,remainder:""};let o=Zn({wordList:n,inputToMatch:e,overlapThreshold:1});return ni(t,o)},ni=(e,t)=>{let n=t[0]??"",o=ot(e.toLowerCase(),n.toLowerCase()),r=n?n+" ":"",i=r.slice(o);return{hint:r,hints:t,overlap:o,remainder:i}};var Le={urgent:"red",critical:"red",important:"red",blocker:"red",asap:"red",immediate:"red",fail:"red",failure:"red",broken:"red",bug:"red",error:"red",incident:"red",outage:"red",production:"red",crash:"red",security:"red",warning:"yellow",warn:"yellow",risky:"yellow",risk:"yellow",attention:"yellow",pending:"yellow",review:"yellow","needs-review":"yellow",qa:"yellow",testing:"yellow",test:"yellow",validate:"yellow",verification:"yellow",staging:"yellow",check:"yellow","follow-up":"yellow",followup:"yellow",waiting:"yellow",blocked:"yellow",hold:"yellow",done:"green",complete:"green",completed:"green",success:"green",ok:"green",stable:"green",resolved:"green",fixed:"green",closed:"green",merged:"green",released:"green",deployed:"green",approved:"green",verified:"green",working:"green",healthy:"green",pass:"green",passing:"green",info:"blue",information:"blue",note:"blue",docs:"blue",documentation:"blue",doc:"blue",guide:"blue",help:"blue",explanation:"blue",detail:"blue",details:"blue",context:"blue",design:"blue",discussion:"blue",proposal:"blue",idea:"blue",feature:"magenta",enhancement:"magenta",improvement:"magenta",refactor:"magenta",refactoring:"magenta",cleanup:"magenta",optimize:"magenta",optimization:"magenta",perf:"magenta",performance:"magenta",upgrade:"magenta",migration:"magenta",modernize:"magenta",debt:"magenta",todo:"cyan",next:"cyan",planned:"cyan",plan:"cyan",future:"cyan",backlog:"cyan",investigate:"cyan",explore:"cyan",prototype:"cyan"};var B=e=>({[N.FILTER]:["tag","assignee","description","title","clear"],[N.DELETE]:["confirm"],[N.RE_OPEN_ISSUE]:["confirm"],[N.CLOSE_ISSUE]:["confirm"],[N.SET_USERNAME]:[],[N.SET_VIEW]:["dense","wide"],[N.SET_EDITOR]:["vi","vim","nvim","nano","micro","emacs","hx","code","code-insiders","subl","notepad","notepad++","idea","webstorm","default","system","$EDITOR","$VISUAL"],[N.NONE]:[...new Set([...Object.values(N)])],[N.TAG]:[...new Set([...Object.keys(Le),...g.getExistingTags()])],[N.ASSIGN]:g.getExistingAssignees(),[N.HELP]:[],[N.RENAME]:[],[N.NEW]:["issue","swimlane","board"]})[e];import Pe from"chalk";var oi=e=>{let t=0;for(let n=0;n<e.length;n++)t=e.charCodeAt(n)+((t<<5)-t),t|=0;return Math.abs(t)},ri=(e,t,n)=>{t/=100,n/=100;let o=(1-Math.abs(2*n-1))*t,r=e/60,i=o*(1-Math.abs(r%2-1)),s=0,a=0,d=0;r>=0&&r<1?(s=o,a=i):r>=1&&r<2?(s=i,a=o):r>=2&&r<3?(a=o,d=i):r>=3&&r<4?(a=i,d=o):r>=4&&r<5?(s=i,d=o):(s=o,d=i);let l=n-o/2,v=p=>Math.round((p+l)*255).toString(16).padStart(2,"0");return`#${v(s)}${v(a)}${v(d)}`},De=e=>{let n=oi(e)%360;return ri(n,65,45)},lt=[[168,85,247],[34,211,238],[59,130,246]],zt=(e,t,n)=>e+(t-e)*n,ii=(e,t,n)=>[Math.round(zt(e[0],t[0],n)),Math.round(zt(e[1],t[1],n)),Math.round(zt(e[2],t[2],n))],to=e=>{let t=Math.max(0,Math.min(1,e)),n=lt.length-1,o=t*n,r=Math.min(Math.floor(o),n-1),i=o-r;return lt?ii(lt[r],lt[r+1],i):[0,0,0]},si=e=>{let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)>>>0;return t},je=e=>si(e.toLowerCase().trim())/4294967295,ai=e=>{let t=je(e),[n,o,r]=to(t);return{normal:i=>Pe.bgRgb(n,o,r).black(i),cursor:i=>Pe.bgRgb(n,o,r).white.bold(i)}},jt=e=>{let t=je(e),[n,o,r]=to(t);return{fg:i=>Pe.rgb(n,o,r)(i),fgCursor:i=>Pe.rgb(n,o,r).inverse(i),bg:i=>Pe.bgRgb(n,o,r).black(i),bgCursor:i=>Pe.bgRgb(n,o,r).white.bold(i)}},Gt=e=>ai(e).normal(` ${e} `);var ne=()=>({validity:Q.Valid,completionWordList:[]}),te=({message:e,completionWordList:t})=>({validity:Q.Invalid,message:e,completionWordList:t}),ct=e=>e.length===0,ee=({prefix:e="",wordList:t,postfix:n="",noOfHints:o=2,inputString:r})=>{let a=[...t.filter(Boolean).filter(l=>l.startsWith(r.trim()))].sort((l,v)=>je(l)-je(v)).slice(0,o).map(Gt),d=a.length>1?a.join(" "):"";return d?`${e}${d}${n}`:""},no=()=>ne(),qt=({modifier:e})=>{let t="confirm";return e===t?ne():te({message:ct(e)?`if you are certain, enter ${Gt(t)}`:"",completionWordList:[t]})},oo=({list:e,hint:t})=>({modifier:n})=>e.includes(n)?ne():te({message:ct(n)?t:"",completionWordList:[]}),ro=({hint:e})=>({modifier:t,inputString:n})=>ct(t)&&ct(n)?te({message:e,completionWordList:[]}):ne(),di={[N.FILTER]:e=>{if(e.modifier==="clear")return ne();let t=s=>B(N.FILTER).includes(s);if(!e.modifier||!t(e.modifier??""))return te({message:ee({wordList:B(N.FILTER),noOfHints:100,inputString:e.inputString}),completionWordList:B(N.FILTER)});let o=Object.values(f().tags).map(s=>s.name),r=Object.values(f().contributors).map(s=>s.name),i=e.modifier==="tag"?o:e.modifier==="assignee"?r:[];return e.inputString?i.length&&!i.includes(e.inputString.trim()??"")?te({message:ee({prefix:`existing ${e.modifier}s...`,wordList:i,noOfHints:10,inputString:e.inputString}),completionWordList:i}):ne():te({message:ee({prefix:"one of... ",wordList:i,noOfHints:10,inputString:e.inputString}),completionWordList:i})},[N.NONE]:e=>{let t=B(N.NONE);return e.command?ne():te({message:ee({prefix:"commands... ",wordList:t,noOfHints:100,inputString:e.inputString}),completionWordList:[]})},[N.NEW]:e=>oo({list:B(N.NEW),hint:ee({wordList:B(N.NEW),noOfHints:3,inputString:e.inputString})})(e),[N.HELP]:no,[N.RENAME]:no,[N.DELETE]:e=>qt(e),[N.CLOSE_ISSUE]:e=>qt(e),[N.RE_OPEN_ISSUE]:e=>qt(e),[N.TAG]:e=>ro({hint:ee({prefix:"tag name like... ",wordList:B(N.TAG),noOfHints:3,inputString:e.inputString})})(e),[N.ASSIGN]:e=>ro({hint:ee({wordList:B(N.ASSIGN),postfix:", etc.",noOfHints:3,inputString:e.inputString})})(e),[N.SET_EDITOR]:e=>{let t=B(N.SET_EDITOR);return e.modifier?ne():te({message:ee({wordList:t,noOfHints:100,inputString:e.inputString}),completionWordList:[]})},[N.SET_USERNAME]:e=>e.inputString?ne():te({message:"enter global username (must be unique in project for consistent logs)",completionWordList:[]}),[N.SET_VIEW]:e=>oo({list:B(N.SET_VIEW),hint:ee({wordList:B(N.SET_VIEW),noOfHints:3,inputString:e.inputString})})(e)},io=Object.fromEntries(Object.entries(di).map(([e,t])=>[e,{validate:(n,o,r)=>t({modifier:o,command:n,inputString:r})}]));var so=["frontend","backend","infrastructure","architecture","integration","configuration","implementation","application","deployment","environment","framework","platform","service","component","module","gateway","pipeline","containerization","orchestrator","exception","incident","defect","regression","degradation","malfunction","instability","intermittent","reproducibility","reproduction","investigation","triage","workaround","mitigation","remediation","optimization","stabilization","refinement","failure","outage","blocking","criticality","severity","escalation","diagnostics","analysis","resolution","corruption","inconsistency","validation","verification","authorization","authentication","confidentiality","availability","accessibility","reliability","compliance","governance","encryption","decryption","integrity","auditing","traceability","accountability","protection","privileges","permissions","dependency","orchestration","provisioning","synchronization","compatibility","incompatibility","interoperability","observability","instrumentation","telemetry","loadbalancing","discovery","registration","scheduling","coordination","distribution","isolation","virtualization","serialization","deserialization","initialization","instantiation","propagation","aggregation","consolidation","normalization","standardization","transformation","reconciliation","correlation","processing","indexing","partitioning","enrichment","validation","filtering","streaming","batching","concurrency","parallelism","contention","deadlock","throttling","ratelimiting","backpressure","fragmentation","saturation","exhaustion","partitioning","replication","redundancy","failover","deprecation","obsolescence","starvation","overload","underutilization","latency","throughput","refactoring","modularization","encapsulation","abstraction","extensibility","configurability","maintainability","recoverability","sustainability","readability","testability","debuggability","reusability","simplicity","consistency","performance","functionality","requirement","recommendation","improvement","enhancement","clarification","documentation","description","acceptance","criteria","estimation","prioritization","dependency","deliverable","milestone","iteration"];var L={None:"none",ViewHelp:"view-help",Rename:"rename",Delete:"delete",Filter:"filter",SetView:"set-view",SetEditor:"set-editor",SetUserName:"set-user-name",NewItem:"add-new-item",TagTicket:"ticket-tag",AssignUserToTicket:"ticket-assign-user",CloseIssue:"close-issue",ReopenIssue:"re-open-issue"};var ao=e=>Object.values(N).includes(e),lo=(e,t)=>{let n=e.command??"",{modifier:o,target:r,inputString:i}=e,{message:s,validity:a,completionWordList:d}=io[n].validate(n,o,i),l=r==="command"?Object.values(N):n&&e.target==="modifier"?B(n):so;return{validity:a,command:e.command,modifier:e.modifier,inputString:e.inputString,infoMessage:s??"",autoCompletion:t?eo(e,[...d,...l]):{hint:"",hints:[],remainder:"",overlap:0}}};var co=e=>{let t=e.trimStart(),n=ci(t),o=(n[0]??"").trimStart().trimEnd(),r=(n[1]??"").trimStart().trimEnd(),i=mi(e),s=ao(o)?o:null,a=s!==null,d=o!=="",l=e.endsWith(" "),v=s?B(s)??[]:[],p=s&&v.includes(r)?r:"",C="word";n.length<=1?C="command":n.length===2&&(C="modifier");let h=li(t,s,p);return{raw:e,trimmedStart:t,words:n,firstWord:o,lastWord:i,hasCommand:d,command:s,isCommandKeyword:a,isLastWordCompleted:l,modifier:p,target:C,inputToMatch:i,inputString:h}},li=(e,t,n)=>{let o=e;return t&&o.startsWith(t)&&(o=o.slice(t.length)),o=o.replace(/^\s+/,""),n&&o.startsWith(n)&&(o=o.slice(n.length),o=o.replace(/^\s+/,"")),o},ci=e=>e?e.split(/\s+/):[],mi=e=>e.trimEnd().split(/\s+/).at(-1)??"";var mo=" ",R={commandHistory:[],value:"",commandHistoryIndex:-1,cursorPosition:0,commandIsPending:!1,commandMeta:{command:null,modifier:"",infoMessage:"",inputString:"",validity:Q.None,autoCompletion:{hint:"",hints:[],remainder:"",overlap:0}}},Xt=new Set,uo=()=>{for(let e of Xt)e()},po=e=>(Xt.add(e),()=>Xt.delete(e)),oe=e=>{let n=e(R),o=co(n.value),r=n.cursorPosition===n.value.length;R={...n,commandMeta:lo(o,r)},uo()},Jt=({message:e,result:t})=>{let n=structuredClone(R);n.commandMeta={...n.commandMeta,infoMessage:e??"",validity:t==="fail"?"invalid":"valid"},n.commandIsPending=!0,R=n,uo()},Yt=e=>{oe(t=>({...t,cursorPosition:Math.max(0,Math.min(t.value.length,t.cursorPosition+e))}))},Qt=e=>{oe(t=>{let{value:n,cursorPosition:o}=t,r=o;if(e==="left"){for(;r>0&&n[r-1]===" ";)r--;for(;r>0&&n[r-1]!==" ";)r--}else{for(;r<n.length&&n[r]!==" ";)r++;for(;r<n.length&&n[r]===" ";)r++}return{...t,cursorPosition:r}})},fo=()=>{oe(e=>{let t=e.value.slice(e.cursorPosition),n=Math.max(0,e.cursorPosition-1);return{...e,value:e.value.slice(0,n)+t,cursorPosition:n,commandIsPending:!1}})},go=()=>{oe(e=>{let{value:t,cursorPosition:n}=e,o=n;for(;o>0&&t[o-1]===" ";)o--;for(;o>0&&t[o-1]!==" ";)o--;let r=t.slice(n);return{...e,value:t.slice(0,o)+r,cursorPosition:o,commandIsPending:!1}})},fe=e=>{oe(t=>{let n=Math.max(0,Math.min(t.cursorPosition,t.value.length)),o=t.value.slice(0,n),r=t.value.slice(n),i=e(o,t.commandMeta.autoCompletion),s=i+r,a=Math.max(0,Math.min(i.length,s.length));return{...t,value:s,cursorPosition:a,commandIsPending:!1}})},xo=()=>{oe(e=>({...e,commandIsPending:!0}))},vo=()=>{oe(e=>({...e,commandHistory:[e.value,...e.commandHistory].slice(0,20),commandHistoryIndex:-1,commandIsPending:!1})),ui()},Co=()=>{oe(e=>{let t=Math.min(e.commandHistoryIndex+1,e.commandHistory.length-1),n=e.commandHistory[t]??"";return{...e,commandHistoryIndex:t,value:n,cursorPosition:n.length}})},yo=()=>{oe(e=>{let t=Math.max(e.commandHistoryIndex-1,-1),n=t===-1?"":e.commandHistory[t]??"";return{...e,commandHistoryIndex:t,value:n,cursorPosition:n.length}})},ui=()=>fe(()=>""),re=()=>R,mt=()=>{let[e,...t]=R.value.split(mo);return t.join(mo).trim()};function pi(e){switch(e.name){case"up":case"down":case"left":case"right":return e.name;case"k":return"up";case"j":return"down";case"h":return"left";case"l":return"right";default:return null}}function fi(e,t,n){let o=f().currentNode.childNavigationAcrossParents;switch(t){case"up":return e==="vertical"?n.prevItem:o?n.prevContainer:null;case"down":return e==="vertical"?n.nextItem:o?n.nextContainer:null;case"left":return e==="horizontal"?n.prevItem:o?n.prevContainer:null;case"right":return e==="horizontal"?n.nextItem:o?n.nextContainer:null}}function No(e,t){let n=re();if(e.sequence===":"&&n.value==="")return"initCommandLine";if(t===u.MOVE)switch(e.name){case"m":case"return":return"confirmMove"}if(t===u.COMMAND_LINE)return Xn(e,n.value);let o=pi(e);if(o){let r=t===u.MOVE?{prevItem:"movePreviousItem",nextItem:"moveNextItem",prevContainer:"moveToPreviousContainer",nextContainer:"moveToNextContainer"}:{prevItem:"navPreviousItem",nextItem:"navNextItem",prevContainer:"navToPreviousContainer",nextContainer:"navToNextContainer"};return fi(f().currentNode.childRenderAxis,o,r)}if(e.ctrl&&e.name==="c")return"exit";switch(e.name){case"e":return"edit";case"n":return"addItem";case"m":return"initMove";case"d":return"Delete";case"e":case"return":return"confirm";case"space":return"confirm";case"v":return f().viewMode==="wide"?"SetViewDense":"SetViewWide";case"q":case"escape":return"exit";default:return null}}import{ulid as ho}from"ulid";var Fe=null,Io=()=>structuredClone(Fe),ut=e=>Fe=e,Eo=()=>{let{currentNode:e,selectedIndex:t}=f(),o=b(e.id)[t];return o?m("Resolved selected child",o):c("Target node not found")};function Zt(e){let t=Eo();if(x(t))return t;let{currentNode:n,nodes:o}=f();if(!n.parentNodeId)return c("Missing parent node id");let r=o[n.parentNodeId];if(!r)return c("Missing parent node");let i=P(r.id),s=i.findIndex(({id:l})=>l===n.id);if(s<0)return c("Current node not found among siblings");let a=i[s+e];if(!a)return c("Missing sibling node");if(ut({id:ho(),userId:J(),action:"move.node",payload:{id:t.data.id,parent:a.id,pos:{at:"end"}}}),!Fe)return c("Could not materialize move state");let d=we(Fe);return x(d)?d:m("Node moved successfully",d.data)}function en(e){let t=Eo();if(x(t))return t;let{currentNode:n,selectedIndex:o}=f(),i=P(n.id)[o+e];if(!i)return c("Missing sibling node");if(ut({id:ho(),userId:J(),action:"move.node",payload:{id:t.data.id,parent:n.id,pos:{at:e===1?"after":"before",sibling:i.id}}}),!Fe)return c("Could not materialize move state");let s=we(Fe);return x(s)?s:m("Node moved successfully",s.data)}var pt=[{intent:"exit",mode:u.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(M({mode:u.DEFAULT}),m("Cancelling move",null))},{intent:"initMove",mode:u.DEFAULT,description:"[m] move init/confirm",action:()=>f().selectedIndex===-1?c("No item selected"):(M({mode:u.MOVE}),m("Init movie succeeded",null))},{intent:"confirmMove",mode:u.MOVE,action:()=>{M({mode:u.DEFAULT});let e=Io();return e!==null&&U(e),ut(null),m("Pasting item",null)}}],ft=[{intent:"movePreviousItem",mode:u.MOVE,action:()=>en(-1)},{intent:"moveNextItem",mode:u.MOVE,action:()=>en(1)}],Ao=[{intent:"moveToNextContainer",mode:u.MOVE,action:()=>Zt(1)},{intent:"moveToPreviousContainer",mode:u.MOVE,action:()=>Zt(-1)}];var bo={[T.WORKSPACE]:[...pt,...ft],[T.BOARD]:[...pt,...ft],[T.SWIMLANE]:[...pt,...ft,...Ao],[T.TICKET]:[],[T.FIELD]:[],[T.FIELD_LIST]:[],[T.TEXT]:[]};import{ulid as Ti}from"ulid";import{spawnSync as Ii}from"node:child_process";import Ei from"node:os";import wo from"node:path";import{ulid as Ai}from"ulid";import{accessSync as gi,copyFileSync as xi,existsSync as gt,mkdirSync as So,readdirSync as To,readFileSync as vi,renameSync as Ci,rmSync as yi,statSync as Mo,unlinkSync as Ni,writeFileSync as hi}from"node:fs";import Be from"node:path";var $={writeToFile:(e,t)=>{try{let n=Be.dirname(e);gt(n)||So(n,{recursive:!0});let o=typeof t=="string"?t:JSON.stringify(t,null,2);hi(e,o,"utf-8")}catch(n){logger.error(`Failed to write file at ${e}:`,n)}},readFile:e=>{try{return vi(e,"utf-8")}catch(t){return logger.error(`Failed to read file at ${e}:`,t),null}},readFileJSON(e){try{let t=$.readFile(e);return t===null?null:JSON.parse(t)}catch(t){return logger.error(`Failed to read JSON at ${e}:`,t),null}},dirExists:e=>{try{return gt(e)&&Mo(e).isDirectory()}catch{return!1}},async fileExists(e){try{return await gi(e),!0}catch{return!1}},mkDir:e=>So(e,{recursive:!0}),locateFolder:e=>{let t=process.cwd(),{root:n}=Be.parse(t);for(;;){let o=Be.join(t,e);try{if(gt(o)&&Mo(o).isDirectory())return o}catch{logger.error(`Unable to locate folder ${e}`)}if(t===n)break;t=Be.dirname(t)}return null},readFirstJSON(e){try{if(!$.dirExists(e))return null;let t=To(e).filter(o=>o.endsWith(".json")).sort()[0];if(!t)return null;let n=Be.join(e,t);return $.readFileJSON(n)}catch(t){return logger.error(`Could not read first JSON in folder ${e}`,t),null}},listDir:e=>{try{return $.dirExists(e)?To(e):[]}catch(t){return logger.error(`Failed to list dir ${e}`,t),[]}},rmFile(e){try{Ni(e)}catch(t){t?.code!=="ENOENT"&&logger.error(`Unable to remove file ${e}`)}},rmDir(e){try{yi(e,{recursive:!0,force:!0})}catch(t){t?.code!=="ENOENT"&&logger.error(`Unable to remove dir ${e}`)}},moveFile(e,t,n){if(this.mkDir(Be.dirname(t)),!n?.overwrite&&gt(t))throw new Error(`moveFile: destination exists: ${t}`);n?.overwrite&&this.rmFile(t);try{Ci(e,t)}catch(o){if(o?.code==="EXDEV"){xi(e,t),this.rmFile(e);return}throw o}}};function bi(){let{preferredEditor:e}=pe(),t=[e,process.env.VISUAL,process.env.EDITOR,"vim","vi","nano"].filter(n=>!!n?.trim());return[...new Set(t)]}function Si(e,t){return/(^|\/)code(-insiders)?$/.test(e.trim())?`${e} --wait "${t}"`:`${e} "${t}"`}function Lo(e){let t=wo.join(Ei.tmpdir(),"epiq");$.mkDir(t);let n=wo.join(t,Ai());$.writeToFile(n,e??"");let o=bi();for(let r of o){let i=Si(r,n),s=Ii(i,{stdio:"inherit",shell:!0});if(!s.error&&s.status===0){let a=$.readFile(n);if(a==null)return c("Unable to read edited file");let d=a.replace(/\r?\n$/,"");return m("Successfully edited",d)}}return c("Unable to open editor")}var Ie=(e,t)=>{let n=e.find(o=>o.context===t);return n!==void 0?m("Found node",n):c("Unable to find node in breadcrumb")};var D={exit(){process.exit(0)},enterChildNode(){let e=f(),t=e.currentNode,n=Math.max(0,e.selectedIndex),o=b(t.id)[n];!o||t.context==="FIELD"||D.navigate({currentNode:o,selectedIndex:b(o.id).length?0:-1})},enterParentNode(){let{currentNode:e,nodes:t}=f();if(!e.parentNodeId){logger.info("Missing parent node id");return}let n=t[e.parentNodeId];if(!n){logger.error("Parent not found");return}let o=b(n.id),r=o.findIndex(({id:s})=>s===e.id),i=o.length===0?-1:r>=0?r:0;D.navigate({currentNode:n,selectedIndex:i})},navigateToNextItem:()=>Po(1),navigateToPreviousItem:()=>Po(-1),navigateToNextContainer:()=>Do(1),navigateToPreviousContainer:()=>Do(-1),navigate:({currentNode:e=f().currentNode,selectedIndex:t})=>{M({currentNodeId:e.id,selectedIndex:t})}},Po=e=>{let t=f(),n=b(t.currentNode.id).length;if(n===0)return;let r=(Math.max(0,t.selectedIndex)+e+n)%n;D.navigate({selectedIndex:r})},Do=e=>{let{currentNode:t,nodes:n,selectedIndex:o}=f();if(!t.childNavigationAcrossParents)return;if(!t.parentNodeId){logger.error("Missing parent node id");return}let r=n[t.parentNodeId];if(!t||!r)return;let i=b(r.id),s=i.findIndex(C=>C.id===t.id);if(s<0)return;let a=i.at(s+e)??i.at(0);if(!a)return;let d=b(a.id),l=Math.max(0,d.length-1),v=Math.min(Math.max(0,o),l),p=d.length?v:-1;D.navigate({currentNode:a,selectedIndex:p})};var Fo=[{intent:"addItem",mode:u.DEFAULT,description:"[n] new...",action:()=>(M({mode:u.COMMAND_LINE}),fe(()=>`${N.NEW} `),m("Adding new item",null))},{intent:"Delete",mode:u.DEFAULT,description:"[d] delete",action:()=>(M({mode:u.COMMAND_LINE}),fe(()=>`${N.DELETE} `),m("Deleting item",null))},{intent:"initCommandLine",mode:u.DEFAULT,description:"[:] focus command line",action:()=>(M({mode:u.COMMAND_LINE}),fe(()=>""),m("Entering command line mode",null))},{intent:"confirm",mode:u.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>(D.enterChildNode(),m("Entering context",null))},{intent:"exit",mode:u.DEFAULT,description:"[q] exit context",action:()=>(D.enterParentNode(),m("Exiting context",null))},{intent:"navPreviousItem",mode:u.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(D.navigateToPreviousItem(),m("Navigating to previous item",null))},{intent:"navNextItem",mode:u.DEFAULT,action:()=>(D.navigateToNextItem(),m("Navigating to next item",null))},{intent:"navToPreviousContainer",mode:u.DEFAULT,action:()=>(D.navigateToPreviousContainer(),m("Navigating to previous container",null))},{intent:"navToNextContainer",mode:u.DEFAULT,action:()=>(D.navigateToNextContainer(),m("Navigating to next container",null))},{intent:"edit",mode:u.DEFAULT,action:()=>{let e=Ie(f().breadCrumb,"TICKET");if(x(e))return c("No issue node");let t=e.data,n=b(t.id).find(s=>s?.title==="Description");if(!n)return c("Description field not found");let o=n.props.value;if(typeof o!="string")return c("Description field is not a text field");let r=Lo(o);if(x(r))return c("Failed to edit description");let i=r.data;return i===o?m("No changes made",void 0):U({id:Ti(),action:"edit.description",userId:J(),payload:{id:n.id,md:i}})}},{intent:"SetViewDense",mode:u.DEFAULT,description:"[v] view change (wide/dense)",action:()=>(M({viewMode:"dense"}),m("View set",null))},{intent:"SetViewWide",mode:u.DEFAULT,action:()=>(M({viewMode:"wide"}),m("View set",null))}];var Bo=e=>{let{context:t}=f()?.currentNode;if(!t)return L.None;switch(e){case N.DELETE:return L.Delete;case N.HELP:return L.ViewHelp;case N.RE_OPEN_ISSUE:return L.ReopenIssue;case N.CLOSE_ISSUE:return L.CloseIssue;case N.TAG:return L.TagTicket;case N.ASSIGN:return L.AssignUserToTicket;case N.RENAME:return L.Rename;case N.NEW:return L.NewItem;case N.FILTER:return L.Filter;case N.SET_USERNAME:return L.SetUserName;case N.SET_EDITOR:return L.SetEditor;case N.SET_VIEW:return L.SetView;default:return L.None}};import{ulid as O}from"ulid";import{monotonicFactory as Mi,ulid as xt}from"ulid";var vt=Mi(),ko=({name:e,parent:t,userId:n})=>{let o=vt(),r=vt(),i=vt(),s=vt();return[{id:xt(),userId:n,action:"add.issue",payload:{id:o,parent:t,name:e}},{id:xt(),userId:n,action:"add.field",payload:{id:r,parent:o,name:"Description",val:""}},{id:xt(),userId:n,action:"add.field",payload:{id:i,parent:o,name:"Assignees"}},{id:xt(),userId:n,action:"add.field",payload:{id:s,parent:o,name:"Tags"}}]};import wi from"node:os";import Li from"node:path";var Pi=".epiqrc",Ct=()=>Li.join(wi.homedir(),Pi),Di=e=>{try{let t=JSON.parse(e);return m("Parsed config",t??{})}catch{return c("Invalid ~/.epiqrc JSON")}},tn=()=>{let e=Ct(),t=$.readFile(e);return t==null||t.trim()===""?m("No config found, using empty config",{}):Di(t)},nn=e=>{let t=Ct();try{return $.writeToFile(t,JSON.stringify(e,null,2)+`
9
- `),m("Config written",null)}catch{return c("Unable to write ~/.epiqrc")}},on=e=>{let t=tn();if(x(t))return c("Failed to set preferred editor");let n={...t.data,...e};return nn(n)};var Fi=e=>Object.values(f().tags).find(t=>t.name===e),Bi=e=>Object.values(f().contributors).find(t=>t.name===e),q=()=>J(),Ro=[{intent:L.Delete,mode:u.COMMAND_LINE,action:()=>{let{currentNode:e,selectedIndex:t}=f(),n=b(e.id)[t];return n?U({id:O(),userId:q(),action:"delete.node",payload:{id:n.id}}):c("Unable to resolve child to delete")},onSuccess:()=>M({mode:u.DEFAULT})},{intent:L.Filter,mode:u.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=re().commandMeta,n=/(!=|=)/,[o,r]=e.split(n);if(!o||!(a=>B(N.FILTER).map(d=>d.split(n)[0]).includes(a))(o))return c("Invalid filter modifier");let s={target:o,operator:"=",value:t.trim()};return j(a=>({...a,filters:e==="clear"?[]:[...a.filters,s],mode:u.DEFAULT})),m("Viewing help",null)}},{intent:L.ViewHelp,mode:u.COMMAND_LINE,action:()=>(M({mode:u.HELP}),m("Viewing help",null))},{intent:L.CloseIssue,mode:u.COMMAND_LINE,action:()=>{let{currentNode:e,selectedIndex:t}=f(),n=b(e.id)[t];if(!n)return c("Unable to close issue, no target found");if(!n.parentNodeId)return c("No target parent found");if(!he(n))return c("Cannot close in this context");let o=U({id:O(),userId:q(),action:"close.issue",payload:{id:n.id,parent:n.parentNodeId}});return x(o)?o:m("Viewing help",null)}},{intent:L.ReopenIssue,mode:u.COMMAND_LINE,action:()=>{let{currentNode:e,selectedIndex:t}=f(),n=b(e.id)[t];if(!n)return c("Unable to reopen issue, no target found");let o=n.context==="TICKET"?m("Resolved ticket",n):Te(n.id,"TICKET");if(x(o))return c("Cannot reopen in this context");let r=o.data,i=U({id:O(),userId:q(),action:"reopen.issue",payload:{id:r.id}});return x(i)?i:m("Issue reopened",null)},onSuccess:()=>M({mode:u.DEFAULT})},{intent:L.SetUserName,mode:u.COMMAND_LINE,action:()=>{let e=mt()?.trim();if(!e)return c("No username provided");let t=on({userName:e});return x(t)?t:(ze({userName:e}),M({mode:u.DEFAULT}),m(`Username set to "${e}"`,null))}},{intent:L.SetEditor,mode:u.COMMAND_LINE,action:()=>{let e=mt()?.trim();if(!e)return c("No editor provided");let t=on({preferredEditor:e});return x(t)?t:(ze({preferredEditor:e}),M({mode:u.DEFAULT}),m(`Editor configuration set to "${e}"`,null))}},{intent:L.NewItem,mode:u.COMMAND_LINE,action:(e,t)=>{if(!t.inputString)return c(`provide a name for your ${t.modifier}`);let n=o=>{let r=U(o);if(x(r))return r;let i=g.getNode(r.data.result.id);if(!i)return c("Created node not found");if(!i.parentNodeId)return r;let s=g.getNode(i.parentNodeId);return s?(D.navigate({currentNode:s,selectedIndex:g.getSiblings(i.parentNodeId).findIndex(({id:a})=>a===i.id)}),r):c("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:o}=f(),r=g.getNode(o);return r?n({id:O(),userId:q(),action:"add.board",payload:{id:O(),name:t.inputString,parent:r.id}}):c("Workspace not found")}if(t.modifier==="swimlane"){let o=Ie(f().breadCrumb,"BOARD");return x(o)?c("Unable to add swimlane in this context"):n({id:O(),userId:q(),action:"add.swimlane",payload:{id:O(),name:t.inputString,parent:o.data.id}})}if(t.modifier==="issue"){let o=Ie(f().breadCrumb,"SWIMLANE");if(x(o))return c("Unable to add issue in this context");let r=ko({name:t.inputString,parent:o.data.id,userId:q()}),i=dt(r);if(i.some(d=>x(d)))return c("Issue create failed: "+i.filter(x).map(d=>d.message).filter(Boolean).join(", "));let s=i[0];if(!s||x(s))return c("Issue creation failed");let a=r[0]?.payload.id;return a?(D.navigate({currentNode:o.data,selectedIndex:g.getSiblings(o.data.id).findIndex(({id:d})=>d===a)}),m("Issue created",null)):c("Unable to determine ticket id")}return Dn()},onSuccess:()=>M({mode:u.DEFAULT})},{intent:L.SetView,mode:u.COMMAND_LINE,action:()=>{let{commandMeta:e}=re();return e.validity===Q.Invalid?c("Invalid command "+Z):(j(t=>({...t,viewMode:e.modifier==="wide"?"wide":e.modifier==="dense"?"dense":t.viewMode})),m("View set",null))},onSuccess:()=>M({mode:u.DEFAULT})},{intent:L.Rename,mode:u.COMMAND_LINE,action:()=>{let{currentNode:e,selectedIndex:t}=f(),n=b(e.id)[t];if(!n)return c("Missing node");let o=mt();return o?U({id:O(),userId:q(),action:"edit.title",payload:{id:n.id,name:o}}):c("Provide a new name")},onSuccess:()=>M({mode:u.DEFAULT})},{intent:L.TagTicket,mode:u.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=re().commandMeta,n=e||t;if(!n)return c("Provide a tag");let{selectedIndex:o,currentNode:r}=f(),i=b(r.id)[o];if(!i)return c("Invalid tag target");let s=Te(i.id,"TICKET");if(x(s))return c("Unable to tag issue in this context");let a=s.data,d=Fi(n),l;if(d)l=d.id;else{let C=O(),h=U({id:O(),userId:q(),action:"create.tag",payload:{id:C,name:n}});if(x(h))return h;l=h.data.result.id}let v=g.getFieldByTitle(a.id,"Tags");return v?b(v.id).some(C=>C.props?.value===l)?c("Already tagged with that tag"):U({id:O(),userId:q(),action:"tag.issue",payload:{id:O(),target:a.id,tagId:l}}):c("Unable to locate tags field")},onSuccess:()=>M({mode:u.DEFAULT})},{intent:L.AssignUserToTicket,mode:u.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=re().commandMeta,n=e||t;if(!n)return c("Provide an assignee");let{selectedIndex:o,currentNode:r}=f(),i=b(r.id)[o];if(!i)return c("Invalid assign target");let s=Te(i.id,"TICKET");if(x(s))return c("Unable to assign issue in this context");let a=s.data,d=Bi(n),l;if(d)l=d.id;else{let C=O(),h=U({id:O(),userId:q(),action:"create.contributor",payload:{id:C,name:n}});if(x(h))return h;l=h.data.result.id}let v=g.getFieldByTitle(a.id,"Assignees");return v?b(v.id).some(C=>C.props?.value===l)?c("Assignee already assigned"):U({id:O(),userId:q(),action:"assign.issue",payload:{id:O(),target:a.id,contributor:l}}):c("Unable to locate assignees field")},onSuccess:()=>M({mode:u.DEFAULT})}];var Oo=(...e)=>{let{commandMeta:{command:t,validity:n,modifier:o,inputString:r}}=re();if(!t)return;let i=Bo(t);if(xo(),n===Q.Invalid)return;let s=Ro.find(d=>d.intent===i);if(!s)return Jt({result:Z.Fail,message:"Command not found",data:null});let a=s.action(s,{command:t,inputString:r,modifier:o});if(x(a))return Jt(a);vo(),s?.onSuccess?.()};var Uo=[{intent:"viewHelp",mode:u.DEFAULT,action:()=>(M({mode:u.HELP}),m("Viewing help",null))},{intent:"exit",mode:u.HELP,action:()=>(M({mode:u.DEFAULT}),m("Exiting help",null))},{intent:"confirm",mode:u.COMMAND_LINE,action:(...e)=>(Oo(...e),m("Executing command",null))},{intent:"MoveCursorLeft",mode:u.COMMAND_LINE,action:()=>(Yt(-1),m("Moving cursor left",null))},{intent:"MoveCursorRight",mode:u.COMMAND_LINE,action:()=>(Yt(1),m("Moving cursor right",null))},{intent:"MoveCursorLeftOfWord",mode:u.COMMAND_LINE,action:()=>(Qt("left"),m("Moving cursor left of word",null))},{intent:"MoveCursorRightOfWord",mode:u.COMMAND_LINE,action:()=>(Qt("right"),m("Moving cursor right of word",null))},{intent:"exitCommandLine",mode:u.COMMAND_LINE,action:()=>(M({mode:u.DEFAULT}),m("Exiting command line",null))},{intent:"autoCompleteCommand",mode:u.COMMAND_LINE,action:()=>(fe((e,{remainder:t})=>t?e+t:e),m("Auto-completing command",null))},{intent:"captureInput",mode:u.COMMAND_LINE,action:(e,{sequence:t})=>(fe(n=>n+t),m("Capturing input",null))},{intent:"eraseInput",mode:u.COMMAND_LINE,action:()=>(fo(),m("Erasing input",null))},{intent:"EraseInputWord",mode:u.COMMAND_LINE,action:()=>(go(),m("Erasing input word",null))},{intent:"getLastCommandFromHistory",mode:u.COMMAND_LINE,action:()=>(Co(),m("Getting last command from history",null))},{intent:"getNextCommandFromHistory",mode:u.COMMAND_LINE,action:()=>(yo(),m("Getting next command from history",null))}];import ki from"chalk";var Ge={bg:"#1a1b26",fg:"#c0caf5",grayDark:"#2f344d",gray:"#4c567a",grayLight:"#7f8bb3",cyan:"#7dcfff",cyanSoft:"#89ddff",blue:"#7aa2f7",magenta:"#9d7cd8",magentaSoft:"#a890e8",green:"#9ece6a",yellow:"#e0af68",red:"#f7768e",white:"#ffffff"},y={accent:Ge.cyan,accent2:Ge.magenta,primary:Ge.white,secondary:Ge.grayDark,secondary2:Ge.grayLight};var yt=": for command line",Wo="q to exit",Ho=`${ki.hex(y.accent)("m")} to confirm`,rn={[T.WORKSPACE]:[yt],[T.BOARD]:[yt],[T.BOARD+u.COMMAND_LINE]:[yt],[T.SWIMLANE]:[yt],[T.TICKET+u.HELP]:[Wo],[T.SWIMLANE+u.HELP]:[Wo],[T.TICKET]:[],[T.FIELD]:[],[T.SWIMLANE+u.MOVE]:[Ho],[T.TICKET+u.MOVE]:[Ho]};var Nt=e=>e.trim().toLocaleLowerCase(),Ri=(e,t)=>{let n=g.getFieldByTitle(e,t);if(!n)return"";let o=n.props?.value;return typeof o=="string"?o:""},Oi=e=>{let{tags:t}=f(),n=g.getFieldByTitle(e,"Tags");return n?P(n.id).map(o=>{let r=o.props?.value;return typeof r=="string"?t[r]?.name:void 0}).filter(o=>!!o):[]},Ui=e=>{let{contributors:t}=f(),n=g.getFieldByTitle(e,"Assignees");return n?P(n.id).map(o=>{let r=o.props?.value;return typeof r=="string"?t[r]?.name:void 0}).filter(o=>!!o):[]},_o=(e,t)=>{let n=t.value;if(!n)return!0;switch(t.target){case"title":return Nt(e.title??"").includes(n);case"description":return Nt(Ri(e.id,"Description")).includes(n);case"tag":return Oi(e.id).map(Nt).some(a=>a.includes(n));case"assignee":return Ui(e.id).map(Nt).some(a=>a.includes(n));default:return!0}};function Vo(e,t,n){let o=t[e];if(!o)return c("buildBreadCrumb(): current node not found");let r=[],i=o;for(;i&&(r.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let s=r[r.length-1];return!s||s.id!==n?c("buildBreadCrumb(): node is not connected to root"):(r.reverse(),m("Breadcrumb built",r))}var Ko=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 ht,sn=new Set,$o=()=>{for(let e of sn)e()},Hi=e=>(sn.add(e),()=>sn.delete(e));function zo(e){let{currentNodeId:t,mode:n,rootNodeId:o,nodes:r,filters:i}=e;if(!t)return c("derive(): currentNodeId is missing");if(!o)return c("derive(): rootNode is missing");if(!r[o])return c("derive(): unable to find root node");let a=r[t];if(!a)return logger.error("Unable to derive state, currentNode not found"),c("Unable to derive state, currentNode not found");let d=Vo(t,r,o);if(x(d))return logger.error(d.message),d;let l=d.data,{context:v}=a,p=rn[v+n]??rn[v]??[],C=[...Fo,...bo[v]??[],...Uo],h=Ko(C);return m("Derived successfully",{...e,currentNode:a,breadCrumb:l,availableHints:p,availableActions:C,actionIndex:h,renderedChildrenIndex:_i(r,i)})}var f=()=>(ht||logger.error("State not initialized. Call initWorkspaceState() first.",new Error().stack),ht);function Un(e){let t={filters:[],tags:{},contributors:{},viewMode:"dense",mode:u.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,currentNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1},n=zo(t);return x(n)?n:(ht=n.data,$o(),m("State initialized",null))}function j(e){let t=f(),n=e(t),o=zo(n);return x(o)?c(o.message??"Unable to update state"):(ht=o.data,$o(),m("State updated",null))}var M=e=>j(t=>({...t,...e}));var k=()=>Wi(Hi,f,f),_i=(e,t)=>{let n={};for(let o of Object.values(e))he(o)&&t.length>0&&!t.every(r=>_o(o,r))||!o.parentNodeId||o.isDeleted||((!o.parentNodeId||!n[o.parentNodeId])&&(n[o.parentNodeId]=[]),n[o.parentNodeId].push(o));for(let o of Object.keys(n))n[o].sort((r,i)=>{let s=e[r.id],a=e[i.id];return!s||!a?0:s.rank.localeCompare(a.rank)});return n},b=e=>f().renderedChildrenIndex[e]??[];import{Box as It,Text as an}from"ink";import ge from"react";import{Text as jo}from"ink";import Go,{useEffect as Vi,useState as Ki}from"react";var qo={help:["\u25B8 ","\u25B8 ","\u25B8 "],default:["\u25B8 ","\u25B8 ","\u25B8 "],move:["\u2191 ","\u2192 ","\u2193 ","\u2190 "],"command-line":["\u276F ","\u276F ","\u276F "]},_=({isSelected:e,placeholder:t=" "})=>{let{mode:n}=k(),o=qo[n]??qo.default,[r,i]=Ki(o.length-1);return Vi(()=>{if(!e)return;let s=setInterval(()=>{i(a=>(a+1)%o.length)},800);return()=>clearInterval(s)},[e,o]),e?Go.createElement(jo,{color:y.accent,dimColor:r===1},o[r]):Go.createElement(jo,null,t)};function dn(){let e=k(),t=e.nodes[e.rootNodeId],r=process.stdout.rows-1-3,i=process.stdout.columns||120,s=t?.id?b(t?.id):[];return ge.createElement(It,{flexDirection:"column",height:r,padding:1,borderStyle:"round",borderColor:y.secondary,width:i},ge.createElement(It,{padding:1,paddingTop:0,paddingBottom:0},ge.createElement(an,null,"Select a board:")),ge.createElement(It,{padding:1,flexDirection:"column"},s.map((a,d)=>{let l=e.currentNode.context==="WORKSPACE"&&e.selectedIndex===d,p=b(a.id).flatMap(({id:C})=>P(C)).length;return ge.createElement(It,{key:a.id??d},ge.createElement(an,{color:l?y.accent:y.secondary},ge.createElement(_,{isSelected:l})),ge.createElement(an,{color:l?y.accent:y.secondary},a.title," (",p," issues)",a.readonly?" \u{1F512}":""))})))}import{Box as xs}from"ink";import Tt from"react";import{Box as mn,Text as ts}from"ink";import Y from"react";import{Box as ln,Text as $i}from"ink";import Et from"react";var At=({children:e=[],height:t,selectedIndex:n,itemHeight:o=1,scrollByOne:r=!1})=>{if(e.length===0)return null;let i=Math.max(1,Math.floor(t)),s=Math.max(1,Math.ceil(o)),a=Math.max(1,Math.floor(i/s)),d=Math.max(0,Math.min(n,e.length-1)),l=Math.max(0,e.length-a),v=r?Math.min(l,Math.max(0,d-a+1)):Math.min(l,Math.floor(d/a)*a),p=v+a,C=e.slice(v,p),h=e.length>a,A=i,E=h?Math.max(1,Math.floor(a/e.length*A)):A,I=Math.max(0,A-E),S=Math.max(1,e.length-a),z=h?Math.floor(v/S*I):0;return Et.createElement(ln,{flexDirection:"row",height:i,width:"100%"},Et.createElement(ln,{flexDirection:"column",flexGrow:1,height:i},C),Et.createElement(ln,{flexDirection:"column",width:1,height:A},Array.from({length:A}).map((_e,me)=>Et.createElement($i,{key:me,color:h&&me>=z&&me<z+E?y.accent:y.secondary},h?"\u2502":" "))))};import{Box as bt,Text as Qi}from"ink";import Ee from"react";import{Text as zi}from"ink";import ji from"react";var Gi=e=>e.toLowerCase().trim(),qi=(e,t=Le)=>{let n=Gi(e);return t[n]?t[n]:De(n)},ke=({id:e,isSelected:t})=>{let n=g.getContributor(e);if(n)return ji.createElement(zi,{underline:t,color:qi(n.name)},"@"+n.name)};import{Text as Xi}from"ink";import Ji from"react";var Yi=e=>e.toLowerCase().trim(),qe=(e,t=Le)=>{let n=Yi(e);return t[n]?t[n]:De(n)},Re=({id:e,isSelected:t})=>{let n=g.getTag(e);if(n)return Ji.createElement(Xi,{underline:t,backgroundColor:qe(n.name),color:y.primary}," "+n.name+" ")};var Xo=({width:e,ticket:t,isSelected:n})=>{let o=e-14,r=rt(it(t.title),o),i=b(t.id),s=l=>{let v=i.find(p=>p.title===l);return v?b(v.id).map(p=>typeof p.props?.value=="string"?p.props.value:"").filter(p=>!!p):[]},a=s("Tags").map(l=>g.getTag(l)).filter(l=>!!l),d=s("Assignees").map(l=>g.getContributor(l)).filter(l=>!!l);return Ee.createElement(bt,{borderStyle:"round",width:e-7,height:4,flexDirection:"column",borderColor:n?y.accent:y.secondary,justifyContent:"space-between"},Ee.createElement(bt,{borderBottom:!0},Ee.createElement(bt,{paddingLeft:1,flexDirection:"column"},Ee.createElement(Qi,{color:y.primary},r))),Ee.createElement(bt,{flexDirection:"row",paddingLeft:1},a.map(l=>Ee.createElement(Re,{key:l.id,id:l.id})),d.map(l=>Ee.createElement(ke,{key:l.id,id:l.id}))))};import Zi from"chalk";import{Box as Xe,Text as cn}from"ink";import ie from"react";var es=(e,t)=>e.length>=t?e.slice(0,t)+"...":e,Jo=({width:e,ticket:t,isSelected:n,index:o,mode:r})=>{let i=b(t.id),s=E=>{let I=i.find(S=>S.title===E);return I?b(I.id).map(S=>typeof S.props?.value=="string"?S.props.value:"").filter(S=>!!S):[]},a=s("Tags").map(E=>g.getTag(E)).filter(E=>!!E),d=s("Assignees").map(E=>g.getContributor(E)).filter(E=>!!E),l=1,v=a.length*(1+l),p=d.length*(2+l),C=a.map(E=>ie.createElement(Xe,{key:E.id,paddingRight:l},ie.createElement(cn,{color:qe(E.name)},"\u25A0"))),h=d.map(E=>ie.createElement(Xe,{key:E.id,paddingRight:l},ie.createElement(cn,{color:De(E.name)},"@"+E.name.at(0)))),A=n?y.accent:r===u.MOVE?y.secondary:y.primary;return ie.createElement(Xe,{borderBottom:!0,justifyContent:"space-between"},ie.createElement(Xe,null,ie.createElement(_,{isSelected:n,placeholder:Zi.dim.gray(o+1+" ")}),ie.createElement(cn,{wrap:"truncate",color:A},es(t.title,e-v-p-14),"v")),ie.createElement(Xe,null,C,h))};var ns=({swimlane:e,isSelected:t,width:n,height:o,isDense:r,isFocused:i,listSelectedIndex:s,mode:a})=>{let{renderedChildrenIndex:d}=k(),l=d[e.id]??[],v=`${e.title} (${l.length})`,p=3,C=r?1:4,h=o-p-(r?2:1),A=Y.createElement(mn,{borderStyle:"round",borderColor:y.secondary,justifyContent:"flex-start",borderLeft:!1,borderTop:!1,borderRight:!1},Y.createElement(_,{isSelected:t}),Y.createElement(ts,{bold:!0,color:t?y.accent:y.primary},v," ",e.readonly?"\u{1F512}":"")),E=(I,S)=>{let z=i&&s===S;return r?Y.createElement(Jo,{key:I.id,index:S,width:n,ticket:I,isSelected:z,mode:a}):Y.createElement(Xo,{key:I.id,width:n,ticket:I,isSelected:z})};return Y.createElement(mn,{flexDirection:"column",width:n,borderStyle:"round",borderColor:t?y.accent:y.secondary,paddingRight:1,paddingLeft:1,height:o},A,Y.createElement(mn,{padding:r?1:0},l.length>0&&Y.createElement(At,{selectedIndex:s,height:h,itemHeight:C},l.map(E)),Y.createElement(_,{isSelected:i&&s===-1})))},Yo=Y.memo(ns);import{Box as fn,Text as fs}from"ink";import xe,{useEffect as gn,useMemo as ir}from"react";import Oe from"chalk";import Zo from"string-width";import{decodeTime as os}from"ulid";var Qo=e=>{let t=Date.now()-e,n=[{label:"y",ms:1e3*60*60*24*365},{label:"mo",ms:1e3*60*60*24*30},{label:"w",ms:1e3*60*60*24*7},{label:"d",ms:1e3*60*60*24},{label:"h",ms:1e3*60*60},{label:"m",ms:1e3*60},{label:"s",ms:1e3}];for(let{label:o,ms:r}of n){let i=Math.floor(t/r);if(i>=1)return`${i}${o} ago`}return"just now"};var rs=(e,t)=>e+" ".repeat(Math.max(0,t-Zo(e))),is=(e,t)=>" ".repeat(Math.max(0,t-Zo(e)))+e,ss=e=>(()=>{let n={"add.issue":"Created with title","assign.issue":"Assigned to","close.issue":"Closed","delete.node":"Deleted","edit.title":"Changed title to","edit.description":"Changed description","reopen.issue":"Reopened","tag.issue":"Tagged with","lock.node":"Locked node","move.node":"Moved issue to"};return(r=>n[r]??(r.endsWith("e")?`${r}d`:`${r}ed`))(e)})(),as=e=>{switch(e.action){case"move.node":{let t=g.getNode(e.payload.parent);return t?`${Oe.bgBlack(` ${t.title} `)}`:"to unknown"}case"tag.issue":{let t=f().tags[e.payload.tagId];return t?Oe.bgHex(qe(t.name))(` ${t.name} `):"unknown tag"}case"assign.issue":{let t=f().contributors[e.payload.contributor];return t?Oe.bgBlack(` ${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""}},ds=e=>{let t=Qo(os(e));return Oe.gray(is(t,8))},ls=12,cs=e=>Oe.dim(rs(`${e}`,ls)),er=e=>{let t=ds(e.id),n=cs(e.userId),o=ss(e.action),r=as(e),i=Oe.dim("\u203A"),s=[o,r].filter(Boolean).join(" ");return`${n} ${t} ${i} ${s}`};import{Box as St,Text as ms}from"ink";import se from"react";var tr=({selectedIndex:e,parent:t,selected:n})=>{let{currentNode:o}=k(),{title:r}=t,i=b(t.id).map(s=>{let a=typeof s.props?.value=="string"?s.props.value:"";if(r==="Assignees")return g.getContributor(a)?.id;if(r==="Tags")return g.getTag(a)?.id}).filter(s=>!!s);return se.createElement(St,{alignItems:"center",paddingTop:1},se.createElement(St,{minWidth:12},se.createElement(_,{isSelected:n}),se.createElement(ms,{color:n?y.accent:y.secondary},r,":")),se.createElement(St,{flexDirection:"row",marginLeft:1,paddingRight:1},i.map((s,a)=>{let d=o.id===t.id&&a===e;return se.createElement(St,{key:`${r}-${s}`,paddingRight:2,minHeight:1},se.createElement(_,{isSelected:d}),r==="Assignees"?se.createElement(ke,{isSelected:d,id:s}):r==="Tags"?se.createElement(Re,{isSelected:d,id:s}):null)})))};import nr from"chalk";import{Box as un,Text as or}from"ink";import{marked as rr}from"marked";import us from"marked-terminal";import Ae,{useEffect as ps}from"react";var pn=({id:e,text:t,height:n,selected:o,maxWidth:r})=>{let{selectedIndex:i,currentNode:s}=k();rr.setOptions({renderer:new us});let a=p=>String(rr.parseInline(p)).replace(/\r?\n/g,""),d=typeof t=="string"?t.split(/\r?\n|\u2028|\u2029/):[];ps(()=>{let p=[];return d.forEach((C,h)=>{let A=H.text(`${h}`,`Line ${h+1}`,e,{value:C}),E=g.createNodeAtPosition(A);ue(E)&&p.push(E.data.id)}),()=>p.forEach(g.deleteNode)},[e,t]);let l="\u2029",v=d.map((p,C)=>Ae.createElement(or,{key:`${e}-${C}`},(s.id===e&&i===C?nr.cyan(`\u25B8 ${Array.from({length:String(C).length}).map(()=>" ").join("")}`):nr.dim.gray(`${C+1} `))+a(p.length?rt(p,r-10):l)));return Ae.createElement(un,{flexDirection:"column",paddingTop:1},Ae.createElement(un,null,Ae.createElement(_,{isSelected:o}),Ae.createElement(or,{color:o?y.accent:y.secondary},"Inline Editor (press e to edit)")),Ae.createElement(un,{flexDirection:"row",borderStyle:"round",borderColor:y.secondary,paddingLeft:1,paddingRight:1,marginLeft:1},Ae.createElement(At,{scrollByOne:!0,children:v,height:n-2,selectedIndex:i,itemHeight:1})))};var gs=e=>`${e}::log`,sr=({ticket:e,height:t})=>{let{selectedIndex:n,currentNode:o}=k(),r=process.stdout.columns||120,i=ir(()=>gs(e.id),[e.id]),s=ir(()=>[...e.log].reverse().map(er).join(`
10
- `),[e.log]);gn(()=>{if(g.getNode(i))return;let S={...H.field(i,"Log",e.id,{value:s}),readonly:!0,childRenderAxis:"vertical"};return g.createNodeAtPosition(S),()=>{g.deleteNode(i)}},[i,e.id]),gn(()=>{let I=g.getNode(i);I&&I.props.value!==s&&g.updateNode({...I,props:{...I.props,value:s},childRenderAxis:"vertical",readonly:!0})},[i,s]);let a=o.id===e.id,d=o.id===i||o.parentNodeId===i;gn(()=>{d&&(n>=0||D.navigate({selectedIndex:0}))},[d,n]);let l=b(e.id);if(d){let I=g.getNode(i),z=t-3;return xe.createElement(fn,{width:r,flexDirection:"column",paddingRight:1,paddingBottom:1,minHeight:t},I?xe.createElement(pn,{id:I.id,text:I.props.value??"",selected:!1,maxWidth:r,height:z}):null)}let v=l.reduce((I,S)=>S.title==="Assignees"||S.title==="Tags"||S.id===i?++I:I,0),p=2,C=v*1,A=t-3-C-p,E=(I,S)=>I.title==="Assignees"||I.title==="Tags"?xe.createElement(tr,{key:I.id,parent:I,selected:S,selectedIndex:n}):I.id===i?xe.createElement(fn,{key:I.id,paddingTop:1},xe.createElement(_,{isSelected:S}),xe.createElement(fs,{backgroundColor:y.secondary,color:S?y.accent:y.primary}," History \u203A\u203A ")):xe.createElement(pn,{key:I.id,id:I.id,text:I.props.value??"",selected:S,maxWidth:r,height:A});return xe.createElement(fn,{width:r,flexDirection:"column",paddingRight:1,paddingBottom:1,minHeight:t},l.map((I,S)=>E(I,a&&n===S)))};var vs=({swimlanes:e,currentNode:t,selectedIndex:n,breadCrumb:o,mode:r,viewMode:i,height:s,width:a})=>{let d=t.context,l=d===T.TICKET||d===T.FIELD_LIST||d===T.FIELD,v=d===T.BOARD||d===T.SWIMLANE,p=d===T.TICKET?t:o.find(I=>I.context===T.TICKET),C=Math.floor(a/3),h=Math.floor(a/Math.max(e.length,1)),A=Math.min(h,C),E=i==="dense";return Tt.createElement(xs,{flexDirection:"row",height:s},v&&e.map((I,S)=>{let z=t.id===I.id,_e=z?n:-1,me=t.context===T.BOARD&&n===S;return Tt.createElement(Yo,{key:I.id,height:s,width:A,swimlane:I,isSelected:me,isDense:E,isFocused:z,listSelectedIndex:_e,mode:r})}),l&&p&&Tt.createElement(sr,{height:s,ticket:p}))},ar=Tt.memo(vs);var Ns=({currentNode:e,selectedIndex:t,breadCrumb:n,mode:o,viewMode:r,height:i,width:s})=>{let{renderedChildrenIndex:a}=k(),d=n.find(({context:C})=>C==="BOARD"),p=i-1-3;return Je.createElement(Cs,{flexDirection:"row"},e.context==="WORKSPACE"?Je.createElement(dn,null):d?Je.createElement(ar,{height:p,width:s,swimlanes:(a[d.id]??[]).filter(C=>C!==void 0&&Pn(C)),currentNode:e,selectedIndex:t,breadCrumb:n,viewMode:r,mode:o}):Je.createElement(ys,null))},dr=Je.memo(Ns);import{Box as Cn,Text as fr}from"ink";import Ue from"react";import vn from"chalk";import{Box as xn,Text as lr}from"ink";import Ye,{useEffect as hs,useMemo as Is,useState as Es}from"react";var cr=vn.gray,As=vn.inverse,bs=vn.inverse.gray,Ss={hint:"",hints:[],overlap:0,remainder:""},ur=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),r=e.length-n.length;return e.slice(r,r+t.length)!==t?null:{start:r,end:r+t.length}},Ts=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let o=ur({value:e,command:t});if(!o)return null;let i=e.slice(o.end).match(/^\s*/)?.[0].length??0,s=o.end+i;return e.slice(s,s+n.length)!==n?null:{start:s,end:s+n.length}},mr=()=>({value:R.value,cursorPosition:R.cursorPosition,commandIsPending:R.commandIsPending,autoCompletion:R.commandMeta.autoCompletion??Ss,infoMessage:R.commandMeta.infoMessage,validationStatus:R.commandMeta.validity,command:R.commandMeta.command,inputString:R.commandMeta.inputString,modifier:R.commandMeta.modifier}),Ms=(e,t)=>e.value===t.value&&e.cursorPosition===t.cursorPosition&&e.commandIsPending===t.commandIsPending&&e.infoMessage===t.infoMessage&&e.autoCompletion.hint===t.autoCompletion.hint&&e.autoCompletion.overlap===t.autoCompletion.overlap&&e.autoCompletion.remainder===t.autoCompletion.remainder&&e.validationStatus===t.validationStatus&&e.command===t.command&&e.modifier===t.modifier&&e.inputString===t.inputString,pr=({width:e})=>{let[t,n]=Es(mr());hs(()=>{let p=()=>{let h=mr();n(A=>Ms(A,h)?A:h)},C=po(p);return p(),()=>{C()}},[]);let{value:o,cursorPosition:r,infoMessage:i,commandIsPending:s,autoCompletion:a,command:d,modifier:l}=t,v=Is(()=>{let p=Math.max(0,Math.min(r,o.length)),C=ur({value:o,command:d}),h=Ts({value:o,command:d,modifier:l}),A=d?jt(d):null,E=l?jt(l):null,I=(V,K)=>{let Rt=C&&K>=C.start&&K<C.end,Ot=h&&K>=h.start&&K<h.end;return Rt&&A?A.fg(V):Ot&&E?E.bg(V):V},S=(V,K)=>{let Rt=C&&K>=C.start&&K<C.end,Ot=h&&K>=h.start&&K<h.end;return Rt&&A?A.fgCursor(V):Ot&&E?E.bgCursor(V):As(V)},z=o.slice(0,p),_e=o[p]??" ",me=p<o.length?o.slice(p+1):"",Tr=Array.from(z).map((V,K)=>I(V,K)).join(""),bn=S(_e,p),Sn=Array.from(me).map((V,K)=>I(V,p+1+K)).join("");if(a.hint){let V=a.hint[a.overlap]??_e;bn=bs(V),Sn=cr(a.remainder.slice(1)+me)}return cr(":")+Tr+bn+Sn},[o,r,a,d,l]);return Ye.createElement(xn,{flexDirection:"column",justifyContent:"flex-start"},Ye.createElement(xn,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},Ye.createElement(xn,null,Ye.createElement(lr,null,v),i&&Ye.createElement(lr,{wrap:"truncate",color:s?"red":y.secondary},` ${i} `))))};var yn=({width:e,mode:t,availableHints:n})=>{let o=[],r=0;for(let i of n){let a=(o.length>0?" | ":"").length+i.length;if(r+a>e+2)break;o.push(i),r+=a}return Ue.createElement(Cn,null,t===u.COMMAND_LINE?Ue.createElement(pr,{width:e}):Ue.createElement(Cn,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},Ue.createElement(Cn,{flexDirection:"row"},o.map((i,s)=>Ue.createElement(fr,{key:i,color:y.secondary},(s>0?" | ":"")+i)),Ue.createElement(fr,null," "))))};import{Box as We,Text as gr}from"ink";import ve from"react";var xr=({width:e})=>{let t=[...f().availableActions].map(n=>n.description).filter(n=>n!==void 0).map(n=>{let[o,r]=n.split("]"),i=o?.replace("[",""),s=r?.trim();return[i,s]}).filter(n=>n[0]!==void 0&&n[1]!==void 0).sort(([n],[o])=>n.length===1&&o.length!==1?-1:n.length!==1&&o.length===1?1:n.localeCompare(o,void 0,{sensitivity:"base"}));return t.unshift(["Key(s)","Action"]),ve.createElement(We,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,minHeight:19},ve.createElement(We,{flexDirection:"column",width:e},f().mode===u.HELP?t.map(([n,o],r)=>ve.createElement(We,{paddingLeft:1,key:r,flexDirection:"row"},ve.createElement(We,{key:r,flexDirection:"row",paddingBottom:r?0:1},ve.createElement(We,{width:20,justifyContent:"flex-end"},ve.createElement(gr,{color:r?y.accent:y.secondary},n)),ve.createElement(We,{flexGrow:1,width:40,paddingLeft:2},ve.createElement(gr,{color:r?y.primary:y.secondary},o))))):null))};import{Box as He,Text as Ce}from"ink";import F from"react";var Mt=({isDone:e,command:t,value:n})=>F.createElement(He,null,F.createElement(Ce,{color:y.accent,dimColor:e},e?" \u2714 ":" "),F.createElement(Ce,{dimColor:e},"Type "),F.createElement(Ce,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n&&F.createElement(F.Fragment,null,F.createElement(Ce,{dimColor:e}," "),F.createElement(Ce,{color:y.secondary,dimColor:e},"<"+n+">")));function Nn({width:e,height:t,hasUserName:n,hasPreferredEditor:o,userName:r,preferredEditor:i}){let s=n&&o,a=n?o?null:":set:editor":":set:username";return F.createElement(He,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},F.createElement(Ce,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),!s&&F.createElement(Ce,{dimColor:!0},a===":set:username"?"First, choose your username.":"Nice. One more step."),F.createElement(He,{flexDirection:"column"},n&&F.createElement(He,{marginBottom:1},F.createElement(Mt,{isDone:!0,command:":set:username",value:r})),!n&&F.createElement(Mt,{isDone:!1,command:":set:username"}),n&&!o&&F.createElement(Mt,{isDone:!1,command:":set:editor"}),s&&F.createElement(He,null,F.createElement(Mt,{isDone:!0,command:":set:editor",value:i}))),F.createElement(He,{marginTop:1,flexDirection:"column"},s&&F.createElement(Ce,{color:"green"},"You are ready to go.")))}import Nr from"chalk";import{Box as In,Text as Ir}from"ink";import de from"react";import{Box as wt,Text as hn}from"ink";import ae from"react";var vr=()=>{let{breadCrumb:e,currentNode:t,selectedIndex:n,viewMode:o}=f(),r=P(t.id)[n],i=Te(r?.id??t.id,"TICKET"),s=ue(i)?i.data:void 0,a=s?.id?P(s.id):[],d=C=>{let h=a.find(A=>A.title===C);return h?P(h.id).map(A=>typeof A.props?.value=="string"?A.props.value:"").filter(A=>!!A):[]},l=d("Tags"),v=d("Assignees"),p=s?.parentNodeId?!_t(t.id,s?.parentNodeId)&&o==="dense":!1;return ae.createElement(wt,null,e.map((C,h)=>{let A=h===e.length-1,E=P(C.id),I=A?E?.[n]?.title:void 0;return ae.createElement(wt,{key:`${C.id}-${h}`},ae.createElement(hn,{color:y.secondary2},h?" / ":""),ae.createElement(hn,{color:y.secondary2},C.title??""),I?ae.createElement(hn,{color:y.primary},` \u25B8 ${I}`):null,p&&A?l.map(S=>ae.createElement(wt,{key:S,paddingLeft:2},ae.createElement(Re,{id:S}))):null,p&&A?v.map(S=>ae.createElement(wt,{key:S,paddingLeft:2},ae.createElement(ke,{id:S}))):null)}))};import{Box as ws,Text as Cr}from"ink";import Lt from"react";var Ls=({filters:e})=>Lt.createElement(ws,{columnGap:1},Lt.createElement(Cr,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:o})=>Lt.createElement(Cr,{backgroundColor:"black",color:"white"},` ${n}${o}"${t}" `))),yr=Lt.memo(Ls);function En({filters:e,hideBreadCrumb:t=!1}){let{userName:n,preferredEditor:o}=pe();return de.createElement(In,{justifyContent:"space-between",flexDirection:"row"},t?de.createElement(Ir,null," "):de.createElement(In,{paddingLeft:1},e.length>0?de.createElement(yr,{filters:e}):de.createElement(vr,null)),de.createElement(In,{columnGap:1,paddingRight:2},de.createElement(hr,{icon:"@",value:n}),de.createElement(hr,{icon:"\u276F",value:o})))}function hr({icon:e,value:t}){return de.createElement(Ir,null,Nr.dim(e)+Nr.hex(y.accent2)(` ${t??"-"} `))}function Qe({width:e,height:t}){let n=k(),o=pe(),r=!!o.userName?.trim(),i=!!o.preferredEditor?.trim(),s=r&&i,a=k().filters,d=!o.userName||!o.preferredEditor;if(!s)return X.createElement(Pt,{flexDirection:"column"},X.createElement(Pt,{flexDirection:"column"},X.createElement(En,{hideBreadCrumb:d,filters:a}),X.createElement(Nn,{height:t,width:e,hasUserName:r,hasPreferredEditor:i,userName:o.userName??"",preferredEditor:o.preferredEditor??""})),X.createElement(yn,{width:e,mode:n.mode,availableHints:n.availableHints}));let l=Ie(f().breadCrumb??[],"BOARD");if(ue(l)){let v=l.data.id,p=b(v).length,C=3,h=Math.floor(e/C),A=Math.floor(e/Math.max(p,1));e=Math.min(A,h)*Math.max(p,C)}return X.createElement(Pt,{flexDirection:"column"},n.mode!==u.HELP&&X.createElement(Pt,{flexDirection:"column"},X.createElement(En,{filters:a}),X.createElement(dr,{width:e,height:t,currentNode:n.currentNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:n.viewMode,mode:n.mode})),n.mode===u.HELP&&X.createElement(xr,{width:e}),n.mode!==u.HELP&&X.createElement(yn,{width:e,mode:n.mode,availableHints:n.availableHints}))}import{Box as be,Text as ye}from"ink";import W,{useEffect as Ps,useMemo as Ds,useState as Fs}from"react";var Bs=["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557","\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551","\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551\u2584\u2584 \u2588\u2588\u2551","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D","\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2580\u2580\u255D "];function ks(e,t,n){return Math.min(n,Math.max(t,e))}function Rs(e,t){return W.createElement(ye,null,W.createElement(ye,{color:t%2===0?"cyan":"blue",bold:!0},e.slice(0,14)),W.createElement(ye,{color:t%2===0?"cyan":"blue",bold:!0},e.slice(14)))}function Os(e,t=28){if(e>=1)return"\u2588".repeat(t);let n=Math.floor(e*(t-1));return Array.from({length:t},(o,r)=>{let i=Math.abs(r-n);return i===0?"\u2588":i===1?"\u2593":i===2?"\u2592":i===3?"\u2591":r<n?"\u2500":"\xB7"}).join("")}function Dt({durationMs:e=3e3,slogan:t="Never leave the command line"}){let n=Math.max(1,e),[o,r]=Fs(0);Ps(()=>{let d=Date.now(),l=setInterval(()=>{let v=Date.now()-d;if(v>=n){r(n),clearInterval(l);return}r(v)},33);return()=>clearInterval(l)},[n]);let i=ks(o/n,0,1),s=Ds(()=>Os(i,28),[i]),a=`${Math.round(i*100)}%`;return W.createElement(be,{flexDirection:"column",alignItems:"center",justifyContent:"center",paddingX:4,paddingY:1},W.createElement(be,{flexDirection:"column",minWidth:42},W.createElement(be,{flexDirection:"column",marginBottom:1},Bs.map((d,l)=>W.createElement(be,{key:l,justifyContent:"center"},Rs(d,l)))),W.createElement(be,{justifyContent:"center",marginBottom:1},W.createElement(ye,{color:"gray"},t)),W.createElement(be,{justifyContent:"center",marginBottom:1},W.createElement(ye,{color:"cyan"},s.slice(0,10)),W.createElement(ye,{color:"blue"},s.slice(10,18)),W.createElement(ye,{color:"magenta"},s.slice(18))),W.createElement(be,{justifyContent:"center",marginBottom:1},W.createElement(ye,{color:"gray"},a))))}import Us from"readline";var Ft,Ws=()=>async function(t,n){if(n.ctrl&&n.name==="c")return D.exit();let{actionIndex:o,mode:r}=f(),i=No(n,r);if(!i)return;let s=o[r]?.[i];if(s?.action)try{await s.action(s,n)}catch(a){logger.error(a)}};function Er(){Ft&&process.stdin.removeListener("keypress",Ft),Ft=Ws(),Us.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("keypress",Ft)}import An from"chalk";import{monotonicFactory as Hs,ulid as le}from"ulid";var ce="system";function _s(){let e=Object.values(f().nodes).find(o=>o.context==="WORKSPACE");if(!e)throw new Error("No workspace found in event log");let[t]=b(e.id),[n]=t?b(t.id):[];return n??t??e}function Vs(){let e=_s(),t=f().renderedChildrenIndex?.[e.id]??[];D.navigate({currentNode:e,selectedIndex:t.length>0?0:-1})}var Ze=Hs();function Ks(){let e=Ze(),t=Ze(),n=Ze(),o=Ze(),r=Ze();return[{id:le(),userId:ce,action:"init.workspace",payload:{id:e,name:"Workspace"}},{id:le(),userId:ce,action:"add.board",payload:{id:t,name:"Default",parent:e}},{id:le(),userId:ce,action:"add.swimlane",payload:{id:n,name:"Todo",parent:t}},{id:le(),userId:ce,action:"add.swimlane",payload:{id:o,name:"Review",parent:t}},{id:le(),userId:ce,action:"add.swimlane",payload:{id:r,name:"Done",parent:t}},{id:le(),userId:ce,action:"add.board",payload:{id:st,name:"Closed",parent:e}},{id:le(),userId:ce,action:"add.swimlane",payload:{id:Me,name:"Closed",parent:st}},{id:le(),userId:ce,action:"lock.node",payload:{id:st}},{id:le(),userId:ce,action:"lock.node",payload:{id:Me}}]}function Ar(e){let n=(e.length===0?dt(Ks()):On(e)).filter(x);if(n.length>0)throw new Error([An.bold.red("Materializing failed"),"",...n.map((o,r)=>`${An.dim.gray(`${r+1}.`)} ${An.dim(o.message)}`),`
2
+ import{render as sa}from"ink";import aa from"meow";import Dr from"react";import $s from"chalk";import{Box as ee,Text as be}from"ink";import P from"react";import $e from"chalk";import{monotonicFactory as Xi,ulid as ce}from"ulid";import{useSyncExternalStore as ji}from"react";var M={WORKSPACE:"WORKSPACE",BOARD:"BOARD",SWIMLANE:"SWIMLANE",TICKET:"TICKET",FIELD:"FIELD",FIELD_LIST:"FIELD_LIST",TEXT:"TEXT"};function Ae(e){return e.context==="TICKET"}function On(e){return e.context==="FIELD_LIST"}var kn=e=>e.context==="SWIMLANE";var p={INIT:"init",HELP:"help",NEW:"new",TAG:"tag",FILTER:"filter",MOVE:"move",ASSIGN:"assign",DELETE:"delete",RENAME:"rename",CLOSE_ISSUE:"close",RE_OPEN_ISSUE:"reopen",SET_DESCRIPTION:"edit",SET_EDITOR:"set:editor",SET_VIEW:"set:view",SET_USERNAME:"set:username",NONE:""},ae={None:"none",Invalid:"invalid",Valid:"valid"},de={None:"none",Success:"success",Fail:"fail"},d=e=>({result:de.Fail,message:e,data:null}),m=(e,t)=>({result:de.Success,message:e,data:t}),Un=()=>({result:de.None,message:"No result",data:null}),f=e=>e.result==="fail",Pe=e=>e.result==="success";var u={DEFAULT:"default",MOVE:"move",HELP:"help",COMMAND_LINE:"command-line"};function at(e,t){let n=Math.min(e.length,t.length),o=0;for(;o<n&&e[o]===t[o];)o++;return o}var dt=(e,t)=>t<=0?"":e.length<=t?e:t<=3?"...".slice(0,t):e.slice(0,t-3)+"...",lt=e=>typeof e!="string"?"":e.replace(/[\x00-\x08\x0B-\x1F\x7F]/g,"").replace(/[\r\n\t]/g," ").replace(/\s+/g," ").trim();var Wn=e=>{let t=new Map;for(let n of e)for(let o=1;o<=n.length;o++){let r=n.slice(0,o),i=t.get(r);i?i.push(n):t.set(r,[n])}return t},_n=(e,t)=>t?e.get(t)??[]:[];var Hn=new WeakMap,Ur=e=>{let t=Hn.get(e);return t||(t=Wn(e),Hn.set(e,t)),t};var Vn=({wordList:e,inputToMatch:t,overlapThreshold:n=1})=>{let o=t.toLowerCase();return _n(Ur(e),o).filter(i=>at(o,i)>=n)};var Kn=({inputToMatch:e,lastWord:t},n)=>{if(t.endsWith(" "))return{hint:"",hints:[],overlap:0,remainder:""};let o=Vn({wordList:n,inputToMatch:e,overlapThreshold:1});return Wr(t,o)},Wr=(e,t)=>{let n=t[0]??"",o=at(e.toLowerCase(),n.toLowerCase()),r=n?n+" ":"",i=r.slice(o);return{hint:r,hints:t,overlap:o,remainder:i}};var $n=["vi","vim","nvim","nano","micro","emacs","hx","code","code-insiders","subl","notepad","notepad++","idea","webstorm","default","system","$EDITOR","$VISUAL"];var De=24n,_r=De*4n,ct=(1n<<_r)-1n,Hr=/^[0-9a-f]+$/;function zn(e){if(!e||!Hr.test(e))throw new Error(`Invalid hex rank: ${e}`);return BigInt("0x"+e)}function mt(e,t=De){if(e<0n)throw new Error("Negative rank not allowed");return e.toString(16).padStart(Number(t),"0")}function Je(e,t){if(!e&&!t)return mt(ct/2n,De);let n=e?zn(e):0n,o=t?zn(t):ct;if(o<=n)return mt(ct/2n,De);let r=(n+o)/2n;return r===n||r===o?"":mt(r,De)}function Q(){return mt(ct/2n,De)}var V={workspace:(e,t)=>({id:e,title:t,rank:Q(),isDeleted:!1,props:{},context:M.WORKSPACE,childRenderAxis:"vertical",parentNodeId:null,readonly:!0,log:[]}),board:(e,t,n,o=!1)=>({id:e,title:t,rank:Q(),isDeleted:!1,props:{},context:M.BOARD,childRenderAxis:"horizontal",parentNodeId:n,readonly:o,log:[]}),swimlane:(e,t,n)=>({id:e,title:t,rank:Q(),isDeleted:!1,props:{},context:M.SWIMLANE,childRenderAxis:"vertical",childNavigationAcrossParents:!0,parentNodeId:n,readonly:!1,log:[]}),field:(e,t,n,o={},r="horizontal")=>({id:e,title:t,rank:Q(),isDeleted:!1,props:o,context:M.FIELD,childRenderAxis:r,parentNodeId:n,readonly:!1,log:[]}),ticket:(e,t,n)=>({id:e,title:t,rank:Q(),isDeleted:!1,props:{},context:M.TICKET,childRenderAxis:"vertical",parentNodeId:n,readonly:!1,log:[]}),text:({id:e,name:t,parentNodeId:n,props:o={},readonly:r=!0})=>({id:e,title:t,rank:Q(),isDeleted:!1,props:o,context:M.TEXT,childRenderAxis:"vertical",parentNodeId:n,readonly:r,log:[]})};var F=e=>Object.values(v().nodes).filter(t=>!!t&&!t.isDeleted&&t.parentNodeId===e).sort((t,n)=>t.rank.localeCompare(n.rank)),jn=(e,t)=>e.findIndex(n=>n.id===t),qt=(e,t={at:"end"})=>{if(e.length===0)return m("Resolved rank",Q());switch(t.at){case"start":{let n=e[0];return n?m("Resolved rank",Je(void 0,n.rank)):d("Unable to resolve first sibling")}case"end":{let n=e[e.length-1];return n?m("Resolved rank",Je(n.rank,void 0)):d("Unable to resolve last sibling")}case"before":{let n=jn(e,t.sibling);if(n<0)return d("Sibling not found");let o=n>0?e[n-1]:void 0,r=e[n];return r?m("Resolved rank",Je(o?.rank,r.rank)):d("Sibling not found")}case"after":{let n=jn(e,t.sibling);if(n<0)return d("Sibling not found");let o=e[n],r=n<e.length-1?e[n+1]:void 0;return o?m("Resolved rank",Je(o.rank,r?.rank)):d("Sibling not found")}}};var Re=(e,t)=>{let{nodes:n}=v(),o=n[e];if(!o)return d("Node not found");if(o.context===t)return m("Resolved ancestor node",o);let r=o.parentNodeId?n[o.parentNodeId]:void 0;for(;r;){if(r.context===t)return m("Resolved ancestor node",r);r=r.parentNodeId?n[r.parentNodeId]:void 0}return d(`No ancestor found for context: ${t}`)},Xt=(e,t)=>{let{nodes:n}=v(),o=n[e];for(;o?.parentNodeId;){if(o.parentNodeId===t)return!0;o=n[o.parentNodeId]}return!1};function Vr(e){return lt(e).replace(/\s+/g," ").trim()}function qn(e,t){if(!e)return[];let n=[],o=new Set,r=v(),{renderedChildrenIndex:i,tags:s,contributors:a}=r,l=c=>{let g=i[c.id];if(c.title===t&&On(c))for(let x of g??[]){if(!x)continue;let N=typeof x.props?.value=="string"?x.props.value:"",h=(t==="Tags"?s[N]?.name:t==="Assignees"?a[N]?.name:void 0)??x.title??String(x.props?.value??""),I=Vr(h),E=I.toLowerCase();I&&!o.has(E)&&(o.add(E),n.push(I))}for(let x of g??[])l(x)};return l(e),n.sort((c,g)=>c.localeCompare(g))}var Gt=(e,t)=>e?e.readonly?d({move:"Cannot move readonly node",rename:"Cannot rename readonly node",edit:"Cannot edit readonly node"}[t]):null:d("Node not found"),C={deleteNode(e){J(t=>{let n={...t.nodes};return delete n[e],{...t,nodes:n}})},editValue(e,t){let{nodes:n}=v(),o=n[e];if(!o)return d("Edit target node not found");let r=Gt(o,"edit");if(r)return r;let i={...o,props:{...o.props,value:t}};return C.updateNode(i),m("Issue description updated",{md:t})},renameNode(e,t){let n=this.getNode(e);if(!n)return d("Rename target node not found");let o=Gt(n,"rename");if(o)return o;let r={...n,title:t};return this.updateNode(r),m("Renamed node",r)},getExistingTags(){let{rootNodeId:e,nodes:t}=v(),n=t[e];return n?qn(n,"Tags"):[]},getExistingAssignees(){let{rootNodeId:e,nodes:t}=v(),n=t[e];return n?qn(n,"Assignees"):[]},getFieldByTitle(e,t){return F(e).find(n=>n.title===t)},moveNode({id:e,parentId:t,position:n={at:"end"},navigate:o=!0}){let{rootNodeId:r}=v(),i=this.getNode(e),s=this.getNode(t);if(!i)return d("Node not found");if(!s)return d("Target parent not found");if(r===e)return d("Cannot move root node");if(e===t)return d("Cannot move node into itself");let a=Gt(i,"move");if(a)return a;if(Xt(t,e))return d("Cannot move node into its own descendant");let l=F(t).filter(x=>x.id!==e),c=qt(l,n);if(f(c))return c;let g={...i,parentNodeId:t,rank:c.data};return o?this.updateNodeAndSelectInParent(g):this.updateNode(g),m("Moved node successfully",g)},tombstoneNode(e){let{nodes:t,currentNodeId:n,rootNodeId:o}=v(),r=this.getNode(e);if(!r)return d("Node not found");if(o===e)return d("Cannot delete root node");let i=new Set,s=c=>{let g=t[c];if(!(!g||i.has(c))){i.add(c);for(let x of F(g.id))s(x.id)}};s(e);let a={...structuredClone(t)};for(let c of i){if(!a[c])return d("Unable to locate node to delete");a[c]={...a[c],isDeleted:!0}}if(!n)return d("Unable to delete undefined");let l=i.has(n)?r.parentNodeId??o:n;return b({nodes:a}),D.navigate({currentNode:a[l],selectedIndex:0}),m("Successfully tomb stoned",r)},createContributor(e){let t=J(n=>({...n,contributors:{...n.contributors,[e.id]:e}}));return f(t)?d("Unable to create contributor"):m("Created contributor",e)},assign(e,t,n){let o=C.getContributor(t),r=C.getNode(e);if(!r||!o)return d("Unable assign contributor to issue");let i=this.getFieldByTitle(r.id,"Assignees");if(!i)return d("Unable to locate assignees field");if(F(i.id).some(l=>l.props?.value===t))return d("Contributor already assigned");let a=this.createNodeAtPosition(V.field(n,o.name,i.id,{value:t}));return f(a)?a:m("Assigned contributor",a.data)},createTag(e){let t=J(n=>({...n,tags:{...n.tags,[e.id]:e}}));return f(t)?d("Could not create tag"):m("Tag created",e)},tag(e,t,n){let o=C.getTag(t),r=C.getNode(e);if(!o)return d("Unable to add tag, missing tag");if(!r)return d("Unable to add tag, missing target");let i=this.getFieldByTitle(r.id,"Tags");if(!i)return d("Unable to locate tags field");if(F(i.id).some(l=>l.props?.value===t))return d("Tag already assigned");let a=this.createNodeAtPosition(V.field(n,o.name,i.id,{value:t}));return f(a)?a:m("Tag added",a.data)},createNodeAtPosition(e,t={at:"end"}){if(!e.parentNodeId){let i={...e,rank:Q()};return this.createNode(i),m("Created node",i)}let n=F(e.parentNodeId),o=qt(n,t);if(f(o))return o;let r={...e,rank:o.data};return this.createNode(r),m("Created node",r)},createNode(e){let t=J(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return f(t)?m("Node created",e):d("Unable to create node")},lockNode(e){let t=this.getNode(e);if(!t)return d("Failed to locate node");let n={...t,readonly:!0},o=J(r=>({...r,nodes:{...r.nodes,[e]:n}}));return f(o)?d(o.message):m("Locked node",n)},updateNode(e){let t=J(n=>({...n,nodes:{...n.nodes,[e.id]:e}}));return f(t)?m("Updated node",e):t},updateNodeAndSelectInParent(e){return J(t=>{let n={...t.nodes,[e.id]:e},o=Object.values(n).filter(i=>!i.isDeleted&&i.parentNodeId===e.parentNodeId).sort((i,s)=>i.rank.localeCompare(s.rank)),r=e.parentNodeId?n[e.parentNodeId]:n[t.rootNodeId];return D.navigate({currentNode:r,selectedIndex:o.findIndex(({id:i})=>i===e.id)}),{...t,nodes:n}}),m("Updated and selected",e)},getContributor(e){return v().contributors[e]},getTag(e){return v().tags[e]},getNode(e){return v().nodes[e]},getSiblings:e=>Object.values(v().nodes).filter(t=>!t.isDeleted&&t.parentNodeId===e).sort((t,n)=>t.rank.localeCompare(n.rank))};var ut={preferredEditor:null,userName:null,userId:null},te=()=>ut,Ye=e=>(ut={...ut,...e},ut);var pt=()=>{let e=te(),t=!!e.userName?.trim(),n=!!e.preferredEditor?.trim();return{isSetup:n&&t,hasPreferredEditor:n,hasUserName:t,userName:e.userName,preferredEditor:e.preferredEditor}},Gn=()=>!ft();var Fe={urgent:"red",critical:"red",important:"red",blocker:"red",asap:"red",immediate:"red",fail:"red",failure:"red",broken:"red",bug:"red",error:"red",incident:"red",outage:"red",production:"red",crash:"red",security:"red",warning:"yellow",warn:"yellow",risky:"yellow",risk:"yellow",attention:"yellow",pending:"yellow",review:"yellow","needs-review":"yellow",qa:"yellow",testing:"yellow",test:"yellow",validate:"yellow",verification:"yellow",staging:"yellow",check:"yellow","follow-up":"yellow",followup:"yellow",waiting:"yellow",blocked:"yellow",hold:"yellow",done:"green",complete:"green",completed:"green",success:"green",ok:"green",stable:"green",resolved:"green",fixed:"green",closed:"green",merged:"green",released:"green",deployed:"green",approved:"green",verified:"green",working:"green",healthy:"green",pass:"green",passing:"green",info:"blue",information:"blue",note:"blue",docs:"blue",documentation:"blue",doc:"blue",guide:"blue",help:"blue",explanation:"blue",detail:"blue",details:"blue",context:"blue",design:"blue",discussion:"blue",proposal:"blue",idea:"blue",feature:"magenta",enhancement:"magenta",improvement:"magenta",refactor:"magenta",refactoring:"magenta",cleanup:"magenta",optimize:"magenta",optimization:"magenta",perf:"magenta",performance:"magenta",upgrade:"magenta",migration:"magenta",modernize:"magenta",debt:"magenta",todo:"cyan",next:"cyan",planned:"cyan",plan:"cyan",future:"cyan",backlog:"cyan",investigate:"cyan",explore:"cyan",prototype:"cyan"};var O=e=>{let{currentNode:t}=v(),n=pt().isSetup,o=t.context,r=[p.HELP,p.SET_VIEW,p.SET_EDITOR,p.SET_USERNAME],i=[p.NEW,p.RENAME,p.DELETE],s=[p.TAG,p.ASSIGN,p.CLOSE_ISSUE,p.RE_OPEN_ISSUE,p.SET_DESCRIPTION],l=[...{WORKSPACE:[...r],BOARD:[p.FILTER,...r,...i],SWIMLANE:[p.FILTER,...r,...i],TICKET:[...r,...i,...s],FIELD:[...r,...s],FIELD_LIST:[...r,...s],TEXT:[...r]}[o||"WORKSPACE"]],c={[p.INIT]:[],[p.SET_USERNAME]:[],[p.SET_DESCRIPTION]:["confirm"],[p.DELETE]:["confirm"],[p.RE_OPEN_ISSUE]:["confirm"],[p.MOVE]:["start","confirm","next","previous","to-next","to-previous","cancel"],[p.CLOSE_ISSUE]:["confirm"],[p.FILTER]:["tag","assignee","description","title","clear"],[p.SET_VIEW]:["dense","wide"],[p.SET_EDITOR]:[...$n,"vim"],[p.TAG]:[...new Set([...Object.keys(Fe),...C.getExistingTags()])],[p.ASSIGN]:C.getExistingAssignees(),[p.HELP]:[],[p.RENAME]:[],[p.NEW]:o==="TICKET"||o==="FIELD"||o==="FIELD_LIST"?["issue","swimlane","board"]:o==="SWIMLANE"?["issue","swimlane","board"]:o==="BOARD"?["swimlane","board"]:["board"],[p.NONE]:l};return n?Gn()||(c={[p.NONE]:[p.HELP,p.INIT],[p.HELP]:c[p.HELP],[p.INIT]:c[p.INIT]}):c={[p.NONE]:[p.HELP,p.SET_EDITOR,p.SET_USERNAME],[p.HELP]:c[p.HELP],[p.SET_EDITOR]:c[p.SET_EDITOR],[p.SET_USERNAME]:c[p.SET_USERNAME]},c[e]??[]};import Gr from"chalk";import Be from"chalk";var Kr=e=>{let t=0;for(let n=0;n<e.length;n++)t=e.charCodeAt(n)+((t<<5)-t),t|=0;return Math.abs(t)},$r=(e,t,n)=>{t/=100,n/=100;let o=(1-Math.abs(2*n-1))*t,r=e/60,i=o*(1-Math.abs(r%2-1)),s=0,a=0,l=0;r>=0&&r<1?(s=o,a=i):r>=1&&r<2?(s=i,a=o):r>=2&&r<3?(a=o,l=i):r>=3&&r<4?(a=i,l=o):r>=4&&r<5?(s=i,l=o):(s=o,l=i);let c=n-o/2,g=x=>Math.round((x+c)*255).toString(16).padStart(2,"0");return`#${g(s)}${g(a)}${g(l)}`},Oe=e=>{let n=Kr(e)%360;return $r(n,65,45)},gt=[[168,139,250],[59,130,246],[34,211,238]],Jt=(e,t,n)=>e+(t-e)*n,zr=(e,t,n)=>[Math.round(Jt(e[0],t[0],n)),Math.round(Jt(e[1],t[1],n)),Math.round(Jt(e[2],t[2],n))],Xn=e=>{let t=Math.max(0,Math.min(1,e)),n=gt.length-1,o=t*n,r=Math.min(Math.floor(o),n-1),i=o-r;return gt?zr(gt[r],gt[r+1],i):[0,0,0]},jr=e=>{let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)>>>0;return t},Qe=e=>jr(e.toLowerCase().trim())/4294967295,qr=e=>{let t=Qe(e),[n,o,r]=Xn(t);return{normal:i=>Be.bgRgb(n,o,r).black(i),cursor:i=>Be.bgRgb(n,o,r).white.bold(i)}},Yt=e=>{let t=Qe(e),[n,o,r]=Xn(t);return{fg:i=>Be.rgb(n,o,r)(i),fgCursor:i=>Be.rgb(n,o,r).inverse(i),bg:i=>Be.bgRgb(n,o,r).black(i),bgCursor:i=>Be.bgRgb(n,o,r).white.bold(i)}},Qt=e=>qr(e).normal(` ${e} `);var Ce="<ENTER> to confirm",G=(e="",t=[])=>({message:e,validity:ae.Valid,completionWordList:t}),ne=({message:e,completionWordList:t})=>({validity:ae.Invalid,message:e,completionWordList:t}),xt=e=>e.length===0,Z=({prefix:e="",wordList:t,postfix:n="",noOfHints:o=2,inputString:r,minLengthForHints:i=1})=>{let l=[...t.filter(Boolean).filter(g=>g.startsWith(r.trim()))].sort((g,x)=>Qe(g)-Qe(x)).slice(0,o).map(Qt),c=l.length>i?l.join(" "):"";return c?`${e}${c}${n}`:""},Zt=({modifier:e})=>{let t="confirm";return e===t?G(Ce):ne({message:xt(e)?`if you are certain, enter ${Qt(t)}`:"",completionWordList:[t]})},Jn=({list:e,hint:t})=>({modifier:n})=>e.includes(n)?G(Ce):ne({message:xt(n)?t:"",completionWordList:[]}),Yn=({hint:e})=>({modifier:t,inputString:n})=>xt(t)&&xt(n)?ne({message:e,completionWordList:[]}):G(Ce),Xr=({list:e,prefix:t="",noOfHints:n=10,minLengthForHints:o=1})=>({modifier:r,inputString:i})=>{let a=(r||i).trim();return i.length?G(Z({wordList:e,noOfHints:n,inputString:a}),[...e]):ne({message:Z({prefix:t,wordList:e,noOfHints:n,inputString:"",minLengthForHints:o}),completionWordList:[...e]})},Jr={[p.INIT]:()=>G(Ce),[p.FILTER]:e=>{if(e.modifier==="clear")return G();let t=s=>O(p.FILTER).includes(s);if(!e.modifier||!t(e.modifier??""))return ne({message:Z({wordList:O(p.FILTER),noOfHints:100,inputString:e.inputString}),completionWordList:O(p.FILTER)});let o=Object.values(v().tags).map(s=>s.name),r=Object.values(v().contributors).map(s=>s.name),i=e.modifier==="tag"?o:e.modifier==="assignee"?r:[];return e.inputString?i.length&&!i.includes(e.inputString.trim()??"")?ne({message:Z({prefix:`existing ${e.modifier}s... `,wordList:i,noOfHints:10,inputString:e.inputString}),completionWordList:i}):G():ne({message:Z({prefix:"one of... ",wordList:i,noOfHints:10,inputString:e.inputString}),completionWordList:i})},[p.NONE]:e=>e.command?G():ne({message:Z({prefix:"commands... ",wordList:O(p.NONE),noOfHints:100,inputString:e.inputString,minLengthForHints:0}),completionWordList:[]}),[p.NEW]:e=>Jn({list:O(p.NEW),hint:Z({wordList:O(p.NEW),noOfHints:3,inputString:e.inputString,minLengthForHints:0})})(e),[p.SET_DESCRIPTION]:()=>G(Ce),[p.HELP]:()=>G(Ce),[p.RENAME]:()=>G(Ce),[p.DELETE]:e=>Zt(e),[p.CLOSE_ISSUE]:e=>Zt(e),[p.RE_OPEN_ISSUE]:e=>Zt(e),[p.MOVE]:e=>Yn({hint:Z({prefix:"hey hacker! These commands are blocked for you... ",wordList:O(p.MOVE),noOfHints:10,inputString:e.inputString})})(e),[p.TAG]:e=>Yn({hint:Z({prefix:"tag name like... ",wordList:O(p.TAG),noOfHints:3,inputString:e.inputString})})(e),[p.ASSIGN]:e=>{let t=Object.values(v().contributors).map(n=>n.name);return Xr({list:[...t],prefix:"enter assignee name... ",noOfHints:10,minLengthForHints:0})(e)},[p.SET_EDITOR]:e=>{logger.debug(`Validating command: ${e.command} ${e.modifier} ${e.inputString}`);let t=O(p.SET_EDITOR);return e.modifier?G(Ce):ne({message:Z({wordList:t,noOfHints:100,inputString:e.inputString}),completionWordList:[]})},[p.SET_USERNAME]:e=>e.inputString?G():ne({message:`Enter a username. Saved in ${Gr.bgBlack("~/.epiqrc")}`,completionWordList:[]}),[p.SET_VIEW]:e=>Jn({list:O(p.SET_VIEW),hint:Z({wordList:O(p.SET_VIEW),noOfHints:3,inputString:e.inputString})})(e)},Qn=Object.fromEntries(Object.entries(Jr).map(([e,t])=>[e,{validate:(n,o,r)=>t({modifier:o,command:n,inputString:r})}]));var Zn=["frontend","backend","infrastructure","architecture","integration","configuration","implementation","application","deployment","environment","framework","platform","service","component","module","gateway","pipeline","containerization","orchestrator","exception","incident","defect","regression","degradation","malfunction","instability","intermittent","reproducibility","reproduction","investigation","triage","workaround","mitigation","remediation","optimization","stabilization","refinement","failure","outage","blocking","criticality","severity","escalation","diagnostics","analysis","resolution","corruption","inconsistency","validation","verification","authorization","authentication","confidentiality","availability","accessibility","reliability","compliance","governance","encryption","decryption","integrity","auditing","traceability","accountability","protection","privileges","permissions","dependency","orchestration","provisioning","synchronization","compatibility","incompatibility","interoperability","observability","instrumentation","telemetry","loadbalancing","discovery","registration","scheduling","coordination","distribution","isolation","virtualization","serialization","deserialization","initialization","instantiation","propagation","aggregation","consolidation","normalization","standardization","transformation","reconciliation","correlation","processing","indexing","partitioning","enrichment","validation","filtering","streaming","batching","concurrency","parallelism","contention","deadlock","throttling","ratelimiting","backpressure","fragmentation","saturation","exhaustion","partitioning","replication","redundancy","failover","deprecation","obsolescence","starvation","overload","underutilization","latency","throughput","refactoring","modularization","encapsulation","abstraction","extensibility","configurability","maintainability","recoverability","sustainability","readability","testability","debuggability","reusability","simplicity","consistency","performance","functionality","requirement","recommendation","improvement","enhancement","clarification","documentation","description","acceptance","criteria","estimation","prioritization","dependency","deliverable","milestone","iteration"];var w={Init:"init",None:"none",ViewHelp:"view-help",Rename:"rename",Edit:"edit",Delete:"delete",Filter:"filter",Move:"move",SetView:"set-view",SetEditor:"set-editor",SetUserName:"set-user-name",NewItem:"add-new-item",TagTicket:"ticket-tag",AssignUserToTicket:"ticket-assign-user",CloseIssue:"close-issue",ReopenIssue:"re-open-issue"};var eo=e=>Object.values(p).includes(e),to=(e,t)=>{let n=e.command??"",{modifier:o,target:r,inputString:i}=e,{message:s,validity:a,completionWordList:l}=Qn[n].validate(n,o,i),c=r==="command"?Object.values(p):n&&e.target==="modifier"?O(n):Zn;return{validity:a,command:e.command,modifier:e.modifier,inputString:e.inputString,infoMessage:s??"",autoCompletion:t?Kn(e,[...l,...c]):{hint:"",hints:[],remainder:"",overlap:0}}};var no=e=>{let t=e.trimStart(),n=Qr(t),o=(n[0]??"").trimStart().trimEnd(),r=(n[1]??"").trimStart().trimEnd(),i=Zr(e),s=eo(o)?o:null,a=s!==null,l=o!=="",c=e.endsWith(" "),g=s?O(s)??[]:[],x=s&&g.includes(r)?r:"",N="word";n.length<=1?N="command":n.length===2&&(N="modifier");let S=Yr(t,s,x);return{raw:e,trimmedStart:t,words:n,firstWord:o,lastWord:i,hasCommand:l,command:s,isCommandKeyword:a,isLastWordCompleted:c,modifier:x,target:N,inputToMatch:i,inputString:S}},Yr=(e,t,n)=>{let o=e;return t&&o.startsWith(t)&&(o=o.slice(t.length)),o=o.replace(/^\s+/,""),n&&o.startsWith(n)&&(o=o.slice(n.length),o=o.replace(/^\s+/,"")),o},Qr=e=>e?e.split(/\s+/):[],Zr=e=>e.trimEnd().split(/\s+/).at(-1)??"";var oo=" ",U={commandHistory:[],value:"",commandHistoryIndex:-1,cursorPosition:0,commandIsPending:!1,commandMeta:{command:null,modifier:"",infoMessage:"",inputString:"",validity:ae.None,autoCompletion:{hint:"",hints:[],remainder:"",overlap:0}}},en=new Set,ro=()=>{for(let e of en)e()},io=e=>(en.add(e),()=>en.delete(e)),le=e=>{let n=e(U),o=no(n.value),r=n.cursorPosition===n.value.length;U={...n,commandMeta:to(o,r)},ro()},vt=({message:e,result:t})=>{let n=structuredClone(U);return n.commandMeta={...n.commandMeta,infoMessage:e??"",validity:t==="fail"?"invalid":"valid"},n.commandIsPending=!0,U=n,ro(),m(e,null)},tn=e=>{le(t=>({...t,cursorPosition:Math.max(0,Math.min(t.value.length,t.cursorPosition+e))}))},nn=e=>{le(t=>{let{value:n,cursorPosition:o}=t,r=o;if(e==="left"){for(;r>0&&n[r-1]===" ";)r--;for(;r>0&&n[r-1]!==" ";)r--}else{for(;r<n.length&&n[r]!==" ";)r++;for(;r<n.length&&n[r]===" ";)r++}return{...t,cursorPosition:r}})},so=()=>{le(e=>{let t=e.value.slice(e.cursorPosition),n=Math.max(0,e.cursorPosition-1);return{...e,value:e.value.slice(0,n)+t,cursorPosition:n,commandIsPending:!1}})},ao=()=>{le(e=>{let{value:t,cursorPosition:n}=e,o=n;for(;o>0&&t[o-1]===" ";)o--;for(;o>0&&t[o-1]!==" ";)o--;let r=t.slice(n);return{...e,value:t.slice(0,o)+r,cursorPosition:o,commandIsPending:!1}})},k=e=>{le(t=>{let n=Math.max(0,Math.min(t.cursorPosition,t.value.length)),o=t.value.slice(0,n),r=t.value.slice(n),i=e(o,t.commandMeta.autoCompletion),s=i+r,a=Math.max(0,Math.min(i.length,s.length));return{...t,value:s,cursorPosition:a,commandIsPending:!1}})},lo=()=>{le(e=>({...e,commandIsPending:!0}))},co=({addToHistory:e=!0})=>{le(n=>({...n,commandHistory:e?[n.value,...n.commandHistory].slice(0,40):n.commandHistory,commandHistoryIndex:-1,commandIsPending:!1})),ei()},mo=()=>{le(e=>{let t=Math.min(e.commandHistoryIndex+1,e.commandHistory.length-1),n=e.commandHistory[t]??"";return{...e,commandHistoryIndex:t,value:n,cursorPosition:n.length}})},uo=()=>{le(e=>{let t=Math.max(e.commandHistoryIndex-1,-1),n=t===-1?"":e.commandHistory[t]??"";return{...e,commandHistoryIndex:t,value:n,cursorPosition:n.length}})},ei=()=>k(()=>""),oe=()=>U,yt=()=>{let[e,...t]=U.value.split(oo);return t.join(oo).trim()};var ti=(e,t)=>e.ctrl&&e.name==="w"||e.meta&&e.name==="backspace"||t==="",ni=(e,t)=>e.meta&&e.name==="b"||t==="\x1Bb",oi=(e,t)=>e.meta&&e.name==="f"||t==="\x1Bf",po=(e,t)=>{if(ni(e,e.sequence))return"MoveCursorLeftOfWord";if(oi(e,e.sequence))return"MoveCursorRightOfWord";if(ti(e,e.sequence))return"EraseInputWord";switch(e.name){case"tab":return"autoCompleteCommand";case"up":return"getLastCommandFromHistory";case"down":return"getNextCommandFromHistory";case"left":return"MoveCursorLeft";case"right":return"MoveCursorRight";case"return":return"confirm";case"backspace":return t?"eraseInput":"exitCommandLine";case"escape":return"exitCommandLine";default:return"captureInput"}};function ri(e){switch(e.name){case"up":case"down":case"left":case"right":return e.name;case"k":return"up";case"j":return"down";case"h":return"left";case"l":return"right";default:return null}}function ii(e,t,n){let o=v().currentNode.childNavigationAcrossParents;switch(t){case"up":return e==="vertical"?n.prevItem:o?n.prevContainer:null;case"down":return e==="vertical"?n.nextItem:o?n.nextContainer:null;case"left":return e==="horizontal"?n.prevItem:o?n.prevContainer:null;case"right":return e==="horizontal"?n.nextItem:o?n.nextContainer:null}}function fo(e,t){let n=oe();if(e.sequence===":"&&n.value==="")return"initCommandLine";if(t===u.MOVE)switch(e.name){case"m":case"return":return"confirmMove"}if(t===u.COMMAND_LINE)return po(e,n.value);let o=ri(e);if(o){let r=t===u.MOVE?{prevItem:"movePreviousItem",nextItem:"moveNextItem",prevContainer:"moveToPreviousContainer",nextContainer:"moveToNextContainer"}:{prevItem:"navPreviousItem",nextItem:"navNextItem",prevContainer:"navToPreviousContainer",nextContainer:"navToNextContainer"};return ii(v().currentNode.childRenderAxis,o,r)}if(e.ctrl&&e.name==="c")return"exit";switch(e.name){case"e":return"edit";case"n":return"addItem";case"m":return"initMove";case"d":return"Delete";case"return":return"confirm";case"space":return"confirm";case"v":return v().viewMode==="wide"?"SetViewDense":"SetViewWide";case"q":case"escape":return"exit";default:return null}}var go=e=>{let{context:t}=v()?.currentNode;if(!t)return w.None;switch(e){case p.INIT:return w.Init;case p.DELETE:return w.Delete;case p.SET_DESCRIPTION:return w.Edit;case p.HELP:return w.ViewHelp;case p.RE_OPEN_ISSUE:return w.ReopenIssue;case p.CLOSE_ISSUE:return w.CloseIssue;case p.TAG:return w.TagTicket;case p.ASSIGN:return w.AssignUserToTicket;case p.RENAME:return w.Rename;case p.NEW:return w.NewItem;case p.FILTER:return w.Filter;case p.MOVE:return w.Move;case p.SET_USERNAME:return w.SetUserName;case p.SET_EDITOR:return w.SetEditor;case p.SET_VIEW:return w.SetView;default:return w.None}};import{ulid as B}from"ulid";import{spawnSync as pi}from"node:child_process";import fi from"node:os";import Co from"node:path";import{ulid as gi}from"ulid";import{accessSync as si,copyFileSync as ai,existsSync as Ct,mkdirSync as xo,readdirSync as vo,readFileSync as di,renameSync as li,rmSync as ci,statSync as yo,unlinkSync as mi,writeFileSync as ui}from"node:fs";import ke from"node:path";var X={writeToFile:(e,t)=>{try{let n=ke.dirname(e);Ct(n)||xo(n,{recursive:!0});let o=typeof t=="string"?t:JSON.stringify(t,null,2);ui(e,o,"utf-8")}catch(n){logger.error(`Failed to write file at ${e}:`,n)}},readFile:e=>{try{return di(e,"utf-8")}catch(t){return logger.error(`Failed to read file at ${e}:`,t),null}},readFileJSON(e){try{let t=X.readFile(e);return t===null?null:JSON.parse(t)}catch(t){return logger.error(`Failed to read JSON at ${e}:`,t),null}},dirExists:e=>{try{return Ct(e)&&yo(e).isDirectory()}catch{return!1}},async fileExists(e){try{return await si(e),!0}catch{return!1}},mkDir:e=>xo(e,{recursive:!0}),locateFolder:e=>{let t=process.cwd(),{root:n}=ke.parse(t);for(;;){let o=ke.join(t,e);try{if(Ct(o)&&yo(o).isDirectory())return o}catch{logger.error(`Unable to locate folder ${e}`)}if(t===n)break;t=ke.dirname(t)}return null},readFirstJSON(e){try{if(!X.dirExists(e))return null;let t=vo(e).filter(o=>o.endsWith(".json")).sort()[0];if(!t)return null;let n=ke.join(e,t);return X.readFileJSON(n)}catch(t){return logger.error(`Could not read first JSON in folder ${e}`,t),null}},listDir:e=>{try{return X.dirExists(e)?vo(e):[]}catch(t){return logger.error(`Failed to list dir ${e}`,t),[]}},rmFile(e){try{mi(e)}catch(t){t?.code!=="ENOENT"&&logger.error(`Unable to remove file ${e}`)}},rmDir(e){try{ci(e,{recursive:!0,force:!0})}catch(t){t?.code!=="ENOENT"&&logger.error(`Unable to remove dir ${e}`)}},moveFile(e,t,n){if(this.mkDir(ke.dirname(t)),!n?.overwrite&&Ct(t))throw new Error(`moveFile: destination exists: ${t}`);n?.overwrite&&this.rmFile(t);try{li(e,t)}catch(o){if(o?.code==="EXDEV"){ai(e,t),this.rmFile(e);return}throw o}}};function xi(){let{preferredEditor:e}=te(),t=[e,process.env.VISUAL,process.env.EDITOR,"vim","vi","nano"].filter(n=>!!n?.trim());return[...new Set(t)]}function vi(e,t){return/(^|\/)code(-insiders)?$/.test(e.trim())?`${e} --wait "${t}"`:`${e} "${t}"`}function No(e){let t=Co.join(fi.tmpdir(),"epiq");X.mkDir(t);let n=Co.join(t,gi());X.writeToFile(n,e??"");let o=xi();for(let r of o){let i=vi(r,n),s=pi(i,{stdio:"inherit",shell:!0});if(!s.error&&s.status===0){let a=X.readFile(n);if(a==null)return d("Unable to read edited file");let l=a.replace(/\r?\n$/,"");return m("Successfully edited",l)}}return d("Unable to open editor")}import{monotonicFactory as yi,ulid as Nt}from"ulid";var It=yi(),Io=({name:e,parent:t,userId:n})=>{let o=It(),r=It(),i=It(),s=It();return[{id:Nt(),userId:n,action:"add.issue",payload:{id:o,parent:t,name:e}},{id:Nt(),userId:n,action:"add.field",payload:{id:r,parent:o,name:"Description",val:""}},{id:Nt(),userId:n,action:"add.field",payload:{id:i,parent:o,name:"Assignees"}},{id:Nt(),userId:n,action:"add.field",payload:{id:s,parent:o,name:"Tags"}}]};var Eo=e=>{let t=e.log??[];for(let n=t.length-1;n>=0;n--){let o=t[n];if(o&&o.action==="close.issue"&&o.payload.id===e.id)return o.payload.parent}return null};var Ci=["00KM6CZ900T7180RM46K0JAYNF","00JR3R8E00A1Z4X9FGP9DV0SM5"],[Ue,Et]=Ci;var L=(e,t)=>d(`${t.split(".").join(" ")+" failed, "+e.toLowerCase()}`),Ni={"init.workspace":({action:e,payload:t})=>{let{id:n,name:o}=t,r=V.workspace(n,o);ho(r);let i=C.createNodeAtPosition(r);return f(i)?L(i.message??"Failed to initialize workspace",e):m("Workspace initialized",{action:e,result:i.data})},"add.workspace":({action:e,payload:t})=>{let{id:n,name:o}=t,r=V.workspace(n,o),i=C.createNodeAtPosition(r);return f(i)?L(i.message??"Failed to add workspace",e):m("Added workspace",{action:e,result:i.data})},"add.board":({action:e,payload:t})=>{let{id:n,name:o,parent:r}=t,i=C.createNodeAtPosition(V.board(n,o,r));return f(i)?L(i.message??"Unable to create board",e):m("Added board",{action:e,result:i.data})},"add.swimlane":({action:e,payload:t})=>{let{id:n,name:o,parent:r}=t,i=C.createNodeAtPosition(V.swimlane(n,o,r));return f(i)?L(i.message??"Unable to create swimlane",e):m("Added swimlane",{action:e,result:i.data})},"add.issue":({action:e,payload:t})=>{let{id:n,name:o,parent:r}=t,i=C.createNodeAtPosition(V.ticket(n,o,r));return f(i)?L(i.message??"Unable to create issue",e):m("Added issue",{action:e,result:i.data})},"add.field":({action:e,payload:t})=>{let{id:n,name:o,parent:r,val:i}=t,s=C.createNodeAtPosition(V.field(n,o,r,{value:i},o.includes("Description")?"vertical":"horizontal"));return f(s)?L(s.message??`Unable to create field: ${o}`,e):m("Added field",{action:e,result:s.data})},"edit.title":({action:e,payload:t})=>{let{id:n,name:o}=t;if(!C.getNode(n))return L("Unable to locate node",e);let i=C.renameNode(n,o);return f(i)?L(i.message??"Unable to edit title",e):m("Edited title",{action:e,result:i.data})},"delete.node":({action:e,payload:t})=>{let{id:n}=t,o=C.tombstoneNode(n);return f(o)?L(o.message??"Unable to delete node",e):m("Deleted node",{action:e,result:o.data})},"create.tag":({action:e,payload:t})=>{let{id:n,name:o}=t,r=C.createTag({id:n,name:o});return f(r)?L(r.message??"Unable to create tag",e):m("Tag added",{action:e,result:r.data})},"create.contributor":({action:e,payload:t})=>{let{id:n,name:o}=t,r=C.createContributor({id:n,name:o});return f(r)?L(r.message??"Unable to create contributor",e):m("Contributor created",{action:e,result:r.data})},"tag.issue":({action:e,payload:t})=>{let{id:n,target:o,tagId:r}=t,i=C.tag(o,r,n);return f(i)?L(i.message??"Unable to tag issue",e):m("Issue tagged",{action:e,result:i.data})},"assign.issue":({action:e,payload:t})=>{let{id:n,contributor:o,target:r}=t,i=C.assign(r,o,n);return f(i)?L(i.message??"Unable to assign issue",e):m("Assigned successfully",{action:e,result:i.data})},"move.node":({action:e,payload:t})=>{let{id:n,parent:o,pos:r}=t,i=C.moveNode({id:n,parentId:o,position:r});return f(i)?L(i.message??"Failed to move node",e):m("Moved node",{action:e,result:i.data})},"edit.description":({action:e,payload:t})=>{let{id:n,md:o}=t,r=C.editValue(n,o);return f(r)?L(r.message??"Unable to edit description",e):m("Set node value",{action:e,result:r.data})},"close.issue":({action:e,payload:t})=>{let{id:n}=t,o=C.getNode(n);if(!o)return L("Unable to locate issue",e);if(!Ae(o))return L("Can only close issues",e);let r=C.getNode(Ue);if(!r)return L("Unable to locate target swimlane",e);if(r.id===o.parentNodeId)return L("Cannot close closed issue",e);let s=C.moveNode({id:n,parentId:r.id,navigate:!1});return f(s)?L(s.message??"Unable to close issue",e):m("Issue closed",{action:e,result:s.data})},"reopen.issue":({action:e,payload:t})=>{let{id:n}=t,o=C.getNode(n);if(!o)return L("Unable to locate issue",e);if(!Ae(o))return L("Can only reopen issues",e);let r=C.getNode(Ue);if(!r)return L("Unable to locate closed swimlane",e);if(!(o.parentNodeId===r.id))return L("Issue is not closed",e);let s=Eo(o);if(!s)return L("Unable to resolve previous parent from issue history",e);if(s===r.id)return L("Previous parent resolves to closed swimlane",e);if(!C.getNode(s))return L("Previous parent no longer exists",e);let l=C.moveNode({id:n,parentId:s,navigate:!1});return f(l)?L(l.message??"Unable to reopen issue",e):m("Issue reopened",{action:e,result:l.data})},"lock.node":({action:e,payload:t})=>{let{id:n}=t,o=C.lockNode(n);return f(o)?L(o.message??"Unable to lock node",e):m("Node locked",{action:e,result:o.data})}},Ii=(e,t)=>{let n=C.getNode(e);n&&C.updateNode({...n,log:[...n.log??[],t]})},Ei=e=>{switch(e.action){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"delete.node":case"move.node":case"close.issue":case"reopen.issue":return[e.payload.id];case"edit.description":let t=[e.payload.id],n=v().nodes[e.payload.id]?.parentNodeId;return n&&t.push(n),t;case"tag.issue":case"assign.issue":return[e.payload.id,e.payload.target];case"create.tag":case"create.contributor":default:return[]}};function We(e,t=!1){let n=Ni[e.action],o=n(e);if(f(o))return o;if(!t){let s=[...new Set(Ei(e))];for(let a of s)Ii(a,e)}let[r,i]=e.userId.split(".");return!r?.length||!i?.length?L("Invalid user ID format",e.action):(C.createContributor({name:i,id:r}),o)}var rn=e=>e.map(t=>We(t));import ht from"node:fs";import Te from"node:path";import{decodeTime as wi,monotonicFactory as Li}from"ulid";import sn from"node:fs";import an from"node:path";var hi=".epiq",bi="events",Si=(e=process.cwd())=>an.join(_e(e),hi,bi),Ai=e=>{let t=Object.keys(e).filter(n=>n!=="id");return t.length!==2?d(`Invalid persisted event: expected exactly 2 keys, got ${t.length}`):!t[0]||!(t[0]in e)?d("Invalid persisted event: action key is missing or invalid"):m("Resolved persisted action",t[0])},Ti=e=>{let{userId:t,...n}=e,o=Ai(n);if(f(o))return d(o.message);let r=o.data;if(!r)return d("Action key is undefined");let i=e.id?.[0];if(!i)return d("Persisted event is missing id");let s=n[r];return m("Decoded persisted event",{id:i,action:r,payload:s,userId:t})};function bo(e=process.cwd()){let t=Si(e);if(!sn.existsSync(t))return d("No events found");let n=sn.readdirSync(t).filter(r=>r.endsWith(".jsonl")).map(r=>an.join(t,r)),o=[];for(let r of n){let i=sn.readFileSync(r,"utf8"),s=an.basename(r,".jsonl")||"unknown";for(let a of i.split(`
3
+ `)){let l=a.trim();if(l)try{let c=JSON.parse(l);o.push({...c,userId:s})}catch{return d(`Failed to parse event from line: ${l}`)}}}return m("All events loaded",Mi(o))}function So(e=process.cwd()){let t=bo(e);if(f(t))return d(t.message);let n=[];for(let o of t.data){let r=Ti(o);if(f(r))return d(`Failed to decode event ${o.id?.[0]??"<unknown>"}: ${r.message}`);n.push(r.data)}return m("Loaded merged events",n)}function Ao(e=process.cwd()){let t=bo(e);return f(t)?d(t.message):m("Loaded edge reference",t.data.at(-1)?.id?.[0]??null)}var Mi=e=>{let t=new Map(e.map(a=>[a.id[0],a])),n=new Map;for(let a of e){let l=a.id[1],c=n.get(l)??[];c.push(a),n.set(l,c)}for(let a of n.values())a.sort((l,c)=>{let[g]=l.id,[x]=c.id;return g.localeCompare(x)});let o=[],r=new Set,i=a=>{let l=n.get(a)??[];for(let c of l){let[g]=c.id;r.has(g)||(r.add(g),o.push(c),i(g))}};i(null);let s=[...e].filter(a=>{let[l]=a.id;return!r.has(l)}).sort((a,l)=>{let[c,g]=a.id,[x,N]=l.id,S=g===null||t.has(g),h=N===null||t.has(N);if(S&&!h)return-1;if(!S&&h)return 1;let I=(g??"").localeCompare(N??"");return I!==0?I:c.localeCompare(x)});return[...o,...s]};var To=e=>({action:e.action,payload:e.payload});var Pi=1,Mo=Li(),dn=".epiq",Di="events",wo=e=>e.trim().toLowerCase().replace(/[^a-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"")||"unknown",K=()=>{let{userName:e,userId:t}=te();if(!e)return d("User name not configured");if(!t)return d("User ID not configured");let n=`${wo(t)}.${wo(e)}`;return e.trim()?m("Successfully resolved actor ID",n):d("Unable to resolve actor ID from settings or OS user info")},Ri=e=>ht.existsSync(Te.join(e,dn))&&ht.statSync(Te.join(e,dn)).isDirectory(),_e=(e=process.cwd())=>{let t=Te.resolve(e);for(;;){if(Ri(t))return t;let n=Te.dirname(t);if(n===t)return Te.resolve(e);t=n}},Lo=(e=process.cwd())=>Te.join(_e(e),dn,Di),Fi=(e=process.cwd())=>{let t=K();return f(t)||!t.data?d("Unable to resolve event log path"):m("Successfully resolved event log path",Te.join(Lo(e),`${t.data}.jsonl`))},Bi=(e,t)=>({[e.action]:e.payload,v:Pi,id:t});function Po(e,t=process.cwd()){try{let n=_e(t),o=Lo(n),r=Fi(n);if(f(r))return r;ht.mkdirSync(o,{recursive:!0});let i=Ao(n);if(f(i))return d(i.message);let s;if(i.data){let l=wi(i.data),c=Math.max(Date.now(),l+1);s=Mo(c)}else s=Mo();let a=Bi(To(e),[s,i.data]);return ht.appendFileSync(r.data,`${JSON.stringify(a)}
4
+ `,"utf8"),m("Event persisted",{path:r.data,entry:a})}catch(n){let o=n instanceof Error?n.message:"Unknown persist error";return d(`Failed to persist event: ${o}`)}}function $(e){let t=We(e);if(t.result!==de.Success)return t;let n=Po(e);return f(n)?n:t}function bt(e){return e.map(t=>$(t))}import{ulid as Do}from"ulid";var He=null,Me=()=>structuredClone(He),Ve=e=>He=e,Ro=()=>{let{currentNode:e,selectedIndex:t}=v(),o=A(e.id)[t];return o?m("Resolved selected child",o):d("Target node not found")};function ln(e){let t=Ro();if(f(t))return t;let{currentNode:n,nodes:o}=v();if(!n.parentNodeId)return d("Missing parent node id");let r=o[n.parentNodeId];if(!r)return d("Missing parent node");let i=F(r.id),s=i.findIndex(({id:x})=>x===n.id);if(s<0)return d("Current node not found among siblings");let a=i[s+e];if(!a)return d("Missing sibling node");let l=K();if(f(l))return d("Unable to resolve user ID");let c=l.data;if(Ve({id:Do(),userId:c,action:"move.node",payload:{id:t.data.id,parent:a.id,pos:{at:"end"}}}),!He)return d("Could not materialize move state");let g=We(He,!0);return f(g)?g:m("Node moved successfully",g.data)}function cn(e){let t=Ro();if(f(t))return t;let{currentNode:n,selectedIndex:o}=v(),i=F(n.id)[o+e];if(!i)return d("Missing sibling node");let s=K();if(f(s))return d("Unable to resolve user ID");let a=s.data;if(Ve({id:Do(),userId:a,action:"move.node",payload:{id:t.data.id,parent:n.id,pos:{at:e===1?"after":"before",sibling:i.id}}}),!He)return d("Could not materialize move state");let l=We(He,!0);return f(l)?l:m("Node moved successfully",l.data)}import Oi from"node:os";import ki from"node:path";var Ui=".epiqrc",St=()=>ki.join(Oi.homedir(),Ui),Wi=e=>{try{let t=JSON.parse(e);return m("Parsed config",t??{})}catch{return d("Invalid ~/.epiqrc JSON")}},mn=()=>{let e=St(),t=X.readFile(e);return t==null||t.trim()===""?m("No config found, using empty config",{}):Wi(t)},un=e=>{let t=St();try{return X.writeToFile(t,JSON.stringify(e,null,2)+`
5
+ `),m("Config written",null)}catch{return d("Unable to write ~/.epiqrc")}},pn=e=>{let t=mn();if(f(t))return d("Failed to set preferred editor");let n={...t.data,...e};return un(n)};var Ke=(e,t)=>{let n=e.find(o=>o.context===t);return n!==void 0?m("Found node",n):d("Unable to find node in breadcrumb")};var _i=e=>Object.values(v().tags).find(t=>t.name===e),Hi=e=>Object.values(v().contributors).find(t=>t.name===e),Fo=[{systemOnly:!0,intent:w.Move,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{modifier:n}=oe().commandMeta,{currentNode:o,selectedIndex:r}=v(),i=A(o.id)[r];if(!i)return b({mode:u.DEFAULT}),d("No move target");if(n==="start"){if(i.readonly)return d("Target node is read-only");if(r===-1)return d("No item selected");if(!i.parentNodeId)return d("Target has no parent");let s=A(i.parentNodeId),a=s.findIndex(({id:x})=>x===i.id);if(a===-1)return d("Target not found among siblings");let l=s[a-1],c=s[a+1],g=c!=null?{at:"before",sibling:c.id}:l!=null?{at:"after",sibling:l.id}:{at:"start"};return Ve({id:B(),userId:t,action:"move.node",payload:{id:i.id,parent:i.parentNodeId,pos:g}}),b({mode:u.MOVE}),m("Move initialized",null)}if(n==="next")return b({mode:u.MOVE}),cn(1);if(n==="previous")return b({mode:u.MOVE}),cn(-1);if(n==="to-next")return b({mode:u.MOVE}),ln(1);if(n==="to-previous")return b({mode:u.MOVE}),ln(-1);if(n==="confirm"){b({mode:u.DEFAULT});let s=Me();if(!s)return d("No pending move to confirm");let a=$(s);return f(a)?a:(Ve(null),m("Moved item",null))}return n==="cancel"?(Ve(null),b({mode:u.DEFAULT}),m("Cancelling move",null)):d("Invalid move modifier")}},{intent:w.Delete,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:o}=v(),r=A(n.id)[o];return r?$({id:B(),userId:t,action:"delete.node",payload:{id:r.id}}):d("Unable to resolve child to delete")},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.Edit,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,n=Ke(v().breadCrumb,"TICKET");if(f(n))return d("Edit target must be an issue");let o=n.data;if(o.readonly)return d("Cannot edit readonly field");let{currentNode:r,selectedIndex:i}=v();if(!A(o.id)[i])return d("No selected field");let a=A(r.id)[i];if(!a)return d("No selected field");if(a.readonly)return d("Cannot edit readonly field");let l=a.props.value;if(typeof l!="string")return d("Selected field is not editable text");let c=No(l);if(f(c))return d("Failed to edit field");let g=c.data;return g===l?m("No changes made",null):a.title==="Description"?$({id:B(),userId:t,action:"edit.description",payload:{id:a.id,md:g}}):a.title==="Title"?$({id:B(),userId:t,action:"edit.title",payload:{id:a.id,name:g}}):d(`Editing not supported for "${a.title}"`)},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.Filter,mode:u.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=oe().commandMeta,n=/(!=|=)/,[o,r]=e.split(n);if(!o||!(a=>O(p.FILTER).map(l=>l.split(n)[0]).includes(a))(o))return d("Invalid filter modifier");let s={target:o,operator:"=",value:t.trim()};return J(a=>({...a,filters:e==="clear"?[]:[...a.filters,s],mode:u.DEFAULT})),m("Viewing help",null)}},{intent:w.ViewHelp,mode:u.COMMAND_LINE,action:()=>(b({mode:u.HELP}),m("Viewing help",null))},{intent:w.CloseIssue,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:o}=v(),r=A(n.id)[o];if(!r)return d("Unable to close issue, no target found");if(!r.parentNodeId)return d("No target parent found");if(!Ae(r))return d("Cannot close in this context");let i=$({id:B(),userId:t,action:"close.issue",payload:{id:r.id,parent:r.parentNodeId}});return f(i)?i:m("Viewing help",null)}},{intent:w.ReopenIssue,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:o}=v(),r=A(n.id)[o];if(!r)return d("Unable to reopen issue, no target found");let i=r.context==="TICKET"?m("Resolved ticket",r):Re(r.id,"TICKET");if(f(i))return d("Cannot reopen in this context");let s=i.data,a=$({id:B(),userId:t,action:"reopen.issue",payload:{id:s.id}});return f(a)?a:m("Issue reopened",null)},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.SetUserName,mode:u.COMMAND_LINE,action:()=>{let{userId:e,preferredEditor:t,userName:n}=te(),o=yt()?.trim();if(!o)return d("No username provided");let r=o??n,i=e??B();if(!r||!i)return d("Unable to resolve user name or id");let s=pn({userName:r,userId:i,preferredEditor:t??""});return f(s)?s:(Ye({userName:r,userId:i}),b({mode:u.DEFAULT}),m(`Username set to "${o}"`,null))}},{intent:w.Init,mode:u.COMMAND_LINE,action:()=>{let e=Bo();if(f(e))return e;let{rootNodeId:t,nodes:n}=v();return D.navigate({currentNode:n[t],selectedIndex:0}),m("Project initialized",null)}},{intent:w.SetEditor,mode:u.COMMAND_LINE,action:()=>{let e=yt()?.trim();if(!e)return d("No editor provided");let t=pn({preferredEditor:e});return f(t)?t:(Ye({preferredEditor:e}),b({mode:u.DEFAULT}),m(`Editor configuration set to "${e}"`,null))}},{intent:w.NewItem,mode:u.COMMAND_LINE,action:(e,t)=>{let n=K();if(f(n))return d("Unable to resolve user ID");let o=n.data;if(!t.inputString)return d(`provide a name for your ${t.modifier}`);let r=i=>{let s=$(i);if(f(s))return s;let a=C.getNode(s.data.result.id);if(!a)return d("Created node not found");if(!a.parentNodeId)return s;let l=C.getNode(a.parentNodeId);return l?(D.navigate({currentNode:l,selectedIndex:C.getSiblings(a.parentNodeId).findIndex(({id:c})=>c===a.id)}),s):d("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:i}=v(),s=C.getNode(i);return s?r({id:B(),userId:o,action:"add.board",payload:{id:B(),name:t.inputString,parent:s.id}}):d("Workspace not found")}if(t.modifier==="swimlane"){let i=Ke(v().breadCrumb,"BOARD");return f(i)?d("Unable to add swimlane in this context"):r({id:B(),userId:o,action:"add.swimlane",payload:{id:B(),name:t.inputString,parent:i.data.id}})}if(t.modifier==="issue"){let i=Ke(v().breadCrumb,"SWIMLANE");if(f(i))return d("Unable to add issue in this context");let s=Io({userId:o,name:t.inputString,parent:i.data.id}),a=bt(s);if(a.some(g=>f(g)))return d("Issue create failed: "+a.filter(f).map(g=>g.message).filter(Boolean).join(", "));let l=a[0];if(!l||f(l))return d("Issue creation failed");let c=s[0]?.payload.id;return c?(D.navigate({currentNode:i.data,selectedIndex:C.getSiblings(i.data.id).findIndex(({id:g})=>g===c)}),m("Issue created",null)):d("Unable to determine ticket id")}return Un()},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.SetView,mode:u.COMMAND_LINE,action:()=>{let{commandMeta:e}=oe();return e.validity===ae.Invalid?d("Invalid command "+de):(J(t=>({...t,viewMode:e.modifier==="wide"?"wide":e.modifier==="dense"?"dense":t.viewMode})),m("View set",null))},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.Rename,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:o}=v(),r=A(n.id)[o];if(!r)return d("Missing node");if(r.readonly)return d("Cannot rename readonly node");let i=yt();return i?$({id:B(),userId:t,action:"edit.title",payload:{id:r.id,name:i}}):d("Provide a new name")},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.TagTicket,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{modifier:n,inputString:o}=oe().commandMeta,r=n||o;if(!r)return d("Provide a tag");let{selectedIndex:i,currentNode:s}=v(),a=A(s.id)[i];if(!a)return d("Invalid tag target");let l=Re(a.id,"TICKET");if(f(l))return d("Unable to tag issue in this context");let c=l.data,g=_i(r),x;if(g)x=g.id;else{let h=B(),I=$({id:B(),userId:t,action:"create.tag",payload:{id:h,name:r}});if(f(I))return I;x=I.data.result.id}let N=C.getFieldByTitle(c.id,"Tags");return N?A(N.id).some(h=>h.props?.value===x)?d("Already tagged with that tag"):$({id:B(),userId:t,action:"tag.issue",payload:{id:B(),target:c.id,tagId:x}}):d("Unable to locate tags field")},onSuccess:()=>b({mode:u.DEFAULT})},{intent:w.AssignUserToTicket,mode:u.COMMAND_LINE,action:()=>{let e=K();if(f(e))return d("Unable to resolve user ID");let t=e.data,{modifier:n,inputString:o}=oe().commandMeta,r=(n||o).trim();if(!r)return d("Provide an assignee");let{selectedIndex:i,currentNode:s}=v(),a=A(s.id)[i];if(!a)return d("Invalid assign target");let l=Re(a.id,"TICKET");if(f(l))return d("Unable to assign issue in this context");let c=l.data,g=Hi(r),x;if(g)x=g.id;else{let h=B(),I=$({id:B(),userId:t,action:"create.contributor",payload:{id:h,name:r}});if(f(I))return I;x=I.data.result.id}let N=C.getFieldByTitle(c.id,"Assignees");return N?A(N.id).some(h=>h.props?.value===x)?d("Assignee already assigned"):$({id:B(),userId:t,action:"assign.issue",payload:{id:B(),target:c.id,contributor:x}}):d("Unable to locate assignees field")},onSuccess:()=>b({mode:u.DEFAULT})}];var Y=({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:o,inputString:r}}=oe();if(!t)return d("No command to confirm");if(!e&&n===ae.Invalid)return d("Invalid command");let i=go(t);lo();let s=Fo.filter(l=>e||l.systemOnly!==!0).find(l=>l.intent===i);if(!s)return vt({result:de.Fail,message:"Command not found",data:null});let a=s.action(s,{command:t,inputString:r,modifier:o});return f(a)?vt(a):(co({addToHistory:!e}),s?.onSuccess?.(),vt(a))};var At=[{intent:"exit",mode:u.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(b({mode:u.COMMAND_LINE}),k(()=>"move cancel"),Y({isForceExecutedBySystem:!0}))},{intent:"initMove",mode:u.DEFAULT,description:"[m] move init/confirm",action:()=>(b({mode:u.COMMAND_LINE}),k(()=>"move start"),Y({isForceExecutedBySystem:!0}))},{intent:"confirmMove",mode:u.MOVE,action:()=>(b({mode:u.COMMAND_LINE}),k(()=>"move confirm"),Y({isForceExecutedBySystem:!0}))}],Tt=[{intent:"movePreviousItem",mode:u.MOVE,action:()=>Me()?(b({mode:u.COMMAND_LINE}),k(()=>"move previous"),Y({isForceExecutedBySystem:!0})):d("No pending move")},{intent:"moveNextItem",mode:u.MOVE,action:()=>Me()?(b({mode:u.COMMAND_LINE}),k(()=>"move next"),Y({isForceExecutedBySystem:!0})):d("No pending move")}],Oo=[{intent:"moveToNextContainer",mode:u.MOVE,action:()=>Me()?(b({mode:u.COMMAND_LINE}),k(()=>"move to-next"),Y({isForceExecutedBySystem:!0})):d("No pending move")},{intent:"moveToPreviousContainer",mode:u.MOVE,action:()=>Me()?(b({mode:u.COMMAND_LINE}),k(()=>"move to-previous"),Y({isForceExecutedBySystem:!0})):d("No pending move")}];var ko={[M.WORKSPACE]:[...At,...Tt],[M.BOARD]:[...At,...Tt],[M.SWIMLANE]:[...At,...Tt,...Oo],[M.TICKET]:[],[M.FIELD]:[],[M.FIELD_LIST]:[],[M.TEXT]:[]};var Uo=[{intent:"addItem",mode:u.DEFAULT,description:"[n] new...",action:()=>(b({mode:u.COMMAND_LINE}),k(()=>`${p.NEW} `),m("Adding new item",null))},{intent:"Delete",mode:u.DEFAULT,description:"[d] delete",action:()=>(b({mode:u.COMMAND_LINE}),k(()=>`${p.DELETE} `),m("Deleting item",null))},{intent:"initCommandLine",mode:u.DEFAULT,description:"[:] focus command line",action:()=>(b({mode:u.COMMAND_LINE}),k(()=>""),m("Entering command line mode",null))},{intent:"confirm",mode:u.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>(D.enterChildNode(),m("Entering context",null))},{intent:"exit",mode:u.DEFAULT,description:"[q] exit context",action:()=>(logger.debug("Executing exit action"),D.enterParentNode(),m("Exiting context",null))},{intent:"navPreviousItem",mode:u.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(D.navigateToPreviousItem(),m("Navigating to previous item",null))},{intent:"navNextItem",mode:u.DEFAULT,action:()=>(D.navigateToNextItem(),m("Navigating to next item",null))},{intent:"navToPreviousContainer",mode:u.DEFAULT,action:()=>(D.navigateToPreviousContainer(),m("Navigating to previous container",null))},{intent:"navToNextContainer",mode:u.DEFAULT,action:()=>(D.navigateToNextContainer(),m("Navigating to next container",null))},{intent:"edit",mode:u.DEFAULT,action:()=>(b({mode:u.COMMAND_LINE}),k(()=>"edit"),Y())},{intent:"SetViewDense",mode:u.DEFAULT,description:"[v] view change (wide/dense)",action:()=>(b({viewMode:"dense"}),m("View set",null))},{intent:"SetViewWide",mode:u.DEFAULT,action:()=>(b({viewMode:"wide"}),m("View set",null))}];var Wo=[{intent:"viewHelp",mode:u.DEFAULT,action:()=>(b({mode:u.HELP}),m("Viewing help",null))},{intent:"exit",mode:u.HELP,action:()=>(b({mode:u.DEFAULT}),m("Exiting help",null))},{intent:"confirm",mode:u.COMMAND_LINE,action:()=>(Y(),m("Executing command",null))},{intent:"MoveCursorLeft",mode:u.COMMAND_LINE,action:()=>(tn(-1),m("Moving cursor left",null))},{intent:"MoveCursorRight",mode:u.COMMAND_LINE,action:()=>(tn(1),m("Moving cursor right",null))},{intent:"MoveCursorLeftOfWord",mode:u.COMMAND_LINE,action:()=>(nn("left"),m("Moving cursor left of word",null))},{intent:"MoveCursorRightOfWord",mode:u.COMMAND_LINE,action:()=>(nn("right"),m("Moving cursor right of word",null))},{intent:"exitCommandLine",mode:u.COMMAND_LINE,action:()=>(b({mode:u.DEFAULT}),m("Exiting command line",null))},{intent:"autoCompleteCommand",mode:u.COMMAND_LINE,action:()=>(k((e,{remainder:t})=>t?e+t:e),m("Auto-completing command",null))},{intent:"captureInput",mode:u.COMMAND_LINE,action:(e,{sequence:t})=>(k(n=>n+t),m("Capturing input",null))},{intent:"eraseInput",mode:u.COMMAND_LINE,action:()=>(so(),m("Erasing input",null))},{intent:"EraseInputWord",mode:u.COMMAND_LINE,action:()=>(ao(),m("Erasing input word",null))},{intent:"getLastCommandFromHistory",mode:u.COMMAND_LINE,action:()=>(mo(),m("Getting last command from history",null))},{intent:"getNextCommandFromHistory",mode:u.COMMAND_LINE,action:()=>(uo(),m("Getting next command from history",null))}];import Vi from"chalk";var Ze={bg:"#1a1b26",fg:"#c8d3ff",grayDark:"#2a2f45",gray:"#46507a",grayLight:"#9ea2b6",cyan:"#6ee7f0",cyanSoft:"#9ff1f7",blue:"#5b8cff",magenta:"#a78bfa",magentaSoft:"#c4b5fd",green:"#8fdc8c",yellow:"#f1c27d",red:"#ff7a90",white:"#ffffff"},y={accent:Ze.cyan,accent2:Ze.magenta,primary:Ze.white,secondary:Ze.grayDark,secondary2:Ze.grayLight};var Mt=": for command line",_o="q to exit",Ho=`${Vi.hex(y.accent)("m")} to confirm`,fn={[M.WORKSPACE]:[Mt],[M.BOARD]:[Mt],[M.BOARD+u.COMMAND_LINE]:[Mt],[M.SWIMLANE]:[Mt],[M.TICKET+u.HELP]:[_o],[M.SWIMLANE+u.HELP]:[_o],[M.TICKET]:[],[M.FIELD]:[],[M.SWIMLANE+u.MOVE]:[Ho],[M.TICKET+u.MOVE]:[Ho]};var wt=e=>e.trim().toLocaleLowerCase(),Ki=(e,t)=>{let n=C.getFieldByTitle(e,t);if(!n)return"";let o=n.props?.value;return typeof o=="string"?o:""},$i=e=>{let{tags:t}=v(),n=C.getFieldByTitle(e,"Tags");return n?F(n.id).map(o=>{let r=o.props?.value;return typeof r=="string"?t[r]?.name:void 0}).filter(o=>!!o):[]},zi=e=>{let{contributors:t}=v(),n=C.getFieldByTitle(e,"Assignees");return n?F(n.id).map(o=>{let r=o.props?.value;return typeof r=="string"?t[r]?.name:void 0}).filter(o=>!!o):[]},Vo=(e,t)=>{let n=t.value;if(!n)return!0;switch(t.target){case"title":return wt(e.title??"").includes(n);case"description":return wt(Ki(e.id,"Description")).includes(n);case"tag":return $i(e.id).map(wt).some(a=>a.includes(n));case"assignee":return zi(e.id).map(wt).some(a=>a.includes(n));default:return!0}};function Ko(e,t,n){let o=t[e];if(!o)return d("buildBreadCrumb(): current node not found");let r=[],i=o;for(;i&&(r.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let s=r[r.length-1];return!s||s.id!==n?d("buildBreadCrumb(): node is not connected to root"):(r.reverse(),m("Breadcrumb built",r))}var $o=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 Lt,gn=new Set,zo=()=>{for(let e of gn)e()},qi=e=>(gn.add(e),()=>gn.delete(e));function jo(e){let{currentNodeId:t,mode:n,rootNodeId:o,nodes:r,filters:i}=e;if(!t)return d("derive(): currentNodeId is missing");if(!o)return d("derive(): rootNode is missing");if(!r[o])return d("derive(): unable to find root node");let a=r[t];if(!a)return logger.error("Unable to derive state, currentNode not found"),d("Unable to derive state, currentNode not found");let l=Ko(t,r,o);if(f(l))return logger.error(l.message),l;let c=l.data,{context:g}=a,x=fn[g+n]??fn[g]??[],N=[...Uo,...ko[g]??[],...Wo],S=$o(N);return m("Derived successfully",{...e,currentNode:a,breadCrumb:c,availableHints:x,availableActions:N,actionIndex:S,renderedChildrenIndex:Gi(r,i)})}var v=()=>(Lt||logger.error("State not initialized. Call initWorkspaceState() first.",new Error().stack),Lt);function ho(e){let t={filters:[],tags:{},contributors:{},viewMode:"dense",mode:u.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,currentNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1},n=jo(t);return f(n)?n:(Lt=n.data,zo(),m("State initialized",null))}function J(e){let t=v(),n=e(t),o=jo(n);return f(o)?d(o.message??"Unable to update state"):(Lt=o.data,zo(),m("State updated",null))}var b=e=>J(t=>({...t,...e}));var W=()=>ji(qi,v,v),Gi=(e,t)=>{let n={};for(let o of Object.values(e))Ae(o)&&t.length>0&&!t.every(r=>Vo(o,r))||!o.parentNodeId||o.isDeleted||((!o.parentNodeId||!n[o.parentNodeId])&&(n[o.parentNodeId]=[]),n[o.parentNodeId].push(o));for(let o of Object.keys(n))n[o].sort((r,i)=>{let s=e[r.id],a=e[i.id];return!s||!a?0:s.rank.localeCompare(a.rank)});return n},A=e=>v().renderedChildrenIndex[e]??[];var D={exit(){process.exit(0)},enterChildNode(){let e=v(),t=e.currentNode,n=Math.max(0,e.selectedIndex),o=A(t.id)[n];!o||t.context==="FIELD"||D.navigate({currentNode:o,selectedIndex:A(o.id).length?0:-1})},enterParentNode(){let{currentNode:e,nodes:t}=v();if(!e.parentNodeId){logger.info("Missing parent node id");return}let n=t[e.parentNodeId];if(!n){logger.error("Parent not found");return}let o=A(n.id),r=o.findIndex(({id:s})=>s===e.id),i=o.length===0?-1:r>=0?r:0;D.navigate({currentNode:n,selectedIndex:i})},navigateToNextItem:()=>qo(1),navigateToPreviousItem:()=>qo(-1),navigateToNextContainer:()=>Go(1),navigateToPreviousContainer:()=>Go(-1),navigate:({currentNode:e=v().currentNode,selectedIndex:t})=>{b({currentNodeId:e.id,selectedIndex:t})}},qo=e=>{let t=v(),n=A(t.currentNode.id).length;if(n===0)return;let r=(Math.max(0,t.selectedIndex)+e+n)%n;D.navigate({selectedIndex:r})},Go=e=>{let{currentNode:t,nodes:n,selectedIndex:o}=v();if(!t.childNavigationAcrossParents)return;if(!t.parentNodeId){logger.error("Missing parent node id");return}let r=n[t.parentNodeId];if(!t||!r)return;let i=A(r.id),s=i.findIndex(N=>N.id===t.id);if(s<0)return;let a=i.at(s+e)??i.at(0);if(!a)return;let l=A(a.id),c=Math.max(0,l.length-1),g=Math.min(Math.max(0,o),c),x=l.length?g:-1;D.navigate({currentNode:a,selectedIndex:x})};var me="system.actor",et=Xi(),Ne=null;function Ji(){let e=Object.values(v().nodes).find(o=>o.context==="WORKSPACE");if(!e)throw new Error("No workspace found in event log");let[t]=A(e.id),[n]=t?A(t.id):[];if(logger.debug("Boot navigation target:",{workspace:e?.id,firstBoard:t?.id,firstSwimlane:n?.id}),n){let o=v().renderedChildrenIndex?.[n.id]??[];return{currentNode:n,selectedIndex:o.length>0?0:-1}}else return t?{currentNode:t,selectedIndex:0}:e?{currentNode:e,selectedIndex:0}:{currentNode:v().nodes[v().rootNodeId],selectedIndex:0}}function Yi(){let e=Ji();D.navigate(e)}function Qi(){let e=et(),t=et(),n=et(),o=et(),r=et();return[{id:ce(),userId:me,action:"init.workspace",payload:{id:e,name:"Workspace"}},{id:ce(),userId:me,action:"add.board",payload:{id:t,name:"Default",parent:e}},{id:ce(),userId:me,action:"add.swimlane",payload:{id:n,name:"Todo",parent:t}},{id:ce(),userId:me,action:"add.swimlane",payload:{id:o,name:"Review",parent:t}},{id:ce(),userId:me,action:"add.swimlane",payload:{id:r,name:"Done",parent:t}},{id:ce(),userId:me,action:"add.board",payload:{id:Et,name:"Closed",parent:e}},{id:ce(),userId:me,action:"add.swimlane",payload:{id:Ue,name:"Closed",parent:Et}},{id:ce(),userId:me,action:"lock.node",payload:{id:Et}},{id:ce(),userId:me,action:"lock.node",payload:{id:Ue}}]}function ft(){return Ne!==null}function Bo(){if(!Ne||Ne.length===0)return m("No pending default events to persist",null);let t=bt(Ne).filter(f);return t.length>0?d([$e.bold.red("Materializing failed"),"",...t.map((n,o)=>`${$e.dim.gray(`${o+1}.`)} ${$e.dim(n.message)}`),`
6
+ `].join(`
7
+ `)):(Ne=null,m("Persisted pending default events",null))}function Xo(e){let t;e.length===0?(Ne=Qi(),t=rn([...Ne])):(Ne=null,t=rn(e));let n=t.filter(f);return n.length>0?d([$e.bold.red("Materializing failed"),"",...n.map((o,r)=>`${$e.dim.gray(`${r+1}.`)} ${$e.dim(o.message)}`),`
11
8
  `].join(`
12
- `));Vs()}var br=()=>{let e=Ct();if(!($.readFile(e)!==null)){let i=nn({});if(x(i))throw new Error("Unable to create ~/.epiqrc")}let n=tn();if(x(n))throw new Error("Unable to load settings");let{preferredEditor:o,userName:r}=n.data;ze({preferredEditor:o,userName:r})};$s(`
9
+ `)):(Yi(),m("State booted successfully",null))}import{Box as yn,Text as tr}from"ink";import ze from"react";import vn from"chalk";import{Box as xn,Text as Jo}from"ink";import tt,{useEffect as Zi,useMemo as es,useState as ts}from"react";var Yo=vn.gray,ns=vn.inverse,os=vn.inverse.gray,rs={hint:"",hints:[],overlap:0,remainder:""},Zo=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),r=e.length-n.length;return e.slice(r,r+t.length)!==t?null:{start:r,end:r+t.length}},is=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let o=Zo({value:e,command:t});if(!o)return null;let i=e.slice(o.end).match(/^\s*/)?.[0].length??0,s=o.end+i;return e.slice(s,s+n.length)!==n?null:{start:s,end:s+n.length}},Qo=()=>({value:U.value,cursorPosition:U.cursorPosition,commandIsPending:U.commandIsPending,autoCompletion:U.commandMeta.autoCompletion??rs,infoMessage:U.commandMeta.infoMessage,validationStatus:U.commandMeta.validity,command:U.commandMeta.command,inputString:U.commandMeta.inputString,modifier:U.commandMeta.modifier}),ss=(e,t)=>e.value===t.value&&e.cursorPosition===t.cursorPosition&&e.commandIsPending===t.commandIsPending&&e.infoMessage===t.infoMessage&&e.autoCompletion.hint===t.autoCompletion.hint&&e.autoCompletion.overlap===t.autoCompletion.overlap&&e.autoCompletion.remainder===t.autoCompletion.remainder&&e.validationStatus===t.validationStatus&&e.command===t.command&&e.modifier===t.modifier&&e.inputString===t.inputString,er=({width:e})=>{let[t,n]=ts(Qo());Zi(()=>{let x=()=>{let S=Qo();n(h=>ss(h,S)?h:S)},N=io(x);return x(),()=>{N()}},[]);let{value:o,cursorPosition:r,infoMessage:i,commandIsPending:s,autoCompletion:a,command:l,modifier:c}=t,g=es(()=>{let x=Math.max(0,Math.min(r,o.length)),N=Zo({value:o,command:l}),S=is({value:o,command:l,modifier:c}),h=l?Yt(l):null,I=c?Yt(c):null,E=(j,q)=>{let zt=N&&q>=N.start&&q<N.end,jt=S&&q>=S.start&&q<S.end;return zt&&h?h.fg(j):jt&&I?I.bg(j):j},T=(j,q)=>{let zt=N&&q>=N.start&&q<N.end,jt=S&&q>=S.start&&q<S.end;return zt&&h?h.fgCursor(j):jt&&I?I.bgCursor(j):ns(j)},H=o.slice(0,x),ve=o[x]??" ",ye=x<o.length?o.slice(x+1):"",kr=Array.from(H).map((j,q)=>E(j,q)).join(""),Fn=T(ve,x),Bn=Array.from(ye).map((j,q)=>E(j,x+1+q)).join("");if(a.hint){let j=a.hint[a.overlap]??ve;Fn=os(j),Bn=Yo(a.remainder.slice(1)+ye)}return Yo(":")+kr+Fn+Bn},[o,r,a,l,c]);return tt.createElement(xn,{flexDirection:"column",justifyContent:"flex-start"},tt.createElement(xn,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},tt.createElement(xn,null,tt.createElement(Jo,null,g),i&&tt.createElement(Jo,{wrap:"truncate",color:s?"red":y.secondary2},` ${i} `))))};var Pt=({width:e,mode:t,availableHints:n})=>{let o=[],r=0;for(let i of n){let a=(o.length>0?" | ":"").length+i.length;if(r+a>e+2)break;o.push(i),r+=a}return ze.createElement(yn,null,t===u.COMMAND_LINE?ze.createElement(er,{width:e}):ze.createElement(yn,{flexDirection:"column",paddingX:1,borderColor:y.secondary,borderStyle:"round",width:e},ze.createElement(yn,{flexDirection:"row"},o.map((i,s)=>ze.createElement(tr,{key:i,color:y.secondary2},(s>0?" | ":"")+i)),ze.createElement(tr,null," "))))};import{Box as je,Text as nr}from"ink";import Ie from"react";var or=({width:e})=>{let t=[...v().availableActions].map(n=>n.description).filter(n=>n!==void 0).map(n=>{let[o,r]=n.split("]"),i=o?.replace("[",""),s=r?.trim();return[i,s]}).filter(n=>n[0]!==void 0&&n[1]!==void 0).sort(([n],[o])=>n.length===1&&o.length!==1?-1:n.length!==1&&o.length===1?1:n.localeCompare(o,void 0,{sensitivity:"base"}));return t.unshift(["Key(s)","Action"]),Ie.createElement(je,{flexDirection:"column",marginTop:3,borderColor:y.secondary,borderStyle:"round",width:e,minHeight:19},Ie.createElement(je,{flexDirection:"column",width:e},v().mode===u.HELP?t.map(([n,o],r)=>Ie.createElement(je,{paddingLeft:1,key:r,flexDirection:"row"},Ie.createElement(je,{key:r,flexDirection:"row",paddingBottom:r?0:1},Ie.createElement(je,{width:20,justifyContent:"flex-end"},Ie.createElement(nr,{color:r?y.accent:y.secondary},n)),Ie.createElement(je,{flexGrow:1,width:40,paddingLeft:2},Ie.createElement(nr,{color:r?y.primary:y.secondary},o))))):null))};import ar from"chalk";import{Box as Nn,Text as lr}from"ink";import ue from"react";import{Box as Cn,Text as fs}from"ink";import Xe from"react";import{Text as as}from"ink";import ds from"react";var ls=e=>e.toLowerCase().trim(),cs=(e,t=Fe)=>{let n=ls(e);return t[n]?t[n]:Oe(n)},qe=({id:e,isSelected:t})=>{let n=C.getContributor(e);if(n)return ds.createElement(as,{underline:t,color:cs(n.name)},"@"+n.name)};import{Text as ms}from"ink";import us from"react";var ps=e=>e.toLowerCase().trim(),nt=(e,t=Fe)=>{let n=ps(e);return t[n]?t[n]:Oe(n)},Ge=({id:e,isSelected:t})=>{let n=C.getTag(e);if(n)return us.createElement(ms,{underline:t,backgroundColor:nt(n.name),color:y.primary}," "+n.name+" ")};var gs=(e,t)=>e.length<=t?e:t<=1?"\u2026":e.slice(0,t-1)+"\u2026",rr=({width:e})=>{let{breadCrumb:t,currentNode:n,selectedIndex:o,viewMode:r}=v(),i=F(n.id)[o],s=Re(i?.id??n.id,"TICKET"),a=Pe(s)?s.data:void 0,l=a?.id?F(a.id):[],c=I=>{let E=l.find(T=>T.title===I);return E?F(E.id).map(T=>typeof T.props?.value=="string"?T.props.value:"").filter(T=>!!T):[]},g=c("Tags"),x=c("Assignees"),N=a?.parentNodeId?!Xt(n.id,a?.parentNodeId)&&r==="dense":!1,S=t.map((I,E)=>{let T=E===t.length-1,H=F(I.id),ve=T?H?.[o]?.title:void 0;return`${E?" / ":""}${I.title??""}${ve?` \u25B8 ${ve}`:""}`}).join(""),h=gs(S,e);return Xe.createElement(Cn,null,Xe.createElement(fs,{color:y.secondary2},h),N?g.map(I=>Xe.createElement(Cn,{key:I,paddingLeft:2},Xe.createElement(Ge,{id:I}))):null,N?x.map(I=>Xe.createElement(Cn,{key:I,paddingLeft:2},Xe.createElement(qe,{id:I}))):null)};import{Box as xs,Text as ir}from"ink";import Dt from"react";var vs=({filters:e})=>Dt.createElement(xs,{columnGap:1},Dt.createElement(ir,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:o})=>Dt.createElement(ir,{backgroundColor:"black",color:"white"},` ${n}${o}"${t}" `))),sr=Dt.memo(vs);function Rt({filters:e,hideBreadCrumb:t=!1}){let{userName:n,preferredEditor:o}=te(),r=40,i=process.stdout.columns-r-8;return ue.createElement(Nn,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},t?ue.createElement(lr,null," "):ue.createElement(Nn,{paddingLeft:1},e.length>0?ue.createElement(sr,{filters:e}):ue.createElement(rr,{width:i})),ue.createElement(Nn,{columnGap:1,paddingRight:2,"max-width":r,overflow:"hidden",justifyContent:"flex-end"},ue.createElement(dr,{icon:"@",value:n}),ue.createElement(dr,{icon:"\u276F",value:o})))}function dr({icon:e,value:t}){return ue.createElement(lr,null,ar.dim(e)+ar.hex(y.accent2)(` ${t??"-"} `))}import{Box as Hs,Text as Vs}from"ink";import rt from"react";import{Box as Ft,Text as In}from"ink";import Ee from"react";import{Text as cr}from"ink";import mr,{useEffect as ys,useState as Cs}from"react";var ur={help:["\u25B8 ","\u25B8 ","\u25B8 "],default:["\u25B8 ","\u25B8 ","\u25B8 "],move:["\u2191 ","\u2192 ","\u2193 ","\u2190 "],"command-line":["\u276F ","\u276F ","\u276F "]},z=({isSelected:e,placeholder:t=" "})=>{let{mode:n}=W(),o=ur[n]??ur.default,[r,i]=Cs(o.length-1);return ys(()=>{if(!e)return;let s=setInterval(()=>{i(a=>(a+1)%o.length)},800);return()=>clearInterval(s)},[e,o]),e?mr.createElement(cr,{color:y.accent,dimColor:r===1},o[r]):mr.createElement(cr,null,t)};function En(){let e=W(),t=e.nodes[e.rootNodeId],r=process.stdout.rows-1-3,i=process.stdout.columns||120,s=t?.id?A(t?.id):[];return Ee.createElement(Ft,{flexDirection:"column",height:r,padding:1,borderStyle:"round",borderColor:y.secondary,width:i},Ee.createElement(Ft,{padding:1,paddingTop:0,paddingBottom:0},Ee.createElement(In,null,"Select a board:")),Ee.createElement(Ft,{padding:1,flexDirection:"column"},s.map((a,l)=>{let c=e.currentNode.context==="WORKSPACE"&&e.selectedIndex===l,x=A(a.id).flatMap(({id:N})=>F(N)).length;return Ee.createElement(Ft,{key:a.id??l},Ee.createElement(In,{color:c?y.accent:y.secondary},Ee.createElement(z,{isSelected:c})),Ee.createElement(In,{color:c?y.accent:y.secondary},a.title," (",x," issues)",a.readonly?" \u{1F512}":""))})))}import{Box as Ws}from"ink";import _t from"react";import{Box as Sn,Text as bs}from"ink";import re from"react";import{Box as hn,Text as Ns}from"ink";import Bt from"react";var Ot=({children:e=[],height:t,selectedIndex:n,itemHeight:o=1,scrollByOne:r=!1})=>{if(e.length===0)return null;let i=Math.max(1,Math.floor(t)),s=Math.max(1,Math.ceil(o)),a=Math.max(1,Math.floor(i/s)),l=Math.max(0,Math.min(n,e.length-1)),c=Math.max(0,e.length-a),g=r?Math.min(c,Math.max(0,l-a+1)):Math.min(c,Math.floor(l/a)*a),x=g+a,N=e.slice(g,x),S=e.length>a,h=i,I=S?Math.max(1,Math.floor(a/e.length*h)):h,E=Math.max(0,h-I),T=Math.max(1,e.length-a),H=S?Math.floor(g/T*E):0;return Bt.createElement(hn,{flexDirection:"row",height:i,width:"100%"},Bt.createElement(hn,{flexDirection:"column",flexGrow:1,height:i},N),Bt.createElement(hn,{flexDirection:"column",width:1,height:h},Array.from({length:h}).map((ve,ye)=>Bt.createElement(Ns,{key:ye,color:S&&ye>=H&&ye<H+I?y.accent:y.secondary},S?"\u2502":" "))))};import{Box as kt,Text as Is}from"ink";import we from"react";var pr=({width:e,ticket:t,isSelected:n})=>{let o=e-14,r=dt(lt(t.title),o),i=A(t.id),s=c=>{let g=i.find(x=>x.title===c);return g?A(g.id).map(x=>typeof x.props?.value=="string"?x.props.value:"").filter(x=>!!x):[]},a=s("Tags").map(c=>C.getTag(c)).filter(c=>!!c),l=s("Assignees").map(c=>C.getContributor(c)).filter(c=>!!c);return we.createElement(kt,{borderStyle:"round",width:e-7,height:4,flexDirection:"column",borderColor:n?y.accent:y.secondary,justifyContent:"space-between"},we.createElement(kt,{borderBottom:!0},we.createElement(kt,{paddingLeft:1,flexDirection:"column"},we.createElement(Is,{color:y.primary},r))),we.createElement(kt,{flexDirection:"row",paddingLeft:1},a.map(c=>we.createElement(Ge,{key:c.id,id:c.id})),l.map(c=>we.createElement(qe,{key:c.id,id:c.id}))))};import Es from"chalk";import{Box as ot,Text as bn}from"ink";import pe from"react";var hs=(e,t)=>e.length>=t?e.slice(0,t)+"...":e,fr=({width:e,ticket:t,isSelected:n,index:o,mode:r})=>{let i=A(t.id),s=I=>{let E=i.find(T=>T.title===I);return E?A(E.id).map(T=>typeof T.props?.value=="string"?T.props.value:"").filter(T=>!!T):[]},a=s("Tags").map(I=>C.getTag(I)).filter(I=>!!I),l=s("Assignees").map(I=>C.getContributor(I)).filter(I=>!!I),c=1,g=a.length*(1+c),x=l.length*(2+c),N=a.map(I=>pe.createElement(ot,{key:I.id,paddingRight:c},pe.createElement(bn,{color:nt(I.name)},"\u25A0"))),S=l.map(I=>pe.createElement(ot,{key:I.id,paddingRight:c},pe.createElement(bn,{color:Oe(I.name)},"@"+I.name.at(0)))),h=n?y.accent:r===u.MOVE?y.secondary:y.primary;return pe.createElement(ot,{borderBottom:!0,justifyContent:"space-between"},pe.createElement(ot,null,pe.createElement(z,{isSelected:n,placeholder:Es.dim.gray(o+1+" ")}),pe.createElement(bn,{wrap:"truncate",color:h},hs(t.title,e-g-x-14))),pe.createElement(ot,null,N,S))};var Ss=({swimlane:e,isSelected:t,width:n,height:o,isDense:r,isFocused:i,listSelectedIndex:s,mode:a})=>{let{renderedChildrenIndex:l}=W(),c=l[e.id]??[],g=`${e.title} (${c.length})`,x=3,N=r?1:4,S=o-x-(r?2:1),h=re.createElement(Sn,{borderStyle:"round",borderColor:y.secondary,justifyContent:"flex-start",borderLeft:!1,borderTop:!1,borderRight:!1},re.createElement(z,{isSelected:t}),re.createElement(bs,{bold:!0,color:t?y.accent:y.primary},g," ",e.readonly?"\u{1F512}":"")),I=(E,T)=>{let H=i&&s===T;return r?re.createElement(fr,{key:E.id,index:T,width:n,ticket:E,isSelected:H,mode:a}):re.createElement(pr,{key:E.id,width:n,ticket:E,isSelected:H})};return re.createElement(Sn,{flexDirection:"column",width:n,borderStyle:"round",borderColor:t?y.accent:y.secondary,paddingRight:1,paddingLeft:1,height:o},h,re.createElement(Sn,{padding:r?1:0},c.length>0&&re.createElement(Ot,{selectedIndex:s,height:S,itemHeight:N},c.map(I)),re.createElement(z,{isSelected:i&&s===-1})))},gr=re.memo(Ss);import{Box as Mn,Text as ks}from"ink";import he,{useEffect as wn,useMemo as Ir}from"react";import fe from"chalk";import vr from"string-width";import{decodeTime as As}from"ulid";var xr=e=>{let t=Date.now()-e,n=[{label:"y",ms:1e3*60*60*24*365},{label:"mo",ms:1e3*60*60*24*30},{label:"w",ms:1e3*60*60*24*7},{label:"d",ms:1e3*60*60*24},{label:"h",ms:1e3*60*60},{label:"m",ms:1e3*60},{label:"s",ms:1e3}];for(let{label:o,ms:r}of n){let i=Math.floor(t/r);if(i>=1)return`${i}${o} ago`}return"just now"};var Ts=(e,t)=>e+" ".repeat(Math.max(0,t-vr(e))),Ms=(e,t)=>" ".repeat(Math.max(0,t-vr(e)))+e,ws=e=>(()=>{let n={"add.issue":"Created with title","assign.issue":"Assigned to","close.issue":"Closed","delete.node":"Deleted","edit.title":"Changed title to","edit.description":"Changed description","reopen.issue":"Reopened","tag.issue":"Tagged with","lock.node":"Locked node","move.node":"Moved issue"};return(r=>n[r]??(r.endsWith("e")?`${r}d`:`${r}ed`))(e)})(),Ls=e=>{switch(e.action){case"move.node":{let t=C.getNode(e.payload.parent),n=t?fe.dim.bgBlack(` ${t.title} `):"unknown",o=e.payload.pos;if(!o)return`to ${n}`;switch(o.at){case"start":return`to ${n} ${fe.dim("(to top of list)")}`;case"end":return`to ${n} ${fe.dim("(to bottom of list)")}`;case"before":return`to ${n} ${fe.dim("(up in list)")}`;case"after":return`to ${n} ${fe.dim("(down in list)")}`}}case"tag.issue":{let t=v().tags[e.payload.tagId];return t?fe.bgHex(nt(t.name))(` ${t.name} `):"unknown tag"}case"assign.issue":{let t=v().contributors[e.payload.contributor];return t?fe.bgBlack(` ${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""}},Ps=e=>{let t=xr(As(e));return fe.gray(Ms(t,8))},Ds=12,Rs=e=>{let t=e.split(".")[1]??"unknown";return Ts(`${t}`,Ds)},yr=e=>{let t=Ps(e.id),n=Rs(e.userId),o=ws(e.action),r=Ls(e),i=fe.dim("\u203A"),s=[o,r].filter(Boolean).join(" ");return`${n} ${t} ${i} ${s}`};import{Box as Ut,Text as Fs}from"ink";import ge from"react";var Cr=({selectedIndex:e,parent:t,selected:n})=>{let{currentNode:o}=W(),{title:r}=t,i=A(t.id).map(s=>{let a=typeof s.props?.value=="string"?s.props.value:"";if(r==="Assignees")return C.getContributor(a)?.id;if(r==="Tags")return C.getTag(a)?.id}).filter(s=>!!s);return ge.createElement(Ut,{alignItems:"center",paddingTop:1},ge.createElement(Ut,{minWidth:12},ge.createElement(z,{isSelected:n}),ge.createElement(Fs,{color:n?y.accent:y.secondary2},r,":")),ge.createElement(Ut,{flexDirection:"row",marginLeft:1,paddingRight:1},i.map((s,a)=>{let l=o.id===t.id&&a===e;return ge.createElement(Ut,{key:`${r}-${s}`,paddingRight:2,minHeight:1},ge.createElement(z,{isSelected:l}),r==="Assignees"?ge.createElement(qe,{isSelected:l,id:s}):r==="Tags"?ge.createElement(Ge,{isSelected:l,id:s}):null)})))};import{Box as Wt,Text as An}from"ink";import{marked as Nr}from"marked";import Bs from"marked-terminal";import xe,{useEffect as Os}from"react";var Tn=({id:e,label:t,text:n,height:o,selected:r,maxWidth:i})=>{let{selectedIndex:s,currentNode:a}=W();Nr.setOptions({renderer:new Bs});let l=N=>String(Nr.parseInline(N)).replace(/\r?\n/g,""),c=typeof n=="string"?n.split(/\r?\n|\u2028|\u2029/):[];Os(()=>{let N=[];return c.forEach((S,h)=>{let I=V.text({id:`${h}`,name:`Line ${h+1}`,parentNodeId:e,props:{value:S},readonly:!0}),E=C.createNodeAtPosition(I);Pe(E)&&N.push(E.data.id)}),()=>N.forEach(C.deleteNode)},[e,n]);let g="\u2029",x=c.map((N,S)=>{let h=a.id===e&&s===S;return xe.createElement(Wt,{key:`${e}-${S}`},xe.createElement(An,{color:h?y.primary:y.secondary2,dimColor:!h},`${S+1} `.padStart(5,"\xA0")),xe.createElement(An,{backgroundColor:h?"gray":""},l(N.length?dt(N,i-10):g)))});return xe.createElement(Wt,{flexDirection:"column",paddingTop:1},xe.createElement(Wt,null,xe.createElement(z,{isSelected:r}),xe.createElement(An,{color:r?y.accent:y.secondary2},t)),xe.createElement(Wt,{flexDirection:"row",borderStyle:"round",borderColor:y.secondary,paddingLeft:1,paddingRight:1,marginLeft:1},xe.createElement(Ot,{scrollByOne:!0,children:x,height:o-2,selectedIndex:s,itemHeight:1})))};var Us=e=>`${e}::log`,Er=({ticket:e,height:t})=>{let{selectedIndex:n,currentNode:o}=W(),r=process.stdout.columns||120,i=Ir(()=>Us(e.id),[e.id]),s=Ir(()=>[...e.log].reverse().map(yr).join(`
10
+ `),[e.log]);wn(()=>{if(C.getNode(i))return;let T={...V.field(i,"Log",e.id,{value:s}),readonly:!0,childRenderAxis:"vertical"};return C.createNodeAtPosition(T),()=>{C.deleteNode(i)}},[i,e.id]),wn(()=>{let E=C.getNode(i);E&&E.props.value!==s&&C.updateNode({...E,props:{...E.props,value:s},childRenderAxis:"vertical",readonly:!0})},[i,s]);let a=o.id===e.id,l=o.id===i||o.parentNodeId===i;wn(()=>{l&&(n>=0||D.navigate({selectedIndex:0}))},[l,n]);let c=A(e.id);if(l){let E=C.getNode(i),H=t-3;return he.createElement(Mn,{width:r,flexDirection:"column",paddingRight:1,paddingBottom:1,minHeight:t},E?he.createElement(Tn,{id:E.id,label:"Event log",text:E.props.value??"",selected:!1,maxWidth:r,height:H}):null)}let g=c.reduce((E,T)=>T.title==="Assignees"||T.title==="Tags"||T.id===i?++E:E,0),x=2,N=g*1,h=t-3-N-x,I=(E,T)=>E.title==="Assignees"||E.title==="Tags"?he.createElement(Cr,{key:E.id,parent:E,selected:T,selectedIndex:n}):E.id===i?he.createElement(Mn,{key:E.id,paddingTop:1},he.createElement(z,{isSelected:T}),he.createElement(ks,{backgroundColor:y.secondary,color:T?y.accent:y.primary}," History \u203A\u203A ")):he.createElement(Tn,{label:"Description (press e to edit)",key:E.id,id:E.id,text:E.props.value??"",selected:T,maxWidth:r,height:h});return he.createElement(Mn,{width:r,flexDirection:"column",paddingRight:1,paddingBottom:1,minHeight:t},c.map((E,T)=>I(E,a&&n===T)))};var _s=({swimlanes:e,currentNode:t,selectedIndex:n,breadCrumb:o,mode:r,viewMode:i,height:s,width:a})=>{let l=t.context,c=l===M.TICKET||l===M.FIELD_LIST||l===M.FIELD,g=l===M.BOARD||l===M.SWIMLANE,x=l===M.TICKET?t:o.find(E=>E.context===M.TICKET),N=Math.floor(a/3),S=Math.floor(a/Math.max(e.length,1)),h=Math.min(S,N),I=i==="dense";return _t.createElement(Ws,{flexDirection:"row",height:s},g&&e.map((E,T)=>{let H=t.id===E.id,ve=H?n:-1,ye=t.context===M.BOARD&&n===T;return _t.createElement(gr,{key:E.id,height:s,width:h,swimlane:E,isSelected:ye,isDense:I,isFocused:H,listSelectedIndex:ve,mode:r})}),c&&x&&_t.createElement(Er,{height:s,ticket:x}))},hr=_t.memo(_s);var Ks=({currentNode:e,selectedIndex:t,breadCrumb:n,mode:o,viewMode:r,height:i,width:s})=>{let{renderedChildrenIndex:a}=W(),l=n.find(({context:N})=>N==="BOARD"),x=i-1-3;return rt.createElement(Hs,{flexDirection:"row"},e.context==="WORKSPACE"?rt.createElement(En,null):l?rt.createElement(hr,{height:x,width:s,swimlanes:(a[l.id]??[]).filter(N=>N!==void 0&&kn(N)),currentNode:e,selectedIndex:t,breadCrumb:n,viewMode:r,mode:o}):rt.createElement(Vs,null))},br=rt.memo(Ks);import{Box as it,Text as ie}from"ink";import R from"react";var Ht=({isDone:e,command:t,value:n})=>R.createElement(it,null,R.createElement(ie,{color:y.accent,dimColor:e},e?" \u2714 ":" "),R.createElement(ie,{dimColor:e},"Type "),R.createElement(ie,{backgroundColor:y.secondary,dimColor:e}," "+t+" "),n&&R.createElement(R.Fragment,null,R.createElement(ie,{dimColor:e}," "),R.createElement(ie,{color:y.secondary,dimColor:e},"<"+n+">")));function Ln({width:e,height:t,hasUserName:n,hasPreferredEditor:o,userName:r,preferredEditor:i}){let s=n&&o,a=n?o?null:":set:editor":":set:username";return R.createElement(it,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},R.createElement(ie,{color:y.accent,bold:!0},"Welcome! \u{1F539}"),R.createElement(ie,null,"Lets get you started - its a breeze."),R.createElement(ie,{color:y.secondary2},"And remember, you can always get help with"," ",R.createElement(ie,{color:y.accent},":help"),"."),!s&&R.createElement(ie,{color:y.secondary2},a===":set:username"?"First, choose your username.":"Nice. One more step."),R.createElement(it,{flexDirection:"column"},n&&R.createElement(it,{marginBottom:1},R.createElement(Ht,{isDone:!0,command:":set:username",value:r})),!n&&R.createElement(Ht,{isDone:!1,command:":set:username"}),n&&!o&&R.createElement(Ht,{isDone:!1,command:":set:editor"}),s&&R.createElement(it,null,R.createElement(Ht,{isDone:!0,command:":set:editor",value:i}))))}var zs=({width:e,height:t})=>P.createElement(ee,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:y.secondary,rowGap:1},P.createElement(be,{color:y.accent,bold:!0},"Initialize project"),P.createElement(be,null,`This folder is not an ${$s.hex(y.accent)("epiq")} project yet.`),P.createElement(be,{color:y.primary},"To start tracking issues here, we need to initialize a new"," ",P.createElement(be,{color:y.primary,backgroundColor:y.secondary}," .epiq/ ")," ","directory in this repository."),P.createElement(ee,{marginTop:1,flexDirection:"column"},P.createElement(ee,null,P.createElement(be,{color:y.accent}," "),P.createElement(be,{color:y.primary},"Type "),P.createElement(be,{backgroundColor:y.secondary}," :init "))),P.createElement(ee,{marginTop:1},P.createElement(be,{color:y.secondary2},"(This will create the local epiq project files)")));function Pn({width:e,height:t}){let n=W(),o=n.filters;if(n.mode===u.HELP)return P.createElement(ee,{flexDirection:"column"},P.createElement(or,{width:e}));let{isSetup:r,hasPreferredEditor:i,hasUserName:s,userName:a,preferredEditor:l}=pt(),c=!r,g=r&&ft();if(c)return P.createElement(ee,{flexDirection:"column"},P.createElement(ee,{flexDirection:"column"},P.createElement(Rt,{hideBreadCrumb:!0,filters:o}),P.createElement(Ln,{height:t,width:e,hasUserName:s,hasPreferredEditor:i,userName:a??"",preferredEditor:l??""})),P.createElement(Pt,{width:e,mode:n.mode,availableHints:n.availableHints}));if(g)return P.createElement(ee,{flexDirection:"column"},P.createElement(ee,{flexDirection:"column"},P.createElement(Rt,{hideBreadCrumb:!0,filters:o}),P.createElement(zs,{height:t,width:e})),P.createElement(Pt,{width:e,mode:n.mode,availableHints:n.availableHints}));let x=Ke(v().breadCrumb??[],"BOARD");if(Pe(x)){let N=x.data.id,S=A(N).length,h=3,I=Math.floor(e/h),E=Math.floor(e/Math.max(S,1));e=Math.min(E,I)*Math.max(S,h)}return P.createElement(ee,{flexDirection:"column"},P.createElement(ee,{flexDirection:"column"},P.createElement(Rt,{filters:o}),P.createElement(br,{width:e,height:t,currentNode:n.currentNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:n.viewMode,mode:n.mode})),P.createElement(Pt,{width:e,mode:n.mode,availableHints:n.availableHints}))}import{Box as Le,Text as Se}from"ink";import _,{useEffect as js,useMemo as qs,useState as Gs}from"react";var Xs=["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ","\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557","\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551","\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551\u2584\u2584 \u2588\u2588\u2551","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D","\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2580\u2580\u255D "];function Js(e,t,n){return Math.min(n,Math.max(t,e))}function Ys(e,t){return _.createElement(Se,null,_.createElement(Se,{color:t%2===0?"cyan":"blue",bold:!0},e.slice(0,14)),_.createElement(Se,{color:t%2===0?"cyan":"blue",bold:!0},e.slice(14)))}function Qs(e,t=28){if(e>=1)return"\u2588".repeat(t);let n=Math.floor(e*(t-1));return Array.from({length:t},(o,r)=>{let i=Math.abs(r-n);return i===0?"\u2588":i===1?"\u2593":i===2?"\u2592":i===3?"\u2591":r<n?"\u2500":"\xB7"}).join("")}function Dn({durationMs:e=3e3,slogan:t="Never leave the command line"}){let n=Math.max(1,e),[o,r]=Gs(0);js(()=>{let l=Date.now(),c=setInterval(()=>{let g=Date.now()-l;if(g>=n){r(n),clearInterval(c);return}r(g)},33);return()=>clearInterval(c)},[n]);let i=Js(o/n,0,1),s=qs(()=>Qs(i,28),[i]),a=`${Math.round(i*100)}%`;return _.createElement(Le,{flexDirection:"column",alignItems:"center",justifyContent:"center",paddingX:4,paddingY:1},_.createElement(Le,{flexDirection:"column",minWidth:42},_.createElement(Le,{flexDirection:"column",marginBottom:1},Xs.map((l,c)=>_.createElement(Le,{key:c,justifyContent:"center"},Ys(l,c)))),_.createElement(Le,{justifyContent:"center",marginBottom:1},_.createElement(Se,{color:"gray"},t)),_.createElement(Le,{justifyContent:"center",marginBottom:1},_.createElement(Se,{color:"cyan"},s.slice(0,10)),_.createElement(Se,{color:"blue"},s.slice(10,18)),_.createElement(Se,{color:"magenta"},s.slice(18))),_.createElement(Le,{justifyContent:"center",marginBottom:1},_.createElement(Se,{color:"gray"},a))))}var Zs={userId:"",userName:"",preferredEditor:""},Sr=()=>{let e=St();if(!(X.readFile(e)!==null)){let s=un(Zs);if(f(s))throw new Error("Unable to create ~/.epiqrc")}let n=mn();if(f(n))throw new Error("Unable to load settings");let{preferredEditor:o,userName:r,userId:i}=n.data;return!r||!i?d("User name or ID not configured in ~/.epiqrc"):Ye({preferredEditor:o,userName:r,userId:i})};import ea from"readline";var Vt,Kt,se,Ar=async e=>{if(e.ctrl&&e.name==="c")return D.exit();let{actionIndex:t,mode:n}=v(),o=fo(e,n);if(!o)return;let r=t[n]?.[o];if(r?.action)try{await r.action(r,e)}catch(i){logger.error(i)}},ta=()=>async function(t,n){n.name!=="escape"&&(se&&(clearTimeout(se),se=void 0),await Ar(n))},na=()=>async function(t){if(t.length===1&&t[0]===27){se&&clearTimeout(se),se=setTimeout(()=>{Ar({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),se=void 0},25);return}se&&(clearTimeout(se),se=void 0)};function Tr(){Vt&&process.stdin.removeListener("keypress",Vt),Kt&&process.stdin.removeListener("data",Kt),Vt=ta(),Kt=na(),ea.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",Kt),process.stdin.on("keypress",Vt)}import st from"fs";import wr from"path";import oa from"util";var Lr=process.env.IS_LOCAL==="true",Mr=1e3,Pr=(e=process.cwd())=>wr.join(_e(e),".epiq","log","epiq.log");function ra(e=process.cwd()){if(!Lr)return;let t=Pr(e);if(!st.existsSync(t))return;let o=st.readFileSync(t,"utf8").split(`
11
+ `);if(o[o.length-1]===""&&o.pop(),o.length<=Mr)return;let r=o.slice(-Mr).join(`
12
+ `)+`
13
+ `;st.writeFileSync(t,r,"utf8")}function Rn(e,t,n=!1,o=process.cwd()){if(!Lr)return;let r=Pr(o),i=oa.format(...t),s=new Date,l=`[${n?s.toISOString().slice(11,19):s.toISOString()}] ${e} ${i}
14
+ `;st.mkdirSync(wr.dirname(r),{recursive:!0}),st.appendFileSync(r,l,"utf8"),ra(o)}var ia={info(...e){Rn("[Info]",e,!1)},debug(...e){Rn("->",e,!0)},error(...e){Rn("[Error]",[...e,new Error().stack],!1)}};globalThis.logger=ia;aa(`
13
15
  View board in directory:
14
16
  $ epiq
15
17
 
16
18
  Init project in directory:
17
19
  $ epiq --init "Project Name"
18
- `,{importMeta:import.meta,flags:{init:{type:"string"}}});var Bt=process.stdout.columns||120,kt=process.stdout.rows||20,zs=5e3,js=600,Ne=null;function Gs(e){return new Promise(t=>setTimeout(t,e))}function qs(){if(!Ne){Ne=Sr(et.createElement(Qe,{width:Bt,height:kt}));return}Ne.rerender(et.createElement(Qe,{width:Bt,height:kt}))}function Xs(e){if(!Ne){Ne=Sr(et.createElement(Dt,{durationMs:e}));return}Ne.rerender(et.createElement(Dt,{durationMs:e}))}async function Js(){br();let e=Vn(),n=e.length===0?zs:js;n>0&&Xs(n);let o=Date.now();Ar(e);let r=Date.now()-o,i=Math.max(0,n-r);i>0&&await Gs(i),qs(),Er()}process.stdout.on("resize",()=>{Bt=process.stdout.columns||120,kt=process.stdout.rows||20,Ne&&Ne.rerender(et.createElement(Qe,{width:Bt,height:kt}))});(async()=>(console.clear(),await Js()))();
20
+ `,{importMeta:import.meta,flags:{init:{type:"string"}}});var da=2e3,la=600,Rr=process.stdout.columns||120,Fr=process.stdout.rows||20,$t=null,ca=e=>new Promise(t=>setTimeout(t,e)),Br=e=>{if(!$t){$t=sa(e);return}$t.rerender(e)},Or=()=>{Br(Dr.createElement(Pn,{width:Rr,height:Fr}))},ma=e=>{Br(Dr.createElement(Dn,{durationMs:e}))},ua=()=>{let e=So();if(f(e)){if(e.message.includes("No events found"))return logger.info("No events found, starting with empty state"),[];throw new Error(e.message)}return e.data},pa=e=>{let t=Xo(e);if(f(t))throw new Error(`Failed to boot state: ${t.message}`)};async function fa(){Sr();let e=ua(),n=e.length===0?da:la;n>0&&ma(n);let o=Date.now();pa(e);let r=Date.now()-o,i=Math.max(0,n-r);i>0&&await ca(i),Or(),Tr()}process.stdout.on("resize",()=>{Rr=process.stdout.columns||120,Fr=process.stdout.rows||20,$t&&Or()});(async()=>(console.clear(),await fa()))();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "EPIQ - CLI based issue tracker",
package/readme.md CHANGED
@@ -3,13 +3,13 @@
3
3
  **CLI-native issue tracker** — powered by Git.
4
4
 
5
5
  ```
6
- '███████╗██████╗ ██╗ ██████╗ '
7
- '██╔════╝██╔══██╗██║██╔═══██╗'
8
- '█████╗ ██████╔╝██║██║ ██║'
9
- '██╔══╝ ██╔═══╝ ██║██║▄▄ ██║'
10
- '███████╗██║ ██║╚██████╔╝'
11
- '╚══════╝╚═╝ ╚═╝ ╚═══▀▀╝ '
12
- 🫡 Never leave your editor!
6
+ '███████╗██████╗ ██╗ ██████╗ '
7
+ '██╔════╝██╔══██╗██║██╔═══██╗'
8
+ '█████╗ ██████╔╝██║██║ ██║'
9
+ '██╔══╝ ██╔═══╝ ██║██║▄▄ ██║'
10
+ '███████╗██║ ██║╚██████╔╝'
11
+ '╚══════╝╚═╝ ╚═╝ ╚═══▀▀╝ '
12
+ 🫡 Never leave your editor!
13
13
  ```
14
14
 
15
15
  ## Why epiq?
@@ -76,7 +76,3 @@ What epiq brings:
76
76
  - Navigation-first UI — fast keyboard-driven workflow
77
77
  - Markdown descriptions — shareable, human-readable boards
78
78
  - Extensible command system — built with automation in mind
79
-
80
- ---
81
-
82
- ## What it looks like