{"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[239c074b] url schema stuff\n\nSide A — unified diff (full patch):\ndiff --git a/AGENTS.md b/AGENTS.md\nindex 426a88e7c1da54fe0a28c5c76fa4e1f1bc117fcf..e60b9ba6012593361ef10e8fdd9439cd9932e09b 100644\n--- a/AGENTS.md\n+++ b/AGENTS.md\n@@ -58,3 +58,4 @@ Use **tmux** for `cargo run --package sorter2-server` (dev server). Rebuild afte\n \n - First `cargo test` / `cargo build --release` is slow; Clojure smoke test always does a release build.\n - `legacy/` and `ideas/` are not part of the workspace build.\n+- **ItemId** for web URLs is a canonical full URL (`https://reddit.com/r/rust`). Rules live in [`server/src/url_rules/`](server/src/url_rules/) (composable Rust, not a config DSL). After changing canonicalization rules, rebuild the projection: `cargo run --package sorter2-server -- replay-index`.\ndiff --git a/Cargo.lock b/Cargo.lock\nindex 0dd4fce5fb6400ae153cca4e3dbf5a5158e6d8b4..49a908ef935c430dbe63c6a28d8a24e38b489486 100644\n--- a/Cargo.lock\n+++ b/Cargo.lock\n@@ -1951,6 +1951,7 @@ dependencies = [\n \"tower-http 0.5.2\",\n \"tracing\",\n \"tracing-subscriber\",\n+ \"url\",\n \"urlencoding\",\n ]\n \ndiff --git a/REPLAY.sh b/REPLAY.sh\nnew file mode 100755\nindex 0000000000000000000000000000000000000000..f2dbd8aea60c02d2feef74805f7ef5c2b7022537\n--- /dev/null\n+++ b/REPLAY.sh\n@@ -0,0 +1,2 @@\n+cargo run --package sorter2-server -- replay-index\n+\ndiff --git a/server/Cargo.toml b/server/Cargo.toml\nindex 27f552c20b97ef28cdde4cb6b1a4980375135111..ad4912791aff59fb1d3293f66ad381ae618cd60b 100644\n--- a/server/Cargo.toml\n+++ b/server/Cargo.toml\n@@ -24,6 +24,7 @@ async-stream = \"0.3\"\n futures-util = { version = \"0.3\", default-features = false, features = [\"std\"] }\n rand = \"0.8\"\n urlencoding = \"2\"\n+url = \"2\"\n durable = { path = \"../durable\" }\n \n [dev-dependencies]\ndiff --git a/server/src/entity_store.rs b/server/src/entity_store.rs\nindex d5d17c3676e4a8ddec998e9f5a9dbafe9c2d9d0e..d29f39aecca6f12cdcf263cf77c3654eb4ee6cfa 100644\n--- a/server/src/entity_store.rs\n+++ b/server/src/entity_store.rs\n@@ -124,7 +124,7 @@ mod tests {\n fn round_trip_payload() {\n let tmp = tempfile::tempdir().unwrap();\n let store = EntityStore::open(tmp.path()).unwrap();\n- let id = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n let payload = json!({\"kind\": \"t5\", \"data\": {\"display_name\": \"rust\"}});\n \n store.put(&id, &payload).unwrap();\ndiff --git a/server/src/event_log.rs b/server/src/event_log.rs\nindex 36f5b406084065b608735987cdb483c236e03081..2c9290b6fdbf2c2ad1c0f1ffd7374b2d9cc97f36 100644\n--- a/server/src/event_log.rs\n+++ b/server/src/event_log.rs\n@@ -199,7 +199,7 @@ mod tests {\n log.append(&sample_record(\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n ))\n .await\n@@ -237,7 +237,7 @@ mod tests {\n let path = tmp.path().join(\"events.jsonl\");\n let log = EventLog::new(&path);\n let event = Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n };\n log.append(&sample_record(1, event)).await.unwrap();\n \n@@ -255,7 +255,7 @@ mod tests {\n let path = tmp.path().join(\"events.jsonl\");\n std::fs::write(\n &path,\n- r#\"{\"type\":\"node_ensured\",\"id\":\"reddit.com/r/rust\"}\n+ r#\"{\"type\":\"node_ensured\",\"id\":\"https://reddit.com/r/rust\"}\n {\"schema\":1,\"seq\":1,\"ts\":1,\"event\":{\"type\":\"vote_recorded\",\"ts\":1,\"a\":\"a\",\"b\":\"b\",\"ratio_left\":2,\"ratio_right\":1,\"scope\":\"\"}}\n \"#,\n )\n@@ -295,7 +295,7 @@ mod tests {\n log.append(&sample_record(\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n ))\n .await\n@@ -303,7 +303,7 @@ mod tests {\n log.append(&sample_record(\n 3,\n Event::NodeEnsured {\n- id: \"reddit.com/r/python\".into(),\n+ id: \"https://reddit.com/r/python\".into(),\n },\n ))\n .await\ndiff --git a/server/src/journal.rs b/server/src/journal.rs\nindex 521a108019de1ea870d14c4fafbfe572c20ce0de..50bc89f976edb82b7b0e49e954a8eccbbe82bf87 100644\n--- a/server/src/journal.rs\n+++ b/server/src/journal.rs\n@@ -141,10 +141,10 @@ mod tests {\n let j2 = journal.clone();\n let (r1, r2) = tokio::join!(\n j1.append(Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n }),\n j2.append(Event::NodeEnsured {\n- id: \"reddit.com/r/python\".into(),\n+ id: \"https://reddit.com/r/python\".into(),\n }),\n );\n r1.unwrap();\n@@ -153,10 +153,10 @@ mod tests {\n assert_eq!(projection_store.last_applied_event_count().unwrap(), 2);\n let tree = projection_store.load_tree().unwrap();\n assert!(tree\n- .get(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .is_some());\n assert!(tree\n- .get(&ItemId::parse(\"reddit.com/r/python\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/python\").unwrap())\n .is_some());\n }\n \n@@ -170,7 +170,7 @@ mod tests {\n 1,\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n ))\n .await\n@@ -186,7 +186,7 @@ mod tests {\n 1,\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n )],\n )\n@@ -202,7 +202,7 @@ mod tests {\n );\n journal\n .append(Event::NodeEnsured {\n- id: \"reddit.com/r/python\".into(),\n+ id: \"https://reddit.com/r/python\".into(),\n })\n .await\n .unwrap();\n@@ -227,13 +227,13 @@ mod tests {\n journal\n .append_many(vec![\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n Event::NodeEnsured {\n- id: \"reddit.com/r/python\".into(),\n+ id: \"https://reddit.com/r/python\".into(),\n },\n Event::NodeEnsured {\n- id: \"reddit.com/r/clojure\".into(),\n+ id: \"https://reddit.com/r/clojure\".into(),\n },\n ])\n .await\n@@ -245,7 +245,7 @@ mod tests {\n assert_eq!(projection_store.last_applied_event_count().unwrap(), 3);\n let tree = projection_store.load_tree().unwrap();\n assert!(tree\n- .get(&ItemId::parse(\"reddit.com/r/clojure\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/clojure\").unwrap())\n .is_some());\n }\n }\ndiff --git a/server/src/lib.rs b/server/src/lib.rs\nindex 9bd5f76fd1406b9b1be4c272f4ba8647edde2678..5c02c8e704e4664453bad75d819df8a067668176 100644\n--- a/server/src/lib.rs\n+++ b/server/src/lib.rs\n@@ -9,6 +9,7 @@ pub mod journal;\n pub mod pair;\n pub mod parser;\n pub mod path_types;\n+pub mod url_rules;\n pub mod projection_apply;\n pub mod projection_store;\n pub mod ranking;\ndiff --git a/server/src/pair.rs b/server/src/pair.rs\nindex 43f780ba6ea6ce1cdc2e1f4cbb252ba8a10684b9..815a97b80e3e9f348e0937a4f147f2862018edb0 100644\n--- a/server/src/pair.rs\n+++ b/server/src/pair.rs\n@@ -381,42 +381,42 @@ mod tests {\n \n #[test]\n fn suggest_prefers_unvoted_pair() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n let mut tree = seed_children(\n &parent,\n &[\n- \"reddit.com/r/rust/a\",\n- \"reddit.com/r/rust/b\",\n- \"reddit.com/r/rust/c\",\n+ \"https://reddit.com/r/rust/a\",\n+ \"https://reddit.com/r/rust/b\",\n+ \"https://reddit.com/r/rust/c\",\n ],\n );\n let vote =\n- VoteData::from_recorded(1, \"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\", 2, 1).unwrap();\n+ VoteData::from_recorded(1, \"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\", 2, 1).unwrap();\n tree.apply_vote(&parent, vote);\n let group = tree.get(&parent).unwrap().local_ranking.clone();\n let pool = children_of(&tree, &parent);\n let (l, r) = suggest_next_pair_in_pool(&group, &pool, None).unwrap();\n- let voted_ab = (l.as_str() == \"reddit.com/r/rust/a\" && r.as_str() == \"reddit.com/r/rust/b\")\n- || (l.as_str() == \"reddit.com/r/rust/b\" && r.as_str() == \"reddit.com/r/rust/a\");\n+ let voted_ab = (l.as_str() == \"https://reddit.com/r/rust/a\" && r.as_str() == \"https://reddit.com/r/rust/b\")\n+ || (l.as_str() == \"https://reddit.com/r/rust/b\" && r.as_str() == \"https://reddit.com/r/rust/a\");\n assert!(!voted_ab);\n }\n \n #[test]\n fn suggest_bridges_separate_components() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n let mut tree = seed_children(\n &parent,\n &[\n- \"reddit.com/r/rust/a\",\n- \"reddit.com/r/rust/b\",\n- \"reddit.com/r/rust/c\",\n- \"reddit.com/r/rust/d\",\n+ \"https://reddit.com/r/rust/a\",\n+ \"https://reddit.com/r/rust/b\",\n+ \"https://reddit.com/r/rust/c\",\n+ \"https://reddit.com/r/rust/d\",\n ],\n );\n let ab =\n- VoteData::from_recorded(1, \"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\", 2, 1).unwrap();\n+ VoteData::from_recorded(1, \"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\", 2, 1).unwrap();\n let cd =\n- VoteData::from_recorded(2, \"reddit.com/r/rust/c\", \"reddit.com/r/rust/d\", 2, 1).unwrap();\n+ VoteData::from_recorded(2, \"https://reddit.com/r/rust/c\", \"https://reddit.com/r/rust/d\", 2, 1).unwrap();\n tree.apply_vote(&parent, ab);\n tree.apply_vote(&parent, cd);\n let group = tree.get(&parent).unwrap().local_ranking.clone();\n@@ -424,37 +424,37 @@ mod tests {\n let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();\n let chosen = pair_set(&pair);\n let from_ab =\n- chosen.contains(\"reddit.com/r/rust/a\") || chosen.contains(\"reddit.com/r/rust/b\");\n+ chosen.contains(\"https://reddit.com/r/rust/a\") || chosen.contains(\"https://reddit.com/r/rust/b\");\n let from_cd =\n- chosen.contains(\"reddit.com/r/rust/c\") || chosen.contains(\"reddit.com/r/rust/d\");\n+ chosen.contains(\"https://reddit.com/r/rust/c\") || chosen.contains(\"https://reddit.com/r/rust/d\");\n assert!(from_ab && from_cd, \"expected bridge pair, got {:?}\", chosen);\n }\n \n #[test]\n fn suggest_prefers_attach_over_isolate_pair_among_many_unranked() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n let mut tree = seed_children(\n &parent,\n &[\n- \"reddit.com/r/rust/a\",\n- \"reddit.com/r/rust/b\",\n- \"reddit.com/r/rust/c\",\n- \"reddit.com/r/rust/d\",\n- \"reddit.com/r/rust/e\",\n+ \"https://reddit.com/r/rust/a\",\n+ \"https://reddit.com/r/rust/b\",\n+ \"https://reddit.com/r/rust/c\",\n+ \"https://reddit.com/r/rust/d\",\n+ \"https://reddit.com/r/rust/e\",\n ],\n );\n let ab =\n- VoteData::from_recorded(1, \"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\", 2, 1).unwrap();\n+ VoteData::from_recorded(1, \"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\", 2, 1).unwrap();\n tree.apply_vote(&parent, ab);\n let group = tree.get(&parent).unwrap().local_ranking.clone();\n let pool = children_of(&tree, &parent);\n let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();\n let chosen = pair_set(&pair);\n let from_ab =\n- chosen.contains(\"reddit.com/r/rust/a\") || chosen.contains(\"reddit.com/r/rust/b\");\n- let from_cde = chosen.contains(\"reddit.com/r/rust/c\")\n- || chosen.contains(\"reddit.com/r/rust/d\")\n- || chosen.contains(\"reddit.com/r/rust/e\");\n+ chosen.contains(\"https://reddit.com/r/rust/a\") || chosen.contains(\"https://reddit.com/r/rust/b\");\n+ let from_cde = chosen.contains(\"https://reddit.com/r/rust/c\")\n+ || chosen.contains(\"https://reddit.com/r/rust/d\")\n+ || chosen.contains(\"https://reddit.com/r/rust/e\");\n assert!(\n from_ab && from_cde,\n \"expected ranked+unranked attach, got {:?}\",\n@@ -464,40 +464,40 @@ mod tests {\n \n #[test]\n fn suggest_connects_isolate_to_existing_component() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n let mut tree = seed_children(\n &parent,\n &[\n- \"reddit.com/r/rust/a\",\n- \"reddit.com/r/rust/b\",\n- \"reddit.com/r/rust/c\",\n+ \"https://reddit.com/r/rust/a\",\n+ \"https://reddit.com/r/rust/b\",\n+ \"https://reddit.com/r/rust/c\",\n ],\n );\n let ab =\n- VoteData::from_recorded(1, \"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\", 2, 1).unwrap();\n+ VoteData::from_recorded(1, \"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\", 2, 1).unwrap();\n tree.apply_vote(&parent, ab);\n let group = tree.get(&parent).unwrap().local_ranking.clone();\n let pool = children_of(&tree, &parent);\n let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();\n let chosen = pair_set(&pair);\n- assert!(chosen.contains(\"reddit.com/r/rust/c\"));\n- assert!(chosen.contains(\"reddit.com/r/rust/a\") || chosen.contains(\"reddit.com/r/rust/b\"));\n+ assert!(chosen.contains(\"https://reddit.com/r/rust/c\"));\n+ assert!(chosen.contains(\"https://reddit.com/r/rust/a\") || chosen.contains(\"https://reddit.com/r/rust/b\"));\n }\n \n #[test]\n fn suggest_zips_adjacent_ranks_when_tree_complete() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n let mut tree = seed_children(\n &parent,\n &[\n- \"reddit.com/r/rust/a\",\n- \"reddit.com/r/rust/b\",\n- \"reddit.com/r/rust/c\",\n+ \"https://reddit.com/r/rust/a\",\n+ \"https://reddit.com/r/rust/b\",\n+ \"https://reddit.com/r/rust/c\",\n ],\n );\n for (a, b, l, r) in [\n- (\"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\", 3, 1),\n- (\"reddit.com/r/rust/a\", \"reddit.com/r/rust/c\", 2, 1),\n+ (\"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\", 3, 1),\n+ (\"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/c\", 2, 1),\n ] {\n let v = VoteData::from_recorded(1, a, b, l, r).unwrap();\n tree.apply_vote(&parent, v);\n@@ -506,26 +506,26 @@ mod tests {\n let pool = children_of(&tree, &parent);\n let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();\n let chosen = pair_set(&pair);\n- assert!(chosen.contains(\"reddit.com/r/rust/b\"));\n- assert!(chosen.contains(\"reddit.com/r/rust/c\"));\n+ assert!(chosen.contains(\"https://reddit.com/r/rust/b\"));\n+ assert!(chosen.contains(\"https://reddit.com/r/rust/c\"));\n }\n \n #[test]\n fn suggest_zip_prefers_1v2_before_2v3_when_both_unvoted() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n let mut tree = seed_children(\n &parent,\n &[\n- \"reddit.com/r/rust/a\",\n- \"reddit.com/r/rust/b\",\n- \"reddit.com/r/rust/c\",\n- \"reddit.com/r/rust/d\",\n+ \"https://reddit.com/r/rust/a\",\n+ \"https://reddit.com/r/rust/b\",\n+ \"https://reddit.com/r/rust/c\",\n+ \"https://reddit.com/r/rust/d\",\n ],\n );\n for (a, b, l, r) in [\n- (\"reddit.com/r/rust/c\", \"reddit.com/r/rust/d\", 3, 1),\n- (\"reddit.com/r/rust/b\", \"reddit.com/r/rust/c\", 2, 1),\n- (\"reddit.com/r/rust/a\", \"reddit.com/r/rust/c\", 2, 1),\n+ (\"https://reddit.com/r/rust/c\", \"https://reddit.com/r/rust/d\", 3, 1),\n+ (\"https://reddit.com/r/rust/b\", \"https://reddit.com/r/rust/c\", 2, 1),\n+ (\"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/c\", 2, 1),\n ] {\n let v = VoteData::from_recorded(1, a, b, l, r).unwrap();\n tree.apply_vote(&parent, v);\n@@ -534,16 +534,16 @@ mod tests {\n let pool = children_of(&tree, &parent);\n let pair = suggest_next_pair_in_pool(&group, &pool, None).unwrap();\n let chosen = pair_set(&pair);\n- assert!(chosen.contains(\"reddit.com/r/rust/a\"));\n- assert!(chosen.contains(\"reddit.com/r/rust/b\"));\n+ assert!(chosen.contains(\"https://reddit.com/r/rust/a\"));\n+ assert!(chosen.contains(\"https://reddit.com/r/rust/b\"));\n }\n \n #[test]\n fn resolve_pair_picks_from_pool() {\n- let parent = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n- let tree = seed_children(&parent, &[\"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\"]);\n+ let parent = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n+ let tree = seed_children(&parent, &[\"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\"]);\n let pair = resolve_pair(&tree, &parent, None, None).unwrap();\n- let pool: HashSet<_> = [\"reddit.com/r/rust/a\", \"reddit.com/r/rust/b\"]\n+ let pool: HashSet<_> = [\"https://reddit.com/r/rust/a\", \"https://reddit.com/r/rust/b\"]\n .into_iter()\n .collect();\n assert!(pool.contains(pair.0.as_str()));\ndiff --git a/server/src/parser.rs b/server/src/parser.rs\nindex 9df2dcc9313f7fe250ce3b6aa167f6ec5d57951f..b2a963dd6cab415576c8d3a9a241966758565bb8 100644\n--- a/server/src/parser.rs\n+++ b/server/src/parser.rs\n@@ -23,7 +23,7 @@ mod tests {\n fn parses_short_path() {\n assert_eq!(\n parse_reddit_url(\"r/rust\").unwrap().as_str(),\n- \"reddit.com/r/rust\"\n+ \"https://reddit.com/r/rust\"\n );\n }\n \n@@ -33,7 +33,7 @@ mod tests {\n parse_reddit_url(\"https://www.reddit.com/r/programming/hot\")\n .unwrap()\n .as_str(),\n- \"reddit.com/r/programming\"\n+ \"https://reddit.com/r/programming\"\n );\n }\n \n@@ -43,7 +43,10 @@ mod tests {\n \"https://old.reddit.com/r/AmItheAsshole/comments/1trnvdl/aita_for_cancelling/\",\n )\n .unwrap();\n- assert_eq!(id.as_str(), \"reddit.com/r/amitheasshole/comments/1trnvdl\");\n+ assert_eq!(\n+ id.as_str(),\n+ \"https://reddit.com/r/amitheasshole/comments/1trnvdl\"\n+ );\n }\n \n #[test]\ndiff --git a/server/src/path_types.rs b/server/src/path_types.rs\nindex fafd924452f6fd85e7a5b27ed2653a19581e6e56..71ffc01f35c5589686ff05dae3b5610fa01f30ce 100644\n--- a/server/src/path_types.rs\n+++ b/server/src/path_types.rs\n@@ -1,13 +1,14 @@\n use serde::{Deserialize, Serialize};\n use std::fmt;\n \n-/// Canonical hierarchical identity for any URL/path in the fractal tree.\n+use crate::url_rules::{looks_like_url, navigable_breadcrumbs, parent_url, resolve_canonical};\n+\n+/// Canonical identity: a real URL (with scheme) or an opaque non-URL key.\n #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default)]\n pub struct ItemId(String);\n \n impl ItemId {\n- /// Parse an already-canonical path (no URL normalization). Empty string is invalid here;\n- /// use [`Self::root`] for the tree root.\n+ /// Parse an already-canonical id (no normalization). Empty string is invalid; use [`Self::root`].\n pub fn parse(s: &str) -> Option {\n let t = s.trim();\n if t.is_empty() {\n@@ -16,12 +17,12 @@ impl ItemId {\n Some(Self(t.to_string()))\n }\n \n- /// Build an opaque item key (legacy demo votes, non-URL items).\n+ /// Build an opaque item key (demo votes, non-URL items).\n pub fn opaque(s: impl Into) -> Self {\n Self(s.into())\n }\n \n- /// Root of the internet tree (empty path).\n+ /// Root of the internet tree.\n pub fn root() -> Self {\n Self(String::new())\n }\n@@ -34,23 +35,18 @@ impl ItemId {\n &self.0\n }\n \n- /// Creates a canonical ID from a raw URL or path. Normalizes domains and\n- /// trims tracking query params.\n+ /// Canonical URL from a raw pasted or fetched URL.\n pub fn from_url(raw_url: &str) -> Option {\n- Self::canonicalize(raw_url).map(Self)\n+ resolve_canonical(raw_url).map(Self)\n }\n \n- /// Normalize strings from forms, events, and Reddit imports into the same\n- /// stored id shape (e.g. drop post title slug after comment id).\n+ /// Normalize strings from forms, events, and imports into canonical identity.\n pub fn from_storage(s: &str) -> Option {\n let t = s.trim();\n if t.is_empty() {\n return None;\n }\n- if t.contains(\"://\") || t.starts_with(\"r/\") {\n- return Self::from_url(t).or_else(|| Self::parse(t));\n- }\n- if t.starts_with(\"reddit.com/\") && t.contains(\"/comments/\") {\n+ if looks_like_url(t) {\n return Self::from_url(t).or_else(|| Self::parse(t));\n }\n Self::parse(t).or_else(|| Self::from_url(t))\n@@ -62,35 +58,52 @@ impl ItemId {\n if s.is_empty() {\n return Self::root();\n }\n- Self(format!(\"reddit.com/r/{s}\"))\n+ if looks_like_url(s) || s.contains('/') {\n+ Self::from_storage(s).unwrap_or_else(|| Self::opaque(s))\n+ } else {\n+ Self(format!(\"https://reddit.com/r/{s}\"))\n+ }\n }\n \n- /// Extract the parent, e.g. `reddit.com/r/aww/comments/1trnvdl` →\n- /// `reddit.com/r/aww`.\n+ /// Immediate parent scope in the tree.\n pub fn parent(&self) -> Option {\n- if self.0.is_empty() {\n+ if self.is_root() {\n return None;\n }\n-\n+ if looks_like_url(self.0.as_str()) {\n+ return parent_url(self.0.as_str()).map(Self);\n+ }\n let parts: Vec<&str> = self.0.trim_end_matches('/').split('/').collect();\n if parts.len() <= 1 {\n return None;\n }\n-\n- if self.0.contains(\"/comments/\") {\n- return Some(Self(parts[..parts.len().saturating_sub(2)].join(\"/\")));\n- }\n-\n Some(Self(parts[..parts.len() - 1].join(\"/\")))\n }\n \n pub fn segments(&self) -> Vec<&str> {\n+ if self.is_root() {\n+ return vec![];\n+ }\n+ if let Some(rest) = self.0.strip_prefix(\"https://\") {\n+ return rest.split('/').filter(|s| !s.is_empty()).collect();\n+ }\n+ if let Some(rest) = self.0.strip_prefix(\"http://\") {\n+ return rest.split('/').filter(|s| !s.is_empty()).collect();\n+ }\n self.0.split('/').filter(|s| !s.is_empty()).collect()\n }\n \n- /// Cumulative paths for breadcrumb rendering, e.g.\n- /// `reddit.com/r/movies` → `[\"reddit.com\", \"reddit.com/r\", \"reddit.com/r/movies\"]`.\n+ /// Cumulative navigable paths for breadcrumbs and tree wiring (includes self).\n pub fn breadcrumb_paths(&self) -> Vec {\n+ if self.is_root() {\n+ return vec![];\n+ }\n+ if looks_like_url(self.0.as_str()) {\n+ return navigable_breadcrumbs(self.0.as_str())\n+ .into_iter()\n+ .map(ItemId)\n+ .collect();\n+ }\n let segs = self.segments();\n let mut paths = Vec::with_capacity(segs.len());\n let mut current = String::new();\n@@ -111,13 +124,13 @@ impl ItemId {\n if self.is_root() {\n return String::new();\n }\n- if self.as_str().contains(\"://\") {\n- return self.as_str().to_string();\n+ if self.0.contains(\"://\") {\n+ return self.0.clone();\n }\n if self.segments().first().is_some_and(|s| s.contains('.')) {\n- format!(\"https://{}\", self.as_str())\n+ format!(\"https://{}\", self.0)\n } else {\n- self.as_str().to_string()\n+ self.0.clone()\n }\n }\n \n@@ -144,70 +157,6 @@ impl ItemId {\n pub fn from_browse_uri(path: &str) -> Option {\n path.strip_prefix(\"/~/\").map(ItemId::from_browse_tail)\n }\n-\n- fn canonicalize(raw: &str) -> Option {\n- let s = raw.trim();\n- if s.is_empty() {\n- return None;\n- }\n-\n- let owned = if let Some(rest) = s.strip_prefix(\"r/\") {\n- format!(\"reddit.com/r/{rest}\")\n- } else if let Some(rest) = s.strip_prefix(\"/r/\") {\n- format!(\"reddit.com/r/{rest}\")\n- } else {\n- s.to_string()\n- };\n-\n- let (host_path, _query) = split_query(&owned);\n- let host_path = host_path.trim_end_matches('/');\n-\n- let path = if host_path.contains(\"://\") {\n- parse_url_host_path(host_path)?\n- } else if host_path.starts_with(\"reddit.com\") || host_path.starts_with(\"www.reddit.com\") {\n- normalize_reddit_host_path(host_path)\n- } else if host_path.contains('/') {\n- host_path.to_string()\n- } else {\n- return None;\n- };\n-\n- Some(normalize_reddit_path(&path))\n- }\n-}\n-\n-fn split_query(s: &str) -> (&str, Option<&str>) {\n- if let Some((path, q)) = s.split_once('?') {\n- (path, Some(q))\n- } else {\n- (s, None)\n- }\n-}\n-\n-fn parse_url_host_path(url: &str) -> Option {\n- let rest = url\n- .strip_prefix(\"https://\")\n- .or_else(|| url.strip_prefix(\"http://\"))\n- .unwrap_or(url);\n- let (host, path) = rest.split_once('/').unwrap_or((rest, \"\"));\n- let host = normalize_host(host);\n- if path.is_empty() {\n- Some(host)\n- } else {\n- Some(format!(\"{host}/{path}\"))\n- }\n-}\n-\n-fn normalize_host(host: &str) -> String {\n- let h = host\n- .strip_prefix(\"www.\")\n- .unwrap_or(host)\n- .to_ascii_lowercase();\n- if h == \"old.reddit.com\" || h == \"new.reddit.com\" || h == \"reddit.com\" {\n- \"reddit.com\".to_string()\n- } else {\n- h\n- }\n }\n \n fn normalize_browse_tail(tail: &str) -> String {\n@@ -215,7 +164,6 @@ fn normalize_browse_tail(tail: &str) -> String {\n if t.is_empty() {\n return String::new();\n }\n- // Some HTTP stacks collapse `https://` → `https:/` inside a path segment.\n if t.starts_with(\"https:/\") && !t.starts_with(\"https://\") {\n return format!(\"https://{}\", &t[7..]);\n }\n@@ -225,33 +173,6 @@ fn normalize_browse_tail(tail: &str) -> String {\n t.to_string()\n }\n \n-fn normalize_reddit_host_path(s: &str) -> String {\n- let (host, path) = s.split_once('/').unwrap_or((s, \"\"));\n- let host = normalize_host(host);\n- if path.is_empty() {\n- host\n- } else {\n- format!(\"{host}/{path}\")\n- }\n-}\n-\n-/// Lowercase subreddit segment, drop listing suffixes, drop title slug after post id.\n-fn normalize_reddit_path(path: &str) -> String {\n- let mut parts: Vec = path.split('/').map(str::to_string).collect();\n- if parts.len() >= 3 && parts[1] == \"r\" {\n- parts[2] = parts[2].to_ascii_lowercase();\n- }\n- if let Some(i) = parts.iter().position(|p| p == \"comments\") {\n- if parts.len() > i + 2 {\n- parts.truncate(i + 2);\n- }\n- } else if parts.len() > 3 && parts.get(1).map(|s| s.as_str()) == Some(\"r\") {\n- // reddit.com/r/{sub}/hot → reddit.com/r/{sub}\n- parts.truncate(3);\n- }\n- parts.join(\"/\")\n-}\n-\n impl fmt::Display for ItemId {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n f.write_str(&self.0)\n@@ -268,43 +189,59 @@ mod tests {\n \"https://old.reddit.com/r/AmItheAsshole/comments/1trnvdl/aita_for_cancelling/\",\n )\n .unwrap();\n- assert_eq!(id.as_str(), \"reddit.com/r/amitheasshole/comments/1trnvdl\");\n+ assert_eq!(\n+ id.as_str(),\n+ \"https://reddit.com/r/amitheasshole/comments/1trnvdl\"\n+ );\n }\n \n #[test]\n fn from_url_strips_query() {\n let id = ItemId::from_url(\"https://www.reddit.com/r/rust/?sort=top\").unwrap();\n- assert_eq!(id.as_str(), \"reddit.com/r/rust\");\n+ assert_eq!(id.as_str(), \"https://reddit.com/r/rust\");\n }\n \n #[test]\n fn from_url_short_path() {\n assert_eq!(\n ItemId::from_url(\"r/rust\").unwrap().as_str(),\n- \"reddit.com/r/rust\"\n+ \"https://reddit.com/r/rust\"\n );\n }\n \n #[test]\n fn parent_of_post_is_subreddit() {\n- let id = ItemId::parse(\"reddit.com/r/aww/comments/1trnvdl\").unwrap();\n- assert_eq!(id.parent().unwrap().as_str(), \"reddit.com/r/aww\");\n+ let id = ItemId::from_url(\"https://reddit.com/r/aww/comments/1trnvdl\").unwrap();\n+ assert_eq!(id.parent().unwrap().as_str(), \"https://reddit.com/r/aww\");\n }\n \n #[test]\n fn parent_of_subreddit_is_r_segment() {\n- let id = ItemId::parse(\"reddit.com/r/movies\").unwrap();\n- assert_eq!(id.parent().unwrap().as_str(), \"reddit.com/r\");\n+ let id = ItemId::from_url(\"https://reddit.com/r/movies\").unwrap();\n+ assert_eq!(id.parent().unwrap().as_str(), \"https://reddit.com/r\");\n+ }\n+\n+ #[test]\n+ fn breadcrumb_paths_skip_phantom_comments() {\n+ let id = ItemId::from_url(\"https://reddit.com/r/aww/comments/1trnvdl\").unwrap();\n+ let crumbs = id.breadcrumb_paths();\n+ let paths: Vec<_> = crumbs.iter().map(|p| p.as_str()).collect();\n+ assert!(!paths.iter().any(|p| p.ends_with(\"/comments\")));\n+ assert!(paths.contains(&\"https://reddit.com/r/aww\"));\n }\n \n #[test]\n- fn breadcrumb_paths() {\n- let id = ItemId::parse(\"reddit.com/r/movies\").unwrap();\n+ fn breadcrumb_paths_subreddit() {\n+ let id = ItemId::from_url(\"https://reddit.com/r/movies\").unwrap();\n let crumbs = id.breadcrumb_paths();\n let paths: Vec<_> = crumbs.iter().map(|p| p.as_str()).collect();\n assert_eq!(\n paths,\n- vec![\"reddit.com\", \"reddit.com/r\", \"reddit.com/r/movies\"]\n+ vec![\n+ \"https://reddit.com\",\n+ \"https://reddit.com/r\",\n+ \"https://reddit.com/r/movies\"\n+ ]\n );\n }\n \n@@ -312,33 +249,33 @@ mod tests {\n fn legacy_scope_maps_to_reddit_sub() {\n assert_eq!(\n ItemId::from_legacy_scope(\"rust\").as_str(),\n- \"reddit.com/r/rust\"\n+ \"https://reddit.com/r/rust\"\n );\n assert!(ItemId::from_legacy_scope(\"\").is_root());\n }\n \n #[test]\n- fn browse_href_wraps_canonical_path() {\n- let id = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ fn browse_href_wraps_canonical_url() {\n+ let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n assert_eq!(id.browse_href(), \"/~/https://reddit.com/r/rust\");\n }\n \n #[test]\n fn from_browse_tail_parses_full_url() {\n let id = ItemId::from_browse_tail(\"https://reddit.com/r/AmITheAsshole\");\n- assert_eq!(id.as_str(), \"reddit.com/r/amitheasshole\");\n+ assert_eq!(id.as_str(), \"https://reddit.com/r/amitheasshole\");\n }\n \n #[test]\n fn from_storage_strips_post_title_slug() {\n let id =\n ItemId::from_storage(\"reddit.com/r/rust/comments/aaa/announcing_rust_199\").unwrap();\n- assert_eq!(id.as_str(), \"reddit.com/r/rust/comments/aaa\");\n+ assert_eq!(id.as_str(), \"https://reddit.com/r/rust/comments/aaa\");\n }\n \n #[test]\n fn from_browse_uri_strips_prefix() {\n let id = ItemId::from_browse_uri(\"/~/https://reddit.com/r/rust\").unwrap();\n- assert_eq!(id.as_str(), \"reddit.com/r/rust\");\n+ assert_eq!(id.as_str(), \"https://reddit.com/r/rust\");\n }\n }\ndiff --git a/server/src/projection_apply.rs b/server/src/projection_apply.rs\nindex ebe122e417bda1d9369a53443de93d28213c5a0d..5644557a41b3e9497c7421b444155ae629fa79f1 100644\n--- a/server/src/projection_apply.rs\n+++ b/server/src/projection_apply.rs\n@@ -19,13 +19,21 @@ use crate::{\n storage_schema::{ensure_path_writes, entity_view_writes, vote_writes},\n };\n \n-/// Legacy-compatible scope parsing for persisted vote events.\n+fn parse_event_id(id: &str) -> Result {\n+ ItemId::from_storage(id)\n+ .or_else(|| ItemId::parse(id))\n+ .ok_or_else(|| EventLogError::Apply(format!(\"invalid id: {id}\")))\n+}\n+\n+/// Scope key from a vote event (canonicalized at apply time).\n fn parent_from_event_scope(scope: &str) -> ItemId {\n- if scope.contains('/') {\n- ItemId::parse(scope).unwrap_or_else(|| ItemId::from_legacy_scope(scope))\n- } else {\n- ItemId::from_legacy_scope(scope)\n+ let s = scope.trim();\n+ if s.is_empty() {\n+ return ItemId::root();\n }\n+ ItemId::from_storage(s)\n+ .or_else(|| ItemId::parse(s))\n+ .unwrap_or_else(|| ItemId::from_legacy_scope(s))\n }\n \n pub fn apply_records(\n@@ -68,15 +76,11 @@ pub fn apply_records(\n vote_parents.insert(parent);\n }\n Event::NodeEnsured { id } => {\n- let parsed = ItemId::parse(id)\n- .or_else(|| ItemId::from_url(id))\n- .ok_or_else(|| EventLogError::Apply(format!(\"invalid node id: {id}\")))?;\n+ let parsed = parse_event_id(id)?;\n ensure_path_writes(&mut batch, &parsed);\n }\n Event::EntityImported { id, payload, .. } => {\n- let parsed = ItemId::parse(id)\n- .or_else(|| ItemId::from_url(id))\n- .ok_or_else(|| EventLogError::Apply(format!(\"invalid entity id: {id}\")))?;\n+ let parsed = parse_event_id(id)?;\n let view = entity_view_from_payload(&parsed, payload);\n entity_view_writes(&mut batch, &parsed, view.as_ref());\n entity_store\n@@ -92,7 +96,6 @@ pub fn apply_records(\n .commit_with(durable::Durability::DisableWal)\n .map_err(|e| EventLogError::Apply(e.to_string()))?;\n \n- // Cap recent-vote windows (idempotent, blind; not part of the cursor batch).\n for parent in vote_parents {\n projection_store\n .trim_recent_votes(&parent)\ndiff --git a/server/src/reddit.rs b/server/src/reddit.rs\nindex 72caf7c33b9dd44ea15b62b59e91227cf96a3431..20b7f9e3f8be39268a1767d09f5cf81eaa6ae0df 100644\n--- a/server/src/reddit.rs\n+++ b/server/src/reddit.rs\n@@ -183,7 +183,7 @@ pub fn entity_view_from_payload(\n id: &ItemId,\n payload: &Value,\n ) -> Option {\n- if id.as_str().starts_with(\"reddit.com\") {\n+ if id.as_str().contains(\"reddit.com\") {\n return parse_reddit_view(id, payload);\n }\n None\n@@ -495,41 +495,59 @@ fn rate_limit_reset_secs(resp: &reqwest::Response) -> u64 {\n .unwrap_or(5)\n }\n \n+fn reddit_path_segments(id: &ItemId) -> Option> {\n+ let s = id.as_str();\n+ let rest = s\n+ .strip_prefix(\"https://reddit.com/\")\n+ .or_else(|| s.strip_prefix(\"http://reddit.com/\"))\n+ .or_else(|| s.strip_prefix(\"reddit.com/\"))?;\n+ let segments: Vec = rest\n+ .split('/')\n+ .filter(|p| !p.is_empty())\n+ .map(str::to_string)\n+ .collect();\n+ Some(segments)\n+}\n+\n pub fn map_item_to_reddit_api(id: &ItemId, api_base: &str) -> String {\n- let path = id.as_str();\n- if !path.starts_with(\"reddit.com/\") && path != \"reddit.com\" {\n- return String::new();\n- }\n+ let segments = match reddit_path_segments(id) {\n+ Some(s) => s,\n+ None if matches!(\n+ id.as_str(),\n+ \"https://reddit.com\" | \"http://reddit.com\" | \"reddit.com\"\n+ ) =>\n+ {\n+ return String::new();\n+ }\n+ None => return String::new(),\n+ };\n \n let base = api_base.trim_end_matches('/');\n \n- let segments: Vec<&str> = path.split('/').collect();\n-\n- if let Some(i) = segments.iter().position(|&p| p == \"comments\") {\n+ if let Some(i) = segments.iter().position(|p| p == \"comments\") {\n if segments.len() > i + 1 {\n- let api_path = segments[1..=i + 1].join(\"/\");\n+ let api_path = segments[..=i + 1].join(\"/\");\n return format!(\"{base}/{api_path}.json?raw_json=1\");\n }\n }\n \n- if segments.len() == 3 && segments[1] == \"r\" {\n- return format!(\"{base}/r/{}/about.json?raw_json=1\", segments[2]);\n+ if segments.len() == 2 && segments[0] == \"r\" {\n+ return format!(\"{base}/r/{}/about.json?raw_json=1\", segments[1]);\n }\n \n String::new()\n }\n \n /// Listing URL for a node's children. Currently only subreddits\n-/// (`reddit.com/r/` → `/r/.json`) expose a child listing.\n+/// (`https://reddit.com/r/` → `/r/.json`) expose a child listing.\n pub fn map_children_url(id: &ItemId, api_base: &str) -> String {\n- let path = id.as_str();\n- if !path.starts_with(\"reddit.com/\") {\n- return String::new();\n- }\n+ let segments = match reddit_path_segments(id) {\n+ Some(s) => s,\n+ None => return String::new(),\n+ };\n let base = api_base.trim_end_matches('/');\n- let segments: Vec<&str> = path.split('/').collect();\n- if segments.len() == 3 && segments[1] == \"r\" {\n- return format!(\"{base}/r/{}.json?raw_json=1&limit=25\", segments[2]);\n+ if segments.len() == 2 && segments[0] == \"r\" {\n+ return format!(\"{base}/r/{}.json?raw_json=1&limit=25\", segments[1]);\n }\n String::new()\n }\n@@ -548,8 +566,8 @@ fn parse_children(_parent: &ItemId, payload: &Value) -> Vec<(ItemId, Value)> {\n Some(p) if !p.is_empty() => p,\n _ => continue,\n };\n- let path = format!(\"reddit.com{}\", permalink.trim_end_matches('/'));\n- if let Some(id) = ItemId::from_storage(&path) {\n+ let raw = format!(\"https://reddit.com{}\", permalink.trim_end_matches('/'));\n+ if let Some(id) = ItemId::from_url(&raw) {\n out.push((id, child.clone()));\n }\n }\n@@ -683,7 +701,7 @@ mod tests {\n \n #[test]\n fn map_subreddit_about_url() {\n- let id = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n assert_eq!(\n map_item_to_reddit_api(&id, \"https://www.reddit.com\"),\n \"https://www.reddit.com/r/rust/about.json?raw_json=1\"\n@@ -699,7 +717,8 @@ mod tests {\n let json = include_str!(\"../../test/fixtures/reddit/r_rust_about.json\");\n let v: Value = serde_json::from_str(json).unwrap();\n let entity =\n- entity_view_from_payload(&ItemId::parse(\"reddit.com/r/rust\").unwrap(), &v).unwrap();\n+ entity_view_from_payload(&ItemId::from_url(\"https://reddit.com/r/rust\").unwrap(), &v)\n+ .unwrap();\n assert_eq!(entity.title, \"The Rust Programming Language\");\n }\n \n@@ -707,7 +726,8 @@ mod tests {\n fn parse_post_listing_extracts_thumb_and_full_preview() {\n let json = include_str!(\"../../test/fixtures/reddit/post_preview.json\");\n let v: Value = serde_json::from_str(json).unwrap();\n- let id = ItemId::parse(\"reddit.com/r/nsfw/comments/1tpy6a1/angel_eyes\").unwrap();\n+ let id =\n+ ItemId::from_url(\"https://reddit.com/r/nsfw/comments/1tpy6a1/angel_eyes\").unwrap();\n let entity = entity_view_from_payload(&id, &v).unwrap();\n assert_eq!(entity.title, \"Angel Eyes\");\n assert!(entity.thumb_url.as_ref().unwrap().contains(\"width=140\"));\ndiff --git a/server/src/reducer.rs b/server/src/reducer.rs\nindex 6578f64a41726845517cdbf59a359c69e0aa56db..5179ddeca7a7cb0fb92dfc4aa9d5a80bd9125611 100644\n--- a/server/src/reducer.rs\n+++ b/server/src/reducer.rs\n@@ -248,16 +248,18 @@ mod from_recorded_tests {\n #[test]\n fn ensure_path_wires_children() {\n let mut tree = GlobalTree::new();\n- let id = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n tree.ensure_path(&id);\n let root = tree.get(&ItemId::root()).unwrap();\n assert!(root\n .children\n- .contains(&ItemId::parse(\"reddit.com\").unwrap()));\n- let reddit = tree.get(&ItemId::parse(\"reddit.com\").unwrap()).unwrap();\n+ .contains(&ItemId::from_url(\"https://reddit.com\").unwrap()));\n+ let reddit = tree\n+ .get(&ItemId::from_url(\"https://reddit.com\").unwrap())\n+ .unwrap();\n assert!(reddit\n .children\n- .contains(&ItemId::parse(\"reddit.com/r\").unwrap()));\n+ .contains(&ItemId::from_url(\"https://reddit.com/r\").unwrap()));\n let sub = tree.get(&id).unwrap();\n assert_eq!(sub.id, id);\n }\ndiff --git a/server/src/render/reddit.rs b/server/src/render/reddit.rs\nindex 7f840aa33b734a31d8cf3341a0581c8bcb9bbcf3..595e202436040b0bfc419e68f083f94757ba5d0c 100644\n--- a/server/src/render/reddit.rs\n+++ b/server/src/render/reddit.rs\n@@ -9,7 +9,7 @@ use crate::{\n };\n \n pub fn is_reddit_post(id: &ItemId) -> bool {\n- id.as_str().starts_with(\"reddit.com/\") && id.as_str().contains(\"/comments/\")\n+ id.as_str().contains(\"reddit.com/\") && id.as_str().contains(\"/comments/\")\n }\n \n /// Post detail card (inside [`crate::fetch::html::entity_panel`]).\ndiff --git a/server/src/state.rs b/server/src/state.rs\nindex 78126f08d90f8069a586279d79258c27a9f9f7a4..513b329ef45fc332e63b3f8ed8498a1f59feb07c 100644\n--- a/server/src/state.rs\n+++ b/server/src/state.rs\n@@ -217,15 +217,21 @@ impl AppState {\n ratio_right: i32,\n ) -> Result<(), String> {\n let ts = crate::html::now_ms();\n- let vote = VoteData::from_recorded(ts, a, b, ratio_left, ratio_right)\n- .ok_or_else(|| \"invalid vote: need two distinct non-empty items\".to_string())?;\n+ let a_raw = a.trim();\n+ let b_raw = b.trim();\n+ if a_raw.is_empty() || b_raw.is_empty() || a_raw == b_raw {\n+ return Err(\"invalid vote: need two distinct non-empty items\".to_string());\n+ }\n+ // Validate items canonicalize (or are opaque keys) before append.\n+ let _ = VoteData::from_recorded(ts, a_raw, b_raw, ratio_left, ratio_right)\n+ .ok_or_else(|| \"invalid vote: need two distinct parseable items\".to_string())?;\n \n let event = Event::VoteRecorded {\n ts,\n- a: vote.a.as_str().to_string(),\n- b: vote.b.as_str().to_string(),\n- ratio_left: vote.ratio_left,\n- ratio_right: vote.ratio_right,\n+ a: a_raw.to_string(),\n+ b: b_raw.to_string(),\n+ ratio_left,\n+ ratio_right,\n scope: parent.as_str().to_string(),\n };\n \n@@ -253,7 +259,7 @@ mod tests {\n let log = EventLog::new(log_path.to_string_lossy().into_owned());\n let payload = json!({\"kind\":\"t5\",\"data\":{\"title\":\"Rust\",\"display_name\":\"rust\"}});\n let event = Event::EntityImported {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n ts: 1,\n payload: payload.clone(),\n };\n@@ -266,14 +272,14 @@ mod tests {\n .await\n .unwrap();\n let tree = projection_store\n- .scope_tree(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .scope_tree(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .unwrap();\n let node = tree\n- .get(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .unwrap();\n assert_eq!(node.data.as_ref().unwrap().title, \"Rust\");\n let stored = entity_store\n- .get(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .unwrap()\n .unwrap();\n assert_eq!(stored[\"data\"][\"display_name\"], \"rust\");\n@@ -289,13 +295,13 @@ mod tests {\n event_record(\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n ),\n event_record(\n 2,\n Event::EntityImported {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n ts: 2,\n payload: payload.clone(),\n },\n@@ -325,7 +331,7 @@ mod tests {\n &[event_record(\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/stale\".into(),\n+ id: \"https://reddit.com/r/stale\".into(),\n },\n )],\n )\n@@ -352,11 +358,11 @@ mod tests {\n let root = tree.get(&ItemId::root()).unwrap();\n assert!(root.children.contains(&ItemId::parse(\"alpha\").unwrap()));\n assert!(projection_store\n- .load_node(&ItemId::parse(\"reddit.com/r/stale\").unwrap())\n+ .load_node(&ItemId::parse(\"https://reddit.com/r/stale\").unwrap())\n .unwrap()\n .is_none());\n let stored = entity_store\n- .get(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .unwrap()\n .unwrap();\n assert_eq!(stored[\"data\"][\"display_name\"], \"rust\");\n@@ -370,7 +376,7 @@ mod tests {\n log.append(&event_record(\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n ))\n .await\n@@ -387,7 +393,7 @@ mod tests {\n &[event_record(\n 2,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n )],\n )\n@@ -454,7 +460,7 @@ mod tests {\n port: 0,\n })\n .await;\n- let id = ItemId::parse(\"reddit.com/r/rust\").unwrap();\n+ let id = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n \n state.ensure_node(&id).await.unwrap();\n \n@@ -465,11 +471,11 @@ mod tests {\n let projected = state.projection_store.load_tree().unwrap();\n assert!(projected.get(&id).is_some());\n let reddit = projected\n- .get(&ItemId::parse(\"reddit.com\").unwrap())\n+ .get(&ItemId::from_url(\"https://reddit.com\").unwrap())\n .unwrap();\n assert!(reddit\n .children\n- .contains(&ItemId::parse(\"reddit.com/r\").unwrap()));\n+ .contains(&ItemId::from_url(\"https://reddit.com/r\").unwrap()));\n }\n \n #[tokio::test]\n@@ -510,7 +516,7 @@ mod tests {\n log.append(&event_record(\n 1,\n Event::NodeEnsured {\n- id: \"reddit.com/r/rust\".into(),\n+ id: \"https://reddit.com/r/rust\".into(),\n },\n ))\n .await\n@@ -518,7 +524,7 @@ mod tests {\n log.append(&event_record(\n 2,\n Event::NodeEnsured {\n- id: \"reddit.com/r/python\".into(),\n+ id: \"https://reddit.com/r/python\".into(),\n },\n ))\n .await\n@@ -544,13 +550,13 @@ mod tests {\n 2\n );\n let tree = second\n- .scope_tree(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .scope_tree(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .unwrap();\n assert!(tree\n- .get(&ItemId::parse(\"reddit.com/r/rust\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n .is_some());\n assert!(tree\n- .get(&ItemId::parse(\"reddit.com/r/python\").unwrap())\n+ .get(&ItemId::parse(\"https://reddit.com/r/python\").unwrap())\n .is_none());\n }\n \n@@ -611,7 +617,7 @@ mod tests {\n #[test]\n fn parse_item_param_from_url() {\n let id = parse_item_param(\"https://reddit.com/r/rust\");\n- assert_eq!(id.as_str(), \"reddit.com/r/rust\");\n+ assert_eq!(id.as_str(), \"https://reddit.com/r/rust\");\n }\n \n #[test]\ndiff --git a/server/src/url_rules/engine.rs b/server/src/url_rules/engine.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..e29b6b48c08deb7bffe031b1e542b1e25a7bef15\n--- /dev/null\n+++ b/server/src/url_rules/engine.rs\n@@ -0,0 +1,187 @@\n+//! Composable URL normalization primitives.\n+\n+use std::collections::HashMap;\n+\n+use url::Url;\n+\n+/// Mutable URL view used by rule combinators before serializing to a canonical string.\n+#[derive(Debug, Clone)]\n+pub struct ParsedUrl {\n+ pub scheme: String,\n+ pub host: String,\n+ pub path_segments: Vec,\n+ pub query: HashMap,\n+ pub fragment: Option,\n+}\n+\n+impl ParsedUrl {\n+ pub fn parse(raw: &str) -> Option {\n+ let trimmed = raw.trim();\n+ if trimmed.is_empty() {\n+ return None;\n+ }\n+\n+ let with_scheme = if trimmed.contains(\"://\") {\n+ trimmed.to_string()\n+ } else if trimmed.starts_with(\"r/\") || trimmed.starts_with(\"/r/\") {\n+ let rest = trimmed.trim_start_matches('/').trim_start_matches(\"r/\");\n+ format!(\"https://reddit.com/r/{rest}\")\n+ } else if trimmed.contains('.') && !trimmed.starts_with('/') {\n+ format!(\"https://{trimmed}\")\n+ } else {\n+ trimmed.to_string()\n+ };\n+\n+ let url = Url::parse(&with_scheme).ok()?;\n+ let host = url.host_str()?.to_string();\n+ let path_segments: Vec = url\n+ .path_segments()\n+ .map(|segs| segs.filter(|s| !s.is_empty()).map(str::to_string).collect())\n+ .unwrap_or_default();\n+\n+ let mut query = HashMap::new();\n+ for (k, v) in url.query_pairs() {\n+ query.insert(k.into_owned(), v.into_owned());\n+ }\n+\n+ Some(Self {\n+ scheme: url.scheme().to_string(),\n+ path_segments,\n+ query,\n+ fragment: url.fragment().map(str::to_string),\n+ host,\n+ })\n+ }\n+\n+ pub fn with_path_segments(&self, segments: &[String]) -> Self {\n+ let mut u = self.clone();\n+ u.path_segments = segments.to_vec();\n+ u\n+ }\n+\n+ pub fn to_url(&self) -> Option {\n+ let mut url = if self.path_segments.is_empty() {\n+ Url::parse(&format!(\"{}://{}\", self.scheme, self.host)).ok()?\n+ } else {\n+ let path = format!(\"/{}\", self.path_segments.join(\"/\"));\n+ Url::parse(&format!(\"{}://{}{}\", self.scheme, self.host, path)).ok()?\n+ };\n+ if !self.query.is_empty() {\n+ let mut pairs: Vec<_> = self.query.iter().collect();\n+ pairs.sort_by(|a, b| a.0.cmp(b.0));\n+ url.query_pairs_mut().clear();\n+ for (k, v) in pairs {\n+ url.query_pairs_mut().append_pair(k, v);\n+ }\n+ }\n+ if let Some(ref frag) = self.fragment {\n+ url.set_fragment(Some(frag));\n+ }\n+ Some(url)\n+ }\n+\n+ pub fn canonical_string(&self) -> Option {\n+ let url = self.to_url()?;\n+ let mut s = url.to_string();\n+ if self.path_segments.is_empty() {\n+ s = s.trim_end_matches('/').to_string();\n+ }\n+ Some(s)\n+ }\n+}\n+\n+pub fn force_https(u: &mut ParsedUrl) {\n+ if u.scheme == \"http\" {\n+ u.scheme = \"https\".to_string();\n+ }\n+}\n+\n+pub fn drop_fragment(u: &mut ParsedUrl) {\n+ u.fragment = None;\n+}\n+\n+pub fn strip_www(u: &mut ParsedUrl) {\n+ if u.host.starts_with(\"www.\") {\n+ u.host = u.host[4..].to_string();\n+ }\n+}\n+\n+pub fn lowercase_host(u: &mut ParsedUrl) {\n+ u.host = u.host.to_ascii_lowercase();\n+}\n+\n+pub fn lowercase_path(u: &mut ParsedUrl) {\n+ for seg in &mut u.path_segments {\n+ *seg = seg.to_ascii_lowercase();\n+ }\n+}\n+\n+pub fn clear_query(u: &mut ParsedUrl) {\n+ u.query.clear();\n+}\n+\n+pub fn keep_only_query(u: &mut ParsedUrl, keys: &[&str]) {\n+ u.query\n+ .retain(|k, _| keys.iter().any(|want| want == &k.as_str()));\n+}\n+\n+pub fn strip_tracking_params(u: &mut ParsedUrl) {\n+ u.query.retain(|k, _| {\n+ let lower = k.to_ascii_lowercase();\n+ !(lower.starts_with(\"utm_\")\n+ || matches!(\n+ lower.as_str(),\n+ \"fbclid\" | \"gclid\" | \"ref\" | \"ref_src\" | \"ref_source\" | \"mc_cid\" | \"mc_eid\"\n+ ))\n+ });\n+}\n+\n+pub fn truncate_after_segment(u: &mut ParsedUrl, name: &str, keep: usize) {\n+ if let Some(i) = u.path_segments.iter().position(|s| s == name) {\n+ let end = (i + 1 + keep).min(u.path_segments.len());\n+ u.path_segments.truncate(end);\n+ }\n+}\n+\n+pub fn drop_listing_suffix(u: &mut ParsedUrl, suffixes: &[&str]) {\n+ if u.path_segments.len() >= 3 && u.path_segments.first().map(String::as_str) == Some(\"r\") {\n+ if let Some(last) = u.path_segments.last() {\n+ if suffixes.iter().any(|s| *s == last.as_str()) {\n+ u.path_segments.pop();\n+ }\n+ }\n+ }\n+}\n+\n+pub fn normalize_reddit_host(u: &mut ParsedUrl) {\n+ if matches!(\n+ u.host.as_str(),\n+ \"old.reddit.com\" | \"new.reddit.com\" | \"www.reddit.com\"\n+ ) {\n+ u.host = \"reddit.com\".to_string();\n+ }\n+}\n+\n+pub fn rewrite_youtu_be(u: &mut ParsedUrl) {\n+ if u.host == \"youtu.be\" && u.path_segments.len() == 1 {\n+ let id = u.path_segments[0].clone();\n+ u.host = \"youtube.com\".to_string();\n+ u.path_segments = vec![\"watch\".to_string()];\n+ u.query.insert(\"v\".to_string(), id);\n+ }\n+}\n+\n+pub fn rewrite_youtube_shorts(u: &mut ParsedUrl) {\n+ if u.host == \"youtube.com\" && u.path_segments.first().map(String::as_str) == Some(\"shorts\") {\n+ if let Some(id) = u.path_segments.get(1).cloned() {\n+ u.path_segments = vec![\"watch\".to_string()];\n+ u.query.insert(\"v\".to_string(), id);\n+ }\n+ }\n+}\n+\n+pub fn normalize_youtube_host(u: &mut ParsedUrl) {\n+ if matches!(u.host.as_str(), \"m.youtube.com\" | \"www.youtube.com\") {\n+ u.host = \"youtube.com\".to_string();\n+ }\n+}\ndiff --git a/server/src/url_rules/mod.rs b/server/src/url_rules/mod.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..03d53bd3e82d704a01ba3fd8dd02b7d31422c0de\n--- /dev/null\n+++ b/server/src/url_rules/mod.rs\n@@ -0,0 +1,13 @@\n+//! URL canonicalization and hierarchy rules for [`crate::path_types::ItemId`].\n+\n+mod engine;\n+mod registry;\n+\n+pub use registry::{\n+ canonicalize_raw, looks_like_url, navigable_breadcrumbs, parent_url, resolve_id, CanonicalResult,\n+};\n+\n+/// Resolve raw input to canonical URL.\n+pub fn resolve_canonical(raw: &str) -> Option {\n+ canonicalize_raw(raw.trim()).map(|r| r.canonical)\n+}\ndiff --git a/server/src/url_rules/registry.rs b/server/src/url_rules/registry.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..14514e9af8385fb2b9b2f35eb9ee14d453d4b97c\n--- /dev/null\n+++ b/server/src/url_rules/registry.rs\n@@ -0,0 +1,235 @@\n+//! Per-domain canonicalization and hierarchy rules.\n+\n+use std::collections::HashSet;\n+\n+use super::engine::{\n+ clear_query, drop_fragment, drop_listing_suffix, force_https, keep_only_query, lowercase_host,\n+ lowercase_path, normalize_reddit_host, normalize_youtube_host, rewrite_youtu_be,\n+ rewrite_youtube_shorts, strip_tracking_params, strip_www, truncate_after_segment, ParsedUrl,\n+};\n+\n+/// Result of canonicalizing a raw URL string.\n+#[derive(Debug, Clone, PartialEq, Eq)]\n+pub struct CanonicalResult {\n+ pub canonical: String,\n+ /// When the input normalizes to a different string, the original is an alias.\n+ pub alias_of: Option,\n+}\n+\n+fn apply_global(u: &mut ParsedUrl) {\n+ force_https(u);\n+ drop_fragment(u);\n+ strip_www(u);\n+ lowercase_host(u);\n+ strip_tracking_params(u);\n+}\n+\n+fn normalize_reddit(u: &mut ParsedUrl) {\n+ normalize_reddit_host(u);\n+ lowercase_path(u);\n+ truncate_after_segment(u, \"comments\", 1);\n+ drop_listing_suffix(u, &[\"hot\", \"top\", \"new\", \"rising\", \"controversial\"]);\n+ clear_query(u);\n+}\n+\n+fn normalize_youtube(u: &mut ParsedUrl) {\n+ rewrite_youtu_be(u);\n+ normalize_youtube_host(u);\n+ rewrite_youtube_shorts(u);\n+ keep_only_query(u, &[\"v\", \"list\"]);\n+}\n+\n+fn normalize_default(_u: &mut ParsedUrl) {\n+ // Global rules only.\n+}\n+\n+fn domain_key(host: &str) -> &'static str {\n+ if host == \"reddit.com\" || host.ends_with(\".reddit.com\") {\n+ \"reddit.com\"\n+ } else if host == \"youtube.com\" || host == \"youtu.be\" {\n+ \"youtube.com\"\n+ } else {\n+ \"default\"\n+ }\n+}\n+\n+fn normalize_for_host(u: &mut ParsedUrl) {\n+ apply_global(u);\n+ match domain_key(&u.host) {\n+ \"reddit.com\" => normalize_reddit(u),\n+ \"youtube.com\" => normalize_youtube(u),\n+ _ => normalize_default(u),\n+ }\n+}\n+\n+/// Structural path segments that must not become standalone tree nodes when more path follows.\n+fn structural_trailing(host: &str) -> &'static [&'static str] {\n+ match domain_key(host) {\n+ \"reddit.com\" => &[\"comments\"],\n+ _ => &[],\n+ }\n+}\n+\n+/// Canonicalize a raw URL. Returns `None` if the input is not URL-like.\n+pub fn canonicalize_raw(raw: &str) -> Option {\n+ let trimmed = raw.trim();\n+ if trimmed.is_empty() {\n+ return None;\n+ }\n+ let mut u = ParsedUrl::parse(trimmed)?;\n+ let input_snapshot = u.canonical_string()?;\n+ normalize_for_host(&mut u);\n+ let canonical = u.canonical_string()?;\n+ let alias_of = if input_snapshot != canonical {\n+ Some(trimmed.to_string())\n+ } else {\n+ None\n+ };\n+ Some(CanonicalResult {\n+ canonical,\n+ alias_of,\n+ })\n+}\n+\n+/// Resolve a stored or event id string to its canonical URL identity.\n+pub fn resolve_id(raw: &str) -> Option {\n+ canonicalize_raw(raw).map(|r| r.canonical)\n+}\n+\n+/// Navigable ancestor URLs from domain root up to and including `canonical` (full URLs).\n+pub fn navigable_breadcrumbs(canonical: &str) -> Vec {\n+ let Some(u) = ParsedUrl::parse(canonical) else {\n+ return vec![canonical.to_string()];\n+ };\n+ let structural: HashSet<&str> = structural_trailing(&u.host).iter().copied().collect();\n+ let n = u.path_segments.len();\n+ let mut out = Vec::new();\n+\n+ // Domain root (no path segments).\n+ if let Some(base) = u.with_path_segments(&[]).canonical_string() {\n+ out.push(base);\n+ }\n+\n+ for i in 0..n {\n+ let segs: Vec = u.path_segments[..=i].to_vec();\n+ let is_last = i == n - 1;\n+ let seg = u.path_segments[i].as_str();\n+ if structural.contains(seg) && !is_last {\n+ continue;\n+ }\n+ if let Some(url) = u.with_path_segments(&segs).canonical_string() {\n+ if out.last() != Some(&url) {\n+ out.push(url);\n+ }\n+ }\n+ }\n+ out\n+}\n+\n+/// Immediate parent scope URL, or `None` for tree root / opaque single-segment ids.\n+pub fn parent_url(canonical: &str) -> Option {\n+ let crumbs = navigable_breadcrumbs(canonical);\n+ if crumbs.len() <= 1 {\n+ None\n+ } else {\n+ crumbs.get(crumbs.len() - 2).cloned()\n+ }\n+}\n+\n+/// True when `raw` looks like a URL (has scheme or host-like shape).\n+pub fn looks_like_url(raw: &str) -> bool {\n+ let t = raw.trim();\n+ t.contains(\"://\")\n+ || t.starts_with(\"r/\")\n+ || t.starts_with(\"/r/\")\n+ || (t.contains('.') && t.contains('/'))\n+ || t.starts_with(\"reddit.com\")\n+ || t.starts_with(\"www.\")\n+ || t.starts_with(\"youtu.be/\")\n+}\n+\n+#[cfg(test)]\n+mod tests {\n+ use super::*;\n+\n+ #[test]\n+ fn reddit_post_drops_slug_and_normalizes_host() {\n+ let r = canonicalize_raw(\n+ \"https://old.reddit.com/r/AmItheAsshole/comments/1trnvdl/aita_for_cancelling/\",\n+ )\n+ .unwrap();\n+ assert_eq!(\n+ r.canonical,\n+ \"https://reddit.com/r/amitheasshole/comments/1trnvdl\"\n+ );\n+ }\n+\n+ #[test]\n+ fn reddit_strips_query_and_listing() {\n+ assert_eq!(\n+ canonicalize_raw(\"https://www.reddit.com/r/rust/?sort=top\")\n+ .unwrap()\n+ .canonical,\n+ \"https://reddit.com/r/rust\"\n+ );\n+ assert_eq!(\n+ canonicalize_raw(\"https://www.reddit.com/r/programming/hot\")\n+ .unwrap()\n+ .canonical,\n+ \"https://reddit.com/r/programming\"\n+ );\n+ }\n+\n+ #[test]\n+ fn reddit_short_path() {\n+ assert_eq!(\n+ canonicalize_raw(\"r/rust\").unwrap().canonical,\n+ \"https://reddit.com/r/rust\"\n+ );\n+ }\n+\n+ #[test]\n+ fn reddit_breadcrumbs_skip_phantom_comments() {\n+ let post = \"https://reddit.com/r/aww/comments/1trnvdl\";\n+ let crumbs = navigable_breadcrumbs(post);\n+ assert!(!crumbs.iter().any(|c| c.ends_with(\"/comments\")));\n+ assert_eq!(\n+ crumbs.last().map(String::as_str),\n+ Some(post)\n+ );\n+ assert!(crumbs.contains(&\"https://reddit.com/r/aww\".to_string()));\n+ }\n+\n+ #[test]\n+ fn reddit_parent_of_post_is_subreddit() {\n+ assert_eq!(\n+ parent_url(\"https://reddit.com/r/aww/comments/1trnvdl\").as_deref(),\n+ Some(\"https://reddit.com/r/aww\")\n+ );\n+ }\n+\n+ #[test]\n+ fn youtube_youtu_be_and_watch_same_canonical() {\n+ let a = canonicalize_raw(\"https://youtu.be/dQw4w9WgXcQ\").unwrap().canonical;\n+ let b = canonicalize_raw(\"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=10\").unwrap();\n+ assert_eq!(a, b.canonical);\n+ assert_eq!(a, \"https://youtube.com/watch?v=dQw4w9WgXcQ\");\n+ }\n+\n+ #[test]\n+ fn legacy_schemeless_upgrades() {\n+ assert_eq!(\n+ canonicalize_raw(\"reddit.com/r/rust/comments/aaa/announcing_rust_199\")\n+ .unwrap()\n+ .canonical,\n+ \"https://reddit.com/r/rust/comments/aaa\"\n+ );\n+ }\n+\n+ #[test]\n+ fn alias_recorded_when_input_differs() {\n+ let r = canonicalize_raw(\"https://youtu.be/abc123\").unwrap();\n+ assert_eq!(r.canonical, \"https://youtube.com/watch?v=abc123\");\n+ assert!(r.alias_of.is_some());\n+ }\n+}\n\n\nSide B — contributor: tommy-mor\nSide B — commit message:\n[23c8134e] Fix /-/ external garden index; resolvers/ + GitHub import cards (#150)\n\n* Fix external garden root listing; add resolvers/ with GitHub cards\n\nThe public and room external index pages queried children of a bogus\nhttps://./ parent, so /-/ always looked empty. Collect host-only https\nroots from all Web items and item_children edges so ghost parents from\nadd_child_edge appear.\n\nMove GitHub resolver into server/src/resolvers/ with default_external.rs\nand a try_render_resolver_item_body hook. Resolver ingests now store\nslug-github-card fenced JSON; render_item_body_in_scope shows a small\nGitHub article card (with legacy support for schema-less json fences on\ngithub.com URLs). Styling in theme_default.css; agents.md updated.\n\nCo-authored-by: tommy \n\n* Vote compare: GitHub cards in columns, layout CSS, tests\n\nPass item_bodies into vote_compare_item_card for linkified tooltips on\nnon-card bodies; clone item_bodies before dropping reducer read guard.\n\nAdd layout rules so rich cards sit in the grid corners (default + retro).\n\nUnit test on vote_compare_item_card; integration GET /vote/compare with\ningested slug-github-card bodies. agents.md clarifies compare columns.\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 7508234d9b04223d0e64cfe69fedbebd06a256b5..d8b801e454fdf37e7ac6038b91a69f83b0746d59 100644\n--- a/agents.md\n+++ b/agents.md\n@@ -42,7 +42,7 @@ Strict **CSP** that blocks `eval` would break the current app. Other projects ma\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.\n \n-- **`ResolveExternal`:** GitHub resolver buttons are browser actions through **`POST /ui`**. Success responses morph **`#external-resolver-status`** then redirect to the sanitized shareable **`GET`** page so imported children render through the normal page path; errors morph the same status region. Resolver results are durable system ingests, while cooldown state is RAM-only.\n+- **`ResolveExternal`:** GitHub resolver buttons are browser actions through **`POST /ui`**. Success responses morph **`#external-resolver-status`** then redirect to the sanitized shareable **`GET`** page so imported children render through the normal page path; errors morph the same status region. Resolver results are durable system ingests, while cooldown state is RAM-only. Implementation lives under **`server/src/resolvers/`** (GitHub resolver + import card JSON); ontology item pages and the **`GET /vote/compare`** left/right columns use **`render_item_body_in_scope`** in **`server/src/html/mod.rs`**, which calls **`server/src/resolvers/mod.rs::try_render_resolver_item_body`** before falling back to the usual **`
    `** linkified view.\n \n - **Garden pin / compare voting:** Cookie **`slug_garden_pin`** via **`set_garden_pin`**. Pairwise UI: **`GET /vote/compare?…`** / **`GET /r/:room_key/vote/compare?…`** (fullscreen **`GET`** page: no HUD; other garden pages). HUD (**`#slug-pin-hud`**): only when **`layout`** passes garden metadata on **`body`**; the label is **`POST /ui`** **`set_garden_pin`** **`clear:true`** (**`slug_ui.js`**), not a permalink to the item.\n \ndiff --git a/server/src/api/ui_html.rs b/server/src/api/ui_html.rs\nindex 4b0214d18b173cd506d09176104f461dc4c4f208..c9eb8e242072e41fcf70da838bdf02dd4c838db8 100644\n--- a/server/src/api/ui_html.rs\n+++ b/server/src/api/ui_html.rs\n@@ -18,7 +18,7 @@ use crate::{\n         rpc::{rpc_post_redact, rpc_post_with_bearer, rpc_room_delete},\n     },\n     canonical_path::canonicalize_tag,\n-    external_resolver::resolve_github_children,\n+    resolvers::resolve_github_children,\n     html::vote_compare_post_success_js,\n     html::{\n         external_resolver_status_markup, fragment_new_thread_slot, login_to_post_hint_markup,\ndiff --git a/server/src/external_resolver.rs b/server/src/external_resolver.rs\ndeleted file mode 100644\nindex a5812250fed7613950b5417f396f886a55fafccf..0000000000000000000000000000000000000000\n--- a/server/src/external_resolver.rs\n+++ /dev/null\n@@ -1,630 +0,0 @@\n-use async_trait::async_trait;\n-use serde_json::Value;\n-use tokio::sync::oneshot;\n-\n-use crate::{path_types::ItemId, state::AppState, write_cmd::WriteCmd};\n-\n-const GITHUB_SYSTEM_PRINCIPAL: &str = \"system:github-resolver\";\n-const GITHUB_RESOLVER_COOLDOWN_MS: i64 = 15_000;\n-const GITHUB_MAX_PAGES: usize = 3;\n-\n-fn now_ms() -> i64 {\n-    use std::time::{SystemTime, UNIX_EPOCH};\n-    SystemTime::now()\n-        .duration_since(UNIX_EPOCH)\n-        .unwrap_or_default()\n-        .as_millis() as i64\n-}\n-\n-#[derive(Debug, Clone, PartialEq, Eq)]\n-pub struct ResolvedChild {\n-    pub url: String,\n-    pub title: String,\n-    pub body: Option,\n-}\n-\n-#[async_trait]\n-pub trait ExternalResolver: Send + Sync {\n-    /// e.g. `\"github.com\"`\n-    fn domain_match(&self) -> &'static str;\n-\n-    /// Normalizes URLs (e.g. stripping fragments); extend per-domain later.\n-    fn normalize(&self, path: &str) -> String;\n-\n-    /// Fetches body when missing; GitHub hook lands here in a follow-up.\n-    async fn fetch_body(&self, item: &ItemId) -> Result;\n-}\n-\n-#[derive(Clone)]\n-pub struct GitHubResolver {\n-    client: reqwest::Client,\n-    api_base_url: String,\n-    token: Option,\n-}\n-\n-impl GitHubResolver {\n-    pub fn from_env() -> Self {\n-        let api_base_url = std::env::var(\"SLUG_GITHUB_API_BASE_URL\")\n-            .ok()\n-            .filter(|s| !s.trim().is_empty())\n-            .unwrap_or_else(|| \"https://api.github.com\".to_string());\n-        let token = std::env::var(\"SLUG_GITHUB_TOKEN\")\n-            .ok()\n-            .filter(|s| !s.trim().is_empty());\n-        Self {\n-            client: reqwest::Client::new(),\n-            api_base_url: api_base_url.trim_end_matches('/').to_string(),\n-            token,\n-        }\n-    }\n-\n-    pub fn can_resolve_children(&self, item: &ItemId) -> bool {\n-        github_segments(item).is_some()\n-    }\n-\n-    pub async fn list_children(&self, item: &ItemId) -> Result, String> {\n-        let segments = github_segments(item).ok_or_else(|| \"not a GitHub URL\".to_string())?;\n-        match segments.as_slice() {\n-            [] => Ok(vec![]),\n-            [owner] => self.list_repos(owner).await,\n-            [owner, repo] => Ok(github_repo_sections(owner, repo)),\n-            [owner, repo, section] if section == \"issues\" => self.list_issues(owner, repo).await,\n-            [owner, repo, section] if section == \"pulls\" => self.list_pulls(owner, repo).await,\n-            [owner, repo, section] if section == \"commits\" => self.list_commits(owner, repo).await,\n-            [owner, repo, section] if section == \"releases\" => {\n-                self.list_releases(owner, repo).await\n-            }\n-            _ => Ok(vec![]),\n-        }\n-    }\n-\n-    async fn get_json(&self, path: &str) -> Result {\n-        let url = format!(\"{}/{}\", self.api_base_url, path.trim_start_matches('/'));\n-        let mut req = self\n-            .client\n-            .get(url)\n-            .header(reqwest::header::USER_AGENT, \"slugsocial-github-resolver\");\n-        if let Some(token) = &self.token {\n-            req = req.bearer_auth(token);\n-        }\n-        let resp = req\n-            .send()\n-            .await\n-            .map_err(|e| format!(\"GitHub request failed: {e}\"))?;\n-        let status = resp.status();\n-        if !status.is_success() {\n-            return Err(format!(\"GitHub request returned {status}\"));\n-        }\n-        resp.json::()\n-            .await\n-            .map_err(|e| format!(\"GitHub response JSON failed: {e}\"))\n-    }\n-\n-    async fn get_json_array_pages(&self, path: &str) -> Result, String> {\n-        let sep = if path.contains('?') { '&' } else { '?' };\n-        let mut out = Vec::new();\n-        for page in 1..=GITHUB_MAX_PAGES {\n-            let value = self.get_json(&format!(\"{path}{sep}page={page}\")).await?;\n-            let arr = value\n-                .as_array()\n-                .ok_or_else(|| \"GitHub paged response was not an array\".to_string())?;\n-            let n = arr.len();\n-            out.extend(arr.iter().cloned());\n-            if n < 100 {\n-                break;\n-            }\n-        }\n-        Ok(out)\n-    }\n-\n-    async fn list_repos(&self, owner: &str) -> Result, String> {\n-        let arr = self\n-            .get_json_array_pages(&format!(\n-                \"/users/{owner}/repos?per_page=100&sort=updated&type=owner\"\n-            ))\n-            .await?;\n-        let mut out = Vec::new();\n-        for repo in &arr {\n-            let name = repo\n-                .get(\"name\")\n-                .and_then(|v| v.as_str())\n-                .unwrap_or_default();\n-            if name.is_empty() {\n-                continue;\n-            }\n-            let full_name = repo\n-                .get(\"full_name\")\n-                .and_then(|v| v.as_str())\n-                .map(|s| s.to_ascii_lowercase())\n-                .unwrap_or_else(|| format!(\"{owner}/{name}\").to_ascii_lowercase());\n-            out.push(ResolvedChild {\n-                url: format!(\"https://github.com/{full_name}\"),\n-                title: full_name.clone(),\n-                body: Some(github_repo_body(repo)),\n-            });\n-        }\n-        out.sort_by(|a, b| a.url.cmp(&b.url));\n-        Ok(out)\n-    }\n-\n-    async fn list_issues(&self, owner: &str, repo: &str) -> Result, String> {\n-        let arr = self\n-            .get_json_array_pages(&format!(\n-                \"/repos/{owner}/{repo}/issues?state=open&per_page=100\"\n-            ))\n-            .await?;\n-        let mut out = Vec::new();\n-        for issue in &arr {\n-            if issue.get(\"pull_request\").is_some() {\n-                continue;\n-            }\n-            let Some(number) = issue.get(\"number\").and_then(|v| v.as_i64()) else {\n-                continue;\n-            };\n-            let title = issue\n-                .get(\"title\")\n-                .and_then(|v| v.as_str())\n-                .unwrap_or(\"Untitled issue\");\n-            out.push(ResolvedChild {\n-                url: format!(\"https://github.com/{owner}/{repo}/issues/{number}\"),\n-                title: format!(\"#{number} {title}\"),\n-                body: Some(github_issue_body(issue, \"issue\")),\n-            });\n-        }\n-        out.sort_by(|a, b| a.url.cmp(&b.url));\n-        Ok(out)\n-    }\n-\n-    async fn list_pulls(&self, owner: &str, repo: &str) -> Result, String> {\n-        let arr = self\n-            .get_json_array_pages(&format!(\n-                \"/repos/{owner}/{repo}/pulls?state=open&per_page=100\"\n-            ))\n-            .await?;\n-        let mut out = Vec::new();\n-        for pull in &arr {\n-            let Some(number) = pull.get(\"number\").and_then(|v| v.as_i64()) else {\n-                continue;\n-            };\n-            let title = pull\n-                .get(\"title\")\n-                .and_then(|v| v.as_str())\n-                .unwrap_or(\"Untitled pull request\");\n-            out.push(ResolvedChild {\n-                url: format!(\"https://github.com/{owner}/{repo}/pulls/{number}\"),\n-                title: format!(\"#{number} {title}\"),\n-                body: Some(github_issue_body(pull, \"pull request\")),\n-            });\n-        }\n-        out.sort_by(|a, b| a.url.cmp(&b.url));\n-        Ok(out)\n-    }\n-\n-    async fn list_commits(&self, owner: &str, repo: &str) -> Result, String> {\n-        let arr = self\n-            .get_json_array_pages(&format!(\"/repos/{owner}/{repo}/commits?per_page=100\"))\n-            .await?;\n-        let mut out = Vec::new();\n-        for commit in &arr {\n-            let Some(sha) = github_string(commit, \"sha\") else {\n-                continue;\n-            };\n-            let short = sha.chars().take(7).collect::();\n-            let title = commit\n-                .get(\"commit\")\n-                .and_then(|c| c.get(\"message\"))\n-                .and_then(|v| v.as_str())\n-                .and_then(|m| m.lines().next())\n-                .filter(|s| !s.trim().is_empty())\n-                .unwrap_or(\"commit\");\n-            let url = github_string(commit, \"html_url\")\n-                .map(|s| s.to_string())\n-                .unwrap_or_else(|| format!(\"https://github.com/{owner}/{repo}/commit/{sha}\"));\n-            out.push(ResolvedChild {\n-                url,\n-                title: format!(\"{short} {title}\"),\n-                body: Some(github_commit_body(commit)),\n-            });\n-        }\n-        out.sort_by(|a, b| a.url.cmp(&b.url));\n-        Ok(out)\n-    }\n-\n-    async fn list_releases(&self, owner: &str, repo: &str) -> Result, String> {\n-        let arr = self\n-            .get_json_array_pages(&format!(\"/repos/{owner}/{repo}/releases?per_page=100\"))\n-            .await?;\n-        let mut out = Vec::new();\n-        for release in &arr {\n-            let Some(tag) = github_string(release, \"tag_name\") else {\n-                continue;\n-            };\n-            let title = github_string(release, \"name\").unwrap_or(tag);\n-            let url = github_string(release, \"html_url\")\n-                .map(|s| s.to_string())\n-                .unwrap_or_else(|| format!(\"https://github.com/{owner}/{repo}/releases/tag/{tag}\"));\n-            out.push(ResolvedChild {\n-                url,\n-                title: title.to_string(),\n-                body: Some(github_release_body(release)),\n-            });\n-        }\n-        out.sort_by(|a, b| a.url.cmp(&b.url));\n-        Ok(out)\n-    }\n-}\n-\n-fn github_segments(item: &ItemId) -> Option> {\n-    let url = url::Url::parse(item.as_str()).ok()?;\n-    if url.host_str()?.eq_ignore_ascii_case(\"github.com\") {\n-        Some(\n-            url.path_segments()\n-                .map(|segments| {\n-                    segments\n-                        .filter(|s| !s.is_empty())\n-                        .map(|s| s.to_ascii_lowercase())\n-                        .collect::>()\n-                })\n-                .unwrap_or_default(),\n-        )\n-    } else {\n-        None\n-    }\n-}\n-\n-fn github_repo_sections(owner: &str, repo: &str) -> Vec {\n-    [\n-        (\"issues\", \"GitHub issues for this repository.\"),\n-        (\"pulls\", \"GitHub pull requests for this repository.\"),\n-        (\"commits\", \"GitHub commits for this repository.\"),\n-        (\"releases\", \"GitHub releases for this repository.\"),\n-    ]\n-    .into_iter()\n-    .map(|(section, body)| ResolvedChild {\n-        url: format!(\"https://github.com/{owner}/{repo}/{section}\"),\n-        title: section.to_string(),\n-        body: Some(body.to_string()),\n-    })\n-    .collect()\n-}\n-\n-fn resolver_thread_tag(item: &ItemId) -> String {\n-    let tail = item\n-        .display_path()\n-        .trim_start_matches(\"-/\")\n-        .replace('/', \":\")\n-        .replace('?', \":\");\n-    format!(\"import:{tail}\")\n-}\n-\n-fn sanitize_body(s: &str) -> String {\n-    s.replace('{', \"(\")\n-        .replace('}', \")\")\n-        .replace(\"```\", \"` ` `\")\n-        .chars()\n-        .take(4_000)\n-        .collect()\n-}\n-\n-fn github_string<'a>(value: &'a Value, key: &str) -> Option<&'a str> {\n-    value\n-        .get(key)\n-        .and_then(|v| v.as_str())\n-        .filter(|s| !s.trim().is_empty())\n-}\n-\n-fn github_user_login(value: &Value) -> Option<&str> {\n-    value\n-        .get(\"user\")\n-        .and_then(|u| u.get(\"login\"))\n-        .and_then(|v| v.as_str())\n-        .filter(|s| !s.trim().is_empty())\n-}\n-\n-fn github_labels(value: &Value) -> Vec {\n-    value\n-        .get(\"labels\")\n-        .and_then(|v| v.as_array())\n-        .into_iter()\n-        .flat_map(|labels| labels.iter())\n-        .filter_map(|label| label.get(\"name\").and_then(|v| v.as_str()))\n-        .filter(|name| !name.trim().is_empty())\n-        .map(|name| name.to_string())\n-        .collect()\n-}\n-\n-fn github_repo_body(repo: &Value) -> String {\n-    let full_name = github_string(repo, \"full_name\")\n-        .or_else(|| github_string(repo, \"name\"))\n-        .unwrap_or(\"GitHub repository\");\n-    let mut lines = vec![full_name.to_string()];\n-    if let Some(desc) = github_string(repo, \"description\") {\n-        lines.push(String::new());\n-        lines.push(desc.to_string());\n-    }\n-    if let Some(url) = github_string(repo, \"html_url\") {\n-        lines.push(String::new());\n-        lines.push(format!(\"Source: {url}\"));\n-    }\n-    if let Some(lang) = github_string(repo, \"language\") {\n-        lines.push(format!(\"Language: {lang}\"));\n-    }\n-    lines.join(\"\\n\")\n-}\n-\n-fn github_issue_body(issue: &Value, kind: &str) -> String {\n-    let number = issue\n-        .get(\"number\")\n-        .and_then(|v| v.as_i64())\n-        .map(|n| format!(\"#{n} \"))\n-        .unwrap_or_default();\n-    let title = github_string(issue, \"title\").unwrap_or(\"Untitled\");\n-    let state = github_string(issue, \"state\").unwrap_or(\"unknown\");\n-    let mut lines = vec![format!(\"{kind} {number}{title}\")];\n-    lines.push(format!(\"State: {state}\"));\n-    if let Some(author) = github_user_login(issue) {\n-        lines.push(format!(\"Author: @{author}\"));\n-    }\n-    let labels = github_labels(issue);\n-    if !labels.is_empty() {\n-        lines.push(format!(\"Labels: {}\", labels.join(\", \")));\n-    }\n-    if let Some(url) = github_string(issue, \"html_url\") {\n-        lines.push(format!(\"Source: {url}\"));\n-    }\n-    if let Some(body) = github_string(issue, \"body\") {\n-        lines.push(String::new());\n-        lines.push(body.to_string());\n-    }\n-    lines.join(\"\\n\")\n-}\n-\n-fn github_commit_body(commit: &Value) -> String {\n-    let sha = github_string(commit, \"sha\").unwrap_or(\"unknown\");\n-    let short = sha.chars().take(7).collect::();\n-    let commit_obj = commit.get(\"commit\");\n-    let message = commit_obj\n-        .and_then(|c| c.get(\"message\"))\n-        .and_then(|v| v.as_str())\n-        .unwrap_or(\"commit\");\n-    let mut lines = vec![format!(\"commit {short}\")];\n-    if let Some(author) = commit_obj\n-        .and_then(|c| c.get(\"author\"))\n-        .and_then(|a| a.get(\"name\"))\n-        .and_then(|v| v.as_str())\n-        .filter(|s| !s.trim().is_empty())\n-    {\n-        lines.push(format!(\"Author: {author}\"));\n-    }\n-    if let Some(login) = github_user_login(commit) {\n-        lines.push(format!(\"GitHub user: @{login}\"));\n-    }\n-    if let Some(date) = commit_obj\n-        .and_then(|c| c.get(\"author\"))\n-        .and_then(|a| a.get(\"date\"))\n-        .and_then(|v| v.as_str())\n-    {\n-        lines.push(format!(\"Date: {date}\"));\n-    }\n-    if let Some(url) = github_string(commit, \"html_url\") {\n-        lines.push(format!(\"Source: {url}\"));\n-    }\n-    lines.push(String::new());\n-    lines.push(message.to_string());\n-    lines.join(\"\\n\")\n-}\n-\n-fn github_release_body(release: &Value) -> String {\n-    let tag = github_string(release, \"tag_name\").unwrap_or(\"untagged\");\n-    let title = github_string(release, \"name\").unwrap_or(tag);\n-    let mut lines = vec![format!(\"release {title}\")];\n-    lines.push(format!(\"Tag: {tag}\"));\n-    if release\n-        .get(\"draft\")\n-        .and_then(|v| v.as_bool())\n-        .unwrap_or(false)\n-    {\n-        lines.push(\"Draft: yes\".to_string());\n-    }\n-    if release\n-        .get(\"prerelease\")\n-        .and_then(|v| v.as_bool())\n-        .unwrap_or(false)\n-    {\n-        lines.push(\"Prerelease: yes\".to_string());\n-    }\n-    if let Some(author) = github_user_login(release) {\n-        lines.push(format!(\"Author: @{author}\"));\n-    }\n-    if let Some(published) = github_string(release, \"published_at\") {\n-        lines.push(format!(\"Published: {published}\"));\n-    }\n-    if let Some(url) = github_string(release, \"html_url\") {\n-        lines.push(format!(\"Source: {url}\"));\n-    }\n-    if let Some(body) = github_string(release, \"body\") {\n-        lines.push(String::new());\n-        lines.push(body.to_string());\n-    }\n-    lines.join(\"\\n\")\n-}\n-\n-fn children_to_dsl(children: &[ResolvedChild]) -> String {\n-    let mut out = String::new();\n-    for child in children {\n-        let body = child\n-            .body\n-            .as_deref()\n-            .filter(|s| !s.trim().is_empty())\n-            .unwrap_or(child.title.as_str());\n-        if body.trim_start().starts_with(\"```\") {\n-            out.push_str(&format!(\"{} {{\\n{}\\n}}\\n\\n\", child.url, body.trim()));\n-        } else {\n-            out.push_str(&format!(\n-                \"{} {{\\n{}\\n}}\\n\\n\",\n-                child.url,\n-                sanitize_body(body)\n-            ));\n-        }\n-    }\n-    out\n-}\n-\n-pub async fn resolve_github_children(\n-    state: &AppState,\n-    room: &str,\n-    item: &ItemId,\n-) -> Result {\n-    if !state.github_resolver.can_resolve_children(item) {\n-        return Err(\"no GitHub resolver for this item\".to_string());\n-    }\n-\n-    let key = format!(\"github:{}:{}\", room.trim(), item.as_str());\n-    let now = now_ms();\n-    {\n-        let mut runs = state.resolver_runs.write().await;\n-        if let Some(last) = runs.get(&key) {\n-            let remaining = GITHUB_RESOLVER_COOLDOWN_MS - (now - *last);\n-            if remaining > 0 {\n-                return Err(format!(\n-                    \"GitHub resolver cooldown: try again in {}s\",\n-                    (remaining + 999) / 1000\n-                ));\n-            }\n-        }\n-        runs.insert(key, now);\n-    }\n-\n-    let children = state.github_resolver.list_children(item).await?;\n-    if children.is_empty() {\n-        return Ok(0);\n-    }\n-    let text = children_to_dsl(&children);\n-    let thread_tag = resolver_thread_tag(item);\n-    let (tx, rx) = oneshot::channel();\n-    state\n-        .write_tx\n-        .send(WriteCmd::SystemIngest {\n-            room: room.to_string(),\n-            thread_tag,\n-            text,\n-            principal: GITHUB_SYSTEM_PRINCIPAL.to_string(),\n-            reply: tx,\n-        })\n-        .await\n-        .map_err(|_| \"writer unavailable\".to_string())?;\n-    rx.await\n-        .map_err(|_| \"writer dropped\".to_string())?\n-        .map_err(|(msg, hint)| hint.map_or(msg.clone(), |h| format!(\"{msg}: {h}\")))?;\n-    Ok(children.len())\n-}\n-\n-/// Placeholder until other domain-specific resolvers exist.\n-pub struct DefaultExternalResolver;\n-\n-#[async_trait]\n-impl ExternalResolver for DefaultExternalResolver {\n-    fn domain_match(&self) -> &'static str {\n-        \"\"\n-    }\n-\n-    fn normalize(&self, path: &str) -> String {\n-        path.to_string()\n-    }\n-\n-    async fn fetch_body(&self, _item: &ItemId) -> Result {\n-        Err(\"external fetch not implemented\".to_string())\n-    }\n-}\n-\n-#[cfg(test)]\n-mod tests {\n-    use super::*;\n-\n-    #[test]\n-    fn github_segments_parse_normalized_url() {\n-        let item = ItemId::parse(\"https://github.com/Sortersocial/Slug/issues\").unwrap();\n-        assert_eq!(\n-            github_segments(&item),\n-            Some(vec![\n-                \"sortersocial\".to_string(),\n-                \"slug\".to_string(),\n-                \"issues\".to_string()\n-            ])\n-        );\n-    }\n-\n-    #[test]\n-    fn repo_sections_are_direct_children() {\n-        let sections = github_repo_sections(\"sortersocial\", \"slug\");\n-        let urls: Vec = sections.into_iter().map(|c| c.url).collect();\n-        assert!(urls.contains(&\"https://github.com/sortersocial/slug/issues\".to_string()));\n-        assert!(urls.contains(&\"https://github.com/sortersocial/slug/pulls\".to_string()));\n-    }\n-\n-    #[test]\n-    fn children_to_dsl_contains_item_bodies() {\n-        let dsl = children_to_dsl(&[ResolvedChild {\n-            url: \"https://github.com/o/r/issues/1\".into(),\n-            title: \"#1 title\".into(),\n-            body: Some(\"body with {braces}\".into()),\n-        }]);\n-        assert!(dsl.contains(\"https://github.com/o/r/issues/1\"));\n-        assert!(dsl.contains(\"body with (braces)\"));\n-    }\n-\n-    #[test]\n-    fn children_to_dsl_preserves_fenced_json_bodies() {\n-        let dsl = children_to_dsl(&[ResolvedChild {\n-            url: \"https://github.com/o/r/issues/1\".into(),\n-            title: \"#1 title\".into(),\n-            body: Some(\"```json\\n{\\\"test\\\": true}\\n```\".into()),\n-        }]);\n-        assert!(dsl.contains(\"https://github.com/o/r/issues/1 {\\n```json\"));\n-        assert!(dsl.contains(\"{\\\"test\\\": true}\"));\n-        assert!(dsl.contains(\"```\\n}\\n\"));\n-    }\n-\n-    #[test]\n-    fn github_issue_body_is_readable_text_not_json_dump() {\n-        let issue = serde_json::json!({\n-            \"number\": 12,\n-            \"title\": \"Render children\",\n-            \"state\": \"open\",\n-            \"html_url\": \"https://github.com/o/r/issues/12\",\n-            \"user\": {\"login\": \"octo\"},\n-            \"labels\": [{\"name\": \"bug\"}],\n-            \"body\": \"The issue body.\"\n-        });\n-        let body = github_issue_body(&issue, \"issue\");\n-        assert!(body.contains(\"issue #12 Render children\"));\n-        assert!(body.contains(\"Author: @octo\"));\n-        assert!(body.contains(\"The issue body.\"));\n-        assert!(!body.trim_start().starts_with(\"```json\"));\n-    }\n-\n-    #[test]\n-    fn github_commit_and_release_bodies_are_readable() {\n-        let commit = serde_json::json!({\n-            \"sha\": \"abcdef123456\",\n-            \"html_url\": \"https://github.com/o/r/commit/abcdef123456\",\n-            \"author\": {\"login\": \"octo\"},\n-            \"commit\": {\n-                \"message\": \"Fix vote page\\n\\nDetails here.\",\n-                \"author\": {\"name\": \"Octo Dev\", \"date\": \"2026-05-17T00:00:00Z\"}\n-            }\n-        });\n-        let release = serde_json::json!({\n-            \"tag_name\": \"v1.2.3\",\n-            \"name\": \"Release 1.2.3\",\n-            \"html_url\": \"https://github.com/o/r/releases/tag/v1.2.3\",\n-            \"author\": {\"login\": \"octo\"},\n-            \"prerelease\": true,\n-            \"body\": \"Release notes.\"\n-        });\n-        assert!(github_commit_body(&commit).contains(\"commit abcdef1\"));\n-        assert!(github_commit_body(&commit).contains(\"Fix vote page\"));\n-        assert!(github_release_body(&release).contains(\"release Release 1.2.3\"));\n-        assert!(github_release_body(&release).contains(\"Prerelease: yes\"));\n-    }\n-}\ndiff --git a/server/src/html/garden.rs b/server/src/html/garden.rs\nindex 9ca66e7c5860d428e95abf5df518fc1e7b4f6332..e2dc6e5529d4a3126723d0dea75931d0738b6c83 100644\n--- a/server/src/html/garden.rs\n+++ b/server/src/html/garden.rs\n@@ -7,7 +7,7 @@ use axum_extra::extract::cookie::CookieJar;\n use maud::html;\n use serde::Deserialize;\n use serde_json::json;\n-use std::collections::HashSet;\n+use std::collections::{HashMap, HashSet};\n \n use base64::{engine::general_purpose::URL_SAFE_NO_PAD as B64_ENGINE, Engine as _};\n \n@@ -21,8 +21,8 @@ use crate::{\n     path_types::ItemId,\n     reducer::{ContentState, ReducerState, ScopeId},\n     scope_rank::{\n-        build_children_rankings, build_rankings_for_item_set, resolve_scope_recursive,\n-        suggest_next_pair_in_pool, ChildrenRankings,\n+        build_children_rankings, build_rankings_for_item_set, external_root_host_items,\n+        resolve_scope_recursive, suggest_next_pair_in_pool, ChildrenRankings,\n     },\n     state::AppState,\n     timeago,\n@@ -33,7 +33,7 @@ use super::{\n     breadcrumb_path::{ExternalOntologyPath, OntologyPath},\n     cli_panel,\n     forum::ThreadNav,\n-    layout, layout_full_bleed_chromeless, now_ms, ratio_pct, render_linkified_with_embeds_in_scope,\n+    layout, layout_full_bleed_chromeless, now_ms, ratio_pct, render_item_body_in_scope,\n     theme_from_jar, theme_next_from_uri,\n };\n \n@@ -358,6 +358,7 @@ fn vote_compare_item_card(\n     item: &ItemId,\n     body: Option<&String>,\n     side_class: &str,\n+    item_bodies: Option<&HashMap>,\n ) -> maud::Markup {\n     html! {\n         div class=(format!(\"vote-compare-side {side_class}\")) {\n@@ -366,10 +367,10 @@ fn vote_compare_item_card(\n             }\n             @if let Some(body) = body.filter(|b| !b.trim().is_empty()) {\n                 div class=\"vote-compare-item-body\" {\n-                    (render_linkified_with_embeds_in_scope(\n+                    (render_item_body_in_scope(\n                         body,\n                         nav.garden_root_url(),\n-                        None,\n+                        item_bodies,\n                     ))\n                 }\n             } @else {\n@@ -678,10 +679,11 @@ pub async fn external_garden_index(\n ) -> impl IntoResponse {\n     let nav = ThreadNav::public();\n     let ext_path = ExternalOntologyPath::from_input(\"\");\n-    let parent = ItemId::parse(\"https://.\").unwrap();\n     let child_rankings = {\n         let reduced = state.reduced.read().await;\n-        build_children_rankings(reduced.public(), &parent)\n+        let content = reduced.public();\n+        let hosts = external_root_host_items(content);\n+        build_rankings_for_item_set(content, &hosts)\n     };\n \n     let url_key = canonical_view_url(&uri);\n@@ -812,9 +814,11 @@ pub async fn room_external_garden_index(\n         return room_not_found_page(&jar, &uri).into_response();\n     }\n     let ext_path = ExternalOntologyPath::from_input(\"\");\n-    let parent = ItemId::parse(\"https://.\").unwrap();\n-    let child_rankings =\n-        build_children_rankings(content_for_garden_view(&reduced, &nav.scope()), &parent);\n+    let child_rankings = {\n+        let content = content_for_garden_view(&reduced, &nav.scope());\n+        let hosts = external_root_host_items(content);\n+        build_rankings_for_item_set(content, &hosts)\n+    };\n     drop(reduced);\n \n     let url_key = canonical_view_url(&uri);\n@@ -1334,7 +1338,7 @@ async fn render_scope_view(\n                 }\n                 @if let Some(body) = &model.body {\n                     div class=\"ont-item-content\" {\n-                        (render_linkified_with_embeds_in_scope(\n+                        (render_item_body_in_scope(\n                             body,\n                             nav.garden_root_url(),\n                             Some(&scope_content.item_bodies),\n@@ -1592,6 +1596,7 @@ async fn vote_compare_inner(\n     let edge_history = vote_edge_history_markup(content, &left, &right);\n     let left_body = content.item_bodies.get(&left).cloned();\n     let right_body = content.item_bodies.get(&right).cloned();\n+    let item_bodies_for_cards = content.item_bodies.clone();\n     let next_pair = suggest_next_vote_pair(content, &left, &right);\n     drop(reduced);\n \n@@ -1623,9 +1628,21 @@ async fn vote_compare_inner(\n     section class=\"vote-compare-shell\" {\n         h2 { \"compare\" }\n         div class=\"vote-compare-pair\" {\n-            (vote_compare_item_card(&nav, &left, left_body.as_ref(), \"vote-compare-left\"))\n+            (vote_compare_item_card(\n+                &nav,\n+                &left,\n+                left_body.as_ref(),\n+                \"vote-compare-left\",\n+                Some(&item_bodies_for_cards),\n+            ))\n             span class=\"vote-compare-vs\" { \"vs\" }\n-            (vote_compare_item_card(&nav, &right, right_body.as_ref(), \"vote-compare-right\"))\n+            (vote_compare_item_card(\n+                &nav,\n+                &right,\n+                right_body.as_ref(),\n+                \"vote-compare-right\",\n+                Some(&item_bodies_for_cards),\n+            ))\n         }\n         (vote_compare_nav_markup(&nav, next_pair.as_ref(), &left, &right, q.thread.as_deref()))\n         div id=\"vote-edge-history-region\" {\n@@ -2020,6 +2037,40 @@ mod tests {\n         assert!(items.contains(\"https://slug.social/~/topic/b\"));\n     }\n \n+    #[test]\n+    fn vote_compare_item_card_renders_github_import_markup() {\n+        use crate::html::forum::ThreadNav;\n+        use super::vote_compare_item_card;\n+        use crate::path_types::ItemId;\n+\n+        let nav = ThreadNav::public();\n+        let item = ItemId::parse(\"https://github.com/o/r/issues/1\").unwrap();\n+        let json = serde_json::json!({\n+            \"v\": 1,\n+            \"schema\": \"slug_github_import\",\n+            \"kind\": \"issue\",\n+            \"url\": \"https://github.com/o/r/issues/1\",\n+            \"headline\": \"#1 Compare card\",\n+            \"sublines\": [\"State: open\"],\n+        });\n+        let body = format!(\"```slug-github-card\\n{}\\n```\", json.to_string());\n+        let html = vote_compare_item_card(\n+            &nav,\n+            &item,\n+            Some(&body),\n+            \"vote-compare-left\",\n+            None,\n+        )\n+        .into_string();\n+        assert!(\n+            html.contains(\"github-import-card\"),\n+            \"expected rich GitHub card markup, got: {html}\"\n+        );\n+        assert!(html.contains(\"item-body-rich\"));\n+        assert!(html.contains(\"vote-compare-left\"));\n+        assert!(html.contains(\"#1 Compare card\"));\n+    }\n+\n     #[test]\n     fn external_source_href_maps_youtube_path_identity_back_to_watch_url() {\n         assert_eq!(\ndiff --git a/server/src/html/mod.rs b/server/src/html/mod.rs\nindex a1b929625acbd5298c0cf62f3ca0892079edcb2a..3b23e19a8b35aa4c0b0480e29de7d46ad57ab276 100644\n--- a/server/src/html/mod.rs\n+++ b/server/src/html/mod.rs\n@@ -793,6 +793,20 @@ pub(super) fn render_linkified_with_embeds_in_scope(\n     }\n }\n \n+/// Item page / thread body: resolver-specific rich HTML, else linkified `
    ` + media embeds.\n+pub(super) fn render_item_body_in_scope(\n+    raw: &str,\n+    garden_prefix: &str,\n+    item_bodies: Option<&HashMap>,\n+) -> Markup {\n+    if let Some(m) = crate::resolvers::try_render_resolver_item_body(raw) {\n+        return html! {\n+            div class=\"item-body-rich\" { (m) }\n+        };\n+    }\n+    render_linkified_with_embeds_in_scope(raw, garden_prefix, item_bodies)\n+}\n+\n /// CLI strings are embedded in a single-quoted JS literal; they must never need escaping.\n fn assert_cli_panel_cmd_js_single_quote_safe(s: &str) {\n     assert!(\ndiff --git a/server/src/lib.rs b/server/src/lib.rs\nindex 84e94bbec144eae77de68482385941cd2c5845eb..c1d477d21aea03aff00e6f0689b0b4379d0d68d2 100644\n--- a/server/src/lib.rs\n+++ b/server/src/lib.rs\n@@ -5,7 +5,7 @@ pub mod canonical_path;\n pub mod dsl;\n pub mod event_log;\n pub mod events;\n-pub mod external_resolver;\n+pub mod resolvers;\n pub mod form_template;\n pub mod html;\n pub mod identity;\n@@ -51,7 +51,7 @@ pub fn create_app_state(cfg: AppConfig) -> AppState {\n         write_tx,\n         views,\n         resolver_runs: Arc::new(RwLock::new(HashMap::new())),\n-        github_resolver: Arc::new(crate::external_resolver::GitHubResolver::from_env()),\n+        github_resolver: Arc::new(crate::resolvers::GitHubResolver::from_env()),\n     };\n     tokio::spawn(crate::api::write_actor::writer_actor(\n         write_rx,\ndiff --git a/server/src/resolvers/default_external.rs b/server/src/resolvers/default_external.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..d37c222abcee3c20b22189b2822da9e9a6ff0515\n--- /dev/null\n+++ b/server/src/resolvers/default_external.rs\n@@ -0,0 +1,22 @@\n+use async_trait::async_trait;\n+\n+use crate::path_types::ItemId;\n+use super::github::ExternalResolver;\n+\n+/// Placeholder until other domain-specific resolvers exist.\n+pub struct DefaultExternalResolver;\n+\n+#[async_trait]\n+impl ExternalResolver for DefaultExternalResolver {\n+    fn domain_match(&self) -> &'static str {\n+        \"\"\n+    }\n+\n+    fn normalize(&self, path: &str) -> String {\n+        path.to_string()\n+    }\n+\n+    async fn fetch_body(&self, _item: &ItemId) -> Result {\n+        Err(\"external fetch not implemented\".to_string())\n+    }\n+}\ndiff --git a/server/src/resolvers/github.rs b/server/src/resolvers/github.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..5a9c0c38ff01ca5894f7dc62c1008371dacb0cf1\n--- /dev/null\n+++ b/server/src/resolvers/github.rs\n@@ -0,0 +1,755 @@\n+use async_trait::async_trait;\n+use maud::html;\n+use serde::{Deserialize, Serialize};\n+use serde_json::Value;\n+use tokio::sync::oneshot;\n+\n+use crate::{path_types::ItemId, state::AppState, write_cmd::WriteCmd};\n+\n+pub const SLUG_GITHUB_SCHEMA: &str = \"slug_github_import\";\n+\n+const GITHUB_SYSTEM_PRINCIPAL: &str = \"system:github-resolver\";\n+const GITHUB_RESOLVER_COOLDOWN_MS: i64 = 15_000;\n+const GITHUB_MAX_PAGES: usize = 3;\n+\n+fn now_ms() -> i64 {\n+    use std::time::{SystemTime, UNIX_EPOCH};\n+    SystemTime::now()\n+        .duration_since(UNIX_EPOCH)\n+        .unwrap_or_default()\n+        .as_millis() as i64\n+}\n+\n+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]\n+#[serde(rename_all = \"snake_case\")]\n+pub enum GithubImportKind {\n+    Repo,\n+    RepoSection,\n+    Issue,\n+    Pull,\n+    Commit,\n+    Release,\n+}\n+\n+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]\n+pub struct GithubImportCard {\n+    pub v: u32,\n+    #[serde(default)]\n+    pub schema: String,\n+    pub kind: GithubImportKind,\n+    pub url: String,\n+    pub headline: String,\n+    #[serde(default)]\n+    pub sublines: Vec,\n+    #[serde(default)]\n+    pub excerpt: Option,\n+}\n+\n+impl GithubImportCard {\n+    fn new(kind: GithubImportKind, url: String, headline: String) -> Self {\n+        Self {\n+            v: 1,\n+            schema: SLUG_GITHUB_SCHEMA.to_string(),\n+            kind,\n+            url,\n+            headline,\n+            sublines: Vec::new(),\n+            excerpt: None,\n+        }\n+    }\n+}\n+\n+#[derive(Debug, Clone, PartialEq, Eq)]\n+pub struct ResolvedChild {\n+    pub url: String,\n+    pub title: String,\n+    pub card: GithubImportCard,\n+}\n+\n+#[async_trait]\n+pub trait ExternalResolver: Send + Sync {\n+    /// e.g. `\"github.com\"`\n+    fn domain_match(&self) -> &'static str;\n+\n+    /// Normalizes URLs (e.g. stripping fragments); extend per-domain later.\n+    fn normalize(&self, path: &str) -> String;\n+\n+    /// Fetches body when missing; GitHub hook lands here in a follow-up.\n+    async fn fetch_body(&self, item: &ItemId) -> Result;\n+}\n+\n+#[derive(Clone)]\n+pub struct GitHubResolver {\n+    client: reqwest::Client,\n+    api_base_url: String,\n+    token: Option,\n+}\n+\n+impl GitHubResolver {\n+    pub fn from_env() -> Self {\n+        let api_base_url = std::env::var(\"SLUG_GITHUB_API_BASE_URL\")\n+            .ok()\n+            .filter(|s| !s.trim().is_empty())\n+            .unwrap_or_else(|| \"https://api.github.com\".to_string());\n+        let token = std::env::var(\"SLUG_GITHUB_TOKEN\")\n+            .ok()\n+            .filter(|s| !s.trim().is_empty());\n+        Self {\n+            client: reqwest::Client::new(),\n+            api_base_url: api_base_url.trim_end_matches('/').to_string(),\n+            token,\n+        }\n+    }\n+\n+    pub fn can_resolve_children(&self, item: &ItemId) -> bool {\n+        github_segments(item).is_some()\n+    }\n+\n+    pub async fn list_children(&self, item: &ItemId) -> Result, String> {\n+        let segments = github_segments(item).ok_or_else(|| \"not a GitHub URL\".to_string())?;\n+        match segments.as_slice() {\n+            [] => Ok(vec![]),\n+            [owner] => self.list_repos(owner).await,\n+            [owner, repo] => Ok(github_repo_sections(owner, repo)),\n+            [owner, repo, section] if section == \"issues\" => self.list_issues(owner, repo).await,\n+            [owner, repo, section] if section == \"pulls\" => self.list_pulls(owner, repo).await,\n+            [owner, repo, section] if section == \"commits\" => self.list_commits(owner, repo).await,\n+            [owner, repo, section] if section == \"releases\" => {\n+                self.list_releases(owner, repo).await\n+            }\n+            _ => Ok(vec![]),\n+        }\n+    }\n+\n+    async fn get_json(&self, path: &str) -> Result {\n+        let url = format!(\"{}/{}\", self.api_base_url, path.trim_start_matches('/'));\n+        let mut req = self\n+            .client\n+            .get(url)\n+            .header(reqwest::header::USER_AGENT, \"slugsocial-github-resolver\");\n+        if let Some(token) = &self.token {\n+            req = req.bearer_auth(token);\n+        }\n+        let resp = req\n+            .send()\n+            .await\n+            .map_err(|e| format!(\"GitHub request failed: {e}\"))?;\n+        let status = resp.status();\n+        if !status.is_success() {\n+            return Err(format!(\"GitHub request returned {status}\"));\n+        }\n+        resp.json::()\n+            .await\n+            .map_err(|e| format!(\"GitHub response JSON failed: {e}\"))\n+    }\n+\n+    async fn get_json_array_pages(&self, path: &str) -> Result, String> {\n+        let sep = if path.contains('?') { '&' } else { '?' };\n+        let mut out = Vec::new();\n+        for page in 1..=GITHUB_MAX_PAGES {\n+            let value = self.get_json(&format!(\"{path}{sep}page={page}\")).await?;\n+            let arr = value\n+                .as_array()\n+                .ok_or_else(|| \"GitHub paged response was not an array\".to_string())?;\n+            let n = arr.len();\n+            out.extend(arr.iter().cloned());\n+            if n < 100 {\n+                break;\n+            }\n+        }\n+        Ok(out)\n+    }\n+\n+    async fn list_repos(&self, owner: &str) -> Result, String> {\n+        let arr = self\n+            .get_json_array_pages(&format!(\n+                \"/users/{owner}/repos?per_page=100&sort=updated&type=owner\"\n+            ))\n+            .await?;\n+        let mut out = Vec::new();\n+        for repo in &arr {\n+            let name = repo\n+                .get(\"name\")\n+                .and_then(|v| v.as_str())\n+                .unwrap_or_default();\n+            if name.is_empty() {\n+                continue;\n+            }\n+            let full_name = repo\n+                .get(\"full_name\")\n+                .and_then(|v| v.as_str())\n+                .map(|s| s.to_ascii_lowercase())\n+                .unwrap_or_else(|| format!(\"{owner}/{name}\").to_ascii_lowercase());\n+            let url = format!(\"https://github.com/{full_name}\");\n+            let mut card = card_for_repo(repo, &url);\n+            card.headline = full_name.clone();\n+            out.push(ResolvedChild {\n+                url,\n+                title: full_name,\n+                card,\n+            });\n+        }\n+        out.sort_by(|a, b| a.url.cmp(&b.url));\n+        Ok(out)\n+    }\n+\n+    async fn list_issues(&self, owner: &str, repo: &str) -> Result, String> {\n+        let arr = self\n+            .get_json_array_pages(&format!(\n+                \"/repos/{owner}/{repo}/issues?state=open&per_page=100\"\n+            ))\n+            .await?;\n+        let mut out = Vec::new();\n+        for issue in &arr {\n+            if issue.get(\"pull_request\").is_some() {\n+                continue;\n+            }\n+            let Some(number) = issue.get(\"number\").and_then(|v| v.as_i64()) else {\n+                continue;\n+            };\n+            let title = issue\n+                .get(\"title\")\n+                .and_then(|v| v.as_str())\n+                .unwrap_or(\"Untitled issue\");\n+            let url = format!(\"https://github.com/{owner}/{repo}/issues/{number}\");\n+            let card = card_for_issue(issue, &url, GithubImportKind::Issue);\n+            out.push(ResolvedChild {\n+                url: url.clone(),\n+                title: format!(\"#{number} {title}\"),\n+                card,\n+            });\n+        }\n+        out.sort_by(|a, b| a.url.cmp(&b.url));\n+        Ok(out)\n+    }\n+\n+    async fn list_pulls(&self, owner: &str, repo: &str) -> Result, String> {\n+        let arr = self\n+            .get_json_array_pages(&format!(\n+                \"/repos/{owner}/{repo}/pulls?state=open&per_page=100\"\n+            ))\n+            .await?;\n+        let mut out = Vec::new();\n+        for pull in &arr {\n+            let Some(number) = pull.get(\"number\").and_then(|v| v.as_i64()) else {\n+                continue;\n+            };\n+            let title = pull\n+                .get(\"title\")\n+                .and_then(|v| v.as_str())\n+                .unwrap_or(\"Untitled pull request\");\n+            let url = format!(\"https://github.com/{owner}/{repo}/pulls/{number}\");\n+            let card = card_for_issue(pull, &url, GithubImportKind::Pull);\n+            out.push(ResolvedChild {\n+                url: url.clone(),\n+                title: format!(\"#{number} {title}\"),\n+                card,\n+            });\n+        }\n+        out.sort_by(|a, b| a.url.cmp(&b.url));\n+        Ok(out)\n+    }\n+\n+    async fn list_commits(&self, owner: &str, repo: &str) -> Result, String> {\n+        let arr = self\n+            .get_json_array_pages(&format!(\"/repos/{owner}/{repo}/commits?per_page=100\"))\n+            .await?;\n+        let mut out = Vec::new();\n+        for commit in &arr {\n+            let Some(sha) = github_string(commit, \"sha\") else {\n+                continue;\n+            };\n+            let short = sha.chars().take(7).collect::();\n+            let title = commit\n+                .get(\"commit\")\n+                .and_then(|c| c.get(\"message\"))\n+                .and_then(|v| v.as_str())\n+                .and_then(|m| m.lines().next())\n+                .filter(|s| !s.trim().is_empty())\n+                .unwrap_or(\"commit\");\n+            let url = github_string(commit, \"html_url\")\n+                .map(|s| s.to_string())\n+                .unwrap_or_else(|| format!(\"https://github.com/{owner}/{repo}/commit/{sha}\"));\n+            let card = card_for_commit(commit, &url, &short, title);\n+            out.push(ResolvedChild {\n+                url: url.clone(),\n+                title: format!(\"{short} {title}\"),\n+                card,\n+            });\n+        }\n+        out.sort_by(|a, b| a.url.cmp(&b.url));\n+        Ok(out)\n+    }\n+\n+    async fn list_releases(&self, owner: &str, repo: &str) -> Result, String> {\n+        let arr = self\n+            .get_json_array_pages(&format!(\"/repos/{owner}/{repo}/releases?per_page=100\"))\n+            .await?;\n+        let mut out = Vec::new();\n+        for release in &arr {\n+            let Some(tag) = github_string(release, \"tag_name\") else {\n+                continue;\n+            };\n+            let title = github_string(release, \"name\").unwrap_or(tag);\n+            let url = github_string(release, \"html_url\")\n+                .map(|s| s.to_string())\n+                .unwrap_or_else(|| format!(\"https://github.com/{owner}/{repo}/releases/tag/{tag}\"));\n+            let card = card_for_release(release, &url, title);\n+            out.push(ResolvedChild {\n+                url: url.clone(),\n+                title: title.to_string(),\n+                card,\n+            });\n+        }\n+        out.sort_by(|a, b| a.url.cmp(&b.url));\n+        Ok(out)\n+    }\n+}\n+\n+fn github_segments(item: &ItemId) -> Option> {\n+    let url = url::Url::parse(item.as_str()).ok()?;\n+    if url.host_str()?.eq_ignore_ascii_case(\"github.com\") {\n+        Some(\n+            url.path_segments()\n+                .map(|segments| {\n+                    segments\n+                        .filter(|s| !s.is_empty())\n+                        .map(|s| s.to_ascii_lowercase())\n+                        .collect::>()\n+                })\n+                .unwrap_or_default(),\n+        )\n+    } else {\n+        None\n+    }\n+}\n+\n+fn title_case_segment(seg: &str) -> String {\n+    let mut c = seg.chars();\n+    match c.next() {\n+        None => String::new(),\n+        Some(f) => f.to_uppercase().chain(c).collect(),\n+    }\n+}\n+\n+fn github_repo_sections(owner: &str, repo: &str) -> Vec {\n+    [\n+        (\"issues\", \"GitHub issues for this repository.\"),\n+        (\"pulls\", \"GitHub pull requests for this repository.\"),\n+        (\"commits\", \"GitHub commits for this repository.\"),\n+        (\"releases\", \"GitHub releases for this repository.\"),\n+    ]\n+    .into_iter()\n+    .map(|(section, blurb)| {\n+        let url = format!(\"https://github.com/{owner}/{repo}/{section}\");\n+        let mut card = GithubImportCard::new(\n+            GithubImportKind::RepoSection,\n+            url.clone(),\n+            format!(\"{owner}/{repo} — {}\", title_case_segment(section)),\n+        );\n+        card.excerpt = Some(blurb.to_string());\n+        ResolvedChild {\n+            url,\n+            title: section.to_string(),\n+            card,\n+        }\n+    })\n+    .collect()\n+}\n+\n+fn resolver_thread_tag(item: &ItemId) -> String {\n+    let tail = item\n+        .display_path()\n+        .trim_start_matches(\"-/\")\n+        .replace('/', \":\")\n+        .replace('?', \":\");\n+    format!(\"import:{tail}\")\n+}\n+\n+fn children_to_dsl(children: &[ResolvedChild]) -> String {\n+    let mut out = String::new();\n+    for child in children {\n+        let json = serde_json::to_string(&child.card).unwrap_or_else(|_| \"{}\".to_string());\n+        let inner = format!(\"```slug-github-card\\n{json}\\n```\");\n+        out.push_str(&format!(\"{} {{\\n{}\\n}}\\n\\n\", child.url, inner));\n+    }\n+    out\n+}\n+\n+fn card_for_repo(repo: &Value, fallback_url: &str) -> GithubImportCard {\n+    let url = github_string(repo, \"html_url\")\n+        .map(|s| s.to_string())\n+        .filter(|s| !s.is_empty())\n+        .unwrap_or_else(|| fallback_url.to_string());\n+    let full_name = github_string(repo, \"full_name\")\n+        .or_else(|| github_string(repo, \"name\"))\n+        .unwrap_or(\"repository\");\n+    let mut card = GithubImportCard::new(GithubImportKind::Repo, url, full_name.to_string());\n+    if let Some(lang) = github_string(repo, \"language\") {\n+        card.sublines.push(format!(\"Language: {lang}\"));\n+    }\n+    if let Some(desc) = github_string(repo, \"description\") {\n+        card.excerpt = Some(desc.to_string());\n+    }\n+    card\n+}\n+\n+fn excerpt_from_github_body(body: Option<&str>) -> Option {\n+    let b = body?.trim();\n+    if b.is_empty() {\n+        return None;\n+    }\n+    let max = 1200usize;\n+    if b.len() <= max {\n+        Some(b.to_string())\n+    } else {\n+        Some(format!(\"{}…\", b.chars().take(max).collect::()))\n+    }\n+}\n+\n+fn card_for_issue(v: &Value, url: &str, kind: GithubImportKind) -> GithubImportCard {\n+    let number = v.get(\"number\").and_then(|n| n.as_i64());\n+    let title = github_string(v, \"title\").unwrap_or(\"Untitled\");\n+    let state = github_string(v, \"state\").unwrap_or(\"unknown\");\n+    let headline = match number {\n+        Some(n) => format!(\"#{n} {title}\"),\n+        None => title.to_string(),\n+    };\n+    let mut card = GithubImportCard::new(kind, url.to_string(), headline);\n+    card.sublines.push(format!(\"State: {state}\"));\n+    if let Some(a) = github_user_login(v) {\n+        card.sublines.push(format!(\"Author: @{a}\"));\n+    }\n+    let labels = github_labels(v);\n+    if !labels.is_empty() {\n+        card.sublines\n+            .push(format!(\"Labels: {}\", labels.join(\", \")));\n+    }\n+    card.excerpt = excerpt_from_github_body(github_string(v, \"body\"));\n+    card\n+}\n+\n+fn card_for_commit(v: &Value, url: &str, short_sha: &str, subject: &str) -> GithubImportCard {\n+    let headline = format!(\"{short_sha} {subject}\");\n+    let mut card = GithubImportCard::new(GithubImportKind::Commit, url.to_string(), headline);\n+    if let Some(name) = v\n+        .get(\"commit\")\n+        .and_then(|c| c.get(\"author\"))\n+        .and_then(|a| a.get(\"name\"))\n+        .and_then(|n| n.as_str())\n+        .filter(|s| !s.trim().is_empty())\n+    {\n+        card.sublines.push(format!(\"Author: {name}\"));\n+    }\n+    if let Some(login) = github_user_login(v) {\n+        card.sublines.push(format!(\"GitHub: @{login}\"));\n+    }\n+    if let Some(date) = v\n+        .get(\"commit\")\n+        .and_then(|c| c.get(\"author\"))\n+        .and_then(|a| a.get(\"date\"))\n+        .and_then(|d| d.as_str())\n+    {\n+        card.sublines.push(format!(\"Date: {date}\"));\n+    }\n+    if let Some(msg) = v\n+        .get(\"commit\")\n+        .and_then(|c| c.get(\"message\"))\n+        .and_then(|m| m.as_str())\n+    {\n+        card.excerpt = excerpt_from_github_body(Some(msg));\n+    }\n+    card\n+}\n+\n+fn card_for_release(v: &Value, url: &str, title: &str) -> GithubImportCard {\n+    let tag = github_string(v, \"tag_name\").unwrap_or(\"untagged\");\n+    let mut card = GithubImportCard::new(\n+        GithubImportKind::Release,\n+        url.to_string(),\n+        format!(\"Release — {title}\"),\n+    );\n+    card.sublines.push(format!(\"Tag: {tag}\"));\n+    if v.get(\"draft\").and_then(|b| b.as_bool()).unwrap_or(false) {\n+        card.sublines.push(\"Draft: yes\".to_string());\n+    }\n+    if v.get(\"prerelease\")\n+        .and_then(|b| b.as_bool())\n+        .unwrap_or(false)\n+    {\n+        card.sublines.push(\"Prerelease: yes\".to_string());\n+    }\n+    if let Some(a) = github_user_login(v) {\n+        card.sublines.push(format!(\"Author: @{a}\"));\n+    }\n+    if let Some(pub_at) = github_string(v, \"published_at\") {\n+        card.sublines.push(format!(\"Published: {pub_at}\"));\n+    }\n+    card.excerpt = excerpt_from_github_body(github_string(v, \"body\"));\n+    card\n+}\n+\n+fn github_string<'a>(value: &'a Value, key: &str) -> Option<&'a str> {\n+    value\n+        .get(key)\n+        .and_then(|v| v.as_str())\n+        .filter(|s| !s.trim().is_empty())\n+}\n+\n+fn github_user_login(value: &Value) -> Option<&str> {\n+    value\n+        .get(\"user\")\n+        .and_then(|u| u.get(\"login\"))\n+        .and_then(|v| v.as_str())\n+        .filter(|s| !s.trim().is_empty())\n+}\n+\n+fn github_labels(value: &Value) -> Vec {\n+    value\n+        .get(\"labels\")\n+        .and_then(|v| v.as_array())\n+        .into_iter()\n+        .flat_map(|labels| labels.iter())\n+        .filter_map(|label| label.get(\"name\").and_then(|v| v.as_str()))\n+        .filter(|name| !name.trim().is_empty())\n+        .map(|name| name.to_string())\n+        .collect()\n+}\n+\n+pub async fn resolve_github_children(\n+    state: &AppState,\n+    room: &str,\n+    item: &ItemId,\n+) -> Result {\n+    if !state.github_resolver.can_resolve_children(item) {\n+        return Err(\"no GitHub resolver for this item\".to_string());\n+    }\n+\n+    let key = format!(\"github:{}:{}\", room.trim(), item.as_str());\n+    let now = now_ms();\n+    {\n+        let mut runs = state.resolver_runs.write().await;\n+        if let Some(last) = runs.get(&key) {\n+            let remaining = GITHUB_RESOLVER_COOLDOWN_MS - (now - *last);\n+            if remaining > 0 {\n+                return Err(format!(\n+                    \"GitHub resolver cooldown: try again in {}s\",\n+                    (remaining + 999) / 1000\n+                ));\n+            }\n+        }\n+        runs.insert(key, now);\n+    }\n+\n+    let children = state.github_resolver.list_children(item).await?;\n+    if children.is_empty() {\n+        return Ok(0);\n+    }\n+    let text = children_to_dsl(&children);\n+    let thread_tag = resolver_thread_tag(item);\n+    let (tx, rx) = oneshot::channel();\n+    state\n+        .write_tx\n+        .send(WriteCmd::SystemIngest {\n+            room: room.to_string(),\n+            thread_tag,\n+            text,\n+            principal: GITHUB_SYSTEM_PRINCIPAL.to_string(),\n+            reply: tx,\n+        })\n+        .await\n+        .map_err(|_| \"writer unavailable\".to_string())?;\n+    rx.await\n+        .map_err(|_| \"writer dropped\".to_string())?\n+        .map_err(|(msg, hint)| hint.map_or(msg.clone(), |h| format!(\"{msg}: {h}\")))?;\n+    Ok(children.len())\n+}\n+\n+fn extract_fence<'a>(body: &'a str, lang: &str) -> Option<&'a str> {\n+    let b = body.trim();\n+    let prefix = format!(\"```{lang}\");\n+    let rest = b.strip_prefix(prefix.as_str())?;\n+    let rest = rest\n+        .strip_prefix('\\n')\n+        .or_else(|| rest.strip_prefix('\\r'))\n+        .unwrap_or(rest);\n+    let end = rest.find(\"\\n```\")?;\n+    Some(rest[..end].trim())\n+}\n+\n+fn parse_github_import_from_body(body: &str) -> Option {\n+    let trimmed = body.trim();\n+    if let Some(json) = extract_fence(trimmed, \"slug-github-card\") {\n+        let c: GithubImportCard = serde_json::from_str(json).ok()?;\n+        return (c.v == 1 && (c.schema.is_empty() || c.schema == SLUG_GITHUB_SCHEMA)).then_some(c);\n+    }\n+    if let Some(json) = extract_fence(trimmed, \"json\") {\n+        if let Ok(c) = serde_json::from_str::(json) {\n+            if c.v == 1\n+                && (c.schema == SLUG_GITHUB_SCHEMA\n+                    || (c.schema.is_empty() && c.url.contains(\"github.com\")))\n+            {\n+                return Some(c);\n+            }\n+        }\n+    }\n+    if trimmed.starts_with('{') {\n+        let c: GithubImportCard = serde_json::from_str(trimmed).ok()?;\n+        return (c.v == 1\n+            && (c.schema == SLUG_GITHUB_SCHEMA\n+                || (c.schema.is_empty() && c.url.contains(\"github.com\"))))\n+        .then_some(c);\n+    }\n+    None\n+}\n+\n+fn kind_badge(kind: &GithubImportKind) -> &'static str {\n+    match kind {\n+        GithubImportKind::Repo => \"GitHub · repository\",\n+        GithubImportKind::RepoSection => \"GitHub · tree\",\n+        GithubImportKind::Issue => \"GitHub · issue\",\n+        GithubImportKind::Pull => \"GitHub · pull request\",\n+        GithubImportKind::Commit => \"GitHub · commit\",\n+        GithubImportKind::Release => \"GitHub · release\",\n+    }\n+}\n+\n+fn render_github_card(card: &GithubImportCard) -> maud::Markup {\n+    html! {\n+        article.github-import-card {\n+            header.github-import-card__hdr {\n+                span class=\"github-import-card__badge\" { (kind_badge(&card.kind)) }\n+                h3.github-import-card__title { (card.headline.as_str()) }\n+            }\n+            @if !card.sublines.is_empty() {\n+                ul.github-import-card__meta {\n+                    @for line in &card.sublines {\n+                        li { (line.as_str()) }\n+                    }\n+                }\n+            }\n+            @if let Some(ex) = &card.excerpt {\n+                div.github-import-card__excerpt {\n+                    @for block in ex.split(\"\\n\\n\") {\n+                        @if !block.trim().is_empty() {\n+                            p { (block) }\n+                        }\n+                    }\n+                }\n+            }\n+            p.github-import-card__link {\n+                a href=(card.url.as_str()) rel=\"noopener noreferrer\" target=\"_blank\" {\n+                    \"Open on GitHub\"\n+                }\n+            }\n+        }\n+    }\n+}\n+\n+/// Rich HTML for bodies that contain a [`GithubImportCard`] fence (or equivalent JSON).\n+pub fn try_render_github_import_markup(raw: &str) -> Option {\n+    let card = parse_github_import_from_body(raw)?;\n+    Some(render_github_card(&card))\n+}\n+\n+#[async_trait]\n+impl ExternalResolver for GitHubResolver {\n+    fn domain_match(&self) -> &'static str {\n+        \"github.com\"\n+    }\n+\n+    fn normalize(&self, path: &str) -> String {\n+        path.to_string()\n+    }\n+\n+    async fn fetch_body(&self, _item: &ItemId) -> Result {\n+        Err(\"GitHub fetch_body not implemented\".to_string())\n+    }\n+}\n+\n+#[cfg(test)]\n+mod tests {\n+    use super::*;\n+\n+    #[test]\n+    fn github_segments_parse_normalized_url() {\n+        let item = ItemId::parse(\"https://github.com/Sortersocial/Slug/issues\").unwrap();\n+        assert_eq!(\n+            github_segments(&item),\n+            Some(vec![\n+                \"sortersocial\".to_string(),\n+                \"slug\".to_string(),\n+                \"issues\".to_string()\n+            ])\n+        );\n+    }\n+\n+    #[test]\n+    fn repo_sections_are_direct_children() {\n+        let sections = github_repo_sections(\"sortersocial\", \"slug\");\n+        let urls: Vec = sections.into_iter().map(|c| c.url).collect();\n+        assert!(urls.contains(&\"https://github.com/sortersocial/slug/issues\".to_string()));\n+        assert!(urls.contains(&\"https://github.com/sortersocial/slug/pulls\".to_string()));\n+    }\n+\n+    #[test]\n+    fn children_to_dsl_wraps_slug_github_card() {\n+        let dsl = children_to_dsl(&[ResolvedChild {\n+            url: \"https://github.com/o/r/issues/1\".into(),\n+            title: \"#1 title\".into(),\n+            card: GithubImportCard::new(\n+                GithubImportKind::Issue,\n+                \"https://github.com/o/r/issues/1\".into(),\n+                \"#1 title\".into(),\n+            ),\n+        }]);\n+        assert!(dsl.contains(\"https://github.com/o/r/issues/1\"));\n+        assert!(dsl.contains(\"```slug-github-card\"));\n+        assert!(dsl.contains(\"\\\"schema\\\":\\\"slug_github_import\\\"\"));\n+    }\n+\n+    #[test]\n+    fn parse_accepts_slug_github_fence() {\n+        let card = GithubImportCard::new(\n+            GithubImportKind::Repo,\n+            \"https://github.com/o/r\".into(),\n+            \"o/r\".into(),\n+        );\n+        let body = format!(\"```slug-github-card\\n{}\\n```\\n\", serde_json::to_string(&card).unwrap());\n+        let parsed = parse_github_import_from_body(&body).expect(\"parses\");\n+        assert_eq!(parsed, card);\n+    }\n+\n+    #[test]\n+    fn parse_accepts_schema_json_fence() {\n+        let card = GithubImportCard::new(\n+            GithubImportKind::Issue,\n+            \"https://github.com/o/r/issues/2\".into(),\n+            \"#2 hi\".into(),\n+        );\n+        let json = serde_json::to_string(&card).unwrap();\n+        let body = format!(\"```json\\n{json}\\n```\");\n+        let parsed = parse_github_import_from_body(&body).expect(\"parses json fence\");\n+        assert_eq!(parsed.headline, \"#2 hi\");\n+    }\n+\n+    #[test]\n+    fn issue_card_includes_author_and_excerpt() {\n+        let issue = serde_json::json!({\n+            \"number\": 12,\n+            \"title\": \"Render children\",\n+            \"state\": \"open\",\n+            \"html_url\": \"https://github.com/o/r/issues/12\",\n+            \"user\": {\"login\": \"octo\"},\n+            \"labels\": [{\"name\": \"bug\"}],\n+            \"body\": \"The issue body.\"\n+        });\n+        let card = card_for_issue(\n+            &issue,\n+            \"https://github.com/o/r/issues/12\",\n+            GithubImportKind::Issue,\n+        );\n+        assert!(card.sublines.iter().any(|l| l.contains(\"@octo\")));\n+        assert_eq!(card.excerpt.as_deref(), Some(\"The issue body.\").as_deref());\n+    }\n+}\ndiff --git a/server/src/resolvers/mod.rs b/server/src/resolvers/mod.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..3e4caad081acdd2f89cba9f661de43996d6470f3\n--- /dev/null\n+++ b/server/src/resolvers/mod.rs\n@@ -0,0 +1,18 @@\n+//! Domain resolvers (GitHub, …) and matching HTML renderers for imported item bodies.\n+//!\n+//! Resolver output is ingested as DSL; bodies may embed a `slug-github-card` fenced JSON\n+//! envelope that [`crate::html::render_item_body_in_scope`] renders instead of a raw `
    `.\n+\n+pub mod github;\n+pub mod default_external;\n+\n+pub use default_external::DefaultExternalResolver;\n+pub use github::{\n+    resolve_github_children, try_render_github_import_markup, ExternalResolver, GitHubResolver,\n+    GithubImportCard, GithubImportKind, ResolvedChild,\n+};\n+\n+/// Extension point: add more `try_render_*` calls here as new resolvers ship.\n+pub fn try_render_resolver_item_body(raw: &str) -> Option {\n+    github::try_render_github_import_markup(raw)\n+}\ndiff --git a/server/src/scope_rank.rs b/server/src/scope_rank.rs\nindex 06c560b8eff09b34896d3935d3917fb28f602bc6..2361b2be5ae6b8e1813b6b7ebd5bbf317429b6ad 100644\n--- a/server/src/scope_rank.rs\n+++ b/server/src/scope_rank.rs\n@@ -162,6 +162,45 @@ pub fn build_children_rankings(content: &ContentState, parent: &ItemId) -> Child\n     build_rankings_for_item_set(content, &items)\n }\n \n+/// Host-only `https://…` roots for the external garden index (`/-/`).\n+///\n+/// Includes every `https://host` ancestor of any [`ItemId::Web`] item that appears in\n+/// `content.items`, as a parent key in `item_children`, or as a child in `item_children`\n+/// (so implied “ghost” parents created only via [`ReducerState::add_child_edge`] still show up).\n+pub fn external_root_host_items(content: &ContentState) -> Vec {\n+    let mut hosts: HashSet = HashSet::new();\n+\n+    let mut consider = |id: ItemId| {\n+        let id = id.normalized_storage();\n+        if !matches!(&id, ItemId::Web(_)) {\n+            return;\n+        }\n+        let mut cur = id;\n+        while let Some(p) = cur.parent() {\n+            cur = p.normalized_storage();\n+        }\n+        if matches!(cur, ItemId::Web(_)) {\n+            hosts.insert(cur);\n+        }\n+    };\n+\n+    for it in &content.items {\n+        consider(it.clone());\n+    }\n+    for parent in content.item_children.keys() {\n+        consider(parent.clone());\n+    }\n+    for set in content.item_children.values() {\n+        for ch in set {\n+            consider(ch.clone());\n+        }\n+    }\n+\n+    let mut out: Vec = hosts.into_iter().collect();\n+    out.sort();\n+    out\n+}\n+\n pub fn is_pair_voted_in_group(group: &GroupState, a: &ItemId, b: &ItemId) -> bool {\n     let Some(&a_idx) = group.item_to_idx.get(a) else {\n         return false;\n@@ -305,4 +344,29 @@ mod tests {\n         assert!(next.0 == c || next.1 == c);\n         assert_ne!(canonical_pair(&next.0, &next.1), canonical_pair(&a, &b));\n     }\n+\n+    #[test]\n+    fn external_root_hosts_include_ghost_chain_hosts() {\n+        use crate::reducer::ContentState;\n+        let gh = ItemId::parse(\"https://github.com\").unwrap();\n+        let org = ItemId::parse(\"https://github.com/org\").unwrap();\n+        let repo = ItemId::parse(\"https://github.com/org/rep\").unwrap();\n+        let mut item_children: HashMap> = HashMap::new();\n+        item_children.entry(gh.clone()).or_default().insert(org.clone());\n+        item_children.entry(org.clone()).or_default().insert(repo.clone());\n+        let mut items = HashSet::new();\n+        items.insert(repo.clone());\n+        let content = ContentState {\n+            ranking_group: crate::reducer::GroupState::new(),\n+            items,\n+            item_bodies: HashMap::new(),\n+            item_children,\n+            item_votes: HashMap::new(),\n+            item_snippets: HashMap::new(),\n+            item_threads: HashMap::new(),\n+            rank_history: HashMap::new(),\n+        };\n+        let roots = external_root_host_items(&content);\n+        assert_eq!(roots, vec![gh]);\n+    }\n }\ndiff --git a/server/src/state.rs b/server/src/state.rs\nindex 48298e2e66456268d23a6462536eb32bfeb5f29b..648ab5304764a329fcabbbbcd3782b94e3e005a8 100644\n--- a/server/src/state.rs\n+++ b/server/src/state.rs\n@@ -4,7 +4,7 @@ use std::sync::Arc;\n use tokio::sync::{broadcast, mpsc, RwLock};\n \n use crate::{\n-    event_log::EventLog, events::ThreadCapability, external_resolver::GitHubResolver,\n+    event_log::EventLog, events::ThreadCapability, resolvers::GitHubResolver,\n     reducer::ReducerState, write_cmd::WriteCmd,\n };\n \ndiff --git a/server/static/theme_default.css b/server/static/theme_default.css\nindex 184e11a590e7019773f7f0abfa41e79161556c71..7ea5f502f9b0b6341ce56d60ae883479070760d6 100644\n--- a/server/static/theme_default.css\n+++ b/server/static/theme_default.css\n@@ -1023,6 +1023,23 @@ body.view-vote-compare .vote-compare-shell > h2 {\n   line-height: 1.35;\n   padding: 8px 10px;\n }\n+.vote-compare-item-body .item-body-rich {\n+  min-width: 0;\n+  text-align: start;\n+}\n+.vote-compare-right .vote-compare-item-body .item-body-rich {\n+  display: flex;\n+  flex-direction: column;\n+  align-items: flex-end;\n+}\n+.vote-compare-item-body .item-body-rich article.github-import-card {\n+  box-sizing: border-box;\n+  width: 100%;\n+  max-width: min(100%, 420px);\n+}\n+.vote-compare-right .vote-compare-item-body .item-body-rich article.github-import-card {\n+  margin-left: auto;\n+}\n .vote-compare-item-body-empty {\n   font-size: 12px;\n   margin: 8px 0 0;\n@@ -1675,3 +1692,47 @@ body.view-ontology-light .rank-history-cause {\n body.view-ontology-light .rank-history-vote {\n   margin-top: 6px;\n }\n+\n+/* GitHub resolver import cards (rich bodies on -/ garden + vote compare) */\n+article.github-import-card {\n+  border: 1px solid var(--lo);\n+  background: var(--g2);\n+  border-radius: 6px;\n+  padding: 12px 14px;\n+  margin: 8px 0;\n+  max-width: 100%;\n+}\n+.github-import-card__hdr {\n+  margin-bottom: 6px;\n+}\n+.github-import-card__badge {\n+  display: block;\n+  font-size: 0.78em;\n+  color: var(--muted);\n+  margin-bottom: 4px;\n+}\n+.github-import-card__title {\n+  margin: 0;\n+  font-size: 1.05em;\n+  font-weight: 600;\n+}\n+ul.github-import-card__meta {\n+  margin: 8px 0 0 1.1em;\n+  padding: 0;\n+  font-size: 0.9em;\n+}\n+.github-import-card__meta li {\n+  margin: 2px 0;\n+}\n+.github-import-card__excerpt {\n+  margin-top: 10px;\n+  font-size: 0.92em;\n+  white-space: pre-wrap;\n+}\n+.github-import-card__excerpt p {\n+  margin: 6px 0;\n+}\n+.github-import-card__link {\n+  margin-top: 12px;\n+  font-size: 0.95em;\n+}\ndiff --git a/server/static/theme_retro.css b/server/static/theme_retro.css\nindex 6747f59eb1ec5c335029fe92d4e5c55b3125a210..d366be6fc8e8fcbc8122b8954b1e356ee36e6bc9 100644\n--- a/server/static/theme_retro.css\n+++ b/server/static/theme_retro.css\n@@ -278,3 +278,20 @@ body.view-ontology .vote-compare-item-body pre {\n   border: 1px solid #ccc;\n   padding: 0.5rem 0.65rem;\n }\n+body.view-ontology .vote-compare-item-body .item-body-rich {\n+  min-width: 0;\n+  text-align: start;\n+}\n+body.view-ontology .vote-compare-right .vote-compare-item-body .item-body-rich {\n+  display: flex;\n+  flex-direction: column;\n+  align-items: flex-end;\n+}\n+body.view-ontology .vote-compare-item-body .item-body-rich article.github-import-card {\n+  box-sizing: border-box;\n+  width: 100%;\n+  max-width: min(100%, 420px);\n+}\n+body.view-ontology .vote-compare-right .vote-compare-item-body .item-body-rich article.github-import-card {\n+  margin-left: auto;\n+}\ndiff --git a/server/static/theme_retro_craft.css b/server/static/theme_retro_craft.css\nindex 55d984a6dd70ebeadeca7baef86b844955f1d78c..d5bc384437f05f001924630947457d416772e950 100644\n--- a/server/static/theme_retro_craft.css\n+++ b/server/static/theme_retro_craft.css\n@@ -907,6 +907,23 @@ body.view-ontology .vote-compare-item-body pre {\n   line-height: 1.35;\n   padding: 0.55rem 0.65rem;\n }\n+body.view-ontology .vote-compare-item-body .item-body-rich {\n+  min-width: 0;\n+  text-align: start;\n+}\n+body.view-ontology .vote-compare-right .vote-compare-item-body .item-body-rich {\n+  display: flex;\n+  flex-direction: column;\n+  align-items: flex-end;\n+}\n+body.view-ontology .vote-compare-item-body .item-body-rich article.github-import-card {\n+  box-sizing: border-box;\n+  width: 100%;\n+  max-width: min(100%, 420px);\n+}\n+body.view-ontology .vote-compare-right .vote-compare-item-body .item-body-rich article.github-import-card {\n+  margin-left: auto;\n+}\n body.view-ontology .vote-compare-item-body-empty {\n   font-size: 0.78rem;\n   margin: 0.45rem 0 0;\ndiff --git a/server/tests/integration.rs b/server/tests/integration.rs\nindex fb0b9335440181d4d50104d37926b0b2eeeb602a..d979000292b6a39db7c7b54f2b804adb9cd39369 100644\n--- a/server/tests/integration.rs\n+++ b/server/tests/integration.rs\n@@ -3,7 +3,7 @@ use sha2::{Digest, Sha256};\n use slug_types::{room_route_segment, ItemId};\n use slugsocial_server::{\n     event_log::EventLog,\n-    events::{Event, TokenIssued, UserRegistered},\n+    events::{Event, Ingest, TokenIssued, UserRegistered},\n     middleware::canonical_view_url,\n     spawn_writer_actor_for_test,\n     state::{AppConfig, AppState},\n@@ -1614,6 +1614,71 @@ async fn test_view_counts_increment_and_display() {\n     );\n }\n \n+#[tokio::test]\n+async fn test_vote_compare_renders_github_import_cards() {\n+    let (addr, _tmp, _log, state, _handle) = create_test_server_with_state().await;\n+    let client = reqwest::Client::new();\n+\n+    let raw = \"@00000000-0000-0000-0000-000000000000:test:local/test\\n\\\n+https://github.com/ghvotehi/a/issues/9 {\\n\\\n+```slug-github-card\\n\\\n+{\\\"v\\\":1,\\\"schema\\\":\\\"slug_github_import\\\",\\\"kind\\\":\\\"issue\\\",\\\"url\\\":\\\"https://github.com/ghvotehi/a/issues/9\\\",\\\"headline\\\":\\\"#9 Left corner\\\",\\\"sublines\\\":[\\\"State: open\\\"]}\\n\\\n+```\\n\\\n+}\\n\\\n+\\n\\\n+https://github.com/ghvotehi/a/issues/10 {\\n\\\n+```slug-github-card\\n\\\n+{\\\"v\\\":1,\\\"schema\\\":\\\"slug_github_import\\\",\\\"kind\\\":\\\"issue\\\",\\\"url\\\":\\\"https://github.com/ghvotehi/a/issues/10\\\",\\\"headline\\\":\\\"#10 Right corner\\\",\\\"sublines\\\":[\\\"State: open\\\"]}\\n\\\n+```\\n\\\n+}\\n\";\n+\n+    {\n+        let mut w = state.reduced.write().await;\n+        w.apply_event(Event::Ingest(Ingest {\n+            ts: 10,\n+            id: \"ing-vote-github-cards\".to_string(),\n+            raw: raw.to_string(),\n+            principal: \"testuser\".to_string(),\n+            delegate: Some(\n+                \"00000000-0000-0000-0000-000000000000:test:local/test\".to_string(),\n+            ),\n+            room_id: \"public\".to_string(),\n+            thread_tag: \"gh-vote-cards\".to_string(),\n+        }));\n+    }\n+\n+    let left = ItemId::parse(\"https://github.com/ghvotehi/a/issues/9\")\n+        .unwrap()\n+        .normalized_storage()\n+        .to_storage_string();\n+    let right = ItemId::parse(\"https://github.com/ghvotehi/a/issues/10\")\n+        .unwrap()\n+        .normalized_storage()\n+        .to_storage_string();\n+    let q = format!(\n+        \"/vote/compare?left={}&right={}\",\n+        urlencoding::encode(&left),\n+        urlencoding::encode(&right)\n+    );\n+    let resp = client\n+        .get(format!(\"http://{addr}{q}\"))\n+        .send()\n+        .await\n+        .unwrap();\n+    assert!(resp.status().is_success(), \"{}\", resp.status());\n+    let body = resp.text().await.unwrap();\n+    let n_cards = body.matches(\"github-import-card\").count();\n+    assert!(\n+        n_cards >= 2,\n+        \"expected two GitHub import cards on vote compare, count={n_cards}, snippet={}\",\n+        body.chars().take(1500).collect::()\n+    );\n+    assert!(body.contains(\"vote-compare-left\"));\n+    assert!(body.contains(\"vote-compare-right\"));\n+    assert!(body.contains(\"#9 Left corner\"));\n+    assert!(body.contains(\"#10 Right corner\"));\n+}\n+\n #[tokio::test]\n async fn test_search_handles_multibyte_unicode() {\n     // HTML search pages are offline during the auth-v3 refactor.\n","role":"user"}],"model":"openai/gpt-5.2-chat"}