Implementation:Promptfoo Promptfoo CLI State
| Knowledge Sources | |
|---|---|
| Domains | CLI, State_Management |
| Last Updated | 2026-02-14 07:45 GMT |
Overview
Concrete shared mutable state object that tracks CLI runtime context including base path, configuration, resume mode, logging paths, and concurrency settings.
Description
The CLI_State module (cliState.ts) exports a single mutable state object of type CliState that serves as the cross-cutting runtime context for CLI operations. Properties include basePath (working directory), config (partial unified config), remote (force remote inference), webUI (web UI mode flag), resume and retryMode (evaluation resumption), debugLogFile/errorLogFile (log paths), and maxConcurrency (from the -j CLI flag).
Usage
Import this module to read or set CLI-wide state that needs to be shared across modules without prop drilling. It is set by the CLI command handlers and read by providers, evaluators, and other core modules.
Code Reference
Source Location
- Repository: Promptfoo_Promptfoo
- File: src/cliState.ts
- Lines: 1-52
Signature
interface CliState {
basePath?: string;
config?: Partial<UnifiedConfig>;
remote?: boolean;
webUI?: boolean;
resume?: boolean;
retryMode?: boolean;
_retryErrorResultIds?: string[];
debugLogFile?: string;
errorLogFile?: string;
postActionCallback?: () => Promise<void>;
maxConcurrency?: number;
}
declare const state: CliState;
export default state;
Import
import cliState from './cliState';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (property assignment) | various | No | Set properties directly on the state object |
Outputs
| Name | Type | Description |
|---|---|---|
| state | CliState | Mutable singleton state object |
Usage Examples
import cliState from './cliState';
// Set base path from CLI
cliState.basePath = '/path/to/project';
// Check if running in web UI mode
if (cliState.webUI) {
// Adjust behavior for web UI
}
// Read max concurrency setting
const concurrency = cliState.maxConcurrency ?? 4;