+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>
150 lines
6.3 KiB
TypeScript
150 lines
6.3 KiB
TypeScript
import fs from "fs/promises"
|
|
import path from "path"
|
|
import { describe, expect } from "bun:test"
|
|
import { Effect, Layer } from "effect"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { PermissionV2 } from "@opencode-ai/core/permission"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { SessionV2 } from "@opencode-ai/core/session"
|
|
import { SkillV2 } from "@opencode-ai/core/skill"
|
|
import { SkillTool } from "@opencode-ai/core/tool/skill"
|
|
import { ToolRegistry } from "@opencode-ai/core/tool/registry"
|
|
import { ToolOutputStore } from "@opencode-ai/core/tool-output-store"
|
|
import { tmpdir } from "./fixture/tmpdir"
|
|
import { it } from "./lib/effect"
|
|
import { toolIdentity, executeTool, settleTool, toolDefinitions } from "./lib/tool"
|
|
|
|
const sessionID = SessionV2.ID.make("ses_skill_tool_test")
|
|
|
|
describe("SkillTool", () => {
|
|
it.live("lists available skills, authorizes the selected name, and loads model-facing content", () =>
|
|
Effect.acquireRelease(
|
|
Effect.promise(() => tmpdir()),
|
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
|
).pipe(
|
|
Effect.flatMap((tmp) =>
|
|
Effect.gen(function* () {
|
|
const directory = path.join(tmp.path, "effect")
|
|
const location = path.join(directory, "SKILL.md")
|
|
const reference = path.join(directory, "reference.md")
|
|
yield* Effect.promise(() => fs.mkdir(directory, { recursive: true }))
|
|
yield* Effect.promise(() =>
|
|
Promise.all([fs.writeFile(location, "unused"), fs.writeFile(reference, "reference")]),
|
|
)
|
|
|
|
const info: SkillV2.Info = {
|
|
name: "effect",
|
|
description: "Use Effect",
|
|
location: AbsolutePath.make(location),
|
|
content: "# Effect\n\nGuidance",
|
|
}
|
|
let current = [info]
|
|
const assertions: PermissionV2.AssertInput[] = []
|
|
let deny = false
|
|
const permission = Layer.succeed(
|
|
PermissionV2.Service,
|
|
PermissionV2.Service.of({
|
|
assert: (input) =>
|
|
Effect.sync(() => assertions.push(input)).pipe(
|
|
Effect.andThen(deny ? Effect.fail(new PermissionV2.DeniedError({ rules: [] })) : Effect.void),
|
|
),
|
|
ask: () => Effect.die("unused"),
|
|
reply: () => Effect.die("unused"),
|
|
get: () => Effect.die("unused"),
|
|
forSession: () => Effect.die("unused"),
|
|
list: () => Effect.die("unused"),
|
|
}),
|
|
)
|
|
const skills = Layer.succeed(
|
|
SkillV2.Service,
|
|
SkillV2.Service.of({
|
|
transform: (_transform) => Effect.die("unused"),
|
|
reload: () => Effect.die("unused"),
|
|
sources: () => Effect.die("unused"),
|
|
list: () => Effect.succeed(current),
|
|
}),
|
|
)
|
|
const skillToolLayer = AppNodeBuilder.build(
|
|
LayerNode.group([ToolRegistry.node, ToolRegistry.toolsNode, SkillTool.node]),
|
|
[
|
|
[PermissionV2.node, permission],
|
|
[SkillV2.node, skills],
|
|
[ToolOutputStore.node, ToolOutputStore.nodeWithoutConfig],
|
|
],
|
|
)
|
|
|
|
return yield* Effect.gen(function* () {
|
|
const registry = yield* ToolRegistry.Service
|
|
expect((yield* toolDefinitions(registry))[0]).toMatchObject({
|
|
name: "skill",
|
|
description: SkillTool.description,
|
|
})
|
|
expect(
|
|
yield* executeTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-skill", name: "skill", input: { name: "effect" } },
|
|
}),
|
|
).toEqual({
|
|
type: "text",
|
|
value: SkillTool.toModelOutput(info, [reference]),
|
|
})
|
|
expect(SkillTool.toModelOutput(info, [reference])).toContain(`Base directory for this skill: ${directory}`)
|
|
expect(
|
|
yield* settleTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-skill-overflow", name: "skill", input: { name: "effect" } },
|
|
}),
|
|
).toMatchObject({
|
|
result: { type: "text", value: SkillTool.toModelOutput(info, [reference]) },
|
|
output: { structured: { name: "effect" } },
|
|
})
|
|
expect(assertions).toMatchObject([
|
|
{ sessionID, action: "skill", resources: ["effect"], save: ["effect"] },
|
|
{ sessionID, action: "skill", resources: ["effect"], save: ["effect"] },
|
|
])
|
|
expect(
|
|
yield* executeTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-missing-skill", name: "skill", input: { name: "missing" } },
|
|
}),
|
|
).toEqual({ type: "error", value: "Unable to load skill missing" })
|
|
deny = true
|
|
expect(
|
|
yield* executeTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-denied-skill", name: "skill", input: { name: "effect" } },
|
|
}),
|
|
).toEqual({ type: "error", value: "Unable to load skill effect" })
|
|
deny = false
|
|
const flat = SkillV2.Info.make({
|
|
name: "public",
|
|
description: "Public guidance",
|
|
location: AbsolutePath.make(path.join(tmp.path, "public.md")),
|
|
content: "Public",
|
|
})
|
|
yield* Effect.promise(() =>
|
|
Promise.all([
|
|
fs.writeFile(flat.location, "public"),
|
|
fs.writeFile(path.join(tmp.path, "secret.md"), "secret"),
|
|
]),
|
|
)
|
|
current = [flat]
|
|
expect(
|
|
yield* executeTool(registry, {
|
|
sessionID,
|
|
...toolIdentity,
|
|
call: { type: "tool-call", id: "call-flat-skill", name: "skill", input: { name: "public" } },
|
|
}),
|
|
).toEqual({ type: "text", value: SkillTool.toModelOutput(flat, []) })
|
|
}).pipe(Effect.provide(skillToolLayer))
|
|
}),
|
|
),
|
|
),
|
|
)
|
|
})
|