[Haik]: ckpt, abstracted helpers within NineRouterProcess

This commit is contained in:
haikdc
2026-04-05 20:47:18 -07:00
parent aa250ce203
commit 28820c91eb
5 changed files with 67 additions and 49 deletions
@@ -0,0 +1,26 @@
import os
from typing import Optional
from typeguard import typechecked
# TODO: type spec this entirely
@typechecked
def find_9router_dir(
root_dir: str,
) -> Optional[str]:
"""Locate the bundled 9Router directory (dev or packaged)."""
p_is_packaged: bool = os.environ.get("OPENSWARM_PACKAGED") == "1"
if p_is_packaged:
p_resources: str = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(root_dir))))
p_candidate: str = os.path.join(p_resources, "9router")
if os.path.isdir(p_candidate):
return p_candidate
else:
p_backend_dir: str = os.path.dirname(os.path.dirname(os.path.dirname(root_dir)))
p_project_root: str = os.path.dirname(p_backend_dir)
p_candidate = os.path.join(p_project_root, "9router")
if os.path.isdir(p_candidate):
return p_candidate
return None
@@ -0,0 +1,15 @@
import os
import shutil
from typing import Optional
from typeguard import typechecked
@typechecked
def find_node() -> Optional[str]:
node: Optional[str] = shutil.which("node")
if node:
return node
electron_path: Optional[str] = os.environ.get("OPENSWARM_ELECTRON_PATH")
if electron_path and os.path.exists(electron_path):
return electron_path
return None
@@ -0,0 +1,18 @@
from typeguard import typechecked
# TODO: type spec this entirely
@typechecked
def forward_output(pipe) -> None:
try:
for line in iter(pipe.readline, b""):
text = line.decode("utf-8", errors="replace").rstrip()
if text:
print(f"[9router] {text}", flush=True)
except Exception:
pass
finally:
try:
pipe.close()
except Exception:
pass