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,8 +1,14 @@
1
+ import { init } from '@pierre/words';
1
2
  import { createHtmlRenderer, escapeHtml, type MermaidPlugin } from '@pierre/words/html';
2
3
  import * as pele from 'pele';
4
+ import wordsModule from 'virtual:words-module';
5
+
6
+ import { budgetOf, htmlAsWritten, htmlMost, htmlWithinLimits } from '@ref0/github/markdown';
3
7
 
4
8
  import {
5
9
  fragmentTargets,
10
+ hasFound,
11
+ linkPrefixOf,
6
12
  linkerOf,
7
13
  recorder,
8
14
  type Found,
@@ -58,46 +64,117 @@ const fragments = (html: string) => {
58
64
  );
59
65
  };
60
66
 
67
+ /** What words starts each id the text gives with, so none meets the app's own. */
68
+ const idPrefix = 'user-content-';
69
+
70
+ /**
71
+ * Words' renderer, from its module under the drop-in's most on its memory (#1098). A call that
72
+ * would grow that memory past the most traps, and the next text starts on a fresh renderer, whose
73
+ * memory is back to its first size: words' memory never shrinks, so the trapped one is let go.
74
+ * Rendering is synchronous, hooks and all, so no other text is mid-render when it's swapped.
75
+ */
76
+ let words = init(wordsModule);
77
+
78
+ /** The bytes words' renderer holds now, which a trap's fresh renderer returns to its first size. */
79
+ export const wordsMemory = () => words.memory.buffer.byteLength;
80
+
61
81
  /**
62
82
  * Words, with `patches`: every patch, for the app, or all but one, for a test showing words still
63
- * needs it. `draw` off leaves diagrams as code, for a pass that only reads references.
83
+ * needs it. `draw` off leaves diagrams as code, for a pass that only reads references. It renders
84
+ * a whole text in one call, with a renderer of its own, since a renderer renders a later text as
85
+ * an edit of its last, and a Mermaid plugin of its own, so no two of a text's diagrams' ids meet.
64
86
  */
