diff --git a/agents.md b/agents.md index c12c7dd0bb81dbf97f2ce5b9427b1af5ca98eafc..94651247558a3edd16dc057fb596dc19c243846c 100644 --- a/agents.md +++ b/agents.md @@ -76,6 +76,8 @@ Strict **CSP** that blocks `eval` would break the current app. Other projects ma - **Aspect sub-scopes:** A `:slug` / `:slug {prompt}` / bare `:` statement is parse-derived from ingest text (no event-schema change, no new write path). Votes under an aspect go to a ranking group keyed `(scope_item, aspect)` where `scope_item` is a shared active-membership scope of both vote items; the canonical `ranking_group` and `rank_position_cache` stay aspect-free. Garden parent/item pages (`render_scope_view`, public `~/`) and the `/try` editor preview list aspect sections **below** the canonical ranking when that scope has aspect votes (heading `:{slug}`, optional prompt). No `?aspect=` routes or default-aspect redirects. CLI `garden children --aspect` / `garden rank --aspect` and MCP `get_rank.aspect` are opt-in reads via `GetGardenRank.aspect`. Prompts live on `ContentState.aspect_prompts` per `(room scope, slug)`. `parent_path` in those reads resolves to its leaf item (`~/x/luke` → `~luke`). +- **Bare-tilde items default to the root electorate:** at ingest, any tilde item with no active membership gets an idempotent sugar claim `item <: root` (weight 1) in `apply_ingest_to_content` (`reducer.rs`) — items are never invisible to scope pages; previously, bare `~x` items floated (votable, page-having, but absent from every scope listing). Scoped items are never re-planted (the default applies only when `scopes_of` is empty), and nested sugar keeps its shape (`~/a/b` → `b <: a <: root` only). Containment may target the root explicitly: `{ why } ~x <: ~` (both `~` and `~/` spellings parse; the write-path validator treats the root as always defined). An item bordered out of every scope falls back to root; an explicit root border holds it out only while border weight ≥ sugar weight. Rank-history entries with `scope_rank == 0` render `unscoped` (scope_total 0) / `unranked of N` instead of `#0 of N` in the web vote-history block and the CLI printer. (Edge investigation: `ideas/bare-tilde-root-scope-edge.md`.) + - **Garden score-history replay (`?v=history`):** Scope pages carry an always-visible `ont-history-link` bar above the ranked children table (`score_history_link_panel` in `server/src/html/garden/replay.rs`): with sufficient history (≥2 members and ≥2 member↔member vote events) it links **"open the replay →"**; otherwise an empty state ("score history draws itself once two or more members carry votes") plus a vote-on-children link when ≥2 children exist. Childless leaf pages render no bar. The replay is a **query-param view of the scope page** (branched in `render_scope_view`): `?v=history` serves a one-HTML-file React app — the sorter-proof "Ranking Replay 2" stack verbatim (CDN React 18 UMD + babel-standalone + Chart.js + React Query, inline JSX; autoplay/scrub/speed controls, hue-rotated `tension: 0.4` lines, current-rankings + unsorted legend, clickable comparison matrix with reasoning dialog, 5s polling) bound to a fixed data URL via `window.SLUG_REPLAY` — and `?v=history.json` serves the payload `{criteria, items, history[], final_matrix}` built from `ContentState`: per-event snapshots **re-solve the scope's member↔member vote graph through the reducer's own kernel** (`GroupState::apply_vote` + `rank_partition`), one honest solve per vote event (cap 240 events / 64 members); comparisons and matrix cells quote vote reasonings from `item_votes` (matrix `weight` = pairwise win share in percent). Bar CSS lives in the `Garden score-history replay link` block of every theme. - **`?by=` garden fork:** Both the flat scope page and the replay accept a voter filter (`voter_from_uri` in `server/src/html/garden/replay.rs`; matches the vote's human principal or full delegate string). The flat page re-solves its ranked children from a graph holding only that voter's canonical votes (`filtered_group_by_voter` + `build_children_rankings_in_group` in `server/src/scope_rank.rs`) and shows a "filtered: only votes by X · show all" notice; the replay payload carries the filter through its votes and exposes it as the `voter` field, and the link bar preserves it into the `?v=history&by=` URL. Aspect sections and the rest of the page stay canonical. diff --git a/cli/src/main.rs b/cli/src/main.rs index 8d4f682f8553c04970dedb2a1a55653135006182..c9e77cf97a116e6bbb07755bb3749c64e55f55b7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -526,13 +526,25 @@ fn print_rank_history_response(resp: &slug_types::RankHistoryResponse) { std::cmp::Ordering::Greater => format!(" ↓{}", e.global_rank_delta), std::cmp::Ordering::Equal => String::new(), }; + let scope_str = if e.scope_rank == 0 && e.scope_total == 0 { + "unscoped".to_string() + } else if e.scope_rank == 0 { + format!("unranked of {}", e.scope_total) + } else { + format!("#{} of {}", e.scope_rank, e.scope_total) + }; + let global_str = if e.global_rank == 0 && e.global_total == 0 { + "ungrouped".to_string() + } else if e.global_rank == 0 { + format!("unranked of {}", e.global_total) + } else { + format!("#{} of {}", e.global_rank, e.global_total) + }; println!( - "\n #{} of {} among siblings{} #{} of {} globally{} {} {} post #{}{}", - e.scope_rank, - e.scope_total, + "\n {} among siblings{} {} globally{} {} {} post #{}{}", + scope_str, scope_delta, - e.global_rank, - e.global_total, + global_str, global_delta, slug_types::timeago::timeago(now_ms, e.ts), e.thread, diff --git a/ideas/bare-tilde-root-scope-edge.md b/ideas/bare-tilde-root-scope-edge.md new file mode 100644 index 0000000000000000000000000000000000000000..e565dbe83712424f235b82c60472e7e99758f87c --- /dev/null +++ b/ideas/bare-tilde-root-scope-edge.md @@ -0,0 +1,77 @@ +# The bare-tilde / root-scope edge (investigated 2026-10-05, reproduced on production) + +## The edge + +Defining an item with bare tilde — `~x { body }` — creates a **floating +item**: it exists, is votable, accumulates rank-history, gets a working item +page (`/~/x`, `/r//~/x`), and appears in the flat global ranking +(`garden rank`, `GetGardenRank` with no parent). But it belongs to **no +electorate** — it is invisible in every scope listing: the root garden page +(`/~`, `/r//~`), pair pools, children tables, and vote-compare pools. + +The UI confesses it: a floating item's vote-history block renders +`#0 of 0` — globally ranked, scope-ranked nowhere. + +Contrast: `~/x { body }` (path sugar) emits `x <: root` as a sugar edge +(weight exactly 1), making the item a root-scope member, visible in the root +listing immediately (unranked until voted). + +## Why (mechanism) + +- DSL: `~/a/b` desugars to sugar containment claims along the path + (`b <: a <: root`); bare `~x` desugars to no containment at all. +- Reducer: `add_child_edge` (`reducer.rs:832`) returns immediately for tilde + items (`if item.tilde_tail().is_some() { return; }`) — it only ghosts + parents for web items (the `/-/` external index). Item statements and + vote-item creation call it, so nothing ever plants a tilde item anywhere. +- Scope views render `members_of(scope)`; a floating item is a member of + nothing. +- The flat global ranking group is containment-independent — hence the + CLI/API showing what the pages hide. + +## The trap is one-way (no DSL escape hatch) + +`~x <: ~/` is a **parse error** ("incomplete containment claim") — the root +is not a valid containment target. A floating item cannot be claimed into +the root electorate explicitly. (A later post containing `~/x` sugar would +plant it — sugar claims accumulate — but authors don't know that, and +nothing tells them.) + +## Reproduction (production, room `fx7gmyd/eros`, 2026-10-05) + +1. Post `~tape { … }`, `~wave { … }`, `{ why } ~tape 2:1 ~wave`. +2. `garden rank` (CLI) shows both, 0.667/0.333. Item pages render fully. +3. Root garden page `/r/fx7gmyderos/~`: neither listed; "no voted pairs yet + in this scope". +4. Post `~/planted { … }`: root page immediately lists `~/planted` + (unranked). tape/wave still absent. +5. `/r//~/wave` page: body, vote history, `#0 of 0`. +6. Room pages 404 for non-members (auth-gating, correct). + +## Fix options + +**A. Semantic — implicit root sugar for bare tilde items at ingest** (weight +1, same as path sugar). Root becomes the default electorate, matching the +user mental model and the docs' own language ("GET /~ is the root-electorate +index"). Replay recomputes everything, so historical floating items (public +garden included — e.g. bare scope items like `~fast-food`) join the root +listing. Blast radius: root page and root pair pools grow. + +**B. Presentational — scope views union a "floating items" section.** +Root (and any scope view?) list unscoped items in a separate section with a +placement CTA. No replay/semantics change; keeps "floating" as a first-class +draft state. Smaller blast radius, but two listing semantics to maintain. + +**C. Parser — allow `~x <: ~/` as an explicit root claim.** Fixes the rescue +path; insufficient alone (nothing tells authors they're floating). + +Regardless of A/B/C: the `#0 of 0` rendering on vote-history blocks should +say something kinder for unscoped items ("unscoped — claim a home with +`{ why } ~/x <: ~/parent`"). + +## Recommendation + +**A + C**, with B's floating-section as the fallback if replay-time growth +of the public root listing is judged undesirable. The default should match +the mental model: the garden is the root electorate, and a thing in the +garden should be *in* the garden. diff --git a/server/src/api/validate.rs b/server/src/api/validate.rs index cc65237d9e327848a82747db808940ce5a0ece65..fa6db6e3ec25be95d97ad7ccabe1afe62a7310b6 100644 --- a/server/src/api/validate.rs +++ b/server/src/api/validate.rs @@ -113,6 +113,10 @@ pub fn validate_ingest_document( )); } }; + // The ontology root is a system item: always defined, no body needed. + if it == crate::path_types::ItemId::ontology_root() { + continue; + } if !defined_in_doc.contains(&it) && !item_exists(&it) { return Err(( StatusCode::BAD_REQUEST, diff --git a/server/src/dsl.rs b/server/src/dsl.rs index 8a9697ae1e9cafbeba7c7be40eb339e51540733c..8241b7b2f51b67a184070ceb6707922f93701355 100644 --- a/server/src/dsl.rs +++ b/server/src/dsl.rs @@ -581,6 +581,15 @@ fn parse_item_name_at_with_mode( return None; } j += 1; + // Bare root token: `~` (or `~/` with no path) is the ontology root, so + // containment can claim it explicitly (`{ why } ~child <: ~`). The wire + // layer already canonicalizes both spellings to the root. + if j >= bytes.len() || is_ws_byte(bytes[j]) { + return Some(("~".to_string(), j)); + } + if bytes[j] == b'/' && (j + 1 >= bytes.len() || is_ws_byte(bytes[j + 1])) { + return Some(("~/".to_string(), j + 1)); + } if j < bytes.len() && bytes[j] == b'/' { j += 1; let start = j; @@ -1941,6 +1950,33 @@ mod tests { ); } + #[test] + fn parse_containment_claim_can_target_root() { + // Bare `~` is the ontology root; the explicit claim needs a reason. + let doc = parse_full("{ home }\n~a <: ~").unwrap(); + assert!(matches!( + containments(&doc) + .iter() + .find(|s| matches!(s, Stmt::Containment { sugar: false, .. })), + Some(Stmt::Containment { + child, + parent, + border: false, + .. + }) if child == "~a" && (parent == "~" || parent == "~/") + )); + // `~/` spells the same target. + let doc2 = parse_full("{ home }\n~a <: ~/").unwrap(); + assert!(matches!( + containments(&doc2) + .iter() + .find(|s| matches!(s, Stmt::Containment { sugar: false, .. })), + Some(Stmt::Containment { + parent, .. + }) if parent == "~/" || parent == "~" + )); + } + #[test] fn parse_bare_tilde_token_item() { let doc = parse_full("~luke { a jedi }").unwrap(); diff --git a/server/src/html/garden/render.rs b/server/src/html/garden/render.rs index 5cff1492fa19ae1e8d53efc7b64036e2c45e854c..5ffe58cd89235246486f3bf4289a6a567a704bb2 100644 --- a/server/src/html/garden/render.rs +++ b/server/src/html/garden/render.rs @@ -265,7 +265,13 @@ pub(super) async fn render_scope_view( div class="rank-history-entry" { div class="rank-history-meta" title=(hover) { span class="rank-history-pos" { - (format!("#{} of {}{}", e.scope_rank, e.scope_total, delta_str)) + @if e.scope_rank == 0 && e.scope_total == 0 { + (format!("unscoped{}", delta_str)) + } @else if e.scope_rank == 0 { + (format!("unranked of {}{}", e.scope_total, delta_str)) + } @else { + (format!("#{} of {}{}", e.scope_rank, e.scope_total, delta_str)) + } } " · " span class="ts-recency" style=(ts_style.as_str()) { (ago) } diff --git a/server/src/html/garden/tests.rs b/server/src/html/garden/tests.rs index c89c3060b8dad9861b95d90f3aad2b5f505bc888..334341eea530e9df7ea3933b25335d9a3efe8ec4 100644 --- a/server/src/html/garden/tests.rs +++ b/server/src/html/garden/tests.rs @@ -693,7 +693,9 @@ fn item_page_scope_labels_prompt_and_lists_memberships() { let jedi = build_item_page_view_model(&reduced, &ScopeId::Public, "~/jedi", 1); assert!(jedi.is_scope, "jedi has an active member"); assert_eq!(jedi.body.as_deref(), Some("who is a jedi")); - assert!(jedi.memberships.is_empty()); + // Top-level items live in the root electorate (the bare-tilde default). + assert_eq!(jedi.memberships.len(), 1); + assert_eq!(jedi.memberships[0].parent, ItemId::parse("~").unwrap()); let luke = build_item_page_view_model(&reduced, &ScopeId::Public, "~/x/luke", 1); assert!(!luke.is_scope); @@ -744,7 +746,9 @@ fn item_page_renders_memberships_suspended_borders_and_journal() { ); apply_ingest(&mut reduced, 2, "{ out }\n~luke !<: ~jedi\n"); let suspended = build_item_page_view_model(&reduced, &ScopeId::Public, "~luke", 1); - assert!(suspended.memberships.is_empty()); + // Excommunicated from jedi, luke falls back to the root electorate. + assert_eq!(suspended.memberships.len(), 1); + assert_eq!(suspended.memberships[0].parent, ItemId::parse("~").unwrap()); assert_eq!(suspended.suspended_borders.len(), 1); assert_eq!( suspended.suspended_borders[0].status, @@ -760,7 +764,8 @@ fn item_page_renders_memberships_suspended_borders_and_journal() { apply_ingest(&mut reduced, 3, "{ still in }\n~luke <: ~jedi\n"); let breached = build_item_page_view_model(&reduced, &ScopeId::Public, "~luke", 1); - assert_eq!(breached.memberships.len(), 1); + // Reactivated jedi membership plus the root fallback. + assert_eq!(breached.memberships.len(), 2); assert_eq!(breached.fallen_journal.len(), 1); let html = item_relations_markup(&breached, &ThreadNav::public(), 10_000).into_string(); assert!( diff --git a/server/src/reducer.rs b/server/src/reducer.rs index dafb8e4ee704cdf0853e87411559958c4c40c0b8..aceb2ce6002b589b19ec412cbbd14c83fae18c90 100644 --- a/server/src/reducer.rs +++ b/server/src/reducer.rs @@ -1151,6 +1151,26 @@ impl ReducerState { } } + // Bare tilde items otherwise float in no electorate — invisible to + // every scope page, including the root garden. Default the root as + // home for anything with no active membership: the garden index is + // the root electorate, and a thing in the garden should be *in* the + // garden. Idempotent sugar (weight 1); never re-plants a scoped item. + let root = ItemId::ontology_root(); + for item in &ingest_items { + if item.tilde_tail().is_none() || !content.scopes_of(item).is_empty() { + continue; + } + content.apply_containment_claim( + item.clone(), + root.clone(), + false, + true, + ing.ts, + &ing.id, + ); + } + for item in ingest_items.iter() { nav!( content.item_snippets, @@ -1588,6 +1608,71 @@ mod rank_position_cache_tests { "c 2:1 a knocks a down one: {a_second:?}" ); } + + #[test] + fn bare_tilde_items_default_to_root_membership() { + let root = ItemId::ontology_root(); + let mut content = ContentState::default(); + + // Bare item definition: joins the root electorate. + ReducerState::apply_ingest_to_content( + &mut content, + &ingest("bare-def", "~ghost { floating no more }"), + ) + .unwrap(); + let ghost = ItemId::parse("~ghost").unwrap(); + assert!( + content.members_of(&root).contains(&ghost), + "bare item joins the root electorate" + ); + + // Bare vote: both endpoints join root and get real scope ranks. + ReducerState::apply_ingest_to_content( + &mut content, + &ingest("bare-vote", "{ tape over wave }\n~tape 2:1 ~wave"), + ) + .unwrap(); + for name in ["~tape", "~wave"] { + assert!( + content + .members_of(&root) + .contains(&ItemId::parse(name).unwrap()), + "{name} joins the root electorate" + ); + } + let tape_hist = &content.rank_history[&ItemId::parse("~tape").unwrap()]; + assert!( + tape_hist.last().unwrap().scope_rank >= 1, + "a real scope rank, not 0: {:?}", + tape_hist.last().unwrap() + ); + + // Path sugar keeps nesting: ~/sect/adept joins ~sect, not root. + ReducerState::apply_ingest_to_content( + &mut content, + &ingest("nested", "~/sect/adept { nested }"), + ) + .unwrap(); + let adept = ItemId::parse("~adept").unwrap(); + assert!( + !content.members_of(&root).contains(&adept), + "nested item stays out of root" + ); + assert!(content + .members_of(&root) + .contains(&ItemId::parse("~sect").unwrap())); + + // An already-scoped item referenced bare later is not re-planted. + ReducerState::apply_ingest_to_content( + &mut content, + &ingest("late-ref", "{ referencing the scoped one }\n~adept 2:1 ~tape"), + ) + .unwrap(); + assert!( + !content.members_of(&root).contains(&adept), + "scoped item is not re-planted into root" + ); + } } #[cfg(test)]