MCPcopy
hub / github.com/anomalyco/opencode / load

Function load

packages/opencode/test/plugin/loader-shared.test.ts:39–69  ·  view source on GitHub ↗
(dir: string, flags?: Parameters<typeof RuntimeFlags.layer>[0])

Source from the content-addressed store, hash-verified

37}
38
39function load(dir: string, flags?: Parameters<typeof RuntimeFlags.layer>[0]) {
40 const source = path.join(dir, "opencode.json")
41 return Effect.gen(function* () {
42 const config = yield* Effect.promise(
43 () => Bun.file(source).json() as Promise<{ plugin?: Array<string | [string, Record<string, unknown>]> }>,
44 )
45 const plugins = config.plugin ?? []
46 return yield* Effect.gen(function* () {
47 const plugin = yield* Plugin.Service
48 yield* plugin.list()
49 }).pipe(
50 Effect.provide(
51 LayerNode.compile(Plugin.node, [
52 [
53 Config.node,
54 TestConfig.layer({
55 get: () =>
56 Effect.succeed({
57 plugin: plugins,
58 plugin_origins: plugins.map((plugin) => ({ spec: plugin, source, scope: "local" as const })),
59 }),
60 directories: () => Effect.succeed([dir]),
61 }),
62 ],
63 [RuntimeFlags.node, RuntimeFlags.layer({ disableDefaultPlugins: true, ...flags })],
64 ]),
65 ),
66 provideInstance(dir),
67 )
68 })
69}
70
71describe("plugin.loader.shared", () => {
72 it.live("loads a file:// plugin function export", () =>

Callers 1

Calls 5

provideInstanceFunction · 0.90
fileMethod · 0.80
jsonMethod · 0.65
listMethod · 0.65
layerMethod · 0.45

Tested by

no test coverage detected