Skip to content

feat: 会话未读状态与系统通知 - #1645

Merged
chen-ran merged 25 commits into
mainfrom
feat/memoh-146-session-unread-notifications
Nov 1, 2026
Merged

chen-ran merged 25 commits into
mainfrom
feat/memoh-146-session-unread-notifications

Conversation

@LittleSound

@LittleSound LittleSound commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

Agent 跑完长任务、运行失败或者等待工具审批时,如果用户当时不在看这个会话,现在什么提示都没有。没接 IM 渠道的网页端和桌面端用户,根本不知道 bot 已经做完了。

这个 PR 给“用户自己在网页 / 桌面端发起的会话”加上未读状态和系统通知,并且用户可以手动把会话标为已读或未读。

后端

  • 新增 migration 0171_session_attention:bot_sessions 增加 attention_at / attention_kind;新表 session_reads 按用户记录 read_at(已读游标)和 marked_unread_at(手动标未读的时间),两个时间都只会向前推进,以较晚的那个为准。0001_init 快照同步更新。
  • 写入时机:运行进入终态时,completed 记为 reply,failed / lost 记为 failed;进入 waiting_decision 时记为 needs_input。用户主动中止(aborted)和重复上报的终态都不写。写入不会改动 updated_at。
  • 只对用户本人创建的 chat / acp_agent、本地渠道、可见的会话生效。IM、定时任务、subagent 和内部会话都不受影响。
  • 接口:
    • GET /users/me/unread:跨 bot 的未读汇总。
    • PUT /users/me/read-state:批量设置已读或未读,请求体是 {items: [{session_id, unread, through?}]}。已读和未读是同一个状态的两面;标已读时 through 必填,缺少时返回 request.field_required(field: through);只读到这个时间为止,避免把之后新到的提醒一并读掉。
    • 用户级 SSE GET /users/me/attention/events:事件有 session_attention、session_unread(手动标未读,不弹通知)、session_read,每一帧都重新检查 bot 访问权限。
    • 会话列表接口也带上 unread / attention_kind / attention_at。
  • 事件和接口都不包含消息正文。

网页端

  • 跨 bot 的未读 store:首屏拉一次汇总,之后通过 SSE 增量更新。处理了几种竞态:汇总请求还没返回时 SSE 已经推来新事件、已读后又被旧数据加回来、同一事件重复推送。
  • “正在看”的判定:面板处于激活状态、页面可见、窗口有焦点、消息已加载,而且这个面板没有被 KeepAlive 缓存起来。满足时自动标为已读。手动标的未读不会因为“正在看”被马上读掉,要重新打开这个会话才会读掉。
  • 侧栏顶部的「需要你」卡片:
    • 跨 bot 列出未读会话,最多显示 5 条,多出的可以展开。点一条会切到对应的 bot 并打开会话。
    • 点标题可以折叠,和“文件夹”“最近”的区头交互一致,折叠状态按设备记住。
    • 标题右侧的 × 会把全部标为已读,先弹小气泡二次确认,完成后的提示里带“撤销”,撤销会把这批会话恢复成未读。
    • 动画:新提醒到达时,这一行高度展开并下落淡入,按种类颜色高亮一次;只有实时到达的提醒才播放,展开列表、刷新页面、切换 bot 时都不会重播。展开“显示全部”和收起的速度一致。开启“减少动态效果”时关闭所有动画。
  • 会话的右键菜单和三点菜单新增“标记为未读 / 标记为已读”。只有能产生未读的会话才显示这一项,判断规则和服务端一致。
  • 会话多选栏(“已选择 N 个会话 · 删除 · 取消”)移到「需要你」卡片下方,作为“文件夹 + 最近”这一组的标题行,并在组内吸顶。卡片没有多选,原来的位置会让人以为卡片也在选择范围内。
  • 会话行上显示未读点,未读标题加粗;bot 切换器上提示其他 bot 有未读;浏览器标签页标题前加 (n)。
  • 颜色按轻重分级:运行失败用红,等待你确认用黄,普通回复和手动标的未读用主题色(--brand,跟着配色方案变)。每一行的点、到达时的底色闪动都按这一行的种类上色;「需要你」卡片的计数、bot 切换器头像上的点、切换器菜单里每个 bot 的计数,都取其中最急的那种颜色(红 > 黄 > 主题色)。卡片计数也把折叠起来没显示的行算进去,所以第 6 条是失败时,计数同样会变红。计数用的是 BadgeCount 新增的 warning / brand 色调,来自配套的 feat: BadgeCount 增加 warning 与 brand 色调 ui#41。
  • 统一的 AttentionDot 组件:新提醒到达时弹一下、外圈扩散一次光晕。
  • 浏览器通知:在「设置 → 外观」里新增“系统通知”开关,网页端默认关闭,打开开关时请求浏览器权限。多个标签页之间会互相询问是否有人正在看这个会话,同一条提醒只弹一次。

