ref0-git 0.0.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/app/apps/github/.dev.vars.example +6 -0
  2. package/app/apps/github/README.md +70 -0
  3. package/app/apps/github/THIRD_PARTY_NOTICES.md +214 -0
  4. package/app/apps/github/components.json +25 -0
  5. package/app/apps/github/generated/git-rest.ts +10444 -0
  6. package/app/apps/github/generated/routeTree.gen.ts +1242 -0
  7. package/app/apps/github/migrations/postgres/0001_auth.sql +46 -0
  8. package/app/apps/github/migrations/sql/0001_auth.sql +19 -0
  9. package/app/apps/github/migrations/sql/0002_passkeys.sql +9 -0
  10. package/app/apps/github/migrations/sql/0003_orgs.sql +22 -0
  11. package/app/apps/github/migrations/sql/0004_avatars.sql +6 -0
  12. package/app/apps/github/package.json +80 -0
  13. package/app/apps/github/src/branches/branch-list.tsx +385 -0
  14. package/app/apps/github/src/branches/branches.ts +55 -0
  15. package/app/apps/github/src/clients/allowed.ts +213 -0
  16. package/app/apps/github/src/clients/at-most.ts +17 -0
  17. package/app/apps/github/src/clients/avatars.ts +410 -0
  18. package/app/apps/github/src/clients/cached.ts +65 -0
  19. package/app/apps/github/src/clients/calls.ts +160 -0
  20. package/app/apps/github/src/clients/clients.ts +82 -0
  21. package/app/apps/github/src/clients/graphql.ts +50 -0
  22. package/app/apps/github/src/clients/host-answer.ts +28 -0
  23. package/app/apps/github/src/clients/host-calls.ts +382 -0
  24. package/app/apps/github/src/clients/icon-bytes.ts +203 -0
  25. package/app/apps/github/src/clients/proxy.ts +59 -0
  26. package/app/apps/github/src/clients/session-ended.ts +18 -0
  27. package/app/apps/github/src/clients/transfers.ts +212 -0
  28. package/app/apps/github/src/code/breadcrumbs.tsx +50 -0
  29. package/app/apps/github/src/code/code-page.tsx +147 -0
  30. package/app/apps/github/src/code/code-tree.tsx +338 -0
  31. package/app/apps/github/src/code/controls.tsx +230 -0
  32. package/app/apps/github/src/code/file-view.tsx +450 -0
  33. package/app/apps/github/src/code/files.ts +332 -0
  34. package/app/apps/github/src/code/folder-list.tsx +122 -0
  35. package/app/apps/github/src/code/go-to-file.tsx +131 -0
  36. package/app/apps/github/src/code/highlighted.tsx +58 -0
  37. package/app/apps/github/src/code/lines.ts +46 -0
  38. package/app/apps/github/src/code/load.ts +147 -0
  39. package/app/apps/github/src/code/markdown-files.ts +58 -0
  40. package/app/apps/github/src/code/places.ts +88 -0
  41. package/app/apps/github/src/code/ref-pages.ts +179 -0
  42. package/app/apps/github/src/code/ref-switcher.tsx +203 -0
  43. package/app/apps/github/src/code/refs.ts +142 -0
  44. package/app/apps/github/src/code/repo-home.tsx +240 -0
  45. package/app/apps/github/src/code/repo.ts +105 -0
  46. package/app/apps/github/src/code/saved-reads.ts +199 -0
  47. package/app/apps/github/src/code/saved.ts +110 -0
  48. package/app/apps/github/src/code/tree-fold.ts +186 -0
  49. package/app/apps/github/src/code/trees.ts +136 -0
  50. package/app/apps/github/src/components/avatar-picture.ts +53 -0
  51. package/app/apps/github/src/components/avatar-url.ts +16 -0
  52. package/app/apps/github/src/components/confirm-action.tsx +100 -0
  53. package/app/apps/github/src/components/count.tsx +24 -0
  54. package/app/apps/github/src/components/create-button.tsx +38 -0
  55. package/app/apps/github/src/components/file-icons/file-icons.css +225 -0
  56. package/app/apps/github/src/components/file-icons/file-icons.tsx +138 -0
  57. package/app/apps/github/src/components/filter.tsx +35 -0
  58. package/app/apps/github/src/components/hotkeys/hotkeys.tsx +255 -0
  59. package/app/apps/github/src/components/item-list.tsx +65 -0
  60. package/app/apps/github/src/components/language-dot.tsx +29 -0
  61. package/app/apps/github/src/components/list-toolbar.tsx +82 -0
  62. package/app/apps/github/src/components/markdown/editor.tsx +57 -0
  63. package/app/apps/github/src/components/markdown/markdown.css +177 -0
  64. package/app/apps/github/src/components/markdown/markdown.tsx +82 -0
  65. package/app/apps/github/src/components/owner-card.tsx +196 -0
  66. package/app/apps/github/src/components/pull-status.tsx +34 -0
  67. package/app/apps/github/src/components/recent.ts +41 -0
  68. package/app/apps/github/src/components/relative-time.tsx +78 -0
  69. package/app/apps/github/src/components/repos/icon-hashes.ts +91 -0
  70. package/app/apps/github/src/components/repos/new-repo-form.tsx +196 -0
  71. package/app/apps/github/src/components/repos/repo-icon.tsx +47 -0
  72. package/app/apps/github/src/components/repos/repo-list.tsx +528 -0
  73. package/app/apps/github/src/components/repos/your-repos.tsx +124 -0
  74. package/app/apps/github/src/components/review-state.tsx +75 -0
  75. package/app/apps/github/src/components/route-dialog.tsx +137 -0
  76. package/app/apps/github/src/components/save-button.tsx +58 -0
  77. package/app/apps/github/src/components/shell/app-shell.tsx +164 -0
  78. package/app/apps/github/src/components/shell/create-org-dialog.tsx +118 -0
  79. package/app/apps/github/src/components/shell/create-row.tsx +49 -0
  80. package/app/apps/github/src/components/shell/link-menu.tsx +94 -0
  81. package/app/apps/github/src/components/shell/nav-user.tsx +97 -0
  82. package/app/apps/github/src/components/shell/owner-repos.tsx +247 -0
  83. package/app/apps/github/src/components/shell/owner-switcher.tsx +104 -0
  84. package/app/apps/github/src/components/shell/repo-switcher.tsx +179 -0
  85. package/app/apps/github/src/components/shell/sections.ts +31 -0
  86. package/app/apps/github/src/components/shell/submenu-chevron.ts +147 -0
  87. package/app/apps/github/src/components/signin/device-card.tsx +139 -0
  88. package/app/apps/github/src/components/signin/login-form.tsx +88 -0
  89. package/app/apps/github/src/components/signin/signin-page.tsx +33 -0
  90. package/app/apps/github/src/components/signin/signup-form.tsx +106 -0
  91. package/app/apps/github/src/components/states/live-status.tsx +42 -0
  92. package/app/apps/github/src/components/states/states.tsx +126 -0
  93. package/app/apps/github/src/components/tab-indicator.tsx +143 -0
  94. package/app/apps/github/src/components/theme-choice.tsx +108 -0
  95. package/app/apps/github/src/components/theme-provider.tsx +126 -0
  96. package/app/apps/github/src/components/tones.ts +23 -0
  97. package/app/apps/github/src/components/ui/alert-dialog.tsx +187 -0
  98. package/app/apps/github/src/components/ui/alert.tsx +78 -0
  99. package/app/apps/github/src/components/ui/avatar.tsx +106 -0
  100. package/app/apps/github/src/components/ui/badge.tsx +51 -0
  101. package/app/apps/github/src/components/ui/breadcrumb.tsx +124 -0
  102. package/app/apps/github/src/components/ui/button-group.tsx +87 -0
  103. package/app/apps/github/src/components/ui/button.tsx +61 -0
  104. package/app/apps/github/src/components/ui/calendar.tsx +221 -0
  105. package/app/apps/github/src/components/ui/card.tsx +102 -0
  106. package/app/apps/github/src/components/ui/checkbox.tsx +26 -0
  107. package/app/apps/github/src/components/ui/collapsible.tsx +19 -0
  108. package/app/apps/github/src/components/ui/combobox.tsx +304 -0
  109. package/app/apps/github/src/components/ui/command.tsx +208 -0
  110. package/app/apps/github/src/components/ui/dialog.tsx +156 -0
  111. package/app/apps/github/src/components/ui/dropdown-menu.tsx +290 -0
  112. package/app/apps/github/src/components/ui/empty.tsx +100 -0
  113. package/app/apps/github/src/components/ui/field.tsx +236 -0
  114. package/app/apps/github/src/components/ui/hover-card.tsx +48 -0
  115. package/app/apps/github/src/components/ui/input-group.tsx +163 -0
  116. package/app/apps/github/src/components/ui/input.tsx +19 -0
  117. package/app/apps/github/src/components/ui/item.tsx +201 -0
  118. package/app/apps/github/src/components/ui/kbd.tsx +27 -0
  119. package/app/apps/github/src/components/ui/label.tsx +33 -0
  120. package/app/apps/github/src/components/ui/popover.tsx +87 -0
  121. package/app/apps/github/src/components/ui/radio-group.tsx +35 -0
  122. package/app/apps/github/src/components/ui/select.tsx +198 -0
  123. package/app/apps/github/src/components/ui/separator.tsx +22 -0
  124. package/app/apps/github/src/components/ui/sheet.tsx +138 -0
  125. package/app/apps/github/src/components/ui/sidebar.tsx +724 -0
  126. package/app/apps/github/src/components/ui/skeleton.tsx +13 -0
  127. package/app/apps/github/src/components/ui/sonner.tsx +47 -0
  128. package/app/apps/github/src/components/ui/styles.css +242 -0
  129. package/app/apps/github/src/components/ui/table.tsx +113 -0
  130. package/app/apps/github/src/components/ui/tabs.tsx +79 -0
  131. package/app/apps/github/src/components/ui/textarea.tsx +17 -0
  132. package/app/apps/github/src/components/ui/title.ts +6 -0
  133. package/app/apps/github/src/components/ui/toggle-group.tsx +89 -0
  134. package/app/apps/github/src/components/ui/toggle.tsx +42 -0
  135. package/app/apps/github/src/components/ui/tooltip.tsx +63 -0
  136. package/app/apps/github/src/components/user-avatar.tsx +145 -0
  137. package/app/apps/github/src/components/view-tabs.tsx +42 -0
  138. package/app/apps/github/src/context/context.ts +133 -0
  139. package/app/apps/github/src/diffs/blobs.ts +94 -0
  140. package/app/apps/github/src/diffs/diff-view.tsx +155 -0
  141. package/app/apps/github/src/diffs/files.ts +121 -0
  142. package/app/apps/github/src/diffs/hunks.tsx +454 -0
  143. package/app/apps/github/src/diffs/patch.ts +131 -0
  144. package/app/apps/github/src/diffs/rows.ts +137 -0
  145. package/app/apps/github/src/history/commit-diff.ts +54 -0
  146. package/app/apps/github/src/history/commit-list.tsx +207 -0
  147. package/app/apps/github/src/history/commit-page.tsx +147 -0
  148. package/app/apps/github/src/history/history.ts +129 -0
  149. package/app/apps/github/src/hooks/allowed.ts +31 -0
  150. package/app/apps/github/src/hooks/answers.ts +65 -0
  151. package/app/apps/github/src/hooks/avatars.ts +54 -0
  152. package/app/apps/github/src/hooks/draft.ts +38 -0
  153. package/app/apps/github/src/hooks/open-counts.ts +127 -0
  154. package/app/apps/github/src/hooks/profiles.ts +120 -0
  155. package/app/apps/github/src/hooks/repos.ts +440 -0
  156. package/app/apps/github/src/hooks/use-mobile.ts +19 -0
  157. package/app/apps/github/src/hooks/viewer.ts +39 -0
  158. package/app/apps/github/src/inbox/count.ts +70 -0
  159. package/app/apps/github/src/inbox/inbox-item.tsx +66 -0
  160. package/app/apps/github/src/inbox/inbox-page.tsx +572 -0
  161. package/app/apps/github/src/inbox/marks.ts +130 -0
  162. package/app/apps/github/src/inbox/release-tags.ts +65 -0
  163. package/app/apps/github/src/inbox/search.ts +97 -0
  164. package/app/apps/github/src/inbox/subjects.ts +184 -0
  165. package/app/apps/github/src/inbox/subscription-controls.tsx +184 -0
  166. package/app/apps/github/src/inbox/subscriptions.ts +189 -0
  167. package/app/apps/github/src/inbox/threads.ts +198 -0
  168. package/app/apps/github/src/issues/changes.ts +332 -0
  169. package/app/apps/github/src/issues/counts.ts +62 -0
  170. package/app/apps/github/src/issues/issue-list.tsx +682 -0
  171. package/app/apps/github/src/issues/issue-page.tsx +533 -0
  172. package/app/apps/github/src/issues/issues.ts +566 -0
  173. package/app/apps/github/src/issues/label-dialog.tsx +310 -0
  174. package/app/apps/github/src/issues/labels-page.tsx +119 -0
  175. package/app/apps/github/src/issues/new-issue.tsx +79 -0
  176. package/app/apps/github/src/issues/parts.tsx +71 -0
  177. package/app/apps/github/src/issues/picker.tsx +298 -0
  178. package/app/apps/github/src/issues/search.ts +238 -0
  179. package/app/apps/github/src/issues/sidebar.tsx +236 -0
  180. package/app/apps/github/src/lib/cn.ts +8 -0
  181. package/app/apps/github/src/lib/highlighting.ts +13 -0
  182. package/app/apps/github/src/live/follow.ts +129 -0
  183. package/app/apps/github/src/live/sse.ts +74 -0
  184. package/app/apps/github/src/live/use-follow.ts +37 -0
  185. package/app/apps/github/src/markdown/README.md +53 -0
  186. package/app/apps/github/src/markdown/allowed-html.ts +69 -0
  187. package/app/apps/github/src/markdown/context.ts +206 -0
  188. package/app/apps/github/src/markdown/images.ts +81 -0
  189. package/app/apps/github/src/markdown/lookup.ts +127 -0
  190. package/app/apps/github/src/markdown/patches.ts +299 -0
  191. package/app/apps/github/src/markdown/query.ts +25 -0
  192. package/app/apps/github/src/markdown/references.ts +158 -0
  193. package/app/apps/github/src/markdown/render.ts +103 -0
  194. package/app/apps/github/src/names/owners.ts +51 -0
  195. package/app/apps/github/src/names/repos.ts +24 -0
  196. package/app/apps/github/src/palette/palette.tsx +562 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +487 -0
  199. package/app/apps/github/src/palette/server.ts +107 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +606 -0
  202. package/app/apps/github/src/private-repos.ts +47 -0
  203. package/app/apps/github/src/pulls/compare-page.tsx +342 -0
  204. package/app/apps/github/src/pulls/files-tab.tsx +776 -0
  205. package/app/apps/github/src/pulls/live.ts +124 -0
  206. package/app/apps/github/src/pulls/merge-box.tsx +367 -0
  207. package/app/apps/github/src/pulls/merge-button.ts +86 -0
  208. package/app/apps/github/src/pulls/pull-list.tsx +235 -0
  209. package/app/apps/github/src/pulls/pull-page.tsx +474 -0
  210. package/app/apps/github/src/pulls/pull.ts +468 -0
  211. package/app/apps/github/src/pulls/pulls.ts +318 -0
  212. package/app/apps/github/src/pulls/review.ts +350 -0
  213. package/app/apps/github/src/pulls/search.ts +130 -0
  214. package/app/apps/github/src/queue/queue-page.tsx +405 -0
  215. package/app/apps/github/src/queue/queue.ts +231 -0
  216. package/app/apps/github/src/releases/latest-release.tsx +55 -0
  217. package/app/apps/github/src/releases/overview.tsx +30 -0
  218. package/app/apps/github/src/releases/release-form.tsx +353 -0
  219. package/app/apps/github/src/releases/release-list.tsx +173 -0
  220. package/app/apps/github/src/releases/release-view.tsx +183 -0
  221. package/app/apps/github/src/releases/releases.ts +308 -0
  222. package/app/apps/github/src/releases/tag-list.tsx +134 -0
  223. package/app/apps/github/src/router.tsx +46 -0
  224. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +33 -0
  225. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +28 -0
  226. package/app/apps/github/src/routes/$owner/$repo/_code.tsx +11 -0
  227. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +19 -0
  228. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +19 -0
  229. package/app/apps/github/src/routes/$owner/$repo/_releases.tsx +23 -0
  230. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +39 -0
  231. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +34 -0
  232. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +42 -0
  233. package/app/apps/github/src/routes/$owner/$repo/compare/$.tsx +19 -0
  234. package/app/apps/github/src/routes/$owner/$repo/index.tsx +24 -0
  235. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +50 -0
  236. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +53 -0
  237. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +43 -0
  238. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +22 -0
  239. package/app/apps/github/src/routes/$owner/$repo/pull/$number/checks.tsx +15 -0
  240. package/app/apps/github/src/routes/$owner/$repo/pull/$number/commits.tsx +15 -0
  241. package/app/apps/github/src/routes/$owner/$repo/pull/$number/files.tsx +15 -0
  242. package/app/apps/github/src/routes/$owner/$repo/pull/$number/index.tsx +19 -0
  243. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +52 -0
  244. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +48 -0
  245. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +22 -0
  246. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +58 -0
  247. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +40 -0
  248. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +35 -0
  249. package/app/apps/github/src/routes/$owner/$repo/route.tsx +102 -0
  250. package/app/apps/github/src/routes/$owner/$repo/settings/access.tsx +9 -0
  251. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +16 -0
  252. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/new.tsx +25 -0
  253. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +17 -0
  254. package/app/apps/github/src/routes/$owner/$repo/settings/route.tsx +28 -0
  255. package/app/apps/github/src/routes/$owner/$repo/settings/rules.tsx +12 -0
  256. package/app/apps/github/src/routes/$owner/$repo/tokens.tsx +16 -0
  257. package/app/apps/github/src/routes/$owner/index.tsx +45 -0
  258. package/app/apps/github/src/routes/-nav.tsx +293 -0
  259. package/app/apps/github/src/routes/-root-testing.ts +107 -0
  260. package/app/apps/github/src/routes/__root.tsx +225 -0
  261. package/app/apps/github/src/routes/api.auth.$.ts +18 -0
  262. package/app/apps/github/src/routes/downloads/$owner/$repo/$asset.tsx +10 -0
  263. package/app/apps/github/src/routes/file-icons[.]svg.ts +21 -0
  264. package/app/apps/github/src/routes/icons/$owner/$repo.tsx +14 -0
  265. package/app/apps/github/src/routes/icons/$owner/index.tsx +14 -0
  266. package/app/apps/github/src/routes/icons/index.tsx +12 -0
  267. package/app/apps/github/src/routes/index.tsx +48 -0
  268. package/app/apps/github/src/routes/login.tsx +24 -0
  269. package/app/apps/github/src/routes/login_.code.tsx +31 -0
  270. package/app/apps/github/src/routes/new.tsx +91 -0
  271. package/app/apps/github/src/routes/notifications.tsx +20 -0
  272. package/app/apps/github/src/routes/orgs/$owner/issues.tsx +8 -0
  273. package/app/apps/github/src/routes/orgs/$owner/pulls.tsx +8 -0
  274. package/app/apps/github/src/routes/orgs/$owner/releases.tsx +8 -0
  275. package/app/apps/github/src/routes/orgs/$owner/route.tsx +25 -0
  276. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +30 -0
  277. package/app/apps/github/src/routes/orgs/$owner/tokens.tsx +15 -0
  278. package/app/apps/github/src/routes/settings.tsx +54 -0
  279. package/app/apps/github/src/routes/signup.tsx +24 -0
  280. package/app/apps/github/src/routes/uploads/$owner/$repo/$release.tsx +10 -0
  281. package/app/apps/github/src/seed/acme.ts +498 -0
  282. package/app/apps/github/src/seed/licenses.ts +114 -0
  283. package/app/apps/github/src/seed/seed.ts +528 -0
  284. package/app/apps/github/src/server.ts +97 -0
  285. package/app/apps/github/src/settings/account-avatar.tsx +43 -0
  286. package/app/apps/github/src/settings/avatar-section.tsx +140 -0
  287. package/app/apps/github/src/settings/avatar.ts +58 -0
  288. package/app/apps/github/src/settings/general-settings.tsx +439 -0
  289. package/app/apps/github/src/settings/general.ts +73 -0
  290. package/app/apps/github/src/settings/hook-form.tsx +195 -0
  291. package/app/apps/github/src/settings/hook-list.tsx +166 -0
  292. package/app/apps/github/src/settings/hooks.ts +87 -0
  293. package/app/apps/github/src/settings/org-settings.tsx +228 -0
  294. package/app/apps/github/src/settings/orgs.ts +116 -0
  295. package/app/apps/github/src/settings/rule-list.tsx +72 -0
  296. package/app/apps/github/src/settings/rules.ts +27 -0
  297. package/app/apps/github/src/settings/settings-layout.tsx +114 -0
  298. package/app/apps/github/src/signin/approval.ts +186 -0
  299. package/app/apps/github/src/signin/auth-client.ts +127 -0
  300. package/app/apps/github/src/signin/auth.ts +753 -0
  301. package/app/apps/github/src/signin/avatars.ts +126 -0
  302. package/app/apps/github/src/signin/client-ip.ts +39 -0
  303. package/app/apps/github/src/signin/credentials.ts +26 -0
  304. package/app/apps/github/src/signin/device-code.ts +95 -0
  305. package/app/apps/github/src/signin/device-prompt.ts +125 -0
  306. package/app/apps/github/src/signin/errors.ts +135 -0
  307. package/app/apps/github/src/signin/host-session.ts +68 -0
  308. package/app/apps/github/src/signin/orgs.ts +283 -0
  309. package/app/apps/github/src/signin/owner-names.ts +183 -0
  310. package/app/apps/github/src/signin/person-lock.ts +104 -0
  311. package/app/apps/github/src/signin/seal.ts +88 -0
  312. package/app/apps/github/src/signin/seed-people.ts +92 -0
  313. package/app/apps/github/src/signin/session.ts +48 -0
  314. package/app/apps/github/src/signin/unborn.ts +110 -0
  315. package/app/apps/github/src/signin/viewer-orgs.ts +47 -0
  316. package/app/apps/github/src/signin/viewer.ts +74 -0
  317. package/app/apps/github/src/signin/with-headers.ts +14 -0
  318. package/app/apps/github/src/tokens/tokens-page.tsx +529 -0
  319. package/app/apps/github/src/tokens/tokens.ts +54 -0
  320. package/app/apps/github/tsconfig.json +25 -0
  321. package/app/apps/github/tsconfig.worker.json +24 -0
  322. package/app/apps/github/vite.config.ts +21 -0
  323. package/app/pnpm-workspace.yaml +216 -0
  324. package/app/tsconfig.base.json +127 -0
  325. package/dist/LICENSE +202 -0
  326. package/dist/cli/child.mjs +42 -0
  327. package/dist/cli/commands.mjs +23 -0
  328. package/dist/cli/credentials.mjs +84 -0
  329. package/dist/cli/documents.mjs +214 -0
  330. package/dist/cli/events.mjs +55 -0
  331. package/dist/cli/failure.mjs +105 -0
  332. package/dist/cli/folders.mjs +32 -0
  333. package/dist/cli/git-remote-ref0.d.mts +1 -0
  334. package/dist/cli/git-remote-ref0.mjs +29 -0
  335. package/dist/cli/git.mjs +69 -0
  336. package/dist/cli/helpers.mjs +184 -0
  337. package/dist/cli/hosts.mjs +127 -0
  338. package/dist/cli/node.mjs +15 -0
  339. package/dist/cli/output.mjs +135 -0
  340. package/dist/cli/prompt.mjs +35 -0
  341. package/dist/cli/queue.mjs +215 -0
  342. package/dist/cli/ref0-git.d.mts +1 -0
  343. package/dist/cli/ref0-git.mjs +144 -0
  344. package/dist/cli/repos.mjs +162 -0
  345. package/dist/cli/resources.mjs +131 -0
  346. package/dist/cli/run-end.mjs +57 -0
  347. package/dist/cli/runtime.mjs +50 -0
  348. package/dist/cli/setup.mjs +1410 -0
  349. package/dist/cli/sign-in.mjs +162 -0
  350. package/dist/cli/sign-ins.mjs +136 -0
  351. package/dist/cli/sqlite.mjs +28 -0
  352. package/dist/cli/tokens.mjs +141 -0
  353. package/dist/cli/vendor.mjs +123 -0
  354. package/dist/init/app.mjs +231 -0
  355. package/dist/init/astro.mjs +49 -0
  356. package/dist/init/choices.mjs +497 -0
  357. package/dist/init/cloudflare.mjs +324 -0
  358. package/dist/init/create.mjs +151 -0
  359. package/dist/init/detect.mjs +297 -0
  360. package/dist/init/files.mjs +80 -0
  361. package/dist/init/frameworks.mjs +248 -0
  362. package/dist/init/git-module.mjs +49 -0
  363. package/dist/init/github-routes.mjs +66 -0
  364. package/dist/init/jsonc.mjs +143 -0
  365. package/dist/init/metadata.mjs +48 -0
  366. package/dist/init/mounts.mjs +109 -0
  367. package/dist/init/next.mjs +203 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +460 -0
  370. package/dist/init/nuxt.mjs +115 -0
  371. package/dist/init/output.mjs +21 -0
  372. package/dist/init/plan.mjs +82 -0
  373. package/dist/init/range-major.mjs +257 -0
  374. package/dist/init/react-router.mjs +59 -0
  375. package/dist/init/routes.mjs +148 -0
  376. package/dist/init/shell.mjs +4 -0
  377. package/dist/init/stores.mjs +51 -0
  378. package/dist/init/sveltekit.mjs +139 -0
  379. package/dist/init/template.mjs +142 -0
  380. package/dist/init/templates.mjs +343 -0
  381. package/dist/init/vercel.mjs +384 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +48 -6
  385. package/README.md +0 -5
