Threaded comments on a record or a document.
Card retries fail with declined since the 5 PM deploy. Logs point at the idempotency key.
Confirmed on staging. @Ben Okafor can you roll back while we look?
Rolling back now. I'll post when it's done.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { Comments, CommentThread } from "./ui/uicontext/components/kit/Comments.ts"import { toggleReaction } from "./ui/uicontext/components/kit/Reactions.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { ada, ben, members, mira, now, scout } from "./team.ts"// An issue's discussion. A pretend server answers after a moment: it refuses a comment that// contains "password", and mentioning @Scout makes the agent reply while it works.const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" } })const threads: ReadonlyArray<CommentThread> = [ { id: "t1", comments: [ { id: "c1", actor: ben, body: "Card retries fail with **declined** since the 5 PM deploy. Logs point at the idempotency key.", at: "2026-12-01T09:12:00Z", reactions: [{ emoji: "👀", count: 2, mine: false, names: ["Mira Patel", "Scout"] }], }, { id: "c2", actor: ada, body: "Confirmed on staging. @Ben Okafor can you roll back while we look?", at: "2026-12-01T09:40:00Z", mine: true, edited: true, }, { id: "c3", actor: mira, body: "Rolling back now. I'll post when it's done.", at: "2026-12-01T09:44:00Z" }, ], }, { id: "t2", resolved: true, comments: [{ id: "c4", actor: ada, body: "Is this a duplicate of PAY-398?", at: "2026-11-30T16:00:00Z", mine: true }], },]const Post = Schema.Struct({ request: Schema.String, thread: Schema.NullOr(Schema.String), body: Schema.String, mentions: Schema.Array(Schema.String) })const Message = UiSchema.TaggedEnum({ RequestedPost: { post: Post }, SucceededPost: { post: Post }, RequestedEdit: { request: Schema.String, comment: Schema.String, body: Schema.String }, RequestedDelete: { request: Schema.String, comment: Schema.String }, SucceededChange: { request: Schema.String, comment: Schema.String, body: Schema.NullOr(Schema.String) }, RequestedResolve: { thread: Schema.String, resolved: Schema.Boolean }, RequestedReaction: { comment: Schema.String, emoji: Schema.String, on: Schema.Boolean }, RequestedStop: { comment: Schema.String }, FinishedReply: { thread: Schema.String },})// stand-ins for the server: each waits, then answersconst SendPost = Command.make("SendPost", { args: { post: Post } }, ({ post }) => Effect.sleep("600 millis").pipe(Effect.as(Message.SucceededPost({ post }))),)const SendChange = Command.make( "SendChange", { args: { request: Schema.String, comment: Schema.String, body: Schema.NullOr(Schema.String) } }, (change) => Effect.sleep("500 millis").pipe(Effect.as(Message.SucceededChange(change))),)const AgentWorks = Command.make("AgentWorks", { args: { thread: Schema.String } }, ({ thread }) => Effect.sleep("2500 millis").pipe(Effect.as(Message.FinishedReply({ thread }))),)const mapComments = (threads: ReadonlyArray<CommentThread>, f: (c: CommentThread["comments"][number]) => CommentThread["comments"][number] | null) => threads.map((t) => ({ ...t, comments: t.comments.flatMap((c) => f(c) ?? []) }))export const IssueComments = Html.component({ name: "IssueComments", model: Schema.Struct({ threads: Schema.Array(CommentThread), outcomes: Schema.Array(Outcome), seq: Schema.Number }), message: Message,}).make({ init: () => ({ threads, outcomes: [], seq: 10 }), update: { RequestedPost: ($, { post }) => $.run(SendPost.make({ post })), SucceededPost: ($, { post }) => { const { request, thread, body, mentions } = post if (body.toLowerCase().includes("password")) { return $.evolve({ outcomes: (o) => [...o.slice(-20), { _tag: "Refused" as const, request, reason: "Comments can't hold passwords. Put it in the vault and link it." }] }) } const id = `c${$.model.seq}` const target = thread ?? `t${$.model.seq}` const comment = { id, actor: ada, body, at: now, mine: true } const working = mentions.includes(scout.id) const reply = { id: `c${$.model.seq + 1}`, actor: scout, onBehalfOf: ada, body: "Reading the payment logs since 5 PM…", at: now, streaming: true } const next = $.evolve({ seq: (s) => s + 2, outcomes: (o) => [...o.slice(-20), { _tag: "Accepted" as const, request }], threads: (all) => thread === null ? [...all, { id: target, comments: working ? [comment, reply] : [comment] }] : all.map((t) => (t.id === thread ? { ...t, comments: [...t.comments, comment, ...(working ? [reply] : [])] } : t)), }) return working ? next.run(AgentWorks.make({ thread: target })) : next }, RequestedEdit: ($, change) => $.run(SendChange.make(change)), RequestedDelete: ($, { request, comment }) => $.run(SendChange.make({ request, comment, body: null })), SucceededChange: ($, { request, comment, body }) => $.evolve({ outcomes: (o) => [...o.slice(-20), { _tag: "Accepted" as const, request }], threads: (all) => mapComments(all, (c) => (c.id !== comment ? c : body === null ? null : { ...c, body, edited: true })), }), RequestedResolve: ($, { thread, resolved }) => $.evolve({ threads: (all) => all.map((t) => (t.id === thread ? { ...t, resolved } : t)) }), // reactions change at once; a real app sends them and corrects the count if the server disagrees RequestedReaction: ($, { comment, emoji, on }) => $.evolve({ threads: (all) => mapComments(all, (c) => (c.id !== comment ? c : { ...c, reactions: toggleReaction(c.reactions ?? [], emoji, on, ada.name) })) }), RequestedStop: ($, { comment }) => $.evolve({ threads: (all) => mapComments(all, (c) => (c.id !== comment ? c : { ...c, streaming: false, body: `${c.body}\n\n*Stopped by Ada.*` })) }), FinishedReply: ($, { thread }) => $.evolve({ threads: (all) => all.map((t) => t.id !== thread ? t : { ...t, comments: t.comments.map((c) => c.streaming === true ? { ...c, streaming: false, body: "Found it: the retry reuses the first attempt's key, so the bank declines it as a duplicate. Fix is on `pay/retry-key`." } : c, ), }, ), }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( Comments(h, { props: { label: "Comments on PAY-412", agentId: "comments-demo", threads: model.threads, me: ada, mentionables: members, outcomes: model.outcomes, now, }, onEmit: { RequestedPost: (post) => Message.RequestedPost({ post }), RequestedEdit: (change) => Message.RequestedEdit(change), RequestedDelete: (change) => Message.RequestedDelete(change), RequestedResolve: (e) => Message.RequestedResolve(e), RequestedReaction: (e) => Message.RequestedReaction(e), RequestedStop: (e) => Message.RequestedStop(e), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/commentsUsage
import type { Actor } from "./ui/uicontext/components/domain/Actor.ts"import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { Comments, type CommentThread } from "./ui/uicontext/components/kit/Comments.ts"const Message = UiSchema.TaggedEnum({ RequestedPostComment: { request: Schema.String, thread: Schema.NullOr(Schema.String), body: Schema.String }, RequestedEditComment: { request: Schema.String, comment: Schema.String, body: Schema.String }, RequestedDeleteComment: { request: Schema.String, comment: Schema.String }, RequestedResolveThread: { thread: Schema.String, resolved: Schema.Boolean }, RequestedReaction: { comment: Schema.String, emoji: Schema.String, on: Schema.Boolean },})// posts, edits and deletes carry a request id: answer each through `outcomes`export const IssueComments = ( h: Html.H<typeof Message.Type>, issue: { readonly threads: ReadonlyArray<CommentThread>; readonly me: Actor; readonly outcomes: ReadonlyArray<Outcome> },) => Comments(h, { props: { label: "Comments", threads: issue.threads, me: issue.me, outcomes: issue.outcomes }, onEmit: { RequestedPost: ({ request, thread, body }) => Message.RequestedPostComment({ request, thread, body }), RequestedEdit: ({ request, comment, body }) => Message.RequestedEditComment({ request, comment, body }), RequestedDelete: ({ request, comment }) => Message.RequestedDeleteComment({ request, comment }), RequestedResolve: ({ thread, resolved }) => Message.RequestedResolveThread({ thread, resolved }), RequestedReaction: ({ comment, emoji, on }) => Message.RequestedReaction({ comment, emoji, on }), RequestedStop: () => undefined, }, })Examples
Discussions on a page
Each thread quotes the text it's about; resolving tucks it under "Show 1 resolved", where it can be reopened.
Retries reuse the first attempt's idempotency key.
Should the key include the attempt number, or a fresh UUID?
Attempt number. Support can then match retries to the first charge.
Roll out to 10% of EU workspaces first.
10% feels slow. Can we start at 25%?
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Comments, CommentThread } from "./ui/uicontext/components/kit/Comments.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { ada, ben, members, mira, now } from "./team.ts"// A page's side panel: each discussion quotes the sentence it's about. Resolve one to tuck it away;// "Show 1 resolved" brings resolved ones back to reopen. One box per discussion; no new thread here,// because a new one starts from a selection in the page.const styles = stylex.create({ panel: { inlineSize: "min(100%, 24rem)" } })const threads: ReadonlyArray<CommentThread> = [ { id: "q1", quote: "Retries reuse the first attempt's idempotency key.", comments: [ { id: "q1a", actor: mira, body: "Should the key include the attempt number, or a fresh UUID?", at: "2026-12-01T10:12:00Z" }, { id: "q1b", actor: ben, body: "Attempt number. Support can then match retries to the first charge.", at: "2026-12-01T10:30:00Z" }, ], }, { id: "q2", quote: "Roll out to 10% of EU workspaces first.", comments: [{ id: "q2a", actor: ada, body: "10% feels slow. Can we start at 25%?", at: "2026-12-01T11:02:00Z", mine: true }], }, { id: "q3", quote: "Owner: Payments", resolved: true, comments: [{ id: "q3a", actor: ben, body: "Payments confirmed in standup.", at: "2026-11-30T09:20:00Z" }], },]const Message = UiSchema.TaggedEnum({ RequestedResolve: { thread: Schema.String, resolved: Schema.Boolean } })export const DiscussionPanel = Html.component({ name: "DiscussionPanel", model: Schema.Struct({ threads: Schema.Array(CommentThread) }), message: Message,}).make({ init: () => ({ threads }), update: { RequestedResolve: ($, { thread, resolved }) => $.evolve({ threads: (all) => all.map((t) => (t.id === thread ? { ...t, resolved } : t)) }), }, view: (h, model) => h.div.attrs(sx(styles.panel)).children( Comments(h, { props: { label: "Discussions on this page", agentId: "comments-inline", threads: model.threads, me: ada, mentionables: members, newThread: false, can: ["comment", "resolve"], empty: "Select text in the page and choose Comment to start one.", now, }, onEmit: { RequestedPost: () => undefined, RequestedEdit: () => undefined, RequestedDelete: () => undefined, RequestedResolve: (e) => Message.RequestedResolve(e), RequestedReaction: () => undefined, RequestedStop: () => undefined, }, }), ),})A long thread
Past fold comments (6 by default), the middle replies fold behind one button.
Proposal: drop the nightly export and stream changes to the warehouse instead.
Added. Anything else before we announce it?
Finance is on board if we keep the file until January 15.
Agreed. I'll write the announcement.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import type { Comment } from "./ui/uicontext/components/kit/Comments.ts"import { Comments } from "./ui/uicontext/components/kit/Comments.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { ada, ben, members, mira, now, scout } from "./team.ts"// A week-long debate on one issue: the first comment and the last three show, the rest fold.const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" } })const lines: ReadonlyArray<readonly [typeof ada, string]> = [ [ben, "Proposal: drop the nightly export and stream changes to the warehouse instead."], [mira, "The finance team reads the nightly file every morning. What replaces it for them?"], [ben, "A saved view in the warehouse with the same columns."], [ada, "They'll need training. Can we keep the file for one more quarter?"], [scout, "The file took **41 minutes** last night and failed twice this month."], [mira, "Then it has to go. I'll set up time with finance."], [ben, "Draft of the saved view is linked in the spec."], [ada, "Looks right. One column is missing: the cost center."], [ben, "Added. Anything else before we announce it?"], [mira, "Finance is on board if we keep the file until January 15."], [ada, "Agreed. I'll write the announcement."],]const comments: ReadonlyArray<Comment> = lines.map(([actor, body], i) => ({ id: `l${i}`, actor, body, at: new Date(Date.parse("2026-11-24T09:00:00Z") + i * 14 * 3600 * 1000).toISOString(), ...(actor.id === ada.id ? { mine: true } : {}),}))export const LongThread = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Comments(h, { props: { label: "Comments on DATA-77", agentId: "comments-long", threads: [{ id: "debate", comments }], me: ada, mentionables: members, newThread: false, now, }, onEmit: { RequestedPost: () => undefined, RequestedEdit: () => undefined, RequestedDelete: () => undefined, RequestedResolve: () => undefined, RequestedReaction: () => undefined, RequestedStop: () => undefined, }, }), )Read-only and empty
With an empty can, reactions are shown but can't be pressed and cannotComment says why. With no threads, the box invites the first comment.
Launch date moves to February 3 so support can staff up.
Updated the timeline to match.
You're a guest with view access. Ask Mira Patel to let you comment.
No comments yet
Ask a question or leave feedback. Type @ to bring someone in.
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Comments } from "./ui/uicontext/components/kit/Comments.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { ben, mira, now } from "./team.ts"// A guest with view access: the discussion and its reactions show, with nothing to press, and a// line says why. Below it, an object nobody has discussed yet.const styles = stylex.create({ frame: { display: "grid", gap: 24, inlineSize: "min(100%, 36rem)" } })const guest = { id: "guest", name: "Jordan Ellis", kind: "person" as const }const handlers = { RequestedPost: () => undefined, RequestedEdit: () => undefined, RequestedDelete: () => undefined, RequestedResolve: () => undefined, RequestedReaction: () => undefined, RequestedStop: () => undefined,}export const GuestComments = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( Comments(h, { key: "guest", props: { label: "Comments on the Q1 launch brief", agentId: "comments-read-only", threads: [ { id: "r1", comments: [ { id: "r1a", actor: mira, body: "Launch date moves to **February 3** so support can staff up.", at: "2026-11-30T14:00:00Z", reactions: [{ emoji: "👍", count: 4, mine: false, names: ["Ben Okafor", "Ada Lovelace", "Theo Robinson", "Maya Chen"] }], }, { id: "r1b", actor: ben, body: "Updated the timeline to match.", at: "2026-11-30T15:10:00Z" }, ], }, ], me: guest, can: [], cannotComment: "You're a guest with view access. Ask Mira Patel to let you comment.", now, }, onEmit: handlers, }), Comments(h, { key: "empty", props: { label: "Comments on PAY-430", agentId: "comments-empty", threads: [], me: guest, now }, onEmit: handlers, }), )API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | What the comments are on, for screen readers and agents: "Comments on ENG-12" |
agentId | string | comments:<label> | This list's id for agents, unique on the page; comments:<label> by default |
threadsrequired | CommentThread[] | — | The threads to show, each with its comments in order |
mentionables | Actor[] | — | Who can be mentioned: people and agents |
merequired | Actor | — | The reader, for the optimistic comment |
can | CommentsCan | — | What the reader may do; every action when left out |
cannotComment | string | — | Why the reader can't comment ("You can view this page, not comment"); hides the boxes |
newThread | boolean | true | A box for a new thread at the end; true by default (one running thread, as an issue has) |
empty | string | — | What shows when there's no open discussion; an empty string shows nothing |
fold | number | 6 | A thread longer than this folds its middle replies behind "Show N more replies"; 6 by default |
outcomes | Outcome[] | — | The app's answer to each RequestedPost, RequestedEdit and RequestedDelete, by its request id |
now | string | — | Now, as an ISO timestamp, for "5 minutes ago"; absolute dates when absent |
locale | string | — | The locale numbers and dates are formatted in; the browser's by default |
timeZone | string | — | The time zone times are shown in; the reader's when left out |
mac | boolean | true | ⌘ on a Mac, Ctrl elsewhere, for the keycaps; true by default |
Events
| Event | Payload | Description |
|---|---|---|
RequestedPost | { request: string; thread: string | null; body: string; mentions: string[] } | A new comment (thread null: a new thread); answer through outcomes with the same request |
RequestedEdit | { request: string; comment: string; body: string } | The person changed the text of their comment; answer through outcomes with the same request |
RequestedDelete | { request: string; comment: string } | The person deleted their comment; answer through outcomes with the same request |
RequestedReaction | { comment: string; emoji: string; on: boolean } | Add the reader's reaction (on) or take it back; toggleReaction applies it optimistically |
RequestedResolve | { thread: string; resolved: boolean } | The person resolved the thread, or reopened it |
RequestedStop | { comment: string } | Stop an agent's reply that is still streaming |
Agent actions
| Action | Description |
|---|---|
PostedComment | Post a comment: thread id to reply, or null for a new thread. Mention with "@Name" (see mentionable); mentioning an agent starts its work |
EditedComment | Change the text of one of the reader's own comments |
ConfirmedDeleteasks first | Delete one of the reader's own comments |
ClickedResolve | Resolve a thread (resolved: true) or reopen it (false) |
PickedReaction | React to a comment with an emoji (on: true), or take the reader's reaction back (on: false) |
ClickedStop | Stop an agent's reply that is still being written |
Accessibility
- Comments are a named region; each thread is a section named for the text it's about, and each comment an article named for its author, with a
<time>. - Mod+Enter posts. Typing
@opens a list of people and agents: Up and Down move, Enter or Tab picks, Escape closes, and the count of matches is announced. - While editing, Escape cancels and Mod+Enter saves. A refused post puts the draft back with the reason as an alert.
- Agents post, edit, delete, resolve and stop, only on comments the reader owns; deleting is marked as consequential.