@oxide/skepsis 0.7.0 → 0.8.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 +16 -2
- package/dist/cli.js +187 -35
- package/dist/web/assets/{highlights-Bu3jR2kn.js → highlights-xCDO0bP7.js} +1 -1
- package/dist/web/assets/index-Ds8xdel2.css +1 -0
- package/dist/web/assets/{index-DsJL1wFW.js → index-w_HTIb39.js} +16 -7
- package/dist/web/assets/{shiki-vIC6REHJ.js → shiki-CoZZwYQ-.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
|
@@ -154,6 +154,14 @@ const end = Number(match[2])
|
|
|
154
154
|
// </review>
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
+
Selecting text in the diff also opens the comment box, to comment on part of a
|
|
158
|
+
line rather than the whole thing. The box opens directly under the selection,
|
|
159
|
+
and the selected text stays highlighted while you write. Selecting whole lines
|
|
160
|
+
(a triple-click, say) is the same as commenting from the gutter. While the box
|
|
161
|
+
is empty, clicking elsewhere in the code closes it, and ⌘C copies the selected
|
|
162
|
+
text. The open tag quotes the selection, eliding the middle if it's long:
|
|
163
|
+
`<review on="Number(match[1])">`.
|
|
164
|
+
|
|
157
165
|
### Marking files viewed
|
|
158
166
|
|
|
159
167
|
Viewed state is stored per file in `~/.local/share/skepsis/` using the file's
|
|
@@ -169,7 +177,9 @@ agent, a tmux pane, or a log. There is not chat UI in skepsis (yet) so replies
|
|
|
169
177
|
from the agent will appear in that session, wherever it is. Send works
|
|
170
178
|
in some cases that inline comments can't (because there is no file to write): on
|
|
171
179
|
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.
|
|
180
|
+
button continues to write a `<review>` marker in the file as usual. When you
|
|
181
|
+
send a comment on selected text, the message includes where the selection
|
|
182
|
+
starts and ends.
|
|
173
183
|
|
|
174
184
|
The only way to set the command is `--send` or `SKEPSIS_SEND`. skepsis never
|
|
175
185
|
reads it from the repo contents, so reviewing someone else's branch
|
|
@@ -212,6 +222,7 @@ The JSON sent to stdin looks like this:
|
|
|
212
222
|
"file": "src/a.ts",
|
|
213
223
|
"side": "additions",
|
|
214
224
|
"lines": [42, 45],
|
|
225
|
+
"columns": null,
|
|
215
226
|
"code": [{ "lines": [41, 46], "text": "const z = 0\nconst a = 1\n…" }],
|
|
216
227
|
"blob": "9daeafb",
|
|
217
228
|
"text": "why two?",
|
|
@@ -220,7 +231,10 @@ The JSON sent to stdin looks like this:
|
|
|
220
231
|
````
|
|
221
232
|
|
|
222
233
|
`side` is `additions` or `deletions`, and `lines` (1-based, inclusive) are in
|
|
223
|
-
that side's numbering. `
|
|
234
|
+
that side's numbering. `columns` is set when the comment is on selected text
|
|
235
|
+
rather than whole lines: where the text starts in the first line and ends
|
|
236
|
+
(exclusive) in the last, 0-based, in UTF-16 code units. The prompt then marks
|
|
237
|
+
the text in the excerpt with `⟦` and `⟧`. `code` is an excerpt of that side around the lines
|
|
224
238
|
commented on, in runs of consecutive lines, each with its own first and last
|
|
225
239
|
line. There's more than one run when the lines commented on span lines the
|
|
226
240
|
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 {
|
|
@@ -6648,6 +6671,76 @@ async function getFileContents(src, cwd, path, oldPath) {
|
|
|
6648
6671
|
newContents
|
|
6649
6672
|
};
|
|
6650
6673
|
}
|
|
6674
|
+
// server/generated.ts
|
|
6675
|
+
const execFileAsync = promisify(execFile);
|
|
6676
|
+
/** Lockfiles count as generated unless the repo says otherwise. */
|
|
6677
|
+
const LOCKFILES = /* @__PURE__ */ new Set([
|
|
6678
|
+
"Cargo.lock",
|
|
6679
|
+
"package-lock.json",
|
|
6680
|
+
"npm-shrinkwrap.json",
|
|
6681
|
+
"pnpm-lock.yaml",
|
|
6682
|
+
"yarn.lock",
|
|
6683
|
+
"bun.lock",
|
|
6684
|
+
"bun.lockb",
|
|
6685
|
+
"deno.lock",
|
|
6686
|
+
"go.sum",
|
|
6687
|
+
"poetry.lock",
|
|
6688
|
+
"uv.lock",
|
|
6689
|
+
"Pipfile.lock",
|
|
6690
|
+
"Gemfile.lock",
|
|
6691
|
+
"composer.lock",
|
|
6692
|
+
"flake.lock"
|
|
6693
|
+
]);
|
|
6694
|
+
/**
|
|
6695
|
+
* The files among `files` that are generated, which the page starts
|
|
6696
|
+
* collapsed, as GitHub does. The `linguist-generated` git attribute decides
|
|
6697
|
+
* whenever it's specified: like Linguist, any value but `false` means
|
|
6698
|
+
* generated. Otherwise only lockfiles count. git reads the attribute from
|
|
6699
|
+
* .gitattributes, .git/info/attributes, and core.attributesFile, so
|
|
6700
|
+
* patterns don't have to be checked in. Without git
|
|
6701
|
+
* (a jj repo with no colocated .git), only the lockfile rule applies.
|
|
6702
|
+
*/
|
|
6703
|
+
async function getGeneratedFiles(cwd, files) {
|
|
6704
|
+
if (files.length === 0) return [];
|
|
6705
|
+
const attrs = await checkAttr(cwd, files).catch(() => /* @__PURE__ */ new Map());
|
|
6706
|
+
return files.filter((file) => {
|
|
6707
|
+
const value = attrs.get(file);
|
|
6708
|
+
if (value === void 0 || value === "unspecified") return LOCKFILES.has(basename(file));
|
|
6709
|
+
return value !== "unset" && value !== "false";
|
|
6710
|
+
});
|
|
6711
|
+
}
|
|
6712
|
+
/** Each file's `linguist-generated` value: set, unset, unspecified, or the
|
|
6713
|
+
* string it's set to (e.g. `true` for `linguist-generated=true`). */
|
|
6714
|
+
async function checkAttr(cwd, files) {
|
|
6715
|
+
const { stdout: top } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], { cwd });
|
|
6716
|
+
return new Promise((resolve, reject) => {
|
|
6717
|
+
const proc = spawn$1("git", [
|
|
6718
|
+
"check-attr",
|
|
6719
|
+
"-z",
|
|
6720
|
+
"--stdin",
|
|
6721
|
+
"linguist-generated"
|
|
6722
|
+
], {
|
|
6723
|
+
cwd: top.trim(),
|
|
6724
|
+
stdio: [
|
|
6725
|
+
"pipe",
|
|
6726
|
+
"pipe",
|
|
6727
|
+
"ignore"
|
|
6728
|
+
]
|
|
6729
|
+
});
|
|
6730
|
+
const stdout = [];
|
|
6731
|
+
proc.stdout.on("data", (d) => stdout.push(d));
|
|
6732
|
+
proc.on("error", reject);
|
|
6733
|
+
proc.stdin.on("error", () => {});
|
|
6734
|
+
proc.on("close", (code) => {
|
|
6735
|
+
if (code !== 0) return reject(/* @__PURE__ */ new Error(`git check-attr exited ${code}`));
|
|
6736
|
+
const fields = Buffer.concat(stdout).toString().split("\0");
|
|
6737
|
+
const values = /* @__PURE__ */ new Map();
|
|
6738
|
+
for (let i = 0; i + 2 < fields.length; i += 3) values.set(fields[i], fields[i + 2]);
|
|
6739
|
+
resolve(values);
|
|
6740
|
+
});
|
|
6741
|
+
proc.stdin.end(files.map((f) => f + "\0").join(""));
|
|
6742
|
+
});
|
|
6743
|
+
}
|
|
6651
6744
|
// server/viewed.ts
|
|
6652
6745
|
/**
|
|
6653
6746
|
* Viewed state: tracks which files the user has marked as viewed.
|
|
@@ -22903,9 +22996,25 @@ const REVIEW_CLOSE_TAG = "</review>";
|
|
|
22903
22996
|
* stays right when lines above it are added or removed, including by other
|
|
22904
22997
|
* comments. The value is in words because agents read it: in testing,
|
|
22905
22998
|
* 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
|
-
|
|
22999
|
+
* and never misread this. A plain `<review>` covers the line just above.
|
|
23000
|
+
*
|
|
23001
|
+
* A comment on some of the text in those lines says which with `on`:
|
|
23002
|
+
* `<review on="the quick … lazy dog">`. It's one line, and cut in the middle
|
|
23003
|
+
* past QUOTE_MAX characters, since the tag sits right under the text and the
|
|
23004
|
+
* two ends are enough to find it there. */
|
|
23005
|
+
function reviewOpenTag(lines, quote) {
|
|
23006
|
+
const on = quote && shortQuote(quote, QUOTE_MAX).replaceAll("\"", """);
|
|
23007
|
+
const text = [lines > 1 && `covers="${lines} lines above"`, on && `on="${on}"`].filter(Boolean).join(" ");
|
|
23008
|
+
return text ? `<review ${text}>` : REVIEW_OPEN_TAG;
|
|
23009
|
+
}
|
|
23010
|
+
const QUOTE_MAX = 80;
|
|
23011
|
+
/** `quote` on one line, with the middle cut out if it's over `max`
|
|
23012
|
+
* characters. It cuts between code points, so it can't split an emoji. */
|
|
23013
|
+
function shortQuote(quote, max) {
|
|
23014
|
+
const chars = [...quote.replace(/\s+/g, " ").trim()];
|
|
23015
|
+
if (chars.length <= max) return chars.join("");
|
|
23016
|
+
const half = (max - 3) / 2;
|
|
23017
|
+
return `${chars.slice(0, Math.ceil(half)).join("").trimEnd()} … ${chars.slice(-Math.floor(half)).join("").trimStart()}`;
|
|
22909
23018
|
}
|
|
22910
23019
|
const OPEN_TAG_SOURCE = "<review(?:\\s+[\\w-]+=\"[^\"]*\")*\\s*>";
|
|
22911
23020
|
new RegExp(OPEN_TAG_SOURCE);
|
|
@@ -23197,7 +23306,7 @@ async function getCommentSyntaxes(cwd, files) {
|
|
|
23197
23306
|
async function assertNotSymlink(cwd, file) {
|
|
23198
23307
|
if ((await lstat(join(cwd, file)).catch(() => null))?.isSymbolicLink()) throw new Error(`Cannot comment on symlink: ${file}`);
|
|
23199
23308
|
}
|
|
23200
|
-
async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1) {
|
|
23309
|
+
async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1, quote) {
|
|
23201
23310
|
await assertNotSymlink(cwd, file);
|
|
23202
23311
|
const filePath = join(cwd, file);
|
|
23203
23312
|
const lines = (await readFile(filePath, "utf-8")).split("\n");
|
|
@@ -23214,7 +23323,7 @@ async function insertComment(cwd, file, afterLine, lineText, text, lineCount = 1
|
|
|
23214
23323
|
suffix
|
|
23215
23324
|
].filter(Boolean).join(" ");
|
|
23216
23325
|
const commentLines = [
|
|
23217
|
-
wrap(reviewOpenTag(Math.min(lineCount, afterLine))),
|
|
23326
|
+
wrap(reviewOpenTag(Math.min(lineCount, afterLine), quote)),
|
|
23218
23327
|
...text.split("\n").map((line) => wrap(line)),
|
|
23219
23328
|
wrap(REVIEW_CLOSE_TAG)
|
|
23220
23329
|
];
|
|
@@ -28576,7 +28685,9 @@ const commentRequestSchema = object({
|
|
|
28576
28685
|
lineText: string(),
|
|
28577
28686
|
text: string(),
|
|
28578
28687
|
/** How many lines the comment covers, ending at afterLine. */
|
|
28579
|
-
lineCount: number().int().min(1).optional()
|
|
28688
|
+
lineCount: number().int().min(1).optional(),
|
|
28689
|
+
/** The selected text, for a comment on part of those lines. */
|
|
28690
|
+
quote: string().optional()
|
|
28580
28691
|
});
|
|
28581
28692
|
/** A comment for the --send command. Only `text` is required by the
|
|
28582
28693
|
* contract; the page always anchors it to lines. */
|
|
@@ -28584,6 +28695,10 @@ const sendRequestSchema = object({
|
|
|
28584
28695
|
file: string().nullable(),
|
|
28585
28696
|
side: _enum(["additions", "deletions"]).nullable(),
|
|
28586
28697
|
lines: tuple([number().int().positive(), number().int().positive()]).nullable(),
|
|
28698
|
+
/** For a comment on selected text rather than whole lines: where the text
|
|
28699
|
+
* starts in the first line and ends (exclusive) in the last, 0-based, in
|
|
28700
|
+
* UTF-16 code units. */
|
|
28701
|
+
columns: tuple([number().int().nonnegative(), number().int().nonnegative()]).nullable(),
|
|
28587
28702
|
/** An excerpt around the lines commented on, as runs of consecutive lines
|
|
28588
28703
|
* with each run's first and last line. Lines the diff hides split it. */
|
|
28589
28704
|
code: array(object({
|
|
@@ -28694,6 +28809,7 @@ function buildPayload(diffSource, root, input) {
|
|
|
28694
28809
|
file: input.file,
|
|
28695
28810
|
side: input.side,
|
|
28696
28811
|
lines: input.lines,
|
|
28812
|
+
columns: input.columns,
|
|
28697
28813
|
code: input.code,
|
|
28698
28814
|
blob: input.blob,
|
|
28699
28815
|
text: input.text
|
|
@@ -28708,6 +28824,35 @@ function fence(code) {
|
|
|
28708
28824
|
const longest = Math.max(0, ...(code.match(/`+/g) ?? []).map((run) => run.length));
|
|
28709
28825
|
return "`".repeat(Math.max(3, longest + 1));
|
|
28710
28826
|
}
|
|
28827
|
+
/** Where the selected text starts and ends, as start-of-text and end-of-text
|
|
28828
|
+
* marks put into the excerpt. */
|
|
28829
|
+
const MARKS = ["⟦", "⟧"];
|
|
28830
|
+
/** `code` with `columns` marked: the start in line `lines[0]` and the end in
|
|
28831
|
+
* `lines[1]`. Null when the excerpt doesn't hold both lines. */
|
|
28832
|
+
function markExcerpt(code, lines, columns) {
|
|
28833
|
+
const runs = code.map((run) => ({
|
|
28834
|
+
...run,
|
|
28835
|
+
rows: run.text.split("\n")
|
|
28836
|
+
}));
|
|
28837
|
+
const points = [0, 1].map((i) => {
|
|
28838
|
+
const run = runs.find((r) => lines[i] >= r.lines[0] && lines[i] <= r.lines[1]);
|
|
28839
|
+
return run && {
|
|
28840
|
+
run,
|
|
28841
|
+
row: lines[i] - run.lines[0]
|
|
28842
|
+
};
|
|
28843
|
+
});
|
|
28844
|
+
if (!points[0] || !points[1]) return null;
|
|
28845
|
+
for (const i of [1, 0]) {
|
|
28846
|
+
const { run, row } = points[i];
|
|
28847
|
+
const text = run.rows[row];
|
|
28848
|
+
const col = Math.min(columns[i], text.length);
|
|
28849
|
+
run.rows[row] = text.slice(0, col) + MARKS[i] + text.slice(col);
|
|
28850
|
+
}
|
|
28851
|
+
return runs.map(({ lines: range, rows }) => ({
|
|
28852
|
+
lines: range,
|
|
28853
|
+
text: rows.join("\n")
|
|
28854
|
+
}));
|
|
28855
|
+
}
|
|
28711
28856
|
function renderPrompt(p) {
|
|
28712
28857
|
const command = `\`${p.diff.command}\``;
|
|
28713
28858
|
if (p.file === null) return `Review comment on ${command}:\n\n${p.text}`;
|
|
@@ -28716,11 +28861,13 @@ function renderPrompt(p) {
|
|
|
28716
28861
|
const head = `Review comment on ${p.file}${where} (${side} of ${command})`;
|
|
28717
28862
|
if (!p.code) return `${head}:\n\n${p.text}`;
|
|
28718
28863
|
const ranges = p.code.map(({ lines: [first, last] }) => first === last ? `line ${first}` : `lines ${first}–${last}`);
|
|
28719
|
-
const
|
|
28864
|
+
const marked = p.lines && p.columns && markExcerpt(p.code, p.lines, p.columns);
|
|
28865
|
+
const on = marked ? `, on the text between ${MARKS[0]} and ${MARKS[1]}` : "";
|
|
28866
|
+
const excerpts = (marked ?? p.code).map(({ text }) => {
|
|
28720
28867
|
const f = fence(text);
|
|
28721
28868
|
return `${f}\n${text}\n${f}`;
|
|
28722
28869
|
});
|
|
28723
|
-
return `${head}, in ${ranges.join(" and ")}:\n\n${excerpts.join("\n\n")}\n\n${p.text}`;
|
|
28870
|
+
return `${head}${on}, in ${ranges.join(" and ")}:\n\n${excerpts.join("\n\n")}\n\n${p.text}`;
|
|
28724
28871
|
}
|
|
28725
28872
|
const TIMEOUT_MS = 1e4;
|
|
28726
28873
|
const MAX_OUTPUT = 65536;
|
|
@@ -28803,8 +28950,12 @@ async function startServer(opts) {
|
|
|
28803
28950
|
});
|
|
28804
28951
|
app.get("/api/diff", async (c) => {
|
|
28805
28952
|
const { patch, fileHashes } = await getDiff(diffSource);
|
|
28806
|
-
const
|
|
28807
|
-
const commentSyntaxes =
|
|
28953
|
+
const files = Object.keys(fileHashes);
|
|
28954
|
+
const [viewed, generated, commentSyntaxes] = await Promise.all([
|
|
28955
|
+
loadViewed(cwd, fileHashes),
|
|
28956
|
+
getGeneratedFiles(cwd, files),
|
|
28957
|
+
diffSource.commentsEnabled ? getCommentSyntaxes(cwd, files) : {}
|
|
28958
|
+
]);
|
|
28808
28959
|
return c.json({
|
|
28809
28960
|
patch,
|
|
28810
28961
|
revset: displayCommand(diffSource),
|
|
@@ -28817,7 +28968,8 @@ async function startServer(opts) {
|
|
|
28817
28968
|
poll,
|
|
28818
28969
|
send: !!send,
|
|
28819
28970
|
viewed,
|
|
28820
|
-
commentSyntaxes
|
|
28971
|
+
commentSyntaxes,
|
|
28972
|
+
generated
|
|
28821
28973
|
});
|
|
28822
28974
|
});
|
|
28823
28975
|
let hashInFlight = null;
|
|
@@ -28852,8 +29004,8 @@ async function startServer(opts) {
|
|
|
28852
29004
|
return c.json({ ok: true });
|
|
28853
29005
|
});
|
|
28854
29006
|
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);
|
|
29007
|
+
const { file, afterLine, lineText, text, lineCount, quote } = c.req.valid("json");
|
|
29008
|
+
await insertComment(cwd, file, afterLine, lineText, text, lineCount, quote);
|
|
28857
29009
|
hashInFlight = null;
|
|
28858
29010
|
return c.json({ ok: true });
|
|
28859
29011
|
});
|