@youtyan/code-viewer 0.1.52 → 0.1.53

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
@@ -14,6 +14,7 @@ Requires Node.js 20 or newer when installed from npm. Development uses
14
14
  - Preview Markdown with a table of contents, task lists, Mermaid diagrams, and Shiki code highlighting.
15
15
  - Preview browser-safe media and show metadata for binary files that cannot be rendered.
16
16
  - Switch the viewer UI between English and Japanese from Viewer Settings.
17
+ - Browse SQLite, PostgreSQL, and MySQL databases with a built-in database viewer.
17
18
  - Read the built-in Help page for repository browsing, diffs, annotations, agent skills, and shortcuts.
18
19
  - Open repository folders in the OS file manager from localhost-only actions.
19
20
  - Upload files into worktree folders when upload is explicitly enabled.
@@ -111,6 +112,75 @@ Use `scope.omitDirs` for directories that should stay visible as skipped, and
111
112
  `scope.excludeNames` for file or directory names that should be hidden entirely.
112
113
  `.DS_Store` is hidden by default.
113
114
 
115
+ ## Database Viewer
116
+
117
+ code-viewer auto-discovers databases in your repository and provides a
118
+ browser-based viewer for exploring their contents.
119
+
120
+ **SQLite** files (`.db`, `.sqlite`, `.sqlite3`, `.s3db`) are detected
121
+ automatically by scanning the repository tree. **PostgreSQL** and **MySQL**
122
+ databases are detected from `docker-compose.yml` and connected through
123
+ Docker.
124
+
125
+ ### Browser UI
126
+
127
+ Open the database icon in the sidebar to access:
128
+
129
+ - **Table browser** — paginated data grid with column sorting, text
130
+ filtering, and CSV/JSON export.
131
+ - **Query editor** — execute read-only SQL with syntax highlighting.
132
+ Results and history are saved and shared across tabs.
133
+ - **ER diagram** — auto-generated entity-relationship diagram showing
134
+ foreign key relationships between tables.
135
+ - **Global search** — full-text search across all tables and text columns.
136
+ - **Snapshots & diffs** — take point-in-time snapshots of selected tables
137
+ and compare any two snapshots to see inserted, updated, and deleted rows
138
+ with full before/after values.
139
+
140
+ ### CLI
141
+
142
+ AI agents can query databases and manage snapshots from the command line:
143
+
144
+ ```sh
145
+ code-viewer query exec --db data.db --sql "SELECT * FROM users LIMIT 10" \
146
+ --title "Sample users" --body "Checking user data shape."
147
+
148
+ code-viewer query search --db app.db --term "john@example.com"
149
+
150
+ code-viewer query snapshot create --db app.db --tables users,orders \
151
+ --note "Before migration"
152
+ ```
153
+
154
+ `code-viewer query --help` shows all commands. `code-viewer query agent-help`
155
+ prints a detailed guide for AI agents covering queries, search, snapshots,
156
+ and diffs.
157
+
158
+ ### Snapshot & Diff Workflow
159
+
160
+ Snapshots capture the state of selected tables at a point in time. Diff any
161
+ two snapshots to verify that a migration, test, or operation changed exactly
162
+ what you expected:
163
+
164
+ ```sh
165
+ # 1. Snapshot before the operation
166
+ code-viewer query snapshot create --db app.db --tables users --note "Before"
167
+
168
+ # 2. (run the migration / test / script)
169
+
170
+ # 3. Snapshot after
171
+ code-viewer query snapshot create --db app.db --tables users --note "After"
172
+
173
+ # 4. List snapshots to get IDs
174
+ code-viewer query snapshot list --db app.db
175
+
176
+ # 5. Compare
177
+ code-viewer query diff tables --before snap-abc123 --after snap-def456
178
+ code-viewer query diff rows --before snap-abc123 --after snap-def456 --table users
179
+ ```
180
+
181
+ Diffs are computed on demand — no pre-computation needed. The browser's
182
+ Snapshot tab provides a visual interface for the same workflow.
183
+
114
184
  ## AI Code Annotations
115
185
 
116
186
  AI coding agents (Claude Code, Codex, and similar CLI agents) can walk you
@@ -163,9 +233,9 @@ write concise Markdown explanations, and how to install the bundled agent skill.
163
233
 
164
234
  ### Agent Skill
165
235
 
