diff --git a/src/lib/debug.ts b/src/lib/debug.ts index 19bb7d64e3e..aa898cf443f 100644 --- a/src/lib/debug.ts +++ b/src/lib/debug.ts @@ -7,6 +7,7 @@ import { platform, tmpdir } from "node:os"; import { basename, dirname, join } from "node:path"; import { DASHBOARD_PORT } from "./ports"; +import { listSandboxes } from "./registry"; // --------------------------------------------------------------------------- // Types @@ -141,6 +142,22 @@ function collectShell(collectDir: string, label: string, shellCmd: string): void // --------------------------------------------------------------------------- function detectSandboxName(): string { + // First, check the local registry for the default sandbox. This is + // the authoritative source — it reflects the user's actual onboard + // choices and survives gateway restarts. Falling back to "default" + // without checking the registry was the bug in #1728: debug always + // targeted a sandbox named "default" even though the user's sandbox + // was named something else (e.g. "my-assistant"). + try { + const registry = listSandboxes(); + if (registry.defaultSandbox) return registry.defaultSandbox; + const names = registry.sandboxes.map((s) => s.name).filter(Boolean); + if (names.length > 0) return names[0]; + } catch { + /* registry unreadable — fall through to openshell probe */ + } + + // Fallback: ask the live gateway directly if (!commandExists("openshell")) return "default"; try { const output = execFileSync("openshell", ["sandbox", "list"], {