forked from enderofwings/NexusOS
Merge origin/main (v1.2.0: Projects, modules, in-app updates)
Reconciles 17 commits of this session's work (self-alteration tools, vendored Curry, slash-command dispatch, Windows toolchain/gate fixes) against origin/main's v1.2.0 sync (Projects/RAG scoping, a new modules/ system for mail and network, in-app updates, the standalone memory microservice folded into an in-process curator, KDE desktop theme overhaul). Nine real conflicts, each resolved by hand after reading both sides' actual diffs rather than picking one side wholesale: - synapse/tools.py, tests/test_tools.py: origin/main's diff here was small and clean (read_file/list_files, two new tests) despite git's diff3 flagging the whole file as one conflict blob -- reset to this branch's version and hand-spliced their addition in at the same points they used, rather than trying to reconcile a false 800-line conflict. Found and fixed a real bug while verifying: _list_files returned backslash-separated paths on Windows, which don't match the forward-slash glob patterns the tool's own schema documents. - synapse/main.py: kept this branch's cue-based standing advertisement of render_preview/run_snippet (independent of any playbook granting them) AND adopted origin/main's fix for routed reference playbooks not bringing their own tools along -- dropping either would have been a real regression, not just a style difference. Also: the standalone memory service (port 8001) is gone upstream, so its dead CORS/kill- target entries were removed; NEXUS_BACKEND_PORT parameterization and the manage_ollama-conditional kill logic (this branch's remote-Ollama support) were kept over origin/main's hardcoded equivalents. - synapse/memory/store.py: kept this branch's _delete_message_vectors helper (already reused elsewhere, batches to stay under SQLite's variable limit) over origin/main's inline duplicate of the same fix. - synapse/nexus_config.py, nexusos_cli/ncp.py: dropped the now-dead memory-service port/service entries; kept NEXUS_BACKEND_PORT env override and the manage_ollama-conditional kill-target list. - CLAUDE.md, README.md: merged both sides' additions, no real conflict. Found and fixed three more issues while independently verifying the merged tree, none of them mine or origin/main's alone -- only visible once both sides actually ran together: - modules/ (the new mail+network package) was never added to pyproject.toml's wheel `packages` list OR the sdist's `include` allowlist, so `from modules.registry import ROUTERS` in main.py would ImportError on any wheel install. Fixed both; bin/check.sh's packaging gate now asserts modules/ actually ships. tests/ test_packaging_deps.py's FIRST_PARTY/SHIPPED_PACKAGES sets were updated to recognize the new package. - tests/test_mail_creds.py's 0600-mode assertions are POSIX-only -- NTFS has no equivalent permission bits, so os.open(path, 0o600) on Windows just creates a normal file and stat.S_IMODE reports 0o666 regardless. Made the assertions platform-aware rather than skip real coverage (the temp-file-cleanup and password round-trip checks in the same test still run on Windows) or paper over a genuine OS limitation with a fake pass. - tests/test_kde_theme.py used bare Path.read_text() in fifteen places; Windows' default locale encoding (cp1252, not UTF-8) can't decode a real UTF-8 byte in the QML it reads, and did fail on one of the fifteen. Fixed all fifteen, not just the one that happened to trip today, since the other fourteen were equally fragile. Verified: full bin/check.sh reports OK end-to-end on this Windows checkout -- pytest (tests + management): 295 passed, 0 failed, 9 skipped; eslint clean; frontend node:test 57/57; PowerShell/shell parse clean; wheel + sdist pass twine check and now correctly carry modules/ (60 files, up from 52 pre-merge). synapse.main:app builds with 74 routes (up from 54 pre-merge, matching the new Projects/mail/ network endpoints).
This commit is contained in:
+54
-39
@@ -25,6 +25,7 @@ import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from synapse import proc_util
|
||||
@@ -103,12 +104,20 @@ def _psutil():
|
||||
|
||||
# -- services ------------------------------------------------------------------
|
||||
|
||||
@dataclass
|
||||
class Service:
|
||||
def __init__(self, key, label, port, cwd, patterns, argv=None):
|
||||
self.key, self.label, self.port = key, label, port
|
||||
self.cwd, self.patterns, self._argv = cwd, patterns, argv
|
||||
self.pid_file = PID_DIR / f"{key}.pid"
|
||||
self.log_file = LOG_DIR / f"{key}.log"
|
||||
key: str
|
||||
label: str
|
||||
port: int
|
||||
cwd: Path
|
||||
patterns: list
|
||||
_argv: object = None
|
||||
pid_file: Path = field(init=False)
|
||||
log_file: Path = field(init=False)
|
||||
|
||||
def __post_init__(self):
|
||||
self.pid_file = PID_DIR / f"{self.key}.pid"
|
||||
self.log_file = LOG_DIR / f"{self.key}.log"
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
@@ -118,7 +127,7 @@ class Service:
|
||||
return self._argv() if callable(self._argv) else self._argv
|
||||
|
||||
|
||||
# Bind loopback by default: the backend/memory REST APIs are unauthenticated, so
|
||||
# Bind loopback by default: the backend REST API is unauthenticated, so
|
||||
# binding 0.0.0.0 handed the full admin+data plane to any host on the LAN. Set
|
||||
# NEXUS_BIND_HOST=0.0.0.0 to opt into LAN exposure once real auth is in place.
|
||||
BIND_HOST = settings.bind_host
|
||||
@@ -137,10 +146,7 @@ def _uvicorn(app: str, port: int):
|
||||
|
||||
|
||||
SERVICES = {
|
||||
"memory": Service("memory", "NEXUS MEMORY SERVICE", settings.memory_port, settings.state_dir,
|
||||
["uvicorn synapse.memory"],
|
||||
lambda: _uvicorn("synapse.memory.service:app", settings.memory_port)),
|
||||
"backend": Service("backend", "NEXUS BACKEND SERVICE", settings.backend_port, settings.state_dir,
|
||||
"backend": Service("backend", "NEXUS BACKEND SERVICE", settings.backend_port, ROOT,
|
||||
["uvicorn synapse.main"],
|
||||
lambda: _uvicorn("synapse.main:sio_app", settings.backend_port)),
|
||||
"frontend": Service("frontend", "NEXUS FRONTEND SERVICE", 5173, FRONTEND_DIR,
|
||||
@@ -233,10 +239,10 @@ _POLL_STEP = 0.25
|
||||
|
||||
def wait_for_port(svc: Service, timeout: int = 30) -> bool:
|
||||
if http_ok(svc.url):
|
||||
# "READY", not "already running": `ncp start` launches memory and backend
|
||||
# together and only then waits on each, so by the time the backend's turn
|
||||
# comes it is normally up - and reporting "already running" for a service
|
||||
# this same command started two seconds ago reads like a stale process.
|
||||
# "READY", not "already running": `ncp start` launches its services and
|
||||
# only then waits on each, so by the time a service's turn comes it is
|
||||
# normally up - and reporting "already running" for a service this same
|
||||
# command started two seconds ago reads like a stale process.
|
||||
print(f" {svc.label} READY (:{svc.port})")
|
||||
return True
|
||||
for _ in range(int(timeout / _POLL_STEP)):
|
||||
@@ -400,9 +406,7 @@ def stop_ollama() -> None:
|
||||
# -- commands ------------------------------------------------------------------
|
||||
|
||||
def cmd_start(target) -> None:
|
||||
if target in ("--memory", "-m"):
|
||||
launch(SERVICES["memory"]); wait_for_port(SERVICES["memory"])
|
||||
elif target in ("--backend", "-b"):
|
||||
if target in ("--backend", "-b"):
|
||||
launch(SERVICES["backend"]); wait_for_port(SERVICES["backend"])
|
||||
start_ollama()
|
||||
elif target in ("--frontend", "-f"):
|
||||
@@ -427,9 +431,7 @@ def cmd_start(target) -> None:
|
||||
# and falls through to the ~30s force-kill path). Still available on
|
||||
# demand via `ncp start --frontend`.
|
||||
t0 = time.perf_counter()
|
||||
launch(SERVICES["memory"])
|
||||
launch(SERVICES["backend"])
|
||||
wait_for_port(SERVICES["memory"])
|
||||
wait_for_port(SERVICES["backend"])
|
||||
t_services = time.perf_counter()
|
||||
start_ollama(background=True)
|
||||
@@ -437,7 +439,7 @@ def cmd_start(target) -> None:
|
||||
launch(SERVICES["frontend"])
|
||||
t_bg = time.perf_counter()
|
||||
print("\nBoot timing:")
|
||||
print(f" services (memory+backend) : {t_services - t0:5.1f}s")
|
||||
print(f" backend : {t_services - t0:5.1f}s")
|
||||
print(f" ollama + frontend (bg kickoff) : {t_bg - t_services:5.1f}s")
|
||||
print(f" total to interactive : {t_bg - t0:5.1f}s")
|
||||
else:
|
||||
@@ -445,16 +447,13 @@ def cmd_start(target) -> None:
|
||||
|
||||
|
||||
def cmd_stop(target) -> None:
|
||||
if target in ("--memory", "-m"):
|
||||
stop_service(SERVICES["memory"])
|
||||
elif target in ("--backend", "-b"):
|
||||
if target in ("--backend", "-b"):
|
||||
stop_ollama(); stop_service(SERVICES["backend"])
|
||||
elif target in ("--frontend", "-f"):
|
||||
stop_service(SERVICES["frontend"])
|
||||
elif target in ("--ai", "-a"):
|
||||
stop_ollama()
|
||||
elif target in (None, "", "all"):
|
||||
stop_service(SERVICES["memory"])
|
||||
stop_ollama()
|
||||
stop_service(SERVICES["backend"])
|
||||
stop_service(SERVICES["frontend"])
|
||||
@@ -466,7 +465,6 @@ def cmd_kill() -> None:
|
||||
print("Force-killing all Nexus processes...")
|
||||
targets = [
|
||||
(settings.backend_port, "SYNAPSE"),
|
||||
(settings.memory_port, "MEMORY"),
|
||||
(5173, "INTERFACE"),
|
||||
]
|
||||
patterns = ["uvicorn synapse", "npm run dev", "vite --host"]
|
||||
@@ -498,7 +496,6 @@ def cmd_status() -> None:
|
||||
|
||||
print("Backend:")
|
||||
one("Synapse ", SERVICES["backend"])
|
||||
one("Memory service", SERVICES["memory"])
|
||||
print("\nFrontend:")
|
||||
one("Vite ", SERVICES["frontend"])
|
||||
print("\nModel server:")
|
||||
@@ -515,26 +512,25 @@ def _tail(path: Path, n: int) -> None:
|
||||
print(f" (no log at {path})")
|
||||
|
||||
|
||||
LOG_HEADINGS = {"memory": "MEMORY SERVICE", "backend": "BACKEND", "frontend": "FRONTEND"}
|
||||
LOG_HEADINGS = {"backend": "BACKEND", "frontend": "FRONTEND"}
|
||||
|
||||
|
||||
def cmd_logs(target) -> None:
|
||||
named = {"--frontend": "frontend", "-f": "frontend",
|
||||
"--backend": "backend", "-b": "backend",
|
||||
"--memory": "memory", "-m": "memory"}
|
||||
"--backend": "backend", "-b": "backend"}
|
||||
if target in named:
|
||||
key = named[target]
|
||||
print(f"=== {LOG_HEADINGS[key]} LOGS ===")
|
||||
_tail(SERVICES[key].log_file, 50)
|
||||
elif target in (None, "", "all"):
|
||||
for i, key in enumerate(("memory", "backend", "frontend")):
|
||||
for i, key in enumerate(("backend", "frontend")):
|
||||
if i:
|
||||
print()
|
||||
print(f"=== {LOG_HEADINGS[key]} LOGS ===")
|
||||
_tail(SERVICES[key].log_file, 30)
|
||||
else:
|
||||
print(f"Unknown logs target: '{target}'")
|
||||
print("Usage: ncp logs [frontend|backend|memory|all]")
|
||||
print("Usage: ncp logs [frontend|backend|all]")
|
||||
|
||||
|
||||
def _apply_fixes() -> None:
|
||||
@@ -642,11 +638,11 @@ def cmd_doctor(fix: bool = False) -> None:
|
||||
mark(importable("from synapse.main import sio_app"),
|
||||
"Backend module importable", "Backend module failed to import")
|
||||
|
||||
print("\nChecking memory service...")
|
||||
print("\nChecking memory...")
|
||||
mark((ROOT / "synapse" / "memory").is_dir(),
|
||||
"Memory module directory found", "Missing memory module directory")
|
||||
mark(importable("from synapse.memory.service import app"),
|
||||
"Memory service module importable", "Memory service module failed to import")
|
||||
mark(importable("from synapse.memory.curator import extract_for_conversation"),
|
||||
"Memory curator importable", "Memory curator failed to import")
|
||||
mark(os.access(ROOT / "synapse" / "memory", os.W_OK),
|
||||
"Memory database directory writable", "Memory database directory not writable")
|
||||
|
||||
@@ -687,6 +683,26 @@ def cmd_update() -> None:
|
||||
cmd_doctor()
|
||||
|
||||
|
||||
def cmd_upgrade() -> int:
|
||||
"""Pull + rebuild + restart the backend. This is what the web UI's "install
|
||||
update" button runs, so it must be spawned DETACHED from the backend - it
|
||||
stops the very server that asked for it.
|
||||
|
||||
Ollama is deliberately left alone (stop_service, not cmd_stop): it is a
|
||||
separate process on :11434, the restore does not touch a present binary, and
|
||||
reloading a multi-GB model is the slowest part of a restart.
|
||||
"""
|
||||
print("Stopping backend...")
|
||||
stop_service(SERVICES["backend"])
|
||||
# --no-desktop: an in-app update should not rewrite XFCE panels/theme.
|
||||
rc = sync_py("restore", "--no-desktop")
|
||||
print("\nRestarting backend...")
|
||||
launch(SERVICES["backend"])
|
||||
ok = wait_for_port(SERVICES["backend"])
|
||||
print("Backend is back up." if ok else "Backend did not come back - see runtime/backend.log")
|
||||
return rc if ok else 1
|
||||
|
||||
|
||||
def cmd_clean() -> None:
|
||||
print("Cleaning Nexus runtime files...\n")
|
||||
print("Removing PID files...")
|
||||
@@ -787,7 +803,6 @@ def cmd_web() -> int:
|
||||
started. Windows uses the pywebview window launch_nexus.ps1 opens."""
|
||||
if WINDOWS:
|
||||
if not http_ok(SERVICES["backend"].url):
|
||||
launch(SERVICES["memory"])
|
||||
launch(SERVICES["backend"])
|
||||
wait_for_port(SERVICES["backend"])
|
||||
return subprocess.run([str(PYTHON), str(ROOT / "bin" / "nexus_window.py")]).returncode
|
||||
@@ -811,14 +826,12 @@ Commands:
|
||||
show <id> Print a playbook's goal + instructions
|
||||
history [query] Recent conversations (optional keyword)
|
||||
|
||||
start Start ALL Nexus services (memory + backend + frontend)
|
||||
--memory, -m Start only the memory service
|
||||
start Start ALL Nexus services (backend + frontend)
|
||||
--frontend,-f Start only the frontend
|
||||
--backend, -b Start only the backend
|
||||
--ai, -a Start only the AI (Ollama); `start`/`start -b` already include it
|
||||
|
||||
stop Stop ALL Nexus services
|
||||
--memory, -m Stop only the memory service
|
||||
--frontend,-f Stop only the frontend
|
||||
--backend, -b Stop only the backend
|
||||
|
||||
@@ -827,12 +840,12 @@ Commands:
|
||||
|
||||
status Show service status
|
||||
logs Show logs for all services
|
||||
--memory, -m Memory service logs
|
||||
--frontend,-f Frontend logs
|
||||
--backend, -b Backend logs
|
||||
|
||||
doctor [--fix] Run Nexus diagnostics (--fix applies safe repairs)
|
||||
update Update Nexus dependencies
|
||||
upgrade Pull, rebuild and restart the backend (what the UI's update button runs)
|
||||
clean Remove runtime files and caches
|
||||
|
||||
models
|
||||
@@ -880,6 +893,8 @@ def main(argv) -> int:
|
||||
cmd_doctor(fix="--fix" in rest)
|
||||
elif cmd == "update":
|
||||
cmd_update()
|
||||
elif cmd == "upgrade":
|
||||
return cmd_upgrade()
|
||||
elif cmd == "clean":
|
||||
cmd_clean()
|
||||
elif cmd == "nvidia-reqs":
|
||||
|
||||
Reference in New Issue
Block a user