Skip to content

Agent Zero AI framework

Turn Launcher host Disconnect into Reconnect

Alessandro3c23b9b94ed6
diff --git a/plugins/_a0_connector/AGENTS.md b/plugins/_a0_connector/AGENTS.md
index 2585e9333..cb3393b41 100644
--- a/plugins/_a0_connector/AGENTS.md
+++ b/plugins/_a0_connector/AGENTS.md
@@ -42,14 +42,17 @@
older gateway declarations without `file_write` read/write compatible.
- The `sync-status-end` Launcher gateway extension renders only when the user agent
includes `A0-Launcher/`. It may show status, master/scope controls,
- preparation errors, and Disconnect; standard browser sessions must
+ preparation errors, and the connection action; standard browser sessions must
not expose it. Keep its trigger inside the existing sync indicator, render one
computer glyph per connected Launcher gateway, and retain one muted glyph
while disconnected so the control remains reachable. Do not add a native
tooltip, visible status label, count badge, or animated expansion.
Keep the open popover above the compact right-canvas rail and report control
failures through the shared notification system. Use the standard WebUI
- border-radius tokens for its controls and popover.
+ border-radius tokens for its controls and popover. After Disconnect is
+ acknowledged, keep the popover open and turn that same action into Reconnect;
+ use only the narrow Launcher WebContents bridge so this also works in a
+ detached Instance window. Pausing remains the reversible master switch.
- File operation results may arrive as chunked JSON/base64
`connector_file_op_result` frames; resolve the pending file operation only
after all chunks for the `op_id` are assembled.
diff --git a/plugins/_a0_connector/extensions/webui/sync-status-end/launcher-gateway.html b/plugins/_a0_connector/extensions/webui/sync-status-end/launcher-gateway.html
index c921d5cae..5f0fca0a9 100644
--- a/plugins/_a0_connector/extensions/webui/sync-status-end/launcher-gateway.html
+++ b/plugins/_a0_connector/extensions/webui/sync-status-end/launcher-gateway.html
@@ -109,11 +109,13 @@
<button
type="button"
- class="launcher-gateway-disconnect"
- x-show="$store.launcherGateway.gateway"
+ class="launcher-gateway-connection-action"
+ :class="{ 'is-reconnect': !$store.launcherGateway.gateway }"
+ x-show="$store.launcherGateway.gateway || $store.launcherGateway.reconnectAvailable"
:disabled="$store.launcherGateway.saving"
- @click="$store.launcherGateway.emergencyDisconnect()"
- >Disconnect</button>
+ @click="$store.launcherGateway.gateway ? $store.launcherGateway.emergencyDisconnect() : $store.launcherGateway.reconnect()"
+ x-text="$store.launcherGateway.saving ? ($store.launcherGateway.gateway ? 'Disconnecting…' : 'Reconnecting…') : ($store.launcherGateway.gateway ? 'Disconnect' : 'Reconnect')"
+ ></button>
</section>
</div>
@@ -157,6 +159,7 @@
.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; }
.launcher-gateway-empty { margin: .7rem 0 0; color: var(--color-text-secondary); font-size: .78rem; }
- .launcher-gateway-disconnect { width: 100%; margin-top: .75rem; padding: .48rem .65rem; border: 1px solid color-mix(in srgb, #db5b61 55%, var(--color-border)); border-radius: var(--border-radius-sm); background: transparent; color: #db5b61; cursor: pointer; }
- .launcher-gateway-disconnect:disabled { opacity: .55; cursor: default; }
+ .launcher-gateway-connection-action { width: 100%; margin-top: .75rem; padding: .48rem .65rem; border: 1px solid color-mix(in srgb, #db5b61 55%, var(--color-border)); border-radius: var(--border-radius-sm); background: transparent; color: #db5b61; cursor: pointer; }
+ .launcher-gateway-connection-action.is-reconnect { border-color: var(--color-highlight); background: var(--color-highlight); color: #fff; }
+ .launcher-gateway-connection-action:disabled { opacity: .55; cursor: default; }
</style>
diff --git a/plugins/_a0_connector/webui/launcher-gateway-store.js b/plugins/_a0_connector/webui/launcher-gateway-store.js
index d57130efc..9908af217 100644
--- a/plugins/_a0_connector/webui/launcher-gateway-store.js
+++ b/plugins/_a0_connector/webui/launcher-gateway-store.js
@@ -11,13 +11,18 @@ const model = {
saving: false,
open: false,
intervalId: null,
+ reconnectAvailable: false,
get visible() {
return /(?:^|\s)A0-Launcher\/[^\s]+/.test(navigator.userAgent);
},
+ get canReconnect() {
+ return typeof window.a0LauncherHost?.reconnect === "function";
+ },
+
get gateway() {
- return this.status?.gateway || null;
+ return this.state === "disconnected" ? null : this.status?.gateway || null;
},
get state() {
@@ -75,6 +80,16 @@ const model = {
this.status = { state: "error", gateway: null, error: error?.message || "Status unavailable" };
} finally {
this.loading = false;
+ await this.refreshReconnectState();
+ }
+ },
+
+ async refreshReconnectState() {
+ try {
+ const state = await window.a0LauncherHost?.getState?.();
+ this.reconnectAvailable = state?.reconnectAvailable === true;
+ } catch {
+ this.reconnectAvailable = false;
}
},
@@ -98,8 +113,31 @@ const model = {
},
async emergencyDisconnect() {
- await this.control({ action: "emergency_disconnect" });
- this.open = false;
+ if (await this.control({ action: "emergency_disconnect" })) {
+ this.reconnectAvailable = this.canReconnect;
+ this.status = { ...this.status, state: "disconnected", connected: false, gateway: null, gateways: [] };
+ if (!this.canReconnect) this.open = false;
+ }
+ },
+
+ async reconnect() {
+ if (this.saving) return;
+ this.saving = true;
+ try {
+ const response = await window.a0LauncherHost?.reconnect?.();
+ if (!response?.ok) throw new Error(response?.message || "Host access could not reconnect.");
+ this.reconnectAvailable = false;
+ this.status = { ...this.status, state: "connecting", connected: false, gateway: null, gateways: [] };
+ } catch (error) {
+ console.error("Failed to reconnect Launcher host:", error);
+ void toastFrontendError(
+ error?.message || "Host access could not reconnect.",
+ "Host access",
+ );
+ await this.refreshReconnectState();
+ } finally {
+ this.saving = false;
+ }
},
async control(payload) {
@@ -108,6 +146,7 @@ const model = {
try {
const response = await callJsonApi(CONTROL_API, payload);
this.status = response?.status || this.status;
+ return true;
} catch (error) {
console.error("Failed to control Launcher host:", error);
void toastFrontendError(
@@ -115,6 +154,7 @@ const model = {
"Host access",
);
await this.refresh();
+ return false;
} finally {
this.saving = false;
}
diff --git a/tests/test_a0_connector_launcher_gateway.py b/tests/test_a0_connector_launcher_gateway.py
index 2efb40722..05d990c85 100644
--- a/tests/test_a0_connector_launcher_gateway.py
+++ b/tests/test_a0_connector_launcher_gateway.py
@@ -78,12 +78,28 @@ def test_launcher_gateway_indicator_joins_sync_status_without_visual_noise() ->
assert "launcher-gateway-trigger-label" not in source
assert "launcher-gateway-dot" not in source
assert ":title=" not in source
- assert ">Disconnect</button>" in source
+ assert "'Disconnect' : 'Reconnect'" in source
+ assert "$store.launcherGateway.gateway ? $store.launcherGateway.emergencyDisconnect() : $store.launcherGateway.reconnect()" in source
assert "Emergency disconnect" not in source
popover_css = source.split(".launcher-gateway-popover {", 1)[1].split("}", 1)[0]
assert "border-radius: var(--border-radius-sm);" in popover_css
+def test_launcher_gateway_disconnect_becomes_reconnect_through_the_launcher_bridge() -> None:
+ source = (
+ Path(__file__).parents[1]
+ / "plugins"
+ / "_a0_connector"
+ / "webui"
+ / "launcher-gateway-store.js"
+ ).read_text(encoding="utf-8")
+ assert "window.a0LauncherHost?.getState?.()" in source
+ assert "window.a0LauncherHost?.reconnect?.()" in source
+ assert 'typeof window.a0LauncherHost?.reconnect === "function"' in source
+ assert 'state: "disconnected", connected: false, gateway: null' in source
+ assert 'state: "connecting", connected: false, gateway: null' in source
+
+
def test_launcher_gateway_is_fallback_after_context_bound_cli() -> None:
context_id = f"ctx-{uuid.uuid4()}"
cli_sid = _sid("cli")