github-issue-tower-defence-management 2.148.19 → 2.149.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/bin/adapter/entry-points/console/ui-dist/assets/{index-DfvjH9_G.js → index-BsWigavn.js} +2 -2
  3. package/bin/adapter/entry-points/console/ui-dist/index.html +1 -1
  4. package/bin/adapter/repositories/LocalStorageRepository.js +5 -2
  5. package/bin/adapter/repositories/LocalStorageRepository.js.map +1 -1
  6. package/bin/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.js +27 -15
  7. package/bin/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.js.map +1 -1
  8. package/bin/domain/entities/StoryObjectMap.js +15 -0
  9. package/bin/domain/entities/StoryObjectMap.js.map +1 -1
  10. package/bin/domain/usecases/ConflictedIssueRevertUseCase.js +1 -1
  11. package/bin/domain/usecases/ConflictedIssueRevertUseCase.js.map +1 -1
  12. package/bin/domain/usecases/HandleScheduledEventUseCase.js +22 -12
  13. package/bin/domain/usecases/HandleScheduledEventUseCase.js.map +1 -1
  14. package/bin/domain/usecases/NotifyFinishedIssuePreparationUseCase.js +1 -1
  15. package/bin/domain/usecases/NotifyFinishedIssuePreparationUseCase.js.map +1 -1
  16. package/bin/domain/usecases/RevertNotReadyReviewQueueIssueUseCase.js +1 -1
  17. package/bin/domain/usecases/RevertNotReadyReviewQueueIssueUseCase.js.map +1 -1
  18. package/bin/domain/usecases/RevertOrphanedPreparationUseCase.js +1 -1
  19. package/bin/domain/usecases/RevertOrphanedPreparationUseCase.js.map +1 -1
  20. package/bin/domain/usecases/SetNoStoryIssueToStoryUseCase.js +18 -12
  21. package/bin/domain/usecases/SetNoStoryIssueToStoryUseCase.js.map +1 -1
  22. package/bin/domain/usecases/SetWorkflowManagementIssueToStoryUseCase.js +32 -14
  23. package/bin/domain/usecases/SetWorkflowManagementIssueToStoryUseCase.js.map +1 -1
  24. package/bin/domain/usecases/resolveNextStepAgentDispatchRepetition.js +3 -1
  25. package/bin/domain/usecases/resolveNextStepAgentDispatchRepetition.js.map +1 -1
  26. package/package.json +1 -1
  27. package/types/adapter/repositories/LocalStorageRepository.d.ts.map +1 -1
  28. package/types/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.d.ts +2 -0
  29. package/types/adapter/repositories/issue/ApiV3CheerioRestIssueRepository.d.ts.map +1 -1
  30. package/types/domain/entities/Issue.d.ts +1 -0
  31. package/types/domain/entities/Issue.d.ts.map +1 -1
  32. package/types/domain/entities/StoryObjectMap.d.ts +5 -1
  33. package/types/domain/entities/StoryObjectMap.d.ts.map +1 -1
  34. package/types/domain/usecases/HandleScheduledEventUseCase.d.ts.map +1 -1
  35. package/types/domain/usecases/SetNoStoryIssueToStoryUseCase.d.ts +0 -1
  36. package/types/domain/usecases/SetNoStoryIssueToStoryUseCase.d.ts.map +1 -1
  37. package/types/domain/usecases/SetWorkflowManagementIssueToStoryUseCase.d.ts +0 -1
  38. package/types/domain/usecases/SetWorkflowManagementIssueToStoryUseCase.d.ts.map +1 -1
  39. package/types/domain/usecases/resolveNextStepAgentDispatchRepetition.d.ts +1 -1
  40. package/types/domain/usecases/resolveNextStepAgentDispatchRepetition.d.ts.map +1 -1
