mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-13 08:03:04 +08:00
fix: port continuous-learning observer fixes
Ports continuous-learning observer signal, storage, remote normalization, and v1 deprecation fixes onto current main.
This commit is contained in:
@@ -38,7 +38,48 @@ except ImportError:
|
||||
# Configuration
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
HOMUNCULUS_DIR = Path.home() / ".claude" / "homunculus"
|
||||
def _resolve_homunculus_dir() -> Path:
|
||||
override = os.environ.get("CLV2_HOMUNCULUS_DIR")
|
||||
if override:
|
||||
if Path(override).is_absolute():
|
||||
return Path(override)
|
||||
print(f"[ecc] CLV2_HOMUNCULUS_DIR={override!r} is not absolute; ignoring", file=sys.stderr)
|
||||
|
||||
xdg = os.environ.get("XDG_DATA_HOME")
|
||||
if xdg:
|
||||
if Path(xdg).is_absolute():
|
||||
return Path(xdg) / "ecc-homunculus"
|
||||
print(f"[ecc] XDG_DATA_HOME={xdg!r} is not absolute; ignoring", file=sys.stderr)
|
||||
|
||||
return Path.home() / ".local" / "share" / "ecc-homunculus"
|
||||
|
||||
|
||||
def _strip_remote_credentials(remote_url: str) -> str:
|
||||
return re.sub(r"://[^@]+@", "://", remote_url or "")
|
||||
|
||||
|
||||
def _normalize_remote_url(remote_url: str) -> str:
|
||||
if not remote_url:
|
||||
return ""
|
||||
|
||||
is_network = (
|
||||
not remote_url.startswith("file://")
|
||||
and ("://" in remote_url or re.match(r"^[^@/:]+@[^:/]+:", remote_url) is not None)
|
||||
)
|
||||
normalized = _strip_remote_credentials(remote_url)
|
||||
normalized = re.sub(r"^[A-Za-z][A-Za-z0-9+.-]*://", "", normalized)
|
||||
normalized = re.sub(r"^[^@/:]+@([^:/]+):", r"\1/", normalized)
|
||||
normalized = re.sub(r"\.git/?$", "", normalized)
|
||||
normalized = re.sub(r"/+$", "", normalized)
|
||||
|
||||
return normalized.lower() if is_network else normalized
|
||||
|
||||
|
||||
def _project_hash(value: str) -> str:
|
||||
return hashlib.sha256(value.encode("utf-8")).hexdigest()[:12]
|
||||
|
||||
|
||||
HOMUNCULUS_DIR = _resolve_homunculus_dir()
|
||||
PROJECTS_DIR = HOMUNCULUS_DIR / "projects"
|
||||
REGISTRY_FILE = HOMUNCULUS_DIR / "projects.json"
|
||||
|
||||
@@ -177,11 +218,35 @@ def detect_project() -> dict:
|
||||
except (subprocess.TimeoutExpired, FileNotFoundError):
|
||||
pass
|
||||
|
||||
hash_source = remote_url if remote_url else project_root
|
||||
project_id = hashlib.sha256(hash_source.encode()).hexdigest()[:12]
|
||||
raw_remote_url = remote_url
|
||||
if remote_url:
|
||||
remote_url = _strip_remote_credentials(remote_url)
|
||||
|
||||
legacy_hash_source = remote_url if remote_url else project_root
|
||||
normalized_remote = _normalize_remote_url(remote_url) if remote_url else ""
|
||||
hash_source = normalized_remote if normalized_remote else legacy_hash_source
|
||||
project_id = _project_hash(hash_source)
|
||||
|
||||
project_dir = PROJECTS_DIR / project_id
|
||||
|
||||
if not project_dir.exists():
|
||||
legacy_sources = []
|
||||
if legacy_hash_source and legacy_hash_source != hash_source:
|
||||
legacy_sources.append(legacy_hash_source)
|
||||
if raw_remote_url and raw_remote_url not in {hash_source, legacy_hash_source}:
|
||||
legacy_sources.append(raw_remote_url)
|
||||
|
||||
for legacy_source in legacy_sources:
|
||||
legacy_id = _project_hash(legacy_source)
|
||||
legacy_dir = PROJECTS_DIR / legacy_id
|
||||
if legacy_id != project_id and legacy_dir.exists():
|
||||
try:
|
||||
legacy_dir.rename(project_dir)
|
||||
except OSError:
|
||||
project_id = legacy_id
|
||||
project_dir = legacy_dir
|
||||
break
|
||||
|
||||
# Ensure project directory structure
|
||||
for d in [
|
||||
project_dir / "instincts" / "personal",
|
||||
|
||||
Reference in New Issue
Block a user