diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index cbd5fac15..274adde37 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -7,11 +7,13 @@ import type { import React, { Children, Fragment, + Suspense, type CSSProperties, type ComponentPropsWithoutRef, type MouseEvent as ReactMouseEvent, createContext, isValidElement, + lazy, useCallback, memo, useContext, @@ -56,10 +58,9 @@ import { runFileAction, useFileActionLaunchers, } from "./fileActionsMenu"; -import { editorLabel } from "./EditorOpenOptions"; +import { editorLabel } from "../editorLabels"; import { useComputerLabel } from "./sidebar/linkedComputers"; -import { resolveDiffThemeName, type DiffThemeName } from "../lib/diffRendering"; -import { fnv1a32 } from "../lib/diffRendering"; +import { fnv1a32, resolveDiffThemeName, type DiffThemeName } from "../lib/diffThemeName"; import { highlightCode, openStreamingHighlight, @@ -107,7 +108,6 @@ import { buildFileLinkLabel, CHAT_MARKDOWN_REMARK_PLUGINS, chatMarkdownUrlTransform, - GITHUB_HTML_REHYPE_PLUGINS, indexWrittenFilePathsByBasename, isFileNameMention, normalizeMarkdownLinkHrefKey, @@ -464,11 +464,15 @@ function ChatCodeBlock({ className, code, plain }: ChatCodeBlockProps) { if (highlightedCodeCache.get(cacheKey) != null) return; let cancelled = false; - void highlightCode(code, language, themeName).then((html) => { - if (cancelled || html === null) return; - highlightedCodeCache.set(cacheKey, html, estimateHighlightedSize(html, code)); - setHighlighted({ cacheKey, html }); - }); + void highlightCode(code, language, themeName) + .then((html) => { + if (cancelled || html === null) return; + highlightedCodeCache.set(cacheKey, html, estimateHighlightedSize(html, code)); + setHighlighted({ cacheKey, html }); + }) + .catch(() => { + // Keep plain code fallback if highlighting fails. + }); return () => { cancelled = true; @@ -1708,20 +1712,39 @@ function ChatMarkdownDocument({ ], ); + const plainMarkdown = ( + + {text} + + ); + + // When a GitHub document contains raw HTML tags or comments, avoid flashing + // literal markup through plain ReactMarkdown while the sanitizer chunk loads. + const githubFallback = text.includes("<") ? null : plainMarkdown; + return ( - - {text} - + {html === "github" ? ( + + + + ) : ( + plainMarkdown + )} ); } +const LazyGitHubHtmlMarkdown = lazy(() => import("./chat/GitHubHtmlMarkdown")); + const MemoChatMarkdownDocument = memo(ChatMarkdownDocument); /** @@ -1821,12 +1844,15 @@ function ChatMarkdown({ className, }: ChatMarkdownProps) { const { resolvedTheme } = useTheme(); - // Boots the highlighting worker and its theme while the page is idle, so the - // first code block of a session is not also the one that loads Shiki. + // Boot the highlighting worker and its theme while idle only once a message + // actually has a fenced code block, so prose-only threads avoid fetching + // @pierre/diffs on startup. const codeThemeName = useCodeThemeName(); + const hasFencedCode = text.includes("```") || text.includes("~~~"); useEffect(() => { + if (!hasFencedCode) return; warmCodeHighlighter(codeThemeName); - }, [codeThemeName]); + }, [codeThemeName, hasFencedCode]); const canRenderVisualizations = environmentId !== undefined && threadId !== undefined; const parsedSegments = useMemo(() => { const rawSegments = canRenderVisualizations diff --git a/apps/web/src/components/ChatView.panels.browser.tsx b/apps/web/src/components/ChatView.panels.browser.tsx index 88e196c32..ae848d559 100644 --- a/apps/web/src/components/ChatView.panels.browser.tsx +++ b/apps/web/src/components/ChatView.panels.browser.tsx @@ -332,7 +332,12 @@ describe("ChatView (full app): right panel and header actions", () => { "Unable to find the sidebar's Source tab.", ); expect(changesTab.getAttribute("data-active")).toBe("true"); - expect(visibleSourceControlPanel()).not.toBeNull(); + await vi.waitFor( + () => { + expect(visibleSourceControlPanel()).not.toBeNull(); + }, + { timeout: 8_000, interval: 16 }, + ); expect(document.querySelector("[data-agents-panel]")).toBeNull(); // The `+` menu adds the second tab and focuses it. diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index eaef505a5..9761d73ce 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -62,6 +62,8 @@ import { Debouncer } from "@tanstack/react-pacer"; import { useQueryClient } from "@tanstack/react-query"; import * as Option from "effect/Option"; import { + Suspense, + lazy, memo, useCallback, useEffect, @@ -191,7 +193,7 @@ import { useNewThreadHandler } from "../hooks/useHandleNewThread"; import { isKeyboardOwnedByDialog } from "../commands/shortcutBlock"; import { useChatFindStore } from "../chatFindStore"; import { installFindRegionTracking, resolveFindShortcutOwner } from "../lib/findShortcutOwner"; -import { selectedChatText } from "./chat/chatFind/ChatFind"; +import { selectedChatText } from "./chat/chatFind/chatFindSelection"; import { RIGHT_PANEL_INLINE_LAYOUT_MEDIA_QUERY, draftRightPanelStateKey, @@ -319,7 +321,6 @@ import { McpAppSidePanel } from "./chat/McpAppCard"; import { NO_COMPOSER_PULL_REQUESTS, type ComposerPullRequest } from "./chat/ComposerPullRequestRow"; import { type ComposerGoalSetInput, threadGoalControls } from "./chat/ComposerGoalBar"; import { getComposerProviderState } from "./chat/composerProviderState"; -import { PullRequestThreadDialog } from "./PullRequestThreadDialog"; import { useProjectBriefSupport } from "../projectBrief"; import { linkedThreadRouteParams } from "../environments/links/linkedThreads"; import { changeProjectNote, useThreadNoteSuggestions } from "../projectContext"; @@ -359,7 +360,29 @@ import { } from "./chat/threadActivity"; import { currentWorkLine } from "./chat/activitySteps"; import { closeExpandedImagePreview, openExpandedImagePreview } from "./chat/ExpandedImagePreview"; -import { FilePreviewDialog, type FilePreviewRequest } from "./chat/FilePreviewDialog"; +import type { FilePreviewRequest } from "./chat/FilePreviewDialog"; +import { SuspenseEscapeTrap } from "./SuspenseEscapeTrap"; + +const LazyPullRequestThreadDialog = lazy(() => + import("./PullRequestThreadDialog").then((module) => ({ + default: module.PullRequestThreadDialog, + })), +); +const LazyFilePreviewDialog = lazy(() => + import("./chat/FilePreviewDialog").then((module) => ({ + default: module.FilePreviewDialog, + })), +); +const LazyBrowserPanel = lazy(() => + import("./browser/BrowserPanel").then((module) => ({ + default: module.BrowserPanel, + })), +); +const LazyBrowserSplitHandle = lazy(() => + import("./browser/BrowserSplitHandle").then((module) => ({ + default: module.BrowserSplitHandle, + })), +); import { NoActiveThreadState } from "./NoActiveThreadState"; import { resolveEffectiveEnvMode, resolveEnvironmentOptionLabel } from "./BranchToolbar.logic"; import { @@ -456,8 +479,6 @@ import { } from "./ChatView.logic"; import { useLocalStorage } from "~/hooks/useLocalStorage"; import { selectThreadBrowserState, useBrowserPanelStore } from "../browserPanelStore"; -import { BrowserPanel } from "./browser/BrowserPanel"; -import { BrowserSplitHandle } from "./browser/BrowserSplitHandle"; import { useComposerHandleContext } from "../composerHandleContext"; import { useServerAvailableEditors, @@ -9364,33 +9385,35 @@ export default function ChatView(props: ChatViewProps) { ) : null} {pullRequestDialogState ? ( - { - if (!open) { - closePullRequestDialog(); - } - }} - onPrepared={handlePreparedPullRequestThread} - /> + }> + { + if (!open) { + closePullRequestDialog(); + } + }} + onPrepared={handlePreparedPullRequestThread} + /> + ) : null} {/* end chat column */} {browserOpen && routeThreadRef !== null ? ( - <> + {browserExpanded ? null : ( - )} - setPendingElementReveal(null)} /> - + ) : null} {/* end horizontal flex container */} @@ -9436,7 +9459,11 @@ export default function ChatView(props: ChatViewProps) { setPendingTerminalAction(null); }} /> - {previewedFile && } + {previewedFile ? ( + }> + + + ) : null} ); } diff --git a/apps/web/src/components/ComposerPromptEditor.tsx b/apps/web/src/components/ComposerPromptEditor.tsx index 3eaaac52b..37910d3d3 100644 --- a/apps/web/src/components/ComposerPromptEditor.tsx +++ b/apps/web/src/components/ComposerPromptEditor.tsx @@ -68,7 +68,8 @@ import { type TerminalContextDraft, } from "~/lib/terminalContext"; import { cn } from "~/lib/utils"; -import { basenameOfPath, getVscodeIconUrlForEntry, inferEntryKindFromPath } from "~/vscode-icons"; +import { basenameOfPath, inferEntryKindFromPath } from "~/lib/vscodeIconPath"; +import { VscodeEntryIcon } from "./chat/VscodeEntryIcon"; import { COMPOSER_INLINE_CHIP_CLASS_NAME, COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, @@ -170,12 +171,11 @@ function ComposerMentionDecorator(props: { path: string }) { spellCheck={false} data-composer-mention-chip="true" > - {basenameOfPath(props.path)} diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx index 61e640832..25391dbb1 100644 --- a/apps/web/src/components/DiffPanel.tsx +++ b/apps/web/src/components/DiffPanel.tsx @@ -37,6 +37,7 @@ import { parseDiffRouteSearch, stripDiffSearchParams } from "../diffRouteSearch" import { useComposerDraftStore } from "../composerDraftStore"; import { useTheme } from "../hooks/useTheme"; import { buildFileDiffRenderKey, getRenderablePatch } from "../lib/diffRendering"; +import "../theme/attachPierreCodeThemes"; import { useCodeThemeName } from "../theme/codeTheme"; import { useTurnDiffSummaries } from "../hooks/useTurnDiffSummaries"; import { useStore } from "../store"; diff --git a/apps/web/src/components/DiffWorkerPoolProvider.tsx b/apps/web/src/components/DiffWorkerPoolProvider.tsx index 4f0960b7e..20ced994c 100644 --- a/apps/web/src/components/DiffWorkerPoolProvider.tsx +++ b/apps/web/src/components/DiffWorkerPoolProvider.tsx @@ -2,6 +2,7 @@ import { WorkerPoolContextProvider, useWorkerPool } from "@pierre/diffs/react"; import DiffsWorker from "../lib/diffsWorker.ts?worker"; import { useEffect, useMemo, type ReactNode } from "react"; import type { DiffThemeName } from "../lib/diffRendering"; +import "../theme/attachPierreCodeThemes"; import { useCodeThemeName } from "../theme/codeTheme"; function DiffWorkerThemeSync({ themeName }: { themeName: DiffThemeName }) { diff --git a/apps/web/src/components/EditorOpenOptions.tsx b/apps/web/src/components/EditorOpenOptions.tsx index bb15e88d7..2fd04ba5b 100644 --- a/apps/web/src/components/EditorOpenOptions.tsx +++ b/apps/web/src/components/EditorOpenOptions.tsx @@ -11,8 +11,7 @@ import type { EditorId } from "@threadlines/contracts"; import { FolderClosedIcon } from "lucide-react"; import { useMemo } from "react"; -import { isMacPlatform, isWindowsPlatform } from "~/lib/utils"; -import { readPrimaryEnvironmentDescriptor } from "~/environments/primary/context"; +import { editorLabel, hostFileManagerLabel } from "../editorLabels"; import { AntigravityIcon, CursorIcon, Icon, KiroIcon, TraeIcon, Zed } from "./Icons"; import { VisualStudioCode, VisualStudioCodeInsiders, VSCodium } from "./ToolIcons"; import { @@ -60,33 +59,7 @@ const EDITOR_OPTIONS: ReadonlyArray = [ { label: "WebStorm", Icon: WebStormIcon, value: "webstorm" }, ]; -function fileManagerLabel(platform: string): string { - return isMacPlatform(platform) ? "Finder" : isWindowsPlatform(platform) ? "Explorer" : "Files"; -} - -/** - * The file manager's name on the computer that opens it: the primary - * server's, which is not this device's when a browser on a Mac is paired with - * a Windows PC. This device's platform stands in until the server says. - */ -function hostFileManagerLabel(): string { - switch (readPrimaryEnvironmentDescriptor()?.platform.os) { - case "darwin": - return "Finder"; - case "windows": - return "Explorer"; - case "linux": - return "Files"; - default: - return fileManagerLabel(navigator.platform); - } -} - -/** The name an editor goes by in menus ("Cursor", "Finder"). */ -export function editorLabel(editor: EditorId): string { - if (editor === "file-manager") return hostFileManagerLabel(); - return EDITOR_OPTIONS.find((option) => option.value === editor)?.label ?? editor; -} +export { editorLabel }; /** * Action label for an option: the file manager reveals a target rather than diff --git a/apps/web/src/components/ProjectScriptsControl.tsx b/apps/web/src/components/ProjectScriptsControl.tsx index 699eee870..343f7e474 100644 --- a/apps/web/src/components/ProjectScriptsControl.tsx +++ b/apps/web/src/components/ProjectScriptsControl.tsx @@ -20,7 +20,7 @@ import { keybindingValueForCommand, decodeProjectScriptKeybindingRule, } from "~/lib/projectScriptKeybindings"; -import { keybindingFromKeyboardEvent } from "~/components/settings/KeybindingsSettings.logic"; +import { keybindingFromKeyboardEvent } from "~/components/settings/keybindingCapture"; import { commandForProjectScript, nextProjectScriptId, diff --git a/apps/web/src/components/SuspenseEscapeTrap.tsx b/apps/web/src/components/SuspenseEscapeTrap.tsx new file mode 100644 index 000000000..bbe38deb0 --- /dev/null +++ b/apps/web/src/components/SuspenseEscapeTrap.tsx @@ -0,0 +1,25 @@ +import { useEffect } from "react"; + +/** + * Keeps Escape responsive during the brief Suspense window while a lazy + * dialog or popover chunk loads, so pressing Escape immediately after + * opening cancels it instead of letting it appear once the chunk arrives. + */ +export function SuspenseEscapeTrap({ onClose }: { readonly onClose: () => void }) { + useEffect(() => { + const onKeyDown = (event: KeyboardEvent) => { + if (event.key !== "Escape" || event.defaultPrevented) { + return; + } + event.preventDefault(); + event.stopPropagation(); + onClose(); + }; + window.addEventListener("keydown", onKeyDown, true); + return () => { + window.removeEventListener("keydown", onKeyDown, true); + }; + }, [onClose]); + + return null; +} diff --git a/apps/web/src/components/addProject/OpenAddProjectDialog.tsx b/apps/web/src/components/addProject/OpenAddProjectDialog.tsx index f160e84d8..16f0c5f48 100644 --- a/apps/web/src/components/addProject/OpenAddProjectDialog.tsx +++ b/apps/web/src/components/addProject/OpenAddProjectDialog.tsx @@ -90,7 +90,7 @@ import { } from "../CommandPalette.logic"; import { CommandPaletteResults } from "../CommandPaletteResults"; import { addComputerNotConnectedNotice } from "../computerConnectionNotices"; -import { editorLabel } from "../EditorOpenOptions"; +import { editorLabel } from "../../editorLabels"; import { AzureDevOpsIcon, BitbucketIcon, GitHubIcon, GitLabIcon } from "../Icons"; import { Button } from "../ui/button"; import { diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 857cdf6e4..9a25cad38 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -31,6 +31,8 @@ import { } from "@threadlines/contracts"; import { createModelSelection, normalizeModelSlug } from "@threadlines/shared/model"; import { + Suspense, + lazy, memo, type ReactNode, useCallback, @@ -152,7 +154,12 @@ import { } from "./ComposerGoalBar"; import { ComposerPlanFollowUpBanner } from "./ComposerPlanFollowUpBanner"; import { NEW_THEME_PROMPT, NewThemeHint } from "../theme/ui/NewThemeHint"; -import { ThemePickerStrip } from "../theme/ui/ThemePickerStrip"; + +const LazyThemePickerStrip = lazy(() => + import("../theme/ui/ThemePickerStrip").then((module) => ({ + default: module.ThemePickerStrip, + })), +); import { type ComposerNotice, selectComposerNotices } from "./composerNotices"; import { useModelRetirementNotice } from "./modelRetirementNotice"; import { ComposerDock, hasComposerDockContent } from "./ComposerDock"; @@ -176,7 +183,8 @@ import { buildExpandedImagePreview, type ExpandedImagePreview } from "./Expanded import { usePinchToExpand } from "./usePinchToExpand"; import { ComposerPdfThumbnail } from "./ComposerPdfThumbnail"; import type { FilePreviewRequest } from "./FilePreviewDialog"; -import { basenameOfPath } from "../../vscode-icons"; +import { SuspenseEscapeTrap } from "../SuspenseEscapeTrap"; +import { basenameOfPath } from "../../lib/vscodeIconPath"; import { cn, randomUUID } from "~/lib/utils"; import { Button } from "../ui/button"; import { Tooltip, TooltipPopup, TooltipProvider, TooltipTrigger } from "../ui/tooltip"; @@ -3659,16 +3667,27 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) data-glass-surface="theme-picker" className="mx-auto mb-1.5 w-full overflow-hidden rounded-[var(--app-radius-xlarge)] border border-border bg-card" > - { - setIsThemePickerOpen(false); - composerEditorRef.current?.focusAtEnd(); - }} - onNewTheme={() => { - fillComposerPrompt(NEW_THEME_PROMPT); - setNewThemeHintDismissed(false); - }} - /> + { + setIsThemePickerOpen(false); + composerEditorRef.current?.focusAtEnd(); + }} + /> + } + > + { + setIsThemePickerOpen(false); + composerEditorRef.current?.focusAtEnd(); + }} + onNewTheme={() => { + fillComposerPrompt(NEW_THEME_PROMPT); + setNewThemeHintDismissed(false); + }} + /> + ) : null} {!isComposerCollapsedMobile && !isThemePickerOpen && showNewThemeHint ? ( diff --git a/apps/web/src/components/chat/GitHubHtmlMarkdown.tsx b/apps/web/src/components/chat/GitHubHtmlMarkdown.tsx new file mode 100644 index 000000000..2b547eabb --- /dev/null +++ b/apps/web/src/components/chat/GitHubHtmlMarkdown.tsx @@ -0,0 +1,32 @@ +import ReactMarkdown, { type Components, type UrlTransform } from "react-markdown"; + +import { CHAT_MARKDOWN_REMARK_PLUGINS } from "../../lib/chatMarkdownDocument"; +import { GITHUB_HTML_REHYPE_PLUGINS } from "../../lib/githubMarkdownHtml"; + +interface GitHubHtmlMarkdownProps { + readonly text: string; + readonly components: Components; + readonly urlTransform: UrlTransform; +} + +/** + * Renders GitHub-authored markdown that can contain sanitized HTML (PR bodies + * and comments). Kept in its own chunk so `parse5` and `rehype-raw` stay out + * of normal chat markdown. + */ +export default function GitHubHtmlMarkdown({ + text, + components, + urlTransform, +}: GitHubHtmlMarkdownProps) { + return ( + + {text} + + ); +} diff --git a/apps/web/src/components/chat/MarkdownDiagram.tsx b/apps/web/src/components/chat/MarkdownDiagram.tsx index 1ece3f1c3..4ecff7887 100644 --- a/apps/web/src/components/chat/MarkdownDiagram.tsx +++ b/apps/web/src/components/chat/MarkdownDiagram.tsx @@ -10,7 +10,7 @@ import { CodeIcon, Maximize2Icon, WorkflowIcon } from "lucide-react"; import { memo, type ReactNode, useState } from "react"; import { useCachedRender } from "../../hooks/useCachedRender"; -import { fnv1a32 } from "../../lib/diffRendering"; +import { fnv1a32 } from "../../lib/diffThemeName"; import { LRUCache } from "../../lib/lruCache"; import { useActiveTheme } from "../../theme/themeStore"; import { Button } from "../ui/button"; diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index 4e253d5a4..d1ea7317d 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -152,6 +152,11 @@ const startsExchange = ( (message.fromThread !== undefined || message.fromOutside !== undefined) && !isTurnAside(message)); +export type TimelineWorkEntry = Extract< + MessagesTimelineRow, + { kind: "work" } +>["groupedEntries"][number]; + export type MessagesTimelineRow = TimelineRowPlacement & ( | { diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx index d00130edb..ba35f2171 100644 --- a/apps/web/src/components/chat/MessagesTimeline.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.tsx @@ -23,7 +23,9 @@ import { TickingText } from "../ui/TickingText"; import { createContext, Fragment, + lazy, memo, + Suspense, use, useCallback, useEffect, @@ -104,7 +106,6 @@ import { ArrowDownIcon, ArrowUpIcon, BotIcon, - CalendarClockIcon, CheckIcon, ChevronRightIcon, CircleAlertIcon, @@ -173,13 +174,6 @@ import { } from "../Sidebar.logic"; import { useComputerLabel } from "../sidebar/linkedComputers"; import { useConnectedComputerCapability } from "../../environments/computerCapabilities"; -import { - describeScheduleCall, - parseScheduleCallResult, - type ScheduleChangeTool, -} from "../scheduled/scheduled.logic"; -import { useScheduledNavigation } from "../scheduled/useScheduledPage"; -import { useScheduledTasksStore } from "../../lib/scheduledTasksState"; import { ThreadProviderGlyph, ThreadStatusText } from "../sidebar/InboxRows"; import { computeStableMessagesTimelineRows, @@ -196,6 +190,7 @@ import { timelineMessageView, timelineRowTurnIds, type StableMessagesTimelineRowsState, + type TimelineWorkEntry, type TurnSummary, type MessagesTimelineRow, } from "./MessagesTimeline.logic"; @@ -2418,7 +2413,7 @@ function keyExtractor(item: MessagesTimelineRow) { // TimelineRowContent — the actual row component // --------------------------------------------------------------------------- -type TimelineWorkEntry = Extract["groupedEntries"][number]; +const LazyScheduleCallRecordLine = lazy(() => import("./ScheduleCallRecordLine")); type TimelineRow = MessagesTimelineRow; type TimelineImagePreviewItem = { id: string; @@ -4864,6 +4859,7 @@ const WorkGroupSection = memo(function WorkGroupSection({ row: Extract; }) { const { + activeThreadEnvironmentId, workspaceRoot, roomAgentNames, turnDiffSummaryByTurnId, @@ -5010,9 +5006,21 @@ const WorkGroupSection = memo(function WorkGroupSection({ {recordedThreadStartEntries.map((entry) => ( ))} - {scheduleCallEntries.map((entry) => ( - - ))} + {scheduleCallEntries.length > 0 ? ( + ( + ); }); @@ -5024,77 +5032,6 @@ function isSettledScheduleChangeEntry(entry: TimelineWorkEntry): boolean { return tool === "schedule_create" || tool === "schedule_update"; } -/** - * Where the agent created or changed a scheduled task: one line with the task - * as it is now (its schedule and next run), or its card still waiting for the - * user. A click opens the task on the Scheduled page. - */ -function ScheduleCallRecordLine({ entry }: { entry: TimelineWorkEntry }) { - const { activeThreadEnvironmentId } = use(TimelineRowCtx); - const nowMs = useRelativeTimeTick(30_000); - const navigation = useScheduledNavigation(); - const snapshot = useScheduledTasksStore( - (state) => state.byEnvironment[activeThreadEnvironmentId], - ); - const result = useMemo( - () => parseScheduleCallResult(entry.toolResult ?? entry.outputPreview), - [entry.outputPreview, entry.toolResult], - ); - const tool: ScheduleChangeTool = - threadlinesRoomToolOf(entry) === "schedule_update" ? "schedule_update" : "schedule_create"; - const record = describeScheduleCall({ - tool, - result, - task: - result.taskId === null - ? null - : (snapshot?.tasks.find((task) => task.id === result.taskId) ?? null), - waiting: - result.requestId !== null && - (snapshot?.requests.some((request) => request.requestId === result.requestId) ?? false), - failed: entry.executionState === "failed", - followed: snapshot !== undefined, - nowMs, - }); - const line = ( - <> - - - {record.heading} - - {record.outcome !== null ? ( - <> - · - - {record.outcome} - - - ) : null} - - ); - const className = "flex min-w-0 items-center gap-[7px] text-xs leading-5 text-foreground/80"; - const open = record.open; - return open === null ? ( -
- {line} -
- ) : ( - - ); -} - /** * Where the agent started threads of its own (child threads): one line for * the call, then each thread with its live status, a click from its chat. In diff --git a/apps/web/src/components/chat/ScheduleCallRecordLine.tsx b/apps/web/src/components/chat/ScheduleCallRecordLine.tsx new file mode 100644 index 000000000..384bcc5d8 --- /dev/null +++ b/apps/web/src/components/chat/ScheduleCallRecordLine.tsx @@ -0,0 +1,91 @@ +import type { EnvironmentId } from "@threadlines/contracts"; +import { CalendarClockIcon } from "lucide-react"; +import { useMemo } from "react"; + +import { useRelativeTimeTick } from "../../hooks/useRelativeTimeTick"; +import { useScheduledTasksStore } from "../../lib/scheduledTasksState"; +import { cn } from "../../lib/utils"; +import { + describeScheduleCall, + parseScheduleCallResult, + type ScheduleChangeTool, +} from "../scheduled/scheduled.logic"; +import { useScheduledNavigation } from "../scheduled/useScheduledNavigation"; +import { threadlinesRoomToolOf } from "./activitySteps"; +import type { TimelineWorkEntry } from "./MessagesTimeline.logic"; + +/** + * Where the agent created or changed a scheduled task: one line with the task + * as it is now (its schedule and next run), or its card still waiting for the + * user. A click opens the task on the Scheduled page. + */ +export default function ScheduleCallRecordLine({ + activeThreadEnvironmentId, + entry, +}: { + readonly activeThreadEnvironmentId: EnvironmentId; + readonly entry: TimelineWorkEntry; +}) { + const nowMs = useRelativeTimeTick(30_000); + const navigation = useScheduledNavigation(); + const snapshot = useScheduledTasksStore( + (state) => state.byEnvironment[activeThreadEnvironmentId], + ); + const result = useMemo( + () => parseScheduleCallResult(entry.toolResult ?? entry.outputPreview), + [entry.outputPreview, entry.toolResult], + ); + const tool: ScheduleChangeTool = + threadlinesRoomToolOf(entry) === "schedule_update" ? "schedule_update" : "schedule_create"; + const record = describeScheduleCall({ + tool, + result, + task: + result.taskId === null + ? null + : (snapshot?.tasks.find((task) => task.id === result.taskId) ?? null), + waiting: + result.requestId !== null && + (snapshot?.requests.some((request) => request.requestId === result.requestId) ?? false), + failed: entry.executionState === "failed", + followed: snapshot !== undefined, + nowMs, + }); + const line = ( + <> + + + {record.heading} + + {record.outcome !== null ? ( + <> + · + + {record.outcome} + + + ) : null} + + ); + const className = "flex min-w-0 items-center gap-[7px] text-xs leading-5 text-foreground/80"; + const open = record.open; + return open === null ? ( +
+ {line} +
+ ) : ( + + ); +} diff --git a/apps/web/src/components/chat/VscodeEntryIcon.tsx b/apps/web/src/components/chat/VscodeEntryIcon.tsx index bf110e2bb..477313b23 100644 --- a/apps/web/src/components/chat/VscodeEntryIcon.tsx +++ b/apps/web/src/components/chat/VscodeEntryIcon.tsx @@ -1,6 +1,6 @@ -import { memo, useMemo, useState } from "react"; -import { getVscodeIconUrlForEntry } from "../../vscode-icons"; +import { memo, useState } from "react"; import { FileIcon, FolderIcon } from "lucide-react"; +import { useVscodeIconUrl } from "../../lib/useVscodeIconUrl"; import { cn } from "~/lib/utils"; export const VscodeEntryIcon = memo(function VscodeEntryIcon(props: { @@ -10,17 +10,20 @@ export const VscodeEntryIcon = memo(function VscodeEntryIcon(props: { className?: string; }) { const [failedIconUrl, setFailedIconUrl] = useState(null); - const iconUrl = useMemo( - () => getVscodeIconUrlForEntry(props.pathValue, props.kind, props.theme), - [props.kind, props.pathValue, props.theme], - ); - const failed = failedIconUrl === iconUrl; + const iconUrl = useVscodeIconUrl(props.pathValue, props.kind, props.theme); + const failed = iconUrl !== null && failedIconUrl === iconUrl; - if (failed) { + if (iconUrl === null || failed) { return props.kind === "directory" ? ( - +