mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
32da5eb358
## Summary - add a shared `codex-core` sleep inhibitor that uses native macOS IOKit assertions (`IOPMAssertionCreateWithName` / `IOPMAssertionRelease`) instead of spawning `caffeinate` - wire sleep inhibition to turn lifecycle in `tui` (`TurnStarted` enables; `TurnComplete` and abort/error finalization disable) - gate this behavior behind a `/experimental` feature toggle (`[features].prevent_idle_sleep`) instead of a dedicated `[tui]` config flag - expose the toggle in `/experimental` on macOS; keep it under development on other platforms - keep behavior no-op on non-macOS targets <img width="1326" height="577" alt="image" src="https://github.com/user-attachments/assets/73fac06b-97ae-46a2-800a-30f9516cf8a3" /> ## Testing - `cargo check -p codex-core -p codex-tui` - `cargo test -p codex-core sleep_inhibitor::tests -- --nocapture` - `cargo test -p codex-core tui_config_missing_notifications_field_defaults_to_enabled -- --nocapture` - `cargo test -p codex-core prevent_idle_sleep_is_ -- --nocapture` ## Semantics and API references - This PR targets `caffeinate -i` semantics: prevent *idle system sleep* while allowing display idle sleep. - `caffeinate -i` mapping in Apple open source (`assertionMap`): - `kIdleAssertionFlag -> kIOPMAssertionTypePreventUserIdleSystemSleep` - Source: https://github.com/apple-oss-distributions/PowerManagement/blob/PowerManagement-1846.60.12/caffeinate/caffeinate.c#L52-L54 - Apple IOKit docs for assertion types and API: - https://developer.apple.com/documentation/iokit/iopmlib_h/iopmassertiontypes - https://developer.apple.com/documentation/iokit/1557092-iopmassertioncreatewithname - https://developer.apple.com/library/archive/qa/qa1340/_index.html ## Codex Electron vs this PR (full stack path) - Codex Electron app requests sleep blocking with `powerSaveBlocker.start("prevent-app-suspension")`: - https://github.com/openai/codex/blob/main/codex/codex-vscode/electron/src/electron-message-handler.ts - Electron maps that string to Chromium wake lock type `kPreventAppSuspension`: - https://github.com/electron/electron/blob/main/shell/browser/api/electron_api_power_save_blocker.cc - Chromium macOS backend maps wake lock types to IOKit assertion constants and calls IOKit: - `kPreventAppSuspension -> kIOPMAssertionTypeNoIdleSleep` - `kPreventDisplaySleep / kPreventDisplaySleepAllowDimming -> kIOPMAssertionTypeNoDisplaySleep` - https://github.com/chromium/chromium/blob/main/services/device/wake_lock/power_save_blocker/power_save_blocker_mac.cc ## Why this PR uses a different macOS constant name - This PR uses `"PreventUserIdleSystemSleep"` directly, via `IOPMAssertionCreateWithName`, in `codex-rs/core/src/sleep_inhibitor.rs`. - Appleās IOKit header documents `kIOPMAssertionTypeNoIdleSleep` as deprecated and recommends `kIOPMAssertPreventUserIdleSystemSleep` / `kIOPMAssertionTypePreventUserIdleSystemSleep`: - https://github.com/apple-oss-distributions/IOKitUser/blob/IOKitUser-100222.60.2/pwr_mgt.subproj/IOPMLib.h#L1000-L1030 - So Chromium and this PR are using different constant names, but semantically equivalent idle-system-sleep prevention behavior. ## Future platform support The architecture is intentionally set up for multi-platform extensions: - UI code (`tui`) only calls `SleepInhibitor::set_turn_running(...)` on turn lifecycle boundaries. - Platform-specific behavior is isolated in `codex-rs/core/src/sleep_inhibitor.rs` behind `cfg(...)` blocks. - Feature exposure is centralized in `core/src/features.rs` and surfaced via `/experimental`. - Adding new OS backends should not require additional TUI wiring; only the backend internals and feature stage metadata need to change. Potential follow-up implementations: - Windows: - Add a backend using Win32 power APIs (`SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)` as baseline). - Optionally move to `PowerCreateRequest` / `PowerSetRequest` / `PowerClearRequest` for richer assertion semantics. - Linux: - Add a backend using logind inhibitors over D-Bus (`org.freedesktop.login1.Manager.Inhibit` with `what="sleep"`). - Keep a no-op fallback where logind/D-Bus is unavailable. This PR keeps the cross-platform API surface minimal so future PRs can add Windows/Linux support incrementally with low churn. --------- Co-authored-by: jif-oai <jif@openai.com>
742 lines
23 KiB
Rust
742 lines
23 KiB
Rust
//! Centralized feature flags and metadata.
|
|
//!
|
|
//! This module defines a small set of toggles that gate experimental and
|
|
//! optional behavior across the codebase. Instead of wiring individual
|
|
//! booleans through multiple types, call sites consult a single `Features`
|
|
//! container attached to `Config`.
|
|
|
|
use crate::config::CONFIG_TOML_FILE;
|
|
use crate::config::Config;
|
|
use crate::config::ConfigToml;
|
|
use crate::config::profile::ConfigProfile;
|
|
use crate::protocol::Event;
|
|
use crate::protocol::EventMsg;
|
|
use crate::protocol::WarningEvent;
|
|
use codex_otel::OtelManager;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use std::collections::BTreeMap;
|
|
use std::collections::BTreeSet;
|
|
use toml::Value as TomlValue;
|
|
|
|
mod legacy;
|
|
pub(crate) use legacy::LegacyFeatureToggles;
|
|
pub(crate) use legacy::legacy_feature_keys;
|
|
|
|
/// High-level lifecycle stage for a feature.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum Stage {
|
|
/// Features that are still under development, not ready for external use
|
|
UnderDevelopment,
|
|
/// Experimental features made available to users through the `/experimental` menu
|
|
Experimental {
|
|
name: &'static str,
|
|
menu_description: &'static str,
|
|
announcement: &'static str,
|
|
},
|
|
/// Stable features. The feature flag is kept for ad-hoc enabling/disabling
|
|
Stable,
|
|
/// Deprecated feature that should not be used anymore.
|
|
Deprecated,
|
|
/// The feature flag is useless but kept for backward compatibility reason.
|
|
Removed,
|
|
}
|
|
|
|
impl Stage {
|
|
pub fn experimental_menu_name(self) -> Option<&'static str> {
|
|
match self {
|
|
Stage::Experimental { name, .. } => Some(name),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
pub fn experimental_menu_description(self) -> Option<&'static str> {
|
|
match self {
|
|
Stage::Experimental {
|
|
menu_description, ..
|
|
} => Some(menu_description),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
pub fn experimental_announcement(self) -> Option<&'static str> {
|
|
match self {
|
|
Stage::Experimental { announcement, .. } => Some(announcement),
|
|
_ => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Unique features toggled via configuration.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
pub enum Feature {
|
|
// Stable.
|
|
/// Create a ghost commit at each turn.
|
|
GhostCommit,
|
|
/// Enable the default shell tool.
|
|
ShellTool,
|
|
|
|
// Experimental
|
|
/// Enable JavaScript REPL tools backed by a persistent Node kernel.
|
|
JsRepl,
|
|
/// Only expose js_repl tools directly to the model.
|
|
JsReplToolsOnly,
|
|
/// Use the single unified PTY-backed exec tool.
|
|
UnifiedExec,
|
|
/// Include the freeform apply_patch tool.
|
|
ApplyPatchFreeform,
|
|
/// Allow the model to request web searches that fetch live content.
|
|
WebSearchRequest,
|
|
/// Allow the model to request web searches that fetch cached content.
|
|
/// Takes precedence over `WebSearchRequest`.
|
|
WebSearchCached,
|
|
/// Legacy search-tool feature flag kept for backward compatibility.
|
|
SearchTool,
|
|
/// Use the bubblewrap-based Linux sandbox pipeline.
|
|
UseLinuxSandboxBwrap,
|
|
/// Allow the model to request approval and propose exec rules.
|
|
RequestRule,
|
|
/// Enable Windows sandbox (restricted token) on Windows.
|
|
WindowsSandbox,
|
|
/// Use the elevated Windows sandbox pipeline (setup + runner).
|
|
WindowsSandboxElevated,
|
|
/// Refresh remote models and emit AppReady once the list is available.
|
|
RemoteModels,
|
|
/// Experimental shell snapshotting.
|
|
ShellSnapshot,
|
|
/// Enable runtime metrics snapshots via a manual reader.
|
|
RuntimeMetrics,
|
|
/// Persist rollout metadata to a local SQLite database.
|
|
Sqlite,
|
|
/// Enable startup memory extraction and file-backed memory consolidation.
|
|
MemoryTool,
|
|
/// Append additional AGENTS.md guidance to user instructions.
|
|
ChildAgentsMd,
|
|
/// Enforce UTF8 output in Powershell.
|
|
PowershellUtf8,
|
|
/// Compress request bodies (zstd) when sending streaming requests to codex-backend.
|
|
EnableRequestCompression,
|
|
/// Enable collab tools.
|
|
Collab,
|
|
/// Enable apps.
|
|
Apps,
|
|
/// Route apps MCP calls through the configured gateway.
|
|
AppsMcpGateway,
|
|
/// Allow prompting and installing missing MCP dependencies.
|
|
SkillMcpDependencyInstall,
|
|
/// Prompt for missing skill env var dependencies.
|
|
SkillEnvVarDependencyPrompt,
|
|
/// Steer feature flag - when enabled, Enter submits immediately instead of queuing.
|
|
Steer,
|
|
/// Enable collaboration modes (Plan, Default).
|
|
CollaborationModes,
|
|
/// Enable personality selection in the TUI.
|
|
Personality,
|
|
/// Prevent idle system sleep while a turn is actively running.
|
|
PreventIdleSleep,
|
|
/// Use the Responses API WebSocket transport for OpenAI by default.
|
|
ResponsesWebsockets,
|
|
/// Enable Responses API websocket v2 mode.
|
|
ResponsesWebsocketsV2,
|
|
}
|
|
|
|
impl Feature {
|
|
pub fn key(self) -> &'static str {
|
|
self.info().key
|
|
}
|
|
|
|
pub fn stage(self) -> Stage {
|
|
self.info().stage
|
|
}
|
|
|
|
pub fn default_enabled(self) -> bool {
|
|
self.info().default_enabled
|
|
}
|
|
|
|
fn info(self) -> &'static FeatureSpec {
|
|
FEATURES
|
|
.iter()
|
|
.find(|spec| spec.id == self)
|
|
.unwrap_or_else(|| unreachable!("missing FeatureSpec for {:?}", self))
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub struct LegacyFeatureUsage {
|
|
pub alias: String,
|
|
pub feature: Feature,
|
|
pub summary: String,
|
|
pub details: Option<String>,
|
|
}
|
|
|
|
/// Holds the effective set of enabled features.
|
|
#[derive(Debug, Clone, Default, PartialEq)]
|
|
pub struct Features {
|
|
enabled: BTreeSet<Feature>,
|
|
legacy_usages: BTreeSet<LegacyFeatureUsage>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct FeatureOverrides {
|
|
pub include_apply_patch_tool: Option<bool>,
|
|
pub web_search_request: Option<bool>,
|
|
}
|
|
|
|
impl FeatureOverrides {
|
|
fn apply(self, features: &mut Features) {
|
|
LegacyFeatureToggles {
|
|
include_apply_patch_tool: self.include_apply_patch_tool,
|
|
tools_web_search: self.web_search_request,
|
|
..Default::default()
|
|
}
|
|
.apply(features);
|
|
}
|
|
}
|
|
|
|
impl Features {
|
|
/// Starts with built-in defaults.
|
|
pub fn with_defaults() -> Self {
|
|
let mut set = BTreeSet::new();
|
|
for spec in FEATURES {
|
|
if spec.default_enabled {
|
|
set.insert(spec.id);
|
|
}
|
|
}
|
|
Self {
|
|
enabled: set,
|
|
legacy_usages: BTreeSet::new(),
|
|
}
|
|
}
|
|
|
|
pub fn enabled(&self, f: Feature) -> bool {
|
|
self.enabled.contains(&f)
|
|
}
|
|
|
|
pub fn enable(&mut self, f: Feature) -> &mut Self {
|
|
self.enabled.insert(f);
|
|
self
|
|
}
|
|
|
|
pub fn disable(&mut self, f: Feature) -> &mut Self {
|
|
self.enabled.remove(&f);
|
|
self
|
|
}
|
|
|
|
pub fn record_legacy_usage_force(&mut self, alias: &str, feature: Feature) {
|
|
let (summary, details) = legacy_usage_notice(alias, feature);
|
|
self.legacy_usages.insert(LegacyFeatureUsage {
|
|
alias: alias.to_string(),
|
|
feature,
|
|
summary,
|
|
details,
|
|
});
|
|
}
|
|
|
|
pub fn record_legacy_usage(&mut self, alias: &str, feature: Feature) {
|
|
if alias == feature.key() {
|
|
return;
|
|
}
|
|
self.record_legacy_usage_force(alias, feature);
|
|
}
|
|
|
|
pub fn legacy_feature_usages(&self) -> impl Iterator<Item = &LegacyFeatureUsage> + '_ {
|
|
self.legacy_usages.iter()
|
|
}
|
|
|
|
pub fn emit_metrics(&self, otel: &OtelManager) {
|
|
for feature in FEATURES {
|
|
if self.enabled(feature.id) != feature.default_enabled {
|
|
otel.counter(
|
|
"codex.feature.state",
|
|
1,
|
|
&[
|
|
("feature", feature.key),
|
|
("value", &self.enabled(feature.id).to_string()),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Apply a table of key -> bool toggles (e.g. from TOML).
|
|
pub fn apply_map(&mut self, m: &BTreeMap<String, bool>) {
|
|
for (k, v) in m {
|
|
match k.as_str() {
|
|
"web_search_request" => {
|
|
self.record_legacy_usage_force(
|
|
"features.web_search_request",
|
|
Feature::WebSearchRequest,
|
|
);
|
|
}
|
|
"web_search_cached" => {
|
|
self.record_legacy_usage_force(
|
|
"features.web_search_cached",
|
|
Feature::WebSearchCached,
|
|
);
|
|
}
|
|
_ => {}
|
|
}
|
|
match feature_for_key(k) {
|
|
Some(feat) => {
|
|
if k != feat.key() {
|
|
self.record_legacy_usage(k.as_str(), feat);
|
|
}
|
|
if *v {
|
|
self.enable(feat);
|
|
} else {
|
|
self.disable(feat);
|
|
}
|
|
}
|
|
None => {
|
|
tracing::warn!("unknown feature key in config: {k}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn from_config(
|
|
cfg: &ConfigToml,
|
|
config_profile: &ConfigProfile,
|
|
overrides: FeatureOverrides,
|
|
) -> Self {
|
|
let mut features = Features::with_defaults();
|
|
|
|
let base_legacy = LegacyFeatureToggles {
|
|
experimental_use_freeform_apply_patch: cfg.experimental_use_freeform_apply_patch,
|
|
experimental_use_unified_exec_tool: cfg.experimental_use_unified_exec_tool,
|
|
tools_web_search: cfg.tools.as_ref().and_then(|t| t.web_search),
|
|
..Default::default()
|
|
};
|
|
base_legacy.apply(&mut features);
|
|
|
|
if let Some(base_features) = cfg.features.as_ref() {
|
|
features.apply_map(&base_features.entries);
|
|
}
|
|
|
|
let profile_legacy = LegacyFeatureToggles {
|
|
include_apply_patch_tool: config_profile.include_apply_patch_tool,
|
|
experimental_use_freeform_apply_patch: config_profile
|
|
.experimental_use_freeform_apply_patch,
|
|
|
|
experimental_use_unified_exec_tool: config_profile.experimental_use_unified_exec_tool,
|
|
tools_web_search: config_profile.tools_web_search,
|
|
};
|
|
profile_legacy.apply(&mut features);
|
|
if let Some(profile_features) = config_profile.features.as_ref() {
|
|
features.apply_map(&profile_features.entries);
|
|
}
|
|
|
|
overrides.apply(&mut features);
|
|
if features.enabled(Feature::JsReplToolsOnly) && !features.enabled(Feature::JsRepl) {
|
|
tracing::warn!("js_repl_tools_only requires js_repl; disabling js_repl_tools_only");
|
|
features.disable(Feature::JsReplToolsOnly);
|
|
}
|
|
|
|
features
|
|
}
|
|
|
|
pub fn enabled_features(&self) -> Vec<Feature> {
|
|
self.enabled.iter().copied().collect()
|
|
}
|
|
}
|
|
|
|
fn legacy_usage_notice(alias: &str, feature: Feature) -> (String, Option<String>) {
|
|
let canonical = feature.key();
|
|
match feature {
|
|
Feature::WebSearchRequest | Feature::WebSearchCached => {
|
|
let label = match alias {
|
|
"web_search" => "[features].web_search",
|
|
"tools.web_search" => "[tools].web_search",
|
|
"features.web_search_request" | "web_search_request" => {
|
|
"[features].web_search_request"
|
|
}
|
|
"features.web_search_cached" | "web_search_cached" => {
|
|
"[features].web_search_cached"
|
|
}
|
|
_ => alias,
|
|
};
|
|
let summary = format!("`{label}` is deprecated. Use `web_search` instead.");
|
|
(summary, Some(web_search_details().to_string()))
|
|
}
|
|
_ => {
|
|
let summary = format!("`{alias}` is deprecated. Use `[features].{canonical}` instead.");
|
|
let details = if alias == canonical {
|
|
None
|
|
} else {
|
|
Some(format!(
|
|
"Enable it with `--enable {canonical}` or `[features].{canonical}` in config.toml. See https://github.com/openai/codex/blob/main/docs/config.md#feature-flags for details."
|
|
))
|
|
};
|
|
(summary, details)
|
|
}
|
|
}
|
|
}
|
|
|
|
fn web_search_details() -> &'static str {
|
|
"Set `web_search` to `\"live\"`, `\"cached\"`, or `\"disabled\"` at the top level (or under a profile) in config.toml."
|
|
}
|
|
|
|
/// Keys accepted in `[features]` tables.
|
|
fn feature_for_key(key: &str) -> Option<Feature> {
|
|
for spec in FEATURES {
|
|
if spec.key == key {
|
|
return Some(spec.id);
|
|
}
|
|
}
|
|
legacy::feature_for_key(key)
|
|
}
|
|
|
|
/// Returns `true` if the provided string matches a known feature toggle key.
|
|
pub fn is_known_feature_key(key: &str) -> bool {
|
|
feature_for_key(key).is_some()
|
|
}
|
|
|
|
/// Deserializable features table for TOML.
|
|
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
|
|
pub struct FeaturesToml {
|
|
#[serde(flatten)]
|
|
pub entries: BTreeMap<String, bool>,
|
|
}
|
|
|
|
/// Single, easy-to-read registry of all feature definitions.
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct FeatureSpec {
|
|
pub id: Feature,
|
|
pub key: &'static str,
|
|
pub stage: Stage,
|
|
pub default_enabled: bool,
|
|
}
|
|
|
|
pub const FEATURES: &[FeatureSpec] = &[
|
|
// Stable features.
|
|
FeatureSpec {
|
|
id: Feature::GhostCommit,
|
|
key: "undo",
|
|
stage: Stage::Stable,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::ShellTool,
|
|
key: "shell_tool",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::UnifiedExec,
|
|
key: "unified_exec",
|
|
stage: Stage::Stable,
|
|
default_enabled: !cfg!(windows),
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::ShellSnapshot,
|
|
key: "shell_snapshot",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::JsRepl,
|
|
key: "js_repl",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::JsReplToolsOnly,
|
|
key: "js_repl_tools_only",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::WebSearchRequest,
|
|
key: "web_search_request",
|
|
stage: Stage::Deprecated,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::WebSearchCached,
|
|
key: "web_search_cached",
|
|
stage: Stage::Deprecated,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::SearchTool,
|
|
key: "search_tool",
|
|
stage: Stage::Removed,
|
|
default_enabled: false,
|
|
},
|
|
// Experimental program. Rendered in the `/experimental` menu for users.
|
|
FeatureSpec {
|
|
id: Feature::RuntimeMetrics,
|
|
key: "runtime_metrics",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::Sqlite,
|
|
key: "sqlite",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::MemoryTool,
|
|
key: "memory_tool",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::ChildAgentsMd,
|
|
key: "child_agents_md",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::ApplyPatchFreeform,
|
|
key: "apply_patch_freeform",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::UseLinuxSandboxBwrap,
|
|
key: "use_linux_sandbox_bwrap",
|
|
#[cfg(target_os = "linux")]
|
|
stage: Stage::Experimental {
|
|
name: "Bubblewrap sandbox",
|
|
menu_description: "Try the new linux sandbox based on bubblewrap.",
|
|
announcement: "NEW: Linux bubblewrap sandbox offers stronger filesystem and network controls than Landlock alone, including keeping .git and .codex read-only inside writable workspaces. Enable it in /experimental and restart Codex to try it.",
|
|
},
|
|
#[cfg(not(target_os = "linux"))]
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::RequestRule,
|
|
key: "request_rule",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::WindowsSandbox,
|
|
key: "experimental_windows_sandbox",
|
|
stage: Stage::Removed,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::WindowsSandboxElevated,
|
|
key: "elevated_windows_sandbox",
|
|
stage: Stage::Removed,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::RemoteModels,
|
|
key: "remote_models",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::PowershellUtf8,
|
|
key: "powershell_utf8",
|
|
#[cfg(windows)]
|
|
stage: Stage::Stable,
|
|
#[cfg(windows)]
|
|
default_enabled: true,
|
|
#[cfg(not(windows))]
|
|
stage: Stage::UnderDevelopment,
|
|
#[cfg(not(windows))]
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::EnableRequestCompression,
|
|
key: "enable_request_compression",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::Collab,
|
|
key: "collab",
|
|
stage: Stage::Experimental {
|
|
name: "Sub-agents",
|
|
menu_description: "Ask Codex to spawn multiple agents to parallelize the work and win in efficiency.",
|
|
announcement: "NEW: Sub-agents can now be spawned by Codex. Enable in /experimental and restart Codex!",
|
|
},
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::Apps,
|
|
key: "apps",
|
|
stage: Stage::Experimental {
|
|
name: "Apps",
|
|
menu_description: "Use a connected ChatGPT App using \"$\". Install Apps via /apps command. Restart Codex after enabling.",
|
|
announcement: "NEW: Use ChatGPT Apps (Connectors) in Codex via $ mentions. Enable in /experimental and restart Codex!",
|
|
},
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::AppsMcpGateway,
|
|
key: "apps_mcp_gateway",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::SkillMcpDependencyInstall,
|
|
key: "skill_mcp_dependency_install",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::SkillEnvVarDependencyPrompt,
|
|
key: "skill_env_var_dependency_prompt",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::Steer,
|
|
key: "steer",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::CollaborationModes,
|
|
key: "collaboration_modes",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::Personality,
|
|
key: "personality",
|
|
stage: Stage::Stable,
|
|
default_enabled: true,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::PreventIdleSleep,
|
|
key: "prevent_idle_sleep",
|
|
stage: if cfg!(target_os = "macos") {
|
|
Stage::Experimental {
|
|
name: "Prevent sleep while running",
|
|
menu_description: "Keep your computer awake while Codex is running a thread.",
|
|
announcement: "NEW: Prevent sleep while running is now available in /experimental.",
|
|
}
|
|
} else {
|
|
Stage::UnderDevelopment
|
|
},
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::ResponsesWebsockets,
|
|
key: "responses_websockets",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
FeatureSpec {
|
|
id: Feature::ResponsesWebsocketsV2,
|
|
key: "responses_websockets_v2",
|
|
stage: Stage::UnderDevelopment,
|
|
default_enabled: false,
|
|
},
|
|
];
|
|
|
|
/// Push a warning event if any under-development features are enabled.
|
|
pub fn maybe_push_unstable_features_warning(
|
|
config: &Config,
|
|
post_session_configured_events: &mut Vec<Event>,
|
|
) {
|
|
if config.suppress_unstable_features_warning {
|
|
return;
|
|
}
|
|
|
|
let mut under_development_feature_keys = Vec::new();
|
|
if let Some(table) = config
|
|
.config_layer_stack
|
|
.effective_config()
|
|
.get("features")
|
|
.and_then(TomlValue::as_table)
|
|
{
|
|
for (key, value) in table {
|
|
if value.as_bool() != Some(true) {
|
|
continue;
|
|
}
|
|
let Some(spec) = FEATURES.iter().find(|spec| spec.key == key.as_str()) else {
|
|
continue;
|
|
};
|
|
if !config.features.enabled(spec.id) {
|
|
continue;
|
|
}
|
|
if matches!(spec.stage, Stage::UnderDevelopment) {
|
|
under_development_feature_keys.push(spec.key.to_string());
|
|
}
|
|
}
|
|
}
|
|
|
|
if under_development_feature_keys.is_empty() {
|
|
return;
|
|
}
|
|
|
|
let under_development_feature_keys = under_development_feature_keys.join(", ");
|
|
let config_path = config
|
|
.codex_home
|
|
.join(CONFIG_TOML_FILE)
|
|
.display()
|
|
.to_string();
|
|
let message = format!(
|
|
"Under-development features enabled: {under_development_feature_keys}. Under-development features are incomplete and may behave unpredictably. To suppress this warning, set `suppress_unstable_features_warning = true` in {config_path}."
|
|
);
|
|
post_session_configured_events.push(Event {
|
|
id: "".to_owned(),
|
|
msg: EventMsg::Warning(WarningEvent { message }),
|
|
});
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn under_development_features_are_disabled_by_default() {
|
|
for spec in FEATURES {
|
|
if matches!(spec.stage, Stage::UnderDevelopment) {
|
|
assert_eq!(
|
|
spec.default_enabled, false,
|
|
"feature `{}` is under development and must be disabled by default",
|
|
spec.key
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn default_enabled_features_are_stable() {
|
|
for spec in FEATURES {
|
|
if spec.default_enabled {
|
|
assert_eq!(
|
|
spec.stage,
|
|
Stage::Stable,
|
|
"feature `{}` is enabled by default but is not stable ({:?})",
|
|
spec.key,
|
|
spec.stage
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(target_os = "linux")]
|
|
#[test]
|
|
fn use_linux_sandbox_bwrap_is_experimental_on_linux() {
|
|
assert!(matches!(
|
|
Feature::UseLinuxSandboxBwrap.stage(),
|
|
Stage::Experimental { .. }
|
|
));
|
|
assert_eq!(Feature::UseLinuxSandboxBwrap.default_enabled(), false);
|
|
}
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
#[test]
|
|
fn use_linux_sandbox_bwrap_is_under_development_off_linux() {
|
|
assert_eq!(
|
|
Feature::UseLinuxSandboxBwrap.stage(),
|
|
Stage::UnderDevelopment
|
|
);
|
|
assert_eq!(Feature::UseLinuxSandboxBwrap.default_enabled(), false);
|
|
}
|
|
}
|