github-issue-tower-defence-management 2.36.0 → 2.36.2

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.
@@ -10,7 +10,7 @@ Error generating stack: `+e.message+`
10
10
 
11
11
  `);i=c.pop()??``;for(let e of c){if(!e.startsWith(`data: `))continue;let n=lr(e.slice(6));if(n!==null){if(n.type===`progress`)r({fetched:typeof n.fetched==`number`?n.fetched:0,total:typeof n.total==`number`?n.total:0});else if(n.type===`done`){let e=sr(n.snapshot);if(e===null){t(`error`),s([`Failed to parse snapshot`]);return}if(e.failures.length>0){s(e.failures),t(`error`);return}await Wn(e),Un(!0),a(e),t(`on`),s([])}}}}}).catch(e=>{e instanceof Error&&e.name===`AbortError`||(t(`error`),s([e instanceof Error?e.message:String(e)]))})},[]),turnOff:(0,y.useCallback)(()=>{c.current!==null&&(c.current.abort(),c.current=null),t(`off`),a(null),r(null),s([]),Un(!1),Kn().catch(()=>{})},[])}},dr=e=>typeof e==`object`&&!!e&&!Array.isArray(e),fr=e=>typeof e==`string`?e:``,pr=e=>typeof e==`number`?e:0,mr=e=>e===!0,hr=`console-api-v1`,gr=async(e,t)=>{let n=`${e}?url=${encodeURIComponent(t)}`;try{let e=await fetch(n);if(!e.ok){let t=`HTTP ${e.status}`;try{let n=await e.json();dr(n)&&typeof n.error==`string`&&n.error.length>0&&(t=n.error)}catch(e){console.warn(`Failed to parse error body from non-ok response:`,e)}throw Error(t)}let t=await e.json();try{`caches`in globalThis&&globalThis.caches.open(hr).then(e=>e.put(n,new Response(JSON.stringify(t),{headers:{"Content-Type":`application/json`}}))).catch(e=>{console.warn(`Failed to persist API response to cache:`,e)})}catch(e){console.warn(`Failed to access cache storage:`,e)}return t}catch(e){try{if(`caches`in globalThis){let e=await(await globalThis.caches.open(hr)).match(n);if(e!==void 0)return e.json()}}catch{}throw e}},_r=e=>!dr(e)||!Array.isArray(e.comments)?[]:e.comments.filter(dr).map(e=>({author:fr(e.author),body:fr(e.body),createdAt:fr(e.createdAt)})),vr=e=>!dr(e)||!Array.isArray(e.files)?[]:e.files.filter(dr).map(e=>({path:fr(e.path)||fr(e.filename),additions:pr(e.additions),deletions:pr(e.deletions),status:fr(e.status),patch:typeof e.patch==`string`?e.patch:null,rawUrl:typeof e.rawUrl==`string`?e.rawUrl:null})),yr=e=>!dr(e)||!Array.isArray(e.commits)?[]:e.commits.filter(dr).map(e=>({sha:fr(e.sha),message:fr(e.message),author:fr(e.author),authoredAt:fr(e.authoredAt)})),br=e=>dr(e)?{title:fr(e.title),body:fr(e.body),additions:pr(e.additions),deletions:pr(e.deletions),changedFiles:pr(e.changedFiles)}:null,xr=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],Sr=e=>e===`MERGEABLE`?`MERGEABLE`:e===`CONFLICTING`?`CONFLICTING`:`UNKNOWN`,Cr=e=>!dr(e)||!Array.isArray(e.relatedPullRequests)?[]:e.relatedPullRequests.filter(dr).map(e=>({url:fr(e.url),branchName:typeof e.branchName==`string`?e.branchName:null,createdAt:fr(e.createdAt),isDraft:mr(e.isDraft),isConflicted:mr(e.isConflicted),mergeableStatus:Sr(e.mergeableStatus),isPassedAllCiJob:mr(e.isPassedAllCiJob),isCiStateSuccess:mr(e.isCiStateSuccess),isResolvedAllReviewComments:mr(e.isResolvedAllReviewComments),isBranchOutOfDate:mr(e.isBranchOutOfDate),missingRequiredCheckNames:xr(e.missingRequiredCheckNames),summary:br(e.summary)})),wr=e=>{if(!dr(e)||!dr(e.status))return{found:!1,isConflicted:!1,mergeableStatus:`UNKNOWN`,isPassedAllCiJob:!1,isCiStateSuccess:!1,isBranchOutOfDate:!1,missingRequiredCheckNames:[]};let t=e.status;return{found:!0,isConflicted:mr(t.isConflicted),mergeableStatus:Sr(t.mergeableStatus),isPassedAllCiJob:mr(t.isPassedAllCiJob),isCiStateSuccess:mr(t.isCiStateSuccess),isBranchOutOfDate:mr(t.isBranchOutOfDate),missingRequiredCheckNames:xr(t.missingRequiredCheckNames)}},Tr=e=>dr(e)?{state:fr(e.state)||`open`,merged:mr(e.merged),isPullRequest:mr(e.isPullRequest),title:fr(e.title)}:{state:`open`,merged:!1,isPullRequest:!1,title:``},Er=()=>({fetchItemBody:async e=>{let t=await gr(`/api/itembody`,e);return dr(t)?fr(t.body):``},fetchComments:async e=>_r(await gr(`/api/comments`,e)),fetchPrFiles:async e=>vr(await gr(`/api/prfiles`,e)),fetchPrCommits:async e=>yr(await gr(`/api/prcommits`,e)),fetchRelatedPrs:async e=>Cr(await gr(`/api/relatedprs`,e)),fetchIssueState:async e=>Tr(await gr(`/api/issuetitle`,e)),fetchPullRequestStatus:async e=>wr(await gr(`/api/pullrequeststatus`,e))}),Dr=async e=>{let t=await e.text().catch(()=>``);if(t.length===0)return`HTTP ${e.status}`;try{let e=JSON.parse(t);if(dr(e)&&typeof e.error==`string`)return e.error}catch{return t}return t},Or=async(e,t)=>{let n=await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok)throw Error(await Dr(n))},kr=`/api/comment`,Ar=e=>{if(!dr(e)||!dr(e.comment))throw Error(`comment was not returned`);return{author:fr(e.comment.author),body:fr(e.comment.body),createdAt:fr(e.comment.createdAt)}},jr=async e=>{let t=await fetch(kr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(`HTTP ${t.status}`);return Ar(await t.json())},Mr=`/api/upload`,Nr=e=>{let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)},Pr=async e=>{let t=await fetch(Mr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t));let n=await t.json();if(!dr(n)||typeof n.markdown!=`string`)throw Error(`markdown was not returned`);return n.markdown},Fr=`/api/addstory`,Ir=async e=>{let t=await fetch(Fr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},Lr=`/api/reviewcomment`,Rr=async e=>{let t=await fetch(Lr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},zr=`/api/createissue`,Br=`/api/storycolor`,Vr=async e=>{let t=await fetch(Br,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},Hr=async e=>{let t=await fetch(zr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t));let n=await t.json();if(!(e=>typeof e==`object`&&!!e&&!Array.isArray(e))(n)||typeof n.issueUrl!=`string`)throw Error(`issueUrl was not returned`);return n.issueUrl},Ur=`/api/reorderstory`,Wr=async e=>{let t=await fetch(Ur,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},Gr=`/api/deleteallcomments`,Kr=async e=>{let t=await fetch(Gr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},qr=`/api/deletestory`,Jr=async e=>{let t=await fetch(qr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},Yr=`/api/renamestory`,Xr=async e=>{let t=await fetch(Yr,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},Zr=async()=>{let e=await fetch(`/api/projects`);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();if(typeof t!=`object`||!t||Array.isArray(t))return{pjcodes:[],workflowImprovementIssueUrl:null};let n=t;return{pjcodes:Array.isArray(n.pjcodes)?n.pjcodes.filter(e=>typeof e==`string`):[],workflowImprovementIssueUrl:typeof n.workflowImprovementIssueUrl==`string`?n.workflowImprovementIssueUrl:null}},Qr=`/api/projectreadmeconfig`,$r=async e=>{let t=`${Qr}?pjcode=${encodeURIComponent(e)}`,n=await fetch(t);if(!n.ok)throw Error(await Dr(n));let r=await n.json();return{maximumPreparingIssuesCount:dr(r)&&typeof r.maximumPreparingIssuesCount==`number`?r.maximumPreparingIssuesCount:null}},ei=`/api/setdependedissueurl`,ti=async e=>{let t=await fetch(ei,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},ni=`/api/projectsettings`,ri=async e=>{let t=await fetch(ni,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Dr(t))},ii=`totally wrong`,ai=`This pull request is unnecessary.`,oi=e=>`The pull request for this issue was unnecessary and has been closed: ${e}\n\nDo not create it again.`,si=e=>e.map(e=>`${e.path}:${e.line} ${e.body}`).join(`
12
12
 
