Files
openclaw/src/cli/tui-cli.ts
Peter Steinberger 96f0983a85 fix(onboarding): skip setup for configured gateways and require inference first (#102883)
* fix(crestodian): keep onboarding RPCs restart-safe

* fix(profiles): isolate approval state migrations

* fix(crestodian): bypass configured gateway setup

* test(crestodian): type onboarding mocks

* fix(onboarding): require inference before Crestodian

* fix(onboarding): enforce verified inference handoff

* fix(macos): reset setup on gateway endpoint edits

* chore(i18n): refresh native source inventory

* fix(gateway): keep socket on request cancellation

* test(packaging): require workspace templates

* fix(onboarding): bind setup to verified inference

* fix(onboarding): align inference gate contracts

* fix(crestodian): classify concurrent policy rejection

* test(crestodian): expect registry restoration

* fix(onboarding): bind setup to configured gateways

* fix(codex): preserve startup phase deadlines

* test(crestodian): match fail-closed policy ordering

* test(onboarding): assert bound gateway handoff

* fix(codex): bind runtime resolution to spawn cwd

* test(crestodian): assert policy rejection order

* fix(cli): preserve gateway routing across restarts

* fix(macos): fail closed during gateway edits

* test(macos): cover gateway route generation races

* chore: keep release notes out of onboarding PR

* fix(ci): refresh onboarding generated checks

* style(swift): align gateway channel formatting

* fix(ci): refresh plugin SDK surface budgets

* fix(ci): resync native string inventory

* refactor(swift): split gateway channel support

* test(doctor): isolate plugin compatibility registry

* test(macos): isolate gateway onboarding fixtures

* test(macos): assert gateway lease health ordering

* fix(codex): reconcile computer-use startup changes
2026-07-11 10:25:14 -07:00

75 lines
3.6 KiB
TypeScript

// Registers the terminal UI subcommand and normalizes its local-vs-gateway options.
import type { Command } from "commander";
import { formatDocsLink } from "../../packages/terminal-core/src/links.js";
import { theme } from "../../packages/terminal-core/src/theme.js";
import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js";
import { defaultRuntime } from "../runtime.js";
import { parseTimeoutMs } from "./parse-timeout.js";
/** Attach the `tui` command plus its `terminal`/`chat` aliases to the root CLI. */
export function registerTuiCli(program: Command) {
program
.command("tui")
.alias("terminal")
.alias("chat")
.description("Open a terminal UI connected to the Gateway")
.option("--local", "Run against the local embedded agent runtime", false)
.option("--url <url>", "Gateway WebSocket URL (defaults to gateway.remote.url when configured)")
.option("--token <token>", "Gateway token (if required)")
.option("--password <password>", "Gateway password (if required)")
.option("--tls-fingerprint <sha256>", "Expected Gateway TLS certificate fingerprint")
.option("--session <key>", 'Session key (default: "main", or "global" when scope is global)')
.option("--deliver", "Deliver assistant replies", false)
.option("--thinking <level>", "Thinking level override")
.option("--message <text>", "Send an initial message after connecting")
.option("--timeout-ms <ms>", "Agent timeout in ms (defaults to agents.defaults.timeoutSeconds)")
.option("--history-limit <n>", "History entries to load", "200")
.addHelpText(
"after",
() => `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/tui", "docs.openclaw.ai/cli/tui")}\n`,
)
.action(async (opts, cmd) => {
try {
// `cmd.name()` always returns the canonical subcommand name (`tui`).
// Use the parsed parent args to see which alias the user actually typed.
const invokedSubcommand = cmd.parent?.args[0];
const invokedAsLocalAlias =
invokedSubcommand === "terminal" || invokedSubcommand === "chat";
const isLocal = Boolean(opts.local) || invokedAsLocalAlias;
if (isLocal && (opts.url || opts.token || opts.password || opts.tlsFingerprint)) {
throw new Error(
"--local cannot be combined with --url, --token, --password, or --tls-fingerprint",
);
}
const timeoutMs = parseTimeoutMs(opts.timeoutMs);
if (opts.timeoutMs !== undefined && timeoutMs === undefined) {
defaultRuntime.error(
`warning: invalid --timeout-ms "${String(opts.timeoutMs)}"; ignoring`,
);
}
const historyLimit = parseStrictPositiveInteger(opts.historyLimit ?? "200");
if (historyLimit === undefined) {
throw new Error("--history-limit must be a positive integer.");
}
const { runTui } = await import("../tui/tui.js");
await runTui({
local: isLocal,
url: opts.url as string | undefined,
token: opts.token as string | undefined,
password: opts.password as string | undefined,
tlsFingerprint: opts.tlsFingerprint as string | undefined,
session: opts.session as string | undefined,
deliver: Boolean(opts.deliver),
thinking: opts.thinking as string | undefined,
message: opts.message as string | undefined,
timeoutMs,
historyLimit,
forceProcessExitOnReturn: true,
});
} catch (err) {
defaultRuntime.error(String(err));
defaultRuntime.exit(1);
}
});
}