87
+ const wordsFor = (context: MarkdownContext, patches: readonly Patch[], draw: boolean) => {
88
+ const { allowedHtml, components, urlTransform, after } = compose(context, patches);
89
+
90
+ return (text: string) => {
91
+ const renderer = createHtmlRenderer({
92
+ math: true,
93
+ allowedHtml,
94
+ components,
95
+ plugins: draw ? { mermaid: mermaid() } : {},
96
+ controls: false,
97
+ lineNumbers: false,
98
+ urlTransform,
99
+ idPrefix,
100
+ });
101
+
102
+ try {
103
+ return after(renderer.render(text, false).html);
104
+ } catch (error) {
105
+ if (error instanceof WebAssembly.RuntimeError) words = init(wordsModule);
106
+
107
+ throw error;
108
+ } finally {
109
+ renderer.dispose();
110
+ }
111
+ };
112
+ };
113
+
114
+ /** `text` through words in one call, with no bound: for a test of what words writes. */
65
115
  export const rendered = (
66
116
  text: string,
67
117
  context: MarkdownContext,
68
118
  patches: readonly Patch[],
69
119
  draw: boolean,
70
- ) => {
71
- const { allowedHtml, components, urlTransform } = compose(context, patches);
72
- const renderer = createHtmlRenderer({
73
- math: true,
74
- allowedHtml,
75
- components,
76
- plugins: draw ? { mermaid: mermaid() } : {},
77
- controls: false,
78
- lineNumbers: false,
79
- urlTransform,
80
- idPrefix: 'user-content-',
120
+ ) => wordsFor(context, patches, draw)(text);
121
+
122
+ /**
123
+ * `text` through words within the drop-in's limits on its HTML (#1098): at most 16 characters a
124
+ * character, and `most`, in one call under words' most on its memory, or as written past them.
125
+ */
126
+ const bounded = (
127
+ text: string,
128
+ context: MarkdownContext,
129
+ patches: readonly Patch[],
130
+ draw: boolean,
131
+ most = htmlMost,
132
+ ) =>
133
+ htmlWithinLimits(text, wordsFor(context, patches, draw), {
134
+ most,
135
+ linkPrefix: linkPrefixOf(context),
81
136
  });
82
137
 
83
- try {
84
- return renderer.render(text, false).html;
85
- } finally {
86
- renderer.dispose();
87
- }
88
- };
138
+ /** The line above a text past its limits, which shows below it as written. */
139
+ export const tooLarge =
140
+ '<p class="markdown-too-large">This text is too large to render, so it\'s shown as written.</p>\n';
89
141
 
90
142
  /**
91
143
  * `text` as sanitized HTML, the same in a preview and on the server: its references linked only
92
- * where `found` says they exist.
144
+ * where `found` says they exist, and, past its limits, as written under a line saying so. `most`
145
+ * is the most HTML it may write, such as what's left of its page's.
93
146
  */
94
- export const renderMarkdown = (text: string, context: MarkdownContext, found: Found): string =>
95
- fragments(rendered(text, context, Object.values(patchesFor(context, linkerOf(found))), true));
147
+ export const renderMarkdown = (
148
+ text: string,
149
+ context: MarkdownContext,
150
+ found: Found,
151
+ most = htmlMost,
152
+ ): string => {
153
+ const all = patchesFor(context, linkerOf(found));
154
+ const patches = hasFound(found)
155
+ ? Object.values(all)
156
+ : Object.entries(all).flatMap(([name, patch]) => (name === 'references' ? [] : [patch]));
157
+ const { html, rendered } = bounded(text, context, patches, true, most);
158
+ if (!rendered) return `${tooLarge}${html}`;
159
+
160
+ // Fragment links resolve after the bound, and may lengthen it: the text's budget holds them too.
161
+ const shown = fragments(html);
162
+
163
+ return shown.length <= budgetOf(text, most) ? shown : `${tooLarge}${htmlAsWritten(text)}`;
164
+ };
96
165
 
97
- /** The issues, pulls, people and commits `text` names in `context`, for a lookup before rendering. */
166
+ /**
167
+ * The issues, pulls, people and commits `text` names in `context`, for a lookup before rendering:
168
+ * none for a text past the bound, which shows as written.
169
+ */
98
170
  export const referencesIn = (text: string, context: MarkdownContext): References => {
99
171
  const { linker, references } = recorder();
100
- rendered(text, context, Object.values(patchesFor(context, linker)), false);
172
+ const { rendered: whole } = bounded(
173
+ text,
174
+ context,
175
+ Object.values(patchesFor(context, linker)),
176
+ false,
177
+ );
101
178
 
102
- return references();
179
+ return whole ? references() : { issues: [], users: [], commits: [] };
103
180
  };
@@ -0,0 +1,43 @@
1
+ import * as Schema from 'effect/Schema';
2
+
3
+ /**
4
+ * A repo's name, as `owner/name` writes it: GitHub's names, one slash between them, neither `.` nor
5
+ * `..`, so the call it names can't climb out of the repo's route.
6
+ */
7
+ const RepoName = Schema.String.check(
8
+ Schema.isPattern(/^(?!\.\.?\/)[\w.-]{1,100}\/(?!\.\.?$)[\w.-]{1,100}$/),
9
+ );
10
+
11
+ /**
12
+ * A file's path in its repo: segments joined by `/`, none empty, `.` or `..`, a line break in a
13
+ * segment too, as `s` lets `.` read one.
14
+ */
15
+ const FilePath = Schema.String.check(
16
+ Schema.isMaxLength(4096),
17
+ Schema.isPattern(/^(?!(?:.*\/)?\.\.?(?:\/|$))[^/]+(?:\/[^/]+)*$/s),
18
+ );
19
+
20
+ /** An issue's or a pull request's number, or a comment's, a review's or a release's ID. */
21
+ const Id = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER }));
22
+
23
+ /**
24
+ * Where a text the app draws is kept in the drop-in (Q860): an issue's or a pull request's own
25
+ * text, a comment on one, a review, a comment on a pull request's lines, a release's notes, or a
26
+ * file at a ref. The image proxy's signer reads the text from there as the viewer, and signs only
27
+ * the remote images it holds.
28
+ */
29
+ export const TextAddress = Schema.Union([
30
+ Schema.Struct({ kind: Schema.Literal('issue'), repo: RepoName, number: Id }),
31
+ Schema.Struct({ kind: Schema.Literal('issue-comment'), repo: RepoName, id: Id }),
32
+ Schema.Struct({ kind: Schema.Literal('review'), repo: RepoName, number: Id, id: Id }),
33
+ Schema.Struct({ kind: Schema.Literal('review-comment'), repo: RepoName, id: Id }),
34
+ Schema.Struct({ kind: Schema.Literal('release'), repo: RepoName, id: Id }),
35
+ Schema.Struct({
36
+ kind: Schema.Literal('file'),
37
+ repo: RepoName,
38
+ ref: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(1024)),
39
+ path: FilePath,
40
+ }),
41
+ ]);
42
+
43
+ export type TextAddress = typeof TextAddress.Type;
@@ -0,0 +1,5 @@
1
+ /** Words' WebAssembly module with its memory's most, which `words-plugin.ts` gives (#1098). */
2
+ declare module 'virtual:words-module' {
3
+ const module: WebAssembly.Module;
4
+ export default module;
5
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Words under the drop-in's limit on its memory (#1098, Q868): a Vite plugin that gives the app
3
+ * `virtual:words-module`, words' WebAssembly module with its memory's most set to
4
+ * `wordsMemoryPagesMost`. Words writes a text's whole HTML into that memory before any hook can stop
5
+ * it, and the memory never shrinks, so the app renders through this module, and starts a fresh
6
+ * renderer from it after a call traps at the most.
7
+ *
8
+ * On workerd, which compiles no WebAssembly at run time, the module is a file written once under
9
+ * Vite's cache, and words' own `./words.wasm` import reads it too, so words starts under the most.
10
+ * Elsewhere, in a browser or Node, the module is compiled at load from words' own bytes, edited.
11
+ */
12
+ import { createHash, randomUUID } from 'node:crypto';
13
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
14
+ import { createRequire } from 'node:module';
15
+ import { dirname, isAbsolute, join } from 'node:path';
16
+
17
+ import type { Plugin } from 'vite-plus';
18
+
19
+ import { withMemoryMax, wordsMemoryPagesMost } from '@ref0/github/markdown';
20
+
21
+ /** The module the app imports for words' WebAssembly, under the most. */
22
+ export const wordsModuleId = 'virtual:words-module';
23
+
24
+ /**
25
+ * The module's id once resolved, holding where words and the drop-in's Markdown entry are, so a
26
+ * load needs nothing from its resolve: Vitest resolves an id it has met before as it is.
27
+ */
28
+ const resolvedPrefix = `\0${wordsModuleId}?`;
29
+
30
+ /** Words' own import of its module, from its workerd entry. */
31
+ const wordsImporter = /[\\/]@pierre[\\/]words[\\/]dist[\\/]workerd\.js$/;
32
+
33
+ /** A path as Vite may give it, without a query. */
34
+ const pathOf = (id: string) => id.replace(/[?#].*$/, '');
35
+
36
+ /**
37
+ * Words' entry as a file. A Node server build keeps words external, and resolves it to its bare
38
+ * name, which has no folder: the file is then where Node finds it from the importer.
39
+ */
40
+ const wordsEntryFile = (resolved: string, importer: string) =>
41
+ isAbsolute(resolved) ? resolved : createRequire(importer).resolve('@pierre/words');
42
+
43
+ export const wordsMemoryMax = (pages = wordsMemoryPagesMost): Plugin => {
44
+ let cacheDir = '';
45
+ let root = '';
46
+ const written = new Map<string, string>();
47
+
48
+ /**
49
+ * `dist`'s `words.wasm` with its most, under Vite's cache: its path. A file there is kept only
50
+ * when it holds these bytes, since a run killed mid-write leaves an empty or short one, which
51
+ * workerd fails to compile. A write goes to a file of its own beside it and is renamed into place,
52
+ * so no reader, in this build or another at once, sees it part-written.
53
+ */
54
+ const withMost = (dist: string) => {
55
+ const known = written.get(dist);
56
+ if (known !== undefined) return known;
57
+
58
+ const bytes = withMemoryMax(readFileSync(join(dist, 'words.wasm')), pages);
59
+ const hash = createHash('sha256').update(bytes).digest('hex').slice(0, 16);
60
+ const file = join(cacheDir, 'ref0-words', `words-${hash}.wasm`);
61
+
62
+ if (!existsSync(file) || !Buffer.from(bytes).equals(readFileSync(file))) {
63
+ mkdirSync(dirname(file), { recursive: true });
64
+ const staged = `${file}.${process.pid}-${randomUUID()}.tmp`;
65
+ writeFileSync(staged, bytes);
66
+ renameSync(staged, file);
67
+ }
68
+
69
+ written.set(dist, file);
70
+
71
+ return file;
72
+ };
73
+
74
+ return {
75
+ name: 'ref0-words-memory-max',
76
+ enforce: 'pre',
77
+ // The dev server's optimizer would bundle words into its cache, where no `words.wasm` sits
78
+ // beside it and this plugin no longer knows its import (#1334): words stays as installed.
79
+ configEnvironment: () => ({ optimizeDeps: { exclude: ['@pierre/words'] } }),
80
+ configResolved: (config) => {
81
+ cacheDir = config.cacheDir;
82
+ root = config.root;
83
+ },
84
+ async resolveId(source, importer, options) {
85
+ if (source.startsWith(resolvedPrefix)) return source;
86
+
87
+ if (source === wordsModuleId) {
88
+ const entry = await this.resolve('@pierre/words', importer, { ...options, skipSelf: true });
89
+ const markdown = await this.resolve('@ref0/github/markdown', importer, {
90
+ ...options,
91
+ skipSelf: true,
92
+ });
93
+ if (entry === null || markdown === null)
94
+ throw new Error(
95
+ `${wordsModuleId} needs @pierre/words and @ref0/github beside its importer`,
96
+ );
97
+
98
+ const where = new URLSearchParams({
99
+ dist: dirname(wordsEntryFile(pathOf(entry.id), importer ?? join(root, 'vite.config.ts'))),
100
+ markdown: pathOf(markdown.id),
101
+ });
102
+
103
+ return `${resolvedPrefix}${where.toString()}`;
104
+ }
105
+
106
+ if (
107
+ source === './words.wasm' &&
108
+ importer !== undefined &&
109
+ wordsImporter.test(pathOf(importer))
110
+ )
111
+ return withMost(dirname(pathOf(importer)));
112
+
113
+ return null;
114
+ },
115
+ load(id) {
116
+ if (!id.startsWith(resolvedPrefix)) return null;
117
+
118
+ // Words' `dist` folder and the drop-in's Markdown entry, as the app resolved them.
119
+ const where = new URLSearchParams(id.slice(resolvedPrefix.length));
120
+ const dist = where.get('dist');
121
+ const markdown = where.get('markdown');
122
+ if (dist === null || markdown === null) throw new Error(`${id} names no words to load`);
123
+
124
+ if (this.environment.config.resolve.conditions.includes('workerd'))
125
+ return `import module from ${JSON.stringify(withMost(dist))};\nexport default module;\n`;
126
+
127
+ return [
128
+ `import bytes from ${JSON.stringify(join(dist, 'words.wasm.mjs'))};`,
129
+ `import { withMemoryMax } from ${JSON.stringify(markdown)};`,
130
+ `export default new WebAssembly.Module(withMemoryMax(bytes, ${pages}));`,
131
+ '',
132
+ ].join('\n');
133
+ },
134
+ };
135
+ };
@@ -7,7 +7,7 @@ export const reservedRepos: ReadonlySet<string> = new Set(['login', 'new', 'sett
7
7
  /**
8
8
  * Why `name` can't name a repository, or `undefined` when it can. The drop-in turns each character
9
9
  * outside these into `-`, and refuses a name starting with `.` or `-` or ending in `.git` or
10
- * `.lock`, as Git's repo IDs do; the form says so before it sends one.
10
+ * `.lock`, as Git's repo names do; the form says so before it sends one.
11
11
  */
12
12
  export const repoProblem = (name: string): string | undefined => {
13
13
  if (name === '') return 'Name the repository';
@@ -15,6 +15,7 @@ import {
15
15
  import { type KeyboardEvent, type ReactNode, useEffect, useRef, useState } from 'react';
16
16
  import { toast } from 'sonner';
17
17
 
18
+ import { useClients } from '../clients/clients.ts';
18
19
  import { copyText } from '../code/controls.tsx';
19
20
  import { commitHref } from '../code/places.ts';
20
21
  import { hotkeys, Keys, onMac } from '../components/hotkeys/hotkeys.tsx';
@@ -209,6 +210,7 @@ function PaletteBody({
209
210
  readonly shown: boolean;
210
211
  readonly close: () => void;
211
212
  }) {
213
+ const clients = useClients();
212
214
  const router = useRouter();
213
215
  const [typed, setTyped] = useState<Typed>({ symbol: undefined, text: '' });
214
216
  const commands = useCommands(at);
@@ -281,7 +283,7 @@ function PaletteBody({
281
283
  const lookup = new AbortController();
282
284
  jump.current = lookup;
283
285
 
284
- const sha = await githubLookups
286
+ const sha = await githubLookups(clients)
285
287
  .commit({ repo: `${commit.owner}/${commit.repo}`, sha: commit.sha }, lookup.signal)
286
288
  .catch(() => null);
287
289
  if (lookup.signal.aborted || !open.current) return;
@@ -510,6 +512,7 @@ export interface PaletteParts {
510
512
  * lists it finds are read ahead once the page is idle.
511
513
  */
512
514
  export const usePalette = (at: PaletteAt | undefined, path: string): PaletteParts | undefined => {
515
+ const clients = useClients();
513
516
  const client = useQueryClient();
514
517
  const [open, setOpen] = useState(false);
515
518
  const owner = at?.here.owner;
@@ -526,7 +529,7 @@ export const usePalette = (at: PaletteAt | undefined, path: string): PalettePart
526
529
  useEffect(() => {
527
530
  if (at === undefined) return;
528
531
 
529
- const readAhead = () => prefetchLists(client, at);
532
+ const readAhead = () => prefetchLists(clients, client, at);
530
533
 
531
534
  if ('requestIdleCallback' in window) {
532
535
  const idle = requestIdleCallback(readAhead, { timeout: 2_000 });
@@ -537,11 +540,11 @@ export const usePalette = (at: PaletteAt | undefined, path: string): PalettePart
537
540
  const next = setTimeout(readAhead, 0);
538
541
 
539
542
  return () => clearTimeout(next);
540
- }, [client, at === undefined, owner, repo]);
543
+ }, [clients, client, at === undefined, owner, repo]);
541
544
 
542
545
  if (at === undefined) return undefined;
543
546
 
544
- const readAhead = () => prefetchLists(client, at);
547
+ const readAhead = () => prefetchLists(clients, client, at);
545
548
  const show = () => setOpen(true);
546
549
 
547
550
  return {
@@ -22,6 +22,7 @@ import { allFiles } from '../code/trees.ts';
22
22
  import { switcherList } from '../components/shell/owner-repos.tsx';
23
23
  import { sectionIcon } from '../components/shell/sections.ts';
24
24
  import type { PageOperation } from '../clients/allowed.ts';
25
+ import { type Clients, useClients } from '../clients/clients.ts';
25
26
  import { allowedHere } from '../hooks/allowed.ts';
26
27
  import { type Owner, repoList } from '../hooks/repos.ts';
27
28
  import { settingsOpen } from '../settings/settings-layout.tsx';
@@ -105,15 +106,18 @@ const refKinds: readonly Kind[] = ['branches', 'tags'];
105
106
  * Reads ahead what the palette lists with no mode, from the switchers' own reads under their own
106
107
  * keys: each owner's repos and, in a repo, its branches and tags. A read still fresh reads nothing.
107
108
  */
108
- export const prefetchLists = (client: QueryClient, at: PaletteAt) => {
109
+ export const prefetchLists = (clients: Clients, client: QueryClient, at: PaletteAt) => {
109
110
  for (const owner of ownersOf(at)) {
110
- void client.prefetchInfiniteQuery({ ...repoList(owner, switcherList), staleTime: 30_000 });
111
+ void client.prefetchInfiniteQuery({
112
+ ...repoList(clients, owner, switcherList),
113
+ staleTime: 30_000,
114
+ });
111
115
  }
112
116
 
113
117
  const place = placeOf(at.here);
114
118
  if (place === undefined) return;
115
119
 
116
- for (const kind of refKinds) void client.prefetchInfiniteQuery(refNameList(place, kind));
120
+ for (const kind of refKinds) void client.prefetchInfiniteQuery(refNameList(clients, place, kind));
117
121
  };
118
122
 
119
123
  /** Draws again whenever a read lands in the cache, so lists read ahead show once they arrive. */
@@ -172,11 +176,16 @@ const noOperations: ReadonlySet<PageOperation> = new Set();
172
176
  * What the viewer may do on the page's repo, as its route read it ahead: the palette reads nothing
173
177
  * of its own, so before that answer lands, and off a repo, it offers no gated row.
174
178
  */
175
- export const useAllowedAt = (here: Here): ReadonlySet<PageOperation> =>
176
- useQuery({
177
- ...allowedHere({ owner: here.owner ?? '', repo: here.repo ?? '' }),
178
- enabled: false,
179
- }).data ?? noOperations;
179
+ export const useAllowedAt = (here: Here): ReadonlySet<PageOperation> => {
180
+ const clients = useClients();
181
+
182
+ return (
183
+ useQuery({
184
+ ...allowedHere(clients, { owner: here.owner ?? '', repo: here.repo ?? '' }),
185
+ enabled: false,
186
+ }).data ?? noOperations
187
+ );
188
+ };
180
189
 
181
190
  /** Whether `page` is one of the repo's settings, which open only as the sidebar's Settings does. */
182
191
  const repoSettings = (page: Target, here: Here) =>
@@ -187,6 +196,7 @@ const repoSettings = (page: Target, here: Here) =>
187
196
 
188
197
  /** The rows with no mode: what a pasted value names, then recent places, pages, repos, orgs and refs. */
189
198
  const useFound = (at: PaletteAt, text: string): readonly Group[] => {
199
+ const clients = useClients();
190
200
  const client = useCacheLanded();
191
201
  const place = placeOf(at.here);
192
202
  const owners = ownersOf(at);
@@ -217,21 +227,22 @@ const useFound = (at: PaletteAt, text: string): readonly Group[] => {
217
227
  (a, b) => Number(b.login === at.here.owner) - Number(a.login === at.here.owner),
218
228
  );
219
229
  const repos = ordered.flatMap((owner) =>
220
- (client.getQueryData(repoList(owner, switcherList).queryKey)?.pages ?? []).flatMap((page) =>
221
- page.repos.map((repo): Row => ({
222
- id: `repo:${owner.login}/${repo.name}`,
223
- label: `${owner.login}/${repo.name}`,
224
- icon: BookMarkedIcon,
225
- act: {
226
- kind: 'go',
227
- href: `/${segment(owner.login)}/${segment(repo.name)}`,
228
- keep: {
229
- kind: 'repo',
230
- label: `${owner.login}/${repo.name}`,
230
+ (client.getQueryData(repoList(clients, owner, switcherList).queryKey)?.pages ?? []).flatMap(
231
+ (page) =>
232
+ page.repos.map((repo): Row => ({
233
+ id: `repo:${owner.login}/${repo.name}`,
234
+ label: `${owner.login}/${repo.name}`,
235
+ icon: BookMarkedIcon,
236
+ act: {
237
+ kind: 'go',
231
238
  href: `/${segment(owner.login)}/${segment(repo.name)}`,
239
+ keep: {
240
+ kind: 'repo',
241
+ label: `${owner.login}/${repo.name}`,
242
+ href: `/${segment(owner.login)}/${segment(repo.name)}`,
243
+ },
232
244
  },
233
- },
234
- })),
245
+ })),
235
246
  ),
236
247
  );
237
248
  const orgs = owners.map((owner): Row => ({
@@ -244,14 +255,15 @@ const useFound = (at: PaletteAt, text: string): readonly Group[] => {
244
255
  const refs = (kind: Kind): readonly Row[] =>
245
256
  place === undefined
246
257
  ? []
247
- : (client.getQueryData(refNameList(place, kind).queryKey)?.pages ?? []).flatMap((page) =>
248
- page.names.map((name): Row => ({
249
- id: `${kind}:${name}`,
250
- label: name,
251
- note: kind === 'branches' ? 'Branch' : 'Tag',
252
- icon: kind === 'branches' ? GitBranchIcon : TagIcon,
253
- act: { kind: 'go', href: treeHref(place, name, '') },
254
- })),
258
+ : (client.getQueryData(refNameList(clients, place, kind).queryKey)?.pages ?? []).flatMap(
259
+ (page) =>
260
+ page.names.map((name): Row => ({
261
+ id: `${kind}:${name}`,
262
+ label: name,
263
+ note: kind === 'branches' ? 'Branch' : 'Tag',
264
+ icon: kind === 'branches' ? GitBranchIcon : TagIcon,
265
+ act: { kind: 'go', href: treeHref(place, name, '') },
266
+ })),
255
267
  );
256
268
  const jump = jumpOf(text, at.here, window.location.origin);
257
269
 
@@ -268,8 +280,9 @@ const useFound = (at: PaletteAt, text: string): readonly Group[] => {
268
280
 
269
281
  /** `@`: the viewer's own owners, then their orgs' members, read once typing stops. */
270
282
  const usePeople = (at: PaletteAt, text: string, asking: boolean): readonly Group[] => {
283
+ const clients = useClients();
271
284
  const members = useQueries({
272
- queries: at.orgs.map((org) => ({ ...orgMembers(org), enabled: asking })),
285
+ queries: at.orgs.map((org) => ({ ...orgMembers(clients, org), enabled: asking })),
273
286
  });
274
287
  const owners = ownersOf(at).map((owner): Row => ({
275
288
  id: `owner:${owner.login}`,
@@ -319,9 +332,13 @@ const useIssues = (
319
332
  settled: string,
320
333
  asking: boolean,
321
334
  ): readonly Group[] => {
335
+ const clients = useClients();
322
336
  const wanted = issueQueryOf(settled, at.here);
323
337
  const typing = issueQueryOf(text, at.here);
324
- const found = useQuery({ ...issueSearch(wanted ?? ''), enabled: asking && wanted !== undefined });
338
+ const found = useQuery({
339
+ ...issueSearch(clients, wanted ?? ''),
340
+ enabled: asking && wanted !== undefined,
341
+ });
325
342
  const number = numberJump(text, at.here);
326
343
 
327
344
  const rows = (found.data?.items ?? []).map((item): Row => {
@@ -379,16 +396,20 @@ const useIssues = (
379
396
  * retries.
380
397
  */
381
398
  const useFiles = (at: PaletteAt, text: string, asking: boolean): readonly Group[] => {
399
+ const clients = useClients();
382
400
  const place = placeOf(at.here);
383
401
  const branch = at.here.defaultBranch;
384
402
  const head = useQuery({
385
- ...headCommit(place ?? { owner: '', repo: '' }, { kind: 'branch', name: branch ?? '' }),
403
+ ...headCommit(clients, place ?? { owner: '', repo: '' }, {
404
+ kind: 'branch',
405
+ name: branch ?? '',
406
+ }),
386
407
  enabled: asking && place !== undefined && branch !== undefined,
387
408
  retry: false,
388
409
  });
389
410
  const tree = head.data?.tree;
390
411
  const files = useQuery({
391
- ...allFiles(place ?? { owner: '', repo: '' }, tree ?? ''),
412
+ ...allFiles(clients, place ?? { owner: '', repo: '' }, tree ?? ''),
392
413
  enabled: asking && place !== undefined && tree !== undefined,
393
414
  retry: false,
394
415
  });
@@ -1,7 +1,7 @@
1
1
  import { queryOptions } from '@tanstack/react-query';
2
2
  import { useEffect, useState } from 'react';
3
3
 
4
- import { github } from '../clients/clients.ts';
4
+ import type { Clients } from '../clients/clients.ts';
5
5
 
6
6
  /**
7
7
  * What the palette asks the drop-in for, once typing stops: one request a mode, each with its
@@ -45,11 +45,11 @@ const repoOfUrl = (url: string) => {
45
45
  };
46
46
 
47
47
  /** The issues and pull requests `GET /search/issues` finds for `q`, at most `resultsMost`. */
48
- export const issueSearch = (q: string) =>
48
+ export const issueSearch = (clients: Clients, q: string) =>
49
49
  queryOptions({
50
50
  queryKey: [...paletteReads, 'issues', q],
51
51
  queryFn: async ({ signal }): Promise<Found<FoundIssue>> => {
52
- const answer = await github.GET('/search/issues', {
52
+ const answer = await clients.github.GET('/search/issues', {
53
53
  params: { query: { q, per_page: resultsMost } },
54
54
  signal,
55
55
  });
@@ -76,11 +76,11 @@ export const issueSearch = (q: string) =>
76
76
  * The logins of `org`'s members, its first 100, which `@` matches in the browser until the
77
77
  * drop-in serves `GET /search/users` (Q778).
78
78
  */
79
- export const orgMembers = (org: string) =>
79
+ export const orgMembers = (clients: Clients, org: string) =>
80
80
  queryOptions({
81
81
  queryKey: [...paletteReads, 'members', org],
82
82
  queryFn: async ({ signal }): Promise<readonly string[]> => {
83
- const answer = await github.GET('/orgs/{org}/members', {
83
+ const answer = await clients.github.GET('/orgs/{org}/members', {
84
84
  params: { path: { org }, query: { per_page: 100 } },
85
85
  signal,
86
86
  });
@@ -106,6 +106,7 @@ const repoPages = (owner: string, repo: string, defaultBranch: string | undefine
106
106
  ['Tags', '/tags'],
107
107
  ['Releases', '/releases', 'releases'],
108
108
  ['Labels', '/labels'],
109
+ ['Milestones', '/milestones'],
109
110
  ...(defaultBranch === undefined
110
111
  ? []
111
112
  : ([['Commits', `/commits/${segment(defaultBranch)}`]] as const)),