feat: 重构项目心跳数据结构并实现项目列表API

- 新增统一项目列表Redis键和迁移工具
- 实现GET /api/projects端点获取项目列表
- 实现POST /api/projects/migrate端点支持数据迁移
- 更新前端ProjectSelector组件使用真实项目数据
- 扩展projectStore状态管理
- 更新相关文档和OpenSpec规范
- 添加测试用例验证新功能
This commit is contained in:
2026-01-13 19:45:05 +08:00
parent 19e65d78dc
commit 282f7268ed
66 changed files with 4378 additions and 456 deletions

View File

@@ -1,13 +1,16 @@
# Change: Update Redis Integration Protocol
## Why
需要为“BLS Project Console ↔ 其他业务项目”的 Redis 交互约定一个稳定、可机器生成的协议,明确每个接入项目必须写入的状态与控制台信息,以及必须读取的控制指令队列。
## What Changes
- 统一 Redis Key 命名规则:每个项目写 2 个 key、读 1 个 key
- 明确每个 key 的 Redis 数据类型STRING/LIST与 value 格式(枚举值/JSON
- 对齐 logging / command / redis-connection 三个 capability 的 requirements以便实现端可依据 spec 开发)
## Impact
- Affected specs: specs/redis-connection/spec.md, specs/logging/spec.md, specs/command/spec.md
- Affected code (planned): src/backend/routes/, src/backend/services/, src/frontend/components/

View File

@@ -1,14 +1,17 @@
## MODIFIED Requirements
### Requirement: Command Sending to Redis
The system SHALL send commands to a per-target Redis key.
#### Scenario: Console enqueues a command for a target project
- **WHEN** the user sends a command from the console
- **THEN** the backend SHALL append a JSON message to Redis LIST key `${targetProjectName}_控制`
- **AND** the JSON message SHALL represent the command payload (an object)
#### Scenario: Target project consumes a command
- **WHEN** a target project listens for commands
- **THEN** it SHALL consume messages from `${projectName}_控制` as JSON objects
- **AND** it SHOULD use Redis LIST queue semantics (producer `RPUSH`, consumer `BLPOP`)

View File

@@ -1,14 +1,17 @@
## MODIFIED Requirements
### Requirement: Log Reading from Redis
The system SHALL read log records from per-project Redis keys.
#### Scenario: External project writes console logs
- **WHEN** an external project emits debug/error information
- **THEN** it SHALL append entries to a Redis LIST key named `${projectName}_项目控制台`
- **AND** each entry SHALL be a JSON string representing a log record
#### Scenario: Server reads project console logs
- **WHEN** the server is configured to show a given project
- **THEN** it SHALL read entries from `${projectName}_项目控制台`
- **AND** it SHALL present them in the console UI with timestamp, level and message

View File

@@ -1,9 +1,11 @@
## ADDED Requirements
### Requirement: Per-Project Status Key
The system SHALL standardize a per-project Redis status key for connected projects.
### Requirement: Per-Project Heartbeat Key
The system SHALL standardize a per-project Redis heartbeat key for connected projects.
#### Scenario: External project writes heartbeat
#### Scenario: External project writes status
- **WHEN** an external project integrates with this console
- **THEN** it SHALL write a Redis STRING key named `${projectName}_项目状态`
- **AND** the value SHALL be one of: `在线`, `离线`, `故障`, `报错`
- **THEN** it SHALL write a Redis STRING key named `${projectName}_项目心跳`
- **AND** the value SHALL be a JSON string containing `apiBaseUrl` and `lastActiveAt`

View File

@@ -1,13 +1,16 @@
## 1. Documentation
- [x] 1.1 Add Redis integration protocol doc for external projects
- [ ] 1.2 Link doc location from README (optional)
## 2. Backend
- [x] 2.1 Add Redis client config + connection helper
- [x] 2.2 Implement command enqueue: write `${targetProjectName}_控制` LIST with JSON payload
- [x] 2.3 Implement log fetch/stream: read `${projectName}_项目控制台` LIST (and status `${projectName}_项目状态` STRING when needed)
- [x] 2.3 Implement log fetch/stream: read `${projectName}_项目控制台` LIST
## 3. Frontend
- [x] 3.1 Wire selected project name into Console (targetProjectName)
- [x] 3.2 Replace simulated command send with API call to backend
- [x] 3.3 Replace simulated logs with backend-provided logs (polling or SSE)