epiq 1.3.2 → 1.3.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.
- package/dist/gui/main.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/gui/main.js
CHANGED
|
@@ -24914,7 +24914,7 @@ var User = ({
|
|
|
24914
24914
|
);
|
|
24915
24915
|
|
|
24916
24916
|
// source/version.ts
|
|
24917
|
-
var EPIQ_VERSION = "1.3.
|
|
24917
|
+
var EPIQ_VERSION = "1.3.3";
|
|
24918
24918
|
|
|
24919
24919
|
// source/gui/client/components/Header.tsx
|
|
24920
24920
|
var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
|
package/dist/index.js
CHANGED
|
@@ -55,7 +55,7 @@ ${m}
|
|
|
55
55
|
|
|
56
56
|
${c}
|
|
57
57
|
`,ii.writeFileSync(t,n,"utf8"),oe.info(`Added ${s.join(", ")} to .gitignore (epiq local state)`),l("Local epiq paths ignored",!0)};var vg=async e=>{let t=await _({cwd:e,args:["status","--porcelain"]});return d(t)?t:l("Checked git diff",t.value.stdout.trim().length>0)},ee=(e,t)=>a(`[${e}] ${t}`),Nc=async()=>{W("");let e=vn(),t=await dt(process.cwd());if(d(t))return ee(1,t.message);let n=t.value,r=await Fr(n);if(d(r))return ee(2,r.message);if(r.value)return ee(2,`Cannot initialize Epiq while a git operation is in progress: ${r.value}`);let o=await vg(n);if(d(o))return ee(2.5,o.message);if(o.value)return ee(3,"Cannot initialize Epiq with uncommitted changes. Commit or stash your changes first.");if(ls(n))return ee(4,"Epiq project already initialized");let s=Ot();if(!s.isSetupDone||!s.userName)return ee(5,"Missing Epiq user configuration (userId / userName). Run setup first.");let i=K(),c=i.userName,u=i.userId;if(!u||!c)return ee(5,"Missing Epiq user id");let m=e.stateBranch,p=await Ur({repoRoot:n,branch:m});if(d(p))return ee(6,p.message);if(p.value)return ee(6,`State branch already exists: ${m}`);let f=await Is({repoRoot:n,stateBranchName:m});if(d(f))return ee(6,f.message);let b=$r();if(d(b))return ee(7,b.message);let N=Cc.join(_r(),e.projectId),S=await en({repoRoot:n,stateBranchRoot:N,stateBranchName:m});if(d(S))return ee(8,S.message);let R=Cc.join(N,".epiq");yg.mkdirSync(R,{recursive:!0});let M=td({userId:u,userName:c});if(d(M))return ee(9,M.message);for(let as of M.value){let Li=eo({event:as,rootDir:N});if(d(Li))return ee(9,Li.message)}let U=await Wr({stateBranchRoot:N,eventFileName:on({userId:u,userName:c})});if(d(U))return ee(10,U.message);let j=await xn({cwd:N,message:"[epiq:init]"});if(d(j))return ee(10,j.message);let D=await Ec(n);if(d(D))return ee(11,D.message);let z=Ui({repoRoot:n,fileContents:e});if(d(z))return ee(12,z.message);let $=await de.stage({cwd:n,pathspec:[".epiq/project.json",".gitignore"]});if(d($))return ee(13,$.message);let P=await de.commit({cwd:n,message:"[epiq:init-project]"});if(d(P))return ee(13,P.message);let O="Project initialized!",Ge=await _({cwd:n,args:["push","-u","origin","HEAD"]});d(Ge)&&(O+=` Warn: [init:14] ${Ge.message}`);let Ne=await Jn({repoRoot:n,stateBranchRoot:N});d(Ne)&&(O+=` Warn: [init:15] ${Ne.message}`);let ue=Ut(M.value).filter(d);if(ue.length>0)return ee(16,ue.map(as=>as.message).join(`
|
|
58
|
-
`));let ce=Je();if(d(ce))return ee(16,ce.message);let{rootNodeId:$n,nodes:Hn}=ce.value,Pi=Hn[$n];return Pi?(T.navigate({contextNode:Pi,selectedIndex:0}),E({hasProjectDefinition:!0,mode:y.DEFAULT}),l(O,null)):ee(16,"Unable to resolve initialized root node")};import{ulid as xg}from"ulid";import{ulid as hg}from"ulid";var Sc=null,Kt=()=>structuredClone(Sc),vr=e=>{Sc=e},Ac=()=>{let{contextNode:e,selectedIndex:t}=g(),r=q(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},ai=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q(t).filter(o=>o.id!==e);return to(r,n)},Rc=({id:e,parentId:t,position:n={at:"end"}})=>{let r=se();if(d(r))return a("Unable to resolve user ID");let o=ai({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:hg(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Tc=e=>{vr(e);let t=Bt(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function di(e){let t=Ac();if(d(t))return t;let{contextNode:n,nodes:r}=g();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=q(o.id),i=s.findIndex(({id:m})=>m===n.id);if(i<0)return a("Current node not found among siblings");let c=s[i+e];if(!c)return a("Missing sibling node");let u=Rc({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Tc(u.value)}function ci(e){let t=Ac();if(d(t))return t;let{contextNode:n,selectedIndex:r}=g(),s=q(n.id)[r+e];if(!s)return a("Missing sibling node");let i=Rc({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Tc(i.value)}var wc=()=>{let e=Kt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=g().nodes[n];if(!r)return a("Move parent not found");let o=q(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},To=(e,t="Moved preview")=>{if(d(e))return e;let n=wc();return d(n)?n:(E({mode:y.MOVE}),l(t,null))},Mc=async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=Y().commandMeta,{contextNode:n,selectedIndex:r}=g(),o=q(n.id)[r];if(!o)return E({mode:y.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let s=q(o.parentNodeId),i=s.findIndex(({id:f})=>f===o.id);if(i===-1)return a("Target not found among siblings");let c=s[i-1],u=s[i+1],m=u!=null?{at:"before",sibling:u.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=ai({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(vr({id:xg(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),E({mode:y.MOVE}),l("Move initialized",null))}if(t==="next")return To(ci(1));if(t==="previous")return To(ci(-1));if(t==="to-next")return To(di(1));if(t==="to-previous")return To(di(-1));if(t==="confirm"){let s=Kt();if(!s)return a("No pending move to confirm");let i=await at();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=wc();return d(u)?u:(vr(null),E({mode:y.DEFAULT}),l("Moved item",null))}return t==="cancel"?(vr(null),E({mode:y.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Mo}from"ulid";import{monotonicFactory as bg,ulid as Ig}from"ulid";var Eg=bg(),wo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Eg();return l("Created issue events",[{id:Ig(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Pc=async(e,t)=>{let n=se();if(d(n))return a("Unable to resolve user ID");let r=await at();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=g(),u=m=>{let p=B([m],o);if(d(p))return p;let f=I.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let b=I.getNode(f.parentNodeId);return b?(T.navigate({contextNode:b,selectedIndex:I.getSiblings(f.parentNodeId).findIndex(({id:N})=>N===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let f=Sn(p.id,n.value,o);return d(f)?f:u({id:Mo(),action:"add.board",payload:{id:Mo(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Le(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Sn(m.value.id,n.value,o);return d(p)?p:u({id:Mo(),action:"add.swimlane",payload:{id:Mo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=G(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Le(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let f=Sn(p.id,n.value,o);if(d(f))return f;let b=wo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(b))return b;let N=b.value,S=B([...N],o);if(d(S))return S;if(!S.value[0])return a("Issue creation failed");let U=N.find(j=>j.action==="add.issue")?.payload.id;return U?(T.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===U)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Po=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=g(),s=_a(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=Gt();if(d(u))return u;let p=Ut(i).filter(d);if(p.length>0)return Gt(),E(o),a(p.map(b=>b.message).join(", "));let f=g().nodes[e];return f?(T.navigate({contextNode:f,selectedIndex:r}),l("",{unappliedEvents:c})):(Gt(),E(o),a("Board did not exist at that date"))};var Cg=20,Ng=16,Sg=150,Lo=null,ko=null;var fn=()=>{Lo!==null&&(clearInterval(Lo),Lo=null),ko!==null&&(clearTimeout(ko),ko=null)},Lc=()=>{fn(),E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Ag=e=>{let t=[],n=0;for(let o=0;o<e.length;o++){let s=o===0?0:Math.max(0,e[o]-e[o-1]);n+=Math.sqrt(s),t[o]=n}let r=n;return t.map((o,s)=>r>0?o/r:(s+1)/e.length)},kc=({events:e,startTime:t,durationMs:n})=>{fn();let r=e.length,o=e.map(f=>Nn(f)??t),s=o[r-1]??Date.now(),i=Ag(o),c=Math.max(1,Math.round(n*Cg/1e3)),u=Math.max(Math.round(n/c),Ng),m=0,p=0;E({mode:y.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),Lo=setInterval(()=>{m++;let f=m/c,b=[],N;for(;p<r&&i[p]<=f;){let R=e[p],M=Bt(R);if(d(M)){Lc();return}b.push(...ws(R)),N=R,p++}if(p>=r||m>=c){for(;p<r;p++){let M=Bt(e[p]);if(d(M))break}let R=g().replay;E({unappliedEvents:[],replay:R&&{...R,progress:1,appliedCount:r}}),fn(),ko=setTimeout(Lc,Sg);return}let S=g().replay;E({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:N?Nn(N)??S?.currentTime??t:S?.currentTime??t,currentLabel:N?La(N):S?.currentLabel??"",flashNodeIds:N?[...new Set(b)]:S?.flashNodeIds??[]}})},u)};var Dc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta;if(fn(),r==="now"){let c=Et(n.value);if(d(c))return a(c.message);let u=Gt();if(d(u))return u;let p=Ut(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=g().eventLog.at(-1),u=Nn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=g().unappliedEvents.at(0),u=Nn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=cn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Po({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(E({mode:y.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var Fc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta,{dateInput:s,durationInput:i}=uo(r,o);if(fn(),g().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=cn(s);if(!c)return a("Invalid replay date");let u=i?lo(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=g(),f=Po({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:b}=f.value;return b.length===0?(Gt(),E(p),l("Nothing to replay from that point",!0)):(kc({events:b,startTime:m,durationMs:u}),l("Replaying board history",!0))};import Tg from"zod";var Bc=()=>{let e=Y().commandMeta.inputString,t=Tg.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=Ze({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),E({mode:y.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Uc=()=>{let e=Y().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=dd(e),n=Ze({autoSync:t});return d(n)?n:(Fe({autoSync:t}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Oc=()=>{let e=Y().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Ze({logLevel:e});return d(n)?n:(Fe({logLevel:e}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};import{spawn as wg}from"node:child_process";var Mg=()=>{switch(process.platform){case"darwin":return{command:"pbcopy",args:[]};case"win32":return{command:"clip",args:[]};default:return process.env.WAYLAND_DISPLAY?{command:"wl-copy",args:[]}:{command:"xclip",args:["-selection","clipboard"]}}},_c=async e=>new Promise(t=>{let{command:n,args:r}=Mg();try{let o=wg(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?l("Copied to clipboard",null):a(`Clipboard tool failed (${n})`))),o.stdin.on("error",()=>{}),o.stdin.write(e),o.stdin.end()}catch{t(a(`Clipboard tool not available (${n})`))}});var hr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await _c(e);return d(n)?n:l(`Copied ${t} to clipboard`,null)},$c=async e=>{let{breadCrumb:t,selectedNode:n}=g(),r=ir({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case pe.REF:return hr(Ue(o.id),"ref");case pe.TITLE:return hr(o.title,"title");case pe.DESCRIPTION:return r?hr(r.props?.description??"","description"):a("No issue in scope");case pe.TAGS:{if(!r)return a("No issue in scope");let s=_t(r).map(({name:i})=>i);return hr(s.join(", "),"tags")}case pe.ASSIGNEES:{if(!r)return a("No issue in scope");let s=$t(r).map(({name:i})=>i);return hr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var Hc=async()=>{W(""),E({mode:y.DEFAULT});let e=Je();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await oo();return d(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:y.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Pg=e=>e.action==="add.issue.comment",Wc=e=>Object.values(g().tags).find(t=>t.name===e),jc=e=>Object.values(g().contributors).find(t=>t.name===e),wt=async()=>{let e=await at();return d(e)?e:l("Resolved persist root",e.value)},Do=[{systemOnly:!0,intent:w.Move,description:"Internal move-state command",mode:y.COMMAND_LINE,action:Mc},{intent:w.Delete,description:"Delete the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await wt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=A(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!A(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Pg).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:we(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:we(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:y.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Y().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ie(x.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return he(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:y.DEFAULT})),l("Filter updated",null)}},{intent:w.ViewHelp,description:"Open the help screen",mode:y.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:y.HELP}),l("Viewing help",null)}},{intent:w.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!A(r))return a("Cannot close in this context");let o=g().nodes[me];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await wt();if(d(s))return s;let i=s.value,c=sn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:we(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):It(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=g().nodes[me];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!A(s))return a("Target node is not issue");let c=Ao(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await wt();if(d(m))return m;let p=m.value,f=sn(u.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let b=B([{id:we(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:f.value},...e.value}],p);return d(b)?b:l("Issue reopened",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Init,description:"Initialize Epiq in the current git repository",mode:y.COMMAND_LINE,action:Nc},{intent:w.NewItem,description:"Create a new board, swimlane, or issue",mode:y.COMMAND_LINE,action:Pc,onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Rename,description:"Rename the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=qd();if(!o)return a("Provide a title");let s=await wt();return d(s)?s:B([{id:we(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UntagTicket,description:"Remove a tag from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Wc(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!A(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(o.id))return a("Issue is not tagged with that tag");let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.TagTicket,description:"Add or create a tag on the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=g();if(!o)return a("Invalid tag target");let s=It(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!A(i))return a("Target node is not issue");let c=await wt();if(d(c))return c;let u=Wc(r),m=u?.id??we();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:we(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:we(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.AssignUserToTicket,description:"Assign a user to the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=g(),i=G(s.id)[o];if(!i)return a("Invalid assign target");let c=It(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!A(u))return a("Target node is not issue");let m=await wt();if(d(m))return m;let p=jc(r),f=p?.id??we();return(u.props.assignees??[]).includes(f)?a("Assignee already assigned"):B([...p?[]:[{id:we(),action:"create.contributor",payload:{id:f,name:r},...e.value}],{id:we(),action:"add.issue.assignee",payload:{id:u.id,assignee:f},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=jc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!A(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(o.id))return a(`Issue is not assigned to "${r}"`);let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Comment,description:"Add a comment to the selected issue",mode:y.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>Pn)return a(`Cannot exceed ${Pn} characters`);let r=se();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=g(),i=Le([...o,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let u=c.context==="TICKET"?l("Resolved ticket",c):It(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!A(m))return a("Target node is not issue");let p=await wt();return d(p)?p:B([{id:we(),action:"add.issue.comment",payload:{id:we(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Sync,description:"Pull, commit, and push Epiq state",mode:y.COMMAND_LINE,action:Hc},{intent:w.Peek,description:"View board state at another point in time",mode:y.COMMAND_LINE,action:Dc},{intent:w.Replay,description:"Replay board history forward from a point in time",mode:y.COMMAND_LINE,action:Fc},{intent:w.Export,description:"Export the current board layout to markdown",mode:y.COMMAND_LINE,action:async()=>{let e=await yc();return d(e)?e:(E({mode:y.DEFAULT}),l("Export successful",!0))}},{intent:w.Exit,description:"Exit the application",mode:y.COMMAND_LINE,action:async()=>(T.exit(),l("Exit successful",!0))},{intent:w.Edit,description:"Edit title or description",mode:y.COMMAND_LINE,action:async(e,t)=>Ic(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:y.COMMAND_LINE,action:async(e,t)=>$c(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:y.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case ne.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??we();if(!i||!c)return a("Unable to resolve user name or id");let u=Ze({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(Fe({userName:i,userId:c}),E({mode:y.DEFAULT}),l(`Username set to "${i}"`,null))}case ne.EDITOR:{if(!n)return a("No editor provided");let r=Ze({preferredEditor:n});return d(r)?r:(Fe({preferredEditor:n}),E({mode:y.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case ne.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Ze({viewMode:n});return d(r)?r:(Fe({viewMode:n}),E({mode:y.DEFAULT}),l(`View set to "${n}"`,null))}case ne.AUTOSYNC:return Uc();case ne.LOG_LEVEL:return Oc();case ne.SYNC_DEBOUNCE_MS:return Bc();case ne.ATTACHMENT_MAX_KB:return Td();default:return a("Unknown config command")}}},{intent:w.Coffee,description:"Sponsor the development of Epiq!",mode:y.COMMAND_LINE,action:()=>{let e=Y().commandMeta.modifier;return e==="custom"?yr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):yr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var Lg=new Set(["peek","replay","filter","view-help","yank"]),yt=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Y();if(!t)return a("No command to confirm");if(!e&&n===pt.Invalid)return a("Invalid command");let s=ho(t);jd();let{readOnly:i}=g();if(i&&!Lg.has(s))return ur({status:Pt.Fail,message:"Command not available in readonly state",value:null});let c=Do.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return ur({status:Pt.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return ur({status:Pt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?ur(u):(Vd({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&io(),u)};var Fo=[{intent:h.Exit,mode:y.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:y.COMMAND_LINE}),W("move cancel"),yt({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:y.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:y.COMMAND_LINE}),W("move start"),yt({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:y.MOVE,action:()=>(E({mode:y.COMMAND_LINE}),W("move confirm"),yt({isForceExecutedBySystem:!0}))}],Bo=[{intent:h.MovePreviousItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move next"),yt({isForceExecutedBySystem:!0})):a("No pending move")}],Vc=[{intent:h.MoveToNextContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-next"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")}];var Kc={[L.WORKSPACE]:[...Fo,...Bo],[L.BOARD]:[...Fo,...Bo],[L.SWIMLANE]:[...Fo,...Bo,...Vc],[L.TICKET]:[],[L.FIELD]:[],[L.FIELD_LIST]:[],[L.TEXT]:[],[L.COMMENT]:[]};import kg from"node:fs";import Dg from"node:path";var Gc=e=>{let t=Ye(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=Mn(e.hash,e.ext),o=Dg.join(Kn(n.value),r);return kg.existsSync(o)?(yr(o),l(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var zc=()=>{W("");let{pendingNavTarget:e}=jt();E({mode:y.DEFAULT}),e&&T.navigate(e),Vt({pendingNavTarget:void 0})},qc=[{intent:h.ExitCommandLine,mode:y.HELP,action:()=>(zc(),l("Exiting help",null))},{intent:h.Exit,mode:y.HELP,action:()=>(zc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:y.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:y.HELP,action:()=>(T.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:y.HELP,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:y.HELP,action:()=>(T.navigateToNextContainer(),l("Navigating to next help container",null))}];var Fg=e=>{E({mode:y.COMMAND_LINE});let{pendingNavTarget:t}=jt();t&&T.navigate(t),Vt({pendingNavTarget:void 0}),W(`${e} `)},Yc=()=>{W("");let{pendingNavTarget:e}=jt();e&&T.navigate(e),Vt({pendingNavTarget:void 0}),E({mode:y.DEFAULT})},Xc=[{intent:h.InitCommandPalette,mode:y.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:y.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:y.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!kt(e))return a("Command only applicable on text nodes");if(e.props.disabled)return a("Command is not available in this context");let t=e.title;return t?(Fg(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:y.PALETTE,action:()=>(Yc(),l("Exiting palette",null))},{intent:h.Exit,mode:y.PALETTE,action:()=>(Yc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:y.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.PALETTE,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.PALETTE,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.PALETTE,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Jc=[...qc,...Xc,{intent:h.AddItem,mode:y.DEFAULT,description:"[n] new...",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:y.DEFAULT,description:"[d] delete",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:y.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:y.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:y.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!q(e?.id??"")?.length){let r=e?I.getAttachment(e.id):void 0;if(r)return Gc(r);if(e?.title===J.DESCRIPTION)return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===J.ASSIGNEES)return E({mode:y.COMMAND_LINE}),W(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===J.TAGS)return E({mode:y.COMMAND_LINE}),W(`${x.TAG} `),l("Propose command",!0);if(t.title===J.DESCRIPTION&&e?.context==="TEXT")return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0)}return T.enterChildNode(),l("Entering context",null)}},{intent:h.Yank,mode:y.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=g(),t=e?.title===J.DESCRIPTION?pe.DESCRIPTION:e?.title===J.TAGS?pe.TAGS:e?.title===J.ASSIGNEES?pe.ASSIGNEES:pe.REF,r=ie(x.YANK).includes(t)?t:pe.REF;return E({mode:y.COMMAND_LINE}),W(`${x.YANK} ${r}`),l("Propose command",!0)}},{intent:h.EditTitle,mode:y.DEFAULT,description:"[r] rename title",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:y.DEFAULT,description:"[e] edit description",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:y.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:y.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.DEFAULT,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.DEFAULT,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.DEFAULT,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Bg=500,Ug=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Qc=e=>{let t=Ug(e);t&&vo(n=>(n+t).slice(0,Bg))};var Og=[y.COMMAND_LINE,y.PALETTE],_g=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(Ys(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(Ys(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Xs("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Xs("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(vo((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=g().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(Qc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>(Hd(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(Wd(),l("Erasing input word",null))}],Zc=[{intent:h.Confirm,mode:y.COMMAND_LINE,action:()=>(yt(),l("Executing command",null))},{intent:h.ViewHelp,mode:y.DEFAULT,action:()=>(E({mode:y.HELP}),l("Viewing help",null))},...Og.flatMap(_g),{intent:h.ExitCommandLine,mode:y.COMMAND_LINE,action:()=>(E({mode:y.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Kd(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Gd(),l("Getting next command from history",null))}];import nl from"chalk";var Uo=nl.dim.hex(v.secondary2)(": for command line"),el="q to exit",tl=`${nl.hex(v.accent)("m")} to confirm`,li={[L.WORKSPACE]:[Uo],[L.BOARD]:[Uo],[L.BOARD+y.COMMAND_LINE]:[Uo],[L.SWIMLANE]:[Uo],[L.TICKET+y.HELP]:[el],[L.SWIMLANE+y.HELP]:[el],[L.TICKET]:[],[L.FIELD]:[],[L.SWIMLANE+y.MOVE]:[tl],[L.TICKET+y.MOVE]:[tl]};var xr=e=>e.trim().toLocaleLowerCase(),$g=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Hg=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},rl=(e,t)=>{let n=xr(t.value);if(!n)return!0;switch(t.target){case"title":return xr(e.title??"").includes(n);case"description":return xr(e.props.description??"").includes(n);case"tag":return $g(e).map(xr).some(o=>o.includes(n));case"assignee":return Hg(e).map(xr).some(o=>o.includes(n));case"ref":return Ia(e.id,t.value);default:return!0}};function ol(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],s=r;for(;s&&(o.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=o[o.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),l("Breadcrumb built",o))}var sl=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 gn,ui,mi=new Set,il=()=>{for(let e of mi)e()},jg=e=>(mi.add(e),()=>mi.delete(e));function al(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let c=o[t];if(!c)return a("Unable to derive state, contextNode not found");let u=ol(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,f=li[p+n]??li[p]??[],b=[...Jc,...Kc[p]??[],...Zc],N=sl(b),S=Vg(o,s),R=S[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:b,actionIndex:N,selectedNode:R,renderedChildrenIndex:S})}var g=()=>{if(!gn)throw new Error("State not initialized. Call initWorkspaceState() first.");return gn},Je=()=>gn?l("Retrieved state",gn):a("State not initialized. Call initWorkspaceState() first.");function nr(e){ui=e;let t=Ye(process.cwd()),n=!1;if(!d(t)){let s=Lt(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:y.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],replay:null,timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{},attachments:{}},o=al(r);return d(o)?o:(gn=o.value,il(),l("State initialized",null))}function he(e){let t=g(),n=e(t),r=al(n);return d(r)?a(r.message??"Unable to update state"):(gn=r.value,il(),l("State updated",null))}var E=e=>he(t=>({...t,...e}));var H=()=>Wg(jg,g,g),Vg=(e,t)=>{let n={};for(let r of Object.values(e))A(r)&&t.length>0&&!t.every(o=>rl(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,s)=>{let i=e[o.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},G=e=>g()?.renderedChildrenIndex[e]??[],Gt=()=>ui?nr(ui):a("Cannot reset state: no initial workspace found"),Rn=()=>gn!==void 0;var pi=e=>{Rn()&&(E({syncStatus:e}),tn({type:"sync-status",payload:e}))},Oo=(e="Syncing...")=>{pi({status:"syncing",msg:e})},_o=(e="Synced")=>{pi({status:"synced",msg:e})},fi=e=>{pi({status:"failed",msg:e})},Qe=e=>(fi(e),a(e));import{decodeTime as ZL}from"ulid";var Kg=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=X("getRepoRootDir",await dt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=X("getStateBranchRoot",Pe({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=X("ensureInitialCommit",await na(r));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:r,stateBranchRoot:s,ensureUpstream:t});let c=X("bootstrapStateBranchStorage",await sa({repoRoot:r,stateBranchRoot:s,ensureUpstream:t}));if(d(c))return a(c.message);logger.debug("[sync] bootstrap result",{bootstrapped:c.value,stateBranchRoot:s}),logger.debug("[sync] checking state branch git operation",{stateBranchRoot:s});let u=X("hasInProgressGitOperation(stateBranchRoot)",await Fr(s));if(d(u))return a(u.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:u.value}),u.value)return logger.info("[sync] state branch git operation in progress"),a("Cannot sync while a git operation is in progress in the state branch");logger.debug("[sync] ensuring state branch layout",{repoRoot:r,stateBranchRoot:s});let m=X("ensureStateBranchLayout",Zi(r,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}),l("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},Gg=async({repoRoot:e,stateBranchRoot:t,ownEventFileName:n})=>{logger.debug("[sync] committing own event file from state branch",{ownEventFileName:n,stateBranchRoot:t}),logger.debug("[sync] staging own event file",{stateBranchRoot:t,ownEventFileName:n});let r=X("stageStateBranchOwnEventFile",await Wr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=X("stageStateBranchMediaFiles",await ra({stateBranchRoot:t}));if(d(o))return a(o.message);let s=X("hasStagedChanges(after stage)",await Gi(t));if(d(s))return a(s.message);if(logger.debug("[sync] state branch change check after stage result",{changed:s.value}),!s.value)return logger.info("[sync] no own event file changes to commit"),l("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=X("createStateBranchSyncCommit",await oa({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),l("Committed own event file",{createdCommit:!0,commitSha:i.value}))},so=async({cwd:e=process.cwd(),ownEventFileName:t})=>{if(logger.debug("[sync] syncEpiqWithRemote:start",{cwd:e,ownEventFileName:t}),t.includes("/")||t.includes("\\"))return logger.error("[sync] invalid own event file name: contains path separator",{ownEventFileName:t}),a("Own event file must be a file name, not a path");if(!t.endsWith(".jsonl"))return logger.error("[sync] invalid own event file name: missing .jsonl suffix",{ownEventFileName:t}),a("Own event file must end with .jsonl");Oo();let n=X("ensureSyncReady",await Kg({cwd:e,ensureUpstream:!0}));if(d(n))return Qe(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=X("isDetachedHead(stateBranchRoot)",await zi(o));if(d(i))return Qe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Qe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,f=X("getStateBranch",hn(r));if(d(f))return Qe(f.message);let b=f.value;logger.debug("[sync] resolved state branch",{stateBranch:b,stateBranchRoot:o});let N=X("commitOwnEventFileToStateBranch",await Gg({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(N))return Qe(N.message);c=N.value.createdCommit,u=N.value.commitSha;let S=X("pullBranchRebaseIfPresent",await hs({cwd:o,branch:b}));if(d(S))return Qe(S.message);if(m=S.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let R=X("pushStateBranch",await Jn({stateBranchRoot:o,repoRoot:r}));if(d(R)&&Ki(R.message)){let M=X("pullBranchRebaseIfPresent(retry)",await hs({cwd:o,branch:b}));if(d(M))return Qe(M.message);m=m||M.value,R=X("pushStateBranch(retry)",await Jn({stateBranchRoot:o,repoRoot:r}))}if(d(R))return Qe(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let R=X("git rev-parse HEAD",await _({args:["rev-parse","HEAD"],cwd:o}));if(d(R))return Qe(R.message);u=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return _o(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var gi=()=>{let e=wn();return d(e)?mt:e.value.attachmentMaxKb??mt},yi=e=>{let t=Ye(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},Me=async e=>{let t=yi(e);if(d(t))return t;let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=vn(),o=await en({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:r.stateBranch});if(d(o))return a(o.message);let s=await _({cwd:n.value,args:["pull","--ff-only"]});d(s)&&oe.info(3,s.message);let i=Et(n.value);if(d(i))return a(i.message);let c=an(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},ke=()=>{let e=wn();return d(e)?a(e.message):e.value.userId?e.value.userName?l("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},je=()=>{let e=Je();return d(e)?a(e.message):e},cl=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)})),ll=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)}));var ul=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes).filter(A).filter(o=>e.includeClosed||o.parentNodeId!==me).map(o=>({id:o.id,ref:Ue(o.id),title:lt(o.title),description:o.props.description??"",parentNodeId:o.parentNodeId,isClosed:o.parentNodeId===me,readonly:!!o.readonly,tags:cl(o),assignees:ll(o)}));return l("Listed issues",r)},ml=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Sn(e.parentId,n.value,t.value.stateBranchRoot);if(d(r))return r;let o=wo({name:e.title,parent:e.parentId,user:n.value,rank:r.value});if(d(o))return o;let s=o.value,i=B([...s],t.value.stateBranchRoot);if(d(i))return a(i.message);let c=s.find(u=>u.action==="add.issue")?.payload.id;return c?l("Created issue",{id:c,title:e.title,parentId:e.parentId}):a("Unable to determine created issue id")},pl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=sn(me,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:ge(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:me,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},fl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Target node is not issue");if(o.parentNodeId!==me)return a("Issue is not closed");let s=Ao(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===me)return a("Previous parent resolves to closed swimlane");let i=r.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=sn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:ge(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=B([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:o.id,parentId:i.id})},gl=async e=>{let t=yi(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Pe({repoRoot:t.value});if(d(r))return r;let o=Et(r.value);if(d(o))return o;let s=an(o.value);if(d(s))return s;let i=sn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:ge(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=B([c],r.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})},$o=async(e={})=>{Oo();let t=yi(e.repoRoot);if(d(t))return a("Sync failed");let n=ke();if(d(n))return n;let r=await so({cwd:t.value,ownEventFileName:on(n.value)});return d(r)?(fi(r.message),r):(_o(),l("Synced",r.value))};var vt=async(e={})=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes),o=r.filter(f=>Vr(f)&&!f.isDeleted),s=new Map,i=new Map;for(let f of r)if(!f.isDeleted){if(Dt(f)&&f.parentNodeId){let b=s.get(f.parentNodeId)??[];b.push(f),s.set(f.parentNodeId,b)}if(A(f)&&f.parentNodeId){let b=i.get(f.parentNodeId)??[];b.push(f),i.set(f.parentNodeId,b)}}let c=wn();if(d(c))return c;let u={};for(let f of r.filter(A))f.isDeleted||(u[f.id]=I.getCommentsByIssue(f.id).map(b=>{let N=I.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:{id:b.authorId,name:N?.name??"Unknown",color:le(N?.name??b.authorId)},createdAt:dl(b.id)}}));let m=new Map;for(let f of n.value.eventLog)f.action==="add.issue.attachment"&&m.set(f.payload.id,f.payload.author);let p={};for(let f of r.filter(A))f.isDeleted||(p[f.id]=I.getAttachmentsByIssue(f.id).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Mn(b.hash,b.ext),bytes:b.bytes,createdAt:dl(b.id),canDelete:m.get(b.id)===c.value.userId})));return l("Retrieved Epiq GUI state",{boards:o.sort((f,b)=>f.rank.localeCompare(b.rank)).map(f=>({id:f.id,ref:Ue(f.id),title:f.title,swimlanes:(s.get(f.id)??[]).sort((b,N)=>b.rank.localeCompare(N.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly,issues:(i.get(b.id)??[]).sort((N,S)=>N.rank.localeCompare(S.rank)).map(N=>({id:N.id,ref:Ue(N.id),title:lt(N.title),description:N.props.description??"",readonly:!!N.readonly,tags:cl(N),assignees:ll(N),parentNodeId:N.parentNodeId,isClosed:N.parentNodeId===me})),parentNodeId:b.parentNodeId}))})),tags:Object.values(n.value.tags).map(f=>({...f,color:le(f.name)})),contributors:Object.values(n.value.contributors).map(f=>({...f,color:le(f.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:le(c.value.userName??"")},commentsByIssueId:u,attachmentsByIssueId:p,attachmentMaxKb:gi()})},yl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=o.props.description??"";if(s===e.description)return l("No changes made",{id:e.issueId,description:s});let i={id:ge(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},vl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=lt(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:ge(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},hl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=lt(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(r.value.tags).find(p=>p.name===s),c=i?.id??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},xl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Untag target must be an issue");if(o.readonly)return a("Cannot untag readonly issue");if(!r.value.tags[e.tagId])return a("Tag not found");let s={id:ge(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},bl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=lt(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(r.value.contributors).find(p=>p.name===s),c=i?.id??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},Il=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Unassign target must be an issue");if(o.readonly)return a("Cannot unassign readonly issue");if(!r.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:ge(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},Ho=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Comment target must be an issue");if(o.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=ge(),c={id:ge(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},Wo=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!o)return a("Unable to resolve comment");if(o.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!A(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return l("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},El=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Attachment target must be an issue");if(o.readonly)return a("Cannot attach to readonly issue");let s=Buffer.from(e.dataBase64??"","base64"),i=Ad(t.value.stateBranchRoot,s,gi());if(d(i))return i;let c=lt(e.name??"").trim()||"image",u=ge(),m={id:ge(),...n.value,action:"add.issue.attachment",payload:{id:u,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=B([m],t.value.stateBranchRoot);return d(p)?a(p.message):l("Added issue attachment",{id:u,issueId:e.issueId,fileName:Mn(i.value.hash,i.value.ext),bytes:i.value.bytes})},Cl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.attachment"&&m.payload.id===e.attachmentId);if(!o)return a("Unable to resolve attachment");if(o.payload.author!==n.value.userId)return a("You can only delete your own attachments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!A(s))return a("Attachment target must be an issue");if(s.readonly)return a("Cannot delete attachment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.attachment"&&m.payload.id===e.attachmentId))return l("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Nl=async e=>{let t=await Me(e.repoRoot);return d(t)?t:Rd(t.value.stateBranchRoot,e.fileName,gi())};var Sl=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=ar();if(d(p))return oe.error(p.message);let{autoSync:f,userName:b,preferredEditor:N}=p.value;return!!(f&&b&&N)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await $o({repoRoot:e.repoRoot}),tn({type:"state",payload:await vt({repoRoot:e.repoRoot})})}finally{o=!1,s&&(s=!1,c())}}},u=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=ar();if(d(p))return oe.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as zg}from"ws";var Ve=(e,t)=>{e.send(JSON.stringify(t))},br=async(e,t)=>Ve(e,{type:"state",payload:await vt({repoRoot:t})}),ht=async(e,t,n,r,o)=>{if(Ve(e,{type:r,payload:o}),d(o))return Ve(e,{type:"failed",payload:o.message});n(),br(e,t)},Al=(e,t,{onStateChanged:n})=>{new zg({server:e,path:"/ws"}).on("connection",o=>{ia(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return br(o,t);if(c==="sync"){let u=await $o({repoRoot:t});return Ve(o,{type:"sync:result",payload:u}),n(),br(o,t)}if(c==="issue:comment:add"){let u=await Ho({repoRoot:t,...i.payload});return ht(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await Wo({repoRoot:t,...i.payload});return Ve(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Ve(o,{type:"failed",payload:u.message}):(n(),br(o,t))}if(c==="issue:edit:description"){let u=await yl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await vl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await hl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await xl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await bl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await Il({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Ve(o,{type:"issues",payload:await ul({repoRoot:t})});if(c==="issues:create"){let u=await ml({...i.payload,repoRoot:t});return Ve(o,{type:"issues:create:result",payload:u}),d(u)?tn({type:"failed",payload:u.message}):(tn({type:"issue:created",payload:u.value}),n(),br(o,t))}if(c==="issues:move"){if(!i.payload.position)return Ve(o,{type:"error",message:"Missing move position"});let u=await gl({...i.payload,repoRoot:t});return ht(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await pl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await fl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:reopen:result",u)}return Ve(o,{type:"error",message:"Unknown message type"})}catch(i){return Ve(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Xg=yn.dirname(Yg(import.meta.url)),Jg=process.env.IS_LOCAL==="true"?yn.resolve(process.cwd(),"dist/gui"):yn.join(Xg,"gui"),jo,Qg=async()=>(jo===void 0&&(jo=await import("node:sea").catch(()=>null)),jo?.isSea()?jo:null),ye=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Rl=async(e,t=1024*1024)=>new Promise((n,r)=>{let o="",s=0;e.on("data",i=>{if(s+=i.length,s>t){e.destroy(),r(new Error("Request body too large"));return}o+=i}),e.on("end",()=>{try{n(o?JSON.parse(o):{})}catch{r(new Error("Invalid JSON body"))}}),e.on("error",r)}),Zg=2*1024*1024,ey={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},ty=e=>e.endsWith(".html")?"text/html; charset=utf-8":e.endsWith(".js")?"text/javascript; charset=utf-8":e.endsWith(".css")?"text/css; charset=utf-8":e.endsWith(".json")?"application/json; charset=utf-8":e.endsWith(".ico")?"image/x-icon":"application/octet-stream",Tl=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=yn.resolve(Jg),o=yn.resolve(r,n),s=yn.relative(r,o);if(s.startsWith("..")||yn.isAbsolute(s))return ye(t,403,{isError:!0,message:"Forbidden"});let i=await Qg();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await wl(o);return t.writeHead(200,{"content-type":ty(o)}),t.end(c)}catch{return ye(t,404,{isError:!0,message:`Not found: ${n}`})}},ny=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){r(new Error("Unable to resolve address"));return}n(u.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),Ml=async e=>{let t=qg.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return ye(s,200,await vt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Rl(o);if(!c.issueId||!c.body?.trim())return ye(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Ho({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="POST"&&i.pathname==="/api/attachments")try{let c=await Rl(o,Zg);if(!c.issueId||!c.dataBase64)return ye(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let u=await El({repoRoot:e.repoRoot,issueId:c.issueId,name:c.name??"",dataBase64:c.dataBase64});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add attachment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/attachments/")){let c=decodeURIComponent(i.pathname.replace("/api/attachments/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing attachment id"});let u=await Cl({repoRoot:e.repoRoot,attachmentId:c});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),u=await Nl({repoRoot:e.repoRoot,fileName:c});if(d(u))return ye(s,404,{isError:!0,message:u.message});try{let m=await wl(u.value.filePath);return s.writeHead(200,{"content-type":ey[u.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return ye(s,404,{isError:!0,message:"Attachment blob not found"})}}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing comment id"});let u=await Wo({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Tl("/",s):Tl(i.pathname,s)});try{await ny(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Sl({repoRoot:e.repoRoot});Al(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):l("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Pl=async e=>{let t=await Ml({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${ry.cyan(n)}`),ki(n),l("Started GUI",{url:n})};import{Box as Jt}from"ink";import ae from"react";import{Box as vi,Text as Ir}from"ink";import ot,{useEffect as oy,useMemo as sy}from"react";import{ulid as iy}from"ulid";var Ll=({text:e,match:t,color:n,highlightColor:r=v.secondary,dimColor:o=!1})=>{if(!t)return ot.createElement(Ir,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?ot.createElement(Ir,{color:n,dimColor:o},e):ot.createElement(Ir,{color:n,dimColor:o},e.slice(0,c),ot.createElement(Ir,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},kl=iy(),ay=e=>`${e}`,dy=e=>{let{pendingNavTarget:t}=jt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ie(x.NONE,{breadCrumb:n,contextNode:r,readOnly:g().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==x.PALETTE).map(i=>{let c=ho(i),u=Do.find(m=>m.intent===c);return{command:i,description:u?.description??`[${i}] Run command`,isAvailable:s.has(i)}}).filter(i=>i.command.toLowerCase().startsWith(e)||e.length>=2&&i.description.toLowerCase().includes(e)).sort((i,c)=>i.isAvailable!==c.isAvailable?i.isAvailable?-1:1:i.command.localeCompare(c.command))},cy=e=>Q.text({id:kl,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),ly=(e,t,n)=>Q.text({id:ay(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),hi=[],uy=e=>{Dl();let t=I.createNode(cy(g().rootNodeId));d(t)||!kt(t.value)||(hi=[t.value,...e.map((n,r)=>ly(n,r,kl)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0}))},Dl=()=>{let e=hi.map(t=>t.id);hi=[];for(let t of e)I.deleteNode(t)};function Fl({width:e,height:t}){let r=zd().value.trim().toLowerCase(),o=sy(()=>dy(r),[r]);oy(()=>(uy(o),()=>{Dl()}),[o]);let s=g().selectedIndex;return ot.createElement(vi,{flexDirection:"column",width:e,height:t-2},ot.createElement(et,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?v.accent:v.secondary2,p=i.isAvailable?"":"[unavailable] ";return ot.createElement(vi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:v.secondary,borderStyle:"single"},ot.createElement(Ir,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",ot.createElement(Ll,{text:ma(i.command),match:r,color:m,dimColor:!i.isAvailable})),ot.createElement(vi,{paddingLeft:2},ot.createElement(Ll,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?v.primary:v.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Ty}from"ink";import Go from"react";import Cr from"chalk";import{Box as xi,Text as Bl}from"ink";import Er,{useEffect as my,useMemo as py,useState as fy}from"react";var Ul=Cr.hex(v.secondary),gy=Cr.inverse,yy=Cr.inverse.hex(v.secondary2),vy={hint:"",hints:[],overlap:0,remainder:""},_l=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},hy=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=le(t);return{bg:r=>Cr.bgHex(n).black(r),bgCursor:r=>Cr.bgHex(n).inverse.black(r)}}return Ts(t)},xy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=_l({value:e,command:t});if(!r)return null;let s=e.slice(r.end).match(/^\s*/)?.[0].length??0,i=r.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},Ol=()=>({value:Ae.value,cursorPosition:Ae.cursorPosition,commandIsPending:Ae.commandIsPending,autoCompletion:Ae.commandMeta.autoCompletion??vy,infoMessage:Ae.commandMeta.infoMessage,validationStatus:Ae.commandMeta.validity,command:Ae.commandMeta.command,inputString:Ae.commandMeta.inputString,modifier:Ae.commandMeta.modifier}),by=(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,$l=({width:e,mode:t})=>{let[n,r]=fy(Ol());my(()=>{let S=()=>{let M=Ol();r(U=>by(U,M)?U:M)},R=qs(S);return S(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p,validationStatus:f}=n,b=c&&f===pt.Invalid,N=py(()=>{let S=Math.max(0,Math.min(s,o.length)),R=_l({value:o,command:m}),M=xy({value:o,command:m,modifier:p}),U=m?Ts(m):null,j=hy({command:m,modifier:p}),D=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fg(ue):Hn&&j?j.bg(ue):ue},z=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fgCursor(ue):Hn&&j?j.bgCursor(ue):gy(ue)},$=o.slice(0,S),P=o[S]??" ",O=S<o.length?o.slice(S+1):"",Ge=Array.from($).map((ue,ce)=>D(ue,ce)).join(""),Ne=z(P,S),ze=Array.from(O).map((ue,ce)=>D(ue,S+1+ce)).join("");if(u.hint){let ue=u.hint[u.overlap]??P;Ne=yy(ue),ze=Ul(u.remainder.slice(1)+O)}return Ul(t===y.PALETTE?"?":":")+Ge+Ne+ze},[o,s,u,m,p]);return Er.createElement(xi,{flexDirection:"column",justifyContent:"flex-start"},Er.createElement(xi,{flexDirection:"column",paddingX:1,borderColor:v.secondary,borderStyle:"round",width:e},Er.createElement(xi,null,Er.createElement(Bl,null,N),i&&Er.createElement(Bl,{wrap:"truncate",color:b?v.red:v.secondary2},` ${i} `))))};import{Box as Iy,Text as Ey}from"ink";import Hl from"react";var Cy=(e,t)=>{let n=[],r=0;for(let o of e){let i=(n.length>0?" | ":"").length+o.length;if(r+i>t-4)break;n.push(o),r+=i}return n},Wl=({width:e,availableHints:t})=>{let n=Cy(t,e).join(" | ");return Hl.createElement(Iy,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1},Hl.createElement(Ey,{color:v.secondary2},n.length?n:"\xA0"))};import{Box as Ny,Text as Vo}from"ink";import Nr,{useEffect as Sy,useRef as Un,useState as Ay}from"react";var Ry=40,Ko=.3,bi="\u2500",jl=1,Vl=16,Kl=({width:e})=>{let{replay:t}=H(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*jl,[c,u]=Ay(0),m=Un(r);m.current=r;let p=Un(0),f=Un(0),b=Un(0),N=Un(0),S=Un(0);if(Sy(()=>{if(!n){p.current=0,b.current=0,N.current=0,S.current=0,u(0);return}p.current=m.current,f.current=Date.now(),b.current=m.current;let D=setInterval(()=>{let z=Date.now(),$=m.current;if($!==b.current){let ze=$-b.current,ue=z-f.current;if(ze<0)N.current=0,S.current=0;else if(ze>0&&ue>0){let ce=ze/ue;N.current=N.current===0?ce:N.current*(1-Ko)+ce*Ko,S.current=S.current===0?ze:S.current*(1-Ko)+ze*Ko}p.current=$,f.current=z,b.current=$}let P=z-f.current,O=Math.min(S.current,N.current*P),Ge=Math.min(1,p.current+O),Ne=Math.round(Ge*i);u(ze=>ze===Ne?ze:Ne)},Ry);return()=>clearInterval(D)},[n,i]),!t)return null;let R=D=>{let z=s>1?D/(s-1):0,$=Math.round(z*(Vl-1))/(Vl-1);return Gr($)},M=Math.min(s,Math.floor(c/jl)),U=[];for(let D=0;D<M;D++){let z=R(D),$=U[U.length-1];$&&$.color===z?$.text+=bi:U.push({text:bi,color:z})}let j=bi.repeat(Math.max(0,s-M));return Nr.createElement(Ny,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1,columnGap:1},Nr.createElement(Vo,{color:v.secondary2},"\u25B6"),Nr.createElement(Vo,null,U.map((D,z)=>Nr.createElement(Vo,{key:z,color:D.color},D.text)),Nr.createElement(Vo,{color:v.secondary,dimColor:!0},j)))};var Sr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=H(),o=t===y.COMMAND_LINE||t===y.PALETTE;return Go.createElement(Ty,null,o?Go.createElement($l,{width:e,mode:t}):r==="replay"?Go.createElement(Kl,{width:e}):Go.createElement(Wl,{width:e,mode:t,availableHints:n}))};import{Box as zt,Text as On}from"ink";import De,{useEffect as wy,useMemo as My}from"react";import{ulid as Gl}from"ulid";var qo=Gl(),Py=()=>[...new Set([...g().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),Ly=e=>Q.text({id:qo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),ky=(e,t,n)=>Q.text({id:Gl(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),zo=[],zl=()=>{let e=zo.filter(n=>n.id!==qo).map(n=>n.id),t=zo.filter(n=>n.id===qo).map(n=>n.id);zo=[];for(let n of[...e,...t])I.deleteNode(n)},Dy=e=>{zl();let t=I.createNode(Ly(g().rootNodeId));if(d(t)||!kt(t.value))return logger.error("Could not attach help nodes");zo=[t.value,...e.map((n,r)=>ky(n,r,qo)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0})},ql=({width:e,height:t})=>{let n=My(()=>Py(),[]);wy(()=>(Dy(n),()=>{zl()}),[n]);let r=g().selectedIndex;return De.createElement(zt,{flexDirection:"column",marginTop:3,borderColor:v.secondary,borderStyle:"round",width:e,height:t-2},De.createElement(zt,{paddingX:1,justifyContent:"center"},De.createElement(On,{color:v.accent},"Help"),De.createElement(On,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),De.createElement(zt,{paddingX:1,marginTop:1},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.secondary},"Key(s)")),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:v.secondary},"Action"))),De.createElement(et,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return De.createElement(zt,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.accent},o)),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:c?v.primary:v.secondary2},s)))})))};import Fy from"chalk";import{Box as Yo,Text as Mt}from"ink";import Ke from"react";var Yl=({width:e,height:t})=>Ke.createElement(Yo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ke.createElement(Mt,{color:v.accent,bold:!0},"Initialize project"),Ke.createElement(Mt,null,`This folder is not an ${Fy.hex(v.accent)("epiq")} project yet.`),Ke.createElement(Mt,{color:v.primary},"To start tracking issues here, we need to initialize a new",Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json "),"file in this repository."),Ke.createElement(Yo,{marginTop:1,flexDirection:"column"},Ke.createElement(Yo,null,Ke.createElement(Mt,{color:v.accent}," "),Ke.createElement(Mt,{color:v.primary},"Type "),Ke.createElement(Mt,{backgroundColor:v.secondary}," :init "))),Ke.createElement(Yo,{marginTop:1},Ke.createElement(Mt,{color:v.secondary2},"This will create, commit and push "),Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json ")));import{Box as Xo,Text as xt}from"ink";import Ce from"react";var By=({isDone:e,command:t,value:n})=>Ce.createElement(Xo,null,Ce.createElement(xt,{color:v.accent,dimColor:e},e?" \u2714 ":" "),Ce.createElement(xt,{dimColor:e},"Type "),Ce.createElement(xt,{backgroundColor:v.secondary,dimColor:e}," "+t+" "),n!==void 0&&Ce.createElement(Ce.Fragment,null,Ce.createElement(xt,{dimColor:e}," "),Ce.createElement(xt,{color:v.secondary,dimColor:e},"<"+n+">"))),Uy=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Ii({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Ot(),u=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:s,message:"Nice. Now pick your editor."},{key:"autosync",done:c,command:":config autosync",value:i,message:"Almost there. Configure auto sync."}],m=u.findIndex(f=>!f.done),p=m===-1?void 0:u[m];return Ce.createElement(Xo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ce.createElement(xt,{color:v.accent,bold:!0},"Welcome! \u{1F539}"),Ce.createElement(xt,null,"Let's get you started - it's a breeze."),Ce.createElement(xt,{color:v.secondary2},"Remember - you can always search available commands by typing:",Ce.createElement(xt,{color:v.accent}," ? ")),p&&Ce.createElement(xt,{color:v.secondary2},p.message),Ce.createElement(Xo,{flexDirection:"column"},u.map((f,b)=>m===-1||b<=m?Ce.createElement(Xo,{key:f.key,marginBottom:1},Ce.createElement(By,{isDone:f.done,command:f.command,value:f.done?Uy(f.value):void 0})):null)))}import ts from"chalk";import{Box as Rr,Text as _n}from"ink";import ve from"react";import{Box as Jo,Text as Xl}from"ink";import qt from"react";import Oy from"chalk";var _y=e=>(I.getTag(e)?.name??"").length+3,$y=e=>(I.getContributor(e)?.name??"").length+3,Jl=({width:e})=>{let{viewMode:t}=K(),n=H(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=It(c?.id??o.id,"TICKET"),m=te(u)?u.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],b=m?.parentNodeId?!Ss(o.id,m.parentNodeId)&&t==="dense":!1,N=r.map(($,P)=>{let O=P===r.length-1,Ge=q($.id),Ne=O?Ge?.[s]?.title:void 0;return`${P?" / ":""}${$.title??""}${Ne?` \u25B8 ${Ne}`:""}`}).join(""),S=m?I.getCommentsByIssue(m.id):[],R=S.length?String(S.length).length+11:0,M=b?p.reduce(($,P)=>$+_y(P),0)+f.reduce(($,P)=>$+$y(P),0)+R:0,U=c?.id!=null&&!(t==="wide"&&A(c)),j=Math.max(0,e-M),D=N.substring(0,j)+(U?Oy.hex(v.secondary2).dim(` ${Ue(c.id)}`):""),z=b?[...p.map($=>qt.createElement(Jo,{key:`tag-${$}`,paddingLeft:1},qt.createElement(kn,{id:$}))),...f.map($=>qt.createElement(Jo,{key:`assignee-${$}`,paddingLeft:1},qt.createElement(Ht,{id:$}))),S.length?qt.createElement(Jo,{key:"comments",paddingLeft:1},qt.createElement(Xl,{color:v.accent},"[",S.length," comment",S.length===1?"":"s","]")):null]:[];return qt.createElement(Jo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},qt.createElement(Xl,{color:v.secondary2},D),z)};import{Box as Hy,Text as Ql}from"ink";import Qo from"react";var Wy=({filters:e})=>Qo.createElement(Hy,{columnGap:1},Qo.createElement(Ql,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Qo.createElement(Ql,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Zl=Qo.memo(Wy);import{Box as jy,Text as Zo}from"ink";import Ar from"react";function eu(){let{eventLog:e,unappliedEvents:t}=H(),n=e.at(-1)?.id,r=Xr(n??""),o=te(r)?Yr(r.value):"INVALID DATE";return Ar.createElement(jy,{paddingLeft:1},Ar.createElement(Zo,{backgroundColor:v.accent,color:v.secondary}," Readonly "),Ar.createElement(Zo,{color:v.accent}," "+t.length+" edits ago at "+o+"."),Ar.createElement(Zo,{color:v.accent}," Resume with "),Ar.createElement(Zo,{backgroundColor:v.accent,color:v.secondary}," ",":peek now"," "))}import{Box as Vy,Text as Ei}from"ink";import es from"react";function tu(){let{replay:e}=H();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return es.createElement(Vy,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},es.createElement(Ei,{backgroundColor:v.accent,color:v.secondary}," \u25B6 REPLAY "),es.createElement(Ei,{color:v.secondary2},Yr(new Date(r))),es.createElement(Ei,{color:v.accent},`${t}/${n} edits`))}import Ci from"chalk";import{Box as Ky,Text as nu}from"ink";import Ni,{useEffect as Gy,useState as zy}from"react";var qy=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],Yy=150,ru=12,Xy=.36,ou=e=>{let t=e.replace("#","");return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}},Jy=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},Qy=(e,t,n)=>{let r=ou(e),o=ou(t);return Jy({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Zy=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,s=e[r],i=e[Math.min(r+1,e.length-1)];return Qy(s,i,o)};function su({syncStatus:e,autoSync:t}){let[n,r]=zy(0);Gy(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*Xy)+1)/2,p=Math.round(m*(ru-1));r(f=>f===p?f:p)},Yy);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:v.secondary2,failed:v.yellow,pending:v.secondary2,syncing:Zy(qy,n/(ru-1))??""}[e.status];return Ni.createElement(Ky,null,Ni.createElement(nu,null,Ci.hex(v.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Ni.createElement(nu,null,Ci.hex(i)("\u25CF")+Ci.hex(v.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import lu from"chalk";import{Text as uu}from"ink";import mu,{useEffect as rv,useState as ov}from"react";var Yt="1.3.2";import Si from"chalk";var ev="https://registry.npmjs.org/epiq/latest",Ai=null,iu=0,tv=1e3*60*60*24,au=e=>e.replace(/^v/,""),nv=(e,t)=>{let n=au(e).split(".").map(Number),r=au(t).split(".").map(Number);for(let o=0;o<Math.max(n.length,r.length);o++){let s=n[o]??0,i=r[o]??0;if(s>i)return 1;if(s<i)return-1}return 0},du=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Ai&&Date.now()-iu<tv)return Ai;try{let t=await fetch(ev);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let r=(await t.json()).version??null,o={current:e,latest:r,updateAvailable:r?nv(r,e)>0:!1};return Ai=o,iu=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},cu=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Si.hex(v.accent).dim(s):Si.hex(v.secondary).dim(s)).join(Si.hex(v.secondary2).dim("."))};function pu(){let[e,t]=ov({current:Yt,latest:null,updateAvailable:!1});return rv(()=>{let n=!0;return du(Yt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?mu.createElement(uu,{dimColor:!0,color:v.secondary2},Yt+" "):mu.createElement(uu,null,lu.hex(v.secondary2).dim(Yt),lu.hex(v.accent).dim(" \u2197 "),cu(Yt,e.latest))}function Tr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=H(),{userName:i,preferredEditor:c,autoSync:u}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",b=s?nn(s.currentLabel,Math.max(0,p)):"";return ve.createElement(Rr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?ve.createElement(Rr,{paddingLeft:1},ve.createElement(_n,{color:v.secondary2},b)):f?ve.createElement(_n,null," "):o===y.PALETTE?ve.createElement(Rr,null,ve.createElement(_n,{color:v.accent},"Command Palette"),ve.createElement(_n,{dimColor:!0,color:v.secondary2}," ","- search, select and press enter")):ve.createElement(Rr,{paddingLeft:1},e.length>0?ve.createElement(Zl,{filters:e}):ve.createElement(Jl,{width:p})),n==="live"?ve.createElement(Rr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},ve.createElement(su,{autoSync:!!u,syncStatus:r}),ve.createElement(_n,null,ts.hex(v.secondary2).dim("Mode: ")+ts.hex(v.secondary2).dim(o.padEnd(8," "))," "),ve.createElement(fu,{icon:"@",value:i}),ve.createElement(fu,{icon:"\u276F",value:c}),ve.createElement(pu,null)):"",n==="peek"?ve.createElement(eu,null):"",n==="replay"?ve.createElement(tu,null):"")}function fu({icon:e,value:t}){return ve.createElement(_n,null,ts.dim(e)+ts.hex(v.accent)(` ${t??"-"} `))}import{Box as sv,Text as iv}from"ink";import wr from"react";import{Box as ns,Text as Ri}from"ink";import Xt from"react";function Ti(){let e=H(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?G(t?.id):[];return Xt.createElement(ns,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:v.secondary,width:s},Xt.createElement(ns,{padding:1,paddingTop:0,paddingBottom:0},Xt.createElement(Ri,null,"Select a board:")),Xt.createElement(ns,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,f=G(c.id).flatMap(({id:b})=>q(b)).length;return Xt.createElement(ns,{key:c.id??u},Xt.createElement(Ri,{color:m?v.accent:v.secondary2},Xt.createElement(Re,{isSelected:m})),Xt.createElement(Ri,{color:m?v.accent:v.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var av=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=H(),u=n.find(({context:b})=>b==="BOARD"),f=s-1-3;return wr.createElement(sv,{flexDirection:"row"},e.context==="WORKSPACE"?wr.createElement(Ti,null):u?wr.createElement(So,{height:f,width:i,swimlanes:(c[u.id]??[]).filter(b=>b!==void 0&&Dt(b)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):wr.createElement(iv,null))},gu=wr.memo(av);import{useEffect as dv}from"react";var cv=e=>{dv(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=K();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=g();u==="default"&&!c&&io(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},yu=({autoSync:e})=>(cv(e),null);function wi({width:e,height:t}){let n=H(),{autoSync:r,viewMode:o}=ha(),s=n.filters;if(n.mode===y.HELP)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(ql,{width:e,height:t}));if(n.mode===y.PALETTE)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(Fl,{width:e,height:t-2}),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Ot(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(Ii,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(Yl,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Le(n.breadCrumb??[],"BOARD");if(te(m)){let p=m.value.id,f=G(p).length,b=3,N=Math.floor(e/b),S=Math.floor(e/Math.max(f,1));e=Math.min(S,N)*Math.max(f,b)}return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(yu,{autoSync:r}),ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(gu,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import lv from"readline";var rs,os,bt,uv=new Set([h.MoveCursorLeft,h.EraseInputWord,h.MoveCursorLeftOfWord,h.MoveCursorRight,h.MoveCursorRightOfWord,h.NavToPreviousContainer,h.NavToNextContainer,h.NavPreviousItem,h.NavNextItem,h.SetViewDense,h.SetViewWide,h.Confirm,h.Exit,h.Yank,h.InitCommandLine,h.InitCommandPalette,h.ExitCommandLine,h.CaptureInput,h.EraseInput,h.EraseInputWord,h.HideHelp,h.ViewHelp,h.SetViewDense,h.SetViewWide,h.GetLastCommandFromHistory,h.GetNextCommandFromHistory,h.AutoCompleteCommand]),mv=new Set([h.NavPreviousItem,h.NavNextItem,h.NavToPreviousContainer,h.NavToNextContainer,h.Confirm,h.Exit,h.InitCommandPalette,h.InitMove,h.MoveNextItem,h.MovePreviousItem,h.MoveToNextContainer,h.MoveToPreviousContainer,h.Delete,h.AddItem,h.EditTitle,h.EditDescription,h.ConfirmMove,h.Edit,h.ViewHelp,h.Yank]),vu=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=g(),s=Yd(e,n);if(!s||r&&!uv.has(s)||o==="replay"&&n===y.DEFAULT&&mv.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},pv=()=>async function(t,n){n.name!=="escape"&&(bt&&(clearTimeout(bt),bt=void 0),await vu(n))},fv=()=>async function(t){if(t.length===1&&t[0]===27){bt&&clearTimeout(bt),bt=setTimeout(()=>{vu({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),bt=void 0},25);return}bt&&(clearTimeout(bt),bt=void 0)};function hu(){rs&&process.stdin.removeListener("keypress",rs),os&&process.stdin.removeListener("data",os),rs=pv(),os=fv(),lv.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",os),process.stdin.on("keypress",rs)}async function xu(){try{let e=wn();te(e)&&Fe(e.value);let t=Ye(process.cwd()),n=[];if(te(t)){let s=Pe({repoRoot:t.value});if(d(s))return dn(3,s.message);let i=vn(),c=await en({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return dn(3,c.message);let u=await _({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=Et(s.value);if(d(m))return dn(3,m.message);n=m.value}let r=an(n);if(d(r))return dn(4,r.message);E({hasProjectDefinition:te(t),hasInitializingEvents:!!n.length});let o=Mi();return d(o)?dn(6,o.message):(hu(),l("Booted Epiq",void 0))}catch(e){return dn(0,ro(e))}}hc();var hv=`${Qt.bold("Epiq CLI")}
|
|
58
|
+
`));let ce=Je();if(d(ce))return ee(16,ce.message);let{rootNodeId:$n,nodes:Hn}=ce.value,Pi=Hn[$n];return Pi?(T.navigate({contextNode:Pi,selectedIndex:0}),E({hasProjectDefinition:!0,mode:y.DEFAULT}),l(O,null)):ee(16,"Unable to resolve initialized root node")};import{ulid as xg}from"ulid";import{ulid as hg}from"ulid";var Sc=null,Kt=()=>structuredClone(Sc),vr=e=>{Sc=e},Ac=()=>{let{contextNode:e,selectedIndex:t}=g(),r=q(e.id)[t];return r?l("Resolved selected child",r):a("Target node not found")},ai=({id:e,parentId:t,position:n={at:"end"}})=>{let r=q(t).filter(o=>o.id!==e);return to(r,n)},Rc=({id:e,parentId:t,position:n={at:"end"}})=>{let r=se();if(d(r))return a("Unable to resolve user ID");let o=ai({parentId:t,id:e,position:n});return d(o)?o:l("Created pending move state",{id:hg(),...r.value,action:"move.node",payload:{id:e,parent:t,rank:o.value.rank}})},Tc=e=>{vr(e);let t=Bt(e,!0);return d(t)?t:l("Node moved successfully",t.value)};function di(e){let t=Ac();if(d(t))return t;let{contextNode:n,nodes:r}=g();if(!n.parentNodeId)return a("Missing parent node id");let o=r[n.parentNodeId];if(!o)return a("Missing parent node");let s=q(o.id),i=s.findIndex(({id:m})=>m===n.id);if(i<0)return a("Current node not found among siblings");let c=s[i+e];if(!c)return a("Missing sibling node");let u=Rc({id:t.value.id,parentId:c.id,position:{at:"end"}});return d(u)?u:Tc(u.value)}function ci(e){let t=Ac();if(d(t))return t;let{contextNode:n,selectedIndex:r}=g(),s=q(n.id)[r+e];if(!s)return a("Missing sibling node");let i=Rc({id:t.value.id,parentId:n.id,position:{at:e===1?"after":"before",sibling:s.id}});return d(i)?i:Tc(i.value)}var wc=()=>{let e=Kt();if(!e)return a("No pending move state");let t=e.payload.id,n=e.payload.parent,r=g().nodes[n];if(!r)return a("Move parent not found");let o=q(n).findIndex(s=>s.id===t);return o===-1?a("Moved node not found among rendered children"):(T.navigate({contextNode:r,selectedIndex:o}),l("Synchronized navigation to moved node",null))},To=(e,t="Moved preview")=>{if(d(e))return e;let n=wc();return d(n)?n:(E({mode:y.MOVE}),l(t,null))},Mc=async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t}=Y().commandMeta,{contextNode:n,selectedIndex:r}=g(),o=q(n.id)[r];if(!o)return E({mode:y.DEFAULT}),a("No move target");if(t==="start"){if(o.readonly)return a("Target node is read-only");if(r===-1)return a("No item selected");if(!o.parentNodeId)return a("Target has no parent");let s=q(o.parentNodeId),i=s.findIndex(({id:f})=>f===o.id);if(i===-1)return a("Target not found among siblings");let c=s[i-1],u=s[i+1],m=u!=null?{at:"before",sibling:u.id}:c!=null?{at:"after",sibling:c.id}:{at:"start"},p=ai({parentId:o.parentNodeId,id:o.id,position:m});return d(p)?p:(vr({id:xg(),action:"move.node",payload:{id:o.id,parent:o.parentNodeId,rank:p.value.rank},...e.value}),E({mode:y.MOVE}),l("Move initialized",null))}if(t==="next")return To(ci(1));if(t==="previous")return To(ci(-1));if(t==="to-next")return To(di(1));if(t==="to-previous")return To(di(-1));if(t==="confirm"){let s=Kt();if(!s)return a("No pending move to confirm");let i=await at();if(d(i))return i;let c=B([s],i.value);if(d(c))return c;let u=wc();return d(u)?u:(vr(null),E({mode:y.DEFAULT}),l("Moved item",null))}return t==="cancel"?(vr(null),E({mode:y.DEFAULT}),l("Cancelling move",null)):a("Invalid move modifier")};import{ulid as Mo}from"ulid";import{monotonicFactory as bg,ulid as Ig}from"ulid";var Eg=bg(),wo=({name:e,parent:t,rank:n,user:{userId:r,userName:o}})=>{let s=Eg();return l("Created issue events",[{id:Ig(),userId:r,userName:o,action:"add.issue",payload:{id:s,parent:t,name:e,rank:n}}])};var Pc=async(e,t)=>{let n=se();if(d(n))return a("Unable to resolve user ID");let r=await at();if(d(r))return r;let o=r.value;if(!t.inputString)return a(`provide a name for your ${t.modifier}`);let{breadCrumb:s,contextNode:i,selectedIndex:c}=g(),u=m=>{let p=B([m],o);if(d(p))return p;let f=I.getNode(p.value[0].result.id);if(!f)return a("Created node not found");if(!f.parentNodeId)return p;let b=I.getNode(f.parentNodeId);return b?(T.navigate({contextNode:b,selectedIndex:I.getSiblings(f.parentNodeId).findIndex(({id:N})=>N===f.id)}),p):a("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=g(),p=I.getNode(m);if(!p)return a("Workspace not found");let f=Sn(p.id,n.value,o);return d(f)?f:u({id:Mo(),action:"add.board",payload:{id:Mo(),name:t.inputString,parent:p.id,rank:f.value},...n.value})}if(t.modifier==="swimlane"){let m=Le(s,"BOARD");if(d(m))return a("Unable to add swimlane in this context");let p=Sn(m.value.id,n.value,o);return d(p)?p:u({id:Mo(),action:"add.swimlane",payload:{id:Mo(),name:t.inputString,parent:m.value.id,rank:p.value},...n.value})}if(t.modifier==="issue"){let m=G(i.id)[c],p=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let j=Le(s,"SWIMLANE");return d(j)?null:j.value})();if(!p)return a("Unable to add issue in this context");let f=Sn(p.id,n.value,o);if(d(f))return f;let b=wo({name:t.inputString,parent:p.id,rank:f.value,user:n.value});if(d(b))return b;let N=b.value,S=B([...N],o);if(d(S))return S;if(!S.value[0])return a("Issue creation failed");let U=N.find(j=>j.action==="add.issue")?.payload.id;return U?(T.navigate({contextNode:p,selectedIndex:I.getSiblings(p.id).findIndex(({id:j})=>j===U)}),l("Issue created",null)):a("Unable to determine ticket id")}return l("Success",null)};var Po=({boardId:e,targetTime:t,stateBranchRoot:n,selectedIndex:r})=>{let o=g(),s=_a(n,t);if(d(s))return a(s.message);let{appliedEvents:i,unappliedEvents:c}=s.value,u=Gt();if(d(u))return u;let p=Ut(i).filter(d);if(p.length>0)return Gt(),E(o),a(p.map(b=>b.message).join(", "));let f=g().nodes[e];return f?(T.navigate({contextNode:f,selectedIndex:r}),l("",{unappliedEvents:c})):(Gt(),E(o),a("Board did not exist at that date"))};var Cg=20,Ng=16,Sg=150,Lo=null,ko=null;var fn=()=>{Lo!==null&&(clearInterval(Lo),Lo=null),ko!==null&&(clearTimeout(ko),ko=null)},Lc=()=>{fn(),E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null,selectedIndex:0})},Ag=e=>{let t=[],n=0;for(let o=0;o<e.length;o++){let s=o===0?0:Math.max(0,e[o]-e[o-1]);n+=Math.sqrt(s),t[o]=n}let r=n;return t.map((o,s)=>r>0?o/r:(s+1)/e.length)},kc=({events:e,startTime:t,durationMs:n})=>{fn();let r=e.length,o=e.map(f=>Nn(f)??t),s=o[r-1]??Date.now(),i=Ag(o),c=Math.max(1,Math.round(n*Cg/1e3)),u=Math.max(Math.round(n/c),Ng),m=0,p=0;E({mode:y.DEFAULT,readOnly:!0,timeMode:"replay",unappliedEvents:e,replay:{progress:0,appliedCount:0,totalCount:r,currentTime:t,startTime:t,endTime:s,currentLabel:"",flashNodeIds:[]}}),Lo=setInterval(()=>{m++;let f=m/c,b=[],N;for(;p<r&&i[p]<=f;){let R=e[p],M=Bt(R);if(d(M)){Lc();return}b.push(...ws(R)),N=R,p++}if(p>=r||m>=c){for(;p<r;p++){let M=Bt(e[p]);if(d(M))break}let R=g().replay;E({unappliedEvents:[],replay:R&&{...R,progress:1,appliedCount:r}}),fn(),ko=setTimeout(Lc,Sg);return}let S=g().replay;E({unappliedEvents:e.slice(p),replay:{progress:Math.min(1,f),appliedCount:p,totalCount:r,startTime:t,endTime:s,currentTime:N?Nn(N)??S?.currentTime??t:S?.currentTime??t,currentLabel:N?La(N):S?.currentLabel??"",flashNodeIds:N?[...new Set(b)]:S?.flashNodeIds??[]}})},u)};var Dc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta;if(fn(),r==="now"){let c=Et(n.value);if(d(c))return a(c.message);let u=Gt();if(d(u))return u;let p=Ut(c.value).filter(d);return p.length>0?a(p.map(f=>f.message).join(", ")):(E({mode:y.DEFAULT,readOnly:!1,timeMode:"live",unappliedEvents:[],replay:null}),l("Peeking now",!0))}let s;if(r==="prev"){let c=g().eventLog.at(-1),u=Nn(c);if(u===null)return a("No previous event to peek");s=u}else if(r==="next"){let c=g().unappliedEvents.at(0),u=Nn(c);if(u===null)return a("No next event to peek");s=u+1}else{let c=cn(r||o.trim());if(!c)return a("Invalid peek date");s=c.getTime()}let i=Po({boardId:e.value.id,targetTime:s,stateBranchRoot:n.value,selectedIndex:0});return d(i)?i:(E({mode:y.DEFAULT,readOnly:!0,timeMode:"peek",unappliedEvents:i.value.unappliedEvents,replay:null}),l("Peeking",!0))};var Fc=async()=>{let e=Le(g().breadCrumb,"BOARD");if(d(e))return e;let t=await dt(process.cwd());if(d(t))return a("Unable to locate repo root");let n=Pe({repoRoot:t.value});if(d(n))return n;let{modifier:r,inputString:o}=Y().commandMeta,{dateInput:s,durationInput:i}=uo(r,o);if(fn(),g().syncStatus.status==="syncing")return a("Cannot replay while syncing, try again in a moment");let c=cn(s);if(!c)return a("Invalid replay date");let u=i?lo(i):15e3;if(u===null)return a("Invalid replay duration (try e.g. 30s or 2m)");let m=c.getTime(),p=g(),f=Po({boardId:e.value.id,targetTime:m,stateBranchRoot:n.value,selectedIndex:-1});if(d(f))return f;let{unappliedEvents:b}=f.value;return b.length===0?(Gt(),E(p),l("Nothing to replay from that point",!0)):(kc({events:b,startTime:m,durationMs:u}),l("Replaying board history",!0))};import Tg from"zod";var Bc=()=>{let e=Y().commandMeta.inputString,t=Tg.coerce.number().int().min(3e3).safeParse(e);if(!t.success)return a("Auto sync duration must be a number of at least 3000 ms");let n=Ze({autoSyncDebounceMs:t.data});return d(n)?n:(Fe({autoSyncIntervalMs:t.data}),E({mode:y.DEFAULT}),l(`Auto sync interval set to ${t.data}ms`,null))};var Uc=()=>{let e=Y().commandMeta.inputString.trim();if(e!=="on"&&e!=="off")return a("Invalid response");let t=dd(e),n=Ze({autoSync:t});return d(n)?n:(Fe({autoSync:t}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};var Oc=()=>{let e=Y().commandMeta.inputString.trim();if(!["debug","error","info"].includes(e))return a("Invalid response");let n=Ze({logLevel:e});return d(n)?n:(Fe({logLevel:e}),E({mode:y.DEFAULT}),l(`Auto sync set to "${e}"`,null))};import{spawn as wg}from"node:child_process";var Mg=()=>{switch(process.platform){case"darwin":return{command:"pbcopy",args:[]};case"win32":return{command:"clip",args:[]};default:return process.env.WAYLAND_DISPLAY?{command:"wl-copy",args:[]}:{command:"xclip",args:["-selection","clipboard"]}}},_c=async e=>new Promise(t=>{let{command:n,args:r}=Mg();try{let o=wg(n,r,{stdio:["pipe","ignore","ignore"]});o.on("error",()=>t(a(`Clipboard tool not available (${n})`))),o.on("close",s=>t(s===0?l("Copied to clipboard",null):a(`Clipboard tool failed (${n})`))),o.stdin.on("error",()=>{}),o.stdin.write(e),o.stdin.end()}catch{t(a(`Clipboard tool not available (${n})`))}});var hr=async(e,t)=>{if(!e.trim())return a(`Nothing to copy: ${t} is empty`);let n=await _c(e);return d(n)?n:l(`Copied ${t} to clipboard`,null)},$c=async e=>{let{breadCrumb:t,selectedNode:n}=g(),r=ir({breadCrumb:t,selectedNode:n}),o=r??n;if(!o)return a("Nothing selected to copy from");switch(e.modifier){case pe.REF:return hr(Ue(o.id),"ref");case pe.TITLE:return hr(o.title,"title");case pe.DESCRIPTION:return r?hr(r.props?.description??"","description"):a("No issue in scope");case pe.TAGS:{if(!r)return a("No issue in scope");let s=_t(r).map(({name:i})=>i);return hr(s.join(", "),"tags")}case pe.ASSIGNEES:{if(!r)return a("No issue in scope");let s=$t(r).map(({name:i})=>i);return hr(s.join(", "),"assignees")}default:return a("Yank one of: ref, title, description, tags, assignees")}};var Hc=async()=>{W(""),E({mode:y.DEFAULT});let e=Je();if(d(e))return a(e.message);if(e.value.syncStatus.status==="syncing")return a("Sync already in progress");E({syncStatus:{msg:"Syncing",status:"syncing"}});let t=await oo();return d(t)?(E({syncStatus:{msg:t.message,status:"failed"}}),t):(E({mode:y.DEFAULT,syncStatus:{msg:"Synced",status:"synced"}}),t)};var Pg=e=>e.action==="add.issue.comment",Wc=e=>Object.values(g().tags).find(t=>t.name===e),jc=e=>Object.values(g().contributors).find(t=>t.name===e),wt=async()=>{let e=await at();return d(e)?e:l("Resolved persist root",e.value)},Do=[{systemOnly:!0,intent:w.Move,description:"Internal move-state command",mode:y.COMMAND_LINE,action:Mc},{intent:w.Delete,description:"Delete the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to resolve child to delete");let o=await wt();if(d(o))return o;if(r.context==="COMMENT"){let s=r.id,i=A(t)?t.id:t.parentNodeId;if(!i)return a("Unable to resolve comment issue");let c=g().nodes[i];if(!c||!A(c))return a("Unable to resolve comment issue");let u=c.log?.filter(Pg).find(m=>m.payload.id===s);return u?u.payload.author!==e.value.userId?a("You can only delete your own comments"):B([{id:we(),action:"delete.issue.comment",payload:{id:s,issue:i},...e.value}],o.value):a("Unable to resolve comment")}return B([{id:we(),action:"delete.node",payload:{id:r.id},...e.value}],o.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Filter,description:"Filter the board, for example `:filter tag urgent`",mode:y.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=Y().commandMeta,n=/(!=|=)/,[r]=e.split(n);if(!r||!(i=>ie(x.FILTER).map(c=>c.split(n)[0]).includes(i))(r))return a("Invalid filter modifier");let s={target:r,operator:"=",value:t.trim()};return he(i=>({...i,filters:e==="clear"?[]:[...i.filters,s],mode:y.DEFAULT})),l("Filter updated",null)}},{intent:w.ViewHelp,description:"Open the help screen",mode:y.COMMAND_LINE,action:()=>{let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,breadCrumb:r,selectedIndex:t,selectedNode:n}}),E({mode:y.HELP}),l("Viewing help",null)}},{intent:w.CloseIssue,description:"Move the selected issue to the closed swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to close issue, no target found");if(!A(r))return a("Cannot close in this context");let o=g().nodes[me];if(!o)return a("Unable to locate closed swimlane");if(r.parentNodeId===o.id)return a("Issue is already closed");let s=await wt();if(d(s))return s;let i=s.value,c=sn(o.id,r.id,{at:"end"},e.value,i);if(d(c))return c;let u=B([{id:we(),action:"close.issue",payload:{id:r.id,parent:o.id,rank:c.value},...e.value}],i);return d(u)?u:l("Issue closed",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.ReopenIssue,description:"Move a closed issue back to its previous swimlane",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Unable to reopen issue, no target found");let o=r.context==="TICKET"?l("Resolved ticket",r):It(r.id,"TICKET");if(d(o))return a("Cannot reopen in this context");let s=o.value,i=g().nodes[me];if(!i)return a("Unable to locate closed swimlane");if(s.parentNodeId!==i.id)return a("Issue is not closed");if(!A(s))return a("Target node is not issue");let c=Ao(s);if(!c)return a("Unable to resolve previous parent from issue history");if(c===i.id)return a("Previous parent resolves to closed swimlane");let u=g().nodes[c];if(!u)return a("Previous parent no longer exists");let m=await wt();if(d(m))return m;let p=m.value,f=sn(u.id,s.id,{at:"end"},e.value,p);if(d(f))return f;let b=B([{id:we(),action:"reopen.issue",payload:{id:s.id,parent:u.id,rank:f.value},...e.value}],p);return d(b)?b:l("Issue reopened",null)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Init,description:"Initialize Epiq in the current git repository",mode:y.COMMAND_LINE,action:Nc},{intent:w.NewItem,description:"Create a new board, swimlane, or issue",mode:y.COMMAND_LINE,action:Pc,onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Rename,description:"Rename the currently selected node",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{contextNode:t,selectedIndex:n}=g(),r=G(t.id)[n];if(!r)return a("Missing node");if(r.readonly)return a("Cannot rename readonly node");let o=qd();if(!o)return a("Provide a title");let s=await wt();return d(s)?s:B([{id:we(),action:"edit.title",payload:{id:r.id,name:o},...e.value}],s.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UntagTicket,description:"Remove a tag from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let o=Wc(r);if(!o)return a(`Tag "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid untag target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to untag issue in this context");let c=i.value;if(!A(c))return a("Target node is not issue");if(!(c.props.tags??[]).includes(o.id))return a("Issue is not tagged with that tag");let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.tag",payload:{id:c.id,tag:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.TagTicket,description:"Add or create a tag on the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide a tag");let{selectedNode:o}=g();if(!o)return a("Invalid tag target");let s=It(o.id,"TICKET");if(d(s))return a("Unable to tag issue in this context");let i=s.value;if(!A(i))return a("Target node is not issue");let c=await wt();if(d(c))return c;let u=Wc(r),m=u?.id??we();return(i.props.tags??[]).includes(m)?a("Already tagged with that tag"):B([...u?[]:[{id:we(),action:"create.tag",payload:{id:m,name:r},...e.value}],{id:we(),action:"add.issue.tag",payload:{id:i.id,tag:m},...e.value}],c.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.AssignUserToTicket,description:"Assign a user to the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee");let{selectedIndex:o,contextNode:s}=g(),i=G(s.id)[o];if(!i)return a("Invalid assign target");let c=It(i.id,"TICKET");if(d(c))return a("Unable to assign issue in this context");let u=c.value;if(!A(u))return a("Target node is not issue");let m=await wt();if(d(m))return m;let p=jc(r),f=p?.id??we();return(u.props.assignees??[]).includes(f)?a("Assignee already assigned"):B([...p?[]:[{id:we(),action:"create.contributor",payload:{id:f,name:r},...e.value}],{id:we(),action:"add.issue.assignee",payload:{id:u.id,assignee:f},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.UnassignUserFromTicket,description:"Remove an assignee from the selected issue",mode:y.COMMAND_LINE,action:async()=>{let e=se();if(d(e))return a("Unable to resolve user ID");let{modifier:t,inputString:n}=Y().commandMeta,r=(t||n).trim();if(!r)return a("Provide an assignee to remove");let o=jc(r);if(!o)return a(`Assignee "${r}" does not exist`);let{selectedNode:s}=g();if(!s)return a("Invalid unassign target");let i=It(s.id,"TICKET");if(d(i))return a("Unable to unassign in this context");let c=i.value;if(!A(c))return a("Target node is not issue");if(!(c.props.assignees??[]).includes(o.id))return a(`Issue is not assigned to "${r}"`);let m=await wt();return d(m)?m:B([{id:we(),action:"remove.issue.assignee",payload:{id:c.id,assignee:o.id},...e.value}],m.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Comment,description:"Add a comment to the selected issue",mode:y.COMMAND_LINE,action:async(e,t)=>{let n=t.inputString.trim();if(!n)return a("Provide a comment");if(n.length>Pn)return a(`Cannot exceed ${Pn} characters`);let r=se();if(d(r))return a("Unable to resolve user ID");let{breadCrumb:o,selectedNode:s}=g(),i=Le([...o,s],"TICKET");if(d(i))return a("Edit target must be an issue");let c=i.value;if(!c)return a("Invalid comment target");let u=c.context==="TICKET"?l("Resolved ticket",c):It(c.id,"TICKET");if(d(u))return a("Unable to comment on issue in this context");let m=u.value;if(!A(m))return a("Target node is not issue");let p=await wt();return d(p)?p:B([{id:we(),action:"add.issue.comment",payload:{id:we(),issue:m.id,author:r.value.userId,md:n},...r.value}],p.value)},onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Sync,description:"Pull, commit, and push Epiq state",mode:y.COMMAND_LINE,action:Hc},{intent:w.Peek,description:"View board state at another point in time",mode:y.COMMAND_LINE,action:Dc},{intent:w.Replay,description:"Replay board history forward from a point in time",mode:y.COMMAND_LINE,action:Fc},{intent:w.Export,description:"Export the current board layout to markdown",mode:y.COMMAND_LINE,action:async()=>{let e=await yc();return d(e)?e:(E({mode:y.DEFAULT}),l("Export successful",!0))}},{intent:w.Exit,description:"Exit the application",mode:y.COMMAND_LINE,action:async()=>(T.exit(),l("Exit successful",!0))},{intent:w.Edit,description:"Edit title or description",mode:y.COMMAND_LINE,action:async(e,t)=>Ic(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Yank,description:"Yank (copy) ref, title, description, tags, or assignees to the clipboard",mode:y.COMMAND_LINE,action:async(e,t)=>$c(t),onSuccess:()=>E({mode:y.DEFAULT})},{intent:w.Config,description:"Update editor, username, view, autosync, or sync debounce",mode:y.COMMAND_LINE,action:(e,t)=>{let n=t.inputString.trim();switch(t.modifier){case ne.USERNAME:{let{userId:r,preferredEditor:o,userName:s}=K(),i=n||s,c=r??we();if(!i||!c)return a("Unable to resolve user name or id");let u=Ze({userName:i,userId:c,preferredEditor:o??""});return d(u)?u:(Fe({userName:i,userId:c}),E({mode:y.DEFAULT}),l(`Username set to "${i}"`,null))}case ne.EDITOR:{if(!n)return a("No editor provided");let r=Ze({preferredEditor:n});return d(r)?r:(Fe({preferredEditor:n}),E({mode:y.DEFAULT}),l(`Editor configuration set to "${n}"`,null))}case ne.VIEW:{if(n!=="wide"&&n!=="dense")return a("Invalid view mode");let r=Ze({viewMode:n});return d(r)?r:(Fe({viewMode:n}),E({mode:y.DEFAULT}),l(`View set to "${n}"`,null))}case ne.AUTOSYNC:return Uc();case ne.LOG_LEVEL:return Oc();case ne.SYNC_DEBOUNCE_MS:return Bc();case ne.ATTACHMENT_MAX_KB:return Td();default:return a("Unknown config command")}}},{intent:w.Coffee,description:"Sponsor the development of Epiq!",mode:y.COMMAND_LINE,action:()=>{let e=Y().commandMeta.modifier;return e==="custom"?yr("https://github.com/sponsors/ljtn?frequency=one-time&sponsor=ljtn"):yr(`https://github.com/sponsors/ljtn/sponsorships?sponsor=ljtn&preview=true&frequency=one-time&amount=${e}`),W(""),l("Thanks you!",null)}}];var Lg=new Set(["peek","replay","filter","view-help","yank"]),yt=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=Y();if(!t)return a("No command to confirm");if(!e&&n===pt.Invalid)return a("Invalid command");let s=ho(t);jd();let{readOnly:i}=g();if(i&&!Lg.has(s))return ur({status:Pt.Fail,message:"Command not available in readonly state",value:null});let c=Do.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===s);if(!c)return ur({status:Pt.Fail,message:"Command not found",value:null});let u;try{u=await c.action(c,{command:t,inputString:o,modifier:r})}catch(m){return ur({status:Pt.Fail,message:m instanceof Error?m.message:"Command failed",value:null})}return d(u)?ur(u):(Vd({addToHistory:!e}),c.onSuccess?.(),K().autoSync&&io(),u)};var Fo=[{intent:h.Exit,mode:y.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(E({mode:y.COMMAND_LINE}),W("move cancel"),yt({isForceExecutedBySystem:!0}))},{intent:h.InitMove,mode:y.DEFAULT,description:"[m] move (init/confirm)",action:()=>(E({mode:y.COMMAND_LINE}),W("move start"),yt({isForceExecutedBySystem:!0}))},{intent:h.ConfirmMove,mode:y.MOVE,action:()=>(E({mode:y.COMMAND_LINE}),W("move confirm"),yt({isForceExecutedBySystem:!0}))}],Bo=[{intent:h.MovePreviousItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveNextItem,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move next"),yt({isForceExecutedBySystem:!0})):a("No pending move")}],Vc=[{intent:h.MoveToNextContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-next"),yt({isForceExecutedBySystem:!0})):a("No pending move")},{intent:h.MoveToPreviousContainer,mode:y.MOVE,action:()=>Kt()?(E({mode:y.COMMAND_LINE}),W("move to-previous"),yt({isForceExecutedBySystem:!0})):a("No pending move")}];var Kc={[L.WORKSPACE]:[...Fo,...Bo],[L.BOARD]:[...Fo,...Bo],[L.SWIMLANE]:[...Fo,...Bo,...Vc],[L.TICKET]:[],[L.FIELD]:[],[L.FIELD_LIST]:[],[L.TEXT]:[],[L.COMMENT]:[]};import kg from"node:fs";import Dg from"node:path";var Gc=e=>{let t=Ye(process.cwd());if(d(t))return a("Unable to resolve project root");let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=Mn(e.hash,e.ext),o=Dg.join(Kn(n.value),r);return kg.existsSync(o)?(yr(o),l(`Opened ${e.name}`,null)):a("Attachment file not found \u2014 run :sync to fetch it")};var zc=()=>{W("");let{pendingNavTarget:e}=jt();E({mode:y.DEFAULT}),e&&T.navigate(e),Vt({pendingNavTarget:void 0})},qc=[{intent:h.ExitCommandLine,mode:y.HELP,action:()=>(zc(),l("Exiting help",null))},{intent:h.Exit,mode:y.HELP,action:()=>(zc(),l("Closed help",null))},{intent:h.NavPreviousItem,mode:y.HELP,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous help item",null))},{intent:h.NavNextItem,mode:y.HELP,action:()=>(T.navigateToNextItem(),l("Navigating to next help item",null))},{intent:h.NavToPreviousContainer,mode:y.HELP,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous help container",null))},{intent:h.NavToNextContainer,mode:y.HELP,action:()=>(T.navigateToNextContainer(),l("Navigating to next help container",null))}];var Fg=e=>{E({mode:y.COMMAND_LINE});let{pendingNavTarget:t}=jt();t&&T.navigate(t),Vt({pendingNavTarget:void 0}),W(`${e} `)},Yc=()=>{W("");let{pendingNavTarget:e}=jt();e&&T.navigate(e),Vt({pendingNavTarget:void 0}),E({mode:y.DEFAULT})},Xc=[{intent:h.InitCommandPalette,mode:y.DEFAULT,description:"[?] view command palette (explore descriptions for every command)",action:()=>{W("");let{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}=g();return Vt({pendingNavTarget:{contextNode:e,selectedIndex:t,selectedNode:n,breadCrumb:r}}),E({mode:y.PALETTE}),l("Opening command palette",null)}},{intent:h.Confirm,mode:y.PALETTE,action:()=>{let{selectedNode:e}=g();if(!e||!kt(e))return a("Command only applicable on text nodes");if(e.props.disabled)return a("Command is not available in this context");let t=e.title;return t?(Fg(t),l("Selected command",t)):l("No command selected",null)}},{intent:h.ExitCommandLine,mode:y.PALETTE,action:()=>(Yc(),l("Exiting palette",null))},{intent:h.Exit,mode:y.PALETTE,action:()=>(Yc(),l("Closed command palette",null))},{intent:h.NavPreviousItem,mode:y.PALETTE,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.PALETTE,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.PALETTE,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.PALETTE,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Jc=[...qc,...Xc,{intent:h.AddItem,mode:y.DEFAULT,description:"[n] new...",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.NEW} `),l("Adding new item",null))},{intent:h.Delete,mode:y.DEFAULT,description:"[d] delete",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.DELETE} `),l("Deleting item",null))},{intent:h.InitCommandLine,mode:y.DEFAULT,description:"[:] focus command line",action:()=>(E({mode:y.COMMAND_LINE}),W(""),l("Entering command line mode",null))},{intent:h.Confirm,mode:y.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>{let{selectedNode:e,contextNode:t}=g();if(!q(e?.id??"")?.length){let r=e?I.getAttachment(e.id):void 0;if(r)return Gc(r);if(e?.title===J.DESCRIPTION)return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0);if(e?.title===J.ASSIGNEES)return E({mode:y.COMMAND_LINE}),W(`${x.ASSIGN} `),l("Propose command",!0);if(e?.title===J.TAGS)return E({mode:y.COMMAND_LINE}),W(`${x.TAG} `),l("Propose command",!0);if(t.title===J.DESCRIPTION&&e?.context==="TEXT")return E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Propose command",!0)}return T.enterChildNode(),l("Entering context",null)}},{intent:h.Yank,mode:y.DEFAULT,description:"[y] yank to clipboard",action:()=>{let{selectedNode:e}=g(),t=e?.title===J.DESCRIPTION?pe.DESCRIPTION:e?.title===J.TAGS?pe.TAGS:e?.title===J.ASSIGNEES?pe.ASSIGNEES:pe.REF,r=ie(x.YANK).includes(t)?t:pe.REF;return E({mode:y.COMMAND_LINE}),W(`${x.YANK} ${r}`),l("Propose command",!0)}},{intent:h.EditTitle,mode:y.DEFAULT,description:"[r] rename title",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} title ${g().selectedNode?.title}`),l("Exiting context",null))},{intent:h.EditDescription,mode:y.DEFAULT,description:"[e] edit description",action:()=>(E({mode:y.COMMAND_LINE}),W(`${x.EDIT} description `),l("Exiting context",null))},{intent:h.Exit,mode:y.DEFAULT,description:"[q] exit context",action:()=>(T.enterParentNode(),l("Exiting context",null))},{intent:h.NavPreviousItem,mode:y.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(T.navigateToPreviousItem(),l("Navigating to previous item",null))},{intent:h.NavNextItem,mode:y.DEFAULT,action:()=>(T.navigateToNextItem(),l("Navigating to next item",null))},{intent:h.NavToPreviousContainer,mode:y.DEFAULT,action:()=>(T.navigateToPreviousContainer(),l("Navigating to previous container",null))},{intent:h.NavToNextContainer,mode:y.DEFAULT,action:()=>(T.navigateToNextContainer(),l("Navigating to next container",null))}];var Bg=500,Ug=e=>e.replace(/[\r\n]/g,"").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g,""),Qc=e=>{let t=Ug(e);t&&vo(n=>(n+t).slice(0,Bg))};var Og=[y.COMMAND_LINE,y.PALETTE],_g=e=>[{intent:h.MoveCursorLeft,mode:e,action:()=>(Ys(-1),l("Moving cursor left",null))},{intent:h.MoveCursorRight,mode:e,action:()=>(Ys(1),l("Moving cursor right",null))},{intent:h.MoveCursorLeftOfWord,mode:e,action:()=>(Xs("left"),l("Moving cursor left of word",null))},{intent:h.MoveCursorRightOfWord,mode:e,action:()=>(Xs("right"),l("Moving cursor right of word",null))},{intent:h.AutoCompleteCommand,mode:e,action:()=>(vo((t,{remainder:n})=>{let r=n?t+n:t,o="";return r==="edit title "&&(o=g().selectedNode?.title??""),r+o}),l("Auto-completing command",null))},{intent:h.CaptureInput,mode:e,action:(t,{sequence:n})=>(Qc(n??""),l("Capturing input",null))},{intent:h.EraseInput,mode:e,action:()=>(Hd(),l("Erasing input",null))},{intent:h.EraseInputWord,mode:e,action:()=>(Wd(),l("Erasing input word",null))}],Zc=[{intent:h.Confirm,mode:y.COMMAND_LINE,action:()=>(yt(),l("Executing command",null))},{intent:h.ViewHelp,mode:y.DEFAULT,action:()=>(E({mode:y.HELP}),l("Viewing help",null))},...Og.flatMap(_g),{intent:h.ExitCommandLine,mode:y.COMMAND_LINE,action:()=>(E({mode:y.DEFAULT}),l("Exiting command line",null))},{intent:h.GetLastCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Kd(),l("Getting last command from history",null))},{intent:h.GetNextCommandFromHistory,mode:y.COMMAND_LINE,action:()=>(Gd(),l("Getting next command from history",null))}];import nl from"chalk";var Uo=nl.dim.hex(v.secondary2)(": for command line"),el="q to exit",tl=`${nl.hex(v.accent)("m")} to confirm`,li={[L.WORKSPACE]:[Uo],[L.BOARD]:[Uo],[L.BOARD+y.COMMAND_LINE]:[Uo],[L.SWIMLANE]:[Uo],[L.TICKET+y.HELP]:[el],[L.SWIMLANE+y.HELP]:[el],[L.TICKET]:[],[L.FIELD]:[],[L.SWIMLANE+y.MOVE]:[tl],[L.TICKET+y.MOVE]:[tl]};var xr=e=>e.trim().toLocaleLowerCase(),$g=e=>{let{tags:t}=g();return(e.props.tags??[]).map(n=>t[n]?.name).filter(n=>!!n)},Hg=e=>{let{contributors:t}=g();return(e.props.assignees??[]).map(n=>t[n]?.name).filter(n=>!!n)},rl=(e,t)=>{let n=xr(t.value);if(!n)return!0;switch(t.target){case"title":return xr(e.title??"").includes(n);case"description":return xr(e.props.description??"").includes(n);case"tag":return $g(e).map(xr).some(o=>o.includes(n));case"assignee":return Hg(e).map(xr).some(o=>o.includes(n));case"ref":return Ia(e.id,t.value);default:return!0}};function ol(e,t,n){let r=t[e];if(!r)return a("buildBreadCrumb(): current node not found");let o=[],s=r;for(;s&&(o.push(s),!(s.id===n||!s.parentNodeId));)s=t[s.parentNodeId];let i=o[o.length-1];return!i||i.id!==n?a("buildBreadCrumb(): node is not connected to root"):(o.reverse(),l("Breadcrumb built",o))}var sl=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 gn,ui,mi=new Set,il=()=>{for(let e of mi)e()},jg=e=>(mi.add(e),()=>mi.delete(e));function al(e){let{contextNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:s}=e;if(!t)return a("derive(): contextNodeId is missing");if(!r)return a("derive(): rootNode is missing");if(!o[r])return a("derive(): unable to find root node");let c=o[t];if(!c)return a("Unable to derive state, contextNode not found");let u=ol(t,o,r);if(d(u))return logger.error(u.message),u;let m=u.value,{context:p}=c,f=li[p+n]??li[p]??[],b=[...Jc,...Kc[p]??[],...Zc],N=sl(b),S=Vg(o,s),R=S[t]?.[e.selectedIndex]??null;return l("Derived successfully",{...e,contextNode:c,breadCrumb:m,availableHints:f,availableActions:b,actionIndex:N,selectedNode:R,renderedChildrenIndex:S})}var g=()=>{if(!gn)throw new Error("State not initialized. Call initWorkspaceState() first.");return gn},Je=()=>gn?l("Retrieved state",gn):a("State not initialized. Call initWorkspaceState() first.");function nr(e){ui=e;let t=Ye(process.cwd()),n=!1;if(!d(t)){let s=Lt(t.value);if(d(s))return a(s.message);n=!0}let r={readOnly:!1,filters:[],tags:{},contributors:{},mode:y.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,contextNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""},eventLog:[],unappliedEvents:[],replay:null,timeMode:"live",hasProjectDefinition:n,hasInitializingEvents:!1,comments:{},attachments:{}},o=al(r);return d(o)?o:(gn=o.value,il(),l("State initialized",null))}function he(e){let t=g(),n=e(t),r=al(n);return d(r)?a(r.message??"Unable to update state"):(gn=r.value,il(),l("State updated",null))}var E=e=>he(t=>({...t,...e}));var H=()=>Wg(jg,g,g),Vg=(e,t)=>{let n={};for(let r of Object.values(e))A(r)&&t.length>0&&!t.every(o=>rl(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,s)=>{let i=e[o.id],c=e[s.id];return!i||!c?0:i.rank.localeCompare(c.rank)});return n},G=e=>g()?.renderedChildrenIndex[e]??[],Gt=()=>ui?nr(ui):a("Cannot reset state: no initial workspace found"),Rn=()=>gn!==void 0;var pi=e=>{Rn()&&(E({syncStatus:e}),tn({type:"sync-status",payload:e}))},Oo=(e="Syncing...")=>{pi({status:"syncing",msg:e})},_o=(e="Synced")=>{pi({status:"synced",msg:e})},fi=e=>{pi({status:"failed",msg:e})},Qe=e=>(fi(e),a(e));import{decodeTime as ZL}from"ulid";var Kg=async({cwd:e,ensureUpstream:t})=>{logger.debug("[sync] ensureSyncReady:start",{cwd:e,ensureUpstream:t});let n=X("getRepoRootDir",await dt(e));if(d(n))return a(n.message);let r=n.value;logger.debug("[sync] repo root",r);let o=X("getStateBranchRoot",Pe({repoRoot:r}));if(d(o))return a(o.message);let s=o.value;logger.debug("[sync] state branch root",s);let i=X("ensureInitialCommit",await na(r));if(d(i))return a(i.message);logger.debug("[sync] initial commit result",{created:i.value}),logger.debug("[sync] bootstrapping state branch storage",{repoRoot:r,stateBranchRoot:s,ensureUpstream:t});let c=X("bootstrapStateBranchStorage",await sa({repoRoot:r,stateBranchRoot:s,ensureUpstream:t}));if(d(c))return a(c.message);logger.debug("[sync] bootstrap result",{bootstrapped:c.value,stateBranchRoot:s}),logger.debug("[sync] checking state branch git operation",{stateBranchRoot:s});let u=X("hasInProgressGitOperation(stateBranchRoot)",await Fr(s));if(d(u))return a(u.message);if(logger.debug("[sync] state branch git operation check result",{inProgress:u.value}),u.value)return logger.info("[sync] state branch git operation in progress"),a("Cannot sync while a git operation is in progress in the state branch");logger.debug("[sync] ensuring state branch layout",{repoRoot:r,stateBranchRoot:s});let m=X("ensureStateBranchLayout",Zi(r,s));return d(m)?a(m.message):(logger.debug("[sync] state branch layout ready"),logger.debug("[sync] ensureSyncReady:done",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}),l("Sync preconditions satisfied",{repoRoot:r,stateBranchRoot:s,bootstrapped:c.value}))},Gg=async({repoRoot:e,stateBranchRoot:t,ownEventFileName:n})=>{logger.debug("[sync] committing own event file from state branch",{ownEventFileName:n,stateBranchRoot:t}),logger.debug("[sync] staging own event file",{stateBranchRoot:t,ownEventFileName:n});let r=X("stageStateBranchOwnEventFile",await Wr({stateBranchRoot:t,eventFileName:n}));if(d(r))return a(r.message);let o=X("stageStateBranchMediaFiles",await ra({stateBranchRoot:t}));if(d(o))return a(o.message);let s=X("hasStagedChanges(after stage)",await Gi(t));if(d(s))return a(s.message);if(logger.debug("[sync] state branch change check after stage result",{changed:s.value}),!s.value)return logger.info("[sync] no own event file changes to commit"),l("No own event file changes to commit",{createdCommit:!1});logger.debug("[sync] creating sync commit");let i=X("createStateBranchSyncCommit",await oa({repoRoot:e,stateBranchRoot:t}));return d(i)?a(i.message):(logger.debug("[sync] created sync commit",i.value),l("Committed own event file",{createdCommit:!0,commitSha:i.value}))},so=async({cwd:e=process.cwd(),ownEventFileName:t})=>{if(logger.debug("[sync] syncEpiqWithRemote:start",{cwd:e,ownEventFileName:t}),t.includes("/")||t.includes("\\"))return logger.error("[sync] invalid own event file name: contains path separator",{ownEventFileName:t}),a("Own event file must be a file name, not a path");if(!t.endsWith(".jsonl"))return logger.error("[sync] invalid own event file name: missing .jsonl suffix",{ownEventFileName:t}),a("Own event file must end with .jsonl");Oo();let n=X("ensureSyncReady",await Kg({cwd:e,ensureUpstream:!0}));if(d(n))return Qe(n.message);let{repoRoot:r,stateBranchRoot:o,bootstrapped:s}=n.value,i=X("isDetachedHead(stateBranchRoot)",await zi(o));if(d(i))return Qe(i.message);if(logger.debug("[sync] detached state branch check result",{detached:i.value}),i.value)return Qe("Cannot run :sync while the state branch is in detached HEAD state");let c=!1,u,m=!1,p=!1,f=X("getStateBranch",hn(r));if(d(f))return Qe(f.message);let b=f.value;logger.debug("[sync] resolved state branch",{stateBranch:b,stateBranchRoot:o});let N=X("commitOwnEventFileToStateBranch",await Gg({repoRoot:r,stateBranchRoot:o,ownEventFileName:t}));if(d(N))return Qe(N.message);c=N.value.createdCommit,u=N.value.commitSha;let S=X("pullBranchRebaseIfPresent",await hs({cwd:o,branch:b}));if(d(S))return Qe(S.message);if(m=S.value,c||s){logger.info("[sync] pushing state branch",{createdCommit:c,bootstrapped:s,stateBranchRoot:o});let R=X("pushStateBranch",await Jn({stateBranchRoot:o,repoRoot:r}));if(d(R)&&Ki(R.message)){let M=X("pullBranchRebaseIfPresent(retry)",await hs({cwd:o,branch:b}));if(d(M))return Qe(M.message);m=m||M.value,R=X("pushStateBranch(retry)",await Jn({stateBranchRoot:o,repoRoot:r}))}if(d(R))return Qe(R.message);p=R.value}if(c){logger.debug("[sync] resolving final sync commit sha",{stateBranchRoot:o});let R=X("git rev-parse HEAD",await _({args:["rev-parse","HEAD"],cwd:o}));if(d(R))return Qe(R.message);u=R.value.stdout.trim(),logger.debug("[sync] final sync commit sha",u)}return _o(p?"Synced and pushed":m||c?"Synced local state":"Already synced"),logger.debug("[sync] syncEpiqWithRemote:done"),l("Synced event logs with state branch",{repoRoot:r,stateBranchRoot:o,createdCommit:c,commitSha:u,pulled:m,pushed:p,bootstrapped:s})};var gi=()=>{let e=wn();return d(e)?mt:e.value.attachmentMaxKb??mt},yi=e=>{let t=Ye(e??process.cwd());return d(t)?a(t.message):l("Resolved Epiq repo root",t.value)},Me=async e=>{let t=yi(e);if(d(t))return t;let n=Pe({repoRoot:t.value});if(d(n))return a(n.message);let r=vn(),o=await en({repoRoot:t.value,stateBranchRoot:n.value,stateBranchName:r.stateBranch});if(d(o))return a(o.message);let s=await _({cwd:n.value,args:["pull","--ff-only"]});d(s)&&oe.info(3,s.message);let i=Et(n.value);if(d(i))return a(i.message);let c=an(i.value);return d(c)?a(c.message):l("Booted Epiq state",{repoRoot:t.value,stateBranchRoot:n.value})},ke=()=>{let e=wn();return d(e)?a(e.message):e.value.userId?e.value.userName?l("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):a("Unable to retrieve user name"):a("Unable to retrieve user id")},je=()=>{let e=Je();return d(e)?a(e.message):e},cl=e=>(e.props.tags??[]).map(t=>I.getTag(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)})),ll=e=>(e.props.assignees??[]).map(t=>I.getContributor(t)).filter(t=>t!=null).map(t=>({id:t.id,name:t.name,color:le(t.name)}));var ul=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes).filter(A).filter(o=>e.includeClosed||o.parentNodeId!==me).map(o=>({id:o.id,ref:Ue(o.id),title:lt(o.title),description:o.props.description??"",parentNodeId:o.parentNodeId,isClosed:o.parentNodeId===me,readonly:!!o.readonly,tags:cl(o),assignees:ll(o)}));return l("Listed issues",r)},ml=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Sn(e.parentId,n.value,t.value.stateBranchRoot);if(d(r))return r;let o=wo({name:e.title,parent:e.parentId,user:n.value,rank:r.value});if(d(o))return o;let s=o.value,i=B([...s],t.value.stateBranchRoot);if(d(i))return a(i.message);let c=s.find(u=>u.action==="add.issue")?.payload.id;return c?l("Created issue",{id:c,title:e.title,parentId:e.parentId}):a("Unable to determine created issue id")},pl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=sn(me,e.issueId,{at:"end"},n.value,t.value.stateBranchRoot);if(d(r))return r;let o={id:ge(),...n.value,action:"close.issue",payload:{id:e.issueId,parent:me,rank:r.value}},s=B([o],t.value.stateBranchRoot);return d(s)?a(s.message):l("Closed issue",{id:e.issueId})},fl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Target node is not issue");if(o.parentNodeId!==me)return a("Issue is not closed");let s=Ao(o);if(!s)return a("Unable to resolve previous parent from issue history");if(s===me)return a("Previous parent resolves to closed swimlane");let i=r.value.nodes[s];if(!i)return a("Previous parent no longer exists");let c=sn(i.id,o.id,{at:"end"},n.value,t.value.stateBranchRoot);if(d(c))return c;let u={id:ge(),...n.value,action:"reopen.issue",payload:{id:o.id,parent:i.id,rank:c.value}},m=B([u],t.value.stateBranchRoot);return d(m)?a(m.message):l("Reopened issue",{id:o.id,parentId:i.id})},gl=async e=>{let t=yi(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=Pe({repoRoot:t.value});if(d(r))return r;let o=Et(r.value);if(d(o))return o;let s=an(o.value);if(d(s))return s;let i=sn(e.parentId,e.issueId,e.position??{at:"end"},n.value,r.value);if(d(i))return i;let c={id:ge(),...n.value,action:"move.node",payload:{id:e.issueId,parent:e.parentId,rank:i.value}},u=B([c],r.value);return d(u)?a(u.message):l("Moved issue",{id:e.issueId,parentId:e.parentId})},$o=async(e={})=>{Oo();let t=yi(e.repoRoot);if(d(t))return a("Sync failed");let n=ke();if(d(n))return n;let r=await so({cwd:t.value,ownEventFileName:on(n.value)});return d(r)?(fi(r.message),r):(_o(),l("Synced",r.value))};var vt=async(e={})=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=je();if(d(n))return n;let r=Object.values(n.value.nodes),o=r.filter(f=>Vr(f)&&!f.isDeleted),s=new Map,i=new Map;for(let f of r)if(!f.isDeleted){if(Dt(f)&&f.parentNodeId){let b=s.get(f.parentNodeId)??[];b.push(f),s.set(f.parentNodeId,b)}if(A(f)&&f.parentNodeId){let b=i.get(f.parentNodeId)??[];b.push(f),i.set(f.parentNodeId,b)}}let c=wn();if(d(c))return c;let u={};for(let f of r.filter(A))f.isDeleted||(u[f.id]=I.getCommentsByIssue(f.id).map(b=>{let N=I.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:{id:b.authorId,name:N?.name??"Unknown",color:le(N?.name??b.authorId)},createdAt:dl(b.id)}}));let m=new Map;for(let f of n.value.eventLog)f.action==="add.issue.attachment"&&m.set(f.payload.id,f.payload.author);let p={};for(let f of r.filter(A))f.isDeleted||(p[f.id]=I.getAttachmentsByIssue(f.id).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:Mn(b.hash,b.ext),bytes:b.bytes,createdAt:dl(b.id),canDelete:m.get(b.id)===c.value.userId})));return l("Retrieved Epiq GUI state",{boards:o.sort((f,b)=>f.rank.localeCompare(b.rank)).map(f=>({id:f.id,ref:Ue(f.id),title:f.title,swimlanes:(s.get(f.id)??[]).sort((b,N)=>b.rank.localeCompare(N.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly,issues:(i.get(b.id)??[]).sort((N,S)=>N.rank.localeCompare(S.rank)).map(N=>({id:N.id,ref:Ue(N.id),title:lt(N.title),description:N.props.description??"",readonly:!!N.readonly,tags:cl(N),assignees:ll(N),parentNodeId:N.parentNodeId,isClosed:N.parentNodeId===me})),parentNodeId:b.parentNodeId}))})),tags:Object.values(n.value.tags).map(f=>({...f,color:le(f.name)})),contributors:Object.values(n.value.contributors).map(f=>({...f,color:le(f.name)})),user:{name:c.value.userName??"",id:c.value.userId??"",color:le(c.value.userName??"")},commentsByIssueId:u,attachmentsByIssueId:p,attachmentMaxKb:gi()})},yl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=o.props.description??"";if(s===e.description)return l("No changes made",{id:e.issueId,description:s});let i={id:ge(),...n.value,action:"edit.description",payload:{id:e.issueId,md:e.description}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue description",{id:e.issueId,description:e.description})},vl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Edit target must be an issue");if(o.readonly)return a("Cannot edit readonly issue");let s=lt(e.title);if(!s.trim())return a("Issue title cannot be empty");if(o.title===s)return l("No changes made",{id:e.issueId,title:s});let i={id:ge(),...n.value,action:"edit.title",payload:{id:e.issueId,name:s}},c=B([i],t.value.stateBranchRoot);return d(c)?a(c.message):l("Edited issue title",{id:e.issueId,title:s})},hl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Tag target must be an issue");if(o.readonly)return a("Cannot tag readonly issue");let s=lt(e.tagName).trim();if(!s)return a("Tag name cannot be empty");let i=Object.values(r.value.tags).find(p=>p.name===s),c=i?.id??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.tag",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.tag",payload:{id:e.issueId,tag:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue tag",{id:e.issueId,tag:{id:c,name:s}})},xl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Untag target must be an issue");if(o.readonly)return a("Cannot untag readonly issue");if(!r.value.tags[e.tagId])return a("Tag not found");let s={id:ge(),...n.value,action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue tag",{id:e.issueId,tagId:e.tagId})},bl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Assign target must be an issue");if(o.readonly)return a("Cannot assign readonly issue");let s=lt(e.assigneeName).trim();if(!s)return a("Assignee name cannot be empty");let i=Object.values(r.value.contributors).find(p=>p.name===s),c=i?.id??ge(),u=[...i?[]:[{id:ge(),...n.value,action:"create.contributor",payload:{id:c,name:s}}],{id:ge(),...n.value,action:"add.issue.assignee",payload:{id:e.issueId,assignee:c}}],m=B(u,t.value.stateBranchRoot);return d(m)?a(m.message):l("Added issue assignee",{id:e.issueId,assignee:{id:c,name:s}})},Il=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Unassign target must be an issue");if(o.readonly)return a("Cannot unassign readonly issue");if(!r.value.contributors[e.assigneeId])return a("Assignee not found");let s={id:ge(),...n.value,action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},i=B([s],t.value.stateBranchRoot);return d(i)?a(i.message):l("Removed issue assignee",{id:e.issueId,assigneeId:e.assigneeId})},Ho=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Comment target must be an issue");if(o.readonly)return a("Cannot comment on readonly issue");let s=e.body.trim();if(!s)return a("Comment cannot be empty");let i=ge(),c={id:ge(),...n.value,action:"add.issue.comment",payload:{id:i,issue:e.issueId,md:s,author:n.value.userId}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Added issue comment",{id:i,issueId:e.issueId,body:s})},Wo=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.comment"&&m.payload.id===e.commentId);if(!o)return a("Unable to resolve comment");if(o.payload.author!==n.value.userId)return a("You can only delete your own comments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!A(s))return a("Comment target must be an issue");if(s.readonly)return a("Cannot delete comment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.comment"&&m.payload.id===e.commentId))return l("Comment already deleted",{id:e.commentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.comment",payload:{id:e.commentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue comment",{id:e.commentId,issueId:o.payload.issue})},El=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.nodes[e.issueId];if(!o)return a("Issue not found");if(!A(o))return a("Attachment target must be an issue");if(o.readonly)return a("Cannot attach to readonly issue");let s=Buffer.from(e.dataBase64??"","base64"),i=Ad(t.value.stateBranchRoot,s,gi());if(d(i))return i;let c=lt(e.name??"").trim()||"image",u=ge(),m={id:ge(),...n.value,action:"add.issue.attachment",payload:{id:u,issue:e.issueId,author:n.value.userId,hash:i.value.hash,ext:i.value.ext,name:c,bytes:i.value.bytes}},p=B([m],t.value.stateBranchRoot);return d(p)?a(p.message):l("Added issue attachment",{id:u,issueId:e.issueId,fileName:Mn(i.value.hash,i.value.ext),bytes:i.value.bytes})},Cl=async e=>{let t=await Me(e.repoRoot);if(d(t))return t;let n=ke();if(d(n))return n;let r=je();if(d(r))return r;let o=r.value.eventLog.find(m=>m.action==="add.issue.attachment"&&m.payload.id===e.attachmentId);if(!o)return a("Unable to resolve attachment");if(o.payload.author!==n.value.userId)return a("You can only delete your own attachments");let s=r.value.nodes[o.payload.issue];if(!s)return a("Issue not found");if(!A(s))return a("Attachment target must be an issue");if(s.readonly)return a("Cannot delete attachment on readonly issue");if(r.value.eventLog.some(m=>m.action==="delete.issue.attachment"&&m.payload.id===e.attachmentId))return l("Attachment already deleted",{id:e.attachmentId,issueId:o.payload.issue});let c={id:ge(),...n.value,action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:o.payload.issue}},u=B([c],t.value.stateBranchRoot);return d(u)?a(u.message):l("Deleted issue attachment",{id:e.attachmentId,issueId:o.payload.issue})},Nl=async e=>{let t=await Me(e.repoRoot);return d(t)?t:Rd(t.value.stateBranchRoot,e.fileName,gi())};var Sl=e=>{let t,n,r=!1,o=!1,s=!1,i=()=>{let p=ar();if(d(p))return oe.error(p.message);let{autoSync:f,userName:b,preferredEditor:N}=p.value;return!!(f&&b&&N)},c=async()=>{if(!r){if(o){s=!0;return}o=!0;try{await $o({repoRoot:e.repoRoot}),tn({type:"state",payload:await vt({repoRoot:e.repoRoot})})}finally{o=!1,s&&(s=!1,c())}}},u=(p=750)=>{r||(n&&clearTimeout(n),n=setTimeout(()=>{c()},p))},m=()=>{if(r)return;let p=ar();if(d(p))return oe.error(p.message);let{autoSyncDebounceMs:f}=p.value;i()&&(t=setTimeout(()=>{c(),m()},f??15e3))};return m(),{scheduleSync:u,dispose:()=>{r=!0,t&&clearTimeout(t),n&&clearTimeout(n)}}};import{WebSocketServer as zg}from"ws";var Ve=(e,t)=>{e.send(JSON.stringify(t))},br=async(e,t)=>Ve(e,{type:"state",payload:await vt({repoRoot:t})}),ht=async(e,t,n,r,o)=>{if(Ve(e,{type:r,payload:o}),d(o))return Ve(e,{type:"failed",payload:o.message});n(),br(e,t)},Al=(e,t,{onStateChanged:n})=>{new zg({server:e,path:"/ws"}).on("connection",o=>{ia(o),o.on("message",async s=>{try{let i=JSON.parse(s.toString()),{type:c}=i;if(c==="state:get")return br(o,t);if(c==="sync"){let u=await $o({repoRoot:t});return Ve(o,{type:"sync:result",payload:u}),n(),br(o,t)}if(c==="issue:comment:add"){let u=await Ho({repoRoot:t,...i.payload});return ht(o,t,n,"issue:comment:add:result",u)}if(c==="issue:comment:delete"){let u=await Wo({repoRoot:t,...i.payload});return Ve(o,{type:"issue:comment:delete:result",payload:u}),d(u)?Ve(o,{type:"failed",payload:u.message}):(n(),br(o,t))}if(c==="issue:edit:description"){let u=await yl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:description:result",u)}if(c==="issue:edit:title"){let u=await vl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:edit:title:result",u)}if(c==="issue:tag:add"){let u=await hl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:add:result",u)}if(c==="issue:tag:remove"){let u=await xl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:tag:remove:result",u)}if(c==="issue:assignee:add"){let u=await bl({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:add:result",u)}if(c==="issue:assignee:remove"){let u=await Il({repoRoot:t,...i.payload});return ht(o,t,n,"issue:assignee:remove:result",u)}if(c==="issues:list")return Ve(o,{type:"issues",payload:await ul({repoRoot:t})});if(c==="issues:create"){let u=await ml({...i.payload,repoRoot:t});return Ve(o,{type:"issues:create:result",payload:u}),d(u)?tn({type:"failed",payload:u.message}):(tn({type:"issue:created",payload:u.value}),n(),br(o,t))}if(c==="issues:move"){if(!i.payload.position)return Ve(o,{type:"error",message:"Missing move position"});let u=await gl({...i.payload,repoRoot:t});return ht(o,t,n,"issues:move:result",u)}if(c==="issue:close"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await pl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:close:result",u)}if(c==="issue:reopen"){if(!i.payload.issueId)return Ve(o,{type:"error",message:"Missing issueId"});let u=await fl({repoRoot:t,issueId:i.payload.issueId});return ht(o,t,n,"issue:reopen:result",u)}return Ve(o,{type:"error",message:"Unknown message type"})}catch(i){return Ve(o,{type:"error",message:i instanceof Error?i.message:String(i)})}})})};var Xg=yn.dirname(Yg(import.meta.url)),Jg=process.env.IS_LOCAL==="true"?yn.resolve(process.cwd(),"dist/gui"):yn.join(Xg,"gui"),jo,Qg=async()=>(jo===void 0&&(jo=await import("node:sea").catch(()=>null)),jo?.isSea()?jo:null),ye=(e,t,n)=>{e.writeHead(t,{"content-type":"application/json"}),e.end(JSON.stringify(n))},Rl=async(e,t=1024*1024)=>new Promise((n,r)=>{let o="",s=0;e.on("data",i=>{if(s+=i.length,s>t){e.destroy(),r(new Error("Request body too large"));return}o+=i}),e.on("end",()=>{try{n(o?JSON.parse(o):{})}catch{r(new Error("Invalid JSON body"))}}),e.on("error",r)}),Zg=2*1024*1024,ey={png:"image/png",jpg:"image/jpeg",gif:"image/gif",webp:"image/webp"},ty=e=>e.endsWith(".html")?"text/html; charset=utf-8":e.endsWith(".js")?"text/javascript; charset=utf-8":e.endsWith(".css")?"text/css; charset=utf-8":e.endsWith(".json")?"application/json; charset=utf-8":e.endsWith(".ico")?"image/x-icon":"application/octet-stream",Tl=async(e,t)=>{let n=e==="/"?"index.html":decodeURIComponent(e).replace(/^\/+/,""),r=yn.resolve(Jg),o=yn.resolve(r,n),s=yn.relative(r,o);if(s.startsWith("..")||yn.isAbsolute(s))return ye(t,403,{isError:!0,message:"Forbidden"});let i=await Qg();try{let c=i?Buffer.from(i.getAsset(`gui/${s}`)):await wl(o);return t.writeHead(200,{"content-type":ty(o)}),t.end(c)}catch{return ye(t,404,{isError:!0,message:`Not found: ${n}`})}},ny=async(e,t=3710)=>new Promise((n,r)=>{let o=s=>{let i=u=>{if(e.off("listening",c),u.code==="EADDRINUSE"&&s===t){e.removeListener("error",i),o(0);return}r(u)},c=()=>{e.off("error",i);let u=e.address();if(!u||typeof u=="string"){r(new Error("Unable to resolve address"));return}n(u.port)};e.once("error",i),e.once("listening",c),e.listen(s,"127.0.0.1")};o(t)}),Ml=async e=>{let t=qg.createServer(async(o,s)=>{let i=new URL(o.url??"/","http://127.0.0.1");if(i.pathname==="/api/state")return ye(s,200,await vt({repoRoot:e.repoRoot}));if(o.method==="POST"&&i.pathname==="/api/comments")try{let c=await Rl(o);if(!c.issueId||!c.body?.trim())return ye(s,400,{isError:!0,message:"Missing issueId or body"});let u=await Ho({repoRoot:e.repoRoot,issueId:c.issueId,body:c.body});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add comment"})}if(o.method==="POST"&&i.pathname==="/api/attachments")try{let c=await Rl(o,Zg);if(!c.issueId||!c.dataBase64)return ye(s,400,{isError:!0,message:"Missing issueId or dataBase64"});let u=await El({repoRoot:e.repoRoot,issueId:c.issueId,name:c.name??"",dataBase64:c.dataBase64});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}catch(c){return ye(s,400,{isError:!0,message:c instanceof Error?c.message:"Unable to add attachment"})}if(o.method==="DELETE"&&i.pathname.startsWith("/api/attachments/")){let c=decodeURIComponent(i.pathname.replace("/api/attachments/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing attachment id"});let u=await Cl({repoRoot:e.repoRoot,attachmentId:c});return d(u)?ye(s,400,{isError:!0,message:u.message}):ye(s,200,await vt({repoRoot:e.repoRoot}))}if(o.method==="GET"&&i.pathname.startsWith("/media/")){let c=decodeURIComponent(i.pathname.replace("/media/","")),u=await Nl({repoRoot:e.repoRoot,fileName:c});if(d(u))return ye(s,404,{isError:!0,message:u.message});try{let m=await wl(u.value.filePath);return s.writeHead(200,{"content-type":ey[u.value.ext]??"application/octet-stream","cache-control":"public, max-age=31536000, immutable"}),s.end(m)}catch{return ye(s,404,{isError:!0,message:"Attachment blob not found"})}}if(o.method==="DELETE"&&i.pathname.startsWith("/api/comments/")){let c=decodeURIComponent(i.pathname.replace("/api/comments/",""));if(!c)return ye(s,400,{isError:!0,message:"Missing comment id"});let u=await Wo({repoRoot:e.repoRoot,commentId:c});return"isError"in u&&u.isError?ye(s,400,u):ye(s,200,await vt({repoRoot:e.repoRoot}))}return i.pathname.startsWith("/board/")?Tl("/",s):Tl(i.pathname,s)});try{await ny(t)}catch(o){return a(o instanceof Error?`Unable to start GUI server: ${o.message}`:`Unable to start GUI server: ${String(o)}`)}let n=Sl({repoRoot:e.repoRoot});Al(t,e.repoRoot,{onStateChanged:()=>n.scheduleSync()}),t.on("close",n.dispose);let r=t.address();return!r||typeof r=="string"?(t.close(),a("Unable to resolve GUI server address")):l("Started GUI server",{url:`http://epiq.localhost:${r.port}${e.boardId?`/board/${e.boardId}`:""}`,server:t})};var Pl=async e=>{let t=await Ml({...e,boardId:""});if(d(t))return t;let{url:n}=t.value;return console.log(`Epiq GUI running at ${ry.cyan(n)}`),ki(n),l("Started GUI",{url:n})};import{Box as Jt}from"ink";import ae from"react";import{Box as vi,Text as Ir}from"ink";import ot,{useEffect as oy,useMemo as sy}from"react";import{ulid as iy}from"ulid";var Ll=({text:e,match:t,color:n,highlightColor:r=v.secondary,dimColor:o=!1})=>{if(!t)return ot.createElement(Ir,{color:n,dimColor:o},e);let s=e.toLowerCase(),i=t.toLowerCase(),c=s.indexOf(i);return c===-1?ot.createElement(Ir,{color:n,dimColor:o},e):ot.createElement(Ir,{color:n,dimColor:o},e.slice(0,c),ot.createElement(Ir,{backgroundColor:r,bold:!0},e.slice(c,c+t.length)),e.slice(c+t.length))},kl=iy(),ay=e=>`${e}`,dy=e=>{let{pendingNavTarget:t}=jt();if(!t)return[];let{breadCrumb:n,contextNode:r,selectedNode:o}=t,s=new Set(ie(x.NONE,{breadCrumb:n,contextNode:r,readOnly:g().readOnly,selectedNode:o}));return[...new Set(Object.values(x))].filter(i=>i!=="move").filter(i=>i.length>0).filter(i=>i!==x.PALETTE).map(i=>{let c=ho(i),u=Do.find(m=>m.intent===c);return{command:i,description:u?.description??`[${i}] Run command`,isAvailable:s.has(i)}}).filter(i=>i.command.toLowerCase().startsWith(e)||e.length>=2&&i.description.toLowerCase().includes(e)).sort((i,c)=>i.isAvailable!==c.isAvailable?i.isAvailable?-1:1:i.command.localeCompare(c.command))},cy=e=>Q.text({id:kl,parentNodeId:e,rank:"000000",name:"Command Palette",props:{},readonly:!0,isVirtual:!0}),ly=(e,t,n)=>Q.text({id:ay(e.command),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.command,props:{value:e.description,disabled:!e.isAvailable},readonly:!0,isVirtual:!0}),hi=[],uy=e=>{Dl();let t=I.createNode(cy(g().rootNodeId));d(t)||!kt(t.value)||(hi=[t.value,...e.map((n,r)=>ly(n,r,kl)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0}))},Dl=()=>{let e=hi.map(t=>t.id);hi=[];for(let t of e)I.deleteNode(t)};function Fl({width:e,height:t}){let r=zd().value.trim().toLowerCase(),o=sy(()=>dy(r),[r]);oy(()=>(uy(o),()=>{Dl()}),[o]);let s=g().selectedIndex;return ot.createElement(vi,{flexDirection:"column",width:e,height:t-2},ot.createElement(et,{height:t-4,itemHeight:3,selectedIndex:s},o.map((i,c)=>{let u=c===s,m=i.isAvailable?v.accent:v.secondary2,p=i.isAvailable?"":"[unavailable] ";return ot.createElement(vi,{key:i.command,flexDirection:"column",paddingX:1,borderLeft:!1,borderBottom:!1,borderRight:!1,borderColor:v.secondary,borderStyle:"single"},ot.createElement(Ir,{color:m,dimColor:!i.isAvailable},u?"\u276F ":" ",ot.createElement(Ll,{text:ma(i.command),match:r,color:m,dimColor:!i.isAvailable})),ot.createElement(vi,{paddingLeft:2},ot.createElement(Ll,{text:p+i.description,match:r.length>=2?r:"",color:u&&i.isAvailable?v.primary:v.secondary2,dimColor:!i.isAvailable})))})))}import{Box as Ty}from"ink";import Go from"react";import Cr from"chalk";import{Box as xi,Text as Bl}from"ink";import Er,{useEffect as my,useMemo as py,useState as fy}from"react";var Ul=Cr.hex(v.secondary),gy=Cr.inverse,yy=Cr.inverse.hex(v.secondary2),vy={hint:"",hints:[],overlap:0,remainder:""},_l=({value:e,command:t})=>{if(!t)return null;let n=e.trimStart(),o=e.length-n.length;return e.slice(o,o+t.length)!==t?null:{start:o,end:o+t.length}},hy=({command:e,modifier:t})=>{if(!t)return null;if(e==="tag"||e==="assign"){let n=le(t);return{bg:r=>Cr.bgHex(n).black(r),bgCursor:r=>Cr.bgHex(n).inverse.black(r)}}return Ts(t)},xy=({value:e,command:t,modifier:n})=>{if(!t||!n)return null;let r=_l({value:e,command:t});if(!r)return null;let s=e.slice(r.end).match(/^\s*/)?.[0].length??0,i=r.end+s;return e.slice(i,i+n.length)!==n?null:{start:i,end:i+n.length}},Ol=()=>({value:Ae.value,cursorPosition:Ae.cursorPosition,commandIsPending:Ae.commandIsPending,autoCompletion:Ae.commandMeta.autoCompletion??vy,infoMessage:Ae.commandMeta.infoMessage,validationStatus:Ae.commandMeta.validity,command:Ae.commandMeta.command,inputString:Ae.commandMeta.inputString,modifier:Ae.commandMeta.modifier}),by=(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,$l=({width:e,mode:t})=>{let[n,r]=fy(Ol());my(()=>{let S=()=>{let M=Ol();r(U=>by(U,M)?U:M)},R=qs(S);return S(),()=>{R()}},[]);let{value:o,cursorPosition:s,infoMessage:i,commandIsPending:c,autoCompletion:u,command:m,modifier:p,validationStatus:f}=n,b=c&&f===pt.Invalid,N=py(()=>{let S=Math.max(0,Math.min(s,o.length)),R=_l({value:o,command:m}),M=xy({value:o,command:m,modifier:p}),U=m?Ts(m):null,j=hy({command:m,modifier:p}),D=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fg(ue):Hn&&j?j.bg(ue):ue},z=(ue,ce)=>{let $n=R&&ce>=R.start&&ce<R.end,Hn=M&&ce>=M.start&&ce<M.end;return $n&&U?U.fgCursor(ue):Hn&&j?j.bgCursor(ue):gy(ue)},$=o.slice(0,S),P=o[S]??" ",O=S<o.length?o.slice(S+1):"",Ge=Array.from($).map((ue,ce)=>D(ue,ce)).join(""),Ne=z(P,S),ze=Array.from(O).map((ue,ce)=>D(ue,S+1+ce)).join("");if(u.hint){let ue=u.hint[u.overlap]??P;Ne=yy(ue),ze=Ul(u.remainder.slice(1)+O)}return Ul(t===y.PALETTE?"?":":")+Ge+Ne+ze},[o,s,u,m,p]);return Er.createElement(xi,{flexDirection:"column",justifyContent:"flex-start"},Er.createElement(xi,{flexDirection:"column",paddingX:1,borderColor:v.secondary,borderStyle:"round",width:e},Er.createElement(xi,null,Er.createElement(Bl,null,N),i&&Er.createElement(Bl,{wrap:"truncate",color:b?v.red:v.secondary2},` ${i} `))))};import{Box as Iy,Text as Ey}from"ink";import Hl from"react";var Cy=(e,t)=>{let n=[],r=0;for(let o of e){let i=(n.length>0?" | ":"").length+o.length;if(r+i>t-4)break;n.push(o),r+=i}return n},Wl=({width:e,availableHints:t})=>{let n=Cy(t,e).join(" | ");return Hl.createElement(Iy,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1},Hl.createElement(Ey,{color:v.secondary2},n.length?n:"\xA0"))};import{Box as Ny,Text as Vo}from"ink";import Nr,{useEffect as Sy,useRef as Un,useState as Ay}from"react";var Ry=40,Ko=.3,bi="\u2500",jl=1,Vl=16,Kl=({width:e})=>{let{replay:t}=H(),n=t!==null,r=t?Math.min(1,Math.max(0,t.progress)):0,s=Math.max(4,e-6),i=s*jl,[c,u]=Ay(0),m=Un(r);m.current=r;let p=Un(0),f=Un(0),b=Un(0),N=Un(0),S=Un(0);if(Sy(()=>{if(!n){p.current=0,b.current=0,N.current=0,S.current=0,u(0);return}p.current=m.current,f.current=Date.now(),b.current=m.current;let D=setInterval(()=>{let z=Date.now(),$=m.current;if($!==b.current){let ze=$-b.current,ue=z-f.current;if(ze<0)N.current=0,S.current=0;else if(ze>0&&ue>0){let ce=ze/ue;N.current=N.current===0?ce:N.current*(1-Ko)+ce*Ko,S.current=S.current===0?ze:S.current*(1-Ko)+ze*Ko}p.current=$,f.current=z,b.current=$}let P=z-f.current,O=Math.min(S.current,N.current*P),Ge=Math.min(1,p.current+O),Ne=Math.round(Ge*i);u(ze=>ze===Ne?ze:Ne)},Ry);return()=>clearInterval(D)},[n,i]),!t)return null;let R=D=>{let z=s>1?D/(s-1):0,$=Math.round(z*(Vl-1))/(Vl-1);return Gr($)},M=Math.min(s,Math.floor(c/jl)),U=[];for(let D=0;D<M;D++){let z=R(D),$=U[U.length-1];$&&$.color===z?$.text+=bi:U.push({text:bi,color:z})}let j=bi.repeat(Math.max(0,s-M));return Nr.createElement(Ny,{width:e,borderStyle:"round",borderColor:v.secondary,paddingX:1,columnGap:1},Nr.createElement(Vo,{color:v.secondary2},"\u25B6"),Nr.createElement(Vo,null,U.map((D,z)=>Nr.createElement(Vo,{key:z,color:D.color},D.text)),Nr.createElement(Vo,{color:v.secondary,dimColor:!0},j)))};var Sr=({width:e,mode:t,availableHints:n})=>{let{timeMode:r}=H(),o=t===y.COMMAND_LINE||t===y.PALETTE;return Go.createElement(Ty,null,o?Go.createElement($l,{width:e,mode:t}):r==="replay"?Go.createElement(Kl,{width:e}):Go.createElement(Wl,{width:e,mode:t,availableHints:n}))};import{Box as zt,Text as On}from"ink";import De,{useEffect as wy,useMemo as My}from"react";import{ulid as Gl}from"ulid";var qo=Gl(),Py=()=>[...new Set([...g().availableActions].map(e=>e.description).filter(e=>e!==void 0))].map(e=>{let[t,n]=e.split("]"),r=t?.replace("[",""),o=n?.trim();return[r,o]}).filter(e=>e[0]!==void 0&&e[1]!==void 0).sort(([e],[t])=>e.length===1&&t.length!==1?-1:e.length!==1&&t.length===1?1:e.localeCompare(t,void 0,{sensitivity:"base"})).map(([e,t])=>({keys:e,action:t})),Ly=e=>Q.text({id:qo,parentNodeId:e,rank:"000000",name:"Help",props:{},isVirtual:!0,readonly:!0}),ky=(e,t,n)=>Q.text({id:Gl(),parentNodeId:n,rank:String(t).padStart(6,"0"),name:e.keys,props:{value:e.action},readonly:!0,isVirtual:!0}),zo=[],zl=()=>{let e=zo.filter(n=>n.id!==qo).map(n=>n.id),t=zo.filter(n=>n.id===qo).map(n=>n.id);zo=[];for(let n of[...e,...t])I.deleteNode(n)},Dy=e=>{zl();let t=I.createNode(Ly(g().rootNodeId));if(d(t)||!kt(t.value))return logger.error("Could not attach help nodes");zo=[t.value,...e.map((n,r)=>ky(n,r,qo)).map(I.createNode).filter(te).map(({value:n})=>n).filter(kt)],T.navigate({contextNode:t.value,selectedIndex:0})},ql=({width:e,height:t})=>{let n=My(()=>Py(),[]);wy(()=>(Dy(n),()=>{zl()}),[n]);let r=g().selectedIndex;return De.createElement(zt,{flexDirection:"column",marginTop:3,borderColor:v.secondary,borderStyle:"round",width:e,height:t-2},De.createElement(zt,{paddingX:1,justifyContent:"center"},De.createElement(On,{color:v.accent},"Help"),De.createElement(On,{dimColor:!0}," \u2014 navigate with arrows/hjkl, press q to close")),De.createElement(zt,{paddingX:1,marginTop:1},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.secondary},"Key(s)")),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:v.secondary},"Action"))),De.createElement(et,{height:t-7,itemHeight:1,selectedIndex:r},n.map(({keys:o,action:s},i)=>{let c=i===r;return De.createElement(zt,{paddingX:1,key:`${o}-${s}-${i}`,flexDirection:"row"},De.createElement(zt,{width:20,justifyContent:"flex-end"},De.createElement(On,{color:v.accent},o)),De.createElement(zt,{flexGrow:1,width:40,paddingLeft:2},De.createElement(On,{color:c?v.primary:v.secondary2},s)))})))};import Fy from"chalk";import{Box as Yo,Text as Mt}from"ink";import Ke from"react";var Yl=({width:e,height:t})=>Ke.createElement(Yo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ke.createElement(Mt,{color:v.accent,bold:!0},"Initialize project"),Ke.createElement(Mt,null,`This folder is not an ${Fy.hex(v.accent)("epiq")} project yet.`),Ke.createElement(Mt,{color:v.primary},"To start tracking issues here, we need to initialize a new",Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json "),"file in this repository."),Ke.createElement(Yo,{marginTop:1,flexDirection:"column"},Ke.createElement(Yo,null,Ke.createElement(Mt,{color:v.accent}," "),Ke.createElement(Mt,{color:v.primary},"Type "),Ke.createElement(Mt,{backgroundColor:v.secondary}," :init "))),Ke.createElement(Yo,{marginTop:1},Ke.createElement(Mt,{color:v.secondary2},"This will create, commit and push "),Ke.createElement(Mt,{color:v.primary,backgroundColor:v.secondary}," .epiq/project.json ")));import{Box as Xo,Text as xt}from"ink";import Ce from"react";var By=({isDone:e,command:t,value:n})=>Ce.createElement(Xo,null,Ce.createElement(xt,{color:v.accent,dimColor:e},e?" \u2714 ":" "),Ce.createElement(xt,{dimColor:e},"Type "),Ce.createElement(xt,{backgroundColor:v.secondary,dimColor:e}," "+t+" "),n!==void 0&&Ce.createElement(Ce.Fragment,null,Ce.createElement(xt,{dimColor:e}," "),Ce.createElement(xt,{color:v.secondary,dimColor:e},"<"+n+">"))),Uy=e=>{if(typeof e=="string")return e;if(typeof e=="boolean")return e?"on":"off"};function Ii({width:e,height:t}){let{isSetPreferredEditor:n,isSetUserName:r,userName:o,preferredEditor:s,autoSync:i,isSetAutoSync:c}=Ot(),u=[{key:"username",done:r,command:":config username",value:o,message:"First, choose your username."},{key:"editor",done:n,command:":config editor",value:s,message:"Nice. Now pick your editor."},{key:"autosync",done:c,command:":config autosync",value:i,message:"Almost there. Configure auto sync."}],m=u.findIndex(f=>!f.done),p=m===-1?void 0:u[m];return Ce.createElement(Xo,{height:t-4,flexDirection:"column",width:e,paddingTop:1,paddingLeft:2,borderStyle:"round",borderColor:v.secondary,rowGap:1},Ce.createElement(xt,{color:v.accent,bold:!0},"Welcome! \u{1F539}"),Ce.createElement(xt,null,"Let's get you started - it's a breeze."),Ce.createElement(xt,{color:v.secondary2},"Remember - you can always search available commands by typing:",Ce.createElement(xt,{color:v.accent}," ? ")),p&&Ce.createElement(xt,{color:v.secondary2},p.message),Ce.createElement(Xo,{flexDirection:"column"},u.map((f,b)=>m===-1||b<=m?Ce.createElement(Xo,{key:f.key,marginBottom:1},Ce.createElement(By,{isDone:f.done,command:f.command,value:f.done?Uy(f.value):void 0})):null)))}import ts from"chalk";import{Box as Rr,Text as _n}from"ink";import ve from"react";import{Box as Jo,Text as Xl}from"ink";import qt from"react";import Oy from"chalk";var _y=e=>(I.getTag(e)?.name??"").length+3,$y=e=>(I.getContributor(e)?.name??"").length+3,Jl=({width:e})=>{let{viewMode:t}=K(),n=H(),{breadCrumb:r,contextNode:o,selectedIndex:s,renderedChildrenIndex:i}=n,c=i[o.id]?.[s],u=It(c?.id??o.id,"TICKET"),m=te(u)?u.value:void 0,p=m?.props.tags??[],f=m?.props.assignees??[],b=m?.parentNodeId?!Ss(o.id,m.parentNodeId)&&t==="dense":!1,N=r.map(($,P)=>{let O=P===r.length-1,Ge=q($.id),Ne=O?Ge?.[s]?.title:void 0;return`${P?" / ":""}${$.title??""}${Ne?` \u25B8 ${Ne}`:""}`}).join(""),S=m?I.getCommentsByIssue(m.id):[],R=S.length?String(S.length).length+11:0,M=b?p.reduce(($,P)=>$+_y(P),0)+f.reduce(($,P)=>$+$y(P),0)+R:0,U=c?.id!=null&&!(t==="wide"&&A(c)),j=Math.max(0,e-M),D=N.substring(0,j)+(U?Oy.hex(v.secondary2).dim(` ${Ue(c.id)}`):""),z=b?[...p.map($=>qt.createElement(Jo,{key:`tag-${$}`,paddingLeft:1},qt.createElement(kn,{id:$}))),...f.map($=>qt.createElement(Jo,{key:`assignee-${$}`,paddingLeft:1},qt.createElement(Ht,{id:$}))),S.length?qt.createElement(Jo,{key:"comments",paddingLeft:1},qt.createElement(Xl,{color:v.accent},"[",S.length," comment",S.length===1?"":"s","]")):null]:[];return qt.createElement(Jo,{overflow:"hidden",justifyContent:"flex-start",alignItems:"flex-start"},qt.createElement(Xl,{color:v.secondary2},D),z)};import{Box as Hy,Text as Ql}from"ink";import Qo from"react";var Wy=({filters:e})=>Qo.createElement(Hy,{columnGap:1},Qo.createElement(Ql,{color:"red"},"APPLIED FILTERS:"),e.map(({value:t,target:n,operator:r})=>Qo.createElement(Ql,{backgroundColor:"black",color:"white"},` ${n}${r}"${t}" `))),Zl=Qo.memo(Wy);import{Box as jy,Text as Zo}from"ink";import Ar from"react";function eu(){let{eventLog:e,unappliedEvents:t}=H(),n=e.at(-1)?.id,r=Xr(n??""),o=te(r)?Yr(r.value):"INVALID DATE";return Ar.createElement(jy,{paddingLeft:1},Ar.createElement(Zo,{backgroundColor:v.accent,color:v.secondary}," Readonly "),Ar.createElement(Zo,{color:v.accent}," "+t.length+" edits ago at "+o+"."),Ar.createElement(Zo,{color:v.accent}," Resume with "),Ar.createElement(Zo,{backgroundColor:v.accent,color:v.secondary}," ",":peek now"," "))}import{Box as Vy,Text as Ei}from"ink";import es from"react";function tu(){let{replay:e}=H();if(!e)return null;let{appliedCount:t,totalCount:n,currentTime:r}=e;return es.createElement(Vy,{paddingRight:2,columnGap:1,justifyContent:"flex-end"},es.createElement(Ei,{backgroundColor:v.accent,color:v.secondary}," \u25B6 REPLAY "),es.createElement(Ei,{color:v.secondary2},Yr(new Date(r))),es.createElement(Ei,{color:v.accent},`${t}/${n} edits`))}import Ci from"chalk";import{Box as Ky,Text as nu}from"ink";import Ni,{useEffect as Gy,useState as zy}from"react";var qy=["#4c567a","#9d7cd8","#7aa2f7","#7dcfff","#9d7cd8"],Yy=150,ru=12,Xy=.36,ou=e=>{let t=e.replace("#","");return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16)}},Jy=({r:e,g:t,b:n})=>{let r=o=>Math.round(Math.max(0,Math.min(255,o))).toString(16).padStart(2,"0");return`#${r(e)}${r(t)}${r(n)}`},Qy=(e,t,n)=>{let r=ou(e),o=ou(t);return Jy({r:r.r+(o.r-r.r)*n,g:r.g+(o.g-r.g)*n,b:r.b+(o.b-r.b)*n})},Zy=(e,t)=>{if(e.length===1)return e[0];let n=t*(e.length-1),r=Math.floor(n),o=n-r,s=e[r],i=e[Math.min(r+1,e.length-1)];return Qy(s,i,o)};function su({syncStatus:e,autoSync:t}){let[n,r]=zy(0);Gy(()=>{if(e.status!=="syncing"){r(0);return}let c=0,u=setInterval(()=>{c+=1;let m=(Math.sin(c*Xy)+1)/2,p=Math.round(m*(ru-1));r(f=>f===p?f:p)},Yy);return()=>clearInterval(u)},[e.status]);let o={synced:" ",failed:"---",syncing:"...",pending:"idle"},i={synced:v.secondary2,failed:v.yellow,pending:v.secondary2,syncing:Zy(qy,n/(ru-1))??""}[e.status];return Ni.createElement(Ky,null,Ni.createElement(nu,null,Ci.hex(v.secondary2).dim(t?"Sync (auto): ":"Sync: ")),Ni.createElement(nu,null,Ci.hex(i)("\u25CF")+Ci.hex(v.secondary2).dim(` ${o[e.status].padEnd(4)} `)))}import lu from"chalk";import{Text as uu}from"ink";import mu,{useEffect as rv,useState as ov}from"react";var Yt="1.3.3";import Si from"chalk";var ev="https://registry.npmjs.org/epiq/latest",Ai=null,iu=0,tv=1e3*60*60*24,au=e=>e.replace(/^v/,""),nv=(e,t)=>{let n=au(e).split(".").map(Number),r=au(t).split(".").map(Number);for(let o=0;o<Math.max(n.length,r.length);o++){let s=n[o]??0,i=r[o]??0;if(s>i)return 1;if(s<i)return-1}return 0},du=async e=>{if(process.env.IS_CI==="true")return{current:"1.2.3",latest:"1.2.3",updateAvailable:!1};if(Ai&&Date.now()-iu<tv)return Ai;try{let t=await fetch(ev);if(!t.ok)throw new Error(`Failed to fetch latest version: ${t.status}`);let r=(await t.json()).version??null,o={current:e,latest:r,updateAvailable:r?nv(r,e)>0:!1};return Ai=o,iu=Date.now(),o}catch{return{current:e,latest:null,updateAvailable:!1}}},cu=(e,t)=>{let n=e.split("."),r=t.split("."),o=r.findIndex((s,i)=>s!=n[i]);return r.map((s,i)=>i>=o?Si.hex(v.accent).dim(s):Si.hex(v.secondary).dim(s)).join(Si.hex(v.secondary2).dim("."))};function pu(){let[e,t]=ov({current:Yt,latest:null,updateAvailable:!1});return rv(()=>{let n=!0;return du(Yt).then(r=>{n&&t(r)}),()=>{n=!1}},[]),!e.updateAvailable||!e.latest?mu.createElement(uu,{dimColor:!0,color:v.secondary2},Yt+" "):mu.createElement(uu,null,lu.hex(v.secondary2).dim(Yt),lu.hex(v.accent).dim(" \u2197 "),cu(Yt,e.latest))}function Tr({filters:e,hideBreadCrumb:t=!1}){let{timeMode:n,syncStatus:r,mode:o,replay:s}=H(),{userName:i,preferredEditor:c,autoSync:u}=K(),m=64,p=process.stdout.columns-m-8,f=t||n==="replay",b=s?nn(s.currentLabel,Math.max(0,p)):"";return ve.createElement(Rr,{justifyContent:"space-between",flexDirection:"row","max-width":process.stdout.columns-40,overflow:"hidden"},n==="replay"?ve.createElement(Rr,{paddingLeft:1},ve.createElement(_n,{color:v.secondary2},b)):f?ve.createElement(_n,null," "):o===y.PALETTE?ve.createElement(Rr,null,ve.createElement(_n,{color:v.accent},"Command Palette"),ve.createElement(_n,{dimColor:!0,color:v.secondary2}," ","- search, select and press enter")):ve.createElement(Rr,{paddingLeft:1},e.length>0?ve.createElement(Zl,{filters:e}):ve.createElement(Jl,{width:p})),n==="live"?ve.createElement(Rr,{columnGap:1,paddingRight:2,"max-width":m,overflow:"hidden",justifyContent:"flex-end"},ve.createElement(su,{autoSync:!!u,syncStatus:r}),ve.createElement(_n,null,ts.hex(v.secondary2).dim("Mode: ")+ts.hex(v.secondary2).dim(o.padEnd(8," "))," "),ve.createElement(fu,{icon:"@",value:i}),ve.createElement(fu,{icon:"\u276F",value:c}),ve.createElement(pu,null)):"",n==="peek"?ve.createElement(eu,null):"",n==="replay"?ve.createElement(tu,null):"")}function fu({icon:e,value:t}){return ve.createElement(_n,null,ts.dim(e)+ts.hex(v.accent)(` ${t??"-"} `))}import{Box as sv,Text as iv}from"ink";import wr from"react";import{Box as ns,Text as Ri}from"ink";import Xt from"react";function Ti(){let e=H(),t=e.nodes[e.rootNodeId],o=process.stdout.rows-1-3,s=process.stdout.columns||120,i=t?.id?G(t?.id):[];return Xt.createElement(ns,{flexDirection:"column",height:o,padding:1,borderStyle:"round",borderColor:v.secondary,width:s},Xt.createElement(ns,{padding:1,paddingTop:0,paddingBottom:0},Xt.createElement(Ri,null,"Select a board:")),Xt.createElement(ns,{padding:1,flexDirection:"column"},i.map((c,u)=>{let m=e.contextNode.context==="WORKSPACE"&&e.selectedIndex===u,f=G(c.id).flatMap(({id:b})=>q(b)).length;return Xt.createElement(ns,{key:c.id??u},Xt.createElement(Ri,{color:m?v.accent:v.secondary2},Xt.createElement(Re,{isSelected:m})),Xt.createElement(Ri,{color:m?v.accent:v.secondary2},c.title," (",f," issues)",c.readonly?" \u{1F512}":""))})))}var av=({contextNode:e,selectedIndex:t,breadCrumb:n,mode:r,viewMode:o,height:s,width:i})=>{let{renderedChildrenIndex:c}=H(),u=n.find(({context:b})=>b==="BOARD"),f=s-1-3;return wr.createElement(sv,{flexDirection:"row"},e.context==="WORKSPACE"?wr.createElement(Ti,null):u?wr.createElement(So,{height:f,width:i,swimlanes:(c[u.id]??[]).filter(b=>b!==void 0&&Dt(b)),contextNode:e,selectedIndex:t,breadCrumb:n,viewMode:o,mode:r}):wr.createElement(iv,null))},gu=wr.memo(av);import{useEffect as dv}from"react";var cv=e=>{dv(()=>{if(!e)return;let t,n=!1,r=()=>{if(n)return;let{autoSyncIntervalMs:o,userName:s,preferredEditor:i}=K();i&&s&&o&&(t=setTimeout(()=>{if(n)return;let{readOnly:c,mode:u}=g();u==="default"&&!c&&io(),r()},o))};return r(),()=>{n=!0,t&&clearTimeout(t)}},[e])},yu=({autoSync:e})=>(cv(e),null);function wi({width:e,height:t}){let n=H(),{autoSync:r,viewMode:o}=ha(),s=n.filters;if(n.mode===y.HELP)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(ql,{width:e,height:t}));if(n.mode===y.PALETTE)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(Fl,{width:e,height:t-2}),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let{isSetupDone:i}=Ot(),c=!i,u=i&&!n.hasProjectDefinition;if(c)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(Ii,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));if(u)return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{hideBreadCrumb:!0,filters:s}),ae.createElement(Yl,{height:t,width:e})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}));let m=Le(n.breadCrumb??[],"BOARD");if(te(m)){let p=m.value.id,f=G(p).length,b=3,N=Math.floor(e/b),S=Math.floor(e/Math.max(f,1));e=Math.min(S,N)*Math.max(f,b)}return ae.createElement(Jt,{flexDirection:"column"},ae.createElement(yu,{autoSync:r}),ae.createElement(Jt,{flexDirection:"column"},ae.createElement(Tr,{filters:s}),ae.createElement(gu,{width:e,height:t,contextNode:n.contextNode,selectedIndex:n.selectedIndex,breadCrumb:n.breadCrumb,viewMode:o??"dense",mode:n.mode})),ae.createElement(Sr,{width:e,mode:n.mode,availableHints:n.availableHints}))}import lv from"readline";var rs,os,bt,uv=new Set([h.MoveCursorLeft,h.EraseInputWord,h.MoveCursorLeftOfWord,h.MoveCursorRight,h.MoveCursorRightOfWord,h.NavToPreviousContainer,h.NavToNextContainer,h.NavPreviousItem,h.NavNextItem,h.SetViewDense,h.SetViewWide,h.Confirm,h.Exit,h.Yank,h.InitCommandLine,h.InitCommandPalette,h.ExitCommandLine,h.CaptureInput,h.EraseInput,h.EraseInputWord,h.HideHelp,h.ViewHelp,h.SetViewDense,h.SetViewWide,h.GetLastCommandFromHistory,h.GetNextCommandFromHistory,h.AutoCompleteCommand]),mv=new Set([h.NavPreviousItem,h.NavNextItem,h.NavToPreviousContainer,h.NavToNextContainer,h.Confirm,h.Exit,h.InitCommandPalette,h.InitMove,h.MoveNextItem,h.MovePreviousItem,h.MoveToNextContainer,h.MoveToPreviousContainer,h.Delete,h.AddItem,h.EditTitle,h.EditDescription,h.ConfirmMove,h.Edit,h.ViewHelp,h.Yank]),vu=async e=>{if(e.ctrl&&e.name==="c")return T.exit();let{actionIndex:t,mode:n,readOnly:r,timeMode:o}=g(),s=Yd(e,n);if(!s||r&&!uv.has(s)||o==="replay"&&n===y.DEFAULT&&mv.has(s))return;let i=t[n]?.[s];if(i?.action)try{await i.action(i,e)}catch(c){logger.error(c)}},pv=()=>async function(t,n){n.name!=="escape"&&(bt&&(clearTimeout(bt),bt=void 0),await vu(n))},fv=()=>async function(t){if(t.length===1&&t[0]===27){bt&&clearTimeout(bt),bt=setTimeout(()=>{vu({name:"escape",ctrl:!1,meta:!1,shift:!1,sequence:"\x1B"}),bt=void 0},25);return}bt&&(clearTimeout(bt),bt=void 0)};function hu(){rs&&process.stdin.removeListener("keypress",rs),os&&process.stdin.removeListener("data",os),rs=pv(),os=fv(),lv.emitKeypressEvents(process.stdin),process.stdin.isTTY&&process.stdin.setRawMode(!0),process.stdin.on("data",os),process.stdin.on("keypress",rs)}async function xu(){try{let e=wn();te(e)&&Fe(e.value);let t=Ye(process.cwd()),n=[];if(te(t)){let s=Pe({repoRoot:t.value});if(d(s))return dn(3,s.message);let i=vn(),c=await en({repoRoot:t.value,stateBranchRoot:s.value,stateBranchName:i.stateBranch});if(d(c))return dn(3,c.message);let u=await _({cwd:s.value,args:["pull","--ff-only"]});d(u)&&logger.info(3,u.message);let m=Et(s.value);if(d(m))return dn(3,m.message);n=m.value}let r=an(n);if(d(r))return dn(4,r.message);E({hasProjectDefinition:te(t),hasInitializingEvents:!!n.length});let o=Mi();return d(o)?dn(6,o.message):(hu(),l("Booted Epiq",void 0))}catch(e){return dn(0,ro(e))}}hc();var hv=`${Qt.bold("Epiq CLI")}
|
|
59
59
|
|
|
60
60
|
${Qt.dim("Boot in directory:")}
|
|
61
61
|
${Qt.cyan("$ epiq")}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epiq",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "EPIQ - ergonomic, distributed CLI-first issue tracker TUI ready for the agentic era",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"scripts": {
|
|
29
29
|
"build": "tsc --noEmit",
|
|
30
30
|
"build:gui:types": "tsc --noEmit -p source/gui/client/tsconfig.json",
|
|
31
|
-
"build:gui": "npm run build:gui:types &&
|
|
31
|
+
"build:gui": "npm run build:gui:types && node source/scripts/build-gui.mjs",
|
|
32
32
|
"build:npm": "node source/scripts/write-version.mjs && rm -rf ./dist && npm run build:gui && esbuild source/Index.tsx --bundle --packages=external --platform=node --format=esm --target=node18 --minify --outfile=dist/index.js --banner:js='#!/usr/bin/env node' && esbuild source/mcp/index.ts --bundle --packages=external --platform=node --format=esm --target=node18 --minify --outfile=dist/mcp.js --banner:js='#!/usr/bin/env node'",
|
|
33
33
|
"build:sea:bundle": "node source/scripts/write-version.mjs && node source/scripts/build-sea.mjs",
|
|
34
34
|
"build:sea": "node source/scripts/build-sea.mjs",
|