会议模式:修"数字连不上运算" + 端点按类型上色 + 分支节点 + 7 个新算子

用户:"运算为啥不给数字类型连?端点颜色根据类型定白色exec 绿色str 蓝色 num
      红色bool。运算可以根据运算的类型从而改变输入端点的类型。加个分支节点,
      输入bool,输入为1走a exec 否则走 b exec。运算加上大于等于,小于等于,
      或,与,异或,左移右移" + "还有值节点如何设置值"

【1. 数字连不上运算 —— 界面的读变量出口写死了 str】
    "readvar" -> listOf(PinSpec("str", "", "值"))     ← 就是这行

读变量的出口类型**必须按变量登记表**。写死 str 的后果:
数字变量 → 读变量 → 运算 的线**接不上**(运算的 num 入口只收 num,
而读变量声称自己给 str)。引擎那边 `_data_out_type` 本来就查登记表,
界面这份漏了 —— **又一次"引擎有、界面没有"**。

修:outputPins 加 varTypes 参数(MeetingEditorScreen 里 remember 算一次),
readvar 的出口类型从登记表查。

【2. 端点按类型上色】
新增 pinColor(kind):白 exec / 绿 str / 蓝 num / 红 bool / 橙 list。
引脚圆点和**连线**用同一个颜色 —— 顺着颜色就能看出这根线接得对不对。

★ 判断/while/分支的 exec 出口保留绿(真)/红(假):
  那表达的是"走哪条"不是"什么类型",和按类型上色不冲突。

(列表给橙色:它是后加的类型,得和前面三个一眼区分开。)

【3. 分支节点】
新节点类型 `branch`:收一个真假,走真/假两条 exec。
  · 和判断节点的区别:判断按**规则**算真假(包含关键词/字数多于…),
    分支**直接收**一个真假 —— 真假从哪来由用户自己接
    (运算的比较结果、变量、读变量、自定义节点)。
  · 规则和判断**完全一致**(同一套坑不能两样):判成的分支没连线 →
    停在原地 + 报警告,不顺走另一条。
  · 条件入口收得宽(bool/str/num):变量和上游多半给的是 "true"/"1" 这类
    文本,用 truthy() 统一判断。

实测:true→A  false→B  1→A  0→B  是→A  空→B

【4. 七个新算子】
  gte 大于等于 ≥    lte 小于等于 ≤
  and 与    or 或    xor 异或
  shl 左移 <<       shr 右移 >>
算子总数 14 → 21。

★ 逻辑运算不要求两边"是严格的 bool":硬卡类型的话用户得先接一堆转换节点。
  用 truthy() 统一判断(认 0/空/false/no/off),输出统一 true/false。
★ 位运算先转**整数**(Python 的 << 对浮点会报错),
  位移量限 0~64(不让用户一不小心写出 1 << 9999999 算到天荒地老),
  负数位移量和超限都报错而不是崩。

【5. 值节点的配置面板(用户:"值节点如何设置值")】
配置面板有 agent/judge/var/py/cast/op/readvar **七个分支,没有 value** ——
值节点打开是空的,根本没法设值。**还是同一个毛病。**

补上:类型选择器 + 值输入框 + 按类型的提示
(数字能接运算、真假能接分支、列表写成 JSON 数组…)。

【端到端实测】
  数字变量 n=7 → 读变量(num) → 运算 gte(5) → 分支 → 走「够大」
  读变量出口类型: num ✓   运算入口类型: ('num',) ✓   边保留 6/6 ✓

【验证】
- 会议引擎 40/40,Node 与 Python 16/16 逐用例一致
- APK 构建通过、装机通过
- 截图确认:bool 引脚红、list 引脚橙、str 引脚绿、exec 白
This commit is contained in:
l
2026-10-12 15:02:56 +08:00
parent ed5a3115df
commit cb7e3a91db
5 changed files with 277 additions and 10 deletions

View File