package/README.md CHANGED
@@ -783,7 +783,7 @@ The issue repository keeps a single always-latest JSON file per project at `${XD
783
783
  - Clearing or rewriting the Depended Issue URL field through the repository replaces the matching issue in the memoized issue list and writes the new value into the cache file, so every later read in the same process (`getAllIssues`, `getStoryObjectMap`, `getAllOpened`, `getIssueByUrl`) sees the written value without another GitHub call. Issue objects handed out before the write keep the value they had.
784
784
  - The two-phase incremental fetch (shipped in v1.123.0) is live on the default branch and available via `npm install npm-cli-github-issue-tower-defence-management@latest`.
785
785
  - `ConvertCheckboxToIssueInStoryIssueUseCase` always fetches the latest story-issue body directly via `getIssueByUrl`, ensuring story bodies are never stale when converting checkboxes to issues.
786
- - Because the memoized list can be older than a value another client wrote a few seconds ago, the use cases that pick an item from that list and write its Story, Status or Agent first read that single item live through `get` (one item query, no list pagination) immediately before the write. The write is skipped, with a warning naming the changed field and both values, when a field that made the item eligible no longer holds its listed value or the item is no longer on the project; the next cycle evaluates the item again from fresh data. This applies to `SetNoStoryIssueToStoryUseCase` and `SetWorkflowManagementIssueToStoryUseCase` (Story), the default Agent write of `AgentDesignationLabelAdoptUseCase`, and the Status writes of `IssueNoStatusUpdateUseCase`, `ChangeStatusByStoryColorUseCase`, `QualityCheckAdvanceUseCase`, `ReopenedDoneIssueRevertUseCase`, `RevertNotReadyReviewQueueIssueUseCase` and the open-item recovery of `SetupTowerDefenceProjectUseCase`. `StartPreparationUseCase` re-reads each spawn candidate live through `get` rather than from the on-disk cache before moving it to Preparation.
786
+ - Because the memoized list can be older than a value another client wrote a few seconds ago, the use cases that pick an item from that list and write its Story, Status or Agent first read that single item live through `get` (one item query, no list pagination) immediately before the write. The write is skipped, with a warning naming the changed field and both values, when a field that made the item eligible no longer holds its listed value or the item is no longer on the project; the next cycle evaluates the item again from fresh data. This applies to `SetNoStoryIssueToStoryUseCase` and `SetWorkflowManagementIssueToStoryUseCase` (Story), the default Agent write of `AgentDesignationLabelAdoptUseCase`, and the Status writes of `IssueNoStatusUpdateUseCase`, `ChangeStatusByStoryColorUseCase`, `QualityCheckAdvanceUseCase`, `ReopenedDoneIssueRevertUseCase`, `RevertNotReadyReviewQueueIssueUseCase`, the open-item recovery of `SetupTowerDefenceProjectUseCase`, and the Todo by human Status write for an author-not-allowed issue in `StartPreparationUseCase`. `StartPreparationUseCase` re-reads each spawn candidate live through `get` rather than from the on-disk cache before moving it to Preparation.
787
787
 
788
788
  ## Migration Guide
789
789
 
@@ -88,6 +88,6 @@ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error
88
88
  `).map(e=>`> ${e}`).join(`
89
89
  `),nd=e=>e.split(`
90
90
  `).find(e=>e.trim()!==``)??``,rd=e=>`${e.author}:${e.createdAt}:${e.body}`,id=({comment:e,buildImageProxyUrl:t,renderReferenceLink:n,repoContext:r})=>{let i=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let e=i.current;if(!e)return;let t=e=>e.stopPropagation();return e.addEventListener(`click`,t),()=>e.removeEventListener(`click`,t)},[]),(0,x.jsx)(`div`,{ref:i,className:`console-comment-body-expanded`,children:(0,x.jsx)(Lu,{body:e.body,buildImageProxyUrl:t,renderReferenceLink:n,repoContext:r})})},ad=({comments:e,isLoading:t,error:n,now:r,buildImageProxyUrl:i,renderReferenceLink:a,repoContext:o,persistenceKey:s=null,issueUrl:c,issueTitle:l,storyEntries:u,agentOptions:d,onCreateIssueFromComment:f})=>{let[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(null),[_,v]=(0,y.useState)(()=>s==null?new Set:Tn(s)),b=e.length>0?rd(e[e.length-1]):null;(0,y.useEffect)(()=>{b!==null&&v(e=>new Set([...e,b]))},[b]),(0,y.useEffect)(()=>{s!=null&&En(s,_)},[s,_]);let S=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};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 C=!p&&e.length>1;return(0,x.jsxs)(`div`,{className:`console-comment-list`,children:[C&&(0,x.jsxs)(`button`,{type:`button`,className:`console-comment-show-all`,onClick:()=>{m(!0),v(t=>new Set([...t,...e.map(rd)]))},children:[`Show all `,e.length]}),e.map(e=>{let t=rd(e),n=_.has(t);return(0,x.jsxs)(`article`,{className:`console-comment${n?` is-expanded`:C?` console-comment--expandable`:``}`,children:[(0,x.jsxs)(`button`,{type:`button`,className:`console-comment-toggle`,onClick:()=>S(t),"aria-expanded":n,children:[(0,x.jsx)(`span`,{className:`console-comment-author`,children:e.author}),(0,x.jsx)(`span`,{className:`console-comment-time`,children:k(e.createdAt,r)}),!n&&(0,x.jsx)(`span`,{className:`console-comment-body-preview`,children:nd(e.body)})]}),f!==void 0&&(0,x.jsx)(`button`,{type:`button`,className:`console-comment-create-workflow-issue`,onClick:t=>{t.stopPropagation(),g(e)},title:`Create workflow improvement issue from this comment`,children:`+`}),n&&(0,x.jsx)(id,{comment:e,buildImageProxyUrl:i,renderReferenceLink:a,repoContext:o})]},t)}),h!==null&&f!==void 0&&(0,x.jsx)(fe,{storyEntries:u??[],agentOptions:d??[],onSubmit:f,onClose:()=>g(null),initialDraft:{title:``,body:(()=>{let e=td(h.body);return c!=null&&l!=null?`${c}\n\n${l}\n\n\n\n\n\n${e}`:l==null?e:`${l}\n\n\n\n\n\n${e}`})(),storyName:null,agentOptionId:null}})]})},od=e=>e.slice(0,7),sd=e=>e.split(`
91
- `)[0],cd=({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:sd(e.message)}),(0,x.jsx)(`span`,{className:`console-commit-sha`,children:od(e.sha)}),(0,x.jsx)(`span`,{className:`console-commit-author`,children:e.author}),(0,x.jsx)(`span`,{className:`console-commit-time`,children:k(e.authoredAt,r)})]},e.sha))}):(0,x.jsx)(`p`,{className:`console-commits-notloaded`,children:`Not loaded.`}),ld=({url:e,label:t=`Copy URL`})=>(0,x.jsx)(gu,{value:e,idleText:`Copy URL`,idleAriaLabel:t,copiedAriaLabel:`URL copied to clipboard`,className:`console-copy-url-button`}),ud=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}))},dd=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`,fd=({failures:e})=>e.length===0?null:(0,x.jsx)(`div`,{role:`alert`,className:`console-detail-fetch-error`,children:ud(e).map(e=>(0,x.jsxs)(`p`,{className:`console-detail-fetch-error-line`,children:[`Failed to load `,dd(e.sections),`:`,` `,e.message]},e.message))}),pd=({title:e,onTitleRename:t})=>{let[n,r]=(0,y.useState)(e),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(e),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(e);(0,y.useEffect)(()=>{let t=e!==f.current;f.current=e,!i&&t&&r(e)},[e,i]);let p=()=>{s(n),d(null),a(!0)},m=()=>{a(!1),d(null)},h=async()=>{let e=o.trim();if(e===``||e===n){a(!1);return}l(!0),d(null);try{await t(e),r(e),a(!1)}catch(e){d(e instanceof Error?e.message:`Failed to rename`)}finally{l(!1)}};return i?(0,x.jsxs)(`span`,{className:`console-detail-title-text console-detail-title-text--editing`,children:[(0,x.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&m()},disabled:c,className:`console-detail-title-input`,"aria-label":`Edit title`}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>void h(),disabled:c,className:`console-detail-title-save`,children:`Save`}),(0,x.jsx)(`button`,{type:`button`,onClick:m,disabled:c,className:`console-detail-title-cancel`,children:`Cancel`}),u!==null&&(0,x.jsx)(`span`,{className:`console-detail-title-error`,role:`alert`,children:u})]}):(0,x.jsxs)(`span`,{className:`console-detail-title-text`,children:[n,(0,x.jsx)(`button`,{type:`button`,onClick:p,className:`console-detail-title-edit`,"aria-label":`Edit title`,children:`Edit`})]})},md={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`}},hd=({mergeableStatus:e})=>{let t=md[e],n=ue(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})},gd=e=>{let t=ue(e);return{color:t.fg,borderColor:t.border,backgroundColor:t.bg}},_d=({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:gd(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:gd(`YELLOW`),title:`This branch is out of date with the base branch`,children:`Out of date`})]})},vd=({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=Ti(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)(hd,{mergeableStatus:e.mergeableStatus}),(0,x.jsx)(_d,{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)(ld,{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)(Ru,{title:`Description`,children:n?(0,x.jsx)(`p`,{className:`console-pr-body-loading`,children:`Loading description...`}):(0,x.jsx)(Lu,{body:p?.body??t,buildImageProxyUrl:u,renderReferenceLink:d,repoContext:h})}),(0,x.jsx)(Ru,{title:`Changed files`,count:g,children:(0,x.jsx)(ed,{files:r,isLoading:i,error:a,buildImageProxyUrl:u,onAddInlineComment:f})}),(0,x.jsx)(Ru,{title:`Commits`,count:_,defaultCollapsed:!0,children:(0,x.jsx)(cd,{commits:o,isLoading:s,error:c,now:l})})]})},yd=({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:ee,buildImageProxyUrl:E,renderReferenceLink:D,onAddInlineComment:O,onTitleRename:te,storyEntries:ne,agentOptions:j,onCreateIssueFromComment:M})=>{let N=a?.state??`open`,re=a?.merged??!1,ie=!e.isPr&&N===`closed`?`Closed`:null,ae=Ei(e.nameWithOwner)??void 0,P=ue(n),oe=r===null?e.status===null?null:{name:e.status,color:i.find(t=>t.name===e.status)?.color??`GRAY`}:r,se=oe===null?null:ue(oe.color),ce=p||m!==null?null:f.length,le=u||d!==null?null:l.length,F=g||_!==null?null:h.length,de=!u&&d===null&&l.length>0,fe=e=>{let t=Ti(e);return t===null?e:`PR #${t.number}`},pe=[{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 ${fe(e.pullRequest.url)}`,message:e.filesError},{section:`commits of ${fe(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)(Ee,{isPr:e.isPr,state:N,merged:re,isDraft:!1,stateReason:``}),te==null?(0,x.jsx)(`span`,{className:`console-detail-title-text`,children:e.title}):(0,x.jsx)(pd,{title:e.title,onTitleRename:te}),(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:[oe!==null&&se!==null&&(0,x.jsx)(`span`,{className:`console-detail-status-chip`,style:{color:se.fg,borderColor:se.border,backgroundColor:se.bg},children:oe.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:P.dot}}),t]}),e.isPr&&y?.found&&(0,x.jsx)(_d,{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:fe(e.pullRequest.url)}),(0,x.jsx)(_d,{isPassedAllCiJob:e.pullRequest.isPassedAllCiJob,isCiStateSuccess:e.pullRequest.isCiStateSuccess,isBranchOutOfDate:e.pullRequest.isBranchOutOfDate,missingRequiredCheckNames:e.pullRequest.missingRequiredCheckNames}),(0,x.jsx)(hd,{mergeableStatus:e.pullRequest.mergeableStatus})]},e.pullRequest.url)),I.map(e=>(0,x.jsx)(hd,{mergeableStatus:e.mergeableStatus},e.url)),ie!==null&&(0,x.jsx)(`span`,{className:`console-detail-closed-label`,children:ie})]}),(0,x.jsx)(fd,{failures:pe}),(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:A(e.createdAt),children:[`opened `,k(e.createdAt,w)]}),(0,x.jsx)(ld,{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)(Ru,{title:`Description`,defaultCollapsed:de,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)(Lu,{body:o,buildImageProxyUrl:E,renderReferenceLink:D,repoContext:ae}):(0,x.jsx)(`p`,{className:`console-detail-body-notloaded`,children:`Not loaded.`})},de?`desc-collapsed`:`desc-open`),e.isPr&&(0,x.jsx)(Ru,{title:`Changed files`,count:ce,children:(0,x.jsx)(ed,{files:f,isLoading:p,error:m,onAddInlineComment:O})}),(0,x.jsx)(Ru,{title:`Comments`,count:le,children:(0,x.jsx)(ad,{comments:l,isLoading:u,error:d,now:w,buildImageProxyUrl:E,renderReferenceLink:D,repoContext:ae,persistenceKey:e.url,issueUrl:e.url,issueTitle:e.title,storyEntries:ne,agentOptions:j,onCreateIssueFromComment:M})}),e.isPr&&(0,x.jsx)(Ru,{title:`Commits`,count:F,defaultCollapsed:!0,children:(0,x.jsx)(cd,{commits:h,isLoading:g,error:_,now:w})}),!e.isPr&&S.map(e=>(0,x.jsx)(vd,{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:E,renderReferenceLink:D,onAddInlineComment:O},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:ee})]})]})},bd=({className:e,ariaLabel:t,placeholder:n,currentOption:r,options:i,onSelect:a})=>{let o=(0,y.useRef)({ready:!1,currentOptionId:r?.id??null});return(0,y.useLayoutEffect)(()=>{o.current.ready=!0,o.current.currentOptionId=r?.id??null}),(0,x.jsxs)(`select`,{className:e,defaultValue:r?.id??``,onChange:e=>{if(!o.current.ready||e.target.value===(o.current.currentOptionId??``))return;let t=i.find(t=>t.id===e.target.value);t!==void 0&&a(t)},"aria-label":t,children:[(0,x.jsx)(`option`,{value:``,children:n}),i.map(e=>(0,x.jsx)(`option`,{value:e.id,children:e.name},e.id))]})},xd=({agentOptions:e,currentAgentName:t,onSetAgent:n})=>{if(e.length===0)return null;let r=t===null?null:e.find(e=>e.name===t)??null;return(0,x.jsx)(`div`,{className:`console-op-group`,children:(0,x.jsx)(bd,{className:`console-agent-select`,ariaLabel:`Set agent`,placeholder:`— agent —`,currentOption:r,options:e,onSelect:n},r?.id??`none`)})},Sd=({onClose:e,onCommentAndClose:t,onOkAndClose:n,isDraftEmpty:r})=>{let[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),c=async e=>{if(!(e===void 0||i)){a(!0),s(null);try{await e()}catch(e){s(e instanceof Error?e.message:`failed to post`)}finally{a(!1)}}};return(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`}),n!==void 0&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,disabled:i,onClick:()=>{c(n)},children:`OK & Close`}),t!==void 0&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,disabled:i||r===!0,onClick:()=>{c(t)},children:`Comment & Close`}),o!==null&&(0,x.jsx)(`span`,{role:`alert`,className:`console-op-comment-close-error`,children:o})]})},Cd=({onDeleteAllComments:e,onDeleteStory:t,storyNameForDeletion:n})=>{let[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=()=>{e(),i(!1)},f=()=>{o(!0),u(null)},p=async e=>{if(t){c(!0),u(null);try{await t(e)}catch(e){u(e instanceof Error?e.message:String(e)),c(!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:()=>i(e=>!e),children:`⚠`}),r&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:d,children:`Delete All Comments`}),t!=null&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:f,disabled:a,children:`Delete Story`})]}),a&&(0,x.jsxs)(`div`,{className:`console-story-delete-confirm`,role:`dialog`,"aria-modal":`true`,"aria-label":`Confirm story deletion`,children:[(0,x.jsxs)(`p`,{className:`console-story-delete-confirm-message`,children:[`Delete story option "`,n,`" from the GitHub custom field?`]}),l!==null&&(0,x.jsx)(`p`,{role:`alert`,className:`console-list-error`,children:l}),(0,x.jsxs)(`div`,{className:`console-story-delete-confirm-actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>void p(!0),disabled:s,children:s?`Deleting…`:`Delete with child tasks`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>void p(!1),disabled:s,children:s?`Deleting…`:`Keep child tasks`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>{o(!1),u(null)},disabled:s,children:`Cancel`})]})]})]})},wd=({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:`+1h`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_3hours`),children:`+3h`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_6hours`),children:`+6h`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1day`),children:`+1d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_2days`),children:`+2d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_3days`),children:`+3d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_5days`),children:`+5d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1week`),children:e?`+1w skip`:`+1w`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1month`),children:`+1mo`})]}),Td=[{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`}],Ed=`Reject needs an inline comment on the diff.`,Dd=({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:Ed}),Td.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)})]}),Od=({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 console-op-group-rare-actions`,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})]})},kd=(e,t)=>{let n=t.toLowerCase();return e.find(e=>e.name.toLowerCase()===n)??null},Ad=({statusOptions:e,onSetStatus:t,onSetInTmuxByHuman:n})=>{let r=xe.map(t=>({name:t,option:kd(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=ue(r.color),a=e===ye;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)})})},jd=({storyOptions:e,currentStoryName:t,onSetStory:n})=>{if(e.length===0)return null;let r=t===null?null:e.find(e=>e.name===t)??null;return(0,x.jsx)(`div`,{className:`console-op-group`,children:(0,x.jsx)(bd,{className:`console-story-select`,ariaLabel:`Set story`,placeholder:`— story —`,currentOption:r,options:e,onSelect:n},r?.id??`none`)})},Md=({tab:e,hasPullRequest:t,rejectEnabled:n,statusOptions:r,storyOptions:i,currentStoryName:a,agentOptions:o,currentAgentName:s,handlers:c,storyNameForDeletion:l,onCommentAndClose:u,onOkAndClose:d,isDraftEmpty:f})=>{let[p,m]=(0,y.useState)(!1);return(0,x.jsxs)(`div`,{className:`console-operation-bar`,children:[t&&(0,x.jsx)(Dd,{onReview:c.onReview,rejectEnabled:n}),(0,x.jsx)(wd,{isManualTriage:Se(e),onSetNextActionDate:c.onSetNextActionDate}),(0,x.jsx)(Ad,{statusOptions:r,onSetStatus:c.onSetStatus,onSetInTmuxByHuman:c.onSetInTmuxByHuman}),p&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(jd,{storyOptions:i,currentStoryName:a,onSetStory:c.onSetStory}),(0,x.jsx)(xd,{agentOptions:o,currentAgentName:s,onSetAgent:c.onSetAgent})]}),(0,x.jsxs)(`div`,{className:`console-op-group-bottom-row`,children:[(0,x.jsxs)(`div`,{className:`console-op-group-left-pair`,children:[(i.length>0||o.length>0)&&(0,x.jsx)(`div`,{className:`console-op-group`,children:(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>m(e=>!e),title:`Change agent or story`,children:`⚙`})}),(0,x.jsx)(Od,{onSetDependedIssueUrl:c.onSetDependedIssueUrl}),(0,x.jsx)(Cd,{onDeleteAllComments:c.onDeleteAllComments,onDeleteStory:c.onDeleteStory,storyNameForDeletion:l})]}),(0,x.jsx)(Sd,{onClose:c.onClose,onCommentAndClose:u,onOkAndClose:d,isDraftEmpty:f})]})]})},Nd=(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}},Pd=[],Fd=[],Id=[],Ld=[],Rd={state:`open`,merged:!1,isPullRequest:!1,title:``},zd={found:!1,isConflicted:!1,mergeableStatus:`UNKNOWN`,isPassedAllCiJob:!1,isCiStateSuccess:!1,isBranchOutOfDate:!1,missingRequiredCheckNames:[]},Bd=(e,t,n)=>{let r=t===null?null:`${t.repo}#${t.number}`,i=t===null?null:t.url,a=t?.isPr??!1,o=Nd(e.body,r,i,``),s=Nd(e.state,r,i,Rd),c=Nd(e.comments,r,i,Pd),l=Nd(e.files,a?r:null,a?i:null,Fd),u=Nd(e.commits,a?r:null,a?i:null,Id),d=Nd(e.prStatus,a?r:null,a?i:null,zd),f=!a&&((t?.relatedOpenPullRequestUrls.length??0)>0||n===`prs`),p=Nd(e.relatedPrs,f?r:null,f?i:null,Ld),[m,h]=(0,y.useState)([]);return(0,y.useEffect)(()=>{if(a||p.data.length===0){h([]);return}let t=!1,n=p.data.map(e=>({pullRequest:e,files:Fd,filesAreLoading:!0,filesError:null,commits:Id,commitsAreLoading:!0,commitsError:null}));h(n);let r=(e,n)=>{t||h(t=>t.map(t=>t.pullRequest.url===e?{...t,...n}:t))};for(let t of p.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,a,p.data]),{state:s.data,body:o.data,bodyIsLoading:o.isLoading,bodyError:o.error,comments:c.data,commentsAreLoading:c.isLoading,commentsError:c.error,files:l.data,filesAreLoading:l.isLoading,filesError:l.error,commits:u.data,commitsAreLoading:u.isLoading,commitsError:u.error,stateError:s.error,pullRequestStatus:a?d.data:null,pullRequestStatusError:a?d.error:null,relatedPullRequests:m,relatedPullRequestsError:a?null:p.error}},Vd=e=>JSON.stringify([e.author,e.createdAt,e.body]),Hd=(e,t)=>{let n=new Set(e.map(Vd));return[...e,...t.filter(e=>!n.has(Vd(e)))]},Ud=({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=Ti(e);return(0,x.jsxs)(`a`,{className:`console-markdown-reference`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:[(0,x.jsx)(Ee,{...Di(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]})]})},Wd=(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},Gd=({cache:e,href:t,fallbackText:n})=>{let r=Wd(e,t);return(0,x.jsx)(Ud,{href:t,fallbackText:n,state:r})},Kd=e=>({itemUrl:e.url,projectItemId:e.projectItemId,itemNumber:e.number,repo:e.repo,isPr:e.isPr}),qd=(e,t,n,r,i)=>({...Kd(t),apiPath:wr,requestBody:Dr(e,t,n,r,i)}),Jd=(e,t,n,r)=>({...Kd(t),apiPath:Tr,requestBody:Or(e,t,n,r)}),Yd=(e,t)=>({...Kd(t),apiPath:Er,requestBody:kr(e,t)}),Xd=({tab:e,item:t,caches:n,operations:r,pjcode:i,statusOptions:a,storyOptions:o,agentOptions:s,storyColors:c,storyName:l,overlayStatus:u,now:d,initialCommentDraft:f,onCommentDraftChange:p,onQueueAction:m,onCommentError:h,onDeleteStory:g,storyNameForDeletion:_,storyEntries:v,onCreateIssueFromComment:b})=>{let S=Bd(n,t,e),C=(0,y.useCallback)(e=>Ai(e,t.url),[t.url]),w=(0,y.useCallback)((e,t)=>(0,x.jsx)(Gd,{cache:n.state,href:e,fallbackText:t}),[n.state]),T=t.isPr||t.relatedOpenPullRequestUrls.length>0||S.relatedPullRequests.length>0,[ee,E]=(0,y.useState)([]),D=(0,y.useCallback)(async(e,t,n,r)=>{E(i=>[...i,{path:e,line:t,side:n,body:r}])},[]),[O,te]=(0,y.useState)([]),k=(0,y.useCallback)(async e=>{let n=await r.addComment(t,e);return te(e=>[...e,n]),n},[t,r]),ne={onReview:e=>{let n=t.isPr?t.url:S.relatedPullRequests[0]?.pullRequest.url??t.relatedOpenPullRequestUrls[0]??t.url,a=e===`request_changes`?ee:[];m({kind:{type:`review`,action:e},item:t,commit:()=>r.reviewPullRequest(t,n,e,a),offline:i==null?void 0:qd(i,t,n,e,a),overlayPatch:{done:!0}})},onSetNextActionDate:e=>{m({kind:{type:`next_action_date`,action:e},item:t,commit:()=>r.setNextActionDate(t,e),offline:i==null?void 0:Jd(i,t,e),overlayPatch:{done:!0}})},onSetStory:e=>{m({kind:{type:`set_story`,optionName:e.name},item:t,commit:()=>r.setStory(t,e),offline:i==null?void 0:Jd(i,t,`set_story`,{storyOptionId:e.id}),overlayPatch:{done:!0,story:{name:e.name,color:e.color}}})},onSetAgent:e=>{m({kind:{type:`set_agent`,optionName:e.name},item:t,commit:()=>r.setAgent(t,e),offline:i==null?void 0:Jd(i,t,`set_agent`,{agentOptionId:e.id}),overlayPatch:{done:!0}})},onSetStatus:e=>{m({kind:{type:`set_status`,optionName:e.name},item:t,commit:()=>r.setStatus(t,e),offline:i==null?void 0:Jd(i,t,`set_status`,{statusName:e.name}),overlayPatch:{done:!0,status:{name:e.name,color:e.color}}})},onSetInTmuxByHuman:e=>{m({kind:{type:`set_in_tmux_by_human`,optionName:e.name},item:t,commit:()=>r.setInTmuxByHuman(t,e),offline:i==null?void 0:Yd(i,t),overlayPatch:{done:!0,status:{name:e.name,color:e.color}}})},onClose:e=>{m({kind:{type:`close`,action:e},item:t,commit:()=>r.closeIssue(t,e),offline:i==null?void 0:Jd(i,t,e),overlayPatch:{done:!0}})},onOkAndAwaitingWorkspace:e=>{m({kind:{type:`ok_and_awaiting_workspace`},item:t,commit:()=>r.okAndMoveToAwaitingWorkspace(t,e),overlayPatch:{done:!0,status:{name:e.name,color:e.color}}})},onDeleteAllComments:()=>{m({kind:{type:`delete_all_comments`},item:t,commit:()=>r.deleteAllComments(t)})},onDeleteStory:g??null,onSetDependedIssueUrl:i==null?null:async e=>{await r.setDependedIssueUrl(t,e)}},A=(0,y.useCallback)(async e=>{await r.issueRename(t,e)},[t,r]),j=a.find(e=>e.name===`Awaiting Workspace`)??null,M=j===null?void 0:async e=>(p?.(``),await new Promise((n,i)=>{let a=!1,o=(e,t)=>{throw h===void 0?console.error(e,t):h(e,String(t)),i(t),t};m({kind:{type:`set_status`,optionName:j.name},item:t,commit:async()=>{if(a){try{await r.setStatus(t,j)}catch(e){o(`Comment already posted, but retrying the move to Awaiting Workspace status failed: ${String(e)}`,e)}try{await r.onAfterMoveToAwaitingWorkspace?.()}catch(e){let t=`Comment posted and status set to Awaiting Workspace, but a post-success refresh action failed: ${String(e)}`;h===void 0?console.error(t,e):h(t,String(e))}return}try{let i=await r.addCommentAndMoveToAwaitingWorkspace(t,e,j);te(e=>[...e,i]),n(i)}catch(e){a=!0,o(`Comment may already be posted; moving to Awaiting Workspace status failed: ${String(e)}`,e)}},overlayPatch:{done:!0,status:{name:j.name,color:j.color}}})})),N=(0,y.useRef)(``),[re,ie]=(0,y.useState)((f??``).trim().length===0),ae=(0,y.useCallback)(e=>{N.current=e,ie(e.trim().length===0),p?.(e)},[p]),P=async e=>{await k(e),ne.onClose(`close`)},oe=async()=>{let e=N.current.trim();e.length!==0&&await P(e)},se=async()=>{m({kind:{type:`ok_and_close`},item:t,commit:async()=>{await r.addComment(t,`ok`),await r.closeIssue(t,`close`)},offline:i==null?void 0:Jd(i,t,`close`),overlayPatch:{done:!0}})},ce=l??(t.story.trim()===``?null:t.story),le=ce===null?null:I(c,ce);return(0,x.jsx)(yd,{item:t,storyName:ce,storyColorEnum:le,overlayStatus:u,statusOptions:a,state:S.state,stateError:S.stateError,body:S.body,bodyIsLoading:S.bodyIsLoading,bodyError:S.bodyError,comments:Hd(S.comments,O),commentsAreLoading:S.commentsAreLoading,commentsError:S.commentsError,files:S.files,filesAreLoading:S.filesAreLoading,filesError:S.filesError,commits:S.commits,commitsAreLoading:S.commitsAreLoading,commitsError:S.commitsError,pullRequestStatus:S.pullRequestStatus,pullRequestStatusError:S.pullRequestStatusError,relatedPullRequests:S.relatedPullRequests,relatedPullRequestsError:S.relatedPullRequestsError,now:d,buildImageProxyUrl:C,renderReferenceLink:w,onAddInlineComment:D,onTitleRename:A,storyEntries:v,agentOptions:s,onCreateIssueFromComment:b,commentComposer:(0,x.jsx)(Ci,{initiallyOpen:!0,initialDraft:f,onSubmit:k,onDraftChange:ae,onOkAndAwaitingWorkspace:j===null?void 0:()=>ne.onOkAndAwaitingWorkspace(j),onSubmitAndMoveToAwaitingWorkspace:M,onUploadFile:e=>r.uploadAttachment(t,e)}),operationBar:(0,x.jsx)(Md,{tab:e,item:t,hasPullRequest:T,rejectEnabled:ee.length>0,statusOptions:a,storyOptions:o,currentStoryName:ce,agentOptions:s,currentAgentName:t.agent,handlers:ne,storyNameForDeletion:_,onCommentAndClose:oe,onOkAndClose:se,isDraftEmpty:re})})},Zd=()=>{let e={};for(let t of j)e[t.name]=0;return e},Qd=`console`,$d=async(e,t,{title:n,storyName:r,agentOptionId:i,body:a,files:o})=>{let s=await Xt({pjcode:e,title:n,storyName:r??``,nameWithOwner:t,agentOptionId:i??null,body:a??null});if(o.length>0){let t=await Bt({pjcode:e,url:s,body:(await Promise.all(o.map(async t=>{let n=Ht(new Uint8Array(await t.arrayBuffer()));return H({pjcode:e,url:s,fileName:t.name,contentBase64:n})}))).join(`
91
+ `)[0],cd=({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:sd(e.message)}),(0,x.jsx)(`span`,{className:`console-commit-sha`,children:od(e.sha)}),(0,x.jsx)(`span`,{className:`console-commit-author`,children:e.author}),(0,x.jsx)(`span`,{className:`console-commit-time`,children:k(e.authoredAt,r)})]},e.sha))}):(0,x.jsx)(`p`,{className:`console-commits-notloaded`,children:`Not loaded.`}),ld=({url:e,label:t=`Copy URL`})=>(0,x.jsx)(gu,{value:e,idleText:`Copy URL`,idleAriaLabel:t,copiedAriaLabel:`URL copied to clipboard`,className:`console-copy-url-button`}),ud=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}))},dd=e=>e.length<=1?e.join(``):`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`,fd=({failures:e})=>e.length===0?null:(0,x.jsx)(`div`,{role:`alert`,className:`console-detail-fetch-error`,children:ud(e).map(e=>(0,x.jsxs)(`p`,{className:`console-detail-fetch-error-line`,children:[`Failed to load `,dd(e.sections),`:`,` `,e.message]},e.message))}),pd=({title:e,onTitleRename:t})=>{let[n,r]=(0,y.useState)(e),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(e),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null),f=(0,y.useRef)(e);(0,y.useEffect)(()=>{let t=e!==f.current;f.current=e,!i&&t&&r(e)},[e,i]);let p=()=>{s(n),d(null),a(!0)},m=()=>{a(!1),d(null)},h=async()=>{let e=o.trim();if(e===``||e===n){a(!1);return}l(!0),d(null);try{await t(e),r(e),a(!1)}catch(e){d(e instanceof Error?e.message:`Failed to rename`)}finally{l(!1)}};return i?(0,x.jsxs)(`span`,{className:`console-detail-title-text console-detail-title-text--editing`,children:[(0,x.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?h():e.key===`Escape`&&m()},disabled:c,className:`console-detail-title-input`,"aria-label":`Edit title`}),(0,x.jsx)(`button`,{type:`button`,onClick:()=>void h(),disabled:c,className:`console-detail-title-save`,children:`Save`}),(0,x.jsx)(`button`,{type:`button`,onClick:m,disabled:c,className:`console-detail-title-cancel`,children:`Cancel`}),u!==null&&(0,x.jsx)(`span`,{className:`console-detail-title-error`,role:`alert`,children:u})]}):(0,x.jsxs)(`span`,{className:`console-detail-title-text`,children:[n,(0,x.jsx)(`button`,{type:`button`,onClick:p,className:`console-detail-title-edit`,"aria-label":`Edit title`,children:`Edit`})]})},md={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`}},hd=({mergeableStatus:e})=>{let t=md[e],n=ue(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})},gd=e=>{let t=ue(e);return{color:t.fg,borderColor:t.border,backgroundColor:t.bg}},_d=({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:gd(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:gd(`YELLOW`),title:`This branch is out of date with the base branch`,children:`Out of date`})]})},vd=({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=Ti(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)(hd,{mergeableStatus:e.mergeableStatus}),(0,x.jsx)(_d,{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)(ld,{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)(Ru,{title:`Description`,children:n?(0,x.jsx)(`p`,{className:`console-pr-body-loading`,children:`Loading description...`}):(0,x.jsx)(Lu,{body:p?.body??t,buildImageProxyUrl:u,renderReferenceLink:d,repoContext:h})}),(0,x.jsx)(Ru,{title:`Changed files`,count:g,children:(0,x.jsx)(ed,{files:r,isLoading:i,error:a,buildImageProxyUrl:u,onAddInlineComment:f})}),(0,x.jsx)(Ru,{title:`Commits`,count:_,defaultCollapsed:!0,children:(0,x.jsx)(cd,{commits:o,isLoading:s,error:c,now:l})})]})},yd=({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:ee,buildImageProxyUrl:E,renderReferenceLink:D,onAddInlineComment:O,onTitleRename:te,storyEntries:ne,agentOptions:j,onCreateIssueFromComment:M})=>{let N=a?.state??`open`,re=a?.merged??!1,ie=!e.isPr&&N===`closed`?`Closed`:null,ae=Ei(e.nameWithOwner)??void 0,P=ue(n),oe=r===null?e.status===null?null:{name:e.status,color:i.find(t=>t.name===e.status)?.color??`GRAY`}:r,se=oe===null?null:ue(oe.color),ce=p||m!==null?null:f.length,le=u||d!==null?null:l.length,F=g||_!==null?null:h.length,de=!u&&d===null&&l.length>0,fe=e=>{let t=Ti(e);return t===null?e:`PR #${t.number}`},pe=[{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 ${fe(e.pullRequest.url)}`,message:e.filesError},{section:`commits of ${fe(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)(Ee,{isPr:e.isPr,state:N,merged:re,isDraft:!1,stateReason:``}),te==null?(0,x.jsx)(`span`,{className:`console-detail-title-text`,children:e.title}):(0,x.jsx)(pd,{title:e.title,onTitleRename:te}),(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:[oe!==null&&se!==null&&(0,x.jsx)(`span`,{className:`console-detail-status-chip`,style:{color:se.fg,borderColor:se.border,backgroundColor:se.bg},children:oe.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:P.dot}}),t]}),e.isPr&&y?.found&&(0,x.jsx)(_d,{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:fe(e.pullRequest.url)}),(0,x.jsx)(_d,{isPassedAllCiJob:e.pullRequest.isPassedAllCiJob,isCiStateSuccess:e.pullRequest.isCiStateSuccess,isBranchOutOfDate:e.pullRequest.isBranchOutOfDate,missingRequiredCheckNames:e.pullRequest.missingRequiredCheckNames}),(0,x.jsx)(hd,{mergeableStatus:e.pullRequest.mergeableStatus})]},e.pullRequest.url)),I.map(e=>(0,x.jsx)(hd,{mergeableStatus:e.mergeableStatus},e.url)),ie!==null&&(0,x.jsx)(`span`,{className:`console-detail-closed-label`,children:ie})]}),(0,x.jsx)(fd,{failures:pe}),(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:A(e.createdAt),children:[`opened `,k(e.createdAt,w)]}),(0,x.jsx)(ld,{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)(Ru,{title:`Description`,defaultCollapsed:de,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)(Lu,{body:o,buildImageProxyUrl:E,renderReferenceLink:D,repoContext:ae}):(0,x.jsx)(`p`,{className:`console-detail-body-notloaded`,children:`Not loaded.`})},de?`desc-collapsed`:`desc-open`),e.isPr&&(0,x.jsx)(Ru,{title:`Changed files`,count:ce,children:(0,x.jsx)(ed,{files:f,isLoading:p,error:m,onAddInlineComment:O})}),(0,x.jsx)(Ru,{title:`Comments`,count:le,children:(0,x.jsx)(ad,{comments:l,isLoading:u,error:d,now:w,buildImageProxyUrl:E,renderReferenceLink:D,repoContext:ae,persistenceKey:e.url,issueUrl:e.url,issueTitle:e.title,storyEntries:ne,agentOptions:j,onCreateIssueFromComment:M})}),e.isPr&&(0,x.jsx)(Ru,{title:`Commits`,count:F,defaultCollapsed:!0,children:(0,x.jsx)(cd,{commits:h,isLoading:g,error:_,now:w})}),!e.isPr&&S.map(e=>(0,x.jsx)(vd,{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:E,renderReferenceLink:D,onAddInlineComment:O},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:ee})]})]})},bd=({className:e,ariaLabel:t,placeholder:n,currentOption:r,options:i,onSelect:a})=>{let o=(0,y.useRef)({ready:!1,currentOptionId:r?.id??null});return(0,y.useLayoutEffect)(()=>{o.current.ready=!0,o.current.currentOptionId=r?.id??null}),(0,x.jsxs)(`select`,{className:e,defaultValue:r?.id??``,onChange:e=>{if(!o.current.ready||e.target.value===(o.current.currentOptionId??``))return;let t=i.find(t=>t.id===e.target.value);t!==void 0&&a(t)},"aria-label":t,children:[(0,x.jsx)(`option`,{value:``,children:n}),i.map(e=>(0,x.jsx)(`option`,{value:e.id,children:e.name},e.id))]})},xd=({agentOptions:e,currentAgentName:t,onSetAgent:n})=>{if(e.length===0)return null;let r=t===null?null:e.find(e=>e.name===t)??null;return(0,x.jsx)(`div`,{className:`console-op-group`,children:(0,x.jsx)(bd,{className:`console-agent-select`,ariaLabel:`Set agent`,placeholder:`— agent —`,currentOption:r,options:e,onSelect:n},r?.id??`none`)})},Sd=({onClose:e,onCommentAndClose:t,onOkAndClose:n,isDraftEmpty:r})=>{let[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)(null),c=async e=>{if(!(e===void 0||i)){a(!0),s(null);try{await e()}catch(e){s(e instanceof Error?e.message:`failed to post`)}finally{a(!1)}}};return(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`}),n!==void 0&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,disabled:i,onClick:()=>{c(n)},children:`OK & Close`}),t!==void 0&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,disabled:i||r===!0,onClick:()=>{c(t)},children:`Comment & Close`}),o!==null&&(0,x.jsx)(`span`,{role:`alert`,className:`console-op-comment-close-error`,children:o})]})},Cd=({onDeleteAllComments:e,onDeleteStory:t,storyNameForDeletion:n})=>{let[r,i]=(0,y.useState)(!1),[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=()=>{e(),i(!1)},f=()=>{o(!0),u(null)},p=async e=>{if(t){c(!0),u(null);try{await t(e)}catch(e){u(e instanceof Error?e.message:String(e)),c(!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:()=>i(e=>!e),children:`⚠`}),r&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:d,children:`Delete All Comments`}),t!=null&&(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:f,disabled:a,children:`Delete Story`})]}),a&&(0,x.jsxs)(`div`,{className:`console-story-delete-confirm`,role:`dialog`,"aria-modal":`true`,"aria-label":`Confirm story deletion`,children:[(0,x.jsxs)(`p`,{className:`console-story-delete-confirm-message`,children:[`Delete story option "`,n,`" from the GitHub custom field?`]}),l!==null&&(0,x.jsx)(`p`,{role:`alert`,className:`console-list-error`,children:l}),(0,x.jsxs)(`div`,{className:`console-story-delete-confirm-actions`,children:[(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>void p(!0),disabled:s,children:s?`Deleting…`:`Delete with child tasks`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-danger`,onClick:()=>void p(!1),disabled:s,children:s?`Deleting…`:`Keep child tasks`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>{o(!1),u(null)},disabled:s,children:`Cancel`})]})]})]})},wd=({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:`+1h`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_3hours`),children:`+3h`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_6hours`),children:`+6h`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1day`),children:`+1d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_2days`),children:`+2d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_3days`),children:`+3d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_5days`),children:`+5d`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1week`),children:e?`+1w skip`:`+1w`}),(0,x.jsx)(`button`,{type:`button`,className:`console-op-button console-op-button-snooze`,onClick:()=>t(`snooze_1month`),children:`+1mo`})]}),Td=[{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`}],Ed=`Reject needs an inline comment on the diff.`,Dd=({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:Ed}),Td.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)})]}),Od=({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 console-op-group-rare-actions`,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})]})},kd=(e,t)=>{let n=t.toLowerCase();return e.find(e=>e.name.toLowerCase()===n)??null},Ad=({statusOptions:e,onSetStatus:t,onSetInTmuxByHuman:n})=>{let r=xe.map(t=>({name:t,option:kd(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=ue(r.color),a=e===ye;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)})})},jd=({storyOptions:e,currentStoryName:t,onSetStory:n})=>{if(e.length===0)return null;let r=t===null?null:e.find(e=>e.name===t)??null;return(0,x.jsx)(`div`,{className:`console-op-group`,children:(0,x.jsx)(bd,{className:`console-story-select`,ariaLabel:`Set story`,placeholder:`— story —`,currentOption:r,options:e,onSelect:n},r?.id??`none`)})},Md=({tab:e,hasPullRequest:t,rejectEnabled:n,statusOptions:r,storyOptions:i,currentStoryName:a,agentOptions:o,currentAgentName:s,handlers:c,storyNameForDeletion:l,onCommentAndClose:u,onOkAndClose:d,isDraftEmpty:f})=>{let[p,m]=(0,y.useState)(!1);return(0,x.jsxs)(`div`,{className:`console-operation-bar`,children:[t&&(0,x.jsx)(Dd,{onReview:c.onReview,rejectEnabled:n}),(0,x.jsx)(wd,{isManualTriage:Se(e),onSetNextActionDate:c.onSetNextActionDate}),(0,x.jsx)(Ad,{statusOptions:r,onSetStatus:c.onSetStatus,onSetInTmuxByHuman:c.onSetInTmuxByHuman}),p&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(jd,{storyOptions:i,currentStoryName:a,onSetStory:c.onSetStory}),(0,x.jsx)(xd,{agentOptions:o,currentAgentName:s,onSetAgent:c.onSetAgent})]}),(0,x.jsxs)(`div`,{className:`console-op-group-bottom-row`,children:[(0,x.jsxs)(`div`,{className:`console-op-group-left-pair`,children:[(i.length>0||o.length>0)&&(0,x.jsx)(`div`,{className:`console-op-group`,children:(0,x.jsx)(`button`,{type:`button`,className:`console-op-button`,onClick:()=>m(e=>!e),title:`Change agent or story`,children:`⚙`})}),(0,x.jsx)(Od,{onSetDependedIssueUrl:c.onSetDependedIssueUrl}),(0,x.jsx)(Cd,{onDeleteAllComments:c.onDeleteAllComments,onDeleteStory:c.onDeleteStory,storyNameForDeletion:l})]}),(0,x.jsx)(Sd,{onClose:c.onClose,onCommentAndClose:u,onOkAndClose:d,isDraftEmpty:f})]})]})},Nd=(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}},Pd=[],Fd=[],Id=[],Ld=[],Rd={state:`open`,merged:!1,isPullRequest:!1,title:``},zd={found:!1,isConflicted:!1,mergeableStatus:`UNKNOWN`,isPassedAllCiJob:!1,isCiStateSuccess:!1,isBranchOutOfDate:!1,missingRequiredCheckNames:[]},Bd=(e,t,n)=>{let r=t===null?null:`${t.repo}#${t.number}`,i=t===null?null:t.url,a=t?.isPr??!1,o=Nd(e.body,r,i,``),s=Nd(e.state,r,i,Rd),c=Nd(e.comments,r,i,Pd),l=Nd(e.files,a?r:null,a?i:null,Fd),u=Nd(e.commits,a?r:null,a?i:null,Id),d=Nd(e.prStatus,a?r:null,a?i:null,zd),f=!a&&((t?.relatedOpenPullRequestUrls.length??0)>0||n===`prs`),p=Nd(e.relatedPrs,f?r:null,f?i:null,Ld),[m,h]=(0,y.useState)([]);return(0,y.useEffect)(()=>{if(a||p.data.length===0){h([]);return}let t=!1,n=p.data.map(e=>({pullRequest:e,files:Fd,filesAreLoading:!0,filesError:null,commits:Id,commitsAreLoading:!0,commitsError:null}));h(n);let r=(e,n)=>{t||h(t=>t.map(t=>t.pullRequest.url===e?{...t,...n}:t))};for(let t of p.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,a,p.data]),{state:s.data,body:o.data,bodyIsLoading:o.isLoading,bodyError:o.error,comments:c.data,commentsAreLoading:c.isLoading,commentsError:c.error,files:l.data,filesAreLoading:l.isLoading,filesError:l.error,commits:u.data,commitsAreLoading:u.isLoading,commitsError:u.error,stateError:s.error,pullRequestStatus:a?d.data:null,pullRequestStatusError:a?d.error:null,relatedPullRequests:m,relatedPullRequestsError:a?null:p.error}},Vd=e=>JSON.stringify([e.author,e.createdAt,e.body]),Hd=(e,t)=>{let n=new Set(e.map(Vd));return[...e,...t.filter(e=>!n.has(Vd(e)))]},Ud=({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=Ti(e);return(0,x.jsxs)(`a`,{className:`console-markdown-reference`,href:e,target:`_blank`,rel:`noopener noreferrer`,children:[(0,x.jsx)(Ee,{...Di(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]})]})},Wd=(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},Gd=({cache:e,href:t,fallbackText:n})=>{let r=Wd(e,t);return(0,x.jsx)(Ud,{href:t,fallbackText:n,state:r})},Kd=e=>({itemUrl:e.url,projectItemId:e.projectItemId,itemNumber:e.number,repo:e.repo,isPr:e.isPr}),qd=(e,t,n,r,i)=>({...Kd(t),apiPath:wr,requestBody:Dr(e,t,n,r,i)}),Jd=(e,t,n,r)=>({...Kd(t),apiPath:Tr,requestBody:Or(e,t,n,r)}),Yd=(e,t)=>({...Kd(t),apiPath:Er,requestBody:kr(e,t)}),Xd=(e,t,n)=>{e===void 0?console.error(t,n):e(t,String(n))},Zd=({tab:e,item:t,caches:n,operations:r,pjcode:i,statusOptions:a,storyOptions:o,agentOptions:s,storyColors:c,storyName:l,overlayStatus:u,now:d,initialCommentDraft:f,onCommentDraftChange:p,onQueueAction:m,onCommentError:h,onDeleteStory:g,storyNameForDeletion:_,storyEntries:v,onCreateIssueFromComment:b})=>{let S=Bd(n,t,e),C=(0,y.useCallback)(e=>Ai(e,t.url),[t.url]),w=(0,y.useCallback)((e,t)=>(0,x.jsx)(Gd,{cache:n.state,href:e,fallbackText:t}),[n.state]),T=t.isPr||t.relatedOpenPullRequestUrls.length>0||S.relatedPullRequests.length>0,[ee,E]=(0,y.useState)([]),D=(0,y.useCallback)(async(e,t,n,r)=>{E(i=>[...i,{path:e,line:t,side:n,body:r}])},[]),[O,te]=(0,y.useState)([]),k=(0,y.useCallback)(async e=>{let n=await r.addComment(t,e);return te(e=>[...e,n]),n},[t,r]),ne={onReview:e=>{let n=t.isPr?t.url:S.relatedPullRequests[0]?.pullRequest.url??t.relatedOpenPullRequestUrls[0]??t.url,a=e===`request_changes`?ee:[];m({kind:{type:`review`,action:e},item:t,commit:()=>r.reviewPullRequest(t,n,e,a),offline:i==null?void 0:qd(i,t,n,e,a),overlayPatch:{done:!0}})},onSetNextActionDate:e=>{m({kind:{type:`next_action_date`,action:e},item:t,commit:()=>r.setNextActionDate(t,e),offline:i==null?void 0:Jd(i,t,e),overlayPatch:{done:!0}})},onSetStory:e=>{m({kind:{type:`set_story`,optionName:e.name},item:t,commit:()=>r.setStory(t,e),offline:i==null?void 0:Jd(i,t,`set_story`,{storyOptionId:e.id}),overlayPatch:{done:!0,story:{name:e.name,color:e.color}}})},onSetAgent:e=>{m({kind:{type:`set_agent`,optionName:e.name},item:t,commit:()=>r.setAgent(t,e),offline:i==null?void 0:Jd(i,t,`set_agent`,{agentOptionId:e.id}),overlayPatch:{done:!0}})},onSetStatus:e=>{m({kind:{type:`set_status`,optionName:e.name},item:t,commit:()=>r.setStatus(t,e),offline:i==null?void 0:Jd(i,t,`set_status`,{statusName:e.name}),overlayPatch:{done:!0,status:{name:e.name,color:e.color}}})},onSetInTmuxByHuman:e=>{m({kind:{type:`set_in_tmux_by_human`,optionName:e.name},item:t,commit:()=>r.setInTmuxByHuman(t,e),offline:i==null?void 0:Yd(i,t),overlayPatch:{done:!0,status:{name:e.name,color:e.color}}})},onClose:e=>{m({kind:{type:`close`,action:e},item:t,commit:()=>r.closeIssue(t,e),offline:i==null?void 0:Jd(i,t,e),overlayPatch:{done:!0}})},onOkAndAwaitingWorkspace:e=>{m({kind:{type:`ok_and_awaiting_workspace`},item:t,commit:()=>r.okAndMoveToAwaitingWorkspace(t,e),overlayPatch:{done:!0,status:{name:e.name,color:e.color}}})},onDeleteAllComments:()=>{m({kind:{type:`delete_all_comments`},item:t,commit:()=>r.deleteAllComments(t)})},onDeleteStory:g??null,onSetDependedIssueUrl:i==null?null:async e=>{await r.setDependedIssueUrl(t,e)}},A=(0,y.useCallback)(async e=>{await r.issueRename(t,e)},[t,r]),j=a.find(e=>e.name===`Awaiting Workspace`)??null,M=j===null?void 0:async e=>(p?.(``),await new Promise((n,i)=>{let a=!1,o=(e,t)=>{throw Xd(h,e,t),i(t),t};m({kind:{type:`set_status`,optionName:j.name},item:t,commit:async()=>{if(a){try{await r.setStatus(t,j)}catch(e){o(`Comment already posted, but retrying the move to Awaiting Workspace status failed: ${String(e)}`,e)}try{await r.onAfterMoveToAwaitingWorkspace?.()}catch(e){Xd(h,`Comment posted and status set to Awaiting Workspace, but a post-success refresh action failed: ${String(e)}`,e)}return}try{let i=await r.addCommentAndMoveToAwaitingWorkspace(t,e,j);te(e=>[...e,i]),n(i)}catch(e){a=!0,o(`Comment may already be posted; moving to Awaiting Workspace status failed: ${String(e)}`,e)}},overlayPatch:{done:!0,status:{name:j.name,color:j.color}}})})),N=(0,y.useRef)(``),[re,ie]=(0,y.useState)((f??``).trim().length===0),ae=(0,y.useCallback)(e=>{N.current=e,ie(e.trim().length===0),p?.(e)},[p]),P=async e=>{await k(e),ne.onClose(`close`)},oe=async()=>{let e=N.current.trim();e.length!==0&&await P(e)},se=async()=>{m({kind:{type:`ok_and_close`},item:t,commit:async()=>{await r.addComment(t,`ok`),await r.closeIssue(t,`close`)},offline:i==null?void 0:Jd(i,t,`close`),overlayPatch:{done:!0}})},ce=l??(t.story.trim()===``?null:t.story),le=ce===null?null:I(c,ce);return(0,x.jsx)(yd,{item:t,storyName:ce,storyColorEnum:le,overlayStatus:u,statusOptions:a,state:S.state,stateError:S.stateError,body:S.body,bodyIsLoading:S.bodyIsLoading,bodyError:S.bodyError,comments:Hd(S.comments,O),commentsAreLoading:S.commentsAreLoading,commentsError:S.commentsError,files:S.files,filesAreLoading:S.filesAreLoading,filesError:S.filesError,commits:S.commits,commitsAreLoading:S.commitsAreLoading,commitsError:S.commitsError,pullRequestStatus:S.pullRequestStatus,pullRequestStatusError:S.pullRequestStatusError,relatedPullRequests:S.relatedPullRequests,relatedPullRequestsError:S.relatedPullRequestsError,now:d,buildImageProxyUrl:C,renderReferenceLink:w,onAddInlineComment:D,onTitleRename:A,storyEntries:v,agentOptions:s,onCreateIssueFromComment:b,commentComposer:(0,x.jsx)(Ci,{initiallyOpen:!0,initialDraft:f,onSubmit:k,onDraftChange:ae,onOkAndAwaitingWorkspace:j===null?void 0:()=>ne.onOkAndAwaitingWorkspace(j),onSubmitAndMoveToAwaitingWorkspace:M,onUploadFile:e=>r.uploadAttachment(t,e)}),operationBar:(0,x.jsx)(Md,{tab:e,item:t,hasPullRequest:T,rejectEnabled:ee.length>0,statusOptions:a,storyOptions:o,currentStoryName:ce,agentOptions:s,currentAgentName:t.agent,handlers:ne,storyNameForDeletion:_,onCommentAndClose:oe,onOkAndClose:se,isDraftEmpty:re})})},Qd=()=>{let e={};for(let t of j)e[t.name]=0;return e},$d=`console`,ef=async(e,t,{title:n,storyName:r,agentOptionId:i,body:a,files:o})=>{let s=await Xt({pjcode:e,title:n,storyName:r??``,nameWithOwner:t,agentOptionId:i??null,body:a??null});if(o.length>0){let t=await Bt({pjcode:e,url:s,body:(await Promise.all(o.map(async t=>{let n=Ht(new Uint8Array(await t.arrayBuffer()));return H({pjcode:e,url:s,fileName:t.name,contentBase64:n})}))).join(`
92
92
 
93
- `)});if(!t.posted)throw Error(t.error)}},ef=()=>{let e=qr(),t=gr(),n=bt(),r=n.status===`on`?n.snapshot:null,{snapshots:i,isLoading:a,error:o,refreshSingleTab:s}=nr(e,r),{timerMode:c,projectMinutes:l,isOpen:u,draftTimerMode:d,draftProjectMinutes:f,openSettings:p,closeSettings:m,saveSettings:h,toggleDraftTimerMode:g,changeDraftMinutes:_}=hi(),{pjcodes:v,projectUrls:b,fleetTaskCreateUrl:C,nameWithOwnerByPjcode:w,isLoading:ee}=Jr(),{isTimerExpired:E}=Qr(e),D=Gr(e??Qd),O=Zr(v),te=(0,y.useMemo)(()=>Vr(D.overlay,i),[D.overlay,i]),k=(0,y.useMemo)(()=>{let e=Zd();for(let t of j){let n=i[t.name];n!==null&&(t.name===`stories`?e[t.name]=n.stories.filter(e=>e.color!==`GRAY`).length:e[t.name]=Ir(n.items,te,t.name))}return e},[i,te]),ne=Cr(e,k,(0,y.useMemo)(()=>{let e=new Set;for(let t of j){let n=i[t.name];n!==null&&!n.fromCache&&e.add(t.name)}return e},[i]),(0,y.useMemo)(()=>{let e=Zd();for(let t of j){let n=i[t.name];n!==null&&(e[t.name]=t.name===`stories`?n.stories.filter(e=>e.color!==`GRAY`).length:n.items.length)}return e},[i])),{activeTab:A,selectedItemKey:M,openItem:N,closeItem:ie}=ne,ae=ui(ne.selectTab),{explicitlySelectedPjcode:P,notifyExplicitSelection:oe}=mr(e),ce=Yr((0,y.useCallback)(e=>{oe(e),fi(`/projects/${e}`)},[oe]));rr(e,A,v,a,c&&r===null);let F=(0,y.useRef)(new Map),ue=(0,y.useCallback)(e=>{M!==null&&(e?F.current.set(M,e):F.current.delete(M))},[M]),de=sr(r),pe=Mr(e,de,(0,y.useCallback)(()=>s(`queued`),[s])),I=Rn(),[R,he]=(0,y.useState)(()=>Date.now());(0,y.useEffect)(()=>{let e=setInterval(()=>{he(Date.now())},1e3);return()=>{clearInterval(e)}},[]);let[ge,_e]=(0,y.useState)(!1),[ve,ye]=(0,y.useState)(!1),[be,xe]=(0,y.useState)({title:``,body:null,storyName:null,agentOptionId:null}),[Se,Ce]=(0,y.useState)({title:``,body:null,storyName:null,agentOptionId:null}),[we,Te]=(0,y.useState)(()=>navigator.onLine);(0,y.useEffect)(()=>{let e=()=>Te(!0),t=()=>Te(!1);return window.addEventListener(`online`,e),window.addEventListener(`offline`,t),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,t)}},[]);let[Ee,De]=(0,y.useState)(new Map),[Oe,je]=(0,y.useState)(new Map),[Me,Pe]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{if(we&&I.offlineActions.length!==0)for(let e of I.offlineActions)Ee.has(e.id)||Me.has(e.id)||(De(t=>new Map(t).set(e.id,null)),de.client.fetchIssueState(e.itemUrl).then(t=>{De(n=>new Map(n).set(e.id,t)),e.isPr&&(je(t=>new Map(t).set(e.id,null)),de.client.fetchPullRequestStatus(e.itemUrl).then(t=>{je(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),Pe(t=>new Set(t).add(e.id))}))},[we,I.offlineActions,de.client,Ee,Me]);let[Fe,Ie]=(0,y.useState)(!1),Le=(0,y.useCallback)(async e=>{Ie(!0);try{await I.confirmOfflineAction(e)}finally{Ie(!1)}},[I]),Re=(0,y.useMemo)(()=>I.offlineActions.map(e=>{let t=Ee.get(e.id)??null,n=Oe.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,Ee,Oe,Me]),ze=i[A],Be=(0,y.useMemo)(()=>ze===null?[]:Lr(ze.items,te,A),[ze,te,A]),[Ve,Ue]=(0,y.useState)(null),We=(0,y.useMemo)(()=>{if(A!==`prs`)return{};let e={};for(let t of Be)t.agent!==null&&t.agent!==``&&(e[t.agent]=(e[t.agent]??0)+1);return e},[Be,A]);(0,y.useEffect)(()=>{A===`prs`&&Ve!==null&&(We[Ve]??0)===0&&Ue(null)},[We,Ve,A]);let Ge=(0,y.useMemo)(()=>A!==`prs`||Ve===null?Be:Be.filter(e=>e.agent===Ve),[Be,A,Ve]),Ke=(0,y.useMemo)(()=>Ge.map(e=>Pr(e)),[Ge]),Xe=ze?.storyOrder??[],Ze=(0,y.useMemo)(()=>me(Ge,D.overlay,Xe,ze?.generatedAt??null),[Ge,D.overlay,Xe,ze]),Qe=ze?.storyColors??{},$e=ze?.statusOptions??[],et=ze?.agentOptions??[],tt=ze?.storyOptions??[],nt=ze?.generatedAt??null,rt=ze?.fromCache??!1,[it,z]=(0,y.useState)(null),B=(0,y.useMemo)(()=>M===null||ze===null?null:ze.items.find(e=>e.projectItemId===M)??null,[M,ze]);pr(de,B,Be),(0,y.useEffect)(()=>{M!==null&&window.scrollTo({top:0})},[M]),(0,y.useEffect)(()=>{if(e===null&&c&&v.length>0){let e=se(v,null,l);e!==null&&pi(`/projects/${e}/todo-by-human`)}},[e,c,v,l]),mi(c,k.prs,k[`todo-by-human`],e,v,l,i.prs!==null,i[`todo-by-human`]!==null,i.prs?.fromCache??!1,i[`todo-by-human`]?.fromCache??!1,P),di(c,e,Ge,M,ne.openItem);let at=k[A],ot=(0,y.useRef)({tab:A,count:at});(0,y.useEffect)(()=>{let e=ot.current;if(ot.current={tab:A,count:at},e.tab===A&&e.count>0&&at===0){let e=_r(A,k);e!==null&&(ae(e),ie())}},[A,at,k,ae,ie]);let st=B===null?null:Rr(D.overlay,B,i[A]?.generatedAt??null),ct=B===null?null:L(B,D.overlay,i[A]?.generatedAt??null),lt=(0,y.useCallback)(e=>{let t=gi(Ke,e);t===null?ie():N(t)},[Ke,N,ie]),ut=(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=Pr(t.item),i=t.overlayPatch;I.enqueue({message:Cn(t.kind,t.item,A),color:xn(t.kind),commit:t.commit,offline:t.offline,revertAdvance:t.revertAdvance,optimistic:i===void 0?void 0:()=>D.patchOverlay(r,i,A),revertOptimistic:i===void 0?void 0:()=>D.revertOverlayEntry(r),advance:()=>{if(t.onAdvance?.(),!t.skipAdvance&&Sn(t.kind,A)){if(c&&E(l[e??``]??15)){let t=se(v,e,l);t!==null&&fi(`/projects/${t}/todo-by-human`)}else lt(r)}}})},[I,A,lt,n.status,D,c,E,l,e,v]),dt=li((0,y.useCallback)(e=>{if(M===null||e===null)return;let t=e===`next`?_i(Ke,M):vi(Ke,M);t!==null&&N(t)},[M,Ke,N])),[ft,pt]=(0,y.useState)(()=>localStorage.getItem(`console-story-show-gray`)===`true`),mt=(0,y.useCallback)(()=>{pt(e=>{let t=!e;return localStorage.setItem(`console-story-show-gray`,String(t)),t})},[]),ht=i.stories,gt=ht?.stories??[],_t=it!==null&&it.generatedAt===ht?.generatedAt?it.stories:gt,vt=ht?.defaultNameWithOwner??null,yt=vt===null?null:`https://github.com/${vt}/issues/new`,V=(0,y.useMemo)(()=>B===null||!B.labels.includes(`story`)?null:_t.find(e=>e.storyName===B.story)??null,[B,_t]),xt=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);if(vt===null)throw Error(`No repository configured for this project.`);await Xt({pjcode:e,title:n,storyName:t,nameWithOwner:vt})},[e,vt]),St=(0,y.useCallback)(({storyName:t,agentOptionId:n,title:r,body:i,files:a})=>{if(e===null||vt===null)return Promise.resolve();let o=e,s=vt,c={title:r,storyName:t,agentOptionId:n,body:i,files:a};return I.enqueue({message:`Task created — "${r}"`,color:`blue`,commit:()=>$d(o,s,c),advance:()=>{}}),Ce({title:``,body:null,storyName:null,agentOptionId:null}),Promise.resolve()},[e,vt,I]),Ct=(0,y.useCallback)(({title:t,body:n,storyName:r,agentOptionId:i,files:a})=>{if(C===null||e===null)return Promise.resolve();let o=C.match(/github\.com\/([^/]+\/[^/]+)/);if(o===null)return Promise.resolve();let s=o[1],c=e,l={title:t,storyName:r,agentOptionId:i,body:n,files:a};return I.enqueue({message:`Task created — "${t}"`,color:`blue`,commit:()=>$d(c,s,l),advance:()=>{}}),xe({title:``,body:null,storyName:null,agentOptionId:null}),Promise.resolve()},[C,e,I]),wt=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await Qt({pjcode:e,storyOptionId:t,direction:n});let r=_t.findIndex(e=>e.storyOptionId===t);if(r!==-1){let e=r+(n===`up`?-1:1);if(e>=0&&e<_t.length){let t=[..._t],n=t[r];t[r]=t[e],t[e]=n,z({generatedAt:ht?.generatedAt,stories:t})}}},[e,_t,ht?.generatedAt]),Tt=(0,y.useCallback)(async t=>{if(e===null)throw Error(`No project specified in the URL path.`);let n=await Wt({pjcode:e,storyName:t});if(n.length>0){let e=n.map(e=>{let t=_t.find(t=>t.storyOptionId===e.id);return{storyOptionId:e.id,storyName:e.name,color:e.color,description:t?.description??``,openItemCount:t?.openItemCount??0,storyViewUrl:t?.storyViewUrl??null,items:t?.items??[]}});z({generatedAt:ht?.generatedAt,stories:e})}},[e,_t,ht?.generatedAt]),Et=(0,y.useCallback)((e,t)=>{Ce({title:t,body:null,storyName:e,agentOptionId:null}),_e(!0)},[]),[Dt,Ot]=(0,y.useState)({}),[kt,At]=(0,y.useState)(null),[jt,Mt]=(0,y.useState)({}),Nt=(0,y.useCallback)((t,n)=>{let r=_t.find(e=>e.storyOptionId===t)?.color;if(At(t),Ot(e=>({...e,[t]:n})),Mt(e=>{let n={...e};return delete n[t],n}),e===null||vt===null){Ot(e=>r===void 0?e:{...e,[t]:r}),Mt(e=>({...e,[t]:`No project or repository configured.`})),At(e=>e===t?null:e);return}Yt({pjcode:e,storyOptionId:t,newColor:n,nameWithOwner:vt}).catch(e=>{Ot(e=>r===void 0?e:{...e,[t]:r}),Mt(n=>({...n,[t]:e instanceof Error?e.message:String(e)}))}).finally(()=>{At(e=>e===t?null:e)})},[e,vt,_t]),Pt=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await nn({pjcode:e,storyOptionId:t,deleteChildTasks:n}),z({generatedAt:ht?.generatedAt,stories:_t.filter(e=>e.storyOptionId!==t)})},[e,_t,ht?.generatedAt]),Ft=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await an({pjcode:e,storyOptionId:t,newName:n});let r=_t.map(e=>e.storyOptionId===t?{...e,storyName:n}:e);z({generatedAt:ht?.generatedAt,stories:r})},[e,_t,ht?.generatedAt]),It=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await sn({pjcode:e,storyOptionId:t,description:n});let r=_t.map(e=>e.storyOptionId===t?{...e,description:n}:e);z({generatedAt:ht?.generatedAt,stories:r})},[e,_t,ht?.generatedAt]),Lt=ai(Be,de.comments,A===`prs`),Rt=(0,y.useCallback)((e,t)=>{ut({kind:{type:`ok_and_awaiting_workspace`},item:e,commit:()=>pe.okAndMoveToAwaitingWorkspace(e,t),skipAdvance:!0,overlayPatch:{done:!0,status:{name:t.name,color:t.color}}})},[ut,pe]);return(0,x.jsxs)(`main`,{className:`console-app`,children:[I.pending!==null&&(0,x.jsx)(Je,{message:I.pending.message,color:I.pending.color,remainingSeconds:I.pending.remainingSeconds,progress:I.pending.progress,onUndo:I.undo,onDismiss:I.dismiss}),I.error!==null&&(0,x.jsx)(Ye,{title:I.error.message,message:`Operation failed: ${I.error.reason}`,onDismiss:I.dismissError,onRetry:I.error.retry===void 0?void 0:()=>{I.dismissError(),I.error?.retry?.()}}),(0,x.jsx)(qe,{actions:Re,isOnline:we,isConfirming:Fe,onConfirm:Le,onDiscard:I.discardOfflineAction}),O.isOpen&&(0,x.jsx)(S,{pjcodes:v,inputValues:O.inputValues,onChangeInput:O.changeInput,isLoading:O.isLoading,isSaving:O.isSaving,error:O.error,nameWithOwnerByPjcode:w,onSave:O.save,onClose:O.close}),(0,x.jsx)(re,{activeTab:A,counts:k,pjcode:e,pjcodes:v,generatedAt:nt,fromCache:rt,tabHref:ne.tabHref,onSelectTab:ae,onSelectProject:ce,settingsButton:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(le,{isOpen:u,isTimerActive:c,timerMode:d,projectMinutes:f,pjcodes:v,isLoadingPjcodes:ee,onOpen:p,onToggleTimerMode:g,onChangeMinutes:_,onSave:h,onClose:m}),(0,x.jsx)(`button`,{type:`button`,className:`console-tab-settings-button`,"aria-label":`Open max settings`,onClick:O.open,children:`⚙`}),e!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`button`,{type:`button`,className:`console-task-create-button`,disabled:vt===null||_t.length===0,onClick:()=>_e(!0),"aria-label":`Create new task`,title:`Create new task`,children:(0,x.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,x.jsx)(`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`}),(0,x.jsx)(`path`,{d:`M18.375 2.625a2.121 2.121 0 0 1 3 3L7 18l-4 1 1-4Z`})]})}),ge&&(0,x.jsx)(fe,{storyEntries:_t,agentOptions:et,onSubmit:St,onClose:()=>_e(!1),initialDraft:Se,onDraftChange:Ce,fleetTaskCreateUrl:C,newIssueUrl:yt})]})]}),airplaneModeEnabled:t.airplaneMode,airplaneModeStatus:n.status,airplaneModeProgress:n.progress,airplaneModeCapturedAt:r?.capturedAt??null,airplaneModeFailures:n.failures,onAirplaneModeStartSync:n.startSync,onAirplaneModeTurnOff:n.turnOff,onAirplaneModeRetryFailed:n.retryFailed,projectUrl:e===null?null:b?.[e]??null,onFleetTaskCreate:C===null?null:()=>ye(!0),now:R}),ve&&(0,x.jsx)(fe,{storyEntries:_t,agentOptions:et,initialDraft:be,onDraftChange:xe,onSubmit:Ct,onClose:()=>ye(!1),containerClassName:`console-fleet-task-create-dialog-container`}),(0,x.jsx)(T,{timerEndsAt:ze?.timerEndsAt??null,timerTotalSeconds:ze?.timerTotalSeconds??null,now:R}),A===`stories`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(He,{stories:_t,isLoading:a,error:o,showGray:ft,onCreateIssue:xt,onAddStory:Tt,onSelectColor:Nt,onToggleGray:mt,onReorderStory:wt,onDeleteStory:Pt,onRenameStory:Ft,onUpdateDescription:It,onStoryTaskCreateEdit:Et,optimisticColors:Dt,colorChangeInFlight:kt,colorErrors:jt})}):B===null?A===`queued`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(Ne,{rows:Ze,storyColors:Qe,statusOptions:$e,agentOptions:et,activeItemId:null,isLoading:a,error:o,onSelectItem:e=>ne.openItem(e.projectItemId)})}):A===`prs`?(0,x.jsxs)(`div`,{className:`console-list-screen`,children:[(0,x.jsx)(Ae,{agentOptions:et,agentCounts:We,selectedAgent:Ve,onAgentChange:Ue}),(0,x.jsx)(ke,{rows:Ze,storyColors:Qe,statusOptions:$e,activeItemId:null,now:R,isLoading:a,error:o,onSelectItem:e=>ne.openItem(e.projectItemId),executiveSummaries:Lt,onOkAndAwaitingWorkspace:Rt})]}):(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(ke,{rows:Ze,storyColors:Qe,statusOptions:$e,activeItemId:null,now:R,isLoading:a,error:o,onSelectItem:e=>ne.openItem(e.projectItemId)})}):(0,x.jsx)(`div`,{className:`console-detail-screen`,ref:dt,children:(0,x.jsx)(Xd,{tab:A,item:B,caches:de,operations:pe,pjcode:e,statusOptions:$e,storyOptions:tt,agentOptions:et,storyEntries:_t,storyColors:Qe,storyName:ct,overlayStatus:st,now:R,initialCommentDraft:F.current.get(B.projectItemId)??``,onCommentDraftChange:ue,onQueueAction:ut,onCommentError:(e,t)=>I.showError(e,t),onDeleteStory:V===null?null:async e=>{await Pt(V.storyOptionId,e),M!==null&&lt(M)},storyNameForDeletion:V?.storyName??null,onCreateIssueFromComment:C===null?void 0:Ct},B.projectItemId)})]})};`serviceWorker`in navigator&&navigator.serviceWorker.register(`/sw.js`).catch(e=>{console.warn(`Service worker registration failed:`,e)});var tf=document.getElementById(`root`);if(tf===null)throw Error(`Root container #root not found`);(0,b.createRoot)(tf).render((0,x.jsx)(y.StrictMode,{children:(0,x.jsx)(ef,{})}));
93
+ `)});if(!t.posted)throw Error(t.error)}},tf=()=>{let e=qr(),t=gr(),n=bt(),r=n.status===`on`?n.snapshot:null,{snapshots:i,isLoading:a,error:o,refreshSingleTab:s}=nr(e,r),{timerMode:c,projectMinutes:l,isOpen:u,draftTimerMode:d,draftProjectMinutes:f,openSettings:p,closeSettings:m,saveSettings:h,toggleDraftTimerMode:g,changeDraftMinutes:_}=hi(),{pjcodes:v,projectUrls:b,fleetTaskCreateUrl:C,nameWithOwnerByPjcode:w,isLoading:ee}=Jr(),{isTimerExpired:E}=Qr(e),D=Gr(e??$d),O=Zr(v),te=(0,y.useMemo)(()=>Vr(D.overlay,i),[D.overlay,i]),k=(0,y.useMemo)(()=>{let e=Qd();for(let t of j){let n=i[t.name];n!==null&&(t.name===`stories`?e[t.name]=n.stories.filter(e=>e.color!==`GRAY`).length:e[t.name]=Ir(n.items,te,t.name))}return e},[i,te]),ne=Cr(e,k,(0,y.useMemo)(()=>{let e=new Set;for(let t of j){let n=i[t.name];n!==null&&!n.fromCache&&e.add(t.name)}return e},[i]),(0,y.useMemo)(()=>{let e=Qd();for(let t of j){let n=i[t.name];n!==null&&(e[t.name]=t.name===`stories`?n.stories.filter(e=>e.color!==`GRAY`).length:n.items.length)}return e},[i])),{activeTab:A,selectedItemKey:M,openItem:N,closeItem:ie}=ne,ae=ui(ne.selectTab),{explicitlySelectedPjcode:P,notifyExplicitSelection:oe}=mr(e),ce=Yr((0,y.useCallback)(e=>{oe(e),fi(`/projects/${e}`)},[oe]));rr(e,A,v,a,c&&r===null);let F=(0,y.useRef)(new Map),ue=(0,y.useCallback)(e=>{M!==null&&(e?F.current.set(M,e):F.current.delete(M))},[M]),de=sr(r),pe=Mr(e,de,(0,y.useCallback)(()=>s(`queued`),[s])),I=Rn(),[R,he]=(0,y.useState)(()=>Date.now());(0,y.useEffect)(()=>{let e=setInterval(()=>{he(Date.now())},1e3);return()=>{clearInterval(e)}},[]);let[ge,_e]=(0,y.useState)(!1),[ve,ye]=(0,y.useState)(!1),[be,xe]=(0,y.useState)({title:``,body:null,storyName:null,agentOptionId:null}),[Se,Ce]=(0,y.useState)({title:``,body:null,storyName:null,agentOptionId:null}),[we,Te]=(0,y.useState)(()=>navigator.onLine);(0,y.useEffect)(()=>{let e=()=>Te(!0),t=()=>Te(!1);return window.addEventListener(`online`,e),window.addEventListener(`offline`,t),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,t)}},[]);let[Ee,De]=(0,y.useState)(new Map),[Oe,je]=(0,y.useState)(new Map),[Me,Pe]=(0,y.useState)(new Set);(0,y.useEffect)(()=>{if(we&&I.offlineActions.length!==0)for(let e of I.offlineActions)Ee.has(e.id)||Me.has(e.id)||(De(t=>new Map(t).set(e.id,null)),de.client.fetchIssueState(e.itemUrl).then(t=>{De(n=>new Map(n).set(e.id,t)),e.isPr&&(je(t=>new Map(t).set(e.id,null)),de.client.fetchPullRequestStatus(e.itemUrl).then(t=>{je(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),Pe(t=>new Set(t).add(e.id))}))},[we,I.offlineActions,de.client,Ee,Me]);let[Fe,Ie]=(0,y.useState)(!1),Le=(0,y.useCallback)(async e=>{Ie(!0);try{await I.confirmOfflineAction(e)}finally{Ie(!1)}},[I]),Re=(0,y.useMemo)(()=>I.offlineActions.map(e=>{let t=Ee.get(e.id)??null,n=Oe.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,Ee,Oe,Me]),ze=i[A],Be=(0,y.useMemo)(()=>ze===null?[]:Lr(ze.items,te,A),[ze,te,A]),[Ve,Ue]=(0,y.useState)(null),We=(0,y.useMemo)(()=>{if(A!==`prs`)return{};let e={};for(let t of Be)t.agent!==null&&t.agent!==``&&(e[t.agent]=(e[t.agent]??0)+1);return e},[Be,A]);(0,y.useEffect)(()=>{A===`prs`&&Ve!==null&&(We[Ve]??0)===0&&Ue(null)},[We,Ve,A]);let Ge=(0,y.useMemo)(()=>A!==`prs`||Ve===null?Be:Be.filter(e=>e.agent===Ve),[Be,A,Ve]),Ke=(0,y.useMemo)(()=>Ge.map(e=>Pr(e)),[Ge]),Xe=ze?.storyOrder??[],Ze=(0,y.useMemo)(()=>me(Ge,D.overlay,Xe,ze?.generatedAt??null),[Ge,D.overlay,Xe,ze]),Qe=ze?.storyColors??{},$e=ze?.statusOptions??[],et=ze?.agentOptions??[],tt=ze?.storyOptions??[],nt=ze?.generatedAt??null,rt=ze?.fromCache??!1,[it,z]=(0,y.useState)(null),B=(0,y.useMemo)(()=>M===null||ze===null?null:ze.items.find(e=>e.projectItemId===M)??null,[M,ze]);pr(de,B,Be),(0,y.useEffect)(()=>{M!==null&&window.scrollTo({top:0})},[M]),(0,y.useEffect)(()=>{if(e===null&&c&&v.length>0){let e=se(v,null,l);e!==null&&pi(`/projects/${e}/todo-by-human`)}},[e,c,v,l]),mi(c,k.prs,k[`todo-by-human`],e,v,l,i.prs!==null,i[`todo-by-human`]!==null,i.prs?.fromCache??!1,i[`todo-by-human`]?.fromCache??!1,P),di(c,e,Ge,M,ne.openItem);let at=k[A],ot=(0,y.useRef)({tab:A,count:at});(0,y.useEffect)(()=>{let e=ot.current;if(ot.current={tab:A,count:at},e.tab===A&&e.count>0&&at===0){let e=_r(A,k);e!==null&&(ae(e),ie())}},[A,at,k,ae,ie]);let st=B===null?null:Rr(D.overlay,B,i[A]?.generatedAt??null),ct=B===null?null:L(B,D.overlay,i[A]?.generatedAt??null),lt=(0,y.useCallback)(e=>{let t=gi(Ke,e);t===null?ie():N(t)},[Ke,N,ie]),ut=(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=Pr(t.item),i=t.overlayPatch;I.enqueue({message:Cn(t.kind,t.item,A),color:xn(t.kind),commit:t.commit,offline:t.offline,revertAdvance:t.revertAdvance,optimistic:i===void 0?void 0:()=>D.patchOverlay(r,i,A),revertOptimistic:i===void 0?void 0:()=>D.revertOverlayEntry(r),advance:()=>{if(t.onAdvance?.(),!t.skipAdvance&&Sn(t.kind,A)){if(c&&E(l[e??``]??15)){let t=se(v,e,l);t!==null&&fi(`/projects/${t}/todo-by-human`)}else lt(r)}}})},[I,A,lt,n.status,D,c,E,l,e,v]),dt=li((0,y.useCallback)(e=>{if(M===null||e===null)return;let t=e===`next`?_i(Ke,M):vi(Ke,M);t!==null&&N(t)},[M,Ke,N])),[ft,pt]=(0,y.useState)(()=>localStorage.getItem(`console-story-show-gray`)===`true`),mt=(0,y.useCallback)(()=>{pt(e=>{let t=!e;return localStorage.setItem(`console-story-show-gray`,String(t)),t})},[]),ht=i.stories,gt=ht?.stories??[],_t=it!==null&&it.generatedAt===ht?.generatedAt?it.stories:gt,vt=ht?.defaultNameWithOwner??null,yt=vt===null?null:`https://github.com/${vt}/issues/new`,V=(0,y.useMemo)(()=>B===null||!B.labels.includes(`story`)?null:_t.find(e=>e.storyName===B.story)??null,[B,_t]),xt=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);if(vt===null)throw Error(`No repository configured for this project.`);await Xt({pjcode:e,title:n,storyName:t,nameWithOwner:vt})},[e,vt]),St=(0,y.useCallback)(({storyName:t,agentOptionId:n,title:r,body:i,files:a})=>{if(e===null||vt===null)return Promise.resolve();let o=e,s=vt,c={title:r,storyName:t,agentOptionId:n,body:i,files:a};return I.enqueue({message:`Task created — "${r}"`,color:`blue`,commit:()=>ef(o,s,c),advance:()=>{}}),Ce({title:``,body:null,storyName:null,agentOptionId:null}),Promise.resolve()},[e,vt,I]),Ct=(0,y.useCallback)(({title:t,body:n,storyName:r,agentOptionId:i,files:a})=>{if(C===null||e===null)return Promise.resolve();let o=C.match(/github\.com\/([^/]+\/[^/]+)/);if(o===null)return Promise.resolve();let s=o[1],c=e,l={title:t,storyName:r,agentOptionId:i,body:n,files:a};return I.enqueue({message:`Task created — "${t}"`,color:`blue`,commit:()=>ef(c,s,l),advance:()=>{}}),xe({title:``,body:null,storyName:null,agentOptionId:null}),Promise.resolve()},[C,e,I]),wt=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await Qt({pjcode:e,storyOptionId:t,direction:n});let r=_t.findIndex(e=>e.storyOptionId===t);if(r!==-1){let e=r+(n===`up`?-1:1);if(e>=0&&e<_t.length){let t=[..._t],n=t[r];t[r]=t[e],t[e]=n,z({generatedAt:ht?.generatedAt,stories:t})}}},[e,_t,ht?.generatedAt]),Tt=(0,y.useCallback)(async t=>{if(e===null)throw Error(`No project specified in the URL path.`);let n=await Wt({pjcode:e,storyName:t});if(n.length>0){let e=n.map(e=>{let t=_t.find(t=>t.storyOptionId===e.id);return{storyOptionId:e.id,storyName:e.name,color:e.color,description:t?.description??``,openItemCount:t?.openItemCount??0,storyViewUrl:t?.storyViewUrl??null,items:t?.items??[]}});z({generatedAt:ht?.generatedAt,stories:e})}},[e,_t,ht?.generatedAt]),Et=(0,y.useCallback)((e,t)=>{Ce({title:t,body:null,storyName:e,agentOptionId:null}),_e(!0)},[]),[Dt,Ot]=(0,y.useState)({}),[kt,At]=(0,y.useState)(null),[jt,Mt]=(0,y.useState)({}),Nt=(0,y.useCallback)((t,n)=>{let r=_t.find(e=>e.storyOptionId===t)?.color;if(At(t),Ot(e=>({...e,[t]:n})),Mt(e=>{let n={...e};return delete n[t],n}),e===null||vt===null){Ot(e=>r===void 0?e:{...e,[t]:r}),Mt(e=>({...e,[t]:`No project or repository configured.`})),At(e=>e===t?null:e);return}Yt({pjcode:e,storyOptionId:t,newColor:n,nameWithOwner:vt}).catch(e=>{Ot(e=>r===void 0?e:{...e,[t]:r}),Mt(n=>({...n,[t]:e instanceof Error?e.message:String(e)}))}).finally(()=>{At(e=>e===t?null:e)})},[e,vt,_t]),Pt=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await nn({pjcode:e,storyOptionId:t,deleteChildTasks:n}),z({generatedAt:ht?.generatedAt,stories:_t.filter(e=>e.storyOptionId!==t)})},[e,_t,ht?.generatedAt]),Ft=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await an({pjcode:e,storyOptionId:t,newName:n});let r=_t.map(e=>e.storyOptionId===t?{...e,storyName:n}:e);z({generatedAt:ht?.generatedAt,stories:r})},[e,_t,ht?.generatedAt]),It=(0,y.useCallback)(async(t,n)=>{if(e===null)throw Error(`No project specified in the URL path.`);await sn({pjcode:e,storyOptionId:t,description:n});let r=_t.map(e=>e.storyOptionId===t?{...e,description:n}:e);z({generatedAt:ht?.generatedAt,stories:r})},[e,_t,ht?.generatedAt]),Lt=ai(Be,de.comments,A===`prs`),Rt=(0,y.useCallback)((e,t)=>{ut({kind:{type:`ok_and_awaiting_workspace`},item:e,commit:()=>pe.okAndMoveToAwaitingWorkspace(e,t),skipAdvance:!0,overlayPatch:{done:!0,status:{name:t.name,color:t.color}}})},[ut,pe]);return(0,x.jsxs)(`main`,{className:`console-app`,children:[I.pending!==null&&(0,x.jsx)(Je,{message:I.pending.message,color:I.pending.color,remainingSeconds:I.pending.remainingSeconds,progress:I.pending.progress,onUndo:I.undo,onDismiss:I.dismiss}),I.error!==null&&(0,x.jsx)(Ye,{title:I.error.message,message:`Operation failed: ${I.error.reason}`,onDismiss:I.dismissError,onRetry:I.error.retry===void 0?void 0:()=>{I.dismissError(),I.error?.retry?.()}}),(0,x.jsx)(qe,{actions:Re,isOnline:we,isConfirming:Fe,onConfirm:Le,onDiscard:I.discardOfflineAction}),O.isOpen&&(0,x.jsx)(S,{pjcodes:v,inputValues:O.inputValues,onChangeInput:O.changeInput,isLoading:O.isLoading,isSaving:O.isSaving,error:O.error,nameWithOwnerByPjcode:w,onSave:O.save,onClose:O.close}),(0,x.jsx)(re,{activeTab:A,counts:k,pjcode:e,pjcodes:v,generatedAt:nt,fromCache:rt,tabHref:ne.tabHref,onSelectTab:ae,onSelectProject:ce,settingsButton:(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(le,{isOpen:u,isTimerActive:c,timerMode:d,projectMinutes:f,pjcodes:v,isLoadingPjcodes:ee,onOpen:p,onToggleTimerMode:g,onChangeMinutes:_,onSave:h,onClose:m}),(0,x.jsx)(`button`,{type:`button`,className:`console-tab-settings-button`,"aria-label":`Open max settings`,onClick:O.open,children:`⚙`}),e!==null&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`button`,{type:`button`,className:`console-task-create-button`,disabled:vt===null||_t.length===0,onClick:()=>_e(!0),"aria-label":`Create new task`,title:`Create new task`,children:(0,x.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,x.jsx)(`path`,{d:`M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7`}),(0,x.jsx)(`path`,{d:`M18.375 2.625a2.121 2.121 0 0 1 3 3L7 18l-4 1 1-4Z`})]})}),ge&&(0,x.jsx)(fe,{storyEntries:_t,agentOptions:et,onSubmit:St,onClose:()=>_e(!1),initialDraft:Se,onDraftChange:Ce,fleetTaskCreateUrl:C,newIssueUrl:yt})]})]}),airplaneModeEnabled:t.airplaneMode,airplaneModeStatus:n.status,airplaneModeProgress:n.progress,airplaneModeCapturedAt:r?.capturedAt??null,airplaneModeFailures:n.failures,onAirplaneModeStartSync:n.startSync,onAirplaneModeTurnOff:n.turnOff,onAirplaneModeRetryFailed:n.retryFailed,projectUrl:e===null?null:b?.[e]??null,onFleetTaskCreate:C===null?null:()=>ye(!0),now:R}),ve&&(0,x.jsx)(fe,{storyEntries:_t,agentOptions:et,initialDraft:be,onDraftChange:xe,onSubmit:Ct,onClose:()=>ye(!1),containerClassName:`console-fleet-task-create-dialog-container`}),(0,x.jsx)(T,{timerEndsAt:ze?.timerEndsAt??null,timerTotalSeconds:ze?.timerTotalSeconds??null,now:R}),A===`stories`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(He,{stories:_t,isLoading:a,error:o,showGray:ft,onCreateIssue:xt,onAddStory:Tt,onSelectColor:Nt,onToggleGray:mt,onReorderStory:wt,onDeleteStory:Pt,onRenameStory:Ft,onUpdateDescription:It,onStoryTaskCreateEdit:Et,optimisticColors:Dt,colorChangeInFlight:kt,colorErrors:jt})}):B===null?A===`queued`?(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(Ne,{rows:Ze,storyColors:Qe,statusOptions:$e,agentOptions:et,activeItemId:null,isLoading:a,error:o,onSelectItem:e=>ne.openItem(e.projectItemId)})}):A===`prs`?(0,x.jsxs)(`div`,{className:`console-list-screen`,children:[(0,x.jsx)(Ae,{agentOptions:et,agentCounts:We,selectedAgent:Ve,onAgentChange:Ue}),(0,x.jsx)(ke,{rows:Ze,storyColors:Qe,statusOptions:$e,activeItemId:null,now:R,isLoading:a,error:o,onSelectItem:e=>ne.openItem(e.projectItemId),executiveSummaries:Lt,onOkAndAwaitingWorkspace:Rt})]}):(0,x.jsx)(`div`,{className:`console-list-screen`,children:(0,x.jsx)(ke,{rows:Ze,storyColors:Qe,statusOptions:$e,activeItemId:null,now:R,isLoading:a,error:o,onSelectItem:e=>ne.openItem(e.projectItemId)})}):(0,x.jsx)(`div`,{className:`console-detail-screen`,ref:dt,children:(0,x.jsx)(Zd,{tab:A,item:B,caches:de,operations:pe,pjcode:e,statusOptions:$e,storyOptions:tt,agentOptions:et,storyEntries:_t,storyColors:Qe,storyName:ct,overlayStatus:st,now:R,initialCommentDraft:F.current.get(B.projectItemId)??``,onCommentDraftChange:ue,onQueueAction:ut,onCommentError:(e,t)=>I.showError(e,t),onDeleteStory:V===null?null:async e=>{await Pt(V.storyOptionId,e),M!==null&&lt(M)},storyNameForDeletion:V?.storyName??null,onCreateIssueFromComment:C===null?void 0:Ct},B.projectItemId)})]})};`serviceWorker`in navigator&&navigator.serviceWorker.register(`/sw.js`).catch(e=>{console.warn(`Service worker registration failed:`,e)});var nf=document.getElementById(`root`);if(nf===null)throw Error(`Root container #root not found`);(0,b.createRoot)(nf).render((0,x.jsx)(y.StrictMode,{children:(0,x.jsx)(tf,{})}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
7
  <title>TDPM Console</title>
8
- <script type="module" crossorigin src="/assets/index-DfvjH9_G.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-BsWigavn.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-BCjejjC0.css">
10
10
  </head>
11
11
  <body>
@@ -11,6 +11,9 @@ const isErrorWithCode = (err, code) => {
11
11
  'code' in err &&
12
12
  err.code === code);
13
13
  };
