@oxide/skepsis 0.8.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 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`.
package/dist/cli.js CHANGED
@@ -6496,13 +6496,17 @@ const GIT_PREFIX_OVERRIDE = [
6496
6496
  "diff.dstPrefix=b/"
6497
6497
  ];
6498
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
+ }
6499
6503
  function diffCommand(src) {
6500
6504
  const fileArgs = src.files.length > 0 ? ["--", ...src.files] : [];
6501
6505
  if (src.vcs === "jj") return {
6502
6506
  cmd: "jj",
6503
6507
  args: [
6504
6508
  ...JJ_PREFIX_OVERRIDE,
6505
- "diff",
6509
+ subcommand(src),
6506
6510
  ...src.args,
6507
6511
  "--git",
6508
6512
  ...fileArgs
@@ -6548,11 +6552,11 @@ function normalizeJjRenames(patch) {
6548
6552
  async function getDiff(src) {
6549
6553
  const { cmd, args } = diffCommand(src);
6550
6554
  const { stdout, stderr, code } = await run(cmd, args);
6551
- if (code !== 0) throw new Error(`${cmd} diff failed (exit ${code}): ${stderr}`);
6555
+ if (code !== 0) throw new Error(`${cmd} ${subcommand(src)} failed (exit ${code}): ${stderr}`);
6552
6556
  const patch = src.vcs === "jj" ? normalizeJjRenames(stdout) : stdout;
6553
6557
  return {
6554
6558
  patch,
6555
- fileHashes: extractFileHashes(patch)
6559
+ fileHashes: extractFileHashes(patch, src.interdiff)
6556
6560
  };
6557
6561
  }
6558
6562
  /** A short content hash of the whole patch, so the page can ask whether the
@@ -6571,31 +6575,35 @@ function patchHash(patch) {
6571
6575
  * of their extended header lines instead. That changes when the rename or
6572
6576
  * mode does, and a content change adds an index line, so viewed state still
6573
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.
6574
6582
  */
6575
- function extractFileHashes(patch) {
6583
+ function extractFileHashes(patch, interdiff = false) {
6576
6584
  const hashes = {};
6577
6585
  let currentFile = null;
6578
- let header = [];
6579
- const finishHeaderOnly = () => {
6586
+ let block = [];
6587
+ const hashBlock = () => {
6580
6588
  if (currentFile == null) return;
6581
- hashes[currentFile] = createHash("sha1").update(header.join("\n")).digest("hex").slice(0, 12);
6589
+ hashes[currentFile] = createHash("sha1").update(block.join("\n")).digest("hex").slice(0, 12);
6582
6590
  };
6583
6591
  for (const line of patch.split("\n")) {
6584
6592
  const diffMatch = line.match(/^diff --git a\/.+ b\/(.+)$/);
6585
6593
  if (diffMatch) {
6586
- finishHeaderOnly();
6594
+ hashBlock();
6587
6595
  currentFile = diffMatch[1];
6588
- header = [line];
6596
+ block = [line];
6589
6597
  continue;
6590
6598
  }
6591
6599
  if (currentFile == null) continue;
6592
- if (line.startsWith("index ")) {
6600
+ if (line.startsWith("index ") && !interdiff) {
6593
6601
  const indexMatch = line.match(/^index [0-9a-f]+\.\.([0-9a-f]+)/);
6594
6602
  if (indexMatch) hashes[currentFile] = indexMatch[1];
6595
6603
  currentFile = null;
6596
- } else header.push(line);
6604
+ } else block.push(line);
6597
6605
  }
6598
- finishHeaderOnly();
6606
+ hashBlock();
6599
6607
  return hashes;
6600
6608
  }
6601
6609
  // server/displayCommand.ts
@@ -6610,7 +6618,7 @@ function displayCommand(diffSource) {
6610
6618
  const args = (diffSource.displayArgs ?? diffSource.args).map(shellQuote);
6611
6619
  const files = diffSource.files.map(shellQuote);
6612
6620
  const fileSuffix = files.length > 0 ? ` -- ${files.join(" ")}` : "";
6613
- return `${diffSource.vcs} diff ${args.join(" ")}${fileSuffix}`;
6621
+ return `${diffSource.vcs} ${subcommand(diffSource)} ${args.join(" ")}${fileSuffix}`;
6614
6622
  }
6615
6623
  // server/fileContents.ts
6616
6624
  /**
@@ -28804,7 +28812,7 @@ function buildPayload(diffSource, root, input) {
28804
28812
  root,
28805
28813
  diff: {
28806
28814
  command: displayCommand(diffSource),
28807
- toWorkingCopy: diffSource.commentsEnabled
28815
+ toWorkingCopy: diffSource.toWorkingCopy
28808
28816
  },
28809
28817
  file: input.file,
28810
28818
  side: input.side,
@@ -28948,20 +28956,22 @@ async function startServer(opts) {
28948
28956
  if (c.req.path === "/api/theme.js" || tokenMatches(c.req.header("X-Skepsis-Token"), token)) return next();
28949
28957
  return c.json({ error: "This page has no valid token. Open the URL skepsis printed when it started." }, 401);
28950
28958
  });
28959
+ const commentsEnabled = diffSource.toWorkingCopy && !diffSource.interdiff;
28951
28960
  app.get("/api/diff", async (c) => {
28952
28961
  const { patch, fileHashes } = await getDiff(diffSource);
28953
28962
  const files = Object.keys(fileHashes);
28954
28963
  const [viewed, generated, commentSyntaxes] = await Promise.all([
28955
28964
  loadViewed(cwd, fileHashes),
28956
28965
  getGeneratedFiles(cwd, files),
28957
- diffSource.commentsEnabled ? getCommentSyntaxes(cwd, files) : {}
28966
+ commentsEnabled ? getCommentSyntaxes(cwd, files) : {}
28958
28967
  ]);
28959
28968
  return c.json({
28960
28969
  patch,
28961
28970
  revset: displayCommand(diffSource),
28962
28971
  repo: basename(cwd),
28963
28972
  vcs: diffSource.vcs,
28964
- commentsEnabled: diffSource.commentsEnabled,
28973
+ interdiff: !!diffSource.interdiff,
28974
+ commentsEnabled,
28965
28975
  expandable: diffSource.endpoints !== null,
28966
28976
  fileHashes,
28967
28977
  patchHash: patchHash(patch),
@@ -29088,16 +29098,17 @@ function parsePort(value) {
29088
29098
  if (!(port >= 0 && port <= 65535)) throw new InvalidArgumentError("port must be an integer between 0 and 65535");
29089
29099
  return port;
29090
29100
  }
29091
- 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();
29092
29102
  const opts = program.opts();
29103
+ function fail(message) {
29104
+ console.error(message);
29105
+ process.exit(1);
29106
+ }
29093
29107
  const files = program.processedArgs[0] ?? [];
29094
29108
  const hostname = opts.host;
29095
29109
  const openCmd = (opts.openCmd ?? process.env["SKEPSIS_OPEN"]) || null;
29096
29110
  const send = (opts.send ?? process.env["SKEPSIS_SEND"]) || null;
29097
- if (send && !LOOPBACK.has(hostname === "::1" ? "[::1]" : hostname)) {
29098
- 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}.`);
29099
- process.exit(1);
29100
- }
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}.`);
29101
29112
  function detectVcs() {
29102
29113
  try {
29103
29114
  execFileSync("jj", ["root"], { stdio: "ignore" });
@@ -29112,6 +29123,11 @@ function detectVcs() {
29112
29123
  }
29113
29124
  }
29114
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
+ }
29115
29131
  const GIT_BASE_CANDIDATES = [
29116
29132
  "origin/HEAD",
29117
29133
  "origin/main",
@@ -29141,13 +29157,9 @@ function resolveGitBase() {
29141
29157
  };
29142
29158
  } catch (error) {
29143
29159
  const { code, stderr } = error;
29144
- if (code === "ENOENT" || stderr?.includes("not a git repository")) {
29145
- console.error(stderr?.trim() || error.message);
29146
- process.exit(1);
29147
- }
29160
+ if (code === "ENOENT" || stderr?.includes("not a git repository")) fail(stderr?.trim() || error.message);
29148
29161
  }
29149
- console.error(`No base revision found for the default diff (tried ${GIT_BASE_CANDIDATES.join(", ")}).\nSpecify a range explicitly with -r or -f/-t.`);
29150
- 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.`);
29151
29163
  }
