Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

WIP studio mode: network policy, studio profile, HTTP gate (unbuilt)

islandmedb06f2374653e
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f655eec0..00293368 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,14 @@ include(cmake/BuildSpeed.cmake)
include(cmake/Dependencies.cmake)
# --- Core library: geometry, sculpting, undo, commands, file IO (no GPU/UI) ---
+# A custom studio build (docs/studios.md): the profile is compiled in (core/StudioProfile.h); empty for public builds.
+set(SCULPTFORGE_STUDIO_PROFILE "" CACHE FILEPATH "studio.json to bake into a studio build (empty: public build)")
+set(SF_STUDIO_JSON "")
+if(SCULPTFORGE_STUDIO_PROFILE)
+ file(READ ${SCULPTFORGE_STUDIO_PROFILE} SF_STUDIO_JSON)
+endif()
+file(CONFIGURE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/StudioBuild.cpp CONTENT
+ "// Generated by CMake (SCULPTFORGE_STUDIO_PROFILE)\nnamespace sf { const char* builtInStudioProfile() { return R\"sfstudio(${SF_STUDIO_JSON})sfstudio\"; } }\n")
add_library(sculptforge_core STATIC
src/core/Mesh.cpp
src/core/BVH.cpp
@@ -62,6 +70,9 @@ add_library(sculptforge_core STATIC
src/core/Script.cpp
src/core/Macro.cpp
src/core/Pack.cpp
+ src/core/NetworkPolicy.cpp
+ src/core/StudioProfile.cpp
+ ${CMAKE_CURRENT_BINARY_DIR}/StudioBuild.cpp
src/core/Json.cpp
src/core/BrushRecipe.cpp
src/core/BrushPacks.cpp
diff --git a/src/ai/Http.cpp b/src/ai/Http.cpp
index 097ab450..d4439b8d 100644
--- a/src/ai/Http.cpp
+++ b/src/ai/Http.cpp
@@ -2,6 +2,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "ai/Http.h"
+#include "core/NetworkPolicy.h"
+
#include <atomic>
#include <chrono>
#include <random>
@@ -19,6 +21,14 @@ namespace sf::ai {
namespace {
std::atomic<uint64_t> gRequests{0};
+
+// Studio mode (core/NetworkPolicy.h): a URL off the studio's list is refused before anything is sent or counted.
+bool refused(const std::string& url, HttpResponse& r) {
+ std::string why;
+ if (net::urlAllowed(url, &why)) return false;
+ r.error = why;
+ return true;
+}
}
uint64_t httpRequestCount() { return gRequests; }
@@ -76,8 +86,9 @@ struct Handle {
HttpResponse httpRequestStream(const std::string& method, const std::string& url, const std::vector<std::string>& headers,
const std::string& body, int timeoutSeconds,
const std::function<bool(const char*, size_t)>& onData) {
- ++gRequests;
HttpResponse r;
+ if (refused(url, r)) return r;
+ ++gRequests;
std::wstring wurl = widen(url);
URL_COMPONENTS uc{};
uc.dwStructSize = sizeof uc;
@@ -102,6 +113,10 @@ HttpResponse httpRequestStream(const std::string& method, const std::string& url
}
const int ms = timeoutSeconds * 1000;
WinHttpSetTimeouts(session.h, ms, ms, ms, ms);
+ if (net::offlineMode()) { // studio mode: a redirect could leave the studio's list
+ DWORD never = WINHTTP_OPTION_REDIRECT_POLICY_NEVER;
+ WinHttpSetOption(session.h, WINHTTP_OPTION_REDIRECT_POLICY, &never, sizeof never);
+ }
Handle connection{WinHttpConnect(session.h, host, uc.nPort, 0)};
if (!connection.h) {
r.error = lastError("WinHttpConnect");
@@ -160,11 +175,11 @@ size_t writeCallback(char* data, size_t size, size_t count, void* user) {
HttpResponse httpRequestStream(const std::string& method, const std::string& url, const std::vector<std::string>& headers,
const std::string& body, int timeoutSeconds,
const std::function<bool(const char*, size_t)>& onData) {
+ HttpResponse r;
+ if (refused(url, r)) return r;
++gRequests;
static std::once_flag once;
std::call_once(once, [] { curl_global_init(CURL_GLOBAL_DEFAULT); });
-
- HttpResponse r;
CURL* curl = curl_easy_init();
if (!curl) {
r.error = "curl_easy_init failed";
@@ -181,7 +196,7 @@ HttpResponse httpRequestStream(const std::string& method, const std::string& url
} else {
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
}
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, net::offlineMode() ? 0L : 1L); // studio mode: no redirects off its list
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 5L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &sink);
@@ -198,10 +213,11 @@ HttpResponse httpRequestStream(const std::string& method, const std::string& url
#else
-HttpResponse httpRequestStream(const std::string&, const std::string&, const std::vector<std::string>&, const std::string&, int,
+HttpResponse httpRequestStream(const std::string&, const std::string& url, const std::vector<std::string>&, const std::string&, int,
const std::function<bool(const char*, size_t)>&) {
- ++gRequests;
HttpResponse r;
+ if (refused(url, r)) return r;
+ ++gRequests;
r.error = "This build of SculptForge has no HTTP support (libcurl was not found at build time)";
return r;
}
diff --git a/src/core/NetworkPolicy.cpp b/src/core/NetworkPolicy.cpp
new file mode 100644
index 00000000..f610370d
--- /dev/null
+++ b/src/core/NetworkPolicy.cpp
@@ -0,0 +1,118 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "core/NetworkPolicy.h"
+
+#include <algorithm>
+#include <atomic>
+#include <cctype>
+#include <memory>
+#include <mutex>
+
+namespace sf::net {
+
+namespace {
+
+std::mutex gMutex;
+std::shared_ptr<const NetworkPolicy> gPolicy = std::make_shared<NetworkPolicy>();
+std::atomic<bool> gOffline{false};
+std::atomic<uint64_t> gBlocked{0};
+
+std::shared_ptr<const NetworkPolicy> current() {
+ std::lock_guard<std::mutex> lock(gMutex);
+ return gPolicy;
+}
+
+std::string lower(std::string s) {
+ for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));
+ return s;
+}
+
+bool refuse(std::string* why, const std::string& text) {
+ ++gBlocked;
+ if (why) *why = text;
+ return false;
+}
+
+} // namespace
+
+void setNetworkPolicy(const NetworkPolicy& policy) {
+ auto p = std::make_shared<const NetworkPolicy>(policy);
+ std::lock_guard<std::mutex> lock(gMutex);
+ gPolicy = std::move(p);
+ gOffline = policy.offline;
+}
+
+NetworkPolicy networkPolicy() { return *current(); }
+bool offlineMode() { return gOffline; }
+
+bool parseUrl(const std::string& url, UrlParts& out) {
+ const size_t sep = url.find("://");
+ if (sep == std::string::npos || sep == 0) return false;
+ out.scheme = lower(url.substr(0, sep));
+ if (out.scheme != "http" && out.scheme != "https") return false;
+ const size_t start = sep + 3;
+ size_t end = url.find_first_of("/?#", start);
+ if (end == std::string::npos) end = url.size();
+ const std::string authority = url.substr(start, end - start);
+ // No user info (a "[email protected]" trick), no IPv6 literals, no backslashes or spaces anywhere.
+ if (authority.empty() || authority.find_first_of("@[]\\ ") != std::string::npos) return false;
+ if (url.find_first_of("\\ \t\r\n") != std::string::npos) return false;
+ const size_t colon = authority.find(':');
+ out.host = lower(authority.substr(0, colon));
+ if (out.host.empty()) return false;
+ out.port = out.scheme == "https" ? 443 : 80;
+ if (colon != std::string::npos) {
+ const std::string port = authority.substr(colon + 1);
+ if (port.empty() || port.size() > 5 || !std::all_of(port.begin(), port.end(), [](char c) { return c >= '0' && c <= '9'; }))
+ return false;
+ out.port = std::stoi(port);
+ if (out.port < 1 || out.port > 65535) return false;
+ }
+ out.path = end < url.size() ? url.substr(end) : "/";
+ if (out.path[0] != '/') out.path = "/" + out.path; // "?q" or "#f" straight after the host
+ return true;
+}
+
+bool urlUnderPrefix(const std::string& url, const std::string& prefix) {
+ UrlParts u, p;
+ if (!parseUrl(url, u) || !parseUrl(prefix, p)) return false;
+ if (u.scheme != p.scheme || u.host != p.host || u.port != p.port) return false;
+ if (u.path.find("..") != std::string::npos || u.path.find('%') != std::string::npos) return false; // no escapes out
+ if (p.path == "/") return true;
+ if (u.path.rfind(p.path, 0) != 0) return false;
+ if (p.path.back() == '/' || u.path.size() == p.path.size()) return true;
+ const char next = u.path[p.path.size()];
+ return next == '/' || next == '?' || next == '#';
+}
+
+bool urlAllowed(const std::string& url, std::string* why) {
+ if (!gOffline) return true;
+ const auto p = current();
+ for (const std::string& prefix : p->allow)
+ if (urlUnderPrefix(url, prefix)) return true;
+ UrlParts u;
+ const std::string host = parseUrl(url, u) ? u.host : url;
+ return refuse(why, "Studio mode: no outside connections (" + host + " is not on this studio's list)");
+}
+
+bool isLoopbackAddress(const std::string& address) {
+ const std::string a = lower(address);
+ return a == "localhost" || a == "::1" || a.rfind("127.", 0) == 0;
+}
+
+bool socketAllowed(const std::string& address, std::string* why) {
+ if (!gOffline || isLoopbackAddress(address) || current()->localNetwork) return true;
+ return refuse(why, "Studio mode: no network connections (" + address + ")");
+}
+
+bool multicastAllowed(std::string* why) {
+ if (!gOffline || current()->localNetwork) return true;
+ return refuse(why, "Studio mode: no local network discovery");
+}
+
+bool localIpcAllowed() { return !gOffline; }
+
+uint64_t blockedCount() { return gBlocked; }
+void resetBlockedCount() { gBlocked = 0; }
+
+} // namespace sf::net
diff --git a/src/core/NetworkPolicy.h b/src/core/NetworkPolicy.h
new file mode 100644
index 00000000..eb4107a2
--- /dev/null
+++ b/src/core/NetworkPolicy.h
@@ -0,0 +1,57 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Studio mode's network gate (a studio build, a studio profile or --offline; core/StudioProfile.h). Off (the
+// default) changes nothing. On, the process opens no outside connection:
+// - HTTP (ai/Http.cpp, every request the app, CLI, MCP and Python make) goes only to the URLs the profile allows
+// (its update channel or mirror, and anything it lists), never follows a redirect, and is refused before
+// anything is sent otherwise;
+// - sockets (link/Socket.cpp) open only on loopback unless the profile allows the local network (Unreal link,
+// phone capture);
+// - Discord presence, the community brush gallery and the AI features are off (they are refused here too).
+// There is no telemetry in SculptForge to turn off.
+#pragma once
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace sf::net {
+
+struct NetworkPolicy {
+ bool offline = false; // studio mode: everything below applies
+ std::vector<std::string> allow; // URL prefixes ("https://mirror.studio.internal/sculptforge/")
+ bool localNetwork = false; // sockets beyond loopback (LAN bridges, phone capture)
+};
+
+// Set once at start-up (before any worker thread runs); reads are lock-free after that.
+void setNetworkPolicy(const NetworkPolicy& policy);
+NetworkPolicy networkPolicy();
+bool offlineMode();
+
+// "https://Host:443/a/b?q" -> scheme "https", host "host", port 443, path "/a/b?q". False for anything else
+// (no scheme, user info, empty host, a bad port).
+struct UrlParts {
+ std::string scheme, host, path;
+ int port = 0;
+};
+bool parseUrl(const std::string& url, UrlParts& out);
+// True when URL starts with PREFIX in the sense of a channel: same scheme, host (any case) and port, and the path
+// begins with the prefix's path at a '/' boundary ("https://a/x/" allows "https://a/x/y", not "https://a/xy").
+bool urlUnderPrefix(const std::string& url, const std::string& prefix);
+
+// May the process request URL? Always true when not offline. Refusals count (blockedCount) and say why.
+bool urlAllowed(const std::string& url, std::string* why = nullptr);
+// May a socket connect to (or listen on) ADDRESS (a numeric IPv4 address or "localhost")?
+bool socketAllowed(const std::string& address, std::string* why = nullptr);
+// Multicast (Unreal discovery) is always the local network.
+bool multicastAllowed(std::string* why = nullptr);
+// Local IPC to another app (Discord): never in studio mode.
+bool localIpcAllowed();
+
+uint64_t blockedCount();
+void resetBlockedCount();
+
+bool isLoopbackAddress(const std::string& address);
+
+} // namespace sf::net
diff --git a/src/core/StudioProfile.cpp b/src/core/StudioProfile.cpp
new file mode 100644
index 00000000..7002e3cc
--- /dev/null
+++ b/src/core/StudioProfile.cpp
@@ -0,0 +1,196 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "core/StudioProfile.h"
+
+#include "core/Json.h"
+#include "core/UpdateCheck.h"
+
+#include <cstdlib>
+#include <filesystem>
+#include <fstream>
+#include <iterator>
+
+namespace sf {
+
+namespace fs = std::filesystem;
+
+namespace {
+
+bool idOk(const std::string& id) {
+ if (id.empty() || id.size() > 64) return false;
+ for (char c : id)
+ if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_')) return false;
+ return true;
+}
+
+bool isUrl(const std::string& s) { return s.rfind("https://", 0) == 0 || s.rfind("http://", 0) == 0; }
+
+// A relative path inside DIR (no absolute path, no "..").
+bool relativeOk(const std::string& p) {
+ if (p.empty() || p[0] == '/' || p[0] == '\\' || p.find(':') != std::string::npos) return false;
+ for (const auto& part : fs::path(p)) if (part == "..") return false;
+ return true;
+}
+
+std::string resolve(const std::string& dir, const std::string& p) {
+ return dir.empty() ? p : (fs::path(dir) / p).lexically_normal().generic_string();
+}
+
+StudioStart gStudio;
+
+} // namespace
+
+bool parseStudioProfile(const std::string& text, const std::string& dir, StudioProfile& out, std::string& error) {
+ Json j;
+ if (!Json::parseStrict(text, j, error)) return false;
+ if (!j.isObject()) return (error = "a studio profile is a JSON object", false);
+ static const char* kKeys[] = {"format", "version", "id", "name", "offline", "updates", "allow", "localNetwork",
+ "ai", "packs", "brushPaths", "preferences", "branding"};
+ for (const auto& [k, v] : j.members()) {
+ bool known = false;
+ for (const char* key : kKeys) known = known || k == key;
+ if (!known) return (error = "unknown key \"" + k + "\"", false);
+ }
+ if (j["format"].asString() != kStudioProfileFormat) return (error = "format must be \"sculptforge-studio\"", false);
+ if (int(j["version"].asNumber()) != kStudioProfileVersion) return (error = "unsupported version", false);
+ StudioProfile p;
+ p.dir = dir;
+ p.id = j["id"].asString();
+ p.name = j["name"].asString();
+ if (!idOk(p.id)) return (error = "id: lower-case letters, digits, '-' and '_'", false);
+ if (p.name.empty() || p.name.size() > 80) return (error = "name: 1 to 80 characters", false);
+ p.offline = j["offline"].asBool(true);
+ p.ai = j["ai"].asBool(false);
+ p.localNetwork = j["localNetwork"].asBool(false);
+ auto location = [&](const std::string& s, std::string& to, const char* what) {
+ if (s.empty()) return true;
+ net::UrlParts u;
+ if (isUrl(s)) {
+ if (!net::parseUrl(s, u)) return (error = std::string(what) + ": not a plain http(s) URL", false);
+ to = s;
+ } else {
+ to = fs::path(s).is_absolute() ? s : resolve(dir, s);
+ }
+ return true;
+ };
+ if (!location(j["updates"]["feed"].asString(), p.updateFeed, "updates.feed") ||
+ !location(j["updates"]["mirror"].asString(), p.updateMirror, "updates.mirror"))
+ return false;
+ for (const Json& a : j["allow"].items()) {
+ net::UrlParts u;
+ if (!net::parseUrl(a.asString(), u)) return (error = "allow: \"" + a.asString() + "\" is not an http(s) URL", false);
+ p.allow.push_back(a.asString());
+ }
+ for (const Json& a : j["packs"].items()) {
+ if (!relativeOk(a.asString())) return (error = "packs: paths stay inside the profile's folder", false);
+ p.packs.push_back(resolve(dir, a.asString()));
+ }
+ for (const Json& a : j["brushPaths"].items()) {
+ if (a.asString().empty()) return (error = "brushPaths: empty path", false);
+ p.brushPaths.push_back(a.asString());
+ }
+ if (const std::string& pr = j["preferences"].asString(); !pr.empty()) {
+ if (!relativeOk(pr)) return (error = "preferences: paths stay inside the profile's folder", false);
+ p.preferences = resolve(dir, pr);
+ }
+ if (const std::string& logo = j["branding"]["logo"].asString(); !logo.empty()) {
+ if (!relativeOk(logo)) return (error = "branding.logo: paths stay inside the profile's folder", false);
+ p.logo = resolve(dir, logo);
+ }
+ p.title = j["branding"]["title"].asString();
+ out = std::move(p);
+ return true;
+}
+
+bool loadStudioProfile(const std::string& path, StudioProfile& out, std::string& error) {
+ std::ifstream f(fs::u8path(path), std::ios::binary);
+ if (!f) return (error = "can't read " + path, false);
+ const std::string text{std::istreambuf_iterator<char>(f), {}};
+ if (!parseStudioProfile(text, fs::u8path(path).parent_path().generic_string(), out, error)) return false;
+ out.source = path;
+ return true;
+}
+
+net::NetworkPolicy studioNetworkPolicy(const StudioProfile& p) {
+ net::NetworkPolicy n;
+ n.offline = p.offline || isStudioBuild();
+ n.localNetwork = p.localNetwork;
+ for (const std::string* u : {&p.updateFeed, &p.updateMirror})
+ if (isUrl(*u)) n.allow.push_back(*u);
+ n.allow.insert(n.allow.end(), p.allow.begin(), p.allow.end());
+ return n;
+}
+
+bool isStudioBuild() { return *builtInStudioProfile() != '\0'; }
+
+std::string findInstalledStudioDir(const std::string& exeDir) {
+ if (exeDir.empty()) return {};
+ std::error_code ec;
+ fs::path dir = fs::u8path(exeDir);
+ for (int up = 0; up < 4; ++up) {
+ for (const char* sub : {"studio", "share/sculptforge/studio", "Resources/studio"})
+ if (fs::is_regular_file(dir / sub / "studio.json", ec)) return (dir / sub).lexically_normal().generic_string();
+ if (!dir.has_parent_path() || dir.parent_path() == dir) break;
+ dir = dir.parent_path();
+ }
+ return {};
+}
+
+StudioStart startStudioMode(const std::string& exeDir, const std::string& overridePath, bool forceOffline) {
+ StudioStart s;
+ std::string error;
+ const char* envPath = std::getenv("SF_STUDIO_PROFILE");
+ const char* envOffline = std::getenv("SF_OFFLINE");
+ const std::string installed = findInstalledStudioDir(exeDir);
+ bool found = false;
+ if (const std::string p = !overridePath.empty() ? overridePath : (envPath ? envPath : ""); !p.empty()) {
+ found = loadStudioProfile(p, s.profile, error);
+ if (!found) s.messages.push_back("Studio profile " + p + ": " + error);
+ } else if (isStudioBuild()) {
+ found = parseStudioProfile(builtInStudioProfile(), installed, s.profile, error);
+ if (found) s.profile.source = "built in";
+ else s.messages.push_back("Built-in studio profile: " + error);
+ } else if (!installed.empty()) {
+ found = loadStudioProfile(installed + "/studio.json", s.profile, error);
+ if (!found) s.messages.push_back("Studio profile " + installed + "/studio.json: " + error);
+ }
+ net::NetworkPolicy policy;
+ if (found) policy = studioNetworkPolicy(s.profile);
+ // Fail closed: a studio build, --offline or SF_OFFLINE=1 is offline even without a usable profile.
+ if (isStudioBuild() || forceOffline || (envOffline && std::string(envOffline) == "1")) policy.offline = true;
+ s.active = policy.offline;
+ net::setNetworkPolicy(policy);
+ if (found && !s.profile.brushPaths.empty()) { // read-only shares, ahead of any already set
+ std::string value;
+#if defined(_WIN32)
+ const char sep = ';';
+#else
+ const char sep = ':';
+#endif
+ for (const std::string& d : s.profile.brushPaths) value += (value.empty() ? "" : std::string(1, sep)) + d;
+ if (const char* old = std::getenv("SCULPTFORGE_BRUSH_PATH"); old && *old) value += sep + std::string(old);
+#if defined(_WIN32)
+ _putenv_s("SCULPTFORGE_BRUSH_PATH", value.c_str());
+#else
+ setenv("SCULPTFORGE_BRUSH_PATH", value.c_str(), 1);
+#endif
+ }
+ gStudio = s;
+ return s;
+}
+
+const StudioStart& studioMode() { return gStudio; }
+
+std::string updateFeedSource(const StudioStart& s, const char* envFeed, std::string& fallback) {
+ fallback.clear();
+ if (s.active) { // only the studio's own channel, then its mirror
+ if (s.profile.updateFeed.empty()) return s.profile.updateMirror;
+ fallback = s.profile.updateMirror;
+ return s.profile.updateFeed;
+ }
+ if (envFeed && *envFeed) return envFeed;
+ fallback = kUpdateFeedMirrorUrl;
+ return kUpdateFeedUrl;
+}
+
+} // namespace sf
diff --git a/src/core/StudioProfile.h b/src/core/StudioProfile.h
new file mode 100644
index 00000000..4b9a7230
--- /dev/null
+++ b/src/core/StudioProfile.h
@@ -0,0 +1,87 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// A studio profile (studio.json, docs/studios.md "Your studio build"): what a custom studio build bakes in and how
+// it reaches the network. Release tooling (tools/studio/bake_profile.py, -DSCULPTFORGE_STUDIO_PROFILE=...) checks
+// the profile, compiles it into the binaries and installs its folder (packs, preferences, logo) next to the
+// assets. A studio build is in studio mode whatever happens to the files: offline, with only its own update
+// channel or mirror allowed (core/NetworkPolicy.h).
+//
+// Where the profile comes from, first found wins:
+// 1. --studio FILE (app and CLI) or SF_STUDIO_PROFILE=FILE (IT testing a profile on a public build);
+// 2. the profile compiled into a studio build;
+// 3. studio/studio.json next to the installed assets (share/sculptforge/studio, Resources/studio);
+// and --offline (or SF_OFFLINE=1) turns studio mode on with nothing allowed when no profile is found.
+//
+// {
+// "format": "sculptforge-studio", "version": 1,
+// "id": "acme", "name": "Acme Animation",
+// "offline": true, // always true in a studio build
+// "updates": {"feed": "https://sw.acme.internal/sculptforge/latest.json", "mirror": "/mnt/sw/sculptforge/latest.json"},
+// "allow": ["https://comfy.acme.internal/"], // more URL prefixes, if the studio wants them
+// "localNetwork": false, // Unreal link and phone capture on the studio LAN
+// "ai": false, // AI features (they may reach only allowed URLs)
+// "packs": ["packs/acme.sfpack"], // brushes, alphas, Lit Spheres, keymaps, macros (core/Pack.h)
+// "brushPaths": ["/studio/brushes"], // read-only brush shares (as SCULPTFORGE_BRUSH_PATH)
+// "preferences": "ui.json", // the first-start interface settings (layout, keys, scale)
+// "branding": {"logo": "logo.png", "title": "Acme"}
+// }
+// Paths are relative to the profile's folder. The profile is data: nothing in it runs.
+#pragma once
+
+#include "core/NetworkPolicy.h"
+
+#include <string>
+#include <vector>
+
+namespace sf {
+
+constexpr const char* kStudioProfileFormat = "sculptforge-studio";
+constexpr int kStudioProfileVersion = 1;
+
+struct StudioProfile {
+ std::string id, name;
+ std::string dir; // the folder relative paths resolve against ("" for a compiled-in profile: the installed one)
+ std::string source; // where it came from, for messages ("--studio /x/studio.json", "built in", ...)
+ bool offline = true;
+ bool ai = false;
+ bool localNetwork = false;
+ std::string updateFeed, updateMirror; // a URL (http/https) or a local file
+ std::vector<std::string> allow;
+ std::vector<std::string> packs, brushPaths; // resolved (absolute when dir is set)
+ std::string preferences;
+ std::string logo, title;
+};
+
+// Reads and checks a profile: format, id (lower-case letters, digits, '-', '_'), name, URLs (http/https only, no user
+// info), and no path that climbs out of DIR. Unknown keys are errors, so a typo never quietly drops a setting.
+bool parseStudioProfile(const std::string& text, const std::string& dir, StudioProfile& out, std::string& error);
+bool loadStudioProfile(const std::string& path, StudioProfile& out, std::string& error);
+
+// What the profile allows: offline, the update channel and mirror (when they are URLs) plus its allow list.
+net::NetworkPolicy studioNetworkPolicy(const StudioProfile& p);
+
+// The profile compiled into this build ("" in public builds; core/StudioBuild.cpp, generated by CMake).
+const char* builtInStudioProfile();
+bool isStudioBuild();
+
+struct StudioStart {
+ bool active = false; // studio mode is on
+ StudioProfile profile; // when one was found
+ std::vector<std::string> messages; // what to log (a broken profile, a pack that didn't install)
+};
+
+// Finds the profile (see the order above), applies the network policy and the brush shares, and returns it. A studio
+// build whose profile is missing or broken still starts offline, with nothing allowed (it fails closed).
+// EXE_DIR is where the binary is (for the installed studio folder); OVERRIDE_PATH is --studio's file.
+StudioStart startStudioMode(const std::string& exeDir, const std::string& overridePath, bool forceOffline);
+// The studio folder next to the installed assets, or "".
+std::string findInstalledStudioDir(const std::string& exeDir);
+// The process's studio state (what startStudioMode found).
+const StudioStart& studioMode();
+
+// The update feed to read: the profile's channel in studio mode ("" = no automatic check, nothing to ask), otherwise
+// SF_UPDATE_FEED or the public feed. FALLBACK gets the mirror to try when the first answer isn't 200.
+std::string updateFeedSource(const StudioStart& s, const char* envFeed, std::string& fallback);
+
+} // namespace sf