Skip to content

Self-improving AI Employees for everyone

refactor(browser+email+code): self-contained plugin folders

trohitg57b816fc0fd3
diff --git a/server/main.py b/server/main.py
index b3e50f53..db08e326 100644
--- a/server/main.py
+++ b/server/main.py
@@ -354,7 +354,7 @@ async def lifespan(app: FastAPI):
await close_relay_client(clear_stored_session=False)
# Shut down agent-browser daemon (prevents orphaned processes and EBUSY file locks)
- from services.browser_service import shutdown_browser_service
+ from nodes.browser._service import shutdown_browser_service
await shutdown_browser_service()
# Kill all managed processes (process manager node)
diff --git a/server/services/browser_service.py b/server/nodes/browser/_service.py
similarity index 100%
rename from server/services/browser_service.py
rename to server/nodes/browser/_service.py
diff --git a/server/nodes/browser/browser.py b/server/nodes/browser/browser.py
index 82a0df6a..7984b3b5 100644
--- a/server/nodes/browser/browser.py
+++ b/server/nodes/browser/browser.py
@@ -3,7 +3,7 @@
Interactive browser automation via the agent-browser CLI. The plugin
maps the high-level operation enum to CLI argv, resolves the browser
binary (system Chrome / Edge / Chromium / bundled), and delegates the
-subprocess invocation to ``services.browser_service``.
+subprocess invocation to ``_service`` (the plugin-private service).
"""
from __future__ import annotations
@@ -317,7 +317,7 @@ class BrowserNode(ActionNode):
@Operation("dispatch")
async def dispatch(self, ctx: NodeContext, params: BrowserParams) -> BrowserOutput:
- from services.browser_service import get_browser_service
+ from ._service import get_browser_service
svc = get_browser_service()
if not svc:
diff --git a/server/services/claude_code_service.py b/server/nodes/code/_claude_code.py
similarity index 100%
rename from server/services/claude_code_service.py
rename to server/nodes/code/_claude_code.py
diff --git a/server/services/himalaya_service.py b/server/nodes/email/_himalaya.py
similarity index 100%
rename from server/services/himalaya_service.py
rename to server/nodes/email/_himalaya.py
diff --git a/server/services/email_service.py b/server/nodes/email/_service.py
similarity index 98%
rename from server/services/email_service.py
rename to server/nodes/email/_service.py
index 7070ed05..3d271589 100644
--- a/server/services/email_service.py
+++ b/server/nodes/email/_service.py
@@ -12,7 +12,7 @@ from core.logging import get_logger
logger = get_logger(__name__)
_CONFIG: Optional[Dict] = None
-_CONFIG_PATH = Path(__file__).parent.parent / "config" / "email_providers.json"
+_CONFIG_PATH = Path(__file__).resolve().parents[2] / "config" / "email_providers.json"
def _load_config() -> Dict:
@@ -46,7 +46,7 @@ class EmailService:
@property
def himalaya(self):
- from services.himalaya_service import get_himalaya_service
+ from ._himalaya import get_himalaya_service
return get_himalaya_service()
def _provider_preset(self, name: str) -> Dict:
diff --git a/server/nodes/email/email_read.py b/server/nodes/email/email_read.py
index e95f2c8d..7e16f933 100644
--- a/server/nodes/email/email_read.py
+++ b/server/nodes/email/email_read.py
@@ -120,5 +120,5 @@ class EmailReadNode(ActionNode):
@Operation("query", cost={"service": "email", "action": "imap", "count": 1})
async def query(self, ctx: NodeContext, params: EmailReadParams) -> Any:
# Body inlined from handlers/email.py (Wave 11.D.1).
- from services.email_service import get_email_service
+ from ._service import get_email_service
return await get_email_service().read(params.model_dump())
diff --git a/server/nodes/email/email_receive.py b/server/nodes/email/email_receive.py
index 192572c3..40a6af3d 100644
--- a/server/nodes/email/email_receive.py
+++ b/server/nodes/email/email_receive.py
@@ -68,7 +68,7 @@ class EmailReceiveNode(TriggerNode):
import asyncio
import time
from datetime import datetime
- from services.email_service import get_email_service
+ from ._service import get_email_service
from services.status_broadcaster import get_status_broadcaster
from services import event_waiter
diff --git a/server/nodes/email/email_send.py b/server/nodes/email/email_send.py
index 9bd666af..c1c71e88 100644
--- a/server/nodes/email/email_send.py
+++ b/server/nodes/email/email_send.py
@@ -54,5 +54,5 @@ class EmailSendNode(ActionNode):
@Operation("send", cost={"service": "email", "action": "send", "count": 1})
async def send(self, ctx: NodeContext, params: EmailSendParams) -> Any:
# Body inlined from handlers/email.py (Wave 11.D.1).
- from services.email_service import get_email_service
+ from ._service import get_email_service
return await get_email_service().send(params.model_dump(by_alias=False))
diff --git a/server/services/deployment/manager.py b/server/services/deployment/manager.py
index 6d2f0f84..fc28f795 100644
--- a/server/services/deployment/manager.py
+++ b/server/services/deployment/manager.py
@@ -779,7 +779,7 @@ class DeploymentManager:
params: Dict[str, Any]) -> Callable:
"""Create Himalaya email polling coroutine for deployment mode."""
async def poll(queue: asyncio.Queue, is_running_fn: Callable):
- from services.email_service import get_email_service
+ from nodes.email._service import get_email_service
svc = get_email_service()
creds = await svc.resolve_credentials(params)
diff --git a/server/tests/nodes/test_email.py b/server/tests/nodes/test_email.py
index 0ae79857..bcd84458 100644
--- a/server/tests/nodes/test_email.py
+++ b/server/tests/nodes/test_email.py
@@ -27,7 +27,8 @@ pytestmark = pytest.mark.node_contract
def _reset_singletons():
"""Wipe cached singletons so each test gets a clean EmailService / HimalayaService."""
- from services import email_service, himalaya_service
+ from nodes.email import _service as email_service
+ from nodes.email import _himalaya as himalaya_service
email_service.EmailService._instance = None
himalaya_service.HimalayaService._instance = None
@@ -47,7 +48,7 @@ def _base_creds_params(**overrides):
def _patch_ensure_binary():
"""Patch HimalayaService.ensure_binary to return a fake path without shutil.which."""
return patch(
- "services.himalaya_service.HimalayaService.ensure_binary",
+ "nodes.email._himalaya.HimalayaService.ensure_binary",
new=AsyncMock(return_value="/usr/bin/himalaya"),
)
@@ -91,7 +92,7 @@ class TestEmailSend:
# Return empty JSON so himalaya "succeeds" with no extra fields
with _patch_ensure_binary(), patched_subprocess(stdout=b"{}", returncode=0), \
patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing(), \
- patch("services.himalaya_service.HimalayaService.execute",
+ patch("nodes.email._himalaya.HimalayaService.execute",
new=AsyncMock(return_value={})) as mock_exec:
result = await harness.execute(
"emailSend",
@@ -149,7 +150,7 @@ class TestEmailRead:
]
# Himalaya returns a list for envelope list -> wrapped in {data: ...}
with _patch_ensure_binary(), \
- patch("services.himalaya_service.HimalayaService.execute",
+ patch("nodes.email._himalaya.HimalayaService.execute",
new=AsyncMock(return_value=envelopes)), \
patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():
result = await harness.execute(
@@ -166,7 +167,7 @@ class TestEmailRead:
async def test_read_merges_dict_output(self, harness):
message = {"subject": "hello", "body": "world", "from": "[email protected]"}
with _patch_ensure_binary(), \
- patch("services.himalaya_service.HimalayaService.execute",
+ patch("nodes.email._himalaya.HimalayaService.execute",
new=AsyncMock(return_value=message)), \
patched_container(auth_api_keys={"email_address": "[email protected]", "email_password": "sekret", "email_provider": "gmail"}), patched_pricing():
result = await harness.execute(
@@ -213,7 +214,7 @@ class TestEmailRead:
class TestEmailReceive:
async def test_new_email_detected_on_second_poll(self, harness):
"""Baseline sees {id1}; next poll returns {id1,id2} -> dispatch id2."""
- from services.email_service import EmailService
+ from nodes.email._service import EmailService
email_detail = {"from": "[email protected]", "subject": "new!", "body": "hi"}
@@ -248,8 +249,8 @@ class TestEmailReceive:
assert dispatch_mock.call_args.args[0] == "email_received"
async def test_mark_as_read_adds_seen_flag(self, harness):
- from services.email_service import EmailService
- from services.himalaya_service import HimalayaService
+ from nodes.email._service import EmailService
+ from nodes.email._himalaya import HimalayaService
poll_ids_mock = AsyncMock(side_effect=[set(), {"42"}])
fetch_detail_mock = AsyncMock(return_value={"message_id": "42", "folder": "INBOX"})
@@ -291,7 +292,7 @@ class TestEmailReceive:
async def test_subprocess_error_surfaces_as_envelope(self, harness):
"""If poll_ids raises (e.g. Himalaya subprocess fails) the handler returns an error envelope."""
- from services.email_service import EmailService
+ from nodes.email._service import EmailService
poll_ids_mock = AsyncMock(side_effect=RuntimeError("himalaya error: connection refused"))
diff --git a/server/tests/nodes/test_web_automation.py b/server/tests/nodes/test_web_automation.py
index 5240722a..439065f2 100644
--- a/server/tests/nodes/test_web_automation.py
+++ b/server/tests/nodes/test_web_automation.py
@@ -50,7 +50,7 @@ class _FakeBrowserService:
def _patch_browser_service(svc):
"""Patch get_browser_service to return the fake."""
- return patch("services.browser_service.get_browser_service", return_value=svc)
+ return patch("nodes.browser._service.get_browser_service", return_value=svc)
# ============================================================================
@@ -140,7 +140,7 @@ class TestBrowser:
async def test_service_not_installed(self, harness):
with patch(
- "services.browser_service.get_browser_service", return_value=None
+ "nodes.browser._service.get_browser_service", return_value=None
):
result = await harness.execute("browser", {"operation": "navigate", "url": "https://x"})