From c1ad0e87542017d4e32e30f4fd3080414820435d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 05:35:11 +0000 Subject: [PATCH] refactor(cli): dedupe browser tab listing output --- src/cli/browser-cli-manage.ts | 48 +++++++++++++---------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/cli/browser-cli-manage.ts b/src/cli/browser-cli-manage.ts index ef5ba9eac8..600d7ac2b4 100644 --- a/src/cli/browser-cli-manage.ts +++ b/src/cli/browser-cli-manage.ts @@ -59,6 +59,22 @@ function runBrowserCommand(action: () => Promise) { }); } +function logBrowserTabs(tabs: BrowserTab[], json?: boolean) { + if (json) { + defaultRuntime.log(JSON.stringify({ tabs }, null, 2)); + return; + } + if (tabs.length === 0) { + defaultRuntime.log("No tabs (browser closed or no targets)."); + return; + } + defaultRuntime.log( + tabs + .map((t, i) => `${i + 1}. ${t.title || "(untitled)"}\n ${t.url}\n id: ${t.targetId}`) + .join("\n"), + ); +} + export function registerBrowserManageCommands( browser: Command, parentOpts: (cmd: Command) => BrowserParentOpts, @@ -161,21 +177,7 @@ export function registerBrowserManageCommands( { timeoutMs: 3000 }, ); const tabs = result.tabs ?? []; - if (parent?.json) { - defaultRuntime.log(JSON.stringify({ tabs }, null, 2)); - return; - } - if (tabs.length === 0) { - defaultRuntime.log("No tabs (browser closed or no targets)."); - return; - } - defaultRuntime.log( - tabs - .map( - (t, i) => `${i + 1}. ${t.title || "(untitled)"}\n ${t.url}\n id: ${t.targetId}`, - ) - .join("\n"), - ); + logBrowserTabs(tabs, parent?.json); }); }); @@ -199,21 +201,7 @@ export function registerBrowserManageCommands( { timeoutMs: 10_000 }, ); const tabs = result.tabs ?? []; - if (parent?.json) { - defaultRuntime.log(JSON.stringify({ tabs }, null, 2)); - return; - } - if (tabs.length === 0) { - defaultRuntime.log("No tabs (browser closed or no targets)."); - return; - } - defaultRuntime.log( - tabs - .map( - (t, i) => `${i + 1}. ${t.title || "(untitled)"}\n ${t.url}\n id: ${t.targetId}`, - ) - .join("\n"), - ); + logBrowserTabs(tabs, parent?.json); }); });