ref0-git 0.3.0 → 0.6.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 +9 -8
  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 +7 -4
  90. package/app/apps/github/src/palette/rows.tsx +54 -33
  91. package/app/apps/github/src/palette/server.ts +5 -5
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +165 -66
  94. package/app/apps/github/src/private-repos.ts +2 -2
  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 -110
  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 +12 -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 +1 -1
  174. package/dist/cli/helpers.mjs +2 -2
  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 +4 -4
  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 +20 -21
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +3 -2
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +120 -13
  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 +2 -2
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +42 -45
  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 +63 -47
  208. package/dist/init/vercel.mjs +37 -37
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -1,16 +1,18 @@
1
- import { accept, refs, reject } from '@ref0/git';
1
+ import { accept, gitError, Rules, reject } from '@ref0/git';
2
2
  import type {
3
3
  ActorId,
4
4
  AuthorizeInput,
5
+ GitError,
5
6
  GitAuthorize,
7
+ InternalRepoId,
6
8
  NamedActor,
7
9
  PushRule,
8
10
  RefName,
9
- RepoId,
11
+ RepoName,
10
12
  TokenInfo,
11
13
  TokenOperation,
12
14
  } from '@ref0/git';
13
- import { defaultOrg, defaultPeople } from '@ref0/github';
15
+ import { defaultOrg, defaultPeople, People } from '@ref0/github';
14
16
  import type {
15
17
  GitHubAuthorization,
16
18
  GitHubAuthorize,
@@ -33,6 +35,7 @@ import type {
33
35
  PeopleUser,
34
36
  PeopleViewer,
35
37
  } from '@ref0/github';
38
+ import * as Effect from 'effect/Effect';
36
39
 
37
40
  import { type StarterApprovalOptions, starterApprovalPage } from './signin/approval.ts';
38
41
  import type { Account, Avatars, Membership } from './context/context.ts';
@@ -50,7 +53,7 @@ import { orgTokenView, type Orgs } from './signin/orgs.ts';
50
53
  /** How long a sign-in lasts before the person signs in again. */
51
54
  export const tokenDays = 30;
52
55
 
53
- const ownerOf = (repo: RepoId) => repo.split('/', 1)[0];
56
+ const ownerOf = (repo: RepoName) => repo.split('/', 1)[0];
54
57
 
55
58
  /** A page of one of the directory's lists, as `People` answers one. */
56
59
  interface Listed<Item> {
@@ -87,6 +90,16 @@ const refusedLookup = (input: PeopleInput): PeopleAnswer => {
87
90
  }
88
91
  };
89
92
 
93
+ /**
94
+ * A read of the starter's own tables, as the directory's Effect: one that rejects fails closed as
95
+ * Git's `UNAVAILABLE`, in fixed words, so neither D1's error nor its words reach the drop-in.
96
+ */
97
+ const read = <A>(run: () => Promise<A>): Effect.Effect<A, GitError> =>
98
+ Effect.tryPromise({
99
+ try: run,
100
+ catch: () => gitError('UNAVAILABLE', "The starter's directory can't be read now"),
101
+ });
102
+
90
103
  /** The orgs' list a directory answers, which the drop-in doesn't name apart. */
91
104
  type PeopleOrgs = Extract<PeopleInput, { readonly kind: 'orgs' }>;
92
105
 
@@ -117,6 +130,20 @@ const contributions: ReadonlySet<string> = new Set([
117
130
  'review.create',
118
131
  ]);
119
132
 
133
+ /**
134
+ * What the drop-in asks as the author of what it acts on (Q857): an issue's edit, a conversation
135
+ * comment's or a review comment's edit or delete (Q869), and a review thread's resolve, by the
136
+ * pull request's author (Q891).
137
+ */
138
+ const authorsOwn: ReadonlySet<string> = new Set([
139
+ 'issue.update',
140
+ 'comment.update',
141
+ 'comment.delete',
142
+ 'review.update',
143
+ 'review.delete',
144
+ 'review.resolve',
145
+ ]);
146
+
120
147
  const signInFirst = reject({ message: 'Sign in first' });
121
148
 
122
149
  /**
@@ -175,7 +202,7 @@ export type PrivateRepos = (
175
202
  prefix: string,
176
203
  most: number,
177
204
  host: GitHubReadableReposInput['host'],
178
- ) => Promise<{ readonly names: readonly RepoId[]; readonly more: boolean }>;
205
+ ) => Promise<{ readonly names: readonly RepoName[]; readonly more: boolean }>;
179
206
 
180
207
  /**
181
208
  * Where the drop-in's people find an uploaded picture (Q757): the app's origin, whose
@@ -186,15 +213,22 @@ export interface Pictures {
186
213
  readonly avatars: Pick<Avatars, 'hash'>;
187
214
  }
188
215
 
216
+ /** The name `internalId`'s repo has now, `undefined` once none holds it. */
217
+ export type RepoNameOf = (
218
+ internalId: InternalRepoId,
219
+ signal: AbortSignal,
220
+ ) => Promise<RepoName | undefined>;
221
+
189
222
  /**
190
- * What the starter's policy reads past its orgs: its `Pictures`, both or neither, and
191
- * `privateRepos`, which lists an owner's private repos for the owner index's hook. With none, it
192
- * names no private repo.
223
+ * What the starter's policy reads past its orgs: its `Pictures`, both or neither,
224
+ * `privateRepos`, which lists an owner's private repos for the owner index's hook, and
225
+ * `repoName`, which the drop-in's owner check reads. With no `privateRepos`, it names no private
226
+ * repo, and with no `repoName`, the owner check reads the name the request named.
193
227
  */
194
228
  export type HostPolicyOptions = (
195
229
  | Pictures
196
230
  | { readonly origin?: undefined; readonly avatars?: undefined }
197
- ) & { readonly privateRepos?: PrivateRepos };
231
+ ) & { readonly privateRepos?: PrivateRepos; readonly repoName?: RepoNameOf };
198
232
 
