Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
433dd0f
feat(messages): pin and unpin channel messages
kalvinnchau Nov 19, 2026
c6f04ed
fix: harden pin list freshness and hydration
kalvinnchau Nov 19, 2026
510f3d2
fix: repair pin lists on channel catch-up and page every overlay
kalvinnchau Nov 19, 2026
43aad04
fix: page pin overlays with the relay keyset cursor
kalvinnchau Nov 19, 2026
7e3a7d3
fix: read pin lists by channel h tag
kalvinnchau Nov 19, 2026
af5ce10
fix: stop retrying a pin command refused as too old
kalvinnchau Nov 19, 2026
a9fe6f3
fix: stop a pin command refused as too old on every retry path
kalvinnchau Nov 19, 2026
68d9854
fix: classify the relay's too-old refusal as the outbox stores it
kalvinnchau Nov 19, 2026
dff8ae2
fix: offer pin commands without advertisement and explain unsupported…
kalvinnchau Nov 19, 2026
b514d86
test: fit message menu tests to the pin item
kalvinnchau Nov 19, 2026
945b6e0
fix(outbox): complete pin commands on relay acceptance
kalvinnchau Nov 19, 2026
dfbe384
perf(pins): read only pinned rows that changed
kalvinnchau Nov 19, 2026
f2f42a2
fix(pins): close the pinned panel when a pin is opened
kalvinnchau Nov 20, 2026
502d3aa
fix(pins): scope pin reads and keep pin replays continuous
kalvinnchau Nov 23, 2026
4e3cc99
refactor(pins): drop the pin notice row
kalvinnchau Nov 23, 2026
36d1c1c
feat(pins): say pin to dm in dms and offer no pins in solo chats
kalvinnchau Nov 23, 2026
c15f8ff
test(pins): give the outbox status pin source the relay self key
kalvinnchau Nov 23, 2026
f53d9d3
fix(pins): reload a pin when its agent's owner is learned, and queue …
kalvinnchau Nov 23, 2026
e7dc4c5
fix(pins): retry a failed pinned row refresh in the background
kalvinnchau Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions browser-host/relay-authority.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ it.each([
}
},
);
it.each([
[{ self }, true],
[{ self, supported_extensions: ["nip-ar"] }, true],
// Without `self` no list can be verified.
[{ pubkey: self }, false],
])(
"offers pin commands where the relay names itself: %j",
async (nip11, supported) => {
const h = await harness(() => Response.json(nip11));
try {
const transport = await h.connect();
expect(transport.writer.kinds.includes(40010)).toBe(supported);
expect(transport.writer.kinds.includes(40011)).toBe(supported);
} finally {
await h.close();
}
},
);
it.each([
["explicit self", { self, pubkey: contact }, self, self],
["self without contact", { self }, self, self],
Expand Down
65 changes: 65 additions & 0 deletions browser-host/relay-broker-live.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,71 @@ test.each([
},
);

test.each([
[40010, 400],
[40011, 400],
// Other kinds keep the unconfirmed answer.
[9000, 503],
])(
"a relay without pins refuses kind %i, answered %i",
async (kind, status) => {
const h = await harness();
let traffic;
try {
browserFetch(h.base);
const transport = await connectBrokerTransport(h.base);
traffic = transport.subscribe(callbacks);
await until(() => h.requests.length >= 1 && !!traffic.identity());
const channel = "00000000-0000-4000-8000-000000000001";
const event = await transport.writer.sign(
{
kind,
content: "",
created_at: Math.floor(Date.now() / 1000),
tags:
kind === 9000
? [
["h", channel],
["p", "a".repeat(64)],
]
: [
["h", channel],
["e", "a".repeat(64)],
["client-id", "local"],
],
},
new AbortController().signal,
);
const result = fetch(`${h.base}/api/relay/publish`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Buzz-Live-ID": traffic.identity(),
},
body: JSON.stringify(event),
});
await until(() => h.publications.length === 1);
await h.sockets[0].receive([
"OK",
event.id,
false,
"restricted: unknown event kind",
]);
const response = await result;
expect(response.status).toBe(status);
expect(await response.json()).toEqual(
status === 400
? { error: "restricted: unknown event kind" }
: { error: "Socket publication could not be confirmed", sent: false },
);
} finally {
traffic?.dispose();
vi.unstubAllGlobals();
await h.close();
}
},
);

