Skip to content

Commit fc8f6b7

Browse files
committed
feat(plugins): implement core plugin nodes (flow/sleep, http/request, file/transfer)
- Add flow/sleep node for workflow delay control with context cancellation support - Add http/request node for REST API integration with auto-JSON handling and retry logic - Add file/transfer node for secure SFTP/SCP file operations - Implement comprehensive Node interface with metadata, validation, and error classification - Add validator with ParamSpec validation for type, pattern, enum, and range checks - Update plugin manager to support dynamically loaded plugin nodes - Add plugin development examples (echo, template) with tests - Add 60+ unit tests and integration tests achieving high coverage - Document node development guide and reference documentation Implementation highlights: - All nodes follow standardized Node interface pattern - Built-in Temporal error classification for smart retry behavior - Complete input validation with detailed error messages - Comprehensive test coverage (unit + integration) - Production-ready with proper error handling and logging - Refactor validator to reduce complexity (split into smaller functions)
1 parent ccaeaaf commit fc8f6b7

61 files changed

Lines changed: 15616 additions & 124 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent

-29.1 MB
Binary file not shown.

docs/adr/0003-plugin-based-node-system.md

Lines changed: 353 additions & 35 deletions
Large diffs are not rendered by default.

docs/architecture.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,72 @@ func (pm *PluginManager) LoadPlugin(path string) error {
409409
- 根据 `uses` 字段查找节点
410410
- 提供节点元数据
411411

412-
**接口:**
412+
**完整接口 (Story 3.1):**
413413
```go
414+
// 核心节点接口 - 所有自定义节点必须实现
415+
type Node interface {
416+
// 基础信息 (Story 1.3)
417+
Name() string
418+
Version() string
419+
Params() map[string]ParamSpec
420+
421+
// 执行和元数据 (Story 3.1)
422+
Execute(ctx context.Context, inputs map[string]interface{}) (*NodeResult, error)
423+
Metadata() NodeMetadata
424+
}
425+
426+
// 节点注册表接口
414427
type NodeRegistry interface {
415428
Register(node Node) error
416429
Get(nodeType string) (Node, error)
417430
List() []NodeMetadata
418431
}
419432

420-
type Node interface {
421-
Execute(ctx context.Context, args map[string]interface{}) (NodeResult, error)
433+
// 执行结果结构
434+
type NodeResult struct {
435+
Outputs map[string]interface{} // 输出数据
436+
Logs []string // 执行日志
437+
Duration time.Duration // 执行耗时
438+
Metadata map[string]interface{} // 扩展元数据
439+
}
440+
441+
// 节点元数据(用于文档和验证)
442+
type NodeMetadata struct {
443+
Description string // 节点描述
444+
Category string // 分类 (exec/docker/http/file/flow)
445+
InputSchema map[string]ParamSpec // 输入参数 Schema
446+
OutputSchema map[string]interface{} // 输出结构定义
447+
}
448+
449+
// 参数规格(支持高级验证)
450+
type ParamSpec struct {
451+
Type string // 参数类型
452+
Required bool // 是否必需
453+
Description string // 参数说明
454+
Default interface{} // 默认值
455+
Pattern string // 正则表达式验证
456+
Enum []interface{} // 枚举值验证
457+
MinValue *float64 // 最小值(数值类型)
458+
MaxValue *float64 // 最大值(数值类型)
422459
}
423460
```
424461

462+
**插件注册:**
463+
```go
464+
// 插件必须导出的注册函数
465+
type RegisterFunc func() Node
466+
467+
// 插件示例
468+
func Register() Node {
469+
return &CheckoutNode{}
470+
}
471+
```
472+
473+
**关键决策:**
474+
- [ADR-0003: 插件化节点系统](adr/0003-plugin-based-node-system.md)
475+
- Story 1.3: 节点注册表实现
476+
- Story 3.1: 节点接口扩展
477+
425478
#### 3.2.4 Workflow Handlers
426479

427480
**职责:**

docs/epics.md

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,15 +1031,15 @@ So that **快速在服务器上部署 Agent**。
10311031

10321032
## Epic 3: 核心节点插件库
10331033

1034-
用户可以使用 8 个核心节点构建实用的工作流,覆盖 Shell 操作、文件传输、HTTP 请求、Docker 管理等常见场景。所有节点都编译为 .so 插件,通过 Agent 启动时自动加载 (ADR-0003 插件化节点系统)。控制流(条件、循环)由 DSL 原生支持 (if 条件、matrix 并行)。
1034+
用户可以使用 7 个核心节点构建实用的工作流,覆盖 Shell 操作、文件传输、HTTP 请求、Docker 管理等常见场景。所有节点都编译为 .so 插件,通过 Agent 启动时自动加载 (ADR-0003 插件化节点系统)。控制流(条件、循环)由 DSL 原生支持 (if 条件、matrix 并行)。
10351035

10361036
**FRs covered:** FR12
10371037

10381038
**关键架构特性:**
10391039
- 插件化节点系统: 所有节点编译为 Go Plugin (.so 文件)
10401040
- 自动加载: Agent 启动时扫描 /opt/waterflow/plugins/ 目录
10411041
- 统一接口: 所有节点实现 Node 接口 (Execute, Metadata, Schema)
1042-
- 8个核心节点: shell, script, sleep, file/transfer, http/request, docker/exec, docker/compose-up, docker/compose-down
1042+
- 7个核心节点: shell, script, sleep, file/transfer, http/request, docker/exec, docker/compose
10431043

10441044
### Story 3.1: 节点接口设计 (插件化接口)
10451045

@@ -1163,53 +1163,84 @@ So that **管理容器和镜像**。
11631163
**And** Docker 未安装时返回明确错误
11641164
**And** 支持常用命令: run, ps, stop, rm, images, pull
11651165

1166-
### Story 3.8: Docker Compose Up 节点
1166+
### Story 3.8: Docker Compose 节点
11671167

11681168
As a **工作流用户**,
1169-
I want **启动 Docker Compose **,
1170-
So that **部署多容器应用**
1169+
I want **管理 Docker Compose 栈的完整生命周期**,
1170+
So that **部署和清理多容器应用**
11711171

11721172
**Acceptance Criteria:**
11731173

1174+
**Docker Compose Up 操作:**
11741175
**Given** Agent 服务器有 docker-compose 文件
1175-
**When** Step 使用 `docker/compose-up` 节点
1176+
**When** Step 使用 `docker/compose` 节点配置 `action: up`
11761177
**Then** 执行 docker-compose up
1177-
**And** 支持参数: file, project_name, detach, build
1178+
**And** 节点编译为 docker-compose.so 插件,Agent 启动时自动加载
1179+
**And** 支持参数: action (up/down), file, project_name, detach, build
11781180
**And** 等待所有服务启动完成
11791181
**And** 捕获启动日志
1180-
**And** 健康检查验证服务可用
1181-
1182-
### Story 3.9: Docker Compose Down 节点
1183-
1184-
As a **工作流用户**,
1185-
I want **停止 Docker Compose 栈**,
1186-
So that **清理部署的应用**
1187-
1188-
**Acceptance Criteria:**
1182+
**And** 健康检查验证服务可用
1183+
**And** 返回输出: 已启动的容器列表, 服务状态
11891184

1185+
**Docker Compose Down 操作:**
11901186
**Given** Docker Compose 栈正在运行
1191-
**When** Step 使用 `docker/compose-down` 节点
1187+
**When** Step 使用 `docker/compose` 节点配置 `action: down`
11921188
**Then** 执行 docker-compose down
1193-
**And** 支持参数: file, project_name, volumes, rmi
1189+
**And** 支持参数: action (down), file, project_name, volumes, rmi (none/local/all)
11941190
**And** 等待所有容器停止
11951191
**And** 可选删除 volumes 和镜像
1196-
**And** 捕获停止日志
1197-
1198-
### Story 3.10: 节点参考文档
1192+
**And** 捕获停止日志
1193+
**And** 返回输出: 已停止的容器列表, 清理摘要
1194+
1195+
**通用特性:**
1196+
**Given** 使用 docker/compose 节点
1197+
**When** 执行任何操作
1198+
**Then** 自动检测 docker-compose 是否已安装
1199+
**And** docker-compose 未安装时返回明确错误
1200+
**And** 支持自定义工作目录
1201+
**And** 支持环境变量注入
1202+
**And** 操作超时时自动终止并清理资源
1203+
**And** 所有操作输出结构化日志 (JSON 格式)
1204+
1205+
**示例配置:**
1206+
```yaml
1207+
# 启动示例
1208+
- name: Deploy application
1209+
uses: docker/compose
1210+
with:
1211+
action: up
1212+
file: docker-compose.yml
1213+
project_name: myapp
1214+
detach: true
1215+
build: false
1216+
1217+
# 停止示例
1218+
- name: Cleanup application
1219+
uses: docker/compose
1220+
with:
1221+
action: down
1222+
file: docker-compose.yml
1223+
project_name: myapp
1224+
volumes: true
1225+
rmi: local
1226+
```
1227+
1228+
### Story 3.9: 节点参考文档
11991229
12001230
As a **工作流用户**,
12011231
I want **每个节点的完整参考文档**,
12021232
So that **了解如何使用节点**。
12031233
12041234
**Acceptance Criteria:**
12051235
1206-
**Given** 11 个节点已实现
1236+
**Given** 7 个核心节点已实现
12071237
**When** 查阅节点文档
12081238
**Then** 每个节点有独立文档页面
12091239
**And** 文档包含描述、参数列表、返回值、示例
12101240
**And** 参数说明包含类型、必需性、默认值
12111241
**And** 至少 2 个实际使用示例
1212-
**And** 说明常见错误和解决方法
1242+
**And** 说明常见错误和解决方法
1243+
**And** 核心节点包括: exec/shell, exec/script, flow/sleep, file/transfer, http/request, docker/exec, docker/compose
12131244
12141245
---
12151246

0 commit comments

Comments
 (0)