Skip to content
TypeScript

fix(web): skill chips in chat open the same details popover as the composer (#25432)

oliver278588a61a3a
diff --git a/apps/web/src/components/ChatMarkdown.browser.test.tsx b/apps/web/src/components/ChatMarkdown.browser.test.tsx
index 558fe2d7ea9..d67803a6399 100644
--- a/apps/web/src/components/ChatMarkdown.browser.test.tsx
+++ b/apps/web/src/components/ChatMarkdown.browser.test.tsx
@@ -2,6 +2,7 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
import { AsyncResult } from "effect/reactivity";
import { type ReactElement } from "react";
import { describe, expect, it, vi } from "vite-plus/test";
+import { page, userEvent } from "vite-plus/test/browser";
import { act, render } from "../../test/render";
import "../index.css";
@@ -260,6 +261,37 @@ describe("ChatMarkdown workspace file opens", () => {
});
});
+describe("ChatMarkdown skill chips", () => {
+ it("shows the skill's details and opens its instructions", async () => {
+ setup();
+ const threadRef = {
+ environmentId: EnvironmentId.make("workspace"),
+ threadId: ThreadId.make("thread"),
+ };
+ await using screen = await renderText("Run $review now", {
+ threadRef,
+ skills: [
+ {
+ name: "review",
+ displayName: "Review",
+ description: "Reviews the current branch.",
+ path: "/skills/review/SKILL.md",
+ enabled: true,
+ },
+ ],
+ });
+ using openFile = vi
+ .spyOn(useRightPanelStore.getState(), "openFile")
+ .mockImplementation(() => {});
+
+ await userEvent.click(screen.getByRole("button", { name: "Skill Review. Show details" }));
+ await expect.element(page.getByText("Reviews the current branch.")).toBeVisible();
+ await userEvent.click(page.getByRole("button", { name: "View instructions" }));
+
+ expect(openFile).toHaveBeenCalledExactlyOnceWith(threadRef, "/skills/review/SKILL.md");
+ });
+});
+
describe("ChatMarkdown headings", () => {
it("never gives two headings the same id, even when a suffix matches another heading", async () => {
setup();
diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx
index e5691c8cbd3..8831ec98e22 100644
--- a/apps/web/src/components/ChatMarkdown.tsx
+++ b/apps/web/src/components/ChatMarkdown.tsx
@@ -227,7 +227,7 @@ interface ChatMarkdownProps {
environmentId?: EnvironmentId | undefined;
onTaskListChange?: ((input: { markerOffset: number; checked: boolean }) => void) | undefined;
isStreaming?: boolean;
- skills?: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
+ skills?: ReadonlyArray<ServerProviderSkill>;
className?: string;
lineBreaks?: boolean;
parseRawHtml?: boolean;
@@ -250,7 +250,7 @@ export interface ChatMarkdownContextReference {
label: string;
}
-const EMPTY_MARKDOWN_SKILLS: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">> = [];
+const EMPTY_MARKDOWN_SKILLS: ReadonlyArray<ServerProviderSkill> = [];
const EMPTY_REMARK_PLUGINS: NonNullable<ReactMarkdownOptions["remarkPlugins"]> = [];
const ARTIFACT_TEMPLATE_ICON_BY_KIND = {
@@ -958,8 +958,8 @@ const CHAT_MARKDOWN_COMPONENTS = {
return <div {...props}>{children}</div>;
},
p: function MarkdownParagraph({ node: _node, children, ...props }) {
- const { skills } = use(ChatMarkdownRendererContext);
- return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills)}</p>;
+ const { skills, threadRef } = use(ChatMarkdownRendererContext);
+ return <p {...props}>{renderSkillInlineMarkdownChildren(children, skills, threadRef)}</p>;
},
blockquote: function MarkdownBlockquote({ node: _node, children, ...props }) {
const alert =
@@ -994,12 +994,12 @@ const CHAT_MARKDOWN_COMPONENTS = {
);
},
li: function MarkdownListItem({ node, children, ...props }) {
- const { skills } = use(ChatMarkdownRendererContext);
+ const { skills, threadRef } = use(ChatMarkdownRendererContext);
// Resolve checkbox markers by offset to avoid rerendering list items on every streamed token.
const isTaskItem = String(props.className ?? "").includes("task-list-item");
return (
<li {...props} data-list-item-offset={isTaskItem ? node?.position?.start.offset : undefined}>
- {renderSkillInlineMarkdownChildren(children, skills)}
+ {renderSkillInlineMarkdownChildren(children, skills, threadRef)}
</li>
);
},
diff --git a/apps/web/src/components/ComposerPromptEditorTiptap.tsx b/apps/web/src/components/ComposerPromptEditorTiptap.tsx
index 4d20d5b5cb1..f0a23d2ab43 100644
--- a/apps/web/src/components/ComposerPromptEditorTiptap.tsx
+++ b/apps/web/src/components/ComposerPromptEditorTiptap.tsx
@@ -108,11 +108,9 @@ import { cn, isMacPlatform } from "~/lib/utils";
import { basenameOfPath } from "~/pierre-icons";
import { WorkspaceEntryTooltip } from "./chat/WorkspaceEntryIcon";
import { FileTagChipContent } from "./chat/FileTagChip";
-import { SkillChipIcon } from "./chat/SkillInlineText";
+import { SkillChipPopover, skillPopoverDescription } from "./chat/SkillInlineText";
import { AssistantCitationChip } from "./chat/AssistantCitationChip";
import { getTimelinePageScrollKey } from "./chat/pageScrollController";
-import { ContextChipPopover } from "./contextChipParts";
-import { Button } from "./ui/button";
import { ContextChip } from "./ContextChip";
import {
ComposerContextActionsContext,
@@ -348,31 +346,19 @@ function ComposerSkillNodeView({ node }: NodeViewProps) {
const skill = skills.find(
(candidate) => candidate.name === skillName && isProviderSkillUserInvocable(candidate),
);
- const description = skill
- ? skill.description?.trim() || skill.shortDescription?.trim()
- : skillDescription;
// The node outlives a provider switch, so its stored label can be another provider's.
const skillLabel = skill
? formatProviderSkillDisplayName(skill)
: (node.attrs.skillLabel as string) || skillName;
return (
<NodeViewWrapper as="span" className={CHIP_NODE_SELECTION_CLASS_NAME}>
- <ContextChipPopover
- kind="skill"
- icon={<SkillChipIcon />}
+ <SkillChipPopover
label={skillLabel}
- accessibleLabel={`Skill ${skillLabel}`}
- >
- <div className="space-y-3 p-2 text-sm">
- <p className="font-medium">{skillLabel}</p>
- <p>{description || "No description is available for this skill."}</p>
- {skill?.path && actions.environmentId ? (
- <Button variant="outline" size="sm" onClick={() => actions.openMention(skill.path)}>
- View instructions
- </Button>
- ) : null}
- </div>
- </ContextChipPopover>
+ description={skill ? skillPopoverDescription(skill) : skillDescription}
+ onViewInstructions={
+ skill?.path && actions.environmentId ? () => actions.openMention(skill.path) : undefined
+ }
+ />
</NodeViewWrapper>
);
}
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index 6458bd12e58..a8a81d66dd8 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -157,7 +157,7 @@ function TimelineListFooter({
);
}
-const EMPTY_TIMELINE_SKILLS: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">> = [];
+const EMPTY_TIMELINE_SKILLS: ReadonlyArray<ServerProviderSkill> = [];
const TIMELINE_MAINTAIN_SCROLL_AT_END = {
animated: false,
on: {
@@ -253,7 +253,7 @@ interface MessagesTimelineProps {
resolvedTheme: "light" | "dark";
timestampFormat: TimestampFormat;
workspaceRoot: string | undefined;
- skills?: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
+ skills?: ReadonlyArray<ServerProviderSkill>;
runs: ReadonlyArray<HandoffTimelineRun>;
anchorMessageId: MessageId | null;
onAnchorReady: (messageId: MessageId, anchorIndex: number) => void;
diff --git a/apps/web/src/components/chat/SkillInlineText.tsx b/apps/web/src/components/chat/SkillInlineText.tsx
index 0190298d294..59fb9d141e5 100644
--- a/apps/web/src/components/chat/SkillInlineText.tsx
+++ b/apps/web/src/components/chat/SkillInlineText.tsx
@@ -1,11 +1,18 @@
+import type { ScopedThreadRef, ServerProviderSkill } from "@t3tools/contracts";
import { formatProviderSkillDisplayName } from "@t3tools/shared/inlineSkills";
import { Children, cloneElement, isValidElement, type ReactNode } from "react";
-import { matchInlineSkills, type InlineSkill } from "@t3tools/shared/inlineSkills";
+import { matchInlineSkills } from "@t3tools/shared/inlineSkills";
+import { useRightPanelStore } from "~/rightPanelStore";
import { SKILL_CHIP_ICON_SVG } from "../composerInlineChip";
-import { ContextChip, ContextChipLabel } from "../ContextChip";
+import { ContextChipPopover } from "../contextChipParts";
+import { Button } from "../ui/button";
-function SkillInlineText(props: { text: string; skills: ReadonlyArray<InlineSkill> }) {
+function SkillInlineText(props: {
+ text: string;
+ skills: ReadonlyArray<ServerProviderSkill>;
+ threadRef: ScopedThreadRef | undefined;
+}) {
const nodes: ReactNode[] = [];
let cursor = 0;
@@ -13,7 +20,15 @@ function SkillInlineText(props: { text: string; skills: ReadonlyArray<InlineSkil
if (start > cursor) {
nodes.push(props.text.slice(cursor, start));
}
- nodes.push(<SkillChip key={`${start}:${skill.name}`} skill={skill} rawText={rawText} />);
+ nodes.push(
+ <SkillChipPopover
+ key={`${start}:${skill.name}`}
+ label={formatProviderSkillDisplayName(skill)}
+ description={skillPopoverDescription(skill)}
+ copyMarkdown={rawText}
+ onViewInstructions={skillInstructionsOpener(props.threadRef, skill)}
+ />,
+ );
cursor = end;
}
@@ -28,11 +43,12 @@ function SkillInlineText(props: { text: string; skills: ReadonlyArray<InlineSkil
export function renderSkillInlineMarkdownChildren(
children: ReactNode,
- skills: ReadonlyArray<InlineSkill>,
+ skills: ReadonlyArray<ServerProviderSkill>,
+ threadRef: ScopedThreadRef | undefined,
): ReactNode {
return Children.map(children, (child) => {
if (typeof child === "string") {
- return <SkillInlineText text={child} skills={skills} />;
+ return <SkillInlineText text={child} skills={skills} threadRef={threadRef} />;
}
if (!isValidElement<{ children?: ReactNode; node?: { tagName?: string } }>(child)) {
return child;
@@ -48,21 +64,53 @@ export function renderSkillInlineMarkdownChildren(
return cloneElement(
child,
undefined,
- renderSkillInlineMarkdownChildren(child.props.children, skills),
+ renderSkillInlineMarkdownChildren(child.props.children, skills, threadRef),
);
});
}
-function SkillChip(props: { skill: InlineSkill; rawText: string }) {
+export function skillPopoverDescription(
+ skill: Pick<ServerProviderSkill, "description" | "shortDescription">,
+) {
+ return skill.description?.trim() || skill.shortDescription?.trim() || null;
+}
+
+export function skillInstructionsOpener(
+ threadRef: ScopedThreadRef | null | undefined,
+ skill: Pick<ServerProviderSkill, "path"> | undefined,
+) {
+ if (!threadRef || !skill?.path) return undefined;
+ return () => useRightPanelStore.getState().openFile(threadRef, skill.path);
+}
+
+export function SkillChipPopover(props: {
+ label: string;
+ description: string | null | undefined;
+ copyMarkdown?: string | undefined;
+ onViewInstructions: (() => void) | undefined;
+}) {
return (
- <ContextChip kind="skill" data-markdown-copy={props.rawText}>
- <SkillChipIcon />
- <ContextChipLabel>{formatProviderSkillDisplayName(props.skill)}</ContextChipLabel>
- </ContextChip>
+ <ContextChipPopover
+ kind="skill"
+ icon={<SkillChipIcon />}
+ label={props.label}
+ accessibleLabel={`Skill ${props.label}`}
+ copyMarkdown={props.copyMarkdown}
+ >
+ <div className="space-y-3 p-2 text-sm">
+ <p className="font-medium">{props.label}</p>
+ <p>{props.description || "No description is available for this skill."}</p>
+ {props.onViewInstructions ? (
+ <Button variant="outline" size="sm" onClick={props.onViewInstructions}>
+ View instructions
+ </Button>
+ ) : null}
+ </div>
+ </ContextChipPopover>
);
}
-export function SkillChipIcon() {
+function SkillChipIcon() {
return (
<span
aria-hidden="true"
diff --git a/apps/web/src/components/chat/TimelineUserMessageRow.tsx b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
index 6d2a7776091..392311aacd4 100644
--- a/apps/web/src/components/chat/TimelineUserMessageRow.tsx
+++ b/apps/web/src/components/chat/TimelineUserMessageRow.tsx
@@ -735,7 +735,7 @@ const COLLAPSED_USER_MESSAGE_FADE_MASK = `linear-gradient(to bottom, black calc(
const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(props: {
text: string;
renderContextReference: (reference: ChatMarkdownContextReference) => ReactNode;
- skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
+ skills: ReadonlyArray<ServerProviderSkill>;
markdownCwd: string | undefined;
collapsible?: boolean;
footer?: ReactNode;
@@ -811,7 +811,7 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
const UserMessageBody = memo(function UserMessageBody(props: {
text: string;
renderContextReference?: (reference: ChatMarkdownContextReference) => ReactNode;
- skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
+ skills: ReadonlyArray<ServerProviderSkill>;
markdownCwd: string | undefined;
}) {
const ctx = use(TimelineRowCtx);
diff --git a/apps/web/src/components/chat/UserMessageContextChips.tsx b/apps/web/src/components/chat/UserMessageContextChips.tsx
index 8b6b8301fd9..b1179a83c77 100644
--- a/apps/web/src/components/chat/UserMessageContextChips.tsx
+++ b/apps/web/src/components/chat/UserMessageContextChips.tsx
@@ -31,7 +31,6 @@ import { TerminalContextInlineChip } from "./TerminalContextInlineChip";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import {
ContextChipPopover as UserMessageContextPopover,
- ContextChipShell,
FileChip,
ImageChipButton,
PULL_REQUEST_CHIP_KINDS,
@@ -48,7 +47,11 @@ import { formatComposerContextReference } from "@t3tools/shared/composerContextR
import { ContextChip, ContextChipLabel, type ContextChipKind } from "../ContextChip";
import { createContextPresentationRegistry } from "../contextPresentationRegistry";
import type { ChatMarkdownContextReference } from "../ChatMarkdown";
-import { SkillChipIcon } from "./SkillInlineText";
+import {
+ SkillChipPopover,
+ skillInstructionsOpener,
+ skillPopoverDescription,
+} from "./SkillInlineText";
import { formatWorkspaceRelativePath } from "../../filePathDisplay";
import {
buildReviewCommentRenderablePatch,
@@ -99,22 +102,18 @@ function UserMessageMentionChip(props: {
);
}
-function UserMessageContextChip(props: {
- icon: ReactNode;
- label: string;
- kindLabel?: string;
+function UserMessageSkillChip(props: {
+ record: Extract<KnownComposerContextRecord, { kind: "skill" }>;
copyMarkdown: string;
- tooltip?: string;
- kind: ContextChipKind;
}) {
+ const { skills, threadRef } = use(TimelineRowCtx);
+ const skill = skills.find((candidate) => candidate.name === props.record.name);
return (
- <ContextChipShell
- kind={props.kind}
- icon={props.icon}
- label={props.label}
- aria-label={props.kindLabel ? `${props.kindLabel}, ${props.label}` : undefined}
- data-markdown-copy={props.copyMarkdown}
- tooltip={props.tooltip}
+ <SkillChipPopover
+ label={props.record.label || props.record.name}
+ description={skill ? skillPopoverDescription(skill) : null}
+ copyMarkdown={props.copyMarkdown}
+ onViewInstructions={skillInstructionsOpener(threadRef, skill)}
/>
);
}
@@ -315,14 +314,7 @@ const userMessageContextPresentationRegistry = createContextPresentationRegistry
canRender: (record) => record.kind === "skill",
render: (record, context) =>
record.kind === "skill" ? (
- <UserMessageContextChip
- icon={<SkillChipIcon />}
- label={record.label || record.name}
- kindLabel="Skill"
- tooltip={`$${record.name}`}
- copyMarkdown={context.copyMarkdown}
- kind="skill"
- />
+ <UserMessageSkillChip record={record} copyMarkdown={context.copyMarkdown} />
) : (
<UnavailableUserMessageContextChip {...context} />
),
@@ -562,6 +554,7 @@ function UserMessageReviewCommentCard({ comment }: { comment: ReviewCommentConte
<ChatMarkdown
text={comment.text}
cwd={ctx.markdownCwd}
+ threadRef={ctx.threadRef ?? undefined}
skills={ctx.skills}
parseRawHtml={false}
lineBreaks
diff --git a/apps/web/src/components/chat/timelineRowContext.ts b/apps/web/src/components/chat/timelineRowContext.ts
index aa0c919ab10..0b20a001ac7 100644
--- a/apps/web/src/components/chat/timelineRowContext.ts
+++ b/apps/web/src/components/chat/timelineRowContext.ts
@@ -45,7 +45,7 @@ export interface TimelineRowSharedState {
markdownCwd: string | undefined;
resolvedTheme: "light" | "dark";
workspaceRoot: string | undefined;
- skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
+ skills: ReadonlyArray<ServerProviderSkill>;
runs: ReadonlyArray<HandoffTimelineRun>;
activeThreadEnvironmentId: EnvironmentId;
onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
diff --git a/apps/web/src/components/contextChipParts.tsx b/apps/web/src/components/contextChipParts.tsx
index 0917efc269d..9fac67baec2 100644
--- a/apps/web/src/components/contextChipParts.tsx
+++ b/apps/web/src/components/contextChipParts.tsx
@@ -65,7 +65,7 @@ export function ContextChipPopover(props: {
kind: ContextChipKind;
icon: ReactNode;
label: string;
- copyMarkdown?: string;
+ copyMarkdown?: string | undefined;
accessibleLabel: string;
children: ReactNode;
}) {
diff --git a/packages/shared/src/inlineSkills.ts b/packages/shared/src/inlineSkills.ts
index b5f4437b7a3..4898d037682 100644
--- a/packages/shared/src/inlineSkills.ts
+++ b/packages/shared/src/inlineSkills.ts
@@ -24,7 +24,10 @@ export function formatProviderSkillDisplayName(
const SKILL_TOKEN_REGEX =
/(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/gu;
-export function* matchInlineSkills(text: string, skills: readonly InlineSkill[]) {
+export function* matchInlineSkills<Skill extends InlineSkill>(
+ text: string,
+ skills: readonly Skill[],
+) {
for (const match of text.matchAll(SKILL_TOKEN_REGEX)) {
const name = match[2] ?? "";
const skill = skills.find((candidate) => candidate.name === name);