merge: 集成V2.7 企业协作与管理治理

# Conflicts:
#	apps/server/src/app.module.ts
#	apps/web/components/layout/Sidebar.tsx
#	apps/web/lib/permissions.ts
#	docs/architecture.md
#	docs/decisions.md
#	docs/roadmap.md
This commit is contained in:
2026-07-08 18:10:08 +08:00
60 changed files with 3219 additions and 19 deletions

View File

@@ -351,3 +351,22 @@ Current source-of-truth boundary:
- V2.2 read APIs and V2.3 relation sync remain compatibility infrastructure for fast reads, historical AppData imports, and rollback. They are no longer the main proof of data freshness for domains that now write relation tables directly.
- `packages/shared` status contracts have been aligned with the current workflow statuses before the V2.4 write switch.
- V2.5 boundary: audit/RBAC/consistency are active on domain writes. Xiaobao risk snapshots/insights and warning read-state AppData keys are read-only archives pending V2.6 relation writer/backgrounding and V2.7 per-user read-state API.
## V2.7 Enterprise Collaboration And Governance Layer (2026-07-08)
V2.7 adds enterprise collaboration capabilities on top of the relational source-of-truth direction. New collaboration data does not add AppData keys:
- `notifications`: per-recipient notification records with stable event types `assignment / mention / risk_alert / overdue_item`.
- `comments`: polymorphic comments for `dev_task / test_case / bug / requirement / version_plan`, with mention metadata and soft deletion.
- `project_members`: project-level Owner/Admin/Member/Viewer governance, now exposed through server-enforced APIs.
- `audit_logs`: append-only governance and collaboration audit events.
- `governance_dictionaries`: centralized requirement type/platform/source dictionaries; task categories continue to use `task_categories`.
V2.7 uses stable server adapters for collaboration and governance modules:
- `RbacService`: project role and global permission assertion adapter. Feature modules call this instead of hard-coding permission checks, while V2.5 `PermissionGuard` / `@ProtectedMutation()` continue to protect existing domain mutation controllers.
- `AuditService`: append-only collaboration/governance audit adapter. Feature modules call this instead of writing ad-hoc audit records; V2.5 `audit_events` remains the cross-domain mutation audit control plane.
When the later JWT/NextAuth server verification replaces the current header auth adapter, global permission sourcing should be swapped behind these auth/RBAC adapters; feature modules should keep depending on the adapter boundary.
Management overview reads only relation tables and summaries. It intentionally avoids AppData so it reflects the target backend boundary rather than the compatibility document store.

View File

@@ -680,3 +680,17 @@
- 前端 `/admin/ops` 使用 `RouteGuard permission="ops:view"`;权限字典新增 `ops:view`,但不默认授给非管理员 preset。后端通过 `OpsPermissionAdapter` 保留 `ops:view` 校验入口,待 V2.5 RBAC guard 落地后替换。
**理由**:当前目标是让 V2.6 的性能和后台化能力可观察,而不是建设完整监控平台。进程内 ring buffer 成本低、对生产数据无额外写放大;结合脱敏规则可避免把 secrets 带进管理端。权限 adapter 明确了未来替换点,避免 Ops 看板和未定型 RBAC/audit 合同互相绑死。
## 52. V2.7 协作治理先落稳定适配器,不硬编码临时权限
**问题**V2.7 需要通知、评论、项目成员治理、管理驾驶舱和治理字典。如果各 V2.7 模块直接写临时权限判断和审计插入,就会绕开 V2.5 已落地的服务端权限、审计和资源作用域边界,后续认证治理也会再次返工。
**决策**
- 新增 `RbacService` 作为项目角色与全局权限断言适配器Owner/Admin/Member/Viewer 的层级判断和 `management:view` / `governance:manage` 等全局权限入口集中在此处。
- 新增 `AuditService` 作为审计写入适配器,业务模块只提交 `actorId/action/resource/before/after`
- 通知事件类型固定为 `assignment / mention / risk_alert / overdue_item`,跨模块通过这些稳定语义发通知。
- 通用评论使用 `entityType + entityId + entityVersionId` 的多态引用,不给每个业务表单独建评论表。
- 管理驾驶舱只读关系表和 `xiaobao_risk_summaries`,不回读 AppData。
- 治理字典使用软删除或使用中禁止硬删,变更必须写审计。
**理由**:适配器把协作治理模块的权限和审计接入点收束在一层,既能复用 V2.5 的服务端控制面,也给后续 JWT/NextAuth 和企业级角色体系留下替换点。稳定事件名和多态评论引用能避免后续模块继续扩散 ad-hoc 字段。

