Repository navigation
Run jj and git in the diff's directory - #123
Merged
david-crespo merged 1 commit intoNov 19, 2026
Conversation
david-crespo
force-pushed
the
spr/run-jj-and-git-in-the-diffs-directory
branch
from
November 19, 2026 18:20
023c145 to
16869b7
Compare
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Built on #122, this PR lets one process serve diffs from more than one repository.
jjandgitinvocations, 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 passesprocess.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 forbuildDiffSourceanddetectVcsin a directory other than the process's working directory. The source change is about 55 lines that add the directory argument.