Files
loki/scripts/sync-agent-runtime-config.py
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00

111 lines
3.5 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import shutil
import tempfile
import urllib.error
import urllib.request
from pathlib import Path
def sync_file(target: Path, legacy: Path) -> None:
if not legacy.exists():
return
if target.exists() and target.stat().st_mtime >= legacy.stat().st_mtime:
return
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(legacy, target)
def read_env_file(path: Path) -> dict[str, str]:
values: dict[str, str] = {}
if not path.exists():
return values
for raw in path.read_text(encoding="utf-8").splitlines():
line = raw.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
values[key.strip()] = value.strip().strip('"').strip("'")
return values
def clean_field(value: object) -> str:
return str(value or "").replace("|", "-").replace("\n", " ").strip()
def sync_projects_from_cloud(target: Path, env: dict[str, str]) -> bool:
base_url = (
os.environ.get("APP_BASE_URL")
or os.environ.get("LOKI_BASE_URL")
or os.environ.get("COCKPIT_BASE_URL")
or env.get("APP_BASE_URL")
or env.get("LOKI_BASE_URL")
or env.get("COCKPIT_BASE_URL")
or ""
).rstrip("/")
token = (
os.environ.get("APP_DAEMON_TOKEN")
or os.environ.get("LOKI_DAEMON_TOKEN")
or os.environ.get("COCKPIT_DAEMON_TOKEN")
or env.get("APP_DAEMON_TOKEN")
or env.get("LOKI_DAEMON_TOKEN")
or env.get("COCKPIT_DAEMON_TOKEN")
or ""
)
if not base_url or not token:
return False
req = urllib.request.Request(
f"{base_url}/api/agent/projects",
headers={"Authorization": f"Bearer {token}", "Accept": "application/json"},
)
try:
with urllib.request.urlopen(req, timeout=8) as res:
import json
payload = json.loads(res.read().decode("utf-8"))
except (OSError, urllib.error.URLError, ValueError):
return False
projects = payload.get("projects")
if not isinstance(projects, list):
return False
lines = [
"# Managed by Loki. Edit projects in the web Control page; the daemon syncs this file.",
"# Format: tab_name|/absolute/path/to/project|agent|model",
]
for project in projects:
if not isinstance(project, dict):
continue
name = clean_field(project.get("name"))
dir_path = clean_field(project.get("dirPath"))
agent = clean_field(project.get("agent"))
model = clean_field(project.get("model"))
if name and dir_path:
lines.append(f"{name}|{dir_path}|{agent}|{model}")
target.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=str(target.parent), delete=False) as tmp:
tmp.write("\n".join(lines) + "\n")
tmp_name = tmp.name
os.replace(tmp_name, target)
return True
def main() -> int:
home = Path(os.path.expanduser("~"))
config = home / ".config"
loki_env = read_env_file(config / "loki" / "daemon.env")
cockpit_env = read_env_file(config / "cockpit" / "daemon.env")
env = {**cockpit_env, **loki_env}
if not sync_projects_from_cloud(config / "agent-projects.conf", env):
sync_file(config / "agent-projects.conf", config / "claude-projects.conf")
sync_file(config / "agent-prompts.json", config / "claude-prompts.json")
return 0
if __name__ == "__main__":
raise SystemExit(main())