mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
fix(app): render inline content for built-in skills (#60464)
This commit is contained in:
committed by
GitHub
Unverified
parent
f1627d98e3
commit
78f8dffd48
@@ -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()
|
||||
|
||||
@@ -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<FileState["content"]> =>
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user