ref0-git 0.2.0 → 0.4.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 (210) hide show
  1. package/app/apps/github/.dev.vars.example +2 -1
  2. package/app/apps/github/generated/git-rest.ts +191 -25
  3. package/app/apps/github/generated/routeTree.gen.ts +21 -0
  4. package/app/apps/github/package.json +1 -1
  5. package/app/apps/github/src/branches/branch-list.tsx +8 -4
  6. package/app/apps/github/src/branches/branches.ts +10 -5
  7. package/app/apps/github/src/camo/addresses.ts +120 -0
  8. package/app/apps/github/src/camo/client.ts +125 -0
  9. package/app/apps/github/src/camo/fetch.ts +201 -0
  10. package/app/apps/github/src/camo/lookup.ts +23 -0
  11. package/app/apps/github/src/camo/node.ts +50 -0
  12. package/app/apps/github/src/camo/proxy.ts +116 -0
  13. package/app/apps/github/src/camo/sign-images.ts +307 -0
  14. package/app/apps/github/src/camo/signing.ts +80 -0
  15. package/app/apps/github/src/clients/allowed.ts +111 -18
  16. package/app/apps/github/src/clients/clients.ts +76 -61
  17. package/app/apps/github/src/clients/transport.ts +13 -0
  18. package/app/apps/github/src/code/code-tree.tsx +3 -1
  19. package/app/apps/github/src/code/file-view.tsx +15 -6
  20. package/app/apps/github/src/code/files.ts +26 -19
  21. package/app/apps/github/src/code/go-to-file.tsx +2 -1
  22. package/app/apps/github/src/code/load.ts +41 -23
  23. package/app/apps/github/src/code/markdown-files.ts +13 -2
  24. package/app/apps/github/src/code/ref-pages.ts +14 -5
  25. package/app/apps/github/src/code/ref-switcher.tsx +4 -3
  26. package/app/apps/github/src/code/refs.ts +42 -8
  27. package/app/apps/github/src/code/repo-home.tsx +6 -2
  28. package/app/apps/github/src/code/repo.ts +12 -6
  29. package/app/apps/github/src/code/saved.ts +5 -3
  30. package/app/apps/github/src/code/trees.ts +11 -9
  31. package/app/apps/github/src/components/markdown/markdown.css +6 -0
  32. package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
  33. package/app/apps/github/src/components/owner-card.tsx +3 -1
  34. package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
  35. package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
  36. package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
  37. package/app/apps/github/src/components/signin/device-card.tsx +9 -2
  38. package/app/apps/github/src/components/user-avatar.tsx +2 -1
  39. package/app/apps/github/src/context/context.ts +13 -0
  40. package/app/apps/github/src/diffs/blobs.ts +37 -14
  41. package/app/apps/github/src/diffs/diff-job.ts +53 -0
  42. package/app/apps/github/src/diffs/diff-worker.ts +6 -0
  43. package/app/apps/github/src/diffs/diffing.ts +136 -0
  44. package/app/apps/github/src/diffs/files.ts +4 -3
  45. package/app/apps/github/src/diffs/hunks.tsx +101 -53
  46. package/app/apps/github/src/diffs/patch.ts +20 -11
  47. package/app/apps/github/src/history/commit-diff.ts +10 -5
  48. package/app/apps/github/src/history/commit-list.tsx +3 -1
  49. package/app/apps/github/src/history/commit-page.tsx +4 -2
  50. package/app/apps/github/src/history/history.ts +12 -10
  51. package/app/apps/github/src/hooks/allowed.ts +9 -9
  52. package/app/apps/github/src/hooks/avatars.ts +3 -3
  53. package/app/apps/github/src/hooks/open-counts.ts +5 -4
  54. package/app/apps/github/src/hooks/profiles.ts +26 -12
  55. package/app/apps/github/src/hooks/repos.ts +78 -25
  56. package/app/apps/github/src/inbox/count.ts +30 -29
  57. package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
  58. package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
  59. package/app/apps/github/src/inbox/marks.ts +26 -15
  60. package/app/apps/github/src/inbox/release-tags.ts +7 -6
  61. package/app/apps/github/src/inbox/subjects.ts +5 -4
  62. package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
  63. package/app/apps/github/src/inbox/subscriptions.ts +95 -35
  64. package/app/apps/github/src/inbox/threads.ts +6 -6
  65. package/app/apps/github/src/issues/changes.ts +40 -16
  66. package/app/apps/github/src/issues/counts.ts +8 -5
  67. package/app/apps/github/src/issues/issue-list.tsx +20 -6
  68. package/app/apps/github/src/issues/issue-page.tsx +30 -14
  69. package/app/apps/github/src/issues/issues.ts +195 -46
  70. package/app/apps/github/src/issues/label-dialog.tsx +8 -11
  71. package/app/apps/github/src/issues/labels-page.tsx +35 -3
  72. package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
  73. package/app/apps/github/src/issues/milestones-page.tsx +269 -0
  74. package/app/apps/github/src/issues/new-issue.tsx +3 -1
  75. package/app/apps/github/src/issues/sidebar.tsx +8 -6
  76. package/app/apps/github/src/markdown/README.md +22 -17
  77. package/app/apps/github/src/markdown/context.ts +83 -10
  78. package/app/apps/github/src/markdown/images.ts +3 -2
  79. package/app/apps/github/src/markdown/lookup.ts +17 -11
  80. package/app/apps/github/src/markdown/page-budget.ts +50 -0
  81. package/app/apps/github/src/markdown/patches.ts +74 -32
  82. package/app/apps/github/src/markdown/query.ts +7 -2
  83. package/app/apps/github/src/markdown/remote.ts +106 -0
  84. package/app/apps/github/src/markdown/render.ts +101 -24
  85. package/app/apps/github/src/markdown/texts.ts +43 -0
  86. package/app/apps/github/src/markdown/words-module.d.ts +5 -0
  87. package/app/apps/github/src/markdown/words-plugin.ts +135 -0
  88. package/app/apps/github/src/names/repos.ts +1 -1
  89. package/app/apps/github/src/palette/palette.tsx +28 -10
  90. package/app/apps/github/src/palette/rows.tsx +93 -40
  91. package/app/apps/github/src/palette/server.ts +10 -7
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +137 -61
  94. package/app/apps/github/src/private-repos.ts +5 -5
  95. package/app/apps/github/src/pulls/compare-page.tsx +6 -3
  96. package/app/apps/github/src/pulls/files-tab.tsx +480 -214
  97. package/app/apps/github/src/pulls/held-summary.ts +178 -0
  98. package/app/apps/github/src/pulls/live.ts +6 -4
  99. package/app/apps/github/src/pulls/merge-box.tsx +17 -10
  100. package/app/apps/github/src/pulls/pull-list.tsx +6 -3
  101. package/app/apps/github/src/pulls/pull-page.tsx +19 -10
  102. package/app/apps/github/src/pulls/pull.ts +68 -40
  103. package/app/apps/github/src/pulls/pulls.ts +39 -22
  104. package/app/apps/github/src/pulls/review-drafts.ts +131 -0
  105. package/app/apps/github/src/pulls/review.ts +374 -99
  106. package/app/apps/github/src/pulls/threads.tsx +152 -0
  107. package/app/apps/github/src/queue/queue-page.tsx +15 -8
  108. package/app/apps/github/src/queue/queue.ts +35 -20
  109. package/app/apps/github/src/releases/latest-release.tsx +3 -1
  110. package/app/apps/github/src/releases/overview.tsx +4 -2
  111. package/app/apps/github/src/releases/release-form.tsx +8 -5
  112. package/app/apps/github/src/releases/release-list.tsx +8 -5
  113. package/app/apps/github/src/releases/release-view.tsx +1 -0
  114. package/app/apps/github/src/releases/releases.ts +33 -23
  115. package/app/apps/github/src/releases/tag-list.tsx +3 -1
  116. package/app/apps/github/src/router.tsx +5 -2
  117. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
  118. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
  119. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
  120. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
  121. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
  122. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
  123. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
  124. package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
  125. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
  126. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
  127. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
  128. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
  129. package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
  130. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
  131. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
  132. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
  133. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
  134. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
  135. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
  136. package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
  137. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
  138. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
  139. package/app/apps/github/src/routes/-nav.tsx +10 -2
  140. package/app/apps/github/src/routes/-root-testing.ts +29 -6
  141. package/app/apps/github/src/routes/__root.tsx +9 -4
  142. package/app/apps/github/src/routes/index.tsx +3 -1
  143. package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
  144. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
  145. package/app/apps/github/src/seed/acme.ts +1 -1
  146. package/app/apps/github/src/seed/seed.ts +199 -120
  147. package/app/apps/github/src/server.ts +24 -15
  148. package/app/apps/github/src/settings/account-avatar.tsx +4 -1
  149. package/app/apps/github/src/settings/general-settings.tsx +3 -1
  150. package/app/apps/github/src/settings/general.ts +4 -4
  151. package/app/apps/github/src/settings/hook-form.tsx +3 -1
  152. package/app/apps/github/src/settings/hook-list.tsx +5 -2
  153. package/app/apps/github/src/settings/hooks.ts +7 -7
  154. package/app/apps/github/src/settings/org-settings.tsx +3 -1
  155. package/app/apps/github/src/settings/orgs.ts +21 -11
  156. package/app/apps/github/src/settings/settings-layout.tsx +3 -1
  157. package/app/apps/github/src/signin/approval.ts +4 -3
  158. package/app/apps/github/src/signin/auth.ts +9 -2
  159. package/app/apps/github/src/signin/device-code.ts +8 -3
  160. package/app/apps/github/src/signin/device-prompt.ts +28 -3
  161. package/app/apps/github/src/signin/revoke.ts +36 -0
  162. package/app/apps/github/tsconfig.json +4 -1
  163. package/app/apps/github/vite.config.ts +8 -0
  164. package/app/pnpm-workspace.yaml +9 -5
  165. package/app/tsconfig.base.json +1 -0
  166. package/dist/cli/child.mjs +1 -1
  167. package/dist/cli/credentials.mjs +4 -4
  168. package/dist/cli/documents.mjs +32 -22
  169. package/dist/cli/events.mjs +1 -1
  170. package/dist/cli/failure.mjs +20 -7
  171. package/dist/cli/folders.mjs +2 -2
  172. package/dist/cli/git-remote-ref0.mjs +47 -22
  173. package/dist/cli/git.mjs +26 -5
  174. package/dist/cli/helpers.mjs +168 -35
  175. package/dist/cli/hosts.mjs +3 -3
  176. package/dist/cli/output.mjs +2 -2
  177. package/dist/cli/prompt.mjs +1 -1
  178. package/dist/cli/queue.mjs +7 -7
  179. package/dist/cli/ref0-git.mjs +2 -2
  180. package/dist/cli/repos.mjs +35 -18
  181. package/dist/cli/resources.mjs +5 -5
  182. package/dist/cli/retry-after.mjs +8 -0
  183. package/dist/cli/setup.mjs +172 -66
  184. package/dist/cli/sign-in.mjs +65 -23
  185. package/dist/cli/sign-ins.mjs +70 -13
  186. package/dist/cli/sqlite.mjs +2 -2
  187. package/dist/cli/tokens.mjs +3 -3
  188. package/dist/cli/vendor.mjs +1 -1
  189. package/dist/init/app.mjs +18 -20
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +4 -3
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +121 -9
  195. package/dist/init/frameworks.mjs +16 -0
  196. package/dist/init/git-module.mjs +22 -7
  197. package/dist/init/jsonc.mjs +9 -7
  198. package/dist/init/metadata.mjs +9 -3
  199. package/dist/init/mounts.mjs +13 -10
  200. package/dist/init/next.mjs +3 -5
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +41 -42
  203. package/dist/init/nuxt.mjs +153 -27
  204. package/dist/init/stores.mjs +14 -9
  205. package/dist/init/sveltekit.mjs +4 -2
  206. package/dist/init/template.mjs +9 -6
  207. package/dist/init/templates.mjs +64 -48
  208. package/dist/init/vercel.mjs +37 -36
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -4,6 +4,7 @@ import { LockIcon } from 'lucide-react';
4
4
  import { useState, type FormEvent } from 'react';
