refactor(commands): split CLI commands

This commit is contained in:
Peter Steinberger
2026-01-14 05:39:47 +00:00
parent 2b60ee96f2
commit a58ff1ac63
74 changed files with 7995 additions and 7806 deletions

View File

@@ -0,0 +1,76 @@
import { listChatChannels } from "../channels/registry.js";
import type { ClawdbotConfig } from "../config/config.js";
import { CONFIG_PATH_CLAWDBOT } from "../config/config.js";
import type { RuntimeEnv } from "../runtime.js";
import { note } from "../terminal/note.js";
import { confirm, select } from "./configure.shared.js";
import { guardCancel } from "./onboard-helpers.js";
export async function removeChannelConfigWizard(
cfg: ClawdbotConfig,
runtime: RuntimeEnv,
): Promise<ClawdbotConfig> {
let next = { ...cfg };
const listConfiguredChannels = () =>
listChatChannels().filter((meta) => next.channels?.[meta.id] !== undefined);
while (true) {
const configured = listConfiguredChannels();
if (configured.length === 0) {
note(
[
"No channel config found in clawdbot.json.",
"Tip: `clawdbot channels status` shows what is configured and enabled.",
].join("\n"),
"Remove channel",
);
return next;
}
const channel = guardCancel(
await select({
message: "Remove which channel config?",
options: [
...configured.map((meta) => ({
value: meta.id,
label: meta.label,
hint: "Deletes tokens + settings from config (credentials stay on disk)",
})),
{ value: "done", label: "Done" },
],
}),
runtime,
) as string;
if (channel === "done") return next;
const label =
listChatChannels().find((meta) => meta.id === channel)?.label ?? channel;
const confirmed = guardCancel(
await confirm({
message: `Delete ${label} configuration from ${CONFIG_PATH_CLAWDBOT}?`,
initialValue: false,
}),
runtime,
);
if (!confirmed) continue;
const nextChannels: Record<string, unknown> = { ...next.channels };
delete nextChannels[channel];
next = {
...next,
channels: Object.keys(nextChannels).length
? (nextChannels as ClawdbotConfig["channels"])
: undefined,
};
note(
[
`${label} removed from config.`,
"Note: credentials/sessions on disk are unchanged.",
].join("\n"),
"Channel removed",
);
}
}