199
233
  /**
200
234
  * What of `owner`'s repos `token` covers: every one, those under the token's longer prefix, its
@@ -217,7 +251,12 @@ const coverOf = (owner: string, token: GitHubReadableReposInput['token']) => {
217
251
  * directory of people and orgs, by Better Auth's tables, with what `options` adds.
218
252
  */
219
253
  export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPolicy => {
220
- const { origin, avatars, privateRepos = async () => ({ names: [], more: false }) } = options;
254
+ const {
255
+ origin,
256
+ avatars,
257
+ privateRepos = async () => ({ names: [], more: false }),
258
+ repoName,
259
+ } = options;
221
260
 
222
261
  /**
223
262
  * The `avatar_url` of `login`, held by `account`, when it has an upload: the app's route, by its
@@ -233,9 +272,11 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
233
272
  };
234
273
 
235
274
  /** An org as `defaultOrg` makes it, with its upload's `avatar_url` when it has one. */
236
- const orgOf = async (login: string): Promise<GitHubOrg> => ({
237
- ...(await defaultOrg(login)),
238
- ...(await pictureOf(login, await orgs.account(login))),
275
+ const orgOf = Effect.fnUntraced(function* (login: string) {
276
+ const org = yield* defaultOrg(login);
277
+ const picture = yield* read(async () => pictureOf(login, await orgs.account(login)));
278
+
279
+ return { ...org, ...picture } satisfies GitHubOrg;
239
280
  });
240
281
 
241
282
  /**
@@ -290,13 +331,32 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
290
331
  owner === actor.id || (owner !== undefined && (await belongs(actor, owner)));
291
332
 
292
333
  /**
293
- * Git's `authorize`: public repos for anyone to read and list, the rest for a repo's owner, once
294
- * the caller's token still holds.
334
+ * The owner now of the repo a drop-in operation on `name` acts on: its current name's, read by
335
+ * `repoName` from the repo's internal ID, so a repo transferred since the request named it is
336
+ * its new owner's, and none once no name holds it or the input names no repo. With no
337
+ * `repoName`, the owner of `name`.
338
+ */
339
+ const ownerNow = async (name: RepoName, input: GitHubAuthorization) => {
340
+ if (repoName === undefined) return ownerOf(name);
341
+
342
+ if (input.repo === undefined) return undefined;
343
+
344
+ const now = await repoName(input.repo.internalId, input.signal);
345
+
346
+ return now === undefined ? undefined : ownerOf(now);
347
+ };
348
+
349
+ /**
350
+ * Git's `authorize`: public repos for anyone to read and list, who they are for anyone signed in,
351
+ * and the rest for a repo's owner, once the caller's token still holds.
295
352
  */
296
353
  const authorize: GitAuthorize = async (input: AuthorizeInput) => {
297
354
  const { actor, operation, repo } = input;
298
355
  if (!(await tokenHolds(input))) return tokenEnded;
299
356
 
357
+ // Who the caller is, at Git's `/me`: theirs, once their token holds.
358
+ if (operation.kind === 'me') return actor.anonymous === true ? signInFirst : accept();
359
+
300
360
  const reads = operation.kind === 'read' || operation.kind === 'fetch';
301
361
  if (reads && repo?.public === true) return accept();
302
362
 
@@ -402,20 +462,24 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
402
462
 
403
463
  /**
404
464
  * The drop-in's `authorize`: a public repo's reads for anyone, as Git's, and its contributions
405
- * for anyone signed in, but a hook's for its owner. An org's members, teams and hooks are its
465
+ * for anyone signed in, an issue's author's edit of it, and a comment's or a review comment's
466
+ * author's edit or delete of it, for them, but a hook's for its owner. A review's body is its
467
+ * author's alone, as on GitHub: not the owner's, nor the admin's unless they wrote it. An org's members, teams and hooks are its
406
468
  * own members' alone, as GitHub shows outsiders only public members and this host keeps none
407
469
  * public (#644). A person's own account, such as their notifications, is theirs once signed in.
408
470
  * Everything else is the owner's and the admin's. A token that no longer holds gets nothing, as
409
471
  * in Git's, its own account included.
410
472
  */
411
- const authorizeGitHub: GitHubAuthorize = async (input: GitHubAuthorization) => {
473
+ const authorizeGitHub: GitHubAuthorize = Effect.fnUntraced(function* (
474
+ input: GitHubAuthorization,
475
+ ) {
412
476
  const { actor, operation } = input;
413
- if (!(await tokenHolds(input))) return tokenEnded;
477
+ if (!(yield* read(() => tokenHolds(input)))) return tokenEnded;
414
478
 
415
479
  if ('org' in operation) {
416
480
  if (actor.anonymous === true) return signInFirst;
417
481
 
418
- return actor.id === admin.id || (await owns(actor, operation.org))
482
+ return actor.id === admin.id || (yield* read(() => owns(actor, operation.org)))
419
483
  ? accept()
420
484
  : reject({ message: "Only the org's members may do this" });
421
485
  }
@@ -432,12 +496,25 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
432
496
 
433
497
  if (actor.anonymous === true) return signInFirst;
434
498
 
499
+ // GitHub lets only a review's author edit its body, so no one else does here, the admin
500
+ // included: the drop-in asks it as the author only once its own read shows the caller wrote it.
501
+ if (operation.kind === 'review.edit') {
502
+ return operation.asAuthor === true
503
+ ? accept()
504
+ : reject({ message: "Only a review's author can edit its body" });
505
+ }
506
+
435
507
  if (actor.id === admin.id || (visible && contributions.has(operation.kind))) return accept();
436
508
 
437
- return (await owns(actor, ownerOf(operation.repo)))
509
+ // The drop-in asks an issue's edit, or a comment's or a review comment's edit or delete, as its
510
+ // author only once its own read shows the caller wrote it (Q857), so the caller's token
511
+ // holding the repo is all that's left to ask.
512
+ if (operation.asAuthor === true && authorsOwn.has(operation.kind)) return accept();
513
+
514
+ return (yield* read(async () => owns(actor, await ownerNow(operation.repo, input))))
438
515
  ? accept()
439
516
  : reject({ message: 'Only the owner may do this' });
440
- };
517
+ });
441
518
 
442
519
  /**
443
520
  * The owner index's hook: every private repo under `owner` for its owner, a person's own login
@@ -474,63 +551,68 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
474
551
 
475
552
  // A person by the name they go by, as GitHub names someone who set one: a merge the drop-in
476
553
  // makes for them is authored under it.
477
- const user = async (input: PeopleUser): Promise<GitHubUser | undefined> => {
478
- const person = await orgs.person(input.login);
554
+ const user = Effect.fnUntraced(function* (input: PeopleUser) {
555
+ const person = yield* read(() => orgs.person(input.login));
479
556
  if (person === undefined) return undefined;
480
557
 
481
- const found = await base(input);
558
+ const found = yield* base(input);
482
559
  if (found === undefined) return undefined;
483
560
 
484
- const picture = await pictureOf(input.login, { kind: 'user', id: person.id });
561
+ const picture = yield* read(() => pictureOf(input.login, { kind: 'user', id: person.id }));
485
562
 
486
- return { ...found, name: person.name, ...picture };
487
- };
563
+ return { ...found, name: person.name, ...picture } satisfies GitHubUser;
564
+ });
488
565
 
489
- const org = async (input: PeopleOrg): Promise<GitHubOrg | undefined> =>
490
- (await orgs.org(input.org)) ? orgOf(input.org) : undefined;
566
+ const org = Effect.fnUntraced(function* (input: PeopleOrg) {
567
+ return (yield* read(() => orgs.org(input.org))) ? yield* orgOf(input.org) : undefined;
568
+ });
491
569
 
492
- const members = async (input: PeopleMembers): Promise<Listed<GitHubUser>> => {
493
- if (input.filter !== 'all') return { items: [] };
570
+ const members = Effect.fnUntraced(function* (input: PeopleMembers) {
571
+ if (input.filter !== 'all') return { items: [] } satisfies Listed<GitHubUser>;
494
572
 
495
573
  const page = { after: input.page?.after, limit: input.page?.limit ?? listedEach };
496
- const listed = await orgs.members(input.org, { ...page, role: input.role });
497
- const found = await Promise.all(
498
- listed.logins.map(async (login) => user({ ...input, kind: 'user', login })),
574
+ const listed = yield* read(() => orgs.members(input.org, { ...page, role: input.role }));
575
+ const found = yield* Effect.forEach(
576
+ listed.logins,
577
+ (login) => user({ ...input, kind: 'user', login }),
578
+ { concurrency: 'unbounded' },
499
579
  );
500
580
  const items = found.filter((each) => each !== undefined);
501
581
 
502
- return listed.next === undefined ? { items } : { items, next: listed.next };
503
- };
582
+ return (
583
+ listed.next === undefined ? { items } : { items, next: listed.next }
584
+ ) satisfies Listed<GitHubUser>;
585
+ });
504
586
 
505
- const orgsOf = async (input: PeopleOrgs): Promise<Listed<GitHubOrg>> => {
506
- if (input.actor.anonymous === true) return { items: [] };
587
+ const orgsOf = Effect.fnUntraced(function* (input: PeopleOrgs) {
588
+ const { actor } = input;
589
+ if (actor.anonymous === true) return { items: [] } satisfies Listed<GitHubOrg>;
507
590
 
508
591
  const page = { after: input.page?.after, limit: input.page?.limit ?? listedEach };
509
- const listed = await orgs.orgsOf(input.actor.id, page);
510
- const items = await Promise.all(
511
- listed.logins.filter((login) => reaches(input, login)).map(orgOf),
592
+ const listed = yield* read(() => orgs.orgsOf(actor.id, page));
593
+ const items = yield* Effect.forEach(
594
+ listed.logins.filter((login) => reaches(input, login)),
595
+ orgOf,
596
+ { concurrency: 'unbounded' },
512
597
  );
513
598
 
514
- return listed.next === undefined ? { items } : { items, next: listed.next };
515
- };
599
+ return (
600
+ listed.next === undefined ? { items } : { items, next: listed.next }
601
+ ) satisfies Listed<GitHubOrg>;
602
+ });
516
603
 
517
- function lookup(input: PeopleViewer | PeopleUser): Promise<GitHubUser | undefined>;
518
- function lookup(input: PeopleOrg): Promise<GitHubOrg | undefined>;
519
- function lookup(input: PeopleOrgs): Promise<Listed<GitHubOrg>>;
520
- function lookup(input: PeopleMembers | PeopleTeamMembers): Promise<Listed<GitHubUser>>;
521
- function lookup(input: PeopleTeams): Promise<Listed<GitHubTeam>>;
522
- function lookup(input: PeopleMembership): Promise<readonly string[]>;
523
- function lookup(input: PeopleTeam): Promise<GitHubTeam | undefined>;
524
- function lookup(input: PeopleSearch): Promise<PeopleSearchAnswer>;
525
- async function lookup(input: PeopleInput): Promise<PeopleAnswer> {
526
- // A token whose person left the org it's over reads no one and lists nothing: `/user` 404s,
527
- // as every other use of it is refused.
528
- if (!(await tokenHolds(input))) return refusedLookup(input);
604
+ const search = Effect.fnUntraced(function* (input: PeopleSearch) {
605
+ // A range of each index, read to the limit: it never stops short of its own accord.
606
+ const found = yield* read(() => orgs.search(input.prefix, input.limit, input.type));
529
607
 
608
+ return { found, incomplete: false } satisfies PeopleSearchAnswer;
609
+ });
610
+
611
+ const answer = (input: PeopleInput): Effect.Effect<PeopleAnswer, GitError> => {
530
612
  switch (input.kind) {
531
613
  case 'viewer':
532
614
  return input.actor.anonymous === true
533
- ? undefined
615
+ ? Effect.succeed(undefined)
534
616
  : user({ ...input, kind: 'user', login: input.actor.id });
535
617
  case 'user':
536
618
  return user(input);
@@ -539,15 +621,11 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
539
621
  case 'orgs':
540
622
  return orgsOf(input);
541
623
  case 'search':
542
- // A range of each index, read to the limit: it never stops short of its own accord.
543
- return {
544
- found: await orgs.search(input.prefix, input.limit, input.type),
545
- incomplete: false,
546
- };
624
+ return search(input);
547
625
  case 'members':
548
626
  return members(input);
549
627
  case 'membership':
550
- return orgs.among(input.org, input.logins);
628
+ return read(() => orgs.among(input.org, input.logins));
551
629
  case 'team-members':
552
630
  return base(input);
553
631
  case 'teams':
@@ -555,9 +633,30 @@ export const hostPolicy = (orgs: Orgs, options: HostPolicyOptions = {}): HostPol
555
633
  case 'team':
556
634
  return base(input);
557
635
  }
636
+ };
637
+
638
+ function lookup(
639
+ input: PeopleViewer | PeopleUser,
640
+ ): Effect.Effect<GitHubUser | undefined, GitError>;
641
+ function lookup(input: PeopleOrg): Effect.Effect<GitHubOrg | undefined, GitError>;
642
+ function lookup(input: PeopleOrgs): Effect.Effect<Listed<GitHubOrg>, GitError>;
643
+ function lookup(
644
+ input: PeopleMembers | PeopleTeamMembers,
645
+ ): Effect.Effect<Listed<GitHubUser>, GitError>;
646
+ function lookup(input: PeopleTeams): Effect.Effect<Listed<GitHubTeam>, GitError>;
647
+ function lookup(input: PeopleMembership): Effect.Effect<readonly string[], GitError>;
648
+ function lookup(input: PeopleTeam): Effect.Effect<GitHubTeam | undefined, GitError>;
649
+ function lookup(input: PeopleSearch): Effect.Effect<PeopleSearchAnswer, GitError>;
650
+ function lookup(input: PeopleInput): Effect.Effect<PeopleAnswer, GitError> {
651
+ // A token whose person left the org it's over reads no one and lists nothing: `/user` 404s,
652
+ // as every other use of it is refused.
653
+ return Effect.flatMap(
654
+ read(() => tokenHolds(input)),
655
+ (holds) => (holds ? answer(input) : Effect.succeed(refusedLookup(input))),
656
+ );
558
657
  }
559
658
 
560
- return lookup;
659
+ return People.make(lookup);
561
660
  };
562
661
 
563
662
  return { authorize, authorizeGitHub, people, readableRepos };
@@ -575,12 +674,12 @@ export interface HostRule {
575
674
  */
576
675
  export const hostRules: readonly HostRule[] = [
577
676
  // `main` takes fast-forwards only, so no one, an owner included, force-pushes or deletes it (#193).
578
- { rule: refs.protect('refs/heads/main'), covers: ['refs/heads/main'] },
677
+ { rule: Rules.protect('refs/heads/main'), covers: ['refs/heads/main'] },
579
678
  // Every branch and tag refuses a push that adds or changes one of these files, which usually
580
679
  // hold secrets. `git push -o allow-files` asks `authorize` instead. Edit the list, or delete
581
680
  // the line.
582
681
  {
583
- rule: refs.files(['*', 'refs/tags/*'], {
682
+ rule: Rules.files(['**', 'refs/tags/**'], {
584
683
  refuse: [
585
684
  '.env',
586
685
  '.env.*',
@@ -591,7 +690,7 @@ export const hostRules: readonly HostRule[] = [
591
690
  '**/id_ed25519',
592
691
  ],
593
692
  }),
594
- covers: ['refs/heads/*', 'refs/tags/*'],
693
+ covers: ['refs/heads/**', 'refs/tags/**'],
595
694
  },
596
695
  ];
597
696
 
@@ -1,4 +1,4 @@
1
- import type { Actor, GitServer, RepoId } from '@ref0/git';
1
+ import type { Actor, GitServer, RepoName } from '@ref0/git';
2
2
 
3
3
  import { admin } from './policy.ts';
4
4
  import type { PrivateRepos } from './policy.ts';
@@ -40,7 +40,7 @@ export const privateReposOf =
40
40
  listed(host.list, admin),
41
41
  listed(git.repos.list, { anonymous: true }),
42
42
  ]);
43
- const open = new Set<RepoId>(shown.names);
43
+ const open = new Set<RepoName>(shown.names);
44
44
  const hidden = all.names.filter((name) => !open.has(name));
45
45
 
46
46
  return { names: hidden, more: !all.whole || !shown.whole };
@@ -3,6 +3,7 @@ import { useNavigate } from '@tanstack/react-router';
3
3
  import { ArrowLeftIcon, GitCompareArrowsIcon, GitPullRequestIcon } from 'lucide-react';
4
4
  import { useState } from 'react';
5
5
 
6
+ import { useClients } from '../clients/clients.ts';
6
7
  import { Go } from '../code/controls.tsx';
7
8
  import { repoHref, type RepoPlace } from '../code/places.ts';
8
9
  import { RefSwitcher } from '../code/ref-switcher.tsx';
@@ -93,6 +94,7 @@ function OpenForm({
93
94
  readonly basehead: Basehead;
94
95
  readonly comparison: Comparison;
95
96
  }) {
97
+ const clients = useClients();
96
98
  const client = useQueryClient();
97
99
  const navigate = useNavigate();
98
100
  // One commit's message is the pull request's, as GitHub's form starts it; more name the branch.
@@ -103,7 +105,7 @@ function OpenForm({
103
105
  );
104
106
  const opened = useMutation({
105
107
  mutationFn: (draft: boolean) =>
106
- openPull(place, { ...basehead, title: title.trim(), body, draft }),
108
+ openPull(clients, place, { ...basehead, title: title.trim(), body, draft }),
107
109
  onSuccess: async (number) => {
108
110
  await client.invalidateQueries({ queryKey: ['pulls', place.owner, place.repo] });
109
111
  await navigate({ href: pullHref(place, number) });
@@ -184,8 +186,9 @@ function NothingToCompare({ children }: { readonly children: React.ReactNode })
184
186
 
185
187
  /** What `basehead`'s comparison shows: the open form or its open pull request, its commits and its diff. */
186
188
  function Compared({ place, basehead }: { readonly place: RepoPlace; readonly basehead: Basehead }) {
187
- const comparison = useQuery(comparisonOf(place, basehead));
188
- const open = useQuery(openPullOf(place, basehead));
189
+ const clients = useClients();
190
+ const comparison = useQuery(comparisonOf(clients, place, basehead));
191
+ const open = useQuery(openPullOf(clients, place, basehead));
189
192
  const allowed = useAllowed(place);
190
193
  const { base, head } = basehead;
191
194