From c6a47c84acd3017ead5bb8c3285cad6d39f87fc5 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sun, 12 Apr 2026 18:33:34 -0300 Subject: [PATCH] fix: use ADD_SUGGESTION_TOOL instead of ADD_SUGG_TOOL --- src/basic/compiler/mod.rs | 6 ++-- src/basic/keywords/add_suggestion.rs | 43 ++++++++-------------------- src/basic/mod.rs | 18 ++++-------- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/src/basic/compiler/mod.rs b/src/basic/compiler/mod.rs index c041f78d..5eb15734 100644 --- a/src/basic/compiler/mod.rs +++ b/src/basic/compiler/mod.rs @@ -488,9 +488,9 @@ impl BasicCompiler { .replace("FOR EACH", "FOR_EACH") .replace("EXIT FOR", "EXIT_FOR") .replace("GROUP BY", "GROUP_BY") - .replace("ADD SUGGESTION TOOL", "ADD_SUGG_TOOL") - .replace("ADD SUGGESTION TEXT", "ADD_SUGG_TEXT") - .replace("ADD SUGGESTION", "ADD_SUGG"); + .replace("ADD SUGGESTION TOOL", "ADD_SUGGESTION_TOOL") + .replace("ADD SUGGESTION TEXT", "ADD_SUGGESTION_TEXT") + .replace("ADD SUGGESTION", "ADD_SUGGESTION"); if normalized.starts_with("SET SCHEDULE") || trimmed.starts_with("SET SCHEDULE") { has_schedule = true; let parts: Vec<&str> = normalized.split('"').collect(); diff --git a/src/basic/keywords/add_suggestion.rs b/src/basic/keywords/add_suggestion.rs index 55d53f4d..cc94845d 100644 --- a/src/basic/keywords/add_suggestion.rs +++ b/src/basic/keywords/add_suggestion.rs @@ -69,17 +69,15 @@ pub fn add_suggestion_keyword( ) { // Each closure needs its own Arc and UserSession clone let cache = state.cache.clone(); - let cache2 = state.cache.clone(); let cache3 = state.cache.clone(); let cache4 = state.cache.clone(); - let user_session2 = user_session.clone(); let user_session3 = user_session.clone(); let user_session4 = user_session.clone(); - // ADD_SUGG_TOOL "tool_name" AS "button text" — single-token to avoid ADD conflicts + // ADD_SUGGESTION_TOOL "tool_name" AS "button text" engine .register_custom_syntax( - ["ADD_SUGG_TOOL", "$expr$", "AS", "$expr$"], + ["ADD_SUGGESTION_TOOL", "$expr$", "AS", "$expr$"], true, move |context, inputs| { let tool_name = context.eval_expression_tree(&inputs[0])?.to_string(); @@ -98,32 +96,10 @@ pub fn add_suggestion_keyword( ) .expect("valid syntax registration"); - // ADD_SUGGESTION_TOOL — legacy alias, same handler + // ADD_SUGGESTION_TEXT "text_value" AS "button text" engine .register_custom_syntax( - ["ADD_SUGGESTION_TOOL", "$expr$", "AS", "$expr$"], - true, - move |context, inputs| { - let tool_name = context.eval_expression_tree(&inputs[0])?.to_string(); - let button_text = context.eval_expression_tree(&inputs[1])?.to_string(); - - add_tool_suggestion( - cache2.as_ref(), - &user_session2, - &tool_name, - None, - &button_text, - )?; - - Ok(Dynamic::UNIT) - }, - ) - .expect("valid syntax registration"); - - // ADD_SUGG_TEXT "text_value" AS "button text" — single-token - engine - .register_custom_syntax( - ["ADD_SUGG_TEXT", "$expr$", "AS", "$expr$"], + ["ADD_SUGGESTION_TEXT", "$expr$", "AS", "$expr$"], true, move |context, inputs| { let text_value = context.eval_expression_tree(&inputs[0])?.to_string(); @@ -136,16 +112,21 @@ pub fn add_suggestion_keyword( ) .expect("valid syntax registration"); - // ADD_SUGG "context_name" AS "button text" — single-token + // ADD_SUGGESTION "context_name" AS "button text" engine .register_custom_syntax( - ["ADD_SUGG", "$expr$", "AS", "$expr$"], + ["ADD_SUGGESTION", "$expr$", "AS", "$expr$"], true, move |context, inputs| { let context_name = context.eval_expression_tree(&inputs[0])?.to_string(); let button_text = context.eval_expression_tree(&inputs[1])?.to_string(); - add_context_suggestion(cache4.as_ref(), &user_session4, &context_name, &button_text)?; + add_context_suggestion( + cache4.as_ref(), + &user_session4, + &context_name, + &button_text, + )?; Ok(Dynamic::UNIT) }, diff --git a/src/basic/mod.rs b/src/basic/mod.rs index b427c841..2bfde63a 100644 --- a/src/basic/mod.rs +++ b/src/basic/mod.rs @@ -2022,14 +2022,11 @@ impl ScriptService { (r#"CLEAR\s+TOOLS"#, 0, 0, vec![]), (r#"CLEAR\s+WEBSITES"#, 0, 0, vec![]), - // ADD family - single-token keywords to avoid ADD conflicts - (r#"ADD_SUGG_TOOL"#, 2, 2, vec!["tool", "text"]), - (r#"ADD_SUGG_TEXT"#, 2, 2, vec!["value", "text"]), - (r#"ADD_SUGG(?!\s+TOOL|\s+TEXT|_)"#, 2, 2, vec!["context", "text"]), - (r#"ADD_SUGGESTION_TOOL"#, 2, 2, vec!["tool", "text"]), - (r#"ADD_SUGGESTION_TEXT"#, 2, 2, vec!["value", "text"]), - (r#"ADD_SUGGESTION(?!\s+TOOL|\s+TEXT|_)"#, 2, 2, vec!["context", "text"]), - (r#"ADD\s+MEMBER"#, 2, 2, vec!["name", "role"]), +// ADD family - single-token keywords to avoid ADD conflicts + (r#"ADD_SUGGESTION_TOOL"#, 2, 2, vec!["tool", "text"]), + (r#"ADD_SUGGESTION_TEXT"#, 2, 2, vec!["value", "text"]), + (r#"ADD_SUGGESTION(?!\\s+TOOL|\\s+TEXT|_)"#, 2, 2, vec!["context", "text"]), + (r#"ADD\\s+MEMBER"#, 2, 2, vec!["name", "role"]), // CREATE family (r#"CREATE\s+TASK"#, 1, 1, vec!["task"]), @@ -2057,11 +2054,8 @@ impl ScriptService { // Skip lines that already use underscore-style custom syntax // These are registered directly with Rhai and should not be converted let trimmed_upper = trimmed.to_uppercase(); - if trimmed_upper.contains("ADD_SUGG_TOOL") || - trimmed_upper.contains("ADD_SUGG_TEXT") || - trimmed_upper.contains("ADD_SUGGESTION_TOOL") || + if trimmed_upper.contains("ADD_SUGGESTION_TOOL") || trimmed_upper.contains("ADD_SUGGESTION_TEXT") || - trimmed_upper.starts_with("ADD_SUGG_") || trimmed_upper.starts_with("ADD_SUGGESTION_") || trimmed_upper.starts_with("ADD_MEMBER") || (trimmed_upper.starts_with("USE_") && trimmed.contains('(')) {