epiq 0.2.19 → 0.2.21
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/cli.js +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,7 @@ import{render as bd}from"ink";import Sd from"meow";import Ii from"react";import
|
|
|
8
8
|
`).filter(i=>i.startsWith("worktree ")).map(i=>i.slice(9)).map(i=>Ue.resolve(i)).includes(r);return c("Checked worktree registration",o)},kt=async e=>{let t=await Ze({args:["rev-parse","--abbrev-ref","--symbolic-full-name","@{u}"],cwd:e});return c("Checked upstream",t.exitCode===0&&t.stdout.trim().length>0)},Dn=async e=>{let t=await F({args:["rev-parse","--abbrev-ref","HEAD"],cwd:e});return l(t)?s(t.message):t.data?c("Resolved current branch",t.data.stdout.trim()):s("Git command returned no branch name")},co=async e=>{let t=await F({args:["rev-parse","--short","HEAD"],cwd:e});return l(t)?s(t.message):t.data?c("Resolved short HEAD sha",t.data.stdout.trim()):s("Git command returned no short sha")},Fn=async e=>{if((await Ze({args:["rev-parse","--verify","HEAD"],cwd:e})).exitCode===0)return c("Repo already initialized",!1);let n=await F({args:["commit","--allow-empty","-m","[epiq:init]"],cwd:e});return l(n)?s(`Failed to create initial commit
|
|
9
9
|
${n.message}`):n.data?c("Created initial commit",!0):s("Git command returned no commit result data")},Bn=async({cwd:e,remote:t,branch:n})=>{let r=await kt(e);if(l(r))return s(r.message);if(!r.data)return c("No upstream configured, skipped pull",!1);let o=await Bt({repoRoot:e,remote:t,branch:n});if(l(o))return s(o.message);if(!o.data)return c("Remote branch missing, skipped pull",!1);let i=await F({args:["fetch",t,n],cwd:e});if(l(i))return s(`Failed to fetch ${n}
|
|
10
10
|
${i.message}`);if(!i.data)return s("Git command returned no fetch result data");let a=await F({args:["pull","--rebase"],cwd:e});return l(a)?s(`Failed during pull --rebase
|
|
11
|
-
${a.message}`):a.data?c("Pulled with rebase",!0):s("Git command returned no pull result data")};var go=pe(),fo="events",O="epiq-state-5",le="origin",xo=e=>re.join(go,fo,e),Bs=e=>Ds("sha1").update(e).digest("hex").slice(0,12),yo=()=>re.join(Fs.homedir(),".epiq"),vo=()=>re.join(yo(),"worktrees"),ho=e=>re.join(vo(),Bs(e)),Co=e=>re.join(e,go),lt=e=>re.join(Co(e),fo),lo=({root:e,fileName:t})=>re.join(lt(e),t),kn=e=>(B.mkdirSync(e,{recursive:!0}),c("Ensured directory",void 0)),ks=()=>{let e=kn(yo());if(l(e))return s(e.message);let t=kn(vo());return l(t)?s(t.message):c("Ensured epiq storage",void 0)},mo=e=>{let t=Co(e);return B.existsSync(t)?c("Epiq dir already exists",!1):(B.mkdirSync(t,{recursive:!0}),c("Created epiq dir",!0))},uo=e=>{let t=lt(e);return B.existsSync(t)?c("Events dir already exists",!1):(B.mkdirSync(t,{recursive:!0}),c("Created events dir",!0))},Os=e=>{B.existsSync(e)&&B.rmSync(e,{recursive:!0,force:!0})},Us=e=>e.endsWith(".jsonl")?e.includes("/")||e.includes("\\")?s("Own event file must be a file name, not a path"):e==="."||e===".."||e.trim()===""?s("Own event file name is invalid"):c("Validated own event file name",e):s("Own event file must end with .jsonl"),Ws=e=>{let t=lt(e);return B.existsSync(t)?c("Listed event files",B.readdirSync(t,{withFileTypes:!0}).filter(n=>n.isFile()).map(n=>n.name).filter(n=>n.endsWith(".jsonl")).sort()):c("Events dir missing",[])},Hs=({repoRoot:e,worktreeRoot:t,ownEventFileName:n})=>{let r=lo({root:e,fileName:n}),o=lo({root:t,fileName:n});if(!B.existsSync(r))return c("Local own event file missing, nothing to copy",!1);let i=B.readFileSync(r,"utf8"),a=B.existsSync(o)?B.readFileSync(o,"utf8"):"";return i===a?c("Own event file already matches board worktree",!1):(B.mkdirSync(re.dirname(o),{recursive:!0}),B.copyFileSync(r,o),c("Copied own event file into board worktree",!0))},No=({repoRoot:e,worktreeRoot:t})=>{let
|
|
11
|
+
${a.message}`):a.data?c("Pulled with rebase",!0):s("Git command returned no pull result data")};var go=pe(),fo="events",O="epiq-state-5",le="origin",xo=e=>re.join(go,fo,e),Bs=e=>Ds("sha1").update(e).digest("hex").slice(0,12),yo=()=>re.join(Fs.homedir(),".epiq"),vo=()=>re.join(yo(),"worktrees"),ho=e=>re.join(vo(),Bs(e)),Co=e=>re.join(e,go),lt=e=>re.join(Co(e),fo),lo=({root:e,fileName:t})=>re.join(lt(e),t),kn=e=>(B.mkdirSync(e,{recursive:!0}),c("Ensured directory",void 0)),ks=()=>{let e=kn(yo());if(l(e))return s(e.message);let t=kn(vo());return l(t)?s(t.message):c("Ensured epiq storage",void 0)},mo=e=>{let t=Co(e);return B.existsSync(t)?c("Epiq dir already exists",!1):(B.mkdirSync(t,{recursive:!0}),c("Created epiq dir",!0))},uo=e=>{let t=lt(e);return B.existsSync(t)?c("Events dir already exists",!1):(B.mkdirSync(t,{recursive:!0}),c("Created events dir",!0))},Os=e=>{B.existsSync(e)&&B.rmSync(e,{recursive:!0,force:!0})},Us=e=>e.endsWith(".jsonl")?e.includes("/")||e.includes("\\")?s("Own event file must be a file name, not a path"):e==="."||e===".."||e.trim()===""?s("Own event file name is invalid"):c("Validated own event file name",e):s("Own event file must end with .jsonl"),Ws=e=>{let t=lt(e);return B.existsSync(t)?c("Listed event files",B.readdirSync(t,{withFileTypes:!0}).filter(n=>n.isFile()).map(n=>n.name).filter(n=>n.endsWith(".jsonl")).sort()):c("Events dir missing",[])},Hs=({repoRoot:e,worktreeRoot:t,ownEventFileName:n})=>{let r=lo({root:e,fileName:n}),o=lo({root:t,fileName:n});if(!B.existsSync(r))return c("Local own event file missing, nothing to copy",!1);let i=B.readFileSync(r,"utf8"),a=B.existsSync(o)?B.readFileSync(o,"utf8"):"";return i===a?c("Own event file already matches board worktree",!1):(B.mkdirSync(re.dirname(o),{recursive:!0}),B.copyFileSync(r,o),c("Copied own event file into board worktree",!0))},No=({repoRoot:e,worktreeRoot:t,skipFileNames:n=[]})=>{let r=Ws(t);if(l(r))return s(r.message);let o=lt(t),i=lt(e),a=new Set(n),d=!1;for(let m of r.data){if(a.has(m))continue;let u=re.join(o,m),f=re.join(i,m),y=B.existsSync(u)?B.readFileSync(u,"utf8"):"",N=B.existsSync(f)?B.readFileSync(f,"utf8"):"";y!==N&&(B.mkdirSync(re.dirname(f),{recursive:!0}),B.copyFileSync(u,f),d=!0)}return c("Hydrated event files from board worktree",d)},po=e=>e.trim().replace(/\s+/g,"-").replace(/[^A-Za-z0-9._/-]/g,"-").replace(/-+/g,"-").replace(/^[-/.]+|[-/.]+$/g,"")||"unknown",_s=async e=>{let t=await Dn(e);if(l(t))return s(t.message);let n=await co(e);return l(n)?s(n.message):c("Built sync commit message",`[epiq:sync:${po(t.data)}:${po(n.data)}]`)},$s=async({repoRoot:e})=>{let t=await ao({repoRoot:e,branch:O});if(l(t))return s(t.message);if(t.data)return c("Local board branch already exists",!1);let n=await Ln({repoRoot:e,remote:le});if(l(n))return s(n.message);if(n.data){let o=await Bt({repoRoot:e,remote:le,branch:O});if(l(o))return s(o.message);if(o.data){let i=await F({args:["fetch",le,O],cwd:e});if(l(i))return s(`Failed to fetch ${O} from remote
|
|
12
12
|
${i.message}`);let a=await F({args:["branch","--track",O,`${le}/${O}`],cwd:e});return l(a)?s(`Failed to create local ${O} from remote
|
|
13
13
|
${a.message}`):c("Created local board branch from remote",!0)}}let r=await F({args:["branch",O,"HEAD"],cwd:e});return l(r)?s(`Failed to create local ${O}
|
|
14
14
|
${r.message}`):c("Created local board branch",!0)},Vs=async({repoRoot:e,worktreeRoot:t})=>{let n=kn(re.dirname(t));if(l(n))return s(n.message);B.existsSync(t)&&!B.existsSync(re.join(t,".git"))&&Os(t);let r=await F({args:["worktree","add",t,O],cwd:e});return l(r)?s(`Failed to create board worktree
|
|
@@ -22,7 +22,7 @@ ${o.message}`):c("Published board branch and configured upstream",!0)},qs=async(
|
|
|
22
22
|
${n.message}`):c("Staged board own event file",void 0)},Gs=async({worktreeRoot:e,ownEventFileName:t})=>{let n=await F({args:["diff","--cached","--quiet","--",xo(t)],cwd:e});return l(n)?n.message.includes("git diff --cached --quiet")?c("Has staged board own event file change",!0):s(n.message):c("No staged board own event file change",!1)},Xs=async({repoRoot:e,worktreeRoot:t,ownEventFileName:n})=>{let r=await Gs({worktreeRoot:t,ownEventFileName:n});if(l(r))return s(r.message);if(!r.data)return c("No board own event file commit needed",null);let o=await _s(e);if(l(o))return s(o.message);let i=await F({args:["commit","-m",o.data],cwd:t});if(l(i))return s(`Failed to commit board own event file
|
|
23
23
|
${i.message}`);let a=await F({args:["rev-parse","HEAD"],cwd:t});return l(a)?s(a.message):c("Created board sync commit",a.data.stdout.trim())},Ys=async e=>{let t=await kt(e);if(l(t))return s(t.message);if(!t.data)return c("No upstream configured, skipped push",!1);let n=await F({args:["push"],cwd:e});return l(n)?s(`Failed during board push
|
|
24
24
|
${n.message}`):c("Pushed board",!0)},Eo=async({repoRoot:e,worktreeRoot:t,ensureUpstream:n})=>{let r=!1;for(let o of[ks(),await $s({repoRoot:e}),await Ks({repoRoot:e,worktreeRoot:t}),await js(t),n?await zs(t):c("Skipped upstream bootstrap",!1)]){if(l(o))return s(o.message);r=r||!!o.data}return c(n?"Bootstrapped board storage":"Bootstrapped board storage (readonly)",r)},Io=(e,t)=>{for(let n of[mo(e),mo(t),uo(e),uo(t)])if(l(n))return s(n.message);return c("Ensured board layout",void 0)},bo=async({cwd:e=process.cwd(),ownEventFileName:t})=>{let n=Us(t);if(l(n))return s(n.message);let r=await Rn(e);if(l(r))return s(r.message);let o=r.data,i=ho(o);for(let K of[await ct(o),await so(o)]){if(l(K))return s(K.message);if(K.data)return s(K.message.includes("staged")?"Cannot run :sync while staged changes exist. Please commit or unstage them first.":"Cannot run :sync while a merge, rebase, cherry-pick, or revert is in progress in the current repo")}let a=await Fn(o);if(l(a))return s(a.message);let d=await Eo({repoRoot:o,worktreeRoot:i,ensureUpstream:!0});if(l(d))return s(d.message);let m=await ct(i);if(l(m))return s(m.message);if(m.data)return s("Cannot run :sync while a merge, rebase, cherry-pick, or revert is in progress in the board worktree");let u=Io(o,i);if(l(u))return s(u.message);let f=!1,y,N=!1,S=!1,b=!1,I=await Bn({cwd:i,remote:le,branch:O});if(l(I))return s(I.message);N=I.data;let E=Hs({repoRoot:o,worktreeRoot:i,ownEventFileName:n.data});if(l(E))return s(E.message);if(E.data){let K=await qs({worktreeRoot:i,ownEventFileName:n.data});if(l(K))return s(K.message);let Z=await Xs({repoRoot:o,worktreeRoot:i,ownEventFileName:n.data});if(l(Z))return s(Z.message);f=!!Z.data,y=Z.data??void 0}let w=await Ys(i);if(l(w))return s([w.message,f&&y?`Local board sync commit exists: ${y}`:""].filter(Boolean).join(`
|
|
25
|
-
`));S=w.data;let k=No({repoRoot:o,worktreeRoot:i});return l(k)?s(k.message):(b=k.data,c("Synced board event logs via git",{repoRoot:o,worktreeRoot:i,createdCommit:f,commitSha:y,pulled:N,pushed:S,hydrated:b,bootstrapped:d.data}))},So=async(e=process.cwd())=>{let t=await Rn(e);if(l(t))return s(t.message);let n=t.data,r=ho(n),o=await ct(n);if(l(o))return s(o.message);if(o.data)return s("Cannot sync while a git operation is in progress in the current repo");let i=await Fn(n);if(l(i))return s(i.message);let a=await Eo({repoRoot:n,worktreeRoot:r,ensureUpstream:!1});if(l(a))return s(a.message);let d=await ct(r);if(l(d))return s(d.message);if(d.data)return s("Cannot sync while a git operation is in progress in the board worktree");let m=Io(n,r);if(l(m))return s(m.message);let u=await Bn({cwd:r,remote:le,branch:O});if(l(u))return s(u.message);let f=No({repoRoot:n,worktreeRoot:r});return l(f)?s(f.message):c("Synced from remote",{repoRoot:n,worktreeRoot:r})};var Js=e=>Object.values(h().tags).find(t=>t.name===e),Qs=e=>Object.values(h().contributors).find(t=>t.name===e),Ao=[{systemOnly:!0,intent:M.Move,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{modifier:n}=ue().commandMeta,{currentNode:r,selectedIndex:o}=h(),i=T(r.id)[o];if(!i)return A({mode:p.DEFAULT}),s("No move target");if(n==="start"){if(i.readonly)return s("Target node is read-only");if(o===-1)return s("No item selected");if(!i.parentNodeId)return s("Target has no parent");let a=T(i.parentNodeId),d=a.findIndex(({id:y})=>y===i.id);if(d===-1)return s("Target not found among siblings");let m=a[d-1],u=a[d+1],f=u!=null?{at:"before",sibling:u.id}:m!=null?{at:"after",sibling:m.id}:{at:"start"};return Je({id:_(),userId:t,action:"move.node",payload:{id:i.id,parent:i.parentNodeId,pos:f}}),A({mode:p.MOVE}),c("Move initialized",null)}if(n==="next")return A({mode:p.MOVE}),Sn(1);if(n==="previous")return A({mode:p.MOVE}),Sn(-1);if(n==="to-next")return A({mode:p.MOVE}),bn(1);if(n==="to-previous")return A({mode:p.MOVE}),bn(-1);if(n==="confirm"){A({mode:p.DEFAULT});let a=Oe();if(!a)return s("No pending move to confirm");let d=J(a);return l(d)?d:(Je(null),c("Moved item",null))}return n==="cancel"?(Je(null),A({mode:p.DEFAULT}),c("Cancelling move",null)):s("Invalid move modifier")}},{intent:M.Delete,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];return o?J({id:_(),userId:t,action:"delete.node",payload:{id:o.id}}):s("Unable to resolve child to delete")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Edit,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,n=Qe(h().breadCrumb,"TICKET");if(l(n))return s("Edit target must be an issue");let r=n.data;if(r.readonly)return s("Cannot edit readonly field");let{currentNode:o,selectedIndex:i}=h();if(!T(r.id)[i])return s("No selected field");let d=T(o.id)[i];if(!d)return s("No selected field");if(d.readonly)return s("Cannot edit readonly field");let m=d.props.value;if(typeof m!="string")return s("Selected field is not editable text");let u=Hr(m);if(l(u))return s("Failed to edit field");let f=u.data;return f===m?c("No changes made",null):d.title==="Description"?J({id:_(),userId:t,action:"edit.description",payload:{id:d.id,md:f}}):d.title==="Title"?J({id:_(),userId:t,action:"edit.title",payload:{id:d.id,name:f}}):s(`Editing not supported for "${d.title}"`)},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Filter,mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=ue().commandMeta,n=/(!=|=)/,[r,o]=e.split(n);if(!r||!(d=>V(g.FILTER).map(m=>m.split(n)[0]).includes(d))(r))return s("Invalid filter modifier");let a={target:r,operator:"=",value:t.trim()};return ie(d=>({...d,filters:e==="clear"?[]:[...d.filters,a],mode:p.DEFAULT})),c("Viewing help",null)}},{intent:M.ViewHelp,mode:p.COMMAND_LINE,action:()=>(A({mode:p.HELP}),c("Viewing help",null))},{intent:M.CloseIssue,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];if(!o)return s("Unable to close issue, no target found");if(!o.parentNodeId)return s("No target parent found");if(!Be(o))return s("Cannot close in this context");let i=J({id:_(),userId:t,action:"close.issue",payload:{id:o.id,parent:o.parentNodeId}});return l(i)?i:c("Viewing help",null)}},{intent:M.ReopenIssue,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];if(!o)return s("Unable to reopen issue, no target found");let i=o.context==="TICKET"?c("Resolved ticket",o):Ve(o.id,"TICKET");if(l(i))return s("Cannot reopen in this context");let a=i.data,d=J({id:_(),userId:t,action:"reopen.issue",payload:{id:a.id}});return l(d)?d:c("Issue reopened",null)},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.SetUserName,mode:p.COMMAND_LINE,action:()=>{let{userId:e,preferredEditor:t,userName:n}=de(),r=wt()?.trim();if(!r)return s("No username provided");let o=r??n,i=e??_();if(!o||!i)return s("Unable to resolve user name or id");let a=Tn({userName:o,userId:i,preferredEditor:t??""});return l(a)?a:(st({userName:o,userId:i}),A({mode:p.DEFAULT}),c(`Username set to "${r}"`,null))}},{intent:M.Init,mode:p.COMMAND_LINE,action:()=>{let e=wo();if(l(e))return e;let{rootNodeId:t,nodes:n}=h();return D.navigate({currentNode:n[t],selectedIndex:0}),c("Project initialized",null)}},{intent:M.SetEditor,mode:p.COMMAND_LINE,action:()=>{let e=wt()?.trim();if(!e)return s("No editor provided");let t=Tn({preferredEditor:e});return l(t)?t:(st({preferredEditor:e}),A({mode:p.DEFAULT}),c(`Editor configuration set to "${e}"`,null))}},{intent:M.NewItem,mode:p.COMMAND_LINE,action:(e,t)=>{let n=Y();if(l(n))return s("Unable to resolve user ID");let r=n.data;if(!t.inputString)return s(`provide a name for your ${t.modifier}`);let{breadCrumb:o,currentNode:i,selectedIndex:a}=h(),d=m=>{let u=J(m);if(l(u))return u;let f=C.getNode(u.data.result.id);if(!f)return s("Created node not found");if(!f.parentNodeId)return u;let y=C.getNode(f.parentNodeId);return y?(D.navigate({currentNode:y,selectedIndex:C.getSiblings(f.parentNodeId).findIndex(({id:N})=>N===f.id)}),u):s("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=h(),u=C.getNode(m);return u?d({id:_(),userId:r,action:"add.board",payload:{id:_(),name:t.inputString,parent:u.id}}):s("Workspace not found")}if(t.modifier==="swimlane"){let m=Qe(o,"BOARD");return l(m)?s("Unable to add swimlane in this context"):d({id:_(),userId:r,action:"add.swimlane",payload:{id:_(),name:t.inputString,parent:m.data.id}})}if(t.modifier==="issue"){let m=T(i.id)[a],u=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let b=Qe(o,"SWIMLANE");return l(b)?null:b.data})();if(!u)return s("Unable to add issue in this context");let f=_r({userId:r,name:t.inputString,parent:u.id}),y=Ft(f);if(y.some(b=>l(b)))return s("Issue create failed: "+y.filter(l).map(b=>b.message).filter(Boolean).join(", "));let N=y[0];if(!N||l(N))return s("Issue creation failed");let S=f[0]?.payload.id;return S?(D.navigate({currentNode:u,selectedIndex:C.getSiblings(u.id).findIndex(({id:b})=>b===S)}),c("Issue created",null)):s("Unable to determine ticket id")}return sr()},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.SetView,mode:p.COMMAND_LINE,action:()=>{let{commandMeta:e}=ue();return e.validity===ye.Invalid?s("Invalid command "+ve):(ie(t=>({...t,viewMode:e.modifier==="wide"?"wide":e.modifier==="dense"?"dense":t.viewMode})),c("View set",null))},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Rename,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];if(!o)return s("Missing node");if(o.readonly)return s("Cannot rename readonly node");let i=wt();return i?J({id:_(),userId:t,action:"edit.title",payload:{id:o.id,name:i}}):s("Provide a new name")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.TagTicket,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{modifier:n,inputString:r}=ue().commandMeta,o=(n||r).trim();if(!o)return s("Provide a tag");let{selectedIndex:i,currentNode:a}=h(),d=T(a.id)[i];if(!d)return s("Invalid tag target");let m=Ve(d.id,"TICKET");if(l(m))return s("Unable to tag issue in this context");let u=m.data,f=Js(o),y;if(f)y=f.id;else{let b=_(),I=J({id:_(),userId:t,action:"create.tag",payload:{id:b,name:o}});if(l(I))return I;y=I.data.result.id}let N=C.getFieldByTitle(u.id,"Tags");return N?T(N.id).some(b=>b.props?.value===y)?s("Already tagged with that tag"):J({id:_(),userId:t,action:"tag.issue",payload:{id:_(),target:u.id,tagId:y}}):s("Unable to locate tags field")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.AssignUserToTicket,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{modifier:n,inputString:r}=ue().commandMeta,o=(n||r).trim();if(!o)return s("Provide an assignee");let{selectedIndex:i,currentNode:a}=h(),d=T(a.id)[i];if(!d)return s("Invalid assign target");let m=Ve(d.id,"TICKET");if(l(m))return s("Unable to assign issue in this context");let u=m.data,f=Qs(o),y;if(f)y=f.id;else{let b=_(),I=J({id:_(),userId:t,action:"create.contributor",payload:{id:b,name:o}});if(l(I))return I;y=I.data.result.id}let N=C.getFieldByTitle(u.id,"Assignees");return N?T(N.id).some(b=>b.props?.value===y)?s("Assignee already assigned"):J({id:_(),userId:t,action:"assign.issue",payload:{id:_(),target:u.id,contributor:y}}):s("Unable to locate assignees field")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Sync,mode:p.COMMAND_LINE,action:async()=>{H(()=>""),A({syncStatus:{msg:"Syncing",status:"syncing"}});let{userId:e,userName:t}=de();if(!e)return s("Unable to resolve userId");if(!t)return s("Unable to resolve userName");let n=In();if(l(n))return s("Unable to resolve log file name");let r=await bo({ownEventFileName:n.data});return l(r)?(A({syncStatus:{msg:r.message,status:"outOfSync"}}),s(`Unable to sync state. ${r.message}`)):(A({syncStatus:{msg:"Synced",status:"synced"},mode:p.DEFAULT}),c("Synced",!0))}}];var oe=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=ue();if(!t)return s("No command to confirm");if(!e&&n===ye.Invalid)return s("Invalid command");let i=Br(t);Mr();let a=Ao.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!a)return At({result:ve.Fail,message:"Command not found",data:null});let d=await a.action(a,{command:t,inputString:o,modifier:r});return l(d)?At(d):(Rr({addToHistory:!e}),a.onSuccess?.(),At(d))};var Ot=[{intent:"exit",mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"move cancel"),oe({isForceExecutedBySystem:!0}))},{intent:"initMove",mode:p.DEFAULT,description:"[m] move init/confirm",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"move start"),oe({isForceExecutedBySystem:!0}))},{intent:"confirmMove",mode:p.MOVE,action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"move confirm"),oe({isForceExecutedBySystem:!0}))}],Ut=[{intent:"movePreviousItem",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move previous"),oe({isForceExecutedBySystem:!0})):s("No pending move")},{intent:"moveNextItem",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move next"),oe({isForceExecutedBySystem:!0})):s("No pending move")}],To=[{intent:"moveToNextContainer",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move to-next"),oe({isForceExecutedBySystem:!0})):s("No pending move")},{intent:"moveToPreviousContainer",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move to-previous"),oe({isForceExecutedBySystem:!0})):s("No pending move")}];var Mo={[R.WORKSPACE]:[...Ot,...Ut],[R.BOARD]:[...Ot,...Ut],[R.SWIMLANE]:[...Ot,...Ut,...To],[R.TICKET]:[],[R.FIELD]:[],[R.FIELD_LIST]:[],[R.TEXT]:[]};var Ro=[{intent:"addItem",mode:p.DEFAULT,description:"[n] new...",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>`${g.NEW} `),c("Adding new item",null))},{intent:"Delete",mode:p.DEFAULT,description:"[d] delete",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>`${g.DELETE} `),c("Deleting item",null))},{intent:"initCommandLine",mode:p.DEFAULT,description:"[:] focus command line",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>""),c("Entering command line mode",null))},{intent:"confirm",mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>(D.enterChildNode(),c("Entering context",null))},{intent:"exit",mode:p.DEFAULT,description:"[q] exit context",action:()=>(logger.debug("Executing exit action"),D.enterParentNode(),c("Exiting context",null))},{intent:"navPreviousItem",mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(D.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:"navNextItem",mode:p.DEFAULT,action:()=>(D.navigateToNextItem(),c("Navigating to next item",null))},{intent:"navToPreviousContainer",mode:p.DEFAULT,action:()=>(D.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:"navToNextContainer",mode:p.DEFAULT,action:()=>(D.navigateToNextContainer(),c("Navigating to next container",null))},{intent:"edit",mode:p.DEFAULT,action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"edit"),oe(),c("Fired command",!0))},{intent:"SetViewDense",mode:p.DEFAULT,description:"[v] view change (wide/dense)",action:()=>(A({viewMode:"dense"}),c("View set",null))},{intent:"SetViewWide",mode:p.DEFAULT,action:()=>(A({viewMode:"wide"}),c("View set",null))},{intent:"sync",mode:p.DEFAULT,description:"[s] sync epiq with remote state branch",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"sync"),oe({isForceExecutedBySystem:!0}),c("Synced",!0))}];var Lo=[{intent:"viewHelp",mode:p.DEFAULT,action:()=>(A({mode:p.HELP}),c("Viewing help",null))},{intent:"exit",mode:p.HELP,action:()=>(A({mode:p.DEFAULT}),c("Exiting help",null))},{intent:"confirm",mode:p.COMMAND_LINE,action:()=>(oe(),c("Executing command",null))},{intent:"MoveCursorLeft",mode:p.COMMAND_LINE,action:()=>(yn(-1),c("Moving cursor left",null))},{intent:"MoveCursorRight",mode:p.COMMAND_LINE,action:()=>(yn(1),c("Moving cursor right",null))},{intent:"MoveCursorLeftOfWord",mode:p.COMMAND_LINE,action:()=>(vn("left"),c("Moving cursor left of word",null))},{intent:"MoveCursorRightOfWord",mode:p.COMMAND_LINE,action:()=>(vn("right"),c("Moving cursor right of word",null))},{intent:"exitCommandLine",mode:p.COMMAND_LINE,action:()=>(A({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:"autoCompleteCommand",mode:p.COMMAND_LINE,action:()=>(H((e,{remainder:t})=>t?e+t:e),c("Auto-completing command",null))},{intent:"captureInput",mode:p.COMMAND_LINE,action:(e,{sequence:t})=>(H(n=>n+t),c("Capturing input",null))},{intent:"eraseInput",mode:p.COMMAND_LINE,action:()=>(wr(),c("Erasing input",null))},{intent:"EraseInputWord",mode:p.COMMAND_LINE,action:()=>(Tr(),c("Erasing input word",null))},{intent:"getLastCommandFromHistory",mode:p.COMMAND_LINE,action:()=>(Lr(),c("Getting last command from history",null))},{intent:"getNextCommandFromHistory",mode:p.COMMAND_LINE,action:()=>(Pr(),c("Getting next command from history",null))}];import Zs from"chalk";var Wt=": for command line",Po="q to exit",Do=`${Zs.hex(v.accent)("m")} to confirm`,On={[R.WORKSPACE]:[Wt],[R.BOARD]:[Wt],[R.BOARD+p.COMMAND_LINE]:[Wt],[R.SWIMLANE]:[Wt],[R.TICKET+p.HELP]:[Po],[R.SWIMLANE+p.HELP]:[Po],[R.TICKET]:[],[R.FIELD]:[],[R.SWIMLANE+p.MOVE]:[Do],[R.TICKET+p.MOVE]:[Do]};var Ht=e=>e.trim().toLocaleLowerCase(),ea=(e,t)=>{let n=C.getFieldByTitle(e,t);if(!n)return"";let r=n.props?.value;return typeof r=="string"?r:""},ta=e=>{let{tags:t}=h(),n=C.getFieldByTitle(e,"Tags");return n?W(n.id).map(r=>{let o=r.props?.value;return typeof o=="string"?t[o]?.name:void 0}).filter(r=>!!r):[]},na=e=>{let{contributors:t}=h(),n=C.getFieldByTitle(e,"Assignees");return n?W(n.id).map(r=>{let o=r.props?.value;return typeof o=="string"?t[o]?.name:void 0}).filter(r=>!!r):[]},Fo=(e,t)=>{let n=t.value;if(!n)return!0;switch(t.target){case"title":return Ht(e.title??"").includes(n);case"description":return Ht(ea(e.id,"Description")).includes(n);case"tag":return ta(e.id).map(Ht).some(d=>d.includes(n));case"assignee":return na(e.id).map(Ht).some(d=>d.includes(n));default:return!0}};function Bo(e,t,n){let r=t[e];if(!r)return s("buildBreadCrumb(): current node not found");let o=[],i=r;for(;i&&(o.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let a=o[o.length-1];return!a||a.id!==n?s("buildBreadCrumb(): node is not connected to root"):(o.reverse(),c("Breadcrumb built",o))}var ko=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t};var _t,Un=new Set,Oo=()=>{for(let e of Un)e()},oa=e=>(Un.add(e),()=>Un.delete(e));function Uo(e){let{currentNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:i}=e;if(!t)return s("derive(): currentNodeId is missing");if(!r)return s("derive(): rootNode is missing");if(!o[r])return s("derive(): unable to find root node");let d=o[t];if(!d)return logger.error("Unable to derive state, currentNode not found"),s("Unable to derive state, currentNode not found");let m=Bo(t,o,r);if(l(m))return logger.error(m.message),m;let u=m.data,{context:f}=d,y=On[f+n]??On[f]??[],N=[...Ro,...Mo[f]??[],...Lo],S=ko(N);return c("Derived successfully",{...e,currentNode:d,breadCrumb:u,availableHints:y,availableActions:N,actionIndex:S,renderedChildrenIndex:ia(o,i)})}var h=()=>(_t||logger.error("State not initialized. Call initWorkspaceState() first.",new Error().stack),_t);function Vr(e){let t={filters:[],tags:{},contributors:{},viewMode:"dense",mode:p.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,currentNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""}},n=Uo(t);return l(n)?n:(_t=n.data,Oo(),c("State initialized",null))}function ie(e){let t=h(),n=e(t),r=Uo(n);return l(r)?s(r.message??"Unable to update state"):(_t=r.data,Oo(),c("State updated",null))}var A=e=>ie(t=>({...t,...e}));var $=()=>ra(oa,h,h),ia=(e,t)=>{let n={};for(let r of Object.values(e))Be(r)&&t.length>0&&!t.every(o=>Fo(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,i)=>{let a=e[o.id],d=e[i.id];return!a||!d?0:a.rank.localeCompare(d.rank)});return n},T=e=>h().renderedChildrenIndex[e]??[];var D={exit(){process.exit(0)},enterChildNode(){let e=h(),t=e.currentNode,n=Math.max(0,e.selectedIndex),r=T(t.id)[n];!r||t.context==="FIELD"||D.navigate({currentNode:r,selectedIndex:T(r.id).length?0:-1})},enterParentNode(){let{currentNode:e,nodes:t}=h();if(!e.parentNodeId){logger.info("Missing parent node id");return}let n=t[e.parentNodeId];if(!n){logger.error("Parent not found");return}let r=T(n.id),o=r.findIndex(({id:a})=>a===e.id),i=r.length===0?-1:o>=0?o:0;D.navigate({currentNode:n,selectedIndex:i})},navigateToNextItem:()=>Wo(1),navigateToPreviousItem:()=>Wo(-1),navigateToNextContainer:()=>Ho(1),navigateToPreviousContainer:()=>Ho(-1),navigate:({currentNode:e=h().currentNode,selectedIndex:t})=>{A({currentNodeId:e.id,selectedIndex:t})}},Wo=e=>{let t=h(),n=T(t.currentNode.id).length;if(n===0)return;let o=(Math.max(0,t.selectedIndex)+e+n)%n;D.navigate({selectedIndex:o})},Ho=e=>{let{currentNode:t,nodes:n,selectedIndex:r}=h();if(!t.childNavigationAcrossParents)return;if(!t.parentNodeId){logger.error("Missing parent node id");return}let o=n[t.parentNodeId];if(!t||!o)return;let i=T(o.id),a=i.findIndex(N=>N.id===t.id);if(a<0)return;let d=i.at(a+e)??i.at(0);if(!d)return;let m=T(d.id),u=Math.max(0,m.length-1),f=Math.min(Math.max(0,r),u),y=m.length?f:-1;D.navigate({currentNode:d,selectedIndex:y})};var Ee="system.actor",mt=sa(),Me=null;function aa(){let e=Object.values(h().nodes).find(r=>r.context==="WORKSPACE");if(!e)throw new Error("No workspace found in event log");let[t]=T(e.id),[n]=t?T(t.id):[];if(logger.debug("Boot navigation target:",{workspace:e?.id,firstBoard:t?.id,firstSwimlane:n?.id}),n){let r=h().renderedChildrenIndex?.[n.id]??[];return{currentNode:n,selectedIndex:r.length>0?0:-1}}else return t?{currentNode:t,selectedIndex:0}:e?{currentNode:e,selectedIndex:0}:{currentNode:h().nodes[h().rootNodeId],selectedIndex:0}}function da(){let e=aa();D.navigate(e)}function ca(){let e=mt(),t=mt(),n=mt(),r=mt(),o=mt();return[{id:Ne(),userId:Ee,action:"init.workspace",payload:{id:e,name:"Workspace"}},{id:Ne(),userId:Ee,action:"add.board",payload:{id:t,name:"Default",parent:e}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:n,name:"Todo",parent:t}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:r,name:"Review",parent:t}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:o,name:"Done",parent:t}},{id:Ne(),userId:Ee,action:"add.board",payload:{id:Lt,name:"Closed",parent:e}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:qe,name:"Closed",parent:Lt}},{id:Ne(),userId:Ee,action:"lock.node",payload:{id:Lt}},{id:Ne(),userId:Ee,action:"lock.node",payload:{id:qe}}]}function bt(){return Me!==null}function wo(){if(!Me||Me.length===0)return c("No pending default events to persist",null);let t=Ft(Me).filter(l);return t.length>0?s([et.bold.red("Materializing failed"),"",...t.map((n,r)=>`${et.dim.gray(`${r+1}.`)} ${et.dim(n.message)}`),`
|
|
25
|
+
`));S=w.data;let k=No({repoRoot:o,worktreeRoot:i,skipFileNames:[n.data]});return l(k)?s(k.message):(b=k.data,c("Synced board event logs via git",{repoRoot:o,worktreeRoot:i,createdCommit:f,commitSha:y,pulled:N,pushed:S,hydrated:b,bootstrapped:d.data}))},So=async(e=process.cwd())=>{let t=await Rn(e);if(l(t))return s(t.message);let n=t.data,r=ho(n),o=await ct(n);if(l(o))return s(o.message);if(o.data)return s("Cannot sync while a git operation is in progress in the current repo");let i=await Fn(n);if(l(i))return s(i.message);let a=await Eo({repoRoot:n,worktreeRoot:r,ensureUpstream:!1});if(l(a))return s(a.message);let d=await ct(r);if(l(d))return s(d.message);if(d.data)return s("Cannot sync while a git operation is in progress in the board worktree");let m=Io(n,r);if(l(m))return s(m.message);let u=await Bn({cwd:r,remote:le,branch:O});if(l(u))return s(u.message);let f=No({repoRoot:n,worktreeRoot:r});return l(f)?s(f.message):c("Synced from remote",{repoRoot:n,worktreeRoot:r})};var Js=e=>Object.values(h().tags).find(t=>t.name===e),Qs=e=>Object.values(h().contributors).find(t=>t.name===e),Ao=[{systemOnly:!0,intent:M.Move,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{modifier:n}=ue().commandMeta,{currentNode:r,selectedIndex:o}=h(),i=T(r.id)[o];if(!i)return A({mode:p.DEFAULT}),s("No move target");if(n==="start"){if(i.readonly)return s("Target node is read-only");if(o===-1)return s("No item selected");if(!i.parentNodeId)return s("Target has no parent");let a=T(i.parentNodeId),d=a.findIndex(({id:y})=>y===i.id);if(d===-1)return s("Target not found among siblings");let m=a[d-1],u=a[d+1],f=u!=null?{at:"before",sibling:u.id}:m!=null?{at:"after",sibling:m.id}:{at:"start"};return Je({id:_(),userId:t,action:"move.node",payload:{id:i.id,parent:i.parentNodeId,pos:f}}),A({mode:p.MOVE}),c("Move initialized",null)}if(n==="next")return A({mode:p.MOVE}),Sn(1);if(n==="previous")return A({mode:p.MOVE}),Sn(-1);if(n==="to-next")return A({mode:p.MOVE}),bn(1);if(n==="to-previous")return A({mode:p.MOVE}),bn(-1);if(n==="confirm"){A({mode:p.DEFAULT});let a=Oe();if(!a)return s("No pending move to confirm");let d=J(a);return l(d)?d:(Je(null),c("Moved item",null))}return n==="cancel"?(Je(null),A({mode:p.DEFAULT}),c("Cancelling move",null)):s("Invalid move modifier")}},{intent:M.Delete,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];return o?J({id:_(),userId:t,action:"delete.node",payload:{id:o.id}}):s("Unable to resolve child to delete")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Edit,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,n=Qe(h().breadCrumb,"TICKET");if(l(n))return s("Edit target must be an issue");let r=n.data;if(r.readonly)return s("Cannot edit readonly field");let{currentNode:o,selectedIndex:i}=h();if(!T(r.id)[i])return s("No selected field");let d=T(o.id)[i];if(!d)return s("No selected field");if(d.readonly)return s("Cannot edit readonly field");let m=d.props.value;if(typeof m!="string")return s("Selected field is not editable text");let u=Hr(m);if(l(u))return s("Failed to edit field");let f=u.data;return f===m?c("No changes made",null):d.title==="Description"?J({id:_(),userId:t,action:"edit.description",payload:{id:d.id,md:f}}):d.title==="Title"?J({id:_(),userId:t,action:"edit.title",payload:{id:d.id,name:f}}):s(`Editing not supported for "${d.title}"`)},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Filter,mode:p.COMMAND_LINE,action:()=>{let{modifier:e,inputString:t}=ue().commandMeta,n=/(!=|=)/,[r,o]=e.split(n);if(!r||!(d=>V(g.FILTER).map(m=>m.split(n)[0]).includes(d))(r))return s("Invalid filter modifier");let a={target:r,operator:"=",value:t.trim()};return ie(d=>({...d,filters:e==="clear"?[]:[...d.filters,a],mode:p.DEFAULT})),c("Viewing help",null)}},{intent:M.ViewHelp,mode:p.COMMAND_LINE,action:()=>(A({mode:p.HELP}),c("Viewing help",null))},{intent:M.CloseIssue,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];if(!o)return s("Unable to close issue, no target found");if(!o.parentNodeId)return s("No target parent found");if(!Be(o))return s("Cannot close in this context");let i=J({id:_(),userId:t,action:"close.issue",payload:{id:o.id,parent:o.parentNodeId}});return l(i)?i:c("Viewing help",null)}},{intent:M.ReopenIssue,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];if(!o)return s("Unable to reopen issue, no target found");let i=o.context==="TICKET"?c("Resolved ticket",o):Ve(o.id,"TICKET");if(l(i))return s("Cannot reopen in this context");let a=i.data,d=J({id:_(),userId:t,action:"reopen.issue",payload:{id:a.id}});return l(d)?d:c("Issue reopened",null)},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.SetUserName,mode:p.COMMAND_LINE,action:()=>{let{userId:e,preferredEditor:t,userName:n}=de(),r=wt()?.trim();if(!r)return s("No username provided");let o=r??n,i=e??_();if(!o||!i)return s("Unable to resolve user name or id");let a=Tn({userName:o,userId:i,preferredEditor:t??""});return l(a)?a:(st({userName:o,userId:i}),A({mode:p.DEFAULT}),c(`Username set to "${r}"`,null))}},{intent:M.Init,mode:p.COMMAND_LINE,action:()=>{let e=wo();if(l(e))return e;let{rootNodeId:t,nodes:n}=h();return D.navigate({currentNode:n[t],selectedIndex:0}),c("Project initialized",null)}},{intent:M.SetEditor,mode:p.COMMAND_LINE,action:()=>{let e=wt()?.trim();if(!e)return s("No editor provided");let t=Tn({preferredEditor:e});return l(t)?t:(st({preferredEditor:e}),A({mode:p.DEFAULT}),c(`Editor configuration set to "${e}"`,null))}},{intent:M.NewItem,mode:p.COMMAND_LINE,action:(e,t)=>{let n=Y();if(l(n))return s("Unable to resolve user ID");let r=n.data;if(!t.inputString)return s(`provide a name for your ${t.modifier}`);let{breadCrumb:o,currentNode:i,selectedIndex:a}=h(),d=m=>{let u=J(m);if(l(u))return u;let f=C.getNode(u.data.result.id);if(!f)return s("Created node not found");if(!f.parentNodeId)return u;let y=C.getNode(f.parentNodeId);return y?(D.navigate({currentNode:y,selectedIndex:C.getSiblings(f.parentNodeId).findIndex(({id:N})=>N===f.id)}),u):s("Parent node not found")};if(t.modifier==="board"){let{rootNodeId:m}=h(),u=C.getNode(m);return u?d({id:_(),userId:r,action:"add.board",payload:{id:_(),name:t.inputString,parent:u.id}}):s("Workspace not found")}if(t.modifier==="swimlane"){let m=Qe(o,"BOARD");return l(m)?s("Unable to add swimlane in this context"):d({id:_(),userId:r,action:"add.swimlane",payload:{id:_(),name:t.inputString,parent:m.data.id}})}if(t.modifier==="issue"){let m=T(i.id)[a],u=i.context==="SWIMLANE"?i:i.context==="BOARD"&&m?.context==="SWIMLANE"?m:(()=>{let b=Qe(o,"SWIMLANE");return l(b)?null:b.data})();if(!u)return s("Unable to add issue in this context");let f=_r({userId:r,name:t.inputString,parent:u.id}),y=Ft(f);if(y.some(b=>l(b)))return s("Issue create failed: "+y.filter(l).map(b=>b.message).filter(Boolean).join(", "));let N=y[0];if(!N||l(N))return s("Issue creation failed");let S=f[0]?.payload.id;return S?(D.navigate({currentNode:u,selectedIndex:C.getSiblings(u.id).findIndex(({id:b})=>b===S)}),c("Issue created",null)):s("Unable to determine ticket id")}return sr()},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.SetView,mode:p.COMMAND_LINE,action:()=>{let{commandMeta:e}=ue();return e.validity===ye.Invalid?s("Invalid command "+ve):(ie(t=>({...t,viewMode:e.modifier==="wide"?"wide":e.modifier==="dense"?"dense":t.viewMode})),c("View set",null))},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Rename,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{currentNode:n,selectedIndex:r}=h(),o=T(n.id)[r];if(!o)return s("Missing node");if(o.readonly)return s("Cannot rename readonly node");let i=wt();return i?J({id:_(),userId:t,action:"edit.title",payload:{id:o.id,name:i}}):s("Provide a new name")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.TagTicket,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{modifier:n,inputString:r}=ue().commandMeta,o=(n||r).trim();if(!o)return s("Provide a tag");let{selectedIndex:i,currentNode:a}=h(),d=T(a.id)[i];if(!d)return s("Invalid tag target");let m=Ve(d.id,"TICKET");if(l(m))return s("Unable to tag issue in this context");let u=m.data,f=Js(o),y;if(f)y=f.id;else{let b=_(),I=J({id:_(),userId:t,action:"create.tag",payload:{id:b,name:o}});if(l(I))return I;y=I.data.result.id}let N=C.getFieldByTitle(u.id,"Tags");return N?T(N.id).some(b=>b.props?.value===y)?s("Already tagged with that tag"):J({id:_(),userId:t,action:"tag.issue",payload:{id:_(),target:u.id,tagId:y}}):s("Unable to locate tags field")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.AssignUserToTicket,mode:p.COMMAND_LINE,action:()=>{let e=Y();if(l(e))return s("Unable to resolve user ID");let t=e.data,{modifier:n,inputString:r}=ue().commandMeta,o=(n||r).trim();if(!o)return s("Provide an assignee");let{selectedIndex:i,currentNode:a}=h(),d=T(a.id)[i];if(!d)return s("Invalid assign target");let m=Ve(d.id,"TICKET");if(l(m))return s("Unable to assign issue in this context");let u=m.data,f=Qs(o),y;if(f)y=f.id;else{let b=_(),I=J({id:_(),userId:t,action:"create.contributor",payload:{id:b,name:o}});if(l(I))return I;y=I.data.result.id}let N=C.getFieldByTitle(u.id,"Assignees");return N?T(N.id).some(b=>b.props?.value===y)?s("Assignee already assigned"):J({id:_(),userId:t,action:"assign.issue",payload:{id:_(),target:u.id,contributor:y}}):s("Unable to locate assignees field")},onSuccess:()=>A({mode:p.DEFAULT})},{intent:M.Sync,mode:p.COMMAND_LINE,action:async()=>{H(()=>""),A({syncStatus:{msg:"Syncing",status:"syncing"}});let{userId:e,userName:t}=de();if(!e)return s("Unable to resolve userId");if(!t)return s("Unable to resolve userName");let n=In();if(l(n))return s("Unable to resolve log file name");let r=await bo({ownEventFileName:n.data});return l(r)?(A({syncStatus:{msg:r.message,status:"outOfSync"}}),s(`Unable to sync state. ${r.message}`)):(A({syncStatus:{msg:"Synced",status:"synced"},mode:p.DEFAULT}),c("Synced",!0))}}];var oe=async({isForceExecutedBySystem:e=!1}={})=>{let{commandMeta:{command:t,validity:n,modifier:r,inputString:o}}=ue();if(!t)return s("No command to confirm");if(!e&&n===ye.Invalid)return s("Invalid command");let i=Br(t);Mr();let a=Ao.filter(m=>e||m.systemOnly!==!0).find(m=>m.intent===i);if(!a)return At({result:ve.Fail,message:"Command not found",data:null});let d=await a.action(a,{command:t,inputString:o,modifier:r});return l(d)?At(d):(Rr({addToHistory:!e}),a.onSuccess?.(),At(d))};var Ot=[{intent:"exit",mode:p.MOVE,description:"[<Esc>] exit context / cancel",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"move cancel"),oe({isForceExecutedBySystem:!0}))},{intent:"initMove",mode:p.DEFAULT,description:"[m] move init/confirm",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"move start"),oe({isForceExecutedBySystem:!0}))},{intent:"confirmMove",mode:p.MOVE,action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"move confirm"),oe({isForceExecutedBySystem:!0}))}],Ut=[{intent:"movePreviousItem",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move previous"),oe({isForceExecutedBySystem:!0})):s("No pending move")},{intent:"moveNextItem",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move next"),oe({isForceExecutedBySystem:!0})):s("No pending move")}],To=[{intent:"moveToNextContainer",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move to-next"),oe({isForceExecutedBySystem:!0})):s("No pending move")},{intent:"moveToPreviousContainer",mode:p.MOVE,action:()=>Oe()?(A({mode:p.COMMAND_LINE}),H(()=>"move to-previous"),oe({isForceExecutedBySystem:!0})):s("No pending move")}];var Mo={[R.WORKSPACE]:[...Ot,...Ut],[R.BOARD]:[...Ot,...Ut],[R.SWIMLANE]:[...Ot,...Ut,...To],[R.TICKET]:[],[R.FIELD]:[],[R.FIELD_LIST]:[],[R.TEXT]:[]};var Ro=[{intent:"addItem",mode:p.DEFAULT,description:"[n] new...",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>`${g.NEW} `),c("Adding new item",null))},{intent:"Delete",mode:p.DEFAULT,description:"[d] delete",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>`${g.DELETE} `),c("Deleting item",null))},{intent:"initCommandLine",mode:p.DEFAULT,description:"[:] focus command line",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>""),c("Entering command line mode",null))},{intent:"confirm",mode:p.DEFAULT,description:"[<Enter>] confirm/enter",action:()=>(D.enterChildNode(),c("Entering context",null))},{intent:"exit",mode:p.DEFAULT,description:"[q] exit context",action:()=>(logger.debug("Executing exit action"),D.enterParentNode(),c("Exiting context",null))},{intent:"navPreviousItem",mode:p.DEFAULT,description:"[arrows/hjkl] navigate",action:()=>(D.navigateToPreviousItem(),c("Navigating to previous item",null))},{intent:"navNextItem",mode:p.DEFAULT,action:()=>(D.navigateToNextItem(),c("Navigating to next item",null))},{intent:"navToPreviousContainer",mode:p.DEFAULT,action:()=>(D.navigateToPreviousContainer(),c("Navigating to previous container",null))},{intent:"navToNextContainer",mode:p.DEFAULT,action:()=>(D.navigateToNextContainer(),c("Navigating to next container",null))},{intent:"edit",mode:p.DEFAULT,action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"edit"),oe(),c("Fired command",!0))},{intent:"SetViewDense",mode:p.DEFAULT,description:"[v] view change (wide/dense)",action:()=>(A({viewMode:"dense"}),c("View set",null))},{intent:"SetViewWide",mode:p.DEFAULT,action:()=>(A({viewMode:"wide"}),c("View set",null))},{intent:"sync",mode:p.DEFAULT,description:"[s] sync epiq with remote state branch",action:()=>(A({mode:p.COMMAND_LINE}),H(()=>"sync"),oe({isForceExecutedBySystem:!0}),c("Synced",!0))}];var Lo=[{intent:"viewHelp",mode:p.DEFAULT,action:()=>(A({mode:p.HELP}),c("Viewing help",null))},{intent:"exit",mode:p.HELP,action:()=>(A({mode:p.DEFAULT}),c("Exiting help",null))},{intent:"confirm",mode:p.COMMAND_LINE,action:()=>(oe(),c("Executing command",null))},{intent:"MoveCursorLeft",mode:p.COMMAND_LINE,action:()=>(yn(-1),c("Moving cursor left",null))},{intent:"MoveCursorRight",mode:p.COMMAND_LINE,action:()=>(yn(1),c("Moving cursor right",null))},{intent:"MoveCursorLeftOfWord",mode:p.COMMAND_LINE,action:()=>(vn("left"),c("Moving cursor left of word",null))},{intent:"MoveCursorRightOfWord",mode:p.COMMAND_LINE,action:()=>(vn("right"),c("Moving cursor right of word",null))},{intent:"exitCommandLine",mode:p.COMMAND_LINE,action:()=>(A({mode:p.DEFAULT}),c("Exiting command line",null))},{intent:"autoCompleteCommand",mode:p.COMMAND_LINE,action:()=>(H((e,{remainder:t})=>t?e+t:e),c("Auto-completing command",null))},{intent:"captureInput",mode:p.COMMAND_LINE,action:(e,{sequence:t})=>(H(n=>n+t),c("Capturing input",null))},{intent:"eraseInput",mode:p.COMMAND_LINE,action:()=>(wr(),c("Erasing input",null))},{intent:"EraseInputWord",mode:p.COMMAND_LINE,action:()=>(Tr(),c("Erasing input word",null))},{intent:"getLastCommandFromHistory",mode:p.COMMAND_LINE,action:()=>(Lr(),c("Getting last command from history",null))},{intent:"getNextCommandFromHistory",mode:p.COMMAND_LINE,action:()=>(Pr(),c("Getting next command from history",null))}];import Zs from"chalk";var Wt=": for command line",Po="q to exit",Do=`${Zs.hex(v.accent)("m")} to confirm`,On={[R.WORKSPACE]:[Wt],[R.BOARD]:[Wt],[R.BOARD+p.COMMAND_LINE]:[Wt],[R.SWIMLANE]:[Wt],[R.TICKET+p.HELP]:[Po],[R.SWIMLANE+p.HELP]:[Po],[R.TICKET]:[],[R.FIELD]:[],[R.SWIMLANE+p.MOVE]:[Do],[R.TICKET+p.MOVE]:[Do]};var Ht=e=>e.trim().toLocaleLowerCase(),ea=(e,t)=>{let n=C.getFieldByTitle(e,t);if(!n)return"";let r=n.props?.value;return typeof r=="string"?r:""},ta=e=>{let{tags:t}=h(),n=C.getFieldByTitle(e,"Tags");return n?W(n.id).map(r=>{let o=r.props?.value;return typeof o=="string"?t[o]?.name:void 0}).filter(r=>!!r):[]},na=e=>{let{contributors:t}=h(),n=C.getFieldByTitle(e,"Assignees");return n?W(n.id).map(r=>{let o=r.props?.value;return typeof o=="string"?t[o]?.name:void 0}).filter(r=>!!r):[]},Fo=(e,t)=>{let n=t.value;if(!n)return!0;switch(t.target){case"title":return Ht(e.title??"").includes(n);case"description":return Ht(ea(e.id,"Description")).includes(n);case"tag":return ta(e.id).map(Ht).some(d=>d.includes(n));case"assignee":return na(e.id).map(Ht).some(d=>d.includes(n));default:return!0}};function Bo(e,t,n){let r=t[e];if(!r)return s("buildBreadCrumb(): current node not found");let o=[],i=r;for(;i&&(o.push(i),!(i.id===n||!i.parentNodeId));)i=t[i.parentNodeId];let a=o[o.length-1];return!a||a.id!==n?s("buildBreadCrumb(): node is not connected to root"):(o.reverse(),c("Breadcrumb built",o))}var ko=e=>{let t={};for(let n of e)n.intent&&(t[n.mode]||(t[n.mode]={}),t[n.mode][n.intent]=n);return t};var _t,Un=new Set,Oo=()=>{for(let e of Un)e()},oa=e=>(Un.add(e),()=>Un.delete(e));function Uo(e){let{currentNodeId:t,mode:n,rootNodeId:r,nodes:o,filters:i}=e;if(!t)return s("derive(): currentNodeId is missing");if(!r)return s("derive(): rootNode is missing");if(!o[r])return s("derive(): unable to find root node");let d=o[t];if(!d)return logger.error("Unable to derive state, currentNode not found"),s("Unable to derive state, currentNode not found");let m=Bo(t,o,r);if(l(m))return logger.error(m.message),m;let u=m.data,{context:f}=d,y=On[f+n]??On[f]??[],N=[...Ro,...Mo[f]??[],...Lo],S=ko(N);return c("Derived successfully",{...e,currentNode:d,breadCrumb:u,availableHints:y,availableActions:N,actionIndex:S,renderedChildrenIndex:ia(o,i)})}var h=()=>(_t||logger.error("State not initialized. Call initWorkspaceState() first.",new Error().stack),_t);function Vr(e){let t={filters:[],tags:{},contributors:{},viewMode:"dense",mode:p.DEFAULT,nodes:{[e.id]:e},rootNodeId:e.id,currentNodeId:e.id,renderedChildrenIndex:{},selectedIndex:-1,syncStatus:{status:"synced",msg:""}},n=Uo(t);return l(n)?n:(_t=n.data,Oo(),c("State initialized",null))}function ie(e){let t=h(),n=e(t),r=Uo(n);return l(r)?s(r.message??"Unable to update state"):(_t=r.data,Oo(),c("State updated",null))}var A=e=>ie(t=>({...t,...e}));var $=()=>ra(oa,h,h),ia=(e,t)=>{let n={};for(let r of Object.values(e))Be(r)&&t.length>0&&!t.every(o=>Fo(r,o))||!r.parentNodeId||r.isDeleted||((!r.parentNodeId||!n[r.parentNodeId])&&(n[r.parentNodeId]=[]),n[r.parentNodeId].push(r));for(let r of Object.keys(n))n[r].sort((o,i)=>{let a=e[o.id],d=e[i.id];return!a||!d?0:a.rank.localeCompare(d.rank)});return n},T=e=>h().renderedChildrenIndex[e]??[];var D={exit(){process.exit(0)},enterChildNode(){let e=h(),t=e.currentNode,n=Math.max(0,e.selectedIndex),r=T(t.id)[n];!r||t.context==="FIELD"||D.navigate({currentNode:r,selectedIndex:T(r.id).length?0:-1})},enterParentNode(){let{currentNode:e,nodes:t}=h();if(!e.parentNodeId){logger.info("Missing parent node id");return}let n=t[e.parentNodeId];if(!n){logger.error("Parent not found");return}let r=T(n.id),o=r.findIndex(({id:a})=>a===e.id),i=r.length===0?-1:o>=0?o:0;D.navigate({currentNode:n,selectedIndex:i})},navigateToNextItem:()=>Wo(1),navigateToPreviousItem:()=>Wo(-1),navigateToNextContainer:()=>Ho(1),navigateToPreviousContainer:()=>Ho(-1),navigate:({currentNode:e=h().currentNode,selectedIndex:t})=>{A({currentNodeId:e.id,selectedIndex:t})}},Wo=e=>{let t=h(),n=T(t.currentNode.id).length;if(n===0)return;let o=(Math.max(0,t.selectedIndex)+e+n)%n;D.navigate({selectedIndex:o})},Ho=e=>{let{currentNode:t,nodes:n,selectedIndex:r}=h();if(!t.childNavigationAcrossParents)return;if(!t.parentNodeId){logger.error("Missing parent node id");return}let o=n[t.parentNodeId];if(!t||!o)return;let i=T(o.id),a=i.findIndex(N=>N.id===t.id);if(a<0)return;let d=i.at(a+e)??i.at(0);if(!d)return;let m=T(d.id),u=Math.max(0,m.length-1),f=Math.min(Math.max(0,r),u),y=m.length?f:-1;D.navigate({currentNode:d,selectedIndex:y})};var Ee="system.actor",mt=sa(),Me=null;function aa(){let e=Object.values(h().nodes).find(r=>r.context==="WORKSPACE");if(!e)throw new Error("No workspace found in event log");let[t]=T(e.id),[n]=t?T(t.id):[];if(logger.debug("Boot navigation target:",{workspace:e?.id,firstBoard:t?.id,firstSwimlane:n?.id}),n){let r=h().renderedChildrenIndex?.[n.id]??[];return{currentNode:n,selectedIndex:r.length>0?0:-1}}else return t?{currentNode:t,selectedIndex:0}:e?{currentNode:e,selectedIndex:0}:{currentNode:h().nodes[h().rootNodeId],selectedIndex:0}}function da(){let e=aa();D.navigate(e)}function ca(){let e=mt(),t=mt(),n=mt(),r=mt(),o=mt();return[{id:Ne(),userId:Ee,action:"init.workspace",payload:{id:e,name:"Workspace"}},{id:Ne(),userId:Ee,action:"add.board",payload:{id:t,name:"Default",parent:e}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:n,name:"Todo",parent:t}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:r,name:"Review",parent:t}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:o,name:"Done",parent:t}},{id:Ne(),userId:Ee,action:"add.board",payload:{id:Lt,name:"Closed",parent:e}},{id:Ne(),userId:Ee,action:"add.swimlane",payload:{id:qe,name:"Closed",parent:Lt}},{id:Ne(),userId:Ee,action:"lock.node",payload:{id:Lt}},{id:Ne(),userId:Ee,action:"lock.node",payload:{id:qe}}]}function bt(){return Me!==null}function wo(){if(!Me||Me.length===0)return c("No pending default events to persist",null);let t=Ft(Me).filter(l);return t.length>0?s([et.bold.red("Materializing failed"),"",...t.map((n,r)=>`${et.dim.gray(`${r+1}.`)} ${et.dim(n.message)}`),`
|
|
26
26
|
`].join(`
|
|
27
27
|
`)):(Me=null,c("Persisted pending default events",null))}function _o(e){let t;e.some(r=>r.action==="init.workspace")?(Me=null,t=Cn(e)):(Me=ca(),t=Cn([...Me]));let n=t.filter(l);return n.length>0?s([et.bold.red("Materializing failed"),"",...n.map((r,o)=>`${et.dim.gray(`${o+1}.`)} ${et.dim(r.message)}`),`
|
|
28
28
|
`].join(`
|