Round 2 of the REST profile-scope pass. A call-graph audit (AST over every router plus their imported helpers, following functools.partial bindings, closures and callbacks handed to to_thread/_spawn_job) found the writes a signature grep cannot see, and the SPA/Desktop callers that never named a profile at all. Handlers that reached a config write through indirection: * PUT /api/dashboard/plugin-providers wrote memory.provider + context.engine through functools.partial(_write_config_value, ...) — the SAME key PUT /api/memory/provider scopes — into the launch profile's config.yaml. * POST /api/local-models/quickstart is `activate` plus a download; only `activate` had been scoped, so _set_runtime_enabled/_assign_default landed in the launch profile. * POST /api/local-models/runtime/install regenerates launch presets under get_hermes_home(). * GET /api/model/recommended-default lazily PERSISTS discovered custom-provider models via build_models_payload -> _save_discovered_models_to_config. Policy gaps: * POST /api/ops/hooks is now gated like DELETE: writing an arbitrary command into `hooks:` and, with approve, into the consent allowlist is strictly more privileged than removing one. * POST /api/sessions/prune (non-dry-run), DELETE /api/sessions/empty and POST /api/sessions/bulk-delete join the same destructive class. * PUT /api/memory/provider ran its readiness check OUTSIDE the scope, so it judged the launch profile and could write a broken setting into another. Callers: * /api/credentials was missing from the SPA's PROFILE_SCOPED_PREFIXES, so the credential-pool delete button 400'd unconditionally; so were /api/dashboard/plugin-providers, /api/local-models and the model route above. * The management scope was empty until the switcher resolved, so every destructive route 400'd in working UI on any host with a second profile directory. The backend now injects the profile it itself serves (__HERMES_DASHBOARD_PROFILE__) — and only when that name provably resolves back to its own home, so the fallback can never retarget another profile. * authedFetch went around the scope entirely; the Desktop /api/ops callers (doctor, security-audit, backup, debug-share) sent no profile while Electron pins that family to the shared primary backend.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
declare global {
|
|
interface Window {
|
|
__HERMES_DASHBOARD_PROFILE__?: string;
|
|
__HERMES_INITIAL_PROFILE__?: string;
|
|
}
|
|
}
|
|
|
|
export function dashboardInitialProfile(): string {
|
|
if (typeof window === "undefined") return "";
|
|
return window.__HERMES_INITIAL_PROFILE__ ?? "";
|
|
}
|
|
|
|
/**
|
|
* The profile this backend process itself serves, injected by the server and
|
|
* empty when it cannot be named unambiguously (custom HERMES_HOME).
|
|
*
|
|
* It is the LAST fallback for the management scope: without it the dashboard
|
|
* sends no `?profile=` at all, which a multi-profile host now refuses (400) on
|
|
* every destructive route. It is never a guess — the backend only emits a name
|
|
* that provably resolves back to its own home, so it targets exactly the home
|
|
* an unnamed request used to reach.
|
|
*/
|
|
export function dashboardServingProfile(): string {
|
|
if (typeof window === "undefined") return "";
|
|
return window.__HERMES_DASHBOARD_PROFILE__ ?? "";
|
|
}
|
|
|
|
export function initialProfileScope(
|
|
searchParams: URLSearchParams,
|
|
bootstrapProfile = dashboardInitialProfile(),
|
|
servingProfile = dashboardServingProfile(),
|
|
): string {
|
|
const urlProfile = searchParams.get("profile");
|
|
if (urlProfile !== null) return urlProfile;
|
|
return bootstrapProfile || servingProfile;
|
|
}
|
|
|
|
export function shouldAdoptActiveProfile(
|
|
urlProfile: string | null,
|
|
bootstrapProfile: string,
|
|
currentProfile: string,
|
|
activeProfile: string,
|
|
): boolean {
|
|
return (
|
|
urlProfile === null &&
|
|
!bootstrapProfile &&
|
|
activeProfile !== currentProfile
|
|
);
|
|
}
|