---
catalog_id: "R-050"
kind: "repo"
domain: "backend"
domain_label: "后端隐私 / Backend & Infra"
date: "2026-11-27"
title: "herdrdev/herdr-app"
verdict: "GPUI 桌面连核心，须防无沙箱脚本与默认日报遥测"
summary: "Herdr 第二代原生 GPUI 桌面端与 QuickJS-JIT Mod 宿主，通过 hc connect 管道复用接入本地与 SSH 远端 herdr-core；开源但发行版默认开启 Opt-Out 日报遥测与后台静默更新，且 JS Mod 拥有无沙箱全宿主权限。"
summary_en: "Native GPUI desktop client and QuickJS-JIT mod host connecting over hc pipes, with opt-out daily telemetry and unsandboxed full-host JS mods."
canonical_url: "https://oumuatown.com/repos/herdrdev__herdr-app/"
markdown_url: "https://oumuatown.com/repos/herdrdev__herdr-app.md"
og_image_zh: "https://oumuatown.com/og/zh/R-050.png"
og_image_en: "https://oumuatown.com/og/en/R-050.png"
cite_count: 65
repo: "herdrdev/herdr-app"
github_url: "https://github.com/herdrdev/herdr-app"
commit: "1180a5c"
tags:
  - "gpui"
  - "desktop-client"
  - "quickjs-jit"
  - "rust"
  - "telemetry-audit"
  - "coding-agent-ui"
  - "mod-runtime"
github_repos:
  - "https://github.com/herdrdev/herdr-app/tree/1180a5c"
  - "https://github.com/herdrdev/herdr-core/tree/2e8043a"
  - "https://github.com/herdrdev/herdr/tree/e8d7d97"
---

# R-050 · herdrdev/herdr-app

> **结论 / Verdict**: GPUI 桌面连核心，须防无沙箱脚本与默认日报遥测
> **EN Summary**: Native GPUI desktop client and QuickJS-JIT mod host connecting over hc pipes, with opt-out daily telemetry and unsandboxed full-host JS mods.

## Provenance & Evidence

