refactor(plugin): use direct runtime registry

This commit is contained in:
Dax Raad 2026-06-22 20:10:29 -04:00
commit 975b1132f1
14 changed files with 129 additions and 167 deletions

View file

@ -197,22 +197,19 @@ describe("LocationServiceMap", () => {
Effect.flatMap((dir) =>
Effect.gen(function* () {
const plugins = yield* PluginV2.Service
yield* plugins.transform((draft) =>
draft.add(
define({
id: "reviewer",
effect: (ctx) =>
ctx.agent
.transform((agent) => {
agent.update("reviewer", (item) => {
item.description = "Reviews code"
item.mode = "subagent"
})
})
.pipe(Effect.asVoid),
}),
),
)
const reviewer = define({
id: "reviewer",
effect: (ctx) =>
ctx.agent
.transform((agent) => {
agent.update("reviewer", (item) => {
item.description = "Reviews code"
item.mode = "subagent"
})
})
.pipe(Effect.asVoid),
})
yield* plugins.add(PluginV2.ID.make(reviewer.id), reviewer.effect)
expect(yield* (yield* AgentV2.Service).get(AgentV2.ID.make("reviewer"))).toMatchObject({
description: "Reviews code",

View file

@ -9,35 +9,34 @@ import { PluginTestLayer } from "./plugin/fixture"
const it = testEffect(PluginTestLayer)
describe("PluginV2", () => {
it.effect("reconciles transformed plugins", () =>
it.effect("adds, replaces, and removes plugins", () =>
Effect.gen(function* () {
const plugins = yield* PluginV2.Service
const agents = yield* AgentV2.Service
let description = "first"
const registration = yield* plugins.transform((draft) => {
draft.add(
define({
id: "managed",
effect: (ctx) =>
ctx.agent
.transform((agents) =>
agents.update("configured", (agent) => {
agent.description = description
}),
)
.pipe(Effect.asVoid),
}),
)
})
const managed = () =>
define({
id: "managed",
effect: (ctx) =>
ctx.agent
.transform((agents) =>
agents.update("configured", (agent) => {
agent.description = description
}),
)
.pipe(Effect.asVoid),
})
yield* plugins.add(PluginV2.ID.make("managed"), managed().effect)
expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("first")
description = "second"
yield* plugins.reload()
yield* plugins.add(PluginV2.ID.make("managed"), managed().effect)
expect((yield* agents.get(AgentV2.ID.make("configured")))?.description).toBe("second")
yield* registration.dispose
yield* plugins.remove(PluginV2.ID.make("managed"))
expect(yield* agents.get(AgentV2.ID.make("configured"))).toBeUndefined()
}),
)

View file

@ -33,8 +33,8 @@ export function host(overrides: Overrides = {}): PluginContext {
reload: () => Effect.die("unused integration.reload"),
},
plugin: overrides.plugin ?? {
transform: () => Effect.die("unused plugin.transform"),
reload: () => Effect.die("unused plugin.reload"),
add: () => Effect.die("unused plugin.add"),
remove: () => Effect.die("unused plugin.remove"),
},
reference: overrides.reference ?? {
transform: () => Effect.die("unused reference.transform"),