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
4 changes: 3 additions & 1 deletion crates/tinycomputer-engine/src/agentic/flow/act/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ const MOVES: &[(&str, &str)] = &[

/// Standard macOS shortcuts that are safe to try: none sends, deletes, or
/// quits. `confirm` (Return) commits text typed into a field; it is refused
/// while a sheet or alert is showing, where Return presses the default button.
/// while a sheet or alert is showing, where Return presses the default button,
/// and outside a search box in a flow with a `stop_before`, where Return may
/// send.
pub(super) const SHORTCUTS: &[(&str, &str, &str)] = &[
(
"new_item",
Expand Down
6 changes: 6 additions & 0 deletions crates/tinycomputer-engine/src/agentic/flow/act/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ impl<B: AgentBackend + Sync> FlowRun<'_, B> {
));
return Ok(Move::Skipped);
}
// In a composer Return sends: a flow that stops before an
// irreversible step must press a control, which is gated.
if combo == "return" && !searching && !self.stop_before.is_empty() {
self.history.push("refused return: this flow stops before an irreversible step, and Return may perform it; press the control instead".to_owned());
return Ok(Move::Skipped);
}
let app = self.app.clone();
let reply = self
.act(log, &format!("press {combo}"), None, move |backend| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,24 @@ fn a_pressed_controls_copies_are_only_on_the_other_items_of_its_list() {
"the bar's own has none"
);
}

#[tokio::test]
async fn return_is_not_pressed_when_the_flow_stops_before_sending() {
// In a message composer Return sends. The flow declared it stops before
// sending, so the "confirm" shortcut must not press Return unasked.
let run = run_with(
App::default(),
json!({"app": "Mail", "steps": [
"confirm the message text",
{"stop_before": "sending the message"}
]}),
|request| request.max_actions = 2,
|id, question, _| match id {
"shortcut" => Some(pick(question, "confirm", 0.9)),
_ => None,
},
)
.await;
let presses = run.app.sim().presses.clone();
assert!(!presses.iter().any(|key| key == "return"), "{presses:?}");
}
57 changes: 41 additions & 16 deletions crates/tinycomputer-engine/src/agentic/flow/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,51 @@ pub(in crate::agentic) fn is_banned(
banned.contains(&signature(candidate)) || banned.contains(&press_key(candidate))
}

/// Words that commit to something wherever they sit in a label ("Post",
/// "Transfer $500", "Log out"). Matched as whole words, so "Postcode" and
/// "Design" stay pressable; "sign" counts unless it is signing in.
const COMMITTING_WORDS: &[&str] = &[
"post",
"transfer",
"checkout",
"check out",
"log out",
"logout",
"sign",
];

/// Whether a lower-cased label names an action that is hard to undo. A
/// counter's minus button ("remove adult") is not: it only lowers a number.
pub(in crate::agentic) fn destructive_label(evidence: &str) -> bool {
let words = format!(
" {} ",
evidence
.split(|character: char| !character.is_alphanumeric())
.filter(|word| !word.is_empty())
.collect::<Vec<_>>()
.join(" ")
)
.replace(" sign in ", " ");
!tinycomputer_core::adjusts_a_count(evidence)
&& [
"delete",
"remove",
"send",
"purchase",
"buy",
"pay",
"submit",
"confirm",
"overwrite",
"quit without saving",
"empty trash",
"sign out",
]
.iter()
.any(|term| evidence.contains(term))
&& (COMMITTING_WORDS
.iter()
.any(|word| words.contains(&format!(" {word} ")))
|| [
"delete",
"remove",
"send",
"purchase",
"buy",
"pay",
"submit",
"confirm",
"overwrite",
"quit without saving",
"empty trash",
"sign out",
]
.iter()
.any(|term| evidence.contains(term)))
}

/// Whether `label` is named by a `stop_before` phrase the flow itself
Expand Down
34 changes: 34 additions & 0 deletions crates/tinycomputer-engine/src/agentic/flow/view/view_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,37 @@ fn the_elements_a_purpose_names_are_offered_first_in_their_own_order() {
"filler names nothing"
);
}

#[test]
fn posting_transferring_checking_out_paying_deleting_logging_out_and_signing_are_destructive() {
let screen = clickable_screen();
let pressable: Vec<&str> = [
"Post",
"Transfer $500",
"Checkout",
"Check out",
"Pay",
"Delete",
"Log out",
"Sign",
"Sign up",
]
.into_iter()
.filter(|name| !is_destructive(&button(name), &screen, &[]))
.collect();
assert!(
pressable.is_empty(),
"pressed with no approval: {pressable:?}"
);
// Signing in commits to nothing, and a word that only contains one of
// these is not one of them.
for name in [
"Sign in",
"Sign-in with Google",
"Postcode",
"Design",
"Logo",
] {
assert!(!is_destructive(&button(name), &screen, &[]), "{name}");
}
}
Loading