DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
chore(deps): 删除零引用依赖与孤儿 catalog 条目 (#808)
Mao Mr6765c5be86d4
diff --git a/docs/audit/README.md b/docs/audit/README.mdnew file mode 100644index 00000000..21126739--- /dev/null+++ b/docs/audit/README.md@@ -0,0 +1,83 @@+# ponytail-audit · 全仓过度设计审查++> 仓库 `dsh-tauri-desk/deepseek-harness-desktop` · 审查日期 2026-09-30 · **只读审查,未改动任何被审查代码**(`git status --porcelain` 全仓仅 `?? docs/audit/`)+> 规则集:`ponytail-audit`(level full)—— 只裁「过度设计 / 复杂度」,正确性、安全、性能明确不在范围+> 硬约束(用户指定):**协议类方法即使本仓无调用方也不得标记为删除**(`useListen`、`useListenIframe`、`useInvoke` 等)++## 怎么读这份报告++- 每条 finding 一行:`<tag> <裁什么>. <换什么>. [path:line]`,按可裁剪行数从大到小排序,每条结尾给出 `(-N LOC)`。+- tag 含义:`delete:` 死代码/无人设的开关/投机能力,替换为「无」。`stdlib:` 手写了标准库已有的东西,点名函数。`native:` 依赖或代码在做平台已经做的事,点名平台特性。`yagni:` 只有一个实现的抽象、没人设的配置、只有一个调用方的层。`shrink:` 逻辑不变、行数更少,给出更短的写法。+- 每份报告末尾的 `net: -N lines, -M deps possible.` 是该域的净收益;本 README 末尾是汇总。+- 搜索证据:本机 `rg` 不在 PATH(`Get-Command rg` 失败),零调用方证明统一改用 ripgrep 内核的 harness grep 工具与 `git grep`,搜索范围排除 `node_modules` / `dist` / `target`。**grep 只能证明「没有显式引用」,不能证明「没有被隐式消费」**(例如构建工具的约定式自动发现、配置文件里的字符串引用)——这类条目一律进「需人工确认」或降级为 `keep:`。++## 排除面(不参与裁剪,且在每份报告中被显式保护)++1. **协议面 / IPC 面** —— `docs/audit/protocol-surface.md` 是本次审查的唯一豁免清单,所有 agent 都被要求遵守。要点:从 `src/index.ts` / `client/index.ts` / `host/routes/index.ts` 出口的符号、`docs/specs/plugin.*.md` 里点名的 API、注释自述「协议 / 先定义好 / 暂无调用方」的符号、以及任何通过**字符串通道**(事件名、Tauri command 名、slot 名、route path、capability 名、**`cordis.patch.yml` 里的包名**)被引用的符号,一律不删;只有「纯实现内部、未出口、且无字符串引用」的私有符号才允许 `delete:`。仓内无调用方 ≠ 死代码:消费者在仓外(iframe 里的 dsh 核心 GUI、第三方 cordis 插件、上游 dsh、未来版本)。+2. **信任边界** —— `src-tauri/src/service/fs_guard.rs`、`src/hooks/use-invoke-iframe.ts:31-37` 的 iframe invoke 白名单、`recovery/mod.rs` 的包名校验、tar 安全阶梯、`perm.rs` 提权提示等,明确不因「看起来多余」而删。+3. **`src-tauri/vendor/**`** —— 第三方 vendored 代码,不属于本仓可裁范围。+4. **`source/`** —— 13 个 git submodule(BongoCat、deepseek-harness、dsh-market…),仓内 0 字节,是外部移植参考,不审。+5. **`archive/`** —— AGENTS.md 禁止读取。++## 报告索引++| 域 | 报告 | findings | net |+| --- | --- | --- | --- |+| 依赖层(根 + 各包) | [dependencies.md](dependencies.md) | 9 | -0 行,-9 deps(去重后见汇总) |+| 构建/配置/测试/脚本 | [tooling-config-tests.md](tooling-config-tests.md) | 8 | -496 行 |+| Rust · 插件服务 | [rust-plugin-service.md](rust-plugin-service.md) | 23 | -508 行 |+| Rust · 核心服务 | [rust-service.md](rust-service.md) | 39 | -855 行(含 1 项建议加依赖的 -128,纯裁剪 -727) |+| Rust · 壳层/IPC/配置 | [rust-shell.md](rust-shell.md) | 32 | -397 行 |+| 包 · dsh-tauri 核心 | [pkg-core.md](pkg-core.md) | 4 cuts + 3 keep | -20 行 |+| 包 · ui + extension | [pkg-ui-extension.md](pkg-ui-extension.md) | 17 cuts + 5 keep | -265 行,-1 dep |+| 包 · model + experimental | [pkg-model-experimental.md](pkg-model-experimental.md) | 17 | -456 行,-2 deps(与 pkg-core 重叠,见汇总) |+| 包 · worktree + archive + pet | [pkg-worktree-archive-pet.md](pkg-worktree-archive-pet.md) | 31 | -490 行,-4 deps |+| 包 · ssh + scheduler + notification + rightclick | [pkg-ssh-scheduler-notify-rightclick.md](pkg-ssh-scheduler-notify-rightclick.md) | 27(ssh 13 / scheduler 10 / notification 2 / rightclick 2) | -452 行,-4 deps(去重后见汇总) |+| 前端 `src/**` | [frontend-src.md](frontend-src.md) | 12 | -341 行,-1 dep |+| **协议豁免清单** | [protocol-surface.md](protocol-surface.md) | —(豁免规则) | — |++合计 **213 条 finding**(不含 dependencies 的 9 条依赖项)。++## Lead 复核修正(agent 报告经复核后改动的地方)++review 阶段发现 5 处 agent 判断按 `protocol-surface.md` §1 需要降级或修正,均已直接改进对应报告:++1. `pkg-core.md`:`defineRegister(ctx, setup)` 双参重载(文档在 `packages/dsh-tauri/src/client/register/index.ts:23-24`,实现 `:76-85` 带 `TypeError` 守卫)、`defineAdapter(ctx, { migrations })` 第二参(文档在 `packages/dsh-tauri/src/client/register/index.adapter.ts:664`,签名 `:796`)、`invoke/listen/useInvoke/useListen` 的 `options` 形参——三者都被 `packages/dsh-tauri/src/client/index.ts` 的 `export * from './register'` 等出口面引用,收窄会让仓外插件编译失败 ⇒ 降级 `keep:`,net 由 -44 改为 **-20**。+2. `pkg-ui-extension.md`:`Card.Header/Icon/Content/TitleRow/End` 由 `delete:` 降级 `keep:` —— `packages/dsh-tauri-ui/src/client/components/card.tsx:37` 是 `Object.assign(CardBase, {...})`,经 `components/index.ts` → `packages/dsh-tauri-ui/src/client/index.ts:17` 出口,且已被 `packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx:5`、`mcp-import-dialog.tsx:4` 消费 ⇒ net 由 -285 改为 **-265**。+3. `pkg-worktree-archive-pet.md`:pet 的 `@deepseek-ai/dsh-skill-filesystem` 由 `delete:` 降级 `keep:` —— 它在 `packages/dsh-tauri-pet/src` 内零命中,但是**字符串通道引用**:`packages/dsh-tauri-pet/cordis.patch.yml:3` 的 `name: '@deepseek-ai/dsh-skill-filesystem'` 把它作为 skill provider 行插进运行时插件图(`THIRD_PARTY_NOTICES.md:14` 记载 `includeDefaultRoots: false` + `customSkillDirs`)⇒ deps 由 -5 改为 **-4**。**这条判例推出一条通用教训:本仓的「零调用方」证明必须覆盖 `cordis.patch.yml` 等配置型字符串面,只检索 `src/` 不足以定论**——据此对全仓 `packages/**/*.yml` 做了依赖名扫描,确认其余待裁依赖名无配置型引用。+4. `tooling-config-tests.md`:`test/e2e/probe-wdio.ts` 实为 212 行(原报告写 251),且文件头自述「保留为不依赖 WDIO 的最小诊断通道之一」⇒ 移入「需人工确认」;`postcss.config.js` 因 Vite 的隐式自动发现不可 grep ⇒ 同样移入「需人工确认」;net 由 -535 改为 **-496**。+5. `pkg-ssh-scheduler-notify-rightclick.md`:rightclick 的 `SessionSummaryLike` 声明行 `:18` → 实为 `client/types/index.ts:14`(已改);并在该条注明引用点 15 处、改名不改行数。++Lead 另行抽查确认(grep 工具 / `git grep` 复核过):`SharedRotatingWriter` 全仓只出现在 `src-tauri/src/logger/mod.rs:238,239,273`;`restore_real_backup_to_temp` 的硬编码路径在 `src-tauri/src/service/backup/mod.rs:423`;`download_file`(`src-tauri/src/service/download/core.rs:21-26`)唯一调用方是 `src-tauri/src/service/plugin/install/pnpm.rs:106`;`ENSURE_REUSE_WINDOW` 在 `src-tauri/src/service/plugin/internal/mod.rs:77`;`allowlist.rs:171` 确有作者自留的 `TODO(v1)`;scheduler 的 `followGlobal` 全仓仅 locale 定义处 2 命中(死键);`useZoomLevel` 在 `src/**` 只命中自身文件;`navbar.tsx` 的 `onOpenMachineManager`/`onOpenSyncToRemote` 全仓只出现在该文件 4 行。++## 需人工确认(grep 无法定论,删除前必须人工判断)++1. `test/e2e/probe-wdio.ts`(212 行)—— 全仓零引用(`git grep --fixed-strings "probe-wdio"` 无命中,docs 亦无),但文件头注释自称「保留为不依赖 WDIO 的最小诊断通道之一」。属作者声明式保留,删前确认。+2. `postcss.config.js`(5 行)—— 没有任何**显式**引用,但 `vite.config.ts` 未设置 `css.postcss`,Vite 会按约定**隐式自动加载**该文件,grep 看不见。本仓禁止跑构建(用户可能正处于插件热重载中),故无法用构建验证。+3. `knip`(4 处配置,见 `dependencies.md`)—— 装了、有 script,但 CI 从不调用、也无 knip 配置文件。是「配置了没用」还是「留给本地用」属维护者意图。+4. `src/hooks/use-zoom-level.ts`(75 行,frontend-src.md)—— `src/hooks/use-zoom-level.ts:8` 自述「签名与 `@reause/electron` 的同名 hook 完全一致」,若属迁移期 API 对齐面则应 `keep:`,届时前端域 net 减 92。++## 汇总++**net: -4280 行(各报告自报值算术和)**++按「不加新依赖、不含待确认项」的稳妥口径:++| 口径 | 行数 | deps |+| --- | --- | --- |+| 各报告自报合计 | -4280 | 自报 -21(有重复计数) |+| 扣除建议新增依赖的项(`junction` crate,-128) | -4152 | — |+| 扣除「需人工确认」项(probe-wdio 212 + postcss 5 + use-zoom-level 级联 92) | **-3843** | — |++**deps:确定可删 11 项声明**——`citty`、`consola`、`dotenv`、`tinyexec`、`@genapi/parser`、`@deepseek-ai/dsh-storage-domain`、`@hairy/utils`、`packages/dsh-tauri-worktree` 的 `hookable`、`packages/dsh-tauri-model` 的 `react-if-lite` 声明、`packages/dsh-tauri-extension` 的 `@deepseek-ai/cordis`、`packages/dsh-tauri-worktree` 的 `simple-git`。+**条件项 3 个**——`knip`(是否接入 CI)、`packages/dsh-tauri` 的 `hookable`(需先落地 controller 的 `hookable` → `Set`)、`lodash-es` + `@types/lodash-es`(需落地 scheduler / rightclick / worktree / archive / extension / dsh-tauri 六处原生替换,声明点 7 处)。++去重说明(自报 -21 → 确定 11):`pkg-model-experimental` 的 -2 deps 与 `pkg-core` 的 `dsh-tauri` `hookable` 项是同一处、其 `react-if-lite` 已由 `dependencies.md` 计数;`pkg-ssh-scheduler-notify-rightclick` 的 -4 deps 全部落在 `lodash-es`/`@types/lodash-es` 条件项内;`frontend-src` 的 -1 dep 即 `@hairy/utils`;`pkg-worktree-archive-pet` 的 -4 deps 中 `lodash-es` 两项属条件项。++汇总口径与限制:++- 只累加各报告 `net:` 里号称可裁的行数,不含 `keep:` 条目,不含「需人工确认」项,也不含建议「新增一个依赖」的项(`junction` crate,rust-service 里计 -128 行但 +1 dep)。+- 算术和是**估算**:跨域存在少量可能重叠(同一文件被两条 finding 触及的不同侧面,例如 rust-plugin-service 的 `internal/manifest.rs:117-166` 同时出现在「原子写」与「MoveFileExW」两条),未逐条核减;实际收益应按下限预期。+- 本次审查**未运行任何构建命令**(AGENTS.md 禁止,用户可能正处于插件热重载中),所有结论均为静态阅读 + `git grep`/grep 工具的证据,故「隐式消费」类风险统一进「需人工确认」。+- 覆盖度限制已在各报告末尾「覆盖度(诚实交代)」小节逐域列出:全量逐行覆盖了 Rust 全部 `src-tauri/src/**`(除 `vendor/`)、`packages/dsh-tauri` 核心、tooling/scripts、`src/hooks`/`src/utils`/`src/components`/`src/config`/`src/i18n`;`src/ui`(3.3k 行)/`src/store`(4.8k 行)/`src/layout` 其余部分、以及 ssh 的 manager/transport/bootstrap/sync 等大文件只做了符号级交叉引用扫描(已证明无「导出但零消费者」的函数,但可能仍有未发现的行数级冗余)。+- 顺带记录(不属行数问题):`packages/dsh-tauri-ssh/package.json` 把运行时依赖 `yaml`(被 `packages/dsh-tauri-ssh/src/host/service/allowlist.ts:21` import)声明在 `catalog:testing` 组,按 `pnpm-workspace.yaml` 的分组语义应归 `catalog:utils`;`packages/dsh-tauri-experimental` 有约 12 个 `*.test.ts` 却没有 `test` script 与 vitest devDep(测试跑不起来,属正确性问题,交普通 review)。diff --git a/docs/audit/dependencies.md b/docs/audit/dependencies.mdnew file mode 100644index 00000000..e29cd664--- /dev/null+++ b/docs/audit/dependencies.md@@ -0,0 +1,42 @@+# 依赖层审查(ponytail-audit)++范围:根 `package.json`、`pnpm-workspace.yaml`(catalog / catalogs / patchedDependencies)、`packages/*/package.json`、`patches/`。+方法:`git grep -l --fixed-strings "<name>" -- . ':!pnpm-lock.yaml' ':!node_modules'` 逐依赖计数;每个 `delete:` 都给出证明零引用的检索式。+判定规则沿用 `docs/audit/protocol-surface.md`:**本仓无调用方 ≠ 死代码**。协议面(`dsh-tauri/client` 的 `modules/*` 具名出口、插件公开 API、Tauri command / event 名)即使当前无人 import 也一律保留;只有「本仓唯一引用处是自己被声明的那一行」才算死依赖。++重要前置约定(不要误删):`packages/dsh-tauri/src/client/modules/*.ts`(`lodash-es` / `date-fns` / `hookable` / `css-render` / `valtio-define` / `reause`)不是转发层,而是**依赖收敛的唯一出口**:插件 client bundle 走 CJS 工厂 + 模块表,直接 `import` 这些包会发出模块表查不到的 `require`;`packages/dsh-tauri/src/client/modules/reause.ts:1-16` 记录了 306 导出 → 具名清单后 941KB → 70KB 的实测。另:`react-if-lite` 由 `docs/specs/desktop.baisc.md:90` 强制使用(禁止 `?:` / `&&`),永不列入删除。++## 可直接删除(全仓零引用)++- `delete: citty / consola / dotenv / tinyexec 四个根 devDependency —— 全仓零引用(含 scripts/、.github/**、vite/vitest/tailwind 配置),只出现在自己被声明的那一行。连同 catalogs.utils 里的四条目一起删。[package.json:104-106,117 / pnpm-workspace.yaml:213,214,217,226]` (-4 deps)+- `delete: @genapi/parser —— 零引用。genapi 实际只吃 @genapi/core(genapi.config.ts:1)、@genapi/shared(genapi.pipeline.ts:1)、@genapi/presets(genapi.pipeline.ts:7)、@genapi/pipeline(genapi.pipeline.ts:6)。删 package.json:85 与 pnpm-workspace.yaml:110。[package.json:85]` (-1 dep)+- `delete: packages/dsh-tauri-worktree 声明的 hookable —— git grep -l --fixed-strings hookable -- packages/dsh-tauri-worktree 只命中 package.json:60 本身;包内 src 无任何 hookable 用法(同仓 archive/experimental/extension 都是在 src/host/events/index.ts 真用)。[packages/dsh-tauri-worktree/package.json:60]` (-1 dep)+- `yagni: knip —— 仓库里只有一个 "knip": "knip" 脚本和一条 devDependency,无 knip 配置文件,.github/workflows/** 中零调用(grep -E "knip" .github/workflows → 无命中)。它本身是「找未使用导出」的工具、正对本次审查的题,所以是判断题而非铁定死依赖:要么接进 CI(否则没人跑),要么连 catalogs.lint 条目一起删。[package.json:26,110]` (-1 dep,取决于是否接入 CI)+- `delete: @hairy/utils —— 全仓唯一用法是 src/store/modules/harness/readiness.ts:1 的 import { delay };换成 await new Promise(r => setTimeout(r, ms)) 后根依赖与 catalogs.utils 条目一起消失。[package.json:35, src/store/modules/harness/readiness.ts:1]` (-1 dep)+- `delete: packages/dsh-tauri-model 的 react-if-lite —— 该包 src 零 import;react-if-lite 的真实消费者全在根 src/**(src/components/logs.tsx:3 等 13 处)。其 tsdown.config.ts:6 的 noExternal: ['react-if-lite'] 因此也是空转(没有 import 可内联)。[packages/dsh-tauri-model/package.json:87, packages/dsh-tauri-model/tsdown.config.ts:6]`+- `delete: @deepseek-ai/dsh-storage-domain(根 devDependency)—— 零引用;仅出现在 package.json:79、pnpm-workspace.yaml:50(minimumReleaseAgeExclude)与 :155(catalog)三处声明。删除前确认它不是别的 dsh 包的 peer。[package.json:79]` (-1 dep)++## 可原生替代(stdlib / native)++- `stdlib: lodash-es 的绝大多数具名导入都有原生等价物,逐处替换后整个依赖可退场。原生对照:isArray→Array.isArray、isString→typeof、isFunction→typeof、isFinite→Number.isFinite、isInteger→Number.isInteger、isNil→x == null、compact→filter(Boolean)、uniq→[...new Set]、uniqBy/keyBy→Map 或 Object.fromEntries、groupBy→Object.groupBy、orderBy/sortBy→Array.prototype.toSorted、head/last→arr[0]/arr.at(-1)、take/takeRight→slice、difference→filter + Set、castArray→Array.isArray 三元、inRange→比较、trimEnd→String.prototype.trimEnd、partition→两次 filter、reject→filter 取反。只有 get(路径取值,可选链 a?.b 覆盖常见形)与 debounce/throttle/cloneDeep 无原生等价物,需保留或自行实现。[packages/dsh-tauri-worktree/src/host/{prompts,service,tools,utils}/*.ts, packages/dsh-tauri-scheduler/src/host/{service,utils}/*.ts, packages/dsh-tauri-extension/src/host/service/*.ts, packages/dsh-tauri-archive/src/host/service/*.ts, packages/dsh-tauri-rightclick/src/host/routes/open/*/post.ts, packages/dsh-tauri/src/client/modules/lodash-es.ts]` (-1 dep possible,前提是 6 个包的 41 个 import 点全部落地)++## catalog / 配置卫生++- `yagni: catalogs.utils 里 date-fns、lodash-es、pathe、unstorage、hookable、ofetch 等条目被 7 个包以 catalog:utils 共享,是正确的收敛方式,保留。但 citty/consola/dotenv/tinyexec 四条在删根依赖后即成孤儿条目,需同步删除。[pnpm-workspace.yaml:213,214,217,226]`+- `shrink: minimumReleaseAgeExclude 的 80 条目是 pnpm trustPolicy: no-downgrade + 每日跟着 dsh 预发布走的必要逃生口,不是过度设计,保留。[pnpm-workspace.yaml:13-95]`++## Considered and rejected(看过但不动)++- `source/`(13 个 git submodule:BongoCat、deepseek-harness、dsh-automation、dsh-dafeiyu、dsh-market、dsh-notification(s)、dsh-pet、dsh-plugin-capabilities、dsh-plugin-codex-pets、dsh-session-notification、tauri-plugin-notifications、zcode)—— `.gitignore:33` 忽略、`.gitmodules` 登记,本仓 0 字节,是上游移植参考而非代码,不构成可删减的实现。+- `patches/` 两个补丁都真的在生效:`pnpm-lock.yaml:343-344` 的 patch_hash 显示 `@tauri-apps/[email protected]` 与 `[email protected]` 均按 patch 解析(`pnpm-workspace.yaml:103-105` 绑定)。+- `publint`(package.json:114)虽然零 import,但 `packages/dsh-tauri-tsdown/src/index.ts:85` 会把 `publint: true` 透给 tsdown,tsdown 运行时按需加载该包,保留。+- `@types/semver`(package.json:96)零 import 是正常的:`semver` 自身不带类型,由 tsc 隐式解析。+- `@types/*`、`tsdown`、`typescript` 在包内「零引用」都是误报(tsc / tsdown 隐式消费),不删。+- root `ssh2`(package.json:115)唯一消费者是 `test/e2e/plugins/dsh-tauri-ssh.e2e.ts:20`(真实 SSH 协议往返的 e2e 服务端),保留。+- `@eslint-react/eslint-plugin`、`eslint-plugin-react-refresh`:由 `@antfu/eslint-config` 的 react:true 与 `eslint.config.mjs:3` 注释确认是预设的运行期依赖,保留。+- `@vitest/coverage-v8`:`vitest.config.ts:31-32` 的 coverage 块依赖它,保留。+- `changelogithub`:`.github/workflows/release.yml:102` 真跑,保留。+- `date-fns`:唯一出口是 `packages/dsh-tauri/src/client/modules/date-fns.ts:1` 的 4 个函数,属协议面收敛出口;`test/plugin-resource-closure.test.ts:55` 还专门断言它不会被作为嵌套副本打进插件产物,保留。+- `dsh-tauri-bundle`(只有 package.json、显式列出 11 个兄弟包)——是打包聚合用的清单包,不是空壳依赖,保留。++net: -0 lines, -9 deps possible(确定可删 8 项:citty、consola、dotenv、tinyexec、@genapi/parser、packages/dsh-tauri-worktree 的 hookable、@hairy/utils、@deepseek-ai/dsh-storage-domain;knip 视是否接入 CI 决定;若 lodash-es 全量原生化再 -1)。diff --git a/docs/audit/frontend-src.md b/docs/audit/frontend-src.mdnew file mode 100644index 00000000..66c9dc8d--- /dev/null+++ b/docs/audit/frontend-src.md@@ -0,0 +1,129 @@+# 前端 `src/**` — ponytail-audit++> Scope: `src/**`(git 跟踪 144 个文件,~14.5k LOC)+ `index.html`(12 行)+ `pet.html`(12 行)· 审查日期 2026-09-30 · 只读审查,未改动任何源码+> 排除面全部遵守:`docs/audit/protocol-surface.md` 的协议/IPC 豁免清单(iframe 桥 hook、`ALLOWED_INVOKE_CMDS` 信任边界、Tauri 命令名与事件名、`dsh://*` 消息通道、slot/样式 ID);`react-if-lite` 依 `docs/specs/desktop.baisc.md:90` 保留;未读写 `src-tauri/vendor/**`、`archive/`;未运行任何构建/dev 命令。+> 范围外(仅备注、不作 finding):正确性 bug、安全、性能。++## 方法与证据口径++- 本机 `rg`/`fd` 不在 PATH,零调用方证明统一用 ripgrep 内核的 harness `grep` 工具 + `git grep -n --fixed-strings`;搜索范围 `src/ test/ index.html pet.html`,必要时扩到全仓(排除 `pnpm-lock.yaml`)。+- 另跑了一个 `node` 静态扫描:解析全部 git 跟踪文件的 `from '…'` / `import '…'`(`@/`→`src/`、相对路径,候选后缀 `.ts/.tsx/index.ts/index.tsx`),得到「每个文件被谁导入」与「每个 `export` 在其他文件中的出现次数」两张表;`src/store/modules/*/store.ts` 的顶层方法另做了一轮「模块外零引用」扫描。+- **扫描器的两个已知盲区(本次报告已规避)**:① 后缀候选不含 `.css`,所以 `src/styles/main.css`、`src/pet/main.css`、`src/styles/components/scrollbar.css` 会被误报 0 导入方 —— 实际分别由 `src/main.tsx:11`、`src/pet/main.tsx:6`、`src/styles/main.css:6` 的 `@import` 导入,**保留,不作 finding**;② 「导出但 0 外部引用」的 63 个导出绝大多数是**同文件内部使用**(例如 `src/store/modules/harness/utils.ts:179 readServiceLogTail` 被同文件 `:200` 调用),LOC 节省为 0,**一律不作 finding**。+- 覆盖度诚实声明:`src/hooks`、`src/utils`、`src/components`、`src/config`、`src/i18n`、`src/layout/components/nav-bridge.ts` 为逐行阅读 + 符号级交叉验证;`src/ui`(3.3k LOC)、`src/layout` 的其余部分、`src/store`(4.8k LOC)、`src/pet` 只做了符号级交叉引用扫描(死文件 / 死导出 / 单消费者),**未逐行审查**,因此这几节不会出现「Lean already」这类断言。++## src/hooks++`delete: `use-zoom-level.ts` 整个文件:`useZoomLevel` 的完整实现(含重复的 `RefOrValue`/`isRefLike`/`toValue` 与 1.2 底数换算)在本仓零调用方,功能已被 `useZoomFactor` 覆盖。删文件;`src/utils/zoom.ts:43-59` 与之级联作废(见 `src/utils` 一节)。 [src/hooks/use-zoom-level.ts:1-75] (-75 LOC)`+ - `git grep --fixed-strings "useZoomLevel"` 全仓仅命中自身文件(`:8,12,13,14,28,44,48,50,51,52`);`git grep --fixed-strings "use-zoom-level"` 全仓 **0 命中**;文件在第 4 节的全量导入表里「导入方(排除测试/main)= 0」。+ - 该文件不在 `docs/audit/protocol-surface.md` 白名单内,无字符串通道引用(它是纯 TS 函数,`ZoomLevelSetter` 是类型)。+ - ⚠ 需维护者确认的最后一点:`src/hooks/use-zoom-level.ts:8` 的自述是「签名与 `@reause/electron` 的同名 hook 完全一致」——若这是刻意保留的**迁移期 API 对齐面**(而非普通实现),按协议豁免的同类精神应降级为 `keep:`;本报告按「非协议、无调用方、仓内已有真值实现」判为 `delete:`,并把这一分歧记入「需人工确认」。++`shrink: `use-zoom-factor.ts` 里从未被触发的「ref / Webview 重载」灵活性:删 `import type { Webview }`、`import type { RefObject }`、`RefOrValue<T>`、`isRefLike`、`toValue`、`isFactorArgument` 与两个重载签名,收敛成单一签名 `useZoomFactor(factor?: number)` 并用 `webview.setZoom(factor)` 直接落地。 [src/hooks/use-zoom-factor.ts:1-2,39,55-67,106-113] (-26 LOC)`+ - 唯一调用方是 `src/layout/components/iframe.tsx:227` 的 `useZoomFactor(setting.zoom_factor)`——永远是纯 number,永远不传 ref、不传 `Webview`;全仓无第二处 `useZoomFactor(` 调用。+ - **必须保留**:`isNativeZoomSupported()`(`:79-91`)与 `MIN_MACOS_ZOOM_MAJOR = 11`(`:70`)—— macOS 11 以下 wry 的 `WKWebView.pageZoom` 不可用会崩,是平台保护不是过度设计。++`delete: `use-const.ts` 整个文件:手搓 ref 缓存的 `useConst` 在本仓零调用方。删文件;需要惰性初值的地方用 React 自带的 `useState(() => …)`。 [src/hooks/use-const.ts:1-20] (-20 LOC)`+ - `git grep --fixed-strings "useConst"` 全仓仅命中自身定义行 `:7`;`git grep --fixed-strings "use-const"` 全仓 0 命中。+ - 不在协议白名单,无字符串通道引用。++## src/utils++`delete: `backup-settings.ts` 整个文件:`BackupSettings` 接口与 `normalizeIntervalDays`/`normalizeRetentionCount` 两个纯函数在本仓(含 `src/**` 与 `src-tauri`、`packages`)没有任何生产消费者。删文件;其唯一引用方是一次自测。 [src/utils/backup-settings.ts:1-49] (-49 LOC)`+ - `git grep --fixed-strings "backup-settings"` 全仓仅 `test/backup.test.ts:1,8`;`git grep "normalizeIntervalDays|normalizeRetentionCount|BackupSettings"` 全仓仅命中自身定义行与该测试。+ - 同域的 `test/backup.test.ts:1-58` 随文件一并失去被测对象,可整段移除(上表 LOC 未含测试)。++`shrink: `toast.ts` 的 6 档 placement 机制只服务 1 个真实档位:删 `placements`(6 值)、`queues`/`linuxQueues`/`activeQueues` 三张表、`placementOrder: Map<Placement, string[]>` 的 key 维度与 `placements.forEach(p => activeQueues[p].clear())`,收敛为单个 `ToastQueue`;`placement` 选项与 `placementOrder` 的对外行为逐字不变(仍收 6 个合法值、仍按传入顺序排队)。`src/components/toast-provider.tsx` 同步只渲染 1 个 `Toast.Provider`。 [src/utils/toast.ts:24-31,39-49,51-52,67,120,181 + src/components/toast-provider.tsx:8,38-43] (-30 LOC)`+ - 全仓显式 `placement:` 共 6 处,**全部**是 `'bottom end'`:`src/layout/index.tsx:110`、`src/store/modules/desktop-updater/store.ts:142,153,160,174`、`src/store/modules/harness-updater/store.ts:115`;其余调用点走默认值 `'bottom end'`(`src/utils/toast.ts:115` 的解构默认),无一处使用 `'top start'`/`'top end'`/`'bottom start'` 等其余 5 档。+ - 收敛时**必须保留** `linuxQueues` 与 `queues` 的唯一真实差异 `wrapUpdate: fn => fn()`(Linux 下禁掉 HeroUI 的更新过渡,是平台 workaround),写成 `const queue = isLinux ? new ToastQueue({ wrapUpdate: fn => fn() }) : new ToastQueue()`。++`delete: `zoom.ts:61-84`:`ZOOM_FACTOR_DEFAULT/STEP/MIN/MAX` 四个常量与 `normalizeZoomFactor` 与设置模块的真值实现逐字重复。删这 24 行,缩放真值统一走 `src/store/modules/setting/{constants,utils}`。 [src/utils/zoom.ts:61-84] (-24 LOC)`+ - 与 `src/store/modules/setting/constants.ts:3-12`(四个常量)和 `src/store/modules/setting/utils/index.ts:1-8`(`normalizeZoomFactor`)逐字同值同实现;后者的 `normalizeZoomFactor` 被设置面板/存储路径真实消费,`src/utils/zoom.ts:78` 的这一个则 0 消费者(`normalizeZoomFactor` 全仓调用点只在 `setting` 侧)。+ - 连带 SSOT 冲突:`src/utils/zoom.ts:1` 的 `ZoomAction` 与 `src/store/modules/setting/types/index.ts:24` 重复定义,而 `src/store/modules/setting/store.ts:1` 用的是后者 ⇒ 前者删掉、改从 `@/store/modules/setting/types` 导入(-1 LOC,附带上表)。++`delete: `zoom.ts:43-59`:`ZOOM_LEVEL_BASE = 1.2` 与 `zoomFactorFromLevel`/`zoomLevelFromFactor` 的**唯一**生产消费者是已判删的 `src/hooks/use-zoom-level.ts`;删这 17 行后 `src/utils/zoom.ts` 只剩被 `src/layout/components/iframe.tsx:292,399` 真实消费的快捷键盘/桥消息解析部分。 [src/utils/zoom.ts:43-59] (-17 LOC)`+ - `git grep "zoomFactorFromLevel|zoomLevelFromFactor"`:生产侧只有 `src/hooks/use-zoom-level.ts:5,60,67,73`,其余是 `test/zoom.test.ts:6,7,61-77`(随文件一并失去被测对象)。++`delete: `close-action.ts:3` 的 `CLOSE_ACTION_DEFAULT`:常量只被测试引用,生产代码一律自带兜底值。删这一行。 [src/utils/close-action.ts:3] (-1 LOC)`+ - `git grep --fixed-strings "CLOSE_ACTION_DEFAULT"` 仅 `test/close-action.test.ts:4,11`;同文件 `CLOSE_ACTION_OPTIONS`(`:5`)与 `normalizeCloseAction`(`:9`)有生产消费者 `src/ui/config/components/close-action.tsx:6,53,58,60`,**保留**。++## src/store++`delete: `AppSetting` 接口:设置模块的一个空壳类型,全仓只在自己文件里出现,没有任何一处用它标注值。删 13 行;`src/store/modules/setting/store.ts:1` 只导入 `AppSettingUpdate, ZoomAction`,不受影响。 [src/store/modules/setting/types/index.ts:1-12] (-13 LOC)`+ - `git grep --fixed-strings "AppSetting"` 全仓命中只有该定义块本身(`src/store/modules/setting/types/index.ts:1-12`);`AppSettingUpdate` 另有消费,不在本条。++`native: `@hairy/utils` 整条 runtime 依赖只为 `readiness` 的默认参数提供 `delay`——用平台原生的 `new Promise(resolve => setTimeout(resolve, ms))` 一行替代,然后从 `package.json` 移除该依赖。 [src/store/modules/harness/readiness.ts:1,103,178] (-0 LOC, -1 dep)`+ - `git grep --fixed-strings "@hairy/utils"` 全仓仅 `src/store/modules/harness/readiness.ts:1`、`package.json:35`(`"@hairy/utils": "catalog:utils"`)、`pnpm-workspace.yaml:212`(catalog 定义),无第二个导入方 ⇒ 依赖可整条下线。+ - 用法极窄:`import { delay } from '@hairy/utils'` 只做 `wait = delay` 的默认参数(`:103`、`:178`),实际调用是 `await wait(waitMs)`(`:162`)与 `await wait(boundedWait(...))`(`:227`),签名就是 `(ms: number) => Promise<void>`。+ - 净效果是 +1 行源码、-1 依赖,故本行按 0 行计入 `net:`(依赖数照算)。++## src/config++`yagni: `storage.ts` 单调用方中间层:6 行文件只为把 `tauriStorageDriver` 包成 `createStorage`,唯一消费者是 `src/store/modules/setting/store.ts`;把这三行合并进 `storage.driver.ts` 的出口,删掉中间文件与两层导入。 [src/config/storage.ts:1-6] (-6 LOC)`+ - `createStorage`/`tauriStorageDriver`/`storage` 三个符号的导入方各只有 1 处(`storage.driver.ts` 只被 `storage.ts` 导入,`storage.ts` 只被 `src/store/modules/setting/store.ts` 导入),符合 `docs/specs/devlopment.md` 的零中间层条款。+ - 注:`storage.driver.ts`(42 行,unstorage 自定义 driver 包 `@tauri-apps/plugin-store`)**不是**冗余——它是跨平台适配层实现在被真实使用,保留。++`delete: `query-keys.ts` 的 `logs: ['logs']`:缓存键零引用,是唯一的孤儿键。删这一行。 [src/config/query-keys.ts:13] (-1 LOC)`+ - `git grep --fixed-strings "queryKeys.logs"` 全仓 0 命中(`queryKeys.` 其余键共 31 处引用:`info` 3、`cliStatus` 2、`cores` 5、`plugins` 10、`profiles` 7、`backups` 3、`launchOnLogin` 1)。配置本身作为 SSOT 合理,只删这一个键。++## src/i18n++`delete: 两个语言文件里 39 个从未被引用的翻译键(整个 `remote.form.*` 15 个与 `remote.manager.*` 11 个子树全死,加上零散的 `backup.*`/`nav.forward`/`messages.*` 等):这些键在 `src/**`、`index.html`、`pet.html` 中零出现,且不落在任何一种动态拼接前缀内,删除不影响运行时。 [src/i18n/locales/en-US.json + src/i18n/locales/zh-CN.json] (-78 LOC)`+ - 两文件是**扁平点号键、每行一个键**(各 496 个叶子键 / 498 行含花括号),键集完全一致(en-only 0、zh-only 0),所以每个键 2 行,39 × 2 = 78。+ - 搜索方式:脚本收集 `src/**`+HTML 中所有 `t('…')` 字面量,与两个 JSON 的键集求差;再**手工排除动态前缀**——全仓动态键模板只有 5 种:`t(\`remote.step.${phase}\`)`、`t(\`remote.state.${machine.state}\`)`、`t(\`remote.auth.${machine.authMethod}\`)`、`t(\`startup.phase.${phase}\`)`、`t(\`errors.startup_${kind}\`)`,对应 `remote.step.*` 1 个、`remote.state.*` 4 个、`remote.auth.*` 2 个、`startup.phase.*` 3 个、`errors.startup_*` 3 个,共 13 个键被排除在删除清单外。57 − 13 = 44,再扣除被测试断言钉住的 5 个(`plugins.disable_toast` / `plugins.disable_failed` / `plugins.enable_toast` / `plugins.enable_failed` 见 `test/plugin-disable.test.ts:68-71,80-83`,`profiles.clone_invalid` 见 `test/clone-profile.test.ts:166`)得到 39 个干净死键(那 5 个若要删需同步改测试,可再得 10 行,未计入)。+ - 39 个键全表:`app.expand_sidebar`;`errors.service_start_timeout`;`messages.logs_copy_failed`;`messages.zoom_failed`;`nav.forward`;`backup.title`;`backup.tooltip`;`backup.tabs_label`;`backup.settings_saved`;`backup.settings_failed`;`remote.manage_hint`;`remote.form.host`;`remote.form.name`;`remote.form.id`;`remote.form.port`;`remote.form.user`;`remote.form.remote_port`;`remote.form.password`;`remote.form.passphrase`;`remote.form.color`;`remote.form.tint_border`;`remote.form.start_command`;`remote.form.start_command_hint`;`remote.form.keep_blank`;`remote.form.host_required`;`remote.form.id_invalid`;`remote.form.id_taken`;`remote.manager.title`;`remote.manager.subtitle`;`remote.manager.add`;`remote.manager.edit`;`remote.manager.edit_action`;`remote.manager.remove_action`;`remote.manager.remove_title`;`remote.manager.remove_desc`;`remote.manager.connect`;`remote.manager.disconnect`;`remote.manager.test`;`remote.manager.empty`。+ - 附带结论(供维护者判断,不是 finding):`remote.form.*` 与 `remote.manager.*` 两个子树**整体**死掉,说明远端机器管理表单 UI 要么从未落地,要么已废弃但 i18n 与 store 的字段定义没跟着删。++## src/layout++本次未发现可净裁项(符号级交叉引用扫描:无存活死文件、无死导出、无单消费者文件;`src/layout` 其余部分未逐行审查)。`src/layout/components/nav-bridge.ts` 看似死代码,实为协议通道,降级进 `keep:`(见下)。++## src/components++`Lean already. Ship.`(10 个文件全部逐行读过)+- `src/components/primitives.ts`(28 行)的 `button` 有 2 个消费者(`src/layout/components/loadable.tsx:5`、`src/layout/components/setup.tsx:8`),不是单调用方层;`src/components/logs.utils.ts`(45 行)的 `formatLogLine`/`pickErrorLines`/`containsInotifyLimitError`/`containsHeapOomError` 全部被 `src/store/modules/harness/utils.ts:8,202,209,212` 真实消费,不是「只给测试用」的纯函数;`src/components/panel.tsx`(124 行)把原三个文件收敛成一个复合组件,是正向简化;`modal.tsx`/`item.tsx`/`empty.tsx`/`info.tsx`/`ellipsis.tsx`/`toast-provider.tsx` 各有 ≥2 生产消费者。`toast-provider.tsx` 的 6 个 `Toast.Provider` 是本次 `shrink:` 的另一半,已计入 `src/utils` 一节。++## src/pet++本次未发现可净裁项(符号级交叉引用扫描)。+- `src/pet/hooks/use-bubble-tracker.helpers.ts`(200 行)不在「单导入方」名单里(hook 与其测试都导入它),拆分成立;`src/pet/hooks/use-bubble-tracker.ts:40-42` 消费的事件名 `session:create|update|remove` 属协议通道。+- `src/pet/utils/log.ts`(33 行,`reportPetIssue` → `log_frontend` 命令)是桌宠独立 webview 唯一日志出口,真实功能。+- `src/pet/main.css` 由 `src/pet/main.tsx:6` 导入(扫描器假阳性,见「方法与证据口径」)。++## src/ui · src/store(大文件部分)· src/types · index.html · pet.html++- `index.html`(12 行)与 `pet.html`(12 行):`Lean already. Ship.`——只有 Vite 入口脚本与 `#root`,无冗余 meta/无未用 preload。+- `src/config/client.ts`(21 行,`QueryClient({ retry: false })` + `MutationCache.onError` 兜底打印)与 `src/pet/utils/log.ts`:真实功能,保留。+- `src/ui/config/hooks/use-core-profile-switch.tsx`(124 行)与 `use-core-breaking-confirm.tsx`(40 行)各有 3 个生产消费者(`src/layout/index.tsx:13,14`、`src/ui/config/core.tsx:18,19`、`src/ui/config/debug.tsx:18,19`),不是单调用方层。+- 覆盖度声明:`src/ui`(3.3k LOC,最大 `src/ui/config/plugin.tsx` 665、`profile.tsx` 563、`core.tsx` 530、`debug.tsx` 438)、`src/store`(4.8k LOC,最大 `src/store/modules/harness/store.ts` 845、`plugins/store.ts` 694)、`src/layout` 的其余大文件只做了符号级扫描(死文件 / 死导出 / 单消费者 / store 方法外引用),**未逐行审查**,因此这里不写 `Lean already`。可复核的扫描结果:`src/store/modules/*/store.ts` 的顶层方法**没有一个**在所属模块目录外零引用(各模块方法数:harness 10、plugins 34、recovery 3、remote 3、setting 3、desktop-updater 3、harness-updater 2、preinstall 2)⇒ 未发现死 store action。++## keep: 协议面(不计入 net)++- `keep: navBridgeOf 保留(协议通道生产者);其内部三条 payload 与 webview 逐字重复,可收敛。`——`src/layout/components/nav-bridge.ts:32-33` 是壳层侧**唯一**构造 `dsh://settings:open` 的地方,而该消息的消费方在仓外的插件包里真实存在:`packages/dsh-tauri-ui/src/client/register/settings-open.ts:5`(`SETTINGS_OPEN_MESSAGE = 'dsh://settings:open'`,注释自述「壳层 deep-link:宿主窗口 postMessage」)与 `packages/dsh-tauri-ssh/src/client/constants/index.ts:30`。文件在导入表里只有自己的测试导入(`src/layout/components/nav-bridge.test.ts:2`),但按豁免清单「字符串通道引用 ⇒ keep」不判删除。可收敛处:`onToggleSidebar`/`onNewChat`/`onOpenFolder` 三条(`:28-30`)与 `src/layout/components/webview.tsx:91-93` 逐字重复,让 `webview.tsx` 复用 `navBridgeOf(post, true)` 可去重 3 行(不计入 net)。+- 一行备注(正确性,非 finding):`src/layout/components/navbar.tsx:220,222,229,688` 声明并透传 `onOpenMachineManager`/`onOpenSyncToRemote` 给 `<RemoteSwitcher onManage=… onSync=…>`,但生产接线 `src/layout/components/webview.tsx:89-96` 只传 4 个回调——这两个入口当前永远是 `undefined`,即「机器管理 / 同步到远端」按钮在壳层里点不动。只有 `nav-bridge.ts:32-33` 提供过它们。+- `keep: useListen / useListenIframe / useInvoke / useInvokeIframe(+ALLOWED_INVOKE_CMDS) / useIframeMessage / useIframePost(+IFRAME_HOST_SOURCE) 全部原样保留。`——`useInvoke`(`src/hooks/use-invoke.ts:5`)与 `useListenIframe`(`src/hooks/use-listen-iframe.ts:38`,含 `:25-26` 的「目前尚无调用方……先按协议定义好」)在仓内确实 0 调用方,`useInvokeIframe` 的 15 条命令白名单是 iframe 插件越权的信任边界(`src/hooks/use-invoke-iframe.ts:39-59`,被 `src/layout/components/iframe.tsx:220` 使用,未命中时 `:66-69` 仅 `console.warn` 后忽略),均不提议删除或削弱。内部未发现值得收敛的冗余。+- `keep: src/config/hooks.ts 的两个事件钩子保留。`——`'toast.updated'`(触发 `src/utils/toast.ts:158`,消费 `src/components/toast-provider.tsx:26`)与 `'config.dialog.hidden'`(触发 `src/store/modules/harness/store.ts:694,807`、`src/store/modules/preinstall/store.ts:249`,消费 `src/ui/dialog/config.tsx:48`)都有真实两端。+- `keep: useNotificationClicked / useNotificationAction 保留。`——虽各只有 1 个调用方(`src/layout/components/iframe.tsx:235,236`),但它们绑定的是跨进程事件名 `dsh-notification-clicked` 与通知动作通道,属协议面;同理 `useSyncVisibility`(iframe 可见性 `dsh://visibility-state`)、`useListen` 的 `session:*`/`preinstall-log`/`setting_updated` 消费点(`src/pet/hooks/use-bubble-tracker.ts:40-42`、`src/hooks/use-invalidate-on-setting-updated.ts:17`、`src/ui/config/debug.tsx:51`)都不作裁剪。++## Considered and rejected++- `src/utils/silence.ts`(15 行)——22 处调用(`src/ui/config/backup.tsx:57,107,134`、`core.tsx:181,201,269`、`plugin.tsx:164-358` 共 14 处、`profile.tsx:212,281,318`、`src/ui/dialog/about.tsx:88`、`src/ui/plugin/recovery.tsx:55`),真实共用件,不是中间层。+- `src/utils/core-version.ts`(101 行)——`compareVersions`(:23)、`coreProfileName`(:44)、`isCoreUpgrade`(:64)、`isCoreBreakingVersion`(:79)、`isCoreUnsupported`(:99)、`CORE_BREAKING_BASELINE`(:7)、`MIN_SUPPORTED_CORE_VERSION`(:91) 全部有生产消费者(`src/ui/config/core.tsx:108,127,150,165,529`、`hooks/use-core-profile-switch.tsx:63,71`、`hooks/use-core-breaking-confirm.tsx:20,28`)。+- `src/utils/clipboard.ts`(27 行)——3 个生产消费者(`src/layout/components/navbar.tsx:381`、`setup-preinstall.tsx:143`、`setup.tsx:37`),且文件注释说明为何刻意不用 `@tauri-apps/plugin-clipboard-manager`(Linux Wayland 崩溃),是兼容性刚需。+- `src/utils/iframe.ts`(15 行)——`getIframeOrigin` 有 2 个消费者(`src/hooks/use-iframe-message.ts:37`、`src/hooks/use-iframe-post.ts:30`),且是 origin 校验的唯一入口,贴着协议面。+- `src/utils/logger.ts`(139 行)——劫持 `console.*` 并透传到 Rust `log_frontend`(`:81`),含全局 `error`/`unhandledrejection` 兜底(`:92-101`),真实功能。可选微裁(未计入 net,收益 2 行且需确认目标浏览器基线):`:20` 的 `console.debug ?? console.log` 与 `:23` 的 `console.trace ?? console.log` 在现代 webview 恒非空。+- `src/utils/zoom.ts:1-42` 的 `zoomActionFromShortcut`(:16)/`zoomActionFromBridgeMessage`(:29) —— 被 `src/layout/components/iframe.tsx:292,399` 消费,保留(同文件其余两条已列 finding)。+- `src/hooks/use-theme-adaptive.ts:14`、`use-remote-machines.ts:17`、`use-sync-visibility.ts:10`、`use-window-draggable.ts:54`、`use-omit-ignore-cursor-events.ts:40`、`use-dsh-style.ts`、`use-dsh-shortcuts.ts`、`use-wakelock-release.ts`——都只有 1 个调用方,字面上符合「零中间层」,但逐个看内容后不判 `yagni:`:它们不是纯转发(含 `matchMedia` 监听、`getCurrentWindow()` 拖拽、桌宠 hitbox 的 `ignoreCursorEvents` 平台调用、wakelock 释放、全局状态 `createGlobalState`),内联只会把平台细节摊进组件。唯一勉强可算的 `use-sync-visibility.ts:10` 只做「组件卸载 → 发一条 `dsh://visibility-state`」,但它是协议消息的发送端,归入 keep 更稳妥。+- `src/config/storage.driver.ts`(42 行)—— unstorage 自定义 driver 确实只有 1 个实现、1 个使用点,但它包装的是 `@tauri-apps/plugin-store` 的跨平台适配边界(SSOT 角度它才是 `createStorage` 的真值实现),保留。+- `src/store/**` 的 `modules/<name>/index.ts` 再导出 barrel(2-9 行)——逐个人工确认**都有**生产导入方(`@/store/modules/plugins`、`harness`、`remote`、`preinstall`、`setting` 均有 import 点),删除只会换来一批 import 改写,纯增改动量 ⇒ 留。+- 63 个「导出但仅同文件使用」的导出(如 `src/hooks/use-plugins-manager.ts:20,25` 的 `UseDshPluginsManagerOptions`/`UseDshPluginsManagerResult`、`src/store/modules/harness/patch-layer.ts:19,36` 的两个错误码常量、`src/i18n/index.detector.ts:7` 的 `LANGUAGE_STORAGE_KEY`)——只是 `export` 关键字多余,LOC 节省 0(去掉关键字反而可能触发 lint 的未使用告警),不作 finding。+- `react-if-lite`——`docs/specs/desktop.baisc.md:90` 强制 `<If>/<Then>/<Else>` 且禁止 JSX 里用 `?:`/`&&`,明确保护的依赖,不提任何裁剪。+- `src-tauri/vendor/**`、`archive/`、`packages/**`——不在本次范围。+- 未提议给任何代码加解释性注释(仓库 0 注释政策),也未提议 `_legacy` 桩(`docs/specs/devlopment.md` 要求直接删)。++## 需人工确认++1. `src/hooks/use-zoom-level.ts`(75 行)的删除是本报告最大的一笔,但其 `:8` 自述「签名与 `@reause/electron` 的同名 hook 完全一致」。若这是刻意保留的迁移期 API 对齐面(而非普通实现),应降级为 `keep:`,`net` 相应减少 75(同时 `src/utils/zoom.ts:43-59` 的 17 行级联删除也随之取消,合计 −92 行)。+2. i18n 另有 5 个键(`plugins.disable_toast`/`disable_failed`/`enable_toast`/`enable_failed`、`profiles.clone_invalid`)被测试断言钉住,删除它们需同步改 `test/plugin-disable.test.ts:68-71,80-83` 与 `test/clone-profile.test.ts:166`,可再得 10 行,未计入 `net`。+3. 本报告的零调用方结论来自静态 `import`/标识符扫描(`rg` 不可用,未跑 knip:knip 任务输出落盘失败,证据不可用)。grep 只能证明「没有显式引用」,不能证明「没有约定式/反射式消费」——上述每条 finding 的删除都建议先跑一次类型检查确认。++net: -341 lines, -1 deps possible.diff --git a/docs/audit/pkg-core.md b/docs/audit/pkg-core.mdnew file mode 100644index 00000000..6d2af412--- /dev/null+++ b/docs/audit/pkg-core.md@@ -0,0 +1,48 @@+# packages/dsh-tauri (+ tsdown / ui-playground / bundle) — ponytail-audit++> Scope: packages/dsh-tauri, dsh-tauri-tsdown, dsh-tauri-ui-playground, dsh-tauri-bundle, packages/.test · ~6.7k LOC · read 2026-09-30+> Exclusions honoured: `docs/audit/protocol-surface.md` §1/§2.2 (entry-exported symbols, `defineAdapter`/`adapter.has(...)` capability names, IPC/route/event/slot/constant protocol) are never proposed for deletion. Only over-engineering *inside* them is reported.++## Findings (ranked, biggest cut first)++`shrink: controller 用 hookable 事件总线只为承载一个 dispose 钩子;`add()` 的返回注销 = `Set.delete`,`dispose()` 的顺序触发 = 迭代,`removeAllHooks` = `clear`。换成 `const disposers = new Set<() => void>()`,删掉 `LifecycleHooks` 类型与 `createHooks` 接线。公开 API(`add/timeout/interval/listen/observe/isDisposed/dispose`)逐字不变。 [packages/dsh-tauri/src/client/controller/index.ts:9,12-14,58,62-75,140-153] (-10 LOC)`+ - rg `createHooks` → `controller/index.ts:9`、`modules/hookable.ts:1`;`controller/index.ts` 直连 `'hookable'`,不经自己的 shim。+ - rg `callHook|removeAllHooks|hooks\.hook` → 仅 `controller/index.ts`,唯一钩子名 `'dispose'`。++`delete: `defineDshConfig` 的 `client: false` 分支("只要 server half")全仓无人设置、docs 无记载。删 `client?: ... | false` 联合、`options.client === false` 三元与提前 return。 [packages/dsh-tauri-tsdown/src/index.ts:15,80,97-100] (-6 LOC)`+ - rg `client: false` 于 `packages/*/tsdown.config.ts` → 0 命中(14 个 `defineDshConfig(...)` 调用点全部保留 client half)。+ - rg `client: false|defineDshConfig|publint` 于 `docs/` → 0 命中。++`delete: `click(selector)` 只包一层 `clickIfPresent` 并丢弃返回值,全仓零调用方(实际使用者都直接用 `clickIfPresent`)。删函数,`utils/browser.ts` 只剩 `clickIfPresent`。 [packages/dsh-tauri/src/client/utils/browser.ts:17-19] (-3 LOC)`+ - rg `click\(` → 71 命中,全部是 DOM `.click()`、`fireEvent.click`、`controller.click`;`clickIfPresent` 的唯一调用方是 `src/client/register/index.adapter.ts` 的退级阶梯。++`delete: `dshClientInline` 白名单里的 `pathe`:仓内 `pathe` 只被宿主侧文件导入,客户端 bundle 从不需要内联它。从正则可选分支移除即可。 [packages/dsh-tauri-tsdown/src/index.ts:73] (-1 LOC)`+ - rg `from 'pathe'` → 66 命中,路径全部为 `packages/*/src/host/**`(含 host 侧测试),`src/client/**` 0 命中。++## keep: 协议面(不计入 net)++> Lead 复核:以下三条原为 `yagni:` 裁剪项,但其符号经 `packages/dsh-tauri/src/client/index.ts` 出口(`export * from './register'`、`export * from './service/invoke'`、`export * from './service/listen'`、`export * from './hooks/use-invoke'`、`export * from './hooks/use-listen'`、`export type * from './types/tauri'`),仓外插件的既有调用会因签名单方面收窄而编译失败。按 `docs/audit/protocol-surface.md` §1「本仓无调用方 ≠ 死代码」,降级为 `keep:`。++- `keep: defineRegister(ctx, setup) 双参重载保留;其内部 boundCtx 解析可收敛(例如改由调用方显式传 ctx)。` — 该重载是**文件内自述的对外签名**:`packages/dsh-tauri/src/client/register/index.ts:23-24`「若调用方不使用 `ctx.effect`,可用双参形式显式传入:`defineRegister(ctx, setup)`」,实现 `:76-85` 还带 `throw new TypeError('defineRegister: 缺少注册回调,签名是 defineRegister([ctx,] setup)')` 守卫;两参形式在 `packages/dsh-tauri/src/client/register/index.test.ts:145` 有覆盖。+- `keep: defineAdapter(ctx, options) 第二参保留;其内部默认值(DEFAULT_DSH_MIGRATIONS / defaultWarn)可收敛。` — 文档承诺在 `packages/dsh-tauri/src/client/register/index.adapter.ts:664`「消费方可用 `defineAdapter(ctx, { migrations })` 追加,追加项在最后执行」,签名 `:796`;`DefineAdapterOptions` 定义在 `packages/dsh-tauri/src/client/types/adapter.ts:225-229`(出口类型)。+- `keep: invoke/listen/useInvoke/useListen 的 options 形参保留;其内部可收敛。` — `InvokeOptions`(`packages/dsh-tauri/src/client/types/tauri.ts:4-6`)与 `Options { target? }`(`:16-18`)都被出口函数签名引用,删形参即改对外契约;顺带记录:这两个字段当前是**静默 no-op**(下划线形参),属正确性问题,应走普通 review 而非 ponytail 裁剪。++## Considered and rejected++- `host/modules/h3.ts:1-2` 的 `HTTPError` / `readRawBody` / 类型 `EventStreamMessage` / `EventStreamOptions` — 仓内零消费者(rg:这些标识符只出现在该重导出行;`EventStream` 有消费方 `packages/dsh-tauri-pet/src/host/routes/session/stream/get.ts:2`)。但这行经 `src/index.ts` 出口,属协议面 ⇒ `keep: h3 重导出面保留;其内部 4 个零消费符号可收敛,但不得删导出本身。` 不计入 net。+- `client/types/harness.ts:61-62` `SlotEntryLike = StoredEntry` / `SlotEntryOptions = StoredEntry['options']` — rg `SlotEntryLike|SlotEntryOptions` 全仓仅这 2 行声明。是 `export type * from './types/harness'` 的出口面 ⇒ `keep:`,不删。+- `client/types/tauri.ts` 的 `InvokeOptions` / `Options` 接口本体(4 行)——出口面类型,同上,只删实现里的无效参数。+- `client/register/index.ts:98-103` 的"返回 cleanup / cleanup 数组"兜底分支 — 生产 setup 无返回值,仅 `index.test.ts:34 return []` 触发;但文件注释写明是既有插件的"老写法兜底"(跨仓兼容),保留成本 6 行 < 破坏在仓外插件的风险 ⇒ 留。+- `client/modules/*`(css-render / hookable / tailwind-variants / date-fns / lodash-es / reause / valtio-define)单行重导出 — 不是冗余:`docs/specs/plugin.client.md:132` 规定客户端依赖必须经 `dsh-tauri/client` 隔离(`export *` 会把 reause 的 306 个导出灌进 client.cjs,941KB → 70KB)。`modules/hookable.ts` 与 `modules/date-fns.ts` 仓内暂无插件消费,但同属该白名单契约 ⇒ 留。+- `client/modules/lodash-es.ts` 38 名字白名单 — 部分名字仓内暂无消费者,但该表按规范是"按需追加"的对外 surface(规范明确要求缺方法时补进此文件)。剪枝会静默破坏仓外插件 ⇒ `keep: lodash 白名单保留;其内部未被消费的名字由维护者按发布节奏收敛。` 不计入 net。+- `client/types/index.ts` = `export * from './harness'`(单行 barrel)— 是"只导出一行",但被 8 处 `from '../types'` 依赖,删它只换来 8 个文件的 import 改写,纯增改动量 ⇒ 留。+- `host/config/runtime.ts` `defineHostRuntime<C>()` 单调用点 — 注释声称"每插件各调一次",本仓仅 1 次;但 `getCurrentHostInstance/setCurrentHostInstance` 被 7 个包消费(`packages/dsh-tauri-*`),是跨包协议 ⇒ 留。+- `host/service/index.ts` `defineService` 6 行恒等函数 — 编译期宏,`docs/specs/plugin.host.service.md:11-16` 强制,~30 个服务文件消费 ⇒ 留。+- `host/routes/index.ts` 的 401/403、OPTIONS 204、405+allow、loopback、`cross-origin-request`、`cache-control: no-transform` 分支 — 每条都对应宿主版本漂移/压缩中间件的实错,非投机 ⇒ 留。+- `host/service/gate.ts`(双 gate 接管 + restore 记账)、`host/utils/atomic.ts`(Windows EPERM rename 重试)、`host/utils/open.ts:27-42`(刻意不复用 `spawnDetached`,避免 explorer 首窗被 SW_HIDE)、`client/locale/index.ts` `installations` 引用计数 — 均为已记录的兼容性刚需 ⇒ 留。+- `dsh-tauri-bundle/package.json`(11 个 `workspace:*` 的私有聚合包)、ui-playground(`src/host/apply.ts:2` 故意空实现、constants/locale/panel 每条常量都有消费方)、`packages/.test/test-utils.ts` — 无过度设计。+- 依赖:`h3`/`hookable`/`ofetch`/`unstorage` 四个 runtime dep 全都被真实调用,devDeps 全部被 `src/client/modules/*` shim 或测试消费 ⇒ 无可删依赖。++## net: -20 lines, -0 deps possible.++> Lead 复核修正:原 net -44 含三条协议面裁剪(-10/-8/-6),已移入上方 `keep:` 小节并不计入 net。剩余裁剪项:controller hookable→Set (-10)、`defineDshConfig` client:false 分支 (-6)、`click` (-3)、`dshClientInline` 白名单里的 `pathe` (-1)。diff --git a/docs/audit/pkg-model-experimental.md b/docs/audit/pkg-model-experimental.mdnew file mode 100644index 00000000..6c9cae75--- /dev/null+++ b/docs/audit/pkg-model-experimental.md@@ -0,0 +1,80 @@+# packages/dsh-tauri-model + dsh-tauri-experimental — ponytail-audit++> Scope: packages/dsh-tauri-model, packages/dsh-tauri-experimental · ~13.4k LOC · read 2026-09-30++方法:每个 `delete:` / `yagni:` 都用全仓检索证明零调用方(本会话 `rg` 不在 PATH,全部用同等的全仓正则检索,检索式写在各条末尾)。判定沿用 `docs/audit/protocol-surface.md`:被 `src/index.ts` / `client/index.ts` / `host/routes/index.ts` 导出、或被字符串通道引用的符号属协议面,只做 `shrink:`(保留同名对外形状)或 `keep:`。++## Findings (ranked, biggest cut first)++### dsh-tauri-model++`shrink: modelStyles / welcomeStyles / onboardingStyles / onboardingDialogStyles 是 84 行人工维护的「键 → 哈希类名」映射表,必须与上面的 CSS 模板字符串手工对齐;四张表都能从 CSS 文本推导。` 写法:`const modelStyles = Object.fromEntries([...MODELS_CSS.matchAll(/\.(zGbnIq_\w+)/g)].map(m => [m[1].slice(7), m[1]]))`(`prefix` 换成 `zGbnIqw_`/`zGbnIqo_`/`zGbnIqd_` 各 1 行;`hiddenLabel` 这类驼峰键与类名本来就一一对应)。漂移已经发生过:`org`/`w3` 两个键指向的类名在 CSS 里根本不存在,`hiddenLabel`/`switchThumb` 两个键(规则在 `styles.ts:611`、`styles.ts:622` 的 media 块内)零消费者。 [packages/dsh-tauri-model/src/client/models/styles.ts:779-868] (-80 LOC)++`shrink: packages/dsh-tauri-model/src/client/types/remotes.ts 前 10 行 + LlmModelDiscoveryRequest + LlmDiscoveredModel 是对 packages/dsh-tauri-ui/src/client/types/remotes.ts 的逐字重复。` `dsh-tauri-ui/client` 已经发布这几张类型(`packages/dsh-tauri-ui/src/client/index.ts:23` 的 `export * from './types/remotes'`),且已是本包的直接依赖(`packages/dsh-tauri-model/package.json:73`)与本包 src 里到处在 import 的入口(`ModelInputTypes.tsx:4` 等 13 处)。改成 `export type { JsonValue, RemoteFailure, RemoteResult, LlmModelDiscoveryRequest } from 'dsh-tauri-ui/client'`,`LlmDiscoveredModel` 换成 `interface LlmDiscoveredModel extends UILlmDiscoveredModel { inputModalities?: readonly string[] }`(本包只多这一个字段)。检索式:`JsonValue|RemoteFailure|RemoteResult|LlmModelDiscoveryRequest`(全仓)。 [packages/dsh-tauri-model/src/client/types/remotes.ts:1-10,52-57] (-14 LOC)++`delete: model-extras 的 MODEL_EXTRAS_KEYS —— 17 项字面量数组 + barrel 转出,唯一读者是它自己的测试。` 测试只是断言「每条 key 在字典里非空」,删 key 列表后该断言对 UI 无意义。检索式:`MODEL_EXTRAS_KEYS`(全仓,命中 translate.ts:4 声明、index.ts:9 转出、model-extras.test.tsx:7,59,60)。 [packages/dsh-tauri-model/src/client/ui/model-extras/translate.ts:4-21, packages/dsh-tauri-model/src/client/ui/model-extras/index.ts:9] (-19 LOC)++`yagni: createSettingsSchemaOperations —— 20 行工厂里 7 个成员全是纯转发 lambda(rehydrate/validate/nodeAtPath/getPath/hasPath/setPath/deletePath 逐个 `=> service.x(...)`),全仓唯一构造点是 register/models.ts:48。` 直接传 `ctx.settingsSchema`:`SettingsSchemaOperations = Pick<SettingsSchemaService, …>` 是结构类型,赋值即成立;工厂没有任何运行时行为可保留。检索式:`createSettingsSchemaOperations|SettingsSchemaOperations`(全仓)。 [packages/dsh-tauri-model/src/client/models/schema-operations.ts:10-20] (-11 LOC)++`delete: 同一批类型被声明两遍 —— ModelDiscoveryOutcome 在 service/model-config.ts:21 与 models/operations.ts:15 各写一份;ServiceLookup 在 models/remote.ts:3 与 models/settings-forms.ts:24 各写一份。` 各自只保留一份、另一处 import。检索式:`ModelDiscoveryOutcome`、`ServiceLookup`(全仓)。 [packages/dsh-tauri-model/src/client/models/operations.ts:15, packages/dsh-tauri-model/src/client/models/settings-forms.ts:24] (-10 LOC)++`delete: 三个只被自己的测试读到的导出 —— withPath(model-config.utils.ts:69-71,生产只用 withDetail/withCount/modelConfigNotice)、presetTableSize(model-presets.ts:42-44)、PRESET_FIXTURE 整个文件(model-preset-fixtures.ts:1-12,测试夹具却躺在 src/ 里、会被打进产物)。` `withPath` 直接删;`presetTableSize` 删(测试改成 `Object.keys(PRESET_FIXTURE).length`);夹具搬进 `model-presets.test.ts`。检索式:`withPath`、`presetTableSize`、`PRESET_FIXTURE`(全仓,三者的非测试命中数均为 0)。 [packages/dsh-tauri-model/src/client/service/model-config.utils.ts:69-71, packages/dsh-tauri-model/src/client/service/model-presets.ts:42-44, packages/dsh-tauri-model/src/client/service/model-preset-fixtures.ts:1-12] (-20 LOC)++`yagni: model-extras 的 *.types.ts 拆包 —— auto-config-all-button.types.ts(5 行,导出 AutoConfigAllButtonProps)与 model-fetch-config-button.types.ts(5 行,导出 ModelFetchConfigButtonProps)各自只被同目录的一个 .tsx 消费一次,再加 index.ts 一行转出。` 类型内联进对应 .tsx(`model-compat-fields.tsx:21`、`model-config-toolbar.tsx:21` 就是这么做的,格式本来就不统一)。 [packages/dsh-tauri-model/src/client/ui/model-extras/auto-config-all-button.types.ts:1-5, packages/dsh-tauri-model/src/client/ui/model-extras/model-fetch-config-button.types.ts:1-5] (-9 LOC, -2 files)++### dsh-tauri-experimental++`delete: 整个客户端「摘要重试调度」机器 —— 它唯一的 arm 开关(`awaitingTurn`)从来没被扳过。` `awaitingTurn` 只由 `service/summary.ts:38-49` 的 `expectTurn` 写入,而 `expectTurn` 全仓零调用方(检索式:`expectTurn`,命中 summary.ts:38 的声明与其文档;无任何 import);于是 `register/summary.ts:36-37` 的判定永远走 `forget/continue`,重试循环 20 行永不执行,`attempts`/`nextAt` 两个 Map 恒空。删除面:`register/summary.ts:23-53`、`service/summary.ts:32-49`、`session.types.ts:8-12` 的 `awaitingTurn`、`constants/index.ts` 的 4 个 `RUNNING_CHANGES_SUMMARY_*`、`utils/format.ts` 的 `summaryRetryDelayMs`(唯一调用点 register/summary.ts:49)。行为等价:`awaitingTurn` 恒为 `null` 时该循环就是 no-op。 [packages/dsh-tauri-experimental/src/client/register/summary.ts:23-53, packages/dsh-tauri-experimental/src/client/service/summary.ts:32-49, packages/dsh-tauri-experimental/src/client/store/modules/session.types.ts:8-12] (-62 LOC)++`delete: host/utils/paths.ts 的「撤销/回滚写盘」整块能力 —— assertSafeParents + removeCreatedPath + PathSafety 类型 + 三个为此存在的 reason 码,生产调用方 0。` 唯一消费者是 `paths.test.ts`(检索式:`removeCreatedPath|assertSafeParents|REASON_NON_EMPTY_DIR|REASON_UNSAFE_PATH`,非测试命中只有 `config/constants.ts:13` 的 import 自己、`paths.ts` 自身、以及 `shared/constants.ts:34` 的码值声明)。连带 `host/config/constants.ts:12-13,68-72` 与 `shared/constants.ts:34`。保留 `resolveInsideWorkspace`(retention.ts:81 在用)。注意 `REASON_WORKSPACE_CHANGED` 不在此列 —— capture.ts:136,149,376 真用。 [packages/dsh-tauri-experimental/src/host/utils/paths.ts:28-80, packages/dsh-tauri-experimental/src/host/utils/paths.types.ts:1-2] (-62 LOC)++`delete: 七个只被自家测试碰过的服务/工具成员。` 全部检索式均为「符号名 + 全仓」,非测试命中数为 0:+- `capture.begin` —— `capture.ts:88-93`,注释自己写着「这里保留合并形态」;只有 capture.test.ts(22 处)。(检索式:`capture.begin`)+- `capture.pending` —— `capture.ts:229-246`;只有 capture.test.ts(9 处)。(检索式:`capture.pending`)+- `snapshot.generation` —— `snapshot.ts:82-86`;只有 snapshot.test.ts:413,421。(检索式:`snapshot.generation`)+- `snapshot.read` —— `snapshot.ts:208-216`;只有 snapshot.test.ts:423。(检索式:`snapshot.read`)+- `retention.describe` —— `retention.ts:145-154`;只有 retention.test.ts:156,163。(检索式:`retention.describe`)+- `queue.size` —— `queue.ts:42,113`;只有 queue.test.ts(8 处)。(检索式:`\.size\(\)`)+- `lock.lockPath` —— `lock.ts:148` + `lock.types.ts:32-33`,注释自己写着「诊断与测试用」;只有 lock.test.ts(11 处)。(检索式:`\.lockPath`)++[capture.ts:88-93,229-246 / snapshot.ts:82-86,208-216 / retention.ts:145-154 / queue.ts:42,113 / lock.ts:148, lock.types.ts:32-33] (-56 LOC)++`shrink: src/client/types/index.ts 把两个路由的线上类型整套手写了一遍,而同一份形状已经由 src/client/apis/index.type.ts 生成。` 该文件被 `client/index.ts:23` 的 `export type * from './types'` 转出,属协议面 —— 保留对外名字,把 40 行声明换成 `export type { LiveSnapshot, TurnFileChange, TurnFileStatus, TurnSummary } from '../apis/index.type'` + 本文件仅留 `SessionSummary`/`LocaleKey` 的别名。检索式:`TurnFileStatus|TurnFileChange|SummaryPayload|LiveSnapshot`(全仓)。 [packages/dsh-tauri-experimental/src/client/types/index.ts:1-49] (-40 LOC)++`delete: CaptureLimits 这套「可注入上限」—— CaptureOptions.limits 的生产调用方 0,唯一注入点是 snapshot.test.ts:245,264。` 生产 `capture.ts:358` 只传 `{exclude, nestedDirs}`,于是 `snapshot.ts:107-111` 的 `options.limits?.x ?? MAX_*` 三行退化为常量,`types/index.ts:41-49` 的接口与 `:58` 的字段一起删。检索式:`CaptureLimits|limits\?\.`(全仓)。 [packages/dsh-tauri-experimental/src/host/types/index.ts:41-49,58, packages/dsh-tauri-experimental/src/host/service/snapshot.ts:104-111] (-16 LOC)++`delete: host/config/constants.ts 的 16 行「孤儿文档注释」—— 注释还在,被注释的常量早已不存在。` 具体行:`17`(快照 ref 前缀)、`39-43`(聚合字节/文件数/预扫排除/仓库容量四项上限)、`46-51`(资格探测超时、工作区缓存 TTL/条目上限、摘要文件上限、未纳入快照路径上限、实时刷新间隔六项)、`55`(PATH 无 git 的原因码)、`59-61`(快照文件数/聚合字节/超限文件三项原因码)。同文件现存声明只有 18 个(19/22/25/28/31/37/44/53/57/63/66/69/72/75/78/88/91/94 行),其余注释无对应代码。 [packages/dsh-tauri-experimental/src/host/config/constants.ts:17,39-43,46-51,55,59-61] (-16 LOC)++`stdlib: retention.measure 手写递归目录遍历(19 行 walk + 逐文件 stat),Node 20+ 的 fs.promises.readdir 自带递归。` 换成 `const entries = await readdir(dir, { recursive: true, withFileTypes: true }).catch(() => [])`,再对 `entry.isFile()` 取 `stat(join(entry.parentPath, entry.name)).size`(原本就 best-effort、每个 stat 各自吞异常)。函数名:`fs.promises.readdir(path, { recursive: true, withFileTypes: true })`(Dirent.parentPath)。 [packages/dsh-tauri-experimental/src/host/service/retention.ts:117-143] (-10 LOC)++`yagni: hookable 事件总线只服务一个自产自销的 hook —— runningChangesHooks 的唯一 emit 点是 capture.ts:181,监听方 0(只有 capture.test.ts:65,70 注册过)。` 该模块不在包入口(`src/index.ts` 只导出 `apply`,`package.json` 的 `exports` 只有 `.` 与 `./client`),仓外插件拿不到它。把 `await runningChangesHooks.callHook('turn:captured', …)` 换成直接调用/删掉这一行,`host/events/index.ts:1-9` 与 `hookable` 依赖一起退场。检索式:`runningChangesHooks|turn:captured|from 'hookable'`(全仓;其他包各自有自己的 hooks,与本包无关)。 [packages/dsh-tauri-experimental/src/host/events/index.ts:1-9] (-9 LOC, -1 dep)++`shrink: snapshot.ts:469 的 store.commonDir ?? await resolveSourceCommonDir(store.worktree) 是防御一个不可能发生的分支。` `snapshot.resolve` 的三个生产调用点里,`capture.ts:338` 传的 `probe.commonDir` 在 ok 分支上必然是 string;`resolveSourceCommonDir`(git.ts:98-108)除这一行外零调用方,`SnapshotStore.commonDir?` 的可选性也随之可以收紧。检索式:`resolveSourceCommonDir`(全仓,命中 snapshot.ts:469 与 git.ts 定义)。 [packages/dsh-tauri-experimental/src/host/service/snapshot.ts:469, packages/dsh-tauri-experimental/src/host/utils/git.ts:98-108] (-12 LOC)++`yagni: 客户端 store 的三层壳 —— store/index.ts 只包了一个成员、session.utils.ts 的泛型只有一个实例化形状、service/summary.ts 的 messageOf 只有一个调用点。` `store/index.ts:1-5` 的 `{ runningChanges }` 命名空间可以直接 export 那个 store(`store.runningChanges.$state` 的中间层消失);`session.utils.ts:17` 的 `<C extends { bySession: Record<string, unknown> }>` 收成具体参数类型;`messageOf`(summary.ts:53-56)内联进唯一调用点 summary.ts:28。 [packages/dsh-tauri-experimental/src/client/store/index.ts:1-5, packages/dsh-tauri-experimental/src/client/store/modules/session.utils.ts:17-24, packages/dsh-tauri-experimental/src/client/service/summary.ts:53-56] (-10 LOC)++## Considered and rejected++- `packages/dsh-tauri-model/src/client/models/styles.ts` 的 870 行哈希 CSS —— 看着像「上游 CSS 的复制品」,实际不是:`packages/dsh-tauri-model/THIRD_PARTY_NOTICES.md:49` 明写「Styling runs on this repo's css-render stack;upstream `.module.css` files are not copied」,`.zGbnIq_*` 的哈希名是为对齐上游 DOM 的 `className` 而保留。本仓没有第二份 `.zGbnIq_` 定义(检索式 `zGbnIq`;`packages/dsh-tauri-ui/src/client/components/action.tsx:1` 只是登记上游来源的注释),所以它是本插件唯一样式来源,不删。(可删的是上面那条:人工映射表 + 4 个死键。)+- `packages/dsh-tauri-model/src/client/models/styles.overrides.ts:1-39` —— `.{x}.{x}` 双写选择器提权到上游样式之上,是刻意的、也只 39 行,没有更短的可移植写法。+- `packages/dsh-tauri-model/src/client/models/locales.ts` 的 131 个 key —— 全仓逐个核对,**零未使用**(检索式:每个 key 在全仓 `.ts/.tsx` 的出现次数,统计脚本见下)。265 行不是冗余。+- `packages/dsh-tauri-model/src/client/service/model-presets.ts` 的 13 条家族正则表 + `FAMILY_RULES`/`GRADED`/`combine` —— 与 host 侧 litellm 表是两套互补来源(表命中就查表,未命中才退正则),不是重复实现。+- `packages/dsh-tauri-experimental/src/host/utils/lock.ts` 的 TCP 监听锁 —— 用内核持有的监听句柄做跨进程互斥、且**刻意不做 TTL 抢占**(`config/constants.ts:80-88` 有完整理由),Node 没有等价的跨进程锁原语,`native:` 不成立。+- `packages/dsh-tauri-experimental/src/host/utils/queue.ts` 的双闸设计(FIFO 尾链 + 锁超时预算 `waitDeadline`)—— `capture.ts` 真的两个都传,`waitDeadline` 不是死配置。+- `packages/dsh-tauri-experimental/src/host/utils/git.ts:66-71` 的 `child.stdin?.on('error', () => {})` —— 针对 Linux EPIPE 的已知 workaround,删了会偶发崩,保留。+- `packages/dsh-tauri-experimental/src/client/register/paste-collapse.types.ts` 的 13 个结构类型 —— 描述 `ctx.inject(['inputTriggers'])` 的跨包契约(`inputTriggers` 是协议面),虽然 5 个类型只在同文件内被引用,仍属对外形状,只算 export 关键字多余,不值得动。+- `packages/dsh-tauri-experimental/src/client/register/running-chip.ts:5,12` 的 3 处 `as never` —— 类型逃逸难闻,但换成正确的槽位泛型要引入跨包类型耦合,代价大于收益。+- `pathe` / `unstorage` —— 两者都是实验包 host 侧的真实实现依赖(`host/storage/index.ts:2-3`、`host/utils/lock.ts:23` 等),`fsAtomicDriver` 来自 `dsh-tauri` 而非本包手搓;`pathe` 提供 posix 语义的路径运算,正是 git 子进程需要的,`node:path` 在 Windows 上不等价。+- `packages/dsh-tauri-model` 的 `react-if-lite` devDependency + `tsdown.config.ts:6` 的 `noExternal` —— 已由 `docs/audit/dependencies.md:16` 记录在案,本文件不重复计数。+- `packages/dsh-tauri-model/package.json:42-52` 的 `dsh.client.inject` 与 `src/client/index.ts:17-26` 的 `inject` —— 名字撞车但语义不同:前者是客户端 bundle 的模块依赖(`@deepseek-ai/*` 包名),后者是内核服务名,不是同一份声明的两处副本。+- `packages/dsh-tauri-experimental/src/host/service/workspace.ts` 的 60s 缓存 + stale-while-revalidate —— 把 30s 的 git 资格探测从 pre-step 屏障上摘下来是这个设计的全部理由,不是为了抽象而抽象。++统计脚本(用于 locales / styles 的未使用 key 判定,`rg` 不在 PATH 时的替代):++```powershell+$files = git ls-files "packages/dsh-tauri-model/src"+$body = ($files | Where-Object { $_ -notmatch 'styles\.ts$' -and $_ -notmatch '\.test\.' } | ForEach-Object { Get-Content $_ -Raw }) -join "`n"+# 对每个候选 key 判 $body -notmatch "\b$k\b"+```++net: -456 lines, -2 deps possible.diff --git a/docs/audit/pkg-ssh-scheduler-notify-rightclick.md b/docs/audit/pkg-ssh-scheduler-notify-rightclick.mdnew file mode 100644index 00000000..b3dd6ac1--- /dev/null+++ b/docs/audit/pkg-ssh-scheduler-notify-rightclick.md@@ -0,0 +1,75 @@+# ponytail-audit · dsh-tauri-{ssh, scheduler, notification, rightclick}++> Scope:`packages/dsh-tauri-ssh` / `packages/dsh-tauri-scheduler` / `packages/dsh-tauri-notification` / `packages/dsh-tauri-rightclick` 的过度设计审查(level full)。只读审查,未改动任何被审查代码,未跑任何构建命令(只做静态阅读与只读 `git grep`)。+> 豁免:协议面按 `docs/audit/protocol-surface.md` 处理——凡从 `src/index.ts` / `client/index.ts` / `host/routes/index.ts` 出口、或经字符串通道(route `path`、Tauri command 名、slot 名、`ctx.effect` 标签、事件名)被引用者一律不判死;此类若内部确有冗余,写成 `keep:` 且**不计入 net**。正确性 bug / 安全 / 性能明确不在范围(仅必要时一句话注记)。+> 方法说明:对 ~70 个 ssh 导出名逐个跑了「定义行 / 非定义行」分离的 `git grep`(排除 `*.test.*`),除自设哨兵名外**没有任何 0 非测试消费者的导出**,故本报告不含「无人调用的函数」类发现,全部条目均为「有消费者但结构冗余」。+> 定位口径:`(-N LOC)` 是删掉该结构后净减少的行数(含随之消失的 import/空行),不含测试行数的二次收益。++## packages/dsh-tauri-ssh++- `delete: client/store/index.ts:172-200 / 203-231 / 234-259 / 335-369 四个手写 wire 解析器 machineEventsOf(29 行) + syncPreviewOf(29) + syncApplyResultOf(26) + machineRowOf(35). 把 this.callApi<unknown>(...) 的类型参数换成 host 响应类型后直接消费响应,删掉这四个函数及其校验分支. 证据:调用点 :634 / :814 / :844 全部写 `callApi<unknown>('machine.events'|'sync.preview'|'sync.apply')` 再手工 parse;同仓 scheduler 客户端(client/service/scheduler.ts:14-20)对同类生成物 wire 零运行时校验;且 host 侧 routes/index.ts 的 saveRowOf/listItemOf 已经校验过同一份数据。若坚持保留运行时校验,可用本包**已有依赖** `schemastery`(host/storage/index.ts:14 在用)声明式表达,仍远短于 119 行. (-119 LOC)`+- `shrink: client/styles/index.ts:22-110 的 cls 表 87 条手写字面量('rowCard': 'dshp-ssh-row-card' 这类). 键名保留为 as const 元组(类型仍是 keyof,错拼照样报错),值用派生式生成:'dshp-ssh-' + (k.replace(/([A-Z])/g,'-$1').replace(/(\d+)/g,'-$1')).toLowerCase(). 证据:pwsh 逐条比对 87 条(脚本用 -creplace 保证大小写敏感)→ entries=87 mismatches=0,span3→dshp-ssh-span-3、remoteIcon→dshp-ssh-remote-icon 均成立;cssr 侧 100 处 dshp-ssh- 字面量不动,语义不变. (-84 LOC)`+- `shrink: client/types/sync.ts:37-88 的 SshMachineEvent / SyncPluginItem / SyncSkillItem / SyncPreview / SyncItemResult / SyncApplyResult 与 host/types/index.ts:199 / 266 / 278 / 285 / 303 / 324 逐字同形(client 版仅把 stage 放宽成 string). 把这 6 个 wire 类型收进 src/shared/types.ts,两侧 import(src/index.ts 继续 re-export 以保住协议面),客户端文件退化成一行 re-export. 证据:client/types/sync.ts 的唯一消费者是 client/types/index.ts:42-52 的 re-export;两侧字段名可逐字对齐. (-50 LOC)`+- `native: client/store/index.ts:134-137 的 SnapshotStore<T> 与 :140-156 的 createSnapshotStore<T> 是平台已提供的原始件的手写副本. 改用 @deepseek-ai/dsh-client-store 的 createSnapshotStore / SnapshotStore;或按同仓另两个插件的做法改用 dsh-tauri/client 的 defineStore + useStore,顺带去掉机器/同步/外壳三处的 useSyncExternalStore 手接. 证据:git grep -n "createSnapshotStore" -- packages 命中 dsh-tauri-model/src/client/models/welcome-store.ts:2、store.ts:13+131、store.account.test.ts:9;dsh-tauri-notification/src/client/store/modules/settings.ts:2+5、dsh-tauri-scheduler/src/client/store/modules/prefill.ts:2+4 用 defineStore;ssh 包内 git grep "defineStore|useStore" 命中 0;useSyncExternalStore 出现在 machines-section.tsx:684、ssh-section.tsx:44、sync-panel.tsx:43. (-21 LOC)`+- `delete: client/utils/retry.ts:1-19 整个文件(retrySecondsOf 是单表达式 Math.max(0, Math.ceil((nextRetryAt - nowMs) / 1000)),19 行的模块只服务一个调用点). 把表达式内联进 machines-section.tsx:538 并删文件与 import. 证据:git grep -n retrySecondsOf -- packages/dsh-tauri-ssh/src 只命中定义行与 machines-section.tsx:538(另 :13 附近的 import)——单消费者、无测试引用. (-17 LOC)`+- `shrink: host/service/host-keys.ts:35-46 writeFileAtomic(async)与 host/storage/index.ts:178-189 writeStateFile(sync)是同一套原子写配方抄了两遍:mkdir(0o700) → `${file}.${randomBytes(6).toString('hex')}.tmp` → write(0o600, flag 'wx') → rename → 失败 rm. 抽一个同目录共享的原子写 helper,两处都调它. 证据:两段逐行对照,仅 fs/promises 与 fs 同步 API 之差;功能无差异. (-12 LOC)`+- `delete: host/apply.ts:105-111 传给 SshManager 的 emitStatus 钩子(唯一生产实现是空函数体,注释自述「no live consumers」)+ manager.ts:83 的 deps 声明 + manager.ts:955 的调用. 删掉钩子,状态一律走 settings 页轮询 /api-ssh. 证据:git grep -n emitStatus -- packages/dsh-tauri-ssh/src 命中 apply.ts:108(真实实现为空)、manager.ts:83/955、bootstrap.e2e.test.ts:114(测试传空函数)、manager.test.ts:313(测试自记一份)——即无生产消费者,删后测试里那两处也可一并去掉. (-7 LOC)`+- `yagni: host/service/events.ts:29 构造参数 capacity(外加 :25-28 的 JSDoc). 生产端恒用默认值,改成模块级常量 EVENT_RING_CAPACITY 直接引用;裁剪逻辑用默认容量即可覆盖(现有测试 events.test.ts:65-67 就是这么测的). 证据:git grep -n "new SshMachineEvents(" 命中 apply.ts:88(无参)、routes/index.test.ts:23、manager.test.ts:299、bootstrap.e2e.test.ts:107、events.test.ts 多处——只有 events.test.ts:53 传了 3. (-5 LOC)`+- `delete: client/locales/index.ts 的 hero.loadFailed(:12 与 :137)与 log.title(:66 与 :191),zh + en 各一份. 删这 4 行. 证据:pwsh 从 locales 文件抽键集合,与 git grep -n -o -E "'[A-Za-z][A-Za-z0-9._]*'" -- packages/dsh-tauri-ssh/src(剔除 /locales/ 路径)求差 → keys=118 deadKeys=2;逐键复核 git grep -c "'hero.loadFailed'" 等 occ=2(仅 zh/en 定义处,无任何 t(...) 调用点). (-4 LOC)`+- `shrink: client/store/index.ts:159 与 client/components/machines-section.tsx:549 各有一份逐字相同的 messageOf(error)(error instanceof Error ? error.message : String(error)). 留一份导出给两处用(scheduler 的 client/service/scheduler.ts:100 是第三份,见该包). 证据:两处代码逐字相同;git grep -n "function messageOf" -- packages 命中 3 处. (-3 LOC)`+- `shrink: client/constants/index.ts:33 的 SSH_API_PATH = '/api-ssh' 与 src/shared/constants.ts:16 的 SSH_API_PREFIX = '/api-ssh' 同值同名不同家;client/components/machines-section.tsx:13 的 DEFAULT_REMOTE_PORT = 3080 又与 host/storage/index.ts:18 重复(host 侧同值还散在 apply.ts:177、routes/index.ts saveRowOf 的默认值里). 按 docs/specs/plugin.baisc.md 的跨侧归属:SSH_API_PREFIX 与 DEFAULT_REMOTE_PORT/DEFAULT_SSH_PORT 收进 src/shared/constants.ts,客户端 import. 证据:git grep -n "SSH_API_PATH|SSH_API_PREFIX|DEFAULT_REMOTE_PORT" 显示两侧各写一份;route path 字面量例外不适用于这类数值/前缀常量. (-2 LOC)`+- `shrink: host/service/plugins-sync.ts:36-37 自己声明 const REMOTE_ROOT = '.dsh-desktop'(注释自述 mirrors bootstrap REMOTE_ROOT). 改成从 './bootstrap' import(host/service/manager.ts:24 已经这么做). 证据:bootstrap.ts:32 export const REMOTE_ROOT = '.dsh-desktop',plugins-sync.ts:39/193/194/198 用同一值;两处一旦漂移就是远端路径错配. (-1 LOC)`+- `shrink: host/service/sync.ts:29 const REMOTE_PLUGIN_PROFILE = DEFAULT_REMOTE_PROFILE(纯同值别名). 直接用 DEFAULT_REMOTE_PROFILE. 证据:git grep -n REMOTE_PLUGIN_PROFILE 只命中 sync.ts:29 定义与 sync.ts:119 的默认参数. (-1 LOC)`+- `keep: host/routes/index.ts:40-53 的 13 个 SshApiMethod 字面量与 :156 createSshApiHandler 的分派、:343-405 的 payload 解析器(machineIdOf/saveRowOf/secretsOf/pluginRefsOf/skillRefsOf)保留;其内部 saveRowOf 的 22/3080 内联默认值可收敛到 src/shared/constants.ts 的常量. (keep,不计 net)`+- `keep: host/apply.ts:56 SshRemoteService 类、src/index.ts 的 barrel(apply/Config/default/inject/name/SshRemoteService 与 4 个类型 re-export)、client/service/bridge.ts:9-12 的两个 Tauri command 名、client/constants 的 slot/样式 ID 保留——均为协议出口,仓内调用方多少与死活无关. (keep,不计 net)`++ssh 小计:**-326 行**(13 条)。++## packages/dsh-tauri-scheduler++- `delete: client/locales/index.ts 的 20 个死键(zh 与 en 各一份,共 40 行):active、followGlobal、loading、menu.aria、module、moduleDefault、perDay、perWeek、perWorkday、providerDefault、refresh、sort、sortCreatedAsc、sortCreatedDesc、sortPlannedAsc、sortPlannedDesc、triggerManual、triggerSchedule、wakeHint、workspaceDaily(zh 侧 :9-15、:60、:66-69、:73、:81、:102-104、:122-124,en 侧 :134-140、:185、:191-194、:198、:206、:227-229、:247-249). 键与两种语言的文案一并删;这些是已消失的排序菜单 / 触发来源列 / 按天-按周标签的残骸. 证据:pwsh 抽键后与「排除 /locales/ 路径后的全部字符串字面量」求差 → keys=120 deadKeys=20;逐键 git grep -c "'sort'" 等全部 occ=2(仅 zh/en 定义处);另单独核过动态调用点 t(WEEKDAY_KEYS[day]) / t(STATUS_KEYS[...]) / t(PERMISSION_LABEL_KEYS[...]) / t(rec.nameKey) / t(errorKey)——其值都来自带字面量的映射表,不在死键集合内. (-40 LOC)`+- `shrink: client/types/index.ts:15-19 / 21-25 / 27-30 / 32-39 / 41-45 的 PermissionOption / ModelReasoningEffort / ModelReasoning / ModelOption / ModelCatalogFailure 与生成物 client/apis/index.type.ts:30-56 逐字同形(仅 readonly 与 Array<> 之别),而 client/types 里其余类型是真正的客户端视图. 删这 27 行,改成从 '../apis/index.type' re-export 这几个 wire 类型. 证据:两文件逐字段比对(provider/providerLabel/model/label/description/reasoning 完全一致);service/scheduler.ts:2-13 本来就从 '../apis' 引入并已在依赖生成物. (-27 LOC)`+- `shrink: client/components/recommendations.tsx:22-41 的 2 个条目各自同时带 schedule 字面量与 form(t) 工厂,而 form 内部把同一份 schedule 又抄一遍(如 form: t => ({ name: t('recReviewName'), schedule: { kind: 'weekly', weekdays: ['FR'], time: '16:00' }, prompt: t('recReviewPrompt'), ... })). 条目只留 id/nameKey/promptKey/schedule/accent/icon,form 由一个共享 builder 按这三项生成. 证据:每个条目的 schedule 与 form().schedule 字面量重复一次(2 处);TaskFormState 其余字段全是常量默认值. (-9 LOC)`+- `delete: client/register/hydrate.ts:1-7 整个文件(只把一次性的 void recoverScheduler() 包成 defineRegister 中间层). 把这一行挪进 client/index.ts 的 apply(与 :25 现有 effect 同处),删文件与 import. 证据:git grep -n hydrateFeature 只命中定义行与 client/index.ts:12、:25 两处——单调用方的 register 层,违反 docs/specs/devlopment.md 的零中间层. (-7 LOC)`+- `delete: client/hooks/use-scheduler.ts:1-6 整个文件(useScheduler() 只是 return useStore(store.scheduler)). 组件内直接 useStore(store.scheduler),删文件与 import. 证据:git grep -n useScheduler 只命中定义行与 scheduler-panel.tsx:8(import)、:41(调用)——单消费者中间层. (-7 LOC)`+- `delete: host/types/index.ts:89-90 的 SchedulerTask.module? / agentPreset?(以及生成物 client/apis/index.type.ts:71-72 与 client/types/index.ts:58 的对应行)无可达写入点;executor.ts:72 的 const agentPreset = task.agentPreset?.trim() || SCHEDULER_AGENT_PRESET 因此恒为 'standard'. 删字段,executor.ts:72/80/207/214/217 直接用 SCHEDULER_AGENT_PRESET. 证据:task.ts:137 的 OPTIONAL_FIELDS 不含这两项、update-task.ts 的 TEXT_FIELDS 不含、host/routes/index.types.ts 的 TaskCreateBody/TaskUpdateBody 不含;module 全仓只出现在类型声明与 locale 键里(无任何读取). (-5 LOC)`+- `delete: host/utils/session-title.ts:1-3 整个文件(schedulerSessionTitle(taskName) 是恒等函数). executor.ts:237 直接 title?.rename?.(session, taskName),删文件与 :18 的 import. 证据:git grep -n schedulerSessionTitle 只命中定义行与 executor.ts:18、:237——单消费者且无变换. (-4 LOC)`+- `shrink: host/service/task.ts:161-163 的 merge(current, patch) 只是 return defaults({}, patch, current). 调用点 :39 直接写 defaults({}, patch, current)(或对象展开),删掉这个单调用点包装. 证据:git grep -n "merge(" -- packages/dsh-tauri-scheduler/src/host 只命中定义与 :39. (-4 LOC)`+- `delete: client/store/modules/prefill.types.ts:1-3(PrefillState 只被同目录 prefill.ts:1 的 type import 用). 把 interface 移进 prefill.ts(同侧单文件消费的常量/类型归属规则). 证据:git grep -n PrefillState 只命中 prefill.types.ts:1 与 prefill.ts:1、:5. (-3 LOC)`+- `yagni: client/components/schedule.utils.ts:61-63 的 isTaskPaused(task) 只返回 !task.enabled. 调用点 scheduler-panel.tsx:161 直接写 paused={!task.enabled},删函数. 证据:git grep -n isTaskPaused 只命中定义行与 scheduler-panel.tsx:13(import)、:161(调用). (-3 LOC)`+- `native: 11 个文件里的 lodash-es 调用点(executor.utils.ts:2、options.ts:3、recovery.ts:2、runs.ts:3、scheduler.ts:3、task.ts:4、utils/agent-runtime.ts:2、utils/schedule.ts:3、utils/waiting.ts:2、routes/history/get.ts:4、routes/tasks/get.ts:4)换成原生:filter/map/find/isEmpty/isString/isNil/isArray/isObject/isFinite/isInteger/isFunction 有同名 Array/typeof/Number.isFinite 等价物,orderBy→sort、takeRight(_,200)→slice(-200)、take(_,n)→slice(0,n)、uniq/sortBy→Set 去重 + sort、castArray(x)[0]→Array.isArray 判断、head→[0]、isEqual→Object.is. 行数基本持平——只有 runs.ts:isRun 与 task.ts:isTask 两处 conformsTo 需要改写成手写形状校验(约 +10 行),与删掉的 11 行 import 相抵;**真正的收益是删掉 lodash-es 与 @types/lodash-es 两个依赖**. (0 LOC,-2 deps)`++scheduler 小计:**-109 行**(10 条),另 -2 deps。++## packages/dsh-tauri-notification++- `delete: client/register/notify.ts:339 的 let statusAttached = false、:350 的 statusAttached = true、:355 的 void statusAttached. 三行全删(写进去只为了被 void 掉,没有任何读取分支). 证据:git grep -n statusAttached -- packages/dsh-tauri-notification/src 只有这 3 处命中. (-3 LOC)`+- `delete: client/types/index.ts:24 的 SessionSummaryFace.updatedAt、:53 的 PendingQuestionFace.multiSelect、:86 的 PendingInteractionFace.callId、:98 的 SessionStatusFace.completionUnread. 删这 4 个字段(结构面只留真正被读的成员). 证据:逐字段 git grep -n -E "\b字段名\b" -- packages/dsh-tauri-notification/src 剔除 types/index.ts 与 *.test.* 后 0 命中;同文件其余字段(toolName/reason/answerable/detail/header/silent/requireInteraction/displayReason…)均有命中,故只列这 4 个. (-4 LOC)`+- `keep: client/types/index.ts 头部自述「只声明结构类型…用最小结构面读取」(官方 dsh-client-ui 系列包不在本仓依赖内)、client/service/sound-assets.ts:15-16 的 SOUNDS_REQUEST_MESSAGE/SOUNDS_MESSAGE 桥消息名、以及 client/index.ts:8/14/16 的 name/inject/apply 出口保留——结构面与字符串通道都是协议. (keep,不计 net)`++notification 小计:**-7 行**(2 条)。除此之外这个包是干净的连线层,注释里给出的理由(内嵌 WebView2 原生 confirm 不随主题、原子写、Windows toast 静音标志)都站得住,不编发现。++## packages/dsh-tauri-rightclick++- `native: 12 处 lodash 别名(client/register/locate.ts:7 的 compact/filter/find/includes/map、client/register/official-menu.ts:2 的 find、client/register/context-menu.menu.ts:9 的 reject、client/service/menu.ts:9 的 difference/filter/get、client/service/registry.ts:3 的 sortBy、client/utils/url.ts:1 的 includes)与 2 处直连(host/routes/open/path/post.ts:4 的 isEmpty/isString/trim、host/routes/open/url/post.ts:4 的 get)换成原生:compact→filter(Boolean)、map→map、filter→filter、find→find、includes→includes、reject→filter(x => !f(x))、difference→filter + Set、get(o,'url')→o?.url、sortBy→[...].sort((a,b)=>f(a)-f(b))、isEmpty/isString/trim→trim() + typeof;host 侧三连判空可收成一处 typeof 判断. 删掉 lodash-es 与 @types/lodash-es 两个依赖. 证据:git grep -n "from 'lodash-es'" -- packages/dsh-tauri-rightclick/src 命中 2 行(host 路由);git grep -n "dsh-tauri/client'" 显示 6 个客户端文件从这里取别名(同一份 lodash 再导出);无一处用到 lodash 的独有能力(深比较、防抖、复杂迭代)——全部等价于原生一行. (-8 LOC,-2 deps)`+- `delete: client/types/index.ts:14 的 export type SessionSummaryLike = SessionSummary 与 :27 的 export type WorkspaceViewLike = WorkspaceView(纯同类型别名). 直接用被导入的 SessionSummary / WorkspaceView,删这 2 行并替换引用(引用点共 15 处,改名不改行数). 证据:两行右侧就是同文件 :2-9 导入的同名类型,别名不携带任何附加约束(同文件其余 *Like 别名都带 Pick/& 收窄,不是这一类). (-2 LOC)`+- `keep: client/types/index.ts:62 的 ContextMenuEventDetail 与 client/service/registry.types.ts 的 ExtensionRegistry、client/constants/index.ts 的 CONTEXT_MENU_EVENT/EXTENSIONS_REGISTRY_KEY 保留——仓内 0 引用但均为跨插件字符串通道(globalThis 注册表键与 CustomEvent 名)的载荷形状,第三方插件在仓外消费. (keep,不计 net)`++rightclick 小计:**-10 行**(2 条),另 -2 deps。++## Considered and rejected(看过但认为不该动)++- `packages/dsh-tauri-ssh/src/client/components/machines-section.tsx`(1023 行):EditPanel(:136) 与 AddMachineDialog(:569) 是两套机器字段表单(同一批 name/host/port/user/remotePort/profileName 字段),合并成一个受控表单能省 ~40 行,但两处的状态模型不同(Draft 缓冲 + 脏值/密钥状态 vs 局部 useState + id 自动派生 freeIdOf/slugOf),合并会把 id 派生与密钥态耦进同一个组件——收益不值这个风险,故不计入 net。+- `packages/dsh-tauri-ssh/src/host/routes/index.ts:110 readBody` 的 64KB 上限与 :97 isLoopbackPeer、:132 SHELL_ORIGINS CORS:属信任边界与前置拦截,按协议豁免清单与 ponytail 规则不简化。+- `packages/dsh-tauri-scheduler/src/host/config/runtime.ts:8 withWriteQueue`(5 行手写串行队列,2 个同侧消费者 task.ts:101/113、runs.ts:23/35)与 rightclick 的 `host/service/mutation-queue.ts`(16 行)、`host/service/opener.ts` 的 `warn` 薄封装:都是「一次交互不能并发拉起多个写入/OS 打开」的显式串行化,注释给了理由,保留。+- `packages/dsh-tauri-rightclick/src/client/register/official-menu.ts:33` 的双 `requestAnimationFrame` 等待(带 `// keep:effect` 注释)与 `src/client/service/registry.ts` 的 globalThis 注册表:前者是官方按钮 hover 后渲染的既知时序,后者是跨插件协议。+- `packages/dsh-tauri-notification/src/client/service/sound-assets.ts` 的桥消息握手、`client/register/settings.ts`、`client/register/notify.ts`:只做静态阅读,未发现可证明的冗余;该包 29 个 locale 键 0 死键。+- 三个包的 locale 表(notification 29 / rightclick 69)经脚本比对无死键;只有 scheduler 20 个与 ssh 2 个是死的(已列)。++## 覆盖度(诚实交代)++- 逐行通读:ssh 的 `src/index.ts`、`src/shared/constants.ts`、`client/index.ts`、`client/constants/index.ts`、`client/types/**`、`client/styles/index.ts`、`client/components/ssh-section.tsx`、`client/service/bridge.ts`、`client/utils/{retry,error}.ts`、`host/service/host-keys.ts`、`host/service/events.ts`;host/apply.ts、host/routes/index.ts、client/store/index.ts、client/components/machines-section.tsx、host/storage/index.ts 读了大部分(解析器、构造器、方法体、表单区段)。+- 只做声明面扫描(`git grep` 导出清单 + 逐名消费者计数),未逐行精读:ssh 的 `host/service/{manager,transport,bootstrap,sync,ssh-config,allowlist,plugins-sync,version,assets,sync-local,boot-html}.ts`、`client/components/sync-panel.tsx`、`client/locales/index.ts`、`client/styles/index.cssr.ts`(后面两个用脚本核过键/类名)。这几个文件里可能还有未发现的行数级冗余,但**没有**「导出但无消费者的函数」(已用专门脚本证明),故未列推测性条目。+- 另:`packages/dsh-tauri-ssh/package.json` 把 `yaml`(被 `host/service/allowlist.ts:21` 运行时 import)声明在 `catalog:testing` 分组——这是依赖归属问题,不是行数问题,交给 `dependencies.md` 口径处理。++net: -452 lines, -4 deps possible.diff --git a/docs/audit/pkg-ui-extension.md b/docs/audit/pkg-ui-extension.mdnew file mode 100644index 00000000..72290e41--- /dev/null+++ b/docs/audit/pkg-ui-extension.md@@ -0,0 +1,74 @@+# packages/dsh-tauri-ui + dsh-tauri-extension — ponytail-audit++> Scope: packages/dsh-tauri-ui, packages/dsh-tauri-extension · ~12k LOC · read 2026-09-30++Over-engineering only. Protocol/bridge surface (`useListen*`, `useInvoke*`, `defineAdapter`, IPC command names, route paths, slot names, effect/constant entries, entrypoints) is never proposed for deletion; where it is unused in-repo it is tagged `keep:`. Vendored `packages/dsh-tauri-extension/skills/**` (third-party) and generated code were not audited.++## Findings (ranked, biggest cut first)++`shrink:` `UI_COMPONENT_REGISTRY`'s 19 `reforkVariant(...)` rows (registry.ts:90-209) each repeat `package` / `availableAt` / `upstreamPath` / `mappedClass` on 7 lines; a 6-field tuple table plus the existing mapper emits the same `UiComponentEntry[]`. [packages/dsh-tauri-ui/src/client/components/registry.ts:90-209] (-110 LOC)+ - Only consumer: the dev playground (`packages/dsh-tauri-ui-playground/src/client/ui/components-playground/ui-components.tsx:1,25,66,222,227`). Search string: `UI_COMPONENT_REGISTRY|UiComponentEntry`. `THIRD_PARTY_NOTICES.md:18` is prose only.++`stdlib:` `rmtree`'s `clearReadOnly` hand-walks the tree chmod-ing dirs `0o777` / files `0o666` with per-call try/catch; `chmodSync(path, 0o777, { recursive: true })` is the Node API for exactly this. [packages/dsh-tauri-extension/src/host/service/rmtree.ts:20-48] (-24 LOC)++`shrink:` `clearReadOnly`'s three sibling MCP scanners `scanClaudeMcp` / `scanCursorMcp` / `scanGeminiMcp` are the same `existsSync → JSON.parse (try/catch) → isObject(parsed.mcpServers) → compact(Object.entries(...).map(map…))` block three times; one `scanJsonMcp(home, file, agent, mapper)` covers all three (the two mappers `mapMcpServersEntry` / `mapAgentEntry` stay). [packages/dsh-tauri-extension/src/host/service/agents.ts:106-154] (-20 LOC)++`keep: Card.Header / Card.Icon / Card.Content / Card.TitleRow / Card.End 保留;其内部 tv slot 可按需收敛。` — 仓内确无调用方(search string: `Card\.(List|Header|Icon|Content|TitleRow|Title|Description|End)` → 全仓命中只有 `Card.List` / `Card.Title` / `Card.Description`,位于 extension `skills-tab.tsx:247,254,258`、`mcp-tab.tsx:346,350,355`、`mcp-import-dialog.tsx:68,73`、scheduler `task-card.tsx:99,103`、`runs-tab.tsx:41,56,61`、`scheduler-panel.tsx:153`),但 `Card` 是 `Object.assign(CardBase, {...})`(`packages/dsh-tauri-ui/src/client/components/card.tsx:37`),经 `components/index.ts` → `packages/dsh-tauri-ui/src/client/index.ts:17` 出口,且 `dsh-tauri-ui/client` 是**跨包公共 UI 面**(`packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx:5`、`mcp-import-dialog.tsx:4` 等直接 import `Card`)⇒ 删成员即收窄出口契约,按 `docs/audit/protocol-surface.md` §1 不计入 net。(Lead 复核修正:原为 `delete:` -20。)++`shrink:` `mcp-tab.tsx` and `skills-tab.tsx` are the same remote-resource UI written twice: the load effect (`mcp-tab.tsx:38-57` ≈ `skills-tab.tsx:45-62`), the outcome `Notice` block (`mcp-tab.tsx:322-327` = `skills-tab.tsx:224-229`), the error-text builder `` `${t('failed')}: ${error instanceof Error ? error.message : String(error)}` `` (`mcp-tab.tsx:50,73,93,107,237,254`, `skills-tab.tsx:55,100,130,148,156,164,191`), and skills-tab's two polling loops (`refreshUntil` 77-91 vs the inline `IMPORT_REFRESH_DELAYS_MS` loop 184-189). Four small shared helpers (`OutcomeNotice`, `failText(t, error)`, `useRemoteResource`, one `pollUntil`) collapse all of it. [packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx, .../skills-tab.tsx] (-40 LOC)++`shrink:` `new-session.ts` is two ~20-line features that differ only in the button matcher (`newSessionButtonFrom` vs `ungroupedCreateButtonFrom`) and one warn string; one factory taking `(matcher, warnText)` emits both. [packages/dsh-tauri-ui/src/client/register/new-session.ts:14-36,44-66] (-20 LOC)++`yagni:` `market-tab.tsx` is a file whose whole body is `return <>{market.render({ preferredSubsectionId: 'installed' })}</>`; inline it at the one call site. [packages/dsh-tauri-extension/src/client/components/market-tab.tsx:15-17, used at .../extension-panel.tsx:27-33] (-14 LOC)++`delete:` `SettingsSidebarProps` is declared but never read — the component is `SettingsSidebar(_props)` and touches no prop; and `useWorkspaces?: unknown` is declared in two prop interfaces and never read. [packages/dsh-tauri-ui/src/client/ui/settings-sidebar.tsx:21-24,39, packages/dsh-tauri-ui/src/client/ui/settings-trigger.tsx:37 with `SettingsTrigger({ wide, useSessions })` at :45] (-6 LOC)+ - Search string: `useWorkspaces` → only those two declarations plus the real use in `ui/hero-workspace.tsx:45` / `ui/hero-workspace.types.ts:27`.++`shrink:` `loadSections` / `loadOnboardingSteps` are `async` with no `await` in either body; drop `async` and the two `void` at the call site. [packages/dsh-tauri-ui/src/client/service/sections.ts:7,14, callers packages/dsh-tauri-ui/src/client/register/sections.ts:8-9] (-6 LOC)++`shrink:` `useMountStyle`'s `disposerRef` retread is what `useEffect` cleanup already gives: `useEffect(() => mountStyle(cnode, id, owner), [cnode, id, owner])`. [packages/dsh-tauri-ui/src/client/hooks/use-mount-style.ts:6-12] (-6 LOC)++`shrink:` `PlatformModuleLoader` (ui) and `PlatformPluginLoader` (extension) are line-for-line copies of `HostPluginLoader`, already exported from `dsh-tauri`'s root. `import type { HostPluginLoader } from 'dsh-tauri'` deletes both. [packages/dsh-tauri-ui/src/host/types/index.ts:5-8, packages/dsh-tauri-extension/src/host/service/provider.types.ts:1-4, source packages/dsh-tauri/src/host/types/harness.ts:47-50 re-exported at packages/dsh-tauri/src/index.ts:28] (-8 LOC)++`shrink:` `SessionResumeResponse` / `UngroupedResponse` are hand-written twice, once per side of the wire; `src/shared/` exists for exactly this. [packages/dsh-tauri-ui/src/client/apis/index.type.ts:3-12 vs packages/dsh-tauri-ui/src/host/routes/index.types.ts:1-4] (-6 LOC)++`shrink:` `startProvider` exists only to `void remountProvider(); return clearHostRuntime` for its single caller one line above. [packages/dsh-tauri-extension/src/host/apply.ts:41-44, caller :32] (-5 LOC)++`shrink:` `restartHost` declares `Promise<{ ok: boolean, error?: string }>` and returns `{ ok: true }` on all three paths; the only caller is `void restartHost()`. Return `Promise<void>`. [packages/dsh-tauri-extension/src/client/service/restart.ts:4-14, caller packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx:265] (-5 LOC)++`shrink:` `profile.peek(name)` is a one-line alias of `profileDir(name)` from the same package's utils; the service adds nothing. [packages/dsh-tauri-extension/src/host/service/profile.ts:13-15, caller packages/dsh-tauri-extension/src/host/apply.ts:31] (-4 LOC)++`shrink:` `localButton`'s `size: { md: '', sm: '' }` variants are empty strings that exist only so the single `compoundVariants` entry can match `size: 'sm'`; inline that clause on `variant === 'danger' && size === 'sm'`. [packages/dsh-tauri-ui/src/client/components/button.tsx:23,26] (-3 LOC)++`shrink:` the host writes only `scope` (`host/service/mcp.ts` list path), never `layer`; both client expressions carry a dead fallback. [packages/dsh-tauri-extension/src/client/components/mcp-tab.tsx:347,351, field at packages/dsh-tauri-extension/src/host/routes/index.types.ts:72] (-2 LOC)++`delete:` `@deepseek-ai/cordis` is a devDependency with zero imports anywhere in the package; the `cordis.patch.yml` bundle patch is a separate `dsh.bundle` field and stays. [packages/dsh-tauri-extension/package.json:71] (-1 dependency)+ - Search string: `cordis` → only `package.json:71`, `THIRD_PARTY_NOTICES.md:40`, `host/config/constants.ts:9` (the file name string), `host/service/mcp.utils.test.ts:57` (a filename).++`keep:` `SEAT_EFFECT` and `TURN_NAVIGATION_LABEL_ZH/EN` + `TURN_NAVIGATION_SELECTOR` + `TURN_NAVIGATION_SLOT_SELECTOR` have no in-repo reader (search strings `SEAT_EFFECT`, `TURN_NAVIGATION_` → definitions only), but they are entries in the plugin's public constants module. [packages/dsh-tauri-ui/src/client/constants/index.ts:55,65-68]++`keep:` `restartNeeded` is hard-coded `true` by six routes and never read by the TS client, but the e2e suite asserts it. [packages/dsh-tauri-extension/src/host/routes/index.types.ts:89,95,100,116; writers mcp/get.ts:7, mcp/post.ts:22, mcp/delete.ts:21, mcp/toggle/post.ts:22, mcp/copy/post.ts:28, import/apply/post.ts:45; asserted at test/e2e/plugins/dsh-tauri-extension.e2e.ts:32,51,115,371]++`keep:` `src/client/types/remotes.ts` (24 LOC) restates five types that already exist verbatim in `packages/dsh-tauri-model/src/client/types/remotes.ts:1-19` and has no in-repo consumer — but it is re-exported from the package's client entrypoint. [packages/dsh-tauri-ui/src/client/types/remotes.ts:1-24, re-export packages/dsh-tauri-ui/src/client/index.ts:18]++`keep:` `stepSegment` is exported but has exactly one caller, in the same file, and no test. [packages/dsh-tauri-ui/src/client/components/segmented-control.tsx:37, internal call :70]++## Considered and rejected++- `packages/dsh-tauri-ui/src/client/styles/index.ts` — 2205 lines of generated Tailwind v4.1.11 in one template literal, but it is generated output of `scripts/taiwindcss.ts` (excluded category), and its only consumer is `register/styles.ts:12`.+- `utils/style.ts` `mountCounts` refcount — load-bearing: `useMountStyle` mounts the same cnode from independent component instances (playground `ui-components.tsx:26,92`, experimental `running-changes-chip.tsx:10,20`).+- `components/official.tsx` (112), `components/icons.tsx` (49), `components/index.ts` — re-export barrels with a documented constraint (only members present in both `0.1.5-rc.1` and `0.1.7-*` may be forwarded, else React #130).+- `components/checkbox.tsx`, `components/dot.tsx` — reforked copies of upstream members added in 0.1.7; needed while the 0.1.5 kernel is supported.+- `Select` props `icon` / `chevron` / `variant` — exercised by the playground, and `variant="composerTrigger"` is used in production (`dsh-tauri-scheduler/.../task-create-dialog.tsx:318,325`, `dsh-tauri-model/.../model-config-toolbar.tsx:67`).+- `Action` variants `search|model|round|row|help` — only the playground renders them, but they are the documented refork surface for the official buttons.+- `Button` variants `add` / `addGhost` / `elevated` — used outside this package (`dsh-tauri-scheduler/.../scheduler-panel.tsx:103,106`); `Chip.badge` used at `dsh-tauri-scheduler/.../model-picker.tsx:185`.+- extension `locales/index.ts` (234 lines, 113 keys ×2) — every suspect key resolves to a caller (`importIntro` mcp-import-dialog:30, `editorJsonTab`/`formatPaste` mcp-editor-form:38,47,57, `scopeAll`/`checkLabel`/`checkRunning` mcp-tab:305,362, `transportStdio` mcp-editor-form:27, `restartConfirmBody` mcp-tab:427, `skillUserOnly`/`skillModelOnly` via `policyTag` skills-tab.utils.ts:10-12). No dead keys.+- extension `client/apis/index.ts` wrappers with no caller (`postMcpCopy`:34, `getRoots`:64, `deleteRoots`:74) — swagger-generated file; the routes are protocol surface.+- `host/service/tar.ts` (146 lines hand-rolled ustar/gzip reader) — no tar/unzipper dependency exists anywhere in the workspace catalog, so this is a deliberate zero-dep implementation.+- extension `register/settings.ts:53-100` `publishLauncherShortcut`/`shortcutOf`/`CatalogLike` — has a real consumer (`ui/settings-trigger.tsx` forwards `settingsShortcut` into `SETTINGS_LAUNCHER_SLOT`).+- `registry.ts:60-88` primitives rows — one line per member, already minimal; only the `reforkVariant` rows are worth collapsing.+- `styles/global.cssr.ts`, `ui/hero-workspace.cssr.ts`, `register/obstructions.ts`, `register/composer-resume.ts` — host-UI override logic keyed to official class suffixes; the size is the compatibility surface, not dead weight.++## net: -265 lines, -1 dependency possible.++> Lead 复核修正:原 net -285 含 `Card.*` 五成员删除(-20),已按协议面出口契约降级为 `keep:`(见上),不计入 net。findings 计数相应为 17 条裁剪 + 5 条 `keep:`(原 18 + 4)。diff --git a/docs/audit/pkg-worktree-archive-pet.md b/docs/audit/pkg-worktree-archive-pet.mdnew file mode 100644index 00000000..3ce3d517--- /dev/null+++ b/docs/audit/pkg-worktree-archive-pet.md@@ -0,0 +1,59 @@+# packages/dsh-tauri-worktree + dsh-tauri-archive + dsh-tauri-pet — ponytail-audit++> Scope: packages/dsh-tauri-worktree, dsh-tauri-archive, dsh-tauri-pet · ~13k LOC · read 2026-09-30++搜索证据说明:本机 `rg` 不在 PATH,零引用证明统一用 harness grep 工具(ripgrep 内核)+ `git ls-files`,范围排除 `node_modules` / `dist`,每条的检索串写在括号里。++## Findings (ranked, biggest cut first)++- `shrink:` `handoff.complete` 把 `createInherited` 整个函数体抄了一遍(presets/seed/meta/inheritedEventCount/agentOptions/setup/agents.create/resolveByPath+attachSession/pendingWorktreeTitles),只多一句 followup。改成 `createInherited(sourceSession.id, { cwd: binding.worktreePath, parentSession: sourceSession.id, targetSessionId, attach: true })` 后再发 followup;`createInherited` 已经收 `targetSessionId`,只需把 agent handle 一并返回。 [packages/dsh-tauri-worktree/src/host/service/handoff.ts:73-119] (-45 LOC)+- `yagni:` cleaner 的进程内退避重试阶梯(`RETRY_BACKOFF_MS` 17、`timers` 22、`clearRetry` 148-154、`backoffOf` 156-159、`scheduleRetry` 162-177、settle 里 203-205)与既有的 `recover()` 巡检重复:失败任务已经由 `worktree.recover()` → `cleaner.unsettled()` → `cleaner.start(..., true)` 在每次 turn/end(`events/session-event.ts:20`)、插件启动与每 5 分钟(`host/apply.ts:36-38`)重跑。删掉退避梯子,失败态交给巡检。 [packages/dsh-tauri-worktree/src/host/service/cleaner.ts:148-177] (-35 LOC)+- `shrink:` `createKeyedThrottle` 59 行通用节流器只有 1 个调用点(`register/hydration.ts:55`),`now` 选项从未传过、`schedule` 永远是同一个 `controller.timeout`;`KeyedThrottleOptions`/`KeyedThrottle` 也只为它存在。内联成 hydration.ts 里 15 行的 `Map<string, number>` 时间戳判断。 [packages/dsh-tauri-worktree/src/client/register/hydration.utils.ts:9-58] (-30 LOC)+- `shrink:` `pet.ts` 12 个导出全是同一个 `try { await … } catch { console.error('[dsh-tauri-pet] X failed:', e); return { ok:false, error: messageOf(e) } }` 模板。换成 `guard(label, fn)` 一个 helper,12 个导出各剩 1 行。 [packages/dsh-tauri-pet/src/client/service/pet.ts:1-229] (-30 LOC)+- `yagni:` `pet.invoke.ts` 是 10 个纯转发包装(`return invoke(CMD_X, {...})`),唯一调用方就是上一层 `pet.ts`;合进 `pet.ts` 后这一整层消失。 [packages/dsh-tauri-pet/src/client/service/pet.invoke.ts:1-58] (-30 LOC)+- `shrink:` `ledger.load`、`checkoutContext.load`、`jobs.load` 各自手写「读 DSH_HOME 下的 JSON 文件 + 容忍文件缺失 + 校验形状」,而三者的 `save` 都走同一个 `storage` driver。抽一个 `readJson<T>(key, parse)`,三个 load 各剩 2 行。 [packages/dsh-tauri-worktree/src/host/service/ledger.ts:11-13, checkout-context.ts:10-17, jobs.ts:14-26] (-30 LOC)+- `shrink:` 7 个 archive route handler 的 6 行「取 body → 校验 sessionId(s) → 400」块逐字重复,只有 error 文案不同。抽 `readSessionId(event)` / `readSessionIds(event)` 放 `routes/index.types.ts`。 [packages/dsh-tauri-archive/src/host/routes/session/archive/post.ts:6-11, session/archive/delete.ts:6-11, session/workspace/archive/post.ts:6-13, session/archive/restore/post.ts, session/archive/clear/post.ts, session/workspace/archive/delete.ts, session/open/path/post.ts] (-25 LOC)+- `shrink:` `session-switch.ts` 里 `waitForSessionListed`(20-30)、`waitForInputActions`(32-42)、`openSession`(44-65) 是三个同构 `for (attempt < attempts) { …; await input.wait(delayMs) }` 重试循环(两个 `*WaitInput` interface 也只是把同一组字段抄三遍)。抽一个 `retryUntil(input, probe, delayMs)`。三个函数都是活的(`mode-select.tsx:148,167,206`、`dialog.tsx:89,97`),只是重复。 [packages/dsh-tauri-worktree/src/client/service/session-switch.ts:20-65] (-25 LOC)+- `shrink:` `pet-settings.tsx` 6 个 handler(97-162)各自重复 `if (busy) return; setBusy(true); setError(null); … if (!result.ok) setError(locale.text(key)); setBusy(false)`。抽 `run(action, errorKey)`。 [packages/dsh-tauri-pet/src/client/components/pet-settings.tsx:97-162] (-25 LOC)+- `delete:` pet 的 `toolActivity` 全链路是只产不消的死字段:`PetToolActivity` 类型、`PetSessionPayload.toolActivity`、`PetSessionState.toolActivity`、`toolActivityOf`、两处赋值、`payloadEqual` 里的一处比较。检索串 `toolActivity`(全仓 `*.ts/*.tsx`):`src/` 只命中前端自有的 `toolActivityGroup(toolName)`(`src/pet/hooks/use-bubble-tracker.helpers.ts:62,178`),没有任何 `session.toolActivity` 读取;`src-tauri/src/**/*.rs` 检索 `toolActivity|tool_activity` 零命中(Rust 只做转发)。 [packages/dsh-tauri-pet/src/host/service/session-stream.utils.ts:207-218,373,394,541; host/types/index.ts:15,35; host/service/session-stream.types.ts:65] (-22 LOC)+- `shrink:` `RemoveDirectoryDependencies` DI 接口 + `defaultDependencies` 只有一份生产实现,替换实现只出现在它自己的测试里(检索串 `RemoveDirectoryDependencies`)。直接用 `node:fs/promises`,测试改注入模块而非选项对象。 [packages/dsh-tauri-worktree/src/host/utils/filesystem.ts:17-31,102-148] (-20 LOC)+- `native:` 用 `simple-git` 只为跑 8 个 git 子命令(`git`/stagedPatch/applyStagedPatch/carryStagedChanges/gitToplevel/shortHead/headSubject),而 `applyPatchArchive` 本来就要自己落 patch 文件。改成 `node:child_process` 的 `execFile('git', args)`(git 已是硬依赖)。 [packages/dsh-tauri-worktree/src/host/utils/git.ts:5-6] (-20 LOC, -1 dep)+- `shrink:` session 列表快照类型被抄了 4 份:worktree 内两份(`session-switch.types.ts:16-19` 与 `hydration.types.ts:1-5`,后者多一个 `phase?`),archive `types/runtime.ts` 一份,pet `pet.utils.ts:10-13` 一份。收敛成一处导出。 [packages/dsh-tauri-worktree/src/client/service/session-switch.types.ts:16-19] (-20 LOC)+- `shrink:` `archive-panel.tsx` 里三个并列 `<Modal>`(`confirm.kind` 分别为 single/all/workspace)共用同一个 `footer` 与 `closeLabel`,只有 title/description 不同。合成一个由 `confirm.kind` 计算文案的 Modal。 [packages/dsh-tauri-archive/src/client/components/archive-panel.tsx:212-235] (-18 LOC)+- `stdlib:` 三个包里用 `lodash-es` 的地方基本只有 `get` / `isString` / `compact` / `filter` / `map` / `find` / `isEmpty`,全都有原生等价物(`?.` + `??`、`typeof x === 'string'`、`Array.prototype.filter/map/find`、`Object.keys(x).length === 0`)。替换后 worktree 16 个文件 + archive 3 个文件的 import 行消失,且这两个包可以去掉 `lodash-es`。 [packages/dsh-tauri-worktree/src/**; packages/dsh-tauri-archive/src/**] (-19 LOC, -2 dep entries)+- `shrink:` `pet-settings.tsx` 的 `petsPanel`(197-231) 与 `codexPanel`(233-251) 把同一组 `<PetCard>` props 逐字映射两遍(215-227 与 237-249 仅来源数组不同)。抽一个 `<CardList items actionLabel/>`。 [packages/dsh-tauri-pet/src/client/components/pet-settings.tsx:215-249] (-15 LOC)+- `shrink:` `worktree-section.ts` 与 `worktree-context.ts` 结构逐行相同(`{ name, order: WORKTREE_SECTION_ORDER, text(context) { 取 scope.session.id → ledger.load → 调文案函数 } }`),只差 `name` 和文案函数;合成一个 `promptProvider(name, build)` 工厂。 [packages/dsh-tauri-worktree/src/host/prompts/worktree-section.ts:1-18, worktree-context.ts:1-18] (-12 LOC)+- `delete:` `loadJobStatus` 在两个 client service 里逐字重复,保留一处导出即可。 [packages/dsh-tauri-worktree/src/client/service/hydration.ts:269-279 与 client/service/worktree.ts:112-122] (-11 LOC)+- `shrink:` `workspace.ts` 里 `registryOf()`(39-46) 与 `workspaceOf(path)`(48-54) 是同一个 `getCurrentHostInstance().workspaceRegistry` 之上的两个访问器,合一个。 [packages/dsh-tauri-worktree/src/host/service/workspace.ts:39-54] (-8 LOC)+- `delete:` 三个纯死类型/字段(检索串 `CheckoutContexts`、`\bLedger\b`、`SessionSummaryLike`、`firstSeqAt`):worktree `CheckoutContexts` 只在定义处命中,`Ledger` 只在定义处命中(另有一个局部测试别名 `worktree.recover.test.ts:21`,与本类型无关);archive `SessionSummaryLike` 本包零引用(rightclick 有自己的一份);pet `firstSeqAt` 只在 `session-stream.types.ts:66` 声明、`session-stream.utils.ts:166` 置 0,从不读取。 [packages/dsh-tauri-worktree/src/host/types/index.ts:21,30; packages/dsh-tauri-archive/src/client/types/runtime.ts:11; packages/dsh-tauri-pet/src/host/service/session-stream.types.ts:66] (-7 LOC)+- `delete:` worktree 的两个 link 选项没人设:`linkDependencyDirectories`(`EnsureOptions` 与 `CheckoutOptions` 各一份)全仓只被 `worktree.ts:69,213` 读、没有任何调用方传入(检索串 `linkDependencyDirectories`);`linkDependencies` 只有 `worktree.test.ts:419,424,463` 传,生产恒取 `LINK_DEPENDENCIES = true`(检索串 `linkDependencies`)。删选项后 `normalizeLinkDirectories`/`removalLinkDirectories` 也可退化为常量。 [packages/dsh-tauri-worktree/src/host/types/index.ts:41-42,48; src/host/service/worktree.ts:52,69-70,213] (-7 LOC)+- `shrink:` `create-worktree.ts` 与 `checkout-worktree.ts` 结尾各有一份逐字节相同的私有 `textBlock(text)`。留一份共享 util。 [packages/dsh-tauri-worktree/src/host/tools/create-worktree.ts:89-91, tools/checkout-worktree.ts:68-70] (-6 LOC)+- `shrink:` `archive.delete(sessionId)` 与 `archive.deleteSelected(sessionIds)` 都是 3 行转调 `permanentlyDelete`。留一个收数组的入口(路由层各自包一层即可省掉一个 service 方法与一对 DTO)。 [packages/dsh-tauri-archive/src/host/service/archive.ts:36-43] (-6 LOC)+- `yagni:` 三个包的 `client/store/index.ts` 都是同构单字段包装(`export const store = { worktree }` / `{ archive }` / `{ pet }`),store 模块本身已是具名导出;直接导出模块。 [packages/dsh-tauri-worktree/src/client/store/index.ts:3-5; packages/dsh-tauri-archive/src/client/store/index.ts:3-5; packages/dsh-tauri-pet/src/client/store/index.ts:4-6] (-6 LOC)+- `delete:` `liveActivity.command` / `liveActivity.path` 只声明不产出、也无人读:`toolActivity()` 只返回 `{ kind, name, args }`,`payloadEqual` 里对 `command`/`path` 的比较恒为 `undefined === undefined`;前端 `use-bubble-tracker.helpers.ts:149` 只解构 `kind/text/name/args`。 [packages/dsh-tauri-pet/src/host/types/index.ts:36-42; host/service/session-stream.utils.ts:529-558] (-6 LOC)+- `shrink:` `routes/bindings/get.ts:16` 与 `routes/post.ts:41` 各自内联 `` `${hash}/${dirname}` ``,而 `utils/paths.ts` 已有 `worktreeKey()`;改调它。 [packages/dsh-tauri-worktree/src/host/routes/bindings/get.ts:16, routes/post.ts:41] (-3 LOC)+- `yagni:` `WorktreeParams` 同时收 `worktreeHashDirname` 与 `worktree_hash_dirname`(`create` 里 `??` 兜底),但每条调用链永远只有一种拼法(tools 传 snake_case,client/routes 传 camelCase)。删掉别名,各层按自己那一种传。检索串 `worktree_hash_dirname|worktreeHashDirname`。 [packages/dsh-tauri-worktree/src/host/types/index.ts:67-68; src/host/service/worktree.ts:206] (-3 LOC)+- `delete:` `SIDEBAR_ATTACH_POLL_MS` / `SIDEBAR_ATTACH_MAX_TRIES` 是两处无人读的数值轮询常量(检索串 `SIDEBAR_ATTACH_` 全仓只命中定义行;不是字符串通道 ID,属协议文件内部的多余配置)。 [packages/dsh-tauri-archive/src/client/constants/index.ts:17-18] (-2 LOC)+- `shrink:` `session-context.resolve` 里 `if (!isString(cwd) || !cwd) return null`(24-25)与紧接的 `if (!cwd) return null`(26-27)是同一个判空的两次写法。 [packages/dsh-tauri-worktree/src/host/service/session-context.ts:26-27] (-2 LOC)+- `delete:` pet payload 的 `activity` 是 `status` 的逐字节副本(`foldPetPayload` 同一变量写两次),前端读的是 `session.status ?? session.activity ?? session.phase`。 [packages/dsh-tauri-pet/src/host/service/session-stream.utils.ts:194-195] (-3 LOC)+- `delete:` worktree 声明了却从没被 import 的依赖:`hookable`(检索串 `hookable` 在本包内只命中 `package.json:60`)。 [packages/dsh-tauri-worktree/package.json:60] (-1 dep)+- `keep: pet 的 @deepseek-ai/dsh-skill-filesystem 保留。` — Lead 复核修正:原报告按「`packages/dsh-tauri-pet/src` 零命中」判为可删,但它是**字符串通道引用**——`packages/dsh-tauri-pet/cordis.patch.yml:3` 以 `name: '@deepseek-ai/dsh-skill-filesystem'` 把官方 skill provider 作为一行插进运行时插件图(`package.json:62` 在 `dependencies` 中声明;`THIRD_PARTY_NOTICES.md:14` 说明 `includeDefaultRoots: false` + `customSkillDirs` 指向本包 `skills/`)。按 `docs/audit/protocol-surface.md` §1「字符串通道引用 ⇒ keep」保留,不计入依赖裁剪。**教训:本仓的零调用方证明必须覆盖 `cordis.patch.yml` 等配置型字符串面,只检索 `src/` 不足以定论。**++## Considered and rejected++- `canonicalPath` 的「逐级上溯到存在的父目录再拼接」实现(`worktree.ts:506-529`)— 不是手写 realpath 的重复:`fs.realpathSync.native` 对尚未创建的工作树路径会抛 ENOENT,上溯回退正是它的用途。+- cleaner 的 `jobs.load/save` + `restore()` 落盘 — 进程重启后继续删上一次没删完的队列是这个功能的语义,不是在造持久层。+- `worktree-section/worktree-context/checkout-context` 三个 prompt provider、`defineRoutes` 的每条路由、`*_EFFECT` tag、slot id、`CMD_*` 命令名、`SESSION_STREAM_PATH`、`SSE_STATE_LOST_COMMENT`、`PET_HATCH_PROMPT` — 协议/字符串通道面,仓内无调用方是发布型插件的正常状态,一律保留(只裁它们内部的重复,见 findings)。+- `src/client/apis/index.ts` + `index.type.ts`(worktree、archive 各一份)— @swagger genapi 生成物,排除在审查外。+- `handoff.handback`、`worktree.detach`、`status.resolve`、`workspace.unregisterLegacy` 这些单调用方服务 — 各自是对外的生命周期/IPC 入口,不是「一个实现的抽象」。+- pet payload 的 `phase`、`pending`、`pendingInteraction`、`description`、`name`、`task`、`workStatus` — 前端气泡确实在读(`src/pet/hooks/use-bubble-tracker.helpers.ts:91,95,104-105,186`),属活协议字段;`src-tauri` 只做原样转发(`*.rs` 检索这些字段名零命中),删任何一项都会打断 webview。+- `pathe` — 故意用 POSIX 归一化的 join,产物会进 git 命令与 ledger key;换 `node:path` 会在 Windows 上回退。+- `unstorage` + `fsAtomicDriver`(`src/host/storage/index.ts`)— 原子写没有标准库替代。+- `session-icons.ts` 的 MutationObserver + React fiber 上溯找 sidebar 行 — 平台没有「定位宿主渲染的行」的 API,400ms 自取消轮询有上界。+- `RETRY_BACKOFF_MS` 的 5 档是否可达 — 可达(`backoffOf` 按 `attempts/3` 取档,每轮失败后重排,5 档都会命中),不是死配置;要裁它只能连整条自愈重试一起裁(见 findings 第 2 条)。+- `session-switch.types.ts` 的 `ListSessions/InputSessions/SwitchSessions` 三层窄化 — 三个都被 `session-switch.ts` 与其测试用到,是活类型,只是形状冗余(记在 shrink 项里)。+- 三个 `client/register/*.ts` slot 注入适配器(21/33/17 行)— `defineRegister` 是框架注册面,不是包装层。++## net: -490 lines, -4 deps possible.++> Lead 复核修正:原 net 的 -5 deps 含 pet 的 `@deepseek-ai/dsh-skill-filesystem`(实为 `cordis.patch.yml:3` 字符串通道引用,已降级 `keep:`)。当前 -4 deps = worktree `hookable` + worktree/archive 的 `lodash-es` 原生化 + worktree `simple-git` → `node:child_process`。diff --git a/docs/audit/protocol-surface.md b/docs/audit/protocol-surface.mdnew file mode 100644index 00000000..1b8f7d00--- /dev/null+++ b/docs/audit/protocol-surface.md@@ -0,0 +1,84 @@+# 协议面白名单(审计豁免) — ponytail-audit++> 用户约束(本轮审计的硬性前提):+> **协议类方法,就算没用上,也不允许标记为删除**(`useListen`、`useListenIframe`、`useInvoke` 等等)。+> 本文件是 `docs/audit/*` 的**豁免清单**:凡落入下列类别者,即使全仓 0 调用方,也只能写+> `keep:` 或在「Considered and rejected」中说明,**不得**出现在 `net:` 计数里。++## 1. 判定原则++> 「本仓无调用方」≠「死代码」。++协议面的消费者在仓外:dsh 核心 GUI(iframe 内)、第三方 cordis 插件、上游 dsh 版本、以及未来+版本的自己。这些接口先于调用方存在,删除它们等于破坏对外契约。判据:++| 证据 | 结论 |+| :--- | :--- |+| 被 `src/index.ts` / `client/index.ts` / `host/routes/index.ts` 导出 | 协议面,`keep:` |+| 名字出现在 `docs/specs/plugin.*.md` 的示例或命名约定中 | 协议面,`keep:` |+| 注释显式声明「协议 / 先定义好 / 暂无调用方」 | 协议面,`keep:`(本仓已有先例,见 §3.1) |+| 通过字符串通道被引用(事件名、命令名、槽位名、路由 path) | 协议面,`keep:` |+| 仅在仓内实现体之间调用、无导出、无字符串引用 | 才允许 `delete:` |++## 2. 白名单类别++### 2.1 壳层 iframe 桥(`src/hooks/**`)++| 符号 | 文件 | 方向 | 说明 |+| :--- | :--- | :--- | :--- |+| `useListen` | `src/hooks/use-listen.ts:16` | Tauri 事件 → 组件 | 全部 Tauri 事件订阅的统一入口 |+| `useListenIframe` | `src/hooks/use-listen-iframe.ts:38` | 宿主 → iframe | 与 `useInvokeIframe` 成对;注释声明「目前尚无调用方…先按协议定义好」 |+| `useInvoke` | `src/hooks/use-invoke.ts:5` | command 拉取 | 声明式 `invoke` 封装 |+| `useInvokeIframe` | `src/hooks/use-invoke-iframe.ts:61` | iframe → 宿主 | 含 `ALLOWED_INVOKE_CMDS` 白名单(`src/hooks/use-invoke-iframe.ts:39-59`,15 条命令),是**越权防线**,只可增不可减 |+| `useIframeMessage` / `useIframePost` + `IFRAME_HOST_SOURCE` | `src/hooks/use-iframe-message.ts:25`、`src/hooks/use-iframe-post.ts:6,26` | 桥基础设施 | `source`/`origin` 校验的唯一入口;`IFRAME_HOST_SOURCE = 'dsh-desktop'` 是协议标识 |+| `listenParent` / `useListenParent` | `packages/dsh-tauri/src/client/hooks/use-listen-parent.ts:17`、`packages/dsh-tauri/src/client/service/listen-parent.ts` | 宿主 → 插件 | 插件自有协议档位(`ParentMessageTypes`) |++> `ALLOWED_INVOKE_CMDS` 里的每条命令(`get_pet_status`、`remote_bridge_ping`、`open_external_url` …)+> 与 `packages/dsh-tauri-pet/src/client/constants/index.ts` 的 `CMD_*` 一一对应,属于跨包契约。++### 2.2 插件客户端协议(`packages/dsh-tauri/src/client/**`)++- `useListen` / `useInvoke`:`packages/dsh-tauri/src/client/hooks/*.ts`(插件侧版本,签名与壳层版不同,勿合并)。+- `request/` 层:`packages/dsh-tauri/src/client/request/index.ts` + `index.utils.ts` —— dsh 官方 API 的调用契约。+- `controller/`:`packages/dsh-tauri/src/client/controller/index.ts` —— DOM 补丁生命周期托管(规范 3 级退级)。+- 适配器探测:`defineAdapter` / `adapter.has(...)`,实现于 `packages/dsh-tauri/src/client/register/index.adapter.ts`、类型见 `packages/dsh-tauri/src/client/types/adapter.ts`。**能力名即协议**,包括当前无调用方的档位:++ `sessions.list`、`sessions.provideInfo`、`workspaces.list`、`workspaces.create`、`navigation.startSession`、`navigation.addWorkspace`、`navigation.openSession`、`composer.workspace-less`(消费方 `packages/dsh-tauri-ui/src/client/register/hero-workspace.ts:26`、`new-session.ts:23,53`)。++### 2.3 宿主 IPC surface++- **Tauri commands**:`src-tauri/src/bridge/**` 中 14 个文件、共 **97** 处 `#[tauri::command]`;注册点为 `src-tauri/src/bridge/mod.rs`(`generate_handler`)与 `src-tauri/src/desktop/builder.rs`。命令名是跨进程字符串契约,**不得**因子系统改名而删。+- **事件名**:Rust 侧 `.emit(...)` / `emit_to(...)` 的事件字符串 ↔ 前端 `useListen('...')`。含 `pet://status`、`session:create|update|remove|clear`、`preinstall-log`、`setting_updated`、`dsh-notification-clicked` 等。+- **路由 path**:`packages/*/src/host/routes/index.ts`。按 `docs/specs/plugin.baisc.md` 规则,path **不**入常量模块,直接字面量书写;因此不受「常量 0 消费即删」规则约束。+- **能力/权限声明**:`src-tauri/capabilities/**`、插件 manifest 键。+- **槽位名 / `ctx.effect` 标签 / 样式 ID**:`packages/*/src/{client,host}/constants/index.ts`、`src/shared/constants.ts`。++### 2.4 平台/第三方边界++- `@deepseek-ai/dsh-*`、`@tauri-apps/*`、`@heroui/*`、`@reause/core` 的再导出面。+- `src-tauri/vendor/**`(第三方 vendored,仅可注明体量,不审计内部)。+- `archive/` 目录:按 AGENTS.md 禁止读取(本仓根目录当前无此目录;`packages/dsh-tauri-archive` 是**另一个**东西,属正常审计范围)。++## 3. 本仓已有的协议面先例(证据)++### 3.1 `useListenIframe` —— 显式声明的「无调用方协议」++`src/hooks/use-listen-iframe.ts:25-26`:++> 目前尚无调用方(壳层现有的宿主 → iframe 推送仍写在 `layout/components/iframe.tsx` 里),先按协议定义好,新增「Tauri 事件 → iframe」通道时直接复用。++### 3.2 iframe invoke 白名单 —— 安全边界,不是复杂度++`src/hooks/use-invoke-iframe.ts:31-37` 说明白名单用于「防止 iframe 内其他插件借道桥执行任意 Tauri command(越权)」。此类代码即使看起来是「手写的 Set + 分支」,也属于**信任边界校验**,ponytail 规则明确排除(never simplify away input validation at trust boundaries)。++### 3.3 适配器档位探测 —— 退级策略要求++`docs/specs/plugin.baisc.md` 要求「客户端统一通过 `defineAdapter(ctx)` 探测…禁止猜版本」。因此 `adapter.has(...)` 的分支**不能**因「当前版本恒为真/假」而被判定为死分支。++## 4. 使用方法++1. 各分册作者在标注 `delete:` / `yagni:` 前,先对照本文件与 §1 判据。+2. 命中白名单但确有内部冗余时,写法为:+ `keep: <公开符号> 保留;其内部 <X> 可收敛。<replacement>。[path:lines]`+ 该行**不计入** `net:`。+3. 存疑时降级为「问句」写入 `## Considered and rejected`,不要计入净收益。diff --git a/docs/audit/rust-plugin-service.md b/docs/audit/rust-plugin-service.mdnew file mode 100644index 00000000..62199620--- /dev/null+++ b/docs/audit/rust-plugin-service.md@@ -0,0 +1,81 @@+# Rust · plugin service — ponytail-audit++> Scope: src-tauri/src/service/plugin/** · 31 files · ~16.6k LOC · read 2026-09-30++Over-engineering only。正确性 / 安全 / 性能不在本报告范围。所有 `delete:` / `yagni:` 均给出全仓搜索串(`rg` 在本机不可用,改用 ripgrep 内核的内置 grep 工具与 `git grep`,搜索范围排除 `node_modules` / `dist` / `target`)。+重点结论:本模块的复杂度几乎全部来自 pnpm / Windows / 老核心版本的真实缺陷绕行(issue 编号遍布注释),**这些东西不该删**。可裁的是三类:迁移期兜底(v1 后整体退役)、同一语义的 N 份手写拷贝、只服务一个调用点的包装层。++## Findings (ranked, biggest cut first)++`delete:` `install/allowlist.rs:171-173` 的自述 `TODO(v1)` 遗留自愈:v1 起只需解析干净配置,`apply_allow_build_keys` 解析失败后的「同键去重再解析」兜底(`install/allowlist.rs:223-233`)与 `collapse_allow_builds_duplicates` 全体(`install/allowlist.rs:313-369`,含 doc ~57 行)、配套测试 `collapse_dedupes_allow_builds_keys`(`install/allowlist.rs:661-681`)与 `apply_overwrites_placeholder_value_without_duplicate` 里的损坏输入用例(`install/allowlist.rs:640-659`)一并删除。替换:无(只在 v1 版本边界后、确认无旧版字符串拼接残留文件时执行;旧 YAML 仍可读)。 [src-tauri/src/service/plugin/install/allowlist.rs:171-173] (-88 LOC)++`shrink:` `process.rs` 与 `verify.rs` 各有一份「隐藏控制台 spawn 子进程 → 抽干 stdout/stderr 线程 → 等退出 → 取回累积输出」的完整实现:`run_plugin_process`(`process.rs:256-344`)+ `drain_captured`(`process.rs:347-352`)+ `spawn_line_emitter`(`process.rs:357-400`) vs `spawn_and_wait`(`verify.rs:217-299`)+ `drain_pipe`(`verify.rs:303-313`)+ `drain_captured`(`verify.rs:316-321`,与 process.rs 版本逐字相同)。替换:一个 `spawn_and_drain(program, args, cwd, envs, sink: impl FnMut(&str))`,`preinstall-log` 事件与 payload 保持逐字不变。 [src-tauri/src/service/plugin/process.rs:256-400] (-70 LOC)++`delete:` `internal/mod.rs` 的 30 秒指纹复用缓存整套:`ENSURE_REUSE_WINDOW`(`internal/mod.rs:77`)、`EnsureReceipt`(`internal/mod.rs:89-93`)、`EnsureCoordinator.receipt` 字段与 `reuse`/`record`(`internal/mod.rs:117-138`)、`ensure_fingerprint`(`internal/mod.rs:284-316`,为算指纹要读 profile `package.json` + `cordis.yml` + 两层 patch 再哈希)。它只服务「同一次启动里第二路 `ensure` 少跑一遍」。替换:无,第二路照常完整重跑(本函数按设计幂等,重复执行是 no-op)。 [src-tauri/src/service/plugin/internal/mod.rs:89-138,284-316] (-70 LOC)++`shrink:` `dsh.profile.bundles` upsert 有两份手写实现,语义完全一致(缺段则建 → 写 `dependencies[id]` → 去重追加 bundle):`write_back_manifest_refs_at`(`snapshot.rs:517-583`,66 行)与 `upsert_manifest`(`internal/materialize.rs:109-160`,52 行)。替换:`internal/manifest.rs` 里一个共享 `upsert_manifest(refs: &[(&str, &str)])`,两处调用。 [src-tauri/src/service/plugin/snapshot.rs:517-583] (-50 LOC)++`shrink:` 「同目录临时文件 → 写入 → 替换」在本模块树里写了三遍:`internal/manifest.rs:117-166`(temp + `sync_all` + 平台替换)、`write_patch_layer_atomically`(`patch_entries.rs:410-424`)、`write_archive_atomic`(`snapshot.rs:245-264`,其 `write_fn: impl FnOnce(&Path)` 闭包参数生产调用点只有 `snapshot.rs:378` 一处,其余是测试)。替换:一个 `atomic_write(dest: &Path, bytes: &[u8]) -> Result<(), String>`,三处调用,闭包参数去掉。 [src-tauri/src/service/plugin/patch_entries.rs:410-424] (-45 LOC)++`native:` `internal/manifest.rs:141-166` 用 FFI 手写 Windows 原子替换 `MoveFileExW(MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)`,并为此写了 `#[cfg]` 双实现 + `unsafe` 块。`std::fs::rename` 在 Windows 上本就是 `MoveFileExW(MOVEFILE_REPLACE_EXISTING)`,多出来的只有 `WRITE_THROUGH`(持久化),而持久化在同文件 `write_profile_manifest`(`internal/manifest.rs:117-139`)里已经用 `sync_all()` 做过。替换:`std::fs::rename` + 保留 `sync_all`(Windows/Unix 同一份代码,删掉 `#[cfg]` 分支与 `unsafe`)。 [src-tauri/src/service/plugin/internal/manifest.rs:141-166] (-26 LOC)++`yagni:` pnpm 版本探测的三个一次性包装:`probe_task_or_fallback`(`pnpm.rs:507-515`)、`probe_output_or_fallback`(`pnpm.rs:517-528`)、`probe_timeout_or_fallback`(`pnpm.rs:536-539`)。三者各自只做「调 6 行的 `log_probe_fallback`(`pnpm.rs:500-505`)+ 返回 `None`/`Ok(None)`」,各 1 个生产调用点(`pnpm.rs:184`、`pnpm.rs:192`、`pnpm.rs:244`)与 1 个测试直呼(`pnpm.rs:812`、`pnpm.rs:827`、`pnpm.rs:837`)。替换:调用点直接 `log_probe_fallback(pnpm, "<phase>", err)` + `None`,删三个函数与三个测试。 [src-tauri/src/service/plugin/install/pnpm.rs:507-539] (-15 LOC)++`shrink:` 插件 `package.json` 读取有两套同名函数、字段集不相交:`watch.rs:127-130` 的 `read_plugin_meta(dir) -> Option<PluginPackageJson>`(name/version/description/homepage/repository)与 `recovery/ownership.rs:22-39` 的 `read_plugin_meta(dir) -> Option<PluginMeta>`(dependencies/optionalDependencies/dsh.bundle.patch)。替换:合成一个 serde 结构 + 一个读取函数。 [src-tauri/src/service/plugin/recovery/ownership.rs:22-39] (-20 LOC)++`shrink:` 手写时间戳四份:`now_timestamp`(`snapshot.rs:138-152`,`YYYY-MM-DDTHH-MM-SS`)、`now_stamp`(`patch_guard.rs:149-163`,`yyyymmddhhmmss`)、`now_seconds_string`(`disable.rs:241-246`)、`errors.rs:60-63` 的 `d.as_secs().to_string()`——前两者都是 `time::OffsetDateTime` + `format!("{:04}{:02}…")` 手工补零,`time` crate 已在依赖里且自带 `format_description!`。替换:`now.format(format_description!("[year]-[month]-[day]T[hour]-[minute]-[second]"))` 与一个 `unix_secs()`。 [src-tauri/src/service/plugin/snapshot.rs:138-152] (-25 LOC)++`shrink:` `transient_fs_retry_delay`(`install/mod.rs:106-113`)与 `policy_verification_retry_delay`(`install/mod.rs:124-131`)是逐字相同的上限指数退避,只有 base/cap 常量不同(1s→64 / 5s→30)。替换:`fn capped_backoff(retry: usize, base_secs: u64, cap_secs: u64) -> Duration` + 两个一行包装。 [src-tauri/src/service/plugin/install/mod.rs:106-131] (-8 LOC)++`shrink:` `is_core_package` 两份逐字相同:`disable.rs:228-230`(`id.starts_with("@deepseek-ai/")`,注释 L227 自承「与 recovery 模块的保护名单一致」)与 `recovery/mod.rs:49-51`。替换:`recovery/mod.rs` 出一份 `pub(crate)`,`disable.rs` 引用。 [src-tauri/src/service/plugin/disable.rs:228-230] (-6 LOC)++`shrink:` cordis 补丁条目匹配谓词两份:`patch_entry_targets`(`recovery/uninstall.rs:153-161`,`map.iter().any(|(k,v)| k==id || v==id)`)与 `disable.rs:165-169` 的内联闭包(`disable.rs:57-59` 注释自承「匹配口径与 `recovery::uninstall::patch_entry_targets` 一致」)。替换:共享一个 `patch_entry_targets(entry, names: &[String]) -> bool`。 [src-tauri/src/service/plugin/disable.rs:165-169] (-10 LOC)++`shrink:` bundles 移除两份:`remove_from_bundles`(`disable.rs:195-207`)与 `remove_plugin_from_manifest` 内部的 retain(`recovery/uninstall.rs:23-34`)。替换:共享 `remove_bundle(manifest: &mut Value, id: &str) -> bool`。 [src-tauri/src/service/plugin/disable.rs:195-207] (-8 LOC)++`shrink:` 悬空 insert 项判定在 `patch_entries.rs` 写了两遍:`scan_layer` 的 `patch_entries.rs:224` 与 `strip_entries` 的 `patch_entries.rs:277-284` 都是 `is_bare_package_name(name) && !package_resolvable(profile_dir, install_anchor, name)`。替换:`fn dangling_package(profile_dir, anchor, item: &Value) -> Option<&str>`,两处复用。 [src-tauri/src/service/plugin/patch_entries.rs:224,277-284] (-8 LOC)++`shrink:` 同一段 `STATE.get_or_init(|| Mutex::new(WatchState { last_fp: None, last_emit: None, pending_fp: None }))` 在 `watch.rs:259-268`(`force_emit`)与 `watch.rs:321-330`(`check_and_emit`)各写一遍。替换:`WatchState` 派 `Default` + `fn state() -> MutexGuard<'static, WatchState>`。 [src-tauri/src/service/plugin/watch.rs:259-268] (-10 LOC)++`shrink:` git URL 归一逻辑两份:`normalize_repo_url`(`watch.rs:112-124`)与 debug-only 的 `normalize_dev_repo_url`(`preset.rs:133-145`),同为「剥 `git+` / `git://`→`https://` / 去掉尾部 `.git`」。替换:一个 `pub(crate) fn normalize_repo_url`(去掉 `#[cfg(debug_assertions)]` 门)。 [src-tauri/src/service/plugin/watch.rs:112-124] (-8 LOC)++`shrink:` `run_ensure_operation` 的 `tokio::select!` 超时臂与取消臂几乎逐字重复(各含 `terminate_owned_install(owner).await` + `timeout(ENSURE_CLEANUP_TIMEOUT, …)` + `mark_cleanup_failed`),只有 emit 的 detail 与 reason 串不同。替换:一个 `finish_with(detail, reason)` 闭包/内层 async fn。 [src-tauri/src/service/plugin/internal/mod.rs:575-597] (-10 LOC)++`stdlib:` `hex_value`(`update.rs:396-403`)手写十六进制 nibble 表(`b'0'..=b'9'` / `b'a'..=b'f'` / `b'A'..=b'F'`)。替换:`char::from(value).to_digit(16).map(|d| d as u8)`,函数体一行。 [src-tauri/src/service/plugin/update.rs:396-403] (-8 LOC)++`yagni:` `DisabledEntry.reason`(`disable.rs:25-26`)恒为 `"user"`(仅 `disable.rs:298`、`disable.rs:321` 两处写入),全仓无读者。搜索串 `disabledAt|disabled_at|DisabledEntry|disabled-plugins` 命中仅为:`disable.rs` 自身定义/写入/测试断言、`watch.rs:634` 测试 fixture 字符串、`watch.rs:297`(`disabled-plugins.json` 进指纹拼接)、`src/types/plugin.ts:24` 注释。替换:无(旧 JSON 里多出的键被 serde 忽略)。 [src-tauri/src/service/plugin/disable.rs:25-26] (-4 LOC)++`delete:` `SnapshotManifest.patches: Vec<String>`(`snapshot.rs:93-94`)注释自承「v1 为空」,只在 `snapshot.rs:371` 写 `Vec::new()`(测试 `snapshot.rs:751`、`snapshot.rs:795`),全仓无读者。替换:无(serde 忽略未知键,旧归档仍可反序列化)。 [src-tauri/src/service/plugin/snapshot.rs:93-94] (-2 LOC)++`yagni:` `remove_legacy_candidates(candidates, remove: impl FnMut(&Path) -> io::Result<()>)`(`preset.rs:399-419`)的闭包参数只有一个生产调用点直接传 `fs::remove_dir_all`(`preset.rs:395`),另一个调用点是测试为注入失败而传闭包(`preset.rs:873`)。降级说明:该参数是为测错误聚合而留的注入口,删掉需把测试改成构造真实不可删目录。替换:去掉参数、内部直接 `remove_dir_all`。 [src-tauri/src/service/plugin/preset.rs:395-419] (-6 LOC)++`shrink:` `RE_CANNOT_RESOLVE_BUNDLE`(`recovery/extract.rs:40-42`)的正则字面量与同文件 `PLUGIN_REF_PATTERNS` 第 2 条(`recovery/extract.rs:15`)完全相同,同一模式被编译两份。替换:命名一个 `static` 供两处引用(或让 `classify_reason` 复用 `PLUGIN_REF_PATTERNS[1]` 的具名别名)。 [src-tauri/src/service/plugin/recovery/extract.rs:40-42] (-3 LOC)++`shrink:` `monitor_probe_wait_task` 的错误分支(`pnpm.rs:423-428`)与 `monitor_orphaned_probe_pid` 的尾部(`pnpm.rs:444-449`)是同一段 6 行「`wait_for_probe_cleanup_with(|| !plugin_process_has_exited(pid), PNPM_PROBE_LIVENESS_INTERVAL).await` → `release_process_cleanup(owner, pid_guard, process_guard)`」。替换:`async fn await_exit_then_release(owner, pid, pid_guard, process_guard)`。 [src-tauri/src/service/plugin/install/pnpm.rs:423-449] (-8 LOC)++## Considered and rejected++- `compat.rs:98-122 normalize_range` 手写 npm 空格分隔比较符归一 —— `semver::VersionReq` 不接受 `>=1.0 <2.0` 这种 npm 写法,不是 stdlib 重复;三种形态都有测试钉住,删了会失去清单里按 npm 习惯书写的区间支持。+- `compat.rs:80-96 matches_including_prerelease` 绕过 semver 的预发布门槛 —— 这是刻意的口径(清单里 `^0.1.7-rc.1` 要能匹配 `0.1.7-rc.3`),有测试覆盖。+- `process.rs:42-43` 的 `NEXT_PROCESS_OWNER` + `ACTIVE_PLUGIN_PIDS: HashMap<ProcessOwner, u32>` 看似「单进程就够了」的过剩灵活性(`acquire_process_lock` 已经全局串行化进程启动,任一时刻最多一个活进程)。但 `process.rs:407-461` 的测试专门钉多 owner 并存、stale guard 与「别的 owner 的 cleanup failure 不得清掉我的状态」,属刻意设计,不裁。+- `recovery/mod.rs:54-95 is_package_name`(42 行 npm 包名校验)—— 这是从启动日志里取出的字符串进入文件系统操作前的路径穿越防线,没有 stdlib 等价物,不能删。+- `watch.rs:282-303 fingerprint` 用秒级轮询而不是引入 `notify` —— 模块头注 `watch.rs:5-8` 明确记录为刻意取舍(插件只有个位数、每次只读小 JSON),且 `DEBOUNCE` 2s 有防抖理由。属性能议题,本就不在范围。+- `recovery/ownership.rs:240-306` 的 pass 1(`bundle_owns_package`)→ pass 1b(`plugin_references_packages`)两轮近乎重复的归属循环 —— 语义不同:pass 1 命中多个候选时 pass 1b 仍可能返回唯一归属,合并会改变判定结果。+- `patch_guard.rs:94-106 backup_path(path, suffix, stamp)` 的 `suffix` 参数 —— 有 2 个真实调用点(`patch_guard.rs:118` 的 `broken`、`patch_entries.rs:158` 的 `bak`),不是单实现参数化。+- `install/spec.rs:147-229` 的 `normalize_git_spec` / `shell_quote_spec` / `joins_pnpm_args_in_shell` —— 三个按核心版本分档的 spec 变换。看着像「没人设的 flag」,但每个都绑着真实缺陷回归(issue #104 / #3948 / #647 / #369),且 `SHELL_JOINED_PNPM_CLI_BELOW` 是开区间上界,随着老核心退出使用会自然退役;现阶段删任一条都会让一部分用户必失败。+- `errors.rs:19-28 PluginError.at: String` 用字符串存 unix 秒(可缩成 `u64`)—— 但 `PluginError` 是经 `DshPlugin.error` 下发前端的 IPC payload,改类型就是改线格式,需与 `src/types/plugin.ts` 同步。不作为 finding。+- `install/env.rs` 全文件(`build_plugin_envs` 的各段环境注入、`git_https_isolation_env`、`rewrite_rule_targets_ssh_github`)—— 分支密集但没有一处冗余:每段都带 issue 编号与回归测试,删任一段都会让某类桌面环境安装必失败。+- `snapshot.rs:179-203 count_tree` 与 `snapshot.rs:293-316 count_archive_package` —— 一个走文件系统、一个走 tar 条目,无法合并。+- `preset.rs:289-347` 旧布局回退探测(`LEGACY_BUNDLED_PLUGINS_DIR`,`preset.rs:293`)与 `remove_legacy_bundled_plugins`(`preset.rs:377-430`)并存 —— 前者服务「就地升级的旧安装仍能自愈」,后者清残留,要按版本边界与 allowlist 的 v1 清理一起退役,不宜单删。+- `internal/mod.rs:950-1042` 一串 pnpm 输出字符串嗅探(`looks_like_link_readback_failure`、`failed_open_path`、`normalize_link_path`、`path_lives_under`)—— 服务一个具体的 pnpm 回读缺陷兜底,属健壮性而非过度设计。+- `internal/mod.rs:1044-1133 remove_legacy_profile_module_fallback*` —— 迁移清理,但有 `internal/mod.rs:1400` 的 issue #466 活体回归测试且两个调用点都在关键路径上;与 allowlist 的 v1 清理同批退役。+- `recovery/extract.rs:71-88` 每次调用重编译 `Regex`(同文件 `PLUGIN_REF_PATTERNS` 已用 `LazyLock` 编译一次)—— 不一致,但这是性能问题,明确 OUT OF SCOPE。++## risk/notes++- 迁移期兜底(findings #1、以及 rejected 里 `preset.rs` 旧布局回退 / `internal/mod.rs` legacy fallback 清理)应在同一个 v1 版本边界整批删除,不要零散摘除:它们共享「升级期间的旧文件形态」这一前提。+- `internal/manifest.rs:141-166` 换 `std::fs::rename` 时必须保留 `sync_all` 早于 rename 的顺序,否则崩溃窗口会留下零长度的 `package.json`。+- `process.rs` / `verify.rs` 合并会碰到 `preinstall-log` 事件发射点:事件名与 `PreinstallLogPayload` 载荷必须逐字不变(前端字符串通道)。+- `DisabledEntry.reason` 与 `SnapshotManifest.patches` 的删除不需要数据迁移:serde 默认忽略未知键,旧 JSON / 旧归档照常反序列化。++## net: -508 lines, -0 deps possible.diff --git a/docs/audit/rust-service.md b/docs/audit/rust-service.mdnew file mode 100644index 00000000..84fa974d--- /dev/null+++ b/docs/audit/rust-service.md@@ -0,0 +1,69 @@+# Rust · core services — ponytail-audit++> Scope: src-tauri/src/service/** (excl. plugin/) · ~20k LOC · read 2026-09-30++## Findings (ranked, biggest cut first)++- `shrink:` Drop the native-probe stamp cache (stamp path/key, `NATIVE_ARTIFACT_DIRS`, `collect_probe_stamp_entries`, `push_probe_stamp_entry`, `path_modified_nanos`, `file_modified_nanos`, `read_native_probe_stamp`, `write_native_probe_stamp` and both call sites); probe unconditionally or store only node size+mtime + core version. [src-tauri/src/service/core/runtime.rs:59-61, 248-270, 982-1122] (-110 LOC)+- `native:` Replace the hand-rolled `CreateFileW`+`DeviceIoControl(FSCTL_SET_REPARSE_POINT)` junction writer with the `junction` crate (`junction::create`) or `mklink /J`; adds one dependency. Also removes its 50-line test. [src-tauri/src/service/core/runtime.rs:787-914, 1689-1739] (-128 LOC, +1 dep)+- `shrink:` Collapse the ten duplicated `if let Err(e) = patch::<mod>::apply(&app_handle) { log::warn!(...) }` blocks into one loop over the module table that already exists at `patch/mod.rs:34-44`. [src-tauri/src/service/workflow/launch.rs:386-449] (-35 LOC)+- `shrink:` Delete `patch_dsh` (a one-line wrapper over `patch_core_file` + `active_core_install_dir`) and the nine per-module `apply` wrappers; keep one `apply_at(core_dir)` per patch module and resolve the active core dir in the caller. [src-tauri/src/utils/mod.rs:23-47, src-tauri/src/service/patch/{renderer.rs:72-77, composer.rs:104-109, session.rs:39-44, llm_session.rs:76-81, pi_ai_thinking.rs:140-145, model_selection.rs:58-63, workspace.rs:45-50, workspace_view.rs:81-86, plugin_visibility.rs:154-174}] (-45 LOC)+- `shrink:` Hoist `locate_return_module_exports` (`Option<(usize, &str)>`) and its `ANCHOR_KEYWORD` const into one shared `patch::insert_before_module_exports(source, text)` helper; it is duplicated verbatim today. [src-tauri/src/service/patch/renderer.rs:27, 56-67, src-tauri/src/service/patch/composer.rs:47, 91-99] (-24 LOC)+- `shrink:` Merge `append_log`'s inline rotation with `rotate_service_log`; both run the same remove-oldest → shift `.i`→`.i+1` → rename-into-`.1` sequence. One `fn rotate_log(log_path: &Path, keep: usize)`. [src-tauri/src/service/workflow/utils.rs:259-270, 295-315] (-20 LOC)+- `shrink:` Merge `run_command` and `run_process_with_timeout`; both build the identical `Command` (args, current_dir, piped stdout/stderr, `creation_flags(0x08000000)`). [src-tauri/src/service/core/runtime.rs:1490-1573] (-25 LOC)+- `shrink:` Extract one `asset_and_digest(...) -> (String, Option<String>)` — the asset lookup, `browser_download_url`, `digest` filter and the three-arm expanded-assets fallback ladder are written twice. [src-tauri/src/service/download/github.rs:315-362, 440-479] (-30 LOC)+- `shrink:` Delete the `#[allow(unused_imports)]` re-export blocks whose own comments admit the names have no caller; keep only the names with real callers. The API types stay (IPC payloads). [src-tauri/src/service/core/mod.rs:30-32, src-tauri/src/service/update/mod.rs:33-35] (-6 LOC, -2 allow attrs)+- `shrink:` Have one `download::utils::parse_digest_from_expanded_assets` and delete the byte-identical copy (same 4096-byte window, same char-boundary clamp, same 64-hex check) plus its duplicate test. [src-tauri/src/service/update/meta.rs:111-129, 279-296 vs src-tauri/src/service/download/github.rs:182-200, 824-866] (-20 LOC)+- `shrink:` Extract `fn is_link(file_type: &std::fs::FileType) -> bool`; the windows `is_symlink() || is_symlink_dir()` / unix `is_symlink()` pair is written out four times in this file alone. [src-tauri/src/service/core/runtime.rs:462-465, 493-500, 515-518, 752-757] (-30 LOC crate-wide)+- `shrink:` Replace the `temp_dir(tag)` test fixture with one `#[cfg(test)] test_util::temp_dir(prefix, tag)`; near-identical bodies exist in at least six modules. [src-tauri/src/service/cli/path/mod.rs:213-225, cli/shim/mod.rs:156-168, cli/shim/write.rs:278-290, workflow/win_inspector.rs:142-144, core/local.rs:471-482, migrate.rs:355-361] (-50 LOC)+- `shrink:` Make `package_dir_from_bin` return the resolved layout (`Npm`/`Pnpm`) so `local_core_uses_pnpm` stops re-walking the same `prefix_candidates` + `probe_package_dir` + `read_dir(prefix/global)` ladder. [src-tauri/src/service/core/local.rs:292-315, 347-367] (-25 LOC)+- `shrink:` Extract `validate_new_profile_id(root, name)`; `clone_with_root` re-implements `create`'s entire ladder with the same five error codes (`PROFILE_EMPTY_NAME`, `PROFILE_INVALID_NAME`, `PROFILE_NAME_TOO_LONG`, `PROFILE_RESERVED`, `PROFILE_EXISTS`). [src-tauri/src/service/profile/mod.rs:362-380, 657-682] (-26 LOC)+- `shrink:` Replace the two test-only execa re-implementations (`execa_escape_meta_chars` + `execa_escape_argument`) with the single expected escaped literal in the one test that uses them. [src-tauri/src/service/cli/shim/build.rs:894-915] (-20 LOC)+- `shrink:` Use the typed `read_manifest`/`write_manifest` in `backup/retention.rs`; it re-parses `.manifest.json` into a raw `Value` and hand-writes its own tmp+rename, duplicating `backup/mod.rs`. [src-tauri/src/service/backup/retention.rs:23-29, 49-57] (-18 LOC)+- `shrink:` Add one `utils::atomic_write(path, content)`; "pid + nanos temp name then rename" is implemented three times for three different files. [src-tauri/src/service/backup/mod.rs:116-128, backup/archive.rs:278-289, profile/mod.rs:939-957] (-16 LOC)+- `shrink:` Extract `async fn first_asset_matching(pred, missing_code)`; `fetch_dsh_pkg_version` and `fetch_latest_non_preview` are the same find-tag-then-`fetch_dsh_pkg_asset` shape. [src-tauri/src/service/download/github.rs:377-384, 393-403] (-14 LOC)+- `shrink:` Extract one `atom_entries(body) -> Vec<(String, String)>`; `parse_atom_entries` and `first_non_preview_tag_from_atom` each hand-scan the same `<entry>` feed. [src-tauri/src/service/update/meta.rs:51-69, src-tauri/src/service/download/github.rs:132-155] (-25 LOC)+- `shrink:` Extract `utils::recreate_symlink(target, dst)`; the unix-`symlink` / windows-`symlink_dir().or_else(symlink_file)` twin is written twice. [src-tauri/src/service/backup/archive.rs:15-27, src-tauri/src/service/profile/mod.rs:751-767] (-14 LOC)+- `shrink:` Make the tar extractor take the decompressor (`enum Compression { Zstd, Gzip }`); `extract_archive` and `extract_archive_gzip` differ only in `zstd::Decoder` vs `GzDecoder` and already share `extract_tar_entries`. [src-tauri/src/service/backup/archive.rs:172-192] (-10 LOC)+- `shrink:` Merge `append_version_dirs`/`version_key` with the inline windows version-dir loop — both do "read_dir a version root, sort, append bin dirs". [src-tauri/src/service/core/local.rs:166-194, 222-234] (-20 LOC)+- `shrink:` Inline the one-caller predicate `all_client_modules_ready` at its only call site (and drop its test). [src-tauri/src/service/workflow/health.rs:55-57, 90] (-6 LOC)+- `shrink:` Remove the two-file-level `#[allow(unused_imports)]` blocks in `cli/shim/write.rs` by importing the shim builders inside `mod tests` instead of at file scope. [src-tauri/src/service/cli/shim/write.rs:9-16] (-6 LOC)+- `shrink:` Inline `is_foreign_file` (`!is_generated_shim`) at its three call sites. [src-tauri/src/service/cli/shim/write.rs:31-33, 122, 145, 230] (-4 LOC)+- `shrink:` Turn `macro_rules! write_if_ours!` into a 4-line fn — its returned `target` is unused at all five expansion sites. [src-tauri/src/service/cli/shim/write.rs:184-190, 200-221] (-8 LOC)+- `shrink:` Give `harness_command(...)` to the unix retry path; the full `Command` (program, args, envs, current_dir, stdio, `process_group(0)`) is built twice. [src-tauri/src/service/workflow/launch.rs:765-775, 801-808] (-18 LOC)+- `shrink:` Extract `record_active_app_tag(app_handle, tag)`; the tag+commit store write (including the byte-identical `fetch_dsh_pkg_tags` commit lookup) appears twice. [src-tauri/src/service/core/version.rs:545-558, 653-666] (-28 LOC)+- `shrink:` Inline `NativeProbeFailure::is_platform_import` into `has_platform_import_failure`. [src-tauri/src/service/core/runtime.rs:160-162, 192-196] (-6 LOC)+- `shrink:` Inline `meets_baseline` into its only caller `core_supports_bundled_plugins`. [src-tauri/src/service/core/source.rs:87-95, 101-106] (-8 LOC)+- `shrink:` Collapse `is_dsh_running`'s async-`Option` round trip to `client.get(&url).send().await.is_ok_and(|r| r.status() == StatusCode::OK)`. [src-tauri/src/service/workflow/utils.rs:143-164] (-10 LOC)+- `shrink:` Make the no-op windows facade disappear: the `#[cfg(not(windows))] mod imp` stubs (`apply -> Ok(())`, `git_bash_bin_dirs -> Vec::new()`) plus the always-compiled `pub fn` wrappers are two layers for nothing — `#[cfg(windows)]` the call sites directly. Same pattern in the other cfg-twin stubs. [src-tauri/src/service/workflow/win_inspector.rs:222-249, cli/shim/write.rs:167-170, cli/path/pnpm.rs:154-157, update/version.rs:52-55] (-20 LOC)+- `shrink:` Make `create_file_with_retry` and `download::core::remove_path_if_exists` share one transient-error retry helper (`Some(32|5)` → sleep 250 ms, N attempts). [src-tauri/src/service/download/extractor.rs:14-37, download/core.rs:364-388] (-15 LOC)+- `shrink:` Reuse the character-set whitelist from `fs_guard::validate_id` in `plugin_visibility::is_safe_bundle_name`; the same "alphanumeric / `.-_`" rule is hand-written twice. [src-tauri/src/service/patch/plugin_visibility.rs:146-151 vs src-tauri/src/service/fs_guard.rs:29-36] (-8 LOC)+- `shrink:` Stop re-running `find_user_dsh_bin` in the list builder when `local_core` already resolved the bin — it is a full PATH walk. [src-tauri/src/service/core/version.rs:124-128] (-4 LOC)+- `shrink:` Cache the canonical `updates_dir` in `resolve_installer_path`; it re-canonicalizes a constant directory on every open. [src-tauri/src/service/update/install.rs:343-359] (-6 LOC)+- `shrink:` Delete `download_file` (one-line forward to `download_file_from_sources`); its single caller sits in `service/plugin/install/pnpm.rs`. [src-tauri/src/service/download/core.rs:21-26, download/mod.rs:10] (-6 LOC)+- `shrink:` Replace the `PathBuf`-typed log helpers with `&Path` — `append_log(&PathBuf)`/`rotate_service_log(&PathBuf)` force callers to clone. [src-tauri/src/service/workflow/utils.rs:245, 295] (-4 LOC)+- `delete:` Remove `restore_real_backup_to_temp`; it hardcodes one developer's absolute `/Users/coderstory/.dsh/.backups/2026-08-31T15-04-18.tar.zst`, self-skips when absent, and asserts nothing — ~70 lines of `println!` diagnostic. [src-tauri/src/service/backup/mod.rs:421-496] (-70 LOC)++## Considered and rejected++- `service/core/runtime.rs` size (2185 lines) — owned by `docs/specs/rust.optimize.md` §3.1, which mandates splitting large files; not an over-engineering finding.+- The four-source GitHub fallback ladder (api.github.com → releases.atom → expanded_assets HTML → tag build-id) — each rung fixes a documented 403/limit failure (issues #48, #92, #299, #379).+- `resolve_update`'s branch lattice and `record_matches_latest_release` — the branches encode real regressions (rc releases reusing a git commit, build-id vs full SHA records, tag aliases).+- Hand-rolled HTML/atom scanners (`parse_release_list_from_html`, `first_non_preview_tag_from_atom`, `parse_digest_from_expanded_assets`) — the tree has no HTML parser, and adding one needs a §4.2 dependency justification.+- `decode_multibyte` / `encode_multibyte` / `short_path` / `console_code_page` — no std equivalent; `WC_NO_BEST_FIT_CHARS` and the ANSI-code-page fallback are deliberate correctness choices.+- `win_spawn::quote_arg` and the `CREATE_NEW_CONSOLE | SW_HIDE` trick — reproduces MSVC argv quoting and suppresses the black-cmd popup; no std API covers either.+- `cli/shim/templates.rs`'s three shell-language template sets — a cmd/ps1/sh shim cannot share one implementation.+- `perm.rs` remedy strings (`remedy_hint`, `shell_quote`, `owner_suffix`) — that copy-pasteable chown/takeown text is the deliverable of issue #466; ~60 LOC and worth it.+- `backup/archive.rs` tar safety ladder (reject `..`, reject hard links, `AlreadyExists` symlink skip, tmp-then-rename) — each rung is a data-loss/security guard.+- `workflow/sweep.rs` (`sweep_orphan_harness`, `port_owner_pid`, `relaunch_via_shell_escape`) — every branch is a documented "never kill an unknown process" guard; the 448 RedirectionGuard relaunch is a real Windows 11 25H2 workaround.+- `workflow/process.rs` — the PID+handle pairing, `take_owned_process_if`, and the launch/core-transition lock encode the WARN-5/WARN-6 race fixes; do not merge the two guards.+- The nine core patches (`renderer`, `composer`, `session`, `llm_session`, `pi_ai_thinking`, `model_selection`, `workspace`, `workspace_view`, `plugin_visibility`) — each is a documented upstream-drift shim with an idempotence marker and an anchor-missing fallback; none is speculative.+- `workflow/health.rs::not_owned_probe_signal` and `workflow/install.rs`'s retry/outdated logic — both encode observed startup/rc race behaviour.+- `download/installable.rs`'s `Installable` trait — four real implementors (Nodejs, Dsh, Pnpm, Git); not a single-impl abstraction.+- `workflow/heap.rs::node_options_heap_limit` — the token forms (`--flag value`, `--flag=value`, quoted) are all real Node invocations.+- `migrate.rs` — every branch (linked-dir refusal, `node_modules` special case, mtime compare, stale pnpm metadata purge) is a documented data-loss guard (issues #103, #452).+- `service/plugin/**` — another agent's scope; the `download_file` caller and `extract_archive_gzip`'s caller live there but were not audited.++## net: -855 lines, -0 deps possible.++(Line total counts the junction finding as `native:`, which adds the `junction` crate; excluding it, the non-dependency total is -727 lines.)diff --git a/docs/audit/rust-shell.md b/docs/audit/rust-shell.mdnew file mode 100644index 00000000..c6b2f1d3--- /dev/null+++ b/docs/audit/rust-shell.md@@ -0,0 +1,60 @@+# Rust · shell / bridge / desktop — ponytail-audit++> Scope: src-tauri/src/{bridge,desktop,config,logger,utils,task}, lib.rs, main.rs, Cargo.toml, capabilities/, resources/ · ~8.8k LOC · read 2026-09-30+>+> 只读审查,未改动任何被审查代码。协议面(`#[tauri::command]`、`generate_handler!` 名单、事件名、capacity/permission 标识、用户可设配置键、CLI 旗标)一律保留,只报其**内部**的过度设计。+> `src-tauri/vendor/**`(约 5.6k 行 vendored tauri-plugin-wdio-webdriver / tauri-plugin-notifications)不计入本报告。`src-tauri/src/service/**` 由其它报告覆盖。+> 搜索证据:本机 `rg` 不在 PATH,零调用方证明统一用 harness `grep` 工具(ripgrep 内核),范围 `src-tauri/src` / `src-tauri`,排除 `node_modules` / `dist` / `target`。每条 `delete:`/`yagni:` 都给出实际跑过的搜索串。++## Findings (ranked, biggest cut first)++- `delete:` 删掉 `#[allow(dead_code)] struct SharedRotatingWriter(Arc<SizeRotatingWriter>)` 及其 `impl Write` / `impl MakeWriter`(第三个、也是最绕的一份写盘路径:嵌套重锁 + `ensure_file` 重试)。类型只在自身定义处出现(搜索串 `SharedRotatingWriter|append_bytes|SizeRotatingWriter|FRONTDESK_WRITER`,22 命中,其中该类型仅 logger/mod.rs:238/239/273 三处)。 [src-tauri/src/logger/mod.rs:237-279] (-43 LOC)+- `shrink:` 把 `build_main_window` 的建窗链抽成 `fn with_shell_chrome(app, builder)`:`build_shell_window` 逐字复制了基础链(1280×840 / min 860×620 / resizable)、`#[cfg(windows)]` 的 `.data_directory(webview_data_directory(app)).additional_browser_args(..).icon(..)` 三元组、`#[cfg(not(windows))]` 六条 `.initialization_script_for_all_frames` 链,以及 `#[cfg(target_os="macos")]` 的 `.decorations(true).title_bar_style(Overlay).hidden_title(true).traffic_light_position(..).theme(match get_dsh_theme(app) ..)` 块。三处调用点(主窗口 / 附加窗口 / 桌宠)各写一遍。 [src-tauri/src/desktop/builder.rs:600-605, 609-649, 687-694 vs 765-806, 782-789] (-40 LOC)+- `delete:` 通知权限注册为同一主窗口做了两遍,其中一遍结构上不可达:`build_main_window` 在建窗后已有守卫块 `if !_notification_handlers_registered.swap(true, SeqCst) { ..with_webview(enable_notification_permissions) }`(builder.rs:715-731),而 `window.rs` 自己的 `on_page_load` 里又是同一把 `Arc<AtomicBool>` 的 `swap(true)` + 同一调用(window.rs:109-138)——前者的 swap 先把标志置真,所以 `on_page_load` 那条路径永不执行,这正是 window.rs:75-78 作者自述「本函数在主窗口可能压根没执行」的原因。合并成 `build()` 之后一次无条件 `enable_notification_permissions`,同时删掉 `disable_external_drop` 的 before/after 取值回读与诊断日志(只留 `controller.SetAllowExternalDrop(false)`)。 [src-tauri/src/desktop/builder.rs:715-731; src-tauri/src/desktop/window.rs:75-107, 109-138] (-55 LOC)+- `shrink:` 同一段「JSON 字符串包裹值」解包惯用法 `v.as_str().and_then(|s| serde_json::from_str(s).ok()).or_else(|| Some(v.clone()))` 写了四遍,抽一个 `fn unwrap_json_object(value: &serde_json::Value) -> Option<&serde_json::Value>`。 [src-tauri/src/config/setting.rs:310-314, 256-267; src-tauri/src/config/window_state.rs:101-107; src-tauri/src/desktop/pet.rs:72-76] (-14 LOC)+- `shrink:` 窗口几何采样在两个事件臂里逐字重复:`WindowEvent::Moved` 与 `WindowEvent::Resized` 都是 `pet::PET_WINDOW_LABEL => pet::save_pet_window_geometry(window)` / `MAIN_WINDOW_LABEL => config::save_geometry(window)` / `_ => {}`,抽 `fn sample_window_geometry(window)` 由两处调用。 [src-tauri/src/desktop/builder.rs:1279-1285, 1291-1298] (-4 LOC)+- `shrink:` 删掉 `#[cfg(windows)] fn windows_drag_browser_args() -> &'static str { WINDOWS_DRAG_BROWSER_ARGS }`;唯一用途是 `.additional_browser_args(windows_drag_browser_args())`,直接写常量。 [src-tauri/src/desktop/builder.rs:74-76, 616, 777] (-3 LOC)+- `shrink:` 两处 `.about(..)` 分支各自重写一遍 `.add_item(&PredefinedMenuItem::about(..))`,`install_macos_menu` 与 `sync_macos_fullscreen_menu` 的全屏菜单文案表达式也重复两次;各抽一个 `fn set_fullscreen_menu_label` / 单一 about 构造即可。 [src-tauri/src/desktop/builder.rs:295-311, 405-421, 466-470] (-24 LOC)+- `shrink:` `push_pet_session` 内联的 `match action` 把 create/update/remove 映射到 `session:*` 又写了一遍(同一映射也存在于 `session_event_of`),删除内联 match 改调 `session_event_of`。 [src-tauri/src/bridge/pet.rs:309-314 vs 336-344] (-8 LOC)+- `shrink:` 手写 PNG IHDR + WebP VP8X/VP8L/VP8 头解析器(逐字节位运算取宽高)与已在本仓 `Cargo.toml` 的 `image = "0.25"`(`image::image_dimensions` / `ImageReader`)重复,改用后者。 [src-tauri/src/bridge/pet.rs:822-861] (-55 LOC)+- `delete:` 16 个后端 i18n 键从没被查过,删掉这些 match 臂:`runtime.unsupported_platform` / `runtime.title` / `runtime.not_found` / `runtime.incompatible` / `harness.title` / `harness.core_not_found` / `harness.manifest_invalid` / `harness.asset_not_found` / `harness.hash_mismatch` / `harness.start_failed` / `harness.health_unhealthy` / `process.manager_poisoned` / `config.load_failed` / `config.save_failed` / `download.failed` / `install.downloaded`。搜索串 `runtime.unsupported_platform|runtime.title|harness.title|config.load_failed|download.failed|install.downloaded`(`src-tauri/src` 0 命中;仅前端 `src/**` 另有同名键走前端 i18n)。保留 23 个 `menu.*`(builder.rs:276-466)与 3 个 `install.*`(service/workflow/install.rs:140,203,226)。 [src-tauri/src/config/i18n.rs:20-95] (-32 LOC)+- `yagni:` 派生的 `pub fn pet_stream_wanted(app) -> bool` 恒等于 `status.enabled`:`status.visible` 就是 `setting.pet_enabled`,`enabled && visible` 是死合取,直接返回 `enabled`(或让 `PetStatus::visible` 这个「恒等于 enabled、只为契约稳定保留」的字段真正退役)。 [src-tauri/src/bridge/pet.rs:459-463(含 visible 赋值 :196-206)] (-2 LOC)+- `yagni:` `src-tauri/src/task/mod.rs` 只有一行 `pub mod tick_check_dsh_process;`,被它包住的模块只有一个 `trigger`,唯一调用方是 `src-tauri/src/service/scheduler/mod.rs:19`。合并为 `task::trigger`(删一行 mod + 两层模块目录)。 [src-tauri/src/task/mod.rs:1; src-tauri/src/task/tick_check_dsh_process/mod.rs] (-3 LOC)+- `shrink:` `read_preset_catalog` 的 6 个「形状检查」是 6 段同形 `if <cond> { return Err(format!("PET_PRESET_CATALOG_INVALID: preset {:?} must ...", spec.id)) }`(安全 id / id 唯一 / name 非空 / config 非空 / uri.default 非空 / kind ∈ {dsh,codex}),改成一张 `[(字段名, 判定闭包)]` 表循环。 [src-tauri/src/bridge/preset_pet.rs:29-67] (-25 LOC)+- `shrink:` 「标记 preinstall 已完成 + 写入 preset 指纹」这段 `let mut setting = get_store_dat_setting(); setting.preinstall_done = true; if let Some(hash) = current_preset_hash() { setting.preset_hash = Some(hash) }; set_store_dat_setting(..)` 在 `install_preinstall_plugins`(早退分支 + 尾部分支)与 `skip_preinstall_plugins` 里写了三遍,抽 `fn mark_preinstall_done(app_handle)`。 [src-tauri/src/bridge/plugin.rs:33-41, 63-69, 130-138] (-12 LOC)+- `yagni:` `CLOSE_ACTION_TRAY` / `CLOSE_ACTION_QUIT` 是 `close_action` 取值域的第二份真值(第一份在 `config::setting` 的 `default_close_action` / `normalize_close_action`);把常量搬到 `config::setting` 并让 builder.rs:1242 与 activation.rs:39 都引用同一份。 [src-tauri/src/desktop/activation.rs:14, 17] (-4 LOC)+- `yagni:` 「整对象写」与 `preserve_persisted_fields` 两套写路径重叠:`set_store_dat_setting` 自述是「兼容旧调用方的整对象写入」,但它其实是**主**写入路径(19 处外部调用,见 `bridge/config.rs:116`、`bridge/plugin.rs:39,68,136`、`bridge/lifecycle.rs:121,243,270`、`service/**` 12 处),归一化块又和 `read_store_dat_setting` / `update_store_dat_setting` 各写一遍(`zoom_factor` / `harness_max_heap_mb` / `close_action` / `normalize_backup_fields`)。合并成唯一写路径 + 一个 `fn normalize_setting(&mut Setting)`。 [src-tauri/src/config/setting.rs:318-321, 342-348, 354-365, 378-382] (-22 LOC)+- `shrink:` `set_dsh_pkg_commit` / `set_dsh_pkg_tag` 各自「读整对象 → 改一个字段 → 整对象写回」;两个调用方都是背靠背成对调用(`bridge/lifecycle.rs:205-206`、`service/workflow/install.rs:217-218`),合成一个经 `update_store_dat_setting` 的 `set_dsh_pkg_identity(app, commit, tag)`:写盘次数减半、这一对变原子。 [src-tauri/src/config/setting.rs:405-409, 417-421] (-8 LOC)+- `shrink:` `let timer = OffsetTime::new(..)` 与 `let file_timer = OffsetTime::new(..)` 构造同一个格式串 `"[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]Z"` 两遍,构造一次复用。 [src-tauri/src/logger/mod.rs:309-315, 316-322] (-6 LOC)+- `shrink:` 写盘序列「加锁 → `ensure_file` → `f.write` → `f.flush` → `drop(guard)` → `rotate_if_needed`」在 `append_bytes` / `impl Write for SizeRotatingWriter` / `impl Write for SizeRotatingWriterGuard` 里各写一遍,抽 `fn write_and_rotate(&self, buf: &[u8]) -> io::Result<usize>`。 [src-tauri/src/logger/mod.rs:162-175, 179-191, 215-225] (-18 LOC)+- `shrink:` `read_tail` 与 `read_backend_tail` 两个闭包是同一段 `exists() → read_to_string → lines → saturating_sub → join`,只差一个 `.filter(|line| !is_frontend_log_line(line))`,加个 `filter_frontend: bool` 参数。 [src-tauri/src/bridge/system_os.rs:206-214, 217-228] (-8 LOC)+- `native:` `reveal_data_dir` 手搓 `Command::new("explorer"|"open"|"xdg-open")` 分支,而同一文件往下 5 行的 `open_dir` 就是 `tauri_plugin_opener::open_path(&path, None::<&str>)`;改成同一个调用(保留 `create_dir_all`)。 [src-tauri/src/bridge/system_os.rs:74-95 vs 69] (-18 LOC)+- `delete:` `get_preinstall_plugins` 是 `pub async fn` 但体内只有 `Ok(plugin::list(&app_handle))`(纯同步、无 await),命令名保留、去掉 async 包装。 [src-tauri/src/bridge/plugin.rs:13-18] (-2 LOC)+- `delete:` `fn disable_external_drop` 的 before/after 取值回读 + `log::info!`/`log::warn!` 诊断,作者注释自述「下面的日志就是用来判定的(本函数在主窗口可能压根没执行,见 #591 follow-up)」——诊断使命已由代码里的结论完成,只留 `controller.SetAllowExternalDrop(false)` 与错误分支。 [src-tauri/src/desktop/window.rs:79-107] (-25 LOC)+- `shrink:` `take_pending_accessory` 的 `let was_pending = *pending; *pending = false; was_pending` 就是 `std::mem::replace(&mut *slot, false)`;连带 `fn pending_accessory_slot()` 这个 4 行取值器(为 2 行 static 而写、且只服务同一文件)一起内联。 [src-tauri/src/desktop/activation.rs:64-67, 78-86] (-8 LOC)+- `shrink:` `pub fn get_node_version_of_path(node: &Path) -> Option<String> { get_node_version_of(node) }` 是到私有 `get_node_version_of` 的纯转递(唯一调用方 `service/core/runtime.rs:1280`),删掉并对内改 `pub(crate)`。 [src-tauri/src/config/runtime.rs:536-539] (-4 LOC)+- `shrink:` `fn dsh_core_base_url() -> &'static str { DSH_CORE_URL }` 是常量的 3 行取值器,两个调用点都在同文件(runtime.rs:97、:114),直接用 `DSH_CORE_URL`。 [src-tauri/src/config/runtime.rs:75-77] (-3 LOC)+- `shrink:` `fn simplify_resource_root(path) -> PathBuf { dunce::simplified(&path).to_path_buf() }` 只有两个用途(生产 manifest.rs:391 + 测试 manifest.rs:986),内联该表达式。 [src-tauri/src/config/manifest.rs:396-398] (-4 LOC)+- `yagni:` `config/format.rs` 整个模块只有一个函数 `pub fn get_dsh_service_url(port) -> String { format!("{}:{}", DSH_HOST, port) }`,连同 `config/mod.rs` 的 3 行声明可以并进 `constants.rs`(或让 7 个调用点自己拼)。 [src-tauri/src/config/format.rs:1-6] (-5 LOC)+- `yagni:` `resources/manifest.jsonc` 的 `engines` 段为 `node` / `pnpm` / `git` 各给了一份 `version` + `sha256`,但 Rust 侧 `struct Engines` 只有 `dsh: DshEngine` 一个字段(serde 默认忽略未知字段),这三个值读从不被读——真实版本/摘要都在 `config/constants.rs`(`NODE_VERSION`、`PNPM_VERSION`、`PNPM_SHA256`、`MINGIT_*`)。删掉这三段(搜索串 `engines|"engine"|DshEngine|struct Engines`,14 命中,全部指向 `engines.dsh`)。 [src-tauri/resources/manifest.jsonc:7-20] (-14 LOC)+- `delete:` `disable_external_drop` 的调用点与「主窗口的守卫已被提前消费」这一结论并存(同 f3),若保留 `disable_external_drop` 则至少要让它从真正会执行的路径挂载,否则它连同 `on_page_load` 的 `Arc<AtomicBool>` 参数都是空转的线。 [src-tauri/src/desktop/window.rs:75-78, 109-138] (-0 LOC,见 f3)++## Considered and rejected++- `src-tauri/src/bridge/mod.rs:1-30` 的 13 个 `pub use <mod>::*` 被当成「双重路径 yagni」——不成立:`generate_handler!` 与全仓调用点都用重导出名(`crate::bridge::<cmd>`),glob 是唯一注册机制,且这些 handler 是硬豁免面。+- `src-tauri/src/config/mod.rs:1-22` 同时 `pub mod manifest` 与 `pub use manifest::{..}`——两条路径都有真实调用方(`config::dependencies::active_root` / `config::get_dsh_install_path` 并存),保留。+- `src-tauri/src/desktop/mod.rs:1-19` 的 `pub use builder::{builder, handler, setup, tray};`——四项都是 `lib.rs` 的入口,不是单调用方转发层。+- `src-tauri/src/logger/mod.rs:identifier_dir()` 手搓 `%APPDATA%` / `Application Support` / `XDG_DATA_HOME` 而不走 `AppHandle::path().app_data_dir()`——文档写明它要在任何 `AppHandle` 存在之前被 `config::force_xwayland_setting` 调用,属正当。+- `SizeRotatingWriter` 本身——`tracing-appender` 的 rolling appender 是按天滚动,本仓要按字节滚动(5 MiB × 3 份),无替代。+- `src-tauri/src/bridge/system_os.rs:111-118 tail_bytes`——按字节取后缀且要落在 UTF-8 边界,稳定版 `str::floor_char_boundary` 仍是 nightly,手写循环正当。+- `src-tauri/src/config/runtime.rs:154 is_executable`(`mode & 0o111`)与 `src-tauri/src/service/cli/path/pnpm.rs:147 pnpm_is_executable` 是同一规则的两份实现(后者在 `service/`,不由本报告处置)——跨域重复,记录不裁。+- `src-tauri/src/config/manifest.rs:580-668` 的 `strip_jsonc` + `strip_trailing_commas` 是两趟字符扫描、各自带一份字符串字面量状态机(584-606 与 631-653 几乎逐字相同)。抽一趟同时产出两种变换可省约 40 行;换成 `json5` / `jsonc-parser` 依赖可省约 80 行,但要 +1 dep——本报告按「不新增依赖」计 0 行,留给维护者选;`serde_json` 已在依赖里但原生不支持注释与尾逗号。+- `src-tauri/src/desktop/autostart.rs` 的 ~270 行 `#[cfg(test)]` 系统集成测试(CI / `DSH_RUN_AUTOSTART_TESTS` 门控,`auto-launch 0.5` 仅 dev-dependency)——测试不是「过度设计」,但它是本域最大的测试尾,记录备查。+- `src-tauri/src/config/theme.rs` 两个手写 `settings.yaml` 迷你解析器——`serde_yaml` 虽在依赖里,但这里只按键取一行、且要容忍 legacy 与 profile 两种布局,属正当。+- `src-tauri/src/desktop/linux_tray.rs`(118 行)——文件头文档说明是 tauri 2.11.5 钉 `tray-icon ^0.24`(Linux 只有 libappindicator 后端、不报事件)与 0.25 KSNI + muda 0.19/0.20 类型分叉的临时绕行,tauri 2.x bump 后可整文件删除,属上游版本 workaround。+- `src-tauri/src/desktop/{paste.rs, compat.rs, frame_log.rs, plugin_boot.rs, tauri_internals.rs, deep_link.rs, zoom.rs, payload.rs}` 与 `src-tauri/src/bridge/{core,profile,updater,backup,remote,guard}.rs`——逐个读过:都是单目的垫片或 `#[tauri::command]` 转发层,每个都有一段命名具体失败(`AbortSignal.any` 缺失、pdf.js `Iterator.prototype.join`、WebKitGTK 剪贴板图片、跨源 iframe `__TAURI_INTERNALS__` 骨架)的说明,无内部过度设计。+- `src-tauri/Cargo.toml` 依赖表——逐项核对引用(`serde_yaml` 在 `service/**` 大量使用、`auto-launch` 仅测试、`winreg`/`webview2-com`/`windows-core`/`rfd` 均有调用点),没有可删依赖。+- `src-tauri/capabilities/desktop.json` 是 `"platforms": ["macOS","windows","linux"]` + `"permissions": []` 且在途没有唯一窗口授权——权限标识与能力声明是硬豁免面,不裁;但它当前不贡献任何授权,属纯脚手架,记录不裁。+- `src-tauri/build.rs`(3 行)与 `src-tauri/src/main.rs`(19 行,`--patch-core` 是用户 CLI 旗标)——无发现。++## net: -397 lines, -0 deps possible. (-1 dep if `strip_jsonc` is replaced by a JSONC crate, +80 lines more裁掉)diff --git a/docs/audit/tooling-config-tests.md b/docs/audit/tooling-config-tests.mdnew file mode 100644index 00000000..b5dc5b2c--- /dev/null+++ b/docs/audit/tooling-config-tests.md@@ -0,0 +1,47 @@+# Tooling · configs / scripts / tests — ponytail-audit++> Scope: root configs, scripts/, genapi*, test/, .github/, patches/, skills/, public/, types/ · ~7k LOC · read 2026-09-30++## Findings (ranked, biggest cut first)++`shrink: seven hand-rolled char scanners in genapi.pipeline.ts all re-implement the same quote/depth walk (splitTopLevel 133-170, splitMembers 181-219, genericArgs 232-264, genericOf 266-299, sliceBalanced 301-330, sliceDeclaration 332-366, scanArrow 702-732 = 233 LOC). Replace with one parameterized scanner scan(src, start, {stopOn, trackAngle, stopAtNewline}) ≈ 70 LOC; or drop the parsers to the TypeScript compiler API already in the tree (scripts/build-plugins.ts:136-158 does the sibling job `relativeSpecifiers` in 23 LOC via ts.createSourceFile + ts.forEachChild, typescript ~5.8.3 in pnpm-workspace.yaml). [genapi.pipeline.ts:133-366,702-732] (-150 LOC)`++`delete: test/e2e/probe-wdio.ts — self-declared "D0 临时探针", spawns the debug exe and polls ports over raw HTTP. ripgrep for "probe-wdio" over the whole repo (excl. node_modules/dist/target): No matches found — no package.json script, no .github workflow, no test imports it. The real WebDriver path is used by test/e2e/desktop/*.e2e.ts. [test/e2e/probe-wdio.ts:1-212] (-212 LOC)`++> Lead 复核修正:文件实际 212 行(非 251),全仓引用仍为 0(`git grep -n --fixed-strings "probe-wdio" -- .` 无命中,`docs/**` 亦无)。但其头部注释自称「保留为不依赖 WDIO 的最小诊断通道之一」——属于作者声明式保留而非协议面,删除前需向作者确认(见 README「需人工确认」)。++`delete: postcss.config.js — Tailwind already enters the build twice elsewhere: @tailwindcss/vite (vite.config.ts:16) for the shell, and packages/dsh-tauri-ui/scripts/taiwindcss.ts:48 which passes plugins programmatically (postcss([tailwindcss(...)]).process(rawCss, ...)) so no config-file lookup happens. ripgrep "postcss.config": 0 hits; the only other postcss hits are package.json:88,113, pnpm-workspace.yaml:121,125, packages/dsh-tauri-ui/package.json:70,73 (dependency findings excluded) and taiwindcss.ts:6-7. [postcss.config.js:1-5] (-5 LOC)`++> Lead 复核补充:`vite.config.ts` 未设置 `css.postcss`,而 Vite 会**隐式自动加载** postcss.config.js —— 这种引用 grep 看不见。grep 证据只能证明「没有显式引用」,不能证明「未被隐式消费」;本仓禁止跑构建,故该条降级为需人工确认(见 README「需人工确认」)。++`yagni: two tsconfigs that differ only in build-script inclusion — tsconfig.json:33 adds scripts/build-plugins.ts back and tsconfig.node.json:10 excludes it, with composite:true + references existing only to satisfy that split. Fold into one tsconfig.json (include src, test, packages/*/src, packages/*/scripts, types, scripts) and delete tsconfig.node.json, letting typecheck also cover vitest.*.config.ts / genapi.* / bump.config.ts, which today are in NO tsconfig and therefore never typechecked. [tsconfig.json:25-34, tsconfig.node.json:1-11] (-11 LOC, +0 files)`++`yagni: four vitest config files where three would do — vitest.config.ts is a defineConfig whose entire body is one active line (`projects`); its resolve.alias (18-22) and coverage.exclude (32-44) are mirrored from the unit project / coverage defaults, and by its own header comment at :11 a project-level config cannot even inherit that alias. The three project files then repeat the same envelope (name/include/globalSetup/environment:node/fileParallelism:false/timeouts). Keep the three defineProject files, move `projects`, coverage and shared alias into a plain module both they and vitest.config.ts import. [vitest.config.ts:16-45, vitest.unit.config.ts:27-56, vitest.plugin.config.ts:17-27, vitest.desktop.config.ts:16-25] (-25 LOC)`++`shrink: four copies of the same `@` -> src alias with two different spellings — vite.config.ts:31 as the string '/src', vitest.config.ts:18-22 and vitest.unit.config.ts:28-32 as fileURLToPath(...). Export one SHARED_ALIAS const and import it in all three. [vite.config.ts:31, vitest.config.ts:18-22, vitest.unit.config.ts:28-32] (-8 LOC)`++`shrink: test-source readers are re-declared per file — readSource(relativePath) verbatim twice (test/clipboard-image-bridge.test.ts:16, test/pet-window-lifecycle.test.ts:16), readLocale(name) verbatim twice (test/navbar-maximize-icon.test.ts:16, test/navbar-run-menu.test.ts:20), navbarSource = readFileSync('../src/layout/components/navbar.tsx') four times (test/menu-restart.test.ts:12-15, test/navbar-mask-mirror.test.ts:13-16, test/navbar-maximize-icon.test.ts:11-14, test/navbar-run-menu.test.ts:15-18), and 6 one-line arrow readers for one module each in test/core-upgrade-profile.test.ts:12-17. Add test/setup/read-source.ts exporting readSource(rel) / readLocale(name) / readNavbar() and use it at every one of those sites. [test/clipboard-image-bridge.test.ts:16, test/pet-window-lifecycle.test.ts:16, test/navbar-maximize-icon.test.ts:11-16, test/navbar-run-menu.test.ts:15-20, test/menu-restart.test.ts:12-15, test/navbar-mask-mirror.test.ts:13-16, test/core-upgrade-profile.test.ts:12-17] (-45 LOC)`++`shrink: seven test files assert on raw source text of app files instead of behaviour, so every refactor must edit two files — test/shell-theme-alignment.test.ts (splits src/styles/main.css on /^html\[data-theme="light"\] \{/m and asserts literal --accent: #f9fafb / #0f1115 / --accent-foreground #0f1115 / #ffffff; then toContain 5 literal lines of tailwind.config.js), test/navbar-maximize-icon.test.ts:5-7+49-56, test/navbar-run-menu.test.ts:63-73, test/navbar-mask-mirror.test.ts:24-28, test/menu-restart.test.ts:17-64 (indexOf ordering inside builder.rs + i18n regex), test/wdio-e2e-gate.test.ts:24-30, test/plugin-patch-targets.test.ts:47-58. Coverage stays (exclusion 2) — the cut is the duplication: keep the token→value assertions, drop the "assert the source still spells the implementation this way" regexes where the same contract is already covered at runtime, and centralise the ones that must stay. [test/shell-theme-alignment.test.ts:12-76, test/navbar-maximize-icon.test.ts:49-56, test/navbar-run-menu.test.ts:63-73, test/navbar-mask-mirror.test.ts:24-28, test/wdio-e2e-gate.test.ts:24-30] (-40 LOC)`++---++Also spotted, below the noise floor of the ranking (listed for completeness, no separate LOC claim): test/navbar-run-menu.test.ts:20 and test/navbar-maximize-icon.test.ts:16 are byte-identical `readLocale` bodies reading the same zh-CN/en-US JSON; test/backup.test.ts, test/plugin-uninstall.test.ts, test/plugin-disable.test.ts, test/setup-copy-logs.test.ts, test/close-action.test.ts each repeat the `readFileSync(new URL('../src/...'), 'utf8')` shape 4-12 times — those calls carry per-site path arguments, so folding them is cosmetic and NOT counted above.++## Considered and rejected++- `.github/workflows/**` scripts — every named script is live protocol surface: `scripts/bundle-metadata.mjs` (.github/actions/prepare-bundle-resources/action.yml:133,173 and release-bundle.yml:172,206 incl. a `git cat-file -e` existence check), `scripts/release-identity.mjs` (release.yml:70), `scripts/fix-appimage-host-libs.sh --require-removal` (build-linux.yml:80, asserted by test/appimage-host-libs.test.ts:149,155). Not dead, not touched.+- `tailwind.config.js` + `tailwind.plugins.config.js` — both live and deliberately independent: referenced by `@config "../../tailwind.config.js"` in src/styles/main.css:3 / src/pet/main.css:3, and `@config "../../../../../tailwind.plugins.config.js"` in packages/dsh-tauri-ui/src/client/styles/index.css:13; `tailwind.plugins.config.js` exists to stop the plugin artifact from rescanning the shell's tokens. taiwindcss.ts:20 whitelists exactly these two. Two token families, two files — correct, not duplication.+- `scripts/rebuild-macos-icon.ts` — fills a real gap: `tauri icon` does not emit macOS tray-size assets, so the script composes the Apple 1024 grid (DOCK_SCALE 12.875, DOCK_GUTTER 100) and then reuses the CLI (`node node_modules/@tauri-apps/cli/tauri.js icon`) rather than reimplementing it.+- `scripts/build-plugins.ts` `materializeTree` (57-79) instead of `fs.cpSync(..., { dereference: true })` — the comment at 44-56 records that dereference regressed in Node 22.17 (nodejs/node#59168) and produces absolute links into a deleted temp dir, breaking `tauri build` with "resource path ... doesn't exist". Justified `native:`-looking code.+- `scripts/build-debug.ts` (56) — its only native-looking part is the temp `tauri-e2e.json` overlay; without it the root tauri.conf.json beforeBuildCommand runs twice. Deleting the script would move 3 build steps into CI YAML, not remove them. ~10 LOC at best; below the ranking cut-off.+- `build:taiwindcss` script — NOT dead: docs/specs/plugin.client.md:122 tells contributors to run `pnpm build:taiwindcss` before committing, and packages/dsh-tauri-ui/scripts/taiwindcss.ts:41 documents the same entry point.+- `test/setup/tauri-runtime.ts` — not dead: wired via vitest.unit.config.ts:52 (mockIPC + mockWindows for shell modules that touch Tauri at import time).+- `test/e2e/support/selectors.ts` / `preinstall.ts` / `onboarding.ts`, `setup-desktop.ts`, `setup-plugin.ts` — all consumed; selectors.ts:7-8 states it already prunes anchors with no consumer.+- No knip config file exists anywhere in the tree (git ls-files: none), so the `knip` script neither hides findings nor is itself dead.+- ESLint ignores correctly do not cover `archive/` or `test/archive/`, but those directories are out of audit scope by rule.+- `patches/bumpp.patch`, `patches/@[email protected]`, `types/slot-outlet.d.ts`, `skills/handle/SKILL.md`, `public/*.wav|*.svg`, `index.html`, `pet.html`, `.env.example`, `.editorconfig`, `bump.config.ts`, `genapi.config.ts` — all referenced or shipped surface; no finding.++## net: -496 lines, -0 deps possible.++> Lead 复核后修正:probe-wdio 实际 212 行(-251 → -212),故小计由 -535 修正为 -496。diff --git a/package.json b/package.jsonindex a76e5e42..0ba0a52c 100644--- a/package.json+++ b/package.json@@ -23,7 +23,6 @@"test:e2e:plugin": "vitest --project plugin","test:e2e:desktop": "vitest --project desktop","lint": "eslint",- "knip": "knip","lint:fix": "eslint . --fix","typecheck": "tsc --noEmit","icons": "tauri icon public/favicon.svg && tsx scripts/rebuild-macos-icon.ts"@@ -32,7 +31,6 @@"@choochmeque/tauri-plugin-notifications-api": "catalog:","@genapi/pipeline": "catalog:","@gravity-ui/icons": "catalog:runtime",- "@hairy/utils": "catalog:utils","@heroui/react": "catalog:runtime","@heroui/styles": "catalog:runtime","@overlastic/react": "catalog:runtime",@@ -76,13 +74,11 @@"@deepseek-ai/dsh-permission-presets": "catalog:dsh","@deepseek-ai/dsh-session": "catalog:dsh","@deepseek-ai/dsh-skill-filesystem": "catalog:dsh",- "@deepseek-ai/dsh-storage-domain": "catalog:dsh","@deepseek-ai/dsh-tools": "catalog:dsh","@deepseek-ai/dsh-user-approval": "catalog:dsh","@deepseek-ai/dsh-workspace": "catalog:dsh","@eslint-react/eslint-plugin": "catalog:lint","@genapi/core": "catalog:",- "@genapi/parser": "catalog:","@genapi/presets": "catalog:","@genapi/shared": "catalog:","@tailwindcss/postcss": "catalog:build",@@ -101,20 +97,15 @@"babel-plugin-react-compiler": "catalog:build","bumpp": "catalog:release","changelogithub": "catalog:release",- "citty": "catalog:utils",- "consola": "catalog:utils",- "dotenv": "catalog:utils","eslint": "catalog:lint","eslint-plugin-react-refresh": "catalog:lint","jsdom": "catalog:testing",- "knip": "catalog:lint","pathe": "catalog:utils","playwright": "catalog:testing","postcss": "catalog:build","publint": "catalog:cli","ssh2": "catalog:utils","tailwindcss": "catalog:build",- "tinyexec": "catalog:utils","tsx": "catalog:build","typescript": "catalog:cli","vite": "catalog:build",diff --git a/packages/dsh-tauri-model/package.json b/packages/dsh-tauri-model/package.jsonindex 6c662a7f..cdbbe896 100644--- a/packages/dsh-tauri-model/package.json+++ b/packages/dsh-tauri-model/package.json@@ -84,7 +84,6 @@"@deepseek-ai/dsh-util-values": "catalog:dsh","@types/node": "catalog:types","dsh-tauri-tsdown": "workspace:*",- "react-if-lite": "catalog:runtime","tsdown": "catalog:cli","vitest": "catalog:testing"}diff --git a/packages/dsh-tauri-model/tsdown.config.ts b/packages/dsh-tauri-model/tsdown.config.tsindex b889e553..3efc8343 100644--- a/packages/dsh-tauri-model/tsdown.config.ts+++ b/packages/dsh-tauri-model/tsdown.config.ts@@ -3,6 +3,5 @@ import { defineDshConfig } from '../dsh-tauri-tsdown/src/index.ts'export default defineDshConfig({client: {dts: true,- noExternal: ['react-if-lite'],},})diff --git a/packages/dsh-tauri-worktree/package.json b/packages/dsh-tauri-worktree/package.jsonindex 09a797aa..b744459f 100644--- a/packages/dsh-tauri-worktree/package.json+++ b/packages/dsh-tauri-worktree/package.json@@ -57,7 +57,6 @@},"dependencies": {"dsh-tauri": "workspace:*",- "hookable": "catalog:utils","lodash-es": "catalog:utils","pathe": "catalog:utils","simple-git": "catalog:utils",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex d77612b9..1a6a5ee5 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -47,9 +47,6 @@ catalogs:'@genapi/core':specifier: ^4.1.4version: 4.1.4- '@genapi/parser':- specifier: ^4.1.4- version: 4.1.4'@genapi/pipeline':specifier: ^4.1.4version: 4.1.4@@ -135,9 +132,6 @@ catalogs:'@deepseek-ai/dsh-skill-filesystem':specifier: 0.2.0-rc.2version: 0.2.0-rc.2- '@deepseek-ai/dsh-storage-domain':- specifier: 0.2.0-rc.2- version: 0.2.0-rc.2'@deepseek-ai/dsh-tools':specifier: 0.2.0-rc.2version: 0.2.0-rc.2@@ -163,9 +157,6 @@ catalogs:eslint-plugin-react-refresh:specifier: ^0.5.4version: 0.5.4- knip:- specifier: ^6.32.2- version: 6.32.2release:bumpp:specifier: 12.2.1@@ -290,24 +281,12 @@ catalogs:specifier: ^18.0.10version: 18.0.11utils:- '@hairy/utils':- specifier: ^1.52.0- version: 1.52.0- citty:- specifier: ^0.2.2- version: 0.2.2- consola:- specifier: ^3.4.2- version: 3.4.2cron-schedule:specifier: ^6.0.0version: 6.0.0date-fns:specifier: ^4.4.0version: 4.4.0- dotenv:- specifier: ^17.4.2- version: 17.4.2hookable:specifier: ^6.1.1version: 6.1.1@@ -332,9 +311,6 @@ catalogs:ssh2:specifier: ^1.17.0version: 1.17.0- tinyexec:- specifier: ^1.3.0- version: 1.3.1unstorage:specifier: ^1.17.5version: 1.17.5@@ -356,9 +332,6 @@ importers:'@gravity-ui/icons':specifier: catalog:runtimeversion: 2.21.0([email protected])- '@hairy/utils':- specifier: catalog:utils- version: 1.52.0'@heroui/react':specifier: catalog:runtimeversion: 3.2.4(@react-aria/[email protected]([email protected]([email protected]))([email protected]))(@react-aria/[email protected]([email protected]([email protected]))([email protected]))(@react-aria/[email protected]([email protected]([email protected]))([email protected]))(@react-spectrum/[email protected]([email protected]([email protected]))([email protected]))(@types/[email protected](@types/[email protected]))(@types/[email protected])([email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])([email protected])@@ -483,9 +456,6 @@ importers:'@deepseek-ai/dsh-skill-filesystem':specifier: catalog:dshversion: 0.2.0-rc.2(@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))))))(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))))- '@deepseek-ai/dsh-storage-domain':- specifier: catalog:dsh- version: 0.2.0-rc.2(@deepseek-ai/[email protected])(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))(@deepseek-ai/[email protected](@deepseek-ai/[email protected]))'@deepseek-ai/dsh-tools':specifier: catalog:dshversion: 0.2.0-rc.2(52b5a8ab481be2b3d891c22a71641755)@@ -501,9 +471,6 @@ importers:'@genapi/core':specifier: 'catalog:'version: 4.1.4- '@genapi/parser':- specifier: 'catalog:'- version: 4.1.4'@genapi/presets':specifier: 'catalog:'version: 4.1.4@@ -558,15 +525,6 @@ importers:changelogithub:specifier: catalog:releaseversion: 15.0.5- citty:- specifier: catalog:utils- version: 0.2.2- consola:- specifier: catalog:utils- version: 3.4.2- dotenv:- specifier: catalog:utils- version: 17.4.2eslint:specifier: catalog:lintversion: 10.8.1([email protected])@@ -576,9 +534,6 @@ importers:jsdom:specifier: catalog:testingversion: 26.1.0- knip:- specifier: catalog:lint- version: 6.32.2pathe:specifier: catalog:utilsversion: 2.0.3@@ -597,9 +552,6 @@ importers:tailwindcss:specifier: catalog:buildversion: 4.1.11- tinyexec:- specifier: catalog:utils- version: 1.3.1tsx:specifier: catalog:buildversion: 4.23.12@@ -857,9 +809,6 @@ importers:dsh-tauri-tsdown:specifier: workspace:*version: link:../dsh-tauri-tsdown- react-if-lite:- specifier: catalog:runtime- version: 0.1.0([email protected])tsdown:specifier: catalog:cliversion: 0.17.4(@emnapi/[email protected])(@emnapi/[email protected])([email protected])([email protected])([email protected])([email protected])@@ -1130,9 +1079,6 @@ importers:dsh-tauri:specifier: workspace:*version: link:../dsh-tauri- hookable:- specifier: catalog:utils- version: 6.1.1lodash-es:specifier: catalog:utilsversion: 4.18.1@@ -2539,137 +2485,12 @@ packages:react: '>=18'react-dom: '>=18'- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-n9uozULWflPqBtdmI8lAabLqGKNgLVNN0ZH8HfgCwpKGNtzRzauB76jTiW/3YLkcA7N1zskpi9GdVnZuu1SAvg==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm]- os: [android]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-9BbdjHETk6O3zH/DDid9IgBtF0GlpLabNKN231uraXpRDSfY+iiZxTP5bk1Z63GBownVdhdINFIeddmMz4MzpQ==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm64]- os: [android]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-gh+6ecoHUy4/sUcolBl/1qPXKBbYNxFY0Pk0ujgQvINTMSftJY7o4yb8gOkDJPeZeB8+a+u7xTe6umoP8N5HFA==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm64]- os: [darwin]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-qd1hl2d+lXgHv/VQ/M9qm8TrMC5T4RqDBwtOnl+1D0QMjwcz+8AaB4JSg8STgeag0GP6a6L74XEGAsrTSJWNzQ==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [x64]- os: [darwin]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-M5XXcNa7aOqLPKTR41msfghKu2yQ4xWvCm11/gwU0JzOzHNk5sgW//rVEjJ+LO48+VDAMzXTSzurUVxIDKwozw==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [x64]- os: [freebsd]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-T/GXusuOkPNQhCQCSBbcU/N8j0rAypuDBl1IyFK+lyYT594XsVz80clPC/OtbSSpBGyJxj8uYEfctxVuxVYoww==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm]- os: [linux]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-oKu4RcBlXSqo3OC62dp6YTnQaZIurNDpCX3BnAM3+bJxt7s8J2TJKMnC0UYer1qhlRaDCg6wkTaTw+2IlsZ12w==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm]- os: [linux]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-WJBbD186AZmMGaSIhlktC+rPl8L3peCTXAh88Ih9uEvK0en2mPojGyCGYiL6mHtV1RPV3JyfJW5t6n5hh0lXhA==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm64]- os: [linux]- libc: [glibc]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-t1AcYOwEzgceadT4v5e+vaCCb0AncCA3v5AyzfBAz/tMq11qzVccXKzNHtkWdjBsgvTKwRkaUF3QvT4kot8vcQ==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm64]- os: [linux]- libc: [musl]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-RsnO/NoD8376LMJq8JS8TwI0ieNaFRTuNe2GVJntQg6gwZNMENZsEbknHdVwjpOmxdGLGodcwaGSbAeRr5Bgjw==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [ppc64]- os: [linux]- libc: [glibc]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-48fSVfR9TZi5CASZFyv0VC6z6BCoeihFsX031mAD/oSH7d9PYsPgIqza7d9mjP7Z2KTEpTFyH6SIu0Ui6R1vdg==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [riscv64]- os: [linux]- libc: [glibc]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-T8CpdD+SfE01DnIOD4HpVxu0ZJOfMJ/VhCvikKfaXAxkZ+9veyLM/D2hpi7Y2hFUyPmVQO3FNZHmYzV/WlVR4g==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [riscv64]- os: [linux]- libc: [musl]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-QLdeMsCcacenPEFsfxnBUDF1y6opyz5+fmOz9bfD5Y7fiGCMupUCuB3KTPQhNwshIG1P9fPqar9MHxuBDd4bwQ==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [s390x]- os: [linux]- libc: [glibc]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-659ujfqLy6k7cuH3sbzhd8b+ztSq+i6E2E9pG78Q0BmHjAExfGIdgc8cGgMdwAozDXeZFHkJ+LXYJdWsaGdgyw==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [x64]- os: [linux]- libc: [glibc]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-/Mw/9j4TfZcnKphPrzOE6t4MMknXadcAAuVUlDRTF/ETWB5xOgQvOJV2Mh9We/bWxZdoxaGAdc+hy4GuYwQ2yQ==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [x64]- os: [linux]- libc: [musl]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-8rIKWR2BFuifbIK/1XB9wTaSdtuJ25dlE7ZQYDnEwj/2xH2vHsxnvIjHT3ZjSVuLLwGGlSslIG/fbOJ8TV8rTw==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm64]- os: [openharmony]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-5U9kQYMfRRI6Zq7KDxgbIP0RMnKrfn3gLepRMgJuRkPSUALTiRCk9d/uyhb4lGDjUdzwK7mBkKqhLgzBPCmLpQ==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [arm64]- os: [win32]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-25P7AaHk4R88Yv2XH4gToDVmh0cOu+bEURQU10CRrmvgabfRArSGAP5osmwUKeSUHj0VS50upbpbRWWW/m7mHA==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [ia32]- os: [win32]-- '@oxc-parser/[email protected]':- resolution: {integrity: sha512-ORMh3JE1s6V7ySicdRK7vgaDQnn5o+UHg9ct989PlWHbel8O9ARrmWXM6kZjrBMtNucxNayQ8g69G0VfWzhANw==}- engines: {node: ^20.19.0 || >=22.12.0}- cpu: [x64]- os: [win32]-'@oxc-project/[email protected]':resolution: {integrity: sha512-nuFhqlUzJX+gVIPPfuE6xurd4lST3mdcWOhyK/rZO0B9XWMKm79SuszIQEnSMmmDhq1DC8WWVYGVd+6F93o1gQ==}'@oxc-project/[email protected]':resolution: {integrity: sha512-aIYXQBo4lCbO4z0R3FHeucQHpF46l2LbMdxRvqvuRuW2OxdnSkcng5B8+K12spgLDj93rtN3+J2Vac/TIO+ciQ==}- '@oxc-project/[email protected]':- resolution: {integrity: sha512-u6JZdLBTLotrNC9Vd6vPssINdzcCzleKAH6EJKImQb7GtYvX5keN2dxkoK44stCc4tffE6QQRtZTXVSzsLUlWA==}-'@oxc-resolver/[email protected]':resolution: {integrity: sha512-y09e0L0SRI2OA2tUIrjBgoV3eH5hvUKXNkJqXmNo5V2WxIjyC7I7aJfRLMEVpA8yi95f90gFDvO0VMgrDw+vwA==}cpu: [arm]@@ -4886,9 +4707,6 @@ packages:resolution: {integrity: sha512-WtySTkS4OKev5JtpHXnib4Gxiurzh5NCGvWrFaZ34m6JehfTUhKZvn9njTfw48t6JumVQOmrKqpmGcdwxnhqBQ==}- resolution: {integrity: sha512-jKmm9YtsNXN789RS/0mSzOC1NUq9mkVd65vbSSVsKdjGvYXBuE4oWe2QOEoFeRmJg+lPuZxpmrfFclNhoRMneQ==}-resolution: {integrity: sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==}@@ -4932,11 +4750,6 @@ packages:resolution: {integrity: sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==}engines: {node: '>=0.4.x'}- resolution: {integrity: sha512-9XNj/o4wrRFyhSMJOvsuyMwy8aUfBaZ1VrqHVfohyXf0Sw0e+yfKG+xZaY3arGCOMdwFsqObtzVOc1gU9KiT9w==}- engines: {node: '>=18.3.0'}- hasBin: true-resolution: {integrity: sha512-EQsFzMUJkCKGr1ePqlYADkIUmHW1s3ZXr5Yqy6wbGrfUCphpl2maM/kyOIRA2HpP3AaFQTZXD4ldjek+nccddA==}engines: {node: '>=14.14'}@@ -4975,9 +4788,6 @@ packages:resolution: {integrity: sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==}engines: {node: '>=8'}- resolution: {integrity: sha512-Dz/6HxkrxgNehhxLVeyv8sad9UzF2xBVeaKBQNDfJ5XiSXmp2gTR0eO0RWiT2NCKS5aGP9jjkOMggTN90qU50A==}-resolution: {integrity: sha512-XpwZALwwl/BaKTAyC6+c5T8y6kCg2jk+XGqOVrKIQmW49pNypYLMRjCUXqa28tQgJlhS2RlzP7sc+Rx7W6qsfw==}@@ -5329,11 +5139,6 @@ packages:resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}- resolution: {integrity: sha512-WXTXbmocrw7gqm1A1TQvFN0OgJ7hUSU6E1g6SPRIzzHFogUBhXByc7cYeOFVtJ2uODg7DP4VbESYBYnfbtBYsg==}- engines: {node: ^20.19.0 || >=22.12.0}- hasBin: true-resolution: {integrity: sha512-2ZSpGOZclbgJ6wnyWaPJFeYVD+oJ6A7fbcFImBmk7bOQ4Bk39/Yy7cALCnswjT5W/nnz39b2czkQkG/XRKPqWw==}@@ -5835,10 +5640,6 @@ packages:resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==}engines: {node: '>= 0.8.0'}- resolution: {integrity: sha512-ov0NzaDCOInknS7mP1cwKdJERt3utPW8ldjtdUXQ8Ty0GEFD08wk422vCUN0d7pST6kqtV7dxoI9w1Zi0l/9TA==}- engines: {node: ^20.19.0 || >=22.12.0}-resolution: {integrity: sha512-FY91FiDBj7ls5MsFS9jN3tjz2o0/zsdSsymlakySaBwVJZorHhkWyICLZMKxlu1R9vYo+sd3z1jwb4J8x7bNDw==}@@ -6398,10 +6199,6 @@ packages:resolution: {integrity: sha512-SlyRoSkdh1dYP0PzclLE7r0M9sgbFKKMFXpFRUMNuKhQSbC6VQIGzq3E0qsfvGJaUFJPGv6Ws1NZ/haTAjfbMA==}engines: {node: '>=12'}- resolution: {integrity: sha512-1tB5mhVo7U+ETBKNf92xT4hrQa3pm0MZ0PQvuDnWgAAGHDsfp4lPSpiS6psrSiet87wyGPh9ft6wmhOMQ0hDiw==}- engines: {node: '>=14.16'}-resolution: {integrity: sha512-JXpm4DZLQqcioH+wooEc3jCFRlwu/pJvemuuNUv37gOWTVzdYgw1khGWPYulMxdkK7rlsi0pIc5gDFTw+pF8+A==}@@ -6590,10 +6387,6 @@ packages:resolution: {integrity: sha512-JFNbkD1Svwe0KvGi8GOeLcP4kAWQ609twvCdcHxq1oSL8svv39ZuSvajcD8B+5D0eL4+s1Is2D/O6KN3qcTeRA==}- resolution: {integrity: sha512-b7zoBQvpWp0vuN5q2vK2RRBR2SvuruQAs50DApdDveBSn3eSYd84IaHodFqQIMlvY9K2VnyBUEXgwOBuGU9GBg==}- engines: {node: '>=14'}-resolution: {integrity: sha512-Su3FauozOGP44ZmKdHy2oE6LPjk51M/TRRjHv2HNCWiDvfvCoxC2lno6jevMA91MYAdCdwP05QnWdWpSbncX/w==}@@ -6868,10 +6661,6 @@ packages:engines: {node: '>=10'}hasBin: true- resolution: {integrity: sha512-3hu+tD8YzSLGuFYtPRb48vdhKMi0KQV5sn+uWr8+7dMEq/2G/dtLrdDinkLjqq5TIbIBjYJ4Ax/n3YiaW7QM8A==}- engines: {node: 20 || >=22}-resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}@@ -8497,69 +8286,10 @@ snapshots:react: 19.2.8react-dom: 19.2.8([email protected])- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-- '@oxc-parser/[email protected]':- optional: true-'@oxc-project/[email protected]': {}'@oxc-project/[email protected]': {}- '@oxc-project/[email protected]': {}-'@oxc-resolver/[email protected]':optional: true@@ -10801,10 +10531,6 @@ snapshots:dependencies:format: 0.2.2- dependencies:- walk-up-path: 4.0.0-dependencies:pend: 1.2.0@@ -10842,10 +10568,6 @@ snapshots:- dependencies:- fd-package-json: 2.0.0-dependencies:graceful-fs: 4.2.11@@ -10882,10 +10604,6 @@ snapshots:dependencies:pump: 3.0.4- dependencies:- resolve-pkg-maps: 1.0.0-dependencies:resolve-pkg-maps: 1.0.0@@ -11242,22 +10960,6 @@ snapshots:dependencies:json-buffer: 3.0.1- dependencies:- fdir: 6.5.0([email protected])- formatly: 0.3.0- get-tsconfig: 4.14.1- jiti: 2.7.0- oxc-parser: 0.143.0- oxc-resolver: 11.24.2- picomatch: 4.0.5- smol-toml: 1.8.0- strip-json-comments: 5.0.3- tinyglobby: 0.2.17- unbash: 4.0.10- yaml: 2.9.0- zod: 4.4.3-@@ -11915,30 +11617,6 @@ snapshots:type-check: 0.4.0word-wrap: 1.2.5- dependencies:- '@oxc-project/types': 0.143.0- optionalDependencies:- '@oxc-parser/binding-android-arm-eabi': 0.143.0- '@oxc-parser/binding-android-arm64': 0.143.0- '@oxc-parser/binding-darwin-arm64': 0.143.0- '@oxc-parser/binding-darwin-x64': 0.143.0- '@oxc-parser/binding-freebsd-x64': 0.143.0- '@oxc-parser/binding-linux-arm-gnueabihf': 0.143.0- '@oxc-parser/binding-linux-arm-musleabihf': 0.143.0- '@oxc-parser/binding-linux-arm64-gnu': 0.143.0- '@oxc-parser/binding-linux-arm64-musl': 0.143.0- '@oxc-parser/binding-linux-ppc64-gnu': 0.143.0- '@oxc-parser/binding-linux-riscv64-gnu': 0.143.0- '@oxc-parser/binding-linux-riscv64-musl': 0.143.0- '@oxc-parser/binding-linux-s390x-gnu': 0.143.0- '@oxc-parser/binding-linux-x64-gnu': 0.143.0- '@oxc-parser/binding-linux-x64-musl': 0.143.0- '@oxc-parser/binding-openharmony-arm64': 0.143.0- '@oxc-parser/binding-win32-arm64-msvc': 0.143.0- '@oxc-parser/binding-win32-ia32-msvc': 0.143.0- '@oxc-parser/binding-win32-x64-msvc': 0.143.0-optionalDependencies:'@oxc-resolver/binding-android-arm-eabi': 11.24.2@@ -11960,6 +11638,7 @@ snapshots:'@oxc-resolver/binding-wasm32-wasi': 11.24.2'@oxc-resolver/binding-win32-arm64-msvc': 11.24.2'@oxc-resolver/binding-win32-x64-msvc': 11.24.2+ optional: truedependencies:@@ -12572,8 +12251,6 @@ snapshots:- [email protected]: {}-@@ -12763,8 +12440,6 @@ snapshots:- [email protected]: {}-dependencies:'@quansync/fs': 1.0.0@@ -12958,8 +12633,6 @@ snapshots:transitivePeerDependencies:- supports-color- [email protected]: {}-dependencies:defaults: 1.0.4diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yamlindex 8d29c0a0..4be5d310 100644--- a/pnpm-workspace.yaml+++ b/pnpm-workspace.yaml@@ -107,7 +107,6 @@ patchedDependencies:catalog:'@choochmeque/tauri-plugin-notifications-api': 0.5.0-rc.14'@genapi/core': ^4.1.4- '@genapi/parser': ^4.1.4'@genapi/pipeline': ^4.1.4'@genapi/presets': ^4.1.4'@genapi/shared': ^4.1.4@@ -152,7 +151,6 @@ catalogs:'@deepseek-ai/dsh-permission-presets': 0.2.0-rc.2'@deepseek-ai/dsh-session': 0.2.0-rc.2'@deepseek-ai/dsh-skill-filesystem': 0.2.0-rc.2- '@deepseek-ai/dsh-storage-domain': 0.2.0-rc.2'@deepseek-ai/dsh-tools': 0.2.0-rc.2'@deepseek-ai/dsh-user-approval': 0.2.0-rc.2'@deepseek-ai/dsh-util-values': 0.2.0-rc.2@@ -162,7 +160,6 @@ catalogs:'@eslint-react/eslint-plugin': ^5.18.6eslint: ^10.8.1eslint-plugin-react-refresh: ^0.5.4- knip: ^6.32.2release:bumpp: 12.2.1changelogithub: 15.0.5@@ -209,12 +206,8 @@ catalogs:dompurify: ^3.4.13marked: ^18.0.10utils:- '@hairy/utils': ^1.52.0- citty: ^0.2.2- consola: ^3.4.2cron-schedule: ^6.0.0date-fns: ^4.4.0- dotenv: ^17.4.2hookable: ^6.1.1lodash-es: ^4.18.1ofetch: ^1.5.1@@ -223,7 +216,6 @@ catalogs:simple-git: ^3.36.0smol-toml: ^1.3.1ssh2: ^1.17.0- tinyexec: ^1.3.0unstorage: ^1.17.5trustPolicyIgnoreAfter: 525600diff --git a/src/store/modules/harness/readiness.ts b/src/store/modules/harness/readiness.tsindex 86537683..7be4d473 100644--- a/src/store/modules/harness/readiness.ts+++ b/src/store/modules/harness/readiness.ts@@ -1,4 +1,6 @@-import { delay } from '@hairy/utils'+function delay(milliseconds: number): Promise<void> {+ return new Promise<void>(resolve => setTimeout(resolve, milliseconds))+}export type StartupPhase = 'plugin-install' | 'process-boot' | 'client-modules'export type ReadinessTimeout = 'inactivity' | 'absolute'