29152
29164
  /** Split an `A..B` range into its two revs. Returns null for anything that
29153
29165
  * isn't a simple two-sided range with both sides non-empty. */
@@ -29165,21 +29177,21 @@ function parseRange(rev) {
29165
29177
  function buildDiffSource() {
29166
29178
  if (vcs === "jj") {
29167
29179
  const args = [];
29168
- let commentsEnabled;
29180
+ let toWorkingCopy;
29169
29181
  let endpoints;
29170
29182
  if (opts.from || opts.to || !opts.revisions) {
29171
29183
  const from = opts.from ?? (opts.to ? void 0 : "fork_point(trunk() | @)");
29172
29184
  if (from) args.push("--from", from);
29173
29185
  if (opts.to) args.push("--to", opts.to);
29174
- commentsEnabled = !opts.to || opts.to === "@";
29175
- endpoints = {
29186
+ toWorkingCopy = !opts.to || opts.to === "@";
29187
+ endpoints = opts.interdiff ? null : {
29176
29188
  left: from ?? "@",
29177
29189
  right: { rev: opts.to ?? "@" }
29178
29190
  };
29179
29191
  } else {
29180
29192
  const rev = opts.revisions;
29181
29193
  args.push("-r", rev);
29182
- commentsEnabled = rev === "@" || rev.endsWith("..@");
29194
+ toWorkingCopy = rev === "@" || rev.endsWith("..@");
29183
29195
  const range = parseRange(rev);
29184
29196
  if (range) endpoints = {
29185
29197
  left: range.left,
@@ -29193,27 +29205,28 @@ function buildDiffSource() {
29193
29205
  }
29194
29206
  return {
29195
29207
  vcs: "jj",
29208
+ interdiff: opts.interdiff,
29196
29209
  args,
29197
- commentsEnabled,
29210
+ toWorkingCopy,
29198
29211
  files,
29199
29212
  endpoints
29200
29213
  };
29201
29214
  } else {
29202
29215
  let args;
29203
- let commentsEnabled;
29216
+ let toWorkingCopy;
29204
29217
  let endpoints;
29205
29218
  let displayArgs;
29206
29219
  if (opts.from || opts.to) {
29207
29220
  if (opts.to) {
29208
29221
  args = [opts.from ?? "HEAD", opts.to];
29209
- commentsEnabled = false;
29222
+ toWorkingCopy = false;
29210
29223
  endpoints = {
29211
29224
  left: opts.from ?? "HEAD",
29212
29225
  right: { rev: opts.to }
29213
29226
  };
29214
29227
  } else {
29215
29228
  args = [opts.from];
29216
- commentsEnabled = true;
29229
+ toWorkingCopy = true;
29217
29230
  endpoints = {
29218
29231
  left: opts.from,
29219
29232
  right: "workingCopy"
@@ -29223,14 +29236,14 @@ function buildDiffSource() {
29223
29236
  const { base, mergeBase } = resolveGitBase();
29224
29237
  args = [mergeBase];
29225
29238
  displayArgs = ["--merge-base", base];
29226
- commentsEnabled = true;
29239
+ toWorkingCopy = true;
29227
29240
  endpoints = {
29228
29241
  left: mergeBase,
29229
29242
  right: "workingCopy"
29230
29243
  };
29231
29244
  } else {
29232
29245
  const rev = opts.revisions;
29233
- commentsEnabled = !rev.includes("..");
29246
+ toWorkingCopy = !rev.includes("..");
29234
29247
  args = [rev];
29235
29248
  const range = parseRange(rev);
29236
29249
  if (range) endpoints = {
@@ -29246,7 +29259,7 @@ function buildDiffSource() {
29246
29259
  return {
29247
29260
  vcs: "git",
29248
29261
  args,
29249
- commentsEnabled,
29262
+ toWorkingCopy,
29250
29263
  files,
29251
29264
  endpoints,
29252
29265
  displayArgs