Skip to content

refactor(build): the shell build takes its policies from shared - #3717

Merged
devswha merged 1 commit into
mainfrom
refactor/shell-build-shared-policy
Nov 12, 2026
Merged

devswha merged 1 commit into
mainfrom
refactor/shell-build-shared-policy

Conversation

@devswha

@devswha devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • The frontend shell build (scripts/shell-build.ts) imported its page policy and static-asset policy values from server files. They now live in shared/web-policy.ts; server/static.ts and server/file-view.ts re-export them, so every existing importer is unchanged.
  • A convention rule keeps the frontend build scripts from importing server/ or relay/.
  • Move only: no value, header or behaviour changes. dist-shell/_headers and dist-shell/_redirects are byte-identical before and after.

Why

  • First step toward a public frontend tree that builds without server sources.

Notes for review

  • server/static-encoding.test.ts copies static.ts alone into a temp folder; it now copies shared/web-policy.ts beside it.
  • The new rule checks the direct imports of the listed build scripts; it does not follow an import passed through another file under scripts/.
  • No changelog fragment: nothing user-visible changes.

Validation

  • Ran: bun run check fast (exit 0) on the rebased commit; bun test scripts/conventions.test.ts; bun run build:shell; cmp of _headers and _redirects built on the parent and on this commit.
  • Skipped: bun run check full, browser regressions (no file under src/ changed).

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Improvements
    • Web security policies are now applied consistently across the app, hosted shell, and rendered pages. Rendered pages remain sandboxed, and media sources are included only when provided.
  • Tests
    • Added checks to catch build scripts that import server- or relay-specific modules.

The pull request moves cache and web security policies into shared/web-policy.ts. Server and shell modules use or re-export the shared definitions. A convention test checks frontend build scripts and vite.config.ts for imports containing server/ or relay/ path segments.

Changes: Shared web policy

Layer / File(s) Summary
Shared policy definitions
shared/web-policy.ts
Adds shared cache values, CSP directives, shell policy, account-service origin handling, and rendered-page policy.
Server and shell integration
server/static.ts, server/file-view.ts, scripts/shell-build.ts, server/static-encoding.test.ts, scripts/conventions.test.ts
Server and shell modules import or re-export shared policies. The static-server fixture copies the shared module. A convention test checks frontend imports for server/ or relay/ path segments.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

  • devswha/ovis#2509: Adds policy behavior that this pull request moves from server modules into the shared policy module.

Suggested reviewers: radicor, movieholic-plex

Merge Risk: Minimal · up to 6257c

