Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
refactor(gateway): isolate provider adapter boundary
Rahmanf821d358a34c
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 1abfcb54..5e82c4b4 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -19,6 +19,7 @@ this is the *what*, and it is what Settings → About shows as “What's new”.**Changed**+- `gateway` isolate provider adapter boundary- `gateway` make lifecycle provider agnostic**Docs**diff --git a/docs/GATEWAY.md b/docs/GATEWAY.mdindex 74d2cde6..306fcc57 100644--- a/docs/GATEWAY.md+++ b/docs/GATEWAY.md@@ -150,7 +150,9 @@ Cloudflare currently reports managed-process/restart/reconnect support. A generireports public-health/external-detection capability but no managed-process/restart authority.The managed adapter contract is intentionally small: parse/validate start intent, start/reconcile through-its provider implementation, inspect health/state through the generic core, and expose capabilities.+its provider implementation, inspect health/state through the generic core, and expose capabilities. Provider-specific+tool/tunnel code is loaded lazily through this boundary, so read-only status/external-route paths do not import the+Cloudflare adapter and generic reconciliation calls the provider probe contract rather than a Cloudflare helper.This is additive to the existing shell architecture; it is not a new heavyweight plugin framework.## Managed versus external gatewaydiff --git a/scripts/lib/gateway-cloudflare-edge.sh b/scripts/lib/gateway-cloudflare-edge.shnew file mode 100755index 00000000..6ad50ef6--- /dev/null+++ b/scripts/lib/gateway-cloudflare-edge.sh@@ -0,0 +1,71 @@+#!/usr/bin/env bash+# Cloudflare edge readiness and Quick Tunnel discovery. Loaded only by the provider adapter.++# Cloudflare Quick Tunnel readiness discovery stays inside the adapter.+gateway_discover_quick_url() {+ local pid i+ pid="$(jq -r .pid <<<"$TUNNEL_IDENTITY")"+ for i in $(seq 1 80); do+ GATEWAY_PUBLIC_URL="$(grep -Eo 'https://[A-Za-z0-9-]+\.trycloudflare\.(com|app)' "$PROVIDER_LOG" | tail -1 || true)"+ [ -n "$GATEWAY_PUBLIC_URL" ] && return 0+ # Startup may legitimately exec an interpreter before publishing the URL.+ # Pin the spawned lifetime here; require exact executable/argv after readiness.+ [ "$(gateway_proc_start_ticks "$pid" 2>/dev/null || true)" = "$TUNNEL_PENDING_TICKS" ] || return 1+ sleep 0.25+ done+ return 1+}++gateway_quick_public_ipv4s() {+ local host response+ host="$(node - "$GATEWAY_PUBLIC_URL" <<'NODE'+try {+ const u = new URL(process.argv[2]);+ if (u.protocol !== 'https:' || !/^[A-Za-z0-9-]+\.trycloudflare\.(?:com|app)$/.test(u.hostname)) process.exit(1);+ process.stdout.write(u.hostname);+} catch { process.exit(1); }+NODE+)" || return 1+ response="$("$CURL" -fsS --max-time 5 -H 'accept: application/dns-json' \+ "https://cloudflare-dns.com/dns-query?name=$host&type=A" 2>/dev/null || true)"+ [ -n "$response" ] || return 1+ jq -r '.Answer[]? | select(.type == 1) | .data' <<<"$response" 2>/dev/null \+ | node -e '+ const net=require("net"), readline=require("readline");+ const blocked=(ip)=>{const p=ip.split(".").map(Number); return p[0]===0||p[0]===10||p[0]===127||p[0]>=224||+ (p[0]===169&&p[1]===254)||(p[0]===172&&p[1]>=16&&p[1]<=31)||(p[0]===192&&p[1]===168)||+ (p[0]===100&&p[1]>=64&&p[1]<=127)||(p[0]===198&&(p[1]===18||p[1]===19));};+ const rl=readline.createInterface({input:process.stdin,crlfDelay:Infinity});+ rl.on("line",ip=>{ip=ip.trim(); if(net.isIP(ip)===4&&!blocked(ip)) console.log(ip);});'+}++gateway_quick_edge_health_ok() {+ local host ip body+ [ "$GATEWAY_MODE" = temporary ] || return 1+ host="${GATEWAY_PUBLIC_URL#https://}"+ while IFS= read -r ip; do+ [ -n "$ip" ] || continue+ # --resolve bypasses only the caller's DNS cache. TLS still verifies the+ # random trycloudflare hostname, and the body must match this launch's nonce.+ body="$("$CURL" -fsS --max-time 5 --resolve "$host:443:$ip" \+ "$GATEWAY_PUBLIC_URL/api/health" 2>/dev/null || true)"+ gateway_health_body_matches_identity "$body" "$LOCAL_HEALTH_IDENTITY" && return 0+ done < <(gateway_quick_public_ipv4s || true)+ return 1+}++gateway_probe_public() {+ local seconds="${MSO_GATEWAY_PUBLIC_READY_SECONDS:-60}" i+ [ "${MSO_GATEWAY_SKIP_PUBLIC_PROBE:-0}" = 1 ] && return 0+ [[ "$seconds" =~ ^[0-9]+$ ]] && [ "$seconds" -ge 10 ] && [ "$seconds" -le 120 ] \+ || gateway_fail "MSO_GATEWAY_PUBLIC_READY_SECONDS must be an integer from 10 to 120"+ # A newly allocated Quick Tunnel hostname can exist before the edge route has+ # propagated. Do not weaken the MSO health/instance check; give the provider a+ # bounded readiness window instead. Named tunnels usually pass on the first poll.+ for i in $(seq 1 "$seconds"); do+ gateway_health_url_matches_identity "$GATEWAY_PUBLIC_URL" "$LOCAL_HEALTH_IDENTITY" && return 0+ gateway_quick_edge_health_ok && return 0+ sleep 1+ done+ return 1+}diff --git a/scripts/lib/gateway-config.sh b/scripts/lib/gateway-config.shindex 5ef7ffe0..a521fef1 100644--- a/scripts/lib/gateway-config.sh+++ b/scripts/lib/gateway-config.sh@@ -69,27 +69,17 @@ NODE}gateway_cmd_domain() {- local sub="${1:-show}" origin domain_host+ local sub="${1:-show}" origincase "$sub" inshow) origin="$(gateway_env_origin)"; [ -n "$origin" ] && gateway_info "$origin" || gateway_info "OS_PUBLIC_ORIGIN is not set" ;;set)[ -n "${2-}" ] || gateway_fail "usage: mso gateway domain set https://mso.example.com"origin="$(gateway_validate_public_origin "$2" 2>/dev/null || true)"[ -n "$origin" ] || gateway_fail "public origin must be a clean HTTPS origin"- gateway_rewrite_env_origin set "$origin"; domain_host="${origin#https://}"+ gateway_rewrite_env_origin set "$origin"gateway_info "saved OS_PUBLIC_ORIGIN=$origin in $ENVF"gateway_info "MSO still binds only to $LOCAL_URL"- cat <<CFG-named Cloudflare config example:- tunnel: <TUNNEL-UUID>- credentials-file: $HOME/.cloudflared/<TUNNEL-UUID>.json- ingress:- - hostname: $domain_host- service: $LOCAL_URL- - service: http_status:404-then: cloudflared tunnel route dns <TUNNEL-UUID-or-name> $domain_host-and: mso gateway start --config ~/.cloudflared/config.yml --tunnel <TUNNEL-UUID-or-name>-CFG+ gateway_provider_domain_hint "$(gateway_provider_default)" "$origin"gateway_info "rebuild/restart MSO after stable origin or split-host env changes" ;;clear) gateway_rewrite_env_origin clear; gateway_info "removed OS_PUBLIC_ORIGIN" ;;*) gateway_fail "usage: mso gateway domain show|set <https://host>|clear" ;;diff --git a/scripts/lib/gateway-lock.sh b/scripts/lib/gateway-lock.shindex 53595234..15561855 100755--- a/scripts/lib/gateway-lock.sh+++ b/scripts/lib/gateway-lock.sh@@ -27,7 +27,17 @@ GATEWAY_PENDING_CLEANUP=0gateway_operation_cleanup() {[ "${GATEWAY_PENDING_CLEANUP:-0}" = 1 ] || return 0if declare -F gateway_cleanup_failed_start >/dev/null 2>&1; then+ # A loaded managed-provider adapter owns provider + runtime rollback.gateway_cleanup_failed_start || true+ elif declare -F gateway_stop_pending_runtime >/dev/null 2>&1; then+ # Local-only fallback must remain signal-safe even when no provider adapter+ # has been loaded. Once the runtime has a captured identity, stop that exact+ # owned process; otherwise roll back only the provisional PID/start-ticks.+ if [ "${RUNTIME_STARTED_NOW:-false}" = true ] && [ "${RUNTIME_IDENTITY:-null}" != null ]; then+ gateway_stop_identity "$RUNTIME_IDENTITY" || true+ else+ gateway_stop_pending_runtime || true+ fifiGATEWAY_PENDING_CLEANUP=0}diff --git a/scripts/lib/gateway-pending.sh b/scripts/lib/gateway-pending.shindex 9e125d53..662e878a 100755--- a/scripts/lib/gateway-pending.sh+++ b/scripts/lib/gateway-pending.sh@@ -1,5 +1,5 @@#!/usr/bin/env bash-# Handshake + provisional child identity for the fork -> cloudflared exec window.+# Handshake + provisional child identity for the fork -> provider process exec window.TUNNEL_PENDING_PID=0TUNNEL_PENDING_TICKS=''@@ -63,12 +63,12 @@ gateway_spawn_held_tunnel() {[ -n "${gate:-}" ] || return 1TUNNEL_PENDING_GATE="$gate"- # The helper starts in a scrubbed environment and cannot exec cloudflared until+ # The helper starts in a scrubbed environment and cannot exec the provider process until# this parent has recorded the child lifetime. If this parent dies first, the# helper observes the missing/reused parent PID and exits on its own.nohup env -i "HOME=$HOME" "PATH=$safe_path" "LANG=$safe_lang" \/bin/bash "$ROOT/scripts/lib/gateway-held-child.sh" "$$" "$parent_ticks" "$gate" "$@" \- >>"$CF_LOG" 2>&1 & pid=$!+ >>"$PROVIDER_LOG" 2>&1 & pid=$!if ! gateway_track_pending_tunnel "$pid"; thenkill "$pid" 2>/dev/null || truegateway_pending_gate_cleanup@@ -77,18 +77,3 @@ gateway_spawn_held_tunnel() {printf '1\n' | mso_private_state_atomic_write "$gate" >/dev/null || { gateway_stop_pending_tunnel; return 1; }TUNNEL_SPAWN_PID="$pid"}--# Readiness discovery belongs to the provisional child lifetime, before final identity.-gateway_discover_quick_url() {- local pid i- pid="$(jq -r .pid <<<"$TUNNEL_IDENTITY")"- for i in $(seq 1 80); do- GATEWAY_PUBLIC_URL="$(grep -Eo 'https://[A-Za-z0-9-]+\.trycloudflare\.(com|app)' "$CF_LOG" | tail -1 || true)"- [ -n "$GATEWAY_PUBLIC_URL" ] && return 0- # Startup may legitimately exec an interpreter before publishing the URL.- # Pin the spawned lifetime here; require exact executable/argv after readiness.- [ "$(gateway_proc_start_ticks "$pid" 2>/dev/null || true)" = "$TUNNEL_PENDING_TICKS" ] || return 1- sleep 0.25- done- return 1-}diff --git a/scripts/lib/gateway-provider.sh b/scripts/lib/gateway-provider.shindex 2ef77f83..6f94e166 100644--- a/scripts/lib/gateway-provider.sh+++ b/scripts/lib/gateway-provider.sh@@ -4,6 +4,19 @@# gateway-tunnel.sh. New providers should implement the same small contract rather# than branching provider names through the core.+GATEWAY_CLOUDFLARE_ADAPTER_LOADED=0+gateway_provider_load_cloudflare_adapter() {+ [ "$GATEWAY_CLOUDFLARE_ADAPTER_LOADED" = 1 ] && return 0+ # Provider-specific tool/tunnel code is loaded only through this boundary.+ # shellcheck source=scripts/lib/gateway-tool.sh+ . "$ROOT/scripts/lib/gateway-tool.sh"+ # shellcheck source=scripts/lib/gateway-tunnel.sh+ . "$ROOT/scripts/lib/gateway-tunnel.sh"+ # shellcheck source=scripts/lib/gateway-cloudflare-edge.sh+ . "$ROOT/scripts/lib/gateway-cloudflare-edge.sh"+ GATEWAY_CLOUDFLARE_ADAPTER_LOADED=1+}+gateway_provider_family() {case "${1:-}" incloudflare|cloudflare-quick|cloudflare-named) printf '%s\n' cloudflare ;;@@ -34,6 +47,7 @@ gateway_provider_default() { printf '%s\n' cloudflare; }gateway_provider_parse_start_args() {GATEWAY_SELECTED_PROVIDER="$(gateway_provider_default)"# Backward-compatible Cloudflare adapter arguments remain the current default.+ gateway_provider_load_cloudflare_adaptergateway_parse_start_args "$@"}@@ -46,7 +60,7 @@ gateway_provider_start_locked() {# explicit named-start semantics under the same lifecycle lock.if active="$(gateway_active_state)"; thencase "$(gateway_provider_family "$provider")" in- cloudflare) gateway_cmd_start_locked ;;+ cloudflare) gateway_provider_load_cloudflare_adapter; gateway_cmd_start_locked ;;*) gateway_fail "provider '$provider' is not implemented for managed start yet" ;;esacreturn $?@@ -60,7 +74,7 @@ gateway_provider_start_locked() {# ownership takeover from public-route observation.if [ -n "${GATEWAY_CONFIG:-}${GATEWAY_TUNNEL:-}" ]; thencase "$(gateway_provider_family "$provider")" in- cloudflare) gateway_cmd_start_locked ;;+ cloudflare) gateway_provider_load_cloudflare_adapter; gateway_cmd_start_locked ;;*) gateway_fail "provider '$provider' is not implemented for managed start yet" ;;esacreturn $?@@ -76,7 +90,7 @@ gateway_provider_start_locked() {ficase "$(gateway_provider_family "$provider")" in- cloudflare) gateway_cmd_start_locked ;;+ cloudflare) gateway_provider_load_cloudflare_adapter; gateway_cmd_start_locked ;;*) gateway_fail "provider '$provider' is not implemented for managed start yet" ;;esac}@@ -85,6 +99,7 @@ gateway_provider_doctor_readonly() {local provider="$(gateway_provider_family "${1:-custom}")"case "$provider" incloudflare)+ gateway_provider_load_cloudflare_adapter# Explicitly disable the resolver's install path: doctor is observational.if MSO_GATEWAY_NO_AUTO_INSTALL=1 gateway_resolve_cloudflared >/dev/null 2>&1; thengateway_info " ok provider cloudflare: $("$CLOUDFLARED" --version 2>/dev/null | head -1)"@@ -97,6 +112,43 @@ gateway_provider_doctor_readonly() {esac}+gateway_provider_install() {+ local provider="$(gateway_provider_family "${1:-$(gateway_provider_default)}")"+ case "$provider" in+ cloudflare) gateway_provider_load_cloudflare_adapter; gateway_cmd_install_tool ;;+ *) gateway_fail "provider '$provider' has no MSO-managed install adapter" ;;+ esac+}++gateway_provider_probe_public() {+ local provider="$(gateway_provider_family "${1:-custom}")"+ case "$provider" in+ cloudflare) gateway_provider_load_cloudflare_adapter; gateway_probe_public ;;+ *) gateway_health_url_matches_identity "$GATEWAY_PUBLIC_URL" "$LOCAL_HEALTH_IDENTITY" ;;+ esac+}++gateway_provider_domain_hint() {+ local provider="$(gateway_provider_family "${1:-$(gateway_provider_default)}")" origin="$2" domain_host+ domain_host="${origin#https://}"+ case "$provider" in+ cloudflare)+ cat <<CFG+named Cloudflare config example:+ tunnel: <TUNNEL-UUID>+ credentials-file: $HOME/.cloudflared/<TUNNEL-UUID>.json+ ingress:+ - hostname: $domain_host+ service: $LOCAL_URL+ - service: http_status:404+then: cloudflared tunnel route dns <TUNNEL-UUID-or-name> $domain_host+and: mso gateway start --config ~/.cloudflared/config.yml --tunnel <TUNNEL-UUID-or-name>+CFG+ ;;+ *) gateway_info "configure provider '$provider' to route $origin to $LOCAL_URL; MSO will verify it through /api/health" ;;+ esac+}+gateway_provider_supervisor() {local ownership="$1" explicit="${MSO_GATEWAY_SUPERVISOR:-}"if [ -n "$explicit" ]; then printf '%s\n' "$explicit"; return 0; fidiff --git a/scripts/lib/gateway-reconcile.sh b/scripts/lib/gateway-reconcile.shindex f1ea9753..863fd60f 100755--- a/scripts/lib/gateway-reconcile.sh+++ b/scripts/lib/gateway-reconcile.sh@@ -22,7 +22,7 @@ gateway_reconcile_active_tunnel() {gateway_assert_port_loopback_onlyLOCAL_HEALTH_IDENTITY="$(gateway_health_url_identity "$LOCAL_URL" "${RUNTIME_INSTANCE_ID:-}")" \|| { gateway_reconcile_runtime_rollback; gateway_fail "active tunnel has no verified local MSO runtime"; }- if ! gateway_probe_public; then+ if ! gateway_provider_probe_public "$provider"; thengateway_reconcile_runtime_rollbackgateway_fail "active tunnel did not return the selected local MSO health identity"fidiff --git a/scripts/lib/gateway-tunnel.sh b/scripts/lib/gateway-tunnel.shindex dc1b746a..9132c5b6 100644--- a/scripts/lib/gateway-tunnel.sh+++ b/scripts/lib/gateway-tunnel.sh@@ -62,7 +62,7 @@ gateway_validate_named_tunnel() {gateway_spawn_tunnel() {local pid identity- gateway_private_file "$CF_LOG"; : >"$CF_LOG"+ gateway_private_file "$PROVIDER_LOG"; : >"$PROVIDER_LOG"# The parent intentionally has OS_LOGIN_PASSWORD, session secrets and BYOK keys# for the Next runtime. The held-child helper scrubs that environment and cannot# exec cloudflared until this parent has persisted the child lifetime identity.@@ -98,60 +98,6 @@ gateway_refresh_tunnel_identity() {}-gateway_quick_public_ipv4s() {- local host response- host="$(node - "$GATEWAY_PUBLIC_URL" <<'NODE'-try {- const u = new URL(process.argv[2]);- if (u.protocol !== 'https:' || !/^[A-Za-z0-9-]+\.trycloudflare\.(?:com|app)$/.test(u.hostname)) process.exit(1);- process.stdout.write(u.hostname);-} catch { process.exit(1); }-NODE-)" || return 1- response="$("$CURL" -fsS --max-time 5 -H 'accept: application/dns-json' \- "https://cloudflare-dns.com/dns-query?name=$host&type=A" 2>/dev/null || true)"- [ -n "$response" ] || return 1- jq -r '.Answer[]? | select(.type == 1) | .data' <<<"$response" 2>/dev/null \- | node -e '- const net=require("net"), readline=require("readline");- const blocked=(ip)=>{const p=ip.split(".").map(Number); return p[0]===0||p[0]===10||p[0]===127||p[0]>=224||- (p[0]===169&&p[1]===254)||(p[0]===172&&p[1]>=16&&p[1]<=31)||(p[0]===192&&p[1]===168)||- (p[0]===100&&p[1]>=64&&p[1]<=127)||(p[0]===198&&(p[1]===18||p[1]===19));};- const rl=readline.createInterface({input:process.stdin,crlfDelay:Infinity});- rl.on("line",ip=>{ip=ip.trim(); if(net.isIP(ip)===4&&!blocked(ip)) console.log(ip);});'-}--gateway_quick_edge_health_ok() {- local host ip body- [ "$GATEWAY_MODE" = temporary ] || return 1- host="${GATEWAY_PUBLIC_URL#https://}"- while IFS= read -r ip; do- [ -n "$ip" ] || continue- # --resolve bypasses only the caller's DNS cache. TLS still verifies the- # random trycloudflare hostname, and the body must match this launch's nonce.- body="$("$CURL" -fsS --max-time 5 --resolve "$host:443:$ip" \- "$GATEWAY_PUBLIC_URL/api/health" 2>/dev/null || true)"- gateway_health_body_matches_identity "$body" "$LOCAL_HEALTH_IDENTITY" && return 0- done < <(gateway_quick_public_ipv4s || true)- return 1-}--gateway_probe_public() {- local seconds="${MSO_GATEWAY_PUBLIC_READY_SECONDS:-60}" i- [ "${MSO_GATEWAY_SKIP_PUBLIC_PROBE:-0}" = 1 ] && return 0- [[ "$seconds" =~ ^[0-9]+$ ]] && [ "$seconds" -ge 10 ] && [ "$seconds" -le 120 ] \- || gateway_fail "MSO_GATEWAY_PUBLIC_READY_SECONDS must be an integer from 10 to 120"- # A newly allocated Quick Tunnel hostname can exist before the edge route has- # propagated. Do not weaken the MSO health/instance check; give the provider a- # bounded readiness window instead. Named tunnels usually pass on the first poll.- for i in $(seq 1 "$seconds"); do- gateway_health_url_matches_identity "$GATEWAY_PUBLIC_URL" "$LOCAL_HEALTH_IDENTITY" && return 0- gateway_quick_edge_health_ok && return 0- sleep 1- done- return 1-}-gateway_cleanup_failed_start() {# Until durable commit, the PID/start-ticks handshake proves this is OUR child# even if an interpreter exec or process-title update changed its argv identity.@@ -186,11 +132,11 @@ gateway_cmd_start_locked() {TUNNEL_IDENTITY=null; GATEWAY_PUBLIC_URL="${GATEWAY_PUBLIC_URL:-}"gateway_spawn_tunnel || { gateway_cleanup_failed_start; gateway_fail "cloudflared failed to start with the expected argv"; }if [ "$GATEWAY_MODE" = temporary ]; then- gateway_discover_quick_url || { gateway_cleanup_failed_start; gateway_fail "Quick Tunnel did not return a public URL; see $CF_LOG"; }+ gateway_discover_quick_url || { gateway_cleanup_failed_start; gateway_fail "Quick Tunnel did not return a public URL; see $PROVIDER_LOG"; }fiGATEWAY_PUBLIC_URL="$(gateway_validate_public_origin "$GATEWAY_PUBLIC_URL" 2>/dev/null || true)"[ -n "$GATEWAY_PUBLIC_URL" ] || { gateway_cleanup_failed_start; gateway_fail "tunnel produced an invalid public origin"; }- gateway_probe_public || { gateway_cleanup_failed_start; gateway_fail "public endpoint did not return the MSO health contract; see $CF_LOG"; }+ gateway_probe_public || { gateway_cleanup_failed_start; gateway_fail "public endpoint did not return the MSO health contract; see $PROVIDER_LOG"; }gateway_refresh_tunnel_identity || { gateway_cleanup_failed_start; gateway_fail "ready tunnel no longer matches its spawned process"; }if ! gateway_write_state "$GATEWAY_PROVIDER" "$GATEWAY_MODE" "$GATEWAY_PUBLIC_URL" "$TUNNEL_IDENTITY"; thengateway_cleanup_failed_startdiff --git a/scripts/mso-gateway b/scripts/mso-gatewayindex c3e40bdc..e8f235f5 100755--- a/scripts/mso-gateway+++ b/scripts/mso-gateway@@ -14,7 +14,6 @@ STATE_ROOT=''GATEWAY_CANONICAL_ROOT=''GATEWAY_SCOPE_ID=''GATEWAY_ENV_IDENTITY=''-CLOUDFLARED=""CURL="${MSO_GATEWAY_CURL:-$(command -v curl 2>/dev/null || true)}"for dep in node jq sha256sum realpath stat mktemp flock; do command -v "$dep" >/dev/null || { echo "mso gateway: missing dependency: $dep" >&2; exit 1; }; done@@ -54,7 +53,7 @@ elseSTATE_ROOT="$(mso_private_state_dir "$STATE_BASE/$GATEWAY_SCOPE_ID")" || gateway_fail "unsafe scoped gateway state directory"fiSTATE_FILE="$STATE_ROOT/state.json"-CF_LOG="$STATE_ROOT/cloudflared.log"+PROVIDER_LOG="$STATE_ROOT/provider.log"RUNTIME_LOG="$STATE_ROOT/runtime.log"LOCK_FILE="$STATE_ROOT/lifecycle.lock"LOCK_HELD=0@@ -62,10 +61,7 @@ GATEWAY_LOCK_FD=''# shellcheck source=scripts/lib/gateway-network.sh. "$ROOT/scripts/lib/gateway-network.sh"-# Cloudflare is the current managed-provider adapter; generic core calls it through-# gateway-provider.sh rather than treating it as an architecture boundary.-# shellcheck source=scripts/lib/gateway-tool.sh-. "$ROOT/scripts/lib/gateway-tool.sh"+# Provider-specific implementation is loaded lazily by gateway-provider.sh.# shellcheck source=scripts/lib/gateway-provider.sh. "$ROOT/scripts/lib/gateway-provider.sh"# shellcheck source=scripts/lib/gateway-lock.sh@@ -82,8 +78,6 @@ GATEWAY_LOCK_FD=''. "$ROOT/scripts/lib/gateway-state.sh"# shellcheck source=scripts/lib/gateway-pending.sh. "$ROOT/scripts/lib/gateway-pending.sh"-# shellcheck source=scripts/lib/gateway-tunnel.sh-. "$ROOT/scripts/lib/gateway-tunnel.sh"# shellcheck source=scripts/lib/gateway-reconcile.sh. "$ROOT/scripts/lib/gateway-reconcile.sh"gateway_with_runtime_shared() {@@ -109,7 +103,7 @@ case "${1:-status}" instatus) shift || true; gateway_cmd_status "$@" ;;url) gateway_cmd_url ;;doctor) gateway_cmd_doctor ;;- install) gateway_cmd_install_tool ;;+ install) gateway_provider_install ;;domain) shift; gateway_cmd_domain "$@" ;;web) gateway_cmd_web "$@" ;;local-start) gateway_with_lock gateway_with_runtime_shared gateway_cmd_local_start_locked ;; # internal: onboard/web/update fallbackdiff --git a/scripts/mso-gateway-provider-boundary.test.ts b/scripts/mso-gateway-provider-boundary.test.tsnew file mode 100644index 00000000..1ad8a8d6--- /dev/null+++ b/scripts/mso-gateway-provider-boundary.test.ts@@ -0,0 +1,36 @@+import fs from "node:fs";+import path from "node:path";+import { describe, expect, it } from "vitest";++const ROOT = path.resolve(__dirname, "..");+const read = (relative: string) => fs.readFileSync(path.join(ROOT, relative), "utf8");++describe("gateway provider adapter boundary", () => {+ it("keeps Cloudflare implementation imports out of the generic dispatcher", () => {+ const dispatcher = read("scripts/mso-gateway");+ expect(dispatcher).toContain('scripts/lib/gateway-provider.sh');+ expect(dispatcher).not.toContain('scripts/lib/gateway-tool.sh');+ expect(dispatcher).not.toContain('scripts/lib/gateway-tunnel.sh');+ expect(dispatcher).not.toContain("CLOUDFLARED");+ expect(dispatcher).not.toContain("CF_LOG");+ });++ it("keeps provisional process handling provider-neutral and routes probes through the adapter", () => {+ const pending = read("scripts/lib/gateway-pending.sh");+ const reconcile = read("scripts/lib/gateway-reconcile.sh");+ const provider = read("scripts/lib/gateway-provider.sh");++ expect(pending).not.toContain("trycloudflare");+ expect(pending).not.toContain("cloudflared");+ expect(pending).not.toContain("CF_LOG");+ expect(pending).toContain("PROVIDER_LOG");++ expect(reconcile).toContain('gateway_provider_probe_public "$provider"');+ expect(reconcile).not.toMatch(/\bgateway_probe_public\b/);++ expect(provider).toContain('scripts/lib/gateway-tool.sh');+ expect(provider).toContain('scripts/lib/gateway-tunnel.sh');+ expect(provider).toContain('scripts/lib/gateway-cloudflare-edge.sh');+ expect(provider).toContain("gateway_provider_load_cloudflare_adapter");+ });+});