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.

Smart Results: ask for a table when comparing two options too (#253)

Oleksandr Ivanchenkod242c937996a
diff --git a/src/server/smart_results/mod.rs b/src/server/smart_results/mod.rs
index 9acd7000..8110d96c 100644
--- a/src/server/smart_results/mod.rs
+++ b/src/server/smart_results/mod.rs
@@ -43,8 +43,13 @@ pub const MAX_REPLY: usize = 128 * 1024;
pub const PICK_REASON: &str = "named as the pick in this reply";
/// The one line of the bot system prompt that asks for structure the selectors can read (plan
/// §A.4). It is in every bot's system prompt once (`drivers::TurnInput::system_prompt_parts`).
-pub const PROMPT_LINE: &str = "When you compare 3 or more options use a table, for steps use a numbered list, and for key \
- numbers use '**Label:** value' lines; kwant shows them as cards and charts.";
+///
+/// Two options count too: "Aldi vs Lidl" came back as bullets when the line said "3 or more", and
+/// the transposed shape (options as columns, a row per point) is what [`selector`] reads as a
+/// comparison. Every header cell must be filled, or the table stays text.
+pub const PROMPT_LINE: &str = "When you compare options use a table with every header cell filled (one row per option; for \
+ just two, a column each and a row per point), for steps use a numbered list, and for key numbers use '**Label:** value' \
+ lines; kwant shows them as cards and charts.";
/// The checked block set for a reply: the first candidate, in priority order ([`rank`]), whose
/// type is enabled and that passes [`validate`]; `None` when there isn't one. A selector bug must never
diff --git a/src/server/smart_results/selector_tests.rs b/src/server/smart_results/selector_tests.rs
index 2625673a..b40d38c8 100644
--- a/src/server/smart_results/selector_tests.rs
+++ b/src/server/smart_results/selector_tests.rs
@@ -43,6 +43,25 @@ fn a_pipe_table_is_a_comparison_with_cells_copied_verbatim() {
assert_eq!((c.highlight_row, c.highlight_reason), (None, None));
}
+/// The prompt line asks for this shape when a reply compares just two options ("Compare Aldi with
+/// Lidl" came back as bullets and stayed text): the options as columns, a row per point.
+#[test]
+fn a_two_option_table_with_a_row_per_point_is_a_comparison() {
+ let text = "They're close on price; it depends on what you buy.\n\n\
+ | Point | Aldi Süd | Lidl |\n|---|---|---|\n\
+ | Prices | Basket €42.07, about 4% less | Basket €44.02 |\n\
+ | Deals | Tighter range | More non-food deals each week |\n\
+ | App | Nothing comparable | Lidl Plus coupons |\n\
+ | Store feel | Quicker to shop | Bigger, more variety |\n\n\
+ If you mostly buy staples, Aldi Süd is the slightly cheaper default.\n";
+ let c = comparison_of(text);
+ let labels: Vec<&str> = c.columns.iter().map(|k| k.label.as_str()).collect();
+ assert_eq!(labels, ["Point", "Aldi Süd", "Lidl"]);
+ let points: Vec<&str> = c.rows.iter().map(|r| r.cells[0].as_str()).collect();
+ assert_eq!(points, ["Prices", "Deals", "App", "Store feel"]);
+ assert_eq!(c.rows[0].cells, ["Prices", "Basket €42.07, about 4% less", "Basket €44.02"]);
+}
+
#[test]
fn small_ragged_wide_or_repeated_tables_stay_text() {
let two_rows = "| Plan | Price |\n|---|---|\n| Basic | 12 |\n| Team | 18 |\n";