@@ -44,7 +44,7 @@ import paths
_lock = threading.Lock()
NODE_TYPES = ('start', 'agent', 'judge', 'end', 'var', 'readvar', 'while', 'value',
'cast', 'op', 'py', 'custom')
'cast', 'op', 'py', 'custom', 'branch')
# 判断节点支持的条件。**结构化而不是表达式**,理由见文件头。
# --------------------------------------------------------------------------- #
@@ -215,8 +215,17 @@ OPS = (
('ne', '不等于 ≠', 'str', 'bool', 2),
('gt', '大于 >', 'num', 'bool', 2),
('lt', '小于 <', 'num', 'bool', 2),
('gte', '大于等于 ≥', 'num', 'bool', 2),
('lte', '小于等于 ≤', 'num', 'bool', 2),
('neg', '取反(负号)', 'num', 'num', 1),
('not', '逻辑非 !', 'bool', 'bool', 1),
# ---- 逻辑运算:两边都是真假,结果也是真假 ----
('and', '与 and', 'bool', 'bool', 2),
('or', '或 or', 'bool', 'bool', 2),
('xor', '异或 xor', 'bool', 'bool', 2),
# ---- 位运算:整数才有的操作,结果为数字 ----
('shl', '左移 <<', 'num', 'num', 2),
('shr', '右移 >>', 'num', 'num', 2),
('append', '追加到列表', 'list', 'list', 2),
('clear', '清空列表', 'list', 'list', 1),
)
@@ -298,6 +307,40 @@ def apply_op(op_key: str, a, b=None):
return ('false' if truthy(a) else 'true'), ''
return '', f'不认识的运算:{op_key}'
# ---- 逻辑运算 ----
#
# ★ 不要求两边"是严格的 bool":变量和上游多半给的是 "true"/"1"/"是" 这类文本,
# 硬卡类型的话用户得先接一堆转换节点才能做一次与运算。
# 用 truthy() 统一判断(它认得 0/空/false/no/off),结果统一输出 true/false。
if op_key in ('and', 'or', 'xor'):
x, y = truthy(a), truthy(b)
if op_key == 'and':
return ('true' if (x and y) else 'false'), ''
if op_key == 'or':
return ('true' if (x or y) else 'false'), ''
return ('true' if (x != y) else 'false'), ''
# ---- 位运算 ----
#
# ★ 先转成**整数**:Python 的 << 对浮点会报错,而我们的数值一路上都是文本。
# 负数照常(Python 的位运算是任意精度,这点比 C 好)。
if op_key in ('shl', 'shr'):
x, e1 = as_num(a)
y, e2 = as_num(b)
if e1 or e2:
return '0', (e1 or e2)
try:
n = int(x)
s = int(y)
if s < 0:
return '0', f'位移量不能是负数:{s}'
if s > 64:
# 不让用户一不小心写出 1 << 9999999(那会算到天荒地老)
return '0', f'位移量太大:{s}(最多 64)'
return cast_value((n << s) if op_key == 'shl' else (n >> s), 'num'), ''
except (ValueError, OverflowError) as exc:
return '0', f'位移算不了:{exc}'
if op_key == 'concat':
return str(a) + str(b), ''
if op_key in ('eq', 'ne'):
@@ -326,6 +369,10 @@ def apply_op(op_key: str, a, b=None):
return cast_value(x > y, out_type), ''
if op_key == 'lt':
return cast_value(x < y, out_type), ''
if op_key == 'gte':
return cast_value(x >= y, out_type), ''
if op_key == 'lte':
return cast_value(x <= y, out_type), ''
return '', f'不认识的运算:{op_key}'
@@ -765,6 +812,8 @@ NODE_DATA_IN = {
# 自定义节点:真正收什么由它声明的引脚决定(见 _data_in_type),
# 这里给宽松值,免得还没加载到定义时就把线丢了
'custom': ('str', 'bool', 'num', 'list'),
# 分支节点:只收一个真假
'branch': ('bool', 'str'),
'end': ('str', 'bool', 'num', 'list'),
# 转换:什么都收,出口由 castTo 决定
'cast': ('str', 'bool', 'num'),
@@ -1569,6 +1618,30 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
'note': f'读到 {name}' + ('' if value else '(还没设过,是空的)')})
next_ids = [e['to'] for e in _exec_out(edges, node_id)]
elif node_type == 'branch':
# ★ 分支节点:收一个真假,走 A 或 B。
#
# 和判断节点的区别:判断是按**规则**算真假(包含关键词 / 字数多于…),
# 分支是**直接收一个真假值** —— 真假从哪来由用户自己接
# (运算的比较结果、变量、读变量、自定义节点…)。
# 有了它,"先算个条件、再决定走哪条"就不用绕道判断节点了。
#
# 规则和判断节点**完全一致**(同一套坑,不能两样):
# · 判成的那个分支没连线 → 停在原地 + 报警告,不顺走另一条
# · 输入为空也报警告(exec 不传值,用户很容易忘了接数据线)
verdict = truthy(incoming)
outputs[node_id] = 'true' if verdict else 'false'
bname = 'true' if verdict else 'false'
next_ids = [e['to'] for e in _exec_out(edges, node_id, bname)]
if not next_ids:
emit({'type': 'node_warn', 'nodeId': node_id,
'warn': f'判定为{"真" if verdict else "假"},但那个分支没连线 —— '
f'执行链在这里停了。'})
emit({'type': 'node_done', 'nodeId': node_id, 'nodeType': node_type,
'output': outputs[node_id], 'verdict': verdict,
'branch': bname, 'run': run_index,
'note': f'{"真" if verdict else "假"} → 走 {bname} 分支'})
elif node_type == 'custom':
# ★ 用户用 Python 拓展出来的节点
import custom_nodes as _cn