桌面端

  • 主进程负责发原生通知,按 sessionId + attentionAt 去重,会校验 IPC 参数;点击通知时打开窗口并跳到对应会话。
  • 用 app.setBadgeCount 在 Dock 上显示未读总数。桌面端默认开启通知。

Related Issues

  • Linear: MEMOH-146
  • 相关:MEMOH-193(切换 bot 会中止当前 bot 正在运行的任务,这是 main 上已有的问题,单独修复,不在本 PR 范围内)
  • 配套 UI PR:felinics/ui#41 已合并;packages/ui 现指向正式仓库的合并提交 2a40d38f36818b27b2400a3a81aa64e5765dbb62,包含 BadgeCount 的 warning / brand 色调及 UI fix: correct store import path case #42 的 ErrorIcon 依赖修复。
  • 已合入 Memoh main 94f715054b41ce5f0736219b0b94f44c7aa029a9,保留主线外部 runtime Registry / Session Manager 接口和路由异步防竞态检查。迁移编号调整为尚未占用的 0171;主线已发布的 0170_history_checkpoints 未修改。

仍保留的行为与验证边界

  • 刷新页面继续算“重新打开”,会读掉当前会话手动标记的未读;本轮未改变此行为。
  • 点“新会话”后最近列表运行转圈滞留的问题,本轮仍可观察到;这是原 PR 已记录的独立问题。后台提醒卡片能收到完成事件,重新打开会话后转圈消失。
  • macOS 系统通知横幅及 Windows/Linux 平台行为的未验证项见下文,本轮未补做这些平台验证。

Validation

2026-11-02 合入 main / UI #41 后的验证(42f3bcd30)

  • 独立 worktree:codex/pr1645-continue。通过项目 scripts/dev-compose.sh 启动隔离的 memoh-pr1645-qa 开发栈,Web http://127.0.0.1:30082,Server 30080。确认源码挂载指向本轮 worktree,Server / Channel / PostgreSQL / pgvector / Connect-It 健康,数据库版本 171、dirty=false。
  • mise run sqlc-generate、mise run sdk-generate、Web typecheck 通过。
  • 提交钩子通过(本机用 MISE_SHELLCHECK_VERSION=0.11.0 明确选定已安装的 shellcheck,未跳过钩子)。
  • mise run lint 通过:UI contract、ESLint、Go lint 均无错误;保留现有告警。
  • Go 测试通过:./internal/chat/... ./internal/handlers/... ./internal/agent/application/... ./internal/agent/runtime/session/... ./cmd/...。
  • Vitest 20 个文件、247 项测试通过:unread store、viewing、notifications、sidebar、session-attention、chat-list、desktop attention-notifications。
  • 独立 PostgreSQL 测试库:attention integration 测试通过;0171 down/up/up 后重跑通过;完整迁移链 down/up 后回到 171、dirty=false。
  • Agent 实际页面验证:森林配色的浅/深色 Bot 菜单同时显示失败红色、等待黄色、回复主题色;跨 Bot 打开提醒会读掉对应项;当前会话手动标未读后不会立即被自动读掉;卡片折叠/展开、全部已读二次确认、撤销恢复 3 条均通过。390px 中文窄屏下卡片可读,点击跨 Bot 提醒后导航抽屉关闭、目标会话打开且未读数减少。
  • 受控模型的实际 Agent 回合:在 Web 发送消息后点“新会话”,后台运行 completed 且持久化 attention_kind=reply,SSE 驱动未读数 3 → 4;点击提醒打开回复正文,未读数 4 → 3。颜色样本通过隔离测试库准备,不代表真实失败/审批触发已在本轮重测。此次未调用真实模型服务,也未验证操作系统通知横幅。
  • 用户于 2026-11-02 明确确认“我已复核本轮页面,允许提交并推送”。本轮人工复核范围是 Web 页面;历史桌面端及操作系统层面的验证限制仍保留。

以下为此前提交的验证记录,环境与提交不同:

自动检查(基于 origin/main bbedfb5f5)

  • Go:go test 跑了 ./internal/chat/...、./internal/handlers/、./internal/agent/application/、./internal/agent/runtime/session/、./cmd/...,全部通过。
  • 集成测试:go test -tags=integration ./internal/chat/attention/ 通过,覆盖资格判断、updated_at 不变、时间戳只向前推进、未读规则、手动标未读和读掉手动未读。
  • Web typecheck、eslint、UI 契约检查(scripts/check-ui-contract.mjs)通过。
  • Vitest:本 PR 相关的测试(unread store、viewing、notifications、needs-you inbox、session-attention、sidebar、chat-list,以及 desktop 主进程去重与点击)全部通过。
    • 在本机跑全量 vitest 时,有几个文件失败:ui-icon-contract、chat-user-input-form、panel-preview、useMediaGallery、desktop 的 server-connection 和 docker/server-entrypoint。本 PR 没有改动这些文件,报错是 localStorage is not defined、mock 缺少导出这类和本机环境有关的问题。9ca58892b 上 CI 的 Test、Lint、迁移、桌面端构建等全部通过。
  • 更新到最新 main 后,CI 的 TestBadRequestsCarryNoUserText 发现 read-state 接口在缺少 through 时用了带文字的 echo.NewHTTPError。已改成 apperror.FieldRequired("through"),handler 测试同步更新;重启 server 后用真实接口确认返回 400 request.field_required,界面上标记未读 / 已读照常工作。
  • 旧 head 上 CI 的 Go Test 还失败过一次 TestTerminalWSPongsDoNotCountAsActivity(终端 WebSocket),和本 PR 无关,本机重跑通过。

实际页面验证(Agent 自测,不算 Human QA)

  • 环境:本地 memoh-dev 环境,web 地址 http://127.0.0.1:25100,模型用 deepseek-flash,bot 有 Nyanko、Gamer、[memoh-193] bot a / b。
  1. 发消息后马上切到另一个会话:回复完成后出现红点、标题加粗、「需要你」卡片新增一条,标签页标题显示 (1),通知只弹一次。
  2. 点开这个会话:红点、卡片里的条目和计数都清掉了。
  3. 一直停在会话里看完回复:没有红点,也没有通知。
  4. 跨 bot:在一个 bot 发消息后切到另一个 bot,后台运行完成后,能看到卡片条目和切换器上的红点,并收到通知;从卡片点这一条会切回原来的 bot 并标为已读。
    • 注意:MEMOH-193 修好之前,切换 bot 会中止正在运行的任务。这一项是我在本地临时去掉那段中止逻辑后测的,那个临时改动没有提交。
  5. 等待确认:打开“执行命令需审批”,让 bot 执行 date。卡片显示黄色的“等待你确认”,切换器上也是黄点,并发出通知;点“允许”后运行完成,因为当时正在看,没有重复提醒。
  6. 标记为未读:右键一条已读的会话,选“标记为未读”,它出现在卡片里,计数加 1,会话行出现红点;再选“标记为已读”,又从卡片里消失。
  7. 折叠:点卡片标题,列表收起,只剩标题和计数;再点一次展开。展开“显示全部”和收起的速度一致,展开出来的条目不会重播高亮。
  8. 全部标为已读:点 ×,弹出“全部 13 条标为已读?”的确认;确认后卡片消失,提示“已将 13 条标为已读”;点“撤销”,13 条全部恢复。
  9. 多选栏:右键 → Select 进入多选,多选栏出现在卡片下方、“文件夹”上方。在真实页面量了间距:卡片、多选栏、文件夹、最近之间都是 8px,多选栏出现和不出现、卡片折叠、没有卡片时都一样。往下滚动时多选栏吸在顶部,背景不透明,不会盖到卡片上。
  10. 颜色分级:在森林配色的浅色和深色下各测一遍。我临时把一条会话的状态改成“运行失败”,测完已改回。结果:只有回复时,每行是主题色的点;卡片计数是黄色,因为折叠起来的行里有一条在等待确认;有失败时,那一行变成红点和红字,卡片计数变红。bot 切换器菜单里三种颜色同时出现。深色模式下三种颜色的数字都看得清。
  • 浏览器通知:测试用的是无界面浏览器,弹不出真正的系统通知,所以把 Notification 换成了一个记录器,确认通知只调用一次,标题和正文都正确。
  • 桌面端:用 electron-vite dev 连到测试环境,通过调试端口检查:
    • 后台回复完成时主进程只发出 1 条原生通知,Dock 角标随之增加。
    • 同一条提醒连发两次、再发一条参数不合法的,最后只弹出 1 条。
    • 模拟点击通知后跳到对应会话,会话标为已读,角标减 1。

