Skip to content

feat(web-extensions): expose read-only active session context and composer-dock region - #1302

Merged
iruriQ merged 3 commits into
BytePioneer-AI:mainfrom
ABC-xiaoxuan:feat/web-extension-session-context
Nov 28, 2026
Merged

iruriQ merged 3 commits into
BytePioneer-AI:mainfrom
ABC-xiaoxuan:feat/web-extension-session-context

Conversation

@ABC-xiaoxuan

@ABC-xiaoxuan ABC-xiaoxuan commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds two minimal, general-purpose host primitives to WebExtensionApi so web host extensions (such as Git status indicators, project-aware widgets, or composer utilities) can observe the active main-view session and mount below the composer without scraping private DOM attributes or internal stores:

No visual changes: adds data-cx-region="composer-dock" mount anchor only.

  1. Read-only active session context (api.session)
    • packages/shared-contracts/src/web-native-extensions.ts: defines WebExtensionActiveSession (id, title, cwd, workspaceId, isBlank, isRemote, running) and adds session: { getActive(), onChange(listener) } to WebExtensionApi.
    • apps/web-ui/packages/client/ui-codexhost/src/client/native-extensions/api.ts: derives cloned read-only snapshots from the existing sessions.list (retainedBy.mainView), workspaces.list, and layout.panelInfo stores:
      • Returns null (and emits onChange(null) / re-emits on return) when a global main panel (layout.panelInfo.activePanelId !== null, e.g. Plugins) hides the conversation view and unmounts composer-dock.
      • Walks parent lineage to inherit the first non-empty ancestor cwd (preserving parent worktree / projectless cwd for subagents), falling back to owning workspace.path, and detects remote sessions.
      • Subscribes lazily only while listeners exist, deduplicates unchanged snapshots, isolates listener errors, and detaches cleanly on unsubscribe and reclaim().
  2. Stable composer-dock mount region
    • Adds "composer-dock" to WEB_EXTENSION_REGIONS and marks InputBar's dock element with data-cx-region="composer-dock".
    • Scopes api.dom.mount("composer-dock") to [data-cx-region="conversation"] when the app shell is present so extensions never accidentally mount into embedded sidebar composer docks.
  3. Docs & Tests
    • Documents api.session and composer-dock in docs/architecture/desktop-ui-extensions.md and .agents/skills/codexhost-add-desktop-extension/SKILL.md.
    • Adds unit tests in apps/web-ui/packages/client/ui-codexhost/test/web-native-extensions-api.test.ts and updates packages/shared-contracts/test/host-extensions.test.ts.

Verification

  • npx tsc -b --pretty false — passed
  • npm run build:web:ui — passed
  • npx vitest run --config tests/vitest.config.js packages/shared-contracts/test/host-extensions.test.ts apps/web-ui/packages/client/ui-codexhost/test/web-native-extensions-api.test.ts apps/web-ui/packages/client/ui-codexhost/test/shell-zoom.test.ts — 3 files / 60 tests passed
  • npx eslint packages/shared-contracts/src/web-native-extensions.ts packages/shared-contracts/test/host-extensions.test.ts — passed
  • node tools/check-boundaries.mjs — passed
  • npx prettier --check on all changed files — passed

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 新功能
    • Web 扩展可读取当前主会话的只读信息,并订阅会话变化。
    • 新增 composer dock 挂载区域,扩展可在主会话中挂载内容。
  • 文档
    • 补充 Web 扩展的挂载区域、会话上下文、资源、设置、面板及生命周期管理说明。

Web 扩展新增活动会话快照查询与变更订阅,并新增 composer-dock 挂载区域。运行时读取主视图保留的会话,监听存储变化,并依据主 conversation 选择挂载目标。

Changes: Web 扩展会话与挂载

Layer / File(s) Summary
扩展契约与挂载区域
packages/shared-contracts/src/web-native-extensions.ts、apps/web-ui/packages/client/ui-conversation/src/client/skeleton/InputBar.tsx、packages/shared-contracts/test/host-extensions.test.ts
共享契约新增只读活动会话类型、session.getActive()、session.onChange() 和 composer-dock 区域。InputBar 为 dock 容器添加区域标记;测试校验区域名称及顺序。
活动会话读取与订阅
apps/web-ui/packages/client/ui-codexhost/src/client/native-extensions/api.ts、apps/web-ui/packages/client/ui-codexhost/test/web-native-extensions-api.test.ts、.agents/skills/codexhost-add-desktop-extension/SKILL.md、docs/architecture/desktop-ui-extensions.md
运行时根据会话、工作区和布局存储生成活动会话快照,并在快照字段变化时通知订阅者。composer-dock 优先解析主 conversation 下的目标。测试覆盖快照、订阅、挂载和回收行为;文档补充相关 API 说明。

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Extension
  participant WebExtensionApi
  participant SessionStore
  participant WorkspaceStore
  Extension->>WebExtensionApi: 调用 getActive() 或注册 onChange()
  WebExtensionApi->>SessionStore: 读取主视图保留的会话
  WebExtensionApi->>WorkspaceStore: 读取工作区数据
  WebExtensionApi-->>Extension: 返回快照或 null
  SessionStore-->>WebExtensionApi: 通知会话存储变化
  WorkspaceStore-->>WebExtensionApi: 通知工作区存储变化
  WebExtensionApi-->>Extension: 快照变化时发送通知
