Repository navigation
Skepsis as a library: host the review page in another server - #124
Merged
Conversation
david-crespo
added a commit
that referenced
this pull request
Nov 19, 2026
`/api/file-contents` and the two comment routes take a file path from the request and read or write that file under the repository directory. They didn't check the path, so one starting with `../` reached files outside the repository. `GET /api/file-contents?path=../outside.txt` returned `outside.txt`, and the comment routes could rewrite it. These routes are behind the per-run token, so only the page could do this. It matters more for the `createApp` export stacked on this PR (#124), where a host application can turn the token off and check requests itself. The routes now accept only a path in the latest diff, or a rename's old path, and return 400 otherwise. That also blocks files inside the repository that the diff doesn't show, such as an ignored `.env`. When a path isn't in the last diff, the server runs the diff once more before refusing, so a file that just changed isn't rejected. The 71 changed lines are 36 for the check and 35 in tests. We checked that `/api/file-contents` returns 400 for a file outside the repository and for an unchanged file inside it, and that both comment routes return 400 for the outside file and leave it unchanged. Both content requests returned 200 before the fix. The git test fixture now runs `git add --intent-to-add`, because two existing tests request untracked files, which `git diff` leaves out. Reviewers: Pull Request: #121
With guard off, the app issues no token and /api/send skips its Host and Origin check. This is for a host application that checks requests before passing them on. The CLI's server always has it on.
buildApp now takes send as a function that delivers a payload. startServer wraps the --send command in one and gives it SKEPSIS_URL and SKEPSIS_ROOT, so the app no longer needs its own address or a shell.
The package now exports createApp from lib.ts, built to dist/lib.js and dist/lib.d.ts. It builds the diff source from the CLI's revision options, takes send as a function with a timeout, and rejects a cwd below the repository root, where root-relative diff paths and cwd-relative file paths differ.
The mounted-page test in a later commit starts its own host process, so it needs the temp repo and the browser without the CLI server.
Fixes "Illegal invocation" from `new Request(url, request)` on Node 26.11 or later (honojs/node-server#408), which is how a host passes a request on to a mounted app.
The page's asset and API URLs are now relative, so it works at any path ending in /. Paths with no file get a 404 in place of index.html, which could not load its assets from there. The stored token is keyed by path, so pages at different paths on one origin each keep their own. A browser test mounts the built package under a prefix in a stand-in host. CI now builds before the type-check so the package import resolves.
david-crespo
force-pushed
the
spr/skepsis-as-a-library-host-the-review-page-in-another-server
branch
from
November 19, 2026 18:20
9fd0fef to
8020445
Compare
david-crespo
deleted the
spr/skepsis-as-a-library-host-the-review-page-in-another-server
branch
November 19, 2026 18:43
|
Canary published: |
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 #123, this PR lets another Node server mount the review page under a URL prefix, for any number of diffs in one process.
@oxide/skepsisnow exportscreateApp, which returns afetchhandler 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.mdabout 95, and build and CI config about 55.Choosing the diff
A caller tells
createAppwhich diff to show with the same options the CLI has:revisionsfor-r, orfromandtofor-fand-t.createAppworks out thejjorgitcommand from those, as the CLI does.createApprejects acwdbelow 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 ontocwd(withcwdset to<repo>/sub,sub/f.txtbecomes<repo>/sub/sub/f.txt). The CLI started from a subdirectory has the same mismatch, which this PR doesn't change.sendis a functionThe CLI's
--sendtakes a shell command, butcreateApp'ssendtakes only a function. A shell command would inherit the host's environment, including aSKEPSIS_URLthat isn't the page's. So the CLI's server, which knows its own URL, now turns its--sendcommand into a function before building the app (server/main.ts):The guard
The page's API (the
/api/...routes the app serves) reads and writes files in the repository and callssend, 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, plusHostandOriginchecks on/api/send. This PR calls those checks the guard, andcreateApphas 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 theHostandOriginchecks. EachcreateAppcall 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: falseto turn the token and theHostandOriginchecks 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 returnindex.html.Tests
A Playwright test mounts the built package at
/some/prefixin 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-serverbefore 2.1.8 (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.