refactor(effect): scope bridges to callback setup

This commit is contained in:
Kit Langton
2026-04-14 19:46:13 -04:00
parent 779616bf6c
commit be1eb706c5
5 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -79,10 +79,10 @@ export namespace Command {
const config = yield* Config.Service
const mcp = yield* MCP.Service
const skill = yield* Skill.Service
const bridge = yield* EffectBridge.make()
const init = Effect.fn("Command.state")(function* (ctx: InstanceContext) {
const cfg = yield* config.get()
const bridge = yield* EffectBridge.make()
const commands: Record<string, Info> = {}
commands[Default.INIT] = {
+5 -4
View File
@@ -444,7 +444,6 @@ export namespace MCP {
return { mcpClient, status, defs: listed } satisfies CreateResult
})
const cfgSvc = yield* Config.Service
const bridge = yield* EffectBridge.make()
const descendants = Effect.fnUntraced(
function* (pid: number) {
@@ -472,7 +471,7 @@ export namespace MCP {
Effect.catch(() => Effect.succeed([] as number[])),
)
function watch(s: State, name: string, client: MCPClient, timeout?: number) {
function watch(s: State, name: string, client: MCPClient, bridge: EffectBridge.Shape, timeout?: number) {
client.setNotificationHandler(ToolListChangedNotificationSchema, async () => {
log.info("tools list changed notification received", { server: name })
if (s.clients[name] !== client || s.status[name]?.status !== "connected") return
@@ -489,6 +488,7 @@ export namespace MCP {
const state = yield* InstanceState.make<State>(
Effect.fn("MCP.state")(function* () {
const cfg = yield* cfgSvc.get()
const bridge = yield* EffectBridge.make()
const config = cfg.mcp ?? {}
const s: State = {
status: {},
@@ -517,7 +517,7 @@ export namespace MCP {
if (result.mcpClient) {
s.clients[key] = result.mcpClient
s.defs[key] = result.defs!
watch(s, key, result.mcpClient, mcp.timeout)
watch(s, key, result.mcpClient, bridge, mcp.timeout)
}
}),
{ concurrency: "unbounded" },
@@ -564,11 +564,12 @@ export namespace MCP {
listed: MCPToolDef[],
timeout?: number,
) {
const bridge = yield* EffectBridge.make()
yield* closeClient(s, name)
s.status[name] = { status: "connected" }
s.clients[name] = client
s.defs[name] = listed
watch(s, name, client, timeout)
watch(s, name, client, bridge, timeout)
return s.status[name]
})
+5 -5
View File
@@ -108,15 +108,15 @@ export namespace Plugin {
Effect.gen(function* () {
const bus = yield* Bus.Service
const config = yield* Config.Service
const bridge = yield* EffectBridge.make()
function publishPluginError(message: string) {
bridge.fork(bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }))
}
const state = yield* InstanceState.make<State>(
Effect.fn("Plugin.state")(function* (ctx) {
const hooks: Hooks[] = []
const bridge = yield* EffectBridge.make()
function publishPluginError(message: string) {
bridge.fork(bus.publish(Session.Event.Error, { error: new NamedError.Unknown({ message }).toObject() }))
}
const { Server } = yield* Effect.promise(() => import("../server/server"))
+1 -1
View File
@@ -1039,11 +1039,11 @@ export namespace Provider {
const auth = yield* Auth.Service
const env = yield* Env.Service
const plugin = yield* Plugin.Service
const bridge = yield* EffectBridge.make()
const state = yield* InstanceState.make<State>(() =>
Effect.gen(function* () {
using _ = log.time("state")
const bridge = yield* EffectBridge.make()
const cfg = yield* config.get()
const modelsDev = yield* Effect.promise(() => ModelsDev.get())
const database = mapValues(modelsDev, fromModelsDevProvider)
+1 -1
View File
@@ -119,7 +119,6 @@ export namespace Pty {
Effect.gen(function* () {
const bus = yield* Bus.Service
const plugin = yield* Plugin.Service
const bridge = yield* EffectBridge.make()
function teardown(session: Active) {
try {
session.process.kill()
@@ -174,6 +173,7 @@ export namespace Pty {
const create = Effect.fn("Pty.create")(function* (input: CreateInput) {
const s = yield* InstanceState.get(state)
const bridge = yield* EffectBridge.make()
const id = PtyID.ascending()
const command = input.command || Shell.preferred()
const args = input.args || []