aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
14
akode-rs/features/BUILD.bazel
Normal file
14
akode-rs/features/BUILD.bazel
Normal file
@@ -0,0 +1,14 @@
|
||||
load("//:defs.bzl", "codex_rust_crate")
|
||||
|
||||
codex_rust_crate(
|
||||
name = "features",
|
||||
compile_data = glob(
|
||||
include = ["**"],
|
||||
allow_empty = True,
|
||||
exclude = [
|
||||
"BUILD.bazel",
|
||||
"Cargo.toml",
|
||||
],
|
||||
),
|
||||
crate_name = "akode_features",
|
||||
)
|
||||
25
akode-rs/features/Cargo.toml
Normal file
25
akode-rs/features/Cargo.toml
Normal file
@@ -0,0 +1,25 @@
|
||||
[package]
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
name = "akode-features"
|
||||
version.workspace = true
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
name = "akode_features"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
akode-network-proxy = { workspace = true }
|
||||
akode-protocol = { workspace = true }
|
||||
akode-utils-redacted-string = { workspace = true }
|
||||
schemars = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
toml = { workspace = true }
|
||||
tracing = { workspace = true, features = ["log"] }
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = { workspace = true }
|
||||
622
akode-rs/features/src/feature_configs.rs
Normal file
622
akode-rs/features/src/feature_configs.rs
Normal file
@@ -0,0 +1,622 @@
|
||||
use crate::FeatureConfig;
|
||||
use crate::FeatureToml;
|
||||
use akode_network_proxy::CredentialProviderConfig;
|
||||
use akode_protocol::openai_models::ReasoningEffort;
|
||||
use akode_utils_redacted_string::RedactedString;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
/// Connection to a board provisioned by the research host.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RemoteMessageBoardConfigToml {
|
||||
pub url: String,
|
||||
/// Board credential supplied directly by a runtime config override.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub bearer_token: Option<RedactedString>,
|
||||
/// Read the credential from this environment variable instead of bearer_token.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub bearer_token_env_var: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ToolRegistryConfigToml {
|
||||
/// Fail the turn when multiple tools share the same effective name.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub error_on_tool_collisions: Option<bool>,
|
||||
/// Include authoritative tool information in per-turn request metadata.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub turn_metadata_includes_tool_info: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CodeModeConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
/// Default yield timeout for code-mode exec calls, in milliseconds.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub default_exec_yield_time_ms: Option<u64>,
|
||||
/// Show handler duration, code-mode host duration, and harness overhead
|
||||
/// in each code-mode cell response.
|
||||
/// Experimental: this option and the response format may change or be removed.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub experimental_show_cell_overhead: Option<bool>,
|
||||
/// Maximum UTF-8 bytes per rendered tool input type, with a 16,000-byte minimum and default.
|
||||
/// For ordinary MCP tools, this is also at least their server's explicitly configured input limit.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tool_input_schema_max_bytes: Option<NonZeroUsize>,
|
||||
/// Exact tool namespaces to omit from the code-mode nested tool surface.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub excluded_tool_namespaces: Option<Vec<String>>,
|
||||
/// Exact tool namespaces to expose only as direct model tools.
|
||||
/// These tools bypass deferral, remain top-level in code-mode-only sessions, and are omitted
|
||||
/// from the nested code-mode tool surface.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub direct_only_tool_namespaces: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for CodeModeConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CodeModeHostConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
/// Keep code mode fail-closed when the standalone host is unavailable.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_in_process_fallback: Option<bool>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for CodeModeHostConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NonPrefixedMcpToolNamesConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
/// MCP servers whose tools should omit the legacy `mcp__` namespace prefix.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub server_names: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for NonPrefixedMcpToolNamesConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
/// Optional conversation sources available to the Guardian v2 classifier.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum GuardianV2TranscriptSource {
|
||||
ToolCalls,
|
||||
ToolOutputs,
|
||||
Reasoning,
|
||||
}
|
||||
|
||||
/// Bounds and optional sources for the Guardian v2 conversation transcript.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GuardianV2TranscriptConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sources: Option<Vec<GuardianV2TranscriptSource>>,
|
||||
/// Include recent screenshots from messages and configured tool outputs.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub include_images: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_message_entry_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_tool_entry_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_message_transcript_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_tool_transcript_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub max_recent_non_user_entries: Option<usize>,
|
||||
}
|
||||
|
||||
/// Optional tool-call categories available to the Guardian v2 classifier.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GuardianV2ReviewScopeConfigToml {
|
||||
/// Restrict asynchronous classification and fast approvals to browser and computer-use tools.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub computer_use_only: Option<bool>,
|
||||
/// Include sandboxed shell command calls in Guardian v2 classification.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sandboxed_exec_commands: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GuardianElasticSectionConfigToml {
|
||||
pub min_total_section_tokens: usize,
|
||||
pub max_section_entry_tokens: usize,
|
||||
/// Upper bound for the section's allocation.
|
||||
/// Omit to use the global request budget as the upper bound.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max_total_section_tokens: Option<usize>,
|
||||
}
|
||||
|
||||
/// User-configurable prompt, approval, and context settings for Guardian v2.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GuardianV2ConfigToml {
|
||||
/// Enable elastic allocation for synchronous Guardian requests. Defaults to false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sync_elastic_budgeting: Option<bool>,
|
||||
/// Named section limits, decoded and validated by Guardian when the switch is enabled.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sync_elastic_sections: Option<BTreeMap<String, GuardianElasticSectionConfigToml>>,
|
||||
/// Transcript encoding for synchronous Guardian review and asynchronous scoring. Defaults to line.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub transcript_mode: Option<akode_protocol::TranscriptFormat>,
|
||||
/// Deprecated and ignored; asynchronous classification always uses conversations.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub async_classifier_mode: Option<akode_protocol::openai_models::AsyncClassifierMode>,
|
||||
/// Reset retained async history when the next request exceeds this token estimate.
|
||||
/// Defaults to 100,000. Fresh requests remain subject to the model's input limit.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub async_classifier_conversation_token_limit: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
/// Legacy setting retained for config compatibility; the backend now controls Guardian billing.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub free_guardian: Option<bool>,
|
||||
/// Deprecated and ignored; thread-owned Guardian context is always enabled.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub thread_context: Option<bool>,
|
||||
/// Persist reviewed actions and risk scores to rollout files for debugging.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub persist_scores: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub classifier_instructions: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 0.0, max = 1.0))]
|
||||
pub review_threshold: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub max_tool_call_lag: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reasoning_effort: Option<ReasoningEffort>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_action_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_classifier_instruction_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reuse_parent_compaction: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 100, max = 100000))]
|
||||
pub max_parent_compaction_tokens: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub review_scope: Option<GuardianV2ReviewScopeConfigToml>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub transcript: Option<GuardianV2TranscriptConfigToml>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for GuardianV2ConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize_guardian_v2_feature<'de, D>(
|
||||
deserializer: D,
|
||||
) -> Result<Option<FeatureToml<GuardianV2ConfigToml>>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
const MIN_TOKENS: usize = 100;
|
||||
const MAX_TOKENS: usize = 100_000;
|
||||
|
||||
let feature = Option::<FeatureToml<GuardianV2ConfigToml>>::deserialize(deserializer)?;
|
||||
let Some(FeatureToml::Config(config)) = feature.as_ref() else {
|
||||
return Ok(feature);
|
||||
};
|
||||
|
||||
if let Some(threshold) = config.review_threshold
|
||||
&& (!threshold.is_finite() || !(0.0..=1.0).contains(&threshold))
|
||||
{
|
||||
return Err(serde::de::Error::custom(
|
||||
"Guardian v2 review_threshold must be between 0.0 and 1.0",
|
||||
));
|
||||
}
|
||||
|
||||
let transcript = config.transcript.as_ref();
|
||||
if config.async_classifier_conversation_token_limit == Some(0) {
|
||||
return Err(serde::de::Error::custom(
|
||||
"Guardian v2 async_classifier_conversation_token_limit must be positive",
|
||||
));
|
||||
}
|
||||
let message_entry = transcript.and_then(|value| value.max_message_entry_tokens);
|
||||
let tool_entry = transcript.and_then(|value| value.max_tool_entry_tokens);
|
||||
let message_total = transcript.and_then(|value| value.max_message_transcript_tokens);
|
||||
let tool_total = transcript.and_then(|value| value.max_tool_transcript_tokens);
|
||||
for (field, tokens) in [
|
||||
("max_action_tokens", config.max_action_tokens),
|
||||
(
|
||||
"max_classifier_instruction_tokens",
|
||||
config.max_classifier_instruction_tokens,
|
||||
),
|
||||
(
|
||||
"max_parent_compaction_tokens",
|
||||
config.max_parent_compaction_tokens,
|
||||
),
|
||||
("transcript max_message_entry_tokens", message_entry),
|
||||
("transcript max_tool_entry_tokens", tool_entry),
|
||||
("transcript max_message_transcript_tokens", message_total),
|
||||
("transcript max_tool_transcript_tokens", tool_total),
|
||||
] {
|
||||
if let Some(tokens) = tokens
|
||||
&& !(MIN_TOKENS..=MAX_TOKENS).contains(&tokens)
|
||||
{
|
||||
return Err(serde::de::Error::custom(format!(
|
||||
"Guardian v2 {field} must be between {MIN_TOKENS} and {MAX_TOKENS} tokens"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
if transcript
|
||||
.and_then(|value| value.max_recent_non_user_entries)
|
||||
.is_some_and(|count| count == 0)
|
||||
{
|
||||
return Err(serde::de::Error::custom(
|
||||
"Guardian v2 transcript max_recent_non_user_entries must be positive",
|
||||
));
|
||||
}
|
||||
|
||||
for (kind, entry, total) in [
|
||||
("message", message_entry, message_total),
|
||||
("tool", tool_entry, tool_total),
|
||||
] {
|
||||
if let (Some(entry), Some(total)) = (entry, total)
|
||||
&& entry > total
|
||||
{
|
||||
return Err(serde::de::Error::custom(format!(
|
||||
"Guardian v2 transcript max_{kind}_entry_tokens must not exceed max_{kind}_transcript_tokens"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(feature)
|
||||
}
|
||||
|
||||
/// User-configurable settings for Guardian V3.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct GuardianV3ConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for GuardianV3ConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct MultiAgentV2ConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub max_concurrent_threads_per_session: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 0, max = 3600000))]
|
||||
pub min_wait_timeout_ms: Option<i64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 0, max = 3600000))]
|
||||
pub max_wait_timeout_ms: Option<i64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 0, max = 3600000))]
|
||||
pub default_wait_timeout_ms: Option<i64>,
|
||||
/// Deprecated compatibility field. Its value is ignored.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub usage_hint_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub usage_hint_text: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub root_agent_usage_hint_text: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub subagent_usage_hint_text: Option<String>,
|
||||
/// Overrides inherited developer instructions for subagents without role-specific instructions.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub subagent_developer_instructions: Option<String>,
|
||||
/// Preserve the parent's model-visible history on full forks and append child instructions.
|
||||
/// Defaults to true. Legacy compaction without a reusable context baseline still rebuilds.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub preserve_fork_prefix: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub multi_agent_mode_hint_text: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(length(min = 1, max = 64), regex(pattern = r"^[a-zA-Z0-9_-]+$"))]
|
||||
pub tool_namespace: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub hide_spawn_agent_metadata: Option<bool>,
|
||||
/// Exposes `model` and `reasoning_effort` on the multi-agent v2 spawn tool and adds
|
||||
/// corresponding guidance to root and subagent usage hints.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub expose_spawn_agent_model_overrides: Option<bool>,
|
||||
/// Expose the multi-agent v2 `wait_agent` tool.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wait_agent_enabled: Option<bool>,
|
||||
/// Hide native multi-agent tools while retaining the V2 runtime for host-provided tools.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_native_tools: Option<bool>,
|
||||
/// Disable the model's direct-message tools; spawning and automatic child results remain available.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub disable_direct_message: Option<bool>,
|
||||
/// Keep the message board in memory for a training session, including ephemeral sessions.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message_board_in_memory: Option<bool>,
|
||||
/// Use a session-scoped remote board instead of local storage.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message_board_remote: Option<RemoteMessageBoardConfigToml>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub non_code_mode_only: Option<bool>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for MultiAgentV2ConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ContextManagementConfigToml {
|
||||
/// Enables experimental context management.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub experimental_mode: Option<bool>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for ContextManagementConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.experimental_mode
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct TokenBudgetConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
/// Removed: the hosted history and notes extension was deleted. Accepted and ignored.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub use_history_notes_extension: Option<bool>,
|
||||
/// Number of tokens remaining before auto-compaction when the wrap-up reminder is emitted.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub reminder_threshold_tokens: Option<i64>,
|
||||
/// Reminder template. `{n_remaining}` is replaced with the tokens remaining before
|
||||
/// auto-compaction.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(length(min = 1, max = 2000))]
|
||||
pub reminder_message_template: Option<String>,
|
||||
/// Guidance appended to the context-window metadata in a developer message.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(length(max = 2000))]
|
||||
pub guidance_message: Option<String>,
|
||||
/// Developer message sampled before an automatic context-window rollover.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(length(max = 2000))]
|
||||
pub auto_compact_fallback_prompt: Option<String>,
|
||||
/// Additional tokens available after the compaction threshold for fallback note-taking.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub auto_compact_fallback_buffer_tokens: Option<i64>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for TokenBudgetConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RolloutBudgetConfigToml {
|
||||
/// Stop when the shared budget is exhausted. Defaults to true.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enforce_limit: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1))]
|
||||
pub limit_tokens: Option<i64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
/// Remaining weighted-token values that trigger reminders when crossed.
|
||||
pub reminder_at_remaining_tokens: Option<Vec<i64>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 0.0))]
|
||||
pub sampling_token_weight: Option<f64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 0.0))]
|
||||
pub prefill_token_weight: Option<f64>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for RolloutBudgetConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CurrentTimeSource {
|
||||
#[default]
|
||||
System,
|
||||
External,
|
||||
}
|
||||
|
||||
/// Which inference boundaries may receive current-time reminders.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum CurrentTimeReminderDeliveryMode {
|
||||
/// Allow a reminder before any inference request once the interval is due.
|
||||
#[default]
|
||||
AnyInference,
|
||||
/// Allow reminders after user input or tool output; new context windows still force one.
|
||||
AfterUserOrToolOutput,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct CurrentTimeReminderConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub reminder_interval_seconds: Option<u64>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub clock_source: Option<CurrentTimeSource>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub delivery_mode: Option<CurrentTimeReminderDeliveryMode>,
|
||||
/// Expose the input-interruptible `clock.sleep` tool.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub sleep_tool: Option<bool>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for CurrentTimeReminderConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
/// How the sleep tool is selected when its feature gate is enabled.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum SleepToolMode {
|
||||
/// Preserve the existing model and legacy clock configuration defaults.
|
||||
#[default]
|
||||
ModelDriven,
|
||||
/// Register sleep regardless of the model or legacy clock configuration.
|
||||
AlwaysOn,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct SleepToolConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mode: Option<SleepToolMode>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for SleepToolConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct RemovedAppsMcpPathOverrideConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct NetworkProxyConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub proxy_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enable_socks5: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub socks_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enable_socks5_udp: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub allow_upstream_proxy: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub dangerously_allow_non_loopback_proxy: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub dangerously_allow_all_unix_sockets: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mode: Option<NetworkProxyModeToml>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub domains: Option<BTreeMap<String, NetworkProxyDomainPermissionToml>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub unix_sockets: Option<BTreeMap<String, NetworkProxyUnixSocketPermissionToml>>,
|
||||
/// Permits local servers and direct host-loopback connections and skips the proxy's
|
||||
/// additional private-network destination checks. Proxy domain rules still apply.
|
||||
/// Defaults to true for MXC, which cannot enforce false; otherwise defaults to false.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub allow_local_binding: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub credential_broker: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub credentials: Option<BTreeMap<String, CredentialProviderConfig>>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for NetworkProxyConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkProxyModeToml {
|
||||
Limited,
|
||||
Full,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkProxyDomainPermissionToml {
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum NetworkProxyUnixSocketPermissionToml {
|
||||
Allow,
|
||||
Deny,
|
||||
}
|
||||
|
||||
/// Background compaction settings. A threshold alone does not enable the feature.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct AsyncCompactionConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
/// Percentage of the model's full context window that starts background compaction.
|
||||
/// Defaults to 65; valid values are 1–100, including when disabled.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
#[schemars(range(min = 1, max = 100))]
|
||||
pub model_async_compact_threshold_percent: Option<u8>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for AsyncCompactionConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
115
akode-rs/features/src/legacy.rs
Normal file
115
akode-rs/features/src/legacy.rs
Normal file
@@ -0,0 +1,115 @@
|
||||
use crate::Feature;
|
||||
use crate::Features;
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Alias {
|
||||
legacy_key: &'static str,
|
||||
feature: Feature,
|
||||
}
|
||||
|
||||
const ALIASES: &[Alias] = &[
|
||||
Alias {
|
||||
legacy_key: "connectors",
|
||||
feature: Feature::Apps,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "enable_experimental_windows_sandbox",
|
||||
feature: Feature::WindowsSandbox,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "experimental_use_unified_exec_tool",
|
||||
feature: Feature::UnifiedExec,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "request_permissions",
|
||||
feature: Feature::ExecPermissionApprovals,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "web_search",
|
||||
feature: Feature::WebSearchRequest,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "imagegenext",
|
||||
feature: Feature::ImageGeneration,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "collab",
|
||||
feature: Feature::Collab,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "memory_tool",
|
||||
feature: Feature::MemoryTool,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "telepathy",
|
||||
feature: Feature::Chronicle,
|
||||
},
|
||||
Alias {
|
||||
legacy_key: "codex_hooks",
|
||||
feature: Feature::CodexHooks,
|
||||
},
|
||||
];
|
||||
|
||||
pub fn legacy_feature_keys() -> impl Iterator<Item = &'static str> {
|
||||
ALIASES.iter().map(|alias| alias.legacy_key)
|
||||
}
|
||||
|
||||
pub(crate) fn feature_for_key(key: &str) -> Option<Feature> {
|
||||
ALIASES
|
||||
.iter()
|
||||
.find(|alias| alias.legacy_key == key)
|
||||
.map(|alias| {
|
||||
log_alias(alias.legacy_key, alias.feature);
|
||||
alias.feature
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct LegacyFeatureToggles {
|
||||
pub experimental_use_unified_exec_tool: Option<bool>,
|
||||
}
|
||||
|
||||
impl LegacyFeatureToggles {
|
||||
pub fn apply(self, features: &mut Features) {
|
||||
set_if_some(
|
||||
features,
|
||||
Feature::UnifiedExec,
|
||||
self.experimental_use_unified_exec_tool,
|
||||
"experimental_use_unified_exec_tool",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_if_some(
|
||||
features: &mut Features,
|
||||
feature: Feature,
|
||||
maybe_value: Option<bool>,
|
||||
alias_key: &'static str,
|
||||
) {
|
||||
if let Some(enabled) = maybe_value {
|
||||
set_feature(features, feature, enabled);
|
||||
log_alias(alias_key, feature);
|
||||
features.record_legacy_usage(alias_key, feature);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_feature(features: &mut Features, feature: Feature, enabled: bool) {
|
||||
if enabled {
|
||||
features.enable(feature);
|
||||
} else {
|
||||
features.disable(feature);
|
||||
}
|
||||
}
|
||||
|
||||
fn log_alias(alias: &str, feature: Feature) {
|
||||
let canonical = feature.key();
|
||||
if alias == canonical {
|
||||
return;
|
||||
}
|
||||
info!(
|
||||
%alias,
|
||||
canonical,
|
||||
"legacy feature toggle detected; prefer `[features].{canonical}`"
|
||||
);
|
||||
}
|
||||
2472
akode-rs/features/src/lib.rs
Normal file
2472
akode-rs/features/src/lib.rs
Normal file
File diff suppressed because it is too large
Load Diff
31
akode-rs/features/src/runtime_auth.rs
Normal file
31
akode-rs/features/src/runtime_auth.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
//! Configuration for runtime assertions; enabling the feature is separate from selecting its mode.
|
||||
|
||||
use crate::FeatureConfig;
|
||||
use schemars::JsonSchema;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RuntimeAuthMode {
|
||||
/// Send the actor credential and a runtime assertion together during migration.
|
||||
#[default]
|
||||
DualHeader,
|
||||
/// Send only the runtime assertion as the request credential.
|
||||
AssertionOnly,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, Eq, JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RuntimeAgentInstancesConfigToml {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub mode: Option<RuntimeAuthMode>,
|
||||
}
|
||||
|
||||
impl FeatureConfig for RuntimeAgentInstancesConfigToml {
|
||||
fn enabled(&self) -> Option<bool> {
|
||||
self.enabled
|
||||
}
|
||||
}
|
||||
980
akode-rs/features/src/tests.rs
Normal file
980
akode-rs/features/src/tests.rs
Normal file
@@ -0,0 +1,980 @@
|
||||
use crate::Feature;
|
||||
use crate::FeatureConfigSource;
|
||||
use crate::FeatureOverrides;
|
||||
use crate::FeatureToml;
|
||||
use crate::Features;
|
||||
use crate::FeaturesToml;
|
||||
use crate::Stage;
|
||||
use crate::feature_for_key;
|
||||
use crate::unstable_features_warning_event;
|
||||
use akode_protocol::protocol::EventMsg;
|
||||
use akode_protocol::protocol::WarningEvent;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::collections::BTreeMap;
|
||||
use toml::Table;
|
||||
use toml::Value as TomlValue;
|
||||
|
||||
#[test]
|
||||
fn guardian_transcript_mode_rejects_invalid_values() {
|
||||
for input in [
|
||||
"[guardianv2]\ntranscript_mode = 'xml'",
|
||||
"[guardianv2]\ntranscript_mode = true",
|
||||
] {
|
||||
assert!(toml::from_str::<FeaturesToml>(input).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sleep_tool_config_rejects_unknown_mode() {
|
||||
assert!(toml::from_str::<FeaturesToml>("[sleep_tool]\nmode = 'off'").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_auth_config_accepts_modes_without_implicitly_enabling_the_feature() {
|
||||
for mode in ["dual_header", "assertion_only"] {
|
||||
let config: FeaturesToml =
|
||||
toml::from_str(&format!("[runtime_agent_instances]\nmode = '{mode}'")).unwrap();
|
||||
let mut features = Features::with_defaults();
|
||||
features.apply_toml(&config);
|
||||
assert!(!features.enabled(Feature::RuntimeAgentInstances));
|
||||
|
||||
let config: FeaturesToml = toml::from_str(&format!(
|
||||
"[runtime_agent_instances]\nenabled = true\nmode = '{mode}'"
|
||||
))
|
||||
.unwrap();
|
||||
features.apply_toml(&config);
|
||||
assert!(features.enabled(Feature::RuntimeAgentInstances));
|
||||
}
|
||||
assert!(
|
||||
toml::from_str::<FeaturesToml>("[runtime_agent_instances]\nmode = 'credential_only'")
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn under_development_features_are_disabled_by_default() {
|
||||
for spec in crate::FEATURES {
|
||||
// Instant interrupts are enabled by default while retaining their development stage.
|
||||
if matches!(spec.stage, Stage::UnderDevelopment) && spec.id != Feature::InstantInterrupt {
|
||||
assert_eq!(
|
||||
spec.default_enabled, false,
|
||||
"feature `{}` is under development and must be disabled by default",
|
||||
spec.key
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_registry_config_is_not_a_feature_toggle() {
|
||||
let features: FeaturesToml = toml::from_str(
|
||||
"[tool_registry]\nerror_on_tool_collisions = true\nturn_metadata_includes_tool_info = true\n",
|
||||
)
|
||||
.expect("tool registry settings should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.tool_registry,
|
||||
Some(crate::ToolRegistryConfigToml {
|
||||
error_on_tool_collisions: Some(true),
|
||||
turn_metadata_includes_tool_info: Some(true),
|
||||
})
|
||||
);
|
||||
assert!(features.entries().is_empty());
|
||||
assert!(crate::is_known_feature_key("tool_registry"));
|
||||
assert_eq!(feature_for_key("tool_registry"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn executor_capability_discovery_is_an_opt_in_map_feature() {
|
||||
let mut features = Features::with_defaults();
|
||||
assert!(!features.enabled(Feature::ExecutorCapabilityDiscovery));
|
||||
|
||||
features.apply_map(&BTreeMap::from([(
|
||||
"executor_capability_discovery".to_string(),
|
||||
true,
|
||||
)]));
|
||||
|
||||
assert!(features.enabled(Feature::ExecutorCapabilityDiscovery));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cwd_relative_turn_diffs_is_an_opt_in_map_feature() {
|
||||
let mut features = Features::with_defaults();
|
||||
assert!(!features.enabled(Feature::CwdRelativeTurnDiffs));
|
||||
|
||||
features.apply_map(&BTreeMap::from([(
|
||||
"cwd_relative_turn_diffs".to_string(),
|
||||
true,
|
||||
)]));
|
||||
|
||||
assert!(features.enabled(Feature::CwdRelativeTurnDiffs));
|
||||
|
||||
features.apply_map(&BTreeMap::from([(
|
||||
"cwd_relative_turn_diffs".to_string(),
|
||||
false,
|
||||
)]));
|
||||
|
||||
assert!(!features.enabled(Feature::CwdRelativeTurnDiffs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_enabled_features_have_shipped() {
|
||||
for spec in crate::FEATURES {
|
||||
// Instant interrupts are enabled by default while retaining their development stage.
|
||||
if spec.default_enabled && spec.id != Feature::InstantInterrupt {
|
||||
assert!(
|
||||
matches!(
|
||||
spec.stage,
|
||||
Stage::Stable | Stage::Deprecated | Stage::Removed
|
||||
),
|
||||
"feature `{}` is enabled by default at stage {:?}",
|
||||
spec.key,
|
||||
spec.stage
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn removed_apps_mcp_path_override_shapes_are_ignored() {
|
||||
let features = [
|
||||
toml::from_str::<FeaturesToml>("apps_mcp_path_override = true")
|
||||
.expect("boolean compatibility form should deserialize"),
|
||||
toml::from_str::<FeaturesToml>(
|
||||
r#"
|
||||
[apps_mcp_path_override]
|
||||
enabled = true
|
||||
path = "/custom/mcp"
|
||||
"#,
|
||||
)
|
||||
.expect("structured compatibility form should deserialize"),
|
||||
];
|
||||
|
||||
assert_eq!(
|
||||
features.map(|features| features.entries()),
|
||||
[BTreeMap::new(), BTreeMap::new()]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_mode_only_requires_code_mode() {
|
||||
let mut features = Features::with_defaults();
|
||||
features.enable(Feature::CodeModeOnly);
|
||||
features.normalize_dependencies();
|
||||
|
||||
assert_eq!(features.enabled(Feature::CodeModeOnly), true);
|
||||
assert_eq!(features.enabled(Feature::CodeMode), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_mode_host_feature_config_preserves_boolean_toggle() {
|
||||
let features: FeaturesToml =
|
||||
toml::from_str("code_mode_host = false").expect("features table should deserialize");
|
||||
|
||||
assert_eq!(features.code_mode_host, Some(FeatureToml::Enabled(false)));
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("code_mode_host".to_string(), false)])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_v2_feature_config_preserves_boolean_toggle() {
|
||||
let features: FeaturesToml =
|
||||
toml::from_str("guardianv2 = true").expect("Guardian v2 boolean should deserialize");
|
||||
|
||||
assert_eq!(features.guardianv2, Some(FeatureToml::Enabled(true)));
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("guardianv2".to_owned(), true)])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_v3_feature_config_resolves_base_and_profile_toggles() {
|
||||
for (base, profile, enabled) in [
|
||||
("guardianv3 = true", "", true),
|
||||
("guardianv3 = false", "", false),
|
||||
("[guardianv3]", "", false),
|
||||
("[guardianv3]\nenabled = true", "", true),
|
||||
("[guardianv3]\nenabled = false", "", false),
|
||||
(
|
||||
"[guardianv3]\nenabled = true",
|
||||
"[guardianv3]\nenabled = false",
|
||||
false,
|
||||
),
|
||||
(
|
||||
"[guardianv3]\nenabled = false",
|
||||
"[guardianv3]\nenabled = true",
|
||||
true,
|
||||
),
|
||||
("[guardianv3]\nenabled = true", "[guardianv3]", true),
|
||||
] {
|
||||
let base = toml::from_str::<FeaturesToml>(base).expect("base features");
|
||||
let profile = toml::from_str::<FeaturesToml>(profile).expect("profile features");
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&base),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource {
|
||||
features: Some(&profile),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
assert_eq!(features.enabled(Feature::GuardianV3), enabled);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_thread_context_is_ignored_with_a_migration_notice() {
|
||||
let enabled_context = "[guardianv2]\nthread_context = true";
|
||||
let disabled_context = "[guardianv2]\nthread_context = false";
|
||||
for (base, profile, deprecated) in [
|
||||
("", "", false),
|
||||
("guardianv2 = false", "", false),
|
||||
(disabled_context, "", true),
|
||||
(enabled_context, "", true),
|
||||
(enabled_context, disabled_context, true),
|
||||
(disabled_context, enabled_context, true),
|
||||
(
|
||||
"[guardianv2]\nenabled = false\nthread_context = true",
|
||||
"",
|
||||
true,
|
||||
),
|
||||
] {
|
||||
let base = toml::from_str::<FeaturesToml>(base).expect("base features");
|
||||
let profile = toml::from_str::<FeaturesToml>(profile).expect("profile features");
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&base),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource {
|
||||
features: Some(&profile),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
assert_eq!(
|
||||
features
|
||||
.legacy_feature_usages()
|
||||
.map(|usage| usage.alias.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
if deprecated {
|
||||
vec!["features.guardianv2.thread_context"]
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_v2_feature_config_deserializes_classifier_and_transcript_settings() {
|
||||
let features: FeaturesToml = toml::from_str(
|
||||
r#"
|
||||
[guardianv2]
|
||||
enabled = true
|
||||
free_guardian = true
|
||||
persist_scores = true
|
||||
classifier_instructions = "Review this action"
|
||||
review_threshold = 0.65
|
||||
max_tool_call_lag = 2
|
||||
async_classifier_conversation_token_limit = 120000
|
||||
reasoning_effort = "minimal"
|
||||
max_action_tokens = 512
|
||||
max_classifier_instruction_tokens = 256
|
||||
reuse_parent_compaction = false
|
||||
max_parent_compaction_tokens = 384
|
||||
|
||||
[guardianv2.review_scope]
|
||||
computer_use_only = true
|
||||
sandboxed_exec_commands = true
|
||||
|
||||
[guardianv2.transcript]
|
||||
sources = ["tool_outputs", "reasoning"]
|
||||
include_images = true
|
||||
max_message_entry_tokens = 128
|
||||
max_tool_entry_tokens = 128
|
||||
max_message_transcript_tokens = 512
|
||||
max_tool_transcript_tokens = 256
|
||||
max_recent_non_user_entries = 12
|
||||
"#,
|
||||
)
|
||||
.expect("Guardian v2 settings should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.guardianv2,
|
||||
Some(FeatureToml::Config(crate::GuardianV2ConfigToml {
|
||||
sync_elastic_budgeting: None,
|
||||
sync_elastic_sections: None,
|
||||
transcript_mode: None,
|
||||
async_classifier_mode: None,
|
||||
async_classifier_conversation_token_limit: Some(120_000),
|
||||
enabled: Some(true),
|
||||
free_guardian: Some(true),
|
||||
thread_context: None,
|
||||
persist_scores: Some(true),
|
||||
classifier_instructions: Some("Review this action".to_owned()),
|
||||
review_threshold: Some(0.65),
|
||||
max_tool_call_lag: Some(2),
|
||||
reasoning_effort: Some(akode_protocol::openai_models::ReasoningEffort::Minimal),
|
||||
max_action_tokens: Some(512),
|
||||
max_classifier_instruction_tokens: Some(256),
|
||||
reuse_parent_compaction: Some(false),
|
||||
max_parent_compaction_tokens: Some(384),
|
||||
review_scope: Some(crate::GuardianV2ReviewScopeConfigToml {
|
||||
computer_use_only: Some(true),
|
||||
sandboxed_exec_commands: Some(true),
|
||||
}),
|
||||
transcript: Some(crate::GuardianV2TranscriptConfigToml {
|
||||
sources: Some(vec![
|
||||
crate::GuardianV2TranscriptSource::ToolOutputs,
|
||||
crate::GuardianV2TranscriptSource::Reasoning,
|
||||
]),
|
||||
include_images: Some(true),
|
||||
max_message_entry_tokens: Some(128),
|
||||
max_tool_entry_tokens: Some(128),
|
||||
max_message_transcript_tokens: Some(512),
|
||||
max_tool_transcript_tokens: Some(256),
|
||||
max_recent_non_user_entries: Some(12),
|
||||
}),
|
||||
}))
|
||||
);
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("guardianv2".to_owned(), true)])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_v2_feature_config_rejects_invalid_settings() {
|
||||
for setting in [
|
||||
"max_action_tokens",
|
||||
"max_classifier_instruction_tokens",
|
||||
"max_parent_compaction_tokens",
|
||||
"transcript.max_message_entry_tokens",
|
||||
"transcript.max_tool_entry_tokens",
|
||||
"transcript.max_message_transcript_tokens",
|
||||
"transcript.max_tool_transcript_tokens",
|
||||
] {
|
||||
for value in [99, 100_001] {
|
||||
let settings = format!("[guardianv2]\n{setting} = {value}");
|
||||
assert!(
|
||||
toml::from_str::<FeaturesToml>(&settings).is_err(),
|
||||
"out-of-range Guardian v2 setting should fail: {setting} = {value}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for settings in [
|
||||
"review_threshold = -0.1",
|
||||
"review_threshold = 1.1",
|
||||
"review_threshold = nan",
|
||||
"async_classifier_conversation_token_limit = 0",
|
||||
"transcript.max_recent_non_user_entries = 0",
|
||||
"transcript.max_message_entry_tokens = 200\ntranscript.max_message_transcript_tokens = 100",
|
||||
"transcript.max_tool_entry_tokens = 200\ntranscript.max_tool_transcript_tokens = 100",
|
||||
] {
|
||||
assert!(
|
||||
toml::from_str::<FeaturesToml>(&format!("[guardianv2]\n{settings}")).is_err(),
|
||||
"invalid Guardian v2 settings should fail: {settings}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn guardian_v2_feature_config_accepts_boundary_values() {
|
||||
for (threshold, tokens) in [(0.0, 100), (1.0, 100_000)] {
|
||||
let features: FeaturesToml = toml::from_str(&format!(
|
||||
"[guardianv2]\n\
|
||||
review_threshold = {threshold:.1}\n\
|
||||
max_action_tokens = {tokens}\n\
|
||||
max_classifier_instruction_tokens = {tokens}\n\
|
||||
max_parent_compaction_tokens = {tokens}\n\
|
||||
[guardianv2.transcript]\n\
|
||||
max_message_entry_tokens = {tokens}\n\
|
||||
max_tool_entry_tokens = {tokens}\n\
|
||||
max_message_transcript_tokens = {tokens}\n\
|
||||
max_tool_transcript_tokens = {tokens}\n\
|
||||
max_recent_non_user_entries = 1"
|
||||
))
|
||||
.expect("Guardian v2 boundary settings should deserialize");
|
||||
|
||||
assert!(matches!(features.guardianv2, Some(FeatureToml::Config(_))));
|
||||
}
|
||||
|
||||
for setting in [
|
||||
"max_message_transcript_tokens",
|
||||
"max_tool_transcript_tokens",
|
||||
] {
|
||||
let features: FeaturesToml =
|
||||
toml::from_str(&format!("[guardianv2.transcript]\n{setting} = 100"))
|
||||
.expect("partial Guardian v2 transcript settings should deserialize");
|
||||
|
||||
assert!(matches!(features.guardianv2, Some(FeatureToml::Config(_))));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn code_mode_host_feature_config_deserializes_fallback_setting() {
|
||||
let features: FeaturesToml = toml::from_str(
|
||||
r#"
|
||||
[code_mode_host]
|
||||
enabled = true
|
||||
disable_in_process_fallback = true
|
||||
"#,
|
||||
)
|
||||
.expect("features table should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.code_mode_host,
|
||||
Some(FeatureToml::Config(crate::CodeModeHostConfigToml {
|
||||
enabled: Some(true),
|
||||
disable_in_process_fallback: Some(true),
|
||||
}))
|
||||
);
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("code_mode_host".to_string(), true)])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_terminal_resize_reflow_feature_key() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([(
|
||||
"terminal_resize_reflow".to_string(),
|
||||
false,
|
||||
)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
assert_eq!(features.enabled(Feature::TerminalResizeReflow), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_generation_extension_alias_is_supported() {
|
||||
assert_eq!(
|
||||
feature_for_key("imagegenext"),
|
||||
Some(Feature::ImageGeneration)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn image_generation_toggle_controls_extension_backed_generation() {
|
||||
let mut entries = BTreeMap::new();
|
||||
entries.insert("image_generation".to_string(), false);
|
||||
let mut features = Features::with_defaults();
|
||||
features.apply_map(&entries);
|
||||
assert!(!features.enabled(Feature::ImageGeneration));
|
||||
|
||||
entries.insert("image_generation".to_string(), true);
|
||||
features.disable(Feature::ImageGeneration);
|
||||
features.apply_map(&entries);
|
||||
assert!(features.enabled(Feature::ImageGeneration));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canonical_image_generation_toggle_wins_over_extension_alias() {
|
||||
for (canonical, alias) in [(false, true), (true, false)] {
|
||||
let entries = BTreeMap::from([
|
||||
("image_generation".to_string(), canonical),
|
||||
("imagegenext".to_string(), alias),
|
||||
]);
|
||||
let mut features = Features::with_defaults();
|
||||
features.apply_map(&entries);
|
||||
assert_eq!(features.enabled(Feature::ImageGeneration), canonical);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_legacy_landlock_config_records_deprecation_notice() {
|
||||
let mut entries = BTreeMap::new();
|
||||
entries.insert("use_legacy_landlock".to_string(), true);
|
||||
|
||||
let mut features = Features::with_defaults();
|
||||
features.apply_map(&entries);
|
||||
|
||||
let usages = features.legacy_feature_usages().collect::<Vec<_>>();
|
||||
assert_eq!(usages.len(), 1);
|
||||
assert_eq!(usages[0].alias, "features.use_legacy_landlock");
|
||||
assert_eq!(usages[0].feature, Feature::UseLegacyLandlock);
|
||||
assert_eq!(
|
||||
usages[0].summary,
|
||||
"`[features].use_legacy_landlock` is deprecated and will be removed soon."
|
||||
);
|
||||
assert_eq!(
|
||||
usages[0].details.as_deref(),
|
||||
Some("Remove this setting to stop opting into the legacy Linux sandbox behavior.")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remote_control_config_is_ignored() {
|
||||
let mut entries = BTreeMap::new();
|
||||
entries.insert("remote_control".to_string(), true);
|
||||
|
||||
let mut features = Features::with_defaults();
|
||||
features.apply_map(&entries);
|
||||
|
||||
assert_eq!(features.enabled(Feature::RemoteControl), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn telepathy_is_legacy_alias_for_chronicle() {
|
||||
assert_eq!(feature_for_key("chronicle"), Some(Feature::Chronicle));
|
||||
assert_eq!(feature_for_key("telepathy"), Some(Feature::Chronicle));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collab_is_legacy_alias_for_multi_agent() {
|
||||
assert_eq!(feature_for_key("multi_agent"), Some(Feature::Collab));
|
||||
assert_eq!(feature_for_key("collab"), Some(Feature::Collab));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn codex_hooks_is_legacy_alias_for_hooks() {
|
||||
assert_eq!(feature_for_key("hooks"), Some(Feature::CodexHooks));
|
||||
assert_eq!(feature_for_key("codex_hooks"), Some(Feature::CodexHooks));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apps_require_feature_flag_and_chatgpt_auth() {
|
||||
let mut features = Features::with_defaults();
|
||||
assert!(!features.apps_enabled_for_auth(/*has_chatgpt_auth*/ false));
|
||||
|
||||
features.enable(Feature::Apps);
|
||||
assert!(!features.apps_enabled_for_auth(/*has_chatgpt_auth*/ false));
|
||||
assert!(features.apps_enabled_for_auth(/*has_chatgpt_auth*/ true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_applies_base_profile_and_overrides() {
|
||||
let mut base_entries = BTreeMap::new();
|
||||
base_entries.insert("plugins".to_string(), true);
|
||||
let base_features = FeaturesToml {
|
||||
entries: base_entries,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut profile_entries = BTreeMap::new();
|
||||
profile_entries.insert("code_mode_only".to_string(), true);
|
||||
let profile_features = FeaturesToml {
|
||||
entries: profile_entries,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&base_features),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource {
|
||||
features: Some(&profile_features),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureOverrides {
|
||||
web_search_request: Some(false),
|
||||
},
|
||||
);
|
||||
|
||||
assert_eq!(features.enabled(Feature::Plugins), true);
|
||||
assert_eq!(features.enabled(Feature::CodeModeOnly), true);
|
||||
assert_eq!(features.enabled(Feature::CodeMode), true);
|
||||
assert_eq!(features.enabled(Feature::ApplyPatchFreeform), false);
|
||||
assert_eq!(features.enabled(Feature::WebSearchRequest), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_image_detail_original_feature_key() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([(
|
||||
"image_detail_original".to_string(),
|
||||
true,
|
||||
)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_resize_all_images_feature_key() {
|
||||
let features_toml =
|
||||
FeaturesToml::from(BTreeMap::from([("resize_all_images".to_string(), false)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_item_ids_feature_key() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([("item_ids".to_string(), false)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
assert_eq!(features.enabled(Feature::ItemIds), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_undo_feature_key() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([("undo".to_string(), true)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_js_repl_feature_keys() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([
|
||||
("js_repl".to_string(), true),
|
||||
("js_repl_tools_only".to_string(), true),
|
||||
]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_apply_patch_freeform_feature_key() {
|
||||
let features_toml =
|
||||
FeaturesToml::from(BTreeMap::from([("apply_patch_freeform".to_string(), true)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_accepts_and_ignores_removed_personality_feature_values() {
|
||||
for enabled in [false, true] {
|
||||
let features_toml: FeaturesToml = toml::from_str(&format!("personality = {enabled}"))
|
||||
.expect("legacy personality feature should deserialize");
|
||||
let source = FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
Features::from_sources(
|
||||
source,
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
),
|
||||
Features::with_defaults()
|
||||
);
|
||||
assert_eq!(
|
||||
Features::from_sources(
|
||||
FeatureConfigSource::default(),
|
||||
source,
|
||||
FeatureOverrides::default(),
|
||||
),
|
||||
Features::with_defaults()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_plugin_hooks_feature_key() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([("plugin_hooks".to_string(), true)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_sources_ignores_removed_tool_search_always_defer_mcp_tools_feature_key() {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([(
|
||||
"tool_search_always_defer_mcp_tools".to_string(),
|
||||
false,
|
||||
)]));
|
||||
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_agent_v2_feature_config_deserializes_boolean_toggle() {
|
||||
let features: FeaturesToml = toml::from_str(
|
||||
r#"
|
||||
multi_agent_v2 = true
|
||||
"#,
|
||||
)
|
||||
.expect("features table should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("multi_agent_v2".to_string(), true)])
|
||||
);
|
||||
assert_eq!(features.multi_agent_v2, Some(FeatureToml::Enabled(true)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_agent_v2_feature_config_deserializes_table() {
|
||||
let features: FeaturesToml = toml::from_str(
|
||||
r#"
|
||||
[multi_agent_v2]
|
||||
enabled = true
|
||||
max_concurrent_threads_per_session = 4
|
||||
min_wait_timeout_ms = 2500
|
||||
max_wait_timeout_ms = 120000
|
||||
default_wait_timeout_ms = 30000
|
||||
usage_hint_enabled = false
|
||||
usage_hint_text = "Custom delegation guidance."
|
||||
root_agent_usage_hint_text = "Root guidance."
|
||||
subagent_usage_hint_text = "Subagent guidance."
|
||||
subagent_developer_instructions = "Delegate carefully."
|
||||
preserve_fork_prefix = true
|
||||
multi_agent_mode_hint_text = "Custom mode guidance."
|
||||
tool_namespace = "agents"
|
||||
hide_spawn_agent_metadata = true
|
||||
expose_spawn_agent_model_overrides = true
|
||||
wait_agent_enabled = false
|
||||
disable_native_tools = true
|
||||
disable_direct_message = true
|
||||
message_board_in_memory = true
|
||||
non_code_mode_only = true
|
||||
"#,
|
||||
)
|
||||
.expect("features table should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("multi_agent_v2".to_string(), true)])
|
||||
);
|
||||
assert_eq!(
|
||||
features.multi_agent_v2,
|
||||
Some(crate::FeatureToml::Config(crate::MultiAgentV2ConfigToml {
|
||||
enabled: Some(true),
|
||||
max_concurrent_threads_per_session: Some(4),
|
||||
min_wait_timeout_ms: Some(2500),
|
||||
max_wait_timeout_ms: Some(120000),
|
||||
default_wait_timeout_ms: Some(30000),
|
||||
usage_hint_enabled: Some(false),
|
||||
usage_hint_text: Some("Custom delegation guidance.".to_string()),
|
||||
root_agent_usage_hint_text: Some("Root guidance.".to_string()),
|
||||
subagent_usage_hint_text: Some("Subagent guidance.".to_string()),
|
||||
subagent_developer_instructions: Some("Delegate carefully.".to_string()),
|
||||
preserve_fork_prefix: Some(true),
|
||||
multi_agent_mode_hint_text: Some("Custom mode guidance.".to_string()),
|
||||
tool_namespace: Some("agents".to_string()),
|
||||
hide_spawn_agent_metadata: Some(true),
|
||||
expose_spawn_agent_model_overrides: Some(true),
|
||||
wait_agent_enabled: Some(false),
|
||||
disable_native_tools: Some(true),
|
||||
disable_direct_message: Some(true),
|
||||
message_board_in_memory: Some(true),
|
||||
message_board_remote: None,
|
||||
non_code_mode_only: Some(true),
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_prefixed_mcp_tool_names_feature_config_deserializes_boolean_toggle() {
|
||||
let features: FeaturesToml = toml::from_str("non_prefixed_mcp_tool_names = true")
|
||||
.expect("features table should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("non_prefixed_mcp_tool_names".to_string(), true)])
|
||||
);
|
||||
assert_eq!(
|
||||
features.non_prefixed_mcp_tool_names,
|
||||
Some(FeatureToml::Enabled(true))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_prefixed_mcp_tool_names_feature_config_deserializes_table() {
|
||||
let features: FeaturesToml = toml::from_str(
|
||||
r#"
|
||||
[non_prefixed_mcp_tool_names]
|
||||
enabled = true
|
||||
server_names = ["history", "notes"]
|
||||
"#,
|
||||
)
|
||||
.expect("features table should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
features.entries(),
|
||||
BTreeMap::from([("non_prefixed_mcp_tool_names".to_string(), true)])
|
||||
);
|
||||
assert_eq!(
|
||||
features.non_prefixed_mcp_tool_names,
|
||||
Some(FeatureToml::Config(
|
||||
crate::NonPrefixedMcpToolNamesConfigToml {
|
||||
enabled: Some(true),
|
||||
server_names: Some(vec!["history".to_string(), "notes".to_string()]),
|
||||
}
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unstable_warning_event_only_mentions_enabled_under_development_features() {
|
||||
let mut configured_features = Table::new();
|
||||
configured_features.insert(
|
||||
"apply_patch_streaming_events".to_string(),
|
||||
TomlValue::Boolean(true),
|
||||
);
|
||||
configured_features.insert("fast_mode".to_string(), TomlValue::Boolean(true));
|
||||
configured_features.insert("unknown".to_string(), TomlValue::Boolean(true));
|
||||
|
||||
let mut features = Features::with_defaults();
|
||||
features.enable(Feature::ApplyPatchStreamingEvents);
|
||||
|
||||
let warning = unstable_features_warning_event(
|
||||
Some(&configured_features),
|
||||
/*suppress_unstable_features_warning*/ false,
|
||||
&features,
|
||||
"/tmp/config.toml",
|
||||
)
|
||||
.expect("warning event");
|
||||
|
||||
let EventMsg::Warning(WarningEvent { message }) = warning.msg else {
|
||||
panic!("expected warning event");
|
||||
};
|
||||
assert!(message.contains("apply_patch_streaming_events"));
|
||||
assert!(!message.contains("fast_mode"));
|
||||
assert!(message.contains("/tmp/config.toml"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unstable_warning_event_ignores_enabled_structured_stable_feature() {
|
||||
let configured_features: Table = toml::from_str(
|
||||
r#"
|
||||
multi_agent_v2 = { enabled = true, tool_namespace = "agents" }
|
||||
code_mode = true
|
||||
"#,
|
||||
)
|
||||
.expect("features table should deserialize");
|
||||
|
||||
let mut features = Features::with_defaults();
|
||||
features.enable(Feature::MultiAgentV2);
|
||||
features.enable(Feature::CodeMode);
|
||||
|
||||
let warning = unstable_features_warning_event(
|
||||
Some(&configured_features),
|
||||
/*suppress_unstable_features_warning*/ false,
|
||||
&features,
|
||||
"/tmp/config.toml",
|
||||
)
|
||||
.expect("warning event");
|
||||
|
||||
let EventMsg::Warning(WarningEvent { message }) = warning.msg else {
|
||||
panic!("expected warning event");
|
||||
};
|
||||
assert_eq!(
|
||||
"Under-development features enabled: code_mode. Under-development features are incomplete and may behave unpredictably. To suppress this warning, set `suppress_unstable_features_warning = true` in /tmp/config.toml.".to_string(),
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retired_worktree_and_voice_config_overrides_are_ignored() {
|
||||
for enabled in [false, true] {
|
||||
let features_toml = FeaturesToml::from(BTreeMap::from([
|
||||
("worktrees".to_string(), enabled),
|
||||
("realtime_conversation".to_string(), enabled),
|
||||
]));
|
||||
let features = Features::from_sources(
|
||||
FeatureConfigSource {
|
||||
features: Some(&features_toml),
|
||||
..Default::default()
|
||||
},
|
||||
FeatureConfigSource::default(),
|
||||
FeatureOverrides::default(),
|
||||
);
|
||||
assert_eq!(features, Features::with_defaults());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn model_change_suppression_config_preserves_omission_and_explicit_values() {
|
||||
for (input, expected) in [
|
||||
("", false),
|
||||
("suppress_model_change_announcements = false", false),
|
||||
("suppress_model_change_announcements = true", true),
|
||||
] {
|
||||
let config: FeaturesToml = toml::from_str(input).unwrap();
|
||||
let mut features = Features::with_defaults();
|
||||
features.apply_toml(&config);
|
||||
assert_eq!(
|
||||
features.enabled(Feature::SuppressModelChangeAnnouncements),
|
||||
expected,
|
||||
"{input}"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user