From 4227f413451acdb51f08aaca0cbbb1ae41306fc7 Mon Sep 17 00:00:00 2001 From: linletian Date: Fri, 19 Jun 2026 10:24:33 +0800 Subject: [PATCH 1/5] docs: add ghostty-web research report MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调研 anomalyco/ghostty-web(Ghostty VT 解析器 WASM 化 + xterm.js API 兼容) 与 myworktree 的相似/差异点,以及作为 xterm.js 替代 renderer 的借鉴方案。 结论:精准命中 TERMINAL_FILTER_REVIEW.md 与 CHINESE_IME_ANALYSIS.md 已记录 的 OSC/DA 回声与复杂脚本渲染两类痛点,建议以 feature flag 灰度引入。 --- docs/GHOSTTY_WEB_RESEARCH.md | 139 +++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 docs/GHOSTTY_WEB_RESEARCH.md diff --git a/docs/GHOSTTY_WEB_RESEARCH.md b/docs/GHOSTTY_WEB_RESEARCH.md new file mode 100644 index 0000000..0bb9e8f --- /dev/null +++ b/docs/GHOSTTY_WEB_RESEARCH.md @@ -0,0 +1,139 @@ +# ghostty-web 调研报告:与 myworktree 的对比与借鉴 + +**调研日期**: 2026-06-19 +**目标项目**: https://github.com/anomalyco/ghostty-web +**调研目的**: 评估 ghostty-web 是否可作为 myworktree 前端终端渲染器(xterm.js)的替代方案 +**结论摘要**: ghostty-web 精准命中 myworktree 已记录的两类 xterm.js 痛点(OSC/DA 查询回声、复杂脚本渲染),推荐作为可选 renderer 引入,feature flag 灰度过渡。 + +--- + +## 1. 项目背景 + +**ghostty-web** 是 Coder 公司 fork 自 `coder/ghostty-web` 的一个 TypeScript 库,把原生 [Ghostty](https://github.com/ghostty-org/ghostty) 终端模拟器的解析层编译成 WASM,在浏览器里跑出 xterm.js 兼容的 `Terminal` API。 + +**核心卖点**(来自上游 README): +- 与 xterm.js 完全 API 兼容:「Migrate from xterm by changing your import: `@xterm/xterm` → `ghostty-web`」 +- WASM 编译的 VT 解析器,与原生 Ghostty 共用同一份经过实战检验的代码 +- 零运行时依赖,~400KB WASM bundle +- 修掉 xterm.js 的两个长期 issue: + - 复杂脚本(Devanagari、Arabic)渲染 + - XTPUSHSGR/XTPOPSGR 等控制序列缺失 +- 依赖 Mitchell Hashimoto 正在做的 [libghostty](https://mitchellh.com/writing/libghostty-is-coming),目前 patch 极小(见 `patches/ghostty-wasm-api.patch`) + +**目录结构**: +``` +ghostty-web/ +├── lib/ # TS 库主体(Terminal、Buffer、Renderer、InputHandler、SelectionManager、LinkDetector…) +├── demo/ # Web demo,连接真实 shell +├── dist/ # 构建产物 +├── ghostty/ # 子模块:upstream Ghostty 源码 +├── patches/ # Ghostty 的 WASM 补丁 +├── scripts/ # 构建脚本 +├── bench/ # 基准测试 +├── AGENTS.md # AI 协作指南 +├── biome.json # Biome 格式化 + lint 配置 +├── bun.lock # Bun 依赖锁 +├── vite.config.js # Vite 构建 +└── flake.nix # Nix 开发环境 +``` + +--- + +## 2. 与 myworktree 的相同点 + +两者都面向「**浏览器里的终端体验**」,且都把一个终端渲染器 vendored 到前端用: + +| 维度 | ghostty-web | myworktree | +|---|---|---| +| 终端渲染器 | `ghostty-vt.wasm`(Zig→WASM 的 Ghostty VT 解析器) | `xterm.js v6.0.0` + `xterm-addon-fit`(vendor 在 `internal/ui/static/vendor/`) | +| 接入方式 | 前端 JS 库 + WASM | 前端 `