mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-16 10:52:27 +03:00
360f48814c
61 call sites counted directories up from their own __file__ to find the install folder. They now call hermes_cli._startup_fast.project_root_str(), so the layout move changes one line instead of 61. Kept with a reason in the lint baseline: files that cannot import Hermes code (bootstrap, update path, pm/) and the sys.path bootstraps left for part 2b. The baseline drops from 89 to 28 root_from_file sites. Six existing tests that patched a module __file__ now patch the owner.
41 lines
2.1 KiB
Python
41 lines
2.1 KiB
Python
"""Static asset lookups the SPA catch-all must not answer with ``index.html``.
|
|
|
|
The sign-in page (``dashboard_auth/login_page.py``) loads its brand fonts from ``/fonts/``. Those
|
|
files ship in the dashboard's ``web/public`` tree, which the dashboard build copies into its own
|
|
dist, but the Webapp serves ``apps/desktop/dist-webapp`` and has no ``fonts/`` dir. A font missing
|
|
from the served dist is read from the packaged dashboard dist (``HERMES_WEB_DIST`` / ``web_dist``,
|
|
which is all a Nix or wheel install ships, since those exclude ``web/``), then from a source
|
|
checkout's ``web/public``.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from hermes_cli._startup_fast import project_root_str
|
|
|
|
# Requests under these prefixes are files, never client-side routes, so a miss is a 404 rather
|
|
# than the SPA shell (a font answered with HTML renders in a fallback face, silently).
|
|
STATIC_ASSET_PREFIXES: tuple[str, ...] = ("assets/", "ds-assets/", "fonts/", "fonts-terminal/")
|
|
# Root page icons answer without sign-in, so a missing (or out-of-dist) icon must be a 404, not
|
|
# the SPA shell served anonymously.
|
|
STATIC_ASSET_FILES: frozenset[str] = frozenset({"apple-touch-icon.png", "favicon.ico"})
|
|
_PUBLIC_FONT_DIRS: tuple[str, ...] = ("fonts", "fonts-terminal")
|
|
_WEB_PUBLIC = Path(project_root_str()) / "web" / "public"
|
|
|
|
|
|
def is_static_asset_path(full_path: str) -> bool:
|
|
return full_path in STATIC_ASSET_FILES or full_path.startswith(STATIC_ASSET_PREFIXES)
|
|
|
|
|
|
def public_font_file(dist: Path, dashboard_dist: Path, full_path: str) -> Path | None:
|
|
"""The served dist's copy of ``fonts/<name>`` (or ``fonts-terminal/<name>``), else the packaged
|
|
dashboard dist's, else the ``web/public`` copy the dashboard build takes it from; ``None`` when
|
|
none has it."""
|
|
folder, _, name = full_path.partition("/")
|
|
if folder not in _PUBLIC_FONT_DIRS or not name:
|
|
return None
|
|
for root in (dist / folder, dashboard_dist / folder, _WEB_PUBLIC / folder):
|
|
candidate = root / name
|
|
if candidate.is_file() and candidate.resolve().is_relative_to(root.resolve()):
|
|
return candidate
|
|
return None
|