Skip to content
Merged
29 changes: 29 additions & 0 deletions docs/design/web-shell/web-shell-browser-notification-details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Browser notification details and session navigation

[English](web-shell-browser-notification-details.md) | [简体中文](web-shell-browser-notification-details.zh-CN.md)

Following the base implementation in #11398, this enhancement lets users identify the session behind a notification, preview this turn's reply, and click to return to that session. The browser switch, permissions, background trigger, and deduplication rules remain those of the base implementation. No daemon route or public SDK field is added.
Comment thread
doudouOUC marked this conversation as resolved.
Resolved

## Content and icon

The title is QwenCode · session title. If a new session has no title yet or its title has been cleared, use the first line of this turn's request; if neither exists, display QwenCode. The body retains the turn status and includes a plain-text excerpt from the last main-assistant reply for a completed turn, without another model call to summarize it. Extraction matches the terminal promptId exactly and excludes tools, thoughts, background agents, and internal insight messages. Missing text does not fall back to an older turn, and failures do not expose partial replies or error details.

Extraction runs after the live/replay transcript projection. Titles use the owning session's state and owner-matched connection metadata. The main chat suppresses the submitting user's SSE echo, and the local optimistic user block may lack a promptId. The observer therefore retains a title fallback through the existing admission promptId/label; live pending-start events can also supply it. Labels remain only in the pending-turn memory Map and are removed on consumption, removal, or release of the last observer.

Titles retain at most 60 Unicode code points and reply excerpts at most 120, ending in an ellipsis when truncated. Excerpts remove common Markdown formatting, link destinations, and HTML tags, collapse whitespace, and avoid splitting Unicode code points.

Notifications include a package-local copy of the project's existing 128×128 PNG mark, with Vite resolving and bundling its URL. Business text does not append IP addresses, ports, or navigation URLs. Chrome's site attribution and its own macOS logo are controlled by the browser and OS and cannot be replaced by the business icon. Content may appear in the notification center or on the lock screen; the setting description explains that titles and reply excerpts are shown. Shared storage continues to record only deduplication hashes, never bodies, titles, or navigation targets.

## Clicking to open a session

The internal owner binding captures sessionId and product context: workspace uses the resolved owner.workspaceCwd, while standalone/live omit internal working directories. The target remains in the notification's in-memory closure. Clicking attempts to focus the original window, passes the explicit target to the existing qwen:open-session entry point, and closes the notification. Navigation is still attempted if the browser refuses focus.

App reuses the existing session-loading flow for settings, split view, draft context, asynchronous navigation, and failure reporting. Existing session links without explicit context keep their behavior. Malformed or conflicting explicit contexts are rejected instead of falling back to the current or primary workspace. If the target is already the healthy current session, its context matches, and there is no pending draft intent, only reveal chat and close panels to avoid disrupting the next turn with a duplicate load. Split-view notifications open the main chat, and the existing callback updates the address bar after a successful load.

The original page and main App navigation listener must still be alive. Expired sessions, removed workspaces, and load failures use existing error feedback without creating a session or switching to another workspace. Closed-page delivery, Channel, Service Worker, and Web Push are outside this enhancement.

## Validation scope

Unit tests cover live/replay content projection, admission title fallback, exact-turn and main-assistant filtering, Unicode truncation, failure and empty-content fallbacks, icon parameters, captured targets, cross-workspace and standalone/live navigation, exiting settings and split view, avoiding duplicate current-session loads, legacy links, and focus failure.

Page verification uses an isolated runtime and Chrome: capture the notification produced after a real submission settles, switch to another session and open settings, then invoke the captured notification's click callback. Check that the original session and URL return, settings exits, and the notification closes. A Notification stub and simulated loss of focus demonstrate browser parameters and navigation, not actual OS banner or icon display. The icon is separately checked for production HTTP availability, PNG signature, and dimensions. Detailed test plans and results are kept locally under .qwen/e2e-tests/.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 浏览器通知内容与会话导航

[English](web-shell-browser-notification-details.md) | [简体中文](web-shell-browser-notification-details.zh-CN.md)

基础版合入 #11398 后,本次增强让用户直接辨认通知对应的会话、查看本轮回复摘录,并点击返回对应会话。浏览器开关、权限、后台触发和去重规则沿用基础版,不增加 daemon 路由或公共 SDK 字段。

## 内容与图标

