feat: 重构项目心跳为Redis LIST并更新相关文档

重构项目心跳数据结构为Redis LIST,更新相关文档和OpenSpec规范。主要变更包括:
- 将项目心跳从STRING改为LIST类型
- 更新后端服务以支持LIST操作
- 同步更新文档和OpenSpec规范
- 统一后端端口为3001
- 添加部署指南和Windows部署文档

修复前端API请求路径,移除硬编码的localhost地址。添加PM2和Nginx配置文件模板,完善部署流程文档。更新Redis集成协议文档,明确LIST数据结构和外部项目对接规范。
This commit is contained in:
2026-01-17 18:36:52 +08:00
parent a8faa7dcaa
commit 7ac3949dfa
40 changed files with 4179 additions and 323 deletions

View File

@@ -0,0 +1,28 @@
# Change: Store project heartbeats as Redis LIST
## Why
当前项目将 `项目心跳` 存为 Redis STRINGJSON 数组),与外部项目的写入方式和并发更新场景不匹配;同时规范、文档与实现存在漂移(例如命令下发已改为 HTTP 调用,但规范仍描述 Redis 控制队列)。
## What Changes
- **BREAKING**`项目心跳` 的 Redis 数据类型从 STRING 变更为 **LIST**
- 心跳记录以 JSON 字符串写入 LIST每条元素表示一个项目的心跳记录`{ projectName, apiBaseUrl, lastActiveAt }`
- 控制台后端按 `projectName` 去重,保留 `lastActiveAt` 最新的一条,作为项目列表/在线状态计算依据。
- 对齐 OpenSpec 与文档:明确 DB 固定为 15日志来自 `${projectName}_项目控制台`LIST命令下发通过 HTTP API 转发。
## Impact
- Affected specs: redis-connection, logging, command
- Affected code:
- src/backend/services/migrateHeartbeatData.js
- src/backend/routes/projects.js
- src/backend/routes/logs.js
- src/backend/routes/commands.js
- src/backend/server.js
- Affected docs:
- docs/redis-integration-protocol.md
- docs/redis-data-structure.md
- docs/openapi.yaml
- README.md

View File

@@ -0,0 +1,12 @@
## MODIFIED Requirements
### Requirement: Command Sending to Redis
The system SHALL send commands to a target project's HTTP API.
#### Scenario: Sending a command to target project API
- **WHEN** the user enters a command in the console
- **AND** clicks the "Send" button
- **THEN** the backend SHALL resolve `apiBaseUrl` from the project's heartbeat
- **AND** it SHALL call `POST {apiBaseUrl}/{apiName}` with a structured payload
- **AND** the user SHALL receive a success confirmation if upstream returns 2xx

View File

@@ -0,0 +1,10 @@
## MODIFIED Requirements
### Requirement: Log Reading from Redis
The system SHALL read log records from a Redis LIST `${projectName}_项目控制台`.
#### Scenario: Reading logs by polling
- **WHEN** the user is viewing a project console
- **THEN** the system SHALL read the latest log entries via `LRANGE`
- **AND** it SHALL return logs in a user-friendly structure

View File

@@ -0,0 +1,21 @@
## MODIFIED Requirements
### Requirement: Redis Connection Configuration
The system SHALL allow configuration of Redis connection parameters.
#### Scenario: Configuring Redis connection via environment variables
- **WHEN** the server starts with Redis environment variables set
- **THEN** it SHALL use those variables to configure the Redis connection
- **AND** it SHALL use Redis database 15
## ADDED Requirements
### Requirement: Project Heartbeat List Retrieval
The system SHALL read project heartbeats from Redis key `项目心跳` stored as a LIST.
#### Scenario: Reading projects list from Redis LIST
- **WHEN** the client requests the projects list
- **THEN** the system SHALL read `LRANGE 项目心跳 0 -1`
- **AND** it SHALL parse each list element as JSON heartbeat record
- **AND** it SHALL deduplicate by `projectName` and keep the latest `lastActiveAt`

View File

@@ -0,0 +1,9 @@
## 1. Implementation
- [ ] 1.1 Update OpenSpec specs for redis-connection/logging/command
- [ ] 1.2 Update backend to read `项目心跳` as Redis LIST and dedupe projects
- [ ] 1.3 Update backend to write migrated heartbeats into LIST
- [ ] 1.4 Align backend port with Vite proxy/OpenAPI (default 3001)
- [ ] 1.5 Update docs to match new Redis protocol and current behavior
- [ ] 1.6 Update tests and validate with `npm test`