13
- `),ci=`In Tmux by human`,li=[`In Tmux by agent`,`In Tmux by human`,`Todo by human`,`Todo by agent`,`Awaiting Workspace`],ui=e=>e===`todo-by-human`||e===`todo-by-agent`,di=5e3,fi=e=>`${e.isPr?`PR #`:`#`}${e.number}`,pi=(e,t)=>{switch(e.type){case`review`:return e.action===`approve_and_merge`?`Approved & Merged`:e.action===`request_changes`?`Rejected`:e.action===`totally_wrong`?`Marked totally wrong`:`Marked unnecessary`;case`next_action_date`:return e.action===`snooze_1hour`?`Next Action Hour +1 hour`:e.action===`snooze_3hours`?`Next Action Hour +3 hours`:e.action===`snooze_1day`?`Next Action Date +1 day`:ui(t)?`Next Action Date +1 week and skip`:`Next Action Date +1 week`;case`set_story`:return`Story → ${e.optionName}`;case`set_status`:return`Status → ${e.optionName}`;case`set_in_tmux_by_human`:return`Added to In Tmux by human`;case`ok_and_awaiting_workspace`:return`ok → Awaiting Workspace`;case`close`:return e.action===`close`?`Closed`:`Closed as not planned`;case`delete_all_comments`:return`Deleted all comments`}},mi=e=>{switch(e.type){case`review`:return e.action===`approve_and_merge`?`green`:e.action===`request_changes`?`amber`:e.action===`totally_wrong`?`red`:`gray`;case`next_action_date`:return`amber`;case`set_story`:case`set_status`:case`set_in_tmux_by_human`:case`ok_and_awaiting_workspace`:return`blue`;case`close`:return`red`;case`delete_all_comments`:return`red`}},hi=(e,t)=>e.type===`next_action_date`?ui(t):e.type!==`delete_all_comments`,gi=(e,t,n)=>`${pi(e,n)} — ${fi(t)}`,_i=`console-offline-action-queue`,vi=e=>{if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&typeof t.message==`string`&&typeof t.color==`string`&&typeof t.enqueuedAt==`number`&&typeof t.itemUrl==`string`&&typeof t.projectItemId==`string`&&typeof t.itemNumber==`number`&&typeof t.repo==`string`&&typeof t.isPr==`boolean`&&typeof t.apiPath==`string`&&typeof t.requestBody==`object`&&t.requestBody!==null},yi=()=>{try{let e=localStorage.getItem(_i);if(e===null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(vi):[]}catch{return[]}},bi=e=>{localStorage.setItem(_i,JSON.stringify(e))},xi=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`,Si=e=>e instanceof TypeError,Ci=e=>e instanceof Error&&e.message.length>0?e.message:String(e),wi=100,Ti=e=>Math.max(0,Math.ceil((di-e)/1e3)),Ei=e=>Math.max(0,1-e/di),Di=()=>{let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(yi),o=(0,y.useRef)(i);o.current=i;let s=(0,y.useRef)(null),c=(0,y.useRef)(0),l=(0,y.useRef)(null),u=(0,y.useRef)(!1),d=(0,y.useCallback)(()=>{l.current!==null&&(clearInterval(l.current),l.current=null)},[]),f=(0,y.useCallback)(e=>{if(e.offline===void 0)return;let t={id:xi(),message:e.message,color:e.color,enqueuedAt:Date.now(),...e.offline};a(e=>{let n=[...e,t];return bi(n),n})},[]),p=(0,y.useCallback)(e=>{e.commit().catch(t=>{Si(t)&&e.offline!==void 0?f(e):r({message:e.message,reason:Ci(t)})})},[f]),m=(0,y.useCallback)(()=>{let e=s.current;d(),s.current=null,t(null),e!==null&&!u.current&&(u.current=!0,p(e))},[d,p]),h=(0,y.useCallback)(()=>{d(),s.current=null,u.current=!0,t(null)},[d]),g=(0,y.useCallback)(()=>{r(null)},[]),_=(0,y.useCallback)((e,t)=>{r({message:e,reason:t})},[]),v=(0,y.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return bi(n),n})},[]),b=(0,y.useCallback)(async e=>{let t=o.current.find(t=>t.id===e);if(t!==void 0)try{await Or(t.apiPath,t.requestBody),v(e)}catch(n){Si(n)?r({message:t.message,reason:`Still offline — action is still held in the queue`}):(r({message:t.message,reason:Ci(n)}),v(e))}},[v]),x=(0,y.useCallback)(e=>{if(s.current!==null&&!u.current){let e=s.current;d(),u.current=!0,p(e)}u.current=!1,s.current=e,c.current=Date.now(),t({message:e.message,color:e.color,remainingSeconds:Ti(0),progress:Ei(0)}),e.advance(),l.current=setInterval(()=>{let n=Date.now()-c.current;if(n>=5e3){m();return}t({message:e.message,color:e.color,remainingSeconds:Ti(n),progress:Ei(n)})},wi)},[d,m,p]);return(0,y.useEffect)(()=>d,[d]),{pending:e,error:n,offlineActions:i,enqueue:x,showError:_,undo:h,dismissError:g,confirmOfflineAction:b,discardOfflineAction:v}},Oi=class{fetcher;cache=new Map;inFlight=new Map;prefetchInFlight=new Set;constructor(e){this.fetcher=e}peek=e=>this.cache.get(e);has=e=>this.cache.has(e);load=(e,t)=>{let n=this.cache.get(e);if(n!==void 0)return Promise.resolve(n);let r=this.inFlight.get(e);if(r!==void 0)return r;let i=this.fetcher(t).then(t=>(this.cache.set(e,t),t)).finally(()=>{this.inFlight.delete(e)});return this.inFlight.set(e,i),i};prefetch=(e,t)=>{this.cache.has(e)||this.inFlight.has(e)||this.prefetchInFlight.has(e)||(this.prefetchInFlight.add(e),this.fetcher(t).then(t=>{this.cache.set(e,t)}).catch(()=>{}).finally(()=>{this.prefetchInFlight.delete(e)}))};seed(e,t){this.cache.set(e,t)}invalidate=e=>{this.cache.delete(e)}},ki=e=>{try{let t=new URL(e).pathname.split(`/`).filter(Boolean);if(t.length>=4)return`${t[0]}/${t[1]}#${t[3]}`}catch{}return e},Ai=(e,t)=>{for(let[n,r]of Object.entries(t.items)){let t=ki(n);e.body.seed(t,r.body),e.comments.seed(t,r.comments),e.state.seed(t,r.state),r.files!==null&&e.files.seed(t,r.files),r.commits!==null&&e.commits.seed(t,r.commits),r.prStatus!==null&&e.prStatus.seed(t,r.prStatus),r.relatedPrs!==null&&e.relatedPrs.seed(t,r.relatedPrs)}},ji=(e=null)=>(0,y.useMemo)(()=>{let t=Er(),n={client:t,body:new Oi(t.fetchItemBody),comments:new Oi(t.fetchComments),files:new Oi(t.fetchPrFiles),commits:new Oi(t.fetchPrCommits),relatedPrs:new Oi(t.fetchRelatedPrs),state:new Oi(t.fetchIssueState),prStatus:new Oi(t.fetchPullRequestStatus)};return e!==null&&Ai(n,e),n},[e]),H=0,Mi=500,Ni=2e3,Pi=e=>{let t=window;if(typeof t.requestIdleCallback==`function`&&typeof t.cancelIdleCallback==`function`){let n=t.requestIdleCallback(e,{timeout:Ni});return{cancel:()=>t.cancelIdleCallback?.(n)}}let n=window.setTimeout(e,0);return{cancel:()=>window.clearTimeout(n)}},Fi=(e,t)=>{let n=`${t.repo}#${t.number}`;e.body.prefetch(n,t.url),e.state.prefetch(n,t.url),e.comments.prefetch(n,t.url),t.isPr?(e.files.prefetch(n,t.url),e.commits.prefetch(n,t.url),e.prStatus.prefetch(n,t.url)):e.relatedPrs.prefetch(n,t.url)},Ii=(e,t,n)=>{(0,y.useEffect)(()=>{if(t===null)return;let r=n.findIndex(e=>e.projectItemId===t.projectItemId);if(r===-1)return;let i=n.slice(r+1,r+1+H);if(i.length===0)return;let a=null,o=window.setTimeout(()=>{a=Pi(()=>{for(let t of i)Fi(e,t)})},Mi);return()=>{window.clearTimeout(o),a?.cancel()}},[e,t,n])},Li=`/api/features`,Ri=()=>{let[e,t]=(0,y.useState)({airplaneMode:!1});return(0,y.useEffect)(()=>{fetch(Li).then(async e=>{if(!e.ok)return;let n=await e.json();typeof n==`object`&&n&&!Array.isArray(n)&&`airplaneMode`in n&&typeof n.airplaneMode==`boolean`&&t({airplaneMode:n.airplaneMode})}).catch(e=>{console.warn(`Failed to fetch /api/features`,e)})},[]),e},zi=(e,t)=>{let n=D.findIndex(t=>t.name===e);if(n===-1)return null;for(let e=n+1;e<D.length;e+=1){let n=D[e].name;if((t[n]??0)>0)return n}return null},Bi=e=>{for(let t of D)if((e[t.name]??0)>0)return t.name;return D[0].name},Vi=new Set(D.map(e=>e.name)),Hi=e=>{let t=e.split(`/`).filter(e=>e.length>0);if(t.length<3||t[0]!==`projects`)return null;let n=t[2];return Vi.has(n)?n:null},Ui=e=>{if(!e.startsWith(`#item/`))return null;let t=e.slice(6);return t.length===0?null:decodeURIComponent(t)},Wi=(e,t)=>{let n=(0,y.useCallback)(()=>{let e=Bi(t);return typeof window>`u`?{activeTab:e,selectedItemKey:null}:{activeTab:Hi(window.location.pathname)??e,selectedItemKey:Ui(window.location.hash)}},[t]),[r,i]=(0,y.useState)(n);(0,y.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>{i(n())};return window.addEventListener(`popstate`,e),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`popstate`,e),window.removeEventListener(`hashchange`,e)}},[n]),(0,y.useEffect)(()=>{if(typeof window>`u`||Hi(window.location.pathname)!==null)return;let e=Bi(t);i(t=>t.activeTab===e?t:{...t,activeTab:e})},[t]);let a=(0,y.useCallback)(t=>e===null?`#${t}`:`/projects/${e}/${t}`,[e]),o=(0,y.useCallback)(e=>{if(typeof window>`u`){i({activeTab:e,selectedItemKey:null});return}window.history.pushState({},``,a(e)),i({activeTab:e,selectedItemKey:null})},[a]),s=(0,y.useCallback)(e=>{typeof window<`u`&&(window.location.hash=`#item/${encodeURIComponent(e)}`),i(t=>({...t,selectedItemKey:e}))},[]),c=(0,y.useCallback)(()=>{if(typeof window<`u`&&window.location.hash!==``){let e=`${window.location.pathname}${window.location.search}`;window.history.pushState({},``,e)}i(e=>({...e,selectedItemKey:null}))},[]);return{activeTab:r.activeTab,selectedItemKey:r.selectedItemKey,tabHref:a,selectTab:o,openItem:s,closeItem:c}},Gi=e=>`pv_overlay_${e}`,Ki=e=>e.projectItemId===``?e.itemId:e.projectItemId,qi=(e,t)=>e!==void 0&&e.done===!0&&e.mode===t,Ji=(e,t,n)=>e.filter(e=>!qi(t[Ki(e)],n)).length,Yi=(e,t,n)=>e.filter(e=>!qi(t[Ki(e)],n)),Xi=(e,t)=>{let n=Date.parse(t);if(Number.isNaN(n))return{};let r={};for(let[t,i]of Object.entries(e))i.ts>=n&&(r[t]=i);return r},Zi=(e,t,n)=>{if(n===null)return null;let r=Date.parse(n);if(Number.isNaN(r))return null;let i=e[Ki(t)];return i===void 0||i.ts<r?null:i.status??null},Qi=(e,t,n,r,i)=>{let a={...e[t]??{},...n,ts:i,mode:r};return{...e,[t]:a}},$i=`/api/review`,ea=`/api/triage`,ta=`/api/intmux`,na=(e,t,n,r,i)=>{if(r===`approve_and_merge`)return{pjcode:e,action:`approve_and_merge`,prUrl:n,projectItemId:t.projectItemId};if(r===`request_changes`){let r=i[0];return{pjcode:e,action:`request_changes`,prUrl:n,projectItemId:t.projectItemId,commentBody:si(i),...r===void 0?{}:{changedFilePath:r.path,line:r.line,side:r.side}}}return r===`totally_wrong`?{pjcode:e,action:`close`,prUrl:n,issueUrl:t.url,projectItemId:t.projectItemId,commentBody:ii}:{pjcode:e,action:`unnecessary`,prUrl:n,projectItemId:t.projectItemId,issueUrl:t.url,commentBody:ai,issueCommentBody:oi(n)}},ra=(e,t,n,r)=>({pjcode:e,action:n,issueUrl:t.url,projectItemId:t.projectItemId,...r??{}}),ia=(e,t)=>({pjcode:e,action:`set_intmux`,issueUrl:t.url,projectItemId:t.projectItemId}),aa=()=>Error(`No project specified in the URL path.`),oa=(e,t,n,r)=>{let{patchOverlay:i}=n,a=(0,y.useCallback)(e=>{if(r===void 0)return;let t=`${e.repo}#${e.number}`;r.body.invalidate(t),r.comments.invalidate(t)},[r]),o=(0,y.useCallback)(e=>{i(Ki(e),{done:!0},t)},[i,t]);return{reviewPullRequest:(0,y.useCallback)(async(t,n,r,i=[])=>{if(e===null)throw aa();o(t),await Or($i,na(e,t,n,r,i)),a(t)},[e,o,a]),setNextActionDate:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();let r={pjcode:e,action:n,issueUrl:t.url,projectItemId:t.projectItemId};o(t),await Or(ea,r),a(t)},[e,o,a]),setStory:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();let o={pjcode:e,action:`set_story`,issueUrl:n.url,projectItemId:n.projectItemId,storyOptionId:r.id};i(Ki(n),{done:!0,story:{name:r.name,color:r.color}},t),await Or(ea,o),a(n)},[e,a,i,t]),setStatus:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();let o={pjcode:e,action:`set_status`,issueUrl:n.url,projectItemId:n.projectItemId,statusName:r.name};i(Ki(n),{done:!0,status:{name:r.name,color:r.color}},t),await Or(ea,o),a(n)},[e,a,i,t]),setInTmuxByHuman:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();let o={pjcode:e,action:`set_intmux`,issueUrl:n.url,projectItemId:n.projectItemId};i(Ki(n),{done:!0,status:{name:r.name,color:r.color}},t),await Or(ta,o),a(n)},[e,a,i,t]),closeIssue:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();let r={pjcode:e,action:n,issueUrl:t.url,projectItemId:t.projectItemId};o(t),await Or(ea,r),a(t)},[e,o,a]),okAndMoveToAwaitingWorkspace:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();i(Ki(n),{done:!0,status:{name:r.name,color:r.color}},t),await jr({pjcode:e,url:n.url,body:`ok`}),await Or(ea,{pjcode:e,action:`set_status`,issueUrl:n.url,projectItemId:n.projectItemId,statusName:r.name}),a(n)},[e,a,i,t]),addComment:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();let r=await jr({pjcode:e,url:t.url,body:n});return a(t),r},[e,a]),uploadAttachment:(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`no project in the URL path`);let r=Nr(new Uint8Array(await n.arrayBuffer()));return Pr({pjcode:e,url:t.url,fileName:n.name,contentBase64:r})},[e]),addInlineReviewComment:(0,y.useCallback)(async(t,n,r,i,a)=>{if(e===null)throw aa();await Rr({pjcode:e,url:t,path:n,line:r,side:i,body:a})},[e]),deleteAllComments:(0,y.useCallback)(async e=>{await Kr({issueUrl:e.url}),a(e)},[a]),setDependedIssueUrl:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();await ti({pjcode:e,issueUrl:t.url,dependedIssueUrl:n})},[e])}},sa=e=>typeof e==`object`&&!!e&&typeof e.ts==`number`,ca=e=>{if(typeof localStorage>`u`)return{};let t=localStorage.getItem(Gi(e));if(t===null)return{};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{};let r={};for(let[e,t]of Object.entries(n))sa(t)&&(r[e]=t);return r},la=(e,t)=>{typeof localStorage<`u`&&localStorage.setItem(Gi(e),JSON.stringify(t))},ua=e=>{let[t,n]=(0,y.useState)(()=>ca(e));return{overlay:t,patchOverlay:(0,y.useCallback)((t,r,i)=>{n(n=>{let a=Qi(n,t,r,i,Date.now());return la(e,a),a})},[e])}},da=e=>{let t=e.split(`/`).filter(e=>e.length>0);if(t.length<2||t[0]!==`projects`)return null;let n=t[1];return n.length===0?null:n},fa=()=>da(typeof window>`u`?``:window.location.pathname),pa=()=>{let[e,t]=(0,y.useState)([]),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(null);return(0,y.useEffect)(()=>{let e=!1;return a(!0),s(null),Zr().then(n=>{e||(t(n.pjcodes),r(n.workflowImprovementIssueUrl),a(!1))}).catch(t=>{e||(s(t instanceof Error?t:Error(String(t))),a(!1))}),()=>{e=!0}},[]),{pjcodes:e,workflowImprovementIssueUrl:n,isLoading:i,error:o}},ma=e=>{let[t,n]=(0,y.useState)(!1),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(``),d=(0,y.useCallback)(async()=>{if(e!==null){n(!0),i(!0),c(null);try{let t=await $r(e);u(t.maximumPreparingIssuesCount===null?``:String(t.maximumPreparingIssuesCount))}catch(e){c(e instanceof Error?e.message:`Failed to load settings`)}finally{i(!1)}}},[e]),f=(0,y.useCallback)(()=>{n(!1),c(null)},[]),p=(0,y.useCallback)(e=>{u(e)},[]),m=(0,y.useCallback)(async t=>{if(e!==null){o(!0),c(null);try{await ri({pjcode:e,maximumPreparingIssuesCount:t}),n(!1)}catch(e){c(e instanceof Error?e.message:`Failed to save settings`)}finally{o(!1)}}},[e]);return(0,y.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&f()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t,f]),{isOpen:t,isLoading:r,isSaving:a,error:s,inputValue:l,open:d,close:f,changeInput:p,save:m}},ha=e=>{let t=(0,y.useRef)(e),n=(0,y.useRef)(Date.now());return t.current!==e&&(t.current=e,n.current=Date.now()),{isTimerExpired:(0,y.useCallback)(e=>e<=0?!1:Date.now()-n.current>=e*60*1e3,[])}},ga=(e,t)=>{let n=Math.abs(e);return n<60||n<=Math.abs(t)*1.5?null:e<0?`next`:`previous`},_a=(e,t)=>{let n=Math.abs(e),r=Math.abs(t);return r>n*1.5&&r>20},va=e=>{let t=e instanceof Element?e:null;for(;t!==null&&t!==document.body;){let e=window.getComputedStyle(t).overflowX;if((e===`auto`||e===`scroll`)&&t.scrollWidth>t.clientWidth)return!0;t=t.parentElement}return!1},ya=e=>{let t=(0,y.useRef)(e);t.current=e;let n=(0,y.useRef)(null),r=(0,y.useCallback)(e=>{let n=0,r=0,i=!1,a=e=>{if(e.touches.length!==1){i=!1;return}if(va(e.target)){i=!1;return}let t=e.touches[0];n=t.clientX,r=t.clientY,i=!0},o=e=>{if(!i)return;let t=e.touches[0];_a(t.clientX-n,t.clientY-r)&&(i=!1)},s=e=>{if(!i||(i=!1,e.changedTouches.length!==1))return;let a=e.changedTouches[0],o=ga(a.clientX-n,a.clientY-r);o!==null&&t.current(o)};return e.addEventListener(`touchstart`,a,{passive:!0}),e.addEventListener(`touchmove`,o,{passive:!0}),e.addEventListener(`touchend`,s,{passive:!0}),()=>{e.removeEventListener(`touchstart`,a),e.removeEventListener(`touchmove`,o),e.removeEventListener(`touchend`,s)}},[]),i=(0,y.useCallback)(e=>{n.current!==null&&(n.current(),n.current=null),e!==null&&(n.current=r(e))},[r]);return(0,y.useEffect)(()=>()=>{n.current!==null&&(n.current(),n.current=null)},[]),i},ba=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xa=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],Sa=e=>!ba(e)||!Array.isArray(e.items)?[]:e.items.filter(ba).map(e=>({...e,relatedOpenPullRequestUrls:xa(e.relatedOpenPullRequestUrls)})),Ca=e=>Array.isArray(e)?e.filter(ba):[],wa=e=>Array.isArray(e)?e.filter(ba):[],Ta=e=>({items:Sa(e),generatedAt:ba(e)&&typeof e.generatedAt==`string`?e.generatedAt:``,statusOptions:ba(e)?Ca(e.statusOptions):[],agentOptions:ba(e)?Ca(e.agentOptions):[],storyOptions:ba(e)?Ca(e.storyOptions):[],storyColors:ba(e)&&ba(e.storyColors)?e.storyColors:{},stories:ba(e)?wa(e.stories):[],defaultNameWithOwner:ba(e)&&typeof e.defaultNameWithOwner==`string`?e.defaultNameWithOwner:null,storyOrder:ba(e)?xa(e.storyOrder):[],timerEndsAt:ba(e)&&typeof e.timerEndsAt==`string`?e.timerEndsAt:null,timerTotalSeconds:ba(e)&&typeof e.timerTotalSeconds==`number`&&e.timerTotalSeconds>0?e.timerTotalSeconds:null}),Ea=()=>{let e={};for(let t of D)e[t.name]=null;return e},Da=(e,t)=>`/projects/${e}/${t}/list.json`,Oa=6e4,ka=`console-list-v1`,Aa=(e,t)=>{try{if(!(`caches`in globalThis))return;globalThis.caches.open(ka).then(n=>n.put(e,new Response(JSON.stringify(t),{headers:{"Content-Type":`application/json`}}))).catch(e=>{console.warn(`Failed to persist tab snapshot to cache:`,e)})}catch(e){console.warn(`Failed to access cache storage:`,e)}},ja=async e=>{if(!(`caches`in globalThis))return null;try{let t=await(await globalThis.caches.open(ka)).match(e);return t===void 0?null:{...Ta(await t.json()),fromCache:!0}}catch{return null}},Ma=async(e,t)=>{let n=Da(e,t);try{let e=await fetch(n);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();return Aa(n,t),{snapshot:{...Ta(t),fromCache:!1},error:null}}catch(e){let t=await ja(n);return t===null?{snapshot:null,error:e instanceof Error?e:Error(String(e))}:{snapshot:t,error:null}}},Na=async e=>{let t=await Promise.all(D.map(async t=>{let{snapshot:n,error:r}=await Ma(e,t.name);return{tabName:t.name,snapshot:n,error:r}})),n=Ea(),r=null;for(let{tabName:e,snapshot:i,error:a}of t)n[e]=i,a!==null&&r===null&&(r=a);return{snapshots:n,firstError:Object.values(n).every(e=>e===null)?r:null}},Pa=(e,t=null)=>{let[n,r]=(0,y.useState)(Ea),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(null);return(0,y.useEffect)(()=>{if(t!==null&&e!==null){let n=t.tabs[e];if(n!==void 0){let e=Ea();for(let t of D){let r=n[t.name];r!==void 0&&(e[t.name]={...r})}r(e),a(!1),s(null);return}}let n=!1;if(a(!0),s(null),e===null)return r(Ea()),a(!1),s(`No project specified in the URL path.`),()=>{n=!0};let i=()=>{Na(e).then(({snapshots:e,firstError:t})=>{n||(r(e),s(t===null?null:t.message),a(!1))}).catch(e=>{n||(s(e instanceof Error?e.message:String(e)),a(!1))})};i();let o=setInterval(i,Oa);return()=>{n=!0,clearInterval(o)}},[e,t]),{snapshots:n,isLoading:i,error:o}},Fa=`tdpm-timer-settings`,Ia=()=>({timerMode:!1,projectMinutes:{}}),La=()=>{if(typeof localStorage>`u`)return Ia();let e=localStorage.getItem(Fa);if(e===null)return Ia();try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return Ia();let n=t,r=typeof n.timerMode==`boolean`&&n.timerMode,i=n.projectMinutes;return{timerMode:r,projectMinutes:typeof i==`object`&&i&&!Array.isArray(i)?Object.fromEntries(Object.entries(i).filter(([,e])=>typeof e==`number`).map(([e,t])=>[e,t])):{}}}catch{return Ia()}},Ra=e=>{typeof localStorage<`u`&&localStorage.setItem(Fa,JSON.stringify(e))},za=(e,t,n)=>{if(e.length===0)return null;let r=t===null?-1:e.indexOf(t),i=r===-1?0:(r+1)%e.length,a=r===-1?e.length:e.length-1;for(let t=0;t<a;t++){let r=e[(i+t)%e.length];if((n[r]??0)>0)return r}return null},Ba=()=>{let[e,t]=(0,y.useState)(La),[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(e),o=(0,y.useCallback)(()=>{t(e=>(a(e),e)),r(!0)},[]),s=(0,y.useCallback)(()=>{r(!1)},[]),c=(0,y.useCallback)(()=>{a(e=>(Ra(e),t(e),e)),r(!1)},[]),l=(0,y.useCallback)(e=>{a(t=>({...t,timerMode:e}))},[]),u=(0,y.useCallback)((e,t)=>{a(n=>({...n,projectMinutes:{...n.projectMinutes,[e]:t}}))},[]);return{timerMode:e.timerMode,projectMinutes:e.projectMinutes,isOpen:n,draftTimerMode:i.timerMode,draftProjectMinutes:i.projectMinutes,openSettings:o,closeSettings:s,saveSettings:c,toggleDraftTimerMode:l,changeDraftMinutes:u}},Va=e=>{window.location.replace(e)},Ha=e=>{window.location.assign(e)},Ua=(e,t)=>{let n=e.indexOf(t);if(n<0)return e.length>0?e[0]:null;let r=n+1;return r<e.length?e[r]:null},Wa=(e,t)=>{let n=e.indexOf(t);return n<0||n>=e.length-1?null:e[n+1]},Ga=(e,t)=>{let n=e.indexOf(t);return n<=0?null:e[n-1]},Ka=(e,t)=>e.length===0?`${t}\n`:e.endsWith(`
13
+ `),ci=`In Tmux by human`,li=[`In Tmux by human`,`Todo by human`,`Awaiting Workspace`],ui=e=>e===`todo-by-human`||e===`todo-by-agent`,di=5e3,fi=e=>`${e.isPr?`PR #`:`#`}${e.number}`,pi=(e,t)=>{switch(e.type){case`review`:return e.action===`approve_and_merge`?`Approved & Merged`:e.action===`request_changes`?`Rejected`:e.action===`totally_wrong`?`Marked totally wrong`:`Marked unnecessary`;case`next_action_date`:return e.action===`snooze_1hour`?`Next Action Hour +1 hour`:e.action===`snooze_3hours`?`Next Action Hour +3 hours`:e.action===`snooze_1day`?`Next Action Date +1 day`:ui(t)?`Next Action Date +1 week and skip`:`Next Action Date +1 week`;case`set_story`:return`Story → ${e.optionName}`;case`set_status`:return`Status → ${e.optionName}`;case`set_in_tmux_by_human`:return`Added to In Tmux by human`;case`ok_and_awaiting_workspace`:return`ok → Awaiting Workspace`;case`close`:return e.action===`close`?`Closed`:`Closed as not planned`;case`delete_all_comments`:return`Deleted all comments`}},mi=e=>{switch(e.type){case`review`:return e.action===`approve_and_merge`?`green`:e.action===`request_changes`?`amber`:e.action===`totally_wrong`?`red`:`gray`;case`next_action_date`:return`amber`;case`set_story`:case`set_status`:case`set_in_tmux_by_human`:case`ok_and_awaiting_workspace`:return`blue`;case`close`:return`red`;case`delete_all_comments`:return`red`}},hi=(e,t)=>e.type===`next_action_date`?ui(t):e.type!==`delete_all_comments`,gi=(e,t,n)=>`${pi(e,n)} — ${fi(t)}`,_i=`console-offline-action-queue`,vi=e=>{if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&typeof t.message==`string`&&typeof t.color==`string`&&typeof t.enqueuedAt==`number`&&typeof t.itemUrl==`string`&&typeof t.projectItemId==`string`&&typeof t.itemNumber==`number`&&typeof t.repo==`string`&&typeof t.isPr==`boolean`&&typeof t.apiPath==`string`&&typeof t.requestBody==`object`&&t.requestBody!==null},yi=()=>{try{let e=localStorage.getItem(_i);if(e===null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(vi):[]}catch{return[]}},bi=e=>{localStorage.setItem(_i,JSON.stringify(e))},xi=()=>typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`,Si=e=>e instanceof TypeError,Ci=e=>e instanceof Error&&e.message.length>0?e.message:String(e),wi=100,Ti=e=>Math.max(0,Math.ceil((di-e)/1e3)),Ei=e=>Math.max(0,1-e/di),Di=()=>{let[e,t]=(0,y.useState)(null),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(yi),o=(0,y.useRef)(i);o.current=i;let s=(0,y.useRef)(null),c=(0,y.useRef)(0),l=(0,y.useRef)(null),u=(0,y.useRef)(!1),d=(0,y.useCallback)(()=>{l.current!==null&&(clearInterval(l.current),l.current=null)},[]),f=(0,y.useCallback)(e=>{if(e.offline===void 0)return;let t={id:xi(),message:e.message,color:e.color,enqueuedAt:Date.now(),...e.offline};a(e=>{let n=[...e,t];return bi(n),n})},[]),p=(0,y.useCallback)(e=>{e.commit().catch(t=>{Si(t)&&e.offline!==void 0?f(e):r({message:e.message,reason:Ci(t)})})},[f]),m=(0,y.useCallback)(()=>{let e=s.current;d(),s.current=null,t(null),e!==null&&!u.current&&(u.current=!0,p(e))},[d,p]),h=(0,y.useCallback)(()=>{d(),s.current=null,u.current=!0,t(null)},[d]),g=(0,y.useCallback)(()=>{r(null)},[]),_=(0,y.useCallback)((e,t)=>{r({message:e,reason:t})},[]),v=(0,y.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e);return bi(n),n})},[]),b=(0,y.useCallback)(async e=>{let t=o.current.find(t=>t.id===e);if(t!==void 0)try{await Or(t.apiPath,t.requestBody),v(e)}catch(n){Si(n)?r({message:t.message,reason:`Still offline — action is still held in the queue`}):(r({message:t.message,reason:Ci(n)}),v(e))}},[v]),x=(0,y.useCallback)(e=>{if(s.current!==null&&!u.current){let e=s.current;d(),u.current=!0,p(e)}u.current=!1,s.current=e,c.current=Date.now(),t({message:e.message,color:e.color,remainingSeconds:Ti(0),progress:Ei(0)}),e.advance(),l.current=setInterval(()=>{let n=Date.now()-c.current;if(n>=5e3){m();return}t({message:e.message,color:e.color,remainingSeconds:Ti(n),progress:Ei(n)})},wi)},[d,m,p]);return(0,y.useEffect)(()=>d,[d]),{pending:e,error:n,offlineActions:i,enqueue:x,showError:_,undo:h,dismissError:g,confirmOfflineAction:b,discardOfflineAction:v}},Oi=class{fetcher;cache=new Map;inFlight=new Map;prefetchInFlight=new Set;constructor(e){this.fetcher=e}peek=e=>this.cache.get(e);has=e=>this.cache.has(e);load=(e,t)=>{let n=this.cache.get(e);if(n!==void 0)return Promise.resolve(n);let r=this.inFlight.get(e);if(r!==void 0)return r;let i=this.fetcher(t).then(t=>(this.cache.set(e,t),t)).finally(()=>{this.inFlight.delete(e)});return this.inFlight.set(e,i),i};prefetch=(e,t)=>{this.cache.has(e)||this.inFlight.has(e)||this.prefetchInFlight.has(e)||(this.prefetchInFlight.add(e),this.fetcher(t).then(t=>{this.cache.set(e,t)}).catch(()=>{}).finally(()=>{this.prefetchInFlight.delete(e)}))};seed(e,t){this.cache.set(e,t)}invalidate=e=>{this.cache.delete(e)}},ki=e=>{try{let t=new URL(e).pathname.split(`/`).filter(Boolean);if(t.length>=4)return`${t[0]}/${t[1]}#${t[3]}`}catch{}return e},Ai=(e,t)=>{for(let[n,r]of Object.entries(t.items)){let t=ki(n);e.body.seed(t,r.body),e.comments.seed(t,r.comments),e.state.seed(t,r.state),r.files!==null&&e.files.seed(t,r.files),r.commits!==null&&e.commits.seed(t,r.commits),r.prStatus!==null&&e.prStatus.seed(t,r.prStatus),r.relatedPrs!==null&&e.relatedPrs.seed(t,r.relatedPrs)}},ji=(e=null)=>(0,y.useMemo)(()=>{let t=Er(),n={client:t,body:new Oi(t.fetchItemBody),comments:new Oi(t.fetchComments),files:new Oi(t.fetchPrFiles),commits:new Oi(t.fetchPrCommits),relatedPrs:new Oi(t.fetchRelatedPrs),state:new Oi(t.fetchIssueState),prStatus:new Oi(t.fetchPullRequestStatus)};return e!==null&&Ai(n,e),n},[e]),H=0,Mi=500,Ni=2e3,Pi=e=>{let t=window;if(typeof t.requestIdleCallback==`function`&&typeof t.cancelIdleCallback==`function`){let n=t.requestIdleCallback(e,{timeout:Ni});return{cancel:()=>t.cancelIdleCallback?.(n)}}let n=window.setTimeout(e,0);return{cancel:()=>window.clearTimeout(n)}},Fi=(e,t)=>{let n=`${t.repo}#${t.number}`;e.body.prefetch(n,t.url),e.state.prefetch(n,t.url),e.comments.prefetch(n,t.url),t.isPr?(e.files.prefetch(n,t.url),e.commits.prefetch(n,t.url),e.prStatus.prefetch(n,t.url)):e.relatedPrs.prefetch(n,t.url)},Ii=(e,t,n)=>{(0,y.useEffect)(()=>{if(t===null)return;let r=n.findIndex(e=>e.projectItemId===t.projectItemId);if(r===-1)return;let i=n.slice(r+1,r+1+H);if(i.length===0)return;let a=null,o=window.setTimeout(()=>{a=Pi(()=>{for(let t of i)Fi(e,t)})},Mi);return()=>{window.clearTimeout(o),a?.cancel()}},[e,t,n])},Li=`/api/features`,Ri=()=>{let[e,t]=(0,y.useState)({airplaneMode:!1});return(0,y.useEffect)(()=>{fetch(Li).then(async e=>{if(!e.ok)return;let n=await e.json();typeof n==`object`&&n&&!Array.isArray(n)&&`airplaneMode`in n&&typeof n.airplaneMode==`boolean`&&t({airplaneMode:n.airplaneMode})}).catch(e=>{console.warn(`Failed to fetch /api/features`,e)})},[]),e},zi=(e,t)=>{let n=D.findIndex(t=>t.name===e);if(n===-1)return null;for(let e=n+1;e<D.length;e+=1){let n=D[e].name;if((t[n]??0)>0)return n}return null},Bi=e=>{for(let t of D)if((e[t.name]??0)>0)return t.name;return D[0].name},Vi=new Set(D.map(e=>e.name)),Hi=e=>{let t=e.split(`/`).filter(e=>e.length>0);if(t.length<3||t[0]!==`projects`)return null;let n=t[2];return Vi.has(n)?n:null},Ui=e=>{if(!e.startsWith(`#item/`))return null;let t=e.slice(6);return t.length===0?null:decodeURIComponent(t)},Wi=(e,t)=>{let n=(0,y.useCallback)(()=>{let e=Bi(t);return typeof window>`u`?{activeTab:e,selectedItemKey:null}:{activeTab:Hi(window.location.pathname)??e,selectedItemKey:Ui(window.location.hash)}},[t]),[r,i]=(0,y.useState)(n);(0,y.useEffect)(()=>{if(typeof window>`u`)return;let e=()=>{i(n())};return window.addEventListener(`popstate`,e),window.addEventListener(`hashchange`,e),()=>{window.removeEventListener(`popstate`,e),window.removeEventListener(`hashchange`,e)}},[n]),(0,y.useEffect)(()=>{if(typeof window>`u`||Hi(window.location.pathname)!==null)return;let e=Bi(t);i(t=>t.activeTab===e?t:{...t,activeTab:e})},[t]);let a=(0,y.useCallback)(t=>e===null?`#${t}`:`/projects/${e}/${t}`,[e]),o=(0,y.useCallback)(e=>{if(typeof window>`u`){i({activeTab:e,selectedItemKey:null});return}window.history.pushState({},``,a(e)),i({activeTab:e,selectedItemKey:null})},[a]),s=(0,y.useCallback)(e=>{typeof window<`u`&&(window.location.hash=`#item/${encodeURIComponent(e)}`),i(t=>({...t,selectedItemKey:e}))},[]),c=(0,y.useCallback)(()=>{if(typeof window<`u`&&window.location.hash!==``){let e=`${window.location.pathname}${window.location.search}`;window.history.pushState({},``,e)}i(e=>({...e,selectedItemKey:null}))},[]);return{activeTab:r.activeTab,selectedItemKey:r.selectedItemKey,tabHref:a,selectTab:o,openItem:s,closeItem:c}},Gi=e=>`pv_overlay_${e}`,Ki=e=>e.projectItemId===``?e.itemId:e.projectItemId,qi=(e,t)=>e!==void 0&&e.done===!0&&e.mode===t,Ji=(e,t,n)=>e.filter(e=>!qi(t[Ki(e)],n)).length,Yi=(e,t,n)=>e.filter(e=>!qi(t[Ki(e)],n)),Xi=(e,t)=>{let n=Date.parse(t);if(Number.isNaN(n))return{};let r={};for(let[t,i]of Object.entries(e))i.ts>=n&&(r[t]=i);return r},Zi=(e,t,n)=>{if(n===null)return null;let r=Date.parse(n);if(Number.isNaN(r))return null;let i=e[Ki(t)];return i===void 0||i.ts<r?null:i.status??null},Qi=(e,t,n,r,i)=>{let a={...e[t]??{},...n,ts:i,mode:r};return{...e,[t]:a}},$i=`/api/review`,ea=`/api/triage`,ta=`/api/intmux`,na=(e,t,n,r,i)=>{if(r===`approve_and_merge`)return{pjcode:e,action:`approve_and_merge`,prUrl:n,projectItemId:t.projectItemId};if(r===`request_changes`){let r=i[0];return{pjcode:e,action:`request_changes`,prUrl:n,projectItemId:t.projectItemId,commentBody:si(i),...r===void 0?{}:{changedFilePath:r.path,line:r.line,side:r.side}}}return r===`totally_wrong`?{pjcode:e,action:`close`,prUrl:n,issueUrl:t.url,projectItemId:t.projectItemId,commentBody:ii}:{pjcode:e,action:`unnecessary`,prUrl:n,projectItemId:t.projectItemId,issueUrl:t.url,commentBody:ai,issueCommentBody:oi(n)}},ra=(e,t,n,r)=>({pjcode:e,action:n,issueUrl:t.url,projectItemId:t.projectItemId,...r??{}}),ia=(e,t)=>({pjcode:e,action:`set_intmux`,issueUrl:t.url,projectItemId:t.projectItemId}),aa=()=>Error(`No project specified in the URL path.`),oa=(e,t,n,r)=>{let{patchOverlay:i}=n,a=(0,y.useCallback)(e=>{if(r===void 0)return;let t=`${e.repo}#${e.number}`;r.body.invalidate(t),r.comments.invalidate(t)},[r]),o=(0,y.useCallback)(e=>{i(Ki(e),{done:!0},t)},[i,t]);return{reviewPullRequest:(0,y.useCallback)(async(t,n,r,i=[])=>{if(e===null)throw aa();o(t),await Or($i,na(e,t,n,r,i)),a(t)},[e,o,a]),setNextActionDate:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();let r={pjcode:e,action:n,issueUrl:t.url,projectItemId:t.projectItemId};o(t),await Or(ea,r),a(t)},[e,o,a]),setStory:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();let o={pjcode:e,action:`set_story`,issueUrl:n.url,projectItemId:n.projectItemId,storyOptionId:r.id};i(Ki(n),{done:!0,story:{name:r.name,color:r.color}},t),await Or(ea,o),a(n)},[e,a,i,t]),setStatus:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();let o={pjcode:e,action:`set_status`,issueUrl:n.url,projectItemId:n.projectItemId,statusName:r.name};i(Ki(n),{done:!0,status:{name:r.name,color:r.color}},t),await Or(ea,o),a(n)},[e,a,i,t]),setInTmuxByHuman:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();let o={pjcode:e,action:`set_intmux`,issueUrl:n.url,projectItemId:n.projectItemId};i(Ki(n),{done:!0,status:{name:r.name,color:r.color}},t),await Or(ta,o),a(n)},[e,a,i,t]),closeIssue:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();let r={pjcode:e,action:n,issueUrl:t.url,projectItemId:t.projectItemId};o(t),await Or(ea,r),a(t)},[e,o,a]),okAndMoveToAwaitingWorkspace:(0,y.useCallback)(async(n,r)=>{if(e===null)throw aa();i(Ki(n),{done:!0,status:{name:r.name,color:r.color}},t),await jr({pjcode:e,url:n.url,body:`ok`}),await Or(ea,{pjcode:e,action:`set_status`,issueUrl:n.url,projectItemId:n.projectItemId,statusName:r.name}),a(n)},[e,a,i,t]),addComment:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();let r=await jr({pjcode:e,url:t.url,body:n});return a(t),r},[e,a]),uploadAttachment:(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`no project in the URL path`);let r=Nr(new Uint8Array(await n.arrayBuffer()));return Pr({pjcode:e,url:t.url,fileName:n.name,contentBase64:r})},[e]),addInlineReviewComment:(0,y.useCallback)(async(t,n,r,i,a)=>{if(e===null)throw aa();await Rr({pjcode:e,url:t,path:n,line:r,side:i,body:a})},[e]),deleteAllComments:(0,y.useCallback)(async e=>{await Kr({issueUrl:e.url}),a(e)},[a]),setDependedIssueUrl:(0,y.useCallback)(async(t,n)=>{if(e===null)throw aa();await ti({pjcode:e,issueUrl:t.url,dependedIssueUrl:n})},[e])}},sa=e=>typeof e==`object`&&!!e&&typeof e.ts==`number`,ca=e=>{if(typeof localStorage>`u`)return{};let t=localStorage.getItem(Gi(e));if(t===null)return{};let n=JSON.parse(t);if(typeof n!=`object`||!n)return{};let r={};for(let[e,t]of Object.entries(n))sa(t)&&(r[e]=t);return r},la=(e,t)=>{typeof localStorage<`u`&&localStorage.setItem(Gi(e),JSON.stringify(t))},ua=e=>{let[t,n]=(0,y.useState)(()=>ca(e));return{overlay:t,patchOverlay:(0,y.useCallback)((t,r,i)=>{n(n=>{let a=Qi(n,t,r,i,Date.now());return la(e,a),a})},[e])}},da=e=>{let t=e.split(`/`).filter(e=>e.length>0);if(t.length<2||t[0]!==`projects`)return null;let n=t[1];return n.length===0?null:n},fa=()=>da(typeof window>`u`?``:window.location.pathname),pa=()=>{let[e,t]=(0,y.useState)([]),[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(null);return(0,y.useEffect)(()=>{let e=!1;return a(!0),s(null),Zr().then(n=>{e||(t(n.pjcodes),r(n.workflowImprovementIssueUrl),a(!1))}).catch(t=>{e||(s(t instanceof Error?t:Error(String(t))),a(!1))}),()=>{e=!0}},[]),{pjcodes:e,workflowImprovementIssueUrl:n,isLoading:i,error:o}},ma=e=>{let[t,n]=(0,y.useState)(!1),[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(``),d=(0,y.useCallback)(async()=>{if(e!==null){n(!0),i(!0),c(null);try{let t=await $r(e);u(t.maximumPreparingIssuesCount===null?``:String(t.maximumPreparingIssuesCount))}catch(e){c(e instanceof Error?e.message:`Failed to load settings`)}finally{i(!1)}}},[e]),f=(0,y.useCallback)(()=>{n(!1),c(null)},[]),p=(0,y.useCallback)(e=>{u(e)},[]),m=(0,y.useCallback)(async t=>{if(e!==null){o(!0),c(null);try{await ri({pjcode:e,maximumPreparingIssuesCount:t}),n(!1)}catch(e){c(e instanceof Error?e.message:`Failed to save settings`)}finally{o(!1)}}},[e]);return(0,y.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&f()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[t,f]),{isOpen:t,isLoading:r,isSaving:a,error:s,inputValue:l,open:d,close:f,changeInput:p,save:m}},ha=e=>{let t=(0,y.useRef)(e),n=(0,y.useRef)(Date.now());return t.current!==e&&(t.current=e,n.current=Date.now()),{isTimerExpired:(0,y.useCallback)(e=>e<=0?!1:Date.now()-n.current>=e*60*1e3,[])}},ga=(e,t)=>{let n=Math.abs(e);return n<60||n<=Math.abs(t)*1.5?null:e<0?`next`:`previous`},_a=(e,t)=>{let n=Math.abs(e),r=Math.abs(t);return r>n*1.5&&r>20},va=e=>{let t=e instanceof Element?e:null;for(;t!==null&&t!==document.body;){let e=window.getComputedStyle(t).overflowX;if((e===`auto`||e===`scroll`)&&t.scrollWidth>t.clientWidth)return!0;t=t.parentElement}return!1},ya=e=>{let t=(0,y.useRef)(e);t.current=e;let n=(0,y.useRef)(null),r=(0,y.useCallback)(e=>{let n=0,r=0,i=!1,a=e=>{if(e.touches.length!==1){i=!1;return}if(va(e.target)){i=!1;return}let t=e.touches[0];n=t.clientX,r=t.clientY,i=!0},o=e=>{if(!i)return;let t=e.touches[0];_a(t.clientX-n,t.clientY-r)&&(i=!1)},s=e=>{if(!i||(i=!1,e.changedTouches.length!==1))return;let a=e.changedTouches[0],o=ga(a.clientX-n,a.clientY-r);o!==null&&t.current(o)};return e.addEventListener(`touchstart`,a,{passive:!0}),e.addEventListener(`touchmove`,o,{passive:!0}),e.addEventListener(`touchend`,s,{passive:!0}),()=>{e.removeEventListener(`touchstart`,a),e.removeEventListener(`touchmove`,o),e.removeEventListener(`touchend`,s)}},[]),i=(0,y.useCallback)(e=>{n.current!==null&&(n.current(),n.current=null),e!==null&&(n.current=r(e))},[r]);return(0,y.useEffect)(()=>()=>{n.current!==null&&(n.current(),n.current=null)},[]),i},ba=e=>typeof e==`object`&&!!e&&!Array.isArray(e),xa=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],Sa=e=>!ba(e)||!Array.isArray(e.items)?[]:e.items.filter(ba).map(e=>({...e,relatedOpenPullRequestUrls:xa(e.relatedOpenPullRequestUrls)})),Ca=e=>Array.isArray(e)?e.filter(ba):[],wa=e=>Array.isArray(e)?e.filter(ba):[],Ta=e=>({items:Sa(e),generatedAt:ba(e)&&typeof e.generatedAt==`string`?e.generatedAt:``,statusOptions:ba(e)?Ca(e.statusOptions):[],agentOptions:ba(e)?Ca(e.agentOptions):[],storyOptions:ba(e)?Ca(e.storyOptions):[],storyColors:ba(e)&&ba(e.storyColors)?e.storyColors:{},stories:ba(e)?wa(e.stories):[],defaultNameWithOwner:ba(e)&&typeof e.defaultNameWithOwner==`string`?e.defaultNameWithOwner:null,storyOrder:ba(e)?xa(e.storyOrder):[],timerEndsAt:ba(e)&&typeof e.timerEndsAt==`string`?e.timerEndsAt:null,timerTotalSeconds:ba(e)&&typeof e.timerTotalSeconds==`number`&&e.timerTotalSeconds>0?e.timerTotalSeconds:null}),Ea=()=>{let e={};for(let t of D)e[t.name]=null;return e},Da=(e,t)=>`/projects/${e}/${t}/list.json`,Oa=6e4,ka=`console-list-v1`,Aa=(e,t)=>{try{if(!(`caches`in globalThis))return;globalThis.caches.open(ka).then(n=>n.put(e,new Response(JSON.stringify(t),{headers:{"Content-Type":`application/json`}}))).catch(e=>{console.warn(`Failed to persist tab snapshot to cache:`,e)})}catch(e){console.warn(`Failed to access cache storage:`,e)}},ja=async e=>{if(!(`caches`in globalThis))return null;try{let t=await(await globalThis.caches.open(ka)).match(e);return t===void 0?null:{...Ta(await t.json()),fromCache:!0}}catch{return null}},Ma=async(e,t)=>{let n=Da(e,t);try{let e=await fetch(n);if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();return Aa(n,t),{snapshot:{...Ta(t),fromCache:!1},error:null}}catch(e){let t=await ja(n);return t===null?{snapshot:null,error:e instanceof Error?e:Error(String(e))}:{snapshot:t,error:null}}},Na=async e=>{let t=await Promise.all(D.map(async t=>{let{snapshot:n,error:r}=await Ma(e,t.name);return{tabName:t.name,snapshot:n,error:r}})),n=Ea(),r=null;for(let{tabName:e,snapshot:i,error:a}of t)n[e]=i,a!==null&&r===null&&(r=a);return{snapshots:n,firstError:Object.values(n).every(e=>e===null)?r:null}},Pa=(e,t=null)=>{let[n,r]=(0,y.useState)(Ea),[i,a]=(0,y.useState)(!0),[o,s]=(0,y.useState)(null);return(0,y.useEffect)(()=>{if(t!==null&&e!==null){let n=t.tabs[e];if(n!==void 0){let e=Ea();for(let t of D){let r=n[t.name];r!==void 0&&(e[t.name]={...r})}r(e),a(!1),s(null);return}}let n=!1;if(a(!0),s(null),e===null)return r(Ea()),a(!1),s(`No project specified in the URL path.`),()=>{n=!0};let i=()=>{Na(e).then(({snapshots:e,firstError:t})=>{n||(r(e),s(t===null?null:t.message),a(!1))}).catch(e=>{n||(s(e instanceof Error?e.message:String(e)),a(!1))})};i();let o=setInterval(i,Oa);return()=>{n=!0,clearInterval(o)}},[e,t]),{snapshots:n,isLoading:i,error:o}},Fa=`tdpm-timer-settings`,Ia=()=>({timerMode:!1,projectMinutes:{}}),La=()=>{if(typeof localStorage>`u`)return Ia();let e=localStorage.getItem(Fa);if(e===null)return Ia();try{let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return Ia();let n=t,r=typeof n.timerMode==`boolean`&&n.timerMode,i=n.projectMinutes;return{timerMode:r,projectMinutes:typeof i==`object`&&i&&!Array.isArray(i)?Object.fromEntries(Object.entries(i).filter(([,e])=>typeof e==`number`).map(([e,t])=>[e,t])):{}}}catch{return Ia()}},Ra=e=>{typeof localStorage<`u`&&localStorage.setItem(Fa,JSON.stringify(e))},za=(e,t,n)=>{if(e.length===0)return null;let r=t===null?-1:e.indexOf(t),i=r===-1?0:(r+1)%e.length,a=r===-1?e.length:e.length-1;for(let t=0;t<a;t++){let r=e[(i+t)%e.length];if((n[r]??0)>0)return r}return null},Ba=()=>{let[e,t]=(0,y.useState)(La),[n,r]=(0,y.useState)(!1),[i,a]=(0,y.useState)(e),o=(0,y.useCallback)(()=>{t(e=>(a(e),e)),r(!0)},[]),s=(0,y.useCallback)(()=>{r(!1)},[]),c=(0,y.useCallback)(()=>{a(e=>(Ra(e),t(e),e)),r(!1)},[]),l=(0,y.useCallback)(e=>{a(t=>({...t,timerMode:e}))},[]),u=(0,y.useCallback)((e,t)=>{a(n=>({...n,projectMinutes:{...n.projectMinutes,[e]:t}}))},[]);return{timerMode:e.timerMode,projectMinutes:e.projectMinutes,isOpen:n,draftTimerMode:i.timerMode,draftProjectMinutes:i.projectMinutes,openSettings:o,closeSettings:s,saveSettings:c,toggleDraftTimerMode:l,changeDraftMinutes:u}},Va=e=>{window.location.replace(e)},Ha=e=>{window.location.assign(e)},Ua=(e,t)=>{let n=e.indexOf(t);if(n<0)return e.length>0?e[0]:null;let r=n+1;return r<e.length?e[r]:null},Wa=(e,t)=>{let n=e.indexOf(t);return n<0||n>=e.length-1?null:e[n+1]},Ga=(e,t)=>{let n=e.indexOf(t);return n<=0?null:e[n-1]},Ka=(e,t)=>e.length===0?`${t}\n`:e.endsWith(`
14
14
  `)?`${e}${t}\n`:`${e}\n${t}\n`,qa=(e,t)=>{let n=`![uploading ${t}]()`;return`${e.length===0?``:e.replace(/\n*$/,`
15
15
  `)}\n\n\n${n}\n`},Ja=(e,t,n)=>{let r=`![uploading ${t}]()`,i=e.indexOf(r);return i===-1?Ka(e,n):e.slice(0,i)+n+e.slice(i+r.length)},Ya=(e,t)=>{let n=`![uploading ${t}]()`,r=e.indexOf(n);if(r===-1)return e;let i=r,a=0;for(;a<3&&i>0&&e[i-1]===`
16
16
  `;)i--,a++;let o=+(e[r+n.length]===`
@@ -85,4 +85,4 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
85
85
  `)}),o+=1,r=[])};for(let e of t){if(a){r.push(e),kl(e)&&(a=!1);continue}if(i===null&&Dl(e)){s(),i=[];continue}if(i!==null){if(kl(e)){n.push({kind:`mermaid`,key:`mermaid:${o}`,code:i.join(`
86
86
  `)}),o+=1,i=null;continue}i.push(e);continue}if(Ol(e)){r.push(e),a=!0;continue}r.push(e)}return i!==null&&r.push("```mermaid",...i),s(),n},jl=({code:e,label:t=`Copy code`})=>(0,x.jsx)(Cn,{value:e,idleText:t,idleAriaLabel:t,copiedAriaLabel:`Code copied to clipboard`,className:`console-copy-code-button`}),Ml=`https://cdn.jsdelivr.net/npm/mermaid@10.9.6/dist/mermaid.min.js`,Nl=null,Pl=0,Fl=e=>(e.initialize({startOnLoad:!1,securityLevel:`strict`,theme:`dark`,themeVariables:{background:`#0d1117`,primaryColor:`#161b22`,primaryTextColor:`#e6edf3`,primaryBorderColor:`#30363d`,lineColor:`#8b949e`,fontSize:`14px`}}),e),Il=()=>Nl===null?window.mermaid===void 0?(Nl=new Promise((e,t)=>{let n=document.createElement(`script`);n.src=Ml,n.async=!0,n.onload=()=>{if(window.mermaid===void 0){t(Error(`mermaid failed to load`));return}e(Fl(window.mermaid))},n.onerror=()=>t(Error(`mermaid script failed to load`)),document.head.appendChild(n)}),Nl):(Nl=Promise.resolve(Fl(window.mermaid)),Nl):Nl,J=async e=>{let t=await Il();Pl+=1;let n=`console-mermaid-${Pl}`,{svg:r}=await t.render(n,e);return ks.sanitize(r,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:[`foreignObject`]})},Ll=.5,Y=e=>Number.isNaN(e)||e<1?1:e>6?6:e,X=e=>Y(Y(e)+Ll),Z=e=>Y(Y(e)-Ll),Rl=e=>Y(e)<=1,zl=e=>Y(e)>=6,Bl=e=>`${Math.round(Y(e)*100)}%`,Vl=e=>`${Y(e)*100}%`,Hl=({svg:e,onClose:t})=>{let[n,r]=(0,y.useState)(1),i=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let t=i.current;if(t===null)return;t.innerHTML=e;let n=t.querySelector(`svg`);n!==null&&(n.style.removeProperty(`max-width`),n.style.setProperty(`width`,`100%`),n.style.setProperty(`height`,`auto`))},[e]),(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),()=>{document.removeEventListener(`keydown`,e)}},[t]),(0,x.jsxs)(`div`,{className:`console-mermaid-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":`Enlarged diagram`,children:[(0,x.jsxs)(`div`,{className:`console-mermaid-modal-bar`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-mermaid-modal-button`,"aria-label":`Zoom out`,disabled:Rl(n),onClick:()=>r(Z(n)),children:`−`}),(0,x.jsx)(`span`,{className:`console-mermaid-modal-scale`,children:Bl(n)}),(0,x.jsx)(`button`,{type:`button`,className:`console-mermaid-modal-button`,"aria-label":`Zoom in`,disabled:zl(n),onClick:()=>r(X(n)),children:`+`}),(0,x.jsx)(`button`,{type:`button`,className:`console-mermaid-modal-close`,"aria-label":`Close enlarged diagram`,onClick:t,children:`✕`})]}),(0,x.jsx)(`div`,{className:`console-mermaid-modal-viewport`,children:(0,x.jsx)(`div`,{ref:i,className:`console-mermaid-modal-canvas`,style:{width:Vl(n)}})})]})},Ul=({code:e})=>{let[t,n]=(0,y.useState)({status:`loading`}),[r,i]=(0,y.useState)(!1),a=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let t=!1;return n({status:`loading`}),J(e).then(e=>{t||n({status:`ready`,svg:e})}).catch(e=>{t||n({status:`error`,message:e instanceof Error?e.message:String(e)})}),()=>{t=!0}},[e]),(0,y.useEffect)(()=>{let e=a.current;e!==null&&(e.innerHTML=t.status===`ready`?t.svg:``)},[t]),t.status===`loading`?(0,x.jsx)(`div`,{className:`console-mermaid-loading`,children:`Rendering diagram...`}):t.status===`error`?(0,x.jsxs)(`div`,{className:`console-mermaid`,children:[(0,x.jsxs)(`div`,{className:`console-mermaid-error`,children:[`Mermaid render error: `,t.message]}),(0,x.jsx)(`pre`,{className:`console-mermaid-source`,children:(0,x.jsx)(`code`,{children:e})})]}):(0,x.jsxs)(`div`,{className:`console-mermaid`,children:[(0,x.jsx)(`div`,{ref:a,className:`console-mermaid-rendered`}),(0,x.jsx)(`button`,{type:`button`,className:`console-mermaid-enlarge`,onClick:()=>i(!0),children:`Enlarge diagram`}),r&&(0,x.jsx)(Hl,{svg:t.svg,onClose:()=>i(!1)})]})},Wl=e=>{let t=e.querySelectorAll(`a[href]`),n=[];return t.forEach((e,t)=>{let r=e.getAttribute(`href`)??``;if(Qa(r)===null)return;let i=e.textContent??r,a=document.createElement(`span`);a.className=`console-markdown-reference-host`,e.replaceWith(a),n.push({key:`${t}:${r}`,host:a,href:r,fallbackText:i})}),n},Gl=e=>{let t=e.querySelectorAll(`pre > code`),n=[];return t.forEach((e,t)=>{let r=e.parentElement;if(r===null)return;let i=e.textContent??``,a=document.createElement(`div`);a.className=`console-markdown-code-block`;let o=document.createElement(`div`);o.className=`console-markdown-code-copy-host`,r.replaceWith(a),a.append(o,r),n.push({key:`code:${t}`,host:o,code:i})}),n},Kl=({source:e,buildImageProxyUrl:t,renderReferenceLink:n,repoContext:r})=>{let i=(0,y.useMemo)(()=>{let n=El(e,r);return t===void 0?n:io(n,t)},[e,t,r]),a=(0,y.useRef)(null),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)([]);return(0,y.useEffect)(()=>{let e=a.current;e!==null&&(e.innerHTML=i,l(Gl(e)),s(n===void 0?[]:Wl(e)))},[i,n]),(0,x.jsxs)(`div`,{ref:a,className:`console-markdown`,children:[c.map(e=>(0,E.createPortal)((0,x.jsx)(jl,{code:e.code}),e.host,e.key)),n!==void 0&&o.map(e=>(0,E.createPortal)(n(e.href,e.fallbackText),e.host,e.key))]})},ql=({body:e,buildImageProxyUrl:t,renderReferenceLink:n,repoContext:r})=>{let i=(0,y.useMemo)(()=>Al(e),[e]);return e.trim()===``?(0,x.jsx)(`p`,{className:`console-markdown-empty`,children:`No description provided.`}):(0,x.jsx)(`div`,{className:`console-markdown-view`,children:i.map(e=>e.kind===`mermaid`?(0,x.jsx)(Ul,{code:e.code},e.key):(0,x.jsx)(Kl,{source:e.source,buildImageProxyUrl:t,renderReferenceLink:n,repoContext:r},e.key))})},Jl=({title:e,count:t=null,defaultCollapsed:n=!1,headerAction:r,children:i})=>{let[a,o]=(0,y.useState)(n),s=t===null?e:`${e} (${t})`;return(0,x.jsxs)(`section`,{className:`console-panel`,children:[(0,x.jsxs)(`header`,{className:`console-panel-header`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`console-panel-toggle`,"aria-expanded":!a,onClick:()=>o(e=>!e),children:[(0,x.jsx)(`span`,{className:`console-panel-caret`,children:a?`▸`:`▾`}),(0,x.jsx)(`span`,{className:`console-panel-title`,children:s})]}),r!==void 0&&(0,x.jsx)(`div`,{className:`console-panel-action`,children:r})]}),!a&&(0,x.jsx)(`div`,{className:`console-panel-body`,children:i})]})},Yl=e=>{switch(e){case`added`:return{label:`A`,color:`#3fb950`};case`modified`:return{label:`M`,color:`#d29922`};case`removed`:return{label:`D`,color:`#f85149`};case`renamed`:return{label:`R`,color:`#a371f7`};case`changed`:return{label:`M`,color:`#d29922`};default:return{label:`?`,color:`#8b949e`}}},Xl=()=>({directories:new Map,files:[]}),Zl=e=>e.split(`/`).filter(e=>e!==``),Ql=(e,t)=>e.name.localeCompare(t.name),$l=(e,t)=>{let n=[];e.directories.forEach((e,r)=>{let i=t===``?r:`${t}/${r}`;n.push({kind:`directory`,name:r,path:i,children:$l(e,i)})}),n.sort(Ql);let r=e.files.map(e=>({kind:`file`,name:Zl(e.path).at(-1)??e.path,path:e.path,file:e}));return r.sort(Ql),[...n,...r]},eu=e=>{let t=Xl();for(let n of e){let e=Zl(n.path);if(e.length===0){t.files.push(n);continue}let r=e.slice(0,-1),i=t;for(let e of r){let t=i.directories.get(e);if(t===void 0){let t=Xl();i.directories.set(e,t),i=t;continue}i=t}i.files.push(n)}return $l(t,``)},tu=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/,nu=e=>{let t=[],n=0,r=0;for(let i of e.split(`
87
87
  `)){if(i.startsWith(`@@`)){let e=i.match(tu);e!==null&&(n=Number(e[1]),r=Number(e[2])),t.push({kind:`hunk`,oldLineNumber:null,newLineNumber:null,content:i});continue}if(i.startsWith(`+`)){t.push({kind:`add`,oldLineNumber:null,newLineNumber:r,content:i}),r+=1;continue}if(i.startsWith(`-`)){t.push({kind:`del`,oldLineNumber:n,newLineNumber:null,content:i}),n+=1;continue}t.push({kind:`ctx`,oldLineNumber:n,newLineNumber:r,content:i}),n+=1,r+=1}return t},ru=[`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`,`.svg`,`.avif`,`.bmp`,`.ico`],iu=e=>{let t=e.toLowerCase();return ru.some(e=>t.endsWith(e))},au=e=>e.kind===`add`||e.kind===`ctx`?e.newLineNumber===null?null:{line:e.newLineNumber,side:`RIGHT`}:e.kind===`del`?e.oldLineNumber===null?null:{line:e.oldLineNumber,side:`LEFT`}:null,ou=e=>`${e.kind}:${e.oldLineNumber??`x`}:${e.newLineNumber??`x`}:${e.content}`,su=({target:e,onSubmit:t,onClose:n})=>{let[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)({kind:`idle`}),s=async()=>{let n=r.trim();if(n.length!==0&&a.kind!==`posting`){o({kind:`posting`});try{await t(e.path,e.line,e.side,n),i(``),o({kind:`posted`})}catch(e){o({kind:`error`,message:e instanceof Error?e.message:`failed to post`})}}};return(0,x.jsxs)(`div`,{className:`console-diff-composer`,children:[(0,x.jsxs)(`div`,{className:`console-diff-composer-anchor`,children:[`commenting on line `,e.line,` (`,e.side,`)`]}),a.kind===`posted`?(0,x.jsx)(`p`,{className:`console-diff-composer-posted`,children:`Comment saved.`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`textarea`,{className:`console-diff-composer-input`,rows:3,placeholder:`Leave a review comment on this line…`,value:r,onChange:e=>i(e.target.value)}),(0,x.jsxs)(`div`,{className:`console-diff-composer-controls`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-diff-composer-submit`,disabled:a.kind===`posting`,onClick:()=>{s()},children:`Comment`}),(0,x.jsx)(`button`,{type:`button`,className:`console-diff-composer-cancel`,onClick:n,children:`Cancel`}),a.kind===`posting`&&(0,x.jsx)(`span`,{className:`console-diff-composer-status`,children:`Posting…`}),a.kind===`error`&&(0,x.jsxs)(`span`,{role:`alert`,className:`console-diff-composer-status console-diff-composer-error`,children:[`Failed: `,a.message]})]})]})]})},cu=({patch:e,path:t,rawUrl:n,buildImageProxyUrl:r,onAddInlineComment:i})=>{let[a,o]=(0,y.useState)(null);if(e===null||e===``){if(t!==void 0&&n!=null){if(n.startsWith(`data:image/`))return(0,x.jsx)(`div`,{className:`console-file-diff-image`,children:(0,x.jsx)(`img`,{className:`console-file-diff-image-content`,src:n,alt:t})});if(iu(t)&&r!==void 0)return(0,x.jsx)(`div`,{className:`console-file-diff-image`,children:(0,x.jsx)(`img`,{className:`console-file-diff-image-content`,src:r(n),alt:t})})}return(0,x.jsx)(`p`,{className:`console-file-diff-empty`,children:`(no diff / binary or too large)`})}let s=nu(e),c=i!==void 0&&t!==void 0&&t.length>0,l=c?4:3;return(0,x.jsx)(`table`,{className:`console-file-diff`,children:(0,x.jsx)(`tbody`,{children:s.map(e=>{let n=ou(e),r=c?au(e):null,s=a!==null&&r!==null&&a.line===r.line&&a.side===r.side;return(0,x.jsxs)(y.Fragment,{children:[(0,x.jsxs)(`tr`,{className:`console-diff-row console-diff-${e.kind}`,children:[c&&(0,x.jsx)(`td`,{className:`console-diff-comment-cell`,children:r!==null&&t!==void 0&&(0,x.jsx)(`button`,{type:`button`,className:`console-diff-comment-button`,"aria-label":`Comment on line ${r.line} (${r.side})`,"aria-expanded":s,onClick:()=>o(s?null:{path:t,line:r.line,side:r.side}),children:`+`})}),(0,x.jsx)(`td`,{className:`console-diff-ln`,children:e.oldLineNumber??``}),(0,x.jsx)(`td`,{className:`console-diff-ln`,children:e.newLineNumber??``}),(0,x.jsx)(`td`,{className:`console-diff-code`,children:e.content})]}),s&&i!==void 0&&a!==null&&(0,x.jsx)(`tr`,{className:`console-diff-composer-row`,children:(0,x.jsx)(`td`,{colSpan:l,children:(0,x.jsx)(su,{target:a,onSubmit:i,onClose:()=>o(null)})})})]},n)})})})},lu=e=>({paddingLeft:`${e*16}px`}),uu=({file:e,depth:t,name:n,buildImageProxyUrl:r,onAddInlineComment:i})=>{let[a,o]=(0,y.useState)(!1),s=Yl(e.status);return(0,x.jsxs)(`li`,{className:`console-file`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`console-file-row`,style:lu(t),"aria-expanded":a,onClick:()=>o(e=>!e),children:[(0,x.jsx)(`span`,{className:`console-file-caret`,children:a?`▾`:`▸`}),(0,x.jsx)(`span`,{className:`console-file-badge`,style:{color:s.color,borderColor:s.color},children:s.label}),(0,x.jsx)(`span`,{className:`console-file-path`,children:n}),(0,x.jsxs)(`span`,{className:`console-file-stat console-file-add`,children:[`+`,e.additions]}),(0,x.jsxs)(`span`,{className:`console-file-stat console-file-del`,children:[`-`,e.deletions]})]}),a&&(0,x.jsx)(cu,{patch:e.patch,path:e.path,rawUrl:e.rawUrl,buildImageProxyUrl:r,onAddInlineComment:i})]})},du=({node:e,depth:t,buildImageProxyUrl:n,onAddInlineComment:r})=>e.kind===`file`?(0,x.jsx)(uu,{file:e.file,depth:t,name:e.name,buildImageProxyUrl:n,onAddInlineComment:r}):(0,x.jsxs)(`li`,{className:`console-file-tree-dir`,children:[(0,x.jsxs)(`div`,{className:`console-file-tree-dir-name`,style:lu(t),children:[(0,x.jsx)(`span`,{className:`console-file-tree-dir-icon`,"aria-hidden":`true`,children:`📁`}),e.name]}),(0,x.jsx)(`ul`,{className:`console-file-tree-children`,children:e.children.map(e=>(0,x.jsx)(du,{node:e,depth:t+1,buildImageProxyUrl:n,onAddInlineComment:r},e.path))})]}),fu=({files:e,isLoading:t,error:n,buildImageProxyUrl:r,onAddInlineComment:i})=>{if(n!==null)return(0,x.jsx)(`p`,{className:`console-files-notloaded`,children:`Not loaded.`});if(t)return(0,x.jsx)(`p`,{className:`console-files-loading`,children:`Loading changed files...`});if(e.length===0)return(0,x.jsx)(`p`,{className:`console-files-empty`,children:`No changed files.`});let a=eu(e);return(0,x.jsx)(`ul`,{className:`console-files console-file-tree`,children:a.map(e=>(0,x.jsx)(du,{node:e,depth:0,buildImageProxyUrl:r,onAddInlineComment:i},e.path))})},pu=({comments:e,isLoading:t,error:n,now:r,buildImageProxyUrl:i,renderReferenceLink:a,repoContext:o})=>{let[s,c]=(0,y.useState)(!1);if(n!==null)return(0,x.jsx)(`p`,{className:`console-comment-notloaded`,children:`Not loaded.`});if(t)return(0,x.jsx)(`p`,{className:`console-comment-loading`,children:`Loading comments...`});if(e.length===0)return(0,x.jsx)(`p`,{className:`console-comment-empty`,children:`No comments.`});let l=s?e:e.slice(-1);return(0,x.jsxs)(`div`,{className:`console-comment-list`,children:[!s&&e.length>1&&(0,x.jsxs)(`button`,{type:`button`,className:`console-comment-show-all`,onClick:()=>c(!0),children:[`Show all `,e.length]}),l.map(e=>(0,x.jsxs)(`article`,{className:`console-comment`,children:[(0,x.jsxs)(`header`,{className:`console-comment-header`,children:[(0,x.jsx)(`span`,{className:`console-comment-author`,children:e.author}),(0,x.jsx)(`span`,{className:`console-comment-time`,children:se(e.createdAt,r)})]}),(0,x.jsx)(ql,{body:e.body,buildImageProxyUrl:i,renderReferenceLink:a,repoContext:o})]},`${e.author}:${e.createdAt}:${e.body}`))]})},mu=e=>e.slice(0,7),hu=e=>e.split(`
88
- `)[0],gu=({commits:e,isLoading:t,error:n,now:r})=>n===null?t?(0,x.jsx)(`p`,{className:`console-commits-loading`,children:`Loading commits...`}):e.length===0?(0,x.jsx)(`p`,{className:`console-commits-empty`,children:`No commits.`}):(0,x.jsx)(`ul`,{className:`console-commits`,children:e.map(e=>(0,x.jsxs)(`li`,{className:`console-commit`,children:[(0,x.jsx)(`span`,{className:`console-commit-message`,children:hu(e.message)}),(0,x.jsx)(`span`,{className:`console-commit-sha`,children:mu(e.sha)}),(0,x.jsx)(`span`,{className:`console-commit-author`,children:e.author}),(0,x.jsx)(`span`,{className:`console-commit-time`,children:se(e.authoredAt,r)})]},e.sha))}):(0,x.jsx)(`p`,{className:`console-commits-notloaded`,children:`Not loaded.`}),_u=({url:e,label:t=`Copy URL`})=>(0,x.jsx)(Cn,{value:e,idleText:`Copy URL`,idleAriaLabel:t,copiedAriaLabel:`URL copied to clipboard`,className:`console-copy-url-button`}),vu=e=>{let t=new Map;for(let n of e){let e=t.get(n.message);if(e===void 0){t.set(n.message,[n.section]);continue}e.push(n.section)}return Array.from(t,([e,t])=>({message:e,sections:t}))},yu=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`,bu=({failures:e})=>e.length===0?null:(0,x.jsx)(`div`,{role:`alert`,className:`console-detail-fetch-error`,children:vu(e).map(e=>(0,x.jsxs)(`p`,{className:`console-detail-fetch-error-line`,children:[`Failed to load `,yu(e.sections),`:`,` `,e.message]},e.message))}),xu={MERGEABLE:{color:`GREEN`,label:`No conflict`,title:`This pull request has no merge conflicts`,modifier:`console-detail-mergeable-chip-ok`},CONFLICTING:{color:`RED`,label:`Conflict`,title:`This pull request has merge conflicts`,modifier:`console-detail-mergeable-chip-conflict`},UNKNOWN:{color:`GRAY`,label:`Checking merge status`,title:`GitHub has not finished computing the merge status yet`,modifier:`console-detail-mergeable-chip-unknown`}},Su=({mergeableStatus:e})=>{let t=xu[e],n=ae(t.color);return(0,x.jsx)(`span`,{className:`console-detail-status-chip console-detail-mergeable-chip ${t.modifier}`,style:{color:n.fg,borderColor:n.border,backgroundColor:n.bg},title:t.title,children:t.label})},Cu=e=>{let t=ae(e);return{color:t.fg,borderColor:t.border,backgroundColor:t.bg}},wu=({isPassedAllCiJob:e,isCiStateSuccess:t,isBranchOutOfDate:n,missingRequiredCheckNames:r})=>{let i=e&&t,a=i?`GREEN`:`RED`,o=i?`CI passing`:`CI failing`,s=!i&&r.length>0?`missing: ${r.join(`, `)}`:null;return(0,x.jsxs)(`span`,{className:`console-detail-pr-status`,children:[(0,x.jsxs)(`span`,{className:`console-detail-status-chip console-detail-ci-chip`,style:Cu(a),title:s??o,children:[o,s!==null&&(0,x.jsxs)(`span`,{className:`console-detail-ci-missing`,children:[` `,`(`,s,`)`]})]}),n&&(0,x.jsx)(`span`,{className:`console-detail-status-chip console-detail-outofdate-chip`,style:Cu(`YELLOW`),title:`This branch is out of date with the base branch`,children:`Out of date`})]})},Tu=({pullRequest:e,body:t,bodyIsLoading:n,files:r,filesAreLoading:i,filesError:a,commits:o,commitsAreLoading:s,commitsError:c,now:l,buildImageProxyUrl:u,renderReferenceLink:d,onAddInlineComment:f})=>{let p=e.summary,m=Qa(e.url),h=m===null?void 0:{owner:m.owner,repo:m.repo},g=i||a!==null?null:r.length,_=s||c!==null?null:o.length;return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`console-pr-header`,children:[(0,x.jsx)(`a`,{href:e.url,className:`console-pr-section-title`,target:`_blank`,rel:`noopener noreferrer`,children:p?.title??e.url}),e.isDraft&&(0,x.jsx)(`span`,{className:`console-pr-section-state`,children:`draft`}),(0,x.jsx)(Su,{mergeableStatus:e.mergeableStatus}),(0,x.jsx)(wu,{isPassedAllCiJob:e.isPassedAllCiJob,isCiStateSuccess:e.isCiStateSuccess,isBranchOutOfDate:e.isBranchOutOfDate,missingRequiredCheckNames:e.missingRequiredCheckNames}),(0,x.jsx)(`a`,{href:e.url,className:`console-panel-open-link`,target:`_blank`,rel:`noopener noreferrer`,children:`open`}),(0,x.jsx)(_u,{url:e.url,label:`Copy PR URL`}),(0,x.jsxs)(`div`,{className:`console-pr-statbar`,children:[m!==null&&(0,x.jsxs)(`span`,{className:`console-pr-repo`,children:[m.owner,`/`,m.repo]}),e.branchName!==null&&(0,x.jsx)(`span`,{className:`console-pr-branch`,children:e.branchName}),p!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`span`,{className:`console-pr-add`,children:[`+`,p.additions]}),(0,x.jsxs)(`span`,{className:`console-pr-del`,children:[`-`,p.deletions]}),(0,x.jsxs)(`span`,{className:`console-pr-files-count`,children:[p.changedFiles,` files`]})]})]})]}),(0,x.jsx)(Jl,{title:`Description`,children:n?(0,x.jsx)(`p`,{className:`console-pr-body-loading`,children:`Loading description...`}):(0,x.jsx)(ql,{body:p?.body??t,buildImageProxyUrl:u,renderReferenceLink:d,repoContext:h})}),(0,x.jsx)(Jl,{title:`Changed files`,count:g,children:(0,x.jsx)(fu,{files:r,isLoading:i,error:a,buildImageProxyUrl:u,onAddInlineComment:f})}),(0,x.jsx)(Jl,{title:`Commits`,count:_,defaultCollapsed:!0,children:(0,x.jsx)(gu,{commits:o,isLoading:s,error:c,now:l})})]})},Eu=({item:e,storyName:t,storyColorEnum:n,overlayStatus:r,statusOptions:i,state:a,body:o,bodyIsLoading:s,bodyError:c,comments:l,commentsAreLoading:u,commentsError:d,files:f,filesAreLoading:p,filesError:m,commits:h,commitsAreLoading:g,commitsError:_,stateError:v,pullRequestStatus:y,pullRequestStatusError:b,relatedPullRequests:S,relatedPullRequestsError:C,now:w,commentComposer:T,operationBar:E,buildImageProxyUrl:D,renderReferenceLink:O,onAddInlineComment:ee})=>{let te=a?.state??`open`,ne=a?.merged??!1,k=!e.isPr&&te===`closed`?`Closed`:null,A=$a(e.nameWithOwner)??void 0,re=ae(n),ie=r===null?e.status===null?null:{name:e.status,color:i.find(t=>t.name===e.status)?.color??`GRAY`}:r,j=ie===null?null:ae(ie.color),M=p||m!==null?null:f.length,N=u||d!==null?null:l.length,oe=g||_!==null?null:h.length,P=e=>{let t=Qa(e);return t===null?e:`PR #${t.number}`},F=[{section:`item state`,message:v},{section:`pull request status`,message:e.isPr?b:null},{section:`description`,message:c},{section:`comments`,message:d},{section:`changed files`,message:e.isPr?m:null},{section:`commits`,message:e.isPr?_:null},{section:`related pull requests`,message:e.isPr?null:C},...S.flatMap(e=>[{section:`changed files of ${P(e.pullRequest.url)}`,message:e.filesError},{section:`commits of ${P(e.pullRequest.url)}`,message:e.commitsError}])].flatMap(e=>e.message===null?[]:[{section:e.section,message:e.message}]),I=e.isPr&&y?.found?[{url:e.url,mergeableStatus:y.mergeableStatus}]:[];return(0,x.jsxs)(`article`,{className:`console-detail`,children:[(0,x.jsxs)(`div`,{className:`console-detail-header`,children:[(0,x.jsxs)(`h2`,{className:`console-detail-title`,children:[(0,x.jsx)(de,{isPr:e.isPr,state:te,merged:ne,isDraft:!1,stateReason:``}),(0,x.jsx)(`span`,{className:`console-detail-title-text`,children:e.title}),(0,x.jsx)(`span`,{className:`console-detail-number`,children:e.isPr?`PR #${e.number}`:`#${e.number}`})]}),(0,x.jsxs)(`div`,{className:`console-detail-topline`,children:[ie!==null&&j!==null&&(0,x.jsx)(`span`,{className:`console-detail-status-chip`,style:{color:j.fg,borderColor:j.border,backgroundColor:j.bg},children:ie.name}),e.agent!==null&&e.agent!==``&&(0,x.jsx)(`span`,{className:`console-detail-agent-chip`,children:e.agent}),t!==null&&(0,x.jsxs)(`span`,{className:`console-storytag`,children:[(0,x.jsx)(`span`,{className:`console-story-dot`,style:{backgroundColor:re.dot}}),t]}),e.isPr&&y?.found&&(0,x.jsx)(wu,{isPassedAllCiJob:y.isPassedAllCiJob,isCiStateSuccess:y.isCiStateSuccess,isBranchOutOfDate:y.isBranchOutOfDate,missingRequiredCheckNames:y.missingRequiredCheckNames}),!e.isPr&&S.map(e=>(0,x.jsxs)(`span`,{className:`console-related-pr-group`,children:[S.length>1&&(0,x.jsx)(`span`,{className:`console-related-pr-label`,children:P(e.pullRequest.url)}),(0,x.jsx)(wu,{isPassedAllCiJob:e.pullRequest.isPassedAllCiJob,isCiStateSuccess:e.pullRequest.isCiStateSuccess,isBranchOutOfDate:e.pullRequest.isBranchOutOfDate,missingRequiredCheckNames:e.pullRequest.missingRequiredCheckNames}),(0,x.jsx)(Su,{mergeableStatus:e.pullRequest.mergeableStatus})]},e.pullRequest.url)),I.map(e=>(0,x.jsx)(Su,{mergeableStatus:e.mergeableStatus},e.url)),k!==null&&(0,x.jsx)(`span`,{className:`console-detail-closed-label`,children:k})]}),(0,x.jsx)(bu,{failures:F}),(0,x.jsxs)(`div`,{className:`console-detail-subbar`,children:[(0,x.jsxs)(`a`,{href:e.url,className:`console-detail-link`,target:`_blank`,rel:`noopener noreferrer`,children:[`#`,e.number]}),(0,x.jsx)(`span`,{className:`console-detail-repo`,children:e.repo}),(0,x.jsxs)(`span`,{className:`console-detail-createdat`,title:ce(e.createdAt),children:[`opened `,se(e.createdAt,w)]}),(0,x.jsx)(_u,{url:e.url}),e.labels.map(e=>(0,x.jsx)(`span`,{className:`console-label-chip`,children:e},e))]})]}),(0,x.jsxs)(`div`,{className:`console-detail-body`,children:[(0,x.jsx)(Jl,{title:`Description`,headerAction:(0,x.jsx)(`a`,{href:e.url,className:`console-panel-open-link`,target:`_blank`,rel:`noopener noreferrer`,children:`open`}),children:c===null?s?(0,x.jsx)(`p`,{className:`console-detail-body-loading`,children:`Loading description...`}):(0,x.jsx)(ql,{body:o,buildImageProxyUrl:D,renderReferenceLink:O,repoContext:A}):(0,x.jsx)(`p`,{className:`console-detail-body-notloaded`,children:`Not loaded.`})}),e.isPr&&(0,x.jsx)(Jl,{title:`Changed files`,count:M,children:(0,x.jsx)(fu,{files:f,isLoading:p,error:m,onAddInlineComment:ee})}),(0,x.jsx)(Jl,{title:`Comments`,count:N,defaultCollapsed:e.isPr,children:(0,x.jsx)(pu,{comments:l,isLoading:u,error:d,now:w,buildImageProxyUrl:D,renderReferenceLink:O,repoContext:A})}),e.isPr&&(0,x.jsx)(Jl,{title:`Commits`,count:oe,defaultCollapsed:!0,children:(0,x.jsx)(gu,{commits:h,isLoading:g,error:_,now:w})}),!e.isPr&&S.map(e=>(0,x.jsx)(Tu,{pullRequest:e.pullRequest,body:e.pullRequest.summary?.body??``,bodyIsLoading:!1,files:e.files,filesAreLoading:e.filesAreLoading,filesError:e.filesError,commits:e.commits,commitsAreLoading:e.commitsAreLoading,commitsError:e.commitsError,now:w,buildImageProxyUrl:D,renderReferenceLink:O,onAddInlineComment:ee},e.pullRequest.url))]}),(0,x.jsxs)(`div`,{className:`console-detail-dock`,children:[(0,x.jsx)(`div`,{className:`console-detail-dock-composer`,children:T}),(0,x.jsx)(`div`,{className:`console-actionbar`,children:E})]})]})},Du=({onClose:e})=>(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>e(`close_not_planned`),children:`Close as not planned`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>e(`close`),children:`Close`})]}),Ou=({onDeleteAllComments:e})=>{let[t,n]=(0,y.useState)(!1);return(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>n(e=>!e),children:`⚠`}),t&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>{e(),n(!1)},children:`Delete All Comments`})]})},ku=({isManualTriage:e,onSetNextActionDate:t})=>(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1hour`),children:`+1 hour`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_3hours`),children:`+3 hours`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1day`),children:`+1 day`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1week`),children:e?`+1 week and skip`:`+1 week`})]}),Au=[{action:`unnecessary`,label:`Unnecessary`,variant:`unneeded`},{action:`totally_wrong`,label:`Totally wrong`,variant:`wrong`},{action:`request_changes`,label:`Reject`,variant:`reject`},{action:`approve_and_merge`,label:`Approve & Merge`,variant:`approve`}],ju=`Reject needs an inline comment on the diff.`,Mu=({onReview:e,rejectEnabled:t})=>(0,x.jsxs)(`div`,{className:`console-op-group console-op-group-review`,children:[!t&&(0,x.jsx)(`p`,{className:`console-op-requirement`,children:ju}),Au.map(n=>{let r=n.action===`request_changes`&&!t;return(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-${n.variant}`,disabled:r,onClick:()=>e(n.action),children:n.label},n.action)})]}),Nu=({onSetDependedIssueUrl:e})=>{let[t,n]=(0,y.useState)(!1),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null);return(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>{n(e=>!e),c(null)},title:`Rare actions`,children:`⋯`}),t&&e!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`input`,{type:`url`,className:`console-settings-modal-input`,placeholder:`Depended issue URL`,value:r,onChange:e=>i(e.target.value),disabled:a}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:async()=>{if(e!==null&&r.trim()!==``){o(!0),c(null);try{await e(r.trim()),i(``),n(!1)}catch(e){c(e instanceof Error?e.message:`Failed to set depended issue URL`)}finally{o(!1)}}},disabled:a||r.trim()===``,children:a?`...`:`Set Depended Issue`})]}),s!==null&&(0,x.jsx)(`p`,{className:`console-settings-modal-error`,children:s})]})},Pu=(e,t)=>{let n=t.toLowerCase();return e.find(e=>e.name.toLowerCase()===n)??null},Fu=({statusOptions:e,onSetStatus:t,onSetInTmuxByHuman:n})=>{let r=li.map(t=>({name:t,option:Pu(e,t)})).filter(e=>e.option!==null);return r.length===0?null:(0,x.jsx)(`div`,{className:`console-op-group`,children:r.map(({name:e,option:r})=>{let i=ae(r.color),a=e===ci;return(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,style:{color:i.fg,borderColor:i.border,backgroundColor:i.bg},onClick:()=>a?n(r):t(r),children:r.name},r.id)})})},Iu=({tab:e,hasPullRequest:t,rejectEnabled:n,statusOptions:r,handlers:i})=>(0,x.jsxs)(`div`,{className:`console-operation-bar`,children:[(0,x.jsx)(Nu,{onSetDependedIssueUrl:i.onSetDependedIssueUrl}),t&&(0,x.jsx)(Mu,{onReview:i.onReview,rejectEnabled:n}),(0,x.jsx)(ku,{isManualTriage:ui(e),onSetNextActionDate:i.onSetNextActionDate}),(0,x.jsx)(Fu,{statusOptions:r,onSetStatus:i.onSetStatus,onSetInTmuxByHuman:i.onSetInTmuxByHuman}),(0,x.jsxs)(`div`,{className:`console-op-group-bottom-row`,children:[(0,x.jsx)(Ou,{onDeleteAllComments:i.onDeleteAllComments}),(0,x.jsx)(Du,{onClose:i.onClose})]})]}),Lu=(e,t,n,r)=>{let i=t===null?void 0:e.peek(t),[a,o]=(0,y.useState)(i??r),[s,c]=(0,y.useState)(t!==null&&i===void 0),[l,u]=(0,y.useState)(null);return(0,y.useEffect)(()=>{if(t===null||n===null)return;let r=e.peek(t);if(r!==void 0){o(r),c(!1),u(null);return}let i=!1;return c(!0),u(null),e.load(t,n).then(e=>{i||(o(e),c(!1))}).catch(e=>{i||(u(e instanceof Error?e.message:String(e)),c(!1))}),()=>{i=!0}},[e,t,n]),{data:a,isLoading:s,error:l}},Ru=[],zu=[],Bu=[],Vu=[],Hu={state:`open`,merged:!1,isPullRequest:!1,title:``},Uu={found:!1,isConflicted:!1,mergeableStatus:`UNKNOWN`,isPassedAllCiJob:!1,isCiStateSuccess:!1,isBranchOutOfDate:!1,missingRequiredCheckNames:[]},Q=(e,t)=>{let n=t===null?null:`${t.repo}#${t.number}`,r=t===null?null:t.url,i=t?.isPr??!1,a=Lu(e.body,n,r,``),o=Lu(e.state,n,r,Hu),s=Lu(e.comments,n,r,Ru),c=Lu(e.files,i?n:null,i?r:null,zu),l=Lu(e.commits,i?n:null,i?r:null,Bu),u=Lu(e.prStatus,i?n:null,i?r:null,Uu),d=!i&&(t?.relatedOpenPullRequestUrls.length??0)>0,f=Lu(e.relatedPrs,d?n:null,d?r:null,Vu),[p,m]=(0,y.useState)([]);return(0,y.useEffect)(()=>{if(i||f.data.length===0){m([]);return}let t=!1,n=f.data.map(e=>({pullRequest:e,files:zu,filesAreLoading:!0,filesError:null,commits:Bu,commitsAreLoading:!0,commitsError:null}));m(n);let r=(e,n)=>{t||m(t=>t.map(t=>t.pullRequest.url===e?{...t,...n}:t))};for(let t of f.data){let n=t.url;e.files.load(n,t.url).then(e=>r(t.url,{files:e,filesAreLoading:!1})).catch(e=>r(t.url,{filesAreLoading:!1,filesError:e instanceof Error?e.message:String(e)})),e.commits.load(n,t.url).then(e=>r(t.url,{commits:e,commitsAreLoading:!1})).catch(e=>r(t.url,{commitsAreLoading:!1,commitsError:e instanceof Error?e.message:String(e)}))}return()=>{t=!0}},[e,i,f.data]),{state:o.data,body:a.data,bodyIsLoading:a.isLoading,bodyError:a.error,comments:s.data,commentsAreLoading:s.isLoading,commentsError:s.error,files:c.data,filesAreLoading:c.isLoading,filesError:c.error,commits:l.data,commitsAreLoading:l.isLoading,commitsError:l.error,stateError:o.error,pullRequestStatus:i?u.data:null,pullRequestStatusError:i?u.error:null,relatedPullRequests:p,relatedPullRequestsError:i?null:f.error}},Wu=e=>JSON.stringify([e.author,e.createdAt,e.body]),Gu=(e,t)=>{let n=new Set(e.map(Wu));return[...e,...t.filter(e=>!n.has(Wu(e)))]},Ku=({href:e,fallbackText:t,state:n})=>{if(n===null||n.title.trim()===``)return(0,x.jsx)(`a`,{className:`console-markdown-reference console-markdown-reference-plain`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:t});let r=Qa(e);return(0,x.jsxs)(`a`,{className:`console-markdown-reference`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:[(0,x.jsx)(de,{...eo(n)}),(0,x.jsx)(`span`,{className:`console-markdown-reference-title`,children:n.title}),r!==null&&(0,x.jsxs)(`span`,{className:`console-markdown-reference-number`,children:[`#`,r.number]})]})},qu=(e,t)=>{let[n,r]=(0,y.useState)(()=>e.peek(t)??null);return(0,y.useEffect)(()=>{let n=e.peek(t);if(n!==void 0){r(n);return}let i=!1;return r(null),e.load(t,t).then(e=>{i||r(e)}).catch(()=>{i||r(null)}),()=>{i=!0}},[e,t]),n},Ju=({cache:e,href:t,fallbackText:n})=>{let r=qu(e,t);return(0,x.jsx)(Ku,{href:t,fallbackText:n,state:r})},Yu=e=>({itemUrl:e.url,projectItemId:e.projectItemId,itemNumber:e.number,repo:e.repo,isPr:e.isPr}),Xu=(e,t,n,r,i)=>({...Yu(t),apiPath:$i,requestBody:na(e,t,n,r,i)}),Zu=(e,t,n,r)=>({...Yu(t),apiPath:ea,requestBody:ra(e,t,n,r)}),Qu=(e,t)=>({...Yu(t),apiPath:ta,requestBody:ia(e,t)}),$u=({tab:e,item:t,caches:n,operations:r,pjcode:i,statusOptions:a,storyColors:o,storyName:s,overlayStatus:c,now:l,initialCommentDraft:u,onCommentDraftChange:d,onQueueAction:f})=>{let p=Q(n,t),m=(0,y.useCallback)(e=>ro(e,t.url),[t.url]),h=(0,y.useCallback)((e,t)=>(0,x.jsx)(Ju,{cache:n.state,href:e,fallbackText:t}),[n.state]),g=t.isPr||t.relatedOpenPullRequestUrls.length>0||p.relatedPullRequests.length>0,[_,v]=(0,y.useState)([]),b=(0,y.useCallback)(async(e,t,n,r)=>{v(i=>[...i,{path:e,line:t,side:n,body:r}])},[]),[S,C]=(0,y.useState)([]),w=(0,y.useCallback)(async e=>{let n=await r.addComment(t,e);return C(e=>[...e,n]),n},[t,r]),T={onReview:e=>{let n=t.isPr?t.url:p.relatedPullRequests[0]?.pullRequest.url??t.relatedOpenPullRequestUrls[0]??t.url,a=e===`request_changes`?_:[];f({kind:{type:`review`,action:e},item:t,commit:()=>r.reviewPullRequest(t,n,e,a),offline:i==null?void 0:Xu(i,t,n,e,a)})},onSetNextActionDate:e=>{f({kind:{type:`next_action_date`,action:e},item:t,commit:()=>r.setNextActionDate(t,e),offline:i==null?void 0:Zu(i,t,e)})},onSetStory:e=>{f({kind:{type:`set_story`,optionName:e.name},item:t,commit:()=>r.setStory(t,e),offline:i==null?void 0:Zu(i,t,`set_story`,{storyOptionId:e.id})})},onSetStatus:e=>{f({kind:{type:`set_status`,optionName:e.name},item:t,commit:()=>r.setStatus(t,e),offline:i==null?void 0:Zu(i,t,`set_status`,{statusName:e.name})})},onSetInTmuxByHuman:e=>{f({kind:{type:`set_in_tmux_by_human`,optionName:e.name},item:t,commit:()=>r.setInTmuxByHuman(t,e),offline:i==null?void 0:Qu(i,t)})},onClose:e=>{f({kind:{type:`close`,action:e},item:t,commit:()=>r.closeIssue(t,e),offline:i==null?void 0:Zu(i,t,e)})},onOkAndAwaitingWorkspace:e=>{f({kind:{type:`ok_and_awaiting_workspace`},item:t,commit:()=>r.okAndMoveToAwaitingWorkspace(t,e)})},onDeleteAllComments:()=>{f({kind:{type:`delete_all_comments`},item:t,commit:()=>r.deleteAllComments(t)})},onSetDependedIssueUrl:i==null?null:async e=>{await r.setDependedIssueUrl(t,e)}},E=a.find(e=>e.name===`Awaiting Workspace`)??null,D=E===null?void 0:async e=>{let t=await w(e);return T.onSetStatus(E),t},O=s??(t.story.trim()===``?null:t.story),ee=O===null?null:A(o,O);return(0,x.jsx)(Eu,{item:t,storyName:O,storyColorEnum:ee,overlayStatus:c,statusOptions:a,state:p.state,stateError:p.stateError,body:p.body,bodyIsLoading:p.bodyIsLoading,bodyError:p.bodyError,comments:Gu(p.comments,S),commentsAreLoading:p.commentsAreLoading,commentsError:p.commentsError,files:p.files,filesAreLoading:p.filesAreLoading,filesError:p.filesError,commits:p.commits,commitsAreLoading:p.commitsAreLoading,commitsError:p.commitsError,pullRequestStatus:p.pullRequestStatus,pullRequestStatusError:p.pullRequestStatusError,relatedPullRequests:p.relatedPullRequests,relatedPullRequestsError:p.relatedPullRequestsError,now:l,buildImageProxyUrl:m,renderReferenceLink:h,onAddInlineComment:b,commentComposer:(0,x.jsx)(Xa,{initiallyOpen:!0,initialDraft:u,onSubmit:w,onDraftChange:d,onOkAndAwaitingWorkspace:E===null?void 0:()=>T.onOkAndAwaitingWorkspace(E),onSubmitAndMoveToAwaitingWorkspace:D,onUploadFile:e=>r.uploadAttachment(t,e)}),operationBar:(0,x.jsx)(Iu,{tab:e,item:t,hasPullRequest:g,rejectEnabled:_.length>0,statusOptions:a,handlers:T})})},ed=()=>{let e={};for(let t of D)e[t.name]=0;return e},td=`console`,nd=()=>{let e=fa(),t=Ri(),n=ur(),r=n.status===`on`?n.snapshot:null,{snapshots:i,isLoading:a,error:o}=Pa(e,r),{timerMode:s,projectMinutes:c,isOpen:l,draftTimerMode:u,draftProjectMinutes:d,openSettings:f,closeSettings:p,saveSettings:m,toggleDraftTimerMode:h,changeDraftMinutes:g}=Ba(),{pjcodes:_,workflowImprovementIssueUrl:v,isLoading:b}=pa(),{isTimerExpired:C}=ha(e),w=ua(e??td),E=ma(e),O=(0,y.useMemo)(()=>{let e=ed();for(let t of D){let n=i[t.name];n!==null&&(t.name===`stories`?e[t.name]=n.stories.filter(e=>e.color!==`GRAY`).length:e[t.name]=Ji(n.items,Xi(w.overlay,n.generatedAt),t.name))}return e},[i,w.overlay]),ee=Wi(e,O),{activeTab:k,selectedItemKey:A,openItem:ie,closeItem:M,selectTab:ae}=ee,N=(0,y.useRef)(new Map),oe=(0,y.useCallback)(e=>{A!==null&&(e?N.current.set(A,e):N.current.delete(A))},[A]),P=ji(r),F=oa(e,k,w,P),I=Di(),[se,ce]=(0,y.useState)(()=>Date.now());(0,y.useEffect)(()=>{let e=setInterval(()=>{ce(Date.now())},1e3);return()=>{clearInterval(e)}},[]);let[le,ue]=(0,y.useState)(()=>navigator.onLine);(0,y.useEffect)(()=>{let e=()=>ue(!0),t=()=>ue(!1);return window.addEventListener(`online`,e),window.addEventListener(`offline`,t),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,t)}},[]);let[de,L]=(0,y.useState)(new Map),[fe,pe]=(0,y.useState)(new Map),[me,ge]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{if(!(!le||I.offlineActions.length===0))for(let e of I.offlineActions)de.has(e.id)||me.has(e.id)||(L(t=>new Map(t).set(e.id,null)),P.client.fetchIssueState(e.itemUrl).then(t=>{L(n=>new Map(n).set(e.id,t)),e.isPr&&(pe(t=>new Map(t).set(e.id,null)),P.client.fetchPullRequestStatus(e.itemUrl).then(t=>{pe(n=>new Map(n).set(e.id,t))}).catch(e=>{console.warn(`Failed to fetch PR status for offline action:`,e)}))}).catch(t=>{console.warn(`Failed to fetch current state for offline action:`,t),ge(t=>new Set(t).add(e.id))}))},[le,I.offlineActions,P.client,de,me]);let[_e,ve]=(0,y.useState)(!1),ye=(0,y.useCallback)(async e=>{ve(!0);try{await I.confirmOfflineAction(e)}finally{ve(!1)}},[I]),be=(0,y.useMemo)(()=>I.offlineActions.map(e=>{let t=de.get(e.id)??null,n=fe.get(e.id)??null,r=me.has(e.id);return{id:e.id,message:e.message,color:e.color,itemNumber:e.itemNumber,isPr:e.isPr,currentTitle:r?null:t?.title??null,currentState:r||t===null?null:t.merged?`closed`:t.state,currentPrStatus:n,fetchError:r}}),[I.offlineActions,de,fe,me]),xe=i[k],Se=(0,y.useMemo)(()=>xe===null?[]:Yi(xe.items,Xi(w.overlay,xe.generatedAt),k),[xe,w.overlay,k]),Ce=(0,y.useMemo)(()=>Se.map(e=>Ki(e)),[Se]),we=xe?.storyOrder??[],Te=(0,y.useMemo)(()=>j(Se,w.overlay,we,xe?.generatedAt??null),[Se,w.overlay,we,xe]),Ee=xe?.storyColors??{},De=xe?.statusOptions??[],Oe=xe?.agentOptions??[],ke=xe?.generatedAt??null,Ae=xe?.fromCache??!1,[je,Me]=(0,y.useState)(null),Ne=(0,y.useMemo)(()=>A===null||xe===null?null:xe.items.find(e=>e.projectItemId===A)??null,[A,xe]);Ii(P,Ne,Se),(0,y.useEffect)(()=>{A!==null&&window.scrollTo({top:0})},[A]),(0,y.useEffect)(()=>{if(e===null&&s&&_.length>0){let e=za(_,null,c);e!==null&&Va(`/projects/${e}`)}},[e,s,_,c]);let Pe=O[k],Fe=(0,y.useRef)({tab:k,count:Pe});(0,y.useEffect)(()=>{let e=Fe.current;if(Fe.current={tab:k,count:Pe},e.tab===k&&e.count>0&&Pe===0){let e=zi(k,O);e!==null&&(ae(e),M())}},[k,Pe,O,ae,M]);let Ie=Ne===null?null:Zi(w.overlay,Ne,i[k]?.generatedAt??null),Le=Ne===null?null:re(Ne,w.overlay,i[k]?.generatedAt??null),Re=(0,y.useCallback)(e=>{let t=Ua(Ce,e);t===null?M():ie(t)},[Ce,ie,M]),ze=(0,y.useCallback)(t=>{if(n.status===`on`){I.showError(`Airplane mode`,`This action requires a network connection. Turn off airplane mode and try again.`);return}let r=Ki(t.item);I.enqueue({message:gi(t.kind,t.item,k),color:mi(t.kind),commit:t.commit,offline:t.offline,advance:()=>{if(hi(t.kind,k)){if(s&&C(c[e??``]??0)){let t=za(_,e,c);t!==null&&Ha(`/projects/${t}`)}else Re(r)}}})},[I,k,Re,n.status,s,C,c,e,_]),Be=ya((0,y.useCallback)(e=>{if(A===null||e===null)return;let t=e===`next`?Wa(Ce,A):Ga(Ce,A);t!==null&&ie(t)},[A,Ce,ie])),[Ve,He]=(0,y.useState)(()=>localStorage.getItem(`console-story-show-gray`)===`true`),Ue=(0,y.useCallback)(()=>{He(e=>{let t=!e;return localStorage.setItem(`console-story-show-gray`,String(t)),t})},[]),We=i.stories,Ge=We?.stories??[],Ke=je!==null&&je.generatedAt===We?.generatedAt?je.stories:Ge,qe=We?.defaultNameWithOwner??null,Je=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);if(qe===null)throw Error(`No repository configured for this project.`);await Hr({pjcode:e,title:n,storyOptionId:t,nameWithOwner:qe})},[e,qe]),Ye=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await Wr({pjcode:e,storyOptionId:t,direction:n});let r=Ke.findIndex(e=>e.storyOptionId===t);if(r!==-1){let e=r+(n===`up`?-1:1);if(e>=0&&e<Ke.length){let t=[...Ke],n=t[r];t[r]=t[e],t[e]=n,Me({generatedAt:We?.generatedAt,stories:t})}}},[e,Ke,We?.generatedAt]),Xe=(0,y.useCallback)(async t=>{if(e===null)throw Error(`No project specified in the URL path.`);await Ir({pjcode:e,storyName:t})},[e]),[Ze,Qe]=(0,y.useState)({}),[$e,et]=(0,y.useState)(null),[tt,nt]=(0,y.useState)({}),rt=(0,y.useCallback)((t,n)=>{let r=Ke.find(e=>e.storyOptionId===t)?.color;if(et(t),Qe(e=>({...e,[t]:n})),nt(e=>{let n={...e};return delete n[t],n}),e===null||qe===null){Qe(e=>r===void 0?e:{...e,[t]:r}),nt(e=>({...e,[t]:`No project or repository configured.`})),et(e=>e===t?null:e);return}Vr({pjcode:e,storyOptionId:t,newColor:n,nameWithOwner:qe}).catch(e=>{Qe(e=>r===void 0?e:{...e,[t]:r}),nt(n=>({...n,[t]:e instanceof Error?e.message:String(e)}))}).finally(()=>{et(e=>e===t?null:e)})},[e,qe,Ke]),it=(0,y.useCallback)(async t=>{if(e===null)throw Error(`No project specified in the URL path.`);await Jr({pjcode:e,storyOptionId:t}),Me({generatedAt:We?.generatedAt,stories:Ke.filter(e=>e.storyOptionId!==t)})},[e,Ke,We?.generatedAt]),at=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await Xr({pjcode:e,storyOptionId:t,newName:n});let r=Ke.map(e=>e.storyOptionId===t?{...e,storyName:n}:e);Me({generatedAt:We?.generatedAt,stories:r})},[e,Ke,We?.generatedAt]);return(0,x.jsxs)(`main`,{className:`console-app`,children:[I.pending!==null&&(0,x.jsx)(Ln,{message:I.pending.message,color:I.pending.color,remainingSeconds:I.pending.remainingSeconds,progress:I.pending.progress,onUndo:I.undo}),I.error!==null&&(0,x.jsx)(Rn,{title:I.error.message,message:`Operation failed: ${I.error.reason}`,onDismiss:I.dismissError}),(0,x.jsx)(In,{actions:be,isOnline:le,isConfirming:_e,onConfirm:ye,onDiscard:I.discardOfflineAction}),E.isOpen&&(0,x.jsx)(S,{value:E.inputValue,onChange:E.changeInput,isLoading:E.isLoading,isSaving:E.isSaving,error:E.error,onSave:E.save,onClose:E.close}),(0,x.jsx)(te,{activeTab:k,counts:O,pjcode:e,pjcodes:_,generatedAt:ke,fromCache:Ae,tabHref:ee.tabHref,onSelectTab:ee.selectTab,onSelectProject:e=>Ha(`/projects/${e}`),settingsButton:(0,x.jsxs)(x.Fragment,{children:[e!==null&&(0,x.jsx)(`button`,{type:`button`,className:`console-tab-settings-button`,"aria-label":`Open project settings`,onClick:E.open,children:`⚙`}),(0,x.jsx)(ne,{isOpen:l,timerMode:u,projectMinutes:d,pjcodes:_,isLoadingPjcodes:b,onOpen:f,onToggleTimerMode:h,onChangeMinutes:g,onSave:m,onClose:p})]}),airplaneModeEnabled:t.airplaneMode,airplaneModeStatus:n.status,airplaneModeProgress:n.progress,airplaneModeCapturedAt:r?.capturedAt??null,airplaneModeFailures:n.failures,onAirplaneModeStartSync:n.startSync,onAirplaneModeTurnOff:n.turnOff,workflowImprovementIssueUrl:v}),(0,x.jsx)(T,{timerEndsAt:xe?.timerEndsAt??null,timerTotalSeconds:xe?.timerTotalSeconds??null,now:se}),k===`stories`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(jn,{stories:Ke,isLoading:a,error:o,showGray:Ve,onCreateIssue:Je,onAddStory:Xe,onSelectColor:rt,onToggleGray:Ue,onReorderStory:Ye,onDeleteStory:it,onRenameStory:at,optimisticColors:Ze,colorChangeInFlight:$e,colorErrors:tt})}):Ne===null?k===`queued`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(he,{rows:Te,storyColors:Ee,statusOptions:De,agentOptions:Oe,activeItemId:null,isLoading:a,error:o,onSelectItem:e=>ee.openItem(e.projectItemId)})}):(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(R,{rows:Te,storyColors:Ee,statusOptions:De,activeItemId:null,now:se,isLoading:a,error:o,onSelectItem:e=>ee.openItem(e.projectItemId)})}):(0,x.jsx)(`div`,{className:`console-detail-screen`,ref:Be,children:(0,x.jsx)($u,{tab:k,item:Ne,caches:P,operations:F,pjcode:e,statusOptions:De,storyColors:Ee,storyName:Le,overlayStatus:Ie,now:se,initialCommentDraft:N.current.get(Ne.projectItemId)??``,onCommentDraftChange:oe,onQueueAction:ze},Ne.projectItemId)})]})};`serviceWorker`in navigator&&navigator.serviceWorker.register(`/sw.js`).catch(e=>{console.warn(`Service worker registration failed:`,e)});var rd=document.getElementById(`root`);if(rd===null)throw Error(`Root container #root not found`);(0,b.createRoot)(rd).render((0,x.jsx)(y.StrictMode,{children:(0,x.jsx)(nd,{})}));
88
+ `)[0],gu=({commits:e,isLoading:t,error:n,now:r})=>n===null?t?(0,x.jsx)(`p`,{className:`console-commits-loading`,children:`Loading commits...`}):e.length===0?(0,x.jsx)(`p`,{className:`console-commits-empty`,children:`No commits.`}):(0,x.jsx)(`ul`,{className:`console-commits`,children:e.map(e=>(0,x.jsxs)(`li`,{className:`console-commit`,children:[(0,x.jsx)(`span`,{className:`console-commit-message`,children:hu(e.message)}),(0,x.jsx)(`span`,{className:`console-commit-sha`,children:mu(e.sha)}),(0,x.jsx)(`span`,{className:`console-commit-author`,children:e.author}),(0,x.jsx)(`span`,{className:`console-commit-time`,children:se(e.authoredAt,r)})]},e.sha))}):(0,x.jsx)(`p`,{className:`console-commits-notloaded`,children:`Not loaded.`}),_u=({url:e,label:t=`Copy URL`})=>(0,x.jsx)(Cn,{value:e,idleText:`Copy URL`,idleAriaLabel:t,copiedAriaLabel:`URL copied to clipboard`,className:`console-copy-url-button`}),vu=e=>{let t=new Map;for(let n of e){let e=t.get(n.message);if(e===void 0){t.set(n.message,[n.section]);continue}e.push(n.section)}return Array.from(t,([e,t])=>({message:e,sections:t}))},yu=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`,bu=({failures:e})=>e.length===0?null:(0,x.jsx)(`div`,{role:`alert`,className:`console-detail-fetch-error`,children:vu(e).map(e=>(0,x.jsxs)(`p`,{className:`console-detail-fetch-error-line`,children:[`Failed to load `,yu(e.sections),`:`,` `,e.message]},e.message))}),xu={MERGEABLE:{color:`GREEN`,label:`No conflict`,title:`This pull request has no merge conflicts`,modifier:`console-detail-mergeable-chip-ok`},CONFLICTING:{color:`RED`,label:`Conflict`,title:`This pull request has merge conflicts`,modifier:`console-detail-mergeable-chip-conflict`},UNKNOWN:{color:`GRAY`,label:`Checking merge status`,title:`GitHub has not finished computing the merge status yet`,modifier:`console-detail-mergeable-chip-unknown`}},Su=({mergeableStatus:e})=>{let t=xu[e],n=ae(t.color);return(0,x.jsx)(`span`,{className:`console-detail-status-chip console-detail-mergeable-chip ${t.modifier}`,style:{color:n.fg,borderColor:n.border,backgroundColor:n.bg},title:t.title,children:t.label})},Cu=e=>{let t=ae(e);return{color:t.fg,borderColor:t.border,backgroundColor:t.bg}},wu=({isPassedAllCiJob:e,isCiStateSuccess:t,isBranchOutOfDate:n,missingRequiredCheckNames:r})=>{let i=e&&t,a=i?`GREEN`:`RED`,o=i?`CI passing`:`CI failing`,s=!i&&r.length>0?`missing: ${r.join(`, `)}`:null;return(0,x.jsxs)(`span`,{className:`console-detail-pr-status`,children:[(0,x.jsxs)(`span`,{className:`console-detail-status-chip console-detail-ci-chip`,style:Cu(a),title:s??o,children:[o,s!==null&&(0,x.jsxs)(`span`,{className:`console-detail-ci-missing`,children:[` `,`(`,s,`)`]})]}),n&&(0,x.jsx)(`span`,{className:`console-detail-status-chip console-detail-outofdate-chip`,style:Cu(`YELLOW`),title:`This branch is out of date with the base branch`,children:`Out of date`})]})},Tu=({pullRequest:e,body:t,bodyIsLoading:n,files:r,filesAreLoading:i,filesError:a,commits:o,commitsAreLoading:s,commitsError:c,now:l,buildImageProxyUrl:u,renderReferenceLink:d,onAddInlineComment:f})=>{let p=e.summary,m=Qa(e.url),h=m===null?void 0:{owner:m.owner,repo:m.repo},g=i||a!==null?null:r.length,_=s||c!==null?null:o.length;return(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`div`,{className:`console-pr-header`,children:[(0,x.jsx)(`a`,{href:e.url,className:`console-pr-section-title`,target:`_blank`,rel:`noopener noreferrer`,children:p?.title??e.url}),e.isDraft&&(0,x.jsx)(`span`,{className:`console-pr-section-state`,children:`draft`}),(0,x.jsx)(Su,{mergeableStatus:e.mergeableStatus}),(0,x.jsx)(wu,{isPassedAllCiJob:e.isPassedAllCiJob,isCiStateSuccess:e.isCiStateSuccess,isBranchOutOfDate:e.isBranchOutOfDate,missingRequiredCheckNames:e.missingRequiredCheckNames}),(0,x.jsx)(`a`,{href:e.url,className:`console-panel-open-link`,target:`_blank`,rel:`noopener noreferrer`,children:`open`}),(0,x.jsx)(_u,{url:e.url,label:`Copy PR URL`}),(0,x.jsxs)(`div`,{className:`console-pr-statbar`,children:[m!==null&&(0,x.jsxs)(`span`,{className:`console-pr-repo`,children:[m.owner,`/`,m.repo]}),e.branchName!==null&&(0,x.jsx)(`span`,{className:`console-pr-branch`,children:e.branchName}),p!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(`span`,{className:`console-pr-add`,children:[`+`,p.additions]}),(0,x.jsxs)(`span`,{className:`console-pr-del`,children:[`-`,p.deletions]}),(0,x.jsxs)(`span`,{className:`console-pr-files-count`,children:[p.changedFiles,` files`]})]})]})]}),(0,x.jsx)(Jl,{title:`Description`,children:n?(0,x.jsx)(`p`,{className:`console-pr-body-loading`,children:`Loading description...`}):(0,x.jsx)(ql,{body:p?.body??t,buildImageProxyUrl:u,renderReferenceLink:d,repoContext:h})}),(0,x.jsx)(Jl,{title:`Changed files`,count:g,children:(0,x.jsx)(fu,{files:r,isLoading:i,error:a,buildImageProxyUrl:u,onAddInlineComment:f})}),(0,x.jsx)(Jl,{title:`Commits`,count:_,defaultCollapsed:!0,children:(0,x.jsx)(gu,{commits:o,isLoading:s,error:c,now:l})})]})},Eu=({item:e,storyName:t,storyColorEnum:n,overlayStatus:r,statusOptions:i,state:a,body:o,bodyIsLoading:s,bodyError:c,comments:l,commentsAreLoading:u,commentsError:d,files:f,filesAreLoading:p,filesError:m,commits:h,commitsAreLoading:g,commitsError:_,stateError:v,pullRequestStatus:y,pullRequestStatusError:b,relatedPullRequests:S,relatedPullRequestsError:C,now:w,commentComposer:T,operationBar:E,buildImageProxyUrl:D,renderReferenceLink:O,onAddInlineComment:ee})=>{let te=a?.state??`open`,ne=a?.merged??!1,k=!e.isPr&&te===`closed`?`Closed`:null,A=$a(e.nameWithOwner)??void 0,re=ae(n),ie=r===null?e.status===null?null:{name:e.status,color:i.find(t=>t.name===e.status)?.color??`GRAY`}:r,j=ie===null?null:ae(ie.color),M=p||m!==null?null:f.length,N=u||d!==null?null:l.length,oe=g||_!==null?null:h.length,P=e=>{let t=Qa(e);return t===null?e:`PR #${t.number}`},F=[{section:`item state`,message:v},{section:`pull request status`,message:e.isPr?b:null},{section:`description`,message:c},{section:`comments`,message:d},{section:`changed files`,message:e.isPr?m:null},{section:`commits`,message:e.isPr?_:null},{section:`related pull requests`,message:e.isPr?null:C},...S.flatMap(e=>[{section:`changed files of ${P(e.pullRequest.url)}`,message:e.filesError},{section:`commits of ${P(e.pullRequest.url)}`,message:e.commitsError}])].flatMap(e=>e.message===null?[]:[{section:e.section,message:e.message}]),I=e.isPr&&y?.found?[{url:e.url,mergeableStatus:y.mergeableStatus}]:[];return(0,x.jsxs)(`article`,{className:`console-detail`,children:[(0,x.jsxs)(`div`,{className:`console-detail-header`,children:[(0,x.jsxs)(`h2`,{className:`console-detail-title`,children:[(0,x.jsx)(de,{isPr:e.isPr,state:te,merged:ne,isDraft:!1,stateReason:``}),(0,x.jsx)(`span`,{className:`console-detail-title-text`,children:e.title}),(0,x.jsx)(`span`,{className:`console-detail-number`,children:e.isPr?`PR #${e.number}`:`#${e.number}`})]}),(0,x.jsxs)(`div`,{className:`console-detail-topline`,children:[ie!==null&&j!==null&&(0,x.jsx)(`span`,{className:`console-detail-status-chip`,style:{color:j.fg,borderColor:j.border,backgroundColor:j.bg},children:ie.name}),e.agent!==null&&e.agent!==``&&(0,x.jsx)(`span`,{className:`console-detail-agent-chip`,children:e.agent}),t!==null&&(0,x.jsxs)(`span`,{className:`console-storytag`,children:[(0,x.jsx)(`span`,{className:`console-story-dot`,style:{backgroundColor:re.dot}}),t]}),e.isPr&&y?.found&&(0,x.jsx)(wu,{isPassedAllCiJob:y.isPassedAllCiJob,isCiStateSuccess:y.isCiStateSuccess,isBranchOutOfDate:y.isBranchOutOfDate,missingRequiredCheckNames:y.missingRequiredCheckNames}),!e.isPr&&S.map(e=>(0,x.jsxs)(`span`,{className:`console-related-pr-group`,children:[S.length>1&&(0,x.jsx)(`span`,{className:`console-related-pr-label`,children:P(e.pullRequest.url)}),(0,x.jsx)(wu,{isPassedAllCiJob:e.pullRequest.isPassedAllCiJob,isCiStateSuccess:e.pullRequest.isCiStateSuccess,isBranchOutOfDate:e.pullRequest.isBranchOutOfDate,missingRequiredCheckNames:e.pullRequest.missingRequiredCheckNames}),(0,x.jsx)(Su,{mergeableStatus:e.pullRequest.mergeableStatus})]},e.pullRequest.url)),I.map(e=>(0,x.jsx)(Su,{mergeableStatus:e.mergeableStatus},e.url)),k!==null&&(0,x.jsx)(`span`,{className:`console-detail-closed-label`,children:k})]}),(0,x.jsx)(bu,{failures:F}),(0,x.jsxs)(`div`,{className:`console-detail-subbar`,children:[(0,x.jsxs)(`a`,{href:e.url,className:`console-detail-link`,target:`_blank`,rel:`noopener noreferrer`,children:[`#`,e.number]}),(0,x.jsx)(`span`,{className:`console-detail-repo`,children:e.repo}),(0,x.jsxs)(`span`,{className:`console-detail-createdat`,title:ce(e.createdAt),children:[`opened `,se(e.createdAt,w)]}),(0,x.jsx)(_u,{url:e.url}),e.labels.map(e=>(0,x.jsx)(`span`,{className:`console-label-chip`,children:e},e))]})]}),(0,x.jsxs)(`div`,{className:`console-detail-body`,children:[(0,x.jsx)(Jl,{title:`Description`,headerAction:(0,x.jsx)(`a`,{href:e.url,className:`console-panel-open-link`,target:`_blank`,rel:`noopener noreferrer`,children:`open`}),children:c===null?s?(0,x.jsx)(`p`,{className:`console-detail-body-loading`,children:`Loading description...`}):(0,x.jsx)(ql,{body:o,buildImageProxyUrl:D,renderReferenceLink:O,repoContext:A}):(0,x.jsx)(`p`,{className:`console-detail-body-notloaded`,children:`Not loaded.`})}),e.isPr&&(0,x.jsx)(Jl,{title:`Changed files`,count:M,children:(0,x.jsx)(fu,{files:f,isLoading:p,error:m,onAddInlineComment:ee})}),(0,x.jsx)(Jl,{title:`Comments`,count:N,defaultCollapsed:e.isPr,children:(0,x.jsx)(pu,{comments:l,isLoading:u,error:d,now:w,buildImageProxyUrl:D,renderReferenceLink:O,repoContext:A})}),e.isPr&&(0,x.jsx)(Jl,{title:`Commits`,count:oe,defaultCollapsed:!0,children:(0,x.jsx)(gu,{commits:h,isLoading:g,error:_,now:w})}),!e.isPr&&S.map(e=>(0,x.jsx)(Tu,{pullRequest:e.pullRequest,body:e.pullRequest.summary?.body??``,bodyIsLoading:!1,files:e.files,filesAreLoading:e.filesAreLoading,filesError:e.filesError,commits:e.commits,commitsAreLoading:e.commitsAreLoading,commitsError:e.commitsError,now:w,buildImageProxyUrl:D,renderReferenceLink:O,onAddInlineComment:ee},e.pullRequest.url))]}),(0,x.jsxs)(`div`,{className:`console-detail-dock`,children:[(0,x.jsx)(`div`,{className:`console-detail-dock-composer`,children:T}),(0,x.jsx)(`div`,{className:`console-actionbar`,children:E})]})]})},Du=({onClose:e})=>(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>e(`close_not_planned`),children:`Close as not planned`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>e(`close`),children:`Close`})]}),Ou=({onDeleteAllComments:e})=>{let[t,n]=(0,y.useState)(!1);return(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>n(e=>!e),children:`⚠`}),t&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>{e(),n(!1)},children:`Delete All Comments`})]})},ku=({isManualTriage:e,onSetNextActionDate:t})=>(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1hour`),children:`+1 hour`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_3hours`),children:`+3 hours`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1day`),children:`+1 day`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1week`),children:e?`+1 week and skip`:`+1 week`})]}),Au=[{action:`unnecessary`,label:`Unnecessary`,variant:`unneeded`},{action:`totally_wrong`,label:`Totally wrong`,variant:`wrong`},{action:`request_changes`,label:`Reject`,variant:`reject`},{action:`approve_and_merge`,label:`Approve & Merge`,variant:`approve`}],ju=`Reject needs an inline comment on the diff.`,Mu=({onReview:e,rejectEnabled:t})=>(0,x.jsxs)(`div`,{className:`console-op-group console-op-group-review`,children:[!t&&(0,x.jsx)(`p`,{className:`console-op-requirement`,children:ju}),Au.map(n=>{let r=n.action===`request_changes`&&!t;return(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-${n.variant}`,disabled:r,onClick:()=>e(n.action),children:n.label},n.action)})]}),Nu=({onSetDependedIssueUrl:e})=>{let[t,n]=(0,y.useState)(!1),[r,i]=(0,y.useState)(``),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(null);return(0,x.jsxs)(`div`,{className:`console-op-group`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>{n(e=>!e),c(null)},title:`Rare actions`,children:`⋯`}),t&&e!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`input`,{type:`url`,className:`console-settings-modal-input`,placeholder:`Depended issue URL`,value:r,onChange:e=>i(e.target.value),disabled:a}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:async()=>{if(e!==null&&r.trim()!==``){o(!0),c(null);try{await e(r.trim()),i(``),n(!1)}catch(e){c(e instanceof Error?e.message:`Failed to set depended issue URL`)}finally{o(!1)}}},disabled:a||r.trim()===``,children:a?`...`:`Set Depended Issue`})]}),s!==null&&(0,x.jsx)(`p`,{className:`console-settings-modal-error`,children:s})]})},Pu=(e,t)=>{let n=t.toLowerCase();return e.find(e=>e.name.toLowerCase()===n)??null},Fu=({statusOptions:e,onSetStatus:t,onSetInTmuxByHuman:n})=>{let r=li.map(t=>({name:t,option:Pu(e,t)})).filter(e=>e.option!==null);return r.length===0?null:(0,x.jsx)(`div`,{className:`console-op-group`,children:r.map(({name:e,option:r})=>{let i=ae(r.color),a=e===ci;return(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,style:{color:i.fg,borderColor:i.border,backgroundColor:i.bg},onClick:()=>a?n(r):t(r),children:r.name},r.id)})})},Iu=({tab:e,hasPullRequest:t,rejectEnabled:n,statusOptions:r,handlers:i})=>(0,x.jsxs)(`div`,{className:`console-operation-bar`,children:[(0,x.jsx)(Nu,{onSetDependedIssueUrl:i.onSetDependedIssueUrl}),t&&(0,x.jsx)(Mu,{onReview:i.onReview,rejectEnabled:n}),(0,x.jsx)(ku,{isManualTriage:ui(e),onSetNextActionDate:i.onSetNextActionDate}),(0,x.jsx)(Fu,{statusOptions:r,onSetStatus:i.onSetStatus,onSetInTmuxByHuman:i.onSetInTmuxByHuman}),(0,x.jsxs)(`div`,{className:`console-op-group-bottom-row`,children:[(0,x.jsx)(Ou,{onDeleteAllComments:i.onDeleteAllComments}),(0,x.jsx)(Du,{onClose:i.onClose})]})]}),Lu=(e,t,n,r)=>{let i=t===null?void 0:e.peek(t),[a,o]=(0,y.useState)(i??r),[s,c]=(0,y.useState)(t!==null&&i===void 0),[l,u]=(0,y.useState)(null);return(0,y.useEffect)(()=>{if(t===null||n===null)return;let r=e.peek(t);if(r!==void 0){o(r),c(!1),u(null);return}let i=!1;return c(!0),u(null),e.load(t,n).then(e=>{i||(o(e),c(!1))}).catch(e=>{i||(u(e instanceof Error?e.message:String(e)),c(!1))}),()=>{i=!0}},[e,t,n]),{data:a,isLoading:s,error:l}},Ru=[],zu=[],Bu=[],Vu=[],Hu={state:`open`,merged:!1,isPullRequest:!1,title:``},Uu={found:!1,isConflicted:!1,mergeableStatus:`UNKNOWN`,isPassedAllCiJob:!1,isCiStateSuccess:!1,isBranchOutOfDate:!1,missingRequiredCheckNames:[]},Q=(e,t)=>{let n=t===null?null:`${t.repo}#${t.number}`,r=t===null?null:t.url,i=t?.isPr??!1,a=Lu(e.body,n,r,``),o=Lu(e.state,n,r,Hu),s=Lu(e.comments,n,r,Ru),c=Lu(e.files,i?n:null,i?r:null,zu),l=Lu(e.commits,i?n:null,i?r:null,Bu),u=Lu(e.prStatus,i?n:null,i?r:null,Uu),d=!i&&(t?.relatedOpenPullRequestUrls.length??0)>0,f=Lu(e.relatedPrs,d?n:null,d?r:null,Vu),[p,m]=(0,y.useState)([]);return(0,y.useEffect)(()=>{if(i||f.data.length===0){m([]);return}let t=!1,n=f.data.map(e=>({pullRequest:e,files:zu,filesAreLoading:!0,filesError:null,commits:Bu,commitsAreLoading:!0,commitsError:null}));m(n);let r=(e,n)=>{t||m(t=>t.map(t=>t.pullRequest.url===e?{...t,...n}:t))};for(let t of f.data){let n=t.url;e.files.load(n,t.url).then(e=>r(t.url,{files:e,filesAreLoading:!1})).catch(e=>r(t.url,{filesAreLoading:!1,filesError:e instanceof Error?e.message:String(e)})),e.commits.load(n,t.url).then(e=>r(t.url,{commits:e,commitsAreLoading:!1})).catch(e=>r(t.url,{commitsAreLoading:!1,commitsError:e instanceof Error?e.message:String(e)}))}return()=>{t=!0}},[e,i,f.data]),{state:o.data,body:a.data,bodyIsLoading:a.isLoading,bodyError:a.error,comments:s.data,commentsAreLoading:s.isLoading,commentsError:s.error,files:c.data,filesAreLoading:c.isLoading,filesError:c.error,commits:l.data,commitsAreLoading:l.isLoading,commitsError:l.error,stateError:o.error,pullRequestStatus:i?u.data:null,pullRequestStatusError:i?u.error:null,relatedPullRequests:p,relatedPullRequestsError:i?null:f.error}},Wu=e=>JSON.stringify([e.author,e.createdAt,e.body]),Gu=(e,t)=>{let n=new Set(e.map(Wu));return[...e,...t.filter(e=>!n.has(Wu(e)))]},Ku=({href:e,fallbackText:t,state:n})=>{if(n===null||n.title.trim()===``)return(0,x.jsx)(`a`,{className:`console-markdown-reference console-markdown-reference-plain`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:t});let r=Qa(e);return(0,x.jsxs)(`a`,{className:`console-markdown-reference`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:[(0,x.jsx)(de,{...eo(n)}),(0,x.jsx)(`span`,{className:`console-markdown-reference-title`,children:n.title}),r!==null&&(0,x.jsxs)(`span`,{className:`console-markdown-reference-number`,children:[`#`,r.number]})]})},qu=(e,t)=>{let[n,r]=(0,y.useState)(()=>e.peek(t)??null);return(0,y.useEffect)(()=>{let n=e.peek(t);if(n!==void 0){r(n);return}let i=!1;return r(null),e.load(t,t).then(e=>{i||r(e)}).catch(()=>{i||r(null)}),()=>{i=!0}},[e,t]),n},Ju=({cache:e,href:t,fallbackText:n})=>{let r=qu(e,t);return(0,x.jsx)(Ku,{href:t,fallbackText:n,state:r})},Yu=e=>({itemUrl:e.url,projectItemId:e.projectItemId,itemNumber:e.number,repo:e.repo,isPr:e.isPr}),Xu=(e,t,n,r,i)=>({...Yu(t),apiPath:$i,requestBody:na(e,t,n,r,i)}),Zu=(e,t,n,r)=>({...Yu(t),apiPath:ea,requestBody:ra(e,t,n,r)}),Qu=(e,t)=>({...Yu(t),apiPath:ta,requestBody:ia(e,t)}),$u=({tab:e,item:t,caches:n,operations:r,pjcode:i,statusOptions:a,storyColors:o,storyName:s,overlayStatus:c,now:l,initialCommentDraft:u,onCommentDraftChange:d,onQueueAction:f})=>{let p=Q(n,t),m=(0,y.useCallback)(e=>ro(e,t.url),[t.url]),h=(0,y.useCallback)((e,t)=>(0,x.jsx)(Ju,{cache:n.state,href:e,fallbackText:t}),[n.state]),g=t.isPr||t.relatedOpenPullRequestUrls.length>0||p.relatedPullRequests.length>0,[_,v]=(0,y.useState)([]),b=(0,y.useCallback)(async(e,t,n,r)=>{v(i=>[...i,{path:e,line:t,side:n,body:r}])},[]),[S,C]=(0,y.useState)([]),w=(0,y.useCallback)(async e=>{let n=await r.addComment(t,e);return C(e=>[...e,n]),n},[t,r]),T={onReview:e=>{let n=t.isPr?t.url:p.relatedPullRequests[0]?.pullRequest.url??t.relatedOpenPullRequestUrls[0]??t.url,a=e===`request_changes`?_:[];f({kind:{type:`review`,action:e},item:t,commit:()=>r.reviewPullRequest(t,n,e,a),offline:i==null?void 0:Xu(i,t,n,e,a)})},onSetNextActionDate:e=>{f({kind:{type:`next_action_date`,action:e},item:t,commit:()=>r.setNextActionDate(t,e),offline:i==null?void 0:Zu(i,t,e)})},onSetStory:e=>{f({kind:{type:`set_story`,optionName:e.name},item:t,commit:()=>r.setStory(t,e),offline:i==null?void 0:Zu(i,t,`set_story`,{storyOptionId:e.id})})},onSetStatus:e=>{f({kind:{type:`set_status`,optionName:e.name},item:t,commit:()=>r.setStatus(t,e),offline:i==null?void 0:Zu(i,t,`set_status`,{statusName:e.name})})},onSetInTmuxByHuman:e=>{f({kind:{type:`set_in_tmux_by_human`,optionName:e.name},item:t,commit:()=>r.setInTmuxByHuman(t,e),offline:i==null?void 0:Qu(i,t)})},onClose:e=>{f({kind:{type:`close`,action:e},item:t,commit:()=>r.closeIssue(t,e),offline:i==null?void 0:Zu(i,t,e)})},onOkAndAwaitingWorkspace:e=>{f({kind:{type:`ok_and_awaiting_workspace`},item:t,commit:()=>r.okAndMoveToAwaitingWorkspace(t,e)})},onDeleteAllComments:()=>{f({kind:{type:`delete_all_comments`},item:t,commit:()=>r.deleteAllComments(t)})},onSetDependedIssueUrl:i==null?null:async e=>{await r.setDependedIssueUrl(t,e)}},E=a.find(e=>e.name===`Awaiting Workspace`)??null,D=E===null?void 0:async e=>{let t=await w(e);return d?.(``),T.onSetStatus(E),t},O=s??(t.story.trim()===``?null:t.story),ee=O===null?null:A(o,O);return(0,x.jsx)(Eu,{item:t,storyName:O,storyColorEnum:ee,overlayStatus:c,statusOptions:a,state:p.state,stateError:p.stateError,body:p.body,bodyIsLoading:p.bodyIsLoading,bodyError:p.bodyError,comments:Gu(p.comments,S),commentsAreLoading:p.commentsAreLoading,commentsError:p.commentsError,files:p.files,filesAreLoading:p.filesAreLoading,filesError:p.filesError,commits:p.commits,commitsAreLoading:p.commitsAreLoading,commitsError:p.commitsError,pullRequestStatus:p.pullRequestStatus,pullRequestStatusError:p.pullRequestStatusError,relatedPullRequests:p.relatedPullRequests,relatedPullRequestsError:p.relatedPullRequestsError,now:l,buildImageProxyUrl:m,renderReferenceLink:h,onAddInlineComment:b,commentComposer:(0,x.jsx)(Xa,{initiallyOpen:!0,initialDraft:u,onSubmit:w,onDraftChange:d,onOkAndAwaitingWorkspace:E===null?void 0:()=>T.onOkAndAwaitingWorkspace(E),onSubmitAndMoveToAwaitingWorkspace:D,onUploadFile:e=>r.uploadAttachment(t,e)}),operationBar:(0,x.jsx)(Iu,{tab:e,item:t,hasPullRequest:g,rejectEnabled:_.length>0,statusOptions:a,handlers:T})})},ed=()=>{let e={};for(let t of D)e[t.name]=0;return e},td=`console`,nd=()=>{let e=fa(),t=Ri(),n=ur(),r=n.status===`on`?n.snapshot:null,{snapshots:i,isLoading:a,error:o}=Pa(e,r),{timerMode:s,projectMinutes:c,isOpen:l,draftTimerMode:u,draftProjectMinutes:d,openSettings:f,closeSettings:p,saveSettings:m,toggleDraftTimerMode:h,changeDraftMinutes:g}=Ba(),{pjcodes:_,workflowImprovementIssueUrl:v,isLoading:b}=pa(),{isTimerExpired:C}=ha(e),w=ua(e??td),E=ma(e),O=(0,y.useMemo)(()=>{let e=ed();for(let t of D){let n=i[t.name];n!==null&&(t.name===`stories`?e[t.name]=n.stories.filter(e=>e.color!==`GRAY`).length:e[t.name]=Ji(n.items,Xi(w.overlay,n.generatedAt),t.name))}return e},[i,w.overlay]),ee=Wi(e,O),{activeTab:k,selectedItemKey:A,openItem:ie,closeItem:M,selectTab:ae}=ee,N=(0,y.useRef)(new Map),oe=(0,y.useCallback)(e=>{A!==null&&(e?N.current.set(A,e):N.current.delete(A))},[A]),P=ji(r),F=oa(e,k,w,P),I=Di(),[se,ce]=(0,y.useState)(()=>Date.now());(0,y.useEffect)(()=>{let e=setInterval(()=>{ce(Date.now())},1e3);return()=>{clearInterval(e)}},[]);let[le,ue]=(0,y.useState)(()=>navigator.onLine);(0,y.useEffect)(()=>{let e=()=>ue(!0),t=()=>ue(!1);return window.addEventListener(`online`,e),window.addEventListener(`offline`,t),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,t)}},[]);let[de,L]=(0,y.useState)(new Map),[fe,pe]=(0,y.useState)(new Map),[me,ge]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{if(!(!le||I.offlineActions.length===0))for(let e of I.offlineActions)de.has(e.id)||me.has(e.id)||(L(t=>new Map(t).set(e.id,null)),P.client.fetchIssueState(e.itemUrl).then(t=>{L(n=>new Map(n).set(e.id,t)),e.isPr&&(pe(t=>new Map(t).set(e.id,null)),P.client.fetchPullRequestStatus(e.itemUrl).then(t=>{pe(n=>new Map(n).set(e.id,t))}).catch(e=>{console.warn(`Failed to fetch PR status for offline action:`,e)}))}).catch(t=>{console.warn(`Failed to fetch current state for offline action:`,t),ge(t=>new Set(t).add(e.id))}))},[le,I.offlineActions,P.client,de,me]);let[_e,ve]=(0,y.useState)(!1),ye=(0,y.useCallback)(async e=>{ve(!0);try{await I.confirmOfflineAction(e)}finally{ve(!1)}},[I]),be=(0,y.useMemo)(()=>I.offlineActions.map(e=>{let t=de.get(e.id)??null,n=fe.get(e.id)??null,r=me.has(e.id);return{id:e.id,message:e.message,color:e.color,itemNumber:e.itemNumber,isPr:e.isPr,currentTitle:r?null:t?.title??null,currentState:r||t===null?null:t.merged?`closed`:t.state,currentPrStatus:n,fetchError:r}}),[I.offlineActions,de,fe,me]),xe=i[k],Se=(0,y.useMemo)(()=>xe===null?[]:Yi(xe.items,Xi(w.overlay,xe.generatedAt),k),[xe,w.overlay,k]),Ce=(0,y.useMemo)(()=>Se.map(e=>Ki(e)),[Se]),we=xe?.storyOrder??[],Te=(0,y.useMemo)(()=>j(Se,w.overlay,we,xe?.generatedAt??null),[Se,w.overlay,we,xe]),Ee=xe?.storyColors??{},De=xe?.statusOptions??[],Oe=xe?.agentOptions??[],ke=xe?.generatedAt??null,Ae=xe?.fromCache??!1,[je,Me]=(0,y.useState)(null),Ne=(0,y.useMemo)(()=>A===null||xe===null?null:xe.items.find(e=>e.projectItemId===A)??null,[A,xe]);Ii(P,Ne,Se),(0,y.useEffect)(()=>{A!==null&&window.scrollTo({top:0})},[A]),(0,y.useEffect)(()=>{if(e===null&&s&&_.length>0){let e=za(_,null,c);e!==null&&Va(`/projects/${e}`)}},[e,s,_,c]);let Pe=O[k],Fe=(0,y.useRef)({tab:k,count:Pe});(0,y.useEffect)(()=>{let e=Fe.current;if(Fe.current={tab:k,count:Pe},e.tab===k&&e.count>0&&Pe===0){let e=zi(k,O);e!==null&&(ae(e),M())}},[k,Pe,O,ae,M]);let Ie=Ne===null?null:Zi(w.overlay,Ne,i[k]?.generatedAt??null),Le=Ne===null?null:re(Ne,w.overlay,i[k]?.generatedAt??null),Re=(0,y.useCallback)(e=>{let t=Ua(Ce,e);t===null?M():ie(t)},[Ce,ie,M]),ze=(0,y.useCallback)(t=>{if(n.status===`on`){I.showError(`Airplane mode`,`This action requires a network connection. Turn off airplane mode and try again.`);return}let r=Ki(t.item);I.enqueue({message:gi(t.kind,t.item,k),color:mi(t.kind),commit:t.commit,offline:t.offline,advance:()=>{if(hi(t.kind,k)){if(s&&C(c[e??``]??0)){let t=za(_,e,c);t!==null&&Ha(`/projects/${t}`)}else Re(r)}}})},[I,k,Re,n.status,s,C,c,e,_]),Be=ya((0,y.useCallback)(e=>{if(A===null||e===null)return;let t=e===`next`?Wa(Ce,A):Ga(Ce,A);t!==null&&ie(t)},[A,Ce,ie])),[Ve,He]=(0,y.useState)(()=>localStorage.getItem(`console-story-show-gray`)===`true`),Ue=(0,y.useCallback)(()=>{He(e=>{let t=!e;return localStorage.setItem(`console-story-show-gray`,String(t)),t})},[]),We=i.stories,Ge=We?.stories??[],Ke=je!==null&&je.generatedAt===We?.generatedAt?je.stories:Ge,qe=We?.defaultNameWithOwner??null,Je=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);if(qe===null)throw Error(`No repository configured for this project.`);await Hr({pjcode:e,title:n,storyOptionId:t,nameWithOwner:qe})},[e,qe]),Ye=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await Wr({pjcode:e,storyOptionId:t,direction:n});let r=Ke.findIndex(e=>e.storyOptionId===t);if(r!==-1){let e=r+(n===`up`?-1:1);if(e>=0&&e<Ke.length){let t=[...Ke],n=t[r];t[r]=t[e],t[e]=n,Me({generatedAt:We?.generatedAt,stories:t})}}},[e,Ke,We?.generatedAt]),Xe=(0,y.useCallback)(async t=>{if(e===null)throw Error(`No project specified in the URL path.`);await Ir({pjcode:e,storyName:t})},[e]),[Ze,Qe]=(0,y.useState)({}),[$e,et]=(0,y.useState)(null),[tt,nt]=(0,y.useState)({}),rt=(0,y.useCallback)((t,n)=>{let r=Ke.find(e=>e.storyOptionId===t)?.color;if(et(t),Qe(e=>({...e,[t]:n})),nt(e=>{let n={...e};return delete n[t],n}),e===null||qe===null){Qe(e=>r===void 0?e:{...e,[t]:r}),nt(e=>({...e,[t]:`No project or repository configured.`})),et(e=>e===t?null:e);return}Vr({pjcode:e,storyOptionId:t,newColor:n,nameWithOwner:qe}).catch(e=>{Qe(e=>r===void 0?e:{...e,[t]:r}),nt(n=>({...n,[t]:e instanceof Error?e.message:String(e)}))}).finally(()=>{et(e=>e===t?null:e)})},[e,qe,Ke]),it=(0,y.useCallback)(async t=>{if(e===null)throw Error(`No project specified in the URL path.`);await Jr({pjcode:e,storyOptionId:t}),Me({generatedAt:We?.generatedAt,stories:Ke.filter(e=>e.storyOptionId!==t)})},[e,Ke,We?.generatedAt]),at=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await Xr({pjcode:e,storyOptionId:t,newName:n});let r=Ke.map(e=>e.storyOptionId===t?{...e,storyName:n}:e);Me({generatedAt:We?.generatedAt,stories:r})},[e,Ke,We?.generatedAt]);return(0,x.jsxs)(`main`,{className:`console-app`,children:[I.pending!==null&&(0,x.jsx)(Ln,{message:I.pending.message,color:I.pending.color,remainingSeconds:I.pending.remainingSeconds,progress:I.pending.progress,onUndo:I.undo}),I.error!==null&&(0,x.jsx)(Rn,{title:I.error.message,message:`Operation failed: ${I.error.reason}`,onDismiss:I.dismissError}),(0,x.jsx)(In,{actions:be,isOnline:le,isConfirming:_e,onConfirm:ye,onDiscard:I.discardOfflineAction}),E.isOpen&&(0,x.jsx)(S,{value:E.inputValue,onChange:E.changeInput,isLoading:E.isLoading,isSaving:E.isSaving,error:E.error,onSave:E.save,onClose:E.close}),(0,x.jsx)(te,{activeTab:k,counts:O,pjcode:e,pjcodes:_,generatedAt:ke,fromCache:Ae,tabHref:ee.tabHref,onSelectTab:ee.selectTab,onSelectProject:e=>Ha(`/projects/${e}`),settingsButton:(0,x.jsxs)(x.Fragment,{children:[e!==null&&(0,x.jsx)(`button`,{type:`button`,className:`console-tab-settings-button`,"aria-label":`Open project settings`,onClick:E.open,children:`⚙`}),(0,x.jsx)(ne,{isOpen:l,timerMode:u,projectMinutes:d,pjcodes:_,isLoadingPjcodes:b,onOpen:f,onToggleTimerMode:h,onChangeMinutes:g,onSave:m,onClose:p})]}),airplaneModeEnabled:t.airplaneMode,airplaneModeStatus:n.status,airplaneModeProgress:n.progress,airplaneModeCapturedAt:r?.capturedAt??null,airplaneModeFailures:n.failures,onAirplaneModeStartSync:n.startSync,onAirplaneModeTurnOff:n.turnOff,workflowImprovementIssueUrl:v}),(0,x.jsx)(T,{timerEndsAt:xe?.timerEndsAt??null,timerTotalSeconds:xe?.timerTotalSeconds??null,now:se}),k===`stories`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(jn,{stories:Ke,isLoading:a,error:o,showGray:Ve,onCreateIssue:Je,onAddStory:Xe,onSelectColor:rt,onToggleGray:Ue,onReorderStory:Ye,onDeleteStory:it,onRenameStory:at,optimisticColors:Ze,colorChangeInFlight:$e,colorErrors:tt})}):Ne===null?k===`queued`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(he,{rows:Te,storyColors:Ee,statusOptions:De,agentOptions:Oe,activeItemId:null,isLoading:a,error:o,onSelectItem:e=>ee.openItem(e.projectItemId)})}):(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(R,{rows:Te,storyColors:Ee,statusOptions:De,activeItemId:null,now:se,isLoading:a,error:o,onSelectItem:e=>ee.openItem(e.projectItemId)})}):(0,x.jsx)(`div`,{className:`console-detail-screen`,ref:Be,children:(0,x.jsx)($u,{tab:k,item:Ne,caches:P,operations:F,pjcode:e,statusOptions:De,storyColors:Ee,storyName:Le,overlayStatus:Ie,now:se,initialCommentDraft:N.current.get(Ne.projectItemId)??``,onCommentDraftChange:oe,onQueueAction:ze},Ne.projectItemId)})]})};`serviceWorker`in navigator&&navigator.serviceWorker.register(`/sw.js`).catch(e=>{console.warn(`Service worker registration failed:`,e)});var rd=document.getElementById(`root`);if(rd===null)throw Error(`Root container #root not found`);(0,b.createRoot)(rd).render((0,x.jsx)(y.StrictMode,{children:(0,x.jsx)(nd,{})}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>TDPM Console</title>
7
- <script type="module" crossorigin src="/assets/index-BnbaVJp1.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-DNFU14bb.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-BZz0VAuo.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "github-issue-tower-defence-management",
3
- "version": "2.36.0",
3
+ "version": "2.36.2",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {