{"messages":[{"content":"You are a constitutional council ranking individual git commits for ownership allocation.\n\nCompare these two commits. Decide which contributed more lasting value to the project.\n\nJudge substance, not spectacle:\n- Prefer correct, lasting design and real bugfixes over churn, formatting, renames, or generated noise.\n- Prefer clarity and necessity over sheer line count. A small precise change can beat a large diffuse one.\n- Do not favor a side merely because its patch is longer or noisier.\n- Weight what the change does for the project, not the contributor's name.\n\nReturn ONLY a JSON object: {\"winner\": \"A\" or \"B\", \"ratio\": \"N:M\", \"explanation\": \"...\"}\nThe explanation must cite concrete differences in the patches (1-3 sentences).\n\nSide A — contributor: tommy-mor\nSide A — commit message:\n[8f69c309] Require Reddit OAuth when credentials are set and refresh on 401/403.\n\nAvoid falling back to the public www.reddit.com API from cloud IPs, which\nreturns Reddit's network-security block page. Also pin SORTER2_BASE_URL in fly.toml.\n\nCo-authored-by: Cursor \n\nSide A — unified diff (full patch):\ndiff --git a/fly.toml b/fly.toml\nindex f0c6a39f643c204987debc177234d95a8ef44b65..ca7e0088a7efd7d58d29d808f8d89080b2bff233 100644\n--- a/fly.toml\n+++ b/fly.toml\n@@ -5,6 +5,7 @@ primary_region = \"iad\"\n dockerfile = \"Dockerfile\"\n \n [env]\n+ SORTER2_BASE_URL = \"https://reddit.sorter.social\"\n SORTER2_DATA_DIR = \"/data\"\n SORTER2_EVENT_LOG = \"/data/events.jsonl\"\n PORT = \"8080\"\ndiff --git a/server/src/reddit.rs b/server/src/reddit.rs\nindex a874814f8927192ee62cab2d0db1efd27dcd57b7..f409764c1e1f36216f1b08107043c2eab905694c 100644\n--- a/server/src/reddit.rs\n+++ b/server/src/reddit.rs\n@@ -283,26 +283,35 @@ async fn reddit_worker(\n );\n tokio::time::sleep(current_delay).await;\n \n- if let Some(c) = &creds {\n- oauth = ensure_oauth_token(&client, &oauth_token_base, c, oauth.take()).await;\n- }\n-\n- let token = oauth.as_ref().map(|t| t.access_token.as_str());\n- let fetch_base = if token.is_some() {\n- tracing::debug!(\n- item = %fetch_id,\n- base = %oauth_api_base,\n- \"reddit fetch using OAuth bearer\"\n- );\n- &oauth_api_base\n- } else {\n- &api_base\n- };\n- let url = match kind {\n- FetchKind::SelfEntity => map_item_to_reddit_api(&fetch_id, fetch_base),\n- FetchKind::Children => map_children_url(&fetch_id, fetch_base),\n+ let outcome = match &creds {\n+ Some(c) => {\n+ // OAuth is required when credentials are configured — never fall\n+ // back to the public www.reddit.com JSON endpoints (cloud IPs\n+ // get blocked with a 403 HTML interstitial).\n+ fetch_with_oauth(\n+ &client,\n+ &oauth_token_base,\n+ &oauth_api_base,\n+ c,\n+ &mut oauth,\n+ &fetch_id,\n+ kind,\n+ )\n+ .await\n+ }\n+ None => {\n+ let url = match kind {\n+ FetchKind::SelfEntity => map_item_to_reddit_api(&fetch_id, &api_base),\n+ FetchKind::Children => map_children_url(&fetch_id, &api_base),\n+ };\n+ match do_fetch(&client, &url, &fetch_id, None).await {\n+ Ok(FetchOutcome::AuthRejected { status, detail }) => {\n+ Err(format!(\"Reddit API {status}: {detail}\"))\n+ }\n+ other => other,\n+ }\n+ }\n };\n- let outcome = do_fetch(&client, &url, &fetch_id, token).await;\n \n match outcome {\n Ok(FetchOutcome::Payload(payload)) => {\n@@ -342,6 +351,12 @@ async fn reddit_worker(\n current_delay = (current_delay * 2).min(Duration::from_secs(60));\n notify(done, FetchJobResult::RateLimited { reset_secs });\n }\n+ Ok(FetchOutcome::AuthRejected { status, detail }) => {\n+ let e = format!(\"Reddit API {status}: {detail}\");\n+ tracing::warn!(item = %fetch_id, err = %e, \"reddit fetch auth rejected\");\n+ current_delay = (current_delay * 2).min(Duration::from_secs(60));\n+ notify(done, FetchJobResult::Failed(e));\n+ }\n Err(e) => {\n tracing::warn!(item = %fetch_id, err = %e, \"reddit fetch failed\");\n current_delay = (current_delay * 2).min(Duration::from_secs(60));\n@@ -357,6 +372,60 @@ enum FetchOutcome {\n Payload(Value),\n NotFound,\n RateLimited { reset_secs: u64 },\n+ /// Bearer rejected — caller should drop the cached token and retry once.\n+ AuthRejected { status: StatusCode, detail: String },\n+}\n+\n+async fn fetch_with_oauth(\n+ client: &Client,\n+ oauth_token_base: &str,\n+ oauth_api_base: &str,\n+ creds: &RedditCredentials,\n+ oauth: &mut Option,\n+ fetch_id: &ItemId,\n+ kind: FetchKind,\n+) -> Result {\n+ for attempt in 0..2 {\n+ let force_refresh = attempt > 0;\n+ *oauth = Some(\n+ ensure_oauth_token(client, oauth_token_base, creds, oauth.take(), force_refresh)\n+ .await?,\n+ );\n+ let token = oauth\n+ .as_ref()\n+ .expect(\"token set above\")\n+ .access_token\n+ .clone();\n+\n+ tracing::debug!(\n+ item = %fetch_id,\n+ base = %oauth_api_base,\n+ attempt,\n+ \"reddit fetch using OAuth bearer\"\n+ );\n+\n+ let url = match kind {\n+ FetchKind::SelfEntity => map_item_to_reddit_api(fetch_id, oauth_api_base),\n+ FetchKind::Children => map_children_url(fetch_id, oauth_api_base),\n+ };\n+ match do_fetch(client, &url, fetch_id, Some(&token)).await? {\n+ FetchOutcome::AuthRejected { status, detail } if attempt == 0 => {\n+ tracing::warn!(\n+ item = %fetch_id,\n+ %status,\n+ %detail,\n+ \"reddit OAuth rejected; refreshing token and retrying\"\n+ );\n+ *oauth = None;\n+ continue;\n+ }\n+ FetchOutcome::AuthRejected { status, detail } => {\n+ return Err(format!(\"Reddit API {status}: {detail}\"));\n+ }\n+ other => return Ok(other),\n+ }\n+ }\n+ unreachable!(\"loop always returns\")\n }\n \n async fn ensure_oauth_token(\n@@ -364,35 +433,35 @@ async fn ensure_oauth_token(\n oauth_base: &str,\n creds: &RedditCredentials,\n existing: Option,\n-) -> Option {\n- if let Some(t) = existing {\n- if Instant::now() < t.expires_at - Duration::from_secs(60) {\n- tracing::debug!(\"reddit OAuth token still valid\");\n- return Some(t);\n+ force_refresh: bool,\n+) -> Result {\n+ if !force_refresh {\n+ if let Some(t) = existing {\n+ if Instant::now() < t.expires_at - Duration::from_secs(60) {\n+ tracing::debug!(\"reddit OAuth token still valid\");\n+ return Ok(t);\n+ }\n }\n }\n \n let url = format!(\"{}/api/v1/access_token\", oauth_base.trim_end_matches('/'));\n- tracing::debug!(%url, \"reddit OAuth token request\");\n+ tracing::debug!(%url, force_refresh, \"reddit OAuth token request\");\n \n let resp = client\n .post(&url)\n .basic_auth(&creds.client_id, Some(&creds.client_secret))\n .form(&[(\"grant_type\", \"client_credentials\")])\n .send()\n- .await;\n-\n- let resp = match resp {\n- Ok(r) => r,\n- Err(e) => {\n- tracing::warn!(\"reddit OAuth token request failed: {e}\");\n- return None;\n- }\n- };\n+ .await\n+ .map_err(|e| format!(\"Reddit OAuth token request failed: {e}\"))?;\n \n if !resp.status().is_success() {\n- tracing::warn!(\"reddit OAuth token HTTP {}\", resp.status());\n- return None;\n+ let status = resp.status();\n+ let body = resp.text().await.unwrap_or_default();\n+ return Err(format!(\n+ \"Reddit OAuth token HTTP {status}: {}\",\n+ truncate_for_error(&body)\n+ ));\n }\n \n #[derive(Deserialize)]\n@@ -401,21 +470,40 @@ async fn ensure_oauth_token(\n expires_in: u64,\n }\n \n- let body: TokenResponse = match resp.json().await {\n- Ok(b) => b,\n- Err(e) => {\n- tracing::warn!(\"reddit OAuth token parse failed: {e}\");\n- return None;\n- }\n- };\n+ let body: TokenResponse = resp\n+ .json()\n+ .await\n+ .map_err(|e| format!(\"Reddit OAuth token parse failed: {e}\"))?;\n \n- tracing::debug!(expires_in = body.expires_in, \"reddit OAuth token acquired\");\n- Some(OAuthToken {\n+ tracing::info!(expires_in = body.expires_in, \"reddit OAuth token acquired\");\n+ Ok(OAuthToken {\n access_token: body.access_token,\n expires_at: Instant::now() + Duration::from_secs(body.expires_in),\n })\n }\n \n+fn truncate_for_error(body: &str) -> String {\n+ let compact: String = body.split_whitespace().collect::>().join(\" \");\n+ if compact.is_empty() {\n+ return \"(empty body)\".into();\n+ }\n+ // Prefer the human-readable block message over dumping Reddit's CSS.\n+ if let Some(idx) = compact.find(\"You've been blocked\") {\n+ let slice: String = compact.chars().skip(idx).take(160).collect();\n+ return if compact.chars().count() > idx + 160 {\n+ format!(\"{slice}…\")\n+ } else {\n+ slice\n+ };\n+ }\n+ let chars: String = compact.chars().take(200).collect();\n+ if compact.chars().count() > 200 {\n+ format!(\"{chars}…\")\n+ } else {\n+ chars\n+ }\n+}\n+\n async fn do_fetch(\n client: &Client,\n url: &str,\n@@ -460,15 +548,16 @@ async fn do_fetch(\n \n if !status.is_success() {\n let body = resp.text().await.unwrap_or_default();\n+ let detail = truncate_for_error(&body);\n tracing::debug!(\n item = %id,\n %status,\n body_len = body.len(),\n- body_prefix = %body.chars().take(240).collect::(),\n+ %detail,\n \"reddit non-success body\"\n );\n if status == StatusCode::FORBIDDEN || status == StatusCode::UNAUTHORIZED {\n- return Err(format!(\"Reddit API {status}: {body}\"));\n+ return Ok(FetchOutcome::AuthRejected { status, detail });\n }\n return Ok(FetchOutcome::NotFound);\n }\n@@ -716,6 +805,15 @@ fn reddit_direct_image_url(url: &str) -> bool {\n mod tests {\n use super::*;\n \n+ #[test]\n+ fn truncate_error_prefers_block_message() {\n+ let html = r#\"
You've been blocked by network security. To continue, log in
\"#;\n+ let msg = truncate_for_error(html);\n+ assert!(msg.starts_with(\"You've been blocked\"));\n+ assert!(msg.len() < 200);\n+ assert!(!msg.contains(\".x{color\"));\n+ }\n+\n #[test]\n fn map_subreddit_about_url() {\n let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n\n\nSide B — contributor: tommy-mor\nSide B — commit message:\n[8f6be6d0] Add copy button for garden rankings (markdown clipboard) (#168)\n\n* Add garden ranking markdown copy button via POST /ui\n\nIntroduce HtmlUiAction::CopyGardenRank that rebuilds the visible child\nranking and returns JsBuilder clipboard JS (fetch → eval), matching\nCopyThread. Place a copy control on garden ranking headings; clipboard\ntext is a concise markdown numbered list with unranked bullets.\n\nCo-authored-by: tommy \n\n* Fix paren balance in garden ranking copy browser test\n\nCo-authored-by: tommy \n\n---------\n\nCo-authored-by: Cursor Agent \n\nSide B — unified diff (full patch):\ndiff --git a/agents.md b/agents.md\nindex 7d6fea5791f7c95677e17e8975a14df83f998fd6..1dc989e4b23071f2eef69f2479c9a1ca2bd04b32 100644\n--- a/agents.md\n+++ b/agents.md\n@@ -40,6 +40,8 @@ Strict **CSP** that blocks `eval` would break the current app. Other projects ma\n \n - **Non-morph `POST /ui` responses:** **`SetGardenPin`** returns **`303 See Other`** and **`Set-Cookie`** (same as **`POST /theme`**). Garden pin/unpin is a normal **`
`** — browser navigation applies cookies reliably (see **`test/browser_garden_pin.clj`**). Each **`__rpc__`** payload includes **`form_action: \"/ui\"`**; **`post_ui_html`** rejects mismatches to bind tokens to the UI endpoint.\n \n+- **`CopyGardenRank`:** Browser copy control on garden ranking headings. Returns **`text/javascript`** via **`JsBuilder::clipboard_write_text_and_label_btn`** (same **`fetch` → `eval`** loop as **`CopyThread`**). Payload includes **`room`**, **`parent_path`**, **`depth`**, **`copy_btn_id`**, and optional **`external_hosts`** (for **`/-/`** host-root indexes). Clipboard text is a concise markdown numbered list of display paths (plus unranked bullets).\n+\n - **`VoteComparePost`:** On success returns **`text/javascript`** that **morphs** **`#vote-edge-history-region`** (recomputed **`
    `** — ratios match **`left`/`right`** query order, bullets, sorted by strength toward **`left`** then newer) and **`.vote-compare-nav`** (fresh next-pair link). The compare **`GET`** page uses **`layout_full_bleed_chromeless`** (no breadcrumbs, no **`#controls`**, no **`slug-pin-hud`**; **`view-vote-compare-fullscreen`** full-width **`body`**). **`__rpc__`** carries **`form_action: \"/ui\"`**; **`thread_tag`** and ratio fields come from the same form as **`$form`** holes. **Guests** on a shared pair see the compose UI with **`post vote`** as a link to **`/login?next=`** (class **`vote-compare-login-cta`**); after OAuth / username selection they return to that matchup. An unauthenticated **`VoteComparePost`** (forged/stale form) still JS-redirects to the same **`/login?next=`** target.\n \n - **`ThreadGraduate` / `GraduateThread`:** Private-room forum threads with **Manage** can be published to the public site under the same tag. The writer replays non-redacted ingests into **`room: public`** (chronological order), then appends a durable **`ThreadGraduated`** marker. Graduated private threads show a banner linking to public **`/t/:tag`**, block further private posts, and cannot be graduated twice. CLI: **`npx slugsocial private forum graduate `**; RPC: **`ThreadGraduate`**.\ndiff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs\nindex b4a0c9e87e462050bd52728e49e0d6781bf1cfc8..611956d0a46062b49ce350be176e4be139312ff0 100644\n--- a/server/src/api/ui_html.rs\n+++ b/server/src/api/ui_html.rs\n@@ -24,9 +24,9 @@ use crate::{\n external_resolver_status_markup, fragment_new_thread_slot, login_to_post_hint_markup,\n parse_html_ui_from_form, room_members_section_markup, thread_feed_html,\n thread_feed_html_for_room, thread_feed_region_markup, thread_ui_collapse_redacted_post,\n- thread_ui_copy_thread,\n- thread_ui_expand_post_full, thread_ui_expand_redacted_post, ui_js_warn, user_can_post_room,\n- user_can_view_room, HtmlUiAction, JsBuilder, ThreadNav,\n+ garden_ui_copy_rank, thread_ui_copy_thread, thread_ui_expand_post_full,\n+ thread_ui_expand_redacted_post, ui_js_warn, user_can_post_room, user_can_view_room,\n+ HtmlUiAction, JsBuilder, ThreadNav,\n },\n reducer::{scope_from_room_wire, ScopeId},\n state::AppState,\n@@ -575,6 +575,25 @@ async fn dispatch_ui_action(\n let viewer = session.map(|s| s.username.as_str());\n thread_ui_copy_thread(state, &room, &thread_tag, ©_btn_id, viewer).await\n }\n+ HtmlUiAction::CopyGardenRank {\n+ room,\n+ parent_path,\n+ depth,\n+ copy_btn_id,\n+ external_hosts,\n+ } => {\n+ let viewer = session.map(|s| s.username.as_str());\n+ garden_ui_copy_rank(\n+ state,\n+ &room,\n+ &parent_path,\n+ depth,\n+ ©_btn_id,\n+ external_hosts,\n+ viewer,\n+ )\n+ .await\n+ }\n HtmlUiAction::GraduateThread { room, thread_tag } => {\n let Some(session) = session else {\n return js_redirect(\"/login\").into_response();\ndiff --git a/server/src/html/garden/copy.rs b/server/src/html/garden/copy.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..271ea87c34c99e23ab1b0d8572632fdc41380b78\n--- /dev/null\n+++ b/server/src/html/garden/copy.rs\n@@ -0,0 +1,199 @@\n+//! Copy garden rankings to the clipboard as concise markdown (POST /ui + JsBuilder eval).\n+\n+use crate::form_template::template_json_compact;\n+use crate::html::forum::ThreadNav;\n+use crate::html::js_string_literal;\n+use crate::html::ui_action::HtmlUiAction;\n+use crate::html::{JsBuilder, ui_js_warn};\n+use crate::path_types::ItemId;\n+use crate::reducer::scope_from_room_wire;\n+use crate::scope_rank::{\n+ build_children_rankings, build_rankings_for_item_set, external_root_host_items,\n+ resolve_scope_recursive, ChildrenRankings,\n+};\n+use crate::state::AppState;\n+use maud::{html, Markup};\n+\n+use super::access::user_can_view_room;\n+use super::item::item_display_path;\n+use crate::reducer::{ContentState, ScopeId};\n+\n+const COPY_BTN_ID: &str = \"garden-rank-copy\";\n+\n+/// `POST /ui` + `__rpc__` from an inline button; response body is `eval`'d (same as forum copy).\n+fn garden_ui_fetch_onclick(rpc_compact_json: &str) -> String {\n+ format!(\n+ \"fetch('/ui',{{method:'POST',headers:{{'Content-Type':'application/x-www-form-urlencoded'}},body:new URLSearchParams({{__rpc__:{}}}).toString(),credentials:'same-origin'}}).then(r=>r.text()).then(eval);return false\",\n+ js_string_literal(rpc_compact_json)\n+ )\n+}\n+\n+/// Concise markdown for ranked child groups (numbered lists + unranked bullets).\n+pub(crate) fn format_garden_rank_markdown(rankings: &ChildrenRankings) -> String {\n+ let mut out = String::new();\n+ let multi = rankings.component_rankings.len() > 1;\n+ for (ci, comp) in rankings.component_rankings.iter().enumerate() {\n+ if ci > 0 {\n+ out.push('\\n');\n+ }\n+ if multi {\n+ out.push_str(&format!(\"### ordering {}\\n\\n\", ci + 1));\n+ }\n+ for (i, r) in comp.ranked.iter().enumerate() {\n+ out.push_str(&format!(\n+ \"{}. {}\\n\",\n+ i + 1,\n+ item_display_path(r.item.as_str())\n+ ));\n+ }\n+ }\n+ if !rankings.unranked_items.is_empty() {\n+ if !out.is_empty() {\n+ out.push('\\n');\n+ }\n+ for name in &rankings.unranked_items {\n+ out.push_str(&format!(\"- {}\\n\", item_display_path(name.as_str())));\n+ }\n+ }\n+ out\n+}\n+\n+fn rankings_for_copy(\n+ state_content: &crate::reducer::ContentState,\n+ parent_path: &str,\n+ depth: usize,\n+ external_hosts: bool,\n+) -> ChildrenRankings {\n+ if external_hosts {\n+ let hosts = external_root_host_items(state_content);\n+ return build_rankings_for_item_set(state_content, &hosts);\n+ }\n+ let parent = ItemId::parse(parent_path.trim())\n+ .unwrap_or_else(|| ItemId::ontology_root())\n+ .normalized_storage();\n+ let depth = depth.clamp(1, 5);\n+ if depth > 1 {\n+ let items = resolve_scope_recursive(state_content, &[parent.as_str().to_string()], depth);\n+ build_rankings_for_item_set(state_content, &items)\n+ } else {\n+ build_children_rankings(state_content, &parent)\n+ }\n+}\n+\n+pub(crate) async fn garden_ui_copy_rank(\n+ state: &AppState,\n+ room: &str,\n+ parent_path: &str,\n+ depth: usize,\n+ copy_btn_id: &str,\n+ external_hosts: bool,\n+ viewer: Option<&str>,\n+) -> axum::response::Response {\n+ let room = room.trim();\n+ let scope = scope_from_room_wire(room);\n+ if let ScopeId::Room(ref rid) = scope {\n+ let reduced = state.reduced.read().await;\n+ if !user_can_view_room(&reduced, rid, viewer) {\n+ return ui_js_warn(\"forbidden\");\n+ }\n+ }\n+\n+ let reduced = state.reduced.read().await;\n+ let empty = ContentState::default();\n+ let content = match &scope {\n+ ScopeId::Public => reduced.public(),\n+ ScopeId::Room(_) => reduced.content_for_scope(&scope).unwrap_or(&empty),\n+ };\n+ let rankings = rankings_for_copy(content, parent_path, depth, external_hosts);\n+ let text = format_garden_rank_markdown(&rankings);\n+ drop(reduced);\n+\n+ if text.is_empty() {\n+ return ui_js_warn(\"nothing to copy\");\n+ }\n+\n+ JsBuilder::new()\n+ .clipboard_write_text_and_label_btn(&text, copy_btn_id, \"copied\")\n+ .into_response()\n+}\n+\n+pub(super) fn garden_rank_copy_button_markup(\n+ nav: &ThreadNav,\n+ parent_path: &str,\n+ depth: usize,\n+ external_hosts: bool,\n+) -> Markup {\n+ let rpc = template_json_compact(&HtmlUiAction::CopyGardenRank {\n+ room: nav.room_wire.clone(),\n+ parent_path: parent_path.to_string(),\n+ depth,\n+ copy_btn_id: COPY_BTN_ID.to_string(),\n+ external_hosts,\n+ })\n+ .expect(\"CopyGardenRank serializes\");\n+ html! {\n+ button type=\"button\" id=(COPY_BTN_ID) class=\"post-nav-btn ont-rank-copy-btn\" title=\"Copy ranking as markdown\"\n+ onclick=(garden_ui_fetch_onclick(&rpc)) {\n+ \"copy\"\n+ }\n+ }\n+}\n+\n+#[cfg(test)]\n+mod tests {\n+ use super::*;\n+ use crate::path_types::ItemId;\n+ use crate::ranking::RankedItem;\n+ use crate::scope_rank::ScopedComponent;\n+\n+ #[test]\n+ fn markdown_single_component_and_unranked() {\n+ let rankings = ChildrenRankings {\n+ component_rankings: vec![ScopedComponent {\n+ pairs: 1,\n+ ranked: vec![\n+ RankedItem {\n+ item: ItemId::parse(\"~/a\").unwrap(),\n+ score: 0.9,\n+ },\n+ RankedItem {\n+ item: ItemId::parse(\"~/b\").unwrap(),\n+ score: 0.1,\n+ },\n+ ],\n+ }],\n+ unranked_items: vec![ItemId::parse(\"~/c\").unwrap()],\n+ };\n+ assert_eq!(\n+ format_garden_rank_markdown(&rankings),\n+ \"1. ~/a\\n2. ~/b\\n\\n- ~/c\\n\"\n+ );\n+ }\n+\n+ #[test]\n+ fn markdown_multi_component_headers() {\n+ let rankings = ChildrenRankings {\n+ component_rankings: vec![\n+ ScopedComponent {\n+ pairs: 1,\n+ ranked: vec![RankedItem {\n+ item: ItemId::parse(\"~/a\").unwrap(),\n+ score: 1.0,\n+ }],\n+ },\n+ ScopedComponent {\n+ pairs: 1,\n+ ranked: vec![RankedItem {\n+ item: ItemId::parse(\"~/b\").unwrap(),\n+ score: 1.0,\n+ }],\n+ },\n+ ],\n+ unranked_items: vec![],\n+ };\n+ assert_eq!(\n+ format_garden_rank_markdown(&rankings),\n+ \"### ordering 1\\n\\n1. ~/a\\n\\n### ordering 2\\n\\n1. ~/b\\n\"\n+ );\n+ }\n+}\ndiff --git a/server/src/html/garden/mod.rs b/server/src/html/garden/mod.rs\nindex ee8696727e5473fe1fa913b8a7b9f3cb9c32d12f..69012a2c1d069e47fa611d63d3bd2a329fd6255d 100644\n--- a/server/src/html/garden/mod.rs\n+++ b/server/src/html/garden/mod.rs\n@@ -2,6 +2,7 @@\n \n mod access;\n mod browse;\n+mod copy;\n mod external;\n mod item;\n mod item_page;\n@@ -13,6 +14,7 @@ mod vote;\n #[cfg(test)]\n mod tests;\n \n+pub(crate) use copy::garden_ui_copy_rank;\n pub(crate) use external::external_resolver_status_markup;\n pub(crate) use pin::{encode_pin_cookie_value, GARDEN_PIN_COOKIE};\n pub(crate) use vote::vote_compare_post_success_js;\ndiff --git a/server/src/html/garden/render.rs b/server/src/html/garden/render.rs\nindex ca546693ecb2bb9ae5fb370f02b860c943f604b9..eed80e807d77e6b4eeeb0c3f38d6372e91ad2852 100644\n--- a/server/src/html/garden/render.rs\n+++ b/server/src/html/garden/render.rs\n@@ -25,6 +25,7 @@ use crate::{\n use super::{\n access::content_for_garden_view,\n browse::{garden_layout_meta, scoped_bc_path_for, GardenBrowsePath},\n+ copy::garden_rank_copy_button_markup,\n external::{external_frame_allowed, external_source_href, github_resolver_controls},\n item::{child_depth_from_uri, item_code_label, item_display_path, item_href},\n item_page::{build_item_page_view_model, sibling_nav_markup},\n@@ -196,6 +197,15 @@ pub(super) async fn render_scope_view(\n \" \"\n span class=\"muted\" { (format!(\"(depth {})\", model.child_depth)) }\n }\n+ @if total_children > 0 {\n+ \" \"\n+ (garden_rank_copy_button_markup(\n+ &nav,\n+ &item_display_path(&model.item),\n+ model.child_depth,\n+ false,\n+ ))\n+ }\n @if total_children >= 2 {\n \" \"\n a class=\"ont-vote-children-btn\" href=(vote_pool_href(&nav, &model.item)) {\ndiff --git a/server/src/html/garden/routes.rs b/server/src/html/garden/routes.rs\nindex 8a0499576d9093dbac0fffa1cf2ed88187e14acb..31b61355b1ec75645d405e16ab6abf8205c66380 100644\n--- a/server/src/html/garden/routes.rs\n+++ b/server/src/html/garden/routes.rs\n@@ -28,6 +28,7 @@ use crate::{\n use super::{\n access::{content_for_garden_view, room_not_found_page, room_scope_has_garden_content, user_can_view_room},\n browse::{GardenBrowsePath, scoped_bc_path_external},\n+ copy::garden_rank_copy_button_markup,\n item::{item_display_path, item_href},\n render::render_scope_view,\n };\n@@ -52,7 +53,13 @@ pub async fn garden_index(\n html! {\n @let root_path = OntologyPath::root();\n nav class=\"breadcrumb\" { (bc_path(&root_path)) }\n- h2 { \"paths\" }\n+ h2 {\n+ \"paths\"\n+ @if !(child_rankings.component_rankings.is_empty() && child_rankings.unranked_items.is_empty()) {\n+ \" \"\n+ (garden_rank_copy_button_markup(&nav, \"~/\", 1, false))\n+ }\n+ }\n @if child_rankings.component_rankings.is_empty() && child_rankings.unranked_items.is_empty() {\n p class=\"muted\" { \"no items yet\" }\n } @else {\n@@ -137,7 +144,13 @@ pub async fn external_garden_index(\n \"view-ontology view-ontology-light\",\n html! {\n nav class=\"breadcrumb\" { (bc_path_external(&ext_path)) }\n- h2 { \"external paths\" }\n+ h2 {\n+ \"external paths\"\n+ @if !(child_rankings.component_rankings.is_empty() && child_rankings.unranked_items.is_empty()) {\n+ \" \"\n+ (garden_rank_copy_button_markup(&nav, \"\", 1, true))\n+ }\n+ }\n p class=\"muted\" { \"Items outside slug.social use the \" code { \"-/\" } \" prefix followed by the full \" code { \"https://…\" } \" URL (legacy \" code { \"-/host/path\" } \" still works).\" }\n @if child_rankings.component_rankings.is_empty() && child_rankings.unranked_items.is_empty() {\n p class=\"muted\" { \"no external items indexed yet\" }\n@@ -272,7 +285,13 @@ pub async fn room_external_garden_index(\n \"view-ontology view-ontology-light\",\n html! {\n nav class=\"breadcrumb\" { (scoped_bc_path_external(&ext_path, &nav)) }\n- h2 { \"external paths\" }\n+ h2 {\n+ \"external paths\"\n+ @if !(child_rankings.component_rankings.is_empty() && child_rankings.unranked_items.is_empty()) {\n+ \" \"\n+ (garden_rank_copy_button_markup(&nav, \"\", 1, true))\n+ }\n+ }\n @if child_rankings.component_rankings.is_empty() && child_rankings.unranked_items.is_empty() {\n p class=\"muted\" { \"no external items indexed yet\" }\n } @else {\ndiff --git a/server/src/html/mod.rs b/server/src/html/mod.rs\nindex d7014fc7f934e5b0c7fb47ebf00cb4ef50d306c2..645d54f2e117ba901e02ed958ada6ff69a78ae34 100644\n--- a/server/src/html/mod.rs\n+++ b/server/src/html/mod.rs\n@@ -37,8 +37,8 @@ pub(crate) use forum::{\n user_can_post_room, user_can_view_room,\n };\n pub(crate) use garden::{\n- encode_pin_cookie_value, external_resolver_status_markup, vote_compare_post_success_js,\n- GARDEN_PIN_COOKIE,\n+ encode_pin_cookie_value, external_resolver_status_markup, garden_ui_copy_rank,\n+ vote_compare_post_success_js, GARDEN_PIN_COOKIE,\n };\n pub use garden::{\n external_garden_index, external_ontology_path, garden_index, ontology_path,\ndiff --git a/server/src/html/ui_action.rs b/server/src/html/ui_action.rs\nindex 5cf3168fb74e7654215cd9ff8942c6ed63fd0002..7dc3db062954370b5504fc311c0ab24bab569f80 100644\n--- a/server/src/html/ui_action.rs\n+++ b/server/src/html/ui_action.rs\n@@ -118,6 +118,18 @@ pub enum HtmlUiAction {\n thread_tag: String,\n copy_btn_id: String,\n },\n+ /// Copy garden child ranking as a concise markdown list to the clipboard.\n+ CopyGardenRank {\n+ room: String,\n+ /// Parent item path (storage or display). Ignored when `external_hosts` is true.\n+ parent_path: String,\n+ #[serde(default = \"default_garden_rank_depth\")]\n+ depth: usize,\n+ copy_btn_id: String,\n+ /// When true, copy rankings for external host roots (`/-/` index), not parent children.\n+ #[serde(default)]\n+ external_hosts: bool,\n+ },\n /// Publish a private-room thread to the public forum (Manage only).\n GraduateThread {\n room: String,\n@@ -125,6 +137,10 @@ pub enum HtmlUiAction {\n },\n }\n \n+fn default_garden_rank_depth() -> usize {\n+ 1\n+}\n+\n #[derive(Debug, Error)]\n pub enum HtmlUiParseError {\n #[error(\"missing __rpc__ field\")]\n@@ -272,4 +288,57 @@ mod tests {\n }\n );\n }\n+\n+ #[test]\n+ fn copy_garden_rank_round_trip() {\n+ let template = serde_json::json!({\n+ \"action\": \"copy_garden_rank\",\n+ \"room\": \"public\",\n+ \"parent_path\": \"~/topic\",\n+ \"depth\": 2,\n+ \"copy_btn_id\": \"garden-rank-copy\",\n+ });\n+ let mut form = HashMap::new();\n+ form.insert(\n+ UI_RPC_FIELD.to_string(),\n+ serde_json::to_string(&template).unwrap(),\n+ );\n+ let a = parse_html_ui_from_form(&form).unwrap();\n+ assert_eq!(\n+ a,\n+ HtmlUiAction::CopyGardenRank {\n+ room: \"public\".into(),\n+ parent_path: \"~/topic\".into(),\n+ depth: 2,\n+ copy_btn_id: \"garden-rank-copy\".into(),\n+ external_hosts: false,\n+ }\n+ );\n+ }\n+\n+ #[test]\n+ fn copy_garden_rank_defaults_depth_and_external_hosts() {\n+ let template = serde_json::json!({\n+ \"action\": \"copy_garden_rank\",\n+ \"room\": \"public\",\n+ \"parent_path\": \"~/\",\n+ \"copy_btn_id\": \"garden-rank-copy\",\n+ });\n+ let mut form = HashMap::new();\n+ form.insert(\n+ UI_RPC_FIELD.to_string(),\n+ serde_json::to_string(&template).unwrap(),\n+ );\n+ let a = parse_html_ui_from_form(&form).unwrap();\n+ assert_eq!(\n+ a,\n+ HtmlUiAction::CopyGardenRank {\n+ room: \"public\".into(),\n+ parent_path: \"~/\".into(),\n+ depth: 1,\n+ copy_btn_id: \"garden-rank-copy\".into(),\n+ external_hosts: false,\n+ }\n+ );\n+ }\n }\ndiff --git a/server/tests/integration_ui.rs b/server/tests/integration_ui.rs\nindex d242abff5769cc704b3c8070d7456e5788c31a45..6b1475b773106a2dd3f326475c9fb4cc727f6b4b 100644\n--- a/server/tests/integration_ui.rs\n+++ b/server/tests/integration_ui.rs\n@@ -490,3 +490,71 @@ async fn test_vote_compare_post_rejects_over_max_ratio() {\n );\n }\n \n+#[tokio::test]\n+async fn test_copy_garden_rank_returns_clipboard_js_with_markdown() {\n+ let (addr, _tmp, _log, _handle) = create_test_server().await;\n+ let client = reqwest::Client::new();\n+ let bearer = test_bearer();\n+\n+ let seed = rpc_batch(\n+ &client,\n+ addr,\n+ Some(&bearer),\n+ serde_json::json!([{\n+ \"Post\": {\n+ \"room\": \"public\",\n+ \"thread_tag\": \"copy-rank-ui\",\n+ \"text\": \"# copy-rank-ui\\n\\n~/copy-a {a}\\n~/copy-b {b}\\n~/copy-c {c}\\n{vote}\\n~/copy-a 2:1 ~/copy-b\\n\",\n+ \"return_rank_diff\": false\n+ }\n+ }]),\n+ )\n+ .await;\n+ assert_eq!(seed[\"results\"][0][\"ok\"], true, \"seed: {:?}\", seed);\n+\n+ let page = client\n+ .get(format!(\"http://{addr}/~\"))\n+ .send()\n+ .await\n+ .unwrap();\n+ assert!(page.status().is_success());\n+ let html = page.text().await.unwrap();\n+ assert!(\n+ html.contains(\"id=\\\"garden-rank-copy\\\"\") && html.contains(\"copy_garden_rank\"),\n+ \"garden index should include copy button + action payload\"\n+ );\n+\n+ let rpc = serde_json::json!({\n+ \"action\": \"copy_garden_rank\",\n+ \"room\": \"public\",\n+ \"parent_path\": \"~/\",\n+ \"depth\": 1,\n+ \"copy_btn_id\": \"garden-rank-copy\",\n+ })\n+ .to_string();\n+ let resp = client\n+ .post(format!(\"http://{addr}/ui\"))\n+ .header(\"Authorization\", format!(\"Bearer {bearer}\"))\n+ .form(&[(\"__rpc__\", rpc.as_str())])\n+ .send()\n+ .await\n+ .unwrap();\n+ assert_eq!(resp.status(), reqwest::StatusCode::OK);\n+ assert_eq!(\n+ resp.headers()\n+ .get(reqwest::header::CONTENT_TYPE)\n+ .and_then(|v| v.to_str().ok()),\n+ Some(\"text/javascript; charset=utf-8\")\n+ );\n+ let js = resp.text().await.unwrap();\n+ assert!(\n+ js.contains(\"navigator.clipboard.writeText\") && js.contains(\"garden-rank-copy\"),\n+ \"expected clipboard JsBuilder snippet, got: {js}\"\n+ );\n+ assert!(\n+ js.contains(\"1. ~/copy-a\") && js.contains(\"2. ~/copy-b\") && js.contains(\"- ~/copy-c\"),\n+ \"expected concise markdown ranking in clipboard payload, got: {js}\"\n+ );\n+ assert!(js.contains(\"\\\"copied\\\"\"), \"expected button label flip to copied\");\n+}\n+\ndiff --git a/test/browser_public_garden.clj b/test/browser_public_garden.clj\nindex 5dd49f1f70c870e25a2a9f5348f0bdb85647e897..8ceb532c664f9fc3d6f66a451e5ea5eaa1671007 100644\n--- a/test/browser_public_garden.clj\n+++ b/test/browser_public_garden.clj\n@@ -73,6 +73,7 @@\n (core/with-playwright [pw]\n (core/with-browser [browser (core/launch-chromium pw {:headless true :channel \"chrome\"})]\n (core/with-context [ctx (core/new-context browser)]\n+ (core/context-grant-permissions! ctx [\"clipboard-read\" \"clipboard-write\"])\n (core/with-page [pg (core/new-page-from-context ctx)]\n (page/navigate pg (str base-url \"/login\"))\n (is (wait-for-text pg \"body\" \"@alice\" 15000) \"alice session after login\")\n@@ -84,7 +85,12 @@\n (is (wait-for-text pg \"body\" \"~/br-pub-b\" 10000) \"ranked list shows ~/br-pub-b\")\n (is (wait-for-text pg \"body\" \"unranked\" 10000) \"unranked section present\")\n (is (wait-for-text pg \"body\" \"~/br-pub-c\" 10000)\n- \"unranked list shows ~/br-pub-c\"))))))\n+ \"unranked list shows ~/br-pub-c\")\n+ (is (wait-for-text pg \"#garden-rank-copy\" \"copy\" 5000)\n+ \"garden ranking copy button visible\")\n+ (locator/click (page/locator pg \"#garden-rank-copy\"))\n+ (is (wait-for-text pg \"#garden-rank-copy\" \"copied\" 10000)\n+ \"copy button flips to copied after POST /ui eval\"))))))\n \n (finally\n (when-some [s @!server] (common/kill-server s))\n","role":"user"}],"model":"openai/gpt-chat-latest"}