+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>
143 lines
4.2 KiB
TypeScript
143 lines
4.2 KiB
TypeScript
import { describe, expect } from "bun:test"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { Effect, Layer } from "effect"
|
|
import type { Agent } from "../../src/agent/agent"
|
|
import { NamedError } from "@opencode-ai/core/util/error"
|
|
import { Skill } from "../../src/skill"
|
|
import { Permission } from "../../src/permission"
|
|
import { SystemPrompt } from "../../src/session/system"
|
|
import { MCP } from "../../src/mcp"
|
|
import { testEffect } from "../lib/effect"
|
|
|
|
const skills: Skill.Info[] = [
|
|
{
|
|
name: "zeta-skill",
|
|
description: "Zeta skill.",
|
|
location: "/tmp/zeta-skill/SKILL.md",
|
|
content: "# zeta-skill",
|
|
},
|
|
{
|
|
name: "alpha-skill",
|
|
description: "Alpha skill.",
|
|
location: "/tmp/alpha-skill/SKILL.md",
|
|
content: "# alpha-skill",
|
|
},
|
|
{
|
|
name: "middle-skill",
|
|
description: "Middle skill.",
|
|
location: "/tmp/middle-skill/SKILL.md",
|
|
content: "# middle-skill",
|
|
},
|
|
{
|
|
name: "manual-skill",
|
|
location: "/tmp/manual-skill/SKILL.md",
|
|
content: "# manual-skill",
|
|
},
|
|
]
|
|
|
|
const build: Agent.Info = {
|
|
name: "build",
|
|
mode: "primary",
|
|
permission: Permission.fromConfig({ "*": "allow" }),
|
|
options: {},
|
|
}
|
|
|
|
const it = testEffect(
|
|
LayerNode.compile(SystemPrompt.node, [
|
|
[
|
|
MCP.node,
|
|
Layer.mock(MCP.Service, {
|
|
instructions: () =>
|
|
Effect.succeed([
|
|
{
|
|
name: "guide-server",
|
|
instructions: "Use lookup before mutate.",
|
|
tools: [],
|
|
},
|
|
{
|
|
name: "tool-server",
|
|
instructions: "Prefer search before update.",
|
|
tools: ["tool-server_search", "tool-server_update"],
|
|
},
|
|
]),
|
|
}),
|
|
],
|
|
[
|
|
Skill.node,
|
|
Layer.succeed(
|
|
Skill.Service,
|
|
Skill.Service.of({
|
|
get: (name) => Effect.succeed(skills.find((skill) => skill.name === name)),
|
|
require: (name) => {
|
|
const info = skills.find((skill) => skill.name === name)
|
|
if (info) return Effect.succeed(info)
|
|
return Effect.fail(new Skill.NotFoundError({ name, available: skills.map((skill) => skill.name) }))
|
|
},
|
|
all: () => Effect.succeed(skills),
|
|
dirs: () => Effect.succeed([]),
|
|
available: () => Effect.succeed(skills),
|
|
}),
|
|
),
|
|
],
|
|
]),
|
|
)
|
|
|
|
describe("session.system", () => {
|
|
it.effect("skills output is sorted by name and stable across calls", () =>
|
|
Effect.gen(function* () {
|
|
const prompt = yield* SystemPrompt.Service
|
|
const first = yield* prompt.skills(build)
|
|
const second = yield* prompt.skills(build)
|
|
const output = first ?? (yield* Effect.fail(new NamedError.Unknown({ message: "missing skills output" })))
|
|
|
|
expect(first).toBe(second)
|
|
|
|
const alpha = output.indexOf("<name>alpha-skill</name>")
|
|
const middle = output.indexOf("<name>middle-skill</name>")
|
|
const zeta = output.indexOf("<name>zeta-skill</name>")
|
|
|
|
expect(alpha).toBeGreaterThan(-1)
|
|
expect(middle).toBeGreaterThan(alpha)
|
|
expect(zeta).toBeGreaterThan(middle)
|
|
expect(output).not.toContain("manual-skill")
|
|
}),
|
|
)
|
|
|
|
it.effect("MCP output includes connected server instructions", () =>
|
|
Effect.gen(function* () {
|
|
const prompt = yield* SystemPrompt.Service
|
|
const output = yield* prompt.mcp(build)
|
|
|
|
expect(output).toBe(
|
|
[
|
|
"<mcp_instructions>",
|
|
' <server name="guide-server">',
|
|
" Use lookup before mutate.",
|
|
" </server>",
|
|
' <server name="tool-server">',
|
|
" Prefer search before update.",
|
|
" </server>",
|
|
"</mcp_instructions>",
|
|
].join("\n"),
|
|
)
|
|
}),
|
|
)
|
|
|
|
it.effect("MCP output omits servers when all advertised tools are denied", () =>
|
|
Effect.gen(function* () {
|
|
const prompt = yield* SystemPrompt.Service
|
|
const output = yield* prompt.mcp(build, Permission.fromConfig({ "tool-server_*": "deny" }))
|
|
|
|
expect(output).toBe(
|
|
[
|
|
"<mcp_instructions>",
|
|
' <server name="guide-server">',
|
|
" Use lookup before mutate.",
|
|
" </server>",
|
|
"</mcp_instructions>",
|
|
].join("\n"),
|
|
)
|
|
}),
|
|
)
|
|
})
|