From 78f8dffd48e1aa4c8a7f822736b393c39e303f59 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Fri, 30 Oct 2026 14:27:04 +1000 Subject: [PATCH] fix(app): render inline content for built-in skills (#60464) --- .../e2e/regression/session-summary.spec.ts | 25 +++++++++- packages/app/src/workspaces/files/model.tsx | 48 +++++++++++++++---- 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/packages/app/e2e/regression/session-summary.spec.ts b/packages/app/e2e/regression/session-summary.spec.ts index 4ea24f3a0af..25e5a048d89 100644 --- a/packages/app/e2e/regression/session-summary.spec.ts +++ b/packages/app/e2e/regression/session-summary.spec.ts @@ -679,11 +679,15 @@ test("Extensions lists open on hover, hold course into the open list, and follow test("Extensions lists open config files and skills in a side tab and start setup sessions", async ({ page }) => { const global = "C:/Users/kit/.config/opencode/opencode.jsonc" const skill = `${fixture.directory}/.opencode/skills/release-notes/SKILL.md` + let builtinReads = 0 await mockStressTimeline(page, { mcp: [{ name: "atlas-search", status: { status: "connected" } }], plugins: [], - skills: [{ id: "release-notes", name: "release-notes", path: skill, content: "Release notes" }], + skills: [ + { id: "opencode", name: "OpenCode", path: "/builtin/opencode.md", content: "# Built-in OpenCode guide" }, + { id: "release-notes", name: "release-notes", path: skill, content: "Release notes" }, + ], configEntries: [ { type: "document", @@ -695,6 +699,16 @@ test("Extensions lists open config files and skills in a side tab and start setu ], fileContent: (path) => ({ type: "text", content: `contents:${path}` }), }) + + await page.route(/\/api\/fs\/read\/opencode\.md(\?|$)/, (route) => { + builtinReads += 1 + + return route.fulfill({ + status: 404, + json: { message: "Location not found: /builtin" }, + headers: cors, + }) + }) await page.goto(sessionHref(fixture.targetID)) const trigger = page.getByRole("button", { name: "Session details", exact: true }) const summary = page.getByRole("dialog", { name: "Session details", exact: true }) @@ -711,6 +725,15 @@ test("Extensions lists open config files and skills in a side tab and start setu await expect(page.getByRole("tab", { name: "opencode.jsonc", exact: true })).toHaveAttribute("aria-selected", "true") await expect(page.getByText("contents:opencode.jsonc", { exact: true })).toBeVisible() + await trigger.click() + await row("Skills").hover() + await list("Skills").getByRole("button", { name: "OpenCode", exact: true }).click() + await expect(summary).toBeHidden() + await expect(page.getByRole("tab", { name: "opencode.md", exact: true })).toHaveAttribute("aria-selected", "true") + await expect(page.getByRole("heading", { name: "Built-in OpenCode guide", exact: true })).toBeVisible() + await expect(page.getByText("Failed to load file", { exact: true })).toHaveCount(0) + expect(builtinReads).toBe(0) + await trigger.click() await row("Skills").hover() await list("Skills").getByRole("button", { name: "release-notes", exact: true }).click() diff --git a/packages/app/src/workspaces/files/model.tsx b/packages/app/src/workspaces/files/model.tsx index 9a6042b670b..49d066acea4 100644 --- a/packages/app/src/workspaces/files/model.tsx +++ b/packages/app/src/workspaces/files/model.tsx @@ -9,7 +9,7 @@ import { useWorkspaceLocation } from "@/workspaces/location" import { useLanguage } from "@/runtime/i18n/language" import { usePluginAttachment } from "@/runtime/plugin/host-apis" import { createPathHelpers } from "./path" -import { artifactKind } from "@opencode/util/artifact" +import { artifactKind, artifactMime } from "@opencode/util/artifact" import { usePlatform } from "@/runtime/platform/platform" import { fileStreamUrl } from "@/runtime/server/api" import { fileContentFromBytes, streamedFileContent, streamedKinds } from "./artifact" @@ -23,6 +23,7 @@ import { } from "./content-cache" import { createFileViewCache } from "./view-cache" import { useServerSDK } from "@/runtime/server/client" +import { useData } from "@/runtime/server/current" import { formatServerError } from "@/runtime/server/errors" import { createFileTreeStore } from "./tree-store" import { invalidateFromWatcher } from "./watcher" @@ -39,6 +40,7 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({ const sdk = useWorkspaceLocation() const params = useParams() const serverSDK = useServerSDK() + const data = useData() const platform = usePlatform() const language = useLanguage() const attachment = usePluginAttachment() @@ -178,6 +180,20 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({ ) } + // Built-in skills register virtual `/builtin/*.md` paths whose content is inline in `/api/skill`. + const builtinSkill = async (file: string, directory: string) => { + if (data.location.skill.list({ directory }) === undefined) { + await data.location.skill.sync({ directory }) + } + + return (data.location.skill.list({ directory }) ?? data.location.skill.list())?.find((item) => item.path === file) + } + + const readBuiltin = (file: string, directory: string): Promise => + builtinSkill(file, directory).then((skill) => + skill ? { type: "text", content: skill.content, mimeType: artifactMime(file) } : undefined, + ) + const load = (input: string, options?: { force?: boolean; silent?: boolean }) => { const file = path.normalize(input) @@ -202,20 +218,32 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({ setLoading(file) - // Files outside the workspace are read from their own directory, like markdown images. - // The trailing separator from getDirectory keeps "/" and "C:/" valid, like readLocalImage. - const request = path.absolute(file) - ? { path: getFilename(file), location: { directory: getDirectory(file) } } - : { path: file, location: { directory } } - const entry = { silent, promise: Promise.resolve(), } - entry.promise = read(file, request) + // Files outside the workspace are read from their own directory, like markdown images. + // The trailing separator from getDirectory keeps "/" and "C:/" valid, like readLocalImage. + const source = file.startsWith("/builtin/") + ? readBuiltin(file, directory) + : read( + file, + path.absolute(file) + ? { path: getFilename(file), location: { directory: getDirectory(file) } } + : { path: file, location: { directory } }, + ) + + entry.promise = source .then((content) => { if (scope() !== directory) return + + if (!content) { + setLoadError(file, file, true, entry.silent) + + return + } + setLoaded(file, content) touchFileContent(file, approxBytes(content)) evictContent(new Set([file])) @@ -244,6 +272,10 @@ export const { use: useFile, provider: FileProvider } = createSimpleContext({ if (!file) return Promise.resolve(false) + if (file.startsWith("/builtin/")) { + return builtinSkill(file, scope()).then(Boolean, () => false) + } + const parent = /[\\/]/.test(file) ? getDirectory(file) : undefined return serverSDK.api.file.list({ path: parent, location: { directory: scope() } }).then(