@peaske7/readit 0.1.8 → 0.2.1

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 (221) hide show
  1. package/.claude/CLAUDE.md +118 -76
  2. package/.claude/commands/review.md +1 -1
  3. package/.claude/roadmap.md +32 -9
  4. package/.claude/user-stories.md +100 -15
  5. package/AGENTS.md +30 -26
  6. package/Makefile +32 -0
  7. package/README.md +90 -5
  8. package/biome.json +18 -8
  9. package/bun.lock +426 -710
  10. package/bunfig.toml +2 -0
  11. package/docs/perf-baseline.md +130 -0
  12. package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
  13. package/docs/superpowers/specs/2026-03-27-go-server-rewrite-design.md +284 -0
  14. package/e2e/comments.spec.ts +14 -58
  15. package/e2e/document-load.spec.ts +1 -23
  16. package/e2e/export.spec.ts +4 -4
  17. package/e2e/perf/add-comment.spec.ts +116 -0
  18. package/e2e/perf/fixtures/generate.ts +327 -0
  19. package/e2e/perf/initial-load.spec.ts +49 -0
  20. package/e2e/perf/perf.setup.ts +23 -0
  21. package/e2e/perf/perf.teardown.ts +9 -0
  22. package/e2e/perf/screenshot-final.png +0 -0
  23. package/e2e/perf/scroll.spec.ts +39 -0
  24. package/e2e/perf/tab-switch.spec.ts +69 -0
  25. package/e2e/perf/text-selection.spec.ts +119 -0
  26. package/e2e/perf/utils/metrics.ts +350 -0
  27. package/e2e/perf/utils/perf-cli.ts +86 -0
  28. package/e2e/persistence-file.spec.ts +41 -26
  29. package/e2e/utils/selection.ts +17 -73
  30. package/go/cmd/readit/main.go +416 -0
  31. package/go/go.mod +20 -0
  32. package/go/go.sum +41 -0
  33. package/go/internal/server/anchor.go +302 -0
  34. package/go/internal/server/anchor_test.go +111 -0
  35. package/go/internal/server/comments.go +390 -0
  36. package/go/internal/server/documents.go +113 -0
  37. package/go/internal/server/embed.go +17 -0
  38. package/go/internal/server/headings.go +33 -0
  39. package/go/internal/server/headings_test.go +75 -0
  40. package/go/internal/server/htmltext.go +123 -0
  41. package/go/internal/server/markdown.go +157 -0
  42. package/go/internal/server/markdown_bench_test.go +42 -0
  43. package/go/internal/server/markdown_test.go +79 -0
  44. package/go/internal/server/server.go +453 -0
  45. package/go/internal/server/server_bench_test.go +122 -0
  46. package/go/internal/server/settings.go +110 -0
  47. package/go/internal/server/sse.go +140 -0
  48. package/go/internal/server/storage.go +275 -0
  49. package/go/internal/server/storage_test.go +118 -0
  50. package/go/internal/server/template.go +66 -0
  51. package/go/internal/server/types.go +101 -0
  52. package/go/internal/server/watcher.go +74 -0
  53. package/index.html +4 -14
  54. package/nvim-readit/lua/readit/health.lua +64 -0
  55. package/nvim-readit/lua/readit/init.lua +463 -0
  56. package/nvim-readit/plugin/readit.lua +19 -0
  57. package/package.json +24 -41
  58. package/playwright.config.ts +12 -0
  59. package/shell/_readit +158 -0
  60. package/shell/readit.zsh +87 -0
  61. package/src/App.svelte +881 -0
  62. package/src/{cli/index.ts → cli.ts} +216 -70
  63. package/src/components/ActionsMenu.svelte +95 -0
  64. package/src/components/CommentBadge.svelte +67 -0
  65. package/src/components/CommentErrorBanner.svelte +33 -0
  66. package/src/components/CommentInput.svelte +75 -0
  67. package/src/components/CommentListItem.svelte +95 -0
  68. package/src/components/CommentManager.svelte +129 -0
  69. package/src/components/CommentNav.svelte +109 -0
  70. package/src/components/DocumentViewer.svelte +218 -0
  71. package/src/components/FloatingComment.svelte +107 -0
  72. package/src/components/Header.svelte +76 -0
  73. package/src/components/InlineEditor.svelte +72 -0
  74. package/src/components/MarginNote.svelte +167 -0
  75. package/src/components/MarginNotesContainer.svelte +33 -0
  76. package/src/components/RawModal.svelte +126 -0
  77. package/src/components/ReanchorConfirm.svelte +30 -0
  78. package/src/components/SettingsModal.svelte +220 -0
  79. package/src/components/ShortcutCapture.svelte +82 -0
  80. package/src/components/ShortcutList.svelte +145 -0
  81. package/src/components/TabBar.svelte +52 -0
  82. package/src/components/TableOfContents.svelte +125 -0
  83. package/src/components/ui/ActionLink.svelte +40 -0
  84. package/src/components/ui/Button.svelte +53 -0
  85. package/src/components/ui/Dialog.svelte +97 -0
  86. package/src/components/ui/DropdownMenu.svelte +85 -0
  87. package/src/components/ui/DropdownMenuItem.svelte +38 -0
  88. package/src/components/ui/DropdownMenuSeparator.svelte +11 -0
  89. package/src/components/ui/Text.svelte +42 -0
  90. package/src/env.d.ts +6 -0
  91. package/src/index.css +36 -166
  92. package/src/lib/__fixtures__/bench-data.ts +1 -54
  93. package/src/lib/anchor.bench.ts +47 -68
  94. package/src/lib/anchor.test.ts +5 -9
  95. package/src/lib/anchor.ts +9 -93
  96. package/src/lib/comment-storage.bench.ts +6 -20
  97. package/src/lib/comment-storage.test.ts +45 -37
  98. package/src/lib/comment-storage.ts +23 -64
  99. package/src/lib/export.bench.ts +9 -23
  100. package/src/lib/export.ts +7 -14
  101. package/src/lib/headings.test.ts +103 -0
  102. package/src/lib/headings.ts +44 -0
  103. package/src/lib/highlight/core.test.ts +1 -6
  104. package/src/lib/highlight/dom.ts +53 -280
  105. package/src/lib/highlight/highlight-registry.ts +221 -0
  106. package/src/lib/highlight/highlight.bench.ts +92 -0
  107. package/src/lib/highlight/highlighter.ts +122 -302
  108. package/src/lib/highlight/{core.ts → resolver.ts} +3 -19
  109. package/src/lib/highlight/types.ts +0 -40
  110. package/src/lib/html-text.test.ts +162 -0
  111. package/src/lib/html-text.ts +161 -0
  112. package/src/lib/i18n/en.ts +13 -36
  113. package/src/lib/i18n/ja.ts +14 -37
  114. package/src/lib/i18n/types.ts +13 -36
  115. package/src/lib/margin-layout.bench.ts +48 -15
  116. package/src/lib/margin-layout.ts +2 -31
  117. package/src/lib/markdown-renderer.test.ts +154 -0
  118. package/src/lib/markdown-renderer.ts +177 -0
  119. package/src/lib/mermaid-config.ts +38 -0
  120. package/src/lib/mermaid-renderer.ts +162 -0
  121. package/src/lib/mermaid-worker.ts +60 -0
  122. package/src/lib/positions.ts +157 -0
  123. package/src/lib/shortcut-registry.ts +138 -103
  124. package/src/lib/utils.ts +2 -48
  125. package/src/main.ts +16 -0
  126. package/src/schema.ts +92 -0
  127. package/src/{server/index.ts → server.ts} +427 -163
  128. package/src/stores/app.svelte.ts +231 -0
  129. package/src/stores/locale.svelte.ts +46 -0
  130. package/src/stores/settings.svelte.ts +90 -0
  131. package/src/stores/shortcuts.svelte.ts +104 -0
  132. package/src/stores/ui.svelte.ts +12 -0
  133. package/src/template.ts +104 -0
  134. package/src/test-setup.ts +47 -0
  135. package/svelte.config.js +5 -0
  136. package/tsconfig.json +2 -2
  137. package/vite.config.ts +31 -3
  138. package/vscode-readit/.mcp.json +7 -0
  139. package/vscode-readit/.vscodeignore +7 -0
  140. package/vscode-readit/bun.lock +78 -0
  141. package/vscode-readit/icon.svg +10 -0
  142. package/vscode-readit/package.json +110 -0
  143. package/vscode-readit/src/extension.ts +117 -0
  144. package/vscode-readit/src/server-manager.ts +272 -0
  145. package/vscode-readit/src/webview-provider.ts +204 -0
  146. package/vscode-readit/tsconfig.json +20 -0
  147. package/e2e/fixtures/sample.html +0 -13
  148. package/src/App.tsx +0 -416
  149. package/src/components/ActionsMenu.tsx +0 -112
  150. package/src/components/DocumentViewer/CodeBlock.tsx +0 -160
  151. package/src/components/DocumentViewer/DocumentViewer.tsx +0 -259
  152. package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
  153. package/src/components/DocumentViewer/InlineCode.tsx +0 -60
  154. package/src/components/DocumentViewer/MermaidDiagram.tsx +0 -137
  155. package/src/components/DocumentViewer/index.ts +0 -1
  156. package/src/components/FloatingTOC.tsx +0 -61
  157. package/src/components/Header.tsx +0 -65
  158. package/src/components/InlineEditor.tsx +0 -74
  159. package/src/components/MarginNote.tsx +0 -207
  160. package/src/components/MarginNotes.tsx +0 -50
  161. package/src/components/RawModal.tsx +0 -143
  162. package/src/components/ReanchorConfirm.tsx +0 -36
  163. package/src/components/SettingsModal.tsx +0 -310
  164. package/src/components/ShortcutCapture.tsx +0 -48
  165. package/src/components/ShortcutList.tsx +0 -198
  166. package/src/components/TabBar.tsx +0 -60
  167. package/src/components/TableOfContents.tsx +0 -108
  168. package/src/components/comments/CommentBadge.tsx +0 -49
  169. package/src/components/comments/CommentInput.tsx +0 -114
  170. package/src/components/comments/CommentListItem.tsx +0 -92
  171. package/src/components/comments/CommentManager.tsx +0 -113
  172. package/src/components/comments/CommentMinimap.tsx +0 -62
  173. package/src/components/comments/CommentNav.tsx +0 -109
  174. package/src/components/ui/ActionBar.tsx +0 -16
  175. package/src/components/ui/ActionLink.tsx +0 -32
  176. package/src/components/ui/Button.tsx +0 -55
  177. package/src/components/ui/Dialog.tsx +0 -156
  178. package/src/components/ui/DropdownMenu.tsx +0 -114
  179. package/src/components/ui/SeparatorDot.tsx +0 -9
  180. package/src/components/ui/Text.tsx +0 -54
  181. package/src/contexts/CommentContext.tsx +0 -229
  182. package/src/contexts/LayoutContext.tsx +0 -88
  183. package/src/contexts/LocaleContext.tsx +0 -35
  184. package/src/hooks/useClickOutside.ts +0 -35
  185. package/src/hooks/useClipboard.ts +0 -82
  186. package/src/hooks/useCommentNavigation.ts +0 -130
  187. package/src/hooks/useComments.ts +0 -323
  188. package/src/hooks/useDocument.ts +0 -156
  189. package/src/hooks/useEditorScheme.ts +0 -51
  190. package/src/hooks/useFontPreference.ts +0 -59
  191. package/src/hooks/useHeadings.test.ts +0 -159
  192. package/src/hooks/useHeadings.ts +0 -129
  193. package/src/hooks/useKeybindings.ts +0 -108
  194. package/src/hooks/useKeyboardShortcuts.ts +0 -63
  195. package/src/hooks/useLayoutMode.ts +0 -44
  196. package/src/hooks/useLocalePreference.ts +0 -42
  197. package/src/hooks/useReanchorMode.ts +0 -33
  198. package/src/hooks/useScrollMetrics.ts +0 -56
  199. package/src/hooks/useScrollSpy.ts +0 -81
  200. package/src/hooks/useTextSelection.ts +0 -123
  201. package/src/hooks/useThemePreference.ts +0 -66
  202. package/src/lib/context.bench.ts +0 -41
  203. package/src/lib/context.test.ts +0 -224
  204. package/src/lib/context.ts +0 -193
  205. package/src/lib/editor-links.ts +0 -59
  206. package/src/lib/highlight/colors.ts +0 -37
  207. package/src/lib/highlight/index.ts +0 -23
  208. package/src/lib/highlight/script-builder.ts +0 -485
  209. package/src/lib/html-processor.test.tsx +0 -170
  210. package/src/lib/html-processor.tsx +0 -95
  211. package/src/lib/i18n/completeness.test.ts +0 -51
  212. package/src/lib/i18n/translations.test.ts +0 -39
  213. package/src/lib/layout-constants.ts +0 -12
  214. package/src/lib/scroll.test.ts +0 -118
  215. package/src/lib/scroll.ts +0 -47
  216. package/src/lib/shortcut-registry.test.ts +0 -173
  217. package/src/lib/utils.test.ts +0 -110
  218. package/src/main.tsx +0 -13
  219. package/src/store/index.test.ts +0 -242
  220. package/src/store/index.ts +0 -254
  221. package/src/types/index.ts +0 -127
