Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(https): prefer Homebrew tailscale over sandboxed MAS app for cert provisioning
[._.]/ Adam Eivy7c469f6bef97
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex debe646edb..7b71ce17de 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -14,6 +14,7 @@- Top-level `/reference-repos` global summary page and sidebar entry. Reference repos are now exclusively app-scoped — manage them via each app's "References" tab. Removed `client/src/pages/ReferenceRepos.jsx`, the route + lazy import from `client/src/App.jsx`, the sidebar entry from `client/src/components/Layout.jsx`, and the `nav.reference-repos` entry from `server/lib/navManifest.js` (the manifest's shape-invariant tests cover the deletion automatically). The `compact` / `initialRefs` props on `ReferenceReposPanel` are gone since the global summary was their only consumer.## Fixed+- macOS "Enable HTTPS" on the Instances page failed with `tailscale cert failed: ... operation not permitted` when the only Tailscale CLI on the machine was the Mac App Store / GUI app bundle. The MAS build runs under macOS App Sandbox and can't write the LE cert temp file outside its container. PortOS now: (1) reorders `TAILSCALE_CANDIDATES` in `server/lib/tailscale.js` so Homebrew (`/opt/homebrew/bin/tailscale`, `/usr/local/bin/tailscale`) is preferred over the App-bundle (kept as last-resort fallback); (2) detects the sandboxed-only state at boot via the new `hasOnlySandboxedTailscale()` helper and prints actionable `brew install tailscale` guidance from `scripts/setup-cert.js` before the doomed `tailscale cert` call; (3) rewrites the runtime EPERM toast in `server/services/certProvisioner.js` to point at the brew fix instead of surfacing raw sandbox stderr (new `tailscale-sandboxed` reason code); (4) on macOS, `./setup.sh` now detects the sandboxed-only state via the JS helper (single source of truth for the candidate paths) and unattended-installs `brew install tailscale` when available, with printed guidance when brew is missing. Non-fatal in every branch.- Federated peer-sync category toggles for **Universe** and **Pipeline** silently no-op'd. The Zod `syncCategoriesSchema` in `server/routes/instances.js` was missing both keys; Zod's default object parsing strips unknown keys, so the PATCH validated as an empty `syncCategories` object, the service-side merge became a no-op, and the checkbox stayed unchecked with no server-side error. Added `universe` and `pipeline` to the schema to restore parity with `DEFAULT_SYNC_CATEGORIES` and the UI's `SYNC_CATEGORY_META`.- Auto-run the world → universe data rename on server boot. The conversion previously shipped as a manual CLI script (`server/scripts/migrateWorldToUniverse.js`) that nobody knew to invoke, so installs upgrading from the World Builder era kept stale `data/world-builder.json` files and never saw their worlds appear as universes. The new migration `031-world-to-universe-data-rename.js` does the file rename, top-level key rename (`worlds`→`universes`), `worldId`→`universeId` rewrite in `pipeline-series.json`, `worldRun`→`universeRun` rewrite in `media-jobs.json`, and also relinks any `"World: <name>"` render collections in `media-collections.json` to their universe by canonical-name match.- Universe Builder picker dropdown rendered beneath the tab subnav and downstream section cards in Lumen Glass / Blueprint Ops themes. Those themes ship a non-`none` `--port-backdrop-filter`, and the global rule in `index.css` applies it to every `.bg-port-card.border.rounded*` — which turns each such card into its own stacking context. The picker's `absolute z-30` dropdown was trapped inside the header card's context and couldn't paint over later sibling cards. Adding `relative z-30` to the picker's `<header>` lets that stacking context win against subsequent siblings so the dropdown overlays them as intended.diff --git a/scripts/setup-cert.js b/scripts/setup-cert.jsindex d9a70e37a0..cbf1b98cfb 100644--- a/scripts/setup-cert.js+++ b/scripts/setup-cert.js@@ -31,7 +31,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from 'fsimport { networkInterfaces } from 'os';import { join, dirname } from 'path';import { fileURLToPath } from 'url';-import { findTailscale } from '../server/lib/tailscale.js';+import { findTailscale, hasOnlySandboxedTailscale } from '../server/lib/tailscale.js';import { hasTailscaleCert } from '../lib/tailscale-https.js';import { certPaths } from '../lib/certPaths.js';@@ -242,6 +242,15 @@ if (SELF_SIGNED_ONLY) {process.exit(0);}+if (hasOnlySandboxedTailscale()) {+ console.log(`⚠️ Only the sandboxed Tailscale.app CLI is installed.`);+ console.log(` It can't write the LE cert to data/certs/ ("operation not permitted").`);+ console.log(` Install the unsandboxed CLI: brew install tailscale`);+ console.log(` Then re-run: npm run setup:cert`);+ maybeFallbackSelfSigned();+ process.exit(0);+}+const bin = findTailscale();if (!bin) {console.log(`ℹ️ Tailscale CLI not found.`);diff --git a/server/lib/README.md b/server/lib/README.mdindex f6c840aeeb..2a0c16a129 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -108,7 +108,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `peerUrl.js` | Build the base URL for a peer. || `sharingOrigin.js` | Origin metadata for records imported from share buckets. || `syncWire.js` | Single source of truth for what fields cross the federated-peer wire (snapshot loop + per-record push agree). |-| `tailscale.js` | Common paths where the Tailscale CLI binary is found. |+| `tailscale.js` | Locate the Tailscale CLI binary and flag the sandboxed macOS App-bundle build (which can't write `tailscale cert` output outside its container). || `httpsState.js` | Captures whether PortOS booted with HTTPS active. || `networkExposure.js` | Snapshot of scheme + bind + cert mode for the dashboard's Network Exposure widget. |diff --git a/server/lib/tailscale.js b/server/lib/tailscale.jsindex fd53c4c74b..d7fd26ed7d 100644--- a/server/lib/tailscale.js+++ b/server/lib/tailscale.js@@ -4,20 +4,29 @@ import { join, delimiter } from 'path';const IS_WIN = process.platform === 'win32';const TAILSCALE_BIN = IS_WIN ? 'tailscale.exe' : 'tailscale';+export const MACOS_TAILSCALE_APP_BUNDLE = '/Applications/Tailscale.app/Contents/MacOS/Tailscale';+// Paths where the Tailscale CLI binary is commonly found. On macOS the GUI app// doesn't put the CLI in PATH by default; Homebrew installs to /usr/local/bin// (Intel) or /opt/homebrew/bin (Apple Silicon); Linux packages land in /usr/bin;// Windows installs land in Program Files.+//+// On macOS we prefer Homebrew over the App Store bundle. The Mac App Store+// build of Tailscale runs under macOS App Sandbox and `tailscale cert` cannot+// write the cert temp file outside its container (EPERM "operation not+// permitted" when targeting paths like data/certs/). The Homebrew binary is+// the open-source CLI and is not sandboxed, so it can write anywhere the+// shell user can. App-bundle is kept as a last-resort fallback.const TAILSCALE_CANDIDATES = IS_WIN? ['C:\\Program Files\\Tailscale\\tailscale.exe','C:\\Program Files (x86)\\Tailscale\\tailscale.exe']: [- '/Applications/Tailscale.app/Contents/MacOS/Tailscale',- '/usr/local/bin/tailscale','/opt/homebrew/bin/tailscale',- '/usr/bin/tailscale'+ '/usr/local/bin/tailscale',+ '/usr/bin/tailscale',+ MACOS_TAILSCALE_APP_BUNDLE];export function findTailscale() {@@ -32,3 +41,12 @@ export function findTailscale() {}return null;}++export function isSandboxedTailscale(binPath) {+ return binPath === MACOS_TAILSCALE_APP_BUNDLE;+}++export function hasOnlySandboxedTailscale() {+ if (process.platform !== 'darwin') return false;+ return findTailscale() === MACOS_TAILSCALE_APP_BUNDLE;+}diff --git a/server/lib/tailscale.test.js b/server/lib/tailscale.test.jsindex f6fed3fa47..1431765f97 100644--- a/server/lib/tailscale.test.js+++ b/server/lib/tailscale.test.js@@ -5,7 +5,12 @@ vi.mock('fs', () => ({}));import { existsSync } from 'fs';-import { findTailscale } from './tailscale.js';+import {+ findTailscale,+ isSandboxedTailscale,+ hasOnlySandboxedTailscale,+ MACOS_TAILSCALE_APP_BUNDLE+} from './tailscale.js';describe('findTailscale', () => {let originalPath;@@ -23,7 +28,7 @@ describe('findTailscale', () => {const isWin = process.platform === 'win32';const expected = isWin? 'C:\\Program Files\\Tailscale\\tailscale.exe'- : '/Applications/Tailscale.app/Contents/MacOS/Tailscale';+ : '/opt/homebrew/bin/tailscale';existsSync.mockImplementation((p) => p === expected);expect(findTailscale()).toBe(expected);});@@ -32,7 +37,7 @@ describe('findTailscale', () => {const isWin = process.platform === 'win32';const target = isWin? 'C:\\Program Files (x86)\\Tailscale\\tailscale.exe'- : '/opt/homebrew/bin/tailscale';+ : '/Applications/Tailscale.app/Contents/MacOS/Tailscale';existsSync.mockImplementation((p) => p === target);expect(findTailscale()).toBe(target);});@@ -68,3 +73,67 @@ describe('findTailscale', () => {expect(callsWithBin.length).toBeGreaterThan(0);});});++describe('isSandboxedTailscale', () => {+ it('returns true for the App bundle path', () => {+ expect(isSandboxedTailscale(MACOS_TAILSCALE_APP_BUNDLE)).toBe(true);+ });++ it('returns false for Homebrew, /usr/bin, and arbitrary paths', () => {+ expect(isSandboxedTailscale('/opt/homebrew/bin/tailscale')).toBe(false);+ expect(isSandboxedTailscale('/usr/local/bin/tailscale')).toBe(false);+ expect(isSandboxedTailscale('/usr/bin/tailscale')).toBe(false);+ expect(isSandboxedTailscale('/some/random/path/tailscale')).toBe(false);+ expect(isSandboxedTailscale(null)).toBe(false);+ });+});++describe('hasOnlySandboxedTailscale', () => {+ let originalPath;+ let originalPlatform;++ beforeEach(() => {+ originalPath = process.env.PATH;+ originalPlatform = process.platform;+ Object.defineProperty(process, 'platform', { value: 'darwin', configurable: true });+ process.env.PATH = '';+ vi.clearAllMocks();+ });++ afterEach(() => {+ process.env.PATH = originalPath;+ Object.defineProperty(process, 'platform', { value: originalPlatform, configurable: true });+ });++ it('returns false on non-darwin platforms', () => {+ Object.defineProperty(process, 'platform', { value: 'linux', configurable: true });+ existsSync.mockReturnValue(true);+ expect(hasOnlySandboxedTailscale()).toBe(false);+ });++ it('returns false when the App bundle is absent', () => {+ existsSync.mockReturnValue(false);+ expect(hasOnlySandboxedTailscale()).toBe(false);+ });++ it('returns true when only the App bundle exists', () => {+ existsSync.mockImplementation((p) => p === MACOS_TAILSCALE_APP_BUNDLE);+ expect(hasOnlySandboxedTailscale()).toBe(true);+ });++ it('returns false when Homebrew tailscale is also present', () => {+ existsSync.mockImplementation((p) =>+ p === MACOS_TAILSCALE_APP_BUNDLE || p === '/opt/homebrew/bin/tailscale'+ );+ expect(hasOnlySandboxedTailscale()).toBe(false);+ });++ it('returns false when an unsandboxed tailscale is on PATH and no App-bundle is present', () => {+ // findTailscale walks candidates first, App-bundle last; PATH scan only+ // runs if NO candidate matches. So this case (no candidates + PATH match)+ // resolves to the PATH binary and the helper reports unsandboxed.+ process.env.PATH = '/some/custom/bin';+ existsSync.mockImplementation((p) => p === '/some/custom/bin/tailscale');+ expect(hasOnlySandboxedTailscale()).toBe(false);+ });+});diff --git a/server/services/certProvisioner.js b/server/services/certProvisioner.jsindex ec1a14a7be..34f2552679 100644--- a/server/services/certProvisioner.js+++ b/server/services/certProvisioner.js@@ -21,7 +21,7 @@ import { execFile } from 'child_process';import { existsSync, mkdirSync, statSync } from 'fs';import { promisify } from 'util';import { PATHS, atomicWrite } from '../lib/fileUtils.js';-import { findTailscale } from '../lib/tailscale.js';+import { findTailscale, isSandboxedTailscale } from '../lib/tailscale.js';import { getHttpsEnabledAtBoot } from '../lib/httpsState.js';import { PORTS } from '../lib/ports.js';import { certPaths } from '../../lib/certPaths.js';@@ -97,6 +97,15 @@ export async function provisionTailscaleCert() {const stderr = certResult._err;const firstLine = stderr.split('\n')[0].trim() || 'unknown error';const needsPeriod = !/[.!?]$/.test(firstLine);++ if (isSandboxedTailscale(bin) && /operation not permitted/i.test(stderr)) {+ return {+ ok: false,+ reason: 'tailscale-sandboxed',+ message: 'The macOS Tailscale.app CLI is sandboxed and can\'t write the cert file. Install the unsandboxed CLI with `brew install tailscale`, then restart PortOS and retry.'+ };+ }+const httpsHint = /HTTPS.*not.*enabled|invalid request/i.test(stderr)? ' Enable "HTTPS Certificates" at login.tailscale.com/admin/dns and retry.': '';diff --git a/setup.sh b/setup.shindex 5933150c0a..01161f0012 100755--- a/setup.sh+++ b/setup.sh@@ -36,6 +36,23 @@ fiecho ""+# macOS Tailscale.app CLI is sandboxed (`tailscale cert` can't write outside its+# container → EPERM). Detection delegates to server/lib/tailscale.js so the+# candidate path list stays a single source of truth.+if node -e "import('./server/lib/tailscale.js').then(m => process.exit(m.hasOnlySandboxedTailscale() ? 0 : 1)).catch(() => process.exit(1))" 2>/dev/null; then+ echo "Detected Tailscale.app without the unsandboxed CLI."+ echo "Installing tailscale via Homebrew so 'tailscale cert' can write to data/certs/..."+ if command -v brew &> /dev/null; then+ if ! brew install tailscale; then+ echo "⚠️ brew install tailscale failed — HTTPS via Tailscale won't work until you install it manually."+ fi+ else+ echo "⚠️ Homebrew not found. Install brew (https://brew.sh) then run: brew install tailscale"+ echo " Without it, the 'Enable HTTPS' button on the Instances page will fail with EPERM."+ fi+ echo ""+fi+# Install/update slash-do (project-level slash commands for Claude Code et al.)# via npx. Auto-detects the installed AI environments and lays down the latest# command set under ~/.claude/commands (or per-environment equivalent). The