@youtyan/code-viewer 0.2.8 → 0.2.10

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/README.md CHANGED
@@ -7,17 +7,33 @@ Requires Node.js 20 or newer when installed from npm. Development uses
7
7
 
8
8
  ## Features
9
9
 
10
- - Browse repository files and folders in a persistent sidebar.
11
- - View git diffs with unified or split layout, lazy loading, and viewed-file state.
12
- - Browse commit history per branch and open any commit's changed files and diff, with shareable `/history?commit=<sha>` links.
13
- - Open files directly from the repository or diff view, including large generated files.
14
- - Preview Markdown with a table of contents, task lists, Mermaid diagrams, and Shiki code highlighting.
15
- - Preview browser-safe media and show metadata for binary files that cannot be rendered.
16
- - Switch the viewer UI between English and Japanese from Viewer Settings.
17
- - Browse SQLite, PostgreSQL, MySQL, Redis, and Elasticsearch with a built-in database viewer.
18
- - Read the built-in Help page for repository browsing, diffs, annotations, agent skills, and shortcuts.
19
- - Open repository folders in the OS file manager from localhost-only actions.
20
- - Upload files into worktree folders when upload is explicitly enabled.
10
+ - Browse repository files and folders in a persistent sidebar with live
11
+ worktree change updates over SSE.
12
+ - View git diffs with unified or split layout, lazy loading, viewed-file
13
+ state, ignore-whitespace and hide-tests toggles, and per-line "reference
14
+ pills" that copy `@path#start-end` for AI agents.
15
+ - Browse commit history per branch and open any commit's changed files and
16
+ diff, with shareable `/history?ref=<branch>&commit=<sha>` links.
17
+ - Open files directly from the repository or diff view, including large
18
+ generated files (virtualized source viewer with copy/open-full-view).
19
+ - Preview Markdown with a table of contents, task lists, Mermaid diagrams
20
+ (click to enlarge), and Shiki code highlighting.
21
+ - Preview browser-safe media and show metadata for binary files that cannot
22
+ be rendered.
23
+ - Find files and grep across the repository with `Ctrl+K` (file palette) and
24
+ `Ctrl+G` (text palette).
25
+ - Switch the viewer UI between English and Japanese from Viewer Settings —
26
+ the language toggle live-updates every screen including the datastore
27
+ viewer.
28
+ - Browse SQLite, PostgreSQL, MySQL, Redis, Elasticsearch, and S3-compatible
29
+ object storage (MinIO, LocalStack) with a built-in datastore viewer.
30
+ - Read the built-in Help page for repository browsing, diffs, annotations,
31
+ the datastore viewer, agent skills, and shortcuts.
32
+ - Open repository folders (and parent folders of files) in the OS file
33
+ manager, create folders, and trash/restore files from localhost-only
34
+ actions.
35
+ - Upload files into worktree folders. Uploads are enabled by default for
36
+ worktree targets; toggle them off from Viewer Settings.
21
37
 
22
38
  ## Usage
23
39
 
@@ -57,6 +73,16 @@ code-viewer
57
73
  The published CLI runs on Node.js 20 or newer. Bun is supported as a package
58
74
  runner through `bunx`, but the npm package no longer requires Bun at runtime.
59
75
 
76
+ Common options:
77
+
78
+ - `--cwd <dir>` — repository to view (default: current working directory).
79
+ - `--open` — open the printed URL in the default browser.
80
+ - `--port <port>` — bind to a specific port (default: pick a free port).
81
+ - `--scope-omit-dir <name>` — skip a directory under the worktree (repeatable;
82
+ overrides the Viewer Settings list for this session).
83
+ - `--version`, `-v` — print the installed version.
84
+ - `--help`, `-h` — print full CLI help.
85
+
60
86
  Arguments after options are passed to `git diff`. By default, code-viewer
61
87
  compares `HEAD` with the working tree.
62
88
 
@@ -70,7 +96,7 @@ code-viewer --cwd /path/to/repo --staged
70
96
  Open **Viewer Settings** in the header to change display options such as
71
97
  theme, layout, sidebar mode, font sizes, and UI language. The language setting
72
98
  translates the viewer chrome itself, including the Help page, settings labels,
