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

@@ -0,0 +1,66 @@
## MODIFIED Requirements
### Requirement: Command Sending
The system SHALL send console commands to a target project via HTTP API calls (not via Redis control queues).
#### Scenario: Sending a command to a target project API
- **WHEN** the user enters a command line in the console
- **AND** the command line contains at least one token
- **THEN** the system SHALL treat the first token as `apiName`
- **AND** the system SHALL treat remaining tokens as arguments
- **AND** the backend SHALL invoke the target project's HTTP endpoint derived from `apiName`
- **AND** the user SHALL receive a success confirmation if the target project returns a successful response
#### Scenario: Rejecting an empty command
- **WHEN** the user tries to send an empty command line
- **THEN** the system SHALL display an error message
- **AND** the backend SHALL NOT attempt any outbound call
### Requirement: Target Routing
The system SHALL route outbound calls by `targetProjectName` using the target project's Redis heartbeat info.
#### Scenario: Target project is not configured
- **WHEN** the user sends a command to a target project
- **AND** the backend cannot resolve `apiBaseUrl` from the target project's heartbeat
- **THEN** the backend SHALL return an error response
- **AND** the outbound call SHALL NOT be attempted
#### Scenario: Target project is offline
- **WHEN** the user sends a command to a target project
- **AND** the last heartbeat update is older than 10 seconds
- **THEN** the backend SHALL treat the target project as offline
- **AND** the outbound call SHALL NOT be attempted
### Requirement: Error Handling
The system SHALL handle target API failures gracefully.
#### Scenario: Target API is unreachable or times out
- **WHEN** the backend invokes the target project API
- **AND** the target project cannot be reached or times out
- **THEN** the backend SHALL return a failure response to the frontend
#### Scenario: Target API returns a non-success status
- **WHEN** the target project returns a non-2xx HTTP status
- **THEN** the backend SHALL return a failure response
- **AND** it SHOULD include the upstream status and message for debugging
## REMOVED Requirements
### Requirement: Command Sending to Redis
**Reason**: Command control channel is migrated to HTTP API calls.
**Migration**: Target projects must expose HTTP endpoints; they no longer consume `${projectName}_控制`.
### Requirement: Command Response Handling from Redis
**Reason**: Responses are returned directly via HTTP responses.
**Migration**: Any additional async responses should be written to the project's console/log channel (e.g., Redis console log LIST) if needed.