Side B is a substantial architectural migration (REST endpoints → unified RPC batch protocol, room/scope model rework, CLI restructuring, extensive test updates) that lastingly changes how the whole system communicates, whereas Side A is a small, focused feature addition (pool-scoped voting) that is useful but narrow in scope. Despite B's larger diff being partly explained by scope, its content is deliberate consolidation and simplification (removing many near-duplicate REST handlers into one rpc.rs) rather than noise, giving it more durable architectural value than A's incremental UI feature.
constitution · epochs · watch · epoch 3
c_c6f5afec1d36 (tommy-mor) vs c_2595b6007624 (tommy-mor)
download prompt · raw event · cmp_4a334070d9d855
council reasoning
B is a foundational redesign: it collapses scattered REST handlers into a batch RPC API, splits rooms from forum threads in the event/reducer model (room_id + thread_tag, ScopeId::Room, grants on rooms), and rewires CLI and tests around that model. A is a solid, complete UX feature (pool-scoped /vote and next-pair navigation) but stays local to the garden vote UI and does not reshape core product architecture the way B does.
Side B introduces a foundational API redesign by replacing many individual endpoints with a typed RPC batch interface, refactoring the reducer and event model from thread-centric to room/scope-aware data, and updating the CLI and tests to use the new architecture. Side A is a well-executed feature that adds pool-scoped voting, including `pool` query handling, UI links, and context-preserving navigation, but it builds on the existing system rather than reshaping core infrastructure.
sides
A — c_c6f5afec1d36 (tommy-mor)
message
[5350388a] Add pool-scoped voting: /vote?pool=<parent> picks pairs from children. - /vote now accepts an optional `pool` param (parent item path). When provided without left/right, it picks the first unvoted pair from the pool's children. When provided alongside left/right, it constrains "next pair" navigation to siblings within the pool. - "vote on children" button appears on item pages with ≥2 children, linking to /vote?pool=<item>. - Pool is threaded through VoteComparePost → success JS so in-page morph after voting keeps the pool context for next-pair navigation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
diff preview
diff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs
index 5faa642451d69555cb391974beb0ad22c9355c8c..b79efdb4d52bd445a67f38cbfd61d3507d2b3014 100644
--- a/server/src/api/ui_html.rs
+++ b/server/src/api/ui_html.rs
@@ -193,6 +193,7 @@ async fn dispatch_ui_action(
ratio_right,
explanation,
next,
+ pool,
form_action,
} => {
if form_action != "/ui" {
@@ -239,6 +240,9 @@ async fn dispatch_ui_action(
.into_response();
}
};
+ let pool_id = pool.as_deref().and_then(|p| {
+ crate::path_types::ItemId::parse(p.trim()).map(|i| i.normalized_storage())
+ });
let mut rl = ratio_left.trim().parse::<i32>().unwrap_or(0).max(0);
let mut rr = ratio_right.trim().parse::<i32>().unwrap_or(0).max(0);
if rl == 0 && rr == 0 {
@@ -294,6 +298,7 @@ async fn dispatch_ui_action(
&thread_tag,
&left_id,
&right_id,
+ pool_id.as_ref(),
pid.as_str(),
post_index,
)
diff --git a/server/src/html/garden/pin.rs b/server/src/html/garden/pin.rs
index 5865cfdbc06aeb6555c97380e25591fae6b3d125..1820d7fe7ee167ecbf5ad5124f23b2ab92ffb01f 100644
--- a/server/src/html/garden/pin.rs
+++ b/server/src/html/garden/pin.rs
@@ -79,7 +79,7 @@ pub(super) fn ont_pin_vote_controls(
}
}
} @else {
- a class="ont-vote-compare-btn" href=(vote_compare_href(nav, pi, ¤t, None)) title="Compare and vote" {
+ a class="ont-vote-compare-btn" href=(vote_compare_href(nav, pi, ¤t, None, None)) title="Compare and vote" {
span class="ont-vote-glyph" aria-hidden="true" { "⚖" }
span { "vote" }
}
@@ -121,7 +121,7 @@ pub(super) fn child_row_pin_or_vote(
if nv == 1 { "" } else { "s" },
);
@let aria = format!("Vote; {} pairwise {}", nv, if nv == 1 { "vote" } else { "votes" });
- a class="ont-garden-vote-ico" href=(vote_compare_href(nav, pi, row_item, None)) title=(tip) aria-label=(aria) {
+ a class="ont-garden-vote-ico" href=(vote_compare_href(nav, pi, row_item, None, None)) title=(tip) aria-label=(aria) {
span class="ont-garden-vote-glyph" aria-hidden="true" { "⚖" }
span class="ont-garden-vote-count" { (format!("{}", nv)) }
}
diff --git a/server/src/html/garden/render.rs b/server/src/html/garden/render.rs
index 5c3986ca36902f6c9019a4b5590f0b3b9d2cb4ff..bd8cbce059ee789de6e8dc9b6f69f54beee2f994 100644
--- a/server/src/html/garden/render.rs
+++ b/server/src/html/garden/render.rs
@@ -29,6 +29,7 @@ use super::{
item::{child_depth_from_uri, item_code_label, item_display_path, item_href},
item_page::{build_item_page_view_model, sibling_nav_markup},
pin::{child_row_pin_or_vote, ont_pin_vote_controls, pinned_item_from_jar},
+ vote::vote_pool_href,
};
pub(super) async fn render_scope_view(
@@ -186,12 +187,21 @@ pub(super) async fn render_scope_view(
}
section class="ont-tab-panel ont-tab-panel-children" {
+ @let total_children = model.child_rankings.component_rankings
+ .iter().map(|c| c.ranked.len()).sum::<usize>()
+ + model.child_rankings.unranked_items.len();
h3 {
"ranked child groups"
@if model.child_depth > 1 {
" "
span class="muted" { (format!("(depth {})", model.child_depth)) }
}
+ @if total_children >= 2 {
+ " "
+ a class="ont-vote-children-btn" href=(vote_pool_href(&nav, &model.item)) {
+ "vote on children"
+ }
+ }
}
@if model.child_rankings.component_rankings.is_empty() {
p class="muted" { "no voted pairs yet in this scope" }
diff --git a/server/src/html/garden/tests.rs b/server/src/html/garden/tests.rs
index 6900a6795bcde866a176722149d6378e5127b4c3..c2036fca7752aef63d260e36cfe9649f63b5c550 100644
--- a/server/src/html/garden/tests.rs
+++ b/server/src/html/garden/tests.rs
@@ -105,7 +105,7 @@ fn suggest_next_vote_pair_prefers_unvoted_sibling_pair() {
let content = content_for_garden_view(&reduced, &ScopeId::Public);
let a = ItemId::parse("~/topic/a").unwrap().normalized_storage();
let b = ItemId::parse("~/topic/b").unwrap().normalized_storage();
- let next = suggest_next_vote_pair(content, &a, &b).expect("next sibling pair");
+ let next = suggest_next_vote_pair(content, &a, &b, None).expect("next sibling pair");
assert_ne!(
canonical_edge_items(&next.0, &next.1),
canonical_edge_items(&a, &b)
diff --git a/server/src/html/garden/vote.rs b/server/src/html/garden/vote.rs
index 1d7fc8aa7436bfa9c1186dfd940a8d751ab7e088..2682cfcbd2f834b56459a02831aa225cffe67c58 100644
--- a/server/src/html/garden/vote.rs
+++ b/server/src/html/garden/vote.rs
@@ -211,14 +211,15 @@ pub(crate) async fn vote_compare_post_success_js(
_thread_tag: &str,
left: &ItemId,
right: &ItemId,
+ pool: Option<&ItemId>,
_post_id: &str,
_post_idx: Option<usize>,
) -> String {
let reduced = state.reduced.read().await;
let content = content_for_garden_view(&reduced, &nav.scope());
let edge_history = vote_edge_history_markup(content, left, right);
- let next_pair = suggest_next_vote_pair(content, left, right);
- let nav_markup = vote_compare_nav_markup(nav, next_pair.as_ref());
+ let next_pair = suggest_next_vote_pair(content, left, right, pool);
+ let nav_markup = vote_compare_nav_markup(nav, next_pair.as_ref(), pool);
drop(reduced);
JsBuilder::new()
.morph_inner_selector("#vote-edge-history-region", edge_history)
@@ -231,27 +232,39 @@ pub(super) fn vote_compare_href(
left: &ItemId,
right: &ItemId,
thread_override: Option<&str>,
+ pool: Option<&ItemId>,
) -> String {
let left_q = urlencoding::encode(left.as_str());
let right_q = urlencoding::encode(right.as_str());
- let base = format!(
+ let mut base = format!(
"{}/vote?left={}&right={}",
nav.room_path_prefix_for_vote_compare(),
left_q,
right_q
);
if let Some(t) = thread_override.filter(|s| !s.is_empty()) {
- format!("{}&thread={}", base, urlencoding::encode(t))
- } else {
- base
+ base = format!("{}&thread={}", base, urlencoding::encode(t));
+ }
+ if let Some(p) = pool {
+ base = format!("{}&pool={}", base, urlencoding::encode(p.as_str()));
}
+ base
+}
+
+pub(super) fn vote_pool_href(nav: &ThreadNav, pool_item_str: &str) -> String {
+ format!(
+ "{}/vote?pool={}",
+ nav.room_path_prefix_for_vote_compare(),
+ urlencoding::encode(pool_item_str)
+ )
}
fn vote_compare_nav_markup(
nav: &ThreadNav,
next_pair: Option<&(ItemId, ItemId)>,
+ pool: Option<&ItemId>,
) -> maud::Markup {
- let next_pair_href = next_pair.map(|(nl, nr)| vote_compare_href(nav, nl, nr, None));
+ let next_pair_href = next_pair.map(|(nl, nr)| vote_compare_href(nav, nl, nr, None, pool));
html! {
div class="vote-compare-nav" {
@if let Some(href) = &next_pair_href {
@@ -267,8 +280,15 @@ pub(super) fn suggest_next_vote_pair(
content: &ContentState,
current_left: &ItemId,
current_right: &ItemId,
+ pool_parent: Option<&ItemId>,
) -> Option<(ItemId, ItemId)> {
- let pool: Vec<ItemId> = if current_left.parent().as_ref().map(|p| p.as_str())
+ let pool: Vec<ItemId> = if let Some(parent) = pool_parent {
+ content
+ .item_children
+ .get(parent)
+ .map(|s| s.iter().cloned().collect())
+ .unwrap_or_default()
+ } else if current_left.parent().as_ref().map(|p| p.as_str())
== current_right.parent().as_ref().map(|p| p.as_str())
{
current_left
@@ -322,10 +342,14 @@ pub(super) fn vote_compare_item_card(
}
#[derive(Debug, Deserialize)]
pub struct VoteCompareQuery {
- pub left: String,
- pub right: String,
+ #[serde(default)]
+ pub left: Option<String>,
+ #[serde(default)]
+ pub right: Option<String>,
#[serde(default)]
pub thread: Option<String>,
+ #[serde(default)]
+ pub pool: Option<String>,
}
/// Public pairwise vote UI — `/vote?left=&right=&thread=`.
@@ -376,17 +400,53 @@ async fn vote_compare_inner(
jar: CookieJar,
uri: Uri,
) -> axum::response::Response {
- let left = match ItemId::parse(q.left.trim()) {
- Some(i) => i.normalized_storage(),
- None => return (StatusCode::NOT_FOUND, "bad left item").into_response(),
+ let pool_id: Option<ItemId> = match q.pool.as_deref() {
+ Some(p) => match ItemId::parse(p.trim()) {
+ Some(i) => Some(i.normalized_storage()),
+ None => return (StatusCode::BAD_REQUEST, "bad pool item").into_response(),
+ },
+ None => None,
};
- let right = match ItemId::parse(q.right.trim()) {
- Some(i) => i.normalized_storage(),
- None => return (StatusCode::NOT_FOUND, "bad right item").into_response(),
+
+ let (left, right) = match (q.left.as_deref(), q.right.as_deref()) {
+ (Some(l), Some(r)) => {
+ let left = match ItemId::parse(l.trim()) {
+ Some(i) => i.normalized_storage(),
+ None => return (StatusCode::NOT_FOUND, "bad left item").into_response(),
+ };
+ let right = match ItemId::parse(r.trim()) {
+ Some(i) => i.normalized_storage(),
+ None => return (StatusCode::NOT_FOUND, "bad right item").into_response(),
+ };
+ if left == right {
+ return (StatusCode::BAD_REQUEST, "items must differ").into_response();
+ }
+ (left, right)
+ }
+ (None, None) => {
+ let Some(pool) = pool_id.as_ref() else {
+ return (StatusCode::BAD_REQUEST, "provide left+right or pool").into_response();
+ };
+ let reduced = state.reduced.read().await;
+ let content = content_for_garden_view(&reduced, &nav.scope());
+ let children: Vec<ItemId> = content
+ .item_children
+ .get(pool)
+ .map(|s| s.iter().cloned().collect())
+ .unwrap_or_default();
+ if children.len() < 2 {
+ drop(reduced);
+ return (StatusCode::BAD_REQUEST, "pool has fewer than 2 children to compare").into_response();
+ }
+ let pair = suggest_next_pair_in_pool(&content.ranking_group, &children, None);
+ drop(reduced);
+ match pair {
+ Some(p) => p,
+ None => return (StatusCode::BAD_REQUEST, "no pairs available in pool").into_response(),
+ }
+ }
+ _ => return (StatusCode::BAD_REQUEST, "provide both left and right, or just pool").into_response(),
};
- if left == right {
- return (StatusCode::BAD_REQUEST, "items must differ").into_response();
- }
let reduced = state.reduced.read().await;
let content = content_for_garden_view(&reduced, &nav.scope());
@@ -409,7 +469,7 @@ async fn vote_compare_inner(
let left_body = content.item_bodies.get(&left).cloned();
let right_body = content.item_bodies.get(&right).cloned();
let item_bodies_for_cards = content.item_bodies.
… preview truncated; 1,501 characters omittedB — c_2595b6007624 (tommy-mor)
message
[96b6da05] rpc + reducer changes first pass
diff preview
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 630c5dea1f78c0ec9bc53e6b96234a0dc75bb705..8d0442959f4332bafe499a2a8cdf364731a06871 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -21,8 +21,9 @@ struct Cli {
cmd: Option<Command>,
}
+/// Commands scoped to a room (`public` or `shortid/slug`).
#[derive(Subcommand, Debug)]
-enum Command {
+enum ScopedCmd {
/// Browse the garden (ontology) — light mode, ranked by votes
Garden {
#[command(subcommand)]
@@ -174,6 +175,23 @@ enum Command {
#[arg(long)]
json: bool,
},
+}
+
+#[derive(Subcommand, Debug)]
+enum Command {
+ /// Public site (same as room `public`)
+ Public {
+ #[command(subcommand)]
+ sub: ScopedCmd,
+ },
+ /// Private room id (`shortid/slug` from `room create`)
+ Private {
+ /// Room id, e.g. `a1b2c3d/my-project`
+ #[arg(value_name = "ROOM_ID")]
+ room: String,
+ #[command(subcommand)]
+ sub: ScopedCmd,
+ },
/// Show all activity since you last posted (global feed)
///
@@ -628,6 +646,37 @@ fn http_client() -> Result<reqwest::Client> {
.build()?)
}
+async fn send_rpc(
+ client: &reqwest::Client,
+ base: &str,
+ bearer: Option<&str>,
+ commands: Vec<RpcCommand>,
+) -> Result<RpcBatchResponse> {
+ let url = format!("{}/api/v0/rpc", base.trim_end_matches('/'));
+ let mut req = client.post(url).json(&RpcBatch(commands));
+ if let Some(b) = bearer {
+ req = req.header("Authorization", format!("Bearer {}", b));
+ }
+ let resp = req.send().await?;
+ let status = resp.status();
+ let text = resp.text().await.unwrap_or_default();
+ if !status.is_success() {
+ return Err(anyhow!("rpc HTTP {}: {}", status, text.trim()));
+ }
+ serde_json::from_str(&text).map_err(|e| anyhow!("rpc response: {e}"))
+}
+
+fn rpc_line_ok(line: &RpcLine) -> Result<&RpcResult> {
+ if !line.ok {
+ let mut m = line.error.clone().unwrap_or_else(|| "rpc error".into());
+ if let Some(h) = &line.hint {
+ m.push_str(&format!("\nhint: {h}"));
+ }
+ return Err(anyhow!(m));
+ }
+ line.result.as_ref().ok_or_else(|| anyhow!("rpc missing result"))
+}
+
/// Normalize ontology path for API. Accepts path with or without ~/ (shell expands ~ to $HOME).
/// Returns a bare slug path (e.g. `languages/python`) with no leading `/` or `~/`.
/// Call `ontology_path_for_api_query` before sending `item=` / `parent=` params so the server
@@ -729,231 +778,262 @@ fn write_secret_file(name: &str, contents: &str) -> Result<()> {
Ok(())
}
-#[tokio::main]
-async fn main() -> Result<()> {
- let Cli { cmd, server } = Cli::parse();
-
- // If no command provided, print the guide
- let Some(cmd) = cmd else {
- print!("{}", include_str!("../GUIDE.sorter"));
- return Ok(());
- };
-
- let base = server.trim_end_matches('/');
-
- match cmd {
- Command::Healthz { json } => {
- let client = http_client()?;
- let url = format!("{base}/healthz");
- let body = client.get(url).send().await?.text().await?;
- if json {
- // Wrap plain text response in a JSON object
- println!("{}", serde_json::json!({ "ok": true, "body": body.trim() }));
- } else {
- println!("{body}");
- }
- }
-
- Command::Search { query, json } => {
- let client = http_client()?;
- let url = format!("{base}/api/v0/search?q={}", urlencoding::encode(&query));
- let resp: slug_types::SearchResponse = expect_json(client.get(url).send().await?).await?;
- if json {
- println!("{}", serde_json::to_string_pretty(&resp)?);
- } else {
- if !resp.items.is_empty() {
- println!("items ({})", resp.items.len());
- for item in &resp.items {
- print!(" {}", item.path);
- if let Some(body) = &item.body {
- let first_line = body.lines().next().unwrap_or("").trim();
- if !first_line.is_empty() {
- print!(" {}", first_line);
+async fn run_scoped(base: &str, room: &str, sub: ScopedCmd) -> Result<()> {
+ let room = room.trim();
+ let client = http_client()?;
+ match sub {
+ ScopedCmd::Garden { sub } => match sub {
+ GardenCmd::Tree { json } => {
+ let batch = send_rpc(&client, base, None, vec![RpcCommand::GetLeaves { room: room.to_string() }]).await?;
+ match rpc_line_ok(&batch.results[0])? {
+ RpcResult::Leaves(resp) => {
+ if json {
+ println!("{}", serde_json::to_string_pretty(&resp)?);
+ } else {
+ for p in &resp.paths {
+ println!("~/{}", p);
}
}
- println!();
- }
- }
- if !resp.threads.is_empty() {
- if !resp.items.is_empty() { println!(); }
- println!("threads ({})", resp.threads.len());
- let now_ms = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or_default()
- .as_millis() as i64;
- for t in &resp.threads {
- println!(" {} {}n {}", t.tag, t.post_count, slug_types::timeago::timeago(now_ms, t.last_activity));
- }
- }
- if !resp.posts.is_empty() {
- if !resp.items.is_empty() || !resp.threads.is_empty() { println!(); }
- println!("posts ({})", resp.posts.len());
- let now_ms = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or_default()
- .as_millis() as i64;
- for p in &resp.posts {
- let first_line = p.snippet.lines().next().unwrap_or("").trim();
- println!(" {} · {} {}", p.thread, slug_types::timeago::timeago(now_ms, p.ts), first_line);
- }
- }
- if resp.items.is_empty() && resp.threads.is_empty() && resp.posts.is_empty() {
- println!("no results");
- }
- }
- }
-
- Command::Garden { sub } => match sub {
- GardenCmd::Tree { json } => {
- let client = http_client()?;
- let url = format!("{base}/api/v0/leaves");
- let builder = client.get(url);
- let resp: LeavesResponse = expect_json(builder.send().await?).await?;
- if json {
- println!("{}", serde_json::to_string_pretty(&resp)?);
- } else {
- for p in &resp.paths {
- println!("~/{}", p);
}
+ _ => return Err(anyhow!("unexpected RPC result")),
}
}
-
GardenCmd::Body { path, json, full } => {
let path = normalize_ontology_path_input(&path).map_err(anyhow::Error::msg)?;
let item_q = ontology_path_for_api_query(&path);
- let client = http_client()?;
- let mut url = format!("{base}/api/v0/item?item={}", urlencoding::encode(&item_q));
- if full {
- url.push_str("&full=true");
- }
- let builder = client.get(url);
- let resp: ItemResponse = expect_json(builder.send().await?).await?;
- if json {
- println!("{}", serde_json::to_string_pretty(&resp)?);
- } else {
- print_item_response(&resp);
+ let batch = send_rpc(
+ &client,
+ base,
+ None,
+ vec![RpcCommand::GetGardenItem {
+ room: room.to_string(),
+ item_path: item_q,
+ full: Some(full),
+ }],
+ )
+ .await?;
+ match rpc_line_ok(&batch.results[0])? {
+ RpcResult::GardenItem(resp) => {
+ if json {
+ println!("{}", serde_json::to_string_pretty(&resp)?);
+ } else {
+ print_item_response(&resp);
+ }
+ }
+ _ => return Err(anyhow!("unexpected RPC result")),
}
}
-
GardenCmd::Children { paths, depth, json } => {
let paths: Vec<String> = paths
.iter()
.map(|p| normalize_ontology_path_input(p).map_err(anyhow::Error::msg))
.collect::<Result<Vec<_>>>()?;
- let client = http_client()?;
let parent_param = paths
.iter()
.map(|p| ontology_path_for_api_query(p))
.collect::<Vec<_>>()
.join(",");
- let mut url = format!("{base}/api/v0/rank?parent={}", urlencoding::encode(&parent_param));
- if let Some(d) = depth {
- url.push_str(&format!("&depth={d}"));
- }
- let builder = client.get(url);
- let resp: RankResponse = expect_json(builder.send().await?).await?;
-
- if json {
- println!("{}", serde_json::to_string_pretty(&resp)?);
- } else {
- print_rank_response(&resp);
+ let batch = send_rpc(
+ &client,
+ base,
+ None,
+ vec![RpcCommand::GetGardenRank {
+ room: room.to_string(),
+ parent_path: parent_param,
+ depth,
+ offset: None,
+ limit: None,
+ percent: None,
+ }],
+ )
+ .await?;
+ match rpc_line_ok(&batch.results[0])? {
+ RpcResult::GardenRank(resp) => {
+ if json {
+ println!("{}", serde_json::to_string_pretty(&resp)?);
+ } else {
+ print_rank_response(&resp);
+ }
+ }
+ _ => return Err(anyhow!("unexpected RPC result")),
}
}
-
GardenCmd::Pair { path, json } => {
let path = normalize_ontology_path_input(&path).map_err(anyhow::Error::msg)?;
let parent_q = ontology_path_for_api_query(&path);
- let client = http_client()?;
- let url = format!("{base}/api/v0/pair?parent={}", urlencoding::encode(&parent_q));
- let builder = client.get(url);
- let resp: PairResponse = expect_json(builder.send().await?).await?;
- if json {
- println!("{}", serde_json::to_string_pretty(&resp)?);
- } else {
- print_pair_response(&resp);
+ let batch = send_rpc(
+ &client,
+ base,
+ None,
+ vec![RpcCommand::GetPair {
+ room: room.to_string(),
+ parent_path: parent_q,
+ }]
… preview truncated; 237,234 characters omittedHardlinks — judgments / attempts / prompt
judgments
attempts
Prompt text is loaded only by the download route.