diff --git a/CHANGELOG.md b/CHANGELOG.md index 06dbc82d..dbadb21d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### v0.33.0 +- 🧩 **DSH 0.2.3 上 `/sidebar/*` 恢复可用**(关联 [#1204](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1204)):0.2.3 把 `admit` 的凭据校验委托给嵌套服务 `connection.authentication`,cordis 只允许**显式注入**该服务的调用方读取它;插件此前只注入 `connection`,`admit` 一被调用就抛 `cannot get property "connection.authentication" without inject`,被宿主兜底成空 body 的 400——底部终端 chunk 加载、打开文件、侧边对话全部只剩 `HTTP 400`。现在准入改走 `ctx.inject(['connection.authentication'])` 子 fiber 里的 `admit`;rc.2–rc.5 没有该服务,子 fiber 不激活,继续走 `requestRejection` / 直接 `admit`,旧宿主行为不变。 + - 🧪 测试:`tests/trusted-hosts.spec.ts` 新增「0.2.3 宿主:插件上下文调用 `admit` 抛错、经注入的 provider 上下文放行」三档(放行 / 401 / 403),旧宿主两条路径的既有断言保留。 + - 🧷 **Git 详情面板的关闭按钮常驻在 Tabs 同一行的最右侧**([#991](https://github.com/omdsh-dev/DSH-better-sidebar/issues/991)):底部面板的「提交详情 / 内容 / 差异」是一条 Tabs,但关闭整块面板的 X 原先画在「内容 / 差异」的页内头行上——切到「提交详情」时它整条头行都不渲染,于是那个页签根本没有关闭入口,只能先切页签再点 X。现在关闭按钮属于 Tabs 那一行:无论选中哪个页签都停在最右端、位置不变,点击关闭的是整块面板;「内容 / 差异」头行里那个重复的 X 已移除。只有一个视图、没有 Tabs 行的预览仍保持原来的头行位置。 - 🧪 测试:`tests/changes-tab.spec.tsx` 逐个页签断言面板里**只有一个**关闭按钮、它挂在 Tabs 那一行且排在 tablist 之后(行尾),并从「提交详情」页签点击它关闭整块面板。 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index feeb82da..9c2d7e61 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -6,6 +6,9 @@ ### v0.33.0 +- 🧩 **`/sidebar/*` works again on DSH 0.2.3** (related: [#1204](https://github.com/omdsh-dev/DSH-better-sidebar/issues/1204)): 0.2.3 moved `admit`'s credential check into the nested `connection.authentication` service, and cordis only lets a caller read that service when it **declares the dependency**. The plugin injected `connection` alone, so `admit` threw `cannot get property "connection.authentication" without inject` on the first request and the host's last-resort guard turned it into an empty-body 400 — the bottom terminal chunk, opening a file and the side chat all showed `HTTP 400` only. Admission now runs `admit` inside a `ctx.inject(['connection.authentication'])` child fiber; rc.2–rc.5 have no such service, so the fiber never activates there and those hosts keep the `requestRejection` / direct `admit` paths unchanged. + - 🧪 Tests: `tests/trusted-hosts.spec.ts` adds the 0.2.3 shape (plugin-context `admit` throws, the injected provider context decides) for allow / 401 / 403, and keeps the existing assertions for older hosts. + - 🧷 **The Git details pane's close button now sits permanently at the right end of the tab row** ([#991](https://github.com/omdsh-dev/DSH-better-sidebar/issues/991)): the bottom pane's "commit details / content / diff" strip is one tab row, but the X that closes the whole pane was drawn inside the content/diff head — a row that does not render at all on the details tab, so that tab had no exit and closing meant switching views first. The button now belongs to the tab row: it stays at the right end on every tab, never moves, and closes the whole pane; the duplicate X inside the content/diff head is gone. A single-view preview with no tab row keeps its previous head placement. - 🧪 Tests: `tests/changes-tab.spec.tsx` asserts, per tab, that the pane holds exactly one close button, that it rides the tab row after the tablist (the row's right end), and that clicking it from the details tab closes the whole pane. diff --git a/docs/dsh-version-adaptation.md b/docs/dsh-version-adaptation.md index 0e49a2ec..7c17ead4 100644 --- a/docs/dsh-version-adaptation.md +++ b/docs/dsh-version-adaptation.md @@ -54,7 +54,7 @@ ## 5. 仍然生效的删除契约(alpha.5 起) - 不再依赖 `dsh-invariants`、`ctx.invariants` 或上游 `/invariant` 子路径;不发布 invariant companion。 -- HTTP/WS 准入优先调用 `ctx.connection.requestRejection(req)`,**只有 `undefined` 放行**;DSH 0.2.2-rc.3 起该方法 deprecated、master 已删除,缺席时改调 `admit(req)` 并读同一个 `rejection` 字段(两者都没有则直接抛错);不恢复 `webRuntime`,不自建信任例外。 +- HTTP/WS 准入优先调用 `ctx.connection.requestRejection(req)`,**只有 `undefined` 放行**;DSH 0.2.2-rc.3 起该方法 deprecated、0.2.3 已删除,缺席时改调 `admit(req)` 并读同一个 `rejection` 字段。0.2.3 的 `admit` 把凭据校验委托给嵌套服务 `connection.authentication`,cordis 只允许**显式注入**该服务的调用方读取它,所以这一段放在 `ctx.inject(['connection.authentication'])` 子 fiber 里执行;rc.2–rc.5 没有该服务,子 fiber 不激活,旧宿主行为不变。两者都没有则直接抛错;不恢复 `webRuntime`,不自建信任例外。 ## 6. 0.2.1 → 0.2.2 的代码级差异(v0.30.0) diff --git a/docs/host-contracts.md b/docs/host-contracts.md index b31dd79e..550aeb01 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 均由宿主 Connection 的准入方法裁决 Host/Origin 与浏览器认证——`requestRejection(req)` 存在时用它(只有 `undefined` 放行),rc.3 之后它被删除、只剩 `admit(req)`,则读 `admit` 返回对象上的同一个 `rejection` 字段;不读取已删除的 `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` 字段。0.2.3 的 `admit` 需要一个由调用方显式注入的嵌套服务 `connection.authentication`(rc.2–rc.5 没有它),因此 `admit` 在 `ctx.inject(['connection.authentication'])` 子 fiber 内调用;不读取已删除的 `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/src/index.ts b/src/index.ts index 65ed4f3c..2ec72666 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1463,20 +1463,33 @@ 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. - // DSH 0.2.2-rc.3 deprecated `requestRejection` and DSH master removed it, leaving + // DSH 0.2.2-rc.3 deprecated `requestRejection` and DSH 0.2.3 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. + // From 0.2.3 `admit` also delegates the credential check to the verifier + // registered under the NESTED `connection.authentication` service, and cordis + // refuses that read unless the caller declares the dependency. Hosts at + // rc.2–rc.5 have no such service (their `admit` verifies in place), so the + // dependency lives in a child fiber: where the service never appears the + // callback never runs and admission keeps using the host's own method. Never + // rebuild a trust list here: when no admission path is available the request + // fails loudly. + /** `admit` refuses by carrying `rejection`; nothing else counts as a refusal. */ + const admitted = (verdict: unknown): boolean => + !(verdict !== null && typeof verdict === 'object' && 'rejection' in verdict) + let admitThroughProvider: ((req: SidebarHttpRequest) => boolean) | undefined + ctx.inject(['connection.authentication'], (providerCtx) => { + const connection = (providerCtx as Context).connection + const admit = connection.admit + if (typeof admit !== 'function') return + admitThroughProvider = (req) => admitted(admit.call(connection, req)) + }) const fence = (req: SidebarHttpRequest): boolean => { const connection = ctx.connection const requestRejection = connection.requestRejection if (typeof requestRejection === 'function') return requestRejection.call(connection, req) === undefined + if (admitThroughProvider !== undefined) return admitThroughProvider(req) const admit = connection.admit - if (typeof admit === 'function') { - const admission = admit.call(connection, req) - return !(admission !== null && typeof admission === 'object' && 'rejection' in admission) - } + if (typeof admit === 'function') return admitted(admit.call(connection, req)) throw new TypeError('connection exposes neither requestRejection nor admit') } // The model-facing open-request registry: queues `sidebar_open` requests diff --git a/tests/trusted-hosts.spec.ts b/tests/trusted-hosts.spec.ts index af7a84e9..869c5dfc 100644 --- a/tests/trusted-hosts.spec.ts +++ b/tests/trusted-hosts.spec.ts @@ -10,6 +10,7 @@ function mount(initialRejection: 401 | 403 | undefined = undefined) { const routes: SidebarWebRoute[] = [] const upgrades: SidebarWebUpgradeRoute[] = [] const effects: Array<() => void> = [] + const injections: Array<{ deps: readonly string[]; activate: (ctx: unknown) => void }> = [] apply({ connection, webServer: { @@ -22,7 +23,10 @@ function mount(initialRejection: 401 | 403 | undefined = undefined) { const cleanup = fn() if (typeof cleanup === 'function') effects.push(cleanup) }, - inject: () => () => {}, + inject: (deps: readonly string[], callback: (ctx: unknown) => void) => { + injections.push({ deps, activate: callback }) + return () => {} + }, on: () => () => {}, get: () => undefined, } as never) @@ -31,6 +35,12 @@ function mount(initialRejection: 401 | 403 | undefined = undefined) { routes, upgrades, setRejection: (next: 401 | 403 | undefined) => { rejection = next }, + /** Fire the child fiber that waits for `connection.authentication` (0.2.3+). */ + activateProvider: (providerConnection: unknown = connection) => { + for (const injection of injections) { + if (injection.deps.includes('connection.authentication')) injection.activate({ connection: providerConnection }) + } + }, cleanup: () => { for (const cleanup of effects) cleanup() }, } } @@ -168,6 +178,31 @@ describe('native Connection admission', () => { } }) + it('admits through the injected authentication provider when admit reads the nested service', async () => { + const mounted = mount() + try { + let rejection: 401 | 403 | undefined + const providerAdmit = vi.fn(() => (rejection === undefined ? { peer: {} } : { rejection })) + // 0.2.3 host: the plugin's own context exposes `admit`, but cordis refuses the + // nested `connection.authentication` read unless the provider fiber declared it. + Reflect.deleteProperty(mounted.connection, 'requestRejection') + Object.assign(mounted.connection as unknown as Record, { + admit: () => { throw new Error('cannot get property "connection.authentication" without inject') }, + }) + mounted.activateProvider({ admit: providerAdmit }) + 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(providerAdmit).toHaveBeenCalledTimes(3) + } finally { + mounted.cleanup() + } + }) + it('does not bypass native refusals for former desktop, image, or port exceptions', async () => { const mounted = mount(403) try {