: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(tasks): show file type icons on space feed artifact chips (#110455)
Shy Alter6c8a4aebc7ea
diff --git a/products/posthog_ai/frontend/api/taskArtifacts.ts b/products/posthog_ai/frontend/api/taskArtifacts.tsnew file mode 100644index 000000000000..6bbd47804c8c--- /dev/null+++ b/products/posthog_ai/frontend/api/taskArtifacts.ts@@ -0,0 +1,17 @@+// The files a task run hands back, for hosts that show them outside the task page, such as space feed cards.+//+// Kept apart from `./primitives` on purpose: a feed card only needs the icon, the rules and the link, and+// `./primitives` statically pulls the thread presenters and the product data-tool widgets into its chunk.+//+// Part of the `products/posthog_ai/frontend/api/<module>` public surface. Import from here, not from deep+// `../scenes/*` paths. See ../README.md for the tier model and ../AGENTS.md for the coupling rule.++export { captureArtifactChipClicked } from '../scenes/TaskTracker/artifactChipTelemetry'+export { ArtifactIcon } from '../scenes/TaskTracker/components/ArtifactIcon'+export {+ artifactPreviewKind,+ collectRunArtifacts,+ groupArtifactVersions,+ taskArtifactPath,+} from '../scenes/TaskTracker/taskRunArtifacts'+export type { ArtifactFile, ArtifactPreviewKind } from '../scenes/TaskTracker/taskRunArtifacts'diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/artifactChipTelemetry.ts b/products/posthog_ai/frontend/scenes/TaskTracker/artifactChipTelemetry.tsnew file mode 100644index 000000000000..37238af29b5b--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/artifactChipTelemetry.ts@@ -0,0 +1,20 @@+import posthog from 'posthog-js'++import type { ArtifactPreviewKind } from './taskRunArtifacts'++export interface ArtifactChipClick {+ kind: ArtifactPreviewKind+ inOverflow: boolean+ fileCount: number+ surface: 'space_feed'+}++export function captureArtifactChipClicked({ kind, inOverflow, fileCount, surface }: ArtifactChipClick): void {+ // pinned: analytics event name and properties. Renaming them breaks insights.+ posthog.capture('task artifact chip clicked', {+ kind,+ in_overflow: inOverflow,+ file_count: fileCount,+ surface,+ })+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactIcon.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactIcon.tsxnew file mode 100644index 000000000000..1371b65cfff0--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactIcon.tsx@@ -0,0 +1,73 @@+import {+ IconBolt,+ IconCode,+ IconCursor,+ IconDashboard,+ IconDatabase,+ IconDocument,+ IconExternal,+ IconFlask,+ IconGraph,+ IconImage,+ IconListCheck,+ IconMessage,+ IconNotebook,+ IconPeople,+ IconPerson,+ IconRewindPlay,+ IconSparkles,+ IconToggle,+ IconVideoCamera,+ IconWarning,+} from '@posthog/icons'++import type { TaskRunArtifactResponseApi } from 'products/tasks/frontend/generated/api.schemas'++import { ArtifactPreviewKind, LivingVersion, artifactPreviewKind, postHogObjectRef } from '../taskRunArtifacts'++function KindIcon({ kind, className }: { kind: ArtifactPreviewKind; className?: string }): JSX.Element {+ const Icon =+ kind === 'html'+ ? IconCode+ : kind === 'image'+ ? IconImage+ : kind === 'video'+ ? IconVideoCamera+ : kind === 'csv'+ ? IconDatabase+ : IconDocument+ return <Icon className={className} />+}++const OBJECT_KIND_ICONS: Record<string, typeof IconGraph> = {+ insight: IconGraph,+ hogql: IconDatabase,+ dashboard: IconDashboard,+ error: IconWarning,+ replay: IconRewindPlay,+ flag: IconToggle,+ experiment: IconFlask,+ survey: IconMessage,+ ticket: IconMessage,+ report: IconNotebook,+ trace: IconSparkles,+ eval: IconListCheck,+ event: IconBolt,+ cohort: IconPeople,+ action: IconCursor,+ person: IconPerson,+}++interface ArtifactIconProps {+ artifact: TaskRunArtifactResponseApi & { living?: LivingVersion }+ className?: string+}++export function ArtifactIcon({ artifact, className }: ArtifactIconProps): JSX.Element {+ const ref = postHogObjectRef(artifact)+ if (ref) {+ const Icon = OBJECT_KIND_ICONS[ref.objectKind] ?? IconExternal+ return <Icon className={className} />+ }+ return <KindIcon kind={artifactPreviewKind(artifact)} className={className} />+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsxindex fef25ad9529f..dc8232c764df 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx@@ -2,35 +2,17 @@ import { useActions, useValues } from 'kea'import { KeyboardEvent, Suspense, lazy, useEffect, useMemo, useState } from 'react'import {- IconBolt,IconCheck,IconChevronLeft,IconChevronRight,- IconCode,IconCollapse45,IconCopy,- IconCursor,- IconDashboard,- IconDatabase,IconDocument,IconDownload,IconExpand45,IconExternal,- IconFlask,- IconGraph,- IconImage,- IconListCheck,IconLock,- IconMessage,- IconNotebook,- IconPeople,- IconPerson,- IconRewindPlay,IconShare,- IconSparkles,- IconToggle,- IconVideoCamera,- IconWarning,} from '@posthog/icons'import {Badge,@@ -89,7 +71,6 @@ import { LinkPrimitive } from 'lib/lemon-ui/Link'import { withStrictCsp } from '../artifactHtml'import {ArtifactFile,- ArtifactPreviewKind,RunArtifact,TaskRunTab,artifactPreviewKind,@@ -102,6 +83,7 @@ import {postHogObjectRef,} from '../taskRunArtifacts'import { artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'+import { ArtifactIcon } from './ArtifactIcon'import { ArtifactImageViewer } from './ArtifactImageViewer'const MAX_CSV_ROWS = 500@@ -112,48 +94,6 @@ const ArtifactObjectEmbed = lazy(() =>type PreviewMode = 'rendered' | 'source'-function KindIcon({ kind, className }: { kind: ArtifactPreviewKind; className?: string }): JSX.Element {- const Icon =- kind === 'html'- ? IconCode- : kind === 'image'- ? IconImage- : kind === 'video'- ? IconVideoCamera- : kind === 'csv'- ? IconDatabase- : IconDocument- return <Icon className={className} />-}--const OBJECT_KIND_ICONS: Record<string, typeof IconGraph> = {- insight: IconGraph,- hogql: IconDatabase,- dashboard: IconDashboard,- error: IconWarning,- replay: IconRewindPlay,- flag: IconToggle,- experiment: IconFlask,- survey: IconMessage,- ticket: IconMessage,- report: IconNotebook,- trace: IconSparkles,- eval: IconListCheck,- event: IconBolt,- cohort: IconPeople,- action: IconCursor,- person: IconPerson,-}--function ArtifactIcon({ artifact, className }: { artifact: RunArtifact; className?: string }): JSX.Element {- const ref = postHogObjectRef(artifact)- if (ref) {- const Icon = OBJECT_KIND_ICONS[ref.objectKind] ?? IconExternal- return <Icon className={className} />- }- return <KindIcon kind={artifactPreviewKind(artifact)} className={className} />-}-/** Size for a file, the object kind for a cited PostHog object, where the agent sent a living document. */function artifactDetail(artifact: RunArtifact): string {if (artifact.living) {diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.tsindex ff7c231f6988..8951966a75dd 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifacts.ts@@ -1,3 +1,5 @@+import { combineUrl } from 'kea-router'+import type {TaskRunArtifactResponseApi,TaskRunLivingArtifactResponseApi,@@ -6,6 +8,20 @@ import type {export type TaskRunTab = 'conversation' | 'artifacts'+// pinned: URL search params. Shared links and the space feed's file chips use them.+// A link opens the tab on one file, and on one version when it is not the latest.+export const ARTIFACT_PARAM = 'artifact'+export const VERSION_PARAM = 'artifact_version'++/** The path that opens a task's Artifacts tab on one file. `fileKey` is an `ArtifactFile` key. */+export function taskArtifactPath(taskId: string, fileKey: string, versionId?: string | null): string {+ const params: Record<string, string> = { task: taskId, [ARTIFACT_PARAM]: fileKey }+ if (versionId) {+ params[VERSION_PARAM] = versionId+ }+ return combineUrl('/ai', params).url+}+export type ArtifactPreviewKind = 'markdown' | 'html' | 'image' | 'video' | 'csv' | 'text' | 'reference' | 'none'export const ARTIFACT_KIND_LABEL: Record<ArtifactPreviewKind, string> = {diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.tsindex ced4c99c64b0..b7183dabc528 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts+++ b/products/posthog_ai/frontend/scenes/TaskTracker/taskRunArtifactsLogic.ts@@ -13,7 +13,7 @@ import {selectors,} from 'kea'import { loaders } from 'kea-loaders'-import { actionToUrl, combineUrl, router, urlToAction } from 'kea-router'+import { actionToUrl, router, urlToAction } from 'kea-router'import posthog from 'posthog-js'import api from 'lib/api'@@ -34,6 +34,7 @@ import type {import type { TaskRun } from '../../types/taskTypes'import { taskDetailSceneLogic } from './taskDetailSceneLogic'import {+ ARTIFACT_PARAM,ArtifactFile,ArtifactPreviewKind,RunArtifact,@@ -45,6 +46,8 @@ import {livingArtifactFiles,livingArtifactsFromResponse,postHogObjectRef,+ taskArtifactPath,+ VERSION_PARAM,} from './taskRunArtifacts'export interface TaskRunArtifactsLogicProps {@@ -255,10 +258,6 @@ export function artifactDownloadUrl(projectId: number | null, taskId: string, arreturn getTasksRunsArtifactsDownloadRetrieveUrl(String(projectId), taskId, artifact.runId, artifact.id)}-// A shared link opens the tab on one file, and on one version when it is not the latest.-const ARTIFACT_PARAM = 'artifact'-const VERSION_PARAM = 'artifact_version'-/** The standalone page puts the task in the path, an embedded runner in `?task=`. */function urlIsForTask(pathname: string, searchParams: Record<string, any>, taskId: string): boolean {return searchParams.task === taskId || pathname.split('/').includes(taskId)@@ -503,11 +502,9 @@ export const taskRunArtifactsLogic = kea<taskRunArtifactsLogicType>([if (currentProjectId === null || !fileKey) {return null}- const params: Record<string, string> = { task: taskId, [ARTIFACT_PARAM]: fileKey }- if (selectedVersionId) {- params[VERSION_PARAM] = selectedVersionId- }- return urls.absolute(urls.project(currentProjectId, combineUrl('/ai', params).url))+ return urls.absolute(+ urls.project(currentProjectId, taskArtifactPath(taskId, fileKey, selectedVersionId))+ )},],selectedText: [diff --git a/products/tasks/frontend/spaces/SpaceFeedCard.stories.tsx b/products/tasks/frontend/spaces/SpaceFeedCard.stories.tsxnew file mode 100644index 000000000000..cad0c5466218--- /dev/null+++ b/products/tasks/frontend/spaces/SpaceFeedCard.stories.tsx@@ -0,0 +1,111 @@+import type { Meta, StoryObj } from '@storybook/react'++import { FEATURE_FLAGS } from 'lib/constants'++import { mswDecorator } from '~/mocks/browser'++import { TaskBasicApi, TaskRunArtifactResponseApi, TaskRuntimeEnumApi } from '../generated/api.schemas'+import { SpaceFeedCard } from './SpaceFeedCard'++const SPACE_ID = 'space-growth'++function file(name: string, uploadedAt: string, contentType?: string): TaskRunArtifactResponseApi {+ return {+ id: `artifact-${name}`,+ name,+ type: 'output',+ source: 'agent_output',+ storage_path: `tasks/artifacts/${name}`,+ content_type: contentType,+ uploaded_at: uploadedAt,+ }+}++function session(id: string, title: string, artifacts: TaskRunArtifactResponseApi[]): TaskBasicApi {+ return {+ id,+ task_number: 12,+ slug: id,+ title,+ title_manually_set: true,+ origin_product: 'user_created',+ runtime: TaskRuntimeEnumApi.Acp,+ repository: null,+ repositories: [],+ github_integration: null,+ github_user_integration: null,+ signal_report: null,+ json_schema: null,+ internal: false,+ archived: false,+ archived_at: null,+ ci_prompt: null,+ channel: SPACE_ID,+ slack_thread_references: [],+ description_preview: 'Find out why trial starts fell last week and write up what changed.',+ created_at: '2026-09-28T14:00:00Z',+ updated_at: '2026-09-28T16:00:00Z',+ last_activity_at: '2026-09-28T16:00:00Z',+ latest_run: {+ id: `${id}-run`,+ task: id,+ stage: null,+ branch: null,+ status: 'completed',+ environment: 'cloud',+ error_message: null,+ output: null,+ task_summary: null,+ task_tags: [],+ state: {},+ artifacts,+ },+ }+}++const ONE_FILE = session('session-one-file', 'Weekly signups summary', [+ file('signups-summary.md', '2026-09-28T15:00:00Z', 'text/markdown'),+])++const MANY_FILES = session('session-many-files', 'Trial starts dropped at the plan picker', [+ file('trial-starts-report.md', '2026-09-28T15:50:00Z', 'text/markdown'),+ file('trial-funnel-summary.html', '2026-09-28T15:40:00Z', 'text/html'),+ file('trial-starts-by-week.csv', '2026-09-28T15:30:00Z', 'text/csv'),+ file('trial-starts-by-step.svg', '2026-09-28T15:20:00Z', 'image/svg+xml'),+ file('plan-picker-walkthrough.mp4', '2026-09-28T15:10:00Z', 'video/mp4'),+])++const NO_FILES = session('session-no-files', 'Check the pricing page events', [])++const meta: Meta = {+ title: 'Scenes-App/Tasks/Space feed card',+ // No snapshots while the today-rail-nav layout is still changing quickly, the same as the Today stories.+ tags: ['test-skip'],+ decorators: [mswDecorator({})],+ parameters: {+ layout: 'padded',+ viewMode: 'story',+ mockDate: '2026-09-28 18:30:00',+ featureFlags: [FEATURE_FLAGS.TODAY_RAIL_NAV, FEATURE_FLAGS.TASKS],+ },+}+export default meta++type Story = StoryObj<{}>++export const ArtifactChips: Story = {+ render: () => (+ <div className="Today flex max-w-[720px] flex-col">+ {[MANY_FILES, ONE_FILE, NO_FILES].map((task) => (+ <SpaceFeedCard+ key={task.id}+ spaceId={SPACE_ID}+ task={task}+ pinned={false}+ unread={false}+ repository={null}+ />+ ))}+ </div>+ ),+}diff --git a/products/tasks/frontend/spaces/SpaceFeedCard.tsx b/products/tasks/frontend/spaces/SpaceFeedCard.tsxindex d670bbb25b19..d7a4ffd526a6 100644--- a/products/tasks/frontend/spaces/SpaceFeedCard.tsx+++ b/products/tasks/frontend/spaces/SpaceFeedCard.tsx@@ -1,7 +1,7 @@-import { useValues } from 'kea'+import { useActions, useValues } from 'kea'import { useId } from 'react'-import { IconDocument, IconGitBranch } from '@posthog/icons'+import { IconGitBranch } from '@posthog/icons'import {Badge,Card,@@ -29,6 +29,7 @@ import { TodaySessionRenameInput } from '~/layout/today/TodaySessionRenameInput'import { todaySpacesLogic } from '~/layout/today/todaySpacesLogic'import { sessionItem, sessionMenuTarget, shortTimeAgo } from '~/layout/today/todayWorkItems'+import { artifactPreviewKind } from 'products/posthog_ai/frontend/api/taskArtifacts'import { getOriginProductMeta } from 'products/posthog_ai/frontend/api/taskSource'import { TaskListItemApi } from '../generated/api.schemas'@@ -37,29 +38,14 @@ import { spaceFeedPreview } from './spaceFeedPreview'import { SpaceFeedSelectCheckbox } from './SpaceFeedSelectCheckbox'import { spaceFeedStatus } from './spaceFeedStatus'import { SpaceFeedStatusIcon } from './SpaceFeedStatusIcon'+import { spaceSceneLogic } from './spaceSceneLogic'+import { TaskFileChip } from './TaskFileChip'import { TaskFile, VISIBLE_FILE_COUNT, taskFiles } from './taskFiles'import { TASK_CHIP_CLASS, TaskPullRequestChip } from './TaskPullRequestChip'import { pullRequestLabel, splitPullRequests } from './taskPullRequests'import { TaskUserAvatar, taskUserName } from './TaskUserAvatar'import { useSpaceFeedBulkSelection } from './useSpaceFeedBulkSelection'-function TaskFileChip({ file }: { file: TaskFile }): JSX.Element {- return (- <Badge- render={<LinkPrimitive to={file.url} />}- aria-label={`Open ${file.name}`}- data-attr="today-file-chip-feed"- className={cn(- TASK_CHIP_CLASS,- 'border-border bg-fill-hover text-muted-foreground hover:bg-fill-selected hover:text-foreground'- )}- >- <IconDocument className="size-3 shrink-0" />- <span className="max-w-40 min-w-0 truncate">{file.name}</span>- </Badge>- )-}-interface SpaceFeedCardProps {spaceId: stringtask: TaskListItemApi@@ -80,7 +66,17 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spaconst [mainPullRequest] = item.pullRequestsconst status = spaceFeedStatus(task.latest_run, mainPullRequest && pullRequestStates[mainPullRequest.url])const pullRequests = splitPullRequests(item.pullRequests)- const files = taskFiles(task.id, task.latest_run?.artifacts)+ const { reportArtifactChipClicked } = useActions(spaceSceneLogic({ id: spaceId }))+ const files = taskFiles(task.id, task.latest_run)+ const fileChip = (taskFile: TaskFile, inOverflow: boolean): JSX.Element => (+ <TaskFileChip+ key={taskFile.file.key}+ taskFile={taskFile}+ onOpen={() =>+ reportArtifactChipClicked(artifactPreviewKind(taskFile.file.latest), inOverflow, files.length)+ }+ />+ )const hiddenFiles = files.slice(VISIBLE_FILE_COUNT)const preview = spaceFeedPreview('description_preview' in task ? task.description_preview : task.description)const author = task.created_by@@ -203,9 +199,7 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spa</PopoverContent></Popover>)}- {files.slice(0, VISIBLE_FILE_COUNT).map((file) => (- <TaskFileChip key={file.name} file={file} />- ))}+ {files.slice(0, VISIBLE_FILE_COUNT).map((taskFile) => fileChip(taskFile, false))}{hiddenFiles.length > 0 && (<Popover><PopoverTrigger@@ -219,9 +213,7 @@ export function SpaceFeedCard({ spaceId, task, pinned, unread, repository }: Spa{`+${hiddenFiles.length} ${hiddenFiles.length === 1 ? 'file' : 'files'}`}</PopoverTrigger><PopoverContent align="start" className="flex max-w-72 flex-col items-start gap-1">- {hiddenFiles.map((file) => (- <TaskFileChip key={file.name} file={file} />- ))}+ {hiddenFiles.map((taskFile) => fileChip(taskFile, true))}</PopoverContent></Popover>)}diff --git a/products/tasks/frontend/spaces/TaskFileChip.tsx b/products/tasks/frontend/spaces/TaskFileChip.tsxnew file mode 100644index 000000000000..f716ff98bb27--- /dev/null+++ b/products/tasks/frontend/spaces/TaskFileChip.tsx@@ -0,0 +1,32 @@+import { Badge, cn } from '@posthog/quill'++import { LinkPrimitive } from 'lib/lemon-ui/Link'++import { ArtifactIcon } from 'products/posthog_ai/frontend/api/taskArtifacts'++import { TaskFile } from './taskFiles'+import { TASK_CHIP_CLASS } from './TaskPullRequestChip'++interface TaskFileChipProps {+ taskFile: TaskFile+ onOpen: () => void+}++/** A file the agent handed back. It opens the session's Artifacts tab on that file, like PostHog Desktop. */+export function TaskFileChip({ taskFile, onOpen }: TaskFileChipProps): JSX.Element {+ const { file, url } = taskFile+ return (+ <Badge+ render={<LinkPrimitive to={url} onClick={onOpen} />}+ aria-label={`Open ${file.name}`}+ data-attr="today-file-chip-feed"+ className={cn(+ TASK_CHIP_CLASS,+ 'border-border bg-fill-hover text-muted-foreground hover:bg-fill-selected hover:text-foreground'+ )}+ >+ <ArtifactIcon artifact={file.latest} className="size-3 shrink-0" />+ <span className="max-w-40 min-w-0 truncate">{file.name}</span>+ </Badge>+ )+}diff --git a/products/tasks/frontend/spaces/spaceSceneLogic.ts b/products/tasks/frontend/spaces/spaceSceneLogic.tsindex 557110dde866..4195afb00e78 100644--- a/products/tasks/frontend/spaces/spaceSceneLogic.ts+++ b/products/tasks/frontend/spaces/spaceSceneLogic.ts@@ -22,6 +22,7 @@ import { canvasesDestroy, canvasesList, canvasesPartialUpdate } from 'products/cimport type { CanvasApi } from 'products/canvas/frontend/generated/api.schemas'import { ComposerSeed, composerSeedLogic } from 'products/posthog_ai/frontend/api/logics'import type { EmbeddedTaskComposerProps } from 'products/posthog_ai/frontend/api/runner'+import { type ArtifactPreviewKind, captureArtifactChipClicked } from 'products/posthog_ai/frontend/api/taskArtifacts'import {taskChannelsDestroy,@@ -304,6 +305,15 @@ export interface spaceSceneLogicActions {space: ChannelDTOApi | nullpayload?: any}+ reportArtifactChipClicked: (+ kind: ArtifactPreviewKind,+ inOverflow: boolean,+ fileCount: number+ ) => {+ fileCount: number+ inOverflow: boolean+ kind: ArtifactPreviewKind+ }saveAutoArchiveCustomDays: () => {value: true}@@ -477,6 +487,11 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([canvasDeleteStarted: true,canvasDeleted: (canvasId: string) => ({ canvasId }),canvasDeleteFailed: true,+ reportArtifactChipClicked: (kind: ArtifactPreviewKind, inOverflow: boolean, fileCount: number) => ({+ kind,+ inOverflow,+ fileCount,+ }),}),loaders(({ props, values }) => ({space: [@@ -857,6 +872,9 @@ export const spaceSceneLogic = kea<spaceSceneLogicType>([actions.setSeed({ prompt, autoSubmit: false })actions.focusComposer()},+ reportArtifactChipClicked: ({ kind, inOverflow, fileCount }) => {+ captureArtifactChipClicked({ kind, inOverflow, fileCount, surface: 'space_feed' })+ },setTypes: () => {actions.ensureCanvases()actions.loadPullRequestTitles()diff --git a/products/tasks/frontend/spaces/taskFiles.test.ts b/products/tasks/frontend/spaces/taskFiles.test.tsindex 73cf07ecdcaf..697aaf1e11ae 100644--- a/products/tasks/frontend/spaces/taskFiles.test.ts+++ b/products/tasks/frontend/spaces/taskFiles.test.ts@@ -25,6 +25,17 @@ describe('taskFiles', () => {artifact('skill.zip', { type: 'skill_bundle' }),artifact('reference', { storage_path: undefined }),artifact('old.csv', { dismissed_at: '2026-01-02T00:00:00Z' }),+ artifact('Weekly signups', {+ type: 'reference',+ storage_path: undefined,+ metadata: {+ reference_type: 'posthog_object',+ object_kind: 'insight',+ object_id: 'abc123',+ source_message_ids: ['message-1'],+ occurrence_count: 1,+ },+ }),],[],],@@ -38,11 +49,11 @@ describe('taskFiles', () => {['summary.md', 'chart.html'],],])('lists %s', (_, artifacts, expected) => {- expect(taskFiles('task-1', artifacts).map((file) => file.name)).toEqual(expected)+ expect(taskFiles('task-1', { id: 'run-1', artifacts }).map(({ file }) => file.name)).toEqual(expected)})it('links a file to its session with the file selected', () => {- expect(taskFiles('task-1', [artifact('q3 revenue.md')])[0].url).toEqual(+ expect(taskFiles('task-1', { id: 'run-1', artifacts: [artifact('q3 revenue.md')] })[0].url).toEqual('/ai?task=task-1&artifact=q3%20revenue.md')})diff --git a/products/tasks/frontend/spaces/taskFiles.ts b/products/tasks/frontend/spaces/taskFiles.tsindex fb74da62a7ad..6ca202cd3d6d 100644--- a/products/tasks/frontend/spaces/taskFiles.ts+++ b/products/tasks/frontend/spaces/taskFiles.ts@@ -1,41 +1,31 @@-import { combineUrl } from 'kea-router'--import { urls } from 'scenes/urls'+import {+ ArtifactFile,+ collectRunArtifacts,+ groupArtifactVersions,+ taskArtifactPath,+} from 'products/posthog_ai/frontend/api/taskArtifacts'import { TaskRunArtifactResponseApi } from '../generated/api.schemas'export interface TaskFile {- name: string+ file: ArtifactFile+ /** Opens the session's Artifacts tab with this file selected. */url: string}export const VISIBLE_FILE_COUNT = 2-function isAgentFile(artifact: TaskRunArtifactResponseApi): boolean {- return (- !!artifact.id &&- !!artifact.storage_path &&- (artifact.type === 'output' || artifact.type === 'artifact') &&- artifact.source === 'agent_output' &&- !artifact.dismissed_at- )+interface RunWithArtifacts {+ id: string+ artifacts?: readonly TaskRunArtifactResponseApi[] | null}-export function taskFiles(- taskId: string,- artifacts: readonly TaskRunArtifactResponseApi[] | null | undefined-): TaskFile[] {- const newestByName = new Map<string, string>()- for (const artifact of artifacts ?? []) {- if (!isAgentFile(artifact)) {- continue- }- const seen = newestByName.get(artifact.name)- if (seen === undefined || artifact.uploaded_at > seen) {- newestByName.set(artifact.name, artifact.uploaded_at)- }- }- return [...newestByName]- .sort(([, a], [, b]) => b.localeCompare(a))- .map(([name]) => ({ name, url: combineUrl(urls.aiTask(taskId), { artifact: name }).url }))+/**+ * The files the agent handed back on the run, newest first, one per name. It uses the Artifacts tab's own+ * rules, so a chip always opens a file the tab lists. Cited PostHog objects stay out, like PostHog Desktop.+ */+export function taskFiles(taskId: string, run: RunWithArtifacts | null | undefined): TaskFile[] {+ return groupArtifactVersions(collectRunArtifacts([run]))+ .filter((file) => file.latest.type !== 'reference')+ .map((file) => ({ file, url: taskArtifactPath(taskId, file.key) }))}