agent-fleet/openspec/changes/dual-execution-model/tasks.md
Zer4tul e39a16498c feat: dual execution model (SSH CLI + HTTP pull)
- ExecutionMode enum: SshCli (orchestrator dispatches) | HttpPull (agent pulls)
- SSH CLI executor: spawn remote agents via ssh + CLI template
- Local subprocess as SSH special case (localhost)
- HostConfig with capability matching and load-based selection
- Dispatch loop: scan created tasks → select host → execute → update
- CliAdapterConfig: CLI templates for Codex and Claude Code
- Structured prompt construction (Issue → goal/constraints/validation)
- Output parsers: Codex JSON, Claude Code JSON, raw fallback
- TaskStatus::ReviewPending + review_count loop limit
- Forgejo webhook: pull_request (opened→review_pending, merged→completed)
- Forgejo webhook: push events (task/* branch → last_activity_at)
- HTTP API: dequeue only returns http_pull tasks
- HTTP API: status update only for http_pull mode
- Token auth config for http_pull agents
- Adapter module rewritten: AgentAdapter trait removed → config-driven CLI templates
- New fields: execution_mode, assigned_host, branch_name, pr_title, last_activity_at, review_count
- 30/30 tests pass
2026-05-12 14:07:56 +08:00

3.1 KiB
Raw Blame History

1. 数据模型扩展

  • 1.1 Task 模型新增 execution_mode 字段(ssh_cli | http_pull,默认 ssh_cli
  • 1.2 Task 模型新增 assigned_host 字段ssh_cli 模式下的目标主机 ID
  • 1.3 Task 模型新增 branch_namepr_titlelast_activity_atreview_count 字段
  • 1.4 TaskStatus 新增 review_pending 状态

2. 主机管理

  • 2.1 新增 HostConfig structhost_id, hostname, ssh_user, ssh_port, ssh_key_path, agents
  • 2.2 config.toml 新增 [[hosts]] section
  • 2.3 实现 SSH 连通性检查(ssh {host} echo ok
  • 2.4 实现 Agent CLI 可用性检查(ssh {host} which codex

3. SSH CLI 执行器

  • 3.1 创建 src/execution/mod.rs 模块
  • 3.2 实现 SshExecutor:通过 SSH 执行远程 CLI 命令,处理超时和错误
  • 3.3 实现 CliTemplate:命令模板 + 变量替换({prompt}, {work_dir}, {task_id}, {branch}
  • 3.4 实现结构化 prompt 构造Issue 内容 → 结构化 prompt目标、约束、文件范围、验证命令
  • 3.5 实现 output parser解析 Codex JSON 输出 → Receipt
  • 3.6 实现 output parser解析 Claude Code JSON 输出 → Receipt
  • 3.7 支持本地 subprocess 作为 SSH 的特例hostname = localhost 时)

4. 调度循环

  • 4.1 实现 dispatch loop扫描 created 状态的 ssh_cli 任务 → 选择主机 → SSH 执行 → 更新状态
  • 4.2 主机选择逻辑:按能力匹配 + 并发数限制 + 负载最低优先
  • 4.3 执行结果处理:成功 → assigned → running → review_pending/completed失败 → failed + retry
  • 4.4 Review 循环review_pending + PR feedback → 重新调度 → 检查 review_count ≤ max_retries

5. HTTP API 调整

  • 5.1 POST /api/v1/tasks/dequeue 仅返回 execution_mode = http_pull 的任务
  • 5.2 POST /api/v1/tasks/{task_id}/status 仅 http_pull 模式可用
  • 5.3 GET /api/v1/tasks/{task_id} 返回 execution_mode 和 assigned_host
  • 5.4 POST /api/v1/tasks/{task_id}/complete 两种模式通用
  • 5.5 Token 认证中间件(仅 http_pull 模式的 API 需要)

6. Adapter 模块重写

  • 6.1 重写 src/adapters/mod.rs:移除 AgentAdapter trait 和 AdapterRunner
  • 6.2 保留 AdapterKind,新增 CliAdapterConfigcli_template, output_format, timeout, output_parser
  • 6.3 内置 Codex 和 Claude Code 的默认 CLI 模板

7. Forgejo webhook 扩展

  • 7.1 支持 pull_request 事件opened → review_pending, merged → completed + auto receipt
  • 7.2 支持 push 事件task/* 分支 → last_activity_at 更新)

8. 测试与验证

  • 8.1 cargo check 通过
  • 8.2 cargo test 全部通过
  • 8.3 SSH executor 测试mock SSH 或本地 localhost 测试)
  • 8.4 CLI template 变量替换测试
  • 8.5 Output parser 测试Codex JSON、Claude Code JSON、malformed
  • 8.6 Prompt 构造测试
  • 8.7 主机选择逻辑测试
  • 8.8 Dispatch loop 测试ssh_cli 调度流程、http_pull 排除)
  • 8.9 Review 循环 limit 测试
  • 8.10 Forgejo PR/push webhook 测试