opencode-ts

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Opencode TypeScript

Opencode TypeScript

Code like the opencode core team. This skill contains real code extracted from the repo — complete implementations, not abstract rules. Follow the workflow below based on your task.

像opencode核心团队一样编写代码。本技能包含从代码仓库中提取的真实代码——完整的实现方案,而非抽象规则。根据你的任务遵循以下工作流程。

Implement (new code)

实现(新增代码)

Follow these phases in order:
按顺序遵循以下阶段:

1. Orient — where does this go?

1. 定位——代码应该放在哪里?

Load architecture.md. Find:
  • Which module owns this behavior
  • What the dependency direction allows
  • What file naming convention to follow
  • Whether this is a new module or an addition to an existing one
查看architecture.md,找到:
  • 哪个模块负责该行为
  • 依赖方向允许的内容
  • 需要遵循的文件命名规范
  • 这是新增模块还是在现有模块上扩展

2. Gather — what already exists?

2. 梳理——已有哪些可用内容?

Load helpers-deep-dive.md. Before writing ANY utility:
  • Check if it already exists in
    util/
    ,
    effect/
    ,
    bus/
    ,
    sync/
  • Check the usage matrix to see how other modules use it
  • If it exists, use it. If it doesn't, inline first — extract only when awkwardness repeats.
For quick lookups: primitives.md (shorter, import paths + signatures only)
查看helpers-deep-dive.md。在编写任何工具函数前:
  • 检查它是否已存在于
    util/
    effect/
    bus/
    sync/
    目录中
  • 查看使用矩阵,了解其他模块如何使用它
  • 如果已存在,直接使用;如果不存在,先内联实现——仅当重复出现不便时再提取为独立工具函数
快速查询可参考:primitives.md(内容更简洁,仅包含导入路径和签名)

3. Build — write the code

3. 编写——实现代码

Load the reference that matches what you're building:
Building...Load this
Service module (namespace + Effect service + schemas + events)service-module.md
Tool or modifying tool behaviortool-module.md
Database tables, schemas, events, error typesschemas-and-state.md
Server routes, config, plugins, project lifecycleserver-and-routes.md
Teststest-writing.md
查看与你正在构建的内容匹配的参考文档:
构建内容参考文档
服务模块(命名空间 + Effect服务 + 模式 + 事件)service-module.md
工具或修改工具行为tool-module.md
数据库表、模式、事件、错误类型schemas-and-state.md
服务器路由、配置、插件、项目生命周期server-and-routes.md
测试test-writing.md

4. CHECK GATE — code MUST pass all of these before proceeding

4. 检查关卡——代码必须全部通过以下检查才能继续

Load style-dna.md. If ANY of the following fail, fix the code before proceeding to Review:
  • Single-word variable names where clear
  • No
    try
    /
    catch
    , no
    else
    , no
    any
    , no unnecessary destructuring
  • const
    + ternary over
    let
    + mutation
  • snake_case Drizzle fields,
    .meta({ref})
    on boundary schemas
  • Effect is used for services, not plain async classes
  • No patterns from Section 7 ("Things That Compile But Get Rejected") present in the diff
DO NOT proceed if any check fails. Go back to phase 3 and fix.
查看style-dna.md如果以下任何一项不满足,在进入评审阶段前修复代码:
  • 清晰情况下使用单字变量名
  • 不使用
    try
    /
    catch
    else
    any
    ,避免不必要的解构
  • 使用
    const
    + 三元表达式替代
    let
    + 变量突变
  • Drizzle字段使用snake_case,边界模式添加
    .meta({ref})
  • 服务使用Effect实现,不使用普通异步类
  • 代码差异中不包含第7节(“可编译但会被拒绝的写法”)中的任何模式
如果有任何检查不通过,请勿继续。回到第3阶段修复代码。

5. REVIEW GATE — REJECT the diff if any of these apply

5. 评审关卡——如果存在以下任何情况,拒绝代码差异