test("publication diagnostics distinguish missing and mismatched live owner without dispatch", async () => {
const logger = getLogger("relay-broker");
const reporters = [...logger.options.reporters];
Expand Down
47 changes: 45 additions & 2 deletions browser-host/relay-broker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ async function relayAuthority(fetch, relay) {
searchSort:
Array.isArray(nip11.supported_extensions) &&
nip11.supported_extensions.includes("buzz-search-sort"),
// NIP-PM is not advertised: a relay without it refuses the commands. Its
// lists are verified by `self`, so without it no pin can be shown.
pins: nip11.self === author,
...(readSnapshotCommunity(nip11.read_state_snapshot)
? { readStateCommunity: readSnapshotCommunity(nip11.read_state_snapshot) }
: {}),
Expand Down Expand Up @@ -575,6 +578,36 @@ export function validReport(event) {
].includes(target[2])
);
}
/** A pin (40010) or unpin (40011): one channel and one message, as native
* `valid_pin_command`; the relay decides who may pin what. */
export function validPinCommand(event) {
if (
![40010, 40011].includes(event?.kind) ||
event.content !== "" ||
!Number.isSafeInteger(event.created_at) ||
event.created_at < 0 ||
!Array.isArray(event.tags) ||
!event.tags.every(
(tag) =>
Array.isArray(tag) &&
tag.length === 2 &&
tag.every((value) => typeof value === "string") &&
["h", "e", "client-id"].includes(tag[0]),
)
)
return false;
const named = (name) => event.tags.filter((tag) => tag[0] === name);
const [channel] = named("h");
const [target] = named("e");
return (
named("h").length === 1 &&
channel[1].length > 0 &&
channel[1].length <= 256 &&
named("e").length === 1 &&
/^[0-9a-f]{64}$/.test(target[1]) &&
named("client-id").length <= 1
);
}
/** Channel-local NIP-09 removal; the relay enforces authorship of each target. */
export function validMessageDeletion(event) {
if (
Expand Down Expand Up @@ -1737,6 +1770,7 @@ export function relayBrokerPlugin({
...((await getAuthority(relay)).artifactSupport ? [45010] : []),
...WORKFLOW_KINDS,
...((await getAuthority(relay)).channelCreation ? [9007] : []),
...((await getAuthority(relay)).pins ? [40010, 40011] : []),
],
channelLifecycle: true,
channelDetails: true,
Expand Down Expand Up @@ -3172,6 +3206,12 @@ export function relayBrokerPlugin({
error: "Report rejected",
sent: false,
});
} else if ([40010, 40011].includes(filters?.kind)) {
if (!validPinCommand(filters))
return json(res, 400, {
error: "Invalid pin command",
sent: false,
});
} else if (filters?.kind === 20002) {
if (!validTypingTemplate(filters))
return json(res, 400, {
Expand Down Expand Up @@ -3288,10 +3328,13 @@ export function relayBrokerPlugin({
failure.refusal?.startsWith("conflict:");
// Answer a proven validation refusal as the relay's HTTP API does,
// 400 with its bounded text, so every publish path shows the same
// reason. The text goes to this client only, never to the log.
// reason. The text goes to this client only, never to the log. A
// relay without NIP-PM refuses pin commands as `restricted:`.
if (
failure?.sent === false &&
failure.reason?.startsWith("invalid:") &&
(failure.reason?.startsWith("invalid:") ||
([40010, 40011].includes(filters.kind) &&
failure.reason?.startsWith("restricted:"))) &&
!(
readPublishing &&
failure.refusal === READ_STATE_TIMESTAMP_REFUSAL
Expand Down
31 changes: 31 additions & 0 deletions browser-host/relay-broker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createUpstream,
validFilters,
validMessageTemplate,
validPinCommand,
} from "./relay-broker.mjs";

test("read broker accepts non-channel finite reads without relaxing filter budgets", () => {
Expand Down Expand Up @@ -230,3 +231,33 @@ test("workflow list batches alone may exceed four filters, with 128 unique chann
])
assert.equal(validFilters(invalid), false);
});

test("pin commands name one channel and one message, with only a client id besides", () => {
const pin = {
kind: 40010,
created_at: 1,
content: "",
tags: [
["h", "channel"],
["e", "a".repeat(64)],
["client-id", "local"],
],
};
assert.equal(validPinCommand(pin), true);
assert.equal(validPinCommand({ ...pin, kind: 40011 }), true);
for (const invalid of [
{ ...pin, kind: 9 },
{ ...pin, content: "x" },
{ ...pin, tags: pin.tags.slice(1) },
{ ...pin, tags: [pin.tags[0], pin.tags[2]] },
{ ...pin, tags: [...pin.tags, ["h", "other"]] },
{ ...pin, tags: [...pin.tags, ["e", "b".repeat(64)]] },
{ ...pin, tags: [...pin.tags, ["client-id", "again"]] },
{ ...pin, tags: [...pin.tags, ["p", "c".repeat(64)]] },
{ ...pin, tags: [["h", ""], pin.tags[1]] },
{ ...pin, tags: [["h", "x".repeat(257)], pin.tags[1]] },
{ ...pin, tags: [pin.tags[0], ["e", "A".repeat(64)]] },
{ ...pin, tags: [pin.tags[0], ["e", "a".repeat(64), "relay"]] },
])
assert.equal(validPinCommand(invalid), false);
});
2 changes: 1 addition & 1 deletion browser-host/workflow-broker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ it("existing backend signs only canonical workflow sign/publish with exact own e
live = await openBrokerSocket(t);
expect(t.writer.kinds).toEqual([
30315, 30030, 7, 9, 40003, 42000, 9000, 9001, 30078, 30175, 30177, 30178,
40100, 1984, 30620, 46020, 5,
40100, 1984, 30620, 46020, 5, 40010, 40011,
]);
for (const input of [
template(),
Expand Down
14 changes: 7 additions & 7 deletions crates/agent-controller/src/app_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use std::path::{Path, PathBuf};
/// (9), a channel member change (9000, 9001), edit (9002), creation (9007),
/// deletion (9008), join (9021) or leave (9022), typing (20002), an edit of its
/// own message (40003), a shared note (30023), a channel canvas (40100), a
/// request to open a DM (41010), a repository announcement (30617) or an
/// artifact revision (45010). The relay decides which channel changes and
/// artifact edits it may make. Its profile (0) is the app's, and
/// its memory (30174) is written by `memory`.
const KINDS: [u16; 17] = [
5, 7, 9, 9000, 9001, 9002, 9007, 9008, 9021, 9022, 20002, 30023, 30617, 40003, 40100, 41010,
45010,
/// pin or unpin (40010, 40011), a request to open a DM (41010), a repository
/// announcement (30617) or an artifact revision (45010). The relay decides
/// which channel changes, pins and artifact edits it may make. Its profile (0)
/// is the app's, and its memory (30174) is written by `memory`.
const KINDS: [u16; 19] = [
5, 7, 9, 9000, 9001, 9002, 9007, 9008, 9021, 9022, 20002, 30023, 30617, 40003, 40010, 40011,
40100, 41010, 45010,
];

/// Content of a live channel Canvas (40100), in UTF-8 bytes. Mirrors
Expand Down
4 changes: 2 additions & 2 deletions crates/agent-controller/src/app_agent/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ fn signs_only_bounded_kinds_with_the_saved_attestation() {
let key = agent.read_key(&credentials).unwrap();
let saved: Vec<String> = serde_json::from_str(&agent.auth).unwrap();
for kind in [
5, 7, 9, 9000, 9001, 9002, 9007, 9008, 9021, 9022, 20002, 30023, 30617, 40003, 40100,
41010, 45010,
5, 7, 9, 9000, 9001, 9002, 9007, 9008, 9021, 9022, 20002, 30023, 30617, 40003, 40010,
40011, 40100, 41010, 45010,
] {
let tags = vec![
vec!["auth".to_owned(), "forged".to_owned()],
Expand Down
6 changes: 6 additions & 0 deletions docs/buzz-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ if that desktop app is up and running.
- **Messages.** Hover or right-click a message to react, **Reply**, copy a link,
forward it, or start a chat about it. On an agent's reply, **View activity**
shows what it did.
- **Pins.** **Pin to channel** (**Pin to DM** in a DM) in a message's More
menu adds it to the pin list, up to 250; the pin button in the header lists
them. Solo chats have no pins.
Anyone who can post can pin or unpin any message. Forum posts can't be
pinned. A community that doesn't take pins refuses them, and Buzz says so.
Agents pin with the `pin` tool.
- **Composer.** **#** links a channel. On desktop, **!** gives your agents a
folder and **/** a skill. Attach files by pasting or dragging them in.
- **Drafts.** Every message box open on a conversation shares its draft. A box
Expand Down
11 changes: 6 additions & 5 deletions src-tauri/src/credential_service/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ pub(super) enum Verdict {
}

/// Everyday work: messages and their edits, pins, bookmarks, schedules and
/// reminders (9, 40002–40008), reactions (7), shared notes (30023), forum posts,
/// votes and comments (45001–45003), presence and typing (20001–20003), read
/// state (30078) and user status (30315), the identity's own lists (10000,
/// reminders (9, 40002–40008), channel pin commands (40010, 40011), reactions
/// (7), shared notes (30023), forum posts, votes and comments (45001–45003),
/// presence and typing (20001–20003), read state (30078) and user status
/// (30315), the identity's own lists (10000,
/// 10001, 10003, 10030, 30000, 30003, 30030), canvases (40100), artifacts
/// (45010), git patches, pull requests, issues and statuses (1617–1633), DM
/// open and hide (41010, 41012), archive requests (9035, 9036), workflow
Expand All @@ -25,8 +26,8 @@ pub(super) enum Verdict {
const ORDINARY: &[u16] = &[
7, 9, 1617, 1618, 1619, 1621, 1630, 1631, 1632, 1633, 9035, 9036, 10000, 10001, 10003, 10030,
20001, 20002, 20003, 24200, 30000, 30003, 30023, 30030, 30078, 30174, 30315, 40002, 40003,
40004, 40005, 40006, 40007, 40008, 40100, 41010, 41012, 43001, 43002, 43003, 43004, 43005,
43006, 45001, 45002, 45003, 45010, 46020,
40004, 40005, 40006, 40007, 40008, 40010, 40011, 40100, 41010, 41012, 43001, 43002, 43003,
43004, 43005, 43006, 45001, 45002, 45003, 45010, 46020,
];

/// Changes to who the identity is, what it controls or what others see about
Expand Down
4 changes: 3 additions & 1 deletion src-tauri/src/credential_service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,9 @@ fn the_policy_binds_each_proof_to_the_community() {
#[test]
fn every_kind_has_one_class() {
let classes = |kind| classify(kind, &[], NOW, NOW, RELAY);
for kind in [7, 9, 30174, 20001, 24200, 40002, 41010, 45010, 46020, 1621] {
for kind in [
7, 9, 30174, 20001, 24200, 40002, 40010, 40011, 41010, 45010, 46020, 1621,
] {
assert_eq!(classes(kind), Verdict::Sign, "{kind}");
}
for kind in [
Expand Down
24 changes: 24 additions & 0 deletions src-tauri/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ fn validate_event(community: &str, event: &EventTemplate) -> Result<()> {
{
return Err("Invalid agent presence".into());
}
} else if matches!(event.kind, 40010 | 40011) {
if !valid_pin_command(event) {
return Err("Invalid pin command".into());
}
} else if matches!(event.kind, 9030..=9032) {
if !valid_member_command(event) {
return Err("Invalid member change".into());
Expand Down Expand Up @@ -596,6 +600,26 @@ fn valid_reaction_deletion(event: &EventTemplate) -> bool {
.any(|tag| tag[0] == "e" && hex_key(&tag[1]))
}

/** A pin (40010) or unpin (40011): one channel and one message, as the
* broker's `validPinCommand`; the relay decides who may pin what. */
fn valid_pin_command(event: &EventTemplate) -> bool {
let tag = |name: &str| {
event
.tags
.iter()
.filter(|tag| tag.first().map(String::as_str) == Some(name))
.collect::<Vec<_>>()
};
event.content.is_empty()
&& event
.tags
.iter()
.all(|tag| tag.len() == 2 && matches!(tag[0].as_str(), "h" | "e" | "client-id"))
&& matches!(tag("h").as_slice(), [h] if !h[1].is_empty() && h[1].len() <= 256)
&& matches!(tag("e").as_slice(), [e] if hex_key(&e[1]))
&& tag("client-id").len() <= 1
}

/** Keep the shared kind-5 writer aligned with the broker's channel-local deletion shape. */
fn valid_message_deletion(event: &EventTemplate) -> bool {
if event.kind != 5
Expand Down
Loading
Loading