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:
Dylan Hurd authored and copyberry committed 2026-08-26 21:39:05 +00:00
1 parent 21ff2e802c
commit a57b398351
41 files changed
+861 -169

No files matched your search

@@ -26,16 +26,10 @@ pub(crate) enum GuardianApprovalRequest {
justification: Option<String>,
tty: bool,
},
#[cfg_attr(
not(test),
expect(
dead_code,
reason = "Constructed by the follow-up stdin approval routing change"
)
)]
WriteStdin {
id: String,
approval_id: String,
environment_id: String,
process_id: i32,
input: String,
cwd: PathUri,
@@ -129,6 +123,7 @@ struct CommandApprovalAction<'a> {
#[derive(Serialize)]
struct WriteStdinApprovalAction<'a> {
tool: &'static str,
environment_id: &'a str,
session_id: i32,
chars: &'a str,
cwd: LegacyAppPathString,
@@ -300,6 +295,7 @@ pub(crate) fn guardian_approval_request_to_json(
Some(*tty),
),
GuardianApprovalRequest::WriteStdin {
environment_id,
process_id,
input,
cwd,
@@ -307,6 +303,7 @@ pub(crate) fn guardian_approval_request_to_json(
..
} => serialize_guardian_action(WriteStdinApprovalAction {
tool: "write_stdin",
environment_id,
session_id: *process_id,
chars: input,
cwd: cwd.clone().into(),
+5 -3
View File
@@ -313,10 +313,12 @@ pub(crate) async fn build_guardian_prompt_items_with_parent_turn(
push_text("Retry reason:\n".to_string());
push_text(format!("{reason}\n\n"));
}
push_text(
let action_scope = if matches!(&request, GuardianApprovalRequest::WriteStdin { .. }) {
"Assess input to the existing terminal, not a fresh command. The `cwd` field is its launch directory; the terminal's current directory and state may have changed. Use the retained transcript and read-only checks when that state matters.\n"
} else {
"Assess the exact planned action below. Use read-only tool checks when local state matters.\n"
.to_string(),
);
};
push_text(action_scope.to_string());
push_text("Planned action JSON:\n".to_string());
}
}
+2
View File
@@ -1371,6 +1371,7 @@ fn guardian_write_stdin_preserves_input_and_foreign_cwd() -> serde_json::Result<
let action = GuardianApprovalRequest::WriteStdin {
id: "terminal-open".to_string(),
approval_id: "terminal-write".to_string(),
environment_id: "windows-executor".to_string(),
process_id: 1000,
input: input.to_string(),
cwd: cwd.clone(),
@@ -1381,6 +1382,7 @@ fn guardian_write_stdin_preserves_input_and_foreign_cwd() -> serde_json::Result<
guardian_approval_request_to_json(&action)?,
serde_json::json!({
"tool": "write_stdin",
"environment_id": "windows-executor",
"session_id": 1000,
"chars": input,
"cwd": r"C:\workspace",