标题显示 QwenCode · 会话标题。新会话标题尚未生成或已清空时,使用本轮问题首行;两者均缺失时显示 QwenCode。正文保留回合状态,完成时附本轮最后一段主助手回复的纯文本摘录,不额外调用模型生成摘要。摘录严格匹配终态 promptId,排除工具、思考、后台子代理和内部 insight 消息;无匹配文本时不借用旧轮回复,失败时不展示部分回复或错误详情。

提取发生在 live/replay transcript 投影完成后。标题使用所属 session 的状态及 owner 匹配的 connection 元数据。主聊天会抑制本人 user SSE 回显,本地 optimistic user block 不一定带 promptId,因此观察器通过已有 admission 的 promptId/label 保存标题兜底,live pending 启动事件也可提供该文本。标签仅保留在未结束回合的内存 Map,消费、移除或最后观察者退出时清理。

标题最多保留 60 个 Unicode 码点,回复摘录最多 120 个,超长时以省略号结尾。摘录移除常见 Markdown 格式、链接地址和 HTML 标记并合并空白,截断不拆开 Unicode 码点。

通知携带项目现有 128×128 PNG 标志的本包副本,由 Vite 解析和打包图片 URL。标题与正文不额外拼接 IP、端口或跳转地址;Chrome 自带的站点来源和 macOS 上的 Chrome 标志由浏览器及系统控制,业务图标不能替换它们。通知内容可能显示在通知中心或锁屏上,设置说明告知会展示标题与回复摘录。共享存储仍仅记录去重哈希,不保存正文、标题或导航目标。

## 点击打开会话

内部 owner 绑定时捕获 sessionId 和产品上下文:workspace 使用已解析 owner.workspaceCwd,standalone/live 不携带内部工作目录。目标仅保留在通知的内存闭包。点击时尝试聚焦原窗口,将显式目标传给已有 qwen:open-session 入口,再关闭通知;浏览器拒绝聚焦时仍尝试导航。

App 复用现有会话加载流程处理设置页、分屏、草稿上下文、异步导航与失败报告。没有显式上下文的旧会话链接保持原行为;畸形或冲突的显式上下文直接拒绝,不回落到当前或主工作区。目标已经是当前健康会话、上下文一致且没有待分配草稿意图时,只显示聊天并关闭面板,避免重复加载干扰下一轮。分屏通知统一打开主聊天,加载成功后既有回调同步更新地址栏。

范围限于原页面仍打开且主 App 导航监听仍挂载的情形。过期会话、已移除工作区和加载失败复用既有错误反馈,不自动创建会话或切换到另一工作区。关闭页面后的通知、Channel、Service Worker 与 Web Push 不属于本次增强。

## 验证范围

单元测试覆盖 live/replay 内容投影、admission 标题兜底、精确回合及主助手过滤、Unicode 截断、失败与空内容兜底、图标参数、捕获目标、跨工作区及 standalone/live 导航、设置页与分屏退出、同会话避免重复加载、旧链接兼容和聚焦失败。

页面验证使用独立 runtime 与 Chrome:真实提交产生终态后捕获通知,切换到另一会话并打开设置,再调用捕获通知的点击回调,检查原会话及 URL 恢复、设置退出与通知关闭。Notification stub 和模拟失焦只证明浏览器参数与导航链路,不代表 OS 横幅或图标实际展示。图标另外核对生产资源的 HTTP 状态、PNG 签名和尺寸。详细测试计划及结果记录在本地 .qwen/e2e-tests/。
5 changes: 3 additions & 2 deletions packages/web-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ Tailwind 或额外引入全局 CSS。
不写入 daemon 或 workspace 设置,同源标签页之间同步。

页面在后台或窗口失焦时,当前聊天及 Split View 中仍挂载的聊天在回合结束或失败后
可以发送系统通知。取消回合、初次加载历史和前台已处理的回合保持静默。通知只显示
通用状态,不含聊天正文、错误详情或工作目录;点击通知尝试聚焦原窗口。
可以发送系统通知。取消回合、初次加载历史和前台已处理的回合保持静默。通知显示会话标题(最多 60 字)、回合状态和本轮回复的纯文本摘录(最多 120 字)。
标题显示 QwenCode · 会话名,尚未生成时使用本轮问题首行,两者均缺失时显示 QwenCode;业务文案不额外添加地址。通知携带 Qwen Code 图标,实际显示位置由浏览器和操作系统决定,不能替换 macOS 上 Chrome 自身的标志。摘要直接截取回复,不额外调用模型;无正文时只显示状态,失败时不展示错误详情或部分回复。
通知内容可能显示在系统通知中心或锁屏上,遵循系统的预览设置;点击通知尝试聚焦原窗口并在主聊天中打开对应会话,退出设置页或分屏;已在目标会话时不会重新加载。

