何时打开:你想看 newtype 怎么 同时玩 OpenCode + 自建 npm CLI 工具 的完整范本。Oh My OpenCode 自定义指南(1729 lines,文档级别最完整)+ newtype CLI(产品级别的 8 Agent 多 Agent 内容生产 CLI)。
跟 Claude Code 最佳实践(Cal Rueb · Anthropic 内部讲座) 的区别:那份是 Anthropic Claude Code 视角。本 wiki 是 newtype 的 OpenCode + 自建 CLI 双工具栈。
一、Part 1:Oh My OpenCode 自定义指南
1.1 项目背景
- Oh My OpenCode:OpenCode 的强大插件
- 官方仓库:https://github.com/code-yeongyu/oh-my-opencode
- 许可证:SUL-1.0(Sustainable Use License)— 允许修改和分发(非商业)
- 功能:多模型编排、并行后台代理、LSP/AST 工具
1.2 10 个内置 Agent
| 英文名 | 中文化建议 | 角色 |
|---|---|---|
| Sisyphus | 西西弗斯 | 主 Agent / 默认编排 |
| oracle | 神谕者 | 架构顾问 |
| librarian | 图书管理员 | 文档/知识检索 |
| explore | 探索者 | 代码探索 |
| frontend-ui-ux-engineer | 前端工程师 | UI / UX 实现 |
| document-writer | 文档撰写员 | 文档生成 |
| multimodal-looker | 多模态观察者 | 图像 / 多模态 |
| Metis (Plan Consultant) | 墨提斯(计划顾问) | 规划顾问 |
| Momus (Plan Reviewer) | 摩摩斯(计划审查员) | 计划审查 |
| orchestrator-sisyphus | 编排西西弗斯 | 多 Agent 编排 |
1.3 2 种自定义方法对比
| 方式 | 适用场景 | 需要编程 | 可否改名 | 安装方式 |
|---|---|---|---|---|
| 配置文件 | 修改参数 / 添加 Agent | ❌ | ❌ | 编辑 JSON |
| Fork + GitHub | 完全自定义、中文化 | ✅ | ✅ | 用户名/仓库#标签 |
| Fork + npm | 公开分享 | ✅ | ✅ | npm publish |
1.4 方法一:配置文件(推荐入门)
位置(优先级低到高):
~/.config/opencode/oh-my-opencode.json(用户级).opencode/oh-my-opencode.json(项目级)
核心字段:
model/temperature/top_pprompt/prompt_append(替换 vs 追加)tools/disable/descriptionmode:subagent/primary/allpermission:edit/bash/webfetch/doom_loop/external_directory
示例 — 权限控制:
{
"agents": {
"explore": {
"permission": {
"edit": "deny",
"bash": "ask",
"webfetch": "allow",
"doom_loop": "deny"
}
},
"oracle": {
"permission": {
"bash": {
"git": "allow",
"rm": "deny",
"npm": "ask"
}
}
}
}
}
1.5 方法二:Fork 仓库 + 完整中文化(进阶)
关键 — 修改 3 个文件
| 文件 | 修改对象 | 位置 |
|---|---|---|
src/agents/types.ts |
BuiltinAgentName 类型 |
第 59-70 行 |
src/config/schema.ts |
BuiltinAgentNameSchema + OverridableAgentNameSchema + AgentOverridesSchema |
第 19-30, 38-53, 118-133 行 |
src/agents/utils.ts |
工具函数中的 Agent 名引用 | (随文件) |
自动化中文化脚本(perl 替换)
#!/bin/bash
set -e
mkdir -p .backups
cp src/agents/types.ts .backups/
cp src/config/schema.ts .backups/
cp src/agents/utils.ts .backups/
perl -i -pe 's/"Sisyphus"/"西西弗斯"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"oracle"/"神谕者"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"librarian"/"图书管理员"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"explore"/"探索者"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"frontend-ui-ux-engineer"/"前端工程师"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"document-writer"/"文档撰写员"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"multimodal-looker"/"多模态观察者"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"Metis \(Plan Consultant\)"/"墨提斯 (计划顾问)"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"Momus \(Plan Reviewer\)"/"摩摩斯 (计划审查员)"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
perl -i -pe 's/"Prometheus \(Planner\)"/"普罗米修斯 (规划者)"/g' src/config/schema.ts
perl -i -pe 's/"orchestrator-sisyphus"/"编排西西弗斯"/g' src/agents/types.ts src/config/schema.ts src/agents/utils.ts
echo "✅ 中文化完成"
8 步实战流程
- Fork + Clone +
bun install - 运行自动化脚本 中文化
- 构建 + 验证:
bun run build+bun run typecheck+bun test - MODIFICATIONS.md 修改声明(SUL-1.0 要求)
- Git commit + push 到 fork
- GitHub Release 打 tag:
v3.0.0-zh.1(gh release create v3.0.0-zh.1 --title "...") - 配置 OpenCode 使用 GitHub 版本:
"plugin": ["你的用户名/oh-my-opencode#v3.0.0-zh.1"] - 测试:
Ask @神谕者 to explain this function
1.6 GitHub 版本 vs 本地构建 vs npm
| 方式 | 配置 | 适用 |
|---|---|---|
| GitHub 版本(推荐) | 用户名/仓库名#标签 |
个人使用 / 朋友分享 |
| 本地构建 | file:///path/to/dist/index.js |
开发时 / 频繁修改 |
| npm | @scope/包名 |
公开分享 / 广泛使用 |
1.7 关键 Q&A
| Q | A |
|---|---|
| 如何强制更新 GitHub 版本 | rm -rf ~/.cache/opencode/node_modules/ 后重启 |
| 私有仓库如何使用 | (1) HTTPS + credential helper(2) 本地 clone + file:/// 路径 |
| SUL-1.0 限制 | 个人使用 / 内部业务,不能商业用途,修改必须声明 |
1.8 推荐工作流
开发时:
Fork → Clone → 修改 → 本地构建测试
配置: "file:///path/to/dist/index.js"
个人使用:
推送 GitHub → 创建 Release → 使用 GitHub 引用
配置: "用户名/仓库名#v3.0.0-zh.1"
公开分享:
发布 npm → 让其他人 npm 安装
配置: "@scope/包名"
二、Part 2:newtype CLI 多 Agent 内容团队
2.1 项目定位
Binary:
nt| Package:npm i -g @newtype-os/cli8 个专业 AI agents(researcher / writer / editor / fact-checker / extractor / analyst / archivist / chief)作为 non-interactive CLI 命令。专为其他 AI agents 程序化调用设计。
核心定位:给 AI 用的 CLI(其他 AI agents 调用,不是给人交互的)
2.2 8 个核心 Agent
| Agent | 用途 |
|---|---|
| researcher | 深度研究(默认 + fact-checker) |
| writer | 内容生成 |
| editor | 4 层精修(structure → paragraph → sentence → word) |
| fact-checker | 事实核验 / 声明验证 |
| extractor | 从文档/图像/网页提取结构化内容 |
| analyst | 框架分析(12 framework) |
| archivist | 知识库 CRUD(语义搜索) |
| chief | 编排器(协调所有 agent) |
2.3 8 个核心命令
nt research [topic..] # 主题研究(+ fact-check 默认)
nt write [topic..] # 内容生成
nt edit [file] # 4 层精修
nt fact-check [topic..] # 事实核验
nt analyze [topic..] # 框架分析(12 framework)
nt extract [topic..] # 内容提取
nt archive <action> # 知识库(store/search/list/delete)
nt pipeline [topic..] # 全流程编排
2.4 输出模式(4 个 Flag)
| Flag | 行为 | 用于 |
|---|---|---|
| (无) | 纯文本 stdout | 人读、简单 piping |
--json |
JSON 信封 stdout | Agent 程序化解析 |
--stream |
NDJSON 事件流 | 实时进度监控 |
-o <file> |
写入文件 | 保存输出、流水线 |
2.5 JSON Envelope Schema(关键 — 给 AI 用的)
成功响应:
{
"success": true,
"result": "... text output ...",
"metadata": {
"agent": "researcher",
"sessionID": "...",
"duration_ms": 45000,
"tools": [{ "name": "web_search", "title": "..." }]
}
}
错误响应:
{
"success": false,
"error": { "code": 2, "message": "..." },
"metadata": { "agent": "researcher", "sessionID": "...", "duration_ms": 12000, "tools": [] }
}
2.6 Exit Codes
| Code | 含义 |
|---|---|
| 0 | Success |
| 1 | Input / argument error |
| 2 | Model call failed |
| 3 | Timeout |
| 4 | Config / auth error |
2.7 输入方式(优先级高到低)
1. 位置参数: nt research AI Agent architectures
2. --input <file>: nt write --input notes.md
3. --topic <text>: nt analyze --topic "Tesla EV"
4. stdin 管道: cat notes.md | nt write
2.8 全局 flags(关键)
| Flag | Short | 用途 |
|---|---|---|
--output <path> |
-o |
输出文件 |
--json |
JSON envelope | |
--stream |
NDJSON event stream | |
--verbose |
显示工具执行 | |
--quiet |
-q |
静默(只显示结果) |
--model <p/m> |
-m |
覆盖模型(provider/model) |
--lang <code> |
输出语言:zh / en / ja |
|
--timeout <sec> |
-t |
超时(默认 300s,pipeline 600s) |
2.9 关键命令详解
nt research — 主题研究
# 基础
nt research "AI Agent architectures 2026" -o research.md
# 深度研究 + focus
nt research "MCP vs CLI" --depth deep --focus "developer experience,adoption" -o deep.md
# JSON 输出
nt research "Kubernetes security" --json
# 跳过 fact-check 加速
nt research "quick overview of RAG" --no-fact-check -o quick.md
| Flag | 默认 | 描述 |
|---|---|---|
--depth <level> |
normal |
shallow / normal / deep |
--sources <n> |
5 |
期望来源数 |
--focus <keywords> |
关键词,逗号分隔 | |
--no-fact-check |
跳过 fact-check |
nt write — 内容生成
# 从研究材料生成 newsletter
nt write --input research.md --style newsletter -o draft.md
# 从主题写 essay
nt write "Why CLI is the native language of AI Agents" --style essay --words 2000 -o article.md
| Flag | 选项 |
|---|---|
--style <s> |
newsletter / essay / report / tweet-thread / technical / story |
--method <m> |
WRITE / AIDA / PAS / STORYTELLING / ANALYTICAL / CONVERSATIONAL |
--words <n> |
默认 1500 |
--tone <t> |
professional / casual / academic / provocative |
--audience <desc> |
目标受众描述 |
nt edit — 4 层精修
# 全 4 层
nt edit --input draft.md -o final.md
# 只调结构
nt edit --input draft.md --layer structure -o restructured.md
# 保留 voice,只改语法
nt edit --input draft.md --preserve-voice -o polished.md
# 带 diff
nt edit --input draft.md --diff -o final.md
| Flag | 默认 | 描述 |
|---|---|---|
--layer <l> |
all |
structure / paragraph / sentence / word / all |
--preserve-voice |
保留原 voice,只改语法 / 逻辑 | |
--diff |
输出差异 |
nt analyze — 12 框架分析
nt analyze --input research.md --framework swot -o analysis.md
nt analyze "Why are all tools moving to CLI" --framework first-principles
nt analyze --input data.md --framework "swot,pestel" -o combo.md
12 框架:swot、pestel、porter、first-principles、5why、jobs-to-be-done、blue-ocean、value-chain、bcg-matrix、ansoff、okr、systems-thinking
nt pipeline — 全流程编排
# 默认流程 (research → analyze → write → fact-check → edit)
nt pipeline "AI Agent trends 2026" --style newsletter --output-dir ./output/
# 自定义步骤
nt pipeline "MCP future" --steps "research,write,edit" -o result.md
# 从已有材料(跳过 research)
nt pipeline --input notes.md --steps "analyze,write,edit" -o final.md
2.10 Pipeline Composition(链式)
# Research → Write → Edit
nt research "AI Agents" -o /tmp/r.md \
&& nt write --input /tmp/r.md --style newsletter -o /tmp/d.md \
&& nt edit --input /tmp/d.md -o final.md
# Extract → Fact-check → Archive
nt extract --input paper.pdf -o /tmp/e.md \
&& nt fact-check --input /tmp/e.md -o /tmp/fc.md \
&& nt archive store --input /tmp/fc.md --tags "paper,verified"
2.11 给 AI Agent 调用的示例
# 获取结构化输出
result=$(nt research "Kubernetes best practices" --json)
echo "$result" | jq -r '.result' # 取文本
echo "$result" | jq '.success' # 检查成功
echo "$result" | jq '.metadata' # 取元数据
# 检查 exit code
nt research "topic" --json -o out.json
if [ $? -eq 0 ]; then
echo "Success"
elif [ $? -eq 2 ]; then
echo "Model call failed, retry"
elif [ $? -eq 3 ]; then
echo "Timeout, increase with --timeout"
fi
三、Part 3:两个工具的整体哲学
3.1 为什么自建 CLI 而非 Skill
| 维度 | Claude Code Skill | newtype CLI |
|---|---|---|
| 调用方 | LLM 内部 | 外部任何 AI / 脚本 |
| 安装 | drop .skill 文件 |
npm i -g |
| 跨工具复用 | 锁 Claude Code | 任何 CLI 环境(VSCode / Cursor / shell / 其他 AI) |
| 输出 | LLM 文字 | JSON envelope / NDJSON / 文件(可编程消费) |
| 价值 | 单次任务方法论 | 作为 building block 编排其他 AI |
关键洞察:newtype 把 8 个 Agent 包装成 CLI,是因为他要在 AI Coding 工作流里调用(Claude Code 调 nt research → 拿 JSON → 进一步处理)。Skill 是给 Claude 用,CLI 是给 Claude 调 Claude(自己嵌套自己)。
3.2 两个工具的协同关系
Oh My OpenCode (10 agents) ──→ 主要做编程任务
↓
Claude Code / OpenCode 调用 nt
↓
newtype CLI (8 agents) ──→ 主要做内容任务
↓
JSON / Markdown 文件
↓
回写到代码 / 文档
3.3 Newtype 工具生态全图
| 层级 | 工具 | 角色 |
|---|---|---|
| CLI / IDE | OpenCode + Oh My OpenCode plugin | 编程主战场 |
| CLI / IDE | Claude Code | 编程主战场 |
| CLI 工具 | nt(newtype CLI) |
内容生产工具 |
| Skill | Super Analyst Pro / Super Writer | Anthropic Skill 格式 |
| MCP | Prompt House local / Sequential Thinking / Tavily | 工具层 |
| 客户端 | ChatWise / Cherry Studio | 兜底对话 |
四、对独立开发者的启示
4.1 你该不该 Fork Oh My OpenCode?
| 你的情况 | 推荐方法 |
|---|---|
| 只想调参数 / 加 prompt | 方法一(配置文件),不要 Fork |
| 想全中文化 / 私人化 | 方法二(Fork + GitHub),SUL-1.0 允许 |
| 想公开分享 | 方法二 + npm publish,记得遵守 SUL-1.0 |
关键约束:SUL-1.0 禁止商业用途。
4.2 你该不该做 newtype 风格的 CLI?
做的 5 个理由:
- 被其他 AI 调用 — JSON 输出可程序化消费
- 跨 IDE 复用 — VSCode + Cursor + Claude Code 都能跑
- 链式编排 —
nt research && nt write && nt edit - timeout / error / retry 由 shell 处理(成熟工具链)
- 可发布 npm,获得分发
不做的 3 个理由:
- 用户只在 Claude Code 用 — Skill 更方便
- 没有 npm publish 习惯 / 维护意愿
- 8 个 Agent 太多 — 先做 1-2 个验证
4.3 newtype 的设计哲学(从两个工具提炼)
- Stage 分明:命令对应 stage(research → write → edit → fact-check)
- JSON 优先:输出可程序化消费(给 AI 调用,不是给人看)
- Exit code 规范:0/1/2/3/4 各代表不同失败,可重试
- 链式可组合:每个命令是 building block,可以 pipe / chain
- 多输入方式(位置参数 / --input / --topic / stdin)— 适配多种调用场景
- timeout 默认 300s,pipeline 默认 600s — 实测合理值
五、跟其他 wiki 的连接
- Claude Code 最佳实践(Cal Rueb · Anthropic 内部讲座) — Anthropic Claude Code 视角(本 wiki 是 OpenCode + 自建 CLI 视角)
- newtype · AI Coding 实战与工具栈演化 — newtype 的 AI Coding 工具栈演化史
- newtype Skill 体系实战(Super Analyst v1/v2 + Super Writer) — Anthropic Skill 格式(本 wiki 的 CLI 是另一种范式)
- newtype · Vibe Coding 独立产品实战 — newtype 自建产品史(newtype CLI 是其中一员)
- newtype 知识系统与 Life OS 全演化 — Oh My OpenCode 是其 AI Coding 系统的核心组件
History
- 2026-05-17:Phase 5.1 ingest 从 file_037(1729 lines Oh My OpenCode 完整指南)+ file_032(newtype CLI 358 lines 产品文档)合并写 1 个 wiki。完整覆盖 OpenCode 自定义 2 种方法 + 中文化 8 步实战 + newtype CLI 8 个 agent / 8 个命令 / JSON envelope / pipeline composition。