This is a move-only refactor of web policy values with unchanged re-exports for existing importers. No concrete regression has been identified, and the change is ready to merge after normal checks.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the shell build now takes its policy values from the shared module. The changeset moves pagePolicy and the web-policy constants into shared/web-policy.ts, and scripts/…
Description check Passed The description follows the template. The Change section explains the problem (the shell build imported policy values from server files), the resulting behavior (values moved to shared/web-policy.ts, …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the shell build now takes its policy values from the shared module. The changeset moves pagePolicy and the web-policy constants into shared/web-policy.ts, and scripts/shell-build.ts imports them from there. The title is specific and matches the changeset. It uses a conventional commit prefix and a single sentence.

Full details: Description check

Explanation

The description follows the template. The Change section explains the problem (the shell build imported policy values from server files), the resulting behavior (values moved to shared/web-policy.ts, with re-exports that keep existing importers unchanged), and that the move changes no values, headers, or behavior. The Validation section lists the commands run, their results, and the checks skipped with reasons. The template's contract-test line applies to HTTP/WS changes, and this PR makes none. The description does not link an issue, but the template asks for one only for features, and this is a refactor. The description also cites the changelog convention and states that no fragment is needed, which fits the template's changelog pointer.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a61844c and 6257c30.

Files selected for processing: 6

  • scripts/conventions.test.ts
  • scripts/shell-build.ts
  • server/file-view.ts
  • server/static-encoding.test.ts
  • server/static.ts
  • shared/web-policy.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@devswha
devswha merged commit 599653f into main Nov 12, 2026
21 checks passed
@devswha

devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 6257c304e24e as 599653f2c963 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Two reviewers at this head: Claude (Opus) CLEAR, Codex Terra CLEAR with no findings.

Move only. The page policy and the static-asset policy values that the frontend shell build (scripts/shell-build.ts) imported from server/file-view.ts and server/static.ts now live in shared/web-policy.ts; the two server files re-export them, so every importer is unchanged. A convention rule keeps the listed frontend build scripts from importing server/ or relay/ directly; it fails on main and passes here.

Checked by the merge pass: git diff --color-moved shows only the import lines, the re-exports and the new module comment as not moved; and bun run build:shell on the PR's base (a61844c) and on this head gives byte-identical dist-shell/_headers (1140 bytes) and dist-shell/_redirects (234 bytes). The Opus reviewer ran the seven unit test files around it: 90 pass, 0 fail, and confirmed the remote bundle and the Electron build copy all of shared/.

Left, both LOW (Claude, read):

  • Four places still say the policies live in server/static.ts: scripts/shell-build.ts:11 and :130, scripts/csp-violations.ts:4, docs/relay.md:81. Line 130 is written into _headers, so changing it changes that file.
  • The new rule reads only direct imports of a hand-kept list of build scripts: a new build plugin left off the list, or a helper under scripts/ that imports server/, passes it.

Reports: ~/.cache/ovis-tmp/reports/pr-3717-6257c304-*.report.md.

@devswha
devswha deleted the refactor/shell-build-shared-policy branch November 12, 2026 02:59
devswha added a commit that referenced this pull request Nov 12, 2026
## Summary

The server can be built into one compiled binary, `ovis-server <entry>`,
that serves every entry the server starts:
`serve`, `managed`, `supervisor`, `remote`, `machine`, `plugin`,
`askpass` and `windows-launch`
(`server/entries.ts`, `server/main.ts`). `bun scripts/build-server.ts
<platform> <dir>` builds it for linux-x64,
linux-arm64, darwin-arm64, darwin-x64 and windows-x64 (`--compile
--minify --bytecode --format=esm`, the file worker
as a second entry, no source maps). Every child process the server
starts from its own code, and every lookup of
`dist/`, the version, the PTY hosts and the statusline helper, now works
both from source and from the binary. Run
from source, nothing changes. `/api/health` also reports the server's
own `version` to callers that get its full
answer.

The binary holds minified JavaScript and Bun bytecode. It keeps the
source out of what is published, but it does
not hide the code: anyone who unpacks the file can read it.

## Why

Todo 4 of the relay-fleet plan: releases, remote bundles, installers and
updates (todos 5, 6 and 7) ship and run
this one binary instead of a source checkout with Bun and
`node_modules`. Todo 7 reads the running server's version
from `/api/health`.

## Read first

- **`server/dispatch.ts`, `/api/health`:** `version` is added where
`security` already goes:
`access.level === "full"`. That covers every caller that gets the full
answer:
  - this PC on loopback while no token is set (`local`)
  - the token (`token`)
  - a paired device that drives or only watches (`device`, `relay`)
  - a Tailscale owner (`tailscale`)
  - a Portal sign-in (`portal`)
- anyone on the network (not through Tailscale Funnel) while the install
is still open, with no token and nothing paired (`open`)

A caller refused a token or a pairing gets the reduced answer without
it, and `?scope=bridge` does not carry it.
The value is `package.json`'s, the same import the rest of the server
uses. In the binary it is embedded at
  build time.
- **`server/windows-launch.ts`:** it `import()`s the file path it is
given. This crosses no privilege boundary:
- It runs as the user who starts it, with that user's rights, and loads
only a file that user names.
- Anyone who can run `ovis-server windows-launch <file>` can already run
that file with Bun, or with
    `BUN_BE_BUN=1 ovis-server <file>`.
- Its one caller is the scheduled task `windows-herdr-start.ts`
registers for the current user (interactive
token, ordinary rights). That task names the private launcher written
into a folder only that user and SYSTEM
    may read.
- **The PowerShell action string in `server/windows-herdr-start.ts`:**
  `$action.Arguments = [string]$payload.prefix + '"' + $launcher + '"'`.
- From source the payload carries no `prefix`, so the action is `bun.exe
"<launcher>"` as before.
- In the binary it is `ovis-server.exe windows-launch "<launcher>"`,
because a task action cannot set
    `BUN_BE_BUN`.
- Both actions were captured in the Windows 11 VM; the source action
matched origin/main's character for
    character.

## Left to later todos

- Updates in the binary: `/api/updates` stays unmanaged there (the
updater needs a git checkout). This belongs to
  todo 7, as do the source updater's Bun build steps.
- `node-pty` beside the binary for the Node PTY fallback, and the remote
bundles, desktop app and release jobs
  that carry the binary: todo 5.
- Installers and the plugin fetching the binary: todo 6.

## Known equivalent mutants

`process.argv.splice(1, 1)` and `splice(0, 1)` in `server/main.ts` (in
place of `splice(2, 1)`) pass the
tests. They leave every argument an entry reads unchanged, and no entry
reads its own `argv[0]` or `argv[1]`.
Dropping the splice, `splice(2, 2)` and `splice(3, 1)` are all caught.

## Review

This changes an HTTP contract (`/api/health` gains `version`) and how a
Windows scheduled task is started, so it
waits for a real review (AGENTS.md, "Maintainer workflow").

Builds on #3717 (merged).

## Validation

Ran:
- `bun run check fast` on b9be7e6e1, this branch rebased onto main
599653f: exit 0 (unit 16172 pass, 0 fail,
54 skip in 909 files), run by the independent verifier in a fresh
detached worktree. The executor's own run on the
branch rebased onto #3717's head gave the same counts; that head and
main differ only in
`scripts/copilot-chat-browser-qa.ts` and `server/opencode-native.ts`.
The pushed head differs from b9be7e6e1 only
in the wording of `changelog.d/health-version.md`; the changelog and
convention tests were run again on it.
- Touched test files, three times each: `server/entries.test.ts`,
`server/dispatch.test.ts`, `server/static.test.ts`,
`server/static-encoding.test.ts`, `server/conventions.test.ts`,
`scripts/conventions.test.ts`,
  `scripts/shell-build.test.ts`.
- The fixture of `server/static-encoding.test.ts` fails without
`entries.ts` and without `shared/web-policy.ts`.
The new tests fail under each mutation of the entry table, the command
line, the server and assets roots, the
  argv handling and the Windows prefix.
- Binary acceptance on Linux (linux-x64 binary, sha256
`e9876c62181b463c8e7fea5f65ca1f65f541adb39dad650d00d54e769bedee34`), run
against an isolated herdr and a throwaway
  HOME:
  - `ovis-server managed` brings up managed, supervisor and serve.
- `/api/health` answers 200 with `version` 0.5.3 for the owner, and
without `version` for an unauthenticated
    caller.
- `/api/fs/stat` answers 200 through the file worker, and `/` is served
from `OVIS_ASSETS`.
- `ovis-server nosuch` exits 2 and lists the entries; `ovis-server
machine` exits 1 with its refusal.
- No `.ts` file sits in the output folder, and the worktree is clean
after the build.
- Windows 11 VM (`winvm`), in the desktop session through
`Invoke-InSession.ps1`, in a fresh `%TEMP%` folder
  that was then removed:
  - The source-mode scheduled-task action matched origin/main's.
- The windows-x64 binary's `remote` entry started herdr through the task
(`windows-launch`, last result
    267009, still running).
  - The bridge answered `/api/health` with 200 and `version` 0.5.3.

Skipped:
- `bun run check full` (integration and browser lanes). The
integration-lane files covering the touched code
(`server/pty/host.test.ts`, `server/pty/session.test.ts`) were run
directly instead.
- Browser regressions: none applies, because `src/` changes only a type
(`HealthInfo.version`) and no shared
  UI component changes.
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