Agent Zero AI framework
Split Launcher host file permissions
Alessandrob11a57424e30
diff --git a/plugins/_a0_connector/AGENTS.md b/plugins/_a0_connector/AGENTS.mdindex 649f41f21..69dd2b7d2 100644--- a/plugins/_a0_connector/AGENTS.md+++ b/plugins/_a0_connector/AGENTS.md@@ -36,6 +36,9 @@WebUI mutations require CSRF, await the matching acknowledgement, and returnrefreshed status. Never let the WebUI select a host folder or personalbrowser profile.+- Launcher gateway scopes expose file reading and writing separately. File+ writing depends on reading, and Code execution depends on file writing. Keep+ older gateway declarations without `file_write` read/write compatible.- The `chat-top-end` Launcher gateway extension renders only when the user agentincludes `A0-Launcher/`. It may show status, master/scope controls,preparation errors, and Emergency disconnect; standard browser sessions mustdiff --git a/plugins/_a0_connector/api/v1/capabilities.py b/plugins/_a0_connector/api/v1/capabilities.pyindex d52574acc..4c9e5e035 100644--- a/plugins/_a0_connector/api/v1/capabilities.py+++ b/plugins/_a0_connector/api/v1/capabilities.py@@ -29,6 +29,7 @@ _BASE_FEATURES = ["remote_file_tree","token_status","launcher_gateway",+ "launcher_gateway_file_write",]_OPTIONAL_FEATURES: dict[str, tuple[str, ...]] = {diff --git a/plugins/_a0_connector/api/v1/launcher_gateway_control.py b/plugins/_a0_connector/api/v1/launcher_gateway_control.pyindex 04a94a7d5..e1e95074a 100644--- a/plugins/_a0_connector/api/v1/launcher_gateway_control.py+++ b/plugins/_a0_connector/api/v1/launcher_gateway_control.py@@ -18,7 +18,7 @@ from plugins._a0_connector.helpers.ws_runtime import (_CONTROL_EVENT = "connector_gateway_control"_CONTROL_TIMEOUT_SECONDS = 8.0-_SCOPE_KEYS = ("files", "code_execution", "browser", "computer_use")+_SCOPE_KEYS = ("files", "file_write", "code_execution", "browser", "computer_use")class LauncherGatewayControl(connector_base.ProtectedConnectorApiHandler):@@ -41,11 +41,13 @@ class LauncherGatewayControl(connector_base.ProtectedConnectorApiHandler):not isinstance(scopes.get(key), bool) for key in _SCOPE_KEYS):return Response(- "scopes must contain boolean files, code_execution, browser, and computer_use values",+ "scopes must contain boolean files, file_write, code_execution, browser, and computer_use values",status=400,)normalized = {key: scopes[key] for key in _SCOPE_KEYS}if not normalized["files"]:+ normalized["file_write"] = False+ if not normalized["file_write"]:normalized["code_execution"] = Falsepayload["scopes"] = normalizedelif action != "emergency_disconnect":diff --git a/plugins/_a0_connector/extensions/webui/chat-top-end/launcher-gateway.html b/plugins/_a0_connector/extensions/webui/chat-top-end/launcher-gateway.htmlindex d762e1ed4..aa8764bca 100644--- a/plugins/_a0_connector/extensions/webui/chat-top-end/launcher-gateway.html+++ b/plugins/_a0_connector/extensions/webui/chat-top-end/launcher-gateway.html@@ -48,26 +48,48 @@<template x-if="$store.launcherGateway.gateway"><div class="launcher-gateway-controls">- <label class="launcher-gateway-row is-master">+ <div class="launcher-gateway-row is-master"><span>Host access</span>- <input type="checkbox" :checked="$store.launcherGateway.gateway.master_enabled" :disabled="$store.launcherGateway.saving" @change="$store.launcherGateway.setMaster($event.target.checked)">- </label>- <label class="launcher-gateway-row">- <span>Files read/write</span>- <input type="checkbox" :checked="$store.launcherGateway.gateway.scopes.files" :disabled="$store.launcherGateway.saving" @change="$store.launcherGateway.setScope('files', $event.target.checked)">- </label>- <label class="launcher-gateway-row">+ <label class="toggle launcher-gateway-switch">+ <input type="checkbox" aria-label="Host access" :checked="$store.launcherGateway.gateway.master_enabled" :disabled="$store.launcherGateway.saving" @change="$store.launcherGateway.setMaster($event.target.checked)">+ <span class="toggler"></span>+ </label>+ </div>+ <div class="launcher-gateway-row" :class="{ 'is-disabled': !$store.launcherGateway.gateway.master_enabled }">+ <span>Files read</span>+ <label class="toggle launcher-gateway-switch">+ <input type="checkbox" aria-label="Files read" :checked="$store.launcherGateway.gateway.scopes.files" :disabled="$store.launcherGateway.saving || !$store.launcherGateway.gateway.master_enabled" @change="$store.launcherGateway.setScope('files', $event.target.checked)">+ <span class="toggler"></span>+ </label>+ </div>+ <div class="launcher-gateway-row" :class="{ 'is-disabled': !$store.launcherGateway.gateway.master_enabled || !$store.launcherGateway.gateway.scopes.files }">+ <span>Files write</span>+ <label class="toggle launcher-gateway-switch">+ <input type="checkbox" aria-label="Files write" :checked="$store.launcherGateway.gateway.scopes.file_write" :disabled="$store.launcherGateway.saving || !$store.launcherGateway.gateway.master_enabled || !$store.launcherGateway.gateway.scopes.files" @change="$store.launcherGateway.setScope('file_write', $event.target.checked)">+ <span class="toggler"></span>+ </label>+ </div>+ <div class="launcher-gateway-row" :class="{ 'is-disabled': !$store.launcherGateway.gateway.master_enabled || !$store.launcherGateway.gateway.scopes.file_write }"><span>Code execution</span>- <input type="checkbox" :checked="$store.launcherGateway.gateway.scopes.code_execution" :disabled="$store.launcherGateway.saving || !$store.launcherGateway.gateway.scopes.files" @change="$store.launcherGateway.setScope('code_execution', $event.target.checked)">- </label>- <label class="launcher-gateway-row">- <span>Personal browser</span>- <input type="checkbox" :checked="$store.launcherGateway.gateway.scopes.browser" :disabled="$store.launcherGateway.saving" @change="$store.launcherGateway.setScope('browser', $event.target.checked)">- </label>- <label class="launcher-gateway-row">+ <label class="toggle launcher-gateway-switch">+ <input type="checkbox" aria-label="Code execution" :checked="$store.launcherGateway.gateway.scopes.code_execution" :disabled="$store.launcherGateway.saving || !$store.launcherGateway.gateway.master_enabled || !$store.launcherGateway.gateway.scopes.file_write" @change="$store.launcherGateway.setScope('code_execution', $event.target.checked)">+ <span class="toggler"></span>+ </label>+ </div>+ <div class="launcher-gateway-row" :class="{ 'is-disabled': !$store.launcherGateway.gateway.master_enabled }">+ <span>Use my Browser</span>+ <label class="toggle launcher-gateway-switch">+ <input type="checkbox" aria-label="Use my Browser" :checked="$store.launcherGateway.gateway.scopes.browser" :disabled="$store.launcherGateway.saving || !$store.launcherGateway.gateway.master_enabled" @change="$store.launcherGateway.setScope('browser', $event.target.checked)">+ <span class="toggler"></span>+ </label>+ </div>+ <div class="launcher-gateway-row" :class="{ 'is-disabled': !$store.launcherGateway.gateway.master_enabled }"><span>Computer Use</span>- <input type="checkbox" :checked="$store.launcherGateway.gateway.scopes.computer_use" :disabled="$store.launcherGateway.saving" @change="$store.launcherGateway.setScope('computer_use', $event.target.checked)">- </label>+ <label class="toggle launcher-gateway-switch">+ <input type="checkbox" aria-label="Computer Use" :checked="$store.launcherGateway.gateway.scopes.computer_use" :disabled="$store.launcherGateway.saving || !$store.launcherGateway.gateway.master_enabled" @change="$store.launcherGateway.setScope('computer_use', $event.target.checked)">+ <span class="toggler"></span>+ </label>+ </div></div></template>@@ -132,7 +154,12 @@.launcher-gateway-controls { display: grid; gap: .15rem; margin-top: .7rem; }.launcher-gateway-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; min-height: 2rem; font-size: .82rem; }.launcher-gateway-row.is-master { padding-bottom: .35rem; margin-bottom: .2rem; border-bottom: 1px solid var(--color-border); font-weight: 650; }- .launcher-gateway-row input { accent-color: var(--color-primary); }+ .launcher-gateway-row.is-disabled { color: var(--color-text-secondary); opacity: .55; }+ .launcher-gateway-switch { flex: 0 0 auto; width: 2.2rem; height: 1.25rem; }+ .launcher-gateway-switch .toggler:before { width: .9rem; height: .9rem; left: .18rem; bottom: .18rem; }+ .launcher-gateway-switch input:checked + .toggler:before { transform: translateX(.94rem); }+ .launcher-gateway-switch input:focus-visible + .toggler { outline: 2px solid var(--color-primary); outline-offset: 2px; }+ .launcher-gateway-switch input:disabled + .toggler { cursor: default; }.launcher-gateway-notices { display: grid; gap: .35rem; margin-top: .55rem; }.launcher-gateway-notices p { display: flex; gap: .35rem; margin: 0; color: #d79b35; font-size: .75rem; line-height: 1.3; }.launcher-gateway-notices .material-symbols-outlined { font-size: .95rem; }diff --git a/plugins/_a0_connector/helpers/ws_runtime.py b/plugins/_a0_connector/helpers/ws_runtime.pyindex 199d9c46e..ee4a2e325 100644--- a/plugins/_a0_connector/helpers/ws_runtime.py+++ b/plugins/_a0_connector/helpers/ws_runtime.py@@ -208,7 +208,7 @@ _GATEWAY_STATES = {"error","disconnected",}-_GATEWAY_SCOPE_KEYS = ("files", "code_execution", "browser", "computer_use")+_GATEWAY_SCOPE_KEYS = ("files", "file_write", "code_execution", "browser", "computer_use")def _bounded_gateway_status(value: Any, *, depth: int = 0) -> Any:@@ -250,10 +250,14 @@ def store_sid_launcher_gateway_metadata(raw_scopes = payload.get("scopes")scopes = {- key: bool(raw_scopes.get(key)) if isinstance(raw_scopes, dict) else False+ key: bool(+ raw_scopes.get(key, raw_scopes.get("files") if key == "file_write" else False)+ ) if isinstance(raw_scopes, dict) else Falsefor key in _GATEWAY_SCOPE_KEYS}if not scopes["files"]:+ scopes["file_write"] = False+ if not scopes["file_write"]:scopes["code_execution"] = Falsemaster_enabled = bool(payload.get("master_enabled", True))state = str(payload.get("state", "connected") or "").strip().lower()diff --git a/plugins/_a0_connector/webui/launcher-gateway-store.js b/plugins/_a0_connector/webui/launcher-gateway-store.jsindex 503655462..7073593db 100644--- a/plugins/_a0_connector/webui/launcher-gateway-store.js+++ b/plugins/_a0_connector/webui/launcher-gateway-store.js@@ -99,12 +99,14 @@ const model = {const current = this.gateway?.scopes || {};const scopes = {files: Boolean(current.files),+ file_write: Boolean(current.file_write ?? current.files),code_execution: Boolean(current.code_execution),browser: Boolean(current.browser),computer_use: Boolean(current.computer_use),[scope]: Boolean(enabled),};- if (!scopes.files) scopes.code_execution = false;+ if (!scopes.files) scopes.file_write = false;+ if (!scopes.file_write) scopes.code_execution = false;await this.control({ action: "replace_scopes", scopes });},diff --git a/tests/test_a0_connector_launcher_gateway.py b/tests/test_a0_connector_launcher_gateway.pyindex b52ca56dc..ee6947148 100644--- a/tests/test_a0_connector_launcher_gateway.py+++ b/tests/test_a0_connector_launcher_gateway.py@@ -15,7 +15,12 @@ def _sid(label: str) -> str:return f"gateway-{label}-{uuid.uuid4()}"-def _gateway(gateway_id: str, *, files: bool = True) -> dict:+def _gateway(+ gateway_id: str,+ *,+ files: bool = True,+ file_write: bool | None = None,+) -> dict:return {"version": 1,"kind": "launcher",@@ -25,6 +30,7 @@ def _gateway(gateway_id: str, *, files: bool = True) -> dict:"master_enabled": True,"scopes": {"files": files,+ "file_write": files if file_write is None else file_write,"code_execution": True,"browser": True,"computer_use": True,@@ -34,6 +40,7 @@ def _gateway(gateway_id: str, *, files: bool = True) -> dict:def test_launcher_gateway_features_are_negotiated_on_http_and_websocket() -> None:assert "launcher_gateway" in _feature_list()+ assert "launcher_gateway_file_write" in _feature_list()assert "launcher_gateway_control" in WS_FEATURESassert LauncherGatewayStatus.requires_auth() is True@@ -105,18 +112,45 @@ def test_duplicate_gateway_identity_replaces_stale_socket() -> None:ws_runtime.unregister_sid(fresh_sid)-def test_gateway_disables_code_execution_when_files_are_off() -> None:+def test_gateway_scope_dependencies_keep_reads_separate_from_writes() -> None:sid = _sid("scope")ws_runtime.register_sid(sid)ws_runtime.store_sid_launcher_gateway_metadata(sid, _gateway("installation-a", files=False))try:gateway = ws_runtime.launcher_gateway_status()["gateway"]assert gateway["scopes"]["files"] is False+ assert gateway["scopes"]["file_write"] is False+ assert gateway["scopes"]["code_execution"] is False+ finally:+ ws_runtime.unregister_sid(sid)++ sid = _sid("read-only")+ ws_runtime.register_sid(sid)+ ws_runtime.store_sid_launcher_gateway_metadata(+ sid,+ _gateway("installation-a", file_write=False),+ )+ try:+ gateway = ws_runtime.launcher_gateway_status()["gateway"]+ assert gateway["scopes"]["files"] is True+ assert gateway["scopes"]["file_write"] is Falseassert gateway["scopes"]["code_execution"] is Falsefinally:ws_runtime.unregister_sid(sid)+def test_legacy_gateway_files_scope_keeps_read_write_behavior() -> None:+ sid = _sid("legacy")+ payload = _gateway("installation-a")+ payload["scopes"].pop("file_write")+ ws_runtime.register_sid(sid)+ ws_runtime.store_sid_launcher_gateway_metadata(sid, payload)+ try:+ assert ws_runtime.launcher_gateway_status()["gateway"]["scopes"]["file_write"] is True+ finally:+ ws_runtime.unregister_sid(sid)++def test_gateway_status_metadata_is_bounded() -> None:sid = _sid("bounded")payload = _gateway("installation-a")@@ -178,6 +212,25 @@ def test_gateway_control_requires_csrf_and_waits_for_ack(monkeypatch) -> None:ws_runtime.unregister_sid(sid)+def test_gateway_scope_control_requires_explicit_file_write() -> None:+ handler = launcher_gateway_control.LauncherGatewayControl(None, None)+ result = asyncio.run(+ handler.process(+ {+ "action": "replace_scopes",+ "scopes": {+ "files": True,+ "code_execution": True,+ "browser": False,+ "computer_use": False,+ },+ },+ None,+ )+ )+ assert result.status_code == 400++def test_gateway_control_acknowledgement_timeout(monkeypatch) -> None:sid = _sid("timeout")ws_runtime.register_sid(sid)