effect
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEffect
Effect
Use this skill when work touches Effect v4 beta usage, service/layer architecture, runtime entrypoints, Schema v4, platform modules, testing, or migrations from Effect v3.
当你的工作涉及Effect v4 beta使用、服务/层架构、运行时入口点、Schema v4、平台模块、测试或从Effect v3迁移时,可使用此技能。
Workflow
工作流程
- Inspect the local Effect surface before changing code:
- Package versions for ,
effect, TypeScript, runtime platform packages, test libraries, and adapters.@effect/* - Imports: root , direct modules like
effect,effect/Effect,effect/Schema, platform packages, or old v3 packages.effect/unstable/* - Runtime boundary: CLI, HTTP handler, worker, server, browser, test, library, or framework-managed entrypoint.
- Dependency shape: services, layers, config providers, platform layers, managed runtimes, and scope ownership.
- Package versions for
- Clone into
Effect-TS/effect-smol(if missing) and always browse that checkout when referencing Effect v4 code — APIs, migration guides, package READMEs, and tests. Do not rely on memory or stale docs alone. Details: source-map.md..temp/effect-smol - Refresh current docs whenever the task asks for latest behavior or the local beta version is different. Start from source-map.md.
- For install/version, core Effect usage, generator style, typed errors, async interop, config, and runtime boundaries, use setup-core.md.
- For services, , references, layers, memoization, scopes, and
Context.Service, use services-layers-runtime.md.ManagedRuntime - For Schema v4 shapes, validation, classes, tagged errors, transformations, codecs, serialization, and JSON Schema generation, use schema-v4.md.
- For (runners, TestClock, layers, flaky/live, good/bad patterns), use vitest-testing.md.
@effect/vitest - For v3 to v4 migration, unstable modules, and HTTP/platform packages, use migration-platform-testing.md.
- Implement in the existing project style:
- Match the installed beta version and local import style.
- Prefer explicit service and layer composition over hidden globals.
- Keep framework/process edges thin; push business logic into Effects, services, and layers.
- Treat APIs as beta-plus-unstable. Check installed declarations before using or recommending them.
effect/unstable/*
- 在修改代码前检查本地Effect的相关情况:
- 包版本:、
effect、TypeScript、运行时平台包、测试库和适配器的版本。@effect/* - 导入情况:根目录、直接模块如
effect、effect/Effect、effect/Schema、平台包或旧版v3包。effect/unstable/* - 运行时边界:CLI、HTTP处理器、工作线程、服务器、浏览器、测试、库或框架管理的入口点。
- 依赖形态:服务、层、配置提供器、平台层、托管运行时和作用域归属。
- 包版本:
- 将克隆到
Effect-TS/effect-smol目录(若不存在),并且在查阅Effect v4代码(包括API、迁移指南、包README和测试)时,务必查看该克隆版本。不要仅依赖记忆或过时文档。详情:source-map.md。.temp/effect-smol - 当任务要求最新行为或本地beta版本不同时,刷新最新文档。从source-map.md开始。
- 关于安装/版本、核心Effect使用、生成器风格、类型化错误、异步互操作、配置和运行时边界,请参考setup-core.md。
- 关于服务、、引用、层、 memoization、作用域和
Context.Service,请参考services-layers-runtime.md。ManagedRuntime - 关于Schema v4的形态、验证、类、标记错误、转换、编解码器、序列化和JSON Schema生成,请参考schema-v4.md。
- 关于(运行器、TestClock、层、不稳定/实时测试、优劣模式),请参考vitest-testing.md。
@effect/vitest - 关于v3到v4的迁移、不稳定模块和HTTP/平台包,请参考migration-platform-testing.md。
- 按照现有项目风格实现:
- 匹配已安装的beta版本和本地导入风格。
- 优先选择显式的服务和层组合,而非隐藏的全局变量。
- 保持框架/进程边缘简洁;将业务逻辑推入Effects、服务和层中。
- 将API视为beta加不稳定版本。在使用或推荐前检查已安装的声明文件。
effect/unstable/*
Effect Judgment
Effect使用判断
- Effect v4 is beta. Be honest about API drift and verify local declarations before making broad changes.
- Use for v4 services. Do not introduce v3
Context.Service,Context.Tag,Context.GenericTag, orEffect.Tagpatterns in v4 code.Effect.Service - Prefer inside
yield* Servicefor service access. UseEffect.genandService.useonly for small, local one-liners.useSync - Define layers explicitly with ,
Layer.succeed, orLayer.effect; wire dependencies withLayer.effectDiscardandLayer.provide.Layer.provideMerge - Compose and provide layers once when possible. Use or
Layer.freshonly for intentional isolation.Effect.provide(..., { local: true }) - Use for repeated JS entrypoint runs against shared services, and dispose it when done.
ManagedRuntime.make(layer) - Use ,
Effect.runPromise,runPromiseExit, or theirrunForkvariants only at application edges.With - Inside ,
Effect.genworks with Yieldable values. Outside generators, convert non-Effect Yieldables explicitly or use module functions such asyield*,Ref.get, andDeferred.await.Fiber.join - Prefer typed failures and tagged error classes over throwing. Use defects only for unrecoverable programmer errors.
- Keep Schema v4 encode/decode direction visible at boundaries; do not assume decoded and encoded input are the same.
Type - For tests: install v4 (→
@effect/vitest@beta; never bare/4.0.0-beta.x→latestv3). Prefer0.30.x(already scoped + TestClock/TestConsole). Importit.effectfromTestClock. Do not useeffect/testing/it.scopedfor Effect Scope. Treatit.scopedLiveas shared across tests unless youlayer()per test.Effect.provide
- Effect v4处于beta阶段。对于API变化要诚实告知,在进行大范围修改前先验证本地声明文件。
- v4服务使用。不要在v4代码中引入v3的
Context.Service、Context.Tag、Context.GenericTag或Effect.Tag模式。Effect.Service - 在内部优先使用
Effect.gen来访问服务。仅在小型本地单行代码中使用yield* Service和Service.use。useSync - 使用、
Layer.succeed或Layer.effect显式定义层;使用Layer.effectDiscard和Layer.provide连接依赖。Layer.provideMerge - 尽可能一次性组合并提供层。仅在需要刻意隔离时使用或
Layer.fresh。Effect.provide(..., { local: true }) - 针对共享服务的重复JS入口点运行,使用,完成后销毁它。
ManagedRuntime.make(layer) - 仅在应用边缘使用、
Effect.runPromise、runPromiseExit或它们的runFork变体。With - 在内部,
Effect.gen可处理Yieldable值。在生成器外部,显式转换非Effect的Yieldable值,或使用模块函数如yield*、Ref.get和Deferred.await。Fiber.join - 优先使用类型化失败和标记错误类,而非抛出异常。仅将缺陷用于不可恢复的程序员错误。
- 在边界处保持Schema v4的编码/解码方向可见;不要假设解码后的与编码输入相同。
Type - 测试相关:安装v4版本的(即
@effect/vitest@beta;绝不要使用裸版本/4.0.0-beta.x对应的latestv3版本)。优先使用0.30.x(已包含作用域 + TestClock/TestConsole)。从it.effect导入effect/testing。不要将TestClock/it.scoped用于Effect Scope。除非你在每个测试中使用it.scopedLive,否则将Effect.provide视为跨测试共享。layer()
Verification
验证
Prefer the repo's existing checks. For meaningful Effect v4 work, include the relevant subset:
- Typecheck for requirements, service availability, layer composition, Schema encoded/type sides, and beta API names.
Effect<A, E, R> - Focused tests with (
@effect/vitest@beta, TestClock, scoped resources, typed Exit/Result failures). Use per-testit.effectwhen isolation matters; treat sharedEffect.provideas suite-scoped.layer() - Runtime smoke at JS/framework edges where Effects are run or managed runtimes are disposed.
- Schema decode/encode tests for valid input, invalid input, defaults, excess properties, transformations, classes, tagged errors, and generated JSON Schema.
- Migration scans for v3-only APIs, old package imports, old catch/fork names, old runtime patterns, ,
FiberRef, and removed Schema APIs.Either
优先使用仓库现有的检查机制。对于重要的Effect v4工作,需包含以下相关子集:
- 类型检查:验证要求、服务可用性、层组合、Schema编码/类型侧以及beta API名称。
Effect<A, E, R> - 聚焦测试:使用(
@effect/vitest@beta、TestClock、作用域资源、类型化Exit/Result失败)。当需要隔离时,在每个测试中使用it.effect;将共享的Effect.provide视为套件作用域。layer() - 运行时冒烟测试:在JS/框架边缘处测试Effects的运行或托管运行时的销毁。
- Schema编码/解码测试:针对有效输入、无效输入、默认值、多余属性、转换、类、标记错误和生成的JSON Schema进行测试。
- 迁移扫描:检查仅v3可用的API、旧包导入、旧catch/fork名称、旧运行时模式、、
FiberRef以及已移除的Schema API。Either