73
- sidebars, history controls, and annotation panel labels.
99
+ sidebars, history controls, datastore viewer, and annotation panel labels.
74
100
 
75
101
  ## Repository View
76
102
 
@@ -81,36 +107,56 @@ metadata instead of dumping bytes as text.
81
107
 
82
108
  Markdown files use a dedicated preview tab. Relative links and images are
83
109
  resolved inside the repository, code blocks are highlighted with Shiki, and
84
- Mermaid diagrams are rendered lazily in the browser.
110
+ Mermaid diagrams are rendered lazily in the browser (click any diagram to
111
+ open it in a lightbox).
85
112
 
86
113
  Very large text files use a virtualized source viewer. Only visible rows are
87
114
  rendered, and the page includes controls to copy the full file or reopen it in
88
115
  the full non-virtual view.
89
116
 
90
- ## Uploads
91
-
92
- File uploads are available for the local worktree target. Git tree views remain
93
- read-only.
94
-
95
- Place `.code-viewer.json` at the repository root to configure repository scope
96
- defaults:
97
-
98
- ```json
99
- {
100
- "version": 1,
101
- "scope": {
102
- "omitDirs": ["node_modules", "dist", "build"]
103
- }
104
- }
105
- ```
106
-
107
- Repository scope settings control recursive repository browsing and search scope
108
- for the left tree, Ctrl+K file palette, and Ctrl+G grep palette. The in-app Scope
109
- Settings popover stores only a browser-local override in localStorage; edit
110
- `.code-viewer.json` directly for project defaults shared with the repository.
111
- Use `scope.omitDirs` for directories that should stay visible as skipped, and
112
- `scope.excludeNames` for file or directory names that should be hidden entirely.
113
- `.DS_Store` is hidden by default.
117
+ The worktree is watched and changes are pushed to every open tab over SSE so
118
+ files reload as you edit. The directory watcher is capped at 1024 directories
119
+ by default and can be tuned from Viewer Settings **File change watcher**
120
+ (range slider + numeric input, 16–65536); when the cap is hit the viewer
121
+ shows a banner so reloads are not silently missed.
122
+
123
+ Large repositories load folder children on demand. The sidebar remembers which
124
+ lazy-loaded folders you opened and re-expands them on the next reload, so the
125
+ tree state survives navigation and refresh.
126
+
127
+ ## Uploads and Scope Settings
128
+
129
+ File uploads are available for the local worktree target by default. Git tree
130
+ views remain read-only. Open **Viewer Settings** in the header to toggle
131
+ uploads off, edit the directories to skip while browsing/searching, and hide
132
+ files or directory names completely.
133
+
134
+ Scope settings control directory exclusions shared by the sidebar, Ctrl+K file
135
+ palette, Ctrl+G grep palette, the Datastores browser, and the file change
136
+ watcher the same list applies to all five. Everything you change in Viewer
137
+ Settings is saved on the server under `.code-viewer/settings.json` (no
138
+ separate project-level config file). `.DS_Store` and a broad set of
139
+ build/cache directories (`node_modules`, `dist`, `build`, `.next`, `.turbo`,
140
+ `.parcel-cache`, `.vite`, `.angular`, `.dart_tool`, `.venv`, …) are hidden by
141
+ default. Pass `--scope-omit-dir <name>` (repeatable) to override the omit
142
+ list on the command line for one session.
143
+
144
+ The viewer keeps its per-project state under `.code-viewer/` at the repository
145
+ root:
146
+
147
+ - `settings.json` — viewer chrome settings, scope overrides, annotation
148
+ panel/follow/TTS state.
149
+ - `view-state.json` — last opened file, scroll positions, viewed-file marks.
150
+ - `db-ui.json` — per-DB-tab UI state (column widths, related-panel size,
151
+ Rails FK toggle, S3 tooltip).
152
+ - `tabs.json` — datastore tab list, order, and drafts.
153
+ - `annotations.json` — AI Code Annotations.
154
+ - `query-history.json` — datastore query history.
155
+ - `db-snapshots.sqlite` — datastore snapshots and diff blobs.
156
+
157
+ The `.code-viewer` directory is tool-internal: it never shows up in the file
158
+ tree, searches, or diffs. Add it to `.gitignore` if you do not want to share
159
+ its contents through git.
114
160
 
