effect-v3-to-v4
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEffect v3 to v4 Migration
Effect v3 迁移至 v4
Drive an Effect v3 → v4 migration from the generated migration reference that ships in the Effect repo. Every rename, removal, and signature change is answered by upstream data — do not guess replacements.
基于Effect仓库中提供的迁移参考文档,完成Effect v3 → v4的迁移工作。所有重命名、移除和签名变更都以上游数据为准——请勿自行猜测替代方案。
Workflow
工作流程
Work through these steps in order; each one is detailed in the section named.
- Set up and validate the local checkouts — two shallow clones; verify any pre-existing before trusting it. See Setup: Local Checkouts.
.repos/effect - Read and
MIGRATION.mdfor the background and guide index. See Reading Order.ls .repos/effect/migration/ - Migrate — remove consolidated packages, align every remaining Effect package on one v4 version. Do this before type-checking, or the first run drowns in unresolved-import noise from packages that no longer exist. See Repo-Level Changes.
package.json - Run the project's type-check (e.g. ) to get the initial error inventory.
tsc --noEmit - Iterate until the type-check is clean. For each error, resolve the API through the lookup discipline — search for the symbol, escalate per Reading Order — then fix the call site, delegating per-file fixes to sub-agents per Delegating to Sub-Agents. Never silence an error instead of resolving it; see Hard Prohibitions.
migration/v3-to-v4.md - Finish — type-check clean; run tests and report their outcome honestly (not a gate); write the final summary. See Done Condition.
按顺序完成以下步骤,每个步骤的详细说明见对应章节:
- 设置并验证本地检出 —— 创建两个浅克隆;在使用之前,验证已存在的是否可用。详见设置:本地检出。
.repos/effect - 阅读和查看
MIGRATION.md以获取背景信息和指南索引。详见阅读顺序。ls .repos/effect/migration/ - 迁移—— 移除合并后的包,将所有剩余的Effect包统一对齐到同一个v4版本。在类型检查之前完成此操作,否则首次运行会因已不存在的包产生大量未解析导入的报错。详见仓库级变更。
package.json - 运行项目的类型检查(例如)以获取初始错误清单。
tsc --noEmit - 迭代直到类型检查通过。对于每个错误,通过查找规则解析API——在中搜索符号,按照阅读顺序逐步排查——然后修复调用位置,根据委托给子代理将每个文件的修复工作委托给子代理。切勿通过忽略错误来解决问题;详见严格禁令。
migration/v3-to-v4.md - 完成 —— 类型检查通过;运行测试并如实报告结果(不作为通关条件);撰写最终总结。详见完成条件。
Setup: Local Checkouts
设置:本地检出
The migration is driven from two shallow, single-branch clones of the canonical Effect repo:
sh
git clone --depth 1 --single-branch https://github.com/Effect-TS/effect .repos/effect
git clone --depth 1 --single-branch --branch v3 https://github.com/Effect-TS/effect .repos/effect-v3- — v4 (
.repos/effect). Containsmain, theMIGRATION.mdguides, and the v4 source.migration/ - — v3 (
.repos/effect-v3branch). Escalation-only reference for old semantics.v3
Each clone is independently re-runnable and separately deletable. Do not use to share one clone between branches.
git worktree迁移工作基于两个规范Effect仓库的浅克隆(单分支):
sh
git clone --depth 1 --single-branch https://github.com/Effect-TS/effect .repos/effect
git clone --depth 1 --single-branch --branch v3 https://github.com/Effect-TS/effect .repos/effect-v3- —— v4版本(
.repos/effect分支)。包含main、MIGRATION.md指南和v4源码。migration/ - —— v3版本(
.repos/effect-v3分支)。仅用于查阅旧版语义的参考。v3
每个克隆均可独立重新运行和删除。请勿使用在分支之间共享同一个克隆。
git worktreeValidate an existing checkout before trusting it
使用前验证现有检出
./.repos/effectEffect-TS/effect-smolmigration/v3-to-v4.mdsh
git -C .repos/effect remote get-url origin # must be the canonical Effect-TS/effect repo
node -p "require('./.repos/effect/packages/effect/package.json').version" # must be 4.xIf the origin points at , or the version is not , delete the directory and re-clone as above.
effect-smol4.x.repos/effectEffect-TS/effect-smolmigration/v3-to-v4.mdsh
git -C .repos/effect remote get-url origin # 必须指向规范的Effect-TS/effect仓库
node -p "require('./.repos/effect/packages/effect/package.json').version" # 版本必须为4.x如果源指向,或者版本不是,请删除该目录并按照上述步骤重新克隆。
effect-smol4.xReading Order
阅读顺序
- Front-load once (
MIGRATION.md)..repos/effect/MIGRATION.md - — the first stop for every API. The generated reference covers every removed or changed API. Search it (see below); never read it whole.
migration/v3-to-v4.md - A per-topic guide () when the mapping implies a rewrite rather than a rename — e.g.
.repos/effect/migration/*.md→Context.Tagis a structural change, not a symbol swap. Reach these on demand from theContext.Serviceindex, not front-loaded.MIGRATION.md - v4 source (, including
.repos/effect/packages/*/src/) to confirm a replacement's real signature before writing code against it.unstable/ - v3 source () as escalation only — for when unsure about the old v3 semantics.
.repos/effect-v3
- 先完整阅读一次(
MIGRATION.md)。.repos/effect/MIGRATION.md - —— 所有API查询的第一站。生成的参考文档涵盖了所有已移除或变更的API。搜索该文档(见下文);切勿通篇阅读。
migration/v3-to-v4.md - 主题指南()—— 当映射涉及重写而非重命名时使用,例如
.repos/effect/migration/*.md→Context.Tag是结构性变更,而非符号替换。从Context.Service索引按需访问这些指南,无需提前阅读。MIGRATION.md - v4源码(,包括
.repos/effect/packages/*/src/)—— 在编写代码前确认替代方案的真实签名。unstable/ - v3源码()—— 仅在不确定旧版v3语义时作为升级参考。
.repos/effect-v3
Never Read the Reference Doc Whole
切勿通篇阅读参考文档
This is the single most important rule in this skill. is ~16,000 lines / ~350k tokens. Reading it in one pass blows the context window and takes the migration with it.
migration/v3-to-v4.mdAlways search it and read only matched lines plus surrounding context. The file has four sections — Import Map, No Counterpart Imports, Removed Modules, and API Reference (one heading per module). Entries are grep-able one-liners of the form , and removals are explicit entries with a stated alternative.
### `<v3 module path>`- `Old.symbol` -> `New.symbol`: <rationale>-> `none`Concrete recipes:
sh
undefined这是本技能中最重要的规则。约有16000行 / 350k个标记。一次性通篇阅读会超出上下文窗口,导致迁移工作受阻。
migration/v3-to-v4.md始终搜索该文档,仅阅读匹配行及其上下文。该文档分为四个部分——导入映射、无对应导入、已移除模块和API参考(每个模块对应一个标题)。条目为可通过grep查找的单行内容,格式为,移除的条目会明确标记为并说明替代方案。
### `<v3 module path>`- `Old.symbol` -> `New.symbol`: <rationale>-> `none`具体操作示例:
sh
undefinedLook up a specific v3 symbol
查找特定的v3符号
rg -n 'AnthropicTokenizer.layer' .repos/effect/migration/v3-to-v4.md
rg -n 'AnthropicTokenizer.layer' .repos/effect/migration/v3-to-v4.md
Read a whole module's section via its heading
通过标题查看整个模块的章节
rg -n -A 40 '^### ' .repos/effect/migration/v3-to-v4.md
@effect/platform/FileSystemrg -n -A 40 '^### ' .repos/effect/migration/v3-to-v4.md
@effect/platform/FileSystemResolve a v3 import path in the Import Map
在导入映射中查找v3导入路径
rg -n '^@effect/platform/FileSystem ' .repos/effect/migration/v3-to-v4.md
rg -n '^@effect/platform/FileSystem ' .repos/effect/migration/v3-to-v4.md
List every module section for a package
列出某个包的所有模块章节
rg -n '^### `@effect/cluster/' .repos/effect/migration/v3-to-v4.md
Look up APIs as you encounter them, one search at a time. A miss in the Import Map is not a dead end — check the **Removed Modules** and **No Counterpart Imports** sections before concluding anything.rg -n '^### `@effect/cluster/' .repos/effect/migration/v3-to-v4.md
遇到API时逐个查找,每次搜索一个。如果在导入映射中未找到,不要就此放弃——在得出结论前先检查**已移除模块**和**无对应导入**部分。Repo-Level Changes
仓库级变更
Faithful per-API lookup alone still yields a broken . Handle these once, up front:
package.json- Package consolidation. ,
@effect/platform,@effect/rpc, and others merged into the core@effect/clusterpackage — remove them fromeffectand rewrite their imports per the Import Map. Packages that remain separate (package.json,@effect/platform-*,@effect/sql-*,@effect/ai-*,@effect/opentelemetry, …) stay as dependencies.@effect/vitest - Version alignment. All Effect ecosystem packages share one version number in v4. Every remaining /
effectdependency must be on the same matching version.@effect/* - Unstable modules. Some functionality only exists under import paths (e.g.
effect/unstable/*,effect/unstable/http). These are correct v4 imports — use them where the reference maps to them; they may receive breaking changes in minor releases.effect/unstable/rpc
仅依赖API查找仍会导致出现问题。请先一次性处理以下变更:
package.json- 包合并。、
@effect/platform、@effect/rpc等已合并到核心@effect/cluster包中——从effect中移除它们,并根据导入映射重写其导入语句。仍保持独立的包(package.json、@effect/platform-*、@effect/sql-*、@effect/ai-*、@effect/opentelemetry等)继续作为依赖保留。@effect/vitest - 版本对齐。v4版本中所有Effect生态系统包共享同一个版本号。所有剩余的/
effect依赖必须使用相同的匹配版本。@effect/* - 不稳定模块。部分功能仅存在于导入路径下(例如
effect/unstable/*、effect/unstable/http)。这些是正确的v4导入语句——当参考文档指向这些路径时使用它们;它们可能在小版本更新中发生破坏性变更。effect/unstable/rpc
Delegating to Sub-Agents
委托给子代理
Per-file migration work is context-hungry; do it in sub-agents so the main session's context survives the whole migration.
- Spawn one sub-agent per file (or per module), giving it the specific v3 symbols to resolve in that file.
- The sub-agent returns the edit and the mappings it used; the main session keeps the error inventory and the running summary.
- Sub-agents inherit the same lookup discipline (Reading Order, the recipes) and Hard Prohibitions.
rg - The reference doc is never read whole in a sub-agent either — a blown sub-agent context still costs the migration that file.
每个文件的迁移工作需要大量上下文;请使用子代理完成,以便主会话的上下文在整个迁移过程中得以保留。
- 为每个文件(或模块)生成一个子代理,向其提供该文件中需要解析的特定v3符号。
- 子代理返回编辑内容和使用的映射关系;主会话保留错误清单和运行摘要。
- 子代理继承相同的查找规则(阅读顺序、操作示例)和严格禁令。
rg - 子代理同样不得通篇阅读参考文档——子代理上下文溢出仍会导致该文件的迁移工作失败。
Hard Prohibitions
严格禁令
- Never reintroduce a v3-shaped compatibility layer. Writing a that re-exports old names makes type errors vanish and permanently freezes the codebase between versions. Migrate call sites to the v4 API.
v3-compat.ts - No , no
anycasts to silence a post-migration type error. Such an error is usually evidence the replacement has a different shape; casting deletes that information. Go back to the reference or the v4 source.as - No invented APIs. Every replacement must trace to the reference doc, a topic guide, or the v4 source.
- 切勿重新引入v3兼容层。编写重新导出旧名称会使类型错误消失,并永久将代码库冻结在两个版本之间。将调用位置迁移到v4 API。
v3-compat.ts - 禁止使用或
any类型断言来掩盖迁移后的类型错误。此类错误通常表明替代方案的结构不同;类型断言会删除该信息。请返回参考文档或v4源码查找解决方案。as - 禁止自创API。所有替代方案必须可追溯到参考文档、主题指南或v4源码。
Done Condition
完成条件
The project type-checks against v4. A v4 migration is fundamentally a type-level exercise; unresolved imports and changed signatures surface there and nowhere else. Run the project's type-check (e.g. ) until clean.
tsc --noEmitRunning the test suite is recommended, and its outcome must be reported honestly — but it is not a gate. A repo mid-migration often has tests that cannot run for unrelated reasons; do not weaken tests to make them pass.
The final summary must state: the type-check result, the test result (or why tests were not run), every constructed replacement, and any gaps that were reported rather than bridged.
项目针对v4版本类型检查通过。v4迁移本质上是类型层面的操作;未解析的导入和变更的签名会在此处显现,不会在其他地方出现。运行项目的类型检查(例如)直到无错误。
tsc --noEmit建议运行测试套件,并且必须如实报告测试结果——但这不是通关条件。迁移中的仓库通常会因无关原因导致测试无法运行;请勿修改测试使其通过。
最终总结必须说明:类型检查结果、测试结果(或无法运行测试的原因)、所有构建的替代方案,以及已报告但未解决的问题。