@pi-chamber/web 1.0.3 → 1.0.4-rc.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.
- package/dist/assets/DiagramView-DfZMQkXY.js +1 -0
- package/dist/assets/{DiffView-D19Jps0i.js → DiffView-BjWUdbL5.js} +6 -6
- package/dist/assets/FileSaveConflictDialog-u5L4k_5k.js +3 -0
- package/dist/assets/FilesView-qP1ypN9J.js +6 -0
- package/dist/assets/GitHubDetailScaffold-zCKCy5OJ.js +11 -0
- package/dist/assets/GitHubLinkPicker-CwxKY3lN.js +1 -0
- package/dist/assets/GitHubListPrimitives-Ck3zllel.js +1 -0
- package/dist/assets/GitView-y2k2i4gR.js +9 -0
- package/dist/assets/IssuesSurface-HWgR87N3.js +7 -0
- package/dist/assets/JsonTreeView-DSuC4naV.js +1 -0
- package/dist/assets/{MarkdownRendererImpl-DV5Xkj8N.js → MarkdownRendererImpl-CT5ln9em.js} +5 -5
- package/dist/assets/PatchDiff-DArTeWeK.js +1 -0
- package/dist/assets/PierreDiffViewer-DQKujzLb.js +134 -0
- package/dist/assets/PullRequestsSurface-Cfb1wSvC.js +2 -0
- package/dist/assets/SessionSwitcherContent-DEGJyZBl.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-cC9wVBH7.js +2 -0
- package/dist/assets/SessionUnreadDot-CELKNVIM.js +1 -0
- package/dist/assets/SettingsView-CZvRRgJe.js +6 -0
- package/dist/assets/SettingsWindow-CZM1dmVb.js +1 -0
- package/dist/assets/ToolOutputDialog-DClOSbJc.js +8 -0
- package/dist/assets/ToolPartDiffPreview-BaFiGUDE.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-CJondRlh.js → VirtualizedFileDiff-D6KbvKc6.js} +3 -3
- package/dist/assets/Virtualizer-wpC51ZBQ.js +1 -0
- package/dist/assets/collapsible-DhV9d4dT.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-CeMpF2xC.js +3 -0
- package/dist/assets/{contextFileOpenGuard-CsZL8yie.js → contextFileOpenGuard-Ck5u_kAP.js} +1 -1
- package/dist/assets/gitStatusPredicates-DEBSqUNE.js +1 -0
- package/dist/assets/githubLink-DT7i2NlH.js +10 -0
- package/dist/assets/index-6IO1AcJI.js +10 -0
- package/dist/assets/index-BAmzAlNx.css +1 -0
- package/dist/assets/index-eDf4LKLY.js +1 -0
- package/dist/assets/main-BczEScAA.js +2 -0
- package/dist/assets/main-CHLNMYeJ.js +136 -0
- package/dist/assets/markdownCore-C4Gk5Zht.js +2 -0
- package/dist/assets/miniChat-Do3hE87Z.js +2 -0
- package/dist/assets/mobile-CTnihwfa.js +2 -0
- package/dist/assets/permissionStore-B9Hkrqny.js +1 -0
- package/dist/assets/pi-session-focus-preference-LDVCJ_YR.js +10 -0
- package/dist/assets/renderDiffWithHighlighter-CDsgOnkH.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-DSa3gYqR.js +2 -0
- package/dist/assets/renderFileWithHighlighter-TpKRyfCY.js +1 -0
- package/dist/assets/renderMobileApp-CPE-3uMl.js +11 -0
- package/dist/assets/runtimeEndpointReset-CzJfovWI.js +62 -0
- package/dist/assets/{runtimeSurface-BdndJV2m.js → runtimeSurface-DW_Ia4q3.js} +1 -1
- package/dist/assets/shell-CjFT_Tl9.js +1 -0
- package/dist/assets/sprite-HGQGInUp.js +6510 -0
- package/dist/assets/useAppFontEffects-CG3_yteE.js +212 -0
- package/dist/assets/{useFilesViewSearch-DJ3psTKU.js → useFilesViewSearch-C_LzYIgD.js} +1 -1
- package/dist/assets/useGitHubRemoteSearch-DsxWOzKZ.js +1 -0
- package/dist/assets/useSwitcherItems-BmoCnS9W.js +1 -0
- package/dist/assets/vendor-base-ui-DIkTOIJS.js +1 -0
- package/dist/assets/{vendor-beautiful-mermaid-D3YCkKz7.js → vendor-beautiful-mermaid-DApbjBp2.js} +1 -1
- package/dist/assets/vendor-boot-DyL2td56.js +69 -0
- package/dist/assets/vendor-codemirror-autocomplete-DsFn4GLp.js +1 -0
- package/dist/assets/vendor-codemirror-lang-angular-B_NMmBbS.js +1 -0
- package/dist/assets/vendor-codemirror-lang-cpp-GOE7Gjd0.js +1 -0
- package/dist/assets/vendor-codemirror-lang-css-Dwf2XpnZ.js +1 -0
- package/dist/assets/vendor-codemirror-lang-go-C2KHbcll.js +7 -0
- package/dist/assets/vendor-codemirror-lang-html-DcKqyeGk.js +1 -0
- package/dist/assets/vendor-codemirror-lang-java-6eGbyB2k.js +1 -0
- package/dist/assets/vendor-codemirror-lang-javascript-DpTUrvx8.js +13 -0
- package/dist/assets/vendor-codemirror-lang-jinja-xSUJjXhr.js +1 -0
- package/dist/assets/vendor-codemirror-lang-json-CLGxdOCz.js +1 -0
- package/dist/assets/vendor-codemirror-lang-less-6nXi1rS9.js +1 -0
- package/dist/assets/vendor-codemirror-lang-liquid-B9hmb9P8.js +1 -0
- package/dist/assets/vendor-codemirror-lang-markdown-DmFP9s6x.js +1 -0
- package/dist/assets/vendor-codemirror-lang-php-DC6To8iX.js +1 -0
- package/dist/assets/vendor-codemirror-lang-python-yuxIkjit.js +3 -0
- package/dist/assets/vendor-codemirror-lang-rust-di1Sjz-0.js +1 -0
- package/dist/assets/vendor-codemirror-lang-sass-BWpV9NPV.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-sql-HpQWHJjv.js → vendor-codemirror-lang-sql-C_RazIaB.js} +2 -2
- package/dist/assets/vendor-codemirror-lang-vue-BYL0r7KR.js +1 -0
- package/dist/assets/vendor-codemirror-lang-wast-BiVarhcz.js +1 -0
- package/dist/assets/vendor-codemirror-lang-xml-Cn1lY1ts.js +1 -0
- package/dist/assets/vendor-codemirror-lang-yaml-BZ6mZw9L.js +1 -0
- package/dist/assets/vendor-codemirror-language-data-DglcKYWT.js +2 -0
- package/dist/assets/vendor-codemirror-search-DaE6R5gH.js +2 -0
- package/dist/assets/{vendor-elkjs-mzfkf0ML.js → vendor-elkjs-D27273Ms.js} +1 -1
- package/dist/assets/{vendor-heic2any-BHsbokcA.js → vendor-heic2any-pq-UTQQR.js} +1 -1
- package/dist/assets/vendor-lezer-cpp-Dt99h3WT.js +1 -0
- package/dist/assets/vendor-lezer-css-DNU_fzPI.js +1 -0
- package/dist/assets/vendor-lezer-go-BEFtcNyS.js +1 -0
- package/dist/assets/vendor-lezer-html-DDGRhRUz.js +1 -0
- package/dist/assets/vendor-lezer-java-DmfZtW09.js +1 -0
- package/dist/assets/vendor-lezer-javascript-oje4tdp_.js +1 -0
- package/dist/assets/vendor-lezer-json-BRXb_bDX.js +1 -0
- package/dist/assets/vendor-lezer-lr-BU2qmu_5.js +1 -0
- package/dist/assets/{vendor-lezer-markdown-C6g-d6P3.js → vendor-lezer-markdown-CicYv7V9.js} +4 -4
- package/dist/assets/vendor-lezer-php-COORrTpE.js +1 -0
- package/dist/assets/vendor-lezer-python-Cuvm9X9Y.js +1 -0
- package/dist/assets/vendor-lezer-rust-C_zOfHbX.js +1 -0
- package/dist/assets/vendor-lezer-sass-DWP4w7O1.js +1 -0
- package/dist/assets/vendor-lezer-xml-Br6nOYeG.js +1 -0
- package/dist/assets/vendor-lezer-yaml-CYQmm6Sb.js +1 -0
- package/dist/assets/{vendor-lru_map-Cy8fTs3_.js → vendor-lru_map-DOPmc7GU.js} +1 -1
- package/dist/assets/{vendor-qrcode-B0KNSajT.js → vendor-qrcode-Dv4uniC1.js} +1 -1
- package/dist/assets/vendor-react-DASdDPIk.js +1 -0
- package/dist/assets/{vendor-react-drawio-BYDptOsj.js → vendor-react-drawio-Duu5LgQA.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-DaSwPsXt.js → vendor-replit-codemirror-vim-CZy3BUVv.js} +15 -15
- package/dist/assets/vendor-zustand-CUi8eEds.js +6 -0
- package/dist/assets/{web-components-CCKlju0Z.js → web-components-CH3-XV-n.js} +4 -4
- package/dist/index.html +7 -9
- package/dist/mini-chat.html +6 -8
- package/dist/mobile.html +6 -8
- package/package.json +1 -1
- package/server/index.js +3 -1
- package/server/lib/fs/DOCUMENTATION.md +1 -1
- package/server/lib/fs/routes.js +1 -50
- package/server/lib/git/DOCUMENTATION.md +18 -11
- package/server/lib/git/index.js +8 -3
- package/server/lib/git/routes.js +0 -129
- package/server/lib/git/service.js +40 -152
- package/server/lib/git/service.test.js +42 -18
- package/server/lib/github/DOCUMENTATION.md +271 -0
- package/server/lib/github/cache.js +164 -0
- package/server/lib/github/checks.js +230 -0
- package/server/lib/github/client.js +305 -0
- package/server/lib/github/context.js +177 -0
- package/server/lib/github/contracts.test.js +235 -0
- package/server/lib/github/correctness.test.js +356 -0
- package/server/lib/github/credential.js +46 -0
- package/server/lib/github/errors.js +151 -0
- package/server/lib/github/gh-cli.js +336 -0
- package/server/lib/github/index.js +27 -0
- package/server/lib/github/issues.js +495 -0
- package/server/lib/github/pulls.js +699 -0
- package/server/lib/github/repo-scope.js +688 -0
- package/server/lib/github/routes.js +599 -0
- package/server/lib/github/security.test.js +275 -0
- package/server/lib/github/templates.js +153 -0
- package/server/lib/package-manager-detect-child.js +12 -0
- package/server/lib/package-manager.js +366 -92
- package/server/lib/package-manager.test.js +109 -0
- package/server/lib/pi/routes-extension-events.test.js +268 -4
- package/server/lib/pi/routes.js +109 -25
- package/server/lib/pi/routes.test.js +118 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +5 -3
- package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +222 -0
- package/server/lib/pi/session-daemon/extension-bridge.js +415 -42
- package/server/lib/pi/session-daemon/extension-name.js +87 -0
- package/server/lib/pi/session-daemon/extension-name.test.js +143 -0
- package/server/lib/pi/session-daemon/extension-theme.js +142 -0
- package/server/lib/pi/session-daemon/extension-theme.test.js +117 -0
- package/server/lib/pi/session-daemon/extension-tool-render.js +365 -0
- package/server/lib/pi/session-daemon/extension-tool-render.test.js +607 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +322 -2
- package/server/lib/pi/session-daemon/session-daemon-list-live.test.js +244 -0
- package/server/lib/pi/session-daemon/session-daemon.js +204 -33
- package/server/lib/pi/session-daemon/session-daemon.test.js +218 -0
- package/server/lib/pi/ui-settings-store.js +1 -1
- package/server/lib/static-cache-control.js +18 -0
- package/server/lib/static-cache-control.test.js +25 -0
- package/server/lib/workspace/host.js +2 -0
- package/dist/assets/DiagramView-Bj1ZrdhI.js +0 -1
- package/dist/assets/FileSaveConflictDialog-2Z4V_gZU.js +0 -3
- package/dist/assets/FilesView-K18gBSws.js +0 -6
- package/dist/assets/GitView-Hm1KBPaD.js +0 -8
- package/dist/assets/JsonTreeView-fNsiZEIo.js +0 -1
- package/dist/assets/PatchDiff-DZaJG6jj.js +0 -1
- package/dist/assets/SessionSwitcherContent-RAsmsuYk.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-DuLPlIF_.js +0 -2
- package/dist/assets/SessionUnreadDot-Dm6k5OCd.js +0 -1
- package/dist/assets/SettingsView-Chu4zbWo.js +0 -6
- package/dist/assets/SettingsWindow-CJzFmmfu.js +0 -1
- package/dist/assets/ToolOutputDialog-uYeXsAGc.js +0 -8
- package/dist/assets/ToolPartDiffPreview-DnAHVRs-.js +0 -1
- package/dist/assets/Virtualizer-BSHVMKgK.js +0 -1
- package/dist/assets/collapsible-BH1vXEAI.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DXkR5jdw.js +0 -3
- package/dist/assets/gitStatusPredicates-BW8heN1a.js +0 -134
- package/dist/assets/index-5fyXnZFi.css +0 -1
- package/dist/assets/index-BrgKwTb0.js +0 -1
- package/dist/assets/index-C-sV_9sb.js +0 -8
- package/dist/assets/isDiffPlainText-DZFr1Tta.js +0 -1
- package/dist/assets/isFilePlainText-KNpEMvb-.js +0 -1
- package/dist/assets/main-BPY2ug1A.js +0 -135
- package/dist/assets/main-BRIjzIRl.js +0 -2
- package/dist/assets/markdownCore-DYizLr1N.js +0 -3
- package/dist/assets/miniChat-Dva4MINl.js +0 -2
- package/dist/assets/mobile-6jNUNv_x.js +0 -2
- package/dist/assets/permissionStore-iKN1K2_x.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-BIeBrZmO.js +0 -2
- package/dist/assets/renderMobileApp-BDCtZpeS.js +0 -11
- package/dist/assets/runtimeEndpointReset-DqdGOWp8.js +0 -53
- package/dist/assets/useAppFontEffects-BABx-DxZ.js +0 -6722
- package/dist/assets/usePushVisibilityBeacon-BciEu3HS.js +0 -10
- package/dist/assets/useSwitcherItems-C7_5TB_n.js +0 -1
- package/dist/assets/vendor-aria-hidden-DvXkyWUv.js +0 -1
- package/dist/assets/vendor-base-ui-DXSHfszQ.js +0 -1
- package/dist/assets/vendor-class-variance-authority-5VPnzWs2.js +0 -1
- package/dist/assets/vendor-cmdk-zXx6sGnS.js +0 -1
- package/dist/assets/vendor-codemirror-autocomplete-wd6iRebq.js +0 -1
- package/dist/assets/vendor-codemirror-commands-CNlncqrr.js +0 -1
- package/dist/assets/vendor-codemirror-lang-angular-DU_4KiiW.js +0 -1
- package/dist/assets/vendor-codemirror-lang-cpp-CmIT9Z5_.js +0 -1
- package/dist/assets/vendor-codemirror-lang-css-djiuoTi8.js +0 -1
- package/dist/assets/vendor-codemirror-lang-go-COZSwZYW.js +0 -7
- package/dist/assets/vendor-codemirror-lang-html-CKHqhW5R.js +0 -1
- package/dist/assets/vendor-codemirror-lang-java-CNMP5hyC.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js +0 -13
- package/dist/assets/vendor-codemirror-lang-jinja-DaKn_b1k.js +0 -1
- package/dist/assets/vendor-codemirror-lang-json-CZ07HmNC.js +0 -1
- package/dist/assets/vendor-codemirror-lang-less-wJdQiDBf.js +0 -1
- package/dist/assets/vendor-codemirror-lang-liquid-0z48Roi8.js +0 -1
- package/dist/assets/vendor-codemirror-lang-markdown-DtcZDGqe.js +0 -1
- package/dist/assets/vendor-codemirror-lang-php-W8plS-JQ.js +0 -1
- package/dist/assets/vendor-codemirror-lang-python-DzzokVau.js +0 -3
- package/dist/assets/vendor-codemirror-lang-rust-C4ulBVpf.js +0 -1
- package/dist/assets/vendor-codemirror-lang-sass-BkZJYEwS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-vue-DiBPljCc.js +0 -1
- package/dist/assets/vendor-codemirror-lang-wast-DoABsogh.js +0 -1
- package/dist/assets/vendor-codemirror-lang-xml-BhLJhOCH.js +0 -1
- package/dist/assets/vendor-codemirror-lang-yaml-D95i1Y5R.js +0 -1
- package/dist/assets/vendor-codemirror-language-BByA_dGF.js +0 -3
- package/dist/assets/vendor-codemirror-language-data-BB5mQv-R.js +0 -2
- package/dist/assets/vendor-codemirror-search-BV44140v.js +0 -2
- package/dist/assets/vendor-codemirror-state-CNWM3Q8V.js +0 -5
- package/dist/assets/vendor-codemirror-view-Ct4T37Ue.js +0 -4
- package/dist/assets/vendor-crelt-C8TCjufn.js +0 -1
- package/dist/assets/vendor-detect-node-es-l0sNRNKZ.js +0 -1
- package/dist/assets/vendor-dnd-kit-accessibility-DZKKhs9S.js +0 -1
- package/dist/assets/vendor-dnd-kit-core-C9qcAm_1.js +0 -5
- package/dist/assets/vendor-dnd-kit-sortable-D8ozj8M-.js +0 -1
- package/dist/assets/vendor-dnd-kit-utilities-DTY1C6ST.js +0 -1
- package/dist/assets/vendor-floating-ui-core-CXmKXOXc.js +0 -1
- package/dist/assets/vendor-floating-ui-dom-WyXykhNi.js +0 -1
- package/dist/assets/vendor-floating-ui-react-dom-BZOGXAGe.js +0 -1
- package/dist/assets/vendor-floating-ui-utils-BzXdqYpP.js +0 -1
- package/dist/assets/vendor-framer-motion-CfplGuM0.js +0 -1
- package/dist/assets/vendor-get-nonce-C-Z93AgS.js +0 -1
- package/dist/assets/vendor-lezer-common-B3-cUCR_.js +0 -1
- package/dist/assets/vendor-lezer-cpp-BleAU9o-.js +0 -1
- package/dist/assets/vendor-lezer-css-C5xB6jxd.js +0 -1
- package/dist/assets/vendor-lezer-go-CXK1UKk8.js +0 -1
- package/dist/assets/vendor-lezer-highlight-CDMHUZ74.js +0 -1
- package/dist/assets/vendor-lezer-html-C0I1p52t.js +0 -1
- package/dist/assets/vendor-lezer-java-D_zzj-NV.js +0 -1
- package/dist/assets/vendor-lezer-javascript-D7Tj24ot.js +0 -1
- package/dist/assets/vendor-lezer-json-Iaex0UN-.js +0 -1
- package/dist/assets/vendor-lezer-lr-bhwg1HMg.js +0 -1
- package/dist/assets/vendor-lezer-php-_DHrbsZG.js +0 -1
- package/dist/assets/vendor-lezer-python-CvuFxeZl.js +0 -1
- package/dist/assets/vendor-lezer-rust-Lqgd5SAo.js +0 -1
- package/dist/assets/vendor-lezer-sass-Dnm2lY4t.js +0 -1
- package/dist/assets/vendor-lezer-xml-hUDuAyS5.js +0 -1
- package/dist/assets/vendor-lezer-yaml-BNIl6S_O.js +0 -1
- package/dist/assets/vendor-marijn-find-cluster-break-DXwl3gUT.js +0 -1
- package/dist/assets/vendor-motion-dom-DhJ-sYS5.js +0 -1
- package/dist/assets/vendor-motion-l0sNRNKZ.js +0 -1
- package/dist/assets/vendor-motion-utils-CKEGc_YG.js +0 -1
- package/dist/assets/vendor-radix-ui-primitive-Dc_FVRD7.js +0 -1
- package/dist/assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js +0 -1
- package/dist/assets/vendor-radix-ui-react-context-CFsX-AUC.js +0 -1
- package/dist/assets/vendor-radix-ui-react-dialog-D2yhEu2p.js +0 -5
- package/dist/assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js +0 -1
- package/dist/assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js +0 -1
- package/dist/assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js +0 -1
- package/dist/assets/vendor-radix-ui-react-id-D2kS9K1j.js +0 -1
- package/dist/assets/vendor-radix-ui-react-portal-YgCRIyi7.js +0 -1
- package/dist/assets/vendor-radix-ui-react-presence-D432pCMB.js +0 -1
- package/dist/assets/vendor-radix-ui-react-primitive-DkH8dMOR.js +0 -1
- package/dist/assets/vendor-radix-ui-react-slot-BIDFZX0-.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-effect-event-D94va83M.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js +0 -1
- package/dist/assets/vendor-react-B5Z1Mdn3.js +0 -9
- package/dist/assets/vendor-react-remove-scroll-bar-CSAHp1YF.js +0 -38
- package/dist/assets/vendor-react-remove-scroll-vR1dy1aP.js +0 -4
- package/dist/assets/vendor-react-style-singleton-Ctw6HnYx.js +0 -1
- package/dist/assets/vendor-reselect-l0sNRNKZ.js +0 -1
- package/dist/assets/vendor-scheduler-7OC5HNn7.js +0 -1
- package/dist/assets/vendor-simplewebauthn-browser-VDA66rT_.js +0 -2
- package/dist/assets/vendor-sonner-BDtm25td.js +0 -1
- package/dist/assets/vendor-style-mod-NZ5MEPvj.js +0 -3
- package/dist/assets/vendor-tanstack-react-virtual-2skouoFw.js +0 -1
- package/dist/assets/vendor-tanstack-virtual-core-Dubg10g5.js +0 -1
- package/dist/assets/vendor-tslib-De9GV7Vy.js +0 -1
- package/dist/assets/vendor-use-callback-ref-CVVuCyLj.js +0 -1
- package/dist/assets/vendor-use-sidecar-Vv4V8Nd1.js +0 -1
- package/dist/assets/vendor-use-sync-external-store-D0AXkdQC.js +0 -1
- package/dist/assets/vendor-w3c-keyname-Vcq4gwWv.js +0 -1
- package/dist/assets/vendor-zustand-GVb4H8HE.js +0 -6
- package/server/lib/git/credentials.js +0 -41
- package/server/lib/git/identity-storage.js +0 -122
- /package/dist/assets/{vendor-katex-CNckGUMB.js → vendor-katex-DZG0Ov6p.js} +0 -0
- /package/dist/assets/{vendor-katex-Cp579UoJ.css → vendor-katex-css-Cp579UoJ.css} +0 -0
- /package/dist/assets/{vendor-xterm-xterm-CrXqRur4.js → vendor-xterm-xterm-B-qIQCd3.js} +0 -0
- /package/dist/assets/{vendor-xterm-xterm-DDGTF8rc.css → vendor-xterm-xterm-css-DDGTF8rc.css} +0 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
/** Thin Express adapter for `/api/github/*` (§5.3). See DOCUMENTATION.md. */
|
|
2
|
+
|
|
3
|
+
import { createChecksService } from './checks.js';
|
|
4
|
+
import { createGitHubClient } from './client.js';
|
|
5
|
+
import { createContextBuilder } from './context.js';
|
|
6
|
+
import { createCredentialStore } from './credential.js';
|
|
7
|
+
import {
|
|
8
|
+
failed,
|
|
9
|
+
inputError,
|
|
10
|
+
isGitHubIntegrationError,
|
|
11
|
+
toErrorBody,
|
|
12
|
+
toHttpStatus,
|
|
13
|
+
unavailable,
|
|
14
|
+
} from './errors.js';
|
|
15
|
+
import { createGhCli, formatVersion } from './gh-cli.js';
|
|
16
|
+
import { createIssuesService } from './issues.js';
|
|
17
|
+
import { createPullsService } from './pulls.js';
|
|
18
|
+
import { getViewerPermission } from './repo-scope.js';
|
|
19
|
+
import { createTemplatesService } from './templates.js';
|
|
20
|
+
import { createRepoInfoLoader, createRepoScopeResolver, isValidIssueNumber, parseRepoRef } from './repo-scope.js';
|
|
21
|
+
|
|
22
|
+
const readTrimmedParam = (req, name) => {
|
|
23
|
+
const fromQuery = Array.isArray(req.query?.[name]) ? req.query[name][0] : req.query?.[name];
|
|
24
|
+
const fromBody = typeof req.body?.[name] === 'string' ? req.body[name] : null;
|
|
25
|
+
const value = typeof fromQuery === 'string' && fromQuery.trim() ? fromQuery : fromBody;
|
|
26
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const readDirectory = (req) => readTrimmedParam(req, 'directory');
|
|
30
|
+
|
|
31
|
+
const readRepoParam = (req) => readTrimmedParam(req, 'repo');
|
|
32
|
+
|
|
33
|
+
// Fork enrichment fan-out is paced so a large scope cannot burst dozens of
|
|
34
|
+
// concurrent API calls on first load (repeat loads hit the repo-info cache).
|
|
35
|
+
const SCOPE_ENRICH_CONCURRENCY = 4;
|
|
36
|
+
|
|
37
|
+
const readNumberParam = (req, name = 'number') => {
|
|
38
|
+
const raw = req.params?.[name] ?? req.query?.[name] ?? req.body?.[name];
|
|
39
|
+
return raw;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const sendIntegrationError = (res, error) => {
|
|
43
|
+
if (isGitHubIntegrationError(error)) {
|
|
44
|
+
return res.status(toHttpStatus(error)).json(toErrorBody(error));
|
|
45
|
+
}
|
|
46
|
+
console.error('GitHub route failed:', error?.message || error);
|
|
47
|
+
return res.status(502).json({ error: { kind: 'failed', message: 'GitHub request failed unexpectedly.' } });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const PR_ACTIONS = new Set(['merge', 'squash', 'rebase', 'ready', 'draft', 'close', 'reopen', 'update-branch']);
|
|
51
|
+
const THREAD_ACTIONS = new Set(['reply', 'resolve', 'unresolve']);
|
|
52
|
+
const CONTEXT_TYPES = new Set(['issue', 'pr', 'checks', 'threads']);
|
|
53
|
+
|
|
54
|
+
const slugifyBranchPart = (value) => String(value || '')
|
|
55
|
+
.toLowerCase()
|
|
56
|
+
.replace(/[^a-z0-9_-]+/g, '-')
|
|
57
|
+
.replace(/^-+|-+$/g, '')
|
|
58
|
+
.slice(0, 40) || 'pr';
|
|
59
|
+
|
|
60
|
+
const loadGitService = async () => {
|
|
61
|
+
try {
|
|
62
|
+
const service = await import('../git/service.js');
|
|
63
|
+
if (typeof service.validateWorktreeCreate === 'function' && typeof service.createWorktree === 'function') {
|
|
64
|
+
return service;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const createGitHubRoutes = (overrides = {}) => {
|
|
73
|
+
const ghCli = overrides.ghCli || createGhCli();
|
|
74
|
+
const credential = overrides.credential || createCredentialStore({ ghCli });
|
|
75
|
+
const client = overrides.client || createGitHubClient();
|
|
76
|
+
const scopeResolver = overrides.scopeResolver || createRepoScopeResolver();
|
|
77
|
+
const repoInfo = overrides.repoInfo || createRepoInfoLoader({ client });
|
|
78
|
+
const resolveViewer = async (cred) => credential.getViewer(cred, async () => {
|
|
79
|
+
const response = await client.request({ credential: cred, host: cred.host, method: 'GET', path: '/user', operation: 'viewer lookup' });
|
|
80
|
+
const login = response.body?.login;
|
|
81
|
+
if (typeof login !== 'string' || !login) throw failed('Could not resolve the signed-in GitHub user.');
|
|
82
|
+
return login;
|
|
83
|
+
}).catch(() => null);
|
|
84
|
+
const resolvePermission = (cred, repo) => getViewerPermission(
|
|
85
|
+
(credential, repoRef) => repoInfo.getRepoInfo(credential, repoRef),
|
|
86
|
+
cred,
|
|
87
|
+
repo,
|
|
88
|
+
);
|
|
89
|
+
const pulls = overrides.pulls || createPullsService({ client, resolveViewer, resolvePermission });
|
|
90
|
+
const issues = overrides.issues || createIssuesService({ client, resolveViewer, resolvePermission });
|
|
91
|
+
const checks = overrides.checks || createChecksService({ client });
|
|
92
|
+
const templates = overrides.templates || createTemplatesService({ client });
|
|
93
|
+
const contextBuilder = overrides.contextBuilder || createContextBuilder();
|
|
94
|
+
const gitRunner = overrides.gitRunner || null;
|
|
95
|
+
|
|
96
|
+
const runGitForCheckout = async (cwd, args) => {
|
|
97
|
+
if (gitRunner) return gitRunner(cwd, args);
|
|
98
|
+
const { execFile } = await import('node:child_process');
|
|
99
|
+
const { promisify } = await import('node:util');
|
|
100
|
+
const execFileAsync = promisify(execFile);
|
|
101
|
+
try {
|
|
102
|
+
const result = await execFileAsync('git', args, {
|
|
103
|
+
cwd,
|
|
104
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never', GIT_ASKPASS: '', SSH_ASKPASS: '' },
|
|
105
|
+
timeout: 60_000,
|
|
106
|
+
windowsHide: true,
|
|
107
|
+
maxBuffer: 4 * 1024 * 1024,
|
|
108
|
+
});
|
|
109
|
+
return { success: true, stdout: String(result?.stdout || '') };
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return { success: false, stdout: String(error?.stdout || ''), message: String(error?.message || 'Git command failed') };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// Best-effort safe fast-forward of a leftover local branch to the fetched
|
|
116
|
+
// PR head: only moves when the branch is an ancestor of the head, so local
|
|
117
|
+
// commits or divergence are never discarded.
|
|
118
|
+
const fastForwardBranchToHeadIfSafe = async (cwd, branch, head) => {
|
|
119
|
+
const ancestor = await runGitForCheckout(cwd, ['merge-base', '--is-ancestor', branch, head]);
|
|
120
|
+
if (!ancestor.success) return;
|
|
121
|
+
await runGitForCheckout(cwd, ['branch', '-f', branch, head]);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Resolve directory → scope → allow-listed repo → pinned credential, then
|
|
126
|
+
* run the handler. Rejects unknown repos with `no-access`.
|
|
127
|
+
*/
|
|
128
|
+
const withRepoContext = async (req, res, handler) => {
|
|
129
|
+
try {
|
|
130
|
+
const directory = readDirectory(req);
|
|
131
|
+
if (!directory) {
|
|
132
|
+
return res.status(400).json({ error: { kind: 'failed', message: 'directory parameter is required.' } });
|
|
133
|
+
}
|
|
134
|
+
const repoParam = readRepoParam(req);
|
|
135
|
+
if (!repoParam) {
|
|
136
|
+
return res.status(400).json({ error: { kind: 'failed', message: 'repo parameter is required (host/owner/name).' } });
|
|
137
|
+
}
|
|
138
|
+
if (!parseRepoRef(repoParam)) {
|
|
139
|
+
return res.status(400).json({ error: { kind: 'failed', message: 'repo must be host/owner/name with valid owner and repo names.' } });
|
|
140
|
+
}
|
|
141
|
+
const scope = await scopeResolver.resolveScope(directory);
|
|
142
|
+
const entry = scopeResolver.matchAllowedRepo(scope, repoParam);
|
|
143
|
+
if (!entry) {
|
|
144
|
+
return res.status(403).json({ error: { kind: 'unavailable', reason: 'no-access' } });
|
|
145
|
+
}
|
|
146
|
+
const repo = { host: entry.host, owner: entry.owner, repo: entry.repo };
|
|
147
|
+
const payload = await credential.withPinnedCredential(repo.host, (cred) => handler({ scope, entry, repo, credential: cred }));
|
|
148
|
+
return res.json(payload);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
return sendIntegrationError(res, error);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const withNumber = async (req, res, handler) => withRepoContext(req, res, async (context) => {
|
|
155
|
+
const raw = readNumberParam(req);
|
|
156
|
+
if (!isValidIssueNumber(raw)) {
|
|
157
|
+
throw inputError('Invalid number parameter.');
|
|
158
|
+
}
|
|
159
|
+
return handler({ ...context, number: Number(raw) });
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const handlers = {
|
|
163
|
+
getStatus: async (req, res) => {
|
|
164
|
+
try {
|
|
165
|
+
const binary = await ghCli.resolveGhBinary();
|
|
166
|
+
if (!binary) {
|
|
167
|
+
throw unavailable('gh-missing');
|
|
168
|
+
}
|
|
169
|
+
const version = await ghCli.getVersion().catch(() => null);
|
|
170
|
+
const { hosts } = await ghCli.getAuthState();
|
|
171
|
+
return res.json({
|
|
172
|
+
installed: true,
|
|
173
|
+
version: version ? formatVersion(version) : null,
|
|
174
|
+
hosts: hosts.map((host) => ({
|
|
175
|
+
host: host.host,
|
|
176
|
+
authenticated: host.authenticated === true,
|
|
177
|
+
login: host.login || null,
|
|
178
|
+
scopes: host.scopes || [],
|
|
179
|
+
})),
|
|
180
|
+
fetchedAt: Date.now(),
|
|
181
|
+
});
|
|
182
|
+
} catch (error) {
|
|
183
|
+
return sendIntegrationError(res, error);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
getScope: async (req, res) => {
|
|
188
|
+
try {
|
|
189
|
+
const directory = readDirectory(req);
|
|
190
|
+
if (!directory) {
|
|
191
|
+
return res.status(400).json({ error: { kind: 'failed', message: 'directory parameter is required.' } });
|
|
192
|
+
}
|
|
193
|
+
const scope = await scopeResolver.resolveScope(directory);
|
|
194
|
+
// Best-effort fork enrichment: needs a credential, never fails scope.
|
|
195
|
+
// Every entry is enriched (the UI reads fork/parent/defaultBranch for
|
|
196
|
+
// whichever repository is selected), paced to bound burst load.
|
|
197
|
+
const byHost = new Map();
|
|
198
|
+
for (const entry of scope.repositories) {
|
|
199
|
+
if (!entry.host) continue;
|
|
200
|
+
if (!byHost.has(entry.host)) byHost.set(entry.host, []);
|
|
201
|
+
byHost.get(entry.host).push(entry);
|
|
202
|
+
}
|
|
203
|
+
await Promise.all([...byHost.entries()].map(async ([host, entries]) => {
|
|
204
|
+
try {
|
|
205
|
+
await credential.withPinnedCredential(host, async (cred) => {
|
|
206
|
+
for (let start = 0; start < entries.length; start += SCOPE_ENRICH_CONCURRENCY) {
|
|
207
|
+
await Promise.all(entries.slice(start, start + SCOPE_ENRICH_CONCURRENCY).map(async (entry) => {
|
|
208
|
+
try {
|
|
209
|
+
const info = await repoInfo.getRepoInfo(cred, { host: entry.host, owner: entry.owner, repo: entry.repo });
|
|
210
|
+
entry.fork = info.isFork;
|
|
211
|
+
entry.parent = info.parent;
|
|
212
|
+
entry.defaultBranch = info.defaultBranch;
|
|
213
|
+
} catch {
|
|
214
|
+
entry.fork = null;
|
|
215
|
+
}
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
} catch {
|
|
220
|
+
// Unauthenticated: fork stays null, scope still succeeds.
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
return res.json(scope);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return sendIntegrationError(res, error);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
listPulls: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => pulls.listPulls(cred, repo, {
|
|
230
|
+
state: req.query.state || 'open',
|
|
231
|
+
filter: req.query.filter || 'all',
|
|
232
|
+
q: req.query.q || '',
|
|
233
|
+
cursor: req.query.cursor || null,
|
|
234
|
+
sort: req.query.sort || 'updated',
|
|
235
|
+
perPage: req.query.perPage ?? undefined,
|
|
236
|
+
})),
|
|
237
|
+
|
|
238
|
+
getPull: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => pulls.getPull(cred, repo, number)),
|
|
239
|
+
|
|
240
|
+
listPullFiles: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => pulls.listFiles(cred, repo, number, {
|
|
241
|
+
cursor: req.query.cursor || null,
|
|
242
|
+
})),
|
|
243
|
+
|
|
244
|
+
// Head SHA comes from one single-resource read, not the detail fan-out.
|
|
245
|
+
getPullChecks: (req, res) => withNumber(req, res, async ({ repo, credential: cred, number }) => {
|
|
246
|
+
const headSha = await pulls.getPullHeadSha(cred, repo, number);
|
|
247
|
+
return checks.getChecks(cred, repo, headSha, { details: req.query.details === 'full' });
|
|
248
|
+
}),
|
|
249
|
+
|
|
250
|
+
getPrStatus: async (req, res) => {
|
|
251
|
+
try {
|
|
252
|
+
const directory = readDirectory(req);
|
|
253
|
+
if (!directory) {
|
|
254
|
+
return res.status(400).json({ error: { kind: 'failed', message: 'directory parameter is required.' } });
|
|
255
|
+
}
|
|
256
|
+
const requestedBranch = typeof req.query.branch === 'string' && req.query.branch.trim() ? req.query.branch.trim() : null;
|
|
257
|
+
const scope = await scopeResolver.resolveScope(directory);
|
|
258
|
+
const branch = requestedBranch || scope.branch;
|
|
259
|
+
if (!branch) {
|
|
260
|
+
return res.json({ branch: null, pr: null, checks: null, fetchedAt: Date.now() });
|
|
261
|
+
}
|
|
262
|
+
const containing = scope.repositories.find((entry) => entry.kind === 'containing' && entry.host);
|
|
263
|
+
if (!containing) {
|
|
264
|
+
throw unavailable(scope.topLevel ? 'not-github' : 'no-repository');
|
|
265
|
+
}
|
|
266
|
+
const repo = { host: containing.host, owner: containing.owner, repo: containing.repo };
|
|
267
|
+
const payload = await credential.withPinnedCredential(repo.host, async (cred) => {
|
|
268
|
+
let defaultBranch = containing.defaultBranch || null;
|
|
269
|
+
if (!defaultBranch) {
|
|
270
|
+
try {
|
|
271
|
+
const info = await repoInfo.getRepoInfo(cred, repo);
|
|
272
|
+
defaultBranch = info.defaultBranch;
|
|
273
|
+
} catch {
|
|
274
|
+
defaultBranch = null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (defaultBranch && branch === defaultBranch) {
|
|
278
|
+
return { repo, branch, pr: null, skippedDefaultBranch: true, defaultBranch, fetchedAt: Date.now() };
|
|
279
|
+
}
|
|
280
|
+
const found = await pulls.findPullForBranch(cred, repo, { branch, headOwner: repo.owner, defaultBranch });
|
|
281
|
+
if (!found.pr || found.pr.state !== 'open' || !found.pr.headSha) {
|
|
282
|
+
return { repo, branch, pr: found.pr, defaultBranch, fetchedAt: found.fetchedAt };
|
|
283
|
+
}
|
|
284
|
+
const checkResult = await checks.getChecks(cred, repo, found.pr.headSha, { details: false }).catch(() => null);
|
|
285
|
+
return {
|
|
286
|
+
repo, branch, pr: found.pr,
|
|
287
|
+
checks: checkResult?.summary || null,
|
|
288
|
+
defaultBranch,
|
|
289
|
+
fetchedAt: Date.now(),
|
|
290
|
+
...(checkResult?.stale ? { checksStale: true } : {}),
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
return res.json(payload);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
return sendIntegrationError(res, error);
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
createPull: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => pulls.createPull(cred, repo, {
|
|
300
|
+
title: req.body?.title,
|
|
301
|
+
head: req.body?.head,
|
|
302
|
+
base: req.body?.base,
|
|
303
|
+
body: req.body?.body,
|
|
304
|
+
draft: req.body?.draft,
|
|
305
|
+
})),
|
|
306
|
+
|
|
307
|
+
runPullAction: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => {
|
|
308
|
+
const action = String(req.body?.action || '').trim();
|
|
309
|
+
if (!PR_ACTIONS.has(action)) {
|
|
310
|
+
throw inputError('Unknown pull request action.');
|
|
311
|
+
}
|
|
312
|
+
return pulls.runAction(cred, repo, number, action, { expectedHeadSha: req.body?.expectedHeadSha });
|
|
313
|
+
}),
|
|
314
|
+
|
|
315
|
+
listPullComments: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => pulls.listPullComments(cred, repo, number, {
|
|
316
|
+
cursor: req.query.cursor || null,
|
|
317
|
+
})),
|
|
318
|
+
|
|
319
|
+
commentOnPull: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => pulls.postComment(cred, repo, number, {
|
|
320
|
+
body: req.body?.body,
|
|
321
|
+
})),
|
|
322
|
+
|
|
323
|
+
reviewPull: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => pulls.submitReview(cred, repo, number, {
|
|
324
|
+
event: req.body?.event,
|
|
325
|
+
body: req.body?.body,
|
|
326
|
+
comments: req.body?.comments,
|
|
327
|
+
commitId: req.body?.commitId,
|
|
328
|
+
})),
|
|
329
|
+
|
|
330
|
+
threadAction: async (req, res) => {
|
|
331
|
+
const threadId = req.params.threadId;
|
|
332
|
+
const action = String(req.body?.action || '').trim();
|
|
333
|
+
if (typeof threadId !== 'string' || !threadId.trim() || threadId.length > 200 || !THREAD_ACTIONS.has(action)) {
|
|
334
|
+
return res.status(400).json({ error: { kind: 'failed', message: 'A valid thread id and action (reply|resolve|unresolve) are required.' } });
|
|
335
|
+
}
|
|
336
|
+
return withNumber(req, res, ({ repo, credential: cred, number }) => {
|
|
337
|
+
if (action === 'reply') {
|
|
338
|
+
const commentId = Number(req.body?.commentId ?? threadId);
|
|
339
|
+
if (!isValidIssueNumber(commentId)) throw inputError('A numeric comment id is required to reply.');
|
|
340
|
+
return pulls.replyToThread(cred, repo, number, commentId, { body: req.body?.body });
|
|
341
|
+
}
|
|
342
|
+
return pulls.setThreadResolved(cred, repo, number, threadId, action === 'resolve');
|
|
343
|
+
});
|
|
344
|
+
},
|
|
345
|
+
|
|
346
|
+
updatePull: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => pulls.updatePull(cred, repo, number, {
|
|
347
|
+
title: req.body?.title,
|
|
348
|
+
body: req.body?.body,
|
|
349
|
+
})),
|
|
350
|
+
|
|
351
|
+
checkoutPull: (req, res) => withNumber(req, res, async ({ scope, entry, repo, credential: cred, number }) => {
|
|
352
|
+
const mode = req.body?.mode === 'current' ? 'current' : 'worktree';
|
|
353
|
+
const detail = await pulls.getPull(cred, repo, number);
|
|
354
|
+
const headRef = detail.pr?.head;
|
|
355
|
+
if (!headRef) throw failed('Pull request has no head branch.');
|
|
356
|
+
const branchName = `pr-${number}-${slugifyBranchPart(headRef)}`;
|
|
357
|
+
const remoteName = entry.remote || 'origin';
|
|
358
|
+
const fetchResult = await runGitForCheckout(scope.topLevel || scope.directory, ['fetch', remoteName, `refs/pull/${number}/head`]);
|
|
359
|
+
if (!fetchResult.success) {
|
|
360
|
+
throw failed('Could not fetch the pull request head from the remote.');
|
|
361
|
+
}
|
|
362
|
+
const shaResult = await runGitForCheckout(scope.topLevel || scope.directory, ['rev-parse', 'FETCH_HEAD']);
|
|
363
|
+
const headSha = shaResult.success ? shaResult.stdout.trim().split('\n')[0]?.trim() : null;
|
|
364
|
+
if (!headSha) throw failed('Could not resolve the fetched pull request head.');
|
|
365
|
+
const gitService = await loadGitService();
|
|
366
|
+
if (!gitService) {
|
|
367
|
+
throw failed('Pull request checkout is temporarily unavailable while the worktree service is being refactored. The branch fetch succeeded; create the worktree manually from the fetched head.');
|
|
368
|
+
}
|
|
369
|
+
if (mode === 'current') {
|
|
370
|
+
if (typeof gitService.checkoutBranch === 'function') {
|
|
371
|
+
const cwd = scope.topLevel || scope.directory;
|
|
372
|
+
const existing = await runGitForCheckout(cwd, ['show-ref', '--verify', '--quiet', `refs/heads/${branchName}`]);
|
|
373
|
+
if (!existing.success) {
|
|
374
|
+
const create = await runGitForCheckout(cwd, ['branch', branchName, headSha]);
|
|
375
|
+
if (!create.success) throw failed('Could not create the local pull request branch.');
|
|
376
|
+
} else if (typeof gitService.getWorktrees === 'function') {
|
|
377
|
+
try {
|
|
378
|
+
const worktrees = await gitService.getWorktrees(scope.directory);
|
|
379
|
+
const checkedOut = Array.isArray(worktrees) && worktrees.some((entry) => !entry?.prunable && entry?.branch === branchName);
|
|
380
|
+
if (!checkedOut) {
|
|
381
|
+
await fastForwardBranchToHeadIfSafe(cwd, branchName, headSha);
|
|
382
|
+
}
|
|
383
|
+
} catch {
|
|
384
|
+
// Best-effort: checkout still proceeds on the existing branch.
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
await gitService.checkoutBranch(scope.directory, branchName, {});
|
|
388
|
+
return { ok: true, mode, branch: branchName, headSha, path: scope.directory, fetchedAt: Date.now() };
|
|
389
|
+
}
|
|
390
|
+
throw failed('Checking out into the current directory is not supported by the worktree service build.');
|
|
391
|
+
}
|
|
392
|
+
const cwd = scope.topLevel || scope.directory;
|
|
393
|
+
const branchExists = await runGitForCheckout(cwd, ['show-ref', '--verify', '--quiet', `refs/heads/${branchName}`]);
|
|
394
|
+
if (branchExists.success) {
|
|
395
|
+
if (typeof gitService.getWorktrees === 'function') {
|
|
396
|
+
try {
|
|
397
|
+
const worktrees = await gitService.getWorktrees(scope.directory);
|
|
398
|
+
const reused = Array.isArray(worktrees)
|
|
399
|
+
? worktrees.find((entry) => !entry?.prunable && entry?.branch === branchName)
|
|
400
|
+
: null;
|
|
401
|
+
if (reused) {
|
|
402
|
+
return { ok: true, mode, branch: branchName, headSha, path: reused.path, worktree: reused, reused: true, fetchedAt: Date.now() };
|
|
403
|
+
}
|
|
404
|
+
} catch {
|
|
405
|
+
// Fall through to the existing-branch attach below.
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
await fastForwardBranchToHeadIfSafe(cwd, branchName, headSha);
|
|
409
|
+
const existingValidation = await gitService.validateWorktreeCreate(scope.directory, { mode: 'existing', existingBranch: branchName });
|
|
410
|
+
if (!existingValidation?.ok) {
|
|
411
|
+
throw failed(existingValidation?.errors?.[0]?.message || 'Worktree creation failed validation.');
|
|
412
|
+
}
|
|
413
|
+
const existingCreated = await gitService.createWorktree(scope.directory, { mode: 'existing', existingBranch: branchName });
|
|
414
|
+
pulls.invalidate(cred, repo, number);
|
|
415
|
+
return { ok: true, mode, branch: branchName, headSha, path: existingCreated?.path || null, worktree: existingCreated || null, fetchedAt: Date.now() };
|
|
416
|
+
}
|
|
417
|
+
const validation = await gitService.validateWorktreeCreate(scope.directory, { mode: 'new', branchName, startRef: headSha });
|
|
418
|
+
if (!validation?.ok) {
|
|
419
|
+
throw failed(validation?.errors?.[0]?.message || 'Worktree creation failed validation.');
|
|
420
|
+
}
|
|
421
|
+
const created = await gitService.createWorktree(scope.directory, { mode: 'new', branchName, startRef: headSha });
|
|
422
|
+
pulls.invalidate(cred, repo, number);
|
|
423
|
+
return { ok: true, mode, branch: branchName, headSha, path: created?.path || null, worktree: created || null, fetchedAt: Date.now() };
|
|
424
|
+
}),
|
|
425
|
+
|
|
426
|
+
listIssues: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => issues.listIssues(cred, repo, {
|
|
427
|
+
state: req.query.state || 'open',
|
|
428
|
+
filter: req.query.filter || 'all',
|
|
429
|
+
q: req.query.q || '',
|
|
430
|
+
labels: req.query.labels || '',
|
|
431
|
+
cursor: req.query.cursor || null,
|
|
432
|
+
sort: req.query.sort || 'updated',
|
|
433
|
+
perPage: req.query.perPage ?? undefined,
|
|
434
|
+
})),
|
|
435
|
+
|
|
436
|
+
getIssue: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => issues.getIssue(cred, repo, number)),
|
|
437
|
+
|
|
438
|
+
listIssueComments: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => issues.listComments(cred, repo, number, {
|
|
439
|
+
cursor: req.query.cursor || null,
|
|
440
|
+
})),
|
|
441
|
+
|
|
442
|
+
createIssue: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => issues.createIssue(cred, repo, {
|
|
443
|
+
title: req.body?.title,
|
|
444
|
+
body: req.body?.body,
|
|
445
|
+
labels: req.body?.labels,
|
|
446
|
+
assignees: req.body?.assignees,
|
|
447
|
+
milestone: req.body?.milestone,
|
|
448
|
+
})),
|
|
449
|
+
|
|
450
|
+
updateIssue: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => issues.updateIssue(cred, repo, number, {
|
|
451
|
+
title: req.body?.title,
|
|
452
|
+
body: req.body?.body,
|
|
453
|
+
state: req.body?.state,
|
|
454
|
+
stateReason: req.body?.stateReason,
|
|
455
|
+
labels: req.body?.labels,
|
|
456
|
+
assignees: req.body?.assignees,
|
|
457
|
+
milestone: req.body?.milestone,
|
|
458
|
+
})),
|
|
459
|
+
|
|
460
|
+
commentOnIssue: (req, res) => withNumber(req, res, ({ repo, credential: cred, number }) => issues.postComment(cred, repo, number, {
|
|
461
|
+
body: req.body?.body,
|
|
462
|
+
})),
|
|
463
|
+
|
|
464
|
+
getTemplates: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => templates.listIssueTemplates(cred, repo)),
|
|
465
|
+
|
|
466
|
+
getMeta: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => {
|
|
467
|
+
const kinds = typeof req.query.kinds === 'string' && req.query.kinds
|
|
468
|
+
? req.query.kinds.split(',').map((kind) => kind.trim()).filter(Boolean)
|
|
469
|
+
: ['labels', 'assignees'];
|
|
470
|
+
return issues.listMeta(cred, repo, { kinds });
|
|
471
|
+
}),
|
|
472
|
+
|
|
473
|
+
getJobSteps: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => checks.getJobSteps(cred, repo, {
|
|
474
|
+
runId: req.query.runId,
|
|
475
|
+
jobId: req.query.jobId ?? null,
|
|
476
|
+
})),
|
|
477
|
+
|
|
478
|
+
getAnnotations: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => checks.getAnnotations(cred, repo, {
|
|
479
|
+
checkRunId: req.query.checkRunId,
|
|
480
|
+
})),
|
|
481
|
+
|
|
482
|
+
rerunFailed: (req, res) => withRepoContext(req, res, ({ repo, credential: cred }) => checks.rerunFailed(cred, repo, {
|
|
483
|
+
runId: req.body?.runId,
|
|
484
|
+
})),
|
|
485
|
+
|
|
486
|
+
getContext: (req, res) => withRepoContext(req, res, async ({ repo, credential: cred }) => {
|
|
487
|
+
const type = String(req.query.type || '').trim();
|
|
488
|
+
if (!CONTEXT_TYPES.has(type)) {
|
|
489
|
+
throw inputError('Context type must be issue, pr, checks, or threads.');
|
|
490
|
+
}
|
|
491
|
+
const rawNumber = req.query.number;
|
|
492
|
+
if (!isValidIssueNumber(rawNumber)) throw inputError('A valid number is required.');
|
|
493
|
+
const number = Number(rawNumber);
|
|
494
|
+
// Partial reads stay partial: a failed comments/files fetch is marked
|
|
495
|
+
// in the context text, never silently rendered as "no comments".
|
|
496
|
+
const withWarning = (promise, label) => promise.then(
|
|
497
|
+
(page) => ({ page, warning: null }),
|
|
498
|
+
(error) => ({ page: null, warning: `${label} could not be loaded (${error?.message || 'GitHub request failed'})` }),
|
|
499
|
+
);
|
|
500
|
+
if (type === 'issue') {
|
|
501
|
+
const [detail, commentsResult] = await Promise.all([
|
|
502
|
+
issues.getIssue(cred, repo, number),
|
|
503
|
+
withWarning(issues.listComments(cred, repo, number, {}), 'Comments'),
|
|
504
|
+
]);
|
|
505
|
+
const warnings = commentsResult.warning ? [commentsResult.warning] : [];
|
|
506
|
+
return { ...contextBuilder.buildIssueContext({ repo, issue: detail.issue, comments: commentsResult.page?.comments || [], warnings }), repo, number, fetchedAt: Date.now() };
|
|
507
|
+
}
|
|
508
|
+
if (type === 'pr') {
|
|
509
|
+
const includeDiff = req.query.includeDiff === 'true' || req.query.includeDiff === '1';
|
|
510
|
+
const [detail, filesResult] = await Promise.all([
|
|
511
|
+
pulls.getPull(cred, repo, number),
|
|
512
|
+
withWarning(pulls.listFiles(cred, repo, number, {}), 'Changed files'),
|
|
513
|
+
]);
|
|
514
|
+
const warnings = filesResult.warning ? [filesResult.warning] : [];
|
|
515
|
+
return { ...contextBuilder.buildPullContext({ repo, pr: detail.pr, files: filesResult.page?.files || [], threads: detail.threads || [], includeDiff, warnings }), repo, number, fetchedAt: Date.now() };
|
|
516
|
+
}
|
|
517
|
+
if (type === 'threads') {
|
|
518
|
+
const detail = await pulls.getPull(cred, repo, number);
|
|
519
|
+
return { ...contextBuilder.buildReviewThreadsContext({ repo, number, threads: detail.threads || [] }), repo, number, fetchedAt: Date.now() };
|
|
520
|
+
}
|
|
521
|
+
const ref = typeof req.query.ref === 'string' && req.query.ref.trim() ? req.query.ref.trim() : null;
|
|
522
|
+
let checkData = null;
|
|
523
|
+
if (type === 'checks') {
|
|
524
|
+
if (ref) {
|
|
525
|
+
checkData = await checks.getChecks(cred, repo, ref, { details: true });
|
|
526
|
+
} else {
|
|
527
|
+
const detail = await pulls.getPull(cred, repo, number);
|
|
528
|
+
if (!detail.pr?.headSha) throw failed('Pull request has no head commit to check.');
|
|
529
|
+
checkData = await checks.getChecks(cred, repo, detail.pr.headSha, { details: true });
|
|
530
|
+
}
|
|
531
|
+
return { ...contextBuilder.buildFailedChecksContext({ repo, ref: checkData.ref, checks: checkData }), repo, number, fetchedAt: Date.now() };
|
|
532
|
+
}
|
|
533
|
+
throw failed('Unknown context type.');
|
|
534
|
+
}),
|
|
535
|
+
|
|
536
|
+
invalidate: async (req, res) => {
|
|
537
|
+
try {
|
|
538
|
+
const directory = readDirectory(req);
|
|
539
|
+
const repoParam = readRepoParam(req);
|
|
540
|
+
const kind = typeof req.body?.kind === 'string' ? req.body.kind : (typeof req.query?.kind === 'string' ? req.query.kind : null);
|
|
541
|
+
const rawNumber = req.body?.number ?? req.query?.number;
|
|
542
|
+
const number = rawNumber !== undefined && rawNumber !== null ? Number(rawNumber) : null;
|
|
543
|
+
if (directory) scopeResolver.invalidate(directory);
|
|
544
|
+
else scopeResolver.invalidate();
|
|
545
|
+
const parsed = repoParam ? parseRepoRef(repoParam) : null;
|
|
546
|
+
const repo = parsed ? { host: parsed.host, owner: parsed.owner, repo: parsed.repo } : null;
|
|
547
|
+
if (!kind || kind === 'pulls' || kind === 'all') pulls.invalidate(null, repo, Number.isInteger(number) ? number : null);
|
|
548
|
+
if (!kind || kind === 'issues' || kind === 'all') issues.invalidate(null, repo, Number.isInteger(number) ? number : null);
|
|
549
|
+
if (!kind || kind === 'checks' || kind === 'all') checks.invalidate(null, repo);
|
|
550
|
+
if (!kind || kind === 'repo' || kind === 'all') repoInfo.invalidate(null, repo);
|
|
551
|
+
if (!kind || kind === 'repo' || kind === 'all') templates.invalidate(null, repo);
|
|
552
|
+
credential.invalidateViewer();
|
|
553
|
+
return res.json({ ok: true, fetchedAt: Date.now() });
|
|
554
|
+
} catch (error) {
|
|
555
|
+
return sendIntegrationError(res, error);
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
return {
|
|
561
|
+
...handlers,
|
|
562
|
+
_internals: { withRepoContext, ghCli, credential, client, scopeResolver, repoInfo, pulls, issues, checks },
|
|
563
|
+
};
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
export const registerGitHubRoutes = (app, dependencies = {}) => {
|
|
567
|
+
const routes = createGitHubRoutes(dependencies);
|
|
568
|
+
|
|
569
|
+
app.get('/api/github/status', routes.getStatus);
|
|
570
|
+
app.get('/api/github/scope', routes.getScope);
|
|
571
|
+
app.get('/api/github/pulls', routes.listPulls);
|
|
572
|
+
app.get('/api/github/pulls/:number', routes.getPull);
|
|
573
|
+
app.get('/api/github/pulls/:number/files', routes.listPullFiles);
|
|
574
|
+
app.get('/api/github/pulls/:number/checks', routes.getPullChecks);
|
|
575
|
+
app.get('/api/github/pr-status', routes.getPrStatus);
|
|
576
|
+
app.post('/api/github/pulls', routes.createPull);
|
|
577
|
+
app.post('/api/github/pulls/:number/actions', routes.runPullAction);
|
|
578
|
+
app.get('/api/github/pulls/:number/comments', routes.listPullComments);
|
|
579
|
+
app.post('/api/github/pulls/:number/comments', routes.commentOnPull);
|
|
580
|
+
app.post('/api/github/pulls/:number/reviews', routes.reviewPull);
|
|
581
|
+
app.post('/api/github/pulls/:number/threads/:threadId', routes.threadAction);
|
|
582
|
+
app.patch('/api/github/pulls/:number', routes.updatePull);
|
|
583
|
+
app.post('/api/github/pulls/:number/checkout', routes.checkoutPull);
|
|
584
|
+
app.get('/api/github/issues', routes.listIssues);
|
|
585
|
+
app.get('/api/github/issues/:number', routes.getIssue);
|
|
586
|
+
app.get('/api/github/issues/:number/comments', routes.listIssueComments);
|
|
587
|
+
app.post('/api/github/issues', routes.createIssue);
|
|
588
|
+
app.patch('/api/github/issues/:number', routes.updateIssue);
|
|
589
|
+
app.post('/api/github/issues/:number/comments', routes.commentOnIssue);
|
|
590
|
+
app.get('/api/github/meta', routes.getMeta);
|
|
591
|
+
app.get('/api/github/templates', routes.getTemplates);
|
|
592
|
+
app.get('/api/github/checks/jobs', routes.getJobSteps);
|
|
593
|
+
app.get('/api/github/checks/annotations', routes.getAnnotations);
|
|
594
|
+
app.post('/api/github/checks/rerun', routes.rerunFailed);
|
|
595
|
+
app.get('/api/github/context', routes.getContext);
|
|
596
|
+
app.post('/api/github/invalidate', routes.invalidate);
|
|
597
|
+
|
|
598
|
+
return routes;
|
|
599
|
+
};
|