diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d447abc..e416d38d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - 🧷 **安装下限改由 `package.json#engines.dsh` 独立裁决(`>=0.2.2-rc.3 <0.3.0`)**:宿主预检先读该字段,字段存在时不再看 14 条 DSH peer,因此停在 0.2.1 及更早宿主的安装失败会被插件市场判成「先升级 DSH」,不再当作插件缺陷自动开 issue。0.2.2-rc.2 及更早的 0.2.2 宿主继续使用 v0.32.1。 +- 🧩 **DSH master(0.2.2-rc.3 之后)删除 `connection.requestRejection` 后,`/sidebar/*` 不再全部裸 400**([#1204](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1204)):HTTP/WS 准入改为先调用 `requestRejection`(rc.1–rc.3 行为不变),该方法缺席时改用官方替代 `admit` 并读同一个 `rejection` 字段;两者都没有时仍然直接抛错,不重建信任表。此前宿主删掉该方法后,每个请求在第一句就抛 `TypeError`,被宿主兜底成空 body 的 400,界面只剩 `HTTP 400`。 + - 🧪 测试:`tests/trusted-hosts.spec.ts` 新增「`requestRejection` 缺席时走 `admit`」三档(放行 / 401 / 403),并保留「两者都没有仍抛 TypeError」的既有断言。 + - 💻 **侧边对话显示 PTC(run_code)工具调用树**:`run_code` 行收起时显示模型写的 description,展开后显示程序代码和最终结果;程序内通过 PTC 派发的 bash / read / grep / edit 等子调用缩进挂在它下方,根行收起也可见,并复用终端 / diff / read / search / web 结构卡片。运行中、失败、无 start 的 dispatch 都有对应显示;PTC 内成功 write/edit 的文件也进入可点击路径提及。`present` 仍保留顶层交付卡片,同时在子调用区留下一行。 - 🧪 测试:`tests/sidechat-ptc-rows.spec.ts`(配对 / 运行态 / 失败 / 无 start / 嵌套 / 父行缺失 / 身份复用)、`tests/sidechat-ptc-subcalls.spec.tsx`(description 摘要、代码体、缩进与卡片、根行收起仍可见)、`tests/sidechat-mention-sources.spec.tsx`(PTC mutation 进入提及、read 不进入)。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index f80aa5be..340ea84b 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -8,6 +8,9 @@ - 🧷 **The install floor is now arbitrated by `package.json#engines.dsh` alone (`>=0.2.2-rc.3 <0.3.0`)**: the host precheck reads that field first and, when present, ignores the 14 DSH peers, so an install that fails on a 0.2.1-or-older host is classified by the plugin market as "upgrade DSH first" instead of being filed against this plugin. Hosts on 0.2.2-rc.2 or earlier 0.2.2 prereleases stay on v0.32.1. +- 🧩 **`/sidebar/*` no longer answers a bare 400 once DSH master (after 0.2.2-rc.3) removed `connection.requestRejection`** ([#1204](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1204)): HTTP/WS admission calls `requestRejection` while it exists (rc.1–rc.3 behaviour unchanged) and otherwise uses the official replacement `admit`, reading the same `rejection` field; when neither exists it still throws instead of rebuilding a trust list. Before this, every request threw a `TypeError` on its first line and the host's fallback turned that into an empty-body 400, leaving only `HTTP 400` on screen. + - 🧪 Tests: `tests/trusted-hosts.spec.ts` gains the "`requestRejection` gone → `admit`" path (allow / 401 / 403) and keeps the existing "neither method still throws TypeError" assertion. + - 💻 **Side Chat renders PTC (run_code) tool trees**: the collapsed `run_code` line shows the model-written description, and its expanded body shows the program plus the final result. Tools dispatched inside the program (bash / read / grep / edit, …) render as indented rows under it — visible even when the root row is collapsed — through the same terminal / diff / read / search / web cards. Running, failed and start-less dispatches all render; successful PTC writes/edits join the clickable path mentions. `present` keeps its top-level delivery card and also leaves a sub-call row. - 🧪 Tests: `tests/sidechat-ptc-rows.spec.ts` (pairing / running / failed / no-start / nested / missing parent / identity reuse), `tests/sidechat-ptc-subcalls.spec.tsx` (description summary, program body, indentation and cards, collapsed-root visibility) and `tests/sidechat-mention-sources.spec.tsx` (PTC mutations count, reads do not). diff --git a/docs/dsh-version-adaptation.md b/docs/dsh-version-adaptation.md index 90085721..85a29aeb 100644 --- a/docs/dsh-version-adaptation.md +++ b/docs/dsh-version-adaptation.md @@ -53,7 +53,7 @@ ## 5. 仍然生效的删除契约(alpha.5 起) - 不再依赖 `dsh-invariants`、`ctx.invariants` 或上游 `/invariant` 子路径;不发布 invariant companion。 -- HTTP/WS 准入统一调用 `ctx.connection.requestRejection(req)`,**只有 `undefined` 放行**;不恢复 `webRuntime`,不自建信任例外。 +- HTTP/WS 准入优先调用 `ctx.connection.requestRejection(req)`,**只有 `undefined` 放行**;DSH 0.2.2-rc.3 起该方法 deprecated、master 已删除,缺席时改调 `admit(req)` 并读同一个 `rejection` 字段(两者都没有则直接抛错);不恢复 `webRuntime`,不自建信任例外。 ## 6. 0.2.1 → 0.2.2 的代码级差异(v0.30.0) diff --git a/docs/host-contracts.md b/docs/host-contracts.md index 46a21b46..b31dd79e 100644 --- a/docs/host-contracts.md +++ b/docs/host-contracts.md @@ -4,7 +4,7 @@ > **编号保持不变**:代码、测试与文档里写的「AGENTS.md §3.4 第 N 条」就是本文第 N 条。 > 历史版本已不在支持线内(当前基线 DSH 0.2.2-rc.2,见 [docs/dsh-version-adaptation.md](dsh-version-adaptation.md));逐条适配过程见 [docs/plans/](plans/) 与 [CHANGELOG.md](../CHANGELOG.md)。 -当前适配约束:HTTP/WS 均由 `ctx.connection.requestRejection(req)` 裁决 Host/Origin 与浏览器认证,只有 `undefined` 放行,不读取已删除的 `webRuntime`。alpha.5 同时移除了 `@deepseek-ai/dsh-invariants`、`ctx.invariants` 和上游 `/invariant` 子路径;本插件不再发布 invariant companion。 +当前适配约束:HTTP/WS 均由宿主 Connection 的准入方法裁决 Host/Origin 与浏览器认证——`requestRejection(req)` 存在时用它(只有 `undefined` 放行),rc.3 之后它被删除、只剩 `admit(req)`,则读 `admit` 返回对象上的同一个 `rejection` 字段;不读取已删除的 `webRuntime`,也不自建信任表。alpha.5 同时移除了 `@deepseek-ai/dsh-invariants`、`ctx.invariants` 和上游 `/invariant` 子路径;本插件不再发布 invariant companion。 **本次 0.2.2-rc.1 → rc.2 有真实契约变化**:`ui-primitives` 的 `Menu` 用 `anchorRef` / `anchorPoint` 取代 `getAnchorRect`,portal 菜单改为 CSS Anchor Positioning,子菜单改为 portal 到 `document.body` 并按空间选 side / single-page;`@deepseek-ai/dsh-agent-team`(base composition)取代实验包,`TeamService` 的 `tryMembership` 换成 `isEnabled`;所有宿主包把 Cordis peer 收紧到 `~4.1.0`,并新增 `@deepseek-ai/dsh-error` 传递 peer。上一轮 0.2.1 → 0.2.2 的 `AgentModel` / PTC / sprite 变化见 [0.2.2-rc.1 适配记录](plans/2026-11-04-dsh-0.2.2-rc.1-adaptation.md)。逐项证据见 [0.2.2-rc.2 适配记录](plans/2026-11-12-dsh-0.2.2-rc.2-adaptation.md)。 diff --git a/scripts/e2e-common.sh b/scripts/e2e-common.sh index 75a30706..4738bcb6 100644 --- a/scripts/e2e-common.sh +++ b/scripts/e2e-common.sh @@ -44,7 +44,7 @@ e2e_require_cmd() { # 回退的 npx 版本是显式钉死的:不钉就会解析 npm 的 dist-tag,可能静默挂到 # 插件不支持的宿主上。**必须写精确版本,不能写 `@next`/`@alpha` 等 dist-tag**。 # 该版本必须与 package.json 的 DSH peer 基线同步。 -DSH_NPX_SPEC="${DSH_NPX_SPEC:-@deepseek-ai/dsh@0.2.2-rc.2}" +DSH_NPX_SPEC="${DSH_NPX_SPEC:-@deepseek-ai/dsh@0.2.2-rc.3}" e2e_resolve_dsh_cmd() { local explicit="${DSH_CMD}" if ! command -v "$DSH_CMD" >/dev/null 2>&1; then @@ -66,7 +66,7 @@ e2e_resolve_dsh_cmd() { # 己在挂什么),只告警。 e2e_check_dsh_version() { local explicit="$1" actual expected - expected="${DSH_EXPECT_VERSION:-0.2.2-rc.2}" + expected="${DSH_EXPECT_VERSION:-0.2.2-rc.3}" # `dsh --version` 冷启动要走 npx,给足预算;拿不到版本就只告警。 actual="$($DSH_CMD --version 2>/dev/null | tr -d '[:space:]' | head -c 64 || true)" case "$actual" in diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 0b016c1a..636ea0ba 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1,4 +1,4 @@ -## ============================================================================= +## ============================================================================= # dsh-better-sidebar 一键安装脚本(官方 CLI 方式,Windows PowerShell 5.1+ / pwsh) # # 通过 DSH 官方插件命令安装 npm 包并自动挂载: @@ -28,7 +28,7 @@ # 环境变量(均可省略): # DSH_HOME 默认 %USERPROFILE%\.dsh # REGISTRY 默认 https://registry.npmjs.org -# DSH_CMD 默认优先 PATH 上的 dsh,缺省回退 npx -y --package @deepseek-ai/dsh@0.2.2-rc.2 +# DSH_CMD 默认优先 PATH 上的 dsh,缺省回退 npx -y --package @deepseek-ai/dsh@0.2.2-rc.3 # # 说明: # - pnpm 11 的 minimumReleaseAge 会拒绝发布 <24h 的新版本。脚本会预写 @@ -174,7 +174,7 @@ Ensure-WorkspaceSettings if ($CLI -eq 'dsh') { $cliArgs = @('plugin', '--profile', $Profile, 'add', "$PKG@$SPEC") } else { - $cliArgs = @('-y', '--package', '@deepseek-ai/dsh@0.2.2-rc.2', 'dsh', 'plugin', '--profile', $Profile, 'add', "$PKG@$SPEC") + $cliArgs = @('-y', '--package', '@deepseek-ai/dsh@0.2.2-rc.3', 'dsh', 'plugin', '--profile', $Profile, 'add', "$PKG@$SPEC") } Say "执行 $CLI plugin --profile $Profile add $PKG@$SPEC ..." $addOut = & $CLI @cliArgs 2>&1 diff --git a/scripts/install.sh b/scripts/install.sh index ce69e504..d0651dfc 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -24,7 +24,7 @@ # 环境(均可省略,脚本会自动探测): # DSH_HOME 默认 ~/.dsh(Windows Git Bash 下回退 $USERPROFILE/.dsh) # REGISTRY 默认 https://registry.npmjs.org(发布源;装依赖仍走 pnpm 配置) -# DSH_CMD 默认优先用 PATH 上的 `dsh`,缺省回退 npx -y --package @deepseek-ai/dsh@0.2.2-rc.2 +# DSH_CMD 默认优先用 PATH 上的 `dsh`,缺省回退 npx -y --package @deepseek-ai/dsh@0.2.2-rc.3 # # 说明: # - pnpm 11 的 minimumReleaseAge 会拒绝发布 <24h 的新版本。脚本会预写 @@ -140,7 +140,7 @@ dsh_cli() { if command -v "$DSH_CMD" >/dev/null 2>&1; then printf '%s' "$DSH_CMD" elif command -v npx >/dev/null 2>&1; then - printf 'npx -y --package @deepseek-ai/dsh@0.2.2-rc.2 dsh' + printf 'npx -y --package @deepseek-ai/dsh@0.2.2-rc.3 dsh' else die "未找到 dsh 或 npx。请先安装 DSH(并确保 Node/npm 可用),或用 DSH_CMD 指定 dsh 路径。" fi diff --git a/src/context-types.ts b/src/context-types.ts index c2622426..86614147 100644 --- a/src/context-types.ts +++ b/src/context-types.ts @@ -118,8 +118,12 @@ export interface SidebarSessionStore { * Host request admission plus the client transport recovery face. */ export interface SidebarConnectionService { - /** Public Host/Origin and authentication policy (DSH 0.2.0-rc.2+). */ - requestRejection(request: { headers: Record }): 401 | 403 | undefined + /** Public Host/Origin and authentication policy (DSH 0.2.0-rc.2+). Deprecated + * after 0.2.2-rc.3 and removed on DSH master — `admit` is the replacement. */ + requestRejection?(request: { headers: Record }): 401 | 403 | undefined + /** Host admission (DSH 0.2.2-rc.3+, the method `requestRejection` delegated to). + * Returns an object carrying `rejection` when the request is refused. */ + admit?(request: { headers: Record }): unknown state: { getSnapshot(): 'connected' | 'disconnected' | 'connecting' | undefined subscribe(listener: () => void): () => void diff --git a/src/index.ts b/src/index.ts index c7701dc4..65ed4f3c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1463,7 +1463,22 @@ export function apply(ctx: Context, config?: SidebarConfig): void { const resolved = resolveSidebarConfig(config) // Connection owns both deployment trust and authentication; never infer or // bypass its policy from invocation flags or a copied trust list. - const fence = (req: SidebarHttpRequest): boolean => ctx.connection.requestRejection(req) === undefined + // DSH 0.2.2-rc.3 deprecated `requestRejection` and DSH master removed it, leaving + // `admit` (the method the old wrapper delegated to) as the only admission call. + // Prefer the old method while it exists so rc.1–rc.3 semantics stay byte-identical, + // then fall back to `admit` and read the same `rejection` field. Never rebuild a + // trust list here: when neither method exists the request fails loudly. + const fence = (req: SidebarHttpRequest): boolean => { + const connection = ctx.connection + const requestRejection = connection.requestRejection + if (typeof requestRejection === 'function') return requestRejection.call(connection, req) === undefined + const admit = connection.admit + if (typeof admit === 'function') { + const admission = admit.call(connection, req) + return !(admission !== null && typeof admission === 'object' && 'rejection' in admission) + } + throw new TypeError('connection exposes neither requestRejection nor admit') + } // The model-facing open-request registry: queues `sidebar_open` requests // per session and pushes them to connected sidebar views over the // `/sidebar/ws/agent-opens` socket. diff --git a/tests/dsh-baseline.spec.ts b/tests/dsh-baseline.spec.ts index 65bf51e3..f9429251 100644 --- a/tests/dsh-baseline.spec.ts +++ b/tests/dsh-baseline.spec.ts @@ -6,6 +6,10 @@ import { readFileSync } from 'node:fs' import { describe, expect, it } from 'vitest' const baseline = '0.2.2-rc.2' +/** The host runtime the mount lane and the standalone installers pin. It follows + * `package.json#engines.dsh`, which is stricter than the peer floor: the plugin + * installs on this line or newer, so every place that actually runs it moves. */ +const hostBaseline = '0.2.2-rc.3' const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')) const bash = readFileSync(new URL('../scripts/install.sh', import.meta.url), 'utf8') const powershell = readFileSync(new URL('../scripts/install.ps1', import.meta.url), 'utf8') @@ -32,16 +36,16 @@ describe('DSH host baseline', () => { }) it('pins both standalone installer npx fallbacks', () => { - expect(bash).toContain(`printf 'npx -y --package @deepseek-ai/dsh@${baseline} dsh'`) - expect(powershell).toContain(`$cliArgs = @('-y', '--package', '@deepseek-ai/dsh@${baseline}', 'dsh', 'plugin'`) + expect(bash).toContain(`printf 'npx -y --package @deepseek-ai/dsh@${hostBaseline} dsh'`) + expect(powershell).toContain(`$cliArgs = @('-y', '--package', '@deepseek-ai/dsh@${hostBaseline}', 'dsh', 'plugin'`) for (const source of [bash, powershell]) { expect(source).not.toMatch(/^\s*(?:source|\.)\s+[^\r\n]*e2e-common/m) } }) it('pins the e2e fallback and expected version to the same baseline', () => { - expect(e2e).toContain('DSH_NPX_SPEC="${DSH_NPX_SPEC:-@deepseek-ai/dsh@' + baseline + '}"') - expect(e2e).toContain('expected="${DSH_EXPECT_VERSION:-' + baseline + '}"') + expect(e2e).toContain('DSH_NPX_SPEC="${DSH_NPX_SPEC:-@deepseek-ai/dsh@' + hostBaseline + '}"') + expect(e2e).toContain('expected="${DSH_EXPECT_VERSION:-' + hostBaseline + '}"') }) it.each(['\n', '\r\n'])('pins CI with its heap budget and peer resolution intact (%j)', (eol) => { diff --git a/tests/trusted-hosts.spec.ts b/tests/trusted-hosts.spec.ts index 7575485b..af7a84e9 100644 --- a/tests/trusted-hosts.spec.ts +++ b/tests/trusted-hosts.spec.ts @@ -148,6 +148,26 @@ describe('native Connection admission', () => { } }) + it('falls back to native admit once requestRejection is gone', async () => { + const mounted = mount() + try { + let rejection: 401 | 403 | undefined + const admit = vi.fn(() => (rejection === undefined ? {} : { rejection })) + Reflect.deleteProperty(mounted.connection, 'requestRejection') + Object.assign(mounted.connection as unknown as Record, { admit }) + const route = mounted.routes.find(candidate => candidate.path === '/sidebar/api')! + for (const [verdict, expected] of [[undefined, 200], [401, 403], [403, 403]] as const) { + rejection = verdict + const { res, out } = response() + await route.handler(request('/sidebar/api/session.cwd').req, res) + expect(out.status).toBe(expected) + } + expect(admit).toHaveBeenCalledTimes(3) + } finally { + mounted.cleanup() + } + }) + it('does not bypass native refusals for former desktop, image, or port exceptions', async () => { const mounted = mount(403) try {