From 66e1009671d89d4bb70168873f94f05f7308350c Mon Sep 17 00:00:00 2001 From: elpresidank Date: Tue, 2 Jun 2026 09:45:29 -0500 Subject: [PATCH] Use Match for knowledge core operations --- ts/EFFECT_NATIVE_REWRITE_AUDIT.md | 20 +++++++++++ ts/packages/flow/src/cores/service.ts | 49 ++++++++++++--------------- 2 files changed, 42 insertions(+), 27 deletions(-) diff --git a/ts/EFFECT_NATIVE_REWRITE_AUDIT.md b/ts/EFFECT_NATIVE_REWRITE_AUDIT.md index 9cc214d6..14c3a60b 100644 --- a/ts/EFFECT_NATIVE_REWRITE_AUDIT.md +++ b/ts/EFFECT_NATIVE_REWRITE_AUDIT.md @@ -409,6 +409,23 @@ Notes: - `cd ts && bun run build` - `cd ts && bun run test` +### 2026-06-02: KnowledgeCore Operation Match Slice + +- Status: migrated and package-verified. +- Completed: + - `ts/packages/flow/src/cores/service.ts` now dispatches + `KnowledgeOperation` with `effect/Match` instead of a native `switch`. + - The dispatcher is a named `Effect.fn` and uses `Match.exhaustive` against + the schema-derived `KnowledgeOperation` union, so newly modeled operations + should surface as type/check failures until handled. +- Verification: + - `bun run --cwd ts/packages/flow test -- src/__tests__/knowledge-core-service.test.ts` + - `cd ts && bun run check:tsgo` + - `cd ts && bun run build` + - `cd ts && bun run test` + - `cd ts && bun run lint` + - `git diff --check` + ### 2026-06-02: Flow Manager And Librarian Runtime Normalization - Status: migrated and root-verified. @@ -1775,6 +1792,9 @@ Notes: - FlowManager `() => Effect.gen(...)` factories are normalized to `Effect.fn` / `Effect.fnUntraced`. Sibling service factories still need a focused scan before treating them as valid migration targets. + - KnowledgeCore operation dispatch now uses `effect/Match` with + `Match.exhaustive`; remaining service operation switches are in config and + librarian surfaces. - Long-lived `Map` / `Set` state in ref-backed services can move toward Effect collections later; local pure traversal maps/sets remain no-ops. diff --git a/ts/packages/flow/src/cores/service.ts b/ts/packages/flow/src/cores/service.ts index 7b4fbcf7..37c656e5 100644 --- a/ts/packages/flow/src/cores/service.ts +++ b/ts/packages/flow/src/cores/service.ts @@ -25,7 +25,7 @@ import { type Message, type ProcessorConfig, } from "@trustgraph/base"; -import {Duration, Effect, Layer, ManagedRuntime, SynchronizedRef} from "effect"; +import {Duration, Effect, Layer, ManagedRuntime, Match, SynchronizedRef} from "effect"; import * as O from "effect/Option"; import * as S from "effect/Schema"; import {ensureDirectory, joinPath, readTextFile, writeTextFile} from "../runtime/effect-files.js"; @@ -654,34 +654,29 @@ export function makeKnowledgeCoreService(config: KnowledgeCoreServiceConfig): Kn }); const baseStop = base.stop; - const handleOperationEffect = (request: KnowledgeRequest, requestId: string) => { + const handleOperationEffect = Effect.fn("KnowledgeCoreService.handleOperation")(function* ( + request: KnowledgeRequest, + requestId: string, + ) { const operation: KnowledgeOperation = request.operation; - switch (operation) { - case "list-kg-cores": - return listKgCoresEffect(state, request, requestId); - case "get-kg-core": - return getKgCoreEffect(state, request, requestId); - case "delete-kg-core": - return deleteKgCoreEffect(state, persistPath, request, requestId); - case "put-kg-core": - return putKgCoreEffect(state, persistPath, request, requestId); - case "load-kg-core": - return getService.pipe(Effect.flatMap((current) => loadKgCoreEffect(state, current, request, requestId))); - case "unload-kg-core": - return sendResponse(state, {}, requestId); - case "list-de-cores": - return listDeCoresEffect(state, request, requestId); - case "get-de-core": - return getDeCoreEffect(state, request, requestId); - case "delete-de-core": - return deleteDeCoreEffect(state, persistPath, request, requestId); - case "put-de-core": - return putDeCoreEffect(state, persistPath, request, requestId); - case "load-de-core": - return loadDeCoreEffect(state, request, requestId); - } - }; + return yield* Match.value(operation).pipe( + Match.when("list-kg-cores", () => listKgCoresEffect(state, request, requestId)), + Match.when("get-kg-core", () => getKgCoreEffect(state, request, requestId)), + Match.when("delete-kg-core", () => deleteKgCoreEffect(state, persistPath, request, requestId)), + Match.when("put-kg-core", () => putKgCoreEffect(state, persistPath, request, requestId)), + Match.when("load-kg-core", () => + getService.pipe(Effect.flatMap((current) => loadKgCoreEffect(state, current, request, requestId))) + ), + Match.when("unload-kg-core", () => sendResponse(state, {}, requestId)), + Match.when("list-de-cores", () => listDeCoresEffect(state, request, requestId)), + Match.when("get-de-core", () => getDeCoreEffect(state, request, requestId)), + Match.when("delete-de-core", () => deleteDeCoreEffect(state, persistPath, request, requestId)), + Match.when("put-de-core", () => putDeCoreEffect(state, persistPath, request, requestId)), + Match.when("load-de-core", () => loadDeCoreEffect(state, request, requestId)), + Match.exhaustive, + ); + }); const handleMessageEffect = Effect.fn("KnowledgeCoreService.handleMessage")(function* (msg: Message) { const request = yield* S.decodeUnknownEffect(KnowledgeRequestSchema)(msg.value()).pipe(