Skip to content
Merged
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
24 changes: 16 additions & 8 deletions crates/noa-app/src/app/auto_approve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ impl App {
else {
return;
};
let reject = || {
let reject = |why: &str| {
if auto_approve::trace_enabled() {
eprintln!("[auto-approve] reject {signature:?}: {why}");
}
let _ = feedback_tx.send(AutoApproveFeedback {
signature,
region_hash,
accepted: false,
});
};
if !pane_live || !auto_enabled {
reject();
reject(if pane_live { "mode off" } else { "pane gone" });
return;
}

Expand All @@ -53,11 +56,13 @@ impl App {
.get(&id)
.and_then(|card| card.process.clone())
else {
reject();
reject("no foreground process name yet");
return;
};
if classify_agent(&process) != signature.agent() {
reject();
reject(&format!(
"foreground process {process:?} is not the prompt's agent"
));
return;
}

Expand All @@ -67,7 +72,7 @@ impl App {
.get(&window_id)
.and_then(|state| state.surfaces.get(&pane_id))
else {
reject();
reject("surface gone");
return;
};
let terminal = surface.terminal.lock();
Expand All @@ -77,7 +82,7 @@ impl App {
scrollback_offset: terminal.viewport_offset(),
guards: *surface.auto_approve_guards.lock(),
};
let rows = auto_approve::viewport_rows_from_terminal(&terminal);
let rows = auto_approve::live_rows_from_terminal(&terminal);
let cursor = terminal.active().cursor;
auto_approve::rescan_signature(
&rows,
Expand All @@ -90,17 +95,20 @@ impl App {
)
};
if live_match.is_none_or(|matched| matched.region_hash != region_hash) {
reject();
reject("prompt changed or suppressed at injection time");
return;
}

match self.queue_pane_pty_bytes(window_id, pane_id, signature.bytes()) {
QueueInputResult::Queued | QueueInputResult::Deferred => {}
QueueInputResult::Dropped | QueueInputResult::Disconnected => {
reject();
reject("pty input queue refused the bytes");
return;
}
}
if auto_approve::trace_enabled() {
eprintln!("[auto-approve] sent {signature:?} to {process:?}");
}
let _ = feedback_tx.send(AutoApproveFeedback {
signature,
region_hash,
Expand Down
Loading