115
161
  ## Datastore Viewer
116
162
 
@@ -119,97 +165,105 @@ browser-based viewer for exploring their contents.
119
165
 
120
166
  **SQLite** files (`.db`, `.sqlite`, `.sqlite3`, `.s3db`) are detected
121
167
  automatically by scanning the repository tree. **PostgreSQL**, **MySQL**,
122
- **Redis**, **Elasticsearch**, **MinIO**, and **LocalStack S3** services are detected from any
123
- `docker-compose.yml` (or `compose.yml`) found by the same recursive
124
- scan both the repository root and subdirectories are considered, so a
125
- single `code-viewer --cwd <root>` brings up every DB defined under that
126
- root. `.git/` and `node_modules/` are skipped. Services whose names
127
- collide across subdirectories are kept distinct via `docker:<service>@<relDir>`
128
- ids (cwd-direct compose files keep the historical `docker:<service>` id
129
- for backward compatibility). Redis support is read-only: browse DB 0–15,
130
- SCAN keys, and view values per type (string/hash/list as dedicated
131
- panes, set/zset/stream as raw JSON). Elasticsearch support is read-only
132
- too: list indices, view mappings, paginate docs with `search_after`, run
133
- lucene `q=` searches, and take snapshots / diffs over `_search` iteration.
134
- S3-compatible object storage support is read-only: browse buckets, search by
135
- prefix or filename, sort scanned objects by update time, and preview images,
136
- video, audio, PDFs, Markdown, HTML, and text files. Updated-time sorting is
137
- scoped to the objects scanned for the current prefix/search rather than a
138
- persistent whole-bucket index. HTML previews are rendered in a sandboxed
139
- `srcdoc` iframe; relative subresources inside the HTML are not rewritten.
140
- If the S3 service publishes a host port, code-viewer connects through
141
- `localhost:<port>`; otherwise it falls back to `docker exec <container> curl`
142
- against the service's container-local endpoint.
168
+ **Redis**, **Elasticsearch**, **MinIO**, and **LocalStack S3** services are
169
+ detected from any `docker-compose.yml`, `docker-compose.yaml`, `compose.yml`,
170
+ or `compose.yaml` found by the same recursive scan both the repository root
171
+ and subdirectories are considered, so a single `code-viewer --cwd <root>`
172
+ brings up every DB defined under that root. `.git/`, `.code-viewer/`, and
173
+ `node_modules/` are skipped, and discovery is capped at a few-level depth and
174
+ a few dozen services per scan to keep startup cheap.
175
+
176
+ Services whose names collide across subdirectories are kept distinct via
177
+ `docker:<service>@<relDir>` ids (cwd-direct compose files keep the historical
178
+ `docker:<service>` id for backward compatibility).
179
+
180
+ **Redis** support is read-only: browse DB 0–15, SCAN keys, and view values per
181
+ type (string/hash/list as dedicated panes, set/zset/stream as JSON views). It
182
+ also participates in snapshots and diffs.
183
+
184
+ **Elasticsearch** support is read-only: list indices, view mappings, paginate
185
+ docs with `search_after`, run lucene `q=` searches, and submit DSL queries to a
186
+ small allowlist of `_search` / `_count` / `_msearch` / `_explain` /
187
+ `_validate` / `_field_caps` / `_eql`. Snapshots and diffs over `_search`
188
+ iteration are supported.
189
+
190
+ **S3-compatible object storage** (MinIO, LocalStack) is read-only: browse
191
+ buckets as a folder tree, search by prefix or filename, sort scanned objects by
192
+ update time, and preview images, video, audio, PDFs, Markdown, HTML, and text
193
+ files. Updated-time sorting is scoped to the objects scanned for the current
194
+ prefix/search rather than a persistent whole-bucket index. HTML previews are
195
+ rendered in a sandboxed `srcdoc` iframe; relative subresources inside the HTML
196
+ are not rewritten. **LocalStack** falls back to `docker exec <container> curl`
197
+ against the container-local endpoint when the service does not publish a host
198
+ port; **MinIO** requires a published host port (add a `9000:9000` mapping) and
199
+ will refuse to browse otherwise.
143
200
 
144
201
  ### Browser UI
145
202
 
146
203
  Open Datastores in the global navigation to access:
147
204
 
148
- - **Multi-DB tabs** — open multiple databases side by side (each tab has
149
- its own sidebar, panes, and history). `+` adds an empty tab; `×` or
150
- middle-click closes one (the last tab is reset to empty instead of
151
- vanishing). Tabs persist in `.code-viewer/tabs.json` and survive
152
- reloads.
153
- - **Table browser** — paginated data grid with column sorting, text
154
- filtering, and CSV/JSON export.
155
- - **Query editor** execute read-only SQL with syntax highlighting.
156
- Results and history are saved and shared across tabs.
205
+ - **Multi-DB tabs** — open multiple databases side by side, with their own
206
+ sidebar, panes, and history. `+` adds an empty tab; `×` or middle-click
207
+ closes one (the last tab resets to empty instead of vanishing). Tabs can be
208
+ reordered by drag and drop and persist in `.code-viewer/tabs.json`.
209
+ - **PostgreSQL schema selector** — switch between schemas without reopening
210
+ the database.
211
+ - **Table browser** — paginated data grid with column sort, text filter, cell
212
+ copy, and CSV/JSON export (capped at 100,000 rows; export respects current
213
+ filter/sort).
214
+ - **Detail footer and related panel** — click any cell to open a resizable
215
+ detail footer; foreign-key cells open a related panel showing the
216
+ referenced or referencing rows, with multi-step drill-down breadcrumbs.
217
+ Cells that match the focused row are highlighted in both panels.
218
+ - **Rails FK inference toggle** — opt-in heuristic that adds virtual foreign
219
+ keys following Rails naming conventions (e.g. `user_id → users.id`) on top
220
+ of the database-declared FKs.
221
+ - **Query editor** — execute read-only SQL with syntax highlighting. The
222
+ allowlist depends on the engine (SQLite: `SELECT`, `PRAGMA`, `EXPLAIN`,
223
+ `WITH`; PostgreSQL and MySQL also accept `SHOW` and `DESCRIBE`, and
224
+ PostgreSQL queries run inside `BEGIN TRANSACTION READ ONLY`). Per-DB results
225
+ and history are saved and synced across tabs over SSE; the editor records
226
+ whether each entry came from the browser or the CLI.
157
227
  - **ER diagram** — auto-generated entity-relationship diagram showing
158
- foreign key relationships between tables.
159
- - **Global search** — full-text search across all tables and text columns.
160
- - **Snapshots & diffs** — take point-in-time snapshots of selected tables
161
- and compare any two snapshots to see inserted, updated, and deleted rows
162
- with full before/after values.
228
+ foreign-key relationships between tables.
229
+ - **Schema view** — table columns, indexes, foreign keys, triggers, and DDL.
230
+ - **Global search** — full-text search across all tables and text columns of
231
+ a database.
232
+ - **Snapshots and diffs** — take point-in-time snapshots of selected tables
233
+ (or Redis key spaces, or Elasticsearch indices) and compare any two
234
+ snapshots to see inserted, updated, and deleted rows with full before/after
235
+ values.
236
+ - **Datastore explorers** — first-class sidebars for Redis (DB / SCAN),
237
+ Elasticsearch (indices / mappings / docs), and S3 (folder tree, kind
238
+ badges) so the same Multi-DB tab UI works for non-SQL stores too.
163
239
 
164
240
  ### CLI
165
241
 
166
- AI agents can query databases and manage snapshots from the command line:
242
+ AI agents can read data and query history from the command line. The current
243
+ CLI ships `exec`, `list`, and `clear`; search, snapshot, and diff operations
244
+ are performed from the browser UI.
167
245
 
168
246
  ```sh
169
247
  code-viewer query exec --db data.db --sql "SELECT * FROM users LIMIT 10" \
170
248
  --title "Sample users" --body "Checking user data shape."
171
249
 
172
- code-viewer query search --db app.db --term "john@example.com"
250
+ code-viewer query exec --db app.db --sql "SELECT count(*) FROM orders" \
251
+ --max-rows 1 --no-save
173
252
 
174
- code-viewer query snapshot create --db app.db --tables users,orders \
175
- --note "Before migration"
253
+ code-viewer query list --db app.db --json
254
+ code-viewer query clear --db app.db
176
255
  ```
177
256
 
178
- `code-viewer query --help` shows all commands. `code-viewer query agent-help`
179
- prints a detailed guide for AI agents covering queries, search, snapshots,
180
- and diffs.
181
-
182
- ### Snapshot & Diff Workflow
183
-
184
- Snapshots capture the state of selected tables at a point in time. Diff any
185
- two snapshots to verify that a migration, test, or operation changed exactly
186
- what you expected:
187
-
188
- ```sh
189
- # 1. Snapshot before the operation
190
- code-viewer query snapshot create --db app.db --tables users --note "Before"
191
-
192
- # 2. (run the migration / test / script)
193
-
194
- # 3. Snapshot after
195
- code-viewer query snapshot create --db app.db --tables users --note "After"
196
-
197
- # 4. List snapshots to get IDs
198
- code-viewer query snapshot list --db app.db
199
-
200
- # 5. Compare
201
- code-viewer query diff tables --before snap-abc123 --after snap-def456
202
- code-viewer query diff rows --before snap-abc123 --after snap-def456 --table users
203
- ```
204
-
205
- Diffs are computed on demand — no pre-computation needed. The browser's
206
- Snapshot tab provides a visual interface for the same workflow.
257
+ `code-viewer query --help` shows all command syntax. `code-viewer query
258
+ agent-help` prints a longer guide for AI agents covering query shape and
259
+ conventions. Both `query` and `annotate` accept `--cwd <repo>` and
260
+ `--server <url>` for targeting a specific running server.
207
261
 
208
262
  ## AI Code Annotations
209
263
 
210
- AI coding agents (Claude Code, Codex, and similar CLI agents) can walk you
211
- through a codebase inside the viewer. An agent posts explanations for
212
- specific code locations with the `annotate` subcommand, and every open
264
+ AI coding agents (Claude Code, Codex, Cursor, Gemini, and similar CLI agents)
265
+ can walk you through a codebase inside the viewer. An agent posts explanations
266
+ for specific code locations with the `annotate` subcommand, and every open
213
267
  browser tab jumps to that location live — in the diff view when the file has
214
268
  changes in the current range, or in the source view otherwise:
215
269
 
@@ -223,6 +277,8 @@ code-viewer annotate add --file web-src/app.ts --line 9650 \
223
277
  code-viewer annotate add --after a-previous --file web-src/app.ts --line 9700 \
224
278
  --body "This inserted note now appears in the middle of the walkthrough."
225
279
  code-viewer annotate move a-late --before a-early
280
+ code-viewer annotate rename sess-abc --title "Renamed walkthrough"
281
+ code-viewer annotate edit a-id --body "Tightened wording."
226
282
  code-viewer annotate add-db --db app.db --table users --tab schema \
227
283
  --body "This table is the identity root for user-facing records."
228
284
  code-viewer annotate add-db --db app.db --table orders --tab data \