5
5
  import { toast } from 'sonner';
6
6
 
7
+ import { useClients } from '../clients/clients.ts';
7
8
  import type { RepoPlace } from '../code/places.ts';
8
9
  import { Alert, AlertDescription } from '../components/ui/alert.tsx';
9
10
  import { Button } from '../components/ui/button.tsx';
@@ -74,6 +75,7 @@ function Choice<Value extends string>({
74
75
  * whether it's active. The secret is sent once and never shown again.
75
76
  */
76
77
  export function HookForm({ place }: { readonly place: RepoPlace }) {
78
+ const clients = useClients();
77
79
  const allowed = useAllowed(place);
78
80
  const client = useQueryClient();
79
81
  const navigate = useNavigate();
@@ -86,7 +88,7 @@ export function HookForm({ place }: { readonly place: RepoPlace }) {
86
88
  const [events, setEvents] = useState<EventChoice>('push');
87
89
  const [tried, setTried] = useState(false);
88
90
  const made = useMutation({
89
- mutationFn: () => createHook(place, { ...hook, events: eventChoices[events] }),
91
+ mutationFn: () => createHook(clients, place, { ...hook, events: eventChoices[events] }),
90
92
  onSuccess: async () => {
91
93
  await client.invalidateQueries({ queryKey: ['hooks', place.owner, place.repo] });
92
94
  toast.success(`Added the webhook to ${hook.url}`);
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2
2
  import { WebhookIcon } from 'lucide-react';
3
3
 
4
4
  import { Go } from '../code/controls.tsx';
5
+ import { useClients } from '../clients/clients.ts';
5
6
  import type { RepoPlace } from '../code/places.ts';
6
7
  import { ConfirmAction } from '../components/confirm-action.tsx';
7
8
  import { LoadFailed } from '../components/states/states.tsx';
@@ -43,9 +44,10 @@ function HookRow({
43
44
  readonly hook: Hook;
44
45
  readonly deletes: boolean;
45
46
  }) {
47
+ const clients = useClients();
46
48
  const client = useQueryClient();
47
49
  const deleted = useMutation({
48
- mutationFn: () => deleteHook(place, hook.id),
50
+ mutationFn: () => deleteHook(clients, place, hook.id),
49
51
  onSuccess: () => client.invalidateQueries({ queryKey: ['hooks', place.owner, place.repo] }),
50
52
  });
51
53
 
@@ -102,7 +104,8 @@ function HookRow({
102
104
 
103
105
  /** The repo's webhooks, with Add webhook for whoever may add one. */
104
106
  export function HookList({ place }: { readonly place: RepoPlace }) {
105
- const hooks = useQuery(hookList(place));
107
+ const clients = useClients();
108
+ const hooks = useQuery(hookList(clients, place));
106
109
  const allowed = useAllowed(place);
107
110
 
108
111
  return (
@@ -1,7 +1,7 @@
1
1
  import type { components, operations } from '@octokit/openapi-types';
2
2
  import { queryOptions } from '@tanstack/react-query';
3
3
 
4
- import { github } from '../clients/clients.ts';
4
+ import type { Clients } from '../clients/clients.ts';
5
5
  import type { RepoPlace } from '../code/places.ts';
6
6
  import { everyPage, failure } from '../hooks/answers.ts';
7
7
 
@@ -42,13 +42,13 @@ const hookOf = (hook: RestHook): Hook => ({
42
42
  });
43
43
 
44
44
  /** The repo's webhooks, every page of them. */
45
- export const hookList = (place: RepoPlace) =>
45
+ export const hookList = (clients: Clients, place: RepoPlace) =>
46
46
  queryOptions({
47
47
  queryKey: ['hooks', place.owner, place.repo],
48
48
  queryFn: async () => {
49
49
  const hooks = await everyPage(async (after) => {
50
50
  // `after` is the drop-in's cursor, which GitHub's types don't name: a spread passes it.
51
- const answer = await github.GET('/repos/{owner}/{repo}/hooks', {
51
+ const answer = await clients.github.GET('/repos/{owner}/{repo}/hooks', {
52
52
  params: { path: place, query: { ...{ per_page: 100, after } } },
53
53
  });
54
54
  if (answer.data === undefined) throw failure("The webhooks didn't load", answer);
@@ -61,7 +61,7 @@ export const hookList = (place: RepoPlace) =>
61
61
  });
62
62
 
63
63
  /** Adds a webhook to the repo; an empty secret sends none. */
64
- export const createHook = async (place: RepoPlace, hook: NewHook) => {
64
+ export const createHook = async (clients: Clients, place: RepoPlace, hook: NewHook) => {
65
65
  const config: HookConfig = {
66
66
  url: hook.url,
67
67
  content_type: hook.contentType,
@@ -69,7 +69,7 @@ export const createHook = async (place: RepoPlace, hook: NewHook) => {
69
69
  insecure_ssl: '0',
70
70
  };
71
71
  if (hook.secret !== '') config.secret = hook.secret;
72
- const answer = await github.POST('/repos/{owner}/{repo}/hooks', {
72
+ const answer = await clients.github.POST('/repos/{owner}/{repo}/hooks', {
73
73
  params: { path: place },
74
74
  body: { name: 'web', config, events: [...hook.events], active: hook.active },
75
75
  });
@@ -79,8 +79,8 @@ export const createHook = async (place: RepoPlace, hook: NewHook) => {
79
79
  };
80
80
 
81
81
  /** Deletes the repo's webhook `id`. */
82
- export const deleteHook = async (place: RepoPlace, id: number) => {
83
- const answer = await github.DELETE('/repos/{owner}/{repo}/hooks/{hook_id}', {
82
+ export const deleteHook = async (clients: Clients, place: RepoPlace, id: number) => {
83
+ const answer = await clients.github.DELETE('/repos/{owner}/{repo}/hooks/{hook_id}', {
84
84
  params: { path: { ...place, hook_id: id } },
85
85
  });
86
86
  if (!answer.response.ok) throw failure("The webhook wasn't deleted", answer);
@@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query';
2
2
  import { UsersIcon } from 'lucide-react';
3
3
  import type { ReactNode } from 'react';
4
4
 
5
+ import { useClients } from '../clients/clients.ts';
5
6
  import { LoadFailed, LoadingSkeleton, NotFound } from '../components/states/states.tsx';
6
7
  import { Card, CardContent, CardHeader, CardTitle } from '../components/ui/card.tsx';
7
8
  import {
@@ -148,7 +149,8 @@ const among = (logins: readonly string[], login: string) =>
148
149
  * changes it.
149
150
  */
150
151
  export function OrgSettings({ org, viewer }: { readonly org: string; readonly viewer: string }) {
151
- const directory = useQuery(orgDirectory(org));
152
+ const clients = useClients();
153
+ const directory = useQuery(orgDirectory(clients, org));
152
154
  if (directory.error !== null) return <LoadFailed message={directory.error.message} />;
153
155
 
154
156
  if (directory.data === undefined) return <OrgSettingsSkeleton />;
@@ -1,6 +1,6 @@
1
1
  import { queryOptions } from '@tanstack/react-query';
2
2
 
3
- import { github } from '../clients/clients.ts';
3
+ import type { Clients } from '../clients/clients.ts';
4
4
  import { everyPage, failure, type EveryPage } from '../hooks/answers.ts';
5
5
  import { type Pictures, picturesOf } from '../hooks/avatars.ts';
6
6
 
@@ -38,9 +38,14 @@ const loginsOf = (
38
38
  };
39
39
 
40
40
  /** Every login of team `slug` in `org`, to the pages `everyPage` reads, into `pictures`. */
41
- const teamMembers = (org: string, slug: string, pictures: Map<string, string | null>) =>
41
+ const teamMembers = (
42
+ clients: Clients,
43
+ org: string,
44
+ slug: string,
45
+ pictures: Map<string, string | null>,
46
+ ) =>
42
47
  everyPage(async (after) => {
43
- const answer = await github.GET('/orgs/{org}/teams/{team_slug}/members', {
48
+ const answer = await clients.github.GET('/orgs/{org}/teams/{team_slug}/members', {
44
49
  params: { path: { org, team_slug: slug }, query: paging(after) },
45
50
  });
46
51
  if (answer.data === undefined) throw failure(`${slug}'s members didn't load`, answer);
@@ -55,9 +60,14 @@ const teamMembers = (org: string, slug: string, pictures: Map<string, string | n
55
60
  * Every login in `org` with `role`, GitHub's `all` or `admin`, which holds its owners too, into
56
61
  * `pictures`.
57
62
  */
58
- const orgMembers = (org: string, role: 'all' | 'admin', pictures: Map<string, string | null>) =>
63
+ const orgMembers = (
64
+ clients: Clients,
65
+ org: string,
66
+ role: 'all' | 'admin',
67
+ pictures: Map<string, string | null>,
68
+ ) =>
59
69
  everyPage(async (after) => {
60
- const answer = await github.GET('/orgs/{org}/members', {
70
+ const answer = await clients.github.GET('/orgs/{org}/members', {
61
71
  params: { path: { org }, query: { ...paging(after), role } },
62
72
  });
63
73
  if (answer.data === undefined) throw failure("The members didn't load", answer);
@@ -72,20 +82,20 @@ const orgMembers = (org: string, role: 'all' | 'admin', pictures: Map<string, st
72
82
  * `org`, its members and its teams with theirs, as the drop-in's org routes read them from the
73
83
  * host's `people`: `null` when there's no such org.
74
84
  */
75
- export const orgDirectory = (org: string) =>
85
+ export const orgDirectory = (clients: Clients, org: string) =>
76
86
  queryOptions({
77
87
  queryKey: ['org-directory', org],
78
88
  queryFn: async (): Promise<OrgDirectory | null> => {
79
- const found = await github.GET('/orgs/{org}', { params: { path: { org } } });
89
+ const found = await clients.github.GET('/orgs/{org}', { params: { path: { org } } });
80
90
  if (found.response.status === 404) return null;
81
91
 
82
92
  if (found.data === undefined) throw failure(`${org} didn't load`, found);
83
93
 
84
94
  const pictures = new Map<string, string | null>();
85
- const members = orgMembers(org, 'all', pictures);
86
- const admins = orgMembers(org, 'admin', pictures);
95
+ const members = orgMembers(clients, org, 'all', pictures);
96
+ const admins = orgMembers(clients, org, 'admin', pictures);
87
97
  const teams = everyPage(async (after) => {
88
- const answer = await github.GET('/orgs/{org}/teams', {
98
+ const answer = await clients.github.GET('/orgs/{org}/teams', {
89
99
  params: { path: { org }, query: paging(after) },
90
100
  });
91
101
  if (answer.data === undefined) throw failure("The teams didn't load", answer);
@@ -95,7 +105,7 @@ export const orgDirectory = (org: string) =>
95
105
  slug: team.slug,
96
106
  name: team.name,
97
107
  description: team.description,
98
- members: await teamMembers(org, team.slug, pictures),
108
+ members: await teamMembers(clients, org, team.slug, pictures),
99
109
  })),
100
110
  );
101
111
 
@@ -4,6 +4,7 @@ import type { ReactNode } from 'react';
4
4
 
5
5
  import type { PageOperation } from '../clients/allowed.ts';
6
6
  import { Go } from '../code/controls.tsx';
7
+ import { useClients } from '../clients/clients.ts';
7
8
  import type { RepoPlace } from '../code/places.ts';
8
9
  import { LoadFailed } from '../components/states/states.tsx';
9
10
  import { Alert, AlertDescription } from '../components/ui/alert.tsx';
@@ -48,7 +49,8 @@ export function SettingsLayout({
48
49
  readonly current: string;
49
50
  readonly children: ReactNode;
50
51
  }) {
51
- const asked = useQuery(allowedHere(place));
52
+ const clients = useClients();
53
+ const asked = useQuery(allowedHere(clients, place));
52
54
  const allowed = asked.data;
53
55
 
54
56
  if (allowed === undefined) {
@@ -9,7 +9,7 @@ import type {
9
9
 
10
10
  import { ownerProblem } from '../names/owners.ts';
11
11
  import { type StarterAuth, sessionFrom } from './auth.ts';
12
- import { openPrompt, sealPrompt, sealRetry } from './device-prompt.ts';
12
+ import { openPrompt, sealPrompt, sealRetry, tokenScopeOf } from './device-prompt.ts';
13
13
 
14
14
  /** What the starter's approval page decides with: the person's session, and where it's served. */
15
15
  export interface StarterApprovalOptions {
@@ -124,7 +124,8 @@ const shown = async (
124
124
  /**
125
125
  * A decision posted from the Card: from the app's own page, by a live session, with the sealed
126
126
  * prompt it showed, for that person, unexpired and for the code Git found. It decides on Git's
127
- * prompt, never the sealed one, and Git checks the code is still pending as it settles.
127
+ * prompt, never the sealed one, granting `tokenScopeOf` its scopes, and Git checks the code is still
128
+ * pending as it settles.
128
129
  */
129
130
  const decided = async (
130
131
  input: ConfirmApprovalPage,
@@ -157,7 +158,7 @@ const decided = async (
157
158
  kind: 'approve',
158
159
  actor: { id: login },
159
160
  target: { prefix: '' },
160
- scope: 'write',
161
+ scope: tokenScopeOf(prompt.scopes),
161
162
  expiresAt: Date.now() + options.tokenDays * day,
162
163
  });
163
164
 
@@ -28,6 +28,7 @@ import {
28
28
  isTaken,
29
29
  ownerNames,
30
30
  } from './owner-names.ts';
31
+ import { revokeRetrying } from './revoke.ts';
31
32
  import { open, seal } from './seal.ts';
32
33
  import { avatarTable, avatars } from './avatars.ts';
33
34
  import { type Unborn, forgetUnborn } from './unborn.ts';
@@ -599,7 +600,11 @@ export const starterAuth = (options: StarterAuthOptions): Auth => {
599
600
  update: { gitTokenId: made.value.id, gitToken },
600
601
  });
601
602
  // Only a row with no token takes it; `returning` answers nothing for one it skipped.
602
- if (held === null || held === undefined) await options.tokens.revoke(made.value.id);
603
+ if (held !== null && held !== undefined) return;
604
+
605
+ const revoked = await revokeRetrying(() => options.tokens.revoke(made.value.id));
606
+ if (revoked.kind !== 'success')
607
+ console.error(`Git didn't revoke token ${made.value.id}`);
603
608
  },
604
609
  },
605
610
  delete: {
@@ -608,7 +613,9 @@ export const starterAuth = (options: StarterAuthOptions): Auth => {
608
613
  // on it, and one still to come is refused until the session would end.
609
614
  const key = sessionKeyOf(session.id);
610
615
  const until = session.expiresAt;
611
- const revoked = await options.tokens.revokeKey({ prefix: '' }, key, { until });
616
+ const revoked = await revokeRetrying(() =>
617
+ options.tokens.revokeKey({ prefix: '' }, key, { until }),
618
+ );
612
619
  if (revoked.kind !== 'success') console.error(`Git didn't revoke session token ${key}`);
613
620
  },
614
621
  },
@@ -4,7 +4,9 @@ import { flow } from 'effect/Function';
4
4
  import * as Option from 'effect/Option';
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { clientLabel, openPrompt, openRetry } from './device-prompt.ts';
7
+ import type { TokenScope } from '@ref0/git';
8
+
9
+ import { clientLabel, openPrompt, openRetry, tokenScopeOf } from './device-prompt.ts';
8
10
 
9
11
  /**
10
12
  * What `/login/code`'s Card shows: the Code field, with any error under it; the confirm, with a
@@ -24,9 +26,11 @@ export type DeviceCardState =
24
26
  readonly client: string;
25
27
  readonly login: string;
26
28
  readonly userCode: string;
27
- /** What Approve grants: write to every repo `login` may write, for this many days. */
29
+ /** What Approve grants over every repo `login` may reach: `tokenScopeOf` the device's scopes. */
30
+ readonly tokenScope: TokenScope;
31
+ /** How many days the token Approve mints lasts. */
28
32
  readonly days: number;
29
- /** The scopes the device asked for, which the starter doesn't narrow the grant to. */
33
+ /** The scopes the device asked for, which `tokenScope` reaches past `read` only if one names it. */
30
34
  readonly scopes: readonly string[];
31
35
  /** The sealed prompt, posted back in a hidden field beside `user_code` and `decision`. */
32
36
  readonly prompt: string;
@@ -88,6 +92,7 @@ export const deviceCard = createServerFn({ method: 'GET' })
88
92
  client: clientLabel(opened.clientId),
89
93
  login: session.login,
90
94
  userCode: opened.userCode,
95
+ tokenScope: tokenScopeOf(opened.scopes),
91
96
  days: opened.days,
92
97
  scopes: opened.scopes,
93
98
  prompt: data.prompt,
@@ -1,5 +1,6 @@
1
- import type { DeviceApproval } from '@ref0/git';
2
- import { ghClientId } from '@ref0/git/auth';
1
+ import type { DeviceApproval, TokenScope } from '@ref0/git';
2
+ import { ghClientId, ghWriteScope } from '@ref0/git/auth';
3
+ import { tokenScopes } from '@ref0/git/rest';
3
4
  import * as Option from 'effect/Option';
4
5
  import * as Schema from 'effect/Schema';
5
6
 
@@ -33,7 +34,31 @@ const purpose = 'device-prompt';
33
34
  /** How long a sealed prompt holds. */
34
35
  const promptLife = 10 * 60 * 1000;
35
36
 
36
- /** What Approve would grant: write as `login`, over every repo they may write, for `days`. */
37
+ /**
38
+ * The GitHub scopes a device may ask for that reach past `read`: `ghWriteScope`, `repo`, writes,
39
+ * as gh's and `ref0-git login`'s pushes need, and `repo:status` and `repo_deployment` report, as
40
+ * the drop-in's statuses, checks and deployments take. Every other scope, known or not, and none
41
+ * at all, gets `read`, Git's narrowest token scope, so nothing a device asks for reaches past it
42
+ * unless it names one of these. `public_repo` reads, where GitHub would let it write public repos:
43
+ * a deliberate narrowing, since a Git token has no write over public repos alone.
44
+ */
45
+ const pastRead: ReadonlyMap<string, TokenScope> = new Map([
46
+ [ghWriteScope, 'write'],
47
+ ['repo:status', 'report'],
48
+ ['repo_deployment', 'report'],
49
+ ]);
50
+
51
+ /** Approve's token scope: each scope a device asks for maps as GitHub reads it; the widest wins. */
52
+ export const tokenScopeOf = (scopes: readonly string[]): TokenScope => {
53
+ const reached = scopes.map((scope) => tokenScopes.indexOf(pastRead.get(scope) ?? 'read'));
54
+
55
+ return tokenScopes[Math.max(0, ...reached)] ?? 'read';
56
+ };
57
+
58
+ /**
59
+ * What Approve would grant: a token as `login`, over every repo they may reach, for `days`, at
60
+ * `tokenScopeOf` the prompt's scopes.
61
+ */
37
62
  export interface Grant {
38
63
  readonly login: string;
39
64
  readonly days: number;
@@ -0,0 +1,36 @@
1
+ import type { GitError, Result } from '@ref0/git';
2
+
3
+ /**
4
+ * The most times a session's token revoke is sent again after other writes to the same tokens won
5
+ * every try. It matches the CLI's `tooManyWritesTriesMost` today, and the two are apart on purpose:
6
+ * a person at a terminal waits on the CLI's, while nobody waits on a sign-out's hook.
7
+ */
8
+ export const revokeTriesMost = 3;
9
+
10
+ /** How long a revoke waits before it's sent again the first time, in ms, doubling after each. */
11
+ export const revokePauseFirst = 250;
12
+
13
+ /** Whether `error` says nothing was written, so sending the same revoke again is safe. */
14
+ const tooManyWrites = (error: GitError) =>
15
+ error.code === 'UNAVAILABLE' && error.context?.reason === 'too-many-writes';
16
+
17
+ const paused = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
18
+
19
+ /**
20
+ * `revoke`, sent again while Git answers that other writes won every try, `revokeTriesMost` times
21
+ * at most. Any other failure answers at once, as does the last try's.
22
+ */
23
+ export const revokeRetrying = async (
24
+ revoke: () => Promise<Result<void>>,
25
+ ): Promise<Result<void>> => {
26
+ let revoked = await revoke();
27
+
28
+ for (let tried = 0; tried < revokeTriesMost; tried += 1) {
29
+ if (revoked.kind === 'success' || !tooManyWrites(revoked.error)) return revoked;
30
+
31
+ await paused(revokePauseFirst * 2 ** tried);
32
+ revoked = await revoke();
33
+ }
34
+
35
+ return revoked;
36
+ };
@@ -20,6 +20,9 @@
20
20
  "src/git.ts",
21
21
  "src/policy.ts",
22
22
  "src/env.ts",
23
- "src/signin/approval.ts"
23
+ "src/signin/approval.ts",
24
+ "src/camo/lookup.ts",
25
+ "src/camo/node.ts",
26
+ "src/markdown/words-plugin.ts"
24
27
  ]
25
28
  }
@@ -4,13 +4,21 @@ import { tanstackStart } from '@tanstack/react-start/plugin/vite';
4
4
  import viteReact from '@vitejs/plugin-react';
5
5
  import { defineConfig } from 'vite-plus';
6
6
 
7
+ import { wordsMemoryMax } from './src/markdown/words-plugin.ts';
8
+
7
9
  // Start's server build runs in the Worker: Cloudflare's plugin takes its `ssr` environment.
8
10
  export default defineConfig(({ command }) => ({
9
11
  // The dev seed is on only under the dev server, `vp dev`: every build drops it and its imports,
10
12
  // whatever its mode or `NODE_ENV`.
11
13
  define: { __DEV_SEED__: JSON.stringify(command === 'serve') },
14
+ // The diff and highlight Workers are modules: `@pierre/diffs`' loads its highlighter lazily.
15
+ worker: { format: 'es' },
12
16
  plugins: [
13
17
  cloudflare({ viteEnvironment: { name: 'ssr' } }),
18
+ // Words' WebAssembly under the drop-in's most on its memory (#1098): after Cloudflare's
19
+ // plugin, whose resolve of a `.wasm` import asks this one for the file and makes it the
20
+ // Worker's module.
21
+ wordsMemoryMax(),
14
22
  tanstackStart({
15
23
  // NodeNext, as the repo types it, resolves only imports that name their extension.
16
24
  router: { generatedRouteTree: '../generated/routeTree.gen.ts', addExtensions: true },
@@ -1,5 +1,5 @@
1
- # The workspace's three packages, `@ref0/infra`, `@ref0/git` and `@ref0/github`, the app over them,
2
- # `apps/github`, the examples that host them, the benchmarks, and the root's tooling. The catalog
1
+ # The workspace's packages, `@ref0/infra`, `@ref0/xdiff-wasm`, `@ref0/git` and `@ref0/github`, the
2
+ # app over them, `apps/github`, the examples that host them, the benchmarks, and the root's tooling. The catalog
3
3
  # pins every shared version once, at home's versions.
4
4
  packages:
5
5
  - packages/*
@@ -45,6 +45,11 @@ catalog:
45
45
  # Octokit's GitHub App auth, which @ref0/github's App tests sign JWTs and mint installation
46
46
  # tokens with, as a CI job would. MIT.
47
47
  '@octokit/auth-app': 8.3.1
48
+ # Octokit's core client and its retry plugin, which the `octokit` package turns on by default:
49
+ # @ref0/github's tests send the drop-in's refusals through them, as such a client would, to see
50
+ # which it sends again. MIT.
51
+ '@octokit/core': 7.0.8
52
+ '@octokit/plugin-retry': 8.1.1
48
53
  # Octokit's request, which the App tests point at the handler's fetch for auth-app. MIT.
49
54
  '@octokit/request': 10.0.16
50
55
  # Octokit's webhook signature check, which @ref0/github's webhook tests verify deliveries with.
@@ -62,7 +67,7 @@ catalog:
62
67
  # The app's Markdown renderer: words, a WebAssembly parser, with hooks for GitHub's alerts,
63
68
  # anchors, references and URLs (Q213). Apache-2.0.
64
69
  '@pierre/words': 0.3.0
65
- '@ref0/workspace': 0.4.0
70
+ '@ref0/workspace': 0.6.0
66
71
  '@tailwindcss/vite': 4.3.5
67
72
  # The app's stack: TanStack Start, its router and Query, and React, as spike F ran them, at the
68
73
  # newest releases past pnpm's minimum release age.
@@ -157,7 +162,6 @@ catalog:
157
162
  # The app's REST clients, typed by OpenAPI: GitHub's by @octokit/openapi-types, and Git's by
158
163
  # types `openapi-typescript` writes from its OpenAPI document. MIT.
159
164
  openapi-fetch: 0.17.0
160
- openapi-react-query: 0.5.4
161
165
  openapi-typescript: 7.13.0
162
166
  # Mermaid drawn as SVG on the server, with no DOM: the app's diagrams, in its Markdown. MIT.
163
167
  pele: 1.13.0
@@ -168,7 +172,7 @@ catalog:
168
172
  react-day-picker: 10.0.2
169
173
  react-dom: 19.3.1
170
174
  # Rolldown, the bundler Alchemy's Workers build with: for examples/git-alchemy's test that
171
- # @ref0/git/xdiff.wasm resolves as Alchemy's Worker bundle does, at Alchemy's own version. MIT.
175
+ # @ref0/xdiff-wasm resolves as Alchemy's Worker bundle does, at Alchemy's own version. MIT.
172
176
  rolldown: 1.2.16
173
177
  # npm's version ranges, for ref0-git's property that `init` reads a framework's major from its
174
178
  # package.json spec as npm does. ISC. At the release already in the lockfile.
@@ -114,6 +114,7 @@
114
114
  "packages/*/src/**/*.test.ts",
115
115
  "packages/*/src/**/testing/*.ts",
116
116
  "apps/*/src/**/*.test.ts",
117
+ "examples/*/src/**/*.test.ts",
117
118
  "bench/src/**/*.test.ts",
118
119
  "scripts/**/*.test.ts",
119
120
  "verification/**/*.test.ts"
@@ -13,7 +13,7 @@ const signalled = (error) => /receipt of signal: '([A-Z0-9]+)'/.exec(error.messa
13
13
  * can't prompt, and its output on stderr, so stdout holds only the answer. A cancel sends it
14
14
  * SIGINT, and SIGKILL if it hasn't stopped within `stopMs`.
15
15
  */
16
- const runChild = Effect.fnUntraced(function* (argv, cwd) {
16
+ const runChild = /* @__PURE__ */ Effect.fnUntraced(function* (argv, cwd) {
17
17
  const [command, ...args] = argv;
18
18
  const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
19
19
  const stdio = yield* Stdio.Stdio;
@@ -1,7 +1,7 @@
1
1
  import { gitRun } from "./git.mjs";
2
2
  import * as Effect from "effect/Effect";
3
- import * as Redacted from "effect/Redacted";
4
3
  import * as Data from "effect/Data";
4
+ import * as Redacted from "effect/Redacted";
5
5
  // src/cli/credentials.ts
6
6
  /**
7
7
  * Git's credential protocol, as `git-remote-ref0` and `ref0-git` speak it: `git credential fill`,
@@ -44,7 +44,7 @@ const fieldsOf = (text) => new Map(text.split("\n").flatMap((line) => {
44
44
  * The credential Git's helpers keep for `url`, or `undefined` when none does. With `ask`, Git may
45
45
  * ask at the terminal, as it does for a push; without, it never does.
46
46
  */
47
- const fillCredential = Effect.fnUntraced(function* (url, options = {}) {
47
+ const fillCredential = /* @__PURE__ */ Effect.fnUntraced(function* (url, options = {}) {
48
48
  const input = yield* credentialInput(url);
49
49
  const ran = yield* gitRun(options.ask === true ? ["credential", "fill"] : [
50
50
  "-c",
@@ -71,14 +71,14 @@ const fillCredential = Effect.fnUntraced(function* (url, options = {}) {
71
71
  };
72
72
  });
73
73
  /** Stores `credential` for `url` in each of Git's helpers. */
74
- const approveCredential = Effect.fnUntraced(function* (url, credential) {
74
+ const approveCredential = /* @__PURE__ */ Effect.fnUntraced(function* (url, credential) {
75
75
  yield* gitRun(["credential", "approve"], {
76
76
  input: yield* credentialInput(url, credential),
77
77
  keepStarted: true
78
78
  });
79
79
  });
80
80
  /** Removes `credential`, or whatever is kept for `url` with none, from each of Git's helpers. */
81
- const rejectCredential = Effect.fnUntraced(function* (url, credential) {
81
+ const rejectCredential = /* @__PURE__ */ Effect.fnUntraced(function* (url, credential) {
82
82
  yield* gitRun(["credential", "reject"], { input: yield* credentialInput(url, credential) });
83
83
  });
84
84
  export { BrokenField, approveCredential, breaksField, fillCredential, rejectCredential, signals };