没有验证的

  • macOS 系统通知横幅本身:本机的开发版 Electron 只有 ad-hoc 签名,而且签名不完整。macOS 直接拒绝它发通知(Notifications are not allowed for this application),既不弹授权框,也不出现在「系统设置 → 通知」里。主进程确实发出了通知,但横幅显示需要用正式签名的版本做人工 QA。
  • Windows 的角标,以及 Linux 的通知。
  • 待定:刷新页面目前算“重新打开”,会把手动标的未读读掉。

Screenshots / Recordings

2026-11-02 当前集成版本(Agent 捕获,用户已复核本轮页面)
2026-11-02 当前集成版本:浅色森林配色,Bot 菜单的失败红色、等待黄色、回复主题色

2026-11-02 当前集成版本:深色森林配色的三种提醒计数

2026-11-02 当前集成版本:受控模型回合在后台完成,未读数从 3 增为 4;最近列表转圈滞留为原 PR 已记录问题

2026-11-02 当前集成版本:打开后台回复后显示正文,未读数回到 3

2026-11-02 当前集成版本:批量已读前二次确认

2026-11-02 当前集成版本:390px 窄屏中文提醒卡片,跨 Bot 打开后关闭导航并标为已读

此前提交的历史截图

以下 1–20 来自此前运行的开发环境(Agent 自测);1–7 的卡片样式较早,8–20 是合入本轮 main 前的版本。当前提交请以上方六张截图为准。

  1. 跨 bot 未读:当前在 Gamer,Kitty 的会话在后台回复完成。「需要你」卡片列出这条未读,切换器头像上有红点。

跨 bot 未读:停在 Gamer 时看到 Kitty 的回复

  1. 从卡片跨 bot 打开:点这一条后切回 Kitty 并打开会话,会话被标为已读,计数从 3 变成 2。

从卡片切回 Kitty 打开会话

  1. 等待你确认:运行在等待工具审批,卡片里显示黄色的“等待你确认”,切换器上也是黄点。

等待你确认以黄色显示

  1. 打开后看到审批卡片:点开会话,看到待审批的 date 命令。

会话里的审批卡片

  1. 批准后运行完成:因为当时正在看这个会话,没有新增红点,也没有重复提醒。

批准后运行完成,没有重复提醒

  1. 桌面端点击通知后:模拟点击原生通知,窗口跳到 Kitty 的「你好」会话,并标为已读。

桌面端点击通知后打开对应会话

  1. 桌面端 Dock 角标:Memoh 开发版图标上的角标是 3,和主进程读到的未读数一致。

Dock 上的未读角标

  1. 右键菜单“标记为未读”:右键一条已读的会话,菜单里有“标记为未读”。

右键菜单里的标记为未读

  1. 标记后:海鹦这条出现在卡片里,计数从 12 变成 13,会话行出现红点、标题加粗。

标记为未读后出现在卡片里

  1. 折叠卡片:点标题后只剩“需要你”和计数。

折叠后的卡片

  1. 全部标为已读的二次确认:点 × 弹出小气泡,确认前不会改动任何状态。

全部标为已读的确认气泡

  1. 带撤销的提示:确认后卡片消失,右上角提示带“撤销”,点了之后 13 条全部恢复。

全部标为已读后的撤销提示

  1. 多选栏,修改前:多选栏在卡片上方,看起来像是把卡片也算进了选择范围。

修改前,多选栏在卡片上方

  1. 多选栏,修改后:多选栏在卡片下方,作为“文件夹 + 最近”的标题行,上下间距都是 8px。

修改后,多选栏在卡片下方

  1. 多选栏吸顶:往下滚动后,多选栏吸在顶部,删除和取消一直点得到。

滚动时多选栏吸顶

  1. 卡片折叠时的多选栏:间距和展开时一样。

卡片折叠时的多选栏

  1. 颜色分级(浅色):普通回复是主题色(森林绿)的点,卡片计数是黄色,因为折叠起来的行里有一条在等待确认。

颜色分级:普通回复用主题色

  1. 出现失败时:那一行变成红点和红字,卡片计数变红。

出现失败时计数变红

  1. bot 切换器里的计数:只有回复的 bot 是主题色,有等待确认的 bot 是黄色,有失败的 bot 是红色。

bot 切换器里三种色调

  1. 深色模式:同一个菜单在深色下的效果。

