Skip to content

Run jj and git in the diff's directory - #123

Merged
david-crespo merged 1 commit into
spr/extract-diff-selection-and-the-http-app-from-the-clifrom
spr/run-jj-and-git-in-the-diffs-directory
Nov 19, 2026
Merged

david-crespo merged 1 commit into
spr/extract-diff-selection-and-the-http-app-from-the-clifrom
spr/run-jj-and-git-in-the-diffs-directory

Conversation

@david-crespo

@david-crespo david-crespo commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Built on #122, this PR lets one process serve diffs from more than one repository. jj and git invocations, working-copy reads, and comment writes now take the repository directory as an argument. The static file middleware also receives an absolute path to the web files' directory, so nothing depends on the process's working directory. The CLI passes process.cwd(), so its behavior is the same. The directory is fixed when an app is built and each app has its own token, so a request can't choose a directory or reach another app's repository, and #121 keeps its file paths to the files in the diff. A new test builds two apps for separate repositories in one process and checks that each returns its own diff and file contents. About 160 of the 220 changed lines are tests: that test, and new unit tests for buildDiffSource and detectVcs in a directory other than the process's working directory. The source change is about 55 lines that add the directory argument.

@david-crespo
david-crespo force-pushed the spr/run-jj-and-git-in-the-diffs-directory branch from 023c145 to 16869b7 Compare November 19, 2026 18:20
@david-crespo
david-crespo merged commit d8e412f into main Nov 19, 2026
2 checks passed
@david-crespo
david-crespo deleted the spr/run-jj-and-git-in-the-diffs-directory branch November 19, 2026 18:43
david-crespo added a commit that referenced this pull request Nov 19, 2026
Built on #123, this PR lets another Node server mount the review page
under a URL prefix, for any number of diffs in one process.
`@oxide/skepsis` now exports `createApp`, which returns a `fetch`
handler and the token. The README has a new Embedding section. The
library API may change in a minor version while the package is 0.x.

Of about 920 changed lines, about 510 are tests, including a 90-line
refactor of the Playwright fixture that changes no test. Source is about
260 lines, the README and `CLAUDE.md` about 95, and build and CI config
about 55.

### Choosing the diff

A caller tells `createApp` which diff to show with the same options the
CLI has: `revisions` for `-r`, or `from` and `to` for `-f` and `-t`.
`createApp` works out the `jj` or `git` command from those, as the CLI
does.

```ts
const app = await createApp({
  cwd,
  revisions: 'abc',
  send: (payload) => deliver(payload.prompt),
})
```

`createApp` rejects a `cwd` below the jj workspace or git worktree root.
Both jj and git print diff paths relative to the root, whereas the
server reads working-copy files and writes review comments by joining
those paths onto `cwd` (with `cwd` set to `<repo>/sub`, `sub/f.txt`
becomes `<repo>/sub/sub/f.txt`). The CLI started from a subdirectory has
the same mismatch, which this PR doesn't change.

### `send` is a function

The CLI's `--send` takes a shell command, but `createApp`'s `send` takes
only a function. A shell command would inherit the host's environment,
including a `SKEPSIS_URL` that isn't the page's. So the CLI's server,
which knows its own URL, now turns its `--send` command into a function
before building the app (`server/main.ts`):

```ts
const send = command
  ? (payload: SendPayload) => {
      const env = { SKEPSIS_URL: serverUrl, SKEPSIS_ROOT: cwd }
      return runSend(command, payload, { cwd, env })
    }
  : null
const app = await buildApp({ ...opts, send })
```

### The guard

The page's API (the `/api/...` routes the app serves) reads and writes
files in the repository and calls `send`, so something has to decide
which requests to those routes are allowed. The CLI's server does that
with a per-run token that only the page it opened has, plus `Host` and
`Origin` checks on `/api/send`. This PR calls those checks the guard,
and `createApp` has them on by default.

With the guard on, the host puts the token in the page's URL as
`#token=${app.token}`. Send only works when the host is reached on
loopback over plain http, because of the `Host` and `Origin` checks.
Each `createApp` call makes a new token, so the host has to keep the app
for as long as its page may be open.

A host that already decides who may reach the mounted page, with its own
login or signed URLs for example, can pass `guard: false` to turn the
token and the `Host` and `Origin` checks off. Any other host should
leave the guard on. The README's Embedding section covers both cases.

### One small change for CLI users

The page's asset and API URLs are now relative, so it works at any path
ending in `/`. For CLI users, the one change is that a path with no file
returns 404 where the server used to return `index.html`.

### Tests

A Playwright test mounts the built package at `/some/prefix` in a
stand-in host with the guard off. It checks that the diff renders, the
theme script and highlighter worker load, Send reaches the host's
function, viewed state survives a reload, no request leaves the prefix,
and an unknown path is a 404. A second case leaves the guard on and
checks that the page works from the URL with the token, still works on
the bare URL after a reload, can Send, and that the API returns 401
without the token.

The host passes requests on with `new Request(url, request)`, which
fails on Node 26.11 or later with `@hono/node-server` before 2.1.8
([honojs/node-server#408](honojs/node-server#408)),
so the dev dependency's minimum is raised. CI now builds before the
type-check so the test's package import resolves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant