Skip to content

fix(server): this Mac's pairings and agent setting live outside the library (ISSUE-38) - #35

Merged
2witstudios merged 3 commits into
mainfrom
pu/hardening-mac-state
Nov 26, 2026
Merged

2witstudios merged 3 commits into
mainfrom
pu/hardening-mac-state

Conversation

@2witstudios

@2witstudios 2witstudios commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

What this delivers

This Mac's paired phones and tablets (devices.json) and its agent on-air setting (settings.json) now live with the Mac, not in the library. Before, a cloned or synced library could bring someone else's paired devices, which then count as paired once Wi-Fi is on, or a looser agent setting.

  • Location. ~/Library/Application Support/ViewSwitcher/libraries/<hash of the library path> (apps/server/src/machine-state.ts, config.machineState). VIEWSWITCHER_STATE moves the root. The on-air record and the kit's bookkeeping stay in the library's .viewswitcher/, because they describe the library.
  • Migration, once at startup.
    • The agent setting carries over only when it's "never", so a file that came with the library can't widen anything.
    • Paired devices never carry over, so phones and tablets pair again once.
    • The old copies are removed from the library.
  • Hand edits to the setting are still followed: the server watches the new folder.
  • Tests never touch the real Application Support. bunfig.toml preloads test-setup.ts, which points VIEWSWITCHER_STATE at a temp folder for every test and every server a test starts. mac:e2e does the same.
  • Docs. README (a new env row, the pairing sentence), SECURITY.md, the glossary and the comments say where they live. The decision is on the Decisions page (2026-11-26).

Tasks: ISSUE-38

How it was checked

Locally on macOS with Bun 1.4.2:

  • bun test: 4598 pass, 0 fail, from the repo root and from apps/server. Neither run adds anything to the real Application Support. New tests:
    • machine-state.test.ts: the folder per library path; devices are dropped, not trusted; "never" carries over and "always" doesn't; this Mac's setting is never overwritten.
    • settings-follow.test.ts: a real server follows a hand edit in the new folder and ignores a settings.json that appears in the library.
  • bun run typecheck: clean. astro check: 0 errors.
  • mac:build --app + mac:e2e: see the comment that follows.

Notes for review

  • Users re-pair once. That cost is deliberate, since carrying the old file over is exactly how someone else's devices would get in.
  • Two independent review rounds. Fixes from them: no test can reach the real Application Support from any folder (every spawn passes TEST_STATE_ROOT, and a server under bun test without VIEWSWITCHER_STATE refuses to start); the state is keyed by the library's real path; the migration reads the old file as settings.ts did (malformed means never); a kept-own result for the log; ipad-shots.sh's own state folder. Two folders an earlier test run left in the real Application Support were removed (neither was the real library's).

PageSpace

Builder: owner (Claude Code session)

Criteria

Criterion Code Test Evidence
ISSUE-38 — Given a cloned library that brings its own plain .viewswitcher/, this Mac's pairings and agent setting should be this Mac's own apps/server/src/machine-state.ts, config.ts machineState, main.ts (migration and watch), settings.ts, http/routes/agent.ts apps/server/src/machine-state.test.ts, apps/server/src/settings-follow.test.ts, apps/server/src/mcp/http.test.ts 70e9ae5: 4598 pass; mac:e2e all checks passed

🤖 Generated with Claude Code

https://claude.ai/code/session_01QyQdJ1ZdpFyktLPZbQXJSh

…ibrary (ISSUE-38)

A cloned or synced library could bring its own .viewswitcher/devices.json (someone else's paired
devices) or a looser settings.json. Both are this Mac's, not the library's, so they move to
~/Library/Application Support/ViewSwitcher/libraries/<library path's hash> (VIEWSWITCHER_STATE moves
the root; machine-state.ts). Once, at startup: the agent setting carries over only when it's
"never"; paired devices never carry over (phones and tablets pair again); the old copies are removed
from the library. Hand edits are still followed, by watching the new folder.