需要支持 Notifications API 的桌面浏览器以及 HTTPS 或可信的 localhost 环境。
支持 Web Locks 且存储可用时,同源标签页协调去重;否则退化为页面内去重及相同 tag
Expand Down
134 changes: 134 additions & 0 deletions packages/web-shell/client/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19432,6 +19432,106 @@ describe('App session callbacks', () => {
expect(editorFocus).toHaveBeenCalledOnce();
});

it.each([
{ kind: 'workspace' as const, cwd: '/notification/workspace' },
{ kind: 'standalone' as const },
{ kind: 'live' as const },
])(
'opens a notification using its captured $kind context',
async (sessionContext) => {
mockConnection.sessionContext = { kind: 'workspace', cwd: '/workspace' };
const { container } = renderApp();
await flush();
await act(async () => {
container
.querySelector<HTMLButtonElement>(
'[data-testid="open-sidebar-settings"]',
)
?.click();
});
expect(
container.querySelector('[data-testid="settings-message"]'),
).not.toBeNull();
await act(async () => {
window.dispatchEvent(
new CustomEvent('qwen:open-session', {
detail: { sessionId: 'session-1', sessionContext },
}),
);
await Promise.resolve();
});
expect(mockSessionActions.loadSession).toHaveBeenCalledExactlyOnceWith(
'session-1',
{
workspaceCwd:
sessionContext.kind === 'workspace'
? sessionContext.cwd
: undefined,
sessionContext,
},
);
expect(
container.querySelector('[data-testid="settings-message"]'),
).toBeNull();
},
);

it('reveals the current notification target without reloading an active session', async () => {
mockConnection.sessionContext = { kind: 'workspace', cwd: '/workspace' };
mockConnection.workspaceCwd = '/workspace';
mockConnection.status = 'connected';
const { container } = renderApp();
await flush();
await act(async () => {
container
.querySelector<HTMLButtonElement>(
'[data-testid="open-sidebar-settings"]',
)
?.click();
});
expect(
container.querySelector('[data-testid="settings-message"]'),
).not.toBeNull();
await act(async () => {
window.dispatchEvent(
new CustomEvent('qwen:open-session', {
detail: {
sessionId: 'session-1',
sessionContext: { kind: 'workspace', cwd: '/workspace' },
},
}),
);
});
expect(mockSessionActions.loadSession).not.toHaveBeenCalled();
expect(
container.querySelector('[data-testid="settings-message"]'),
).toBeNull();
});

it.each([
{ sessionContext: { kind: 'unknown' } },
{ sessionContext: { kind: 'workspace', cwd: ' ' } },
{
sessionContext: { kind: 'workspace', cwd: '/target' },
workspaceCwd: '/other',
},
{ sessionContext: { kind: 'standalone' }, workspaceCwd: '/other' },
])(
'rejects invalid or conflicting notification contexts: %j',
async (detail) => {
renderApp();
await flush();
await act(async () => {
window.dispatchEvent(
new CustomEvent('qwen:open-session', {
detail: { sessionId: 'notification-session', ...detail },
}),
);
});
expect(mockSessionActions.loadSession).not.toHaveBeenCalled();
},
);

