Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Scenes, templates and fixtures are compared byte for byte: LF everywhere, on every checkout.
* text=auto eol=lf
*.png binary
*.jpg binary
*.ico binary
*.zip binary
*.mp4 binary
*.woff2 binary
37 changes: 36 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
jobs:
test:
name: Test and typecheck
# The product is Mac-only, and the end-to-end tests bind this machine's LAN address.
# The end-to-end tests bind this machine's LAN address. (Windows has its own job below.)
runs-on: macos-latest
timeout-minutes: 20
steps:
Expand Down Expand Up @@ -52,3 +52,38 @@ jobs:
working-directory: apps/apple/Kit
- run: swift test
working-directory: apps/apple/Kit

windows:
name: Server and switcher on Windows
# The server runs on Windows too (apps/windows bundles it): its tests there, where paths, renames
# and links behave differently. GitHub's runners are admins, so the file-link tests run too.
runs-on: windows-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .bun-version
- run: bun install --frozen-lockfile
- run: bun test
- run: bun run typecheck

windows-app:
name: Windows app (dotnet test, build)
runs-on: windows-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# The Core tests start Bun stub servers; without bun they skip.
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: .bun-version
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
with:
dotnet-version: 10.0.x
- run: dotnet test apps/windows/ViewSwitcher.Core.Tests
- run: dotnet build apps/windows/ViewSwitcher.Windows/ViewSwitcher.Windows.csproj -c Release -p:Platform=x64 -warnaserror
12 changes: 10 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Statuses on the board: To Do, In Progress, In Review, Blocked, Done.

## Workstreams

Scene editor (EDIT) first and landing page (SITE) in parallel; Mac app (MAC) after EDIT merges. The Product map holds the order.
Scene editor (EDIT) first and landing page (SITE) in parallel; Mac app (MAC) after EDIT merges; Windows app (WIN) after that. The Product map holds the order.

## Task codes

Expand All @@ -28,6 +28,7 @@ Scene editor (EDIT) first and landing page (SITE) in parallel; Mac app (MAC) aft
- `MAC`: Mac app (plan `gz7zkvlaofixz6ljsljdj6sh`)
- `MCP`: agent connection, the MCP server and Edit with AI (plan `q47xu7oithlmzpkeshfn5bdh`)
- `PHONE`: iPhone app, one universal app with the iPad's (plan `yxec9dlaej36ib1ytknvdoq7`)
- `WIN`: Windows app: the server on Windows and the WinUI 3 shell (plan `krx65gign63m8v3pb27jnpep`)
- `HARD`: hardening: CI and repo hygiene, the live path, the trust boundary, the Mac and iOS shells, vocabulary (plan `giqaj703oqbthlkfknwewy9h`)
- `ISSUE`: bugs, debt and loose ends found outside a slice

