@youtyan/code-viewer 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +389 -13
- package/dist/code-viewer.js +15568 -9512
- package/package.json +1 -1
- package/skills/code-viewer-query/SKILL.md +159 -14
- package/skills/code-viewer-snapshot/SKILL.md +59 -2
- package/web/app.js +771 -147
- package/web/index.html +1 -1
- package/web/style.css +12 -0
package/README.md
CHANGED
|
@@ -40,14 +40,21 @@ Requires Node.js 20 or newer when installed from npm. Development uses
|
|
|
40
40
|
toggled by the 🩺 icon in the header): runtime (Node / Bun / ABI),
|
|
41
41
|
`@youtyan/code-viewer` version and execution origin (npx cache vs
|
|
42
42
|
local), SQLite driver and snapshot store, Git, discovery summary,
|
|
43
|
+
per-source datastore connectivity (each discovered SQLite / docker
|
|
44
|
+
SQL / Redis / Elasticsearch / S3 source gets one row with a 2s
|
|
45
|
+
minimal-read probe; failure rows include a paste-safe retry hint),
|
|
43
46
|
Docker / Compose health (config dry-parse + `compose ps` per service),
|
|
44
47
|
and the listening port. Useful when `npx` cache mismatch (e.g.
|
|
45
|
-
`NODE_MODULE_VERSION` errors) needs a remediation hint
|
|
48
|
+
`NODE_MODULE_VERSION` errors) needs a remediation hint, or when a
|
|
49
|
+
docker compose datastore is discovered but unreachable.
|
|
46
50
|
- Open repository folders (and parent folders of files) in the OS file
|
|
47
51
|
manager, create folders, and trash/restore files from localhost-only
|
|
48
52
|
actions.
|
|
49
53
|
- Upload files into worktree folders. Uploads are enabled by default for
|
|
50
54
|
worktree targets; toggle them off from Viewer Settings.
|
|
55
|
+
- Expose a local, read-only MCP endpoint (`/_mcp`) on the running server so
|
|
56
|
+
AI agents can call status, file, search, and datastore tools directly
|
|
57
|
+
over JSON-RPC instead of spawning CLI subprocesses.
|
|
51
58
|
|
|
52
59
|
## Usage
|
|
53
60
|
|
|
@@ -284,43 +291,377 @@ Open Datastores in the global navigation to access:
|
|
|
284
291
|
|
|
285
292
|
### CLI
|
|
286
293
|
|
|
287
|
-
AI agents can run read-only queries, search
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
294
|
+
AI agents can run read-only queries, search across tables, and capture
|
|
295
|
+
snapshots / diffs from the command line. Query results are written to the
|
|
296
|
+
per-repository history visible in the browser; search results are returned
|
|
297
|
+
by the CLI and mirror the browser Search tab; snapshots are stored in the
|
|
298
|
+
snapshot store. The same operations are available in the browser's
|
|
299
|
+
Datastores tab (Query History, Search, and Snapshot tabs).
|
|
291
300
|
|
|
292
301
|
```sh
|
|
302
|
+
# Discover datastore ids the running server has detected (SQLite files plus
|
|
303
|
+
# any PostgreSQL / MySQL / Redis / Elasticsearch / S3 services from a nearby
|
|
304
|
+
# docker-compose). Use the printed id as --db on every other command.
|
|
305
|
+
code-viewer query sources --json
|
|
306
|
+
# Or skip composing the next SQL call yourself: --commands prints
|
|
307
|
+
# shell-pasteable schema/exec lines for SQL sources, plus paste-safe
|
|
308
|
+
# `list --db ... --json` and `snapshot list --db ... --json` so you can
|
|
309
|
+
# step into the existing query history and snapshot store without
|
|
310
|
+
# rebuilding those commands. Redis sources get
|
|
311
|
+
# `redis databases / redis keys` lines, Elasticsearch sources get
|
|
312
|
+
# `elasticsearch indices / elasticsearch docs` lines, and S3 sources get
|
|
313
|
+
# `s3 buckets / s3 objects` lines with `--bucket <bucket-name>` as a
|
|
314
|
+
# placeholder. Every emitted SQL command line pins --server '<url>' to the
|
|
315
|
+
# same server URL this invocation resolved, so pasting them elsewhere
|
|
316
|
+
# never silently re-runs auto-discovery. --json and --commands are
|
|
317
|
+
# mutually exclusive. Notice/comment metadata is collapsed to one line
|
|
318
|
+
# so copied command blocks stay intact.
|
|
319
|
+
code-viewer query sources --commands
|
|
320
|
+
|
|
321
|
+
# Introspect tables and columns without writing dialect-specific SQL.
|
|
322
|
+
# `query schema --json` adds paste-safe `columnsCommand` / `ddlCommand` fields
|
|
323
|
+
# to every tables[] element (each pins --server and single-quotes the db /
|
|
324
|
+
# schema / table) so AI/human can drill into a specific table without
|
|
325
|
+
# rebuilding the call.
|
|
326
|
+
code-viewer query schemas --db docker:pg-svc --json
|
|
327
|
+
code-viewer query schema --db app.db --json
|
|
328
|
+
code-viewer query schema --db docker:pg-svc --schema analytics --with-columns --json
|
|
329
|
+
code-viewer query columns --db app.db --table users --json
|
|
330
|
+
code-viewer query ddl --db app.db --table users
|
|
331
|
+
|
|
293
332
|
code-viewer query exec --db data.db --sql "SELECT * FROM users LIMIT 10" \
|
|
294
333
|
--title "Sample users" --body "Checking user data shape."
|
|
334
|
+
code-viewer query exec --db docker:pg-svc --schema analytics \
|
|
335
|
+
--sql "SELECT * FROM events LIMIT 10"
|
|
295
336
|
|
|
296
337
|
code-viewer query exec --db app.db --sql "SELECT count(*) FROM orders" \
|
|
297
338
|
--max-rows 1 --no-save
|
|
298
339
|
|
|
340
|
+
# Show saved query history. `list --json` enriches each entries[] element
|
|
341
|
+
# with a paste-safe `replayCommand` — `code-viewer query --server '<url>'
|
|
342
|
+
# exec --db '<dbId>' [--schema '<schema>'] --sql '<sql>' [--title '<title>']
|
|
343
|
+
# --no-save` — so AI/human can re-run a past query without rebuilding the
|
|
344
|
+
# call. server URL / dbId / schema / sql / title are POSIX single-quoted;
|
|
345
|
+
# `--no-save` is fixed so replay does not re-pollute history (drop it if you
|
|
346
|
+
# do want the replay saved).
|
|
299
347
|
code-viewer query list --db app.db --json
|
|
300
348
|
code-viewer query clear --db app.db
|
|
349
|
+
# PostgreSQL multi-schema query history: keep list/clear scoped to one schema.
|
|
350
|
+
code-viewer query list --db docker:pg-svc --schema analytics --json
|
|
351
|
+
code-viewer query clear --db docker:pg-svc --schema analytics
|
|
301
352
|
|
|
302
|
-
|
|
303
|
-
|
|
353
|
+
# Locate a value across every table (default: text-like columns only).
|
|
354
|
+
# Blocks until the scan finishes or --timeout (default 60s) expires.
|
|
355
|
+
code-viewer query search --db app.db --term "needle@example.com" --json
|
|
356
|
+
code-viewer query search --db app.db --term "needle@example.com" \
|
|
357
|
+
--tables users,orders --max-hits 20 --include-non-text --json
|
|
304
358
|
|
|
305
359
|
code-viewer query snapshot create --db app.db --tables users,orders \
|
|
306
360
|
--note "Before user registration test"
|
|
361
|
+
# The no-wait output also prints a paste-safe "Poll with: ..." line that
|
|
362
|
+
# pins --server '<url>' and single-quotes db/schema, so AI/human paste never
|
|
363
|
+
# silently falls back to auto-discovery. The same string is available as a
|
|
364
|
+
# pollCommand field in --json ack output.
|
|
365
|
+
# Block until the snapshot finishes (default --timeout 120s) and emit the
|
|
366
|
+
# final meta as JSON — handy when an AI agent needs the snapshot id without
|
|
367
|
+
# polling snapshot list separately.
|
|
368
|
+
code-viewer query snapshot create --db app.db --tables users,orders \
|
|
369
|
+
--note "Before user registration test" --wait --json
|
|
370
|
+
# `snapshot list --json` enriches each snapshots[] element with paste-safe
|
|
371
|
+
# `deleteCommand` and `noteCommand` fields. Each pins --server '<url>' and
|
|
372
|
+
# single-quotes the snapshot id; `noteCommand` quotes the current note as-is
|
|
373
|
+
# so AI/human can paste and edit the value to update.
|
|
307
374
|
code-viewer query snapshot list --db app.db --json
|
|
375
|
+
# PostgreSQL multi-schema: pin both create and list to the same schema so
|
|
376
|
+
# the before/after pair and --wait polling stay scoped to that schema.
|
|
377
|
+
code-viewer query snapshot create --db docker:pg-svc --schema analytics \
|
|
378
|
+
--tables events --note "Before backfill" --wait --json
|
|
379
|
+
code-viewer query snapshot list --db docker:pg-svc --schema analytics --json
|
|
308
380
|
code-viewer query snapshot note --id snap-abc123 --note "Updated context"
|
|
309
381
|
code-viewer query snapshot delete --id snap-abc123
|
|
310
382
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
code-viewer query diff
|
|
315
|
-
code-viewer query diff
|
|
316
|
-
|
|
383
|
+
# diff tables prints per-table summary lines plus a paste-safe "# diff rows: ..."
|
|
384
|
+
# hint per table, and --json adds a diffRowsCommand field to each tables[] element
|
|
385
|
+
# so AI/human can copy the exact row-detail command without rebuilding it.
|
|
386
|
+
code-viewer query diff tables --before snap-abc123 --after snap-def456 --json
|
|
387
|
+
code-viewer query diff rows --before snap-abc123 --after snap-def456 \
|
|
388
|
+
--table users --json
|
|
317
389
|
```
|
|
318
390
|
|
|
391
|
+
`query exec` prints pretty JSON with `dbId`, `columns`, `columnTypes`, `rows`,
|
|
392
|
+
`rowCount`, `truncated`, `elapsedMs`, and optional `schema` / `executedSql`.
|
|
393
|
+
Check `truncated` before treating the result as complete.
|
|
394
|
+
|
|
319
395
|
`code-viewer query --help` shows all command syntax. `code-viewer query
|
|
320
396
|
agent-help` prints a longer guide for AI agents covering query shape and
|
|
321
397
|
conventions. Both `query` and `annotate` accept `--cwd <repo>` and
|
|
322
398
|
`--server <url>` for targeting a specific running server.
|
|
323
399
|
|
|
400
|
+
For discovered Redis sources, `code-viewer query redis` exposes the same
|
|
401
|
+
read-only endpoints the browser's Datastores tab uses, so AI agents and
|
|
402
|
+
shell scripts can look inside without opening a browser. The CLI calls
|
|
403
|
+
the existing `/_db/redis/databases`, `/_db/redis/keys`, and
|
|
404
|
+
`/_db/redis/value` routes (writes stay browser-only):
|
|
405
|
+
|
|
406
|
+
```sh
|
|
407
|
+
# List the 16 logical DBs and their key counts.
|
|
408
|
+
code-viewer query redis databases --db docker:redis-svc --json
|
|
409
|
+
|
|
410
|
+
# SCAN-style key paging — re-issue with the returned nextCursor until "0".
|
|
411
|
+
code-viewer query redis keys --db docker:redis-svc --db-index 0 \
|
|
412
|
+
--pattern '*' --count 500 --json
|
|
413
|
+
|
|
414
|
+
# Read a single key's value. Binary content surfaces as binaryBase64.
|
|
415
|
+
code-viewer query redis value --db docker:redis-svc --db-index 0 \
|
|
416
|
+
--key sample:key --json
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Default text output is tab-separated (`index<TAB>keyCount` for
|
|
420
|
+
databases, `name<TAB>type` for keys). For `keys` a non-terminal cursor
|
|
421
|
+
appears as a trailing `# nextCursor: <cursor>` line so pagination needs
|
|
422
|
+
no JSON parsing; 0 keys prints `no redis keys` to stderr and exits 0.
|
|
423
|
+
`value`'s default output is the `RedisValue` payload as pretty JSON;
|
|
424
|
+
`--json` wraps the same payload in the full `RedisValueResponse`
|
|
425
|
+
(dbId / dbIndex / key included).
|
|
426
|
+
|
|
427
|
+
For discovered Elasticsearch sources, `code-viewer query elasticsearch`
|
|
428
|
+
exposes the same read-only endpoints the browser's Datastores tab uses.
|
|
429
|
+
The CLI calls the existing `/_db/elasticsearch/indices`, `/mapping`,
|
|
430
|
+
`/docs`, and `/doc` routes (writes stay browser-only):
|
|
431
|
+
|
|
432
|
+
```sh
|
|
433
|
+
# List indices: name, doc count, byte size, health.
|
|
434
|
+
code-viewer query elasticsearch indices --db docker:es-svc --json
|
|
435
|
+
|
|
436
|
+
# Inspect a single index's mapping (field types / nested properties).
|
|
437
|
+
code-viewer query elasticsearch mapping --db docker:es-svc \
|
|
438
|
+
--index sample-index --json
|
|
439
|
+
|
|
440
|
+
# Search documents with a Lucene query; --size caps hits, --search-after
|
|
441
|
+
# pages by feeding back the previous response's lastSort JSON array.
|
|
442
|
+
code-viewer query elasticsearch docs --db docker:es-svc \
|
|
443
|
+
--index sample-index --q 'status:active' --size 10 --json
|
|
444
|
+
code-viewer query elasticsearch docs --db docker:es-svc \
|
|
445
|
+
--index sample-index --q 'status:active' --size 10 \
|
|
446
|
+
--search-after '[1700000000000,"abc"]' --json
|
|
447
|
+
|
|
448
|
+
# Read a single document by id.
|
|
449
|
+
code-viewer query elasticsearch doc --db docker:es-svc \
|
|
450
|
+
--index sample-index --id sample-id --json
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Default text output is tab-separated:
|
|
454
|
+
`name<TAB>docCount<TAB>sizeBytes<TAB>health` for `indices`,
|
|
455
|
+
`_id<TAB>_score` per hit for `docs` (followed by `# lastSort: <json>` and
|
|
456
|
+
`# totalHits: <n> (returned <k>)` trailing lines so paging needs no JSON
|
|
457
|
+
parsing). `mapping` and `doc` default to pretty JSON of the inner payload
|
|
458
|
+
(`EsMapping` and `_source`). 0 hits on `docs` prints `no elasticsearch
|
|
459
|
+
hits` to stderr (exit 0); a missing `doc` id prints
|
|
460
|
+
`not found: <index>/<id>` to stderr (exit 0). `--json` always emits the
|
|
461
|
+
full server response envelope.
|
|
462
|
+
|
|
463
|
+
For discovered S3 sources, `code-viewer query s3` exposes the same
|
|
464
|
+
read-only endpoints the browser's Datastores tab uses. The CLI calls the
|
|
465
|
+
existing `/_db/s3/buckets`, `/objects`, `/folder`, `/head`, and `/text`
|
|
466
|
+
routes (writes and raw byte streams stay browser-only):
|
|
467
|
+
|
|
468
|
+
```sh
|
|
469
|
+
# List buckets in the source.
|
|
470
|
+
code-viewer query s3 buckets --db docker:s3-svc --json
|
|
471
|
+
|
|
472
|
+
# List objects in a bucket. --mode prefix walks --prefix; --mode contains
|
|
473
|
+
# scans for --q across keys/basenames. Use --token to page.
|
|
474
|
+
code-viewer query s3 objects --db docker:s3-svc --bucket sample-bucket \
|
|
475
|
+
--prefix logs/ --limit 50 --json
|
|
476
|
+
|
|
477
|
+
# Walk one folder level (delimiter "/") — folders and files separately.
|
|
478
|
+
code-viewer query s3 folder --db docker:s3-svc --bucket sample-bucket \
|
|
479
|
+
--prefix logs/ --json
|
|
480
|
+
|
|
481
|
+
# Object metadata only (size / contentType / etag / updatedAt).
|
|
482
|
+
code-viewer query s3 head --db docker:s3-svc --bucket sample-bucket \
|
|
483
|
+
--key logs/sample.json --json
|
|
484
|
+
|
|
485
|
+
# Preview a text-shaped object's body (server caps at 512KiB and sets
|
|
486
|
+
# truncated=true when it had to cut). Non-text keys return HTTP 415.
|
|
487
|
+
code-viewer query s3 text --db docker:s3-svc --bucket sample-bucket \
|
|
488
|
+
--key logs/sample.json
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Default text output is tab-separated:
|
|
492
|
+
`name<TAB>createdAt-or-"?"` for `buckets`,
|
|
493
|
+
`key<TAB>sizeBytes<TAB>updatedAt-or-"?"<TAB>contentType-or-"?"` per object
|
|
494
|
+
for `objects` (with `# nextToken: <token>` / `# scanLimitReached: true`
|
|
495
|
+
trailing lines when the server returned them), and `DIR<TAB><prefix>` /
|
|
496
|
+
`OBJ<TAB><key><TAB><sizeBytes>` rows for `folder`. 0 hits on `objects`
|
|
497
|
+
prints `no s3 objects` to stderr (exit 0); an empty `folder` listing
|
|
498
|
+
prints `no s3 folder entries` to stderr (exit 0). `head` defaults to
|
|
499
|
+
pretty JSON of `S3ObjectHeadResponse`. `text` prints the object body to
|
|
500
|
+
stdout and adds `text truncated` to stderr when the server flagged
|
|
501
|
+
truncation. `--json` always emits the full server response envelope.
|
|
502
|
+
|
|
503
|
+
AI agents who don't yet know which subcommand they need can run
|
|
504
|
+
`code-viewer agent-help` once. It prints a short index of the seven
|
|
505
|
+
AI-facing entry points (`status`, `query`, `annotate`, `search`,
|
|
506
|
+
`file`, `skill`, `doctor`) with the exact `code-viewer <name>
|
|
507
|
+
agent-help` command for each full guide. The index runs without any
|
|
508
|
+
preflight, so it works even before SQLite or a running server is set
|
|
509
|
+
up.
|
|
510
|
+
|
|
511
|
+
### Workspace status CLI
|
|
512
|
+
|
|
513
|
+
`code-viewer status` prints a one-shot snapshot of the current repo so
|
|
514
|
+
an AI agent (or you) can orient yourself in a single call: current
|
|
515
|
+
branch, remote URL, every file that differs from HEAD (staged +
|
|
516
|
+
unstaged + untracked), the staged subset, the most recent commits, and
|
|
517
|
+
a paste-safe shortlist of follow-up `code-viewer` commands. It runs
|
|
518
|
+
locally over `git` — no running server, no SQLite preflight — so it is
|
|
519
|
+
safe to call as the first command after entering any repository.
|
|
520
|
+
|
|
521
|
+
```sh
|
|
522
|
+
# Human-readable summary.
|
|
523
|
+
code-viewer status
|
|
524
|
+
|
|
525
|
+
# Structured payload for agents.
|
|
526
|
+
code-viewer status --json
|
|
527
|
+
|
|
528
|
+
# Override the ref / depth used for "recent commits".
|
|
529
|
+
code-viewer status --ref main --limit 20 --json
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
The `nextCommands` field pins `--server '<url>'` automatically for
|
|
533
|
+
server-backed follow-ups when a code-viewer server is registered for
|
|
534
|
+
the repo; local follow-ups stay bare. With no server, the snapshot
|
|
535
|
+
itself still succeeds.
|
|
536
|
+
|
|
537
|
+
### Code search CLI
|
|
538
|
+
|
|
539
|
+
`code-viewer search code` exposes the running server's `/_grep`
|
|
540
|
+
endpoint — the same engine that powers the browser's `Ctrl+G` palette —
|
|
541
|
+
to the command line for AI agents and shell scripts. The search uses
|
|
542
|
+
ripgrep when available and falls back to git grep / fixed-string
|
|
543
|
+
scanning, honours the same scope rules as the UI (`.git`,
|
|
544
|
+
`.code-viewer`, scope-omit directories filtered out), and can target a
|
|
545
|
+
git ref instead of the worktree.
|
|
546
|
+
|
|
547
|
+
```sh
|
|
548
|
+
# default: fixed-string search across the worktree, plain text output.
|
|
549
|
+
code-viewer search code --term "TODO"
|
|
550
|
+
|
|
551
|
+
# JSON output: { ref, engine, truncated, matches[{path,line,column,preview}] }.
|
|
552
|
+
# Prefer --json from agents — column / engine / truncated drive follow-up logic.
|
|
553
|
+
code-viewer search code --term "TODO" --json
|
|
554
|
+
|
|
555
|
+
# extended-regex search, restricted to two subtrees, on the `main` ref.
|
|
556
|
+
code-viewer search code --term "fn handler" --regex \
|
|
557
|
+
--path src --path tests --ref main --json
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Default text output is `path:line:column<TAB>preview`, one line per
|
|
561
|
+
match. An empty result prints `no matches` to stderr and exits 0.
|
|
562
|
+
Parse errors and unreachable servers exit 1. `--max` accepts a positive
|
|
563
|
+
integer up to the server's hard cap; `truncated=true` in the JSON
|
|
564
|
+
response means more matches exist beyond the cap. Run
|
|
565
|
+
`code-viewer search agent-help` for the full AI-agent guide.
|
|
566
|
+
|
|
567
|
+
`code-viewer search files` is the sister command for **filename**
|
|
568
|
+
lookups — the CLI mirror of the browser's `Ctrl+K` palette. It calls
|
|
569
|
+
`/_files` for the ref's full tree, then ranks paths with the same
|
|
570
|
+
`fuzzy + glob` algorithm the palette uses. `--term` auto-switches
|
|
571
|
+
between modes: bare words (e.g. `"auth"`, `"userId"`) use fuzzy
|
|
572
|
+
ranking; patterns containing `*` or `?` (e.g. `"src/**/*.test.ts"`) use
|
|
573
|
+
glob matching, and the mode used is reported in `--json`. The `.git`,
|
|
574
|
+
`.code-viewer`, and scope-omit directories are filtered out just like in
|
|
575
|
+
the palette.
|
|
576
|
+
|
|
577
|
+
```sh
|
|
578
|
+
# Fuzzy search across the worktree, top 50 paths printed one per line.
|
|
579
|
+
code-viewer search files --term "userId"
|
|
580
|
+
|
|
581
|
+
# Glob: ranked JSON with score / ranges / mode for AI agents.
|
|
582
|
+
code-viewer search files --term "src/**/*.test.ts" --max 200 --json
|
|
583
|
+
|
|
584
|
+
# Look at a specific ref instead of the worktree.
|
|
585
|
+
code-viewer search files --term "config" --ref main --json
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
Default text output is one path per line, best first. An empty result
|
|
589
|
+
prints `no matching files` to stderr and exits 0. `--json` emits a
|
|
590
|
+
ranked payload `{ ref, generation, query, mode, truncated,
|
|
591
|
+
candidateTruncated, totalCandidates, totalMatches,
|
|
592
|
+
matches[{ path, score, ranges }] }`. `truncated` means the ranked
|
|
593
|
+
matches were sliced by `--max`; `candidateTruncated` means the server
|
|
594
|
+
file-list cap was reached before ranking. The default `--max` is `50`
|
|
595
|
+
(intentionally smaller than `search code` so the result fits an AI
|
|
596
|
+
agent's context window); raise it up to the server-side cap when needed.
|
|
597
|
+
|
|
598
|
+
### File inspect CLI
|
|
599
|
+
|
|
600
|
+
After `search` locates a path, `code-viewer file` drills into it
|
|
601
|
+
from git refs or the worktree. The CLI reuses the same read paths the
|
|
602
|
+
browser uses for the Blame, History, and Diff tabs and the source viewer,
|
|
603
|
+
so output matches the on-screen views. **No running code-viewer server is
|
|
604
|
+
required** — these commands run locally, which makes them safe to use
|
|
605
|
+
before the server has started (or from CI).
|
|
606
|
+
|
|
607
|
+
```sh
|
|
608
|
+
# "Who wrote this line?" — porcelain blame for a path, JSON DTO output.
|
|
609
|
+
code-viewer file blame --path src/sample.ts --json
|
|
610
|
+
|
|
611
|
+
# Force a committed-only blame against an explicit ref.
|
|
612
|
+
code-viewer file blame --path src/sample.ts --base HEAD --ref main --json
|
|
613
|
+
|
|
614
|
+
# "What changed on this path recently?" — paginated commit log.
|
|
615
|
+
code-viewer file history --path src/sample.ts --limit 10 --json
|
|
616
|
+
code-viewer file history --path src/sample.ts --query "author:tester" --json
|
|
617
|
+
|
|
618
|
+
# Read the file (or a line range) as of a ref. AI-friendly JSON output
|
|
619
|
+
# includes totalLines / complete so the caller knows what was sliced.
|
|
620
|
+
code-viewer file show --path src/sample.ts --json
|
|
621
|
+
code-viewer file show --path src/sample.ts --start 100 --end 150 --json
|
|
622
|
+
code-viewer file show --path src/sample.ts --ref main --json
|
|
623
|
+
|
|
624
|
+
# Unified diff for one path. Defaults to HEAD..worktree and a preview cap
|
|
625
|
+
# (hunks/lines); pass --full for the entire diff.
|
|
626
|
+
code-viewer file diff --path src/sample.ts --json
|
|
627
|
+
code-viewer file diff --path src/sample.ts --from HEAD~1 --to HEAD --full --json
|
|
628
|
+
code-viewer file diff --path new_sample.ts --untracked --json
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
Default (non-`--json`) output is tab-separated and easy to grep:
|
|
632
|
+
|
|
633
|
+
- `blame` — `<line><TAB><shortSha or "worktree"><TAB><summary>`. Lines
|
|
634
|
+
with uncommitted edits show `worktree` and `<uncommitted>`.
|
|
635
|
+
- `history` — `<shortSha><TAB><whenISO><TAB><author><TAB><subject>`.
|
|
636
|
+
A path with zero commits prints `no history` to stderr and exits 0.
|
|
637
|
+
- `show` — the worktree file (or sliced lines) by default. Pass `--ref`
|
|
638
|
+
for a committed snapshot. Empty slices succeed.
|
|
639
|
+
- `diff` — the unified diff text. An empty (or worktree == worktree)
|
|
640
|
+
range prints nothing on stdout and exits 0.
|
|
641
|
+
|
|
642
|
+
Run `code-viewer file agent-help` for the full AI-agent guide
|
|
643
|
+
including the JSON contract for each subcommand.
|
|
644
|
+
|
|
645
|
+
### Doctor CLI
|
|
646
|
+
|
|
647
|
+
The same diagnostic report behind the Environment Doctor sheet (see
|
|
648
|
+
Features above) is available from the terminal without a browser, so AI
|
|
649
|
+
agents and CI can introspect the runtime, SQLite driver, Git, Docker
|
|
650
|
+
discovery, and snapshot store status directly.
|
|
651
|
+
|
|
652
|
+
```sh
|
|
653
|
+
# Human-readable status summary.
|
|
654
|
+
code-viewer doctor
|
|
655
|
+
|
|
656
|
+
# Full DoctorReport JSON (matches the /_doctor endpoint).
|
|
657
|
+
code-viewer doctor --json
|
|
658
|
+
code-viewer doctor --cwd /path/to/repo --port 64160 --json
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
The exit code is `1` iff the worst check status is `"error"` (never on
|
|
662
|
+
`"warn"`), so it doubles as a CI gate. Run `code-viewer doctor agent-help`
|
|
663
|
+
for the full AI-agent guide.
|
|
664
|
+
|
|
324
665
|
## AI Code Annotations
|
|
325
666
|
|
|
326
667
|
AI coding agents (Claude Code, Codex, Cursor, Gemini, and similar CLI agents)
|
|
@@ -422,6 +763,41 @@ npx -y @youtyan/code-viewer skill install --agent all # claude, codex,
|
|
|
422
763
|
and `--cwd <dir>` to target a specific repository. Running the same command
|
|
423
764
|
again updates an existing installation in place.
|
|
424
765
|
|
|
766
|
+
## MCP Server
|
|
767
|
+
|
|
768
|
+
While `code-viewer` is running, the same server also exposes a local MCP
|
|
769
|
+
(Model Context Protocol) endpoint at `/_mcp` — for example
|
|
770
|
+
`http://127.0.0.1:<port>/_mcp`, where `<port>` is the port printed at
|
|
771
|
+
startup. It speaks JSON-RPC 2.0 over the Streamable HTTP transport
|
|
772
|
+
(`initialize`, `ping`, `tools/list`, `tools/call`; POST only,
|
|
773
|
+
`application/json`) and is guarded by the same localhost/same-origin check
|
|
774
|
+
as every other route, so MCP clients can call it directly instead of
|
|
775
|
+
spawning `code-viewer` CLI subprocesses.
|
|
776
|
+
|
|
777
|
+
All tools are read-only:
|
|
778
|
+
|
|
779
|
+
| Tool | What it does |
|
|
780
|
+
| --- | --- |
|
|
781
|
+
| `code_viewer_agent_help` | Index of every AI-facing CLI subcommand. |
|
|
782
|
+
| `code_viewer_status` | Branch, remote, changed files, and recent commits. |
|
|
783
|
+
| `code_viewer_file_show` | Read a file (optionally a line range) at any ref. |
|
|
784
|
+
| `code_viewer_file_blame` | Per-line blame (sha / author / time / summary). |
|
|
785
|
+
| `code_viewer_file_history` | Commit history for one path (follows renames). |
|
|
786
|
+
| `code_viewer_file_diff` | Unified diff for one path (preview-capped by default). |
|
|
787
|
+
| `code_viewer_search_files` | Rank repository paths by fuzzy or glob match. |
|
|
788
|
+
| `code_viewer_search_code` | Grep the repository (`rg` / `git grep` / fallback). |
|
|
789
|
+
| `code_viewer_datastore_sources` | Discover read-only datastore source ids. |
|
|
790
|
+
| `code_viewer_datastore_schemas` | List schemas for one SQL datastore. |
|
|
791
|
+
| `code_viewer_datastore_schema` | Inspect tables, indexes, FKs, and columns. |
|
|
792
|
+
| `code_viewer_datastore_columns` | Inspect columns for one SQL table. |
|
|
793
|
+
| `code_viewer_datastore_ddl` | Inspect the `CREATE` statement and triggers. |
|
|
794
|
+
| `code_viewer_datastore_query` | Run a read-only `SELECT` / `PRAGMA` / `EXPLAIN` / `WITH`. |
|
|
795
|
+
| `code_viewer_datastore_history` | Inspect saved query history. |
|
|
796
|
+
|
|
797
|
+
Point any MCP-compatible client (Claude Code, Codex, etc.) at the endpoint
|
|
798
|
+
URL above as a Streamable HTTP MCP server; no separate install step or
|
|
799
|
+
extra process is needed beyond `code-viewer` already running.
|
|
800
|
+
|
|
425
801
|
## Development
|
|
426
802
|
|
|
427
803
|
```sh
|