feat(desktop): link workstream blocker messages

Add strict validation for optional manual blocker message destinations and route valid links to the exact channel message or thread while preserving existing entity links.

Co-authored-by: Other Brother Darryl <cee32d92756729ee0c097c5661b879c6199931cd25315c8cf398dcbf0f155cf1@buzz.block.builderlab.xyz>
Signed-off-by: loganj <loganj@squareup.com>
This commit is contained in:
Logan Johnson
2026-08-19 21:43:07 +00:00
parent 10e6bf7052
commit 381fe2c0cc
3 changed files with 112 additions and 12 deletions

View File

@@ -5,11 +5,49 @@ import {
deriveReviewerWaits,
mergeWorkstreamWaits,
parseManualWorkstreamWaits,
parseWorkstreamWaitMessageLink,
sortWorkstreamCards,
} from "./workstreamWaits.ts";
const LOGAN = "a".repeat(64);
const CHANNEL = "123e4567-e89b-12d3-a456-426614174000";
const MESSAGE = "a".repeat(64);
const THREAD = "b".repeat(64);
test("message-linked manual waits preserve valid exact destinations", () => {
const message = `buzz://message?channel=${CHANNEL}&id=${MESSAGE}&thread=${THREAD}`;
const [wait] = parseManualWorkstreamWaits([
{
key: "message",
actor: { kind: "person", name: "Logan" },
reason: "Need an answer",
message,
},
]);
assert.equal(wait.message, message);
assert.deepEqual(parseWorkstreamWaitMessageLink(wait.message), {
channelId: CHANNEL,
messageId: MESSAGE,
threadRootId: THREAD,
});
});
test("message-linked waits fail closed for malformed or non-canonical destinations", () => {
const valid = `buzz://message?channel=${CHANNEL}&id=${MESSAGE}`;
for (const message of [
"not-a-link",
`buzz://message?channel=not-a-uuid&id=${MESSAGE}`,
`buzz://message?channel=${CHANNEL}&id=short`,
`buzz://message?channel=${CHANNEL}&id=${MESSAGE}&thread=short`,
`${valid}&extra=ignored`,
`buzz://message?id=${MESSAGE}&channel=${CHANNEL}`,
]) {
assert.equal(parseWorkstreamWaitMessageLink(message), null, message);
}
assert.equal(parseWorkstreamWaitMessageLink(undefined), null);
});
test("manual waits retain simultaneous unique entries and ignore malformed or duplicate keys", () => {
assert.deepEqual(
parseManualWorkstreamWaits([

View File

@@ -1,5 +1,7 @@
import { normalizePubkey } from "@/shared/lib/pubkey";
import type { ActiveChannelTurnSummary } from "@/features/agents/activeAgentTurnsStore";
import { parseMessageLink } from "@/features/messages/lib/messageLink";
import type { ParsedMessageLink } from "@/features/messages/lib/messageLink";
import { normalizePubkey } from "@/shared/lib/pubkey";
import type { WorkstreamCardV1 } from "@/features/workstream-board/lib/workstreamCardParser";
import type {
WorkstreamPullRequestDisplayState,
@@ -17,9 +19,45 @@ export type WorkstreamWait = {
actor: WorkstreamWaitActor;
reason: string;
since?: string;
/** Optional canonical `buzz://message?...` destination from the canvas. */
message?: string;
source: "manual" | "derived";
};
const CHANNEL_ID_PATTERN =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
const EVENT_ID_PATTERN = /^[0-9a-f]{64}$/;
/**
* Parse and strictly validate a manual Workstream Board message destination.
*
* `parseMessageLink` intentionally accepts any non-empty route values for
* general markdown links. Canvas-authored blockers need the stronger wire
* contract: a canonical URL, a UUID channel ID, and 64-hex event IDs.
*/
export function parseWorkstreamWaitMessageLink(
value: unknown,
): ParsedMessageLink | null {
if (typeof value !== "string") return null;
const parsed = parseMessageLink(value);
if (!parsed.ok) return null;
const { channelId, messageId, threadRootId } = parsed.value;
if (
!CHANNEL_ID_PATTERN.test(channelId) ||
!EVENT_ID_PATTERN.test(messageId) ||
(threadRootId !== null && !EVENT_ID_PATTERN.test(threadRootId))
) {
return null;
}
// Reject encoded values, unknown query parameters, and non-canonical query
// ordering rather than silently navigating to a different destination.
const canonical = `buzz://message?channel=${channelId}&id=${messageId}${
threadRootId ? `&thread=${threadRootId}` : ""
}`;
return canonical === value ? parsed.value : null;
}
export type WorkstreamCardSortInput = {
channelId: string;
channelName: string;
@@ -60,6 +98,8 @@ export function isWorkstreamWait(
(typeof wait.since !== "string" || !Number.isFinite(Date.parse(wait.since)))
)
return false;
// Keep malformed destinations attached to an otherwise valid blocker. The
// renderer validates the link before making the row interactive.
return (
actor.pubkey === undefined ||
(typeof actor.pubkey === "string" && !!actor.pubkey.trim())
@@ -74,7 +114,14 @@ export function parseManualWorkstreamWaits(
for (const value of values) {
if (!isWorkstreamWait(value) || keys.has(value.key)) continue;
keys.add(value.key);
waits.push({ ...value, actor: { ...value.actor }, source: "manual" });
const message =
typeof value.message === "string" ? value.message : undefined;
waits.push({
...value,
...(message === undefined ? { message: undefined } : { message }),
actor: { ...value.actor },
source: "manual",
});
}
return waits;
}

View File

@@ -1,6 +1,8 @@
import { ExternalLink } from "lucide-react";
import { openUrl } from "@tauri-apps/plugin-opener";
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
import { parseWorkstreamWaitMessageLink } from "@/features/workstream-board/lib/workstreamWaits";
import type { UserProfileLookup } from "@/features/profile/lib/identity";
import type { WorkstreamPullRequestReference } from "@/features/workstream-board/lib/workstreamPullRequestStatus";
import type { WorkstreamWait } from "@/features/workstream-board/lib/workstreamWaits";
@@ -59,6 +61,7 @@ export function WorkstreamWaits({
}) {
const now = useNow(60_000);
const openEntityLink = useOpenEntityLink();
const { goChannel } = useAppNavigation();
if (waits.length === 0) return null;
const referencesByIdentity = new Map(
references.map((reference) => [reference.identity, reference]),
@@ -88,16 +91,28 @@ export function WorkstreamWaits({
{orderedWaits.map((wait) => {
const age = waitAge(wait.since, now);
const reference = referencesByIdentity.get(wait.key);
const open = reference
? () => {
const parsed =
reference.kind === "buzz"
? parseEntityLink(reference.href)
: null;
if (parsed?.ok) openEntityLink(parsed.value);
else void openUrl(reference.href);
}
: undefined;
const messageDestination = parseWorkstreamWaitMessageLink(
wait.message,
);
const open =
wait.message !== undefined
? messageDestination
? () =>
void goChannel(messageDestination.channelId, {
messageId: messageDestination.messageId,
threadRootId: messageDestination.threadRootId,
})
: undefined
: reference
? () => {
const parsed =
reference.kind === "buzz"
? parseEntityLink(reference.href)
: null;
if (parsed?.ok) openEntityLink(parsed.value);
else void openUrl(reference.href);
}
: undefined;
const content = (
<>
<WaitAvatar profiles={profiles} wait={wait} />