From 4c096020a2d2a7c3f97aa17d0eef50c1e7ae3722 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 18 Feb 2026 18:37:17 +0000 Subject: [PATCH] refactor(commands): share configure wizard channel/daemon steps --- src/commands/configure.wizard.ts | 73 ++++++++++++++------------------ 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/src/commands/configure.wizard.ts b/src/commands/configure.wizard.ts index fd00144f5..e96983461 100644 --- a/src/commands/configure.wizard.ts +++ b/src/commands/configure.wizard.ts @@ -345,6 +345,33 @@ export async function runConfigureWizard( await ensureWorkspaceAndSessions(workspaceDir, runtime); }; + const configureChannelsSection = async () => { + await noteChannelStatus({ cfg: nextConfig, prompter }); + const channelMode = await promptChannelMode(runtime); + if (channelMode === "configure") { + nextConfig = await setupChannels(nextConfig, runtime, prompter, { + allowDisable: true, + allowSignalInstall: true, + skipConfirm: true, + skipStatusNote: true, + }); + } else { + nextConfig = await removeChannelConfigWizard(nextConfig, runtime); + } + }; + + const promptDaemonPort = async () => { + const portInput = guardCancel( + await text({ + message: "Gateway port for service install", + initialValue: String(gatewayPort), + validate: (value) => (Number.isFinite(Number(value)) ? undefined : "Invalid port"), + }), + runtime, + ); + gatewayPort = Number.parseInt(String(portInput), 10); + }; + if (opts.sections) { const selected = opts.sections; if (!selected || selected.length === 0) { @@ -372,18 +399,7 @@ export async function runConfigureWizard( } if (selected.includes("channels")) { - await noteChannelStatus({ cfg: nextConfig, prompter }); - const channelMode = await promptChannelMode(runtime); - if (channelMode === "configure") { - nextConfig = await setupChannels(nextConfig, runtime, prompter, { - allowDisable: true, - allowSignalInstall: true, - skipConfirm: true, - skipStatusNote: true, - }); - } else { - nextConfig = await removeChannelConfigWizard(nextConfig, runtime); - } + await configureChannelsSection(); } if (selected.includes("skills")) { @@ -395,15 +411,7 @@ export async function runConfigureWizard( if (selected.includes("daemon")) { if (!selected.includes("gateway")) { - const portInput = guardCancel( - await text({ - message: "Gateway port for service install", - initialValue: String(gatewayPort), - validate: (value) => (Number.isFinite(Number(value)) ? undefined : "Invalid port"), - }), - runtime, - ); - gatewayPort = Number.parseInt(String(portInput), 10); + await promptDaemonPort(); } await maybeInstallDaemon({ runtime, port: gatewayPort, gatewayToken }); @@ -448,18 +456,7 @@ export async function runConfigureWizard( } if (choice === "channels") { - await noteChannelStatus({ cfg: nextConfig, prompter }); - const channelMode = await promptChannelMode(runtime); - if (channelMode === "configure") { - nextConfig = await setupChannels(nextConfig, runtime, prompter, { - allowDisable: true, - allowSignalInstall: true, - skipConfirm: true, - skipStatusNote: true, - }); - } else { - nextConfig = await removeChannelConfigWizard(nextConfig, runtime); - } + await configureChannelsSection(); await persistConfig(); } @@ -471,15 +468,7 @@ export async function runConfigureWizard( if (choice === "daemon") { if (!didConfigureGateway) { - const portInput = guardCancel( - await text({ - message: "Gateway port for service install", - initialValue: String(gatewayPort), - validate: (value) => (Number.isFinite(Number(value)) ? undefined : "Invalid port"), - }), - runtime, - ); - gatewayPort = Number.parseInt(String(portInput), 10); + await promptDaemonPort(); } await maybeInstallDaemon({ runtime,