it('opens a Live session through its explicit product context', async () => {
mockWorkspace.capabilities = {
features: ['multi_workspace_sessions'],
Expand Down Expand Up @@ -29259,6 +29359,40 @@ describe('App session callbacks', () => {
}
});

it('opens a notification target in the main chat from split view', async () => {
window.history.pushState({}, '', '/?split=s1,s2');
try {
const { container } = renderApp();
await flush();
expect(
container.querySelector('[data-testid="split-view-page"]'),
).not.toBeNull();
await act(async () => {
window.dispatchEvent(
new CustomEvent('qwen:open-session', {
detail: {
sessionId: 's2',
sessionContext: { kind: 'workspace', cwd: '/target' },
},
}),
);
await Promise.resolve();
});
expect(
container.querySelector('[data-testid="split-view-page"]'),
).toBeNull();
expect(mockSessionActions.loadSession).toHaveBeenCalledExactlyOnceWith(
's2',
{
workspaceCwd: '/target',
sessionContext: { kind: 'workspace', cwd: '/target' },
},
);
} finally {
window.history.pushState({}, '', '/');
}
});

it('does not restore over a consumed split deep link after capabilities refresh', async () => {
window.history.pushState({}, '', '/?split=s1,s2');
try {
Expand Down
77 changes: 65 additions & 12 deletions packages/web-shell/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12994,34 +12994,61 @@ export function App({
// to that session. loadSidebarSession already closes the panel, so this just
// returns to the chat view and reports load failures.
const handleOpenSessionFromOverview = useCallback(
(sessionId: string, workspaceCwd?: string) => {
(
sessionId: string,
workspaceCwd?: string,
explicitContext?: DaemonProductSessionContext,
) => {
splitClassificationGenerationRef.current += 1;
// Explicit navigation cancels any pending shrink-fold split restore.
splitFoldedByShrinkRef.current = false;
showChat();
const current = connectionRef.current;
Comment thread
doudouOUC marked this conversation as resolved.
Resolved
if (
explicitContext &&
!pendingSessionContextRef.current &&
Comment thread
doudouOUC marked this conversation as resolved.
Resolved
current.status === 'connected' &&
!current.loadingTranscript &&
!current.missingSession &&
!current.standaloneSession?.creationRecovery &&
current.sessionId === sessionId &&
Comment thread
doudouOUC marked this conversation as resolved.
Resolved
current.sessionContext?.kind === explicitContext.kind &&
(explicitContext.kind !== 'workspace' ||
current.workspaceCwd === explicitContext.cwd)
) {
closePanel();
closeMobileDrawer();
return;
Comment thread
doudouOUC marked this conversation as resolved.
Resolved
}
const currentContext =
pendingSessionContextRef.current ??
connectionRef.current.sessionContext;
const inheritedContext =
workspaceCwd === undefined && currentContext?.kind !== 'workspace'
? currentContext
: undefined;
void loadSidebarSession(sessionId, workspaceCwd, inheritedContext).catch(
(error: unknown) => {
reportError(error, 'Failed to open session');
},
);
void loadSidebarSession(
sessionId,
workspaceCwd,
explicitContext ?? inheritedContext,
).catch((error: unknown) => {
reportError(error, 'Failed to open session');
});
},
[loadSidebarSession, reportError, showChat],
[closeMobileDrawer, closePanel, loadSidebarSession, reportError, showChat],
);

// Listen for `qwen:open-session` events dispatched by the markdown renderer
// when a `qwen-session://<id>` link is clicked. Navigate to the session.
// Markdown links and browser notifications share the session navigation path.
useEffect(() => {
const handler = (e: Event) => {
const detail = (
e as CustomEvent<
string | { sessionId?: unknown; workspaceCwd?: unknown }
| string
| {
sessionId?: unknown;
workspaceCwd?: unknown;
sessionContext?: unknown;
}
>
).detail;
const sessionId = typeof detail === 'string' ? detail : detail?.sessionId;
Expand All @@ -13031,8 +13058,34 @@ export function App({
typeof detail.workspaceCwd === 'string'
? detail.workspaceCwd
: undefined;
if (typeof sessionId === 'string' && sessionId) {
handleOpenSessionFromOverview(sessionId, workspaceCwd);
let sessionContext: DaemonProductSessionContext | undefined;
if (
typeof detail === 'object' &&
detail !== null &&
'sessionContext' in detail
) {
const context = detail.sessionContext;
if (
typeof context !== 'object' ||
context === null ||
!('kind' in context)
)
return;
if (context.kind === 'standalone' || context.kind === 'live') {
if (workspaceCwd) return;
sessionContext = { kind: context.kind };
} else if (
context.kind === 'workspace' &&
'cwd' in context &&
typeof context.cwd === 'string' &&
context.cwd.trim()
) {
if (workspaceCwd && workspaceCwd !== context.cwd) return;
sessionContext = { kind: 'workspace', cwd: context.cwd };
} else return;
}
if (typeof sessionId === 'string' && sessionId.trim()) {
handleOpenSessionFromOverview(sessionId, workspaceCwd, sessionContext);
}
};
window.addEventListener('qwen:open-session', handler);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading