feat: add EIP4 agent CLI and skills plan
This commit is contained in:
@@ -13,6 +13,7 @@ EIP4 平台正式工程(路线 A'):双层制模块化单体——**保真层供
|
|||||||
| platform-converter | 模板转换器(P4) | 可独立 CLI 跑批 |
|
| platform-converter | 模板转换器(P4) | 可独立 CLI 跑批 |
|
||||||
| platform-flow-gateway | P3 占位:Flowable 网关 | |
|
| platform-flow-gateway | P3 占位:Flowable 网关 | |
|
||||||
| platform-ai | P5 AI Agent 开发底座:草稿/变更包/本地门禁/自动修复/人工部署包 | Agent 不直连线上执行生产变更 |
|
| platform-ai | P5 AI Agent 开发底座:草稿/变更包/本地门禁/自动修复/人工部署包 | Agent 不直连线上执行生产变更 |
|
||||||
|
| platform-cli | EIP4 Agent 受控命令入口:环境探测、AI 自动开发、后续发布编排 | Agent 优先通过 CLI/API 操作 |
|
||||||
| platform-parity | C1 对拍框架:录制/重放/RowDiff/自对拍 CLI | P1 一级交付物 |
|
| platform-parity | C1 对拍框架:录制/重放/RowDiff/自对拍 CLI | P1 一级交付物 |
|
||||||
| platform-app | Boot 启动器,组装全部模块 | ArchUnit 规则在此模块测试里 |
|
| platform-app | Boot 启动器,组装全部模块 | ArchUnit 规则在此模块测试里 |
|
||||||
|
|
||||||
@@ -75,6 +76,10 @@ java -cp "$CP" com.eip4.platform.parity.selfcheck.ParityCli --privilege # C
|
|||||||
# 指向 eip4dev 自对拍:
|
# 指向 eip4dev 自对拍:
|
||||||
mvn -pl platform-parity exec:java -Dexec.mainClass="com.eip4.platform.parity.selfcheck.ParityCli" \
|
mvn -pl platform-parity exec:java -Dexec.mainClass="com.eip4.platform.parity.selfcheck.ParityCli" \
|
||||||
"-Dexec.args=--discover --jdbc=jdbc:postgresql://localhost:5433/eip4dev?currentSchema=eip3 --engine=http://localhost:8093 --out=parity-reports/eip4dev"
|
"-Dexec.args=--discover --jdbc=jdbc:postgresql://localhost:5433/eip4dev?currentSchema=eip3 --engine=http://localhost:8093 --out=parity-reports/eip4dev"
|
||||||
|
|
||||||
|
# EIP4 Agent CLI
|
||||||
|
mvn -pl platform-cli package
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status --base-url http://localhost:8084
|
||||||
```
|
```
|
||||||
|
|
||||||
## tools/
|
## tools/
|
||||||
|
|||||||
@@ -36,6 +36,27 @@ JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -pl platform-app -am install -DskipTe
|
|||||||
|
|
||||||
## 请求示例
|
## 请求示例
|
||||||
|
|
||||||
|
推荐优先使用 `platform-cli`,让 Agent 通过稳定命令入口操作自动开发链路:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn -pl platform-cli package
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar ai auto-develop \
|
||||||
|
--base-url http://localhost:8093 \
|
||||||
|
--objective "新增客户等级维护功能" \
|
||||||
|
--feature-name "客户等级维护" \
|
||||||
|
--table-name EIP4AI_CUSTOMER_LEVEL \
|
||||||
|
--entity-name "客户等级" \
|
||||||
|
--template-id eip4ai-customer-level \
|
||||||
|
--menu-name "客户等级维护" \
|
||||||
|
--field NAME:名称:string:100:true \
|
||||||
|
--field CODE:编码:string:64:true \
|
||||||
|
--field ENABLED:启用:boolean::false \
|
||||||
|
--max-repair-attempts 2 \
|
||||||
|
--output target/ai-runs/customer-level.json
|
||||||
|
```
|
||||||
|
|
||||||
|
底层 REST API 仍可直接调用:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X POST http://localhost:8093/api/ai/features/auto-develop \
|
curl -X POST http://localhost:8093/api/ai/features/auto-develop \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
|
|||||||
167
docs/AI_AGENT_Nocobase_ADOPTION_PLAN.md
Normal file
167
docs/AI_AGENT_Nocobase_ADOPTION_PLAN.md
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
# AI Agent 借鉴 NocoBase 的落地路线
|
||||||
|
|
||||||
|
日期:2026-06-17
|
||||||
|
|
||||||
|
本文记录 EIP4 对 NocoBase AI + no-code 体系的可借鉴点和落地顺序。目标不是照搬 NocoBase 的 TypeScript 插件运行时,而是吸收它的工程边界:核心平台稳定、业务能力包化、AI 通过受控 CLI/API 操作、所有变更可审计、可验证、可回滚。
|
||||||
|
|
||||||
|
参考:
|
||||||
|
|
||||||
|
- NocoBase README: https://github.com/nocobase/nocobase
|
||||||
|
- NocoBase Plugin Development: https://docs.nocobase.com/plugin-development/
|
||||||
|
- NocoBase Project Structure: https://docs.nocobase.com/plugin-development/project-structure
|
||||||
|
- NocoBase AI Builder: https://docs.nocobase.com/ai-builder/
|
||||||
|
- NocoBase AI Plugin Development: https://docs.nocobase.com/ai-dev/
|
||||||
|
- NocoBase CLI: https://docs.nocobase.com/api/cli/
|
||||||
|
- NocoBase Skills: https://github.com/nocobase/skills
|
||||||
|
|
||||||
|
## 一、判断
|
||||||
|
|
||||||
|
NocoBase 最核心的启发是:AI 不应该默认直接写一堆业务代码,而是基于平台已有的可配置能力工作。AI 负责把自然语言需求转换为数据模型、页面配置、工作流、权限和发布包,人负责审核关键边界。
|
||||||
|
|
||||||
|
EIP4 当前已经有实体、页面 schema、服务流、菜单、smoke、部署包这些受控对象,因此更适合走“AI 操作元数据和发布包”的路线,而不是引入一套新的插件运行时。
|
||||||
|
|
||||||
|
## 二、可借鉴点
|
||||||
|
|
||||||
|
| NocoBase 做法 | EIP4 对应落点 | 处理方式 |
|
||||||
|
|---|---|---|
|
||||||
|
| AI 基于 no-code 基础设施工作 | `platform-ai` 生成实体/页面/服务流/菜单草稿 | 已落地,继续收敛到受控接口 |
|
||||||
|
| CLI 作为 Agent 操作入口 | `platform-cli` | P1 建立,后续扩展环境/发布/回滚 |
|
||||||
|
| Skills 让 Agent 理解平台 | `docs/skills/` | P1 建立规范骨架 |
|
||||||
|
| 插件生命周期 | EIP4 `FeaturePackage` 生命周期 | P2 设计和持久化 |
|
||||||
|
| 版本控制/里程碑回滚 | `SYS_AI_REVISION` / release evidence | P2-P3 |
|
||||||
|
| FlowEngine 的可配置模型 | EIP4 typed page schema + component registry | P4 借鉴思想,不照搬实现 |
|
||||||
|
|
||||||
|
## 三、落地顺序
|
||||||
|
|
||||||
|
### P0:全自动开发主链路
|
||||||
|
|
||||||
|
状态:已完成。
|
||||||
|
|
||||||
|
完成内容:
|
||||||
|
|
||||||
|
- `POST /api/ai/features/auto-develop`
|
||||||
|
- 草稿生成、变更包、release plan、本地 apply、smoke、自动修复、人工部署包
|
||||||
|
- JDBC 审计和运行证据
|
||||||
|
- 本地 jar 验证通过
|
||||||
|
|
||||||
|
验收标准:
|
||||||
|
|
||||||
|
- 本地可从一段功能需求生成可审核部署包
|
||||||
|
- 线上执行仍停在人审边界
|
||||||
|
|
||||||
|
### P1:受控入口和 Agent 知识包
|
||||||
|
|
||||||
|
状态:第一版完成。
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- 建立 `platform-cli`,让 Agent 通过命令调用 EIP4,而不是直接猜 HTTP 接口或直连数据库。
|
||||||
|
- 建立 `docs/skills/`,把 EIP4 的环境管理、自动开发、发布管理写成 Agent 可复用的操作规程。
|
||||||
|
|
||||||
|
本阶段交付:
|
||||||
|
|
||||||
|
- `eip4 env status`
|
||||||
|
- `eip4 ai auto-develop`
|
||||||
|
- `docs/skills/eip4-env-manage.md`
|
||||||
|
- `docs/skills/eip4-ai-feature-development.md`
|
||||||
|
- `docs/skills/eip4-release-manage.md`
|
||||||
|
|
||||||
|
验收标准:
|
||||||
|
|
||||||
|
- CLI 单测覆盖命令解析和请求组装
|
||||||
|
- README 和自动开发文档给出 CLI 用法
|
||||||
|
- Agent 后续操作优先引用 Skills 和 CLI
|
||||||
|
|
||||||
|
### P2:FeaturePackage 和里程碑版本
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- 把 AI 生成结果从松散的 draft/change-set 升级为稳定的 `FeaturePackage`。
|
||||||
|
- 保存里程碑版本,支持本地回滚和线上部署前差异确认。
|
||||||
|
|
||||||
|
建议对象:
|
||||||
|
|
||||||
|
- `FeaturePackage`: manifest、entity、serviceflow、page schema、menu、acl、sql、rollback、smoke、evidence
|
||||||
|
- `SYS_AI_FEATURE_PACKAGE`
|
||||||
|
- `SYS_AI_REVISION`
|
||||||
|
|
||||||
|
验收标准:
|
||||||
|
|
||||||
|
- 一个功能包可以导出、导入、重复校验
|
||||||
|
- 每个通过 smoke 的里程碑都能追溯输入、输出、测试证据和回滚脚本
|
||||||
|
|
||||||
|
### P3:发布、回滚和环境治理
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- CLI 扩展为环境管理和发布编排入口。
|
||||||
|
- 建立本地、测试、生产环境的只读探测、部署前检查和人工批准边界。
|
||||||
|
|
||||||
|
建议命令:
|
||||||
|
|
||||||
|
- `eip4 env list/use/status`
|
||||||
|
- `eip4 release package`
|
||||||
|
- `eip4 release verify`
|
||||||
|
- `eip4 release apply --require-approval`
|
||||||
|
- `eip4 release rollback --package-id`
|
||||||
|
|
||||||
|
验收标准:
|
||||||
|
|
||||||
|
- 默认不能连接线上执行写操作
|
||||||
|
- 生产写操作必须有显式环境、审批标记和部署包
|
||||||
|
- 发布失败能用结构化 evidence 回到本地修复链路
|
||||||
|
|
||||||
|
### P4:Typed Page Schema 和组件注册表
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- 借鉴 NocoBase FlowEngine 的“可配置模型”思想,把页面 block、field、action、linkage 抽象为 typed schema。
|
||||||
|
- 让 AI 和人工设计器操作同一份 schema。
|
||||||
|
|
||||||
|
验收标准:
|
||||||
|
|
||||||
|
- 页面 schema 有版本、类型、组件能力表和校验器
|
||||||
|
- AI 只能选择注册过的组件和动作
|
||||||
|
- 设计器变更和 AI 变更能互相接续
|
||||||
|
|
||||||
|
### P5:多 Agent 协作和 AI 员工
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- 在平台内提供面向业务用户的 AI 助手能力,而不只是在开发侧使用 Agent。
|
||||||
|
|
||||||
|
建议方向:
|
||||||
|
|
||||||
|
- 数据分析 Agent
|
||||||
|
- 表单配置 Agent
|
||||||
|
- 服务流诊断 Agent
|
||||||
|
- 权限风险审查 Agent
|
||||||
|
- 发布审计 Agent
|
||||||
|
|
||||||
|
验收标准:
|
||||||
|
|
||||||
|
- 每个 Agent 有独立权限、审计、工具白名单
|
||||||
|
- 业务侧操作和开发侧操作共用平台审计模型
|
||||||
|
|
||||||
|
## 四、不照搬的部分
|
||||||
|
|
||||||
|
NocoBase 是 TypeScript/Yarn workspace/插件包体系。EIP4 是 Java/Spring/Maven,并且必须兼容 EIP3 的实体、服务流和 XML 模板迁移路径。直接照搬 NocoBase 插件运行时会引入过高迁移成本。
|
||||||
|
|
||||||
|
EIP4 应该借鉴的是边界和流程:
|
||||||
|
|
||||||
|
1. 稳定核心能力。
|
||||||
|
2. 业务功能包化。
|
||||||
|
3. Agent 通过 CLI/API 操作。
|
||||||
|
4. 人审控制生产变更。
|
||||||
|
5. 每一步有 evidence、版本和回滚。
|
||||||
|
|
||||||
|
## 五、当前推进状态
|
||||||
|
|
||||||
|
| 阶段 | 状态 | 说明 |
|
||||||
|
|---|---|---|
|
||||||
|
| P0 | 完成 | `platform-ai` 主链路已提交 |
|
||||||
|
| P1 | 第一版完成 | 已新增 `platform-cli` 和 Skills 规范骨架 |
|
||||||
|
| P2 | 待开始 | 依赖 P1 的 CLI 和规范稳定 |
|
||||||
|
| P3 | 待开始 | 依赖 P2 的功能包和版本模型 |
|
||||||
|
| P4 | 待开始 | 依赖页面 schema 现状清理 |
|
||||||
|
| P5 | 待开始 | 依赖权限、审计、工具白名单成熟 |
|
||||||
20
docs/skills/README.md
Normal file
20
docs/skills/README.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# EIP4 Agent Skills
|
||||||
|
|
||||||
|
本目录是 EIP4 给 AI Agent 使用的领域操作规程。目标是让 Codex、Claude Code、Cursor、OpenCode 等 Agent 都按同一套规则操作 EIP4,而不是临时猜接口、猜表结构或直连线上库。
|
||||||
|
|
||||||
|
## Skills
|
||||||
|
|
||||||
|
| Skill | 用途 |
|
||||||
|
|---|---|
|
||||||
|
| `eip4-env-manage` | 环境探测、启动检查、端口和 profile 边界 |
|
||||||
|
| `eip4-ai-feature-development` | 从自然语言需求生成实体、服务流、页面、菜单和本地 smoke |
|
||||||
|
| `eip4-release-manage` | 部署包、人审、发布前校验和回滚边界 |
|
||||||
|
|
||||||
|
## 通用原则
|
||||||
|
|
||||||
|
1. 优先使用 `platform-cli`,其次使用公开 REST API,最后才考虑人工 SQL。
|
||||||
|
2. 默认只允许本地开发和测试环境自动执行写操作。
|
||||||
|
3. 线上环境只能生成部署包和校验证据,不能由 Agent 默认直接写入。
|
||||||
|
4. 每次自动开发必须保留 request、draft、change-set、apply、smoke、repair、deployment package evidence。
|
||||||
|
5. 任何失败先回到本地复现和修复,再重新生成部署包。
|
||||||
|
|
||||||
66
docs/skills/eip4-ai-feature-development.md
Normal file
66
docs/skills/eip4-ai-feature-development.md
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# Skill: eip4-ai-feature-development
|
||||||
|
|
||||||
|
## 触发场景
|
||||||
|
|
||||||
|
- 用户描述一个新功能,希望 AI 自动生成。
|
||||||
|
- 用户要求从 EIP3 模板、实体、服务流或页面定义生成 EIP4 功能。
|
||||||
|
- 用户要求本地自动开发、自动修复和 smoke。
|
||||||
|
|
||||||
|
## 输入要求
|
||||||
|
|
||||||
|
最小需求应包含:
|
||||||
|
|
||||||
|
- 功能目标
|
||||||
|
- 功能名称
|
||||||
|
- 业务表名
|
||||||
|
- 实体名称
|
||||||
|
- 页面 templateId
|
||||||
|
- 菜单名称
|
||||||
|
- 字段列表
|
||||||
|
|
||||||
|
字段格式:
|
||||||
|
|
||||||
|
```text
|
||||||
|
column:label:type[:length][:required]
|
||||||
|
```
|
||||||
|
|
||||||
|
示例:
|
||||||
|
|
||||||
|
```text
|
||||||
|
NAME:名称:string:100:true
|
||||||
|
CODE:编码:string:64:true
|
||||||
|
ENABLED:启用:boolean::false
|
||||||
|
```
|
||||||
|
|
||||||
|
## 推荐命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar ai auto-develop \
|
||||||
|
--base-url http://localhost:8084 \
|
||||||
|
--objective "新增客户等级维护功能" \
|
||||||
|
--feature-name "客户等级维护" \
|
||||||
|
--table-name EIP4AI_CUSTOMER_LEVEL \
|
||||||
|
--entity-name "客户等级" \
|
||||||
|
--template-id eip4ai-customer-level \
|
||||||
|
--menu-name "客户等级维护" \
|
||||||
|
--field NAME:名称:string:100:true \
|
||||||
|
--field CODE:编码:string:64:true \
|
||||||
|
--field ENABLED:启用:boolean::false \
|
||||||
|
--max-repair-attempts 2 \
|
||||||
|
--output target/ai-runs/customer-level.json
|
||||||
|
```
|
||||||
|
|
||||||
|
## 通过标准
|
||||||
|
|
||||||
|
- `applyStatus` 为 `PASSED`。
|
||||||
|
- `smokeStatus` 为 `PASSED`。
|
||||||
|
- 最终状态为 `READY_FOR_HUMAN_REVIEW`。
|
||||||
|
- 部署包存在且 `requiresHumanApproval=true`。
|
||||||
|
|
||||||
|
## 失败处理
|
||||||
|
|
||||||
|
1. 查看输出 JSON 中的 apply/smoke/repair evidence。
|
||||||
|
2. 如果自动修复已尝试但失败,基于 evidence 修改本地代码或元数据生成逻辑。
|
||||||
|
3. 重新运行本地 auto-develop。
|
||||||
|
4. 不直接连接线上库修复。
|
||||||
|
|
||||||
34
docs/skills/eip4-env-manage.md
Normal file
34
docs/skills/eip4-env-manage.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Skill: eip4-env-manage
|
||||||
|
|
||||||
|
## 触发场景
|
||||||
|
|
||||||
|
- 用户要求启动、检查或切换 EIP4 环境。
|
||||||
|
- 用户要求 Agent 在本地验证功能。
|
||||||
|
- 用户要求确认当前服务是否可被 AI 自动开发链路使用。
|
||||||
|
|
||||||
|
## 操作规则
|
||||||
|
|
||||||
|
1. 确认当前目录是否是独立 worktree,避免污染用户正在做的任务。
|
||||||
|
2. 使用 JDK 21,不能使用 JDK 26。
|
||||||
|
3. 默认本地 profile:
|
||||||
|
- `local`: `http://localhost:8084`
|
||||||
|
- `dev`: `http://localhost:8093`
|
||||||
|
4. 使用 CLI 探测环境:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status --base-url http://localhost:8084
|
||||||
|
```
|
||||||
|
|
||||||
|
5. 如果服务未启动,优先使用重新打包后的 jar:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -pl platform-app -am install -DskipTests
|
||||||
|
/opt/homebrew/opt/openjdk@21/bin/java -jar platform-app/target/platform-app-0.1.0-SNAPSHOT.jar --spring.profiles.active=local
|
||||||
|
```
|
||||||
|
|
||||||
|
## 禁止事项
|
||||||
|
|
||||||
|
- 不在用户原始任务目录中直接改动或启动长时间任务,除非用户明确要求。
|
||||||
|
- 不把线上环境设置为默认写入目标。
|
||||||
|
- 不跳过 JDK 版本检查。
|
||||||
|
|
||||||
39
docs/skills/eip4-release-manage.md
Normal file
39
docs/skills/eip4-release-manage.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Skill: eip4-release-manage
|
||||||
|
|
||||||
|
## 触发场景
|
||||||
|
|
||||||
|
- 用户要求生成部署包。
|
||||||
|
- 用户要求发布 AI 生成的功能。
|
||||||
|
- 用户要求线上 bug 修复或回滚。
|
||||||
|
|
||||||
|
## 当前边界
|
||||||
|
|
||||||
|
当前 `platform-ai` 只生成线上人工部署包,不自动连接线上环境执行写操作。这是设计边界,不是功能缺失。
|
||||||
|
|
||||||
|
## 发布前检查
|
||||||
|
|
||||||
|
1. 确认本地 auto-develop 已通过。
|
||||||
|
2. 确认部署包包含:
|
||||||
|
- manifest
|
||||||
|
- SQL 草案
|
||||||
|
- rollback SQL
|
||||||
|
- 本地 apply evidence
|
||||||
|
- smoke evidence
|
||||||
|
- repair evidence
|
||||||
|
3. 确认部署包需要人工审批。
|
||||||
|
4. 如果包含 `${parentMenuId}` 等占位符,必须人工替换并复核。
|
||||||
|
|
||||||
|
## 线上 bug 修复路径
|
||||||
|
|
||||||
|
1. 收集线上错误日志、请求样本或人工复现步骤。
|
||||||
|
2. 在本地创建新的 AI 修复任务。
|
||||||
|
3. 本地执行 apply/smoke/repair。
|
||||||
|
4. 生成新的部署包。
|
||||||
|
5. 人工审核后走现有上线流程。
|
||||||
|
|
||||||
|
## 禁止事项
|
||||||
|
|
||||||
|
- 不让 Agent 默认直接写线上数据库。
|
||||||
|
- 不绕过部署包和人审。
|
||||||
|
- 不把 smoke 失败的变更包交给发布流程。
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ eip4-platform(Maven 多模块单体)
|
|||||||
├── platform-flow-gateway Flowable REST 客户端、待办聚合、3 个 handler bean
|
├── platform-flow-gateway Flowable REST 客户端、待办聚合、3 个 handler bean
|
||||||
├── platform-converter 模板转换器 + S3 脚本改写器(可独立 CLI 跑批)
|
├── platform-converter 模板转换器 + S3 脚本改写器(可独立 CLI 跑批)
|
||||||
├── platform-ai AI Agent 开发底座、schema 双闸校验、自动修复、本地门禁和人工部署包
|
├── platform-ai AI Agent 开发底座、schema 双闸校验、自动修复、本地门禁和人工部署包
|
||||||
|
├── platform-cli EIP4 Agent 受控命令入口:环境探测、AI 自动开发、后续发布编排
|
||||||
├── platform-parity C1 逐行对拍框架:录制/重放/逐行 diff(P1 一级交付物,可独立 CLI 跑批)
|
├── platform-parity C1 逐行对拍框架:录制/重放/逐行 diff(P1 一级交付物,可独立 CLI 跑批)
|
||||||
└── platform-app Spring Boot 启动器,组装上述模块
|
└── platform-app Spring Boot 启动器,组装上述模块
|
||||||
```
|
```
|
||||||
|
|||||||
56
platform-cli/pom.xml
Normal file
56
platform-cli/pom.xml
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.eip4</groupId>
|
||||||
|
<artifactId>eip4-platform</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<artifactId>platform-cli</artifactId>
|
||||||
|
<name>platform-cli</name>
|
||||||
|
<description>EIP4 Agent 受控命令入口:环境探测、AI 自动开发、发布前门禁编排</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.7.1</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.eip4.platform.cli.Eip4Cli</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
328
platform-cli/src/main/java/com/eip4/platform/cli/Eip4Cli.java
Normal file
328
platform-cli/src/main/java/com/eip4/platform/cli/Eip4Cli.java
Normal file
@@ -0,0 +1,328 @@
|
|||||||
|
package com.eip4.platform.cli;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
|
public final class Eip4Cli {
|
||||||
|
|
||||||
|
private static final String DEFAULT_BASE_URL = "http://localhost:8084";
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
private final Eip4HttpClient httpClient;
|
||||||
|
|
||||||
|
public Eip4Cli(Eip4HttpClient httpClient) {
|
||||||
|
this.objectMapper = new ObjectMapper();
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
int code = new Eip4Cli(new JdkEip4HttpClient(objectMapper)).run(args, System.out, System.err);
|
||||||
|
if (code != 0) {
|
||||||
|
System.exit(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int run(String[] args, PrintStream out, PrintStream err) {
|
||||||
|
try {
|
||||||
|
if (args.length == 0 || isHelp(args[0])) {
|
||||||
|
printHelp(out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return switch (args[0]) {
|
||||||
|
case "env" -> runEnv(args, out, err);
|
||||||
|
case "ai" -> runAi(args, out, err);
|
||||||
|
default -> fail(err, "Unknown command: " + args[0]);
|
||||||
|
};
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
return fail(err, ex.getMessage());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
return fail(err, "I/O failed: " + ex.getMessage());
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
return fail(err, "Interrupted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runEnv(String[] args, PrintStream out, PrintStream err) throws IOException, InterruptedException {
|
||||||
|
if (args.length < 2 || isHelp(args[1])) {
|
||||||
|
printEnvHelp(out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!"status".equals(args[1])) {
|
||||||
|
return fail(err, "Unknown env command: " + args[1]);
|
||||||
|
}
|
||||||
|
Options options = Options.parse(args, 2);
|
||||||
|
String baseUrl = baseUrl(options);
|
||||||
|
URI uri = endpoint(baseUrl, "/v3/api-docs");
|
||||||
|
Eip4HttpResponse response = httpClient.send("GET", uri, null);
|
||||||
|
if (!response.successful()) {
|
||||||
|
err.println("EIP4 env NOT_READY");
|
||||||
|
err.println("baseUrl: " + baseUrl);
|
||||||
|
err.println("status: " + response.statusCode());
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
out.println("EIP4 env READY");
|
||||||
|
out.println("baseUrl: " + baseUrl);
|
||||||
|
out.println("apiDocs: " + uri);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runAi(String[] args, PrintStream out, PrintStream err) throws IOException, InterruptedException {
|
||||||
|
if (args.length < 2 || isHelp(args[1])) {
|
||||||
|
printAiHelp(out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!"auto-develop".equals(args[1])) {
|
||||||
|
return fail(err, "Unknown ai command: " + args[1]);
|
||||||
|
}
|
||||||
|
Options options = Options.parse(args, 2);
|
||||||
|
ObjectNode request = buildAutoDevelopRequest(options);
|
||||||
|
String baseUrl = baseUrl(options);
|
||||||
|
Eip4HttpResponse response = httpClient.send(
|
||||||
|
"POST",
|
||||||
|
endpoint(baseUrl, "/api/ai/features/auto-develop"),
|
||||||
|
request);
|
||||||
|
if (!response.successful()) {
|
||||||
|
err.println("AI auto-develop failed");
|
||||||
|
err.println("status: " + response.statusCode());
|
||||||
|
err.println(response.body());
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
JsonNode body = response.body().isBlank()
|
||||||
|
? objectMapper.createObjectNode()
|
||||||
|
: objectMapper.readTree(response.body());
|
||||||
|
String formatted = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(body);
|
||||||
|
String output = options.single("output");
|
||||||
|
if (output == null) {
|
||||||
|
out.println(formatted);
|
||||||
|
} else {
|
||||||
|
Path outputPath = Path.of(output);
|
||||||
|
if (outputPath.getParent() != null) {
|
||||||
|
Files.createDirectories(outputPath.getParent());
|
||||||
|
}
|
||||||
|
Files.writeString(outputPath, formatted + System.lineSeparator(), StandardCharsets.UTF_8);
|
||||||
|
out.println("Wrote run result: " + outputPath.toAbsolutePath());
|
||||||
|
printAutoDevelopSummary(body, out);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode buildAutoDevelopRequest(Options options) {
|
||||||
|
ObjectNode root = objectMapper.createObjectNode();
|
||||||
|
String baseUrl = baseUrl(options);
|
||||||
|
root.put("baseUrl", baseUrl);
|
||||||
|
root.put("generateDeploymentPackage", !options.has("no-deployment-package"));
|
||||||
|
String maxRepairAttempts = options.single("max-repair-attempts");
|
||||||
|
if (maxRepairAttempts != null) {
|
||||||
|
root.put("maxRepairAttempts", parseInt(maxRepairAttempts, "max-repair-attempts"));
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectNode feature = root.putObject("feature");
|
||||||
|
putRequired(feature, "objective", options, "objective");
|
||||||
|
putRequired(feature, "featureName", options, "feature-name");
|
||||||
|
putRequired(feature, "tableName", options, "table-name");
|
||||||
|
putRequired(feature, "entityName", options, "entity-name");
|
||||||
|
putRequired(feature, "templateId", options, "template-id");
|
||||||
|
putRequired(feature, "menuName", options, "menu-name");
|
||||||
|
|
||||||
|
List<String> fields = options.values("field");
|
||||||
|
if (fields.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Missing required option: --field");
|
||||||
|
}
|
||||||
|
ArrayNode fieldNodes = feature.putArray("fields");
|
||||||
|
for (String field : fields) {
|
||||||
|
fieldNodes.add(parseField(field));
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode parseField(String spec) {
|
||||||
|
String[] parts = spec.split(":", -1);
|
||||||
|
if (parts.length < 3 || parts.length > 5) {
|
||||||
|
throw new IllegalArgumentException("Invalid --field, expected column:label:type[:length][:required]");
|
||||||
|
}
|
||||||
|
ObjectNode node = objectMapper.createObjectNode();
|
||||||
|
node.put("column", requiredPart(parts[0], "field column"));
|
||||||
|
node.put("label", requiredPart(parts[1], "field label"));
|
||||||
|
node.put("type", requiredPart(parts[2], "field type").toLowerCase(Locale.ROOT));
|
||||||
|
if (parts.length >= 4 && !parts[3].isBlank()) {
|
||||||
|
node.put("length", parseInt(parts[3], "field length"));
|
||||||
|
}
|
||||||
|
if (parts.length >= 5 && !parts[4].isBlank()) {
|
||||||
|
node.put("required", Boolean.parseBoolean(parts[4]));
|
||||||
|
} else {
|
||||||
|
node.put("required", false);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void putRequired(ObjectNode node, String jsonName, Options options, String optionName) {
|
||||||
|
node.put(jsonName, requiredPart(options.single(optionName), optionName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String baseUrl(Options options) {
|
||||||
|
String value = options.single("base-url");
|
||||||
|
if (value == null || value.isBlank()) {
|
||||||
|
value = System.getenv("EIP4_BASE_URL");
|
||||||
|
}
|
||||||
|
if (value == null || value.isBlank()) {
|
||||||
|
value = DEFAULT_BASE_URL;
|
||||||
|
}
|
||||||
|
while (value.endsWith("/")) {
|
||||||
|
value = value.substring(0, value.length() - 1);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private URI endpoint(String baseUrl, String path) {
|
||||||
|
return URI.create(baseUrl + path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printAutoDevelopSummary(JsonNode body, PrintStream out) {
|
||||||
|
out.println("status: " + text(body, "status"));
|
||||||
|
out.println("taskId: " + text(body, "taskId"));
|
||||||
|
out.println("changeSetId: " + text(body, "changeSetId"));
|
||||||
|
JsonNode apply = body.path("applyRun");
|
||||||
|
if (!apply.isMissingNode()) {
|
||||||
|
out.println("applyStatus: " + text(apply, "status"));
|
||||||
|
}
|
||||||
|
JsonNode smoke = body.path("smokeRun");
|
||||||
|
if (!smoke.isMissingNode()) {
|
||||||
|
out.println("smokeStatus: " + text(smoke, "status"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String text(JsonNode node, String field) {
|
||||||
|
JsonNode value = node.path(field);
|
||||||
|
return value.isMissingNode() || value.isNull() ? "" : value.asText();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int parseInt(String value, String name) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new IllegalArgumentException("Invalid integer for " + name + ": " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String requiredPart(String value, String name) {
|
||||||
|
if (value == null || value.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Missing required value: " + name);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isHelp(String arg) {
|
||||||
|
return "--help".equals(arg) || "-h".equals(arg) || "help".equals(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int fail(PrintStream err, String message) {
|
||||||
|
err.println(message);
|
||||||
|
err.println("Run `eip4 --help` for usage.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printHelp(PrintStream out) {
|
||||||
|
out.println("""
|
||||||
|
EIP4 CLI
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
eip4 env status [--base-url URL]
|
||||||
|
eip4 ai auto-develop --objective TEXT --feature-name NAME --table-name TABLE --entity-name NAME --template-id ID --menu-name NAME --field column:label:type[:length][:required]
|
||||||
|
|
||||||
|
Environment:
|
||||||
|
EIP4_BASE_URL defaults the target service URL when --base-url is omitted.
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printEnvHelp(PrintStream out) {
|
||||||
|
out.println("""
|
||||||
|
Usage:
|
||||||
|
eip4 env status [--base-url URL]
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printAiHelp(PrintStream out) {
|
||||||
|
out.println("""
|
||||||
|
Usage:
|
||||||
|
eip4 ai auto-develop [options]
|
||||||
|
|
||||||
|
Required:
|
||||||
|
--objective TEXT
|
||||||
|
--feature-name NAME
|
||||||
|
--table-name TABLE
|
||||||
|
--entity-name NAME
|
||||||
|
--template-id ID
|
||||||
|
--menu-name NAME
|
||||||
|
--field column:label:type[:length][:required]
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
--base-url URL
|
||||||
|
--max-repair-attempts N
|
||||||
|
--no-deployment-package
|
||||||
|
--output FILE
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class Options {
|
||||||
|
private final Map<String, List<String>> values = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
static Options parse(String[] args, int from) {
|
||||||
|
Options options = new Options();
|
||||||
|
for (int i = from; i < args.length; i++) {
|
||||||
|
String arg = args[i];
|
||||||
|
if (!arg.startsWith("--")) {
|
||||||
|
throw new IllegalArgumentException("Unexpected argument: " + arg);
|
||||||
|
}
|
||||||
|
String name = arg.substring(2);
|
||||||
|
if (name.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Invalid option: " + arg);
|
||||||
|
}
|
||||||
|
if ("no-deployment-package".equals(name)) {
|
||||||
|
options.add(name, "true");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (i + 1 >= args.length || args[i + 1].startsWith("--")) {
|
||||||
|
throw new IllegalArgumentException("Missing value for option: " + arg);
|
||||||
|
}
|
||||||
|
options.add(name, args[++i]);
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean has(String name) {
|
||||||
|
return values.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
String single(String name) {
|
||||||
|
List<String> list = values.get(name);
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list.get(list.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> values(String name) {
|
||||||
|
return values.getOrDefault(name, List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void add(String name, String value) {
|
||||||
|
values.computeIfAbsent(name, ignored -> new ArrayList<>()).add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.eip4.platform.cli;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
|
||||||
|
interface Eip4HttpClient {
|
||||||
|
Eip4HttpResponse send(String method, URI uri, JsonNode body) throws IOException, InterruptedException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.eip4.platform.cli;
|
||||||
|
|
||||||
|
record Eip4HttpResponse(int statusCode, String body) {
|
||||||
|
boolean successful() {
|
||||||
|
return statusCode >= 200 && statusCode < 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.eip4.platform.cli;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
final class JdkEip4HttpClient implements Eip4HttpClient {
|
||||||
|
|
||||||
|
private static final Duration TIMEOUT = Duration.ofSeconds(30);
|
||||||
|
|
||||||
|
private final HttpClient client;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
JdkEip4HttpClient(ObjectMapper objectMapper) {
|
||||||
|
this.client = HttpClient.newBuilder().connectTimeout(TIMEOUT).build();
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Eip4HttpResponse send(String method, URI uri, JsonNode body) throws IOException, InterruptedException {
|
||||||
|
HttpRequest.BodyPublisher publisher = body == null
|
||||||
|
? HttpRequest.BodyPublishers.noBody()
|
||||||
|
: HttpRequest.BodyPublishers.ofString(objectMapper.writeValueAsString(body));
|
||||||
|
HttpRequest request = HttpRequest.newBuilder(uri)
|
||||||
|
.timeout(TIMEOUT)
|
||||||
|
.header("Accept", "application/json")
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.method(method, publisher)
|
||||||
|
.build();
|
||||||
|
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
return new Eip4HttpResponse(response.statusCode(), response.body());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
package com.eip4.platform.cli;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
class Eip4CliTest {
|
||||||
|
|
||||||
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@TempDir
|
||||||
|
Path tempDir;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void envStatusChecksOpenApiEndpoint() {
|
||||||
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, "{}"));
|
||||||
|
CliResult result = run(client, "env", "status", "--base-url", "http://localhost:8084/");
|
||||||
|
|
||||||
|
assertEquals(0, result.code());
|
||||||
|
assertEquals("GET", client.method);
|
||||||
|
assertEquals(URI.create("http://localhost:8084/v3/api-docs"), client.uri);
|
||||||
|
assertTrue(result.out().contains("EIP4 env READY"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoDevelopBuildsRequestAndWritesResponse() throws Exception {
|
||||||
|
String response = """
|
||||||
|
{
|
||||||
|
"status": "READY_FOR_HUMAN_REVIEW",
|
||||||
|
"taskId": "task-1",
|
||||||
|
"changeSetId": "cs-1",
|
||||||
|
"applyRun": {"status": "PASSED"},
|
||||||
|
"smokeRun": {"status": "PASSED"}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, response));
|
||||||
|
Path output = tempDir.resolve("run.json");
|
||||||
|
|
||||||
|
CliResult result = run(client,
|
||||||
|
"ai", "auto-develop",
|
||||||
|
"--base-url", "http://localhost:8084",
|
||||||
|
"--objective", "新增客户等级维护",
|
||||||
|
"--feature-name", "客户等级维护",
|
||||||
|
"--table-name", "EIP4AI_CUSTOMER_LEVEL",
|
||||||
|
"--entity-name", "客户等级",
|
||||||
|
"--template-id", "eip4ai-customer-level",
|
||||||
|
"--menu-name", "客户等级维护",
|
||||||
|
"--field", "NAME:名称:string:100:true",
|
||||||
|
"--field", "ENABLED:启用:boolean::false",
|
||||||
|
"--max-repair-attempts", "3",
|
||||||
|
"--no-deployment-package",
|
||||||
|
"--output", output.toString());
|
||||||
|
|
||||||
|
assertEquals(0, result.code());
|
||||||
|
assertEquals("POST", client.method);
|
||||||
|
assertEquals(URI.create("http://localhost:8084/api/ai/features/auto-develop"), client.uri);
|
||||||
|
assertFalse(client.body.path("generateDeploymentPackage").asBoolean());
|
||||||
|
assertEquals(3, client.body.path("maxRepairAttempts").asInt());
|
||||||
|
JsonNode feature = client.body.path("feature");
|
||||||
|
assertEquals("EIP4AI_CUSTOMER_LEVEL", feature.path("tableName").asText());
|
||||||
|
assertEquals(2, feature.path("fields").size());
|
||||||
|
assertEquals("NAME", feature.path("fields").get(0).path("column").asText());
|
||||||
|
assertEquals(100, feature.path("fields").get(0).path("length").asInt());
|
||||||
|
assertTrue(feature.path("fields").get(0).path("required").asBoolean());
|
||||||
|
assertTrue(Files.readString(output, StandardCharsets.UTF_8).contains("READY_FOR_HUMAN_REVIEW"));
|
||||||
|
assertTrue(result.out().contains("applyStatus: PASSED"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoDevelopRequiresAtLeastOneField() {
|
||||||
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, "{}"));
|
||||||
|
|
||||||
|
CliResult result = run(client,
|
||||||
|
"ai", "auto-develop",
|
||||||
|
"--objective", "新增客户等级维护",
|
||||||
|
"--feature-name", "客户等级维护",
|
||||||
|
"--table-name", "EIP4AI_CUSTOMER_LEVEL",
|
||||||
|
"--entity-name", "客户等级",
|
||||||
|
"--template-id", "eip4ai-customer-level",
|
||||||
|
"--menu-name", "客户等级维护");
|
||||||
|
|
||||||
|
assertEquals(1, result.code());
|
||||||
|
assertTrue(result.err().contains("Missing required option: --field"));
|
||||||
|
assertEquals(0, client.calls);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CliResult run(CapturingClient client, String... args) {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||||
|
int code = new Eip4Cli(client).run(
|
||||||
|
args,
|
||||||
|
new PrintStream(out, true, StandardCharsets.UTF_8),
|
||||||
|
new PrintStream(err, true, StandardCharsets.UTF_8));
|
||||||
|
return new CliResult(
|
||||||
|
code,
|
||||||
|
out.toString(StandardCharsets.UTF_8),
|
||||||
|
err.toString(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class CapturingClient implements Eip4HttpClient {
|
||||||
|
private final Eip4HttpResponse response;
|
||||||
|
private int calls;
|
||||||
|
private String method;
|
||||||
|
private URI uri;
|
||||||
|
private JsonNode body = objectMapper.createObjectNode();
|
||||||
|
|
||||||
|
private CapturingClient(Eip4HttpResponse response) {
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Eip4HttpResponse send(String method, URI uri, JsonNode body) {
|
||||||
|
this.calls++;
|
||||||
|
this.method = method;
|
||||||
|
this.uri = uri;
|
||||||
|
this.body = body == null ? objectMapper.createObjectNode() : body;
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record CliResult(int code, String out, String err) {
|
||||||
|
}
|
||||||
|
}
|
||||||
6
pom.xml
6
pom.xml
@@ -25,6 +25,7 @@
|
|||||||
<module>platform-flow-gateway</module>
|
<module>platform-flow-gateway</module>
|
||||||
<module>platform-converter</module>
|
<module>platform-converter</module>
|
||||||
<module>platform-ai</module>
|
<module>platform-ai</module>
|
||||||
|
<module>platform-cli</module>
|
||||||
<module>platform-parity</module>
|
<module>platform-parity</module>
|
||||||
<module>platform-app</module>
|
<module>platform-app</module>
|
||||||
<!-- P3:Flowable 独立工作流服务(单客户交付四进程之一,独立可执行 jar,端口 8089) -->
|
<!-- P3:Flowable 独立工作流服务(单客户交付四进程之一,独立可执行 jar,端口 8089) -->
|
||||||
@@ -70,6 +71,11 @@
|
|||||||
<artifactId>platform-ai</artifactId>
|
<artifactId>platform-ai</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.eip4</groupId>
|
||||||
|
<artifactId>platform-cli</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.eip4</groupId>
|
<groupId>com.eip4</groupId>
|
||||||
<artifactId>platform-parity</artifactId>
|
<artifactId>platform-parity</artifactId>
|
||||||
|
|||||||
Reference in New Issue
Block a user