Commit Graph

21 Commits

Author SHA1 Message Date
1a57000458 refactor(ai): 抽 AiDeploymentSqlBuilder 收窄 AiAgentService(§10.2 SRP slice 1)
把 AiAgentService 内联的部署/回滚 SQL 生成簇(deploymentSql/serviceFlowSql/pageSchemaSql/menuSql/rollbackSql/serviceFlowRollbackSql/entityDeploymentNote + json/sqlString/sha256)逐字移入新 AiDeploymentSqlBuilder(构造取 ObjectMapper,终构造器内 new,不改对外构造签名);AiAgentService 1846→1677 行,SQL 文本字节零变更(红线逐字节对拍)。新增 AiDeploymentSqlBuilderTest 8 用例钉死关键 token(表名/AI_AGENT 审计字面量/ON CONFLICT/version+1/::xml·::jsonb/单引号转义/占位符回退/entityId 替换);AiAgentServiceTest 22/22 行为不变,全 reactor 绿。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 13:00:32 +08:00
c4ef673b0a refactor(ai): 三处本机判定统一到 LocalHostPolicy(D5)
AiToolRegistry/AiSmokeRunner/AiLocalReleaseExecutor 原各写一份本机白名单且互异(一处认 0:0:0:0:0:0:0:1 漏 [::1],另两处反之)。
新增 LocalHostPolicy.isLocalHost:去 IPv6 方括号归一 + 精确比对回环集 {localhost,127.0.0.1,::1,0:0:0:0:0:0:0:1},杜绝 127.0.0.1.evil.com 伪本地绕过;三处删副本统一委托。
验证:新增 LocalHostPolicyTest(全回环形态接受 + 伪本地/非本机拒绝)3/3 + 三处既有测试无回归,platform-ai 69/69 绿。见总览 §10 D5。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 11:12:22 +08:00
378fd74682 refactor(ai): AI 本地发布裸写下沉到 AiReleaseWriter + 补值断言测试
A5 安全半步:把 AiLocalReleaseExecutor 里所有 sys_serviceflow/sys_menu 裸 JDBC(含 ensureAiMenuParent/tableExists/实体复用查询)收拢到新类 AiReleaseWriter,执行器只剩编排;SQL 逐字保留=零行为变更。
新增 AiReleaseWriterTest 4 值断言(serviceflow 审计/?::xml/bool→int、菜单 INSERT 全列值、UPDATE 全字段、自动建「AI Agent」目录),补上原黄金测试只查表名的宽松缺口。
platform-ai 30/30 绿(黄金测试经搬迁仍绿=行为未变)。与人走五环 MenuRegistrar 的完整统一(两者已分叉)留作专项,见总览 §10 A5。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 10:52:25 +08:00
46ff5c5779 fix(P0②/P1⑥): 对抗审查收口 4 major + minor
对抗审查 workflow(3 lens)揪出并修复:
- [major] AlterTableSqlGuard 移除 ALTER COLUMN TYPE:静态守卫拿不到旧尺寸,无法
  保证扩长(varchar(1)/numeric(1,0) 缩短会截断/溢出存量数据),一律拒;扩长须由
  MetaController 比对旧列长度后再生成
- [major] addAttributes 校验-写分离 + @Transactional + ALTER 失败抛异常:
  杜绝「元数据写了但物理表没加」孤儿(PG 事务性 DDL 一起回滚)
- [major] createEntity 检查 executeCreateSql 返回值 + @Transactional:引擎拒建表
  不再静默成功
- [major] AiToolRegistry isLocalEnv/isProductionEnv 改 URI host 精确解析:防
  http://127.0.0.1.evil.com / localhost.evil.com 伪本地前缀绕过安全门
- [minor] deleteStandard templateId trim + 菜单查询限 isactive=1(两表口径一致,
  不连带删历史同 templateId 菜单/授权)
- [minor] publish roleIds 只接 String 元素(滤 null/非串);warning 改依据
  roleIds.isEmpty()(重复发布不误报)
- [minor] menuauth grantToRoles 改 INSERT...WHERE NOT EXISTS(sys_role_menu 无
  唯一约束,ON CONFLICT 不去重,重复发布会插重复行)+ columnSqlType 空 refTable 抛错

全单测绿(Failures=0)、p0-alter/p1-6 真库验收绿(含幂等+负控)、浏览器 e2e 6/6 绿

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 14:15:29 +08:00
8b28595f9e feat(P0②): 引擎ALTER安全通道 + AI安全门enforced
- AlterTableSqlGuard(legacy-core,纯静态白名单):只允许 加列/同族扩长/改可空,
  拒 DROP COLUMN/RENAME/SET NOT NULL/多语句/跨族/小写绕过;放legacy-core避免反向依赖
- DataDicService.executeAlterSql 受控通道(过Guard再execute,defense-in-depth)
- MetaController POST /api/meta/entity/{table}/attributes 加列端点
  (saveAttr元数据+alterAddColumnDdl镜像appendColumnDdl类型映射+evictByTable+补索引,恒可空)
- AiAgentService.applyLocalRelease 织入 AiToolRegistry.check:安全门 advisory→enforced
  (local.apply工具身份,非本机/越权写路径403)
- 单测 Guard15/alter2/gate22(112基线无回归);scripts/p0-alter-acceptance.sh 真库验收

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-21 13:56:14 +08:00
25494efadf feat(blueprint): master-detail recipe 接入 registry/composer + YAML
PageRecipeRegistry.defaults+compile switch 加 master-detail-v1。
RecipePageComposer.Spec 携带 childTable/listColumn/childAttributes
(7-arg 兼容构造保留),toBlueprint 装配 PageBlueprintChild。
新增 page-recipes/master-detail-v1.yaml(镜像 maintenance/tree,
gates 含 typed-page-schema/amis-schema)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 15:18:22 +08:00
1ff0d334d0 feat(ai-recipe): align maintenance-crud-v1 to converter house-style
AI 生成的单表维护页与转换器基线产出存在「陌生感」:缺查询区、走自创
/api/entity REST 而非保真层服务流、动作放 per-row 操作列。本次对齐:

- crud.api → /api/flow/<TABLE>_SEARCH(amis 自动追 page/perPage,无 adaptor)
  + selectable/checkOnItemClick/primaryField
- 补 filter 查询区(string 列 → input-text 文本搜索)
- 新增/编辑/删除挂 headerToolbar 操作 selectedItems(带 id + disabledOn 守卫,
  删掉 per-row 操作列);增改 inline 表单绑 _ADD/_UPDATE + reload,编辑用
  dialog data:{"&":"${selectedItems[0]}"} 预填 + hidden 主键;删除
  data={ids:"${selectedItems|pick:<PK>|join:','}"}(照搬基线,键为 ids)
- 连带:AiFeatureDraftGenerator.expectedPageApi + AiAgentService 的
  render-plan 门禁改 recipe-aware(原硬编码 /api/entity + /list? 会让整条
  pipeline 409)

证据:2727 转换页聚合 0 用 per-row operation 列 / 1976 headerToolbar /
1211 filter / 1277 _SEARCH。DefaultFlowHelper 流名吻合,AI pipeline 仅生成
list 页无独立表单页 → recipe 保持 inline 自包含。

验证:platform-metadata 397 + platform-ai 61 测试绿;8093 live 经 AI pipeline
重生成页 + 浏览器实证查询区/工具栏/选中守卫/flow 取数/编辑预填全绿,0 console error。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 19:07:39 +08:00
d3b88467e0 feat(page-schema): converge net-new standard writes to single PageSchemaWriter (M3a)
sys_page_schema standard layer had two runtime writers: the converter import CLI and AiLocalReleaseExecutor's raw JDBC INSERT (the critic-flagged net-new bypass). Introduce PageSchemaWriter as the single runtime write function (typed-recipe validation warn-not-block + etag + UPSERT), and route both a new admin-gated PUT /api/page/schema/{id}/standard endpoint (net-new producer for the design-center 'new feature' path) and AiLocalReleaseExecutor.applyPageSchema through it. No remaining raw INSERT into sys_page_schema in the AI runtime write path.

Scope: page_schema runtime write only. The deployment-package SQL-text generator (AiAgentService.pageSchemaSql, offline human-apply artifact) and SchemaImportCli (batch converter import) are separate legitimate paths. AiLocalReleaseExecutor sys_serviceflow/sys_menu raw writes remain (follow-on). Completion = code-complete, integration-pending (end-to-end render proof env-gated).

Tests: PageSchemaWriterTest (4) + PageSchemaControllerTest putStandard success/403/split (27 total) + AiLocalReleaseExecutorTest/AiAgentApiPipelineTest unchanged-green. TDD.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 17:21:06 +08:00
9aea6c1cd0 docs(ai): converge external wording to AI-assisted + human review, not full-auto
Per the architecture-review redline (EIP3 决策会纪要: AI claims limited to 'AI-assisted, human-reviewed'; never promise 'AI full-auto development'), soften endpoint @Operation summaries, the default task objective, and AI docs that read as committed full-automation. Endpoint paths/method names unchanged (API contract). Added a capability-boundary disclaimer at the top of AI_AGENT_AUTO_DEVELOPMENT.md. 33 platform-ai tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 16:39:45 +08:00
c379f5b1ea feat(ai): require admin for AI agent mutation/action endpoints
AiAgentController's endpoints relied only on the SecurityFilterChain (prod: /api/** authenticated; dev: permitAll), so any authenticated user could trigger AI writes/actions (auto-develop, local-apply, change-sets, deployment packages) - a lower bar than the comparable overlay/standard-page write endpoints which require admin.

Gate the 14 mutating/action POST endpoints with requireAdmin() (UserSession CURRENTUSER == ADMIN), aligned with PageSchemaController.requireAdmin / AdminWriteController. Read GETs and the pure validate-schema/access-check endpoints stay open. Actual three-truth writes are now admin + localhost double-gated.

Tests: AiAgentControllerTest + AiAgentApiPipelineTest run under an ADMIN session (+ AfterEach clear); added a 403 test for non-admin. 61 platform-ai tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 16:22:17 +08:00
4b2cedfd1d feat: add AI page preview URL 2026-06-17 14:17:53 +08:00
d91da77038 feat: add AI render plan gate 2026-06-17 13:28:49 +08:00
718c5a5b9b feat: add AI tree CRUD recipe 2026-06-17 13:03:38 +08:00
2b0b673ce9 feat: expose AI page recipes 2026-06-17 12:38:26 +08:00
fcc5719bc6 feat: enforce AI page recipe gate 2026-06-17 12:33:09 +08:00
e55072598e feat: add AI page blueprint compiler 2026-06-17 12:14:57 +08:00
c1ff0db96b feat: enforce typed page schema in AI drafts 2026-06-17 09:15:10 +08:00
c5b7b68210 fix: harden AI tool access check 2026-06-17 08:57:59 +08:00
8bdde45e89 feat: add AI tool access registry 2026-06-17 08:45:56 +08:00
c5bfbd3ca3 feat: add AI feature package revisions 2026-06-17 07:56:45 +08:00
3b4d3dbd24 feat: add AI agent auto-development pipeline 2026-06-17 07:32:54 +08:00