View File

@@ -1,6 +1,16 @@
# 开发路线图
## 当前阶段V2.6 已完成 — 下一阶段 V2.7 企业协作 + V2.8 运维闭环集成
## 当前阶段V2.7 已完成 — 下一阶段 V2.8 生产硬化与运维闭环集成
V2.7 已在关系表主源方向上补齐企业协作和治理能力:通知、评论与提及、项目成员治理、管理驾驶舱、治理字典、以及统一 RBAC/audit 适配器。V2.7 不新增 AppData 主存储。
### 当前重点
1. **协作通知**通知记录、已读状态、NotificationBell并覆盖 assignment / mention / risk_alert / overdue_item 稳定事件类型。
2. **通用评论**DevTask/TestCase/Bug/Requirement/VersionPlan 统一评论面板,支持 `@成员名` 和显式成员选择,创建/删除写 audit。
3. **项目成员治理**Owner/Admin/Member/Viewer 服务端强校验,禁止移除最后 Owner角色变更写 audit。
4. **管理驾驶舱**:只读关系表和 summary聚合活跃版本、逾期、阻塞、风险和成员负载。
5. **治理设置**:集中维护 task category、requirement type/platform/source使用中的字典不可硬删支持导入导出。
V2.4 已将高增长和核心业务领域从“AppData 主写 + 关系表同步副本”推进到“领域 CRUD 主写关系表 + AppData 兼容/迁移兜底”。V2.2 快读 API 和 V2.3 AppData 写后同步继续保留,但它们现在是兼容基础设施,不再是已迁移领域的数据新鲜度主链路。
@@ -8,7 +18,9 @@ V2.5 的目标是正式收口后端权限、审计、AppData 禁写和一致性
V2.6 的目标是在关系表主源稳定后完成大数据性能增强、小宝风险后台化、AI 解读队列和运行时 Ops 看板,让高增长热路径、后台任务和风险摘要不再依赖页面打开。
### V2.5-V2.6 完成范围
V2.8 的目标是在现有生产部署基线上补齐备份恢复演练、发布 smoke test、监控告警、日志检索、迁移回滚和运维手册形成生产交付稳定版。
### V2.5-V2.7 完成范围
1. **RBAC 收口**:领域 mutation API 已接入服务端权限校验、资源作用域和当前用户上下文。
2. **审计事件**:领域 mutation 通过 `audit_events` 写 append-only audit event支持后台查询和敏感字段脱敏。
@@ -20,6 +32,11 @@ V2.6 的目标是在关系表主源稳定后完成大数据性能增强、小宝
8. **后台任务运行时**:已补 PostgreSQL-backed `background_jobs`、dedupe、lease、retry、失败记录和单步 worker。
9. **小宝后台化**:已补服务端 summary refresh、dirty/enqueue 桥接和 `xiaobao.ai.interpret` AI 解读队列。
10. **Ops 看板**:已补 `/admin/ops``GET /api/v1/ops/runtime`展示慢请求、慢查询、job 队列和 dirty summary 数。
11. **协作通知**:已补通知记录、已读状态和 `NotificationBell`,覆盖 assignment / mention / risk_alert / overdue_item 稳定事件类型。
12. **通用评论**DevTask/TestCase/Bug/Requirement/VersionPlan 已接入统一评论面板,支持 `@成员名`、显式成员选择、删除和审计。
13. **项目成员治理**:已补项目成员 Owner/Admin/Member/Viewer 服务端治理,禁止移除最后 Owner角色变更写审计。
14. **管理驾驶舱**:已补只读关系表和 summary 的管理概览,聚合活跃版本、逾期、阻塞、风险和成员负载。
15. **治理设置**:已补 task category、requirement type/platform/source 等治理字典能力,使用中的字典不可硬删,支持导入导出。
## V2 分阶段交付链路
@@ -54,10 +71,20 @@ V2.6 的目标是在关系表主源稳定后完成大数据性能增强、小宝
- V2.6.4 已新增服务端小宝风险 summary refresh、后台 job handler以及领域写入 dirty/enqueue 桥接。
- V2.6.5 已新增服务端小宝 AI 解读队列summary 刷新后按 signature/cooldown/escalation policy 入队,只写 `xiaobao_risk_insights` 缓存。
- V2.6.6 已新增 `/admin/ops` 运行时看板和 `GET /api/v1/ops/runtime`展示慢请求、慢查询、job 队列和 dirty summary 数。
- V2.7.1 已新增通知和已读状态,前端 `NotificationBell` 可展示 assignment / mention / risk_alert / overdue_item。
- V2.7.2 已新增通用评论和提及能力,覆盖 DevTask/TestCase/Bug/Requirement/VersionPlan。
- V2.7.3 已新增项目成员治理 API 和项目页成员面板,服务端强校验 Owner/Admin/Member/Viewer 边界。
- V2.7.4 已新增管理驾驶舱和治理设置,聚合关系表指标并维护治理字典。
- V2.7.5 已新增协作治理 RBAC/audit adapter避免新增模块绕开服务端权限和审计边界。
### 已完成(按时间倒序)
**2026-07-08**
- V2.7.5 added shared collaboration/governance RBAC and audit adapters so notification, comment, project-member, management, and governance modules keep a single permission/audit boundary.
- V2.7.4 added management and governance admin pages for relation-backed overview metrics and dictionary governance.
- V2.7.3 added project-member governance APIs and project member panel with Owner/Admin/Member/Viewer safeguards.
- V2.7.2 added polymorphic comments, mention parsing, and comment panels for core work entities.
- V2.7.1 added notification records, read-state APIs, frontend notification store, and `NotificationBell`.
- V2.6.6 added the Ops runtime dashboard with `ops:view`, redacted slow request/query buffers, background job queue summary, failed job list, and dirty Xiaobao summary count.
- V2.6.5 moved Xiaobao AI interpretation behind the background job runtime, reusing `AiService.interpretRisk()` and writing only insight cache rows.
- V2.6.4 moved deterministic Xiaobao risk summary refresh into the server, registered the `xiaobao.summary.refresh` background job handler, and enqueue refresh jobs from dirty domain writes.
@@ -161,12 +188,12 @@ V2.6 的目标是在关系表主源稳定后完成大数据性能增强、小宝
### 进行中
- V2.6 大数据性能增强与小宝预警后台化压测、慢查询治理、后台任务、Xiaobao relation writer、幂等与失败重试
- V2.8 生产硬化与运维闭环:备份恢复演练、发布 smoke test、监控告警、日志检索、迁移回滚和运维手册
- 项目详情页 VersionCard 状态胶囊数据联动(部分已完成)
## V2 — 后端接入
NestJS + Prisma + PostgreSQL 已推进到 V2.5。第一阶段用 `app_data` JSONB 文档表承接现有 store 数据形状避免浏览器清站点数据导致业务数据丢失第二阶段建立分区关系表、V2.2 快读 API 和 V2.3 AppData 写后同步;第三阶段 V2.4 已逐领域启用写 API让前端 store 从 AppData 主写入迁移到领域 CRUD 主写;第四阶段 V2.5 已冻结 AppData 业务写入并收口服务端 RBAC、审计和一致性校验。
NestJS + Prisma + PostgreSQL 已推进到 V2.7。第一阶段用 `app_data` JSONB 文档表承接现有 store 数据形状避免浏览器清站点数据导致业务数据丢失第二阶段建立分区关系表、V2.2 快读 API 和 V2.3 AppData 写后同步;第三阶段 V2.4 已逐领域启用写 API让前端 store 从 AppData 主写入迁移到领域 CRUD 主写;第四阶段 V2.5 已冻结 AppData 业务写入并收口服务端 RBAC、审计和一致性校验;第五阶段 V2.6 已完成大数据性能和小宝后台化;第六阶段 V2.7 已补齐协作治理能力
### 关键任务
@@ -178,7 +205,7 @@ NestJS + Prisma + PostgreSQL 已推进到 V2.5。第一阶段用 `app_data` JSON
6. **基础权限/审计骨架**:领域 API 从迁移期开始接入用户身份、资源作用域、操作人和审计事件入口V2.5 已收口)
7. **AppData 主路径移除**:业务写入已冻结;后续按核对结果逐模块删除 JSON fallback 和 `/data/:key` 依赖
8. **认证**:当前为 V2.5 header auth adapter正式 NextAuth.js + JWT 服务端校验待后续治理
9. **权限**RBACOwner/Admin/Member/Viewer按项目/版本级别V2.5 服务端 guard 已启用,企业级配置表待 V2.7
9. **权限**RBACOwner/Admin/Member/Viewer按项目/版本级别V2.5 服务端 guard 已启用,V2.7 项目成员治理和企业级配置已补齐
10. **版本规则引擎收敛**VersionPlan 完成条件、关联需求候选、TaskCategory 语义码、TestCase.categoryId 统一收束到规则层
### 数据迁移策略
@@ -279,6 +306,6 @@ V2.5 完成后的保留边界:`GET /api/v1/data/:key` 仍可读历史 JSONX
|------|------|
| V1 业务流程打磨 | 进行中 |
| V1 朋友试用反馈 | 持续中 |
| V2 后端接入 | 进行中V2.5 RBAC/审计/AppData 退场已完成V2.6/V2.7 待推进 |
| V2 后端接入 | 进行中V2.7 已完成V2.8 生产硬化与运维闭环待集成 |
| V3 AI 集成 | 等 V2 数据沉淀 |
| 公开发布 | TBD |

