~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

A feed tile's check for newer posts sees past a pinned one

Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:workspace/newer-past-pins
crates/hud-core/src/tools.rs+50−10
@@ -1932,13 +1932,13 @@ impl Hud {
)
.await
.unwrap_or_else(|| json_ui(&structured));
// What tells something newer came asks for the newest item alone,
// where the method takes a limit (as small as its lexicon allows).
let limit = &def["parameters"]["properties"]["limit"];
if let Some(args) = ui.pointer_mut("/latest/call/args")
&& limit["type"] == "integer"
{
args["params"]["limit"] = limit["minimum"].as_u64().unwrap_or(1).max(1).into();
// What tells something newer came asks for the newest items alone,
// where the method takes a limit (`peek_limit`).
if let Some(args) = ui.pointer_mut("/latest/call/args") {
let own = args["params"]["limit"].as_u64();
if let Some(limit) = peek_limit(&def["parameters"]["properties"]["limit"], own) {
args["params"]["limit"] = limit.into();
}
}
Ok(Output {
text,
@@ -2111,9 +2111,9 @@ fn query_ui(
/// How to tell something newer came than a page of a query's items, where
/// its view names each one's key: the call again with no cursor (its
/// `limit` made 1 by `query`, where the method takes one), the items drawn
/// by their keys, and what they are (the summary's plural noun). Something
/// newer came when that call's tree has a key these lack.
/// `limit` made `peek_limit` by `query`, where the method takes one), the
/// items drawn by their keys, and what they are (the summary's plural
/// noun). Something newer came when that call's tree has a key these lack.
fn latest_ui(q: &view::QueryMode, items: &Value, arguments: Option<&Value>) -> Option<Value> {
let key = q.latest.as_ref()?;
let items: Vec<Value> = items
@@ -2140,6 +2140,26 @@ fn latest_ui(q: &view::QueryMode, items: &Value, arguments: Option<&Value>) -> O
/// allows at most (100 for the AppView's feeds).
const MAX_LATEST_ITEMS: usize = 100;
/// How many items what tells something newer came asks for, where the
/// method takes an integer `limit` (its lexicon's `limit`): two, so the
/// newest is seen past one pinned first (an author feed's with
/// `includePins`), within the least and most the lexicon allows, and no
/// more than the call's own `limit` (`own`) drew, as one it never drew
/// would always be newer.
fn peek_limit(limit: &Value, own: Option<u64>) -> Option<u64> {
if limit["type"] != "integer" {
return None;
}
let least = limit["minimum"].as_u64().unwrap_or(1).max(1);
let most = limit["maximum"].as_u64().unwrap_or(u64::MAX).max(least);
let peek = PEEK_ITEMS.clamp(least, most);
Some(own.map_or(peek, |own| peek.min(own.max(least))))
}
/// What a call telling something newer came asks for: the newest, and one
/// more, past a pinned item.
const PEEK_ITEMS: u64 = 2;
/// The call for the page after a page of records, when it has a cursor.
fn next_page(structured: &Value, arguments: Option<&Value>) -> Option<Value> {
structured["cursor"]
@@ -3698,6 +3718,26 @@ mod tests {
assert!(ui.get("latest").is_none());
}
#[test]
fn a_peek_sees_past_a_pinned_item_within_the_lexicons_limit() {
let limit = |l: Value| peek_limit(&l, None);
// The AppView's feeds (1 to 100): the newest and one more, so a
// pinned post first never hides it.
let feeds = json!({ "type": "integer", "minimum": 1, "maximum": 100 });
assert_eq!(limit(feeds.clone()), Some(2));
assert_eq!(limit(json!({ "type": "integer" })), Some(2));
// Within what the lexicon allows.
assert_eq!(limit(json!({ "type": "integer", "minimum": 5 })), Some(5));
assert_eq!(limit(json!({ "type": "integer", "maximum": 1 })), Some(1));
// No more than the call drew: a tile of one item asks for one, as
// a second it never drew would be newer every time.
assert_eq!(peek_limit(&feeds, Some(1)), Some(1));
assert_eq!(peek_limit(&feeds, Some(30)), Some(2));
// No integer limit: the call as it is.
assert_eq!(limit(Value::Null), None);
assert_eq!(limit(json!({ "type": "string" })), None);
}
#[test]
fn descriptions_stripped() {
let mut defs = json!({ "main": { "type": "record", "description": "a record",
docs/views.md+3−2
@@ -134,8 +134,9 @@ and, with `children`, the arrays nested in it (`Thread: "…" by alice.example:
A list that runs newest first can name each item's key in `latest`, a path within each item
(`"latest": "post.uri"`). HUD then puts `_meta.ui.latest` in the tree. It holds the same call with
no cursor (`call`), the items drawn by their keys (`items`, each `{ key }`), and the summary's
plural noun (`noun`, "posts"). Where the method
takes a `limit`, that call asks for the fewest its lexicon allows (1 for the AppView's feeds).
plural noun (`noun`, "posts"). Where the method takes a `limit`, that call asks for 2, within what
its lexicon allows and no more than the tile's own `limit`. That's the newest item and one more, so
a post pinned first (`includePins`) doesn't hide a newer one.
Something newer came when that call's tree has a key the drawn ones lack. So a pinned post at the
top of an author feed doesn't count, since it was drawn too. The bundled timeline, author feed, and
schemas/place.hud.ui.json+1−1
@@ -56,7 +56,7 @@
"description": "How to tell something newer came than the items a query's tree drew: make call, and something did when its tree's latest has an item whose key none of these items has.",
"required": ["call", "items"],
"properties": {
"call": { "type": "ref", "ref": "#call", "description": "The tree's own call with no cursor, asking for as few items as its method allows." },
"call": { "type": "ref", "ref": "#call", "description": "The tree's own call with no cursor, asking for its newest items alone (2, where its method takes a limit)." },
"items": { "type": "array", "maxLength": 100, "items": { "type": "ref", "ref": "#latestItem" }, "description": "The items drawn, in order." },
"noun": { "type": "string", "maxLength": 32, "description": "What the items are, plural (posts), as its view's summary names them." }
}