+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
220 lines
7.9 KiB
TypeScript
220 lines
7.9 KiB
TypeScript
import fs from "fs/promises"
|
|
import path from "path"
|
|
import { describe, expect } from "bun:test"
|
|
import { Deferred, Effect, Fiber, Layer, Stream } from "effect"
|
|
import { AgentV2 } from "@opencode-ai/core/agent"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { EventV2 } from "@opencode-ai/core/event"
|
|
import { FSUtil } from "@opencode-ai/core/fs-util"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { SkillV2 } from "@opencode-ai/core/skill"
|
|
import { SkillDiscovery } from "@opencode-ai/core/skill/discovery"
|
|
import { FileSystemWatcher } from "@opencode-ai/schema/filesystem-watcher"
|
|
import { tmpdir } from "./fixture/tmpdir"
|
|
import { testEffect } from "./lib/effect"
|
|
|
|
const urls = new Map<string, AbsolutePath[]>()
|
|
let pulls = 0
|
|
const discovery = Layer.succeed(
|
|
SkillDiscovery.Service,
|
|
SkillDiscovery.Service.of({
|
|
pull: (url) => {
|
|
pulls++
|
|
return Effect.succeed(urls.get(url) ?? [])
|
|
},
|
|
}),
|
|
)
|
|
const it = testEffect(
|
|
AppNodeBuilder.build(LayerNode.group([SkillV2.node, AgentV2.node, EventV2.node]), [
|
|
[SkillDiscovery.node, discovery],
|
|
]),
|
|
)
|
|
|
|
function write(directory: string, name: string, description: string) {
|
|
return fs.writeFile(
|
|
path.join(directory, name, "SKILL.md"),
|
|
`---
|
|
name: ${name}
|
|
description: ${description}
|
|
---
|
|
# ${name}`,
|
|
)
|
|
}
|
|
|
|
function waitForSkillUpdate() {
|
|
return Effect.gen(function* () {
|
|
const events = yield* EventV2.Service
|
|
const deferred = yield* Deferred.make<void>()
|
|
const fiber = yield* events.subscribe(SkillV2.Event.Updated).pipe(
|
|
Stream.runForEach(() => Deferred.succeed(deferred, undefined).pipe(Effect.asVoid)),
|
|
Effect.forkScoped,
|
|
)
|
|
yield* Effect.yieldNow
|
|
return { deferred, fiber }
|
|
})
|
|
}
|
|
|
|
describe("SkillV2", () => {
|
|
it.live("registers sources and resolves later source precedence", () =>
|
|
Effect.acquireRelease(
|
|
Effect.promise(() => tmpdir()),
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
).pipe(
|
|
Effect.flatMap((tmp) =>
|
|
Effect.gen(function* () {
|
|
const first = path.join(tmp.path, "first")
|
|
const second = path.join(tmp.path, "second")
|
|
yield* Effect.promise(async () => {
|
|
await fs.mkdir(path.join(first, "review"), { recursive: true })
|
|
await fs.mkdir(path.join(second, "review"), { recursive: true })
|
|
await write(first, "review", "First")
|
|
await write(second, "review", "Second")
|
|
await fs.writeFile(path.join(first, "foo.md"), "---\nslash: true\n---\n# foo")
|
|
})
|
|
|
|
const skill = yield* SkillV2.Service
|
|
yield* skill.transform((editor) => {
|
|
editor.source({ type: "directory", path: AbsolutePath.make(first) })
|
|
editor.source({ type: "directory", path: AbsolutePath.make(first) })
|
|
editor.source({ type: "directory", path: AbsolutePath.make(second) })
|
|
expect(editor.list()).toEqual([
|
|
{ type: "directory", path: AbsolutePath.make(first) },
|
|
{ type: "directory", path: AbsolutePath.make(second) },
|
|
])
|
|
})
|
|
|
|
expect(yield* skill.sources()).toEqual([
|
|
{ type: "directory", path: AbsolutePath.make(first) },
|
|
{ type: "directory", path: AbsolutePath.make(second) },
|
|
])
|
|
expect(yield* skill.list()).toEqual([
|
|
SkillV2.Info.make({
|
|
name: "foo",
|
|
slash: true,
|
|
location: AbsolutePath.make(path.join(first, "foo.md")),
|
|
content: "# foo",
|
|
}),
|
|
{
|
|
name: "review",
|
|
description: "Second",
|
|
location: AbsolutePath.make(path.join(second, "review", "SKILL.md")),
|
|
content: "# review",
|
|
},
|
|
])
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
|
|
it.live("loads URL sources and filters skills for agents", () =>
|
|
Effect.acquireRelease(
|
|
Effect.promise(() => tmpdir()),
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
).pipe(
|
|
Effect.flatMap((tmp) =>
|
|
Effect.gen(function* () {
|
|
yield* Effect.promise(async () => {
|
|
await fs.mkdir(path.join(tmp.path, "deploy"), { recursive: true })
|
|
await write(tmp.path, "deploy", "Deploy production")
|
|
})
|
|
pulls = 0
|
|
urls.set("https://example.test/skills/", [AbsolutePath.make(tmp.path)])
|
|
|
|
const agents = yield* AgentV2.Service
|
|
yield* agents.transform((editor) =>
|
|
editor.update(AgentV2.ID.make("reviewer"), (agent) => {
|
|
agent.permissions.push({ action: "skill", resource: "deploy", effect: "deny" })
|
|
}),
|
|
)
|
|
|
|
const skill = yield* SkillV2.Service
|
|
yield* skill.transform((editor) => editor.source({ type: "url", url: "https://example.test/skills/" }))
|
|
|
|
expect((yield* skill.list()).map((item) => item.name)).toEqual(["deploy"])
|
|
expect((yield* skill.list()).map((item) => item.name)).toEqual(["deploy"])
|
|
expect(pulls).toBe(1)
|
|
expect(SkillV2.available(yield* skill.list(), (yield* agents.get(AgentV2.ID.make("reviewer")))!)).toEqual([])
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
|
|
it.live("parses opencode metadata flags from skill frontmatter", () =>
|
|
Effect.acquireRelease(
|
|
Effect.promise(() => tmpdir()),
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
).pipe(
|
|
Effect.flatMap((tmp) =>
|
|
Effect.gen(function* () {
|
|
yield* Effect.promise(async () => {
|
|
await fs.mkdir(path.join(tmp.path, "manual"), { recursive: true })
|
|
await fs.writeFile(
|
|
path.join(tmp.path, "manual", "SKILL.md"),
|
|
`---
|
|
name: manual
|
|
description: Manual only
|
|
metadata:
|
|
opencode/slash: true
|
|
opencode/autoinvoke: false
|
|
---
|
|
# manual`,
|
|
)
|
|
})
|
|
|
|
const skill = yield* SkillV2.Service
|
|
yield* skill.transform((editor) => editor.source({ type: "directory", path: AbsolutePath.make(tmp.path) }))
|
|
|
|
expect(yield* skill.list()).toEqual([
|
|
{
|
|
name: "manual",
|
|
description: "Manual only",
|
|
slash: true,
|
|
autoinvoke: false,
|
|
location: AbsolutePath.make(path.join(tmp.path, "manual", "SKILL.md")),
|
|
content: "# manual",
|
|
},
|
|
])
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
|
|
it.live("invalidates cached skills and publishes updates for watcher changes", () =>
|
|
Effect.acquireRelease(
|
|
Effect.promise(() => tmpdir()),
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
).pipe(
|
|
Effect.flatMap((tmp) =>
|
|
Effect.gen(function* () {
|
|
yield* Effect.promise(async () => {
|
|
await fs.mkdir(path.join(tmp.path, "deploy"), { recursive: true })
|
|
await write(tmp.path, "deploy", "Initial deploy")
|
|
})
|
|
|
|
const events = yield* EventV2.Service
|
|
const skill = yield* SkillV2.Service
|
|
yield* skill.transform((editor) => editor.source({ type: "directory", path: AbsolutePath.make(tmp.path) }))
|
|
|
|
expect((yield* skill.list()).find((item) => item.name === "deploy")?.description).toBe("Initial deploy")
|
|
|
|
const file = path.join(tmp.path, "deploy", "SKILL.md")
|
|
yield* Effect.promise(() => write(tmp.path, "deploy", "Updated deploy"))
|
|
expect((yield* skill.list()).find((item) => item.name === "deploy")?.description).toBe("Initial deploy")
|
|
|
|
yield* Effect.acquireUseRelease(
|
|
waitForSkillUpdate(),
|
|
({ deferred }) =>
|
|
events
|
|
.publish(FileSystemWatcher.Event.Updated, { file, event: "change" })
|
|
.pipe(Effect.andThen(Deferred.await(deferred)), Effect.timeout("1 second")),
|
|
({ fiber }) => Fiber.interrupt(fiber),
|
|
)
|
|
|
|
expect((yield* skill.list()).find((item) => item.name === "deploy")?.description).toBe("Updated deploy")
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
})
|