Load review-voice.md. The diff MUST NOT contain any of the following. If it does, fix before submitting:
  • Changes to files outside the scope of the task
  • as any
    or
    as unknown as
    casts
  • Custom utilities that duplicate community primitives or
    @/util/*
    helpers
  • Provider-specific code that should live in models.dev
  • Code removal without a clear reason documented in the commit
  • Unexplained variable renames or structural changes
  • Abstraction the core team would ask to remove (check refactoring-patterns.md)

查看review-voice.md代码差异中绝对不能包含以下内容。如果存在,提交前修复:
  • 修改了任务范围外的文件
  • 使用
    as any
    as unknown as
    类型断言
  • 自定义工具函数重复了社区原生工具或
    @/util/*
    中的助手函数
  • 应在models.dev中实现的供应商特定代码
  • 代码删除但未在提交中记录明确原因
  • 无解释的变量重命名或结构变更
  • 核心团队会要求移除的抽象(查看refactoring-patterns.md)

Refactor (changing existing code)

重构(修改现有代码)

1. Orient — what touches what?

1. 定位——代码影响范围

Load architecture.md. Map the blast radius before changing anything.
查看architecture.md。在修改任何内容前,梳理代码的影响范围。

2. Study — which pattern applies here?

2. 分析——适用哪种模式?

Load refactoring-patterns.md. Start with the Decision Matrix at the top — match the code smell you see to the correct pattern. Then read the specific pattern section for real before/after diffs:
  • Simplification patterns (removing unnecessary abstraction)
  • Consolidation patterns (Bun → Node migration)
  • Extraction patterns (pulling reusable utilities)
  • Migration patterns (moving to Effect services)
  • Deletion patterns (removing dead code)
  • Stabilization patterns (fixing ordering/race conditions)
  • Variant elimination (removing special cases)
查看refactoring-patterns.md从顶部的决策矩阵开始——将你发现的代码异味匹配到正确的模式。然后查看具体模式章节中的真实前后代码差异:
  • 简化模式(移除不必要的抽象)
  • 合并模式(Bun → Node迁移)
  • 提取模式(抽取可复用工具函数)
  • 迁移模式(转向Effect服务)
  • 删除模式(移除死代码)
  • 稳定模式(修复顺序/竞态条件)
  • 变体消除(移除特殊情况)

3. Gather — can an existing utility replace this code?

3. 梳理——是否可以用现有工具函数替代这段代码?

Load helpers-deep-dive.md. The best refactor often replaces 20 lines with one utility call.
查看helpers-deep-dive.md。最佳的重构往往是用一行工具函数调用替代20行代码。

4. Check + Review

4. 检查 + 评审

Same as implement phases 4-5: style-dna.md then review-voice.md.

与实现阶段的第4-5步相同:先查看style-dna.md,再查看review-voice.md

Key decisions (always apply)

核心决策(始终遵循)

  • Effect is mandatory — all services use
    ServiceMap.Service
    /
    Layer
    /
    makeRuntime
    . No plain async classes.
  • Namespace ownership — one
    export namespace X {}
    per feature, one file until real split pressure.
  • Zod for boundaries, Effect Schema for internals — Zod +
    z.infer
    for DTOs/tool params.
    Schema.TaggedErrorClass
    for Effect errors.
    Newtype
    for branded IDs.
  • Event-sourced writes — mutations go through
    SyncEvent.run
    → projectors → SQLite. Direct DB writes only for non-event-sourced features.
  • No mocks in tests — use
    tmpdir
    +
    Instance.provide
    + real services. Mocks only for external SDKs.
  • Single-word variables
    state
    ,
    pending
    ,
    info
    ,
    row
    ,
    cfg
    ,
    tx
    . Multi-word only when genuinely ambiguous.

  • 必须使用Effect——所有服务使用
    ServiceMap.Service
    /
    Layer
    /
    makeRuntime
    。禁止使用普通异步类。
  • 命名空间归属——每个功能对应一个
    export namespace X {}
    ,在出现明确的拆分需求前,一个功能对应一个文件。
  • 边界用Zod,内部用Effect Schema——DTO/工具参数使用Zod +
    z.infer
    。Effect错误使用
    Schema.TaggedErrorClass
    。品牌化ID使用
    Newtype
  • 事件溯源写入——变更操作通过
    SyncEvent.run
    → 投影器 → SQLite执行。仅非事件溯源功能允许直接写入数据库。
  • 测试中不使用Mock——使用
    tmpdir
    +
    Instance.provide
    + 真实服务。仅外部SDK允许使用Mock。
  • 单字变量名——使用
    state
    pending
    info
    row
    cfg
    tx
    等。仅当确实存在歧义时使用多字变量名。

Reference index

参考索引

FileSizeWhat it contains
style-dna.md18KMandatory style rules, naming, control flow, 14 review traps
primitives.md22KQuick-lookup: every utility with import path + signature
helpers-deep-dive.md~40KFull deep-dive: every utility, every usage site, when NOT to use
architecture.md~30KModule map, dependency graph, data flow, file conventions
service-module.md27KComplete Question + Permission implementations
tool-module.md28KFull tool implementations, registry, prompt loop
test-writing.md42K5 complete test files with all fixture patterns
schemas-and-state.md36KSQL tables, Zod/Effect schemas, SyncEvent flow, errors
server-and-routes.md32KRoutes, config, plugins, project lifecycle
review-voice.md~25KReal PR review comments from Dax + Aiden
refactoring-patterns.md~25KReal before/after diffs from cleanup commits
文件大小包含内容
style-dna.md18K强制风格规则、命名规范、控制流、14个评审陷阱
primitives.md22K快速查询:所有工具函数的导入路径 + 签名
helpers-deep-dive.md~40K深度解析:所有工具函数、使用场景、不适用场景
architecture.md~30K模块映射、依赖图、数据流、文件规范
service-module.md27K完整的Question + Permission实现
tool-module.md28K完整的工具实现、注册、提示循环
test-writing.md42K5个完整的测试文件,包含所有 fixture 模式
schemas-and-state.md36KSQL表、Zod/Effect模式、SyncEvent流程、错误定义
server-and-routes.md32K路由、配置、插件、项目生命周期
review-voice.md~25K来自Dax + Aiden的真实PR评审评论
refactoring-patterns.md~25K来自清理提交的真实前后代码差异