Implementation:Openclaw Openclaw Globals CLI State
| Knowledge Sources | |
|---|---|
| Domains | CLI, Logging, Configuration |
| Last Updated | 2026-02-06 12:00 GMT |
Overview
Global verbose/yes flag accessors and themed console output helpers that provide shared CLI state across the OpenClaw codebase.
Description
The globals.ts module exports getter/setter pairs for two global CLI flags: verbose mode (controls debug-level logging) and yes mode (auto-confirms interactive prompts). It also re-exports themed console formatters (success, warn, info, danger) from the terminal theme module. The verbose logging functions integrate with both the structured file logger and themed console output.
Usage
Import these functions in any CLI command or subsystem that needs to check or set global verbosity or auto-confirm state. The `logVerbose` function is the standard way to emit debug-level output that respects the `--verbose` flag.
Code Reference
Source Location
- Repository: Openclaw_Openclaw
- File: src/globals.ts
- Lines: 1-52
Signature
export function setVerbose(v: boolean): void
// Sets the global verbose flag.
export function isVerbose(): boolean
// Returns the current verbose flag value.
export function shouldLogVerbose(): boolean
// Returns true if verbose flag is set OR file log level includes 'debug'.
export function logVerbose(message: string): void
// Logs to the structured file logger (debug level) if shouldLogVerbose(),
// and to themed console output if globalVerbose is true.
export function logVerboseConsole(message: string): void
// Logs to themed console output only if globalVerbose is true.
// Skips the file logger (useful for console-only debug output).
export function setYes(v: boolean): void
// Sets the global auto-confirm (yes) flag.
export function isYes(): boolean
// Returns the current auto-confirm flag value.
export const success: (text: string) => string
// Themed console formatter for success messages (green).
export const warn: (text: string) => string
// Themed console formatter for warning messages (yellow).
export const info: (text: string) => string
// Themed console formatter for info messages (blue).
export const danger: (text: string) => string
// Themed console formatter for error/danger messages (red).
Import
import { setVerbose, isVerbose, logVerbose, setYes, isYes, success, warn, info, danger } from "./globals.js";
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| v (setVerbose) | boolean | Yes | Enable or disable verbose mode |
| v (setYes) | boolean | Yes | Enable or disable auto-confirm mode |
| message (logVerbose) | string | Yes | Debug message to log |
Outputs
| Name | Type | Description |
|---|---|---|
| isVerbose() | boolean | Current verbose flag state |
| isYes() | boolean | Current auto-confirm flag state |
| shouldLogVerbose() | boolean | Whether verbose logging is active (flag or file log level) |
| logVerbose() | void | Writes to file logger (debug) and console (themed muted) |
| success/warn/info/danger | (text: string) => string | Themed string formatters from terminal theme |
Usage Examples
Setting Verbose Mode from CLI
import { setVerbose, logVerbose, isVerbose } from "./globals.js";
// CLI parser sets verbose from --verbose flag
setVerbose(true);
// Throughout the codebase, emit debug output:
logVerbose("Loading configuration from ~/.openclaw/config.yaml");
// Check verbose state for conditional logic:
if (isVerbose()) {
console.log("Full config dump:", JSON.stringify(config, null, 2));
}
Auto-Confirm Mode
import { setYes, isYes } from "./globals.js";
// CLI parser sets yes from --yes flag
setYes(true);
// In interactive prompts, skip confirmation:
if (isYes()) {
// Proceed without asking
} else {
const confirmed = await prompt("Continue? (y/n)");
if (confirmed !== "y") return;
}
Themed Console Output
import { success, warn, danger } from "./globals.js";
console.log(success("Channel connected successfully"));
console.log(warn("Config file not found, using defaults"));
console.log(danger("Failed to reach gateway"));