epiq 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- process.env.NODE_ENV||="production";await import("./Index-LDGDOFWA.js");
2
+ process.env.NODE_ENV||="production";await import("./Index-S6LJGU7V.js");
package/dist/mcp.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- process.env.EPIQ_MCP="true";process.env.NODE_ENV||="production";console.log=console.error;console.info=console.error;console.debug=console.error;console.warn=console.error;var{applyActorNameArgument:r}=await import("./actor-env-F6R6NBSD.js"),{isFail:s}=await import("./result-types-RM3ASLV3.js"),{parseMcpArgs:t}=await import("./args-R7R2SBPG.js"),e=t(process.argv.slice(2));e.kind==="error"&&(console.error(e.message),process.exit(1));e.kind==="print"&&(process.stdout.write(e.text),process.exit(0));if(e.kind==="name"){let o=r(e.name,"The name argument");s(o)&&(console.error(o.message),process.exit(1))}var{setVirtualNodesEnabled:n}=await import("./virtual-nodes-QB7VWWF2.js");n(!1);var{startMcpServer:a}=await import("./server-GPNBR24F.js");await a();
2
+ process.env.EPIQ_MCP="true";process.env.NODE_ENV||="production";console.log=console.error;console.info=console.error;console.debug=console.error;console.warn=console.error;var{applyActorNameArgument:r}=await import("./actor-env-F6R6NBSD.js"),{isFail:s}=await import("./result-types-RM3ASLV3.js"),{parseMcpArgs:t}=await import("./args-SB26WNBZ.js"),e=t(process.argv.slice(2));e.kind==="error"&&(console.error(e.message),process.exit(1));e.kind==="print"&&(process.stdout.write(e.text),process.exit(0));if(e.kind==="name"){let o=r(e.name,"The name argument");s(o)&&(console.error(o.message),process.exit(1))}var{setVirtualNodesEnabled:n}=await import("./virtual-nodes-QB7VWWF2.js");n(!1);var{startMcpServer:a}=await import("./server-ZFM45XFD.js");await a();
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{$ as Ie,B as Y,C as W,D as V,E as Z,F as ee,G as te,H as ie,I as oe,J as ne,K as se,L as re,M as ae,N as ce,O as le,P as de,Q as me,R as pe,S as he,T as ue,U as ge,V as fe,W as we,X as be,Y as ye,Z as _e,_ as ve,b as R,ba as ke,ca as qe,da as Se,fa as Re,i as D,k as G,ka as Te,l as O,m as $,p as B,t as F,u as H,v as K,w as z,x as X,y as J,z as Q}from"./chunk-KQQQ5HBS.js";import{Kb as U,ab as S,b as N,ca as M,h as A,l as C,m as P,x as L}from"./chunk-C4V7IKIG.js";import{a as x}from"./chunk-WUCQWBQE.js";import{b as r,c as w,d as a}from"./chunk-5RIQL7P4.js";import{McpServer as Be}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as Fe}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as e}from"zod";import{ulid as De}from"ulid";var Ee=[{name:"userName",question:"the name they want to appear under on the board"},{name:"preferredEditor",question:'the command that opens a file for editing, e.g. "vim", "nano" or "code --wait"'},{name:"autoSync",question:"whether the TUI and GUI should sync with the git remote on their own (true or false)"}],je=t=>t.trim().toLowerCase(),xe=async(t={})=>{let o=C();if(a(o))return r(o.message);let n=o.value,c=t.userName?.trim(),E=(process.env[x]??"").trim();if(c&&E&&je(c)===je(E))return r(`userName "${c}" is this agent's own identity. Pass the user's name, the one they want the TUI and GUI to write as.`);let m={userName:c||void 0,preferredEditor:t.preferredEditor?.trim()||void 0,autoSync:t.autoSync},g={userName:n.userName?.trim()||void 0,preferredEditor:n.preferredEditor?.trim()||void 0,autoSync:typeof n.autoSync=="boolean"?n.autoSync:void 0};for(let s of Ee){let d=m[s.name],f=g[s.name];if(!(d===void 0||f===void 0||d===f))return r(`This machine is already set up with ${s.name} ${JSON.stringify(f)}; epiq_project_init does not change it. Call again without ${s.name}, or let the user change it in the TUI with :config.`)}let l={};if(m.userName&&!g.userName&&(l.userName=m.userName),m.preferredEditor&&!g.preferredEditor&&(l.preferredEditor=m.preferredEditor),m.autoSync!==void 0&&g.autoSync===void 0&&(l.autoSync=m.autoSync),(l.userName||g.userName)&&!n.userId&&(l.userId=De()),Object.keys(l).length>0){let s=P(l);if(a(s))return r(s.message)}let I={...n,...l},k=Ee.filter(s=>{let d=I[s.name];return typeof d=="boolean"?!1:!d?.trim()});if(k.length>0){let s=k.map(_=>`${_.name} (${_.question})`).join("; "),d=k.some(_=>_.name==="userName")?await D(t.repoRoot??process.cwd()):null,f=d?` This repository's git user.name is ${JSON.stringify(d)} \u2014 offer it as the default for userName, and use it only if the user agrees.`:"";return r(`Setup incomplete. Ask the user for: ${s}.${f} Then call epiq_project_init again with the answers; what was given so far is saved.`)}let b={userId:I.userId??"",userName:I.userName??""};if(!b.userId||!b.userName)return r("Missing Epiq user id");let q=await U({cwd:t.repoRoot??process.cwd(),user:b});if(a(q))return q;let{defaultEvents:ze,...y}=q.value,j=M({root:y.repoRoot});a(j)&&N.info(j.message);let Ue=y.warnings.length===0?"Project initialized":`Project initialized, with warnings: ${y.warnings.join(" ")}`;return w(Ue,{...y,user:b})};import v from"node:fs";import Ne from"node:path";var p=".claude/skills/epiq/SKILL.md",T=`---
2
+ import{$ as Ie,B as Y,C as W,D as V,E as Z,F as ee,G as te,H as ie,I as oe,J as ne,K as se,L as re,M as ae,N as ce,O as le,P as de,Q as me,R as pe,S as he,T as ue,U as ge,V as fe,W as we,X as be,Y as ye,Z as _e,_ as ve,b as R,ba as ke,ca as qe,da as Se,fa as Re,i as D,k as G,ka as Te,l as O,m as $,p as B,t as F,u as H,v as K,w as z,x as X,y as J,z as Q}from"./chunk-FLZ5VLKV.js";import{Kb as U,ab as S,b as N,ca as M,h as A,l as C,m as P,x as L}from"./chunk-C4V7IKIG.js";import{a as x}from"./chunk-WUCQWBQE.js";import{b as r,c as w,d as a}from"./chunk-5RIQL7P4.js";import{McpServer as Be}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as Fe}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as e}from"zod";import{ulid as De}from"ulid";var Ee=[{name:"userName",question:"the name they want to appear under on the board"},{name:"preferredEditor",question:'the command that opens a file for editing, e.g. "vim", "nano" or "code --wait"'},{name:"autoSync",question:"whether the TUI and GUI should sync with the git remote on their own (true or false)"}],je=t=>t.trim().toLowerCase(),xe=async(t={})=>{let o=C();if(a(o))return r(o.message);let n=o.value,c=t.userName?.trim(),E=(process.env[x]??"").trim();if(c&&E&&je(c)===je(E))return r(`userName "${c}" is this agent's own identity. Pass the user's name, the one they want the TUI and GUI to write as.`);let m={userName:c||void 0,preferredEditor:t.preferredEditor?.trim()||void 0,autoSync:t.autoSync},g={userName:n.userName?.trim()||void 0,preferredEditor:n.preferredEditor?.trim()||void 0,autoSync:typeof n.autoSync=="boolean"?n.autoSync:void 0};for(let s of Ee){let d=m[s.name],f=g[s.name];if(!(d===void 0||f===void 0||d===f))return r(`This machine is already set up with ${s.name} ${JSON.stringify(f)}; epiq_project_init does not change it. Call again without ${s.name}, or let the user change it in the TUI with :config.`)}let l={};if(m.userName&&!g.userName&&(l.userName=m.userName),m.preferredEditor&&!g.preferredEditor&&(l.preferredEditor=m.preferredEditor),m.autoSync!==void 0&&g.autoSync===void 0&&(l.autoSync=m.autoSync),(l.userName||g.userName)&&!n.userId&&(l.userId=De()),Object.keys(l).length>0){let s=P(l);if(a(s))return r(s.message)}let I={...n,...l},k=Ee.filter(s=>{let d=I[s.name];return typeof d=="boolean"?!1:!d?.trim()});if(k.length>0){let s=k.map(_=>`${_.name} (${_.question})`).join("; "),d=k.some(_=>_.name==="userName")?await D(t.repoRoot??process.cwd()):null,f=d?` This repository's git user.name is ${JSON.stringify(d)} \u2014 offer it as the default for userName, and use it only if the user agrees.`:"";return r(`Setup incomplete. Ask the user for: ${s}.${f} Then call epiq_project_init again with the answers; what was given so far is saved.`)}let b={userId:I.userId??"",userName:I.userName??""};if(!b.userId||!b.userName)return r("Missing Epiq user id");let q=await U({cwd:t.repoRoot??process.cwd(),user:b});if(a(q))return q;let{defaultEvents:ze,...y}=q.value,j=M({root:y.repoRoot});a(j)&&N.info(j.message);let Ue=y.warnings.length===0?"Project initialized":`Project initialized, with warnings: ${y.warnings.join(" ")}`;return w(Ue,{...y,user:b})};import v from"node:fs";import Ne from"node:path";var p=".claude/skills/epiq/SKILL.md",T=`---
3
3
  name: epiq
4
4
  description: Workflow for working an epiq issue board through the epiq MCP \u2014 take an identity, sync on demand, keep tickets small and their status, tags and comments current.
