@oxide/skepsis 0.7.0 → 0.9.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 +28 -2
- package/dist/cli.js +237 -72
- package/dist/web/assets/{highlights-Bu3jR2kn.js → highlights-CzsfRyuJ.js} +1 -1
- package/dist/web/assets/{index-DsJL1wFW.js → index-BNMa6k1t.js} +16 -7
- package/dist/web/assets/index-Ds8xdel2.css +1 -0
- package/dist/web/assets/{shiki-vIC6REHJ.js → shiki-7tdSK7dy.js} +1 -1
- package/dist/web/index.html +2 -2
- package/package.json +2 -2
- package/dist/web/assets/index-D1KnlUfq.css +0 -1
package/README.md
CHANGED
|
@@ -98,8 +98,20 @@ skepsis # review branch vs trunk, GitHub PR style
|
|
|
98
98
|
skepsis -r @ # review working copy only
|
|
99
99
|
skepsis -r 'mybranch..@' # review a range
|
|
100
100
|
skepsis -f main -t @ # diff between two revisions
|
|
101
|
+
skepsis --interdiff -f mybranch@origin -t mybranch
|
|
102
|
+
# review changes to a commit since push
|
|
103
|
+
# (jj interdiff)
|
|
101
104
|
```
|
|
102
105
|
|
|
106
|
+
In jj repos, `--interdiff` (used with `-f`, `-t`, or both) runs `jj interdiff`,
|
|
107
|
+
rebasing the `--from` revision onto the `--to` revision's parents before
|
|
108
|
+
diffing. After you amend and rebase a commit, `-f A -t B` includes upstream
|
|
109
|
+
changes from the rebase, while `--interdiff` shows only what changed in the
|
|
110
|
+
commit itself. A changed description shows as a file named
|
|
111
|
+
`JJ-COMMIT-DESCRIPTION`. If rebasing `--from` conflicts, jj conflict markers
|
|
112
|
+
appear as removed lines on the old side. Line expansion and inline comments are
|
|
113
|
+
disabled for interdiffs (`--send` still works).
|
|
114
|
+
|
|
103
115
|
### git examples
|
|
104
116
|
|
|
105
117
|
Ranges passed with `-r` are passed through verbatim to `git diff`.
|
|
@@ -154,6 +166,14 @@ const end = Number(match[2])
|
|
|
154
166
|
// </review>
|
|
155
167
|
```
|
|
156
168
|
|
|
169
|
+
Selecting text in the diff also opens the comment box, to comment on part of a
|
|
170
|
+
line rather than the whole thing. The box opens directly under the selection,
|
|
171
|
+
and the selected text stays highlighted while you write. Selecting whole lines
|
|
172
|
+
(a triple-click, say) is the same as commenting from the gutter. While the box
|
|
173
|
+
is empty, clicking elsewhere in the code closes it, and ⌘C copies the selected
|
|
174
|
+
text. The open tag quotes the selection, eliding the middle if it's long:
|
|
175
|
+
`<review on="Number(match[1])">`.
|
|
176
|
+
|
|
157
177
|
### Marking files viewed
|
|
158
178
|
|
|
159
179
|
Viewed state is stored per file in `~/.local/share/skepsis/` using the file's
|
|
@@ -169,7 +189,9 @@ agent, a tmux pane, or a log. There is not chat UI in skepsis (yet) so replies
|
|
|
169
189
|
from the agent will appear in that session, wherever it is. Send works
|
|
170
190
|
in some cases that inline comments can't (because there is no file to write): on
|
|
171
191
|
removed lines, and on diffs that don't end at the working copy. The **Comment**
|
|
172
|
-
button continues to write a `<review>` marker in the file as usual.
|
|
192
|
+
button continues to write a `<review>` marker in the file as usual. When you
|
|
193
|
+
send a comment on selected text, the message includes where the selection
|
|
194
|
+
starts and ends.
|
|
173
195
|
|
|
174
196
|
The only way to set the command is `--send` or `SKEPSIS_SEND`. skepsis never
|
|
175
197
|
reads it from the repo contents, so reviewing someone else's branch
|
|
@@ -212,6 +234,7 @@ The JSON sent to stdin looks like this:
|
|
|
212
234
|
"file": "src/a.ts",
|
|
213
235
|
"side": "additions",
|
|
214
236
|
"lines": [42, 45],
|
|
237
|
+
"columns": null,
|
|
215
238
|
"code": [{ "lines": [41, 46], "text": "const z = 0\nconst a = 1\n…" }],
|
|
216
239
|
"blob": "9daeafb",
|
|
217
240
|
"text": "why two?",
|
|
@@ -220,7 +243,10 @@ The JSON sent to stdin looks like this:
|
|
|
220
243
|
````
|
|
221
244
|
|
|
222
245
|
`side` is `additions` or `deletions`, and `lines` (1-based, inclusive) are in
|
|
223
|
-
that side's numbering. `
|
|
246
|
+
that side's numbering. `columns` is set when the comment is on selected text
|
|
247
|
+
rather than whole lines: where the text starts in the first line and ends
|
|
248
|
+
(exclusive) in the last, 0-based, in UTF-16 code units. The prompt then marks
|
|
249
|
+
the text in the excerpt with `⟦` and `⟧`. `code` is an excerpt of that side around the lines
|
|
224
250
|
commented on, in runs of consecutive lines, each with its own first and last
|
|
225
251
|
line. There's more than one run when the lines commented on span lines the
|
|
226
252
|
diff doesn't show. `blob` is the ID of the
|
package/dist/cli.js
CHANGED
|
@@ -3,10 +3,10 @@ import { execFileSync, spawn } from "child_process";
|
|
|
3
3
|
import fs, { createReadStream, existsSync, statSync } from "node:fs";
|
|
4
4
|
import path, { basename, dirname, extname, join, relative } from "node:path";
|
|
5
5
|
import { EventEmitter } from "node:events";
|
|
6
|
-
import childProcess, { spawn as spawn$1 } from "node:child_process";
|
|
6
|
+
import childProcess, { execFile, spawn as spawn$1 } from "node:child_process";
|
|
7
7
|
import process$1, { versions } from "node:process";
|
|
8
|
-
import { stripVTControlCharacters } from "node:util";
|
|
9
|
-
import { STATUS_CODES, createServer } from "node:http";
|
|
8
|
+
import { promisify, stripVTControlCharacters } from "node:util";
|
|
9
|
+
import { STATUS_CODES, ServerResponse, createServer } from "node:http";
|
|
10
10
|
import { Http2ServerRequest, constants } from "node:http2";
|
|
11
11
|
import { Readable } from "node:stream";
|
|
12
12
|
import { lstat, open, readFile, readlink, writeFile } from "node:fs/promises";
|
|
@@ -5728,7 +5728,10 @@ const handleResponseError = (e, outgoing) => {
|
|
|
5728
5728
|
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") console.info("The user aborted a request.");
|
|
5729
5729
|
else {
|
|
5730
5730
|
console.error(e);
|
|
5731
|
-
if (!outgoing.headersSent)
|
|
5731
|
+
if (!outgoing.headersSent) {
|
|
5732
|
+
if (outgoing instanceof ServerResponse) outgoing._contentLength = null;
|
|
5733
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
5734
|
+
}
|
|
5732
5735
|
outgoing.end(`Error: ${err.message}`);
|
|
5733
5736
|
outgoing.destroy(err);
|
|
5734
5737
|
}
|
|
@@ -5736,6 +5739,21 @@ const handleResponseError = (e, outgoing) => {
|
|
|
5736
5739
|
const flushHeaders = (outgoing) => {
|
|
5737
5740
|
if ("flushHeaders" in outgoing && outgoing.writable) outgoing.flushHeaders();
|
|
5738
5741
|
};
|
|
5742
|
+
const trySetContentLength = (outgoing, status, length) => {
|
|
5743
|
+
const http1 = outgoing;
|
|
5744
|
+
if (http1._contentLength === null && http1._hasBody && http1.useChunkedEncodingByDefault && !http1._removedContLen && status >= 200 && status !== 204 && status !== 304 && !outgoing.hasHeader("content-length") && !outgoing.hasHeader("transfer-encoding") && !outgoing.hasHeader("trailer")) {
|
|
5745
|
+
http1._contentLength = length;
|
|
5746
|
+
return true;
|
|
5747
|
+
}
|
|
5748
|
+
return false;
|
|
5749
|
+
};
|
|
5750
|
+
const writeDefaultHeaders = (outgoing, status, length) => {
|
|
5751
|
+
if (trySetContentLength(outgoing, status, length)) outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
5752
|
+
else outgoing.writeHead(status, {
|
|
5753
|
+
"Content-Type": defaultContentType,
|
|
5754
|
+
"Content-Length": length
|
|
5755
|
+
});
|
|
5756
|
+
};
|
|
5739
5757
|
const responseViaCache = async (res, outgoing) => {
|
|
5740
5758
|
let [status, body, header] = res[cacheKey];
|
|
5741
5759
|
if (!header) {
|
|
@@ -5743,22 +5761,13 @@ const responseViaCache = async (res, outgoing) => {
|
|
|
5743
5761
|
outgoing.writeHead(status);
|
|
5744
5762
|
outgoing.end();
|
|
5745
5763
|
} else if (typeof body === "string") {
|
|
5746
|
-
outgoing
|
|
5747
|
-
"Content-Type": defaultContentType,
|
|
5748
|
-
"Content-Length": Buffer.byteLength(body)
|
|
5749
|
-
});
|
|
5764
|
+
writeDefaultHeaders(outgoing, status, Buffer.byteLength(body));
|
|
5750
5765
|
outgoing.end(body);
|
|
5751
5766
|
} else if (body instanceof Uint8Array) {
|
|
5752
|
-
outgoing
|
|
5753
|
-
"Content-Type": defaultContentType,
|
|
5754
|
-
"Content-Length": body.byteLength
|
|
5755
|
-
});
|
|
5767
|
+
writeDefaultHeaders(outgoing, status, body.byteLength);
|
|
5756
5768
|
outgoing.end(body);
|
|
5757
5769
|
} else if (body instanceof Blob) {
|
|
5758
|
-
outgoing
|
|
5759
|
-
"Content-Type": defaultContentType,
|
|
5760
|
-
"Content-Length": body.size
|
|
5761
|
-
});
|
|
5770
|
+
writeDefaultHeaders(outgoing, status, body.size);
|
|
5762
5771
|
outgoing.end(new Uint8Array(await body.arrayBuffer()));
|
|
5763
5772
|
} else {
|
|
5764
5773
|
outgoing.writeHead(status, { "Content-Type": defaultContentType });
|
|
@@ -5769,6 +5778,8 @@ const responseViaCache = async (res, outgoing) => {
|
|
|
5769
5778
|
return;
|
|
5770
5779
|
}
|
|
5771
5780
|
let hasContentLength = false;
|
|
5781
|
+
let plainHeaders = false;
|
|
5782
|
+
let canAutoLength = true;
|
|
5772
5783
|
if (header instanceof Headers) {
|
|
5773
5784
|
hasContentLength = header.has("content-length");
|
|
5774
5785
|
header = buildOutgoingHttpHeaders(header, body === null ? void 0 : defaultContentType);
|
|
@@ -5776,14 +5787,25 @@ const responseViaCache = async (res, outgoing) => {
|
|
|
5776
5787
|
const headerObj = new Headers(header);
|
|
5777
5788
|
hasContentLength = headerObj.has("content-length");
|
|
5778
5789
|
header = buildOutgoingHttpHeaders(headerObj, body === null ? void 0 : defaultContentType);
|
|
5779
|
-
} else
|
|
5780
|
-
|
|
5781
|
-
|
|
5790
|
+
} else {
|
|
5791
|
+
plainHeaders = true;
|
|
5792
|
+
for (const key in header) {
|
|
5793
|
+
if (key.length === 14 && key.toLowerCase() === "content-length") {
|
|
5794
|
+
hasContentLength = true;
|
|
5795
|
+
break;
|
|
5796
|
+
}
|
|
5797
|
+
if (key.length === 17 && key.toLowerCase() === "transfer-encoding" || key.length === 7 && key.toLowerCase() === "trailer") canAutoLength = false;
|
|
5798
|
+
}
|
|
5782
5799
|
}
|
|
5783
5800
|
if (!hasContentLength) {
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
else if (body instanceof
|
|
5801
|
+
let length;
|
|
5802
|
+
if (typeof body === "string") length = Buffer.byteLength(body);
|
|
5803
|
+
else if (body instanceof Uint8Array) length = body.byteLength;
|
|
5804
|
+
else if (body instanceof Blob) length = body.size;
|
|
5805
|
+
if (length !== void 0 && (!plainHeaders || !canAutoLength || !trySetContentLength(outgoing, status, length))) {
|
|
5806
|
+
if (plainHeaders) header = { ...header };
|
|
5807
|
+
header["Content-Length"] = length;
|
|
5808
|
+
}
|
|
5787
5809
|
}
|
|
5788
5810
|
outgoing.writeHead(status, header);
|
|
5789
5811
|
if (body == null) outgoing.end();
|
|
@@ -6246,6 +6268,7 @@ const serveStatic = (options = { root: "" }) => {
|
|
|
6246
6268
|
let filename;
|
|
6247
6269
|
if (optionPath) filename = optionPath;
|
|
6248
6270
|
else try {
|
|
6271
|
+
if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
|
|
6249
6272
|
filename = tryDecodeURI(c.req.path);
|
|
6250
6273
|
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
|
|
6251
6274
|
} catch {
|
|
@@ -6473,13 +6496,17 @@ const GIT_PREFIX_OVERRIDE = [
|
|
|
6473
6496
|
"diff.dstPrefix=b/"
|
|
6474
6497
|
];
|
|
6475
6498
|
const JJ_PREFIX_OVERRIDE = ["--config", "diff.git.show-path-prefix=true"];
|
|
6499
|
+
/** `interdiff` or `diff`, the subcommand that produces the patch */
|
|
6500
|
+
function subcommand(src) {
|
|
6501
|
+
return src.interdiff ? "interdiff" : "diff";
|
|
6502
|
+
}
|
|
6476
6503
|
function diffCommand(src) {
|
|
6477
6504
|
const fileArgs = src.files.length > 0 ? ["--", ...src.files] : [];
|
|
6478
6505
|
if (src.vcs === "jj") return {
|
|
6479
6506
|
cmd: "jj",
|
|
6480
6507
|
args: [
|
|
6481
6508
|
...JJ_PREFIX_OVERRIDE,
|
|
6482
|
-
|
|
6509
|
+
subcommand(src),
|
|
6483
6510
|
...src.args,
|
|
6484
6511
|
"--git",
|
|
6485
6512
|
...fileArgs
|
|
@@ -6525,11 +6552,11 @@ function normalizeJjRenames(patch) {
|
|
|
6525
6552
|
async function getDiff(src) {
|
|
6526
6553
|
const { cmd, args } = diffCommand(src);
|
|
6527
6554
|
const { stdout, stderr, code } = await run(cmd, args);
|
|
6528
|
-
if (code !== 0) throw new Error(`${cmd}
|
|
6555
|
+
if (code !== 0) throw new Error(`${cmd} ${subcommand(src)} failed (exit ${code}): ${stderr}`);
|
|
6529
6556
|
const patch = src.vcs === "jj" ? normalizeJjRenames(stdout) : stdout;
|
|
6530
6557
|
return {
|
|
6531
6558
|
patch,
|
|
6532
|
-
fileHashes: extractFileHashes(patch)
|
|
6559
|
+
fileHashes: extractFileHashes(patch, src.interdiff)
|
|
6533
6560
|
};
|
|
6534
6561
|
}
|
|
6535
6562
|
/** A short content hash of the whole patch, so the page can ask whether the
|
|
@@ -6548,31 +6575,35 @@ function patchHash(patch) {
|
|
|
6548
6575
|
* of their extended header lines instead. That changes when the rename or
|
|
6549
6576
|
* mode does, and a content change adds an index line, so viewed state still
|
|
6550
6577
|
* resets whenever there is something new to look at.
|
|
6578
|
+
*
|
|
6579
|
+
* An interdiff hashes each file's whole block instead. It shows only how the
|
|
6580
|
+
* change to a file changed, so keying on the new blob would mark the file
|
|
6581
|
+
* viewed in the commit's own diff too, where most of it is unseen.
|
|
6551
6582
|
*/
|
|
6552
|
-
function extractFileHashes(patch) {
|
|
6583
|
+
function extractFileHashes(patch, interdiff = false) {
|
|
6553
6584
|
const hashes = {};
|
|
6554
6585
|
let currentFile = null;
|
|
6555
|
-
let
|
|
6556
|
-
const
|
|
6586
|
+
let block = [];
|
|
6587
|
+
const hashBlock = () => {
|
|
6557
6588
|
if (currentFile == null) return;
|
|
6558
|
-
hashes[currentFile] = createHash("sha1").update(
|
|
6589
|
+
hashes[currentFile] = createHash("sha1").update(block.join("\n")).digest("hex").slice(0, 12);
|
|
6559
6590
|
};
|
|
6560
6591
|
for (const line of patch.split("\n")) {
|
|
6561
6592
|
const diffMatch = line.match(/^diff --git a\/.+ b\/(.+)$/);
|
|
6562
6593
|
if (diffMatch) {
|
|
6563
|
-
|
|
6594
|
+
hashBlock();
|
|
6564
6595
|
currentFile = diffMatch[1];
|
|
6565
|
-
|
|
6596
|
+
block = [line];
|
|
6566
6597
|
continue;
|
|
6567
6598
|
}
|
|
6568
6599
|
if (currentFile == null) continue;
|
|
6569
|
-
if (line.startsWith("index ")) {
|
|
6600
|
+
if (line.startsWith("index ") && !interdiff) {
|
|
6570
6601
|
const indexMatch = line.match(/^index [0-9a-f]+\.\.([0-9a-f]+)/);
|
|
6571
6602
|
if (indexMatch) hashes[currentFile] = indexMatch[1];
|
|
6572
6603
|
currentFile = null;
|
|
6573
|
-
} else
|
|
6604
|
+
} else block.push(line);
|
|
6574
6605
|
}
|
|
6575
|
-
|
|
6606
|
+
hashBlock();
|
|
6576
6607
|
return hashes;
|
|
6577
6608
|
}
|
|
6578
6609
|
// server/displayCommand.ts
|
|
@@ -6587,7 +6618,7 @@ function displayCommand(diffSource) {
|
|
|
6587
6618
|
const args = (diffSource.displayArgs ?? diffSource.args).map(shellQuote);
|
|
6588
6619
|
const files = diffSource.files.map(shellQuote);
|
|
6589
6620
|
const fileSuffix = files.length > 0 ? ` -- ${files.join(" ")}` : "";
|
|
6590
|
-
return `${diffSource.vcs}
|
|
6621
|
+
return `${diffSource.vcs} ${subcommand(diffSource)} ${args.join(" ")}${fileSuffix}`;
|
|
6591
6622
|
}
|
|
6592
6623
|
// server/fileContents.ts
|
|
6593
6624
|
/**
|
|
@@ -6648,6 +6679,76 @@ async function getFileContents(src, cwd, path, oldPath) {
|
|
|
6648
6679
|
newContents
|
|
6649
6680
|
};
|
|
6650
6681
|
}
|
|
6682
|
+
// server/generated.ts
|
|
6683
|
+
const execFileAsync = promisify(execFile);
|
|
6684
|
+
/** Lockfiles count as generated unless the repo says otherwise. */
|
|
6685
|
+
const LOCKFILES = /* @__PURE__ */ new Set([
|
|
6686
|
+
"Cargo.lock",
|
|
6687
|
+
"package-lock.json",
|
|
6688
|
+
"npm-shrinkwrap.json",
|
|
6689
|
+
"pnpm-lock.yaml",
|
|
6690
|
+
"yarn.lock",
|
|
6691
|
+
"bun.lock",
|
|
6692
|
+
"bun.lockb",
|
|
6693
|
+
"deno.lock",
|
|
6694
|
+
"go.sum",
|
|
6695
|
+
"poetry.lock",
|
|
6696
|
+
"uv.lock",
|
|
6697
|
+
"Pipfile.lock",
|
|
6698
|
+
"Gemfile.lock",
|
|
6699
|
+
"composer.lock",
|
|
6700
|
+
"flake.lock"
|
|
6701
|
+
]);
|
|
6702
|
+
/**
|
|
6703
|
+
* The files among `files` that are generated, which the page starts
|
|
6704
|
+
* collapsed, as GitHub does. The `linguist-generated` git attribute decides
|
|
6705
|
+
* whenever it's specified: like Linguist, any value but `false` means
|
|
6706
|
+
* generated. Otherwise only lockfiles count. git reads the attribute from
|
|
6707
|
+
* .gitattributes, .git/info/attributes, and core.attributesFile, so
|
|
6708
|
+
* patterns don't have to be checked in. Without git
|
|
6709
|
+
* (a jj repo with no colocated .git), only the lockfile rule applies.
|
|
6710
|
+
*/
|
|
6711
|
+
async function getGeneratedFiles(cwd, files) {
|
|
6712
|
+
if (files.length === 0) return [];
|
|
6713
|
+
const attrs = await checkAttr(cwd, files).catch(() => /* @__PURE__ */ new Map());
|
|
6714
|
+
return files.filter((file) => {
|
|
6715
|
+
const value = attrs.get(file);
|
|
6716
|
+
if (value === void 0 || value === "unspecified") return LOCKFILES.has(basename(file));
|
|
6717
|
+
return value !== "unset" && value !== "false";
|
|
6718
|
+
});
|
|
6719
|
+
}
|
|
6720
|
+
/** Each file's `linguist-generated` value: set, unset, unspecified, or the
|
|
6721
|
+
* string it's set to (e.g. `true` for `linguist-generated=true`). */
|
|
6722
|
+
async function checkAttr(cwd, files) {
|
|
6723
|
+
const { stdout: top } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], { cwd });
|
|
6724
|
+
return new Promise((resolve, reject) => {
|
|
6725
|
+
const proc = spawn$1("git", [
|
|
6726
|
+
"check-attr",
|
|
6727
|
+
"-z",
|
|
6728
|
+
"--stdin",
|
|
6729
|
+
"linguist-generated"
|
|
6730
|
+
], {
|
|
6731
|
+
cwd: top.trim(),
|
|
6732
|
+
stdio: [
|
|
6733
|
+
"pipe",
|
|
6734
|
+
"pipe",
|
|
6735
|
+
"ignore"
|
|
6736
|
+
]
|
|
6737
|
+
});
|
|
6738
|
+
const stdout = [];
|
|
6739
|
+
proc.stdout.on("data", (d) => stdout.push(d));
|
|
6740
|
+
proc.on("error", reject);
|
|
6741
|
+
proc.stdin.on("error", () => {});
|
|
6742
|
+
proc.on("close", (code) => {
|
|
6743
|
+
if (code !== 0) return reject(/* @__PURE__ */ new Error(`git check-attr exited ${code}`));
|
|
6744
|
+
const fields = Buffer.concat(stdout).toString().split("\0");
|
|
6745
|
+
const values = /* @__PURE__ */ new Map();
|
|
6746
|
+
for (let i = 0; i + 2 < fields.length; i += 3) values.set(fields[i], fields[i + 2]);
|
|
6747
|
+
resolve(values);
|
|
6748
|
+
});
|
|
6749
|
+
proc.stdin.end(files.map((f) => f + "\0").join(""));
|
|
6750
|
+
});
|
|
6751
|
+
}
|
|
6651
6752
|
// server/viewed.ts
|
|
6652
6753
|
/**
|
|
6653
6754
|
* Viewed state: tracks which files the user has marked as viewed.
|
|
@@ -22903,9 +23004,25 @@ const REVIEW_CLOSE_TAG = "</review>";
|
|
|
22903
23004
|
* stays right when lines above it are added or removed, including by other
|
|
22904
23005
|
* comments. The value is in words because agents read it: in testing,
|
|
22905
23006
|
* Sonnet and Haiku sometimes took `above="6"` or `span="6"` to mean line 6,
|
|
22906
|
-
* and never misread this. A plain `<review>` covers the line just above.
|
|
22907
|
-
|
|
22908
|
-
|
|
23007
|
+
* and never misread this. A plain `<review>` covers the line just above.
|
|
23008
|
+
*
|
|
23009
|
+
* A comment on some of the text in those lines says which with `on`:
|
|
23010
|
+
* `<review on="the quick … lazy dog">`. It's one line, and cut in the middle
|
|
23011
|
+
* past QUOTE_MAX characters, since the tag sits right under the text and the
|
|
23012
|
+
* two ends are enough to find it there. */
|
|
23013
|
+
function reviewOpenTag(lines, quote) {
|
|
23014
|
+
const on = quote && shortQuote(quote, QUOTE_MAX).replaceAll("\"", """);
|
|
23015
|
+
const text = [lines > 1 && `covers="${lines} lines above"`, on && `on="${on}"`].filter(Boolean).join(" ");
|
|
23016
|
+
return text ? `<review ${text}>` : REVIEW_OPEN_TAG;
|
|
23017
|
+
}
|
|
23018
|
+
const QUOTE_MAX = 80;
|
|
23019
|
+
/** `quote` on one line, with the middle cut out if it's over `max`
|
|
23020
|
+
* characters. It cuts between code points, so it can't split an emoji. */
|
|
23021
|
+
function shortQuote(quote, max) {
|
|
23022
|
+
const chars = [...quote.replace(/\s+/g, " ").trim()];
|
|
23023
|
+
if (chars.length <= max) return chars.join("");
|
|
23024
|
+
const half = (max - 3) / 2;
|
|
23025
|
+
return `${chars.slice(0, Math.ceil(half)).join("").trimEnd()} … ${chars.slice(-Math.floor(half)).join("").trimStart()}`;
|
|
22909
23026
|
}
|
|
22910
23027
|
const OPEN_TAG_SOURCE = "<review(?:\\s+[\\w-]+=\"[^\"]*\")*\\s*>";
|
|
22911
23028
|
new RegExp(OPEN_TAG_SOURCE);
|
|
@@ -23197,7 +23314,7 @@ async function getCommentSyntaxes(cwd, files) {
|
|
|
23197
23314
|
async function assertNotSymlink(cwd, file) {
|
|
23198
23315
|
if ((await lstat(join(cwd, file)).catch(() => null))?.isSymbolicLink()) throw new Error(`Cannot comment on symlink: ${file}`);
|
|
23199
23316
|
}
|
|
23200
|
-
async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1) {
|
|
23317
|
+
async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1, quote) {
|
|
23201
23318
|
await assertNotSymlink(cwd, file);
|
|
23202
23319
|
const filePath = join(cwd, file);
|
|
23203
23320
|
const lines = (await readFile(filePath, "utf-8")).split("\n");
|
|
@@ -23214,7 +23331,7 @@ async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1
|
|
|
23214
23331
|
suffix
|
|
23215
23332
|
].filter(Boolean).join(" ");
|
|
23216
23333
|
const commentLines = [
|
|
23217
|
-
wrap(reviewOpenTag(Math.min(lineCount, afterLine))),
|
|
23334
|
+
wrap(reviewOpenTag(Math.min(lineCount, afterLine), quote)),
|
|
23218
23335
|
...text.split("\n").map((line) => wrap(line)),
|
|
23219
23336
|
wrap(REVIEW_CLOSE_TAG)
|
|
23220
23337
|
];
|
|
@@ -28576,7 +28693,9 @@ const commentRequestSchema = object({
|
|
|
28576
28693
|
lineText: string(),
|
|
28577
28694
|
text: string(),
|
|
28578
28695
|
/** How many lines the comment covers, ending at afterLine. */
|
|
28579
|
-
lineCount: number().int().min(1).optional()
|
|
28696
|
+
lineCount: number().int().min(1).optional(),
|
|
28697
|
+
/** The selected text, for a comment on part of those lines. */
|
|
28698
|
+
quote: string().optional()
|
|
28580
28699
|
});
|
|
28581
28700
|
/** A comment for the --send command. Only `text` is required by the
|
|
28582
28701
|
* contract; the page always anchors it to lines. */
|
|
@@ -28584,6 +28703,10 @@ const sendRequestSchema = object({
|
|
|
28584
28703
|
file: string().nullable(),
|
|
28585
28704
|
side: _enum(["additions", "deletions"]).nullable(),
|
|
28586
28705
|
lines: tuple([number().int().positive(), number().int().positive()]).nullable(),
|
|
28706
|
+
/** For a comment on selected text rather than whole lines: where the text
|
|
28707
|
+
* starts in the first line and ends (exclusive) in the last, 0-based, in
|
|
28708
|
+
* UTF-16 code units. */
|
|
28709
|
+
columns: tuple([number().int().nonnegative(), number().int().nonnegative()]).nullable(),
|
|
28587
28710
|
/** An excerpt around the lines commented on, as runs of consecutive lines
|
|
28588
28711
|
* with each run's first and last line. Lines the diff hides split it. */
|
|
28589
28712
|
code: array(object({
|
|
@@ -28689,11 +28812,12 @@ function buildPayload(diffSource, root, input) {
|
|
|
28689
28812
|
root,
|
|
28690
28813
|
diff: {
|
|
28691
28814
|
command: displayCommand(diffSource),
|
|
28692
|
-
toWorkingCopy: diffSource.
|
|
28815
|
+
toWorkingCopy: diffSource.toWorkingCopy
|
|
28693
28816
|
},
|
|
28694
28817
|
file: input.file,
|
|
28695
28818
|
side: input.side,
|
|
28696
28819
|
lines: input.lines,
|
|
28820
|
+
columns: input.columns,
|
|
28697
28821
|
code: input.code,
|
|
28698
28822
|
blob: input.blob,
|
|
28699
28823
|
text: input.text
|
|
@@ -28708,6 +28832,35 @@ function fence(code) {
|
|
|
28708
28832
|
const longest = Math.max(0, ...(code.match(/`+/g) ?? []).map((run) => run.length));
|
|
28709
28833
|
return "`".repeat(Math.max(3, longest + 1));
|
|
28710
28834
|
}
|
|
28835
|
+
/** Where the selected text starts and ends, as start-of-text and end-of-text
|
|
28836
|
+
* marks put into the excerpt. */
|
|
28837
|
+
const MARKS = ["⟦", "⟧"];
|
|
28838
|
+
/** `code` with `columns` marked: the start in line `lines[0]` and the end in
|
|
28839
|
+
* `lines[1]`. Null when the excerpt doesn't hold both lines. */
|
|
28840
|
+
function markExcerpt(code, lines, columns) {
|
|
28841
|
+
const runs = code.map((run) => ({
|
|
28842
|
+
...run,
|
|
28843
|
+
rows: run.text.split("\n")
|
|
28844
|
+
}));
|
|
28845
|
+
const points = [0, 1].map((i) => {
|
|
28846
|
+
const run = runs.find((r) => lines[i] >= r.lines[0] && lines[i] <= r.lines[1]);
|
|
28847
|
+
return run && {
|
|
28848
|
+
run,
|
|
28849
|
+
row: lines[i] - run.lines[0]
|
|
28850
|
+
};
|
|
28851
|
+
});
|
|
28852
|
+
if (!points[0] || !points[1]) return null;
|
|
28853
|
+
for (const i of [1, 0]) {
|
|
28854
|
+
const { run, row } = points[i];
|
|
28855
|
+
const text = run.rows[row];
|
|
28856
|
+
const col = Math.min(columns[i], text.length);
|
|
28857
|
+
run.rows[row] = text.slice(0, col) + MARKS[i] + text.slice(col);
|
|
28858
|
+
}
|
|
28859
|
+
return runs.map(({ lines: range, rows }) => ({
|
|
28860
|
+
lines: range,
|
|
28861
|
+
text: rows.join("\n")
|
|
28862
|
+
}));
|
|
28863
|
+
}
|
|
28711
28864
|
function renderPrompt(p) {
|
|
28712
28865
|
const command = `\`${p.diff.command}\``;
|
|
28713
28866
|
if (p.file === null) return `Review comment on ${command}:\n\n${p.text}`;
|
|
@@ -28716,11 +28869,13 @@ function renderPrompt(p) {
|
|
|
28716
28869
|
const head = `Review comment on ${p.file}${where} (${side} of ${command})`;
|
|
28717
28870
|
if (!p.code) return `${head}:\n\n${p.text}`;
|
|
28718
28871
|
const ranges = p.code.map(({ lines: [first, last] }) => first === last ? `line ${first}` : `lines ${first}–${last}`);
|
|
28719
|
-
const
|
|
28872
|
+
const marked = p.lines && p.columns && markExcerpt(p.code, p.lines, p.columns);
|
|
28873
|
+
const on = marked ? `, on the text between ${MARKS[0]} and ${MARKS[1]}` : "";
|
|
28874
|
+
const excerpts = (marked ?? p.code).map(({ text }) => {
|
|
28720
28875
|
const f = fence(text);
|
|
28721
28876
|
return `${f}\n${text}\n${f}`;
|
|
28722
28877
|
});
|
|
28723
|
-
return `${head}, in ${ranges.join(" and ")}:\n\n${excerpts.join("\n\n")}\n\n${p.text}`;
|
|
28878
|
+
return `${head}${on}, in ${ranges.join(" and ")}:\n\n${excerpts.join("\n\n")}\n\n${p.text}`;
|
|
28724
28879
|
}
|
|
28725
28880
|
const TIMEOUT_MS = 1e4;
|
|
28726
28881
|
const MAX_OUTPUT = 65536;
|
|
@@ -28801,23 +28956,30 @@ async function startServer(opts) {
|
|
|
28801
28956
|
if (c.req.path === "/api/theme.js" || tokenMatches(c.req.header("X-Skepsis-Token"), token)) return next();
|
|
28802
28957
|
return c.json({ error: "This page has no valid token. Open the URL skepsis printed when it started." }, 401);
|
|
28803
28958
|
});
|
|
28959
|
+
const commentsEnabled = diffSource.toWorkingCopy && !diffSource.interdiff;
|
|
28804
28960
|
app.get("/api/diff", async (c) => {
|
|
28805
28961
|
const { patch, fileHashes } = await getDiff(diffSource);
|
|
28806
|
-
const
|
|
28807
|
-
const commentSyntaxes =
|
|
28962
|
+
const files = Object.keys(fileHashes);
|
|
28963
|
+
const [viewed, generated, commentSyntaxes] = await Promise.all([
|
|
28964
|
+
loadViewed(cwd, fileHashes),
|
|
28965
|
+
getGeneratedFiles(cwd, files),
|
|
28966
|
+
commentsEnabled ? getCommentSyntaxes(cwd, files) : {}
|
|
28967
|
+
]);
|
|
28808
28968
|
return c.json({
|
|
28809
28969
|
patch,
|
|
28810
28970
|
revset: displayCommand(diffSource),
|
|
28811
28971
|
repo: basename(cwd),
|
|
28812
28972
|
vcs: diffSource.vcs,
|
|
28813
|
-
|
|
28973
|
+
interdiff: !!diffSource.interdiff,
|
|
28974
|
+
commentsEnabled,
|
|
28814
28975
|
expandable: diffSource.endpoints !== null,
|
|
28815
28976
|
fileHashes,
|
|
28816
28977
|
patchHash: patchHash(patch),
|
|
28817
28978
|
poll,
|
|
28818
28979
|
send: !!send,
|
|
28819
28980
|
viewed,
|
|
28820
|
-
commentSyntaxes
|
|
28981
|
+
commentSyntaxes,
|
|
28982
|
+
generated
|
|
28821
28983
|
});
|
|
28822
28984
|
});
|
|
28823
28985
|
let hashInFlight = null;
|
|
@@ -28852,8 +29014,8 @@ async function startServer(opts) {
|
|
|
28852
29014
|
return c.json({ ok: true });
|
|
28853
29015
|
});
|
|
28854
29016
|
app.post("/api/comment", zValidator("json", commentRequestSchema), async (c) => {
|
|
28855
|
-
const { file, afterLine, lineText, text, lineCount } = c.req.valid("json");
|
|
28856
|
-
await insertComment(cwd, file, afterLine, lineText, text, lineCount);
|
|
29017
|
+
const { file, afterLine, lineText, text, lineCount, quote } = c.req.valid("json");
|
|
29018
|
+
await insertComment(cwd, file, afterLine, lineText, text, lineCount, quote);
|
|
28857
29019
|
hashInFlight = null;
|
|
28858
29020
|
return c.json({ ok: true });
|
|
28859
29021
|
});
|
|
@@ -28936,16 +29098,17 @@ function parsePort(value) {
|
|
|
28936
29098
|
if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("port must be an integer between 0 and 65535");
|
|
28937
29099
|
return port;
|
|
28938
29100
|
}
|
|
28939
|
-
const program = new Command().name("skepsis").description("Local diff review UI (auto-detects jj or git)").option("-r, --revisions <revsets>", "Show changes in these revisions").option("-f, --from <rev>", "Show changes from this revision").option("-t, --to <rev>", "Show changes to this revision").option("--git", "force git mode (skip jj detection)").option("--dev", "run with Vite dev server for development").option("--host <address>", "address to bind the HTTP server to", "localhost").option("-p, --port <number>", "port for the browser UI (default: a free one)", parsePort).option("--no-open", "don't open a browser").option("--open-cmd <command>", "shell command that opens the page, given the URL as its last argument (default: $SKEPSIS_OPEN, else the system opener)").option("--no-poll", "don't check for changes to the diff while the page is open").option("--send <command>", "add a Send button that pipes the comment to this shell command (default: $SKEPSIS_SEND)").argument("[files...]", "Limit diff to these paths (passed through to jj/git)").addHelpText("after", "\nOnce the server is listening, it prints one line to stdout,\n`skepsis on <url> (<diff command>)`, for scripts that start it in the\nbackground with --no-open. The URL ends in a per-run #token= the page\nneeds, so open it whole.\n\nWith --send, the comment box sends to `sh -c <command>`, run in this\ndirectory, with the comment as one JSON object on stdin (its `prompt`\nfield has it all as plain text). Exit 0 means delivered; anything else,\nor taking over 10 s, is an error, and stderr is shown.\nSee the README for the fields and recipes.").parse();
|
|
29101
|
+
const program = new Command().name("skepsis").description("Local diff review UI (auto-detects jj or git)").option("-r, --revisions <revsets>", "Show changes in these revisions").option("-f, --from <rev>", "Show changes from this revision").option("-t, --to <rev>", "Show changes to this revision").option("--interdiff", "Show how the change in --to differs from the change in --from (jj only)").option("--git", "force git mode (skip jj detection)").option("--dev", "run with Vite dev server for development").option("--host <address>", "address to bind the HTTP server to", "localhost").option("-p, --port <number>", "port for the browser UI (default: a free one)", parsePort).option("--no-open", "don't open a browser").option("--open-cmd <command>", "shell command that opens the page, given the URL as its last argument (default: $SKEPSIS_OPEN, else the system opener)").option("--no-poll", "don't check for changes to the diff while the page is open").option("--send <command>", "add a Send button that pipes the comment to this shell command (default: $SKEPSIS_SEND)").argument("[files...]", "Limit diff to these paths (passed through to jj/git)").addHelpText("after", "\nOnce the server is listening, it prints one line to stdout,\n`skepsis on <url> (<diff command>)`, for scripts that start it in the\nbackground with --no-open. The URL ends in a per-run #token= the page\nneeds, so open it whole.\n\nWith --send, the comment box sends to `sh -c <command>`, run in this\ndirectory, with the comment as one JSON object on stdin (its `prompt`\nfield has it all as plain text). Exit 0 means delivered; anything else,\nor taking over 10 s, is an error, and stderr is shown.\nSee the README for the fields and recipes.").parse();
|
|
28940
29102
|
const opts = program.opts();
|
|
29103
|
+
function fail(message) {
|
|
29104
|
+
console.error(message);
|
|
29105
|
+
process.exit(1);
|
|
29106
|
+
}
|
|
28941
29107
|
const files = program.processedArgs[0] ?? [];
|
|
28942
29108
|
const hostname = opts.host;
|
|
28943
29109
|
const openCmd = (opts.openCmd ?? process.env["SKEPSIS_OPEN"]) || null;
|
|
28944
29110
|
const send = (opts.send ?? process.env["SKEPSIS_SEND"]) || null;
|
|
28945
|
-
if (send && !LOOPBACK.has(hostname === "::1" ? "[::1]" : hostname)) {
|
|
28946
|
-
console.error(`--send runs a command on request from the page, so it needs a loopback\n--host (localhost, 127.0.0.1 or ::1), not ${hostname}.`);
|
|
28947
|
-
process.exit(1);
|
|
28948
|
-
}
|
|
29111
|
+
if (send && !LOOPBACK.has(hostname === "::1" ? "[::1]" : hostname)) fail(`--send runs a command on request from the page, so it needs a loopback\n--host (localhost, 127.0.0.1 or ::1), not ${hostname}.`);
|
|
28949
29112
|
function detectVcs() {
|
|
28950
29113
|
try {
|
|
28951
29114
|
execFileSync("jj", ["root"], { stdio: "ignore" });
|
|
@@ -28960,6 +29123,11 @@ function detectVcs() {
|
|
|
28960
29123
|
}
|
|
28961
29124
|
}
|
|
28962
29125
|
const vcs = opts.git ? "git" : detectVcs();
|
|
29126
|
+
if (opts.interdiff) {
|
|
29127
|
+
if (vcs !== "jj") fail("--interdiff needs jj");
|
|
29128
|
+
if (opts.revisions) fail("--interdiff can't be combined with -r");
|
|
29129
|
+
if (!opts.from && !opts.to) fail("--interdiff needs -f, -t, or both");
|
|
29130
|
+
}
|
|
28963
29131
|
const GIT_BASE_CANDIDATES = [
|
|
28964
29132
|
"origin/HEAD",
|
|
28965
29133
|
"origin/main",
|
|
@@ -28989,13 +29157,9 @@ function resolveGitBase() {
|
|
|
28989
29157
|
};
|
|
28990
29158
|
} catch (error) {
|
|
28991
29159
|
const { code, stderr } = error;
|
|
28992
|
-
if (code === "ENOENT" || stderr?.includes("not a git repository"))
|
|
28993
|
-
console.error(stderr?.trim() || error.message);
|
|
28994
|
-
process.exit(1);
|
|
28995
|
-
}
|
|
29160
|
+
if (code === "ENOENT" || stderr?.includes("not a git repository")) fail(stderr?.trim() || error.message);
|
|
28996
29161
|
}
|
|
28997
|
-
|
|
28998
|
-
process.exit(1);
|
|
29162
|
+
fail(`No base revision found for the default diff (tried ${GIT_BASE_CANDIDATES.join(", ")}).\nSpecify a range explicitly with -r or -f/-t.`);
|
|
28999
29163
|
}
|
|
29000
29164
|
/** Split an `A..B` range into its two revs. Returns null for anything that
|
|
29001
29165
|
* isn't a simple two-sided range with both sides non-empty. */
|
|
@@ -29013,21 +29177,21 @@ function parseRange(rev) {
|
|
|
29013
29177
|
function buildDiffSource() {
|
|
29014
29178
|
if (vcs === "jj") {
|
|
29015
29179
|
const args = [];
|
|
29016
|
-
let
|
|
29180
|
+
let toWorkingCopy;
|
|
29017
29181
|
let endpoints;
|
|
29018
29182
|
if (opts.from || opts.to || !opts.revisions) {
|
|
29019
29183
|
const from = opts.from ?? (opts.to ? void 0 : "fork_point(trunk() | @)");
|
|
29020
29184
|
if (from) args.push("--from", from);
|
|
29021
29185
|
if (opts.to) args.push("--to", opts.to);
|
|
29022
|
-
|
|
29023
|
-
endpoints = {
|
|
29186
|
+
toWorkingCopy = !opts.to || opts.to === "@";
|
|
29187
|
+
endpoints = opts.interdiff ? null : {
|
|
29024
29188
|
left: from ?? "@",
|
|
29025
29189
|
right: { rev: opts.to ?? "@" }
|
|
29026
29190
|
};
|
|
29027
29191
|
} else {
|
|
29028
29192
|
const rev = opts.revisions;
|
|
29029
29193
|
args.push("-r", rev);
|
|
29030
|
-
|
|
29194
|
+
toWorkingCopy = rev === "@" || rev.endsWith("..@");
|
|
29031
29195
|
const range = parseRange(rev);
|
|
29032
29196
|
if (range) endpoints = {
|
|
29033
29197
|
left: range.left,
|
|
@@ -29041,27 +29205,28 @@ function buildDiffSource() {
|
|
|
29041
29205
|
}
|
|
29042
29206
|
return {
|
|
29043
29207
|
vcs: "jj",
|
|
29208
|
+
interdiff: opts.interdiff,
|
|
29044
29209
|
args,
|
|
29045
|
-
|
|
29210
|
+
toWorkingCopy,
|
|
29046
29211
|
files,
|
|
29047
29212
|
endpoints
|
|
29048
29213
|
};
|
|
29049
29214
|
} else {
|
|
29050
29215
|
let args;
|
|
29051
|
-
let
|
|
29216
|
+
let toWorkingCopy;
|
|
29052
29217
|
let endpoints;
|
|
29053
29218
|
let displayArgs;
|
|
29054
29219
|
if (opts.from || opts.to) {
|
|
29055
29220
|
if (opts.to) {
|
|
29056
29221
|
args = [opts.from ?? "HEAD", opts.to];
|
|
29057
|
-
|
|
29222
|
+
toWorkingCopy = false;
|
|
29058
29223
|
endpoints = {
|
|
29059
29224
|
left: opts.from ?? "HEAD",
|
|
29060
29225
|
right: { rev: opts.to }
|
|
29061
29226
|
};
|
|
29062
29227
|
} else {
|
|
29063
29228
|
args = [opts.from];
|
|
29064
|
-
|
|
29229
|
+
toWorkingCopy = true;
|
|
29065
29230
|
endpoints = {
|
|
29066
29231
|
left: opts.from,
|
|
29067
29232
|
right: "workingCopy"
|
|
@@ -29071,14 +29236,14 @@ function buildDiffSource() {
|
|
|
29071
29236
|
const { base, mergeBase } = resolveGitBase();
|
|
29072
29237
|
args = [mergeBase];
|
|
29073
29238
|
displayArgs = ["--merge-base", base];
|
|
29074
|
-
|
|
29239
|
+
toWorkingCopy = true;
|
|
29075
29240
|
endpoints = {
|
|
29076
29241
|
left: mergeBase,
|
|
29077
29242
|
right: "workingCopy"
|
|
29078
29243
|
};
|
|
29079
29244
|
} else {
|
|
29080
29245
|
const rev = opts.revisions;
|
|
29081
|
-
|
|
29246
|
+
toWorkingCopy = !rev.includes("..");
|
|
29082
29247
|
args = [rev];
|
|
29083
29248
|
const range = parseRange(rev);
|
|
29084
29249
|
if (range) endpoints = {
|
|
@@ -29094,7 +29259,7 @@ function buildDiffSource() {
|
|
|
29094
29259
|
return {
|
|
29095
29260
|
vcs: "git",
|
|
29096
29261
|
args,
|
|
29097
|
-
|
|
29262
|
+
toWorkingCopy,
|
|
29098
29263
|
files,
|
|
29099
29264
|
endpoints,
|
|
29100
29265
|
displayArgs
|