diff --git a/cli/GUIDE.sorter b/cli/GUIDE.sorter index 02ef324bc8af9657ef37ab643e73369cd49ecdf0..2e8ac901180c2163c71996404c9b1d675dde82aa 100644 --- a/cli/GUIDE.sorter +++ b/cli/GUIDE.sorter @@ -78,6 +78,16 @@ Two kinds of things. In .sorter documents you write #thread and ~name (or ~/path ~claude-sonnet ~/languages/rust - path sugar: item ~rust plus rust <: languages <: root +https://… - a web item: any normal URL is an item, no import step needed + https://example.com/widgets/acme { a widget page } + { reason } + https://example.com/widgets/acme 2:1 ~/tools/acme-alt + { reason } + https://example.com/widgets/acme <: ~tools + atomic - no path sugar; join scopes with an explicit, reasoned <: + host lowercased; www. is not collapsed - pick one spelling and keep it + dotted tildes like ~mcdonalds.com are rejected: write the full URL instead + These coexist. A thread is a session. An item is a thing that persists. Multiple threads can reference the same items. A scope is any item with active members; its body is the prompt for that role. Item definitions (attaches a description to an item): diff --git a/server/src/reducer.rs b/server/src/reducer.rs index e848c8b7fdacf39bd1fe6577d073ac0580f39bdc..dafb8e4ee704cdf0853e87411559958c4c40c0b8 100644 --- a/server/src/reducer.rs +++ b/server/src/reducer.rs @@ -1176,12 +1176,15 @@ impl ReducerState { let (before_scope, before_global, _) = before.get(item).copied().unwrap_or((0, 0, 0.0)); let prev = content.rank_history.get(item).and_then(|v| v.last()); - let scope_delta = if prev.is_none() { + // Entering from unranked (before == 0) is an arrival, not a + // drop: `after - 0` would render nonsense like "#1 (↓1)". + // Zero it, matching first-appearance semantics. + let scope_delta = if prev.is_none() || before_scope == 0 { 0 } else { after_scope as i32 - before_scope as i32 }; - let global_delta = if prev.is_none() { + let global_delta = if prev.is_none() || before_global == 0 { 0 } else { after_global as i32 - before_global as i32 @@ -1552,6 +1555,39 @@ mod rank_position_cache_tests { ); assert_eq!(content.rank_history[&ItemId::parse("~b").unwrap()].len(), 2); } + + #[test] + fn entrance_from_unranked_reports_zero_delta() { + let mut content = ContentState::default(); + ReducerState::apply_ingest_to_content( + &mut content, + &ingest( + "first", + "~/memo/a { a }\n~/memo/b { b }\n{ a wins }\n~/memo/a 2:1 ~/memo/b", + ), + ) + .unwrap(); + ReducerState::apply_ingest_to_content( + &mut content, + &ingest("second", "{ c arrives }\n~/memo/c 2:1 ~/memo/a"), + ) + .unwrap(); + + // c was unranked before this ingest: its arrival is not a "↓" drop. + let c_hist = &content.rank_history[&ItemId::parse("~c").unwrap()]; + let entrance = c_hist.last().unwrap(); + assert_eq!(entrance.scope_rank, 1, "c takes the top of the scope"); + assert_eq!(entrance.scope_rank_delta, 0, "arrival is not a drop"); + assert_eq!(entrance.global_rank_delta, 0); + + // An item ranked on both sides still reports real movement. + let a_hist = &content.rank_history[&ItemId::parse("~a").unwrap()]; + let a_second = a_hist.last().unwrap(); + assert_eq!( + a_second.scope_rank_delta, 1, + "c 2:1 a knocks a down one: {a_second:?}" + ); + } } #[cfg(test)] diff --git a/types/src/lib.rs b/types/src/lib.rs index d84a33538dfef2c748716566fd8ac110b5b5abbb..f0ebf477451b300e83a96a1249064ec42c21e775 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -745,13 +745,15 @@ pub struct RankHistoryRow { pub ts: i64, /// 1-indexed rank within the item's parent scope after this ingest. 0 = unranked. pub scope_rank: usize, - /// scope_rank delta vs prior entry (after - before; 0 on first appearance). + /// scope_rank delta vs prior entry (after - before; 0 on first appearance + /// and when entering from unranked). pub scope_rank_delta: i32, /// Total items in scope at time of this ingest. pub scope_total: usize, /// 1-indexed rank globally across all items after this ingest. 0 = not in ranking group. pub global_rank: usize, - /// global_rank delta vs prior entry (after - before; 0 on first appearance). + /// global_rank delta vs prior entry (after - before; 0 on first appearance + /// and when entering from unranked). pub global_rank_delta: i32, /// Total items in the global ranking group at time of this ingest. pub global_total: usize,