agent-fleet/openspec/changes/agent-fleet-platform/specs/task-router/spec.md
Zer4tul aabd52ed52 init: OpenSpec project scaffolding with proposal, design, specs, tasks
- 7 capabilities: agent-registry, task-router, receipt-protocol,
  forgejo-integration, matrix-chatops, agent-adapter, orchestrator-core
- Tech stack: Rust + axum + zigbuild (single binary)
- Forgejo as task source of truth
- Matrix as real-time ChatOps layer
- Adapter pattern for multi-agent type support
2026-05-11 14:37:43 +08:00

52 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## ADDED Requirements
### Requirement: Forgejo webhook event ingestion
Orchestrator SHALL 监听 Forgejo webhook 事件Issue 创建/更新/标签变更、PR 创建/更新/合并、Push 等),解析为内部任务事件。
#### Scenario: New issue with agent label
- **WHEN** Forgejo 上创建了新 Issue带有 `agent:code` 标签
- **THEN** Orchestrator SHALL 接收到 `issues` webhook 事件,解析为 `task.created` 事件,提取 Issue 编号、标题、描述、标签、仓库信息
#### Scenario: Issue label changed to trigger assignment
- **WHEN** Issue 的标签从 `agent:code` 变更为 `agent:review`
- **THEN** Orchestrator SHALL 生成 `task.reroute` 事件,重新匹配具备 `review` 能力的 Agent
### Requirement: Task parsing from Issue
Orchestrator SHALL 将 Issue 解析为结构化任务task_id、sourceforgejo issue URL、type由标签推断、priority由 label/milestone 推断、requirementsIssue body、labels。
#### Scenario: Issue with priority label
- **WHEN** Issue 带有 `priority:high` 标签和 `agent:code` 标签
- **THEN** 解析出的任务 SHALL 包含 `priority: "high"``type: "code"`
### Requirement: Agent matching and assignment
Task Router SHALL 根据任务类型、所需能力、Agent 负载和在线状态,将任务分配给最合适的 Agent。
#### Scenario: Match by capability and load
- **WHEN** 一个 `code:typescript` + `review` 类型的任务需要分配
- **THEN** Task Router SHALL 选择声明了对应能力、当前并发任务数未达上限、且状态为 `online` 的 Agent
#### Scenario: No matching agent available
- **WHEN** 没有在线 Agent 满足任务所需能力
- **THEN** 任务 SHALL 进入 `queued` 状态Task Router SHALL 通过 Matrix 通知人工介入
### Requirement: Task lifecycle management
任务 SHALL 具有明确的生命周期状态:`created``assigned``running``completed` / `failed` / `agent_lost`
#### Scenario: Task completes successfully
- **WHEN** Agent 通过 receipt 协议报告任务完成
- **THEN** 任务状态 SHALL 变更为 `completed`Issue 标签 SHALL 更新为 `status:done`
#### Scenario: Task fails with error
- **WHEN** Agent 报告任务失败,附带错误信息
- **THEN** 任务状态 SHALL 变更为 `failed`Issue comment SHALL 写入错误摘要Task Router SHALL 根据策略决定重试或升级
### Requirement: Manual task assignment
人类 SHALL 能通过 Matrix slash command 或 Forgejo Issue comment 手动指定任务分配给特定 Agent。
#### Scenario: Manual assignment via Matrix
- **WHEN** 人类在 Matrix 发送 `/assign @worker-03 issue#42`
- **THEN** Task Router SHALL 将 Issue #42 分配给 agent_id 为 `worker-03` 的 Agent无论自动匹配结果
#### Scenario: Manual assignment via Issue comment
- **WHEN** 人类在 Issue #42 评论 `/assign worker-03`
- **THEN** 效果同上