|
|
@@ -0,0 +1,847 @@
|
|
|
+# λ-Scientist P0-B Research Inbox Implementation Plan
|
|
|
+
|
|
|
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
|
+
|
|
|
+**Goal:** 为当前项目提供一个统一的“待处理”入口,集中展示待审批、失败和完成未读,并能一键回到对应会话。
|
|
|
+
|
|
|
+**Architecture:** 新增纯逻辑的 Inbox 聚合与已读模块,由 `PaasChat` 把当前项目会话和任务索引合成为 Inbox,通过常驻顶栏 Portal 渲染入口。Inbox v1 只覆盖当前项目;任务仅在 `thread_id` 能映射到当前项目会话时纳入。
|
|
|
+
|
|
|
+**Tech Stack:** SolidJS、TypeScript、Bun test、Playwright、浏览器 `localStorage`、现有 PaaS 会话与任务索引。
|
|
|
+
|
|
|
+**Spec:** `PAAS_PRODUCT_BRAINSTORM.zh-CN.md`
|
|
|
+
|
|
|
+## Global Constraints
|
|
|
+
|
|
|
+- Inbox 只展示真实可确认状态,不生成推测性提醒。
|
|
|
+- Inbox v1 只聚合当前项目;跨项目全局 Inbox 留到后续计划。
|
|
|
+- 已读状态仅保存在本机,不伪装成平台已读。
|
|
|
+- 待审批和失败不会因为已读而消失;只有完成未读会因已读消失。
|
|
|
+- 同一 run 在会话和任务索引中重复时去重,会话来源优先。
|
|
|
+- 任务只有 `thread_id` 属于当前项目会话时才纳入。
|
|
|
+- 顶栏只保留一个待处理入口,删除旧的“进行中 · 待确认”重复计数。
|
|
|
+- 不使用 emoji;所有用户文案使用中文。
|
|
|
+- 测试必须从包目录运行;类型检查使用 `bun typecheck`。
|
|
|
+- 每个 Task 独立提交。
|
|
|
+
|
|
|
+## Scope
|
|
|
+
|
|
|
+本计划包含:
|
|
|
+
|
|
|
+- 当前项目 Inbox 的聚合、优先级、去重和排序。
|
|
|
+- 本机已读状态。
|
|
|
+- 会话消息与任务索引聚合。
|
|
|
+- 顶栏入口、弹出面板、打开会话和键盘关闭。
|
|
|
+- 单元测试、浏览器测试和 README。
|
|
|
+
|
|
|
+不包含:
|
|
|
+
|
|
|
+- 跨项目 Inbox 与项目切换跳转。
|
|
|
+- 预算告警、连接异常、系统通知。
|
|
|
+- 平台级已读同步、多设备已读。
|
|
|
+- Inbox 批量处理、忽略规则和自定义过滤。
|
|
|
+- Run Inspector 和成果资产库。
|
|
|
+
|
|
|
+## File Structure
|
|
|
+
|
|
|
+| 文件 | 责任 |
|
|
|
+| --- | --- |
|
|
|
+| `packages/app/src/pages/paas/inbox.ts` | Inbox 类型、来源聚合、优先级、去重和排序 |
|
|
|
+| `packages/app/src/pages/paas/inbox.test.ts` | 聚合、任务映射和去重测试 |
|
|
|
+| `packages/app/src/pages/paas/inbox-seen.ts` | 本机已读 key、读写和损坏恢复 |
|
|
|
+| `packages/app/src/pages/paas/inbox-seen.test.ts` | 已读作用域和持久化测试 |
|
|
|
+| `packages/app/src/pages/paas/inbox-panel.tsx` | 顶栏按钮、弹出面板、空态、Escape/外部关闭 |
|
|
|
+| `packages/app/src/pages/paas/chat.tsx` | Inbox memo、已读更新、打开会话、Portal |
|
|
|
+| `packages/app/src/pages/paas/index.tsx` | 顶栏 Inbox mount、任务索引输入、移除旧计数 |
|
|
|
+| `packages/app/src/pages/paas/studio.css` | Inbox 入口和面板样式 |
|
|
|
+| `packages/app/e2e/paas/inbox.spec.ts` | 当前项目 Inbox 浏览器验收 |
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### Task 1: Inbox 聚合模型
|
|
|
+
|
|
|
+**Files:**
|
|
|
+- Create: `packages/app/src/pages/paas/inbox.ts`
|
|
|
+- Create: `packages/app/src/pages/paas/inbox.test.ts`
|
|
|
+
|
|
|
+**Interfaces:**
|
|
|
+- Consumes: `ResearchChat`、任务索引行
|
|
|
+- Produces:
|
|
|
+ - `type InboxKind = "approval" | "failed" | "unread"`
|
|
|
+ - `type InboxItem = { id; kind; title; detail; projectID; chatID; runID?; at }`
|
|
|
+ - `buildProjectInbox(input): InboxItem[]`
|
|
|
+
|
|
|
+- [ ] **Step 1: 写失败测试**
|
|
|
+
|
|
|
+```ts
|
|
|
+import { expect, test } from "bun:test"
|
|
|
+import { buildProjectInbox } from "./inbox"
|
|
|
+
|
|
|
+const chat = (id: string, projectID: string, messages: Record<string, unknown>[]) => ({
|
|
|
+ id,
|
|
|
+ projectID,
|
|
|
+ agentID: "research67",
|
|
|
+ name: "科研助手",
|
|
|
+ title: `会话 ${id}`,
|
|
|
+ threadID: `thread-${id}`,
|
|
|
+ draft: "",
|
|
|
+ files: [],
|
|
|
+ messages,
|
|
|
+})
|
|
|
+
|
|
|
+test("builds approvals, failures and unread completions for the current project", () => {
|
|
|
+ const items = buildProjectInbox({
|
|
|
+ projectID: "p1",
|
|
|
+ seen: new Set<string>(),
|
|
|
+ chats: [
|
|
|
+ chat("a", "p1", [
|
|
|
+ { id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "请确认" },
|
|
|
+ { id: "m2", role: "assistant", runID: "run-b", status: "failed", text: "", error: "失败" },
|
|
|
+ { id: "m3", role: "assistant", runID: "run-c", status: "completed", text: "完成报告" },
|
|
|
+ ]),
|
|
|
+ chat("b", "p2", [
|
|
|
+ { id: "m4", role: "assistant", runID: "run-d", status: "waiting_human", text: "其他项目" },
|
|
|
+ ]),
|
|
|
+ ],
|
|
|
+ tasks: [],
|
|
|
+ })
|
|
|
+ expect(items.map((item) => item.kind)).toEqual(["approval", "failed", "unread"])
|
|
|
+ expect(items.every((item) => item.projectID === "p1")).toBe(true)
|
|
|
+})
|
|
|
+
|
|
|
+test("task rows only join through current project threads and dedupe runs", () => {
|
|
|
+ const items = buildProjectInbox({
|
|
|
+ projectID: "p1",
|
|
|
+ seen: new Set<string>(),
|
|
|
+ chats: [chat("a", "p1", [{ id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "" }])],
|
|
|
+ tasks: [
|
|
|
+ { run_id: "run-a", thread_id: "thread-a", status: "waiting_human", input: "重复" },
|
|
|
+ { run_id: "run-b", thread_id: "thread-b", status: "failed", input: "外部任务" },
|
|
|
+ { run_id: "run-c", thread_id: "thread-a", status: "completed", input: "任务完成" },
|
|
|
+ ],
|
|
|
+ })
|
|
|
+ expect(items.filter((item) => item.runID === "run-a")).toHaveLength(1)
|
|
|
+ expect(items.some((item) => item.runID === "run-b")).toBe(false)
|
|
|
+ expect(items.some((item) => item.runID === "run-c" && item.kind === "unread")).toBe(true)
|
|
|
+})
|
|
|
+
|
|
|
+test("seen only hides completed unread items", () => {
|
|
|
+ const items = buildProjectInbox({
|
|
|
+ projectID: "p1",
|
|
|
+ seen: new Set(["unread:run-b"]),
|
|
|
+ chats: [
|
|
|
+ chat("a", "p1", [
|
|
|
+ { id: "m1", role: "assistant", runID: "run-a", status: "waiting_human", text: "" },
|
|
|
+ { id: "m2", role: "assistant", runID: "run-b", status: "completed", text: "完成" },
|
|
|
+ ]),
|
|
|
+ ],
|
|
|
+ tasks: [],
|
|
|
+ })
|
|
|
+ expect(items.map((item) => item.kind)).toEqual(["approval"])
|
|
|
+})
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 2: 运行测试确认失败**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun test --conditions=solid --preload ./happydom.ts src/pages/paas/inbox.test.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: FAIL,`inbox.ts` 不存在。
|
|
|
+
|
|
|
+- [ ] **Step 3: 实现聚合**
|
|
|
+
|
|
|
+```ts
|
|
|
+import { paasStatus, paasText } from "@/paas"
|
|
|
+
|
|
|
+export type InboxKind = "approval" | "failed" | "unread"
|
|
|
+
|
|
|
+export type InboxItem = {
|
|
|
+ id: string
|
|
|
+ kind: InboxKind
|
|
|
+ title: string
|
|
|
+ detail: string
|
|
|
+ projectID: string
|
|
|
+ chatID: string
|
|
|
+ runID?: string
|
|
|
+ at: number
|
|
|
+}
|
|
|
+
|
|
|
+type Message = {
|
|
|
+ id: string
|
|
|
+ role?: string
|
|
|
+ status?: string
|
|
|
+ text?: string
|
|
|
+ error?: string
|
|
|
+ runID?: string
|
|
|
+ updated?: number
|
|
|
+ started?: number
|
|
|
+}
|
|
|
+
|
|
|
+type Chat = {
|
|
|
+ id: string
|
|
|
+ projectID?: string
|
|
|
+ title: string
|
|
|
+ name: string
|
|
|
+ threadID: string
|
|
|
+ messages: Message[]
|
|
|
+}
|
|
|
+
|
|
|
+const time = (value: unknown) => {
|
|
|
+ const result = typeof value === "number" ? value : Date.parse(paasText(value))
|
|
|
+ return Number.isFinite(result) ? result : 0
|
|
|
+}
|
|
|
+
|
|
|
+export function buildProjectInbox(input: {
|
|
|
+ projectID: string
|
|
|
+ chats: Chat[]
|
|
|
+ tasks: Record<string, unknown>[]
|
|
|
+ seen: Set<string>
|
|
|
+}): InboxItem[] {
|
|
|
+ const chats = input.chats.filter((chat) => chat.projectID === input.projectID)
|
|
|
+ const threads = new Set(chats.map((chat) => chat.threadID).filter(Boolean))
|
|
|
+ const items = new Map<string, InboxItem>()
|
|
|
+ const add = (item: InboxItem) => {
|
|
|
+ const key = item.runID || item.id
|
|
|
+ if (!items.has(key)) items.set(key, item)
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const chat of chats) {
|
|
|
+ for (const message of chat.messages) {
|
|
|
+ if (message.role !== "assistant" || !message.runID) continue
|
|
|
+ const at = message.updated || message.started || 0
|
|
|
+ if (["waiting_human", "waiting_confirmation"].includes(message.status || ""))
|
|
|
+ add({
|
|
|
+ id: `approval:${message.runID}`,
|
|
|
+ kind: "approval",
|
|
|
+ title: chat.title,
|
|
|
+ detail: "需要确认后才能继续",
|
|
|
+ projectID: input.projectID,
|
|
|
+ chatID: chat.id,
|
|
|
+ runID: message.runID,
|
|
|
+ at,
|
|
|
+ })
|
|
|
+ else if (message.status === "failed")
|
|
|
+ add({
|
|
|
+ id: `failed:${message.runID}`,
|
|
|
+ kind: "failed",
|
|
|
+ title: chat.title,
|
|
|
+ detail: message.error || "任务执行失败",
|
|
|
+ projectID: input.projectID,
|
|
|
+ chatID: chat.id,
|
|
|
+ runID: message.runID,
|
|
|
+ at,
|
|
|
+ })
|
|
|
+ else if (
|
|
|
+ ["completed", "partial"].includes(message.status || "") &&
|
|
|
+ message.text &&
|
|
|
+ !input.seen.has(`unread:${message.runID}`)
|
|
|
+ )
|
|
|
+ add({
|
|
|
+ id: `unread:${message.runID}`,
|
|
|
+ kind: "unread",
|
|
|
+ title: chat.title,
|
|
|
+ detail: chat.name,
|
|
|
+ projectID: input.projectID,
|
|
|
+ chatID: chat.id,
|
|
|
+ runID: message.runID,
|
|
|
+ at,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (const task of input.tasks) {
|
|
|
+ const runID = paasText(task.run_id) || paasText(task.id)
|
|
|
+ const threadID = paasText(task.thread_id) || paasText(task.session_id)
|
|
|
+ if (!runID || !threadID || !threads.has(threadID) || items.has(runID)) continue
|
|
|
+ const chat = chats.find((item) => item.threadID === threadID)!
|
|
|
+ const status = paasStatus(task)
|
|
|
+ const at = time(task.updated_at) || time(task.created_at)
|
|
|
+ if (status.startsWith("waiting"))
|
|
|
+ add({
|
|
|
+ id: `approval:${runID}`,
|
|
|
+ kind: "approval",
|
|
|
+ title: chat.title,
|
|
|
+ detail: "任务需要确认",
|
|
|
+ projectID: input.projectID,
|
|
|
+ chatID: chat.id,
|
|
|
+ runID,
|
|
|
+ at,
|
|
|
+ })
|
|
|
+ else if (status === "failed")
|
|
|
+ add({
|
|
|
+ id: `failed:${runID}`,
|
|
|
+ kind: "failed",
|
|
|
+ title: chat.title,
|
|
|
+ detail: paasText(task.error_message) || "任务执行失败",
|
|
|
+ projectID: input.projectID,
|
|
|
+ chatID: chat.id,
|
|
|
+ runID,
|
|
|
+ at,
|
|
|
+ })
|
|
|
+ else if (["completed", "partial"].includes(status) && !input.seen.has(`unread:${runID}`))
|
|
|
+ add({
|
|
|
+ id: `unread:${runID}`,
|
|
|
+ kind: "unread",
|
|
|
+ title: chat.title,
|
|
|
+ detail: chat.name,
|
|
|
+ projectID: input.projectID,
|
|
|
+ chatID: chat.id,
|
|
|
+ runID,
|
|
|
+ at,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const priority: Record<InboxKind, number> = { approval: 0, failed: 1, unread: 2 }
|
|
|
+ return [...items.values()].sort((a, b) => priority[a.kind] - priority[b.kind] || b.at - a.at)
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 4: 运行测试**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun test --conditions=solid --preload ./happydom.ts src/pages/paas/inbox.test.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: PASS。
|
|
|
+
|
|
|
+- [ ] **Step 5: 提交**
|
|
|
+
|
|
|
+```bash
|
|
|
+git add packages/app/src/pages/paas/inbox.ts packages/app/src/pages/paas/inbox.test.ts
|
|
|
+git commit -m "feat(paas): aggregate current project inbox items"
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### Task 2: 本机已读状态
|
|
|
+
|
|
|
+**Files:**
|
|
|
+- Create: `packages/app/src/pages/paas/inbox-seen.ts`
|
|
|
+- Create: `packages/app/src/pages/paas/inbox-seen.test.ts`
|
|
|
+
|
|
|
+**Interfaces:**
|
|
|
+- Produces:
|
|
|
+ - `inboxSeenKey(scope, windowID, projectID): string`
|
|
|
+ - `readInboxSeen(storage, key): Set<string>`
|
|
|
+ - `markInboxSeen(storage, key, id): Set<string>`
|
|
|
+
|
|
|
+- [ ] **Step 1: 写失败测试**
|
|
|
+
|
|
|
+```ts
|
|
|
+import { expect, test } from "bun:test"
|
|
|
+import { inboxSeenKey, markInboxSeen, readInboxSeen } from "./inbox-seen"
|
|
|
+
|
|
|
+class MemoryStorage implements Storage {
|
|
|
+ private data = new Map<string, string>()
|
|
|
+ get length() { return this.data.size }
|
|
|
+ clear() { this.data.clear() }
|
|
|
+ getItem(key: string) { return this.data.get(key) ?? null }
|
|
|
+ key(index: number) { return [...this.data.keys()][index] ?? null }
|
|
|
+ removeItem(key: string) { this.data.delete(key) }
|
|
|
+ setItem(key: string, value: string) { this.data.set(key, value) }
|
|
|
+}
|
|
|
+
|
|
|
+test("seen state is isolated by scope, window and project", () => {
|
|
|
+ const storage = new MemoryStorage()
|
|
|
+ const a = inboxSeenKey("scope-a", "main", "p1")
|
|
|
+ const b = inboxSeenKey("scope-a", "main", "p2")
|
|
|
+ markInboxSeen(storage, a, "unread:run-a")
|
|
|
+ expect([...readInboxSeen(storage, a)]).toEqual(["unread:run-a"])
|
|
|
+ expect(readInboxSeen(storage, b).size).toBe(0)
|
|
|
+})
|
|
|
+
|
|
|
+test("corrupt seen state falls back to empty and remains writable", () => {
|
|
|
+ const storage = new MemoryStorage()
|
|
|
+ const key = inboxSeenKey("scope", "main", "p1")
|
|
|
+ storage.setItem(key, "{broken")
|
|
|
+ expect(readInboxSeen(storage, key).size).toBe(0)
|
|
|
+ expect([...markInboxSeen(storage, key, "unread:run-b")]).toEqual(["unread:run-b"])
|
|
|
+})
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 2: 运行测试确认失败**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun test --conditions=solid --preload ./happydom.ts src/pages/paas/inbox-seen.test.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: FAIL。
|
|
|
+
|
|
|
+- [ ] **Step 3: 实现**
|
|
|
+
|
|
|
+```ts
|
|
|
+export function inboxSeenKey(scope: string, windowID: string, projectID: string) {
|
|
|
+ return `lambda-scientist.inbox-seen.v1:${scope}:${windowID}:${projectID}`
|
|
|
+}
|
|
|
+
|
|
|
+export function readInboxSeen(storage: Storage, key: string) {
|
|
|
+ try {
|
|
|
+ const value = JSON.parse(storage.getItem(key) || "[]") as unknown
|
|
|
+ return new Set(Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : [])
|
|
|
+ } catch {
|
|
|
+ return new Set<string>()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function writeInboxSeen(storage: Storage, key: string, seen: Set<string>) {
|
|
|
+ storage.setItem(key, JSON.stringify([...seen]))
|
|
|
+}
|
|
|
+
|
|
|
+export function markInboxSeen(storage: Storage, key: string, id: string) {
|
|
|
+ const seen = readInboxSeen(storage, key)
|
|
|
+ seen.add(id)
|
|
|
+ writeInboxSeen(storage, key, seen)
|
|
|
+ return seen
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 4: 运行测试与类型检查**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun test --conditions=solid --preload ./happydom.ts src/pages/paas/inbox-seen.test.ts)
|
|
|
+(cd packages/app && bun typecheck)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: PASS。
|
|
|
+
|
|
|
+- [ ] **Step 5: 提交**
|
|
|
+
|
|
|
+```bash
|
|
|
+git add packages/app/src/pages/paas/inbox-seen.ts packages/app/src/pages/paas/inbox-seen.test.ts
|
|
|
+git commit -m "feat(paas): persist inbox read state locally"
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### Task 3: 在会话状态中计算当前项目 Inbox
|
|
|
+
|
|
|
+**Files:**
|
|
|
+- Modify: `packages/app/src/pages/paas/chat.tsx`
|
|
|
+- Modify: `packages/app/src/pages/paas/index.tsx`
|
|
|
+
|
|
|
+**Interfaces:**
|
|
|
+- Consumes: `buildProjectInbox`、`readInboxSeen`、`markInboxSeen`,以及现有 `PaasChat.props.onShowChat`
|
|
|
+- Produces:
|
|
|
+ - `PaasChat.props.inboxTasks: () => Record<string, unknown>[]`
|
|
|
+ - `inbox` memo 与 `openInboxItem(item)`
|
|
|
+
|
|
|
+- [ ] **Step 1: 接入计算逻辑**
|
|
|
+
|
|
|
+`chat.tsx` 增加导入:
|
|
|
+
|
|
|
+```ts
|
|
|
+import { buildProjectInbox, type InboxItem } from "./inbox"
|
|
|
+import { inboxSeenKey, markInboxSeen, readInboxSeen } from "./inbox-seen"
|
|
|
+```
|
|
|
+
|
|
|
+props 增加:
|
|
|
+
|
|
|
+```ts
|
|
|
+inboxTasks: () => Record<string, unknown>[]
|
|
|
+```
|
|
|
+
|
|
|
+在 `createResearchChats` 后增加:
|
|
|
+
|
|
|
+```ts
|
|
|
+const [seenVersion, setSeenVersion] = createSignal(0)
|
|
|
+const seenKey = createMemo(() =>
|
|
|
+ inboxSeenKey(props.scope || "local", platform.windowID || "main", props.projectID),
|
|
|
+)
|
|
|
+const seen = createMemo(() => {
|
|
|
+ seenVersion()
|
|
|
+ return readInboxSeen(localStorage, seenKey())
|
|
|
+})
|
|
|
+const inbox = createMemo(() =>
|
|
|
+ buildProjectInbox({
|
|
|
+ projectID: props.projectID,
|
|
|
+ chats: state.chats,
|
|
|
+ tasks: props.inboxTasks(),
|
|
|
+ seen: seen(),
|
|
|
+ }),
|
|
|
+)
|
|
|
+const openInboxItem = (item: InboxItem) => {
|
|
|
+ markInboxSeen(localStorage, seenKey(), item.id)
|
|
|
+ setSeenVersion((value) => value + 1)
|
|
|
+ model.activate(item.chatID)
|
|
|
+ props.onShowChat?.()
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+`index.tsx` 传入:
|
|
|
+
|
|
|
+```tsx
|
|
|
+inboxTasks={() => tasks.state.rows}
|
|
|
+onShowChat={() => goPage("chat")}
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 2: 运行类型检查**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun typecheck)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: PASS。
|
|
|
+
|
|
|
+- [ ] **Step 3: 运行现有工作台回归**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun x --no-install playwright test e2e/paas/workbench.spec.ts --config e2e/paas/playwright.config.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: PASS,确认新增 props 不破坏现有会话。
|
|
|
+
|
|
|
+- [ ] **Step 4: 提交**
|
|
|
+
|
|
|
+```bash
|
|
|
+git add packages/app/src/pages/paas/chat.tsx packages/app/src/pages/paas/index.tsx
|
|
|
+git commit -m "feat(paas): compute current project inbox"
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### Task 4: Inbox 入口、面板与顶栏接线
|
|
|
+
|
|
|
+**Files:**
|
|
|
+- Create: `packages/app/src/pages/paas/inbox-panel.tsx`
|
|
|
+- Modify: `packages/app/src/pages/paas/chat.tsx`
|
|
|
+- Modify: `packages/app/src/pages/paas/index.tsx`
|
|
|
+- Modify: `packages/app/src/pages/paas/studio.css`
|
|
|
+- Create: `packages/app/e2e/paas/inbox.spec.ts`
|
|
|
+
|
|
|
+**Interfaces:**
|
|
|
+- Consumes: `inbox` memo、`openInboxItem`
|
|
|
+- Produces: 顶栏“待处理 N 项”按钮和弹出面板;为空时不渲染
|
|
|
+
|
|
|
+- [ ] **Step 1: 写失败 E2E**
|
|
|
+
|
|
|
+```ts
|
|
|
+import { expect, test } from "@playwright/test"
|
|
|
+
|
|
|
+test("completed research appears in inbox until opened", async ({ page }) => {
|
|
|
+ await page.goto("/e2e/paas/index.html?completed")
|
|
|
+ await page.getByLabel("API Key", { exact: true }).fill("inbox-test")
|
|
|
+ await page.getByRole("button", { name: "连接平台", exact: true }).click()
|
|
|
+ await page
|
|
|
+ .getByRole("button", { name: /已有研究/ })
|
|
|
+ .first()
|
|
|
+ .click()
|
|
|
+ const inbox = page.getByRole("button", { name: /待处理/ })
|
|
|
+ await expect(inbox).toContainText("1")
|
|
|
+ await inbox.click()
|
|
|
+ const panel = page.getByRole("dialog", { name: "待处理" })
|
|
|
+ await panel.getByRole("button", { name: /已有研究/ }).click()
|
|
|
+ await expect(page.getByRole("button", { name: /待处理/ })).toHaveCount(0)
|
|
|
+})
|
|
|
+
|
|
|
+test("inbox panel closes with Escape and restores focus", async ({ page }) => {
|
|
|
+ await page.goto("/e2e/paas/index.html?completed")
|
|
|
+ await page.getByLabel("API Key", { exact: true }).fill("inbox-escape")
|
|
|
+ await page.getByRole("button", { name: "连接平台", exact: true }).click()
|
|
|
+ await page
|
|
|
+ .getByRole("button", { name: /已有研究/ })
|
|
|
+ .first()
|
|
|
+ .click()
|
|
|
+ const inbox = page.getByRole("button", { name: /待处理/ })
|
|
|
+ await inbox.click()
|
|
|
+ await expect(page.getByRole("dialog", { name: "待处理" })).toBeVisible()
|
|
|
+ await page.keyboard.press("Escape")
|
|
|
+ await expect(page.getByRole("dialog", { name: "待处理" })).toHaveCount(0)
|
|
|
+ await expect(inbox).toBeFocused()
|
|
|
+})
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 2: 运行测试确认失败**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun x --no-install playwright test e2e/paas/inbox.spec.ts --config e2e/paas/playwright.config.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: FAIL,找不到待处理入口。
|
|
|
+
|
|
|
+- [ ] **Step 3: 实现面板**
|
|
|
+
|
|
|
+`inbox-panel.tsx`:
|
|
|
+
|
|
|
+```tsx
|
|
|
+import { For, Show, createSignal, onCleanup, onMount } from "solid-js"
|
|
|
+import { ResearchIcon } from "./research-icon"
|
|
|
+import type { InboxItem } from "./inbox"
|
|
|
+
|
|
|
+const labels = { approval: "待确认", failed: "失败", unread: "未读结果" }
|
|
|
+
|
|
|
+export function InboxPanel(props: { items: InboxItem[]; onOpen: (item: InboxItem) => void }) {
|
|
|
+ const [open, setOpen] = createSignal(false)
|
|
|
+ let root: HTMLDetailsElement | undefined
|
|
|
+
|
|
|
+ onMount(() => {
|
|
|
+ const close = (event: KeyboardEvent) => {
|
|
|
+ if (event.key !== "Escape" || !open()) return
|
|
|
+ event.preventDefault()
|
|
|
+ setOpen(false)
|
|
|
+ root?.querySelector("summary")?.focus()
|
|
|
+ }
|
|
|
+ const outside = (event: PointerEvent) => {
|
|
|
+ if (!open() || !root || (event.target instanceof Node && root.contains(event.target))) return
|
|
|
+ setOpen(false)
|
|
|
+ }
|
|
|
+ document.addEventListener("keydown", close)
|
|
|
+ document.addEventListener("pointerdown", outside)
|
|
|
+ onCleanup(() => {
|
|
|
+ document.removeEventListener("keydown", close)
|
|
|
+ document.removeEventListener("pointerdown", outside)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Show when={props.items.length}>
|
|
|
+ <details
|
|
|
+ ref={root}
|
|
|
+ class="paas-inbox"
|
|
|
+ open={open()}
|
|
|
+ onToggle={(event) => setOpen(event.currentTarget.open)}
|
|
|
+ >
|
|
|
+ <summary aria-label={`待处理 ${props.items.length} 项`} title="待处理">
|
|
|
+ <ResearchIcon kind="task" />
|
|
|
+ <span>{props.items.length > 99 ? "99+" : props.items.length}</span>
|
|
|
+ </summary>
|
|
|
+ <section class="paas-inbox-panel" role="dialog" aria-label="待处理">
|
|
|
+ <header>
|
|
|
+ <strong>待处理</strong>
|
|
|
+ <span>{props.items.length} 项</span>
|
|
|
+ </header>
|
|
|
+ <For each={props.items}>
|
|
|
+ {(item) => (
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class={`paas-inbox-item is-${item.kind}`}
|
|
|
+ onClick={() => {
|
|
|
+ setOpen(false)
|
|
|
+ props.onOpen(item)
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <span>{labels[item.kind]}</span>
|
|
|
+ <strong>{item.title}</strong>
|
|
|
+ <small>{item.detail}</small>
|
|
|
+ </button>
|
|
|
+ )}
|
|
|
+ </For>
|
|
|
+ </section>
|
|
|
+ </details>
|
|
|
+ </Show>
|
|
|
+ )
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+`chat.tsx` 增加常驻 Portal:
|
|
|
+
|
|
|
+```tsx
|
|
|
+<Show when={props.inboxMount}>
|
|
|
+ {(mount) => (
|
|
|
+ <Portal mount={mount()}>
|
|
|
+ <InboxPanel items={inbox()} onOpen={openInboxItem} />
|
|
|
+ </Portal>
|
|
|
+ )}
|
|
|
+</Show>
|
|
|
+```
|
|
|
+
|
|
|
+`chat.tsx` props 增加:
|
|
|
+
|
|
|
+```ts
|
|
|
+inboxMount?: HTMLElement
|
|
|
+```
|
|
|
+
|
|
|
+`index.tsx` 增加:
|
|
|
+
|
|
|
+```ts
|
|
|
+const [inboxMount, setInboxMount] = createSignal<HTMLElement>()
|
|
|
+```
|
|
|
+
|
|
|
+顶栏在预览按钮前增加:
|
|
|
+
|
|
|
+```tsx
|
|
|
+<div class="paas-topbar-inbox" ref={setInboxMount} />
|
|
|
+```
|
|
|
+
|
|
|
+删除旧的 `paas-task-shortcut` 按钮块(包括其 `Show`),任务页仍可通过导航进入。
|
|
|
+
|
|
|
+`PaasChat` 传入:
|
|
|
+
|
|
|
+```tsx
|
|
|
+inboxMount={inboxMount()}
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 4: 加样式并运行 E2E**
|
|
|
+
|
|
|
+```css
|
|
|
+.paas-topbar-inbox {
|
|
|
+ flex-shrink: 0;
|
|
|
+}
|
|
|
+.paas-inbox {
|
|
|
+ position: relative;
|
|
|
+}
|
|
|
+.paas-inbox > summary {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ gap: 4px;
|
|
|
+ min-height: 34px;
|
|
|
+ padding: 5px 9px;
|
|
|
+ border-radius: 8px;
|
|
|
+ color: var(--text-weak);
|
|
|
+ font-size: var(--paas-type-caption);
|
|
|
+ cursor: pointer;
|
|
|
+ list-style: none;
|
|
|
+}
|
|
|
+.paas-inbox > summary::-webkit-details-marker {
|
|
|
+ display: none;
|
|
|
+}
|
|
|
+.paas-inbox[open] > summary,
|
|
|
+.paas-inbox > summary:hover {
|
|
|
+ background: var(--background-weak);
|
|
|
+ color: var(--text-base);
|
|
|
+}
|
|
|
+.paas-inbox-panel {
|
|
|
+ position: absolute;
|
|
|
+ top: calc(100% + 8px);
|
|
|
+ right: 0;
|
|
|
+ z-index: 30;
|
|
|
+ display: grid;
|
|
|
+ gap: 6px;
|
|
|
+ width: min(360px, 82vw);
|
|
|
+ padding: 12px;
|
|
|
+ border: 1px solid var(--border-weak-base);
|
|
|
+ border-radius: 12px;
|
|
|
+ background: var(--paas-surface);
|
|
|
+ box-shadow: var(--paas-shadow);
|
|
|
+}
|
|
|
+.paas-inbox-panel > header {
|
|
|
+ display: flex;
|
|
|
+ justify-content: space-between;
|
|
|
+ color: var(--text-weak);
|
|
|
+ font-size: var(--paas-type-meta);
|
|
|
+}
|
|
|
+.paas-inbox-item {
|
|
|
+ display: grid;
|
|
|
+ gap: 3px;
|
|
|
+ padding: 9px 10px;
|
|
|
+ border-color: transparent;
|
|
|
+ border-radius: 8px;
|
|
|
+ background: transparent;
|
|
|
+ text-align: left;
|
|
|
+}
|
|
|
+.paas-inbox-item:hover,
|
|
|
+.paas-inbox-item:focus-visible {
|
|
|
+ background: var(--background-weak);
|
|
|
+}
|
|
|
+.paas-inbox-item > span {
|
|
|
+ color: var(--text-weak);
|
|
|
+ font-size: var(--paas-type-meta);
|
|
|
+}
|
|
|
+.paas-inbox-item > small {
|
|
|
+ color: var(--text-weak);
|
|
|
+ font-size: var(--paas-type-meta);
|
|
|
+}
|
|
|
+.paas-inbox-item.is-approval > span {
|
|
|
+ color: var(--paas-accent);
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun x --no-install playwright test e2e/paas/inbox.spec.ts --config e2e/paas/playwright.config.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: PASS。
|
|
|
+
|
|
|
+- [ ] **Step 5: 提交**
|
|
|
+
|
|
|
+```bash
|
|
|
+git add packages/app/src/pages/paas/inbox-panel.tsx packages/app/src/pages/paas/chat.tsx packages/app/src/pages/paas/index.tsx packages/app/src/pages/paas/studio.css packages/app/e2e/paas/inbox.spec.ts
|
|
|
+git commit -m "feat(paas): add current project research inbox"
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### Task 5: 完整回归与文档
|
|
|
+
|
|
|
+**Files:**
|
|
|
+- Modify: `packages/app/src/pages/paas/README.md`
|
|
|
+- Modify: `PAAS_RESEARCH_INBOX_PLAN.zh-CN.md` 仅当实现与计划有偏差
|
|
|
+
|
|
|
+**Interfaces:**
|
|
|
+- Consumes: Task 1–4
|
|
|
+- Produces: 可重复验收证据和边界记录
|
|
|
+
|
|
|
+- [ ] **Step 1: 更新 README**
|
|
|
+
|
|
|
+在 `packages/app/src/pages/paas/README.md` 增加:
|
|
|
+
|
|
|
+```md
|
|
|
+## P0-B Research Inbox(2026-11-30)
|
|
|
+
|
|
|
+- 顶栏提供当前项目的统一待处理入口,聚合待确认、失败和完成未读。
|
|
|
+- Inbox 只展示真实可确认状态;待确认和失败不会因为已读而消失。
|
|
|
+- 完成未读的已读状态保存在本机,按平台作用域、窗口和项目隔离,不伪装成平台已读。
|
|
|
+- 任务索引只有在 `thread_id` 属于当前项目会话时才纳入 Inbox。
|
|
|
+- Inbox v1 只覆盖当前项目;跨项目全局 Inbox 留到后续计划。
|
|
|
+```
|
|
|
+
|
|
|
+- [ ] **Step 2: 运行完整单测**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun test --conditions=solid --only-failures --preload ./happydom.ts src/pages/paas)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: 全部 PASS。
|
|
|
+
|
|
|
+- [ ] **Step 3: 运行完整浏览器回归**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun x --no-install playwright test e2e/paas --config e2e/paas/playwright.config.ts)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: 全部 PASS。
|
|
|
+
|
|
|
+- [ ] **Step 4: 类型检查与生产构建**
|
|
|
+
|
|
|
+```bash
|
|
|
+(cd packages/app && bun typecheck)
|
|
|
+(cd packages/desktop && bun typecheck)
|
|
|
+(cd packages/app && bun run build)
|
|
|
+```
|
|
|
+
|
|
|
+Expected: 全部 exit 0。
|
|
|
+
|
|
|
+- [ ] **Step 5: 提交**
|
|
|
+
|
|
|
+```bash
|
|
|
+git add packages/app/src/pages/paas/README.md PAAS_RESEARCH_INBOX_PLAN.zh-CN.md
|
|
|
+git commit -m "docs(paas): document research inbox"
|
|
|
+```
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+## P0-B 验收清单
|
|
|
+
|
|
|
+- [ ] 当前项目有待确认、失败或完成未读时,顶栏出现唯一的“待处理”入口。
|
|
|
+- [ ] Inbox 数量与当前项目内可确认事项一致,其他项目不进入。
|
|
|
+- [ ] 待确认和失败不会因打开而消失。
|
|
|
+- [ ] 完成未读打开一次后消失,刷新后仍保持已读。
|
|
|
+- [ ] 同一 run 不会同时因会话和任务索引重复出现。
|
|
|
+- [ ] 任务索引不匹配当前项目 `thread_id` 时不进入 Inbox。
|
|
|
+- [ ] Escape 关闭面板并将焦点还给入口;点击外部也关闭。
|
|
|
+- [ ] 旧顶栏“进行中 · 待确认”重复计数已移除。
|
|
|
+- [ ] 1280/600 宽度、亮暗主题无横向溢出。
|
|
|
+- [ ] 单测、完整 E2E、App/Desktop 类型检查和构建通过。
|
|
|
+
|
|
|
+## 后续计划
|
|
|
+
|
|
|
+1. **P0-C 全局 Inbox**:跨项目聚合、项目切换跳转和任务中心统一。
|
|
|
+2. **P1 Run Inspector 2.0**:阶段、证据、成本、恢复点和子智能体参与记录。
|
|
|
+3. **P1 成果资产库**:项目级文件树、版本、比较和交付包。
|
|
|
+4. **P2 项目上下文与团队能力**:上下文包、记忆、分享和权限。
|
|
|
+
|
|
|
+## Self-Review
|
|
|
+
|
|
|
+- **Spec coverage:** 覆盖当前项目 Inbox、任务映射、去重、已读、顶栏入口、键盘关闭和验收。
|
|
|
+- **Deferred coverage:** 全局 Inbox、连接/预算提醒、平台已读同步明确留到后续计划。
|
|
|
+- **Placeholder scan:** 无 TBD、TODO、未定义函数或“按实际情况调整”的实现步骤。
|
|
|
+- **Type consistency:** `InboxItem`、`InboxKind`、`buildProjectInbox`、`inboxSeenKey` 在任务间保持一致。
|