Tests never touch the real Application Support: bunfig.toml preloads test-setup.ts, which points
VIEWSWITCHER_STATE at a temp folder for every test and every server a test starts; e2e does the same.
README, SECURITY.md, the glossary and the comments say where they live now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QyQdJ1ZdpFyktLPZbQXJSh
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viewswitcher-site Ready Ready Preview Nov 26, 2026 7:05am UTC

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T07:05:53.118701Z
We couldn’t complete this review. Comment @codex review to try again.
492c99b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e7d16d59-b92c-4206-b071-993cbfe8b084
Commits

Reviewing files that changed from the base of the PR and between 5a61c06 and 70e9ae5.

Files selected for processing: 27

  • README.md
  • SECURITY.md
  • apps/apple/scripts/e2e.ts
  • apps/apple/scripts/ipad-shots.sh
  • apps/server/src/agent-guard.ts
  • apps/server/src/atomic.test.ts
  • apps/server/src/config.test.ts
  • apps/server/src/config.ts
  • apps/server/src/http-guard.test.ts
  • apps/server/src/http/routes.ts
  • apps/server/src/http/routes/agent.ts
  • apps/server/src/library/contain.test.ts
  • apps/server/src/library/contain.ts
  • apps/server/src/machine-state.test.ts
  • apps/server/src/machine-state.ts
  • apps/server/src/main.ts
  • apps/server/src/mcp/http.test.ts
  • apps/server/src/mcp/stdio.test.ts
  • apps/server/src/scene-edit.test.ts
  • apps/server/src/settings-follow.test.ts
  • apps/server/src/settings.test.ts
  • apps/server/src/settings.ts
  • apps/server/src/test-server.ts
  • bunfig.toml
  • docs/glossary.md
  • packages/shared/src/types.ts
  • test-setup.ts
  • 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

@2witstudios

Copy link
Copy Markdown
Owner Author

Mac app end-to-end at 492c99b: bun run mac:build --app then bun run mac:e2e: all checks passed, including Wi-Fi pairing, removal surviving a quit, and the agent setting, on a real build with VIEWSWITCHER_STATE in a temp folder. Nothing from the test or e2e runs landed in the real ~/Library/Application Support/ViewSwitcher.

… state keyed by the real path, migration fails closed (ISSUE-38)

- A run from apps/server didn't load the root bunfig.toml, so tests that spawn the server directly
  wrote to the real Application Support. Every spawn now passes test-server's TEST_STATE_ROOT, and a
  server under bun test (NODE_ENV=test) with no VIEWSWITCHER_STATE refuses to start (config.ts),
  tested in config.test.ts. ipad-shots.sh gets its own state folder.
- machineStateDir keys on the library's real path, computed after the library exists, so a link or
  another spelling of it is the same library.
- The migration reads the old file as settings.ts did: a malformed file or a bad value meant "never"
  and carries over as that; no setting yet is the default. Its result says "dropped" when this Mac's
  own setting was kept, and failing to remove an old file is logged, not fatal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QyQdJ1ZdpFyktLPZbQXJSh
@2witstudios

Copy link
Copy Markdown
Owner Author

Correction to my e2e comment above: I wrote that nothing landed in the real ~/Library/Application Support/ViewSwitcher. That was wrong. Two folders (libraries/9bb9… with a devices.json, and libraries/ede1…) were made during review by tests run from apps/server, where the root bunfig.toml preload doesn't apply, so servers that tests spawn directly had no VIEWSWITCHER_STATE.

Fixed in the latest commit: every spawn passes TEST_STATE_ROOT, and a server under bun test with no VIEWSWITCHER_STATE now refuses to start (tested). A full run from apps/server adds nothing there now. I removed both stray folders after checking that neither is the real library's (d0b3…). The same commit answers the independent review: real-path keying, the migration failing closed, and ipad-shots.sh.

@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

Deployment failed for project viewswitcher-site with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/2witstudios-projects?upgradeToPro=build-rate-limit

… kept, so the log doesn't claim a reset (ISSUE-38)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QyQdJ1ZdpFyktLPZbQXJSh
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

Deployment failed for project viewswitcher-site with the following error:

Resource is limited - try again in 1 day (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/2witstudios-projects?upgradeToPro=build-rate-limit

@2witstudios
2witstudios merged commit cc99911 into main Nov 26, 2026
3 of 4 checks passed
@2witstudios
2witstudios deleted the pu/hardening-mac-state branch November 26, 2026 07:17
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