~ 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

iOS: feeds hear of the posts seen as they're scrolled past

Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:ios/interactions-timer
crates/hud-server/src/xrpc.rs+15−1
@@ -47,7 +47,7 @@ use serde_json::{Map, Value as Json, json};
use std::collections::VecDeque;
use std::convert::Infallible;
use std::sync::{Arc, LazyLock};
use std::time::Duration;
use std::time::{Duration, Instant};
/// The methods' namespace.
const NS: &str = "place.hud.";
@@ -852,6 +852,18 @@ async fn call(
"The canvas tools are an agent's: the workspace changes the canvas through its own methods",
));
}
// One `mcp tool` line, as `/mcp` logs a tools/call, so the
// page's and the app's calls show alike (`telemetry::tool`).
let started = Instant::now();
let logged = |error: Option<&str>, reason: Option<&str>| {
hud_core::telemetry::tool(&hud_core::telemetry::Tool {
name: tool,
did: Some(caller.account.did.as_str()),
error,
reason,
took: started.elapsed(),
})
};
let answered = match hud
.call_tool(tool, input.get("arguments"), Some(&caller.account))
.await
@@ -863,6 +875,7 @@ async fn call(
Err(hud_core::oauth::SIGN_IN_AGAIN.to_string())
}
Some(Err(Refusal::SignIn)) => {
logged(None, Some("sign-in asked"));
return Err(fail(
StatusCode::UNAUTHORIZED,
"AuthRequired",
@@ -872,6 +885,7 @@ async fn call(
Some(Err(Refusal::Error(e))) => Err(e),
Some(Ok(out)) => Ok(out),
};
logged(answered.as_ref().err().map(String::as_str), None);
json!({ "result": tool_result(answered, false) })
}
_ => {
docs/observability.md+1−1
@@ -31,7 +31,7 @@ Each line has `timestamp`, `level` (`ERROR`, `WARN`, `INFO`, `DEBUG`), `message`
`url.query` masks the value of any parameter a secret could be in (`code`, `state`, `iss`, `token`, `access_token`, `refresh_token`, `password`, `secret`, `key`) as `_`, and cuts it at 200 characters. A request under `/oauth` logs no query.
`mcp tool` is one line per `tools/call`, with the caller's DID when signed in. A tool that answered an error is `mcp tool failed`, with the error the client saw. A call that asked the person to sign in has `reason: sign-in asked`. HUD never logs a tool's arguments or its result, since tokens, records and messages can be in them.
`mcp tool` is one line per tool call, a `tools/call` on `/mcp` (the iOS app, agents) or a `place.hud.callTool` (the workspace's page), with the caller's DID when signed in. A tool that answered an error is `mcp tool failed`, with the error the client saw. A call that asked the person to sign in has `reason: sign-in asked`. HUD never logs a tool's arguments or its result, since tokens, records and messages can be in them.
`outgoing` is one line per call through hud-core's outbound client (`hud_core::net`), which every request to a PDS, PLC, an AppView, a feed generator or any other service goes through. `rpc.method` is the XRPC method, for a path under `/xrpc/`. `error.type` is why it failed before an answer (`timeout`, `connect`, `body` or `request`, with the cause), or the status of a 5xx. A call its wait cut off is `timeout`. One dropped before then, because what asked for it stopped waiting (a search typed past, the loser of a race), is `abandoned`: no failure, at debug, and not counted as failed. Calls are at debug, so a busy minute doesn't drown the log. Set `hud::outgoing=debug` to see each one.
ios/HUDKit/Sources/HUDKit/Data/Interactions.swift+5−2
@@ -41,8 +41,11 @@ public final class Interactions {
let due = last.map { $0 + Self.every } ?? .now
timer = Task { [weak self] in
try? await Task.sleep(until: due, clock: .continuous)
guard !Task.isCancelled else { return }
await self?.flush()
guard !Task.isCancelled, let self else { return }
// No longer waiting: `flush` cancels a waiting timer, and this one,
// cancelled, would have its own send cancelled before it went.
timer = nil
await flush()
}
}
ios/HUDKit/Tests/HUDKitTests/HUDKitTests.swift+14−0
@@ -99,6 +99,20 @@ private func conversation() throws -> (drawn: Drawn, root: JSON) {
#expect(input.stamped(now: Date(timeIntervalSince1970: 0))["message"]?["text"] == ["$text": true])
}
/// A queued send goes from the throttle's own task uncancelled: URLSession
/// refuses a cancelled task's request, and the server never hears of it.
@MainActor @Test func aQueuedSendGoesUncancelled() async throws {
final class Sends { var cancelled: [Bool] = [] }
let sends = Sends()
let feedback = Interactions { _, interactions in
sends.cancelled.append(Task.isCancelled)
return (interactions.count, nil)
}
feedback.add("at://did:plc:f/app.bsky.feed.generator/f", ["item": "at://did:plc:a/app.bsky.feed.post/1", "event": .string(Interactions.seen)])
for _ in 0..<200 where sends.cancelled.isEmpty { try await Task.sleep(for: .milliseconds(10)) }
#expect(sends.cancelled == [false])
}
@MainActor @Test func anActionsCallIsTrustedTreesOnlyAndCallsCallProcedure() throws {
let (_, root) = try conversation()
let p = try #require(root["items"]?.array?[1]["k"]?.array?[1]["p"])
ios/project.yml+1−1
@@ -51,7 +51,7 @@ targets:
base:
PRODUCT_BUNDLE_IDENTIFIER: place.hud.app
MARKETING_VERSION: "1.0"
CURRENT_PROJECT_VERSION: "2"
CURRENT_PROJECT_VERSION: "3"
SWIFT_VERSION: "6.0"
TARGETED_DEVICE_FAMILY: "1,2"
# App/Assets.xcassets: one 1024 px square, which iOS scales and masks.