Skip to content
TypeScript

fix(mobile): skill chips in messages open their instructions (#22120)

oliverd3415f36d0cf
diff --git a/apps/mobile/src/features/threads/ThreadFeed.tsx b/apps/mobile/src/features/threads/ThreadFeed.tsx
index 8dd30630755..03e9066c9c2 100644
--- a/apps/mobile/src/features/threads/ThreadFeed.tsx
+++ b/apps/mobile/src/features/threads/ThreadFeed.tsx
@@ -3,7 +3,12 @@ import * as Dialog from "../../components/ui/Dialog";
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
import { ThreadMarkdownVideo, ThreadMediaVisibleContext } from "./ThreadMarkdownVideo";
import { useMarkdownImageSource } from "../../native/useMarkdownImageSource";
-import { enrichedContextLinkPresentation } from "../../lib/enrichedLinkPresentation";
+import {
+ enrichedContextLinkPresentation,
+ enrichedSkillDisplayName,
+ enrichedSkillInstructionsPath,
+ enrichedSkillReference,
+} from "../../lib/enrichedLinkPresentation";
import { ThreadContextDivider } from "./thread-context-divider";
import { ThreadHandoffDivider, ThreadHandoffRow } from "./thread-handoff-row";
import { SecretRequestCard } from "./SecretRequestCard";
@@ -1788,6 +1793,14 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
const iconSubtleColor = theme["--color-icon-subtle"];
const screenColor = theme["--color-screen"];
const userBubbleColor = theme["--color-user-bubble"];
+ const openSkillInstructions = (path: string) => {
+ void Haptics.selectionAsync();
+ navigation.navigate("ThreadFile", {
+ environmentId: String(props.environmentId),
+ threadId: String(props.threadId),
+ path: fileRoutePathSegments(path),
+ });
+ };
const resolveLinkedThread = (href: string) => {
const linkedThreadId = parseThreadLinkHref(href);
if (!linkedThreadId) return null;
@@ -1798,6 +1811,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
);
};
const onMarkdownLinkPress = (href: string, imageEmbed = false) => {
+ const skill = enrichedSkillReference(href, props.skills);
+ if (skill) {
+ const instructionsPath = enrichedSkillInstructionsPath(skill);
+ if (instructionsPath) openSkillInstructions(instructionsPath);
+ return;
+ }
const target = resolveLinkedThread(href);
if (target) {
navigation.navigate("Thread", {
@@ -1868,6 +1887,20 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
onImagePress: (href) => onMarkdownLinkPress(href, true),
resolveImageSource,
fileContextMenu: (href) => {
+ const skill = enrichedSkillReference(href, props.skills);
+ if (skill) {
+ return {
+ title: enrichedSkillDisplayName(skill),
+ actions: [
+ {
+ id: "open-skill",
+ title: "View instructions",
+ disabled: !enrichedSkillInstructionsPath(skill),
+ },
+ { id: "copy-skill", title: "Copy skill" },
+ ],
+ };
+ }
const thread = resolveLinkedThread(href);
if (thread) {
return {
@@ -1883,6 +1916,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
return target ? fileChipMenu(target) : undefined;
},
onFileContextMenuAction: (href, actionId) => {
+ const skill = enrichedSkillReference(href, props.skills);
+ if (skill) {
+ const instructionsPath = enrichedSkillInstructionsPath(skill);
+ if (actionId === "open-skill" && instructionsPath) openSkillInstructions(instructionsPath);
+ else if (actionId === "copy-skill") copyTextWithHaptic(`$${skill.name}`);
+ return;
+ }
if (resolveLinkedThread(href)) {
if (actionId === "open-thread") onMarkdownLinkPress(href);
else if (actionId === "copy-thread-link") copyTextWithHaptic(href);
diff --git a/apps/mobile/src/lib/enrichedLinkPresentation.test.ts b/apps/mobile/src/lib/enrichedLinkPresentation.test.ts
index a6730ce858c..d4c6e5648f0 100644
--- a/apps/mobile/src/lib/enrichedLinkPresentation.test.ts
+++ b/apps/mobile/src/lib/enrichedLinkPresentation.test.ts
@@ -3,6 +3,7 @@ import type { ComposerContextId, ReviewCommentContextRecord } from "@t3tools/con
import {
enrichedContextLinkPresentation,
enrichedLinkVariantPattern,
+ enrichedSkillInstructionsPath,
enrichedSkillLinkRegex,
enrichedSkillReference,
ENRICHED_INLINE_FILE_LINK_REGEX,
@@ -54,6 +55,25 @@ describe("Enriched link presentation", () => {
expect(regex.test(`${sigil}${sigil}check`)).toBe(false);
},
);
+ it("opens skill instructions only for filesystem paths", () => {
+ expect(
+ enrichedSkillInstructionsPath({
+ name: "ketchup",
+ path: "/home/me/.claude/skills/ketchup/SKILL.md",
+ }),
+ ).toBe("/home/me/.claude/skills/ketchup/SKILL.md");
+ expect(
+ enrichedSkillInstructionsPath({ name: "review", path: "C:\\skills\\review\\SKILL.md" }),
+ ).toBe("C:\\skills\\review\\SKILL.md");
+ expect(
+ enrichedSkillInstructionsPath({
+ name: "workspace-skill",
+ path: "acp://skill/workspace-skill",
+ }),
+ ).toBeUndefined();
+ expect(enrichedSkillInstructionsPath({ name: "bare" })).toBeUndefined();
+ });
+
it("matches only the complete URL, including literal regex metacharacters", () => {
const url = "file:///workspace/app[1].tsx?line=3+4";
const pattern = new RegExp(enrichedLinkVariantPattern(url));
diff --git a/apps/mobile/src/lib/enrichedLinkPresentation.ts b/apps/mobile/src/lib/enrichedLinkPresentation.ts
index 1c681691981..99289ed247b 100644
--- a/apps/mobile/src/lib/enrichedLinkPresentation.ts
+++ b/apps/mobile/src/lib/enrichedLinkPresentation.ts
@@ -65,3 +65,7 @@ export function enrichedSkillReference(
const match = /^\p{Sc}(.+)$/u.exec(url);
return match ? skills?.find((skill) => skill.name === match[1]) : undefined;
}
+
+export function enrichedSkillInstructionsPath(skill: SelectableMarkdownSkill) {
+ return skill.path && !/^[a-z][a-z\d+.-]*:\/\//i.test(skill.path) ? skill.path : undefined;
+}
diff --git a/apps/mobile/src/native/SelectableMarkdownText.types.ts b/apps/mobile/src/native/SelectableMarkdownText.types.ts
index 34cf66c12ee..e1a133e57bc 100644
--- a/apps/mobile/src/native/SelectableMarkdownText.types.ts
+++ b/apps/mobile/src/native/SelectableMarkdownText.types.ts
@@ -25,6 +25,7 @@ export interface NativeMarkdownTextStyle {
export interface SelectableMarkdownSkill {
readonly name: string;
readonly displayName?: string | null;
+ readonly path?: string;
}
export interface MarkdownImageRequest {