Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(tasks): show artifact comment threads inline (#110830)

Shy Alter40047f4b2d10
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx
index 111f66fa3117..8a2fde3632ff 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx
@@ -19,6 +19,8 @@ import type {
} from 'products/tasks/frontend/generated/api.schemas'
import { TaskRuntimeEnumApi } from 'products/tasks/frontend/generated/api.schemas'
+import { expect, userEvent, waitFor } from 'storybook/test'
+
import { OriginProduct, Task, TaskRun, TaskRunEnvironment, TaskRunStatus } from '../../types/taskTypes'
import { TaskDetailPage } from './components/TaskDetailPage'
import { TaskRunTab } from './taskRunArtifacts'
@@ -837,3 +839,39 @@ export const ImageCommentPins: Story = {
parameters: { msw: { mocks: commentMocks() } },
render: () => <StoryPage fileName="trial-starts-by-step.svg" commentsOpen />,
}
+
+export const MarkdownCommentThread: Story = {
+ parameters: { msw: { mocks: commentMocks() } },
+ render: () => <StoryPage fileName={REPORT_FILE_NAME} />,
+ play: async ({ canvasElement }) => {
+ const highlight = await waitFor(
+ () => {
+ const element = canvasElement.querySelector<HTMLElement>(
+ '[data-attr="task-artifact-comment-highlight"]'
+ )
+ expect(element).not.toBeNull()
+ return element!
+ },
+ { timeout: 10_000 }
+ )
+ await userEvent.click(highlight)
+ },
+}
+
+export const ImageCommentThread: Story = {
+ parameters: { msw: { mocks: commentMocks() } },
+ render: () => <StoryPage fileName="trial-starts-by-step.svg" />,
+ play: async ({ canvasElement }) => {
+ const pin = await waitFor(
+ () => {
+ const element = canvasElement.querySelector<HTMLElement>(
+ '[data-attr="task-artifact-comment-pin-marker"]'
+ )
+ expect(element).not.toBeNull()
+ return element!
+ },
+ { timeout: 10_000 }
+ )
+ await userEvent.click(pin)
+ },
+}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentActions.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentActions.tsx
index f6149b2b859f..a5b7c4d95971 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentActions.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentActions.tsx
@@ -1,18 +1,15 @@
import { useActions, useValues } from 'kea'
-import { IconComment, IconPin } from '@posthog/icons'
-import { Button, Text, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill-primitives'
+import { IconPin } from '@posthog/icons'
+import { Button, Tooltip, TooltipContent, TooltipTrigger, cn } from '@posthog/quill-primitives'
import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
-import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
+import { ArtifactCommentsMenu } from './ArtifactCommentsMenu'
-/** The toolbar controls for comments: show the panel, and on an image, pin a comment to a spot. */
+/** The toolbar controls for comments: the comments menu, and on an image, pin a comment to a spot. */
export function ArtifactCommentActions({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
- const { openCount, pinMode } = useValues(taskArtifactCommentsLogic(logicProps))
+ const { pinMode } = useValues(taskArtifactCommentsLogic(logicProps))
const { setPinMode } = useActions(taskArtifactCommentsLogic(logicProps))
- const { commentsOpen } = useValues(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
- const { setCommentsOpen } = useActions(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
- const commentsLabel = commentsOpen ? 'Hide comments' : 'Show comments'
const pinLabel = pinMode ? 'Stop pinning' : 'Pin a comment to a spot on the image'
return (
<>
@@ -37,28 +34,7 @@ export function ArtifactCommentActions({ logicProps }: { logicProps: TaskArtifac
<TooltipContent>{pinLabel}</TooltipContent>
</Tooltip>
)}
- <Tooltip>
- <TooltipTrigger
- delay={0}
- render={
- <Button
- aria-label={openCount > 0 ? `${commentsLabel}, ${openCount} open` : commentsLabel}
- aria-pressed={commentsOpen}
- className={cn(commentsOpen && 'bg-fill-selected')}
- onClick={() => setCommentsOpen(!commentsOpen)}
- data-attr="task-artifact-comments-toggle"
- />
- }
- >
- <IconComment />
- {openCount > 0 && (
- <Text size="xs" render={<span />} className="tabular-nums">
- {openCount}
- </Text>
- )}
- </TooltipTrigger>
- <TooltipContent>{commentsLabel}</TooltipContent>
- </Tooltip>
+ <ArtifactCommentsMenu logicProps={logicProps} />
</>
)
}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx
index 5f25931448b3..83301b266850 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx
@@ -1,7 +1,7 @@
import { useActions, useValues } from 'kea'
import { useEffect, useRef } from 'react'
-import { IconCheck, IconPin, IconRefresh } from '@posthog/icons'
+import { IconCheck, IconPin, IconRefresh, IconX } from '@posthog/icons'
import { Badge, Button, Text, ThreadItemAction, ThreadItemGroup, cn } from '@posthog/quill-primitives'
import { ArtifactCommentThread } from '../artifactComments'
@@ -13,9 +13,11 @@ import { ArtifactCommentEntry } from './ArtifactCommentEntry'
export function ArtifactCommentThreadCard({
logicProps,
thread,
+ inline = false,
}: {
logicProps: TaskArtifactCommentsLogicProps
thread: ArtifactCommentThread
+ inline?: boolean
}): JSX.Element {
const { activeThreadId, writing, drafts } = useValues(taskArtifactCommentsLogic(logicProps))
const { activateThread, setThreadResolved, replyToThread, setDraft } = useActions(
@@ -28,10 +30,10 @@ export function ArtifactCommentThreadCard({
// A click on a highlight or a pin in the preview brings its thread into view.
useEffect(() => {
- if (active) {
+ if (active && !inline) {
ref.current?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
}
- }, [active])
+ }, [active, inline])
const resolveAction = (
<ThreadItemAction
@@ -52,6 +54,70 @@ export function ArtifactCommentThreadCard({
? `Comments on pin ${thread.pinNumber}`
: 'Comments on this file'
+ if (inline) {
+ return (
+ <section
+ aria-label={anchorLabel}
+ className="flex min-h-0 flex-col"
+ data-attr="task-artifact-comment-thread"
+ >
+ <div className="flex min-w-0 items-start gap-2 border-b border-border py-2 pr-1 pl-3">
+ <div className="flex min-w-0 flex-1 flex-wrap items-center gap-1">
+ {anchor?.kind === 'text' && (
+ <Text
+ size="xs"
+ variant="muted"
+ render={<span />}
+ className="line-clamp-2 w-full border-l-2 border-warning pl-2 italic"
+ >
+ {anchor.quote}
+ </Text>
+ )}
+ {thread.pinNumber && (
+ <Badge variant="info">
+ <IconPin />
+ {`Pin ${thread.pinNumber}`}
+ </Badge>
+ )}
+ {thread.resolved && <Badge variant="completed">Resolved</Badge>}
+ </div>
+ <Button
+ size="icon-sm"
+ aria-label="Close comment"
+ onClick={() => activateThread(null)}
+ data-attr="task-artifact-comment-thread-close"
+ >
+ <IconX />
+ </Button>
+ </div>
+ <div className="min-h-0 flex-1 overflow-y-auto py-2">
+ <ThreadItemGroup>
+ <ArtifactCommentEntry comment={thread.root} actions={resolveAction} />
+ {thread.replies.map((reply) => (
+ <ArtifactCommentEntry key={reply.id} comment={reply} />
+ ))}
+ </ThreadItemGroup>
+ </div>
+ {!thread.resolved && (
+ <div className="border-t border-border p-2">
+ <ArtifactCommentComposer
+ value={drafts[rootId] ?? ''}
+ onChange={(value) => setDraft(rootId, value)}
+ onSubmit={() => replyToThread(rootId)}
+ saving={writing === rootId}
+ busy={!!writing && writing !== rootId}
+ label="Reply"
+ placeholder="Reply"
+ submitLabel="Reply"
+ rows={2}
+ dataAttr="task-artifact-comment-reply"
+ />
+ </div>
+ )}
+ </section>
+ )
+ }
+
return (
<section
ref={ref}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx
new file mode 100644
index 000000000000..2b5903e657d5
--- /dev/null
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx
@@ -0,0 +1,266 @@
+import { useActions, useValues } from 'kea'
+import { Fragment } from 'react'
+
+import { IconComment, IconPin, IconWarning } from '@posthog/icons'
+import {
+ Avatar,
+ AvatarFallback,
+ Badge,
+ Button,
+ Empty,
+ EmptyContent,
+ EmptyDescription,
+ EmptyHeader,
+ EmptyMedia,
+ EmptyTitle,
+ Label,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+ Separator,
+ Skeleton,
+ SkeletonText,
+ Switch,
+ Text,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+ cn,
+} from '@posthog/quill-primitives'
+
+import { dayjs } from 'lib/dayjs'
+import { fullNameOrEmail } from 'lib/utils/strings'
+
+import { TaskUserAvatar } from 'products/tasks/frontend/spaces/TaskUserAvatar'
+
+import { ArtifactCommentThread, supportsSelectionComments } from '../artifactComments'
+import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
+import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
+import { ArtifactCommentComposer } from './ArtifactCommentComposer'
+import { ArtifactCommentThreadCard } from './ArtifactCommentThreadCard'
+
+function emptyHint(kind: TaskArtifactCommentsLogicProps['kind']): string {
+ if (kind === 'image') {
+ return 'Comment on the whole image, or pin a comment to a spot on it.'
+ }
+ if (supportsSelectionComments(kind)) {
+ return 'Comment on the whole file, or select text in the preview to comment on it.'
+ }
+ return 'Comment on the whole file.'
+}
+
+function AnchoredThreadRow({ thread, onOpen }: { thread: ArtifactCommentThread; onOpen: () => void }): JSX.Element {
+ const name = thread.root.created_by ? fullNameOrEmail(thread.root.created_by) : 'Deleted user'
+ const { anchor } = thread
+ return (
+ <button
+ type="button"
+ className="flex w-full min-w-0 cursor-pointer gap-2 rounded-md px-2 py-2 text-left hover:bg-fill-hover focus-visible:bg-fill-hover focus-visible:outline-none"
+ onClick={onOpen}
+ data-attr="task-artifact-comments-menu-thread"
+ >
+ {thread.root.created_by ? (
+ <TaskUserAvatar
+ className="shrink-0"
+ user={{
+ uuid: thread.root.created_by.uuid,
+ email: thread.root.created_by.email,
+ first_name: thread.root.created_by.first_name ?? '',
+ last_name: thread.root.created_by.last_name ?? '',
+ }}
+ />
+ ) : (
+ <Avatar size="xs" className="shrink-0">
+ <AvatarFallback>?</AvatarFallback>
+ </Avatar>
+ )}
+ <span className="flex min-w-0 flex-1 flex-col gap-0.5">
+ <span className="flex min-w-0 items-baseline gap-1.5">
+ <Text size="xs" weight="medium" className="truncate" render={<span />}>
+ {name}
+ </Text>
+ <Text size="xxs" variant="muted" className="shrink-0" render={<span />}>
+ {dayjs(thread.root.created_at).fromNow()}
+ </Text>
+ </span>
+ {anchor?.kind === 'text' && (
+ <Text
+ size="xs"
+ variant="muted"
+ render={<span />}
+ className="line-clamp-1 border-l-2 border-warning pl-1.5 italic"
+ >
+ {anchor.quote}
+ </Text>
+ )}
+ <Text size="xs" render={<span />} className="line-clamp-2 break-words">
+ {thread.root.content}
+ </Text>
+ {(thread.pinNumber || thread.resolved || thread.replies.length > 0) && (
+ <span className="flex flex-wrap items-center gap-1">
+ {thread.pinNumber && (
+ <Badge variant="info">
+ <IconPin />
+ {`Pin ${thread.pinNumber}`}
+ </Badge>
+ )}
+ {thread.resolved && <Badge variant="completed">Resolved</Badge>}
+ {thread.replies.length > 0 && (
+ <Text size="xxs" variant="muted" render={<span />}>
+ {thread.replies.length === 1 ? '1 reply' : `${thread.replies.length} replies`}
+ </Text>
+ )}
+ </span>
+ )}
+ </span>
+ </button>
+ )
+}
+
+function ThreadList({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
+ const { visibleThreads, threads, commentsLoadFailed, commentsLoading } = useValues(
+ taskArtifactCommentsLogic(logicProps)
+ )
+ const { loadComments, activateThread } = useActions(taskArtifactCommentsLogic(logicProps))
+ const { setCommentsOpen } = useActions(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
+ if (!threads) {
+ if (commentsLoadFailed) {
+ return (
+ <Empty className="border-0">
+ <EmptyHeader>
+ <EmptyMedia variant="icon">
+ <IconWarning />
+ </EmptyMedia>
+ <EmptyTitle>Comments didn't load</EmptyTitle>
+ <EmptyDescription>Check your connection and try again.</EmptyDescription>
+ </EmptyHeader>
+ <EmptyContent>
+ <Button
+ variant="outline"
+ loading={commentsLoading}
+ onClick={() => loadComments()}
+ data-attr="task-artifact-comments-retry"
+ >
+ Try again
+ </Button>
+ </EmptyContent>
+ </Empty>
+ )
+ }
+ return (
+ <div className="flex flex-col gap-4 p-3">
+ {[0, 1].map((index) => (
+ <div key={index} className="flex gap-2">
+ <Skeleton className="size-6 shrink-0 rounded-full" />
+ <SkeletonText lines={2} className="flex-1" />
+ </div>
+ ))}
+ </div>
+ )
+ }
+ if (!visibleThreads || visibleThreads.length === 0) {
+ return (
+ <Empty className="border-0">
+ <EmptyHeader>
+ <EmptyMedia variant="icon">
+ <IconComment />
+ </EmptyMedia>
+ <EmptyTitle>{threads.length > 0 ? 'No open comments' : 'No comments yet'}</EmptyTitle>
+ <EmptyDescription>{emptyHint(logicProps.kind)}</EmptyDescription>
+ </EmptyHeader>
+ </Empty>
+ )
+ }
+ return (
+ <div className="flex min-h-0 flex-col gap-1 overflow-y-auto p-1">
+ {visibleThreads.map((thread, index) => (
+ <Fragment key={thread.root.id}>
+ {index > 0 && <Separator />}
+ {thread.anchor && thread.anchor.kind !== 'document' ? (
+ <AnchoredThreadRow
+ thread={thread}
+ onOpen={() => {
+ setCommentsOpen(false)
+ activateThread(thread.root.id, 'menu')
+ }}
+ />
+ ) : (
+ <ArtifactCommentThreadCard logicProps={logicProps} thread={thread} />
+ )}
+ </Fragment>
+ ))}
+ </div>
+ )
+}
+
+export function ArtifactCommentsMenu({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
+ const { openCount, resolvedCount, showResolved, drafts, writing } = useValues(taskArtifactCommentsLogic(logicProps))
+ const { setShowResolved, setDraft, submitComment } = useActions(taskArtifactCommentsLogic(logicProps))
+ const { commentsOpen } = useValues(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
+ const { setCommentsOpen } = useActions(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
+ const label = openCount > 0 ? `Comments, ${openCount} open` : 'Comments'
+ const switchId = `task-artifact-comments-show-resolved-${logicProps.artifactId}`
+ return (
+ <Popover open={commentsOpen} onOpenChange={(open: boolean) => setCommentsOpen(open)}>
+ <Tooltip>
+ <TooltipTrigger delay={0} render={<span className="inline-flex" />}>
+ <PopoverTrigger
+ render={
+ <Button
+ aria-label={label}
+ className={cn(commentsOpen && 'bg-fill-selected')}
+ data-attr="task-artifact-comments-toggle"
+ />
+ }
+ >
+ <IconComment />
+ {openCount > 0 && (
+ <Text size="xs" render={<span />} className="tabular-nums">
+ {openCount}
+ </Text>
+ )}
+ </PopoverTrigger>
+ </TooltipTrigger>
+ <TooltipContent>Comments</TooltipContent>
+ </Tooltip>
+ <PopoverContent
+ align="end"
+ className="max-h-[min(560px,var(--available-height))] w-80 gap-0 overflow-hidden p-0"
+ data-attr="task-artifact-comments-menu"
+ >
+ <div className="flex shrink-0 items-center gap-2 border-b border-border px-3 py-2">
+ <Text size="xs" weight="medium" variant="muted" render={<span />}>
+ Comments
+ </Text>
+ {resolvedCount > 0 && (
+ <div className="ml-auto flex items-center gap-2">
+ <Switch
+ id={switchId}
+ size="sm"
+ checked={showResolved}
+ onCheckedChange={(checked: boolean) => setShowResolved(checked)}
+ data-attr="task-artifact-comments-show-resolved"
+ />
+ <Label htmlFor={switchId} className="text-xs">
+ {`Show resolved (${resolvedCount})`}
+ </Label>
+ </div>
+ )}
+ </div>
+ <div className="shrink-0 border-b border-border p-2">
+ <ArtifactCommentComposer
+ value={drafts.document ?? ''}
+ onChange={(value) => setDraft('document', value)}
+ onSubmit={() => submitComment('document')}
+ saving={writing === 'document'}
+ busy={!!writing && writing !== 'document'}
+ label="Comment on this file"
+ placeholder="Comment on this file"
+ dataAttr="task-artifact-comment-document"
+ />
+ </div>
+ <ThreadList logicProps={logicProps} />
+ </PopoverContent>
+ </Popover>
+ )
+}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsPanel.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsPanel.tsx
deleted file mode 100644
index 86f3ce84ffe5..000000000000
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsPanel.tsx
+++ /dev/null
@@ -1,170 +0,0 @@
-import { useActions, useValues } from 'kea'
-import { Fragment } from 'react'
-
-import { IconComment, IconWarning, IconX } from '@posthog/icons'
-import {
- Button,
- Empty,
- EmptyContent,
- EmptyDescription,
- EmptyHeader,
- EmptyMedia,
- EmptyTitle,
- Label,
- Separator,
- Skeleton,
- SkeletonText,
- Switch,
- Text,
- Tooltip,
- TooltipContent,
- TooltipTrigger,
-} from '@posthog/quill-primitives'
-
-import { supportsSelectionComments } from '../artifactComments'
-import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
-import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
-import { ArtifactCommentComposer } from './ArtifactCommentComposer'
-import { ArtifactCommentThreadCard } from './ArtifactCommentThreadCard'
-
-function emptyHint(kind: TaskArtifactCommentsLogicProps['kind']): string {
- if (kind === 'image') {
- return 'Comment on the whole image above, or pin a comment to a spot on it.'
- }
- if (supportsSelectionComments(kind)) {
- return 'Comment on the whole file above, or select text in the preview to comment on it.'
- }
- return 'Comment on the whole file above.'
-}
-
-function ThreadList({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
- const { visibleThreads, threads, commentsLoadFailed, commentsLoading } = useValues(
- taskArtifactCommentsLogic(logicProps)
- )
- const { loadComments } = useActions(taskArtifactCommentsLogic(logicProps))
- if (!threads) {
- if (commentsLoadFailed) {
- return (
- <Empty className="min-h-0 flex-1 border-0">
- <EmptyHeader>
- <EmptyMedia variant="icon">
- <IconWarning />
- </EmptyMedia>
- <EmptyTitle>Comments didn't load</EmptyTitle>
- <EmptyDescription>Check your connection and try again.</EmptyDescription>
- </EmptyHeader>
- <EmptyContent>
- <Button
- variant="outline"
- loading={commentsLoading}
- onClick={() => loadComments()}
- data-attr="task-artifact-comments-retry"
- >
- Try again
- </Button>
- </EmptyContent>
- </Empty>
- )
- }
- return (
- <div className="flex flex-col gap-4 p-3">
- {[0, 1].map((index) => (
- <div key={index} className="flex gap-2">
- <Skeleton className="size-6 shrink-0 rounded-full" />
- <SkeletonText lines={2} className="flex-1" />
- </div>
- ))}
- </div>
- )
- }
- if (!visibleThreads || visibleThreads.length === 0) {
- return (
- <Empty className="min-h-0 flex-1 border-0">
- <EmptyHeader>
- <EmptyMedia variant="icon">
- <IconComment />
- </EmptyMedia>
- <EmptyTitle>{threads.length > 0 ? 'No open comments' : 'No comments yet'}</EmptyTitle>
- <EmptyDescription>{emptyHint(logicProps.kind)}</EmptyDescription>
- </EmptyHeader>
- </Empty>
- )
- }
- return (
- <div className="flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto p-1">
- {visibleThreads.map((thread, index) => (
- <Fragment key={thread.root.id}>
- {index > 0 && <Separator />}
- <ArtifactCommentThreadCard logicProps={logicProps} thread={thread} />
- </Fragment>
- ))}
- </div>
- )
-}
-
-/** The comment threads on the open artifact version, with a box to comment on the whole file. */
-export function ArtifactCommentsPanel({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
- const { resolvedCount, showResolved, drafts, writing } = useValues(taskArtifactCommentsLogic(logicProps))
- const { setShowResolved, setDraft, submitComment } = useActions(taskArtifactCommentsLogic(logicProps))
- const { setCommentsOpen } = useActions(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
- const switchId = `task-artifact-comments-show-resolved-${logicProps.artifactId}`
- return (
- <aside
- aria-label="Comments"
- // Below this width the panel covers the preview, so the preview keeps a readable width.
- className="absolute inset-y-0 right-0 z-20 flex w-full max-w-80 flex-col border-l border-border bg-background shadow-md @[64rem]/main-content:static @[64rem]/main-content:w-80 @[64rem]/main-content:shrink-0 @[64rem]/main-content:shadow-none"
- data-attr="task-artifact-comments-panel"
- >
- <div className="flex h-10 shrink-0 items-center gap-2 border-b border-border px-3">
- <Text size="xs" weight="medium" variant="muted" render={<span />}>
- Comments
- </Text>
- <div className="ml-auto flex items-center gap-2">
- {resolvedCount > 0 && (
- <>
- <Switch
- id={switchId}
- size="sm"
- checked={showResolved}
- onCheckedChange={(checked: boolean) => setShowResolved(checked)}
- data-attr="task-artifact-comments-show-resolved"
- />
- <Label htmlFor={switchId} className="text-xs">
- {`Show resolved (${resolvedCount})`}
- </Label>
- </>
- )}
- <Tooltip>
- <TooltipTrigger
- delay={0}
- render={
- <Button
- size="icon-sm"
- aria-label="Close comments"
- onClick={() => setCommentsOpen(false)}
- data-attr="task-artifact-comments-close"
- />
- }
- >
- <IconX />
- </TooltipTrigger>
- <TooltipContent>Close comments</TooltipContent>
- </Tooltip>
- </div>
- </div>
- <div className="shrink-0 border-b border-border p-2">
- <ArtifactCommentComposer
- value={drafts.document ?? ''}
- onChange={(value) => setDraft('document', value)}
- onSubmit={() => submitComment('document')}
- saving={writing === 'document'}
- busy={!!writing && writing !== 'document'}
- label="Comment on this file"
- placeholder="Comment on this file"
- dataAttr="task-artifact-comment-document"
- />
- </div>
- <ThreadList logicProps={logicProps} />
- </aside>
- )
-}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactImagePins.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactImagePins.tsx
index 46cdd30f01f7..2b62c302aea2 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactImagePins.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactImagePins.tsx
@@ -1,5 +1,5 @@
import { useActions, useValues } from 'kea'
-import { useEffect, useRef } from 'react'
+import { CSSProperties, useEffect, useRef } from 'react'
import { cn } from '@posthog/quill-primitives'
@@ -7,6 +7,7 @@ import { fullNameOrEmail } from 'lib/utils/strings'
import type { RegionCommentAnchor } from '../artifactComments'
import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
+import { ArtifactInlineThread } from './ArtifactInlineThread'
import { ArtifactPendingComment } from './ArtifactPendingComment'
/** The point of a pin sits on its region's bottom left corner, the same spot Desktop draws it on. */
@@ -14,6 +15,19 @@ function pinStyle(anchor: RegionCommentAnchor): { left: string; top: string } {
return { left: `${anchor.x * 100}%`, top: `${(anchor.y + anchor.height) * 100}%` }
}
+function besidePinStyle(region: RegionCommentAnchor): CSSProperties {
+ return {
+ ...(region.y < 0.5
+ ? { top: `${(region.y + region.height) * 100}%` }
+ : { bottom: `${(1 - region.y - region.height) * 100}%` }),
+ ...(region.x < 0.5 ? { left: `${region.x * 100}%` } : { right: `${(1 - region.x - region.width) * 100}%` }),
+ }
+}
+
+function besidePinClassName(region: RegionCommentAnchor): string {
+ return cn('pointer-events-auto', region.y < 0.5 ? 'mt-1' : 'mb-8')
+}
+
function PinMarker({
label,
number,
@@ -57,7 +71,7 @@ export function ArtifactImagePins({ logicProps }: { logicProps: TaskArtifactComm
const { activateThread } = useActions(taskArtifactCommentsLogic(logicProps))
const rootRef = useRef<HTMLDivElement>(null)
- // A pick in the comments panel scrolls its pin into view when the image is zoomed in.
+ // A pick in the comments menu scrolls its pin into view when the image is zoomed in.
useEffect(() => {
if (activeThreadId) {
rootRef.current
@@ -67,6 +81,8 @@ export function ArtifactImagePins({ logicProps }: { logicProps: TaskArtifactComm
}, [activeThreadId])
const pendingRegion = pendingAnchor?.kind === 'region' ? pendingAnchor : null
+ const activeAnchor = anchoredThreads.find((thread) => thread.root.id === activeThreadId)?.anchor
+ const activeRegion = activeAnchor?.kind === 'region' ? activeAnchor : null
return (
<div ref={rootRef} className="pointer-events-none absolute inset-0">
{anchoredThreads.map((thread) => {
@@ -91,19 +107,19 @@ export function ArtifactImagePins({ logicProps }: { logicProps: TaskArtifactComm
<PinMarker label="New pin" number={null} active anchor={pendingRegion} />
<ArtifactPendingComment
logicProps={logicProps}
- className={cn('pointer-events-auto', pendingRegion.y < 0.5 ? 'mt-1' : 'mb-8')}
+ className={besidePinClassName(pendingRegion)}
// The box opens toward the middle of the image, so it stays on the image as far as it can.
- style={{
- ...(pendingRegion.y < 0.5
- ? { top: `${(pendingRegion.y + pendingRegion.height) * 100}%` }
- : { bottom: `${(1 - pendingRegion.y - pendingRegion.height) * 100}%` }),
- ...(pendingRegion.x < 0.5
- ? { left: `${pendingRegion.x * 100}%` }
- : { right: `${(1 - pendingRegion.x - pendingRegion.width) * 100}%` }),
- }}
+ style={besidePinStyle(pendingRegion)}
/>
</>
)}
+ {activeRegion && !pendingRegion && (
+ <ArtifactInlineThread
+ logicProps={logicProps}
+ className={besidePinClassName(activeRegion)}
+ style={besidePinStyle(activeRegion)}
+ />
+ )}
</div>
)
}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactInlineThread.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactInlineThread.tsx
new file mode 100644
index 000000000000..27ef144174b2
--- /dev/null
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactInlineThread.tsx
@@ -0,0 +1,74 @@
+import { useActions, useValues } from 'kea'
+import { CSSProperties, useEffect, useRef } from 'react'
+
+import { cn } from '@posthog/quill-primitives'
+
+import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
+import { ArtifactCommentThreadCard } from './ArtifactCommentThreadCard'
+
+export const INLINE_THREAD_WIDTH_PX = 320
+
+const KEEP_OPEN_SELECTOR =
+ '[data-quill-portal], [data-attr="task-artifact-comment-highlight"], [data-attr="task-artifact-comment-pin-marker"], [data-attr="task-artifact-comments-toggle"]'
+
+export function ArtifactInlineThread({
+ logicProps,
+ style,
+ className,
+}: {
+ logicProps: TaskArtifactCommentsLogicProps
+ style: CSSProperties
+ className?: string
+}): JSX.Element | null {
+ const { activeThreadId, threads } = useValues(taskArtifactCommentsLogic(logicProps))
+ const { activateThread } = useActions(taskArtifactCommentsLogic(logicProps))
+ const ref = useRef<HTMLDivElement>(null)
+ const thread = threads?.find((candidate) => candidate.root.id === activeThreadId) ?? null
+ const open = !!thread
+
+ useEffect(() => {
+ if (!open) {
+ return
+ }
+ const onKeyDown = (event: KeyboardEvent): void => {
+ if (event.key === 'Escape') {
+ activateThread(null)
+ }
+ }
+ const onPointerDown = (event: PointerEvent): void => {
+ const target = event.target
+ if (target instanceof Element && (ref.current?.contains(target) || target.closest(KEEP_OPEN_SELECTOR))) {
+ return
+ }
+ activateThread(null)
+ }
+ window.addEventListener('keydown', onKeyDown)
+ document.addEventListener('pointerdown', onPointerDown)
+ return () => {
+ window.removeEventListener('keydown', onKeyDown)
+ document.removeEventListener('pointerdown', onPointerDown)
+ }
+ }, [open, activateThread])
+
+ if (!thread) {
+ return null
+ }
+ return (
+ <div
+ ref={ref}
+ data-quill
+ role="dialog"
+ aria-label="Comment thread"
+ className={cn(
+ 'absolute z-30 flex max-h-[480px] w-80 max-w-[calc(100%-16px)] flex-col overflow-hidden rounded-lg border border-border bg-background text-left shadow-lg',
+ className
+ )}
+ style={style}
+ onPointerDown={(event) => event.stopPropagation()}
+ onClick={(event) => event.stopPropagation()}
+ data-attr="task-artifact-comment-inline-thread"
+ >
+ <ArtifactCommentThreadCard logicProps={logicProps} thread={thread} inline />
+ </div>
+ )
+}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx
index b575fe8d0e51..386fbfd8c720 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx
@@ -7,6 +7,7 @@ import { fullNameOrEmail } from 'lib/utils/strings'
import { createTextCommentAnchor, resolveTextCommentAnchor } from '../artifactComments'
import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
+import { ArtifactInlineThread, INLINE_THREAD_WIDTH_PX } from './ArtifactInlineThread'
import { ArtifactPendingComment, PENDING_COMMENT_WIDTH_PX } from './ArtifactPendingComment'
const EDGE_MARGIN_PX = 8
@@ -176,7 +177,7 @@ export function ArtifactTextAnnotations({
}
}, [])
- // A pick in the comments panel scrolls its quote into view.
+ // A pick in the comments menu scrolls its quote into view.
useEffect(() => {
const root = rootRef.current
const thread = textThreads.find((candidate) => candidate.root.id === activeThreadId)
@@ -256,6 +257,10 @@ export function ArtifactTextAnnotations({
}
})
+ const activeEnd = rects.filter((rect) => rect.id === activeThreadId).at(-1)
+ const pendingText = pendingAnchor?.kind === 'text' && !!pendingPosition
+ const maxThreadLeft = (containerRef.current?.clientWidth ?? 0) - INLINE_THREAD_WIDTH_PX - EDGE_MARGIN_PX
+
return (
<div ref={containerRef} className="relative">
<div ref={rootRef}>{children}</div>
@@ -281,6 +286,15 @@ export function ArtifactTextAnnotations({
/>
))}
</div>
+ {activeEnd && !pendingText && (
+ <ArtifactInlineThread
+ logicProps={logicProps}
+ style={{
+ left: Math.max(EDGE_MARGIN_PX, Math.min(activeEnd.left, maxThreadLeft)),
+ top: activeEnd.top + activeEnd.height + 6,
+ }}
+ />
+ )}
{pendingAnchor?.kind === 'text' && pendingPosition && (
<ArtifactPendingComment
logicProps={logicProps}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
index 3f26eae50307..e314f79e8a79 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
@@ -93,7 +93,6 @@ import {
} from '../taskRunArtifacts'
import { FullPageSource, artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
import { ArtifactCommentActions } from './ArtifactCommentActions'
-import { ArtifactCommentsPanel } from './ArtifactCommentsPanel'
import { ArtifactEditor } from './ArtifactEditor'
import { ArtifactEditToolbar } from './ArtifactEditToolbar'
import { ArtifactIcon } from './ArtifactIcon'
@@ -917,17 +916,13 @@ function PreviewSurface({ taskId, mode }: { taskId: string; mode: PreviewMode })
)
}
-/** The preview, with the comments panel beside it when it is open. */
function PreviewBody({ taskId, mode }: { taskId: string; mode: PreviewMode }): JSX.Element {
- const { selectedArtifact, selectedKind, commentsOpen } = useValues(taskRunArtifactsLogic({ taskId }))
- const comments = commentLogicProps(taskId, selectedArtifact, selectedKind)
return (
<div className="relative flex min-h-0 flex-1">
<div className="flex min-w-0 flex-1 flex-col">
<OlderVersionNotice taskId={taskId} />
<PreviewSurface taskId={taskId} mode={mode} />
</div>
- {comments && commentsOpen && <ArtifactCommentsPanel key={comments.artifactId} logicProps={comments} />}
</div>
)
}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskArtifactCommentsLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskArtifactCommentsLogic.ts
index 36b80c8753a7..6334961079d1 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskArtifactCommentsLogic.ts
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskArtifactCommentsLogic.ts
@@ -18,7 +18,6 @@ import {
buildArtifactCommentThreads,
} from './artifactComments'
import type { ArtifactPreviewKind } from './taskRunArtifacts'
-import { taskRunArtifactsLogic } from './taskRunArtifactsLogic'
const COMMENTS_POLL_INTERVAL_MS = 10_000
// The comments list pages at 100. This many pages covers any real artifact, the same cap as Desktop.
@@ -34,6 +33,8 @@ export interface TaskArtifactCommentsLogicProps {
/** What a draft or a write is for: a new comment on the whole file, the pending pin or selection, or a thread. */
export type CommentTarget = 'document' | 'pending' | string
+export type ArtifactThreadSource = 'preview' | 'menu' | 'created'
+
/** Where the pending selection composer sits, in pixels inside the scroll content of the preview. */
export interface PendingPosition {
left: number
@@ -83,11 +84,12 @@ export interface taskArtifactCommentsLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface taskArtifactCommentsLogicActions {
- setCommentsOpen: (open: boolean) => {
- open: boolean
- } // taskRunArtifactsLogic
- activateThread: (id: string | null) => {
+ activateThread: (
+ id: string | null,
+ source?: ArtifactThreadSource
+ ) => {
id: string | null
+ source: ArtifactThreadSource
}
dismissPending: () => {
value: true
@@ -178,9 +180,8 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
props({} as TaskArtifactCommentsLogicProps),
key((props) => `${props.taskId}:${props.artifactId}`),
path((key) => ['products', 'posthog_ai', 'frontend', 'scenes', 'TaskTracker', 'taskArtifactCommentsLogic', key]),
- connect((props: TaskArtifactCommentsLogicProps) => ({
+ connect(() => ({
values: [projectLogic, ['currentProjectId']],
- actions: [taskRunArtifactsLogic({ taskId: props.taskId }), ['setCommentsOpen']],
})),
actions({
setDraft: (target: CommentTarget, draft: string) => ({ target, draft }),
@@ -195,7 +196,7 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
setThreadResolved: (rootId: string, resolved: boolean) => ({ rootId, resolved }),
/** The write for `target` ended. `target` is null when it failed. */
writeFinished: (target: CommentTarget | null) => ({ target }),
- activateThread: (id: string | null) => ({ id }),
+ activateThread: (id: string | null, source: ArtifactThreadSource = 'preview') => ({ id, source }),
setShowResolved: (showResolved: boolean) => ({ showResolved }),
}),
loaders(({ props, values }) => ({
@@ -241,6 +242,7 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
{
setPendingAnchor: (_, { anchor }) => anchor,
dismissPending: () => null,
+ activateThread: (state, { id }) => (id ? null : state),
setPinMode: (state, { pinMode }) => (pinMode ? state : null),
writeFinished: (state, { target }) => (target === 'pending' ? null : state),
},
@@ -263,7 +265,14 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
writeFinished: () => null,
},
],
- activeThreadId: [null as string | null, { activateThread: (_, { id }) => id }],
+ activeThreadId: [
+ null as string | null,
+ {
+ activateThread: (_, { id }) => id,
+ setPendingAnchor: () => null,
+ setPinMode: (state, { pinMode }) => (pinMode ? null : state),
+ },
+ ],
showResolved: [false, { setShowResolved: (_, { showResolved }) => showResolved }],
commentsLoadFailed: [false, { loadCommentsSuccess: () => false, loadCommentsFailure: () => true }],
}),
@@ -326,11 +335,6 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
}
}
return {
- setPinMode: ({ pinMode }) => {
- if (pinMode) {
- actions.setCommentsOpen(true)
- }
- },
setPendingAnchor: ({ anchor }) => {
// pinned: analytics event name and properties. Renaming them breaks insights.
posthog.capture('task artifact comment started', {
@@ -356,9 +360,8 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
})
if (target === 'pending') {
window.getSelection()?.removeAllRanges()
+ actions.activateThread(saved.id, 'created')
}
- actions.setCommentsOpen(true)
- actions.activateThread(saved.id)
}
},
replyToThread: async ({ rootId }) => {
@@ -402,9 +405,14 @@ export const taskArtifactCommentsLogic = kea<taskArtifactCommentsLogicType>([
})
}
},
- activateThread: ({ id }) => {
- if (id) {
- actions.setCommentsOpen(true)
+ activateThread: ({ id, source }) => {
+ const thread = id ? values.threads?.find((candidate) => candidate.root.id === id) : null
+ if (thread && source !== 'created') {
+ posthog.capture('task artifact comment thread opened', {
+ anchor_kind: anchorKindLabel(thread.anchor),
+ kind: props.kind,
+ source,
+ })
}
},
loadCommentsSuccess: () => schedulePoll(),