P1: 条件表达式 DSL 化 — 从字符串解析升级为树形条件节点 #36

Open
opened 2026-06-12 22:39:12 +08:00 by orion · 0 comments
Owner

背景

当前 judge 的 condition 已支持运算符表达式字符串解析:

"condition": "confidence > 0.8"

但这是字符串解析(_parse_literal + _match_condition,见 pipeline.py 第 450-510 行),存在几个问题:

  1. 可验证性差 — 字符串解析错误只能在运行时发现
  2. AI 不友好 — AI 生成 JSON 时容易写错字符串格式
  3. 无法组合 — 不支持 and/or/not 组合条件
  4. 错误提示差 — 解析失败时难以定位问题

需求

将条件表达式升级为树形 DSL 节点

{
  "condition": {
    "op": "and",
    "conditions": [
      { "op": ">=", "field": "confidence", "value": 0.8 },
      { "op": "!=", "field": "status", "value": "blocked" },
      {
        "op": "or",
        "conditions": [
          { "op": "==", "field": "source", "value": "web" },
          { "op": "==", "field": "source", "value": "api" }
        ]
      }
    ]
  }
}

设计

  1. 节点类型and / or / not(逻辑节点)+ == / != / > / < / >= / <= / =~(比较节点)
  2. 向后兼容:旧版字符串 "confidence > 0.8" 继续支持,内部自动转换为树形节点
  3. 验证:DSLValidator 中增加条件树结构的校验(操作符合法性、字段名存在性可选)
  4. AI 提示:在文档和错误提示中优先推荐树形格式

关联

  • pipeline.py _parse_literal / _match_condition — 现有实现
  • #26 增强 DSL 语义分析 — 与条件树验证有交集
## 背景 当前 `judge` 的 condition 已支持运算符表达式字符串解析: ```json "condition": "confidence > 0.8" ``` 但这是字符串解析(`_parse_literal` + `_match_condition`,见 `pipeline.py` 第 450-510 行),存在几个问题: 1. 可验证性差 — 字符串解析错误只能在运行时发现 2. AI 不友好 — AI 生成 JSON 时容易写错字符串格式 3. 无法组合 — 不支持 and/or/not 组合条件 4. 错误提示差 — 解析失败时难以定位问题 ## 需求 将条件表达式升级为**树形 DSL 节点**: ```json { "condition": { "op": "and", "conditions": [ { "op": ">=", "field": "confidence", "value": 0.8 }, { "op": "!=", "field": "status", "value": "blocked" }, { "op": "or", "conditions": [ { "op": "==", "field": "source", "value": "web" }, { "op": "==", "field": "source", "value": "api" } ] } ] } } ``` ## 设计 1. **节点类型**:`and` / `or` / `not`(逻辑节点)+ `==` / `!=` / `>` / `<` / `>=` / `<=` / `=~`(比较节点) 2. **向后兼容**:旧版字符串 `"confidence > 0.8"` 继续支持,内部自动转换为树形节点 3. **验证**:DSLValidator 中增加条件树结构的校验(操作符合法性、字段名存在性可选) 4. **AI 提示**:在文档和错误提示中优先推荐树形格式 ## 关联 - `pipeline.py` `_parse_literal` / `_match_condition` — 现有实现 - #26 增强 DSL 语义分析 — 与条件树验证有交集
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bixiu/bixiweave#36
No description provided.