@@ -0,0 +1,121 @@
1
+ import type { components } from '@octokit/openapi-types';
2
+ import type { DiffLineAnnotation, SelectedLineRange } from '@pierre/diffs';
3
+ import * as Schema from 'effect/Schema';
4
+ import type { ReactNode } from 'react';
5
+
6
+ import { github } from '../clients/clients.ts';
7
+ import { nextCursor } from '../hooks/repos.ts';
8
+
9
+ /** A changed file, as GitHub's REST lists a pull request's or a comparison's. */
10
+ export type ChangedFile = components['schemas']['diff-entry'];
11
+
12
+ /** One page of changed files, and the cursor of the page after it, or none on the last. */
13
+ export interface FilePage {
14
+ readonly files: readonly ChangedFile[];
15
+ readonly next: string | undefined;
16
+ }
17
+
18
+ /**
19
+ * A list of changed files, a page at a time: `key` names it for the query cache, and `page`
20
+ * loads the page at a cursor, or the first.
21
+ */
22
+ export interface FileList {
23
+ readonly key: readonly (string | number)[];
24
+ readonly page: (after: string | undefined, signal: AbortSignal) => Promise<FilePage>;
25
+ }
26
+
27
+ /** The repo a diff is in and the two commits it's between, whose blobs **Load diff** reads. */
28
+ export interface Revisions {
29
+ readonly repo: string;
30
+ readonly base: string;
31
+ readonly head: string;
32
+ }
33
+
34
+ /**
35
+ * What a diff shows under its lines, such as review comments, and how a reader starts one: `of`
36
+ * places a file's notes by a key, `render` draws a key's, and `pick` takes lines picked from the
37
+ * gutter, which shows only when it's given.
38
+ */
39
+ export interface Notes {
40
+ readonly of: (path: string) => DiffLineAnnotation<string>[];
41
+ readonly render: (path: string, key: string) => ReactNode;
42
+ readonly pick: ((path: string, lines: SelectedLineRange) => void) | undefined;
43
+ }
44
+
45
+ /** As many files as GitHub's REST lists a page. */
46
+ const perPage = 100;
47
+
48
+ /** `owner/name` as the REST client's path parameters. */
49
+ export const repoPath = (repo: string) => {
50
+ const [owner = '', name = ''] = repo.split('/');
51
+
52
+ return { owner, repo: name };
53
+ };
54
+
55
+ /** A page's size and its cursor: the drop-in's, which GitHub's types don't name. */
56
+ const paging = (after: string | undefined) => ({ per_page: perPage, after });
57
+
58
+ /**
59
+ * A pull request's files at `head`, a page of 100 at a time, as the drop-in lists them, up to
60
+ * 3,000, so the lines shown are the head's a comment is posted on. The drop-in lists the files of
61
+ * the head it holds, and takes no head to list: so each page reads the pull request after its
62
+ * files, and if a push has moved it off `head`, calls `moved` and fails, for the caller to read
63
+ * the pull request again and list the new head's. A head that moves and then back between the
64
+ * two reads goes unseen.
65
+ */
66
+ export const pullFiles = (
67
+ repo: string,
68
+ number: number,
69
+ head: string,
70
+ moved: () => void,
71
+ ): FileList => ({
72
+ key: ['pull-files', repo, number, head],
73
+ page: async (after, signal) => {
74
+ const path = { ...repoPath(repo), pull_number: number };
75
+ const answer = await github.GET('/repos/{owner}/{repo}/pulls/{pull_number}/files', {
76
+ // A spread passes the cursor GitHub's types don't name.
77
+ params: { path, query: { ...paging(after) } },
78
+ signal,
79
+ });
80
+
81
+ if (answer.data === undefined) {
82
+ throw new Error(`${repo}#${number}'s files didn't load (${answer.response.status})`);
83
+ }
84
+
85
+ const now = await github.GET('/repos/{owner}/{repo}/pulls/{pull_number}', {
86
+ params: { path },
87
+ signal,
88
+ });
89
+
90
+ if (now.data === undefined) {
91
+ throw new Error(`${repo}#${number} didn't load (${now.response.status})`);
92
+ }
93
+
94
+ if (now.data.head.sha !== head) {
95
+ moved();
96
+ throw new Error(`${repo}#${number} has a new commit: reading its files again`);
97
+ }
98
+
99
+ return { files: answer.data, next: nextCursor(answer.response.headers.get('link')) };
100
+ },
101
+ });
102
+
103
+ /** Whether the drop-in answered a diff's text rather than its JSON, as a media type asks for. */
104
+ export const isText = Schema.is(Schema.String);
105
+
106
+ /** The two commits a comparison is between, and its files, which GitHub lists up to 300. */
107
+ export interface Compared {
108
+ /** The commit the diff is from: the merge base, as GitHub diffs `base...head`. */
109
+ readonly base: string;
110
+ readonly head: string;
111
+ readonly files: readonly ChangedFile[];
112
+ }
113
+
114
+ /**
115
+ * A comparison's files, from the answer its commits came in, so the list and its commits are of
116
+ * one pair of commits even when a branch moves between reads.
117
+ */
118
+ export const comparedFiles = (repo: string, compared: Compared): FileList => ({
119
+ key: ['compared-files', repo, compared.base, compared.head],
120
+ page: () => Promise.resolve({ files: compared.files, next: undefined }),
121
+ });
@@ -0,0 +1,454 @@
1
+ import {
2
+ Virtualizer,
3
+ type FileDiffLoadedFiles,
4
+ type FileDiffMetadata,
5
+ type SelectedLineRange,
6
+ } from '@pierre/diffs';
7
+ import { FileDiff, VirtualizerContext } from '@pierre/diffs/react';
8
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
9
+ import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
10
+
11
+ import { highlightedCharsMost, highlightedLinesMost } from '#/lib/highlighting';
12
+
13
+ import { FileIcon } from '../components/file-icons/file-icons.tsx';
14
+ import { useTheme } from '../components/theme-provider.tsx';
15
+ import { Button } from '../components/ui/button.tsx';
16
+ import { loadFile, type LoadedFile } from './blobs.ts';
17
+ import type { ChangedFile, Notes, Revisions } from './files.ts';
18
+ import { diffOfPatch, diffOfSides, wordDiffOf } from './patch.ts';
19
+ import {
20
+ drawnRows,
21
+ endsOf,
22
+ inOrder,
23
+ moved,
24
+ rangeSaid,
25
+ rowDrawn,
26
+ rowsHolding,
27
+ rowsOf,
28
+ type Row,
29
+ } from './rows.ts';
30
+
31
+ /** GitHub's own diff: one column, and no highlighting past a long line. */
32
+ const options = { diffStyle: 'unified', overflow: 'scroll' } as const;
33
+
34
+ /**
35
+ * The page's own scroll, which `@pierre/diffs`' React `Virtualizer` doesn't watch: it scrolls a
36
+ * box of its own. Each file under it draws only the lines near the window.
37
+ */
38
+ function WindowVirtualizer({ children }: { readonly children: ReactNode }) {
39
+ const [virtualizer] = useState(() => new Virtualizer());
40
+ const content = useCallback(
41
+ (node: HTMLDivElement | null) => {
42
+ if (node === null) virtualizer.cleanUp();
43
+ else virtualizer.setup(document, node);
44
+ },
45
+ [virtualizer],
46
+ );
47
+
48
+ return (
49
+ <VirtualizerContext.Provider value={virtualizer}>
50
+ <div ref={content}>{children}</div>
51
+ </VirtualizerContext.Provider>
52
+ );
53
+ }
54
+
55
+ /** Why a file that GitHub's REST sends with no patch shows no diff once loaded. */
56
+ const notShown = {
57
+ binary: 'Binary file not shown.',
58
+ 'too-large': 'This file is too large to show its diff here.',
59
+ 'too-different': 'This file changed too much to show its diff here.',
60
+ unchanged: "The file's contents didn't change.",
61
+ } as const;
62
+
63
+ /** Why `file` shows no diff once loaded: a rename with its blob unchanged says so. */
64
+ const notShownFor = (file: ChangedFile, kind: keyof typeof notShown) =>
65
+ kind === 'unchanged' && file.status === 'renamed'
66
+ ? 'File renamed without changes.'
67
+ : notShown[kind];
68
+
69
+ /** What **Load diff** shows: the file's diff, or why there is none. */
70
+ type Loaded =
71
+ | { readonly kind: 'diff'; readonly diff: FileDiffMetadata }
72
+ | { readonly kind: keyof typeof notShown };
73
+
74
+ /** Two sides read whole, diffed here, or why they aren't. */
75
+ const diffed = (sides: LoadedFile, cacheKey: string): Loaded => {
76
+ if (sides.kind !== 'text') return sides;
77
+
78
+ const diff = diffOfSides(sides.old, sides.new, cacheKey);
79
+
80
+ return diff === undefined ? { kind: 'too-different' } : { kind: 'diff', diff };
81
+ };
82
+
83
+ /**
84
+ * Reads `file`'s two sides once, through the query's cache, for **Load diff** and for expanding
85
+ * a diff's context alike.
86
+ */
87
+ const useSides = (file: ChangedFile, revisions: Revisions) => {
88
+ const client = useQueryClient();
89
+
90
+ return useCallback(
91
+ () =>
92
+ client.fetchQuery({
93
+ queryKey: ['file-sides', revisions, file.filename, file.sha],
94
+ queryFn: ({ signal }) => loadFile(file, revisions, signal),
95
+ staleTime: Infinity,
96
+ }),
97
+ [client, file, revisions],
98
+ );
99
+ };
100
+
101
+ /** How many lines `text` holds. */
102
+ const linesIn = (text: string) => {
103
+ let lines = 1;
104
+
105
+ for (let at = text.indexOf('\n'); at !== -1; at = text.indexOf('\n', at + 1)) lines += 1;
106
+
107
+ return lines;
108
+ };
109
+
110
+ /** Whether either side is too long for its context to expand. */
111
+ const tooLong = (sides: LoadedFile) =>
112
+ sides.kind === 'text' &&
113
+ [sides.old, sides.new].some(
114
+ (side) =>
115
+ side !== null &&
116
+ (side.contents.length > highlightedCharsMost ||
117
+ linesIn(side.contents) > highlightedLinesMost),
118
+ );
119
+
120
+ /** The sides `@pierre/diffs` reads to expand a diff's context: both, or a pure rename's new. */
121
+ const expanded = (sides: LoadedFile): FileDiffLoadedFiles => {
122
+ if (sides.kind !== 'text') throw new Error(`Its context can't expand: the file is ${sides.kind}`);
123
+
124
+ if (sides.new === null) throw new Error("Its context can't expand: the file was removed");
125
+
126
+ const newFile = { ...sides.new };
127
+
128
+ return sides.old === null ? { oldFile: null, newFile } : { oldFile: { ...sides.old }, newFile };
129
+ };
130
+
131
+ /**
132
+ * The gutter's **+**, which picks a line or, dragged, a range, for `pick`. The selection is the
133
+ * page's, through `select`, so the keyboard moves it too.
134
+ */
135
+ const picking = (
136
+ pick: ((lines: SelectedLineRange) => void) | undefined,
137
+ select: (lines: SelectedLineRange | null) => void,
138
+ ) =>
139
+ pick === undefined
140
+ ? { enableGutterUtility: false, enableLineSelection: false }
141
+ : {
142
+ enableGutterUtility: true,
143
+ enableLineSelection: true,
144
+ onGutterUtilityClick: pick,
145
+ onLineSelected: select,
146
+ };
147
+
148
+ /** The shadow root `@pierre/diffs` draws a file's lines in, under `at`, once it has. */
149
+ const shownIn = (at: HTMLElement | null) =>
150
+ at?.querySelector('diffs-container')?.shadowRoot ?? undefined;
151
+
152
+ /**
153
+ * `diff` drawn: its context expands by reading both sides, up to `highlightedLinesMost`, and its
154
+ * lines mark what changed word by word, as far as `wordDiffOf` lets them. `notes` on `path` show
155
+ * under their lines.
156
+ */
157
+ function Drawn({
158
+ diff,
159
+ sides,
160
+ path,
161
+ notes,
162
+ }: {
163
+ readonly diff: FileDiffMetadata;
164
+ readonly sides: () => Promise<LoadedFile>;
165
+ readonly path: string;
166
+ readonly notes: Notes | undefined;
167
+ }) {
168
+ const [refused, setRefused] = useState(false);
169
+ const [selected, setSelected] = useState<SelectedLineRange | null>(null);
170
+ const rows = useMemo(() => rowsOf(diff), [diff]);
171
+ const lines = useRef<HTMLDivElement>(null);
172
+ // The rows drawn, context expanded included, when they hold `needed`; else the hunks'.
173
+ const rowsFor = useCallback(
174
+ (needed: readonly Row[]) => {
175
+ const root = shownIn(lines.current);
176
+
177
+ return rowsHolding(root === undefined ? [] : drawnRows(root), rows, needed);
178
+ },
179
+ [rows],
180
+ );
181
+ const pick = notes?.pick;
182
+ // A pick opens its comment form and clears the selection, so the next **+** picks its own line.
183
+ // The diff commits the **+**'s range after it calls the pick, so the clear waits for that.
184
+ const picked = useMemo(
185
+ () =>
186
+ pick &&
187
+ ((lines: SelectedLineRange) => {
188
+ queueMicrotask(() => setSelected(null));
189
+ const { start, end } = endsOf(lines);
190
+ pick(path, inOrder(rowsFor([start, end]), lines));
191
+ }),
192
+ [pick, path, rowsFor],
193
+ );
194
+ // Its colours follow the theme picked, as the file view's do: its own `system` is the system's.
195
+ const { theme } = useTheme();
196
+ const drawn = useMemo(
197
+ () => ({
198
+ ...options,
199
+ themeType: theme,
200
+ ...wordDiffOf(diff),
201
+ ...picking(picked, setSelected),
202
+ loadDiffFiles: async () => {
203
+ const read = await sides();
204
+ if (!tooLong(read)) return expanded(read);
205
+
206
+ setRefused(true);
207
+ throw new Error("Its context can't expand: a side is too long to draw whole");
208
+ },
209
+ }),
210
+ [diff, sides, picked, theme],
211
+ );
212
+ const annotations = useMemo(() => notes?.of(path) ?? [], [notes, path]);
213
+ // The end a key moves comes into view: a range extended down shows its last row, not its first.
214
+ useEffect(() => {
215
+ if (selected === null) return;
216
+
217
+ const root = shownIn(lines.current);
218
+ const { end } = endsOf(selected);
219
+ if (root !== undefined)
220
+ rowDrawn(root, end.line, end.side)?.scrollIntoView?.({ block: 'nearest' });
221
+ }, [selected]);
222
+
223
+ const file = (
224
+ <FileDiff
225
+ fileDiff={diff}
226
+ options={drawn}
227
+ selectedLines={selected}
228
+ lineAnnotations={annotations}
229
+ renderAnnotation={(note) => notes?.render(path, note.metadata)}
230
+ renderHeaderPrefix={() => <FileIcon path={path} className="block" />}
231
+ />
232
+ );
233
+
234
+ return (
235
+ <>
236
+ {picked === undefined ? (
237
+ file
238
+ ) : (
239
+ // The gutter's **+** takes only a pointer: its lines are one tab stop, whose arrows move
240
+ // the selection, with Shift to extend it, and whose Enter comments on it.
241
+ <div
242
+ ref={lines}
243
+ role="group"
244
+ tabIndex={0}
245
+ aria-label={`Lines of ${path}: arrow keys pick lines, Shift extends, Enter comments`}
246
+ className="focus-visible:ring-ring outline-none focus-visible:ring-2"
247
+ onKeyDown={(event) => {
248
+ if (event.target !== event.currentTarget) return;
249
+
250
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
251
+ event.preventDefault();
252
+ const by = event.key === 'ArrowDown' ? 1 : -1;
253
+ setSelected((was) =>
254
+ moved(was === null ? rows : rowsFor([endsOf(was).end]), was, by, event.shiftKey),
255
+ );
256
+ } else if (event.key === 'Enter' && selected !== null) {
257
+ event.preventDefault();
258
+ picked(selected);
259
+ } else if (event.key === 'Escape') {
260
+ setSelected(null);
261
+ }
262
+ }}
263
+ >
264
+ <span className="sr-only" aria-live="polite">
265
+ {rangeSaid(selected)}
266
+ </span>
267
+ {file}
268
+ </div>
269
+ )}
270
+ {refused && (
271
+ <p className="text-muted-foreground px-3 py-2 text-sm">
272
+ This file is too long to expand its context here.
273
+ </p>
274
+ )}
275
+ </>
276
+ );
277
+ }
278
+
279
+ /** A file listed with no patch: collapsed, until **Load diff** reads both blobs and diffs them. */
280
+ function LoadDiff({
281
+ file,
282
+ revisions,
283
+ cacheKey,
284
+ notes,
285
+ }: {
286
+ readonly file: ChangedFile;
287
+ readonly revisions: Revisions;
288
+ readonly cacheKey: string;
289
+ readonly notes: Notes | undefined;
290
+ }) {
291
+ const [asked, setAsked] = useState(false);
292
+ const sides = useSides(file, revisions);
293
+ const loaded = useQuery({
294
+ queryKey: ['loaded-file', revisions, file.filename, file.sha],
295
+ queryFn: async () => diffed(await sides(), cacheKey),
296
+ enabled: asked,
297
+ staleTime: Infinity,
298
+ });
299
+ const shown = loaded.data;
300
+
301
+ if (shown?.kind === 'diff') {
302
+ return <Drawn diff={shown.diff} sides={sides} path={file.filename} notes={notes} />;
303
+ }
304
+
305
+ return (
306
+ <div className="flex items-center justify-between gap-3 border px-3 py-2 text-sm">
307
+ <span className="flex min-w-0 items-center gap-2 font-mono">
308
+ <FileIcon path={file.filename} />
309
+ <span className="truncate">{file.filename}</span>
310
+ </span>
311
+ {shown !== undefined ? (
312
+ <span className="text-muted-foreground">{notShownFor(file, shown.kind)}</span>
313
+ ) : loaded.isError ? (
314
+ <span className="text-destructive">The diff didn't load.</span>
315
+ ) : (
316
+ <Button
317
+ variant="outline"
318
+ size="sm"
319
+ disabled={loaded.isFetching}
320
+ onClick={() => setAsked(true)}
321
+ >
322
+ {loaded.isFetching ? 'Loading…' : 'Load diff'}
323
+ </Button>
324
+ )}
325
+ </div>
326
+ );
327
+ }
328
+
329
+ /** How far from the window a file's hunks mount, and the next page is asked for. */
330
+ const near = '1000px 0px';
331
+
332
+ /** Calls `onNear` once `target` comes within `near` of the window, and keeps watching. */
333
+ const useNear = (onNear: () => void) => {
334
+ const target = useRef<HTMLDivElement>(null);
335
+ useEffect(() => {
336
+ const at = target.current;
337
+ if (at === null) return;
338
+
339
+ const watch = new IntersectionObserver(
340
+ (entries) => {
341
+ if (entries.some((entry) => entry.isIntersecting)) onNear();
342
+ },
343
+ { rootMargin: near },
344
+ );
345
+ watch.observe(at);
346
+
347
+ return () => watch.disconnect();
348
+ }, [onNear]);
349
+
350
+ return target;
351
+ };
352
+
353
+ /** About the height a line of a diff draws at, to hold a file's place until it mounts. */
354
+ const lineHeight = 20;
355
+
356
+ /**
357
+ * A file's hunks, from the patch GitHub's REST sent: parsed and mounted once the file nears the
358
+ * window, and until then a box of about its height, so 1,000 files cost what shows.
359
+ */
360
+ function PatchHunks({
361
+ file,
362
+ revisions,
363
+ cacheKey,
364
+ notes,
365
+ }: {
366
+ readonly file: ChangedFile;
367
+ readonly revisions: Revisions;
368
+ readonly cacheKey: string;
369
+ readonly notes: Notes | undefined;
370
+ }) {
371
+ const [shown, setShown] = useState(false);
372
+ const show = useCallback(() => setShown(true), []);
373
+ const box = useNear(show);
374
+ const sides = useSides(file, revisions);
375
+ const diff = useMemo(
376
+ () => (shown ? diffOfPatch(file, cacheKey) : undefined),
377
+ [shown, file, cacheKey],
378
+ );
379
+
380
+ if (diff !== undefined) {
381
+ return <Drawn diff={diff} sides={sides} path={file.filename} notes={notes} />;
382
+ }
383
+
384
+ // A patch with no hunks to draw, such as an empty one, reads both blobs instead.
385
+ if (shown) {
386
+ return <LoadDiff file={file} revisions={revisions} cacheKey={cacheKey} notes={notes} />;
387
+ }
388
+
389
+ const lines = (file.patch?.split('\n').length ?? 0) + 2;
390
+
391
+ return <div ref={box} data-pending="" style={{ height: lines * lineHeight }} />;
392
+ }
393
+
394
+ function FileHunks({
395
+ file,
396
+ index,
397
+ revisions,
398
+ notes,
399
+ }: {
400
+ readonly file: ChangedFile;
401
+ readonly index: number;
402
+ readonly revisions: Revisions;
403
+ readonly notes: Notes | undefined;
404
+ }) {
405
+ const cacheKey = `${revisions.repo}:${revisions.base}:${revisions.head}:${index}`;
406
+
407
+ return (
408
+ <section id={`diff-${index}`} data-file={file.filename} className="scroll-mt-4">
409
+ {file.patch === undefined ? (
410
+ <LoadDiff file={file} revisions={revisions} cacheKey={cacheKey} notes={notes} />
411
+ ) : (
412
+ <PatchHunks file={file} revisions={revisions} cacheKey={cacheKey} notes={notes} />
413
+ )}
414
+ </section>
415
+ );
416
+ }
417
+
418
+ /** Calls `onEnd` when the end of the list comes near the window, to load the next page. */
419
+ function End({ onEnd }: { readonly onEnd: () => void }) {
420
+ return <div ref={useNear(onEnd)} data-end="" />;
421
+ }
422
+
423
+ /**
424
+ * Each loaded file's hunks, drawn by `@pierre/diffs` as it nears the window, and the next page
425
+ * asked for as the list's end does. The browser alone loads this, and Shiki's grammars with it.
426
+ */
427
+ export default function Hunks({
428
+ files,
429
+ revisions,
430
+ notes,
431
+ onEnd,
432
+ }: {
433
+ readonly files: readonly ChangedFile[];
434
+ readonly revisions: Revisions;
435
+ readonly notes: Notes | undefined;
436
+ readonly onEnd: () => void;
437
+ }) {
438
+ return (
439
+ <WindowVirtualizer>
440
+ <div className="flex flex-col gap-4">
441
+ {files.map((file, index) => (
442
+ <FileHunks
443
+ key={`${index}:${file.filename}`}
444
+ file={file}
445
+ index={index}
446
+ revisions={revisions}
447
+ notes={notes}
448
+ />
449
+ ))}
450
+ </div>
451
+ <End onEnd={onEnd} />
452
+ </WindowVirtualizer>
453
+ );
454
+ }
@@ -0,0 +1,131 @@
1
+ import { parsePatchFiles, type FileDiffMetadata } from '@pierre/diffs';
2
+ import { createTwoFilesPatch } from 'diff';
3
+
4
+ import type { Side } from './blobs.ts';
5
+ import type { ChangedFile } from './files.ts';
6
+
7
+ /** How `@pierre/diffs` names each change GitHub's REST lists. */
8
+ const changeOf = (file: ChangedFile): FileDiffMetadata['type'] => {
9
+ switch (file.status) {
10
+ case 'added':
11
+ return 'new';
12
+ case 'removed':
13
+ return 'deleted';
14
+ case 'renamed':
15
+ return file.patch === '' ? 'rename-pure' : 'rename-changed';
16
+ default:
17
+ return 'change';
18
+ }
19
+ };
20
+
21
+ /**
22
+ * `file`'s patch, as GitHub's REST sends it, ready to draw, or `undefined` when it has none: past
23
+ * GitHub's limits, or binary. GitHub sends only its hunks, which `@pierre/diffs` reads as no file
24
+ * at all, so the file's names go before them; `key` keeps each file's render cached apart.
25
+ */
26
+ export const diffOfPatch = (file: ChangedFile, key: string): FileDiffMetadata | undefined => {
27
+ if (file.patch === undefined) return undefined;
28
+
29
+ const from = JSON.stringify(file.previous_filename ?? file.filename);
30
+ const patch = `--- ${from}\n+++ ${JSON.stringify(file.filename)}\n${file.patch}\n`;
31
+ const parsed = parsePatchFiles(patch, { cacheKeyPrefix: key })[0]?.files[0];
32
+
33
+ return parsed === undefined ? undefined : { ...parsed, type: changeOf(file) };
34
+ };
35
+
36
+ /**
37
+ * How long the browser may spend diffing two blobs, in milliseconds. Myers' diff takes time by
38
+ * the lines that differ: two 800 KB sides changed on every line took 134 s, and a tab stops for
39
+ * as long, so past this it gives up.
40
+ */
41
+ export const diffedMillisMost = 1000;
42
+
43
+ /**
44
+ * Two sides **Load diff** read, diffed here with GitHub's 3 lines of context, or `undefined` when
45
+ * they differ too much to diff within `diffedMillisMost`.
46
+ */
47
+ export const diffOfSides = (
48
+ old: Side | null,
49
+ changed: Side | null,
50
+ key: string,
51
+ ): FileDiffMetadata | undefined => {
52
+ const name = changed?.name ?? old?.name ?? '';
53
+ const patch = createTwoFilesPatch(
54
+ old?.name ?? name,
55
+ name,
56
+ old?.contents ?? '',
57
+ changed?.contents ?? '',
58
+ undefined,
59
+ undefined,
60
+ {
61
+ context: 3,
62
+ timeout: diffedMillisMost,
63
+ },
64
+ );
65
+ const parsed =
66
+ patch === undefined ? undefined : parsePatchFiles(patch, { cacheKeyPrefix: key })[0]?.files[0];
67
+ if (parsed === undefined) return undefined;
68
+
69
+ if (old === null) return { ...parsed, type: 'new' };
70
+
71
+ return changed === null ? { ...parsed, type: 'deleted' } : parsed;
72
+ };
73
+
74
+ /** The longest line `@pierre/diffs` diffs word by word, its own default. */
75
+ const wordDiffedLengthMost = 1000;
76
+
77
+ /**
78
+ * What the words of a file's changed lines may cost to diff, as the sum of each paired line's
79
+ * length squared. `@pierre/diffs` diffs them on the page's thread with no time limit, and Myers'
80
+ * diff of two lines that share no word takes about the square of their length: 45 million a
81
+ * second in Node, so this is about half a second.
82
+ */
83
+ export const wordDiffedMost = 20_000_000;
84
+
85
+ /** A line's length as `@pierre/diffs` measures it, without its line ending. */
86
+ const lengthOf = (line: string | undefined) => {
87
+ if (line === undefined) return 0;
88
+
89
+ if (line.endsWith('\r\n')) return line.length - 2;
90
+
91
+ return line.endsWith('\n') ? line.length - 1 : line.length;
92
+ };
93
+
94
+ /**
95
+ * How `@pierre/diffs` marks what changed within `diff`'s lines: word by word, as GitHub does, in
96
+ * each pair of a removed and an added line no longer than the length this gives. It's the
97
+ * longest that keeps the pairs within it under `wordDiffedMost`, so short pairs keep their marks
98
+ * when long ones would cost too much.
99
+ */
100
+ export const wordDiffOf = (diff: FileDiffMetadata) => {
101
+ const pairs: { readonly longest: number; readonly cost: number }[] = [];
102
+
103
+ for (const hunk of diff.hunks) {
104
+ for (const content of hunk.hunkContent) {
105
+ if (content.type !== 'change') continue;
106
+
107
+ for (let pair = 0; pair < Math.min(content.additions, content.deletions); pair += 1) {
108
+ const removed = lengthOf(diff.deletionLines[content.deletionLineIndex + pair]);
109
+ const added = lengthOf(diff.additionLines[content.additionLineIndex + pair]);
110
+ const longest = Math.max(removed, added);
111
+
112
+ if (longest <= wordDiffedLengthMost) {
113
+ pairs.push({ longest, cost: removed * removed + added * added });
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ pairs.sort((one, other) => one.longest - other.longest);
120
+ let cost = 0;
121
+
122
+ for (const [index, { longest }] of pairs.entries()) {
123
+ cost += pairs[index]?.cost ?? 0;
124
+
125
+ // Pairs as long as this one are all marked or none: stop below their length.
126
+ if (cost > wordDiffedMost)
127
+ return { lineDiffType: 'word-alt', maxLineDiffLength: longest - 1 } as const;
128
+ }
129
+
130
+ return { lineDiffType: 'word-alt', maxLineDiffLength: wordDiffedLengthMost } as const;
131
+ };