5
5
  ---
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epiq",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "EPIQ - ergonomic, distributed CLI-first issue tracker TUI ready for the agentic era",
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- var o="1.14.0";export{o as a};
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- import{$b as Ge,A as Nt,Aa as rt,B as kt,Ba as de,C as Pt,Ca as Qt,D as De,Da as ue,E as M,Ea as te,F as Ot,Fa as Zt,G as Mt,Ga as es,H as le,Ha as S,I as Dt,J as D,K as Fe,Lb as hs,M as ye,Ma as ts,N as Ft,Na as ss,O as _t,P as tt,Pa as os,Q as $t,Qa as ns,Qb as bs,R as Wt,Ra as rs,Rb as at,S as Gt,Sa as is,Sb as ys,T as _,Ta as as,Ua as ls,V as Q,Va as ds,W,Wa as us,Wb as We,Xb as Rs,_ as C,_b as As,ab as it,ac as lt,b as ke,bb as cs,c as ae,ca as jt,cb as P,d as Pe,dc as dt,e as Oe,ec as je,f as wt,fa as L,g as J,ga as Ut,ha as Ht,hc as F,i as St,ic as Ts,jc as Es,k as Me,ka as zt,la as st,lb as ce,ma as _e,mb as Ae,n as ee,na as Kt,o as xt,oa as Xt,ob as me,pa as Re,q as et,qa as $e,ra as qt,rb as ms,s as Ct,sa as Vt,sb as ps,ta as ot,tb as fs,ua as nt,va as A,wa as Yt,wb as gs,xa as w,xb as Is,y as Bt,ya as Jt,yb as vs,z as Lt}from"./chunk-C4V7IKIG.js";import{g as Et}from"./chunk-WUCQWBQE.js";import{b as d,c as f,d as a}from"./chunk-5RIQL7P4.js";var Eo=e=>e.payload??{},ut=e=>{let t=new Map,s={},o=new Set,n=new Set,l=new Set;for(let r of e){let{id:i,name:u}=Eo(r);if(i)switch(r.action){case"create.contributor":case"create.tag":t.set(i,u??""),o.add(i),n.delete(i);break;case"rename.contributor":u!==void 0&&o.has(i)&&!n.has(i)&&t.set(i,u);break;case"tombstone.contributor":o.has(i)&&(t.set(i,Fe),n.add(i));break;case"restore.contributor":case"restore.tag":u!==void 0&&o.has(i)&&(t.set(i,u),n.delete(i));break;case"add.board":u!==void 0&&(t.set(i,u),l.add(i));break;case"add.swimlane":u!==void 0&&(t.set(i,u),l.add(i),s[i]=u);break;case"edit.title":u!==void 0&&l.has(i)&&(t.set(i,u),i in s&&(s[i]=u));break;default:break}}return{byId:t,lanes:s}};var wo=e=>{let t=new Map,s=new Map;for(let o of e){let n=o.payload;!n?.id||!n.parent||(o.action==="move.node"&&t.set(o.id,s.get(n.id)),s.set(n.id,n.parent))}return t},Ss=e=>{let t=e.payload;return e.action==="tombstone.tag"||e.action==="restore.tag"?t?.id:t?.tag},So=e=>{let t=new Set,s=new Map;for(let o of e){let n=o.payload,l=n?.id;l&&(o.action==="add.issue"&&t.add(l),n.parent&&s.set(l,n.parent))}return{issueIds:t,parentById:s}},xo=(e,{issueIds:t,parentById:s})=>{let o=e.payload;if(o?.issue)return o.issue;let n=new Set,l=o?.id;for(;l!==void 0&&!n.has(l);){if(t.has(l))return l;n.add(l),l=s.get(l)}return null},Co=new Set(["add.issue.comment","edit.issue.comment","delete.issue.comment"]),Bo=e=>Co.has(e.action)?e.payload?.id??null:null,Lo=new Set(["add.issue","move.node","close.issue","reopen.issue"]),No=(e,t)=>{let s=new Map;return e.map((o,n)=>{let l=t[n]??null;if(l===null)return{lane:null,laneBefore:null};let r=o.payload,i=null;if(Lo.has(o.action)&&r?.id===l&&r.parent){let u=s.get(l);u!==void 0&&u!==r.parent&&(i=u),s.set(l,r.parent)}return{lane:s.get(l)??null,laneBefore:i}})},ws=90,ko=e=>{let t=e.trim().split(`
3
- `)[0]?.trim()??"";return t.length>ws?`${t.slice(0,ws).trimEnd()}\u2026`:t},Po=(e,t,s,o)=>{let n=e.payload,l=Ss(e),r=e.action?Ts(e.action):"";if(n?.md!==void 0){let u=ko(n.md),g=e.action==="edit.description"&&!o&&n.id?t.get(n.id):void 0,m=g?`${r} of ${g}`:r;return u?`${m}: ${u}`:m}if(e.action==="move.node"&&n?.parent){let u=t.get(n.parent);return u?s.get(e.id)===n.parent?`Moved within ${u}`:`Moved to ${u}`:r}if(kt(e.action))return[r,Pt(e)].filter(Boolean).join(" ");let i=l!==void 0?t.get(l)??"":n?.assignee!==void 0?t.get(n.assignee)??"":n?.email!==void 0?n.email:n?.name!==void 0?`"${n.name}"`:"";return[r,i].filter(Boolean).join(" ")},ct=(e,t)=>e?D(e,t.get(e)):null,Oo=(e,t)=>{let s=e.payload;return{actor:ct(e.userId,t),tag:ct(Ss(e),t),assignee:ct(s?.assignee,t)}},xs=e=>{let t=new Map,s=new Set,o=n=>{let l=new Set,r=n;for(;r&&!l.has(r);){if(s.has(r))return r;l.add(r),r=t.get(r)}return null};return e.map(n=>{let l=n.payload,r=l?.id;if(!r)return null;n.action==="add.board"&&s.add(r);let i=n.action==="close.issue"?o(r):null,u=l.parent??l.issue;return u&&t.set(r,u),i!==null?i:s.has(r)?r:o(r)})},Cs=e=>Mo.has(e),Mo=new Set(["create.contributor","rename.contributor","tombstone.contributor","restore.contributor","link.contributor.user","link.contributor.email","unlink.contributor.email","connect.repo","edit.repo","disconnect.repo"]),Bs=(e,t)=>{let s=xs(e);return e.filter((o,n)=>s[n]===t)},Do=(e,t=new Map)=>{let s=new Map([...t,...ut(e).byId]),o=wo(e),n=So(e),l=e.map(m=>xo(m,n)),r=No(e,l),i=xs(e),u=Ot(e.map(m=>le(m)));return e.flatMap((m,c)=>{let I=u[c]??null;return I===null?[]:[{id:m.id,t:I,action:m.action,label:Po(m,s,o,l[c]??null),issue:l[c]??null,target:Bo(m),...r[c],board:i[c]??null,...Oo(m,s)}]}).sort((m,c)=>m.t-c.t)},Fo=e=>{let t=new Map;for(let o of e){if(o.issue===null||o.lane===null)continue;let n=t.get(o.issue)??[],l=n[n.length-1];(l===void 0||l.lane!==o.lane)&&(n.push({t:o.t,lane:o.lane,board:o.board}),t.set(o.issue,n))}let s=new Map;for(let[o,n]of t){let l=n[n.length-1];s.set(o,{changes:n,from:n[0].t,closedFrom:l.lane===L?l.t:null})}return s},_o=(e,t)=>{let s=0,o=e.length;for(;s<o;){let n=s+o>>1;e[n].t<t?s=n+1:o=n}return e[s-1]},Ls=(e,t,s)=>{let o={};for(let[n,l]of e){if(l.from>=t||l.closedFrom!==null&&l.closedFrom<t)continue;let r=_o(l.changes,t);r===void 0||r.lane===L||s&&r.board!==s||(o[n]=r.lane)}return o},$o=e=>ut(e).lanes,Te=null,Ns=e=>{let t=$e(e);if(Te&&Te.root===e&&Te.signature===t)return f("Timeline entries, cached",Te.index);let s=te(e);if(a(s))return d(s.message);let o=Do(s.value,ue(e)),n={entries:o,lanes:Fo(o),laneNames:$o(s.value)};return Te={root:e,signature:t,index:n},f("Timeline entries, built",n)};var ks=1e5,Wo=2e4,Ue=null,Ps=Promise.resolve(),Ms=e=>{let t=Ps.then(e,e);return Ps=t.then(()=>{},()=>{}),t},He=e=>{let t=Re(e);return a(t)?t:J({repoRoot:t.value})},U=()=>{if(!je())return{mode:"live",asOfTime:null};let{timeMode:e}=As();return e==="live"?{mode:"live",asOfTime:null}:{mode:"scrub",asOfTime:Ue}},Os=(e,t)=>{let s=0,o=e.length;for(;s<o;){let n=s+o>>1;e[n].t<t?s=n+1:o=n}return s},ri=async(e={})=>{let t=He(e.repoRoot);if(a(t))return d(t.message);let s=Ns(t.value);if(a(s))return d(s.message);let o=s.value.entries,n=Date.now(),l=e.end??n,r=e.start??o[0]?.t??l;if(l<=r)return f("Empty time window",{bucketMs:0,buckets:[],capped:!1,events:[],lanesAtStart:{},laneNames:s.value.laneNames,closedLane:L,earliest:r,latest:l});let i=Os(o,r),u=Os(o,l),g=o.slice(i,u).filter(p=>!e.boardId||p.board===e.boardId||Cs(p.action)),m=g.map(p=>p.t),c=Math.max(1,Math.ceil((l-r)/ks)),I=new Map;for(let p of m){let b=Math.min(ks-1,Math.floor((p-r)/c)),R=r+b*c;I.set(R,(I.get(R)??0)+1)}let v=[...I.entries()].sort(([p],[b])=>p-b).map(([p,b])=>({t:p,count:b})),h=g.length>Wo;return f("Computed event timeline",{bucketMs:c,buckets:v,capped:h,events:h?[]:g,lanesAtStart:Ls(s.value.lanes,r,e.boardId),laneNames:s.value.laneNames,closedLane:L,earliest:r,latest:l})},Ds=e=>{let t=te(e);if(a(t))return d(t.message);let s=dt();if(a(s))return d(s.message);Ue=null;let o=rt(t.value),{fatal:n,skipped:l}=ot(o);return n.length>0?d(n.map(r=>r.message).join(", ")):(nt(l),lt({readOnly:!1,readOnlyReason:void 0,timeMode:"live",unappliedEvents:[],replay:null}),f("Restored live state",!0))},Go=(e,t)=>{Ue=null;let s=Ds(e);return a(s)?d(`${t} (recovery to live also failed: ${s.message})`):d(t)},jo=e=>Ms(async()=>{let t=He(e.repoRoot);if(a(t))return d(t.message);let s=Zt(t.value,e.targetTime);if(a(s))return d(s.message);let{appliedEvents:o,unappliedEvents:n}=s.value,l=dt();if(a(l))return l;let r=rt(o),{fatal:i,skipped:u}=ot(r);return i.length>0?Go(t.value,i.map(g=>g.message).join(", ")):(nt(u),lt({readOnly:!0,timeMode:"peek",unappliedEvents:n,replay:null}),Ue=e.targetTime,f("Checked out historical state",{asOfTime:e.targetTime}))}),ii=async e=>{let t=He(e.repoRoot);if(a(t))return d(t.message);let s=es(t.value);if(a(s))return d(s.message);let o=s.value.get(e.eventId)??null;return o===null?d("Event not found in the log"):jo({repoRoot:e.repoRoot,targetTime:o+1})},ai=(e={})=>Ms(async()=>{let t=He(e.repoRoot);if(a(t))return d(t.message);let s=Ds(t.value);return a(s)?d(s.message):f("Returned to live state",!0)});import{ulid as Ko}from"ulid";import Ho from"node:fs";var Fs=new Map,Uo=3e4,_s=async e=>{let t=Fs.get(e);if(t&&Date.now()-t.readAt<Uo)return{name:t.name,email:t.email};let s=await Oe({args:["config","--get-regexp","^user\\.(name|email)$"],cwd:e}),o=null,n=null;if(s.exitCode===0)for(let l of(s.stdout??"").split(`
4
- `)){let r=l.indexOf(" ");if(r===-1)continue;let i=l.slice(0,r),u=l.slice(r+1);i==="user.name"&&(o=u.trim()||null),i==="user.email"&&(n=ye(u)||null)}return Fs.set(e,{name:o,email:n,readAt:Date.now()}),{name:o,email:n}},$s=async e=>(await _s(e)).email,pe=async e=>(await _s(e)).name;var se=e=>{let t=Me(e??process.cwd());return a(t)?d(t.message):f("Resolved Epiq repo root",t.value)},ze=null,zo=async(e,t)=>{let s=se(e);if(a(s))return s;let o=J({repoRoot:s.value});if(a(o))return d(o.message);let n=ae(s.value);if(a(n))return d(n.message);if(!(ze!==null&&ze.repoRoot===s.value&&ze.stateBranchRoot===o.value&&Ho.existsSync(St(o.value)))){let c=await gs({repoRoot:s.value,stateBranchName:n.value});if(a(c))return d(c.message);let I=await Is({repoRoot:s.value,stateBranchRoot:o.value,stateBranchName:n.value});if(a(I))return d(I.message);ze={repoRoot:s.value,stateBranchRoot:o.value}}if(t?.pull??!1){let c=await Pe({cwd:o.value,args:["pull","--ff-only"]});a(c)&&ke.info(3,c.message)}let r={repoRoot:s.value,stateBranchRoot:o.value},i=ee();a(i)||et(i.value),et({gitEmail:await $s(s.value),gitName:await pe(s.value)});let u=$e(o.value);if(qt(o.value)===u&&je()&&U().mode==="live")return f("Booted Epiq state, unchanged",r);let g=de(o.value);if(a(g))return d(g.message);let m=me(g.value.events,g.value.unreadable);return a(m)?d(m.message):(Vt(o.value,u),f("Booted Epiq state",r))},G=()=>{let e=ee();return a(e)?d(e.message):e.value.userId?e.value.userName?f("Resolved actor",{userId:e.value.userId,userName:e.value.userName}):d("Unable to retrieve user name"):d("Unable to retrieve user id")},B=()=>{let e=Ge();return a(e)?d(e.message):e},O=e=>zo(e,{pull:!1}),T=async e=>{let t=await O(e);if(a(t))return t;let s=G();if(a(s))return s;let o=B();return a(o)?o:f("Booted",{boot:t.value,actor:s.value,state:o.value})};var N=e=>{let t=B();if(a(t))return t;let s=t.value.nodes[e];return!s||s.isDeleted?d("Issue not found"):_(s)?s.readonly?d("Issue is readonly"):f("Found issue",s):d("Target must be an issue")},X=e=>{let t=B();if(a(t))return t;let s=t.value.nodes[e];return!s||s.isDeleted?d("Swimlane not found"):Q(s)?s.readonly?d("Swimlane is readonly"):f("Found swimlane",s):d("Target must be a swimlane")},Ee=e=>{let t=B();if(a(t))return t;let s=t.value.nodes[e];return!s||s.isDeleted?d("Board not found"):W(s)?s.readonly?d("Board is readonly"):f("Found board",s):d("Target must be a board")};var mt=e=>{if(!e)return;let t=B();if(a(t))return;let s=t.value.nodes[e];if(!s||!(W(s)||Q(s)))return;let o=s.props?.description;return o?.trim()?o:void 0},Ke=e=>{let t=mt(e);return t?{laneDescription:t}:{}},we=e=>{let t=mt(e);return t?{boardDescription:t}:{}},fe=e=>{let t=mt(e);return t?{description:t}:{}},Xe=({node:e,label:t,max:s,description:o,actor:n,stateBranchRoot:l})=>{let r=cs(o),i=P(t,r,s);if(i)return d(i);if(U().mode!=="live")return d(`Cannot edit the ${t.toLowerCase()} while time travelling`);let u={id:e.id,ref:w(e.id),description:r};if((e.props?.description??"")===r)return f("No changes made",u);let g={id:Ko(),...A(n),action:"edit.description",payload:{id:e.id,md:r}},m=S([g],l);return a(m)?d(m.message):f(`Edited ${t.toLowerCase()}`,u)},Xo=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=Ee(e.boardId);return a(s)?s:Xe({node:s.value,label:"Board description",max:it("board"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},qo=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=X(e.swimlaneId);return a(s)?s:Xe({node:s.value,label:"Swimlane description",max:it("swimlane"),description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})};import Vo from"node:fs";import Yo from"node:path";import{ulid as pt}from"ulid";var Jo=e=>{if(e.filePath)try{return f("Read attachment file",{data:Vo.readFileSync(e.filePath),name:e.name??Yo.basename(e.filePath)})}catch(t){return d(`Unable to read ${e.filePath}: ${t instanceof Error?t.message:String(t)}`)}return e.dataBase64?f("Decoded attachment data",{data:Buffer.from(e.dataBase64,"base64"),name:e.name??"image"}):d("Provide either filePath or dataBase64")},qe=()=>{let e=ee();return a(e)?st:e.value.attachmentMaxKb??st},Qo=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);if(a(s))return s;let o=Jo(e);if(a(o))return o;let n=Kt(t.value.boot.stateBranchRoot,o.value.data,qe());if(a(n))return n;let l=C(o.value.name).trim()||"image",r=pt(),i={id:pt(),...A(t.value.actor),action:"add.issue.attachment",payload:{id:r,issue:e.issueId,author:t.value.actor.userId,hash:n.value.hash,ext:n.value.ext,name:l,bytes:n.value.bytes}},u=S([i],t.value.boot.stateBranchRoot);if(a(u))return d(u.message);let g=_e(n.value.hash,n.value.ext);return f("Added issue attachment",{id:r,issueId:e.issueId,fileName:g,bytes:n.value.bytes,markdown:zt(l,g)})},Zo=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.eventLog.find(i=>i.action==="add.issue.attachment"&&i.payload.id===e.attachmentId);if(!s)return d("Unable to resolve attachment");if(s.payload.author!==t.value.actor.userId)return d("You can only delete your own attachments");let o=N(s.payload.issue);if(a(o))return o;if(t.value.state.eventLog.some(i=>i.action==="delete.issue.attachment"&&i.payload.id===e.attachmentId))return f("Attachment already deleted",{id:e.attachmentId,issueId:s.payload.issue});let l={id:pt(),...A(t.value.actor),action:"delete.issue.attachment",payload:{id:e.attachmentId,issue:s.payload.issue}},r=S([l],t.value.boot.stateBranchRoot);return a(r)?d(r.message):f("Deleted issue attachment",{id:e.attachmentId,issueId:s.payload.issue})},en=async e=>{let t=await O(e.repoRoot);return a(t)?t:Xt(t.value.stateBranchRoot,e.fileName,qe())};var tn=e=>{switch(e.action){case"add.issue":case"move.node":case"close.issue":case"reopen.issue":return e.payload.parent;default:return null}},ft=(e,t)=>{let s=[];for(let o of e){let n=tn(o);if(n===null||n===s.at(-1)?.laneId)continue;let l=le(o);s.push({laneId:n,enteredAt:l===null?t:De(l)})}return s},Se=(e,t)=>ft(e,t).at(-1)?.enteredAt??t;var Ws=new WeakMap,sn=e=>{let t=F.getNode(e);if(!t)return[];let s=Ws.get(t);if(s)return s;let o=new Set;t.parentNodeId&&o.add(t.parentNodeId);for(let l of t.log??[]){let r=l.payload;r.id===e&&r.parent&&o.add(r.parent)}let n=[...o];return Ws.set(t,n),n},xe=e=>{let t=new Set;e.parentNodeId&&t.add(e.parentNodeId);for(let o of e.log??[]){let n=o.payload;n.id===e.id&&n.parent&&t.add(n.parent)}let s=new Set;for(let o of t)for(let n of sn(o))s.add(n);return[...s]},oe=e=>Ut(e).map(t=>D(t.id,t.name)),Gs=e=>F.getCommentsByIssue(e).sort((t,s)=>t.id<s.id?-1:t.id>s.id?1:0).map(t=>({id:t.id,author:Dt(t.authorId,F.getContributor(t.authorId)?.name),createdAt:M(t.id),body:t.md})),ne=e=>Ht(e).map(({id:t,name:s})=>D(t,s));var on=async(e={})=>{let t=await O(e.repoRoot);if(a(t))return t;let s=B();return a(s)?s:f("Retrieved Epiq state",{root:t.value.repoRoot,stateBranchRoot:t.value.stateBranchRoot,nodes:s.value.nodes,rootNodeId:s.value.rootNodeId,contextNode:s.value.contextNode,selectedIndex:s.value.selectedIndex,eventLog:s.value.eventLog})},nn=365*24*60*60*1e3,rn=e=>{let t=B();if(a(t))return t;let s=t.value.nodes[e];return f("Issue description",s&&_(s)&&!s.isDeleted?s.props.description??"":"")},gt=()=>{let e=B();if(a(e))return e;let t=U(),s=t.mode!=="live",o=Object.values(e.value.nodes),n=o.filter(p=>W(p)&&!p.isDeleted),l=Date.now()-nn,r=new Map,i=new Map;for(let p of o)if(!p.isDeleted){if(Q(p)&&p.parentNodeId){let b=r.get(p.parentNodeId)??[];b.push(p),r.set(p.parentNodeId,b)}if(_(p)&&p.parentNodeId){if(p.parentNodeId===L&&M(p.id)<l)continue;let b=i.get(p.parentNodeId)??[];b.push(p),i.set(p.parentNodeId,b)}}let u=new Set;for(let p of i.values())for(let b of p)u.add(b.id);let g=ee();if(a(g))return g;let m={},c=F.getCommentsGroupedByIssue();for(let p of o.filter(_))p.isDeleted||!u.has(p.id)||(m[p.id]=(c.get(p.id)??[]).map(b=>{let R=F.getContributor(b.authorId);return{id:b.id,issueId:b.issue,body:b.md,author:D(b.authorId,R?.name),createdAt:M(b.id)}}));let I=new Map;for(let p of e.value.eventLog)p.action==="add.issue.attachment"&&I.set(p.payload.id,p.payload.author);let v={},h=F.getAttachmentsGroupedByIssue();for(let p of o.filter(_))p.isDeleted||!u.has(p.id)||(v[p.id]=(h.get(p.id)??[]).map(b=>({id:b.id,issueId:b.issue,name:b.name,fileName:_e(b.hash,b.ext),bytes:b.bytes,createdAt:M(b.id),canDelete:I.get(b.id)===g.value.userId})));return f("Retrieved Epiq GUI state",{boards:n.sort((p,b)=>p.rank.localeCompare(b.rank)).map(p=>({id:p.id,ref:w(p.id),title:p.title,readonly:!!p.readonly||s,...fe(p.id),swimlanes:(r.get(p.id)??[]).sort((b,R)=>b.rank.localeCompare(R.rank)).map(b=>({id:b.id,title:b.title,readonly:!!b.readonly||s,issues:(i.get(b.id)??[]).sort((R,V)=>R.rank.localeCompare(V.rank)).map(R=>({id:R.id,ref:w(R.id),title:C(R.title),description:R.props.description??"",createdAt:M(R.id),enteredLaneAt:Se(R.log??[],M(R.id)),readonly:!!R.readonly||s,tags:oe(R),assignees:ne(R),parentNodeId:R.parentNodeId,isClosed:R.parentNodeId===L,boardIds:xe(R)})),parentNodeId:b.parentNodeId,...fe(b.id)}))})),tags:F.getTags().map(p=>({...p,...D(p.id,p.name)})),contributors:Object.values(e.value.contributors).map(p=>({...p,...D(p.id,p.name)})),user:{id:g.value.userId??"",name:g.value.userName??"",color:Ct(g.value.userName??"")},commentsByIssueId:m,attachmentsByIssueId:v,attachmentMaxKb:qe(),timeTravel:t})},js=null,an=e=>{if(e===js)return;let t=jt({root:e});if(a(t)){ke.info(t.message);return}js=e},ln=async(e={})=>{if(U().mode!=="live")return gt();let t=await O(e.repoRoot);return a(t)?t:(an(t.value.repoRoot),gt())},dn=async(e={})=>{ms();let t=se(e.repoRoot);if(a(t))return d("Sync failed");let s=G();if(a(s))return s;let o=await vs({cwd:t.value,ownEventFileName:Yt(s.value)});return a(o)?(fs(o.message),o):(ps(),f("Synced",o.value))};import{ulid as H}from"ulid";var Ce=e=>{let t=[...new Set([...e.issueIds??[],...e.issueId?[e.issueId]:[]])];return t.length?f("Resolved targets",t):d("Provide issueId or issueIds")},ge=(e,t)=>{let s=t.done.length,o=`${e} ${s} issue${s===1?"":"s"}`+(t.failed.length?`, ${t.failed.length} failed`:"");return s?f(o,t):d(`${o}: ${t.failed.map(n=>`${n.ref} ${n.reason}`).join("; ")}`)},Be=(e,t)=>{let s={done:[],failed:[]};for(let o of e){let n=t(o);a(n)?s.failed.push({id:o,ref:w(o),reason:n.message}):s.done.push({id:o,ref:w(o)})}return s};var un=async e=>{let t=await O(e.repoRoot);if(a(t))return t;let s=B();if(a(s))return s;let o=e.idOrRef.trim();if(!o)return d("Provide an issue id or ref");let n=Object.values(s.value.nodes).filter(_).filter(u=>!u.isDeleted),l=n.find(u=>u.id===o),r=l?[l]:n.filter(u=>Jt(u.id,o));if(r.length===0)return d(`No issue matches "${o}"`);if(r.length>1)return d(`"${o}" matches ${r.length} issues: ${r.map(u=>`${w(u.id)} (${C(u.title)})`).join(", ")}. Use a full ref or id.`);let i=r[0];return f("Found issue",{id:i.id,ref:w(i.id),title:C(i.title),description:i.props.description??"",createdAt:M(i.id),enteredLaneAt:Se(i.log??[],M(i.id)),parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===L,boardIds:xe(i),readonly:!!i.readonly,tags:oe(i),assignees:ne(i),comments:Gs(i.id),...Ke(i.parentNodeId)})},zs=(e,t)=>e.trim().toLowerCase()===t.trim().toLowerCase();async function cn(e){let t=await O(e.repoRoot);if(a(t))return t;let s=B();if(a(s))return s;let o=s.value.nodes,n=e.query?.trim().toLowerCase(),l=Object.values(o).filter(_).filter(i=>!i.isDeleted).filter(i=>e.includeClosed||i.parentNodeId!==L).filter(i=>e.boardId?(i.parentNodeId?o[i.parentNodeId]:void 0)?.parentNodeId===e.boardId:!0).filter(i=>!e.swimlaneId||i.parentNodeId===e.swimlaneId).filter(i=>!e.tag||oe(i).some(u=>zs(u.name,e.tag))).filter(i=>!e.assignee||ne(i).some(u=>zs(u.name,e.assignee))).filter(i=>!n||i.title.toLowerCase().includes(n)||(i.props.description??"").toLowerCase().includes(n)),r=i=>C((i.parentNodeId?o[i.parentNodeId]?.title:void 0)??"");return e.brief?f("Listed issues",l.map(i=>({id:i.id,ref:w(i.id),title:C(i.title),swimlane:r(i),tags:oe(i).map(u=>u.name),assignees:ne(i).map(u=>u.name)}))):f("Listed issues",l.map(i=>({id:i.id,ref:w(i.id),title:C(i.title),description:i.props.description??"",createdAt:M(i.id),enteredLaneAt:Se(i.log??[],M(i.id)),parentNodeId:i.parentNodeId,isClosed:i.parentNodeId===L,boardIds:xe(i),readonly:!!i.readonly,tags:oe(i),assignees:ne(i)})))}var mn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=C(e.title);if(!s)return d("Issue title cannot be empty");let o=e.description??"",n=P("Issue title",s,300)??P("Issue description",o,2e4);if(n)return d(n);if((e.tagNames?.length??0)>20)return d(`Cannot set more than ${20} tags at once`);if((e.assigneeNames?.length??0)>20)return d(`Cannot set more than ${20} assignees at once`);let l=X(e.parentId);if(a(l))return l;let r=Ae(e.parentId,t.value.actor,t.value.boot.stateBranchRoot);if(a(r))return r;let i=hs({name:s,parent:e.parentId,user:t.value.actor,rank:r.value});if(a(i))return i;let u=[...i.value],g=u.find(v=>v.action==="add.issue")?.payload.id;if(!g)return d("Unable to determine created issue id");o&&u.push({id:H(),...A(t.value.actor),action:"edit.description",payload:{id:g,md:o}});let m=[];for(let v of e.tagNames??[]){let h=C(v).trim();if(!h||m.some(V=>V.name===h))continue;let p=P("Tag name",h,60);if(p)return d(p);let b=F.findTagByName(h),R=b?.id??H();b||u.push({id:H(),...A(t.value.actor),action:"create.tag",payload:{id:R,name:h}}),u.push({id:H(),...A(t.value.actor),action:"add.issue.tag",payload:{id:g,tag:R}}),m.push({id:R,name:h})}let c=[];for(let v of e.assigneeNames??[]){let h=C(v).trim();if(!h||c.some(V=>V.name===h))continue;let p=P("Assignee name",h,80);if(p)return d(p);let b=Object.values(t.value.state.contributors).find(V=>V.name===h),R=b?.id??H();b||u.push({id:H(),...A(t.value.actor),action:"create.contributor",payload:{id:R,name:h}}),u.push({id:H(),...A(t.value.actor),action:"add.issue.assignee",payload:{id:g,assignee:R}}),c.push({id:R,name:h})}let I=S(u,t.value.boot.stateBranchRoot);return a(I)?d(I.message):f("Created issue",{id:g,ref:w(g),title:s,parentId:e.parentId,description:o,tags:m,assignees:c,...Ke(e.parentId),...we(t.value.state.nodes[e.parentId]?.parentNodeId)})},pn=(e,t,s)=>{let o=N(e);if(a(o))return o;let n=ce(L,e,{at:"end"},t,s);if(a(n))return n;let l={id:H(),...A(t),action:"close.issue",payload:{id:e,parent:L,rank:n.value}},r=S([l],s);return a(r)?d(r.message):f("Closed issue",{id:e,ref:w(e)})};async function fn(e){let t=await O(e.repoRoot);if(a(t))return t;let s=G();if(a(s))return s;let o=Ce(e);if(a(o))return o;let n=l=>pn(l,s.value,t.value.stateBranchRoot);return e.issueIds?ge("Closed",Be(o.value,n)):n(o.value[0])}var gn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.nodes[e.issueId];if(!s||s.isDeleted)return d("Issue not found");if(!_(s))return d("Target must be an issue");if(s.parentNodeId!==L)return d("Issue is not closed");let o=bs(s);if(!o)return d("Unable to resolve previous parent from issue history");if(o===L)return d("Previous parent resolves to closed swimlane");let n=X(o);if(a(n))return n;let l=n.value,r=ce(l.id,s.id,{at:"end"},t.value.actor,t.value.boot.stateBranchRoot);if(a(r))return r;let i={id:H(),...A(t.value.actor),action:"reopen.issue",payload:{id:s.id,parent:l.id,rank:r.value}},u=S([i],t.value.boot.stateBranchRoot);return a(u)?d(u.message):f("Reopened issue",{id:s.id,ref:w(s.id),parentId:l.id})},In=(e,t,s,o)=>{let n=N(e);if(a(n))return n;let l=X(t.parentId);if(a(l))return l;let r=ce(t.parentId,e,t.position??{at:"end"},s,o);if(a(r))return r;let i={id:H(),...A(s),action:"move.node",payload:{id:e,parent:t.parentId,rank:r.value}},u=S([i],o);return a(u)?d(u.message):f("Moved issue",{id:e,ref:w(e),parentId:t.parentId})};async function vn(e){let t=se(e.repoRoot);if(a(t))return t;let s=G();if(a(s))return s;let o=J({repoRoot:t.value});if(a(o))return o;let n=de(o.value);if(a(n))return n;let l=me(n.value.events,n.value.unreadable);if(a(l))return l;let r=Ce(e);if(a(r))return r;let i=(()=>{let m=B();if(a(m))return()=>({});let{nodes:c}=m.value,I=p=>p?c[p]?.parentNodeId:void 0,v=I(e.parentId),h=r.value.some(p=>I(c[p]?.parentNodeId)!==v);return()=>({...Ke(e.parentId),...h?we(v):{}})})(),u=m=>In(m,e,s.value,o.value);if(!e.issueIds){let m=u(r.value[0]);return a(m)?m:f(m.message,{...m.value,...i()})}let g=ge("Moved",Be(r.value,u));return a(g)?g:f(g.message,{...g.value,...i()})}var hn=e=>{let t=B();if(a(t))return t;let s=t.value.nodes[e];return s?f("Read issue history",(s.log??[]).map(o=>({id:o.id,t:M(o.id),action:o.action,label:Es(o),...o.action==="move.node"?{parentId:o.payload.parent}:{},actor:D(o.userId,t.value.contributors[o.userId]?.name)}))):d("Issue not found")},bn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);return a(s)?s:Xe({node:s.value,label:"Issue description",max:2e4,description:e.description,actor:t.value.actor,stateBranchRoot:t.value.boot.stateBranchRoot})},yn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);if(a(s))return s;let o=s.value,n=C(e.title);if(!n.trim())return d("Issue title cannot be empty");let l=P("Issue title",n,300);if(l)return d(l);if(o.title===n)return f("No changes made",{id:e.issueId,ref:w(e.issueId),title:n});let r={id:H(),...A(t.value.actor),action:"edit.title",payload:{id:e.issueId,name:n}},i=S([r],t.value.boot.stateBranchRoot);return a(i)?d(i.message):f("Edited issue title",{id:e.issueId,ref:w(e.issueId),title:n})};import{ulid as Z}from"ulid";var Rn=async(e={})=>{let t=await O(e.repoRoot);if(a(t))return t;let s=B();if(a(s))return s;let o=Object.values(s.value.nodes).filter(n=>n.context==="BOARD"&&!n.isDeleted).map(n=>({id:n.id,ref:w(n.id),title:n.title,parentId:n.parentNodeId,readonly:!!n.readonly,...fe(n.id)}));return f("Listed boards",o)},An=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.nodes[t.value.state.rootNodeId];if(!s)return d("Workspace not found");if(U().mode!=="live")return d("Cannot add a board while time travelling");let o=C(e.title);if(!o.trim())return d("Board title cannot be empty");let n=P("Board title",o,300);if(n)return d(n);let l=Ae(s.id,t.value.actor,t.value.boot.stateBranchRoot);if(a(l))return l;let r=Z(),i={id:Z(),...A(t.value.actor),action:"add.board",payload:{id:r,name:o,parent:s.id,rank:l.value}},u=S([i],t.value.boot.stateBranchRoot);return a(u)?d(u.message):f("Created board",{id:r,ref:w(r),title:o})},Tn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.nodes[e.boardId];if(!s||s.isDeleted)return d("Board not found");if(!W(s))return d("Edit target must be a board");if(s.readonly)return d("Cannot edit readonly board");if(U().mode!=="live")return d("Cannot rename a board while time travelling");let o=C(e.title);if(!o.trim())return d("Board title cannot be empty");let n=P("Board title",o,300);if(n)return d(n);if(s.title===o)return f("No changes made",{id:e.boardId,ref:w(e.boardId),title:o});let l={id:Z(),...A(t.value.actor),action:"edit.title",payload:{id:e.boardId,name:o}},r=S([l],t.value.boot.stateBranchRoot);return a(r)?d(r.message):f("Edited board title",{id:e.boardId,ref:w(e.boardId),title:o})},En=async(e={})=>{let t=await O(e.repoRoot);if(a(t))return t;let s=B();if(a(s))return s;let o=Object.values(s.value.nodes).filter(n=>n.context==="SWIMLANE"&&!n.isDeleted).filter(n=>!e.boardId||n.parentNodeId===e.boardId).map(n=>({id:n.id,title:n.title,boardId:n.parentNodeId,isClosed:n.id===L,readonly:!!n.readonly,...fe(n.id)}));return f("Listed swimlanes",o)},wn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=Ee(e.boardId);if(a(s))return s;if(U().mode!=="live")return d("Cannot add a swimlane while time travelling");let o=C(e.title);if(!o.trim())return d("Swimlane title cannot be empty");let n=P("Swimlane title",o,300);if(n)return d(n);let l=Ae(e.boardId,t.value.actor,t.value.boot.stateBranchRoot);if(a(l))return l;let r=Z(),i={id:Z(),...A(t.value.actor),action:"add.swimlane",payload:{id:r,name:o,parent:e.boardId,rank:l.value}},u=S([i],t.value.boot.stateBranchRoot);return a(u)?d(u.message):f("Created swimlane",{id:r,ref:w(r),title:o,boardId:e.boardId})},Sn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=X(e.swimlaneId);if(a(s))return s;let o=s.value,n=C(e.title);if(!n.trim())return d("Swimlane title cannot be empty");let l=P("Swimlane title",n,300);if(l)return d(l);if(o.title===n)return f("No changes made",{id:e.swimlaneId,ref:w(e.swimlaneId),title:n});let r={id:Z(),...A(t.value.actor),action:"edit.title",payload:{id:e.swimlaneId,name:n}},i=S([r],t.value.boot.stateBranchRoot);return a(i)?d(i.message):f("Edited swimlane title",{id:e.swimlaneId,ref:w(e.swimlaneId),title:n})},xn=async e=>{let t=se(e.repoRoot);if(a(t))return t;let s=G();if(a(s))return s;let o=J({repoRoot:t.value});if(a(o))return o;let n=de(o.value);if(a(n))return n;let l=me(n.value.events,n.value.unreadable);if(a(l))return l;let r=X(e.swimlaneId);if(a(r))return r;let i=Ee(e.boardId);if(a(i))return i;let u=ce(e.boardId,e.swimlaneId,e.position??{at:"end"},s.value,o.value);if(a(u))return u;let g={id:Z(),...A(s.value),action:"move.node",payload:{id:e.swimlaneId,parent:e.boardId,rank:u.value}},m=S([g],o.value);return a(m)?d(m.message):f("Moved swimlane",{id:e.swimlaneId,ref:w(e.swimlaneId),boardId:e.boardId})},Cn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=X(e.swimlaneId);if(a(s))return s;let o={id:Z(),...A(t.value.actor),action:"delete.node",payload:{id:e.swimlaneId}},n=S([o],t.value.boot.stateBranchRoot);return a(n)?d(n.message):f("Deleted swimlane",{id:e.swimlaneId,ref:w(e.swimlaneId)})};import{ulid as Ie}from"ulid";async function Bn(e){let t=await O(e.repoRoot);if(a(t))return t;let s=G();if(a(s))return s;let o=Ce(e);if(a(o))return o;let n=C(e.tagName).trim();if(!n)return d("Tag name cannot be empty");let l=P("Tag name",n,60);if(l)return d(l);let r=Be(o.value,N);if(!e.issueIds&&r.failed[0])return d(r.failed[0].reason);if(r.done.length===0)return d(ge("Tagged",r).message);let i=F.findTagByName(n),u=i?.id??Ie(),g=[...i?[]:[{id:Ie(),...A(s.value),action:"create.tag",payload:{id:u,name:n}}],...r.done.map(({id:v})=>({id:Ie(),...A(s.value),action:"add.issue.tag",payload:{id:v,tag:u}}))],m=S(g,t.value.stateBranchRoot);if(a(m))return d(m.message);let c={id:u,name:n};if(!e.issueIds)return f("Added issue tag",{...r.done[0],tag:c});let I=ge("Tagged",r);return a(I)?I:f(I.message,{...I.value,tag:c})}var Ln=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.tags[e.tagId];if(!s)return d("Tag not found");if(s.tombstoned)return d("Tag is already deleted");let o=[{id:Ie(),...A(t.value.actor),action:"tombstone.tag",payload:{id:e.tagId}}],n=S(o,t.value.boot.stateBranchRoot);return a(n)?d(n.message):f("Deleted tag",{id:s.id,name:s.name})},Nn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.tags[e.tagId];if(!s)return d("Tag not found");if(!s.tombstoned)return d("Tag is not deleted");if(F.findTagByName(s.name))return d(`Cannot restore: another tag is already named "${s.name}"`);let o=[{id:Ie(),...A(t.value.actor),action:"restore.tag",payload:{id:e.tagId,name:s.name}}],n=S(o,t.value.boot.stateBranchRoot);return a(n)?d(n.message):f("Restored tag",{id:s.id,name:s.name})},kn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);if(a(s))return s;if(!t.value.state.tags[e.tagId])return d("Tag not found");let o={id:Ie(),...A(t.value.actor),action:"remove.issue.tag",payload:{id:e.issueId,tag:e.tagId}},n=S([o],t.value.boot.stateBranchRoot);return a(n)?d(n.message):f("Removed issue tag",{id:e.issueId,ref:w(e.issueId),tagId:e.tagId})};import{ulid as Y}from"ulid";var Pn=async e=>{let t=Et(e.name,"name");if(a(t))return d(t.message);let s=await T(e.repoRoot);if(a(s))return s;let o=s.value.actor,n=!!s.value.state.contributors[o.userId];if(!n){let r=S([{id:Y(),...A(o),action:"create.contributor",payload:{id:o.userId,name:o.userName}}],s.value.boot.stateBranchRoot);if(a(r))return d(r.message)}let l=Object.values(s.value.state.nodes).filter(r=>W(r)&&!r.isDeleted).flatMap(r=>{let{boardDescription:i}=we(r.id);return i?[{id:r.id,title:C(r.title),boardDescription:i}]:[]});return f(`Assumed ${o.userName}`,{...o,registered:!n,...l.length?{boards:l}:{}})},Xs=async(e,t)=>{let s=ue(e).get(t);return s===void 0?void 0:{id:t,name:s}},On=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);if(a(s))return s;let o=e.self?t.value.actor.userId:e.assigneeId;if(o){let v=t.value.state.contributors[o],h=v?void 0:await Xs(t.value.boot.stateBranchRoot,o);if(!v&&!h)return d("Unknown assignee id");let p=v??h,b=[...v?[]:[{id:Y(),...A(t.value.actor),action:"create.contributor",payload:{id:p.id,name:p.name}}],{id:Y(),...A(t.value.actor),action:"add.issue.assignee",payload:{id:e.issueId,assignee:p.id}}],R=S(b,t.value.boot.stateBranchRoot);return a(R)?d(R.message):f("Added issue assignee",{id:e.issueId,ref:w(e.issueId),assignee:{id:p.id,name:p.name}})}let n=C(e.assigneeName??"").trim();if(!n)return d("Provide assigneeId, self or assigneeName");let l=P("Assignee name",n,80);if(l)return d(l);let r=at({events:t.value.state.eventLog??[],registry:t.value.state.contributors,logFileNames:ue(t.value.boot.stateBranchRoot)}).filter(v=>v.name===n);if(r.length>1)return d(`"${n}" matches ${r.length} contributors (${r.map(({id:v})=>v).join(", ")}). Assign by assigneeId to choose.`);let i=r[0];if(!i&&!e.createUnlinked)return d(`No contributor named "${n}". Assign by id, or pass createUnlinked to add them as an external assignee.`);let u=i?.id??Y(),g=i?.name??n,c=[...!!t.value.state.contributors[u]?[]:[{id:Y(),...A(t.value.actor),action:"create.contributor",payload:{id:u,name:g}}],{id:Y(),...A(t.value.actor),action:"add.issue.assignee",payload:{id:e.issueId,assignee:u}}],I=S(c,t.value.boot.stateBranchRoot);return a(I)?d(I.message):f("Added issue assignee",{id:e.issueId,ref:w(e.issueId),assignee:{id:u,name:g}})},Mn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;if(!t.value.state.contributors[e.contributorId])return d("Contributor not found");if(await Xs(t.value.boot.stateBranchRoot,e.contributorId))return d("Cannot remove a contributor who has authored events \u2014 their name appears throughout the log");let n=[{id:Y(),...A(t.value.actor),action:"tombstone.contributor",payload:{id:e.contributorId}}],l=S(n,t.value.boot.stateBranchRoot);return a(l)?d(l.message):f("Tombstoned contributor",{id:e.contributorId,name:Fe})},Dn=async(e,t)=>{let s=te(e);if(a(s))return;let o;for(let n of s.value){if(n.action!=="create.contributor")continue;let l=n.payload;l.id===t&&l.name&&(o=l.name)}return o},Fn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.contributors[e.contributorId];if(!s)return d("Contributor not found");if(!s.tombstoned)return d("Contributor is not tombstoned");let o=await Dn(t.value.boot.stateBranchRoot,e.contributorId);if(!o)return d("Cannot restore this contributor \u2014 no original name found in the event log");let n=[{id:Y(),...A(t.value.actor),action:"restore.contributor",payload:{id:e.contributorId,name:o}}],l=S(n,t.value.boot.stateBranchRoot);return a(l)?d(l.message):f("Restored contributor",{id:e.contributorId,name:o})},_n=async(e={})=>{let t=await T(e.repoRoot);if(a(t))return t;let s=te(t.value.boot.stateBranchRoot);if(a(s))return d(s.message);let o=e.boardId?Bs(s.value,e.boardId):s.value,n=new Set,l=Qt(t.value.boot.stateBranchRoot);if(a(l))return d(l.message);for(let u of l.value)u.userId&&n.add(u.userId);let r=t.value.state.contributors,i=at({events:o,registry:r,logFileNames:ue(t.value.boot.stateBranchRoot)}).map(({id:u,name:g,isExternal:m})=>({...D(u,g),isSelf:u===t.value.actor.userId,isExternal:m,isRemoved:r[u]?.tombstoned===!0,hasAuthoredAnywhere:n.has(u)}));return f("Listed board contributors",i)},$n=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);if(a(s))return s;if(!t.value.state.contributors[e.assigneeId])return d("Assignee not found");let o={id:Y(),...A(t.value.actor),action:"remove.issue.assignee",payload:{id:e.issueId,assignee:e.assigneeId}},n=S([o],t.value.boot.stateBranchRoot);return a(n)?d(n.message):f("Removed issue assignee",{id:e.issueId,ref:w(e.issueId),assigneeId:e.assigneeId})};import{ulid as Ye}from"ulid";var Wn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=N(e.issueId);if(a(s))return s;let o=e.body.trim();if(!o)return d("Comment cannot be empty");if(o.length>4e3)return d(`Comment cannot exceed ${4e3} characters (got ${o.length})`);let n=Ye(),l={id:Ye(),...A(t.value.actor),action:"add.issue.comment",payload:{id:n,issue:e.issueId,md:o,author:t.value.actor.userId}},r=S([l],t.value.boot.stateBranchRoot);return a(r)?d(r.message):f("Added issue comment",{id:n,issueId:e.issueId,body:o})},Gn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.eventLog.find(i=>i.action==="add.issue.comment"&&i.payload.id===e.commentId);if(!s)return d("Unable to resolve comment");if(s.payload.author!==t.value.actor.userId)return d("You can only delete your own comments");let o=N(s.payload.issue);if(a(o))return o;if(t.value.state.eventLog.some(i=>i.action==="delete.issue.comment"&&i.payload.id===e.commentId))return f("Comment already deleted",{id:e.commentId,issueId:s.payload.issue});let l={id:Ye(),...A(t.value.actor),action:"delete.issue.comment",payload:{id:e.commentId,issue:s.payload.issue}},r=S([l],t.value.boot.stateBranchRoot);return a(r)?d(r.message):f("Deleted issue comment",{id:e.commentId,issueId:s.payload.issue})},jn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=t.value.state.eventLog.find(u=>u.action==="add.issue.comment"&&u.payload.id===e.commentId);if(!s)return d("Unable to resolve comment");if(s.payload.author!==t.value.actor.userId)return d("You can only edit your own comments");let o=N(s.payload.issue);if(a(o))return o;if(t.value.state.eventLog.some(u=>u.action==="delete.issue.comment"&&u.payload.id===e.commentId))return d("Comment was deleted");let l=e.body.trim();if(!l)return d("Comment cannot be empty");if(l.length>4e3)return d(`Comment cannot exceed ${4e3} characters (got ${l.length})`);let r={id:Ye(),...A(t.value.actor),action:"edit.issue.comment",payload:{id:e.commentId,issue:s.payload.issue,md:l}},i=S([r],t.value.boot.stateBranchRoot);return a(i)?d(i.message):f("Edited issue comment",{id:e.commentId,issueId:s.payload.issue,body:l})};import{ulid as qs}from"ulid";var Un=async e=>{let t=await T(e.repoRoot);if(a(t))return t;if(!Ft(e.email))return d(`Not an email address: ${e.email}`);let s=ye(e.email),o=e.contributorId??t.value.actor.userId;if(!t.value.state.contributors[o])return d(`Unknown contributor: ${o}`);let n=tt(t.value.state.emailLinks,s);if(n.includes(o))return f(`${s} is already yours`,{contributor:o,email:s,contested:n.filter(r=>r!==o)});let l=S([{id:qs(),action:"link.contributor.email",payload:{contributor:o,email:s},userId:t.value.actor.userId}],t.value.boot.stateBranchRoot);return a(l)?d(l.message):f(n.length>0?`Claimed ${s}, but somebody else claims it too, so it now resolves to neither of you`:`Claimed ${s}`,{contributor:o,email:s,contested:n})},Hn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let s=ye(e.email),o=e.contributorId??t.value.actor.userId,n=t.value.state.emailLinks[_t(s,o)];if(!n||n.tombstoned)return d(`No such link: ${s} to ${o}`);if(!Gt(t.value.actor.userId,n))return d("Only whoever made a claim, or the contributor it names, may undo it");let l=S([{id:qs(),action:"unlink.contributor.email",payload:{contributor:o,email:s},userId:t.value.actor.userId}],t.value.boot.stateBranchRoot);return a(l)?d(l.message):f(`Unclaimed ${s}`,{contributor:o,email:s})},zn=async(e={})=>{let t=await O(e.repoRoot);if(a(t))return t;let s=B();if(a(s))return s;let{emailLinks:o,contributors:n}=s.value,l=new Map;for(let c of Object.values(o)){if(c.tombstoned)continue;let I=l.get(c.email)??new Set;I.add(c.contributor),l.set(c.email,I)}let r=[...l.entries()].map(([c,I])=>({email:c,contested:I.size>1,claimants:[...I].map(v=>D(v,n[v]?.name))})).sort((c,I)=>c.email.localeCompare(I.email)),i=G(),u=a(i)?[]:$t(o,i.value.userId),g=xt().gitEmail,m=g?tt(o,g).filter(c=>a(i)||c!==i.value.userId):[];return f("Listed contributor emails",{emails:r,mine:u,git:g?{email:g,linkedToMe:u.includes(g),heldByOthers:m.map(c=>D(c,n[c]?.name))}:null})},Kn=async(e={})=>{let t=await T(e.repoRoot);if(a(t))return t;let{userId:s,userName:o}=t.value.actor,n=ae(t.value.boot.repoRoot),l=await We({repoRoot:t.value.boot.repoRoot,stateBranch:a(n)?void 0:n.value,names:[o,await pe(t.value.boot.repoRoot)],links:t.value.state.emailLinks});if(a(l))return l;let r=Rs(l.value),i=r.filter(u=>u.looksLikeYours);return f(r.length===0?"No unclaimed addresses in this history":`${r.length} unclaimed address(es) in this history, ${i.length>0?`${i.length} of which look like yours`:"none obviously yours"}. Show them to the user and link only the ones they confirm; each is a permanent event that replicates to every clone.`,{contributor:s,candidates:r,likely:i.length})};var ht=e=>{let t=ns(e);return a(t)?d(t.message):f("Listed repos",{repos:t.value,claimedBytes:ds(e),limit:Lt,allowLocal:Bt()})},Xn=async(e={})=>{let t=Re(e.repoRoot);return a(t)?d(t.message):ht(t.value)},qn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let{repoRoot:s}=t.value.boot,o=await us({repoRoot:s,actorId:t.value.actor.userId,url:e.url,branches:e.branches,since:e.since,label:e.label,mode:e.previewOnly?"preview":e.confirm?"confirm":"auto"});if(a(o))return d(o.message);let n=ht(s);return a(n)?d(n.message):f(o.message,{...n.value,...o.value.kind==="preview"?{preview:o.value.preview}:{}})},Vn=async e=>{let t=await T(e.repoRoot);if(a(t))return t;let{repoRoot:s}=t.value.boot,o=rs({repoRoot:s,actorId:t.value.actor.userId,repo:e.repo});if(a(o))return d(o.message);let n=ht(s);return a(n)?d(n.message):f(o.message,n.value)},Yn=e=>(ls("repo"in e?e.repo:Nt(e.url.trim())),f("Cancelled",null)),Jn=async(e,t={},s=2e4)=>{if(a(e))return e;let o,n=await Promise.race([Vs(t),new Promise(l=>{o=setTimeout(()=>l(null),s)})]);return clearTimeout(o),n===null?f(`${e.message} \xB7 still fetching other repos; epiq_repo_list shows how they stand`,e.value):a(n)||n.value.length===0?e:f([e.message,as(n.value)].filter(Boolean).join(" \xB7 "),{...e.value,repos:n.value})},Vs=async(e={})=>{let t=Re(e.repoRoot);return a(t)?d(t.message):is({repoRoot:t.value,minIntervalMs:e.minIntervalMs})};var Ys=(e,t)=>{let s=0,o=0,n=null;for(let l of e){if(l.userId!==t)continue;l.action==="add.issue"&&s++,l.action==="add.issue.comment"&&o++;let r=Mt(l.id);if(a(r))continue;let i=r.value.getTime();(n===null||i<n)&&(n=i)}return{tickets:s,comments:o,joinedAt:n}};var Qn=async(e={})=>{let t=await T(e.repoRoot);if(a(t))return t;let{userId:s,userName:o}=t.value.actor,n=Ys(t.value.state.eventLog,s),l=ae(t.value.boot.repoRoot),r=await We({repoRoot:t.value.boot.repoRoot,stateBranch:a(l)?void 0:l.value,names:[o,await pe(t.value.boot.repoRoot)],links:t.value.state.emailLinks}),i=a(r)?[]:r.value.filter(u=>u.claimedBy.length===1&&u.claimedBy[0]===s);return f("Derived personal stats",{...n,scanned:!a(r),commits:i.reduce((u,g)=>u+g.commits,0),claimedEmails:i.length})};var Js=e=>{if(e.length===0)return null;let t=Math.floor(e.length/2);return e.length%2===0?(e[t-1]+e[t])/2:e[t]};var Zn=8,er=(e,t)=>{let s=new Date(e);return s.setHours(0,0,0,0),s.setDate(s.getDate()-(s.getDay()+6)%7),Array.from({length:t},(o,n)=>{let l=new Date(s);return l.setDate(s.getDate()-7*(t-1-n)),l.getTime()})},tr=e=>Js([...e].sort((t,s)=>t-s)),Qs=({boardId:e,lanes:t,formerLaneIds:s=[],tickets:o,now:n})=>{let l=new Map(t.map((E,x)=>[E.id,x])),r=new Set(s),i=E=>E!=null&&(l.has(E)||r.has(E)),g=o.map(E=>({ticket:E,visits:ft(E.log,E.createdAt)})).filter(({visits:E})=>E.some(x=>i(x.laneId))),m=E=>{let x=le(E);return x===null?null:Math.min(De(x,n),n)},c=E=>{let x=E.flatMap(K=>{let $=l.get(K.laneId);return $===void 0?[]:[$]});return x.some((K,$)=>$>0&&K<x[$-1])},I=g.flatMap(({ticket:E,visits:x})=>{let K=E.log.findLast(be=>be.action==="close.issue");if(!K||i(E.parentNodeId))return[];let $=m(K),Ro=x.at(-2)?.laneId;if($===null||!i(Ro))return[];let Ao=x.slice(0,-1).flatMap((be,To)=>i(be.laneId)?[{laneId:be.laneId,ms:x[To+1].enteredAt-be.enteredAt}]:[]);return[{closedAt:$,leadTime:$-E.createdAt,sentBack:c(x),stays:Ao}]}),v=er(n,Zn),h=v[0],p=I.filter(E=>E.closedAt>=h),b=v.map((E,x)=>{let K=v[x+1]??1/0;return{t:E,closed:p.filter($=>$.closedAt>=E&&$.closedAt<K).length}}),R=new Map;for(let{stays:E}of p)for(let{laneId:x,ms:K}of E)R.set(x,(R.get(x)??0)+K);let V=t.reduce((E,x)=>E+(R.get(x.id)??0),0),yo=t.flatMap(E=>{let x=R.get(E.id)??0;return x<=0?[]:[{laneId:E.id,title:E.title,meanMs:x/p.length,share:x/V}]});return{boardId:e,throughput:b,filed:g.filter(({ticket:E,visits:x})=>E.createdAt>=h&&i(x[0]?.laneId)).length,closed:p.length,medianLeadTimeMs:tr(p.map(E=>E.leadTime)),sentBackShare:p.length===0?null:p.filter(E=>E.sentBack).length/p.length,laneTime:yo}};var sr=e=>{let t=B();if(a(t))return t;let s=Object.values(t.value.nodes),o=s.find(r=>r.id===e.boardId);if(!o||o.isDeleted||!W(o))return d("Board not found");let n=s.filter(r=>Q(r)&&r.parentNodeId===o.id),l=n.filter(r=>!r.isDeleted).sort((r,i)=>r.rank.localeCompare(i.rank));return f("Derived board overview",Qs({boardId:o.id,lanes:l,formerLaneIds:n.filter(r=>r.isDeleted).map(r=>r.id),tickets:s.filter(r=>!r.isDeleted).filter(_).map(r=>({id:r.id,parentNodeId:r.parentNodeId,log:r.log??[],createdAt:M(r.id)})),now:Date.now()}))};var q=e=>({path:e.path,sha:e.shas[e.shas.length-1]??""});var or=e=>{let t=e.lastIndexOf("/");return t===-1?".":e.slice(0,t)},Zs=({commits:e,patch:t})=>{let s=e.map(r=>r.time),n=t.files.map(r=>({...q(r),changed:r.addedCount+r.removed})).reduce((r,i)=>r===null||i.changed>r.changed?i:r,null),l=t.insertions+t.deletions;return{commits:e.length,authors:[...new Set(e.map(r=>r.author))].sort(),firstCommitAt:s.length?Math.min(...s):null,lastCommitAt:s.length?Math.max(...s):null,files:t.files.length,filesAdded:t.files.filter(r=>r.status==="added").length,filesModified:t.files.filter(r=>r.status==="modified").length,filesDeleted:t.files.filter(r=>r.status==="deleted").length,binaryFiles:t.files.filter(r=>r.binary).length,directories:new Set(t.files.map(r=>or(r.path))).size,insertions:t.insertions,deletions:t.deletions,net:t.insertions-t.deletions,largestFile:n,concentration:n&&l>0?n.changed/l:0,selfChurn:t.selfChurn,truncated:t.truncated}};var k={line:["//"],block:[["/*","*/"]]},j={line:["#"],block:[]},bt={line:["--"],block:[]},ve={line:[],block:[["<!--","-->"]]},nr={line:[],block:[]},y=(e,t)=>({name:e,comment:t}),Je=y("TypeScript",k),Qe=y("JavaScript",k),eo={ts:Je,tsx:Je,mts:Je,cts:Je,js:Qe,jsx:Qe,mjs:Qe,cjs:Qe,py:y("Python",{line:["#"],block:[['"""','"""']]}),rb:y("Ruby",{line:["#"],block:[["=begin","=end"]]}),go:y("Go",k),rs:y("Rust",k),java:y("Java",k),kt:y("Kotlin",k),swift:y("Swift",k),c:y("C",k),h:y("C",k),cc:y("C++",k),cpp:y("C++",k),hpp:y("C++",k),cs:y("C#",k),php:y("PHP",k),scala:y("Scala",k),dart:y("Dart",k),lua:y("Lua",bt),hs:y("Haskell",bt),sql:y("SQL",bt),ex:y("Elixir",j),exs:y("Elixir",j),pl:y("Perl",j),r:y("R",j),jl:y("Julia",j),sh:y("Shell",j),bash:y("Shell",j),zsh:y("Shell",j),vue:y("Vue",ve),svelte:y("Svelte",ve),html:y("HTML",ve),xml:y("XML",ve),md:y("Markdown",ve),mdx:y("Markdown",ve),css:y("CSS",{line:[],block:[["/*","*/"]]}),scss:y("CSS",k),less:y("CSS",k),yml:y("YAML",j),yaml:y("YAML",j),toml:y("TOML",j),ini:y("INI",j),json:y("JSON",nr)},rr="Other",to=e=>{let t=e.slice(e.lastIndexOf("/")+1),s=t.lastIndexOf(".");return s<=0?"":t.slice(s+1).toLowerCase()},ie=e=>eo[to(e)]?.name??rr,Le=e=>eo[to(e)]?.comment??null,ir=[/\.(test|spec)\.[a-z0-9]+$/i,/(^|\/)test_[^/]+\.py$/,/_test\.[a-z0-9]+$/i,/(^|\/)conftest\.py$/,/Tests?\.(java|kt|cs|scala)$/],ar=/(^|\/)(tests?|__tests__|spec|specs|e2e|src\/test|features)\//i,he=e=>ar.test(e)||ir.some(t=>t.test(e)),lr=/(^|\/)(package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|Cargo\.lock|go\.sum|poetry\.lock|Gemfile\.lock|composer\.lock)$/,dr=/(^|\/)(node_modules|dist|build|out|target|vendor|coverage|\.next|__snapshots__)\//,ur=/(\.min\.(js|css)|\.map|\.snap|\.pb\.go|_pb2\.py)$/,z=e=>lr.test(e)||dr.test(e)||ur.test(e),so=e=>/(^|\/)(package\.json|go\.mod|Cargo\.toml|requirements[^/]*\.txt|pyproject\.toml|Gemfile|composer\.json|pom\.xml|build\.gradle(\.kts)?)$/.test(e),oo=e=>/(^|\/)\.github\/workflows\//.test(e)||/(^|\/)(Dockerfile|docker-compose[^/]*\.ya?ml|Makefile|Jenkinsfile|\.gitlab-ci\.yml)$/.test(e)||/\.tf$/.test(e),no=e=>/\.(md|mdx|rst|txt)$/i.test(e)||/(^|\/)docs?\//i.test(e),cr=/\b(it|test|describe|context|suite)\.skip\b|\bx(it|describe|test)\s*\(|@pytest\.mark\.skip|@unittest\.skip|\bt\.Skip\s*\(|@(Ignore|Disabled)\b/,mr=/\b(it|test|describe|context|suite)\.only\b|\bf(it|describe|test)\s*\(/,ro=e=>cr.test(e),io=e=>mr.test(e);var ao=/\b(TODO|FIXME|HACK|XXX)\b/,pr=/[;{}]\s*$|^\s*(const|let|var|function|def|class|if|for|while|return|import|export|await|print)\b.*[=(]/,yt=(e,t)=>{let s=e.trim();return s===""?"blank":t&&(t.line.some(o=>s.startsWith(o))||t.block.some(([o])=>s.startsWith(o))||t.block.some(([o])=>o==="/*")&&(s.startsWith("*")||s.startsWith("*/")))?"comment":"code"},fr=(e,t)=>{let s=e.trim();for(let o of[...t.line,...t.block.flat(),"*"])if(s.startsWith(o)){s=s.slice(o.length).trim();break}return s},lo=({patch:e,repoShareByLanguage:t})=>{let s=new Map,o=0,n=0,l=0,r=0,i=0,u=0;for(let m of e.files){if(m.binary||z(m.path))continue;let c=Le(m.path);if(!c||c.line.length===0&&c.block.length===0)continue;let I=ie(m.path),v=s.get(I)??{comment:0,code:0};for(let{text:h}of m.added){let p=yt(h,c);if(ao.test(h)&&r++,p==="blank"){l++;continue}if(p==="comment"){o++,v.comment++,c&&pr.test(fr(h,c))&&u++;continue}n++,v.code++}for(let{text:h}of m.removedLines)ao.test(h)&&i++;s.set(I,v)}let g=o+n;return{byLanguage:[...s.entries()].map(([m,c])=>({name:m,commentLines:c.comment,codeLines:c.code,share:c.comment+c.code===0?0:c.comment/(c.comment+c.code),repoShare:t?.get(m)??null})).sort((m,c)=>c.commentLines+c.codeLines-(m.commentLines+m.codeLines)),commentLines:o,codeLines:n,blankLines:l,share:g===0?0:o/g,todoLinesAdded:r,todoLinesRemoved:i,commentedOutCodeLines:u}};var gr=/\bconsole\.(log|debug|dir)\s*\(|\bdebugger\b|^\s*print\s*\(|\bfmt\.Print(ln|f)?\s*\(|\bSystem\.out\.print|\bdbg!\s*\(/,Ze=6,Rt=10,Ir=e=>{let t=0;for(let s of e){if(s.trim()===""||s.startsWith(" "))continue;let o=s.length-s.trimStart().length;o>0&&(t===0||o<t)&&(t=o)}return Math.min(Math.max(t,2),8)},vr=(e,t)=>{let s=e.length-e.trimStart().length;if(s===0)return 0;let o=e.slice(0,s).split(" ").length-1;return o>0?o:Math.floor(s/t)},hr=e=>{if(e.length<Ze*2)return 0;let t=new Map,s=new Array(e.length).fill(!1);for(let o=0;o+Ze<=e.length;o++){let n=e.slice(o,o+Ze);if(n.some(i=>i.text.length<3))continue;let l=n.map(i=>i.text).join(`
5
- `),r=t.get(l);if(r===void 0){t.set(l,{...n[0],at:o});continue}if(r.file!==n[0]?.file)for(let i=0;i<Ze;i++)s[r.at+i]=!0,s[o+i]=!0}return s.filter(Boolean).length},uo=({patch:e})=>{let t=[],s=[],o=[],n=!1,l=0,r=0,i=null,u=[];for(let[g,m]of e.files.entries()){if(z(m.path)&&t.push(q(m)),so(m.path)&&s.push(q(m)),oo(m.path)&&o.push(q(m)),no(m.path)&&(n=!0),m.binary||z(m.path))continue;let c=m.added.map(h=>h.text),I=Ir(c),v=m.status!=="deleted";for(let h of c){gr.test(h)&&l++;let p=vr(h,I);p>r&&(r=p,i=q(m)),v&&u.push({text:h.trim(),file:g})}u.push({text:" ",file:g})}return{generatedPaths:t.slice(0,Rt),dependencyManifests:s.slice(0,Rt),buildOrCiPaths:o.slice(0,Rt),docsTouched:n,debugPrintLinesAdded:l,maxIndentLevels:r,deepestFile:i,duplicatedLines:hr(u)}};var co=({patch:e,languagesBefore:t})=>{let s=new Map,o=0;for(let r of e.files){if(r.binary)continue;let i=r.addedCount+r.removed;if(z(r.path)){o+=i;continue}let u=ie(r.path),g=s.get(u)??{name:u,added:0,removed:0,addedInTests:0,share:0};g.added+=r.addedCount,g.removed+=r.removed,he(r.path)&&(g.addedInTests+=r.addedCount),s.set(u,g)}let n=[...s.values()].reduce((r,i)=>r+i.added+i.removed,0),l=[...s.values()].map(r=>({...r,share:n===0?0:(r.added+r.removed)/n})).sort((r,i)=>i.added+i.removed-(r.added+r.removed));return{languages:l,introduced:t===null?[]:l.filter(r=>!t.has(r.name)).map(r=>r.name),generatedLines:o}};var br=200,At=2e5,yr=5e4,Rr=25,mo=64*1024*1024,Tt="",Ar=/^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/,Tr=/^diff --git a\/(.+) b\/\1$/,po=(e,t)=>e==="/dev/null"?null:e.startsWith(t)?e.slice(2):e,fo=(e,t)=>e===null?"added":t===null?"deleted":"modified",Er=()=>({byPath:new Map,insertions:0,deletions:0,selfChurn:0,retainedLines:0}),wr=(e,t)=>{let s=e.byPath,o="",n=null,l=null,r=null,i=!1,u=0,g=(c,I)=>I==="modified"&&c==="added"?"added":I,m=(c,I)=>{let v=s.get(c);if(v)return v.entry.status=g(v.entry.status,I),v.entry.shas.includes(o)||v.entry.shas.push(o),v;let p={entry:{path:c,status:I,binary:!1,added:[],addedCount:0,removed:0,removedLines:[],shas:[o]},pendingByText:new Map};return s.set(c,p),p};for(let c of t.split(`
6
- `)){if(c.startsWith(Tt)){o=c.slice(Tt.length).trim(),n=null,l=null,r=null,i=!1;continue}if(c.startsWith("diff --git ")){n=null,r=null,i=!0,l=Tr.exec(c)?.[1]??null;continue}if(i&&c.startsWith("Binary files ")&&l){let[,v=""]=/^Binary files (.*) differ$/.exec(c)??[],[h="",p=""]=v.split(" and ");n=m(l,fo(h==="/dev/null"?null:h,p==="/dev/null"?null:p)),n.entry.binary=!0;continue}if(i&&c.startsWith("--- ")){r=po(c.slice(4),"a/");continue}if(i&&c.startsWith("+++ ")){let v=po(c.slice(4),"b/"),h=v??r??l;h&&(n=m(h,fo(r,v)));continue}let I=Ar.exec(c);if(I){u=Number(I[1]),i=!1;continue}if(n){if(c.startsWith("+")){let v=c.slice(1);e.insertions++,n.entry.addedCount++,e.retainedLines<At&&(n.entry.added.push({sha:o,line:u,text:v}),e.retainedLines++),n.pendingByText.size<yr&&n.pendingByText.set(v,(n.pendingByText.get(v)??0)+1),u++;continue}if(c.startsWith("-")){let v=c.slice(1);e.deletions++,n.entry.removed++,e.retainedLines<At&&(n.entry.removedLines.push({sha:o,line:0,text:v}),e.retainedLines++);let h=n.pendingByText.get(v)??0;h>0&&v.trim().length>2&&(e.selfChurn++,n.pendingByText.set(v,h-1))}}}},Sr=e=>({files:[...e.byPath.values()].map(t=>t.entry),insertions:e.insertions,deletions:e.deletions,selfChurn:e.selfChurn,retainedLines:e.retainedLines});var go=async({repoRoot:e,shas:t,cwdOf:s=()=>e})=>{if(t.length===0)return f("No commits to scan",{files:[],insertions:0,deletions:0,selfChurn:0,scannedCommits:0,truncated:!1});let o=t.slice(0,br).reverse(),n=Er(),l=0,r=0,i=!1,u=[];for(let m of o){let c=s(m),I=u[u.length-1];I&&I.cwd===c&&I.shas.length<Rr?I.shas.push(m):u.push({cwd:c,shas:[m]})}for(let{cwd:m,shas:c}of u){let I=await Pe({cwd:m,maxOutput:Math.max(1,mo-l),keepPartial:!0,args:["-c","core.quotePath=false","show","--unified=0","--no-renames","--no-color",`--format=${Tt}%H`,...c]});if(a(I)){if(m!==e)continue;return d(I.message)}if(wr(n,I.value.stdout),l+=I.value.stdout.length,r+=c.length,I.value.truncated||l>mo){i=!0;break}}let g=Sr(n);return f("Scanned ticket patch",{files:g.files,insertions:g.insertions,deletions:g.deletions,selfChurn:g.selfChurn,scannedCommits:r,truncated:i||r<t.length||g.retainedLines>=At})};var xr=40,Cr=/^\d{6} blob ([0-9a-f]{40})\t(.+)$/,Io=async({repoRoot:e,sha:t})=>{let s=await Oe({cwd:e,args:["-c","core.quotePath=false","ls-tree","-r",`${t}~1`]});if(s.exitCode!==0)return null;let o=new Set,n=new Map;for(let m of s.stdout.split(`
7
- `)){let c=Cr.exec(m);if(!c)continue;let[,I="",v=""]=c;if(z(v))continue;let h=ie(v);if(o.add(h),he(v)||!Le(v))continue;let p=n.get(h)??[];p.length<xr&&(p.push({blob:I,path:v}),n.set(h,p))}let l=[...n.values()].flat(),r=await wt(l.map(m=>m.blob),e);if(a(r))return{languages:o,commentShareByLanguage:new Map};let i=r.value,u=new Map;for(let{blob:m,path:c}of l){let I=i.get(m);if(I===void 0)continue;let v=Le(c),h=ie(c),p=u.get(h)??{comment:0,code:0};for(let b of I.split(`
8
- `)){let R=yt(b,v);R==="comment"&&p.comment++,R==="code"&&p.code++}u.set(h,p)}let g=new Map;for(let[m,c]of u){let I=c.comment+c.code;I>0&&g.set(m,c.comment/I)}return{languages:o,commentShareByLanguage:g}};var vo=({patch:e})=>{let t=0,s=0,o=[],n=[],l=0,r=0;for(let i of e.files)if(!(i.binary||z(i.path))&&he(i.path)){t+=i.addedCount,s+=i.removed,i.status==="added"&&o.push(q(i)),i.status==="deleted"&&n.push(q(i));for(let{text:u}of i.added)ro(u)&&l++,io(u)&&r++}return{testLinesAdded:t,testLinesRemoved:s,addedTestFiles:o,deletedTestFiles:n,skippedTestLinesAdded:l,focusedTestLinesAdded:r}};var Br=e=>e.reduce((t,s)=>t===null||s.time<t.time?s:t,null),ho=async({repoRoot:e,ref:t,commits:s})=>{let o=await ts(e);if(a(o))return d(o.message);let n=ss(o.value),l=new Map(s.map(c=>[c.sha,c.repo])),r=c=>n(l.get(c))??e,i=await go({repoRoot:e,shas:s.map(c=>c.sha),cwdOf:r});if(a(i))return d(i.message);let u=i.value,g=Br(s),m=g?await Io({repoRoot:r(g.sha),sha:g.sha}):null;return f("Derived issue stats",{ref:t,shape:Zs({commits:s,patch:u}),languages:co({patch:u,languagesBefore:m?.languages??null}),tests:vo({patch:u}),comments:lo({patch:u,repoShareByLanguage:m?.commentShareByLanguage??null}),flags:uo({patch:u})})};var bo=e=>{if(a(e))return e;let t=Ge(),s=a(t)?{}:t.value.emailLinks,o=a(t)?{}:t.value.contributors,n=Wt(s),l=e.value.map(r=>({...r,authorIdentity:ys({authorName:r.author,authorEmail:r.authorEmail,owners:n,registry:o})}));return f(e.message,l)};var Nr=32,Ne=new Map;var kr=(e,t)=>{if(Ne.set(e,t),Ne.size>Nr){let s=Ne.keys().next();s.done||Ne.delete(s.value)}return t},Jc=async(e={idOrRef:""})=>{let t=e.idOrRef.trim();if(!t)return d("idOrRef must not be empty");let s=t.length>7?w(t):t.toUpperCase(),o=Me(e.repoRoot??process.cwd());if(a(o))return d(o.message);let n=o.value,l=bo(await os({repoRoot:n,ref:s}));if(a(l))return d(l.message);let r=l.value.map(m=>({sha:m.sha,...m.repo?{repo:m.repo}:{},time:m.time,author:m.authorIdentity?.resolved?m.authorIdentity.name:m.author,subject:m.subject})),i=[n,s,r.map(m=>`${m.sha}:${m.author}`).join(",")].join(" "),u=Ne.get(i);if(u)return f("Derived issue stats",u);let g=await ho({repoRoot:n,ref:s,commits:r});return a(g)?d(g.message):f("Derived issue stats",kr(i,g.value))};export{ft as a,Ms as b,U as c,ri as d,jo as e,ii as f,ai as g,$s as h,pe as i,B as j,Xo as k,qo as l,Qo as m,Zo as n,en as o,on as p,rn as q,gt as r,ln as s,dn as t,un as u,cn as v,mn as w,fn as x,gn as y,vn as z,hn as A,bn as B,yn as C,Rn as D,An as E,Tn as F,En as G,wn as H,Sn as I,xn as J,Cn as K,Bn as L,Ln as M,Nn as N,kn as O,Pn as P,On as Q,Mn as R,Fn as S,_n as T,$n as U,Wn as V,Gn as W,jn as X,Un as Y,Hn as Z,zn as _,Kn as $,Qn as aa,Xn as ba,qn as ca,Vn as da,Yn as ea,Jn as fa,Vs as ga,Js as ha,sr as ia,bo as ja,Jc as ka};