Add configuration support for TUI input presets (#54379)

## What changed

Add `tui.presets` entries keyed by a single digit from `0` to `9`, each with an `input` prompt or slash command and an optional `label`. Expose presets in the configuration schema, load them into runtime configuration, and preserve them in TUI local settings.

Reject invalid slots, blank inputs, shell commands beginning with `!` after leading whitespace, and inputs exceeding 8,000 UTF-8 bytes.

## Testing

Extend the runtime configuration test to verify loading both a slash command with a label and a prompt without one.

GitOrigin-RevId: d2911e540bc50f05b4a5224abf17ce4ef5a18ea3
This commit is contained in:
Felipe Coury
2026-10-15 19:01:43 +00:00
committed by copyberry
parent 0884c8047a
commit 1544ffc79d
6 changed files with 110 additions and 0 deletions
+30
View File
@@ -822,6 +822,32 @@ pub struct ModelAvailabilityNuxConfig {
/// Fallback resize-reflow row cap when Codex cannot identify a terminal-specific scrollback size.
pub const DEFAULT_TERMINAL_RESIZE_REFLOW_FALLBACK_MAX_ROWS: usize = 1_000;
/// One reusable prompt or slash command submitted through the TUI composer.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
#[schemars(deny_unknown_fields, rename = "Preset")]
pub struct QuickDial {
/// Plain-text input, limited to 8,000 UTF-8 bytes.
pub input: String,
/// Optional short name for the picker and shortcut hints.
pub label: Option<String>,
}
impl QuickDial {
/// Keep stored inputs nonempty and below the context-item limit even with byte tokenization.
pub fn validate(&self) -> Result<(), &'static str> {
if self.input.trim().is_empty() {
return Err("Preset input cannot be empty.");
}
if self.input.trim_start().starts_with('!') {
return Err("Presets support prompts and slash commands, not shell commands.");
}
if self.input.len() > 8_000 {
return Err("Preset input cannot exceed 8,000 UTF-8 bytes.");
}
Ok(())
}
}
/// Collection of settings that are specific to the TUI.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, JsonSchema)]
#[schemars(deny_unknown_fields)]
@@ -978,6 +1004,10 @@ pub struct Tui {
#[serde(default)]
pub keymap: TuiKeymap,
/// Saved inputs keyed by a single digit (`0` through `9`).
#[serde(default, rename = "presets")]
pub quick_dials: BTreeMap<String, QuickDial>,
/// Startup tooltip availability NUX state persisted by the TUI.
#[serde(default)]
pub model_availability_nux: ModelAvailabilityNuxConfig,