Skip to content

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

stop silently flipping :5555 from HTTP to self-signed HTTPS on first run

[._.]/ Adam Eivyd82c88f84756
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 1bcf107edc..c8a7bf67c7 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -4,6 +4,8 @@
## Changed
+- **First-run no longer silently flips :5555 from HTTP to self-signed HTTPS.** `scripts/setup-cert.js` ran on every `npm start` and, when Tailscale was unavailable, auto-generated a self-signed cert — breaking the documented `http://localhost:5555` URL and forcing a browser click-through. It now only auto-generates a self-signed cert when (a) the user explicitly passes `--self-signed`, or (b) a self-signed cert is already present (renewal path). Fresh installs without Tailscale stay HTTP-only on :5555 so the URL in the README and in `setup.sh`'s final banner just works. `setup.sh`'s "Access at:" banner is now cert-aware — when HTTPS got provisioned it prints the loopback HTTP mirror (`http://localhost:5553`) and the Tailscale hostname instead of the broken `http://localhost:5555`.
+
- **PLAN.md — CODEX 5.5 review residue folded in.** Triaged the 2026-04-25 CODEX 5.5 product/engineering review: confirmed the six concrete bugs (Brain Feeds + Time Capsule nav coverage, `/cos/scripts` dead target, `/ask` full-height workaround, client lint, route/nav contract tests) are all shipped, and added 15 unaddressed strategic items to PLAN.md under a new `### CODEX 5.5 review residue` Backlog section (perf/bundle, polling consolidation, client error reporter, network exposure UI, unified Review Queue, health provenance chips, dashboard intent layouts, autonomy guardrails, onboarding capability map, mobile task flows, operating-loop dashboard, sidebar IA collapse, visual modes, decision/provenance pattern, teaching empty states). Enriched the existing Knowledge Legacy Future Idea with the bundle scope from the review.
## Fixed
diff --git a/PLAN.md b/PLAN.md
index f57c939190..e29aae462b 100644
--- a/PLAN.md
+++ b/PLAN.md
@@ -79,6 +79,7 @@ _Nothing currently parked — pick the next item from the Backlog._
- [ ] [datasync-migrate-categories-to-atomicwrite] **Migrate all `dataSync.js` categories to `atomicWrite`.** Every category (`goals`, `character`, `digitalTwin`, `meatspace`, `universe`, `pipeline`) inlines `ensureDir + writeFile + JSON.stringify(..., null, 2)` — 6+ duplicate sites. `server/lib/fileUtils.js:124` exports `atomicWrite(path, data)` that handles all three steps as a temp+rename atomic write. One-line collapse per site + meaningful partial-write protection for the larger pipeline JSON files (which other services write concurrently). Surfaced by /simplify during `extend-syncorchestrator-to-cover-pipeline-universe`; deferred to keep that PR focused on the new categories.
- [ ] [datasync-checksum-only-fast-path] **Add a checksum-only fast path to `dataSync.js`.** `getChecksum(category)` currently calls the category's `getSnapshot` and discards `data` (`server/services/dataSync.js:451-456`) — every probe materializes the full payload. With pipeline/universe added the wasted work scales with the largest user-creative payload. Define per-category `getChecksum` shortcuts (e.g. hash file size+mtime, or hash raw bytes without parse) and dispatch via `CATEGORIES[cat].getChecksum`. The orchestrator hits the checksum endpoint every cycle — this is the hottest sync-side I/O. Surfaced by /simplify during `extend-syncorchestrator-to-cover-pipeline-universe`.
- [x] [extract-flatten-canon-descriptor-fragments-helper] ~~**Extract `flattenCanonDescriptorFragments(fragments, { separator, trailingPeriod })` into `server/lib/canonPrompt.js` (+ client mirror).**~~ Shipped — `flattenCanonDescriptorFragments` + `mapCanonDescriptorFragments` added to `server/lib/canonPrompt.js` and mirrored to `client/src/lib/canonPrompt.js`. All 6 inline sites migrated: server `canonPrompt.js`/`scenePrompt.js`/`services/pipeline/visualStages.js`/`services/universeBuilder.js` + the two client mirrors. The `mapCanonDescriptorFragments` companion supports the scene-prompt budget-truncator that needs the array form.
+- [ ] [consolidate-cert-path-constants] **Consolidate `CERT_DIR`/`CERT_PATH`/`KEY_PATH`/`META_PATH` constants.** Re-declared in `scripts/setup-cert.js`, `scripts/open-ui-in-browser.js`, `server/services/certProvisioner.js`, and `server/services/certRenewer.js` (4 sites). Surfaced by `/simplify` during the first-run HTTPS-auto-flip fix (2026-05-19); deferred to keep that PR scoped. Candidate home: `lib/certPaths.js` (alongside `lib/tailscale-https.js` so both runtime + bootstrap can import).
- [ ] [cleanplateprompt-migrate-to-rich-canon-fragments] **Migrate `client/src/lib/cleanPlatePrompt.js#composeCleanPlatePrompt` to `richCanonDescriptorFragments('place', setting)`.** Clean-plate prompt builder (Cluster A — A4 setting reference renders) hand-rolls `description + Palette + recurringDetails` extraction at `cleanPlatePrompt.js:26-30` and is missing `era` / `weather` for the same reason `[pipeline-visual-stages-setting-field-injection]` was missing them — both are visual prompts that benefit from period/atmosphere cues. Tightly scoped sibling change (one client file + one test file). Deferred from that PR because the PLAN item targeted storyboard+comic-panel specifically; clean plates are setting-reference renders, adjacent but distinct.
### v2.1.0 pre-release review residue (deferred from main→release multi-agent review, 2026-05-16)
diff --git a/README.md b/README.md
index d284682879..b1be848b1c 100644
--- a/README.md
+++ b/README.md
@@ -239,12 +239,15 @@ Access PortOS at `http://localhost:5555` (or via Tailscale at `http://<machine>.
For HTTPS (recommended — required for the in-browser microphone, and you'll get a trusted cert via Tailscale's Let's Encrypt integration):
```bash
-npm run setup:cert # uses `tailscale cert` if available, else self-signed
+npm run setup:cert # Tailscale + Let's Encrypt (trusted)
+npm run setup:cert -- --self-signed # fallback if you don't have Tailscale
pm2 restart ecosystem.config.cjs
```
After that, `https://<machine>.<tailnet>.ts.net:5555` is the user-facing URL on every device. The same `:5555` is used for both HTTP and HTTPS — only the scheme changes. When HTTPS is enabled a loopback-only HTTP mirror also spawns at `http://localhost:5553` so local curl/scripts skip cert warnings (override with `PORTOS_HTTP_PORT`).
+> A fresh install with no Tailscale **stays on HTTP**, so `http://localhost:5555` works out of the box. `npm start` will only auto-provision a cert when Tailscale's `tailscale cert` succeeds — it won't silently flip you to a self-signed HTTPS that breaks the URL above. Pass `--self-signed` if you want HTTPS without Tailscale (browser warning included).
+
PM2 keeps PortOS running in the background and auto-restarts on reboot (with `pm2 save` + `pm2 startup`).
### Development Mode
diff --git a/scripts/setup-cert.js b/scripts/setup-cert.js
index 81f1fc14fd..87e42882ed 100644
--- a/scripts/setup-cert.js
+++ b/scripts/setup-cert.js
@@ -3,9 +3,13 @@
* Provisions a TLS cert for PortOS at data/certs/{cert,key}.pem.
*
* Prefers a real Let's Encrypt cert via `tailscale cert` (browsers trust it,
- * no click-through). Falls back to a self-signed cert covering localhost +
- * every non-internal IPv4 on the host (including the Tailscale IP) when
- * Tailscale HTTPS isn't available.
+ * no click-through). Will only generate a self-signed cert when the user opts
+ * in via `--self-signed` OR a self-signed cert is already present on disk
+ * (renewal/IP-rotation path). On a fresh install without Tailscale and without
+ * `--self-signed`, this script exits cleanly and PortOS keeps serving plain
+ * HTTP on :5555 — silently flipping a vanilla install to HTTPS with a
+ * self-signed cert breaks the documented `http://localhost:5555` URL and
+ * forces a click-through warning, which is a worse first-run UX than HTTP.
*
* Why we prefer Tailscale: Let's Encrypt does not issue certs for bare IPs.
* Tailscale owns `ts.net` and provisions LE certs against your tailnet's
@@ -28,6 +32,7 @@ import { networkInterfaces } from 'os';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { findTailscale } from '../server/lib/tailscale.js';
+import { hasTailscaleCert } from '../lib/tailscale-https.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = join(__dirname, '..');
@@ -178,6 +183,23 @@ function trySelfSigned() {
}
}
+// Implicit fallback gate. We only auto-generate a self-signed cert when the
+// user has previously opted in (existing self-signed cert on disk — we want
+// to keep it fresh on IP changes). Otherwise we exit without provisioning so
+// `npm start`'s mandatory `setup-cert.js` step doesn't silently flip a vanilla
+// install from HTTP→HTTPS-self-signed and break the documented :5555 URL.
+function maybeFallbackSelfSigned() {
+ const meta = readMeta();
+ if (meta?.mode === 'self-signed' && hasTailscaleCert(CERT_DIR)) {
+ trySelfSigned();
+ return;
+ }
+ console.log(`ℹ️ Staying HTTP-only on :5555 (no Tailscale cert provisioned).`);
+ console.log(` To enable HTTPS (required for in-browser mic), choose one:`);
+ console.log(` • Install Tailscale + enable HTTPS in the tailnet admin, then \`npm run setup:cert\``);
+ console.log(` • Generate a self-signed cert (browser warning): \`npm run setup:cert -- --self-signed\``);
+}
+
if (SELF_SIGNED_ONLY) {
trySelfSigned();
process.exit(0);
@@ -185,8 +207,8 @@ if (SELF_SIGNED_ONLY) {
const bin = findTailscale();
if (!bin) {
- console.log(`ℹ️ Tailscale CLI not found — falling back to self-signed cert.`);
- trySelfSigned();
+ console.log(`ℹ️ Tailscale CLI not found.`);
+ maybeFallbackSelfSigned();
process.exit(0);
}
@@ -194,15 +216,15 @@ let status;
try {
status = tailscaleStatus(bin);
} catch (err) {
- console.log(`ℹ️ tailscale status failed (${err.message}) — falling back to self-signed cert.`);
- trySelfSigned();
+ console.log(`ℹ️ tailscale status failed (${err.message}).`);
+ maybeFallbackSelfSigned();
process.exit(0);
}
const hostname = tailscaleHostname(status);
if (!hostname || status.BackendState !== 'Running') {
- console.log(`ℹ️ Tailscale not running or no DNSName — falling back to self-signed cert.`);
- trySelfSigned();
+ console.log(`ℹ️ Tailscale not running or no DNSName.`);
+ maybeFallbackSelfSigned();
process.exit(0);
}
@@ -217,15 +239,15 @@ console.log(`🔒 Fetching Let's Encrypt cert for ${hostname} via Tailscale...`)
try {
runTailscaleCert(bin, hostname);
} catch (err) {
- console.log(`⚠️ tailscale cert failed (${err.message}) — falling back to self-signed cert.`);
+ console.log(`⚠️ tailscale cert failed (${err.message}).`);
console.log(` (Common cause: HTTPS Certificates not enabled in the tailnet admin console at login.tailscale.com/admin/dns)`);
- trySelfSigned();
+ maybeFallbackSelfSigned();
process.exit(0);
}
if (!existsSync(CERT_PATH) || !existsSync(KEY_PATH)) {
- console.log(`⚠️ tailscale cert returned success but files missing — falling back to self-signed.`);
- trySelfSigned();
+ console.log(`⚠️ tailscale cert returned success but files missing.`);
+ maybeFallbackSelfSigned();
process.exit(0);
}
diff --git a/setup.sh b/setup.sh
index 7040c04a61..bf99896924 100755
--- a/setup.sh
+++ b/setup.sh
@@ -93,6 +93,22 @@ if [ -t 0 ]; then
done
fi
+# Print the URL the user should open. The server flips between HTTP and HTTPS
+# on :5555 based on whether data/certs/{cert,key}.pem exist (see
+# lib/tailscale-https.js). When HTTPS is active, :5555 speaks TLS only — plain
+# http://localhost:5555 hits a TLS mismatch — and a loopback HTTP mirror spawns
+# on :5553 (or $PORTOS_HTTP_PORT) for cert-free local access.
+print_access_url() {
+ if [ -f data/certs/cert.pem ] && [ -f data/certs/key.pem ]; then
+ local mirror_port="${PORTOS_HTTP_PORT:-5553}"
+ echo "Access at: http://localhost:${mirror_port} (loopback HTTP mirror — no cert warning)"
+ echo " or: https://<machine>.<tailnet>.ts.net:5555 (trusted via Tailscale)"
+ echo " or: https://localhost:5555 (browser will warn on self-signed cert)"
+ else
+ echo "Access at: http://localhost:5555"
+ fi
+}
+
if [ "$start_now" = "1" ]; then
echo ""
echo "Starting PortOS..."
@@ -104,7 +120,7 @@ if [ "$start_now" = "1" ]; then
echo " PortOS is running"
echo "==================================="
echo ""
- echo "Access at: http://localhost:5555"
+ print_access_url
echo "Logs: npm run pm2:logs"
echo "Stop: npm run pm2:stop"
echo ""
@@ -119,6 +135,6 @@ else
echo " Stop: npm run pm2:stop"
echo " Logs: npm run pm2:logs"
echo ""
- echo "Access at: http://localhost:5555"
+ print_access_url
echo ""
fi