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(posthog-ai): artifact comments as a read and reply page on phones (#111549)

Shy Alterba49903d8d07
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentComposer.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentComposer.tsx
index d252fb6e3e32..a6c49764c475 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentComposer.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentComposer.tsx
@@ -18,6 +18,7 @@ export function ArtifactCommentComposer({
quote,
autoFocus = false,
rows = 2,
+ showShortcut = true,
dataAttr,
}: {
value: string
@@ -35,6 +36,7 @@ export function ArtifactCommentComposer({
quote?: string
autoFocus?: boolean
rows?: number
+ showShortcut?: boolean
dataAttr: string
}): JSX.Element {
const submit = (): void => {
@@ -80,10 +82,12 @@ export function ArtifactCommentComposer({
data-attr={`${dataAttr}-input`}
/>
<div className="flex items-center justify-end gap-2">
- <KbdGroup className="mr-auto text-muted-foreground" aria-label="Keyboard shortcut to send">
- <Kbd>{isMac() ? '⌘' : 'Ctrl'}</Kbd>
- <Kbd>Enter</Kbd>
- </KbdGroup>
+ {showShortcut && (
+ <KbdGroup className="mr-auto text-muted-foreground" aria-label="Keyboard shortcut to send">
+ <Kbd>{isMac() ? '⌘' : 'Ctrl'}</Kbd>
+ <Kbd>Enter</Kbd>
+ </KbdGroup>
+ )}
{onCancel && (
<Button
type="button"
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx
index 5fb68a2531eb..6aad6ec0828a 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentThreadCard.tsx
@@ -6,6 +6,7 @@ import { Badge, Button, Text, cn } from '@posthog/quill-primitives'
import { ArtifactCommentThread, threadAnchorLabel } from '../artifactComments'
import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
+import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
import { ArtifactCommentComposer } from './ArtifactCommentComposer'
import { ArtifactCommentThreadEntries } from './ArtifactCommentThreadEntries'
@@ -19,6 +20,7 @@ export function ArtifactCommentThreadCard({
}): JSX.Element {
const { activeThreadId, writing, drafts } = useValues(taskArtifactCommentsLogic(logicProps))
const { activateThread, replyToThread, setDraft } = useActions(taskArtifactCommentsLogic(logicProps))
+ const { todayPhone } = useValues(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
const ref = useRef<HTMLElement>(null)
const rootId = thread.root.id
const active = activeThreadId === rootId
@@ -98,6 +100,7 @@ export function ArtifactCommentThreadCard({
placeholder="Reply"
submitLabel="Reply"
rows={1}
+ showShortcut={!todayPhone}
dataAttr="task-artifact-comment-reply"
/>
</div>
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx
index 2b5903e657d5..9bd9a244de7f 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsMenu.tsx
@@ -117,7 +117,13 @@ function AnchoredThreadRow({ thread, onOpen }: { thread: ArtifactCommentThread;
)
}
-function ThreadList({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
+export function ArtifactCommentThreadList({
+ logicProps,
+ cardsOnly = false,
+}: {
+ logicProps: TaskArtifactCommentsLogicProps
+ cardsOnly?: boolean
+}): JSX.Element {
const { visibleThreads, threads, commentsLoadFailed, commentsLoading } = useValues(
taskArtifactCommentsLogic(logicProps)
)
@@ -166,7 +172,11 @@ function ThreadList({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps
<IconComment />
</EmptyMedia>
<EmptyTitle>{threads.length > 0 ? 'No open comments' : 'No comments yet'}</EmptyTitle>
- <EmptyDescription>{emptyHint(logicProps.kind)}</EmptyDescription>
+ <EmptyDescription>
+ {cardsOnly
+ ? 'To add a comment, open this file on a larger screen.'
+ : emptyHint(logicProps.kind)}
+ </EmptyDescription>
</EmptyHeader>
</Empty>
)
@@ -176,7 +186,7 @@ function ThreadList({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps
{visibleThreads.map((thread, index) => (
<Fragment key={thread.root.id}>
{index > 0 && <Separator />}
- {thread.anchor && thread.anchor.kind !== 'document' ? (
+ {!cardsOnly && thread.anchor && thread.anchor.kind !== 'document' ? (
<AnchoredThreadRow
thread={thread}
onOpen={() => {
@@ -259,7 +269,7 @@ export function ArtifactCommentsMenu({ logicProps }: { logicProps: TaskArtifactC
dataAttr="task-artifact-comment-document"
/>
</div>
- <ThreadList logicProps={logicProps} />
+ <ArtifactCommentThreadList logicProps={logicProps} />
</PopoverContent>
</Popover>
)
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsPage.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsPage.tsx
new file mode 100644
index 000000000000..1e594d00f53d
--- /dev/null
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactCommentsPage.tsx
@@ -0,0 +1,87 @@
+import { useActions, useValues } from 'kea'
+
+import { IconChevronLeft, IconComment } from '@posthog/icons'
+import { Button, Label, Switch, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill-primitives'
+
+import { TaskArtifactCommentsLogicProps, taskArtifactCommentsLogic } from '../taskArtifactCommentsLogic'
+import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
+import { ArtifactCommentThreadList } from './ArtifactCommentsMenu'
+
+export function ArtifactCommentsButton({ logicProps }: { logicProps: TaskArtifactCommentsLogicProps }): JSX.Element {
+ const { openCount } = useValues(taskArtifactCommentsLogic(logicProps))
+ const { setCommentsOpen } = useActions(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
+ return (
+ <Button
+ size="lg"
+ aria-label={openCount > 0 ? `Comments, ${openCount} open` : 'Comments'}
+ onClick={() => setCommentsOpen(true)}
+ data-attr="task-artifact-comments-toggle"
+ >
+ <IconComment />
+ {openCount > 0 && (
+ <Text size="xs" render={<span />} className="tabular-nums">
+ {openCount}
+ </Text>
+ )}
+ </Button>
+ )
+}
+
+export function ArtifactCommentsPage({
+ logicProps,
+ artifactName,
+}: {
+ logicProps: TaskArtifactCommentsLogicProps
+ artifactName: string
+}): JSX.Element {
+ const { resolvedCount, showResolved } = useValues(taskArtifactCommentsLogic(logicProps))
+ const { setShowResolved } = useActions(taskArtifactCommentsLogic(logicProps))
+ const { setCommentsOpen } = useActions(taskRunArtifactsLogic({ taskId: logicProps.taskId }))
+ const switchId = `task-artifact-comments-page-show-resolved-${logicProps.artifactId}`
+ return (
+ <section aria-label="Comments" className="flex min-h-0 flex-1 flex-col" data-attr="task-artifact-comments-page">
+ <div className="flex h-12 shrink-0 items-center gap-1 border-b border-border bg-background px-1">
+ <Tooltip>
+ <TooltipTrigger
+ delay={0}
+ render={
+ <Button
+ size="icon-lg"
+ aria-label={`Back to ${artifactName}`}
+ onClick={() => setCommentsOpen(false)}
+ data-attr="task-artifact-comments-back"
+ />
+ }
+ >
+ <IconChevronLeft />
+ </TooltipTrigger>
+ <TooltipContent>{`Back to ${artifactName}`}</TooltipContent>
+ </Tooltip>
+ <span className="flex min-w-0 flex-1 flex-col pl-1">
+ <Text size="sm" weight="medium" render={<span />}>
+ Comments
+ </Text>
+ <Text size="xs" variant="muted" render={<span />} className="truncate">
+ {artifactName}
+ </Text>
+ </span>
+ {resolvedCount > 0 && (
+ <div className="flex shrink-0 items-center gap-2 pr-2">
+ <Switch
+ id={switchId}
+ checked={showResolved}
+ onCheckedChange={(checked: boolean) => setShowResolved(checked)}
+ data-attr="task-artifact-comments-show-resolved"
+ />
+ <Label htmlFor={switchId} className="text-xs">
+ {`Resolved (${resolvedCount})`}
+ </Label>
+ </div>
+ )}
+ </div>
+ <div className="flex min-h-0 flex-1 flex-col overflow-y-auto px-2">
+ <ArtifactCommentThreadList logicProps={logicProps} cardsOnly />
+ </div>
+ </section>
+ )
+}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx
index 386fbfd8c720..fbbc7c51ad53 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactTextAnnotations.tsx
@@ -94,9 +94,11 @@ function outermostRects(rects: Iterable<DOMRect>): DOMRect[] {
*/
export function ArtifactTextAnnotations({
logicProps,
+ selectable = true,
children,
}: {
logicProps: TaskArtifactCommentsLogicProps
+ selectable?: boolean
children: ReactNode
}): JSX.Element {
const logic = taskArtifactCommentsLogic(logicProps)
@@ -193,6 +195,9 @@ export function ArtifactTextAnnotations({
}, [activeThreadId])
useEffect(() => {
+ if (!selectable) {
+ return
+ }
let frame = 0
const readSelection = (): void => {
const root = rootRef.current
@@ -248,7 +253,7 @@ export function ArtifactTextAnnotations({
document.removeEventListener('pointerup', onRelease)
document.removeEventListener('keyup', onRelease)
}
- }, [logic, setPendingAnchor, dismissPending])
+ }, [logic, setPendingAnchor, dismissPending, selectable])
const firstRectIndex = new Map<string, number>()
rects.forEach((rect, index) => {
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
index 8815de15e658..b791623f9eb9 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx
@@ -98,7 +98,7 @@ import {
} from '../taskRunArtifacts'
import { FullPageSource, artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'
import { ArtifactCommentActions } from './ArtifactCommentActions'
-import { ArtifactCommentsMenu } from './ArtifactCommentsMenu'
+import { ArtifactCommentsButton, ArtifactCommentsPage } from './ArtifactCommentsPage'
import { ArtifactEditor } from './ArtifactEditor'
import { ArtifactEditToolbar } from './ArtifactEditToolbar'
import { ArtifactIcon } from './ArtifactIcon'
@@ -400,8 +400,15 @@ function ReferencePreview({ taskId, artifact }: { taskId: string; artifact: RunA
}
function ArtifactPreview({ taskId, mode }: { taskId: string; mode: PreviewMode }): JSX.Element | null {
- const { selectedArtifact, selectedKind, selectedText, selectedRun, currentProjectId, artifactTextLoading } =
- useValues(taskRunArtifactsLogic({ taskId }))
+ const {
+ selectedArtifact,
+ selectedKind,
+ selectedText,
+ selectedRun,
+ currentProjectId,
+ artifactTextLoading,
+ todayPhone,
+ } = useValues(taskRunArtifactsLogic({ taskId }))
const { ensureSelectedText, loadArtifactText } = useActions(taskRunArtifactsLogic({ taskId }))
useEffect(() => {
ensureSelectedText()
@@ -483,7 +490,7 @@ function ArtifactPreview({ taskId, mode }: { taskId: string; mode: PreviewMode }
// Desktop counts a markdown quote in the rendered page, not in the source, so only the page takes selections.
if (comments && supportsSelectionComments(selectedKind) && (mode === 'rendered' || selectedKind === 'text')) {
return (
- <ArtifactTextAnnotations key={selectedArtifact.id} logicProps={comments}>
+ <ArtifactTextAnnotations key={selectedArtifact.id} logicProps={comments} selectable={!todayPhone}>
{selectedKind === 'markdown' ? (
<MarkdownArticle text={selectedText.text} />
) : (
@@ -975,7 +982,7 @@ function PhoneArtifactHeader({
{`${artifactDetail(artifact)} · ${dayjs(artifact.uploaded_at).fromNow()}`}
</Text>
</span>
- {comments && <ArtifactCommentsMenu logicProps={comments} />}
+ {comments && <ArtifactCommentsButton logicProps={comments} />}
<Tooltip>
<TooltipTrigger
delay={0}
@@ -1123,7 +1130,7 @@ function PreviewBody({ taskId, mode }: { taskId: string; mode: PreviewMode }): J
}
function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {
- const { files, selectedArtifact, isEditing, todayPhone, showArtifactList } = useValues(
+ const { files, selectedArtifact, isEditing, todayPhone, showArtifactList, commentsOpen } = useValues(
taskRunArtifactsLogic({ taskId })
)
const { setActiveTab, reportFullPageOpened } = useActions(taskRunArtifactsLogic({ taskId }))
@@ -1176,6 +1183,13 @@ function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {
if (showArtifactList && !isEditing) {
return <ArtifactFileList taskId={taskId} size="sm" label="Artifacts" />
}
+ const phoneComments =
+ todayPhone && commentsOpen && selectedArtifact && !isEditing
+ ? commentLogicProps(taskId, selectedArtifact, artifactPreviewKind(selectedArtifact))
+ : null
+ if (phoneComments && selectedArtifact) {
+ return <ArtifactCommentsPage logicProps={phoneComments} artifactName={selectedArtifact.name} />
+ }
const toolbar =
todayPhone && selectedArtifact && !isEditing ? (
<PhoneArtifactHeader taskId={taskId} artifact={selectedArtifact} mode={mode} onModeChange={setMode} />
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.test.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.test.ts
index a14cc2099223..39771a7aebcd 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.test.ts
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.test.ts
@@ -111,9 +111,13 @@ describe('taskRunArtifactsLogic', () => {
expect.objectContaining({ kind: 'markdown', source: 'click' })
)
+ logic.actions.setCommentsOpen(true)
logic.actions.closeArtifact()
expect(logic.values.showArtifactList).toBe(true)
expect(router.values.searchParams).toEqual({ task: TASK_ID })
+
+ logic.actions.selectArtifact('report.md')
+ expect(logic.values.commentsOpen).toBe(false)
} finally {
Object.defineProperty(window, 'innerWidth', { configurable: true, value: originalWidth })
}
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts
index b5b1cf20dc01..4347a8be26b2 100644
--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts
+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts
@@ -573,7 +573,10 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([
// A phone shows the list until a file is picked. A wider window always shows the open file beside the list.
artifactOpen: [false, { selectArtifact: () => true, openFromUrl: () => true, closeArtifact: () => false }],
// The panel stays open across files, so a reviewer can read the comments on each one in turn.
- commentsOpen: [false, { setCommentsOpen: (_, { open }) => open }],
+ commentsOpen: [
+ false,
+ { setCommentsOpen: (_, { open }) => open, selectArtifact: () => false, closeArtifact: () => false },
+ ],
selectedFileKey: [
null as string | null,
{