深色模式下的三种色调

Human QA

  • Human QA passed

@github-actions github-actions Bot added change:desktop Changes the Electron desktop app or shared desktop configuration change:migrations Adds, modifies, or removes database migrations change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:XL PR size uses the larger of added or deleted lines, excluding generated files labels Oct 22, 2026
A chat tab that is no longer shown is kept alive with the props it had
when it was last rendered, so it still looked visible and active and
marked new replies read the moment they arrived. Track activation in
useSessionViewing so every cached pane stops reading.

Refs MEMOH-146
The inbox becomes one raised card aligned to the sidebar title and dot
columns, with a mail-style row (title and elapsed time, then bot and
state). Rows and the card reveal and collapse on the house spring, and
one AttentionDot component now owns the unread mark everywhere: a
spring pop and a single halo when attention arrives, yellow when the
agent waits on the user, and a cutout on the bot switcher avatar.

Refs MEMOH-146
main took 0169 for dropping compaction settings.

Refs MEMOH-146
Expanding the needs-you list replayed the arrival highlight and dot pop on
rows that were already there, because the motion ran on mount. Arrival motion
now keys off the unread store's isFresh (a live attention within the last
two seconds), so expanding, reloading or switching bots stays still.

Rows and the card use the slide-in + highlight motion picked in the design
lab: height, fade and a short drop on one ease-out curve, a staggered burst,
a one-shot kind tint, a dot pop and a count bump, all collapsing to instant
under prefers-reduced-motion.

Refs MEMOH-146
Rows revealed by "Show all" used the live-arrival entrance (340ms plus an
80ms stagger per row), so expanding four rows took about 600ms while
collapsing took 240ms. Revealed rows now open together at the collapse
duration; the slower staggered entrance stays for live arrivals.

Refs MEMOH-146
Read and unread are now two sides of one per-user state: session_reads
keeps a forward-only read_at and a forward-only marked_unread_at, and the
later one wins, so concurrent tabs and devices converge. A session the user
marks unread keeps its own attention kind and time; one that never needed
attention shows as "marked".

PUT /users/me/read-state replaces the per-bot mark-read endpoint and takes
a batch of {session_id, unread, through} changes, so marking one session,
reading everything, and undoing it all use one call. Only sessions the
caller created and that can carry unread state are touched. Marking unread
publishes session_unread, never session_attention, so it never notifies.

On the web, a session marked unread while it is on screen is left alone
until it is opened again; new attention on screen is still read at once.

Refs MEMOH-146
… unread

The card header now folds the list like the Folders and Recents section
headers (whole row toggles, chevron on hover or focus, remembered per
device). A trailing × reads every unread session behind a confirm bubble,
and the toast it raises offers an undo that marks the same sessions unread
again, restoring their kind and time.

Session rows gain "Mark as unread" / "Mark as read" in both the context
menu and the hover menu, shown only on sessions that can carry unread
state (canHoldUnread mirrors the server rule).

leaveRow now drops its held end state once Vue hides the element, so a
list folded with v-show does not stay at zero height when reopened.

Refs MEMOH-146
The multi-select bar sat above the Needs you card, as if the card's rows
were part of the selection. It now heads the Folders and Recents group it
acts on, sticky inside that group in the shared scrollport, with even 8px
gaps to the card and the Folders header.

Refs MEMOH-146
@LittleSound
LittleSound force-pushed the feat/memoh-146-session-unread-notifications branch from 9aebf00 to 3031542 Compare October 29, 2026 13:13
main now refuses echo.NewHTTPError bad requests that carry text, since the
boundary never sends that text to the user. A read that omits through
answers request.field_required for the through field instead.

Refs MEMOH-146
@LittleSound
LittleSound marked this pull request as ready for review October 29, 2026 13:37
Red was spent on every unread reply, so a real failure did not stand out.
Dots, arrival tints and counts now follow one ladder: red for a failed run,
yellow while the agent waits on the user, the scheme's brand for a plain
reply or a manual mark. The needs-you count and the bot switcher speak for
their most urgent unread, through BadgeCount's new warning and brand tones.

Refs MEMOH-146
@chen-ran chen-ran changed the title feat: 会话未读红点与系统通知 feat: 会话未读状态与系统通知 Nov 1, 2026
@chen-ran
chen-ran merged commit 164c8c6 into main Nov 1, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:desktop Changes the Electron desktop app or shared desktop configuration change:migrations Adds, modifies, or removes database migrations change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:XL PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants