mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Require approval for input to escalated terminals (#40978)
## What changed - Add the `write_stdin_approval` feature flag, disabled by default, to require a fresh approval before sending non-empty input to an escalated unified-exec terminal. - Route these reviews through hooks, Guardian, app-server, and the TUI as `writeStdin` approvals while keeping the parent command item unchanged. - Preserve the terminal environment, launch directory, and escalation state across turns, and revalidate the process identity after approval before writing input. ## Testing - Cover approval routing, policy decisions, process reuse, terminal identity preservation, app-server events, analytics, and TUI rendering. GitOrigin-RevId: 4ba29eaae6208e934737ba078c96e589c7c2164d
This commit is contained in:
1 parent
21ff2e802c
commit
a57b398351
41 files changed
+861
-169
No files matched your search
@@ -7,6 +7,9 @@ use crate::tools::registry::CoreToolRuntime;
|
||||
use crate::tools::registry::PostToolUsePayload;
|
||||
use crate::tools::registry::PreToolUsePayload;
|
||||
use crate::tools::registry::ToolExecutor;
|
||||
use crate::tools::sandboxing::ToolError;
|
||||
use crate::unified_exec::UnifiedExecContext;
|
||||
use crate::unified_exec::UnifiedExecError;
|
||||
use crate::unified_exec::WriteStdinInteractionEvent;
|
||||
use crate::unified_exec::WriteStdinRequest;
|
||||
use codex_tools::ToolName;
|
||||
@@ -56,6 +59,9 @@ impl WriteStdinHandler {
|
||||
let ToolInvocation {
|
||||
session,
|
||||
turn,
|
||||
step_context,
|
||||
cancellation_token,
|
||||
call_id,
|
||||
payload,
|
||||
..
|
||||
} = invocation;
|
||||
@@ -70,23 +76,37 @@ impl WriteStdinHandler {
|
||||
};
|
||||
|
||||
let args: WriteStdinArgs = parse_arguments(&arguments)?;
|
||||
let context =
|
||||
UnifiedExecContext::new(session.clone(), step_context, cancellation_token, call_id);
|
||||
let response = session
|
||||
.services
|
||||
.unified_exec_manager
|
||||
.write_stdin(WriteStdinRequest {
|
||||
process_id: args.session_id,
|
||||
input: &args.chars,
|
||||
yield_time_ms: args.yield_time_ms,
|
||||
max_output_tokens: args.max_output_tokens,
|
||||
truncation_policy: turn.model_info().truncation_policy.into(),
|
||||
interaction_event: Some(WriteStdinInteractionEvent {
|
||||
session: &session,
|
||||
turn: &turn,
|
||||
}),
|
||||
})
|
||||
.write_stdin(
|
||||
&context,
|
||||
WriteStdinRequest {
|
||||
process_id: args.session_id,
|
||||
input: &args.chars,
|
||||
yield_time_ms: args.yield_time_ms,
|
||||
max_output_tokens: args.max_output_tokens,
|
||||
truncation_policy: turn.model_info().truncation_policy.into(),
|
||||
interaction_event: Some(WriteStdinInteractionEvent {
|
||||
session: &session,
|
||||
turn: &turn,
|
||||
}),
|
||||
},
|
||||
)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
FunctionCallError::RespondToModel(format!("write_stdin failed: {err}"))
|
||||
let message = match err {
|
||||
UnifiedExecError::StdinApproval(ToolError::Rejected(reason)) => {
|
||||
format!("write_stdin rejected: {reason}")
|
||||
}
|
||||
UnifiedExecError::StdinApproval(ToolError::Codex(err)) => {
|
||||
format!("write_stdin approval failed: {err}")
|
||||
}
|
||||
err => format!("write_stdin failed: {err}"),
|
||||
};
|
||||
FunctionCallError::RespondToModel(message)
|
||||
})?;
|
||||
|
||||
Ok(boxed_tool_output(response))
|
||||
|
||||
Reference in new issue
Block a user