Files
openclaw/src/cli/tui-cli.ts
T
fuller-stack-devandAyaan Zaidi 276c00015c fix: add local embedded TUI mode (#66767) (thanks @fuller-stack-dev)
* feat(tui): add local embedded TUI mode with terminal/chat aliases

Adds a gateway-free local TUI path so users can run openclaw in their
terminal without needing a running gateway process.

- TuiBackend interface abstraction (tui-backend.ts) with EmbeddedTuiBackend
  implementation that drives the agent loop in-process
- openclaw tui --local flag for local embedded mode
- openclaw terminal / openclaw chat aliases that imply --local
- /auth slash command with codex CLI delegation to avoid prolite plan issue
- Default model display fallback on startup
- Local-aware status text and log suppression
- Concise auth error hints, raw HTML 403 suppression
- Onboarding hatch flow launches local TUI (no gateway required)
- Commander alias bug fix in run-main.ts (.aliases() check)
- All new and updated tests passing (145/145)

* TUI: fix alias detection, cross-platform codex lookup, and history byte-budget safeguards

* TUI: remove RuntimeEnv type annotation to fix CI oxlint error

* TUI: filter gateway-dependent tools and auto-approve plugin hooks in embedded mode

* TUI: suppress console noise and add embedded mode system prompt note

* TUI: reduce embedded-mode tool filtering from 15 to 7, add local session tools

* TUI: fix remaining PR review comments

* TUI: address latest review feedback and CI drift

* Core: align prompt helper with latest base

* Core: match prompt helper formatting with base

* Core: restore prompt helper from latest base

* fix(tui): preserve local auth fallback in source checkouts

* fix(tts): guard telephony provider invocation

* fix(tui): support Windows codex auth shim

* fix(tui): harden local auth flow

* fix: preserve embedded tool-first run events

* fix(tui): keep embedded plugin approvals gated

* fix(tui): restore embedded attempt import

* fix(tui): resolve sessions in embedded stub

* fix: add embedded TUI changelog entry (#66767) (thanks @fuller-stack-dev)

* fix: pass setup TUI local mode through relaunch (#66767) (thanks @fuller-stack-dev)

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-04-22 10:08:57 +05:30

64 lines
2.9 KiB
TypeScript

import type { Command } from "commander";
import { defaultRuntime } from "../runtime.js";
import { formatDocsLink } from "../terminal/links.js";
import { theme } from "../terminal/theme.js";
import { runTui } from "../tui/tui.js";
import { parseTimeoutMs } from "./parse-timeout.js";
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("--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)) {
throw new Error("--local cannot be combined with --url, --token, or --password");
}
const timeoutMs = parseTimeoutMs(opts.timeoutMs);
if (opts.timeoutMs !== undefined && timeoutMs === undefined) {
defaultRuntime.error(
`warning: invalid --timeout-ms "${String(opts.timeoutMs)}"; ignoring`,
);
}
const historyLimit = Number.parseInt(String(opts.historyLimit ?? "200"), 10);
await runTui({
local: isLocal,
url: opts.url as string | undefined,
token: opts.token as string | undefined,
password: opts.password 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: Number.isNaN(historyLimit) ? undefined : historyLimit,
});
} catch (err) {
defaultRuntime.error(String(err));
defaultRuntime.exit(1);
}
});
}