ref0-git 0.0.0-stage → 0.2.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 +122 -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 +547 -0
  197. package/app/apps/github/src/palette/recent.ts +116 -0
  198. package/app/apps/github/src/palette/rows.tsx +455 -0
  199. package/app/apps/github/src/palette/server.ts +104 -0
  200. package/app/apps/github/src/palette/targets.ts +306 -0
  201. package/app/apps/github/src/policy.ts +600 -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 +538 -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 +48 -0
  336. package/dist/cli/helpers.mjs +51 -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 +79 -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 +75 -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 +205 -0
  368. package/dist/init/node-app.mjs +189 -0
  369. package/dist/init/node.mjs +458 -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 +383 -0
  382. package/dist/init/versions.mjs +32 -0
  383. package/dist/init/workspace.mjs +20 -0
  384. package/package.json +52 -3
  385. package/README.md +0 -3
@@ -0,0 +1,162 @@
1
+ import { TokenInput, logoutJson } from "./documents.mjs";
2
+ import { answered, failure, snakeCase, usageFailure } from "./failure.mjs";
3
+ import { chosenHost, hostFlag, hostName, hostOf, remoteOf } from "./hosts.mjs";
4
+ import { CliModes, answer, cliDocument, commandLine, document, printable, receipt, say, secrets, utcDay } from "./output.mjs";
5
+ import { checkedHelpers, removeSignIn, storeSignIn } from "./sign-ins.mjs";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Redacted from "effect/Redacted";
8
+ import * as Stream from "effect/Stream";
9
+ import * as Stdio from "effect/Stdio";
10
+ import * as FetchHttpClient from "effect/http/FetchHttpClient";
11
+ import * as Command from "effect/cli/Command";
12
+ import * as Schema from "effect/Schema";
13
+ import * as DateTime from "effect/DateTime";
14
+ import * as Flag from "effect/cli/Flag";
15
+ import { createRestClient } from "@ref0/git/rest";
16
+ import * as Argument from "effect/cli/Argument";
17
+ import * as Clock from "effect/Clock";
18
+ import * as Result from "effect/Result";
19
+ import * as HttpClient from "effect/http/HttpClient";
20
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
21
+ import { deviceGrant, ghClientId, readAccessTokenAnswer, readDeviceCodeAnswer, signInPaths } from "@ref0/git/auth";
22
+ // src/cli/sign-in.ts
23
+ /**
24
+ * `login`, `logout` and `whoami`. A token reaches Git's helpers through `git credential approve`
25
+ * and comes back through `fill`, so Git and `ref0-git` share one store; it never reaches a URL, an
26
+ * argument, stdout or a log line. A host has one sign-in at a time: a new one replaces the last.
27
+ */
28
+ /** How long a sign-in request may take, when the code's expiry doesn't come first. */
29
+ const requestMs = 3e4;
30
+ /**
31
+ * A form POST to the host's sign-in, at its origin's root whatever its base path, as GitHub's is,
32
+ * its JSON read by `read`, as `@ref0/git/auth` reads the server's answer, or `undefined`, within
33
+ * `within` ms. It follows no redirect, which could send the device code, and the token, elsewhere.
34
+ */
35
+ const signInPost = (host, path, fields, read, within = requestMs) => HttpClient.HttpClient.pipe(Effect.flatMap((client) => client.execute(HttpClientRequest.post(`${host.origin}${path}`).pipe(HttpClientRequest.acceptJson, HttpClientRequest.bodyUrlParams(fields)))), Effect.flatMap((response) => response.text), Effect.timeout(Math.max(within, 1)), Effect.provideService(FetchHttpClient.RequestInit, { redirect: "error" }), Effect.mapError(() => failure("unreachable", `Couldn't reach ${hostName(host)}'s sign-in`, "Check the host, then sign in again")), Effect.map(read));
36
+ /** `HH:MM UTC`, when a wait ends. */
37
+ const utcTime = (at) => `${DateTime.formatIso(DateTime.makeUnsafe(at)).slice(11, 16)} UTC`;
38
+ const sleep = (seconds) => Effect.sleep(`${seconds} seconds`);
39
+ /**
40
+ * GitHub's device flow, as `gh auth login` runs it with `gh`'s client ID: the code and link on
41
+ * stderr in every mode, then a poll at the host's interval until the person decides or it expires.
42
+ */
43
+ const deviceToken = Effect.fnUntraced(function* (host) {
44
+ const started = yield* signInPost(host, signInPaths.deviceCode, { client_id: ghClientId }, readDeviceCodeAnswer);
45
+ if (started === void 0) return yield* failure("sign_in_unavailable", `${hostName(host)} doesn't offer sign-in from a device`, "Sign in with a token instead: --with-token");
46
+ const link = URL.parse(started.verification_uri);
47
+ if (/[\s\p{Cc}\p{Cf}]/u.test(started.verification_uri) || link?.origin !== host.origin || link.username !== "" || link.password !== "") return yield* failure("sign_in_elsewhere", `${hostName(host)} sent a sign-in link to another host`, "Check the host, then sign in again");
48
+ const expiresIn = started.expires_in;
49
+ const deviceCode = started.device_code;
50
+ let interval = started.interval ?? 5;
51
+ const until = (yield* Clock.currentTimeMillis) + expiresIn * 1e3;
52
+ yield* say(`Signing in to ${hostName(host)} in your browser. Enter this code there:`, ` ${printable(started.user_code)}`, ` ${printable(started.verification_uri)}`, `Waiting until ${utcTime(until)}.`);
53
+ for (;;) {
54
+ yield* sleep(interval);
55
+ const left = until - (yield* Clock.currentTimeMillis);
56
+ if (left <= 0) break;
57
+ const polled = yield* signInPost(host, signInPaths.accessToken, {
58
+ client_id: ghClientId,
59
+ device_code: deviceCode,
60
+ grant_type: deviceGrant
61
+ }, readAccessTokenAnswer, Math.min(left, requestMs)).pipe(Effect.catchIf((failed) => failed.reason === "unreachable" && left <= requestMs, () => Effect.succeed({ error: "authorization_pending" })));
62
+ if (polled?.access_token !== void 0) return Redacted.make(polled.access_token);
63
+ const error = polled?.error;
64
+ if (error === "authorization_pending") continue;
65
+ if (error === "slow_down") {
66
+ interval = polled?.interval ?? interval + 5;
67
+ continue;
68
+ }
69
+ if (error === "access_denied") return yield* failure("access_denied", `The sign-in to ${hostName(host)} was denied`);
70
+ if (error === "expired_token") break;
71
+ return yield* failure(snakeCase(error ?? "sign_in_failed"), `${hostName(host)} refused the sign-in`, polled?.error_description);
72
+ }
73
+ return yield* failure("timeout", `The code expired at ${utcTime(until)} before it was approved`, "Sign in again for a new code");
74
+ });
75
+ const decodeToken = Schema.decodeUnknownResult(TokenInput);
76
+ /** The token on stdin, as `TokenInput` reads it: never typed at a prompt. */
77
+ const tokenFromStdin = Effect.fnUntraced(function* (host) {
78
+ if ((yield* CliModes).stdinTerminal) return yield* usageFailure("token_not_piped", "--with-token reads the token from stdin", `Pipe it in, as \`read -rs t; printf '%s\\n' "$t" | ${commandLine([
79
+ "login",
80
+ host,
81
+ "--with-token"
82
+ ])}\``);
83
+ const piped = yield* (yield* Stdio.Stdio).stdin.pipe(Stream.decodeText(), Stream.mkString, Effect.mapError(() => usageFailure("token_unreadable", "stdin couldn't be read to its end", "Pipe in one token, on one line")));
84
+ const read = decodeToken(piped);
85
+ return Result.isSuccess(read) ? read.success : yield* usageFailure("token_unreadable", read.failure.message, "Pipe in one token, on one line");
86
+ });
87
+ /** Who `token` signs in on the host, as `GET /me` answers. */
88
+ const meWith = (host, token) => answered(hostName(host), (signal) => createRestClient({
89
+ url: host.endpoint,
90
+ credentials: { token: Redacted.value(token) }
91
+ }).me({ signal }));
92
+ /** A token's coverage and scope, as a person reads it. */
93
+ const coverage = (token) => token.repo !== void 0 ? `${token.scope} on ${printable(token.repo)}` : token.prefix === "" ? `${token.scope} on every repo` : `${token.scope} on ${printable(token.prefix)}*`;
94
+ /** The sign-in group's commands, at the top of the tree. */
95
+ const signInCommands = [
96
+ Command.make("login", {
97
+ host: Argument.String("HOST").pipe(Argument.withDescription("The host, as git.acme.dev, git.acme.dev/git where Git is under a path, or http://localhost:5173")),
98
+ withToken: Flag.Boolean("with-token").pipe(Flag.withDescription("Read a token from stdin instead of signing in in the browser"), Flag.withDefault(false)),
99
+ allowPlaintext: Flag.Boolean("allow-plaintext").pipe(Flag.withDescription("Store the token even where Git's helper keeps it as plain text"), Flag.withDefault(false))
100
+ }, Effect.fnUntraced(function* ({ host, withToken, allowPlaintext }) {
101
+ const named = yield* hostOf(host);
102
+ const helpers = yield* checkedHelpers(named, allowPlaintext);
103
+ const token = withToken ? yield* tokenFromStdin(hostName(named)) : yield* deviceToken(named);
104
+ secrets.hide(Redacted.value(token));
105
+ const me = yield* meWith(named, token);
106
+ const { pushes } = yield* storeSignIn(named, {
107
+ username: me.actor.id,
108
+ password: token,
109
+ expiresAt: me.token?.expiresAt
110
+ }, helpers);
111
+ if ((yield* CliModes).json) return yield* document(me);
112
+ yield* receipt({
113
+ done: `Signed in to ${hostName(named)} as ${printable(me.actor.id)}`,
114
+ fields: [
115
+ ["Token", `In ${helpers.join(", ")}, for Git and ref0-git`],
116
+ ["Recorded", "As ref0-git.host, in Git's global config"],
117
+ ...me.token === void 0 ? [] : [["Expires", utcDay(me.token.expiresAt)]],
118
+ ...pushes ? [["Pushes", "Through git-remote-ref0, for large packs"]] : []
119
+ ],
120
+ next: {
121
+ says: "See who you are there",
122
+ run: [[
123
+ "whoami",
124
+ "--host",
125
+ hostName(named)
126
+ ]]
127
+ }
128
+ });
129
+ })).pipe(Command.withDescription("Sign in, and store a token for Git and ref0-git (experimental)")),
130
+ Command.make("logout", { host: Argument.String("HOST").pipe(Argument.withDescription("The host to sign out of, if you are signed in to more than one"), Argument.optional) }, Effect.fnUntraced(function* ({ host }) {
131
+ const chosen = yield* chosenHost(host, "Name the one to sign out of, as logout's HOST").pipe(Effect.catchIf((failed) => failed.reason === "no_host", () => Effect.succeed(void 0)));
132
+ const mode = yield* CliModes;
133
+ if (chosen === void 0) return yield* mode.json ? cliDocument(logoutJson, {
134
+ host: null,
135
+ removed: false
136
+ }) : say("You're not signed in to a host: nothing to remove");
137
+ const removed = yield* removeSignIn(chosen);
138
+ if (mode.json) return yield* cliDocument(logoutJson, {
139
+ host: hostName(chosen),
140
+ removed
141
+ });
142
+ yield* removed ? receipt({ done: `Signed out of ${hostName(chosen)}` }) : say(`Not signed in to ${hostName(chosen)}: nothing to remove`);
143
+ })).pipe(Command.withDescription("Remove the stored token (experimental)")),
144
+ Command.make("whoami", { host: hostFlag }, Effect.fnUntraced(function* ({ host }) {
145
+ const remote = yield* remoteOf(yield* chosenHost(host));
146
+ const me = yield* answered(remote.host, (signal) => remote.client.me({ signal }));
147
+ if ((yield* CliModes).json) return yield* document(me);
148
+ const token = me.token;
149
+ const rows = [
150
+ ["Host", remote.host],
151
+ ["Actor", printable(me.actor.id)],
152
+ ...me.subject === void 0 ? [] : [["For", printable(me.subject.id)]],
153
+ ...token === void 0 ? [["Token", "The host's own sign-in, with no scope or expiry"]] : [
154
+ ["Token", printable(token.id)],
155
+ ["Scope", coverage(token)],
156
+ ["Expires", utcDay(token.expiresAt)]
157
+ ]
158
+ ];
159
+ yield* answer(rows.map(([label, value]) => `${label.padEnd(16)}${value}`).join("\n"));
160
+ })).pipe(Command.withDescription("Show who you are on the host (experimental)"))
161
+ ];
162
+ export { signInCommands };
@@ -0,0 +1,79 @@
1
+ import { BrokenField, approveCredential, breaksField, fillCredential, rejectCredential } from "./credentials.mjs";
2
+ import { failure, unsafeCredential, usageFailure } from "./failure.mjs";
3
+ import { gitRun } from "./git.mjs";
4
+ import { credentialHelpers, isPlaintext, onPath, suggestedHelper } from "./helpers.mjs";
5
+ import { forgetHost, globalConfig, hostName, recordHost, signedInHosts } from "./hosts.mjs";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Redacted from "effect/Redacted";
8
+ // src/cli/sign-ins.ts
9
+ /**
10
+ * A signed-in host, kept whole: its token in Git's helpers, by its origin, its `ref0-git.host`
11
+ * record, by its endpoint, and, with `git-remote-ref0` on `PATH`, its origin's `pushInsteadOf`.
12
+ * Each origin has one sign-in, so one record; each step is checked.
13
+ */
14
+ /** Git's config key that sends `origin`'s pushes through `git-remote-ref0`. */
15
+ const pushKey = (origin) => `url.ref0::${origin}/.pushInsteadOf`;
16
+ /**
17
+ * Where Git's helpers stand for `origin`: the helpers, refused when there's none, when one keeps
18
+ * plain text and `allowPlaintext` isn't set, or when Git asks them by repo path, which a host's
19
+ * one sign-in can't answer.
20
+ */
21
+ const checkedHelpers = Effect.fnUntraced(function* (host, allowPlaintext) {
22
+ const { origin } = host;
23
+ const helpers = yield* credentialHelpers(origin);
24
+ if (helpers.length === 0) return yield* failure("no_credential_helper", "Git has no credential helper to keep the token in", `Set one up: \`git config --global credential.helper ${suggestedHelper()}\`, then sign in again`);
25
+ const plain = helpers.filter(isPlaintext);
26
+ if (plain.length > 0 && !allowPlaintext) return yield* usageFailure("plaintext_helper", `Git's ${plain.join(", ")} helper keeps the token as plain text in a file`, `Use a secure helper, as \`git config --global credential.helper ${suggestedHelper()}\`, or sign in with --allow-plaintext`);
27
+ if ((yield* gitRun([
28
+ "config",
29
+ "--type=bool",
30
+ "--get-urlmatch",
31
+ "credential.useHttpPath",
32
+ `${origin}/`
33
+ ])).stdout.trim() === "true") return yield* failure("credential_by_path", `Git asks for ${hostName(host)}'s credentials by repo, with credential.useHttpPath, so one sign-in can't reach its repos`, `Turn it off for this host: \`git config --global credential.${origin}/.useHttpPath false\`, then sign in again`);
34
+ return helpers;
35
+ });
36
+ /** The records of `host`'s origin, its own among them when it's recorded. */
37
+ const recordsOf = (host) => Effect.map(signedInHosts, (hosts) => hosts.filter((one) => one.origin === host.origin));
38
+ /**
39
+ * Stores `credential` as `host`'s origin's one sign-in, refusing a line break a host could use to
40
+ * store it for another host, and forgets a host it just recorded when the helpers don't give it
41
+ * back. Once it's kept, the origin's other records go: the token they named is this one now.
42
+ */
43
+ const storeSignIn = Effect.fnUntraced(function* (host, credential, helpers) {
44
+ const { origin } = host;
45
+ if (breaksField(credential.username) || breaksField(Redacted.value(credential.password))) return yield* unsafeCredential(hostName(host));
46
+ const url = new URL(`${origin}/`);
47
+ const records = yield* recordsOf(host);
48
+ const known = records.some((one) => one.record === host.endpoint);
49
+ const pushes = yield* onPath("git-remote-ref0");
50
+ if (!known) yield* recordHost(host);
51
+ const stored = Effect.gen(function* () {
52
+ yield* rejectCredential(url);
53
+ yield* approveCredential(url, credential);
54
+ const kept = yield* fillCredential(url);
55
+ if (kept === void 0 || Redacted.value(kept.password) !== Redacted.value(credential.password)) return yield* failure("credential_not_kept", `Git's ${helpers.join(", ")} helper didn't keep the token`, "Check the helper works, as `git credential fill` does, then sign in again");
56
+ yield* pushes ? globalConfig([pushKey(origin), `${origin}/`]) : globalConfig([pushKey(origin)], { unset: true });
57
+ });
58
+ const undone = Effect.andThen(forgetHost(host.endpoint), rejectCredential(url, credential));
59
+ yield* stored.pipe(Effect.mapError((failed) => failed instanceof BrokenField ? unsafeCredential(hostName(host)) : failed), Effect.tapError(() => known ? Effect.void : Effect.ignore(undone)));
60
+ for (const other of records) if (other.record !== host.endpoint) yield* forgetHost(other.record);
61
+ return { pushes };
62
+ });
63
+ /**
64
+ * Removes `host`'s sign-in, and says whether there was a token: the kept credential, then the
65
+ * origin's, then each record of the origin; while a helper still gives one back, it fails and
66
+ * keeps the records.
67
+ */
68
+ const removeSignIn = Effect.fnUntraced(function* (host) {
69
+ const { origin } = host;
70
+ const url = new URL(`${origin}/`);
71
+ const kept = yield* fillCredential(url);
72
+ if (kept !== void 0) yield* rejectCredential(url, kept);
73
+ yield* rejectCredential(url);
74
+ if ((yield* fillCredential(url)) !== void 0) return yield* failure("credential_not_removed", `Git's helper still keeps the token for ${hostName(host)}`, "Remove it with the helper's own tool, then sign out again");
75
+ for (const one of yield* recordsOf(host)) yield* forgetHost(one.record);
76
+ yield* globalConfig([pushKey(origin)], { unset: true });
77
+ return kept !== void 0;
78
+ }, (removing, host) => Effect.catchTag(removing, "BrokenField", () => Effect.fail(unsafeCredential(hostName(host)))));
79
+ export { checkedHelpers, removeSignIn, storeSignIn };
@@ -0,0 +1,28 @@
1
+ import { node } from "./node.mjs";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Data from "effect/Data";
4
+ import * as Layer from "effect/Layer";
5
+ import * as Context from "effect/Context";
6
+ // src/cli/sqlite.ts
7
+ /** A SQLite file that couldn't be opened or read, as one that isn't a database. */
8
+ var SqliteUnreadable = class extends Data.TaggedError("SqliteUnreadable") {};
9
+ /** The local SQLite `doctor` reads, read-only: Node's own, which has no Effect service (D12). */
10
+ var Sqlite = class extends Context.Service()("ref0-git/cli/Sqlite") {};
11
+ const migrated = (path) => Effect.try({
12
+ try: () => {
13
+ if (!node.fs.existsSync(path)) return /* @__PURE__ */ new Set();
14
+ const database = new (node.sqlite()).DatabaseSync(path, { readOnly: true });
15
+ try {
16
+ return database.prepare("select \"name\" from \"sqlite_master\" where \"name\" = ?").all("_migrations").length === 0 ? /* @__PURE__ */ new Set() : new Set(database.prepare("select \"name\" from \"_migrations\"").all().map((row) => String(row.name)));
17
+ } finally {
18
+ database.close();
19
+ }
20
+ },
21
+ catch: (cause) => new SqliteUnreadable({
22
+ path,
23
+ cause
24
+ })
25
+ });
26
+ /** `Sqlite` over `node:sqlite`. */
27
+ const layer = Layer.succeed(Sqlite, { migrated });
28
+ export { Sqlite, SqliteUnreadable, layer };
@@ -0,0 +1,141 @@
1
+ import { usageFailure } from "./failure.mjs";
2
+ import { hostFlag } from "./hosts.mjs";
3
+ import { CliModes, answer, printable, receipt, secrets, shown, utcDay } from "./output.mjs";
4
+ import { called, changed, durationOf, listed, pageFlags, pagesOf } from "./resources.mjs";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Redacted from "effect/Redacted";
7
+ import * as Option from "effect/Option";
8
+ import * as Command from "effect/cli/Command";
9
+ import * as Flag from "effect/cli/Flag";
10
+ import { tokenScopes, tokenStates } from "@ref0/git/rest";
11
+ import * as Argument from "effect/cli/Argument";
12
+ import * as Clock from "effect/Clock";
13
+ // src/cli/tokens.ts
14
+ /**
15
+ * `tokens`: create, list and revoke a host's tokens. A token `create` mints is for its subject, so
16
+ * it's never stored here: it's printed, alone on stdout, only with `--show-token`, which declares
17
+ * that delivery, and refused before anything is minted without it (Q3, as changed 21 Nov).
18
+ */
19
+ const coverageFlags = {
20
+ repo: Argument.String("REPO").pipe(Argument.withDescription("The repo the token covers, as acme/app"), Argument.optional),
21
+ prefix: Flag.String("prefix").pipe(Flag.withDescription("Every repo whose name starts with it, as acme/, instead of a REPO"), Flag.withMetavar("PREFIX"), Flag.optional)
22
+ };
23
+ /** The repo or the prefix a token command names: exactly one of them. */
24
+ const targetOf = (flags) => {
25
+ if (Option.isSome(flags.repo) && Option.isNone(flags.prefix)) return Effect.succeed(flags.repo.value);
26
+ if (Option.isSome(flags.prefix) && Option.isNone(flags.repo)) return Effect.succeed({ prefix: flags.prefix.value });
27
+ return Effect.fail(usageFailure("missing_target", "Name a REPO or a --prefix, not both"));
28
+ };
29
+ /** What a token covers, as a person reads it. */
30
+ const coverage = (token) => token.repo !== void 0 ? printable(token.repo) : token.prefix === "" ? "every repo" : `${printable(token.prefix ?? "")}*`;
31
+ const create = Command.make("create", {
32
+ ...coverageFlags,
33
+ host: hostFlag,
34
+ subject: Flag.String("subject").pipe(Flag.withDescription("Who the token is for: the actor it signs in as"), Flag.withMetavar("ID")),
35
+ scope: Flag.Literals("scope", tokenScopes).pipe(Flag.withDescription("What it may do: read, report a check, or write"), Flag.withDefault("read")),
36
+ expires: Flag.String("expires").pipe(Flag.withDescription("How long until it expires, as 12h or 90d"), Flag.withMetavar("DURATION"), Flag.withDefault("30d")),
37
+ showToken: Flag.Boolean("show-token").pipe(Flag.withDescription("Print the token on stdout, the only way to get it"), Flag.withDefault(false))
38
+ }, Effect.fnUntraced(function* (flags) {
39
+ const target = yield* targetOf(flags);
40
+ const lasts = yield* durationOf("expires", flags.expires);
41
+ if (!flags.showToken) {
42
+ const named = Option.match(flags.repo, {
43
+ onNone: () => ["--prefix", Option.getOrElse(flags.prefix, () => "")],
44
+ onSome: (repo) => [repo]
45
+ });
46
+ const host = Option.match(flags.host, {
47
+ onNone: () => [],
48
+ onSome: (h) => ["--host", h]
49
+ });
50
+ return yield* usageFailure("token_not_shown", "A token for someone else goes to them, so tokens create stores none: it prints it only with --show-token", {
51
+ says: "Print it, to hand to its subject",
52
+ run: [[
53
+ "tokens",
54
+ "create",
55
+ ...named,
56
+ ...host,
57
+ "--subject",
58
+ flags.subject,
59
+ "--scope",
60
+ flags.scope,
61
+ "--expires",
62
+ flags.expires,
63
+ "--show-token"
64
+ ]]
65
+ });
66
+ }
67
+ const now = yield* Clock.currentTimeMillis;
68
+ const made = yield* called(flags.host, (client, signal) => client.tokens.create(target, {
69
+ scope: flags.scope,
70
+ expiresAt: now + lasts,
71
+ subject: { id: flags.subject },
72
+ signal
73
+ }));
74
+ const { secret: received, ...record } = made.value;
75
+ const secret = Redacted.make(received);
76
+ secrets.hide(Redacted.value(secret));
77
+ const token = record;
78
+ yield* receipt({
79
+ done: `Created a token for ${printable(token.subject.id)} on ${made.host}`,
80
+ fields: [
81
+ ["ID", printable(token.id)],
82
+ ["Scope", `${token.scope} on ${coverage(token)}`],
83
+ ["Expires", utcDay(token.expiresAt)]
84
+ ]
85
+ });
86
+ if ((yield* CliModes).json) return yield* shown(secret, record);
87
+ yield* answer(Redacted.value(secret));
88
+ })).pipe(Command.withDescription("Create a token for someone, printed only with --show-token; it expires in 30 days unless --expires says"));
89
+ /** A token's row, as `tokens list` prints it. */
90
+ const tokenLine = (token) => [
91
+ token.id,
92
+ `${token.scope} on ${coverage(token)}`,
93
+ token.subject.id,
94
+ token.revokedAt === void 0 ? `expires ${utcDay(token.expiresAt)}` : "revoked"
95
+ ].map(printable).join(" ");
96
+ const list = Command.make("list", {
97
+ ...coverageFlags,
98
+ host: hostFlag,
99
+ state: Flag.Literals("state", tokenStates).pipe(Flag.withDescription("Which tokens: active, the default, expired, revoked or all"), Flag.optional),
100
+ ...pageFlags
101
+ }, Effect.fnUntraced(function* (flags) {
102
+ const target = yield* targetOf(flags);
103
+ const state = Option.getOrUndefined(flags.state);
104
+ const command = (host) => [
105
+ "tokens",
106
+ "list",
107
+ ...Option.match(flags.repo, {
108
+ onNone: () => ["--prefix", Option.getOrElse(flags.prefix, () => "")],
109
+ onSome: (repo) => [repo]
110
+ }),
111
+ ...["--host", host],
112
+ ...state === void 0 ? [] : ["--state", state]
113
+ ];
114
+ const read = yield* pagesOf(flags.host, flags, command, tokenLine, (client, page, signal) => {
115
+ const input = {
116
+ page,
117
+ signal
118
+ };
119
+ if (state !== void 0) input.state = state;
120
+ return client.tokens.list(target, input);
121
+ });
122
+ yield* listed(read, {
123
+ line: tokenLine,
124
+ none: "No tokens",
125
+ command,
126
+ choice: flags
127
+ });
128
+ })).pipe(Command.withDescription("List a repo's or a prefix's tokens"));
129
+ const revoke = Command.make("revoke", {
130
+ token: Argument.String("TOKEN").pipe(Argument.withDescription("The token's ID, as tokens list prints it")),
131
+ host: hostFlag
132
+ }, Effect.fnUntraced(function* (flags) {
133
+ const done = yield* called(flags.host, (client, signal) => client.tokens.revoke(flags.token, { signal }));
134
+ yield* changed({}, flags.token, { done: `Revoked token ${printable(flags.token)} on ${done.host}` });
135
+ })).pipe(Command.withDescription("Revoke a token, so it signs nothing in again"));
136
+ const tokensCommand = Command.make("tokens").pipe(Command.withDescription("The host's tokens (experimental)"), Command.withSubcommands([
137
+ create,
138
+ list,
139
+ revoke
140
+ ]));
141
+ export { tokensCommand };
@@ -0,0 +1,123 @@
1
+ import { forget, leftBehind, notPutBack } from "./failure.mjs";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Predicate from "effect/Predicate";
4
+ import * as FileSystem from "effect/FileSystem";
5
+ import * as Path from "effect/Path";
6
+ import * as Result from "effect/Result";
7
+ // src/cli/vendor.ts
8
+ const why = (error) => error.message;
9
+ /** A missing path's failure, which a check that it's there answers as `undefined`. */
10
+ const missing = (error) => Predicate.isTagged(error.reason, "NotFound") ? Effect.succeed(void 0) : Effect.fail(error);
11
+ /** A tag no other run's folder uses. */
12
+ const freshTag = () => Buffer.from(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(6))).toString("hex");
13
+ /**
14
+ * Puts `packed`'s tarballs into `folder`'s `vendor/`, where the specs `init` writes name them,
15
+ * before it writes, as one change that a failure undoes, all of it in one folder the run owns,
16
+ * `vendor/.ref0-init-<tag>/`, made with an exclusive `mkdir` that fails on any path already there,
17
+ * a link too, without following it:
18
+ *
19
+ * 1. Each tarball is written into the folder, as `<n>.part`.
20
+ * 2. Each destination is read without following a link: one that's there and isn't a file refuses.
21
+ * 3. Each is committed: a tarball already there is moved into the folder, as `<n>.kept`, then the
22
+ * part is renamed into place, both on `vendor/`'s own file system.
23
+ *
24
+ * A failure renames each moved tarball back and removes the one folder, which a recursive remove
25
+ * does without following its links, and `vendor/` and `vendor/cli/` when this run made them: a
26
+ * folder it can't remove is recorded as left, for the run's end to name. A destination it can't
27
+ * put back is `stranded`, with the file in the folder that holds its old
28
+ * bytes, and the folder stays. On success, the folder goes, or is recorded as left for the run's
29
+ * end to name. A cancel waits for all of that to end: it's uninterruptible, and waits on nothing
30
+ * but the disk, so no destination is left between its old tarball and its new one. The packed
31
+ * folder is `init`'s to remove, however the run ends.
32
+ */
33
+ const vendored = Effect.fnUntraced(function* (packed, folder, tag = freshTag()) {
34
+ const fs = yield* FileSystem.FileSystem;
35
+ const path = yield* Path.Path;
36
+ const own = `${folder}/vendor/.ref0-init-${tag}`;
37
+ const paths = [...packed.vendor.values()];
38
+ const made = [];
39
+ const moved = [];
40
+ /** `at`'s own entry, a link not followed, or `undefined` when nothing is there. */
41
+ const entryAt = (at) => fs.lstat(at).pipe(Effect.catch(missing));
42
+ const removed = (at) => fs.remove(at, {
43
+ recursive: true,
44
+ force: true
45
+ });
46
+ const madeFolder = Effect.fnUntraced(function* (at) {
47
+ if ((yield* entryAt(at)) !== void 0) return;
48
+ yield* fs.makeDirectory(at, { recursive: true });
49
+ made.push(at);
50
+ });
51
+ /**
52
+ * `why` as the run's refusal, once `paths` are removed, latest first: each is tried, and one
53
+ * that stays is recorded as left, inside the mask, so the run's end names it however it ends.
54
+ */
55
+ const refusedAfter = (why, removing) => Effect.forEach(removing(), (at) => removed(at).pipe(Effect.catch((error) => leftBehind(at, error))), { discard: true }).pipe(Effect.as({
56
+ kind: "refused",
57
+ why
58
+ }));
59
+ /** The run's folder and the folders it made, latest first. */
60
+ const everything = () => [own, ...made.toReversed()];
61
+ const vendorMade = yield* Effect.result(madeFolder(`${folder}/vendor`));
62
+ if (Result.isFailure(vendorMade)) return {
63
+ kind: "refused",
64
+ why: why(vendorMade.failure)
65
+ };
66
+ const ownMade = yield* Effect.result(fs.makeDirectory(own));
67
+ if (Result.isFailure(ownMade)) return yield* refusedAfter(why(ownMade.failure), () => made.toReversed());
68
+ const staged = yield* Effect.result(Effect.gen(function* () {
69
+ for (const [at, each] of paths.entries()) {
70
+ yield* fs.writeFile(`${own}/${at}.part`, yield* fs.readFile(`${packed.folder}/${each}`), { flag: "wx" });
71
+ yield* madeFolder(path.dirname(`${folder}/${each}`));
72
+ }
73
+ for (const each of paths) {
74
+ const held = yield* entryAt(`${folder}/${each}`);
75
+ if (held !== void 0 && held.type !== "File") return `${folder}/${each} is there and isn't a file`;
76
+ }
77
+ }));
78
+ if (Result.isFailure(staged)) return yield* refusedAfter(why(staged.failure), everything);
79
+ if (staged.success !== void 0) return yield* refusedAfter(staged.success, everything);
80
+ const committed = yield* Effect.result(Effect.gen(function* () {
81
+ for (const [at, each] of paths.entries()) {
82
+ const to = `${folder}/${each}`;
83
+ const one = {
84
+ to,
85
+ kept: (yield* entryAt(to)) !== void 0 ? `${own}/${at}.kept` : void 0,
86
+ placed: false
87
+ };
88
+ const { kept } = one;
89
+ if (kept !== void 0) {
90
+ yield* notPutBack(one, { message: "the run stopped before it could" });
91
+ yield* fs.rename(to, kept).pipe(Effect.tapError(() => forget(kept)));
92
+ }
93
+ moved.push(one);
94
+ yield* fs.rename(`${own}/${at}.part`, to);
95
+ one.placed = true;
96
+ }
97
+ }));
98
+ if (Result.isFailure(committed)) {
99
+ const stranded = [];
100
+ for (const each of moved.toReversed()) {
101
+ const back = each.kept !== void 0 ? fs.rename(each.kept, each.to) : each.placed ? removed(each.to) : Effect.void;
102
+ const putBack = yield* Effect.result(back);
103
+ if (each.kept !== void 0) yield* forget(each.kept);
104
+ if (Result.isFailure(putBack)) {
105
+ stranded.push({
106
+ to: each.to,
107
+ kept: each.kept
108
+ });
109
+ yield* notPutBack(each, putBack.failure);
110
+ }
111
+ }
112
+ if (stranded.length > 0) return {
113
+ kind: "stranded",
114
+ why: why(committed.failure),
115
+ stranded
116
+ };
117
+ return yield* refusedAfter(why(committed.failure), everything);
118
+ }
119
+ for (const each of moved) if (each.kept !== void 0) yield* forget(each.kept);
120
+ yield* removed(own).pipe(Effect.catch((error) => leftBehind(own, error)));
121
+ return { kind: "placed" };
122
+ }, Effect.uninterruptible);
123
+ export { vendored };