From ba64fc5add49ad5b5700ef93e1a4629e6d0023bd Mon Sep 17 00:00:00 2001 From: elpresidank Date: Tue, 2 Jun 2026 01:13:40 -0500 Subject: [PATCH] Normalize flow service runtime entrypoints --- ts/EFFECT_NATIVE_REWRITE_AUDIT.md | 38 +++++++++++++++----- ts/packages/flow/src/flow-manager/service.ts | 11 ++++-- ts/packages/flow/src/librarian/service.ts | 11 ++++-- ts/scripts/run-flow-manager.ts | 7 ++-- ts/scripts/run-librarian.ts | 7 ++-- 5 files changed, 51 insertions(+), 23 deletions(-) diff --git a/ts/EFFECT_NATIVE_REWRITE_AUDIT.md b/ts/EFFECT_NATIVE_REWRITE_AUDIT.md index a9ac57d8..a3c734c7 100644 --- a/ts/EFFECT_NATIVE_REWRITE_AUDIT.md +++ b/ts/EFFECT_NATIVE_REWRITE_AUDIT.md @@ -12,14 +12,14 @@ Verified source roots: - Effect v4 subtree: `/home/elpresidank/YeeBois/projects/beep-effect2/.repos/effect-v4` - Installed Effect beta used by this workspace: `ts/node_modules/effect` -Current signal counts from `ts/packages` after the 2026-06-02 KnowledgeCore -ref-backed state slice: +Current signal counts from `ts/packages` after the 2026-06-02 +flow-manager/librarian runtime normalization slice: | Signal | Count | | --- | ---: | -| `Effect.runPromise` | 200 | -| `Map<` | 72 | -| `WebSocket` | 51 | +| `Effect.runPromise` | 198 | +| `Map<` | 71 | +| `WebSocket` | 47 | | `new Map` | 53 | | `toPromiseRequestor` | 0 | | `makeAsyncProcessor` | 19 | @@ -196,6 +196,25 @@ Notes: - `cd ts && bun run build` - `cd ts && bun run test` +### 2026-06-02: Flow Manager And Librarian Runtime Normalization + +- Status: migrated and root-verified. +- Completed: + - `ts/packages/flow/src/flow-manager/service.ts` and + `ts/packages/flow/src/librarian/service.ts` now expose `runMain()` through + `NodeRuntime.runMain`. + - Their legacy `run()` Promise facades now use `ManagedRuntime` instead of + directly owning `Effect.runPromise`. + - `ts/scripts/run-flow-manager.ts` and `ts/scripts/run-librarian.ts` now + delegate to `runMain()` instead of wrapping startup with local + `.catch(console.error/process.exit)` handlers. +- Verification: + - `bun run --cwd ts/packages/flow build` + - `cd ts && bun run check` + - `cd ts && bun run build` + - `cd ts && bun run test` + - `git diff --check` + ## Subagent Findings To Preserve - MCP/workbench: @@ -206,10 +225,11 @@ Notes: - MCP env is now Config-backed; continue that policy for future MCP settings. - Flow stateful services: - Config service and KnowledgeCore service ref-backed state are complete. - Librarian and flow-manager still have mutable poller service objects. - These remain good - candidates for `Context` services, - scoped layers, `Ref`/`SynchronizedRef`, `Schedule`, and managed + Librarian and flow-manager now have native Effect module startup + (`NodeRuntime.runMain` with `ManagedRuntime` compatibility facades), but + they still have mutable poller service objects. These remain good + candidates for `Context` services, scoped layers, + `Ref`/`SynchronizedRef`, `Schedule`, and managed persistence. - Persistence IO should move toward `FileSystem` or `KeyValueStore` where the installed beta has the needed provider surface. diff --git a/ts/packages/flow/src/flow-manager/service.ts b/ts/packages/flow/src/flow-manager/service.ts index ff99ed58..8fb22ff7 100644 --- a/ts/packages/flow/src/flow-manager/service.ts +++ b/ts/packages/flow/src/flow-manager/service.ts @@ -26,7 +26,8 @@ import { } from "@trustgraph/base"; import { makeProcessorProgram } from "@trustgraph/base"; import type { Message } from "@trustgraph/base"; -import { Context, Duration, Effect, Option } from "effect"; +import { NodeRuntime } from "@effect/platform-node"; +import { Context, Duration, Effect, Layer, ManagedRuntime, Option } from "effect"; import * as S from "effect/Schema"; // ---------- Internal state types ---------- @@ -885,6 +886,12 @@ export const program = makeProcessorProgram({ make: (config) => makeFlowManagerService(config), }); +const flowManagerRuntime = ManagedRuntime.make(Layer.empty); + export function run(): Promise { - return Effect.runPromise(program); + return flowManagerRuntime.runPromise(program); +} + +export function runMain(): void { + NodeRuntime.runMain(program); } diff --git a/ts/packages/flow/src/librarian/service.ts b/ts/packages/flow/src/librarian/service.ts index 1877c293..51c3f2e2 100644 --- a/ts/packages/flow/src/librarian/service.ts +++ b/ts/packages/flow/src/librarian/service.ts @@ -25,7 +25,8 @@ import { type ProcessingMetadata, } from "@trustgraph/base"; import type { Message } from "@trustgraph/base"; -import { Clock, Config, Context, DateTime, Duration, Effect, Random } from "effect"; +import { NodeRuntime } from "@effect/platform-node"; +import { Clock, Config, Context, DateTime, Duration, Effect, Layer, ManagedRuntime, Random } from "effect"; import * as S from "effect/Schema"; import { makeCollectionManager } from "./collection-manager.js"; import { @@ -1349,6 +1350,12 @@ export const program = makeProcessorProgram({ make: (config) => makeLibrarianService(config), }); +const librarianRuntime = ManagedRuntime.make(Layer.empty); + export function run(): Promise { - return Effect.runPromise(program); + return librarianRuntime.runPromise(program); +} + +export function runMain(): void { + NodeRuntime.runMain(program); } diff --git a/ts/scripts/run-flow-manager.ts b/ts/scripts/run-flow-manager.ts index 31a20350..79315b28 100644 --- a/ts/scripts/run-flow-manager.ts +++ b/ts/scripts/run-flow-manager.ts @@ -6,9 +6,6 @@ * Env: * NATS_URL (default: nats://localhost:4222) */ -import { run } from "../packages/flow/src/flow-manager/service.js"; +import { runMain } from "../packages/flow/src/flow-manager/service.js"; -run().catch((err) => { - console.error("Flow manager failed:", err); - process.exit(1); -}); +runMain(); diff --git a/ts/scripts/run-librarian.ts b/ts/scripts/run-librarian.ts index 82c5f95e..e008e446 100644 --- a/ts/scripts/run-librarian.ts +++ b/ts/scripts/run-librarian.ts @@ -7,9 +7,6 @@ * NATS_URL (default: nats://localhost:4222) * LIBRARIAN_DATA_DIR (optional, e.g., ./data/librarian) */ -import { run } from "../packages/flow/src/librarian/service.js"; +import { runMain } from "../packages/flow/src/librarian/service.js"; -run().catch((err) => { - console.error("Librarian service failed:", err); - process.exit(1); -}); +runMain();