From b27ef7a7988e41e27ece81fcbae27a9852d17da4 Mon Sep 17 00:00:00 2001 From: kev1n77 Date: Thu, 29 Oct 2026 09:44:46 +0800 Subject: [PATCH] fix(web-ui): hide disabled external session views --- .../external-ai-work-sources-design.md | 4 +- .../capabilities.json | 14 ++--- .../feature.ecosystem-compatibility.md | 4 +- .../technical/product-control-open-audit.json | 2 +- .../technical/tauri-command-map.json | 2 +- .../generated/product-control-catalog.json | 14 ++--- .../interactive-capabilities/catalog.json | 8 +-- .../sections/sessions/SessionsSection.tsx | 22 +++++--- .../useWorkspaceSessionDiscovery.test.tsx | 24 ++++++++- .../sessions/useWorkspaceSessionDiscovery.ts | 52 +++++++++++++++++-- .../NavPanel/workspaceSessionView.test.ts | 13 +++++ .../NavPanel/workspaceSessionView.ts | 19 +++++++ .../generated/interactive-capabilities.json | 14 ++--- .../api/generated/productControl.ts | 2 +- .../en-US/scenes/ecosystem-compatibility.json | 2 +- .../zh-CN/scenes/ecosystem-compatibility.json | 2 +- .../zh-TW/scenes/ecosystem-compatibility.json | 2 +- 17 files changed, 154 insertions(+), 46 deletions(-) diff --git a/docs/architecture/extensions/external-ai-work-sources-design.md b/docs/architecture/extensions/external-ai-work-sources-design.md index 2080305519..bb8bead6c0 100644 --- a/docs/architecture/extensions/external-ai-work-sources-design.md +++ b/docs/architecture/extensions/external-ai-work-sources-design.md @@ -164,7 +164,7 @@ Zcode 会话读取不意味着其 ACP 运行时、设置、Skill、MCP 或 Hook 会话自动发现由 `app.external_session_discovery` 按来源选择,默认全部关闭。生态兼容页提供 各来源开关;工作区打开或启动后的原生会话列表首次读取时,由服务主机在后台扫描已开启来源。 会话列表入口从主机的集中式会话存储目录解析所属项目及关联工作树,重新打开工作区按主机记录的 -最近访问版本重新扫描;开关保存通知已挂载的会话列表重新读取,绕过保存前的短期缓存。 +最近访问版本重新扫描;开关保存通知已挂载的会话列表重新读取,绕过保存前的短期缓存,并立即隐藏已关闭来源的跟随条目;已分叉的本地副本继续显示。 工作区归属按来源目录匹配最近的已登记本地工作区。后台任务不依赖控制端在线;会话元数据分页 通过可选的 `discoveryPending` / `discoveryWarnings` 投影进度和非致命错误,已有原生会话始终可读。 服务主机合并同一批工作区打开请求的来源目录扫描,Codex 读取器按文件大小和修改时间复用已解析的 @@ -312,7 +312,7 @@ Peer 主机或取消操作会清空详情与确认状态,迟到的旧请求不 `get_external_source_discovery_snapshot` 返回版本化发现包装,声明是否允许修改、是否已有扫描和本次可扫描类别。既有严格策略与目录 DTO 不加字段,旧主机降级读取原目录、开关只读;无法识别的响应不能伪装成空目录。DiscoveryCatalog 使用独立的静态发现协调器和只读投影,扫描时仅在内存派生策略中跨过运行总开关,仍遵守各生态的禁用设置,绝不调用或撤销执行路由。开启后恢复查找,关闭后暂停该目录的新自动扫描,已有扫描可完成;手动刷新和导入预览可以显式读取。已有运行功能自身的刷新、执行校验仍由原 owner 负责。 -Skill/Hook 自动读取沿用各自 owner,并随页面开关暂停;MCP 导入计划的读取也遵守开关,暂停时延后到主动导入。关闭不删除目录或副本,不自动启用发现的内容。前端保留按执行主机与工作区隔离的有限内存结果,失败保留内容并停止把旧结果当作导入资格证明。主机不支持修改或策略版本不兼容时解释只读原因;保存失败直接反馈,保存使用主机偏好版本并阻止旧快照回退已确认状态。 +Skill/Hook 自动读取沿用各自 owner,并随页面开关暂停;MCP 导入计划的读取也遵守开关,暂停时延后到主动导入。关闭不删除目录或副本,不自动启用发现的内容;工作区导航立即隐藏该来源的跟随会话,已分叉的本地副本继续显示。前端保留按执行主机与工作区隔离的有限内存结果,失败保留内容并停止把旧结果当作导入资格证明。主机不支持修改或策略版本不兼容时解释只读原因;保存失败直接反馈,保存使用主机偏好版本并阻止旧快照回退已确认状态。 ACP 配置嵌入时也只展示所选产品的 clients,并隐藏包含全部产品内容的 JSON 视图。 - Skill 使用现有扫描报告按稳定 sourceId 归属筛选,展示该生态的诊断。目录包复制完整依赖,PI/DSH 支持的 Markdown 单文件转换为独立 SKILL.md 包;包内链接依赖明确拒绝。 diff --git a/docs/interactive-capabilities/capabilities.json b/docs/interactive-capabilities/capabilities.json index 834d748578..4c33f27459 100644 --- a/docs/interactive-capabilities/capabilities.json +++ b/docs/interactive-capabilities/capabilities.json @@ -4,7 +4,7 @@ "title": "OpenBitFun Playbook", "origin": "https://playbook.openbitfun.com", "source": "src/shared/interactive-capabilities/catalog.json", - "digest": "40fada109d5dbcfdbc1b289af574f7ac736da1620d4eee26128a40d3f0f5818c", + "digest": "9ec82305067852766c79ed3d802c3a16f1c4dd992f7d3195f91a2989da32f544", "ownerDigest": "f27c231da2e536e4f2123910f34f862b55d21feb0528bc915d4d13edbd528af9", "searchAcceptance": [ { @@ -24455,14 +24455,14 @@ ], "highlightsZh": [ "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源" ], "highlightsEn": [ "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views" @@ -24592,14 +24592,14 @@ ], "stepsZh": [ "打开“外部导入”并选择应用", - "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后保留结果,也可手动刷新", + "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "查看分类状态,打开分类弹窗浏览、搜索并选择内容", "审阅可导入项目并确认创建副本;Command、Tool、子智能体按已有兼容功能使用", "前往对应管理页确认副本启用或连接;当前页不将“已导入”视为可用" ], "stepsEn": [ "Open External Import and choose an app", - "Toggle automatic discovery above the sidebar search and hover for details; pausing retains results and manual refresh remains available", + "Toggle automatic discovery above the sidebar search and hover for details; disabling immediately hides source-following sessions while local forks remain visible", "Inspect category status, then open a category dialog to browse, search, and select content", "Review importable items and confirm copies; use commands, tools and subagents through existing compatibility features", "Confirm copy activation or connection in the relevant settings; Imported does not mean available" @@ -24643,12 +24643,12 @@ "Z.ai", "session import", "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源", "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views", diff --git a/docs/interactive-capabilities/capabilities/feature.ecosystem-compatibility.md b/docs/interactive-capabilities/capabilities/feature.ecosystem-compatibility.md index f7a0054ba1..7bb44638a7 100644 --- a/docs/interactive-capabilities/capabilities/feature.ecosystem-compatibility.md +++ b/docs/interactive-capabilities/capabilities/feature.ecosystem-compatibility.md @@ -44,8 +44,8 @@ Inspect external AI content and status, import supported Skills, MCP, Hooks, and 1. 打开“外部导入”并选择应用 Open External Import and choose an app -2. 在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后保留结果,也可手动刷新 - Toggle automatic discovery above the sidebar search and hover for details; pausing retains results and manual refresh remains available +2. 在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留 + Toggle automatic discovery above the sidebar search and hover for details; disabling immediately hides source-following sessions while local forks remain visible 3. 查看分类状态,打开分类弹窗浏览、搜索并选择内容 Inspect category status, then open a category dialog to browse, search, and select content 4. 审阅可导入项目并确认创建副本;Command、Tool、子智能体按已有兼容功能使用 diff --git a/docs/interactive-capabilities/technical/product-control-open-audit.json b/docs/interactive-capabilities/technical/product-control-open-audit.json index e9d16ef946..2247e29765 100644 --- a/docs/interactive-capabilities/technical/product-control-open-audit.json +++ b/docs/interactive-capabilities/technical/product-control-open-audit.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "generatedFrom": "src/shared/interactive-capabilities/catalog.json", - "catalogDigest": "40fada109d5dbcfdbc1b289af574f7ac736da1620d4eee26128a40d3f0f5818c", + "catalogDigest": "9ec82305067852766c79ed3d802c3a16f1c4dd992f7d3195f91a2989da32f544", "count": 213, "reasonCounts": { "externalAuth": 4, diff --git a/docs/interactive-capabilities/technical/tauri-command-map.json b/docs/interactive-capabilities/technical/tauri-command-map.json index bb7479f679..232541ab0d 100644 --- a/docs/interactive-capabilities/technical/tauri-command-map.json +++ b/docs/interactive-capabilities/technical/tauri-command-map.json @@ -1,7 +1,7 @@ { "schemaVersion": 2, "generatedFrom": "src/shared/interactive-capabilities/catalog.json", - "catalogDigest": "40fada109d5dbcfdbc1b289af574f7ac736da1620d4eee26128a40d3f0f5818c", + "catalogDigest": "9ec82305067852766c79ed3d802c3a16f1c4dd992f7d3195f91a2989da32f544", "commandCount": 706, "coverage": { "commandCount": 706, diff --git a/src/crates/contracts/product-domains/src/generated/product-control-catalog.json b/src/crates/contracts/product-domains/src/generated/product-control-catalog.json index e8c9c1c91b..a632771ff9 100644 --- a/src/crates/contracts/product-domains/src/generated/product-control-catalog.json +++ b/src/crates/contracts/product-domains/src/generated/product-control-catalog.json @@ -4,7 +4,7 @@ "title": "OpenBitFun Playbook", "origin": "https://playbook.openbitfun.com", "source": "src/shared/interactive-capabilities/catalog.json", - "digest": "40fada109d5dbcfdbc1b289af574f7ac736da1620d4eee26128a40d3f0f5818c", + "digest": "9ec82305067852766c79ed3d802c3a16f1c4dd992f7d3195f91a2989da32f544", "ownerDigest": "f27c231da2e536e4f2123910f34f862b55d21feb0528bc915d4d13edbd528af9", "searchAcceptance": [ { @@ -24496,14 +24496,14 @@ ], "highlightsZh": [ "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源" ], "highlightsEn": [ "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views" @@ -24633,14 +24633,14 @@ ], "stepsZh": [ "打开“外部导入”并选择应用", - "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后保留结果,也可手动刷新", + "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "查看分类状态,打开分类弹窗浏览、搜索并选择内容", "审阅可导入项目并确认创建副本;Command、Tool、子智能体按已有兼容功能使用", "前往对应管理页确认副本启用或连接;当前页不将“已导入”视为可用" ], "stepsEn": [ "Open External Import and choose an app", - "Toggle automatic discovery above the sidebar search and hover for details; pausing retains results and manual refresh remains available", + "Toggle automatic discovery above the sidebar search and hover for details; disabling immediately hides source-following sessions while local forks remain visible", "Inspect category status, then open a category dialog to browse, search, and select content", "Review importable items and confirm copies; use commands, tools and subagents through existing compatibility features", "Confirm copy activation or connection in the relevant settings; Imported does not mean available" @@ -24684,12 +24684,12 @@ "Z.ai", "session import", "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源", "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views", diff --git a/src/shared/interactive-capabilities/catalog.json b/src/shared/interactive-capabilities/catalog.json index 597065f760..af0b246aa4 100644 --- a/src/shared/interactive-capabilities/catalog.json +++ b/src/shared/interactive-capabilities/catalog.json @@ -3993,14 +3993,14 @@ ], "highlightsZh": [ "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源" ], "highlightsEn": [ "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views" @@ -4192,14 +4192,14 @@ ], "stepsZh": [ "打开“外部导入”并选择应用", - "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后保留结果,也可手动刷新", + "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "查看分类状态,打开分类弹窗浏览、搜索并选择内容", "审阅可导入项目并确认创建副本;Command、Tool、子智能体按已有兼容功能使用", "前往对应管理页确认副本启用或连接;当前页不将“已导入”视为可用" ], "stepsEn": [ "Open External Import and choose an app", - "Toggle automatic discovery above the sidebar search and hover for details; pausing retains results and manual refresh remains available", + "Toggle automatic discovery above the sidebar search and hover for details; disabling immediately hides source-following sessions while local forks remain visible", "Inspect category status, then open a category dialog to browse, search, and select content", "Review importable items and confirm copies; use commands, tools and subagents through existing compatibility features", "Confirm copy activation or connection in the relevant settings; Imported does not mean available" diff --git a/src/web-ui/src/app/components/NavPanel/sections/sessions/SessionsSection.tsx b/src/web-ui/src/app/components/NavPanel/sections/sessions/SessionsSection.tsx index 8793dd23a5..fc06e48588 100644 --- a/src/web-ui/src/app/components/NavPanel/sections/sessions/SessionsSection.tsx +++ b/src/web-ui/src/app/components/NavPanel/sections/sessions/SessionsSection.tsx @@ -47,6 +47,7 @@ import { DEFAULT_WORKSPACE_SESSION_FILTERS, hasWorkspaceSessionFilters, matchesWorkspaceSessionView, + matchesWorkspaceExternalDiscovery, matchesWorkspaceSourceAgent, sessionSourceAgentLabel, useWorkspaceSessionViewStore, @@ -300,6 +301,9 @@ const SessionsSection: React.FC = ({ onDiscoveryCompleted, ); const observeDiscovery = discovery.observe; + const matchesExternalDiscovery = useCallback((session: Session) => matchesWorkspaceExternalDiscovery( + session, discovery.enabledSources, + ), [discovery.enabledSources]); useEffect(() => { // The same host scan is observed by the active workspace row and, in some // layouts, by an aggregate or assistant-history row. Show one toast per @@ -371,11 +375,15 @@ const SessionsSection: React.FC = ({ void orderingRevision; return new Set([...flowChatState.sessions.keys()].filter(sessionNavStatusService.isRunning)); }, [flowChatState.sessions, orderingRevision]); + const discoveryEnabledSources = discovery.enabledSources; + const discoveryFilterActive = discoveryEnabledSources !== undefined + && Object.keys(EXTERNAL_SESSION_NAMES).some(source => !discoveryEnabledSources.has(source)); const catalogQueryJson = useMemo(() => { void orderingRevision; + if (discoveryFilterActive) return JSON.stringify(null); return JSON.stringify(workspaceSessionCatalogQuery(workspaceId, sessionOrdering, sessionShow, sessionFilters, sourceAgent, flowChatState.sessions.values(), sessionNavStatusService.getSortTimestamp) ?? null); - }, [workspaceId, sessionOrdering, sessionShow, sessionFilters, sourceAgent, flowChatState.sessions, orderingRevision]); + }, [discoveryFilterActive, workspaceId, sessionOrdering, sessionShow, sessionFilters, sourceAgent, flowChatState.sessions, orderingRevision]); const captureCatalogQuery = useCallback((query: SessionCatalogQuery) => captureWorkspaceSessionCatalogQuery( query, flowChatStore.getState().sessions.values(), sessionNavStatusService.getSortTimestamp, ), []); @@ -796,21 +804,23 @@ const SessionsSection: React.FC = ({ }, [flowChatState.sessions, orderingRevision, runningSessionIds, sessionOrdering, workspaceId, workspaceScopes]); const topLevelSessions = useMemo( - () => allTopLevelSessions.filter(session => matchesSourceAgent(session) && matchesWorkspaceSessionView( + () => allTopLevelSessions.filter(session => matchesExternalDiscovery(session) + && matchesSourceAgent(session) && matchesWorkspaceSessionView( session, sessionShow, sessionFilters, runningSessionIds.has(session.sessionId), )), - [allTopLevelSessions, matchesSourceAgent, runningSessionIds, sessionFilters, sessionShow], + [allTopLevelSessions, matchesExternalDiscovery, matchesSourceAgent, runningSessionIds, sessionFilters, sessionShow], ); const visibleChildrenByParent = useMemo(() => { - if (!hasActiveSessionFilter) return childrenByParent; + if (!hasActiveSessionFilter && discoveryEnabledSources === undefined) return childrenByParent; const filtered = new Map(); for (const [parentId, children] of childrenByParent) { - filtered.set(parentId, children.filter(session => matchesSourceAgent(session) && matchesWorkspaceSessionView( + filtered.set(parentId, children.filter(session => matchesExternalDiscovery(session) + && matchesSourceAgent(session) && matchesWorkspaceSessionView( session, sessionShow, sessionFilters, @@ -818,7 +828,7 @@ const SessionsSection: React.FC = ({ ))); } return filtered; - }, [childrenByParent, hasActiveSessionFilter, matchesSourceAgent, runningSessionIds, sessionFilters, sessionShow]); + }, [childrenByParent, discoveryEnabledSources, hasActiveSessionFilter, matchesExternalDiscovery, matchesSourceAgent, runningSessionIds, sessionFilters, sessionShow]); const sessionDisplayLimit = useMemo(() => { return getSessionDisplayLimit({ diff --git a/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.test.tsx b/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.test.tsx index 61dce3a031..ea61db5c7a 100644 --- a/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.test.tsx +++ b/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.test.tsx @@ -3,10 +3,18 @@ import React, { act } from 'react'; import { createRoot, type Root } from 'react-dom/client'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import type { SessionMetadataPage } from '@/infrastructure/api/service-api/SessionAPI'; -const mocks = vi.hoisted(() => ({ loadPage: vi.fn(), completed: vi.fn(), epoch: 0, host: 'local', configListeners: new Set<(path: string) => void>() })); +const mocks = vi.hoisted(() => ({ + loadPage: vi.fn(), + getOptionalConfig: vi.fn(), + completed: vi.fn(), + epoch: 0, + host: 'local', + configListeners: new Set<(path: string, oldValue?: unknown, newValue?: unknown) => void>(), +})); vi.mock('@/flow_chat/store/FlowChatStore', () => ({ flowChatStore: { loadSessionMetadataPage: mocks.loadPage } })); vi.mock('@/infrastructure/config/services/ConfigManager', () => ({ configManager: { - onConfigChange: (callback: (path: string) => void) => { + getOptionalConfig: mocks.getOptionalConfig, + onConfigChange: (callback: (path: string, oldValue?: unknown, newValue?: unknown) => void) => { mocks.configListeners.add(callback); return () => mocks.configListeners.delete(callback); }, @@ -38,6 +46,7 @@ describe('workspace discovery observation', () => { mocks.epoch = 0; mocks.host = 'local'; mocks.configListeners.clear(); + mocks.getOptionalConfig.mockResolvedValue({ codex: true, zcode: false }); mocks.loadPage.mockResolvedValue(page(false)); container = document.createElement('div'); root = createRoot(container); @@ -71,6 +80,17 @@ describe('workspace discovery observation', () => { expect(mocks.completed).toHaveBeenCalledTimes(1); }); + it('publishes source settings and applies a saved disable immediately', async () => { + await render(); + await act(async () => { await Promise.resolve(); }); + expect([...current.enabledSources ?? []]).toEqual(['codex']); + + await act(async () => { + mocks.configListeners.forEach(callback => callback('app.external_session_discovery.codex', true, false)); + }); + expect([...current.enabledSources ?? []]).toEqual([]); + }); + it('refreshes filtered totals even when a settings-triggered scan finishes before the first response', async () => { await render(); await act(async () => current.observe('workspace', page(false))); diff --git a/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.ts b/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.ts index e445f29377..a8df58ce6d 100644 --- a/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.ts +++ b/src/web-ui/src/app/components/NavPanel/sections/sessions/useWorkspaceSessionDiscovery.ts @@ -4,6 +4,7 @@ import { getActiveSurfaceId, getActiveSurfaceScope, surfaceScopedKey } from '@/i import { flowChatStore } from '@/flow_chat/store/FlowChatStore'; import { configManager } from '@/infrastructure/config/services/ConfigManager'; import { createLogger } from '@/shared/utils/logger'; +import { EXTERNAL_SESSION_NAMES, isExternalSessionEcosystem } from '@/shared/types/external-session'; const log = createLogger('WorkspaceSessionDiscovery'); interface DiscoveryState { @@ -12,6 +13,14 @@ interface DiscoveryState { diagnostics: SessionDiscoveryDiagnostic[]; } +const DISCOVERY_CONFIG_PATH = 'app.external_session_discovery'; + +function parseEnabledSources(value: unknown): ReadonlySet | undefined { + if (!value || typeof value !== 'object' || Array.isArray(value)) return undefined; + const settings = value as Record; + return new Set(Object.keys(EXTERNAL_SESSION_NAMES).filter(source => settings[source] === true)); +} + /** Watches only host-advertised in-progress work. Imports remain on the host * when this observer is hidden, unmounted, disconnected or switched to a peer. */ export function useWorkspaceSessionDiscovery( @@ -24,9 +33,28 @@ export function useWorkspaceSessionDiscovery( const [failed, setFailed] = useState(false); const [retryVersion, setRetryVersion] = useState(0); const [settingsVersion, setSettingsVersion] = useState(0); + const [enabledSources, setEnabledSources] = useState>(); + const enabledSourcesRef = useRef>(); + const settingsRequestRef = useRef(0); const scopeKey = JSON.stringify(workspaceIds); const scopedWorkspaceIds = useMemo(() => JSON.parse(scopeKey) as string[], [scopeKey]); const surfaceId = getActiveSurfaceId(); + const publishEnabledSources = useCallback((next: ReadonlySet | undefined) => { + enabledSourcesRef.current = next; + setEnabledSources(next); + }, []); + const loadEnabledSources = useCallback(() => { + const request = ++settingsRequestRef.current; + const scope = getActiveSurfaceScope(); + void configManager.getOptionalConfig>(DISCOVERY_CONFIG_PATH) + .then(settings => { + if (request !== settingsRequestRef.current || !scope.isCurrent()) return; + publishEnabledSources(parseEnabledSources(settings)); + }) + .catch(() => { + if (request === settingsRequestRef.current && scope.isCurrent()) publishEnabledSources(undefined); + }); + }, [publishEnabledSources]); const observe = useCallback((workspaceId: string, page: SessionMetadataPage, refresh = false) => { const key = surfaceScopedKey(surfaceId, workspaceId); const next = { @@ -60,11 +88,28 @@ export function useWorkspaceSessionDiscovery( )); }, [scopedWorkspaceIds, states, surfaceId]); - useEffect(() => configManager.onConfigChange(path => { - if (path === 'app' || path === 'app.external_session_discovery' || path.startsWith('app.external_session_discovery.')) { + useEffect(() => { + publishEnabledSources(undefined); + loadEnabledSources(); + return () => { settingsRequestRef.current += 1; }; + }, [loadEnabledSources, publishEnabledSources, surfaceId]); + + useEffect(() => configManager.onConfigChange((path, _oldValue, newValue) => { + if (path === 'app' || path === DISCOVERY_CONFIG_PATH || path.startsWith(`${DISCOVERY_CONFIG_PATH}.`)) { setSettingsVersion(version => version + 1); + const source = path.slice(`${DISCOVERY_CONFIG_PATH}.`.length); + const current = enabledSourcesRef.current; + if (isExternalSessionEcosystem(source) && typeof newValue === 'boolean' && current !== undefined) { + settingsRequestRef.current += 1; + const next = new Set(current); + if (newValue) next.add(source); + else next.delete(source); + publishEnabledSources(next); + } else { + loadEnabledSources(); + } } - }), []); + }), [loadEnabledSources, publishEnabledSources]); useEffect(() => { if (!settingsVersion || !visible || scopedWorkspaceIds.length === 0) return; @@ -115,6 +160,7 @@ export function useWorkspaceSessionDiscovery( pending: pendingKey !== '[]', warnings, diagnostics, + enabledSources, failed, retry: () => setRetryVersion(value => value + 1), }; diff --git a/src/web-ui/src/app/components/NavPanel/workspaceSessionView.test.ts b/src/web-ui/src/app/components/NavPanel/workspaceSessionView.test.ts index 9143e31a77..2dd59c3730 100644 --- a/src/web-ui/src/app/components/NavPanel/workspaceSessionView.test.ts +++ b/src/web-ui/src/app/components/NavPanel/workspaceSessionView.test.ts @@ -9,6 +9,7 @@ import { deriveWorkspaceSessionWorktree, getNextWorkspaceSessionGrouping, matchesWorkspaceSessionView, + matchesWorkspaceExternalDiscovery, matchesWorkspaceSourceAgent, normalizeWorkspaceSessionGrouping, } from './workspaceSessionView'; @@ -45,6 +46,18 @@ describe('workspace session view model', () => { expect(matchesWorkspaceSourceAgent(imported, source)).toBe(true); expect(matchesWorkspaceSourceAgent(imported, 'openbitfun')).toBe(false); }); + it('hides disabled source-following views while retaining native forks and unknown settings', () => { + const followed = session({ + importedSource: 'codex', + externalHistory: { mode: 'follow' }, + }); + const fork = session({ importedSource: 'codex' }); + const enabled = new Set(['zcode']); + + expect(matchesWorkspaceExternalDiscovery(followed, enabled)).toBe(false); + expect(matchesWorkspaceExternalDiscovery(fork, enabled)).toBe(true); + expect(matchesWorkspaceExternalDiscovery(followed, undefined)).toBe(true); + }); it('toggles between unified groups and the flat all-session view', () => { expect(getNextWorkspaceSessionGrouping('grouped')).toBe('all'); expect(getNextWorkspaceSessionGrouping('all')).toBe('grouped'); diff --git a/src/web-ui/src/app/components/NavPanel/workspaceSessionView.ts b/src/web-ui/src/app/components/NavPanel/workspaceSessionView.ts index 613e6f1927..1fb0828469 100644 --- a/src/web-ui/src/app/components/NavPanel/workspaceSessionView.ts +++ b/src/web-ui/src/app/components/NavPanel/workspaceSessionView.ts @@ -174,6 +174,25 @@ export function matchesWorkspaceSourceAgent(session: Session, source: WorkspaceS return source === 'all' || (session.importedSource || 'openbitfun') === source; } +/** + * Automatic discovery controls whether source-following views are shown in + * workspace navigation. A forked/local continuation has no `externalHistory` + * marker and remains a native OpenBitFun session even when its original + * source is disabled. + * + * `undefined` means the host setting has not been resolved yet. Keep the + * existing projection visible during that brief window so an old host or a + * transient config read failure does not hide user data. + */ +export function matchesWorkspaceExternalDiscovery( + session: Session, + enabledSources: ReadonlySet | undefined, +): boolean { + if (enabledSources === undefined || session.externalHistory?.mode !== 'follow') return true; + return typeof session.importedSource === 'string' + && enabledSources.has(session.importedSource); +} + export function sessionSourceAgentLabel(source: string): string { return source === 'openbitfun' ? 'OpenBitFun' : isExternalSessionEcosystem(source) ? EXTERNAL_SESSION_NAMES[source] : source; } diff --git a/src/web-ui/src/app/global-search/generated/interactive-capabilities.json b/src/web-ui/src/app/global-search/generated/interactive-capabilities.json index 834d748578..4c33f27459 100644 --- a/src/web-ui/src/app/global-search/generated/interactive-capabilities.json +++ b/src/web-ui/src/app/global-search/generated/interactive-capabilities.json @@ -4,7 +4,7 @@ "title": "OpenBitFun Playbook", "origin": "https://playbook.openbitfun.com", "source": "src/shared/interactive-capabilities/catalog.json", - "digest": "40fada109d5dbcfdbc1b289af574f7ac736da1620d4eee26128a40d3f0f5818c", + "digest": "9ec82305067852766c79ed3d802c3a16f1c4dd992f7d3195f91a2989da32f544", "ownerDigest": "f27c231da2e536e4f2123910f34f862b55d21feb0528bc915d4d13edbd528af9", "searchAcceptance": [ { @@ -24455,14 +24455,14 @@ ], "highlightsZh": [ "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源" ], "highlightsEn": [ "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views" @@ -24592,14 +24592,14 @@ ], "stepsZh": [ "打开“外部导入”并选择应用", - "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后保留结果,也可手动刷新", + "在左侧导航搜索框上方切换自动发现,悬停查看说明;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "查看分类状态,打开分类弹窗浏览、搜索并选择内容", "审阅可导入项目并确认创建副本;Command、Tool、子智能体按已有兼容功能使用", "前往对应管理页确认副本启用或连接;当前页不将“已导入”视为可用" ], "stepsEn": [ "Open External Import and choose an app", - "Toggle automatic discovery above the sidebar search and hover for details; pausing retains results and manual refresh remains available", + "Toggle automatic discovery above the sidebar search and hover for details; disabling immediately hides source-following sessions while local forks remain visible", "Inspect category status, then open a category dialog to browse, search, and select content", "Review importable items and confirm copies; use commands, tools and subagents through existing compatibility features", "Confirm copy activation or connection in the relevant settings; Imported does not mean available" @@ -24643,12 +24643,12 @@ "Z.ai", "session import", "按已识别与更多应用浏览;可发现表示支持查找,分类状态表示当前结果", - "自动发现只控制列表更新;关闭后保留结果,仍可手动刷新,已接入的功能照常运行", + "自动发现控制列表更新;关闭后立即隐藏对应来源的跟随会话,已分叉副本继续保留", "审阅并导入受支持的 Skill、MCP 与 Hook;Command、Tool、子智能体暂无副本导入", "已导入表示副本已保存;在对应管理页确认启用与连接", "Codex、Zcode 会话按工作区自动发现;打开来源时刷新历史,首次发送创建独立分支,可移除和重新添加来源", "Browse identified and more apps; discovery coverage and current category results are separate", - "Automatic discovery controls list updates; pausing retains results and allows manual refresh without changing active integrations", + "Automatic discovery controls list updates; disabling immediately hides source-following sessions while retaining local forks", "Review and import supported Skills, MCP and Hooks; command, tool and subagent copy import is unavailable", "Imported means a copy was saved; confirm activation and connection in the relevant settings", "Discover Codex and Zcode sessions by workspace, refresh history on open, continue in a new branch on first send, and remove or restore source views", diff --git a/src/web-ui/src/infrastructure/api/generated/productControl.ts b/src/web-ui/src/infrastructure/api/generated/productControl.ts index 097f98f03e..33d46c8957 100644 --- a/src/web-ui/src/infrastructure/api/generated/productControl.ts +++ b/src/web-ui/src/infrastructure/api/generated/productControl.ts @@ -1,5 +1,5 @@ // Generated by scripts/generate-interactive-capabilities.mjs; do not edit. -export const PRODUCT_CONTROL_GRAPH_DIGEST = "40fada109d5dbcfdbc1b289af574f7ac736da1620d4eee26128a40d3f0f5818c" as const; +export const PRODUCT_CONTROL_GRAPH_DIGEST = "9ec82305067852766c79ed3d802c3a16f1c4dd992f7d3195f91a2989da32f544" as const; export type ProductControlCapabilityId = "feature.ai-assistant" | "feature.agents" | "feature.personal-assistants" | "feature.projects" | "feature.files-editor" | "feature.terminal" | "feature.git" | "feature.code-review" | "feature.browser" | "feature.computer-use" | "feature.skills" | "feature.miniapps" | "feature.canvas" | "feature.tasks-automation" | "feature.insights" | "feature.ecosystem-compatibility" | "feature.remote-workspaces" | "feature.remote-connect" | "feature.detached-dispatch" | "feature.pages" | "feature.voice-input" | "feature.desktop-pet" | "feature.desktop-cards" | "setting.application.general" | "setting.application.appearance" | "setting.application.pet" | "setting.application.input" | "setting.application.shortcuts" | "setting.application.development" | "setting.ai.models" | "setting.ai.memory" | "setting.workspace.session" | "setting.workspace.worktrees" | "setting.tools.execution" | "setting.application.terminal" | "setting.tools.desktop-control" | "setting.tools.browser-control" | "setting.tools.automation" | "setting.tools.web-search" | "setting.tools.mcp" | "setting.tools.acp" | "setting.data.usage" | "setting.data.archived" | "setting.data.diagnostics"; diff --git a/src/web-ui/src/locales/en-US/scenes/ecosystem-compatibility.json b/src/web-ui/src/locales/en-US/scenes/ecosystem-compatibility.json index c3145a517f..6dcf77a1e6 100644 --- a/src/web-ui/src/locales/en-US/scenes/ecosystem-compatibility.json +++ b/src/web-ui/src/locales/en-US/scenes/ecosystem-compatibility.json @@ -84,7 +84,7 @@ }, "autoDiscovery": { "label": "Automatically discover {{name}} sessions", - "description": "When a workspace opens, list its {{name}} sessions using a lightweight index. The full history is saved locally the first time you open or continue a session. Unopened history requires the original source. Turning this off keeps existing entries and copies. SSH workspace discovery is not available.", + "description": "When a workspace opens, list its {{name}} sessions using a lightweight index. The full history is saved locally the first time you open or continue a session. Unopened history requires the original source. Turning this off immediately hides source-following entries; local forks remain visible. SSH workspace discovery is not available.", "unsupported": "This host does not support automatic session discovery. Update the serving host to enable it.", "loadFailed": "Could not load automatic session discovery settings.", "saveFailed": "Could not save the automatic session discovery setting." diff --git a/src/web-ui/src/locales/zh-CN/scenes/ecosystem-compatibility.json b/src/web-ui/src/locales/zh-CN/scenes/ecosystem-compatibility.json index bf5562f86e..9c7c6e6b14 100644 --- a/src/web-ui/src/locales/zh-CN/scenes/ecosystem-compatibility.json +++ b/src/web-ui/src/locales/zh-CN/scenes/ecosystem-compatibility.json @@ -84,7 +84,7 @@ }, "autoDiscovery": { "label": "自动发现 {{name}} 会话", - "description": "打开工作区时,只建立 {{name}} 会话的轻量索引并显示在列表中。首次打开或续聊时才保存完整历史;未打开的会话仍依赖原始来源。关闭开关保留已有条目和副本。暂不支持 SSH 工作区发现。", + "description": "打开工作区时,只建立 {{name}} 会话的轻量索引并显示在列表中。首次打开或续聊时才保存完整历史;未打开的会话仍依赖原始来源。关闭开关后立即隐藏该来源的跟随条目,已分叉的本地副本继续保留。暂不支持 SSH 工作区发现。", "unsupported": "当前主机不支持会话自动发现,请更新会话所在主机后启用。", "loadFailed": "无法加载会话自动发现设置。", "saveFailed": "无法保存会话自动发现设置。" diff --git a/src/web-ui/src/locales/zh-TW/scenes/ecosystem-compatibility.json b/src/web-ui/src/locales/zh-TW/scenes/ecosystem-compatibility.json index 968e508fff..9c01f81b24 100644 --- a/src/web-ui/src/locales/zh-TW/scenes/ecosystem-compatibility.json +++ b/src/web-ui/src/locales/zh-TW/scenes/ecosystem-compatibility.json @@ -84,7 +84,7 @@ }, "autoDiscovery": { "label": "自動探索 {{name}} 工作階段", - "description": "開啟工作區時,只建立 {{name}} 工作階段的輕量索引並顯示於清單。首次開啟或繼續對話時才儲存完整歷史;尚未開啟的工作階段仍依賴原始來源。關閉開關保留既有項目與副本。暫不支援 SSH 工作區探索。", + "description": "開啟工作區時,只建立 {{name}} 工作階段的輕量索引並顯示於清單。首次開啟或繼續對話時才儲存完整歷史;尚未開啟的工作階段仍依賴原始來源。關閉開關後立即隱藏該來源的跟隨項目,已分支的本機副本繼續保留。暫不支援 SSH 工作區探索。", "unsupported": "目前主機不支援工作階段自動探索,請更新工作階段所在主機後啟用。", "loadFailed": "無法載入工作階段自動探索設定。", "saveFailed": "無法儲存工作階段自動探索設定。"