|
|
@@ -2,7 +2,7 @@ export * as ConfigExternalPlugin from "./external"
|
|
|
|
|
|
import type { Plugin as EffectPlugin } from "@opencode-ai/plugin/v2/effect"
|
|
|
import type { Plugin as PromisePlugin } from "@opencode-ai/plugin/v2/promise"
|
|
|
-import { Effect, Schema, Stream } from "effect"
|
|
|
+import { Effect, Schema } from "effect"
|
|
|
import path from "path"
|
|
|
import { fileURLToPath, pathToFileURL } from "url"
|
|
|
import { Config } from "../../config"
|
|
|
@@ -42,7 +42,6 @@ export const Plugin = define({
|
|
|
const fs = yield* FSUtil.Service
|
|
|
const location = yield* Location.Service
|
|
|
const npm = yield* Npm.Service
|
|
|
- const active = new Set<string>()
|
|
|
const load = Effect.fn("ConfigExternalPlugin.load")(function* () {
|
|
|
const configured: { package: string; options?: Record<string, unknown> }[] = []
|
|
|
|
|
|
@@ -117,23 +116,7 @@ export const Plugin = define({
|
|
|
}).pipe(Effect.catchCause(() => Effect.succeed(undefined))),
|
|
|
).pipe(Effect.map((plugins) => plugins.filter((plugin) => plugin !== undefined)))
|
|
|
})
|
|
|
- const reconcile = Effect.fn("ConfigExternalPlugin.reconcile")(function* () {
|
|
|
- const plugins = yield* load()
|
|
|
- const next = new Set(plugins.map((plugin) => plugin.id))
|
|
|
- for (const id of active) {
|
|
|
- if (!next.has(id)) yield* ctx.plugin.remove(id)
|
|
|
- }
|
|
|
- for (const plugin of plugins) yield* ctx.plugin.add(plugin)
|
|
|
- active.clear()
|
|
|
- for (const id of next) active.add(id)
|
|
|
- })
|
|
|
-
|
|
|
- yield* reconcile()
|
|
|
- yield* ctx.event.subscribe().pipe(
|
|
|
- Stream.filter((event) => event.type === "config.updated"),
|
|
|
- Stream.runForEach(() => reconcile()),
|
|
|
- Effect.forkScoped({ startImmediately: true }),
|
|
|
- )
|
|
|
+ for (const plugin of yield* load()) yield* ctx.plugin.add(plugin)
|
|
|
}),
|
|
|
})
|
|
|
|