Expand All @@ -52,10 +53,17 @@ Bun workspaces monorepo: a live-stream switcher that drives OBS (`apps/`, `packa
- `packages/shared` holds the wire types and pure logic, whichever app uses it: `resolveStream` and `parseLibraryPath` (server and switcher), the HTML scanner (`scanElements`, the editor), the pack validator (server, `packages/packs`, the site), and the OBS math only the server uses (`coverTransform`, `obsColor`, in `apps/server/src/live/placement.ts`). Keep it dependency-free and tested (`bun test`).
- `apps/web` must stay a static SPA (no SSR or server functions). The iPad app (`apps/apple`, target ViewSwitcher iPad) loads it from the server over its USB-C tunnel; deploy with `bun run ipad:deploy`. Safe areas come from the shells: `env(safe-area-inset-*)` on the iPad, `--shell-*` variables and `data-shell` from the Mac app (MAC-13a).
- `apps/apple` is one Xcode project generated from `project.yml` (XcodeGen; the .xcodeproj is gitignored): ViewSwitcher.app for macOS around the server compiled with `bun build --compile` (Contents/Helpers), the iPad app, and the shared ViewSwitcherKit package. The server must keep running as that binary (no repo-relative paths without an env override, see `apps/server/src/config.ts`). Build with `bun run mac:build`, check with `bun run mac:e2e` (never on port 7420), test with `xcodebuild test` (apps/apple/README.md).
- `apps/windows` is the Windows app: a WinUI 3 shell (.NET 10, Windows App SDK, unpackaged) around the same server compiled for Windows (`Helpers\viewswitcher-server.exe`) and the switcher in WebView2; `ViewSwitcher.Core` ports Kit's logic with its tests (apps/windows/README.md). Build with `bun run win:build`, check with `bun run win:e2e` (never on port 7420), test with `bun run win:test`. The page in its window gets no host objects or web messages.
- The server runs on macOS and Windows:
- a path from `relative()` becomes a library path with `/` (`split(sep).join("/")`), never with a backslash;
- per-user folders come from `platform-dirs.ts`;
- a folder is claimed with `fsx.ts` `claimRename` (Windows never renames over a folder), and a file replaced with `renameOver`;
- what phones and agents are told names the computer through `COMPUTER` ("Mac" or "PC").
Tests that need a file symlink, a named pipe or POSIX permissions use `test.skipIf(!fileLinks)` / `test.skipIf(!posix)` (`test-links.ts`); folder links work on Windows through junctions. Checkouts are LF (`.gitattributes`).
- Scenes are untrusted code (agents, template packs from anyone): `/library/` pages are served with a CSP sandbox (`apps/server/src/scene-sandbox.ts`) and every scene frame is sandboxed (`apps/web/src/lib/scene-frame.ts`). Never give a scene frame `allow-same-origin` together with `allow-scripts`, except the editor's, which only ever loads `?inert` (served with `script-src 'none'`); never reach into a scene frame with contentDocument except that one; the program page talks to scenes through the bridge (`scene-bridge.ts`). Template packs: docs/template-packs.md.
- Routes live in one table, `apps/server/src/http/routes.ts`, and `http/dispatch.ts` is the only way in: host guard, audience, exact Origin for non-GET (and WebSocket upgrades), JSON body (multipart for the two upload routes), then the handler, with `frame-ancestors 'self'` and nosniff on everything outside `/library/`. Every route declares its audience (`mac`, `macOrUsb`, `paired`, `public`; gate.ts); undeclared is Mac-only, and so is a path no route has. With the Wi-Fi setting off, nothing but this Mac and the USB-C device is served (tailscale serve included).
- No absolute filesystem paths in API responses, except `GET /api/info` (the library folder and Edit with AI's commands, for the Mac app's Open Library Folder and the sheet) and `GET /api/agent/viewswitcher.mcpb` (the Claude Desktop extension, whose command is this install's server), which are `mac` routes: `isMac` in `apps/server/src/gate.ts` (loopback peer and Host, no proxy headers, not the Wi-Fi listener, and not the USB-C iPad, whose bridge sockets are marked). Phones paired over Wi-Fi never get these, nor `/mcp`. Errors go through `scrub.ts`, and only `mac` sees a 500's message.
- Every library path a client sends, read or write, goes through `resolveInLibrary` (`apps/server/src/library/contain.ts`): real-path containment through links, and no dot segments except a staged pack's preview, which may only be read.
- `/mcp` (agents, `apps/server/src/mcp/`) is a `mac` route, refuses any `Origin` that `originAllowed` rejects, and sits under `hostTrusted`. The agent on-air guard (`agent-guard.ts`) limits MCP tools only, never the switcher's own routes.
- The agent skill and library CLAUDE.md that new libraries get live in `apps/server/library-kit/`; change the skill there.
- Typecheck: `bun run typecheck` (apps/web and its tests, apps/server, packages/shared with its tests). CI (`.github/workflows/ci.yml`) runs it with `bun test`, `astro check`, the switcher build and Kit's `swift test` on every PR; keep it green. Bun is pinned in `.bun-version`.
- Typecheck: `bun run typecheck` (apps/web and its tests, apps/server, packages/shared with its tests). CI (`.github/workflows/ci.yml`) runs it with `bun test`, `astro check`, the switcher build and Kit's `swift test` on macOS, and `bun test`, the typecheck, `dotnet test` and the Windows app's build on Windows, on every PR; keep it green. Bun is pinned in `.bun-version`.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ bun run start # builds the switcher, serves everything on http://loca
# or, while working on the app itself:
bun run dev # server on :7420 (watch) + Vite on http://localhost:5173
bun run mac:dev # builds the Mac app (Debug) and runs it, attached to the server above (or starting one from source)
bun run win:dev # on Windows: builds the Windows app (Debug) and runs it, the same way
```

The server runs on macOS and Windows. The Windows app (a WinUI 3 shell, the same server compiled for Windows, the switcher in WebView2, phones and tablets over the Wi-Fi) is in [apps/windows](apps/windows/README.md); it needs the .NET 10 SDK to build.

Vite's dev server proxies `/api`, `/library` and `/ws` to the server and keeps the browser's Host (`apps/web/vite.config.ts`), so the dev page at `http://localhost:5173` is the server's own origin and its changes are accepted; no extra setting is needed. Another dev host needs its origin in `VIEWSWITCHER_ORIGINS`.

The library (your shows) is `~/ViewSwitcher Library` unless `VIEWSWITCHER_LIBRARY` says otherwise. The first run creates it with the agent skill and a first show, "My channel". Closing the Mac app's window keeps the server running for OBS and the iPhone or iPad; Quit (in the menu bar or ⌘Q) stops it.
Expand All @@ -97,16 +100,17 @@ The library (your shows) is `~/ViewSwitcher Library` unless `VIEWSWITCHER_LIBRAR
| var | default |
|---|---|
| `VIEWSWITCHER_LIBRARY` | `~/ViewSwitcher Library` |
| `VIEWSWITCHER_STATE` | `~/Library/Application Support/ViewSwitcher`: this Mac's own state for each library (paired phones and tablets, the agent on-air setting), kept outside the library so nothing cloned, pulled or synced with it can carry them |
| `VIEWSWITCHER_STATE` | `~/Library/Application Support/ViewSwitcher` (on Windows `%APPDATA%\ViewSwitcher`): this computer's own state for each library (paired phones and tablets, the agent on-air setting), kept outside the library so nothing cloned, pulled or synced with it can carry them |
| `PORT` | `7420` |
| `HOST` | `127.0.0.1`. Loopback only: the server refuses to start with another address; the Wi-Fi setting is the way onto the network (below) |
| `VIEWSWITCHER_LAN` | `1` also listens on the Wi-Fi from the start (the Mac app passes its "Let Phones and Tablets on This Wi-Fi Connect" setting) |
| `VIEWSWITCHER_LAN_HOST` | `0.0.0.0`: the address the Wi-Fi listener binds (tests bind this Mac's LAN IP) |
| `VIEWSWITCHER_ADMIN_TOKEN` | set by the Mac app at each launch: the secret for the pairing endpoints (`/api/remote…`); unset, they answer 404 |
| `OBS_URL` / `OBS_PASSWORD` | `ws://127.0.0.1:4455` / read from OBS's own settings on this Mac |
| `OBS_URL` / `OBS_PASSWORD` | `ws://127.0.0.1:4455` / read from OBS's own settings on this computer (`~/Library/Application Support/obs-studio`, on Windows `%APPDATA%\obs-studio`) |
| `OBS_SCENE` / `OBS_PROGRAM_SOURCE` / `OBS_GROUND_SOURCE` | `ViewSwitcher` / `ViewSwitcher Program` / `ViewSwitcher Ground` |
| `OBS_SOURCES` (or the older `OBS_DEVICES`) | `Camera,Screen,iPad`: the OBS sources a view can place in its camera boxes. A view hides each of these that it has no camera box for, and also any other source a view has ever placed (a Guest or Camera 2 box; remembered in `.viewswitcher/state.json`). Every other item in the ViewSwitcher scene (a mic, music, a watermark) and the program and ground sources are never touched. |
| `VIEWSWITCHER_EDITOR` | app for "Open the file", e.g. `Cursor` (default: your text editor) |
| `VIEWSWITCHER_EDITOR` | app for "Open the file", e.g. `Cursor` (on Windows, the editor's .exe; default: your text editor, or Notepad) |
| `VIEWSWITCHER_STOP_ON_STDIN` | Windows app: `1` stops the server, saving paired devices first, when its stdin closes (Windows has no SIGTERM) |
| `VIEWSWITCHER_LOG` | `1` prints requests, placements and OBS-browser errors |
| `VIEWSWITCHER_USB` | `0` turns off the USB-C bridge |
| `VIEWSWITCHER_WEB_DIST` / `VIEWSWITCHER_STARTER` / `VIEWSWITCHER_LIBRARY_KIT` | `apps/web/dist` / `apps/server/starter` / `apps/server/library-kit` (the Mac app points these into its Resources) |
Expand Down
7 changes: 4 additions & 3 deletions apps/apple/scripts/node-modules-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// bun apps/apple/scripts/node-modules-dirs.ts <repo> prints one path per line, relative to <repo>
// It exits non-zero rather than print a short list, so build.sh never skips a folder in silence.
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { join, posix } from "node:path";

export function nodeModulesDirs(repo: string): string[] {
const { workspaces } = JSON.parse(readFileSync(join(repo, "package.json"), "utf8"));
Expand All @@ -15,9 +15,10 @@ export function nodeModulesDirs(repo: string): string[] {
throw new Error(`can't clean for workspace pattern ${JSON.stringify(pattern)}`);
}
// A workspace is a folder with a package.json; Bun.Glob skips dot folders (.git, .pu/worktrees).
for (const file of new Bun.Glob(`${pattern.replace(/\/+$/, "")}/package.json`).scanSync({ cwd: repo })) {
for (const found of new Bun.Glob(`${pattern.replace(/\/+$/, "")}/package.json`).scanSync({ cwd: repo })) {
const file = found.split("\\").join("/"); // Glob answers with backslashes on Windows
if (file.split("/").includes("node_modules")) continue;
dirs.add(join(file, "..", "node_modules"));
dirs.add(posix.join(file, "..", "node_modules"));
}
}
return [...dirs].sort();
Expand Down
Loading
Loading