Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/tui/src/core/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ pub struct EngineConfig {
/// When true, the model is instructed to respond in the current locale
/// and a post-hoc translation layer replaces remaining English output.
pub translation_enabled: bool,
/// When false, thinking blocks are hidden in the TUI. Propagated to the
/// system prompt builder so `reasoning_content` stays in English (saving
/// tokens) while the final reply still matches the user's language.
pub show_thinking: bool,
/// Maximum number of assistant steps before stopping.
pub max_steps: u32,
/// Maximum number of concurrently active subagents.
Expand Down Expand Up @@ -181,6 +185,7 @@ impl Default for EngineConfig {
instructions: Vec::new(),
project_context_pack_enabled: true,
translation_enabled: false,
show_thinking: true,
max_steps: 100,
max_subagents: DEFAULT_MAX_SUBAGENTS,
features: Features::with_defaults(),
Expand Down Expand Up @@ -434,6 +439,7 @@ impl Engine {
project_context_pack_enabled: config.project_context_pack_enabled,
locale_tag: &config.locale_tag,
translation_enabled: config.translation_enabled,
show_thinking: config.show_thinking,
},
session.approval_mode,
);
Expand Down Expand Up @@ -589,6 +595,7 @@ impl Engine {
auto_approve,
approval_mode,
translation_enabled,
show_thinking,
} => {
self.handle_send_message(
content,
Expand All @@ -603,6 +610,7 @@ impl Engine {
auto_approve,
approval_mode,
translation_enabled,
show_thinking,
)
.await;
}
Expand Down Expand Up @@ -802,6 +810,7 @@ impl Engine {
self.session.auto_approve,
self.session.approval_mode,
self.config.translation_enabled,
self.config.show_thinking,
)
.await;
}
Expand Down Expand Up @@ -890,6 +899,7 @@ impl Engine {
auto_approve: bool,
approval_mode: crate::tui::approval::ApprovalMode,
translation_enabled: bool,
show_thinking: bool,
) {
// Reset cancel token for fresh turn (in case previous was cancelled)
self.reset_cancel_token();
Expand Down Expand Up @@ -973,6 +983,7 @@ impl Engine {
self.session.trust_mode = trust_mode;
self.config.trust_mode = trust_mode;
self.config.translation_enabled = translation_enabled;
self.config.show_thinking = show_thinking;
self.session.auto_approve = auto_approve;
self.session.approval_mode = if auto_approve {
crate::tui::approval::ApprovalMode::Auto
Expand Down Expand Up @@ -1792,6 +1803,7 @@ impl Engine {
project_context_pack_enabled: self.config.project_context_pack_enabled,
locale_tag: &self.config.locale_tag,
translation_enabled: self.config.translation_enabled,
show_thinking: self.config.show_thinking,
},
self.session.approval_mode,
);
Expand Down
1 change: 1 addition & 0 deletions crates/tui/src/core/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum Op {
auto_approve: bool,
approval_mode: ApprovalMode,
translation_enabled: bool,
show_thinking: bool,
},

/// Cancel the current request
Expand Down
2 changes: 2 additions & 0 deletions crates/tui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4636,6 +4636,7 @@ async fn run_exec_agent(
instructions: config.instructions_paths(),
project_context_pack_enabled: config.project_context_pack_enabled(),
translation_enabled: false,
show_thinking: true,
max_steps: 100,
max_subagents,
features: config.features(),
Expand Down Expand Up @@ -4725,6 +4726,7 @@ async fn run_exec_agent(
trust_mode,
auto_approve,
translation_enabled: false,
show_thinking: true,
approval_mode: if auto_approve {
crate::tui::approval::ApprovalMode::Auto
} else {
Expand Down
33 changes: 33 additions & 0 deletions crates/tui/src/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pub struct PromptSessionContext<'a> {
/// to the system prompt instructing the model to respond in
/// the resolved session locale.
pub translation_enabled: bool,
/// When false, the user has hidden thinking blocks in the UI.
/// The prompt builder injects a language override so
/// `reasoning_content` stays in English (saving tokens) while
/// the final reply still matches the user's language.
pub show_thinking: bool,
}

/// Conventional location for the structured session relay artifact (#32).
Expand Down Expand Up @@ -549,6 +554,7 @@ pub fn system_prompt_for_mode_with_context_and_skills(
project_context_pack_enabled: true,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
)
}
Expand Down Expand Up @@ -641,6 +647,23 @@ pub fn system_prompt_for_mode_with_context_skills_session_and_approval(
);
}

// 2.3b. Thinking language override — when the user has hidden
// thinking blocks in the UI, redirect reasoning_content to
// English regardless of user language. This saves tokens
// (English is the most token-efficient language) while keeping
// the final reply in the user's language as described above.
if !session_context.show_thinking {
full_prompt.push_str(
"\n\n## Thinking Language\n\n\
The user has disabled thinking display in settings — they will \
never see your `reasoning_content`. Therefore, your internal \
thinking MUST be in English regardless of the user's language. \
This directive overrides the `## Language` section above for \
reasoning_content only. Your final reply must STILL match the \
user's language.",
);
}

// 3. Skills block. #432: walks every candidate workspace
// skills directory (`.agents/skills`, `skills`,
// `.opencode/skills`, `.claude/skills`, `.cursor/skills`) plus global
Expand Down Expand Up @@ -881,6 +904,7 @@ mod tests {
project_context_pack_enabled: false,
locale_tag: "zh-Hans",
translation_enabled: false,
show_thinking: true,
},
ApprovalMode::Suggest,
) {
Expand Down Expand Up @@ -950,6 +974,7 @@ mod tests {
project_context_pack_enabled: false,
locale_tag: "zh-Hans",
translation_enabled: false,
show_thinking: true,
},
ApprovalMode::Suggest,
) {
Expand Down Expand Up @@ -994,6 +1019,7 @@ mod tests {
project_context_pack_enabled: false,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
ApprovalMode::Suggest,
) {
Expand Down Expand Up @@ -1083,6 +1109,7 @@ mod tests {
project_context_pack_enabled: true,
locale_tag: "ja",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down Expand Up @@ -1118,6 +1145,7 @@ mod tests {
project_context_pack_enabled: false,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down Expand Up @@ -1145,6 +1173,7 @@ mod tests {
project_context_pack_enabled: false,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down Expand Up @@ -1174,6 +1203,7 @@ mod tests {
project_context_pack_enabled: false,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down Expand Up @@ -1201,6 +1231,7 @@ mod tests {
project_context_pack_enabled: true,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down Expand Up @@ -1395,6 +1426,7 @@ mod tests {
project_context_pack_enabled: true,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down Expand Up @@ -1428,6 +1460,7 @@ mod tests {
project_context_pack_enabled: true,
locale_tag: "en",
translation_enabled: false,
show_thinking: true,
},
) {
SystemPrompt::Text(text) => text,
Expand Down
2 changes: 2 additions & 0 deletions crates/tui/src/runtime_threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,7 @@ impl RuntimeThreadManager {
trust_mode,
auto_approve,
translation_enabled: false,
show_thinking: false,
approval_mode: if auto_approve {
crate::tui::approval::ApprovalMode::Auto
} else {
Expand Down Expand Up @@ -1933,6 +1934,7 @@ impl RuntimeThreadManager {
instructions: self.config.instructions_paths(),
project_context_pack_enabled: self.config.project_context_pack_enabled(),
translation_enabled: false,
show_thinking: false,
max_steps: 100,
max_subagents: self.config.max_subagents().clamp(1, MAX_SUBAGENTS),
features: self.config.features(),
Expand Down
3 changes: 3 additions & 0 deletions crates/tui/src/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ fn build_engine_config(app: &App, config: &Config) -> EngineConfig {
instructions: config.instructions_paths(),
project_context_pack_enabled: config.project_context_pack_enabled(),
translation_enabled: app.translation_enabled,
show_thinking: app.show_thinking,
// Effectively unlimited. V4 has a 1M context window and the user
// wants the model running until it's actually done. The previous cap
// of 100 hit the ceiling on long multi-step plans (wide refactors,
Expand Down Expand Up @@ -3882,6 +3883,7 @@ async fn dispatch_user_message(
project_context_pack_enabled: config.project_context_pack_enabled(),
locale_tag: app.ui_locale.tag(),
translation_enabled: app.translation_enabled,
show_thinking: app.show_thinking,
},
),
);
Expand Down Expand Up @@ -3978,6 +3980,7 @@ async fn dispatch_user_message(
auto_approve: app.mode == AppMode::Yolo,
approval_mode: app.approval_mode,
translation_enabled: app.translation_enabled,
show_thinking: app.show_thinking,
})
.await
{
Expand Down