@@ -0,0 +1,327 @@
1
+ import * as crypto from "node:crypto";
2
+ import * as fs from "node:fs/promises";
3
+ import * as os from "node:os";
4
+ import * as path from "node:path";
5
+
6
+ // ─── Types ───────────────────────────────────────────────────────────
7
+
8
+ interface Comment {
9
+ id: string;
10
+ selectedText: string;
11
+ comment: string;
12
+ startOffset: number;
13
+ endOffset: number;
14
+ lineHint: string;
15
+ }
16
+
17
+ interface CommentFile {
18
+ source: string;
19
+ hash: string;
20
+ version: number;
21
+ comments: Comment[];
22
+ }
23
+
24
+ export interface Tier {
25
+ name: string;
26
+ lines: number;
27
+ comments: number;
28
+ fileName: string;
29
+ }
30
+
31
+ export const TIERS: Tier[] = [
32
+ { name: "medium", lines: 1000, comments: 100, fileName: "medium.md" },
33
+ { name: "large", lines: 3000, comments: 200, fileName: "large.md" },
34
+ ];
35
+
36
+ // Second medium doc for tab-switch tests
37
+ export const TAB_SWITCH_TIER: Tier = {
38
+ name: "medium-b",
39
+ lines: 1000,
40
+ comments: 100,
41
+ fileName: "medium-b.md",
42
+ };
43
+
44
+ export const FIXTURES_DIR = path.join(os.tmpdir(), "readit-perf-fixtures");
45
+
46
+ // ─── Markdown generation ─────────────────────────────────────────────
47
+
48
+ function generateMarkdownDoc(lineCount: number, seed: number): string {
49
+ const lines: string[] = [];
50
+ lines.push(`# Performance Benchmark Document (seed=${seed})`);
51
+ lines.push("");
52
+ lines.push(
53
+ "This document is auto-generated for performance benchmarking. It contains realistic markdown patterns.",
54
+ );
55
+ lines.push("");
56
+
57
+ let sectionNum = 1;
58
+ while (lines.length < lineCount) {
59
+ lines.push(`## Section ${sectionNum}: Topic Area ${sectionNum}`);
60
+ lines.push("");
61
+ lines.push(
62
+ `This section covers topic ${sectionNum} in detail. It includes various formatting such as **bold text**, *italic text*, and \`inline code\`. The content is designed to exercise the rendering pipeline.`,
63
+ );
64
+ lines.push("");
65
+
66
+ // Paragraph
67
+ lines.push(
68
+ `When reviewing documents of this complexity, it is important to consider the performance implications of rendering each element. Section ${sectionNum} demonstrates how the margin notes system handles comments distributed across a long document.`,
69
+ );
70
+ lines.push("");
71
+
72
+ // List
73
+ for (let j = 1; j <= 4; j++) {
74
+ lines.push(
75
+ `- Item ${j} in section ${sectionNum}: a list entry with enough text to be selectable`,
76
+ );
77
+ }
78
+ lines.push("");
79
+
80
+ // Code block
81
+ lines.push("```typescript");
82
+ lines.push(`function processSection${sectionNum}(data: unknown) {`);
83
+ lines.push(` const result = validate(data);`);
84
+ lines.push(
85
+ ` if (!result.ok) throw new Error("Section ${sectionNum} failed");`,
86
+ );
87
+ lines.push(` return transform(result.value);`);
88
+ lines.push("}");
89
+ lines.push("```");
90
+ lines.push("");
91
+
92
+ // Another paragraph
93
+ lines.push(
94
+ `The conclusion of section ${sectionNum} summarizes the key findings and provides actionable recommendations for the reader. This paragraph exists to ensure sufficient text density for highlight testing.`,
95
+ );
96
+ lines.push("");
97
+
98
+ // Table every 4th section
99
+ if (sectionNum % 4 === 0) {
100
+ lines.push("| Metric | Before | After | Change |");
101
+ lines.push("|--------|--------|-------|--------|");
102
+ lines.push(
103
+ `| Latency | ${sectionNum * 10}ms | ${sectionNum * 5}ms | -50% |`,
104
+ );
105
+ lines.push(
106
+ `| Throughput | ${sectionNum * 100} | ${sectionNum * 200} | +100% |`,
107
+ );
108
+ lines.push("");
109
+ }
110
+
111
+ // Blockquote every 5th section
112
+ if (sectionNum % 5 === 0) {
113
+ lines.push(
114
+ `> Note: Section ${sectionNum} contains important observations about system behavior under load.`,
115
+ );
116
+ lines.push("");
117
+ }
118
+
119
+ sectionNum++;
120
+ }
121
+
122
+ return lines.slice(0, lineCount).join("\n");
123
+ }
124
+
125
+ // ─── Comment generation ──────────────────────────────────────────────
126
+
127
+ function makeComment(
128
+ index: number,
129
+ doc: string,
130
+ totalComments: number,
131
+ ): Comment {
132
+ const lines = doc.split("\n");
133
+
134
+ // Distribute comments evenly across the document, skipping empty lines and headers
135
+ const contentLines: { lineIndex: number; text: string }[] = [];
136
+ for (let i = 0; i < lines.length; i++) {
137
+ const line = lines[i];
138
+ if (
139
+ line.length > 20 &&
140
+ !line.startsWith("#") &&
141
+ !line.startsWith("```") &&
142
+ !line.startsWith("|") &&
143
+ !line.startsWith(">") &&
144
+ !line.startsWith("- ")
145
+ ) {
146
+ contentLines.push({ lineIndex: i, text: line });
147
+ }
148
+ }
149
+
150
+ // Pick a content line for this comment
151
+ const targetIdx = Math.floor(
152
+ (index / totalComments) * (contentLines.length - 1),
153
+ );
154
+ const target = contentLines[Math.min(targetIdx, contentLines.length - 1)];
155
+
156
+ // Select a substring from the target line
157
+ const selectStart = 0;
158
+ const selectEnd = Math.min(40, target.text.length);
159
+ const selectedText = target.text.slice(selectStart, selectEnd);
160
+
161
+ // Compute character offset in the full document
162
+ let startOffset = 0;
163
+ for (let i = 0; i < target.lineIndex; i++) {
164
+ startOffset += lines[i].length + 1; // +1 for \n
165
+ }
166
+ startOffset += selectStart;
167
+ const endOffset = startOffset + selectedText.length;
168
+
169
+ // Line hint (1-indexed)
170
+ const lineHint = `L${target.lineIndex + 1}`;
171
+
172
+ return {
173
+ id: `perf${String(index).padStart(4, "0")}`,
174
+ selectedText,
175
+ comment: `Review comment #${index + 1}: This section needs attention regarding clarity and accuracy.`,
176
+ startOffset,
177
+ endOffset,
178
+ lineHint,
179
+ };
180
+ }
181
+
182
+ // ─── Comment serialization (standalone, no imports from src/) ────────
183
+
184
+ function computeHash(content: string): string {
185
+ return crypto.createHash("sha256").update(content).digest("hex").slice(0, 16);
186
+ }
187
+
188
+ function serializeComments(file: CommentFile): string {
189
+ const lines: string[] = [];
190
+
191
+ lines.push("---");
192
+ lines.push(`source: ${file.source}`);
193
+ lines.push(`hash: ${file.hash}`);
194
+ lines.push(`version: ${file.version}`);
195
+ lines.push("---");
196
+ lines.push("");
197
+
198
+ for (const comment of file.comments) {
199
+ // Metadata
200
+ lines.push(`<!-- c:${comment.id}|${comment.lineHint} -->`);
201
+
202
+ // Selected text as blockquote
203
+ const quotedLines = comment.selectedText
204
+ .split("\n")
205
+ .map((line) => `> ${line}`);
206
+ lines.push(...quotedLines);
207
+
208
+ // Comment body
209
+ if (comment.comment) {
210
+ lines.push("");
211
+ lines.push(comment.comment);
212
+ }
213
+
214
+ lines.push("");
215
+ lines.push("---");
216
+ lines.push("");
217
+ }
218
+
219
+ return lines.join("\n");
220
+ }
221
+
222
+ /**
223
+ * Compute comment path using realpath to match the server's path resolution.
224
+ * The server uses fs.realpath() which resolves symlinks (e.g., /var → /private/var on macOS).
225
+ * The sourcePath must exist on disk before calling this.
226
+ */
227
+ async function getCommentPathReal(sourcePath: string): Promise<string> {
228
+ const real = await fs.realpath(path.resolve(sourcePath));
229
+ const normalized = real.replace(/^\//, "").replace(/^[A-Z]:[\\/]/, "");
230
+ const ext = path.extname(normalized);
231
+ const withoutExt = normalized.slice(0, -ext.length || undefined);
232
+ return path.join(
233
+ os.homedir(),
234
+ ".readit",
235
+ "comments",
236
+ `${withoutExt}.comments.md`,
237
+ );
238
+ }
239
+
240
+ /** Sync version for cleanup (file may not exist) */
241
+ function getCommentPathSync(sourcePath: string): string {
242
+ let absolute: string;
243
+ try {
244
+ absolute = require("node:fs").realpathSync(path.resolve(sourcePath));
245
+ } catch {
246
+ absolute = path.resolve(sourcePath);
247
+ }
248
+ const normalized = absolute.replace(/^\//, "").replace(/^[A-Z]:[\\/]/, "");
249
+ const ext = path.extname(normalized);
250
+ const withoutExt = normalized.slice(0, -ext.length || undefined);
251
+ return path.join(
252
+ os.homedir(),
253
+ ".readit",
254
+ "comments",
255
+ `${withoutExt}.comments.md`,
256
+ );
257
+ }
258
+
259
+ // ─── Public API ──────────────────────────────────────────────────────
260
+
261
+ export function getFixturePath(tier: Tier): string {
262
+ return path.join(FIXTURES_DIR, tier.fileName);
263
+ }
264
+
265
+ export async function generateFixtures(): Promise<void> {
266
+ await fs.mkdir(FIXTURES_DIR, { recursive: true });
267
+
268
+ const allTiers = [...TIERS, TAB_SWITCH_TIER];
269
+
270
+ for (const tier of allTiers) {
271
+ const doc = generateMarkdownDoc(tier.lines, tier.lines);
272
+ const fixturePath = getFixturePath(tier);
273
+ await fs.writeFile(fixturePath, doc, "utf-8");
274
+
275
+ // Generate and write comment file
276
+ const comments: Comment[] = [];
277
+ for (let i = 0; i < tier.comments; i++) {
278
+ comments.push(makeComment(i, doc, tier.comments));
279
+ }
280
+
281
+ // Use realpath for the comment path (file must exist first)
282
+ const realFixturePath = await fs.realpath(fixturePath);
283
+
284
+ const commentFile: CommentFile = {
285
+ source: realFixturePath,
286
+ hash: computeHash(doc),
287
+ version: 1,
288
+ comments,
289
+ };
290
+
291
+ const commentPath = await getCommentPathReal(fixturePath);
292
+ await fs.mkdir(path.dirname(commentPath), { recursive: true });
293
+ await fs.writeFile(commentPath, serializeComments(commentFile), "utf-8");
294
+ }
295
+ }
296
+
297
+ export async function cleanupFixtures(): Promise<void> {
298
+ // Collect comment paths before removing fixtures (need realpath while files exist)
299
+ const commentPaths: string[] = [];
300
+ const allTiers = [...TIERS, TAB_SWITCH_TIER];
301
+ for (const tier of allTiers) {
302
+ commentPaths.push(getCommentPathSync(getFixturePath(tier)));
303
+ }
304
+
305
+ // Remove fixture files
306
+ try {
307
+ await fs.rm(FIXTURES_DIR, { recursive: true, force: true });
308
+ } catch {
309
+ // Ignore if already removed
310
+ }
311
+
312
+ // Remove comment files
313
+ for (const commentPath of commentPaths) {
314
+ try {
315
+ await fs.unlink(commentPath);
316
+ } catch {
317
+ // Ignore if already removed
318
+ }
319
+ }
320
+ }
321
+
322
+ // Allow running directly: bun e2e/perf/fixtures/generate.ts
323
+ if (import.meta.url === `file://${process.argv[1]}`) {
324
+ generateFixtures().then(() => {
325
+ console.log(`Fixtures generated in ${FIXTURES_DIR}`);
326
+ });
327
+ }
@@ -0,0 +1,49 @@
1
+ import { test } from "@playwright/test";
2
+ import { getFixturePath, TIERS } from "./fixtures/generate";
3
+ import { collectLoadMetrics, reportLoadMetrics } from "./utils/metrics";
4
+ import { spawnPerfCli } from "./utils/perf-cli";
5
+
6
+ const ITERATIONS = 3;
7
+
8
+ for (const tier of TIERS) {
9
+ test(`initial-load: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
10
+ page,
11
+ }, testInfo) => {
12
+ const fixturePath = getFixturePath(tier);
13
+ const { url, cleanup } = await spawnPerfCli(fixturePath, {
14
+ port: 4600 + TIERS.indexOf(tier),
15
+ });
16
+
17
+ try {
18
+ const results: (typeof collected)[] = [];
19
+ let collected!: Awaited<ReturnType<typeof collectLoadMetrics>>;
20
+
21
+ for (let i = 0; i < ITERATIONS; i++) {
22
+ // Clear performance entries between iterations
23
+ if (i > 0) {
24
+ await page.evaluate(() => performance.clearResourceTimings());
25
+ }
26
+
27
+ collected = await collectLoadMetrics(page, url, tier.comments);
28
+ results.push(collected);
29
+
30
+ // Navigate away between iterations to force full reload
31
+ if (i < ITERATIONS - 1) {
32
+ await page.goto("about:blank");
33
+ }
34
+ }
35
+
36
+ // Report median
37
+ results.sort((a, b) => a.allHighlightsPainted - b.allHighlightsPainted);
38
+ const median = results[Math.floor(results.length / 2)];
39
+
40
+ reportLoadMetrics(
41
+ testInfo,
42
+ `initial-load (${tier.name}: ${tier.lines} lines, ${tier.comments} comments)`,
43
+ median,
44
+ );
45
+ } finally {
46
+ await cleanup();
47
+ }
48
+ });
49
+ }
@@ -0,0 +1,23 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { generateFixtures } from "./fixtures/generate";
5
+
6
+ async function globalSetup() {
7
+ // Build the app if dist doesn't exist
8
+ const distIndex = resolve(import.meta.dirname, "../../dist/cli.js");
9
+ if (!existsSync(distIndex)) {
10
+ console.log("[perf] Building app...");
11
+ execFileSync("bun", ["run", "build"], {
12
+ cwd: resolve(import.meta.dirname, "../.."),
13
+ stdio: "inherit",
14
+ });
15
+ }
16
+
17
+ // Generate fixture files and comment files
18
+ console.log("[perf] Generating fixtures...");
19
+ await generateFixtures();
20
+ console.log("[perf] Setup complete.");
21
+ }
22
+
23
+ export default globalSetup;
@@ -0,0 +1,9 @@
1
+ import { cleanupFixtures } from "./fixtures/generate";
2
+
3
+ async function globalTeardown() {
4
+ console.log("[perf] Cleaning up fixtures...");
5
+ await cleanupFixtures();
6
+ console.log("[perf] Teardown complete.");
7
+ }
8
+
9
+ export default globalTeardown;
Binary file
@@ -0,0 +1,39 @@
1
+ import { test } from "@playwright/test";
2
+ import { getFixturePath, TIERS } from "./fixtures/generate";
3
+ import {
4
+ collectScrollMetrics,
5
+ reportScrollMetrics,
6
+ waitForHighlightCount,
7
+ } from "./utils/metrics";
8
+ import { spawnPerfCli } from "./utils/perf-cli";
9
+
10
+ for (const tier of TIERS) {
11
+ test(`scroll: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
12
+ page,
13
+ }, testInfo) => {
14
+ const fixturePath = getFixturePath(tier);
15
+ const { url, cleanup } = await spawnPerfCli(fixturePath, {
16
+ port: 4610 + TIERS.indexOf(tier),
17
+ });
18
+
19
+ try {
20
+ await page.goto(url);
21
+
22
+ // Wait for all highlights to be painted before starting scroll
23
+ await waitForHighlightCount(page, tier.comments);
24
+
25
+ // Small pause for layout to settle
26
+ await page.waitForTimeout(500);
27
+
28
+ const metrics = await collectScrollMetrics(page);
29
+
30
+ reportScrollMetrics(
31
+ testInfo,
32
+ `scroll (${tier.name}: ${tier.lines} lines, ${tier.comments} comments)`,
33
+ metrics,
34
+ );
35
+ } finally {
36
+ await cleanup();
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,69 @@
1
+ import { test } from "@playwright/test";
2
+ import { getFixturePath, TAB_SWITCH_TIER, TIERS } from "./fixtures/generate";
3
+ import {
4
+ measureInteraction,
5
+ reportInteraction,
6
+ waitForHighlightCount,
7
+ } from "./utils/metrics";
8
+ import { spawnPerfCli } from "./utils/perf-cli";
9
+
10
+ const tierA = TIERS[0]; // medium
11
+ const tierB = TAB_SWITCH_TIER; // medium-b
12
+
13
+ test(`tab-switch: between two ${tierA.name} documents`, async ({
14
+ page,
15
+ }, testInfo) => {
16
+ const pathA = getFixturePath(tierA);
17
+ const pathB = getFixturePath(tierB);
18
+
19
+ const { url, cleanup } = await spawnPerfCli([pathA, pathB], { port: 4640 });
20
+
21
+ try {
22
+ await page.goto(url);
23
+
24
+ // Wait for first document to be fully loaded with highlights
25
+ await waitForHighlightCount(page, tierA.comments);
26
+ await page.waitForTimeout(500);
27
+
28
+ // Find the second tab and measure the switch
29
+ const duration = await measureInteraction(
30
+ page,
31
+ "tab-switch",
32
+ async () => {
33
+ // Click the second tab — tabs display file names
34
+ const tabs = page.locator('[role="tab"], button').filter({
35
+ hasText: tierB.fileName.replace(".md", ""),
36
+ });
37
+
38
+ // If tabs aren't labeled with role="tab", find by filename text
39
+ const tabCount = await tabs.count();
40
+ if (tabCount > 0) {
41
+ await tabs.first().click();
42
+ } else {
43
+ // Fallback: find any clickable element containing the filename
44
+ const allButtons = page.locator("button, a");
45
+ const count = await allButtons.count();
46
+ for (let i = 0; i < count; i++) {
47
+ const text = await allButtons.nth(i).textContent();
48
+ if (text?.includes("medium-b")) {
49
+ await allButtons.nth(i).click();
50
+ break;
51
+ }
52
+ }
53
+ }
54
+ },
55
+ async () => {
56
+ // Wait for the second document's highlights to paint
57
+ await waitForHighlightCount(page, tierB.comments, 60_000);
58
+ },
59
+ );
60
+
61
+ reportInteraction(
62
+ testInfo,
63
+ `tab-switch: ${tierA.name} → ${tierB.name} (${tierA.comments} → ${tierB.comments} comments)`,
64
+ duration,
65
+ );
66
+ } finally {
67
+ await cleanup();
68
+ }
69
+ });
@@ -0,0 +1,119 @@
1
+ import { test } from "@playwright/test";
2
+ import { getFixturePath, TIERS } from "./fixtures/generate";
3
+ import {
4
+ measureInteraction,
5
+ reportInteraction,
6
+ waitForHighlightCount,
7
+ } from "./utils/metrics";
8
+ import { spawnPerfCli } from "./utils/perf-cli";
9
+
10
+ // Use medium tier
11
+ const tier = TIERS[0];
12
+ const ITERATIONS = 5;
13
+
14
+ test(`text-selection: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
15
+ page,
16
+ }, testInfo) => {
17
+ const fixturePath = getFixturePath(tier);
18
+ const { url, cleanup } = await spawnPerfCli(fixturePath, { port: 4630 });
19
+
20
+ try {
21
+ await page.goto(url);
22
+ await waitForHighlightCount(page, tier.comments);
23
+ await page.waitForTimeout(300);
24
+
25
+ // Collect selectable text positions distributed across the document
26
+ const targets = await page.evaluate((count) => {
27
+ const article = document.querySelector("article");
28
+ if (!article) throw new Error("Article not found");
29
+
30
+ const paragraphs = [...article.querySelectorAll("p")];
31
+ const step = Math.floor(paragraphs.length / (count + 1));
32
+
33
+ return paragraphs
34
+ .filter((_, i) => i % step === 0)
35
+ .slice(0, count)
36
+ .map((p) => {
37
+ const text = (p.textContent || "").slice(0, 25).trim();
38
+ return text;
39
+ })
40
+ .filter((t) => t.length > 10);
41
+ }, ITERATIONS);
42
+
43
+ const durations: number[] = [];
44
+
45
+ for (const targetText of targets) {
46
+ // Clear any existing selection state
47
+ await page.evaluate(() => window.getSelection()?.removeAllRanges());
48
+ await page.waitForTimeout(100);
49
+
50
+ const duration = await measureInteraction(
51
+ page,
52
+ `text-selection-${targets.indexOf(targetText)}`,
53
+ async () => {
54
+ // Trigger text selection via custom event
55
+ await page.evaluate((text) => {
56
+ const article = document.querySelector("article");
57
+ if (!article) throw new Error("Article not found");
58
+
59
+ const walker = document.createTreeWalker(
60
+ article,
61
+ NodeFilter.SHOW_TEXT,
62
+ );
63
+ let currentOffset = 0;
64
+
65
+ while (walker.nextNode()) {
66
+ const textNode = walker.currentNode as Text;
67
+ const content = textNode.textContent || "";
68
+ const index = content.indexOf(text);
69
+
70
+ if (index !== -1) {
71
+ const startOffset = currentOffset + index;
72
+ const endOffset = startOffset + text.length;
73
+ window.dispatchEvent(
74
+ new CustomEvent("test:select-text", {
75
+ detail: { text, startOffset, endOffset },
76
+ }),
77
+ );
78
+ return;
79
+ }
80
+
81
+ currentOffset += content.length;
82
+ }
83
+
84
+ throw new Error(`Text "${text}" not found`);
85
+ }, targetText);
86
+ },
87
+ async () => {
88
+ // Wait for comment input textarea to appear
89
+ await page
90
+ .locator('textarea[placeholder="Add your comment..."]')
91
+ .waitFor({ state: "visible", timeout: 10_000 });
92
+ },
93
+ );
94
+
95
+ durations.push(duration);
96
+
97
+ // Cancel the selection (press Escape to dismiss the comment input)
98
+ await page.keyboard.press("Escape");
99
+ await page.waitForTimeout(100);
100
+ }
101
+
102
+ // Report median
103
+ durations.sort((a, b) => a - b);
104
+ const median = durations[Math.floor(durations.length / 2)];
105
+
106
+ reportInteraction(
107
+ testInfo,
108
+ `text-selection: median of ${durations.length} iterations (${tier.name})`,
109
+ median,
110
+ );
111
+
112
+ // Also report all iterations
113
+ console.log(
114
+ ` All iterations: ${durations.map((d) => `${Math.round(d)}ms`).join(", ")}`,
115
+ );
116
+ } finally {
117
+ await cleanup();
118
+ }
119
+ });