docs: 整理文档目录结构 — 清理过时文档、归集功能子目录、统一命名规范

清理:
- 删除 34 份过时文档(gap reports/QA临时报告/验收报告/阶段性文档)
- 删除 docs/.hermes/skills 第三方 skills 副本(16 文件)
- 删除 skills-lock.json

目录归集:
- 根目录仅保留 README.md 索引
- product/ — 产品与架构设计(PRD + ARCHITECTURE + P2设计文档 + AI/企业路线图)
- tracking/ — Chatwoot parity 开发跟踪
- requirements/ — M01-M12 模块需求
- plans/ — 历史实现计划
- parity/ — 路由 parity 与前端契约
- qa/ — QA 报告与测试计划
- ops/ — 运维部署

命名规范:
- 全小写 kebab-case,禁止全大写文件名
- product/tracking/ops 用 NN- 序号前缀
- requirements 用 MNN- 两位零填充模块号
- plans/qa 用 YYYY-MM-DD- 日期前缀
- requirements M1-M9 零填充为 M01-M09(修复字典序)

同步更新:
- backend/cmd/route_parity/main.go 路径默认值
- backend/scripts/parity_frontend_smoke.sh 报告路径
- 所有 docs 内部交叉引用
- .gitignore 排除编译产物 (backend/gochat, backend/route_parity)
- 新增迁移 000052/000053
- 前端 WS 相关修改
This commit is contained in:
2026-07-09 14:53:27 +08:00
parent 805402f938
commit 0dabb8cfa5
136 changed files with 1240 additions and 14484 deletions
+34 -5
View File
@@ -36,13 +36,19 @@ type Handler struct {
// The authenticator provides both JWT (agent) and pubsub_token (contact) auth paths.
func NewHandler(hub *Hub, authenticator *wspkg.WSAuthenticator) *Handler {
return &Handler{
hub: hub,
hub: hub,
authenticator: authenticator,
upgrader: websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
// Allow all origins — CORS is handled at the Gin middleware layer
CheckOrigin: func(r *http.Request) bool { return true },
// ActionCable clients send Sec-WebSocket-Protocol: actioncable-v1-json.
// If the server doesn't echo back a supported subprotocol, the JS
// client immediately closes the connection ("Protocol is unsupported")
// and enters a reconnect loop. gorilla/websocket picks the first
// requested protocol listed here that the client also offered.
Subprotocols: []string{"actioncable-v1-json"},
},
}
}
@@ -91,6 +97,12 @@ func (h *Handler) ServeWS(c *gin.Context) {
logger.L().Infof("ws: connection established (user=%d, account=%d, is_contact=%v)", claims.UserID, claims.AccountID, claims.IsContact)
// Send ActionCable welcome frame — the JS client expects this immediately
// after upgrade. Without it the client's ConnectionMonitor considers the
// connection stale and enters a reconnect loop.
welcomeData, _ := json.Marshal(WelcomeFrame{Type: ServerWelcome})
client.Send <- welcomeData
// Start pumps in separate goroutines
go h.writePump(client)
go h.readPump(client)
@@ -144,6 +156,11 @@ func (h *Handler) readPump(client *Client) {
h.handleUnsubscribe(client, cmd)
case CommandPing:
h.handlePing(client)
case CommandMessage:
// ActionCable "message" command — client performs a channel action
// (e.g. update_presence). We acknowledge but don't require a
// specific handler for presence yet.
logger.L().Debugf("ws: message command from user=%d, data=%s", client.UserID, cmd.Data)
default:
logger.L().Warnf("ws: unknown command '%s' from user=%d", cmd.Command, client.UserID)
}
@@ -177,9 +194,15 @@ func (h *Handler) writePump(client *Client) {
}
case <-ticker.C:
// Send ping frame for heartbeat
// Send ActionCable-level ping message (JSON text frame).
// The JS ConnectionMonitor expects periodic ping messages to
// keep the connection alive (staleThreshold = 6s by default).
pingMsg, _ := json.Marshal(PingFrame{
Type: ServerPing,
Message: time.Now().UTC().Format(time.RFC3339),
})
client.Conn.SetWriteDeadline(time.Now().Add(WriteWait))
if err := client.Conn.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
if err := client.Conn.WriteMessage(websocket.TextMessage, pingMsg); err != nil {
logger.L().Errorf("ws: ping write failed for user=%d: %v", client.UserID, err)
return
}
@@ -217,7 +240,9 @@ func (h *Handler) handleSubscribe(client *Client, cmd CommandFrame) {
// Determine room name based on channel type (uses Hub's canonical naming)
room := ""
switch identifier.Channel {
case ChannelAccount:
case ChannelAccount, ChannelRoom:
// RoomChannel is Chatwoot's single-subscription model — it maps
// to the account room (all account-level events are delivered).
room = accountRoomName(identifier.AccountID)
case ChannelConversation:
if identifier.ConversationID == 0 {
@@ -243,6 +268,10 @@ func (h *Handler) handleSubscribe(client *Client, cmd CommandFrame) {
// Subscribe the client to the room
client.Subscribe(room)
// Store the ActionCable subscription identifier on the client so that
// event frames can be wrapped with it for correct client-side routing.
client.Identifier = cmd.Identifier
// Send confirmation frame
confirmData, _ := json.Marshal(ConfirmFrame{
Type: ServerConfirmSubscribe,
@@ -262,7 +291,7 @@ func (h *Handler) handleUnsubscribe(client *Client, cmd CommandFrame) {
// Determine room name (uses Hub's canonical naming)
room := ""
switch identifier.Channel {
case ChannelAccount:
case ChannelAccount, ChannelRoom:
room = accountRoomName(identifier.AccountID)
case ChannelConversation:
room = conversationRoomName(identifier.AccountID, identifier.ConversationID)