@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.
- package/.claude/CLAUDE.md +118 -76
- package/.claude/commands/review.md +1 -1
- package/.claude/roadmap.md +32 -9
- package/.claude/user-stories.md +100 -15
- package/AGENTS.md +30 -26
- package/Makefile +32 -0
- package/README.md +90 -5
- package/biome.json +18 -8
- package/bun.lock +426 -710
- package/bunfig.toml +2 -0
- package/docs/perf-baseline.md +130 -0
- package/docs/superpowers/plans/2026-03-26-surgical-pruning.md +1176 -0
- package/docs/superpowers/specs/2026-03-27-go-server-rewrite-design.md +284 -0
- package/e2e/comments.spec.ts +14 -58
- package/e2e/document-load.spec.ts +1 -23
- package/e2e/export.spec.ts +4 -4
- package/e2e/perf/add-comment.spec.ts +116 -0
- package/e2e/perf/fixtures/generate.ts +327 -0
- package/e2e/perf/initial-load.spec.ts +49 -0
- package/e2e/perf/perf.setup.ts +23 -0
- package/e2e/perf/perf.teardown.ts +9 -0
- package/e2e/perf/screenshot-final.png +0 -0
- package/e2e/perf/scroll.spec.ts +39 -0
- package/e2e/perf/tab-switch.spec.ts +69 -0
- package/e2e/perf/text-selection.spec.ts +119 -0
- package/e2e/perf/utils/metrics.ts +350 -0
- package/e2e/perf/utils/perf-cli.ts +86 -0
- package/e2e/persistence-file.spec.ts +41 -26
- package/e2e/utils/selection.ts +17 -73
- package/go/cmd/readit/main.go +416 -0
- package/go/go.mod +20 -0
- package/go/go.sum +41 -0
- package/go/internal/server/anchor.go +302 -0
- package/go/internal/server/anchor_test.go +111 -0
- package/go/internal/server/comments.go +390 -0
- package/go/internal/server/documents.go +113 -0
- package/go/internal/server/embed.go +17 -0
- package/go/internal/server/headings.go +33 -0
- package/go/internal/server/headings_test.go +75 -0
- package/go/internal/server/htmltext.go +123 -0
- package/go/internal/server/markdown.go +157 -0
- package/go/internal/server/markdown_bench_test.go +42 -0
- package/go/internal/server/markdown_test.go +79 -0
- package/go/internal/server/server.go +453 -0
- package/go/internal/server/server_bench_test.go +122 -0
- package/go/internal/server/settings.go +110 -0
- package/go/internal/server/sse.go +140 -0
- package/go/internal/server/storage.go +275 -0
- package/go/internal/server/storage_test.go +118 -0
- package/go/internal/server/template.go +66 -0
- package/go/internal/server/types.go +101 -0
- package/go/internal/server/watcher.go +74 -0
- package/index.html +4 -14
- package/nvim-readit/lua/readit/health.lua +64 -0
- package/nvim-readit/lua/readit/init.lua +463 -0
- package/nvim-readit/plugin/readit.lua +19 -0
- package/package.json +24 -41
- package/playwright.config.ts +12 -0
- package/shell/_readit +158 -0
- package/shell/readit.zsh +87 -0
- package/src/App.svelte +881 -0
- package/src/{cli/index.ts → cli.ts} +216 -70
- package/src/components/ActionsMenu.svelte +95 -0
- package/src/components/CommentBadge.svelte +67 -0
- package/src/components/CommentErrorBanner.svelte +33 -0
- package/src/components/CommentInput.svelte +75 -0
- package/src/components/CommentListItem.svelte +95 -0
- package/src/components/CommentManager.svelte +129 -0
- package/src/components/CommentNav.svelte +109 -0
- package/src/components/DocumentViewer.svelte +218 -0
- package/src/components/FloatingComment.svelte +107 -0
- package/src/components/Header.svelte +76 -0
- package/src/components/InlineEditor.svelte +72 -0
- package/src/components/MarginNote.svelte +167 -0
- package/src/components/MarginNotesContainer.svelte +33 -0
- package/src/components/RawModal.svelte +126 -0
- package/src/components/ReanchorConfirm.svelte +30 -0
- package/src/components/SettingsModal.svelte +220 -0
- package/src/components/ShortcutCapture.svelte +82 -0
- package/src/components/ShortcutList.svelte +145 -0
- package/src/components/TabBar.svelte +52 -0
- package/src/components/TableOfContents.svelte +125 -0
- package/src/components/ui/ActionLink.svelte +40 -0
- package/src/components/ui/Button.svelte +53 -0
- package/src/components/ui/Dialog.svelte +97 -0
- package/src/components/ui/DropdownMenu.svelte +85 -0
- package/src/components/ui/DropdownMenuItem.svelte +38 -0
- package/src/components/ui/DropdownMenuSeparator.svelte +11 -0
- package/src/components/ui/Text.svelte +42 -0
- package/src/env.d.ts +6 -0
- package/src/index.css +36 -166
- package/src/lib/__fixtures__/bench-data.ts +1 -54
- package/src/lib/anchor.bench.ts +47 -68
- package/src/lib/anchor.test.ts +5 -9
- package/src/lib/anchor.ts +9 -93
- package/src/lib/comment-storage.bench.ts +6 -20
- package/src/lib/comment-storage.test.ts +45 -37
- package/src/lib/comment-storage.ts +23 -64
- package/src/lib/export.bench.ts +9 -23
- package/src/lib/export.ts +7 -14
- package/src/lib/headings.test.ts +103 -0
- package/src/lib/headings.ts +44 -0
- package/src/lib/highlight/core.test.ts +1 -6
- package/src/lib/highlight/dom.ts +53 -280
- package/src/lib/highlight/highlight-registry.ts +221 -0
- package/src/lib/highlight/highlight.bench.ts +92 -0
- package/src/lib/highlight/highlighter.ts +122 -302
- package/src/lib/highlight/{core.ts → resolver.ts} +3 -19
- package/src/lib/highlight/types.ts +0 -40
- package/src/lib/html-text.test.ts +162 -0
- package/src/lib/html-text.ts +161 -0
- package/src/lib/i18n/en.ts +13 -36
- package/src/lib/i18n/ja.ts +14 -37
- package/src/lib/i18n/types.ts +13 -36
- package/src/lib/margin-layout.bench.ts +48 -15
- package/src/lib/margin-layout.ts +2 -31
- package/src/lib/markdown-renderer.test.ts +154 -0
- package/src/lib/markdown-renderer.ts +177 -0
- package/src/lib/mermaid-config.ts +38 -0
- package/src/lib/mermaid-renderer.ts +162 -0
- package/src/lib/mermaid-worker.ts +60 -0
- package/src/lib/positions.ts +157 -0
- package/src/lib/shortcut-registry.ts +138 -103
- package/src/lib/utils.ts +2 -48
- package/src/main.ts +16 -0
- package/src/schema.ts +92 -0
- package/src/{server/index.ts → server.ts} +427 -163
- package/src/stores/app.svelte.ts +231 -0
- package/src/stores/locale.svelte.ts +46 -0
- package/src/stores/settings.svelte.ts +90 -0
- package/src/stores/shortcuts.svelte.ts +104 -0
- package/src/stores/ui.svelte.ts +12 -0
- package/src/template.ts +104 -0
- package/src/test-setup.ts +47 -0
- package/svelte.config.js +5 -0
- package/tsconfig.json +2 -2
- package/vite.config.ts +31 -3
- package/vscode-readit/.mcp.json +7 -0
- package/vscode-readit/.vscodeignore +7 -0
- package/vscode-readit/bun.lock +78 -0
- package/vscode-readit/icon.svg +10 -0
- package/vscode-readit/package.json +110 -0
- package/vscode-readit/src/extension.ts +117 -0
- package/vscode-readit/src/server-manager.ts +272 -0
- package/vscode-readit/src/webview-provider.ts +204 -0
- package/vscode-readit/tsconfig.json +20 -0
- package/e2e/fixtures/sample.html +0 -13
- package/src/App.tsx +0 -416
- package/src/components/ActionsMenu.tsx +0 -112
- package/src/components/DocumentViewer/CodeBlock.tsx +0 -160
- package/src/components/DocumentViewer/DocumentViewer.tsx +0 -259
- package/src/components/DocumentViewer/IframeContainer.tsx +0 -251
- package/src/components/DocumentViewer/InlineCode.tsx +0 -60
- package/src/components/DocumentViewer/MermaidDiagram.tsx +0 -137
- package/src/components/DocumentViewer/index.ts +0 -1
- package/src/components/FloatingTOC.tsx +0 -61
- package/src/components/Header.tsx +0 -65
- package/src/components/InlineEditor.tsx +0 -74
- package/src/components/MarginNote.tsx +0 -207
- package/src/components/MarginNotes.tsx +0 -50
- package/src/components/RawModal.tsx +0 -143
- package/src/components/ReanchorConfirm.tsx +0 -36
- package/src/components/SettingsModal.tsx +0 -310
- package/src/components/ShortcutCapture.tsx +0 -48
- package/src/components/ShortcutList.tsx +0 -198
- package/src/components/TabBar.tsx +0 -60
- package/src/components/TableOfContents.tsx +0 -108
- package/src/components/comments/CommentBadge.tsx +0 -49
- package/src/components/comments/CommentInput.tsx +0 -114
- package/src/components/comments/CommentListItem.tsx +0 -92
- package/src/components/comments/CommentManager.tsx +0 -113
- package/src/components/comments/CommentMinimap.tsx +0 -62
- package/src/components/comments/CommentNav.tsx +0 -109
- package/src/components/ui/ActionBar.tsx +0 -16
- package/src/components/ui/ActionLink.tsx +0 -32
- package/src/components/ui/Button.tsx +0 -55
- package/src/components/ui/Dialog.tsx +0 -156
- package/src/components/ui/DropdownMenu.tsx +0 -114
- package/src/components/ui/SeparatorDot.tsx +0 -9
- package/src/components/ui/Text.tsx +0 -54
- package/src/contexts/CommentContext.tsx +0 -229
- package/src/contexts/LayoutContext.tsx +0 -88
- package/src/contexts/LocaleContext.tsx +0 -35
- package/src/hooks/useClickOutside.ts +0 -35
- package/src/hooks/useClipboard.ts +0 -82
- package/src/hooks/useCommentNavigation.ts +0 -130
- package/src/hooks/useComments.ts +0 -323
- package/src/hooks/useDocument.ts +0 -156
- package/src/hooks/useEditorScheme.ts +0 -51
- package/src/hooks/useFontPreference.ts +0 -59
- package/src/hooks/useHeadings.test.ts +0 -159
- package/src/hooks/useHeadings.ts +0 -129
- package/src/hooks/useKeybindings.ts +0 -108
- package/src/hooks/useKeyboardShortcuts.ts +0 -63
- package/src/hooks/useLayoutMode.ts +0 -44
- package/src/hooks/useLocalePreference.ts +0 -42
- package/src/hooks/useReanchorMode.ts +0 -33
- package/src/hooks/useScrollMetrics.ts +0 -56
- package/src/hooks/useScrollSpy.ts +0 -81
- package/src/hooks/useTextSelection.ts +0 -123
- package/src/hooks/useThemePreference.ts +0 -66
- package/src/lib/context.bench.ts +0 -41
- package/src/lib/context.test.ts +0 -224
- package/src/lib/context.ts +0 -193
- package/src/lib/editor-links.ts +0 -59
- package/src/lib/highlight/colors.ts +0 -37
- package/src/lib/highlight/index.ts +0 -23
- package/src/lib/highlight/script-builder.ts +0 -485
- package/src/lib/html-processor.test.tsx +0 -170
- package/src/lib/html-processor.tsx +0 -95
- package/src/lib/i18n/completeness.test.ts +0 -51
- package/src/lib/i18n/translations.test.ts +0 -39
- package/src/lib/layout-constants.ts +0 -12
- package/src/lib/scroll.test.ts +0 -118
- package/src/lib/scroll.ts +0 -47
- package/src/lib/shortcut-registry.test.ts +0 -173
- package/src/lib/utils.test.ts +0 -110
- package/src/main.tsx +0 -13
- package/src/store/index.test.ts +0 -242
- package/src/store/index.ts +0 -254
- package/src/types/index.ts +0 -127
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Go Server Rewrite Design Spec
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Rewrite readit's server and CLI from Bun/TypeScript to Go. The Svelte 5 frontend stays unchanged. Go handles all heavy computation (markdown rendering, syntax highlighting, comment storage, file watching, SSE) while Svelte handles client-side interactivity (highlights, margin notes, comment CRUD UI).
|
|
6
|
+
|
|
7
|
+
## Motivation
|
|
8
|
+
|
|
9
|
+
The current Bun server's cold-start path is dominated by Shiki WASM initialization (80-200ms) and the JSDOM mermaid worker (2-5s). A compiled Go binary with native libraries eliminates both bottlenecks:
|
|
10
|
+
|
|
11
|
+
- Process startup: 30-50ms (Bun) → <1ms (Go binary)
|
|
12
|
+
- Syntax highlighting init: 80-200ms (Shiki WASM) → 0ms (chroma, compiled in)
|
|
13
|
+
- Markdown render (3000 lines): 5-20ms (markdown-it) → <1ms (goldmark)
|
|
14
|
+
- Single binary distribution, no node_modules runtime dependency
|
|
15
|
+
|
|
16
|
+
Target: 50-100x improvement on server-side TTFB.
|
|
17
|
+
|
|
18
|
+
## Architecture
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
readit/
|
|
22
|
+
├── go/
|
|
23
|
+
│ ├── cmd/readit/main.go # CLI entry point
|
|
24
|
+
│ ├── internal/server/
|
|
25
|
+
│ │ ├── server.go # Mux setup, static serving, dev proxy
|
|
26
|
+
│ │ ├── documents.go # Document routes + file state
|
|
27
|
+
│ │ ├── comments.go # Comment CRUD routes
|
|
28
|
+
│ │ ├── settings.go # Settings routes
|
|
29
|
+
│ │ ├── sse.go # SSE broker, heartbeat, shutdown timer
|
|
30
|
+
│ │ ├── markdown.go # goldmark + chroma rendering
|
|
31
|
+
│ │ ├── headings.go # AST-based heading extraction
|
|
32
|
+
│ │ ├── storage.go # .comments.md parse/serialize
|
|
33
|
+
│ │ ├── anchor.go # Anchor resolution + fuzzy matching
|
|
34
|
+
│ │ ├── watcher.go # fsnotify file watching + debounce
|
|
35
|
+
│ │ ├── template.go # HTML page template
|
|
36
|
+
│ │ ├── types.go # Shared types
|
|
37
|
+
│ │ └── embed.go # go:embed dist/ assets
|
|
38
|
+
│ ├── go.mod
|
|
39
|
+
│ └── go.sum
|
|
40
|
+
├── src/ # Svelte frontend (unchanged)
|
|
41
|
+
├── dist/ # Vite build output (Go embeds this)
|
|
42
|
+
├── Makefile
|
|
43
|
+
├── vite.config.ts
|
|
44
|
+
└── package.json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Single Go package (`internal/server`) with flat files. `cmd/readit/main.go` calls `server.Start(opts)`. No nested packages, no interface indirection.
|
|
48
|
+
|
|
49
|
+
## Decisions
|
|
50
|
+
|
|
51
|
+
| Decision | Choice | Rationale |
|
|
52
|
+
|----------|--------|-----------|
|
|
53
|
+
| Language | Go | goldmark+chroma ecosystem, fast dev velocity, single binary |
|
|
54
|
+
| Repo structure | Monorepo (`go/` + `src/`) | Shared build pipeline, colocated frontend |
|
|
55
|
+
| Asset serving | `go:embed` + `--assets-dir` override | Single binary for production, filesystem for dev |
|
|
56
|
+
| Mermaid | Client-only with `<link rel="modulepreload">` | Eliminates JSDOM complexity, door open for server-side later |
|
|
57
|
+
| Dev workflow | `make dev` — Go manages Vite child process | Single command, Go proxies to Vite for HMR |
|
|
58
|
+
| Comment format | Keep `.comments.md` unchanged | Backward compatible, simple to parse in Go |
|
|
59
|
+
| File support | Markdown only | Tight scope for v1 |
|
|
60
|
+
| HTTP router | `net/http.ServeMux` (Go 1.22+) | Method+pattern routing, no framework dependency |
|
|
61
|
+
| CLI parsing | `flag` package | Simple subcommands, no cobra overhead |
|
|
62
|
+
|
|
63
|
+
## Server Core
|
|
64
|
+
|
|
65
|
+
The `Server` struct holds all shared state:
|
|
66
|
+
|
|
67
|
+
```go
|
|
68
|
+
type Server struct {
|
|
69
|
+
mux *http.ServeMux
|
|
70
|
+
files map[string]*FileState
|
|
71
|
+
fileOrder []string
|
|
72
|
+
sse *SSEBroker
|
|
73
|
+
watcher *Watcher
|
|
74
|
+
renderer *Renderer
|
|
75
|
+
settings Settings
|
|
76
|
+
workingDir string
|
|
77
|
+
clean bool
|
|
78
|
+
assetsFS fs.FS
|
|
79
|
+
template *template.Template
|
|
80
|
+
mu sync.RWMutex
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Routes registered as methods on `Server` — no handler interfaces, no middleware chain. Dev mode proxies non-API requests to Vite at `localhost:24678`.
|
|
85
|
+
|
|
86
|
+
## API Contract
|
|
87
|
+
|
|
88
|
+
The Go server implements the exact same API the Svelte frontend consumes. No changes to request/response shapes.
|
|
89
|
+
|
|
90
|
+
### Document Routes (`documents.go`)
|
|
91
|
+
|
|
92
|
+
| Method | Path | Purpose |
|
|
93
|
+
|--------|------|---------|
|
|
94
|
+
| GET | `/api/documents` | List open files |
|
|
95
|
+
| POST | `/api/documents` | Add file to session |
|
|
96
|
+
| GET | `/api/document?path=` | Get rendered HTML + headings |
|
|
97
|
+
|
|
98
|
+
### Comment Routes (`comments.go`)
|
|
99
|
+
|
|
100
|
+
| Method | Path | Purpose |
|
|
101
|
+
|--------|------|---------|
|
|
102
|
+
| GET | `/api/comments?path=` | List comments (with anchor resolution) |
|
|
103
|
+
| POST | `/api/comments?path=` | Create comment |
|
|
104
|
+
| PUT | `/api/comments/{id}?path=` | Update comment text |
|
|
105
|
+
| DELETE | `/api/comments/{id}?path=` | Delete comment |
|
|
106
|
+
| DELETE | `/api/comments?path=` | Delete all comments |
|
|
107
|
+
| PUT | `/api/comments/{id}/reanchor?path=` | Reanchor comment |
|
|
108
|
+
| GET | `/api/comments/raw?path=` | Raw .comments.md content |
|
|
109
|
+
|
|
110
|
+
### Settings Routes (`settings.go`)
|
|
111
|
+
|
|
112
|
+
| Method | Path | Purpose |
|
|
113
|
+
|--------|------|---------|
|
|
114
|
+
| GET | `/api/settings` | Read settings |
|
|
115
|
+
| PUT | `/api/settings` | Update font family |
|
|
116
|
+
|
|
117
|
+
### SSE Endpoints (`sse.go`)
|
|
118
|
+
|
|
119
|
+
| Method | Path | Purpose |
|
|
120
|
+
|--------|------|---------|
|
|
121
|
+
| GET | `/api/document/stream` | Document change events |
|
|
122
|
+
| GET | `/api/heartbeat` | Keep-alive, manages auto-shutdown |
|
|
123
|
+
|
|
124
|
+
### Other
|
|
125
|
+
|
|
126
|
+
| Method | Path | Purpose |
|
|
127
|
+
|--------|------|---------|
|
|
128
|
+
| GET | `/api/health` | Health check (`{"status":"ok"}`) |
|
|
129
|
+
| GET | `/` | SSR page with inline data |
|
|
130
|
+
| GET | `/assets/*` | Static assets (embedded or filesystem) |
|
|
131
|
+
|
|
132
|
+
### Inline Data Shape
|
|
133
|
+
|
|
134
|
+
The root page embeds JSON in `<script type="application/json" id="__readit">`:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"files": [{"path": "...", "fileName": "..."}],
|
|
139
|
+
"activeFile": "...",
|
|
140
|
+
"clean": false,
|
|
141
|
+
"workingDirectory": "...",
|
|
142
|
+
"documents": {
|
|
143
|
+
"/path/to/file.md": {
|
|
144
|
+
"html": "...",
|
|
145
|
+
"headings": [{"id": "...", "text": "...", "level": 1}],
|
|
146
|
+
"comments": [...]
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"settings": {"version": 1, "fontFamily": "serif"}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Markdown Pipeline (`markdown.go` + `headings.go`)
|
|
154
|
+
|
|
155
|
+
goldmark with extensions, configured once at startup:
|
|
156
|
+
|
|
157
|
+
- **GFM**: tables, strikethrough, autolinks, task lists
|
|
158
|
+
- **Chroma highlighting**: `onedark` style, CSS classes (not inline styles)
|
|
159
|
+
- **Auto heading IDs**: generated from heading text
|
|
160
|
+
- **Unsafe HTML**: raw HTML passthrough (matches current behavior)
|
|
161
|
+
|
|
162
|
+
Heading extraction walks the goldmark AST directly instead of regex.
|
|
163
|
+
|
|
164
|
+
Mermaid fenced code blocks pass through as `<pre><code class="language-mermaid">`. The Svelte frontend's `DocumentViewer.svelte` hydrates these client-side via lazy `import("mermaid")`. A `<link rel="modulepreload">` hint in the template accelerates the mermaid chunk download.
|
|
165
|
+
|
|
166
|
+
## Comment Storage (`storage.go` + `anchor.go`)
|
|
167
|
+
|
|
168
|
+
Parses and serializes the existing `.comments.md` format unchanged:
|
|
169
|
+
|
|
170
|
+
- Storage path: `~/.readit/comments/<mirrored-path>.comments.md`
|
|
171
|
+
- Format: YAML frontmatter (`source`, `hash`, `version`) + comment blocks separated by `---`
|
|
172
|
+
- Atomic writes: temp file + `os.Rename`
|
|
173
|
+
- Hash: SHA-256 of source content, truncated to 16 hex chars
|
|
174
|
+
|
|
175
|
+
Anchor resolution algorithm (direct port):
|
|
176
|
+
|
|
177
|
+
1. Exact match near `lineHint` position
|
|
178
|
+
2. Exact match anywhere in source
|
|
179
|
+
3. Normalized match (collapse whitespace)
|
|
180
|
+
4. Mark as `unresolved`
|
|
181
|
+
|
|
182
|
+
Two-key cache: comment file mtime + source content hash. Skip re-parsing when neither changed.
|
|
183
|
+
|
|
184
|
+
## SSE & File Watching (`sse.go` + `watcher.go`)
|
|
185
|
+
|
|
186
|
+
SSE broker manages two client sets:
|
|
187
|
+
|
|
188
|
+
- **Document stream clients**: receive `document-updated` and `document-added` events
|
|
189
|
+
- **Heartbeat clients**: keep-alive pings, manage auto-shutdown timer (1.5s grace after last client disconnects, production only)
|
|
190
|
+
|
|
191
|
+
File watcher uses `fsnotify` with 100ms debounce per file. On change: invalidate render cache → invalidate comment cache → broadcast SSE event.
|
|
192
|
+
|
|
193
|
+
## CLI (`cmd/readit/main.go`)
|
|
194
|
+
|
|
195
|
+
Subcommands:
|
|
196
|
+
|
|
197
|
+
- `readit <file.md> [flags]` — start server + open browser
|
|
198
|
+
- `readit list` — list files with comments (stdout)
|
|
199
|
+
- `readit show <file.md>` — print comments for file (stdout)
|
|
200
|
+
- `readit open <file.md>` — attach to running server or start new one
|
|
201
|
+
|
|
202
|
+
Flags:
|
|
203
|
+
|
|
204
|
+
- `--port` (default: random available)
|
|
205
|
+
- `--host` (default: `127.0.0.1`)
|
|
206
|
+
- `--no-open` (skip browser launch)
|
|
207
|
+
- `--clean` (clear existing comments)
|
|
208
|
+
- `--assets-dir` (override embedded assets)
|
|
209
|
+
- `--dev` (spawn Vite child process, proxy to it)
|
|
210
|
+
|
|
211
|
+
Server discovery: `~/.readit/server.json` with PID liveness check + HTTP health check. File lock (`server.lock`) prevents race conditions.
|
|
212
|
+
|
|
213
|
+
## Build & Dev Workflow
|
|
214
|
+
|
|
215
|
+
```makefile
|
|
216
|
+
dev: # Go spawns Vite child process, single command
|
|
217
|
+
build: # bun vite build → go build (embeds dist/)
|
|
218
|
+
test: # go test ./...
|
|
219
|
+
test-client: # bun run test
|
|
220
|
+
test-e2e: # playwright
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Dev mode: `make dev` → Go runs with `--dev`, spawns `bunx vite` on port 24678, proxies non-API requests. Ctrl+C kills both.
|
|
224
|
+
|
|
225
|
+
Production build: `make build` → Vite builds frontend into `dist/`, then `go build` embeds `dist/` into the binary.
|
|
226
|
+
|
|
227
|
+
## Types (`types.go`)
|
|
228
|
+
|
|
229
|
+
```go
|
|
230
|
+
type Comment struct {
|
|
231
|
+
ID string `json:"id"`
|
|
232
|
+
SelectedText string `json:"selectedText"`
|
|
233
|
+
Comment string `json:"comment"`
|
|
234
|
+
StartOffset int `json:"startOffset"`
|
|
235
|
+
EndOffset int `json:"endOffset"`
|
|
236
|
+
CreatedAt string `json:"createdAt"`
|
|
237
|
+
LineHint string `json:"lineHint,omitempty"`
|
|
238
|
+
AnchorConfidence string `json:"anchorConfidence,omitempty"`
|
|
239
|
+
AnchorPrefix string `json:"anchorPrefix,omitempty"`
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
type Heading struct {
|
|
243
|
+
ID string `json:"id"`
|
|
244
|
+
Text string `json:"text"`
|
|
245
|
+
Level int `json:"level"`
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
type FileState struct {
|
|
249
|
+
FilePath string
|
|
250
|
+
FileName string
|
|
251
|
+
Content []byte
|
|
252
|
+
RenderedHTML string
|
|
253
|
+
Headings []Heading
|
|
254
|
+
mu sync.Mutex
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
type Settings struct {
|
|
258
|
+
Version int `json:"version"`
|
|
259
|
+
FontFamily string `json:"fontFamily"`
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
JSON tags match the current API responses exactly.
|
|
264
|
+
|
|
265
|
+
## Go Dependencies
|
|
266
|
+
|
|
267
|
+
| Package | Purpose |
|
|
268
|
+
|---------|---------|
|
|
269
|
+
| `github.com/yuin/goldmark` | Markdown → HTML |
|
|
270
|
+
| `github.com/yuin/goldmark-highlighting/v2` | Chroma integration for goldmark |
|
|
271
|
+
| `github.com/alecthomas/chroma/v2` | Syntax highlighting (native Go) |
|
|
272
|
+
| `github.com/fsnotify/fsnotify` | Cross-platform file watching |
|
|
273
|
+
| `github.com/pkg/browser` | Cross-platform browser launch |
|
|
274
|
+
|
|
275
|
+
Five dependencies total. No HTTP framework, no CLI framework.
|
|
276
|
+
|
|
277
|
+
## Migration Path
|
|
278
|
+
|
|
279
|
+
1. Build Go server implementing the full API contract
|
|
280
|
+
2. Verify Svelte frontend works unchanged against Go server
|
|
281
|
+
3. Run existing E2E perf tests, compare against React/Svelte baselines
|
|
282
|
+
4. Remove `src/server.ts`, `src/cli.ts`, `src/lib/markdown-renderer.ts`, `src/lib/mermaid-worker.ts`, `src/lib/mermaid-renderer.ts`, `src/lib/comment-storage.ts`, `src/lib/anchor.ts`, related server-side code
|
|
283
|
+
5. Update `package.json` scripts to use Makefile
|
|
284
|
+
6. Remove server-side JS dependencies (`shiki`, `markdown-it`, `jsdom`, `mermaid`, `commander`)
|
package/e2e/comments.spec.ts
CHANGED
|
@@ -3,11 +3,7 @@ import * as os from "node:os";
|
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
4
|
import { expect, test } from "@playwright/test";
|
|
5
5
|
import { spawnCli } from "./utils/cli";
|
|
6
|
-
import {
|
|
7
|
-
addComment,
|
|
8
|
-
selectTextInArticle,
|
|
9
|
-
selectTextInIframe,
|
|
10
|
-
} from "./utils/selection";
|
|
6
|
+
import { addComment, selectTextInArticle } from "./utils/selection";
|
|
11
7
|
|
|
12
8
|
const FIXTURES_DIR = resolve(import.meta.dirname, "fixtures");
|
|
13
9
|
|
|
@@ -34,18 +30,13 @@ function cleanupCommentFile(sourcePath: string): void {
|
|
|
34
30
|
|
|
35
31
|
test.describe("Comment Creation", () => {
|
|
36
32
|
const sampleMdPath = resolve(FIXTURES_DIR, "sample.md");
|
|
37
|
-
const sampleHtmlPath = resolve(FIXTURES_DIR, "sample.html");
|
|
38
33
|
|
|
39
34
|
test.beforeEach(() => {
|
|
40
|
-
// Clean up any existing comment files before each test
|
|
41
35
|
cleanupCommentFile(sampleMdPath);
|
|
42
|
-
cleanupCommentFile(sampleHtmlPath);
|
|
43
36
|
});
|
|
44
37
|
|
|
45
38
|
test.afterEach(() => {
|
|
46
|
-
// Clean up after each test
|
|
47
39
|
cleanupCommentFile(sampleMdPath);
|
|
48
|
-
cleanupCommentFile(sampleHtmlPath);
|
|
49
40
|
});
|
|
50
41
|
|
|
51
42
|
test("adds comment to selected text in markdown document", async ({
|
|
@@ -57,7 +48,7 @@ test.describe("Comment Creation", () => {
|
|
|
57
48
|
await page.goto(url);
|
|
58
49
|
|
|
59
50
|
// Wait for document to load
|
|
60
|
-
const article = page.locator("article");
|
|
51
|
+
const article = page.locator("article#document-content");
|
|
61
52
|
await expect(article).toBeVisible();
|
|
62
53
|
|
|
63
54
|
// Select text in the article
|
|
@@ -68,55 +59,20 @@ test.describe("Comment Creation", () => {
|
|
|
68
59
|
const commentText = "This is my test comment";
|
|
69
60
|
await addComment(page, commentText);
|
|
70
61
|
|
|
71
|
-
// Verify: highlight exists
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
// Verify: highlight exists via CSS Custom Highlight API observability hook
|
|
63
|
+
await page.waitForFunction(
|
|
64
|
+
() => {
|
|
65
|
+
const h = (window as unknown as Record<string, unknown>)
|
|
66
|
+
.__readitHighlights as { commentIds: string[] } | undefined;
|
|
67
|
+
return h && h.commentIds.length > 0;
|
|
68
|
+
},
|
|
69
|
+
{ timeout: 10_000 },
|
|
70
|
+
);
|
|
75
71
|
|
|
76
|
-
// Verify
|
|
77
|
-
await expect(
|
|
78
|
-
} finally {
|
|
79
|
-
await cleanup();
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("adds comment to selected text in HTML document (iframe)", async ({
|
|
84
|
-
page,
|
|
85
|
-
}) => {
|
|
86
|
-
const { url, cleanup } = await spawnCli(sampleHtmlPath, { port: 4573 });
|
|
87
|
-
|
|
88
|
-
try {
|
|
89
|
-
await page.goto(url);
|
|
90
|
-
|
|
91
|
-
// Wait for iframe to load and its script to initialize
|
|
92
|
-
const iframe = page.frameLocator("iframe");
|
|
93
|
-
await expect(iframe.locator("body")).toBeVisible();
|
|
94
|
-
|
|
95
|
-
// Wait for iframe script to execute and send iframeReady
|
|
96
|
-
await page.waitForTimeout(500);
|
|
97
|
-
|
|
98
|
-
// Select text inside iframe - use test event which bypasses tree walking
|
|
99
|
-
// The test event directly sends offsets to the parent
|
|
100
|
-
const textToSelect = "testing text selection";
|
|
101
|
-
await selectTextInIframe(page, iframe, textToSelect);
|
|
102
|
-
|
|
103
|
-
// Verify pending highlight exists in iframe
|
|
104
|
-
const pendingMark = iframe.locator("mark[data-pending]");
|
|
105
|
-
await expect(pendingMark).toBeVisible({ timeout: 5000 });
|
|
72
|
+
// Verify the selected text is still visible in the article
|
|
73
|
+
await expect(article).toContainText(textToSelect);
|
|
106
74
|
|
|
107
|
-
//
|
|
108
|
-
const commentText = "Comment on HTML content";
|
|
109
|
-
await addComment(page, commentText);
|
|
110
|
-
|
|
111
|
-
// Wait for the comment to be saved via API and highlights to be applied
|
|
112
|
-
await page.waitForTimeout(500);
|
|
113
|
-
|
|
114
|
-
// Verify: highlight exists inside iframe with comment ID
|
|
115
|
-
const highlight = iframe.locator("mark[data-comment-id]").first();
|
|
116
|
-
await expect(highlight).toBeVisible();
|
|
117
|
-
await expect(highlight).toContainText(textToSelect);
|
|
118
|
-
|
|
119
|
-
// Verify: margin note shows the comment (in parent frame)
|
|
75
|
+
// Verify: margin note shows the comment
|
|
120
76
|
await expect(page.locator("body")).toContainText(commentText);
|
|
121
77
|
} finally {
|
|
122
78
|
await cleanup();
|
|
@@ -15,7 +15,7 @@ test.describe("Document Loading", () => {
|
|
|
15
15
|
await page.goto(url);
|
|
16
16
|
|
|
17
17
|
// Wait for document to load - use article scope to avoid header h1
|
|
18
|
-
const article = page.locator("article");
|
|
18
|
+
const article = page.locator("article#document-content");
|
|
19
19
|
await expect(article.locator("h1")).toContainText("Test Document");
|
|
20
20
|
|
|
21
21
|
// Verify paragraph content is rendered
|
|
@@ -29,26 +29,4 @@ test.describe("Document Loading", () => {
|
|
|
29
29
|
await cleanup();
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
|
-
|
|
33
|
-
test("loads HTML document in iframe", async ({ page }) => {
|
|
34
|
-
const { url, cleanup } = await spawnCli(
|
|
35
|
-
resolve(FIXTURES_DIR, "sample.html"),
|
|
36
|
-
{ port: 4571 },
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
await page.goto(url);
|
|
41
|
-
|
|
42
|
-
// Wait for iframe to exist
|
|
43
|
-
const iframe = page.frameLocator("iframe");
|
|
44
|
-
|
|
45
|
-
// Verify content inside iframe
|
|
46
|
-
await expect(iframe.locator("h1")).toContainText("Test Document");
|
|
47
|
-
await expect(iframe.locator("p").first()).toContainText(
|
|
48
|
-
"This is a paragraph for testing text selection",
|
|
49
|
-
);
|
|
50
|
-
} finally {
|
|
51
|
-
await cleanup();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
32
|
});
|
package/e2e/export.spec.ts
CHANGED
|
@@ -19,7 +19,7 @@ test.describe("Comment Export", () => {
|
|
|
19
19
|
await page.goto(url);
|
|
20
20
|
|
|
21
21
|
// Wait for document to load
|
|
22
|
-
const article = page.locator("article");
|
|
22
|
+
const article = page.locator("article#document-content");
|
|
23
23
|
await expect(article).toBeVisible();
|
|
24
24
|
|
|
25
25
|
// Add a comment
|
|
@@ -48,9 +48,9 @@ test.describe("Comment Export", () => {
|
|
|
48
48
|
expect(clipboardContent).toContain(textToSelect);
|
|
49
49
|
expect(clipboardContent).toContain(commentText);
|
|
50
50
|
|
|
51
|
-
// Verify it follows the prompt format (selected text + comment
|
|
52
|
-
expect(clipboardContent).
|
|
53
|
-
expect(clipboardContent).toContain("
|
|
51
|
+
// Verify it follows the prompt format (quoted selected text + comment)
|
|
52
|
+
expect(clipboardContent).toMatch(/"testing text selection"/);
|
|
53
|
+
expect(clipboardContent).toContain("This is my review comment");
|
|
54
54
|
} finally {
|
|
55
55
|
await cleanup();
|
|
56
56
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { expect, 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 the medium tier — most representative of real usage
|
|
11
|
+
const tier = TIERS[0];
|
|
12
|
+
|
|
13
|
+
test(`add-comment: ${tier.name} (${tier.lines} lines, ${tier.comments} comments)`, async ({
|
|
14
|
+
page,
|
|
15
|
+
}, testInfo) => {
|
|
16
|
+
const fixturePath = getFixturePath(tier);
|
|
17
|
+
const { url, cleanup } = await spawnPerfCli(fixturePath, { port: 4620 });
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
await page.goto(url);
|
|
21
|
+
await waitForHighlightCount(page, tier.comments);
|
|
22
|
+
await page.waitForTimeout(300);
|
|
23
|
+
|
|
24
|
+
// Capture actual highlight count as baseline (may differ from tier.comments)
|
|
25
|
+
const baselineCount = await page.evaluate(() => {
|
|
26
|
+
const h = (window as unknown as Record<string, unknown>)
|
|
27
|
+
.__readitHighlights as { commentIds: string[] } | undefined;
|
|
28
|
+
return h?.commentIds?.length ?? 0;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Find a text that isn't already highlighted — use a line near the end
|
|
32
|
+
const selectionText = await page.evaluate(() => {
|
|
33
|
+
const article = document.querySelector("article");
|
|
34
|
+
if (!article) throw new Error("Article not found");
|
|
35
|
+
|
|
36
|
+
// Find paragraph text near the bottom of the document
|
|
37
|
+
const paragraphs = article.querySelectorAll("p");
|
|
38
|
+
const target = paragraphs[paragraphs.length - 2];
|
|
39
|
+
if (!target?.textContent) throw new Error("No paragraph found");
|
|
40
|
+
|
|
41
|
+
// Use first 30 chars
|
|
42
|
+
return target.textContent.slice(0, 30).trim();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Select text via custom event
|
|
46
|
+
await page.evaluate((text) => {
|
|
47
|
+
const article = document.querySelector("article");
|
|
48
|
+
if (!article) throw new Error("Article not found");
|
|
49
|
+
|
|
50
|
+
const walker = document.createTreeWalker(article, NodeFilter.SHOW_TEXT);
|
|
51
|
+
let currentOffset = 0;
|
|
52
|
+
|
|
53
|
+
while (walker.nextNode()) {
|
|
54
|
+
const textNode = walker.currentNode as Text;
|
|
55
|
+
const content = textNode.textContent || "";
|
|
56
|
+
const index = content.indexOf(text);
|
|
57
|
+
|
|
58
|
+
if (index !== -1) {
|
|
59
|
+
const startOffset = currentOffset + index;
|
|
60
|
+
const endOffset = startOffset + text.length;
|
|
61
|
+
window.dispatchEvent(
|
|
62
|
+
new CustomEvent("test:select-text", {
|
|
63
|
+
detail: { text, startOffset, endOffset },
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
currentOffset += content.length;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
throw new Error(`Text "${text}" not found`);
|
|
73
|
+
}, selectionText);
|
|
74
|
+
|
|
75
|
+
// Wait for comment input to appear
|
|
76
|
+
const textarea = page.locator(
|
|
77
|
+
'textarea[placeholder="Add your comment..."]',
|
|
78
|
+
);
|
|
79
|
+
await textarea.waitFor({ state: "visible", timeout: 10_000 });
|
|
80
|
+
|
|
81
|
+
// Fill in the comment
|
|
82
|
+
await textarea.fill("Performance benchmark comment");
|
|
83
|
+
|
|
84
|
+
// Mark start and click Add
|
|
85
|
+
const duration = await measureInteraction(
|
|
86
|
+
page,
|
|
87
|
+
"add-comment",
|
|
88
|
+
async () => {
|
|
89
|
+
await page.getByRole("button", { name: "Add" }).click();
|
|
90
|
+
},
|
|
91
|
+
async () => {
|
|
92
|
+
await page.waitForFunction((expected) => {
|
|
93
|
+
const h = (window as unknown as Record<string, unknown>)
|
|
94
|
+
.__readitHighlights as { commentIds: string[] } | undefined;
|
|
95
|
+
return (h?.commentIds?.length ?? 0) > expected;
|
|
96
|
+
}, baselineCount);
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
reportInteraction(
|
|
101
|
+
testInfo,
|
|
102
|
+
`add-comment: time to new highlight (${tier.name})`,
|
|
103
|
+
duration,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Verify the highlight actually appeared
|
|
107
|
+
const finalCount = await page.evaluate(() => {
|
|
108
|
+
const h = (window as unknown as Record<string, unknown>)
|
|
109
|
+
.__readitHighlights as { commentIds: string[] } | undefined;
|
|
110
|
+
return h?.commentIds?.length ?? 0;
|
|
111
|
+
});
|
|
112
|
+
expect(finalCount).toBeGreaterThan(tier.comments);
|
|
113
|
+
} finally {
|
|
114
|
+
await cleanup();
|
|
115
|
+
}
|
|
116
|
+
});
|