Loading

Possibly related issues

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · previous review 61a7b

This adds a read-only active-session API and a composer-dock mount region for web extensions. The reported follow-up fixes (global panel handling and cwd inheritance) are covered by tests. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题描述了本次变更的主要内容:为 web 扩展新增只读的活动会话上下文(api.session)以及 composer-dock 挂载区域。标题与变更集中的 shared-contracts、ui-codexhost api.ts、InputBar.tsx 及文档一致。标题长度为 86 个字符,略长,但仍清晰具体。
Description check Passed 描述说明了两项新增原语:api.session 只读活动会话上下文,以及 composer-dock 挂载锚点。描述还列出了修改的文件(web-native-extensions.ts、api.ts、文档与测试)以及验证命令,与变更集直接相关。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@iruriQ iruriQ added the awaiting-author Waiting for the author to respond or update the PR. label Nov 27, 2026
@iruriQ

iruriQ commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

感谢贡献!我们已完成代码深审与独立隔离 Web 实测(真实安装并挂载测试扩展到 composer-dock,只读隔离、切换会话、禁用/卸载回收、侧栏防误挂与边界检查均通过),同时实测复现了一处影响 composer-dock 扩展生命周期的真实缺陷,请修正后再合入:

  1. 阻断 — 切换到全局主面板(如 Plugins)时 api.session.getActive() 未变为 null 且 onChange 不触发:
    • layout.selectPanel(panelId) 切换到 Plugins 等全局面板时不会清除 retainedBy.mainView,但 AppFrame.tsx 会直接卸载 ConversationMainPanel(销毁 composer-dock)。
    • 实测切到 Plugins 时 api.dom.mount("composer-dock") 返回 undefined,但 api.session.getActive() 仍返回隐藏的会话;随后再切回同一会话,React 重建了 composer-dock,但 api.session.onChange 不会触发,导致依赖 onChange 挂载状态条的扩展丢失挂载。
    • 修复建议:在 api.ts 的 readActiveSessionSnapshot 与 ensureSessionWatchers 中一并读取并订阅 ctx.get("layout")?.panelInfo,当 activePanelId !== null 时将激活会话视为 null(并把 api.ts:289 注释从 (e.g. Settings/Plugins) 改为 (e.g. Plugins or other global main panels),因 Web 设置页为模态框不卸载对话)。
  2. 建议 — 子会话继承父会话 worktree cwd:
    • 子会话行通常不填 cwd,在祖先链 while 循环中顺手记录首个非空 list.byId[cursor]?.cwd,返回 inheritedCwd ?? nonEmptyString(workspace?.path),避免父会话在 worktree 或无项目目录时退回主仓或 null。
  3. 补充:请在 PR 描述中加上 No visual changes: adds data-cx-region="composer-dock" mount anchor only(或附带测试扩展渲染截图)。

@ABC-xiaoxuan

Copy link
Copy Markdown
Contributor Author

感谢深入审查与隔离 Web 实测!已按 3 点反馈全部修正并推送更新:

  1. 订阅 layout.panelInfo 感知全局主面板切换:
    • readActiveSessionSnapshot 与 ensureSessionWatchers 现同时读取并订阅 ctx.get("layout")?.panelInfo。当 activePanelId !== null(如切到 Plugins 等全局主面板)时,api.session.getActive() 返回 null 并触发 onChange(null);切回会话(activePanelId === null)时自动重新派发激活会话快照,并在全部取消订阅或 reclaim() 时解绑 panelInfo。
    • 同步修正了 api.ts 注释为 (e.g. Plugins or other global main panels)。
  2. 子会话沿祖先链继承父会话 cwd:
    • 在祖先链 while 循环中记录首个非空 list.byId[cursor]?.cwd,最终返回 inheritedCwd ?? nonEmptyString(workspace?.path)(保留父会话 worktree / 无项目目录 cwd),并顺手消除了循环内的非空断言。
  3. 单测与 PR 描述:
    • 在 web-native-extensions-api.test.ts 中补充了 layout.panelInfo 切换(null → codexhost-plugins → null)的快照/订阅/回收测试,以及子会话继承父 worktree cwd 与无项目父 cwd 的测试用例。
    • 已在 PR 正文补充 No visual changes: adds data-cx-region="composer-dock" mount anchor only。

本地已重新验证:npx tsc -b --pretty false、npm run build:web:ui、相关 Vitest(3 files / 60 tests)、eslint、node tools/check-boundaries.mjs、prettier --check 全部通过,请复审!

@iruriQ
iruriQ merged commit 2aad43d into BytePioneer-AI:main Nov 28, 2026
@iruriQ

iruriQ commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

感谢按隔离实测反馈快速修完 layout.panelInfo 等全部 3 项,已解掉 web-native-extensions.ts 与 #1332 的单行冲突并合并到 main!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Waiting for the author to respond or update the PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants