: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): edit text artifacts in the web artifacts tab (#110446)
Shy Alter81ab879effc9
diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsxindex 83c5d788e2b7..f5eb21e00ed0 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/TaskRunArtifacts.stories.tsx@@ -266,6 +266,28 @@ const CONTENT_BY_PATH: Record<string, string> = {'tasks/artifacts/artifact-csv': WEEKS_CSV,}+const EDITED_REPORT_MARKDOWN = `${REPORT_MARKDOWN}+## Owner++Ada owns the fix. The A/B test starts on Monday.+`++// A version the agent writes while the story's user edits the report.+const REPORT_NEWER_VERSION: TaskRunArtifactResponseApi = {+ id: 'artifact-report-v4',+ name: REPORT_FILE_NAME,+ type: 'output',+ source: 'agent_output',+ size: 7168,+ content_type: 'text/markdown',+ storage_path: 'tasks/artifacts/artifact-report-v4',+ uploaded_at: '2026-09-28T18:24:00Z',+ uploaded_by: 'agent',+}++// The conflict story sets this when it presses Save, so the run read after that holds the newer version.+let newerReportArrived = false+function mockRun(artifacts: TaskRunArtifactResponseApi[], id = RUN_ID): TaskRun {return {id,@@ -428,16 +450,27 @@ function TodayWebLayout({ children }: { children: ReactNode }): JSX.Element {)}+/** Opens the file in the editor once its text loads, types `draft`, and with `save` presses Save. */+interface StoryEdit {+ draft: string+ save?: boolean+}+function StoryPage({tab = 'artifacts',fileName,versionId,+ edit,}: {tab?: TaskRunTabfileName?: stringversionId?: string+ edit?: StoryEdit}): JSX.Element {- const { setActiveTab, selectArtifact, selectVersion } = useActions(taskRunArtifactsLogic({ taskId: TASK_ID }))+ const { setActiveTab, selectArtifact, selectVersion, startEditing, setEditDraft, saveEdit } = useActions(+ taskRunArtifactsLogic({ taskId: TASK_ID })+ )+ const { selectedText, isEditing } = useValues(taskRunArtifactsLogic({ taskId: TASK_ID }))useEffect(() => {if (fileName) {selectArtifact(fileName)@@ -447,6 +480,18 @@ function StoryPage({}setActiveTab(tab)}, [tab, fileName, versionId, setActiveTab, selectArtifact, selectVersion])+ const textLoaded = typeof selectedText?.text === 'string'+ useEffect(() => {+ if (!edit || !textLoaded || isEditing) {+ return+ }+ startEditing()+ setEditDraft(edit.draft)+ if (edit.save) {+ newerReportArrived = true+ saveEdit()+ }+ }, [edit, textLoaded, isEditing, startEditing, setEditDraft, saveEdit])return (<TodayWebLayout><TaskDetailPage taskId={TASK_ID} isMobile={false} />@@ -616,6 +661,32 @@ export const LivingSlackFile: Story = {render: () => <StoryPage fileName="living-doc-trial-chart" />,}+export const EditingMarkdown: Story = {+ render: () => <StoryPage fileName={REPORT_FILE_NAME} edit={{ draft: EDITED_REPORT_MARKDOWN }} />,+}++function conflictMocks(): ReturnType<typeof taskMocks> {+ const mocks = taskMocks(ARTIFACTS)+ return {+ get: {+ ...mocks.get,+ [`/api/projects/:team_id/tasks/${TASK_ID}/runs/${RUN_ID}/`]: () => [+ 200,+ mockRun(newerReportArrived ? [REPORT_NEWER_VERSION, ...ARTIFACTS] : ARTIFACTS),+ ],+ },+ post: mocks.post,+ }+}++export const SaveConflict: Story = {+ parameters: { msw: { mocks: conflictMocks() } },+ beforeEach: () => {+ newerReportArrived = false+ },+ render: () => <StoryPage fileName={REPORT_FILE_NAME} edit={{ draft: EDITED_REPORT_MARKDOWN, save: true }} />,+}+export const ResumedTask: Story = {parameters: { msw: { mocks: taskMocks(ARTIFACTS, { resumed: true }) } },render: () => <StoryPage fileName={REPORT_FILE_NAME} />,diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactEditToolbar.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactEditToolbar.tsxnew file mode 100644index 000000000000..ac49cedbc7d1--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactEditToolbar.tsx@@ -0,0 +1,112 @@+import { useActions, useValues } from 'kea'++import { IconPencil } from '@posthog/icons'+import {+ AlertDialog,+ AlertDialogClose,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ AlertDialogTrigger,+ Badge,+ Button,+ Text,+ Tooltip,+ TooltipContent,+ TooltipTrigger,+} from '@posthog/quill-primitives'++import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'++/** The toolbar while a file is open in the editor. `expandAction` is the full page toggle of the preview toolbar. */+export function ArtifactEditToolbar({+ taskId,+ expandAction,+}: {+ taskId: string+ expandAction: JSX.Element+}): JSX.Element | null {+ const { editSession, editDirty, editSaving } = useValues(taskRunArtifactsLogic({ taskId }))+ const { saveEdit, cancelEditing } = useActions(taskRunArtifactsLogic({ taskId }))+ if (!editSession) {+ return null+ }+ const saveButton = (+ <Button+ variant="primary"+ loading={editSaving}+ disabled={!editDirty}+ onClick={() => saveEdit()}+ data-attr="task-artifact-edit-save"+ >+ Save+ </Button>+ )+ return (+ <div className="flex h-10 shrink-0 items-center gap-2 border-b border-border bg-background px-3">+ <IconPencil className="size-4 shrink-0 text-muted-foreground" />+ <Text size="sm" weight="medium" render={<span />} className="min-w-0 truncate">+ {editSession.name}+ </Text>+ <Badge variant="info" className="shrink-0">+ Editing+ </Badge>+ <div className="ml-auto flex shrink-0 items-center gap-1">+ {editDirty ? (+ <AlertDialog>+ <AlertDialogTrigger+ disabled={editSaving}+ render={+ <Button variant="outline" disabled={editSaving} data-attr="task-artifact-edit-cancel" />+ }+ >+ Cancel+ </AlertDialogTrigger>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Discard your changes?</AlertDialogTitle>+ <AlertDialogDescription>+ {`Your changes to ${editSession.name} aren't saved. If you discard them, you can't get them back.`}+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogClose render={<Button variant="outline" />}>Keep editing</AlertDialogClose>+ <AlertDialogClose+ render={+ <Button+ variant="destructive-outline"+ onClick={() => cancelEditing()}+ data-attr="task-artifact-edit-discard"+ />+ }+ >+ Discard changes+ </AlertDialogClose>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ ) : (+ <Button+ variant="outline"+ disabled={editSaving}+ onClick={() => cancelEditing()}+ data-attr="task-artifact-edit-cancel"+ >+ Cancel+ </Button>+ )}+ {editDirty ? (+ saveButton+ ) : (+ <Tooltip>+ <TooltipTrigger render={saveButton} />+ <TooltipContent>There are no changes to save</TooltipContent>+ </Tooltip>+ )}+ {expandAction}+ </div>+ </div>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactEditor.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactEditor.tsxnew file mode 100644index 000000000000..8f636154125a--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactEditor.tsx@@ -0,0 +1,45 @@+import { useActions, useValues } from 'kea'++import { IconWarning } from '@posthog/icons'+import { Text } from '@posthog/quill-primitives'++import { CodeEditor } from 'lib/monaco/CodeEditor'++import { EDITOR_LANGUAGE } from '../taskRunArtifacts'+import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'+import { ArtifactSaveConflictDialog } from './ArtifactSaveConflictDialog'++/** The source of the file under edit. The logic holds the draft, so a remount in full page keeps it. */+export function ArtifactEditor({ taskId }: { taskId: string }): JSX.Element | null {+ const { editSession, editDraft, editError } = useValues(taskRunArtifactsLogic({ taskId }))+ const { setEditDraft } = useActions(taskRunArtifactsLogic({ taskId }))+ if (!editSession) {+ return null+ }+ return (+ <div className="flex min-h-0 flex-1 flex-col">+ {editError && (+ <div+ role="alert"+ className="flex shrink-0 items-center gap-2 border-b border-border bg-destructive px-3 py-2 text-destructive-foreground"+ >+ <IconWarning className="size-4 shrink-0" />+ <Text size="xs" render={<span />} className="min-w-0 text-destructive-foreground">+ {editError}+ </Text>+ </div>+ )}+ <div className="min-h-0 flex-1 bg-background" data-attr="task-artifact-editor">+ <CodeEditor+ queryKey={`task-artifact-edit-${editSession.baseArtifactId}`}+ language={EDITOR_LANGUAGE[editSession.kind]}+ value={editDraft}+ onChange={(value) => setEditDraft(value ?? '')}+ autoFocus+ options={{ wordWrap: 'on' }}+ />+ </div>+ <ArtifactSaveConflictDialog taskId={taskId} />+ </div>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactSaveConflictDialog.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactSaveConflictDialog.tsxnew file mode 100644index 000000000000..6b9e2d5d6ada--- /dev/null+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/ArtifactSaveConflictDialog.tsx@@ -0,0 +1,66 @@+import { useActions, useValues } from 'kea'++import {+ AlertDialog,+ AlertDialogClose,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ Button,+} from '@posthog/quill-primitives'++import { taskRunArtifactsLogic } from '../taskRunArtifactsLogic'++/** Asks before a save replaces a version that someone else wrote, or restores a file that was dismissed. */+export function ArtifactSaveConflictDialog({ taskId }: { taskId: string }): JSX.Element {+ const { editConflict, editSaving } = useValues(taskRunArtifactsLogic({ taskId }))+ const { resolveEditConflict } = useActions(taskRunArtifactsLogic({ taskId }))+ const dismissed = editConflict === 'dismissed'+ return (+ <AlertDialog+ open={editConflict !== null}+ onOpenChange={(open: boolean) => {+ if (!open && !editSaving) {+ resolveEditConflict('keep_editing')+ }+ }}+ >+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>+ {dismissed ? 'This file was dismissed' : 'A newer version is available'}+ </AlertDialogTitle>+ <AlertDialogDescription>+ {dismissed+ ? 'Every version of this file was dismissed while you were editing. Save your changes to restore it as the latest version?'+ : 'A newer version of this file was saved while you were editing. Save your changes as the latest version anyway?'}+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogClose+ disabled={editSaving}+ render={+ <Button+ variant="outline"+ disabled={editSaving}+ data-attr="task-artifact-conflict-keep-editing"+ />+ }+ >+ Keep editing+ </AlertDialogClose>+ <Button+ variant="primary"+ loading={editSaving}+ onClick={() => resolveEditConflict('save_as_latest')}+ data-attr="task-artifact-conflict-save"+ >+ {dismissed ? 'Save and restore' : 'Save as latest'}+ </Button>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ )+}diff --git a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsxindex e6af88eb3227..9992d8e744a3 100644--- a/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx+++ b/products/posthog_ai/frontend/scenes/TaskTracker/components/TaskRunArtifacts.tsx@@ -12,6 +12,7 @@ import {IconExpand45,IconExternal,IconLock,+ IconPencil,IconShare,IconHide,} from '@posthog/icons'@@ -88,6 +89,8 @@ import {postHogObjectRef,} from '../taskRunArtifacts'import { FullPageSource, artifactDownloadUrl, taskRunArtifactsLogic } from '../taskRunArtifactsLogic'+import { ArtifactEditor } from './ArtifactEditor'+import { ArtifactEditToolbar } from './ArtifactEditToolbar'import { ArtifactIcon } from './ArtifactIcon'import { ArtifactImageViewer } from './ArtifactImageViewer'@@ -473,7 +476,7 @@ function fileMeta(file: ArtifactFile): string {}function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {- const { files, selectedFile } = useValues(taskRunArtifactsLogic({ taskId }))+ const { files, selectedFile, isEditing } = useValues(taskRunArtifactsLogic({ taskId }))const { selectArtifact } = useActions(taskRunArtifactsLogic({ taskId }))// Cited PostHog objects sit under their own label, after the files.const objects = files.filter((file) => !!postHogObjectRef(file.latest))@@ -508,7 +511,7 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {)}// Item drops a `role` prop, so the option role goes on the rendered element.// eslint-disable-next-line react/forbid-elements- render={<button type="button" role="option" />}+ render={<button type="button" role="option" disabled={isEditing} aria-disabled={isEditing} />}onClick={() => selectArtifact(file.key)}data-attr="task-artifact-nav-item">@@ -532,6 +535,11 @@ function ArtifactNav({ taskId }: { taskId: string }): JSX.Element {{files.length - objects.length}</Text></div>+ {isEditing && (+ <Text size="xs" variant="muted" className="border-b border-border px-3 py-2">+ Save or cancel your changes to open another file.+ </Text>+ )}<divrole="listbox"aria-label="Files"@@ -696,10 +704,17 @@ function ArtifactToolbar({expanded: booleanonExpandedChange: (expanded: boolean, source: FullPageSource) => void}): JSX.Element {- const { files, selectedFile, selectedIndex, selectedText, currentProjectId, dismissalPending } = useValues(- taskRunArtifactsLogic({ taskId })- )- const { stepArtifact, downloadArtifact, reportObjectOpened, dismissFile } = useActions(+ const {+ files,+ selectedFile,+ selectedIndex,+ selectedText,+ currentProjectId,+ selectedEditableKind,+ editDisabledReason,+ dismissalPending,+ } = useValues(taskRunArtifactsLogic({ taskId }))+ const { stepArtifact, downloadArtifact, reportObjectOpened, startEditing, dismissFile } = useActions(taskRunArtifactsLogic({ taskId }))const kind = artifactPreviewKind(artifact)@@ -765,6 +780,16 @@ function ArtifactToolbar({</ToggleGroupItem></ToggleGroup>)}+ {selectedEditableKind && (+ <IconAction+ label="Edit"+ disabledReason={editDisabledReason ?? undefined}+ onClick={() => startEditing()}+ dataAttr="task-artifact-edit"+ >+ <IconPencil className="size-4" />+ </IconAction>+ )}{isTextPreview(kind) && <CopySourceAction text={selectedText?.text ?? null} />}{/* The file list replaces these once there is room for it. */}<div className="flex items-center gap-1 @[52rem]/main-content:hidden">@@ -839,7 +864,10 @@ function ArtifactToolbar({}function PreviewSurface({ taskId, mode }: { taskId: string; mode: PreviewMode }): JSX.Element {- const { selectedKind } = useValues(taskRunArtifactsLogic({ taskId }))+ const { selectedKind, isEditing } = useValues(taskRunArtifactsLogic({ taskId }))+ if (isEditing) {+ return <ArtifactEditor taskId={taskId} />+ }const fills =mode === 'rendered' &&(selectedKind === 'html' ||@@ -854,7 +882,7 @@ function PreviewSurface({ taskId, mode }: { taskId: string; mode: PreviewMode })}function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {- const { files, selectedArtifact } = useValues(taskRunArtifactsLogic({ taskId }))+ const { files, selectedArtifact, isEditing } = useValues(taskRunArtifactsLogic({ taskId }))const { setActiveTab, reportFullPageOpened } = useActions(taskRunArtifactsLogic({ taskId }))const [mode, setMode] = useState<PreviewMode>('rendered')const [expanded, setExpanded] = useState(false)@@ -880,7 +908,8 @@ function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {[expanded, selectedArtifact])- if (files.length === 0 || !selectedArtifact) {+ // A dismissal while editing can empty the list, and the editor must stay to keep the draft.+ if (!isEditing && (files.length === 0 || !selectedArtifact)) {return (<Empty className="flex-1"><EmptyHeader>@@ -901,16 +930,30 @@ function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {</Empty>)}- const toolbar = (- <ArtifactToolbar- taskId={taskId}- artifact={selectedArtifact}- mode={mode}- onModeChange={setMode}- expanded={expanded}- onExpandedChange={changeExpanded}- />- )+ const toolbar =+ selectedArtifact && !isEditing ? (+ <ArtifactToolbar+ taskId={taskId}+ artifact={selectedArtifact}+ mode={mode}+ onModeChange={setMode}+ expanded={expanded}+ onExpandedChange={changeExpanded}+ />+ ) : (+ <ArtifactEditToolbar+ taskId={taskId}+ expandAction={+ <IconAction+ label={expanded ? 'Exit full page' : 'Open full page'}+ onClick={() => changeExpanded(!expanded, 'button')}+ dataAttr={expanded ? 'task-artifact-collapse' : 'task-artifact-expand'}+ >+ {expanded ? <IconCollapse45 className="size-4" /> : <IconExpand45 className="size-4" />}+ </IconAction>+ }+ />+ )return (<div className="flex min-h-0 flex-1"><ArtifactNav taskId={taskId} />@@ -929,7 +972,7 @@ function ArtifactsWorkspace({ taskId }: { taskId: string }): JSX.Element {showCloseButton={false}className="inset-0 flex h-dvh max-h-none w-screen max-w-none translate-none flex-col gap-0 rounded-none p-0 shadow-none">- <DialogTitle className="sr-only">{selectedArtifact.name}</DialogTitle>+ <DialogTitle className="sr-only">{selectedArtifact?.name ?? 'Artifact'}</DialogTitle>{/* The toolbar hides parts by container width, so the dialog gets its own container. */}<div className="@container/main-content flex min-h-0 flex-1 flex-col">{toolbar}