Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat(dsh-tauri-connection): 以插件覆写鉴权闸门取代 alpha_auth 核心补丁

hairyf68001ea488a4
diff --git a/.gitmodules b/.gitmodules
index 75f36ad9..f668e088 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -19,3 +19,6 @@
[submodule "source/dsh-market"]
path = source/dsh-market
url = https://github.com/dsh-market/dsh-market.git
+[submodule "source/deepseek-harness"]
+ path = source/deepseek-harness
+ url = https://github.com/deepseek-ai/deepseek-harness
diff --git a/README.en.md b/README.en.md
index 420306f5..bebf3f52 100644
--- a/README.en.md
+++ b/README.en.md
@@ -66,6 +66,7 @@ Plugins offered in the first-run wizard; select what you need and install on dem
First-party plugins bundled with the installer:
- [DSH Tauri](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri) — provides a communication channel with the Tauri 2 shell
+- [DSH Tauri Connection](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-connection) — lets the cross-origin sandboxed WebView reach the loopback Host by overriding the desktop carrier's two authentication gates on the `connection` service
- [DSH Model Config](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-model-config) — takes over the model settings page and adds context and output limits, image input, thinking modes, and local-endpoint compatibility options
- [DSH Tauri UI](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-ui) — provides a custom settings sidebar for the Tauri 2 shell
- [DSH Tauri Worktree](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-worktree) — creates an isolated Git worktree per session, with checkout to a local branch or archive-and-abandon flows
diff --git a/README.es.md b/README.es.md
index 81e68e0a..1765bf02 100644
--- a/README.es.md
+++ b/README.es.md
@@ -65,6 +65,7 @@ Plugins ofrecidos en el asistente del primer arranque; marcá los que necesites
Plugins propios incluidos con el instalador:
- [DSH Tauri](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri) — provee el canal de comunicación con el shell Tauri 2
+- [DSH Tauri Connection](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-connection) — permite que el WebView integrado en un sandbox de origen cruzado alcance el Host de loopback sobrescribiendo las dos puertas de autenticación del carrier de escritorio en el servicio `connection`
- [DSH Model Config](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-model-config) — toma el control de la página de ajustes de modelos y agrega límites de contexto y salida, entrada de imágenes, modos de pensamiento y opciones de compatibilidad para endpoints locales
- [DSH Tauri UI](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-ui) — provee una barra lateral de ajustes personalizada para el shell Tauri 2
- [DSH Tauri Worktree](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-worktree) — crea un Git worktree aislado por sesión, con checkout a rama local o flujos de archivar-y-abandonar
diff --git a/README.md b/README.md
index 80e48174..b288ad5d 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,7 @@
随安装包资源内置的第一方插件:
- [DSH Tauri](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri) — 提供与 Tauri 2 外壳的通信通道
+- [DSH Tauri Connection](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-connection) — 让跨源沙箱内嵌 WebView 用上回环宿主:在 `connection` 服务上覆写桌面载体的两道鉴权闸门
- [DSH Model Config](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-model-config) — 接管模型设置页,补齐上下文与输出上限、图片输入、思考模式和本地端点兼容选项
- [DSH Tauri UI](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-ui) — 为 Tauri 2 外壳提供自定义设置侧边栏
- [DSH Tauri Worktree](https://github.com/dsh-tauri/deepseek-harness-desktop/tree/main/packages/dsh-tauri-worktree) — 为每个会话创建隔离的 Git Worktree,并支持检出到本地分支或归档放弃
diff --git a/docs/specs/connection.proposal.md b/docs/specs/connection.proposal.md
new file mode 100644
index 00000000..07fbbdb4
--- /dev/null
+++ b/docs/specs/connection.proposal.md
@@ -0,0 +1,166 @@
+# 桌面载体鉴权适配提案 (dsh-tauri-connection)
+
+> 状态:已实施。内置插件 `packages/dsh-tauri-connection` 取代
+> `src-tauri/src/service/patch/alpha_auth.rs`(该补丁已删除)。
+
+---
+
+## 1. 问题
+
+桌面端用 Tauri WebView 承载 DSH Web UI:壳层文档是 `tauri.localhost`,UI 跑在
+`http://127.0.0.1:<port>` 的**跨源沙箱 iframe** 里(`src/layout/components/iframe.tsx:192`,
+地址由 `src/store/modules/harness/utils.ts:37` 生成)。
+
+上游 `dsh-client-connection` 的浏览器鉴权只有一条通道:根路径 `GET /?token=<...>`
+把进程 token 换成绑定 authority 的签名 Cookie,此后每个 Host RPC 方法与 WebSocket
+stream 都要求该 Cookie 在场,否则 401(`dsh-client-connection/README.zh.md:35`)。
+
+该 Cookie 是 `SameSite=Strict`(`dsh-client-connection/lib/index.js:293`),跨源 iframe
+下浏览器不会携带它,token 交换也无法稳定完成——于是桌面端每一次请求都是 401。
+
+## 2. 结论
+
+不换载体、不改核心磁盘文件:在**插件层**覆写 `connection` 服务的两道鉴权闸门。
+
+原 `alpha_auth` 补丁的做法是在活动核心的 JS 里改两个方法体,并把开关做成
+`--skip-auth` CLI 选项——需要同时改 `dsh-web-app/lib/startup.js` 与
+`dsh-client-connection/lib/index.js` 两个文件,并兼容 pkg / npm 两种布局锚点
+(见 issue #358 的回归用例)。插件把同一件事移到运行期:**锚点消失,核心换版本不再
+需要重新验证补丁命中**,WebSocket 通道也一并覆盖。
+
+## 3. 契约:两道闸门
+
+| 闸门 | 返回 | 已装核心调用点 |
+| --- | --- | --- |
+| `requestRejection(request)` | `401 \| 403 \| undefined` | `dsh-client-connection/lib/index.js:611`(per-channel `register()`)、`:774`(`/api` 共享通道)、`dsh-api-gateway/lib/index.js:463`(WebSocket upgrade)、`dsh-host-open-in-app/lib/index.js:1318` |
+| `authorizeIndex(request, response)` | `boolean`,`false` 表示调用方不再写出 index | `dsh-host-frontend-static/lib/index.js:95`(`serveStatic` 在 `:60` 以 `if (!authorizeIndex()) return` 消费返回值) |
+
+四处调用点**全部是调用时属性查找**(`this.requestRejection(req)` /
+`connection.requestRejection(req)` / `ctx.connection.authorizeIndex(req, res)`),
+因此在服务实例上覆盖方法即可同时生效——包括 WebSocket upgrade。
+
+上游对应位置:`packages/client/connection/src/rpc-host.ts:75`(`super(ctx, 'connection')`
+——插件名是 `client-connection`,服务名才是 `connection`)、
+`packages/client/connection/src/index.ts:144`(`/api`)、
+`packages/api/gateway/src/index.ts:215`(WS upgrade)、
+`packages/host/frontend-static/src/index.ts:139`(index)。
+
+### 语义
+
+```ts
+connection.requestRejection = (request) => {
+ const rejected = rejection.call(connection, request)
+ return rejected === 401 ? undefined : rejected // 403 原样保留
+}
+connection.authorizeIndex = () => true
+```
+
+`requestRejection` **不整体放行**:Host/Origin fence 的 403 继续生效,只把
+browser-session 的 401 降级为放行——与 `alpha_auth` 补丁后的方法体逐字等价。
+
+## 4. 载体标记
+
+插件只在自己被**显式**要求接管时才生效:
+
+* Tauri 壳在 spawn 时注入 `DSH_TAURI_EMBEDDED=1`
+ (`src-tauri/src/service/workflow/launch.rs` 的 envs 注入点,与 `DSH_PNPM` 同一处)。
+* 未注入时 `gate.attach()` 直接返回空卸载函数,插件是 no-op。
+
+这一步不能省:内置插件被安装进**用户档案**(`internal-plugins.json`),而档案是桌面端
+与终端 `dsh web` 共用的。没有这个标记,任何一次 `dsh web --profile web` 都会静默绕过
+鉴权。
+
+## 5. 安全边界
+
+放行等价于原 `--skip-auth`:**凡通过 `isTrustedApiRequest` Host/Origin fence 的请求
+一律视为已鉴权**。这是「跨源 iframe 无法完成 Cookie 交换」这一载体约束的直接代价,
+不是修复。要真正恢复 browser-session 鉴权,必须换载体(让 DSH Web UI 成为独立顶层
+上下文),不在本提案范围内。
+
+静态资源本来就是公开的;本插件不放宽任何比原补丁更宽的口子。
+
+## 6. 插件落点
+
+```text
+packages/dsh-tauri-connection/
+├── cordis.patch.yml # 插入 loader entry dsh-tauri-connection
+├── package.json # dsh.bundle.patch 指向上面
+├── tsdown.config.ts # defineDshConfig({ client: false })
+└── src/
+ ├── index.ts # name / inject: ['connection'] / apply
+ ├── shared/constants.ts # PLUGIN_ID
+ └── host/
+ ├── apply.ts # 装配:绑定宿主 → ctx.effect(gate.attach())
+ ├── config/runtime.ts # defineHostRuntime<ConnectionHost>()
+ ├── service/gate.ts # 覆写/还原两道闸门(唯一接触宿主的层)
+ ├── service/gate.test.ts
+ └── types/index.ts # ConnectionHost / ConnectionLogger
+```
+
+`defineDshConfig()` 原本**无条件**产出 `src/client/index.ts` 入口,本插件是本仓第一个纯宿主
+插件,因此 `packages/dsh-tauri-tsdown/src/index.ts` 新增 `client: false`:只产出宿主 entry,
+其余插件的 `client` 选项语义不变(已用 `dsh-tauri-session` 回归双入口构建)。
+
+登记点(缺一不可):
+
+1. `packages/dsh-tauri-bundle/package.json` 的 `dependencies` —— 决定 `build:plugins`
+ 把哪些 workspace 包 deploy 进 `src-tauri/resources/node_modules`;
+2. `src-tauri/resources/internal-plugins.json` —— 决定启动时把哪些内置插件自愈安装进
+ 用户档案;
+3. `pnpm-lock.yaml`(`pnpm install --lockfile-only`)。
+
+插件没有路由、没有 client half,因此**不**登记进 `genapi.config.ts`。
+
+## 7. 落地清单
+
+**新增**
+
+* `packages/dsh-tauri-connection/**`
+* `docs/specs/connection.proposal.md`(本文)
+
+**删除**
+
+* `src-tauri/src/service/patch/alpha_auth.rs`
+* `docs/host.proposal.md`、`docs/host.migration.md`(旧载体方案,已废弃)
+
+**改动**
+
+* `src-tauri/src/service/patch/mod.rs`:移除 `alpha_auth` 模块声明与 `apply_all_at`
+ 注册项,数组长度 `7` → `6`。
+* `src-tauri/src/service/workflow/launch.rs`:
+ * 删除 `alpha_auth::apply` 调用块;
+ * 删除 `skip_auth` 判定与三处 `--skip-auth` 参数(Windows args、Unix 首次 spawn、
+ Unix 重复 loader entry 重试);
+ * 新增 `envs.insert("DSH_TAURI_EMBEDDED", "1")`。
+* `packages/dsh-tauri-bundle/package.json`、`src-tauri/resources/internal-plugins.json`、
+ `pnpm-lock.yaml`。
+* `src-tauri/src/utils/mod.rs`:删除只服务 `--skip-auth` 能力探测的 `dsh_rel_contains`
+ (`alpha_auth` 是它唯一的调用方)。
+* `packages/dsh-tauri-tsdown/src/index.ts`:`DshConfigOptions.client` 接受 `false`,
+ 让纯宿主插件不再被迫产出浏览器半区。
+* `README.md` / `README.en.md` / `README.es.md`:插件清单登记新包。
+* `docs/specs/upstram.sync.md` §5.2、`docs/specs/plugin.test.md`、`docs/testing/plugins/02-dsh-tauri-core.md`
+ 中指向旧补丁的表述。
+
+`--no-open` 与 `web_supports_no_open_flag` 保持不动。
+
+## 8. 验证
+
+| 层 | 断言 |
+| --- | --- |
+| 单元 | `gate.test.ts`:未注入标记时两道闸门引用不变;注入后 401 降级、403 透传、`authorizeIndex` 恒真且不调用原实现;卸载后引用复原;核心缺闸门时告警且不抛错 |
+| 类型 | `pnpm typecheck` |
+| 构建 | `pnpm --filter dsh-tauri-connection build`:只产出 `dist/index.js` + `dist/index.d.ts`,publint 无问题,入口无静态 `@deepseek-ai/*` 导入 |
+| 资源闭包 | `test/plugin-resource-closure.test.ts`(构建后)覆盖新包的 `dist/index.js` 入口与「无静态 `@deepseek-ai/*` 导入」 |
+| L2 / L3 | 桌面端启动后 iframe 内 `/api` 不再 401;终端 `dsh web` 仍走 Cookie 交换 |
+| Rust | `cargo check` 零警告、`cargo test --lib` 全绿 |
+
+## 9. 已知残留
+
+* **已装核心上的补丁残留**:`alpha_auth` 对活动核心的改写不会被回滚。打过补丁的
+ `dsh-client-connection/lib/index.js` 保留两处 `if (process.env.DSH_SKIP_AUTH === "1")`
+ 分支与标记注释。因为再没有任何路径写入 `DSH_SKIP_AUTH`,它们是死代码;插件覆写整个
+ 方法后更不可达。重新安装核心即得到干净文件。
+* **上游改动风险**:若 `requestRejection` / `authorizeIndex` 改名或改语义,插件告警并
+ 降级为 no-op(表现回到 401),不阻断启动——与其他核心补丁「最佳努力、失败只告警」
+ 的约定一致。
diff --git a/docs/specs/plugin.test.md b/docs/specs/plugin.test.md
index 628fdfd8..6c80b720 100644
--- a/docs/specs/plugin.test.md
+++ b/docs/specs/plugin.test.md
@@ -102,7 +102,7 @@ docs/testing/plugins/<序号>-<插件名>.md # 插件测试文档
```
> **鉴权说明**:上游只接受「根路径 `GET /?token=<...>` 换 Cookie」这一条通道——`/` 之外的请求带 query token 或 Authorization 头都不认。交换成功返回 303 + `Set-Cookie`(host-only、`Path=/`、`HttpOnly`、`SameSite=Strict`、无 `Secure`),此后 `/api` 与插件自有路由都必须带回该 Cookie,否则 401。
-> 桌面端内嵌 WebView 走的是另一条路(`alpha_auth` 补丁提供的 `--skip-auth`),**L2 不复用该参数**:npm 上的核心没有这个补丁,且绕过鉴权会让「未鉴权」与「路由丢失」在测试里不可区分。
+> 桌面端内嵌 WebView 走的是另一条路(`dsh-tauri-connection` 插件在 `DSH_TAURI_EMBEDDED=1` 时覆写 connection 的两道鉴权闸门,见 [connection.proposal.md](./connection.proposal.md)),**L2 不复用该通道**:npm 上的核心没有这个插件,且绕过鉴权会让「未鉴权」与「路由丢失」在测试里不可区分。
>
> **核心解析**:`DSH_E2E_DSH_BIN` → 仓库依赖树 → 桌面端装配目录,依次尝试。仓库刻意**不**把 `@deepseek-ai/dsh` 装进依赖树——它会与本仓 catalog 的 `@deepseek-ai/dsh-*` 形成双树,profile 组合时取到不匹配的实例。三者皆无时**直接抛错**,不提供「跳过」开关:一旦可跳过,CI 会在什么都没断言的情况下报绿。
>
diff --git a/docs/specs/upstram.sync.md b/docs/specs/upstram.sync.md
index 2fd45e72..5a783cea 100644
--- a/docs/specs/upstram.sync.md
+++ b/docs/specs/upstram.sync.md
@@ -162,7 +162,8 @@ git diff --check
### 5.2 已知配置与异常记录
-* **子模块绑定**:`source/*` 下 7 个参考仓库均已引入 `.gitmodules`。其中 `source/dsh-market` 是 2026-09 新增的**临时**参考仓库:上游 `render()` API 只存在于 main 分支,尚未发版,故先以源码子模块承载供 GitHub 源安装测试;上游发版后应改为 npm 依赖并移除该子模块。当前 gitlink 配置已暂存,待提交。
+* **子模块绑定**:`source/*` 下 8 个参考仓库均已引入 `.gitmodules`。其中 `source/dsh-market` 是 2026-09 新增的**临时**参考仓库:上游 `render()` API 只存在于 main 分支,尚未发版,故先以源码子模块承载供 GitHub 源安装测试;上游发版后应改为 npm 依赖并移除该子模块。当前 gitlink 配置已暂存,待提交。
+* **内核参考仓库**:`source/deepseek-harness`(`deepseek-ai/deepseek-harness`,基线 `ddefc45fbc` = `dsh 0.1.6-alpha.2`)是 2026-09 新增的**只读对照基线**,为 Issue #496(非 Electron 壳可复用的无端口嵌入式宿主)提供契约比对依据。按 §1.2,DSH 内核**排除在本同步流程之外**:此子模块不参与择优采纳,只用于核对宿主契约与登记核心版本基线。桌面端载体鉴权适配的结论见 `docs/specs/connection.proposal.md`。
* **路径纠偏记录**:
* `source/dsh-automation` 已纠正 gitlink 配置,子模块 HEAD 指向 `f1bc91a`。
* `source/dsh-automation` gitlink 为 `f1bc91a`,但工作区 checkout 停在 `e75499e`(`git submodule status` 前缀 `+`,
diff --git a/docs/testing/plugins/02-dsh-tauri-core.md b/docs/testing/plugins/02-dsh-tauri-core.md
index f1a69271..bea597ea 100644
--- a/docs/testing/plugins/02-dsh-tauri-core.md
+++ b/docs/testing/plugins/02-dsh-tauri-core.md
@@ -132,5 +132,5 @@
## 4. 缺口与假设
- **不可覆盖**:非回环地址发起的变更请求 403(`routes/index.ts:279`)需要非本机来源,本套用例不做,仅登记为已知未覆盖分支。
-- **已定论**:不带会话 Cookie 时 `/api` 与插件路由返回 401(上游 `authorizeIndex` 在根路径之外不做 token 交换)。因此本批一律显式携带 Cookie;L2 不再依赖 `--skip-auth`——那是桌面端 `alpha_auth` 补丁提供的参数,npm 上的核心没有。
+- **已定论**:不带会话 Cookie 时 `/api` 与插件路由返回 401(上游 `authorizeIndex` 在根路径之外不做 token 交换)。因此本批一律显式携带 Cookie;L2 不再依赖桌面端的载体放行——那是 `dsh-tauri-connection` 插件在 `DSH_TAURI_EMBEDDED=1` 时提供的运行时覆写,npm 上的核心没有这个插件。
- **假设**:`allow` 头的成员顺序稳定(`SUPPORTED_METHODS` 过滤后 join,见 `routes/index.ts:255`)。若顺序不稳定,断言改为集合包含而非字符串相等。
diff --git a/packages/dsh-tauri-bundle/package.json b/packages/dsh-tauri-bundle/package.json
index 537194c1..a5cb167a 100644
--- a/packages/dsh-tauri-bundle/package.json
+++ b/packages/dsh-tauri-bundle/package.json
@@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"dsh-tauri": "workspace:*",
+ "dsh-tauri-connection": "workspace:*",
"dsh-tauri-model-config": "workspace:*",
"dsh-tauri-panel-extension": "workspace:*",
"dsh-tauri-panel-scheduler": "workspace:*",
diff --git a/packages/dsh-tauri-connection/cordis.patch.yml b/packages/dsh-tauri-connection/cordis.patch.yml
new file mode 100644
index 00000000..0bf26a74
--- /dev/null
+++ b/packages/dsh-tauri-connection/cordis.patch.yml
@@ -0,0 +1,3 @@
+- insert:
+ - id: dsh-tauri-connection
+ name: dsh-tauri-connection
diff --git a/packages/dsh-tauri-connection/package.json b/packages/dsh-tauri-connection/package.json
new file mode 100644
index 00000000..e59e5317
--- /dev/null
+++ b/packages/dsh-tauri-connection/package.json
@@ -0,0 +1,51 @@
+{
+ "name": "dsh-tauri-connection",
+ "type": "module",
+ "version": "1.0.0",
+ "author": "Hairyf <[email protected]>",
+ "license": "MIT",
+ "homepage": "https://github.com/dsh-tauri-desk/dsh-tauri-plugins#readme",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/dsh-tauri-desk/dsh-tauri-plugins.git"
+ },
+ "bugs": "https://github.com/dsh-tauri-desk/dsh-tauri-plugins/issues",
+ "keywords": [
+ "dsh",
+ "plugin",
+ "dsh-plugin",
+ "tauri",
+ "deepseek-harness"
+ ],
+ "sideEffects": false,
+ "exports": {
+ ".": "./dist/index.js",
+ "./package.json": "./package.json"
+ },
+ "main": "./dist/index.js",
+ "module": "./dist/index.js",
+ "types": "./dist/index.d.ts",
+ "files": [
+ "cordis.patch.yml",
+ "dist"
+ ],
+ "dsh": {
+ "bundle": {
+ "patch": "./cordis.patch.yml"
+ }
+ },
+ "scripts": {
+ "build": "tsdown",
+ "dev": "tsdown --watch",
+ "prepublishOnly": "nr build",
+ "start": "tsx src/index.ts",
+ "typecheck": "tsc"
+ },
+ "dependencies": {
+ "dsh-tauri": "workspace:*"
+ },
+ "devDependencies": {
+ "dsh-tauri-tsdown": "workspace:*",
+ "tsdown": "catalog:cli"
+ }
+}
diff --git a/packages/dsh-tauri-connection/src/host/apply.ts b/packages/dsh-tauri-connection/src/host/apply.ts
new file mode 100644
index 00000000..e69129dc
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/host/apply.ts
@@ -0,0 +1,12 @@
+import type { HostContext } from 'dsh-tauri'
+import type { ConnectionHost } from './types'
+import { PLUGIN_ID } from '../shared/constants'
+import { clearHostRuntime, setCurrentHostInstance } from './config/runtime'
+import { gate } from './service/gate'
+
+export function apply(ctx: HostContext): void {
+ setCurrentHostInstance(ctx as unknown as ConnectionHost)
+
+ ctx.effect(() => gate.attach(), `${PLUGIN_ID}: gate`)
+ ctx.effect(() => () => clearHostRuntime(), `${PLUGIN_ID}: host runtime`)
+}
diff --git a/packages/dsh-tauri-connection/src/host/config/runtime.ts b/packages/dsh-tauri-connection/src/host/config/runtime.ts
new file mode 100644
index 00000000..225d7361
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/host/config/runtime.ts
@@ -0,0 +1,8 @@
+import type { ConnectionHost } from '../types'
+import { defineHostRuntime } from 'dsh-tauri'
+
+export const { setCurrentHostInstance, getCurrentHostInstance } = defineHostRuntime<ConnectionHost>()
+
+export function clearHostRuntime(): void {
+ setCurrentHostInstance(undefined)
+}
diff --git a/packages/dsh-tauri-connection/src/host/service/gate.test.ts b/packages/dsh-tauri-connection/src/host/service/gate.test.ts
new file mode 100644
index 00000000..20250dff
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/host/service/gate.test.ts
@@ -0,0 +1,98 @@
+import type { IncomingMessage, ServerResponse } from 'node:http'
+import type { ConnectionHost } from '../types'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { clearHostRuntime, setCurrentHostInstance } from '../config/runtime'
+import { gate } from './gate'
+
+const request = {} as IncomingMessage
+const response = {} as ServerResponse
+
+/** 最小 connection 面:两道闸门都记账,用于断言是否调用了原实现。 */
+function makeHost(rejection: 401 | 403 | undefined) {
+ const calls: string[] = []
+ const connection: ConnectionHost['connection'] = {
+ requestRejection: () => {
+ calls.push('requestRejection')
+ return rejection
+ },
+ authorizeIndex: () => {
+ calls.push('authorizeIndex')
+ return false
+ },
+ }
+ setCurrentHostInstance({ connection })
+ return { connection, calls }
+}
+
+beforeEach(() => {
+ delete process.env.DSH_TAURI_EMBEDDED
+})
+
+afterEach(() => {
+ delete process.env.DSH_TAURI_EMBEDDED
+ clearHostRuntime()
+})
+
+describe('gate.attach without the carrier marker', () => {
+ it('leaves both gates untouched', () => {
+ const { connection } = makeHost(401)
+ const rejection = connection.requestRejection
+ const authorize = connection.authorizeIndex
+
+ gate.attach()()
+
+ expect(connection.requestRejection).toBe(rejection)
+ expect(connection.authorizeIndex).toBe(authorize)
+ })
+})
+
+describe('gate.attach with the carrier marker', () => {
+ beforeEach(() => {
+ process.env.DSH_TAURI_EMBEDDED = '1'
+ })
+
+ it('downgrades the browser-session 401 to allowed', () => {
+ const { connection } = makeHost(401)
+ const detach = gate.attach()
+
+ expect(connection.requestRejection(request)).toBeUndefined()
+ detach()
+ })
+
+ it('keeps the 403 Host/Origin fence', () => {
+ const { connection } = makeHost(403)
+ const detach = gate.attach()
+
+ expect(connection.requestRejection(request)).toBe(403)
+ detach()
+ })
+
+ it('serves the index without consulting the original gate', () => {
+ const { connection, calls } = makeHost(401)
+ const detach = gate.attach()
+
+ expect(connection.authorizeIndex(request, response)).toBe(true)
+ expect(calls).not.toContain('authorizeIndex')
+ detach()
+ })
+
+ it('restores both gates on detach', () => {
+ const { connection } = makeHost(401)
+ const rejection = connection.requestRejection
+ const authorize = connection.authorizeIndex
+
+ gate.attach()()
+
+ expect(connection.requestRejection).toBe(rejection)
+ expect(connection.authorizeIndex).toBe(authorize)
+ })
+
+ it('stays inert and warns when the core lacks the gates', () => {
+ const warn = vi.fn()
+ setCurrentHostInstance({ connection: {} as never, logger: { warn } })
+
+ gate.attach()()
+
+ expect(warn).toHaveBeenCalledOnce()
+ })
+})
diff --git a/packages/dsh-tauri-connection/src/host/service/gate.ts b/packages/dsh-tauri-connection/src/host/service/gate.ts
new file mode 100644
index 00000000..c27d7999
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/host/service/gate.ts
@@ -0,0 +1,58 @@
+import type { IncomingMessage } from 'node:http'
+import process from 'node:process'
+import { defineService } from 'dsh-tauri'
+import { PLUGIN_ID } from '../../shared/constants'
+import { getCurrentHostInstance } from '../config/runtime'
+
+/**
+ * 桌面壳在 spawn 时注入的载体标记;与 `src-tauri/src/service/workflow/launch.rs` 的
+ * envs 注入点逐字一致。未注入时本插件完全不接管鉴权,同一 profile 下独立运行的
+ * `dsh web` 保持 browser-session 鉴权。
+ */
+const EMBEDDED_ENV = 'DSH_TAURI_EMBEDDED'
+
+/**
+ * 桌面载体鉴权适配。
+ *
+ * 内嵌 WebView 是 `tauri.localhost` 下的跨源沙箱 iframe,`SameSite=Strict` 的
+ * browser-session Cookie 不会被携带,根路径 token 交换也就无法完成。这里在
+ * `connection` 服务实例上覆写两道闸门:`requestRejection` 保留 Host/Origin fence
+ * 的 403、只把 401 降级为放行;`authorizeIndex` 直接放行 index。
+ */
+export const gate = defineService({
+ attach(): () => void {
+ if (process.env[EMBEDDED_ENV] !== '1') {
+ return noop
+ }
+
+ const { connection } = getCurrentHostInstance()
+ const rejection = connection.requestRejection
+ const authorize = connection.authorizeIndex
+ if (typeof rejection !== 'function' || typeof authorize !== 'function') {
+ warn('connection 服务缺少 requestRejection/authorizeIndex,桌面载体鉴权适配未生效')
+ return noop
+ }
+
+ connection.requestRejection = (request: IncomingMessage) => {
+ const rejected = rejection.call(connection, request)
+ return rejected === 401 ? undefined : rejected
+ }
+ connection.authorizeIndex = () => true
+
+ return () => {
+ connection.requestRejection = rejection
+ connection.authorizeIndex = authorize
+ }
+ },
+})
+
+// --- internal ---
+
+function noop(): void {}
+
+function warn(message: string): void {
+ try {
+ getCurrentHostInstance().logger?.warn?.(`[${PLUGIN_ID}] ${message}`)
+ }
+ catch {}
+}
diff --git a/packages/dsh-tauri-connection/src/host/types/index.ts b/packages/dsh-tauri-connection/src/host/types/index.ts
new file mode 100644
index 00000000..80daa7eb
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/host/types/index.ts
@@ -0,0 +1,21 @@
+import type { ConnectionGate } from 'dsh-tauri'
+import type { IncomingMessage, ServerResponse } from 'node:http'
+
+/** 宿主日志出口(与 dsh-tauri 其它插件一致的可选注入面)。 */
+export interface ConnectionLogger {
+ warn?: (message: string, error?: unknown) => void
+}
+
+/**
+ * 桌面载体鉴权适配要覆写的两道闸门。
+ *
+ * `requestRejection` 取自 dsh-tauri 的 `ConnectionGate`;`authorizeIndex` 只被
+ * frontend-static 以 `() => ctx.connection.authorizeIndex(req, res)` 调用,返回值即
+ * 「index 是否继续由调用方写出」,因此按调用点在这里补齐。
+ */
+export interface ConnectionHost {
+ connection: ConnectionGate & {
+ authorizeIndex: (request: IncomingMessage, response: ServerResponse) => boolean
+ }
+ logger?: ConnectionLogger
+}
diff --git a/packages/dsh-tauri-connection/src/index.ts b/packages/dsh-tauri-connection/src/index.ts
new file mode 100644
index 00000000..87de3ca0
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/index.ts
@@ -0,0 +1,7 @@
+import { PLUGIN_ID } from './shared/constants'
+
+export const name = PLUGIN_ID
+
+export const inject = ['connection']
+
+export { apply } from './host/apply'
diff --git a/packages/dsh-tauri-connection/src/shared/constants.ts b/packages/dsh-tauri-connection/src/shared/constants.ts
new file mode 100644
index 00000000..a36783c3
--- /dev/null
+++ b/packages/dsh-tauri-connection/src/shared/constants.ts
@@ -0,0 +1,4 @@
+/** shared/constants.ts — 跨 host/client 的稳定协议常量(桌面载体鉴权适配)。 */
+
+/** 插件名(诊断元数据 / registrant)。 */
+export const PLUGIN_ID = 'dsh-tauri-connection'
diff --git a/packages/dsh-tauri-connection/tsdown.config.ts b/packages/dsh-tauri-connection/tsdown.config.ts
new file mode 100644
index 00000000..fdf2b993
--- /dev/null
+++ b/packages/dsh-tauri-connection/tsdown.config.ts
@@ -0,0 +1,3 @@
+import { defineDshConfig } from '../dsh-tauri-tsdown/src/index.ts'
+
+export default defineDshConfig({ client: false })
diff --git a/packages/dsh-tauri-tsdown/src/index.ts b/packages/dsh-tauri-tsdown/src/index.ts
index 1d259e4f..f914c600 100644
--- a/packages/dsh-tauri-tsdown/src/index.ts
+++ b/packages/dsh-tauri-tsdown/src/index.ts
@@ -12,8 +12,8 @@ const isWatchMode = process.argv.includes('--watch') || process.argv.includes('-
export interface DshConfigOptions {
/** 宿主 entry 的 tsdown 选项(覆盖 common)。 */
server?: TsdownOptions
- /** client entry 的 tsdown 选项(覆盖 common;noExternal 并入默认内联表)。 */
- client?: TsdownOptions & { noExternal?: Array<string | RegExp> }
+ /** client entry 的 tsdown 选项(覆盖 common;noExternal 并入默认内联表);`false` 表示纯宿主插件。 */
+ client?: TsdownOptions | false
/** 是否对 server entry 跑 publint(默认 true)。 */
publint?: boolean
}
@@ -76,7 +76,7 @@ const dshClientInline: Array<string | RegExp> = [
]
export function defineDshConfig(options: DshConfigOptions = {}) {
- const { noExternal: clientNoExternal, ...clientOptions } = options.client ?? {}
+ const { noExternal: clientNoExternal, ...clientOptions } = options.client === false ? {} : options.client ?? {}
const common: TsdownOptions = {
outDir: 'dist',
format: 'esm',
@@ -85,15 +85,21 @@ export function defineDshConfig(options: DshConfigOptions = {}) {
external: dshExternal,
}
+ const server: TsdownOptions = {
+ ...common,
+ ...options.server,
+ entry: { index: 'src/index.ts' },
+ dts: true,
+ sourcemap: false,
+ clean: true,
+ }
+ // 纯宿主插件没有浏览器半区:`client: false` 时只产出宿主 entry,不写 `src/client/`。
+ if (options.client === false) {
+ return [server]
+ }
+
return [
- {
- ...common,
- ...options.server,
- entry: { index: 'src/index.ts' },
- dts: true,
- sourcemap: false,
- clean: true,
- },
+ server,
{
...common,
entry: { client: 'src/client/index.ts' },
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4265d76e..6c93b439 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -610,6 +610,9 @@ importers:
dsh-tauri:
specifier: workspace:*
version: link:../dsh-tauri
+ dsh-tauri-connection:
+ specifier: workspace:*
+ version: link:../dsh-tauri-connection
dsh-tauri-model-config:
specifier: workspace:*
version: link:../dsh-tauri-model-config
@@ -638,6 +641,19 @@ importers:
specifier: workspace:*
version: link:../dsh-tauri-worktree
+ packages/dsh-tauri-connection:
+ dependencies:
+ dsh-tauri:
+ specifier: workspace:*
+ version: link:../dsh-tauri
+ devDependencies:
+ dsh-tauri-tsdown:
+ specifier: workspace:*
+ version: link:../dsh-tauri-tsdown
+ tsdown:
+ specifier: catalog:cli
+
packages/dsh-tauri-model-config:
dependencies:
dsh-tauri:
diff --git a/source/deepseek-harness b/source/deepseek-harness
new file mode 160000
index 00000000..ddefc45f
--- /dev/null
+++ b/source/deepseek-harness
@@ -0,0 +1 @@
+Subproject commit ddefc45fbc7f8e46dd73185e68295696d1297887
diff --git a/src-tauri/resources/internal-plugins.json b/src-tauri/resources/internal-plugins.json
index 910c676d..21011b5e 100644
--- a/src-tauri/resources/internal-plugins.json
+++ b/src-tauri/resources/internal-plugins.json
@@ -6,6 +6,13 @@
"description": "Message bridge for the DeepSeek Harness desktop shell",
"repoUrl": "https://github.com/dsh-tauri-desk/dsh-tauri-plugins/tree/main/packages/dsh-tauri"
},
+ {
+ "id": "dsh-tauri-connection",
+ "spec": "dsh-tauri-connection",
+ "name": "DSH Tauri Connection",
+ "description": "Desktop carrier authentication adaptation for the DeepSeek Harness shell: the embedded sandboxed WebView is cross-origin, so it cannot complete the SameSite=Strict browser-session cookie exchange.",
+ "repoUrl": "https://github.com/dsh-tauri-desk/dsh-tauri-plugins/tree/main/packages/dsh-tauri-connection"
+ },
{
"id": "dsh-tauri-model-config",
"spec": "dsh-tauri-model-config",
diff --git a/src-tauri/src/service/patch/alpha_auth.rs b/src-tauri/src/service/patch/alpha_auth.rs
deleted file mode 100644
index f295e9f8..00000000
--- a/src-tauri/src/service/patch/alpha_auth.rs
+++ /dev/null
@@ -1,248 +0,0 @@
-//! alpha 核心的桌面嵌入鉴权补丁:为 `dsh --profile web` 补上可选的
-//! `--skip-auth` 参数,而不是像旧实现那样无条件下发绕过。
-//!
-//! alpha 的 `dsh-client-connection` 默认要求浏览器先用启动 token 换取
-//! `SameSite=Strict` Cookie。桌面端通过沙箱跨源 iframe 承载 Web UI,无法稳定完成
-//! 该 Cookie 交换。旧补丁直接改写鉴权方法体、对所有请求放行;本补丁改为:只有
-//! 显式传入 `--skip-auth` 时跳过 browser-session 层,其余场景保持上游完整鉴权:
-//!
-//! - `dsh-web-app/lib/startup.js`:给 web 命令补上 `--skip-auth` 选项;命中时设置
-//! `DSH_SKIP_AUTH=1`(进程级开关,桌面端在启动参数里显式传该标志)。
-//! - `dsh-client-connection/lib/index.js`:仅当 `DSH_SKIP_AUTH=1` 时跳过
-//! browser-session 层(`authorizeIndex` 直接放行 index、`requestRejection` 不再
-//! 校验 cookie),Host/Origin 信任边界仍由 `isTrustedApiRequest` 保留。
-//!
-//! 锚点兼容两种核心布局(issue #358):
-//! - pkg 打包核心(deepseek-harness-pkg):`startup.js` 的 action 在
-//! `const options = program.opts();` 之后有 `const allowLan =
-//! process.env.DSH_PKG_ALLOW_LAN === "1";` 一行(pkg 构建注入的 0.0.0.0 护栏);
-//! - npm 全局原版核心(`npm i -g @deepseek-ai/dsh`):没有 allowLan 行,`opts()`
-//! 之后直接是 `--host`/`--port` 校验。
-//!
-//! 因此 action 锚点只匹配 `const options = program.opts();` 这一行,注入
-//! `--skip-auth` 处理并把 allowLan 等后续行原样保留;两种布局都能命中。
-//!
-//! 普通用户运行 `dsh web`(不带 `--skip-auth`)时鉴权行为与上游一致;旧核心无
-//! 上述锚点时 `patch_dsh` 安全跳过,不改变旧版行为。
-
-use std::path::Path;
-
-use crate::utils::{dsh_rel_contains, patch_core_file, patch_dsh, PatchOutcome};
-
-const PATCH_MARKER: &str = "dsh-tauri-desktop: alpha embedded auth --skip-auth flag";
-
-// ── dsh-web-app/lib/startup.js ────────────────────────────────────────────────
-const WEB_STARTUP_REL: &str = "node_modules/@deepseek-ai/dsh-web-app/lib/startup.js";
-const STARTUP_OPTION_ANCHOR: &str =
- ".option(\"--no-open\", \"do not open the Web UI in the default browser\")";
-const STARTUP_OPTION_REPLACEMENT: &str = ".option(\"--no-open\", \"do not open the Web UI in the default browser\")\n\t\t.option(\"--skip-auth\", \"skip the browser-session token/cookie exchange; keeps the Host/Origin trust fence (for embedded UIs)\")";
-const STARTUP_ACTION_ANCHOR: &str = "\t\tconst options = program.opts();";
-const STARTUP_ACTION_REPLACEMENT: &str = "\t\tconst options = program.opts();\n\t\t/* dsh-tauri-desktop: alpha embedded auth --skip-auth flag */\n\t\tif (options.skipAuth) process.env.DSH_SKIP_AUTH = \"1\";";
-
-// ── dsh-client-connection/lib/index.js ────────────────────────────────────────
-const CONNECTION_INDEX_JS: &str =
- "node_modules/@deepseek-ai/dsh-client-connection/lib/index.js";
-const REJECTION_ANCHOR: &str = "\trequestRejection(request) {\n\t\tif (!isTrustedApiRequest(request, this.trustedHosts)) return 403;\n\t\treturn this.browserAuth.isAuthenticated(request) ? void 0 : 401;\n\t}";
-const REJECTION_PATCHED: &str = "\trequestRejection(request) {\n\t\tif (!isTrustedApiRequest(request, this.trustedHosts)) return 403;\n\t\tif (process.env.DSH_SKIP_AUTH === \"1\") return void 0;\n\t\treturn this.browserAuth.isAuthenticated(request) ? void 0 : 401;\n\t} /* dsh-tauri-desktop: alpha embedded auth --skip-auth flag */";
-const AUTHORIZE_ANCHOR: &str = "\tauthorizeIndex(request, response) {\n\t\treturn this.browserAuth.authorizeIndex(request, response);\n\t}";
-const AUTHORIZE_PATCHED: &str = "\tauthorizeIndex(request, response) {\n\t\tif (process.env.DSH_SKIP_AUTH === \"1\") return true;\n\t\treturn this.browserAuth.authorizeIndex(request, response);\n\t} /* dsh-tauri-desktop: alpha embedded auth --skip-auth flag */";
-
-/// 替换 web 启动命令:接受 `--skip-auth`;命中时写入 `DSH_SKIP_AUTH=1` 作为与
-/// connection 层之间的进程级开关。
-fn patch_startup(source: &str) -> PatchOutcome {
- if source.contains(PATCH_MARKER) {
- return PatchOutcome::AlreadyPatched;
- }
- if !source.contains(STARTUP_OPTION_ANCHOR) || !source.contains(STARTUP_ACTION_ANCHOR) {
- return PatchOutcome::AnchorMissing;
- }
-
- let patched = source
- .replacen(STARTUP_OPTION_ANCHOR, STARTUP_OPTION_REPLACEMENT, 1)
- .replacen(STARTUP_ACTION_ANCHOR, STARTUP_ACTION_REPLACEMENT, 1);
- PatchOutcome::Patched(patched)
-}
-
-/// 替换 alpha 的 connection 鉴权:仅在 `DSH_SKIP_AUTH=1` 时跳过 browser-session,
-/// 始终保留 Host/Origin trust fence;未设置时行为与上游一致。
-fn patch_connection(source: &str) -> PatchOutcome {
- if source.contains(PATCH_MARKER) {
- return PatchOutcome::AlreadyPatched;
- }
- if !source.contains(REJECTION_ANCHOR) || !source.contains(AUTHORIZE_ANCHOR) {
- return PatchOutcome::AnchorMissing;
- }
-
- let patched = source
- .replacen(REJECTION_ANCHOR, REJECTION_PATCHED, 1)
- .replacen(AUTHORIZE_ANCHOR, AUTHORIZE_PATCHED, 1);
- PatchOutcome::Patched(patched)
-}
-
-/// 对活动核心应用「`--skip-auth` 可选鉴权」补丁。目标缺失或任一锚点变化时安全
-/// 跳过,不阻断启动。
-/// 对显式给定的核心安装目录施加本补丁(E2E 编排复用,无需运行中的桌面端)。
-pub fn apply_at(core_dir: &Path) -> Result<(), String> {
- patch_core_file(core_dir, WEB_STARTUP_REL, patch_startup)?;
- patch_core_file(core_dir, CONNECTION_INDEX_JS, patch_connection)?;
- Ok(())
-}
-pub fn apply(app_handle: &tauri::AppHandle) -> Result<(), String> {
- patch_dsh(app_handle, WEB_STARTUP_REL, patch_startup)?;
- patch_dsh(app_handle, CONNECTION_INDEX_JS, patch_connection)?;
- Ok(())
-}
-
-/// 活动核心是否已具备完整的 `--skip-auth` 支持(选项层与 connection 层都已命中,
-/// 或上游官方合并)。
-///
-/// 供 launch 判定是否往服务参数追加 `--skip-auth`:必须两层都生效才传,否则只传
-/// 了选项、connection 层不认,会造成「看似跳过、实则仍拦」的半吊子状态;同时避免
-/// 旧核心把未知选项当作错误而直接退出。
-pub fn web_startup_supports_skip_auth(app_handle: &tauri::AppHandle) -> bool {
- dsh_rel_contains(app_handle, WEB_STARTUP_REL, "--skip-auth")
- && dsh_rel_contains(app_handle, CONNECTION_INDEX_JS, "DSH_SKIP_AUTH")
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- fn connection_fixture() -> String {
- let mut source = String::new();
- source.push_str("\trequestRejection(request) {\n");
- source.push_str("\t\tif (!isTrustedApiRequest(request, this.trustedHosts)) return 403;\n");
- source.push_str("\t\treturn this.browserAuth.isAuthenticated(request) ? void 0 : 401;\n");
- source.push_str("\t}\n");
- source.push_str("\t/** Authenticate an index request through the process-token exchange or cookie. */\n");
- source.push_str(AUTHORIZE_ANCHOR);
- source.push_str("\n\tdsh web authentication required; reopen the URL printed by dsh web.\n");
- source
- }
-
- fn startup_fixture() -> String {
- let mut source = String::new();
- source.push_str("function webCommand() {\n");
- source.push_str(
- "\treturn new Command().name(\"dsh --profile web\").description(\"Serve the DeepSeek Harness browser UI.\").helpOption(\"-h, --help\", \"show this help\").option(\"--host <host>\", \"bind host\").option(\"--no-open\", \"do not open the Web UI in the default browser\").option(\"--port <port>\", \"listen port; pass 0 to let the OS pick a free one\").option(\"--trusted-host <authority...>\", \"extra authority the /api browser-trust fence accepts (host or host:port; repeatable)\").addHelpText(\"after\", `\nExamples:\n`);\n",
- );
- source.push_str("}\n\n");
- source.push_str("function apply(ctx) {\n");
- source.push_str("\tconst program = webCommand();\n");
- source.push_str("\tprogram.action(() => {\n");
- source.push_str(STARTUP_ACTION_ANCHOR);
- source.push_str("\n\t});\n");
- source.push_str("}\n");
- source
- }
-
- /// pkg 打包核心(deepseek-harness-pkg)布局:`opts()` 之后紧跟 pkg 注入的
- /// allowLan 护栏行(issue #358 中 dev 核心正是此布局,补丁必须保留该行)。
- fn startup_fixture_pkg_layout() -> String {
- let mut source = startup_fixture();
- source = source.replace(
- STARTUP_ACTION_ANCHOR,
- "\t\tconst options = program.opts();\n\t\tconst allowLan = process.env.DSH_PKG_ALLOW_LAN === \"1\";",
- );
- source
- }
-
- #[test]
- fn connection_patch_keeps_trust_fence_and_gates_browser_session() {
- let PatchOutcome::Patched(patched) = patch_connection(&connection_fixture()) else {
- panic!("expected connection patch");
- };
- assert!(patched.contains(PATCH_MARKER));
- // 信任边界保留。
- assert!(
- patched.contains("if (!isTrustedApiRequest(request, this.trustedHosts)) return 403;")
- );
- // 命中开关时不返回 401。
- assert!(patched.contains("if (process.env.DSH_SKIP_AUTH === \"1\") return void 0;"));
- // 未命中时仍走原鉴权。
- assert!(patched.contains("this.browserAuth.isAuthenticated(request) ? void 0 : 401"));
- // 未命中 index 仍交给上游。
- assert!(patched
- .contains("if (process.env.DSH_SKIP_AUTH === \"1\") return true;\n\t\treturn this.browserAuth.authorizeIndex(request, response);"));
- }
-
- #[test]
- fn startup_patch_adds_option_and_env_handoff() {
- let PatchOutcome::Patched(patched) = patch_startup(&startup_fixture()) else {
- panic!("expected startup patch");
- };
- assert!(patched.contains(PATCH_MARKER));
- assert!(patched.contains(".option(\"--skip-auth\", \"skip the browser-session token/cookie exchange; keeps the Host/Origin trust fence (for embedded UIs)\")"));
- assert!(patched
- .contains("\t\tif (options.skipAuth) process.env.DSH_SKIP_AUTH = \"1\";"));
- }
-
- /// 回归(issue #358):npm 全局原版核心的 startup.js 在 `opts()` 之后**没有**
- /// allowLan 行,旧锚点(要求两行紧邻)导致 AnchorMissing、`--skip-auth` 未注入,
- /// boot page 返回 401。现在锚点只匹配 `opts()` 单行,npm 布局必须可打补丁。
- #[test]
- fn startup_patch_applies_to_npm_original_layout_without_allow_lan() {
- let fixture = startup_fixture();
- // npm 原版无 allowLan 行
- assert!(!fixture.contains("DSH_PKG_ALLOW_LAN"));
-
- let PatchOutcome::Patched(patched) = patch_startup(&fixture) else {
- panic!("expected startup patch on npm original layout");
- };
- assert!(patched.contains(PATCH_MARKER));
- assert!(patched
- .contains("\t\tif (options.skipAuth) process.env.DSH_SKIP_AUTH = \"1\";"));
- }
-
- /// 回归(issue #358):pkg 打包核心的 allowLan 行必须在打补丁后原样保留,
- /// 不能因锚点放宽而被吞掉。
- #[test]
- fn startup_patch_preserves_pkg_allow_lan_line() {
- let fixture = startup_fixture_pkg_layout();
- assert!(fixture.contains("DSH_PKG_ALLOW_LAN"));
-
- let PatchOutcome::Patched(patched) = patch_startup(&fixture) else {
- panic!("expected startup patch on pkg layout");
- };
- assert!(patched.contains(PATCH_MARKER));
- assert!(patched
- .contains("\t\tconst allowLan = process.env.DSH_PKG_ALLOW_LAN === \"1\";"));
- assert!(patched
- .contains("\t\tif (options.skipAuth) process.env.DSH_SKIP_AUTH = \"1\";"));
- }
-
- #[test]
- fn patches_are_idempotent() {
- let PatchOutcome::Patched(startup) = patch_startup(&startup_fixture()) else {
- panic!("expected startup patch");
- };
- assert_eq!(patch_startup(&startup), PatchOutcome::AlreadyPatched);
-
- let PatchOutcome::Patched(connection) = patch_connection(&connection_fixture()) else {
- panic!("expected connection patch");
- };
- assert_eq!(patch_connection(&connection), PatchOutcome::AlreadyPatched);
- }
-
- #[test]
- fn legacy_or_changed_layout_is_untouched() {
- assert_eq!(
- patch_connection("requestRejection(request) { return 401; }"),
- PatchOutcome::AnchorMissing
- );
- assert_eq!(patch_startup("no web command here"), PatchOutcome::AnchorMissing);
-
- // `opts()` 行本身不存在(旧核心/上游布局彻底变化)→ 跳过
- let partial = startup_fixture().replace(
- STARTUP_ACTION_ANCHOR,
- "\t\tconst options = program.parse();",
- );
- assert_eq!(patch_startup(&partial), PatchOutcome::AnchorMissing);
-
- let partial = connection_fixture().replace(
- REJECTION_ANCHOR,
- "requestRejection(request) { return 401; }",
- );
- assert_eq!(patch_connection(&partial), PatchOutcome::AnchorMissing);
- }
-}
diff --git a/src-tauri/src/service/patch/mod.rs b/src-tauri/src/service/patch/mod.rs
index 1913a5b2..90b84fc6 100644
--- a/src-tauri/src/service/patch/mod.rs
+++ b/src-tauri/src/service/patch/mod.rs
@@ -8,7 +8,6 @@
//! 命名约定:子模块名不带 `_patch` 后缀(`renderer` / `session` / `workspace` /
//! `client_hmr`),挂点统一为 `service::workflow::launch`,均为最佳努力、失败仅告警。
-pub(crate) mod alpha_auth;
pub(crate) mod client_hmr;
pub(crate) mod llm_session;
pub(crate) mod renderer;
@@ -27,8 +26,7 @@ use std::path::Path;
/// 单个补丁失败不阻断其余:与启动路径一样是「最佳努力」,但这里把错误汇总返回,
/// 让编排层能看见哪一条出了问题。
pub(crate) fn apply_all_at(core_dir: &Path) -> Result<(), String> {
- let patches: [(&str, fn(&Path) -> Result<(), String>); 7] = [
- ("alpha_auth", alpha_auth::apply_at),
+ let patches: [(&str, fn(&Path) -> Result<(), String>); 6] = [
("renderer", renderer::apply_at),
("session", session::apply_at),
("llm_session", llm_session::apply_at),
diff --git a/src-tauri/src/service/workflow/launch.rs b/src-tauri/src/service/workflow/launch.rs
index a7d17584..2d599da7 100644
--- a/src-tauri/src/service/workflow/launch.rs
+++ b/src-tauri/src/service/workflow/launch.rs
@@ -409,13 +409,6 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
if let Err(e) = win_inspector::apply(&app_handle) {
log::warn!("win32 terminal support apply failed: {e}");
}
- // alpha 的 iframe 无法稳定完成 SameSite=Strict browser-session Cookie 交换:
- // 补丁让 dsh 接受 `--skip-auth`,仅在桌面端显式传该标志时跳过 browser-session
- // 层(保留 Host/Origin fence);普通 `dsh web` 不受影响。旧核心无锚点时
- // patch_dsh 安全跳过,不改变旧版行为。
- if let Err(e) = crate::service::patch::alpha_auth::apply(&app_handle) {
- log::warn!("alpha --skip-auth patch failed: {e}");
- }
// renderer 的 SlotOutlet 一行导出补丁(dsh-tauri-ui 设置侧边栏依赖):只补
// 活动核心的 dsh-client-ui-renderer lib/client.js,已含导出即跳过(幂等;核心
// 换版本后自动重打,上游官方导出后自动退休)。最佳努力:失败只告警,不阻断
@@ -580,6 +573,12 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
envs.insert("DSH_PREFER_BUNDLED_PNPM".to_string(), "1".to_string());
}
+ // 内嵌 WebView 是 `tauri.localhost` 下的跨源沙箱 iframe,`SameSite=Strict` 的
+ // browser-session Cookie 不会被携带。载体标记交给 dsh-tauri-connection 插件:
+ // 只有该标记在场时它才覆写 connection 的鉴权闸门,因此同一 profile 下独立运行
+ // 的 `dsh web` 不受影响(取代原先对核心 JS 打的 `--skip-auth` 磁盘补丁)。
+ envs.insert("DSH_TAURI_EMBEDDED".to_string(), "1".to_string());
+
// 日志文件(前端日志面板读取)。
// 每次真实启动前轮转:只保留最近 3 次启动的日志,旧文件后退为
// `dsh-web.log.1` / `dsh-web.log.2`,避免单文件随多次启动无限增长。
@@ -592,12 +591,6 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
// 浏览器,追加 `--no-open` 关闭(老版本无此标志时按版本判定不传)。
let no_open = web_supports_no_open_flag(&app_handle, &dsh_binary_path);
- // 版本判定打不到 alpha 的 web-startup 选项表(见 web_supports_no_open_flag)。
- // alpha 的浏览器会话 Cookie 在沙箱跨源 iframe 上下文无法完成交换,因此桌面端
- // 显式追加 `--skip-auth`:只有核心(经上面的 alpha_auth 补丁,或上游官方合并)
- // 确实支持该标志才传,避免旧核心把未知选项当成错误退出。
- let skip_auth = crate::service::patch::alpha_auth::web_startup_supports_skip_auth(&app_handle);
-
// 补丁层悬空 insert 预检:手写的 `insert` 条目在包被卸载(市场会拒绝卸载
// 「仍被用户补丁引用」的插件,用户于是改走手工删依赖 / pnpm remove)或本地
// `link:` 源被删后仍留在补丁层里,loader 会在 import 时抛 ERR_MODULE_NOT_FOUND,
@@ -645,9 +638,6 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
if no_open {
args.push(OsString::from("--no-open"));
}
- if skip_auth {
- args.push(OsString::from("--skip-auth"));
- }
// 只负责 spawn 并返回管道/PID/句柄:探测与重试期间不登记、不挂
// 监视线程——只有最终采用的那个进程才登记,否则旧监视线程会通过
@@ -758,9 +748,6 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
if no_open {
cmd.arg("--no-open");
}
- if skip_auth {
- cmd.arg("--skip-auth");
- }
cmd.envs(&envs)
.current_dir(config::get_dsh_install_path(&app_handle))
// 核心修正:提供一个空的 stdin 防止 setRawMode 报错
@@ -804,9 +791,6 @@ pub async fn launch(app_handle: tauri::AppHandle) -> Result<(), String> {
if no_open {
cmd.arg("--no-open");
}
- if skip_auth {
- cmd.arg("--skip-auth");
- }
cmd.envs(&envs)
.current_dir(config::get_dsh_install_path(&app_handle))
.stdin(Stdio::null())
diff --git a/src-tauri/src/utils/mod.rs b/src-tauri/src/utils/mod.rs
index 6e95d750..90d454ca 100644
--- a/src-tauri/src/utils/mod.rs
+++ b/src-tauri/src/utils/mod.rs
@@ -78,19 +78,6 @@ pub fn patch_core_file(
Ok(())
}
-/// 判定活动核心安装目录下的某个 dsh 包文件是否包含给定子串。
-///
-/// 用于「按能力追加启动参数」:例如 web 启动命令已具备 `--skip-auth`(本工具已打
-/// 过补丁或上游官方合并)才向服务参数追加该标志。目标不存在或读取失败一律视为
-/// 不包含,调用方据此保守不传标志。
-pub fn dsh_rel_contains(app_handle: &tauri::AppHandle, rel_path: &str, needle: &str) -> bool {
- let target = active_core_install_dir(app_handle).join(rel_path);
- match std::fs::read_to_string(&target) {
- Ok(content) => content.contains(needle),
- Err(_) => false,
- }
-}
-
pub fn show_window<R: Runtime>(window: &WebviewWindow<R>) {
let _ = window.unminimize();
let _ = window.show();