Skip to content

Commit 3d84147

Browse files
authored
fix(cli): align configure and channel wizard behavior (#111720)
1 parent f06b6be commit 3d84147

11 files changed

Lines changed: 195 additions & 18 deletions

‎docs/cli/channels.md‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ Non-interactive add flags shared across channels: `--account <id>`, `--name <nam
100100

101101
If a channel plugin needs to be installed during a flag-driven add command, OpenClaw uses the channel's default install source without opening the interactive plugin install prompt.
102102

103-
When you run `openclaw channels add` without flags, the interactive wizard can prompt:
103+
When you run `openclaw channels add` with no direct account, credential, or channel-config flags, the interactive wizard can prompt. A positional channel id and `--channel <id>` both preselect that channel without bypassing guidance:
104+
105+
```bash
106+
openclaw channels add telegram
107+
openclaw channels add --channel telegram
108+
```
109+
110+
The wizard can prompt for:
104111

105112
- account ids per selected channel
106113
- optional display names for those accounts

‎docs/cli/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Setup commands by intent:
1515
- `openclaw setup` and `openclaw onboard` verify inference first, then start OpenClaw for Gateway, workspace, channels, skills, and health setup.
1616
- `openclaw setup --baseline` creates the baseline config and workspace without walking the guided onboarding flow.
1717
- `openclaw configure` changes targeted parts of an existing setup: model auth, gateway, channels, plugins, or skills.
18-
- `openclaw channels add` configures channel accounts after the baseline exists; run without flags for guided setup, or with channel-specific flags for scripts.
18+
- `openclaw channels add` configures channel accounts after the baseline exists; a channel selection alone uses guided setup, while account, credential, or channel-config flags use the direct path for scripts.
1919

2020
## Command pages
2121

‎src/cli/channels-cli.test.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ import { registerChannelsCli } from "./channels-cli.js";
88
const listBundledPackageChannelMetadataMock = vi.hoisted(() =>
99
vi.fn<() => readonly PluginPackageChannel[]>(() => []),
1010
);
11+
const channelsAddCommandMock = vi.hoisted(() => vi.fn(async () => undefined));
12+
const runtimeMock = vi.hoisted(() => ({
13+
log: vi.fn(),
14+
error: vi.fn(),
15+
exit: vi.fn(),
16+
}));
1117

1218
vi.mock("../plugins/bundled-package-channel-metadata.js", () => ({
1319
listBundledPackageChannelMetadata: listBundledPackageChannelMetadataMock,
1420
}));
1521

22+
vi.mock("../commands/channels.js", () => ({
23+
channelsAddCommand: channelsAddCommandMock,
24+
}));
25+
26+
vi.mock("../runtime.js", () => ({
27+
defaultRuntime: runtimeMock,
28+
}));
29+
1630
function getChannelAddOptionFlags(program: Command): string[] {
1731
const channels = program.commands.find((command) => command.name() === "channels");
1832
const add = channels?.commands.find((command) => command.name() === "add");
@@ -25,6 +39,12 @@ function getChannelSubcommandNames(program: Command, parentName: string): string
2539
return parent?.commands.map((command) => command.name()) ?? [];
2640
}
2741

42+
async function runChannelsAddCli(args: string[]) {
43+
const program = new Command().name("openclaw");
44+
await registerChannelsCli(program, ["node", "openclaw", ...args]);
45+
await program.parseAsync(args, { from: "user" });
46+
}
47+
2848
describe("registerChannelsCli", () => {
2949
const originalArgv = [...process.argv];
3050

@@ -135,4 +155,56 @@ describe("registerChannelsCli", () => {
135155
expect(listBundledPackageChannelMetadataMock).toHaveBeenCalledTimes(1);
136156
expect(getChannelAddOptionFlags(program)).toContain("--homeserver <url>");
137157
});
158+
159+
it.each([
160+
["positional", ["channels", "add", "telegram"]],
161+
["--channel", ["channels", "add", "--channel", "telegram"]],
162+
])("keeps selection-only %s channel adds on the guided path", async (_label, args) => {
163+
await runChannelsAddCli(args);
164+
165+
expect(channelsAddCommandMock).toHaveBeenCalledWith(
166+
expect.objectContaining({ channel: "telegram" }),
167+
runtimeMock,
168+
{ hasFlags: false },
169+
);
170+
});
171+
172+
it.each([
173+
["token", ["--token", "test-token"]],
174+
["token file", ["--token-file", "/tmp/test-token"]],
175+
["environment", ["--use-env"]],
176+
["account", ["--account", "work"]],
177+
])("keeps explicit %s inputs on the direct path", async (_label, extraArgs) => {
178+
await runChannelsAddCli(["channels", "add", "--channel", "telegram", ...extraArgs]);
179+
180+
expect(channelsAddCommandMock).toHaveBeenCalledWith(
181+
expect.objectContaining({ channel: "telegram" }),
182+
runtimeMock,
183+
{ hasFlags: true },
184+
);
185+
});
186+
187+
it("treats plugin-provided config flags as direct automation inputs", async () => {
188+
listBundledPackageChannelMetadataMock.mockReturnValueOnce([
189+
{
190+
id: "matrix",
191+
cliAddOptions: [{ flags: "--homeserver <url>", description: "Matrix homeserver URL" }],
192+
},
193+
]);
194+
195+
await runChannelsAddCli([
196+
"channels",
197+
"add",
198+
"--channel",
199+
"matrix",
200+
"--homeserver",
201+
"https://matrix.example.org",
202+
]);
203+
204+
expect(channelsAddCommandMock).toHaveBeenCalledWith(
205+
expect.objectContaining({ channel: "matrix", homeserver: "https://matrix.example.org" }),
206+
runtimeMock,
207+
{ hasFlags: true },
208+
);
209+
});
138210
});

‎src/cli/channels-cli.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type BundledPackageChannelMetadataModule =
1919
typeof import("../plugins/bundled-package-channel-metadata.js");
2020

2121
const optionNamesRemove = ["channel", "account", "delete"] as const;
22+
const CHANNEL_ADD_SELECTION_OPTION_NAMES = new Set(["channel"]);
2223

2324
type RegisterChannelsCliOptions = {
2425
includeSetupOptions?: boolean;
@@ -282,7 +283,10 @@ export async function registerChannelsCli(
282283
addCommand.action(async (channelArg: string | undefined, opts, command) => {
283284
await runChannelsCommand(async () => {
284285
const { channelsAddCommand } = await loadChannelsCommands();
285-
const hasFlags = hasExplicitOptions(command, getOptionNames(command));
286+
const hasFlags = hasExplicitOptions(
287+
command,
288+
getOptionNames(command).filter((name) => !CHANNEL_ADD_SELECTION_OPTION_NAMES.has(name)),
289+
);
286290
await channelsAddCommand(resolveChannelsAddOptions(channelArg, opts), defaultRuntime, {
287291
hasFlags,
288292
});

‎src/commands/configure.channels.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export async function removeChannelConfigWizard(
100100
options,
101101
}),
102102
runtime,
103+
1,
103104
);
104105

105106
if (choice.kind === "done") {
@@ -114,6 +115,7 @@ export async function removeChannelConfigWizard(
114115
initialValue: false,
115116
}),
116117
runtime,
118+
1,
117119
);
118120
if (!confirmed) {
119121
continue;

‎src/commands/configure.commands.test.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,21 @@ describe("configureCommandFromSectionsArg", () => {
8383
);
8484
});
8585

86-
it("fails closed for a mixed valid/invalid section list on a non-interactive terminal", async () => {
86+
it("rejects a lone invalid section before unrestricted wizard dispatch", async () => {
87+
const runtime = makeRuntime();
88+
89+
await expect(
90+
configureCommandFromSectionsArg(["bogus"], runtime, { interactive: true }),
91+
).rejects.toThrow("exit 1");
92+
93+
expect(runtime.exit).toHaveBeenCalledWith(1);
94+
expect(runtime.error.mock.calls[0]?.[0]).toBe(
95+
"Invalid --section: bogus. Expected one of: workspace, model, web, gateway, daemon, channels, plugins, skills, health. Run openclaw configure without --section to use the full wizard.",
96+
);
97+
expect(runConfigureWizardMock).not.toHaveBeenCalled();
98+
});
99+
100+
it("validates invalid sections before the interactive-terminal guard", async () => {
87101
const runtime = makeRuntime();
88102

89103
await expect(
@@ -92,9 +106,8 @@ describe("configureCommandFromSectionsArg", () => {
92106
}),
93107
).rejects.toThrow("exit 1");
94108

95-
// Non-TTY guard fires before any section validation, so the wizard never runs.
96109
expect(runtime.exit).toHaveBeenCalledWith(1);
97-
expect(runtime.error.mock.calls[0]?.[0]).toContain("interactive terminal (TTY)");
110+
expect(runtime.error.mock.calls[0]?.[0]).toContain("Invalid --section: bogus");
98111
expect(runConfigureWizardMock).not.toHaveBeenCalled();
99112
});
100113
});

‎src/commands/configure.commands.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ export async function configureCommandFromSectionsArg(
6060
runtime: RuntimeEnv = defaultRuntime,
6161
options?: { interactive?: boolean },
6262
): Promise<void> {
63+
const { sections, invalid } = parseConfigureWizardSections(rawSections);
64+
if (invalid.length > 0) {
65+
runtime.error(
66+
`Invalid --section: ${invalid.join(", ")}. Expected one of: ${CONFIGURE_WIZARD_SECTIONS.join(", ")}. Run ${formatCliCommand("openclaw configure")} without --section to use the full wizard.`,
67+
);
68+
runtime.exit(1);
69+
return;
70+
}
71+
6372
// Fail closed once at the shared entry: both `openclaw configure` and the
6473
// no-subcommand `openclaw config` route here, so a single guard keeps them
6574
// consistent instead of partially entering the wizard on a non-TTY pipe.
@@ -69,19 +78,10 @@ export async function configureCommandFromSectionsArg(
6978
return;
7079
}
7180

72-
const { sections, invalid } = parseConfigureWizardSections(rawSections);
7381
if (sections.length === 0) {
7482
await configureCommand(runtime);
7583
return;
7684
}
7785

78-
if (invalid.length > 0) {
79-
runtime.error(
80-
`Invalid --section: ${invalid.join(", ")}. Expected one of: ${CONFIGURE_WIZARD_SECTIONS.join(", ")}. Run ${formatCliCommand("openclaw configure")} without --section to use the full wizard.`,
81-
);
82-
runtime.exit(1);
83-
return;
84-
}
85-
8686
await configureCommandWithSections(sections as never, runtime);
8787
}

‎src/commands/configure.daemon.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export async function maybeInstallDaemon(params: {
4747
],
4848
}),
4949
params.runtime,
50+
1,
5051
);
5152
if (action === "restart") {
5253
await withProgress(
@@ -93,6 +94,7 @@ export async function maybeInstallDaemon(params: {
9394
initialValue: DEFAULT_GATEWAY_DAEMON_RUNTIME,
9495
}),
9596
params.runtime,
97+
1,
9698
) as GatewayDaemonRuntime;
9799
}
98100
}
@@ -156,7 +158,7 @@ export async function maybeInstallDaemon(params: {
156158
await ensureSystemdUserLingerInteractive({
157159
runtime: params.runtime,
158160
prompter: {
159-
confirm: async (p) => guardCancel(await confirm(p), params.runtime),
161+
confirm: async (p) => guardCancel(await confirm(p), params.runtime, 1),
160162
note,
161163
},
162164
reason:

‎src/commands/configure.gateway.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export async function promptGatewayConfig(
5555
validate: validateGatewayPortInput,
5656
}),
5757
runtime,
58+
1,
5859
);
5960
const port = parsePort(portRaw) ?? resolveGatewayPort(cfg);
6061

@@ -90,6 +91,7 @@ export async function promptGatewayConfig(
9091
],
9192
}),
9293
runtime,
94+
1,
9395
);
9496

9597
let customBindHost: string | undefined;
@@ -101,6 +103,7 @@ export async function promptGatewayConfig(
101103
validate: validateDottedDecimalIPv4Input,
102104
}),
103105
runtime,
106+
1,
104107
);
105108
customBindHost = readStringValue(input);
106109
}
@@ -120,6 +123,7 @@ export async function promptGatewayConfig(
120123
initialValue: "token",
121124
}),
122125
runtime,
126+
1,
123127
) as GatewayAuthChoice;
124128

125129
let tailscaleMode = guardCancel(
@@ -128,6 +132,7 @@ export async function promptGatewayConfig(
128132
options: [...TAILSCALE_EXPOSURE_OPTIONS],
129133
}),
130134
runtime,
135+
1,
131136
);
132137

133138
// Detect Tailscale binary before proceeding with serve/funnel setup.
@@ -149,6 +154,7 @@ export async function promptGatewayConfig(
149154
initialValue: false,
150155
}),
151156
runtime,
157+
1,
152158
);
153159
}
154160

@@ -201,6 +207,7 @@ export async function promptGatewayConfig(
201207
initialValue: "plaintext",
202208
}),
203209
runtime,
210+
1,
204211
);
205212
if (tokenInputMode === "ref") {
206213
const envVar = guardCancel(
@@ -221,6 +228,7 @@ export async function promptGatewayConfig(
221228
},
222229
}),
223230
runtime,
231+
1,
224232
);
225233
const envVarName = normalizeOptionalString(envVar) ?? "";
226234
gatewayToken = {
@@ -237,6 +245,7 @@ export async function promptGatewayConfig(
237245
message: "Gateway token (blank to generate)",
238246
}),
239247
runtime,
248+
1,
240249
);
241250
gatewayTokenForCalls = normalizeGatewayTokenInput(tokenInput) || randomToken();
242251
gatewayToken = gatewayTokenForCalls;
@@ -250,6 +259,7 @@ export async function promptGatewayConfig(
250259
validate: validateGatewayPasswordInput,
251260
}),
252261
runtime,
262+
1,
253263
);
254264
gatewayPassword = normalizeOptionalString(passwordInput) ?? "";
255265
}
@@ -275,6 +285,7 @@ export async function promptGatewayConfig(
275285
validate: (value) => (value?.trim() ? undefined : "User header is required"),
276286
}),
277287
runtime,
288+
1,
278289
);
279290

280291
const requiredHeadersRaw = guardCancel(
@@ -283,6 +294,7 @@ export async function promptGatewayConfig(
283294
placeholder: "x-forwarded-proto,x-forwarded-host",
284295
}),
285296
runtime,
297+
1,
286298
);
287299
const requiredHeaders = requiredHeadersRaw
288300
? normalizeStringEntries(requiredHeadersRaw.split(","))
@@ -294,6 +306,7 @@ export async function promptGatewayConfig(
294306
295307
}),
296308
runtime,
309+
1,
297310
);
298311
const allowUsers = allowUsersRaw ? normalizeStringEntries(allowUsersRaw.split(",")) : [];
299312

@@ -309,6 +322,7 @@ export async function promptGatewayConfig(
309322
},
310323
}),
311324
runtime,
325+
1,
312326
);
313327
trustedProxies = normalizeStringEntries(trustedProxiesRaw.split(","));
314328

0 commit comments

Comments
 (0)