View File

@@ -345,6 +345,21 @@ AI 解读不由人工按钮触发。服务端 summary 刷新后按 policy 排入
静默风险包括长期无更新、无日报、无活动、进行中事项无人处理等信号。日报和工作活动是风险解释的重要证据,必须进入 AI 解读输入。
## V2.7 协作治理工作流
通知统一进入 `notifications` 关系表,事件类型固定为:
- `assignment`:负责人或处理人被分配工作。
- `mention`:评论中 `@成员名` 或显式选择成员。
- `risk_alert`:小宝预警保存高风险快照后提醒管理者。
- `overdue_item`:逾期事项提醒。
评论统一使用 `CommentPanel`,支持 DevTask、TestCase、Bug、Requirement 和 VersionPlan。创建/删除评论必须写 audit提及成员必须生成 mention 通知。
项目成员治理走 `/projects/:projectId/members` 服务端接口。角色为 Owner/Admin/Member/ViewerOwner/Admin 可管理成员;服务端禁止移除或降级最后一个 Owner。版本成员可见性继续兼容旧 `version.members` 展示,但治理来源应逐步收敛到 ProjectMember。
管理驾驶舱 `/admin/management` 只查关系表和小宝 summary不读取 AppData并通过 RBAC adapter 校验 `management:view`。治理设置 `/admin/governance` 集中维护任务类型与需求字典;使用中的字典不可硬删,字典变更必须写 audit并通过 RBAC adapter 校验 `governance:manage`
## 日期选择与计划时间
- 调研、产品方案、UI 设计、开发任务、测试用例、Bug 创建时使用统一工作日日期时间选择器。