166
- The package bundles an [Agent Skill](https://agentskills.io) (the SKILL.md
167
- open standard) that teaches AI coding agents when and how to use
168
- `annotate`. Install it into the current project:
236
+ The package bundles [Agent Skills](https://agentskills.io) (the SKILL.md
237
+ open standard) that teach AI coding agents when and how to use
238
+ `annotate`, `query`, and `snapshot`. Install them into the current project:
169
239
 
170
240
  ```sh
171
241
  npx -y @youtyan/code-viewer skill install # Claude Code (.claude/skills/)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@youtyan/code-viewer",
3
- "version": "0.1.52",
3
+ "version": "0.1.53",
4
4
  "description": "Local browser-based code and git diff viewer",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,102 @@
1
+ ---
2
+ name: code-viewer-snapshot
3
+ description: Use when taking database snapshots before/after an operation to verify what changed, diffing two points in time, or confirming a migration/test/feature modified the expected tables and rows. Triggers on "snapshot", "diff", "スナップショット", "差分", "before/after", "DBの変更を確認", "マイグレーション検証", "テスト前後の比較".
4
+ ---
5
+
6
+ # code-viewer snapshot
7
+
8
+ Take point-in-time snapshots of database tables and diff them to see
9
+ exactly what changed — inserted, updated, and deleted rows with full
10
+ before/after values. Use it to verify migrations, test runs, or any
11
+ operation that should modify the database in a predictable way.
12
+
13
+ ## When to use
14
+
15
+ - Verifying a migration added/removed the expected rows
16
+ - Confirming a test correctly modifies the database
17
+ - Debugging "what did that operation actually change?"
18
+ - Auditing data changes before and after a deploy or script
19
+
20
+ ## Requirements
21
+
22
+ - A code-viewer server must already be running for the repository
23
+ (the human starts it with: `code-viewer`). The CLI never starts one.
24
+ - Run from inside the repository, or pass `--cwd <repo>`.
25
+ - If `code-viewer` is not on PATH, prefix every command with
26
+ `npx -y @youtyan/code-viewer`.
27
+
28
+ ## Workflow
29
+
30
+ ### 1. Take a "before" snapshot
31
+
32
+ Specify which database and tables to capture. Always use `--tables` to
33
+ avoid scanning unnecessary tables.
34
+
35
+ ```sh
36
+ code-viewer query snapshot create --db app.db \
37
+ --tables users,orders \
38
+ --note "Before running user registration test"
39
+ ```
40
+
41
+ ### 2. Perform the operation
42
+
43
+ The human (or a test runner, migration script, etc.) modifies the database.
44
+
45
+ ### 3. Take an "after" snapshot
46
+
47
+ ```sh
48
+ code-viewer query snapshot create --db app.db \
49
+ --tables users,orders \
50
+ --note "After running user registration test"
51
+ ```
52
+
53
+ ### 4. Get snapshot IDs
54
+
55
+ ```sh
56
+ code-viewer query snapshot list --db app.db
57
+ ```
58
+
59
+ ### 5. View the diff
60
+
61
+ Compare table-level summary (which tables changed and how many rows):
62
+
63
+ ```sh
64
+ code-viewer query diff tables --before snap-abc123 --after snap-def456
65
+ ```
66
+
67
+ Drill into row-level changes for a specific table:
68
+
69
+ ```sh
70
+ code-viewer query diff rows --before snap-abc123 --after snap-def456 \
71
+ --table users
72
+ ```
73
+
74
+ The human can also view all snapshots and diffs in the browser's
75
+ Database > Snapshot tab.
76
+
77
+ ## Managing snapshots
78
+
79
+ ```sh
80
+ # Update a snapshot's note
81
+ code-viewer query snapshot note --id snap-abc123 --note "Updated note"
82
+
83
+ # Delete a snapshot
84
+ code-viewer query snapshot delete --id snap-abc123
85
+ ```
86
+
87
+ ## Guidelines
88
+
89
+ - Always specify `--tables` — snapshotting every table wastes time.
90
+ - Write meaningful `--note` values — the human uses them to tell
91
+ snapshots apart.
92
+ - Take both snapshots against the same `--db` and `--tables`.
93
+ - For large tables, the snapshot captures all rows — be mindful of
94
+ database size.
95
+ - The diff is computed on demand, not stored — you can diff any two
96
+ snapshots of the same database.
97
+
98
+ ## Full reference
99
+
100
+ ```sh
101
+ code-viewer query agent-help
102
+ ```