mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
The tree was a debranded snapshot of upstream taken around 2026-02-20, and upstream has moved about five months since. This replaces it with upstream master, mechanically re-derived: bin/debrand does the rename, and the pipeline and squashed migrations are restored from the shipped tree. Not a merge. The previous import replaced the tree wholesale in a single commit, so there is no shared content history to merge against. Reproducing the rename on the new tree is what actually converges. What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md, and insights/migrations. The squashed initial migration is load-bearing — the live database records it by name, so upstream's ~918 individual migrations cannot come back. Nine products are dropped as unreferenced. Twenty-one more that we do not run are kept anyway because the core app still imports them; unpicking those is a refactor and does not belong in a rebase. This base does not build yet, and the reasons are not in the rename: upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against our 4.2, and the dependency manifests still name upstream packages that we republish under our own names. Those are decisions, not renames.
120 lines
3.4 KiB
Python
120 lines
3.4 KiB
Python
"""Local config helpers for insightscli devbox preferences."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import TypedDict
|
|
|
|
|
|
class DevboxConfig(TypedDict, total=False):
|
|
git_name: str
|
|
git_email: str
|
|
dotfiles_uri: str
|
|
region: str
|
|
|
|
|
|
_PERSISTED_FIELDS = ("git_name", "git_email", "dotfiles_uri", "region")
|
|
|
|
|
|
def get_config_path() -> Path:
|
|
"""Return the config path for persisted insightscli devbox preferences."""
|
|
return Path.home() / ".config" / "insights" / "insightscli_devbox.json"
|
|
|
|
|
|
def load_config() -> DevboxConfig:
|
|
"""Load persisted insightscli devbox preferences from disk."""
|
|
try:
|
|
data = json.loads(get_config_path().read_text())
|
|
except Exception:
|
|
return DevboxConfig()
|
|
|
|
if not isinstance(data, dict):
|
|
return DevboxConfig()
|
|
|
|
config = DevboxConfig()
|
|
for key in _PERSISTED_FIELDS:
|
|
value = data.get(key)
|
|
if isinstance(value, str):
|
|
stripped_value = value.strip()
|
|
if stripped_value:
|
|
config[key] = stripped_value
|
|
return config
|
|
|
|
|
|
def save_config(config: DevboxConfig) -> None:
|
|
"""Persist insightscli devbox preferences to disk."""
|
|
normalized = DevboxConfig()
|
|
for key in _PERSISTED_FIELDS:
|
|
value = config.get(key)
|
|
if isinstance(value, str):
|
|
stripped_value = value.strip()
|
|
if stripped_value:
|
|
normalized[key] = stripped_value
|
|
|
|
path = get_config_path()
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(json.dumps(normalized, indent=2) + "\n")
|
|
|
|
|
|
def save_git_identity(git_name: str, git_email: str) -> DevboxConfig:
|
|
"""Persist Git identity defaults for new workspaces."""
|
|
config = load_config()
|
|
config["git_name"] = git_name
|
|
config["git_email"] = git_email
|
|
save_config(config)
|
|
return config
|
|
|
|
|
|
def save_dotfiles_uri(dotfiles_uri: str) -> DevboxConfig:
|
|
"""Persist dotfiles repo URL for new workspaces."""
|
|
config = load_config()
|
|
config["dotfiles_uri"] = dotfiles_uri
|
|
save_config(config)
|
|
return config
|
|
|
|
|
|
def clear_dotfiles_uri(config: DevboxConfig | None = None) -> DevboxConfig:
|
|
"""Remove any saved dotfiles repo URL so new workspaces don't clone one.
|
|
|
|
Pass ``config`` to reuse an already-loaded dict and avoid a redundant disk read.
|
|
"""
|
|
if config is None:
|
|
config = load_config()
|
|
config.pop("dotfiles_uri", None)
|
|
save_config(config)
|
|
return config
|
|
|
|
|
|
def clear_git_identity(config: DevboxConfig | None = None) -> DevboxConfig:
|
|
"""Remove any saved Git identity defaults for new workspaces.
|
|
|
|
Pass ``config`` to reuse an already-loaded dict and avoid a redundant disk read.
|
|
"""
|
|
if config is None:
|
|
config = load_config()
|
|
config.pop("git_name", None)
|
|
config.pop("git_email", None)
|
|
save_config(config)
|
|
return config
|
|
|
|
|
|
def save_region(region: str) -> DevboxConfig:
|
|
"""Persist the preferred region for new workspaces."""
|
|
config = load_config()
|
|
config["region"] = region
|
|
save_config(config)
|
|
return config
|
|
|
|
|
|
def clear_region(config: DevboxConfig | None = None) -> DevboxConfig:
|
|
"""Drop the saved preferred region so new workspaces fall back to the built-in default.
|
|
|
|
Pass ``config`` to reuse an already-loaded dict and avoid a redundant disk read.
|
|
"""
|
|
if config is None:
|
|
config = load_config()
|
|
config.pop("region", None)
|
|
save_config(config)
|
|
return config
|