@youtyan/code-viewer 0.1.34 → 0.1.35
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 +11 -6
- package/dist/code-viewer.js +70 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,7 +122,9 @@ code-viewer annotate add --file web-src/app.ts --line 9650 \
|
|
|
122
122
|
|
|
123
123
|
The body is Markdown. Long bodies can be passed with `--body-file <path>` or
|
|
124
124
|
piped through stdin. `code-viewer annotate --help` shows all commands,
|
|
125
|
-
including `list`, `delete <id>`, and `clear`.
|
|
125
|
+
including `list`, `delete <id>`, and `clear`. For AI agents,
|
|
126
|
+
`code-viewer annotate agent-help` prints a skill-style guide covering the
|
|
127
|
+
workflow, conventions, and pitfalls for writing good walkthroughs.
|
|
126
128
|
|
|
127
129
|
Annotations are grouped into sessions and persisted in
|
|
128
130
|
`.code-viewer/annotations.json` at the repository root, so the walkthrough
|
|
@@ -138,11 +140,14 @@ location, and entries and sessions can be deleted there too. The "follow"
|
|
|
138
140
|
checkbox controls whether the tab jumps automatically when an agent adds a
|
|
139
141
|
new annotation.
|
|
140
142
|
|
|
141
|
-
The `annotate` subcommand
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
The `annotate` subcommand talks to the running server for the repository
|
|
144
|
+
(discovered via `~/.cache/code-viewer/servers/`); start one with
|
|
145
|
+
`code-viewer` first. Pass `--cwd <repo>` when annotating a repository other
|
|
146
|
+
than the current directory, or `--server <url>` to target a specific server.
|
|
147
|
+
|
|
148
|
+
`add` appends to the most recent session (creating one when none exists);
|
|
149
|
+
run `annotate start` again to begin a new session, or pass `--session <id>`
|
|
150
|
+
to target a specific one.
|
|
146
151
|
|
|
147
152
|
## Development
|
|
148
153
|
|
package/dist/code-viewer.js
CHANGED
|
@@ -1106,7 +1106,8 @@ var exports_annotate_cli = {};
|
|
|
1106
1106
|
__export(exports_annotate_cli, {
|
|
1107
1107
|
runAnnotateCli: () => runAnnotateCli,
|
|
1108
1108
|
parseAnnotateArgs: () => parseAnnotateArgs,
|
|
1109
|
-
ANNOTATE_HELP: () => ANNOTATE_HELP
|
|
1109
|
+
ANNOTATE_HELP: () => ANNOTATE_HELP,
|
|
1110
|
+
ANNOTATE_AGENT_HELP: () => ANNOTATE_AGENT_HELP
|
|
1110
1111
|
});
|
|
1111
1112
|
import { readFileSync as readFileSync4, realpathSync } from "node:fs";
|
|
1112
1113
|
function takeValue(argv, index, flag) {
|
|
@@ -1162,6 +1163,9 @@ function parseAnnotateArgs(argv) {
|
|
|
1162
1163
|
const subcommand = rest[0];
|
|
1163
1164
|
if (!subcommand)
|
|
1164
1165
|
return { ok: true, args: { command: { kind: "help" } } };
|
|
1166
|
+
if (subcommand === "agent-help") {
|
|
1167
|
+
return { ok: true, args: { command: { kind: "agent-help" } } };
|
|
1168
|
+
}
|
|
1165
1169
|
if (subcommand === "start") {
|
|
1166
1170
|
return {
|
|
1167
1171
|
ok: true,
|
|
@@ -1331,6 +1335,10 @@ async function runAnnotateCli(argv) {
|
|
|
1331
1335
|
console.log(ANNOTATE_HELP);
|
|
1332
1336
|
return;
|
|
1333
1337
|
}
|
|
1338
|
+
if (command.kind === "agent-help") {
|
|
1339
|
+
console.log(ANNOTATE_AGENT_HELP);
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1334
1342
|
const root = resolveRepoRoot(cwd);
|
|
1335
1343
|
const serverUrl = await ensureServerUrl(root, server);
|
|
1336
1344
|
if (command.kind === "start") {
|
|
@@ -1405,6 +1413,9 @@ in <repo>/.code-viewer/annotations.json. A running code-viewer server for
|
|
|
1405
1413
|
the repository is required: start one with "code-viewer" before using
|
|
1406
1414
|
annotate (or point at one explicitly with --server).
|
|
1407
1415
|
|
|
1416
|
+
Run "code-viewer annotate agent-help" for an AI-agent oriented guide
|
|
1417
|
+
(workflow, conventions, and pitfalls for writing good walkthroughs).
|
|
1418
|
+
|
|
1408
1419
|
Usage:
|
|
1409
1420
|
code-viewer annotate start [--title <text>]
|
|
1410
1421
|
code-viewer annotate add --file <path> [--line <n>|<n>-<m>]
|
|
@@ -1424,6 +1435,64 @@ Examples:
|
|
|
1424
1435
|
--body "This endpoint keeps one SSE stream per browser tab."
|
|
1425
1436
|
git diff HEAD~1 | code-viewer annotate add --file src/app.ts --line 10 \\
|
|
1426
1437
|
--from HEAD~1 --to worktree --body "The fix moves the guard up here."
|
|
1438
|
+
`, ANNOTATE_AGENT_HELP = `code-viewer annotate — agent guide
|
|
1439
|
+
|
|
1440
|
+
You are an AI coding agent. Use this tool to walk a human through code in
|
|
1441
|
+
their browser: each annotation jumps every open code-viewer tab to a file
|
|
1442
|
+
location and renders your explanation directly under the annotated lines.
|
|
1443
|
+
|
|
1444
|
+
## When to use
|
|
1445
|
+
|
|
1446
|
+
- Explaining a change you just made (per-file, per-hunk commentary)
|
|
1447
|
+
- Guiding a code review: point at the risky lines, in reading order
|
|
1448
|
+
- Onboarding walkthroughs: "how does feature X flow through the code"
|
|
1449
|
+
|
|
1450
|
+
## Requirements
|
|
1451
|
+
|
|
1452
|
+
- A code-viewer server must already be running for the repository
|
|
1453
|
+
(the human starts it with: code-viewer). This command never starts one.
|
|
1454
|
+
- Run from inside the repository, or pass --cwd <repo>.
|
|
1455
|
+
- If "code-viewer" is not on PATH (e.g. the human runs it via npx), invoke
|
|
1456
|
+
every command below as: npx -y @youtyan/code-viewer annotate ...
|
|
1457
|
+
|
|
1458
|
+
## Workflow
|
|
1459
|
+
|
|
1460
|
+
1. Start a session per walkthrough topic. The title is shown to the human:
|
|
1461
|
+
code-viewer annotate start --title "How the cache invalidation works"
|
|
1462
|
+
2. Add annotations in READING ORDER (the order you want the human to
|
|
1463
|
+
follow). Each add without --session appends to the most recent session:
|
|
1464
|
+
code-viewer annotate add --file src/cache.ts --line 120-145 \\
|
|
1465
|
+
--title "Entry point" --body "Writes land here first. ..."
|
|
1466
|
+
3. Verify what you posted:
|
|
1467
|
+
code-viewer annotate list
|
|
1468
|
+
|
|
1469
|
+
## Conventions for good walkthroughs
|
|
1470
|
+
|
|
1471
|
+
- One idea per annotation. Prefer 5-10 focused annotations over 2 huge ones.
|
|
1472
|
+
- Always pass --line. Use the smallest range that covers the idea; the
|
|
1473
|
+
body is rendered inline directly under the LAST line of the range.
|
|
1474
|
+
- Line numbers must match the "to" side of the range (default: the current
|
|
1475
|
+
worktree state of the file). When annotating a diff against another ref,
|
|
1476
|
+
pass --from/--to and use NEW-side line numbers.
|
|
1477
|
+
- The body is Markdown. Code spans, fenced blocks, and links work. Long
|
|
1478
|
+
bodies: use --body-file <path> or pipe via stdin instead of --body.
|
|
1479
|
+
- Give every annotation a short --title; it becomes the inline heading.
|
|
1480
|
+
- Annotating unchanged code is fine: the viewer auto-expands diff context
|
|
1481
|
+
or falls back to the full source view.
|
|
1482
|
+
|
|
1483
|
+
## Sessions
|
|
1484
|
+
|
|
1485
|
+
- add (no --session) → appends to the most recent session.
|
|
1486
|
+
- annotate start → begins a NEW session; later adds go there.
|
|
1487
|
+
- add --session <id> → targets a specific session (ids: annotate list).
|
|
1488
|
+
- The human can share a walkthrough as a URL; one session = one shareable
|
|
1489
|
+
walkthrough. Do not mix unrelated topics in one session.
|
|
1490
|
+
|
|
1491
|
+
## Cleanup
|
|
1492
|
+
|
|
1493
|
+
- delete <id> removes one annotation or a whole session by its id.
|
|
1494
|
+
- clear removes everything. Ask the human before clearing state you did
|
|
1495
|
+
not create.
|
|
1427
1496
|
`;
|
|
1428
1497
|
var init_annotate_cli = __esm(() => {
|
|
1429
1498
|
init_annotations();
|