Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Glance: writes named like reads keep the full card on the island (22h) (#716)

Oleksandr Ivanchenkodda22844069c
diff --git a/src/server/glance.rs b/src/server/glance.rs
index beb7dee6..ffbb4b9d 100644
--- a/src/server/glance.rs
+++ b/src/server/glance.rs
@@ -187,18 +187,36 @@ const OUTWARD_NOUNS: &[&str] = &["EMAIL", "MAIL", "DROP", "POST", "PAY", "SHARE"
const OUTWARD_NAME_WORDS: &[&str] = &["ship", "rollout"];
/// Whole words that, with the [`READ_VERBS`], say a name with only [`OUTWARD_NOUNS`] in it reads
-/// (21a). Local to the outward layer: `fetch` must not join [`READ_VERBS`], where it would lift
-/// push and commit words too.
-const OUTWARD_READ_WORDS: &[&str] = &["fetch"];
+/// (21a). Local to the outward layer: these must not join [`READ_VERBS`], where they would lift
+/// push and commit words too. 22h: `retrieve` (`STRIPE_RETRIEVE_PAYMENT_INTENT`, Rigel's F3) and
+/// `check` (`check_payment_status`, which the state route no longer lifts on its own).
+const OUTWARD_READ_WORDS: &[&str] = &["fetch", "retrieve", "check"];
/// Last words of a tool name that make it a read of something's state: `rollout_status`,
-/// `get_payment_status`, `ship_state` (21a).
+/// `ship_state` (21a). Only for payments, a ship or a rollout, and only in a short name
+/// ([`reads_state`], 22h).
const OUTWARD_READ_LAST_WORDS: &[&str] = &["status", "state"];
+/// The one part of [`OUTWARD_NOUNS`] whose state a name may read by ending in
+/// [`OUTWARD_READ_LAST_WORDS`] without a read verb (22h), with the [`OUTWARD_NAME_WORDS`]:
+/// `payment_status`, `rollout_status`, `ship_status`. A post, share, upload, mail or drop status is
+/// as often a write (`post_status`, `share_status`), so those need a read verb.
+const STATE_NOUNS: &[&str] = &["PAY"];
+
+/// [`OUTWARD_NOUNS`] and [`OUTWARD_NAME_WORDS`] as whole lowercase words: the outward thing used
+/// as a verb. One of these as a name's first word, ahead of its read word, acts: `post_list`,
+/// `share_get` (22h). After a Composio app prefix the second word counts (`SLACK_SHARE_GET`), and
+/// `DROPBOX_`, `GMAIL_`, `SHAREPOINT_` and `payment` aren't whole outward words, so they don't count.
+const OUTWARD_VERB_WORDS: &[&str] = &["email", "mail", "drop", "post", "pay", "share", "upload", "ship", "rollout"];
+
/// Whole words that add a second action to a read name, so the read verb can't vouch for it:
/// `find_and_share_file`, `get_then_pay`, `list_or_create_posts` (via `create`), `fetch_and_reply` (21a).
+/// 22h (Rigel's F1 on #692): `change_post_status`, `retry_payment_status`, `MAILCHIMP_SUBSCRIBE_TO_LIST`,
+/// `join_mailing_list`, `MAILCHIMP_ARCHIVE_MEMBER_FROM_LIST`.
const SECOND_ACTION_WORDS: &[&str] = &[
"and", "then", "create", "update", "add", "set", "put", "write", "edit", "modify", "reply", "save", "schedule", "upsert", "insert",
+ // 22h
+ "change", "toggle", "retry", "capture", "refund", "subscribe", "unsubscribe", "join", "leave", "archive",
];
/// Whole words in the value of an `action`, `operation` or `op` argument ([`is_action_key`]) that
@@ -376,19 +394,50 @@ fn outward_by_name(tool: &str) -> bool {
}
let name = words(tool);
let noun = OUTWARD_NOUNS.iter().any(|w| upper.contains(w)) || name.iter().any(|w| OUTWARD_NAME_WORDS.contains(&w.as_str()));
- noun && !reads_outward_noun(&name)
+ noun && !reads_outward_noun(tool, &name)
}
-/// Whether a name (already split by [`words`]) whose only outward words are nouns only reads them
-/// (21a): it has a [`READ_VERBS`] or [`OUTWARD_READ_WORDS`] word, or ends in one of
-/// [`OUTWARD_READ_LAST_WORDS`], and has none of [`SECOND_ACTION_WORDS`]. `GMAIL_LIST_THREADS`,
-/// `WORDPRESS_GET_POST` and `ship_status` read; `GMAIL_REPLY_TO_THREAD`, `find_and_share_file` and
-/// `set_payment_status` don't.
-fn reads_outward_noun(name: &[String]) -> bool {
- let read = reads(name)
- || name.iter().any(|w| OUTWARD_READ_WORDS.contains(&w.as_str()))
- || name.last().is_some_and(|w| OUTWARD_READ_LAST_WORDS.contains(&w.as_str()));
- read && !name.iter().any(|w| SECOND_ACTION_WORDS.contains(&w.as_str()))
+/// Whether a name whose only outward words are nouns only reads them (21a; tightened in 22h after
+/// Rigel's F1 on #692). It has none of [`SECOND_ACTION_WORDS`], and either:
+/// - a read word ([`READ_VERBS`], [`OUTWARD_READ_WORDS`]), and the name doesn't open with an
+/// [`OUTWARD_VERB_WORDS`] word ahead of it (the second word after a Composio app prefix):
+/// `GMAIL_LIST_THREADS`, `WORDPRESS_GET_POST`, `getPostStatus` read; `post_list`, `share_get` don't;
+/// - or it reads a payment's, a ship's or a rollout's state ([`reads_state`]): `rollout_status`.
+///
+/// `GMAIL_REPLY_TO_THREAD`, `find_and_share_file`, `set_payment_status`, `post_status` and
+/// `MAILCHIMP_SUBSCRIBE_TO_LIST` don't read.
+fn reads_outward_noun(tool: &str, name: &[String]) -> bool {
+ let is_read = |w: &String| READ_VERBS.contains(&w.as_str()) || OUTWARD_READ_WORDS.contains(&w.as_str());
+ // The verb's place: the first word, or the second after a Composio app prefix
+ let verb_at = usize::from(app_prefixed(tool));
+ let read_first = name.iter().position(is_read).is_some_and(|r| r <= verb_at || !OUTWARD_VERB_WORDS.contains(&name[verb_at].as_str()));
+ (read_first || reads_state(tool, name)) && !name.iter().any(|w| SECOND_ACTION_WORDS.contains(&w.as_str()))
+}
+
+/// Whether a name with no read verb reads a payment's, a ship's or a rollout's state (22h): it ends
+/// in [`OUTWARD_READ_LAST_WORDS`], its only [`OUTWARD_NOUNS`] part is a [`STATE_NOUNS`] one, and every
+/// word before the last is a payment, ship or rollout word, apart from the app prefix of a
+/// Composio-style name ([`app_prefixed`]). `payment_status`, `rollout_status`, `ship_state` and
+/// `STRIPE_PAYMENT_STATUS` read; `post_status`, `MASTODON_POST_STATUS`, `cancel_payment_status` and
+/// `post_payment_status` don't.
+fn reads_state(tool: &str, name: &[String]) -> bool {
+ let Some((last, before)) = name.split_last() else { return false };
+ if !OUTWARD_READ_LAST_WORDS.contains(&last.as_str()) {
+ return false;
+ }
+ let upper = tool.to_ascii_uppercase();
+ if OUTWARD_NOUNS.iter().any(|n| upper.contains(n) && !STATE_NOUNS.contains(n)) {
+ return false;
+ }
+ let skip = usize::from(app_prefixed(tool));
+ let state_word = |w: &String| OUTWARD_NAME_WORDS.contains(&w.as_str()) || STATE_NOUNS.iter().any(|n| w.to_ascii_uppercase().contains(n));
+ before.len() > skip && before.iter().skip(skip).all(state_word)
+}
+
+/// Whether a tool name looks like a Composio one, `APP_ACTION_THING`: no lower-case letter, an
+/// underscore, and three words or more, so its first word names the app (`STRIPE_PAYMENT_STATUS`).
+fn app_prefixed(tool: &str) -> bool {
+ !tool.chars().any(char::is_lowercase) && tool.contains('_') && words(tool).len() >= 3
}
/// Whether a tool or its server is named for running free text (20d: one place for Telegram and the
@@ -1331,6 +1380,122 @@ mod tests {
assert_eq!(inline_refusal(&mcp("x", "fetch_commit", json!({}))), Some(PUSHES));
}
+ /// Step 3's lift as 21a shipped it (#692 06b3406a, unchanged by 21b): a read verb, `fetch`, or a
+ /// last word `status`/`state`, with none of 21a's second-action words.
+ fn outward_at_21a(tool: &str) -> bool {
+ const SECOND_21A: &[&str] = &["and", "then", "create", "update", "add", "set", "put", "write", "edit", "modify", "reply", "save", "schedule", "upsert", "insert"];
+ let upper = tool.to_ascii_uppercase();
+ if OUTWARD_NAMES.iter().any(|w| upper.contains(w)) {
+ return true;
+ }
+ let name = words(tool);
+ let noun = OUTWARD_NOUNS.iter().any(|w| upper.contains(w)) || name.iter().any(|w| OUTWARD_NAME_WORDS.contains(&w.as_str()));
+ let read = reads(&name) || name.iter().any(|w| w == "fetch") || name.last().is_some_and(|w| w == "status" || w == "state");
+ noun && !(read && !name.iter().any(|w| SECOND_21A.contains(&w.as_str())))
+ }
+
+ /// 22h (Rigel's F1, F3 and F5 on #692): (tool, step 3 at 21a refuses, island now).
+ fn writes_named_like_reads_rows() -> Vec<(&'static str, bool, Option<&'static str>)> {
+ vec![
+ // F1, must stay refused: (a) a post, share or upload status is as often a write
+ ("post_status", false, Some(OUTWARD)),
+ ("MASTODON_POST_STATUS", false, Some(OUTWARD)),
+ ("TWITTER_POST_STATUS", false, Some(OUTWARD)),
+ ("facebook_post_status", false, Some(OUTWARD)),
+ ("postStatus", false, Some(OUTWARD)),
+ ("share_status", false, Some(OUTWARD)),
+ ("shareStatus", false, Some(OUTWARD)),
+ ("upload_status", false, Some(OUTWARD)),
+ ("post_payment_status", false, Some(OUTWARD)),
+ // F1 (a): a verb before a payment's state, with or without a 22h second-action word
+ ("cancel_payment_status", false, Some(OUTWARD)),
+ ("approve_payment_status", false, Some(OUTWARD)),
+ // F1 (c): the new second-action words
+ ("retry_payment_status", false, Some(OUTWARD)),
+ ("capture_payment_status", false, Some(OUTWARD)),
+ ("refund_payment_status", false, Some(OUTWARD)),
+ ("change_payment_status", false, Some(OUTWARD)),
+ ("change_post_status", false, Some(OUTWARD)),
+ ("WORDPRESS_CHANGE_POST_STATUS", false, Some(OUTWARD)),
+ ("toggle_post_status", false, Some(OUTWARD)),
+ ("RETRY_PAYMENT_STATUS", false, Some(OUTWARD)),
+ ("MAILCHIMP_SUBSCRIBE_TO_LIST", false, Some(OUTWARD)),
+ ("MAILCHIMP_SUBSCRIBE_MEMBER_TO_LIST", false, Some(OUTWARD)),
+ ("MAILCHIMP_UNSUBSCRIBE_FROM_LIST", false, Some(OUTWARD)),
+ ("MAILCHIMP_ARCHIVE_MEMBER_FROM_LIST", false, Some(OUTWARD)),
+ ("MAILCHIMP_BATCH_SUBSCRIBE_LIST", false, Some(OUTWARD)),
+ ("GMAIL_UNSUBSCRIBE_FROM_MAILING_LIST", false, Some(OUTWARD)),
+ ("subscribe_to_mailing_list", false, Some(OUTWARD)),
+ ("join_mailing_list", false, Some(OUTWARD)),
+ ("leave_mailing_list", false, Some(OUTWARD)),
+ // F1 (b): the outward word is the verb, the read word comes after it
+ ("post_list", false, Some(OUTWARD)),
+ ("postList", false, Some(OUTWARD)),
+ ("share_list", false, Some(OUTWARD)),
+ ("share_get", false, Some(OUTWARD)),
+ ("post_get", false, Some(OUTWARD)),
+ ("post_show", false, Some(OUTWARD)),
+ ("upload_get", false, Some(OUTWARD)),
+ ("pay_list", false, Some(OUTWARD)),
+ ("SLACK_SHARE_GET", false, Some(OUTWARD)),
+ // Must allow: the brief's rows
+ ("get_payment_status", false, None),
+ ("rollout_status", false, None),
+ ("ship_status", false, None),
+ ("GMAIL_FETCH_EMAILS", false, None),
+ ("DROPBOX_LIST_FILES", false, None),
+ ("STRIPE_RETRIEVE_PAYMENT_INTENT", true, None),
+ ("STRIPE_RETRIEVE_A_PAYMENT_INTENT", true, None),
+ // Must allow: reads 21a allowed that sit next to the new rules
+ ("ship_state", false, None),
+ ("payment_status", false, None),
+ ("STRIPE_PAYMENT_STATUS", false, None),
+ ("check_payment_status", false, None),
+ ("STRIPE_CHECK_PAYMENT_STATUS", false, None),
+ ("getPostStatus", false, None),
+ ("get_post_status", false, None),
+ ("SHAREPOINT_GET_FILE", false, None),
+ ("MAILCHIMP_GET_LIST", false, None),
+ ("GMAIL_LIST_THREADS", false, None),
+ ("list_uploads", false, None),
+ // F2 is left as it is: marking mail read keeps Allow once
+ ("GMAIL_MARK_EMAIL_AS_READ", false, None),
+ ("mark_email_as_read", false, None),
+ // F3: check reads too now
+ ("check_email", true, None),
+ ]
+ }
+
+ #[test]
+ fn writes_named_like_reads_keep_the_full_card_and_reads_keep_allow_once() {
+ let rows = writes_named_like_reads_rows();
+ assert_eq!(rows.len(), 58);
+ for (tool, refused_at_21a, want) in rows {
+ assert!(outward_before_21a(tool), "{tool}: step 3 refused it before 21a");
+ assert_eq!(outward_at_21a(tool), refused_at_21a, "{tool}: at 21a");
+ let d = mcp("composio", tool, json!({}));
+ assert_eq!(inline_refusal(&d), want, "island: {tool}");
+ assert_eq!(ships_or_runs(&d), None, "telegram: {tool}");
+ }
+ // 21a's own rows keep their verdicts, and 21a's helper agrees with them
+ for (name, d, want) in outward_rows() {
+ let tool = d["tool"].as_str().unwrap();
+ if d["arguments"].as_object().is_some_and(|a| a.is_empty()) || want.is_none() {
+ assert_eq!(outward_at_21a(tool), want == Some(OUTWARD), "{name}: at 21a");
+ }
+ }
+ }
+
+ #[test]
+ fn retrieve_and_check_lift_outward_nouns_only() {
+ assert!(!READ_VERBS.contains(&"retrieve") && !READ_VERBS.contains(&"check"));
+ assert_eq!(inline_refusal(&mcp("x", "retrieve_and_merge", json!({}))), Some(PUSHES));
+ assert_eq!(inline_refusal(&mcp("x", "check_commit", json!({}))), Some(PUSHES));
+ // A Composio prefix moves the verb's place to the second word only in an APP_ACTION name
+ assert!(app_prefixed("SLACK_SHARE_GET") && app_prefixed("STRIPE_PAYMENT_STATUS"));
+ assert!(!app_prefixed("share_get_x") && !app_prefixed("POST_LIST") && !app_prefixed("GMAILFETCHEMAILS"));
+ }
+
#[test]
fn avatars_are_the_saved_sprite_or_null() {
let avatars: HashMap<String, String> = [("a".to_string(), "architect".to_string()), ("b".to_string(), " ".to_string())].into();
diff --git a/tests/glance_test.rs b/tests/glance_test.rs
index 55ec7e08..7bfefcac 100644
--- a/tests/glance_test.rs
+++ b/tests/glance_test.rs
@@ -689,6 +689,12 @@ async fn reads_of_mail_files_and_payments_keep_allow_once_on_the_island() {
("find_and_share_file", mcp("drive", "find_and_share_file", json!({})), false),
("pay_invoice", mcp("stripe", "pay_invoice", json!({"id": "in_1"})), false),
("get_post with a POST body", mcp("x", "get_post", json!({"url": "https://api.example.com/posts", "method": "POST", "body": {"t": "x"}})), false),
+ // 22h (Rigel's F1/F3 on #692): writes named like reads keep the full card; Stripe's retrieve reads
+ ("STRIPE_RETRIEVE_PAYMENT_INTENT", mcp("composio", "STRIPE_RETRIEVE_PAYMENT_INTENT", json!({"payment_intent": "pi_1"})), true),
+ ("retry_payment_status", mcp("stripe", "retry_payment_status", json!({"id": "pi_1"})), false),
+ ("MASTODON_POST_STATUS", mcp("composio", "MASTODON_POST_STATUS", json!({"status": "hello"})), false),
+ ("post_list", mcp("x", "post_list", json!({})), false),
+ ("MAILCHIMP_SUBSCRIBE_TO_LIST", mcp("composio", "MAILCHIMP_SUBSCRIBE_TO_LIST", json!({"list_id": "l1"})), false),
];
let mut made = Vec::new();
for (name, details, _) in &rows {