- Primary Repository: https://github.com/herdrdev/herdr-app (@1180a5c)
- Referenced Repository: https://github.com/herdrdev/herdr-core/tree/2e8043a
- Referenced Repository: https://github.com/herdrdev/herdr/tree/e8d7d97
- Verified Source Citations (#Lxx): 65
- Web Reader: https://oumuatown.com/repos/herdrdev__herdr-app/

# herdrdev/herdr-app

> 仓库地址：https://github.com/herdrdev/herdr-app · 审计版本：`herdrdev/herdr-app@1180a5c` · 审计日期：2026-11-27
> 来源文章：[关联文章](../articles/2026-11-27-chendahuang-t3code-telemetry-and-self-hosted-alternatives.md)

## 定位与解决的真问题

- **核心定位与目标用户**：`herdrdev/herdr-app`（`v0.1.18`，1,498 个受控文件）是与 [`herdrdev/herdr-core`](herdrdev__herdr-core.md) 配套的第二代原生 GPU 加速桌面客户端（支持 macOS Apple Silicon / Linux X11 & Wayland Vulkan / Windows x64），围绕 `README.md#L59` 核心原则设计：**“The window arranges terminals. The core runs them.”**（窗口只管排版与渲染，所有进程与 SSH 远端会话全部下沉到 `herdr-core`）。
- **相比第一代 TUI 与 Electron 方案解决的关键痛点**：
  1. 摆脱宿主终端模拟器的快捷键劫持、字体/连字与分屏绘制瓶颈，利用定制打补丁的 GPUI 实现原生高帧率终端渲染与统一跨机 Agent 状态侧边栏。
  2. 通过内嵌 `quickjs-jit` 运行时（`herdr-shell`），允许用户和编码 Agent 直接编写热加载 JavaScript **Mod** 动态定制侧边栏、状态栏、Worktree 面板与工具窗口（`src/mods.rs#L1-L2`, `#L75-L93`），甚至内置了完整的 Windows 98 主题与扫雷/纸牌彩蛋（`defaults/mods/win98/`）。

## 技术栈与核心目录结构

- **语言 / 运行时 / 关键依赖**（`Cargo.toml#L1-L113`、`crates/herdr-shell/Cargo.toml#L1-L64`）：
  - **GPUI + Ghostty-VT + QuickJS-JIT**：图形界面依赖深度定制补丁版 `gpui-pre = 0.3.8`（包含修复空闲窗口每帧 vsync 空转唤醒、Linux 半屏贴靠尺寸及 Windows 死键输入等 `HERDR:` 补丁，`Cargo.toml#L78-L95`）；终端虚拟引擎复用 `crates/ghostty-sys`（`libghostty-vt`）；Mod 引擎 `crates/herdr-shell`（`v0.7.1`）绑定 `quickjs-jit = 0.12.11` + `quickjs-jit-stdlib = 0.12.7`，内置 `gpui-pre-reqwest = 0.12.15`（`hyper`/`hyper-rustls`）与 `tungstenite = 0.29` 供 Mod 发起 HTTP/WebSocket 请求（`crates/herdr-shell/Cargo.toml#L36-L63`）。
  - **许可证**：全仓严格采用 **Apache-2.0** 协议（`LICENSE#L1-L10`、`Cargo.toml#L8`、`crates/herdr-shell/LICENSE-APACHE`），无闭源模块。
- **关键目录树与职责划分**：
  - `src/hc.rs`、`src/mirror.rs` & `src/remote_shell.rs`：`hc connect` 子进程二进制多路复用连接、`EventLines` 事件归并、机器端 `Document` 与本地私有 `View` 分层镜像，以及跨 Shell 远程探针包装器。
  - `src/control.rs`：暴露 `~/.config/herdr-app/herdr-app.sock` 本地窗口控制 Socket（支持单实例置顶、`herdr-app do/ls/status/shot` 自动化）。
  - `src/telemetry.rs`、`src/settings.rs` & `src/update.rs`：日度使用统计采集与 `curl` 上报模块、配置解析、以及每小时后台应用/Core 自动更新检查下载器。
  - `crates/herdr-shell/` & `src/mods.rs`：QuickJS Mod 沙箱能力模型与宿主 API 绑定层。
  - `defaults/`：内置 Mod（`workspace-chrome`、`peek`、`worktree`、`win98` 等）、主题、程序图标库及内置 `AGENTS.md`。

## 核心实现源码级剖析（附文件路径与行号）

1. **`hc connect` 多路复用控制面、分层布局镜像与无 Web/Mobile 边界**（`src/hc.rs#L14-L557`、`src/mirror.rs#L9-L225`、`src/remote_shell.rs#L1-L34`、`src/control.rs#L15-L177`）：
   - **纯 `hc connect` 管道耦合**：`Core::connect` 拉起本地 `hc connect` 子进程并发送 `hello {"framed":true}`，通过 `hc-writer`/`hc-reader` 线程在 stdin/stdout 上复用 `[channel:u32 LE][kind:u8][len:u32 LE]` 帧（`hc.rs#L14-L21`, `#L329-L433`）。App 强制校验 Core `GENERATION == 1` 且必须具备 `USES` 中 9 个方法（`terminal.*`、`doc.get/set`、`events.subscribe`，`#L207-L209`, `#L256-L268`）；通过 `AUTOMATIC_INPUT = 6` 区分终端引擎应答与人类键入防止打断 Core 的草稿避让计时，终端流默认下发 `1 MiB` 信用窗口（`#L486-L528`）。
   - **跨机同步的共享文档 vs 私有视图分离**：所有远程 Linux VPS 均通过 `hc` 的 SSH 联邦转接接入（`remote_shell.rs#L3-L33` 自动适配远端 `fish`/`zsh`/`bash` 登录交互 Profile 探测可用 Agent）。`mirror.rs#L9-L225` 把工作区 `spaces/tabs/splits` 树写入对应机器 Core 的 `doc`（`Document` 使用 `#[serde(flatten)] rest` 保留高版本未知字段防旧客户端覆盖丢字段，`#L15-L38`），而把每个桌面窗口自身的 `active`、`focused`、`zoomed`、`settled` 与 `herdr.seen` 已读水位存在本地 `View` 中，避免多客户端连同一远程主机时互相抢焦点。
   - **Web / Mobile 支持核验**：全仓仅构建原生 GPUI 桌面窗口（Linux 明确要求桌面会话与 Vulkan 驱动，`README.md#L13`），**没有任何内置 Web 服务端或 iOS/Android/PWA 客户端**；窗口自动化控制 Socket `$HERDR_APP_HOME/herdr-app.sock` 也仅面向本机 CLI 与测试脚本（`control.rs#L15-L177`）。

2. **重点审计：默认开启的 Opt-Out 日度遥测（Telemetry）与一键擦除机制**（`src/settings.rs#L398-L400`, `#L475`, `#L728-L735`、`src/telemetry.rs#L27-L183`, `#L217-L315`, `#L414-L697`, `#L723-L741`）：
   - **与 `herdr`/`herdr-core` 的关键差异**：`herdr-app` 在配置模型 `Person::default` 中将 `telemetry` 默认置为 **`true`**（`settings.rs#L400`, `#L475`, `#L733`）。在官方预编译发行版（编译时注入 `HERDR_APP_RELEASE`）或配置了 `HERDR_TELEMETRY_URL` 时，应用启动即拉起独立后台线程 `telemetry`（`telemetry.rs#L101-L106`, `#L175-L183`），每 `TICK = 30s` 将使用统计写入 `~/.config/herdr-app/telemetry/today.json`，按 UTC 自然日冻结至 `queue/YYYY-MM-DD.json`（超 `KEEP_DAYS = 7` 天未发即丢弃，`#L29-L31`, `#L546-L576`），并调用系统 `curl -sS --max-time 20 -X POST` 将日报发送至 **`https://telemetry.herdr.dev/v1/report`**（`#L28`, `#L579-L608`, `#L672-L697`）。源码自编译版本（未设 `HERDR_APP_RELEASE`）仅本地采集供设置页预览，不会向外发包（`#L14-L16`, `#L104`）。
   - **载荷脱敏与随机 ID**：每条日报携带一个 32 位十六进制随机 `install_id`（首次启用生成，`#L643-L654`），`Day::report` 对在线/前台时长、启动耗时、Spaces/Tabs/Agents 数量全部分桶处理（`0`、`1`、`2-5`、`6-20`、`21+`；`<15m`、`15m-1h` 等，`#L273-L302`），非内置布局统一记为 `"custom"`，非正规发布版本号归一为 `"other"`，不上传终端正文、目录路径或自定义 Mod/主题名（`a_report_holds_no_free_text` 单测专测防泄漏，`#L723-L741`）。
   - **彻底关闭与即时擦除语义**：在 `settings.json` 设为 `{"telemetry": false}`（或设置环境变量 `DO_NOT_TRACK=1`、`HERDR_TELEMETRY=0`，以及任何常见 CI 环境变量下自动停用，`#L87-L98`）时，代码会递增全局 `EPOCH`、`kill` 仍在执行中的 `curl` 进程并立即 `remove_dir_all` 删除整个 `~/.config/herdr-app/telemetry/` 目录（连同 `id` 与待发队列，`#L148-L155`, `#L439-L444`, `#L688-L692`）。

3. **每小时自动更新下载与 JS Mod 全宿主权限风险**（`src/update.rs#L23-L195`、`docs/security.md#L3-L43`、`crates/herdr-shell/src/capability.rs#L26-L144`、`src/mods.rs#L1094-L1158`, `#L1403-L1420`）：
   - **静默旁路自动更新（缺独立签名验证）**：发行版（`HERDR_APP_RELEASE`）启动 `10s` 后及每 `1h`（失败 `30m` 重试）通过系统 `curl` 检查 `https://releases.herdr.dev/app/latest.json` 与 `core/latest.json`（`update.rs#L23-L25`, `#L72-L74`, `#L122-L195`），自动下载新版本并解压到旁路目录 `<install>.new`（macOS 附加 `.noindex` 防止 Spotlight 索引，`#L50-L59`）等待下次退出切换。更新校验仅依赖同源 Manifest 内的 SHA-256，**不对 Manifest 本身作独立公钥加密验签**（`docs/security.md#L36-L43`）。
   - **QuickJS Mod 的无沙箱宿主权限与凭证暴露面**：尽管底层的 `herdr_shell::Capabilities` 设计了路径白名单、命令白名单与细粒度 `HttpRequestGrant` 权限模型（`capability.rs#L26-L144`），但 `herdr-app` 在 `src/mods.rs#L1407-L1420` 为所有加载的 Mod 统一赋予了：`.read_roots([home])`（**可读整个用户主目录，包含 `~/.claude`、`~/.codex`、`~/.ssh` 等敏感凭证**）、`.execute(ExecuteGrant::Unrestricted)`（允许通过 `herdr.exec` 在本地和任意远程主机执行任意命令，`#L1094-L1136`）、`.network(NetworkGrant::Unrestricted)` 及剪贴板完全读写权限。虽然官方自带代码不会采集凭证，但一旦安装恶意第三方 Mod，其等价于拥有当前用户的完整 Shell 权限（`docs/security.md#L3-L10`）。

## 亮点设计 vs 局限/坑点

- **值得借鉴的设计**：
  - **极度克制且可审计的 Opt-Out 遥测架构**：独立异步线程、`install_id` 闭环擦除、严格分桶与白名单正则归一（`version` + 泄漏断言单测），以及直接在设置页通过 `telemetry::status` 暴露即将发送与已发送 JSON 载荷的透明设计，堪称桌面端收集基础指标的隐私标杆。
  - **共享布局文档（`Document`）与私有交互态（`View`）分离**：多台桌面端挂载同一远端 Linux Core 时互不干扰焦点的清晰数据模型（`src/mirror.rs`）。
  - **可脚本化桌面壳与内嵌 AI 指南**：启动时自动在 `~/.config/herdr-app/` 同步 `AGENTS.md` 与 `herdr.d.ts` / `gpui-kit.d.ts`（`src/mods.rs#L75-L85`），让编码 Agent 能零摩擦自写桌面端 Mod。
- **局限、隐含假设与潜在坑点**：
  - **发行版默认开启遥测 + 后台轮询更新**：企业或高隐私场景分发官方二进制时需通过 `settings.json` 预置 `"telemetry": false` 或注入 `DO_NOT_TRACK=1`（或自行由源码编译不带 `HERDR_APP_RELEASE`），并注意更新 Manifest 缺独立非对称签名。
  - **Mod 运行时有能力声明壳却无实质隔离**：`src/mods.rs#L1407-L1420` 把 `Capabilities` 全部拉满成 `Unrestricted` 与 `$HOME` 全可读，用户不能把 Mod 当作类似浏览器插件的安全沙箱。
  - **纯原生桌面端，无 Web/移动审批通路**：Linux 无显卡/Vulkan 驱动的无头服务器无法运行 `herdr-app`，手机端审批仍需依靠其他 Web 方案或 SSH TUI。

## 可复用的模块或设计模式

- **如何迁移到未来项目**：
  1. `src/telemetry.rs` 的“纯计数分桶 + 单向白名单清洗 + `EPOCH` 原子擦除闭环 + 本地设置页明文预览”模块可直接作为任何开源桌面端客户端（如自研 T3 Code 桌面端）的隐私合规遥测模板。
  2. `src/mirror.rs` 的 `Document`（`#[serde(flatten)] rest` 前向兼容）与 `View` 分离同步模式，可直接迁移到多端共享协同工作区架构。
- **关联 Pattern**：[self-hosted-coding-agent-orchestration-and-telemetry-audit](../patterns/self-hosted-coding-agent-orchestration-and-telemetry-audit.md)

## Cross-Referenced Specimens

- [A-010 · T3 Code 默认遥测风波始末与 8 款多智能体编排替代品自托管及隐私边界审计](https://oumuatown.com/articles/2026-11-27-chendahuang-t3code-telemetry-and-self-hosted-alternatives.md) — T3 Code 遥测边界剖析与六款开源编排自托管审计
- [R-051 · herdrdev/herdr-core](https://oumuatown.com/repos/herdrdev__herdr-core.md) — 双进程分离配逆序关机屏障，借协议化转义实现零遥测长驻
- [P-017 · 多智能体编程编排器自托管控制面选型与五维遥测凭据隐私审计模式（Self-Hosted Coding-Agent Orchestration & Telemetry Audit）](https://oumuatown.com/patterns/self-hosted-coding-agent-orchestration-and-telemetry-audit.md) — 破除开源即零遥测迷思，确立编排器五维隐私审计与选型铁律
- [R-049 · herdrdev/herdr](https://oumuatown.com/repos/herdrdev__herdr.md) — FD 热交接加跨机隧道，靠屏幕正则驱动初代 TUI 编排