14
+ const readFileUtf8 = (path) => {
15
+ return fs_1.default.readFileSync(path, 'utf8');
16
+ };
14
17
  class LocalStorageRepository {
15
18
  constructor() {
16
19
  this.write = (path, value) => {
@@ -19,7 +22,7 @@ class LocalStorageRepository {
19
22
  fs_1.default.writeFileSync(path, value, 'utf8');
20
23
  };
21
24
  this.read = (path) => {
22
- return fs_1.default.readFileSync(path, 'utf8');
25
+ return readFileUtf8(path);
23
26
  };
24
27
  this.rename = (oldPath, newPath) => {
25
28
  fs_1.default.renameSync(oldPath, newPath);
@@ -66,7 +69,7 @@ class LocalStorageRepository {
66
69
  };
67
70
  this.readOrNull = (path) => {
68
71
  try {
69
- return fs_1.default.readFileSync(path, 'utf8');
72
+ return readFileUtf8(path);
70
73
  }
71
74
  catch (err) {
72
75
  if (isErrorWithCode(err, 'ENOENT')) {
@@ -1 +1 @@
1
- {"version":3,"file":"LocalStorageRepository.js","sourceRoot":"","sources":["../../../src/adapter/repositories/LocalStorageRepository.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"LocalStorageRepository.js","sourceRoot":"","sources":["../../../src/adapter/repositories/LocalStorageRepository.ts"],"names":[],"mappings":"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"}
@@ -437,6 +437,27 @@ class ApiV3CheerioRestIssueRepository extends BaseGitHubRepository_1.BaseGitHubR
437
437
  this.getAllIssuesRefreshMemo.set(projectId, result);
438
438
  return result;
439
439
  };
440
+ this.mergeFetchedItemsSkippingOnesRemovedFromCacheWhileFetchWasInFlight = (issuesPresentInCacheAtMergeTime, itemIdsPresentInCacheBeforeFetchStarted, fetchedItems) => {
441
+ const mergedIssuesByUrl = new Map(issuesPresentInCacheAtMergeTime.map((issue) => [issue.url, issue]));
442
+ const itemIdsStillPresentInCacheAtMergeTime = new Set(issuesPresentInCacheAtMergeTime.map((issue) => issue.itemId));
443
+ for (const item of fetchedItems) {
444
+ const itemWasRemovedFromCacheWhileThisFetchWasInFlight = itemIdsPresentInCacheBeforeFetchStarted.has(item.id) &&
445
+ !itemIdsStillPresentInCacheAtMergeTime.has(item.id);
446
+ if (itemWasRemovedFromCacheWhileThisFetchWasInFlight) {
447
+ continue;
448
+ }
449
+ mergedIssuesByUrl.set(item.url, this.convertProjectItemToIssue(item));
450
+ }
451
+ return Array.from(mergedIssuesByUrl.values());
452
+ };
453
+ this.mergeFetchedProjectPreservingCacheChangeWhileFetchWasInFlight = (projectPresentInCacheAtMergeTime, projectPresentInCacheBeforeFetchStarted, fetchedProject) => {
454
+ const projectWasChangedInCacheWhileFetchWasInFlight = projectPresentInCacheAtMergeTime !== null &&
455
+ JSON.stringify(projectPresentInCacheAtMergeTime) !==
456
+ JSON.stringify(projectPresentInCacheBeforeFetchStarted);
457
+ return projectWasChangedInCacheWhileFetchWasInFlight
458
+ ? projectPresentInCacheAtMergeTime
459
+ : fetchedProject;
460
+ };
440
461
  this.refreshAllIssues = async (projectId) => {
441
462
  const now = await this.dateRepository.now();
442
463
  const cache = await this.readCachedProjectIssues(projectId);
@@ -468,21 +489,16 @@ class ApiV3CheerioRestIssueRepository extends BaseGitHubRepository_1.BaseGitHubR
468
489
  false);
469
490
  const effectiveIsFullFetch = isFullFetch || storyOptionsChanged;
470
491
  if (effectiveIsFullFetch) {
492
+ const itemIdsKnownBeforeFetch = new Set(cache?.issues.map((issue) => issue.itemId) ?? []);
471
493
  const items = await this.graphqlProjectItemRepository.fetchProjectItems(projectId);
472
494
  const nowIso = now.toISOString();
473
495
  const issues = await this.projectIssuesCacheRepository.withLock(projectId, async () => {
474
496
  const freshCache = await this.readCachedProjectIssues(projectId);
475
- const issuesByUrl = new Map(freshCache !== null
476
- ? freshCache.issues.map((issue) => [issue.url, issue])
477
- : []);
478
- for (const item of items) {
479
- issuesByUrl.set(item.url, this.convertProjectItemToIssue(item));
480
- }
481
- const mergedIssues = Array.from(issuesByUrl.values());
497
+ const mergedIssues = this.mergeFetchedItemsSkippingOnesRemovedFromCacheWhileFetchWasInFlight(freshCache?.issues ?? [], itemIdsKnownBeforeFetch, items);
482
498
  await this.projectIssuesCacheRepository.write(projectId, {
483
499
  lastFetchedAt: nowIso,
484
500
  lastFullFetchAt: nowIso,
485
- project,
501
+ project: this.mergeFetchedProjectPreservingCacheChangeWhileFetchWasInFlight(freshCache?.project ?? null, cache?.project ?? null, project),
486
502
  issues: mergedIssues,
487
503
  storyIssueUrlByOptionName: buildStoryIssueUrlByOptionName(mergedIssues, project.story?.stories ?? []),
488
504
  storyOptions: buildStoryOptions(project),
@@ -492,6 +508,7 @@ class ApiV3CheerioRestIssueRepository extends BaseGitHubRepository_1.BaseGitHubR
492
508
  this.lastIssuesFetchedAtByProjectId.set(projectId, nowIso);
493
509
  return { issues, project, cacheUsed: false };
494
510
  }
511
+ const itemIdsKnownBeforeFetch = new Set(cache.issues.map((issue) => issue.itemId));
495
512
  const lastFetchedAt = new Date(cache.lastFetchedAt);
496
513
  const cutoff = new Date(lastFetchedAt.getTime() - exports.INCREMENTAL_FETCH_SKEW_BUFFER_MS);
497
514
  const lightItems = await this.graphqlProjectItemRepository.fetchProjectItemsLight(projectId, `updated:>=${this.toDateString(cutoff)}`);
@@ -504,16 +521,11 @@ class ApiV3CheerioRestIssueRepository extends BaseGitHubRepository_1.BaseGitHubR
504
521
  const nowIso = now.toISOString();
505
522
  const issues = await this.projectIssuesCacheRepository.withLock(projectId, async () => {
506
523
  const freshCache = await this.readCachedProjectIssues(projectId);
507
- const issuesByUrl = new Map((freshCache ?? cache).issues.map((issue) => [issue.url, issue]));
508
- for (const item of changedItems) {
509
- const issue = this.convertProjectItemToIssue(item);
510
- issuesByUrl.set(issue.url, issue);
511
- }
512
- const mergedIssues = Array.from(issuesByUrl.values());
524
+ const mergedIssues = this.mergeFetchedItemsSkippingOnesRemovedFromCacheWhileFetchWasInFlight((freshCache ?? cache).issues, itemIdsKnownBeforeFetch, changedItems);
513
525
  await this.projectIssuesCacheRepository.write(projectId, {
514
526
  lastFetchedAt: nowIso,
515
527
  lastFullFetchAt: freshCache?.lastFullFetchAt ?? cache.lastFullFetchAt,
516
- project,
528
+ project: this.mergeFetchedProjectPreservingCacheChangeWhileFetchWasInFlight(freshCache?.project ?? null, cache.project, project),
517
529
  issues: mergedIssues,
518
530
  storyIssueUrlByOptionName: buildStoryIssueUrlByOptionName(mergedIssues, project.story?.stories ?? []),
519
531
  storyOptions: buildStoryOptions(project),