opencode-ts
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpencode 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 behavior | tool-module.md |
| Database tables, schemas, events, error types | schemas-and-state.md |
| Server routes, config, plugins, project lifecycle | server-and-routes.md |
| Tests | test-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, nocatch, noelse, no unnecessary destructuringany - + ternary over
const+ mutationlet - snake_case Drizzle fields, on boundary schemas
.meta({ref}) - 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
- or
as anycastsas unknown as - Custom utilities that duplicate community primitives or helpers
@/util/* - 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. No plain async classes.makeRuntime - Namespace ownership — one per feature, one file until real split pressure.
export namespace X {} - Zod for boundaries, Effect Schema for internals — Zod + for DTOs/tool params.
z.inferfor Effect errors.Schema.TaggedErrorClassfor branded IDs.Newtype - Event-sourced writes — mutations go through → projectors → SQLite. Direct DB writes only for non-event-sourced features.
SyncEvent.run - No mocks in tests — use +
tmpdir+ real services. Mocks only for external SDKs.Instance.provide - Single-word variables — ,
state,pending,info,row,cfg. Multi-word only when genuinely ambiguous.tx
- 必须使用Effect——所有服务使用/
ServiceMap.Service/Layer。禁止使用普通异步类。makeRuntime - 命名空间归属——每个功能对应一个,在出现明确的拆分需求前,一个功能对应一个文件。
export namespace X {} - 边界用Zod,内部用Effect Schema——DTO/工具参数使用Zod + 。Effect错误使用
z.infer。品牌化ID使用Schema.TaggedErrorClass。Newtype - 事件溯源写入——变更操作通过→ 投影器 → SQLite执行。仅非事件溯源功能允许直接写入数据库。
SyncEvent.run - 测试中不使用Mock——使用+
tmpdir+ 真实服务。仅外部SDK允许使用Mock。Instance.provide - 单字变量名——使用、
state、pending、info、row、cfg等。仅当确实存在歧义时使用多字变量名。tx
Reference index
参考索引
| File | Size | What it contains |
|---|---|---|
| style-dna.md | 18K | Mandatory style rules, naming, control flow, 14 review traps |
| primitives.md | 22K | Quick-lookup: every utility with import path + signature |
| helpers-deep-dive.md | ~40K | Full deep-dive: every utility, every usage site, when NOT to use |
| architecture.md | ~30K | Module map, dependency graph, data flow, file conventions |
| service-module.md | 27K | Complete Question + Permission implementations |
| tool-module.md | 28K | Full tool implementations, registry, prompt loop |
| test-writing.md | 42K | 5 complete test files with all fixture patterns |
| schemas-and-state.md | 36K | SQL tables, Zod/Effect schemas, SyncEvent flow, errors |
| server-and-routes.md | 32K | Routes, config, plugins, project lifecycle |
| review-voice.md | ~25K | Real PR review comments from Dax + Aiden |
| refactoring-patterns.md | ~25K | Real before/after diffs from cleanup commits |
| 文件 | 大小 | 包含内容 |
|---|---|---|
| style-dna.md | 18K | 强制风格规则、命名规范、控制流、14个评审陷阱 |
| primitives.md | 22K | 快速查询:所有工具函数的导入路径 + 签名 |
| helpers-deep-dive.md | ~40K | 深度解析:所有工具函数、使用场景、不适用场景 |
| architecture.md | ~30K | 模块映射、依赖图、数据流、文件规范 |
| service-module.md | 27K | 完整的Question + Permission实现 |
| tool-module.md | 28K | 完整的工具实现、注册、提示循环 |
| test-writing.md | 42K | 5个完整的测试文件,包含所有 fixture 模式 |
| schemas-and-state.md | 36K | SQL表、Zod/Effect模式、SyncEvent流程、错误定义 |
| server-and-routes.md | 32K | 路由、配置、插件、项目生命周期 |
| review-voice.md | ~25K | 来自Dax + Aiden的真实PR评审评论 |
| refactoring-patterns.md | ~25K | 来自清理提交的真实前后代码差异 |