@@ -234,14 +290,20 @@ code-viewer annotate add-db --db app.db --tab query \
234
290
  ```
235
291
 
236
292
  The body is Markdown. Long bodies can be passed with `--body-file <path>` or
237
- piped through stdin. `code-viewer annotate --help` shows all commands,
238
- including `move`, `edit`, `list`, `delete <id>`, and `clear`. `add` and
293
+ piped through stdin (works for `add`, `add-db`, and `edit`).
294
+ `code-viewer annotate --help` shows all commands: `start`, `add`, `add-db`,
295
+ `move`, `edit`, `rename`, `list`, `delete <id>`, and `clear`. `add` and
239
296
  `add-db` accept `--before <id>`, `--after <id>`, or `--position <n>` when a
240
- note belongs somewhere other than the end. On the Datastores screen, the
241
- annotations panel also has a pin button that captures the current data grid,
242
- query editor, or global search state as a database annotation. For AI agents,
243
- `code-viewer annotate agent-help` prints a skill-style guide covering the
244
- workflow, conventions, and pitfalls for writing good walkthroughs.
297
+ note belongs somewhere other than the end, and `--title`, `--session <id>`, or
298
+ `--session-title <text>` for session targeting.
299
+
300
+ `add-db` accepts a wide set of DB-pane flags so the agent can pin the exact
301
+ view it is discussing: `--tab <data|schema|query|er|search|snapshot>`,
302
+ `--filter key=value` (repeatable), `--sort col:asc|desc`, `--row <n>`,
303
+ `--grid-search <text>`, `--sql <text>` or `--sql-file <path>` plus
304
+ `--run-query` and `--query-mode <run|explain>`, and `--search-term <text>`
305
+ with `--include-non-text` and `--run-search`. For AI agents,
306
+ `code-viewer annotate agent-help` prints a skill-style guide.
245
307
 
246
308
  Annotations are grouped into sessions and persisted in
247
309
  `.code-viewer/annotations.json` at the repository root, so the walkthrough
@@ -249,13 +311,18 @@ survives reloads and server restarts. The `.code-viewer` directory is
249
311
  tool-internal: it never shows up in the file tree, searches, or diffs. Add it
250
312
  to `.gitignore` if you do not want to share annotations through git.
251
313
 
252
- In the browser, the 💬 button in the header opens the annotation side panel.
253
- The current explanation is rendered at the top of the panel while the code
254
- stays visible next to it, with the annotated lines highlighted. The history
255
- below groups annotations by session; clicking an entry jumps back to its
256
- location, and entries and sessions can be deleted there too. The "follow"
257
- checkbox controls whether the tab jumps automatically when an agent adds a
258
- new annotation.
314
+ In the browser, the annotation icon in the header opens the side panel. The
315
+ current explanation is rendered at the top of the panel while the code stays
316
+ visible next to it, with the annotated lines highlighted. The history below
317
+ groups annotations by session; clicking an entry jumps back to its location,
318
+ and entries and sessions can be deleted there too. The "follow" checkbox
319
+ controls whether the tab jumps automatically when an agent adds a new
320
+ annotation. A built-in player can speak the current annotation aloud with
321
+ play/pause, previous/next, mute, and rate controls (TTS state is saved per
322
+ project).
323
+
324
+ A copy button on each annotation produces a paste-ready prompt block that
325
+ references the annotation by URL for sharing back into the originating agent.
259
326
 
260
327
  The `annotate` subcommand talks to the running server for the repository
261
328
  (discovered via `~/.cache/code-viewer/servers/`); start one with
@@ -281,11 +348,15 @@ open standard) that teach AI coding agents when and how to use
281
348
  ```sh
282
349
  npx -y @youtyan/code-viewer skill install # Claude Code (.claude/skills/)
283
350
  npx -y @youtyan/code-viewer skill install --agent codex,gemini # other agents
284
- npx -y @youtyan/code-viewer skill install --agent all # claude, codex, gemini, cursor, .agents
351
+ npx -y @youtyan/code-viewer skill install --agent all # claude, codex, gemini, cursor, agents (.agents/skills/)
285
352
  ```
286
353
 
287
- Or install it once for all projects with `--global` (`~/.claude/skills/`
288
- etc). Running the same command again updates an existing installation.
354
+ `--agent` accepts a comma-separated list of `claude`, `codex`, `gemini`,
355
+ `cursor`, `agents` (vendor-neutral `.agents/skills`), or `all`. Pass
356
+ `--global` to install into the agent's user-level skill directory
357
+ (`~/.claude/skills/`, `~/.codex/skills/`, …) instead of the current project,
358
+ and `--cwd <dir>` to target a specific repository. Running the same command
359
+ again updates an existing installation in place.
289
360
 
290
361
  ## Development
291
362
 
@@ -295,10 +366,11 @@ bun run verify
295
366
  bun run preview --cwd /path/to/repo
296
367
  ```
297
368
 
298
- `bun run preview` is the development runner. It rebuilds the browser bundle
299
- when browser source files change, restarts the preview server when
300
- `web-src/server/*.ts` changes, and keeps the URL stable on
301
- `http://127.0.0.1:64160/` unless you pass `--port <port>`.
369
+ `bun run preview` (and the alias `bun run dev`) is the development runner. It
370
+ rebuilds the browser bundle when browser source files change, restarts the
371
+ preview server when `web-src/server/*.ts` changes, and keeps the URL stable on
372
+ `http://127.0.0.1:64160/` unless you pass `--port <port>`. Use
373
+ `bun run preview:raw` to launch `preview.ts` directly without the dev watcher.
302
374
 
303
375
  Before releasing:
304
376