bpmax-cli 0.2.1-beta.86 → 0.2.1-beta.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -114,6 +114,44 @@ PERMISSION_HEADER_RULES = {
114
114
  PERMISSION_ACTION_TERMS = ["创建", "查看", "编辑", "删除", "提交", "审批", "导航"]
115
115
  PERMISSION_DENY_TERMS = ["禁止", "不可", "无权限", "隐藏", "只读", "不适用"]
116
116
 
117
+ REVIEW_RECORD_TABLES = {
118
+ "流程评审记录": ["流程评审记录", "设计评审记录"],
119
+ "业务确认问答": ["业务确认问答", "业务确认记录", "确认问答"],
120
+ "待确认事项": ["待确认事项"],
121
+ }
122
+
123
+ # System identifiers that must not appear in reader-facing prose. Each pattern
124
+ # catches a shape that carries no business meaning for a business reader.
125
+ #
126
+ # `\b` is unusable here on two counts: `_` is a word character, so it never forms
127
+ # a boundary inside snake_case keys; and CJK characters are word characters too,
128
+ # so `本流程编号flow454372735由系统生成` has no boundary at all. Since Chinese prose
129
+ # is the normal case, every pattern guards on ASCII characters explicitly.
130
+ _KEY_LEFT = r"(?<![A-Za-z0-9_])"
131
+ _KEY_RIGHT = r"(?![A-Za-z0-9_])"
132
+ SYSTEM_IDENTIFIER_PATTERNS = [
133
+ (rf"{_KEY_LEFT}flow\d{{6,}}{_KEY_RIGHT}", "流程编号(如 flow454372735)"),
134
+ (rf"{_KEY_LEFT}ctx\.[A-Za-z_$][\w$]*", "系统变量(如 ctx.status、ctx.$PROJECT)"),
135
+ (rf"{_KEY_LEFT}\$CAN_[A-Z_]+{_KEY_RIGHT}", "权限变量(如 $CAN_DELETE)"),
136
+ (rf"{_KEY_LEFT}(?:form_template|flow_page_template|data_set_field|data_set|plugin_[a-z0-9_]+){_KEY_RIGHT}", "配置对象键名"),
137
+ (rf"{_KEY_LEFT}[a-z][a-z0-9]*(?:_[a-z0-9]+)*_id{_KEY_RIGHT}", "字段键名(如 form_template_id)"),
138
+ (rf"{_KEY_LEFT}sn_number{_KEY_RIGHT}", "程序类型名"),
139
+ (rf"{_KEY_LEFT}(?:auto_action|enable_auto_action|bpmax_lint){_KEY_RIGHT}", "配置项键名"),
140
+ (rf"{_KEY_LEFT}flow_type{_KEY_RIGHT}", "流程类型键名"),
141
+ (rf"{_KEY_LEFT}/api/[a-z0-9_/{{}}:.-]+", "接口路径"),
142
+ (rf"{_KEY_LEFT}(?:null|undefined|true|false){_KEY_RIGHT}", "程序取值"),
143
+ ]
144
+
145
+ # Sections whose text is meant for implementers, where identifiers are legitimate.
146
+ IMPLEMENTATION_SECTION_TERMS = [
147
+ "BPMAX 实现边界",
148
+ "实现边界",
149
+ "配置对象",
150
+ "对应配置",
151
+ "字段字典",
152
+ "流程数据集",
153
+ ]
154
+
117
155
 
118
156
  @dataclass
119
157
  class Finding:
@@ -308,6 +346,165 @@ def extract_flows(xml: str) -> list[FlowSection]:
308
346
  return flows
309
347
 
310
348
 
349
+ def validate_review_record(findings: list[Finding], xml: str) -> None:
350
+ """Require the design-review and user-confirmation record.
351
+
352
+ A blueprint can be structurally complete and still be wrong for the business.
353
+ The record is the only durable place where review findings and the user's
354
+ answers live, so its absence means those decisions exist nowhere.
355
+ """
356
+ for label, title_terms in REVIEW_RECORD_TABLES.items():
357
+ # Match the heading itself, not any text containing the term: a stray
358
+ # 「待确认」 in an unrelated heading must not satisfy this gate.
359
+ sections = [
360
+ content
361
+ for _, title, content in extract_heading_sections(xml)
362
+ if _heading_matches(title, title_terms)
363
+ ]
364
+ if not sections:
365
+ add_error(
366
+ findings,
367
+ "REVIEW_RECORD_MISSING",
368
+ f"Blueprint must record the design review and business confirmation: missing 「{label}」.",
369
+ )
370
+ continue
371
+ tables = [table for section in sections for table in extract_tables(section)]
372
+ if not tables:
373
+ add_error(
374
+ findings,
375
+ "REVIEW_RECORD_TABLE_MISSING",
376
+ f"「{label}」must be presented as a table.",
377
+ )
378
+ continue
379
+ # An empty table is an unfilled placehorder, not a record. `待确认事项` is
380
+ # allowed to say 无 — but it must say it in a row.
381
+ if not any(table.rows for table in tables):
382
+ add_error(
383
+ findings,
384
+ "REVIEW_RECORD_ROW_MISSING",
385
+ f"「{label}」table has no data row; record the findings/answers, or state 无 explicitly.",
386
+ )
387
+
388
+
389
+ def _heading_matches(title: str, terms: Iterable[str]) -> bool:
390
+ """True when the heading *is* the section, allowing a numeric prefix and a suffix.
391
+
392
+ `待确认` appears inside many ordinary headings (「待确认的业务背景」), so a
393
+ substring test would let an unrelated table satisfy the review-record gate.
394
+ But a real heading may also be annotated (`待确认事项(持续更新)`), so allow a
395
+ trailing parenthetical or colon after the term.
396
+ """
397
+ stripped = re.sub(r"^[\d.、\s]+", "", title).strip()
398
+ for term in terms:
399
+ if stripped == term:
400
+ return True
401
+ if re.match(rf"^{re.escape(term)}(?:[::]|(|\()\s*.*$", stripped):
402
+ return True
403
+ return False
404
+
405
+
406
+ def _identifier_free_prose(xml: str) -> list[tuple[str, str]]:
407
+ """Return (section title, prose text) for sections meant for business readers.
408
+
409
+ Implementation sections are skipped: identifiers there are the point. Only
410
+ the innermost section is returned, because a parent heading's content already
411
+ contains its children and would otherwise report the same leak twice.
412
+ """
413
+ headings = list(re.finditer(r"<h([1-4])[^>]*>(.*?)</h\1>", xml, re.S))
414
+ results: list[tuple[str, str]] = []
415
+ for index, match in enumerate(headings):
416
+ level = int(match.group(1))
417
+ title = plain_text(match.group(2)).strip()
418
+ if _is_implementation_heading(title):
419
+ continue
420
+ end = len(xml)
421
+ for next_match in headings[index + 1 :]:
422
+ # A following heading at the same or shallower level ends this section.
423
+ if int(next_match.group(1)) <= level:
424
+ end = next_match.start()
425
+ break
426
+ else:
427
+ end = len(xml)
428
+ content = xml[match.end() : end]
429
+ # If a child heading exists, this section's own prose ends before it.
430
+ child = re.search(r"<h[1-4]\b", content)
431
+ if child:
432
+ content = content[: child.start()]
433
+ results.append((title, f"{title} {_scan_text(content)}"))
434
+ return results
435
+
436
+
437
+ def _is_implementation_heading(title: str) -> bool:
438
+ """True only when the heading *is* the implementation section.
439
+
440
+ Substring matching would exempt `6.6 流程数据集口径` entirely, hiding real
441
+ business prose; the section name has to be the whole heading or its tail.
442
+ """
443
+ stripped = re.sub(r"^[\d.、\s]+", "", title).strip()
444
+ return any(
445
+ stripped == term or stripped.endswith(term)
446
+ for term in IMPLEMENTATION_SECTION_TERMS
447
+ )
448
+
449
+
450
+ def _scan_text(content: str) -> str:
451
+ """Text a business reader actually reads: prose, node labels, and table cells.
452
+
453
+ Tables and diagrams are checked, not stripped — the node tables and the
454
+ process diagram are where a leaked `flow454372735` does the most damage. The
455
+ only exception is the navigation table's 路由/页面 column, whose values are
456
+ URLs by design.
457
+
458
+ Implementation sections are exempt entirely and never reach here.
459
+ """
460
+ return plain_text(_drop_route_cells(content))
461
+
462
+
463
+ def _drop_route_cells(content: str) -> str:
464
+ """Blank the 路由/页面 column of any table that has one, elsewhere keep it."""
465
+ replaced: list[str] = []
466
+ for table in re.findall(r"<table\b.*?</table>", content, flags=re.I | re.S):
467
+ rows = re.findall(r"<tr\b[^>]*>.*?</tr>", table, flags=re.I | re.S)
468
+ if not rows:
469
+ continue
470
+ header_cells = [
471
+ plain_text(cell).strip()
472
+ for cell in re.findall(r"<(?:th|td)\b[^>]*>(.*?)</(?:th|td)>", rows[0], flags=re.I | re.S)
473
+ ]
474
+ route_index = next(
475
+ (index for index, name in enumerate(header_cells) if "路由" in name or "页面" in name),
476
+ None,
477
+ )
478
+ if route_index is None:
479
+ continue
480
+ scrubbed = table
481
+ for row in rows[1:]:
482
+ row_cells = re.findall(r"<(?:td|th)\b[^>]*>.*?</(?:td|th)>", row, flags=re.I | re.S)
483
+ if len(row_cells) > route_index:
484
+ scrubbed = scrubbed.replace(row_cells[route_index], " ", 1)
485
+ replaced.append((table, scrubbed))
486
+ for original, scrubbed in replaced:
487
+ content = content.replace(original, scrubbed, 1)
488
+ return content
489
+
490
+
491
+ def validate_business_language(findings: list[Finding], xml: str) -> None:
492
+ """Reject system identifiers in sections a business reader is meant to read."""
493
+ seen: set[tuple[str, str]] = set()
494
+ for title, prose in _identifier_free_prose(xml):
495
+ for pattern, description in SYSTEM_IDENTIFIER_PATTERNS:
496
+ for match in re.finditer(pattern, prose):
497
+ key = (title, match.group(0))
498
+ if key in seen:
499
+ continue
500
+ seen.add(key)
501
+ add_error(
502
+ findings,
503
+ "BUSINESS_LANGUAGE_IDENTIFIER",
504
+ f"章节「{title}」出现{description}:{match.group(0)}。改用业务名称;标识符只放在实现边界/配置表格里。",
505
+ )
506
+
507
+
311
508
  def add_error(findings: list[Finding], code: str, message: str, flow: str | None = None) -> None:
312
509
  findings.append(Finding("error", code, message, flow))
313
510
 
@@ -529,6 +726,9 @@ def lint(xml: str, require_terms: list[str], forbid_terms: list[str]) -> tuple[l
529
726
  )
530
727
  validate_matrix_design(findings, matrix_sections)
531
728
 
729
+ validate_review_record(findings, xml)
730
+ validate_business_language(findings, xml)
731
+
532
732
  flows = extract_flows(xml)
533
733
  if not flows:
534
734
  add_error(findings, "FLOW_SECTION_MISSING", "No flow sections matching 流程X: were found.")
@@ -72,6 +72,7 @@ description: "用于通过 bpmax-cli typed config 能力创建和编辑 BPMAX
72
72
  | 本地临时文件闭环、work/submit 映射 | `references/local-temp-workflow.md`, `references/work-file-to-submit-mapping.md` |
73
73
  | payload 自检和差量策略 | `references/payload-checklist.md`, `references/diff-strategy.md` |
74
74
  | 脚本硬规则、beforeNextStepScript、创建页 gotcha | `references/script-review-hard-rules.md`, `references/before-next-step-script-runtime-gotchas.md`, `references/project-create-runtime-gotchas.md` |
75
+ | 消息模板专业标准、正反例、禁发 ack、抄送标准 | `references/message-card-professional-standard.md` |
75
76
  | meta / node 字段和占位符 | `references/runtime-verified-meta-fields.md`, `references/runtime-verified-node-fields.md`, `references/config-surfaces-and-placeholders.md` |
76
77
  | 节点详情、运行态与草稿差异 | `references/runtime-verified-flow-detail-shape.md`, `references/editor-runtime-vs-draft.md` |
77
78
  | 需求到节点、意图模型 | `references/requirement-to-node-mapping.md`, `references/intent-model.md` |
@@ -110,6 +111,8 @@ description: "用于通过 bpmax-cli typed config 能力创建和编辑 BPMAX
110
111
  - `standard` 模式:`message_template_simple` / `*_message_template_simple` 是对象,每个字段各自 `return` 字符串。
111
112
  - 返回裸字符串(如 `return "请处理【环节】。";`)是错的。需要禁止外发时,code 模式写 `return "";`;绝不能把 `message_template` 留空,空值会触发默认消息。
112
113
  - semantic lint 已将 code 模式返回非对象、standard 字段返回非脚本串、空模板、字面量 URL 设为 hard error。
114
+ - 消息模板必须符合 `references/message-card-professional-standard.md` 的专业卡片标准(标题写业务语义、正文写清谁/什么事/需要你做什么、至少一个跳转按钮、按紧急度选色);lint 会对结构不专业和节点消息必要性给出门禁/告警,包括 `bpmax_lint.suppressed_node_messages` 的 ack 要求。
115
+ - 模板返回的是 BPMAX 自有消息对象,不是飞书 Card JSON;返回 `schema`/`body` 的 Card 2.0 结构、且 title/content/elements/actions 四个业务键全缺时,后端会判定为空并**静默不发**。单独带一个 `header` 不影响发送,只是被忽略的冗余键。
113
116
 
114
117
  ## 条件跳转与审批动作
115
118
  - 开始条件跳转使用 `meta.condational_jump`。源码依据:`ProjectModel.getStartNodeId()` 按数组顺序执行,`condition_mode` 为空或 `code` 时执行 `condition`,`condition_mode === "standard"` 时执行 `standard_condition`。
@@ -249,6 +249,9 @@ bpmax-cli config readback form-template --id <form_template_id> --format json
249
249
  - code 模式返回对象可选附加飞书卡片字段:`elements`(数组,支持 `div/lark_md`、`markdown`、`column_set/column`、`img`、`note`、`person_list`)、`unshiftElements`(插到正文最前)、`color`(卡片标题色,默认 `wathet`),让消息以结构化卡片呈现。
250
250
  - semantic lint 已将“code 模式返回非对象、standard 模式字段返回非脚本串、空模板、字面量 URL”设为 hard error,不得用 `--allow-preexisting-lint-errors` 豁免。
251
251
  - 源码依据:`getMessageContent` 在 `message_config_mode==='standard' && message_template_simple` 时走 `parseSimpleMessageTemplate`,否则走 `parseScriptMessageTemplate`;两者返回值形态不可互换。飞书卡片由 `feishu.messageAdaptor` 消费 `data.title/content/elements/unshiftElements/actions/color`。
252
+ - **警告:返回飞书 Card 2.0 JSON 会静默失败。** 模板返回的是 BPMAX 自有消息对象,不是飞书 Card JSON。写成 `{ schema: "2.0", body: { elements: [...] } }`(即 title/content/elements/actions 四个业务键全缺)时,`messageAdaptor` 会判定消息无效,直接 `return []`,只留一条 `[messageAdaptor:无效的消息内容]` 日志 —— 不报错、不兜底默认消息,表现为「配置保存成功但消息不发」。注意判空口径是**四个业务键全缺**,不是「出现 header 就算坏」:真实存量里有同时带完整业务键和多余 `header` 的模板,后端会忽略 `header` 正常发送(只记 warning)。真实生产配置中真正的 Card 2.0 用量为 0,不要发明新结构。
253
+ - 标题配色由 `color`(code)/ `title_color`(standard)控制,后端默认 `wathet`;可按紧急度换色(完成/归档 `green`,临期 `orange`/`yellow`,驳回异常 `red`/`carmine`,抄送 `turquoise`/`purple`),但颜色不能替代标题里的业务语义。
254
+ - 专业卡片标准(标题写业务语义、正文写清谁/什么事/需要做什么、至少一个跳转按钮、按紧急度选色)、正反例对照、`return "";` + `bpmax_lint.suppressed_node_messages` 的 ack 规则、各环节是否需要发消息的判断清单、抄送模板标准,统一见 [message-card-professional-standard.md](message-card-professional-standard.md);本节只保留模式与字段事实,不重复专业标准。
252
255
  - 创建链路中 `meta.project_create_validator` 在单号/流水号生成之后执行。它可以拒绝缺失或不一致的数据,不能在不消耗流水号的前提下修复已经生成的单号;涉及 `sn_number.field_reference` 的问题,应优先在表单侧通过 `ctx.$setValueByKeyToValue(...)` 触发前端订阅刷新,流程级创建校验只做后端兜底拒绝。
253
256
  - 后端单号生成使用提交 payload 中字段规则里的 `result` / `options[].result`,不会重新按当前表单值计算 `field_reference`。校验脚本如需判断“单号是否包含门店编码”,应同时检查提交值、`projectForm.value` / `key_to_value` 和单号字符串本身,避免只看隐藏字段存在就放行。
254
257
  - 对“新增节点后立刻验证流转”的场景,回归样本优先用新建项目,不要优先复用已经跑过旧配置的历史项目;历史 `step` 记录不会自动套用新节点骨架,容易把旧 step 状态、旧 target_step 和缓存误判成新配置问题。
@@ -953,6 +956,7 @@ bpmax-cli config readback form-template --id <form_template_id> --format json
953
956
  - 编辑器运行时与草稿差异排查: [editor-runtime-vs-draft.md](editor-runtime-vs-draft.md)
954
957
  - 页面已验证的流程级字段: [runtime-verified-meta-fields.md](runtime-verified-meta-fields.md)
955
958
  - 页面已验证的节点级字段: [runtime-verified-node-fields.md](runtime-verified-node-fields.md)
959
+ - 消息卡片专业标准与正反例: [message-card-professional-standard.md](message-card-professional-standard.md)
956
960
  - 保存草稿请求形态: [save-draft-request-shape.md](save-draft-request-shape.md)
957
961
  - BPMAX 管理台总览: <https://doc.bpmax.cn/guide/admin/>
958
962
  - BPMAX 高级流程配置: <https://doc.bpmax.cn/guide/admin/advanced.html>
@@ -0,0 +1,234 @@
1
+ # 流程消息卡片专业标准
2
+
3
+ 面向流程配置执行者:当你为 BPMAX 流程节点、流程级抄送、项目结束通知写 `message_template` / `message_template_simple` / `cc_message_template` 时,按本文件判断"能不能发、发得对不对、发得专不专业"。
4
+
5
+ 本文件只写"专业标准"增量。两种模式的字段事实和源码调用链见 `full-detail-guide.md`「消息模板分两种配置模式」一节;本文件不重复字段清单,只补标准、正反例和门禁判断。
6
+
7
+ ## 0. 先记住这一条:返回的是 BPMAX 自有消息对象,不是飞书 Card JSON
8
+
9
+ 这是本主题里最容易犯、后果最严重的错误,所以放在最前面。
10
+
11
+ code 模式脚本 `return` 的对象必须是 BPMAX 自有消息结构:
12
+
13
+ ```js
14
+ return {
15
+ title: '...',
16
+ content: '...', // 字符串;simple 模式是 content[0].body
17
+ actions: [{ type: 'link', btnType: 'primary', text: '...', url: '/...', m_url: '/...' }],
18
+ color: 'wathet',
19
+ messageType: 'step',
20
+ };
21
+ ```
22
+
23
+ 它不是飞书 interactive card,也不是飞书 Card 2.0。下面这类写法是错的:
24
+
25
+ ```js
26
+ // 错误:飞书 Card 2.0 结构
27
+ return {
28
+ schema: '2.0',
29
+ body: { elements: [{ tag: 'markdown', content: '请审批' }] },
30
+ };
31
+ ```
32
+
33
+ 后果链(已从后端源码确认):
34
+
35
+ 1. `messageAdaptor` 只用四个业务字段判断消息是否有效:`content`、`title`、`elements?.length`、`actions?.length`。
36
+ 2. Card 2.0 的顶层只有 `schema` / `body`,四个业务键全空 → 判定为无效消息。
37
+ 3. 函数直接 `return []`,只打一条 `[messageAdaptor:无效的消息内容]` 日志。
38
+ 4. 最终结果是**消息静默不发**:没有报错、没有默认消息兜底,配置看起来"保存成功"。
39
+
40
+ 判定的准确口径:**只有 title / content / elements / actions 四个业务键全部缺失时才判定为空消息**。单独出现 `header` / `config`(或 `schema` 但仍有业务键)并不导致消息丢失——后端会忽略这些多余键、照常按业务键发送。真实存量里就有同时带 `title/content/elements/actions` 和一个额外 `header` 的模板(`sysconfig-cltxdev` / `sysconfig-hoocoo` 的 `flow541143431`),消息正常发出。因此:
41
+
42
+ - 四个业务键全缺 → lint **error**(`flow.message.card_no_business_keys`,消息真的不会发)。
43
+ - 业务键存在、同时带了 `schema`/`body`/`header`/`config` → lint **warning**(`flow.message.card2_key_ignored`),提示这些键被忽略、容易被误读为飞书原生卡片。
44
+ - 只带 `header`/`config` 而没有 `schema`/`body`,且没有业务键 → 同上 error(现有键里没有任何业务键,消息同样不会发)。
45
+ - 带 `schema`/`body` 但对象里还有 `spread` 或 `Object.assign` 的不可解析实参 → **warning**(`flow.message.card_schema_unsupported`):静态分析无法证明业务键缺失,需人工确认运行时会补出 title/content/actions;全字面量时仍按 error 处理。
46
+
47
+ 同样被丢弃的还有所有未知顶层字段。平台发送前还会把 `project`、`messageType`、`currentStep` 从落库内容里剔除,因此不要把自己的业务字段塞进这几个对象里期望被渲染。
48
+
49
+ 全量统计(2340 个流程配置)中 Card 2.0 用量为 0,`code` 模式 40783 处,`standard/simple` 对象模式仅 83 处 —— 说明真实生产配置全部走自有消息对象,不要发明新结构。
50
+
51
+ 源码证据:`huanpingtong-server/src/service/feishu.js` 的 `messageAdaptor`(有效性判断、硬编码重建卡片);`huanpingtong-server/src/model/message.js` 的 `getMessageContent` / `sendMessage`。
52
+
53
+ ## 1. 后端实际消费哪些字段
54
+
55
+ | 字段 | 作用 | 备注 |
56
+ | --- | --- | --- |
57
+ | `title` | 卡片标题 | 纯文本渲染,不解析 Markdown |
58
+ | `content` | 正文第一段 | 按 `lark_md` 渲染,支持换行和简单 Markdown |
59
+ | `elements` | 追加正文块 | 支持 `div/lark_md`、`markdown`、`column_set/column`、`img`、`note`、`person_list` |
60
+ | `unshiftElements` | 插到正文最前的块 | 常用来放单号、金额、申请人等摘要 |
61
+ | `actions[]` | 按钮 | 消费 `text`、`url`、`m_url`、`btnType`、`is_absolute` |
62
+ | `color` | 标题栏配色 | 后端 `template: data.color || 'wathet'` |
63
+ | `messageType` | 决定移动端按钮跳转包装方式 | `step` 走「消息中转 + `m_url`」的环节待办跳转;其它值优先用按钮的 `inAppLink`,否则走站内拼接 |
64
+ | `popup` | 是否弹窗提示 | 真实存在,但不要用来替代正文信息 |
65
+
66
+ 必须同时知道的三条运行时行为:
67
+
68
+ - **simple 模式只读第一个正文块**:后端取 `content?.[0]?.body`。写在 `content[1]`、`content[2]` 的内容不会渲染。多行内容请放在同一个 `body` 里用换行拼接。
69
+ - **simple 模式没有 actions 会自动补一个"查看"按钮**:指到 `/projectContinue`。看起来"能用",但按钮文案和跳转都不体现业务语义,属于隐性降级。
70
+ - **simple 模式标题或正文为空会走默认文案**:默认标题是"新的流程消息",默认正文是"「项目名」项目「环节名」环节需要你处理,请前往查看"。很多配置"看起来有卡片",其实全靠这个默认值在撑,等于固定文案标题。code 模式没有这层兜底:`return {};` 会一路走到 `messageAdaptor`,被判为无效消息后不生成卡片,也不会补默认文案;而平台消息记录(`think_platform_message`)在解析模板之前就已经写入,于是出现"站内有待办记录、外部渠道没收到卡片"的不一致。只有 `return "";` 才会在 `buildStepMessage` 解析后、发送前提前停止。
71
+
72
+ 模式值本身也有坑:后端分支判断的是 `message_config_mode === 'standard'` 且 `message_template_simple` 存在。写成 `simple` 不会被命中,会回落到 `message_template`(通常为空)或默认消息。**对象模式请写 `standard`**;本地配置镜像里确有少量节点写成 `simple`,这些节点的自定义卡片按当前后端逻辑不会生效。
73
+
74
+ 链接形态(决定按钮点开去哪里):
75
+
76
+ - `url` 是站内 PC 路径,必须以 `/` 开头,后端会拼上工作区前缀;`m_url` 是移动端路径,后端拼 `/#/工作区`。
77
+ - 指向外部系统时用 `is_absolute: true`,否则会被错误地拼成站内地址。
78
+ - standard / simple 模式下 `actions[].url` / `m_url` 字段本身是**脚本**:后端 `parseTemplateString` 把它当函数体执行,没有 `return` 就得到 `undefined`,最终按钮 URL 会拼成 `/工作区undefined`。所以这里必须写 `return '/projectContinue?id=' + ...`,不能只写模板字符串字面量。code 模式则相反,`url` 直接就是求值后的字符串。代码模式节点上的 `message_template_simple.actions[].url` 若含 `${...}` 插值却不是函数体,会报错;standard 模式下 literal URL 目前不会被 lint 拦下,不能靠 lint 兜底。
79
+
80
+ ## 2. 专业卡片由四件事构成
81
+
82
+ ### 2.1 title:写业务语义,不写"新消息"
83
+
84
+ 合格标题至少包含"业务对象 + 环节/动作",让用户不进系统就能判断要不要现在处理。
85
+
86
+ - 好:`ZD02制度修订/废止待处理:部门领导`
87
+ - 好:`XS02 销售订单变更:部门负责人`
88
+ - 好:`CW08非合同付款流程已完成`
89
+ - 差:`您有新消息`、`新的流程消息`、`待办提醒`、`流程通知`
90
+
91
+ 真实配置中合格标题的共同点是:`流程编号/名称 + 环节名`,或用变量拼出项目名(`ctx.$PROJECT?.name`)。标题里的变量必须能取到值,否则会渲染成空串或 `undefined`。
92
+
93
+ lint 口径(`flow.message.card_title_static`):**只有整句都是泛化词时才告警**——去掉"新的流程消息 / 您有新消息 / 待办提醒 / 流程通知 / 待处理"等泛化片段和标点、数字后不再剩任何业务词;含流程编号(如 `CW08`、`ZD02`)、单据/流程类型词或环节名的固定标题都算合格,不告警。存量里 1383 条固定标题属于这一类合格标题。
94
+
95
+ **注意:simple/standard 的字段是脚本,不是字面量。** 后端 `parseTemplateString` 把每个字段(`title`、`content[i].body`、`actions[].url`/`m_url`)交给 `parseEvalFunction`,按**函数体** eval。写成普通字面量(`title: "采购审批待处理"`,没有 `return`)时函数体没有返回值,运行时得到 `undefined`,`|| ''` 后实际是空串——编辑器里看得到文字,收件人收到的却是默认文案。这类字段会报 `flow.message.simple_field_missing_return`,并连带触发 `card_title_empty`/`card_content_empty` 或 `missing_for_human_node`。正确写法是 `return "采购审批待处理"` 或 `` return `采购审批待处理:${step.name}` ``。
96
+
97
+ ### 2.2 content:谁、什么事、需要你做什么
98
+
99
+ 正文建议三段式,用换行连接:
100
+
101
+ 1. 谁/什么事:单号、申请人、项目名等能唯一定位的业务标识;
102
+ 2. 当前状态:到了哪个环节、因为什么到这里;
103
+ 3. 需要你做什么:审批、修改、确认、知悉。
104
+
105
+ 真实正例(来自生产配置):
106
+
107
+ ```js
108
+ content: [
109
+ `${ctx.$i18n('单号')}:${requestNo}`,
110
+ ctx.$i18n('请审批特殊出差申请。'),
111
+ ].join('\n')
112
+ ```
113
+
114
+ ```js
115
+ content: `【${ctx.$PROJECT.name}】已结束,请悉知`
116
+ ```
117
+
118
+ 差例:`请处理`、`您有一条待办`、`请查看`。这类文案在收件箱里和十条其它待办无法区分。
119
+
120
+ ### 2.3 actions:至少一个跳转,文案要具体
121
+
122
+ - 数量:至少 1 个;审批类建议 1 个主按钮即可,不要把"同意/驳回"做成消息按钮(动作要回前端走后端流程动作,消息按钮只负责跳转)。
123
+ - 文案:`查看并审批`、`填写处理`、`查看订单`,不要只写"查看"(simple 模式默认就是"查看",等于没写)。
124
+ - 类型:code 模式固定 `type: 'link'`;simple 模式的 `actions[0].type` 会变成 `messageType`,环节待办用 `step`,项目详情用 `project`,但 `link` 也是合法的——后端 `parseSimpleMessageTemplate` 固定把每个按钮的 `type` 改写成 `'link'`,`m_url` 仍会变成 `inAppLink`,所以 `type: 'link'` 不会让按钮失效,lint 允许它。`none/step/project/custom` 之外的值仍会报 `flow.message.action_invalid`。
125
+ - 跳转:环节待办用 `/projectContinue?id=<project_id>&step_id=<step_id>`,移动端 `/pages/taskDetails/taskDetails?id=...`;完成/归档通知指向项目页。
126
+ - 实参要带兜底:`step?.project_id || ctx?.$PROJECT?.id`,避免某个上下文缺字段导致按钮 URL 变成 `undefined`。
127
+
128
+ ### 2.4 color:按紧急度选色,不要全靠默认
129
+
130
+ 标题色由 `color`(code 模式)或 `title_color`(simple 模式)控制,后端默认 `wathet`。前端真实可选 12 个值,按语义用:
131
+
132
+ | 场景 | 推荐色 | 说明 |
133
+ | --- | --- | --- |
134
+ | 常规待办:审批、填写、确认 | `wathet` | 默认色;真实配置绝大多数使用此色,可读性最好 |
135
+ | 通过、完成、归档 | `green` | 正向结束语义 |
136
+ | 临期、待关注、需要催办 | `orange` 或 `yellow` | 提醒但不等于失败 |
137
+ | 驳回、拒绝、异常、退单 | `red` 或 `carmine` | 负向语义 |
138
+ | 抄送、知会(非主待办) | `turquoise` 或 `purple` | 与主待办区分,别用灰色降低可读性 |
139
+ | 一般不用 | `grey` | 对比度低,重要信息容易漏看 |
140
+
141
+ 同一流程内不要超过 3 种颜色。颜色是辅助信号,不能替代标题里的语义。
142
+
143
+ ## 3. 正例 / 反例对照
144
+
145
+ | # | 反例 | 问题 | 正例 |
146
+ | --- | --- | --- | --- |
147
+ | 1 | `return { schema: '2.0', body: { elements: [] } }` | 飞书 Card 2.0;后端判空,消息静默不发 | 返回 `{ title, content, actions, color, messageType }` 自有消息对象 |
148
+ | 2 | `return "请处理【环节】。";` | 裸字符串;truthy 进入发送链路但无法渲染卡片,也发不出有效消息 | `return { title: 'XS02销售订单变更:部门负责人', content: '单号:...\n请审批', actions: [...] }` |
149
+ | 3 | 只写 `title` + `content`,`actions` 为空 | 用户只能读不能跳,必须自己找环节;simple 模式下还会被后端补成通用"查看" | 至少一个 `text: '查看并审批'` 的跳转按钮,指向 `/projectContinue` |
150
+ | 4 | `title: '您有新消息'` / `title: '新的流程消息'` | 固定文案,无项目、无环节、无动作指向;多条待办在收件箱完全不可区分 | `title: 'ZD02制度修订/废止待处理:部门领导'`(流程 + 环节) |
151
+ | 5 | simple 模式把多段正文分别放在 `content[0]`、`content[1]` | 后端只读 `content[0].body`,后续内容全部丢失 | 合并为 `content: [{ body: '单号:...\n请审批' }]` |
152
+ | 6 | 该发消息的审批节点留空 `message_template` | 走默认文案"新的流程消息",看起来"配了"其实没有业务信息 | 写完整卡片;确实不需要通知的节点才用 `return "";` + ack |
153
+
154
+ ## 4. `return "";` 的正确用法
155
+
156
+ `return "";` 是**显式禁发**,不是"占位"。返回空串后 `buildStepMessage` 判空直接 return,不再发送,也不会触发后端默认文案。留空串 `""`(空模板)反而会触发默认消息,两者语义完全相反。
157
+
158
+ 什么时候该显式禁发:
159
+
160
+ - 系统自动节点、定时/数据回写节点、子流程父节点的汇总等待态(无真实办理人)。
161
+ - 中间过渡态:如"申请人修改"由创建人自己完成,且前置申请页已提示过,不需要再打扰。
162
+ - 已经从别的渠道通知过(例如插件已发飞书群消息),且主消息会重复刷屏。
163
+
164
+ 什么时候不该用:
165
+
166
+ - 只要节点有真实办理人(审批人、填写人、矩阵/角色/字段取值算出的负责人),禁发会导致该人没有待办入口提醒。
167
+ - 用禁发来"绕过"消息模板没写完:这是把配置缺口藏起来。
168
+
169
+ 门禁与 ack:
170
+
171
+ - 有真实办理人 + 静态禁发且没有 ack → lint hard error `[flow.message.suppression_requires_ack]`。
172
+ - 无真实办理人 + 静态禁发且没有 ack → warning `[flow.message.suppression_unacked]`,允许通过但要人工确认。
173
+ - 加 ack 后只剩说明性 warning `[flow.message.suppression_acked]`。
174
+ - 运行时可能返回空串(条件分支)→ warning `[flow.message.suppression_dynamic]`,必须运行态证明消息仍会发。
175
+ - ack 写在 work 文件的 `bpmax_lint.suppressed_node_messages[]`,每项 `{ node_id, channel, reason }`,`channel` 只能是 `message` 或 `cc`,`reason` 非空。
176
+ - ack 必须精确对应某个节点的静态空返回,且普通消息与抄送**互不抵扣**:只 ack 了 `cc`,普通消息仍然报错。
177
+ - ack 必须指向真实存在的节点 id,否则本身报错。
178
+ - **"静态禁发"不止 `return "";`**:`return;`、`return null;`、`return undefined;`、`return [];` 在运行期同样得到空值/空数组,`buildStepMessage` 判空后一样不发消息,所以走同一套 ack 门禁。存量里 `return;` 66 个、`return null` 51 个,以前几乎零告警。
179
+ - `return {};` 走另一条 error:`[flow.message.card_no_business_keys]`(见第 0 节),也可以用同一个 ack 声明为有意禁发。
180
+ - 上述 ack 门禁覆盖显式 `code` 模式,以及**没写模式但带非空 `message_template`** 的节点(后端同样按 code 执行)。`standard/simple` 模式的空字段走的是 `simple_field_missing_return` / `*_empty` 一类告警,不触发 ack 门禁。
181
+
182
+ 流程级(meta)消息走各自的模式开关,没有节点 ack 可挂:
183
+
184
+ - 项目创建抄送:`data.meta.cc_message_template` + `project_cc_message_config_mode`,对象模式字段是 `project_cc_message_template_simple`。
185
+ - 项目结束通知项目负责人:源码读的字段名是拼错的 `notify_project_owner_on_end_message_tempalte`(`template` 少一个 `e`,后端 `project.ts` 与前端编辑器 v-model 都按这个拼写读写),对象模式字段是 `notify_project_owner_on_end_message_template_simple`。写成正确拼写 `..._template` 的模板不会被任何代码读取;本地镜像里有 13 处配置用了正确拼写且没有对应的拼错字段,属于"配了但不生效"。另外发送前还要求 `enable_notify_project_owner_on_end = true`,否则 `project.ts` 在读取模板之前就整段 return——此时无论模板写成 `standard` 还是 `simple` 都不会执行,lint 也不再对它报错(报"收件人只会收到默认消息"是错误诊断,会无谓挡住提交)。
186
+ - 结束节点通知:`meta.success_end_config` / `meta.fail_end_config` 里的 `message_template` + `project_end_message_config_mode`,且必须同时 `enable_end_message=true` 与 `notify_users` 非空才会发。
187
+
188
+ 这几处要停发,就删掉模板或关掉对应的 `enable_*` 开关;它们没有节点 ack 可挂,写 `return "";` 只会得到一条空内容消息(项目创建抄送/结束通知的 `withDefault=false`,空内容会直接不发送,但这不是可审计的 ack)。
189
+
190
+ ## 5. 这个环节到底要不要发消息
191
+
192
+ | 环节类型 | 判断 | 做法 |
193
+ | --- | --- | --- |
194
+ | 审批、审核、会签、确认、填写、修改 | 有人要处理 | 必须发,专业卡片 + 跳转按钮 |
195
+ | 转办目标环节 | 新负责人要处理 | 必须发;转办通知走 `step_transfer_message_template` 系列 |
196
+ | 归档、结束通知 | 有人需要知道结果 | 对申请人/负责人发完成通知,标题体现"已完成/已归档",用 `green` |
197
+ | 系统等待、汇总、子流程父节点(`auto_trigger_flows` 非空、`approve_count_required` 为 0/空) | 无真实办理人 | 不发;若平台会创建待办壳,才用 `return "";` + `suppressed_node_messages` ack |
198
+ | 纯自动节点(定时、回写、数据同步) | 无真实办理人 | 不发;不写模板即可,确需阻止平台默认消息时用 `return "";` + ack |
199
+ | 需要知会的下游角色(财务、仓库、HRBP 等) | 有人要知道,但不需要他办理 | 走抄送模板,不要把这些角色塞进主消息收件人 |
200
+ | 项目创建成功 | 申请人要知道已提交 | 用 `meta.cc_message_template` 或项目创建消息,不要靠节点消息代发 |
201
+
202
+ 判断口径只有一句:**这个节点存在一个"必须打开系统才能推进"的人吗?** 有就发,没有就禁发或改抄送。
203
+
204
+ ## 6. 抄送消息模板
205
+
206
+ 抄送是独立字段,渲染链路与主消息完全相同,因此部分"抄送就是一句话"的写法不成立:
207
+
208
+ - 节点抄送:`cc_message_template` + `step_cc_message_config_mode`(`code`),或 `step_cc_message_template_simple` + `step_cc_message_config_mode: 'standard'`。
209
+ - 项目级抄送(项目创建时):`meta.cc_message_template` + `project_cc_message_config_mode`,对象模式字段 `project_cc_message_template_simple`。
210
+ - 项目结束通知项目负责人:字段名是拼错的 `notify_project_owner_on_end_message_tempalte`(+ `_template_simple`)配 `notify_project_owner_on_end_message_config_mode`,并要求 `enable_notify_project_owner_on_end=true`。
211
+ - 转办通知:`step_transfer_message_template` / `step_transfer_message_template_simple` + `step_transfer_message_config_mode`。
212
+
213
+ 抄送卡片同样要满足第 2 节四要素,并且明确说明"为什么通知你":
214
+
215
+ - 标题:`抄送:XS02 销售订单变更 - 财务确认`,不要只写"抄送"或"流程抄送"。
216
+ - 正文:单号、项目名、当前环节、抄送原因(如"你作为财务需要关注付款信息")。
217
+ - 按钮:`查看项目`,指向项目详情或环节详情。
218
+ - 颜色:与主待办区分,用 `turquoise` / `purple`;不要用与主消息相同的待办色,避免用户误以为需要自己处理。
219
+
220
+ 禁止的抄送内容:`已抄送你`、`流程已抄送`、仅一个项目名。这类消息没有信息量,属于噪声。
221
+
222
+ 抄送与普通消息的禁发 ack 相互独立:`channel: 'cc'` 不能替 `channel: 'message'` 豁免。
223
+
224
+ ## 7. 提交前自查
225
+
226
+ 1. 结构:返回的是 `{ title, content, actions, ... }` 自有对象;不要写飞书 Card 2.0 的 `schema` / `body`。带了 `header`/`config` 不会被拦,但属于被忽略的多余键,lint 会给 warning。
227
+ 2. 标题:含流程名或编号 + 环节名 / 业务动作,不是"新消息""待办提醒";simple 模式标题不能为空,否则后端用默认「新的流程消息」兜底。
228
+ 3. 正文:有单号或项目名等定位信息,有一句"需要你做什么";simple 模式 `content[0].body` 不能为空,否则后端用默认文案兜底。code 模式 `content` 必须是字符串(数组会被塞进 `lark_md` 且渲染失败)。
229
+ 4. 按钮:至少一个,文案具体,`url` 与 `m_url` 成对,带空值兜底;外链已加 `is_absolute`。code 模式按钮 `type` 不是 `link` 时仍会发送,但点击行为可能不符合预期,lint 会给 warning。
230
+ 5. 颜色:按第 2.4 节选色,未使用 `grey` 承载关键待办;不写颜色时后端默认 `wathet`(推荐色),lint 不再因此告警。
231
+ 6. 模式:对象模式写 `standard`,脚本模式写 `code`。**不要写 `simple`**:后端只判断 `message_config_mode === 'standard'`,写成 `simple` 的卡片不会生效,lint 直接报 error。
232
+ 7. 必要性:每个禁发节点都在 `bpmax_lint.suppressed_node_messages[]` 有 `node_id` + `channel` + 非空 `reason`,且 ack 精确对应静态 `return "";`。
233
+ 8. 抄送:独立检查,标题/正文/按钮达到同一标准,并说明抄送原因;`cc_type` 为 `role` / `user` 且选了接收人时同样必须有抄送模板。
234
+ 9. 验证:先跑 `bpmax-cli config flow-template lint`,再用新样本项目触发该环节,在真实消息收件箱里看到卡片(标题、正文、按钮、颜色四项都对),才能宣称消息模板完成。
@@ -42,6 +42,23 @@
42
42
  - code-mode `message_template` 留空以为能阻止外发;实际会触发后端默认消息,必须显式写 `return "";`(空串是唯一合法的裸字符串返回值)
43
43
  - code-mode 消息卡片按钮 URL 写成 `/projectContinue?id=${step?.project_id}&step_id=${step?.id}`,而不是 `return '/projectContinue?id=' + step.project_id + '&step_id=' + step.id;`
44
44
 
45
+ ## 消息模板硬规则(补充五条)
46
+
47
+ 专业卡片标准全量说明见 [message-card-professional-standard.md](message-card-professional-standard.md)。
48
+
49
+ - **禁止返回 Card 2.0 结构 / 禁止无业务键的返回对象**
50
+ - 判定标准:`message_template` / `cc_message_template` 的返回对象里 title/content/elements/actions 四个业务键**全部缺失**(含 `return {}`、`return { color: 'blue' }`、只带 `header`/`config`),或顶层出现 `schema`/`body` 却没有任何业务键,或把飞书 interactive card 的 `elements/column_set` 当成顶层结构直接 `return`。BPMAX 模板返回的是自有消息对象 `{ title, content, actions, color, messageType }`,不是飞书 Card JSON。单独出现 `header`/`config` 但仍有业务键,不影响发送(后端会忽略),只算冗余。返回对象里带 `spread` 或 `Object.assign` 的不可解析实参时,静态分析无法证明缺键,降为 warning 并要求人工确认。
51
+ - 修法:改成 `return { title: '流程名:环节名待处理', content: '单号:...\n请审批', actions: [{ type: 'link', btnType: 'primary', text: '查看并审批', url: ... , m_url: ... }], color: 'wathet', messageType: 'step' }`。多维内容放 `content` 字符串换行或 `elements`,不要套 Card 2.0。后端 `messageAdaptor` 会丢弃未知字段并判空,Card 2.0 只会静默不发。
52
+ - **禁止固定文案标题**
53
+ - 判定标准:`title` 是常量且**整句只有泛化词**,如 `您有新消息`、`新的流程消息`、`待办提醒`、`流程通知`;或 simple 模式 `title` 为空、靠后端默认值"新的流程消息"兜底。含流程编号(`CW08`/`ZD02`)、单据/流程类型词或环节名的固定标题是合格的,不告警。
54
+ - 修法:标题至少写「流程编号/名称 + 环节名」或「项目名 + 业务动作」,如 `return \`ZD02制度修订/废止待处理:${step.name}\`;`;标题里用到的变量必须能取到值,避免渲染成空串或 `undefined`。
55
+ - **simple/standard 字段必须是带 return 的脚本**
56
+ - 判定标准:后端 `parseTemplateString` 把 `title`、`content[i].body`、`actions[].url`/`m_url` 当**函数体** eval;写成普通字面量(如 `title: "采购审批待处理"`,没有 `return`)时函数体没有返回值,运行时得到空串。lint 报 `flow.message.simple_field_missing_return`,并连带触发 `card_title_empty`/`card_content_empty` 或 `missing_for_human_node`。
57
+ - 修法:写成 `return "采购审批待处理"` 或 `` return `采购审批待处理:${step.name}` ``。simple 模式 `actions[].type` 写 `link` 是合法的。
58
+ - **有真实办理人的节点必须有消息模板**
59
+ - 判定标准:节点有真实办理人(审批/填写/确认,或 `owner_is_creater`、`owner_roles`、`auto_range_*` 能算出人)时,`message_template` 为空、或静态禁发(`return "";`、`return;`、`return null;`、`return undefined;`、`return [];`)且 `bpmax_lint.suppressed_node_messages[]` 里没有对应 `channel: 'message'` 的 ack。留空模板会触发后端默认文案,静默禁发会让办理人收不到待办提醒。
60
+ - 修法:补完整卡片并至少给一个跳转按钮;确实不能通知时,在 work 的 `bpmax_lint.suppressed_node_messages[]` 写 `{ node_id, channel: 'message', reason: '<业务原因>' }`,并同步确认抄送渠道已覆盖该角色的知会需求。
61
+
45
62
  ## 前端失焦查重专项核查
46
63
  - 任何 `customeValidate`、字段级 `blur` 校验、前端 `fetch`/`$axios` 查重脚本,都必须额外确认调用的是只读接口。
47
64
  - 不要因为接口名里有 `search` / `check` / `validate` 就默认它无副作用;先到对应 controller 看这个 action 是否真的实现。
@@ -48,7 +48,9 @@ description: "用于通过 bpmax-cli typed config 创建或编辑 BPMAX 项目
48
48
  bpmax-cli config list-template submit --id create:list-template --payload .codex/tmp/list-template-editor/submit/<create-file>.json --profile <profile> --confirm "submit list-template create:list-template" --format json
49
49
  bpmax-cli config list-template delete --id <id> --profile <profile> --confirm "delete list-template <id>" --format json
50
50
  ```
51
- 当 build 产物标记 `list_template_safety.submit_gate.validation_required=true` 时,submit 还必须传 `--validation-report <file>`。只有经过审计的紧急情形可用 `--override-reason "<具体原因>"` 绕过;覆盖原因会进入 dry-run 和执行回执,不能用空泛文案代替证据。
51
+ 当 build 产物标记 `list_template_safety.submit_gate.validation_required=true` 时,submit 还必须传 `--validation-report <file>`:`permission_matrix` 类型按权限/高风险矩阵校验。只有经过审计的紧急情形可用 `--override-reason "<具体原因>"` 绕过;覆盖原因会进入 dry-run 和执行回执,不能用空泛文案代替证据。
52
+ 当 build 产物标记 `list_template_safety.presentation_only=true`(只改了 `width`/`minWidth`/`align`/`headerAlign`/`showOverflowTooltip`/`fixed`/`sortable`/`className` 这类展示属性)时,不要求权限矩阵,改为要求 `column_width_runtime_check` 类型的 `--validation-report`:`schema_version=1`、`result="pass"`、绑定 `template_id`/`profile`/`submit_payload_hash`、声明 `template_data_columns`(该模板数据列总数)、`columns[]` 每列显式写 `truncated: true|false`,且测量列数必须≥`template_data_columns`。任一列仍截断即失败。
53
+ build 产物里的 `list_template_warnings`(列宽按语义偏窄、下钻链接未带行上下文、guard 硬编码环节名)是必须先看的告警:lint 会报,但只走 build→submit 时也会随 `list_template_safety.warnings` 输出。
52
54
  9. 提交后必须 `verify/readback`,确认顶层字段、`content.level`、`content.config[]`、列标题顺序、关键 `$template` 和数据集字段引用一致。
53
55
  10. 高风险改动必须以真实用户身份打开运行态列表页,只读验证目标列、操作按钮、图标/头像/badge/图片预览、筛选和 console/network 错误;不得把接口提交伪装成页面回归。
54
56