mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-18 15:28:48 +03:00
feat(plugin): add skill editor lookup
This commit is contained in:
committed by
GitHub
Unverified
parent
22de01e84f
commit
962c26bdf2
@@ -407,6 +407,7 @@ export const make = Effect.fn("PluginHost.make")(function* (
|
||||
skill.transform((editor) => {
|
||||
callback({
|
||||
list: () => mutable(editor.list()),
|
||||
get: editor.get,
|
||||
add: (value) => editor.add(Schema.decodeUnknownSync(Skill.Info)(value)),
|
||||
update: editor.update,
|
||||
remove: editor.remove,
|
||||
|
||||
@@ -74,6 +74,7 @@ export type Data = {
|
||||
|
||||
export type Editor = {
|
||||
list: () => readonly Types.DeepMutable<Info>[]
|
||||
get: (id: string) => Types.DeepMutable<Info> | undefined
|
||||
add: (skill: Info) => void
|
||||
update: (id: string, update: (skill: Types.DeepMutable<Info>) => void) => void
|
||||
remove: (id: string) => void
|
||||
@@ -96,6 +97,7 @@ const layer = Layer.effect(
|
||||
initial: () => ({ skills: new Map() }),
|
||||
editor: (editor) => ({
|
||||
list: () => Array.from(editor.skills.values()),
|
||||
get: (id) => editor.skills.get(ID.make(id)),
|
||||
add: (skill) => {
|
||||
editor.skills.set(skill.id, { ...skill } as Types.DeepMutable<Info>)
|
||||
},
|
||||
|
||||
@@ -20,6 +20,25 @@ const info = (id: string, description: string) =>
|
||||
})
|
||||
|
||||
describe("Skill", () => {
|
||||
it.effect("reads the current editor entry by ID", () =>
|
||||
Effect.gen(function* () {
|
||||
const skill = yield* Skill.Service
|
||||
yield* skill.transform((editor) => editor.add(info("review", "Initial")))
|
||||
yield* skill.transform((editor) => {
|
||||
expect(editor.get("review")).toBe(editor.list()[0])
|
||||
expect(editor.get("missing")).toBeUndefined()
|
||||
editor.update("review", (value) => {
|
||||
value.description = "Updated"
|
||||
})
|
||||
expect(editor.get("review")?.description).toBe("Updated")
|
||||
editor.remove("review")
|
||||
expect(editor.get("review")).toBeUndefined()
|
||||
})
|
||||
|
||||
expect(yield* skill.list()).toEqual([])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("registers values with last-write-wins precedence", () =>
|
||||
Effect.gen(function* () {
|
||||
const skill = yield* Skill.Service
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { Transform } from "./registration.js"
|
||||
|
||||
export interface SkillEditor {
|
||||
list(): readonly Types.DeepMutable<Skill.Info>[]
|
||||
get(id: string): Types.DeepMutable<Skill.Info> | undefined
|
||||
add(skill: Skill.Info): void
|
||||
update(id: string, update: (skill: Types.DeepMutable<Skill.Info>) => void): void
|
||||
remove(id: string): void
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { DeepMutable } from "./types.js"
|
||||
|
||||
export interface SkillEditor {
|
||||
list(): readonly DeepMutable<Skill.Info>[]
|
||||
get(id: string): DeepMutable<Skill.Info> | undefined
|
||||
add(skill: Skill.Info): void
|
||||
update(id: string, update: (skill: DeepMutable<Skill.Info>) => void): void
|
||||
remove(id: string): void
|
||||
|
||||
@@ -747,7 +747,8 @@ effect: (ctx) =>
|
||||
}),
|
||||
```
|
||||
|
||||
Transform and reload skills. Use the re-exported Effect schema constructors for branded values.
|
||||
Transform and reload skills. Use the re-exported Effect schema constructors for branded values. `get(id)` returns the
|
||||
current editor entry, or `undefined` when the skill is absent.
|
||||
|
||||
```ts
|
||||
effect: (ctx) =>
|
||||
@@ -761,6 +762,7 @@ effect: (ctx) =>
|
||||
location: "/workspace/.opencode/skills/review.md",
|
||||
content: "Review the current changes for correctness and missing tests.",
|
||||
}))
|
||||
const review = editor.get("review")
|
||||
editor.update("review", (item) => (item.autoinvoke = true))
|
||||
editor.remove("legacy")
|
||||
})
|
||||
@@ -773,6 +775,7 @@ Schema: [`Skill.Info`](/api#schema-Skill.Info).
|
||||
```ts
|
||||
interface SkillEditor {
|
||||
list(): readonly Types.DeepMutable<Skill.Info>[]
|
||||
get(id: string): Types.DeepMutable<Skill.Info> | undefined
|
||||
add(skill: Skill.Info): void
|
||||
update(id: string, update: (skill: Types.DeepMutable<Skill.Info>) => void): void
|
||||
remove(id: string): void
|
||||
|
||||
@@ -717,7 +717,8 @@ Read the skills available at a location.
|
||||
const skills = await ctx.skill.list()
|
||||
```
|
||||
|
||||
Register a transform to inspect, add, update, or remove skills.
|
||||
Register a transform to inspect, add, update, or remove skills. `get(id)` returns the current editor entry, or `undefined`
|
||||
when the skill is absent.
|
||||
|
||||
```ts
|
||||
await ctx.skill.transform((editor) => {
|
||||
@@ -729,6 +730,7 @@ await ctx.skill.transform((editor) => {
|
||||
location: "/workspace/.opencode/skills/review.md",
|
||||
content: "Review the current changes for correctness and missing tests.",
|
||||
})
|
||||
const review = editor.get("review")
|
||||
editor.update("review", (skill) => {
|
||||
skill.autoinvoke = true
|
||||
})
|
||||
@@ -755,6 +757,7 @@ interface SkillContext {
|
||||
|
||||
interface SkillEditor {
|
||||
list(): readonly SkillInfo[]
|
||||
get(id: string): SkillInfo | undefined
|
||||
add(skill: SkillInfo): void
|
||||
update(id: string, update: (skill: SkillInfo) => void): void
|
||||
remove(id: string): void
|
||||
|
||||
Reference in New Issue
Block a user